1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 Revision 1.77 2001/09/04 15:09:11 hristov
19 fTreeE->Branch replaced temporary by fTreeE->BranchOld to avoid data corruption in case of many events per file
21 Revision 1.76 2001/08/03 14:38:35 morsch
22 Use original method to access TreeH.
24 Revision 1.75 2001/07/28 10:52:27 hristov
25 Event number updated correctly (M.Ivanov)
27 Revision 1.74 2001/07/28 10:39:16 morsch
28 GetEventsPerRun() method needed by afterburners added to AliRun.h
29 Corresponding setters and getters have been from AliGenerator.
31 Revision 1.73 2001/07/27 12:34:30 jchudoba
32 remove the dummy argument in fStack->GetEvent call
34 Revision 1.72 2001/07/03 08:10:57 hristov
35 J.Chudoba's changes merged correctly with the HEAD
37 Revision 1.70 2001/06/29 08:01:36 morsch
38 Small correction to the previous.
40 Revision 1.69 2001/06/28 16:27:50 morsch
41 AliReco() with user control of event range.
43 Revision 1.68 2001/06/11 13:14:40 morsch
44 SetAliGenEventHeader() method added.
46 Revision 1.67 2001/06/07 18:24:50 buncic
47 Removed compilation warning in AliConfig initialisation.
49 Revision 1.66 2001/05/22 14:32:40 hristov
52 Revision 1.65 2001/05/21 17:22:51 buncic
53 Fixed problem with missing AliConfig while reading galice.root
55 Revision 1.64 2001/05/16 14:57:22 alibrary
56 New files for folders and Stack
58 Revision 1.62 2001/04/06 11:12:33 morsch
59 Clear fParticles after each event. (Ivana Hrivnacova)
61 Revision 1.61 2001/03/30 07:04:10 morsch
62 Call fGenerator->FinishRun() for final print-outs, cross-section and weight calculations.
64 Revision 1.60 2001/03/21 18:22:30 hristov
65 fParticleFileMap fix (I.Hrivnacova)
67 Revision 1.59 2001/03/12 17:47:03 hristov
68 Changes needed on Sun with CC 5.0
70 Revision 1.58 2001/03/09 14:27:26 morsch
71 Fix for multiple events per file: inhibit decrease of size of fParticleFileMap.
73 Revision 1.57 2001/02/23 17:40:23 buncic
74 All trees needed for simulation created in RunMC(). TreeR and its branches
75 are now created in new RunReco() method.
77 Revision 1.56 2001/02/14 15:45:20 hristov
78 Algorithmic way of getting entry index in fParticleMap. Protection of fParticleFileMap (I.Hrivnacova)
80 Revision 1.55 2001/02/12 15:52:54 buncic
81 Removed OpenBaseFile().
83 Revision 1.54 2001/02/07 10:39:05 hristov
84 Remove default value for argument
86 Revision 1.53 2001/02/06 11:02:26 hristov
87 New SetTrack interface added, added check for unfilled particles in FinishEvent (I.Hrivnacova)
89 Revision 1.52 2001/02/05 16:22:25 buncic
90 Added TreeS to GetEvent().
92 Revision 1.51 2001/02/02 15:16:20 morsch
93 SetHighWaterMark method added to mark last particle in event.
95 Revision 1.50 2001/01/27 10:32:00 hristov
96 Leave the loop when primaries are filled (I.Hrivnacova)
98 Revision 1.49 2001/01/26 19:58:48 hristov
99 Major upgrade of AliRoot code
101 Revision 1.48 2001/01/17 10:50:50 hristov
102 Corrections to destructors
104 Revision 1.47 2000/12/18 10:44:01 morsch
105 Possibility to set field map by passing pointer to objet of type AliMagF via
108 gAlice->SetField(new AliMagFCM("Map2", "$(ALICE_ROOT)/data/field01.dat",2,1.,10.));
110 Revision 1.46 2000/12/14 19:29:27 fca
111 galice.cuts was not read any more
113 Revision 1.45 2000/11/30 07:12:49 alibrary
114 Introducing new Rndm and QA classes
116 Revision 1.44 2000/10/26 13:58:59 morsch
117 Add possibility to choose the lego generator (of type AliGeneratorLego or derived) when running
118 RunLego(). Default is the base class AliGeneratorLego.
120 Revision 1.43 2000/10/09 09:43:17 fca
121 Special remapping of hits for TPC and TRD. End-of-primary action introduced
123 Revision 1.42 2000/10/02 21:28:14 fca
124 Removal of useless dependecies via forward declarations
126 Revision 1.41 2000/07/13 16:19:09 fca
127 Mainly coding conventions + some small bug fixes
129 Revision 1.40 2000/07/12 08:56:25 fca
130 Coding convention correction and warning removal
132 Revision 1.39 2000/07/11 18:24:59 fca
133 Coding convention corrections + few minor bug fixes
135 Revision 1.38 2000/06/20 13:05:45 fca
136 Writing down the TREE headers before job starts
138 Revision 1.37 2000/06/09 20:05:11 morsch
139 Introduce possibility to chose magnetic field version 3: AliMagFDM + field02.dat
141 Revision 1.36 2000/06/08 14:03:58 hristov
142 Only one initializer for a default argument
144 Revision 1.35 2000/06/07 10:13:14 hristov
145 Delete only existent objects.
147 Revision 1.34 2000/05/18 10:45:38 fca
148 Delete Particle Factory properly
150 Revision 1.33 2000/05/16 13:10:40 fca
151 New method IsNewTrack and fix for a problem in Father-Daughter relations
153 Revision 1.32 2000/04/27 10:38:21 fca
154 Correct termination of Lego Run and introduce Lego getter in AliRun
156 Revision 1.31 2000/04/26 10:17:32 fca
157 Changes in Lego for G4 compatibility
159 Revision 1.30 2000/04/18 19:11:40 fca
160 Introduce variable Config.C function signature
162 Revision 1.29 2000/04/07 11:12:34 fca
163 G4 compatibility changes
165 Revision 1.28 2000/04/05 06:51:06 fca
166 Workaround for an HP compiler problem
168 Revision 1.27 2000/03/22 18:08:07 fca
169 Rationalisation of the virtual MC interfaces
171 Revision 1.26 2000/03/22 13:42:26 fca
172 SetGenerator does not replace an existing generator, ResetGenerator does
174 Revision 1.25 2000/02/23 16:25:22 fca
175 AliVMC and AliGeant3 classes introduced
176 ReadEuclid moved from AliRun to AliModule
178 Revision 1.24 2000/01/19 17:17:20 fca
179 Introducing a list of lists of hits -- more hits allowed for detector now
181 Revision 1.23 1999/12/03 11:14:31 fca
182 Fixing previous wrong checking
184 Revision 1.21 1999/11/25 10:40:08 fca
185 Fixing daughters information also in primary tracks
187 Revision 1.20 1999/10/04 18:08:49 fca
188 Adding protection against inconsistent Euclid files
190 Revision 1.19 1999/09/29 07:50:40 fca
191 Introduction of the Copyright and cvs Log
195 ///////////////////////////////////////////////////////////////////////////////
197 // Control class for Alice C++ //
198 // Only one single instance of this class exists. //
199 // The object is created in main program aliroot //
200 // and is pointed by the global gAlice. //
202 // -Supports the list of all Alice Detectors (fModules). //
203 // -Supports the list of particles (fParticles). //
204 // -Supports the Trees. //
205 // -Supports the geometry. //
206 // -Supports the event display. //
209 <img src="picts/AliRunClass.gif">
214 <img src="picts/alirun.gif">
218 ///////////////////////////////////////////////////////////////////////////////
223 #include <iostream.h>
230 #include <TObjectTable.h>
232 #include <TGeometry.h>
234 #include <TBrowser.h>
237 #include "TParticle.h"
239 #include "AliDisplay.h"
242 #include "AliMagFC.h"
243 #include "AliMagFCM.h"
244 #include "AliMagFDM.h"
246 #include "TRandom3.h"
248 #include "AliGenerator.h"
249 #include "AliLegoGenerator.h"
250 #include "AliConfig.h"
251 #include "AliStack.h"
252 #include "AliGenEventHeader.h"
253 #include "AliHeader.h"
255 #include "AliDetector.h"
261 //_____________________________________________________________________________
265 // Default constructor for AliRun
288 fPDGDB = 0; //Particle factory object!
290 fConfigFunction = "\0";
293 fTransParName = "\0";
294 fBaseFileName = ".\0";
298 //_____________________________________________________________________________
299 AliRun::AliRun(const char *name, const char *title)
303 // Constructor for the main processor.
304 // Creates the geometry
305 // Creates the list of Detectors.
306 // Creates the list of particles.
322 fConfigFunction = "Config();";
324 // Set random number generator
325 gRandom = fRandom = new TRandom3();
327 if (gSystem->Getenv("CONFIG_SEED")) {
328 gRandom->SetSeed((UInt_t)atoi(gSystem->Getenv("CONFIG_SEED")));
331 gROOT->GetListOfBrowsables()->Add(this,name);
334 fStack = new AliStack(10000);
335 // create the support list for the various Detectors
336 fModules = new TObjArray(77);
338 // Create the TNode geometry for the event display
340 BuildSimpleGeometry();
342 fHeader = new AliHeader();
348 // Create default mag field
353 // Prepare the tracking medium lists
354 fImedia = new TArrayI(1000);
355 for(i=0;i<1000;i++) (*fImedia)[i]=-99;
358 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
360 AliConfig::Instance()->Add(fPDGDB);
362 // Create HitLists list
363 fHitLists = new TList();
366 fBaseFileName = ".\0";
372 //_____________________________________________________________________________
376 // Default AliRun destructor
401 //_____________________________________________________________________________
402 void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
405 // Add a hit to detector id
407 TObjArray &dets = *fModules;
408 if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits);
411 //_____________________________________________________________________________
412 void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
415 // Add digit to detector id
417 TObjArray &dets = *fModules;
418 if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits);
421 //_____________________________________________________________________________
422 void AliRun::Browse(TBrowser *b)
425 // Called when the item "Run" is clicked on the left pane
426 // of the Root browser.
427 // It displays the Root Trees and all detectors.
429 if(!fStack) fStack=fHeader->Stack();
430 TTree* pTreeK = fStack->TreeK();
432 if (pTreeK) b->Add(pTreeK,pTreeK->GetName());
433 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
434 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
435 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
436 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
437 if (fTreeS) b->Add(fTreeS,fTreeS->GetName());
439 TIter next(fModules);
441 while((detector = (AliModule*)next())) {
442 b->Add(detector,detector->GetName());
444 b->Add(fMCQA,"AliMCQA");
447 //_____________________________________________________________________________
451 // Initialize Alice geometry
456 //_____________________________________________________________________________
457 void AliRun::BuildSimpleGeometry()
460 // Create a simple TNode geometry used by Root display engine
462 // Initialise geometry
464 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
465 new TMaterial("void","Vacuum",0,0,0); //Everything is void
466 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
467 brik->SetVisibility(0);
468 new TNode("alice","alice","S_alice");
471 //_____________________________________________________________________________
472 void AliRun::CleanDetectors()
475 // Clean Detectors at the end of event
477 TIter next(fModules);
479 while((detector = (AliModule*)next())) {
480 detector->FinishEvent();
484 //_____________________________________________________________________________
485 Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
488 // Return the distance from the mouse to the AliRun object
494 //_____________________________________________________________________________
495 void AliRun::DumpPart (Int_t i) const
498 // Dumps particle i in the stack
503 //_____________________________________________________________________________
504 void AliRun::DumpPStack () const
507 // Dumps the particle stack
509 fStack->DumpPStack();
512 //_____________________________________________________________________________
513 void AliRun::SetField(AliMagF* magField)
515 // Set Magnetic Field Map
520 //_____________________________________________________________________________
521 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
522 Float_t maxField, char* filename)
525 // Set magnetic field parameters
526 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
527 // version Magnetic field map version (only 1 active now)
528 // scale Scale factor for the magnetic field
529 // maxField Maximum value for the magnetic field
532 // --- Sanity check on mag field flags
533 if(fField) delete fField;
535 fField = new AliMagFC("Map1"," ",type,scale,maxField);
536 } else if(version<=2) {
537 fField = new AliMagFCM("Map2-3",filename,type,scale,maxField);
539 } else if(version==3) {
540 fField = new AliMagFDM("Map4",filename,type,scale,maxField);
543 Warning("SetField","Invalid map %d\n",version);
547 //_____________________________________________________________________________
548 void AliRun::PreTrack()
550 TObjArray &dets = *fModules;
553 for(Int_t i=0; i<=fNdets; i++)
554 if((module = (AliModule*)dets[i]))
560 //_____________________________________________________________________________
561 void AliRun::PostTrack()
563 TObjArray &dets = *fModules;
566 for(Int_t i=0; i<=fNdets; i++)
567 if((module = (AliModule*)dets[i]))
571 //_____________________________________________________________________________
572 void AliRun::FinishPrimary()
575 // Called at the end of each primary track
578 // static Int_t count=0;
579 // const Int_t times=10;
580 // This primary is finished, purify stack
581 fStack->PurifyKine();
583 TIter next(fModules);
585 while((detector = (AliModule*)next())) {
586 detector->FinishPrimary();
589 // Write out hits if any
590 if (gAlice->TreeH()) {
591 gAlice->TreeH()->Fill();
595 // if(++count%times==1) gObjectTable->Print();
598 //_____________________________________________________________________________
599 void AliRun::BeginPrimary()
602 // Called at the beginning of each primary track
610 //_____________________________________________________________________________
611 void AliRun::FinishEvent()
614 // Called at the end of the event.
618 if(fLego) fLego->FinishEvent();
620 //Update the energy deposit tables
622 for(i=0;i<fEventEnergy.GetSize();i++) {
623 fSummEnergy[i]+=fEventEnergy[i];
624 fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
629 // Update Header information
631 fHeader->SetNprimary(fStack->GetNprimary());
632 fHeader->SetNtrack(fStack->GetNtrack());
635 // Write out the kinematics
636 fStack->FinishEvent();
638 // Write out the event Header information
640 fHeader->SetStack(fStack);
645 // Write Tree headers
646 TTree* pTreeK = fStack->TreeK();
647 if (pTreeK) pTreeK->Write(0,TObject::kOverwrite);
648 if (fTreeH) fTreeH->Write(0,TObject::kOverwrite);
653 //_____________________________________________________________________________
654 void AliRun::FinishRun()
657 // Called at the end of the run.
661 if(fLego) fLego->FinishRun();
663 // Clean detector information
664 TIter next(fModules);
666 while((detector = (AliModule*)next())) {
667 detector->FinishRun();
670 //Output energy summary tables
673 TFile *file = fTreeE->GetCurrentFile();
677 fTreeE->Write(0,TObject::kOverwrite);
679 // Write AliRun info and all detectors parameters
680 Write(0,TObject::kOverwrite);
682 // Clean tree information
687 delete fTreeH; fTreeH = 0;
690 delete fTreeD; fTreeD = 0;
693 delete fTreeR; fTreeR = 0;
696 // delete fTreeE; fTreeE = 0;
699 delete fTreeS; fTreeS = 0;
701 fGenerator->FinishRun();
707 //_____________________________________________________________________________
708 void AliRun::FlagTrack(Int_t track)
712 fStack->FlagTrack(track);
715 //_____________________________________________________________________________
716 void AliRun::EnergySummary()
719 // Print summary of deposited energy
725 Int_t kn, i, left, j, id;
726 const Float_t kzero=0;
727 Int_t ievent=fHeader->GetEvent()+1;
729 // Energy loss information
731 printf("***************** Energy Loss Information per event (GEV) *****************\n");
732 for(kn=1;kn<fEventEnergy.GetSize();kn++) {
735 fEventEnergy[ndep]=kn;
740 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,kzero))/ed;
743 fSummEnergy[ndep]=ed;
744 fSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,kzero));
749 for(kn=0;kn<(ndep-1)/3+1;kn++) {
751 for(i=0;i<(3<left?3:left);i++) {
753 id=Int_t (fEventEnergy[j]+0.1);
754 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]);
759 // Relative energy loss in different detectors
760 printf("******************** Relative Energy Loss per event ********************\n");
761 printf("Total energy loss per event %10.3f GeV\n",edtot);
762 for(kn=0;kn<(ndep-1)/5+1;kn++) {
764 for(i=0;i<(5<left?5:left);i++) {
766 id=Int_t (fEventEnergy[j]+0.1);
767 printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot);
771 for(kn=0;kn<75;kn++) printf("*");
775 // Reset the TArray's
776 // fEventEnergy.Set(0);
777 // fSummEnergy.Set(0);
778 // fSum2Energy.Set(0);
781 //_____________________________________________________________________________
782 AliModule *AliRun::GetModule(const char *name) const
785 // Return pointer to detector from name
787 return (AliModule*)fModules->FindObject(name);
790 //_____________________________________________________________________________
791 AliDetector *AliRun::GetDetector(const char *name) const
794 // Return pointer to detector from name
796 return (AliDetector*)fModules->FindObject(name);
799 //_____________________________________________________________________________
800 Int_t AliRun::GetModuleID(const char *name) const
803 // Return galice internal detector identifier from name
806 TObject *mod=fModules->FindObject(name);
807 if(mod) i=fModules->IndexOf(mod);
811 //_____________________________________________________________________________
812 Int_t AliRun::GetEvent(Int_t event)
815 // Connect the Trees Kinematics and Hits for event # event
816 // Set branch addresses
819 // Reset existing structures
824 // Delete Trees already connected
825 if (fTreeH) { delete fTreeH; fTreeH = 0;}
826 if (fTreeD) { delete fTreeD; fTreeD = 0;}
827 if (fTreeR) { delete fTreeR; fTreeR = 0;}
828 if (fTreeS) { delete fTreeS; fTreeS = 0;}
830 // Create the particle stack
831 if (fHeader) delete fHeader;
834 // Get header from file
836 fTreeE->SetBranchAddress("Header", &fHeader);
838 if (!fTreeE->GetEntry(event)) {
839 Error("GetEvent","Cannot find event:%d\n",event);
844 Error("GetEvent","Cannot find Header Tree (TE)\n");
848 // Get the stack from the header, set fStack to 0 if it
849 // fails to get event
850 if (fStack) delete fStack;
851 fStack = fHeader->Stack();
853 if (!fStack->GetEvent(event)) fStack = 0;
857 TFile *file = fTreeE->GetCurrentFile();
862 // Get Hits Tree header from file
863 sprintf(treeName,"TreeH%d",event);
864 fTreeH = (TTree*)gDirectory->Get(treeName);
866 Error("GetEvent","cannot find Hits Tree for event:%d\n",event);
869 // Get Digits Tree header from file
870 sprintf(treeName,"TreeD%d",event);
871 fTreeD = (TTree*)gDirectory->Get(treeName);
873 // Warning("GetEvent","cannot find Digits Tree for event:%d\n",event);
878 // Get SDigits Tree header from file
879 sprintf(treeName,"TreeS%d",event);
880 fTreeS = (TTree*)gDirectory->Get(treeName);
882 // Warning("GetEvent","cannot find SDigits Tree for event:%d\n",event);
887 // Get Reconstruct Tree header from file
888 sprintf(treeName,"TreeR%d",event);
889 fTreeR = (TTree*)gDirectory->Get(treeName);
891 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
896 // Set Trees branch addresses
897 TIter next(fModules);
899 while((detector = (AliModule*)next())) {
900 detector->SetTreeAddress();
903 fEvent=event; //MI change
905 return fStack->GetNtrack();
908 //_____________________________________________________________________________
909 TGeometry *AliRun::GetGeometry()
912 // Import Alice geometry from current file
913 // Return pointer to geometry object
915 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
917 // Unlink and relink nodes in detectors
918 // This is bad and there must be a better way...
921 TIter next(fModules);
923 while((detector = (AliModule*)next())) {
924 TList *dnodes=detector->Nodes();
927 for ( j=0; j<dnodes->GetSize(); j++) {
928 node = (TNode*) dnodes->At(j);
929 node1 = fGeometry->GetNode(node->GetName());
930 dnodes->Remove(node);
931 dnodes->AddAt(node1,j);
937 //_____________________________________________________________________________
938 void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
939 Float_t &e, Float_t *vpos, Float_t *polar,
944 fStack->GetNextTrack(mtrack, ipart, pmom, e, vpos, polar, tof);
947 //_____________________________________________________________________________
948 Int_t AliRun::GetPrimary(Int_t track) const
951 // return number of primary that has generated track
953 return fStack->GetPrimary(track);
956 //_____________________________________________________________________________
957 void AliRun::InitMC(const char *setup)
960 // Initialize the Alice setup
964 Warning("Init","Cannot initialise AliRun twice!\n");
968 gROOT->LoadMacro(setup);
969 gInterpreter->ProcessLine(fConfigFunction.Data());
972 gMC->DefineParticles(); //Create standard MC particles
974 TObject *objfirst, *objlast;
976 fNdets = fModules->GetLast()+1;
979 //=================Create Materials and geometry
982 // Added also after in case of interactive initialisation of modules
983 fNdets = fModules->GetLast()+1;
985 TIter next(fModules);
987 while((detector = (AliModule*)next())) {
988 detector->SetTreeAddress();
989 objlast = gDirectory->GetList()->Last();
991 // Add Detector histograms in Detector list of histograms
992 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
993 else objfirst = gDirectory->GetList()->First();
995 detector->Histograms()->Add(objfirst);
996 objfirst = gDirectory->GetList()->After(objfirst);
999 ReadTransPar(); //Read the cuts for all materials
1001 MediaTable(); //Build the special IMEDIA table
1003 //Initialise geometry deposition table
1004 fEventEnergy.Set(gMC->NofVolumes()+1);
1005 fSummEnergy.Set(gMC->NofVolumes()+1);
1006 fSum2Energy.Set(gMC->NofVolumes()+1);
1008 //Compute cross-sections
1009 gMC->BuildPhysics();
1011 //Write Geometry object to current file.
1016 fMCQA = new AliMCQA(fNdets);
1018 AliConfig::Instance();
1020 // Save stuff at the beginning of the file to avoid file corruption
1024 //_____________________________________________________________________________
1025 void AliRun::MediaTable()
1028 // Built media table to get from the media number to
1031 Int_t kz, nz, idt, lz, i, k, ind;
1033 TObjArray &dets = *gAlice->Detectors();
1036 // For all detectors
1037 for (kz=0;kz<fNdets;kz++) {
1038 // If detector is defined
1039 if((det=(AliModule*) dets[kz])) {
1040 TArrayI &idtmed = *(det->GetIdtmed());
1041 for(nz=0;nz<100;nz++) {
1042 // Find max and min material number
1043 if((idt=idtmed[nz])) {
1044 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
1045 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
1048 if(det->LoMedium() > det->HiMedium()) {
1049 det->LoMedium() = 0;
1050 det->HiMedium() = 0;
1052 if(det->HiMedium() > fImedia->GetSize()) {
1053 Error("MediaTable","Increase fImedia from %d to %d",
1054 fImedia->GetSize(),det->HiMedium());
1057 // Tag all materials in rage as belonging to detector kz
1058 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
1065 // Print summary table
1066 printf(" Traking media ranges:\n");
1067 for(i=0;i<(fNdets-1)/6+1;i++) {
1068 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
1070 det=(AliModule*)dets[ind];
1072 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
1075 printf(" %6s: %3d -> %3d;","NULL",0,0);
1081 //____________________________________________________________________________
1082 void AliRun::SetGenerator(AliGenerator *generator)
1085 // Load the event generator
1087 if(!fGenerator) fGenerator = generator;
1090 //____________________________________________________________________________
1091 void AliRun::ResetGenerator(AliGenerator *generator)
1094 // Load the event generator
1098 Warning("ResetGenerator","Replacing generator %s with %s\n",
1099 fGenerator->GetName(),generator->GetName());
1101 Warning("ResetGenerator","Replacing generator %s with NULL\n",
1102 fGenerator->GetName());
1103 fGenerator = generator;
1106 //____________________________________________________________________________
1107 void AliRun::SetTransPar(char *filename)
1109 fTransParName = filename;
1112 //____________________________________________________________________________
1113 void AliRun::SetBaseFile(char *filename)
1115 fBaseFileName = filename;
1118 //____________________________________________________________________________
1119 void AliRun::ReadTransPar()
1122 // Read filename to set the transport parameters
1126 const Int_t kncuts=10;
1127 const Int_t knflags=11;
1128 const Int_t knpars=kncuts+knflags;
1129 const char kpars[knpars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
1130 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
1131 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
1132 "MULS","PAIR","PHOT","RAYL"};
1136 Float_t cut[kncuts];
1137 Int_t flag[knflags];
1138 Int_t i, itmed, iret, ktmed, kz;
1141 // See whether the file is there
1142 filtmp=gSystem->ExpandPathName(fTransParName.Data());
1143 lun=fopen(filtmp,"r");
1146 Warning("ReadTransPar","File %s does not exist!\n",fTransParName.Data());
1151 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1152 printf(" *%59s\n","*");
1153 printf(" * Please check carefully what you are doing!%10s\n","*");
1154 printf(" *%59s\n","*");
1158 // Initialise cuts and flags
1159 for(i=0;i<kncuts;i++) cut[i]=-99;
1160 for(i=0;i<knflags;i++) flag[i]=-99;
1162 for(i=0;i<256;i++) line[i]='\0';
1163 // Read up to the end of line excluded
1164 iret=fscanf(lun,"%[^\n]",line);
1169 printf(" *%59s\n","*");
1170 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1174 // Read the end of line
1177 if(line[0]=='*') continue;
1179 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",
1180 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
1181 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
1182 &flag[8],&flag[9],&flag[10]);
1186 Warning("ReadTransPar","Error reading file %s\n",fTransParName.Data());
1189 // Check that the module exist
1190 AliModule *mod = GetModule(detName);
1192 // Get the array of media numbers
1193 TArrayI &idtmed = *mod->GetIdtmed();
1194 // Check that the tracking medium code is valid
1195 if(0<=itmed && itmed < 100) {
1196 ktmed=idtmed[itmed];
1198 Warning("ReadTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
1201 // Set energy thresholds
1202 for(kz=0;kz<kncuts;kz++) {
1204 if(fDebug) printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
1205 kpars[kz],cut[kz],itmed,mod->GetName());
1206 gMC->Gstpar(ktmed,kpars[kz],cut[kz]);
1209 // Set transport mechanisms
1210 for(kz=0;kz<knflags;kz++) {
1212 if(fDebug) printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
1213 kpars[kncuts+kz],flag[kz],itmed,mod->GetName());
1214 gMC->Gstpar(ktmed,kpars[kncuts+kz],Float_t(flag[kz]));
1218 Warning("ReadTransPar","Invalid medium code %d *\n",itmed);
1222 if(fDebug) printf("%s::ReadTransParModule: %s not present\n",ClassName(),detName);
1229 //_____________________________________________________________________________
1230 void AliRun::MakeTree(Option_t *option, const char *file)
1233 // Create the ROOT trees
1234 // Loop on all detectors to create the Root branch (if any)
1240 const char *oK = strstr(option,"K");
1241 const char *oH = strstr(option,"H");
1242 const char *oE = strstr(option,"E");
1243 const char *oD = strstr(option,"D");
1244 const char *oR = strstr(option,"R");
1245 const char *oS = strstr(option,"S");
1248 TDirectory *cwd = gDirectory;
1250 TBranch *branch = 0;
1252 if (oK) fStack->MakeTree(fEvent, file);
1254 if (oE && !fTreeE) {
1255 fTreeE = new TTree("TE","Header");
1256 // branch = fTreeE->Branch("Header", "AliHeader", &fHeader, 4000, 0);
1257 branch = fTreeE->BranchOld("Header", "AliHeader", &fHeader, 4000, 0);
1258 branch->SetAutoDelete(kFALSE);
1259 TFolder *folder = (TFolder *)gROOT->FindObjectAny("/Folders/RunMC/Event/Header");
1260 if (folder) folder->Add(fHeader);
1261 // branch = fTreeE->Branch("Stack","AliStack", &fStack, 4000, 0);
1262 // branch->SetAutoDelete(kFALSE);
1263 // if (folder) folder->Add(fStack);
1264 fTreeE->Write(0,TObject::kOverwrite);
1267 if (file && branch) {
1268 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
1269 sprintf(outFile,"%s/%s",GetBaseFile(),file);
1270 branch->SetFile(outFile);
1271 TIter next( branch->GetListOfBranches());
1272 while ((branch=(TBranch*)next())) {
1273 branch->SetFile(outFile);
1276 printf("* MakeBranch * Diverting Branch %s to file %s\n", branch->GetName(),file);
1281 if (oH && !fTreeH) {
1282 sprintf(hname,"TreeH%d",fEvent);
1283 fTreeH = new TTree(hname,"Hits");
1284 fTreeH->SetAutoSave(1000000000); //no autosave
1285 fTreeH->Write(0,TObject::kOverwrite);
1287 if (oD && !fTreeD) {
1288 sprintf(hname,"TreeD%d",fEvent);
1289 fTreeD = new TTree(hname,"Digits");
1290 fTreeD->Write(0,TObject::kOverwrite);
1292 if (oS && !fTreeS) {
1293 sprintf(hname,"TreeS%d",fEvent);
1294 fTreeS = new TTree(hname,"SDigits");
1295 fTreeS->Write(0,TObject::kOverwrite);
1297 if (oR && !fTreeR) {
1298 sprintf(hname,"TreeR%d",fEvent);
1299 fTreeR = new TTree(hname,"Reconstruction");
1300 fTreeR->Write(0,TObject::kOverwrite);
1304 // Create a branch for hits/digits for each detector
1305 // Each branch is a TClonesArray. Each data member of the Hits classes
1306 // will be in turn a subbranch of the detector master branch
1307 TIter next(fModules);
1308 AliModule *detector;
1309 while((detector = (AliModule*)next())) {
1310 if (oH) detector->MakeBranch(option,file);
1314 //_____________________________________________________________________________
1315 TParticle* AliRun::Particle(Int_t i)
1317 return fStack->Particle(i);
1320 //_____________________________________________________________________________
1321 void AliRun::BeginEvent()
1323 // Clean-up previous event
1325 fEventEnergy.Reset();
1326 // Clean detector information
1333 // Reset all Detectors & kinematics & trees
1337 // Initialise event header
1338 fHeader->Reset(fRun,fEvent);
1340 fStack->BeginEvent(fEvent);
1344 fLego->BeginEvent();
1357 sprintf(hname,"TreeH%d",fEvent);
1358 fTreeH->SetName(hname);
1362 sprintf(hname,"TreeD%d",fEvent);
1363 fTreeD->SetName(hname);
1364 fTreeD->Write(0,TObject::kOverwrite);
1368 sprintf(hname,"TreeS%d",fEvent);
1369 fTreeS->SetName(hname);
1370 fTreeS->Write(0,TObject::kOverwrite);
1374 sprintf(hname,"TreeR%d",fEvent);
1375 fTreeR->SetName(hname);
1376 fTreeR->Write(0,TObject::kOverwrite);
1379 //_____________________________________________________________________________
1380 void AliRun::ResetDigits()
1383 // Reset all Detectors digits
1385 TIter next(fModules);
1386 AliModule *detector;
1387 while((detector = (AliModule*)next())) {
1388 detector->ResetDigits();
1392 //_____________________________________________________________________________
1393 void AliRun::ResetSDigits()
1396 // Reset all Detectors digits
1398 TIter next(fModules);
1399 AliModule *detector;
1400 while((detector = (AliModule*)next())) {
1401 detector->ResetSDigits();
1405 //_____________________________________________________________________________
1406 void AliRun::ResetHits()
1409 // Reset all Detectors hits
1411 TIter next(fModules);
1412 AliModule *detector;
1413 while((detector = (AliModule*)next())) {
1414 detector->ResetHits();
1418 //_____________________________________________________________________________
1419 void AliRun::ResetPoints()
1422 // Reset all Detectors points
1424 TIter next(fModules);
1425 AliModule *detector;
1426 while((detector = (AliModule*)next())) {
1427 detector->ResetPoints();
1431 //_____________________________________________________________________________
1432 void AliRun::RunMC(Int_t nevent, const char *setup)
1435 // Main function to be called to process a galice run
1437 // Root > gAlice.Run();
1438 // a positive number of events will cause the finish routine
1441 fEventsPerRun = nevent;
1442 // check if initialisation has been done
1443 if (!fInitDone) InitMC(setup);
1445 // Create the Root Tree with one branch per detector
1449 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1450 MakeTree("K","Kine.root");
1451 MakeTree("H","Hits.root");
1456 gMC->ProcessRun(nevent);
1458 // End of this run, close files
1459 if(nevent>0) FinishRun();
1462 //_____________________________________________________________________________
1463 void AliRun::RunReco(const char *selected, Int_t first, Int_t last)
1466 // Main function to be called to reconstruct Alice event
1468 cout << "Found "<< gAlice->TreeE()->GetEntries() << "events" << endl;
1469 Int_t nFirst = first;
1470 Int_t nLast = (last < 0)? (Int_t) gAlice->TreeE()->GetEntries() : last;
1472 for (Int_t nevent = nFirst; nevent <= nLast; nevent++) {
1473 cout << "Processing event "<< nevent << endl;
1476 Digits2Reco(selected);
1480 //_____________________________________________________________________________
1482 void AliRun::Hits2Digits(const char *selected)
1485 // Convert Hits to sumable digits
1487 for (Int_t nevent=0; nevent<gAlice->TreeE()->GetEntries(); nevent++) {
1490 Hits2SDigits(selected);
1491 SDigits2Digits(selected);
1496 //_____________________________________________________________________________
1498 void AliRun::Tree2Tree(Option_t *option, const char *selected)
1501 // Function to transform the content of
1503 // - TreeH to TreeS (option "S")
1504 // - TreeS to TreeD (option "D")
1505 // - TreeD to TreeR (option "R")
1507 // If multiple options are specified ("SDR"), transformation will be done in sequence for
1508 // selected detector and for all detectors if none is selected (detector string
1509 // can contain blank separated list of detector names).
1512 const char *oS = strstr(option,"S");
1513 const char *oD = strstr(option,"D");
1514 const char *oR = strstr(option,"R");
1516 TObjArray *detectors = Detectors();
1518 TIter next(detectors);
1520 AliDetector *detector = 0;
1522 TDirectory *cwd = gDirectory;
1526 while((detector = (AliDetector*)next())) {
1528 if (strcmp(detector->GetName(),selected)) continue;
1529 if (detector->IsActive()){
1530 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1532 sprintf(outFile,"SDigits.%s.root",detector->GetName());
1533 detector->MakeBranch("S",outFile);
1536 sprintf(outFile,"Digits.%s.root",detector->GetName());
1537 detector->MakeBranch("D",outFile);
1540 sprintf(outFile,"Reco.%s.root",detector->GetName());
1541 detector->MakeBranch("R",outFile);
1544 detector->MakeBranch(option);
1550 cout << "Hits2SDigits: Processing " << detector->GetName() << "..." << endl;
1551 detector->Hits2SDigits();
1554 cout << "SDigits2Digits: Processing " << detector->GetName() << "..." << endl;
1555 detector->SDigits2Digits();
1558 cout << "Digits2Reco: Processing " << detector->GetName() << "..." << endl;
1559 detector->Digits2Reco();
1568 //_____________________________________________________________________________
1569 void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min,
1570 Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max,
1571 Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener)
1574 // Generates lego plots of:
1575 // - radiation length map phi vs theta
1576 // - radiation length map phi vs eta
1577 // - interaction length map
1578 // - g/cm2 length map
1580 // ntheta bins in theta, eta
1581 // themin minimum angle in theta (degrees)
1582 // themax maximum angle in theta (degrees)
1584 // phimin minimum angle in phi (degrees)
1585 // phimax maximum angle in phi (degrees)
1586 // rmin minimum radius
1587 // rmax maximum radius
1590 // The number of events generated = ntheta*nphi
1591 // run input parameters in macro setup (default="Config.C")
1593 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1596 <img src="picts/AliRunLego1.gif">
1601 <img src="picts/AliRunLego2.gif">
1606 <img src="picts/AliRunLego3.gif">
1611 // check if initialisation has been done
1612 if (!fInitDone) InitMC(setup);
1613 //Save current generator
1614 AliGenerator *gen=Generator();
1616 // Set new generator
1617 if (!gener) gener = new AliLegoGenerator();
1618 ResetGenerator(gener);
1620 // Configure Generator
1621 gener->SetRadiusRange(rmin, rmax);
1622 gener->SetZMax(zmax);
1623 gener->SetCoor1Range(nc1, c1min, c1max);
1624 gener->SetCoor2Range(nc2, c2min, c2max);
1627 //Create Lego object
1628 fLego = new AliLego("lego",gener);
1630 //Prepare MC for Lego Run
1635 gMC->ProcessRun(nc1*nc2+1);
1637 // Create only the Root event Tree
1640 // End of this run, close files
1642 // Restore current generator
1643 ResetGenerator(gen);
1644 // Delete Lego Object
1645 delete fLego; fLego=0;
1648 //_____________________________________________________________________________
1649 void AliRun::SetConfigFunction(const char * config)
1652 // Set the signature of the function contained in Config.C to configure
1655 fConfigFunction=config;
1658 //_____________________________________________________________________________
1659 void AliRun::SetCurrentTrack(Int_t track)
1662 // Set current track number
1664 fStack->SetCurrentTrack(track);
1667 //_____________________________________________________________________________
1668 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1669 Float_t *vpos, Float_t *polar, Float_t tof,
1670 AliMCProcess mech, Int_t &ntr, Float_t weight)
1672 // Delegate to stack
1674 fStack->SetTrack(done, parent, pdg, pmom, vpos, polar, tof,
1678 //_____________________________________________________________________________
1679 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg,
1680 Double_t px, Double_t py, Double_t pz, Double_t e,
1681 Double_t vx, Double_t vy, Double_t vz, Double_t tof,
1682 Double_t polx, Double_t poly, Double_t polz,
1683 AliMCProcess mech, Int_t &ntr, Float_t weight)
1685 // Delegate to stack
1687 fStack->SetTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
1688 polx, poly, polz, mech, ntr, weight);
1692 //_____________________________________________________________________________
1693 void AliRun::SetHighWaterMark(const Int_t nt)
1696 // Set high water mark for last track in event
1697 fStack->SetHighWaterMark(nt);
1700 //_____________________________________________________________________________
1701 void AliRun::KeepTrack(const Int_t track)
1704 // Delegate to stack
1706 fStack->KeepTrack(track);
1709 //_____________________________________________________________________________
1710 void AliRun::StepManager(Int_t id)
1713 // Called at every step during transport
1717 // --- If lego option, do it and leave
1719 fLego->StepManager();
1722 //Update energy deposition tables
1723 AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
1725 //Call the appropriate stepping routine;
1726 AliModule *det = (AliModule*)fModules->At(id);
1728 fMCQA->StepManager(id);
1734 //_____________________________________________________________________________
1735 void AliRun::Streamer(TBuffer &R__b)
1737 // Stream an object of class AliRun.
1739 if (R__b.IsReading()) {
1740 if (!gAlice) gAlice = this;
1742 AliRun::Class()->ReadBuffer(R__b, this);
1744 gROOT->GetListOfBrowsables()->Add(this,"Run");
1746 fTreeE = (TTree*)gDirectory->Get("TE");
1748 fTreeE->SetBranchAddress("Header", &fHeader);
1751 else Error("Streamer","cannot find Header Tree\n");
1752 fTreeE->GetEntry(0);
1756 AliRun::Class()->WriteBuffer(R__b, this);
1761 //___________________________________________________________________________
1762 Int_t AliRun::CurrentTrack() const {
1764 // Returns current track
1766 return fStack->CurrentTrack();
1769 //___________________________________________________________________________
1770 Int_t AliRun::GetNtrack() const {
1772 // Returns number of tracks in stack
1774 return fStack->GetNtrack();
1777 //___________________________________________________________________________
1778 TObjArray* AliRun::Particles() {
1780 // Returns pointer to Particles array
1782 return fStack->Particles();
1785 //___________________________________________________________________________
1786 TTree* AliRun::TreeK() {
1788 // Returns pointer to the TreeK array
1790 return fStack->TreeK();
1794 void AliRun::SetGenEventHeader(AliGenEventHeader* header)
1796 fHeader->SetGenEventHeader(header);