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.86 2002/05/28 14:24:57 hristov
19 Correct warning messages
21 Revision 1.85 2002/05/24 13:29:58 hristov
22 AliTrackReference added, AliDisplay modified
24 Revision 1.84 2002/05/21 16:26:07 hristov
25 Find correctly TreeK in case CONFIG_SPLIT_FILE is set (Y.Schutz)
27 Revision 1.83 2002/04/04 13:16:17 jchudoba
28 add possibility to write sdigits, digits and rec. points into separate files
30 Revision 1.82 2002/03/12 11:06:03 morsch
31 Add particle status code to argument list of SetTrack(..).
33 Revision 1.81 2001/12/19 14:46:26 morsch
34 Add possibility to disable StepManager() for each module separately.
36 Revision 1.80 2001/10/21 18:22:55 hristov
37 BranchOld replaced by Branch. It works correctly with Root 2.02.xx
39 Revision 1.79 2001/10/09 18:00:35 hristov
40 Temporary fix to provide unique event number in the simulation (J.Chudoba)
42 Revision 1.78 2001/10/04 15:30:56 hristov
43 Changes to accommodate the set of PHOS folders and tasks (Y.Schutz)
45 Revision 1.77 2001/09/04 15:09:11 hristov
46 fTreeE->Branch replaced temporary by fTreeE->BranchOld to avoid data corruption in case of many events per file
48 Revision 1.76 2001/08/03 14:38:35 morsch
49 Use original method to access TreeH.
51 Revision 1.75 2001/07/28 10:52:27 hristov
52 Event number updated correctly (M.Ivanov)
54 Revision 1.74 2001/07/28 10:39:16 morsch
55 GetEventsPerRun() method needed by afterburners added to AliRun.h
56 Corresponding setters and getters have been from AliGenerator.
58 Revision 1.73 2001/07/27 12:34:30 jchudoba
59 remove the dummy argument in fStack->GetEvent call
61 Revision 1.72 2001/07/03 08:10:57 hristov
62 J.Chudoba's changes merged correctly with the HEAD
64 Revision 1.70 2001/06/29 08:01:36 morsch
65 Small correction to the previous.
67 Revision 1.69 2001/06/28 16:27:50 morsch
68 AliReco() with user control of event range.
70 Revision 1.68 2001/06/11 13:14:40 morsch
71 SetAliGenEventHeader() method added.
73 Revision 1.67 2001/06/07 18:24:50 buncic
74 Removed compilation warning in AliConfig initialisation.
76 Revision 1.66 2001/05/22 14:32:40 hristov
79 Revision 1.65 2001/05/21 17:22:51 buncic
80 Fixed problem with missing AliConfig while reading galice.root
82 Revision 1.64 2001/05/16 14:57:22 alibrary
83 New files for folders and Stack
85 Revision 1.62 2001/04/06 11:12:33 morsch
86 Clear fParticles after each event. (Ivana Hrivnacova)
88 Revision 1.61 2001/03/30 07:04:10 morsch
89 Call fGenerator->FinishRun() for final print-outs, cross-section and weight calculations.
91 Revision 1.60 2001/03/21 18:22:30 hristov
92 fParticleFileMap fix (I.Hrivnacova)
94 Revision 1.59 2001/03/12 17:47:03 hristov
95 Changes needed on Sun with CC 5.0
97 Revision 1.58 2001/03/09 14:27:26 morsch
98 Fix for multiple events per file: inhibit decrease of size of fParticleFileMap.
100 Revision 1.57 2001/02/23 17:40:23 buncic
101 All trees needed for simulation created in RunMC(). TreeR and its branches
102 are now created in new RunReco() method.
104 Revision 1.56 2001/02/14 15:45:20 hristov
105 Algorithmic way of getting entry index in fParticleMap. Protection of fParticleFileMap (I.Hrivnacova)
107 Revision 1.55 2001/02/12 15:52:54 buncic
108 Removed OpenBaseFile().
110 Revision 1.54 2001/02/07 10:39:05 hristov
111 Remove default value for argument
113 Revision 1.53 2001/02/06 11:02:26 hristov
114 New SetTrack interface added, added check for unfilled particles in FinishEvent (I.Hrivnacova)
116 Revision 1.52 2001/02/05 16:22:25 buncic
117 Added TreeS to GetEvent().
119 Revision 1.51 2001/02/02 15:16:20 morsch
120 SetHighWaterMark method added to mark last particle in event.
122 Revision 1.50 2001/01/27 10:32:00 hristov
123 Leave the loop when primaries are filled (I.Hrivnacova)
125 Revision 1.49 2001/01/26 19:58:48 hristov
126 Major upgrade of AliRoot code
128 Revision 1.48 2001/01/17 10:50:50 hristov
129 Corrections to destructors
131 Revision 1.47 2000/12/18 10:44:01 morsch
132 Possibility to set field map by passing pointer to objet of type AliMagF via
135 gAlice->SetField(new AliMagFCM("Map2", "$(ALICE_ROOT)/data/field01.dat",2,1.,10.));
137 Revision 1.46 2000/12/14 19:29:27 fca
138 galice.cuts was not read any more
140 Revision 1.45 2000/11/30 07:12:49 alibrary
141 Introducing new Rndm and QA classes
143 Revision 1.44 2000/10/26 13:58:59 morsch
144 Add possibility to choose the lego generator (of type AliGeneratorLego or derived) when running
145 RunLego(). Default is the base class AliGeneratorLego.
147 Revision 1.43 2000/10/09 09:43:17 fca
148 Special remapping of hits for TPC and TRD. End-of-primary action introduced
150 Revision 1.42 2000/10/02 21:28:14 fca
151 Removal of useless dependecies via forward declarations
153 Revision 1.41 2000/07/13 16:19:09 fca
154 Mainly coding conventions + some small bug fixes
156 Revision 1.40 2000/07/12 08:56:25 fca
157 Coding convention correction and warning removal
159 Revision 1.39 2000/07/11 18:24:59 fca
160 Coding convention corrections + few minor bug fixes
162 Revision 1.38 2000/06/20 13:05:45 fca
163 Writing down the TREE headers before job starts
165 Revision 1.37 2000/06/09 20:05:11 morsch
166 Introduce possibility to chose magnetic field version 3: AliMagFDM + field02.dat
168 Revision 1.36 2000/06/08 14:03:58 hristov
169 Only one initializer for a default argument
171 Revision 1.35 2000/06/07 10:13:14 hristov
172 Delete only existent objects.
174 Revision 1.34 2000/05/18 10:45:38 fca
175 Delete Particle Factory properly
177 Revision 1.33 2000/05/16 13:10:40 fca
178 New method IsNewTrack and fix for a problem in Father-Daughter relations
180 Revision 1.32 2000/04/27 10:38:21 fca
181 Correct termination of Lego Run and introduce Lego getter in AliRun
183 Revision 1.31 2000/04/26 10:17:32 fca
184 Changes in Lego for G4 compatibility
186 Revision 1.30 2000/04/18 19:11:40 fca
187 Introduce variable Config.C function signature
189 Revision 1.29 2000/04/07 11:12:34 fca
190 G4 compatibility changes
192 Revision 1.28 2000/04/05 06:51:06 fca
193 Workaround for an HP compiler problem
195 Revision 1.27 2000/03/22 18:08:07 fca
196 Rationalisation of the virtual MC interfaces
198 Revision 1.26 2000/03/22 13:42:26 fca
199 SetGenerator does not replace an existing generator, ResetGenerator does
201 Revision 1.25 2000/02/23 16:25:22 fca
202 AliVMC and AliGeant3 classes introduced
203 ReadEuclid moved from AliRun to AliModule
205 Revision 1.24 2000/01/19 17:17:20 fca
206 Introducing a list of lists of hits -- more hits allowed for detector now
208 Revision 1.23 1999/12/03 11:14:31 fca
209 Fixing previous wrong checking
211 Revision 1.21 1999/11/25 10:40:08 fca
212 Fixing daughters information also in primary tracks
214 Revision 1.20 1999/10/04 18:08:49 fca
215 Adding protection against inconsistent Euclid files
217 Revision 1.19 1999/09/29 07:50:40 fca
218 Introduction of the Copyright and cvs Log
222 ///////////////////////////////////////////////////////////////////////////////
224 // Control class for Alice C++ //
225 // Only one single instance of this class exists. //
226 // The object is created in main program aliroot //
227 // and is pointed by the global gAlice. //
229 // -Supports the list of all Alice Detectors (fModules). //
230 // -Supports the list of particles (fParticles). //
231 // -Supports the Trees. //
232 // -Supports the geometry. //
233 // -Supports the event display. //
236 <img src="picts/AliRunClass.gif">
241 <img src="picts/alirun.gif">
245 ///////////////////////////////////////////////////////////////////////////////
250 #include <iostream.h>
257 #include <TObjectTable.h>
259 #include <TGeometry.h>
261 #include <TBrowser.h>
265 #include "TParticle.h"
267 #include "AliDisplay.h"
270 #include "AliMagFC.h"
271 #include "AliMagFCM.h"
272 #include "AliMagFDM.h"
274 #include "TRandom3.h"
276 #include "AliGenerator.h"
277 #include "AliLegoGenerator.h"
278 #include "AliConfig.h"
279 #include "AliStack.h"
280 #include "AliGenEventHeader.h"
281 #include "AliHeader.h"
283 #include "AliDetector.h"
289 //_____________________________________________________________________________
293 // Default constructor for AliRun
318 fPDGDB = 0; //Particle factory object!
320 fConfigFunction = "\0";
323 fTransParName = "\0";
324 fBaseFileName = ".\0";
334 //_____________________________________________________________________________
335 AliRun::AliRun(const char *name, const char *title)
339 // Constructor for the main processor.
340 // Creates the geometry
341 // Creates the list of Detectors.
342 // Creates the list of particles.
359 fConfigFunction = "Config();";
367 // Set random number generator
368 gRandom = fRandom = new TRandom3();
370 if (gSystem->Getenv("CONFIG_SEED")) {
371 gRandom->SetSeed((UInt_t)atoi(gSystem->Getenv("CONFIG_SEED")));
374 gROOT->GetListOfBrowsables()->Add(this,name);
377 fStack = new AliStack(10000);
378 // create the support list for the various Detectors
379 fModules = new TObjArray(77);
381 // Create the TNode geometry for the event display
383 BuildSimpleGeometry();
385 fHeader = new AliHeader();
392 // Create default mag field
397 // Prepare the tracking medium lists
398 fImedia = new TArrayI(1000);
399 for(i=0;i<1000;i++) (*fImedia)[i]=-99;
402 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
404 AliConfig::Instance()->Add(fPDGDB);
406 // Create HitLists list
407 fHitLists = new TList();
410 fBaseFileName = ".\0";
416 //_____________________________________________________________________________
420 // Default AliRun destructor
423 if(fTreeE)curfil=fTreeE->GetCurrentFile();
446 // avoid to delete TFile objects not owned by this object
447 // avoid multiple deletions
448 if(curfil == fTreeDFile) fTreeDFile=0;
449 if(curfil == fTreeSFile) fTreeSFile=0;
450 if(curfil == fTreeRFile) fTreeRFile=0;
451 if(fTreeSFile == fTreeDFile) fTreeSFile=0;
452 if(fTreeRFile == fTreeDFile) fTreeRFile=0;
453 if(fTreeRFile == fTreeSFile) fTreeRFile=0;
455 if(fTreeDFile->IsOpen())fTreeDFile->Close();
459 if(fTreeSFile->IsOpen())fTreeSFile->Close();
463 if(fTreeRFile->IsOpen())fTreeRFile->Close();
466 if (gROOT->GetListOfBrowsables())
467 gROOT->GetListOfBrowsables()->Remove(this);
470 //_____________________________________________________________________________
471 void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
474 // Add a hit to detector id
476 TObjArray &dets = *fModules;
477 if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits);
480 //_____________________________________________________________________________
481 void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
484 // Add digit to detector id
486 TObjArray &dets = *fModules;
487 if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits);
490 //_____________________________________________________________________________
491 void AliRun::Browse(TBrowser *b)
494 // Called when the item "Run" is clicked on the left pane
495 // of the Root browser.
496 // It displays the Root Trees and all detectors.
498 if(!fStack) fStack=fHeader->Stack();
499 TTree* pTreeK = fStack->TreeK();
501 if (pTreeK) b->Add(pTreeK,pTreeK->GetName());
502 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
503 if (fTreeTR) b->Add(fTreeTR,fTreeH->GetName());
504 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
505 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
506 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
507 if (fTreeS) b->Add(fTreeS,fTreeS->GetName());
509 TIter next(fModules);
511 while((detector = (AliModule*)next())) {
512 b->Add(detector,detector->GetName());
514 b->Add(fMCQA,"AliMCQA");
517 //_____________________________________________________________________________
521 // Initialize Alice geometry
526 //_____________________________________________________________________________
527 void AliRun::BuildSimpleGeometry()
530 // Create a simple TNode geometry used by Root display engine
532 // Initialise geometry
534 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
535 new TMaterial("void","Vacuum",0,0,0); //Everything is void
536 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
537 brik->SetVisibility(0);
538 new TNode("alice","alice","S_alice");
541 //_____________________________________________________________________________
542 void AliRun::CleanDetectors()
545 // Clean Detectors at the end of event
547 TIter next(fModules);
549 while((detector = (AliModule*)next())) {
550 detector->FinishEvent();
554 //_____________________________________________________________________________
555 Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
558 // Return the distance from the mouse to the AliRun object
564 //_____________________________________________________________________________
565 void AliRun::DumpPart (Int_t i) const
568 // Dumps particle i in the stack
573 //_____________________________________________________________________________
574 void AliRun::DumpPStack () const
577 // Dumps the particle stack
579 fStack->DumpPStack();
582 //_____________________________________________________________________________
583 void AliRun::SetField(AliMagF* magField)
585 // Set Magnetic Field Map
590 //_____________________________________________________________________________
591 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
592 Float_t maxField, char* filename)
595 // Set magnetic field parameters
596 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
597 // version Magnetic field map version (only 1 active now)
598 // scale Scale factor for the magnetic field
599 // maxField Maximum value for the magnetic field
602 // --- Sanity check on mag field flags
603 if(fField) delete fField;
605 fField = new AliMagFC("Map1"," ",type,scale,maxField);
606 } else if(version<=2) {
607 fField = new AliMagFCM("Map2-3",filename,type,scale,maxField);
609 } else if(version==3) {
610 fField = new AliMagFDM("Map4",filename,type,scale,maxField);
613 Warning("SetField","Invalid map %d\n",version);
617 //_____________________________________________________________________________
618 void AliRun::PreTrack()
620 TObjArray &dets = *fModules;
623 for(Int_t i=0; i<=fNdets; i++)
624 if((module = (AliModule*)dets[i]))
630 //_____________________________________________________________________________
631 void AliRun::PostTrack()
633 TObjArray &dets = *fModules;
636 for(Int_t i=0; i<=fNdets; i++)
637 if((module = (AliModule*)dets[i]))
641 //_____________________________________________________________________________
642 void AliRun::FinishPrimary()
645 // Called at the end of each primary track
648 // static Int_t count=0;
649 // const Int_t times=10;
650 // This primary is finished, purify stack
651 fStack->PurifyKine();
653 TIter next(fModules);
655 while((detector = (AliModule*)next())) {
656 detector->FinishPrimary();
659 // Write out hits if any
660 if (gAlice->TreeH()) {
661 gAlice->TreeH()->Fill();
664 // Write out hits if any
665 if (gAlice->TreeTR()) {
666 gAlice->TreeTR()->Fill();
671 // if(++count%times==1) gObjectTable->Print();
674 //_____________________________________________________________________________
675 void AliRun::BeginPrimary()
678 // Called at the beginning of each primary track
683 gAlice->ResetTrackReferences();
686 //_____________________________________________________________________________
687 void AliRun::FinishEvent()
690 // Called at the end of the event.
694 if(fLego) fLego->FinishEvent();
696 //Update the energy deposit tables
698 for(i=0;i<fEventEnergy.GetSize();i++) {
699 fSummEnergy[i]+=fEventEnergy[i];
700 fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
705 // Update Header information
707 fHeader->SetNprimary(fStack->GetNprimary());
708 fHeader->SetNtrack(fStack->GetNtrack());
711 // Write out the kinematics
712 fStack->FinishEvent();
714 // Write out the event Header information
716 fHeader->SetStack(fStack);
721 // Write Tree headers
722 TTree* pTreeK = fStack->TreeK();
723 if (pTreeK) pTreeK->Write(0,TObject::kOverwrite);
724 if (fTreeH) fTreeH->Write(0,TObject::kOverwrite);
725 if (fTreeTR) fTreeTR->Write(0,TObject::kOverwrite);
731 //_____________________________________________________________________________
732 void AliRun::FinishRun()
735 // Called at the end of the run.
739 if(fLego) fLego->FinishRun();
741 // Clean detector information
742 TIter next(fModules);
744 while((detector = (AliModule*)next())) {
745 detector->FinishRun();
748 //Output energy summary tables
751 TFile *file = fTreeE->GetCurrentFile();
755 fTreeE->Write(0,TObject::kOverwrite);
757 // Write AliRun info and all detectors parameters
758 Write(0,TObject::kOverwrite);
760 // Clean tree information
765 delete fTreeH; fTreeH = 0;
768 delete fTreeTR; fTreeTR = 0;
772 delete fTreeD; fTreeD = 0;
775 delete fTreeR; fTreeR = 0;
778 // delete fTreeE; fTreeE = 0;
781 delete fTreeS; fTreeS = 0;
783 fGenerator->FinishRun();
789 //_____________________________________________________________________________
790 void AliRun::FlagTrack(Int_t track)
794 fStack->FlagTrack(track);
797 //_____________________________________________________________________________
798 void AliRun::EnergySummary()
801 // Print summary of deposited energy
807 Int_t kn, i, left, j, id;
808 const Float_t kzero=0;
809 Int_t ievent=fHeader->GetEvent()+1;
811 // Energy loss information
813 printf("***************** Energy Loss Information per event (GEV) *****************\n");
814 for(kn=1;kn<fEventEnergy.GetSize();kn++) {
817 fEventEnergy[ndep]=kn;
822 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,kzero))/ed;
825 fSummEnergy[ndep]=ed;
826 fSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,kzero));
831 for(kn=0;kn<(ndep-1)/3+1;kn++) {
833 for(i=0;i<(3<left?3:left);i++) {
835 id=Int_t (fEventEnergy[j]+0.1);
836 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]);
841 // Relative energy loss in different detectors
842 printf("******************** Relative Energy Loss per event ********************\n");
843 printf("Total energy loss per event %10.3f GeV\n",edtot);
844 for(kn=0;kn<(ndep-1)/5+1;kn++) {
846 for(i=0;i<(5<left?5:left);i++) {
848 id=Int_t (fEventEnergy[j]+0.1);
849 printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot);
853 for(kn=0;kn<75;kn++) printf("*");
857 // Reset the TArray's
858 // fEventEnergy.Set(0);
859 // fSummEnergy.Set(0);
860 // fSum2Energy.Set(0);
863 //_____________________________________________________________________________
864 AliModule *AliRun::GetModule(const char *name) const
867 // Return pointer to detector from name
869 return (AliModule*)fModules->FindObject(name);
872 //_____________________________________________________________________________
873 AliDetector *AliRun::GetDetector(const char *name) const
876 // Return pointer to detector from name
878 return (AliDetector*)fModules->FindObject(name);
881 //_____________________________________________________________________________
882 Int_t AliRun::GetModuleID(const char *name) const
885 // Return galice internal detector identifier from name
888 TObject *mod=fModules->FindObject(name);
889 if(mod) i=fModules->IndexOf(mod);
893 //_____________________________________________________________________________
894 Int_t AliRun::GetEvent(Int_t event)
897 // Connect the Trees Kinematics and Hits for event # event
898 // Set branch addresses
901 // Reset existing structures
903 ResetTrackReferences();
907 // Delete Trees already connected
908 if (fTreeH) { delete fTreeH; fTreeH = 0;}
909 if (fTreeTR) { delete fTreeTR; fTreeTR = 0;}
910 if (fTreeD) { delete fTreeD; fTreeD = 0;}
911 if (fTreeR) { delete fTreeR; fTreeR = 0;}
912 if (fTreeS) { delete fTreeS; fTreeS = 0;}
914 // Create the particle stack
915 if (fHeader) delete fHeader;
918 // Get header from file
920 fTreeE->SetBranchAddress("Header", &fHeader);
922 if (!fTreeE->GetEntry(event)) {
923 Error("GetEvent","Cannot find event:%d\n",event);
928 Error("GetEvent","Cannot find Header Tree (TE)\n");
932 // Get the stack from the header, set fStack to 0 if it
933 // fails to get event
935 TFile *file = fTreeE->GetCurrentFile();
940 if (fStack) delete fStack;
941 fStack = fHeader->Stack();
943 if (!fStack->GetEvent(event)) fStack = 0;
946 // Get Hits Tree header from file
947 sprintf(treeName,"TreeH%d",event);
948 fTreeH = (TTree*)gDirectory->Get(treeName);
950 //Error("GetEvent","cannot find Hits Tree for event:%d\n",event);
951 Warning("GetEvent","cannot find Hits Tree for event:%d\n",event);
954 // Get TracReferences Tree header from file
955 sprintf(treeName,"TreeTR%d",event);
956 fTreeTR = (TTree*)gDirectory->Get(treeName);
958 //Error("GetEvent","cannot find TrackReferences Tree for event:%d\n",event);
959 Warning("GetEvent","cannot find TrackReferences Tree for event:%d\n",event);
962 // get current file name and compare with names containing trees S,D,R
963 TString curfilname=(TString)fTreeE->GetCurrentFile()->GetName();
964 if(fTreeDFileName==curfilname)fTreeDFileName="";
965 if(fTreeSFileName==curfilname)fTreeSFileName="";
966 if(fTreeRFileName==curfilname)fTreeRFileName="";
967 // Get Digits Tree header from file
968 sprintf(treeName,"TreeD%d",event);
970 if (!fTreeDFile && fTreeDFileName != "") {
971 InitTreeFile("D",fTreeDFileName);
974 fTreeD = (TTree*)fTreeDFile->Get(treeName);
976 fTreeD = (TTree*)file->Get(treeName);
979 // Warning("GetEvent","cannot find Digits Tree for event:%d\n",event);
981 if(fTreeDFileName != ""){
982 if(fTreeDFileName==fTreeSFileName) {
984 fTreeSFile = fTreeDFile;
986 if(fTreeDFileName==fTreeRFileName) {
988 fTreeRFile = fTreeDFile;
994 // Get SDigits Tree header from file
995 sprintf(treeName,"TreeS%d",event);
996 if (!fTreeSFile && fTreeSFileName != "") {
997 InitTreeFile("S",fTreeSFileName);
1000 fTreeS = (TTree*)fTreeSFile->Get(treeName);
1002 fTreeS = (TTree*)gDirectory->Get(treeName);
1005 // Warning("GetEvent","cannot find SDigits Tree for event:%d\n",event);
1008 if(fTreeSFileName != ""){
1009 if(fTreeSFileName==fTreeRFileName){
1010 fTreeRFileName = "";
1011 fTreeRFile = fTreeSFile;
1017 // Get Reconstruct Tree header from file
1018 sprintf(treeName,"TreeR%d",event);
1019 if (!fTreeRFile && fTreeRFileName != "") {
1020 InitTreeFile("R",fTreeRFileName);
1023 fTreeR = (TTree*)fTreeRFile->Get(treeName);
1025 fTreeR = (TTree*)gDirectory->Get(treeName);
1028 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
1033 // Set Trees branch addresses
1034 TIter next(fModules);
1035 AliModule *detector;
1036 while((detector = (AliModule*)next())) {
1037 detector->SetTreeAddress();
1040 fEvent=event; //MI change
1042 return fHeader->GetNtrack();
1045 //_____________________________________________________________________________
1046 TGeometry *AliRun::GetGeometry()
1049 // Import Alice geometry from current file
1050 // Return pointer to geometry object
1052 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
1054 // Unlink and relink nodes in detectors
1055 // This is bad and there must be a better way...
1058 TIter next(fModules);
1059 AliModule *detector;
1060 while((detector = (AliModule*)next())) {
1061 TList *dnodes=detector->Nodes();
1063 TNode *node, *node1;
1064 for ( j=0; j<dnodes->GetSize(); j++) {
1065 node = (TNode*) dnodes->At(j);
1066 node1 = fGeometry->GetNode(node->GetName());
1067 dnodes->Remove(node);
1068 dnodes->AddAt(node1,j);
1074 //_____________________________________________________________________________
1075 void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
1076 Float_t &e, Float_t *vpos, Float_t *polar,
1079 // Delegate to stack
1081 fStack->GetNextTrack(mtrack, ipart, pmom, e, vpos, polar, tof);
1084 //_____________________________________________________________________________
1085 Int_t AliRun::GetPrimary(Int_t track) const
1088 // return number of primary that has generated track
1090 return fStack->GetPrimary(track);
1093 //_____________________________________________________________________________
1094 void AliRun::InitMC(const char *setup)
1097 // Initialize the Alice setup
1101 Warning("Init","Cannot initialise AliRun twice!\n");
1105 gROOT->LoadMacro(setup);
1106 gInterpreter->ProcessLine(fConfigFunction.Data());
1109 gMC->DefineParticles(); //Create standard MC particles
1111 TObject *objfirst, *objlast;
1113 fNdets = fModules->GetLast()+1;
1116 //=================Create Materials and geometry
1119 // Added also after in case of interactive initialisation of modules
1120 fNdets = fModules->GetLast()+1;
1122 TIter next(fModules);
1123 AliModule *detector;
1124 while((detector = (AliModule*)next())) {
1125 detector->SetTreeAddress();
1126 objlast = gDirectory->GetList()->Last();
1128 // Add Detector histograms in Detector list of histograms
1129 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
1130 else objfirst = gDirectory->GetList()->First();
1132 detector->Histograms()->Add(objfirst);
1133 objfirst = gDirectory->GetList()->After(objfirst);
1136 ReadTransPar(); //Read the cuts for all materials
1138 MediaTable(); //Build the special IMEDIA table
1140 //Initialise geometry deposition table
1141 fEventEnergy.Set(gMC->NofVolumes()+1);
1142 fSummEnergy.Set(gMC->NofVolumes()+1);
1143 fSum2Energy.Set(gMC->NofVolumes()+1);
1145 //Compute cross-sections
1146 gMC->BuildPhysics();
1148 //Write Geometry object to current file.
1153 fMCQA = new AliMCQA(fNdets);
1155 // JCH note: the following line is useless, AliConfig instance is already
1156 // created in AliMC ctor. But it does not hurt.
1157 AliConfig::Instance();
1159 // Save stuff at the beginning of the file to avoid file corruption
1163 //_____________________________________________________________________________
1164 void AliRun::MediaTable()
1167 // Built media table to get from the media number to
1170 Int_t kz, nz, idt, lz, i, k, ind;
1172 TObjArray &dets = *gAlice->Detectors();
1175 // For all detectors
1176 for (kz=0;kz<fNdets;kz++) {
1177 // If detector is defined
1178 if((det=(AliModule*) dets[kz])) {
1179 TArrayI &idtmed = *(det->GetIdtmed());
1180 for(nz=0;nz<100;nz++) {
1181 // Find max and min material number
1182 if((idt=idtmed[nz])) {
1183 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
1184 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
1187 if(det->LoMedium() > det->HiMedium()) {
1188 det->LoMedium() = 0;
1189 det->HiMedium() = 0;
1191 if(det->HiMedium() > fImedia->GetSize()) {
1192 Error("MediaTable","Increase fImedia from %d to %d",
1193 fImedia->GetSize(),det->HiMedium());
1196 // Tag all materials in rage as belonging to detector kz
1197 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
1204 // Print summary table
1205 printf(" Traking media ranges:\n");
1206 for(i=0;i<(fNdets-1)/6+1;i++) {
1207 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
1209 det=(AliModule*)dets[ind];
1211 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
1214 printf(" %6s: %3d -> %3d;","NULL",0,0);
1220 //____________________________________________________________________________
1221 void AliRun::SetGenerator(AliGenerator *generator)
1224 // Load the event generator
1226 if(!fGenerator) fGenerator = generator;
1229 //____________________________________________________________________________
1230 void AliRun::ResetGenerator(AliGenerator *generator)
1233 // Load the event generator
1237 Warning("ResetGenerator","Replacing generator %s with %s\n",
1238 fGenerator->GetName(),generator->GetName());
1240 Warning("ResetGenerator","Replacing generator %s with NULL\n",
1241 fGenerator->GetName());
1242 fGenerator = generator;
1245 //____________________________________________________________________________
1246 void AliRun::SetTransPar(char *filename)
1248 fTransParName = filename;
1251 //____________________________________________________________________________
1252 void AliRun::SetBaseFile(char *filename)
1254 fBaseFileName = filename;
1257 //____________________________________________________________________________
1258 void AliRun::ReadTransPar()
1261 // Read filename to set the transport parameters
1265 const Int_t kncuts=10;
1266 const Int_t knflags=11;
1267 const Int_t knpars=kncuts+knflags;
1268 const char kpars[knpars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
1269 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
1270 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
1271 "MULS","PAIR","PHOT","RAYL"};
1275 Float_t cut[kncuts];
1276 Int_t flag[knflags];
1277 Int_t i, itmed, iret, ktmed, kz;
1280 // See whether the file is there
1281 filtmp=gSystem->ExpandPathName(fTransParName.Data());
1282 lun=fopen(filtmp,"r");
1285 Warning("ReadTransPar","File %s does not exist!\n",fTransParName.Data());
1290 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1291 printf(" *%59s\n","*");
1292 printf(" * Please check carefully what you are doing!%10s\n","*");
1293 printf(" *%59s\n","*");
1297 // Initialise cuts and flags
1298 for(i=0;i<kncuts;i++) cut[i]=-99;
1299 for(i=0;i<knflags;i++) flag[i]=-99;
1301 for(i=0;i<256;i++) line[i]='\0';
1302 // Read up to the end of line excluded
1303 iret=fscanf(lun,"%[^\n]",line);
1308 printf(" *%59s\n","*");
1309 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1313 // Read the end of line
1316 if(line[0]=='*') continue;
1318 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",
1319 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
1320 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
1321 &flag[8],&flag[9],&flag[10]);
1325 Warning("ReadTransPar","Error reading file %s\n",fTransParName.Data());
1328 // Check that the module exist
1329 AliModule *mod = GetModule(detName);
1331 // Get the array of media numbers
1332 TArrayI &idtmed = *mod->GetIdtmed();
1333 // Check that the tracking medium code is valid
1334 if(0<=itmed && itmed < 100) {
1335 ktmed=idtmed[itmed];
1337 Warning("ReadTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
1340 // Set energy thresholds
1341 for(kz=0;kz<kncuts;kz++) {
1343 if(fDebug) printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
1344 kpars[kz],cut[kz],itmed,mod->GetName());
1345 gMC->Gstpar(ktmed,kpars[kz],cut[kz]);
1348 // Set transport mechanisms
1349 for(kz=0;kz<knflags;kz++) {
1351 if(fDebug) printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
1352 kpars[kncuts+kz],flag[kz],itmed,mod->GetName());
1353 gMC->Gstpar(ktmed,kpars[kncuts+kz],Float_t(flag[kz]));
1357 Warning("ReadTransPar","Invalid medium code %d *\n",itmed);
1361 if(fDebug) printf("%s::ReadTransParModule: %s not present\n",ClassName(),detName);
1368 //_____________________________________________________________________________
1369 void AliRun::MakeTree(Option_t *option, const char *file)
1372 // Create the ROOT trees
1373 // Loop on all detectors to create the Root branch (if any)
1379 const char *oK = strstr(option,"K");
1380 const char *oH = strstr(option,"H");
1381 const char *oTR = strstr(option,"T");
1382 const char *oE = strstr(option,"E");
1383 const char *oD = strstr(option,"D");
1384 const char *oR = strstr(option,"R");
1385 const char *oS = strstr(option,"S");
1388 TDirectory *cwd = gDirectory;
1390 TBranch *branch = 0;
1392 if (oK) fStack->MakeTree(fEvent, file);
1394 if (oE && !fTreeE) {
1395 fTreeE = new TTree("TE","Header");
1396 // branch = fTreeE->Branch("Header", "AliHeader", &fHeader, 4000, 0);
1397 branch = fTreeE->Branch("Header", "AliHeader", &fHeader, 4000, 0);
1398 branch->SetAutoDelete(kFALSE);
1399 TFolder *folder = (TFolder *)gROOT->FindObjectAny("/Folders/RunMC/Event/Header");
1400 if (folder) folder->Add(fHeader);
1401 // branch = fTreeE->Branch("Stack","AliStack", &fStack, 4000, 0);
1402 // branch->SetAutoDelete(kFALSE);
1403 // if (folder) folder->Add(fStack);
1404 fTreeE->Write(0,TObject::kOverwrite);
1407 if (file && branch) {
1408 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
1409 sprintf(outFile,"%s/%s",GetBaseFile(),file);
1410 branch->SetFile(outFile);
1411 TIter next( branch->GetListOfBranches());
1412 while ((branch=(TBranch*)next())) {
1413 branch->SetFile(outFile);
1416 printf("* MakeBranch * Diverting Branch %s to file %s\n", branch->GetName(),file);
1421 if (oH && !fTreeH) {
1422 sprintf(hname,"TreeH%d",fEvent);
1423 fTreeH = new TTree(hname,"Hits");
1424 fTreeH->SetAutoSave(1000000000); //no autosave
1425 fTreeH->Write(0,TObject::kOverwrite);
1428 if (oTR && !fTreeTR) {
1429 sprintf(hname,"TreeTR%d",fEvent);
1430 fTreeTR = new TTree(hname,"TrackReferences");
1431 fTreeTR->SetAutoSave(1000000000); //no autosave
1432 fTreeTR->Write(0,TObject::kOverwrite);
1435 if (oD && !fTreeD) {
1436 sprintf(hname,"TreeD%d",fEvent);
1437 fTreeD = new TTree(hname,"Digits");
1438 fTreeD->Write(0,TObject::kOverwrite);
1440 if (oS && !fTreeS) {
1441 sprintf(hname,"TreeS%d",fEvent);
1442 fTreeS = new TTree(hname,"SDigits");
1443 fTreeS->Write(0,TObject::kOverwrite);
1445 if (oR && !fTreeR) {
1446 sprintf(hname,"TreeR%d",fEvent);
1447 fTreeR = new TTree(hname,"Reconstruction");
1448 fTreeR->Write(0,TObject::kOverwrite);
1452 // Create a branch for hits/digits for each detector
1453 // Each branch is a TClonesArray. Each data member of the Hits classes
1454 // will be in turn a subbranch of the detector master branch
1455 TIter next(fModules);
1456 AliModule *detector;
1457 while((detector = (AliModule*)next())) {
1458 if (oH) detector->MakeBranch(option,file);
1459 if (oTR) detector->MakeBranchTR(option,file);
1465 //_____________________________________________________________________________
1466 TParticle* AliRun::Particle(Int_t i)
1468 return fStack->Particle(i);
1471 //_____________________________________________________________________________
1472 void AliRun::BeginEvent()
1474 // Clean-up previous event
1476 fEventEnergy.Reset();
1477 // Clean detector information
1484 // Reset all Detectors & kinematics & trees
1488 // Initialise event header
1489 fHeader->Reset(fRun,fEvent,fEventNrInRun);
1491 fStack->BeginEvent(fEvent);
1495 fLego->BeginEvent();
1502 ResetTrackReferences();
1509 sprintf(hname,"TreeH%d",fEvent);
1510 fTreeH->SetName(hname);
1515 sprintf(hname,"TreeTR%d",fEvent);
1516 fTreeTR->SetName(hname);
1521 sprintf(hname,"TreeD%d",fEvent);
1522 fTreeD->SetName(hname);
1523 fTreeD->Write(0,TObject::kOverwrite);
1527 sprintf(hname,"TreeS%d",fEvent);
1528 fTreeS->SetName(hname);
1529 fTreeS->Write(0,TObject::kOverwrite);
1533 sprintf(hname,"TreeR%d",fEvent);
1534 fTreeR->SetName(hname);
1535 fTreeR->Write(0,TObject::kOverwrite);
1538 //_____________________________________________________________________________
1539 void AliRun::ResetDigits()
1542 // Reset all Detectors digits
1544 TIter next(fModules);
1545 AliModule *detector;
1546 while((detector = (AliModule*)next())) {
1547 detector->ResetDigits();
1551 //_____________________________________________________________________________
1552 void AliRun::ResetSDigits()
1555 // Reset all Detectors digits
1557 TIter next(fModules);
1558 AliModule *detector;
1559 while((detector = (AliModule*)next())) {
1560 detector->ResetSDigits();
1564 //_____________________________________________________________________________
1565 void AliRun::ResetHits()
1568 // Reset all Detectors hits
1570 TIter next(fModules);
1571 AliModule *detector;
1572 while((detector = (AliModule*)next())) {
1573 detector->ResetHits();
1577 //_____________________________________________________________________________
1578 void AliRun::ResetTrackReferences()
1581 // Reset all Detectors hits
1583 TIter next(fModules);
1584 AliModule *detector;
1585 while((detector = (AliModule*)next())) {
1586 detector->ResetTrackReferences();
1592 //_____________________________________________________________________________
1593 void AliRun::ResetPoints()
1596 // Reset all Detectors points
1598 TIter next(fModules);
1599 AliModule *detector;
1600 while((detector = (AliModule*)next())) {
1601 detector->ResetPoints();
1605 //_____________________________________________________________________________
1606 void AliRun::RunMC(Int_t nevent, const char *setup)
1609 // Main function to be called to process a galice run
1611 // Root > gAlice.Run();
1612 // a positive number of events will cause the finish routine
1615 fEventsPerRun = nevent;
1616 // check if initialisation has been done
1617 if (!fInitDone) InitMC(setup);
1619 // Create the Root Tree with one branch per detector
1621 MakeTree("ESDRT"); // MI change
1623 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1624 MakeTree("K","Kine.root");
1625 MakeTree("H","Hits.root");
1630 gMC->ProcessRun(nevent);
1632 // End of this run, close files
1633 if(nevent>0) FinishRun();
1636 //_____________________________________________________________________________
1637 void AliRun::RunReco(const char *selected, Int_t first, Int_t last)
1640 // Main function to be called to reconstruct Alice event
1642 cout << "Found "<< gAlice->TreeE()->GetEntries() << "events" << endl;
1643 Int_t nFirst = first;
1644 Int_t nLast = (last < 0)? (Int_t) gAlice->TreeE()->GetEntries() : last;
1646 for (Int_t nevent = nFirst; nevent <= nLast; nevent++) {
1647 cout << "Processing event "<< nevent << endl;
1650 Digits2Reco(selected);
1654 //_____________________________________________________________________________
1656 void AliRun::Hits2Digits(const char *selected)
1659 // Convert Hits to sumable digits
1661 for (Int_t nevent=0; nevent<gAlice->TreeE()->GetEntries(); nevent++) {
1664 Hits2SDigits(selected);
1665 SDigits2Digits(selected);
1670 //_____________________________________________________________________________
1672 void AliRun::Tree2Tree(Option_t *option, const char *selected)
1675 // Function to transform the content of
1677 // - TreeH to TreeS (option "S")
1678 // - TreeS to TreeD (option "D")
1679 // - TreeD to TreeR (option "R")
1681 // If multiple options are specified ("SDR"), transformation will be done in sequence for
1682 // selected detector and for all detectors if none is selected (detector string
1683 // can contain blank separated list of detector names).
1686 const char *oS = strstr(option,"S");
1687 const char *oD = strstr(option,"D");
1688 const char *oR = strstr(option,"R");
1690 TObjArray *detectors = Detectors();
1692 TIter next(detectors);
1694 AliDetector *detector = 0;
1696 TDirectory *cwd = gDirectory;
1700 while((detector = (AliDetector*)next())) {
1702 if (strcmp(detector->GetName(),selected)) continue;
1703 if (detector->IsActive()){
1704 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1706 sprintf(outFile,"SDigits.%s.root",detector->GetName());
1707 detector->MakeBranch("S",outFile);
1710 sprintf(outFile,"Digits.%s.root",detector->GetName());
1711 detector->MakeBranch("D",outFile);
1714 sprintf(outFile,"Reco.%s.root",detector->GetName());
1715 detector->MakeBranch("R",outFile);
1718 detector->MakeBranch(option);
1724 cout << "Hits2SDigits: Processing " << detector->GetName() << "..." << endl;
1725 detector->Hits2SDigits();
1728 cout << "SDigits2Digits: Processing " << detector->GetName() << "..." << endl;
1729 detector->SDigits2Digits();
1732 cout << "Digits2Reco: Processing " << detector->GetName() << "..." << endl;
1733 detector->Digits2Reco();
1742 //_____________________________________________________________________________
1743 void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min,
1744 Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max,
1745 Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener)
1748 // Generates lego plots of:
1749 // - radiation length map phi vs theta
1750 // - radiation length map phi vs eta
1751 // - interaction length map
1752 // - g/cm2 length map
1754 // ntheta bins in theta, eta
1755 // themin minimum angle in theta (degrees)
1756 // themax maximum angle in theta (degrees)
1758 // phimin minimum angle in phi (degrees)
1759 // phimax maximum angle in phi (degrees)
1760 // rmin minimum radius
1761 // rmax maximum radius
1764 // The number of events generated = ntheta*nphi
1765 // run input parameters in macro setup (default="Config.C")
1767 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1770 <img src="picts/AliRunLego1.gif">
1775 <img src="picts/AliRunLego2.gif">
1780 <img src="picts/AliRunLego3.gif">
1785 // check if initialisation has been done
1786 if (!fInitDone) InitMC(setup);
1787 //Save current generator
1788 AliGenerator *gen=Generator();
1790 // Set new generator
1791 if (!gener) gener = new AliLegoGenerator();
1792 ResetGenerator(gener);
1794 // Configure Generator
1795 gener->SetRadiusRange(rmin, rmax);
1796 gener->SetZMax(zmax);
1797 gener->SetCoor1Range(nc1, c1min, c1max);
1798 gener->SetCoor2Range(nc2, c2min, c2max);
1801 //Create Lego object
1802 fLego = new AliLego("lego",gener);
1804 //Prepare MC for Lego Run
1809 gMC->ProcessRun(nc1*nc2+1);
1811 // Create only the Root event Tree
1814 // End of this run, close files
1816 // Restore current generator
1817 ResetGenerator(gen);
1818 // Delete Lego Object
1819 delete fLego; fLego=0;
1822 //_____________________________________________________________________________
1823 void AliRun::SetConfigFunction(const char * config)
1826 // Set the signature of the function contained in Config.C to configure
1829 fConfigFunction=config;
1832 //_____________________________________________________________________________
1833 void AliRun::SetCurrentTrack(Int_t track)
1836 // Set current track number
1838 fStack->SetCurrentTrack(track);
1841 //_____________________________________________________________________________
1842 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1843 Float_t *vpos, Float_t *polar, Float_t tof,
1844 AliMCProcess mech, Int_t &ntr, Float_t weight, Int_t is)
1846 // Delegate to stack
1848 fStack->SetTrack(done, parent, pdg, pmom, vpos, polar, tof,
1849 mech, ntr, weight, is);
1852 //_____________________________________________________________________________
1853 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg,
1854 Double_t px, Double_t py, Double_t pz, Double_t e,
1855 Double_t vx, Double_t vy, Double_t vz, Double_t tof,
1856 Double_t polx, Double_t poly, Double_t polz,
1857 AliMCProcess mech, Int_t &ntr, Float_t weight, Int_t is)
1859 // Delegate to stack
1861 fStack->SetTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
1862 polx, poly, polz, mech, ntr, weight, is);
1866 //_____________________________________________________________________________
1867 void AliRun::SetHighWaterMark(const Int_t nt)
1870 // Set high water mark for last track in event
1871 fStack->SetHighWaterMark(nt);
1874 //_____________________________________________________________________________
1875 void AliRun::KeepTrack(const Int_t track)
1878 // Delegate to stack
1880 fStack->KeepTrack(track);
1883 //_____________________________________________________________________________
1884 void AliRun::StepManager(Int_t id)
1887 // Called at every step during transport
1891 // --- If lego option, do it and leave
1893 fLego->StepManager();
1896 //Update energy deposition tables
1897 AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
1899 //Call the appropriate stepping routine;
1900 AliModule *det = (AliModule*)fModules->At(id);
1901 if(det && det->StepManagerIsEnabled()) {
1902 fMCQA->StepManager(id);
1908 //_____________________________________________________________________________
1909 void AliRun::Streamer(TBuffer &R__b)
1911 // Stream an object of class AliRun.
1913 if (R__b.IsReading()) {
1914 if (!gAlice) gAlice = this;
1916 AliRun::Class()->ReadBuffer(R__b, this);
1918 gROOT->GetListOfBrowsables()->Add(this,"Run");
1920 fTreeE = (TTree*)gDirectory->Get("TE");
1922 fTreeE->SetBranchAddress("Header", &fHeader);
1925 else Error("Streamer","cannot find Header Tree\n");
1926 fTreeE->GetEntry(0);
1930 AliRun::Class()->WriteBuffer(R__b, this);
1935 //___________________________________________________________________________
1936 Int_t AliRun::CurrentTrack() const {
1938 // Returns current track
1940 return fStack->CurrentTrack();
1943 //___________________________________________________________________________
1944 Int_t AliRun::GetNtrack() const {
1946 // Returns number of tracks in stack
1948 return fStack->GetNtrack();
1951 //___________________________________________________________________________
1952 TObjArray* AliRun::Particles() {
1954 // Returns pointer to Particles array
1956 return fStack->Particles();
1959 //___________________________________________________________________________
1960 TTree* AliRun::TreeK() {
1962 // Returns pointer to the TreeK array
1964 return fStack->TreeK();
1967 ////////////////////////////////////////////////////////////////////////
1968 void AliRun::SetGenEventHeader(AliGenEventHeader* header)
1970 fHeader->SetGenEventHeader(header);
1972 ////////////////////////////////////////////////////////////////////////
1973 TFile* AliRun::InitFile(TString fileName)
1976 // create the file where the whole tree will be saved
1978 TDirectory *wd = gDirectory;
1979 TFile* file = TFile::Open(fileName,"update");
1981 if (!file->IsOpen()) {
1982 Error("Cannot open file, %s\n",fileName);
1988 ////////////////////////////////////////////////////////////////////////
1989 TFile* AliRun::InitTreeFile(Option_t *option, TString fileName)
1992 // create the file where one of the following trees will be saved
1994 // WARNING: by default these trees are saved on the file on which
1995 // hits are stored. If you divert one of these trees, you cannot restore
1996 // it to the original file (usually galice.root) in the same aliroot session
1997 Bool_t oS = (strstr(option,"S")!=0);
1998 Bool_t oR = (strstr(option,"R")!=0);
1999 Bool_t oD = (strstr(option,"D")!=0);
2001 for (Int_t i=0; i<3; i++) choice[i] = 0;
2002 if(oS)choice[0] = 1;
2003 if(oD)choice[1] = 1;
2004 if(oR)choice[2] = 1;
2008 if(!(oS || oR || oD))return ptr;
2011 for (Int_t i=0; i<3; i++) active[i] = 0;
2012 if(fTreeSFileName != "") active[0] = 1;
2013 if(fTreeDFileName != "") active[1] = 1;
2014 if(fTreeDFileName != "") active[2] = 1;
2016 Bool_t alreadyopen1 = kFALSE;
2017 Bool_t alreadyopen2 = kFALSE;
2020 // if already active and same name with non-null ptr
2021 if(active[0]==1 && fileName == fTreeSFileName && fTreeSFile){
2022 Warning("InitTreeFile","File %s already opened",fTreeSFileName.Data());
2026 // if already active with different name with non-null ptr
2027 if(active[0]==1 && fileName != fTreeSFileName && fTreeSFile){
2028 // close the active files and also the other possible files in option
2029 CloseTreeFile(option);
2031 fTreeSFileName = fileName;
2033 (active[1] == 1 && fTreeDFileName == fTreeSFileName && fTreeDFile);
2035 (active[2] == 1 && fTreeRFileName == fTreeSFileName && fTreeRFile);
2036 if(!(alreadyopen1 || alreadyopen2)){
2037 ptr = InitFile(fileName);
2041 if(alreadyopen1){fTreeSFile = fTreeDFile; ptr = fTreeSFile;}
2042 if(alreadyopen2){fTreeSFile = fTreeRFile; ptr = fTreeSFile;}
2044 if(choice[1] == 1) { fTreeDFileName = fileName; fTreeDFile = ptr;}
2045 if(choice[2] == 1) { fTreeRFileName = fileName; fTreeRFile = ptr;}
2051 // if already active and same name with non-null ptr
2052 if(active[1]==1 && fileName == fTreeDFileName && fTreeDFile){
2053 Warning("InitTreeFile","File %s already opened",fTreeDFileName.Data());
2057 // if already active with different name with non-null ptr
2058 if(active[1]==1 && fileName != fTreeDFileName && fTreeDFile){
2059 // close the active files and also the other possible files in option
2060 CloseTreeFile(option);
2062 fTreeDFileName = fileName;
2064 (active[0] == 1 && fTreeSFileName == fTreeDFileName && fTreeSFile);
2066 (active[2] == 1 && fTreeRFileName == fTreeDFileName && fTreeRFile);
2067 if(!(alreadyopen1 || alreadyopen2)){
2068 ptr = InitFile(fileName);
2072 if(alreadyopen1){fTreeDFile = fTreeSFile; ptr = fTreeDFile;}
2073 if(alreadyopen2){fTreeDFile = fTreeRFile; ptr = fTreeDFile;}
2075 if(choice[2] == 1) { fTreeRFileName = fileName; fTreeRFile = ptr;}
2081 // if already active and same name with non-null ptr
2082 if(active[2]==1 && fileName == fTreeRFileName && fTreeRFile){
2083 Warning("InitTreeFile","File %s already opened",fTreeRFileName.Data());
2087 // if already active with different name with non-null ptr
2088 if(active[2]==1 && fileName != fTreeRFileName && fTreeRFile){
2089 // close the active files and also the other possible files in option
2090 CloseTreeFile(option);
2092 fTreeRFileName = fileName;
2094 (active[1] == 1 && fTreeDFileName == fTreeRFileName && fTreeDFile);
2096 (active[0]== 1 && fTreeSFileName == fTreeRFileName && fTreeSFile);
2097 if(!(alreadyopen1 || alreadyopen2)){
2098 ptr = InitFile(fileName);
2102 if(alreadyopen1){fTreeRFile = fTreeDFile; ptr = fTreeRFile;}
2103 if(alreadyopen2){fTreeRFile = fTreeSFile; ptr = fTreeRFile;}
2110 ////////////////////////////////////////////////////////////////////////
2111 void AliRun::CloseTreeFile(Option_t *option)
2114 // closes the file containing the tree specified in option
2117 Bool_t oS = (strstr(option,"S")!=0);
2118 Bool_t oR = (strstr(option,"R")!=0);
2119 Bool_t oD = (strstr(option,"D")!=0);
2120 Bool_t none = !(oS || oR || oD);
2123 fTreeSFileName = "";
2125 if(!((fTreeSFile == fTreeDFile) || (fTreeSFile == fTreeRFile)) &&
2126 fTreeSFile->IsOpen()){
2127 fTreeSFile->Close();
2134 fTreeDFileName = "";
2136 if(!((fTreeDFile == fTreeRFile) || (fTreeDFile == fTreeSFile)) &&
2137 fTreeDFile->IsOpen()){
2138 fTreeDFile->Close();
2145 fTreeRFileName = "";
2147 if(!((fTreeRFile == fTreeSFile) || (fTreeRFile == fTreeDFile)) &&
2148 fTreeRFile->IsOpen()){
2149 fTreeRFile->Close();
2157 ////////////////////////////////////////////////////////////////////////
2158 void AliRun::PrintTreeFile()
2161 // prints the file names and pointer associated to S,D,R trees
2163 cout<<"===================================================\n";
2164 TFile *file = fTreeE->GetCurrentFile();
2165 TString curfilname="";
2166 if(file)curfilname=(TString)file->GetName();
2167 cout<<" Current tree file name: "<<curfilname<<endl;
2168 cout<<"Pointer: "<<file<<endl;
2169 cout<<" Tree S File name: "<<fTreeSFileName<<endl;
2170 cout<<"Pointer: "<<fTreeSFile<<endl<<endl;
2171 cout<<" Tree D File name: "<<fTreeDFileName<<endl;
2172 cout<<"Pointer: "<<fTreeDFile<<endl<<endl;
2173 cout<<" Tree R File name: "<<fTreeRFileName<<endl;
2174 cout<<"Pointer: "<<fTreeRFile<<endl<<endl;
2175 cout<<"===================================================\n";
2177 ////////////////////////////////////////////////////////////////////////
2178 void AliRun::MakeTree(Option_t *option, TFile *file)
2181 // Create some trees in the separate file
2183 const char *oD = strstr(option,"D");
2184 const char *oR = strstr(option,"R");
2185 const char *oS = strstr(option,"S");
2187 TDirectory *cwd = gDirectory;
2192 sprintf(hname,"TreeD%d",fEvent);
2194 fTreeD = static_cast<TTree*>(file->Get("hname"));
2196 fTreeD = new TTree(hname,"Digits");
2197 fTreeD->Write(0,TObject::kOverwrite);
2203 sprintf(hname,"TreeS%d",fEvent);
2205 fTreeS = static_cast<TTree*>(file->Get("hname"));
2207 fTreeS = new TTree(hname,"SDigits");
2208 fTreeS->Write(0,TObject::kOverwrite);
2215 sprintf(hname,"TreeR%d",fEvent);
2217 fTreeR = static_cast<TTree*>(file->Get("hname"));
2219 fTreeR = new TTree(hname,"RecPoint");
2220 fTreeR->Write(0,TObject::kOverwrite);
2225 ////////////////////////////////////////////////////////////////////////