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.82.4.3 2002/10/14 09:45:57 hristov
19 Updating VirtualMC to v3-09-02
21 Revision 1.82.4.2 2002/06/10 17:54:06 hristov
22 Only one SetGenEventHeader function kept
24 Revision 1.82.4.1 2002/06/10 14:43:06 hristov
27 Revision 1.86 2002/05/28 14:24:57 hristov
28 Correct warning messages
30 Revision 1.85 2002/05/24 13:29:58 hristov
31 AliTrackReference added, AliDisplay modified
33 Revision 1.84 2002/05/21 16:26:07 hristov
34 Find correctly TreeK in case CONFIG_SPLIT_FILE is set (Y.Schutz)
36 Revision 1.83 2002/04/04 13:16:17 jchudoba
37 add possibility to write sdigits, digits and rec. points into separate files
39 Revision 1.82 2002/03/12 11:06:03 morsch
40 Add particle status code to argument list of SetTrack(..).
42 Revision 1.81 2001/12/19 14:46:26 morsch
43 Add possibility to disable StepManager() for each module separately.
45 Revision 1.80 2001/10/21 18:22:55 hristov
46 BranchOld replaced by Branch. It works correctly with Root 2.02.xx
48 Revision 1.79 2001/10/09 18:00:35 hristov
49 Temporary fix to provide unique event number in the simulation (J.Chudoba)
51 Revision 1.78 2001/10/04 15:30:56 hristov
52 Changes to accommodate the set of PHOS folders and tasks (Y.Schutz)
54 Revision 1.77 2001/09/04 15:09:11 hristov
55 fTreeE->Branch replaced temporary by fTreeE->BranchOld to avoid data corruption in case of many events per file
57 Revision 1.76 2001/08/03 14:38:35 morsch
58 Use original method to access TreeH.
60 Revision 1.75 2001/07/28 10:52:27 hristov
61 Event number updated correctly (M.Ivanov)
63 Revision 1.74 2001/07/28 10:39:16 morsch
64 GetEventsPerRun() method needed by afterburners added to AliRun.h
65 Corresponding setters and getters have been from AliGenerator.
67 Revision 1.73 2001/07/27 12:34:30 jchudoba
68 remove the dummy argument in fStack->GetEvent call
70 Revision 1.72 2001/07/03 08:10:57 hristov
71 J.Chudoba's changes merged correctly with the HEAD
73 Revision 1.70 2001/06/29 08:01:36 morsch
74 Small correction to the previous.
76 Revision 1.69 2001/06/28 16:27:50 morsch
77 AliReco() with user control of event range.
79 Revision 1.68 2001/06/11 13:14:40 morsch
80 SetAliGenEventHeader() method added.
82 Revision 1.67 2001/06/07 18:24:50 buncic
83 Removed compilation warning in AliConfig initialisation.
85 Revision 1.66 2001/05/22 14:32:40 hristov
88 Revision 1.65 2001/05/21 17:22:51 buncic
89 Fixed problem with missing AliConfig while reading galice.root
91 Revision 1.64 2001/05/16 14:57:22 alibrary
92 New files for folders and Stack
94 Revision 1.62 2001/04/06 11:12:33 morsch
95 Clear fParticles after each event. (Ivana Hrivnacova)
97 Revision 1.61 2001/03/30 07:04:10 morsch
98 Call fGenerator->FinishRun() for final print-outs, cross-section and weight calculations.
100 Revision 1.60 2001/03/21 18:22:30 hristov
101 fParticleFileMap fix (I.Hrivnacova)
103 Revision 1.59 2001/03/12 17:47:03 hristov
104 Changes needed on Sun with CC 5.0
106 Revision 1.58 2001/03/09 14:27:26 morsch
107 Fix for multiple events per file: inhibit decrease of size of fParticleFileMap.
109 Revision 1.57 2001/02/23 17:40:23 buncic
110 All trees needed for simulation created in RunMC(). TreeR and its branches
111 are now created in new RunReco() method.
113 Revision 1.56 2001/02/14 15:45:20 hristov
114 Algorithmic way of getting entry index in fParticleMap. Protection of fParticleFileMap (I.Hrivnacova)
116 Revision 1.55 2001/02/12 15:52:54 buncic
117 Removed OpenBaseFile().
119 Revision 1.54 2001/02/07 10:39:05 hristov
120 Remove default value for argument
122 Revision 1.53 2001/02/06 11:02:26 hristov
123 New SetTrack interface added, added check for unfilled particles in FinishEvent (I.Hrivnacova)
125 Revision 1.52 2001/02/05 16:22:25 buncic
126 Added TreeS to GetEvent().
128 Revision 1.51 2001/02/02 15:16:20 morsch
129 SetHighWaterMark method added to mark last particle in event.
131 Revision 1.50 2001/01/27 10:32:00 hristov
132 Leave the loop when primaries are filled (I.Hrivnacova)
134 Revision 1.49 2001/01/26 19:58:48 hristov
135 Major upgrade of AliRoot code
137 Revision 1.48 2001/01/17 10:50:50 hristov
138 Corrections to destructors
140 Revision 1.47 2000/12/18 10:44:01 morsch
141 Possibility to set field map by passing pointer to objet of type AliMagF via
144 gAlice->SetField(new AliMagFCM("Map2", "$(ALICE_ROOT)/data/field01.dat",2,1.,10.));
146 Revision 1.46 2000/12/14 19:29:27 fca
147 galice.cuts was not read any more
149 Revision 1.45 2000/11/30 07:12:49 alibrary
150 Introducing new Rndm and QA classes
152 Revision 1.44 2000/10/26 13:58:59 morsch
153 Add possibility to choose the lego generator (of type AliGeneratorLego or derived) when running
154 RunLego(). Default is the base class AliGeneratorLego.
156 Revision 1.43 2000/10/09 09:43:17 fca
157 Special remapping of hits for TPC and TRD. End-of-primary action introduced
159 Revision 1.42 2000/10/02 21:28:14 fca
160 Removal of useless dependecies via forward declarations
162 Revision 1.41 2000/07/13 16:19:09 fca
163 Mainly coding conventions + some small bug fixes
165 Revision 1.40 2000/07/12 08:56:25 fca
166 Coding convention correction and warning removal
168 Revision 1.39 2000/07/11 18:24:59 fca
169 Coding convention corrections + few minor bug fixes
171 Revision 1.38 2000/06/20 13:05:45 fca
172 Writing down the TREE headers before job starts
174 Revision 1.37 2000/06/09 20:05:11 morsch
175 Introduce possibility to chose magnetic field version 3: AliMagFDM + field02.dat
177 Revision 1.36 2000/06/08 14:03:58 hristov
178 Only one initializer for a default argument
180 Revision 1.35 2000/06/07 10:13:14 hristov
181 Delete only existent objects.
183 Revision 1.34 2000/05/18 10:45:38 fca
184 Delete Particle Factory properly
186 Revision 1.33 2000/05/16 13:10:40 fca
187 New method IsNewTrack and fix for a problem in Father-Daughter relations
189 Revision 1.32 2000/04/27 10:38:21 fca
190 Correct termination of Lego Run and introduce Lego getter in AliRun
192 Revision 1.31 2000/04/26 10:17:32 fca
193 Changes in Lego for G4 compatibility
195 Revision 1.30 2000/04/18 19:11:40 fca
196 Introduce variable Config.C function signature
198 Revision 1.29 2000/04/07 11:12:34 fca
199 G4 compatibility changes
201 Revision 1.28 2000/04/05 06:51:06 fca
202 Workaround for an HP compiler problem
204 Revision 1.27 2000/03/22 18:08:07 fca
205 Rationalisation of the virtual MC interfaces
207 Revision 1.26 2000/03/22 13:42:26 fca
208 SetGenerator does not replace an existing generator, ResetGenerator does
210 Revision 1.25 2000/02/23 16:25:22 fca
211 AliVMC and AliGeant3 classes introduced
212 ReadEuclid moved from AliRun to AliModule
214 Revision 1.24 2000/01/19 17:17:20 fca
215 Introducing a list of lists of hits -- more hits allowed for detector now
217 Revision 1.23 1999/12/03 11:14:31 fca
218 Fixing previous wrong checking
220 Revision 1.21 1999/11/25 10:40:08 fca
221 Fixing daughters information also in primary tracks
223 Revision 1.20 1999/10/04 18:08:49 fca
224 Adding protection against inconsistent Euclid files
226 Revision 1.19 1999/09/29 07:50:40 fca
227 Introduction of the Copyright and cvs Log
231 ///////////////////////////////////////////////////////////////////////////////
233 // Control class for Alice C++ //
234 // Only one single instance of this class exists. //
235 // The object is created in main program aliroot //
236 // and is pointed by the global gAlice. //
238 // -Supports the list of all Alice Detectors (fModules). //
239 // -Supports the list of particles (fParticles). //
240 // -Supports the Trees. //
241 // -Supports the geometry. //
242 // -Supports the event display. //
245 <img src="picts/AliRunClass.gif">
250 <img src="picts/alirun.gif">
254 ///////////////////////////////////////////////////////////////////////////////
259 #include <iostream.h>
266 #include <TObjectTable.h>
268 #include <TGeometry.h>
270 #include <TBrowser.h>
274 #include "TParticle.h"
276 #include "AliDisplay.h"
279 #include "AliMagFC.h"
280 #include "AliMagFCM.h"
281 #include "AliMagFDM.h"
283 #include "TRandom3.h"
285 #include "AliGenerator.h"
286 #include "AliLegoGenerator.h"
287 #include "AliConfig.h"
288 #include "AliStack.h"
289 #include "AliGenEventHeader.h"
290 #include "AliHeader.h"
292 #include "AliDetector.h"
298 //_____________________________________________________________________________
300 : TVirtualMCApplication()
303 // Default constructor for AliRun
328 fPDGDB = 0; //Particle factory object!
330 fConfigFunction = "\0";
333 fTransParName = "\0";
334 fBaseFileName = ".\0";
344 //_____________________________________________________________________________
345 AliRun::AliRun(const char *name, const char *title)
346 : TVirtualMCApplication(name,title)
349 // Constructor for the main processor.
350 // Creates the geometry
351 // Creates the list of Detectors.
352 // Creates the list of particles.
369 fConfigFunction = "Config();";
377 // Set random number generator
378 gRandom = fRandom = new TRandom3();
380 if (gSystem->Getenv("CONFIG_SEED")) {
381 gRandom->SetSeed((UInt_t)atoi(gSystem->Getenv("CONFIG_SEED")));
384 gROOT->GetListOfBrowsables()->Add(this,name);
387 fStack = new AliStack(10000);
388 // create the support list for the various Detectors
389 fModules = new TObjArray(77);
391 // Create the TNode geometry for the event display
393 BuildSimpleGeometry();
395 fHeader = new AliHeader();
402 // Create default mag field
407 // Prepare the tracking medium lists
408 fImedia = new TArrayI(1000);
409 for(i=0;i<1000;i++) (*fImedia)[i]=-99;
412 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
414 AliConfig::Instance()->Add(fPDGDB);
416 // Create HitLists list
417 fHitLists = new TList();
420 fBaseFileName = ".\0";
426 //_____________________________________________________________________________
430 // Default AliRun destructor
433 if(fTreeE)curfil=fTreeE->GetCurrentFile();
456 // avoid to delete TFile objects not owned by this object
457 // avoid multiple deletions
458 if(curfil == fTreeDFile) fTreeDFile=0;
459 if(curfil == fTreeSFile) fTreeSFile=0;
460 if(curfil == fTreeRFile) fTreeRFile=0;
461 if(fTreeSFile == fTreeDFile) fTreeSFile=0;
462 if(fTreeRFile == fTreeDFile) fTreeRFile=0;
463 if(fTreeRFile == fTreeSFile) fTreeRFile=0;
465 if(fTreeDFile->IsOpen())fTreeDFile->Close();
469 if(fTreeSFile->IsOpen())fTreeSFile->Close();
473 if(fTreeRFile->IsOpen())fTreeRFile->Close();
476 if (gROOT->GetListOfBrowsables())
477 gROOT->GetListOfBrowsables()->Remove(this);
482 //_____________________________________________________________________________
483 void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
486 // Add a hit to detector id
488 TObjArray &dets = *fModules;
489 if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits);
492 //_____________________________________________________________________________
493 void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
496 // Add digit to detector id
498 TObjArray &dets = *fModules;
499 if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits);
502 //_____________________________________________________________________________
503 void AliRun::Browse(TBrowser *b)
506 // Called when the item "Run" is clicked on the left pane
507 // of the Root browser.
508 // It displays the Root Trees and all detectors.
510 if(!fStack) fStack=fHeader->Stack();
511 TTree* pTreeK = fStack->TreeK();
513 if (pTreeK) b->Add(pTreeK,pTreeK->GetName());
514 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
515 if (fTreeTR) b->Add(fTreeTR,fTreeH->GetName());
516 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
517 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
518 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
519 if (fTreeS) b->Add(fTreeS,fTreeS->GetName());
521 TIter next(fModules);
523 while((detector = (AliModule*)next())) {
524 b->Add(detector,detector->GetName());
526 b->Add(fMCQA,"AliMCQA");
529 //_____________________________________________________________________________
533 // Initialize Alice geometry
538 //_____________________________________________________________________________
539 void AliRun::BuildSimpleGeometry()
542 // Create a simple TNode geometry used by Root display engine
544 // Initialise geometry
546 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
547 new TMaterial("void","Vacuum",0,0,0); //Everything is void
548 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
549 brik->SetVisibility(0);
550 new TNode("alice","alice","S_alice");
553 //_____________________________________________________________________________
554 void AliRun::CleanDetectors()
557 // Clean Detectors at the end of event
559 TIter next(fModules);
561 while((detector = (AliModule*)next())) {
562 detector->FinishEvent();
566 //_____________________________________________________________________________
567 Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
570 // Return the distance from the mouse to the AliRun object
576 //_____________________________________________________________________________
577 void AliRun::DumpPart (Int_t i) const
580 // Dumps particle i in the stack
585 //_____________________________________________________________________________
586 void AliRun::DumpPStack () const
589 // Dumps the particle stack
591 fStack->DumpPStack();
594 //_____________________________________________________________________________
595 void AliRun::SetField(AliMagF* magField)
597 // Set Magnetic Field Map
602 //_____________________________________________________________________________
603 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
604 Float_t maxField, char* filename)
607 // Set magnetic field parameters
608 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
609 // version Magnetic field map version (only 1 active now)
610 // scale Scale factor for the magnetic field
611 // maxField Maximum value for the magnetic field
614 // --- Sanity check on mag field flags
615 if(fField) delete fField;
617 fField = new AliMagFC("Map1"," ",type,scale,maxField);
618 } else if(version<=2) {
619 fField = new AliMagFCM("Map2-3",filename,type,scale,maxField);
621 } else if(version==3) {
622 fField = new AliMagFDM("Map4",filename,type,scale,maxField);
625 Warning("SetField","Invalid map %d\n",version);
629 //_____________________________________________________________________________
630 void AliRun::FinishRun()
633 // Called at the end of the run.
637 if(fLego) fLego->FinishRun();
639 // Clean detector information
640 TIter next(fModules);
642 while((detector = (AliModule*)next())) {
643 detector->FinishRun();
646 //Output energy summary tables
649 TFile *file = fTreeE->GetCurrentFile();
653 fTreeE->Write(0,TObject::kOverwrite);
655 // Write AliRun info and all detectors parameters
656 Write(0,TObject::kOverwrite);
658 // Clean tree information
663 delete fTreeH; fTreeH = 0;
666 delete fTreeTR; fTreeTR = 0;
669 delete fTreeD; fTreeD = 0;
672 delete fTreeR; fTreeR = 0;
675 // delete fTreeE; fTreeE = 0;
678 delete fTreeS; fTreeS = 0;
680 fGenerator->FinishRun();
686 //_____________________________________________________________________________
687 void AliRun::FlagTrack(Int_t track)
691 fStack->FlagTrack(track);
694 //_____________________________________________________________________________
695 void AliRun::EnergySummary()
698 // Print summary of deposited energy
704 Int_t kn, i, left, j, id;
705 const Float_t kzero=0;
706 Int_t ievent=fHeader->GetEvent()+1;
708 // Energy loss information
710 printf("***************** Energy Loss Information per event (GEV) *****************\n");
711 for(kn=1;kn<fEventEnergy.GetSize();kn++) {
714 fEventEnergy[ndep]=kn;
719 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,kzero))/ed;
722 fSummEnergy[ndep]=ed;
723 fSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,kzero));
728 for(kn=0;kn<(ndep-1)/3+1;kn++) {
730 for(i=0;i<(3<left?3:left);i++) {
732 id=Int_t (fEventEnergy[j]+0.1);
733 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]);
738 // Relative energy loss in different detectors
739 printf("******************** Relative Energy Loss per event ********************\n");
740 printf("Total energy loss per event %10.3f GeV\n",edtot);
741 for(kn=0;kn<(ndep-1)/5+1;kn++) {
743 for(i=0;i<(5<left?5:left);i++) {
745 id=Int_t (fEventEnergy[j]+0.1);
746 printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot);
750 for(kn=0;kn<75;kn++) printf("*");
754 // Reset the TArray's
755 // fEventEnergy.Set(0);
756 // fSummEnergy.Set(0);
757 // fSum2Energy.Set(0);
760 //_____________________________________________________________________________
761 AliModule *AliRun::GetModule(const char *name) const
764 // Return pointer to detector from name
766 return (AliModule*)fModules->FindObject(name);
769 //_____________________________________________________________________________
770 AliDetector *AliRun::GetDetector(const char *name) const
773 // Return pointer to detector from name
775 return (AliDetector*)fModules->FindObject(name);
778 //_____________________________________________________________________________
779 Int_t AliRun::GetModuleID(const char *name) const
782 // Return galice internal detector identifier from name
785 TObject *mod=fModules->FindObject(name);
786 if(mod) i=fModules->IndexOf(mod);
790 //_____________________________________________________________________________
791 Int_t AliRun::GetEvent(Int_t event)
794 // Connect the Trees Kinematics and Hits for event # event
795 // Set branch addresses
798 // Reset existing structures
800 ResetTrackReferences();
804 // Delete Trees already connected
805 if (fTreeH) { delete fTreeH; fTreeH = 0;}
806 if (fTreeTR) { delete fTreeTR; fTreeTR = 0;}
807 if (fTreeD) { delete fTreeD; fTreeD = 0;}
808 if (fTreeR) { delete fTreeR; fTreeR = 0;}
809 if (fTreeS) { delete fTreeS; fTreeS = 0;}
811 // Create the particle stack
812 if (fHeader) delete fHeader;
815 // Get header from file
817 fTreeE->SetBranchAddress("Header", &fHeader);
819 if (!fTreeE->GetEntry(event)) {
820 Error("GetEvent","Cannot find event:%d\n",event);
825 Error("GetEvent","Cannot find Header Tree (TE)\n");
829 // Get the stack from the header, set fStack to 0 if it
830 // fails to get event
832 TFile *file = fTreeE->GetCurrentFile();
837 if (fStack) delete fStack;
838 fStack = fHeader->Stack();
840 if (!fStack->GetEvent(event)) fStack = 0;
843 // Get Hits Tree header from file
844 sprintf(treeName,"TreeH%d",event);
845 fTreeH = (TTree*)gDirectory->Get(treeName);
847 Warning("GetEvent","cannot find Hits Tree for event:%d\n",event);
850 // Get TracReferences Tree header from file
851 sprintf(treeName,"TreeTR%d",event);
852 fTreeTR = (TTree*)gDirectory->Get(treeName);
854 Warning("GetEvent","cannot find TrackReferences Tree for event:%d\n",event);
857 // get current file name and compare with names containing trees S,D,R
858 TString curfilname=(TString)fTreeE->GetCurrentFile()->GetName();
859 if(fTreeDFileName==curfilname)fTreeDFileName="";
860 if(fTreeSFileName==curfilname)fTreeSFileName="";
861 if(fTreeRFileName==curfilname)fTreeRFileName="";
863 // Get Digits Tree header from file
864 sprintf(treeName,"TreeD%d",event);
866 if (!fTreeDFile && fTreeDFileName != "") {
867 InitTreeFile("D",fTreeDFileName);
870 fTreeD = (TTree*)fTreeDFile->Get(treeName);
872 fTreeD = (TTree*)file->Get(treeName);
875 // Warning("GetEvent","cannot find Digits Tree for event:%d\n",event);
877 if(fTreeDFileName != ""){
878 if(fTreeDFileName==fTreeSFileName) {
880 fTreeSFile = fTreeDFile;
882 if(fTreeDFileName==fTreeRFileName) {
884 fTreeRFile = fTreeDFile;
890 // Get SDigits Tree header from file
891 sprintf(treeName,"TreeS%d",event);
892 if (!fTreeSFile && fTreeSFileName != "") {
893 InitTreeFile("S",fTreeSFileName);
896 fTreeS = (TTree*)fTreeSFile->Get(treeName);
898 fTreeS = (TTree*)gDirectory->Get(treeName);
901 // Warning("GetEvent","cannot find SDigits Tree for event:%d\n",event);
904 if(fTreeSFileName != ""){
905 if(fTreeSFileName==fTreeRFileName){
907 fTreeRFile = fTreeSFile;
913 // Get Reconstruct Tree header from file
914 sprintf(treeName,"TreeR%d",event);
915 if (!fTreeRFile && fTreeRFileName != "") {
916 InitTreeFile("R",fTreeRFileName);
919 fTreeR = (TTree*)fTreeRFile->Get(treeName);
921 fTreeR = (TTree*)gDirectory->Get(treeName);
924 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
929 // Set Trees branch addresses
930 TIter next(fModules);
932 while((detector = (AliModule*)next())) {
933 detector->SetTreeAddress();
936 fEvent=event; //MI change
938 return fHeader->GetNtrack();
941 //_____________________________________________________________________________
942 TGeometry *AliRun::GetGeometry()
945 // Import Alice geometry from current file
946 // Return pointer to geometry object
948 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
950 // Unlink and relink nodes in detectors
951 // This is bad and there must be a better way...
954 TIter next(fModules);
956 while((detector = (AliModule*)next())) {
957 TList *dnodes=detector->Nodes();
960 for ( j=0; j<dnodes->GetSize(); j++) {
961 node = (TNode*) dnodes->At(j);
962 node1 = fGeometry->GetNode(node->GetName());
963 dnodes->Remove(node);
964 dnodes->AddAt(node1,j);
970 //_____________________________________________________________________________
971 Int_t AliRun::GetPrimary(Int_t track) const
974 // return number of primary that has generated track
976 return fStack->GetPrimary(track);
979 //_____________________________________________________________________________
980 void AliRun::MediaTable()
983 // Built media table to get from the media number to
986 Int_t kz, nz, idt, lz, i, k, ind;
988 TObjArray &dets = *gAlice->Detectors();
992 for (kz=0;kz<fNdets;kz++) {
993 // If detector is defined
994 if((det=(AliModule*) dets[kz])) {
995 TArrayI &idtmed = *(det->GetIdtmed());
996 for(nz=0;nz<100;nz++) {
997 // Find max and min material number
998 if((idt=idtmed[nz])) {
999 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
1000 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
1003 if(det->LoMedium() > det->HiMedium()) {
1004 det->LoMedium() = 0;
1005 det->HiMedium() = 0;
1007 if(det->HiMedium() > fImedia->GetSize()) {
1008 Error("MediaTable","Increase fImedia from %d to %d",
1009 fImedia->GetSize(),det->HiMedium());
1012 // Tag all materials in rage as belonging to detector kz
1013 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
1020 // Print summary table
1021 printf(" Traking media ranges:\n");
1022 for(i=0;i<(fNdets-1)/6+1;i++) {
1023 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
1025 det=(AliModule*)dets[ind];
1027 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
1030 printf(" %6s: %3d -> %3d;","NULL",0,0);
1036 //____________________________________________________________________________
1037 void AliRun::SetGenerator(AliGenerator *generator)
1040 // Load the event generator
1042 if(!fGenerator) fGenerator = generator;
1045 //____________________________________________________________________________
1046 void AliRun::ResetGenerator(AliGenerator *generator)
1049 // Load the event generator
1053 Warning("ResetGenerator","Replacing generator %s with %s\n",
1054 fGenerator->GetName(),generator->GetName());
1056 Warning("ResetGenerator","Replacing generator %s with NULL\n",
1057 fGenerator->GetName());
1058 fGenerator = generator;
1061 //____________________________________________________________________________
1062 void AliRun::SetTransPar(char *filename)
1064 fTransParName = filename;
1067 //____________________________________________________________________________
1068 void AliRun::SetBaseFile(char *filename)
1070 fBaseFileName = filename;
1073 //____________________________________________________________________________
1074 void AliRun::ReadTransPar()
1077 // Read filename to set the transport parameters
1081 const Int_t kncuts=10;
1082 const Int_t knflags=11;
1083 const Int_t knpars=kncuts+knflags;
1084 const char kpars[knpars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
1085 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
1086 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
1087 "MULS","PAIR","PHOT","RAYL"};
1091 Float_t cut[kncuts];
1092 Int_t flag[knflags];
1093 Int_t i, itmed, iret, ktmed, kz;
1096 // See whether the file is there
1097 filtmp=gSystem->ExpandPathName(fTransParName.Data());
1098 lun=fopen(filtmp,"r");
1101 Warning("ReadTransPar","File %s does not exist!\n",fTransParName.Data());
1106 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1107 printf(" *%59s\n","*");
1108 printf(" * Please check carefully what you are doing!%10s\n","*");
1109 printf(" *%59s\n","*");
1113 // Initialise cuts and flags
1114 for(i=0;i<kncuts;i++) cut[i]=-99;
1115 for(i=0;i<knflags;i++) flag[i]=-99;
1117 for(i=0;i<256;i++) line[i]='\0';
1118 // Read up to the end of line excluded
1119 iret=fscanf(lun,"%[^\n]",line);
1124 printf(" *%59s\n","*");
1125 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1129 // Read the end of line
1132 if(line[0]=='*') continue;
1134 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",
1135 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
1136 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
1137 &flag[8],&flag[9],&flag[10]);
1141 Warning("ReadTransPar","Error reading file %s\n",fTransParName.Data());
1144 // Check that the module exist
1145 AliModule *mod = GetModule(detName);
1147 // Get the array of media numbers
1148 TArrayI &idtmed = *mod->GetIdtmed();
1149 // Check that the tracking medium code is valid
1150 if(0<=itmed && itmed < 100) {
1151 ktmed=idtmed[itmed];
1153 Warning("ReadTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
1156 // Set energy thresholds
1157 for(kz=0;kz<kncuts;kz++) {
1159 if(fDebug) printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
1160 kpars[kz],cut[kz],itmed,mod->GetName());
1161 gMC->Gstpar(ktmed,kpars[kz],cut[kz]);
1164 // Set transport mechanisms
1165 for(kz=0;kz<knflags;kz++) {
1167 if(fDebug) printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
1168 kpars[kncuts+kz],flag[kz],itmed,mod->GetName());
1169 gMC->Gstpar(ktmed,kpars[kncuts+kz],Float_t(flag[kz]));
1173 Warning("ReadTransPar","Invalid medium code %d *\n",itmed);
1177 if(fDebug) printf("%s::ReadTransParModule: %s not present\n",ClassName(),detName);
1184 //_____________________________________________________________________________
1185 void AliRun::MakeTree(Option_t *option, const char *file)
1188 // Create the ROOT trees
1189 // Loop on all detectors to create the Root branch (if any)
1195 const char *oK = strstr(option,"K");
1196 const char *oH = strstr(option,"H");
1197 const char *oTR = strstr(option,"T");
1198 const char *oE = strstr(option,"E");
1199 const char *oD = strstr(option,"D");
1200 const char *oR = strstr(option,"R");
1201 const char *oS = strstr(option,"S");
1204 TDirectory *cwd = gDirectory;
1206 TBranch *branch = 0;
1208 if (oK) fStack->MakeTree(fEvent, file);
1210 if (oE && !fTreeE) {
1211 fTreeE = new TTree("TE","Header");
1212 // branch = fTreeE->Branch("Header", "AliHeader", &fHeader, 4000, 0);
1213 branch = fTreeE->Branch("Header", "AliHeader", &fHeader, 4000, 0);
1214 branch->SetAutoDelete(kFALSE);
1215 TFolder *folder = (TFolder *)gROOT->FindObjectAny("/Folders/RunMC/Event/Header");
1216 if (folder) folder->Add(fHeader);
1217 // branch = fTreeE->Branch("Stack","AliStack", &fStack, 4000, 0);
1218 // branch->SetAutoDelete(kFALSE);
1219 // if (folder) folder->Add(fStack);
1220 fTreeE->Write(0,TObject::kOverwrite);
1223 if (file && branch) {
1224 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
1225 sprintf(outFile,"%s/%s",GetBaseFile(),file);
1226 branch->SetFile(outFile);
1227 TIter next( branch->GetListOfBranches());
1228 while ((branch=(TBranch*)next())) {
1229 branch->SetFile(outFile);
1232 printf("* MakeBranch * Diverting Branch %s to file %s\n", branch->GetName(),file);
1237 if (oH && !fTreeH) {
1238 sprintf(hname,"TreeH%d",fEvent);
1239 fTreeH = new TTree(hname,"Hits");
1240 fTreeH->SetAutoSave(1000000000); //no autosave
1241 fTreeH->Write(0,TObject::kOverwrite);
1244 if (oTR && !fTreeTR) {
1245 sprintf(hname,"TreeTR%d",fEvent);
1246 fTreeTR = new TTree(hname,"TrackReferences");
1247 fTreeTR->SetAutoSave(1000000000); //no autosave
1248 fTreeTR->Write(0,TObject::kOverwrite);
1251 if (oD && !fTreeD) {
1252 sprintf(hname,"TreeD%d",fEvent);
1253 fTreeD = new TTree(hname,"Digits");
1254 fTreeD->Write(0,TObject::kOverwrite);
1256 if (oS && !fTreeS) {
1257 sprintf(hname,"TreeS%d",fEvent);
1258 fTreeS = new TTree(hname,"SDigits");
1259 fTreeS->Write(0,TObject::kOverwrite);
1261 if (oR && !fTreeR) {
1262 sprintf(hname,"TreeR%d",fEvent);
1263 fTreeR = new TTree(hname,"Reconstruction");
1264 fTreeR->Write(0,TObject::kOverwrite);
1268 // Create a branch for hits/digits for each detector
1269 // Each branch is a TClonesArray. Each data member of the Hits classes
1270 // will be in turn a subbranch of the detector master branch
1271 TIter next(fModules);
1272 AliModule *detector;
1273 while((detector = (AliModule*)next())) {
1274 if (oH) detector->MakeBranch(option,file);
1275 if (oTR) detector->MakeBranchTR(option,file);
1279 //_____________________________________________________________________________
1280 TParticle* AliRun::Particle(Int_t i)
1282 return fStack->Particle(i);
1285 //_____________________________________________________________________________
1286 void AliRun::ResetDigits()
1289 // Reset all Detectors digits
1291 TIter next(fModules);
1292 AliModule *detector;
1293 while((detector = (AliModule*)next())) {
1294 detector->ResetDigits();
1298 //_____________________________________________________________________________
1299 void AliRun::ResetSDigits()
1302 // Reset all Detectors digits
1304 TIter next(fModules);
1305 AliModule *detector;
1306 while((detector = (AliModule*)next())) {
1307 detector->ResetSDigits();
1311 //_____________________________________________________________________________
1312 void AliRun::ResetHits()
1315 // Reset all Detectors hits
1317 TIter next(fModules);
1318 AliModule *detector;
1319 while((detector = (AliModule*)next())) {
1320 detector->ResetHits();
1324 //_____________________________________________________________________________
1325 void AliRun::ResetTrackReferences()
1328 // Reset all Detectors hits
1330 TIter next(fModules);
1331 AliModule *detector;
1332 while((detector = (AliModule*)next())) {
1333 detector->ResetTrackReferences();
1337 //_____________________________________________________________________________
1338 void AliRun::ResetPoints()
1341 // Reset all Detectors points
1343 TIter next(fModules);
1344 AliModule *detector;
1345 while((detector = (AliModule*)next())) {
1346 detector->ResetPoints();
1350 //_____________________________________________________________________________
1351 void AliRun::InitMC(const char *setup)
1354 // Initialize the Alice setup
1358 Warning("Init","Cannot initialise AliRun twice!\n");
1362 gROOT->LoadMacro(setup);
1363 gInterpreter->ProcessLine(fConfigFunction.Data());
1365 // Register MC in configuration
1366 AliConfig::Instance()->Add(gMC);
1367 gMC->SetStack(fStack);
1369 gMC->DefineParticles(); //Create standard MC particles
1371 TObject *objfirst, *objlast;
1373 fNdets = fModules->GetLast()+1;
1376 //=================Create Materials and geometry
1379 // Added also after in case of interactive initialisation of modules
1380 fNdets = fModules->GetLast()+1;
1382 TIter next(fModules);
1383 AliModule *detector;
1384 while((detector = (AliModule*)next())) {
1385 detector->SetTreeAddress();
1386 objlast = gDirectory->GetList()->Last();
1388 // Add Detector histograms in Detector list of histograms
1389 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
1390 else objfirst = gDirectory->GetList()->First();
1392 detector->Histograms()->Add(objfirst);
1393 objfirst = gDirectory->GetList()->After(objfirst);
1396 ReadTransPar(); //Read the cuts for all materials
1398 MediaTable(); //Build the special IMEDIA table
1400 //Initialise geometry deposition table
1401 fEventEnergy.Set(gMC->NofVolumes()+1);
1402 fSummEnergy.Set(gMC->NofVolumes()+1);
1403 fSum2Energy.Set(gMC->NofVolumes()+1);
1405 //Compute cross-sections
1406 gMC->BuildPhysics();
1408 //Write Geometry object to current file.
1413 fMCQA = new AliMCQA(fNdets);
1415 AliConfig::Instance();
1417 // Save stuff at the beginning of the file to avoid file corruption
1421 //_____________________________________________________________________________
1422 void AliRun::RunMC(Int_t nevent, const char *setup)
1425 // Main function to be called to process a galice run
1427 // Root > gAlice.Run();
1428 // a positive number of events will cause the finish routine
1431 fEventsPerRun = nevent;
1432 // check if initialisation has been done
1433 if (!fInitDone) InitMC(setup);
1435 // Create the Root Tree with one branch per detector
1439 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1440 MakeTree("K","Kine.root");
1441 MakeTree("H","Hits.root");
1446 gMC->ProcessRun(nevent);
1448 // End of this run, close files
1449 if(nevent>0) FinishRun();
1452 //_____________________________________________________________________________
1453 void AliRun::RunReco(const char *selected, Int_t first, Int_t last)
1456 // Main function to be called to reconstruct Alice event
1458 cout << "Found "<< gAlice->TreeE()->GetEntries() << "events" << endl;
1459 Int_t nFirst = first;
1460 Int_t nLast = (last < 0)? (Int_t) gAlice->TreeE()->GetEntries() : last;
1462 for (Int_t nevent = nFirst; nevent <= nLast; nevent++) {
1463 cout << "Processing event "<< nevent << endl;
1466 Digits2Reco(selected);
1470 //_____________________________________________________________________________
1472 void AliRun::Hits2Digits(const char *selected)
1475 // Convert Hits to sumable digits
1477 for (Int_t nevent=0; nevent<gAlice->TreeE()->GetEntries(); nevent++) {
1480 Hits2SDigits(selected);
1481 SDigits2Digits(selected);
1486 //_____________________________________________________________________________
1488 void AliRun::Tree2Tree(Option_t *option, const char *selected)
1491 // Function to transform the content of
1493 // - TreeH to TreeS (option "S")
1494 // - TreeS to TreeD (option "D")
1495 // - TreeD to TreeR (option "R")
1497 // If multiple options are specified ("SDR"), transformation will be done in sequence for
1498 // selected detector and for all detectors if none is selected (detector string
1499 // can contain blank separated list of detector names).
1502 const char *oS = strstr(option,"S");
1503 const char *oD = strstr(option,"D");
1504 const char *oR = strstr(option,"R");
1506 TObjArray *detectors = Detectors();
1508 TIter next(detectors);
1510 AliDetector *detector = 0;
1512 TDirectory *cwd = gDirectory;
1516 while((detector = (AliDetector*)next())) {
1518 if (strcmp(detector->GetName(),selected)) continue;
1519 if (detector->IsActive()){
1520 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1522 sprintf(outFile,"SDigits.%s.root",detector->GetName());
1523 detector->MakeBranch("S",outFile);
1526 sprintf(outFile,"Digits.%s.root",detector->GetName());
1527 detector->MakeBranch("D",outFile);
1530 sprintf(outFile,"Reco.%s.root",detector->GetName());
1531 detector->MakeBranch("R",outFile);
1534 detector->MakeBranch(option);
1540 cout << "Hits2SDigits: Processing " << detector->GetName() << "..." << endl;
1541 detector->Hits2SDigits();
1544 cout << "SDigits2Digits: Processing " << detector->GetName() << "..." << endl;
1545 detector->SDigits2Digits();
1548 cout << "Digits2Reco: Processing " << detector->GetName() << "..." << endl;
1549 detector->Digits2Reco();
1558 //_____________________________________________________________________________
1559 void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min,
1560 Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max,
1561 Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener)
1564 // Generates lego plots of:
1565 // - radiation length map phi vs theta
1566 // - radiation length map phi vs eta
1567 // - interaction length map
1568 // - g/cm2 length map
1570 // ntheta bins in theta, eta
1571 // themin minimum angle in theta (degrees)
1572 // themax maximum angle in theta (degrees)
1574 // phimin minimum angle in phi (degrees)
1575 // phimax maximum angle in phi (degrees)
1576 // rmin minimum radius
1577 // rmax maximum radius
1580 // The number of events generated = ntheta*nphi
1581 // run input parameters in macro setup (default="Config.C")
1583 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1586 <img src="picts/AliRunLego1.gif">
1591 <img src="picts/AliRunLego2.gif">
1596 <img src="picts/AliRunLego3.gif">
1601 // check if initialisation has been done
1602 if (!fInitDone) InitMC(setup);
1603 //Save current generator
1604 AliGenerator *gen=Generator();
1606 // Set new generator
1607 if (!gener) gener = new AliLegoGenerator();
1608 ResetGenerator(gener);
1610 // Configure Generator
1611 gener->SetRadiusRange(rmin, rmax);
1612 gener->SetZMax(zmax);
1613 gener->SetCoor1Range(nc1, c1min, c1max);
1614 gener->SetCoor2Range(nc2, c2min, c2max);
1617 //Create Lego object
1618 fLego = new AliLego("lego",gener);
1620 //Prepare MC for Lego Run
1625 //gMC->ProcessRun(nc1*nc2+1);
1626 gMC->ProcessRun(nc1*nc2);
1628 // Create only the Root event Tree
1631 // End of this run, close files
1633 // Restore current generator
1634 ResetGenerator(gen);
1635 // Delete Lego Object
1636 delete fLego; fLego=0;
1639 //_____________________________________________________________________________
1640 void AliRun::SetConfigFunction(const char * config)
1643 // Set the signature of the function contained in Config.C to configure
1646 fConfigFunction=config;
1649 //_____________________________________________________________________________
1650 void AliRun::SetCurrentTrack(Int_t track)
1653 // Set current track number
1655 fStack->SetCurrentTrack(track);
1658 //_____________________________________________________________________________
1659 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1660 Float_t *vpos, Float_t *polar, Float_t tof,
1661 AliMCProcess mech, Int_t &ntr, Float_t weight, Int_t is)
1663 // Delegate to stack
1666 fStack->SetTrack(done, parent, pdg, pmom, vpos, polar, tof,
1667 mech, ntr, weight, is);
1670 //_____________________________________________________________________________
1671 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg,
1672 Double_t px, Double_t py, Double_t pz, Double_t e,
1673 Double_t vx, Double_t vy, Double_t vz, Double_t tof,
1674 Double_t polx, Double_t poly, Double_t polz,
1675 AliMCProcess mech, Int_t &ntr, Float_t weight, Int_t is)
1677 // Delegate to stack
1679 fStack->SetTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
1680 polx, poly, polz, mech, ntr, weight, is);
1684 //_____________________________________________________________________________
1685 void AliRun::SetHighWaterMark(const Int_t nt)
1688 // Set high water mark for last track in event
1689 fStack->SetHighWaterMark(nt);
1692 //_____________________________________________________________________________
1693 void AliRun::KeepTrack(const Int_t track)
1696 // Delegate to stack
1698 fStack->KeepTrack(track);
1705 //_____________________________________________________________________________
1706 void AliRun::ConstructGeometry()
1709 // Create modules, materials, geometry
1713 TIter next(fModules);
1714 AliModule *detector;
1715 printf("Geometry creation:\n");
1716 while((detector = (AliModule*)next())) {
1718 // Initialise detector materials and geometry
1719 detector->CreateMaterials();
1720 detector->CreateGeometry();
1721 printf("%10s R:%.2fs C:%.2fs\n",
1722 detector->GetName(),stw.RealTime(),stw.CpuTime());
1726 //_____________________________________________________________________________
1727 void AliRun::InitGeometry()
1730 // Initialize detectors and display geometry
1733 printf("Initialisation:\n");
1735 TIter next(fModules);
1736 AliModule *detector;
1737 while((detector = (AliModule*)next())) {
1739 // Initialise detector and display geometry
1741 detector->BuildGeometry();
1742 printf("%10s R:%.2fs C:%.2fs\n",
1743 detector->GetName(),stw.RealTime(),stw.CpuTime());
1748 //_____________________________________________________________________________
1749 void AliRun::GeneratePrimaries()
1752 // Generate primary particles and fill them in the stack.
1755 Generator()->Generate();
1758 //_____________________________________________________________________________
1759 void AliRun::BeginEvent()
1761 // Clean-up previous event
1763 fEventEnergy.Reset();
1764 // Clean detector information
1771 // Reset all Detectors & kinematics & trees
1775 // Initialise event header
1776 fHeader->Reset(fRun,fEvent,fEventNrInRun);
1778 fStack->BeginEvent(fEvent);
1782 fLego->BeginEvent();
1789 ResetTrackReferences();
1796 sprintf(hname,"TreeH%d",fEvent);
1797 fTreeH->SetName(hname);
1802 sprintf(hname,"TreeTR%d",fEvent);
1803 fTreeTR->SetName(hname);
1808 sprintf(hname,"TreeD%d",fEvent);
1809 fTreeD->SetName(hname);
1810 fTreeD->Write(0,TObject::kOverwrite);
1814 sprintf(hname,"TreeS%d",fEvent);
1815 fTreeS->SetName(hname);
1816 fTreeS->Write(0,TObject::kOverwrite);
1820 sprintf(hname,"TreeR%d",fEvent);
1821 fTreeR->SetName(hname);
1822 fTreeR->Write(0,TObject::kOverwrite);
1826 //_____________________________________________________________________________
1827 void AliRun::BeginPrimary()
1830 // Called at the beginning of each primary track
1834 gAlice->ResetHits();
1835 gAlice->ResetTrackReferences();
1839 //_____________________________________________________________________________
1840 void AliRun::PreTrack()
1842 TObjArray &dets = *fModules;
1845 for(Int_t i=0; i<=fNdets; i++)
1846 if((module = (AliModule*)dets[i]))
1852 //_____________________________________________________________________________
1853 void AliRun::Stepping()
1856 // Called at every step during transport
1859 Int_t id = DetFromMate(gMC->GetMedium());
1863 // --- If lego option, do it and leave
1865 fLego->StepManager();
1868 //Update energy deposition tables
1869 AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
1871 //Call the appropriate stepping routine;
1872 AliModule *det = (AliModule*)fModules->At(id);
1873 if(det && det->StepManagerIsEnabled()) {
1874 fMCQA->StepManager(id);
1880 //_____________________________________________________________________________
1881 void AliRun::PostTrack()
1883 TObjArray &dets = *fModules;
1886 for(Int_t i=0; i<=fNdets; i++)
1887 if((module = (AliModule*)dets[i]))
1888 module->PostTrack();
1891 //_____________________________________________________________________________
1892 void AliRun::FinishPrimary()
1895 // Called at the end of each primary track
1898 // static Int_t count=0;
1899 // const Int_t times=10;
1900 // This primary is finished, purify stack
1901 fStack->PurifyKine();
1903 TIter next(fModules);
1904 AliModule *detector;
1905 while((detector = (AliModule*)next())) {
1906 detector->FinishPrimary();
1909 // Write out hits if any
1910 if (gAlice->TreeH()) {
1911 gAlice->TreeH()->Fill();
1914 // Write out hits if any
1915 if (gAlice->TreeTR()) {
1916 gAlice->TreeTR()->Fill();
1920 // if(++count%times==1) gObjectTable->Print();
1923 //_____________________________________________________________________________
1924 void AliRun::FinishEvent()
1927 // Called at the end of the event.
1931 if(fLego) fLego->FinishEvent();
1933 //Update the energy deposit tables
1935 for(i=0;i<fEventEnergy.GetSize();i++) {
1936 fSummEnergy[i]+=fEventEnergy[i];
1937 fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
1942 // Update Header information
1944 fHeader->SetNprimary(fStack->GetNprimary());
1945 fHeader->SetNtrack(fStack->GetNtrack());
1948 // Write out the kinematics
1949 fStack->FinishEvent();
1951 // Write out the event Header information
1953 fHeader->SetStack(fStack);
1958 // Write Tree headers
1959 TTree* pTreeK = fStack->TreeK();
1960 if (pTreeK) pTreeK->Write(0,TObject::kOverwrite);
1961 if (fTreeH) fTreeH->Write(0,TObject::kOverwrite);
1962 if (fTreeTR) fTreeTR->Write(0,TObject::kOverwrite);
1968 //_____________________________________________________________________________
1969 void AliRun::Field(const Double_t* x, Double_t *b) const
1972 for (Int_t i=0; i<3; i++) xfloat[i] = x[i];
1976 Field()->Field(xfloat,bfloat);
1977 for (Int_t j=0; j<3; j++) b[j] = bfloat[j];
1980 printf("No mag field defined!\n");
1987 // End of MC Application
1990 //_____________________________________________________________________________
1991 void AliRun::Streamer(TBuffer &R__b)
1993 // Stream an object of class AliRun.
1995 if (R__b.IsReading()) {
1996 if (!gAlice) gAlice = this;
1998 AliRun::Class()->ReadBuffer(R__b, this);
2000 gROOT->GetListOfBrowsables()->Add(this,"Run");
2002 fTreeE = (TTree*)gDirectory->Get("TE");
2004 fTreeE->SetBranchAddress("Header", &fHeader);
2006 else Error("Streamer","cannot find Header Tree\n");
2008 fTreeE->GetEntry(0);
2011 AliRun::Class()->WriteBuffer(R__b, this);
2016 //___________________________________________________________________________
2017 Int_t AliRun::CurrentTrack() const {
2019 // Returns current track
2021 return fStack->CurrentTrack();
2024 //___________________________________________________________________________
2025 Int_t AliRun::GetNtrack() const {
2027 // Returns number of tracks in stack
2029 return fStack->GetNtrack();
2032 //___________________________________________________________________________
2033 TObjArray* AliRun::Particles() {
2035 // Returns pointer to Particles array
2037 return fStack->Particles();
2040 //___________________________________________________________________________
2041 TTree* AliRun::TreeK() {
2043 // Returns pointer to the TreeK array
2045 return fStack->TreeK();
2049 //___________________________________________________________________________
2050 void AliRun::SetGenEventHeader(AliGenEventHeader* header)
2052 fHeader->SetGenEventHeader(header);
2055 //___________________________________________________________________________
2056 TFile* AliRun::InitFile(TString fileName)
2059 // create the file where the whole tree will be saved
2061 TDirectory *wd = gDirectory;
2062 TFile* file = TFile::Open(fileName,"update");
2064 if (!file->IsOpen()) {
2065 Error("Cannot open file, %s\n",fileName);
2071 //___________________________________________________________________________
2072 TFile* AliRun::InitTreeFile(Option_t *option, TString fileName)
2075 // create the file where one of the following trees will be saved
2077 // WARNING: by default these trees are saved on the file on which
2078 // hits are stored. If you divert one of these trees, you cannot restore
2079 // it to the original file (usually galice.root) in the same aliroot session
2080 Bool_t oS = (strstr(option,"S")!=0);
2081 Bool_t oR = (strstr(option,"R")!=0);
2082 Bool_t oD = (strstr(option,"D")!=0);
2084 for (Int_t i=0; i<3; i++) choice[i] = 0;
2085 if(oS)choice[0] = 1;
2086 if(oD)choice[1] = 1;
2087 if(oR)choice[2] = 1;
2091 if(!(oS || oR || oD))return ptr;
2094 for (Int_t i=0; i<3; i++) active[i] = 0;
2095 if(fTreeSFileName != "") active[0] = 1;
2096 if(fTreeDFileName != "") active[1] = 1;
2097 if(fTreeDFileName != "") active[2] = 1;
2099 Bool_t alreadyopen1 = kFALSE;
2100 Bool_t alreadyopen2 = kFALSE;
2103 // if already active and same name with non-null ptr
2104 if(active[0]==1 && fileName == fTreeSFileName && fTreeSFile){
2105 Warning("InitTreeFile","File %s already opened",fTreeSFileName.Data());
2109 // if already active with different name with non-null ptr
2110 if(active[0]==1 && fileName != fTreeSFileName && fTreeSFile){
2111 // close the active files and also the other possible files in option
2112 CloseTreeFile(option);
2114 fTreeSFileName = fileName;
2116 (active[1] == 1 && fTreeDFileName == fTreeSFileName && fTreeDFile);
2118 (active[2] == 1 && fTreeRFileName == fTreeSFileName && fTreeRFile);
2119 if(!(alreadyopen1 || alreadyopen2)){
2120 ptr = InitFile(fileName);
2124 if(alreadyopen1){fTreeSFile = fTreeDFile; ptr = fTreeSFile;}
2125 if(alreadyopen2){fTreeSFile = fTreeRFile; ptr = fTreeSFile;}
2127 if(choice[1] == 1) { fTreeDFileName = fileName; fTreeDFile = ptr;}
2128 if(choice[2] == 1) { fTreeRFileName = fileName; fTreeRFile = ptr;}
2134 // if already active and same name with non-null ptr
2135 if(active[1]==1 && fileName == fTreeDFileName && fTreeDFile){
2136 Warning("InitTreeFile","File %s already opened",fTreeDFileName.Data());
2140 // if already active with different name with non-null ptr
2141 if(active[1]==1 && fileName != fTreeDFileName && fTreeDFile){
2142 // close the active files and also the other possible files in option
2143 CloseTreeFile(option);
2145 fTreeDFileName = fileName;
2147 (active[0] == 1 && fTreeSFileName == fTreeDFileName && fTreeSFile);
2149 (active[2] == 1 && fTreeRFileName == fTreeDFileName && fTreeRFile);
2150 if(!(alreadyopen1 || alreadyopen2)){
2151 ptr = InitFile(fileName);
2155 if(alreadyopen1){fTreeDFile = fTreeSFile; ptr = fTreeDFile;}
2156 if(alreadyopen2){fTreeDFile = fTreeRFile; ptr = fTreeDFile;}
2158 if(choice[2] == 1) { fTreeRFileName = fileName; fTreeRFile = ptr;}
2164 // if already active and same name with non-null ptr
2165 if(active[2]==1 && fileName == fTreeRFileName && fTreeRFile){
2166 Warning("InitTreeFile","File %s already opened",fTreeRFileName.Data());
2170 // if already active with different name with non-null ptr
2171 if(active[2]==1 && fileName != fTreeRFileName && fTreeRFile){
2172 // close the active files and also the other possible files in option
2173 CloseTreeFile(option);
2175 fTreeRFileName = fileName;
2177 (active[1] == 1 && fTreeDFileName == fTreeRFileName && fTreeDFile);
2179 (active[0]== 1 && fTreeSFileName == fTreeRFileName && fTreeSFile);
2180 if(!(alreadyopen1 || alreadyopen2)){
2181 ptr = InitFile(fileName);
2185 if(alreadyopen1){fTreeRFile = fTreeDFile; ptr = fTreeRFile;}
2186 if(alreadyopen2){fTreeRFile = fTreeSFile; ptr = fTreeRFile;}
2194 //___________________________________________________________________________
2195 void AliRun::PrintTreeFile()
2198 // prints the file names and pointer associated to S,D,R trees
2200 cout<<"===================================================\n";
2201 TFile *file = fTreeE->GetCurrentFile();
2202 TString curfilname="";
2203 if(file)curfilname=(TString)file->GetName();
2204 cout<<" Current tree file name: "<<curfilname<<endl;
2205 cout<<"Pointer: "<<file<<endl;
2206 cout<<" Tree S File name: "<<fTreeSFileName<<endl;
2207 cout<<"Pointer: "<<fTreeSFile<<endl<<endl;
2208 cout<<" Tree D File name: "<<fTreeDFileName<<endl;
2209 cout<<"Pointer: "<<fTreeDFile<<endl<<endl;
2210 cout<<" Tree R File name: "<<fTreeRFileName<<endl;
2211 cout<<"Pointer: "<<fTreeRFile<<endl<<endl;
2212 cout<<"===================================================\n";
2214 //___________________________________________________________________________
2215 void AliRun::CloseTreeFile(Option_t *option)
2218 // closes the file containing the tree specified in option
2221 Bool_t oS = (strstr(option,"S")!=0);
2222 Bool_t oR = (strstr(option,"R")!=0);
2223 Bool_t oD = (strstr(option,"D")!=0);
2224 Bool_t none = !(oS || oR || oD);
2227 fTreeSFileName = "";
2229 if(!((fTreeSFile == fTreeDFile) || (fTreeSFile == fTreeRFile)) &&
2230 fTreeSFile->IsOpen()){
2231 fTreeSFile->Close();
2238 fTreeDFileName = "";
2240 if(!((fTreeDFile == fTreeRFile) || (fTreeDFile == fTreeSFile)) &&
2241 fTreeDFile->IsOpen()){
2242 fTreeDFile->Close();
2249 fTreeRFileName = "";
2251 if(!((fTreeRFile == fTreeSFile) || (fTreeRFile == fTreeDFile)) &&
2252 fTreeRFile->IsOpen()){
2253 fTreeRFile->Close();
2261 //___________________________________________________________________________
2262 void AliRun::MakeTree(Option_t *option, TFile *file)
2265 // Create some trees in the separate file
2267 const char *oD = strstr(option,"D");
2268 const char *oR = strstr(option,"R");
2269 const char *oS = strstr(option,"S");
2271 TDirectory *cwd = gDirectory;
2276 sprintf(hname,"TreeD%d",fEvent);
2278 fTreeD = static_cast<TTree*>(file->Get("hname"));
2280 fTreeD = new TTree(hname,"Digits");
2281 fTreeD->Write(0,TObject::kOverwrite);
2287 sprintf(hname,"TreeS%d",fEvent);
2289 fTreeS = static_cast<TTree*>(file->Get("hname"));
2291 fTreeS = new TTree(hname,"SDigits");
2292 fTreeS->Write(0,TObject::kOverwrite);
2299 sprintf(hname,"TreeR%d",fEvent);
2301 fTreeR = static_cast<TTree*>(file->Get("hname"));
2303 fTreeR = new TTree(hname,"RecPoint");
2304 fTreeR->Write(0,TObject::kOverwrite);