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"
36 ClassImp(AliHBTReaderTPC)
38 AliHBTReaderTPC::AliHBTReaderTPC():
39 fFileName("galice.root"),
43 fUseMagFFromRun(kTRUE),
46 fNChi2PerClustMin(0.0),
47 fNChi2PerClustMax(10e5),
53 // galicefilename = "" - this means: Do not open gAlice file -
54 // just leave the global pointer untouched
58 AliHBTReaderTPC::AliHBTReaderTPC(const Char_t* galicefilename):
59 fFileName(galicefilename),
63 fUseMagFFromRun(kTRUE),
66 fNChi2PerClustMin(0.0),
67 fNChi2PerClustMax(10e5),
73 // galicefilename = "" - this means: Do not open gAlice file -
74 // just leave the global pointer untouched
77 /********************************************************************/
78 AliHBTReaderTPC::AliHBTReaderTPC(TObjArray* dirs, const Char_t* galicefilename):
80 fFileName(galicefilename),
84 fUseMagFFromRun(kTRUE),
87 fNChi2PerClustMin(0.0),
88 fNChi2PerClustMax(10e5),
94 // galicefilename = "" - this means: Do not open gAlice file -
95 // just leave the global pointer untached
98 /********************************************************************/
100 AliHBTReaderTPC::~AliHBTReaderTPC()
103 if (AliHBTParticle::GetDebug())
105 Info("~AliHBTReaderTPC","deleting Run Loader");
106 AliLoader::SetDebug(AliHBTParticle::GetDebug());
111 if (AliHBTParticle::GetDebug())
113 Info("~AliHBTReaderTPC","deleting Run Loader Done");
116 /********************************************************************/
118 void AliHBTReaderTPC::Rewind()
124 if (fTrackCounter) fTrackCounter->Reset();
126 /********************************************************************/
128 Int_t AliHBTReaderTPC::ReadNext()
130 //reads data and puts put to the particles and tracks objects
131 //reurns 0 if everything is OK
135 Int_t ntracksread = 0;
137 TObjArray *tarray = new TObjArray(5000); //cotainer for tpc tracks
138 tarray->SetOwner(); //set the ownership of the objects it contains
139 //when array is is deleted or cleared all objects
140 //that it contains are deleted
142 if (fParticlesEvent == 0x0) fParticlesEvent = new AliHBTEvent();
143 if (fTracksEvent == 0x0) fTracksEvent = new AliHBTEvent();
145 fParticlesEvent->Reset();
146 fTracksEvent->Reset();
148 do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
151 if (fRunLoader == 0x0)
152 if (OpenNextSession()) continue;//directory counter is increased inside in case of error
154 if (fCurrentEvent == fRunLoader->GetNumberOfEvents())
156 //read next directory
157 delete fRunLoader;//close current session
158 fRunLoader = 0x0;//assure pointer is null
159 fCurrentDir++;//go to next dir
160 continue;//directory counter is increased inside in case of error
163 Info("ReadNext","Reading Event %d",fCurrentEvent);
165 fRunLoader->GetEvent(fCurrentEvent);
166 TTree *tracktree = fTPCLoader->TreeT();//get the tree
167 if (!tracktree) //check if we got the tree
168 {//if not return with error
169 Error("ReadNext","Can't get a tree with TPC tracks !\n");
170 fCurrentEvent++;//go to next dir
174 TBranch *trackbranch=tracktree->GetBranch("tracks");//get the branch with tracks
175 if (!trackbranch) ////check if we got the branch
176 {//if not return with error
177 Error("ReadNext","Can't get a branch with TPC tracks !\n");
178 fCurrentEvent++;//go to next dir
181 Int_t ntpctracks=(Int_t)tracktree->GetEntries();//get number of TPC tracks
182 Info("ReadNext","Found %d TPC tracks.",ntpctracks);
183 //Copy tracks to array
185 AliTPCtrack *iotrack=0;
187 for (Int_t i=0; i<ntpctracks; i++) //loop over all tpc tracks
189 iotrack=new AliTPCtrack; //create new tracks
190 trackbranch->SetAddress(&iotrack); //tell the branch ehere to put track data from tree(file)
191 tracktree->GetEvent(i); //stream track i to the iotrack
192 tarray->AddLast(iotrack); //put the track in the array
197 Float_t phi, lam, pt;//angles and transverse momentum
198 Int_t label; //label of the current track
200 AliStack* stack = fRunLoader->Stack();
203 Error("ReadNext","Can not get stack for current event",fCurrentEvent);
209 for (Int_t i=0; i<ntpctracks; i++) //loop over all good tracks
211 iotrack = (AliTPCtrack*)tarray->At(i);
212 label = iotrack->GetLabel();
214 if (label < 0) continue;
216 if (CheckTrack(iotrack)) continue;
218 TParticle *p = (TParticle*)stack->Particle(label);
220 if(p == 0x0) continue; //if returned pointer is NULL
221 if(p->GetPDG() == 0x0) continue; //if particle has crezy PDG code (not known to our database)
223 if(Pass(p->GetPdgCode())) continue; //check if we are intersted with particles of this type
224 //if not take next partilce
226 AliHBTParticle* part = new AliHBTParticle(*p,i);
227 if(Pass(part)) { delete part; continue;}//check if meets all criteria of any of our cuts
228 //if it does not delete it and take next good track
230 // iotrack->PropagateTo(3.,0.0028,65.19);
231 // iotrack->PropagateToVertex(36.66,1.2e-3);//orig
232 iotrack->PropagateToVertex(50.,0.0353);
234 iotrack->GetExternalParameters(xk,par); //get properties of the track
236 phi=TMath::ASin(par[2]) + iotrack->GetAlpha();
237 if (phi<-TMath::Pi()) phi+=2*TMath::Pi();
238 if (phi>=TMath::Pi()) phi-=2*TMath::Pi();
240 pt=1.0/TMath::Abs(par[4]);
242 Double_t tpx = pt * TMath::Cos(phi); //track x coordinate of momentum
243 Double_t tpy = pt * TMath::Sin(phi); //track y coordinate of momentum
244 Double_t tpz = pt * lam; //track z coordinate of momentum
246 Double_t mass = p->GetMass();
247 Double_t tEtot = TMath::Sqrt( tpx*tpx + tpy*tpy + tpz*tpz + mass*mass);//total energy of the track
249 AliHBTParticle* track = new AliHBTParticle(p->GetPdgCode(),i, tpx, tpy , tpz, tEtot, 0., 0., 0., 0.);
250 if(Pass(track))//check if meets all criteria of any of our cuts
251 //if it does not delete it and take next good track
257 fParticlesEvent->AddParticle(part);
258 fTracksEvent->AddParticle(track);
261 Info("ReadNext","Read %d tracks and %d particles from event %d (event %d in dir %d).",
262 fParticlesEvent->GetNumberOfParticles(), fTracksEvent->GetNumberOfParticles(),
263 fNEventsRead,fCurrentEvent,fCurrentDir);
264 fTrackCounter->Fill(fTracksEvent->GetNumberOfParticles());
269 }while(fCurrentDir < GetNumberOfDirs());
274 /********************************************************************/
276 Int_t AliHBTReaderTPC::OpenNextSession()
278 TString filename = GetDirName(fCurrentDir);
279 if (filename.IsNull())
281 DoOpenError("Can not get directory name");
284 filename = filename +"/"+ fFileName;
285 fRunLoader = AliRunLoader::Open(filename,AliConfig::fgkDefaultEventFolderName);
286 if( fRunLoader == 0x0)
288 DoOpenError("Can not open session.");
292 fRunLoader->LoadHeader();
293 if (fRunLoader->GetNumberOfEvents() <= 0)
295 DoOpenError("There is no events in this directory.");
299 if (fRunLoader->LoadKinematics())
301 DoOpenError("Error occured while loading kinematics.");
304 fTPCLoader = (AliTPCLoader*)fRunLoader->GetLoader("TPCLoader");
305 if ( fTPCLoader == 0x0)
307 DoOpenError("Exiting due to problems with opening files.");
310 Info("OpenNextSession","________________________________________________________");
311 Info("OpenNextSession","Found %d event(s) in directory %s",
312 fRunLoader->GetNumberOfEvents(),GetDirName(fCurrentDir).Data());
316 fRunLoader->LoadgAlice();
317 mf = fRunLoader->GetAliRun()->Field()->SolenoidField();
318 Info("OpenNextSession","Setting Magnetic Field from run: B=%fT",mf/10.);
319 fRunLoader->UnloadgAlice();
323 Info("OpenNextSession","Setting Own Magnetic Field: B=%fT",fMagneticField);
324 if (fMagneticField == 0x0)
326 Fatal("OpenNextSession","Magnetic field can not be 0.");
329 mf = fMagneticField*10.;
331 AliKalmanTrack::SetConvConst(1000/0.299792458/mf);
334 fRunLoader->CdGAFile();
335 AliTPCParam *TPCParam= (AliTPCParam*)gDirectory->Get("75x40_100x60");
338 TPCParam=(AliTPCParam *)gDirectory->Get("75x40_100x60_150x60");
341 DoOpenError("TPC parameters have not been found !\n");
346 if (fTPCLoader->LoadTracks())
348 DoOpenError("Error occured while loading TPC tracks.");
355 /********************************************************************/
357 void AliHBTReaderTPC::DoOpenError( const char *va_(fmt), ...)
359 // Does error display and clean-up in case error caught on Open Next Session
362 va_start(ap,va_(fmt));
363 Error("OpenNextSession", va_(fmt), ap);
372 /********************************************************************/
373 Bool_t AliHBTReaderTPC::CheckTrack(AliTPCtrack* t)
375 //Performs check of the track
376 if ( (t->GetNumberOfClusters() > fNClustMax) || (t->GetNumberOfClusters() < fNClustMin) ) return kTRUE;
379 t->GetCovariance(cc);
380 if ( (cc[9] < fC44Min) || (cc[9] > fC44Max) ) return kTRUE;
382 Float_t chisqpercl = t->GetChi2()/((Double_t)t->GetNumberOfClusters());
383 if ( (chisqpercl < fNChi2PerClustMin) || (chisqpercl > fNChi2PerClustMax) ) return kTRUE;
388 /********************************************************************/
390 void AliHBTReaderTPC::SetNClustersRange(Int_t min,Int_t max)
392 //sets range of Number Of Clusters that tracks have to have
396 /********************************************************************/
398 void AliHBTReaderTPC::SetChi2PerCluserRange(Float_t min, Float_t max)
400 //sets range of Chi2 per Cluster
401 fNChi2PerClustMin = min;
402 fNChi2PerClustMax = max;
404 /********************************************************************/
406 void AliHBTReaderTPC::SetC44Range(Float_t min, Float_t max)
408 //Sets range of C44 parameter of covariance matrix of the track
409 //it defines uncertainty of the momentum
414 /********************************************************************/
415 /********************************************************************/
416 /********************************************************************/
419 void (AliTPCtrack* iotrack, Double_t curv)
422 iotrack->GetExternalPara
424 Double_t fP4=iotrack->GetC();
425 Double_t fP2=iotrack->GetEta();
427 Double_t x1=fX, x2=x1+(xk-x1), dx=x2-x1, y1=fP0, z1=fP1;
428 Double_t c1=fP4*x1 - fP2, r1=sqrt(1.- c1*c1);
429 Double_t c2=fP4*x2 - fP2, r2=sqrt(1.- c2*c2);
431 fP0 += dx*(c1+c2)/(r1+r2);
432 fP1 += dx*(c1+c2)/(c1*r2 + c2*r1)*fP3;