]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HBTAN/AliHBTReaderTPC.cxx
Coding Violations Corrected.
[u/mrichter/AliRoot.git] / HBTAN / AliHBTReaderTPC.cxx
CommitLineData
1b446896 1#include "AliHBTReaderTPC.h"
3f745d47 2//______________________________________________
3//
4// class AliHBTReaderTPC
5//
c0cebee1 6// reader for TPC tracks
7// needs galice.root
8// just to shut up coding conventions checker
9//
3f745d47 10// more info: http://aliweb.cern.ch/people/skowron/analyzer/index.html
11// Piotr.Skowronski@cern.ch
12//
13///////////////////////////////////////////////////////////////////////////
1b446896 14#include <TTree.h>
16701d1b 15#include <TParticle.h>
bfb09ece 16#include <TH1.h>
1b446896 17
bed069a4 18
16701d1b 19#include <AliRun.h>
88cb7938 20#include <AliLoader.h>
21#include <AliStack.h>
16701d1b 22#include <AliMagF.h>
1b446896 23#include <AliTPCtrack.h>
24#include <AliTPCParam.h>
bed069a4 25#include <AliTPCLoader.h>
1b446896 26
1b446896 27#include "AliHBTEvent.h"
28#include "AliHBTParticle.h"
f5de2f09 29#include "AliHBTTrackPoints.h"
66d1d1a4 30#include "AliHBTClusterMap.h"
bfb09ece 31
32
1b446896 33ClassImp(AliHBTReaderTPC)
3f745d47 34
bed069a4 35AliHBTReaderTPC::AliHBTReaderTPC():
36 fFileName("galice.root"),
37 fRunLoader(0x0),
38 fTPCLoader(0x0),
39 fMagneticField(0.0),
3f745d47 40 fUseMagFFromRun(kTRUE),
f5de2f09 41 fNTrackPoints(0),
42 fdR(0.0),
66d1d1a4 43 fClusterMap(kFALSE),
3f745d47 44 fNClustMin(0),
f5de2f09 45 fNClustMax(150),
3f745d47 46 fNChi2PerClustMin(0.0),
47 fNChi2PerClustMax(10e5),
f5de2f09 48 fC00Min(0.0),
49 fC00Max(10e5),
50 fC11Min(0.0),
51 fC11Max(10e5),
52 fC22Min(0.0),
53 fC22Max(10e5),
54 fC33Min(0.0),
55 fC33Max(10e5),
3f745d47 56 fC44Min(0.0),
57 fC44Max(10e5)
88cb7938 58{
f5de2f09 59 //constructor
88cb7938 60
88cb7938 61}
f5de2f09 62/********************************************************************/
98295f4b 63
bed069a4 64AliHBTReaderTPC::AliHBTReaderTPC(const Char_t* galicefilename):
65 fFileName(galicefilename),
66 fRunLoader(0x0),
67 fTPCLoader(0x0),
68 fMagneticField(0.0),
3f745d47 69 fUseMagFFromRun(kTRUE),
f5de2f09 70 fNTrackPoints(0),
71 fdR(0.0),
3f745d47 72 fNClustMin(0),
f5de2f09 73 fNClustMax(150),
3f745d47 74 fNChi2PerClustMin(0.0),
75 fNChi2PerClustMax(10e5),
f5de2f09 76 fC00Min(0.0),
77 fC00Max(10e5),
78 fC11Min(0.0),
79 fC11Max(10e5),
80 fC22Min(0.0),
81 fC22Max(10e5),
82 fC33Min(0.0),
83 fC33Max(10e5),
3f745d47 84 fC44Min(0.0),
85 fC44Max(10e5)
1b446896 86{
16701d1b 87 //constructor,
1b446896 88 //Defaults:
16701d1b 89}
90/********************************************************************/
f5de2f09 91
88cb7938 92AliHBTReaderTPC::AliHBTReaderTPC(TObjArray* dirs, const Char_t* galicefilename):
bed069a4 93 AliHBTReader(dirs),
94 fFileName(galicefilename),
95 fRunLoader(0x0),
96 fTPCLoader(0x0),
97 fMagneticField(0.0),
3f745d47 98 fUseMagFFromRun(kTRUE),
f5de2f09 99 fNTrackPoints(0),
100 fdR(0.0),
66d1d1a4 101 fClusterMap(kFALSE),
3f745d47 102 fNClustMin(0),
f5de2f09 103 fNClustMax(150),
3f745d47 104 fNChi2PerClustMin(0.0),
105 fNChi2PerClustMax(10e5),
f5de2f09 106 fC00Min(0.0),
107 fC00Max(10e5),
108 fC11Min(0.0),
109 fC11Max(10e5),
110 fC22Min(0.0),
111 fC22Max(10e5),
112 fC33Min(0.0),
113 fC33Max(10e5),
3f745d47 114 fC44Min(0.0),
115 fC44Max(10e5)
16701d1b 116{
117 //constructor,
118 //Defaults:
16701d1b 119 // galicefilename = "" - this means: Do not open gAlice file -
120 // just leave the global pointer untached
88cb7938 121
1b446896 122}
123/********************************************************************/
c0cebee1 124AliHBTReaderTPC::AliHBTReaderTPC(const AliHBTReaderTPC& in):
125 AliHBTReader(in),
126 fFileName(in.fFileName),
127 fRunLoader(0x0),
128 fTPCLoader(0x0),
129 fMagneticField(in.fMagneticField),
130 fUseMagFFromRun(in.fUseMagFFromRun),
131 fNTrackPoints(in.fNTrackPoints),
132 fdR(in.fdR),
133 fNClustMin(in.fNClustMin),
134 fNClustMax(in.fNClustMax),
135 fNChi2PerClustMin(in.fNChi2PerClustMin),
136 fNChi2PerClustMax(in.fNChi2PerClustMax),
137 fC00Min(in.fC00Min),
138 fC00Max(in.fC00Max),
139 fC11Min(in.fC11Min),
140 fC11Max(in.fC11Max),
141 fC22Min(in.fC22Min),
142 fC22Max(in.fC22Max),
143 fC33Min(in.fC33Min),
144 fC33Max(in.fC33Max),
145 fC44Min(in.fC44Min),
146 fC44Max(in.fC44Max)
147{
148 //cpy constructor,
149}
150/********************************************************************/
1b446896 151
152AliHBTReaderTPC::~AliHBTReaderTPC()
bed069a4 153{
1b446896 154 //desctructor
3f745d47 155 if (AliHBTParticle::GetDebug())
156 {
157 Info("~AliHBTReaderTPC","deleting Run Loader");
158 AliLoader::SetDebug(AliHBTParticle::GetDebug());
159 }
160
bed069a4 161 delete fRunLoader;
3f745d47 162
163 if (AliHBTParticle::GetDebug())
164 {
165 Info("~AliHBTReaderTPC","deleting Run Loader Done");
166 }
bed069a4 167}
1b446896 168/********************************************************************/
c0cebee1 169
170AliHBTReaderTPC& AliHBTReaderTPC::operator=(const AliHBTReaderTPC& in)
171{
172//Assigment operator
173
174 delete fRunLoader;
175
176 fFileName = in.fFileName;
177 fRunLoader = 0x0;
178 fTPCLoader = 0x0;
179 fMagneticField = in.fMagneticField;
180 fUseMagFFromRun = in.fUseMagFFromRun;
181 fNTrackPoints = in.fNTrackPoints;
182 fdR = in.fdR;
183 fNClustMin = in.fNClustMin;
184 fNClustMax = in.fNClustMax;
185 fNChi2PerClustMin = in.fNChi2PerClustMin;
186 fNChi2PerClustMax = in.fNChi2PerClustMax;
187 fC00Min = in.fC00Min;
188 fC00Max = in.fC00Max;
189 fC11Min = in.fC11Min;
190 fC11Max = in.fC11Max;
191 fC22Min = in.fC22Min;
192 fC22Max = in.fC22Max;
193 fC33Min = in.fC33Min;
194 fC33Max = in.fC33Max;
195 fC44Min = in.fC44Min;
196 fC44Max = in.fC44Max;
bed069a4 197
c0cebee1 198}
199/********************************************************************/
200
bed069a4 201void AliHBTReaderTPC::Rewind()
202{
c0cebee1 203//Rewind reading to the beginning
bed069a4 204 delete fRunLoader;
205 fRunLoader = 0x0;
206 fCurrentDir = 0;
207 fNEventsRead= 0;
bfb09ece 208 if (fTrackCounter) fTrackCounter->Reset();
bed069a4 209}
1b446896 210/********************************************************************/
211
bed069a4 212Int_t AliHBTReaderTPC::ReadNext()
1b446896 213 {
214 //reads data and puts put to the particles and tracks objects
215 //reurns 0 if everything is OK
216 //
8fe7288a 217 Info("Read","");
bfb09ece 218
16701d1b 219 TObjArray *tarray = new TObjArray(5000); //cotainer for tpc tracks
220 tarray->SetOwner(); //set the ownership of the objects it contains
221 //when array is is deleted or cleared all objects
222 //that it contains are deleted
b71a5edb 223
bed069a4 224 if (fParticlesEvent == 0x0) fParticlesEvent = new AliHBTEvent();
225 if (fTracksEvent == 0x0) fTracksEvent = new AliHBTEvent();
226
227 fParticlesEvent->Reset();
228 fTracksEvent->Reset();
b71a5edb 229
16701d1b 230 do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
1b446896 231 {
bed069a4 232
233 if (fRunLoader == 0x0)
234 if (OpenNextSession()) continue;//directory counter is increased inside in case of error
235
236 if (fCurrentEvent == fRunLoader->GetNumberOfEvents())
88cb7938 237 {
bed069a4 238 //read next directory
239 delete fRunLoader;//close current session
240 fRunLoader = 0x0;//assure pointer is null
241 fCurrentDir++;//go to next dir
242 continue;//directory counter is increased inside in case of error
16701d1b 243 }
bed069a4 244
245 Info("ReadNext","Reading Event %d",fCurrentEvent);
1b446896 246
bed069a4 247 fRunLoader->GetEvent(fCurrentEvent);
248 TTree *tracktree = fTPCLoader->TreeT();//get the tree
249 if (!tracktree) //check if we got the tree
250 {//if not return with error
251 Error("ReadNext","Can't get a tree with TPC tracks !\n");
8041e7cf 252 fCurrentEvent++;//go to next dir
bed069a4 253 continue;
254 }
255
256 TBranch *trackbranch=tracktree->GetBranch("tracks");//get the branch with tracks
257 if (!trackbranch) ////check if we got the branch
258 {//if not return with error
259 Error("ReadNext","Can't get a branch with TPC tracks !\n");
8041e7cf 260 fCurrentEvent++;//go to next dir
bed069a4 261 continue;
262 }
263 Int_t ntpctracks=(Int_t)tracktree->GetEntries();//get number of TPC tracks
264 Info("ReadNext","Found %d TPC tracks.",ntpctracks);
265 //Copy tracks to array
266
267 AliTPCtrack *iotrack=0;
268
269 for (Int_t i=0; i<ntpctracks; i++) //loop over all tpc tracks
88cb7938 270 {
bed069a4 271 iotrack=new AliTPCtrack; //create new tracks
272 trackbranch->SetAddress(&iotrack); //tell the branch ehere to put track data from tree(file)
273 tracktree->GetEvent(i); //stream track i to the iotrack
274 tarray->AddLast(iotrack); //put the track in the array
88cb7938 275 }
bed069a4 276
277 Double_t xk;
278 Double_t par[5];
279 Float_t phi, lam, pt;//angles and transverse momentum
280 Int_t label; //label of the current track
281
282 AliStack* stack = fRunLoader->Stack();
283 if (stack == 0x0)
16701d1b 284 {
bed069a4 285 Error("ReadNext","Can not get stack for current event",fCurrentEvent);
286 fCurrentEvent++;
5ee8b891 287 continue;
16701d1b 288 }
bed069a4 289 stack->Particles();
290
291 for (Int_t i=0; i<ntpctracks; i++) //loop over all good tracks
292 {
293 iotrack = (AliTPCtrack*)tarray->At(i);
294 label = iotrack->GetLabel();
295
296 if (label < 0) continue;
3f745d47 297
298 if (CheckTrack(iotrack)) continue;
299
bed069a4 300 TParticle *p = (TParticle*)stack->Particle(label);
301
302 if(p == 0x0) continue; //if returned pointer is NULL
303 if(p->GetPDG() == 0x0) continue; //if particle has crezy PDG code (not known to our database)
304
305 if(Pass(p->GetPdgCode())) continue; //check if we are intersted with particles of this type
306 //if not take next partilce
307
308 AliHBTParticle* part = new AliHBTParticle(*p,i);
309 if(Pass(part)) { delete part; continue;}//check if meets all criteria of any of our cuts
310 //if it does not delete it and take next good track
311
312// iotrack->PropagateTo(3.,0.0028,65.19);
313// iotrack->PropagateToVertex(36.66,1.2e-3);//orig
314 iotrack->PropagateToVertex(50.,0.0353);
315
316 iotrack->GetExternalParameters(xk,par); //get properties of the track
3f745d47 317
bed069a4 318 phi=TMath::ASin(par[2]) + iotrack->GetAlpha();
319 if (phi<-TMath::Pi()) phi+=2*TMath::Pi();
320 if (phi>=TMath::Pi()) phi-=2*TMath::Pi();
321 lam=par[3];
322 pt=1.0/TMath::Abs(par[4]);
323
324 Double_t tpx = pt * TMath::Cos(phi); //track x coordinate of momentum
325 Double_t tpy = pt * TMath::Sin(phi); //track y coordinate of momentum
326 Double_t tpz = pt * lam; //track z coordinate of momentum
327
328 Double_t mass = p->GetMass();
329 Double_t tEtot = TMath::Sqrt( tpx*tpx + tpy*tpy + tpz*tpz + mass*mass);//total energy of the track
330
331 AliHBTParticle* track = new AliHBTParticle(p->GetPdgCode(),i, tpx, tpy , tpz, tEtot, 0., 0., 0., 0.);
332 if(Pass(track))//check if meets all criteria of any of our cuts
333 //if it does not delete it and take next good track
334 {
335 delete track;
336 delete part;
337 continue;
338 }
f5de2f09 339
340 if (fNTrackPoints > 0)
341 {
342 AliHBTTrackPoints* tpts = new AliHBTTrackPoints(fNTrackPoints,iotrack,fdR);
343 track->SetTrackPoints(tpts);
344 }
66d1d1a4 345 if ( fClusterMap )
346 {
347 AliHBTClusterMap* cmap = new AliHBTClusterMap(iotrack);
348 track->SetClusterMap(cmap);
349 }
350
bed069a4 351 fParticlesEvent->AddParticle(part);
352 fTracksEvent->AddParticle(track);
353 }
354
355 Info("ReadNext","Read %d tracks and %d particles from event %d (event %d in dir %d).",
356 fParticlesEvent->GetNumberOfParticles(), fTracksEvent->GetNumberOfParticles(),
357 fNEventsRead,fCurrentEvent,fCurrentDir);
bfb09ece 358 fTrackCounter->Fill(fTracksEvent->GetNumberOfParticles());
bed069a4 359 fCurrentEvent++;
360 fNEventsRead++;
361 delete tarray;
362 return 0;
363 }while(fCurrentDir < GetNumberOfDirs());
364
365 delete tarray;
366 return 1;
367 }
368/********************************************************************/
369
370Int_t AliHBTReaderTPC::OpenNextSession()
371{
c0cebee1 372//Opens session thats from fCurrentDir
bed069a4 373 TString filename = GetDirName(fCurrentDir);
374 if (filename.IsNull())
375 {
376 DoOpenError("Can not get directory name");
377 return 1;
378 }
379 filename = filename +"/"+ fFileName;
380 fRunLoader = AliRunLoader::Open(filename,AliConfig::fgkDefaultEventFolderName);
381 if( fRunLoader == 0x0)
382 {
383 DoOpenError("Can not open session.");
384 return 1;
385 }
386
387 fRunLoader->LoadHeader();
388 if (fRunLoader->GetNumberOfEvents() <= 0)
389 {
390 DoOpenError("There is no events in this directory.");
391 return 1;
392 }
393
394 if (fRunLoader->LoadKinematics())
395 {
396 DoOpenError("Error occured while loading kinematics.");
397 return 1;
398 }
399 fTPCLoader = (AliTPCLoader*)fRunLoader->GetLoader("TPCLoader");
400 if ( fTPCLoader == 0x0)
401 {
402 DoOpenError("Exiting due to problems with opening files.");
403 return 1;
404 }
405 Info("OpenNextSession","________________________________________________________");
406 Info("OpenNextSession","Found %d event(s) in directory %s",
407 fRunLoader->GetNumberOfEvents(),GetDirName(fCurrentDir).Data());
408 Float_t mf;
409 if (fUseMagFFromRun)
410 {
411 fRunLoader->LoadgAlice();
412 mf = fRunLoader->GetAliRun()->Field()->SolenoidField();
413 Info("OpenNextSession","Setting Magnetic Field from run: B=%fT",mf/10.);
414 fRunLoader->UnloadgAlice();
415 }
416 else
417 {
418 Info("OpenNextSession","Setting Own Magnetic Field: B=%fT",fMagneticField);
419 if (fMagneticField == 0x0)
420 {
421 Fatal("OpenNextSession","Magnetic field can not be 0.");
422 return 1;//pro forma
16701d1b 423 }
bed069a4 424 mf = fMagneticField*10.;
425 }
426 AliKalmanTrack::SetConvConst(1000/0.299792458/mf);
1b446896 427
16701d1b 428
bed069a4 429 fRunLoader->CdGAFile();
c0cebee1 430 AliTPCParam *aTPCParam= (AliTPCParam*)gDirectory->Get("75x40_100x60");
431 if (!aTPCParam)
bed069a4 432 {
c0cebee1 433 aTPCParam=(AliTPCParam *)gDirectory->Get("75x40_100x60_150x60");
434 if (!aTPCParam)
bed069a4 435 {
436 DoOpenError("TPC parameters have not been found !\n");
437 return 1;
438 }
439 }
440
441 if (fTPCLoader->LoadTracks())
442 {
443 DoOpenError("Error occured while loading TPC tracks.");
444 return 1;
445 }
88cb7938 446
bed069a4 447 fCurrentEvent = 0;
1b446896 448 return 0;
bed069a4 449}
450/********************************************************************/
1b446896 451
bed069a4 452void AliHBTReaderTPC::DoOpenError( const char *va_(fmt), ...)
453{
454 // Does error display and clean-up in case error caught on Open Next Session
455
456 va_list ap;
457 va_start(ap,va_(fmt));
458 Error("OpenNextSession", va_(fmt), ap);
459 va_end(ap);
460
461 delete fRunLoader;
462 fRunLoader = 0x0;
463 fTPCLoader = 0x0;
464 fCurrentDir++;
465}
1b446896 466
3f745d47 467/********************************************************************/
c0cebee1 468Bool_t AliHBTReaderTPC::CheckTrack(AliTPCtrack* t) const
3f745d47 469{
470 //Performs check of the track
471 if ( (t->GetNumberOfClusters() > fNClustMax) || (t->GetNumberOfClusters() < fNClustMin) ) return kTRUE;
472
f5de2f09 473 Float_t chisqpercl = t->GetChi2()/((Double_t)t->GetNumberOfClusters());
474 if ( (chisqpercl < fNChi2PerClustMin) || (chisqpercl > fNChi2PerClustMax) ) return kTRUE;
475
3f745d47 476 Double_t cc[15];
477 t->GetCovariance(cc);
f5de2f09 478
479 if ( (cc[0] < fC00Min) || (cc[0] > fC00Max) ) return kTRUE;
480 if ( (cc[2] < fC11Min) || (cc[2] > fC11Max) ) return kTRUE;
481 if ( (cc[5] < fC22Min) || (cc[5] > fC22Max) ) return kTRUE;
482 if ( (cc[9] < fC33Min) || (cc[9] > fC33Max) ) return kTRUE;
483 if ( (cc[14] < fC44Min) || (cc[14] > fC44Max) ) return kTRUE;
3f745d47 484
3f745d47 485
486 return kFALSE;
487
488}
489/********************************************************************/
490
491void AliHBTReaderTPC::SetNClustersRange(Int_t min,Int_t max)
492{
493 //sets range of Number Of Clusters that tracks have to have
494 fNClustMin = min;
495 fNClustMax = max;
496}
497/********************************************************************/
498
499void AliHBTReaderTPC::SetChi2PerCluserRange(Float_t min, Float_t max)
500{
501 //sets range of Chi2 per Cluster
502 fNChi2PerClustMin = min;
503 fNChi2PerClustMax = max;
504}
505/********************************************************************/
506
f5de2f09 507void AliHBTReaderTPC::SetC00Range(Float_t min, Float_t max)
508{
509 //Sets range of C00 parameter of covariance matrix of the track
510 //it defines uncertainty of the momentum
511 fC00Min = min;
512 fC00Max = max;
513}
514/********************************************************************/
515
516void AliHBTReaderTPC::SetC11Range(Float_t min, Float_t max)
517{
518 //Sets range of C11 parameter of covariance matrix of the track
519 //it defines uncertainty of the momentum
520 fC11Min = min;
521 fC11Max = max;
522}
523/********************************************************************/
524
525void AliHBTReaderTPC::SetC22Range(Float_t min, Float_t max)
526{
527 //Sets range of C22 parameter of covariance matrix of the track
528 //it defines uncertainty of the momentum
529 fC22Min = min;
530 fC22Max = max;
531}
532/********************************************************************/
533
534void AliHBTReaderTPC::SetC33Range(Float_t min, Float_t max)
535{
536 //Sets range of C33 parameter of covariance matrix of the track
537 //it defines uncertainty of the momentum
538 fC33Min = min;
539 fC33Max = max;
540}
541/********************************************************************/
542
3f745d47 543void AliHBTReaderTPC::SetC44Range(Float_t min, Float_t max)
544{
545 //Sets range of C44 parameter of covariance matrix of the track
546 //it defines uncertainty of the momentum
547 fC44Min = min;
548 fC44Max = max;
549}
550
1b446896 551/********************************************************************/
552/********************************************************************/
553/********************************************************************/
554
3f745d47 555/*
556void (AliTPCtrack* iotrack, Double_t curv)
557{
558 Double_t x[5];
559 iotrack->GetExternalPara
560 //xk is a
561 Double_t fP4=iotrack->GetC();
562 Double_t fP2=iotrack->GetEta();
563
564 Double_t x1=fX, x2=x1+(xk-x1), dx=x2-x1, y1=fP0, z1=fP1;
565 Double_t c1=fP4*x1 - fP2, r1=sqrt(1.- c1*c1);
566 Double_t c2=fP4*x2 - fP2, r2=sqrt(1.- c2*c2);
567
568 fP0 += dx*(c1+c2)/(r1+r2);
569 fP1 += dx*(c1+c2)/(c1*r2 + c2*r1)*fP3;
570
571}
572*/
573