/** * \file CbmRichGeoOpt.cxx * * \author Tariq Mahmoud * \date 2014 **/ #include "CbmRichGeoOpt.h" #include "TH1D.h" #include "TH3D.h" #include "TH1.h" #include "TCanvas.h" #include "TClonesArray.h" #include "CbmMCTrack.h" #include "FairTrackParam.h" #include "CbmDrawHist.h" #include "CbmTrackMatchNew.h" #include "CbmRichRing.h" #include "CbmRichHit.h" #include #include #include //++++++++++++++++++++++++++++++++++++++++++ #include "CbmRichHitProducer.h" #include "CbmRichRingLight.h" using namespace std; using boost::assign::list_of; CbmRichGeoOpt::CbmRichGeoOpt() : FairTask("CbmRichGeoOpt"), fRichPoints(NULL), fMcTracks(NULL), fRefPoints(NULL), fRichHits(NULL), fGP(), fRichRings(NULL), fRichRingMatches(NULL), fEventNum(0), PointsFilled(0), fMinNofHits(7), nPhotonsNotOnPlane(0), nPhotonsNotOnSphere(0), nTotalPhorons(0), PlanePoints(), PMTPlaneCenter(), ReadPMTPlaneCenter(), ReadPMTPlaneCenterOrig(), MirrorCenter(), //ReadMirrorCenter(), RotX(0.), RotY(0.), r1(), r2(), n(), PMTPlaneX(0.), PMTPlaneY(0.), MirrPosition(), // MirrPosX(0.), // MirrPosY(0.), // MirrPosZ(0.), // PMTPlaneXatThird(0.), // PMTPlaneYatThird(0.), H_DistancePMTtoMirrCenter(NULL), H_DistancePMTtoMirr(NULL), H_MomPrim(NULL), H_PtPrim(NULL), H_MomPt(NULL), H_Hits_XY(NULL), H_PointsIn_XY(NULL), H_PointsOut_XY(NULL), H_NofPhotonsPerEv(NULL), H_NofPhotonsPerHit(NULL), H_NofPhotonsSmallerThan30(NULL), H_DiffXhit(NULL), H_DiffYhit(NULL), H_dFocalPoint_Delta(NULL), H_dFocalPoint_Rho(NULL), H_Alpha(NULL), H_Alpha_UpLeft(NULL), H_Alpha_UpLeft_II(NULL), H_Alpha_UpLeft_RegularTheta(NULL), H_Alpha_UpLeft_LeftHalf(NULL), H_Alpha_UpLeft_RightHalf(NULL), H_Alpha_UpLeft_UpperHalf(NULL), H_Alpha_UpLeft_LowerHalf(NULL), H_Alpha_XYposAtDet(NULL), H_Alpha_XYposAtDet_RegularTheta(NULL), H_Alpha_XYposAtDet_LeftHalf(NULL), H_Alpha_XYposAtDet_RightHalf(NULL), H_Alpha_XYposAtDet_UpperHalf(NULL), H_Alpha_XYposAtDet_LowerHalf(NULL), H_acc_mom_el(NULL), H_acc_pty_el(NULL), H_NofHitsAll(NULL), H_NofRings(NULL), H_NofRings_NofHits(NULL), H_RingCenterX(NULL), H_RingCenterY(NULL), H_RingCenter(NULL), H_Radius(NULL), H_aAxis(NULL), H_bAxis(NULL), H_boa(NULL), H_boa_RegularTheta(NULL), H_boa_LeftHalf(NULL), H_boa_RightHalf(NULL), H_boa_UpperHalf(NULL), H_boa_LowerHalf(NULL), H_dR(NULL), H_dR_RegularTheta(NULL), H_dR_LeftHalf(NULL), H_dR_RightHalf(NULL), H_dR_UpperHalf(NULL), H_dR_LowerHalf(NULL), H_RingCenter_Aaxis(NULL), H_RingCenter_Baxis(NULL), H_RingCenter_boa(NULL), H_RingCenter_boa_RegularTheta(NULL), H_RingCenter_boa_RightHalf(NULL), H_RingCenter_boa_LeftHalf(NULL), H_RingCenter_boa_LowerHalf(NULL), H_RingCenter_boa_UpperHalf(NULL), H_RingCenter_dR(NULL), H_RingCenter_dR_RegularTheta(NULL), H_RingCenter_dR_LeftHalf(NULL), H_RingCenter_dR_RightHalf(NULL), H_RingCenter_dR_UpperHalf(NULL), H_RingCenter_dR_LowerHalf(NULL) { /* fEventNum = 0; PointsFilled = 0; fMinNofHits = 7; nPhotonsNotOnPlane = 0; nPhotonsNotOnSphere = 0; nTotalPhorons = 0; */ } CbmRichGeoOpt::~CbmRichGeoOpt() { } InitStatus CbmRichGeoOpt::Init() { cout << "CbmRichGeoOpt::Init"<GetObject("RichPoint"); if ( NULL == fRichPoints) { Fatal("CbmRichGeoOpt::Init","No RichPoint array!"); } fRefPoints = (TClonesArray*) ioman->GetObject("RefPlanePoint"); if ( NULL == fRefPoints) { Fatal("CbmRichGeoOpt::Init","No fRefPoints array!"); } fMcTracks = (TClonesArray*) ioman->GetObject("MCTrack"); if ( NULL == fMcTracks) { Fatal("CbmRichGeoOpt::Init","No MCTrack array!"); } fRichHits = (TClonesArray*) ioman->GetObject("RichHit"); if ( NULL == fRichHits) { Fatal("CbmRichGeoTest::Init","No RichHit array!"); } fGP = CbmRichHitProducer::InitRootGeometry(); /////////////////////////////////////////// fRichRings = (TClonesArray*) ioman->GetObject("RichRing"); if ( NULL == fRichRings) { Fatal("CbmRichGeoTest::Init","No RichRing array!"); } fRichRingMatches = (TClonesArray*) ioman->GetObject("RichRingMatch"); if ( NULL == fRichRingMatches) { Fatal("CbmRichGeoTest::Init","No RichRingMatch array!"); } /////////////// need three points on the PMT plane to determine its equation //cout<<" initializing points values -1000"<GetEntriesFast(); Int_t nofPoints = fRichPoints->GetEntriesFast(); if(nofPoints==0 || nofRefPoints==0){return;} if(nofPoints>2000){return;} cout<<"nofPoints: "<< nofPoints< calculate angle (to be done later) if(nofPoints<=30){H_NofPhotonsSmallerThan30->Fill(nofPoints); } H_NofPhotonsPerEv->Fill(nofPoints); for (int i = 0; i < nofRefPoints; i++) { TVector3 PosAtRefl; TVector3 PosAtDetIn; TVector3 PosAtDetOut; CbmRichPoint* RefPoint = (CbmRichPoint*)fRefPoints->At(i); if (RefPoint == NULL) continue; int RefPointTrackId = RefPoint->GetTrackID(); if(RefPointTrackId<0) {continue;} RefPoint->Position(PosAtRefl); int Zpos=int(10.*PosAtRefl.Z());//3037 0r 3038 -->take 3038 which is the entrance point //of the REFLECTED photon into the sensitive plane //cout<GetX()); PosAtDetIn.SetY(point->GetY()); PosAtDetIn.SetZ(point->GetZ()); Int_t PointMCTrackId = point->GetTrackID(); CbmMCTrack* PointTrack = static_cast(fMcTracks->At(PointMCTrackId)); if (NULL == PointTrack) continue; TVector3 PointMom; PointTrack->GetMomentum(PointMom); Int_t PointMotherId = PointTrack->GetMotherId(); if (PointMotherId == -1){continue;} CbmMCTrack* motherTrack = static_cast(fMcTracks->At(PointMotherId)); int pdg = TMath::Abs(motherTrack->GetPdgCode()); int motherId = motherTrack->GetMotherId(); TVector3 ElMom; Double_t ElTheta; if (pdg == 11 && motherId == -1){ motherTrack->GetMomentum(ElMom); ElTheta=ElMom.Theta()* 180 / TMath::Pi(); } //////////////////////////////////////////////////// bool Checked=CheckPointLiesOnPlane(PosAtDetIn,PlanePoints[0],n); if(!Checked) continue;//cout<<" point not on plane: ("<GetX()<<","<GetY()<<","<GetZ()<<")"<90.){AlphaInDeg=180.-AlphaInDeg;} /////////// calculate alpha throuh the momentum vector !! double Alpha2=PointMom.Angle(n);//*TMath::RadToDeg(); double Alpha2InDeg=Alpha2*TMath::RadToDeg(); if(Alpha2InDeg>90.){Alpha2InDeg=180.-Alpha2InDeg;} H_PointsIn_XY->Fill(PosAtDetIn.X(),PosAtDetIn.Y()); //PosAtDetOut CbmRichHitProducer::TiltPoint(&PosAtDetIn, &PosAtDetOut, fGP.fPmtPhi, fGP.fPmtTheta, fGP.fPmtZOrig); H_PointsOut_XY->Fill(PosAtDetOut.X(),PosAtDetOut.Y()); H_Alpha->Fill(AlphaInDeg); if(PosAtDetIn.X()<0. && PosAtDetIn.Y()>0) { if(ElTheta<=25){ H_Alpha_UpLeft_RegularTheta->Fill(AlphaInDeg ); H_Alpha_XYposAtDet_RegularTheta->Fill(PosAtDetIn.X(),PosAtDetIn.Y(),AlphaInDeg); } H_Alpha_UpLeft->Fill(AlphaInDeg ); H_Alpha_UpLeft_II->Fill(Alpha2InDeg ); H_Alpha_XYposAtDet->Fill(PosAtDetIn.X(),PosAtDetIn.Y(),AlphaInDeg); if(PosAtDetIn.X() <= PMTPlaneX){H_Alpha_UpLeft_LeftHalf->Fill(AlphaInDeg ); H_Alpha_XYposAtDet_LeftHalf->Fill(PosAtDetIn.X(),PosAtDetIn.Y(),AlphaInDeg);} if(PosAtDetIn.X() > PMTPlaneX){H_Alpha_UpLeft_RightHalf->Fill(AlphaInDeg ); H_Alpha_XYposAtDet_RightHalf->Fill(PosAtDetIn.X(),PosAtDetIn.Y(),AlphaInDeg);} if(PosAtDetIn.Y() <= PMTPlaneY){H_Alpha_UpLeft_LowerHalf->Fill(AlphaInDeg ); H_Alpha_XYposAtDet_LowerHalf->Fill(PosAtDetIn.X(),PosAtDetIn.Y(),AlphaInDeg);} if(PosAtDetIn.Y() > PMTPlaneY){H_Alpha_UpLeft_UpperHalf->Fill(AlphaInDeg ); H_Alpha_XYposAtDet_UpperHalf->Fill(PosAtDetIn.X(),PosAtDetIn.Y(),AlphaInDeg);} } } //*********************************************************** Int_t nofHits = fRichHits->GetEntriesFast(); for (Int_t iH = 0; iH < nofHits; iH++){ CbmRichHit *hit = (CbmRichHit*) fRichHits->At(iH); if ( hit == NULL ) continue; Int_t pointInd = hit->GetRefId(); if (pointInd < 0) continue; CbmRichPoint *point = (CbmRichPoint*) fRichPoints->At(pointInd); if ( point == NULL ) continue; H_NofPhotonsPerHit->Fill(hit->GetNPhotons()); TVector3 inPos(point->GetX(), point->GetY(), point->GetZ()); TVector3 outPos; CbmRichHitProducer::TiltPoint(&inPos, &outPos, fGP.fPmtPhi, fGP.fPmtTheta, fGP.fPmtZOrig); H_Hits_XY->Fill(hit->GetX(), hit->GetY()); H_DiffXhit->Fill(hit->GetX() - outPos.X()); H_DiffYhit->Fill(hit->GetY() - outPos.Y()); } } /////////////////////////////// void CbmRichGeoOpt::RingParameters() { Int_t nofRings = fRichRings->GetEntriesFast(); for (Int_t iR = 0; iR < nofRings; iR++){ CbmRichRing *ring = (CbmRichRing*) fRichRings->At(iR); if (NULL == ring) continue; CbmTrackMatchNew* ringMatch = (CbmTrackMatchNew*) fRichRingMatches->At(iR); if (NULL == ringMatch){ H_NofRings->SetBinContent(8,H_NofRings->GetBinCenter(8)+1); continue;} Int_t mcTrackId = ringMatch->GetMatchedLink().GetIndex(); if (mcTrackId < 0){ H_NofRings->SetBinContent(8,H_NofRings->GetBinCenter(8)+1); continue;}//{ continue;} CbmMCTrack* mcTrack = (CbmMCTrack*)fMcTracks->At(mcTrackId); if (!mcTrack){ H_NofRings->SetBinContent(8,H_NofRings->GetBinCenter(8)+1); continue;}// continue; Int_t motherId = mcTrack->GetMotherId(); Int_t pdg = TMath::Abs(mcTrack->GetPdgCode()); Double_t momentum = mcTrack->GetP(); Double_t pt = mcTrack->GetPt(); Double_t rapidity = mcTrack->GetRapidity(); TVector3 mom; mcTrack->GetMomentum(mom); Double_t theta=mom.Theta()* 180 / TMath::Pi(); // Double_t theta = mcTrack->Theta(); // cout<<" **************************** "<SetBinContent(8,H_NofRings->GetBinCenter(8)+1); continue;}// continue; // only primary electrons H_NofRings->Fill(nofRings); if (ring->GetNofHits() >= fMinNofHits){ H_acc_mom_el->Fill(momentum); H_acc_pty_el->Fill(rapidity, pt); } /////////////////////////////////// float radius=ring->GetRadius(); if(radius<=0.){continue;}//with ideal finder --> many rings with radius -1. //Test if radius is a NAN: if(! (radius<=1. || radius >1.) ){continue;} float aA = ring->GetAaxis(); float bA = ring->GetBaxis(); H_Radius->Fill(radius); H_aAxis->Fill(aA); H_bAxis->Fill(bA); H_boa->Fill(bA/aA); float CentX=ring->GetCenterX(); float CentY=ring->GetCenterY(); H_RingCenter->Fill(CentX,CentY); H_RingCenter_Aaxis->Fill(CentX,CentY,aA); H_RingCenter_Baxis->Fill(CentX,CentY,bA); H_RingCenter_boa->Fill(CentX,CentY,bA/aA); if(theta<=24){H_boa_RegularTheta->Fill(bA/aA); H_RingCenter_boa_RegularTheta->Fill(CentX,CentY,bA/aA);} if(CentX > PMTPlaneX){H_boa_RightHalf->Fill(bA/aA); H_RingCenter_boa_RightHalf->Fill(CentX,CentY,bA/aA);} if(CentX <= PMTPlaneX){H_boa_LeftHalf->Fill(bA/aA); H_RingCenter_boa_LeftHalf->Fill(CentX,CentY,bA/aA);} if(CentY > PMTPlaneY){H_boa_UpperHalf->Fill(bA/aA); H_RingCenter_boa_UpperHalf->Fill(CentX,CentY,bA/aA);} if(CentY <= PMTPlaneY){H_boa_LowerHalf->Fill(bA/aA); H_RingCenter_boa_LowerHalf->Fill(CentX,CentY,bA/aA);} // if(CentX <= PMTPlaneX && CentY >PMTPlaneY){H_boa_Q1->Fill(bA/aA);} int nAllHitsInR=ring->GetNofHits(); H_NofHitsAll->Fill(nAllHitsInR); H_NofRings_NofHits->Fill(nofRings,nAllHitsInR); for(int iH=0;iHAt(ring->GetHit(iH)); double xH=hit->GetX(); double yH=hit->GetY(); double dR=aA-TMath::Sqrt( (CentX-xH)*(CentX-xH) + (CentY-yH)*(CentY-yH) ); H_dR->Fill(dR); H_RingCenter_dR->Fill(CentX,CentY,dR); if(theta<=24){H_dR_RegularTheta->Fill(dR); H_RingCenter_dR_RegularTheta->Fill(CentX,CentY,dR);} if(CentX > PMTPlaneX){H_dR_RightHalf->Fill(dR); H_RingCenter_dR_RightHalf->Fill(CentX,CentY,dR);} if(CentX <= PMTPlaneX){H_dR_LeftHalf->Fill(dR); H_RingCenter_dR_LeftHalf->Fill(CentX,CentY,dR);} if(CentY > PMTPlaneY){H_dR_UpperHalf->Fill(dR); H_RingCenter_dR_UpperHalf->Fill(CentX,CentY,dR);} if(CentY <= PMTPlaneY){H_dR_LowerHalf->Fill(dR); H_RingCenter_dR_LowerHalf->Fill(CentX,CentY,dR);} } } } //////////////////////////////// void CbmRichGeoOpt::FillMcHist() { for (Int_t i = 0; i < fMcTracks->GetEntriesFast(); i++){ CbmMCTrack* mcTrack = (CbmMCTrack*)fMcTracks->At(i); if (!mcTrack) continue; Int_t motherId = mcTrack->GetMotherId(); Int_t pdg = TMath::Abs(mcTrack->GetPdgCode()); if (pdg == 11 && motherId == -1){ H_MomPt->Fill( mcTrack->GetP(), mcTrack->GetPt()); H_MomPrim->Fill(mcTrack->GetP()); H_PtPrim->Fill(mcTrack->GetPt()); } } } //////////////////////////////// void CbmRichGeoOpt::InitHistograms() { int nBinsX = 28; double xMin = -110.; double xMax = 110.; int nBinsY = 40; double yMin = -200; double yMax = 200.; H_MomPrim = new TH1D("H_MomPrim", "H_MomPrim;p [GeV]; Yield", 200, 0., 10.); H_PtPrim = new TH1D("H_PtPrim", "H_PtPrim;p [GeV]; Yield", 80, 0., 4.); H_MomPt = new TH2D("H_MomPt", "H_MomPt;p [GeV];pt [GeV]; Yield", 200, 0., 10., 80, 0., 4.); H_Hits_XY = new TH2D("H_Hits_XY", "H_Hits_XY;X [cm];Y [cm];Counter", 200, -150., 50.,400, 0.,400.); H_PointsIn_XY = new TH2D("H_PointsIn_XY", "H_PointsIn_XY;X [cm];Y [cm];Counter", 400, -100., 100.,400, 0.,400.); H_PointsOut_XY = new TH2D("H_PointsOut_XY", "H_PointsOut_XY;X [cm];Y [cm];Counter", 200, -150., 50.,400, 0.,400.); //cout<<" init hist H_NofPhotonsPerEv"<Write(); H_PtPrim->Write(); H_MomPt->Write(); H_Hits_XY->Write(); H_PointsIn_XY->Write(); H_PointsOut_XY->Write(); H_NofPhotonsPerEv->Write(); H_NofPhotonsPerHit->Write(); H_NofPhotonsSmallerThan30->Write(); H_DiffXhit->Write(); H_DiffYhit->Write(); H_Alpha->Write(); H_Alpha_UpLeft->Write(); H_Alpha_UpLeft_II->Write(); H_Alpha_UpLeft_RegularTheta->Write(); H_Alpha_UpLeft_LeftHalf->Write(); H_Alpha_UpLeft_RightHalf->Write(); H_Alpha_UpLeft_LowerHalf->Write(); H_Alpha_UpLeft_UpperHalf->Write(); H_Alpha_XYposAtDet->Write(); H_Alpha_XYposAtDet_RegularTheta->Write(); H_Alpha_XYposAtDet_LeftHalf->Write(); H_Alpha_XYposAtDet_RightHalf->Write(); H_Alpha_XYposAtDet_LowerHalf->Write(); H_Alpha_XYposAtDet_UpperHalf->Write(); H_acc_mom_el->Write(); H_acc_pty_el->Write(); H_dFocalPoint_Delta->Write(); H_dFocalPoint_Rho->Write(); H_NofHitsAll->Write(); H_NofRings->Write(); H_NofRings_NofHits->Write(); H_Radius->Write(); H_aAxis->Write(); H_bAxis->Write(); H_boa->Write(); H_boa_RegularTheta->Write(); H_boa_LeftHalf->Write(); H_boa_RightHalf->Write(); H_boa_LowerHalf->Write(); H_boa_UpperHalf->Write(); H_dR->Write(); H_dR_RegularTheta->Write(); H_dR_LeftHalf->Write(); H_dR_RightHalf->Write(); H_dR_LowerHalf->Write(); H_dR_UpperHalf->Write(); H_RingCenter->Write(); H_RingCenter_Aaxis->Write(); H_RingCenter_Baxis->Write(); H_RingCenter_boa->Write(); H_RingCenter_boa_RegularTheta->Write(); H_RingCenter_boa_LeftHalf->Write(); H_RingCenter_boa_RightHalf->Write(); H_RingCenter_boa_LowerHalf->Write(); H_RingCenter_boa_UpperHalf->Write(); H_RingCenter_dR->Write(); H_RingCenter_dR_RegularTheta->Write(); H_RingCenter_dR_LeftHalf->Write(); H_RingCenter_dR_RightHalf->Write(); H_RingCenter_dR_LowerHalf->Write(); H_RingCenter_dR_UpperHalf->Write(); } ////////////////////////////////////////////////////////////// /////////////////////////////// CbmRichPoint* CbmRichGeoOpt::GetPMTPoint(int TrackIdOfSensPlane) { Int_t nofPoints = fRichPoints->GetEntriesFast(); for(Int_t ip = 0; ip < nofPoints; ip++){ CbmRichPoint* point = (CbmRichPoint*) fRichPoints->At(ip); if(NULL == point) continue; int trackId = point->GetTrackID(); if(trackId<0) continue; if(trackId == TrackIdOfSensPlane){//cout<<"In Function: got corresponding trackid:"<-1;p2--){ if(TMath::Abs( PlanePoints[p2].X() - PlanePoints[p].X() ) < 1.0){PointFilled=0;} } if(PointFilled==1){continue;} } } //fEventNum++; Int_t nofPoints = fRichPoints->GetEntriesFast(); for(Int_t ip = 0; ip < nofPoints-10; ip+=10){ CbmRichPoint* point = (CbmRichPoint*) fRichPoints->At(ip); if(NULL == point) continue; int trackId = point->GetTrackID(); if(trackId<0) continue; if(point->GetX()>=0 || point->GetY()<=0){continue;} PlanePoints[p].SetX(point->GetX());PlanePoints[p].SetY(point->GetY());PlanePoints[p].SetZ(point->GetZ()); if(PlanePoints[p].X() !=-1000.){break;} } } } ////////////////////////////////////////////////////// ////////////////////////////////////////////////////// float CbmRichGeoOpt::GetIntersectionPointsLS( TVector3 MirrCenter, TVector3 G_P1, TVector3 G_P2, float R){ float A=(G_P1-MirrCenter)*(G_P1-MirrCenter); float B=(G_P2-G_P1)*(G_P2-G_P1); float P=2.*( (G_P1-MirrCenter)*(G_P2-G_P1) )/(B); float q=(A-R*R)/B; float t1=-1.*P/2.-TMath::Sqrt( (P/2.)*(P/2.) -q); float t2=-1.*P/2.+TMath::Sqrt( (P/2.)*(P/2.) -q); //cout<<"t1="<