1 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
2 //*-- Copyright © ASV
11 #include <TClonesArray.h>
14 #include "AliSimDigits.h"
16 #include "AliTPCClustersArray.h"
17 #include "AliTPCClustersRow.h"
18 #include "AliTPCcluster.h"
19 #include "AliTPCParam.h"
20 #include "AliComplexCluster.h"
22 #include "AliL3Defs.h"
23 #include "AliL3Transform.h"
24 #include "AliL3SpacePointData.h"
25 #include "AliL3Track.h"
26 #include "AliL3FileHandler.h"
27 #include "AliL3TrackArray.h"
28 #include "AliL3Evaluate.h"
29 #include "AliL3Logging.h"
31 //_____________________________________________________________
34 // Evaluation class for tracking. Plots efficiencies etc..
36 ClassImp(AliL3Evaluate)
38 AliL3Evaluate::AliL3Evaluate()
42 fMCclusterfile = NULL;
48 fTransform = new AliL3Transform();
51 AliL3Evaluate::AliL3Evaluate(Char_t *mcfile,Int_t *slice)
53 //Normal constructor. Input are the rootfile containing the
54 //original MC information of the simulated event.
56 fEventFile = new TFile(mcfile,"READ");
58 fParam = (AliTPCParam*)fEventFile->Get("75x40_100x60");
59 fTransform = new AliL3Transform();
67 AliL3Evaluate::AliL3Evaluate(Int_t *slice)
69 //ctor to use if you do not need any rootfile.
74 fTransform = new AliL3Transform();
78 AliL3Evaluate::~AliL3Evaluate()
80 if(fDigitsTree) fDigitsTree->Delete();
85 if(fTransform) delete fTransform;
86 if(fTracks) delete fTracks;
87 if(fPtRes) delete fPtRes;
88 if(fNGoodTracksPt) delete fNGoodTracksPt;
89 if(fNFoundTracksPt) delete fNFoundTracksPt;
90 if(fNFakeTracksPt) delete fNFakeTracksPt;
91 if(fTrackEffPt) delete fTrackEffPt;
92 if(fFakeTrackEffPt) delete fFakeTrackEffPt;
93 if(fNGoodTracksEta) delete fNGoodTracksEta;
94 if(fNFoundTracksEta) delete fNFoundTracksEta;
95 if(fNFakeTracksEta) delete fNFakeTracksEta;
96 if(fTrackEffEta) delete fTrackEffEta;
97 if(fFakeTrackEffEta) delete fFakeTrackEffEta;
98 if(fMcIndex) delete [] fMcIndex;
99 if(fMcId) delete [] fMcId;
100 if(fNtuppel) delete fNtuppel;
103 void AliL3Evaluate::Setup(Char_t *trackfile,Char_t *path)
105 //Read in the hit and track information from produced files.
110 AliL3FileHandler *clusterfile[36][6];
111 for(Int_t s=fMinSlice; s<=fMaxSlice; s++)
113 for(Int_t p=0; p<6; p++)
116 clusterfile[s][p] = new AliL3FileHandler();
117 sprintf(fname,"%s/points_%d_%d.raw",path,s,p);
118 if(!clusterfile[s][p]->SetBinaryInput(fname))
120 LOG(AliL3Log::kError,"AliL3Evaluation::Setup","File Open")
121 <<"Inputfile "<<fname<<" does not exist"<<ENDLOG;
122 delete clusterfile[s][p];
123 clusterfile[s][p] = 0;
126 fClusters[s][p] = (AliL3SpacePointData*)clusterfile[s][p]->Allocate();
127 clusterfile[s][p]->Binary2Memory(fNcl[s][p],fClusters[s][p]);
128 clusterfile[s][p]->CloseBinaryInput();
133 AliL3FileHandler *tfile = new AliL3FileHandler();
134 if(!tfile->SetBinaryInput(trackfile)){
135 LOG(AliL3Log::kError,"AliL3Evaluation::Setup","File Open")
136 <<"Inputfile "<<trackfile<<" does not exist"<<ENDLOG;
139 fTracks = new AliL3TrackArray();
140 tfile->Binary2TrackArray(fTracks);
141 tfile->CloseBinaryInput();
145 void AliL3Evaluate::SetupSlow(Char_t *trackfile,Char_t *digitsfile,Char_t *path)
147 //Setup for using the slow simulator.
149 fDigitsFile = new TFile(digitsfile,"READ");
150 if(!fDigitsFile->IsOpen())
152 LOG(AliL3Log::kError,"AliL3Evaluate::SetupSlow","File Open")
153 <<"Inputfile "<<digitsfile<<" does not exist"<<ENDLOG;
157 Setup(trackfile,path);
160 LOG(AliL3Log::kError,"AliL3Evaluation::SetupSlow","Digits Tree")
161 <<"Error setting up digits tree"<<ENDLOG;
165 void AliL3Evaluate::SetupFast(Char_t *trackfile,Char_t *mcClusterfile,Char_t *path)
167 //Setup for using the fast simulator.
170 GetFastClusterIDs(path);
172 fMCclusterfile = new TFile(mcClusterfile);
173 if(!fMCclusterfile->IsOpen())
174 LOG(AliL3Log::kError,"AliL3Evaluation::SetupFast","File Open")
175 <<"Inputfile "<<mcClusterfile<<" does not exist"<<ENDLOG;
177 Setup(trackfile,path);
181 Bool_t AliL3Evaluate::InitMC()
186 fDigitsTree = (TTree*)fDigitsFile->Get("TreeD_75x40_100x60_0");
189 LOG(AliL3Log::kError,"AliL3Evaluate::InitMC","Digits Tree")
190 <<AliL3Log::kHex<<"Error getting digitstree "<<(Int_t)fDigitsTree<<ENDLOG;
193 fDigitsTree->GetBranch("Segment")->SetAddress(&fDigits);
194 for(Int_t i=0; i<fDigitsTree->GetEntries(); i++)
196 if(!fDigitsTree->GetEvent(i)) continue;
197 Int_t se,ro,slice,slicerow;
198 fParam->AdjustSectorRow(fDigits->GetID(),se,ro);
199 fTransform->Sector2Slice(slice,slicerow,se,ro);
200 fRowid[slice][slicerow] = i;
205 gAlice = (AliRun*)fEventFile->Get("gAlice");
208 LOG(AliL3Log::kError,"AliL3Evaluate::InitMC","gAlice")
209 <<"AliRun object non existing on file"<<ENDLOG;
221 void AliL3Evaluate::DefineGoodTracks(Int_t *slice,Int_t *padrow,Int_t good_number,Char_t *fname)
223 //Loop over MC particles, and mark the good ones
224 //(which the tracker should find...)
230 LOG(AliL3Log::kInformational,"AliL3Evaluate::DefineGoodTracks","infile")
231 <<"Reading good particles from file "<<fname<<ENDLOG;
232 while (in>>fGoodTracks[fGoodGen].label>>fGoodTracks[fGoodGen].code>>
233 fGoodTracks[fGoodGen].px>>fGoodTracks[fGoodGen].py>>fGoodTracks[fGoodGen].pz>>
234 fGoodTracks[fGoodGen].pt)
239 LOG(AliL3Log::kWarning,"AliL3Evaluate::DefineGoodTracks","fGoodGen")
240 <<"Too many good tracks"<<ENDLOG;
244 if (!in.eof()) cerr<<"Read error (good_tracks_tpc) !\n";
249 AliTPC *TPC = (AliTPC*)gAlice->GetDetector("TPC");
251 TPC->SetParam(fParam);
253 Int_t ver = TPC->IsVersion();
254 LOG(AliL3Log::kInformational,"AliL3Evaluate::DefineGoodTracks","TPC version")
255 <<"TPC version "<<ver<<" found on file"<<ENDLOG;
257 Int_t zero=TPC->GetParam()->GetZeroSup();
259 Int_t np = gAlice->GetNtrack();
260 Int_t *good = new Int_t[np];
261 for(Int_t ii=0; ii<np; ii++)
267 LOG(AliL3Log::kError,"AliL3Evaluate::DefineGoodTracks","TPC version")
268 <<"TPC version "<<ver<<" does not match."<<ENDLOG;
269 fMCclusterfile->cd();
270 AliTPCClustersArray carray;
271 carray.Setup(fParam);
272 carray.SetClusterType("AliTPCcluster");
275 sprintf(cname,"TreeC_TPC_%d",eventn);
276 Bool_t clusterok = carray.ConnectTree(cname);
278 LOG(AliL3Log::kError,"AliL3Evaluate::DefineGoodTracks","Cluster Array")
279 <<"Error loading clusters from rootfile"<<ENDLOG;
281 for(Int_t i=0; i<carray.GetTree()->GetEntries(); i++)
284 AliSegmentID *s = carray.LoadEntry(i);
285 fParam->AdjustSectorRow(s->GetID(),sec,row);
286 fTransform->Sector2Slice(sl,lr,sec,row);
288 if(sl != slice[0]) {carray.ClearRow(sec,row); continue;}
289 if(lr < padrow[0]) {carray.ClearRow(sec,row); continue;}
290 if(lr > padrow[1]) {carray.ClearRow(sec,row); continue;}
291 AliTPCClustersRow *cRow = carray.GetRow(sec,row);
292 for(Int_t j=0; j<cRow->GetArray()->GetEntriesFast(); j++)
294 AliTPCcluster *cluster=(AliTPCcluster*)(*cRow)[j];
295 Int_t lab=cluster->GetLabel(0);
300 if(carray.GetRow(sec,row))
301 carray.ClearRow(sec,row);
307 LOG(AliL3Log::kError,"AliL3Evaluate::DefineGoodTracks","TPC version")
308 <<"TPC version "<<ver<<" does not match."<<ENDLOG;
309 Int_t *count = new Int_t[np]; //np number of particles.
312 for (i=0; i<np; i++) count[i]=0;
313 for(Int_t sl=slice[0]; sl<=slice[1]; sl++)
315 for (i=padrow[0]; i<=padrow[1]; i++) {
316 Int_t index = fRowid[sl][i];
317 if (!fDigitsTree->GetEvent(index)) continue;
319 fParam->AdjustSectorRow(fDigits->GetID(),sec,row);
322 Int_t it=fDigits->CurrentRow(), ip=fDigits->CurrentColumn();
323 Short_t dig = fDigits->GetDigit(it,ip);
325 if(dig<=fParam->GetZeroSup()) continue;
326 if(it < fParam->GetMaxTBin()-1 && it > 0)
327 if(fDigits->GetDigit(it+1,ip) <= fParam->GetZeroSup()
328 && fDigits->GetDigit(it-1,ip) <= fParam->GetZeroSup())
331 fTransform->Raw2Local(xyz,sec,row,ip,it);
332 if(fParam->GetPadRowRadii(sec,row)<230./250.*fabs(xyz[2]))
335 Int_t idx0=fDigits->GetTrackID(it,ip,0);
336 Int_t idx1=fDigits->GetTrackID(it,ip,1);
337 Int_t idx2=fDigits->GetTrackID(it,ip,2);
339 if (idx0>=0 && dig>=zero) count[idx0]+=1;
340 if (idx1>=0 && dig>=zero) count[idx1]+=1;
341 if (idx2>=0 && dig>=zero) count[idx2]+=1;
342 } while (fDigits->Next());
344 for (Int_t j=0; j<np; j++)
346 if (count[j]>1) //at least two digits at this padrow
358 LOG(AliL3Log::kError,"AliL3Evaluation::FillEffHistos","TPC version")
359 <<"No valid TPC version found"<<ENDLOG;
364 //The following code has been taken from offlinemacro->AliTPCComparison.C
366 TTree *TH=gAlice->TreeH();
367 Int_t npart=(Int_t)TH->GetEntries();
374 AliTPChit * hit = (AliTPChit*) TPC->FirstHit(-1);
376 if (hit->fQ==0.) break;
377 hit = (AliTPChit*) TPC->NextHit();
380 hit0 = new AliTPChit(*hit); //Make copy of hit
384 AliTPChit *hit1=(AliTPChit*)TPC->NextHit();
385 if (hit1==0) continue;
386 if (hit1->fQ != 0.) continue;
387 Int_t i=hit->Track();
388 TParticle *p = (TParticle*)gAlice->Particle(i);
390 //printf("Checking particle %d with code %d\n",i,p->GetPdgCode());
391 if (p->GetFirstMother()>=0) continue; //secondary particle
392 if (good[i] < good_number || good[i]>176) continue;
393 if (p->Pt()<fMinGoodPt) continue;
394 if (TMath::Abs(p->Pz()/p->Pt())>0.999) continue;
395 printf("Found good particle %d, nHits %d\n",i,good[i]);
397 fGoodTracks[fGoodGen].label=i;
398 fGoodTracks[fGoodGen].code=p->GetPdgCode();
399 //**** px py pz - in global coordinate system, x y z - in local !
400 fGoodTracks[fGoodGen].px=hit->X(); fGoodTracks[fGoodGen].py=hit->Y(); fGoodTracks[fGoodGen].pz=hit->Z();
401 fGoodTracks[fGoodGen].pt = p->Pt();
404 if (hit0) delete hit0;
405 if (fGoodGen==max) {cerr<<"Too many good tracks !n"; break;}
410 LOG(AliL3Log::kInformational,"AliL3Evaluate::DefineGoodParticles","Eval")
411 <<AliL3Log::kDec<<"Found "<<fGoodGen<<"good tracks"<<ENDLOG;
416 for (Int_t ngd=0; ngd<fGoodGen; ngd++)
417 out<<fGoodTracks[ngd].label<<' '<<fGoodTracks[ngd].code<<' '<<
418 fGoodTracks[ngd].px<<' '<<fGoodTracks[ngd].py<<' '<<fGoodTracks[ngd].pz<<' '<<
419 fGoodTracks[ngd].pt<<endl;
423 LOG(AliL3Log::kError,"AliL3Evaluate::DefineGoodParticles","file")
424 <<"Can not open file containing good tracks"<<ENDLOG;
430 void AliL3Evaluate::EvaluatePatch(Int_t slice,Int_t patch,Int_t min_points,Int_t good_number)
432 //Make efficiency plots for tracking on patch level (before any merging).
434 Int_t row[6][2] = {{ 0, 45},{46,77},{78,109},{110,141},{142,175}};
435 Int_t sl[2] ={slice,slice};
436 DefineGoodTracks(sl,row[patch],good_number);
437 SetMinPoints(min_points);
444 void AliL3Evaluate::EvaluateSlice(Int_t slice,Int_t min_points,Int_t good_number)
446 //Make efficiency plots for tracking on a slice (after merging).
447 //min_points = minimum points on track to be considered for evaluation
448 //good_number = minimum hits (padrows) produced by simulated track for consideration.
450 Int_t row[2] = {0,175};
451 Int_t sl[2] ={slice,slice};
452 DefineGoodTracks(sl,row,good_number);
454 SetMinPoints(min_points);
462 void AliL3Evaluate::EvaluateGlobal(Int_t min_points,Int_t good_number,Char_t *fname)
464 //Make efficiency plots for tracking on several slices.
466 Int_t row[2] = {0,175};
467 SetMinPoints(min_points);
468 Int_t slice[2] = {fMinSlice,fMaxSlice};
469 DefineGoodTracks(slice,row,good_number,fname);
472 printf("filling histos\n");
474 printf("done fillling\n");
478 void AliL3Evaluate::AssignIDs()
480 //Assign MC id to the tracks.
483 LOG(AliL3Log::kDebug,"AliL3Evaluate::AssignIDs","Track Loop")
484 <<"Assigning MC id to the found tracks...."<<ENDLOG;
485 for(Int_t i=0; i<fTracks->GetNTracks(); i++)
487 AliL3Track *track = (AliL3Track*)fTracks->GetCheckedTrack(i);
489 if(track->GetNumberOfPoints() < fMinPointsOnTrack) break;
492 Int_t tID = GetMCTrackLabel(track);
494 printf("track %i id %d nHits %d\n",i,tID,track->GetNumberOfPoints());
499 struct S {Int_t lab; Int_t max;};
500 Int_t AliL3Evaluate::GetMCTrackLabel(AliL3Track *track){
501 //Returns the MCtrackID of the belonging clusters.
502 //If MCLabel < 0, means that track is fake.
503 //Fake track means that more than 10 percent of clusters are assigned incorrectly.
505 Int_t num_of_clusters = track->GetNumberOfPoints();
506 S *s=new S[num_of_clusters];
508 for (i=0; i<num_of_clusters; i++) s[i].lab=s[i].max=0;
509 UInt_t *hitnum = track->GetHitNumbers();
512 //Int_t **trackID = GetClusterIDs(track);
515 for (i=0; i<num_of_clusters; i++)
517 //Tricks to get the clusters belonging to this track:
519 Int_t slice = (id>>25) & 0x7f;
520 Int_t patch = (id>>22) & 0x7;
521 UInt_t pos = id&0x3fffff;
523 AliL3SpacePointData *points = fClusters[slice][patch];
524 if(!points) continue;
525 if(pos>=fNcl[slice][patch])
527 LOG(AliL3Log::kError,"AliL3Evaluate::GetMCTrackLabel","Clusterarray")
528 <<AliL3Log::kDec<<"ERROR"<<ENDLOG;
532 //Get the label of the cluster:
534 lab=abs(points[pos].fTrackID[0]);
536 for (j=0; j<num_of_clusters; j++)
537 if (s[j].lab==lab || s[j].max==0) break;
543 for (i=0; i<num_of_clusters; i++)
544 if (s[i].max>max) {max=s[i].max; lab=s[i].lab;}
548 for (i=0; i<num_of_clusters; i++)
551 Int_t slice = (id>>25) & 0x7f;
552 Int_t patch = (id>>22) & 0x7;
553 UInt_t pos = id&0x3fffff;
555 AliL3SpacePointData *points = fClusters[slice][patch];
556 if(!points) continue;
557 if(pos>=fNcl[slice][patch])
559 LOG(AliL3Log::kError,"AliL3Evaluate::GetMCTrackLabel","Clusterarray")
560 <<AliL3Log::kDec<<"ERROR"<<ENDLOG;
564 if (abs(points[pos].fTrackID[1]) == lab ||
565 abs(points[pos].fTrackID[2]) == lab ) max++;
568 //check if more than 10% of the clusters are incorrectly assigned (fake track):
569 if (1.-Float_t(max)/num_of_clusters > 0.10)
578 Int_t **AliL3Evaluate::GetClusterIDs(AliL3Track *track)
580 //Return the MC information of all clusters belonging to track.
582 Int_t num_of_clusters = track->GetNumberOfPoints();
583 Int_t **trackID = new Int_t*[num_of_clusters];
585 UInt_t *hitnum = track->GetHitNumbers();
590 for(Int_t i=0; i<num_of_clusters; i++)
593 Int_t slice = (id>>25) & 0x7f;
594 Int_t patch = (id>>22) & 0x7;
595 UInt_t pos = id&0x3fffff;
597 AliL3SpacePointData *points = fClusters[slice][patch];
601 LOG(AliL3Log::kError,"AliL3Evaluate::GetClusterIDs","Clusterarray")
602 <<"No points at slice "<<slice<<" patch "<<patch<<" pos "<<pos<<ENDLOG;
605 if(pos>=fNcl[slice][patch])
607 LOG(AliL3Log::kError,"AliL3Evaluate::GetClusterIDs","Clusterarray")
608 <<AliL3Log::kDec<<"ERROR"<<ENDLOG;
612 xyz[0] = points[pos].fX;
613 xyz[1] = points[pos].fY;
614 xyz[2] = points[pos].fZ;
615 //sector = points[pos].fSector;
616 padrow = points[pos].fPadRow;
618 fTransform->Slice2Sector(slice,padrow,se,ro);
619 fTransform->Global2Raw(xyz,se,ro);
623 Int_t p = fRowid[slice][padrow];
624 if(!fDigitsTree->GetEvent(p))
625 LOG(AliL3Log::kError,"AliL3Evaluate::GetClusterIDs","Digits Tree")
626 <<"Error reading digits tree"<<ENDLOG;
628 trackID[i] = new Int_t[3];
629 trackID[i][0] = fDigits->GetTrackID((Int_t)rint(xyz[2]),(Int_t)rint(xyz[1]),0);
630 trackID[i][1] = fDigits->GetTrackID((Int_t)rint(xyz[2]),(Int_t)rint(xyz[1]),1);
631 trackID[i][2] = fDigits->GetTrackID((Int_t)rint(xyz[2]),(Int_t)rint(xyz[1]),2);
632 //if(trackID[i][0]==6 || trackID[i][0]==32)
633 //printf("trackID %d, padrow %d pad %d time %d\n",fDigits->GetTrackID((Int_t)rint(xyz[2]),(Int_t)rint(xyz[1]),0),padrow,(int)rint(xyz[1]),(int)rint(xyz[2]));
634 /*if(trackID[i][0]<0)
637 printf("trackID %d, padrow %d pad %d time %d\n",trackID[i][0],padrow,(int)rint(xyz[1]),(int)rint(xyz[2]));
638 printf("on the side %d %d %d %d\n",fDigits->GetTrackID(((int)rint(xyz[2])-1),((int)rint(xyz[1])),0),fDigits->GetTrackID(((int)rint(xyz[2])+1),((int)rint(xyz[1])),0),fDigits->GetTrackID(((int)rint(xyz[2])),((int)rint(xyz[1])-1),0),fDigits->GetTrackID(((int)rint(xyz[2])),((int)rint(xyz[1])+1),0));
644 for(Int_t ii=0; ii<fNFastPoints; ii++)
647 if(fMcIndex[ii] == id) break;
649 trackID[i] = new Int_t[3];
650 trackID[i][0] = tmp_pid;
659 void AliL3Evaluate::GetFastClusterIDs(Char_t *path)
661 //Get the MC id of space points in case of using the fast simulator.
663 sprintf(fname,"%s/point_mc.dat",path);
664 FILE *infile = fopen(fname,"r");
669 if(fscanf(infile,"%d %d",&hitid,&hitmc)==EOF) break;
672 fMcId = new Int_t[fNFastPoints];
673 fMcIndex = new UInt_t[fNFastPoints];
675 for(i=0; i<fNFastPoints; i++)
677 if(fscanf(infile,"%d %d",&hitid,&hitmc)==EOF) break;
684 void AliL3Evaluate::CreateHistos(Int_t nbin,Int_t xlow,Int_t xup)
686 //Create the histograms
688 LOG(AliL3Log::kInformational,"AliL3Evaluate::CreateHistos","Allocating")
689 <<"Creating histograms..."<<ENDLOG;
691 fNtuppel = new TNtuple("fNtuppel","Pt resolution","pt_gen:pt_found:nHits");
693 fPtRes = new TH1F("fPtRes","Relative Pt resolution",30,-10.,10.);
694 fNGoodTracksPt = new TH1F("fNGoodTracksPt","Good tracks vs pt",nbin,xlow,xup);
695 fNFoundTracksPt = new TH1F("fNFoundTracksPt","Found tracks vs pt",nbin,xlow,xup);
696 fNFakeTracksPt = new TH1F("fNFakeTracksPt","Fake tracks vs pt",nbin,xlow,xup);
697 fTrackEffPt = new TH1F("fTrackEffPt","Tracking efficiency vs pt",nbin,xlow,xup);
698 fFakeTrackEffPt = new TH1F("fFakeTrackEffPt","Efficiency for fake tracks vs pt",nbin,xlow,xup);
700 fNGoodTracksEta = new TH1F("fNGoodTracksEta","Good tracks vs eta",20,-50,50);
701 fNFoundTracksEta = new TH1F("fNFoundTracksEta","Found tracks vs eta",20,-50,50);
702 fNFakeTracksEta = new TH1F("fNFakeTracksEta","Fake tracks vs eta",20,-50,50);
703 fTrackEffEta = new TH1F("fTrackEffEta","Tracking efficienct vs eta",20,-50,50);
704 fFakeTrackEffEta = new TH1F("fFakeTrackEffEta","Efficiency for fake tracks vs eta",20,-50,50);
705 printf("finished creating histos\n");
708 void AliL3Evaluate::FillEffHistos()
710 //Fill the efficiency histograms.
712 for(Int_t i=0; i<fGoodGen; i++)
714 Double_t ptg=fGoodTracks[i].pt,pzg=fGoodTracks[i].pz;
715 Float_t dipangle=TMath::ATan2(pzg,ptg)*180./TMath::Pi();
716 //printf("filling particle with pt %f and dipangle %f\n",ptg,dipangle);
717 fNGoodTracksPt->Fill(ptg);
718 fNGoodTracksEta->Fill(dipangle);
720 for(Int_t k=0; k<fTracks->GetNTracks(); k++)
722 AliL3Track *track = fTracks->GetCheckedTrack(k);
724 Int_t nHits = track->GetNumberOfPoints();
725 if(nHits < fMinPointsOnTrack) break;
728 tracklabel = track->GetMCid();
729 //printf("evaluating track id %d\n",tracklabel);
730 if(TMath::Abs(tracklabel) != fGoodTracks[i].label) continue;
732 if(tracklabel == fGoodTracks[i].label) {fNFoundTracksPt->Fill(ptg); fNFoundTracksEta->Fill(dipangle);}
733 else {fNFakeTracksPt->Fill(ptg); fNFakeTracksEta->Fill(dipangle);}
734 Float_t pt=track->GetPt();
735 fPtRes->Fill((pt-ptg)/ptg*100.);
736 fNtuppel->Fill(ptg,pt,nHits);
743 void AliL3Evaluate::FillEffHistos()
745 //Fill the efficiency histograms.
747 cout<<endl<<"Note: Doing NAIVE evaluation "<<endl;
748 for(Int_t i=0; i<fGoodGen; i++)
750 Double_t ptg=fGoodTracks[i].pt,pzg=fGoodTracks[i].pz;
751 Float_t dipangle=TMath::ATan2(pzg,ptg)*180./TMath::Pi();
752 //printf("filling particle with pt %f and dipangle %f\n",ptg,dipangle);
753 fNGoodTracksPt->Fill(ptg);
754 fNGoodTracksEta->Fill(dipangle);
758 for(Int_t k=0; k<fTracks->GetNTracks(); k++)
760 AliL3Track *track = fTracks->GetCheckedTrack(k);
762 Int_t nHits = track->GetNumberOfPoints();
763 if(nHits < fMinPointsOnTrack) break;
764 if(track->GetPt()<fMinGoodPt) continue;
765 if(fabs(track->GetPseudoRapidity())>0.9) continue;
767 fNFoundTracksPt->Fill(track->GetPt()); fNFoundTracksEta->Fill(track->GetPseudoRapidity());
768 //Float_t pt=track->GetPt();
769 //fPtRes->Fill((pt-ptg)/ptg*100.);
770 //fNtuppel->Fill(ptg,pt,nHits);
775 void AliL3Evaluate::CalcEffHistos(){
777 Stat_t ngood=fNGoodTracksPt->GetEntries();
778 Stat_t nfound=fNFoundTracksPt->GetEntries();
779 Stat_t nfake=fNFakeTracksPt->GetEntries();
781 LOG(AliL3Log::kInformational,"AliL3Evaluate::FillEffHistos","Efficiency")
782 <<AliL3Log::kDec<<"There was "<<ngood<<" generated good tracks"<<ENDLOG;
783 LOG(AliL3Log::kInformational,"AliL3Evaluate::FillEffHistos","Efficiency")
784 <<AliL3Log::kDec<<"Found "<<nfound<<" tracks"<<ENDLOG;
785 LOG(AliL3Log::kInformational,"AliL3Evaluate::FillEffHistos","Efficiency")
786 <<AliL3Log::kDec<<"Integral efficiency is about "<<nfound/ngood*100<<ENDLOG;
787 LOG(AliL3Log::kInformational,"AliL3Evaluate::FillEffHistos","Efficiency")
788 <<AliL3Log::kDec<<"Fake tracks relative is about "<<nfake/ngood*100<<ENDLOG;
790 LOG(AliL3Log::kInformational,"AliL3Evaluate::FillEffHistos","Efficiency")
791 <<AliL3Log::kDec<<"Naive efficiency "<<(Double_t)fGoodFound/(Double_t)fGoodGen<<ENDLOG;
794 fNFoundTracksPt->Sumw2(); fNGoodTracksPt->Sumw2();
795 fTrackEffPt->Divide(fNFoundTracksPt,fNGoodTracksPt,1,1.,"b");
796 fFakeTrackEffPt->Divide(fNFakeTracksPt,fNGoodTracksPt,1,1.,"b");
797 fTrackEffPt->SetMaximum(1.4);
798 fTrackEffPt->SetXTitle("P_{T} [GeV]");
799 fTrackEffPt->SetLineWidth(2);
800 fFakeTrackEffPt->SetFillStyle(3013);
801 fTrackEffPt->SetLineColor(4);
802 fFakeTrackEffPt->SetFillColor(2);
804 fNFoundTracksEta->Sumw2(); fNGoodTracksEta->Sumw2();
805 fTrackEffEta->Divide(fNFoundTracksEta,fNGoodTracksEta,1,1.,"b");
806 fFakeTrackEffEta->Divide(fNFakeTracksEta,fNGoodTracksEta,1,1.,"b");
807 fTrackEffEta->SetMaximum(1.4);
808 fTrackEffEta->SetXTitle("#lambda [degrees]");
809 fTrackEffEta->SetLineWidth(2);
810 fFakeTrackEffEta->SetFillStyle(3013);
811 fTrackEffEta->SetLineColor(4);
812 fFakeTrackEffEta->SetFillColor(2);
816 void AliL3Evaluate::Write2File(Char_t *outputfile)
818 //Write histograms to file:
820 TFile *of = new TFile(outputfile,"RECREATE");
823 LOG(AliL3Log::kError,"AliL3Evaluate::Write2File","File Open")
824 <<"Problems opening rootfile"<<ENDLOG;
831 fNGoodTracksPt->Write();
832 fNFoundTracksPt->Write();
833 fNFakeTracksPt->Write();
834 fTrackEffPt->Write();
835 fFakeTrackEffPt->Write();
836 fNGoodTracksEta->Write();
837 fNFoundTracksEta->Write();
838 fNFakeTracksEta->Write();
839 fTrackEffEta->Write();
840 fFakeTrackEffEta->Write();
847 TNtuple *AliL3Evaluate::CalculateResiduals()
850 TNtuple *ntuppel=new TNtuple("ntuppel","Residuals","residual_trans:residual_long:zHit:pt:dipangle:beta:padrow:nHits");
852 for(int f=fMinSlice; f<=fMaxSlice; f++)
854 AliL3FileHandler *tfile = new AliL3FileHandler();
856 sprintf(fname,"tracks_tr_%d_0.raw",f);
857 if(!tfile->SetBinaryInput(fname)){
858 LOG(AliL3Log::kError,"AliL3Evaluation::Setup","File Open")
859 <<"Inputfile "<<fname<<" does not exist"<<ENDLOG;
862 fTracks = new AliL3TrackArray();
863 tfile->Binary2TrackArray(fTracks);
864 tfile->CloseBinaryInput();
866 printf("Looking in slice %d\n",f);
867 for(Int_t i=0; i<fTracks->GetNTracks(); i++)
870 AliL3Track *track = (AliL3Track*)fTracks->GetCheckedTrack(i);
873 track->CalculateHelix();
874 UInt_t *hitnum = track->GetHitNumbers();
879 for(Int_t j=0; j<track->GetNumberOfPoints()-1; j++)
882 Int_t slice = (id>>25) & 0x7f;
883 Int_t patch = (id>>22) & 0x7;
884 UInt_t pos = id&0x3fffff;
886 //if(slice!=1) continue;
888 AliL3SpacePointData *points = fClusters[slice][patch];
892 LOG(AliL3Log::kError,"AliL3Evaluate::CalculateResiduals","Clusterarray")
893 <<"No points at slice "<<slice<<" patch "<<patch<<" pos "<<pos<<ENDLOG;
896 if(pos>=fNcl[slice][patch])
898 LOG(AliL3Log::kError,"AliL3Evaluate::CalculateResiduals","Clusterarray")
899 <<AliL3Log::kDec<<"ERROR"<<ENDLOG;
903 xyz[0] = points[pos].fX;
904 xyz[1] = points[pos].fY;
905 xyz[2] = points[pos].fZ;
906 padrow = points[pos].fPadRow;
907 //fTransform->Global2Local(xyz,slice);
909 Float_t xyz_cross[3];
910 track->GetCrossingPoint(padrow,xyz_cross);
911 Double_t beta = track->GetCrossingAngle(padrow);
913 Double_t yres = xyz_cross[1] - xyz[1];
914 Double_t zres = xyz_cross[2] - xyz[2];
916 Double_t dipangle = atan(track->GetTgl());
917 ntuppel->Fill(yres,zres,xyz_cross[2],track->GetPt(),dipangle,beta,padrow,track->GetNumberOfPoints());
927 TNtuple *AliL3Evaluate::EvaluatePoints(Char_t *rootfile)
929 //Compare points to the exact crossing points of track and padrows.
930 //The input file to this function, contains the exact clusters calculated
931 //in AliTPC::Hits2ExactClusters.
933 cout<<"Evaluating points"<<endl;
934 TNtuple *ntuppel = new TNtuple("ntuppel","residuals","slice:padrow:resy:resz:zHit:pt");
936 TFile *exfile = TFile::Open(rootfile);
939 cerr<<"Error opening rootfile "<<rootfile<<endl;
943 AliTPCParam *param = (AliTPCParam*)exfile->Get("75x40_100x60");
945 //Get the exact clusters from file:
946 AliTPCClustersArray *arr = new AliTPCClustersArray;
948 arr->SetClusterType("AliComplexCluster");
950 sprintf(treeName,"TreeCExact_%s",param->GetTitle());
951 Bool_t clusterok = arr->ConnectTree(treeName);//Segment Tree (for offline clusters)
952 if(!clusterok) {printf("AliL3Evaluate::EvaluatePoints : Error in clusterloading\n"); return 0;}
954 cout<<"Entering loop with "<<(Int_t)arr->GetTree()->GetEntries()<<endl;
955 for(Int_t i=0; i<arr->GetTree()->GetEntries(); i++)
957 //Get the exact clusters for this row:
959 AliSegmentID *s = arr->LoadEntry(i);
960 param->AdjustSectorRow(s->GetID(),cursec,currow);
962 AliTPCClustersRow *ro = (AliTPCClustersRow *)arr->GetRow(cursec,currow);
963 TClonesArray *clusters = ro->GetArray();
964 int num_of_offline=clusters->GetEntriesFast();
966 //Get the found clusters:
968 fTransform->Sector2Slice(slice,padrow,cursec,currow);
969 if(slice<fMinSlice || slice>fMaxSlice) continue;
970 AliL3SpacePointData *points = fClusters[slice][0];
972 Int_t index = fRowid[slice][padrow];
973 if(!fDigitsTree->GetEvent(index))
974 printf("AliL3Evaluate::EvaluatePoints : ERROR IN DIGITSTREE\n");
975 printf("Checking slice %d padrow %d with %d clusters\n",slice,padrow,num_of_offline);
977 for(UInt_t c=0; c<fNcl[slice][0]; c++)
979 if(points[c].fPadRow!=padrow) continue;
980 for(Int_t m=0; m<num_of_offline; m++)
982 AliComplexCluster *cluster = (AliComplexCluster *)clusters->UncheckedAt(m);
983 Int_t mcId = cluster->fTracks[0];
984 //Int_t mcId = cluster->GetLabel(0);
985 if(mcId <0) continue;
986 TParticle *part = gAlice->Particle(mcId);
988 Float_t xyz_cl[3] = {points[c].fX,points[c].fY,points[c].fZ};
990 fTransform->Global2Raw(xyz_cl,cursec,currow);
991 if(fDigits->GetTrackID((Int_t)rint(xyz_cl[2]),(Int_t)rint(xyz_cl[1]),0)!=mcId &&
992 fDigits->GetTrackID((Int_t)rint(xyz_cl[2]),(Int_t)rint(xyz_cl[1]),1)!=mcId &&
993 fDigits->GetTrackID((Int_t)rint(xyz_cl[2]),(Int_t)rint(xyz_cl[1]),2)!=mcId)
995 fTransform->Raw2Local(xyz_ex,cursec,currow,cluster->fY,cluster->fX);
996 fTransform->Raw2Local(xyz_cl,cursec,currow,xyz_cl[1],xyz_cl[2]);
997 Float_t resy = xyz_cl[1] - xyz_ex[1];//cluster->GetY()
998 Float_t resz = xyz_cl[2] - xyz_ex[2];//cluster->GetZ()
1000 ntuppel->Fill(slice,padrow,resy,resz,xyz_ex[2],part->Pt());
1003 arr->ClearRow(cursec,currow);
1009 void AliL3Evaluate::GetCFeff(Char_t *outfile)
1012 TNtuple *ntuppel = new TNtuple("ntuppel","Cluster finder efficiency","row:ncrossings:nclusters");
1014 AliTPC *TPC = (AliTPC*)gAlice->GetDetector("TPC");
1016 TPC->SetParam(fParam);
1018 Int_t ver = TPC->IsVersion();
1019 LOG(AliL3Log::kInformational,"AliL3Evaluate::DefineGoodTracks","TPC version")
1020 <<"TPC version "<<ver<<" found on file"<<ENDLOG;
1022 Int_t zero=TPC->GetParam()->GetZeroSup();
1024 Int_t np = gAlice->GetNtrack();
1027 Int_t *count = new Int_t[np]; //np number of particles.
1030 for (i=0; i<np; i++) count[i]=0;
1031 for(Int_t sl=fMinSlice; sl<=fMaxSlice; sl++)
1033 for (i=0; i<=175; i++)
1037 Int_t index = fRowid[sl][i];
1038 if (!fDigitsTree->GetEvent(index)) continue;
1040 fParam->AdjustSectorRow(fDigits->GetID(),sec,row);
1043 Int_t it=fDigits->CurrentRow(), ip=fDigits->CurrentColumn();
1044 Short_t dig = fDigits->GetDigit(it,ip);
1046 if(dig<=fParam->GetZeroSup()) continue;
1047 if(it < fParam->GetMaxTBin()-1 && it > 0)
1048 if(fDigits->GetDigit(it+1,ip) <= fParam->GetZeroSup()
1049 && fDigits->GetDigit(it-1,ip) <= fParam->GetZeroSup())
1052 fTransform->Raw2Local(xyz,sec,row,ip,it);
1053 if(fParam->GetPadRowRadii(sec,row)<230./250.*fabs(xyz[2]))
1057 Int_t idx0=fDigits->GetTrackID(it,ip,0);
1058 Int_t idx1=fDigits->GetTrackID(it,ip,1);
1059 Int_t idx2=fDigits->GetTrackID(it,ip,2);
1061 if (idx0>=0 && dig>=zero) count[idx0]+=1;
1062 if (idx1>=0 && dig>=zero) count[idx1]+=1;
1063 if (idx2>=0 && dig>=zero) count[idx2]+=1;
1064 } while (fDigits->Next());
1066 for (Int_t j=0; j<np; j++)
1068 if (count[j]>1) //at least two digits at this padrow
1072 AliL3SpacePointData *points = fClusters[sl][0];
1073 for(Int_t l=0; l<fNcl[sl][0]; l++)
1075 if(points[l].fPadRow != i) continue;
1078 ntuppel->Fill(i,crossed,recs);
1083 TFile *file = TFile::Open(outfile,"RECREATE");
1089 Bool_t AliL3Evaluate::GetParticleCrossingPoint(TParticle *part,Int_t slice,Int_t padrow,Float_t *xyz)
1091 //Calcluate the crossing point between a generated particle and given padrow.
1094 Double_t kappa = 0.2*0.0029980/part->Pt();
1096 Double_t radius = 1/fabs(kappa);
1097 if(part->GetPdgCode() > 0) kappa = -kappa;
1105 Float_t angl[1] = {part->Phi()};
1107 fTransform->Global2LocalAngle(angl,slice);
1109 Double_t charge = -1.*kappa;
1110 Double_t trackPhi0 = angl[0] + charge*0.5*Pi/fabs(charge);
1114 Double_t xc = x0 - radius * cos(trackPhi0);
1115 Double_t yc = y0 - radius * sin(trackPhi0);
1117 //printf("radius %f xc %f yc %f\n",radius,xc,yc);
1119 Double_t xHit = fTransform->Row2X(padrow);
1121 Double_t aa = (xHit - xc)*(xHit - xc);
1122 Double_t r2 = radius*radius;
1126 Double_t aa2 = sqrt(r2 - aa);
1127 Double_t y1 = yc + aa2;
1128 Double_t y2 = yc - aa2;
1130 if(fabs(y2) < fabs(y1)) xyz[1] = y2;
1132 Double_t tgl = part->Pz()/part->Pt();
1134 Double_t yHit = xyz[1];
1135 Double_t angle1 = atan2((yHit - yc),(xHit - xc));
1136 if(angle1 < 0) angle1 += 2.*Pi;
1137 Double_t angle2 = atan2((0 - yc),(0 - xc));
1138 if(angle2 < 0) angle2 += 2.*Pi;
1139 Double_t diff_angle = angle1 - angle2;
1140 diff_angle = fmod(diff_angle,2*Pi);
1141 if((charg*diff_angle) > 0) diff_angle = diff_angle - charg*2.*Pi;
1142 Double_t s_tot = fabs(diff_angle)*radius;
1143 Double_t zHit = 0 + s_tot*tgl;