/** * \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 "CbmRichPoint.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), fEventNum(0), fEventNum2(0), fGP(), fRichRings(NULL), fRichRingMatches(NULL), fMinNofHits(0) { fEventNum = 0; fEventNum2 = 0; fMinNofHits = 7; } 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 PlanePoints.resize(3); for(int p=0;pGetEntriesFast()>10){ int PointsFilled=0; for(int p=1;pGetEntriesFast(); Int_t nofPoints = fRichPoints->GetEntriesFast(); if(nofPoints==0 || nofRefPoints==0){return;} if(nofPoints>1500){return;} cout<<"nofPoints: "<< nofPoints< calculate angle (to be done later) for (int i = 0; i < nofRefPoints; i++) { TVector3 PosAtRefl; TVector3 PosAtDetIn; //TVector3 PosAtDetOut; CbmRichPoint* RefPoint = (CbmRichPoint*)fRefPoints->At(i); if (RefPoint == NULL) continue; int trackId = RefPoint->GetTrackID(); if(trackId==-2) {continue;} RefPoint->Position(PosAtRefl); int Zpos=int(10.*PosAtRefl.Z());//2653 or 2655 -->take 2655 which is the entrance point //of the REFLECTED photon into the sensitive plane //cout<At(trackId); if(NULL == point) continue; PosAtDetIn.SetX(point->GetX()); PosAtDetIn.SetY(point->GetY()); PosAtDetIn.SetZ(point->GetZ()); //float DistMCToFocalPoint=GetDistanceMirrorCenterToPMTPoint(point); float Delta= GetDistanceMirrorCenterToPMTPoint(PosAtDetIn)-(fGP.fMirrorR/2.); float hypot= GetIntersectionPointsLS(MirrorCenter, PlanePoints[1], PlanePoints[2], fGP.fMirrorR/2.); //if(hypot==-1.){cout<<" ********************+ hypot==-1. :and Delta ="<Fill(Delta); H_dFocalPoint_II->Fill(rho); /////////// calculate the vectors on teh PMT plane TVector3 LineOnPMT1=PlanePoints[1]-PlanePoints[0]; TVector3 LineOnPMT2=PlanePoints[2]-PlanePoints[0]; TVector3 NormToPMT=LineOnPMT1.Cross(LineOnPMT2); TVector3 LineSensToPMT=PosAtDetIn-PosAtRefl; /////////// calculate alpha relative to the "tilted" PMT plane !! double Alpha=LineSensToPMT.Angle(NormToPMT);//*TMath::RadToDeg(); double AlphaInDeg=Alpha*TMath::RadToDeg(); if(AlphaInDeg>90.){AlphaInDeg=180.-AlphaInDeg;} H_PointsIn_XY->Fill(PosAtDetIn.X(),PosAtDetIn.Y()); H_Alpha->Fill(AlphaInDeg); if(PosAtDetIn.X()<0. && PosAtDetIn.Y()>0) { H_Alpha_UpLeft->Fill(AlphaInDeg ); H_Alpha_XYposAtDet->Fill(PosAtDetIn.X(),PosAtDetIn.Y(),AlphaInDeg); } } //*********************************************************** Int_t nofHits = fRichHits->GetEntriesFast(); //cout<<"++++++++++++++++++++++++ nofHits = "<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); //cout<GetX()<<" "<GetY()<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) continue; Int_t mcTrackId = ringMatch->GetMatchedLink().GetIndex(); if (mcTrackId < 0) continue; CbmMCTrack* mcTrack = (CbmMCTrack*)fMcTracks->At(mcTrackId); if (!mcTrack) 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(); //cout<<"pdg = "<Write(); H_PtPrim->Write(); H_Hits_XY->Write(); H_PointsIn_XY->Write(); H_PointsOut_XY->Write(); H_NofPhotonsPerHit->Write(); H_DiffXhit->Write(); H_DiffYhit->Write(); H_Alpha->Write(); H_Alpha_UpLeft->Write(); H_Alpha_XYposAtDet->Write(); H_acc_mom_el->Write(); H_acc_pty_el->Write(); H_dFocalPoint_I->Write(); H_dFocalPoint_II->Write(); H_NofHitsAll->Write(); H_Radius->Write(); H_aAxis->Write(); H_bAxis->Write(); H_boa->Write(); H_RingCenter->Write(); H_RingCenter_Aaxis->Write(); H_RingCenter_Baxis->Write(); H_RingCenter_boa->Write(); H_dR->Write(); } void CbmRichGeoOpt::FillPointsAtPMT() { for(int p=0;p-1;p2--){ if(TMath::Abs( PlanePoints[p2].X() - PlanePoints[p].X() ) < 0.1){PointFilled=0;} } if(PointFilled==1){continue;} } } fEventNum2++; 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==-2) 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); //Check if nan --> no intersection if(! (t1==1. || t1 >1.) ){return -1.;} TVector3 IntersectP1; TVector3 IntersectP2; IntersectP1.SetX( G_P1.X()+t1*(G_P2.X()-G_P1.X()) ); IntersectP1.SetY( G_P1.Y()+t1*(G_P2.Y()-G_P1.Y()) ); IntersectP1.SetZ( G_P1.Z()+t1*(G_P2.Z()-G_P1.Z()) ); IntersectP2.SetX( G_P1.X()+t2*(G_P2.X()-G_P1.X()) ); IntersectP2.SetY( G_P1.Y()+t2*(G_P2.Y()-G_P1.Y()) ); IntersectP2.SetZ( G_P1.Z()+t2*(G_P2.Z()-G_P1.Z()) ); TVector3 Line1=IntersectP1-G_P1; float Length1=TMath::Sqrt(Line1.X()*Line1.X() + Line1.Y()*Line1.Y() + Line1.Z()*Line1.Z()); TVector3 Line2=IntersectP2-G_P1; float Length2=TMath::Sqrt(Line2.X()*Line2.X() + Line2.Y()*Line2.Y() + Line2.Z()*Line2.Z()); if(Length1