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.92 2002/11/15 17:12:04 alibrary
21 Revision 1.91 2002/10/29 14:26:49 hristov
22 Code clean-up (F.Carminati)
24 Revision 1.90 2002/10/22 15:02:15 alibrary
25 Introducing Riostream.h
27 Revision 1.89 2002/10/17 16:26:39 hristov
28 Definition of additional particles moved to VMC (I.Hrivnacova)
30 Revision 1.88 2002/10/14 14:57:32 hristov
31 Merging the VirtualMC branch to the main development branch (HEAD)
33 Revision 1.82.4.3 2002/10/14 09:45:57 hristov
34 Updating VirtualMC to v3-09-02
36 Revision 1.82.4.2 2002/06/10 17:54:06 hristov
37 Only one SetGenEventHeader function kept
39 Revision 1.82.4.1 2002/06/10 14:43:06 hristov
42 Revision 1.86 2002/05/28 14:24:57 hristov
43 Correct warning messages
45 Revision 1.85 2002/05/24 13:29:58 hristov
46 AliTrackReference added, AliDisplay modified
48 Revision 1.84 2002/05/21 16:26:07 hristov
49 Find correctly TreeK in case CONFIG_SPLIT_FILE is set (Y.Schutz)
51 Revision 1.83 2002/04/04 13:16:17 jchudoba
52 add possibility to write sdigits, digits and rec. points into separate files
54 Revision 1.82 2002/03/12 11:06:03 morsch
55 Add particle status code to argument list of SetTrack(..).
57 Revision 1.81 2001/12/19 14:46:26 morsch
58 Add possibility to disable StepManager() for each module separately.
60 Revision 1.80 2001/10/21 18:22:55 hristov
61 BranchOld replaced by Branch. It works correctly with Root 2.02.xx
63 Revision 1.79 2001/10/09 18:00:35 hristov
64 Temporary fix to provide unique event number in the simulation (J.Chudoba)
66 Revision 1.78 2001/10/04 15:30:56 hristov
67 Changes to accommodate the set of PHOS folders and tasks (Y.Schutz)
69 Revision 1.77 2001/09/04 15:09:11 hristov
70 fTreeE->Branch replaced temporary by fTreeE->BranchOld to avoid data corruption in case of many events per file
72 Revision 1.76 2001/08/03 14:38:35 morsch
73 Use original method to access TreeH.
75 Revision 1.75 2001/07/28 10:52:27 hristov
76 Event number updated correctly (M.Ivanov)
78 Revision 1.74 2001/07/28 10:39:16 morsch
79 GetEventsPerRun() method needed by afterburners added to AliRun.h
80 Corresponding setters and getters have been from AliGenerator.
82 Revision 1.73 2001/07/27 12:34:30 jchudoba
83 remove the dummy argument in fStack->GetEvent call
85 Revision 1.72 2001/07/03 08:10:57 hristov
86 J.Chudoba's changes merged correctly with the HEAD
88 Revision 1.70 2001/06/29 08:01:36 morsch
89 Small correction to the previous.
91 Revision 1.69 2001/06/28 16:27:50 morsch
92 AliReco() with user control of event range.
94 Revision 1.68 2001/06/11 13:14:40 morsch
95 SetAliGenEventHeader() method added.
97 Revision 1.67 2001/06/07 18:24:50 buncic
98 Removed compilation warning in AliConfig initialisation.
100 Revision 1.66 2001/05/22 14:32:40 hristov
103 Revision 1.65 2001/05/21 17:22:51 buncic
104 Fixed problem with missing AliConfig while reading galice.root
106 Revision 1.64 2001/05/16 14:57:22 alibrary
107 New files for folders and Stack
109 Revision 1.62 2001/04/06 11:12:33 morsch
110 Clear fParticles after each event. (Ivana Hrivnacova)
112 Revision 1.61 2001/03/30 07:04:10 morsch
113 Call fGenerator->FinishRun() for final print-outs, cross-section and weight calculations.
115 Revision 1.60 2001/03/21 18:22:30 hristov
116 fParticleFileMap fix (I.Hrivnacova)
118 Revision 1.59 2001/03/12 17:47:03 hristov
119 Changes needed on Sun with CC 5.0
121 Revision 1.58 2001/03/09 14:27:26 morsch
122 Fix for multiple events per file: inhibit decrease of size of fParticleFileMap.
124 Revision 1.57 2001/02/23 17:40:23 buncic
125 All trees needed for simulation created in RunMC(). TreeR and its branches
126 are now created in new RunReco() method.
128 Revision 1.56 2001/02/14 15:45:20 hristov
129 Algorithmic way of getting entry index in fParticleMap. Protection of fParticleFileMap (I.Hrivnacova)
131 Revision 1.55 2001/02/12 15:52:54 buncic
132 Removed OpenBaseFile().
134 Revision 1.54 2001/02/07 10:39:05 hristov
135 Remove default value for argument
137 Revision 1.53 2001/02/06 11:02:26 hristov
138 New SetTrack interface added, added check for unfilled particles in FinishEvent (I.Hrivnacova)
140 Revision 1.52 2001/02/05 16:22:25 buncic
141 Added TreeS to GetEvent().
143 Revision 1.51 2001/02/02 15:16:20 morsch
144 SetHighWaterMark method added to mark last particle in event.
146 Revision 1.50 2001/01/27 10:32:00 hristov
147 Leave the loop when primaries are filled (I.Hrivnacova)
149 Revision 1.49 2001/01/26 19:58:48 hristov
150 Major upgrade of AliRoot code
152 Revision 1.48 2001/01/17 10:50:50 hristov
153 Corrections to destructors
155 Revision 1.47 2000/12/18 10:44:01 morsch
156 Possibility to set field map by passing pointer to objet of type AliMagF via
159 gAlice->SetField(new AliMagFCM("Map2", "$(ALICE_ROOT)/data/field01.dat",2,1.,10.));
161 Revision 1.46 2000/12/14 19:29:27 fca
162 galice.cuts was not read any more
164 Revision 1.45 2000/11/30 07:12:49 alibrary
165 Introducing new Rndm and QA classes
167 Revision 1.44 2000/10/26 13:58:59 morsch
168 Add possibility to choose the lego generator (of type AliGeneratorLego or derived) when running
169 RunLego(). Default is the base class AliGeneratorLego.
171 Revision 1.43 2000/10/09 09:43:17 fca
172 Special remapping of hits for TPC and TRD. End-of-primary action introduced
174 Revision 1.42 2000/10/02 21:28:14 fca
175 Removal of useless dependecies via forward declarations
177 Revision 1.41 2000/07/13 16:19:09 fca
178 Mainly coding conventions + some small bug fixes
180 Revision 1.40 2000/07/12 08:56:25 fca
181 Coding convention correction and warning removal
183 Revision 1.39 2000/07/11 18:24:59 fca
184 Coding convention corrections + few minor bug fixes
186 Revision 1.38 2000/06/20 13:05:45 fca
187 Writing down the TREE headers before job starts
189 Revision 1.37 2000/06/09 20:05:11 morsch
190 Introduce possibility to chose magnetic field version 3: AliMagFDM + field02.dat
192 Revision 1.36 2000/06/08 14:03:58 hristov
193 Only one initializer for a default argument
195 Revision 1.35 2000/06/07 10:13:14 hristov
196 Delete only existent objects.
198 Revision 1.34 2000/05/18 10:45:38 fca
199 Delete Particle Factory properly
201 Revision 1.33 2000/05/16 13:10:40 fca
202 New method IsNewTrack and fix for a problem in Father-Daughter relations
204 Revision 1.32 2000/04/27 10:38:21 fca
205 Correct termination of Lego Run and introduce Lego getter in AliRun
207 Revision 1.31 2000/04/26 10:17:32 fca
208 Changes in Lego for G4 compatibility
210 Revision 1.30 2000/04/18 19:11:40 fca
211 Introduce variable Config.C function signature
213 Revision 1.29 2000/04/07 11:12:34 fca
214 G4 compatibility changes
216 Revision 1.28 2000/04/05 06:51:06 fca
217 Workaround for an HP compiler problem
219 Revision 1.27 2000/03/22 18:08:07 fca
220 Rationalisation of the virtual MC interfaces
222 Revision 1.26 2000/03/22 13:42:26 fca
223 SetGenerator does not replace an existing generator, ResetGenerator does
225 Revision 1.25 2000/02/23 16:25:22 fca
226 AliVMC and AliGeant3 classes introduced
227 ReadEuclid moved from AliRun to AliModule
229 Revision 1.24 2000/01/19 17:17:20 fca
230 Introducing a list of lists of hits -- more hits allowed for detector now
232 Revision 1.23 1999/12/03 11:14:31 fca
233 Fixing previous wrong checking
235 Revision 1.21 1999/11/25 10:40:08 fca
236 Fixing daughters information also in primary tracks
238 Revision 1.20 1999/10/04 18:08:49 fca
239 Adding protection against inconsistent Euclid files
241 Revision 1.19 1999/09/29 07:50:40 fca
242 Introduction of the Copyright and cvs Log
246 ///////////////////////////////////////////////////////////////////////////////
248 // Control class for Alice C++ //
249 // Only one single instance of this class exists. //
250 // The object is created in main program aliroot //
251 // and is pointed by the global gAlice. //
253 // -Supports the list of all Alice Detectors (fModules). //
254 // -Supports the list of particles (fParticles). //
255 // -Supports the Trees. //
256 // -Supports the geometry. //
257 // -Supports the event display. //
260 <img src="picts/AliRunClass.gif">
265 <img src="picts/alirun.gif">
269 ///////////////////////////////////////////////////////////////////////////////
275 #include "Riostream.h"
277 #include "TBrowser.h"
281 #include "TGeometry.h"
284 #include "TObjectTable.h"
285 #include "TParticle.h"
286 #include "TRandom3.h"
291 #include "AliConfig.h"
292 #include "AliDetector.h"
293 #include "AliDisplay.h"
294 #include "AliGenEventHeader.h"
295 #include "AliGenerator.h"
296 #include "AliHeader.h"
299 #include "AliLegoGenerator.h"
301 #include "AliMagFC.h"
302 #include "AliMagFCM.h"
303 #include "AliMagFDM.h"
306 #include "AliStack.h"
312 //_______________________________________________________________________
339 fPDGDB(0), //Particle factory object
344 fConfigFunction("\0"),
358 // Default constructor for AliRun
362 //_______________________________________________________________________
363 AliRun::AliRun(const AliRun& arun):
364 TVirtualMCApplication(arun),
390 fPDGDB(0), //Particle factory object
395 fConfigFunction("\0"),
409 // Copy constructor for AliRun
414 //_____________________________________________________________________________
415 AliRun::AliRun(const char *name, const char *title):
416 TVirtualMCApplication(name,title),
422 fHeader(new AliHeader()),
429 fModules(new TObjArray(77)), // Support list for the Detectors
435 fImedia(new TArrayI(1000)),
442 fPDGDB(TDatabasePDG::Instance()), //Particle factory object!
443 fHitLists(new TList()), // Create HitLists list
447 fConfigFunction("Config();"),
448 fRandom(new TRandom3()),
452 fStack(new AliStack(10000)), //Particle stack
461 // Constructor for the main processor.
462 // Creates the geometry
463 // Creates the list of Detectors.
464 // Creates the list of particles.
469 // Set random number generator
472 if (gSystem->Getenv("CONFIG_SEED")) {
473 gRandom->SetSeed(static_cast<UInt_t>(atoi(gSystem->Getenv("CONFIG_SEED"))));
476 // Add to list of browsable
477 gROOT->GetListOfBrowsables()->Add(this,name);
479 // Create the TNode geometry for the event display
480 BuildSimpleGeometry();
482 // Create default mag field
485 // Prepare the tracking medium lists
486 for(Int_t i=0;i<1000;i++) (*fImedia)[i]=-99;
488 // Add particle list to configuration
489 AliConfig::Instance()->Add(fPDGDB);
491 // Set transport parameters
496 //_______________________________________________________________________
500 // Default AliRun destructor
503 if(fTreeE)curfil=fTreeE->GetCurrentFile();
526 // avoid to delete TFile objects not owned by this object
527 // avoid multiple deletions
528 if(curfil == fTreeDFile) fTreeDFile=0;
529 if(curfil == fTreeSFile) fTreeSFile=0;
530 if(curfil == fTreeRFile) fTreeRFile=0;
531 if(fTreeSFile == fTreeDFile) fTreeSFile=0;
532 if(fTreeRFile == fTreeDFile) fTreeRFile=0;
533 if(fTreeRFile == fTreeSFile) fTreeRFile=0;
535 if(fTreeDFile->IsOpen())fTreeDFile->Close();
539 if(fTreeSFile->IsOpen())fTreeSFile->Close();
543 if(fTreeRFile->IsOpen())fTreeRFile->Close();
546 if (gROOT->GetListOfBrowsables())
547 gROOT->GetListOfBrowsables()->Remove(this);
552 //_______________________________________________________________________
553 void AliRun::Copy(AliRun &) const
555 Fatal("Copy","Not implemented!\n");
558 //_______________________________________________________________________
559 void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
562 // Add a hit to detector id
564 TObjArray &dets = *fModules;
565 if(dets[id]) dynamic_cast<AliModule*>(dets[id])->AddHit(track,vol,hits);
568 //_______________________________________________________________________
569 void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
572 // Add digit to detector id
574 TObjArray &dets = *fModules;
575 if(dets[id]) dynamic_cast<AliModule*>(dets[id])->AddDigit(tracks,digits);
578 //_______________________________________________________________________
579 void AliRun::Browse(TBrowser *b)
582 // Called when the item "Run" is clicked on the left pane
583 // of the Root browser.
584 // It displays the Root Trees and all detectors.
586 if(!fStack) fStack=fHeader->Stack();
587 TTree* pTreeK = fStack->TreeK();
589 if (pTreeK) b->Add(pTreeK,pTreeK->GetName());
590 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
591 if (fTreeTR) b->Add(fTreeTR,fTreeH->GetName());
592 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
593 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
594 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
595 if (fTreeS) b->Add(fTreeS,fTreeS->GetName());
597 TIter next(fModules);
599 while((detector = dynamic_cast<AliModule*>(next()))) {
600 b->Add(detector,detector->GetName());
602 b->Add(fMCQA,"AliMCQA");
605 //_______________________________________________________________________
609 // Initialize Alice geometry
614 //_______________________________________________________________________
615 void AliRun::BuildSimpleGeometry()
618 // Create a simple TNode geometry used by Root display engine
620 // Initialise geometry
622 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
623 new TMaterial("void","Vacuum",0,0,0); //Everything is void
624 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
625 brik->SetVisibility(0);
626 new TNode("alice","alice","S_alice");
629 //_______________________________________________________________________
630 void AliRun::CleanDetectors()
633 // Clean Detectors at the end of event
635 TIter next(fModules);
637 while((detector = dynamic_cast<AliModule*>(next()))) {
638 detector->FinishEvent();
642 //_______________________________________________________________________
643 Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
646 // Return the distance from the mouse to the AliRun object
652 //_______________________________________________________________________
653 void AliRun::DumpPart (Int_t i) const
656 // Dumps particle i in the stack
661 //_______________________________________________________________________
662 void AliRun::DumpPStack () const
665 // Dumps the particle stack
667 fStack->DumpPStack();
670 //_______________________________________________________________________
671 void AliRun::SetField(AliMagF* magField)
673 // Set Magnetic Field Map
678 //_______________________________________________________________________
679 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
680 Float_t maxField, char* filename)
683 // Set magnetic field parameters
684 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
685 // version Magnetic field map version (only 1 active now)
686 // scale Scale factor for the magnetic field
687 // maxField Maximum value for the magnetic field
690 // --- Sanity check on mag field flags
691 if(fField) delete fField;
693 fField = new AliMagFC("Map1"," ",type,scale,maxField);
694 } else if(version<=2) {
695 fField = new AliMagFCM("Map2-3",filename,type,scale,maxField);
697 } else if(version==3) {
698 fField = new AliMagFDM("Map4",filename,type,scale,maxField);
701 Warning("SetField","Invalid map %d\n",version);
705 //_______________________________________________________________________
706 void AliRun::FinishRun()
709 // Called at the end of the run.
713 if(fLego) fLego->FinishRun();
715 // Clean detector information
716 TIter next(fModules);
718 while((detector = dynamic_cast<AliModule*>(next()))) {
719 detector->FinishRun();
722 //Output energy summary tables
725 TFile *file = fTreeE->GetCurrentFile();
729 fTreeE->Write(0,TObject::kOverwrite);
731 // Write AliRun info and all detectors parameters
732 Write(0,TObject::kOverwrite);
734 // Clean tree information
739 delete fTreeH; fTreeH = 0;
742 delete fTreeTR; fTreeTR = 0;
745 delete fTreeD; fTreeD = 0;
748 delete fTreeR; fTreeR = 0;
751 // delete fTreeE; fTreeE = 0;
754 delete fTreeS; fTreeS = 0;
756 fGenerator->FinishRun();
762 //_______________________________________________________________________
763 void AliRun::FlagTrack(Int_t track)
767 fStack->FlagTrack(track);
770 //_______________________________________________________________________
771 void AliRun::EnergySummary()
774 // Print summary of deposited energy
780 Int_t kn, i, left, j, id;
781 const Float_t kzero=0;
782 Int_t ievent=fHeader->GetEvent()+1;
784 // Energy loss information
786 printf("***************** Energy Loss Information per event (GEV) *****************\n");
787 for(kn=1;kn<fEventEnergy.GetSize();kn++) {
790 fEventEnergy[ndep]=kn;
795 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,kzero))/ed;
798 fSummEnergy[ndep]=ed;
799 fSum2Energy[ndep]=TMath::Min(static_cast<Float_t>(99.),TMath::Max(ed2,kzero));
804 for(kn=0;kn<(ndep-1)/3+1;kn++) {
806 for(i=0;i<(3<left?3:left);i++) {
808 id=Int_t (fEventEnergy[j]+0.1);
809 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]);
814 // Relative energy loss in different detectors
815 printf("******************** Relative Energy Loss per event ********************\n");
816 printf("Total energy loss per event %10.3f GeV\n",edtot);
817 for(kn=0;kn<(ndep-1)/5+1;kn++) {
819 for(i=0;i<(5<left?5:left);i++) {
821 id=Int_t (fEventEnergy[j]+0.1);
822 printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot);
826 for(kn=0;kn<75;kn++) printf("*");
830 // Reset the TArray's
831 // fEventEnergy.Set(0);
832 // fSummEnergy.Set(0);
833 // fSum2Energy.Set(0);
836 //_______________________________________________________________________
837 AliModule *AliRun::GetModule(const char *name) const
840 // Return pointer to detector from name
842 return dynamic_cast<AliModule*>(fModules->FindObject(name));
845 //_______________________________________________________________________
846 AliDetector *AliRun::GetDetector(const char *name) const
849 // Return pointer to detector from name
851 return dynamic_cast<AliDetector*>(fModules->FindObject(name));
854 //_______________________________________________________________________
855 Int_t AliRun::GetModuleID(const char *name) const
858 // Return galice internal detector identifier from name
861 TObject *mod=fModules->FindObject(name);
862 if(mod) i=fModules->IndexOf(mod);
866 //_______________________________________________________________________
867 Int_t AliRun::GetEvent(Int_t event)
870 // Connect the Trees Kinematics and Hits for event # event
871 // Set branch addresses
874 // Reset existing structures
876 ResetTrackReferences();
880 // Delete Trees already connected
881 if (fTreeH) { delete fTreeH; fTreeH = 0;}
882 if (fTreeTR) { delete fTreeTR; fTreeTR = 0;}
883 if (fTreeD) { delete fTreeD; fTreeD = 0;}
884 if (fTreeR) { delete fTreeR; fTreeR = 0;}
885 if (fTreeS) { delete fTreeS; fTreeS = 0;}
887 // Create the particle stack
888 if (fHeader) delete fHeader;
891 // Get header from file
893 fTreeE->SetBranchAddress("Header", &fHeader);
895 if (!fTreeE->GetEntry(event)) {
896 Error("GetEvent","Cannot find event:%d\n",event);
901 Error("GetEvent","Cannot find Header Tree (TE)\n");
905 // Get the stack from the header, set fStack to 0 if it
906 // fails to get event
908 TFile *file = fTreeE->GetCurrentFile();
913 if (fStack) delete fStack;
914 fStack = fHeader->Stack();
916 if (!fStack->GetEvent(event)) fStack = 0;
919 // Get Hits Tree header from file
920 sprintf(treeName,"TreeH%d",event);
921 fTreeH = dynamic_cast<TTree*>(gDirectory->Get(treeName));
923 Warning("GetEvent","cannot find Hits Tree for event:%d\n",event);
926 // Get TracReferences Tree header from file
927 sprintf(treeName,"TreeTR%d",event);
928 fTreeTR = dynamic_cast<TTree*>(gDirectory->Get(treeName));
930 Warning("GetEvent","cannot find TrackReferences Tree for event:%d\n",event);
933 // get current file name and compare with names containing trees S,D,R
934 TString curfilname=static_cast<TString>(fTreeE->GetCurrentFile()->GetName());
935 if(fTreeDFileName==curfilname)fTreeDFileName="";
936 if(fTreeSFileName==curfilname)fTreeSFileName="";
937 if(fTreeRFileName==curfilname)fTreeRFileName="";
939 // Get Digits Tree header from file
940 sprintf(treeName,"TreeD%d",event);
942 if (!fTreeDFile && fTreeDFileName != "") {
943 InitTreeFile("D",fTreeDFileName);
946 fTreeD = dynamic_cast<TTree*>(fTreeDFile->Get(treeName));
948 fTreeD = dynamic_cast<TTree*>(file->Get(treeName));
951 // Warning("GetEvent","cannot find Digits Tree for event:%d\n",event);
953 if(fTreeDFileName != ""){
954 if(fTreeDFileName==fTreeSFileName) {
956 fTreeSFile = fTreeDFile;
958 if(fTreeDFileName==fTreeRFileName) {
960 fTreeRFile = fTreeDFile;
966 // Get SDigits Tree header from file
967 sprintf(treeName,"TreeS%d",event);
968 if (!fTreeSFile && fTreeSFileName != "") {
969 InitTreeFile("S",fTreeSFileName);
972 fTreeS = dynamic_cast<TTree*>(fTreeSFile->Get(treeName));
974 fTreeS = dynamic_cast<TTree*>(gDirectory->Get(treeName));
977 // Warning("GetEvent","cannot find SDigits Tree for event:%d\n",event);
980 if(fTreeSFileName != ""){
981 if(fTreeSFileName==fTreeRFileName){
983 fTreeRFile = fTreeSFile;
989 // Get Reconstruct Tree header from file
990 sprintf(treeName,"TreeR%d",event);
991 if (!fTreeRFile && fTreeRFileName != "") {
992 InitTreeFile("R",fTreeRFileName);
995 fTreeR = dynamic_cast<TTree*>(fTreeRFile->Get(treeName));
997 fTreeR = dynamic_cast<TTree*>(gDirectory->Get(treeName));
1000 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
1005 // Set Trees branch addresses
1006 TIter next(fModules);
1007 AliModule *detector;
1008 while((detector = dynamic_cast<AliModule*>(next()))) {
1009 detector->SetTreeAddress();
1012 fEvent=event; //MI change
1014 return fHeader->GetNtrack();
1017 //_______________________________________________________________________
1018 TGeometry *AliRun::GetGeometry()
1021 // Import Alice geometry from current file
1022 // Return pointer to geometry object
1024 if (!fGeometry) fGeometry = dynamic_cast<TGeometry*>(gDirectory->Get("AliceGeom"));
1026 // Unlink and relink nodes in detectors
1027 // This is bad and there must be a better way...
1030 TIter next(fModules);
1031 AliModule *detector;
1032 while((detector = dynamic_cast<AliModule*>(next()))) {
1033 TList *dnodes=detector->Nodes();
1035 TNode *node, *node1;
1036 for ( j=0; j<dnodes->GetSize(); j++) {
1037 node = dynamic_cast<TNode*>(dnodes->At(j));
1038 node1 = fGeometry->GetNode(node->GetName());
1039 dnodes->Remove(node);
1040 dnodes->AddAt(node1,j);
1046 //_______________________________________________________________________
1047 Int_t AliRun::GetPrimary(Int_t track) const
1050 // return number of primary that has generated track
1052 return fStack->GetPrimary(track);
1055 //_______________________________________________________________________
1056 void AliRun::MediaTable()
1059 // Built media table to get from the media number to
1062 Int_t kz, nz, idt, lz, i, k, ind;
1064 TObjArray &dets = *gAlice->Detectors();
1067 // For all detectors
1068 for (kz=0;kz<fNdets;kz++) {
1069 // If detector is defined
1070 if((det=dynamic_cast<AliModule*>(dets[kz]))) {
1071 TArrayI &idtmed = *(det->GetIdtmed());
1072 for(nz=0;nz<100;nz++) {
1073 // Find max and min material number
1074 if((idt=idtmed[nz])) {
1075 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
1076 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
1079 if(det->LoMedium() > det->HiMedium()) {
1080 det->LoMedium() = 0;
1081 det->HiMedium() = 0;
1083 if(det->HiMedium() > fImedia->GetSize()) {
1084 Error("MediaTable","Increase fImedia from %d to %d",
1085 fImedia->GetSize(),det->HiMedium());
1088 // Tag all materials in rage as belonging to detector kz
1089 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
1096 // Print summary table
1097 printf(" Traking media ranges:\n");
1098 for(i=0;i<(fNdets-1)/6+1;i++) {
1099 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
1101 det=dynamic_cast<AliModule*>(dets[ind]);
1103 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
1106 printf(" %6s: %3d -> %3d;","NULL",0,0);
1112 //_______________________________________________________________________
1113 void AliRun::SetGenerator(AliGenerator *generator)
1116 // Load the event generator
1118 if(!fGenerator) fGenerator = generator;
1121 //_______________________________________________________________________
1122 void AliRun::ResetGenerator(AliGenerator *generator)
1125 // Load the event generator
1129 Warning("ResetGenerator","Replacing generator %s with %s\n",
1130 fGenerator->GetName(),generator->GetName());
1132 Warning("ResetGenerator","Replacing generator %s with NULL\n",
1133 fGenerator->GetName());
1134 fGenerator = generator;
1137 //_______________________________________________________________________
1138 void AliRun::SetTransPar(const char *filename)
1140 fTransParName = filename;
1143 //_______________________________________________________________________
1144 void AliRun::SetBaseFile(const char *filename)
1146 fBaseFileName = filename;
1149 //_______________________________________________________________________
1150 void AliRun::ReadTransPar()
1153 // Read filename to set the transport parameters
1157 const Int_t kncuts=10;
1158 const Int_t knflags=11;
1159 const Int_t knpars=kncuts+knflags;
1160 const char kpars[knpars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
1161 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
1162 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
1163 "MULS","PAIR","PHOT","RAYL"};
1167 Float_t cut[kncuts];
1168 Int_t flag[knflags];
1169 Int_t i, itmed, iret, ktmed, kz;
1172 // See whether the file is there
1173 filtmp=gSystem->ExpandPathName(fTransParName.Data());
1174 lun=fopen(filtmp,"r");
1177 Warning("ReadTransPar","File %s does not exist!\n",fTransParName.Data());
1182 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1183 printf(" *%59s\n","*");
1184 printf(" * Please check carefully what you are doing!%10s\n","*");
1185 printf(" *%59s\n","*");
1189 // Initialise cuts and flags
1190 for(i=0;i<kncuts;i++) cut[i]=-99;
1191 for(i=0;i<knflags;i++) flag[i]=-99;
1193 for(i=0;i<256;i++) line[i]='\0';
1194 // Read up to the end of line excluded
1195 iret=fscanf(lun,"%[^\n]",line);
1200 printf(" *%59s\n","*");
1201 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1205 // Read the end of line
1208 if(line[0]=='*') continue;
1210 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",
1211 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
1212 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
1213 &flag[8],&flag[9],&flag[10]);
1217 Warning("ReadTransPar","Error reading file %s\n",fTransParName.Data());
1220 // Check that the module exist
1221 AliModule *mod = GetModule(detName);
1223 // Get the array of media numbers
1224 TArrayI &idtmed = *mod->GetIdtmed();
1225 // Check that the tracking medium code is valid
1226 if(0<=itmed && itmed < 100) {
1227 ktmed=idtmed[itmed];
1229 Warning("ReadTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
1232 // Set energy thresholds
1233 for(kz=0;kz<kncuts;kz++) {
1235 if(fDebug) printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
1236 kpars[kz],cut[kz],itmed,mod->GetName());
1237 gMC->Gstpar(ktmed,kpars[kz],cut[kz]);
1240 // Set transport mechanisms
1241 for(kz=0;kz<knflags;kz++) {
1243 if(fDebug) printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
1244 kpars[kncuts+kz],flag[kz],itmed,mod->GetName());
1245 gMC->Gstpar(ktmed,kpars[kncuts+kz],Float_t(flag[kz]));
1249 Warning("ReadTransPar","Invalid medium code %d *\n",itmed);
1253 if(fDebug) printf("%s::ReadTransParModule: %s not present\n",ClassName(),detName);
1260 //_______________________________________________________________________
1261 void AliRun::MakeTree(Option_t *option, const char *file)
1264 // Create the ROOT trees
1265 // Loop on all detectors to create the Root branch (if any)
1271 const char *oK = strstr(option,"K");
1272 const char *oH = strstr(option,"H");
1273 const char *oTR = strstr(option,"T");
1274 const char *oE = strstr(option,"E");
1275 const char *oD = strstr(option,"D");
1276 const char *oR = strstr(option,"R");
1277 const char *oS = strstr(option,"S");
1280 TDirectory *cwd = gDirectory;
1282 TBranch *branch = 0;
1284 if (oK) fStack->MakeTree(fEvent, file);
1286 if (oE && !fTreeE) {
1287 fTreeE = new TTree("TE","Header");
1288 // branch = fTreeE->Branch("Header", "AliHeader", &fHeader, 4000, 0);
1289 branch = fTreeE->Branch("Header", "AliHeader", &fHeader, 4000, 0);
1290 branch->SetAutoDelete(kFALSE);
1291 TFolder *folder = dynamic_cast<TFolder *>(gROOT->FindObjectAny("/Folders/RunMC/Event/Header"));
1292 if (folder) folder->Add(fHeader);
1293 // branch = fTreeE->Branch("Stack","AliStack", &fStack, 4000, 0);
1294 // branch->SetAutoDelete(kFALSE);
1295 // if (folder) folder->Add(fStack);
1296 fTreeE->Write(0,TObject::kOverwrite);
1299 if (file && branch) {
1300 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
1301 sprintf(outFile,"%s/%s",GetBaseFile(),file);
1302 branch->SetFile(outFile);
1303 TIter next( branch->GetListOfBranches());
1304 while ((branch=dynamic_cast<TBranch*>(next()))) {
1305 branch->SetFile(outFile);
1308 printf("* MakeBranch * Diverting Branch %s to file %s\n", branch->GetName(),file);
1313 if (oH && !fTreeH) {
1314 sprintf(hname,"TreeH%d",fEvent);
1315 fTreeH = new TTree(hname,"Hits");
1316 fTreeH->SetAutoSave(1000000000); //no autosave
1317 fTreeH->Write(0,TObject::kOverwrite);
1320 if (oTR && !fTreeTR) {
1321 sprintf(hname,"TreeTR%d",fEvent);
1322 fTreeTR = new TTree(hname,"TrackReferences");
1323 fTreeTR->SetAutoSave(1000000000); //no autosave
1324 fTreeTR->Write(0,TObject::kOverwrite);
1327 if (oD && !fTreeD) {
1328 sprintf(hname,"TreeD%d",fEvent);
1329 fTreeD = new TTree(hname,"Digits");
1330 fTreeD->Write(0,TObject::kOverwrite);
1332 if (oS && !fTreeS) {
1333 sprintf(hname,"TreeS%d",fEvent);
1334 fTreeS = new TTree(hname,"SDigits");
1335 fTreeS->Write(0,TObject::kOverwrite);
1337 if (oR && !fTreeR) {
1338 sprintf(hname,"TreeR%d",fEvent);
1339 fTreeR = new TTree(hname,"Reconstruction");
1340 fTreeR->Write(0,TObject::kOverwrite);
1344 // Create a branch for hits/digits for each detector
1345 // Each branch is a TClonesArray. Each data member of the Hits classes
1346 // will be in turn a subbranch of the detector master branch
1347 TIter next(fModules);
1348 AliModule *detector;
1349 while((detector = dynamic_cast<AliModule*>(next()))) {
1350 if (oH) detector->MakeBranch(option,file);
1351 if (oTR) detector->MakeBranchTR(option,file);
1355 //_______________________________________________________________________
1356 TParticle* AliRun::Particle(Int_t i)
1358 return fStack->Particle(i);
1361 //_______________________________________________________________________
1362 void AliRun::ResetDigits()
1365 // Reset all Detectors digits
1367 TIter next(fModules);
1368 AliModule *detector;
1369 while((detector = dynamic_cast<AliModule*>(next()))) {
1370 detector->ResetDigits();
1374 //_______________________________________________________________________
1375 void AliRun::ResetSDigits()
1378 // Reset all Detectors digits
1380 TIter next(fModules);
1381 AliModule *detector;
1382 while((detector = dynamic_cast<AliModule*>(next()))) {
1383 detector->ResetSDigits();
1387 //_______________________________________________________________________
1388 void AliRun::ResetHits()
1391 // Reset all Detectors hits
1393 TIter next(fModules);
1394 AliModule *detector;
1395 while((detector = dynamic_cast<AliModule*>(next()))) {
1396 detector->ResetHits();
1400 //_______________________________________________________________________
1401 void AliRun::ResetTrackReferences()
1404 // Reset all Detectors hits
1406 TIter next(fModules);
1407 AliModule *detector;
1408 while((detector = dynamic_cast<AliModule*>(next()))) {
1409 detector->ResetTrackReferences();
1413 //_______________________________________________________________________
1414 void AliRun::ResetPoints()
1417 // Reset all Detectors points
1419 TIter next(fModules);
1420 AliModule *detector;
1421 while((detector = dynamic_cast<AliModule*>(next()))) {
1422 detector->ResetPoints();
1426 //_______________________________________________________________________
1427 void AliRun::InitMC(const char *setup)
1430 // Initialize the Alice setup
1434 Warning("Init","Cannot initialise AliRun twice!\n");
1438 gROOT->LoadMacro(setup);
1439 gInterpreter->ProcessLine(fConfigFunction.Data());
1441 // Register MC in configuration
1442 AliConfig::Instance()->Add(gMC);
1443 gMC->SetStack(fStack);
1445 gMC->DefineParticles(); //Create standard MC particles
1446 AliPDG::AddParticlesToPdgDataBase();
1448 TObject *objfirst, *objlast;
1450 fNdets = fModules->GetLast()+1;
1453 //=================Create Materials and geometry
1456 // Added also after in case of interactive initialisation of modules
1457 fNdets = fModules->GetLast()+1;
1459 TIter next(fModules);
1460 AliModule *detector;
1461 while((detector = dynamic_cast<AliModule*>(next()))) {
1462 detector->SetTreeAddress();
1463 objlast = gDirectory->GetList()->Last();
1465 // Add Detector histograms in Detector list of histograms
1466 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
1467 else objfirst = gDirectory->GetList()->First();
1469 detector->Histograms()->Add(objfirst);
1470 objfirst = gDirectory->GetList()->After(objfirst);
1473 ReadTransPar(); //Read the cuts for all materials
1475 MediaTable(); //Build the special IMEDIA table
1477 //Initialise geometry deposition table
1478 fEventEnergy.Set(gMC->NofVolumes()+1);
1479 fSummEnergy.Set(gMC->NofVolumes()+1);
1480 fSum2Energy.Set(gMC->NofVolumes()+1);
1482 //Compute cross-sections
1483 gMC->BuildPhysics();
1485 //Write Geometry object to current file.
1490 fMCQA = new AliMCQA(fNdets);
1492 AliConfig::Instance();
1494 // Save stuff at the beginning of the file to avoid file corruption
1498 //_______________________________________________________________________
1499 void AliRun::RunMC(Int_t nevent, const char *setup)
1502 // Main function to be called to process a galice run
1504 // Root > gAlice.Run();
1505 // a positive number of events will cause the finish routine
1508 fEventsPerRun = nevent;
1509 // check if initialisation has been done
1510 if (!fInitDone) InitMC(setup);
1512 // Create the Root Tree with one branch per detector
1516 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1517 MakeTree("K","Kine.root");
1518 MakeTree("H","Hits.root");
1523 gMC->ProcessRun(nevent);
1525 // End of this run, close files
1526 if(nevent>0) FinishRun();
1529 //_______________________________________________________________________
1530 void AliRun::RunReco(const char *selected, Int_t first, Int_t last)
1533 // Main function to be called to reconstruct Alice event
1535 cout << "Found "<< gAlice->TreeE()->GetEntries() << "events" << endl;
1536 Int_t nFirst = first;
1537 Int_t nLast = (last < 0)? static_cast<Int_t>(gAlice->TreeE()->GetEntries()) : last;
1539 for (Int_t nevent = nFirst; nevent <= nLast; nevent++) {
1540 cout << "Processing event "<< nevent << endl;
1543 Digits2Reco(selected);
1547 //_______________________________________________________________________
1549 void AliRun::Hits2Digits(const char *selected)
1552 // Convert Hits to sumable digits
1554 for (Int_t nevent=0; nevent<gAlice->TreeE()->GetEntries(); nevent++) {
1557 Hits2SDigits(selected);
1558 SDigits2Digits(selected);
1563 //_______________________________________________________________________
1565 void AliRun::Tree2Tree(Option_t *option, const char *selected)
1568 // Function to transform the content of
1570 // - TreeH to TreeS (option "S")
1571 // - TreeS to TreeD (option "D")
1572 // - TreeD to TreeR (option "R")
1574 // If multiple options are specified ("SDR"), transformation will be done in sequence for
1575 // selected detector and for all detectors if none is selected (detector string
1576 // can contain blank separated list of detector names).
1579 const char *oS = strstr(option,"S");
1580 const char *oD = strstr(option,"D");
1581 const char *oR = strstr(option,"R");
1583 TObjArray *detectors = Detectors();
1585 TIter next(detectors);
1587 AliDetector *detector = 0;
1589 TDirectory *cwd = gDirectory;
1593 while((detector = dynamic_cast<AliDetector*>(next()))) {
1595 if (strcmp(detector->GetName(),selected)) continue;
1596 if (detector->IsActive()){
1597 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1599 sprintf(outFile,"SDigits.%s.root",detector->GetName());
1600 detector->MakeBranch("S",outFile);
1603 sprintf(outFile,"Digits.%s.root",detector->GetName());
1604 detector->MakeBranch("D",outFile);
1607 sprintf(outFile,"Reco.%s.root",detector->GetName());
1608 detector->MakeBranch("R",outFile);
1611 detector->MakeBranch(option);
1617 cout << "Hits2SDigits: Processing " << detector->GetName() << "..." << endl;
1618 detector->Hits2SDigits();
1621 cout << "SDigits2Digits: Processing " << detector->GetName() << "..." << endl;
1622 detector->SDigits2Digits();
1625 cout << "Digits2Reco: Processing " << detector->GetName() << "..." << endl;
1626 detector->Digits2Reco();
1635 //_______________________________________________________________________
1636 void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min,
1637 Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max,
1638 Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener)
1641 // Generates lego plots of:
1642 // - radiation length map phi vs theta
1643 // - radiation length map phi vs eta
1644 // - interaction length map
1645 // - g/cm2 length map
1647 // ntheta bins in theta, eta
1648 // themin minimum angle in theta (degrees)
1649 // themax maximum angle in theta (degrees)
1651 // phimin minimum angle in phi (degrees)
1652 // phimax maximum angle in phi (degrees)
1653 // rmin minimum radius
1654 // rmax maximum radius
1657 // The number of events generated = ntheta*nphi
1658 // run input parameters in macro setup (default="Config.C")
1660 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1663 <img src="picts/AliRunLego1.gif">
1668 <img src="picts/AliRunLego2.gif">
1673 <img src="picts/AliRunLego3.gif">
1678 // check if initialisation has been done
1679 if (!fInitDone) InitMC(setup);
1680 //Save current generator
1681 AliGenerator *gen=Generator();
1683 // Set new generator
1684 if (!gener) gener = new AliLegoGenerator();
1685 ResetGenerator(gener);
1687 // Configure Generator
1688 gener->SetRadiusRange(rmin, rmax);
1689 gener->SetZMax(zmax);
1690 gener->SetCoor1Range(nc1, c1min, c1max);
1691 gener->SetCoor2Range(nc2, c2min, c2max);
1694 //Create Lego object
1695 fLego = new AliLego("lego",gener);
1697 //Prepare MC for Lego Run
1702 //gMC->ProcessRun(nc1*nc2+1);
1703 gMC->ProcessRun(nc1*nc2);
1705 // Create only the Root event Tree
1708 // End of this run, close files
1710 // Restore current generator
1711 ResetGenerator(gen);
1712 // Delete Lego Object
1713 delete fLego; fLego=0;
1716 //_______________________________________________________________________
1717 void AliRun::SetConfigFunction(const char * config)
1720 // Set the signature of the function contained in Config.C to configure
1723 fConfigFunction=config;
1726 //_______________________________________________________________________
1727 void AliRun::SetCurrentTrack(Int_t track)
1730 // Set current track number
1732 fStack->SetCurrentTrack(track);
1735 //_______________________________________________________________________
1736 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1737 Float_t *vpos, Float_t *polar, Float_t tof,
1738 TMCProcess mech, Int_t &ntr, Float_t weight, Int_t is)
1740 // Delegate to stack
1743 fStack->SetTrack(done, parent, pdg, pmom, vpos, polar, tof,
1744 mech, ntr, weight, is);
1747 //_______________________________________________________________________
1748 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg,
1749 Double_t px, Double_t py, Double_t pz, Double_t e,
1750 Double_t vx, Double_t vy, Double_t vz, Double_t tof,
1751 Double_t polx, Double_t poly, Double_t polz,
1752 TMCProcess mech, Int_t &ntr, Float_t weight, Int_t is)
1754 // Delegate to stack
1756 fStack->SetTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
1757 polx, poly, polz, mech, ntr, weight, is);
1761 //_______________________________________________________________________
1762 void AliRun::SetHighWaterMark(const Int_t nt)
1765 // Set high water mark for last track in event
1766 fStack->SetHighWaterMark(nt);
1769 //_______________________________________________________________________
1770 void AliRun::KeepTrack(const Int_t track)
1773 // Delegate to stack
1775 fStack->KeepTrack(track);
1782 //_______________________________________________________________________
1783 void AliRun::ConstructGeometry()
1786 // Create modules, materials, geometry
1790 TIter next(fModules);
1791 AliModule *detector;
1792 printf("Geometry creation:\n");
1793 while((detector = dynamic_cast<AliModule*>(next()))) {
1795 // Initialise detector materials and geometry
1796 detector->CreateMaterials();
1797 detector->CreateGeometry();
1798 printf("%10s R:%.2fs C:%.2fs\n",
1799 detector->GetName(),stw.RealTime(),stw.CpuTime());
1803 //_______________________________________________________________________
1804 void AliRun::InitGeometry()
1807 // Initialize detectors and display geometry
1810 printf("Initialisation:\n");
1812 TIter next(fModules);
1813 AliModule *detector;
1814 while((detector = dynamic_cast<AliModule*>(next()))) {
1816 // Initialise detector and display geometry
1818 detector->BuildGeometry();
1819 printf("%10s R:%.2fs C:%.2fs\n",
1820 detector->GetName(),stw.RealTime(),stw.CpuTime());
1825 //_______________________________________________________________________
1826 void AliRun::GeneratePrimaries()
1829 // Generate primary particles and fill them in the stack.
1832 Generator()->Generate();
1835 //_______________________________________________________________________
1836 void AliRun::BeginEvent()
1838 // Clean-up previous event
1840 fEventEnergy.Reset();
1841 // Clean detector information
1848 // Reset all Detectors & kinematics & trees
1852 // Initialise event header
1853 fHeader->Reset(fRun,fEvent,fEventNrInRun);
1855 fStack->BeginEvent(fEvent);
1859 fLego->BeginEvent();
1866 ResetTrackReferences();
1873 sprintf(hname,"TreeH%d",fEvent);
1874 fTreeH->SetName(hname);
1879 sprintf(hname,"TreeTR%d",fEvent);
1880 fTreeTR->SetName(hname);
1885 sprintf(hname,"TreeD%d",fEvent);
1886 fTreeD->SetName(hname);
1887 fTreeD->Write(0,TObject::kOverwrite);
1891 sprintf(hname,"TreeS%d",fEvent);
1892 fTreeS->SetName(hname);
1893 fTreeS->Write(0,TObject::kOverwrite);
1897 sprintf(hname,"TreeR%d",fEvent);
1898 fTreeR->SetName(hname);
1899 fTreeR->Write(0,TObject::kOverwrite);
1903 //_______________________________________________________________________
1904 void AliRun::BeginPrimary()
1907 // Called at the beginning of each primary track
1911 gAlice->ResetHits();
1912 gAlice->ResetTrackReferences();
1916 //_______________________________________________________________________
1917 void AliRun::PreTrack()
1919 TObjArray &dets = *fModules;
1922 for(Int_t i=0; i<=fNdets; i++)
1923 if((module = dynamic_cast<AliModule*>(dets[i])))
1929 //_______________________________________________________________________
1930 void AliRun::Stepping()
1933 // Called at every step during transport
1936 Int_t id = DetFromMate(gMC->GetMedium());
1940 // --- If lego option, do it and leave
1942 fLego->StepManager();
1945 //Update energy deposition tables
1946 AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
1948 //Call the appropriate stepping routine;
1949 AliModule *det = dynamic_cast<AliModule*>(fModules->At(id));
1950 if(det && det->StepManagerIsEnabled()) {
1951 fMCQA->StepManager(id);
1957 //_______________________________________________________________________
1958 void AliRun::PostTrack()
1960 TObjArray &dets = *fModules;
1963 for(Int_t i=0; i<=fNdets; i++)
1964 if((module = dynamic_cast<AliModule*>(dets[i])))
1965 module->PostTrack();
1968 //_______________________________________________________________________
1969 void AliRun::FinishPrimary()
1972 // Called at the end of each primary track
1975 // static Int_t count=0;
1976 // const Int_t times=10;
1977 // This primary is finished, purify stack
1978 fStack->PurifyKine();
1980 TIter next(fModules);
1981 AliModule *detector;
1982 while((detector = dynamic_cast<AliModule*>(next()))) {
1983 detector->FinishPrimary();
1986 // Write out hits if any
1987 if (gAlice->TreeH()) {
1988 gAlice->TreeH()->Fill();
1991 // Write out hits if any
1992 if (gAlice->TreeTR()) {
1993 gAlice->TreeTR()->Fill();
1997 // if(++count%times==1) gObjectTable->Print();
2000 //_______________________________________________________________________
2001 void AliRun::FinishEvent()
2004 // Called at the end of the event.
2008 if(fLego) fLego->FinishEvent();
2010 //Update the energy deposit tables
2012 for(i=0;i<fEventEnergy.GetSize();i++) {
2013 fSummEnergy[i]+=fEventEnergy[i];
2014 fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
2019 // Update Header information
2021 fHeader->SetNprimary(fStack->GetNprimary());
2022 fHeader->SetNtrack(fStack->GetNtrack());
2025 // Write out the kinematics
2026 fStack->FinishEvent();
2028 // Write out the event Header information
2030 fHeader->SetStack(fStack);
2035 // Write Tree headers
2036 TTree* pTreeK = fStack->TreeK();
2037 if (pTreeK) pTreeK->Write(0,TObject::kOverwrite);
2038 if (fTreeH) fTreeH->Write(0,TObject::kOverwrite);
2039 if (fTreeTR) fTreeTR->Write(0,TObject::kOverwrite);
2045 //_______________________________________________________________________
2046 void AliRun::Field(const Double_t* x, Double_t *b) const
2049 for (Int_t i=0; i<3; i++) xfloat[i] = x[i];
2053 Field()->Field(xfloat,bfloat);
2054 for (Int_t j=0; j<3; j++) b[j] = bfloat[j];
2057 printf("No mag field defined!\n");
2064 // End of MC Application
2067 //_______________________________________________________________________
2068 void AliRun::Streamer(TBuffer &R__b)
2070 // Stream an object of class AliRun.
2072 if (R__b.IsReading()) {
2073 if (!gAlice) gAlice = this;
2075 AliRun::Class()->ReadBuffer(R__b, this);
2077 gROOT->GetListOfBrowsables()->Add(this,"Run");
2079 fTreeE = dynamic_cast<TTree*>(gDirectory->Get("TE"));
2081 fTreeE->SetBranchAddress("Header", &fHeader);
2083 else Error("Streamer","cannot find Header Tree\n");
2085 fTreeE->GetEntry(0);
2088 AliRun::Class()->WriteBuffer(R__b, this);
2093 //_______________________________________________________________________
2094 Int_t AliRun::CurrentTrack() const {
2096 // Returns current track
2098 return fStack->CurrentTrack();
2101 //_______________________________________________________________________
2102 Int_t AliRun::GetNtrack() const {
2104 // Returns number of tracks in stack
2106 return fStack->GetNtrack();
2109 //_______________________________________________________________________
2110 TObjArray* AliRun::Particles() {
2112 // Returns pointer to Particles array
2114 return fStack->Particles();
2117 //_______________________________________________________________________
2118 TTree* AliRun::TreeK() {
2120 // Returns pointer to the TreeK array
2122 return fStack->TreeK();
2126 //_______________________________________________________________________
2127 void AliRun::SetGenEventHeader(AliGenEventHeader* header)
2129 fHeader->SetGenEventHeader(header);
2132 //_______________________________________________________________________
2133 TFile* AliRun::InitFile(TString fileName)
2136 // create the file where the whole tree will be saved
2138 TDirectory *wd = gDirectory;
2139 TFile* file = TFile::Open(fileName,"update");
2141 if (!file->IsOpen()) {
2142 Error("Cannot open file, %s\n",fileName);
2148 //_______________________________________________________________________
2149 TFile* AliRun::InitTreeFile(Option_t *option, TString fileName)
2152 // create the file where one of the following trees will be saved
2154 // WARNING: by default these trees are saved on the file on which
2155 // hits are stored. If you divert one of these trees, you cannot restore
2156 // it to the original file (usually galice.root) in the same aliroot session
2157 Bool_t oS = (strstr(option,"S")!=0);
2158 Bool_t oR = (strstr(option,"R")!=0);
2159 Bool_t oD = (strstr(option,"D")!=0);
2161 for (Int_t i=0; i<3; i++) choice[i] = 0;
2162 if(oS)choice[0] = 1;
2163 if(oD)choice[1] = 1;
2164 if(oR)choice[2] = 1;
2168 if(!(oS || oR || oD))return ptr;
2171 for (Int_t i=0; i<3; i++) active[i] = 0;
2172 if(fTreeSFileName != "") active[0] = 1;
2173 if(fTreeDFileName != "") active[1] = 1;
2174 if(fTreeDFileName != "") active[2] = 1;
2176 Bool_t alreadyopen1 = kFALSE;
2177 Bool_t alreadyopen2 = kFALSE;
2180 // if already active and same name with non-null ptr
2181 if(active[0]==1 && fileName == fTreeSFileName && fTreeSFile){
2182 Warning("InitTreeFile","File %s already opened",fTreeSFileName.Data());
2186 // if already active with different name with non-null ptr
2187 if(active[0]==1 && fileName != fTreeSFileName && fTreeSFile){
2188 // close the active files and also the other possible files in option
2189 CloseTreeFile(option);
2191 fTreeSFileName = fileName;
2193 (active[1] == 1 && fTreeDFileName == fTreeSFileName && fTreeDFile);
2195 (active[2] == 1 && fTreeRFileName == fTreeSFileName && fTreeRFile);
2196 if(!(alreadyopen1 || alreadyopen2)){
2197 ptr = InitFile(fileName);
2201 if(alreadyopen1){fTreeSFile = fTreeDFile; ptr = fTreeSFile;}
2202 if(alreadyopen2){fTreeSFile = fTreeRFile; ptr = fTreeSFile;}
2204 if(choice[1] == 1) { fTreeDFileName = fileName; fTreeDFile = ptr;}
2205 if(choice[2] == 1) { fTreeRFileName = fileName; fTreeRFile = ptr;}
2211 // if already active and same name with non-null ptr
2212 if(active[1]==1 && fileName == fTreeDFileName && fTreeDFile){
2213 Warning("InitTreeFile","File %s already opened",fTreeDFileName.Data());
2217 // if already active with different name with non-null ptr
2218 if(active[1]==1 && fileName != fTreeDFileName && fTreeDFile){
2219 // close the active files and also the other possible files in option
2220 CloseTreeFile(option);
2222 fTreeDFileName = fileName;
2224 (active[0] == 1 && fTreeSFileName == fTreeDFileName && fTreeSFile);
2226 (active[2] == 1 && fTreeRFileName == fTreeDFileName && fTreeRFile);
2227 if(!(alreadyopen1 || alreadyopen2)){
2228 ptr = InitFile(fileName);
2232 if(alreadyopen1){fTreeDFile = fTreeSFile; ptr = fTreeDFile;}
2233 if(alreadyopen2){fTreeDFile = fTreeRFile; ptr = fTreeDFile;}
2235 if(choice[2] == 1) { fTreeRFileName = fileName; fTreeRFile = ptr;}
2241 // if already active and same name with non-null ptr
2242 if(active[2]==1 && fileName == fTreeRFileName && fTreeRFile){
2243 Warning("InitTreeFile","File %s already opened",fTreeRFileName.Data());
2247 // if already active with different name with non-null ptr
2248 if(active[2]==1 && fileName != fTreeRFileName && fTreeRFile){
2249 // close the active files and also the other possible files in option
2250 CloseTreeFile(option);
2252 fTreeRFileName = fileName;
2254 (active[1] == 1 && fTreeDFileName == fTreeRFileName && fTreeDFile);
2256 (active[0]== 1 && fTreeSFileName == fTreeRFileName && fTreeSFile);
2257 if(!(alreadyopen1 || alreadyopen2)){
2258 ptr = InitFile(fileName);
2262 if(alreadyopen1){fTreeRFile = fTreeDFile; ptr = fTreeRFile;}
2263 if(alreadyopen2){fTreeRFile = fTreeSFile; ptr = fTreeRFile;}
2271 //_______________________________________________________________________
2272 void AliRun::PrintTreeFile()
2275 // prints the file names and pointer associated to S,D,R trees
2277 cout<<"===================================================\n";
2278 TFile *file = fTreeE->GetCurrentFile();
2279 TString curfilname="";
2280 if(file)curfilname=static_cast<TString>(file->GetName());
2281 cout<<" Current tree file name: "<<curfilname<<endl;
2282 cout<<"Pointer: "<<file<<endl;
2283 cout<<" Tree S File name: "<<fTreeSFileName<<endl;
2284 cout<<"Pointer: "<<fTreeSFile<<endl<<endl;
2285 cout<<" Tree D File name: "<<fTreeDFileName<<endl;
2286 cout<<"Pointer: "<<fTreeDFile<<endl<<endl;
2287 cout<<" Tree R File name: "<<fTreeRFileName<<endl;
2288 cout<<"Pointer: "<<fTreeRFile<<endl<<endl;
2289 cout<<"===================================================\n";
2291 //_______________________________________________________________________
2292 void AliRun::CloseTreeFile(Option_t *option)
2295 // closes the file containing the tree specified in option
2298 Bool_t oS = (strstr(option,"S")!=0);
2299 Bool_t oR = (strstr(option,"R")!=0);
2300 Bool_t oD = (strstr(option,"D")!=0);
2301 Bool_t none = !(oS || oR || oD);
2304 fTreeSFileName = "";
2306 if(!((fTreeSFile == fTreeDFile) || (fTreeSFile == fTreeRFile)) &&
2307 fTreeSFile->IsOpen()){
2308 fTreeSFile->Close();
2315 fTreeDFileName = "";
2317 if(!((fTreeDFile == fTreeRFile) || (fTreeDFile == fTreeSFile)) &&
2318 fTreeDFile->IsOpen()){
2319 fTreeDFile->Close();
2326 fTreeRFileName = "";
2328 if(!((fTreeRFile == fTreeSFile) || (fTreeRFile == fTreeDFile)) &&
2329 fTreeRFile->IsOpen()){
2330 fTreeRFile->Close();
2338 //_______________________________________________________________________
2339 void AliRun::MakeTree(Option_t *option, TFile *file)
2342 // Create some trees in the separate file
2344 const char *oD = strstr(option,"D");
2345 const char *oR = strstr(option,"R");
2346 const char *oS = strstr(option,"S");
2348 TDirectory *cwd = gDirectory;
2353 sprintf(hname,"TreeD%d",fEvent);
2355 fTreeD = static_cast<TTree*>(file->Get("hname"));
2357 fTreeD = new TTree(hname,"Digits");
2358 fTreeD->Write(0,TObject::kOverwrite);
2364 sprintf(hname,"TreeS%d",fEvent);
2366 fTreeS = static_cast<TTree*>(file->Get("hname"));
2368 fTreeS = new TTree(hname,"SDigits");
2369 fTreeS->Write(0,TObject::kOverwrite);
2376 sprintf(hname,"TreeR%d",fEvent);
2378 fTreeR = static_cast<TTree*>(file->Get("hname"));
2380 fTreeR = new TTree(hname,"RecPoint");
2381 fTreeR->Write(0,TObject::kOverwrite);