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.78 2001/10/04 15:30:56 hristov
19 Changes to accommodate the set of PHOS folders and tasks (Y.Schutz)
21 Revision 1.77 2001/09/04 15:09:11 hristov
22 fTreeE->Branch replaced temporary by fTreeE->BranchOld to avoid data corruption in case of many events per file
24 Revision 1.76 2001/08/03 14:38:35 morsch
25 Use original method to access TreeH.
27 Revision 1.75 2001/07/28 10:52:27 hristov
28 Event number updated correctly (M.Ivanov)
30 Revision 1.74 2001/07/28 10:39:16 morsch
31 GetEventsPerRun() method needed by afterburners added to AliRun.h
32 Corresponding setters and getters have been from AliGenerator.
34 Revision 1.73 2001/07/27 12:34:30 jchudoba
35 remove the dummy argument in fStack->GetEvent call
37 Revision 1.72 2001/07/03 08:10:57 hristov
38 J.Chudoba's changes merged correctly with the HEAD
40 Revision 1.70 2001/06/29 08:01:36 morsch
41 Small correction to the previous.
43 Revision 1.69 2001/06/28 16:27:50 morsch
44 AliReco() with user control of event range.
46 Revision 1.68 2001/06/11 13:14:40 morsch
47 SetAliGenEventHeader() method added.
49 Revision 1.67 2001/06/07 18:24:50 buncic
50 Removed compilation warning in AliConfig initialisation.
52 Revision 1.66 2001/05/22 14:32:40 hristov
55 Revision 1.65 2001/05/21 17:22:51 buncic
56 Fixed problem with missing AliConfig while reading galice.root
58 Revision 1.64 2001/05/16 14:57:22 alibrary
59 New files for folders and Stack
61 Revision 1.62 2001/04/06 11:12:33 morsch
62 Clear fParticles after each event. (Ivana Hrivnacova)
64 Revision 1.61 2001/03/30 07:04:10 morsch
65 Call fGenerator->FinishRun() for final print-outs, cross-section and weight calculations.
67 Revision 1.60 2001/03/21 18:22:30 hristov
68 fParticleFileMap fix (I.Hrivnacova)
70 Revision 1.59 2001/03/12 17:47:03 hristov
71 Changes needed on Sun with CC 5.0
73 Revision 1.58 2001/03/09 14:27:26 morsch
74 Fix for multiple events per file: inhibit decrease of size of fParticleFileMap.
76 Revision 1.57 2001/02/23 17:40:23 buncic
77 All trees needed for simulation created in RunMC(). TreeR and its branches
78 are now created in new RunReco() method.
80 Revision 1.56 2001/02/14 15:45:20 hristov
81 Algorithmic way of getting entry index in fParticleMap. Protection of fParticleFileMap (I.Hrivnacova)
83 Revision 1.55 2001/02/12 15:52:54 buncic
84 Removed OpenBaseFile().
86 Revision 1.54 2001/02/07 10:39:05 hristov
87 Remove default value for argument
89 Revision 1.53 2001/02/06 11:02:26 hristov
90 New SetTrack interface added, added check for unfilled particles in FinishEvent (I.Hrivnacova)
92 Revision 1.52 2001/02/05 16:22:25 buncic
93 Added TreeS to GetEvent().
95 Revision 1.51 2001/02/02 15:16:20 morsch
96 SetHighWaterMark method added to mark last particle in event.
98 Revision 1.50 2001/01/27 10:32:00 hristov
99 Leave the loop when primaries are filled (I.Hrivnacova)
101 Revision 1.49 2001/01/26 19:58:48 hristov
102 Major upgrade of AliRoot code
104 Revision 1.48 2001/01/17 10:50:50 hristov
105 Corrections to destructors
107 Revision 1.47 2000/12/18 10:44:01 morsch
108 Possibility to set field map by passing pointer to objet of type AliMagF via
111 gAlice->SetField(new AliMagFCM("Map2", "$(ALICE_ROOT)/data/field01.dat",2,1.,10.));
113 Revision 1.46 2000/12/14 19:29:27 fca
114 galice.cuts was not read any more
116 Revision 1.45 2000/11/30 07:12:49 alibrary
117 Introducing new Rndm and QA classes
119 Revision 1.44 2000/10/26 13:58:59 morsch
120 Add possibility to choose the lego generator (of type AliGeneratorLego or derived) when running
121 RunLego(). Default is the base class AliGeneratorLego.
123 Revision 1.43 2000/10/09 09:43:17 fca
124 Special remapping of hits for TPC and TRD. End-of-primary action introduced
126 Revision 1.42 2000/10/02 21:28:14 fca
127 Removal of useless dependecies via forward declarations
129 Revision 1.41 2000/07/13 16:19:09 fca
130 Mainly coding conventions + some small bug fixes
132 Revision 1.40 2000/07/12 08:56:25 fca
133 Coding convention correction and warning removal
135 Revision 1.39 2000/07/11 18:24:59 fca
136 Coding convention corrections + few minor bug fixes
138 Revision 1.38 2000/06/20 13:05:45 fca
139 Writing down the TREE headers before job starts
141 Revision 1.37 2000/06/09 20:05:11 morsch
142 Introduce possibility to chose magnetic field version 3: AliMagFDM + field02.dat
144 Revision 1.36 2000/06/08 14:03:58 hristov
145 Only one initializer for a default argument
147 Revision 1.35 2000/06/07 10:13:14 hristov
148 Delete only existent objects.
150 Revision 1.34 2000/05/18 10:45:38 fca
151 Delete Particle Factory properly
153 Revision 1.33 2000/05/16 13:10:40 fca
154 New method IsNewTrack and fix for a problem in Father-Daughter relations
156 Revision 1.32 2000/04/27 10:38:21 fca
157 Correct termination of Lego Run and introduce Lego getter in AliRun
159 Revision 1.31 2000/04/26 10:17:32 fca
160 Changes in Lego for G4 compatibility
162 Revision 1.30 2000/04/18 19:11:40 fca
163 Introduce variable Config.C function signature
165 Revision 1.29 2000/04/07 11:12:34 fca
166 G4 compatibility changes
168 Revision 1.28 2000/04/05 06:51:06 fca
169 Workaround for an HP compiler problem
171 Revision 1.27 2000/03/22 18:08:07 fca
172 Rationalisation of the virtual MC interfaces
174 Revision 1.26 2000/03/22 13:42:26 fca
175 SetGenerator does not replace an existing generator, ResetGenerator does
177 Revision 1.25 2000/02/23 16:25:22 fca
178 AliVMC and AliGeant3 classes introduced
179 ReadEuclid moved from AliRun to AliModule
181 Revision 1.24 2000/01/19 17:17:20 fca
182 Introducing a list of lists of hits -- more hits allowed for detector now
184 Revision 1.23 1999/12/03 11:14:31 fca
185 Fixing previous wrong checking
187 Revision 1.21 1999/11/25 10:40:08 fca
188 Fixing daughters information also in primary tracks
190 Revision 1.20 1999/10/04 18:08:49 fca
191 Adding protection against inconsistent Euclid files
193 Revision 1.19 1999/09/29 07:50:40 fca
194 Introduction of the Copyright and cvs Log
198 ///////////////////////////////////////////////////////////////////////////////
200 // Control class for Alice C++ //
201 // Only one single instance of this class exists. //
202 // The object is created in main program aliroot //
203 // and is pointed by the global gAlice. //
205 // -Supports the list of all Alice Detectors (fModules). //
206 // -Supports the list of particles (fParticles). //
207 // -Supports the Trees. //
208 // -Supports the geometry. //
209 // -Supports the event display. //
212 <img src="picts/AliRunClass.gif">
217 <img src="picts/alirun.gif">
221 ///////////////////////////////////////////////////////////////////////////////
226 #include <iostream.h>
233 #include <TObjectTable.h>
235 #include <TGeometry.h>
237 #include <TBrowser.h>
240 #include "TParticle.h"
242 #include "AliDisplay.h"
245 #include "AliMagFC.h"
246 #include "AliMagFCM.h"
247 #include "AliMagFDM.h"
249 #include "TRandom3.h"
251 #include "AliGenerator.h"
252 #include "AliLegoGenerator.h"
253 #include "AliConfig.h"
254 #include "AliStack.h"
255 #include "AliGenEventHeader.h"
256 #include "AliHeader.h"
258 #include "AliDetector.h"
264 //_____________________________________________________________________________
268 // Default constructor for AliRun
292 fPDGDB = 0; //Particle factory object!
294 fConfigFunction = "\0";
297 fTransParName = "\0";
298 fBaseFileName = ".\0";
302 //_____________________________________________________________________________
303 AliRun::AliRun(const char *name, const char *title)
307 // Constructor for the main processor.
308 // Creates the geometry
309 // Creates the list of Detectors.
310 // Creates the list of particles.
326 fConfigFunction = "Config();";
328 // Set random number generator
329 gRandom = fRandom = new TRandom3();
331 if (gSystem->Getenv("CONFIG_SEED")) {
332 gRandom->SetSeed((UInt_t)atoi(gSystem->Getenv("CONFIG_SEED")));
335 gROOT->GetListOfBrowsables()->Add(this,name);
338 fStack = new AliStack(10000);
339 // create the support list for the various Detectors
340 fModules = new TObjArray(77);
342 // Create the TNode geometry for the event display
344 BuildSimpleGeometry();
346 fHeader = new AliHeader();
353 // Create default mag field
358 // Prepare the tracking medium lists
359 fImedia = new TArrayI(1000);
360 for(i=0;i<1000;i++) (*fImedia)[i]=-99;
363 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
365 AliConfig::Instance()->Add(fPDGDB);
367 // Create HitLists list
368 fHitLists = new TList();
371 fBaseFileName = ".\0";
377 //_____________________________________________________________________________
381 // Default AliRun destructor
406 //_____________________________________________________________________________
407 void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
410 // Add a hit to detector id
412 TObjArray &dets = *fModules;
413 if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits);
416 //_____________________________________________________________________________
417 void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
420 // Add digit to detector id
422 TObjArray &dets = *fModules;
423 if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits);
426 //_____________________________________________________________________________
427 void AliRun::Browse(TBrowser *b)
430 // Called when the item "Run" is clicked on the left pane
431 // of the Root browser.
432 // It displays the Root Trees and all detectors.
434 if(!fStack) fStack=fHeader->Stack();
435 TTree* pTreeK = fStack->TreeK();
437 if (pTreeK) b->Add(pTreeK,pTreeK->GetName());
438 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
439 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
440 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
441 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
442 if (fTreeS) b->Add(fTreeS,fTreeS->GetName());
444 TIter next(fModules);
446 while((detector = (AliModule*)next())) {
447 b->Add(detector,detector->GetName());
449 b->Add(fMCQA,"AliMCQA");
452 //_____________________________________________________________________________
456 // Initialize Alice geometry
461 //_____________________________________________________________________________
462 void AliRun::BuildSimpleGeometry()
465 // Create a simple TNode geometry used by Root display engine
467 // Initialise geometry
469 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
470 new TMaterial("void","Vacuum",0,0,0); //Everything is void
471 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
472 brik->SetVisibility(0);
473 new TNode("alice","alice","S_alice");
476 //_____________________________________________________________________________
477 void AliRun::CleanDetectors()
480 // Clean Detectors at the end of event
482 TIter next(fModules);
484 while((detector = (AliModule*)next())) {
485 detector->FinishEvent();
489 //_____________________________________________________________________________
490 Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
493 // Return the distance from the mouse to the AliRun object
499 //_____________________________________________________________________________
500 void AliRun::DumpPart (Int_t i) const
503 // Dumps particle i in the stack
508 //_____________________________________________________________________________
509 void AliRun::DumpPStack () const
512 // Dumps the particle stack
514 fStack->DumpPStack();
517 //_____________________________________________________________________________
518 void AliRun::SetField(AliMagF* magField)
520 // Set Magnetic Field Map
525 //_____________________________________________________________________________
526 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
527 Float_t maxField, char* filename)
530 // Set magnetic field parameters
531 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
532 // version Magnetic field map version (only 1 active now)
533 // scale Scale factor for the magnetic field
534 // maxField Maximum value for the magnetic field
537 // --- Sanity check on mag field flags
538 if(fField) delete fField;
540 fField = new AliMagFC("Map1"," ",type,scale,maxField);
541 } else if(version<=2) {
542 fField = new AliMagFCM("Map2-3",filename,type,scale,maxField);
544 } else if(version==3) {
545 fField = new AliMagFDM("Map4",filename,type,scale,maxField);
548 Warning("SetField","Invalid map %d\n",version);
552 //_____________________________________________________________________________
553 void AliRun::PreTrack()
555 TObjArray &dets = *fModules;
558 for(Int_t i=0; i<=fNdets; i++)
559 if((module = (AliModule*)dets[i]))
565 //_____________________________________________________________________________
566 void AliRun::PostTrack()
568 TObjArray &dets = *fModules;
571 for(Int_t i=0; i<=fNdets; i++)
572 if((module = (AliModule*)dets[i]))
576 //_____________________________________________________________________________
577 void AliRun::FinishPrimary()
580 // Called at the end of each primary track
583 // static Int_t count=0;
584 // const Int_t times=10;
585 // This primary is finished, purify stack
586 fStack->PurifyKine();
588 TIter next(fModules);
590 while((detector = (AliModule*)next())) {
591 detector->FinishPrimary();
594 // Write out hits if any
595 if (gAlice->TreeH()) {
596 gAlice->TreeH()->Fill();
600 // if(++count%times==1) gObjectTable->Print();
603 //_____________________________________________________________________________
604 void AliRun::BeginPrimary()
607 // Called at the beginning of each primary track
615 //_____________________________________________________________________________
616 void AliRun::FinishEvent()
619 // Called at the end of the event.
623 if(fLego) fLego->FinishEvent();
625 //Update the energy deposit tables
627 for(i=0;i<fEventEnergy.GetSize();i++) {
628 fSummEnergy[i]+=fEventEnergy[i];
629 fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
634 // Update Header information
636 fHeader->SetNprimary(fStack->GetNprimary());
637 fHeader->SetNtrack(fStack->GetNtrack());
640 // Write out the kinematics
641 fStack->FinishEvent();
643 // Write out the event Header information
645 fHeader->SetStack(fStack);
650 // Write Tree headers
651 TTree* pTreeK = fStack->TreeK();
652 if (pTreeK) pTreeK->Write(0,TObject::kOverwrite);
653 if (fTreeH) fTreeH->Write(0,TObject::kOverwrite);
659 //_____________________________________________________________________________
660 void AliRun::FinishRun()
663 // Called at the end of the run.
667 if(fLego) fLego->FinishRun();
669 // Clean detector information
670 TIter next(fModules);
672 while((detector = (AliModule*)next())) {
673 detector->FinishRun();
676 //Output energy summary tables
679 TFile *file = fTreeE->GetCurrentFile();
683 fTreeE->Write(0,TObject::kOverwrite);
685 // Write AliRun info and all detectors parameters
686 Write(0,TObject::kOverwrite);
688 // Clean tree information
693 delete fTreeH; fTreeH = 0;
696 delete fTreeD; fTreeD = 0;
699 delete fTreeR; fTreeR = 0;
702 // delete fTreeE; fTreeE = 0;
705 delete fTreeS; fTreeS = 0;
707 fGenerator->FinishRun();
713 //_____________________________________________________________________________
714 void AliRun::FlagTrack(Int_t track)
718 fStack->FlagTrack(track);
721 //_____________________________________________________________________________
722 void AliRun::EnergySummary()
725 // Print summary of deposited energy
731 Int_t kn, i, left, j, id;
732 const Float_t kzero=0;
733 Int_t ievent=fHeader->GetEvent()+1;
735 // Energy loss information
737 printf("***************** Energy Loss Information per event (GEV) *****************\n");
738 for(kn=1;kn<fEventEnergy.GetSize();kn++) {
741 fEventEnergy[ndep]=kn;
746 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,kzero))/ed;
749 fSummEnergy[ndep]=ed;
750 fSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,kzero));
755 for(kn=0;kn<(ndep-1)/3+1;kn++) {
757 for(i=0;i<(3<left?3:left);i++) {
759 id=Int_t (fEventEnergy[j]+0.1);
760 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]);
765 // Relative energy loss in different detectors
766 printf("******************** Relative Energy Loss per event ********************\n");
767 printf("Total energy loss per event %10.3f GeV\n",edtot);
768 for(kn=0;kn<(ndep-1)/5+1;kn++) {
770 for(i=0;i<(5<left?5:left);i++) {
772 id=Int_t (fEventEnergy[j]+0.1);
773 printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot);
777 for(kn=0;kn<75;kn++) printf("*");
781 // Reset the TArray's
782 // fEventEnergy.Set(0);
783 // fSummEnergy.Set(0);
784 // fSum2Energy.Set(0);
787 //_____________________________________________________________________________
788 AliModule *AliRun::GetModule(const char *name) const
791 // Return pointer to detector from name
793 return (AliModule*)fModules->FindObject(name);
796 //_____________________________________________________________________________
797 AliDetector *AliRun::GetDetector(const char *name) const
800 // Return pointer to detector from name
802 return (AliDetector*)fModules->FindObject(name);
805 //_____________________________________________________________________________
806 Int_t AliRun::GetModuleID(const char *name) const
809 // Return galice internal detector identifier from name
812 TObject *mod=fModules->FindObject(name);
813 if(mod) i=fModules->IndexOf(mod);
817 //_____________________________________________________________________________
818 Int_t AliRun::GetEvent(Int_t event)
821 // Connect the Trees Kinematics and Hits for event # event
822 // Set branch addresses
825 // Reset existing structures
830 // Delete Trees already connected
831 if (fTreeH) { delete fTreeH; fTreeH = 0;}
832 if (fTreeD) { delete fTreeD; fTreeD = 0;}
833 if (fTreeR) { delete fTreeR; fTreeR = 0;}
834 if (fTreeS) { delete fTreeS; fTreeS = 0;}
836 // Create the particle stack
837 if (fHeader) delete fHeader;
840 // Get header from file
842 fTreeE->SetBranchAddress("Header", &fHeader);
844 if (!fTreeE->GetEntry(event)) {
845 Error("GetEvent","Cannot find event:%d\n",event);
850 Error("GetEvent","Cannot find Header Tree (TE)\n");
854 // Get the stack from the header, set fStack to 0 if it
855 // fails to get event
856 if (fStack) delete fStack;
857 fStack = fHeader->Stack();
859 if (!fStack->GetEvent(event)) fStack = 0;
863 TFile *file = fTreeE->GetCurrentFile();
868 // Get Hits Tree header from file
869 sprintf(treeName,"TreeH%d",event);
870 fTreeH = (TTree*)gDirectory->Get(treeName);
872 Error("GetEvent","cannot find Hits Tree for event:%d\n",event);
875 // Get Digits Tree header from file
876 sprintf(treeName,"TreeD%d",event);
877 fTreeD = (TTree*)gDirectory->Get(treeName);
879 // Warning("GetEvent","cannot find Digits Tree for event:%d\n",event);
884 // Get SDigits Tree header from file
885 sprintf(treeName,"TreeS%d",event);
886 fTreeS = (TTree*)gDirectory->Get(treeName);
888 // Warning("GetEvent","cannot find SDigits Tree for event:%d\n",event);
893 // Get Reconstruct Tree header from file
894 sprintf(treeName,"TreeR%d",event);
895 fTreeR = (TTree*)gDirectory->Get(treeName);
897 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
902 // Set Trees branch addresses
903 TIter next(fModules);
905 while((detector = (AliModule*)next())) {
906 detector->SetTreeAddress();
909 fEvent=event; //MI change
911 return fHeader->GetNtrack();
914 //_____________________________________________________________________________
915 TGeometry *AliRun::GetGeometry()
918 // Import Alice geometry from current file
919 // Return pointer to geometry object
921 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
923 // Unlink and relink nodes in detectors
924 // This is bad and there must be a better way...
927 TIter next(fModules);
929 while((detector = (AliModule*)next())) {
930 TList *dnodes=detector->Nodes();
933 for ( j=0; j<dnodes->GetSize(); j++) {
934 node = (TNode*) dnodes->At(j);
935 node1 = fGeometry->GetNode(node->GetName());
936 dnodes->Remove(node);
937 dnodes->AddAt(node1,j);
943 //_____________________________________________________________________________
944 void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
945 Float_t &e, Float_t *vpos, Float_t *polar,
950 fStack->GetNextTrack(mtrack, ipart, pmom, e, vpos, polar, tof);
953 //_____________________________________________________________________________
954 Int_t AliRun::GetPrimary(Int_t track) const
957 // return number of primary that has generated track
959 return fStack->GetPrimary(track);
962 //_____________________________________________________________________________
963 void AliRun::InitMC(const char *setup)
966 // Initialize the Alice setup
970 Warning("Init","Cannot initialise AliRun twice!\n");
974 gROOT->LoadMacro(setup);
975 gInterpreter->ProcessLine(fConfigFunction.Data());
978 gMC->DefineParticles(); //Create standard MC particles
980 TObject *objfirst, *objlast;
982 fNdets = fModules->GetLast()+1;
985 //=================Create Materials and geometry
988 // Added also after in case of interactive initialisation of modules
989 fNdets = fModules->GetLast()+1;
991 TIter next(fModules);
993 while((detector = (AliModule*)next())) {
994 detector->SetTreeAddress();
995 objlast = gDirectory->GetList()->Last();
997 // Add Detector histograms in Detector list of histograms
998 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
999 else objfirst = gDirectory->GetList()->First();
1001 detector->Histograms()->Add(objfirst);
1002 objfirst = gDirectory->GetList()->After(objfirst);
1005 ReadTransPar(); //Read the cuts for all materials
1007 MediaTable(); //Build the special IMEDIA table
1009 //Initialise geometry deposition table
1010 fEventEnergy.Set(gMC->NofVolumes()+1);
1011 fSummEnergy.Set(gMC->NofVolumes()+1);
1012 fSum2Energy.Set(gMC->NofVolumes()+1);
1014 //Compute cross-sections
1015 gMC->BuildPhysics();
1017 //Write Geometry object to current file.
1022 fMCQA = new AliMCQA(fNdets);
1024 AliConfig::Instance();
1026 // Save stuff at the beginning of the file to avoid file corruption
1030 //_____________________________________________________________________________
1031 void AliRun::MediaTable()
1034 // Built media table to get from the media number to
1037 Int_t kz, nz, idt, lz, i, k, ind;
1039 TObjArray &dets = *gAlice->Detectors();
1042 // For all detectors
1043 for (kz=0;kz<fNdets;kz++) {
1044 // If detector is defined
1045 if((det=(AliModule*) dets[kz])) {
1046 TArrayI &idtmed = *(det->GetIdtmed());
1047 for(nz=0;nz<100;nz++) {
1048 // Find max and min material number
1049 if((idt=idtmed[nz])) {
1050 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
1051 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
1054 if(det->LoMedium() > det->HiMedium()) {
1055 det->LoMedium() = 0;
1056 det->HiMedium() = 0;
1058 if(det->HiMedium() > fImedia->GetSize()) {
1059 Error("MediaTable","Increase fImedia from %d to %d",
1060 fImedia->GetSize(),det->HiMedium());
1063 // Tag all materials in rage as belonging to detector kz
1064 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
1071 // Print summary table
1072 printf(" Traking media ranges:\n");
1073 for(i=0;i<(fNdets-1)/6+1;i++) {
1074 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
1076 det=(AliModule*)dets[ind];
1078 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
1081 printf(" %6s: %3d -> %3d;","NULL",0,0);
1087 //____________________________________________________________________________
1088 void AliRun::SetGenerator(AliGenerator *generator)
1091 // Load the event generator
1093 if(!fGenerator) fGenerator = generator;
1096 //____________________________________________________________________________
1097 void AliRun::ResetGenerator(AliGenerator *generator)
1100 // Load the event generator
1104 Warning("ResetGenerator","Replacing generator %s with %s\n",
1105 fGenerator->GetName(),generator->GetName());
1107 Warning("ResetGenerator","Replacing generator %s with NULL\n",
1108 fGenerator->GetName());
1109 fGenerator = generator;
1112 //____________________________________________________________________________
1113 void AliRun::SetTransPar(char *filename)
1115 fTransParName = filename;
1118 //____________________________________________________________________________
1119 void AliRun::SetBaseFile(char *filename)
1121 fBaseFileName = filename;
1124 //____________________________________________________________________________
1125 void AliRun::ReadTransPar()
1128 // Read filename to set the transport parameters
1132 const Int_t kncuts=10;
1133 const Int_t knflags=11;
1134 const Int_t knpars=kncuts+knflags;
1135 const char kpars[knpars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
1136 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
1137 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
1138 "MULS","PAIR","PHOT","RAYL"};
1142 Float_t cut[kncuts];
1143 Int_t flag[knflags];
1144 Int_t i, itmed, iret, ktmed, kz;
1147 // See whether the file is there
1148 filtmp=gSystem->ExpandPathName(fTransParName.Data());
1149 lun=fopen(filtmp,"r");
1152 Warning("ReadTransPar","File %s does not exist!\n",fTransParName.Data());
1157 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1158 printf(" *%59s\n","*");
1159 printf(" * Please check carefully what you are doing!%10s\n","*");
1160 printf(" *%59s\n","*");
1164 // Initialise cuts and flags
1165 for(i=0;i<kncuts;i++) cut[i]=-99;
1166 for(i=0;i<knflags;i++) flag[i]=-99;
1168 for(i=0;i<256;i++) line[i]='\0';
1169 // Read up to the end of line excluded
1170 iret=fscanf(lun,"%[^\n]",line);
1175 printf(" *%59s\n","*");
1176 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1180 // Read the end of line
1183 if(line[0]=='*') continue;
1185 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",
1186 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
1187 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
1188 &flag[8],&flag[9],&flag[10]);
1192 Warning("ReadTransPar","Error reading file %s\n",fTransParName.Data());
1195 // Check that the module exist
1196 AliModule *mod = GetModule(detName);
1198 // Get the array of media numbers
1199 TArrayI &idtmed = *mod->GetIdtmed();
1200 // Check that the tracking medium code is valid
1201 if(0<=itmed && itmed < 100) {
1202 ktmed=idtmed[itmed];
1204 Warning("ReadTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
1207 // Set energy thresholds
1208 for(kz=0;kz<kncuts;kz++) {
1210 if(fDebug) printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
1211 kpars[kz],cut[kz],itmed,mod->GetName());
1212 gMC->Gstpar(ktmed,kpars[kz],cut[kz]);
1215 // Set transport mechanisms
1216 for(kz=0;kz<knflags;kz++) {
1218 if(fDebug) printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
1219 kpars[kncuts+kz],flag[kz],itmed,mod->GetName());
1220 gMC->Gstpar(ktmed,kpars[kncuts+kz],Float_t(flag[kz]));
1224 Warning("ReadTransPar","Invalid medium code %d *\n",itmed);
1228 if(fDebug) printf("%s::ReadTransParModule: %s not present\n",ClassName(),detName);
1235 //_____________________________________________________________________________
1236 void AliRun::MakeTree(Option_t *option, const char *file)
1239 // Create the ROOT trees
1240 // Loop on all detectors to create the Root branch (if any)
1246 const char *oK = strstr(option,"K");
1247 const char *oH = strstr(option,"H");
1248 const char *oE = strstr(option,"E");
1249 const char *oD = strstr(option,"D");
1250 const char *oR = strstr(option,"R");
1251 const char *oS = strstr(option,"S");
1254 TDirectory *cwd = gDirectory;
1256 TBranch *branch = 0;
1258 if (oK) fStack->MakeTree(fEvent, file);
1260 if (oE && !fTreeE) {
1261 fTreeE = new TTree("TE","Header");
1262 // branch = fTreeE->Branch("Header", "AliHeader", &fHeader, 4000, 0);
1263 branch = fTreeE->BranchOld("Header", "AliHeader", &fHeader, 4000, 0);
1264 branch->SetAutoDelete(kFALSE);
1265 TFolder *folder = (TFolder *)gROOT->FindObjectAny("/Folders/RunMC/Event/Header");
1266 if (folder) folder->Add(fHeader);
1267 // branch = fTreeE->Branch("Stack","AliStack", &fStack, 4000, 0);
1268 // branch->SetAutoDelete(kFALSE);
1269 // if (folder) folder->Add(fStack);
1270 fTreeE->Write(0,TObject::kOverwrite);
1273 if (file && branch) {
1274 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
1275 sprintf(outFile,"%s/%s",GetBaseFile(),file);
1276 branch->SetFile(outFile);
1277 TIter next( branch->GetListOfBranches());
1278 while ((branch=(TBranch*)next())) {
1279 branch->SetFile(outFile);
1282 printf("* MakeBranch * Diverting Branch %s to file %s\n", branch->GetName(),file);
1287 if (oH && !fTreeH) {
1288 sprintf(hname,"TreeH%d",fEvent);
1289 fTreeH = new TTree(hname,"Hits");
1290 fTreeH->SetAutoSave(1000000000); //no autosave
1291 fTreeH->Write(0,TObject::kOverwrite);
1293 if (oD && !fTreeD) {
1294 sprintf(hname,"TreeD%d",fEvent);
1295 fTreeD = new TTree(hname,"Digits");
1296 fTreeD->Write(0,TObject::kOverwrite);
1298 if (oS && !fTreeS) {
1299 sprintf(hname,"TreeS%d",fEvent);
1300 fTreeS = new TTree(hname,"SDigits");
1301 fTreeS->Write(0,TObject::kOverwrite);
1303 if (oR && !fTreeR) {
1304 sprintf(hname,"TreeR%d",fEvent);
1305 fTreeR = new TTree(hname,"Reconstruction");
1306 fTreeR->Write(0,TObject::kOverwrite);
1310 // Create a branch for hits/digits for each detector
1311 // Each branch is a TClonesArray. Each data member of the Hits classes
1312 // will be in turn a subbranch of the detector master branch
1313 TIter next(fModules);
1314 AliModule *detector;
1315 while((detector = (AliModule*)next())) {
1316 if (oH) detector->MakeBranch(option,file);
1320 //_____________________________________________________________________________
1321 TParticle* AliRun::Particle(Int_t i)
1323 return fStack->Particle(i);
1326 //_____________________________________________________________________________
1327 void AliRun::BeginEvent()
1329 // Clean-up previous event
1331 fEventEnergy.Reset();
1332 // Clean detector information
1339 // Reset all Detectors & kinematics & trees
1343 // Initialise event header
1344 fHeader->Reset(fRun,fEvent,fEventNrInRun);
1346 fStack->BeginEvent(fEvent);
1350 fLego->BeginEvent();
1363 sprintf(hname,"TreeH%d",fEvent);
1364 fTreeH->SetName(hname);
1368 sprintf(hname,"TreeD%d",fEvent);
1369 fTreeD->SetName(hname);
1370 fTreeD->Write(0,TObject::kOverwrite);
1374 sprintf(hname,"TreeS%d",fEvent);
1375 fTreeS->SetName(hname);
1376 fTreeS->Write(0,TObject::kOverwrite);
1380 sprintf(hname,"TreeR%d",fEvent);
1381 fTreeR->SetName(hname);
1382 fTreeR->Write(0,TObject::kOverwrite);
1385 //_____________________________________________________________________________
1386 void AliRun::ResetDigits()
1389 // Reset all Detectors digits
1391 TIter next(fModules);
1392 AliModule *detector;
1393 while((detector = (AliModule*)next())) {
1394 detector->ResetDigits();
1398 //_____________________________________________________________________________
1399 void AliRun::ResetSDigits()
1402 // Reset all Detectors digits
1404 TIter next(fModules);
1405 AliModule *detector;
1406 while((detector = (AliModule*)next())) {
1407 detector->ResetSDigits();
1411 //_____________________________________________________________________________
1412 void AliRun::ResetHits()
1415 // Reset all Detectors hits
1417 TIter next(fModules);
1418 AliModule *detector;
1419 while((detector = (AliModule*)next())) {
1420 detector->ResetHits();
1424 //_____________________________________________________________________________
1425 void AliRun::ResetPoints()
1428 // Reset all Detectors points
1430 TIter next(fModules);
1431 AliModule *detector;
1432 while((detector = (AliModule*)next())) {
1433 detector->ResetPoints();
1437 //_____________________________________________________________________________
1438 void AliRun::RunMC(Int_t nevent, const char *setup)
1441 // Main function to be called to process a galice run
1443 // Root > gAlice.Run();
1444 // a positive number of events will cause the finish routine
1447 fEventsPerRun = nevent;
1448 // check if initialisation has been done
1449 if (!fInitDone) InitMC(setup);
1451 // Create the Root Tree with one branch per detector
1455 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1456 MakeTree("K","Kine.root");
1457 MakeTree("H","Hits.root");
1462 gMC->ProcessRun(nevent);
1464 // End of this run, close files
1465 if(nevent>0) FinishRun();
1468 //_____________________________________________________________________________
1469 void AliRun::RunReco(const char *selected, Int_t first, Int_t last)
1472 // Main function to be called to reconstruct Alice event
1474 cout << "Found "<< gAlice->TreeE()->GetEntries() << "events" << endl;
1475 Int_t nFirst = first;
1476 Int_t nLast = (last < 0)? (Int_t) gAlice->TreeE()->GetEntries() : last;
1478 for (Int_t nevent = nFirst; nevent <= nLast; nevent++) {
1479 cout << "Processing event "<< nevent << endl;
1482 Digits2Reco(selected);
1486 //_____________________________________________________________________________
1488 void AliRun::Hits2Digits(const char *selected)
1491 // Convert Hits to sumable digits
1493 for (Int_t nevent=0; nevent<gAlice->TreeE()->GetEntries(); nevent++) {
1496 Hits2SDigits(selected);
1497 SDigits2Digits(selected);
1502 //_____________________________________________________________________________
1504 void AliRun::Tree2Tree(Option_t *option, const char *selected)
1507 // Function to transform the content of
1509 // - TreeH to TreeS (option "S")
1510 // - TreeS to TreeD (option "D")
1511 // - TreeD to TreeR (option "R")
1513 // If multiple options are specified ("SDR"), transformation will be done in sequence for
1514 // selected detector and for all detectors if none is selected (detector string
1515 // can contain blank separated list of detector names).
1518 const char *oS = strstr(option,"S");
1519 const char *oD = strstr(option,"D");
1520 const char *oR = strstr(option,"R");
1522 TObjArray *detectors = Detectors();
1524 TIter next(detectors);
1526 AliDetector *detector = 0;
1528 TDirectory *cwd = gDirectory;
1532 while((detector = (AliDetector*)next())) {
1534 if (strcmp(detector->GetName(),selected)) continue;
1535 if (detector->IsActive()){
1536 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1538 sprintf(outFile,"SDigits.%s.root",detector->GetName());
1539 detector->MakeBranch("S",outFile);
1542 sprintf(outFile,"Digits.%s.root",detector->GetName());
1543 detector->MakeBranch("D",outFile);
1546 sprintf(outFile,"Reco.%s.root",detector->GetName());
1547 detector->MakeBranch("R",outFile);
1550 detector->MakeBranch(option);
1556 cout << "Hits2SDigits: Processing " << detector->GetName() << "..." << endl;
1557 detector->Hits2SDigits();
1560 cout << "SDigits2Digits: Processing " << detector->GetName() << "..." << endl;
1561 detector->SDigits2Digits();
1564 cout << "Digits2Reco: Processing " << detector->GetName() << "..." << endl;
1565 detector->Digits2Reco();
1574 //_____________________________________________________________________________
1575 void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min,
1576 Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max,
1577 Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener)
1580 // Generates lego plots of:
1581 // - radiation length map phi vs theta
1582 // - radiation length map phi vs eta
1583 // - interaction length map
1584 // - g/cm2 length map
1586 // ntheta bins in theta, eta
1587 // themin minimum angle in theta (degrees)
1588 // themax maximum angle in theta (degrees)
1590 // phimin minimum angle in phi (degrees)
1591 // phimax maximum angle in phi (degrees)
1592 // rmin minimum radius
1593 // rmax maximum radius
1596 // The number of events generated = ntheta*nphi
1597 // run input parameters in macro setup (default="Config.C")
1599 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1602 <img src="picts/AliRunLego1.gif">
1607 <img src="picts/AliRunLego2.gif">
1612 <img src="picts/AliRunLego3.gif">
1617 // check if initialisation has been done
1618 if (!fInitDone) InitMC(setup);
1619 //Save current generator
1620 AliGenerator *gen=Generator();
1622 // Set new generator
1623 if (!gener) gener = new AliLegoGenerator();
1624 ResetGenerator(gener);
1626 // Configure Generator
1627 gener->SetRadiusRange(rmin, rmax);
1628 gener->SetZMax(zmax);
1629 gener->SetCoor1Range(nc1, c1min, c1max);
1630 gener->SetCoor2Range(nc2, c2min, c2max);
1633 //Create Lego object
1634 fLego = new AliLego("lego",gener);
1636 //Prepare MC for Lego Run
1641 gMC->ProcessRun(nc1*nc2+1);
1643 // Create only the Root event Tree
1646 // End of this run, close files
1648 // Restore current generator
1649 ResetGenerator(gen);
1650 // Delete Lego Object
1651 delete fLego; fLego=0;
1654 //_____________________________________________________________________________
1655 void AliRun::SetConfigFunction(const char * config)
1658 // Set the signature of the function contained in Config.C to configure
1661 fConfigFunction=config;
1664 //_____________________________________________________________________________
1665 void AliRun::SetCurrentTrack(Int_t track)
1668 // Set current track number
1670 fStack->SetCurrentTrack(track);
1673 //_____________________________________________________________________________
1674 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1675 Float_t *vpos, Float_t *polar, Float_t tof,
1676 AliMCProcess mech, Int_t &ntr, Float_t weight)
1678 // Delegate to stack
1680 fStack->SetTrack(done, parent, pdg, pmom, vpos, polar, tof,
1684 //_____________________________________________________________________________
1685 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg,
1686 Double_t px, Double_t py, Double_t pz, Double_t e,
1687 Double_t vx, Double_t vy, Double_t vz, Double_t tof,
1688 Double_t polx, Double_t poly, Double_t polz,
1689 AliMCProcess mech, Int_t &ntr, Float_t weight)
1691 // Delegate to stack
1693 fStack->SetTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
1694 polx, poly, polz, mech, ntr, weight);
1698 //_____________________________________________________________________________
1699 void AliRun::SetHighWaterMark(const Int_t nt)
1702 // Set high water mark for last track in event
1703 fStack->SetHighWaterMark(nt);
1706 //_____________________________________________________________________________
1707 void AliRun::KeepTrack(const Int_t track)
1710 // Delegate to stack
1712 fStack->KeepTrack(track);
1715 //_____________________________________________________________________________
1716 void AliRun::StepManager(Int_t id)
1719 // Called at every step during transport
1723 // --- If lego option, do it and leave
1725 fLego->StepManager();
1728 //Update energy deposition tables
1729 AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
1731 //Call the appropriate stepping routine;
1732 AliModule *det = (AliModule*)fModules->At(id);
1734 fMCQA->StepManager(id);
1740 //_____________________________________________________________________________
1741 void AliRun::Streamer(TBuffer &R__b)
1743 // Stream an object of class AliRun.
1745 if (R__b.IsReading()) {
1746 if (!gAlice) gAlice = this;
1748 AliRun::Class()->ReadBuffer(R__b, this);
1750 gROOT->GetListOfBrowsables()->Add(this,"Run");
1752 fTreeE = (TTree*)gDirectory->Get("TE");
1754 fTreeE->SetBranchAddress("Header", &fHeader);
1757 else Error("Streamer","cannot find Header Tree\n");
1758 fTreeE->GetEntry(0);
1762 AliRun::Class()->WriteBuffer(R__b, this);
1767 //___________________________________________________________________________
1768 Int_t AliRun::CurrentTrack() const {
1770 // Returns current track
1772 return fStack->CurrentTrack();
1775 //___________________________________________________________________________
1776 Int_t AliRun::GetNtrack() const {
1778 // Returns number of tracks in stack
1780 return fStack->GetNtrack();
1783 //___________________________________________________________________________
1784 TObjArray* AliRun::Particles() {
1786 // Returns pointer to Particles array
1788 return fStack->Particles();
1791 //___________________________________________________________________________
1792 TTree* AliRun::TreeK() {
1794 // Returns pointer to the TreeK array
1796 return fStack->TreeK();
1800 void AliRun::SetGenEventHeader(AliGenEventHeader* header)
1802 fHeader->SetGenEventHeader(header);