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.62 2001/04/06 11:12:33 morsch
19 Clear fParticles after each event. (Ivana Hrivnacova)
21 Revision 1.61 2001/03/30 07:04:10 morsch
22 Call fGenerator->FinishRun() for final print-outs, cross-section and weight calculations.
24 Revision 1.60 2001/03/21 18:22:30 hristov
25 fParticleFileMap fix (I.Hrivnacova)
27 Revision 1.59 2001/03/12 17:47:03 hristov
28 Changes needed on Sun with CC 5.0
30 Revision 1.58 2001/03/09 14:27:26 morsch
31 Fix for multiple events per file: inhibit decrease of size of fParticleFileMap.
33 Revision 1.57 2001/02/23 17:40:23 buncic
34 All trees needed for simulation created in RunMC(). TreeR and its branches
35 are now created in new RunReco() method.
37 Revision 1.56 2001/02/14 15:45:20 hristov
38 Algorithmic way of getting entry index in fParticleMap. Protection of fParticleFileMap (I.Hrivnacova)
40 Revision 1.55 2001/02/12 15:52:54 buncic
41 Removed OpenBaseFile().
43 Revision 1.54 2001/02/07 10:39:05 hristov
44 Remove default value for argument
46 Revision 1.53 2001/02/06 11:02:26 hristov
47 New SetTrack interface added, added check for unfilled particles in FinishEvent (I.Hrivnacova)
49 Revision 1.52 2001/02/05 16:22:25 buncic
50 Added TreeS to GetEvent().
52 Revision 1.51 2001/02/02 15:16:20 morsch
53 SetHighWaterMark method added to mark last particle in event.
55 Revision 1.50 2001/01/27 10:32:00 hristov
56 Leave the loop when primaries are filled (I.Hrivnacova)
58 Revision 1.49 2001/01/26 19:58:48 hristov
59 Major upgrade of AliRoot code
61 Revision 1.48 2001/01/17 10:50:50 hristov
62 Corrections to destructors
64 Revision 1.47 2000/12/18 10:44:01 morsch
65 Possibility to set field map by passing pointer to objet of type AliMagF via
68 gAlice->SetField(new AliMagFCM("Map2", "$(ALICE_ROOT)/data/field01.dat",2,1.,10.));
70 Revision 1.46 2000/12/14 19:29:27 fca
71 galice.cuts was not read any more
73 Revision 1.45 2000/11/30 07:12:49 alibrary
74 Introducing new Rndm and QA classes
76 Revision 1.44 2000/10/26 13:58:59 morsch
77 Add possibility to choose the lego generator (of type AliGeneratorLego or derived) when running
78 RunLego(). Default is the base class AliGeneratorLego.
80 Revision 1.43 2000/10/09 09:43:17 fca
81 Special remapping of hits for TPC and TRD. End-of-primary action introduced
83 Revision 1.42 2000/10/02 21:28:14 fca
84 Removal of useless dependecies via forward declarations
86 Revision 1.41 2000/07/13 16:19:09 fca
87 Mainly coding conventions + some small bug fixes
89 Revision 1.40 2000/07/12 08:56:25 fca
90 Coding convention correction and warning removal
92 Revision 1.39 2000/07/11 18:24:59 fca
93 Coding convention corrections + few minor bug fixes
95 Revision 1.38 2000/06/20 13:05:45 fca
96 Writing down the TREE headers before job starts
98 Revision 1.37 2000/06/09 20:05:11 morsch
99 Introduce possibility to chose magnetic field version 3: AliMagFDM + field02.dat
101 Revision 1.36 2000/06/08 14:03:58 hristov
102 Only one initializer for a default argument
104 Revision 1.35 2000/06/07 10:13:14 hristov
105 Delete only existent objects.
107 Revision 1.34 2000/05/18 10:45:38 fca
108 Delete Particle Factory properly
110 Revision 1.33 2000/05/16 13:10:40 fca
111 New method IsNewTrack and fix for a problem in Father-Daughter relations
113 Revision 1.32 2000/04/27 10:38:21 fca
114 Correct termination of Lego Run and introduce Lego getter in AliRun
116 Revision 1.31 2000/04/26 10:17:32 fca
117 Changes in Lego for G4 compatibility
119 Revision 1.30 2000/04/18 19:11:40 fca
120 Introduce variable Config.C function signature
122 Revision 1.29 2000/04/07 11:12:34 fca
123 G4 compatibility changes
125 Revision 1.28 2000/04/05 06:51:06 fca
126 Workaround for an HP compiler problem
128 Revision 1.27 2000/03/22 18:08:07 fca
129 Rationalisation of the virtual MC interfaces
131 Revision 1.26 2000/03/22 13:42:26 fca
132 SetGenerator does not replace an existing generator, ResetGenerator does
134 Revision 1.25 2000/02/23 16:25:22 fca
135 AliVMC and AliGeant3 classes introduced
136 ReadEuclid moved from AliRun to AliModule
138 Revision 1.24 2000/01/19 17:17:20 fca
139 Introducing a list of lists of hits -- more hits allowed for detector now
141 Revision 1.23 1999/12/03 11:14:31 fca
142 Fixing previous wrong checking
144 Revision 1.21 1999/11/25 10:40:08 fca
145 Fixing daughters information also in primary tracks
147 Revision 1.20 1999/10/04 18:08:49 fca
148 Adding protection against inconsistent Euclid files
150 Revision 1.19 1999/09/29 07:50:40 fca
151 Introduction of the Copyright and cvs Log
155 ///////////////////////////////////////////////////////////////////////////////
157 // Control class for Alice C++ //
158 // Only one single instance of this class exists. //
159 // The object is created in main program aliroot //
160 // and is pointed by the global gAlice. //
162 // -Supports the list of all Alice Detectors (fModules). //
163 // -Supports the list of particles (fParticles). //
164 // -Supports the Trees. //
165 // -Supports the geometry. //
166 // -Supports the event display. //
169 <img src="picts/AliRunClass.gif">
174 <img src="picts/alirun.gif">
178 ///////////////////////////////////////////////////////////////////////////////
183 #include <iostream.h>
191 #include <TObjectTable.h>
193 #include <TGeometry.h>
195 #include <TBrowser.h>
198 #include "TParticle.h"
200 #include "AliDisplay.h"
203 #include "AliMagFC.h"
204 #include "AliMagFCM.h"
205 #include "AliMagFDM.h"
207 #include "TRandom3.h"
209 #include "AliGenerator.h"
210 #include "AliLegoGenerator.h"
211 #include "AliConfig.h"
212 #include "AliStack.h"
213 #include "AliGenEventHeader.h"
214 #include "AliHeader.h"
216 #include "AliDetector.h"
222 //_____________________________________________________________________________
226 // Default constructor for AliRun
249 fPDGDB = 0; //Particle factory object!
251 fConfigFunction = "\0";
254 fTransParName = "\0";
255 fBaseFileName = ".\0";
259 //_____________________________________________________________________________
260 AliRun::AliRun(const char *name, const char *title)
264 // Constructor for the main processor.
265 // Creates the geometry
266 // Creates the list of Detectors.
267 // Creates the list of particles.
283 fConfigFunction = "Config();";
285 // Set random number generator
286 gRandom = fRandom = new TRandom3();
288 if (gSystem->Getenv("CONFIG_SEED")) {
289 gRandom->SetSeed((UInt_t)atoi(gSystem->Getenv("CONFIG_SEED")));
292 gROOT->GetListOfBrowsables()->Add(this,name);
295 fStack = new AliStack(10000);
296 // create the support list for the various Detectors
297 fModules = new TObjArray(77);
299 // Create the TNode geometry for the event display
301 BuildSimpleGeometry();
303 fHeader = new AliHeader();
309 // Create default mag field
314 // Prepare the tracking medium lists
315 fImedia = new TArrayI(1000);
316 for(i=0;i<1000;i++) (*fImedia)[i]=-99;
319 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
321 AliConfig::Instance()->Add(fPDGDB);
323 // Create HitLists list
324 fHitLists = new TList();
327 fBaseFileName = ".\0";
333 //_____________________________________________________________________________
337 // Default AliRun destructor
362 //_____________________________________________________________________________
363 void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
366 // Add a hit to detector id
368 TObjArray &dets = *fModules;
369 if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits);
372 //_____________________________________________________________________________
373 void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
376 // Add digit to detector id
378 TObjArray &dets = *fModules;
379 if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits);
382 //_____________________________________________________________________________
383 void AliRun::Browse(TBrowser *b)
386 // Called when the item "Run" is clicked on the left pane
387 // of the Root browser.
388 // It displays the Root Trees and all detectors.
390 if(!fStack) fStack=fHeader->Stack();
391 TTree* pTreeK = fStack->TreeK();
393 if (pTreeK) b->Add(pTreeK,pTreeK->GetName());
394 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
395 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
396 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
397 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
398 if (fTreeS) b->Add(fTreeS,fTreeS->GetName());
400 TIter next(fModules);
402 while((detector = (AliModule*)next())) {
403 b->Add(detector,detector->GetName());
405 b->Add(fMCQA,"AliMCQA");
408 //_____________________________________________________________________________
412 // Initialize Alice geometry
417 //_____________________________________________________________________________
418 void AliRun::BuildSimpleGeometry()
421 // Create a simple TNode geometry used by Root display engine
423 // Initialise geometry
425 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
426 new TMaterial("void","Vacuum",0,0,0); //Everything is void
427 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
428 brik->SetVisibility(0);
429 new TNode("alice","alice","S_alice");
432 //_____________________________________________________________________________
433 void AliRun::CleanDetectors()
436 // Clean Detectors at the end of event
438 TIter next(fModules);
440 while((detector = (AliModule*)next())) {
441 detector->FinishEvent();
445 //_____________________________________________________________________________
446 Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
449 // Return the distance from the mouse to the AliRun object
455 //_____________________________________________________________________________
456 void AliRun::DumpPart (Int_t i) const
459 // Dumps particle i in the stack
464 //_____________________________________________________________________________
465 void AliRun::DumpPStack () const
468 // Dumps the particle stack
470 fStack->DumpPStack();
473 //_____________________________________________________________________________
474 void AliRun::SetField(AliMagF* magField)
476 // Set Magnetic Field Map
481 //_____________________________________________________________________________
482 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
483 Float_t maxField, char* filename)
486 // Set magnetic field parameters
487 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
488 // version Magnetic field map version (only 1 active now)
489 // scale Scale factor for the magnetic field
490 // maxField Maximum value for the magnetic field
493 // --- Sanity check on mag field flags
494 if(fField) delete fField;
496 fField = new AliMagFC("Map1"," ",type,scale,maxField);
497 } else if(version<=2) {
498 fField = new AliMagFCM("Map2-3",filename,type,scale,maxField);
500 } else if(version==3) {
501 fField = new AliMagFDM("Map4",filename,type,scale,maxField);
504 Warning("SetField","Invalid map %d\n",version);
508 //_____________________________________________________________________________
509 void AliRun::PreTrack()
511 TObjArray &dets = *fModules;
514 for(Int_t i=0; i<=fNdets; i++)
515 if((module = (AliModule*)dets[i]))
521 //_____________________________________________________________________________
522 void AliRun::PostTrack()
524 TObjArray &dets = *fModules;
527 for(Int_t i=0; i<=fNdets; i++)
528 if((module = (AliModule*)dets[i]))
532 //_____________________________________________________________________________
533 void AliRun::FinishPrimary()
536 // Called at the end of each primary track
539 // static Int_t count=0;
540 // const Int_t times=10;
541 // This primary is finished, purify stack
542 fStack->PurifyKine();
544 TIter next(fModules);
546 while((detector = (AliModule*)next())) {
547 detector->FinishPrimary();
550 // Write out hits if any
551 if (gAlice->TreeH()) {
552 gAlice->TreeH()->Fill();
556 // if(++count%times==1) gObjectTable->Print();
559 //_____________________________________________________________________________
560 void AliRun::BeginPrimary()
563 // Called at the beginning of each primary track
571 //_____________________________________________________________________________
572 void AliRun::FinishEvent()
575 // Called at the end of the event.
579 if(fLego) fLego->FinishEvent();
581 //Update the energy deposit tables
583 for(i=0;i<fEventEnergy.GetSize();i++) {
584 fSummEnergy[i]+=fEventEnergy[i];
585 fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
590 // Update Header information
592 fHeader->SetNprimary(fStack->GetNprimary());
593 fHeader->SetNtrack(fStack->GetNtrack());
596 // Write out the kinematics
597 fStack->FinishEvent();
599 // Write out the event Header information
601 fHeader->SetStack(fStack);
606 // Write Tree headers
607 TTree* pTreeK = fStack->TreeK();
608 if (pTreeK) pTreeK->Write(0,TObject::kOverwrite);
609 if (fTreeH) fTreeH->Write(0,TObject::kOverwrite);
614 //_____________________________________________________________________________
615 void AliRun::FinishRun()
618 // Called at the end of the run.
622 if(fLego) fLego->FinishRun();
624 // Clean detector information
625 TIter next(fModules);
627 while((detector = (AliModule*)next())) {
628 detector->FinishRun();
631 //Output energy summary tables
634 TFile *file = fTreeE->GetCurrentFile();
638 fTreeE->Write(0,TObject::kOverwrite);
640 // Write AliRun info and all detectors parameters
641 Write(0,TObject::kOverwrite);
643 // Clean tree information
648 delete fTreeH; fTreeH = 0;
651 delete fTreeD; fTreeD = 0;
654 delete fTreeR; fTreeR = 0;
657 delete fTreeE; fTreeE = 0;
660 delete fTreeS; fTreeS = 0;
667 //_____________________________________________________________________________
668 void AliRun::FlagTrack(Int_t track)
672 fStack->FlagTrack(track);
675 //_____________________________________________________________________________
676 void AliRun::EnergySummary()
679 // Print summary of deposited energy
685 Int_t kn, i, left, j, id;
686 const Float_t kzero=0;
687 Int_t ievent=fHeader->GetEvent()+1;
689 // Energy loss information
691 printf("***************** Energy Loss Information per event (GEV) *****************\n");
692 for(kn=1;kn<fEventEnergy.GetSize();kn++) {
695 fEventEnergy[ndep]=kn;
700 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,kzero))/ed;
703 fSummEnergy[ndep]=ed;
704 fSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,kzero));
709 for(kn=0;kn<(ndep-1)/3+1;kn++) {
711 for(i=0;i<(3<left?3:left);i++) {
713 id=Int_t (fEventEnergy[j]+0.1);
714 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]);
719 // Relative energy loss in different detectors
720 printf("******************** Relative Energy Loss per event ********************\n");
721 printf("Total energy loss per event %10.3f GeV\n",edtot);
722 for(kn=0;kn<(ndep-1)/5+1;kn++) {
724 for(i=0;i<(5<left?5:left);i++) {
726 id=Int_t (fEventEnergy[j]+0.1);
727 printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot);
731 for(kn=0;kn<75;kn++) printf("*");
735 // Reset the TArray's
736 // fEventEnergy.Set(0);
737 // fSummEnergy.Set(0);
738 // fSum2Energy.Set(0);
741 //_____________________________________________________________________________
742 AliModule *AliRun::GetModule(const char *name) const
745 // Return pointer to detector from name
747 return (AliModule*)fModules->FindObject(name);
750 //_____________________________________________________________________________
751 AliDetector *AliRun::GetDetector(const char *name) const
754 // Return pointer to detector from name
756 return (AliDetector*)fModules->FindObject(name);
759 //_____________________________________________________________________________
760 Int_t AliRun::GetModuleID(const char *name) const
763 // Return galice internal detector identifier from name
766 TObject *mod=fModules->FindObject(name);
767 if(mod) i=fModules->IndexOf(mod);
771 //_____________________________________________________________________________
772 Int_t AliRun::GetEvent(Int_t event)
775 // Connect the Trees Kinematics and Hits for event # event
776 // Set branch addresses
779 // Reset existing structures
784 // Delete Trees already connected
785 if (fTreeH) delete fTreeH;
786 if (fTreeD) delete fTreeD;
787 if (fTreeR) delete fTreeR;
788 if (fTreeS) delete fTreeS;
790 // Create the particle stack
791 if (fHeader) delete fHeader;
794 // Get header from file
796 fTreeE->SetBranchAddress("Header", &fHeader);
797 fTreeE->GetEntry(event);
800 Error("GetEvent","Cannot find Header Tree (TE)\n");
802 // Get the stack from the header
803 if (fStack) delete fStack;
804 fStack = fHeader->Stack();
805 fStack->GetEvent(event);
807 TFile *file = fTreeE->GetCurrentFile();
811 // Get Hits Tree header from file
812 sprintf(treeName,"TreeH%d",event);
813 fTreeH = (TTree*)gDirectory->Get(treeName);
815 Error("GetEvent","cannot find Hits Tree for event:%d\n",event);
818 // Get Digits Tree header from file
819 sprintf(treeName,"TreeD%d",event);
820 fTreeD = (TTree*)gDirectory->Get(treeName);
822 // Warning("GetEvent","cannot find Digits Tree for event:%d\n",event);
827 // Get SDigits Tree header from file
828 sprintf(treeName,"TreeS%d",event);
829 fTreeS = (TTree*)gDirectory->Get(treeName);
831 // Warning("GetEvent","cannot find SDigits Tree for event:%d\n",event);
836 // Get Reconstruct Tree header from file
837 sprintf(treeName,"TreeR%d",event);
838 fTreeR = (TTree*)gDirectory->Get(treeName);
840 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
845 // Set Trees branch addresses
846 TIter next(fModules);
848 while((detector = (AliModule*)next())) {
849 detector->SetTreeAddress();
852 return fStack->GetNtrack();
855 //_____________________________________________________________________________
856 TGeometry *AliRun::GetGeometry()
859 // Import Alice geometry from current file
860 // Return pointer to geometry object
862 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
864 // Unlink and relink nodes in detectors
865 // This is bad and there must be a better way...
868 TIter next(fModules);
870 while((detector = (AliModule*)next())) {
871 TList *dnodes=detector->Nodes();
874 for ( j=0; j<dnodes->GetSize(); j++) {
875 node = (TNode*) dnodes->At(j);
876 node1 = fGeometry->GetNode(node->GetName());
877 dnodes->Remove(node);
878 dnodes->AddAt(node1,j);
884 //_____________________________________________________________________________
885 void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
886 Float_t &e, Float_t *vpos, Float_t *polar,
891 fStack->GetNextTrack(mtrack, ipart, pmom, e, vpos, polar, tof);
894 //_____________________________________________________________________________
895 Int_t AliRun::GetPrimary(Int_t track) const
898 // return number of primary that has generated track
900 return fStack->GetPrimary(track);
903 //_____________________________________________________________________________
904 void AliRun::InitMC(const char *setup)
907 // Initialize the Alice setup
911 Warning("Init","Cannot initialise AliRun twice!\n");
915 gROOT->LoadMacro(setup);
916 gInterpreter->ProcessLine(fConfigFunction.Data());
919 gMC->DefineParticles(); //Create standard MC particles
921 TObject *objfirst, *objlast;
923 fNdets = fModules->GetLast()+1;
926 //=================Create Materials and geometry
929 // Added also after in case of interactive initialisation of modules
930 fNdets = fModules->GetLast()+1;
932 TIter next(fModules);
934 while((detector = (AliModule*)next())) {
935 detector->SetTreeAddress();
936 objlast = gDirectory->GetList()->Last();
938 // Add Detector histograms in Detector list of histograms
939 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
940 else objfirst = gDirectory->GetList()->First();
942 detector->Histograms()->Add(objfirst);
943 objfirst = gDirectory->GetList()->After(objfirst);
946 ReadTransPar(); //Read the cuts for all materials
948 MediaTable(); //Build the special IMEDIA table
950 //Initialise geometry deposition table
951 fEventEnergy.Set(gMC->NofVolumes()+1);
952 fSummEnergy.Set(gMC->NofVolumes()+1);
953 fSum2Energy.Set(gMC->NofVolumes()+1);
955 //Compute cross-sections
958 //Write Geometry object to current file.
963 fMCQA = new AliMCQA(fNdets);
966 // Save stuff at the beginning of the file to avoid file corruption
970 //_____________________________________________________________________________
971 void AliRun::MediaTable()
974 // Built media table to get from the media number to
977 Int_t kz, nz, idt, lz, i, k, ind;
979 TObjArray &dets = *gAlice->Detectors();
983 for (kz=0;kz<fNdets;kz++) {
984 // If detector is defined
985 if((det=(AliModule*) dets[kz])) {
986 TArrayI &idtmed = *(det->GetIdtmed());
987 for(nz=0;nz<100;nz++) {
988 // Find max and min material number
989 if((idt=idtmed[nz])) {
990 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
991 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
994 if(det->LoMedium() > det->HiMedium()) {
998 if(det->HiMedium() > fImedia->GetSize()) {
999 Error("MediaTable","Increase fImedia from %d to %d",
1000 fImedia->GetSize(),det->HiMedium());
1003 // Tag all materials in rage as belonging to detector kz
1004 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
1011 // Print summary table
1012 printf(" Traking media ranges:\n");
1013 for(i=0;i<(fNdets-1)/6+1;i++) {
1014 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
1016 det=(AliModule*)dets[ind];
1018 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
1021 printf(" %6s: %3d -> %3d;","NULL",0,0);
1027 //____________________________________________________________________________
1028 void AliRun::SetGenerator(AliGenerator *generator)
1031 // Load the event generator
1033 if(!fGenerator) fGenerator = generator;
1036 //____________________________________________________________________________
1037 void AliRun::ResetGenerator(AliGenerator *generator)
1040 // Load the event generator
1044 Warning("ResetGenerator","Replacing generator %s with %s\n",
1045 fGenerator->GetName(),generator->GetName());
1047 Warning("ResetGenerator","Replacing generator %s with NULL\n",
1048 fGenerator->GetName());
1049 fGenerator = generator;
1052 //____________________________________________________________________________
1053 void AliRun::SetTransPar(char *filename)
1055 fTransParName = filename;
1058 //____________________________________________________________________________
1059 void AliRun::SetBaseFile(char *filename)
1061 fBaseFileName = filename;
1064 //____________________________________________________________________________
1065 void AliRun::ReadTransPar()
1068 // Read filename to set the transport parameters
1072 const Int_t kncuts=10;
1073 const Int_t knflags=11;
1074 const Int_t knpars=kncuts+knflags;
1075 const char kpars[knpars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
1076 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
1077 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
1078 "MULS","PAIR","PHOT","RAYL"};
1082 Float_t cut[kncuts];
1083 Int_t flag[knflags];
1084 Int_t i, itmed, iret, ktmed, kz;
1087 // See whether the file is there
1088 filtmp=gSystem->ExpandPathName(fTransParName.Data());
1089 lun=fopen(filtmp,"r");
1092 Warning("ReadTransPar","File %s does not exist!\n",fTransParName.Data());
1097 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1098 printf(" *%59s\n","*");
1099 printf(" * Please check carefully what you are doing!%10s\n","*");
1100 printf(" *%59s\n","*");
1104 // Initialise cuts and flags
1105 for(i=0;i<kncuts;i++) cut[i]=-99;
1106 for(i=0;i<knflags;i++) flag[i]=-99;
1108 for(i=0;i<256;i++) line[i]='\0';
1109 // Read up to the end of line excluded
1110 iret=fscanf(lun,"%[^\n]",line);
1115 printf(" *%59s\n","*");
1116 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1120 // Read the end of line
1123 if(line[0]=='*') continue;
1125 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",
1126 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
1127 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
1128 &flag[8],&flag[9],&flag[10]);
1132 Warning("ReadTransPar","Error reading file %s\n",fTransParName.Data());
1135 // Check that the module exist
1136 AliModule *mod = GetModule(detName);
1138 // Get the array of media numbers
1139 TArrayI &idtmed = *mod->GetIdtmed();
1140 // Check that the tracking medium code is valid
1141 if(0<=itmed && itmed < 100) {
1142 ktmed=idtmed[itmed];
1144 Warning("ReadTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
1147 // Set energy thresholds
1148 for(kz=0;kz<kncuts;kz++) {
1150 if(fDebug) printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
1151 kpars[kz],cut[kz],itmed,mod->GetName());
1152 gMC->Gstpar(ktmed,kpars[kz],cut[kz]);
1155 // Set transport mechanisms
1156 for(kz=0;kz<knflags;kz++) {
1158 if(fDebug) printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
1159 kpars[kncuts+kz],flag[kz],itmed,mod->GetName());
1160 gMC->Gstpar(ktmed,kpars[kncuts+kz],Float_t(flag[kz]));
1164 Warning("ReadTransPar","Invalid medium code %d *\n",itmed);
1168 if(fDebug) printf("%s::ReadTransParModule: %s not present\n",ClassName(),detName);
1175 //_____________________________________________________________________________
1176 void AliRun::MakeTree(Option_t *option, const char *file)
1179 // Create the ROOT trees
1180 // Loop on all detectors to create the Root branch (if any)
1186 const char *oK = strstr(option,"K");
1187 const char *oH = strstr(option,"H");
1188 const char *oE = strstr(option,"E");
1189 const char *oD = strstr(option,"D");
1190 const char *oR = strstr(option,"R");
1191 const char *oS = strstr(option,"S");
1194 TDirectory *cwd = gDirectory;
1196 TBranch *branch = 0;
1198 if (oK) fStack->MakeTree(fEvent, file);
1200 if (oE && !fTreeE) {
1201 fTreeE = new TTree("TE","Header");
1202 branch = fTreeE->Branch("Header", "AliHeader", &fHeader, 4000, 0);
1203 branch->SetAutoDelete(kFALSE);
1204 TFolder *folder = (TFolder *)gROOT->FindObjectAny("/Folders/RunMC/Event/Header");
1205 if (folder) folder->Add(fHeader);
1206 // branch = fTreeE->Branch("Stack","AliStack", &fStack, 4000, 0);
1207 // branch->SetAutoDelete(kFALSE);
1208 // if (folder) folder->Add(fStack);
1209 fTreeE->Write(0,TObject::kOverwrite);
1212 if (file && branch) {
1213 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
1214 sprintf(outFile,"%s/%s",GetBaseFile(),file);
1215 branch->SetFile(outFile);
1216 TIter next( branch->GetListOfBranches());
1217 while ((branch=(TBranch*)next())) {
1218 branch->SetFile(outFile);
1221 printf("* MakeBranch * Diverting Branch %s to file %s\n", branch->GetName(),file);
1226 if (oH && !fTreeH) {
1227 sprintf(hname,"TreeH%d",fEvent);
1228 fTreeH = new TTree(hname,"Hits");
1229 fTreeH->SetAutoSave(1000000000); //no autosave
1230 fTreeH->Write(0,TObject::kOverwrite);
1232 if (oD && !fTreeD) {
1233 sprintf(hname,"TreeD%d",fEvent);
1234 fTreeD = new TTree(hname,"Digits");
1235 fTreeD->Write(0,TObject::kOverwrite);
1237 if (oS && !fTreeS) {
1238 sprintf(hname,"TreeS%d",fEvent);
1239 fTreeS = new TTree(hname,"SDigits");
1240 fTreeS->Write(0,TObject::kOverwrite);
1242 if (oR && !fTreeR) {
1243 sprintf(hname,"TreeR%d",fEvent);
1244 fTreeR = new TTree(hname,"Reconstruction");
1245 fTreeR->Write(0,TObject::kOverwrite);
1249 // Create a branch for hits/digits for each detector
1250 // Each branch is a TClonesArray. Each data member of the Hits classes
1251 // will be in turn a subbranch of the detector master branch
1252 TIter next(fModules);
1253 AliModule *detector;
1254 while((detector = (AliModule*)next())) {
1255 if (oH) detector->MakeBranch(option,file);
1259 //_____________________________________________________________________________
1260 inline TParticle* AliRun::Particle(Int_t i)
1262 return fStack->Particle(i);
1265 //_____________________________________________________________________________
1266 void AliRun::BeginEvent()
1268 // Clean-up previous event
1270 fEventEnergy.Reset();
1271 // Clean detector information
1278 // Reset all Detectors & kinematics & trees
1282 // Initialise event header
1283 fHeader->Reset(fRun,fEvent);
1285 fStack->BeginEvent(fEvent);
1289 fLego->BeginEvent();
1302 sprintf(hname,"TreeH%d",fEvent);
1303 fTreeH->SetName(hname);
1307 sprintf(hname,"TreeD%d",fEvent);
1308 fTreeD->SetName(hname);
1309 fTreeD->Write(0,TObject::kOverwrite);
1313 sprintf(hname,"TreeS%d",fEvent);
1314 fTreeS->SetName(hname);
1315 fTreeS->Write(0,TObject::kOverwrite);
1319 sprintf(hname,"TreeR%d",fEvent);
1320 fTreeR->SetName(hname);
1321 fTreeR->Write(0,TObject::kOverwrite);
1324 //_____________________________________________________________________________
1325 void AliRun::ResetDigits()
1328 // Reset all Detectors digits
1330 TIter next(fModules);
1331 AliModule *detector;
1332 while((detector = (AliModule*)next())) {
1333 detector->ResetDigits();
1337 //_____________________________________________________________________________
1338 void AliRun::ResetSDigits()
1341 // Reset all Detectors digits
1343 TIter next(fModules);
1344 AliModule *detector;
1345 while((detector = (AliModule*)next())) {
1346 detector->ResetSDigits();
1350 //_____________________________________________________________________________
1351 void AliRun::ResetHits()
1354 // Reset all Detectors hits
1356 TIter next(fModules);
1357 AliModule *detector;
1358 while((detector = (AliModule*)next())) {
1359 detector->ResetHits();
1363 //_____________________________________________________________________________
1364 void AliRun::ResetPoints()
1367 // Reset all Detectors points
1369 TIter next(fModules);
1370 AliModule *detector;
1371 while((detector = (AliModule*)next())) {
1372 detector->ResetPoints();
1376 //_____________________________________________________________________________
1377 void AliRun::RunMC(Int_t nevent, const char *setup)
1380 // Main function to be called to process a galice run
1382 // Root > gAlice.Run();
1383 // a positive number of events will cause the finish routine
1387 // check if initialisation has been done
1388 if (!fInitDone) InitMC(setup);
1390 // Create the Root Tree with one branch per detector
1394 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1395 MakeTree("K","Kine.root");
1396 MakeTree("H","Hits.root");
1401 gMC->ProcessRun(nevent);
1403 // End of this run, close files
1404 if(nevent>0) FinishRun();
1407 //_____________________________________________________________________________
1408 void AliRun::RunReco(const char *selected)
1411 // Main function to be called to reconstruct Alice event
1413 for (Int_t nevent=0; nevent<gAlice->TreeE()->GetEntries(); nevent++) {
1416 Digits2Reco(selected);
1420 //_____________________________________________________________________________
1422 void AliRun::Hits2Digits(const char *selected)
1425 // Convert Hits to sumable digits
1427 for (Int_t nevent=0; nevent<gAlice->TreeE()->GetEntries(); nevent++) {
1430 Hits2SDigits(selected);
1431 SDigits2Digits(selected);
1436 //_____________________________________________________________________________
1438 void AliRun::Tree2Tree(Option_t *option, const char *selected)
1441 // Function to transform the content of
1443 // - TreeH to TreeS (option "S")
1444 // - TreeS to TreeD (option "D")
1445 // - TreeD to TreeR (option "R")
1447 // If multiple options are specified ("SDR"), transformation will be done in sequence for
1448 // selected detector and for all detectors if none is selected (detector string
1449 // can contain blank separated list of detector names).
1452 const char *oS = strstr(option,"S");
1453 const char *oD = strstr(option,"D");
1454 const char *oR = strstr(option,"R");
1456 TObjArray *detectors = Detectors();
1458 TIter next(detectors);
1460 AliDetector *detector = 0;
1462 TDirectory *cwd = gDirectory;
1466 while((detector = (AliDetector*)next())) {
1468 if (strcmp(detector->GetName(),selected)) continue;
1469 if (detector->IsActive()){
1470 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1472 sprintf(outFile,"SDigits.%s.root",detector->GetName());
1473 detector->MakeBranch("S",outFile);
1476 sprintf(outFile,"Digits.%s.root",detector->GetName());
1477 detector->MakeBranch("D",outFile);
1480 sprintf(outFile,"Reco.%s.root",detector->GetName());
1481 detector->MakeBranch("R",outFile);
1484 detector->MakeBranch(option);
1490 cout << "Hits2SDigits: Processing " << detector->GetName() << "..." << endl;
1491 detector->Hits2SDigits();
1494 cout << "SDigits2Digits: Processing " << detector->GetName() << "..." << endl;
1495 detector->SDigits2Digits();
1498 cout << "Digits2Reco: Processing " << detector->GetName() << "..." << endl;
1499 detector->Digits2Reco();
1508 //_____________________________________________________________________________
1509 void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min,
1510 Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max,
1511 Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener)
1514 // Generates lego plots of:
1515 // - radiation length map phi vs theta
1516 // - radiation length map phi vs eta
1517 // - interaction length map
1518 // - g/cm2 length map
1520 // ntheta bins in theta, eta
1521 // themin minimum angle in theta (degrees)
1522 // themax maximum angle in theta (degrees)
1524 // phimin minimum angle in phi (degrees)
1525 // phimax maximum angle in phi (degrees)
1526 // rmin minimum radius
1527 // rmax maximum radius
1530 // The number of events generated = ntheta*nphi
1531 // run input parameters in macro setup (default="Config.C")
1533 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1536 <img src="picts/AliRunLego1.gif">
1541 <img src="picts/AliRunLego2.gif">
1546 <img src="picts/AliRunLego3.gif">
1551 // check if initialisation has been done
1552 if (!fInitDone) InitMC(setup);
1553 //Save current generator
1554 AliGenerator *gen=Generator();
1556 // Set new generator
1557 if (!gener) gener = new AliLegoGenerator();
1558 ResetGenerator(gener);
1560 // Configure Generator
1561 gener->SetRadiusRange(rmin, rmax);
1562 gener->SetZMax(zmax);
1563 gener->SetCoor1Range(nc1, c1min, c1max);
1564 gener->SetCoor2Range(nc2, c2min, c2max);
1567 //Create Lego object
1568 fLego = new AliLego("lego",gener);
1570 //Prepare MC for Lego Run
1575 gMC->ProcessRun(nc1*nc2+1);
1577 // Create only the Root event Tree
1580 // End of this run, close files
1582 // Restore current generator
1583 ResetGenerator(gen);
1584 // Delete Lego Object
1585 delete fLego; fLego=0;
1588 //_____________________________________________________________________________
1589 void AliRun::SetConfigFunction(const char * config)
1592 // Set the signature of the function contained in Config.C to configure
1595 fConfigFunction=config;
1598 //_____________________________________________________________________________
1599 void AliRun::SetCurrentTrack(Int_t track)
1602 // Set current track number
1604 fStack->SetCurrentTrack(track);
1607 //_____________________________________________________________________________
1608 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1609 Float_t *vpos, Float_t *polar, Float_t tof,
1610 AliMCProcess mech, Int_t &ntr, Float_t weight)
1612 // Delegate to stack
1614 fStack->SetTrack(done, parent, pdg, pmom, vpos, polar, tof,
1618 //_____________________________________________________________________________
1619 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg,
1620 Double_t px, Double_t py, Double_t pz, Double_t e,
1621 Double_t vx, Double_t vy, Double_t vz, Double_t tof,
1622 Double_t polx, Double_t poly, Double_t polz,
1623 AliMCProcess mech, Int_t &ntr, Float_t weight)
1625 // Delegate to stack
1627 fStack->SetTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
1628 polx, poly, polz, mech, ntr, weight);
1632 //_____________________________________________________________________________
1633 void AliRun::SetHighWaterMark(const Int_t nt)
1636 // Set high water mark for last track in event
1637 fStack->SetHighWaterMark(nt);
1640 //_____________________________________________________________________________
1641 void AliRun::KeepTrack(const Int_t track)
1644 // Delegate to stack
1646 fStack->KeepTrack(track);
1649 //_____________________________________________________________________________
1650 void AliRun::StepManager(Int_t id)
1653 // Called at every step during transport
1657 // --- If lego option, do it and leave
1659 fLego->StepManager();
1662 //Update energy deposition tables
1663 AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
1665 //Call the appropriate stepping routine;
1666 AliModule *det = (AliModule*)fModules->At(id);
1668 fMCQA->StepManager(id);
1674 //_____________________________________________________________________________
1675 void AliRun::Streamer(TBuffer &R__b)
1677 // Stream an object of class AliRun.
1679 if (R__b.IsReading()) {
1680 if (!gAlice) gAlice = this;
1682 AliRun::Class()->ReadBuffer(R__b, this);
1684 gROOT->GetListOfBrowsables()->Add(this,"Run");
1686 fTreeE = (TTree*)gDirectory->Get("TE");
1688 fTreeE->SetBranchAddress("Header", &fHeader);
1691 else Error("Streamer","cannot find Header Tree\n");
1692 fTreeE->GetEntry(0);
1696 AliRun::Class()->WriteBuffer(R__b, this);
1701 //___________________________________________________________________________
1702 Int_t AliRun::CurrentTrack() const {
1704 // Returns current track
1706 return fStack->CurrentTrack();
1709 //___________________________________________________________________________
1710 Int_t AliRun::GetNtrack() const {
1712 // Returns number of tracks in stack
1714 return fStack->GetNtrack();
1717 //___________________________________________________________________________
1718 TObjArray* AliRun::Particles() {
1720 // Returns pointer to Particles array
1722 return fStack->Particles();
1725 //___________________________________________________________________________
1726 TTree* AliRun::TreeK() {
1728 // Returns pointer to the TreeK array
1730 return fStack->TreeK();