1 #include "AliHBTReaderTPC.h"
10 #include <AliLoader.h>
13 #include <AliTPCtrack.h>
14 #include <AliTPCParam.h>
15 #include <AliTPCtracker.h>
16 #include <AliTPCLoader.h>
18 #include "AliHBTRun.h"
19 #include "AliHBTEvent.h"
20 #include "AliHBTParticle.h"
21 #include "AliHBTParticleCut.h"
23 ClassImp(AliHBTReaderTPC)
24 //______________________________________________
26 // class AliHBTReaderTPC
28 //reader for TPC tracking
29 //needs galice.root, AliTPCtracks.root, AliTPCclusters.root
31 //more info: http://alisoft.cern.ch/people/skowron/analyzer/index.html
32 //Piotr.Skowronski@cern.ch
33 AliHBTReaderTPC::AliHBTReaderTPC():
34 fFileName("galice.root"),
38 fUseMagFFromRun(kTRUE)
42 // galicefilename = "" - this means: Do not open gAlice file -
43 // just leave the global pointer untouched
47 AliHBTReaderTPC::AliHBTReaderTPC(const Char_t* galicefilename):
48 fFileName(galicefilename),
52 fUseMagFFromRun(kTRUE)
56 // galicefilename = "" - this means: Do not open gAlice file -
57 // just leave the global pointer untouched
60 /********************************************************************/
61 AliHBTReaderTPC::AliHBTReaderTPC(TObjArray* dirs, const Char_t* galicefilename):
63 fFileName(galicefilename),
67 fUseMagFFromRun(kTRUE)
71 // galicefilename = "" - this means: Do not open gAlice file -
72 // just leave the global pointer untached
75 /********************************************************************/
77 AliHBTReaderTPC::~AliHBTReaderTPC()
82 /********************************************************************/
84 void AliHBTReaderTPC::Rewind()
91 /********************************************************************/
93 Int_t AliHBTReaderTPC::ReadNext()
95 //reads data and puts put to the particles and tracks objects
96 //reurns 0 if everything is OK
101 TObjArray *tarray = new TObjArray(5000); //cotainer for tpc tracks
102 tarray->SetOwner(); //set the ownership of the objects it contains
103 //when array is is deleted or cleared all objects
104 //that it contains are deleted
106 if (fParticlesEvent == 0x0) fParticlesEvent = new AliHBTEvent();
107 if (fTracksEvent == 0x0) fTracksEvent = new AliHBTEvent();
109 fParticlesEvent->Reset();
110 fTracksEvent->Reset();
112 do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
115 if (fRunLoader == 0x0)
116 if (OpenNextSession()) continue;//directory counter is increased inside in case of error
118 if (fCurrentEvent == fRunLoader->GetNumberOfEvents())
120 //read next directory
121 delete fRunLoader;//close current session
122 fRunLoader = 0x0;//assure pointer is null
123 fCurrentDir++;//go to next dir
124 continue;//directory counter is increased inside in case of error
127 Info("ReadNext","Reading Event %d",fCurrentEvent);
129 fRunLoader->GetEvent(fCurrentEvent);
130 TTree *tracktree = fTPCLoader->TreeT();//get the tree
131 if (!tracktree) //check if we got the tree
132 {//if not return with error
133 Error("ReadNext","Can't get a tree with TPC tracks !\n");
137 TBranch *trackbranch=tracktree->GetBranch("tracks");//get the branch with tracks
138 if (!trackbranch) ////check if we got the branch
139 {//if not return with error
140 Error("ReadNext","Can't get a branch with TPC tracks !\n");
143 Int_t ntpctracks=(Int_t)tracktree->GetEntries();//get number of TPC tracks
144 Info("ReadNext","Found %d TPC tracks.",ntpctracks);
145 //Copy tracks to array
147 AliTPCtrack *iotrack=0;
149 for (Int_t i=0; i<ntpctracks; i++) //loop over all tpc tracks
151 iotrack=new AliTPCtrack; //create new tracks
152 trackbranch->SetAddress(&iotrack); //tell the branch ehere to put track data from tree(file)
153 tracktree->GetEvent(i); //stream track i to the iotrack
154 tarray->AddLast(iotrack); //put the track in the array
159 Float_t phi, lam, pt;//angles and transverse momentum
160 Int_t label; //label of the current track
162 AliStack* stack = fRunLoader->Stack();
165 Error("ReadNext","Can not get stack for current event",fCurrentEvent);
171 for (Int_t i=0; i<ntpctracks; i++) //loop over all good tracks
173 iotrack = (AliTPCtrack*)tarray->At(i);
174 label = iotrack->GetLabel();
176 if (label < 0) continue;
178 TParticle *p = (TParticle*)stack->Particle(label);
180 if(p == 0x0) continue; //if returned pointer is NULL
181 if(p->GetPDG() == 0x0) continue; //if particle has crezy PDG code (not known to our database)
183 if(Pass(p->GetPdgCode())) continue; //check if we are intersted with particles of this type
184 //if not take next partilce
186 AliHBTParticle* part = new AliHBTParticle(*p,i);
187 if(Pass(part)) { delete part; continue;}//check if meets all criteria of any of our cuts
188 //if it does not delete it and take next good track
190 // iotrack->PropagateTo(3.,0.0028,65.19);
191 // iotrack->PropagateToVertex(36.66,1.2e-3);//orig
192 iotrack->PropagateToVertex(50.,0.0353);
194 iotrack->GetExternalParameters(xk,par); //get properties of the track
195 phi=TMath::ASin(par[2]) + iotrack->GetAlpha();
196 if (phi<-TMath::Pi()) phi+=2*TMath::Pi();
197 if (phi>=TMath::Pi()) phi-=2*TMath::Pi();
199 pt=1.0/TMath::Abs(par[4]);
201 Double_t tpx = pt * TMath::Cos(phi); //track x coordinate of momentum
202 Double_t tpy = pt * TMath::Sin(phi); //track y coordinate of momentum
203 Double_t tpz = pt * lam; //track z coordinate of momentum
205 Double_t mass = p->GetMass();
206 Double_t tEtot = TMath::Sqrt( tpx*tpx + tpy*tpy + tpz*tpz + mass*mass);//total energy of the track
208 AliHBTParticle* track = new AliHBTParticle(p->GetPdgCode(),i, tpx, tpy , tpz, tEtot, 0., 0., 0., 0.);
209 if(Pass(track))//check if meets all criteria of any of our cuts
210 //if it does not delete it and take next good track
216 fParticlesEvent->AddParticle(part);
217 fTracksEvent->AddParticle(track);
220 Info("ReadNext","Read %d tracks and %d particles from event %d (event %d in dir %d).",
221 fParticlesEvent->GetNumberOfParticles(), fTracksEvent->GetNumberOfParticles(),
222 fNEventsRead,fCurrentEvent,fCurrentDir);
228 }while(fCurrentDir < GetNumberOfDirs());
233 /********************************************************************/
235 Int_t AliHBTReaderTPC::OpenNextSession()
237 TString filename = GetDirName(fCurrentDir);
238 if (filename.IsNull())
240 DoOpenError("Can not get directory name");
243 filename = filename +"/"+ fFileName;
244 fRunLoader = AliRunLoader::Open(filename,AliConfig::fgkDefaultEventFolderName);
245 if( fRunLoader == 0x0)
247 DoOpenError("Can not open session.");
251 fRunLoader->LoadHeader();
252 if (fRunLoader->GetNumberOfEvents() <= 0)
254 DoOpenError("There is no events in this directory.");
258 if (fRunLoader->LoadKinematics())
260 DoOpenError("Error occured while loading kinematics.");
263 fTPCLoader = (AliTPCLoader*)fRunLoader->GetLoader("TPCLoader");
264 if ( fTPCLoader == 0x0)
266 DoOpenError("Exiting due to problems with opening files.");
269 Info("OpenNextSession","________________________________________________________");
270 Info("OpenNextSession","Found %d event(s) in directory %s",
271 fRunLoader->GetNumberOfEvents(),GetDirName(fCurrentDir).Data());
275 fRunLoader->LoadgAlice();
276 mf = fRunLoader->GetAliRun()->Field()->SolenoidField();
277 Info("OpenNextSession","Setting Magnetic Field from run: B=%fT",mf/10.);
278 fRunLoader->UnloadgAlice();
282 Info("OpenNextSession","Setting Own Magnetic Field: B=%fT",fMagneticField);
283 if (fMagneticField == 0x0)
285 Fatal("OpenNextSession","Magnetic field can not be 0.");
288 mf = fMagneticField*10.;
290 AliKalmanTrack::SetConvConst(1000/0.299792458/mf);
293 fRunLoader->CdGAFile();
294 AliTPCParam *TPCParam= (AliTPCParam*)gDirectory->Get("75x40_100x60");
297 TPCParam=(AliTPCParam *)gDirectory->Get("75x40_100x60_150x60");
300 DoOpenError("TPC parameters have not been found !\n");
305 if (fTPCLoader->LoadTracks())
307 DoOpenError("Error occured while loading TPC tracks.");
314 /********************************************************************/
316 void AliHBTReaderTPC::DoOpenError( const char *va_(fmt), ...)
318 // Does error display and clean-up in case error caught on Open Next Session
321 va_start(ap,va_(fmt));
322 Error("OpenNextSession", va_(fmt), ap);
331 /********************************************************************/
332 /********************************************************************/
333 /********************************************************************/