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.91 2002/10/29 14:26:49 hristov
19 Code clean-up (F.Carminati)
21 Revision 1.90 2002/10/22 15:02:15 alibrary
22 Introducing Riostream.h
24 Revision 1.89 2002/10/17 16:26:39 hristov
25 Definition of additional particles moved to VMC (I.Hrivnacova)
27 Revision 1.88 2002/10/14 14:57:32 hristov
28 Merging the VirtualMC branch to the main development branch (HEAD)
30 Revision 1.82.4.3 2002/10/14 09:45:57 hristov
31 Updating VirtualMC to v3-09-02
33 Revision 1.82.4.2 2002/06/10 17:54:06 hristov
34 Only one SetGenEventHeader function kept
36 Revision 1.82.4.1 2002/06/10 14:43:06 hristov
39 Revision 1.86 2002/05/28 14:24:57 hristov
40 Correct warning messages
42 Revision 1.85 2002/05/24 13:29:58 hristov
43 AliTrackReference added, AliDisplay modified
45 Revision 1.84 2002/05/21 16:26:07 hristov
46 Find correctly TreeK in case CONFIG_SPLIT_FILE is set (Y.Schutz)
48 Revision 1.83 2002/04/04 13:16:17 jchudoba
49 add possibility to write sdigits, digits and rec. points into separate files
51 Revision 1.82 2002/03/12 11:06:03 morsch
52 Add particle status code to argument list of SetTrack(..).
54 Revision 1.81 2001/12/19 14:46:26 morsch
55 Add possibility to disable StepManager() for each module separately.
57 Revision 1.80 2001/10/21 18:22:55 hristov
58 BranchOld replaced by Branch. It works correctly with Root 2.02.xx
60 Revision 1.79 2001/10/09 18:00:35 hristov
61 Temporary fix to provide unique event number in the simulation (J.Chudoba)
63 Revision 1.78 2001/10/04 15:30:56 hristov
64 Changes to accommodate the set of PHOS folders and tasks (Y.Schutz)
66 Revision 1.77 2001/09/04 15:09:11 hristov
67 fTreeE->Branch replaced temporary by fTreeE->BranchOld to avoid data corruption in case of many events per file
69 Revision 1.76 2001/08/03 14:38:35 morsch
70 Use original method to access TreeH.
72 Revision 1.75 2001/07/28 10:52:27 hristov
73 Event number updated correctly (M.Ivanov)
75 Revision 1.74 2001/07/28 10:39:16 morsch
76 GetEventsPerRun() method needed by afterburners added to AliRun.h
77 Corresponding setters and getters have been from AliGenerator.
79 Revision 1.73 2001/07/27 12:34:30 jchudoba
80 remove the dummy argument in fStack->GetEvent call
82 Revision 1.72 2001/07/03 08:10:57 hristov
83 J.Chudoba's changes merged correctly with the HEAD
85 Revision 1.70 2001/06/29 08:01:36 morsch
86 Small correction to the previous.
88 Revision 1.69 2001/06/28 16:27:50 morsch
89 AliReco() with user control of event range.
91 Revision 1.68 2001/06/11 13:14:40 morsch
92 SetAliGenEventHeader() method added.
94 Revision 1.67 2001/06/07 18:24:50 buncic
95 Removed compilation warning in AliConfig initialisation.
97 Revision 1.66 2001/05/22 14:32:40 hristov
100 Revision 1.65 2001/05/21 17:22:51 buncic
101 Fixed problem with missing AliConfig while reading galice.root
103 Revision 1.64 2001/05/16 14:57:22 alibrary
104 New files for folders and Stack
106 Revision 1.62 2001/04/06 11:12:33 morsch
107 Clear fParticles after each event. (Ivana Hrivnacova)
109 Revision 1.61 2001/03/30 07:04:10 morsch
110 Call fGenerator->FinishRun() for final print-outs, cross-section and weight calculations.
112 Revision 1.60 2001/03/21 18:22:30 hristov
113 fParticleFileMap fix (I.Hrivnacova)
115 Revision 1.59 2001/03/12 17:47:03 hristov
116 Changes needed on Sun with CC 5.0
118 Revision 1.58 2001/03/09 14:27:26 morsch
119 Fix for multiple events per file: inhibit decrease of size of fParticleFileMap.
121 Revision 1.57 2001/02/23 17:40:23 buncic
122 All trees needed for simulation created in RunMC(). TreeR and its branches
123 are now created in new RunReco() method.
125 Revision 1.56 2001/02/14 15:45:20 hristov
126 Algorithmic way of getting entry index in fParticleMap. Protection of fParticleFileMap (I.Hrivnacova)
128 Revision 1.55 2001/02/12 15:52:54 buncic
129 Removed OpenBaseFile().
131 Revision 1.54 2001/02/07 10:39:05 hristov
132 Remove default value for argument
134 Revision 1.53 2001/02/06 11:02:26 hristov
135 New SetTrack interface added, added check for unfilled particles in FinishEvent (I.Hrivnacova)
137 Revision 1.52 2001/02/05 16:22:25 buncic
138 Added TreeS to GetEvent().
140 Revision 1.51 2001/02/02 15:16:20 morsch
141 SetHighWaterMark method added to mark last particle in event.
143 Revision 1.50 2001/01/27 10:32:00 hristov
144 Leave the loop when primaries are filled (I.Hrivnacova)
146 Revision 1.49 2001/01/26 19:58:48 hristov
147 Major upgrade of AliRoot code
149 Revision 1.48 2001/01/17 10:50:50 hristov
150 Corrections to destructors
152 Revision 1.47 2000/12/18 10:44:01 morsch
153 Possibility to set field map by passing pointer to objet of type AliMagF via
156 gAlice->SetField(new AliMagFCM("Map2", "$(ALICE_ROOT)/data/field01.dat",2,1.,10.));
158 Revision 1.46 2000/12/14 19:29:27 fca
159 galice.cuts was not read any more
161 Revision 1.45 2000/11/30 07:12:49 alibrary
162 Introducing new Rndm and QA classes
164 Revision 1.44 2000/10/26 13:58:59 morsch
165 Add possibility to choose the lego generator (of type AliGeneratorLego or derived) when running
166 RunLego(). Default is the base class AliGeneratorLego.
168 Revision 1.43 2000/10/09 09:43:17 fca
169 Special remapping of hits for TPC and TRD. End-of-primary action introduced
171 Revision 1.42 2000/10/02 21:28:14 fca
172 Removal of useless dependecies via forward declarations
174 Revision 1.41 2000/07/13 16:19:09 fca
175 Mainly coding conventions + some small bug fixes
177 Revision 1.40 2000/07/12 08:56:25 fca
178 Coding convention correction and warning removal
180 Revision 1.39 2000/07/11 18:24:59 fca
181 Coding convention corrections + few minor bug fixes
183 Revision 1.38 2000/06/20 13:05:45 fca
184 Writing down the TREE headers before job starts
186 Revision 1.37 2000/06/09 20:05:11 morsch
187 Introduce possibility to chose magnetic field version 3: AliMagFDM + field02.dat
189 Revision 1.36 2000/06/08 14:03:58 hristov
190 Only one initializer for a default argument
192 Revision 1.35 2000/06/07 10:13:14 hristov
193 Delete only existent objects.
195 Revision 1.34 2000/05/18 10:45:38 fca
196 Delete Particle Factory properly
198 Revision 1.33 2000/05/16 13:10:40 fca
199 New method IsNewTrack and fix for a problem in Father-Daughter relations
201 Revision 1.32 2000/04/27 10:38:21 fca
202 Correct termination of Lego Run and introduce Lego getter in AliRun
204 Revision 1.31 2000/04/26 10:17:32 fca
205 Changes in Lego for G4 compatibility
207 Revision 1.30 2000/04/18 19:11:40 fca
208 Introduce variable Config.C function signature
210 Revision 1.29 2000/04/07 11:12:34 fca
211 G4 compatibility changes
213 Revision 1.28 2000/04/05 06:51:06 fca
214 Workaround for an HP compiler problem
216 Revision 1.27 2000/03/22 18:08:07 fca
217 Rationalisation of the virtual MC interfaces
219 Revision 1.26 2000/03/22 13:42:26 fca
220 SetGenerator does not replace an existing generator, ResetGenerator does
222 Revision 1.25 2000/02/23 16:25:22 fca
223 AliVMC and AliGeant3 classes introduced
224 ReadEuclid moved from AliRun to AliModule
226 Revision 1.24 2000/01/19 17:17:20 fca
227 Introducing a list of lists of hits -- more hits allowed for detector now
229 Revision 1.23 1999/12/03 11:14:31 fca
230 Fixing previous wrong checking
232 Revision 1.21 1999/11/25 10:40:08 fca
233 Fixing daughters information also in primary tracks
235 Revision 1.20 1999/10/04 18:08:49 fca
236 Adding protection against inconsistent Euclid files
238 Revision 1.19 1999/09/29 07:50:40 fca
239 Introduction of the Copyright and cvs Log
243 ///////////////////////////////////////////////////////////////////////////////
245 // Control class for Alice C++ //
246 // Only one single instance of this class exists. //
247 // The object is created in main program aliroot //
248 // and is pointed by the global gAlice. //
250 // -Supports the list of all Alice Detectors (fModules). //
251 // -Supports the list of particles (fParticles). //
252 // -Supports the Trees. //
253 // -Supports the geometry. //
254 // -Supports the event display. //
257 <img src="picts/AliRunClass.gif">
262 <img src="picts/alirun.gif">
266 ///////////////////////////////////////////////////////////////////////////////
271 #include <Riostream.h>
277 #include <TObjectTable.h>
279 #include <TGeometry.h>
281 #include <TBrowser.h>
285 #include "TParticle.h"
287 #include "AliDisplay.h"
290 #include "AliMagFC.h"
291 #include "AliMagFCM.h"
292 #include "AliMagFDM.h"
294 #include "TRandom3.h"
296 #include "AliGenerator.h"
297 #include "AliLegoGenerator.h"
298 #include "AliConfig.h"
299 #include "AliStack.h"
300 #include "AliGenEventHeader.h"
301 #include "AliHeader.h"
302 #include "AliDetector.h"
309 //_______________________________________________________________________
336 fPDGDB(0), //Particle factory object
341 fConfigFunction("\0"),
355 // Default constructor for AliRun
359 //_______________________________________________________________________
360 AliRun::AliRun(const AliRun& arun):
361 TVirtualMCApplication(arun),
387 fPDGDB(0), //Particle factory object
392 fConfigFunction("\0"),
406 // Copy constructor for AliRun
411 //_____________________________________________________________________________
412 AliRun::AliRun(const char *name, const char *title):
413 TVirtualMCApplication(name,title),
419 fHeader(new AliHeader()),
426 fModules(new TObjArray(77)), // Support list for the Detectors
432 fImedia(new TArrayI(1000)),
439 fPDGDB(TDatabasePDG::Instance()), //Particle factory object!
440 fHitLists(new TList()), // Create HitLists list
444 fConfigFunction("Config();"),
445 fRandom(new TRandom3()),
449 fStack(new AliStack(10000)), //Particle stack
458 // Constructor for the main processor.
459 // Creates the geometry
460 // Creates the list of Detectors.
461 // Creates the list of particles.
466 // Set random number generator
469 if (gSystem->Getenv("CONFIG_SEED")) {
470 gRandom->SetSeed(static_cast<UInt_t>(atoi(gSystem->Getenv("CONFIG_SEED"))));
473 // Add to list of browsable
474 gROOT->GetListOfBrowsables()->Add(this,name);
476 // Create the TNode geometry for the event display
477 BuildSimpleGeometry();
479 // Create default mag field
482 // Prepare the tracking medium lists
483 for(Int_t i=0;i<1000;i++) (*fImedia)[i]=-99;
485 // Add particle list to configuration
486 AliConfig::Instance()->Add(fPDGDB);
488 // Set transport parameters
493 //_______________________________________________________________________
497 // Default AliRun destructor
500 if(fTreeE)curfil=fTreeE->GetCurrentFile();
523 // avoid to delete TFile objects not owned by this object
524 // avoid multiple deletions
525 if(curfil == fTreeDFile) fTreeDFile=0;
526 if(curfil == fTreeSFile) fTreeSFile=0;
527 if(curfil == fTreeRFile) fTreeRFile=0;
528 if(fTreeSFile == fTreeDFile) fTreeSFile=0;
529 if(fTreeRFile == fTreeDFile) fTreeRFile=0;
530 if(fTreeRFile == fTreeSFile) fTreeRFile=0;
532 if(fTreeDFile->IsOpen())fTreeDFile->Close();
536 if(fTreeSFile->IsOpen())fTreeSFile->Close();
540 if(fTreeRFile->IsOpen())fTreeRFile->Close();
543 if (gROOT->GetListOfBrowsables())
544 gROOT->GetListOfBrowsables()->Remove(this);
549 //_______________________________________________________________________
550 void AliRun::Copy(AliRun &) const
552 Fatal("Copy","Not implemented!\n");
555 //_______________________________________________________________________
556 void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
559 // Add a hit to detector id
561 TObjArray &dets = *fModules;
562 if(dets[id]) dynamic_cast<AliModule*>(dets[id])->AddHit(track,vol,hits);
565 //_______________________________________________________________________
566 void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
569 // Add digit to detector id
571 TObjArray &dets = *fModules;
572 if(dets[id]) dynamic_cast<AliModule*>(dets[id])->AddDigit(tracks,digits);
575 //_______________________________________________________________________
576 void AliRun::Browse(TBrowser *b)
579 // Called when the item "Run" is clicked on the left pane
580 // of the Root browser.
581 // It displays the Root Trees and all detectors.
583 if(!fStack) fStack=fHeader->Stack();
584 TTree* pTreeK = fStack->TreeK();
586 if (pTreeK) b->Add(pTreeK,pTreeK->GetName());
587 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
588 if (fTreeTR) b->Add(fTreeTR,fTreeH->GetName());
589 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
590 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
591 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
592 if (fTreeS) b->Add(fTreeS,fTreeS->GetName());
594 TIter next(fModules);
596 while((detector = dynamic_cast<AliModule*>(next()))) {
597 b->Add(detector,detector->GetName());
599 b->Add(fMCQA,"AliMCQA");
602 //_______________________________________________________________________
606 // Initialize Alice geometry
611 //_______________________________________________________________________
612 void AliRun::BuildSimpleGeometry()
615 // Create a simple TNode geometry used by Root display engine
617 // Initialise geometry
619 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
620 new TMaterial("void","Vacuum",0,0,0); //Everything is void
621 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
622 brik->SetVisibility(0);
623 new TNode("alice","alice","S_alice");
626 //_______________________________________________________________________
627 void AliRun::CleanDetectors()
630 // Clean Detectors at the end of event
632 TIter next(fModules);
634 while((detector = dynamic_cast<AliModule*>(next()))) {
635 detector->FinishEvent();
639 //_______________________________________________________________________
640 Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
643 // Return the distance from the mouse to the AliRun object
649 //_______________________________________________________________________
650 void AliRun::DumpPart (Int_t i) const
653 // Dumps particle i in the stack
658 //_______________________________________________________________________
659 void AliRun::DumpPStack () const
662 // Dumps the particle stack
664 fStack->DumpPStack();
667 //_______________________________________________________________________
668 void AliRun::SetField(AliMagF* magField)
670 // Set Magnetic Field Map
675 //_______________________________________________________________________
676 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
677 Float_t maxField, char* filename)
680 // Set magnetic field parameters
681 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
682 // version Magnetic field map version (only 1 active now)
683 // scale Scale factor for the magnetic field
684 // maxField Maximum value for the magnetic field
687 // --- Sanity check on mag field flags
688 if(fField) delete fField;
690 fField = new AliMagFC("Map1"," ",type,scale,maxField);
691 } else if(version<=2) {
692 fField = new AliMagFCM("Map2-3",filename,type,scale,maxField);
694 } else if(version==3) {
695 fField = new AliMagFDM("Map4",filename,type,scale,maxField);
698 Warning("SetField","Invalid map %d\n",version);
702 //_______________________________________________________________________
703 void AliRun::FinishRun()
706 // Called at the end of the run.
710 if(fLego) fLego->FinishRun();
712 // Clean detector information
713 TIter next(fModules);
715 while((detector = dynamic_cast<AliModule*>(next()))) {
716 detector->FinishRun();
719 //Output energy summary tables
722 TFile *file = fTreeE->GetCurrentFile();
726 fTreeE->Write(0,TObject::kOverwrite);
728 // Write AliRun info and all detectors parameters
729 Write(0,TObject::kOverwrite);
731 // Clean tree information
736 delete fTreeH; fTreeH = 0;
739 delete fTreeTR; fTreeTR = 0;
742 delete fTreeD; fTreeD = 0;
745 delete fTreeR; fTreeR = 0;
748 // delete fTreeE; fTreeE = 0;
751 delete fTreeS; fTreeS = 0;
753 fGenerator->FinishRun();
759 //_______________________________________________________________________
760 void AliRun::FlagTrack(Int_t track)
764 fStack->FlagTrack(track);
767 //_______________________________________________________________________
768 void AliRun::EnergySummary()
771 // Print summary of deposited energy
777 Int_t kn, i, left, j, id;
778 const Float_t kzero=0;
779 Int_t ievent=fHeader->GetEvent()+1;
781 // Energy loss information
783 printf("***************** Energy Loss Information per event (GEV) *****************\n");
784 for(kn=1;kn<fEventEnergy.GetSize();kn++) {
787 fEventEnergy[ndep]=kn;
792 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,kzero))/ed;
795 fSummEnergy[ndep]=ed;
796 fSum2Energy[ndep]=TMath::Min(static_cast<Float_t>(99.),TMath::Max(ed2,kzero));
801 for(kn=0;kn<(ndep-1)/3+1;kn++) {
803 for(i=0;i<(3<left?3:left);i++) {
805 id=Int_t (fEventEnergy[j]+0.1);
806 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]);
811 // Relative energy loss in different detectors
812 printf("******************** Relative Energy Loss per event ********************\n");
813 printf("Total energy loss per event %10.3f GeV\n",edtot);
814 for(kn=0;kn<(ndep-1)/5+1;kn++) {
816 for(i=0;i<(5<left?5:left);i++) {
818 id=Int_t (fEventEnergy[j]+0.1);
819 printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot);
823 for(kn=0;kn<75;kn++) printf("*");
827 // Reset the TArray's
828 // fEventEnergy.Set(0);
829 // fSummEnergy.Set(0);
830 // fSum2Energy.Set(0);
833 //_______________________________________________________________________
834 AliModule *AliRun::GetModule(const char *name) const
837 // Return pointer to detector from name
839 return dynamic_cast<AliModule*>(fModules->FindObject(name));
842 //_______________________________________________________________________
843 AliDetector *AliRun::GetDetector(const char *name) const
846 // Return pointer to detector from name
848 return dynamic_cast<AliDetector*>(fModules->FindObject(name));
851 //_______________________________________________________________________
852 Int_t AliRun::GetModuleID(const char *name) const
855 // Return galice internal detector identifier from name
858 TObject *mod=fModules->FindObject(name);
859 if(mod) i=fModules->IndexOf(mod);
863 //_______________________________________________________________________
864 Int_t AliRun::GetEvent(Int_t event)
867 // Connect the Trees Kinematics and Hits for event # event
868 // Set branch addresses
871 // Reset existing structures
873 ResetTrackReferences();
877 // Delete Trees already connected
878 if (fTreeH) { delete fTreeH; fTreeH = 0;}
879 if (fTreeTR) { delete fTreeTR; fTreeTR = 0;}
880 if (fTreeD) { delete fTreeD; fTreeD = 0;}
881 if (fTreeR) { delete fTreeR; fTreeR = 0;}
882 if (fTreeS) { delete fTreeS; fTreeS = 0;}
884 // Create the particle stack
885 if (fHeader) delete fHeader;
888 // Get header from file
890 fTreeE->SetBranchAddress("Header", &fHeader);
892 if (!fTreeE->GetEntry(event)) {
893 Error("GetEvent","Cannot find event:%d\n",event);
898 Error("GetEvent","Cannot find Header Tree (TE)\n");
902 // Get the stack from the header, set fStack to 0 if it
903 // fails to get event
905 TFile *file = fTreeE->GetCurrentFile();
910 if (fStack) delete fStack;
911 fStack = fHeader->Stack();
913 if (!fStack->GetEvent(event)) fStack = 0;
916 // Get Hits Tree header from file
917 sprintf(treeName,"TreeH%d",event);
918 fTreeH = dynamic_cast<TTree*>(gDirectory->Get(treeName));
920 Warning("GetEvent","cannot find Hits Tree for event:%d\n",event);
923 // Get TracReferences Tree header from file
924 sprintf(treeName,"TreeTR%d",event);
925 fTreeTR = dynamic_cast<TTree*>(gDirectory->Get(treeName));
927 Warning("GetEvent","cannot find TrackReferences Tree for event:%d\n",event);
930 // get current file name and compare with names containing trees S,D,R
931 TString curfilname=static_cast<TString>(fTreeE->GetCurrentFile()->GetName());
932 if(fTreeDFileName==curfilname)fTreeDFileName="";
933 if(fTreeSFileName==curfilname)fTreeSFileName="";
934 if(fTreeRFileName==curfilname)fTreeRFileName="";
936 // Get Digits Tree header from file
937 sprintf(treeName,"TreeD%d",event);
939 if (!fTreeDFile && fTreeDFileName != "") {
940 InitTreeFile("D",fTreeDFileName);
943 fTreeD = dynamic_cast<TTree*>(fTreeDFile->Get(treeName));
945 fTreeD = dynamic_cast<TTree*>(file->Get(treeName));
948 // Warning("GetEvent","cannot find Digits Tree for event:%d\n",event);
950 if(fTreeDFileName != ""){
951 if(fTreeDFileName==fTreeSFileName) {
953 fTreeSFile = fTreeDFile;
955 if(fTreeDFileName==fTreeRFileName) {
957 fTreeRFile = fTreeDFile;
963 // Get SDigits Tree header from file
964 sprintf(treeName,"TreeS%d",event);
965 if (!fTreeSFile && fTreeSFileName != "") {
966 InitTreeFile("S",fTreeSFileName);
969 fTreeS = dynamic_cast<TTree*>(fTreeSFile->Get(treeName));
971 fTreeS = dynamic_cast<TTree*>(gDirectory->Get(treeName));
974 // Warning("GetEvent","cannot find SDigits Tree for event:%d\n",event);
977 if(fTreeSFileName != ""){
978 if(fTreeSFileName==fTreeRFileName){
980 fTreeRFile = fTreeSFile;
986 // Get Reconstruct Tree header from file
987 sprintf(treeName,"TreeR%d",event);
988 if (!fTreeRFile && fTreeRFileName != "") {
989 InitTreeFile("R",fTreeRFileName);
992 fTreeR = dynamic_cast<TTree*>(fTreeRFile->Get(treeName));
994 fTreeR = dynamic_cast<TTree*>(gDirectory->Get(treeName));
997 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
1002 // Set Trees branch addresses
1003 TIter next(fModules);
1004 AliModule *detector;
1005 while((detector = dynamic_cast<AliModule*>(next()))) {
1006 detector->SetTreeAddress();
1009 fEvent=event; //MI change
1011 return fHeader->GetNtrack();
1014 //_______________________________________________________________________
1015 TGeometry *AliRun::GetGeometry()
1018 // Import Alice geometry from current file
1019 // Return pointer to geometry object
1021 if (!fGeometry) fGeometry = dynamic_cast<TGeometry*>(gDirectory->Get("AliceGeom"));
1023 // Unlink and relink nodes in detectors
1024 // This is bad and there must be a better way...
1027 TIter next(fModules);
1028 AliModule *detector;
1029 while((detector = dynamic_cast<AliModule*>(next()))) {
1030 TList *dnodes=detector->Nodes();
1032 TNode *node, *node1;
1033 for ( j=0; j<dnodes->GetSize(); j++) {
1034 node = dynamic_cast<TNode*>(dnodes->At(j));
1035 node1 = fGeometry->GetNode(node->GetName());
1036 dnodes->Remove(node);
1037 dnodes->AddAt(node1,j);
1043 //_______________________________________________________________________
1044 Int_t AliRun::GetPrimary(Int_t track) const
1047 // return number of primary that has generated track
1049 return fStack->GetPrimary(track);
1052 //_______________________________________________________________________
1053 void AliRun::MediaTable()
1056 // Built media table to get from the media number to
1059 Int_t kz, nz, idt, lz, i, k, ind;
1061 TObjArray &dets = *gAlice->Detectors();
1064 // For all detectors
1065 for (kz=0;kz<fNdets;kz++) {
1066 // If detector is defined
1067 if((det=dynamic_cast<AliModule*>(dets[kz]))) {
1068 TArrayI &idtmed = *(det->GetIdtmed());
1069 for(nz=0;nz<100;nz++) {
1070 // Find max and min material number
1071 if((idt=idtmed[nz])) {
1072 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
1073 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
1076 if(det->LoMedium() > det->HiMedium()) {
1077 det->LoMedium() = 0;
1078 det->HiMedium() = 0;
1080 if(det->HiMedium() > fImedia->GetSize()) {
1081 Error("MediaTable","Increase fImedia from %d to %d",
1082 fImedia->GetSize(),det->HiMedium());
1085 // Tag all materials in rage as belonging to detector kz
1086 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
1093 // Print summary table
1094 printf(" Traking media ranges:\n");
1095 for(i=0;i<(fNdets-1)/6+1;i++) {
1096 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
1098 det=dynamic_cast<AliModule*>(dets[ind]);
1100 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
1103 printf(" %6s: %3d -> %3d;","NULL",0,0);
1109 //_______________________________________________________________________
1110 void AliRun::SetGenerator(AliGenerator *generator)
1113 // Load the event generator
1115 if(!fGenerator) fGenerator = generator;
1118 //_______________________________________________________________________
1119 void AliRun::ResetGenerator(AliGenerator *generator)
1122 // Load the event generator
1126 Warning("ResetGenerator","Replacing generator %s with %s\n",
1127 fGenerator->GetName(),generator->GetName());
1129 Warning("ResetGenerator","Replacing generator %s with NULL\n",
1130 fGenerator->GetName());
1131 fGenerator = generator;
1134 //_______________________________________________________________________
1135 void AliRun::SetTransPar(const char *filename)
1137 fTransParName = filename;
1140 //_______________________________________________________________________
1141 void AliRun::SetBaseFile(const char *filename)
1143 fBaseFileName = filename;
1146 //_______________________________________________________________________
1147 void AliRun::ReadTransPar()
1150 // Read filename to set the transport parameters
1154 const Int_t kncuts=10;
1155 const Int_t knflags=11;
1156 const Int_t knpars=kncuts+knflags;
1157 const char kpars[knpars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
1158 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
1159 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
1160 "MULS","PAIR","PHOT","RAYL"};
1164 Float_t cut[kncuts];
1165 Int_t flag[knflags];
1166 Int_t i, itmed, iret, ktmed, kz;
1169 // See whether the file is there
1170 filtmp=gSystem->ExpandPathName(fTransParName.Data());
1171 lun=fopen(filtmp,"r");
1174 Warning("ReadTransPar","File %s does not exist!\n",fTransParName.Data());
1179 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1180 printf(" *%59s\n","*");
1181 printf(" * Please check carefully what you are doing!%10s\n","*");
1182 printf(" *%59s\n","*");
1186 // Initialise cuts and flags
1187 for(i=0;i<kncuts;i++) cut[i]=-99;
1188 for(i=0;i<knflags;i++) flag[i]=-99;
1190 for(i=0;i<256;i++) line[i]='\0';
1191 // Read up to the end of line excluded
1192 iret=fscanf(lun,"%[^\n]",line);
1197 printf(" *%59s\n","*");
1198 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1202 // Read the end of line
1205 if(line[0]=='*') continue;
1207 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",
1208 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
1209 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
1210 &flag[8],&flag[9],&flag[10]);
1214 Warning("ReadTransPar","Error reading file %s\n",fTransParName.Data());
1217 // Check that the module exist
1218 AliModule *mod = GetModule(detName);
1220 // Get the array of media numbers
1221 TArrayI &idtmed = *mod->GetIdtmed();
1222 // Check that the tracking medium code is valid
1223 if(0<=itmed && itmed < 100) {
1224 ktmed=idtmed[itmed];
1226 Warning("ReadTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
1229 // Set energy thresholds
1230 for(kz=0;kz<kncuts;kz++) {
1232 if(fDebug) printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
1233 kpars[kz],cut[kz],itmed,mod->GetName());
1234 gMC->Gstpar(ktmed,kpars[kz],cut[kz]);
1237 // Set transport mechanisms
1238 for(kz=0;kz<knflags;kz++) {
1240 if(fDebug) printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
1241 kpars[kncuts+kz],flag[kz],itmed,mod->GetName());
1242 gMC->Gstpar(ktmed,kpars[kncuts+kz],Float_t(flag[kz]));
1246 Warning("ReadTransPar","Invalid medium code %d *\n",itmed);
1250 if(fDebug) printf("%s::ReadTransParModule: %s not present\n",ClassName(),detName);
1257 //_______________________________________________________________________
1258 void AliRun::MakeTree(Option_t *option, const char *file)
1261 // Create the ROOT trees
1262 // Loop on all detectors to create the Root branch (if any)
1268 const char *oK = strstr(option,"K");
1269 const char *oH = strstr(option,"H");
1270 const char *oTR = strstr(option,"T");
1271 const char *oE = strstr(option,"E");
1272 const char *oD = strstr(option,"D");
1273 const char *oR = strstr(option,"R");
1274 const char *oS = strstr(option,"S");
1277 TDirectory *cwd = gDirectory;
1279 TBranch *branch = 0;
1281 if (oK) fStack->MakeTree(fEvent, file);
1283 if (oE && !fTreeE) {
1284 fTreeE = new TTree("TE","Header");
1285 // branch = fTreeE->Branch("Header", "AliHeader", &fHeader, 4000, 0);
1286 branch = fTreeE->Branch("Header", "AliHeader", &fHeader, 4000, 0);
1287 branch->SetAutoDelete(kFALSE);
1288 TFolder *folder = dynamic_cast<TFolder *>(gROOT->FindObjectAny("/Folders/RunMC/Event/Header"));
1289 if (folder) folder->Add(fHeader);
1290 // branch = fTreeE->Branch("Stack","AliStack", &fStack, 4000, 0);
1291 // branch->SetAutoDelete(kFALSE);
1292 // if (folder) folder->Add(fStack);
1293 fTreeE->Write(0,TObject::kOverwrite);
1296 if (file && branch) {
1297 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
1298 sprintf(outFile,"%s/%s",GetBaseFile(),file);
1299 branch->SetFile(outFile);
1300 TIter next( branch->GetListOfBranches());
1301 while ((branch=dynamic_cast<TBranch*>(next()))) {
1302 branch->SetFile(outFile);
1305 printf("* MakeBranch * Diverting Branch %s to file %s\n", branch->GetName(),file);
1310 if (oH && !fTreeH) {
1311 sprintf(hname,"TreeH%d",fEvent);
1312 fTreeH = new TTree(hname,"Hits");
1313 fTreeH->SetAutoSave(1000000000); //no autosave
1314 fTreeH->Write(0,TObject::kOverwrite);
1317 if (oTR && !fTreeTR) {
1318 sprintf(hname,"TreeTR%d",fEvent);
1319 fTreeTR = new TTree(hname,"TrackReferences");
1320 fTreeTR->SetAutoSave(1000000000); //no autosave
1321 fTreeTR->Write(0,TObject::kOverwrite);
1324 if (oD && !fTreeD) {
1325 sprintf(hname,"TreeD%d",fEvent);
1326 fTreeD = new TTree(hname,"Digits");
1327 fTreeD->Write(0,TObject::kOverwrite);
1329 if (oS && !fTreeS) {
1330 sprintf(hname,"TreeS%d",fEvent);
1331 fTreeS = new TTree(hname,"SDigits");
1332 fTreeS->Write(0,TObject::kOverwrite);
1334 if (oR && !fTreeR) {
1335 sprintf(hname,"TreeR%d",fEvent);
1336 fTreeR = new TTree(hname,"Reconstruction");
1337 fTreeR->Write(0,TObject::kOverwrite);
1341 // Create a branch for hits/digits for each detector
1342 // Each branch is a TClonesArray. Each data member of the Hits classes
1343 // will be in turn a subbranch of the detector master branch
1344 TIter next(fModules);
1345 AliModule *detector;
1346 while((detector = dynamic_cast<AliModule*>(next()))) {
1347 if (oH) detector->MakeBranch(option,file);
1348 if (oTR) detector->MakeBranchTR(option,file);
1352 //_______________________________________________________________________
1353 TParticle* AliRun::Particle(Int_t i)
1355 return fStack->Particle(i);
1358 //_______________________________________________________________________
1359 void AliRun::ResetDigits()
1362 // Reset all Detectors digits
1364 TIter next(fModules);
1365 AliModule *detector;
1366 while((detector = dynamic_cast<AliModule*>(next()))) {
1367 detector->ResetDigits();
1371 //_______________________________________________________________________
1372 void AliRun::ResetSDigits()
1375 // Reset all Detectors digits
1377 TIter next(fModules);
1378 AliModule *detector;
1379 while((detector = dynamic_cast<AliModule*>(next()))) {
1380 detector->ResetSDigits();
1384 //_______________________________________________________________________
1385 void AliRun::ResetHits()
1388 // Reset all Detectors hits
1390 TIter next(fModules);
1391 AliModule *detector;
1392 while((detector = dynamic_cast<AliModule*>(next()))) {
1393 detector->ResetHits();
1397 //_______________________________________________________________________
1398 void AliRun::ResetTrackReferences()
1401 // Reset all Detectors hits
1403 TIter next(fModules);
1404 AliModule *detector;
1405 while((detector = dynamic_cast<AliModule*>(next()))) {
1406 detector->ResetTrackReferences();
1410 //_______________________________________________________________________
1411 void AliRun::ResetPoints()
1414 // Reset all Detectors points
1416 TIter next(fModules);
1417 AliModule *detector;
1418 while((detector = dynamic_cast<AliModule*>(next()))) {
1419 detector->ResetPoints();
1423 //_______________________________________________________________________
1424 void AliRun::InitMC(const char *setup)
1427 // Initialize the Alice setup
1431 Warning("Init","Cannot initialise AliRun twice!\n");
1435 gROOT->LoadMacro(setup);
1436 gInterpreter->ProcessLine(fConfigFunction.Data());
1438 // Register MC in configuration
1439 AliConfig::Instance()->Add(gMC);
1440 gMC->SetStack(fStack);
1442 gMC->DefineParticles(); //Create standard MC particles
1443 AliPDG::AddParticlesToPdgDataBase();
1445 TObject *objfirst, *objlast;
1447 fNdets = fModules->GetLast()+1;
1450 //=================Create Materials and geometry
1453 // Added also after in case of interactive initialisation of modules
1454 fNdets = fModules->GetLast()+1;
1456 TIter next(fModules);
1457 AliModule *detector;
1458 while((detector = dynamic_cast<AliModule*>(next()))) {
1459 detector->SetTreeAddress();
1460 objlast = gDirectory->GetList()->Last();
1462 // Add Detector histograms in Detector list of histograms
1463 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
1464 else objfirst = gDirectory->GetList()->First();
1466 detector->Histograms()->Add(objfirst);
1467 objfirst = gDirectory->GetList()->After(objfirst);
1470 ReadTransPar(); //Read the cuts for all materials
1472 MediaTable(); //Build the special IMEDIA table
1474 //Initialise geometry deposition table
1475 fEventEnergy.Set(gMC->NofVolumes()+1);
1476 fSummEnergy.Set(gMC->NofVolumes()+1);
1477 fSum2Energy.Set(gMC->NofVolumes()+1);
1479 //Compute cross-sections
1480 gMC->BuildPhysics();
1482 //Write Geometry object to current file.
1487 fMCQA = new AliMCQA(fNdets);
1489 AliConfig::Instance();
1491 // Save stuff at the beginning of the file to avoid file corruption
1495 //_______________________________________________________________________
1496 void AliRun::RunMC(Int_t nevent, const char *setup)
1499 // Main function to be called to process a galice run
1501 // Root > gAlice.Run();
1502 // a positive number of events will cause the finish routine
1505 fEventsPerRun = nevent;
1506 // check if initialisation has been done
1507 if (!fInitDone) InitMC(setup);
1509 // Create the Root Tree with one branch per detector
1513 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1514 MakeTree("K","Kine.root");
1515 MakeTree("H","Hits.root");
1520 gMC->ProcessRun(nevent);
1522 // End of this run, close files
1523 if(nevent>0) FinishRun();
1526 //_______________________________________________________________________
1527 void AliRun::RunReco(const char *selected, Int_t first, Int_t last)
1530 // Main function to be called to reconstruct Alice event
1532 cout << "Found "<< gAlice->TreeE()->GetEntries() << "events" << endl;
1533 Int_t nFirst = first;
1534 Int_t nLast = (last < 0)? static_cast<Int_t>(gAlice->TreeE()->GetEntries()) : last;
1536 for (Int_t nevent = nFirst; nevent <= nLast; nevent++) {
1537 cout << "Processing event "<< nevent << endl;
1540 Digits2Reco(selected);
1544 //_______________________________________________________________________
1546 void AliRun::Hits2Digits(const char *selected)
1549 // Convert Hits to sumable digits
1551 for (Int_t nevent=0; nevent<gAlice->TreeE()->GetEntries(); nevent++) {
1554 Hits2SDigits(selected);
1555 SDigits2Digits(selected);
1560 //_______________________________________________________________________
1562 void AliRun::Tree2Tree(Option_t *option, const char *selected)
1565 // Function to transform the content of
1567 // - TreeH to TreeS (option "S")
1568 // - TreeS to TreeD (option "D")
1569 // - TreeD to TreeR (option "R")
1571 // If multiple options are specified ("SDR"), transformation will be done in sequence for
1572 // selected detector and for all detectors if none is selected (detector string
1573 // can contain blank separated list of detector names).
1576 const char *oS = strstr(option,"S");
1577 const char *oD = strstr(option,"D");
1578 const char *oR = strstr(option,"R");
1580 TObjArray *detectors = Detectors();
1582 TIter next(detectors);
1584 AliDetector *detector = 0;
1586 TDirectory *cwd = gDirectory;
1590 while((detector = dynamic_cast<AliDetector*>(next()))) {
1592 if (strcmp(detector->GetName(),selected)) continue;
1593 if (detector->IsActive()){
1594 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1596 sprintf(outFile,"SDigits.%s.root",detector->GetName());
1597 detector->MakeBranch("S",outFile);
1600 sprintf(outFile,"Digits.%s.root",detector->GetName());
1601 detector->MakeBranch("D",outFile);
1604 sprintf(outFile,"Reco.%s.root",detector->GetName());
1605 detector->MakeBranch("R",outFile);
1608 detector->MakeBranch(option);
1614 cout << "Hits2SDigits: Processing " << detector->GetName() << "..." << endl;
1615 detector->Hits2SDigits();
1618 cout << "SDigits2Digits: Processing " << detector->GetName() << "..." << endl;
1619 detector->SDigits2Digits();
1622 cout << "Digits2Reco: Processing " << detector->GetName() << "..." << endl;
1623 detector->Digits2Reco();
1632 //_______________________________________________________________________
1633 void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min,
1634 Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max,
1635 Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener)
1638 // Generates lego plots of:
1639 // - radiation length map phi vs theta
1640 // - radiation length map phi vs eta
1641 // - interaction length map
1642 // - g/cm2 length map
1644 // ntheta bins in theta, eta
1645 // themin minimum angle in theta (degrees)
1646 // themax maximum angle in theta (degrees)
1648 // phimin minimum angle in phi (degrees)
1649 // phimax maximum angle in phi (degrees)
1650 // rmin minimum radius
1651 // rmax maximum radius
1654 // The number of events generated = ntheta*nphi
1655 // run input parameters in macro setup (default="Config.C")
1657 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1660 <img src="picts/AliRunLego1.gif">
1665 <img src="picts/AliRunLego2.gif">
1670 <img src="picts/AliRunLego3.gif">
1675 // check if initialisation has been done
1676 if (!fInitDone) InitMC(setup);
1677 //Save current generator
1678 AliGenerator *gen=Generator();
1680 // Set new generator
1681 if (!gener) gener = new AliLegoGenerator();
1682 ResetGenerator(gener);
1684 // Configure Generator
1685 gener->SetRadiusRange(rmin, rmax);
1686 gener->SetZMax(zmax);
1687 gener->SetCoor1Range(nc1, c1min, c1max);
1688 gener->SetCoor2Range(nc2, c2min, c2max);
1691 //Create Lego object
1692 fLego = new AliLego("lego",gener);
1694 //Prepare MC for Lego Run
1699 //gMC->ProcessRun(nc1*nc2+1);
1700 gMC->ProcessRun(nc1*nc2);
1702 // Create only the Root event Tree
1705 // End of this run, close files
1707 // Restore current generator
1708 ResetGenerator(gen);
1709 // Delete Lego Object
1710 delete fLego; fLego=0;
1713 //_______________________________________________________________________
1714 void AliRun::SetConfigFunction(const char * config)
1717 // Set the signature of the function contained in Config.C to configure
1720 fConfigFunction=config;
1723 //_______________________________________________________________________
1724 void AliRun::SetCurrentTrack(Int_t track)
1727 // Set current track number
1729 fStack->SetCurrentTrack(track);
1732 //_______________________________________________________________________
1733 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1734 Float_t *vpos, Float_t *polar, Float_t tof,
1735 AliMCProcess mech, Int_t &ntr, Float_t weight, Int_t is)
1737 // Delegate to stack
1740 fStack->SetTrack(done, parent, pdg, pmom, vpos, polar, tof,
1741 mech, ntr, weight, is);
1744 //_______________________________________________________________________
1745 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg,
1746 Double_t px, Double_t py, Double_t pz, Double_t e,
1747 Double_t vx, Double_t vy, Double_t vz, Double_t tof,
1748 Double_t polx, Double_t poly, Double_t polz,
1749 AliMCProcess mech, Int_t &ntr, Float_t weight, Int_t is)
1751 // Delegate to stack
1753 fStack->SetTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
1754 polx, poly, polz, mech, ntr, weight, is);
1758 //_______________________________________________________________________
1759 void AliRun::SetHighWaterMark(const Int_t nt)
1762 // Set high water mark for last track in event
1763 fStack->SetHighWaterMark(nt);
1766 //_______________________________________________________________________
1767 void AliRun::KeepTrack(const Int_t track)
1770 // Delegate to stack
1772 fStack->KeepTrack(track);
1779 //_______________________________________________________________________
1780 void AliRun::ConstructGeometry()
1783 // Create modules, materials, geometry
1787 TIter next(fModules);
1788 AliModule *detector;
1789 printf("Geometry creation:\n");
1790 while((detector = dynamic_cast<AliModule*>(next()))) {
1792 // Initialise detector materials and geometry
1793 detector->CreateMaterials();
1794 detector->CreateGeometry();
1795 printf("%10s R:%.2fs C:%.2fs\n",
1796 detector->GetName(),stw.RealTime(),stw.CpuTime());
1800 //_______________________________________________________________________
1801 void AliRun::InitGeometry()
1804 // Initialize detectors and display geometry
1807 printf("Initialisation:\n");
1809 TIter next(fModules);
1810 AliModule *detector;
1811 while((detector = dynamic_cast<AliModule*>(next()))) {
1813 // Initialise detector and display geometry
1815 detector->BuildGeometry();
1816 printf("%10s R:%.2fs C:%.2fs\n",
1817 detector->GetName(),stw.RealTime(),stw.CpuTime());
1822 //_______________________________________________________________________
1823 void AliRun::GeneratePrimaries()
1826 // Generate primary particles and fill them in the stack.
1829 Generator()->Generate();
1832 //_______________________________________________________________________
1833 void AliRun::BeginEvent()
1835 // Clean-up previous event
1837 fEventEnergy.Reset();
1838 // Clean detector information
1845 // Reset all Detectors & kinematics & trees
1849 // Initialise event header
1850 fHeader->Reset(fRun,fEvent,fEventNrInRun);
1852 fStack->BeginEvent(fEvent);
1856 fLego->BeginEvent();
1863 ResetTrackReferences();
1870 sprintf(hname,"TreeH%d",fEvent);
1871 fTreeH->SetName(hname);
1876 sprintf(hname,"TreeTR%d",fEvent);
1877 fTreeTR->SetName(hname);
1882 sprintf(hname,"TreeD%d",fEvent);
1883 fTreeD->SetName(hname);
1884 fTreeD->Write(0,TObject::kOverwrite);
1888 sprintf(hname,"TreeS%d",fEvent);
1889 fTreeS->SetName(hname);
1890 fTreeS->Write(0,TObject::kOverwrite);
1894 sprintf(hname,"TreeR%d",fEvent);
1895 fTreeR->SetName(hname);
1896 fTreeR->Write(0,TObject::kOverwrite);
1900 //_______________________________________________________________________
1901 void AliRun::BeginPrimary()
1904 // Called at the beginning of each primary track
1908 gAlice->ResetHits();
1909 gAlice->ResetTrackReferences();
1913 //_______________________________________________________________________
1914 void AliRun::PreTrack()
1916 TObjArray &dets = *fModules;
1919 for(Int_t i=0; i<=fNdets; i++)
1920 if((module = dynamic_cast<AliModule*>(dets[i])))
1926 //_______________________________________________________________________
1927 void AliRun::Stepping()
1930 // Called at every step during transport
1933 Int_t id = DetFromMate(gMC->GetMedium());
1937 // --- If lego option, do it and leave
1939 fLego->StepManager();
1942 //Update energy deposition tables
1943 AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
1945 //Call the appropriate stepping routine;
1946 AliModule *det = dynamic_cast<AliModule*>(fModules->At(id));
1947 if(det && det->StepManagerIsEnabled()) {
1948 fMCQA->StepManager(id);
1954 //_______________________________________________________________________
1955 void AliRun::PostTrack()
1957 TObjArray &dets = *fModules;
1960 for(Int_t i=0; i<=fNdets; i++)
1961 if((module = dynamic_cast<AliModule*>(dets[i])))
1962 module->PostTrack();
1965 //_______________________________________________________________________
1966 void AliRun::FinishPrimary()
1969 // Called at the end of each primary track
1972 // static Int_t count=0;
1973 // const Int_t times=10;
1974 // This primary is finished, purify stack
1975 fStack->PurifyKine();
1977 TIter next(fModules);
1978 AliModule *detector;
1979 while((detector = dynamic_cast<AliModule*>(next()))) {
1980 detector->FinishPrimary();
1983 // Write out hits if any
1984 if (gAlice->TreeH()) {
1985 gAlice->TreeH()->Fill();
1988 // Write out hits if any
1989 if (gAlice->TreeTR()) {
1990 gAlice->TreeTR()->Fill();
1994 // if(++count%times==1) gObjectTable->Print();
1997 //_______________________________________________________________________
1998 void AliRun::FinishEvent()
2001 // Called at the end of the event.
2005 if(fLego) fLego->FinishEvent();
2007 //Update the energy deposit tables
2009 for(i=0;i<fEventEnergy.GetSize();i++) {
2010 fSummEnergy[i]+=fEventEnergy[i];
2011 fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
2016 // Update Header information
2018 fHeader->SetNprimary(fStack->GetNprimary());
2019 fHeader->SetNtrack(fStack->GetNtrack());
2022 // Write out the kinematics
2023 fStack->FinishEvent();
2025 // Write out the event Header information
2027 fHeader->SetStack(fStack);
2032 // Write Tree headers
2033 TTree* pTreeK = fStack->TreeK();
2034 if (pTreeK) pTreeK->Write(0,TObject::kOverwrite);
2035 if (fTreeH) fTreeH->Write(0,TObject::kOverwrite);
2036 if (fTreeTR) fTreeTR->Write(0,TObject::kOverwrite);
2042 //_______________________________________________________________________
2043 void AliRun::Field(const Double_t* x, Double_t *b) const
2046 for (Int_t i=0; i<3; i++) xfloat[i] = x[i];
2050 Field()->Field(xfloat,bfloat);
2051 for (Int_t j=0; j<3; j++) b[j] = bfloat[j];
2054 printf("No mag field defined!\n");
2061 // End of MC Application
2064 //_______________________________________________________________________
2065 void AliRun::Streamer(TBuffer &R__b)
2067 // Stream an object of class AliRun.
2069 if (R__b.IsReading()) {
2070 if (!gAlice) gAlice = this;
2072 AliRun::Class()->ReadBuffer(R__b, this);
2074 gROOT->GetListOfBrowsables()->Add(this,"Run");
2076 fTreeE = dynamic_cast<TTree*>(gDirectory->Get("TE"));
2078 fTreeE->SetBranchAddress("Header", &fHeader);
2080 else Error("Streamer","cannot find Header Tree\n");
2082 fTreeE->GetEntry(0);
2085 AliRun::Class()->WriteBuffer(R__b, this);
2090 //_______________________________________________________________________
2091 Int_t AliRun::CurrentTrack() const {
2093 // Returns current track
2095 return fStack->CurrentTrack();
2098 //_______________________________________________________________________
2099 Int_t AliRun::GetNtrack() const {
2101 // Returns number of tracks in stack
2103 return fStack->GetNtrack();
2106 //_______________________________________________________________________
2107 TObjArray* AliRun::Particles() {
2109 // Returns pointer to Particles array
2111 return fStack->Particles();
2114 //_______________________________________________________________________
2115 TTree* AliRun::TreeK() {
2117 // Returns pointer to the TreeK array
2119 return fStack->TreeK();
2123 //_______________________________________________________________________
2124 void AliRun::SetGenEventHeader(AliGenEventHeader* header)
2126 fHeader->SetGenEventHeader(header);
2129 //_______________________________________________________________________
2130 TFile* AliRun::InitFile(TString fileName)
2133 // create the file where the whole tree will be saved
2135 TDirectory *wd = gDirectory;
2136 TFile* file = TFile::Open(fileName,"update");
2138 if (!file->IsOpen()) {
2139 Error("Cannot open file, %s\n",fileName);
2145 //_______________________________________________________________________
2146 TFile* AliRun::InitTreeFile(Option_t *option, TString fileName)
2149 // create the file where one of the following trees will be saved
2151 // WARNING: by default these trees are saved on the file on which
2152 // hits are stored. If you divert one of these trees, you cannot restore
2153 // it to the original file (usually galice.root) in the same aliroot session
2154 Bool_t oS = (strstr(option,"S")!=0);
2155 Bool_t oR = (strstr(option,"R")!=0);
2156 Bool_t oD = (strstr(option,"D")!=0);
2158 for (Int_t i=0; i<3; i++) choice[i] = 0;
2159 if(oS)choice[0] = 1;
2160 if(oD)choice[1] = 1;
2161 if(oR)choice[2] = 1;
2165 if(!(oS || oR || oD))return ptr;
2168 for (Int_t i=0; i<3; i++) active[i] = 0;
2169 if(fTreeSFileName != "") active[0] = 1;
2170 if(fTreeDFileName != "") active[1] = 1;
2171 if(fTreeDFileName != "") active[2] = 1;
2173 Bool_t alreadyopen1 = kFALSE;
2174 Bool_t alreadyopen2 = kFALSE;
2177 // if already active and same name with non-null ptr
2178 if(active[0]==1 && fileName == fTreeSFileName && fTreeSFile){
2179 Warning("InitTreeFile","File %s already opened",fTreeSFileName.Data());
2183 // if already active with different name with non-null ptr
2184 if(active[0]==1 && fileName != fTreeSFileName && fTreeSFile){
2185 // close the active files and also the other possible files in option
2186 CloseTreeFile(option);
2188 fTreeSFileName = fileName;
2190 (active[1] == 1 && fTreeDFileName == fTreeSFileName && fTreeDFile);
2192 (active[2] == 1 && fTreeRFileName == fTreeSFileName && fTreeRFile);
2193 if(!(alreadyopen1 || alreadyopen2)){
2194 ptr = InitFile(fileName);
2198 if(alreadyopen1){fTreeSFile = fTreeDFile; ptr = fTreeSFile;}
2199 if(alreadyopen2){fTreeSFile = fTreeRFile; ptr = fTreeSFile;}
2201 if(choice[1] == 1) { fTreeDFileName = fileName; fTreeDFile = ptr;}
2202 if(choice[2] == 1) { fTreeRFileName = fileName; fTreeRFile = ptr;}
2208 // if already active and same name with non-null ptr
2209 if(active[1]==1 && fileName == fTreeDFileName && fTreeDFile){
2210 Warning("InitTreeFile","File %s already opened",fTreeDFileName.Data());
2214 // if already active with different name with non-null ptr
2215 if(active[1]==1 && fileName != fTreeDFileName && fTreeDFile){
2216 // close the active files and also the other possible files in option
2217 CloseTreeFile(option);
2219 fTreeDFileName = fileName;
2221 (active[0] == 1 && fTreeSFileName == fTreeDFileName && fTreeSFile);
2223 (active[2] == 1 && fTreeRFileName == fTreeDFileName && fTreeRFile);
2224 if(!(alreadyopen1 || alreadyopen2)){
2225 ptr = InitFile(fileName);
2229 if(alreadyopen1){fTreeDFile = fTreeSFile; ptr = fTreeDFile;}
2230 if(alreadyopen2){fTreeDFile = fTreeRFile; ptr = fTreeDFile;}
2232 if(choice[2] == 1) { fTreeRFileName = fileName; fTreeRFile = ptr;}
2238 // if already active and same name with non-null ptr
2239 if(active[2]==1 && fileName == fTreeRFileName && fTreeRFile){
2240 Warning("InitTreeFile","File %s already opened",fTreeRFileName.Data());
2244 // if already active with different name with non-null ptr
2245 if(active[2]==1 && fileName != fTreeRFileName && fTreeRFile){
2246 // close the active files and also the other possible files in option
2247 CloseTreeFile(option);
2249 fTreeRFileName = fileName;
2251 (active[1] == 1 && fTreeDFileName == fTreeRFileName && fTreeDFile);
2253 (active[0]== 1 && fTreeSFileName == fTreeRFileName && fTreeSFile);
2254 if(!(alreadyopen1 || alreadyopen2)){
2255 ptr = InitFile(fileName);
2259 if(alreadyopen1){fTreeRFile = fTreeDFile; ptr = fTreeRFile;}
2260 if(alreadyopen2){fTreeRFile = fTreeSFile; ptr = fTreeRFile;}
2268 //_______________________________________________________________________
2269 void AliRun::PrintTreeFile()
2272 // prints the file names and pointer associated to S,D,R trees
2274 cout<<"===================================================\n";
2275 TFile *file = fTreeE->GetCurrentFile();
2276 TString curfilname="";
2277 if(file)curfilname=static_cast<TString>(file->GetName());
2278 cout<<" Current tree file name: "<<curfilname<<endl;
2279 cout<<"Pointer: "<<file<<endl;
2280 cout<<" Tree S File name: "<<fTreeSFileName<<endl;
2281 cout<<"Pointer: "<<fTreeSFile<<endl<<endl;
2282 cout<<" Tree D File name: "<<fTreeDFileName<<endl;
2283 cout<<"Pointer: "<<fTreeDFile<<endl<<endl;
2284 cout<<" Tree R File name: "<<fTreeRFileName<<endl;
2285 cout<<"Pointer: "<<fTreeRFile<<endl<<endl;
2286 cout<<"===================================================\n";
2288 //_______________________________________________________________________
2289 void AliRun::CloseTreeFile(Option_t *option)
2292 // closes the file containing the tree specified in option
2295 Bool_t oS = (strstr(option,"S")!=0);
2296 Bool_t oR = (strstr(option,"R")!=0);
2297 Bool_t oD = (strstr(option,"D")!=0);
2298 Bool_t none = !(oS || oR || oD);
2301 fTreeSFileName = "";
2303 if(!((fTreeSFile == fTreeDFile) || (fTreeSFile == fTreeRFile)) &&
2304 fTreeSFile->IsOpen()){
2305 fTreeSFile->Close();
2312 fTreeDFileName = "";
2314 if(!((fTreeDFile == fTreeRFile) || (fTreeDFile == fTreeSFile)) &&
2315 fTreeDFile->IsOpen()){
2316 fTreeDFile->Close();
2323 fTreeRFileName = "";
2325 if(!((fTreeRFile == fTreeSFile) || (fTreeRFile == fTreeDFile)) &&
2326 fTreeRFile->IsOpen()){
2327 fTreeRFile->Close();
2335 //_______________________________________________________________________
2336 void AliRun::MakeTree(Option_t *option, TFile *file)
2339 // Create some trees in the separate file
2341 const char *oD = strstr(option,"D");
2342 const char *oR = strstr(option,"R");
2343 const char *oS = strstr(option,"S");
2345 TDirectory *cwd = gDirectory;
2350 sprintf(hname,"TreeD%d",fEvent);
2352 fTreeD = static_cast<TTree*>(file->Get("hname"));
2354 fTreeD = new TTree(hname,"Digits");
2355 fTreeD->Write(0,TObject::kOverwrite);
2361 sprintf(hname,"TreeS%d",fEvent);
2363 fTreeS = static_cast<TTree*>(file->Get("hname"));
2365 fTreeS = new TTree(hname,"SDigits");
2366 fTreeS->Write(0,TObject::kOverwrite);
2373 sprintf(hname,"TreeR%d",fEvent);
2375 fTreeR = static_cast<TTree*>(file->Get("hname"));
2377 fTreeR = new TTree(hname,"RecPoint");
2378 fTreeR->Write(0,TObject::kOverwrite);