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