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 <AliTPCLoader.h>
26 #include "AliHBTEvent.h"
27 #include "AliHBTParticle.h"
28 #include "AliHBTTrackPoints.h"
29 #include "AliHBTClusterMap.h"
32 ClassImp(AliHBTReaderTPC)
34 AliHBTReaderTPC::AliHBTReaderTPC():
35 fFileName("galice.root"),
39 fUseMagFFromRun(kTRUE),
45 fNChi2PerClustMin(0.0),
46 fNChi2PerClustMax(10e5),
61 /********************************************************************/
63 AliHBTReaderTPC::AliHBTReaderTPC(const Char_t* galicefilename):
64 fFileName(galicefilename),
68 fUseMagFFromRun(kTRUE),
73 fNChi2PerClustMin(0.0),
74 fNChi2PerClustMax(10e5),
89 /********************************************************************/
91 AliHBTReaderTPC::AliHBTReaderTPC(TObjArray* dirs, const Char_t* galicefilename):
93 fFileName(galicefilename),
97 fUseMagFFromRun(kTRUE),
103 fNChi2PerClustMin(0.0),
104 fNChi2PerClustMax(10e5),
118 // galicefilename = "" - this means: Do not open gAlice file -
119 // just leave the global pointer untached
122 /********************************************************************/
123 AliHBTReaderTPC::AliHBTReaderTPC(const AliHBTReaderTPC& in):
125 fFileName(in.fFileName),
128 fMagneticField(in.fMagneticField),
129 fUseMagFFromRun(in.fUseMagFFromRun),
130 fNTrackPoints(in.fNTrackPoints),
132 fNClustMin(in.fNClustMin),
133 fNClustMax(in.fNClustMax),
134 fNChi2PerClustMin(in.fNChi2PerClustMin),
135 fNChi2PerClustMax(in.fNChi2PerClustMax),
149 /********************************************************************/
151 AliHBTReaderTPC::~AliHBTReaderTPC()
154 if (AliHBTParticle::GetDebug())
156 Info("~AliHBTReaderTPC","deleting Run Loader");
157 AliLoader::SetDebug(AliHBTParticle::GetDebug());
162 if (AliHBTParticle::GetDebug())
164 Info("~AliHBTReaderTPC","deleting Run Loader Done");
167 /********************************************************************/
169 AliHBTReaderTPC& AliHBTReaderTPC::operator=(const AliHBTReaderTPC& in)
175 fFileName = in.fFileName;
178 fMagneticField = in.fMagneticField;
179 fUseMagFFromRun = in.fUseMagFFromRun;
180 fNTrackPoints = in.fNTrackPoints;
182 fNClustMin = in.fNClustMin;
183 fNClustMax = in.fNClustMax;
184 fNChi2PerClustMin = in.fNChi2PerClustMin;
185 fNChi2PerClustMax = in.fNChi2PerClustMax;
186 fC00Min = in.fC00Min;
187 fC00Max = in.fC00Max;
188 fC11Min = in.fC11Min;
189 fC11Max = in.fC11Max;
190 fC22Min = in.fC22Min;
191 fC22Max = in.fC22Max;
192 fC33Min = in.fC33Min;
193 fC33Max = in.fC33Max;
194 fC44Min = in.fC44Min;
195 fC44Max = in.fC44Max;
198 /********************************************************************/
200 void AliHBTReaderTPC::Rewind()
202 //Rewind reading to the beginning
207 if (fTrackCounter) fTrackCounter->Reset();
209 /********************************************************************/
211 Int_t AliHBTReaderTPC::ReadNext()
213 //reads data and puts put to the particles and tracks objects
214 //reurns 0 if everything is OK
218 TObjArray *tarray = new TObjArray(5000); //cotainer for tpc tracks
219 tarray->SetOwner(); //set the ownership of the objects it contains
220 //when array is is deleted or cleared all objects
221 //that it contains are deleted
223 if (fParticlesEvent == 0x0) fParticlesEvent = new AliHBTEvent();
224 if (fTracksEvent == 0x0) fTracksEvent = new AliHBTEvent();
226 fParticlesEvent->Reset();
227 fTracksEvent->Reset();
229 do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
232 if (fRunLoader == 0x0)
233 if (OpenNextSession()) continue;//directory counter is increased inside in case of error
235 if (fCurrentEvent == fRunLoader->GetNumberOfEvents())
237 //read next directory
238 delete fRunLoader;//close current session
239 fRunLoader = 0x0;//assure pointer is null
240 fCurrentDir++;//go to next dir
241 continue;//directory counter is increased inside in case of error
244 Info("ReadNext","Reading Event %d",fCurrentEvent);
246 fRunLoader->GetEvent(fCurrentEvent);
247 TTree *tracktree = fTPCLoader->TreeT();//get the tree
248 if (!tracktree) //check if we got the tree
249 {//if not return with error
250 Error("ReadNext","Can't get a tree with TPC tracks !\n");
251 fCurrentEvent++;//go to next dir
255 TBranch *trackbranch=tracktree->GetBranch("tracks");//get the branch with tracks
256 if (!trackbranch) ////check if we got the branch
257 {//if not return with error
258 Error("ReadNext","Can't get a branch with TPC tracks !\n");
259 fCurrentEvent++;//go to next dir
262 Int_t ntpctracks=(Int_t)tracktree->GetEntries();//get number of TPC tracks
263 Info("ReadNext","Found %d TPC tracks.",ntpctracks);
264 //Copy tracks to array
266 AliTPCtrack *iotrack=0;
268 for (Int_t i=0; i<ntpctracks; i++) //loop over all tpc tracks
270 iotrack=new AliTPCtrack; //create new tracks
271 trackbranch->SetAddress(&iotrack); //tell the branch ehere to put track data from tree(file)
272 tracktree->GetEvent(i); //stream track i to the iotrack
273 tarray->AddLast(iotrack); //put the track in the array
278 Float_t phi, lam, pt;//angles and transverse momentum
279 Int_t label; //label of the current track
281 AliStack* stack = fRunLoader->Stack();
284 Error("ReadNext","Can not get stack for current event",fCurrentEvent);
290 for (Int_t i=0; i<ntpctracks; i++) //loop over all good tracks
292 iotrack = (AliTPCtrack*)tarray->At(i);
293 label = iotrack->GetLabel();
295 if (label < 0) continue;
297 if (CheckTrack(iotrack)) continue;
299 TParticle *p = (TParticle*)stack->Particle(label);
301 if(p == 0x0) continue; //if returned pointer is NULL
302 if(p->GetPDG() == 0x0) continue; //if particle has crezy PDG code (not known to our database)
304 if(Pass(p->GetPdgCode())) continue; //check if we are intersted with particles of this type
305 //if not take next partilce
307 AliHBTParticle* part = new AliHBTParticle(*p,i);
308 if(Pass(part)) { delete part; continue;}//check if meets all criteria of any of our cuts
309 //if it does not delete it and take next good track
311 // iotrack->PropagateTo(3.,0.0028,65.19);
312 // iotrack->PropagateToVertex(36.66,1.2e-3);//orig
313 iotrack->PropagateToVertex(50.,0.0353);
315 iotrack->GetExternalParameters(xk,par); //get properties of the track
317 phi=TMath::ASin(par[2]) + iotrack->GetAlpha();
318 if (phi<-TMath::Pi()) phi+=2*TMath::Pi();
319 if (phi>=TMath::Pi()) phi-=2*TMath::Pi();
321 pt=1.0/TMath::Abs(par[4]);
323 Double_t tpx = pt * TMath::Cos(phi); //track x coordinate of momentum
324 Double_t tpy = pt * TMath::Sin(phi); //track y coordinate of momentum
325 Double_t tpz = pt * lam; //track z coordinate of momentum
327 Double_t mass = p->GetMass();
328 Double_t tEtot = TMath::Sqrt( tpx*tpx + tpy*tpy + tpz*tpz + mass*mass);//total energy of the track
330 AliHBTParticle* track = new AliHBTParticle(p->GetPdgCode(),i, tpx, tpy , tpz, tEtot, 0., 0., 0., 0.);
331 if(Pass(track))//check if meets all criteria of any of our cuts
332 //if it does not delete it and take next good track
339 if (fNTrackPoints > 0)
341 AliHBTTrackPoints* tpts = new AliHBTTrackPoints(fNTrackPoints,iotrack,fdR);
342 track->SetTrackPoints(tpts);
346 AliHBTClusterMap* cmap = new AliHBTClusterMap(iotrack);
347 track->SetClusterMap(cmap);
350 fParticlesEvent->AddParticle(part);
351 fTracksEvent->AddParticle(track);
354 Info("ReadNext","Read %d tracks and %d particles from event %d (event %d in dir %d).",
355 fParticlesEvent->GetNumberOfParticles(), fTracksEvent->GetNumberOfParticles(),
356 fNEventsRead,fCurrentEvent,fCurrentDir);
357 fTrackCounter->Fill(fTracksEvent->GetNumberOfParticles());
362 }while(fCurrentDir < GetNumberOfDirs());
367 /********************************************************************/
369 Int_t AliHBTReaderTPC::OpenNextSession()
371 //Opens session thats from fCurrentDir
372 TString filename = GetDirName(fCurrentDir);
373 if (filename.IsNull())
375 DoOpenError("Can not get directory name");
378 filename = filename +"/"+ fFileName;
379 fRunLoader = AliRunLoader::Open(filename,AliConfig::fgkDefaultEventFolderName);
380 if( fRunLoader == 0x0)
382 DoOpenError("Can not open session.");
386 fRunLoader->LoadHeader();
387 if (fRunLoader->GetNumberOfEvents() <= 0)
389 DoOpenError("There is no events in this directory.");
393 if (fRunLoader->LoadKinematics())
395 DoOpenError("Error occured while loading kinematics.");
398 fTPCLoader = (AliTPCLoader*)fRunLoader->GetLoader("TPCLoader");
399 if ( fTPCLoader == 0x0)
401 DoOpenError("Exiting due to problems with opening files.");
404 Info("OpenNextSession","________________________________________________________");
405 Info("OpenNextSession","Found %d event(s) in directory %s",
406 fRunLoader->GetNumberOfEvents(),GetDirName(fCurrentDir).Data());
410 fRunLoader->LoadgAlice();
411 mf = fRunLoader->GetAliRun()->Field()->SolenoidField();
412 Info("OpenNextSession","Setting Magnetic Field from run: B=%fT",mf/10.);
413 fRunLoader->UnloadgAlice();
417 Info("OpenNextSession","Setting Own Magnetic Field: B=%fT",fMagneticField);
418 if (fMagneticField == 0x0)
420 Fatal("OpenNextSession","Magnetic field can not be 0.");
423 mf = fMagneticField*10.;
425 AliKalmanTrack::SetConvConst(1000/0.299792458/mf);
428 if (fTPCLoader->LoadTracks())
430 DoOpenError("Error occured while loading TPC tracks.");
437 /********************************************************************/
439 void AliHBTReaderTPC::DoOpenError( const char *va_(fmt), ...)
441 // Does error display and clean-up in case error caught on Open Next Session
444 va_start(ap,va_(fmt));
445 Error("OpenNextSession", va_(fmt), ap);
454 /********************************************************************/
455 Bool_t AliHBTReaderTPC::CheckTrack(AliTPCtrack* t) const
457 //Performs check of the track
458 if ( (t->GetNumberOfClusters() > fNClustMax) || (t->GetNumberOfClusters() < fNClustMin) ) return kTRUE;
460 Float_t chisqpercl = t->GetChi2()/((Double_t)t->GetNumberOfClusters());
461 if ( (chisqpercl < fNChi2PerClustMin) || (chisqpercl > fNChi2PerClustMax) ) return kTRUE;
464 t->GetExternalCovariance(cc);
466 if ( (cc[0] < fC00Min) || (cc[0] > fC00Max) ) return kTRUE;
467 if ( (cc[2] < fC11Min) || (cc[2] > fC11Max) ) return kTRUE;
468 if ( (cc[5] < fC22Min) || (cc[5] > fC22Max) ) return kTRUE;
469 if ( (cc[9] < fC33Min) || (cc[9] > fC33Max) ) return kTRUE;
470 if ( (cc[14] < fC44Min) || (cc[14] > fC44Max) ) return kTRUE;
476 /********************************************************************/
478 void AliHBTReaderTPC::SetNClustersRange(Int_t min,Int_t max)
480 //sets range of Number Of Clusters that tracks have to have
484 /********************************************************************/
486 void AliHBTReaderTPC::SetChi2PerCluserRange(Float_t min, Float_t max)
488 //sets range of Chi2 per Cluster
489 fNChi2PerClustMin = min;
490 fNChi2PerClustMax = max;
492 /********************************************************************/
494 void AliHBTReaderTPC::SetC00Range(Float_t min, Float_t max)
496 //Sets range of C00 parameter of covariance matrix of the track
497 //it defines uncertainty of the momentum
501 /********************************************************************/
503 void AliHBTReaderTPC::SetC11Range(Float_t min, Float_t max)
505 //Sets range of C11 parameter of covariance matrix of the track
506 //it defines uncertainty of the momentum
510 /********************************************************************/
512 void AliHBTReaderTPC::SetC22Range(Float_t min, Float_t max)
514 //Sets range of C22 parameter of covariance matrix of the track
515 //it defines uncertainty of the momentum
519 /********************************************************************/
521 void AliHBTReaderTPC::SetC33Range(Float_t min, Float_t max)
523 //Sets range of C33 parameter of covariance matrix of the track
524 //it defines uncertainty of the momentum
528 /********************************************************************/
530 void AliHBTReaderTPC::SetC44Range(Float_t min, Float_t max)
532 //Sets range of C44 parameter of covariance matrix of the track
533 //it defines uncertainty of the momentum
538 /********************************************************************/
539 /********************************************************************/
540 /********************************************************************/
543 void (AliTPCtrack* iotrack, Double_t curv)
546 iotrack->GetExternalPara
548 Double_t fP4=iotrack->GetC();
549 Double_t fP2=iotrack->GetEta();
551 Double_t x1=fX, x2=x1+(xk-x1), dx=x2-x1, y1=fP0, z1=fP1;
552 Double_t c1=fP4*x1 - fP2, r1=sqrt(1.- c1*c1);
553 Double_t c2=fP4*x2 - fP2, r2=sqrt(1.- c2*c2);
555 fP0 += dx*(c1+c2)/(r1+r2);
556 fP1 += dx*(c1+c2)/(c1*r2 + c2*r1)*fP3;