]>
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.58 2001/03/09 14:27:26 morsch | |
19 | Fix for multiple events per file: inhibit decrease of size of fParticleFileMap. | |
20 | ||
21 | Revision 1.57 2001/02/23 17:40:23 buncic | |
22 | All trees needed for simulation created in RunMC(). TreeR and its branches | |
23 | are now created in new RunReco() method. | |
24 | ||
25 | Revision 1.56 2001/02/14 15:45:20 hristov | |
26 | Algorithmic way of getting entry index in fParticleMap. Protection of fParticleFileMap (I.Hrivnacova) | |
27 | ||
28 | Revision 1.55 2001/02/12 15:52:54 buncic | |
29 | Removed OpenBaseFile(). | |
30 | ||
31 | Revision 1.54 2001/02/07 10:39:05 hristov | |
32 | Remove default value for argument | |
33 | ||
34 | Revision 1.53 2001/02/06 11:02:26 hristov | |
35 | New SetTrack interface added, added check for unfilled particles in FinishEvent (I.Hrivnacova) | |
36 | ||
37 | Revision 1.52 2001/02/05 16:22:25 buncic | |
38 | Added TreeS to GetEvent(). | |
39 | ||
40 | Revision 1.51 2001/02/02 15:16:20 morsch | |
41 | SetHighWaterMark method added to mark last particle in event. | |
42 | ||
43 | Revision 1.50 2001/01/27 10:32:00 hristov | |
44 | Leave the loop when primaries are filled (I.Hrivnacova) | |
45 | ||
46 | Revision 1.49 2001/01/26 19:58:48 hristov | |
47 | Major upgrade of AliRoot code | |
48 | ||
49 | Revision 1.48 2001/01/17 10:50:50 hristov | |
50 | Corrections to destructors | |
51 | ||
52 | Revision 1.47 2000/12/18 10:44:01 morsch | |
53 | Possibility to set field map by passing pointer to objet of type AliMagF via | |
54 | SetField(). | |
55 | Example: | |
56 | gAlice->SetField(new AliMagFCM("Map2", "$(ALICE_ROOT)/data/field01.dat",2,1.,10.)); | |
57 | ||
58 | Revision 1.46 2000/12/14 19:29:27 fca | |
59 | galice.cuts was not read any more | |
60 | ||
61 | Revision 1.45 2000/11/30 07:12:49 alibrary | |
62 | Introducing new Rndm and QA classes | |
63 | ||
64 | Revision 1.44 2000/10/26 13:58:59 morsch | |
65 | Add possibility to choose the lego generator (of type AliGeneratorLego or derived) when running | |
66 | RunLego(). Default is the base class AliGeneratorLego. | |
67 | ||
68 | Revision 1.43 2000/10/09 09:43:17 fca | |
69 | Special remapping of hits for TPC and TRD. End-of-primary action introduced | |
70 | ||
71 | Revision 1.42 2000/10/02 21:28:14 fca | |
72 | Removal of useless dependecies via forward declarations | |
73 | ||
74 | Revision 1.41 2000/07/13 16:19:09 fca | |
75 | Mainly coding conventions + some small bug fixes | |
76 | ||
77 | Revision 1.40 2000/07/12 08:56:25 fca | |
78 | Coding convention correction and warning removal | |
79 | ||
80 | Revision 1.39 2000/07/11 18:24:59 fca | |
81 | Coding convention corrections + few minor bug fixes | |
82 | ||
83 | Revision 1.38 2000/06/20 13:05:45 fca | |
84 | Writing down the TREE headers before job starts | |
85 | ||
86 | Revision 1.37 2000/06/09 20:05:11 morsch | |
87 | Introduce possibility to chose magnetic field version 3: AliMagFDM + field02.dat | |
88 | ||
89 | Revision 1.36 2000/06/08 14:03:58 hristov | |
90 | Only one initializer for a default argument | |
91 | ||
92 | Revision 1.35 2000/06/07 10:13:14 hristov | |
93 | Delete only existent objects. | |
94 | ||
95 | Revision 1.34 2000/05/18 10:45:38 fca | |
96 | Delete Particle Factory properly | |
97 | ||
98 | Revision 1.33 2000/05/16 13:10:40 fca | |
99 | New method IsNewTrack and fix for a problem in Father-Daughter relations | |
100 | ||
101 | Revision 1.32 2000/04/27 10:38:21 fca | |
102 | Correct termination of Lego Run and introduce Lego getter in AliRun | |
103 | ||
104 | Revision 1.31 2000/04/26 10:17:32 fca | |
105 | Changes in Lego for G4 compatibility | |
106 | ||
107 | Revision 1.30 2000/04/18 19:11:40 fca | |
108 | Introduce variable Config.C function signature | |
109 | ||
110 | Revision 1.29 2000/04/07 11:12:34 fca | |
111 | G4 compatibility changes | |
112 | ||
113 | Revision 1.28 2000/04/05 06:51:06 fca | |
114 | Workaround for an HP compiler problem | |
115 | ||
116 | Revision 1.27 2000/03/22 18:08:07 fca | |
117 | Rationalisation of the virtual MC interfaces | |
118 | ||
119 | Revision 1.26 2000/03/22 13:42:26 fca | |
120 | SetGenerator does not replace an existing generator, ResetGenerator does | |
121 | ||
122 | Revision 1.25 2000/02/23 16:25:22 fca | |
123 | AliVMC and AliGeant3 classes introduced | |
124 | ReadEuclid moved from AliRun to AliModule | |
125 | ||
126 | Revision 1.24 2000/01/19 17:17:20 fca | |
127 | Introducing a list of lists of hits -- more hits allowed for detector now | |
128 | ||
129 | Revision 1.23 1999/12/03 11:14:31 fca | |
130 | Fixing previous wrong checking | |
131 | ||
132 | Revision 1.21 1999/11/25 10:40:08 fca | |
133 | Fixing daughters information also in primary tracks | |
134 | ||
135 | Revision 1.20 1999/10/04 18:08:49 fca | |
136 | Adding protection against inconsistent Euclid files | |
137 | ||
138 | Revision 1.19 1999/09/29 07:50:40 fca | |
139 | Introduction of the Copyright and cvs Log | |
140 | ||
141 | */ | |
142 | ||
143 | /////////////////////////////////////////////////////////////////////////////// | |
144 | // // | |
145 | // Control class for Alice C++ // | |
146 | // Only one single instance of this class exists. // | |
147 | // The object is created in main program aliroot // | |
148 | // and is pointed by the global gAlice. // | |
149 | // // | |
150 | // -Supports the list of all Alice Detectors (fModules). // | |
151 | // -Supports the list of particles (fParticles). // | |
152 | // -Supports the Trees. // | |
153 | // -Supports the geometry. // | |
154 | // -Supports the event display. // | |
155 | //Begin_Html | |
156 | /* | |
157 | <img src="picts/AliRunClass.gif"> | |
158 | */ | |
159 | //End_Html | |
160 | //Begin_Html | |
161 | /* | |
162 | <img src="picts/alirun.gif"> | |
163 | */ | |
164 | //End_Html | |
165 | // // | |
166 | /////////////////////////////////////////////////////////////////////////////// | |
167 | ||
168 | #include <stdlib.h> | |
169 | #include <stdio.h> | |
170 | #include <string.h> | |
171 | #include <iostream.h> | |
172 | ||
173 | #include <TFile.h> | |
174 | #include <TRandom.h> | |
175 | #include <TBRIK.h> | |
176 | #include <TNode.h> | |
177 | #include <TCint.h> | |
178 | #include <TSystem.h> | |
179 | #include <TObjectTable.h> | |
180 | #include <TTree.h> | |
181 | #include <TGeometry.h> | |
182 | #include <TROOT.h> | |
183 | #include "TBrowser.h" | |
184 | ||
185 | #include "TParticle.h" | |
186 | #include "AliRun.h" | |
187 | #include "AliDisplay.h" | |
188 | #include "AliMC.h" | |
189 | #include "AliLego.h" | |
190 | #include "AliMagFC.h" | |
191 | #include "AliMagFCM.h" | |
192 | #include "AliMagFDM.h" | |
193 | #include "AliHit.h" | |
194 | #include "TRandom3.h" | |
195 | #include "AliMCQA.h" | |
196 | #include "AliGenerator.h" | |
197 | #include "AliLegoGenerator.h" | |
198 | ||
199 | #include "AliDetector.h" | |
200 | ||
201 | AliRun *gAlice; | |
202 | ||
203 | static AliHeader *gAliHeader; | |
204 | ||
205 | ClassImp(AliRun) | |
206 | ||
207 | //_____________________________________________________________________________ | |
208 | AliRun::AliRun() | |
209 | { | |
210 | // | |
211 | // Default constructor for AliRun | |
212 | // | |
213 | gAliHeader=&fHeader; | |
214 | fRun = 0; | |
215 | fEvent = 0; | |
216 | fCurrent = -1; | |
217 | fModules = 0; | |
218 | fGenerator = 0; | |
219 | fTreeD = 0; | |
220 | fTreeK = 0; | |
221 | fTreeH = 0; | |
222 | fTreeE = 0; | |
223 | fTreeR = 0; | |
224 | fTreeS = 0; | |
225 | fParticles = 0; | |
226 | fGeometry = 0; | |
227 | fDisplay = 0; | |
228 | fField = 0; | |
229 | fMC = 0; | |
230 | fNdets = 0; | |
231 | fImedia = 0; | |
232 | fTrRmax = 1.e10; | |
233 | fTrZmax = 1.e10; | |
234 | fInitDone = kFALSE; | |
235 | fLego = 0; | |
236 | fPDGDB = 0; //Particle factory object! | |
237 | fHitLists = 0; | |
238 | fConfigFunction = "\0"; | |
239 | fRandom = 0; | |
240 | fMCQA = 0; | |
241 | fTransParName = "\0"; | |
242 | fBaseFileName = ".\0"; | |
243 | fParticleBuffer = 0; | |
244 | fParticleMap = new TObjArray(10000); | |
245 | } | |
246 | ||
247 | //_____________________________________________________________________________ | |
248 | AliRun::AliRun(const char *name, const char *title) | |
249 | : TNamed(name,title) | |
250 | { | |
251 | // | |
252 | // Constructor for the main processor. | |
253 | // Creates the geometry | |
254 | // Creates the list of Detectors. | |
255 | // Creates the list of particles. | |
256 | // | |
257 | Int_t i; | |
258 | ||
259 | gAlice = this; | |
260 | fTreeD = 0; | |
261 | fTreeK = 0; | |
262 | fTreeH = 0; | |
263 | fTreeE = 0; | |
264 | fTreeR = 0; | |
265 | fTreeS = 0; | |
266 | fTrRmax = 1.e10; | |
267 | fTrZmax = 1.e10; | |
268 | fGenerator = 0; | |
269 | fInitDone = kFALSE; | |
270 | fLego = 0; | |
271 | fField = 0; | |
272 | fConfigFunction = "Config();"; | |
273 | ||
274 | // Set random number generator | |
275 | gRandom = fRandom = new TRandom3(); | |
276 | ||
277 | if (gSystem->Getenv("CONFIG_SEED")) { | |
278 | gRandom->SetSeed((UInt_t)atoi(gSystem->Getenv("CONFIG_SEED"))); | |
279 | } | |
280 | ||
281 | gROOT->GetListOfBrowsables()->Add(this,name); | |
282 | // | |
283 | // create the support list for the various Detectors | |
284 | fModules = new TObjArray(77); | |
285 | // | |
286 | // Create the TNode geometry for the event display | |
287 | ||
288 | BuildSimpleGeometry(); | |
289 | ||
290 | ||
291 | fNtrack=0; | |
292 | fHgwmk=0; | |
293 | fCurrent=-1; | |
294 | gAliHeader=&fHeader; | |
295 | fRun = 0; | |
296 | fEvent = 0; | |
297 | // | |
298 | // Create the particle stack | |
299 | fParticles = new TClonesArray("TParticle",1000); | |
300 | ||
301 | fDisplay = 0; | |
302 | // | |
303 | // Create default mag field | |
304 | SetField(); | |
305 | // | |
306 | fMC = gMC; | |
307 | // | |
308 | // Prepare the tracking medium lists | |
309 | fImedia = new TArrayI(1000); | |
310 | for(i=0;i<1000;i++) (*fImedia)[i]=-99; | |
311 | // | |
312 | // Make particles | |
313 | fPDGDB = TDatabasePDG::Instance(); //Particle factory object! | |
314 | // | |
315 | // Create HitLists list | |
316 | fHitLists = new TList(); | |
317 | // | |
318 | SetTransPar(); | |
319 | fBaseFileName = ".\0"; | |
320 | fParticleBuffer = 0; | |
321 | fParticleMap = new TObjArray(10000); | |
322 | } | |
323 | ||
324 | ||
325 | //_____________________________________________________________________________ | |
326 | AliRun::~AliRun() | |
327 | { | |
328 | // | |
329 | // Default AliRun destructor | |
330 | // | |
331 | delete fImedia; | |
332 | delete fField; | |
333 | delete fMC; | |
334 | delete fGeometry; | |
335 | delete fDisplay; | |
336 | delete fGenerator; | |
337 | delete fLego; | |
338 | delete fTreeD; | |
339 | delete fTreeK; | |
340 | delete fTreeH; | |
341 | delete fTreeE; | |
342 | delete fTreeR; | |
343 | delete fTreeS; | |
344 | if (fModules) { | |
345 | fModules->Delete(); | |
346 | delete fModules; | |
347 | } | |
348 | if (fParticles) { | |
349 | fParticles->Delete(); | |
350 | delete fParticles; | |
351 | } | |
352 | delete fHitLists; | |
353 | delete fPDGDB; | |
354 | delete fMCQA; | |
355 | } | |
356 | ||
357 | //_____________________________________________________________________________ | |
358 | void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const | |
359 | { | |
360 | // | |
361 | // Add a hit to detector id | |
362 | // | |
363 | TObjArray &dets = *fModules; | |
364 | if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits); | |
365 | } | |
366 | ||
367 | //_____________________________________________________________________________ | |
368 | void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const | |
369 | { | |
370 | // | |
371 | // Add digit to detector id | |
372 | // | |
373 | TObjArray &dets = *fModules; | |
374 | if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits); | |
375 | } | |
376 | ||
377 | //_____________________________________________________________________________ | |
378 | void AliRun::Browse(TBrowser *b) | |
379 | { | |
380 | // | |
381 | // Called when the item "Run" is clicked on the left pane | |
382 | // of the Root browser. | |
383 | // It displays the Root Trees and all detectors. | |
384 | // | |
385 | if (fTreeK) b->Add(fTreeK,fTreeK->GetName()); | |
386 | if (fTreeH) b->Add(fTreeH,fTreeH->GetName()); | |
387 | if (fTreeD) b->Add(fTreeD,fTreeD->GetName()); | |
388 | if (fTreeE) b->Add(fTreeE,fTreeE->GetName()); | |
389 | if (fTreeR) b->Add(fTreeR,fTreeR->GetName()); | |
390 | if (fTreeS) b->Add(fTreeS,fTreeS->GetName()); | |
391 | ||
392 | TIter next(fModules); | |
393 | AliModule *detector; | |
394 | while((detector = (AliModule*)next())) { | |
395 | b->Add(detector,detector->GetName()); | |
396 | } | |
397 | b->Add(fMCQA,"AliMCQA"); | |
398 | } | |
399 | ||
400 | //_____________________________________________________________________________ | |
401 | void AliRun::Build() | |
402 | { | |
403 | // | |
404 | // Initialize Alice geometry | |
405 | // Dummy routine | |
406 | // | |
407 | } | |
408 | ||
409 | //_____________________________________________________________________________ | |
410 | void AliRun::BuildSimpleGeometry() | |
411 | { | |
412 | // | |
413 | // Create a simple TNode geometry used by Root display engine | |
414 | // | |
415 | // Initialise geometry | |
416 | // | |
417 | fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits"); | |
418 | new TMaterial("void","Vacuum",0,0,0); //Everything is void | |
419 | TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000); | |
420 | brik->SetVisibility(0); | |
421 | new TNode("alice","alice","S_alice"); | |
422 | } | |
423 | ||
424 | //_____________________________________________________________________________ | |
425 | void AliRun::CleanDetectors() | |
426 | { | |
427 | // | |
428 | // Clean Detectors at the end of event | |
429 | // | |
430 | TIter next(fModules); | |
431 | AliModule *detector; | |
432 | while((detector = (AliModule*)next())) { | |
433 | detector->FinishEvent(); | |
434 | } | |
435 | } | |
436 | ||
437 | //_____________________________________________________________________________ | |
438 | void AliRun::CleanParents() | |
439 | { | |
440 | // | |
441 | // Clean Particles stack. | |
442 | // Set parent/daughter relations | |
443 | // | |
444 | TObjArray &particles = *fParticleMap; | |
445 | TParticle *part; | |
446 | int i; | |
447 | for(i=0; i<fHgwmk+1; i++) { | |
448 | part = (TParticle *)particles.At(i); | |
449 | if(part) if(!part->TestBit(kDaughtersBit)) { | |
450 | part->SetFirstDaughter(-1); | |
451 | part->SetLastDaughter(-1); | |
452 | } | |
453 | } | |
454 | } | |
455 | ||
456 | //_____________________________________________________________________________ | |
457 | Int_t AliRun::DistancetoPrimitive(Int_t, Int_t) | |
458 | { | |
459 | // | |
460 | // Return the distance from the mouse to the AliRun object | |
461 | // Dummy routine | |
462 | // | |
463 | return 9999; | |
464 | } | |
465 | ||
466 | //_____________________________________________________________________________ | |
467 | void AliRun::DumpPart (Int_t i) const | |
468 | { | |
469 | // | |
470 | // Dumps particle i in the stack | |
471 | // | |
472 | ((TParticle*) (*fParticleMap)[i])->Print(); | |
473 | } | |
474 | ||
475 | //_____________________________________________________________________________ | |
476 | void AliRun::DumpPStack () const | |
477 | { | |
478 | // | |
479 | // Dumps the particle stack | |
480 | // | |
481 | TObjArray &particles = *fParticleMap; | |
482 | printf( | |
483 | "\n\n=======================================================================\n"); | |
484 | for (Int_t i=0;i<fNtrack;i++) | |
485 | { | |
486 | printf("-> %d ",i); ((TParticle*) particles[i])->Print(); | |
487 | printf("--------------------------------------------------------------\n"); | |
488 | } | |
489 | printf( | |
490 | "\n=======================================================================\n\n"); | |
491 | } | |
492 | ||
493 | void AliRun::SetField(AliMagF* magField) | |
494 | { | |
495 | // Set Magnetic Field Map | |
496 | fField = magField; | |
497 | fField->ReadField(); | |
498 | } | |
499 | ||
500 | //_____________________________________________________________________________ | |
501 | void AliRun::SetField(Int_t type, Int_t version, Float_t scale, | |
502 | Float_t maxField, char* filename) | |
503 | { | |
504 | // | |
505 | // Set magnetic field parameters | |
506 | // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta | |
507 | // version Magnetic field map version (only 1 active now) | |
508 | // scale Scale factor for the magnetic field | |
509 | // maxField Maximum value for the magnetic field | |
510 | ||
511 | // | |
512 | // --- Sanity check on mag field flags | |
513 | if(fField) delete fField; | |
514 | if(version==1) { | |
515 | fField = new AliMagFC("Map1"," ",type,scale,maxField); | |
516 | } else if(version<=2) { | |
517 | fField = new AliMagFCM("Map2-3",filename,type,scale,maxField); | |
518 | fField->ReadField(); | |
519 | } else if(version==3) { | |
520 | fField = new AliMagFDM("Map4",filename,type,scale,maxField); | |
521 | fField->ReadField(); | |
522 | } else { | |
523 | Warning("SetField","Invalid map %d\n",version); | |
524 | } | |
525 | } | |
526 | ||
527 | //_____________________________________________________________________________ | |
528 | void AliRun::PreTrack() | |
529 | { | |
530 | TObjArray &dets = *fModules; | |
531 | AliModule *module; | |
532 | ||
533 | for(Int_t i=0; i<=fNdets; i++) | |
534 | if((module = (AliModule*)dets[i])) | |
535 | module->PreTrack(); | |
536 | ||
537 | fMCQA->PreTrack(); | |
538 | } | |
539 | ||
540 | //_____________________________________________________________________________ | |
541 | void AliRun::PostTrack() | |
542 | { | |
543 | TObjArray &dets = *fModules; | |
544 | AliModule *module; | |
545 | ||
546 | for(Int_t i=0; i<=fNdets; i++) | |
547 | if((module = (AliModule*)dets[i])) | |
548 | module->PostTrack(); | |
549 | } | |
550 | ||
551 | //_____________________________________________________________________________ | |
552 | void AliRun::FinishPrimary() | |
553 | { | |
554 | // | |
555 | // Called at the end of each primary track | |
556 | // | |
557 | ||
558 | // static Int_t count=0; | |
559 | // const Int_t times=10; | |
560 | // This primary is finished, purify stack | |
561 | PurifyKine(); | |
562 | ||
563 | TIter next(fModules); | |
564 | AliModule *detector; | |
565 | while((detector = (AliModule*)next())) { | |
566 | detector->FinishPrimary(); | |
567 | } | |
568 | ||
569 | // Write out hits if any | |
570 | if (gAlice->TreeH()) { | |
571 | gAlice->TreeH()->Fill(); | |
572 | } | |
573 | ||
574 | // Reset Hits info | |
575 | gAlice->ResetHits(); | |
576 | ||
577 | // | |
578 | // if(++count%times==1) gObjectTable->Print(); | |
579 | } | |
580 | ||
581 | //_____________________________________________________________________________ | |
582 | void AliRun::FinishEvent() | |
583 | { | |
584 | // | |
585 | // Called at the end of the event. | |
586 | // | |
587 | ||
588 | // | |
589 | if(fLego) fLego->FinishEvent(); | |
590 | ||
591 | //Update the energy deposit tables | |
592 | Int_t i; | |
593 | for(i=0;i<fEventEnergy.GetSize();i++) { | |
594 | fSummEnergy[i]+=fEventEnergy[i]; | |
595 | fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i]; | |
596 | } | |
597 | fEventEnergy.Reset(); | |
598 | ||
599 | // Clean detector information | |
600 | CleanDetectors(); | |
601 | ||
602 | // Write out the kinematics | |
603 | if (fTreeK) { | |
604 | CleanParents(); | |
605 | if(fTreeK->GetEntries() ==0) { | |
606 | // set the fParticleFileMap size for the first time | |
607 | if (fHgwmk+1 > fParticleFileMap.GetSize()) | |
608 | fParticleFileMap.Set(fHgwmk+1); | |
609 | } | |
610 | // fTreeK->Fill(); | |
611 | Bool_t allFilled = kFALSE; | |
612 | TObject *part; | |
613 | for(i=0; i<fHgwmk+1; ++i) if((part=fParticleMap->At(i))) { | |
614 | fParticleBuffer = (TParticle*) part; | |
615 | fParticleFileMap[i]= (Int_t) fTreeK->GetEntries(); | |
616 | fTreeK->Fill(); | |
617 | (*fParticleMap)[i]=0; | |
618 | ||
619 | // When all primaries were filled no particle!=0 | |
620 | // should be left => to be removed later. | |
621 | if (allFilled) printf("Why != 0 part # %d?\n",i); | |
622 | } | |
623 | else { | |
624 | // // printf("Why = 0 part # %d?\n",i); => We know. | |
625 | // break; | |
626 | // we don't break now in order to be sure there is no | |
627 | // particle !=0 left. | |
628 | // To be removed later and replaced with break. | |
629 | if(!allFilled) allFilled = kTRUE; | |
630 | } | |
631 | } | |
632 | ||
633 | // Set number of tracks to event header | |
634 | fHeader.SetNtrack(fNtrack); | |
635 | ||
636 | // Write out the digits | |
637 | if (fTreeD) { | |
638 | fTreeD->Fill(); | |
639 | ResetDigits(); | |
640 | } | |
641 | ||
642 | if (fTreeS) { | |
643 | fTreeS->Fill(); | |
644 | ResetSDigits(); | |
645 | } | |
646 | ||
647 | // Write out reconstructed clusters | |
648 | if (fTreeR) { | |
649 | fTreeR->Fill(); | |
650 | } | |
651 | ||
652 | // Write out the event Header information | |
653 | if (fTreeE) fTreeE->Fill(); | |
654 | ||
655 | // Reset stack info | |
656 | ResetStack(); | |
657 | ||
658 | // Write Tree headers | |
659 | if (fTreeK) fTreeK->Write(0,TObject::kOverwrite); | |
660 | if (fTreeH) fTreeH->Write(0,TObject::kOverwrite); | |
661 | if (fTreeD) fTreeD->Write(0,TObject::kOverwrite); | |
662 | if (fTreeR) fTreeR->Write(0,TObject::kOverwrite); | |
663 | if (fTreeS) fTreeS->Write(0,TObject::kOverwrite); | |
664 | ||
665 | ++fEvent; | |
666 | } | |
667 | ||
668 | //_____________________________________________________________________________ | |
669 | void AliRun::FinishRun() | |
670 | { | |
671 | // | |
672 | // Called at the end of the run. | |
673 | // | |
674 | ||
675 | // | |
676 | if(fLego) fLego->FinishRun(); | |
677 | ||
678 | // Clean detector information | |
679 | TIter next(fModules); | |
680 | AliModule *detector; | |
681 | while((detector = (AliModule*)next())) { | |
682 | detector->FinishRun(); | |
683 | } | |
684 | ||
685 | //Output energy summary tables | |
686 | EnergySummary(); | |
687 | ||
688 | TFile *file = fTreeE->GetCurrentFile(); | |
689 | ||
690 | file->cd(); | |
691 | ||
692 | fTreeE->Write(0,TObject::kOverwrite); | |
693 | ||
694 | // Write AliRun info and all detectors parameters | |
695 | Write(0,TObject::kOverwrite); | |
696 | ||
697 | // Clean tree information | |
698 | if (fTreeK) { | |
699 | delete fTreeK; fTreeK = 0; | |
700 | } | |
701 | if (fTreeH) { | |
702 | delete fTreeH; fTreeH = 0; | |
703 | } | |
704 | if (fTreeD) { | |
705 | delete fTreeD; fTreeD = 0; | |
706 | } | |
707 | if (fTreeR) { | |
708 | delete fTreeR; fTreeR = 0; | |
709 | } | |
710 | if (fTreeE) { | |
711 | delete fTreeE; fTreeE = 0; | |
712 | } | |
713 | ||
714 | // Close output file | |
715 | file->Write(); | |
716 | } | |
717 | ||
718 | //_____________________________________________________________________________ | |
719 | void AliRun::FlagTrack(Int_t track) | |
720 | { | |
721 | // | |
722 | // Flags a track and all its family tree to be kept | |
723 | // | |
724 | int curr; | |
725 | TParticle *particle; | |
726 | ||
727 | curr=track; | |
728 | while(1) { | |
729 | particle=(TParticle*)fParticleMap->At(curr); | |
730 | ||
731 | // If the particle is flagged the three from here upward is saved already | |
732 | if(particle->TestBit(kKeepBit)) return; | |
733 | ||
734 | // Save this particle | |
735 | particle->SetBit(kKeepBit); | |
736 | ||
737 | // Move to father if any | |
738 | if((curr=particle->GetFirstMother())==-1) return; | |
739 | } | |
740 | } | |
741 | ||
742 | //_____________________________________________________________________________ | |
743 | void AliRun::EnergySummary() | |
744 | { | |
745 | // | |
746 | // Print summary of deposited energy | |
747 | // | |
748 | ||
749 | Int_t ndep=0; | |
750 | Float_t edtot=0; | |
751 | Float_t ed, ed2; | |
752 | Int_t kn, i, left, j, id; | |
753 | const Float_t kzero=0; | |
754 | Int_t ievent=fHeader.GetEvent()+1; | |
755 | // | |
756 | // Energy loss information | |
757 | if(ievent) { | |
758 | printf("***************** Energy Loss Information per event (GEV) *****************\n"); | |
759 | for(kn=1;kn<fEventEnergy.GetSize();kn++) { | |
760 | ed=fSummEnergy[kn]; | |
761 | if(ed>0) { | |
762 | fEventEnergy[ndep]=kn; | |
763 | if(ievent>1) { | |
764 | ed=ed/ievent; | |
765 | ed2=fSum2Energy[kn]; | |
766 | ed2=ed2/ievent; | |
767 | ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,kzero))/ed; | |
768 | } else | |
769 | ed2=99; | |
770 | fSummEnergy[ndep]=ed; | |
771 | fSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,kzero)); | |
772 | edtot+=ed; | |
773 | ndep++; | |
774 | } | |
775 | } | |
776 | for(kn=0;kn<(ndep-1)/3+1;kn++) { | |
777 | left=ndep-kn*3; | |
778 | for(i=0;i<(3<left?3:left);i++) { | |
779 | j=kn*3+i; | |
780 | id=Int_t (fEventEnergy[j]+0.1); | |
781 | printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]); | |
782 | } | |
783 | printf("\n"); | |
784 | } | |
785 | // | |
786 | // Relative energy loss in different detectors | |
787 | printf("******************** Relative Energy Loss per event ********************\n"); | |
788 | printf("Total energy loss per event %10.3f GeV\n",edtot); | |
789 | for(kn=0;kn<(ndep-1)/5+1;kn++) { | |
790 | left=ndep-kn*5; | |
791 | for(i=0;i<(5<left?5:left);i++) { | |
792 | j=kn*5+i; | |
793 | id=Int_t (fEventEnergy[j]+0.1); | |
794 | printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot); | |
795 | } | |
796 | printf("\n"); | |
797 | } | |
798 | for(kn=0;kn<75;kn++) printf("*"); | |
799 | printf("\n"); | |
800 | } | |
801 | // | |
802 | // Reset the TArray's | |
803 | // fEventEnergy.Set(0); | |
804 | // fSummEnergy.Set(0); | |
805 | // fSum2Energy.Set(0); | |
806 | } | |
807 | ||
808 | //_____________________________________________________________________________ | |
809 | AliModule *AliRun::GetModule(const char *name) const | |
810 | { | |
811 | // | |
812 | // Return pointer to detector from name | |
813 | // | |
814 | return (AliModule*)fModules->FindObject(name); | |
815 | } | |
816 | ||
817 | //_____________________________________________________________________________ | |
818 | AliDetector *AliRun::GetDetector(const char *name) const | |
819 | { | |
820 | // | |
821 | // Return pointer to detector from name | |
822 | // | |
823 | return (AliDetector*)fModules->FindObject(name); | |
824 | } | |
825 | ||
826 | //_____________________________________________________________________________ | |
827 | Int_t AliRun::GetModuleID(const char *name) const | |
828 | { | |
829 | // | |
830 | // Return galice internal detector identifier from name | |
831 | // | |
832 | Int_t i=-1; | |
833 | TObject *mod=fModules->FindObject(name); | |
834 | if(mod) i=fModules->IndexOf(mod); | |
835 | return i; | |
836 | } | |
837 | ||
838 | //_____________________________________________________________________________ | |
839 | Int_t AliRun::GetEvent(Int_t event) | |
840 | { | |
841 | // | |
842 | // Connect the Trees Kinematics and Hits for event # event | |
843 | // Set branch addresses | |
844 | // | |
845 | ||
846 | // Reset existing structures | |
847 | // ResetStack(); | |
848 | ResetHits(); | |
849 | ResetDigits(); | |
850 | ResetSDigits(); | |
851 | ||
852 | // Delete Trees already connected | |
853 | if (fTreeK) delete fTreeK; | |
854 | if (fTreeH) delete fTreeH; | |
855 | if (fTreeD) delete fTreeD; | |
856 | if (fTreeR) delete fTreeR; | |
857 | if (fTreeS) delete fTreeS; | |
858 | ||
859 | // Get header from file | |
860 | if(fTreeE) fTreeE->GetEntry(event); | |
861 | else Error("GetEvent","Cannot file Header Tree\n"); | |
862 | TFile *file = fTreeE->GetCurrentFile(); | |
863 | ||
864 | file->cd(); | |
865 | ||
866 | // Get Kine Tree from file | |
867 | char treeName[20]; | |
868 | sprintf(treeName,"TreeK%d",event); | |
869 | fTreeK = (TTree*)gDirectory->Get(treeName); | |
870 | if (fTreeK) fTreeK->SetBranchAddress("Particles", &fParticleBuffer); | |
871 | else Error("GetEvent","cannot find Kine Tree for event:%d\n",event); | |
872 | // Create the particle stack | |
873 | if(!fParticles) fParticles = new TClonesArray("TParticle",1000); | |
874 | // Build the pointer list | |
875 | if(fParticleMap) { | |
876 | fParticleMap->Clear(); | |
877 | fParticleMap->Expand(fTreeK->GetEntries()); | |
878 | } else | |
879 | fParticleMap = new TObjArray(fTreeK->GetEntries()); | |
880 | ||
881 | file->cd(); | |
882 | ||
883 | // Get Hits Tree header from file | |
884 | sprintf(treeName,"TreeH%d",event); | |
885 | fTreeH = (TTree*)gDirectory->Get(treeName); | |
886 | if (!fTreeH) { | |
887 | Error("GetEvent","cannot find Hits Tree for event:%d\n",event); | |
888 | } | |
889 | ||
890 | file->cd(); | |
891 | ||
892 | // Get Digits Tree header from file | |
893 | sprintf(treeName,"TreeD%d",event); | |
894 | fTreeD = (TTree*)gDirectory->Get(treeName); | |
895 | if (!fTreeD) { | |
896 | // Warning("GetEvent","cannot find Digits Tree for event:%d\n",event); | |
897 | } | |
898 | ||
899 | file->cd(); | |
900 | ||
901 | // Get SDigits Tree header from file | |
902 | sprintf(treeName,"TreeS%d",event); | |
903 | fTreeS = (TTree*)gDirectory->Get(treeName); | |
904 | if (!fTreeS) { | |
905 | // Warning("GetEvent","cannot find SDigits Tree for event:%d\n",event); | |
906 | } | |
907 | ||
908 | file->cd(); | |
909 | ||
910 | // Get Reconstruct Tree header from file | |
911 | sprintf(treeName,"TreeR%d",event); | |
912 | fTreeR = (TTree*)gDirectory->Get(treeName); | |
913 | if (!fTreeR) { | |
914 | // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event); | |
915 | } | |
916 | ||
917 | file->cd(); | |
918 | ||
919 | // Set Trees branch addresses | |
920 | TIter next(fModules); | |
921 | AliModule *detector; | |
922 | while((detector = (AliModule*)next())) { | |
923 | detector->SetTreeAddress(); | |
924 | } | |
925 | ||
926 | fNtrack = Int_t (fTreeK->GetEntries()); | |
927 | return fNtrack; | |
928 | } | |
929 | ||
930 | //_____________________________________________________________________________ | |
931 | TGeometry *AliRun::GetGeometry() | |
932 | { | |
933 | // | |
934 | // Import Alice geometry from current file | |
935 | // Return pointer to geometry object | |
936 | // | |
937 | if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom"); | |
938 | // | |
939 | // Unlink and relink nodes in detectors | |
940 | // This is bad and there must be a better way... | |
941 | // | |
942 | ||
943 | TIter next(fModules); | |
944 | AliModule *detector; | |
945 | while((detector = (AliModule*)next())) { | |
946 | TList *dnodes=detector->Nodes(); | |
947 | Int_t j; | |
948 | TNode *node, *node1; | |
949 | for ( j=0; j<dnodes->GetSize(); j++) { | |
950 | node = (TNode*) dnodes->At(j); | |
951 | node1 = fGeometry->GetNode(node->GetName()); | |
952 | dnodes->Remove(node); | |
953 | dnodes->AddAt(node1,j); | |
954 | } | |
955 | } | |
956 | return fGeometry; | |
957 | } | |
958 | ||
959 | //_____________________________________________________________________________ | |
960 | void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom, | |
961 | Float_t &e, Float_t *vpos, Float_t *polar, | |
962 | Float_t &tof) | |
963 | { | |
964 | // | |
965 | // Return next track from stack of particles | |
966 | // | |
967 | TVector3 pol; | |
968 | fCurrent=-1; | |
969 | TParticle *track; | |
970 | for(Int_t i=fNtrack-1; i>=0; i--) { | |
971 | track=(TParticle*) fParticleMap->At(i); | |
972 | if(track) if(!track->TestBit(kDoneBit)) { | |
973 | // | |
974 | // The track exists and has not yet been processed | |
975 | fCurrent=i; | |
976 | ipart=track->GetPdgCode(); | |
977 | pmom[0]=track->Px(); | |
978 | pmom[1]=track->Py(); | |
979 | pmom[2]=track->Pz(); | |
980 | e =track->Energy(); | |
981 | vpos[0]=track->Vx(); | |
982 | vpos[1]=track->Vy(); | |
983 | vpos[2]=track->Vz(); | |
984 | track->GetPolarisation(pol); | |
985 | polar[0]=pol.X(); | |
986 | polar[1]=pol.Y(); | |
987 | polar[2]=pol.Z(); | |
988 | tof=track->T(); | |
989 | track->SetBit(kDoneBit); | |
990 | break; | |
991 | } | |
992 | } | |
993 | mtrack=fCurrent; | |
994 | // | |
995 | // stop and start timer when we start a primary track | |
996 | Int_t nprimaries = fHeader.GetNprimary(); | |
997 | if (fCurrent >= nprimaries) return; | |
998 | if (fCurrent < nprimaries-1) { | |
999 | fTimer.Stop(); | |
1000 | track=(TParticle*) fParticleMap->At(fCurrent+1); | |
1001 | // track->SetProcessTime(fTimer.CpuTime()); | |
1002 | } | |
1003 | fTimer.Start(); | |
1004 | } | |
1005 | ||
1006 | //_____________________________________________________________________________ | |
1007 | Int_t AliRun::GetPrimary(Int_t track) const | |
1008 | { | |
1009 | // | |
1010 | // return number of primary that has generated track | |
1011 | // | |
1012 | int current, parent; | |
1013 | TParticle *part; | |
1014 | // | |
1015 | parent=track; | |
1016 | while (1) { | |
1017 | current=parent; | |
1018 | part = (TParticle *)fParticleMap->At(current); | |
1019 | parent=part->GetFirstMother(); | |
1020 | if(parent<0) return current; | |
1021 | } | |
1022 | } | |
1023 | ||
1024 | //_____________________________________________________________________________ | |
1025 | void AliRun::InitMC(const char *setup) | |
1026 | { | |
1027 | // | |
1028 | // Initialize the Alice setup | |
1029 | // | |
1030 | ||
1031 | if(fInitDone) { | |
1032 | Warning("Init","Cannot initialise AliRun twice!\n"); | |
1033 | return; | |
1034 | } | |
1035 | ||
1036 | gROOT->LoadMacro(setup); | |
1037 | gInterpreter->ProcessLine(fConfigFunction.Data()); | |
1038 | ||
1039 | ||
1040 | gMC->DefineParticles(); //Create standard MC particles | |
1041 | ||
1042 | TObject *objfirst, *objlast; | |
1043 | ||
1044 | fNdets = fModules->GetLast()+1; | |
1045 | ||
1046 | // | |
1047 | //=================Create Materials and geometry | |
1048 | gMC->Init(); | |
1049 | ||
1050 | // Added also after in case of interactive initialisation of modules | |
1051 | fNdets = fModules->GetLast()+1; | |
1052 | ||
1053 | TIter next(fModules); | |
1054 | AliModule *detector; | |
1055 | while((detector = (AliModule*)next())) { | |
1056 | detector->SetTreeAddress(); | |
1057 | objlast = gDirectory->GetList()->Last(); | |
1058 | ||
1059 | // Add Detector histograms in Detector list of histograms | |
1060 | if (objlast) objfirst = gDirectory->GetList()->After(objlast); | |
1061 | else objfirst = gDirectory->GetList()->First(); | |
1062 | while (objfirst) { | |
1063 | detector->Histograms()->Add(objfirst); | |
1064 | objfirst = gDirectory->GetList()->After(objfirst); | |
1065 | } | |
1066 | } | |
1067 | ReadTransPar(); //Read the cuts for all materials | |
1068 | ||
1069 | MediaTable(); //Build the special IMEDIA table | |
1070 | ||
1071 | //Initialise geometry deposition table | |
1072 | fEventEnergy.Set(gMC->NofVolumes()+1); | |
1073 | fSummEnergy.Set(gMC->NofVolumes()+1); | |
1074 | fSum2Energy.Set(gMC->NofVolumes()+1); | |
1075 | ||
1076 | //Compute cross-sections | |
1077 | gMC->BuildPhysics(); | |
1078 | ||
1079 | //Write Geometry object to current file. | |
1080 | fGeometry->Write(); | |
1081 | ||
1082 | fInitDone = kTRUE; | |
1083 | ||
1084 | fMCQA = new AliMCQA(fNdets); | |
1085 | ||
1086 | // | |
1087 | // Save stuff at the beginning of the file to avoid file corruption | |
1088 | Write(); | |
1089 | } | |
1090 | ||
1091 | //_____________________________________________________________________________ | |
1092 | void AliRun::MediaTable() | |
1093 | { | |
1094 | // | |
1095 | // Built media table to get from the media number to | |
1096 | // the detector id | |
1097 | // | |
1098 | Int_t kz, nz, idt, lz, i, k, ind; | |
1099 | // Int_t ibeg; | |
1100 | TObjArray &dets = *gAlice->Detectors(); | |
1101 | AliModule *det; | |
1102 | // | |
1103 | // For all detectors | |
1104 | for (kz=0;kz<fNdets;kz++) { | |
1105 | // If detector is defined | |
1106 | if((det=(AliModule*) dets[kz])) { | |
1107 | TArrayI &idtmed = *(det->GetIdtmed()); | |
1108 | for(nz=0;nz<100;nz++) { | |
1109 | // Find max and min material number | |
1110 | if((idt=idtmed[nz])) { | |
1111 | det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt; | |
1112 | det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt; | |
1113 | } | |
1114 | } | |
1115 | if(det->LoMedium() > det->HiMedium()) { | |
1116 | det->LoMedium() = 0; | |
1117 | det->HiMedium() = 0; | |
1118 | } else { | |
1119 | if(det->HiMedium() > fImedia->GetSize()) { | |
1120 | Error("MediaTable","Increase fImedia from %d to %d", | |
1121 | fImedia->GetSize(),det->HiMedium()); | |
1122 | return; | |
1123 | } | |
1124 | // Tag all materials in rage as belonging to detector kz | |
1125 | for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) { | |
1126 | (*fImedia)[lz]=kz; | |
1127 | } | |
1128 | } | |
1129 | } | |
1130 | } | |
1131 | // | |
1132 | // Print summary table | |
1133 | printf(" Traking media ranges:\n"); | |
1134 | for(i=0;i<(fNdets-1)/6+1;i++) { | |
1135 | for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) { | |
1136 | ind=i*6+k; | |
1137 | det=(AliModule*)dets[ind]; | |
1138 | if(det) | |
1139 | printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(), | |
1140 | det->HiMedium()); | |
1141 | else | |
1142 | printf(" %6s: %3d -> %3d;","NULL",0,0); | |
1143 | } | |
1144 | printf("\n"); | |
1145 | } | |
1146 | } | |
1147 | ||
1148 | //____________________________________________________________________________ | |
1149 | void AliRun::SetGenerator(AliGenerator *generator) | |
1150 | { | |
1151 | // | |
1152 | // Load the event generator | |
1153 | // | |
1154 | if(!fGenerator) fGenerator = generator; | |
1155 | } | |
1156 | ||
1157 | //____________________________________________________________________________ | |
1158 | void AliRun::ResetGenerator(AliGenerator *generator) | |
1159 | { | |
1160 | // | |
1161 | // Load the event generator | |
1162 | // | |
1163 | if(fGenerator) | |
1164 | if(generator) | |
1165 | Warning("ResetGenerator","Replacing generator %s with %s\n", | |
1166 | fGenerator->GetName(),generator->GetName()); | |
1167 | else | |
1168 | Warning("ResetGenerator","Replacing generator %s with NULL\n", | |
1169 | fGenerator->GetName()); | |
1170 | fGenerator = generator; | |
1171 | } | |
1172 | ||
1173 | //____________________________________________________________________________ | |
1174 | void AliRun::SetTransPar(char *filename) | |
1175 | { | |
1176 | fTransParName = filename; | |
1177 | } | |
1178 | ||
1179 | //____________________________________________________________________________ | |
1180 | void AliRun::SetBaseFile(char *filename) | |
1181 | { | |
1182 | fBaseFileName = filename; | |
1183 | } | |
1184 | ||
1185 | //____________________________________________________________________________ | |
1186 | void AliRun::ReadTransPar() | |
1187 | { | |
1188 | // | |
1189 | // Read filename to set the transport parameters | |
1190 | // | |
1191 | ||
1192 | ||
1193 | const Int_t kncuts=10; | |
1194 | const Int_t knflags=11; | |
1195 | const Int_t knpars=kncuts+knflags; | |
1196 | const char kpars[knpars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO", | |
1197 | "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI", | |
1198 | "BREM","COMP","DCAY","DRAY","HADR","LOSS", | |
1199 | "MULS","PAIR","PHOT","RAYL"}; | |
1200 | char line[256]; | |
1201 | char detName[7]; | |
1202 | char* filtmp; | |
1203 | Float_t cut[kncuts]; | |
1204 | Int_t flag[knflags]; | |
1205 | Int_t i, itmed, iret, ktmed, kz; | |
1206 | FILE *lun; | |
1207 | // | |
1208 | // See whether the file is there | |
1209 | filtmp=gSystem->ExpandPathName(fTransParName.Data()); | |
1210 | lun=fopen(filtmp,"r"); | |
1211 | delete [] filtmp; | |
1212 | if(!lun) { | |
1213 | Warning("ReadTransPar","File %s does not exist!\n",fTransParName.Data()); | |
1214 | return; | |
1215 | } | |
1216 | // | |
1217 | printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n"); | |
1218 | printf(" *%59s\n","*"); | |
1219 | printf(" * Please check carefully what you are doing!%10s\n","*"); | |
1220 | printf(" *%59s\n","*"); | |
1221 | // | |
1222 | while(1) { | |
1223 | // Initialise cuts and flags | |
1224 | for(i=0;i<kncuts;i++) cut[i]=-99; | |
1225 | for(i=0;i<knflags;i++) flag[i]=-99; | |
1226 | itmed=0; | |
1227 | for(i=0;i<256;i++) line[i]='\0'; | |
1228 | // Read up to the end of line excluded | |
1229 | iret=fscanf(lun,"%[^\n]",line); | |
1230 | if(iret<0) { | |
1231 | //End of file | |
1232 | fclose(lun); | |
1233 | printf(" *%59s\n","*"); | |
1234 | printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n"); | |
1235 | return; | |
1236 | } | |
1237 | // Read the end of line | |
1238 | fscanf(lun,"%*c"); | |
1239 | if(!iret) continue; | |
1240 | if(line[0]=='*') continue; | |
1241 | // Read the numbers | |
1242 | 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", | |
1243 | detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8], | |
1244 | &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7], | |
1245 | &flag[8],&flag[9],&flag[10]); | |
1246 | if(!iret) continue; | |
1247 | if(iret<0) { | |
1248 | //reading error | |
1249 | Warning("ReadTransPar","Error reading file %s\n",fTransParName.Data()); | |
1250 | continue; | |
1251 | } | |
1252 | // Check that the module exist | |
1253 | AliModule *mod = GetModule(detName); | |
1254 | if(mod) { | |
1255 | // Get the array of media numbers | |
1256 | TArrayI &idtmed = *mod->GetIdtmed(); | |
1257 | // Check that the tracking medium code is valid | |
1258 | if(0<=itmed && itmed < 100) { | |
1259 | ktmed=idtmed[itmed]; | |
1260 | if(!ktmed) { | |
1261 | Warning("ReadTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName()); | |
1262 | continue; | |
1263 | } | |
1264 | // Set energy thresholds | |
1265 | for(kz=0;kz<kncuts;kz++) { | |
1266 | if(cut[kz]>=0) { | |
1267 | printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n", | |
1268 | kpars[kz],cut[kz],itmed,mod->GetName()); | |
1269 | gMC->Gstpar(ktmed,kpars[kz],cut[kz]); | |
1270 | } | |
1271 | } | |
1272 | // Set transport mechanisms | |
1273 | for(kz=0;kz<knflags;kz++) { | |
1274 | if(flag[kz]>=0) { | |
1275 | printf(" * %-6s set to %10d for tracking medium code %4d for %s\n", | |
1276 | kpars[kncuts+kz],flag[kz],itmed,mod->GetName()); | |
1277 | gMC->Gstpar(ktmed,kpars[kncuts+kz],Float_t(flag[kz])); | |
1278 | } | |
1279 | } | |
1280 | } else { | |
1281 | Warning("ReadTransPar","Invalid medium code %d *\n",itmed); | |
1282 | continue; | |
1283 | } | |
1284 | } else { | |
1285 | Warning("ReadTransPar","Module %s not present\n",detName); | |
1286 | continue; | |
1287 | } | |
1288 | } | |
1289 | } | |
1290 | ||
1291 | //_____________________________________________________________________________ | |
1292 | void AliRun::MakeBranchInTree(TTree *tree, const char* name, void* address, Int_t size, char *file) | |
1293 | { | |
1294 | // | |
1295 | // Makes branch in given tree and diverts them to a separate file | |
1296 | // | |
1297 | if (GetDebug()>1) | |
1298 | printf("* MakeBranch * Making Branch %s \n",name); | |
1299 | ||
1300 | TBranch *branch = tree->Branch(name,address,size); | |
1301 | ||
1302 | if (file) { | |
1303 | char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2]; | |
1304 | sprintf(outFile,"%s/%s",gAlice->GetBaseFile(),file); | |
1305 | TDirectory *cwd = gDirectory; | |
1306 | branch->SetFile(outFile); | |
1307 | TIter next( branch->GetListOfBranches()); | |
1308 | while ((branch=(TBranch*)next())) { | |
1309 | branch->SetFile(outFile); | |
1310 | } | |
1311 | if (GetDebug()>1) | |
1312 | printf("* MakeBranch * Diverting Branch %s to file %s\n",name,file); | |
1313 | cwd->cd(); | |
1314 | delete outFile; | |
1315 | } | |
1316 | } | |
1317 | ||
1318 | //_____________________________________________________________________________ | |
1319 | void AliRun::MakeBranchInTree(TTree *tree, const char* name, const char *classname, void* address, Int_t size, Int_t splitlevel, char *file) | |
1320 | { | |
1321 | // | |
1322 | // Makes branch in given tree and diverts them to a separate file | |
1323 | // | |
1324 | TDirectory *cwd = gDirectory; | |
1325 | TBranch *branch = tree->Branch(name,classname,address,size,splitlevel); | |
1326 | if (GetDebug()>1) | |
1327 | printf("* MakeBranch * Making Branch %s \n",name); | |
1328 | if (file) { | |
1329 | char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2]; | |
1330 | sprintf(outFile,"%s/%s",gAlice->GetBaseFile(),file); | |
1331 | branch->SetFile(outFile); | |
1332 | TIter next( branch->GetListOfBranches()); | |
1333 | while ((branch=(TBranch*)next())) { | |
1334 | branch->SetFile(outFile); | |
1335 | } | |
1336 | if (GetDebug()>1) | |
1337 | printf("* MakeBranch * Diverting Branch %s to file %s\n",name,file); | |
1338 | cwd->cd(); | |
1339 | delete outFile; | |
1340 | } | |
1341 | } | |
1342 | //_____________________________________________________________________________ | |
1343 | void AliRun::MakeTree(Option_t *option, char *file) | |
1344 | { | |
1345 | // | |
1346 | // Create the ROOT trees | |
1347 | // Loop on all detectors to create the Root branch (if any) | |
1348 | // | |
1349 | ||
1350 | char hname[30]; | |
1351 | // | |
1352 | // Analyse options | |
1353 | const char *oK = strstr(option,"K"); | |
1354 | const char *oH = strstr(option,"H"); | |
1355 | const char *oE = strstr(option,"E"); | |
1356 | const char *oD = strstr(option,"D"); | |
1357 | const char *oR = strstr(option,"R"); | |
1358 | const char *oS = strstr(option,"S"); | |
1359 | // | |
1360 | ||
1361 | if (oK && !fTreeK) { | |
1362 | sprintf(hname,"TreeK%d",fEvent); | |
1363 | fTreeK = new TTree(hname,"Kinematics"); | |
1364 | // Create a branch for particles | |
1365 | MakeBranchInTree(fTreeK, | |
1366 | "Particles", "TParticle", &fParticleBuffer, 4000, 1, file) ; | |
1367 | fTreeK->Write(); | |
1368 | } | |
1369 | if (oH && !fTreeH) { | |
1370 | sprintf(hname,"TreeH%d",fEvent); | |
1371 | fTreeH = new TTree(hname,"Hits"); | |
1372 | fTreeH->SetAutoSave(1000000000); //no autosave | |
1373 | fTreeH->Write(); | |
1374 | } | |
1375 | if (oD && !fTreeD) { | |
1376 | sprintf(hname,"TreeD%d",fEvent); | |
1377 | fTreeD = new TTree(hname,"Digits"); | |
1378 | fTreeD->Write(); | |
1379 | } | |
1380 | if (oS && !fTreeS) { | |
1381 | sprintf(hname,"TreeS%d",fEvent); | |
1382 | fTreeS = new TTree(hname,"SDigits"); | |
1383 | fTreeS->Write(); | |
1384 | } | |
1385 | if (oR && !fTreeR) { | |
1386 | sprintf(hname,"TreeR%d",fEvent); | |
1387 | fTreeR = new TTree(hname,"Reconstruction"); | |
1388 | fTreeR->Write(); | |
1389 | } | |
1390 | if (oE && !fTreeE) { | |
1391 | fTreeE = new TTree("TE","Header"); | |
1392 | // Create a branch for Header | |
1393 | MakeBranchInTree(fTreeE, | |
1394 | "Header", "AliHeader", &gAliHeader, 4000, 1, file) ; | |
1395 | fTreeE->Write(); | |
1396 | } | |
1397 | ||
1398 | // | |
1399 | // Create a branch for hits/digits for each detector | |
1400 | // Each branch is a TClonesArray. Each data member of the Hits classes | |
1401 | // will be in turn a subbranch of the detector master branch | |
1402 | TIter next(fModules); | |
1403 | AliModule *detector; | |
1404 | while((detector = (AliModule*)next())) { | |
1405 | if (oH) detector->MakeBranch(option,file); | |
1406 | } | |
1407 | } | |
1408 | ||
1409 | //_____________________________________________________________________________ | |
1410 | Int_t AliRun::PurifyKine(Int_t lastSavedTrack, Int_t nofTracks) | |
1411 | { | |
1412 | // | |
1413 | // PurifyKine with external parameters | |
1414 | // | |
1415 | fHgwmk = lastSavedTrack; | |
1416 | fNtrack = nofTracks; | |
1417 | PurifyKine(); | |
1418 | return fHgwmk; | |
1419 | } | |
1420 | ||
1421 | //_____________________________________________________________________________ | |
1422 | TParticle* AliRun::Particle(Int_t i) | |
1423 | { | |
1424 | if(!(*fParticleMap)[i]) { | |
1425 | Int_t nentries = fParticles->GetEntries(); | |
1426 | ||
1427 | // algorithmic way of getting entry index | |
1428 | // (primary particles are filled after secondaries) | |
1429 | Int_t entry; | |
1430 | if (i<fHeader.GetNprimary()) | |
1431 | entry = i+fHeader.GetNsecondary(); | |
1432 | else | |
1433 | entry = i-fHeader.GetNprimary(); | |
1434 | ||
1435 | // only check the algorithmic way and give | |
1436 | // the fatal error if it is wrong | |
1437 | if (entry != fParticleFileMap[i]) { | |
1438 | Fatal("Particle", | |
1439 | "!!!! The algorithmic way is WRONG: !!!\n entry: %d map: %d", | |
1440 | entry, fParticleFileMap[i]); | |
1441 | } | |
1442 | ||
1443 | fTreeK->GetEntry(fParticleFileMap[i]); | |
1444 | new ((*fParticles)[nentries]) TParticle(*fParticleBuffer); | |
1445 | fParticleMap->AddAt((*fParticles)[nentries],i); | |
1446 | } | |
1447 | return (TParticle *) (*fParticleMap)[i]; | |
1448 | } | |
1449 | ||
1450 | //_____________________________________________________________________________ | |
1451 | void AliRun::PurifyKine() | |
1452 | { | |
1453 | // | |
1454 | // Compress kinematic tree keeping only flagged particles | |
1455 | // and renaming the particle id's in all the hits | |
1456 | // | |
1457 | // TClonesArray &particles = *fParticles; | |
1458 | TObjArray &particles = *fParticleMap; | |
1459 | int nkeep=fHgwmk+1, parent, i; | |
1460 | TParticle *part, *father; | |
1461 | TArrayI map(particles.GetLast()+1); | |
1462 | ||
1463 | // Save in Header total number of tracks before compression | |
1464 | fHeader.SetNtrack(fHeader.GetNtrack()+fNtrack-fHgwmk); | |
1465 | ||
1466 | // If no tracks generated return now | |
1467 | if(fHgwmk+1 == fNtrack) return; | |
1468 | ||
1469 | Int_t toshrink = fNtrack-fHgwmk-1; | |
1470 | ||
1471 | // First pass, invalid Daughter information | |
1472 | for(i=0; i<fNtrack; i++) { | |
1473 | // Preset map, to be removed later | |
1474 | if(i<=fHgwmk) map[i]=i ; | |
1475 | else { | |
1476 | map[i] = -99; | |
1477 | // particles.UncheckedAt(i)->ResetBit(kDaughtersBit); | |
1478 | if((part=(TParticle*) particles.At(i))) part->ResetBit(kDaughtersBit); | |
1479 | } | |
1480 | } | |
1481 | // Invalid daughter information for the parent of the first particle | |
1482 | // generated. This may or may not be the current primary according to | |
1483 | // whether decays have been recorded among the primaries | |
1484 | part = (TParticle *)particles.At(fHgwmk+1); | |
1485 | particles.At(part->GetFirstMother())->ResetBit(kDaughtersBit); | |
1486 | // Second pass, build map between old and new numbering | |
1487 | for(i=fHgwmk+1; i<fNtrack; i++) { | |
1488 | if(particles.At(i)->TestBit(kKeepBit)) { | |
1489 | ||
1490 | // This particle has to be kept | |
1491 | map[i]=nkeep; | |
1492 | // If old and new are different, have to move the pointer | |
1493 | if(i!=nkeep) particles[nkeep]=particles.At(i); | |
1494 | part = (TParticle*) particles.At(nkeep); | |
1495 | ||
1496 | // as the parent is always *before*, it must be already | |
1497 | // in place. This is what we are checking anyway! | |
1498 | if((parent=part->GetFirstMother())>fHgwmk) | |
1499 | if(map[parent]==-99) Fatal("PurifyKine","map[%d] = -99!\n",parent); | |
1500 | else part->SetFirstMother(map[parent]); | |
1501 | ||
1502 | nkeep++; | |
1503 | } | |
1504 | } | |
1505 | ||
1506 | // Fix daughters information | |
1507 | for (i=fHgwmk+1; i<nkeep; i++) { | |
1508 | part = (TParticle *)particles.At(i); | |
1509 | parent = part->GetFirstMother(); | |
1510 | if(parent>=0) { | |
1511 | father = (TParticle *)particles.At(parent); | |
1512 | if(father->TestBit(kDaughtersBit)) { | |
1513 | ||
1514 | if(i<father->GetFirstDaughter()) father->SetFirstDaughter(i); | |
1515 | if(i>father->GetLastDaughter()) father->SetLastDaughter(i); | |
1516 | } else { | |
1517 | // Initialise daughters info for first pass | |
1518 | father->SetFirstDaughter(i); | |
1519 | father->SetLastDaughter(i); | |
1520 | father->SetBit(kDaughtersBit); | |
1521 | } | |
1522 | } | |
1523 | } | |
1524 | ||
1525 | // Now loop on all registered hit lists | |
1526 | TIter next(fHitLists); | |
1527 | TCollection *hitList; | |
1528 | while((hitList = (TCollection*)next())) { | |
1529 | TIter nexthit(hitList); | |
1530 | AliHit *hit; | |
1531 | while((hit = (AliHit*)nexthit())) { | |
1532 | hit->SetTrack(map[hit->GetTrack()]); | |
1533 | } | |
1534 | } | |
1535 | ||
1536 | // | |
1537 | // This for detectors which have a special mapping mechanism | |
1538 | // for hits, such as TPC and TRD | |
1539 | // | |
1540 | ||
1541 | TIter nextmod(fModules); | |
1542 | AliModule *detector; | |
1543 | while((detector = (AliModule*)nextmod())) { | |
1544 | detector->RemapTrackHitIDs(map.GetArray()); | |
1545 | } | |
1546 | ||
1547 | // Now the output bit, from fHgwmk to nkeep we write everything and we erase | |
1548 | if(nkeep>fParticleFileMap.GetSize()) fParticleFileMap.Set(Int_t (nkeep*1.5)); | |
1549 | ||
1550 | ||
1551 | for (i=fHgwmk+1; i<nkeep; ++i) { | |
1552 | fParticleBuffer = (TParticle*) particles.At(i); | |
1553 | fParticleFileMap[i]=(Int_t) fTreeK->GetEntries(); | |
1554 | fTreeK->Fill(); | |
1555 | particles[i]=0; | |
1556 | } | |
1557 | ||
1558 | for (i=nkeep; i<fNtrack; ++i) particles[i]=0; | |
1559 | ||
1560 | fLoadPoint-=toshrink; | |
1561 | for(i=fLoadPoint; i<fLoadPoint+toshrink; ++i) fParticles->RemoveAt(i); | |
1562 | ||
1563 | fNtrack=nkeep; | |
1564 | fHgwmk=nkeep-1; | |
1565 | // delete [] map; | |
1566 | } | |
1567 | ||
1568 | //_____________________________________________________________________________ | |
1569 | void AliRun::BeginEvent() | |
1570 | { | |
1571 | // | |
1572 | // Reset all Detectors & kinematics & trees | |
1573 | // | |
1574 | char hname[30]; | |
1575 | // | |
1576 | ||
1577 | // | |
1578 | if(fLego) { | |
1579 | fLego->BeginEvent(); | |
1580 | return; | |
1581 | } | |
1582 | ||
1583 | // | |
1584 | ResetStack(); | |
1585 | ResetHits(); | |
1586 | ResetDigits(); | |
1587 | ResetSDigits(); | |
1588 | ||
1589 | // Initialise event header | |
1590 | fHeader.Reset(fRun,fEvent); | |
1591 | ||
1592 | if(fTreeK) { | |
1593 | fTreeK->Reset(); | |
1594 | sprintf(hname,"TreeK%d",fEvent); | |
1595 | fTreeK->SetName(hname); | |
1596 | } | |
1597 | if(fTreeH) { | |
1598 | fTreeH->Reset(); | |
1599 | sprintf(hname,"TreeH%d",fEvent); | |
1600 | fTreeH->SetName(hname); | |
1601 | } | |
1602 | if(fTreeD) { | |
1603 | fTreeD->Reset(); | |
1604 | sprintf(hname,"TreeD%d",fEvent); | |
1605 | fTreeD->SetName(hname); | |
1606 | } | |
1607 | if(fTreeS) { | |
1608 | fTreeS->Reset(); | |
1609 | sprintf(hname,"TreeS%d",fEvent); | |
1610 | fTreeS->SetName(hname); | |
1611 | } | |
1612 | if(fTreeR) { | |
1613 | fTreeR->Reset(); | |
1614 | sprintf(hname,"TreeR%d",fEvent); | |
1615 | fTreeR->SetName(hname); | |
1616 | } | |
1617 | } | |
1618 | //_____________________________________________________________________________ | |
1619 | void AliRun::ResetDigits() | |
1620 | { | |
1621 | // | |
1622 | // Reset all Detectors digits | |
1623 | // | |
1624 | TIter next(fModules); | |
1625 | AliModule *detector; | |
1626 | while((detector = (AliModule*)next())) { | |
1627 | detector->ResetDigits(); | |
1628 | } | |
1629 | } | |
1630 | ||
1631 | //_____________________________________________________________________________ | |
1632 | void AliRun::ResetSDigits() | |
1633 | { | |
1634 | // | |
1635 | // Reset all Detectors digits | |
1636 | // | |
1637 | TIter next(fModules); | |
1638 | AliModule *detector; | |
1639 | while((detector = (AliModule*)next())) { | |
1640 | detector->ResetSDigits(); | |
1641 | } | |
1642 | } | |
1643 | ||
1644 | //_____________________________________________________________________________ | |
1645 | void AliRun::ResetHits() | |
1646 | { | |
1647 | // | |
1648 | // Reset all Detectors hits | |
1649 | // | |
1650 | TIter next(fModules); | |
1651 | AliModule *detector; | |
1652 | while((detector = (AliModule*)next())) { | |
1653 | detector->ResetHits(); | |
1654 | } | |
1655 | } | |
1656 | ||
1657 | //_____________________________________________________________________________ | |
1658 | void AliRun::ResetPoints() | |
1659 | { | |
1660 | // | |
1661 | // Reset all Detectors points | |
1662 | // | |
1663 | TIter next(fModules); | |
1664 | AliModule *detector; | |
1665 | while((detector = (AliModule*)next())) { | |
1666 | detector->ResetPoints(); | |
1667 | } | |
1668 | } | |
1669 | ||
1670 | //_____________________________________________________________________________ | |
1671 | void AliRun::RunMC(Int_t nevent, const char *setup) | |
1672 | { | |
1673 | // | |
1674 | // Main function to be called to process a galice run | |
1675 | // example | |
1676 | // Root > gAlice.Run(); | |
1677 | // a positive number of events will cause the finish routine | |
1678 | // to be called | |
1679 | // | |
1680 | ||
1681 | // check if initialisation has been done | |
1682 | if (!fInitDone) InitMC(setup); | |
1683 | ||
1684 | // Create the Root Tree with one branch per detector | |
1685 | ||
1686 | MakeTree("ESD"); | |
1687 | ||
1688 | if (gSystem->Getenv("CONFIG_SPLIT_FILE")) { | |
1689 | MakeTree("K","Kine.root"); | |
1690 | MakeTree("H","Hits.root"); | |
1691 | } else { | |
1692 | MakeTree("KH"); | |
1693 | } | |
1694 | ||
1695 | gMC->ProcessRun(nevent); | |
1696 | ||
1697 | // End of this run, close files | |
1698 | if(nevent>0) FinishRun(); | |
1699 | } | |
1700 | ||
1701 | //_____________________________________________________________________________ | |
1702 | void AliRun::RunReco(const char *detector) | |
1703 | { | |
1704 | // | |
1705 | // Main function to be called to reconstruct Alice event | |
1706 | // | |
1707 | ||
1708 | MakeTree("R"); | |
1709 | Digits2Reco(detector); | |
1710 | } | |
1711 | ||
1712 | //_____________________________________________________________________________ | |
1713 | ||
1714 | void AliRun::Hits2Digits(const char *selected) | |
1715 | { | |
1716 | // Convert Hits to sumable digits | |
1717 | // | |
1718 | Hits2SDigits(selected); | |
1719 | SDigits2Digits(selected); | |
1720 | } | |
1721 | ||
1722 | ||
1723 | //_____________________________________________________________________________ | |
1724 | ||
1725 | void AliRun::Tree2Tree(Option_t *option, const char *selected) | |
1726 | { | |
1727 | // | |
1728 | // Function to transform the content of | |
1729 | // | |
1730 | // - TreeH to TreeS (option "S") | |
1731 | // - TreeS to TreeD (option "D") | |
1732 | // - TreeD to TreeR (option "R") | |
1733 | // | |
1734 | // If multiple options are specified ("SDR"), transformation will be done in sequence for | |
1735 | // selected detector and for all detectors if none is selected (detector string | |
1736 | // can contain blank separated list of detector names). | |
1737 | ||
1738 | ||
1739 | const char *oS = strstr(option,"S"); | |
1740 | const char *oD = strstr(option,"D"); | |
1741 | const char *oR = strstr(option,"R"); | |
1742 | ||
1743 | gAlice->GetEvent(0); | |
1744 | ||
1745 | TObjArray *detectors = gAlice->Detectors(); | |
1746 | ||
1747 | TIter next(detectors); | |
1748 | ||
1749 | AliDetector *detector = 0; | |
1750 | ||
1751 | TDirectory *cwd = gDirectory; | |
1752 | ||
1753 | char outFile[32]; | |
1754 | ||
1755 | while((detector = (AliDetector*)next())) { | |
1756 | if (selected) | |
1757 | if (strcmp(detector->GetName(),selected)) continue; | |
1758 | if (detector->IsActive()){ | |
1759 | if (GetDebug()>0) | |
1760 | cout << "Processing " << detector->GetName() << "..." << endl; | |
1761 | if (gSystem->Getenv("CONFIG_SPLIT_FILE")) { | |
1762 | if (oS) { | |
1763 | sprintf(outFile,"SDigits.%s.root",detector->GetName()); | |
1764 | detector->MakeBranch("S",outFile); | |
1765 | } | |
1766 | if (oD) { | |
1767 | sprintf(outFile,"Digits.%s.root",detector->GetName()); | |
1768 | detector->MakeBranch("D",outFile); | |
1769 | } | |
1770 | if (oR) { | |
1771 | sprintf(outFile,"Reco.%s.root",detector->GetName()); | |
1772 | detector->MakeBranch("R",outFile); | |
1773 | } | |
1774 | } else { | |
1775 | detector->MakeBranch(option); | |
1776 | } | |
1777 | ||
1778 | cwd->cd(); | |
1779 | ||
1780 | if (oS) | |
1781 | detector->Hits2SDigits(); | |
1782 | if (oD) | |
1783 | detector->SDigits2Digits(); | |
1784 | if (oR) | |
1785 | detector->Digits2Reco(); | |
1786 | ||
1787 | cwd->cd(); | |
1788 | ||
1789 | } | |
1790 | } | |
1791 | } | |
1792 | ||
1793 | ||
1794 | //_____________________________________________________________________________ | |
1795 | void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min, | |
1796 | Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max, | |
1797 | Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener) | |
1798 | { | |
1799 | // | |
1800 | // Generates lego plots of: | |
1801 | // - radiation length map phi vs theta | |
1802 | // - radiation length map phi vs eta | |
1803 | // - interaction length map | |
1804 | // - g/cm2 length map | |
1805 | // | |
1806 | // ntheta bins in theta, eta | |
1807 | // themin minimum angle in theta (degrees) | |
1808 | // themax maximum angle in theta (degrees) | |
1809 | // nphi bins in phi | |
1810 | // phimin minimum angle in phi (degrees) | |
1811 | // phimax maximum angle in phi (degrees) | |
1812 | // rmin minimum radius | |
1813 | // rmax maximum radius | |
1814 | // | |
1815 | // | |
1816 | // The number of events generated = ntheta*nphi | |
1817 | // run input parameters in macro setup (default="Config.C") | |
1818 | // | |
1819 | // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates | |
1820 | //Begin_Html | |
1821 | /* | |
1822 | <img src="picts/AliRunLego1.gif"> | |
1823 | */ | |
1824 | //End_Html | |
1825 | //Begin_Html | |
1826 | /* | |
1827 | <img src="picts/AliRunLego2.gif"> | |
1828 | */ | |
1829 | //End_Html | |
1830 | //Begin_Html | |
1831 | /* | |
1832 | <img src="picts/AliRunLego3.gif"> | |
1833 | */ | |
1834 | //End_Html | |
1835 | // | |
1836 | ||
1837 | // check if initialisation has been done | |
1838 | if (!fInitDone) InitMC(setup); | |
1839 | //Save current generator | |
1840 | AliGenerator *gen=Generator(); | |
1841 | ||
1842 | // Set new generator | |
1843 | if (!gener) gener = new AliLegoGenerator(); | |
1844 | ResetGenerator(gener); | |
1845 | // | |
1846 | // Configure Generator | |
1847 | gener->SetRadiusRange(rmin, rmax); | |
1848 | gener->SetZMax(zmax); | |
1849 | gener->SetCoor1Range(nc1, c1min, c1max); | |
1850 | gener->SetCoor2Range(nc2, c2min, c2max); | |
1851 | ||
1852 | ||
1853 | //Create Lego object | |
1854 | fLego = new AliLego("lego",gener); | |
1855 | ||
1856 | //Prepare MC for Lego Run | |
1857 | gMC->InitLego(); | |
1858 | ||
1859 | //Run Lego Object | |
1860 | ||
1861 | gMC->ProcessRun(nc1*nc2+1); | |
1862 | ||
1863 | // Create only the Root event Tree | |
1864 | MakeTree("E"); | |
1865 | ||
1866 | // End of this run, close files | |
1867 | FinishRun(); | |
1868 | // Restore current generator | |
1869 | ResetGenerator(gen); | |
1870 | // Delete Lego Object | |
1871 | delete fLego; fLego=0; | |
1872 | } | |
1873 | ||
1874 | //_____________________________________________________________________________ | |
1875 | void AliRun::SetConfigFunction(const char * config) | |
1876 | { | |
1877 | // | |
1878 | // Set the signature of the function contained in Config.C to configure | |
1879 | // the run | |
1880 | // | |
1881 | fConfigFunction=config; | |
1882 | } | |
1883 | ||
1884 | //_____________________________________________________________________________ | |
1885 | void AliRun::SetCurrentTrack(Int_t track) | |
1886 | { | |
1887 | // | |
1888 | // Set current track number | |
1889 | // | |
1890 | fCurrent = track; | |
1891 | } | |
1892 | ||
1893 | //_____________________________________________________________________________ | |
1894 | void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom, | |
1895 | Float_t *vpos, Float_t *polar, Float_t tof, | |
1896 | AliMCProcess mech, Int_t &ntr, Float_t weight) | |
1897 | { | |
1898 | // | |
1899 | // Load a track on the stack | |
1900 | // | |
1901 | // done 0 if the track has to be transported | |
1902 | // 1 if not | |
1903 | // parent identifier of the parent track. -1 for a primary | |
1904 | // pdg particle code | |
1905 | // pmom momentum GeV/c | |
1906 | // vpos position | |
1907 | // polar polarisation | |
1908 | // tof time of flight in seconds | |
1909 | // mecha production mechanism | |
1910 | // ntr on output the number of the track stored | |
1911 | // | |
1912 | TClonesArray &particles = *fParticles; | |
1913 | TParticle *particle; | |
1914 | Float_t mass; | |
1915 | const Int_t kfirstdaughter=-1; | |
1916 | const Int_t klastdaughter=-1; | |
1917 | const Int_t kS=0; | |
1918 | // const Float_t tlife=0; | |
1919 | ||
1920 | // | |
1921 | // Here we get the static mass | |
1922 | // For MC is ok, but a more sophisticated method could be necessary | |
1923 | // if the calculated mass is required | |
1924 | // also, this method is potentially dangerous if the mass | |
1925 | // used in the MC is not the same of the PDG database | |
1926 | // | |
1927 | mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass(); | |
1928 | Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+ | |
1929 | pmom[1]*pmom[1]+pmom[2]*pmom[2]); | |
1930 | ||
1931 | //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", | |
1932 | //pname,mass,e,fNtrack,pdg,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],kS,mecha); | |
1933 | ||
1934 | particle=new(particles[fLoadPoint++]) TParticle(pdg,kS,parent,-1,kfirstdaughter, | |
1935 | klastdaughter,pmom[0],pmom[1],pmom[2], | |
1936 | e,vpos[0],vpos[1],vpos[2],tof); | |
1937 | particle->SetPolarisation(TVector3(polar[0],polar[1],polar[2])); | |
1938 | particle->SetWeight(weight); | |
1939 | particle->SetUniqueID(mech); | |
1940 | if(!done) particle->SetBit(kDoneBit); | |
1941 | // Declare that the daughter information is valid | |
1942 | particle->SetBit(kDaughtersBit); | |
1943 | // Add the particle to the stack | |
1944 | fParticleMap->AddAtAndExpand(particle,fNtrack); | |
1945 | ||
1946 | if(parent>=0) { | |
1947 | particle=(TParticle*) fParticleMap->At(parent); | |
1948 | particle->SetLastDaughter(fNtrack); | |
1949 | if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack); | |
1950 | } else { | |
1951 | // | |
1952 | // This is a primary track. Set high water mark for this event | |
1953 | fHgwmk=fNtrack; | |
1954 | // | |
1955 | // Set also number if primary tracks | |
1956 | fHeader.SetNprimary(fHgwmk+1); | |
1957 | fHeader.SetNtrack(fHgwmk+1); | |
1958 | } | |
1959 | ntr = fNtrack++; | |
1960 | ||
1961 | /* | |
1962 | // | |
1963 | // Here we get the static mass | |
1964 | // For MC is ok, but a more sophisticated method could be necessary | |
1965 | // if the calculated mass is required | |
1966 | // also, this method is potentially dangerous if the mass | |
1967 | // used in the MC is not the same of the PDG database | |
1968 | // | |
1969 | Float_t mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass(); | |
1970 | Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+ | |
1971 | pmom[1]*pmom[1]+pmom[2]*pmom[2]); | |
1972 | ||
1973 | SetTrack(done, parent, pdg, pmom[0], pmom[1], pmom[2], e, | |
1974 | vpos[0], vpos[1], vpos[2], tof, polar[0],polar[1],polar[2], | |
1975 | mech, ntr, weight); | |
1976 | */ | |
1977 | } | |
1978 | ||
1979 | //_____________________________________________________________________________ | |
1980 | void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, | |
1981 | Double_t px, Double_t py, Double_t pz, Double_t e, | |
1982 | Double_t vx, Double_t vy, Double_t vz, Double_t tof, | |
1983 | Double_t polx, Double_t poly, Double_t polz, | |
1984 | AliMCProcess mech, Int_t &ntr, Float_t weight) | |
1985 | { | |
1986 | // | |
1987 | // Load a track on the stack | |
1988 | // | |
1989 | // done 0 if the track has to be transported | |
1990 | // 1 if not | |
1991 | // parent identifier of the parent track. -1 for a primary | |
1992 | // pdg particle code | |
1993 | // kS generation status code | |
1994 | // px, py, pz momentum GeV/c | |
1995 | // vx, vy, vz position | |
1996 | // polar polarisation | |
1997 | // tof time of flight in seconds | |
1998 | // mech production mechanism | |
1999 | // ntr on output the number of the track stored | |
2000 | // | |
2001 | // New method interface: | |
2002 | // arguments were changed to be in correspondence with TParticle | |
2003 | // constructor. | |
2004 | // Note: the energy is not calculated from the static mass but | |
2005 | // it is passed by argument e. | |
2006 | ||
2007 | TClonesArray &particles = *fParticles; | |
2008 | ||
2009 | const Int_t kS=0; | |
2010 | const Int_t kFirstDaughter=-1; | |
2011 | const Int_t kLastDaughter=-1; | |
2012 | ||
2013 | TParticle* particle | |
2014 | = new(particles[fLoadPoint++]) TParticle(pdg, kS, parent, -1, | |
2015 | kFirstDaughter, kLastDaughter, | |
2016 | px, py, pz, e, vx, vy, vz, tof); | |
2017 | ||
2018 | particle->SetPolarisation(polx, poly, polz); | |
2019 | particle->SetWeight(weight); | |
2020 | particle->SetUniqueID(mech); | |
2021 | ||
2022 | if(!done) particle->SetBit(kDoneBit); | |
2023 | ||
2024 | // Declare that the daughter information is valid | |
2025 | particle->SetBit(kDaughtersBit); | |
2026 | // Add the particle to the stack | |
2027 | fParticleMap->AddAtAndExpand(particle,fNtrack); | |
2028 | ||
2029 | if(parent>=0) { | |
2030 | particle=(TParticle*) fParticleMap->At(parent); | |
2031 | particle->SetLastDaughter(fNtrack); | |
2032 | if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack); | |
2033 | } else { | |
2034 | // | |
2035 | // This is a primary track. Set high water mark for this event | |
2036 | fHgwmk=fNtrack; | |
2037 | // | |
2038 | // Set also number if primary tracks | |
2039 | fHeader.SetNprimary(fHgwmk+1); | |
2040 | fHeader.SetNtrack(fHgwmk+1); | |
2041 | } | |
2042 | ntr = fNtrack++; | |
2043 | } | |
2044 | ||
2045 | //_____________________________________________________________________________ | |
2046 | void AliRun::SetHighWaterMark(const Int_t nt) | |
2047 | { | |
2048 | // | |
2049 | // Set high water mark for last track in event | |
2050 | fHgwmk=fNtrack-1; | |
2051 | // | |
2052 | // Set also number if primary tracks | |
2053 | fHeader.SetNprimary(fHgwmk+1); | |
2054 | fHeader.SetNtrack(fHgwmk+1); | |
2055 | } | |
2056 | ||
2057 | //_____________________________________________________________________________ | |
2058 | void AliRun::KeepTrack(const Int_t track) | |
2059 | { | |
2060 | // | |
2061 | // flags a track to be kept | |
2062 | // | |
2063 | fParticleMap->At(track)->SetBit(kKeepBit); | |
2064 | } | |
2065 | ||
2066 | //_____________________________________________________________________________ | |
2067 | void AliRun::StepManager(Int_t id) | |
2068 | { | |
2069 | // | |
2070 | // Called at every step during transport | |
2071 | // | |
2072 | ||
2073 | // | |
2074 | // --- If lego option, do it and leave | |
2075 | if (fLego) | |
2076 | fLego->StepManager(); | |
2077 | else { | |
2078 | Int_t copy; | |
2079 | //Update energy deposition tables | |
2080 | AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep()); | |
2081 | ||
2082 | //Call the appropriate stepping routine; | |
2083 | AliModule *det = (AliModule*)fModules->At(id); | |
2084 | if(det) { | |
2085 | fMCQA->StepManager(id); | |
2086 | det->StepManager(); | |
2087 | } | |
2088 | } | |
2089 | } | |
2090 | ||
2091 | //_____________________________________________________________________________ | |
2092 | void AliRun::Streamer(TBuffer &R__b) | |
2093 | { | |
2094 | // Stream an object of class AliRun. | |
2095 | ||
2096 | if (R__b.IsReading()) { | |
2097 | if (!gAlice) gAlice = this; | |
2098 | ||
2099 | AliRun::Class()->ReadBuffer(R__b, this); | |
2100 | // | |
2101 | gROOT->GetListOfBrowsables()->Add(this,"Run"); | |
2102 | ||
2103 | fTreeE = (TTree*)gDirectory->Get("TE"); | |
2104 | if (fTreeE) fTreeE->SetBranchAddress("Header", &gAliHeader); | |
2105 | else Error("Streamer","cannot find Header Tree\n"); | |
2106 | fTreeE->GetEntry(0); | |
2107 | ||
2108 | gRandom = fRandom; | |
2109 | } else { | |
2110 | AliRun::Class()->WriteBuffer(R__b, this); | |
2111 | } | |
2112 | } | |
2113 |