10 #include "FairRootManager.h"
33 :FairTask(
"PndDrcReco",verbose),
fVerbose(verbose),
fOutFile(outFile),fLutFile(lutFile),fPdfFile(pdfFile){
40 cout <<
" ---------- INITIALIZATION ------------" << endl;
43 FairRootManager* ioman = FairRootManager::Instance();
45 cout <<
"-E- PndDrcReco::Init: " <<
"RootManager not instantiated!" << endl;
50 fMCArray = (TClonesArray*) ioman->GetObject(
"MCTrack");
52 cout <<
"-W- PndDrcReco::Init: " <<
"No MCTrack array!" << endl;
59 cout <<
"-W- PndDrcReco::Init: " <<
"No DrcBarPoint array!" << endl;
64 fEVPointArray = (TClonesArray*) ioman->GetObject(
"DrcEVPoint");
66 cout <<
"-W- PndDrcReco::Init: " <<
"No DrcEVPoint array!" << endl;
71 fPDPointArray = (TClonesArray*) ioman->GetObject(
"DrcPDPoint");
73 cout <<
"-W- PndDrcReco::Init: " <<
"No DrcPDPoint array!" << endl;
78 fPDHitArray = (TClonesArray*) ioman->GetObject(
"DrcPDHit");
80 cout <<
"-W- PndDrcReco::Init: " <<
"No DrcPDHit array!" << endl;
85 name.Remove(0,name.Last(
'/')+1);
90 for(Int_t l=0; l<5; l++){
91 fLut[l] =
new TClonesArray(
"PndDrcLutNode");
92 fTree->SetBranchAddress(Form(
"LUT%d",l),&
fLut[l]);
98 const Int_t maxpoints(150);
99 Double_t meanc2[maxpoints],spr2[maxpoints],meanc3[maxpoints],spr3[maxpoints];
101 name.Remove(name.Last(
'/')+1);
103 Long_t id,size,flags,modtime;
104 if(!gSystem->GetPathInfo((name+
"corrlut.root").Data(),&id,&size,&flags,&modtime)){
105 TFile *fc =
new TFile(name+
"corrlut.root");
106 TTree *tc = (TTree*)fc->Get(
"corrlut");
107 tc->SetBranchAddress(
"meanc2",&meanc2);
108 tc->SetBranchAddress(
"meanc3",&meanc3);
109 tc->SetBranchAddress(
"spr2",&spr2);
110 tc->SetBranchAddress(
"spr3",&spr3);
112 for (Int_t
i = 0;
i < tc->GetEntriesFast();
i++) {
114 for(Int_t j=0; j<145; j++){
125 for(Int_t
p=0;
p<5;
p++){
126 for(Int_t
m=0;
m<40;
m++){
127 for(Int_t
t=0;
t<120;
t++){
128 for(Int_t
i=0;
i<1100;
i++){
135 if(!gSystem->GetPathInfo(
fPdfFile.Data(),&id,&size,&flags,&modtime)){
137 TIter nextkey(fpdf.GetListOfKeys());
139 while ((key = (TKey*)nextkey())) {
140 TH1F *fun = (TH1F*)key->ReadObj();
142 sscanf(fun->GetName(),
"pdf_%d_%d_%d_%d", &
p,&
m,&
t,&
i);
144 fhPdf[
p][
m][
t][
i]->SetDirectory(0);
168 else fOutFile.ReplaceAll(
".root",
"t.root");
170 fTreeOut =
new TTree(
"barreldirc",
"SPR");
199 fHist =
new TH1F(
"cherenkov_angle_hist",
";#theta_{c} [rad];entries [#]", 100,0.6,0.9);
200 fFit =
new TF1(
"fgaus",
"[0]*exp(-0.5*((x-[1])/[2])*(x-[1])/[2]) + x*[3]+ [4]",0.35,0.85);
201 fSpect =
new TSpectrum(10);
203 fNx = TVector3(1,0,0);
204 fNy = TVector3(0,1,0);
207 Int_t pdg[]={11,13,211,321,2212};
208 Double_t mass[] = {0.000511,0.1056584,0.139570,0.49368,0.9382723};
211 gStyle->SetOptStat(1);
212 gStyle->SetOptTitle(1);
214 for(Int_t
i=0;
i<5;
i++){
225 fFunc[
i] =
new TF1(Form(
"f_%d",
i),
"gaus(0)",0.4,0.9);
227 fFunc[
i]->SetParameter(0,1);
228 fFunc[
i]->SetParameter(2,0.01);
230 if(
i==2)
fFunc[
i]->SetParameter(2,0.0095);
231 if(
i==3)
fFunc[
i]->SetParameter(2,0.0095);
233 fhLk1[
i] =
new TH1F(Form(
"fhLk1_%d",
i),
";ln L(K) - ln L(#pi);entries [#]",150,-400,400);
234 fhLk2[
i] =
new TH1F(Form(
"fhLk2_%d",
i),
";ln L(K) - ln L(#pi);entries [#]",150,-400,400);
235 fhTang[
i] =
new TH1F(Form(
"cherenkov_angle_hist_%d",
i),
";#theta_{c} [rad];entries [#]", 100,0.4,0.9);
237 fhDiff[
i] =
new TH1F(Form(
"fhDiff_%d",
i),
";t_{lut} - t_{daq} [ns];entries [#]",200,-10,10);
238 fhTime[
i] =
new TH1F(Form(
"fhTime_%d",
i),
";time [ns];entries [#]",200,0,100);
239 fhNph[
i] =
new TH1F(Form(
"fhNph_%d",
i),
";detected photons [#];entries [#]",150,0,150);
247 cout <<
"-I- PndDrcReco: Intialization successfull" << endl;
251 TH1F *
hEnergy =
new TH1F(
"hEnergy",
";p [eV];entries [#]",200,0,10);
252 TH1F *
hPathAll =
new TH1F(
"hPathAll",
";pathid [#];entries [#]",30,0,30);
253 TH1F *
hPath =
new TH1F(
"hPath",
";pathid [#];entries [#]",30,0,30);
254 TH2F *
hSD =
new TH2F(
"hSD",
";#theta_{c} [rad];t_{lut} - t_{daq} [ns]",200,0.8,0.85,200,-2,2);
261 if(
fVerbose>1) std::cout<<
"Event # "<<
nevents<<
" has "<<nHits<<
" hits."<< std::endl;
262 else if(
fVerbose==1 &&
nevents%100==0) std::cout<<
"Event # "<<
nevents<<
" has "<<nHits<<
" hits."<< std::endl;
264 for(Int_t itrack=0; itrack<
fMCArray->GetEntriesFast(); itrack++){
269 Int_t mcBoxId(-1), barId;
277 if(mcBoxId==-1)
continue;
296 fhLk1[2] =
new TH1F(
"fhLk1_2",
";ln L(K) - ln L(#pi);entries [#]",150,-100,100);
297 fhLk1[3] =
new TH1F(
"fhLk1_3",
";ln L(K) - ln L(#pi);entries [#]",150,-100,100);
300 fhLk2[2] =
new TH1F(
"fhLk2_2",
";ln L(K) - ln L(#pi);entries [#]",150,-100,100);
301 fhLk2[3] =
new TH1F(
"fhLk2_3",
";ln L(K) - ln L(#pi);entries [#]",150,-100,100);
316 for(Int_t
i=0;
i<5;
i++) {
322 Int_t momid=
fMom*10+0.5;
328 if(
c_spr[i][momid][thetaid]>0.003 &&
c_spr[i][momid][thetaid] < 0.1)
fFunc[
i]->SetParameter(2,
c_spr[i][momid][thetaid]);
338 Int_t pointID =
fPDHit->GetLink(1).GetIndex();
344 if(
fPDPoint->GetTrackID()<1)
continue;
361 gg_pathid += (vec.X()+vec.Y()*10 + vec.Z()*100)*1000*nev;
383 std::cout<<
"method 0 LK = "<<
fLikelihood[0] <<std::endl;
402 TCanvas*
c =
new TCanvas(
"c",
"c",0,0,800,600);
407 fFunc[2]->SetLineColor(kBlue);
408 fFunc[2]->Draw(
"same");
409 fFunc[3]->SetLineColor(kRed);
410 fFunc[3]->Draw(
"same");
412 TLine *line =
new TLine(0,0,0,1000);
415 line->SetY1(gPad->GetUymin());
416 line->SetY2(
fHist->GetMaximum()*1.05);
417 line->SetLineColor(kBlue);
420 TLine *line1 =
new TLine(0,0,0,1000);
423 line1->SetY1(gPad->GetUymin());
424 line1->SetY2(
fHist->GetMaximum()*1.05);
425 line1->SetLineColor(kRed);
451 for(
int i=0;
i<size;
i++){
462 for(
int u=0; u<4; u++){
463 if(u == 0) dir = dird;
464 if(u == 1) dir.SetXYZ(-dird.X(), dird.Y(), dird.Z());
465 if(u == 2) dir.SetXYZ( dird.X(),-dird.Y(), dird.Z());
466 if(u == 3) dir.SetXYZ(-dird.X(),-dird.Y(), dird.Z());
467 if(
fReflected) dir.SetXYZ( dir.X(), dir.Y(),-dir.Z());
471 luttheta = dir.Theta();
473 luttime =
fLenz/
cos(luttheta)/19.8 + evtime;
485 Int_t momid=
fMom*10+0.5;
491 if(tangle < 0.4 || tangle > 0.9)
continue;
496 if(
fabs(tdiff)>1.0)
continue;
501 hSD->Fill(tangle,tdiff);
516 Int_t momid=
fMom*10+0.5;
521 if(
fhPdf[2][momid][thetaid][sensorId] &&
fhPdf[3][momid][thetaid][sensorId]){
535 if(startPhi < 0) startPhi = 360 + startPhi;
536 if(startPhi >= 0 && startPhi < 90) boxPhi = TMath::Floor(startPhi/
fDphi) *
fDphi +
fDphi/2.;
545 if(barId>4 || barId<0){
546 std::cout<<
"Error in PndDrcReco: Bar Id is wrong. barId = "<< barId <<std::endl;
554 if(
fHist->Integral()>20 ){
555 TCanvas*
c =
new TCanvas(
"c",
"c",0,0,800,600);
557 Float_t *xpeaks = (Float_t*)
fSpect->GetPositionX();
558 if(nfound>0) cherenkovreco = xpeaks[0];
559 fFit->SetParameter(1,cherenkovreco);
560 fFit->SetParameter(2,0.01);
561 fHist->Fit(
"fgaus",
"Q",
"",cherenkovreco-0.02,cherenkovreco+0.02);
562 cherenkovreco =
fFit->GetParameter(1);
563 std::cout<<
"sigma "<<
fFit->GetParameter(2) <<std::endl;
565 if(cherenkovreco<0 || cherenkovreco>1 ) cherenkovreco = 0;
577 return cherenkovreco;
583 for(Int_t
i=0;
i<5;
i++){
601 gSystem->mkdir(path,kTRUE);
602 while((c = (TCanvas*)
next())){
604 TCanvas *cc =
new TCanvas(name+
"exp",
"cExport",0,0,800,400);
605 cc = (TCanvas*) c->DrawClone();
606 cc->SetCanvasSize(800,400);
607 cc->SetBottomMargin(0.12);
608 TIter nexth(cc->GetListOfPrimitives());
610 while((obj = nexth())){
611 if(obj->InheritsFrom(
"TH1")){
612 TH1F *
hh = (TH1F*)obj;
613 hh->GetXaxis()->SetTitleSize(0.06);
614 hh->GetYaxis()->SetTitleSize(0.06);
616 hh->GetXaxis()->SetLabelSize(0.05);
617 hh->GetYaxis()->SetLabelSize(0.05);
619 hh->GetXaxis()->SetTitleOffset(0.85);
620 hh->GetYaxis()->SetTitleOffset(0.85);
628 path= tname.Remove(
fOutFile.Last(
'/')) +
"/";
630 uid=tname.Remove(0,
fOutFile.Last(
'/')+1);
632 cc->Print(path+uid+name+
".png");
644 Int_t id_mom =
fMom/step_mom+0.1;
645 Int_t id_theta =
fTheta/step_theta+0.2;
646 Int_t id_phi =
fPhi/step_phi+0.2;
647 TString strrun=Form(
"_%d_%d_%d",id_mom,id_theta,id_phi);
654 if(
fhLk1[2]->Integral()>10){
655 fhLk1[2]->Fit(
"gaus",
"S");
656 ff =
fhLk1[2]->GetFunction(
"gaus");
657 m1=ff->GetParameter(1);
658 s1=ff->GetParameter(2);
660 if(
fhLk1[3]->Integral()>10){
661 fhLk1[3]->Fit(
"gaus",
"S");
662 ff =
fhLk1[3]->GetFunction(
"gaus");
663 m2=ff->GetParameter(1);
664 s2=ff->GetParameter(2);
668 std::cout<<
"separation1 "<<
fSeparation[0] <<std::endl;
671 fhLk1[2]->SetLineColor(4);
672 fhLk1[3]->SetLineColor(2);
674 fhLk1[3]->Draw(
"same");
677 fhDiff[2]->SetLineColor(4);
679 fhDiff[3]->SetLineColor(2);
684 hPath->SetLineColor(2);
688 for(Int_t
i=2;
i<4;
i++){
690 fFit->SetParameter(2,0.01);
691 if(
fhTang[i]->Integral()>10){
700 fhTang[2]->SetLineColor(4);
703 fhTang[3]->SetLineColor(2);
706 TLine *line =
new TLine(0,0,0,1000);
709 line->SetY1(gPad->GetUymin());
710 line->SetY2(
fhTang[2]->GetMaximum()*1.05);
711 line->SetLineColor(kBlue);
714 TLine *line1 =
new TLine(0,0,0,1000);
717 line1->SetY1(gPad->GetUymin());
718 line1->SetY2(
fhTang[2]->GetMaximum()*1.05);
719 line1->SetLineColor(kRed);
727 if(
fhLk2[2]->Integral()>10){
728 fhLk2[2]->Fit(
"gaus",
"S");
729 ff =
fhLk2[2]->GetFunction(
"gaus");
730 m1=ff->GetParameter(1);
731 s1=ff->GetParameter(2);
733 if(
fhLk2[3]->Integral()>10){
734 fhLk2[3]->Fit(
"gaus",
"S");
735 ff =
fhLk2[3]->GetFunction(
"gaus");
736 m2=ff->GetParameter(1);
737 s2=ff->GetParameter(2);
741 std::cout<<
"separation2 "<<
fSeparation[1] <<std::endl;
744 fhLk2[2]->SetLineColor(4);
745 fhLk2[3]->SetLineColor(2);
747 fhLk2[3]->Draw(
"same");
751 fhTime[2]->SetLineColor(4);
753 fhTime[3]->SetLineColor(2);
770 fhNph[2]->SetLineColor(4);
772 fhNph[3]->SetLineColor(2);
773 fhNph[3]->Draw(
"same");
778 for(Int_t l=0; l<5; l++)
fLut[l]->Clear();
779 for(Int_t
i=0;
i<5;
i++){
786 std::cout<<
"N pi "<<
fNph[2] <<
" N K " <<
fNph[3] <<std::endl;
799 cout <<
"-I- PndDrcReco: Finish" << endl;
friend F32vec4 acos(const F32vec4 &a)
Int_t FindPdg(Double_t mom, Double_t cangle)
friend F32vec4 cos(const F32vec4 &a)
virtual InitStatus Init()
PndDrcBarPoint * fBarPoint
Int_t GetPathId(Int_t entry)
Double_t c_spr[5][50][150]
TClonesArray * fPDHitArray
void CanvasSave(TString path="data/reco")
friend F32vec4 sqrt(const F32vec4 &a)
TVector3 GetMomentum() const
void DetermineBarId(Double_t &boxPhi, Int_t &barId)
TClonesArray * fBarPointArray
void DetermineCherenkov(Int_t boxId, Int_t barId)
Double_t GetPath(Int_t entry)
Int_t fParticleArray[3000]
virtual Double_t GetTime()
Int_t GetBarPointID() const
int uid(int lev, int lrun, int lmode)
TString m2(TString pts, TString exts="e px py pz")
TH1F * fhPdf[5][40][120][1100]
Double_t c_mean[5][50][150]
void LookUpTable(Int_t barId, Int_t sensorId)
virtual void Exec(Option_t *option)
friend F32vec4 fabs(const F32vec4 &a)
void CanvasAdd(TString name="c", Int_t w=800, Int_t h=400)
TVector3 GetEntry(Int_t entry)
Double_t GetTime(Int_t entry)
TClonesArray * fPDPointArray
Int_t GetMotherID() const
cout<<"the Event No is "<< i<< endl;{{if(hit_array->GetEntriesFast()!=mc_array->GetEntriesFast()) continue;PndSdsHit *hit=(PndSdsHit *) hit_array-> At(j)
TClonesArray * fEVPointArray
void TimeImaging(Int_t sensorId)