]>
Commit | Line | Data |
---|---|---|
1b446896 | 1 | #include "AliHBTReaderTPC.h" |
3f745d47 | 2 | //______________________________________________ |
3 | // | |
4 | // class AliHBTReaderTPC | |
5 | // | |
6 | // reader for TPC tracking | |
7 | // needs galice.root, AliTPCtracks.root, AliTPCclusters.root | |
8 | // | |
9 | // more info: http://aliweb.cern.ch/people/skowron/analyzer/index.html | |
10 | // Piotr.Skowronski@cern.ch | |
11 | // | |
12 | /////////////////////////////////////////////////////////////////////////// | |
1b446896 | 13 | #include <TTree.h> |
14 | #include <TFile.h> | |
16701d1b | 15 | #include <TParticle.h> |
bfb09ece | 16 | #include <TH1.h> |
1b446896 | 17 | |
bed069a4 | 18 | #include <Varargs.h> |
19 | ||
16701d1b | 20 | #include <AliRun.h> |
88cb7938 | 21 | #include <AliLoader.h> |
22 | #include <AliStack.h> | |
16701d1b | 23 | #include <AliMagF.h> |
1b446896 | 24 | #include <AliTPCtrack.h> |
25 | #include <AliTPCParam.h> | |
88cb7938 | 26 | #include <AliTPCtracker.h> |
bed069a4 | 27 | #include <AliTPCLoader.h> |
1b446896 | 28 | |
1b446896 | 29 | #include "AliHBTRun.h" |
30 | #include "AliHBTEvent.h" | |
31 | #include "AliHBTParticle.h" | |
32 | #include "AliHBTParticleCut.h" | |
33 | ||
bfb09ece | 34 | |
35 | ||
1b446896 | 36 | ClassImp(AliHBTReaderTPC) |
3f745d47 | 37 | |
bed069a4 | 38 | AliHBTReaderTPC::AliHBTReaderTPC(): |
39 | fFileName("galice.root"), | |
40 | fRunLoader(0x0), | |
41 | fTPCLoader(0x0), | |
42 | fMagneticField(0.0), | |
3f745d47 | 43 | fUseMagFFromRun(kTRUE), |
44 | fNClustMin(0), | |
45 | fNClustMax(190), | |
46 | fNChi2PerClustMin(0.0), | |
47 | fNChi2PerClustMax(10e5), | |
48 | fC44Min(0.0), | |
49 | fC44Max(10e5) | |
88cb7938 | 50 | { |
51 | //constructor, | |
52 | //Defaults: | |
53 | // galicefilename = "" - this means: Do not open gAlice file - | |
54 | // just leave the global pointer untouched | |
55 | ||
88cb7938 | 56 | } |
98295f4b | 57 | |
bed069a4 | 58 | AliHBTReaderTPC::AliHBTReaderTPC(const Char_t* galicefilename): |
59 | fFileName(galicefilename), | |
60 | fRunLoader(0x0), | |
61 | fTPCLoader(0x0), | |
62 | fMagneticField(0.0), | |
3f745d47 | 63 | fUseMagFFromRun(kTRUE), |
64 | fNClustMin(0), | |
65 | fNClustMax(190), | |
66 | fNChi2PerClustMin(0.0), | |
67 | fNChi2PerClustMax(10e5), | |
68 | fC44Min(0.0), | |
69 | fC44Max(10e5) | |
1b446896 | 70 | { |
16701d1b | 71 | //constructor, |
1b446896 | 72 | //Defaults: |
1b446896 | 73 | // galicefilename = "" - this means: Do not open gAlice file - |
88cb7938 | 74 | // just leave the global pointer untouched |
1b446896 | 75 | |
16701d1b | 76 | } |
77 | /********************************************************************/ | |
88cb7938 | 78 | AliHBTReaderTPC::AliHBTReaderTPC(TObjArray* dirs, const Char_t* galicefilename): |
bed069a4 | 79 | AliHBTReader(dirs), |
80 | fFileName(galicefilename), | |
81 | fRunLoader(0x0), | |
82 | fTPCLoader(0x0), | |
83 | fMagneticField(0.0), | |
3f745d47 | 84 | fUseMagFFromRun(kTRUE), |
85 | fNClustMin(0), | |
86 | fNClustMax(190), | |
87 | fNChi2PerClustMin(0.0), | |
88 | fNChi2PerClustMax(10e5), | |
89 | fC44Min(0.0), | |
90 | fC44Max(10e5) | |
16701d1b | 91 | { |
92 | //constructor, | |
93 | //Defaults: | |
16701d1b | 94 | // galicefilename = "" - this means: Do not open gAlice file - |
95 | // just leave the global pointer untached | |
88cb7938 | 96 | |
1b446896 | 97 | } |
98 | /********************************************************************/ | |
99 | ||
100 | AliHBTReaderTPC::~AliHBTReaderTPC() | |
bed069a4 | 101 | { |
1b446896 | 102 | //desctructor |
3f745d47 | 103 | if (AliHBTParticle::GetDebug()) |
104 | { | |
105 | Info("~AliHBTReaderTPC","deleting Run Loader"); | |
106 | AliLoader::SetDebug(AliHBTParticle::GetDebug()); | |
107 | } | |
108 | ||
bed069a4 | 109 | delete fRunLoader; |
3f745d47 | 110 | |
111 | if (AliHBTParticle::GetDebug()) | |
112 | { | |
113 | Info("~AliHBTReaderTPC","deleting Run Loader Done"); | |
114 | } | |
bed069a4 | 115 | } |
1b446896 | 116 | /********************************************************************/ |
bed069a4 | 117 | |
118 | void AliHBTReaderTPC::Rewind() | |
119 | { | |
120 | delete fRunLoader; | |
121 | fRunLoader = 0x0; | |
122 | fCurrentDir = 0; | |
123 | fNEventsRead= 0; | |
bfb09ece | 124 | if (fTrackCounter) fTrackCounter->Reset(); |
bed069a4 | 125 | } |
1b446896 | 126 | /********************************************************************/ |
127 | ||
bed069a4 | 128 | Int_t AliHBTReaderTPC::ReadNext() |
1b446896 | 129 | { |
130 | //reads data and puts put to the particles and tracks objects | |
131 | //reurns 0 if everything is OK | |
132 | // | |
8fe7288a | 133 | Info("Read",""); |
bfb09ece | 134 | |
135 | Int_t ntracksread = 0; | |
16701d1b | 136 | |
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 | |
b71a5edb | 141 | |
bed069a4 | 142 | if (fParticlesEvent == 0x0) fParticlesEvent = new AliHBTEvent(); |
143 | if (fTracksEvent == 0x0) fTracksEvent = new AliHBTEvent(); | |
144 | ||
145 | fParticlesEvent->Reset(); | |
146 | fTracksEvent->Reset(); | |
b71a5edb | 147 | |
16701d1b | 148 | do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./" |
1b446896 | 149 | { |
bed069a4 | 150 | |
151 | if (fRunLoader == 0x0) | |
152 | if (OpenNextSession()) continue;//directory counter is increased inside in case of error | |
153 | ||
154 | if (fCurrentEvent == fRunLoader->GetNumberOfEvents()) | |
88cb7938 | 155 | { |
bed069a4 | 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 | |
16701d1b | 161 | } |
bed069a4 | 162 | |
163 | Info("ReadNext","Reading Event %d",fCurrentEvent); | |
1b446896 | 164 | |
bed069a4 | 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"); | |
8041e7cf | 170 | fCurrentEvent++;//go to next dir |
bed069a4 | 171 | continue; |
172 | } | |
173 | ||
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"); | |
8041e7cf | 178 | fCurrentEvent++;//go to next dir |
bed069a4 | 179 | continue; |
180 | } | |
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 | |
184 | ||
185 | AliTPCtrack *iotrack=0; | |
186 | ||
187 | for (Int_t i=0; i<ntpctracks; i++) //loop over all tpc tracks | |
88cb7938 | 188 | { |
bed069a4 | 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 | |
88cb7938 | 193 | } |
bed069a4 | 194 | |
195 | Double_t xk; | |
196 | Double_t par[5]; | |
197 | Float_t phi, lam, pt;//angles and transverse momentum | |
198 | Int_t label; //label of the current track | |
199 | ||
200 | AliStack* stack = fRunLoader->Stack(); | |
201 | if (stack == 0x0) | |
16701d1b | 202 | { |
bed069a4 | 203 | Error("ReadNext","Can not get stack for current event",fCurrentEvent); |
204 | fCurrentEvent++; | |
5ee8b891 | 205 | continue; |
16701d1b | 206 | } |
bed069a4 | 207 | stack->Particles(); |
208 | ||
209 | for (Int_t i=0; i<ntpctracks; i++) //loop over all good tracks | |
210 | { | |
211 | iotrack = (AliTPCtrack*)tarray->At(i); | |
212 | label = iotrack->GetLabel(); | |
213 | ||
214 | if (label < 0) continue; | |
3f745d47 | 215 | |
216 | if (CheckTrack(iotrack)) continue; | |
217 | ||
bed069a4 | 218 | TParticle *p = (TParticle*)stack->Particle(label); |
219 | ||
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) | |
222 | ||
223 | if(Pass(p->GetPdgCode())) continue; //check if we are intersted with particles of this type | |
224 | //if not take next partilce | |
225 | ||
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 | |
229 | ||
230 | // iotrack->PropagateTo(3.,0.0028,65.19); | |
231 | // iotrack->PropagateToVertex(36.66,1.2e-3);//orig | |
232 | iotrack->PropagateToVertex(50.,0.0353); | |
233 | ||
234 | iotrack->GetExternalParameters(xk,par); //get properties of the track | |
3f745d47 | 235 | |
bed069a4 | 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(); | |
239 | lam=par[3]; | |
240 | pt=1.0/TMath::Abs(par[4]); | |
241 | ||
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 | |
245 | ||
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 | |
248 | ||
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 | |
252 | { | |
253 | delete track; | |
254 | delete part; | |
255 | continue; | |
256 | } | |
257 | fParticlesEvent->AddParticle(part); | |
258 | fTracksEvent->AddParticle(track); | |
259 | } | |
260 | ||
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); | |
bfb09ece | 264 | fTrackCounter->Fill(fTracksEvent->GetNumberOfParticles()); |
bed069a4 | 265 | fCurrentEvent++; |
266 | fNEventsRead++; | |
267 | delete tarray; | |
268 | return 0; | |
269 | }while(fCurrentDir < GetNumberOfDirs()); | |
270 | ||
271 | delete tarray; | |
272 | return 1; | |
273 | } | |
274 | /********************************************************************/ | |
275 | ||
276 | Int_t AliHBTReaderTPC::OpenNextSession() | |
277 | { | |
278 | TString filename = GetDirName(fCurrentDir); | |
279 | if (filename.IsNull()) | |
280 | { | |
281 | DoOpenError("Can not get directory name"); | |
282 | return 1; | |
283 | } | |
284 | filename = filename +"/"+ fFileName; | |
285 | fRunLoader = AliRunLoader::Open(filename,AliConfig::fgkDefaultEventFolderName); | |
286 | if( fRunLoader == 0x0) | |
287 | { | |
288 | DoOpenError("Can not open session."); | |
289 | return 1; | |
290 | } | |
291 | ||
292 | fRunLoader->LoadHeader(); | |
293 | if (fRunLoader->GetNumberOfEvents() <= 0) | |
294 | { | |
295 | DoOpenError("There is no events in this directory."); | |
296 | return 1; | |
297 | } | |
298 | ||
299 | if (fRunLoader->LoadKinematics()) | |
300 | { | |
301 | DoOpenError("Error occured while loading kinematics."); | |
302 | return 1; | |
303 | } | |
304 | fTPCLoader = (AliTPCLoader*)fRunLoader->GetLoader("TPCLoader"); | |
305 | if ( fTPCLoader == 0x0) | |
306 | { | |
307 | DoOpenError("Exiting due to problems with opening files."); | |
308 | return 1; | |
309 | } | |
310 | Info("OpenNextSession","________________________________________________________"); | |
311 | Info("OpenNextSession","Found %d event(s) in directory %s", | |
312 | fRunLoader->GetNumberOfEvents(),GetDirName(fCurrentDir).Data()); | |
313 | Float_t mf; | |
314 | if (fUseMagFFromRun) | |
315 | { | |
316 | fRunLoader->LoadgAlice(); | |
317 | mf = fRunLoader->GetAliRun()->Field()->SolenoidField(); | |
318 | Info("OpenNextSession","Setting Magnetic Field from run: B=%fT",mf/10.); | |
319 | fRunLoader->UnloadgAlice(); | |
320 | } | |
321 | else | |
322 | { | |
323 | Info("OpenNextSession","Setting Own Magnetic Field: B=%fT",fMagneticField); | |
324 | if (fMagneticField == 0x0) | |
325 | { | |
326 | Fatal("OpenNextSession","Magnetic field can not be 0."); | |
327 | return 1;//pro forma | |
16701d1b | 328 | } |
bed069a4 | 329 | mf = fMagneticField*10.; |
330 | } | |
331 | AliKalmanTrack::SetConvConst(1000/0.299792458/mf); | |
1b446896 | 332 | |
16701d1b | 333 | |
bed069a4 | 334 | fRunLoader->CdGAFile(); |
335 | AliTPCParam *TPCParam= (AliTPCParam*)gDirectory->Get("75x40_100x60"); | |
336 | if (!TPCParam) | |
337 | { | |
338 | TPCParam=(AliTPCParam *)gDirectory->Get("75x40_100x60_150x60"); | |
339 | if (!TPCParam) | |
340 | { | |
341 | DoOpenError("TPC parameters have not been found !\n"); | |
342 | return 1; | |
343 | } | |
344 | } | |
345 | ||
346 | if (fTPCLoader->LoadTracks()) | |
347 | { | |
348 | DoOpenError("Error occured while loading TPC tracks."); | |
349 | return 1; | |
350 | } | |
88cb7938 | 351 | |
bed069a4 | 352 | fCurrentEvent = 0; |
1b446896 | 353 | return 0; |
bed069a4 | 354 | } |
355 | /********************************************************************/ | |
1b446896 | 356 | |
bed069a4 | 357 | void AliHBTReaderTPC::DoOpenError( const char *va_(fmt), ...) |
358 | { | |
359 | // Does error display and clean-up in case error caught on Open Next Session | |
360 | ||
361 | va_list ap; | |
362 | va_start(ap,va_(fmt)); | |
363 | Error("OpenNextSession", va_(fmt), ap); | |
364 | va_end(ap); | |
365 | ||
366 | delete fRunLoader; | |
367 | fRunLoader = 0x0; | |
368 | fTPCLoader = 0x0; | |
369 | fCurrentDir++; | |
370 | } | |
1b446896 | 371 | |
3f745d47 | 372 | /********************************************************************/ |
373 | Bool_t AliHBTReaderTPC::CheckTrack(AliTPCtrack* t) | |
374 | { | |
375 | //Performs check of the track | |
376 | if ( (t->GetNumberOfClusters() > fNClustMax) || (t->GetNumberOfClusters() < fNClustMin) ) return kTRUE; | |
377 | ||
378 | Double_t cc[15]; | |
379 | t->GetCovariance(cc); | |
380 | if ( (cc[9] < fC44Min) || (cc[9] > fC44Max) ) return kTRUE; | |
381 | ||
382 | Float_t chisqpercl = t->GetChi2()/((Double_t)t->GetNumberOfClusters()); | |
383 | if ( (chisqpercl < fNChi2PerClustMin) || (chisqpercl > fNChi2PerClustMax) ) return kTRUE; | |
384 | ||
385 | return kFALSE; | |
386 | ||
387 | } | |
388 | /********************************************************************/ | |
389 | ||
390 | void AliHBTReaderTPC::SetNClustersRange(Int_t min,Int_t max) | |
391 | { | |
392 | //sets range of Number Of Clusters that tracks have to have | |
393 | fNClustMin = min; | |
394 | fNClustMax = max; | |
395 | } | |
396 | /********************************************************************/ | |
397 | ||
398 | void AliHBTReaderTPC::SetChi2PerCluserRange(Float_t min, Float_t max) | |
399 | { | |
400 | //sets range of Chi2 per Cluster | |
401 | fNChi2PerClustMin = min; | |
402 | fNChi2PerClustMax = max; | |
403 | } | |
404 | /********************************************************************/ | |
405 | ||
406 | void AliHBTReaderTPC::SetC44Range(Float_t min, Float_t max) | |
407 | { | |
408 | //Sets range of C44 parameter of covariance matrix of the track | |
409 | //it defines uncertainty of the momentum | |
410 | fC44Min = min; | |
411 | fC44Max = max; | |
412 | } | |
413 | ||
1b446896 | 414 | /********************************************************************/ |
415 | /********************************************************************/ | |
416 | /********************************************************************/ | |
417 | ||
3f745d47 | 418 | /* |
419 | void (AliTPCtrack* iotrack, Double_t curv) | |
420 | { | |
421 | Double_t x[5]; | |
422 | iotrack->GetExternalPara | |
423 | //xk is a | |
424 | Double_t fP4=iotrack->GetC(); | |
425 | Double_t fP2=iotrack->GetEta(); | |
426 | ||
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); | |
430 | ||
431 | fP0 += dx*(c1+c2)/(r1+r2); | |
432 | fP1 += dx*(c1+c2)/(c1*r2 + c2*r1)*fP3; | |
433 | ||
434 | } | |
435 | */ | |
436 |