]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/trigger/AliBarrelRec_TPCparam.C
Added support for static libraries,
[u/mrichter/AliRoot.git] / HLT / trigger / AliBarrelRec_TPCparam.C
CommitLineData
6f388e0d 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. *
4 * *
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...) *
15 * *
16 * If mode='A' all 5 steps are executed *
17 * If mode='B' only steps 4-5 are executed *
18 * *
19 * Origin: A.Dainese, Padova, andrea.dainese@pd.infn.it *
20 * (from AliTPCtest.C & AliITStestV2.C by I.Belikov) *
21 ****************************************************************************/
22
23// structure for track references
24typedef struct {
25 Int_t lab;
26 Int_t pdg;
27 Int_t mumlab;
28 Int_t mumpdg;
29 Float_t Vx,Vy,Vz;
30 Float_t Px,Py,Pz;
31} RECTRACK;
32
33//===== Functions definition =================================================
34
35void CopyVtx(const Char_t *inName,const Char_t *outName);
36
37void ITSFindClustersV2(Char_t SlowOrFast,Char_t* path[1024]);
38
39void ITSFindTracksV2(Int_t *skipEvt,Char_t* path[1024]);
40
41void ITSMakeRefFile(Int_t *skipEvt,Char_t* path[1024]);
42
43void MarkEvtsToSkip(const Char_t *evtsName,Int_t *skipEvt);
44
45void PrimaryVertex(const Char_t *outName,Char_t vtxMode,Char_t* path[1024]);
46
47void TPCParamTracks(Int_t coll,Double_t Bfield,Char_t* path[1024]);
48
49Int_t UpdateEvtsToSkip(const Char_t *logName,const Char_t *evtsName);
50
51void VtxFromHeader(const Char_t *outName,Bool_t smear,Char_t* path[1024]);
52
53void VtxFromTracks(const Char_t *outName,Char_t* path[1024]);
54
55void ZvtxFromSPD(const Char_t *outName,Char_t* path[1024]);
56
57//=============================================================================
58
59// number of events to be processed
60Int_t gNevents;
61// magnetic field
62Double_t gBfieldValue;
63
64void AliBarrelRec_TPCparam(Int_t n=-1,Char_t mode='A',Char_t* path="./") {
65
66 //---------------------------------------------------------------------
67 // CONFIGURATION
68 //
69 // _Magnetic_field_
70 gBfieldValue = 0.4;
71 //
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
76 Int_t collcode = 0;
77 //
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';
83 //
84 // _Primary_vertex_for_ITS_tracking_
85 // Available choices:
86 // Vtx4Tracking = 'H' from event Header
87 // --- for Pb-Pb ---
88 // Vtx4Tracking = 'S' from event header + Smearing
89 // (x=15,y=15,z=10) micron
90 // --- for pp/pA ---
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)
94 // Available choices:
95 // Vtx4Analysis = 'C' Copy the same used for tracking
96 // --- for pp/pA ---
97 // Vtx4Analysis = 'T' x,y,z from Tracks
98 Char_t Vtx4Analysis = 'C';
99 //
100 // END CONFIGURATION
101 //---------------------------------------------------------------------
102
103 const Char_t *name=" AliBarrelRec_TPCparam";
104 printf("\n %s\n",name);
105 gBenchmark->Start(name);
106
107 if(n==-1) { // read number of events to be processed from file
108 Char_t falice[1024];
109 sprintf(falice,"%s/galice.root",path);
110 TFile *f = new TFile(falice);
111 gAlice = (AliRun*)f->Get("gAlice");
112 n = gAlice->GetEventsPerRun();
113 delete gAlice;
114 gAlice=0;
115 f->Close();
116 delete f;
117 printf(" All %d events in file will be processed\n",n);
118 }
119 gNevents = n;
120
121
122 // conversion constant for kalman tracks
123 AliKalmanTrack::SetConvConst(100/0.299792458/gBfieldValue);
124
125 // Selection of execution mode
126 switch(mode) {
127 case 'A':
128 // Build TPC tracks with parameterization
129 TPCParamTracks(collcode,gBfieldValue,path);
130
131 // ITS clusters
132 ITSFindClustersV2(SlowOrFast,path);
133
134 // Vertex for ITS tracking
135 Char_t fvertex[1024];
136 sprintf(fvertex,"%s/Vtx4Tracking.root",path);
137 PrimaryVertex(fvertex,Vtx4Tracking,path);
138
139 break;
140
141 case 'B':
142 printf(" ---> only tracking in ITS <---\n");
143
144 // Update list of events to be skipped
145 if(!UpdateEvtsToSkip("itstracking.log","evtsToSkip.dat")) return;
146
147 break;
148 }
149
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);
155
156 // Tracking in ITS
157 ITSFindTracksV2(skipEvt,path);
158
159 // Vertex for analysis
160 Char_t ftrack[1024];
161 sprintf(ftrack,"%s/AliITStracksV2.root",path);
162 PrimaryVertex(ftrack,Vtx4Analysis,path);
163
164 // Create ITS tracks reference file
165 ITSMakeRefFile(skipEvt,path);
166 delete [] skipEvt;
167
168 gBenchmark->Stop(name);
169 gBenchmark->Show(name);
170
171 return;
172}
173//-----------------------------------------------------------------------------
174void CopyVtx(const Char_t *inName,const Char_t *outName) {
175
176 // Open input and output files
177 TFile *inFile = new TFile(inName);
178 TFile *outFile = new TFile(outName,"update");
179
180 TDirectory *curdir;
181 Char_t vname[20];
182
183
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;
188 curdir = gDirectory;
189 outFile->cd();
190 vertex->Write();
191 curdir->cd();
192 vertex = 0;
193 }
194
195 inFile->Close();
196 outFile->Close();
197 delete inFile;
198 delete outFile;
199
200 return;
201}
202//-----------------------------------------------------------------------------
203void ITSFindClustersV2(Char_t SlowOrFast,Char_t* path="./") {
204
205 printf("\n------------------------------------\n");
206
207 const Char_t *name="ITSFindClustersV2";
208 printf("\n %s\n",name);
209 gBenchmark->Start(name);
210
211 //--- taken from AliITStestV2.C--------------------------------------
212 //
213 if (SlowOrFast=='f') {
214 //cerr<<"Fast AliITSRecPoint(s) !\n";
215 //gROOT->LoadMacro("$(ALICE_ROOT)/ITS/AliITSHits2FastRecPoints.C");
216 //AliITSHits2FastRecPoints();
217 } else {
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();
224 }
225 gROOT->LoadMacro("./AliITSFindClustersV2.C");
226 AliITSFindClustersV2(SlowOrFast,gNevents,path);
227 //
228 //--------------------------------------------------------------------
229
230
231 gBenchmark->Stop(name);
232 gBenchmark->Show(name);
233
234 return;
235}
236//-----------------------------------------------------------------------------
237Int_t ITSFindTracksV2(Int_t *skipEvt,Char_t* path="./") {
238
239 printf("\n------------------------------------\n");
240
241 const Char_t *name="ITSFindTracksV2";
242 printf("\n %s\n",name);
243 gBenchmark->Start(name);
244
245 Char_t ftrack[1024];
246 sprintf(ftrack,"%s/AliITStracksV2.root",path);
247 TFile *outFile = new TFile(ftrack,"recreate");
248 Char_t fparam[1024];
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);
257
258 AliITSgeom *geom=(AliITSgeom*)inClusters->Get("AliITSgeom");
259 if(!geom) { printf("can't get ITS geometry !\n"); return;}
260
261 Double_t vtx[3];
262 Int_t flag1stPass,flag2ndPass;
263 Char_t vname[20];
264
265 // open logfile for done events
266 FILE *logfile = fopen("itstracking.log","w");
267
268 // Instantiate AliITStrackerV2
269 AliITStrackerV2 tracker(geom);
270
271 // loop on events
272 for(Int_t ev=0; ev<gNevents; ev++){
273 // write to logfile of begun events
274 fprintf(logfile,"%d\n",ev);
275
276 if(skipEvt[ev]) continue;
277 printf(" --- Processing event %d ---\n",ev);
278
279 // pass event number to the tracker
280 tracker.SetEventNumber(ev);
281
282 // set position of primary vertex
283 sprintf(vname,"Vertex_%d",ev);
284 AliITSVertex *vertex = (AliITSVertex*)inVertex->Get(vname);
285 if(vertex) {
286 vertex->GetXYZ(vtx);
287 delete vertex;
288 } else {
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.;
292 }
293
294 flag1stPass=1; // vtx constraint
295 flag2ndPass=0; // no vtx constraint
296
297 // no vtx constraint if vertex not found
298 if(vtx[2]<-999.) {
299 flag1stPass=0;
300 vtx[2]=0.;
301 }
302
303 tracker.SetVertex(vtx);
304
305 // setup vertex constraint in the two tracking passes
306 Int_t flags[2];
307 flags[0]=flag1stPass;
308 tracker.SetupFirstPass(flags);
309 flags[0]=flag2ndPass;
310 tracker.SetupSecondPass(flags);
311
312 // find the tracks
313 tracker.Clusters2Tracks(inTPCtrks,outFile);
314
315 } // loop on events
316
317 fprintf(logfile,"%d\n",gNevents); //this means all evts are successfully completed
318 fclose(logfile);
319
320 delete geom;
321
322 inTPCtrks->Close();
323 inClusters->Close();
324 inVertex->Close();
325 outFile->Close();
326
327
328 gBenchmark->Stop(name);
329 gBenchmark->Show(name);
330
331 return;
332}
333//-----------------------------------------------------------------------------
334void ITSMakeRefFile(Int_t *skipEvt,Char_t* path="./") {
335
336 printf("\n------------------------------------\n");
337
338 const Char_t *name="ITSMakeRefFile";
339 printf("\n %s\n",name);
340 gBenchmark->Start(name);
341
342 Char_t fref[1024];
343 sprintf(fref,"%s/ITStracksRefFile.root",path);
344 TFile *out = TFile::Open(fref,"recreate");
345 Char_t ftrack[1024];
346 sprintf(ftrack,"%s/AliITStracksV2.root",path);
347 TFile *trk = TFile::Open(ftrack);
348 Char_t falice[1024];
349 sprintf(falice,"%s/galice.root",path);
350 TFile *kin = TFile::Open(falice);
351
352
353 // Get gAlice object from file
354 gAlice=(AliRun*)kin->Get("gAlice");
355
356 Int_t label;
357 TParticle *Part;
358 TParticle *Mum;
359 RECTRACK rectrk;
360
361
362 for(Int_t ev=0; ev<gNevents; ev++){
363 if(skipEvt[ev]) continue;
364 printf(" --- Processing event %d ---\n",ev);
365
366 gAlice->GetEvent(ev);
367
368 trk->cd();
369
370 // Tree with ITS tracks
371 char tname[100];
372 sprintf(tname,"TreeT_ITS_%d",ev);
373
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();
379
380 // Tree for true track parameters
381 char ttname[100];
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");
385
386 for(Int_t i=0; i<nentr; i++) {
387 tracktree->GetEvent(i);
388 label = TMath::Abs(itstrack->GetLabel());
389
390 Part = (TParticle*)gAlice->Particle(label);
391 rectrk.lab=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();
397 } else {
398 rectrk.mumpdg=-1;
399 }
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();
406
407 reftree->Fill();
408 } // loop on tracks
409
410 out->cd();
411 reftree->Write();
412
413 delete itstrack;
414 delete reftree;
415 } // loop on events
416
417 trk->Close();
418 kin->Close();
419 out->Close();
420
421 gBenchmark->Stop(name);
422 gBenchmark->Show(name);
423
424
425 return;
426}
427//-----------------------------------------------------------------------------
428void MarkEvtsToSkip(const Char_t *evtsName,Int_t *skipEvt) {
429
430 printf("\n------------------------------------\n");
431 printf("\nChecking for events to skip...\n");
432
433 Int_t evt,ncol;
434
435 FILE *f = fopen(evtsName,"r");
436 while(1) {
437 ncol = fscanf(f,"%d",&evt);
438 if(ncol<1) break;
439 skipEvt[evt] = 1;
440 printf(" event %d will be skipped\n",evt);
441 }
442 fclose(f);
443
444 return;
445}
446//-----------------------------------------------------------------------------
447void PrimaryVertex(const Char_t *outName,Char_t vtxMode,Char_t* path="./") {
448
449 printf("\n------------------------------------\n");
450
451 const Char_t *name="PrimaryVertex";
452 printf("\n %s\n",name);
453 gBenchmark->Start(name);
454
455 switch(vtxMode) {
456 case 'H':
457 printf(" ... from event header\n");
458 VtxFromHeader(outName,kFALSE,path);
459 break;
460 case 'S':
461 printf(" ... from event header + smearing\n");
462 VtxFromHeader(outName,kTRUE);
463 break;
464 case 'P':
465 printf(" ... z from pixels for pp/pA\n");
466 ZvtxFromSPD(outName);
467 break;
468 case 'T':
469 printf(" ... from tracks for pp/pA\n");
470 VtxFromTracks(outName);
471 break;
472 case 'C':
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);
477 break;
478 }
479
480 gBenchmark->Stop(name);
481 gBenchmark->Show(name);
482
483 return;
484}
485//-----------------------------------------------------------------------------
486void TPCParamTracks(Int_t coll,Double_t Bfield,Char_t* path="./") {
487
488 printf("\n------------------------------------\n");
489
490 const Char_t *name="TPCParamTracks";
491 printf("\n %s\n",name);
492 gBenchmark->Start(name);
493
494 Char_t fparam[1024];
495 sprintf(fparam,"%s/AliTPCtracksParam.root",path);
496 TFile *outFile=TFile::Open(fparam,"recreate");
497 Char_t falice[1024];
498 sprintf(falice,"%s/galice.root",path);
499 TFile *inFile =TFile::Open(falice);
500
501 AliTPCtrackerParam tracker(coll,Bfield,gNevents);
502 tracker.BuildTPCtracks(inFile,outFile);
503
504 delete gAlice; gAlice=0;
505
506 inFile->Close();
507 outFile->Close();
508
509 gBenchmark->Stop(name);
510 gBenchmark->Show(name);
511
512 return;
513}
514//-----------------------------------------------------------------------------
515Int_t UpdateEvtsToSkip(const Char_t *logName,const Char_t *evtsName) {
516
517 if(!gSystem->AccessPathName(logName,kFileExists)) {
518 FILE *ifile = fopen(logName,"r");
519 Int_t lEvt=0,nCol=1;
520 while(nCol>0) {
521 nCol = fscanf(ifile,"%d",&lEvt);
522 }
523 fclose(ifile);
524 if(lEvt==gNevents) {
525 printf(" All events already reconstructed\n");
526 return 0;
527 } else {
528 FILE *ofile = fopen("evtsToSkip.dat","a");
529 fprintf(ofile,"%d\n",lEvt);
530 fclose(ofile);
531 }
532 } else {
533 printf("File itstracking.log not found\n");
534 }
535
536 return 1;
537}
538//-----------------------------------------------------------------------------
539void VtxFromHeader(const Char_t *outName,Bool_t smear,Char_t* path="./") {
540
541 TDatime t;
542 UInt_t seed = t.Get();
543 gRandom->SetSeed(seed);
544
545 Char_t falice[1024];
546 sprintf(falice,"%s/galice.root",path);
547 TFile *galice = new TFile(falice);
548 TFile *outFile = new TFile(outName,"update");
549
550 TDirectory *curdir;
551 Double_t pos[3],sigma[3];
552 if(smear) {
553 sigma[0]=15.e-4;
554 sigma[1]=15.e-4;
555 sigma[2]=10.e-4;
556 } else {
557 sigma[0]=0.;
558 sigma[1]=0.;
559 sigma[2]=0.;
560 }
561 Char_t vname[20];
562
563 galice->cd();
564
565 for(Int_t ev=0; ev<gNevents; ev++){
566 printf(" event %d\n",ev);
567 sprintf(vname,"Vertex_%d",ev);
568 TArrayF o = 0;
569 o.Set(3);
570 AliHeader* header = 0;
571 TTree* treeE = (TTree*)gDirectory->Get("TE");
572 treeE->SetBranchAddress("Header",&header);
573 treeE->GetEntry(ev);
574 AliGenEventHeader* genHeader = header->GenEventHeader();
575 if(genHeader) {
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];
581
582 if(smear) {
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]);
586 }
587 // create AliITSVertex
588 AliITSVertex *vertex = new AliITSVertex(pos,sigma,vname);
589 } else {
590 printf(" ! event header not found : setting vertex to (0,0,0) !");
591 pos[0] = 0.;
592 pos[1] = 0.;
593 pos[2] = 0.;
594 // create AliITSVertex
595 AliITSVertex *vertex = new AliITSVertex(pos,sigma,vname);
596 }
597 delete header;
598 // write AliITSVertex to file
599 curdir = gDirectory;
600 outFile->cd();
601 if(smear) {
602 vertex->SetTitle("vertex from header, smeared");
603 } else {
604 vertex->SetTitle("vertex from header");
605 }
606 vertex->Write();
607 curdir->cd();
608 vertex = 0;
609 }
610
611 outFile->Close();
612 galice->Close();
613
614 delete outFile;
615 delete galice;
616
617 return;
618}
619//-----------------------------------------------------------------------------
620void VtxFromTracks(const Char_t *outName,Char_t* path="./") {
621
622 // Open input and output files
623 Char_t ftrack[1024];
624 sprintf(ftrack,"%s/AliITStracksV2.root",path);
625 TFile *inFile = new TFile(ftrack);
626 TFile *outFile = new TFile(outName,"update");
627
628 // set AliRun object to 0
629 if(gAlice) gAlice = 0;
630
631 // Create vertexer
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();
638 // Find vertices
639 vertexer->FindVertices();
640
641 delete vertexer;
642
643 inFile->Close();
644 outFile->Close();
645 delete inFile;
646 delete outFile;
647
648 return;
649}
650//-----------------------------------------------------------------------------
651void ZvtxFromSPD(const Char_t *outName,Char_t* path="./") {
652
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);
657
658 // delphi ---> azimuthal range to accept tracklets
659 // window ---> window in Z around the peak of tracklets proj. in mm
660 Float_t delphi=0.05;
661 Float_t window=3.;
662 Float_t initx=0.;
663 Float_t inity=0.;
664
665 Char_t falice[1024];
666 sprintf(falice,"%s/galice.root",path);
667 TFile *infile = new TFile(falice);
668 TFile *outfile = new TFile(outName,"update");
669
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();
678 delete vertexer;
679 vertexer=0;
680
681 outfile->Close();
682 infile->Close();
683 delete infile;
684 delete outfile;
685
686
687 return;
688}
689//-----------------------------------------------------------------------------
690
691
692
693
694
695
696
697
698