1 #include "AliHBTReaderTPC.h"
2 //______________________________________________
4 // class AliHBTReaderTPC
6 // reader for TPC tracks
8 // just to shut up coding conventions checker
10 // more info: http://aliweb.cern.ch/people/skowron/analyzer/index.html
11 // Piotr.Skowronski@cern.ch
13 ///////////////////////////////////////////////////////////////////////////
15 #include <TParticle.h>
20 #include <AliLoader.h>
23 #include <AliTPCtrack.h>
24 #include <AliTPCParam.h>
25 #include <AliTPCLoader.h>
27 #include "AliHBTEvent.h"
28 #include "AliHBTParticle.h"
29 #include "AliHBTTrackPoints.h"
30 #include "AliHBTClusterMap.h"
33 ClassImp(AliHBTReaderTPC)
35 AliHBTReaderTPC::AliHBTReaderTPC():
36 fFileName("galice.root"),
40 fUseMagFFromRun(kTRUE),
46 fNChi2PerClustMin(0.0),
47 fNChi2PerClustMax(10e5),
62 /********************************************************************/
64 AliHBTReaderTPC::AliHBTReaderTPC(const Char_t* galicefilename):
65 fFileName(galicefilename),
69 fUseMagFFromRun(kTRUE),
74 fNChi2PerClustMin(0.0),
75 fNChi2PerClustMax(10e5),
90 /********************************************************************/
92 AliHBTReaderTPC::AliHBTReaderTPC(TObjArray* dirs, const Char_t* galicefilename):
94 fFileName(galicefilename),
98 fUseMagFFromRun(kTRUE),
104 fNChi2PerClustMin(0.0),
105 fNChi2PerClustMax(10e5),
119 // galicefilename = "" - this means: Do not open gAlice file -
120 // just leave the global pointer untached
123 /********************************************************************/
124 AliHBTReaderTPC::AliHBTReaderTPC(const AliHBTReaderTPC& in):
126 fFileName(in.fFileName),
129 fMagneticField(in.fMagneticField),
130 fUseMagFFromRun(in.fUseMagFFromRun),
131 fNTrackPoints(in.fNTrackPoints),
133 fNClustMin(in.fNClustMin),
134 fNClustMax(in.fNClustMax),
135 fNChi2PerClustMin(in.fNChi2PerClustMin),
136 fNChi2PerClustMax(in.fNChi2PerClustMax),
150 /********************************************************************/
152 AliHBTReaderTPC::~AliHBTReaderTPC()
155 if (AliHBTParticle::GetDebug())
157 Info("~AliHBTReaderTPC","deleting Run Loader");
158 AliLoader::SetDebug(AliHBTParticle::GetDebug());
163 if (AliHBTParticle::GetDebug())
165 Info("~AliHBTReaderTPC","deleting Run Loader Done");
168 /********************************************************************/
170 AliHBTReaderTPC& AliHBTReaderTPC::operator=(const AliHBTReaderTPC& in)
176 fFileName = in.fFileName;
179 fMagneticField = in.fMagneticField;
180 fUseMagFFromRun = in.fUseMagFFromRun;
181 fNTrackPoints = in.fNTrackPoints;
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;
199 /********************************************************************/
201 void AliHBTReaderTPC::Rewind()
203 //Rewind reading to the beginning
208 if (fTrackCounter) fTrackCounter->Reset();
210 /********************************************************************/
212 Int_t AliHBTReaderTPC::ReadNext()
214 //reads data and puts put to the particles and tracks objects
215 //reurns 0 if everything is OK
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
224 if (fParticlesEvent == 0x0) fParticlesEvent = new AliHBTEvent();
225 if (fTracksEvent == 0x0) fTracksEvent = new AliHBTEvent();
227 fParticlesEvent->Reset();
228 fTracksEvent->Reset();
230 do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
233 if (fRunLoader == 0x0)
234 if (OpenNextSession()) continue;//directory counter is increased inside in case of error
236 if (fCurrentEvent == fRunLoader->GetNumberOfEvents())
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
245 Info("ReadNext","Reading Event %d",fCurrentEvent);
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");
252 fCurrentEvent++;//go to next dir
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");
260 fCurrentEvent++;//go to next dir
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
267 AliTPCtrack *iotrack=0;
269 for (Int_t i=0; i<ntpctracks; i++) //loop over all tpc tracks
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
279 Float_t phi, lam, pt;//angles and transverse momentum
280 Int_t label; //label of the current track
282 AliStack* stack = fRunLoader->Stack();
285 Error("ReadNext","Can not get stack for current event",fCurrentEvent);
291 for (Int_t i=0; i<ntpctracks; i++) //loop over all good tracks
293 iotrack = (AliTPCtrack*)tarray->At(i);
294 label = iotrack->GetLabel();
296 if (label < 0) continue;
298 if (CheckTrack(iotrack)) continue;
300 TParticle *p = (TParticle*)stack->Particle(label);
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)
305 if(Pass(p->GetPdgCode())) continue; //check if we are intersted with particles of this type
306 //if not take next partilce
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
312 // iotrack->PropagateTo(3.,0.0028,65.19);
313 // iotrack->PropagateToVertex(36.66,1.2e-3);//orig
314 iotrack->PropagateToVertex(50.,0.0353);
316 iotrack->GetExternalParameters(xk,par); //get properties of the track
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();
322 pt=1.0/TMath::Abs(par[4]);
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
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
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
340 if (fNTrackPoints > 0)
342 AliHBTTrackPoints* tpts = new AliHBTTrackPoints(fNTrackPoints,iotrack,fdR);
343 track->SetTrackPoints(tpts);
347 AliHBTClusterMap* cmap = new AliHBTClusterMap(iotrack);
348 track->SetClusterMap(cmap);
351 fParticlesEvent->AddParticle(part);
352 fTracksEvent->AddParticle(track);
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);
358 fTrackCounter->Fill(fTracksEvent->GetNumberOfParticles());
363 }while(fCurrentDir < GetNumberOfDirs());
368 /********************************************************************/
370 Int_t AliHBTReaderTPC::OpenNextSession()
372 //Opens session thats from fCurrentDir
373 TString filename = GetDirName(fCurrentDir);
374 if (filename.IsNull())
376 DoOpenError("Can not get directory name");
379 filename = filename +"/"+ fFileName;
380 fRunLoader = AliRunLoader::Open(filename,AliConfig::fgkDefaultEventFolderName);
381 if( fRunLoader == 0x0)
383 DoOpenError("Can not open session.");
387 fRunLoader->LoadHeader();
388 if (fRunLoader->GetNumberOfEvents() <= 0)
390 DoOpenError("There is no events in this directory.");
394 if (fRunLoader->LoadKinematics())
396 DoOpenError("Error occured while loading kinematics.");
399 fTPCLoader = (AliTPCLoader*)fRunLoader->GetLoader("TPCLoader");
400 if ( fTPCLoader == 0x0)
402 DoOpenError("Exiting due to problems with opening files.");
405 Info("OpenNextSession","________________________________________________________");
406 Info("OpenNextSession","Found %d event(s) in directory %s",
407 fRunLoader->GetNumberOfEvents(),GetDirName(fCurrentDir).Data());
411 fRunLoader->LoadgAlice();
412 mf = fRunLoader->GetAliRun()->Field()->SolenoidField();
413 Info("OpenNextSession","Setting Magnetic Field from run: B=%fT",mf/10.);
414 fRunLoader->UnloadgAlice();
418 Info("OpenNextSession","Setting Own Magnetic Field: B=%fT",fMagneticField);
419 if (fMagneticField == 0x0)
421 Fatal("OpenNextSession","Magnetic field can not be 0.");
424 mf = fMagneticField*10.;
426 AliKalmanTrack::SetConvConst(1000/0.299792458/mf);
429 fRunLoader->CdGAFile();
430 AliTPCParam *aTPCParam= (AliTPCParam*)gDirectory->Get("75x40_100x60");
433 aTPCParam=(AliTPCParam *)gDirectory->Get("75x40_100x60_150x60");
436 DoOpenError("TPC parameters have not been found !\n");
441 if (fTPCLoader->LoadTracks())
443 DoOpenError("Error occured while loading TPC tracks.");
450 /********************************************************************/
452 void AliHBTReaderTPC::DoOpenError( const char *va_(fmt), ...)
454 // Does error display and clean-up in case error caught on Open Next Session
457 va_start(ap,va_(fmt));
458 Error("OpenNextSession", va_(fmt), ap);
467 /********************************************************************/
468 Bool_t AliHBTReaderTPC::CheckTrack(AliTPCtrack* t) const
470 //Performs check of the track
471 if ( (t->GetNumberOfClusters() > fNClustMax) || (t->GetNumberOfClusters() < fNClustMin) ) return kTRUE;
473 Float_t chisqpercl = t->GetChi2()/((Double_t)t->GetNumberOfClusters());
474 if ( (chisqpercl < fNChi2PerClustMin) || (chisqpercl > fNChi2PerClustMax) ) return kTRUE;
477 t->GetCovariance(cc);
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;
489 /********************************************************************/
491 void AliHBTReaderTPC::SetNClustersRange(Int_t min,Int_t max)
493 //sets range of Number Of Clusters that tracks have to have
497 /********************************************************************/
499 void AliHBTReaderTPC::SetChi2PerCluserRange(Float_t min, Float_t max)
501 //sets range of Chi2 per Cluster
502 fNChi2PerClustMin = min;
503 fNChi2PerClustMax = max;
505 /********************************************************************/
507 void AliHBTReaderTPC::SetC00Range(Float_t min, Float_t max)
509 //Sets range of C00 parameter of covariance matrix of the track
510 //it defines uncertainty of the momentum
514 /********************************************************************/
516 void AliHBTReaderTPC::SetC11Range(Float_t min, Float_t max)
518 //Sets range of C11 parameter of covariance matrix of the track
519 //it defines uncertainty of the momentum
523 /********************************************************************/
525 void AliHBTReaderTPC::SetC22Range(Float_t min, Float_t max)
527 //Sets range of C22 parameter of covariance matrix of the track
528 //it defines uncertainty of the momentum
532 /********************************************************************/
534 void AliHBTReaderTPC::SetC33Range(Float_t min, Float_t max)
536 //Sets range of C33 parameter of covariance matrix of the track
537 //it defines uncertainty of the momentum
541 /********************************************************************/
543 void AliHBTReaderTPC::SetC44Range(Float_t min, Float_t max)
545 //Sets range of C44 parameter of covariance matrix of the track
546 //it defines uncertainty of the momentum
551 /********************************************************************/
552 /********************************************************************/
553 /********************************************************************/
556 void (AliTPCtrack* iotrack, Double_t curv)
559 iotrack->GetExternalPara
561 Double_t fP4=iotrack->GetC();
562 Double_t fP2=iotrack->GetEta();
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);
568 fP0 += dx*(c1+c2)/(r1+r2);
569 fP1 += dx*(c1+c2)/(c1*r2 + c2*r1)*fP3;