]>
Commit | Line | Data |
---|---|---|
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$ | |
18 | Revision 1.43 2000/10/09 09:43:17 fca | |
19 | Special remapping of hits for TPC and TRD. End-of-primary action introduced | |
20 | ||
21 | Revision 1.42 2000/10/02 21:28:14 fca | |
22 | Removal of useless dependecies via forward declarations | |
23 | ||
24 | Revision 1.41 2000/07/13 16:19:09 fca | |
25 | Mainly coding conventions + some small bug fixes | |
26 | ||
27 | Revision 1.40 2000/07/12 08:56:25 fca | |
28 | Coding convention correction and warning removal | |
29 | ||
30 | Revision 1.39 2000/07/11 18:24:59 fca | |
31 | Coding convention corrections + few minor bug fixes | |
32 | ||
33 | Revision 1.38 2000/06/20 13:05:45 fca | |
34 | Writing down the TREE headers before job starts | |
35 | ||
36 | Revision 1.37 2000/06/09 20:05:11 morsch | |
37 | Introduce possibility to chose magnetic field version 3: AliMagFDM + field02.dat | |
38 | ||
39 | Revision 1.36 2000/06/08 14:03:58 hristov | |
40 | Only one initializer for a default argument | |
41 | ||
42 | Revision 1.35 2000/06/07 10:13:14 hristov | |
43 | Delete only existent objects. | |
44 | ||
45 | Revision 1.34 2000/05/18 10:45:38 fca | |
46 | Delete Particle Factory properly | |
47 | ||
48 | Revision 1.33 2000/05/16 13:10:40 fca | |
49 | New method IsNewTrack and fix for a problem in Father-Daughter relations | |
50 | ||
51 | Revision 1.32 2000/04/27 10:38:21 fca | |
52 | Correct termination of Lego Run and introduce Lego getter in AliRun | |
53 | ||
54 | Revision 1.31 2000/04/26 10:17:32 fca | |
55 | Changes in Lego for G4 compatibility | |
56 | ||
57 | Revision 1.30 2000/04/18 19:11:40 fca | |
58 | Introduce variable Config.C function signature | |
59 | ||
60 | Revision 1.29 2000/04/07 11:12:34 fca | |
61 | G4 compatibility changes | |
62 | ||
63 | Revision 1.28 2000/04/05 06:51:06 fca | |
64 | Workaround for an HP compiler problem | |
65 | ||
66 | Revision 1.27 2000/03/22 18:08:07 fca | |
67 | Rationalisation of the virtual MC interfaces | |
68 | ||
69 | Revision 1.26 2000/03/22 13:42:26 fca | |
70 | SetGenerator does not replace an existing generator, ResetGenerator does | |
71 | ||
72 | Revision 1.25 2000/02/23 16:25:22 fca | |
73 | AliVMC and AliGeant3 classes introduced | |
74 | ReadEuclid moved from AliRun to AliModule | |
75 | ||
76 | Revision 1.24 2000/01/19 17:17:20 fca | |
77 | Introducing a list of lists of hits -- more hits allowed for detector now | |
78 | ||
79 | Revision 1.23 1999/12/03 11:14:31 fca | |
80 | Fixing previous wrong checking | |
81 | ||
82 | Revision 1.21 1999/11/25 10:40:08 fca | |
83 | Fixing daughters information also in primary tracks | |
84 | ||
85 | Revision 1.20 1999/10/04 18:08:49 fca | |
86 | Adding protection against inconsistent Euclid files | |
87 | ||
88 | Revision 1.19 1999/09/29 07:50:40 fca | |
89 | Introduction of the Copyright and cvs Log | |
90 | ||
91 | */ | |
92 | ||
93 | /////////////////////////////////////////////////////////////////////////////// | |
94 | // // | |
95 | // Control class for Alice C++ // | |
96 | // Only one single instance of this class exists. // | |
97 | // The object is created in main program aliroot // | |
98 | // and is pointed by the global gAlice. // | |
99 | // // | |
100 | // -Supports the list of all Alice Detectors (fModules). // | |
101 | // -Supports the list of particles (fParticles). // | |
102 | // -Supports the Trees. // | |
103 | // -Supports the geometry. // | |
104 | // -Supports the event display. // | |
105 | //Begin_Html | |
106 | /* | |
107 | <img src="picts/AliRunClass.gif"> | |
108 | */ | |
109 | //End_Html | |
110 | //Begin_Html | |
111 | /* | |
112 | <img src="picts/alirun.gif"> | |
113 | */ | |
114 | //End_Html | |
115 | // // | |
116 | /////////////////////////////////////////////////////////////////////////////// | |
117 | ||
118 | #include <stdlib.h> | |
119 | #include <stdio.h> | |
120 | #include <string.h> | |
121 | ||
122 | #include <TFile.h> | |
123 | #include <TRandom.h> | |
124 | #include <TBRIK.h> | |
125 | #include <TNode.h> | |
126 | #include <TCint.h> | |
127 | #include <TSystem.h> | |
128 | #include <TObjectTable.h> | |
129 | #include <TTree.h> | |
130 | #include <TGeometry.h> | |
131 | #include <TROOT.h> | |
132 | #include "TBrowser.h" | |
133 | ||
134 | #include "TParticle.h" | |
135 | #include "AliRun.h" | |
136 | #include "AliDisplay.h" | |
137 | #include "AliMC.h" | |
138 | #include "AliLego.h" | |
139 | #include "AliMagFC.h" | |
140 | #include "AliMagFCM.h" | |
141 | #include "AliMagFDM.h" | |
142 | #include "AliHit.h" | |
143 | ||
144 | #include "AliDetector.h" | |
145 | ||
146 | AliRun *gAlice; | |
147 | ||
148 | static AliHeader *gAliHeader; | |
149 | ||
150 | ClassImp(AliRun) | |
151 | ||
152 | //_____________________________________________________________________________ | |
153 | AliRun::AliRun() | |
154 | { | |
155 | // | |
156 | // Default constructor for AliRun | |
157 | // | |
158 | gAliHeader=&fHeader; | |
159 | fRun = 0; | |
160 | fEvent = 0; | |
161 | fCurrent = -1; | |
162 | fModules = 0; | |
163 | fGenerator = 0; | |
164 | fTreeD = 0; | |
165 | fTreeK = 0; | |
166 | fTreeH = 0; | |
167 | fTreeE = 0; | |
168 | fTreeR = 0; | |
169 | fParticles = 0; | |
170 | fGeometry = 0; | |
171 | fDisplay = 0; | |
172 | fField = 0; | |
173 | fMC = 0; | |
174 | fNdets = 0; | |
175 | fImedia = 0; | |
176 | fTrRmax = 1.e10; | |
177 | fTrZmax = 1.e10; | |
178 | fInitDone = kFALSE; | |
179 | fLego = 0; | |
180 | fPDGDB = 0; //Particle factory object! | |
181 | fHitLists = 0; | |
182 | fConfigFunction = "\0"; | |
183 | } | |
184 | ||
185 | //_____________________________________________________________________________ | |
186 | AliRun::AliRun(const char *name, const char *title) | |
187 | : TNamed(name,title) | |
188 | { | |
189 | // | |
190 | // Constructor for the main processor. | |
191 | // Creates the geometry | |
192 | // Creates the list of Detectors. | |
193 | // Creates the list of particles. | |
194 | // | |
195 | Int_t i; | |
196 | ||
197 | gAlice = this; | |
198 | fTreeD = 0; | |
199 | fTreeK = 0; | |
200 | fTreeH = 0; | |
201 | fTreeE = 0; | |
202 | fTreeR = 0; | |
203 | fTrRmax = 1.e10; | |
204 | fTrZmax = 1.e10; | |
205 | fGenerator = 0; | |
206 | fInitDone = kFALSE; | |
207 | fLego = 0; | |
208 | fField = 0; | |
209 | fConfigFunction = "Config();"; | |
210 | ||
211 | gROOT->GetListOfBrowsables()->Add(this,name); | |
212 | // | |
213 | // create the support list for the various Detectors | |
214 | fModules = new TObjArray(77); | |
215 | // | |
216 | // Create the TNode geometry for the event display | |
217 | ||
218 | BuildSimpleGeometry(); | |
219 | ||
220 | ||
221 | fNtrack=0; | |
222 | fHgwmk=0; | |
223 | fCurrent=-1; | |
224 | gAliHeader=&fHeader; | |
225 | fRun = 0; | |
226 | fEvent = 0; | |
227 | // | |
228 | // Create the particle stack | |
229 | fParticles = new TClonesArray("TParticle",100); | |
230 | ||
231 | fDisplay = 0; | |
232 | // | |
233 | // Create default mag field | |
234 | SetField(); | |
235 | // | |
236 | fMC = gMC; | |
237 | // | |
238 | // Prepare the tracking medium lists | |
239 | fImedia = new TArrayI(1000); | |
240 | for(i=0;i<1000;i++) (*fImedia)[i]=-99; | |
241 | // | |
242 | // Make particles | |
243 | fPDGDB = TDatabasePDG::Instance(); //Particle factory object! | |
244 | // | |
245 | // Create HitLists list | |
246 | fHitLists = new TList(); | |
247 | } | |
248 | ||
249 | ||
250 | //_____________________________________________________________________________ | |
251 | AliRun::~AliRun() | |
252 | { | |
253 | // | |
254 | // Defaullt AliRun destructor | |
255 | // | |
256 | delete fImedia; | |
257 | delete fField; | |
258 | delete fMC; | |
259 | delete fGeometry; | |
260 | delete fDisplay; | |
261 | delete fGenerator; | |
262 | delete fLego; | |
263 | delete fTreeD; | |
264 | delete fTreeK; | |
265 | delete fTreeH; | |
266 | delete fTreeE; | |
267 | delete fTreeR; | |
268 | if (fModules) { | |
269 | fModules->Delete(); | |
270 | delete fModules; | |
271 | } | |
272 | if (fParticles) { | |
273 | fParticles->Delete(); | |
274 | delete fParticles; | |
275 | } | |
276 | delete fHitLists; | |
277 | delete fPDGDB; | |
278 | } | |
279 | ||
280 | //_____________________________________________________________________________ | |
281 | void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const | |
282 | { | |
283 | // | |
284 | // Add a hit to detector id | |
285 | // | |
286 | TObjArray &dets = *fModules; | |
287 | if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits); | |
288 | } | |
289 | ||
290 | //_____________________________________________________________________________ | |
291 | void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const | |
292 | { | |
293 | // | |
294 | // Add digit to detector id | |
295 | // | |
296 | TObjArray &dets = *fModules; | |
297 | if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits); | |
298 | } | |
299 | ||
300 | //_____________________________________________________________________________ | |
301 | void AliRun::Browse(TBrowser *b) | |
302 | { | |
303 | // | |
304 | // Called when the item "Run" is clicked on the left pane | |
305 | // of the Root browser. | |
306 | // It displays the Root Trees and all detectors. | |
307 | // | |
308 | if (fTreeK) b->Add(fTreeK,fTreeK->GetName()); | |
309 | if (fTreeH) b->Add(fTreeH,fTreeH->GetName()); | |
310 | if (fTreeD) b->Add(fTreeD,fTreeD->GetName()); | |
311 | if (fTreeE) b->Add(fTreeE,fTreeE->GetName()); | |
312 | if (fTreeR) b->Add(fTreeR,fTreeR->GetName()); | |
313 | ||
314 | TIter next(fModules); | |
315 | AliModule *detector; | |
316 | while((detector = (AliModule*)next())) { | |
317 | b->Add(detector,detector->GetName()); | |
318 | } | |
319 | } | |
320 | ||
321 | //_____________________________________________________________________________ | |
322 | void AliRun::Build() | |
323 | { | |
324 | // | |
325 | // Initialize Alice geometry | |
326 | // Dummy routine | |
327 | // | |
328 | } | |
329 | ||
330 | //_____________________________________________________________________________ | |
331 | void AliRun::BuildSimpleGeometry() | |
332 | { | |
333 | // | |
334 | // Create a simple TNode geometry used by Root display engine | |
335 | // | |
336 | // Initialise geometry | |
337 | // | |
338 | fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits"); | |
339 | new TMaterial("void","Vacuum",0,0,0); //Everything is void | |
340 | TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000); | |
341 | brik->SetVisibility(0); | |
342 | new TNode("alice","alice","S_alice"); | |
343 | } | |
344 | ||
345 | //_____________________________________________________________________________ | |
346 | void AliRun::CleanDetectors() | |
347 | { | |
348 | // | |
349 | // Clean Detectors at the end of event | |
350 | // | |
351 | TIter next(fModules); | |
352 | AliModule *detector; | |
353 | while((detector = (AliModule*)next())) { | |
354 | detector->FinishEvent(); | |
355 | } | |
356 | } | |
357 | ||
358 | //_____________________________________________________________________________ | |
359 | void AliRun::CleanParents() | |
360 | { | |
361 | // | |
362 | // Clean Particles stack. | |
363 | // Set parent/daughter relations | |
364 | // | |
365 | TClonesArray &particles = *(gAlice->Particles()); | |
366 | TParticle *part; | |
367 | int i; | |
368 | for(i=0; i<fNtrack; i++) { | |
369 | part = (TParticle *)particles.UncheckedAt(i); | |
370 | if(!part->TestBit(kDaughtersBit)) { | |
371 | part->SetFirstDaughter(-1); | |
372 | part->SetLastDaughter(-1); | |
373 | } | |
374 | } | |
375 | } | |
376 | ||
377 | //_____________________________________________________________________________ | |
378 | Int_t AliRun::DistancetoPrimitive(Int_t, Int_t) | |
379 | { | |
380 | // | |
381 | // Return the distance from the mouse to the AliRun object | |
382 | // Dummy routine | |
383 | // | |
384 | return 9999; | |
385 | } | |
386 | ||
387 | //_____________________________________________________________________________ | |
388 | void AliRun::DumpPart (Int_t i) const | |
389 | { | |
390 | // | |
391 | // Dumps particle i in the stack | |
392 | // | |
393 | TClonesArray &particles = *fParticles; | |
394 | ((TParticle*) particles[i])->Print(); | |
395 | } | |
396 | ||
397 | //_____________________________________________________________________________ | |
398 | void AliRun::DumpPStack () const | |
399 | { | |
400 | // | |
401 | // Dumps the particle stack | |
402 | // | |
403 | TClonesArray &particles = *fParticles; | |
404 | printf( | |
405 | "\n\n=======================================================================\n"); | |
406 | for (Int_t i=0;i<fNtrack;i++) | |
407 | { | |
408 | printf("-> %d ",i); ((TParticle*) particles[i])->Print(); | |
409 | printf("--------------------------------------------------------------\n"); | |
410 | } | |
411 | printf( | |
412 | "\n=======================================================================\n\n"); | |
413 | } | |
414 | ||
415 | //_____________________________________________________________________________ | |
416 | void AliRun::SetField(Int_t type, Int_t version, Float_t scale, | |
417 | Float_t maxField, char* filename) | |
418 | { | |
419 | // | |
420 | // Set magnetic field parameters | |
421 | // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta | |
422 | // version Magnetic field map version (only 1 active now) | |
423 | // scale Scale factor for the magnetic field | |
424 | // maxField Maximum value for the magnetic field | |
425 | ||
426 | // | |
427 | // --- Sanity check on mag field flags | |
428 | if(type<0 || type > 2) { | |
429 | Warning("SetField", | |
430 | "Invalid magnetic field flag: %5d; Helix tracking chosen instead\n" | |
431 | ,type); | |
432 | type=2; | |
433 | } | |
434 | if(fField) delete fField; | |
435 | if(version==1) { | |
436 | fField = new AliMagFC("Map1"," ",type,version,scale,maxField); | |
437 | } else if(version<=2) { | |
438 | fField = new AliMagFCM("Map2-3",filename,type,version,scale,maxField); | |
439 | fField->ReadField(); | |
440 | } else if(version==3) { | |
441 | fField = new AliMagFDM("Map4",filename,type,version,scale,maxField); | |
442 | fField->ReadField(); | |
443 | } else { | |
444 | Warning("SetField","Invalid map %d\n",version); | |
445 | } | |
446 | } | |
447 | ||
448 | //_____________________________________________________________________________ | |
449 | void AliRun::FillTree() | |
450 | { | |
451 | // | |
452 | // Fills all AliRun TTrees | |
453 | // | |
454 | if (fTreeK) fTreeK->Fill(); | |
455 | if (fTreeH) fTreeH->Fill(); | |
456 | if (fTreeD) fTreeD->Fill(); | |
457 | if (fTreeR) fTreeR->Fill(); | |
458 | } | |
459 | ||
460 | //_____________________________________________________________________________ | |
461 | void AliRun::FinishPrimary() | |
462 | { | |
463 | // | |
464 | // Called at the end of each primary track | |
465 | // | |
466 | ||
467 | // static Int_t count=0; | |
468 | // const Int_t times=10; | |
469 | // This primary is finished, purify stack | |
470 | PurifyKine(); | |
471 | ||
472 | TIter next(fModules); | |
473 | AliModule *detector; | |
474 | while((detector = (AliModule*)next())) { | |
475 | detector->FinishPrimary(); | |
476 | } | |
477 | ||
478 | // Write out hits if any | |
479 | if (gAlice->TreeH()) { | |
480 | gAlice->TreeH()->Fill(); | |
481 | } | |
482 | ||
483 | // Reset Hits info | |
484 | gAlice->ResetHits(); | |
485 | ||
486 | // | |
487 | // if(++count%times==1) gObjectTable->Print(); | |
488 | } | |
489 | ||
490 | //_____________________________________________________________________________ | |
491 | void AliRun::FinishEvent() | |
492 | { | |
493 | // | |
494 | // Called at the end of the event. | |
495 | // | |
496 | ||
497 | // | |
498 | if(fLego) fLego->FinishEvent(); | |
499 | ||
500 | //Update the energy deposit tables | |
501 | Int_t i; | |
502 | for(i=0;i<fEventEnergy.GetSize();i++) { | |
503 | fSummEnergy[i]+=fEventEnergy[i]; | |
504 | fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i]; | |
505 | } | |
506 | fEventEnergy.Reset(); | |
507 | ||
508 | // Clean detector information | |
509 | CleanDetectors(); | |
510 | ||
511 | // Write out the kinematics | |
512 | if (fTreeK) { | |
513 | CleanParents(); | |
514 | fTreeK->Fill(); | |
515 | } | |
516 | ||
517 | // Write out the digits | |
518 | if (fTreeD) { | |
519 | fTreeD->Fill(); | |
520 | ResetDigits(); | |
521 | } | |
522 | ||
523 | // Write out reconstructed clusters | |
524 | if (fTreeR) { | |
525 | fTreeR->Fill(); | |
526 | } | |
527 | ||
528 | // Write out the event Header information | |
529 | if (fTreeE) fTreeE->Fill(); | |
530 | ||
531 | // Reset stack info | |
532 | ResetStack(); | |
533 | ||
534 | // Write Tree headers | |
535 | // Int_t ievent = fHeader.GetEvent(); | |
536 | // char hname[30]; | |
537 | // sprintf(hname,"TreeK%d",ievent); | |
538 | if (fTreeK) fTreeK->Write(0,TObject::kOverwrite); | |
539 | // sprintf(hname,"TreeH%d",ievent); | |
540 | if (fTreeH) fTreeH->Write(0,TObject::kOverwrite); | |
541 | // sprintf(hname,"TreeD%d",ievent); | |
542 | if (fTreeD) fTreeD->Write(0,TObject::kOverwrite); | |
543 | // sprintf(hname,"TreeR%d",ievent); | |
544 | if (fTreeR) fTreeR->Write(0,TObject::kOverwrite); | |
545 | ||
546 | ++fEvent; | |
547 | } | |
548 | ||
549 | //_____________________________________________________________________________ | |
550 | void AliRun::FinishRun() | |
551 | { | |
552 | // | |
553 | // Called at the end of the run. | |
554 | // | |
555 | ||
556 | // | |
557 | if(fLego) fLego->FinishRun(); | |
558 | ||
559 | // Clean detector information | |
560 | TIter next(fModules); | |
561 | AliModule *detector; | |
562 | while((detector = (AliModule*)next())) { | |
563 | detector->FinishRun(); | |
564 | } | |
565 | ||
566 | //Output energy summary tables | |
567 | EnergySummary(); | |
568 | ||
569 | // file is retrieved from whatever tree | |
570 | TFile *file = 0; | |
571 | if (fTreeK) file = fTreeK->GetCurrentFile(); | |
572 | if ((!file) && (fTreeH)) file = fTreeH->GetCurrentFile(); | |
573 | if ((!file) && (fTreeD)) file = fTreeD->GetCurrentFile(); | |
574 | if ((!file) && (fTreeE)) file = fTreeE->GetCurrentFile(); | |
575 | if( NULL==file ) { | |
576 | Error("FinishRun","There isn't root file!"); | |
577 | exit(1); | |
578 | } | |
579 | file->cd(); | |
580 | fTreeE->Write(0,TObject::kOverwrite); | |
581 | ||
582 | // Clean tree information | |
583 | if (fTreeK) { | |
584 | delete fTreeK; fTreeK = 0; | |
585 | } | |
586 | if (fTreeH) { | |
587 | delete fTreeH; fTreeH = 0; | |
588 | } | |
589 | if (fTreeD) { | |
590 | delete fTreeD; fTreeD = 0; | |
591 | } | |
592 | if (fTreeR) { | |
593 | delete fTreeR; fTreeR = 0; | |
594 | } | |
595 | if (fTreeE) { | |
596 | delete fTreeE; fTreeE = 0; | |
597 | } | |
598 | ||
599 | // Write AliRun info and all detectors parameters | |
600 | Write(); | |
601 | ||
602 | // Close output file | |
603 | file->Write(); | |
604 | } | |
605 | ||
606 | //_____________________________________________________________________________ | |
607 | void AliRun::FlagTrack(Int_t track) | |
608 | { | |
609 | // | |
610 | // Flags a track and all its family tree to be kept | |
611 | // | |
612 | int curr; | |
613 | TParticle *particle; | |
614 | ||
615 | curr=track; | |
616 | while(1) { | |
617 | particle=(TParticle*)fParticles->UncheckedAt(curr); | |
618 | ||
619 | // If the particle is flagged the three from here upward is saved already | |
620 | if(particle->TestBit(kKeepBit)) return; | |
621 | ||
622 | // Save this particle | |
623 | particle->SetBit(kKeepBit); | |
624 | ||
625 | // Move to father if any | |
626 | if((curr=particle->GetFirstMother())==-1) return; | |
627 | } | |
628 | } | |
629 | ||
630 | //_____________________________________________________________________________ | |
631 | void AliRun::EnergySummary() | |
632 | { | |
633 | // | |
634 | // Print summary of deposited energy | |
635 | // | |
636 | ||
637 | Int_t ndep=0; | |
638 | Float_t edtot=0; | |
639 | Float_t ed, ed2; | |
640 | Int_t kn, i, left, j, id; | |
641 | const Float_t kzero=0; | |
642 | Int_t ievent=fHeader.GetEvent()+1; | |
643 | // | |
644 | // Energy loss information | |
645 | if(ievent) { | |
646 | printf("***************** Energy Loss Information per event (GEV) *****************\n"); | |
647 | for(kn=1;kn<fEventEnergy.GetSize();kn++) { | |
648 | ed=fSummEnergy[kn]; | |
649 | if(ed>0) { | |
650 | fEventEnergy[ndep]=kn; | |
651 | if(ievent>1) { | |
652 | ed=ed/ievent; | |
653 | ed2=fSum2Energy[kn]; | |
654 | ed2=ed2/ievent; | |
655 | ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,kzero))/ed; | |
656 | } else | |
657 | ed2=99; | |
658 | fSummEnergy[ndep]=ed; | |
659 | fSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,kzero)); | |
660 | edtot+=ed; | |
661 | ndep++; | |
662 | } | |
663 | } | |
664 | for(kn=0;kn<(ndep-1)/3+1;kn++) { | |
665 | left=ndep-kn*3; | |
666 | for(i=0;i<(3<left?3:left);i++) { | |
667 | j=kn*3+i; | |
668 | id=Int_t (fEventEnergy[j]+0.1); | |
669 | printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]); | |
670 | } | |
671 | printf("\n"); | |
672 | } | |
673 | // | |
674 | // Relative energy loss in different detectors | |
675 | printf("******************** Relative Energy Loss per event ********************\n"); | |
676 | printf("Total energy loss per event %10.3f GeV\n",edtot); | |
677 | for(kn=0;kn<(ndep-1)/5+1;kn++) { | |
678 | left=ndep-kn*5; | |
679 | for(i=0;i<(5<left?5:left);i++) { | |
680 | j=kn*5+i; | |
681 | id=Int_t (fEventEnergy[j]+0.1); | |
682 | printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot); | |
683 | } | |
684 | printf("\n"); | |
685 | } | |
686 | for(kn=0;kn<75;kn++) printf("*"); | |
687 | printf("\n"); | |
688 | } | |
689 | // | |
690 | // Reset the TArray's | |
691 | // fEventEnergy.Set(0); | |
692 | // fSummEnergy.Set(0); | |
693 | // fSum2Energy.Set(0); | |
694 | } | |
695 | ||
696 | //_____________________________________________________________________________ | |
697 | AliModule *AliRun::GetModule(const char *name) const | |
698 | { | |
699 | // | |
700 | // Return pointer to detector from name | |
701 | // | |
702 | return (AliModule*)fModules->FindObject(name); | |
703 | } | |
704 | ||
705 | //_____________________________________________________________________________ | |
706 | AliDetector *AliRun::GetDetector(const char *name) const | |
707 | { | |
708 | // | |
709 | // Return pointer to detector from name | |
710 | // | |
711 | return (AliDetector*)fModules->FindObject(name); | |
712 | } | |
713 | ||
714 | //_____________________________________________________________________________ | |
715 | Int_t AliRun::GetModuleID(const char *name) const | |
716 | { | |
717 | // | |
718 | // Return galice internal detector identifier from name | |
719 | // | |
720 | Int_t i=-1; | |
721 | TObject *mod=fModules->FindObject(name); | |
722 | if(mod) i=fModules->IndexOf(mod); | |
723 | return i; | |
724 | } | |
725 | ||
726 | //_____________________________________________________________________________ | |
727 | Int_t AliRun::GetEvent(Int_t event) | |
728 | { | |
729 | // | |
730 | // Connect the Trees Kinematics and Hits for event # event | |
731 | // Set branch addresses | |
732 | // | |
733 | ||
734 | // Reset existing structures | |
735 | ResetStack(); | |
736 | ResetHits(); | |
737 | ResetDigits(); | |
738 | ||
739 | // Delete Trees already connected | |
740 | if (fTreeK) delete fTreeK; | |
741 | if (fTreeH) delete fTreeH; | |
742 | if (fTreeD) delete fTreeD; | |
743 | if (fTreeR) delete fTreeR; | |
744 | ||
745 | // Get header from file | |
746 | if(fTreeE) fTreeE->GetEntry(event); | |
747 | else Error("GetEvent","Cannot file Header Tree\n"); | |
748 | ||
749 | // Get Kine Tree from file | |
750 | char treeName[20]; | |
751 | sprintf(treeName,"TreeK%d",event); | |
752 | fTreeK = (TTree*)gDirectory->Get(treeName); | |
753 | if (fTreeK) fTreeK->SetBranchAddress("Particles", &fParticles); | |
754 | else Error("GetEvent","cannot find Kine Tree for event:%d\n",event); | |
755 | ||
756 | // Get Hits Tree header from file | |
757 | sprintf(treeName,"TreeH%d",event); | |
758 | fTreeH = (TTree*)gDirectory->Get(treeName); | |
759 | if (!fTreeH) { | |
760 | Error("GetEvent","cannot find Hits Tree for event:%d\n",event); | |
761 | } | |
762 | ||
763 | // Get Digits Tree header from file | |
764 | sprintf(treeName,"TreeD%d",event); | |
765 | fTreeD = (TTree*)gDirectory->Get(treeName); | |
766 | if (!fTreeD) { | |
767 | Warning("GetEvent","cannot find Digits Tree for event:%d\n",event); | |
768 | } | |
769 | ||
770 | ||
771 | // Get Reconstruct Tree header from file | |
772 | sprintf(treeName,"TreeR%d",event); | |
773 | fTreeR = (TTree*)gDirectory->Get(treeName); | |
774 | if (!fTreeR) { | |
775 | // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event); | |
776 | } | |
777 | ||
778 | // Set Trees branch addresses | |
779 | TIter next(fModules); | |
780 | AliModule *detector; | |
781 | while((detector = (AliModule*)next())) { | |
782 | detector->SetTreeAddress(); | |
783 | } | |
784 | ||
785 | if (fTreeK) fTreeK->GetEvent(0); | |
786 | fNtrack = Int_t (fParticles->GetEntries()); | |
787 | return fNtrack; | |
788 | } | |
789 | ||
790 | //_____________________________________________________________________________ | |
791 | TGeometry *AliRun::GetGeometry() | |
792 | { | |
793 | // | |
794 | // Import Alice geometry from current file | |
795 | // Return pointer to geometry object | |
796 | // | |
797 | if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom"); | |
798 | // | |
799 | // Unlink and relink nodes in detectors | |
800 | // This is bad and there must be a better way... | |
801 | // | |
802 | ||
803 | TIter next(fModules); | |
804 | AliModule *detector; | |
805 | while((detector = (AliModule*)next())) { | |
806 | detector->SetTreeAddress(); | |
807 | TList *dnodes=detector->Nodes(); | |
808 | Int_t j; | |
809 | TNode *node, *node1; | |
810 | for ( j=0; j<dnodes->GetSize(); j++) { | |
811 | node = (TNode*) dnodes->At(j); | |
812 | node1 = fGeometry->GetNode(node->GetName()); | |
813 | dnodes->Remove(node); | |
814 | dnodes->AddAt(node1,j); | |
815 | } | |
816 | } | |
817 | return fGeometry; | |
818 | } | |
819 | ||
820 | //_____________________________________________________________________________ | |
821 | void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom, | |
822 | Float_t &e, Float_t *vpos, Float_t *polar, | |
823 | Float_t &tof) | |
824 | { | |
825 | // | |
826 | // Return next track from stack of particles | |
827 | // | |
828 | TVector3 pol; | |
829 | fCurrent=-1; | |
830 | TParticle *track; | |
831 | for(Int_t i=fNtrack-1; i>=0; i--) { | |
832 | track=(TParticle*) fParticles->UncheckedAt(i); | |
833 | if(!track->TestBit(kDoneBit)) { | |
834 | // | |
835 | // The track has not yet been processed | |
836 | fCurrent=i; | |
837 | ipart=track->GetPdgCode(); | |
838 | pmom[0]=track->Px(); | |
839 | pmom[1]=track->Py(); | |
840 | pmom[2]=track->Pz(); | |
841 | e =track->Energy(); | |
842 | vpos[0]=track->Vx(); | |
843 | vpos[1]=track->Vy(); | |
844 | vpos[2]=track->Vz(); | |
845 | track->GetPolarisation(pol); | |
846 | polar[0]=pol.X(); | |
847 | polar[1]=pol.Y(); | |
848 | polar[2]=pol.Z(); | |
849 | tof=track->T(); | |
850 | track->SetBit(kDoneBit); | |
851 | break; | |
852 | } | |
853 | } | |
854 | mtrack=fCurrent; | |
855 | // | |
856 | // stop and start timer when we start a primary track | |
857 | Int_t nprimaries = fHeader.GetNprimary(); | |
858 | if (fCurrent >= nprimaries) return; | |
859 | if (fCurrent < nprimaries-1) { | |
860 | fTimer.Stop(); | |
861 | track=(TParticle*) fParticles->UncheckedAt(fCurrent+1); | |
862 | // track->SetProcessTime(fTimer.CpuTime()); | |
863 | } | |
864 | fTimer.Start(); | |
865 | } | |
866 | ||
867 | //_____________________________________________________________________________ | |
868 | Int_t AliRun::GetPrimary(Int_t track) const | |
869 | { | |
870 | // | |
871 | // return number of primary that has generated track | |
872 | // | |
873 | int current, parent; | |
874 | TParticle *part; | |
875 | // | |
876 | parent=track; | |
877 | while (1) { | |
878 | current=parent; | |
879 | part = (TParticle *)fParticles->UncheckedAt(current); | |
880 | parent=part->GetFirstMother(); | |
881 | if(parent<0) return current; | |
882 | } | |
883 | } | |
884 | ||
885 | //_____________________________________________________________________________ | |
886 | void AliRun::InitMC(const char *setup) | |
887 | { | |
888 | // | |
889 | // Initialize the Alice setup | |
890 | // | |
891 | ||
892 | if(fInitDone) { | |
893 | Warning("Init","Cannot initialise AliRun twice!\n"); | |
894 | return; | |
895 | } | |
896 | ||
897 | gROOT->LoadMacro(setup); | |
898 | gInterpreter->ProcessLine(fConfigFunction.Data()); | |
899 | ||
900 | gMC->DefineParticles(); //Create standard MC particles | |
901 | ||
902 | TObject *objfirst, *objlast; | |
903 | ||
904 | fNdets = fModules->GetLast()+1; | |
905 | ||
906 | // | |
907 | //=================Create Materials and geometry | |
908 | gMC->Init(); | |
909 | ||
910 | TIter next(fModules); | |
911 | AliModule *detector; | |
912 | while((detector = (AliModule*)next())) { | |
913 | detector->SetTreeAddress(); | |
914 | objlast = gDirectory->GetList()->Last(); | |
915 | ||
916 | // Add Detector histograms in Detector list of histograms | |
917 | if (objlast) objfirst = gDirectory->GetList()->After(objlast); | |
918 | else objfirst = gDirectory->GetList()->First(); | |
919 | while (objfirst) { | |
920 | detector->Histograms()->Add(objfirst); | |
921 | objfirst = gDirectory->GetList()->After(objfirst); | |
922 | } | |
923 | } | |
924 | SetTransPar(); //Read the cuts for all materials | |
925 | ||
926 | MediaTable(); //Build the special IMEDIA table | |
927 | ||
928 | //Initialise geometry deposition table | |
929 | fEventEnergy.Set(gMC->NofVolumes()+1); | |
930 | fSummEnergy.Set(gMC->NofVolumes()+1); | |
931 | fSum2Energy.Set(gMC->NofVolumes()+1); | |
932 | ||
933 | //Compute cross-sections | |
934 | gMC->BuildPhysics(); | |
935 | ||
936 | //Write Geometry object to current file. | |
937 | fGeometry->Write(); | |
938 | ||
939 | fInitDone = kTRUE; | |
940 | ||
941 | // | |
942 | // Save stuff at the beginning of the file to avoid file corruption | |
943 | Write(); | |
944 | } | |
945 | ||
946 | //_____________________________________________________________________________ | |
947 | void AliRun::MediaTable() | |
948 | { | |
949 | // | |
950 | // Built media table to get from the media number to | |
951 | // the detector id | |
952 | // | |
953 | Int_t kz, nz, idt, lz, i, k, ind; | |
954 | // Int_t ibeg; | |
955 | TObjArray &dets = *gAlice->Detectors(); | |
956 | AliModule *det; | |
957 | // | |
958 | // For all detectors | |
959 | for (kz=0;kz<fNdets;kz++) { | |
960 | // If detector is defined | |
961 | if((det=(AliModule*) dets[kz])) { | |
962 | TArrayI &idtmed = *(det->GetIdtmed()); | |
963 | for(nz=0;nz<100;nz++) { | |
964 | // Find max and min material number | |
965 | if((idt=idtmed[nz])) { | |
966 | det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt; | |
967 | det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt; | |
968 | } | |
969 | } | |
970 | if(det->LoMedium() > det->HiMedium()) { | |
971 | det->LoMedium() = 0; | |
972 | det->HiMedium() = 0; | |
973 | } else { | |
974 | if(det->HiMedium() > fImedia->GetSize()) { | |
975 | Error("MediaTable","Increase fImedia from %d to %d", | |
976 | fImedia->GetSize(),det->HiMedium()); | |
977 | return; | |
978 | } | |
979 | // Tag all materials in rage as belonging to detector kz | |
980 | for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) { | |
981 | (*fImedia)[lz]=kz; | |
982 | } | |
983 | } | |
984 | } | |
985 | } | |
986 | // | |
987 | // Print summary table | |
988 | printf(" Traking media ranges:\n"); | |
989 | for(i=0;i<(fNdets-1)/6+1;i++) { | |
990 | for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) { | |
991 | ind=i*6+k; | |
992 | det=(AliModule*)dets[ind]; | |
993 | if(det) | |
994 | printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(), | |
995 | det->HiMedium()); | |
996 | else | |
997 | printf(" %6s: %3d -> %3d;","NULL",0,0); | |
998 | } | |
999 | printf("\n"); | |
1000 | } | |
1001 | } | |
1002 | ||
1003 | //____________________________________________________________________________ | |
1004 | void AliRun::SetGenerator(AliGenerator *generator) | |
1005 | { | |
1006 | // | |
1007 | // Load the event generator | |
1008 | // | |
1009 | if(!fGenerator) fGenerator = generator; | |
1010 | } | |
1011 | ||
1012 | //____________________________________________________________________________ | |
1013 | void AliRun::ResetGenerator(AliGenerator *generator) | |
1014 | { | |
1015 | // | |
1016 | // Load the event generator | |
1017 | // | |
1018 | if(fGenerator) | |
1019 | if(generator) | |
1020 | Warning("ResetGenerator","Replacing generator %s with %s\n", | |
1021 | fGenerator->GetName(),generator->GetName()); | |
1022 | else | |
1023 | Warning("ResetGenerator","Replacing generator %s with NULL\n", | |
1024 | fGenerator->GetName()); | |
1025 | fGenerator = generator; | |
1026 | } | |
1027 | ||
1028 | //____________________________________________________________________________ | |
1029 | void AliRun::SetTransPar(char* filename) | |
1030 | { | |
1031 | // | |
1032 | // Read filename to set the transport parameters | |
1033 | // | |
1034 | ||
1035 | ||
1036 | const Int_t kncuts=10; | |
1037 | const Int_t knflags=11; | |
1038 | const Int_t knpars=kncuts+knflags; | |
1039 | const char kpars[knpars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO", | |
1040 | "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI", | |
1041 | "BREM","COMP","DCAY","DRAY","HADR","LOSS", | |
1042 | "MULS","PAIR","PHOT","RAYL"}; | |
1043 | char line[256]; | |
1044 | char detName[7]; | |
1045 | char* filtmp; | |
1046 | Float_t cut[kncuts]; | |
1047 | Int_t flag[knflags]; | |
1048 | Int_t i, itmed, iret, ktmed, kz; | |
1049 | FILE *lun; | |
1050 | // | |
1051 | // See whether the file is there | |
1052 | filtmp=gSystem->ExpandPathName(filename); | |
1053 | lun=fopen(filtmp,"r"); | |
1054 | delete [] filtmp; | |
1055 | if(!lun) { | |
1056 | Warning("SetTransPar","File %s does not exist!\n",filename); | |
1057 | return; | |
1058 | } | |
1059 | // | |
1060 | printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n"); | |
1061 | printf(" *%59s\n","*"); | |
1062 | printf(" * Please check carefully what you are doing!%10s\n","*"); | |
1063 | printf(" *%59s\n","*"); | |
1064 | // | |
1065 | while(1) { | |
1066 | // Initialise cuts and flags | |
1067 | for(i=0;i<kncuts;i++) cut[i]=-99; | |
1068 | for(i=0;i<knflags;i++) flag[i]=-99; | |
1069 | itmed=0; | |
1070 | for(i=0;i<256;i++) line[i]='\0'; | |
1071 | // Read up to the end of line excluded | |
1072 | iret=fscanf(lun,"%[^\n]",line); | |
1073 | if(iret<0) { | |
1074 | //End of file | |
1075 | fclose(lun); | |
1076 | printf(" *%59s\n","*"); | |
1077 | printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n"); | |
1078 | return; | |
1079 | } | |
1080 | // Read the end of line | |
1081 | fscanf(lun,"%*c"); | |
1082 | if(!iret) continue; | |
1083 | if(line[0]=='*') continue; | |
1084 | // Read the numbers | |
1085 | iret=sscanf(line,"%s %d %f %f %f %f %f %f %f %f %f %f %d %d %d %d %d %d %d %d %d %d %d", | |
1086 | detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8], | |
1087 | &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7], | |
1088 | &flag[8],&flag[9],&flag[10]); | |
1089 | if(!iret) continue; | |
1090 | if(iret<0) { | |
1091 | //reading error | |
1092 | Warning("SetTransPar","Error reading file %s\n",filename); | |
1093 | continue; | |
1094 | } | |
1095 | // Check that the module exist | |
1096 | AliModule *mod = GetModule(detName); | |
1097 | if(mod) { | |
1098 | // Get the array of media numbers | |
1099 | TArrayI &idtmed = *mod->GetIdtmed(); | |
1100 | // Check that the tracking medium code is valid | |
1101 | if(0<=itmed && itmed < 100) { | |
1102 | ktmed=idtmed[itmed]; | |
1103 | if(!ktmed) { | |
1104 | Warning("SetTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName()); | |
1105 | continue; | |
1106 | } | |
1107 | // Set energy thresholds | |
1108 | for(kz=0;kz<kncuts;kz++) { | |
1109 | if(cut[kz]>=0) { | |
1110 | printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n", | |
1111 | kpars[kz],cut[kz],itmed,mod->GetName()); | |
1112 | gMC->Gstpar(ktmed,kpars[kz],cut[kz]); | |
1113 | } | |
1114 | } | |
1115 | // Set transport mechanisms | |
1116 | for(kz=0;kz<knflags;kz++) { | |
1117 | if(flag[kz]>=0) { | |
1118 | printf(" * %-6s set to %10d for tracking medium code %4d for %s\n", | |
1119 | kpars[kncuts+kz],flag[kz],itmed,mod->GetName()); | |
1120 | gMC->Gstpar(ktmed,kpars[kncuts+kz],Float_t(flag[kz])); | |
1121 | } | |
1122 | } | |
1123 | } else { | |
1124 | Warning("SetTransPar","Invalid medium code %d *\n",itmed); | |
1125 | continue; | |
1126 | } | |
1127 | } else { | |
1128 | Warning("SetTransPar","Module %s not present\n",detName); | |
1129 | continue; | |
1130 | } | |
1131 | } | |
1132 | } | |
1133 | ||
1134 | //_____________________________________________________________________________ | |
1135 | void AliRun::MakeTree(Option_t *option) | |
1136 | { | |
1137 | // | |
1138 | // Create the ROOT trees | |
1139 | // Loop on all detectors to create the Root branch (if any) | |
1140 | // | |
1141 | ||
1142 | char hname[30]; | |
1143 | // | |
1144 | // Analyse options | |
1145 | char *oK = strstr(option,"K"); | |
1146 | char *oH = strstr(option,"H"); | |
1147 | char *oE = strstr(option,"E"); | |
1148 | char *oD = strstr(option,"D"); | |
1149 | char *oR = strstr(option,"R"); | |
1150 | // | |
1151 | if (oK && !fTreeK) { | |
1152 | sprintf(hname,"TreeK%d",fEvent); | |
1153 | fTreeK = new TTree(hname,"Kinematics"); | |
1154 | // Create a branch for particles | |
1155 | fTreeK->Branch("Particles",&fParticles,4000); | |
1156 | fTreeK->Write(); | |
1157 | } | |
1158 | if (oH && !fTreeH) { | |
1159 | sprintf(hname,"TreeH%d",fEvent); | |
1160 | fTreeH = new TTree(hname,"Hits"); | |
1161 | fTreeH->SetAutoSave(1000000000); //no autosave | |
1162 | fTreeH->Write(); | |
1163 | } | |
1164 | if (oD && !fTreeD) { | |
1165 | sprintf(hname,"TreeD%d",fEvent); | |
1166 | fTreeD = new TTree(hname,"Digits"); | |
1167 | fTreeD->Write(); | |
1168 | } | |
1169 | if (oR && !fTreeR) { | |
1170 | sprintf(hname,"TreeR%d",fEvent); | |
1171 | fTreeR = new TTree(hname,"Reconstruction"); | |
1172 | fTreeR->Write(); | |
1173 | } | |
1174 | if (oE && !fTreeE) { | |
1175 | fTreeE = new TTree("TE","Header"); | |
1176 | // Create a branch for Header | |
1177 | fTreeE->Branch("Header","AliHeader",&gAliHeader,4000); | |
1178 | fTreeE->Write(); | |
1179 | } | |
1180 | // | |
1181 | // Create a branch for hits/digits for each detector | |
1182 | // Each branch is a TClonesArray. Each data member of the Hits classes | |
1183 | // will be in turn a subbranch of the detector master branch | |
1184 | TIter next(fModules); | |
1185 | AliModule *detector; | |
1186 | while((detector = (AliModule*)next())) { | |
1187 | if (oH || oD || oR) detector->MakeBranch(option); | |
1188 | } | |
1189 | } | |
1190 | ||
1191 | //_____________________________________________________________________________ | |
1192 | Int_t AliRun::PurifyKine(Int_t lastSavedTrack, Int_t nofTracks) | |
1193 | { | |
1194 | // | |
1195 | // PurifyKine with external parameters | |
1196 | // | |
1197 | fHgwmk = lastSavedTrack; | |
1198 | fNtrack = nofTracks; | |
1199 | PurifyKine(); | |
1200 | return fHgwmk; | |
1201 | } | |
1202 | ||
1203 | //_____________________________________________________________________________ | |
1204 | void AliRun::PurifyKine() | |
1205 | { | |
1206 | // | |
1207 | // Compress kinematic tree keeping only flagged particles | |
1208 | // and renaming the particle id's in all the hits | |
1209 | // | |
1210 | TClonesArray &particles = *fParticles; | |
1211 | int nkeep=fHgwmk+1, parent, i; | |
1212 | TParticle *part, *partnew, *father; | |
1213 | int *map = new int[particles.GetEntries()]; | |
1214 | ||
1215 | // Save in Header total number of tracks before compression | |
1216 | fHeader.SetNtrack(fHeader.GetNtrack()+fNtrack-fHgwmk); | |
1217 | ||
1218 | // First pass, invalid Daughter information | |
1219 | for(i=0; i<fNtrack; i++) { | |
1220 | // Preset map, to be removed later | |
1221 | if(i<=fHgwmk) map[i]=i ; else map[i] = -99; | |
1222 | ((TParticle *)particles.UncheckedAt(i))->ResetBit(kDaughtersBit); | |
1223 | } | |
1224 | // Second pass, build map between old and new numbering | |
1225 | for(i=fHgwmk+1; i<fNtrack; i++) { | |
1226 | part = (TParticle *)particles.UncheckedAt(i); | |
1227 | if(part->TestBit(kKeepBit)) { | |
1228 | ||
1229 | // This particle has to be kept | |
1230 | map[i]=nkeep; | |
1231 | if(i!=nkeep) { | |
1232 | ||
1233 | // Old and new are different, have to copy | |
1234 | partnew = (TParticle *)particles.UncheckedAt(nkeep); | |
1235 | // Change due to a bug in the HP compiler | |
1236 | // *partnew = *part; | |
1237 | memcpy(partnew,part,sizeof(TParticle)); | |
1238 | } else partnew = part; | |
1239 | ||
1240 | // as the parent is always *before*, it must be already | |
1241 | // in place. This is what we are checking anyway! | |
1242 | if((parent=partnew->GetFirstMother())>fHgwmk) { | |
1243 | if(map[parent]==-99) printf("map[%d] = -99!\n",parent); | |
1244 | partnew->SetFirstMother(map[parent]); | |
1245 | } | |
1246 | nkeep++; | |
1247 | } | |
1248 | } | |
1249 | fNtrack=nkeep; | |
1250 | ||
1251 | // Fix daughters information | |
1252 | for (i=0; i<fNtrack; i++) { | |
1253 | part = (TParticle *)particles.UncheckedAt(i); | |
1254 | parent = part->GetFirstMother(); | |
1255 | if(parent>=0) { | |
1256 | father = (TParticle *)particles.UncheckedAt(parent); | |
1257 | if(father->TestBit(kDaughtersBit)) { | |
1258 | ||
1259 | if(i<father->GetFirstDaughter()) father->SetFirstDaughter(i); | |
1260 | if(i>father->GetLastDaughter()) father->SetLastDaughter(i); | |
1261 | } else { | |
1262 | // Iitialise daughters info for first pass | |
1263 | father->SetFirstDaughter(i); | |
1264 | father->SetLastDaughter(i); | |
1265 | father->SetBit(kDaughtersBit); | |
1266 | } | |
1267 | } | |
1268 | } | |
1269 | ||
1270 | #ifdef old | |
1271 | // Now loop on all detectors and reset the hits | |
1272 | AliHit *OneHit; | |
1273 | TIter next(fModules); | |
1274 | AliModule *detector; | |
1275 | while((detector = (AliModule*)next())) { | |
1276 | if (!detector->Hits()) continue; | |
1277 | TClonesArray &vHits=*(detector->Hits()); | |
1278 | if(vHits.GetEntries() != detector->GetNhits()) | |
1279 | printf("vHits.GetEntries()!=detector->GetNhits(): %d != %d\n", | |
1280 | vHits.GetEntries(),detector->GetNhits()); | |
1281 | for (i=0; i<detector->GetNhits(); i++) { | |
1282 | OneHit = (AliHit *)vHits.UncheckedAt(i); | |
1283 | OneHit->SetTrack(map[OneHit->GetTrack()]); | |
1284 | } | |
1285 | } | |
1286 | #else | |
1287 | ||
1288 | // Now loop on all registered hit lists | |
1289 | TIter next(fHitLists); | |
1290 | TCollection *hitList; | |
1291 | while((hitList = (TCollection*)next())) { | |
1292 | TIter nexthit(hitList); | |
1293 | AliHit *hit; | |
1294 | while((hit = (AliHit*)nexthit())) { | |
1295 | hit->SetTrack(map[hit->GetTrack()]); | |
1296 | } | |
1297 | } | |
1298 | #endif | |
1299 | ||
1300 | // | |
1301 | // This for detectors which have a special mapping mechanism | |
1302 | // for hits, such as TPC and TRD | |
1303 | // | |
1304 | ||
1305 | TIter nextmod(fModules); | |
1306 | AliModule *detector; | |
1307 | while((detector = (AliModule*)nextmod())) { | |
1308 | detector->RemapTrackHitIDs(map); | |
1309 | } | |
1310 | ||
1311 | ||
1312 | fHgwmk=nkeep-1; | |
1313 | particles.SetLast(fHgwmk); | |
1314 | delete [] map; | |
1315 | } | |
1316 | ||
1317 | //_____________________________________________________________________________ | |
1318 | void AliRun::BeginEvent() | |
1319 | { | |
1320 | // | |
1321 | // Reset all Detectors & kinematics & trees | |
1322 | // | |
1323 | char hname[30]; | |
1324 | // | |
1325 | ||
1326 | // | |
1327 | if(fLego) { | |
1328 | fLego->BeginEvent(); | |
1329 | return; | |
1330 | } | |
1331 | ||
1332 | // | |
1333 | ResetStack(); | |
1334 | ResetHits(); | |
1335 | ResetDigits(); | |
1336 | ||
1337 | // Initialise event header | |
1338 | fHeader.Reset(fRun,fEvent); | |
1339 | ||
1340 | if(fTreeK) { | |
1341 | fTreeK->Reset(); | |
1342 | sprintf(hname,"TreeK%d",fEvent); | |
1343 | fTreeK->SetName(hname); | |
1344 | } | |
1345 | if(fTreeH) { | |
1346 | fTreeH->Reset(); | |
1347 | sprintf(hname,"TreeH%d",fEvent); | |
1348 | fTreeH->SetName(hname); | |
1349 | } | |
1350 | if(fTreeD) { | |
1351 | fTreeD->Reset(); | |
1352 | sprintf(hname,"TreeD%d",fEvent); | |
1353 | fTreeD->SetName(hname); | |
1354 | } | |
1355 | if(fTreeR) { | |
1356 | fTreeR->Reset(); | |
1357 | sprintf(hname,"TreeR%d",fEvent); | |
1358 | fTreeR->SetName(hname); | |
1359 | } | |
1360 | } | |
1361 | ||
1362 | //_____________________________________________________________________________ | |
1363 | void AliRun::ResetDigits() | |
1364 | { | |
1365 | // | |
1366 | // Reset all Detectors digits | |
1367 | // | |
1368 | TIter next(fModules); | |
1369 | AliModule *detector; | |
1370 | while((detector = (AliModule*)next())) { | |
1371 | detector->ResetDigits(); | |
1372 | } | |
1373 | } | |
1374 | ||
1375 | //_____________________________________________________________________________ | |
1376 | void AliRun::ResetHits() | |
1377 | { | |
1378 | // | |
1379 | // Reset all Detectors hits | |
1380 | // | |
1381 | TIter next(fModules); | |
1382 | AliModule *detector; | |
1383 | while((detector = (AliModule*)next())) { | |
1384 | detector->ResetHits(); | |
1385 | } | |
1386 | } | |
1387 | ||
1388 | //_____________________________________________________________________________ | |
1389 | void AliRun::ResetPoints() | |
1390 | { | |
1391 | // | |
1392 | // Reset all Detectors points | |
1393 | // | |
1394 | TIter next(fModules); | |
1395 | AliModule *detector; | |
1396 | while((detector = (AliModule*)next())) { | |
1397 | detector->ResetPoints(); | |
1398 | } | |
1399 | } | |
1400 | ||
1401 | //_____________________________________________________________________________ | |
1402 | void AliRun::RunMC(Int_t nevent, const char *setup) | |
1403 | { | |
1404 | // | |
1405 | // Main function to be called to process a galice run | |
1406 | // example | |
1407 | // Root > gAlice.Run(); | |
1408 | // a positive number of events will cause the finish routine | |
1409 | // to be called | |
1410 | // | |
1411 | ||
1412 | // check if initialisation has been done | |
1413 | if (!fInitDone) InitMC(setup); | |
1414 | ||
1415 | // Create the Root Tree with one branch per detector | |
1416 | MakeTree("KHDER"); | |
1417 | ||
1418 | gMC->ProcessRun(nevent); | |
1419 | ||
1420 | // End of this run, close files | |
1421 | if(nevent>0) FinishRun(); | |
1422 | } | |
1423 | ||
1424 | //_____________________________________________________________________________ | |
1425 | void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min, | |
1426 | Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max, | |
1427 | Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener) | |
1428 | { | |
1429 | // | |
1430 | // Generates lego plots of: | |
1431 | // - radiation length map phi vs theta | |
1432 | // - radiation length map phi vs eta | |
1433 | // - interaction length map | |
1434 | // - g/cm2 length map | |
1435 | // | |
1436 | // ntheta bins in theta, eta | |
1437 | // themin minimum angle in theta (degrees) | |
1438 | // themax maximum angle in theta (degrees) | |
1439 | // nphi bins in phi | |
1440 | // phimin minimum angle in phi (degrees) | |
1441 | // phimax maximum angle in phi (degrees) | |
1442 | // rmin minimum radius | |
1443 | // rmax maximum radius | |
1444 | // | |
1445 | // | |
1446 | // The number of events generated = ntheta*nphi | |
1447 | // run input parameters in macro setup (default="Config.C") | |
1448 | // | |
1449 | // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates | |
1450 | //Begin_Html | |
1451 | /* | |
1452 | <img src="picts/AliRunLego1.gif"> | |
1453 | */ | |
1454 | //End_Html | |
1455 | //Begin_Html | |
1456 | /* | |
1457 | <img src="picts/AliRunLego2.gif"> | |
1458 | */ | |
1459 | //End_Html | |
1460 | //Begin_Html | |
1461 | /* | |
1462 | <img src="picts/AliRunLego3.gif"> | |
1463 | */ | |
1464 | //End_Html | |
1465 | // | |
1466 | ||
1467 | // check if initialisation has been done | |
1468 | if (!fInitDone) InitMC(setup); | |
1469 | //Save current generator | |
1470 | AliGenerator *gen=Generator(); | |
1471 | ||
1472 | // Set new generator | |
1473 | if (!gener) gener = new AliLegoGenerator(); | |
1474 | ResetGenerator(gener); | |
1475 | // | |
1476 | // Configure Generator | |
1477 | gener->SetRadiusRange(rmin, rmax); | |
1478 | gener->SetZMax(zmax); | |
1479 | gener->SetCoor1Range(nc1, c1min, c1max); | |
1480 | gener->SetCoor2Range(nc2, c2min, c2max); | |
1481 | ||
1482 | ||
1483 | //Create Lego object | |
1484 | fLego = new AliLego("lego",gener); | |
1485 | ||
1486 | //Prepare MC for Lego Run | |
1487 | gMC->InitLego(); | |
1488 | ||
1489 | //Run Lego Object | |
1490 | ||
1491 | gMC->ProcessRun(nc1*nc2+1); | |
1492 | ||
1493 | // Create only the Root event Tree | |
1494 | MakeTree("E"); | |
1495 | ||
1496 | // End of this run, close files | |
1497 | FinishRun(); | |
1498 | // Restore current generator | |
1499 | ResetGenerator(gen); | |
1500 | // Delete Lego Object | |
1501 | delete fLego; fLego=0; | |
1502 | } | |
1503 | ||
1504 | //_____________________________________________________________________________ | |
1505 | void AliRun::SetConfigFunction(const char * config) | |
1506 | { | |
1507 | // | |
1508 | // Set the signature of the function contained in Config.C to configure | |
1509 | // the run | |
1510 | // | |
1511 | fConfigFunction=config; | |
1512 | } | |
1513 | ||
1514 | //_____________________________________________________________________________ | |
1515 | void AliRun::SetCurrentTrack(Int_t track) | |
1516 | { | |
1517 | // | |
1518 | // Set current track number | |
1519 | // | |
1520 | fCurrent = track; | |
1521 | } | |
1522 | ||
1523 | //_____________________________________________________________________________ | |
1524 | void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom, | |
1525 | Float_t *vpos, Float_t *polar, Float_t tof, | |
1526 | const char* /* mecha */, Int_t &ntr, Float_t weight) | |
1527 | { | |
1528 | // | |
1529 | // Load a track on the stack | |
1530 | // | |
1531 | // done 0 if the track has to be transported | |
1532 | // 1 if not | |
1533 | // parent identifier of the parent track. -1 for a primary | |
1534 | // pdg particle code | |
1535 | // pmom momentum GeV/c | |
1536 | // vpos position | |
1537 | // polar polarisation | |
1538 | // tof time of flight in seconds | |
1539 | // mecha production mechanism | |
1540 | // ntr on output the number of the track stored | |
1541 | // | |
1542 | TClonesArray &particles = *fParticles; | |
1543 | TParticle *particle; | |
1544 | Float_t mass; | |
1545 | const Int_t kfirstdaughter=-1; | |
1546 | const Int_t klastdaughter=-1; | |
1547 | const Int_t kS=0; | |
1548 | // const Float_t tlife=0; | |
1549 | ||
1550 | // | |
1551 | // Here we get the static mass | |
1552 | // For MC is ok, but a more sophisticated method could be necessary | |
1553 | // if the calculated mass is required | |
1554 | // also, this method is potentially dangerous if the mass | |
1555 | // used in the MC is not the same of the PDG database | |
1556 | // | |
1557 | mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass(); | |
1558 | Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+ | |
1559 | pmom[1]*pmom[1]+pmom[2]*pmom[2]); | |
1560 | ||
1561 | //printf("Loading particle %s mass %f ene %f No %d ip %d pos %f %f %f mom %f %f %f kS %d m %s\n", | |
1562 | //pname,mass,e,fNtrack,pdg,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],kS,mecha); | |
1563 | ||
1564 | particle=new(particles[fNtrack]) TParticle(pdg,kS,parent,-1,kfirstdaughter, | |
1565 | klastdaughter,pmom[0],pmom[1],pmom[2], | |
1566 | e,vpos[0],vpos[1],vpos[2],tof); | |
1567 | // polar[0],polar[1],polar[2],tof, | |
1568 | // mecha,weight); | |
1569 | ((TParticle*)particles[fNtrack])->SetPolarisation(TVector3(polar[0],polar[1],polar[2])); | |
1570 | ((TParticle*)particles[fNtrack])->SetWeight(weight); | |
1571 | if(!done) particle->SetBit(kDoneBit); | |
1572 | //Declare that the daughter information is valid | |
1573 | ((TParticle*)particles[fNtrack])->SetBit(kDaughtersBit); | |
1574 | ||
1575 | if(parent>=0) { | |
1576 | particle=(TParticle*) fParticles->UncheckedAt(parent); | |
1577 | particle->SetLastDaughter(fNtrack); | |
1578 | if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack); | |
1579 | } else { | |
1580 | // | |
1581 | // This is a primary track. Set high water mark for this event | |
1582 | fHgwmk=fNtrack; | |
1583 | // | |
1584 | // Set also number if primary tracks | |
1585 | fHeader.SetNprimary(fHgwmk+1); | |
1586 | fHeader.SetNtrack(fHgwmk+1); | |
1587 | } | |
1588 | ntr = fNtrack++; | |
1589 | } | |
1590 | ||
1591 | //_____________________________________________________________________________ | |
1592 | void AliRun::KeepTrack(const Int_t track) | |
1593 | { | |
1594 | // | |
1595 | // flags a track to be kept | |
1596 | // | |
1597 | TClonesArray &particles = *fParticles; | |
1598 | ((TParticle*)particles[track])->SetBit(kKeepBit); | |
1599 | } | |
1600 | ||
1601 | //_____________________________________________________________________________ | |
1602 | void AliRun::StepManager(Int_t id) | |
1603 | { | |
1604 | // | |
1605 | // Called at every step during transport | |
1606 | // | |
1607 | ||
1608 | // | |
1609 | // --- If lego option, do it and leave | |
1610 | if (fLego) | |
1611 | fLego->StepManager(); | |
1612 | else { | |
1613 | Int_t copy; | |
1614 | //Update energy deposition tables | |
1615 | AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep()); | |
1616 | ||
1617 | //Call the appropriate stepping routine; | |
1618 | AliModule *det = (AliModule*)fModules->At(id); | |
1619 | if(det) det->StepManager(); | |
1620 | } | |
1621 | } | |
1622 | ||
1623 | //_____________________________________________________________________________ | |
1624 | void AliRun::Streamer(TBuffer &R__b) | |
1625 | { | |
1626 | // | |
1627 | // Stream an object of class AliRun. | |
1628 | // | |
1629 | if (R__b.IsReading()) { | |
1630 | Version_t R__v = R__b.ReadVersion(); if (R__v) { } | |
1631 | TNamed::Streamer(R__b); | |
1632 | if (!gAlice) gAlice = this; | |
1633 | gROOT->GetListOfBrowsables()->Add(this,"Run"); | |
1634 | fTreeE = (TTree*)gDirectory->Get("TE"); | |
1635 | if (fTreeE) fTreeE->SetBranchAddress("Header", &gAliHeader); | |
1636 | else Error("Streamer","cannot find Header Tree\n"); | |
1637 | R__b >> fNtrack; | |
1638 | R__b >> fHgwmk; | |
1639 | R__b >> fDebug; | |
1640 | fHeader.Streamer(R__b); | |
1641 | R__b >> fModules; | |
1642 | R__b >> fParticles; | |
1643 | R__b >> fField; | |
1644 | // R__b >> fMC; | |
1645 | R__b >> fNdets; | |
1646 | R__b >> fTrRmax; | |
1647 | R__b >> fTrZmax; | |
1648 | R__b >> fGenerator; | |
1649 | if(R__v>1) { | |
1650 | R__b >> fPDGDB; //Particle factory object! | |
1651 | fTreeE->GetEntry(0); | |
1652 | } else { | |
1653 | fHeader.SetEvent(0); | |
1654 | fPDGDB = TDatabasePDG::Instance(); //Particle factory object! | |
1655 | } | |
1656 | if(R__v>2) { | |
1657 | fConfigFunction.Streamer(R__b); | |
1658 | } else { | |
1659 | fConfigFunction="Config();"; | |
1660 | } | |
1661 | } else { | |
1662 | R__b.WriteVersion(AliRun::IsA()); | |
1663 | TNamed::Streamer(R__b); | |
1664 | R__b << fNtrack; | |
1665 | R__b << fHgwmk; | |
1666 | R__b << fDebug; | |
1667 | fHeader.Streamer(R__b); | |
1668 | R__b << fModules; | |
1669 | R__b << fParticles; | |
1670 | R__b << fField; | |
1671 | // R__b << fMC; | |
1672 | R__b << fNdets; | |
1673 | R__b << fTrRmax; | |
1674 | R__b << fTrZmax; | |
1675 | R__b << fGenerator; | |
1676 | R__b << fPDGDB; //Particle factory object! | |
1677 | fConfigFunction.Streamer(R__b); | |
1678 | } | |
1679 | } |