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