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