]>
Commit | Line | Data |
---|---|---|
9e1a0ddb | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | /* | |
17 | $Log$ | |
da2af24c | 18 | Revision 1.13 2001/08/29 13:31:42 morsch |
19 | Protection against (fTreeK == 0) in destructor. | |
20 | ||
cfb2cc9c | 21 | Revision 1.12 2001/07/27 13:03:13 hristov |
22 | Default Branch split level set to 99 | |
23 | ||
d0f40f23 | 24 | Revision 1.11 2001/07/27 12:34:20 jchudoba |
25 | remove the dummy argument in GetEvent method | |
26 | ||
cec14bc5 | 27 | Revision 1.10 2001/07/20 10:13:54 morsch |
28 | In Particle(Int_t) use GetEntriesFast to speed up the procedure. | |
29 | ||
911a3148 | 30 | Revision 1.9 2001/07/03 08:10:57 hristov |
31 | J.Chudoba's changes merged correctly with the HEAD | |
32 | ||
d1750cff | 33 | Revision 1.6 2001/05/31 06:59:06 fca |
34 | Clean setting and deleting of fParticleBuffer | |
35 | ||
17f4a3d9 | 36 | Revision 1.5 2001/05/30 12:18:46 hristov |
37 | Loop variables declared once | |
38 | ||
3ab6f951 | 39 | Revision 1.4 2001/05/25 07:25:20 hristov |
40 | AliStack destructor corrected (I.Hrivnacova) | |
41 | ||
81694e6a | 42 | Revision 1.3 2001/05/22 14:33:16 hristov |
43 | Minor changes | |
44 | ||
ed54bf31 | 45 | Revision 1.2 2001/05/17 05:49:39 fca |
46 | Reset pointers to daughters | |
47 | ||
76969085 | 48 | Revision 1.1 2001/05/16 14:57:22 alibrary |
49 | New files for folders and Stack | |
50 | ||
9e1a0ddb | 51 | */ |
52 | ||
53 | /////////////////////////////////////////////////////////////////////////////// | |
54 | // // | |
55 | // Particles stack class | |
56 | // // | |
57 | /////////////////////////////////////////////////////////////////////////////// | |
58 | ||
59 | #include <iostream.h> | |
60 | ||
61 | #include <TObjArray.h> | |
62 | #include <TParticle.h> | |
63 | #include <TTree.h> | |
64 | #include <TFile.h> | |
65 | #include <TFolder.h> | |
66 | #include <TROOT.h> | |
67 | ||
68 | #include "AliStack.h" | |
69 | #include "AliRun.h" | |
70 | #include "AliModule.h" | |
71 | #include "AliHit.h" | |
72 | //#include "ETrackBits.h" | |
73 | ||
74 | ClassImp(AliStack) | |
75 | ||
76 | //_____________________________________________________________________________ | |
77 | AliStack::AliStack(Int_t size) | |
78 | { | |
79 | // | |
80 | // Constructor | |
81 | // | |
82 | ||
83 | // Create the particles arrays | |
84 | fParticles = new TClonesArray("TParticle",1000); | |
85 | fParticleMap = new TObjArray(size); | |
17f4a3d9 | 86 | fParticleBuffer = 0; |
ccf7a81f | 87 | fNtrack = 0; |
88 | fNprimary = 0; | |
9e1a0ddb | 89 | fCurrent = -1; |
90 | fCurrentPrimary = -1; | |
ccf7a81f | 91 | fTreeK = 0; |
9e1a0ddb | 92 | } |
93 | ||
94 | ||
95 | //_____________________________________________________________________________ | |
96 | AliStack::AliStack() | |
97 | { | |
98 | // | |
99 | // Default constructor | |
100 | // | |
101 | ||
102 | // Create the particles arrays | |
103 | fParticles = new TClonesArray("TParticle",1000); | |
104 | fParticleMap = new TObjArray(10000); | |
17f4a3d9 | 105 | fParticleBuffer = 0; |
ccf7a81f | 106 | fNtrack = 0; |
9e1a0ddb | 107 | fCurrent = -1; |
ccf7a81f | 108 | fNprimary = 0; |
9e1a0ddb | 109 | fCurrentPrimary = -1; |
ccf7a81f | 110 | fTreeK = 0; |
9e1a0ddb | 111 | } |
112 | ||
113 | ||
114 | //_____________________________________________________________________________ | |
115 | AliStack::~AliStack() | |
116 | { | |
117 | // | |
118 | // Destructor | |
119 | // | |
120 | ||
81694e6a | 121 | delete fParticleBuffer; |
9e1a0ddb | 122 | if (fParticles) { |
123 | fParticles->Delete(); | |
124 | delete fParticles; | |
125 | } | |
126 | delete fParticleMap; | |
cfb2cc9c | 127 | if (fTreeK) delete fTreeK; |
9e1a0ddb | 128 | } |
129 | ||
130 | // | |
131 | // public methods | |
132 | // | |
133 | ||
134 | //_____________________________________________________________________________ | |
135 | void AliStack::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom, | |
136 | Float_t *vpos, Float_t *polar, Float_t tof, | |
137 | AliMCProcess mech, Int_t &ntr, Float_t weight) | |
138 | { | |
139 | // | |
140 | // Load a track on the stack | |
141 | // | |
142 | // done 0 if the track has to be transported | |
143 | // 1 if not | |
144 | // parent identifier of the parent track. -1 for a primary | |
145 | // pdg particle code | |
146 | // pmom momentum GeV/c | |
147 | // vpos position | |
148 | // polar polarisation | |
149 | // tof time of flight in seconds | |
150 | // mecha production mechanism | |
151 | // ntr on output the number of the track stored | |
152 | // | |
153 | ||
154 | Float_t mass; | |
155 | const Int_t kfirstdaughter=-1; | |
156 | const Int_t klastdaughter=-1; | |
157 | const Int_t kS=0; | |
158 | // const Float_t tlife=0; | |
159 | ||
160 | // | |
161 | // Here we get the static mass | |
162 | // For MC is ok, but a more sophisticated method could be necessary | |
163 | // if the calculated mass is required | |
164 | // also, this method is potentially dangerous if the mass | |
165 | // used in the MC is not the same of the PDG database | |
166 | // | |
167 | mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass(); | |
168 | Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+ | |
169 | pmom[1]*pmom[1]+pmom[2]*pmom[2]); | |
170 | ||
ccf7a81f | 171 | // printf("Loading mass %f ene %f No %d ip %d parent %d done %d pos %f %f %f mom %f %f %f kS %d m \n", |
172 | // mass,e,fNtrack,pdg,parent,done,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],kS); | |
173 | ||
9e1a0ddb | 174 | TClonesArray &particles = *fParticles; |
175 | TParticle* particle | |
176 | = new(particles[fLoadPoint++]) | |
177 | TParticle(pdg, kS, parent, -1, kfirstdaughter, klastdaughter, | |
178 | pmom[0], pmom[1], pmom[2], e, vpos[0], vpos[1], vpos[2], tof); | |
179 | particle->SetPolarisation(TVector3(polar[0],polar[1],polar[2])); | |
180 | particle->SetWeight(weight); | |
181 | particle->SetUniqueID(mech); | |
182 | if(!done) particle->SetBit(kDoneBit); | |
183 | ||
184 | ||
185 | // Declare that the daughter information is valid | |
186 | particle->SetBit(kDaughtersBit); | |
187 | // Add the particle to the stack | |
188 | fParticleMap->AddAtAndExpand(particle, fNtrack); | |
189 | ||
190 | if(parent>=0) { | |
191 | particle = (TParticle*) fParticleMap->At(parent); | |
192 | particle->SetLastDaughter(fNtrack); | |
193 | if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack); | |
194 | } | |
195 | else { | |
196 | // | |
197 | // This is a primary track. Set high water mark for this event | |
198 | fHgwmk = fNtrack; | |
199 | // | |
200 | // Set also number if primary tracks | |
201 | fNprimary = fHgwmk+1; | |
202 | fCurrentPrimary++; | |
203 | } | |
204 | ntr = fNtrack++; | |
205 | } | |
206 | ||
207 | //_____________________________________________________________________________ | |
208 | void AliStack::SetTrack(Int_t done, Int_t parent, Int_t pdg, | |
209 | Double_t px, Double_t py, Double_t pz, Double_t e, | |
210 | Double_t vx, Double_t vy, Double_t vz, Double_t tof, | |
211 | Double_t polx, Double_t poly, Double_t polz, | |
212 | AliMCProcess mech, Int_t &ntr, Float_t weight) | |
213 | { | |
214 | // | |
215 | // Load a track on the stack | |
216 | // | |
217 | // done 0 if the track has to be transported | |
218 | // 1 if not | |
219 | // parent identifier of the parent track. -1 for a primary | |
220 | // pdg particle code | |
221 | // kS generation status code | |
222 | // px, py, pz momentum GeV/c | |
223 | // vx, vy, vz position | |
224 | // polar polarisation | |
225 | // tof time of flight in seconds | |
226 | // mech production mechanism | |
227 | // ntr on output the number of the track stored | |
228 | // | |
229 | // New method interface: | |
230 | // arguments were changed to be in correspondence with TParticle | |
231 | // constructor. | |
232 | // Note: the energy is not calculated from the static mass but | |
233 | // it is passed by argument e. | |
234 | ||
235 | ||
236 | const Int_t kS=0; | |
237 | const Int_t kFirstDaughter=-1; | |
238 | const Int_t kLastDaughter=-1; | |
239 | ||
240 | TClonesArray &particles = *fParticles; | |
241 | TParticle* particle | |
242 | = new(particles[fLoadPoint++]) | |
243 | TParticle(pdg, kS, parent, -1, kFirstDaughter, kLastDaughter, | |
244 | px, py, pz, e, vx, vy, vz, tof); | |
245 | ||
246 | particle->SetPolarisation(polx, poly, polz); | |
247 | particle->SetWeight(weight); | |
248 | particle->SetUniqueID(mech); | |
249 | ||
250 | if(!done) particle->SetBit(kDoneBit); | |
251 | ||
252 | // Declare that the daughter information is valid | |
253 | particle->SetBit(kDaughtersBit); | |
254 | // Add the particle to the stack | |
255 | fParticleMap->AddAtAndExpand(particle, fNtrack);//CHECK!! | |
256 | ||
257 | if(parent>=0) { | |
258 | particle = (TParticle*) fParticleMap->At(parent); | |
259 | particle->SetLastDaughter(fNtrack); | |
260 | if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack); | |
261 | } | |
262 | else { | |
263 | // | |
264 | // This is a primary track. Set high water mark for this event | |
265 | fHgwmk = fNtrack; | |
266 | // | |
267 | // Set also number if primary tracks | |
268 | fNprimary = fHgwmk+1; | |
269 | fCurrentPrimary++; | |
270 | } | |
271 | ntr = fNtrack++; | |
272 | } | |
273 | ||
274 | //_____________________________________________________________________________ | |
275 | void AliStack::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom, | |
276 | Float_t &e, Float_t *vpos, Float_t *polar, | |
277 | Float_t &tof) | |
278 | { | |
279 | // | |
280 | // Return next track from stack of particles | |
281 | // | |
282 | ||
283 | ||
284 | TParticle* track = GetNextParticle(); | |
ccf7a81f | 285 | // cout << "GetNextTrack():" << fCurrent << fNprimary << endl; |
9e1a0ddb | 286 | |
287 | if(track) { | |
288 | mtrack=fCurrent; | |
289 | ipart=track->GetPdgCode(); | |
290 | pmom[0]=track->Px(); | |
291 | pmom[1]=track->Py(); | |
292 | pmom[2]=track->Pz(); | |
293 | e =track->Energy(); | |
294 | vpos[0]=track->Vx(); | |
295 | vpos[1]=track->Vy(); | |
296 | vpos[2]=track->Vz(); | |
297 | TVector3 pol; | |
298 | track->GetPolarisation(pol); | |
299 | polar[0]=pol.X(); | |
300 | polar[1]=pol.Y(); | |
301 | polar[2]=pol.Z(); | |
302 | tof=track->T(); | |
303 | track->SetBit(kDoneBit); | |
ccf7a81f | 304 | // cout << "Filled params" << endl; |
9e1a0ddb | 305 | } |
306 | else | |
307 | mtrack=-1; | |
308 | ||
309 | // | |
310 | // stop and start timer when we start a primary track | |
311 | Int_t nprimaries = fNprimary; | |
312 | if (fCurrent >= nprimaries) return; | |
313 | if (fCurrent < nprimaries-1) { | |
314 | fTimer.Stop(); | |
315 | track=(TParticle*) fParticleMap->At(fCurrent+1); | |
316 | // track->SetProcessTime(fTimer.CpuTime()); | |
317 | } | |
318 | fTimer.Start(); | |
319 | } | |
320 | ||
321 | ||
322 | //_____________________________________________________________________________ | |
323 | void AliStack::PurifyKine() | |
324 | { | |
325 | // | |
326 | // Compress kinematic tree keeping only flagged particles | |
327 | // and renaming the particle id's in all the hits | |
328 | // | |
329 | ||
330 | TObjArray &particles = *fParticleMap; | |
331 | int nkeep=fHgwmk+1, parent, i; | |
332 | TParticle *part, *father; | |
333 | TArrayI map(particles.GetLast()+1); | |
334 | ||
335 | // Save in Header total number of tracks before compression | |
336 | ||
337 | // If no tracks generated return now | |
338 | if(fHgwmk+1 == fNtrack) return; | |
339 | ||
9e1a0ddb | 340 | // First pass, invalid Daughter information |
341 | for(i=0; i<fNtrack; i++) { | |
342 | // Preset map, to be removed later | |
343 | if(i<=fHgwmk) map[i]=i ; | |
344 | else { | |
345 | map[i] = -99; | |
76969085 | 346 | if((part=(TParticle*) particles.At(i))) { |
347 | part->ResetBit(kDaughtersBit); | |
348 | part->SetFirstDaughter(-1); | |
349 | part->SetLastDaughter(-1); | |
350 | } | |
9e1a0ddb | 351 | } |
352 | } | |
353 | // Invalid daughter information for the parent of the first particle | |
354 | // generated. This may or may not be the current primary according to | |
355 | // whether decays have been recorded among the primaries | |
356 | part = (TParticle *)particles.At(fHgwmk+1); | |
357 | particles.At(part->GetFirstMother())->ResetBit(kDaughtersBit); | |
358 | // Second pass, build map between old and new numbering | |
359 | for(i=fHgwmk+1; i<fNtrack; i++) { | |
360 | if(particles.At(i)->TestBit(kKeepBit)) { | |
361 | ||
362 | // This particle has to be kept | |
363 | map[i]=nkeep; | |
364 | // If old and new are different, have to move the pointer | |
365 | if(i!=nkeep) particles[nkeep]=particles.At(i); | |
366 | part = (TParticle*) particles.At(nkeep); | |
367 | ||
368 | // as the parent is always *before*, it must be already | |
369 | // in place. This is what we are checking anyway! | |
370 | if((parent=part->GetFirstMother())>fHgwmk) | |
371 | if(map[parent]==-99) Fatal("PurifyKine","map[%d] = -99!\n",parent); | |
372 | else part->SetFirstMother(map[parent]); | |
373 | ||
374 | nkeep++; | |
375 | } | |
376 | } | |
377 | ||
378 | // Fix daughters information | |
379 | for (i=fHgwmk+1; i<nkeep; i++) { | |
380 | part = (TParticle *)particles.At(i); | |
381 | parent = part->GetFirstMother(); | |
382 | if(parent>=0) { | |
383 | father = (TParticle *)particles.At(parent); | |
384 | if(father->TestBit(kDaughtersBit)) { | |
385 | ||
386 | if(i<father->GetFirstDaughter()) father->SetFirstDaughter(i); | |
387 | if(i>father->GetLastDaughter()) father->SetLastDaughter(i); | |
388 | } else { | |
389 | // Initialise daughters info for first pass | |
390 | father->SetFirstDaughter(i); | |
391 | father->SetLastDaughter(i); | |
392 | father->SetBit(kDaughtersBit); | |
393 | } | |
394 | } | |
395 | } | |
396 | ||
397 | // Now loop on all registered hit lists | |
398 | TList* hitLists = gAlice->GetHitLists(); | |
399 | TIter next(hitLists); | |
400 | TCollection *hitList; | |
401 | while((hitList = (TCollection*)next())) { | |
402 | TIter nexthit(hitList); | |
403 | AliHit *hit; | |
404 | while((hit = (AliHit*)nexthit())) { | |
405 | hit->SetTrack(map[hit->GetTrack()]); | |
406 | } | |
407 | } | |
408 | ||
409 | // | |
410 | // This for detectors which have a special mapping mechanism | |
411 | // for hits, such as TPC and TRD | |
412 | // | |
413 | ||
414 | TObjArray* modules = gAlice->Modules(); | |
415 | TIter nextmod(modules); | |
416 | AliModule *detector; | |
417 | while((detector = (AliModule*)nextmod())) { | |
418 | detector->RemapTrackHitIDs(map.GetArray()); | |
419 | } | |
420 | ||
421 | // Now the output bit, from fHgwmk to nkeep we write everything and we erase | |
422 | if(nkeep>fParticleFileMap.GetSize()) fParticleFileMap.Set(Int_t (nkeep*1.5)); | |
423 | ||
424 | for (i=fHgwmk+1; i<nkeep; ++i) { | |
425 | fParticleBuffer = (TParticle*) particles.At(i); | |
426 | fParticleFileMap[i]=(Int_t) fTreeK->GetEntries(); | |
427 | fTreeK->Fill(); | |
17f4a3d9 | 428 | particles[i]=fParticleBuffer=0; |
9e1a0ddb | 429 | } |
430 | ||
431 | for (i=nkeep; i<fNtrack; ++i) particles[i]=0; | |
432 | ||
76969085 | 433 | Int_t toshrink = fNtrack-fHgwmk-1; |
9e1a0ddb | 434 | fLoadPoint-=toshrink; |
435 | for(i=fLoadPoint; i<fLoadPoint+toshrink; ++i) fParticles->RemoveAt(i); | |
436 | ||
437 | fNtrack=nkeep; | |
438 | fHgwmk=nkeep-1; | |
439 | // delete [] map; | |
440 | } | |
441 | ||
442 | //_____________________________________________________________________________ | |
443 | void AliStack::FinishEvent() | |
444 | { | |
445 | // | |
446 | // Write out the kinematics that was not yet filled | |
447 | // | |
448 | ||
449 | // Update event header | |
450 | ||
451 | ||
452 | if (!fTreeK) { | |
453 | // Fatal("FinishEvent", "No kinematics tree is defined."); | |
454 | // Don't panic this is a probably a lego run | |
455 | return; | |
456 | ||
457 | } | |
458 | ||
459 | CleanParents(); | |
460 | if(fTreeK->GetEntries() ==0) { | |
461 | // set the fParticleFileMap size for the first time | |
462 | fParticleFileMap.Set(fHgwmk+1); | |
463 | } | |
464 | ||
465 | Bool_t allFilled = kFALSE; | |
466 | TObject *part; | |
467 | for(Int_t i=0; i<fHgwmk+1; ++i) | |
468 | if((part=fParticleMap->At(i))) { | |
469 | fParticleBuffer = (TParticle*) part; | |
470 | fParticleFileMap[i]= (Int_t) fTreeK->GetEntries(); | |
471 | fTreeK->Fill(); | |
da2af24c | 472 | //PH (*fParticleMap)[i]=fParticleBuffer=0; |
473 | fParticleBuffer=0; | |
474 | fParticleMap->AddAt(0,i); | |
9e1a0ddb | 475 | |
476 | // When all primaries were filled no particle!=0 | |
477 | // should be left => to be removed later. | |
478 | if (allFilled) printf("Why != 0 part # %d?\n",i); | |
479 | } | |
480 | else { | |
481 | // // printf("Why = 0 part # %d?\n",i); => We know. | |
482 | // break; | |
483 | // we don't break now in order to be sure there is no | |
484 | // particle !=0 left. | |
485 | // To be removed later and replaced with break. | |
486 | if(!allFilled) allFilled = kTRUE; | |
487 | } | |
ccf7a81f | 488 | // cout << "Nof particles: " << fNtrack << endl; |
9e1a0ddb | 489 | //Reset(); |
490 | } | |
491 | ||
492 | //_____________________________________________________________________________ | |
493 | void AliStack::FlagTrack(Int_t track) | |
494 | { | |
495 | // | |
496 | // Flags a track and all its family tree to be kept | |
497 | // | |
498 | ||
499 | TParticle *particle; | |
500 | ||
501 | Int_t curr=track; | |
502 | while(1) { | |
503 | particle=(TParticle*)fParticleMap->At(curr); | |
504 | ||
505 | // If the particle is flagged the three from here upward is saved already | |
506 | if(particle->TestBit(kKeepBit)) return; | |
507 | ||
508 | // Save this particle | |
509 | particle->SetBit(kKeepBit); | |
510 | ||
511 | // Move to father if any | |
512 | if((curr=particle->GetFirstMother())==-1) return; | |
513 | } | |
514 | } | |
515 | ||
516 | //_____________________________________________________________________________ | |
ed54bf31 | 517 | void AliStack::KeepTrack(Int_t track) |
9e1a0ddb | 518 | { |
519 | // | |
520 | // Flags a track to be kept | |
521 | // | |
522 | ||
523 | fParticleMap->At(track)->SetBit(kKeepBit); | |
524 | } | |
525 | ||
526 | //_____________________________________________________________________________ | |
527 | void AliStack::Reset(Int_t size) | |
528 | { | |
529 | // | |
530 | // Resets stack | |
531 | // | |
532 | ||
533 | fNtrack=0; | |
534 | fNprimary=0; | |
535 | fHgwmk=0; | |
536 | fLoadPoint=0; | |
537 | fCurrent = -1; | |
538 | ResetArrays(size); | |
539 | } | |
540 | ||
541 | //_____________________________________________________________________________ | |
542 | void AliStack::ResetArrays(Int_t size) | |
543 | { | |
544 | // | |
545 | // Resets stack arrays | |
546 | // | |
547 | ||
548 | fParticles->Clear(); | |
549 | fParticleMap->Clear(); | |
550 | if (size>0) fParticleMap->Expand(size); | |
551 | } | |
552 | ||
553 | //_____________________________________________________________________________ | |
ed54bf31 | 554 | void AliStack::SetHighWaterMark(Int_t nt) |
9e1a0ddb | 555 | { |
556 | // | |
557 | // Set high water mark for last track in event | |
558 | // | |
559 | ||
560 | fHgwmk = fNtrack-1; | |
561 | fCurrentPrimary=fHgwmk; | |
562 | ||
563 | // Set also number of primary tracks | |
564 | fNprimary = fHgwmk+1; | |
565 | fNtrack = fHgwmk+1; | |
566 | } | |
567 | ||
568 | //_____________________________________________________________________________ | |
569 | TParticle* AliStack::Particle(Int_t i) | |
570 | { | |
571 | // | |
572 | // Return particle with specified ID | |
573 | ||
da2af24c | 574 | //PH if(!(*fParticleMap)[i]) { |
575 | if(!fParticleMap->At(i)) { | |
911a3148 | 576 | Int_t nentries = fParticles->GetEntriesFast(); |
9e1a0ddb | 577 | // algorithmic way of getting entry index |
578 | // (primary particles are filled after secondaries) | |
579 | Int_t entry; | |
580 | if (i<fNprimary) | |
581 | entry = i+fNtrack-fNprimary; | |
582 | else | |
583 | entry = i-fNprimary; | |
584 | // check whether algorithmic way and | |
585 | // and the fParticleFileMap[i] give the same; | |
586 | // give the fatal error if not | |
587 | if (entry != fParticleFileMap[i]) { | |
588 | Fatal("Particle", | |
589 | "!! The algorithmic way and map are different: !!\n entry: %d map: %d", | |
590 | entry, fParticleFileMap[i]); | |
591 | } | |
592 | ||
593 | fTreeK->GetEntry(entry); | |
594 | new ((*fParticles)[nentries]) TParticle(*fParticleBuffer); | |
595 | fParticleMap->AddAt((*fParticles)[nentries],i); | |
596 | } | |
da2af24c | 597 | //PH return (TParticle *) (*fParticleMap)[i]; |
598 | return (TParticle *) fParticleMap->At(i); | |
9e1a0ddb | 599 | } |
600 | ||
601 | //_____________________________________________________________________________ | |
602 | Int_t AliStack::GetPrimary(Int_t id) const | |
603 | { | |
604 | // | |
605 | // Return number of primary that has generated track | |
606 | // | |
607 | ||
608 | int current, parent; | |
609 | TParticle *part; | |
610 | // | |
611 | parent=id; | |
612 | while (1) { | |
613 | current=parent; | |
614 | part = (TParticle *)fParticleMap->At(current); | |
615 | parent=part->GetFirstMother(); | |
616 | if(parent<0) return current; | |
617 | } | |
618 | } | |
619 | ||
620 | //_____________________________________________________________________________ | |
621 | void AliStack::DumpPart (Int_t i) const | |
622 | { | |
623 | // | |
624 | // Dumps particle i in the stack | |
625 | // | |
626 | ||
da2af24c | 627 | //PH ((TParticle*) (*fParticleMap)[i])->Print(); |
628 | ((TParticle*) fParticleMap->At(i))->Print(); | |
9e1a0ddb | 629 | } |
630 | ||
631 | //_____________________________________________________________________________ | |
632 | void AliStack::DumpPStack () | |
633 | { | |
634 | // | |
635 | // Dumps the particle stack | |
636 | // | |
637 | ||
3ab6f951 | 638 | Int_t i; |
639 | ||
9e1a0ddb | 640 | printf( |
641 | "\n\n=======================================================================\n"); | |
3ab6f951 | 642 | for (i=0;i<fNtrack;i++) |
9e1a0ddb | 643 | { |
644 | TParticle* particle = Particle(i); | |
645 | if (particle) { | |
646 | printf("-> %d ",i); particle->Print(); | |
647 | printf("--------------------------------------------------------------\n"); | |
648 | } | |
649 | else | |
650 | Warning("DumpPStack", "No particle with id %d.", i); | |
651 | } | |
652 | ||
653 | printf( | |
654 | "\n=======================================================================\n\n"); | |
655 | ||
656 | // print particle file map | |
657 | printf("\nParticle file map: \n"); | |
3ab6f951 | 658 | for (i=0; i<fNtrack; i++) |
9e1a0ddb | 659 | printf(" %d th entry: %d \n",i,fParticleFileMap[i]); |
660 | } | |
661 | ||
662 | ||
663 | //_____________________________________________________________________________ | |
664 | void AliStack::DumpLoadedStack() const | |
665 | { | |
666 | // | |
667 | // Dumps the particle in the stack | |
668 | // that are loaded in memory. | |
669 | // | |
670 | ||
671 | TObjArray &particles = *fParticleMap; | |
672 | printf( | |
673 | "\n\n=======================================================================\n"); | |
674 | for (Int_t i=0;i<fNtrack;i++) | |
675 | { | |
676 | TParticle* particle = (TParticle*) particles[i]; | |
677 | if (particle) { | |
678 | printf("-> %d ",i); particle->Print(); | |
679 | printf("--------------------------------------------------------------\n"); | |
680 | } | |
681 | else { | |
682 | printf("-> %d Particle not loaded.\n",i); | |
683 | printf("--------------------------------------------------------------\n"); | |
684 | } | |
685 | } | |
686 | printf( | |
687 | "\n=======================================================================\n\n"); | |
688 | } | |
689 | ||
690 | // | |
691 | // protected methods | |
692 | // | |
693 | ||
694 | //_____________________________________________________________________________ | |
695 | void AliStack::CleanParents() | |
696 | { | |
697 | // | |
698 | // Clean particles stack | |
699 | // Set parent/daughter relations | |
700 | // | |
701 | ||
702 | TObjArray &particles = *fParticleMap; | |
703 | TParticle *part; | |
704 | int i; | |
705 | for(i=0; i<fHgwmk+1; i++) { | |
706 | part = (TParticle *)particles.At(i); | |
707 | if(part) if(!part->TestBit(kDaughtersBit)) { | |
708 | part->SetFirstDaughter(-1); | |
709 | part->SetLastDaughter(-1); | |
710 | } | |
711 | } | |
712 | } | |
713 | ||
714 | //_____________________________________________________________________________ | |
715 | TParticle* AliStack::GetNextParticle() | |
716 | { | |
717 | // | |
718 | // Return next particle from stack of particles | |
719 | // | |
720 | ||
721 | TParticle* particle = 0; | |
722 | ||
723 | // search secondaries | |
724 | //for(Int_t i=fNtrack-1; i>=0; i--) { | |
725 | for(Int_t i=fNtrack-1; i>fHgwmk; i--) { | |
726 | particle = (TParticle*) fParticleMap->At(i); | |
727 | if ((particle) && (!particle->TestBit(kDoneBit))) { | |
728 | fCurrent=i; | |
729 | //cout << "GetNextParticle() - secondary " | |
730 | // << fNtrack << " " << fHgwmk << " " << fCurrent << endl; | |
731 | return particle; | |
732 | } | |
733 | } | |
734 | ||
735 | // take next primary if all secondaries were done | |
736 | while (fCurrentPrimary>=0) { | |
737 | fCurrent = fCurrentPrimary; | |
738 | particle = (TParticle*) fParticleMap->At(fCurrentPrimary--); | |
739 | if ((particle) && (!particle->TestBit(kDoneBit))) { | |
740 | //cout << "GetNextParticle() - primary " | |
741 | // << fNtrack << " " << fHgwmk << " " << fCurrent << endl; | |
742 | return particle; | |
743 | } | |
744 | } | |
745 | ||
746 | // nothing to be tracked | |
747 | fCurrent = -1; | |
748 | //cout << "GetNextParticle() - none " | |
749 | // << fNtrack << " " << fHgwmk << " " << fCurrent << endl; | |
750 | return particle; | |
751 | } | |
752 | ||
753 | //__________________________________________________________________________________________ | |
754 | void AliStack::MakeTree(Int_t event, const char *file) | |
755 | { | |
756 | // | |
757 | // Make Kine tree and creates branch for writing particles | |
758 | // | |
759 | TBranch *branch=0; | |
760 | // Make Kinematics Tree | |
761 | char hname[30]; | |
ccf7a81f | 762 | // printf("\n MakeTree called %d", event); |
9e1a0ddb | 763 | if (!fTreeK) { |
764 | sprintf(hname,"TreeK%d",event); | |
765 | fTreeK = new TTree(hname,"Kinematics"); | |
766 | // Create a branch for particles | |
d0f40f23 | 767 | branch = fTreeK->Branch("Particles", "TParticle", &fParticleBuffer, 4000); |
9e1a0ddb | 768 | fTreeK->Write(0,TObject::kOverwrite); |
769 | } | |
770 | } | |
771 | ||
81694e6a | 772 | //_____________________________________________________________________________ |
9e1a0ddb | 773 | void AliStack::BeginEvent(Int_t event) |
774 | { | |
775 | // start a new event | |
776 | // | |
777 | // | |
778 | fNprimary = 0; | |
779 | fNtrack = 0; | |
780 | ||
781 | char hname[30]; | |
782 | if(fTreeK) { | |
783 | fTreeK->Reset(); | |
784 | sprintf(hname,"TreeK%d",event); | |
785 | fTreeK->SetName(hname); | |
786 | } | |
787 | } | |
788 | ||
81694e6a | 789 | //_____________________________________________________________________________ |
9e1a0ddb | 790 | void AliStack::FinishRun() |
791 | { | |
792 | // Clean TreeK information | |
793 | if (fTreeK) { | |
794 | delete fTreeK; fTreeK = 0; | |
795 | } | |
796 | } | |
797 | ||
81694e6a | 798 | //_____________________________________________________________________________ |
cec14bc5 | 799 | Bool_t AliStack::GetEvent(Int_t event) |
9e1a0ddb | 800 | { |
801 | // | |
802 | // Get new event from TreeK | |
ccf7a81f | 803 | |
9e1a0ddb | 804 | // Reset/Create the particle stack |
805 | if (fTreeK) delete fTreeK; | |
806 | ||
807 | // Get Kine Tree from file | |
808 | char treeName[20]; | |
809 | sprintf(treeName,"TreeK%d",event); | |
810 | fTreeK = (TTree*)gDirectory->Get(treeName); | |
811 | ||
ccf7a81f | 812 | if (fTreeK) |
813 | fTreeK->SetBranchAddress("Particles", &fParticleBuffer); | |
814 | else { | |
9e1a0ddb | 815 | Error("GetEvent","cannot find Kine Tree for event:%d\n",event); |
ccf7a81f | 816 | return kFALSE; |
817 | } | |
818 | // printf("\n primaries %d", fNprimary); | |
819 | // printf("\n tracks %d", fNtrack); | |
820 | ||
9e1a0ddb | 821 | Int_t size = (Int_t)fTreeK->GetEntries(); |
822 | ResetArrays(size); | |
ccf7a81f | 823 | return kTRUE; |
9e1a0ddb | 824 | } |
ccf7a81f | 825 | |
826 | //---------------------------------------------------------------------- |