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.72 2001/07/03 08:10:57 hristov
19 J.Chudoba's changes merged correctly with the HEAD
21 Revision 1.70 2001/06/29 08:01:36 morsch
22 Small correction to the previous.
24 Revision 1.69 2001/06/28 16:27:50 morsch
25 AliReco() with user control of event range.
27 Revision 1.68 2001/06/11 13:14:40 morsch
28 SetAliGenEventHeader() method added.
30 Revision 1.67 2001/06/07 18:24:50 buncic
31 Removed compilation warning in AliConfig initialisation.
33 Revision 1.66 2001/05/22 14:32:40 hristov
36 Revision 1.65 2001/05/21 17:22:51 buncic
37 Fixed problem with missing AliConfig while reading galice.root
39 Revision 1.64 2001/05/16 14:57:22 alibrary
40 New files for folders and Stack
42 Revision 1.62 2001/04/06 11:12:33 morsch
43 Clear fParticles after each event. (Ivana Hrivnacova)
45 Revision 1.61 2001/03/30 07:04:10 morsch
46 Call fGenerator->FinishRun() for final print-outs, cross-section and weight calculations.
48 Revision 1.60 2001/03/21 18:22:30 hristov
49 fParticleFileMap fix (I.Hrivnacova)
51 Revision 1.59 2001/03/12 17:47:03 hristov
52 Changes needed on Sun with CC 5.0
54 Revision 1.58 2001/03/09 14:27:26 morsch
55 Fix for multiple events per file: inhibit decrease of size of fParticleFileMap.
57 Revision 1.57 2001/02/23 17:40:23 buncic
58 All trees needed for simulation created in RunMC(). TreeR and its branches
59 are now created in new RunReco() method.
61 Revision 1.56 2001/02/14 15:45:20 hristov
62 Algorithmic way of getting entry index in fParticleMap. Protection of fParticleFileMap (I.Hrivnacova)
64 Revision 1.55 2001/02/12 15:52:54 buncic
65 Removed OpenBaseFile().
67 Revision 1.54 2001/02/07 10:39:05 hristov
68 Remove default value for argument
70 Revision 1.53 2001/02/06 11:02:26 hristov
71 New SetTrack interface added, added check for unfilled particles in FinishEvent (I.Hrivnacova)
73 Revision 1.52 2001/02/05 16:22:25 buncic
74 Added TreeS to GetEvent().
76 Revision 1.51 2001/02/02 15:16:20 morsch
77 SetHighWaterMark method added to mark last particle in event.
79 Revision 1.50 2001/01/27 10:32:00 hristov
80 Leave the loop when primaries are filled (I.Hrivnacova)
82 Revision 1.49 2001/01/26 19:58:48 hristov
83 Major upgrade of AliRoot code
85 Revision 1.48 2001/01/17 10:50:50 hristov
86 Corrections to destructors
88 Revision 1.47 2000/12/18 10:44:01 morsch
89 Possibility to set field map by passing pointer to objet of type AliMagF via
92 gAlice->SetField(new AliMagFCM("Map2", "$(ALICE_ROOT)/data/field01.dat",2,1.,10.));
94 Revision 1.46 2000/12/14 19:29:27 fca
95 galice.cuts was not read any more
97 Revision 1.45 2000/11/30 07:12:49 alibrary
98 Introducing new Rndm and QA classes
100 Revision 1.44 2000/10/26 13:58:59 morsch
101 Add possibility to choose the lego generator (of type AliGeneratorLego or derived) when running
102 RunLego(). Default is the base class AliGeneratorLego.
104 Revision 1.43 2000/10/09 09:43:17 fca
105 Special remapping of hits for TPC and TRD. End-of-primary action introduced
107 Revision 1.42 2000/10/02 21:28:14 fca
108 Removal of useless dependecies via forward declarations
110 Revision 1.41 2000/07/13 16:19:09 fca
111 Mainly coding conventions + some small bug fixes
113 Revision 1.40 2000/07/12 08:56:25 fca
114 Coding convention correction and warning removal
116 Revision 1.39 2000/07/11 18:24:59 fca
117 Coding convention corrections + few minor bug fixes
119 Revision 1.38 2000/06/20 13:05:45 fca
120 Writing down the TREE headers before job starts
122 Revision 1.37 2000/06/09 20:05:11 morsch
123 Introduce possibility to chose magnetic field version 3: AliMagFDM + field02.dat
125 Revision 1.36 2000/06/08 14:03:58 hristov
126 Only one initializer for a default argument
128 Revision 1.35 2000/06/07 10:13:14 hristov
129 Delete only existent objects.
131 Revision 1.34 2000/05/18 10:45:38 fca
132 Delete Particle Factory properly
134 Revision 1.33 2000/05/16 13:10:40 fca
135 New method IsNewTrack and fix for a problem in Father-Daughter relations
137 Revision 1.32 2000/04/27 10:38:21 fca
138 Correct termination of Lego Run and introduce Lego getter in AliRun
140 Revision 1.31 2000/04/26 10:17:32 fca
141 Changes in Lego for G4 compatibility
143 Revision 1.30 2000/04/18 19:11:40 fca
144 Introduce variable Config.C function signature
146 Revision 1.29 2000/04/07 11:12:34 fca
147 G4 compatibility changes
149 Revision 1.28 2000/04/05 06:51:06 fca
150 Workaround for an HP compiler problem
152 Revision 1.27 2000/03/22 18:08:07 fca
153 Rationalisation of the virtual MC interfaces
155 Revision 1.26 2000/03/22 13:42:26 fca
156 SetGenerator does not replace an existing generator, ResetGenerator does
158 Revision 1.25 2000/02/23 16:25:22 fca
159 AliVMC and AliGeant3 classes introduced
160 ReadEuclid moved from AliRun to AliModule
162 Revision 1.24 2000/01/19 17:17:20 fca
163 Introducing a list of lists of hits -- more hits allowed for detector now
165 Revision 1.23 1999/12/03 11:14:31 fca
166 Fixing previous wrong checking
168 Revision 1.21 1999/11/25 10:40:08 fca
169 Fixing daughters information also in primary tracks
171 Revision 1.20 1999/10/04 18:08:49 fca
172 Adding protection against inconsistent Euclid files
174 Revision 1.19 1999/09/29 07:50:40 fca
175 Introduction of the Copyright and cvs Log
179 ///////////////////////////////////////////////////////////////////////////////
181 // Control class for Alice C++ //
182 // Only one single instance of this class exists. //
183 // The object is created in main program aliroot //
184 // and is pointed by the global gAlice. //
186 // -Supports the list of all Alice Detectors (fModules). //
187 // -Supports the list of particles (fParticles). //
188 // -Supports the Trees. //
189 // -Supports the geometry. //
190 // -Supports the event display. //
193 <img src="picts/AliRunClass.gif">
198 <img src="picts/alirun.gif">
202 ///////////////////////////////////////////////////////////////////////////////
207 #include <iostream.h>
214 #include <TObjectTable.h>
216 #include <TGeometry.h>
218 #include <TBrowser.h>
222 #include "TParticle.h"
224 #include "AliDisplay.h"
227 #include "AliMagFC.h"
228 #include "AliMagFCM.h"
229 #include "AliMagFDM.h"
231 #include "TRandom3.h"
233 #include "AliGenerator.h"
234 #include "AliLegoGenerator.h"
235 #include "AliConfig.h"
236 #include "AliStack.h"
237 #include "AliGenEventHeader.h"
238 #include "AliHeader.h"
240 #include "AliDetector.h"
246 //_____________________________________________________________________________
250 // Default constructor for AliRun
273 fPDGDB = 0; //Particle factory object!
275 fConfigFunction = "\0";
278 fTransParName = "\0";
279 fBaseFileName = ".\0";
283 //_____________________________________________________________________________
284 AliRun::AliRun(const char *name, const char *title)
288 // Constructor for the main processor.
289 // Creates the geometry
290 // Creates the list of Detectors.
291 // Creates the list of particles.
307 fConfigFunction = "Config();";
309 // Set random number generator
310 gRandom = fRandom = new TRandom3();
312 if (gSystem->Getenv("CONFIG_SEED")) {
313 gRandom->SetSeed((UInt_t)atoi(gSystem->Getenv("CONFIG_SEED")));
316 gROOT->GetListOfBrowsables()->Add(this,name);
319 fStack = new AliStack(10000);
320 // create the support list for the various Detectors
321 fModules = new TObjArray(77);
323 // Create the TNode geometry for the event display
325 BuildSimpleGeometry();
327 fHeader = new AliHeader();
333 // Create default mag field
338 // Prepare the tracking medium lists
339 fImedia = new TArrayI(1000);
340 for(i=0;i<1000;i++) (*fImedia)[i]=-99;
343 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
345 AliConfig::Instance()->Add(fPDGDB);
347 // Create HitLists list
348 fHitLists = new TList();
351 fBaseFileName = ".\0";
357 //_____________________________________________________________________________
361 // Default AliRun destructor
386 //_____________________________________________________________________________
387 void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
390 // Add a hit to detector id
392 TObjArray &dets = *fModules;
393 if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits);
396 //_____________________________________________________________________________
397 void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
400 // Add digit to detector id
402 TObjArray &dets = *fModules;
403 if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits);
406 //_____________________________________________________________________________
407 void AliRun::Browse(TBrowser *b)
410 // Called when the item "Run" is clicked on the left pane
411 // of the Root browser.
412 // It displays the Root Trees and all detectors.
414 if(!fStack) fStack=fHeader->Stack();
415 TTree* pTreeK = fStack->TreeK();
417 if (pTreeK) b->Add(pTreeK,pTreeK->GetName());
418 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
419 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
420 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
421 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
422 if (fTreeS) b->Add(fTreeS,fTreeS->GetName());
424 TIter next(fModules);
426 while((detector = (AliModule*)next())) {
427 b->Add(detector,detector->GetName());
429 b->Add(fMCQA,"AliMCQA");
432 //_____________________________________________________________________________
436 // Initialize Alice geometry
441 //_____________________________________________________________________________
442 void AliRun::BuildSimpleGeometry()
445 // Create a simple TNode geometry used by Root display engine
447 // Initialise geometry
449 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
450 new TMaterial("void","Vacuum",0,0,0); //Everything is void
451 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
452 brik->SetVisibility(0);
453 new TNode("alice","alice","S_alice");
456 //_____________________________________________________________________________
457 void AliRun::CleanDetectors()
460 // Clean Detectors at the end of event
462 TIter next(fModules);
464 while((detector = (AliModule*)next())) {
465 detector->FinishEvent();
469 //_____________________________________________________________________________
470 Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
473 // Return the distance from the mouse to the AliRun object
479 //_____________________________________________________________________________
480 void AliRun::DumpPart (Int_t i) const
483 // Dumps particle i in the stack
488 //_____________________________________________________________________________
489 void AliRun::DumpPStack () const
492 // Dumps the particle stack
494 fStack->DumpPStack();
497 //_____________________________________________________________________________
498 void AliRun::SetField(AliMagF* magField)
500 // Set Magnetic Field Map
505 //_____________________________________________________________________________
506 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
507 Float_t maxField, char* filename)
510 // Set magnetic field parameters
511 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
512 // version Magnetic field map version (only 1 active now)
513 // scale Scale factor for the magnetic field
514 // maxField Maximum value for the magnetic field
517 // --- Sanity check on mag field flags
518 if(fField) delete fField;
520 fField = new AliMagFC("Map1"," ",type,scale,maxField);
521 } else if(version<=2) {
522 fField = new AliMagFCM("Map2-3",filename,type,scale,maxField);
524 } else if(version==3) {
525 fField = new AliMagFDM("Map4",filename,type,scale,maxField);
528 Warning("SetField","Invalid map %d\n",version);
532 //_____________________________________________________________________________
533 void AliRun::PreTrack()
535 TObjArray &dets = *fModules;
538 for(Int_t i=0; i<=fNdets; i++)
539 if((module = (AliModule*)dets[i]))
545 //_____________________________________________________________________________
546 void AliRun::PostTrack()
548 TObjArray &dets = *fModules;
551 for(Int_t i=0; i<=fNdets; i++)
552 if((module = (AliModule*)dets[i]))
556 //_____________________________________________________________________________
557 void AliRun::FinishPrimary()
560 // Called at the end of each primary track
563 // static Int_t count=0;
564 // const Int_t times=10;
565 // This primary is finished, purify stack
566 fStack->PurifyKine();
568 TIter next(fModules);
570 while((detector = (AliModule*)next())) {
571 detector->FinishPrimary();
574 // Write out hits if any
575 if (gAlice->TreeH()) {
576 gAlice->TreeH()->Fill();
580 // if(++count%times==1) gObjectTable->Print();
583 //_____________________________________________________________________________
584 void AliRun::BeginPrimary()
587 // Called at the beginning of each primary track
595 //_____________________________________________________________________________
596 void AliRun::FinishEvent()
599 // Called at the end of the event.
603 if(fLego) fLego->FinishEvent();
605 //Update the energy deposit tables
607 for(i=0;i<fEventEnergy.GetSize();i++) {
608 fSummEnergy[i]+=fEventEnergy[i];
609 fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
614 // Update Header information
616 fHeader->SetNprimary(fStack->GetNprimary());
617 fHeader->SetNtrack(fStack->GetNtrack());
620 // Write out the kinematics
621 fStack->FinishEvent();
623 // Write out the event Header information
625 fHeader->SetStack(fStack);
630 // Write Tree headers
631 TTree* pTreeK = fStack->TreeK();
632 if (pTreeK) pTreeK->Write(0,TObject::kOverwrite);
633 if (fTreeH) fTreeH->Write(0,TObject::kOverwrite);
638 //_____________________________________________________________________________
639 void AliRun::FinishRun()
642 // Called at the end of the run.
646 if(fLego) fLego->FinishRun();
648 // Clean detector information
649 TIter next(fModules);
651 while((detector = (AliModule*)next())) {
652 detector->FinishRun();
655 //Output energy summary tables
658 TFile *file = fTreeE->GetCurrentFile();
662 fTreeE->Write(0,TObject::kOverwrite);
664 // Write AliRun info and all detectors parameters
665 Write(0,TObject::kOverwrite);
667 // Clean tree information
672 delete fTreeH; fTreeH = 0;
675 delete fTreeD; fTreeD = 0;
678 delete fTreeR; fTreeR = 0;
681 delete fTreeE; fTreeE = 0;
684 delete fTreeS; fTreeS = 0;
691 //_____________________________________________________________________________
692 void AliRun::FlagTrack(Int_t track)
696 fStack->FlagTrack(track);
699 //_____________________________________________________________________________
700 void AliRun::EnergySummary()
703 // Print summary of deposited energy
709 Int_t kn, i, left, j, id;
710 const Float_t kzero=0;
711 Int_t ievent=fHeader->GetEvent()+1;
713 // Energy loss information
715 printf("***************** Energy Loss Information per event (GEV) *****************\n");
716 for(kn=1;kn<fEventEnergy.GetSize();kn++) {
719 fEventEnergy[ndep]=kn;
724 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,kzero))/ed;
727 fSummEnergy[ndep]=ed;
728 fSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,kzero));
733 for(kn=0;kn<(ndep-1)/3+1;kn++) {
735 for(i=0;i<(3<left?3:left);i++) {
737 id=Int_t (fEventEnergy[j]+0.1);
738 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]);
743 // Relative energy loss in different detectors
744 printf("******************** Relative Energy Loss per event ********************\n");
745 printf("Total energy loss per event %10.3f GeV\n",edtot);
746 for(kn=0;kn<(ndep-1)/5+1;kn++) {
748 for(i=0;i<(5<left?5:left);i++) {
750 id=Int_t (fEventEnergy[j]+0.1);
751 printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot);
755 for(kn=0;kn<75;kn++) printf("*");
759 // Reset the TArray's
760 // fEventEnergy.Set(0);
761 // fSummEnergy.Set(0);
762 // fSum2Energy.Set(0);
765 //_____________________________________________________________________________
766 AliModule *AliRun::GetModule(const char *name) const
769 // Return pointer to detector from name
771 return (AliModule*)fModules->FindObject(name);
774 //_____________________________________________________________________________
775 AliDetector *AliRun::GetDetector(const char *name) const
778 // Return pointer to detector from name
780 return (AliDetector*)fModules->FindObject(name);
783 //_____________________________________________________________________________
784 Int_t AliRun::GetModuleID(const char *name) const
787 // Return galice internal detector identifier from name
790 TObject *mod=fModules->FindObject(name);
791 if(mod) i=fModules->IndexOf(mod);
795 //_____________________________________________________________________________
796 Int_t AliRun::GetEvent(Int_t event)
799 // Connect the Trees Kinematics and Hits for event # event
800 // Set branch addresses
803 // Reset existing structures
808 // Delete Trees already connected
809 if (fTreeH) { delete fTreeH; fTreeH = 0;}
810 if (fTreeD) { delete fTreeD; fTreeD = 0;}
811 if (fTreeR) { delete fTreeR; fTreeR = 0;}
812 if (fTreeS) { delete fTreeS; fTreeS = 0;}
814 // Create the particle stack
815 if (fHeader) delete fHeader;
818 // Get header from file
820 fTreeE->SetBranchAddress("Header", &fHeader);
822 if (!fTreeE->GetEntry(event)) {
823 Error("GetEvent","Cannot find event:%d\n",event);
828 Error("GetEvent","Cannot find Header Tree (TE)\n");
832 // Get the stack from the header, set fStack to 0 if it
833 // fails to get event
834 if (fStack) delete fStack;
835 fStack = fHeader->Stack();
837 if (!fStack->GetEvent(event)) fStack = 0;
841 TFile *file = fTreeE->GetCurrentFile();
845 // Get Hits Tree header from file
846 sprintf(treeName,"TreeH%d",event);
847 fTreeH = (TTree*)gDirectory->Get(treeName);
849 Error("GetEvent","cannot find Hits Tree for event:%d\n",event);
852 // Get Digits Tree header from file
853 sprintf(treeName,"TreeD%d",event);
854 fTreeD = (TTree*)gDirectory->Get(treeName);
856 // Warning("GetEvent","cannot find Digits Tree for event:%d\n",event);
861 // Get SDigits Tree header from file
862 sprintf(treeName,"TreeS%d",event);
863 fTreeS = (TTree*)gDirectory->Get(treeName);
865 // Warning("GetEvent","cannot find SDigits Tree for event:%d\n",event);
870 // Get Reconstruct Tree header from file
871 sprintf(treeName,"TreeR%d",event);
872 fTreeR = (TTree*)gDirectory->Get(treeName);
874 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
879 // Set Trees branch addresses
880 TIter next(fModules);
882 while((detector = (AliModule*)next())) {
883 detector->SetTreeAddress();
886 return fStack->GetNtrack();
889 //_____________________________________________________________________________
890 TGeometry *AliRun::GetGeometry()
893 // Import Alice geometry from current file
894 // Return pointer to geometry object
896 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
898 // Unlink and relink nodes in detectors
899 // This is bad and there must be a better way...
902 TIter next(fModules);
904 while((detector = (AliModule*)next())) {
905 TList *dnodes=detector->Nodes();
908 for ( j=0; j<dnodes->GetSize(); j++) {
909 node = (TNode*) dnodes->At(j);
910 node1 = fGeometry->GetNode(node->GetName());
911 dnodes->Remove(node);
912 dnodes->AddAt(node1,j);
918 //_____________________________________________________________________________
919 void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
920 Float_t &e, Float_t *vpos, Float_t *polar,
925 fStack->GetNextTrack(mtrack, ipart, pmom, e, vpos, polar, tof);
928 //_____________________________________________________________________________
929 Int_t AliRun::GetPrimary(Int_t track) const
932 // return number of primary that has generated track
934 return fStack->GetPrimary(track);
937 //_____________________________________________________________________________
938 void AliRun::InitMC(const char *setup)
941 // Initialize the Alice setup
945 Warning("Init","Cannot initialise AliRun twice!\n");
949 gROOT->LoadMacro(setup);
950 gInterpreter->ProcessLine(fConfigFunction.Data());
953 gMC->DefineParticles(); //Create standard MC particles
955 TObject *objfirst, *objlast;
957 fNdets = fModules->GetLast()+1;
960 //=================Create Materials and geometry
963 // Added also after in case of interactive initialisation of modules
964 fNdets = fModules->GetLast()+1;
966 TIter next(fModules);
968 while((detector = (AliModule*)next())) {
969 detector->SetTreeAddress();
970 objlast = gDirectory->GetList()->Last();
972 // Add Detector histograms in Detector list of histograms
973 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
974 else objfirst = gDirectory->GetList()->First();
976 detector->Histograms()->Add(objfirst);
977 objfirst = gDirectory->GetList()->After(objfirst);
980 ReadTransPar(); //Read the cuts for all materials
982 MediaTable(); //Build the special IMEDIA table
984 //Initialise geometry deposition table
985 fEventEnergy.Set(gMC->NofVolumes()+1);
986 fSummEnergy.Set(gMC->NofVolumes()+1);
987 fSum2Energy.Set(gMC->NofVolumes()+1);
989 //Compute cross-sections
992 //Write Geometry object to current file.
997 fMCQA = new AliMCQA(fNdets);
999 AliConfig::Instance();
1001 // Save stuff at the beginning of the file to avoid file corruption
1005 //_____________________________________________________________________________
1006 void AliRun::MediaTable()
1009 // Built media table to get from the media number to
1012 Int_t kz, nz, idt, lz, i, k, ind;
1014 TObjArray &dets = *gAlice->Detectors();
1017 // For all detectors
1018 for (kz=0;kz<fNdets;kz++) {
1019 // If detector is defined
1020 if((det=(AliModule*) dets[kz])) {
1021 TArrayI &idtmed = *(det->GetIdtmed());
1022 for(nz=0;nz<100;nz++) {
1023 // Find max and min material number
1024 if((idt=idtmed[nz])) {
1025 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
1026 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
1029 if(det->LoMedium() > det->HiMedium()) {
1030 det->LoMedium() = 0;
1031 det->HiMedium() = 0;
1033 if(det->HiMedium() > fImedia->GetSize()) {
1034 Error("MediaTable","Increase fImedia from %d to %d",
1035 fImedia->GetSize(),det->HiMedium());
1038 // Tag all materials in rage as belonging to detector kz
1039 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
1046 // Print summary table
1047 printf(" Traking media ranges:\n");
1048 for(i=0;i<(fNdets-1)/6+1;i++) {
1049 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
1051 det=(AliModule*)dets[ind];
1053 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
1056 printf(" %6s: %3d -> %3d;","NULL",0,0);
1062 //____________________________________________________________________________
1063 void AliRun::SetGenerator(AliGenerator *generator)
1066 // Load the event generator
1068 if(!fGenerator) fGenerator = generator;
1071 //____________________________________________________________________________
1072 void AliRun::ResetGenerator(AliGenerator *generator)
1075 // Load the event generator
1079 Warning("ResetGenerator","Replacing generator %s with %s\n",
1080 fGenerator->GetName(),generator->GetName());
1082 Warning("ResetGenerator","Replacing generator %s with NULL\n",
1083 fGenerator->GetName());
1084 fGenerator = generator;
1087 //____________________________________________________________________________
1088 void AliRun::SetTransPar(char *filename)
1090 fTransParName = filename;
1093 //____________________________________________________________________________
1094 void AliRun::SetBaseFile(char *filename)
1096 fBaseFileName = filename;
1099 //____________________________________________________________________________
1100 void AliRun::ReadTransPar()
1103 // Read filename to set the transport parameters
1107 const Int_t kncuts=10;
1108 const Int_t knflags=11;
1109 const Int_t knpars=kncuts+knflags;
1110 const char kpars[knpars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
1111 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
1112 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
1113 "MULS","PAIR","PHOT","RAYL"};
1117 Float_t cut[kncuts];
1118 Int_t flag[knflags];
1119 Int_t i, itmed, iret, ktmed, kz;
1122 // See whether the file is there
1123 filtmp=gSystem->ExpandPathName(fTransParName.Data());
1124 lun=fopen(filtmp,"r");
1127 Warning("ReadTransPar","File %s does not exist!\n",fTransParName.Data());
1132 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1133 printf(" *%59s\n","*");
1134 printf(" * Please check carefully what you are doing!%10s\n","*");
1135 printf(" *%59s\n","*");
1139 // Initialise cuts and flags
1140 for(i=0;i<kncuts;i++) cut[i]=-99;
1141 for(i=0;i<knflags;i++) flag[i]=-99;
1143 for(i=0;i<256;i++) line[i]='\0';
1144 // Read up to the end of line excluded
1145 iret=fscanf(lun,"%[^\n]",line);
1150 printf(" *%59s\n","*");
1151 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1155 // Read the end of line
1158 if(line[0]=='*') continue;
1160 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",
1161 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
1162 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
1163 &flag[8],&flag[9],&flag[10]);
1167 Warning("ReadTransPar","Error reading file %s\n",fTransParName.Data());
1170 // Check that the module exist
1171 AliModule *mod = GetModule(detName);
1173 // Get the array of media numbers
1174 TArrayI &idtmed = *mod->GetIdtmed();
1175 // Check that the tracking medium code is valid
1176 if(0<=itmed && itmed < 100) {
1177 ktmed=idtmed[itmed];
1179 Warning("ReadTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
1182 // Set energy thresholds
1183 for(kz=0;kz<kncuts;kz++) {
1185 if(fDebug) printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
1186 kpars[kz],cut[kz],itmed,mod->GetName());
1187 gMC->Gstpar(ktmed,kpars[kz],cut[kz]);
1190 // Set transport mechanisms
1191 for(kz=0;kz<knflags;kz++) {
1193 if(fDebug) printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
1194 kpars[kncuts+kz],flag[kz],itmed,mod->GetName());
1195 gMC->Gstpar(ktmed,kpars[kncuts+kz],Float_t(flag[kz]));
1199 Warning("ReadTransPar","Invalid medium code %d *\n",itmed);
1203 if(fDebug) printf("%s::ReadTransParModule: %s not present\n",ClassName(),detName);
1210 //_____________________________________________________________________________
1211 void AliRun::MakeTree(Option_t *option, const char *file)
1214 // Create the ROOT trees
1215 // Loop on all detectors to create the Root branch (if any)
1221 const char *oK = strstr(option,"K");
1222 const char *oH = strstr(option,"H");
1223 const char *oE = strstr(option,"E");
1224 const char *oD = strstr(option,"D");
1225 const char *oR = strstr(option,"R");
1226 const char *oS = strstr(option,"S");
1229 TDirectory *cwd = gDirectory;
1231 TBranch *branch = 0;
1233 if (oK) fStack->MakeTree(fEvent, file);
1235 if (oE && !fTreeE) {
1236 fTreeE = new TTree("TE","Header");
1237 branch = fTreeE->Branch("Header", "AliHeader", &fHeader, 4000, 0);
1238 branch->SetAutoDelete(kFALSE);
1239 TFolder *folder = (TFolder *)gROOT->FindObjectAny("/Folders/RunMC/Event/Header");
1240 if (folder) folder->Add(fHeader);
1241 // branch = fTreeE->Branch("Stack","AliStack", &fStack, 4000, 0);
1242 // branch->SetAutoDelete(kFALSE);
1243 // if (folder) folder->Add(fStack);
1244 fTreeE->Write(0,TObject::kOverwrite);
1247 if (file && branch) {
1248 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
1249 sprintf(outFile,"%s/%s",GetBaseFile(),file);
1250 branch->SetFile(outFile);
1251 TIter next( branch->GetListOfBranches());
1252 while ((branch=(TBranch*)next())) {
1253 branch->SetFile(outFile);
1256 printf("* MakeBranch * Diverting Branch %s to file %s\n", branch->GetName(),file);
1261 if (oH && !fTreeH) {
1262 sprintf(hname,"TreeH%d",fEvent);
1263 fTreeH = new TTree(hname,"Hits");
1264 fTreeH->SetAutoSave(1000000000); //no autosave
1265 fTreeH->Write(0,TObject::kOverwrite);
1267 if (oD && !fTreeD) {
1268 sprintf(hname,"TreeD%d",fEvent);
1269 fTreeD = new TTree(hname,"Digits");
1270 fTreeD->Write(0,TObject::kOverwrite);
1272 if (oS && !fTreeS) {
1273 sprintf(hname,"TreeS%d",fEvent);
1274 fTreeS = new TTree(hname,"SDigits");
1275 fTreeS->Write(0,TObject::kOverwrite);
1277 if (oR && !fTreeR) {
1278 sprintf(hname,"TreeR%d",fEvent);
1279 fTreeR = new TTree(hname,"Reconstruction");
1280 fTreeR->Write(0,TObject::kOverwrite);
1284 // Create a branch for hits/digits for each detector
1285 // Each branch is a TClonesArray. Each data member of the Hits classes
1286 // will be in turn a subbranch of the detector master branch
1287 TIter next(fModules);
1288 AliModule *detector;
1289 while((detector = (AliModule*)next())) {
1290 if (oH) detector->MakeBranch(option,file);
1294 //_____________________________________________________________________________
1295 TParticle* AliRun::Particle(Int_t i)
1297 return fStack->Particle(i);
1300 //_____________________________________________________________________________
1301 void AliRun::BeginEvent()
1303 // Clean-up previous event
1305 fEventEnergy.Reset();
1306 // Clean detector information
1313 // Reset all Detectors & kinematics & trees
1317 // Initialise event header
1318 fHeader->Reset(fRun,fEvent);
1320 fStack->BeginEvent(fEvent);
1324 fLego->BeginEvent();
1337 sprintf(hname,"TreeH%d",fEvent);
1338 fTreeH->SetName(hname);
1342 sprintf(hname,"TreeD%d",fEvent);
1343 fTreeD->SetName(hname);
1344 fTreeD->Write(0,TObject::kOverwrite);
1348 sprintf(hname,"TreeS%d",fEvent);
1349 fTreeS->SetName(hname);
1350 fTreeS->Write(0,TObject::kOverwrite);
1354 sprintf(hname,"TreeR%d",fEvent);
1355 fTreeR->SetName(hname);
1356 fTreeR->Write(0,TObject::kOverwrite);
1359 //_____________________________________________________________________________
1360 void AliRun::ResetDigits()
1363 // Reset all Detectors digits
1365 TIter next(fModules);
1366 AliModule *detector;
1367 while((detector = (AliModule*)next())) {
1368 detector->ResetDigits();
1372 //_____________________________________________________________________________
1373 void AliRun::ResetSDigits()
1376 // Reset all Detectors digits
1378 TIter next(fModules);
1379 AliModule *detector;
1380 while((detector = (AliModule*)next())) {
1381 detector->ResetSDigits();
1385 //_____________________________________________________________________________
1386 void AliRun::ResetHits()
1389 // Reset all Detectors hits
1391 TIter next(fModules);
1392 AliModule *detector;
1393 while((detector = (AliModule*)next())) {
1394 detector->ResetHits();
1398 //_____________________________________________________________________________
1399 void AliRun::ResetPoints()
1402 // Reset all Detectors points
1404 TIter next(fModules);
1405 AliModule *detector;
1406 while((detector = (AliModule*)next())) {
1407 detector->ResetPoints();
1411 //_____________________________________________________________________________
1412 void AliRun::RunMC(Int_t nevent, const char *setup)
1415 // Main function to be called to process a galice run
1417 // Root > gAlice.Run();
1418 // a positive number of events will cause the finish routine
1422 // check if initialisation has been done
1423 if (!fInitDone) InitMC(setup);
1425 // Create the Root Tree with one branch per detector
1429 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1430 MakeTree("K","Kine.root");
1431 MakeTree("H","Hits.root");
1436 gMC->ProcessRun(nevent);
1438 // End of this run, close files
1439 if(nevent>0) FinishRun();
1442 //_____________________________________________________________________________
1443 void AliRun::RunReco(const char *selected, Int_t first, Int_t last)
1446 // Main function to be called to reconstruct Alice event
1448 cout << "Found "<< gAlice->TreeE()->GetEntries() << "events" << endl;
1449 Int_t nFirst = first;
1450 Int_t nLast = (last < 0)? (Int_t) gAlice->TreeE()->GetEntries() : last;
1452 for (Int_t nevent = nFirst; nevent <= nLast; nevent++) {
1453 cout << "Processing event "<< nevent << endl;
1456 Digits2Reco(selected);
1460 //_____________________________________________________________________________
1462 void AliRun::Hits2Digits(const char *selected)
1465 // Convert Hits to sumable digits
1467 for (Int_t nevent=0; nevent<gAlice->TreeE()->GetEntries(); nevent++) {
1470 Hits2SDigits(selected);
1471 SDigits2Digits(selected);
1476 //_____________________________________________________________________________
1478 void AliRun::Tree2Tree(Option_t *option, const char *selected)
1481 // Function to transform the content of
1483 // - TreeH to TreeS (option "S")
1484 // - TreeS to TreeD (option "D")
1485 // - TreeD to TreeR (option "R")
1487 // If multiple options are specified ("SDR"), transformation will be done in sequence for
1488 // selected detector and for all detectors if none is selected (detector string
1489 // can contain blank separated list of detector names).
1492 const char *oS = strstr(option,"S");
1493 const char *oD = strstr(option,"D");
1494 const char *oR = strstr(option,"R");
1496 TObjArray *detectors = Detectors();
1498 TIter next(detectors);
1500 AliDetector *detector = 0;
1502 TDirectory *cwd = gDirectory;
1506 while((detector = (AliDetector*)next())) {
1508 if (strcmp(detector->GetName(),selected)) continue;
1509 if (detector->IsActive()){
1510 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1512 sprintf(outFile,"SDigits.%s.root",detector->GetName());
1513 detector->MakeBranch("S",outFile);
1516 sprintf(outFile,"Digits.%s.root",detector->GetName());
1517 detector->MakeBranch("D",outFile);
1520 sprintf(outFile,"Reco.%s.root",detector->GetName());
1521 detector->MakeBranch("R",outFile);
1524 detector->MakeBranch(option);
1530 cout << "Hits2SDigits: Processing " << detector->GetName() << "..." << endl;
1531 detector->Hits2SDigits();
1534 cout << "SDigits2Digits: Processing " << detector->GetName() << "..." << endl;
1535 detector->SDigits2Digits();
1538 cout << "Digits2Reco: Processing " << detector->GetName() << "..." << endl;
1539 detector->Digits2Reco();
1548 //_____________________________________________________________________________
1549 void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min,
1550 Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max,
1551 Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener)
1554 // Generates lego plots of:
1555 // - radiation length map phi vs theta
1556 // - radiation length map phi vs eta
1557 // - interaction length map
1558 // - g/cm2 length map
1560 // ntheta bins in theta, eta
1561 // themin minimum angle in theta (degrees)
1562 // themax maximum angle in theta (degrees)
1564 // phimin minimum angle in phi (degrees)
1565 // phimax maximum angle in phi (degrees)
1566 // rmin minimum radius
1567 // rmax maximum radius
1570 // The number of events generated = ntheta*nphi
1571 // run input parameters in macro setup (default="Config.C")
1573 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1576 <img src="picts/AliRunLego1.gif">
1581 <img src="picts/AliRunLego2.gif">
1586 <img src="picts/AliRunLego3.gif">
1591 // check if initialisation has been done
1592 if (!fInitDone) InitMC(setup);
1593 //Save current generator
1594 AliGenerator *gen=Generator();
1596 // Set new generator
1597 if (!gener) gener = new AliLegoGenerator();
1598 ResetGenerator(gener);
1600 // Configure Generator
1601 gener->SetRadiusRange(rmin, rmax);
1602 gener->SetZMax(zmax);
1603 gener->SetCoor1Range(nc1, c1min, c1max);
1604 gener->SetCoor2Range(nc2, c2min, c2max);
1607 //Create Lego object
1608 fLego = new AliLego("lego",gener);
1610 //Prepare MC for Lego Run
1615 gMC->ProcessRun(nc1*nc2+1);
1617 // Create only the Root event Tree
1620 // End of this run, close files
1622 // Restore current generator
1623 ResetGenerator(gen);
1624 // Delete Lego Object
1625 delete fLego; fLego=0;
1628 //_____________________________________________________________________________
1629 void AliRun::SetConfigFunction(const char * config)
1632 // Set the signature of the function contained in Config.C to configure
1635 fConfigFunction=config;
1638 //_____________________________________________________________________________
1639 void AliRun::SetCurrentTrack(Int_t track)
1642 // Set current track number
1644 fStack->SetCurrentTrack(track);
1647 //_____________________________________________________________________________
1648 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1649 Float_t *vpos, Float_t *polar, Float_t tof,
1650 AliMCProcess mech, Int_t &ntr, Float_t weight)
1652 // Delegate to stack
1654 fStack->SetTrack(done, parent, pdg, pmom, vpos, polar, tof,
1658 //_____________________________________________________________________________
1659 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg,
1660 Double_t px, Double_t py, Double_t pz, Double_t e,
1661 Double_t vx, Double_t vy, Double_t vz, Double_t tof,
1662 Double_t polx, Double_t poly, Double_t polz,
1663 AliMCProcess mech, Int_t &ntr, Float_t weight)
1665 // Delegate to stack
1667 fStack->SetTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
1668 polx, poly, polz, mech, ntr, weight);
1672 //_____________________________________________________________________________
1673 void AliRun::SetHighWaterMark(const Int_t nt)
1676 // Set high water mark for last track in event
1677 fStack->SetHighWaterMark(nt);
1680 //_____________________________________________________________________________
1681 void AliRun::KeepTrack(const Int_t track)
1684 // Delegate to stack
1686 fStack->KeepTrack(track);
1689 //_____________________________________________________________________________
1690 void AliRun::StepManager(Int_t id)
1693 // Called at every step during transport
1697 // --- If lego option, do it and leave
1699 fLego->StepManager();
1702 //Update energy deposition tables
1703 AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
1705 //Call the appropriate stepping routine;
1706 AliModule *det = (AliModule*)fModules->At(id);
1708 fMCQA->StepManager(id);
1714 //_____________________________________________________________________________
1715 void AliRun::Streamer(TBuffer &R__b)
1717 // Stream an object of class AliRun.
1719 if (R__b.IsReading()) {
1720 if (!gAlice) gAlice = this;
1722 AliRun::Class()->ReadBuffer(R__b, this);
1724 gROOT->GetListOfBrowsables()->Add(this,"Run");
1726 fTreeE = (TTree*)gDirectory->Get("TE");
1728 fTreeE->SetBranchAddress("Header", &fHeader);
1731 else Error("Streamer","cannot find Header Tree\n");
1732 fTreeE->GetEntry(0);
1736 AliRun::Class()->WriteBuffer(R__b, this);
1741 //___________________________________________________________________________
1742 Int_t AliRun::CurrentTrack() const {
1744 // Returns current track
1746 return fStack->CurrentTrack();
1749 //___________________________________________________________________________
1750 Int_t AliRun::GetNtrack() const {
1752 // Returns number of tracks in stack
1754 return fStack->GetNtrack();
1757 //___________________________________________________________________________
1758 TObjArray* AliRun::Particles() {
1760 // Returns pointer to Particles array
1762 return fStack->Particles();
1765 //___________________________________________________________________________
1766 TTree* AliRun::TreeK() {
1768 // Returns pointer to the TreeK array
1770 return fStack->TreeK();
1774 void AliRun::SetGenEventHeader(AliGenEventHeader* header)
1776 fHeader->SetGenEventHeader(header);