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.75 2001/07/28 10:52:27 hristov
19 Event number updated correctly (M.Ivanov)
21 Revision 1.74 2001/07/28 10:39:16 morsch
22 GetEventsPerRun() method needed by afterburners added to AliRun.h
23 Corresponding setters and getters have been from AliGenerator.
25 Revision 1.73 2001/07/27 12:34:30 jchudoba
26 remove the dummy argument in fStack->GetEvent call
28 Revision 1.72 2001/07/03 08:10:57 hristov
29 J.Chudoba's changes merged correctly with the HEAD
31 Revision 1.70 2001/06/29 08:01:36 morsch
32 Small correction to the previous.
34 Revision 1.69 2001/06/28 16:27:50 morsch
35 AliReco() with user control of event range.
37 Revision 1.68 2001/06/11 13:14:40 morsch
38 SetAliGenEventHeader() method added.
40 Revision 1.67 2001/06/07 18:24:50 buncic
41 Removed compilation warning in AliConfig initialisation.
43 Revision 1.66 2001/05/22 14:32:40 hristov
46 Revision 1.65 2001/05/21 17:22:51 buncic
47 Fixed problem with missing AliConfig while reading galice.root
49 Revision 1.64 2001/05/16 14:57:22 alibrary
50 New files for folders and Stack
52 Revision 1.62 2001/04/06 11:12:33 morsch
53 Clear fParticles after each event. (Ivana Hrivnacova)
55 Revision 1.61 2001/03/30 07:04:10 morsch
56 Call fGenerator->FinishRun() for final print-outs, cross-section and weight calculations.
58 Revision 1.60 2001/03/21 18:22:30 hristov
59 fParticleFileMap fix (I.Hrivnacova)
61 Revision 1.59 2001/03/12 17:47:03 hristov
62 Changes needed on Sun with CC 5.0
64 Revision 1.58 2001/03/09 14:27:26 morsch
65 Fix for multiple events per file: inhibit decrease of size of fParticleFileMap.
67 Revision 1.57 2001/02/23 17:40:23 buncic
68 All trees needed for simulation created in RunMC(). TreeR and its branches
69 are now created in new RunReco() method.
71 Revision 1.56 2001/02/14 15:45:20 hristov
72 Algorithmic way of getting entry index in fParticleMap. Protection of fParticleFileMap (I.Hrivnacova)
74 Revision 1.55 2001/02/12 15:52:54 buncic
75 Removed OpenBaseFile().
77 Revision 1.54 2001/02/07 10:39:05 hristov
78 Remove default value for argument
80 Revision 1.53 2001/02/06 11:02:26 hristov
81 New SetTrack interface added, added check for unfilled particles in FinishEvent (I.Hrivnacova)
83 Revision 1.52 2001/02/05 16:22:25 buncic
84 Added TreeS to GetEvent().
86 Revision 1.51 2001/02/02 15:16:20 morsch
87 SetHighWaterMark method added to mark last particle in event.
89 Revision 1.50 2001/01/27 10:32:00 hristov
90 Leave the loop when primaries are filled (I.Hrivnacova)
92 Revision 1.49 2001/01/26 19:58:48 hristov
93 Major upgrade of AliRoot code
95 Revision 1.48 2001/01/17 10:50:50 hristov
96 Corrections to destructors
98 Revision 1.47 2000/12/18 10:44:01 morsch
99 Possibility to set field map by passing pointer to objet of type AliMagF via
102 gAlice->SetField(new AliMagFCM("Map2", "$(ALICE_ROOT)/data/field01.dat",2,1.,10.));
104 Revision 1.46 2000/12/14 19:29:27 fca
105 galice.cuts was not read any more
107 Revision 1.45 2000/11/30 07:12:49 alibrary
108 Introducing new Rndm and QA classes
110 Revision 1.44 2000/10/26 13:58:59 morsch
111 Add possibility to choose the lego generator (of type AliGeneratorLego or derived) when running
112 RunLego(). Default is the base class AliGeneratorLego.
114 Revision 1.43 2000/10/09 09:43:17 fca
115 Special remapping of hits for TPC and TRD. End-of-primary action introduced
117 Revision 1.42 2000/10/02 21:28:14 fca
118 Removal of useless dependecies via forward declarations
120 Revision 1.41 2000/07/13 16:19:09 fca
121 Mainly coding conventions + some small bug fixes
123 Revision 1.40 2000/07/12 08:56:25 fca
124 Coding convention correction and warning removal
126 Revision 1.39 2000/07/11 18:24:59 fca
127 Coding convention corrections + few minor bug fixes
129 Revision 1.38 2000/06/20 13:05:45 fca
130 Writing down the TREE headers before job starts
132 Revision 1.37 2000/06/09 20:05:11 morsch
133 Introduce possibility to chose magnetic field version 3: AliMagFDM + field02.dat
135 Revision 1.36 2000/06/08 14:03:58 hristov
136 Only one initializer for a default argument
138 Revision 1.35 2000/06/07 10:13:14 hristov
139 Delete only existent objects.
141 Revision 1.34 2000/05/18 10:45:38 fca
142 Delete Particle Factory properly
144 Revision 1.33 2000/05/16 13:10:40 fca
145 New method IsNewTrack and fix for a problem in Father-Daughter relations
147 Revision 1.32 2000/04/27 10:38:21 fca
148 Correct termination of Lego Run and introduce Lego getter in AliRun
150 Revision 1.31 2000/04/26 10:17:32 fca
151 Changes in Lego for G4 compatibility
153 Revision 1.30 2000/04/18 19:11:40 fca
154 Introduce variable Config.C function signature
156 Revision 1.29 2000/04/07 11:12:34 fca
157 G4 compatibility changes
159 Revision 1.28 2000/04/05 06:51:06 fca
160 Workaround for an HP compiler problem
162 Revision 1.27 2000/03/22 18:08:07 fca
163 Rationalisation of the virtual MC interfaces
165 Revision 1.26 2000/03/22 13:42:26 fca
166 SetGenerator does not replace an existing generator, ResetGenerator does
168 Revision 1.25 2000/02/23 16:25:22 fca
169 AliVMC and AliGeant3 classes introduced
170 ReadEuclid moved from AliRun to AliModule
172 Revision 1.24 2000/01/19 17:17:20 fca
173 Introducing a list of lists of hits -- more hits allowed for detector now
175 Revision 1.23 1999/12/03 11:14:31 fca
176 Fixing previous wrong checking
178 Revision 1.21 1999/11/25 10:40:08 fca
179 Fixing daughters information also in primary tracks
181 Revision 1.20 1999/10/04 18:08:49 fca
182 Adding protection against inconsistent Euclid files
184 Revision 1.19 1999/09/29 07:50:40 fca
185 Introduction of the Copyright and cvs Log
189 ///////////////////////////////////////////////////////////////////////////////
191 // Control class for Alice C++ //
192 // Only one single instance of this class exists. //
193 // The object is created in main program aliroot //
194 // and is pointed by the global gAlice. //
196 // -Supports the list of all Alice Detectors (fModules). //
197 // -Supports the list of particles (fParticles). //
198 // -Supports the Trees. //
199 // -Supports the geometry. //
200 // -Supports the event display. //
203 <img src="picts/AliRunClass.gif">
208 <img src="picts/alirun.gif">
212 ///////////////////////////////////////////////////////////////////////////////
217 #include <iostream.h>
224 #include <TObjectTable.h>
226 #include <TGeometry.h>
228 #include <TBrowser.h>
231 #include "TParticle.h"
233 #include "AliDisplay.h"
236 #include "AliMagFC.h"
237 #include "AliMagFCM.h"
238 #include "AliMagFDM.h"
240 #include "TRandom3.h"
242 #include "AliGenerator.h"
243 #include "AliLegoGenerator.h"
244 #include "AliConfig.h"
245 #include "AliStack.h"
246 #include "AliGenEventHeader.h"
247 #include "AliHeader.h"
249 #include "AliDetector.h"
255 //_____________________________________________________________________________
259 // Default constructor for AliRun
282 fPDGDB = 0; //Particle factory object!
284 fConfigFunction = "\0";
287 fTransParName = "\0";
288 fBaseFileName = ".\0";
292 //_____________________________________________________________________________
293 AliRun::AliRun(const char *name, const char *title)
297 // Constructor for the main processor.
298 // Creates the geometry
299 // Creates the list of Detectors.
300 // Creates the list of particles.
316 fConfigFunction = "Config();";
318 // Set random number generator
319 gRandom = fRandom = new TRandom3();
321 if (gSystem->Getenv("CONFIG_SEED")) {
322 gRandom->SetSeed((UInt_t)atoi(gSystem->Getenv("CONFIG_SEED")));
325 gROOT->GetListOfBrowsables()->Add(this,name);
328 fStack = new AliStack(10000);
329 // create the support list for the various Detectors
330 fModules = new TObjArray(77);
332 // Create the TNode geometry for the event display
334 BuildSimpleGeometry();
336 fHeader = new AliHeader();
342 // Create default mag field
347 // Prepare the tracking medium lists
348 fImedia = new TArrayI(1000);
349 for(i=0;i<1000;i++) (*fImedia)[i]=-99;
352 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
354 AliConfig::Instance()->Add(fPDGDB);
356 // Create HitLists list
357 fHitLists = new TList();
360 fBaseFileName = ".\0";
366 //_____________________________________________________________________________
370 // Default AliRun destructor
395 //_____________________________________________________________________________
396 void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
399 // Add a hit to detector id
401 TObjArray &dets = *fModules;
402 if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits);
405 //_____________________________________________________________________________
406 void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
409 // Add digit to detector id
411 TObjArray &dets = *fModules;
412 if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits);
415 //_____________________________________________________________________________
416 void AliRun::Browse(TBrowser *b)
419 // Called when the item "Run" is clicked on the left pane
420 // of the Root browser.
421 // It displays the Root Trees and all detectors.
423 if(!fStack) fStack=fHeader->Stack();
424 TTree* pTreeK = fStack->TreeK();
426 if (pTreeK) b->Add(pTreeK,pTreeK->GetName());
427 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
428 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
429 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
430 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
431 if (fTreeS) b->Add(fTreeS,fTreeS->GetName());
433 TIter next(fModules);
435 while((detector = (AliModule*)next())) {
436 b->Add(detector,detector->GetName());
438 b->Add(fMCQA,"AliMCQA");
441 //_____________________________________________________________________________
445 // Initialize Alice geometry
450 //_____________________________________________________________________________
451 void AliRun::BuildSimpleGeometry()
454 // Create a simple TNode geometry used by Root display engine
456 // Initialise geometry
458 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
459 new TMaterial("void","Vacuum",0,0,0); //Everything is void
460 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
461 brik->SetVisibility(0);
462 new TNode("alice","alice","S_alice");
465 //_____________________________________________________________________________
466 void AliRun::CleanDetectors()
469 // Clean Detectors at the end of event
471 TIter next(fModules);
473 while((detector = (AliModule*)next())) {
474 detector->FinishEvent();
478 //_____________________________________________________________________________
479 Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
482 // Return the distance from the mouse to the AliRun object
488 //_____________________________________________________________________________
489 void AliRun::DumpPart (Int_t i) const
492 // Dumps particle i in the stack
497 //_____________________________________________________________________________
498 void AliRun::DumpPStack () const
501 // Dumps the particle stack
503 fStack->DumpPStack();
506 //_____________________________________________________________________________
507 void AliRun::SetField(AliMagF* magField)
509 // Set Magnetic Field Map
514 //_____________________________________________________________________________
515 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
516 Float_t maxField, char* filename)
519 // Set magnetic field parameters
520 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
521 // version Magnetic field map version (only 1 active now)
522 // scale Scale factor for the magnetic field
523 // maxField Maximum value for the magnetic field
526 // --- Sanity check on mag field flags
527 if(fField) delete fField;
529 fField = new AliMagFC("Map1"," ",type,scale,maxField);
530 } else if(version<=2) {
531 fField = new AliMagFCM("Map2-3",filename,type,scale,maxField);
533 } else if(version==3) {
534 fField = new AliMagFDM("Map4",filename,type,scale,maxField);
537 Warning("SetField","Invalid map %d\n",version);
541 //_____________________________________________________________________________
542 void AliRun::PreTrack()
544 TObjArray &dets = *fModules;
547 for(Int_t i=0; i<=fNdets; i++)
548 if((module = (AliModule*)dets[i]))
554 //_____________________________________________________________________________
555 void AliRun::PostTrack()
557 TObjArray &dets = *fModules;
560 for(Int_t i=0; i<=fNdets; i++)
561 if((module = (AliModule*)dets[i]))
565 //_____________________________________________________________________________
566 void AliRun::FinishPrimary()
569 // Called at the end of each primary track
572 // static Int_t count=0;
573 // const Int_t times=10;
574 // This primary is finished, purify stack
575 fStack->PurifyKine();
577 TIter next(fModules);
579 while((detector = (AliModule*)next())) {
580 detector->FinishPrimary();
583 // Write out hits if any
584 if (gAlice->TreeH()) {
585 gAlice->TreeH()->Fill();
589 // if(++count%times==1) gObjectTable->Print();
592 //_____________________________________________________________________________
593 void AliRun::BeginPrimary()
596 // Called at the beginning of each primary track
604 //_____________________________________________________________________________
605 void AliRun::FinishEvent()
608 // Called at the end of the event.
612 if(fLego) fLego->FinishEvent();
614 //Update the energy deposit tables
616 for(i=0;i<fEventEnergy.GetSize();i++) {
617 fSummEnergy[i]+=fEventEnergy[i];
618 fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
623 // Update Header information
625 fHeader->SetNprimary(fStack->GetNprimary());
626 fHeader->SetNtrack(fStack->GetNtrack());
629 // Write out the kinematics
630 fStack->FinishEvent();
632 // Write out the event Header information
634 fHeader->SetStack(fStack);
639 // Write Tree headers
640 TTree* pTreeK = fStack->TreeK();
641 if (pTreeK) pTreeK->Write(0,TObject::kOverwrite);
642 if (fTreeH) fTreeH->Write(0,TObject::kOverwrite);
647 //_____________________________________________________________________________
648 void AliRun::FinishRun()
651 // Called at the end of the run.
655 if(fLego) fLego->FinishRun();
657 // Clean detector information
658 TIter next(fModules);
660 while((detector = (AliModule*)next())) {
661 detector->FinishRun();
664 //Output energy summary tables
667 TFile *file = fTreeE->GetCurrentFile();
671 fTreeE->Write(0,TObject::kOverwrite);
673 // Write AliRun info and all detectors parameters
674 Write(0,TObject::kOverwrite);
676 // Clean tree information
681 delete fTreeH; fTreeH = 0;
684 delete fTreeD; fTreeD = 0;
687 delete fTreeR; fTreeR = 0;
690 delete fTreeE; fTreeE = 0;
693 delete fTreeS; fTreeS = 0;
695 fGenerator->FinishRun();
701 //_____________________________________________________________________________
702 void AliRun::FlagTrack(Int_t track)
706 fStack->FlagTrack(track);
709 //_____________________________________________________________________________
710 void AliRun::EnergySummary()
713 // Print summary of deposited energy
719 Int_t kn, i, left, j, id;
720 const Float_t kzero=0;
721 Int_t ievent=fHeader->GetEvent()+1;
723 // Energy loss information
725 printf("***************** Energy Loss Information per event (GEV) *****************\n");
726 for(kn=1;kn<fEventEnergy.GetSize();kn++) {
729 fEventEnergy[ndep]=kn;
734 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,kzero))/ed;
737 fSummEnergy[ndep]=ed;
738 fSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,kzero));
743 for(kn=0;kn<(ndep-1)/3+1;kn++) {
745 for(i=0;i<(3<left?3:left);i++) {
747 id=Int_t (fEventEnergy[j]+0.1);
748 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]);
753 // Relative energy loss in different detectors
754 printf("******************** Relative Energy Loss per event ********************\n");
755 printf("Total energy loss per event %10.3f GeV\n",edtot);
756 for(kn=0;kn<(ndep-1)/5+1;kn++) {
758 for(i=0;i<(5<left?5:left);i++) {
760 id=Int_t (fEventEnergy[j]+0.1);
761 printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot);
765 for(kn=0;kn<75;kn++) printf("*");
769 // Reset the TArray's
770 // fEventEnergy.Set(0);
771 // fSummEnergy.Set(0);
772 // fSum2Energy.Set(0);
775 //_____________________________________________________________________________
776 AliModule *AliRun::GetModule(const char *name) const
779 // Return pointer to detector from name
781 return (AliModule*)fModules->FindObject(name);
784 //_____________________________________________________________________________
785 AliDetector *AliRun::GetDetector(const char *name) const
788 // Return pointer to detector from name
790 return (AliDetector*)fModules->FindObject(name);
793 //_____________________________________________________________________________
794 Int_t AliRun::GetModuleID(const char *name) const
797 // Return galice internal detector identifier from name
800 TObject *mod=fModules->FindObject(name);
801 if(mod) i=fModules->IndexOf(mod);
805 //_____________________________________________________________________________
806 Int_t AliRun::GetEvent(Int_t event)
809 // Connect the Trees Kinematics and Hits for event # event
810 // Set branch addresses
813 // Reset existing structures
818 // Delete Trees already connected
819 if (fTreeH) { delete fTreeH; fTreeH = 0;}
820 if (fTreeD) { delete fTreeD; fTreeD = 0;}
821 if (fTreeR) { delete fTreeR; fTreeR = 0;}
822 if (fTreeS) { delete fTreeS; fTreeS = 0;}
824 // Create the particle stack
825 if (fHeader) delete fHeader;
828 // Get header from file
830 fTreeE->SetBranchAddress("Header", &fHeader);
832 if (!fTreeE->GetEntry(event)) {
833 Error("GetEvent","Cannot find event:%d\n",event);
838 Error("GetEvent","Cannot find Header Tree (TE)\n");
842 // Get the stack from the header, set fStack to 0 if it
843 // fails to get event
844 if (fStack) delete fStack;
845 fStack = fHeader->Stack();
847 if (!fStack->GetEvent(event)) fStack = 0;
851 TFile *file = fTreeE->GetCurrentFile();
856 // Get Hits Tree header from file
857 sprintf(treeName,"TreeH%d",event);
858 fTreeH = (TTree*)gDirectory->Get(treeName);
860 Error("GetEvent","cannot find Hits Tree for event:%d\n",event);
863 // Get Digits Tree header from file
864 sprintf(treeName,"TreeD%d",event);
865 fTreeD = (TTree*)gDirectory->Get(treeName);
867 // Warning("GetEvent","cannot find Digits Tree for event:%d\n",event);
872 // Get SDigits Tree header from file
873 sprintf(treeName,"TreeS%d",event);
874 fTreeS = (TTree*)gDirectory->Get(treeName);
876 // Warning("GetEvent","cannot find SDigits Tree for event:%d\n",event);
881 // Get Reconstruct Tree header from file
882 sprintf(treeName,"TreeR%d",event);
883 fTreeR = (TTree*)gDirectory->Get(treeName);
885 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
890 // Set Trees branch addresses
891 TIter next(fModules);
893 while((detector = (AliModule*)next())) {
894 detector->SetTreeAddress();
897 fEvent=event; //MI change
899 return fStack->GetNtrack();
902 //_____________________________________________________________________________
903 TGeometry *AliRun::GetGeometry()
906 // Import Alice geometry from current file
907 // Return pointer to geometry object
909 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
911 // Unlink and relink nodes in detectors
912 // This is bad and there must be a better way...
915 TIter next(fModules);
917 while((detector = (AliModule*)next())) {
918 TList *dnodes=detector->Nodes();
921 for ( j=0; j<dnodes->GetSize(); j++) {
922 node = (TNode*) dnodes->At(j);
923 node1 = fGeometry->GetNode(node->GetName());
924 dnodes->Remove(node);
925 dnodes->AddAt(node1,j);
931 //_____________________________________________________________________________
932 void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
933 Float_t &e, Float_t *vpos, Float_t *polar,
938 fStack->GetNextTrack(mtrack, ipart, pmom, e, vpos, polar, tof);
941 //_____________________________________________________________________________
942 Int_t AliRun::GetPrimary(Int_t track) const
945 // return number of primary that has generated track
947 return fStack->GetPrimary(track);
950 //_____________________________________________________________________________
951 void AliRun::InitMC(const char *setup)
954 // Initialize the Alice setup
958 Warning("Init","Cannot initialise AliRun twice!\n");
962 gROOT->LoadMacro(setup);
963 gInterpreter->ProcessLine(fConfigFunction.Data());
966 gMC->DefineParticles(); //Create standard MC particles
968 TObject *objfirst, *objlast;
970 fNdets = fModules->GetLast()+1;
973 //=================Create Materials and geometry
976 // Added also after in case of interactive initialisation of modules
977 fNdets = fModules->GetLast()+1;
979 TIter next(fModules);
981 while((detector = (AliModule*)next())) {
982 detector->SetTreeAddress();
983 objlast = gDirectory->GetList()->Last();
985 // Add Detector histograms in Detector list of histograms
986 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
987 else objfirst = gDirectory->GetList()->First();
989 detector->Histograms()->Add(objfirst);
990 objfirst = gDirectory->GetList()->After(objfirst);
993 ReadTransPar(); //Read the cuts for all materials
995 MediaTable(); //Build the special IMEDIA table
997 //Initialise geometry deposition table
998 fEventEnergy.Set(gMC->NofVolumes()+1);
999 fSummEnergy.Set(gMC->NofVolumes()+1);
1000 fSum2Energy.Set(gMC->NofVolumes()+1);
1002 //Compute cross-sections
1003 gMC->BuildPhysics();
1005 //Write Geometry object to current file.
1010 fMCQA = new AliMCQA(fNdets);
1012 AliConfig::Instance();
1014 // Save stuff at the beginning of the file to avoid file corruption
1018 //_____________________________________________________________________________
1019 void AliRun::MediaTable()
1022 // Built media table to get from the media number to
1025 Int_t kz, nz, idt, lz, i, k, ind;
1027 TObjArray &dets = *gAlice->Detectors();
1030 // For all detectors
1031 for (kz=0;kz<fNdets;kz++) {
1032 // If detector is defined
1033 if((det=(AliModule*) dets[kz])) {
1034 TArrayI &idtmed = *(det->GetIdtmed());
1035 for(nz=0;nz<100;nz++) {
1036 // Find max and min material number
1037 if((idt=idtmed[nz])) {
1038 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
1039 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
1042 if(det->LoMedium() > det->HiMedium()) {
1043 det->LoMedium() = 0;
1044 det->HiMedium() = 0;
1046 if(det->HiMedium() > fImedia->GetSize()) {
1047 Error("MediaTable","Increase fImedia from %d to %d",
1048 fImedia->GetSize(),det->HiMedium());
1051 // Tag all materials in rage as belonging to detector kz
1052 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
1059 // Print summary table
1060 printf(" Traking media ranges:\n");
1061 for(i=0;i<(fNdets-1)/6+1;i++) {
1062 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
1064 det=(AliModule*)dets[ind];
1066 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
1069 printf(" %6s: %3d -> %3d;","NULL",0,0);
1075 //____________________________________________________________________________
1076 void AliRun::SetGenerator(AliGenerator *generator)
1079 // Load the event generator
1081 if(!fGenerator) fGenerator = generator;
1084 //____________________________________________________________________________
1085 void AliRun::ResetGenerator(AliGenerator *generator)
1088 // Load the event generator
1092 Warning("ResetGenerator","Replacing generator %s with %s\n",
1093 fGenerator->GetName(),generator->GetName());
1095 Warning("ResetGenerator","Replacing generator %s with NULL\n",
1096 fGenerator->GetName());
1097 fGenerator = generator;
1100 //____________________________________________________________________________
1101 void AliRun::SetTransPar(char *filename)
1103 fTransParName = filename;
1106 //____________________________________________________________________________
1107 void AliRun::SetBaseFile(char *filename)
1109 fBaseFileName = filename;
1112 //____________________________________________________________________________
1113 void AliRun::ReadTransPar()
1116 // Read filename to set the transport parameters
1120 const Int_t kncuts=10;
1121 const Int_t knflags=11;
1122 const Int_t knpars=kncuts+knflags;
1123 const char kpars[knpars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
1124 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
1125 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
1126 "MULS","PAIR","PHOT","RAYL"};
1130 Float_t cut[kncuts];
1131 Int_t flag[knflags];
1132 Int_t i, itmed, iret, ktmed, kz;
1135 // See whether the file is there
1136 filtmp=gSystem->ExpandPathName(fTransParName.Data());
1137 lun=fopen(filtmp,"r");
1140 Warning("ReadTransPar","File %s does not exist!\n",fTransParName.Data());
1145 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1146 printf(" *%59s\n","*");
1147 printf(" * Please check carefully what you are doing!%10s\n","*");
1148 printf(" *%59s\n","*");
1152 // Initialise cuts and flags
1153 for(i=0;i<kncuts;i++) cut[i]=-99;
1154 for(i=0;i<knflags;i++) flag[i]=-99;
1156 for(i=0;i<256;i++) line[i]='\0';
1157 // Read up to the end of line excluded
1158 iret=fscanf(lun,"%[^\n]",line);
1163 printf(" *%59s\n","*");
1164 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1168 // Read the end of line
1171 if(line[0]=='*') continue;
1173 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",
1174 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
1175 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
1176 &flag[8],&flag[9],&flag[10]);
1180 Warning("ReadTransPar","Error reading file %s\n",fTransParName.Data());
1183 // Check that the module exist
1184 AliModule *mod = GetModule(detName);
1186 // Get the array of media numbers
1187 TArrayI &idtmed = *mod->GetIdtmed();
1188 // Check that the tracking medium code is valid
1189 if(0<=itmed && itmed < 100) {
1190 ktmed=idtmed[itmed];
1192 Warning("ReadTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
1195 // Set energy thresholds
1196 for(kz=0;kz<kncuts;kz++) {
1198 if(fDebug) printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
1199 kpars[kz],cut[kz],itmed,mod->GetName());
1200 gMC->Gstpar(ktmed,kpars[kz],cut[kz]);
1203 // Set transport mechanisms
1204 for(kz=0;kz<knflags;kz++) {
1206 if(fDebug) printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
1207 kpars[kncuts+kz],flag[kz],itmed,mod->GetName());
1208 gMC->Gstpar(ktmed,kpars[kncuts+kz],Float_t(flag[kz]));
1212 Warning("ReadTransPar","Invalid medium code %d *\n",itmed);
1216 if(fDebug) printf("%s::ReadTransParModule: %s not present\n",ClassName(),detName);
1223 //_____________________________________________________________________________
1224 void AliRun::MakeTree(Option_t *option, const char *file)
1227 // Create the ROOT trees
1228 // Loop on all detectors to create the Root branch (if any)
1234 const char *oK = strstr(option,"K");
1235 const char *oH = strstr(option,"H");
1236 const char *oE = strstr(option,"E");
1237 const char *oD = strstr(option,"D");
1238 const char *oR = strstr(option,"R");
1239 const char *oS = strstr(option,"S");
1242 TDirectory *cwd = gDirectory;
1244 TBranch *branch = 0;
1246 if (oK) fStack->MakeTree(fEvent, file);
1248 if (oE && !fTreeE) {
1249 fTreeE = new TTree("TE","Header");
1250 branch = fTreeE->Branch("Header", "AliHeader", &fHeader, 4000, 0);
1251 branch->SetAutoDelete(kFALSE);
1252 TFolder *folder = (TFolder *)gROOT->FindObjectAny("/Folders/RunMC/Event/Header");
1253 if (folder) folder->Add(fHeader);
1254 // branch = fTreeE->Branch("Stack","AliStack", &fStack, 4000, 0);
1255 // branch->SetAutoDelete(kFALSE);
1256 // if (folder) folder->Add(fStack);
1257 fTreeE->Write(0,TObject::kOverwrite);
1260 if (file && branch) {
1261 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
1262 sprintf(outFile,"%s/%s",GetBaseFile(),file);
1263 branch->SetFile(outFile);
1264 TIter next( branch->GetListOfBranches());
1265 while ((branch=(TBranch*)next())) {
1266 branch->SetFile(outFile);
1269 printf("* MakeBranch * Diverting Branch %s to file %s\n", branch->GetName(),file);
1274 if (oH && !fTreeH) {
1275 sprintf(hname,"TreeH%d",fEvent);
1276 fTreeH = new TTree(hname,"Hits");
1277 fTreeH->SetAutoSave(1000000000); //no autosave
1278 fTreeH->Write(0,TObject::kOverwrite);
1280 if (oD && !fTreeD) {
1281 sprintf(hname,"TreeD%d",fEvent);
1282 fTreeD = new TTree(hname,"Digits");
1283 fTreeD->Write(0,TObject::kOverwrite);
1285 if (oS && !fTreeS) {
1286 sprintf(hname,"TreeS%d",fEvent);
1287 fTreeS = new TTree(hname,"SDigits");
1288 fTreeS->Write(0,TObject::kOverwrite);
1290 if (oR && !fTreeR) {
1291 sprintf(hname,"TreeR%d",fEvent);
1292 fTreeR = new TTree(hname,"Reconstruction");
1293 fTreeR->Write(0,TObject::kOverwrite);
1297 // Create a branch for hits/digits for each detector
1298 // Each branch is a TClonesArray. Each data member of the Hits classes
1299 // will be in turn a subbranch of the detector master branch
1300 TIter next(fModules);
1301 AliModule *detector;
1302 while((detector = (AliModule*)next())) {
1303 if (oH) detector->MakeBranch(option,file);
1307 //_____________________________________________________________________________
1308 TParticle* AliRun::Particle(Int_t i)
1310 return fStack->Particle(i);
1313 //_____________________________________________________________________________
1314 void AliRun::BeginEvent()
1316 // Clean-up previous event
1318 fEventEnergy.Reset();
1319 // Clean detector information
1326 // Reset all Detectors & kinematics & trees
1330 // Initialise event header
1331 fHeader->Reset(fRun,fEvent);
1333 fStack->BeginEvent(fEvent);
1337 fLego->BeginEvent();
1350 sprintf(hname,"TreeH%d",fEvent);
1351 fTreeH->SetName(hname);
1355 sprintf(hname,"TreeD%d",fEvent);
1356 fTreeD->SetName(hname);
1357 fTreeD->Write(0,TObject::kOverwrite);
1361 sprintf(hname,"TreeS%d",fEvent);
1362 fTreeS->SetName(hname);
1363 fTreeS->Write(0,TObject::kOverwrite);
1367 sprintf(hname,"TreeR%d",fEvent);
1368 fTreeR->SetName(hname);
1369 fTreeR->Write(0,TObject::kOverwrite);
1372 //_____________________________________________________________________________
1373 void AliRun::ResetDigits()
1376 // Reset all Detectors digits
1378 TIter next(fModules);
1379 AliModule *detector;
1380 while((detector = (AliModule*)next())) {
1381 detector->ResetDigits();
1385 //_____________________________________________________________________________
1386 void AliRun::ResetSDigits()
1389 // Reset all Detectors digits
1391 TIter next(fModules);
1392 AliModule *detector;
1393 while((detector = (AliModule*)next())) {
1394 detector->ResetSDigits();
1398 //_____________________________________________________________________________
1399 void AliRun::ResetHits()
1402 // Reset all Detectors hits
1404 TIter next(fModules);
1405 AliModule *detector;
1406 while((detector = (AliModule*)next())) {
1407 detector->ResetHits();
1411 //_____________________________________________________________________________
1412 void AliRun::ResetPoints()
1415 // Reset all Detectors points
1417 TIter next(fModules);
1418 AliModule *detector;
1419 while((detector = (AliModule*)next())) {
1420 detector->ResetPoints();
1424 //_____________________________________________________________________________
1425 void AliRun::RunMC(Int_t nevent, const char *setup)
1428 // Main function to be called to process a galice run
1430 // Root > gAlice.Run();
1431 // a positive number of events will cause the finish routine
1434 fEventsPerRun = nevent;
1435 // check if initialisation has been done
1436 if (!fInitDone) InitMC(setup);
1438 // Create the Root Tree with one branch per detector
1442 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1443 MakeTree("K","Kine.root");
1444 MakeTree("H","Hits.root");
1449 gMC->ProcessRun(nevent);
1451 // End of this run, close files
1452 if(nevent>0) FinishRun();
1455 //_____________________________________________________________________________
1456 void AliRun::RunReco(const char *selected, Int_t first, Int_t last)
1459 // Main function to be called to reconstruct Alice event
1461 cout << "Found "<< gAlice->TreeE()->GetEntries() << "events" << endl;
1462 Int_t nFirst = first;
1463 Int_t nLast = (last < 0)? (Int_t) gAlice->TreeE()->GetEntries() : last;
1465 for (Int_t nevent = nFirst; nevent <= nLast; nevent++) {
1466 cout << "Processing event "<< nevent << endl;
1469 Digits2Reco(selected);
1473 //_____________________________________________________________________________
1475 void AliRun::Hits2Digits(const char *selected)
1478 // Convert Hits to sumable digits
1480 for (Int_t nevent=0; nevent<gAlice->TreeE()->GetEntries(); nevent++) {
1483 Hits2SDigits(selected);
1484 SDigits2Digits(selected);
1489 //_____________________________________________________________________________
1491 void AliRun::Tree2Tree(Option_t *option, const char *selected)
1494 // Function to transform the content of
1496 // - TreeH to TreeS (option "S")
1497 // - TreeS to TreeD (option "D")
1498 // - TreeD to TreeR (option "R")
1500 // If multiple options are specified ("SDR"), transformation will be done in sequence for
1501 // selected detector and for all detectors if none is selected (detector string
1502 // can contain blank separated list of detector names).
1505 const char *oS = strstr(option,"S");
1506 const char *oD = strstr(option,"D");
1507 const char *oR = strstr(option,"R");
1509 TObjArray *detectors = Detectors();
1511 TIter next(detectors);
1513 AliDetector *detector = 0;
1515 TDirectory *cwd = gDirectory;
1519 while((detector = (AliDetector*)next())) {
1521 if (strcmp(detector->GetName(),selected)) continue;
1522 if (detector->IsActive()){
1523 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1525 sprintf(outFile,"SDigits.%s.root",detector->GetName());
1526 detector->MakeBranch("S",outFile);
1529 sprintf(outFile,"Digits.%s.root",detector->GetName());
1530 detector->MakeBranch("D",outFile);
1533 sprintf(outFile,"Reco.%s.root",detector->GetName());
1534 detector->MakeBranch("R",outFile);
1537 detector->MakeBranch(option);
1543 cout << "Hits2SDigits: Processing " << detector->GetName() << "..." << endl;
1544 detector->Hits2SDigits();
1547 cout << "SDigits2Digits: Processing " << detector->GetName() << "..." << endl;
1548 detector->SDigits2Digits();
1551 cout << "Digits2Reco: Processing " << detector->GetName() << "..." << endl;
1552 detector->Digits2Reco();
1561 //_____________________________________________________________________________
1562 void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min,
1563 Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max,
1564 Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener)
1567 // Generates lego plots of:
1568 // - radiation length map phi vs theta
1569 // - radiation length map phi vs eta
1570 // - interaction length map
1571 // - g/cm2 length map
1573 // ntheta bins in theta, eta
1574 // themin minimum angle in theta (degrees)
1575 // themax maximum angle in theta (degrees)
1577 // phimin minimum angle in phi (degrees)
1578 // phimax maximum angle in phi (degrees)
1579 // rmin minimum radius
1580 // rmax maximum radius
1583 // The number of events generated = ntheta*nphi
1584 // run input parameters in macro setup (default="Config.C")
1586 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1589 <img src="picts/AliRunLego1.gif">
1594 <img src="picts/AliRunLego2.gif">
1599 <img src="picts/AliRunLego3.gif">
1604 // check if initialisation has been done
1605 if (!fInitDone) InitMC(setup);
1606 //Save current generator
1607 AliGenerator *gen=Generator();
1609 // Set new generator
1610 if (!gener) gener = new AliLegoGenerator();
1611 ResetGenerator(gener);
1613 // Configure Generator
1614 gener->SetRadiusRange(rmin, rmax);
1615 gener->SetZMax(zmax);
1616 gener->SetCoor1Range(nc1, c1min, c1max);
1617 gener->SetCoor2Range(nc2, c2min, c2max);
1620 //Create Lego object
1621 fLego = new AliLego("lego",gener);
1623 //Prepare MC for Lego Run
1628 gMC->ProcessRun(nc1*nc2+1);
1630 // Create only the Root event Tree
1633 // End of this run, close files
1635 // Restore current generator
1636 ResetGenerator(gen);
1637 // Delete Lego Object
1638 delete fLego; fLego=0;
1641 //_____________________________________________________________________________
1642 void AliRun::SetConfigFunction(const char * config)
1645 // Set the signature of the function contained in Config.C to configure
1648 fConfigFunction=config;
1651 //_____________________________________________________________________________
1652 void AliRun::SetCurrentTrack(Int_t track)
1655 // Set current track number
1657 fStack->SetCurrentTrack(track);
1660 //_____________________________________________________________________________
1661 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1662 Float_t *vpos, Float_t *polar, Float_t tof,
1663 AliMCProcess mech, Int_t &ntr, Float_t weight)
1665 // Delegate to stack
1667 fStack->SetTrack(done, parent, pdg, pmom, vpos, polar, tof,
1671 //_____________________________________________________________________________
1672 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg,
1673 Double_t px, Double_t py, Double_t pz, Double_t e,
1674 Double_t vx, Double_t vy, Double_t vz, Double_t tof,
1675 Double_t polx, Double_t poly, Double_t polz,
1676 AliMCProcess mech, Int_t &ntr, Float_t weight)
1678 // Delegate to stack
1680 fStack->SetTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
1681 polx, poly, polz, mech, ntr, weight);
1685 //_____________________________________________________________________________
1686 void AliRun::SetHighWaterMark(const Int_t nt)
1689 // Set high water mark for last track in event
1690 fStack->SetHighWaterMark(nt);
1693 //_____________________________________________________________________________
1694 void AliRun::KeepTrack(const Int_t track)
1697 // Delegate to stack
1699 fStack->KeepTrack(track);
1702 //_____________________________________________________________________________
1703 void AliRun::StepManager(Int_t id)
1706 // Called at every step during transport
1710 // --- If lego option, do it and leave
1712 fLego->StepManager();
1715 //Update energy deposition tables
1716 AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
1718 //Call the appropriate stepping routine;
1719 AliModule *det = (AliModule*)fModules->At(id);
1721 fMCQA->StepManager(id);
1727 //_____________________________________________________________________________
1728 void AliRun::Streamer(TBuffer &R__b)
1730 // Stream an object of class AliRun.
1732 if (R__b.IsReading()) {
1733 if (!gAlice) gAlice = this;
1735 AliRun::Class()->ReadBuffer(R__b, this);
1737 gROOT->GetListOfBrowsables()->Add(this,"Run");
1739 fTreeE = (TTree*)gDirectory->Get("TE");
1741 fTreeE->SetBranchAddress("Header", &fHeader);
1744 else Error("Streamer","cannot find Header Tree\n");
1745 fTreeE->GetEntry(0);
1749 AliRun::Class()->WriteBuffer(R__b, this);
1754 //___________________________________________________________________________
1755 Int_t AliRun::CurrentTrack() const {
1757 // Returns current track
1759 return fStack->CurrentTrack();
1762 //___________________________________________________________________________
1763 Int_t AliRun::GetNtrack() const {
1765 // Returns number of tracks in stack
1767 return fStack->GetNtrack();
1770 //___________________________________________________________________________
1771 TObjArray* AliRun::Particles() {
1773 // Returns pointer to Particles array
1775 return fStack->Particles();
1778 //___________________________________________________________________________
1779 TTree* AliRun::TreeK() {
1781 // Returns pointer to the TreeK array
1783 return fStack->TreeK();
1787 void AliRun::SetGenEventHeader(AliGenEventHeader* header)
1789 fHeader->SetGenEventHeader(header);