1 #include "AliHBTReaderTPC.h"
2 //______________________________________________
4 // class AliHBTReaderTPC
6 // reader for TPC tracking
7 // needs galice.root, AliTPCtracks.root, AliTPCclusters.root
9 // more info: http://aliweb.cern.ch/people/skowron/analyzer/index.html
10 // Piotr.Skowronski@cern.ch
12 ///////////////////////////////////////////////////////////////////////////
15 #include <TParticle.h>
21 #include <AliLoader.h>
24 #include <AliTPCtrack.h>
25 #include <AliTPCParam.h>
26 #include <AliTPCtracker.h>
27 #include <AliTPCLoader.h>
29 #include "AliHBTRun.h"
30 #include "AliHBTEvent.h"
31 #include "AliHBTParticle.h"
32 #include "AliHBTParticleCut.h"
33 #include "AliHBTTrackPoints.h"
37 ClassImp(AliHBTReaderTPC)
39 AliHBTReaderTPC::AliHBTReaderTPC():
40 fFileName("galice.root"),
44 fUseMagFFromRun(kTRUE),
49 fNChi2PerClustMin(0.0),
50 fNChi2PerClustMax(10e5),
65 /********************************************************************/
67 AliHBTReaderTPC::AliHBTReaderTPC(const Char_t* galicefilename):
68 fFileName(galicefilename),
72 fUseMagFFromRun(kTRUE),
77 fNChi2PerClustMin(0.0),
78 fNChi2PerClustMax(10e5),
93 /********************************************************************/
95 AliHBTReaderTPC::AliHBTReaderTPC(TObjArray* dirs, const Char_t* galicefilename):
97 fFileName(galicefilename),
101 fUseMagFFromRun(kTRUE),
106 fNChi2PerClustMin(0.0),
107 fNChi2PerClustMax(10e5),
121 // galicefilename = "" - this means: Do not open gAlice file -
122 // just leave the global pointer untached
125 /********************************************************************/
127 AliHBTReaderTPC::~AliHBTReaderTPC()
130 if (AliHBTParticle::GetDebug())
132 Info("~AliHBTReaderTPC","deleting Run Loader");
133 AliLoader::SetDebug(AliHBTParticle::GetDebug());
138 if (AliHBTParticle::GetDebug())
140 Info("~AliHBTReaderTPC","deleting Run Loader Done");
143 /********************************************************************/
145 void AliHBTReaderTPC::Rewind()
151 if (fTrackCounter) fTrackCounter->Reset();
153 /********************************************************************/
155 Int_t AliHBTReaderTPC::ReadNext()
157 //reads data and puts put to the particles and tracks objects
158 //reurns 0 if everything is OK
162 TObjArray *tarray = new TObjArray(5000); //cotainer for tpc tracks
163 tarray->SetOwner(); //set the ownership of the objects it contains
164 //when array is is deleted or cleared all objects
165 //that it contains are deleted
167 if (fParticlesEvent == 0x0) fParticlesEvent = new AliHBTEvent();
168 if (fTracksEvent == 0x0) fTracksEvent = new AliHBTEvent();
170 fParticlesEvent->Reset();
171 fTracksEvent->Reset();
173 do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
176 if (fRunLoader == 0x0)
177 if (OpenNextSession()) continue;//directory counter is increased inside in case of error
179 if (fCurrentEvent == fRunLoader->GetNumberOfEvents())
181 //read next directory
182 delete fRunLoader;//close current session
183 fRunLoader = 0x0;//assure pointer is null
184 fCurrentDir++;//go to next dir
185 continue;//directory counter is increased inside in case of error
188 Info("ReadNext","Reading Event %d",fCurrentEvent);
190 fRunLoader->GetEvent(fCurrentEvent);
191 TTree *tracktree = fTPCLoader->TreeT();//get the tree
192 if (!tracktree) //check if we got the tree
193 {//if not return with error
194 Error("ReadNext","Can't get a tree with TPC tracks !\n");
195 fCurrentEvent++;//go to next dir
199 TBranch *trackbranch=tracktree->GetBranch("tracks");//get the branch with tracks
200 if (!trackbranch) ////check if we got the branch
201 {//if not return with error
202 Error("ReadNext","Can't get a branch with TPC tracks !\n");
203 fCurrentEvent++;//go to next dir
206 Int_t ntpctracks=(Int_t)tracktree->GetEntries();//get number of TPC tracks
207 Info("ReadNext","Found %d TPC tracks.",ntpctracks);
208 //Copy tracks to array
210 AliTPCtrack *iotrack=0;
212 for (Int_t i=0; i<ntpctracks; i++) //loop over all tpc tracks
214 iotrack=new AliTPCtrack; //create new tracks
215 trackbranch->SetAddress(&iotrack); //tell the branch ehere to put track data from tree(file)
216 tracktree->GetEvent(i); //stream track i to the iotrack
217 tarray->AddLast(iotrack); //put the track in the array
222 Float_t phi, lam, pt;//angles and transverse momentum
223 Int_t label; //label of the current track
225 AliStack* stack = fRunLoader->Stack();
228 Error("ReadNext","Can not get stack for current event",fCurrentEvent);
234 for (Int_t i=0; i<ntpctracks; i++) //loop over all good tracks
236 iotrack = (AliTPCtrack*)tarray->At(i);
237 label = iotrack->GetLabel();
239 if (label < 0) continue;
241 if (CheckTrack(iotrack)) continue;
243 TParticle *p = (TParticle*)stack->Particle(label);
245 if(p == 0x0) continue; //if returned pointer is NULL
246 if(p->GetPDG() == 0x0) continue; //if particle has crezy PDG code (not known to our database)
248 if(Pass(p->GetPdgCode())) continue; //check if we are intersted with particles of this type
249 //if not take next partilce
251 AliHBTParticle* part = new AliHBTParticle(*p,i);
252 if(Pass(part)) { delete part; continue;}//check if meets all criteria of any of our cuts
253 //if it does not delete it and take next good track
255 // iotrack->PropagateTo(3.,0.0028,65.19);
256 // iotrack->PropagateToVertex(36.66,1.2e-3);//orig
257 iotrack->PropagateToVertex(50.,0.0353);
259 iotrack->GetExternalParameters(xk,par); //get properties of the track
261 phi=TMath::ASin(par[2]) + iotrack->GetAlpha();
262 if (phi<-TMath::Pi()) phi+=2*TMath::Pi();
263 if (phi>=TMath::Pi()) phi-=2*TMath::Pi();
265 pt=1.0/TMath::Abs(par[4]);
267 Double_t tpx = pt * TMath::Cos(phi); //track x coordinate of momentum
268 Double_t tpy = pt * TMath::Sin(phi); //track y coordinate of momentum
269 Double_t tpz = pt * lam; //track z coordinate of momentum
271 Double_t mass = p->GetMass();
272 Double_t tEtot = TMath::Sqrt( tpx*tpx + tpy*tpy + tpz*tpz + mass*mass);//total energy of the track
274 AliHBTParticle* track = new AliHBTParticle(p->GetPdgCode(),i, tpx, tpy , tpz, tEtot, 0., 0., 0., 0.);
275 if(Pass(track))//check if meets all criteria of any of our cuts
276 //if it does not delete it and take next good track
283 if (fNTrackPoints > 0)
285 AliHBTTrackPoints* tpts = new AliHBTTrackPoints(fNTrackPoints,iotrack,fdR);
286 track->SetTrackPoints(tpts);
289 fParticlesEvent->AddParticle(part);
290 fTracksEvent->AddParticle(track);
293 Info("ReadNext","Read %d tracks and %d particles from event %d (event %d in dir %d).",
294 fParticlesEvent->GetNumberOfParticles(), fTracksEvent->GetNumberOfParticles(),
295 fNEventsRead,fCurrentEvent,fCurrentDir);
296 fTrackCounter->Fill(fTracksEvent->GetNumberOfParticles());
301 }while(fCurrentDir < GetNumberOfDirs());
306 /********************************************************************/
308 Int_t AliHBTReaderTPC::OpenNextSession()
310 TString filename = GetDirName(fCurrentDir);
311 if (filename.IsNull())
313 DoOpenError("Can not get directory name");
316 filename = filename +"/"+ fFileName;
317 fRunLoader = AliRunLoader::Open(filename,AliConfig::fgkDefaultEventFolderName);
318 if( fRunLoader == 0x0)
320 DoOpenError("Can not open session.");
324 fRunLoader->LoadHeader();
325 if (fRunLoader->GetNumberOfEvents() <= 0)
327 DoOpenError("There is no events in this directory.");
331 if (fRunLoader->LoadKinematics())
333 DoOpenError("Error occured while loading kinematics.");
336 fTPCLoader = (AliTPCLoader*)fRunLoader->GetLoader("TPCLoader");
337 if ( fTPCLoader == 0x0)
339 DoOpenError("Exiting due to problems with opening files.");
342 Info("OpenNextSession","________________________________________________________");
343 Info("OpenNextSession","Found %d event(s) in directory %s",
344 fRunLoader->GetNumberOfEvents(),GetDirName(fCurrentDir).Data());
348 fRunLoader->LoadgAlice();
349 mf = fRunLoader->GetAliRun()->Field()->SolenoidField();
350 Info("OpenNextSession","Setting Magnetic Field from run: B=%fT",mf/10.);
351 fRunLoader->UnloadgAlice();
355 Info("OpenNextSession","Setting Own Magnetic Field: B=%fT",fMagneticField);
356 if (fMagneticField == 0x0)
358 Fatal("OpenNextSession","Magnetic field can not be 0.");
361 mf = fMagneticField*10.;
363 AliKalmanTrack::SetConvConst(1000/0.299792458/mf);
366 fRunLoader->CdGAFile();
367 AliTPCParam *TPCParam= (AliTPCParam*)gDirectory->Get("75x40_100x60");
370 TPCParam=(AliTPCParam *)gDirectory->Get("75x40_100x60_150x60");
373 DoOpenError("TPC parameters have not been found !\n");
378 if (fTPCLoader->LoadTracks())
380 DoOpenError("Error occured while loading TPC tracks.");
387 /********************************************************************/
389 void AliHBTReaderTPC::DoOpenError( const char *va_(fmt), ...)
391 // Does error display and clean-up in case error caught on Open Next Session
394 va_start(ap,va_(fmt));
395 Error("OpenNextSession", va_(fmt), ap);
404 /********************************************************************/
405 Bool_t AliHBTReaderTPC::CheckTrack(AliTPCtrack* t)
407 //Performs check of the track
408 if ( (t->GetNumberOfClusters() > fNClustMax) || (t->GetNumberOfClusters() < fNClustMin) ) return kTRUE;
410 Float_t chisqpercl = t->GetChi2()/((Double_t)t->GetNumberOfClusters());
411 if ( (chisqpercl < fNChi2PerClustMin) || (chisqpercl > fNChi2PerClustMax) ) return kTRUE;
414 t->GetCovariance(cc);
416 if ( (cc[0] < fC00Min) || (cc[0] > fC00Max) ) return kTRUE;
417 if ( (cc[2] < fC11Min) || (cc[2] > fC11Max) ) return kTRUE;
418 if ( (cc[5] < fC22Min) || (cc[5] > fC22Max) ) return kTRUE;
419 if ( (cc[9] < fC33Min) || (cc[9] > fC33Max) ) return kTRUE;
420 if ( (cc[14] < fC44Min) || (cc[14] > fC44Max) ) return kTRUE;
426 /********************************************************************/
428 void AliHBTReaderTPC::SetNClustersRange(Int_t min,Int_t max)
430 //sets range of Number Of Clusters that tracks have to have
434 /********************************************************************/
436 void AliHBTReaderTPC::SetChi2PerCluserRange(Float_t min, Float_t max)
438 //sets range of Chi2 per Cluster
439 fNChi2PerClustMin = min;
440 fNChi2PerClustMax = max;
442 /********************************************************************/
444 void AliHBTReaderTPC::SetC00Range(Float_t min, Float_t max)
446 //Sets range of C00 parameter of covariance matrix of the track
447 //it defines uncertainty of the momentum
451 /********************************************************************/
453 void AliHBTReaderTPC::SetC11Range(Float_t min, Float_t max)
455 //Sets range of C11 parameter of covariance matrix of the track
456 //it defines uncertainty of the momentum
460 /********************************************************************/
462 void AliHBTReaderTPC::SetC22Range(Float_t min, Float_t max)
464 //Sets range of C22 parameter of covariance matrix of the track
465 //it defines uncertainty of the momentum
469 /********************************************************************/
471 void AliHBTReaderTPC::SetC33Range(Float_t min, Float_t max)
473 //Sets range of C33 parameter of covariance matrix of the track
474 //it defines uncertainty of the momentum
478 /********************************************************************/
480 void AliHBTReaderTPC::SetC44Range(Float_t min, Float_t max)
482 //Sets range of C44 parameter of covariance matrix of the track
483 //it defines uncertainty of the momentum
488 /********************************************************************/
489 /********************************************************************/
490 /********************************************************************/
493 void (AliTPCtrack* iotrack, Double_t curv)
496 iotrack->GetExternalPara
498 Double_t fP4=iotrack->GetC();
499 Double_t fP2=iotrack->GetEta();
501 Double_t x1=fX, x2=x1+(xk-x1), dx=x2-x1, y1=fP0, z1=fP1;
502 Double_t c1=fP4*x1 - fP2, r1=sqrt(1.- c1*c1);
503 Double_t c2=fP4*x2 - fP2, r2=sqrt(1.- c2*c2);
505 fP0 += dx*(c1+c2)/(r1+r2);
506 fP1 += dx*(c1+c2)/(c1*r2 + c2*r1)*fP3;