1 #include "AliHBTReaderITSv2.h"
6 #include <TObjString.h>
11 #include <AliRunLoader.h>
12 #include <AliLoader.h>
15 #include <AliITStrackV2.h>
17 #include "AliHBTRun.h"
18 #include "AliHBTEvent.h"
19 #include "AliHBTParticle.h"
20 #include "AliHBTParticleCut.h"
23 ClassImp(AliHBTReaderITSv2)
25 AliHBTReaderITSv2::AliHBTReaderITSv2():
26 fFileName("galice.root"),
30 fUseMagFFromRun(kTRUE)
34 // galicefilename = "galice.root"
36 /********************************************************************/
38 AliHBTReaderITSv2::AliHBTReaderITSv2(const Char_t* galicefilename):
39 fFileName(galicefilename),
43 fUseMagFFromRun(kTRUE)
47 // galicefilename = "galice.root"
49 /********************************************************************/
51 AliHBTReaderITSv2::AliHBTReaderITSv2(TObjArray* dirs, const Char_t* galicefilename):
53 fFileName(galicefilename),
57 fUseMagFFromRun(kTRUE)
61 // galicefilename = "galice.root"
64 /********************************************************************/
66 void AliHBTReaderITSv2::Rewind()
74 /********************************************************************/
76 AliHBTReaderITSv2::~AliHBTReaderITSv2()
81 /********************************************************************/
83 Int_t AliHBTReaderITSv2::ReadNext()
85 //reads data from next event
87 register Int_t i = 0; //iterator
89 // AliITStrackerV2 *tracker; // ITS tracker - used for cooking labels
90 TTree *tracktree = 0x0; // tree for tracks
91 AliITStrackV2 *iotrack = 0x0;
94 Double_t par[5]; //Kalman track parameters
95 Float_t phi, lam, pt;//angles and transverse momentum
96 Int_t label; //label of the current track
99 if (fParticlesEvent == 0x0) fParticlesEvent = new AliHBTEvent();
100 if (fTracksEvent == 0x0) fTracksEvent = new AliHBTEvent();
102 fParticlesEvent->Reset();
103 fTracksEvent->Reset();
104 do //do while is good even if Ndirs==0 (than read from current directory)
106 if (fRunLoader == 0x0)
107 if (OpenNextFile()) continue;//directory counter is increased inside in case of error
109 if (fCurrentEvent == fRunLoader->GetNumberOfEvents())
111 //read next directory
112 delete fRunLoader;//close current session
113 fRunLoader = 0x0;//assure pointer is null
114 fCurrentDir++;//go to next dir
115 continue;//directory counter is increased inside in case of error
118 Info("ReadNext","Reading Event %d",fCurrentEvent);
120 fRunLoader->GetEvent(fCurrentEvent);
122 tracktree=fITSLoader->TreeT();
125 Error("ReadNext","Can't get a tree with ITS tracks");
130 TBranch *tbranch=tracktree->GetBranch("tracks");
133 Error("ReadNext","Can't get a branch with ITS tracks");
138 AliStack* stack = fRunLoader->Stack();
141 Error("ReadNext","Can not get stack for current event",fCurrentEvent);
146 //must be here because on the beginning conv. const. is not set yet
147 if (iotrack == 0x0) iotrack = new AliITStrackV2(); //buffer track for reading data from tree
149 Int_t ntr = (Int_t)tracktree->GetEntries();
151 for (i=0; i < ntr; i++) //loop over all tpc tracks
153 tbranch->SetAddress(&iotrack);
154 tracktree->GetEvent(i);
156 label=iotrack->GetLabel();
162 TParticle *p = stack->Particle(label);
163 if(p == 0x0) continue; //if returned pointer is NULL
164 if(p->GetPDG() == 0x0) continue; //if particle has crezy PDG code (not known to our database)
166 if(Pass(p->GetPdgCode())) continue; //check if we are intersted with particles of this type
167 //if not take next partilce
169 AliHBTParticle* part = new AliHBTParticle(*p,i);
170 if(Pass(part)) { delete part; continue;}//check if meets all criteria of any of our cuts
171 //if it does not delete it and take next good track
173 iotrack->PropagateTo(3.,0.0028,65.19);
174 iotrack->PropagateToVertex();
176 iotrack->GetExternalParameters(xk,par); //get properties of the track
177 phi=TMath::ASin(par[2]) + iotrack->GetAlpha();
178 if (phi<-TMath::Pi()) phi+=2*TMath::Pi();
179 if (phi>=TMath::Pi()) phi-=2*TMath::Pi();
181 pt=1.0/TMath::Abs(par[4]);
183 Double_t tpx = pt * TMath::Cos(phi); //track x coordinate of momentum
184 Double_t tpy = pt * TMath::Sin(phi); //track y coordinate of momentum
185 Double_t tpz = pt * lam; //track z coordinate of momentum
187 Double_t mass = p->GetMass();
188 Double_t tEtot = TMath::Sqrt( tpx*tpx + tpy*tpy + tpz*tpz + mass*mass);//total energy of the track
190 AliHBTParticle* track = new AliHBTParticle(p->GetPdgCode(), i, tpx, tpy , tpz, tEtot, 0., 0., 0., 0.);
191 if(Pass(track))//check if meets all criteria of any of our cuts
192 //if it does not delete it and take next good track
199 fParticlesEvent->AddParticle(part);
200 fTracksEvent->AddParticle(track);
201 }//end of loop over tracks in the event
203 Info("ReadNext","Read %d tracks and %d particles from event %d (event %d in dir %d).",
204 fParticlesEvent->GetNumberOfParticles(), fTracksEvent->GetNumberOfParticles(),
205 fNEventsRead,fCurrentEvent,fCurrentDir);
211 }while(fCurrentDir < GetNumberOfDirs());//end of loop over directories specified in fDirs Obj Array
217 /********************************************************************/
218 Int_t AliHBTReaderITSv2::OpenNextFile()
221 TString filename = GetDirName(fCurrentDir);
222 if (filename.IsNull())
224 DoOpenError("Can not get directory name");
227 filename = filename +"/"+ fFileName;
228 fRunLoader = AliRunLoader::Open(filename,AliConfig::fgkDefaultEventFolderName);
229 if( fRunLoader == 0x0)
231 DoOpenError("Can not open session.");
235 if (fRunLoader->GetNumberOfEvents() <= 0)
237 DoOpenError("There is no events in this directory.");
241 if (fRunLoader->LoadKinematics())
243 DoOpenError("Error occured while loading kinematics.");
246 fITSLoader = fRunLoader->GetLoader("ITSLoader");
247 if ( fITSLoader == 0x0)
249 DoOpenError("Exiting due to problems with opening files.");
253 Info("OpenNextSession","________________________________________________________");
254 Info("OpenNextSession","Found %d event(s) in directory %s",
255 fRunLoader->GetNumberOfEvents(),GetDirName(fCurrentDir).Data());
259 if (fRunLoader->LoadgAlice())
261 DoOpenError("Error occured while loading AliRun.");
264 mf = fRunLoader->GetAliRun()->Field()->SolenoidField();
265 Info("OpenNextSession","Setting Magnetic Field from run: B=%fT",mf/10.);
266 fRunLoader->UnloadgAlice();
270 Info("OpenNextSession","Setting Own Magnetic Field: B=%fT",fMagneticField);
271 if (fMagneticField == 0x0)
273 Fatal("OpenNextSession","Magnetic field can not be 0.");
276 mf = fMagneticField*10.;
278 AliKalmanTrack::SetConvConst(1000/0.299792458/mf);
280 if (fITSLoader->LoadTracks())
282 DoOpenError("Error occured while loading TPC tracks.");
289 /********************************************************************/
291 void AliHBTReaderITSv2::DoOpenError( const char *va_(fmt), ...)
293 // Does error display and clean-up in case error caught on Open Next Session
296 va_start(ap,va_(fmt));
297 Error("OpenNextFile", va_(fmt), ap);
306 /********************************************************************/