1 /****************************************************************************
2 * This macro performs track and vertex reconstruction in TPC and ITS. *
3 * The ITS Kalman tracker V2 is feeded "with" parameterized TPC tracks. *
5 * Reconstruction is performed in the following steps: *
6 * 1) TPC tracking parameterization *
7 * 2) ITS clusters: slow or fast *
8 * 3) Primary vertex reconstruction *
9 * - read from event header for Pb-Pb events *
10 * - determined using points in pixels for pp/pA events *
11 * 4) ITS track finding V2 *
12 * - in pp/pA, redetermine the position of primary vertex *
13 * using the reconstructed tracks *
14 * 5) Create a reference file with simulation info (p,PDG...) *
16 * If mode='A' all 5 steps are executed *
17 * If mode='B' only steps 4-5 are executed *
19 * Origin: A.Dainese, Padova, andrea.dainese@pd.infn.it *
20 * (from AliTPCtest.C & AliITStestV2.C by I.Belikov) *
21 ****************************************************************************/
23 // structure for track references
33 //===== Functions definition =================================================
35 void CopyVtx(const Char_t *inName,const Char_t *outName);
37 void ITSFindClustersV2(Char_t SlowOrFast,Char_t* path[1024]);
39 void ITSFindTracksV2(Int_t *skipEvt,Char_t* path[1024]);
41 void ITSMakeRefFile(Int_t *skipEvt,Char_t* path[1024]);
43 void MarkEvtsToSkip(const Char_t *evtsName,Int_t *skipEvt);
45 void PrimaryVertex(const Char_t *outName,Char_t vtxMode,Char_t* path[1024]);
47 void TPCParamTracks(Int_t coll,Double_t Bfield,Char_t* path[1024]);
49 Int_t UpdateEvtsToSkip(const Char_t *logName,const Char_t *evtsName);
51 void VtxFromHeader(const Char_t *outName,Bool_t smear,Char_t* path[1024]);
53 void VtxFromTracks(const Char_t *outName,Char_t* path[1024]);
55 void ZvtxFromSPD(const Char_t *outName,Char_t* path[1024]);
57 //=============================================================================
59 // number of events to be processed
62 Double_t gBfieldValue;
64 void AliBarrelRec_TPCparam(Int_t n=-1,Char_t mode='A',Char_t* path="./") {
66 //---------------------------------------------------------------------
72 // _Type_of_collision_ (needed for TPC tracking parameterization)
73 // Available choices: !!! ONLY B = 0.4 TESLA !!!
74 // collcode = 0 -> PbPb6000 (HIJING with b<2fm)
75 // collcode = 1 -> low multiplicity: pp or pA
78 // _ITS_clusters_reconstruction_
79 // Available choices: (from AliITStestV2.C)
80 // SlowOrFast = 's' slow points
81 // SlowOrFast = 'f' fast points
82 Char_t SlowOrFast = 'f';
84 // _Primary_vertex_for_ITS_tracking_
86 // Vtx4Tracking = 'H' from event Header
88 // Vtx4Tracking = 'S' from event header + Smearing
89 // (x=15,y=15,z=10) micron
91 // Vtx4Tracking = 'P' z from pixels, x,y in(0,0)
92 Char_t Vtx4Tracking = 'H';
93 // _Primary_vertex_for_analysis_ (AliITSVertex stored in tracks file)
95 // Vtx4Analysis = 'C' Copy the same used for tracking
97 // Vtx4Analysis = 'T' x,y,z from Tracks
98 Char_t Vtx4Analysis = 'C';
101 //---------------------------------------------------------------------
103 const Char_t *name=" AliBarrelRec_TPCparam";
104 printf("\n %s\n",name);
105 gBenchmark->Start(name);
107 if(n==-1) { // read number of events to be processed from file
109 sprintf(falice,"%s/galice.root",path);
110 TFile *f = new TFile(falice);
111 gAlice = (AliRun*)f->Get("gAlice");
112 n = gAlice->GetEventsPerRun();
117 printf(" All %d events in file will be processed\n",n);
122 // conversion constant for kalman tracks
123 AliKalmanTrack::SetConvConst(100/0.299792458/gBfieldValue);
125 // Selection of execution mode
128 // Build TPC tracks with parameterization
129 TPCParamTracks(collcode,gBfieldValue,path);
132 ITSFindClustersV2(SlowOrFast,path);
134 // Vertex for ITS tracking
135 Char_t fvertex[1024];
136 sprintf(fvertex,"%s/Vtx4Tracking.root",path);
137 PrimaryVertex(fvertex,Vtx4Tracking,path);
142 printf(" ---> only tracking in ITS <---\n");
144 // Update list of events to be skipped
145 if(!UpdateEvtsToSkip("itstracking.log","evtsToSkip.dat")) return;
150 // Mark events that have to be skipped (if any)
151 Int_t *skipEvt = new Int_t[gNevents];
152 for(Int_t i=0; i<gNevents; i++) skipEvt[i] = 0;
153 if(!gSystem->AccessPathName("evtsToSkip.dat",kFileExists))
154 MarkEvtsToSkip("evtsToSkip.dat",skipEvt);
157 ITSFindTracksV2(skipEvt,path);
159 // Vertex for analysis
161 sprintf(ftrack,"%s/AliITStracksV2.root",path);
162 PrimaryVertex(ftrack,Vtx4Analysis,path);
164 // Create ITS tracks reference file
165 ITSMakeRefFile(skipEvt,path);
168 gBenchmark->Stop(name);
169 gBenchmark->Show(name);
173 //-----------------------------------------------------------------------------
174 void CopyVtx(const Char_t *inName,const Char_t *outName) {
176 // Open input and output files
177 TFile *inFile = new TFile(inName);
178 TFile *outFile = new TFile(outName,"update");
184 for(Int_t ev=0; ev<gNevents; ev++) {
185 sprintf(vname,"Vertex_%d",ev);
186 AliITSVertex *vertex = (AliITSVertex*)inFile->Get(vname);
187 if(!vertex) continue;
202 //-----------------------------------------------------------------------------
203 void ITSFindClustersV2(Char_t SlowOrFast,Char_t* path="./") {
205 printf("\n------------------------------------\n");
207 const Char_t *name="ITSFindClustersV2";
208 printf("\n %s\n",name);
209 gBenchmark->Start(name);
211 //--- taken from AliITStestV2.C--------------------------------------
213 if (SlowOrFast=='f') {
214 //cerr<<"Fast AliITSRecPoint(s) !\n";
215 //gROOT->LoadMacro("$(ALICE_ROOT)/ITS/AliITSHits2FastRecPoints.C");
216 //AliITSHits2FastRecPoints();
218 gROOT->LoadMacro("$(ALICE_ROOT)/ITS/AliITSHits2SDigits.C");
219 AliITSHits2SDigits();
220 gROOT->LoadMacro("$(ALICE_ROOT)/ITS/AliITSSDigits2Digits.C");
221 AliITSSDigits2Digits();
222 //gROOT->LoadMacro("$(ALICE_ROOT)/ITS/AliITSDigits2RecPoints.C");
223 //AliITSDigits2RecPoints();
225 gROOT->LoadMacro("./AliITSFindClustersV2.C");
226 AliITSFindClustersV2(SlowOrFast,gNevents,path);
228 //--------------------------------------------------------------------
231 gBenchmark->Stop(name);
232 gBenchmark->Show(name);
236 //-----------------------------------------------------------------------------
237 Int_t ITSFindTracksV2(Int_t *skipEvt,Char_t* path="./") {
239 printf("\n------------------------------------\n");
241 const Char_t *name="ITSFindTracksV2";
242 printf("\n %s\n",name);
243 gBenchmark->Start(name);
246 sprintf(ftrack,"%s/AliITStracksV2.root",path);
247 TFile *outFile = new TFile(ftrack,"recreate");
249 sprintf(fparam,"%s/AliTPCtracksParam.root",path);
250 TFile *inTPCtrks = new TFile(fparam);
251 Char_t fvertex[1024];
252 sprintf(fvertex,"%s/Vtx4Tracking.root",path);
253 TFile *inVertex = new TFile(fvertex);
254 Char_t fcluster[1024];
255 sprintf(fcluster,"%s/AliITSclustersV2.root",path);
256 TFile *inClusters = new TFile(fcluster);
258 AliITSgeom *geom=(AliITSgeom*)inClusters->Get("AliITSgeom");
259 if(!geom) { printf("can't get ITS geometry !\n"); return;}
262 Int_t flag1stPass,flag2ndPass;
265 // open logfile for done events
266 FILE *logfile = fopen("itstracking.log","w");
268 // Instantiate AliITStrackerV2
269 AliITStrackerV2 tracker(geom);
272 for(Int_t ev=0; ev<gNevents; ev++){
273 // write to logfile of begun events
274 fprintf(logfile,"%d\n",ev);
276 if(skipEvt[ev]) continue;
277 printf(" --- Processing event %d ---\n",ev);
279 // pass event number to the tracker
280 tracker.SetEventNumber(ev);
282 // set position of primary vertex
283 sprintf(vname,"Vertex_%d",ev);
284 AliITSVertex *vertex = (AliITSVertex*)inVertex->Get(vname);
289 printf(" AliITSVertex not found for event %d\n",ev);
290 printf(" Using (0,0,0) for ITS tracking\n");
291 vtx[0] = vtx[1] = vtx[2] = 0.;
294 flag1stPass=1; // vtx constraint
295 flag2ndPass=0; // no vtx constraint
297 // no vtx constraint if vertex not found
303 tracker.SetVertex(vtx);
305 // setup vertex constraint in the two tracking passes
307 flags[0]=flag1stPass;
308 tracker.SetupFirstPass(flags);
309 flags[0]=flag2ndPass;
310 tracker.SetupSecondPass(flags);
313 tracker.Clusters2Tracks(inTPCtrks,outFile);
317 fprintf(logfile,"%d\n",gNevents); //this means all evts are successfully completed
328 gBenchmark->Stop(name);
329 gBenchmark->Show(name);
333 //-----------------------------------------------------------------------------
334 void ITSMakeRefFile(Int_t *skipEvt,Char_t* path="./") {
336 printf("\n------------------------------------\n");
338 const Char_t *name="ITSMakeRefFile";
339 printf("\n %s\n",name);
340 gBenchmark->Start(name);
343 sprintf(fref,"%s/ITStracksRefFile.root",path);
344 TFile *out = TFile::Open(fref,"recreate");
346 sprintf(ftrack,"%s/AliITStracksV2.root",path);
347 TFile *trk = TFile::Open(ftrack);
349 sprintf(falice,"%s/galice.root",path);
350 TFile *kin = TFile::Open(falice);
353 // Get gAlice object from file
354 gAlice=(AliRun*)kin->Get("gAlice");
362 for(Int_t ev=0; ev<gNevents; ev++){
363 if(skipEvt[ev]) continue;
364 printf(" --- Processing event %d ---\n",ev);
366 gAlice->GetEvent(ev);
370 // Tree with ITS tracks
372 sprintf(tname,"TreeT_ITS_%d",ev);
374 TTree *tracktree=(TTree*)trk->Get(tname);
375 if(!tracktree) continue;
376 AliITStrackV2 *itstrack=new AliITStrackV2;
377 tracktree->SetBranchAddress("tracks",&itstrack);
378 Int_t nentr=(Int_t)tracktree->GetEntries();
380 // Tree for true track parameters
382 sprintf(ttname,"Tree_Ref_%d",ev);
383 TTree *reftree = new TTree(ttname,"Tree with true track params");
384 reftree->Branch("rectracks",&rectrk,"lab/I:pdg:mumlab:mumpdg:Vx/F:Vy:Vz:Px:Py:Pz");
386 for(Int_t i=0; i<nentr; i++) {
387 tracktree->GetEvent(i);
388 label = TMath::Abs(itstrack->GetLabel());
390 Part = (TParticle*)gAlice->Particle(label);
392 rectrk.pdg=Part->GetPdgCode();
393 rectrk.mumlab = Part->GetFirstMother();
394 if(Part->GetFirstMother()>=0) {
395 Mum = (TParticle*)gAlice->Particle(Part->GetFirstMother());
396 rectrk.mumpdg=Mum->GetPdgCode();
400 rectrk.Vx=Part->Vx();
401 rectrk.Vy=Part->Vy();
402 rectrk.Vz=Part->Vz();
403 rectrk.Px=Part->Px();
404 rectrk.Py=Part->Py();
405 rectrk.Pz=Part->Pz();
421 gBenchmark->Stop(name);
422 gBenchmark->Show(name);
427 //-----------------------------------------------------------------------------
428 void MarkEvtsToSkip(const Char_t *evtsName,Int_t *skipEvt) {
430 printf("\n------------------------------------\n");
431 printf("\nChecking for events to skip...\n");
435 FILE *f = fopen(evtsName,"r");
437 ncol = fscanf(f,"%d",&evt);
440 printf(" event %d will be skipped\n",evt);
446 //-----------------------------------------------------------------------------
447 void PrimaryVertex(const Char_t *outName,Char_t vtxMode,Char_t* path="./") {
449 printf("\n------------------------------------\n");
451 const Char_t *name="PrimaryVertex";
452 printf("\n %s\n",name);
453 gBenchmark->Start(name);
457 printf(" ... from event header\n");
458 VtxFromHeader(outName,kFALSE,path);
461 printf(" ... from event header + smearing\n");
462 VtxFromHeader(outName,kTRUE);
465 printf(" ... z from pixels for pp/pA\n");
466 ZvtxFromSPD(outName);
469 printf(" ... from tracks for pp/pA\n");
470 VtxFromTracks(outName);
473 Char_t fvertex[1024];
474 sprintf(fvertex,"%s/Vtx4Tracking.root",path);
475 printf(" ... copied from Vtx4Tracking.root to AliITStracksV2.root\n");
476 CopyVtx(fvertex,outName);
480 gBenchmark->Stop(name);
481 gBenchmark->Show(name);
485 //-----------------------------------------------------------------------------
486 void TPCParamTracks(Int_t coll,Double_t Bfield,Char_t* path="./") {
488 printf("\n------------------------------------\n");
490 const Char_t *name="TPCParamTracks";
491 printf("\n %s\n",name);
492 gBenchmark->Start(name);
495 sprintf(fparam,"%s/AliTPCtracksParam.root",path);
496 TFile *outFile=TFile::Open(fparam,"recreate");
498 sprintf(falice,"%s/galice.root",path);
499 TFile *inFile =TFile::Open(falice);
501 AliTPCtrackerParam tracker(coll,Bfield,gNevents);
502 tracker.BuildTPCtracks(inFile,outFile);
504 delete gAlice; gAlice=0;
509 gBenchmark->Stop(name);
510 gBenchmark->Show(name);
514 //-----------------------------------------------------------------------------
515 Int_t UpdateEvtsToSkip(const Char_t *logName,const Char_t *evtsName) {
517 if(!gSystem->AccessPathName(logName,kFileExists)) {
518 FILE *ifile = fopen(logName,"r");
521 nCol = fscanf(ifile,"%d",&lEvt);
525 printf(" All events already reconstructed\n");
528 FILE *ofile = fopen("evtsToSkip.dat","a");
529 fprintf(ofile,"%d\n",lEvt);
533 printf("File itstracking.log not found\n");
538 //-----------------------------------------------------------------------------
539 void VtxFromHeader(const Char_t *outName,Bool_t smear,Char_t* path="./") {
542 UInt_t seed = t.Get();
543 gRandom->SetSeed(seed);
546 sprintf(falice,"%s/galice.root",path);
547 TFile *galice = new TFile(falice);
548 TFile *outFile = new TFile(outName,"update");
551 Double_t pos[3],sigma[3];
565 for(Int_t ev=0; ev<gNevents; ev++){
566 printf(" event %d\n",ev);
567 sprintf(vname,"Vertex_%d",ev);
570 AliHeader* header = 0;
571 TTree* treeE = (TTree*)gDirectory->Get("TE");
572 treeE->SetBranchAddress("Header",&header);
574 AliGenEventHeader* genHeader = header->GenEventHeader();
576 // get primary vertex position
577 genHeader->PrimaryVertex(o);
578 pos[0] = (Double_t)o[0];
579 pos[1] = (Double_t)o[1];
580 pos[2] = (Double_t)o[2];
583 pos[0] = gRandom->Gaus(pos[0],sigma[0]);
584 pos[1] = gRandom->Gaus(pos[1],sigma[1]);
585 pos[2] = gRandom->Gaus(pos[2],sigma[2]);
587 // create AliITSVertex
588 AliITSVertex *vertex = new AliITSVertex(pos,sigma,vname);
590 printf(" ! event header not found : setting vertex to (0,0,0) !");
594 // create AliITSVertex
595 AliITSVertex *vertex = new AliITSVertex(pos,sigma,vname);
598 // write AliITSVertex to file
602 vertex->SetTitle("vertex from header, smeared");
604 vertex->SetTitle("vertex from header");
619 //-----------------------------------------------------------------------------
620 void VtxFromTracks(const Char_t *outName,Char_t* path="./") {
622 // Open input and output files
624 sprintf(ftrack,"%s/AliITStracksV2.root",path);
625 TFile *inFile = new TFile(ftrack);
626 TFile *outFile = new TFile(outName,"update");
628 // set AliRun object to 0
629 if(gAlice) gAlice = 0;
632 AliITSVertexerTracks *vertexer =
633 new AliITSVertexerTracks(inFile,outFile,gBfieldValue);
634 vertexer->SetFirstEvent(0);
635 vertexer->SetLastEvent(gNevents-1);
636 vertexer->SetDebug(0);
637 vertexer->PrintStatus();
639 vertexer->FindVertices();
650 //-----------------------------------------------------------------------------
651 void ZvtxFromSPD(const Char_t *outName,Char_t* path="./") {
653 // create fast RecPoints, which are used for vertex finding
654 cerr<<"Fast AliITSRecPoint(s) !\n";
655 gROOT->LoadMacro("$(ALICE_ROOT)/ITS/AliITSHits2FastRecPoints.C");
656 AliITSHits2FastRecPoints(0,gNevents-1);
658 // delphi ---> azimuthal range to accept tracklets
659 // window ---> window in Z around the peak of tracklets proj. in mm
666 sprintf(falice,"%s/galice.root",path);
667 TFile *infile = new TFile(falice);
668 TFile *outfile = new TFile(outName,"update");
670 AliITSVertexerPPZ *vertexer = new AliITSVertexerPPZ(infile,outfile,initx,inity);
671 vertexer->SetFirstEvent(0);
672 vertexer->SetLastEvent(gNevents-1);
673 vertexer->SetDebug(0);
674 vertexer->SetDiffPhiMax(delphi);
675 vertexer->SetWindow(window);
676 vertexer->PrintStatus();
677 vertexer->FindVertices();
689 //-----------------------------------------------------------------------------