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.81 2001/12/19 14:46:26 morsch
19 Add possibility to disable StepManager() for each module separately.
21 Revision 1.80 2001/10/21 18:22:55 hristov
22 BranchOld replaced by Branch. It works correctly with Root 2.02.xx
24 Revision 1.79 2001/10/09 18:00:35 hristov
25 Temporary fix to provide unique event number in the simulation (J.Chudoba)
27 Revision 1.78 2001/10/04 15:30:56 hristov
28 Changes to accommodate the set of PHOS folders and tasks (Y.Schutz)
30 Revision 1.77 2001/09/04 15:09:11 hristov
31 fTreeE->Branch replaced temporary by fTreeE->BranchOld to avoid data corruption in case of many events per file
33 Revision 1.76 2001/08/03 14:38:35 morsch
34 Use original method to access TreeH.
36 Revision 1.75 2001/07/28 10:52:27 hristov
37 Event number updated correctly (M.Ivanov)
39 Revision 1.74 2001/07/28 10:39:16 morsch
40 GetEventsPerRun() method needed by afterburners added to AliRun.h
41 Corresponding setters and getters have been from AliGenerator.
43 Revision 1.73 2001/07/27 12:34:30 jchudoba
44 remove the dummy argument in fStack->GetEvent call
46 Revision 1.72 2001/07/03 08:10:57 hristov
47 J.Chudoba's changes merged correctly with the HEAD
49 Revision 1.70 2001/06/29 08:01:36 morsch
50 Small correction to the previous.
52 Revision 1.69 2001/06/28 16:27:50 morsch
53 AliReco() with user control of event range.
55 Revision 1.68 2001/06/11 13:14:40 morsch
56 SetAliGenEventHeader() method added.
58 Revision 1.67 2001/06/07 18:24:50 buncic
59 Removed compilation warning in AliConfig initialisation.
61 Revision 1.66 2001/05/22 14:32:40 hristov
64 Revision 1.65 2001/05/21 17:22:51 buncic
65 Fixed problem with missing AliConfig while reading galice.root
67 Revision 1.64 2001/05/16 14:57:22 alibrary
68 New files for folders and Stack
70 Revision 1.62 2001/04/06 11:12:33 morsch
71 Clear fParticles after each event. (Ivana Hrivnacova)
73 Revision 1.61 2001/03/30 07:04:10 morsch
74 Call fGenerator->FinishRun() for final print-outs, cross-section and weight calculations.
76 Revision 1.60 2001/03/21 18:22:30 hristov
77 fParticleFileMap fix (I.Hrivnacova)
79 Revision 1.59 2001/03/12 17:47:03 hristov
80 Changes needed on Sun with CC 5.0
82 Revision 1.58 2001/03/09 14:27:26 morsch
83 Fix for multiple events per file: inhibit decrease of size of fParticleFileMap.
85 Revision 1.57 2001/02/23 17:40:23 buncic
86 All trees needed for simulation created in RunMC(). TreeR and its branches
87 are now created in new RunReco() method.
89 Revision 1.56 2001/02/14 15:45:20 hristov
90 Algorithmic way of getting entry index in fParticleMap. Protection of fParticleFileMap (I.Hrivnacova)
92 Revision 1.55 2001/02/12 15:52:54 buncic
93 Removed OpenBaseFile().
95 Revision 1.54 2001/02/07 10:39:05 hristov
96 Remove default value for argument
98 Revision 1.53 2001/02/06 11:02:26 hristov
99 New SetTrack interface added, added check for unfilled particles in FinishEvent (I.Hrivnacova)
101 Revision 1.52 2001/02/05 16:22:25 buncic
102 Added TreeS to GetEvent().
104 Revision 1.51 2001/02/02 15:16:20 morsch
105 SetHighWaterMark method added to mark last particle in event.
107 Revision 1.50 2001/01/27 10:32:00 hristov
108 Leave the loop when primaries are filled (I.Hrivnacova)
110 Revision 1.49 2001/01/26 19:58:48 hristov
111 Major upgrade of AliRoot code
113 Revision 1.48 2001/01/17 10:50:50 hristov
114 Corrections to destructors
116 Revision 1.47 2000/12/18 10:44:01 morsch
117 Possibility to set field map by passing pointer to objet of type AliMagF via
120 gAlice->SetField(new AliMagFCM("Map2", "$(ALICE_ROOT)/data/field01.dat",2,1.,10.));
122 Revision 1.46 2000/12/14 19:29:27 fca
123 galice.cuts was not read any more
125 Revision 1.45 2000/11/30 07:12:49 alibrary
126 Introducing new Rndm and QA classes
128 Revision 1.44 2000/10/26 13:58:59 morsch
129 Add possibility to choose the lego generator (of type AliGeneratorLego or derived) when running
130 RunLego(). Default is the base class AliGeneratorLego.
132 Revision 1.43 2000/10/09 09:43:17 fca
133 Special remapping of hits for TPC and TRD. End-of-primary action introduced
135 Revision 1.42 2000/10/02 21:28:14 fca
136 Removal of useless dependecies via forward declarations
138 Revision 1.41 2000/07/13 16:19:09 fca
139 Mainly coding conventions + some small bug fixes
141 Revision 1.40 2000/07/12 08:56:25 fca
142 Coding convention correction and warning removal
144 Revision 1.39 2000/07/11 18:24:59 fca
145 Coding convention corrections + few minor bug fixes
147 Revision 1.38 2000/06/20 13:05:45 fca
148 Writing down the TREE headers before job starts
150 Revision 1.37 2000/06/09 20:05:11 morsch
151 Introduce possibility to chose magnetic field version 3: AliMagFDM + field02.dat
153 Revision 1.36 2000/06/08 14:03:58 hristov
154 Only one initializer for a default argument
156 Revision 1.35 2000/06/07 10:13:14 hristov
157 Delete only existent objects.
159 Revision 1.34 2000/05/18 10:45:38 fca
160 Delete Particle Factory properly
162 Revision 1.33 2000/05/16 13:10:40 fca
163 New method IsNewTrack and fix for a problem in Father-Daughter relations
165 Revision 1.32 2000/04/27 10:38:21 fca
166 Correct termination of Lego Run and introduce Lego getter in AliRun
168 Revision 1.31 2000/04/26 10:17:32 fca
169 Changes in Lego for G4 compatibility
171 Revision 1.30 2000/04/18 19:11:40 fca
172 Introduce variable Config.C function signature
174 Revision 1.29 2000/04/07 11:12:34 fca
175 G4 compatibility changes
177 Revision 1.28 2000/04/05 06:51:06 fca
178 Workaround for an HP compiler problem
180 Revision 1.27 2000/03/22 18:08:07 fca
181 Rationalisation of the virtual MC interfaces
183 Revision 1.26 2000/03/22 13:42:26 fca
184 SetGenerator does not replace an existing generator, ResetGenerator does
186 Revision 1.25 2000/02/23 16:25:22 fca
187 AliVMC and AliGeant3 classes introduced
188 ReadEuclid moved from AliRun to AliModule
190 Revision 1.24 2000/01/19 17:17:20 fca
191 Introducing a list of lists of hits -- more hits allowed for detector now
193 Revision 1.23 1999/12/03 11:14:31 fca
194 Fixing previous wrong checking
196 Revision 1.21 1999/11/25 10:40:08 fca
197 Fixing daughters information also in primary tracks
199 Revision 1.20 1999/10/04 18:08:49 fca
200 Adding protection against inconsistent Euclid files
202 Revision 1.19 1999/09/29 07:50:40 fca
203 Introduction of the Copyright and cvs Log
207 ///////////////////////////////////////////////////////////////////////////////
209 // Control class for Alice C++ //
210 // Only one single instance of this class exists. //
211 // The object is created in main program aliroot //
212 // and is pointed by the global gAlice. //
214 // -Supports the list of all Alice Detectors (fModules). //
215 // -Supports the list of particles (fParticles). //
216 // -Supports the Trees. //
217 // -Supports the geometry. //
218 // -Supports the event display. //
221 <img src="picts/AliRunClass.gif">
226 <img src="picts/alirun.gif">
230 ///////////////////////////////////////////////////////////////////////////////
235 #include <iostream.h>
242 #include <TObjectTable.h>
244 #include <TGeometry.h>
246 #include <TBrowser.h>
250 #include "TParticle.h"
252 #include "AliDisplay.h"
255 #include "AliMagFC.h"
256 #include "AliMagFCM.h"
257 #include "AliMagFDM.h"
259 #include "TRandom3.h"
261 #include "AliGenerator.h"
262 #include "AliLegoGenerator.h"
263 #include "AliConfig.h"
264 #include "AliStack.h"
265 #include "AliGenEventHeader.h"
266 #include "AliHeader.h"
268 #include "AliDetector.h"
274 //_____________________________________________________________________________
278 // Default constructor for AliRun
302 fPDGDB = 0; //Particle factory object!
304 fConfigFunction = "\0";
307 fTransParName = "\0";
308 fBaseFileName = ".\0";
312 //_____________________________________________________________________________
313 AliRun::AliRun(const char *name, const char *title)
317 // Constructor for the main processor.
318 // Creates the geometry
319 // Creates the list of Detectors.
320 // Creates the list of particles.
336 fConfigFunction = "Config();";
338 // Set random number generator
339 gRandom = fRandom = new TRandom3();
341 if (gSystem->Getenv("CONFIG_SEED")) {
342 gRandom->SetSeed((UInt_t)atoi(gSystem->Getenv("CONFIG_SEED")));
345 gROOT->GetListOfBrowsables()->Add(this,name);
348 fStack = new AliStack(10000);
349 // create the support list for the various Detectors
350 fModules = new TObjArray(77);
352 // Create the TNode geometry for the event display
354 BuildSimpleGeometry();
356 fHeader = new AliHeader();
363 // Create default mag field
368 // Prepare the tracking medium lists
369 fImedia = new TArrayI(1000);
370 for(i=0;i<1000;i++) (*fImedia)[i]=-99;
373 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
375 AliConfig::Instance()->Add(fPDGDB);
377 // Create HitLists list
378 fHitLists = new TList();
381 fBaseFileName = ".\0";
387 //_____________________________________________________________________________
391 // Default AliRun destructor
416 //_____________________________________________________________________________
417 void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
420 // Add a hit to detector id
422 TObjArray &dets = *fModules;
423 if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits);
426 //_____________________________________________________________________________
427 void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
430 // Add digit to detector id
432 TObjArray &dets = *fModules;
433 if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits);
436 //_____________________________________________________________________________
437 void AliRun::Browse(TBrowser *b)
440 // Called when the item "Run" is clicked on the left pane
441 // of the Root browser.
442 // It displays the Root Trees and all detectors.
444 if(!fStack) fStack=fHeader->Stack();
445 TTree* pTreeK = fStack->TreeK();
447 if (pTreeK) b->Add(pTreeK,pTreeK->GetName());
448 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
449 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
450 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
451 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
452 if (fTreeS) b->Add(fTreeS,fTreeS->GetName());
454 TIter next(fModules);
456 while((detector = (AliModule*)next())) {
457 b->Add(detector,detector->GetName());
459 b->Add(fMCQA,"AliMCQA");
462 //_____________________________________________________________________________
466 // Initialize Alice geometry
471 //_____________________________________________________________________________
472 void AliRun::BuildSimpleGeometry()
475 // Create a simple TNode geometry used by Root display engine
477 // Initialise geometry
479 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
480 new TMaterial("void","Vacuum",0,0,0); //Everything is void
481 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
482 brik->SetVisibility(0);
483 new TNode("alice","alice","S_alice");
486 //_____________________________________________________________________________
487 void AliRun::CleanDetectors()
490 // Clean Detectors at the end of event
492 TIter next(fModules);
494 while((detector = (AliModule*)next())) {
495 detector->FinishEvent();
499 //_____________________________________________________________________________
500 Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
503 // Return the distance from the mouse to the AliRun object
509 //_____________________________________________________________________________
510 void AliRun::DumpPart (Int_t i) const
513 // Dumps particle i in the stack
518 //_____________________________________________________________________________
519 void AliRun::DumpPStack () const
522 // Dumps the particle stack
524 fStack->DumpPStack();
527 //_____________________________________________________________________________
528 void AliRun::SetField(AliMagF* magField)
530 // Set Magnetic Field Map
535 //_____________________________________________________________________________
536 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
537 Float_t maxField, char* filename)
540 // Set magnetic field parameters
541 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
542 // version Magnetic field map version (only 1 active now)
543 // scale Scale factor for the magnetic field
544 // maxField Maximum value for the magnetic field
547 // --- Sanity check on mag field flags
548 if(fField) delete fField;
550 fField = new AliMagFC("Map1"," ",type,scale,maxField);
551 } else if(version<=2) {
552 fField = new AliMagFCM("Map2-3",filename,type,scale,maxField);
554 } else if(version==3) {
555 fField = new AliMagFDM("Map4",filename,type,scale,maxField);
558 Warning("SetField","Invalid map %d\n",version);
562 //_____________________________________________________________________________
563 void AliRun::PreTrack()
565 TObjArray &dets = *fModules;
568 for(Int_t i=0; i<=fNdets; i++)
569 if((module = (AliModule*)dets[i]))
575 //_____________________________________________________________________________
576 void AliRun::PostTrack()
578 TObjArray &dets = *fModules;
581 for(Int_t i=0; i<=fNdets; i++)
582 if((module = (AliModule*)dets[i]))
586 //_____________________________________________________________________________
587 void AliRun::FinishPrimary()
590 // Called at the end of each primary track
593 // static Int_t count=0;
594 // const Int_t times=10;
595 // This primary is finished, purify stack
596 fStack->PurifyKine();
598 TIter next(fModules);
600 while((detector = (AliModule*)next())) {
601 detector->FinishPrimary();
604 // Write out hits if any
605 if (gAlice->TreeH()) {
606 gAlice->TreeH()->Fill();
610 // if(++count%times==1) gObjectTable->Print();
613 //_____________________________________________________________________________
614 void AliRun::BeginPrimary()
617 // Called at the beginning of each primary track
625 //_____________________________________________________________________________
626 void AliRun::FinishEvent()
629 // Called at the end of the event.
633 if(fLego) fLego->FinishEvent();
635 //Update the energy deposit tables
637 for(i=0;i<fEventEnergy.GetSize();i++) {
638 fSummEnergy[i]+=fEventEnergy[i];
639 fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
644 // Update Header information
646 fHeader->SetNprimary(fStack->GetNprimary());
647 fHeader->SetNtrack(fStack->GetNtrack());
650 // Write out the kinematics
651 fStack->FinishEvent();
653 // Write out the event Header information
655 fHeader->SetStack(fStack);
660 // Write Tree headers
661 TTree* pTreeK = fStack->TreeK();
662 if (pTreeK) pTreeK->Write(0,TObject::kOverwrite);
663 if (fTreeH) fTreeH->Write(0,TObject::kOverwrite);
669 //_____________________________________________________________________________
670 void AliRun::FinishRun()
673 // Called at the end of the run.
677 if(fLego) fLego->FinishRun();
679 // Clean detector information
680 TIter next(fModules);
682 while((detector = (AliModule*)next())) {
683 detector->FinishRun();
686 //Output energy summary tables
689 TFile *file = fTreeE->GetCurrentFile();
693 fTreeE->Write(0,TObject::kOverwrite);
695 // Write AliRun info and all detectors parameters
696 Write(0,TObject::kOverwrite);
698 // Clean tree information
703 delete fTreeH; fTreeH = 0;
706 delete fTreeD; fTreeD = 0;
709 delete fTreeR; fTreeR = 0;
712 // delete fTreeE; fTreeE = 0;
715 delete fTreeS; fTreeS = 0;
717 fGenerator->FinishRun();
723 //_____________________________________________________________________________
724 void AliRun::FlagTrack(Int_t track)
728 fStack->FlagTrack(track);
731 //_____________________________________________________________________________
732 void AliRun::EnergySummary()
735 // Print summary of deposited energy
741 Int_t kn, i, left, j, id;
742 const Float_t kzero=0;
743 Int_t ievent=fHeader->GetEvent()+1;
745 // Energy loss information
747 printf("***************** Energy Loss Information per event (GEV) *****************\n");
748 for(kn=1;kn<fEventEnergy.GetSize();kn++) {
751 fEventEnergy[ndep]=kn;
756 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,kzero))/ed;
759 fSummEnergy[ndep]=ed;
760 fSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,kzero));
765 for(kn=0;kn<(ndep-1)/3+1;kn++) {
767 for(i=0;i<(3<left?3:left);i++) {
769 id=Int_t (fEventEnergy[j]+0.1);
770 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]);
775 // Relative energy loss in different detectors
776 printf("******************** Relative Energy Loss per event ********************\n");
777 printf("Total energy loss per event %10.3f GeV\n",edtot);
778 for(kn=0;kn<(ndep-1)/5+1;kn++) {
780 for(i=0;i<(5<left?5:left);i++) {
782 id=Int_t (fEventEnergy[j]+0.1);
783 printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot);
787 for(kn=0;kn<75;kn++) printf("*");
791 // Reset the TArray's
792 // fEventEnergy.Set(0);
793 // fSummEnergy.Set(0);
794 // fSum2Energy.Set(0);
797 //_____________________________________________________________________________
798 AliModule *AliRun::GetModule(const char *name) const
801 // Return pointer to detector from name
803 return (AliModule*)fModules->FindObject(name);
806 //_____________________________________________________________________________
807 AliDetector *AliRun::GetDetector(const char *name) const
810 // Return pointer to detector from name
812 return (AliDetector*)fModules->FindObject(name);
815 //_____________________________________________________________________________
816 Int_t AliRun::GetModuleID(const char *name) const
819 // Return galice internal detector identifier from name
822 TObject *mod=fModules->FindObject(name);
823 if(mod) i=fModules->IndexOf(mod);
827 //_____________________________________________________________________________
828 Int_t AliRun::GetEvent(Int_t event)
831 // Connect the Trees Kinematics and Hits for event # event
832 // Set branch addresses
835 // Reset existing structures
840 // Delete Trees already connected
841 if (fTreeH) { delete fTreeH; fTreeH = 0;}
842 if (fTreeD) { delete fTreeD; fTreeD = 0;}
843 if (fTreeR) { delete fTreeR; fTreeR = 0;}
844 if (fTreeS) { delete fTreeS; fTreeS = 0;}
846 // Create the particle stack
847 if (fHeader) delete fHeader;
850 // Get header from file
852 fTreeE->SetBranchAddress("Header", &fHeader);
854 if (!fTreeE->GetEntry(event)) {
855 Error("GetEvent","Cannot find event:%d\n",event);
860 Error("GetEvent","Cannot find Header Tree (TE)\n");
864 // Get the stack from the header, set fStack to 0 if it
865 // fails to get event
866 if (fStack) delete fStack;
867 fStack = fHeader->Stack();
869 if (!fStack->GetEvent(event)) fStack = 0;
873 TFile *file = fTreeE->GetCurrentFile();
878 // Get Hits Tree header from file
879 sprintf(treeName,"TreeH%d",event);
880 fTreeH = (TTree*)gDirectory->Get(treeName);
882 Error("GetEvent","cannot find Hits Tree for event:%d\n",event);
885 // Get Digits Tree header from file
886 sprintf(treeName,"TreeD%d",event);
887 fTreeD = (TTree*)gDirectory->Get(treeName);
889 // Warning("GetEvent","cannot find Digits Tree for event:%d\n",event);
894 // Get SDigits Tree header from file
895 sprintf(treeName,"TreeS%d",event);
896 fTreeS = (TTree*)gDirectory->Get(treeName);
898 // Warning("GetEvent","cannot find SDigits Tree for event:%d\n",event);
903 // Get Reconstruct Tree header from file
904 sprintf(treeName,"TreeR%d",event);
905 fTreeR = (TTree*)gDirectory->Get(treeName);
907 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
912 // Set Trees branch addresses
913 TIter next(fModules);
915 while((detector = (AliModule*)next())) {
916 detector->SetTreeAddress();
919 fEvent=event; //MI change
921 return fHeader->GetNtrack();
924 //_____________________________________________________________________________
925 TGeometry *AliRun::GetGeometry()
928 // Import Alice geometry from current file
929 // Return pointer to geometry object
931 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
933 // Unlink and relink nodes in detectors
934 // This is bad and there must be a better way...
937 TIter next(fModules);
939 while((detector = (AliModule*)next())) {
940 TList *dnodes=detector->Nodes();
943 for ( j=0; j<dnodes->GetSize(); j++) {
944 node = (TNode*) dnodes->At(j);
945 node1 = fGeometry->GetNode(node->GetName());
946 dnodes->Remove(node);
947 dnodes->AddAt(node1,j);
953 //_____________________________________________________________________________
954 void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
955 Float_t &e, Float_t *vpos, Float_t *polar,
960 fStack->GetNextTrack(mtrack, ipart, pmom, e, vpos, polar, tof);
963 //_____________________________________________________________________________
964 Int_t AliRun::GetPrimary(Int_t track) const
967 // return number of primary that has generated track
969 return fStack->GetPrimary(track);
972 //_____________________________________________________________________________
973 void AliRun::InitMC(const char *setup)
976 // Initialize the Alice setup
980 Warning("Init","Cannot initialise AliRun twice!\n");
984 gROOT->LoadMacro(setup);
985 gInterpreter->ProcessLine(fConfigFunction.Data());
988 gMC->DefineParticles(); //Create standard MC particles
990 TObject *objfirst, *objlast;
992 fNdets = fModules->GetLast()+1;
995 //=================Create Materials and geometry
998 // Added also after in case of interactive initialisation of modules
999 fNdets = fModules->GetLast()+1;
1001 TIter next(fModules);
1002 AliModule *detector;
1003 while((detector = (AliModule*)next())) {
1004 detector->SetTreeAddress();
1005 objlast = gDirectory->GetList()->Last();
1007 // Add Detector histograms in Detector list of histograms
1008 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
1009 else objfirst = gDirectory->GetList()->First();
1011 detector->Histograms()->Add(objfirst);
1012 objfirst = gDirectory->GetList()->After(objfirst);
1015 ReadTransPar(); //Read the cuts for all materials
1017 MediaTable(); //Build the special IMEDIA table
1019 //Initialise geometry deposition table
1020 fEventEnergy.Set(gMC->NofVolumes()+1);
1021 fSummEnergy.Set(gMC->NofVolumes()+1);
1022 fSum2Energy.Set(gMC->NofVolumes()+1);
1024 //Compute cross-sections
1025 gMC->BuildPhysics();
1027 //Write Geometry object to current file.
1032 fMCQA = new AliMCQA(fNdets);
1034 AliConfig::Instance();
1036 // Save stuff at the beginning of the file to avoid file corruption
1040 //_____________________________________________________________________________
1041 void AliRun::MediaTable()
1044 // Built media table to get from the media number to
1047 Int_t kz, nz, idt, lz, i, k, ind;
1049 TObjArray &dets = *gAlice->Detectors();
1052 // For all detectors
1053 for (kz=0;kz<fNdets;kz++) {
1054 // If detector is defined
1055 if((det=(AliModule*) dets[kz])) {
1056 TArrayI &idtmed = *(det->GetIdtmed());
1057 for(nz=0;nz<100;nz++) {
1058 // Find max and min material number
1059 if((idt=idtmed[nz])) {
1060 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
1061 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
1064 if(det->LoMedium() > det->HiMedium()) {
1065 det->LoMedium() = 0;
1066 det->HiMedium() = 0;
1068 if(det->HiMedium() > fImedia->GetSize()) {
1069 Error("MediaTable","Increase fImedia from %d to %d",
1070 fImedia->GetSize(),det->HiMedium());
1073 // Tag all materials in rage as belonging to detector kz
1074 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
1081 // Print summary table
1082 printf(" Traking media ranges:\n");
1083 for(i=0;i<(fNdets-1)/6+1;i++) {
1084 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
1086 det=(AliModule*)dets[ind];
1088 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
1091 printf(" %6s: %3d -> %3d;","NULL",0,0);
1097 //____________________________________________________________________________
1098 void AliRun::SetGenerator(AliGenerator *generator)
1101 // Load the event generator
1103 if(!fGenerator) fGenerator = generator;
1106 //____________________________________________________________________________
1107 void AliRun::ResetGenerator(AliGenerator *generator)
1110 // Load the event generator
1114 Warning("ResetGenerator","Replacing generator %s with %s\n",
1115 fGenerator->GetName(),generator->GetName());
1117 Warning("ResetGenerator","Replacing generator %s with NULL\n",
1118 fGenerator->GetName());
1119 fGenerator = generator;
1122 //____________________________________________________________________________
1123 void AliRun::SetTransPar(char *filename)
1125 fTransParName = filename;
1128 //____________________________________________________________________________
1129 void AliRun::SetBaseFile(char *filename)
1131 fBaseFileName = filename;
1134 //____________________________________________________________________________
1135 void AliRun::ReadTransPar()
1138 // Read filename to set the transport parameters
1142 const Int_t kncuts=10;
1143 const Int_t knflags=11;
1144 const Int_t knpars=kncuts+knflags;
1145 const char kpars[knpars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
1146 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
1147 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
1148 "MULS","PAIR","PHOT","RAYL"};
1152 Float_t cut[kncuts];
1153 Int_t flag[knflags];
1154 Int_t i, itmed, iret, ktmed, kz;
1157 // See whether the file is there
1158 filtmp=gSystem->ExpandPathName(fTransParName.Data());
1159 lun=fopen(filtmp,"r");
1162 Warning("ReadTransPar","File %s does not exist!\n",fTransParName.Data());
1167 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1168 printf(" *%59s\n","*");
1169 printf(" * Please check carefully what you are doing!%10s\n","*");
1170 printf(" *%59s\n","*");
1174 // Initialise cuts and flags
1175 for(i=0;i<kncuts;i++) cut[i]=-99;
1176 for(i=0;i<knflags;i++) flag[i]=-99;
1178 for(i=0;i<256;i++) line[i]='\0';
1179 // Read up to the end of line excluded
1180 iret=fscanf(lun,"%[^\n]",line);
1185 printf(" *%59s\n","*");
1186 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1190 // Read the end of line
1193 if(line[0]=='*') continue;
1195 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",
1196 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
1197 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
1198 &flag[8],&flag[9],&flag[10]);
1202 Warning("ReadTransPar","Error reading file %s\n",fTransParName.Data());
1205 // Check that the module exist
1206 AliModule *mod = GetModule(detName);
1208 // Get the array of media numbers
1209 TArrayI &idtmed = *mod->GetIdtmed();
1210 // Check that the tracking medium code is valid
1211 if(0<=itmed && itmed < 100) {
1212 ktmed=idtmed[itmed];
1214 Warning("ReadTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
1217 // Set energy thresholds
1218 for(kz=0;kz<kncuts;kz++) {
1220 if(fDebug) printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
1221 kpars[kz],cut[kz],itmed,mod->GetName());
1222 gMC->Gstpar(ktmed,kpars[kz],cut[kz]);
1225 // Set transport mechanisms
1226 for(kz=0;kz<knflags;kz++) {
1228 if(fDebug) printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
1229 kpars[kncuts+kz],flag[kz],itmed,mod->GetName());
1230 gMC->Gstpar(ktmed,kpars[kncuts+kz],Float_t(flag[kz]));
1234 Warning("ReadTransPar","Invalid medium code %d *\n",itmed);
1238 if(fDebug) printf("%s::ReadTransParModule: %s not present\n",ClassName(),detName);
1245 //_____________________________________________________________________________
1246 void AliRun::MakeTree(Option_t *option, const char *file)
1249 // Create the ROOT trees
1250 // Loop on all detectors to create the Root branch (if any)
1256 const char *oK = strstr(option,"K");
1257 const char *oH = strstr(option,"H");
1258 const char *oE = strstr(option,"E");
1259 const char *oD = strstr(option,"D");
1260 const char *oR = strstr(option,"R");
1261 const char *oS = strstr(option,"S");
1264 TDirectory *cwd = gDirectory;
1266 TBranch *branch = 0;
1268 if (oK) fStack->MakeTree(fEvent, file);
1270 if (oE && !fTreeE) {
1271 fTreeE = new TTree("TE","Header");
1272 // branch = fTreeE->Branch("Header", "AliHeader", &fHeader, 4000, 0);
1273 branch = fTreeE->Branch("Header", "AliHeader", &fHeader, 4000, 0);
1274 branch->SetAutoDelete(kFALSE);
1275 TFolder *folder = (TFolder *)gROOT->FindObjectAny("/Folders/RunMC/Event/Header");
1276 if (folder) folder->Add(fHeader);
1277 // branch = fTreeE->Branch("Stack","AliStack", &fStack, 4000, 0);
1278 // branch->SetAutoDelete(kFALSE);
1279 // if (folder) folder->Add(fStack);
1280 fTreeE->Write(0,TObject::kOverwrite);
1283 if (file && branch) {
1284 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
1285 sprintf(outFile,"%s/%s",GetBaseFile(),file);
1286 branch->SetFile(outFile);
1287 TIter next( branch->GetListOfBranches());
1288 while ((branch=(TBranch*)next())) {
1289 branch->SetFile(outFile);
1292 printf("* MakeBranch * Diverting Branch %s to file %s\n", branch->GetName(),file);
1297 if (oH && !fTreeH) {
1298 sprintf(hname,"TreeH%d",fEvent);
1299 fTreeH = new TTree(hname,"Hits");
1300 fTreeH->SetAutoSave(1000000000); //no autosave
1301 fTreeH->Write(0,TObject::kOverwrite);
1303 if (oD && !fTreeD) {
1304 sprintf(hname,"TreeD%d",fEvent);
1305 fTreeD = new TTree(hname,"Digits");
1306 fTreeD->Write(0,TObject::kOverwrite);
1308 if (oS && !fTreeS) {
1309 sprintf(hname,"TreeS%d",fEvent);
1310 fTreeS = new TTree(hname,"SDigits");
1311 fTreeS->Write(0,TObject::kOverwrite);
1313 if (oR && !fTreeR) {
1314 sprintf(hname,"TreeR%d",fEvent);
1315 fTreeR = new TTree(hname,"Reconstruction");
1316 fTreeR->Write(0,TObject::kOverwrite);
1320 // Create a branch for hits/digits for each detector
1321 // Each branch is a TClonesArray. Each data member of the Hits classes
1322 // will be in turn a subbranch of the detector master branch
1323 TIter next(fModules);
1324 AliModule *detector;
1325 while((detector = (AliModule*)next())) {
1326 if (oH) detector->MakeBranch(option,file);
1330 //_____________________________________________________________________________
1331 TParticle* AliRun::Particle(Int_t i)
1333 return fStack->Particle(i);
1336 //_____________________________________________________________________________
1337 void AliRun::BeginEvent()
1339 // Clean-up previous event
1341 fEventEnergy.Reset();
1342 // Clean detector information
1349 // Reset all Detectors & kinematics & trees
1353 // Initialise event header
1354 fHeader->Reset(fRun,fEvent,fEventNrInRun);
1356 fStack->BeginEvent(fEvent);
1360 fLego->BeginEvent();
1373 sprintf(hname,"TreeH%d",fEvent);
1374 fTreeH->SetName(hname);
1378 sprintf(hname,"TreeD%d",fEvent);
1379 fTreeD->SetName(hname);
1380 fTreeD->Write(0,TObject::kOverwrite);
1384 sprintf(hname,"TreeS%d",fEvent);
1385 fTreeS->SetName(hname);
1386 fTreeS->Write(0,TObject::kOverwrite);
1390 sprintf(hname,"TreeR%d",fEvent);
1391 fTreeR->SetName(hname);
1392 fTreeR->Write(0,TObject::kOverwrite);
1395 //_____________________________________________________________________________
1396 void AliRun::ResetDigits()
1399 // Reset all Detectors digits
1401 TIter next(fModules);
1402 AliModule *detector;
1403 while((detector = (AliModule*)next())) {
1404 detector->ResetDigits();
1408 //_____________________________________________________________________________
1409 void AliRun::ResetSDigits()
1412 // Reset all Detectors digits
1414 TIter next(fModules);
1415 AliModule *detector;
1416 while((detector = (AliModule*)next())) {
1417 detector->ResetSDigits();
1421 //_____________________________________________________________________________
1422 void AliRun::ResetHits()
1425 // Reset all Detectors hits
1427 TIter next(fModules);
1428 AliModule *detector;
1429 while((detector = (AliModule*)next())) {
1430 detector->ResetHits();
1434 //_____________________________________________________________________________
1435 void AliRun::ResetPoints()
1438 // Reset all Detectors points
1440 TIter next(fModules);
1441 AliModule *detector;
1442 while((detector = (AliModule*)next())) {
1443 detector->ResetPoints();
1447 //_____________________________________________________________________________
1448 void AliRun::RunMC(Int_t nevent, const char *setup)
1451 // Main function to be called to process a galice run
1453 // Root > gAlice.Run();
1454 // a positive number of events will cause the finish routine
1457 fEventsPerRun = nevent;
1458 // check if initialisation has been done
1459 if (!fInitDone) InitMC(setup);
1461 // Create the Root Tree with one branch per detector
1465 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1466 MakeTree("K","Kine.root");
1467 MakeTree("H","Hits.root");
1472 gMC->ProcessRun(nevent);
1474 // End of this run, close files
1475 if(nevent>0) FinishRun();
1478 //_____________________________________________________________________________
1479 void AliRun::RunReco(const char *selected, Int_t first, Int_t last)
1482 // Main function to be called to reconstruct Alice event
1484 cout << "Found "<< gAlice->TreeE()->GetEntries() << "events" << endl;
1485 Int_t nFirst = first;
1486 Int_t nLast = (last < 0)? (Int_t) gAlice->TreeE()->GetEntries() : last;
1488 for (Int_t nevent = nFirst; nevent <= nLast; nevent++) {
1489 cout << "Processing event "<< nevent << endl;
1492 Digits2Reco(selected);
1496 //_____________________________________________________________________________
1498 void AliRun::Hits2Digits(const char *selected)
1501 // Convert Hits to sumable digits
1503 for (Int_t nevent=0; nevent<gAlice->TreeE()->GetEntries(); nevent++) {
1506 Hits2SDigits(selected);
1507 SDigits2Digits(selected);
1512 //_____________________________________________________________________________
1514 void AliRun::Tree2Tree(Option_t *option, const char *selected)
1517 // Function to transform the content of
1519 // - TreeH to TreeS (option "S")
1520 // - TreeS to TreeD (option "D")
1521 // - TreeD to TreeR (option "R")
1523 // If multiple options are specified ("SDR"), transformation will be done in sequence for
1524 // selected detector and for all detectors if none is selected (detector string
1525 // can contain blank separated list of detector names).
1528 const char *oS = strstr(option,"S");
1529 const char *oD = strstr(option,"D");
1530 const char *oR = strstr(option,"R");
1532 TObjArray *detectors = Detectors();
1534 TIter next(detectors);
1536 AliDetector *detector = 0;
1538 TDirectory *cwd = gDirectory;
1542 while((detector = (AliDetector*)next())) {
1544 if (strcmp(detector->GetName(),selected)) continue;
1545 if (detector->IsActive()){
1546 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1548 sprintf(outFile,"SDigits.%s.root",detector->GetName());
1549 detector->MakeBranch("S",outFile);
1552 sprintf(outFile,"Digits.%s.root",detector->GetName());
1553 detector->MakeBranch("D",outFile);
1556 sprintf(outFile,"Reco.%s.root",detector->GetName());
1557 detector->MakeBranch("R",outFile);
1560 detector->MakeBranch(option);
1566 cout << "Hits2SDigits: Processing " << detector->GetName() << "..." << endl;
1567 detector->Hits2SDigits();
1570 cout << "SDigits2Digits: Processing " << detector->GetName() << "..." << endl;
1571 detector->SDigits2Digits();
1574 cout << "Digits2Reco: Processing " << detector->GetName() << "..." << endl;
1575 detector->Digits2Reco();
1584 //_____________________________________________________________________________
1585 void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min,
1586 Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max,
1587 Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener)
1590 // Generates lego plots of:
1591 // - radiation length map phi vs theta
1592 // - radiation length map phi vs eta
1593 // - interaction length map
1594 // - g/cm2 length map
1596 // ntheta bins in theta, eta
1597 // themin minimum angle in theta (degrees)
1598 // themax maximum angle in theta (degrees)
1600 // phimin minimum angle in phi (degrees)
1601 // phimax maximum angle in phi (degrees)
1602 // rmin minimum radius
1603 // rmax maximum radius
1606 // The number of events generated = ntheta*nphi
1607 // run input parameters in macro setup (default="Config.C")
1609 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1612 <img src="picts/AliRunLego1.gif">
1617 <img src="picts/AliRunLego2.gif">
1622 <img src="picts/AliRunLego3.gif">
1627 // check if initialisation has been done
1628 if (!fInitDone) InitMC(setup);
1629 //Save current generator
1630 AliGenerator *gen=Generator();
1632 // Set new generator
1633 if (!gener) gener = new AliLegoGenerator();
1634 ResetGenerator(gener);
1636 // Configure Generator
1637 gener->SetRadiusRange(rmin, rmax);
1638 gener->SetZMax(zmax);
1639 gener->SetCoor1Range(nc1, c1min, c1max);
1640 gener->SetCoor2Range(nc2, c2min, c2max);
1643 //Create Lego object
1644 fLego = new AliLego("lego",gener);
1646 //Prepare MC for Lego Run
1651 gMC->ProcessRun(nc1*nc2+1);
1653 // Create only the Root event Tree
1656 // End of this run, close files
1658 // Restore current generator
1659 ResetGenerator(gen);
1660 // Delete Lego Object
1661 delete fLego; fLego=0;
1664 //_____________________________________________________________________________
1665 void AliRun::SetConfigFunction(const char * config)
1668 // Set the signature of the function contained in Config.C to configure
1671 fConfigFunction=config;
1674 //_____________________________________________________________________________
1675 void AliRun::SetCurrentTrack(Int_t track)
1678 // Set current track number
1680 fStack->SetCurrentTrack(track);
1683 //_____________________________________________________________________________
1684 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1685 Float_t *vpos, Float_t *polar, Float_t tof,
1686 AliMCProcess mech, Int_t &ntr, Float_t weight, Int_t is)
1688 // Delegate to stack
1690 fStack->SetTrack(done, parent, pdg, pmom, vpos, polar, tof,
1691 mech, ntr, weight, is);
1694 //_____________________________________________________________________________
1695 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg,
1696 Double_t px, Double_t py, Double_t pz, Double_t e,
1697 Double_t vx, Double_t vy, Double_t vz, Double_t tof,
1698 Double_t polx, Double_t poly, Double_t polz,
1699 AliMCProcess mech, Int_t &ntr, Float_t weight, Int_t is)
1701 // Delegate to stack
1703 fStack->SetTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
1704 polx, poly, polz, mech, ntr, weight, is);
1708 //_____________________________________________________________________________
1709 void AliRun::SetHighWaterMark(const Int_t nt)
1712 // Set high water mark for last track in event
1713 fStack->SetHighWaterMark(nt);
1716 //_____________________________________________________________________________
1717 void AliRun::KeepTrack(const Int_t track)
1720 // Delegate to stack
1722 fStack->KeepTrack(track);
1725 //_____________________________________________________________________________
1726 void AliRun::StepManager(Int_t id)
1729 // Called at every step during transport
1733 // --- If lego option, do it and leave
1735 fLego->StepManager();
1738 //Update energy deposition tables
1739 AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
1741 //Call the appropriate stepping routine;
1742 AliModule *det = (AliModule*)fModules->At(id);
1743 if(det && det->StepManagerIsEnabled()) {
1744 fMCQA->StepManager(id);
1750 //_____________________________________________________________________________
1751 void AliRun::Streamer(TBuffer &R__b)
1753 // Stream an object of class AliRun.
1755 if (R__b.IsReading()) {
1756 if (!gAlice) gAlice = this;
1758 AliRun::Class()->ReadBuffer(R__b, this);
1760 gROOT->GetListOfBrowsables()->Add(this,"Run");
1762 fTreeE = (TTree*)gDirectory->Get("TE");
1764 fTreeE->SetBranchAddress("Header", &fHeader);
1767 else Error("Streamer","cannot find Header Tree\n");
1768 fTreeE->GetEntry(0);
1772 AliRun::Class()->WriteBuffer(R__b, this);
1777 //___________________________________________________________________________
1778 Int_t AliRun::CurrentTrack() const {
1780 // Returns current track
1782 return fStack->CurrentTrack();
1785 //___________________________________________________________________________
1786 Int_t AliRun::GetNtrack() const {
1788 // Returns number of tracks in stack
1790 return fStack->GetNtrack();
1793 //___________________________________________________________________________
1794 TObjArray* AliRun::Particles() {
1796 // Returns pointer to Particles array
1798 return fStack->Particles();
1801 //___________________________________________________________________________
1802 TTree* AliRun::TreeK() {
1804 // Returns pointer to the TreeK array
1806 return fStack->TreeK();
1810 void AliRun::SetGenEventHeader(AliGenEventHeader* header)
1812 fHeader->SetGenEventHeader(header);