3 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
4 //*-- Copyright © ALICE HLT Group
6 #include "AliL3StandardIncludes.h"
11 #include <TClonesArray.h>
15 #include <AliSimDigits.h>
17 #include <AliTPCcluster.h>
18 #include <AliTPCClustersArray.h>
19 #include <AliTPCClustersRow.h>
20 #include <AliTPCParam.h>
21 #include <AliComplexCluster.h>
30 #include "AliL3Logging.h"
31 #include "AliL3Transform.h"
32 #include "AliL3SpacePointData.h"
33 #include "AliL3Track.h"
34 #include "AliL3FileHandler.h"
35 #include "AliL3TrackArray.h"
36 #include "AliL3Evaluate.h"
42 /** \class AliL3Evaluate
44 //_____________________________________________________________
47 // Evaluation class for tracking. Plots efficiencies etc..
52 ClassImp(AliL3Evaluate)
54 AliL3Evaluate::AliL3Evaluate()
65 AliL3Evaluate::AliL3Evaluate(Char_t *datapath,Int_t min_clusters,Int_t minhits,Double_t minpt,Int_t *slice)
78 sprintf(fPath,"%s",datapath);
79 fMaxFalseClusters = 0.1;
82 fMinPointsOnTrack = min_clusters;
83 fMinHitsFromParticle = minhits;
85 memset(fClusters,0,36*6*sizeof(AliL3SpacePointData*));
90 void AliL3Evaluate::LoadData(Int_t event,Bool_t sp)
93 AliL3FileHandler *clusterfile[36][6];
94 for(Int_t s=fMinSlice; s<=fMaxSlice; s++)
96 for(Int_t p=0; p<AliL3Transform::GetNPatches(); p++)
105 delete fClusters[s][p];
107 clusterfile[s][p] = new AliL3FileHandler();
109 sprintf(fname,"%s/points_%d_%d.raw",fPath,s,patch);
111 sprintf(fname,"%s/points_%d_%d_%d.raw",fPath,event,s,patch);
112 if(!clusterfile[s][p]->SetBinaryInput(fname))
114 LOG(AliL3Log::kError,"AliL3Evaluation::Setup","File Open")
115 <<"Inputfile "<<fname<<" does not exist"<<ENDLOG;
116 delete clusterfile[s][p];
117 clusterfile[s][p] = 0;
120 fClusters[s][p] = (AliL3SpacePointData*)clusterfile[s][p]->Allocate();
121 clusterfile[s][p]->Binary2Memory(fNcl[s][p],fClusters[s][p]);
122 clusterfile[s][p]->CloseBinaryInput();
128 sprintf(fname,"%s/tracks_%d.raw",fPath,event);
129 AliL3FileHandler *tfile = new AliL3FileHandler();
130 if(!tfile->SetBinaryInput(fname)){
131 LOG(AliL3Log::kError,"AliL3Evaluation::Setup","File Open")
132 <<"Inputfile "<<fname<<" does not exist"<<ENDLOG;
137 fTracks = new AliL3TrackArray();
138 tfile->Binary2TrackArray(fTracks);
139 tfile->CloseBinaryInput();
144 AliL3Evaluate::~AliL3Evaluate()
146 if(fGoodTracks) delete fGoodTracks;
147 if(fDigitsTree) fDigitsTree->Delete();
148 if(fTracks) delete fTracks;
149 if(fPtRes) delete fPtRes;
150 if(fNGoodTracksPt) delete fNGoodTracksPt;
151 if(fNFoundTracksPt) delete fNFoundTracksPt;
152 if(fNFakeTracksPt) delete fNFakeTracksPt;
153 if(fTrackEffPt) delete fTrackEffPt;
154 if(fFakeTrackEffPt) delete fFakeTrackEffPt;
155 if(fNGoodTracksEta) delete fNGoodTracksEta;
156 if(fNFoundTracksEta) delete fNFoundTracksEta;
157 if(fNFakeTracksEta) delete fNFakeTracksEta;
158 if(fTrackEffEta) delete fTrackEffEta;
159 if(fFakeTrackEffEta) delete fFakeTrackEffEta;
160 if(fMcIndex) delete [] fMcIndex;
161 if(fMcId) delete [] fMcId;
162 if(fNtuppel) delete fNtuppel;
166 void AliL3Evaluate::AssignIDs()
168 //Assign MC id to the tracks.
170 cerr<<"AliL3Evaluate::AssignIDs() : You need to compile with the do_mc flag!"<<endl;
175 LOG(AliL3Log::kDebug,"AliL3Evaluate::AssignIDs","Track Loop")
176 <<"Assigning MC id to the found tracks...."<<ENDLOG;
177 for(Int_t i=0; i<fTracks->GetNTracks(); i++)
179 AliL3Track *track = (AliL3Track*)fTracks->GetCheckedTrack(i);
181 if(track->GetNumberOfPoints() < fMinPointsOnTrack) break;
184 Int_t tID = GetMCTrackLabel(track);
187 //cout<<"Found "<<fGoodFound<<" good tracks "<<endl;
191 struct S {Int_t lab; Int_t max;};
192 Int_t AliL3Evaluate::GetMCTrackLabel(AliL3Track *track){
193 //Returns the MCtrackID of the belonging clusters.
194 //If MCLabel < 0, means that track is fake.
195 //Definitions are identical to offline.
197 // - more than 10 percent of clusters are assigned incorrectly
198 // - more than half of the innermost 10% of clusters were assigned incorrectly.
202 Int_t num_of_clusters = track->GetNumberOfPoints();
203 S *s=new S[num_of_clusters];
205 for (i=0; i<num_of_clusters; i++) s[i].lab=s[i].max=0;
206 UInt_t *hitnum = track->GetHitNumbers();
210 for (i=0; i<num_of_clusters; i++)
212 //Tricks to get the clusters belonging to this track:
214 Int_t slice = (id>>25) & 0x7f;
215 Int_t patch = (id>>22) & 0x7;
216 UInt_t pos = id&0x3fffff;
218 AliL3SpacePointData *points = fClusters[slice][patch];
219 if(!points) continue;
220 if(pos>=fNcl[slice][patch])
222 LOG(AliL3Log::kError,"AliL3Evaluate::GetMCTrackLabel","Clusterarray")
223 <<AliL3Log::kDec<<"ERROR"<<ENDLOG;
227 //Get the label of the cluster:
228 lab=points[pos].fTrackID[0];
231 for (j=0; j<num_of_clusters; j++)
232 if (s[j].lab==lab || s[j].max==0) break;
238 for (i=0; i<num_of_clusters; i++)
239 if (s[i].max>max) {max=s[i].max; lab=s[i].lab;}
242 return -1; //If most clusters is -1, this is a noise track.
244 cerr<<"AliL3Evaluate::GetMCTrackLabel : Track label negative :"<<lab<<endl;
248 for (i=0; i<num_of_clusters; i++)
251 Int_t slice = (id>>25) & 0x7f;
252 Int_t patch = (id>>22) & 0x7;
253 UInt_t pos = id&0x3fffff;
255 AliL3SpacePointData *points = fClusters[slice][patch];
256 if(!points) continue;
257 if(pos>=fNcl[slice][patch])
259 LOG(AliL3Log::kError,"AliL3Evaluate::GetMCTrackLabel","Clusterarray")
260 <<AliL3Log::kDec<<"ERROR"<<ENDLOG;
264 if (abs(points[pos].fTrackID[1]) == lab ||
265 abs(points[pos].fTrackID[2]) == lab ) max++;
269 //Check if more than 10% of the clusters were assigned incorrectly:
270 if (1.-Float_t(max)/num_of_clusters > fMaxFalseClusters)
274 else //Check if at least half of the 10% innermost clusters are assigned correctly.
276 Int_t tail=Int_t(0.10*num_of_clusters);
278 for (i=1; i<=tail; i++)
280 id = hitnum[num_of_clusters - i];
281 Int_t slice = (id>>25) & 0x7f;
282 Int_t patch = (id>>22) & 0x7;
283 UInt_t pos = id&0x3fffff;
285 AliL3SpacePointData *points = fClusters[slice][patch];
286 if(lab == abs(points[pos].fTrackID[0]) ||
287 lab == abs(points[pos].fTrackID[1]) ||
288 lab == abs(points[pos].fTrackID[2])) max++;
290 if (max < Int_t(0.5*tail)) return -lab;
294 #else //If we are running with mc_ids or not
300 void AliL3Evaluate::GetFastClusterIDs(Char_t *path)
302 //Get the MC id of space points in case of using the fast simulator.
304 sprintf(fname,"%s/point_mc.dat",path);
305 FILE *infile = fopen(fname,"r");
310 if(fscanf(infile,"%d %d",&hitid,&hitmc)==EOF) break;
313 fMcId = new Int_t[fNFastPoints];
314 fMcIndex = new UInt_t[fNFastPoints];
316 for(i=0; i<fNFastPoints; i++)
318 if(fscanf(infile,"%d %d",&hitid,&hitmc)==EOF) break;
325 void AliL3Evaluate::CreateHistos(Int_t nbin,Float_t xlow,Float_t xup)
327 //Create the histograms
329 LOG(AliL3Log::kInformational,"AliL3Evaluate::CreateHistos","Allocating")
330 <<"Creating histograms..."<<ENDLOG;
332 fNtuppel = new TNtuple("fNtuppel","Pt resolution","pt_gen:pt_found:nHits");
333 fNtuppel->SetDirectory(0);
334 fPtRes = new TH1F("fPtRes","Relative Pt resolution",30,-10.,10.);
335 fNGoodTracksPt = new TH1F("fNGoodTracksPt","Good tracks vs pt",nbin,xlow,xup);
336 fNFoundTracksPt = new TH1F("fNFoundTracksPt","Found tracks vs pt",nbin,xlow,xup);
337 fNFakeTracksPt = new TH1F("fNFakeTracksPt","Fake tracks vs pt",nbin,xlow,xup);
338 fTrackEffPt = new TH1F("fTrackEffPt","Tracking efficiency vs pt",nbin,xlow,xup);
339 fFakeTrackEffPt = new TH1F("fFakeTrackEffPt","Efficiency for fake tracks vs pt",nbin,xlow,xup);
341 fNGoodTracksEta = new TH1F("fNGoodTracksEta","Good tracks vs eta",20,-50,50);
342 fNFoundTracksEta = new TH1F("fNFoundTracksEta","Found tracks vs eta",20,-50,50);
343 fNFakeTracksEta = new TH1F("fNFakeTracksEta","Fake tracks vs eta",20,-50,50);
344 fTrackEffEta = new TH1F("fTrackEffEta","Tracking efficienct vs eta",20,-50,50);
345 fFakeTrackEffEta = new TH1F("fFakeTrackEffEta","Efficiency for fake tracks vs eta",20,-50,50);
349 void AliL3Evaluate::GetGoodParticles(Char_t *path,Int_t event,Int_t *padrowrange)
351 //Read the good particles from file. This file should already have been
352 //generated by macro AliTPCComparison.C.
354 Char_t filename[1024];
355 if(event<0 && !padrowrange)
356 sprintf(filename,"%s/good_tracks_tpc",path);
357 else if(event>=0 && !padrowrange)
358 sprintf(filename,"%s/good_tracks_tpc_%d",path,event);
360 sprintf(filename,"%s/good_tracks_tpc_%d_%d_%d",path,event,padrowrange[0],padrowrange[1]);
361 ifstream in(filename);
364 cerr<<"AliL3Evaluate::GetGoodParticles : Problems opening file :"<<filename<<endl;
367 Int_t MaxTracks=20000;
369 delete [] fGoodTracks;
371 fGoodTracks = new GoodTrack[MaxTracks];
373 while (in>>fGoodTracks[fGoodGen].label>>fGoodTracks[fGoodGen].code>>
374 fGoodTracks[fGoodGen].px>>fGoodTracks[fGoodGen].py>>fGoodTracks[fGoodGen].pz>>
375 fGoodTracks[fGoodGen].x>>fGoodTracks[fGoodGen].y >>fGoodTracks[fGoodGen].z>>fGoodTracks[fGoodGen].nhits>>fGoodTracks[fGoodGen].sector)
379 if (fGoodGen==MaxTracks)
381 cerr<<"AliL3Evaluate::GetGoodParticles : Too many good tracks !\n";
388 void AliL3Evaluate::FillEffHistos()
392 cerr<<"AliL3Evaluate::FillEffHistos : No good tracks"<<endl;
395 //cout<<"Comparing "<<fGoodGen<<" good tracks ..."<<endl;
396 for(Int_t i=0; i<fGoodGen; i++)
398 //cout<<"Checking particle "<<i<<endl;
399 if(fGoodTracks[i].nhits < fMinHitsFromParticle) continue;
400 Float_t ptg = TMath::Sqrt(fGoodTracks[i].px*fGoodTracks[i].px + fGoodTracks[i].py*fGoodTracks[i].py);
401 if(ptg < fMinGoodPt) continue;
402 Float_t pzg=fGoodTracks[i].pz;
403 Float_t dipangle=TMath::ATan2(pzg,ptg)*180./TMath::Pi();
405 fNGoodTracksPt->Fill(ptg);
406 fNGoodTracksEta->Fill(dipangle);
409 for(Int_t k=0; k<fTracks->GetNTracks(); k++)
411 AliL3Track *track = fTracks->GetCheckedTrack(k);
413 Int_t nHits = track->GetNumberOfPoints();
414 if(nHits < fMinPointsOnTrack) break;
416 tracklabel = track->GetMCid();
418 if(TMath::Abs(tracklabel) != fGoodTracks[i].label) continue;
420 Float_t pt=track->GetPt();
421 if(tracklabel == fGoodTracks[i].label)
423 fNFoundTracksPt->Fill(ptg);
424 fNFoundTracksEta->Fill(dipangle);
425 fNtuppel->Fill(ptg,pt,nHits);
426 fPtRes->Fill((pt-ptg)/ptg*100.);
430 fNFakeTracksPt->Fill(ptg);
431 fNFakeTracksEta->Fill(dipangle);
433 //fPtRes->Fill((pt-ptg)/ptg*100.);
434 //fNtuppel->Fill(ptg,pt,nHits);
439 // cout<<"Track "<<fGoodTracks[i].label<<" was not found"<<endl;
443 void AliL3Evaluate::FillEffHistosNAIVE()
445 //Fill the efficiency histograms.
447 cout<<endl<<"Note: Doing NAIVE evaluation "<<endl;
448 for(Int_t i=0; i<fGoodGen; i++)
450 Double_t ptg=TMath::Sqrt(fGoodTracks[i].px*fGoodTracks[i].px + fGoodTracks[i].py*fGoodTracks[i].py);
451 Double_t pzg=fGoodTracks[i].pz;
452 Float_t dipangle=TMath::ATan2(pzg,ptg)*180./TMath::Pi();
453 //printf("filling particle with pt %f and dipangle %f\n",ptg,dipangle);
454 fNGoodTracksPt->Fill(ptg);
455 fNGoodTracksEta->Fill(dipangle);
459 for(Int_t k=0; k<fTracks->GetNTracks(); k++)
461 AliL3Track *track = fTracks->GetCheckedTrack(k);
463 Int_t nHits = track->GetNumberOfPoints();
464 if(nHits < fMinPointsOnTrack) break;
465 if(track->GetPt()<fMinGoodPt) continue;
466 if(fabs(track->GetPseudoRapidity())>0.9) continue;
468 fNFoundTracksPt->Fill(track->GetPt()); fNFoundTracksEta->Fill(track->GetPseudoRapidity());
469 //Float_t pt=track->GetPt();
470 //fPtRes->Fill((pt-ptg)/ptg*100.);
471 //fNtuppel->Fill(ptg,pt,nHits);
476 void AliL3Evaluate::CalcEffHistos()
479 Stat_t ngood=fNGoodTracksPt->GetEntries();
480 Stat_t nfound=fNFoundTracksPt->GetEntries();
481 Stat_t nfake=fNFakeTracksPt->GetEntries();
483 LOG(AliL3Log::kInformational,"AliL3Evaluate::FillEffHistos","Efficiency")
484 <<AliL3Log::kDec<<"There was "<<ngood<<" generated good tracks"<<ENDLOG;
485 LOG(AliL3Log::kInformational,"AliL3Evaluate::FillEffHistos","Efficiency")
486 <<AliL3Log::kDec<<"Found "<<nfound<<" tracks"<<ENDLOG;
487 LOG(AliL3Log::kInformational,"AliL3Evaluate::FillEffHistos","Efficiency")
488 <<AliL3Log::kDec<<"Integral efficiency is about "<<nfound/ngood*100<<ENDLOG;
489 LOG(AliL3Log::kInformational,"AliL3Evaluate::FillEffHistos","Efficiency")
490 <<AliL3Log::kDec<<"Fake tracks relative is about "<<nfake/ngood*100<<ENDLOG;
491 //LOG(AliL3Log::kInformational,"AliL3Evaluate::FillEffHistos","Efficiency")
492 //<<AliL3Log::kDec<<"Naive efficiency "<<(Double_t)fGoodFound/(Double_t)fGoodGen<<ENDLOG;
494 fNFoundTracksPt->Sumw2(); fNGoodTracksPt->Sumw2();
495 fTrackEffPt->Divide(fNFoundTracksPt,fNGoodTracksPt,1,1.,"b");
496 fFakeTrackEffPt->Divide(fNFakeTracksPt,fNGoodTracksPt,1,1.,"b");
497 fTrackEffPt->SetMaximum(1.4);
498 fTrackEffPt->SetXTitle("P_{T} [GeV]");
499 fTrackEffPt->SetLineWidth(2);
500 fFakeTrackEffPt->SetFillStyle(3013);
501 fTrackEffPt->SetLineColor(4);
502 fFakeTrackEffPt->SetFillColor(2);
504 fNFoundTracksEta->Sumw2(); fNGoodTracksEta->Sumw2();
505 fTrackEffEta->Divide(fNFoundTracksEta,fNGoodTracksEta,1,1.,"b");
506 fFakeTrackEffEta->Divide(fNFakeTracksEta,fNGoodTracksEta,1,1.,"b");
507 fTrackEffEta->SetMaximum(1.4);
508 fTrackEffEta->SetXTitle("#lambda [degrees]");
509 fTrackEffEta->SetLineWidth(2);
510 fFakeTrackEffEta->SetFillStyle(3013);
511 fTrackEffEta->SetLineColor(4);
512 fFakeTrackEffEta->SetFillColor(2);
516 void AliL3Evaluate::Write2File(Char_t *outputfile)
518 //Write histograms to file:
520 TFile *of = TFile::Open(outputfile,"RECREATE");
523 LOG(AliL3Log::kError,"AliL3Evaluate::Write2File","File Open")
524 <<"Problems opening rootfile"<<ENDLOG;
531 fNGoodTracksPt->Write();
532 fNFoundTracksPt->Write();
533 fNFakeTracksPt->Write();
534 fTrackEffPt->Write();
535 fFakeTrackEffPt->Write();
536 fNGoodTracksEta->Write();
537 fNFoundTracksEta->Write();
538 fNFakeTracksEta->Write();
539 fTrackEffEta->Write();
540 fFakeTrackEffEta->Write();
546 TNtupleD *AliL3Evaluate::CalculateResiduals(Char_t *datapath)
549 TNtupleD *ntuppel=new TNtupleD("ntuppel","Residuals","residual_trans:residual_long:zHit:pt:dipangle:beta:padrow:nHits");
550 ntuppel->SetDirectory(0);
554 AliL3FileHandler *tfile = new AliL3FileHandler();
556 sprintf(fname,"%s/tracks_0.raw",datapath);
557 if(!tfile->SetBinaryInput(fname)){
558 LOG(AliL3Log::kError,"AliL3Evaluation::Setup","File Open")
559 <<"Inputfile "<<fname<<" does not exist"<<ENDLOG;
562 fTracks = new AliL3TrackArray();
563 tfile->Binary2TrackArray(fTracks);
564 tfile->CloseBinaryInput();
567 for(Int_t i=0; i<fTracks->GetNTracks(); i++)
570 AliL3Track *track = (AliL3Track*)fTracks->GetCheckedTrack(i);
572 if(track->GetNHits() < fMinPointsOnTrack) continue;
574 track->CalculateHelix();
575 UInt_t *hitnum = track->GetHitNumbers();
580 for(Int_t j=0; j<track->GetNumberOfPoints()-1; j++)
583 Int_t slice = (id>>25) & 0x7f;
584 Int_t patch = (id>>22) & 0x7;
585 UInt_t pos = id&0x3fffff;
587 //if(slice!=1) continue;
589 AliL3SpacePointData *points = fClusters[slice][patch];
593 LOG(AliL3Log::kError,"AliL3Evaluate::CalculateResiduals","Clusterarray")
594 <<"No points at slice "<<slice<<" patch "<<patch<<" pos "<<pos<<ENDLOG;
597 if(pos>=fNcl[slice][patch])
599 LOG(AliL3Log::kError,"AliL3Evaluate::CalculateResiduals","Clusterarray")
600 <<AliL3Log::kDec<<"ERROR"<<ENDLOG;
604 xyz[0] = points[pos].fX;
605 xyz[1] = points[pos].fY;
606 xyz[2] = points[pos].fZ;
607 padrow = points[pos].fPadRow;
608 AliL3Transform::Global2Local(xyz,slice,kTRUE);
611 AliL3Transform::Local2GlobalAngle(&angle,slice);
612 track->CalculateReferencePoint(angle,AliL3Transform::Row2X(padrow));
613 Float_t xyz_cross[3] = {track->GetPointX(),track->GetPointY(),track->GetPointZ()};
614 AliL3Transform::Global2Local(xyz_cross,slice,kTRUE);
616 Double_t beta = track->GetCrossingAngle(padrow,slice);
618 Double_t yres = xyz_cross[1] - xyz[1];
619 Double_t zres = xyz_cross[2] - xyz[2];
621 Double_t dipangle = atan(track->GetTgl());
622 ntuppel->Fill(yres,zres,xyz_cross[2],track->GetPt(),dipangle,beta,padrow,track->GetNumberOfPoints());
632 enum tagprimary {kPrimaryCharged = 0x4000};
633 void AliL3Evaluate::EvaluatePoints(Char_t *rootfile,Char_t *exactfile,Char_t *tofile,Int_t nevent,Bool_t offline,Bool_t sp)
635 //Compare points to the exact crossing points of track and padrows.
636 //The input file to this function, contains the exact clusters calculated
637 //in AliTPC::Hits2ExactClusters.
640 cerr<<"AliL3Evaluate::EvaluatePoints : Compile with do_mc flag!"<<endl;
643 cout<<"Evaluating points"<<endl;
644 TNtuple *ntuppel = new TNtuple("ntuppel_res","Cluster properties",
645 "slice:padrow:charge:resy:resz:zHit:pt:beta:sigmaY2:sigmaZ2:psigmaY2:psigmaZ2");
646 ntuppel->SetDirectory(0);
648 TNtuple *ntuppel2 = new TNtuple("ntuppel_eff","Efficiency","slice:padrow:nfound:ngen");
649 ntuppel2->SetDirectory(0);
651 TFile *exfile = TFile::Open(rootfile);
654 cerr<<"Error opening rootfile "<<rootfile<<endl;
657 gAlice = (AliRun*)exfile->Get("gAlice");
660 LOG(AliL3Log::kError,"AliL3Evaluate::InitMC","gAlice")
661 <<"AliRun object non existing on file"<<ENDLOG;
665 AliTPCParam *param = (AliTPCParam*)exfile->Get(AliL3Transform::GetParamName());
667 TFile *exact = TFile::Open(exactfile);
670 cerr<<"AliL3Evaluate::EvaluatePoints : Problems opening file :"<<exactfile<<endl;
674 AliTPCClustersArray *arr=0;
675 for(Int_t event=0; event<nevent; event++)
681 Int_t nparticles = gAlice->GetEvent(event);
682 Int_t nprimaries = 0;//FindPrimaries(nparticles);
683 cout<<"Event "<<event<<" had "<<nparticles<<" particles and "<<nprimaries<<" primaries"<<endl;
686 //Get the exact clusters from file:
687 AliTPCClustersArray *arr = new AliTPCClustersArray;
689 arr->SetClusterType("AliComplexCluster");
691 sprintf(treeName,"TreeCExact_%s_%d",param->GetTitle(),event);
692 Bool_t clusterok = arr->ConnectTree(treeName);//Segment Tree (for offline clusters)
693 if(!clusterok) {printf("AliL3Evaluate::EvaluatePoints : Error in clusterloading\n"); return;}
695 //cout<<"Entering loop with "<<(Int_t)arr->GetTree()->GetEntries()<<endl;
696 for(Int_t i=0; i<arr->GetTree()->GetEntries(); i++)
698 //Get the exact clusters for this row:
700 AliSegmentID *s = arr->LoadEntry(i);
701 param->AdjustSectorRow(s->GetID(),cursec,currow);
703 AliTPCClustersRow *ro = (AliTPCClustersRow *)arr->GetRow(cursec,currow);
704 TClonesArray *clusters = ro->GetArray();
705 int num_of_offline=clusters->GetEntriesFast();
707 //Get the found clusters:
709 AliL3Transform::Sector2Slice(slice,padrow,cursec,currow);
710 if(slice < fMinSlice) continue;
711 if(slice > fMaxSlice) break;
713 Int_t patch = AliL3Transform::GetPatch(padrow);
716 AliL3SpacePointData *points = fClusters[slice][patch];
720 //cout<<"Slice "<<slice<<" padrow "<<padrow<<" has "<<num_of_offline<<" clusters "<<endl;
721 Int_t clustercount=0;
723 for(Int_t m=0; m<num_of_offline; m++)
725 AliComplexCluster *cluster = (AliComplexCluster *)clusters->UncheckedAt(m);
726 Int_t mcId = cluster->fTracks[0];
728 if(mcId <0) continue;
730 if(cluster->fY < 1 || cluster->fY > AliL3Transform::GetNPads(padrow) - 2 ||
731 cluster->fX < 1 || cluster->fX > AliL3Transform::GetNTimeBins() - 2)
736 AliL3Transform::Raw2Local(xyz_ex,cursec,currow,cluster->fY,cluster->fX);
738 //In function AliTPC::Hits2ExactClusters the time offset is not included,
739 //so we have to substract it again here.
741 xyz_ex[2]-=AliL3Transform::GetZOffset();
743 xyz_ex[2]+=AliL3Transform::GetZOffset();
746 if(param->GetPadRowRadii(cursec,currow)<230./250.*fabs(xyz_ex[2]))
749 TParticle *part = gAlice->Particle(mcId);
752 if(part->Pt() < fMinGoodPt) continue;
754 //Dont take secondaries, because in width calculation we assume primaries:
755 //if(!(part->TestBit(kPrimaryCharged))) continue;
756 if(part->GetFirstMother()>=0) continue;
759 for(UInt_t c=0; c<fNcl[slice][patch]; c++)
761 if((Int_t)points[c].fPadRow!=padrow) continue;
762 Float_t xyz_cl[3] = {points[c].fX,points[c].fY,points[c].fZ};
765 AliL3Transform::Global2Local(xyz_cl,cursec);
768 if(points[c].fTrackID[0] != mcId &&
769 points[c].fTrackID[1] != mcId &&
770 points[c].fTrackID[2] != mcId)
774 Float_t resy = xyz_cl[1] - xyz_ex[1];
775 Float_t resz = xyz_cl[2] - xyz_ex[2];
778 Int_t charge = (Int_t)points[c].fCharge;
779 Float_t beta = GetCrossingAngle(part,slice,padrow,xyz_ex);
780 Double_t tanl = xyz_ex[2]/sqrt(xyz_ex[0]*xyz_ex[0]+xyz_ex[1]*xyz_ex[1]);
781 Float_t psigmaY2 = AliL3Transform::GetParSigmaY2(padrow,xyz_ex[2],beta);
782 Float_t psigmaZ2 = AliL3Transform::GetParSigmaZ2(padrow,xyz_ex[2],tanl);
783 Float_t sigmaY2 = points[c].fSigmaY2;
784 Float_t sigmaZ2 = points[c].fSigmaZ2;
785 ntuppel->Fill(slice,padrow,charge,resy,resz,xyz_ex[2],part->Pt(),beta,sigmaY2,sigmaZ2,psigmaY2,psigmaZ2);
787 clustercount=tempcount;
789 ntuppel2->Fill(slice,padrow,clustercount,crosscount);
790 arr->ClearRow(cursec,currow);
796 TFile *ofile = TFile::Open(tofile,"RECREATE");
804 void AliL3Evaluate::GetCFeff(Char_t *path,Char_t *outfile,Int_t nevent,Bool_t sp)
806 //Evaluate the cluster finder efficiency.
809 cerr<<"AliL3Evaluate::GetCFeff : Compile with do_mc flag"<<endl;
812 TNtuple *ntuppel = new TNtuple("ntuppel","Cluster finder efficiency","slice:row:ncrossings:nclusters");
813 ntuppel->SetDirectory(0);
815 Char_t filename[1024];
816 sprintf(filename,"%s/alirunfile.root",path);
817 TFile *rfile = TFile::Open(filename);
818 gAlice = (AliRun*)rfile->Get("gAlice");
820 AliTPCParam *param = (AliTPCParam*)rfile->Get(AliL3Transform::GetParamName());
822 Int_t zero=param->GetZeroSup();
824 sprintf(filename,"%s/digitfile.root",path);
825 TFile *dfile = TFile::Open(filename);
827 for(Int_t event=0; event<nevent; event++)
831 gAlice->GetEvent(event);
832 Int_t np = gAlice->GetNtrack();
833 cout<<"Processing event "<<event<<" with "<<np<<" particles "<<endl;
835 sprintf(filename,"TreeD_75x40_100x60_150x60_%d",event);
836 TTree *TD=(TTree*)gDirectory->Get(filename);
837 AliSimDigits da, *digits=&da;
838 TD->GetBranch("Segment")->SetAddress(&digits);
840 Int_t crossed=0,recs=0;
841 Int_t *count = new Int_t[np]; //np number of particles.
844 for (i=0; i<np; i++) count[i]=0;
848 for(Int_t i=0; i<(Int_t)TD->GetEntries(); i++)
851 if (!TD->GetEvent(i)) continue;
852 param->AdjustSectorRow(digits->GetID(),sec,row);
853 AliL3Transform::Sector2Slice(sl,sr,sec,row);
854 if(sl < fMinSlice) continue;
855 if(sl > fMaxSlice) break;
856 cout<<"Processing slice "<<sl<<" row "<<sr<<endl;
859 Int_t it=digits->CurrentRow(), ip=digits->CurrentColumn();
860 Short_t dig = digits->GetDigit(it,ip);
862 if(dig<=param->GetZeroSup()) continue;
863 AliL3Transform::Raw2Local(xyz,sec,row,ip,it);
864 if(param->GetPadRowRadii(sec,row)<230./250.*fabs(xyz[2]))
867 Int_t idx0=digits->GetTrackID(it,ip,0);
868 Int_t idx1=digits->GetTrackID(it,ip,1);
869 Int_t idx2=digits->GetTrackID(it,ip,2);
871 if (idx0>=0 && dig>=zero) count[idx0]+=1;
872 if (idx1>=0 && dig>=zero) count[idx1]+=1;
873 if (idx2>=0 && dig>=zero) count[idx2]+=1;
874 } while (digits->Next());
875 for (Int_t j=0; j<np; j++)
877 TParticle *part = gAlice->Particle(j);
878 if(part->Pt() < fMinGoodPt) continue;
879 if(part->GetFirstMother() >= 0) continue;
880 if (count[j]>1) //at least two digits at this padrow
887 Int_t patch = AliL3Transform::GetPatch(sr);
890 AliL3SpacePointData *points = fClusters[sl][patch];
893 for(UInt_t k=0; k<fNcl[sl][patch]; k++)
895 if(points[k].fPadRow!=sr) continue;
898 ntuppel->Fill(sl,sr,crossed,recs);
904 TFile *file = TFile::Open(outfile,"RECREATE");
913 Float_t AliL3Evaluate::GetCrossingAngle(TParticle *part,Int_t slice,Int_t padrow,Float_t *xyz)
915 //Calculate the padrow crossing angle of the particle
917 Double_t kappa = AliL3Transform::GetBField()*AliL3Transform::GetBFact()/part->Pt();
919 Double_t radius = 1/fabs(kappa);
920 if(part->GetPdgCode() > 0) kappa = -kappa;
922 Float_t angl[1] = {part->Phi()};
924 AliL3Transform::Global2LocalAngle(angl,slice);
926 Double_t charge = -1.*kappa;
928 Double_t trackPhi0 = angl[0] + charge*0.5*AliL3Transform::Pi()/fabs(charge);
932 Double_t xc = x0 - radius * cos(trackPhi0);
933 Double_t yc = y0 - radius * sin(trackPhi0);
936 tangent[0] = -1.*(xyz[1] - yc)/radius;
937 tangent[1] = (xyz[0] - xc)/radius;
939 Double_t perp_padrow[2] = {1,0}; //locally in slice
941 Double_t cos_beta = fabs(tangent[0]*perp_padrow[0] + tangent[1]*perp_padrow[1]);
942 if(cos_beta > 1) cos_beta=1;
943 return acos(cos_beta);
946 Int_t AliL3Evaluate::FindPrimaries(Int_t nparticles)
949 Double_t vertcut = 0.001;
950 Double_t decacut = 3.;
951 Double_t timecut = 0.;
953 TParticle * part = gAlice->Particle(0);
954 Double_t xori = part->Vx();
955 Double_t yori = part->Vy();
956 Double_t zori = part->Vz();
957 for(Int_t iprim = 0; iprim<nparticles; iprim++){ //loop on tracks
959 part = gAlice->Particle(iprim);
960 char *xxx=strstr(part->GetName(),"XXX");
963 TParticlePDG *ppdg = part->GetPDG();
964 if(TMath::Abs(ppdg->Charge())!=3)continue; // only charged (no quarks)
966 Double_t dist=TMath::Sqrt((part->Vx()-xori)*(part->Vx()-xori)+(part->Vy()-yori)*(part->Vy()-yori)+(part->Vz()-zori)*(part->Vz()-zori));
967 if(dist>vertcut)continue; // cut on the vertex
969 if(part->T()>timecut)continue;
971 Double_t ptot=TMath::Sqrt(part->Px()*part->Px()+part->Py()*part->Py()+part->Pz()*part->Pz());
972 if(ptot==(TMath::Abs(part->Pz())))continue; // no beam particles
974 Bool_t prmch = kTRUE; // candidate primary track
975 Int_t fidau=part->GetFirstDaughter(); // cut on daughters
979 lasdau=part->GetLastDaughter();
983 for(Int_t j=fidau;j<=lasdau;j++){
984 TParticle *dau=gAlice->Particle(j);
985 Double_t distd=TMath::Sqrt((dau->Vx()-xori)*(dau->Vx()-xori)+(dau->Vy()-yori)*(dau->Vy()-yori)+(dau->Vz()-zori)*(dau->Vz()-zori));
986 if(distd<decacut)prmch=kFALSE; // eliminate if the decay is near the vertex
992 part->SetBit(kPrimaryCharged);