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.74 2001/07/28 10:39:16 morsch
19 GetEventsPerRun() method needed by afterburners added to AliRun.h
20 Corresponding setters and getters have been from AliGenerator.
22 Revision 1.73 2001/07/27 12:34:30 jchudoba
23 remove the dummy argument in fStack->GetEvent call
25 Revision 1.72 2001/07/03 08:10:57 hristov
26 J.Chudoba's changes merged correctly with the HEAD
28 Revision 1.70 2001/06/29 08:01:36 morsch
29 Small correction to the previous.
31 Revision 1.69 2001/06/28 16:27:50 morsch
32 AliReco() with user control of event range.
34 Revision 1.68 2001/06/11 13:14:40 morsch
35 SetAliGenEventHeader() method added.
37 Revision 1.67 2001/06/07 18:24:50 buncic
38 Removed compilation warning in AliConfig initialisation.
40 Revision 1.66 2001/05/22 14:32:40 hristov
43 Revision 1.65 2001/05/21 17:22:51 buncic
44 Fixed problem with missing AliConfig while reading galice.root
46 Revision 1.64 2001/05/16 14:57:22 alibrary
47 New files for folders and Stack
49 Revision 1.62 2001/04/06 11:12:33 morsch
50 Clear fParticles after each event. (Ivana Hrivnacova)
52 Revision 1.61 2001/03/30 07:04:10 morsch
53 Call fGenerator->FinishRun() for final print-outs, cross-section and weight calculations.
55 Revision 1.60 2001/03/21 18:22:30 hristov
56 fParticleFileMap fix (I.Hrivnacova)
58 Revision 1.59 2001/03/12 17:47:03 hristov
59 Changes needed on Sun with CC 5.0
61 Revision 1.58 2001/03/09 14:27:26 morsch
62 Fix for multiple events per file: inhibit decrease of size of fParticleFileMap.
64 Revision 1.57 2001/02/23 17:40:23 buncic
65 All trees needed for simulation created in RunMC(). TreeR and its branches
66 are now created in new RunReco() method.
68 Revision 1.56 2001/02/14 15:45:20 hristov
69 Algorithmic way of getting entry index in fParticleMap. Protection of fParticleFileMap (I.Hrivnacova)
71 Revision 1.55 2001/02/12 15:52:54 buncic
72 Removed OpenBaseFile().
74 Revision 1.54 2001/02/07 10:39:05 hristov
75 Remove default value for argument
77 Revision 1.53 2001/02/06 11:02:26 hristov
78 New SetTrack interface added, added check for unfilled particles in FinishEvent (I.Hrivnacova)
80 Revision 1.52 2001/02/05 16:22:25 buncic
81 Added TreeS to GetEvent().
83 Revision 1.51 2001/02/02 15:16:20 morsch
84 SetHighWaterMark method added to mark last particle in event.
86 Revision 1.50 2001/01/27 10:32:00 hristov
87 Leave the loop when primaries are filled (I.Hrivnacova)
89 Revision 1.49 2001/01/26 19:58:48 hristov
90 Major upgrade of AliRoot code
92 Revision 1.48 2001/01/17 10:50:50 hristov
93 Corrections to destructors
95 Revision 1.47 2000/12/18 10:44:01 morsch
96 Possibility to set field map by passing pointer to objet of type AliMagF via
99 gAlice->SetField(new AliMagFCM("Map2", "$(ALICE_ROOT)/data/field01.dat",2,1.,10.));
101 Revision 1.46 2000/12/14 19:29:27 fca
102 galice.cuts was not read any more
104 Revision 1.45 2000/11/30 07:12:49 alibrary
105 Introducing new Rndm and QA classes
107 Revision 1.44 2000/10/26 13:58:59 morsch
108 Add possibility to choose the lego generator (of type AliGeneratorLego or derived) when running
109 RunLego(). Default is the base class AliGeneratorLego.
111 Revision 1.43 2000/10/09 09:43:17 fca
112 Special remapping of hits for TPC and TRD. End-of-primary action introduced
114 Revision 1.42 2000/10/02 21:28:14 fca
115 Removal of useless dependecies via forward declarations
117 Revision 1.41 2000/07/13 16:19:09 fca
118 Mainly coding conventions + some small bug fixes
120 Revision 1.40 2000/07/12 08:56:25 fca
121 Coding convention correction and warning removal
123 Revision 1.39 2000/07/11 18:24:59 fca
124 Coding convention corrections + few minor bug fixes
126 Revision 1.38 2000/06/20 13:05:45 fca
127 Writing down the TREE headers before job starts
129 Revision 1.37 2000/06/09 20:05:11 morsch
130 Introduce possibility to chose magnetic field version 3: AliMagFDM + field02.dat
132 Revision 1.36 2000/06/08 14:03:58 hristov
133 Only one initializer for a default argument
135 Revision 1.35 2000/06/07 10:13:14 hristov
136 Delete only existent objects.
138 Revision 1.34 2000/05/18 10:45:38 fca
139 Delete Particle Factory properly
141 Revision 1.33 2000/05/16 13:10:40 fca
142 New method IsNewTrack and fix for a problem in Father-Daughter relations
144 Revision 1.32 2000/04/27 10:38:21 fca
145 Correct termination of Lego Run and introduce Lego getter in AliRun
147 Revision 1.31 2000/04/26 10:17:32 fca
148 Changes in Lego for G4 compatibility
150 Revision 1.30 2000/04/18 19:11:40 fca
151 Introduce variable Config.C function signature
153 Revision 1.29 2000/04/07 11:12:34 fca
154 G4 compatibility changes
156 Revision 1.28 2000/04/05 06:51:06 fca
157 Workaround for an HP compiler problem
159 Revision 1.27 2000/03/22 18:08:07 fca
160 Rationalisation of the virtual MC interfaces
162 Revision 1.26 2000/03/22 13:42:26 fca
163 SetGenerator does not replace an existing generator, ResetGenerator does
165 Revision 1.25 2000/02/23 16:25:22 fca
166 AliVMC and AliGeant3 classes introduced
167 ReadEuclid moved from AliRun to AliModule
169 Revision 1.24 2000/01/19 17:17:20 fca
170 Introducing a list of lists of hits -- more hits allowed for detector now
172 Revision 1.23 1999/12/03 11:14:31 fca
173 Fixing previous wrong checking
175 Revision 1.21 1999/11/25 10:40:08 fca
176 Fixing daughters information also in primary tracks
178 Revision 1.20 1999/10/04 18:08:49 fca
179 Adding protection against inconsistent Euclid files
181 Revision 1.19 1999/09/29 07:50:40 fca
182 Introduction of the Copyright and cvs Log
186 ///////////////////////////////////////////////////////////////////////////////
188 // Control class for Alice C++ //
189 // Only one single instance of this class exists. //
190 // The object is created in main program aliroot //
191 // and is pointed by the global gAlice. //
193 // -Supports the list of all Alice Detectors (fModules). //
194 // -Supports the list of particles (fParticles). //
195 // -Supports the Trees. //
196 // -Supports the geometry. //
197 // -Supports the event display. //
200 <img src="picts/AliRunClass.gif">
205 <img src="picts/alirun.gif">
209 ///////////////////////////////////////////////////////////////////////////////
214 #include <iostream.h>
221 #include <TObjectTable.h>
223 #include <TGeometry.h>
225 #include <TBrowser.h>
230 #include "TParticle.h"
232 #include "AliDisplay.h"
235 #include "AliMagFC.h"
236 #include "AliMagFCM.h"
237 #include "AliMagFDM.h"
239 #include "TRandom3.h"
241 #include "AliGenerator.h"
242 #include "AliLegoGenerator.h"
243 #include "AliConfig.h"
244 #include "AliStack.h"
245 #include "AliGenEventHeader.h"
246 #include "AliHeader.h"
248 #include "AliDetector.h"
254 //_____________________________________________________________________________
258 // Default constructor for AliRun
281 fPDGDB = 0; //Particle factory object!
283 fConfigFunction = "\0";
286 fTransParName = "\0";
287 fBaseFileName = ".\0";
291 //_____________________________________________________________________________
292 AliRun::AliRun(const char *name, const char *title)
296 // Constructor for the main processor.
297 // Creates the geometry
298 // Creates the list of Detectors.
299 // Creates the list of particles.
315 fConfigFunction = "Config();";
317 // Set random number generator
318 gRandom = fRandom = new TRandom3();
320 if (gSystem->Getenv("CONFIG_SEED")) {
321 gRandom->SetSeed((UInt_t)atoi(gSystem->Getenv("CONFIG_SEED")));
324 gROOT->GetListOfBrowsables()->Add(this,name);
327 fStack = new AliStack(10000);
328 // create the support list for the various Detectors
329 fModules = new TObjArray(77);
331 // Create the TNode geometry for the event display
333 BuildSimpleGeometry();
335 fHeader = new AliHeader();
341 // Create default mag field
346 // Prepare the tracking medium lists
347 fImedia = new TArrayI(1000);
348 for(i=0;i<1000;i++) (*fImedia)[i]=-99;
351 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
353 AliConfig::Instance()->Add(fPDGDB);
355 // Create HitLists list
356 fHitLists = new TList();
359 fBaseFileName = ".\0";
365 //_____________________________________________________________________________
369 // Default AliRun destructor
394 //_____________________________________________________________________________
395 void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
398 // Add a hit to detector id
400 TObjArray &dets = *fModules;
401 if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits);
404 //_____________________________________________________________________________
405 void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
408 // Add digit to detector id
410 TObjArray &dets = *fModules;
411 if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits);
414 //_____________________________________________________________________________
415 void AliRun::Browse(TBrowser *b)
418 // Called when the item "Run" is clicked on the left pane
419 // of the Root browser.
420 // It displays the Root Trees and all detectors.
422 if(!fStack) fStack=fHeader->Stack();
423 TTree* pTreeK = fStack->TreeK();
425 if (pTreeK) b->Add(pTreeK,pTreeK->GetName());
426 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
427 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
428 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
429 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
430 if (fTreeS) b->Add(fTreeS,fTreeS->GetName());
432 TIter next(fModules);
434 while((detector = (AliModule*)next())) {
435 b->Add(detector,detector->GetName());
437 b->Add(fMCQA,"AliMCQA");
440 //_____________________________________________________________________________
444 // Initialize Alice geometry
449 //_____________________________________________________________________________
450 void AliRun::BuildSimpleGeometry()
453 // Create a simple TNode geometry used by Root display engine
455 // Initialise geometry
457 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
458 new TMaterial("void","Vacuum",0,0,0); //Everything is void
459 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
460 brik->SetVisibility(0);
461 new TNode("alice","alice","S_alice");
464 //_____________________________________________________________________________
465 void AliRun::CleanDetectors()
468 // Clean Detectors at the end of event
470 TIter next(fModules);
472 while((detector = (AliModule*)next())) {
473 detector->FinishEvent();
477 //_____________________________________________________________________________
478 Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
481 // Return the distance from the mouse to the AliRun object
487 //_____________________________________________________________________________
488 void AliRun::DumpPart (Int_t i) const
491 // Dumps particle i in the stack
496 //_____________________________________________________________________________
497 void AliRun::DumpPStack () const
500 // Dumps the particle stack
502 fStack->DumpPStack();
505 //_____________________________________________________________________________
506 void AliRun::SetField(AliMagF* magField)
508 // Set Magnetic Field Map
513 //_____________________________________________________________________________
514 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
515 Float_t maxField, char* filename)
518 // Set magnetic field parameters
519 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
520 // version Magnetic field map version (only 1 active now)
521 // scale Scale factor for the magnetic field
522 // maxField Maximum value for the magnetic field
525 // --- Sanity check on mag field flags
526 if(fField) delete fField;
528 fField = new AliMagFC("Map1"," ",type,scale,maxField);
529 } else if(version<=2) {
530 fField = new AliMagFCM("Map2-3",filename,type,scale,maxField);
532 } else if(version==3) {
533 fField = new AliMagFDM("Map4",filename,type,scale,maxField);
536 Warning("SetField","Invalid map %d\n",version);
540 //_____________________________________________________________________________
541 void AliRun::PreTrack()
543 TObjArray &dets = *fModules;
546 for(Int_t i=0; i<=fNdets; i++)
547 if((module = (AliModule*)dets[i]))
553 //_____________________________________________________________________________
554 void AliRun::PostTrack()
556 TObjArray &dets = *fModules;
559 for(Int_t i=0; i<=fNdets; i++)
560 if((module = (AliModule*)dets[i]))
564 //_____________________________________________________________________________
565 void AliRun::FinishPrimary()
568 // Called at the end of each primary track
571 // static Int_t count=0;
572 // const Int_t times=10;
573 // This primary is finished, purify stack
574 fStack->PurifyKine();
576 TIter next(fModules);
578 while((detector = (AliModule*)next())) {
579 detector->FinishPrimary();
582 // Write out hits if any
583 if (gAlice->TreeH()) {
584 gAlice->TreeH()->Fill();
588 // if(++count%times==1) gObjectTable->Print();
591 //_____________________________________________________________________________
592 void AliRun::BeginPrimary()
595 // Called at the beginning of each primary track
603 //_____________________________________________________________________________
604 void AliRun::FinishEvent()
607 // Called at the end of the event.
611 if(fLego) fLego->FinishEvent();
613 //Update the energy deposit tables
615 for(i=0;i<fEventEnergy.GetSize();i++) {
616 fSummEnergy[i]+=fEventEnergy[i];
617 fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
622 // Update Header information
624 fHeader->SetNprimary(fStack->GetNprimary());
625 fHeader->SetNtrack(fStack->GetNtrack());
628 // Write out the kinematics
629 fStack->FinishEvent();
631 // Write out the event Header information
633 fHeader->SetStack(fStack);
638 // Write Tree headers
639 TTree* pTreeK = fStack->TreeK();
640 if (pTreeK) pTreeK->Write(0,TObject::kOverwrite);
641 if (fTreeH) fTreeH->Write(0,TObject::kOverwrite);
646 //_____________________________________________________________________________
647 void AliRun::FinishRun()
650 // Called at the end of the run.
654 if(fLego) fLego->FinishRun();
656 // Clean detector information
657 TIter next(fModules);
659 while((detector = (AliModule*)next())) {
660 detector->FinishRun();
663 //Output energy summary tables
666 TFile *file = fTreeE->GetCurrentFile();
670 fTreeE->Write(0,TObject::kOverwrite);
672 // Write AliRun info and all detectors parameters
673 Write(0,TObject::kOverwrite);
675 // Clean tree information
680 delete fTreeH; fTreeH = 0;
683 delete fTreeD; fTreeD = 0;
686 delete fTreeR; fTreeR = 0;
689 delete fTreeE; fTreeE = 0;
692 delete fTreeS; fTreeS = 0;
694 fGenerator->FinishRun();
700 //_____________________________________________________________________________
701 void AliRun::FlagTrack(Int_t track)
705 fStack->FlagTrack(track);
708 //_____________________________________________________________________________
709 void AliRun::EnergySummary()
712 // Print summary of deposited energy
718 Int_t kn, i, left, j, id;
719 const Float_t kzero=0;
720 Int_t ievent=fHeader->GetEvent()+1;
722 // Energy loss information
724 printf("***************** Energy Loss Information per event (GEV) *****************\n");
725 for(kn=1;kn<fEventEnergy.GetSize();kn++) {
728 fEventEnergy[ndep]=kn;
733 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,kzero))/ed;
736 fSummEnergy[ndep]=ed;
737 fSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,kzero));
742 for(kn=0;kn<(ndep-1)/3+1;kn++) {
744 for(i=0;i<(3<left?3:left);i++) {
746 id=Int_t (fEventEnergy[j]+0.1);
747 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]);
752 // Relative energy loss in different detectors
753 printf("******************** Relative Energy Loss per event ********************\n");
754 printf("Total energy loss per event %10.3f GeV\n",edtot);
755 for(kn=0;kn<(ndep-1)/5+1;kn++) {
757 for(i=0;i<(5<left?5:left);i++) {
759 id=Int_t (fEventEnergy[j]+0.1);
760 printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot);
764 for(kn=0;kn<75;kn++) printf("*");
768 // Reset the TArray's
769 // fEventEnergy.Set(0);
770 // fSummEnergy.Set(0);
771 // fSum2Energy.Set(0);
774 //_____________________________________________________________________________
775 AliModule *AliRun::GetModule(const char *name) const
778 // Return pointer to detector from name
780 return (AliModule*)fModules->FindObject(name);
783 //_____________________________________________________________________________
784 AliDetector *AliRun::GetDetector(const char *name) const
787 // Return pointer to detector from name
789 return (AliDetector*)fModules->FindObject(name);
792 //_____________________________________________________________________________
793 Int_t AliRun::GetModuleID(const char *name) const
796 // Return galice internal detector identifier from name
799 TObject *mod=fModules->FindObject(name);
800 if(mod) i=fModules->IndexOf(mod);
804 //_____________________________________________________________________________
805 Int_t AliRun::GetEvent(Int_t event)
808 // Connect the Trees Kinematics and Hits for event # event
809 // Set branch addresses
812 // Reset existing structures
817 // Delete Trees already connected
818 if (fTreeH) { delete fTreeH; fTreeH = 0;}
819 if (fTreeD) { delete fTreeD; fTreeD = 0;}
820 if (fTreeR) { delete fTreeR; fTreeR = 0;}
821 if (fTreeS) { delete fTreeS; fTreeS = 0;}
823 // Create the particle stack
824 if (fHeader) delete fHeader;
827 // Get header from file
829 fTreeE->SetBranchAddress("Header", &fHeader);
831 if (!fTreeE->GetEntry(event)) {
832 Error("GetEvent","Cannot find event:%d\n",event);
837 Error("GetEvent","Cannot find Header Tree (TE)\n");
841 // Get the stack from the header, set fStack to 0 if it
842 // fails to get event
843 if (fStack) delete fStack;
844 fStack = fHeader->Stack();
846 if (!fStack->GetEvent(event)) fStack = 0;
850 TFile *file = fTreeE->GetCurrentFile();
853 static TIter Iter(gDirectory->GetListOfKeys());
857 // Get Hits Tree header from file
858 sprintf(treeName,"TreeH%d",event);
859 while ((currentKey = (TKey *) Iter.Next())) {
860 if (strcmp(treeName,currentKey->GetName()) == 0) {
861 fTreeH = (TTree*)currentKey->ReadObj();
863 {Error("GetEvent","cannot find Hits Tree for event:%d\n",event);}
868 // Get Digits Tree header from file
869 sprintf(treeName,"TreeD%d",event);
870 fTreeD = (TTree*)gDirectory->Get(treeName);
872 // Warning("GetEvent","cannot find Digits Tree for event:%d\n",event);
877 // Get SDigits Tree header from file
878 sprintf(treeName,"TreeS%d",event);
879 fTreeS = (TTree*)gDirectory->Get(treeName);
881 // Warning("GetEvent","cannot find SDigits Tree for event:%d\n",event);
886 // Get Reconstruct Tree header from file
887 sprintf(treeName,"TreeR%d",event);
888 fTreeR = (TTree*)gDirectory->Get(treeName);
890 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
895 // Set Trees branch addresses
896 TIter next(fModules);
898 while((detector = (AliModule*)next())) {
899 detector->SetTreeAddress();
902 fEvent=event; //MI change
904 return fStack->GetNtrack();
907 //_____________________________________________________________________________
908 TGeometry *AliRun::GetGeometry()
911 // Import Alice geometry from current file
912 // Return pointer to geometry object
914 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
916 // Unlink and relink nodes in detectors
917 // This is bad and there must be a better way...
920 TIter next(fModules);
922 while((detector = (AliModule*)next())) {
923 TList *dnodes=detector->Nodes();
926 for ( j=0; j<dnodes->GetSize(); j++) {
927 node = (TNode*) dnodes->At(j);
928 node1 = fGeometry->GetNode(node->GetName());
929 dnodes->Remove(node);
930 dnodes->AddAt(node1,j);
936 //_____________________________________________________________________________
937 void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
938 Float_t &e, Float_t *vpos, Float_t *polar,
943 fStack->GetNextTrack(mtrack, ipart, pmom, e, vpos, polar, tof);
946 //_____________________________________________________________________________
947 Int_t AliRun::GetPrimary(Int_t track) const
950 // return number of primary that has generated track
952 return fStack->GetPrimary(track);
955 //_____________________________________________________________________________
956 void AliRun::InitMC(const char *setup)
959 // Initialize the Alice setup
963 Warning("Init","Cannot initialise AliRun twice!\n");
967 gROOT->LoadMacro(setup);
968 gInterpreter->ProcessLine(fConfigFunction.Data());
971 gMC->DefineParticles(); //Create standard MC particles
973 TObject *objfirst, *objlast;
975 fNdets = fModules->GetLast()+1;
978 //=================Create Materials and geometry
981 // Added also after in case of interactive initialisation of modules
982 fNdets = fModules->GetLast()+1;
984 TIter next(fModules);
986 while((detector = (AliModule*)next())) {
987 detector->SetTreeAddress();
988 objlast = gDirectory->GetList()->Last();
990 // Add Detector histograms in Detector list of histograms
991 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
992 else objfirst = gDirectory->GetList()->First();
994 detector->Histograms()->Add(objfirst);
995 objfirst = gDirectory->GetList()->After(objfirst);
998 ReadTransPar(); //Read the cuts for all materials
1000 MediaTable(); //Build the special IMEDIA table
1002 //Initialise geometry deposition table
1003 fEventEnergy.Set(gMC->NofVolumes()+1);
1004 fSummEnergy.Set(gMC->NofVolumes()+1);
1005 fSum2Energy.Set(gMC->NofVolumes()+1);
1007 //Compute cross-sections
1008 gMC->BuildPhysics();
1010 //Write Geometry object to current file.
1015 fMCQA = new AliMCQA(fNdets);
1017 AliConfig::Instance();
1019 // Save stuff at the beginning of the file to avoid file corruption
1023 //_____________________________________________________________________________
1024 void AliRun::MediaTable()
1027 // Built media table to get from the media number to
1030 Int_t kz, nz, idt, lz, i, k, ind;
1032 TObjArray &dets = *gAlice->Detectors();
1035 // For all detectors
1036 for (kz=0;kz<fNdets;kz++) {
1037 // If detector is defined
1038 if((det=(AliModule*) dets[kz])) {
1039 TArrayI &idtmed = *(det->GetIdtmed());
1040 for(nz=0;nz<100;nz++) {
1041 // Find max and min material number
1042 if((idt=idtmed[nz])) {
1043 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
1044 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
1047 if(det->LoMedium() > det->HiMedium()) {
1048 det->LoMedium() = 0;
1049 det->HiMedium() = 0;
1051 if(det->HiMedium() > fImedia->GetSize()) {
1052 Error("MediaTable","Increase fImedia from %d to %d",
1053 fImedia->GetSize(),det->HiMedium());
1056 // Tag all materials in rage as belonging to detector kz
1057 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
1064 // Print summary table
1065 printf(" Traking media ranges:\n");
1066 for(i=0;i<(fNdets-1)/6+1;i++) {
1067 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
1069 det=(AliModule*)dets[ind];
1071 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
1074 printf(" %6s: %3d -> %3d;","NULL",0,0);
1080 //____________________________________________________________________________
1081 void AliRun::SetGenerator(AliGenerator *generator)
1084 // Load the event generator
1086 if(!fGenerator) fGenerator = generator;
1089 //____________________________________________________________________________
1090 void AliRun::ResetGenerator(AliGenerator *generator)
1093 // Load the event generator
1097 Warning("ResetGenerator","Replacing generator %s with %s\n",
1098 fGenerator->GetName(),generator->GetName());
1100 Warning("ResetGenerator","Replacing generator %s with NULL\n",
1101 fGenerator->GetName());
1102 fGenerator = generator;
1105 //____________________________________________________________________________
1106 void AliRun::SetTransPar(char *filename)
1108 fTransParName = filename;
1111 //____________________________________________________________________________
1112 void AliRun::SetBaseFile(char *filename)
1114 fBaseFileName = filename;
1117 //____________________________________________________________________________
1118 void AliRun::ReadTransPar()
1121 // Read filename to set the transport parameters
1125 const Int_t kncuts=10;
1126 const Int_t knflags=11;
1127 const Int_t knpars=kncuts+knflags;
1128 const char kpars[knpars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
1129 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
1130 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
1131 "MULS","PAIR","PHOT","RAYL"};
1135 Float_t cut[kncuts];
1136 Int_t flag[knflags];
1137 Int_t i, itmed, iret, ktmed, kz;
1140 // See whether the file is there
1141 filtmp=gSystem->ExpandPathName(fTransParName.Data());
1142 lun=fopen(filtmp,"r");
1145 Warning("ReadTransPar","File %s does not exist!\n",fTransParName.Data());
1150 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1151 printf(" *%59s\n","*");
1152 printf(" * Please check carefully what you are doing!%10s\n","*");
1153 printf(" *%59s\n","*");
1157 // Initialise cuts and flags
1158 for(i=0;i<kncuts;i++) cut[i]=-99;
1159 for(i=0;i<knflags;i++) flag[i]=-99;
1161 for(i=0;i<256;i++) line[i]='\0';
1162 // Read up to the end of line excluded
1163 iret=fscanf(lun,"%[^\n]",line);
1168 printf(" *%59s\n","*");
1169 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1173 // Read the end of line
1176 if(line[0]=='*') continue;
1178 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",
1179 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
1180 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
1181 &flag[8],&flag[9],&flag[10]);
1185 Warning("ReadTransPar","Error reading file %s\n",fTransParName.Data());
1188 // Check that the module exist
1189 AliModule *mod = GetModule(detName);
1191 // Get the array of media numbers
1192 TArrayI &idtmed = *mod->GetIdtmed();
1193 // Check that the tracking medium code is valid
1194 if(0<=itmed && itmed < 100) {
1195 ktmed=idtmed[itmed];
1197 Warning("ReadTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
1200 // Set energy thresholds
1201 for(kz=0;kz<kncuts;kz++) {
1203 if(fDebug) printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
1204 kpars[kz],cut[kz],itmed,mod->GetName());
1205 gMC->Gstpar(ktmed,kpars[kz],cut[kz]);
1208 // Set transport mechanisms
1209 for(kz=0;kz<knflags;kz++) {
1211 if(fDebug) printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
1212 kpars[kncuts+kz],flag[kz],itmed,mod->GetName());
1213 gMC->Gstpar(ktmed,kpars[kncuts+kz],Float_t(flag[kz]));
1217 Warning("ReadTransPar","Invalid medium code %d *\n",itmed);
1221 if(fDebug) printf("%s::ReadTransParModule: %s not present\n",ClassName(),detName);
1228 //_____________________________________________________________________________
1229 void AliRun::MakeTree(Option_t *option, const char *file)
1232 // Create the ROOT trees
1233 // Loop on all detectors to create the Root branch (if any)
1239 const char *oK = strstr(option,"K");
1240 const char *oH = strstr(option,"H");
1241 const char *oE = strstr(option,"E");
1242 const char *oD = strstr(option,"D");
1243 const char *oR = strstr(option,"R");
1244 const char *oS = strstr(option,"S");
1247 TDirectory *cwd = gDirectory;
1249 TBranch *branch = 0;
1251 if (oK) fStack->MakeTree(fEvent, file);
1253 if (oE && !fTreeE) {
1254 fTreeE = new TTree("TE","Header");
1255 branch = fTreeE->Branch("Header", "AliHeader", &fHeader, 4000, 0);
1256 branch->SetAutoDelete(kFALSE);
1257 TFolder *folder = (TFolder *)gROOT->FindObjectAny("/Folders/RunMC/Event/Header");
1258 if (folder) folder->Add(fHeader);
1259 // branch = fTreeE->Branch("Stack","AliStack", &fStack, 4000, 0);
1260 // branch->SetAutoDelete(kFALSE);
1261 // if (folder) folder->Add(fStack);
1262 fTreeE->Write(0,TObject::kOverwrite);
1265 if (file && branch) {
1266 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
1267 sprintf(outFile,"%s/%s",GetBaseFile(),file);
1268 branch->SetFile(outFile);
1269 TIter next( branch->GetListOfBranches());
1270 while ((branch=(TBranch*)next())) {
1271 branch->SetFile(outFile);
1274 printf("* MakeBranch * Diverting Branch %s to file %s\n", branch->GetName(),file);
1279 if (oH && !fTreeH) {
1280 sprintf(hname,"TreeH%d",fEvent);
1281 fTreeH = new TTree(hname,"Hits");
1282 fTreeH->SetAutoSave(1000000000); //no autosave
1283 fTreeH->Write(0,TObject::kOverwrite);
1285 if (oD && !fTreeD) {
1286 sprintf(hname,"TreeD%d",fEvent);
1287 fTreeD = new TTree(hname,"Digits");
1288 fTreeD->Write(0,TObject::kOverwrite);
1290 if (oS && !fTreeS) {
1291 sprintf(hname,"TreeS%d",fEvent);
1292 fTreeS = new TTree(hname,"SDigits");
1293 fTreeS->Write(0,TObject::kOverwrite);
1295 if (oR && !fTreeR) {
1296 sprintf(hname,"TreeR%d",fEvent);
1297 fTreeR = new TTree(hname,"Reconstruction");
1298 fTreeR->Write(0,TObject::kOverwrite);
1302 // Create a branch for hits/digits for each detector
1303 // Each branch is a TClonesArray. Each data member of the Hits classes
1304 // will be in turn a subbranch of the detector master branch
1305 TIter next(fModules);
1306 AliModule *detector;
1307 while((detector = (AliModule*)next())) {
1308 if (oH) detector->MakeBranch(option,file);
1312 //_____________________________________________________________________________
1313 TParticle* AliRun::Particle(Int_t i)
1315 return fStack->Particle(i);
1318 //_____________________________________________________________________________
1319 void AliRun::BeginEvent()
1321 // Clean-up previous event
1323 fEventEnergy.Reset();
1324 // Clean detector information
1331 // Reset all Detectors & kinematics & trees
1335 // Initialise event header
1336 fHeader->Reset(fRun,fEvent);
1338 fStack->BeginEvent(fEvent);
1342 fLego->BeginEvent();
1355 sprintf(hname,"TreeH%d",fEvent);
1356 fTreeH->SetName(hname);
1360 sprintf(hname,"TreeD%d",fEvent);
1361 fTreeD->SetName(hname);
1362 fTreeD->Write(0,TObject::kOverwrite);
1366 sprintf(hname,"TreeS%d",fEvent);
1367 fTreeS->SetName(hname);
1368 fTreeS->Write(0,TObject::kOverwrite);
1372 sprintf(hname,"TreeR%d",fEvent);
1373 fTreeR->SetName(hname);
1374 fTreeR->Write(0,TObject::kOverwrite);
1377 //_____________________________________________________________________________
1378 void AliRun::ResetDigits()
1381 // Reset all Detectors digits
1383 TIter next(fModules);
1384 AliModule *detector;
1385 while((detector = (AliModule*)next())) {
1386 detector->ResetDigits();
1390 //_____________________________________________________________________________
1391 void AliRun::ResetSDigits()
1394 // Reset all Detectors digits
1396 TIter next(fModules);
1397 AliModule *detector;
1398 while((detector = (AliModule*)next())) {
1399 detector->ResetSDigits();
1403 //_____________________________________________________________________________
1404 void AliRun::ResetHits()
1407 // Reset all Detectors hits
1409 TIter next(fModules);
1410 AliModule *detector;
1411 while((detector = (AliModule*)next())) {
1412 detector->ResetHits();
1416 //_____________________________________________________________________________
1417 void AliRun::ResetPoints()
1420 // Reset all Detectors points
1422 TIter next(fModules);
1423 AliModule *detector;
1424 while((detector = (AliModule*)next())) {
1425 detector->ResetPoints();
1429 //_____________________________________________________________________________
1430 void AliRun::RunMC(Int_t nevent, const char *setup)
1433 // Main function to be called to process a galice run
1435 // Root > gAlice.Run();
1436 // a positive number of events will cause the finish routine
1439 fEventsPerRun = nevent;
1440 // check if initialisation has been done
1441 if (!fInitDone) InitMC(setup);
1443 // Create the Root Tree with one branch per detector
1447 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1448 MakeTree("K","Kine.root");
1449 MakeTree("H","Hits.root");
1454 gMC->ProcessRun(nevent);
1456 // End of this run, close files
1457 if(nevent>0) FinishRun();
1460 //_____________________________________________________________________________
1461 void AliRun::RunReco(const char *selected, Int_t first, Int_t last)
1464 // Main function to be called to reconstruct Alice event
1466 cout << "Found "<< gAlice->TreeE()->GetEntries() << "events" << endl;
1467 Int_t nFirst = first;
1468 Int_t nLast = (last < 0)? (Int_t) gAlice->TreeE()->GetEntries() : last;
1470 for (Int_t nevent = nFirst; nevent <= nLast; nevent++) {
1471 cout << "Processing event "<< nevent << endl;
1474 Digits2Reco(selected);
1478 //_____________________________________________________________________________
1480 void AliRun::Hits2Digits(const char *selected)
1483 // Convert Hits to sumable digits
1485 for (Int_t nevent=0; nevent<gAlice->TreeE()->GetEntries(); nevent++) {
1488 Hits2SDigits(selected);
1489 SDigits2Digits(selected);
1494 //_____________________________________________________________________________
1496 void AliRun::Tree2Tree(Option_t *option, const char *selected)
1499 // Function to transform the content of
1501 // - TreeH to TreeS (option "S")
1502 // - TreeS to TreeD (option "D")
1503 // - TreeD to TreeR (option "R")
1505 // If multiple options are specified ("SDR"), transformation will be done in sequence for
1506 // selected detector and for all detectors if none is selected (detector string
1507 // can contain blank separated list of detector names).
1510 const char *oS = strstr(option,"S");
1511 const char *oD = strstr(option,"D");
1512 const char *oR = strstr(option,"R");
1514 TObjArray *detectors = Detectors();
1516 TIter next(detectors);
1518 AliDetector *detector = 0;
1520 TDirectory *cwd = gDirectory;
1524 while((detector = (AliDetector*)next())) {
1526 if (strcmp(detector->GetName(),selected)) continue;
1527 if (detector->IsActive()){
1528 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1530 sprintf(outFile,"SDigits.%s.root",detector->GetName());
1531 detector->MakeBranch("S",outFile);
1534 sprintf(outFile,"Digits.%s.root",detector->GetName());
1535 detector->MakeBranch("D",outFile);
1538 sprintf(outFile,"Reco.%s.root",detector->GetName());
1539 detector->MakeBranch("R",outFile);
1542 detector->MakeBranch(option);
1548 cout << "Hits2SDigits: Processing " << detector->GetName() << "..." << endl;
1549 detector->Hits2SDigits();
1552 cout << "SDigits2Digits: Processing " << detector->GetName() << "..." << endl;
1553 detector->SDigits2Digits();
1556 cout << "Digits2Reco: Processing " << detector->GetName() << "..." << endl;
1557 detector->Digits2Reco();
1566 //_____________________________________________________________________________
1567 void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min,
1568 Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max,
1569 Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener)
1572 // Generates lego plots of:
1573 // - radiation length map phi vs theta
1574 // - radiation length map phi vs eta
1575 // - interaction length map
1576 // - g/cm2 length map
1578 // ntheta bins in theta, eta
1579 // themin minimum angle in theta (degrees)
1580 // themax maximum angle in theta (degrees)
1582 // phimin minimum angle in phi (degrees)
1583 // phimax maximum angle in phi (degrees)
1584 // rmin minimum radius
1585 // rmax maximum radius
1588 // The number of events generated = ntheta*nphi
1589 // run input parameters in macro setup (default="Config.C")
1591 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1594 <img src="picts/AliRunLego1.gif">
1599 <img src="picts/AliRunLego2.gif">
1604 <img src="picts/AliRunLego3.gif">
1609 // check if initialisation has been done
1610 if (!fInitDone) InitMC(setup);
1611 //Save current generator
1612 AliGenerator *gen=Generator();
1614 // Set new generator
1615 if (!gener) gener = new AliLegoGenerator();
1616 ResetGenerator(gener);
1618 // Configure Generator
1619 gener->SetRadiusRange(rmin, rmax);
1620 gener->SetZMax(zmax);
1621 gener->SetCoor1Range(nc1, c1min, c1max);
1622 gener->SetCoor2Range(nc2, c2min, c2max);
1625 //Create Lego object
1626 fLego = new AliLego("lego",gener);
1628 //Prepare MC for Lego Run
1633 gMC->ProcessRun(nc1*nc2+1);
1635 // Create only the Root event Tree
1638 // End of this run, close files
1640 // Restore current generator
1641 ResetGenerator(gen);
1642 // Delete Lego Object
1643 delete fLego; fLego=0;
1646 //_____________________________________________________________________________
1647 void AliRun::SetConfigFunction(const char * config)
1650 // Set the signature of the function contained in Config.C to configure
1653 fConfigFunction=config;
1656 //_____________________________________________________________________________
1657 void AliRun::SetCurrentTrack(Int_t track)
1660 // Set current track number
1662 fStack->SetCurrentTrack(track);
1665 //_____________________________________________________________________________
1666 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1667 Float_t *vpos, Float_t *polar, Float_t tof,
1668 AliMCProcess mech, Int_t &ntr, Float_t weight)
1670 // Delegate to stack
1672 fStack->SetTrack(done, parent, pdg, pmom, vpos, polar, tof,
1676 //_____________________________________________________________________________
1677 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg,
1678 Double_t px, Double_t py, Double_t pz, Double_t e,
1679 Double_t vx, Double_t vy, Double_t vz, Double_t tof,
1680 Double_t polx, Double_t poly, Double_t polz,
1681 AliMCProcess mech, Int_t &ntr, Float_t weight)
1683 // Delegate to stack
1685 fStack->SetTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
1686 polx, poly, polz, mech, ntr, weight);
1690 //_____________________________________________________________________________
1691 void AliRun::SetHighWaterMark(const Int_t nt)
1694 // Set high water mark for last track in event
1695 fStack->SetHighWaterMark(nt);
1698 //_____________________________________________________________________________
1699 void AliRun::KeepTrack(const Int_t track)
1702 // Delegate to stack
1704 fStack->KeepTrack(track);
1707 //_____________________________________________________________________________
1708 void AliRun::StepManager(Int_t id)
1711 // Called at every step during transport
1715 // --- If lego option, do it and leave
1717 fLego->StepManager();
1720 //Update energy deposition tables
1721 AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
1723 //Call the appropriate stepping routine;
1724 AliModule *det = (AliModule*)fModules->At(id);
1726 fMCQA->StepManager(id);
1732 //_____________________________________________________________________________
1733 void AliRun::Streamer(TBuffer &R__b)
1735 // Stream an object of class AliRun.
1737 if (R__b.IsReading()) {
1738 if (!gAlice) gAlice = this;
1740 AliRun::Class()->ReadBuffer(R__b, this);
1742 gROOT->GetListOfBrowsables()->Add(this,"Run");
1744 fTreeE = (TTree*)gDirectory->Get("TE");
1746 fTreeE->SetBranchAddress("Header", &fHeader);
1749 else Error("Streamer","cannot find Header Tree\n");
1750 fTreeE->GetEntry(0);
1754 AliRun::Class()->WriteBuffer(R__b, this);
1759 //___________________________________________________________________________
1760 Int_t AliRun::CurrentTrack() const {
1762 // Returns current track
1764 return fStack->CurrentTrack();
1767 //___________________________________________________________________________
1768 Int_t AliRun::GetNtrack() const {
1770 // Returns number of tracks in stack
1772 return fStack->GetNtrack();
1775 //___________________________________________________________________________
1776 TObjArray* AliRun::Particles() {
1778 // Returns pointer to Particles array
1780 return fStack->Particles();
1783 //___________________________________________________________________________
1784 TTree* AliRun::TreeK() {
1786 // Returns pointer to the TreeK array
1788 return fStack->TreeK();
1792 void AliRun::SetGenEventHeader(AliGenEventHeader* header)
1794 fHeader->SetGenEventHeader(header);