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