3 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
4 //*-- Copyright © ALICE HLT Group
6 /** \class AliL3Evaluate
8 //_____________________________________________________________
11 // Evaluation class for tracking; plots, efficiencies etc..
19 #include <TParticle.h>
21 #include <TClonesArray.h>
26 #include <AliSimDigits.h>
28 #include <AliTPCcluster.h>
29 #include <AliTPCClustersArray.h>
30 #include <AliTPCClustersRow.h>
31 #include <AliTPCParam.h>
32 #include <AliComplexCluster.h>
35 #include "AliL3StandardIncludes.h"
36 #include "AliL3Logging.h"
37 #include "AliL3Transform.h"
38 #include "AliL3SpacePointData.h"
39 #include "AliL3Track.h"
40 #include "AliL3FileHandler.h"
41 #include "AliL3TrackArray.h"
42 #include "AliL3Evaluate.h"
49 ClassImp(AliL3Evaluate)
51 AliL3Evaluate::AliL3Evaluate()
57 AliL3Evaluate::AliL3Evaluate(Char_t *datapath,Int_t minclusters,Int_t minhits,Double_t minpt,Double_t maxpt,Int_t *slice)
73 sprintf(fPath,"%s",datapath);
74 fMinPointsOnTrack = minclusters;
75 fMinHitsFromParticle = minhits;
80 AliL3Evaluate::~AliL3Evaluate()
83 if(fGoodTracks) delete[] fGoodTracks;
84 if(fTracks) delete fTracks;
85 if(fPtRes) delete fPtRes;
86 if(fNGoodTracksPt) delete fNGoodTracksPt;
87 if(fNFoundTracksPt) delete fNFoundTracksPt;
88 if(fNFakeTracksPt) delete fNFakeTracksPt;
89 if(fTrackEffPt) delete fTrackEffPt;
90 if(fFakeTrackEffPt) delete fFakeTrackEffPt;
91 if(fNGoodTracksEta) delete fNGoodTracksEta;
92 if(fNFoundTracksEta) delete fNFoundTracksEta;
93 if(fNFakeTracksEta) delete fNFakeTracksEta;
94 if(fTrackEffEta) delete fTrackEffEta;
95 if(fFakeTrackEffEta) delete fFakeTrackEffEta;
96 if(fMcIndex) delete [] fMcIndex;
97 if(fMcId) delete [] fMcId;
98 if(fNtuppel) delete fNtuppel;
99 if(fNtupleRes) delete fNtupleRes;
101 for(Int_t s=0; s<=35; s++)
102 for(Int_t p=0; p<6; p++)
104 //cout << s << " " << p <<endl;
105 if(fClustersFile[s][p]) delete fClustersFile[s][p];
110 void AliL3Evaluate::Clear()
123 fMinPointsOnTrack = 0;
124 fMinHitsFromParticle = 0;
126 fMaxFalseClusters = 0.1;
136 fNFoundTracksEta = 0;
139 fFakeTrackEffEta = 0;
142 fStandardComparison=kTRUE;
143 for(Int_t s=0; s<=35; s++)
144 for(Int_t p=0; p<6; p++){
146 fClustersFile[s][p]=0;
151 void AliL3Evaluate::LoadData(Int_t event,Bool_t sp)
153 //load cluster points
156 for(Int_t s=fMinSlice; s<=fMaxSlice; s++)
158 for(Int_t p=0; p<AliL3Transform::GetNPatches(); p++)
166 if(fClustersFile[s][p])
167 delete fClustersFile[s][p];
169 fClustersFile[s][p] = new AliL3FileHandler();
171 sprintf(fname,"%s/points_%d_%d.raw",fPath,s,patch);
173 sprintf(fname,"%s/points_%d_%d_%d.raw",fPath,event,s,patch);
174 if(!fClustersFile[s][p]->SetBinaryInput(fname))
176 LOG(AliL3Log::kError,"AliL3Evaluation::Setup","File Open")
177 <<"Inputfile "<<fname<<" does not exist"<<ENDLOG;
178 delete fClustersFile[s][p];
179 fClustersFile[s][p] = 0;
182 fClusters[s][p] = (AliL3SpacePointData*)fClustersFile[s][p]->Allocate();
183 fClustersFile[s][p]->Binary2Memory(fNcl[s][p],fClusters[s][p]);
184 fClustersFile[s][p]->CloseBinaryInput();
190 sprintf(fname,"%s/tracks_%d.raw",fPath,event);
191 AliL3FileHandler *tfile = new AliL3FileHandler();
192 if(!tfile->SetBinaryInput(fname)){
193 LOG(AliL3Log::kError,"AliL3Evaluation::Setup","File Open")
194 <<"Inputfile "<<fname<<" does not exist"<<ENDLOG;
199 fTracks = new AliL3TrackArray();
200 tfile->Binary2TrackArray(fTracks);
201 tfile->CloseBinaryInput();
206 void AliL3Evaluate::AssignPIDs()
211 LOG(AliL3Log::kDebug,"AliL3Evaluate::AssignPIDs","Track Loop")
212 <<"Assigning pid to the found tracks...."<<ENDLOG;
213 for(Int_t i=0; i<fTracks->GetNTracks(); i++)
215 AliL3Track *track = (AliL3Track*)fTracks->GetCheckedTrack(i);
217 if(track->GetNumberOfPoints() < fMinPointsOnTrack)
220 Float_t pid = GetTrackPID(track);
226 void AliL3Evaluate::AssignIDs()
228 //Assign MC id to the tracks.
230 cerr<<"AliL3Evaluate::AssignIDs() : You need to compile with the do_mc flag!"<<endl;
236 LOG(AliL3Log::kDebug,"AliL3Evaluate::AssignIDs","Track Loop")
237 <<"Assigning MC id to the found tracks...."<<ENDLOG;
238 for(Int_t i=0; i<fTracks->GetNTracks(); i++)
240 AliL3Track *track = (AliL3Track*)fTracks->GetCheckedTrack(i);
242 if(track->GetNumberOfPoints() < fMinPointsOnTrack) break;
245 Int_t tID = GetMCTrackLabel(track);
248 //cout<<"Found "<<fGoodFound<<" good tracks "<<endl;
252 Float_t AliL3Evaluate::GetTrackPID(AliL3Track *track)
255 track->CalculateHelix();
257 Int_t nc=track->GetNHits();
258 UInt_t *hits = track->GetHitNumbers();
259 Float_t sampleDEdx[159];
260 for (Int_t iHit = 0; iHit < nc; iHit++) {
261 UInt_t hitID = hits[iHit];
262 Int_t iSector = (hitID>>25) & 0x7f;
263 Int_t patch = (hitID>>22) & 0x7;
264 UInt_t position = hitID&0x3fffff;
265 AliL3SpacePointData *points = fClusters[iSector][patch];
266 if(!points) continue;
267 if(position>=fNcl[iSector][patch])
269 LOG(AliL3Log::kError,"AliL3Evaluate::GetMCTrackLabel","Clusterarray")
270 <<AliL3Log::kDec<<"ERROR"<<ENDLOG;
273 UChar_t padrow = points[position].fPadRow;
274 Float_t pWidth = AliL3Transform::GetPadPitchWidthLow();
276 pWidth = AliL3Transform::GetPadPitchWidthUp();
277 Float_t corr=1.; if (padrow>63) corr=0.67;
278 sampleDEdx[iHit] = points[position].fCharge/pWidth*corr;
279 Double_t crossingangle = track->GetCrossingAngle(padrow,iSector);
280 Double_t s = sin(crossingangle);
281 Double_t t = track->GetTgl();
282 sampleDEdx[iHit] *= sqrt((1-s*s)/(1+t*t));
287 Int_t swap;//stupid sorting
290 for (i=0; i<nc-1; i++) {
291 if (sampleDEdx[i]<=sampleDEdx[i+1]) continue;
292 Float_t tmp=sampleDEdx[i];
293 sampleDEdx[i]=sampleDEdx[i+1]; sampleDEdx[i+1]=tmp;
298 Double_t low=0.05; Double_t up=0.7;
299 Int_t nl=Int_t(low*nc), nu=Int_t(up*nc);
301 for (i=nl; i<=nu; i++) trackDEdx += sampleDEdx[i];
302 trackDEdx /= (nu-nl+1);
304 // cout<<" PID: "<<nc<<" "<<nl<<" "<<nu<<" "<<trackDEdx<<" "<<track->GetPt()<<endl;
309 Int_t AliL3Evaluate::GetMCTrackLabel(AliL3Track *track)
311 //Returns the MCtrackID of the belonging clusters.
312 //If MCLabel < 0, means that track is fake.
313 //Definitions are identical to offline.
315 // - more than 10 percent of clusters are assigned incorrectly
316 // - more than half of the innermost 10% of clusters were assigned incorrectly.
319 Int_t numofclusters = track->GetNumberOfPoints();
320 AliS *s=new AliS[numofclusters];
322 for (i=0; i<numofclusters; i++) s[i].flab=s[i].fmax=0;
323 UInt_t *hitnum = track->GetHitNumbers();
327 for (i=0; i<numofclusters; i++)
329 //Tricks to get the clusters belonging to this track:
331 Int_t slice = (id>>25) & 0x7f;
332 Int_t patch = (id>>22) & 0x7;
333 UInt_t pos = id&0x3fffff;
335 AliL3SpacePointData *points = fClusters[slice][patch];
336 if(!points) continue;
337 if(pos>=fNcl[slice][patch])
339 LOG(AliL3Log::kError,"AliL3Evaluate::GetMCTrackLabel","Clusterarray")
340 <<AliL3Log::kDec<<"ERROR"<<ENDLOG;
344 //Get the label of the cluster:
345 lab=points[pos].fTrackID[0];
348 for (j=0; j<numofclusters; j++)
349 if (s[j].flab==lab || s[j].fmax==0) break;
355 for (i=0; i<numofclusters; i++)
356 if (s[i].fmax>max) {max=s[i].fmax; lab=s[i].flab;}
359 return -1; //If most clusters is -1, this is a noise track.
361 cerr<<"AliL3Evaluate::GetMCTrackLabel : Track label negative :"<<lab<<endl;
365 for (i=0; i<numofclusters; i++)
368 Int_t slice = (id>>25) & 0x7f;
369 Int_t patch = (id>>22) & 0x7;
370 UInt_t pos = id&0x3fffff;
372 AliL3SpacePointData *points = fClusters[slice][patch];
373 if(!points) continue;
374 if(pos>=fNcl[slice][patch])
376 LOG(AliL3Log::kError,"AliL3Evaluate::GetMCTrackLabel","Clusterarray")
377 <<AliL3Log::kDec<<"ERROR"<<ENDLOG;
381 if (abs(points[pos].fTrackID[1]) == lab ||
382 abs(points[pos].fTrackID[2]) == lab ) max++;
386 //Check if more than 10% of the clusters were assigned incorrectly:
387 if (1.-Float_t(max)/numofclusters > fMaxFalseClusters)
391 else //Check if at least half of the 10% innermost clusters are assigned correctly.
393 Int_t tail=Int_t(0.10*numofclusters);
395 for (i=1; i<=tail; i++)
397 id = hitnum[numofclusters - i];
398 Int_t slice = (id>>25) & 0x7f;
399 Int_t patch = (id>>22) & 0x7;
400 UInt_t pos = id&0x3fffff;
402 AliL3SpacePointData *points = fClusters[slice][patch];
403 if(!points) continue;
404 if(lab == abs(points[pos].fTrackID[0]) ||
405 lab == abs(points[pos].fTrackID[1]) ||
406 lab == abs(points[pos].fTrackID[2])) max++;
408 if (max < Int_t(0.5*tail)) return -lab;
412 #else //If we are running with mc_ids or not
413 Int_t AliL3Evaluate::GetMCTrackLabel(AliL3Track */*track*/)
415 // Does nothing if do_mc undefined
421 void AliL3Evaluate::GetFastClusterIDs(Char_t *path)
423 //Get the MC id of space points in case of using the fast simulator.
425 sprintf(name,"%s/point_mc.dat",path);
426 FILE *infile = fopen(name,"r");
431 if(fscanf(infile,"%d %d",&hitid,&hitmc)==EOF) break;
434 fMcId = new Int_t[fNFastPoints];
435 fMcIndex = new UInt_t[fNFastPoints];
437 for(i=0; i<fNFastPoints; i++)
439 if(fscanf(infile,"%d %d",&hitid,&hitmc)==EOF) break;
446 void AliL3Evaluate::CreateHistos(Int_t nbin,Float_t xlow,Float_t xup)
448 //Create the histograms
450 LOG(AliL3Log::kInformational,"AliL3Evaluate::CreateHistos","Allocating")
451 <<"Creating histograms..."<<ENDLOG;
453 fNtuppel = new TNtuple("fNtuppel","Pt resolution","pt_gen:pt_found:nHits");
454 fNtuppel->SetDirectory(0);
455 fPtRes = new TH1F("fPtRes","Relative Pt resolution",30,-10.,10.);
456 fNGoodTracksPt = new TH1F("fNGoodTracksPt","Good tracks vs pt",nbin,xlow,xup);
457 fNFoundTracksPt = new TH1F("fNFoundTracksPt","Found tracks vs pt",nbin,xlow,xup);
458 fNFakeTracksPt = new TH1F("fNFakeTracksPt","Fake tracks vs pt",nbin,xlow,xup);
459 fTrackEffPt = new TH1F("fTrackEffPt","Tracking efficiency vs pt",nbin,xlow,xup);
460 fFakeTrackEffPt = new TH1F("fFakeTrackEffPt","Efficiency for fake tracks vs pt",nbin,xlow,xup);
462 fNGoodTracksEta = new TH1F("fNGoodTracksEta","Good tracks vs eta",20,-50,50);
463 fNFoundTracksEta = new TH1F("fNFoundTracksEta","Found tracks vs eta",20,-50,50);
464 fNFakeTracksEta = new TH1F("fNFakeTracksEta","Fake tracks vs eta",20,-50,50);
465 fTrackEffEta = new TH1F("fTrackEffEta","Tracking efficienct vs eta",20,-50,50);
466 fFakeTrackEffEta = new TH1F("fFakeTrackEffEta","Efficiency for fake tracks vs eta",20,-50,50);
470 void AliL3Evaluate::GetGoodParticles(Char_t *path,Int_t event,Int_t *padrowrange)
472 //Read the good particles from file. This file should already have been
473 //generated by macro AliTPCComparison.C.
475 Char_t filename[1024];
476 if(event<0 && !padrowrange)
477 sprintf(filename,"%s/good_tracks_tpc",path);
478 else if(event>=0 && !padrowrange)
479 sprintf(filename,"%s/good_tracks_tpc_%d",path,event);
481 sprintf(filename,"%s/good_tracks_tpc_%d_%d_%d",path,event,padrowrange[0],padrowrange[1]);
482 ifstream in(filename);
485 cerr<<"AliL3Evaluate::GetGoodParticles : Problems opening file :"<<filename<<endl;
488 Int_t MaxTracks=20000;
490 delete [] fGoodTracks;
492 fGoodTracks = new AliGoodTrack[MaxTracks];
494 if(fStandardComparison){
495 while (in>>fGoodTracks[fGoodGen].flabel>>fGoodTracks[fGoodGen].fcode>>
496 fGoodTracks[fGoodGen].fpx>>fGoodTracks[fGoodGen].fpy>>fGoodTracks[fGoodGen].fpz>>
497 fGoodTracks[fGoodGen].fx>>fGoodTracks[fGoodGen].fy>>fGoodTracks[fGoodGen].fz)
499 fGoodTracks[fGoodGen].fnhits=-1;
500 fGoodTracks[fGoodGen].fsector=-1;
502 if (fGoodGen==MaxTracks)
504 cerr<<"AliL3Evaluate::GetGoodParticles : Too many good tracks !\n";
509 while (in>>fGoodTracks[fGoodGen].flabel>>fGoodTracks[fGoodGen].fcode>>
510 fGoodTracks[fGoodGen].fpx>>fGoodTracks[fGoodGen].fpy>>fGoodTracks[fGoodGen].fpz>>
511 fGoodTracks[fGoodGen].fx>>fGoodTracks[fGoodGen].fy >>fGoodTracks[fGoodGen].fz>>
512 fGoodTracks[fGoodGen].fnhits>>fGoodTracks[fGoodGen].fsector)
515 if (fGoodGen==MaxTracks)
517 cerr<<"AliL3Evaluate::GetGoodParticles : Too many good tracks !\n";
524 void AliL3Evaluate::FillEffHistos()
526 //has to be modified for fakes.
530 cerr<<"AliL3Evaluate::FillEffHistos : No good tracks"<<endl;
535 //cout<<"Comparing "<<fGoodGen<<" good tracks ..."<<endl;
536 for(Int_t i=0; i<fGoodGen; i++)
538 //cout<<"Checking particle "<<i<<endl;
539 if(!fStandardComparison)
540 if(fGoodTracks[i].fnhits < fMinHitsFromParticle) continue;
541 Float_t ptg = TMath::Sqrt(fGoodTracks[i].fpx*fGoodTracks[i].fpx + fGoodTracks[i].fpy*fGoodTracks[i].fpy);
542 if(ptg < fMinGoodPt || ptg > fMaxGoodPt) continue;
543 Float_t pzg=fGoodTracks[i].fpz;
544 Float_t dipangle=TMath::ATan2(pzg,ptg)*180./TMath::Pi();
546 //If we are only considering tracks on one side of the TPC:
551 fNGoodTracksPt->Fill(ptg);
552 fNGoodTracksEta->Fill(dipangle);
555 for(Int_t k=0; k<fTracks->GetNTracks(); k++)
557 AliL3Track *track = fTracks->GetCheckedTrack(k);
559 Int_t nHits = track->GetNumberOfPoints();
560 if(nHits < fMinPointsOnTrack) break;
562 tracklabel = track->GetMCid();
564 if(TMath::Abs(tracklabel) != fGoodTracks[i].flabel) continue;
566 Float_t pt=track->GetPt();
567 if(tracklabel == fGoodTracks[i].flabel)
569 fNFoundTracksPt->Fill(ptg);
570 fNFoundTracksEta->Fill(dipangle);
571 fNtuppel->Fill(ptg,pt,nHits);
572 fPtRes->Fill((pt-ptg)/ptg*100.);
576 fNFakeTracksPt->Fill(ptg);
577 fNFakeTracksEta->Fill(dipangle);
579 //fPtRes->Fill((pt-ptg)/ptg*100.);
580 //fNtuppel->Fill(ptg,pt,nHits);
585 //cout<<"Track "<<fGoodTracks[i].label<<" was not found"<<endl;
589 void AliL3Evaluate::FillEffHistosNAIVE()
591 //Fill the efficiency histograms.
593 cout<<endl<<"Note: Doing NAIVE evaluation "<<endl;
594 for(Int_t i=0; i<fGoodGen; i++)
596 if(!fStandardComparison)
597 if(fGoodTracks[i].fnhits < fMinHitsFromParticle) continue;
598 Double_t ptg=TMath::Sqrt(fGoodTracks[i].fpx*fGoodTracks[i].fpx + fGoodTracks[i].fpy*fGoodTracks[i].fpy);
599 if(ptg < fMinGoodPt || ptg > fMaxGoodPt) continue;
600 Double_t pzg=fGoodTracks[i].fpz;
601 Float_t dipangle=TMath::ATan2(pzg,ptg)*180./TMath::Pi();
602 //printf("filling particle with pt %f and dipangle %f\n",ptg,dipangle);
603 fNGoodTracksPt->Fill(ptg);
604 fNGoodTracksEta->Fill(dipangle);
608 for(Int_t k=0; k<fTracks->GetNTracks(); k++)
610 AliL3Track *track = fTracks->GetCheckedTrack(k);
612 Int_t nHits = track->GetNumberOfPoints();
613 if(nHits < fMinPointsOnTrack) break;
614 if(track->GetPt()<fMinGoodPt || track->GetPt() > fMaxGoodPt) continue;
615 if(fabs(track->GetPseudoRapidity())>0.9) continue;
617 fNFoundTracksPt->Fill(track->GetPt()); fNFoundTracksEta->Fill(track->GetPseudoRapidity());
618 //Float_t pt=track->GetPt();
619 //fPtRes->Fill((pt-ptg)/ptg*100.);
620 //fNtuppel->Fill(ptg,pt,nHits);
624 void AliL3Evaluate::CalcEffHistos()
628 Stat_t ngood=fNGoodTracksPt->GetEntries();
629 Stat_t nfound=fNFoundTracksPt->GetEntries();
630 Stat_t nfake=fNFakeTracksPt->GetEntries();
632 LOG(AliL3Log::kInformational,"AliL3Evaluate::FillEffHistos","Efficiency")
633 <<AliL3Log::kDec<<"There was "<<ngood<<" generated good tracks"<<ENDLOG;
634 LOG(AliL3Log::kInformational,"AliL3Evaluate::FillEffHistos","Efficiency")
635 <<AliL3Log::kDec<<"Found "<<nfound<<" tracks"<<ENDLOG;
636 LOG(AliL3Log::kInformational,"AliL3Evaluate::FillEffHistos","Efficiency")
637 <<AliL3Log::kDec<<"Integral efficiency is about "<<nfound/ngood*100<<ENDLOG;
638 LOG(AliL3Log::kInformational,"AliL3Evaluate::FillEffHistos","Efficiency")
639 <<AliL3Log::kDec<<"Fake tracks relative is about "<<nfake/ngood*100<<ENDLOG;
640 //LOG(AliL3Log::kInformational,"AliL3Evaluate::FillEffHistos","Efficiency")
641 //<<AliL3Log::kDec<<"Naive efficiency "<<(Double_t)fGoodFound/(Double_t)fGoodGen<<ENDLOG;
643 fNFoundTracksPt->Sumw2(); fNGoodTracksPt->Sumw2();
644 fTrackEffPt->Divide(fNFoundTracksPt,fNGoodTracksPt,1,1.,"b");
645 fFakeTrackEffPt->Divide(fNFakeTracksPt,fNGoodTracksPt,1,1.,"b");
646 fTrackEffPt->SetMaximum(1.4);
647 fTrackEffPt->SetXTitle("P_{T} [GeV]");
648 fTrackEffPt->SetLineWidth(2);
649 fFakeTrackEffPt->SetFillStyle(3013);
650 fTrackEffPt->SetLineColor(4);
651 fFakeTrackEffPt->SetFillColor(2);
653 fNFoundTracksEta->Sumw2(); fNGoodTracksEta->Sumw2();
654 fTrackEffEta->Divide(fNFoundTracksEta,fNGoodTracksEta,1,1.,"b");
655 fFakeTrackEffEta->Divide(fNFakeTracksEta,fNGoodTracksEta,1,1.,"b");
656 fTrackEffEta->SetMaximum(1.4);
657 fTrackEffEta->SetXTitle("#lambda [degrees]");
658 fTrackEffEta->SetLineWidth(2);
659 fFakeTrackEffEta->SetFillStyle(3013);
660 fTrackEffEta->SetLineColor(4);
661 fFakeTrackEffEta->SetFillColor(2);
664 void AliL3Evaluate::Write2File(Char_t *outputfile)
666 //Write histograms to file:
668 TFile *of = TFile::Open(outputfile,"RECREATE");
671 LOG(AliL3Log::kError,"AliL3Evaluate::Write2File","File Open")
672 <<"Problems opening rootfile"<<ENDLOG;
679 fNGoodTracksPt->Write();
680 fNFoundTracksPt->Write();
681 fNFakeTracksPt->Write();
682 fTrackEffPt->Write();
683 fFakeTrackEffPt->Write();
684 fNGoodTracksEta->Write();
685 fNFoundTracksEta->Write();
686 fNFakeTracksEta->Write();
687 fTrackEffEta->Write();
688 fFakeTrackEffEta->Write();
693 TNtuple *AliL3Evaluate::GetNtuple()
698 fNtupleRes = new TNtuple("ntuppel","Residuals","residual_trans:residual_long:zHit:pt:dipangle:beta:padrow:nHits");
699 fNtupleRes->SetDirectory(0);//Bug in older version of root.
704 void AliL3Evaluate::CalculateResiduals()
706 //calculate residuals
707 TNtuple *ntuppel = GetNtuple();
709 for(Int_t i=0; i<fTracks->GetNTracks(); i++)
712 AliL3Track *track = (AliL3Track*)fTracks->GetCheckedTrack(i);
714 if(track->GetNHits() < fMinPointsOnTrack) break;
716 track->CalculateHelix();
717 UInt_t *hitnum = track->GetHitNumbers();
722 for(Int_t j=0; j<track->GetNumberOfPoints()-1; j++)
725 Int_t slice = (id>>25) & 0x7f;
726 Int_t patch = (id>>22) & 0x7;
727 UInt_t pos = id&0x3fffff;
729 //if(slice<18) continue;
731 AliL3SpacePointData *points = fClusters[slice][patch];
734 LOG(AliL3Log::kError,"AliL3Evaluate::CalculateResiduals","Clusterarray")
735 <<"No points at slice "<<slice<<" patch "<<patch<<" pos "<<pos<<ENDLOG;
738 if(pos>=fNcl[slice][patch])
740 LOG(AliL3Log::kError,"AliL3Evaluate::CalculateResiduals","Clusterarray")
741 <<AliL3Log::kDec<<"ERROR"<<ENDLOG;
745 xyz[0] = points[pos].fX;
746 xyz[1] = points[pos].fY;
747 xyz[2] = points[pos].fZ;
748 padrow = points[pos].fPadRow;
749 //AliL3Transform::Global2Local(xyz,slice,kTRUE);
750 AliL3Transform::Global2LocHLT(xyz,slice);
753 AliL3Transform::Local2GlobalAngle(&angle,slice);
754 if(!track->CalculateReferencePoint(angle,AliL3Transform::Row2X(padrow)))
756 LOG(AliL3Log::kError,"AliL3Evaluate::CalculateResiduals","Crossing point")
757 <<"Track does not crossing padrow "<<padrow<<" in slice "<<slice<<ENDLOG;
761 Float_t xyzcross[3] = {track->GetPointX(),track->GetPointY(),track->GetPointZ()};
762 //AliL3Transform::Global2Local(xyzcross,slice,kTRUE);
763 AliL3Transform::Global2LocHLT(xyzcross,slice);
765 Double_t beta = track->GetCrossingAngle(padrow,slice);
767 Double_t yres = xyzcross[1] - xyz[1];
768 Double_t zres = xyzcross[2] - xyz[2];
769 Double_t dipangle = atan(track->GetTgl());
770 ntuppel->Fill(yres,zres,xyzcross[2],track->GetPt(),dipangle,beta,padrow,track->GetNumberOfPoints());
776 enum tagprimary {kPrimaryCharged = 0x4000};
778 void AliL3Evaluate::EvaluatePoints(Char_t */*rootfile*/,Char_t */*exactfile*/,Char_t */*tofile*/,Int_t /*nevent*/,Bool_t /*offline*/,Bool_t /*sp*/)
780 // Does nothing if do_mc undefined
782 cerr<<"AliL3Evaluate::EvaluatePoints : Compile with do_mc flag!"<<endl;
785 void AliL3Evaluate::EvaluatePoints(Char_t *rootfile,Char_t *exactfile,Char_t *tofile,Int_t nevent,Bool_t offline,Bool_t sp)
787 //Compare points to the exact crossing points of track and padrows.
788 //The input file to this function, contains the exact clusters calculated
789 //in AliTPC::Hits2ExactClusters.
791 cout<<"Evaluating points"<<endl;
792 TNtuple *ntuppel = new TNtuple("ntuppel_res","Cluster properties",
793 "slice:padrow:charge:resy:resz:zHit:pt:beta:sigmaY2:sigmaZ2:psigmaY2:psigmaZ2");
794 ntuppel->SetDirectory(0);
796 TNtuple *ntuppel2 = new TNtuple("ntuppel_eff","Efficiency","slice:padrow:nfound:ngen");
797 ntuppel2->SetDirectory(0);
799 TFile *exfile = TFile::Open(rootfile);
802 cerr<<"Error opening rootfile "<<rootfile<<endl;
805 gAlice = (AliRun*)exfile->Get("gAlice");
808 LOG(AliL3Log::kError,"AliL3Evaluate::InitMC","gAlice")
809 <<"AliRun object non existing on file"<<ENDLOG;
813 AliTPCParam *param = (AliTPCParam*)exfile->Get(AliL3Transform::GetParamName());
815 TFile *exact = TFile::Open(exactfile);
818 cerr<<"AliL3Evaluate::EvaluatePoints : Problems opening file :"<<exactfile<<endl;
822 AliStack *astack=gAlice->Stack();
824 AliTPCClustersArray *arr=0;
825 for(Int_t event=0; event<nevent; event++)
831 Int_t nparticles = gAlice->GetEvent(event);
832 Int_t nprimaries = 0;//FindPrimaries(nparticles);
833 cout<<"Event "<<event<<" had "<<nparticles<<" particles and "<<nprimaries<<" primaries"<<endl;
836 //Get the exact clusters from file:
837 AliTPCClustersArray *arr = new AliTPCClustersArray;
839 arr->SetClusterType("AliComplexCluster");
841 sprintf(treeName,"TreeCExact_%s_%d",param->GetTitle(),event);
842 Bool_t clusterok = arr->ConnectTree(treeName);//Segment Tree (for offline clusters)
843 if(!clusterok) {printf("AliL3Evaluate::EvaluatePoints : Error in clusterloading\n"); return;}
845 //cout<<"Entering loop with "<<(Int_t)arr->GetTree()->GetEntries()<<endl;
846 for(Int_t i=0; i<arr->GetTree()->GetEntries(); i++)
848 //Get the exact clusters for this row:
850 AliSegmentID *s = arr->LoadEntry(i);
851 param->AdjustSectorRow(s->GetID(),cursec,currow);
853 AliTPCClustersRow *ro = (AliTPCClustersRow *)arr->GetRow(cursec,currow);
854 TClonesArray *clusters = ro->GetArray();
855 int numofoffline=clusters->GetEntriesFast();
857 //Get the found clusters:
859 AliL3Transform::Sector2Slice(slice,padrow,cursec,currow);
860 if(slice < fMinSlice) continue;
861 if(slice > fMaxSlice) break;
863 Int_t patch = AliL3Transform::GetPatch(padrow);
866 AliL3SpacePointData *points = fClusters[slice][patch];
870 //cout<<"Slice "<<slice<<" padrow "<<padrow<<" has "<<numofoffline<<" clusters "<<endl;
871 Int_t clustercount=0;
873 for(Int_t m=0; m<numofoffline; m++)
875 AliComplexCluster *cluster = (AliComplexCluster *)clusters->UncheckedAt(m);
877 Int_t mcId = cluster->GetTrack(0);
879 Int_t mcId = cluster->fTracks[0];
881 if(mcId <0) continue;
884 if(cluster->GetY() < 1 || cluster->GetY() > AliL3Transform::GetNPads(padrow) - 2 ||
885 cluster->GetX() < 1 || cluster->GetX() > AliL3Transform::GetNTimeBins() - 2)
888 if(cluster->fY < 1 || cluster->fY > AliL3Transform::GetNPads(padrow) - 2 ||
889 cluster->fX < 1 || cluster->fX > AliL3Transform::GetNTimeBins() - 2)
895 AliL3Transform::Raw2Local(xyzex,cursec,currow,cluster->GetY(),cluster->GetX());
897 AliL3Transform::Raw2Local(xyzex,cursec,currow,cluster->fY,cluster->fX);
899 //In function AliTPC::Hits2ExactClusters the time offset is not included,
900 //so we have to substract it again here.
902 xyzex[2]-=AliL3Transform::GetZOffset();
904 xyzex[2]+=AliL3Transform::GetZOffset();
907 if(param->GetPadRowRadii(cursec,currow)<230./250.*fabs(xyzex[2]))
910 TParticle *part = astack->Particle(mcId);
913 if(part->Pt() < fMinGoodPt) continue;
915 //Dont take secondaries, because in width calculation we assume primaries:
916 //if(!(part->TestBit(kPrimaryCharged))) continue;
917 if(part->GetFirstMother()>=0) continue;
920 for(UInt_t c=0; c<fNcl[slice][patch]; c++)
922 if((Int_t)points[c].fPadRow!=padrow) continue;
923 Float_t xyzcl[3] = {points[c].fX,points[c].fY,points[c].fZ};
926 AliL3Transform::Global2Local(xyzcl,cursec);
929 if(points[c].fTrackID[0] != mcId &&
930 points[c].fTrackID[1] != mcId &&
931 points[c].fTrackID[2] != mcId)
935 Float_t resy = xyzcl[1] - xyzex[1];
936 Float_t resz = xyzcl[2] - xyzex[2];
939 Int_t charge = (Int_t)points[c].fCharge;
940 Float_t beta = GetCrossingAngle(part,slice,padrow,xyzex);
941 Double_t tanl = xyzex[2]/sqrt(xyzex[0]*xyzex[0]+xyzex[1]*xyzex[1]);
942 Float_t psigmaY2 = AliL3Transform::GetParSigmaY2(padrow,xyzex[2],beta);
943 Float_t psigmaZ2 = AliL3Transform::GetParSigmaZ2(padrow,xyzex[2],tanl);
944 Float_t sigmaY2 = points[c].fSigmaY2;
945 Float_t sigmaZ2 = points[c].fSigmaZ2;
946 ntuppel->Fill(slice,padrow,charge,resy,resz,xyzex[2],part->Pt(),beta,sigmaY2,sigmaZ2,psigmaY2,psigmaZ2);
948 clustercount=tempcount;
950 ntuppel2->Fill(slice,padrow,clustercount,crosscount);
951 arr->ClearRow(cursec,currow);
957 TFile *ofile = TFile::Open(tofile,"RECREATE");
965 void AliL3Evaluate::GetCFeff(Char_t */*path*/,Char_t */*outfile*/,Int_t /*nevent*/,Bool_t /*sp*/)
967 // Does nothing if do_mc undefined
969 cerr<<"AliL3Evaluate::GetCFeff : Compile with do_mc flag"<<endl;
972 void AliL3Evaluate::GetCFeff(Char_t *path,Char_t *outfile,Int_t nevent,Bool_t sp)
974 //Evaluate the cluster finder efficiency.
976 TNtuple *ntuppel = new TNtuple("ntuppel","Cluster finder efficiency","slice:row:ncrossings:nclusters");
977 ntuppel->SetDirectory(0);
979 Char_t filename[1024];
980 sprintf(filename,"%s/alirunfile.root",path);
981 TFile *rfile = TFile::Open(filename);
982 gAlice = (AliRun*)rfile->Get("gAlice");
984 AliStack *astack=gAlice->Stack();
986 AliTPCParam *param = (AliTPCParam*)rfile->Get(AliL3Transform::GetParamName());
988 Int_t zero=param->GetZeroSup();
990 sprintf(filename,"%s/digitfile.root",path);
991 TFile *dfile = TFile::Open(filename);
993 for(Int_t event=0; event<nevent; event++)
997 gAlice->GetEvent(event);
998 Int_t np = astack->GetNtrack();
999 cout<<"Processing event "<<event<<" with "<<np<<" particles "<<endl;
1001 sprintf(filename,"TreeD_75x40_100x60_150x60_%d",event);
1002 TTree *TD=(TTree*)gDirectory->Get(filename);
1003 AliSimDigits da, *digits=&da;
1004 TD->GetBranch("Segment")->SetAddress(&digits);
1006 Int_t crossed=0,recs=0;
1007 Int_t *count = new Int_t[np]; //np number of particles.
1010 for (i=0; i<np; i++) count[i]=0;
1013 Int_t sec,row,sl,sr;
1014 for(Int_t i=0; i<(Int_t)TD->GetEntries(); i++)
1017 if (!TD->GetEvent(i)) continue;
1018 param->AdjustSectorRow(digits->GetID(),sec,row);
1019 AliL3Transform::Sector2Slice(sl,sr,sec,row);
1020 if(sl < fMinSlice) continue;
1021 if(sl > fMaxSlice) break;
1022 cout<<"Processing slice "<<sl<<" row "<<sr<<endl;
1025 Int_t it=digits->CurrentRow(), ip=digits->CurrentColumn();
1026 Short_t dig = digits->GetDigit(it,ip);
1028 if(dig<=param->GetZeroSup()) continue;
1029 AliL3Transform::Raw2Local(xyz,sec,row,ip,it);
1030 if(param->GetPadRowRadii(sec,row)<230./250.*fabs(xyz[2]))
1033 Int_t idx0=digits->GetTrackID(it,ip,0);
1034 Int_t idx1=digits->GetTrackID(it,ip,1);
1035 Int_t idx2=digits->GetTrackID(it,ip,2);
1037 if (idx0>=0 && dig>=zero) count[idx0]+=1;
1038 if (idx1>=0 && dig>=zero) count[idx1]+=1;
1039 if (idx2>=0 && dig>=zero) count[idx2]+=1;
1040 } while (digits->Next());
1041 for (Int_t j=0; j<np; j++)
1043 TParticle *part = astack->Particle(j);
1044 if(part->Pt() < fMinGoodPt) continue;
1045 if(part->GetFirstMother() >= 0) continue;
1046 if (count[j]>1) //at least two digits at this padrow
1053 Int_t patch = AliL3Transform::GetPatch(sr);
1056 AliL3SpacePointData *points = fClusters[sl][patch];
1059 for(UInt_t k=0; k<fNcl[sl][patch]; k++)
1061 if(points[k].fPadRow!=sr) continue;
1064 ntuppel->Fill(sl,sr,crossed,recs);
1070 TFile *file = TFile::Open(outfile,"RECREATE");
1079 Float_t AliL3Evaluate::GetCrossingAngle(TParticle *part,Int_t slice,Int_t /*padrow*/,Float_t *xyz)
1081 //Calculate the padrow crossing angle of the particle
1083 Double_t kappa = AliL3Transform::GetBField()*AliL3Transform::GetBFact()/part->Pt();
1085 Double_t radius = 1/fabs(kappa);
1086 if(part->GetPdgCode() > 0) kappa = -kappa;
1088 Float_t angl[1] = {part->Phi()};
1090 AliL3Transform::Global2LocalAngle(angl,slice);
1092 Double_t charge = -1.*kappa;
1094 Double_t trackPhi0 = angl[0] + charge*0.5*AliL3Transform::Pi()/fabs(charge);
1098 Double_t xc = x0 - radius * cos(trackPhi0);
1099 Double_t yc = y0 - radius * sin(trackPhi0);
1101 Double_t tangent[2];
1102 tangent[0] = -1.*(xyz[1] - yc)/radius;
1103 tangent[1] = (xyz[0] - xc)/radius;
1105 Double_t perppadrow[2] = {1,0}; //locally in slice
1107 Double_t cosbeta = fabs(tangent[0]*perppadrow[0] + tangent[1]*perppadrow[1]);
1108 if(cosbeta > 1) cosbeta=1;
1109 return acos(cosbeta);
1112 Int_t AliL3Evaluate::FindPrimaries(Int_t nparticles)
1115 Double_t vertcut = 0.001;
1116 Double_t decacut = 3.;
1117 Double_t timecut = 0.;
1119 AliStack *astack=gAlice->Stack();
1120 TParticle * part = astack->Particle(0);
1121 Double_t xori = part->Vx();
1122 Double_t yori = part->Vy();
1123 Double_t zori = part->Vz();
1124 for(Int_t iprim = 0; iprim<nparticles; iprim++){ //loop on tracks
1126 part = astack->Particle(iprim);
1127 const char * xxx=strstr(part->GetName(),"XXX");
1130 TParticlePDG *ppdg = part->GetPDG();
1131 if(TMath::Abs(ppdg->Charge())!=3)continue; // only charged (no quarks)
1133 Double_t dist=TMath::Sqrt((part->Vx()-xori)*(part->Vx()-xori)+(part->Vy()-yori)*(part->Vy()-yori)+(part->Vz()-zori)*(part->Vz()-zori));
1134 if(dist>vertcut)continue; // cut on the vertex
1136 if(part->T()>timecut)continue;
1138 Double_t ptot=TMath::Sqrt(part->Px()*part->Px()+part->Py()*part->Py()+part->Pz()*part->Pz());
1139 if(ptot==(TMath::Abs(part->Pz())))continue; // no beam particles
1141 Bool_t prmch = kTRUE; // candidate primary track
1142 Int_t fidau=part->GetFirstDaughter(); // cut on daughters
1146 lasdau=part->GetLastDaughter();
1147 ndau=lasdau-fidau+1;
1150 for(Int_t j=fidau;j<=lasdau;j++){
1151 TParticle *dau=astack->Particle(j);
1152 Double_t distd=TMath::Sqrt((dau->Vx()-xori)*(dau->Vx()-xori)+(dau->Vy()-yori)*(dau->Vy()-yori)+(dau->Vz()-zori)*(dau->Vz()-zori));
1153 if(distd<decacut)prmch=kFALSE; // eliminate if the decay is near the vertex
1159 part->SetBit(kPrimaryCharged);