// ------------------------------------------------------------------------- // ----- PndDrcRecoLookupMap source file ----- // ----- Created 10/11/10 by Maria Patsyuk ----- // ----- ----- // ----- ----- // ------------------------------------------------------------------------- #include #include #include "stdio.h" #include "PndGeoDrc.h" #include "PndDrcRecoLookupMap.h" #include "FairRootManager.h" #include "PndMCTrack.h" #include "PndDrcBarPoint.h" #include "PndDrcPDPoint.h" #include "PndDrcHit.h" #include "PndDrcPDHit.h" #include "TVector3.h" #include "TRandom.h" #include "FairRunAna.h" #include "FairRuntimeDb.h" #include "FairBaseParSet.h" #include "FairGeoVolume.h" #include "TString.h" #include "FairGeoTransform.h" #include "FairGeoVector.h" #include "FairGeoMedium.h" #include "FairGeoNode.h" #include "PndGeoDrcPar.h" #include "TFormula.h" #include "TMath.h" #include "TParticlePDG.h" #include "TDatabasePDG.h" #include "TPDGCode.h" #include "TGeoManager.h" #include "TCanvas.h" #include "TFile.h" #include "TLegend.h" #include "TStyle.h" #include "TF1.h" #include "TExec.h" #include "TLine.h" #include "TPolyLine.h" //#include "PndChPho.h" #include "PndDrcLutInfo.h" #include "PndDrcDigiPar.h" #include "TVectorD.h" using std::endl; using std::cout; // ----- Default constructor ------------------------------------------- PndDrcRecoLookupMap::PndDrcRecoLookupMap() :FairTask("PndDrcRecoLookupMap") { fGeo = new PndGeoDrc(); fGeoH=NULL; fDigiPar = NULL; } // ----- Standard constructor with verbosity level ------------------------------------------- PndDrcRecoLookupMap::PndDrcRecoLookupMap(Int_t verbose) :FairTask("PndDrcRecoLookupMap") { fVerbose = verbose; fGeo = new PndGeoDrc(); fGeoH=NULL; fDigiPar = NULL; } // ----- Destructor ---------------------------------------------------- PndDrcRecoLookupMap::~PndDrcRecoLookupMap() { if (fGeo) delete fGeo; if (fGeoH) delete fGeoH; fHistoList->Delete(); delete fHistoList; } // ----- Initialization ----------------------------------------------- InitStatus PndDrcRecoLookupMap::Init() { cout << " ---------- INITIALIZATION ------------" << endl; nevents = 0; // Get RootManager FairRootManager* ioman = FairRootManager::Instance(); if ( ! ioman ) { cout << "-E- PndDrcRecoLookupMap::Init: " << "RootManager not instantiated!" << endl; return kFATAL; } // Get input array fMCArray = (TClonesArray*) ioman->GetObject("MCTrack"); if ( ! fMCArray ) { cout << "-W- PndDrcRecoLookupMap::Init: " << "No MCTrack array!" << endl; return kERROR; } // Get input array fBarPointArray = (TClonesArray*) ioman->GetObject("DrcBarPoint"); if ( ! fBarPointArray ) { cout << "-W- PndDrcRecoLookupMap::Init: " << "No DrcBarPoint array!" << endl; return kERROR; } // Get Photon point array fPDPointArray = (TClonesArray*) ioman->GetObject("DrcPDPoint"); if ( ! fPDPointArray ) { cout << "-W- PndDrcRecoLookupMap::Init: " << "No DrcPDPoint array!" << endl; return kERROR; } /* // Get input array fHitArray = (TClonesArray*) ioman->GetObject("DrcHit"); if ( ! fHitArray ) { cout << "-W- PndDrcRecoLookupMap::Init: " << "No DrcHit array!" << endl; return kERROR; } */ // Get digi array fDigiArray = (TClonesArray*) ioman->GetObject("DrcDigi"); if ( ! fDigiArray ) { cout << "-W- PndDrcRecoLookupMap::Init: " << "No DrcDigi array!" << endl; return kERROR; } // Get input array fPDHitArray = (TClonesArray*) ioman->GetObject("DrcPDHit"); if ( ! fPDHitArray ) { cout << "-W- PndDrcRecoLookupMap::Init: " << "No DrcPDHit array!" << endl; return kERROR; } // Create and register output array // fChPhoArray = new TClonesArray("PndChPho"); // ioman->Register("ChPho","Drc",fChPhoArray, kTRUE); fDrcLutInfoArray = new TClonesArray("PndDrcLutInfo"); ioman->Register("DrcLutInfo","Drc",fDrcLutInfoArray, kTRUE); // Get parameters: fpi = TMath::Pi(); fR = fGeo->radius(); fzup = fGeo->barBoxZUp(); fzdown = fGeo->barBoxZDown(); fHThick = fGeo->barHalfThick(); fBboxNum = fGeo->BBoxNum(); fBarNum = fGeo->barNum(); fPipehAngle = fGeo->PipehAngle(); fBarBoxGap = fGeo->BBoxGap(); //fLength = (180. - 2.*fPipehAngle - fBarBoxGap/fR*(fBboxNum/2. - 1.)/fpi*180.)/(fBboxNum/2.) * fR/ 180.*fpi; fDphi = 2.*(180. - 2*fPipehAngle)/ fBboxNum; //[degrees] fLSide = fGeo->Lside();//(180. - 2.*fPipehAngle - fBarBoxGap/fR*(fBboxNum/2. - 1.)/fpi*180.)/(fBboxNum/2.) * fR/ 180.*fpi; fBarWidth = fGeo->BarWidth();//fLSide/fBarNum; // vectors of bar surfaces: fnX1.SetXYZ(-1., 0.,0.); fnY1.SetXYZ( 0., 1.,0.); // Time resolution as a function of photon path timeres = new TF1("timeres","[0] + [1]*x", 0., 1000.); timeres->SetParameters(23.2773, 1.11008); cout << "-I- PndDrcRecoLookupMap: Intialization successfull" << endl; CreateHisto(); return kSUCCESS; } // ----- Private method SetParContainers ------------------------------- void PndDrcRecoLookupMap::SetParContainers() { // Get run and runtime database FairRunAna* run = FairRunAna::Instance(); if ( ! run ) Fatal("SetParContainers", "No analysis run"); FairRuntimeDb* db = run->GetRuntimeDb(); if ( ! db ) Fatal("SetParContainers", "No runtime database"); // Get DIRC digitisation parameter container fDigiPar = (PndDrcDigiPar*)(db->getContainer("DIRCLookupTable")); cout << "-I- PndDrcRecoLookupMap::SetParContainers(). read parameters" << endl; cout<<"read them!"<GetNHitPixels()<< endl; cout << "-I- PndDrcRecoLookupMap: Number of hit pixels "<< fDigiPar->GetNAmbiguities()<< endl; if ( fGeoH == NULL ) fGeoH = PndGeoHandling::Instance(); fGeoH->SetParContainers(); if(fVerbose>1) Info("SetParContainers","done."); return; } // ------------------------------------------------------------------------- // ----- Execution of Task --------------------------------------------- void PndDrcRecoLookupMap::Exec(Option_t* option) { //if ( ! fChPhoArray ) Fatal("Exec", "No fChPhoArray"); //fChPhoArray->Clear(); fGeoH->SetVerbose(fVerbose); nevents++; fDetectorID = 0; cout<<"EVENT # "< 0) { cout <<"PndDrcRecoLookupMap: Number of Detected MC Tracks : "<GetEntries()<GetEntriesFast(); j++) { hit = (PndDrcHit*)fHitArray->At(j); Int_t mcRef= hit->GetRefIndex(); pt= (PndDrcBarPoint*)fBarPointArray->At(mcRef); Int_t chtrID= pt->GetTrackID(); tr = (PndMCTrack*)fMCArray->At(chtrID); cout<<"nother track px = "<GetPx()<<", py = "<GetPy()< 0) { cout <<"PndDrcRecoLookupMap: Number of Detected Photon MCPDPoints : "<GetEntries()<GetEntries()<GetEntriesFast(); k++) { pdhit = (PndDrcPDHit*)fPDHitArray->At(k); Int_t mcPDRef= pdhit->GetRefIndex(); Ppt = (PndDrcPDPoint*)fPDPointArray->At(mcPDRef); PndDrcBarPoint *fBarPoint= (PndDrcBarPoint*)fBarPointArray->At(Ppt->GetBarPointID()); fBarId = fBarPoint->GetDetectorID(); //cout<<"bar name - "<GetPath(fBarId)<GetTrackID(); tr = (PndMCTrack*)fMCArray->At(trID); Int_t trMID=tr->GetMotherID(); //if(trMID > -1){ trMr = (PndMCTrack*)fMCArray->At(trMID); trMr->GetMomentum().Print(); Int_t trMpdg=trMr->GetPdgCode(); if(trMr->GetMotherID()==-1){ // charged track is a primary lutinfo.SetChPartPdg(trMpdg); // expected cherenkov angle Double_t Mrmass; Int_t MoSign; if(fabs(trMpdg) == 11){Mrmass = 0.000511; MoSign = 1;} if(fabs(trMpdg) == 13){Mrmass = 0.105658; MoSign = 1;} if(fabs(trMpdg) == 211){Mrmass = 0.139570; MoSign = -1;} if(fabs(trMpdg) == 321){Mrmass = 0.49368; MoSign = -1;} if(fabs(trMpdg) == 2212){Mrmass = 0.938; MoSign = -1;} if(fabs(trMpdg) == 50000050){Mrmass = 0.0; MoSign = -1;} Double_t Mrmom = trMr->GetMomentum().Mag(); CHexp = acos(sqrt(pow(Mrmom,2) + pow(Mrmass,2))/Mrmom/fGeo->nQuartz()); lutinfo.SetCherenkovMC(CHexp); cout<<"+++++++++++++++++++++++++++"<GetMomentum().X(), trMr->GetMomentum().Y(), trMr->GetMomentum().Z()); //fPMo.Print(); lutinfo.SetChPartDir(fPMo); cout<<"mother phi = "< 0.){ Double_t PtMo = sqrt(pow(trMr->GetMomentum().X(),2)+pow(trMr->GetMomentum().Y(),2)); Double_t Rratio = fR*fR/2./pow((PtMo/0.29979/fB)*100.,2); //Double_t phi_extra = fPMo.Phi() + trMpdg/fabs(trMpdg) * acos(1. - Rratio); // muon - ; proton + Double_t phi_extra = fPMo.Phi() + MoSign * trMpdg/fabs(trMpdg) * acos(1. - Rratio); // muon - ; proton + //fHAngleInBDeg = 0.5 * trMpdg/fabs(trMpdg) * (acos(1. - Rratio) /TMath::Pi())*180.; fHAngleInBDeg = 0.5 * MoSign * trMpdg/fabs(trMpdg) * (acos(1. - Rratio) /TMath::Pi())*180.; // cout<<"B = "<GetMomentum().X(), tr->GetMomentum().Y(), tr->GetMomentum().Z()); cout<<"Initial momentum of the photon :"<MasterToLocalShortId(fPMo, fBarId) - fGeoH->MasterToLocalShortId((0.,0.,0.),fBarId)).Unit(); PMBar.Print(); // to find Cherenkov Phi (NOT THETA!!!): TVector3 kB; kB.SetXYZ(fkxBar, fkyBar, fkzBar); // use lookups to get the kXbar and kYbar of photons: NHitPix = fDigiPar->GetNHitPixels(); //cout<<"N pixels = "<GetNAmbiguities(); cout<<"N amb = "<GetNPixelParam(); Double_t par[NPixPar]; if (fDigiPar->GetParamsForPixel(fpixID, par) == kFALSE) { cout<<"NO SUCH HIT IN LUT!!!"< 1.00028/fGeo->nQuartz() || (fkBar.Cross(fnY1)).Mag() > 1.00028/fGeo->nQuartz())){ ambig.push_back(fkBar); CHreco.push_back(fkBar.Angle(PMoBar)); CHdiff(8*i+jamb) = fabs(CHreco[8*i+jamb] - CHexp); Tamb.push_back(RecoAmbigTime(fkBar, fStartVertex, &fPath, 0)); Path.push_back(fPath); Adiff(8*i+jamb) = fkBar.Angle(fPphoB); //cout<<"reco ch angle = "<GetName() ) { currPhiTh = ihi; break; } } if ( currPhiTh == PhiThetaPoints.size() ) { Int_t nbins = (Int_t)(2.*fWidth/0.005); TH1F* newThetaPhiPoint = new TH1F(PhiT.Data(),"Cherenkov angle difference for theta", nbins, -fWidth,fWidth); PhiThetaPoints.push_back(newThetaPhiPoint); TH1F* newThetaPhiPointCut = new TH1F(PhiTCut.Data(),"Cherenkov angle difference for theta with time cut", nbins, -fWidth,fWidth); PhiThetaPointsCut.push_back(newThetaPhiPointCut); TH1F* newThetaPhiPointWeight = new TH1F(PhiTWeight.Data(),"Cherenkov angle difference for theta with time weights", nbins, -fWidth,fWidth); PhiThetaPointsWeight.push_back(newThetaPhiPointWeight); TH1F* newNbo = new TH1F(Nbo.Data(), "Number of bounces", 1000,0.,500.); NboPoints.push_back(newNbo); } //PhiThetaPoints[currPhiTh]->Fill(); //############################################# // fill N bounces for all photons: NboPoints[currPhiTh]->Fill(NumberOfBounces(fStartVertex, fPphoB, fBarId)); fhNboLam->Fill(flambdah, NumberOfBounces(fStartVertex, fPphoB, fBarId)); // fill all the ambiguities with weights: // WEIGHTS ARE BASED ON TIMING!!!!! for(Int_t j=0; j< CHreco.size(); j++){ fWeight = exp(- pow(Tamb[j] - ftime + ftime0, 2.)/2./pow(timeres->Eval(Path[j])/1000.,2.)); //cout<<"CHreco = "<GetName()<<" filled with"<Eval(Path[j])/1000.){ PhiThetaPointsCut[currPhiTh]->Fill(CHreco[j]-CHexp); //fhDTimeCut->Fill(Tamb[j] - ftime + ftime0); } //using weights based on time PhiThetaPointsWeight[currPhiTh]->Fill(CHreco[j]-CHexp, fWeight); //fhDTimeWeight->Fill(Tamb[j] - ftime + ftime0, fWeight); //cout<<"diff was filled with "<GetEntriesFast()]) PndDrcLutInfo(lutinfo); } //---------------------------------------------------------------------------------------------- Double_t PndDrcRecoLookupMap::InBarCoordSyst(TVector3 start, TVector3 *v1, TVector3 *v2, TVector3 *v3, TVector3 *v4){ Double_t startPhi = start.Phi()/fpi*180.; // [degrees] //cout<<"-I- InBarCoordinateSystem: start phi = "< 360.){startPhi = startPhi - 360.;} //cout<<"-I- InBarCoordinateSystem: start phi = "<= 3.1415/2.){ Z0 = -(start.Z() - fzup); } X0 = Z0*TMath::Tan(dir.Theta())*TMath::Cos(dir.Phi()); Y0 = Z0*TMath::Tan(dir.Theta())*TMath::Sin(dir.Phi()); //cout<<"-I- NumberOfBounces: tan th = "<= 0. && x1 + xEn <= a){xK = x1 + xEn;} if(x0 >= 0. && x1 + xEn > a){xK = 2*a - x1 - xEn; n = 1. + n;} if(x0 < 0. && x1 + xEn >= 0.){xK = a - (x1 + xEn); n = -1. -n;} if(x0 < 0. && x1 + xEn < 0.) {xK = a + x1 + xEn; n = -n;} if(printt){std::cout<<"xK = "<< xK<<", n = "<= 0. && x1 + xEn <= a){xK = a - (x1 + xEn);} if(x0 >= 0. && x1 + xEn > a){xK = x1 + xEn - a; n = 1. + n;} if(x0 < 0. && x1 + xEn >= 0.){xK = x1 + xEn; n = -1. -n;} if(x0 < 0. && x1 + xEn < 0.) {xK = - (x1 + xEn); n = -n;} if(printt){std::cout<<"xK = "<< xK<<", n = "<SetLineWidth(2); p6->Draw("same"); } //-------------------------------------------------------------------------------------------- Double_t PndDrcRecoLookupMap::RecoAmbigTime(TVector3 kb, TVector3 start, Double_t *l, Bool_t printout){ // [ns] // group velocities for oil and quartz for Noil and Nquartz assuming that mean lambda = 410 nm: //Double_t nOil = fGeo->nEV(); Double_t u_oil = 19.8;//30./nOil; //Double_t u_quartz = 30./1.46907; // for lambda = 410 nm //Double_t u_quartz = 30./1.47012; // for lambda = 400 nm //Double_t u_quartz = 30./1.46838; // for lambda = 417 nm //Double_t u_quartz = 30./1.47125; // for lambda = 390 nm //Double_t u_quartz = 30./1.47248; // for lambda = 380 nm Double_t u_quartz = 19.8;//30./fNquartz;//1.47805; // for lambda = 370 nm // kb - photon momentum at the production point, first calculate path in QUARTZ BAR: // assume that there are only DIRECT photons!!! // path in quartz: Double_t Z0 = 0.; Double_t kz = 0.; if(kb.Z() < 0.){Z0 = start.Z() - fGeo->barBoxZUp(); kz = kb.Z();} if(kb.Z() >= 0.){Z0 = 2.*fGeo->barBoxZDown() - fGeo->barBoxZUp() - start.Z(); kz = -kb.Z();} if(printout){ cout<<"-I- Reco ambig Time: Zstart = "<Add(fhPDTime); fHistoList->Add(fhPDHits); fHistoList->Add(fhDiff); fHistoList->Add(fhCHreal); fHistoList->Add(fhLam); // also add temp histos fHistoList->Add(fhRecoT1); fHistoList->Add(fhNboLam); fPixelSize = 0.65; fMapHist = new TH2F("fMapHist","Photon yield",30,2.5,152.5,20,0.35,20.35);// 3 bars 41,0.35,20.85); //25,0.5,25.5); fSigHist = new TH2F("fSigHist","fSigHist",30,2.5,152.5, 20,0.35,20.35);// 3 bars 41,0.35,20.85);//7 bars("fSigHist","fSigHist",30,2.5,152.5, 25,0.5,25.5);// 5 bars in bar box fCheHist = new TH2F("fCheHist","fCheHist",30,2.5,152.5, 20,0.35,20.35);// 3 bars 41,0.35,20.85); //("fCheHist","fCheHist",30,2.5,152.5, 25,0.5,25.5); fkBarXHist = new TH2F("fkBarXHist","fkBarXHist",200,-1.,1.,200,-1.,1.); fkBarYHist = new TH2F("fkBarYHist","fkBarYHist",200,-1.,1.,200,-1.,1.); fHistoList->Add(fMapHist); fHistoList->Add(fSigHist); fHistoList->Add(fCheHist); fHistoList->Add(fkBarXHist); fHistoList->Add(fkBarYHist); } //------------------Write to File---------------------------------------------- void PndDrcRecoLookupMap::WriteToFile() { fOutputName.Append(":/"); gDirectory->cd(fOutputName); //gDirectory->cd("13_t90_500ev_l0_oil_5_HIT.root:/"); gDirectory->mkdir("diff"); gDirectory->cd("diff"); for(int i=0; iWrite(); } gDirectory->cd("../"); gDirectory->mkdir("diffCut"); gDirectory->cd("diffCut"); for(int i=0; iWrite(); } gDirectory->cd("../"); gDirectory->mkdir("diffWeight"); gDirectory->cd("diffWeight"); for(int i=0; iWrite(); } gDirectory->cd("../"); gDirectory->mkdir("Nbounces"); gDirectory->cd("Nbounces"); for(int i=0; iWrite(); } gDirectory->cd("../"); TIter next(fHistoList); while ( TH1* histo = ((TH1*)next()) ) histo->Write(); } // ----- Finish Task --------------------------------------------------- void PndDrcRecoLookupMap::Finish() { cout << "-I- PndDrcRecoLookupMap: Finish" << endl; // creating a map in every pixel Double_t sig = 0., chr = 0.; TString hnam, num1, num2, num3; Float_t xx, yy; for(int i=0; iSetParameters(10.,-0.001,0.017,1.,1.); PhiThetaPoints[i]->Fit("fit","V",""); sig = fabs(fit->GetParameter(2)); chr = fit->GetParameter(1); hnam = PhiThetaPoints[i]->GetName(); //cout<<"hnam - "<Fill(xx, yy, chr); } /* // fill diff map with low value to avoid the background color for(Int_t i=0; iGetXaxis()->GetNbins(); i++){ for(Int_t j=0; jGetYaxis()->GetNbins(); j++){ if(fMapHist->GetBinContent(i+1,j+1) == 0.){ fMapHist->SetBinContent(i+1, j+1, -10.); } } } */ WriteToFile(); DrawHisto(); } //---------------------------------------------------------------- void PndDrcRecoLookupMap::DrawHisto() { gStyle->SetOptFit(0111); TCanvas *C1 = new TCanvas("C1","Time", 500,500); C1->Divide(1,2); C1->cd(1); fhPDTime->Draw(); C1->cd(2); fhRecoT1->Draw(); TCanvas *C2 = new TCanvas("C2","PD Plane", 500, 500); fhPDHits->SetMarkerStyle(20); fhPDHits->SetMarkerSize(0.25); //fhPDHits->SetMarkerColor(2); fhPDHits->Draw(); TCanvas *C3 = new TCanvas("C3","Diff", 500,500); fhDiff->GetXaxis()->SetTitle("[rad]"); fhDiff->SetLineWidth(3); fhDiff->Draw(); // C A N V A S W I T H M A P S (lambda and NEntries of pixels) TCanvas *C8= new TCanvas("C8","Nentries map",500,500); SetPlotStyle(); gStyle->SetOptStat(11); fMapHist->GetXaxis()->SetTitle("#Theta_{track} [degrees]"); fMapHist->GetYaxis()->SetTitle("#phi_{track} [degrees]"); fMapHist->GetZaxis()->SetTitle("nEntries"); //fMapHist->Draw("LEGO2Z"); fMapHist->Scale(0.05); fMapHist->Draw("COL2Z"); //DrawDetectorLayout(); //DrawBarBox(fBBver1,fBBver2,fBBver3,fBBver4); TCanvas *C9= new TCanvas("C9","Mean CHreco map",500,500); SetPlotStyle(); gStyle->SetOptStat(11); fCheHist->GetXaxis()->SetTitle("#theta track angle [degrees]"); fCheHist->GetYaxis()->SetTitle("#phi track angle [degrees]"); fCheHist->GetZaxis()->SetTitle(" [rad]"); //fCheHist->Draw("LEGO2Z"); fCheHist->Draw("COL2Z"); //DrawDetectorLayout(); //DrawBarBox(fBBver1,fBBver2,fBBver3,fBBver4); TCanvas *C10= new TCanvas("C10","Sigma map",500,500); SetPlotStyle(); gStyle->SetOptStat(11); //fSigHist->SetMinimum(-0.2); //fSigHist->SetMaximum(0.2); fSigHist->GetXaxis()->SetTitle("#theta track angle [degrees]"); fSigHist->GetYaxis()->SetTitle("#phi track angle [degrees]"); fSigHist->GetZaxis()->SetTitle("#sigma_{CHreco - CHexp}"); fSigHist->Draw("COL2Z"); //DrawDetectorLayout(); //DrawBarBox(fBBver1,fBBver2,fBBver3,fBBver4); TCanvas *C11= new TCanvas("C11","kBar LUT & kBar gen",500,500); C11->Divide(2,1); C11->cd(1); fkBarXHist->GetXaxis()->SetTitle("kxBar from LUT"); fkBarXHist->GetYaxis()->SetTitle("kxBar generated"); fkBarXHist->Draw(); TLine *l1 =new TLine(1.,1.,-1.,-1.); TLine *l2 = new TLine(-1.,1.,1.,-1.); l1->SetLineColor(8); l2->SetLineColor(8); l1->Draw("same"); l2->Draw("same"); C11->cd(2); fkBarYHist->GetXaxis()->SetTitle("kyBar from LUT"); fkBarYHist->GetYaxis()->SetTitle("kyBar generated"); fkBarYHist->Draw(); l1->Draw("same"); l2->Draw("same"); TCanvas *C12= new TCanvas("C12","Lam & CHreal",500,500); C12->Divide(1,2); C12->cd(1); fhCHreal->Draw(); C12->cd(2); fhLam->Draw(); } // ------------------------------------------------------------------------- ClassImp(PndDrcRecoLookupMap)