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.66 2001/05/22 14:32:40 hristov
21 Revision 1.65 2001/05/21 17:22:51 buncic
22 Fixed problem with missing AliConfig while reading galice.root
24 Revision 1.64 2001/05/16 14:57:22 alibrary
25 New files for folders and Stack
27 Revision 1.62 2001/04/06 11:12:33 morsch
28 Clear fParticles after each event. (Ivana Hrivnacova)
30 Revision 1.61 2001/03/30 07:04:10 morsch
31 Call fGenerator->FinishRun() for final print-outs, cross-section and weight calculations.
33 Revision 1.60 2001/03/21 18:22:30 hristov
34 fParticleFileMap fix (I.Hrivnacova)
36 Revision 1.59 2001/03/12 17:47:03 hristov
37 Changes needed on Sun with CC 5.0
39 Revision 1.58 2001/03/09 14:27:26 morsch
40 Fix for multiple events per file: inhibit decrease of size of fParticleFileMap.
42 Revision 1.57 2001/02/23 17:40:23 buncic
43 All trees needed for simulation created in RunMC(). TreeR and its branches
44 are now created in new RunReco() method.
46 Revision 1.56 2001/02/14 15:45:20 hristov
47 Algorithmic way of getting entry index in fParticleMap. Protection of fParticleFileMap (I.Hrivnacova)
49 Revision 1.55 2001/02/12 15:52:54 buncic
50 Removed OpenBaseFile().
52 Revision 1.54 2001/02/07 10:39:05 hristov
53 Remove default value for argument
55 Revision 1.53 2001/02/06 11:02:26 hristov
56 New SetTrack interface added, added check for unfilled particles in FinishEvent (I.Hrivnacova)
58 Revision 1.52 2001/02/05 16:22:25 buncic
59 Added TreeS to GetEvent().
61 Revision 1.51 2001/02/02 15:16:20 morsch
62 SetHighWaterMark method added to mark last particle in event.
64 Revision 1.50 2001/01/27 10:32:00 hristov
65 Leave the loop when primaries are filled (I.Hrivnacova)
67 Revision 1.49 2001/01/26 19:58:48 hristov
68 Major upgrade of AliRoot code
70 Revision 1.48 2001/01/17 10:50:50 hristov
71 Corrections to destructors
73 Revision 1.47 2000/12/18 10:44:01 morsch
74 Possibility to set field map by passing pointer to objet of type AliMagF via
77 gAlice->SetField(new AliMagFCM("Map2", "$(ALICE_ROOT)/data/field01.dat",2,1.,10.));
79 Revision 1.46 2000/12/14 19:29:27 fca
80 galice.cuts was not read any more
82 Revision 1.45 2000/11/30 07:12:49 alibrary
83 Introducing new Rndm and QA classes
85 Revision 1.44 2000/10/26 13:58:59 morsch
86 Add possibility to choose the lego generator (of type AliGeneratorLego or derived) when running
87 RunLego(). Default is the base class AliGeneratorLego.
89 Revision 1.43 2000/10/09 09:43:17 fca
90 Special remapping of hits for TPC and TRD. End-of-primary action introduced
92 Revision 1.42 2000/10/02 21:28:14 fca
93 Removal of useless dependecies via forward declarations
95 Revision 1.41 2000/07/13 16:19:09 fca
96 Mainly coding conventions + some small bug fixes
98 Revision 1.40 2000/07/12 08:56:25 fca
99 Coding convention correction and warning removal
101 Revision 1.39 2000/07/11 18:24:59 fca
102 Coding convention corrections + few minor bug fixes
104 Revision 1.38 2000/06/20 13:05:45 fca
105 Writing down the TREE headers before job starts
107 Revision 1.37 2000/06/09 20:05:11 morsch
108 Introduce possibility to chose magnetic field version 3: AliMagFDM + field02.dat
110 Revision 1.36 2000/06/08 14:03:58 hristov
111 Only one initializer for a default argument
113 Revision 1.35 2000/06/07 10:13:14 hristov
114 Delete only existent objects.
116 Revision 1.34 2000/05/18 10:45:38 fca
117 Delete Particle Factory properly
119 Revision 1.33 2000/05/16 13:10:40 fca
120 New method IsNewTrack and fix for a problem in Father-Daughter relations
122 Revision 1.32 2000/04/27 10:38:21 fca
123 Correct termination of Lego Run and introduce Lego getter in AliRun
125 Revision 1.31 2000/04/26 10:17:32 fca
126 Changes in Lego for G4 compatibility
128 Revision 1.30 2000/04/18 19:11:40 fca
129 Introduce variable Config.C function signature
131 Revision 1.29 2000/04/07 11:12:34 fca
132 G4 compatibility changes
134 Revision 1.28 2000/04/05 06:51:06 fca
135 Workaround for an HP compiler problem
137 Revision 1.27 2000/03/22 18:08:07 fca
138 Rationalisation of the virtual MC interfaces
140 Revision 1.26 2000/03/22 13:42:26 fca
141 SetGenerator does not replace an existing generator, ResetGenerator does
143 Revision 1.25 2000/02/23 16:25:22 fca
144 AliVMC and AliGeant3 classes introduced
145 ReadEuclid moved from AliRun to AliModule
147 Revision 1.24 2000/01/19 17:17:20 fca
148 Introducing a list of lists of hits -- more hits allowed for detector now
150 Revision 1.23 1999/12/03 11:14:31 fca
151 Fixing previous wrong checking
153 Revision 1.21 1999/11/25 10:40:08 fca
154 Fixing daughters information also in primary tracks
156 Revision 1.20 1999/10/04 18:08:49 fca
157 Adding protection against inconsistent Euclid files
159 Revision 1.19 1999/09/29 07:50:40 fca
160 Introduction of the Copyright and cvs Log
164 ///////////////////////////////////////////////////////////////////////////////
166 // Control class for Alice C++ //
167 // Only one single instance of this class exists. //
168 // The object is created in main program aliroot //
169 // and is pointed by the global gAlice. //
171 // -Supports the list of all Alice Detectors (fModules). //
172 // -Supports the list of particles (fParticles). //
173 // -Supports the Trees. //
174 // -Supports the geometry. //
175 // -Supports the event display. //
178 <img src="picts/AliRunClass.gif">
183 <img src="picts/alirun.gif">
187 ///////////////////////////////////////////////////////////////////////////////
192 #include <iostream.h>
200 #include <TObjectTable.h>
202 #include <TGeometry.h>
204 #include <TBrowser.h>
207 #include "TParticle.h"
209 #include "AliDisplay.h"
212 #include "AliMagFC.h"
213 #include "AliMagFCM.h"
214 #include "AliMagFDM.h"
216 #include "TRandom3.h"
218 #include "AliGenerator.h"
219 #include "AliLegoGenerator.h"
220 #include "AliConfig.h"
221 #include "AliStack.h"
222 #include "AliGenEventHeader.h"
223 #include "AliHeader.h"
225 #include "AliDetector.h"
231 //_____________________________________________________________________________
235 // Default constructor for AliRun
258 fPDGDB = 0; //Particle factory object!
260 fConfigFunction = "\0";
263 fTransParName = "\0";
264 fBaseFileName = ".\0";
268 //_____________________________________________________________________________
269 AliRun::AliRun(const char *name, const char *title)
273 // Constructor for the main processor.
274 // Creates the geometry
275 // Creates the list of Detectors.
276 // Creates the list of particles.
292 fConfigFunction = "Config();";
294 // Set random number generator
295 gRandom = fRandom = new TRandom3();
297 if (gSystem->Getenv("CONFIG_SEED")) {
298 gRandom->SetSeed((UInt_t)atoi(gSystem->Getenv("CONFIG_SEED")));
301 gROOT->GetListOfBrowsables()->Add(this,name);
304 fStack = new AliStack(10000);
305 // create the support list for the various Detectors
306 fModules = new TObjArray(77);
308 // Create the TNode geometry for the event display
310 BuildSimpleGeometry();
312 fHeader = new AliHeader();
318 // Create default mag field
323 // Prepare the tracking medium lists
324 fImedia = new TArrayI(1000);
325 for(i=0;i<1000;i++) (*fImedia)[i]=-99;
328 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
330 AliConfig::Instance()->Add(fPDGDB);
332 // Create HitLists list
333 fHitLists = new TList();
336 fBaseFileName = ".\0";
342 //_____________________________________________________________________________
346 // Default AliRun destructor
371 //_____________________________________________________________________________
372 void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
375 // Add a hit to detector id
377 TObjArray &dets = *fModules;
378 if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits);
381 //_____________________________________________________________________________
382 void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
385 // Add digit to detector id
387 TObjArray &dets = *fModules;
388 if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits);
391 //_____________________________________________________________________________
392 void AliRun::Browse(TBrowser *b)
395 // Called when the item "Run" is clicked on the left pane
396 // of the Root browser.
397 // It displays the Root Trees and all detectors.
399 if(!fStack) fStack=fHeader->Stack();
400 TTree* pTreeK = fStack->TreeK();
402 if (pTreeK) b->Add(pTreeK,pTreeK->GetName());
403 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
404 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
405 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
406 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
407 if (fTreeS) b->Add(fTreeS,fTreeS->GetName());
409 TIter next(fModules);
411 while((detector = (AliModule*)next())) {
412 b->Add(detector,detector->GetName());
414 b->Add(fMCQA,"AliMCQA");
417 //_____________________________________________________________________________
421 // Initialize Alice geometry
426 //_____________________________________________________________________________
427 void AliRun::BuildSimpleGeometry()
430 // Create a simple TNode geometry used by Root display engine
432 // Initialise geometry
434 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
435 new TMaterial("void","Vacuum",0,0,0); //Everything is void
436 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
437 brik->SetVisibility(0);
438 new TNode("alice","alice","S_alice");
441 //_____________________________________________________________________________
442 void AliRun::CleanDetectors()
445 // Clean Detectors at the end of event
447 TIter next(fModules);
449 while((detector = (AliModule*)next())) {
450 detector->FinishEvent();
454 //_____________________________________________________________________________
455 Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
458 // Return the distance from the mouse to the AliRun object
464 //_____________________________________________________________________________
465 void AliRun::DumpPart (Int_t i) const
468 // Dumps particle i in the stack
473 //_____________________________________________________________________________
474 void AliRun::DumpPStack () const
477 // Dumps the particle stack
479 fStack->DumpPStack();
482 //_____________________________________________________________________________
483 void AliRun::SetField(AliMagF* magField)
485 // Set Magnetic Field Map
490 //_____________________________________________________________________________
491 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
492 Float_t maxField, char* filename)
495 // Set magnetic field parameters
496 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
497 // version Magnetic field map version (only 1 active now)
498 // scale Scale factor for the magnetic field
499 // maxField Maximum value for the magnetic field
502 // --- Sanity check on mag field flags
503 if(fField) delete fField;
505 fField = new AliMagFC("Map1"," ",type,scale,maxField);
506 } else if(version<=2) {
507 fField = new AliMagFCM("Map2-3",filename,type,scale,maxField);
509 } else if(version==3) {
510 fField = new AliMagFDM("Map4",filename,type,scale,maxField);
513 Warning("SetField","Invalid map %d\n",version);
517 //_____________________________________________________________________________
518 void AliRun::PreTrack()
520 TObjArray &dets = *fModules;
523 for(Int_t i=0; i<=fNdets; i++)
524 if((module = (AliModule*)dets[i]))
530 //_____________________________________________________________________________
531 void AliRun::PostTrack()
533 TObjArray &dets = *fModules;
536 for(Int_t i=0; i<=fNdets; i++)
537 if((module = (AliModule*)dets[i]))
541 //_____________________________________________________________________________
542 void AliRun::FinishPrimary()
545 // Called at the end of each primary track
548 // static Int_t count=0;
549 // const Int_t times=10;
550 // This primary is finished, purify stack
551 fStack->PurifyKine();
553 TIter next(fModules);
555 while((detector = (AliModule*)next())) {
556 detector->FinishPrimary();
559 // Write out hits if any
560 if (gAlice->TreeH()) {
561 gAlice->TreeH()->Fill();
565 // if(++count%times==1) gObjectTable->Print();
568 //_____________________________________________________________________________
569 void AliRun::BeginPrimary()
572 // Called at the beginning of each primary track
580 //_____________________________________________________________________________
581 void AliRun::FinishEvent()
584 // Called at the end of the event.
588 if(fLego) fLego->FinishEvent();
590 //Update the energy deposit tables
592 for(i=0;i<fEventEnergy.GetSize();i++) {
593 fSummEnergy[i]+=fEventEnergy[i];
594 fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
599 // Update Header information
601 fHeader->SetNprimary(fStack->GetNprimary());
602 fHeader->SetNtrack(fStack->GetNtrack());
605 // Write out the kinematics
606 fStack->FinishEvent();
608 // Write out the event Header information
610 fHeader->SetStack(fStack);
615 // Write Tree headers
616 TTree* pTreeK = fStack->TreeK();
617 if (pTreeK) pTreeK->Write(0,TObject::kOverwrite);
618 if (fTreeH) fTreeH->Write(0,TObject::kOverwrite);
623 //_____________________________________________________________________________
624 void AliRun::FinishRun()
627 // Called at the end of the run.
631 if(fLego) fLego->FinishRun();
633 // Clean detector information
634 TIter next(fModules);
636 while((detector = (AliModule*)next())) {
637 detector->FinishRun();
640 //Output energy summary tables
643 TFile *file = fTreeE->GetCurrentFile();
647 fTreeE->Write(0,TObject::kOverwrite);
649 // Write AliRun info and all detectors parameters
650 Write(0,TObject::kOverwrite);
652 // Clean tree information
657 delete fTreeH; fTreeH = 0;
660 delete fTreeD; fTreeD = 0;
663 delete fTreeR; fTreeR = 0;
666 delete fTreeE; fTreeE = 0;
669 delete fTreeS; fTreeS = 0;
676 //_____________________________________________________________________________
677 void AliRun::FlagTrack(Int_t track)
681 fStack->FlagTrack(track);
684 //_____________________________________________________________________________
685 void AliRun::EnergySummary()
688 // Print summary of deposited energy
694 Int_t kn, i, left, j, id;
695 const Float_t kzero=0;
696 Int_t ievent=fHeader->GetEvent()+1;
698 // Energy loss information
700 printf("***************** Energy Loss Information per event (GEV) *****************\n");
701 for(kn=1;kn<fEventEnergy.GetSize();kn++) {
704 fEventEnergy[ndep]=kn;
709 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,kzero))/ed;
712 fSummEnergy[ndep]=ed;
713 fSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,kzero));
718 for(kn=0;kn<(ndep-1)/3+1;kn++) {
720 for(i=0;i<(3<left?3:left);i++) {
722 id=Int_t (fEventEnergy[j]+0.1);
723 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]);
728 // Relative energy loss in different detectors
729 printf("******************** Relative Energy Loss per event ********************\n");
730 printf("Total energy loss per event %10.3f GeV\n",edtot);
731 for(kn=0;kn<(ndep-1)/5+1;kn++) {
733 for(i=0;i<(5<left?5:left);i++) {
735 id=Int_t (fEventEnergy[j]+0.1);
736 printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot);
740 for(kn=0;kn<75;kn++) printf("*");
744 // Reset the TArray's
745 // fEventEnergy.Set(0);
746 // fSummEnergy.Set(0);
747 // fSum2Energy.Set(0);
750 //_____________________________________________________________________________
751 AliModule *AliRun::GetModule(const char *name) const
754 // Return pointer to detector from name
756 return (AliModule*)fModules->FindObject(name);
759 //_____________________________________________________________________________
760 AliDetector *AliRun::GetDetector(const char *name) const
763 // Return pointer to detector from name
765 return (AliDetector*)fModules->FindObject(name);
768 //_____________________________________________________________________________
769 Int_t AliRun::GetModuleID(const char *name) const
772 // Return galice internal detector identifier from name
775 TObject *mod=fModules->FindObject(name);
776 if(mod) i=fModules->IndexOf(mod);
780 //_____________________________________________________________________________
781 Int_t AliRun::GetEvent(Int_t event)
784 // Connect the Trees Kinematics and Hits for event # event
785 // Set branch addresses
788 // Reset existing structures
793 // Delete Trees already connected
794 if (fTreeH) delete fTreeH;
795 if (fTreeD) delete fTreeD;
796 if (fTreeR) delete fTreeR;
797 if (fTreeS) delete fTreeS;
799 // Create the particle stack
800 if (fHeader) delete fHeader;
803 // Get header from file
805 fTreeE->SetBranchAddress("Header", &fHeader);
806 fTreeE->GetEntry(event);
809 Error("GetEvent","Cannot find Header Tree (TE)\n");
811 // Get the stack from the header
812 if (fStack) delete fStack;
813 fStack = fHeader->Stack();
814 fStack->GetEvent(event);
816 TFile *file = fTreeE->GetCurrentFile();
820 // Get Hits Tree header from file
821 sprintf(treeName,"TreeH%d",event);
822 fTreeH = (TTree*)gDirectory->Get(treeName);
824 Error("GetEvent","cannot find Hits Tree for event:%d\n",event);
827 // Get Digits Tree header from file
828 sprintf(treeName,"TreeD%d",event);
829 fTreeD = (TTree*)gDirectory->Get(treeName);
831 // Warning("GetEvent","cannot find Digits Tree for event:%d\n",event);
836 // Get SDigits Tree header from file
837 sprintf(treeName,"TreeS%d",event);
838 fTreeS = (TTree*)gDirectory->Get(treeName);
840 // Warning("GetEvent","cannot find SDigits Tree for event:%d\n",event);
845 // Get Reconstruct Tree header from file
846 sprintf(treeName,"TreeR%d",event);
847 fTreeR = (TTree*)gDirectory->Get(treeName);
849 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
854 // Set Trees branch addresses
855 TIter next(fModules);
857 while((detector = (AliModule*)next())) {
858 detector->SetTreeAddress();
861 return fStack->GetNtrack();
864 //_____________________________________________________________________________
865 TGeometry *AliRun::GetGeometry()
868 // Import Alice geometry from current file
869 // Return pointer to geometry object
871 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
873 // Unlink and relink nodes in detectors
874 // This is bad and there must be a better way...
877 TIter next(fModules);
879 while((detector = (AliModule*)next())) {
880 TList *dnodes=detector->Nodes();
883 for ( j=0; j<dnodes->GetSize(); j++) {
884 node = (TNode*) dnodes->At(j);
885 node1 = fGeometry->GetNode(node->GetName());
886 dnodes->Remove(node);
887 dnodes->AddAt(node1,j);
893 //_____________________________________________________________________________
894 void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
895 Float_t &e, Float_t *vpos, Float_t *polar,
900 fStack->GetNextTrack(mtrack, ipart, pmom, e, vpos, polar, tof);
903 //_____________________________________________________________________________
904 Int_t AliRun::GetPrimary(Int_t track) const
907 // return number of primary that has generated track
909 return fStack->GetPrimary(track);
912 //_____________________________________________________________________________
913 void AliRun::InitMC(const char *setup)
916 // Initialize the Alice setup
920 Warning("Init","Cannot initialise AliRun twice!\n");
924 gROOT->LoadMacro(setup);
925 gInterpreter->ProcessLine(fConfigFunction.Data());
928 gMC->DefineParticles(); //Create standard MC particles
930 TObject *objfirst, *objlast;
932 fNdets = fModules->GetLast()+1;
935 //=================Create Materials and geometry
938 // Added also after in case of interactive initialisation of modules
939 fNdets = fModules->GetLast()+1;
941 TIter next(fModules);
943 while((detector = (AliModule*)next())) {
944 detector->SetTreeAddress();
945 objlast = gDirectory->GetList()->Last();
947 // Add Detector histograms in Detector list of histograms
948 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
949 else objfirst = gDirectory->GetList()->First();
951 detector->Histograms()->Add(objfirst);
952 objfirst = gDirectory->GetList()->After(objfirst);
955 ReadTransPar(); //Read the cuts for all materials
957 MediaTable(); //Build the special IMEDIA table
959 //Initialise geometry deposition table
960 fEventEnergy.Set(gMC->NofVolumes()+1);
961 fSummEnergy.Set(gMC->NofVolumes()+1);
962 fSum2Energy.Set(gMC->NofVolumes()+1);
964 //Compute cross-sections
967 //Write Geometry object to current file.
972 fMCQA = new AliMCQA(fNdets);
974 AliConfig::Instance();
976 // Save stuff at the beginning of the file to avoid file corruption
980 //_____________________________________________________________________________
981 void AliRun::MediaTable()
984 // Built media table to get from the media number to
987 Int_t kz, nz, idt, lz, i, k, ind;
989 TObjArray &dets = *gAlice->Detectors();
993 for (kz=0;kz<fNdets;kz++) {
994 // If detector is defined
995 if((det=(AliModule*) dets[kz])) {
996 TArrayI &idtmed = *(det->GetIdtmed());
997 for(nz=0;nz<100;nz++) {
998 // Find max and min material number
999 if((idt=idtmed[nz])) {
1000 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
1001 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
1004 if(det->LoMedium() > det->HiMedium()) {
1005 det->LoMedium() = 0;
1006 det->HiMedium() = 0;
1008 if(det->HiMedium() > fImedia->GetSize()) {
1009 Error("MediaTable","Increase fImedia from %d to %d",
1010 fImedia->GetSize(),det->HiMedium());
1013 // Tag all materials in rage as belonging to detector kz
1014 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
1021 // Print summary table
1022 printf(" Traking media ranges:\n");
1023 for(i=0;i<(fNdets-1)/6+1;i++) {
1024 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
1026 det=(AliModule*)dets[ind];
1028 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
1031 printf(" %6s: %3d -> %3d;","NULL",0,0);
1037 //____________________________________________________________________________
1038 void AliRun::SetGenerator(AliGenerator *generator)
1041 // Load the event generator
1043 if(!fGenerator) fGenerator = generator;
1046 //____________________________________________________________________________
1047 void AliRun::ResetGenerator(AliGenerator *generator)
1050 // Load the event generator
1054 Warning("ResetGenerator","Replacing generator %s with %s\n",
1055 fGenerator->GetName(),generator->GetName());
1057 Warning("ResetGenerator","Replacing generator %s with NULL\n",
1058 fGenerator->GetName());
1059 fGenerator = generator;
1062 //____________________________________________________________________________
1063 void AliRun::SetTransPar(char *filename)
1065 fTransParName = filename;
1068 //____________________________________________________________________________
1069 void AliRun::SetBaseFile(char *filename)
1071 fBaseFileName = filename;
1074 //____________________________________________________________________________
1075 void AliRun::ReadTransPar()
1078 // Read filename to set the transport parameters
1082 const Int_t kncuts=10;
1083 const Int_t knflags=11;
1084 const Int_t knpars=kncuts+knflags;
1085 const char kpars[knpars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
1086 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
1087 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
1088 "MULS","PAIR","PHOT","RAYL"};
1092 Float_t cut[kncuts];
1093 Int_t flag[knflags];
1094 Int_t i, itmed, iret, ktmed, kz;
1097 // See whether the file is there
1098 filtmp=gSystem->ExpandPathName(fTransParName.Data());
1099 lun=fopen(filtmp,"r");
1102 Warning("ReadTransPar","File %s does not exist!\n",fTransParName.Data());
1107 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1108 printf(" *%59s\n","*");
1109 printf(" * Please check carefully what you are doing!%10s\n","*");
1110 printf(" *%59s\n","*");
1114 // Initialise cuts and flags
1115 for(i=0;i<kncuts;i++) cut[i]=-99;
1116 for(i=0;i<knflags;i++) flag[i]=-99;
1118 for(i=0;i<256;i++) line[i]='\0';
1119 // Read up to the end of line excluded
1120 iret=fscanf(lun,"%[^\n]",line);
1125 printf(" *%59s\n","*");
1126 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1130 // Read the end of line
1133 if(line[0]=='*') continue;
1135 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",
1136 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
1137 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
1138 &flag[8],&flag[9],&flag[10]);
1142 Warning("ReadTransPar","Error reading file %s\n",fTransParName.Data());
1145 // Check that the module exist
1146 AliModule *mod = GetModule(detName);
1148 // Get the array of media numbers
1149 TArrayI &idtmed = *mod->GetIdtmed();
1150 // Check that the tracking medium code is valid
1151 if(0<=itmed && itmed < 100) {
1152 ktmed=idtmed[itmed];
1154 Warning("ReadTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
1157 // Set energy thresholds
1158 for(kz=0;kz<kncuts;kz++) {
1160 if(fDebug) printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
1161 kpars[kz],cut[kz],itmed,mod->GetName());
1162 gMC->Gstpar(ktmed,kpars[kz],cut[kz]);
1165 // Set transport mechanisms
1166 for(kz=0;kz<knflags;kz++) {
1168 if(fDebug) printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
1169 kpars[kncuts+kz],flag[kz],itmed,mod->GetName());
1170 gMC->Gstpar(ktmed,kpars[kncuts+kz],Float_t(flag[kz]));
1174 Warning("ReadTransPar","Invalid medium code %d *\n",itmed);
1178 if(fDebug) printf("%s::ReadTransParModule: %s not present\n",ClassName(),detName);
1185 //_____________________________________________________________________________
1186 void AliRun::MakeTree(Option_t *option, const char *file)
1189 // Create the ROOT trees
1190 // Loop on all detectors to create the Root branch (if any)
1196 const char *oK = strstr(option,"K");
1197 const char *oH = strstr(option,"H");
1198 const char *oE = strstr(option,"E");
1199 const char *oD = strstr(option,"D");
1200 const char *oR = strstr(option,"R");
1201 const char *oS = strstr(option,"S");
1204 TDirectory *cwd = gDirectory;
1206 TBranch *branch = 0;
1208 if (oK) fStack->MakeTree(fEvent, file);
1210 if (oE && !fTreeE) {
1211 fTreeE = new TTree("TE","Header");
1212 branch = fTreeE->Branch("Header", "AliHeader", &fHeader, 4000, 0);
1213 branch->SetAutoDelete(kFALSE);
1214 TFolder *folder = (TFolder *)gROOT->FindObjectAny("/Folders/RunMC/Event/Header");
1215 if (folder) folder->Add(fHeader);
1216 // branch = fTreeE->Branch("Stack","AliStack", &fStack, 4000, 0);
1217 // branch->SetAutoDelete(kFALSE);
1218 // if (folder) folder->Add(fStack);
1219 fTreeE->Write(0,TObject::kOverwrite);
1222 if (file && branch) {
1223 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
1224 sprintf(outFile,"%s/%s",GetBaseFile(),file);
1225 branch->SetFile(outFile);
1226 TIter next( branch->GetListOfBranches());
1227 while ((branch=(TBranch*)next())) {
1228 branch->SetFile(outFile);
1231 printf("* MakeBranch * Diverting Branch %s to file %s\n", branch->GetName(),file);
1236 if (oH && !fTreeH) {
1237 sprintf(hname,"TreeH%d",fEvent);
1238 fTreeH = new TTree(hname,"Hits");
1239 fTreeH->SetAutoSave(1000000000); //no autosave
1240 fTreeH->Write(0,TObject::kOverwrite);
1242 if (oD && !fTreeD) {
1243 sprintf(hname,"TreeD%d",fEvent);
1244 fTreeD = new TTree(hname,"Digits");
1245 fTreeD->Write(0,TObject::kOverwrite);
1247 if (oS && !fTreeS) {
1248 sprintf(hname,"TreeS%d",fEvent);
1249 fTreeS = new TTree(hname,"SDigits");
1250 fTreeS->Write(0,TObject::kOverwrite);
1252 if (oR && !fTreeR) {
1253 sprintf(hname,"TreeR%d",fEvent);
1254 fTreeR = new TTree(hname,"Reconstruction");
1255 fTreeR->Write(0,TObject::kOverwrite);
1259 // Create a branch for hits/digits for each detector
1260 // Each branch is a TClonesArray. Each data member of the Hits classes
1261 // will be in turn a subbranch of the detector master branch
1262 TIter next(fModules);
1263 AliModule *detector;
1264 while((detector = (AliModule*)next())) {
1265 if (oH) detector->MakeBranch(option,file);
1269 //_____________________________________________________________________________
1270 TParticle* AliRun::Particle(Int_t i)
1272 return fStack->Particle(i);
1275 //_____________________________________________________________________________
1276 void AliRun::BeginEvent()
1278 // Clean-up previous event
1280 fEventEnergy.Reset();
1281 // Clean detector information
1288 // Reset all Detectors & kinematics & trees
1292 // Initialise event header
1293 fHeader->Reset(fRun,fEvent);
1295 fStack->BeginEvent(fEvent);
1299 fLego->BeginEvent();
1312 sprintf(hname,"TreeH%d",fEvent);
1313 fTreeH->SetName(hname);
1317 sprintf(hname,"TreeD%d",fEvent);
1318 fTreeD->SetName(hname);
1319 fTreeD->Write(0,TObject::kOverwrite);
1323 sprintf(hname,"TreeS%d",fEvent);
1324 fTreeS->SetName(hname);
1325 fTreeS->Write(0,TObject::kOverwrite);
1329 sprintf(hname,"TreeR%d",fEvent);
1330 fTreeR->SetName(hname);
1331 fTreeR->Write(0,TObject::kOverwrite);
1334 //_____________________________________________________________________________
1335 void AliRun::ResetDigits()
1338 // Reset all Detectors digits
1340 TIter next(fModules);
1341 AliModule *detector;
1342 while((detector = (AliModule*)next())) {
1343 detector->ResetDigits();
1347 //_____________________________________________________________________________
1348 void AliRun::ResetSDigits()
1351 // Reset all Detectors digits
1353 TIter next(fModules);
1354 AliModule *detector;
1355 while((detector = (AliModule*)next())) {
1356 detector->ResetSDigits();
1360 //_____________________________________________________________________________
1361 void AliRun::ResetHits()
1364 // Reset all Detectors hits
1366 TIter next(fModules);
1367 AliModule *detector;
1368 while((detector = (AliModule*)next())) {
1369 detector->ResetHits();
1373 //_____________________________________________________________________________
1374 void AliRun::ResetPoints()
1377 // Reset all Detectors points
1379 TIter next(fModules);
1380 AliModule *detector;
1381 while((detector = (AliModule*)next())) {
1382 detector->ResetPoints();
1386 //_____________________________________________________________________________
1387 void AliRun::RunMC(Int_t nevent, const char *setup)
1390 // Main function to be called to process a galice run
1392 // Root > gAlice.Run();
1393 // a positive number of events will cause the finish routine
1397 // check if initialisation has been done
1398 if (!fInitDone) InitMC(setup);
1400 // Create the Root Tree with one branch per detector
1404 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1405 MakeTree("K","Kine.root");
1406 MakeTree("H","Hits.root");
1411 gMC->ProcessRun(nevent);
1413 // End of this run, close files
1414 if(nevent>0) FinishRun();
1417 //_____________________________________________________________________________
1418 void AliRun::RunReco(const char *selected)
1421 // Main function to be called to reconstruct Alice event
1423 cout << "Found "<< gAlice->TreeE()->GetEntries() << "events" << endl;
1424 for (Int_t nevent=0; nevent<gAlice->TreeE()->GetEntries(); nevent++) {
1425 cout << "Processing event "<< nevent << endl;
1428 Digits2Reco(selected);
1432 //_____________________________________________________________________________
1434 void AliRun::Hits2Digits(const char *selected)
1437 // Convert Hits to sumable digits
1439 for (Int_t nevent=0; nevent<gAlice->TreeE()->GetEntries(); nevent++) {
1442 Hits2SDigits(selected);
1443 SDigits2Digits(selected);
1448 //_____________________________________________________________________________
1450 void AliRun::Tree2Tree(Option_t *option, const char *selected)
1453 // Function to transform the content of
1455 // - TreeH to TreeS (option "S")
1456 // - TreeS to TreeD (option "D")
1457 // - TreeD to TreeR (option "R")
1459 // If multiple options are specified ("SDR"), transformation will be done in sequence for
1460 // selected detector and for all detectors if none is selected (detector string
1461 // can contain blank separated list of detector names).
1464 const char *oS = strstr(option,"S");
1465 const char *oD = strstr(option,"D");
1466 const char *oR = strstr(option,"R");
1468 TObjArray *detectors = Detectors();
1470 TIter next(detectors);
1472 AliDetector *detector = 0;
1474 TDirectory *cwd = gDirectory;
1478 while((detector = (AliDetector*)next())) {
1480 if (strcmp(detector->GetName(),selected)) continue;
1481 if (detector->IsActive()){
1482 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1484 sprintf(outFile,"SDigits.%s.root",detector->GetName());
1485 detector->MakeBranch("S",outFile);
1488 sprintf(outFile,"Digits.%s.root",detector->GetName());
1489 detector->MakeBranch("D",outFile);
1492 sprintf(outFile,"Reco.%s.root",detector->GetName());
1493 detector->MakeBranch("R",outFile);
1496 detector->MakeBranch(option);
1502 cout << "Hits2SDigits: Processing " << detector->GetName() << "..." << endl;
1503 detector->Hits2SDigits();
1506 cout << "SDigits2Digits: Processing " << detector->GetName() << "..." << endl;
1507 detector->SDigits2Digits();
1510 cout << "Digits2Reco: Processing " << detector->GetName() << "..." << endl;
1511 detector->Digits2Reco();
1520 //_____________________________________________________________________________
1521 void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min,
1522 Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max,
1523 Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener)
1526 // Generates lego plots of:
1527 // - radiation length map phi vs theta
1528 // - radiation length map phi vs eta
1529 // - interaction length map
1530 // - g/cm2 length map
1532 // ntheta bins in theta, eta
1533 // themin minimum angle in theta (degrees)
1534 // themax maximum angle in theta (degrees)
1536 // phimin minimum angle in phi (degrees)
1537 // phimax maximum angle in phi (degrees)
1538 // rmin minimum radius
1539 // rmax maximum radius
1542 // The number of events generated = ntheta*nphi
1543 // run input parameters in macro setup (default="Config.C")
1545 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1548 <img src="picts/AliRunLego1.gif">
1553 <img src="picts/AliRunLego2.gif">
1558 <img src="picts/AliRunLego3.gif">
1563 // check if initialisation has been done
1564 if (!fInitDone) InitMC(setup);
1565 //Save current generator
1566 AliGenerator *gen=Generator();
1568 // Set new generator
1569 if (!gener) gener = new AliLegoGenerator();
1570 ResetGenerator(gener);
1572 // Configure Generator
1573 gener->SetRadiusRange(rmin, rmax);
1574 gener->SetZMax(zmax);
1575 gener->SetCoor1Range(nc1, c1min, c1max);
1576 gener->SetCoor2Range(nc2, c2min, c2max);
1579 //Create Lego object
1580 fLego = new AliLego("lego",gener);
1582 //Prepare MC for Lego Run
1587 gMC->ProcessRun(nc1*nc2+1);
1589 // Create only the Root event Tree
1592 // End of this run, close files
1594 // Restore current generator
1595 ResetGenerator(gen);
1596 // Delete Lego Object
1597 delete fLego; fLego=0;
1600 //_____________________________________________________________________________
1601 void AliRun::SetConfigFunction(const char * config)
1604 // Set the signature of the function contained in Config.C to configure
1607 fConfigFunction=config;
1610 //_____________________________________________________________________________
1611 void AliRun::SetCurrentTrack(Int_t track)
1614 // Set current track number
1616 fStack->SetCurrentTrack(track);
1619 //_____________________________________________________________________________
1620 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1621 Float_t *vpos, Float_t *polar, Float_t tof,
1622 AliMCProcess mech, Int_t &ntr, Float_t weight)
1624 // Delegate to stack
1626 fStack->SetTrack(done, parent, pdg, pmom, vpos, polar, tof,
1630 //_____________________________________________________________________________
1631 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg,
1632 Double_t px, Double_t py, Double_t pz, Double_t e,
1633 Double_t vx, Double_t vy, Double_t vz, Double_t tof,
1634 Double_t polx, Double_t poly, Double_t polz,
1635 AliMCProcess mech, Int_t &ntr, Float_t weight)
1637 // Delegate to stack
1639 fStack->SetTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
1640 polx, poly, polz, mech, ntr, weight);
1644 //_____________________________________________________________________________
1645 void AliRun::SetHighWaterMark(const Int_t nt)
1648 // Set high water mark for last track in event
1649 fStack->SetHighWaterMark(nt);
1652 //_____________________________________________________________________________
1653 void AliRun::KeepTrack(const Int_t track)
1656 // Delegate to stack
1658 fStack->KeepTrack(track);
1661 //_____________________________________________________________________________
1662 void AliRun::StepManager(Int_t id)
1665 // Called at every step during transport
1669 // --- If lego option, do it and leave
1671 fLego->StepManager();
1674 //Update energy deposition tables
1675 AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
1677 //Call the appropriate stepping routine;
1678 AliModule *det = (AliModule*)fModules->At(id);
1680 fMCQA->StepManager(id);
1686 //_____________________________________________________________________________
1687 void AliRun::Streamer(TBuffer &R__b)
1689 // Stream an object of class AliRun.
1691 if (R__b.IsReading()) {
1692 if (!gAlice) gAlice = this;
1694 AliRun::Class()->ReadBuffer(R__b, this);
1696 gROOT->GetListOfBrowsables()->Add(this,"Run");
1698 fTreeE = (TTree*)gDirectory->Get("TE");
1700 fTreeE->SetBranchAddress("Header", &fHeader);
1703 else Error("Streamer","cannot find Header Tree\n");
1704 fTreeE->GetEntry(0);
1708 AliRun::Class()->WriteBuffer(R__b, this);
1713 //___________________________________________________________________________
1714 Int_t AliRun::CurrentTrack() const {
1716 // Returns current track
1718 return fStack->CurrentTrack();
1721 //___________________________________________________________________________
1722 Int_t AliRun::GetNtrack() const {
1724 // Returns number of tracks in stack
1726 return fStack->GetNtrack();
1729 //___________________________________________________________________________
1730 TObjArray* AliRun::Particles() {
1732 // Returns pointer to Particles array
1734 return fStack->Particles();
1737 //___________________________________________________________________________
1738 TTree* AliRun::TreeK() {
1740 // Returns pointer to the TreeK array
1742 return fStack->TreeK();