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; fTreeH = 0;}
795 if (fTreeD) { delete fTreeD; fTreeD = 0;}
796 if (fTreeR) { delete fTreeR; fTreeR = 0;}
797 if (fTreeS) { delete fTreeS; fTreeS = 0;}
799 // Create the particle stack
800 if (fHeader) delete fHeader;
803 // Get header from file
805 fTreeE->SetBranchAddress("Header", &fHeader);
807 if (!fTreeE->GetEntry(event)) {
808 Error("GetEvent","Cannot find event:%d\n",event);
813 Error("GetEvent","Cannot find Header Tree (TE)\n");
817 // Get the stack from the header, set fStack to 0 if it
818 // fails to get event
819 if (fStack) delete fStack;
820 fStack = fHeader->Stack();
822 if (!fStack->GetEvent(event,0)) fStack = 0;
826 TFile *file = fTreeE->GetCurrentFile();
830 // Get Hits Tree header from file
831 sprintf(treeName,"TreeH%d",event);
832 fTreeH = (TTree*)gDirectory->Get(treeName);
834 Error("GetEvent","cannot find Hits Tree for event:%d\n",event);
837 // Get Digits Tree header from file
838 sprintf(treeName,"TreeD%d",event);
839 fTreeD = (TTree*)gDirectory->Get(treeName);
841 // Warning("GetEvent","cannot find Digits Tree for event:%d\n",event);
846 // Get SDigits Tree header from file
847 sprintf(treeName,"TreeS%d",event);
848 fTreeS = (TTree*)gDirectory->Get(treeName);
850 // Warning("GetEvent","cannot find SDigits Tree for event:%d\n",event);
855 // Get Reconstruct Tree header from file
856 sprintf(treeName,"TreeR%d",event);
857 fTreeR = (TTree*)gDirectory->Get(treeName);
859 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
864 // Set Trees branch addresses
865 TIter next(fModules);
867 while((detector = (AliModule*)next())) {
868 detector->SetTreeAddress();
871 return fStack->GetNtrack();
874 //_____________________________________________________________________________
875 TGeometry *AliRun::GetGeometry()
878 // Import Alice geometry from current file
879 // Return pointer to geometry object
881 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
883 // Unlink and relink nodes in detectors
884 // This is bad and there must be a better way...
887 TIter next(fModules);
889 while((detector = (AliModule*)next())) {
890 TList *dnodes=detector->Nodes();
893 for ( j=0; j<dnodes->GetSize(); j++) {
894 node = (TNode*) dnodes->At(j);
895 node1 = fGeometry->GetNode(node->GetName());
896 dnodes->Remove(node);
897 dnodes->AddAt(node1,j);
903 //_____________________________________________________________________________
904 void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
905 Float_t &e, Float_t *vpos, Float_t *polar,
910 fStack->GetNextTrack(mtrack, ipart, pmom, e, vpos, polar, tof);
913 //_____________________________________________________________________________
914 Int_t AliRun::GetPrimary(Int_t track) const
917 // return number of primary that has generated track
919 return fStack->GetPrimary(track);
922 //_____________________________________________________________________________
923 void AliRun::InitMC(const char *setup)
926 // Initialize the Alice setup
930 Warning("Init","Cannot initialise AliRun twice!\n");
934 gROOT->LoadMacro(setup);
935 gInterpreter->ProcessLine(fConfigFunction.Data());
938 gMC->DefineParticles(); //Create standard MC particles
940 TObject *objfirst, *objlast;
942 fNdets = fModules->GetLast()+1;
945 //=================Create Materials and geometry
948 // Added also after in case of interactive initialisation of modules
949 fNdets = fModules->GetLast()+1;
951 TIter next(fModules);
953 while((detector = (AliModule*)next())) {
954 detector->SetTreeAddress();
955 objlast = gDirectory->GetList()->Last();
957 // Add Detector histograms in Detector list of histograms
958 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
959 else objfirst = gDirectory->GetList()->First();
961 detector->Histograms()->Add(objfirst);
962 objfirst = gDirectory->GetList()->After(objfirst);
965 ReadTransPar(); //Read the cuts for all materials
967 MediaTable(); //Build the special IMEDIA table
969 //Initialise geometry deposition table
970 fEventEnergy.Set(gMC->NofVolumes()+1);
971 fSummEnergy.Set(gMC->NofVolumes()+1);
972 fSum2Energy.Set(gMC->NofVolumes()+1);
974 //Compute cross-sections
977 //Write Geometry object to current file.
982 fMCQA = new AliMCQA(fNdets);
984 AliConfig *config = AliConfig::Instance();
986 // Save stuff at the beginning of the file to avoid file corruption
990 //_____________________________________________________________________________
991 void AliRun::MediaTable()
994 // Built media table to get from the media number to
997 Int_t kz, nz, idt, lz, i, k, ind;
999 TObjArray &dets = *gAlice->Detectors();
1002 // For all detectors
1003 for (kz=0;kz<fNdets;kz++) {
1004 // If detector is defined
1005 if((det=(AliModule*) dets[kz])) {
1006 TArrayI &idtmed = *(det->GetIdtmed());
1007 for(nz=0;nz<100;nz++) {
1008 // Find max and min material number
1009 if((idt=idtmed[nz])) {
1010 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
1011 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
1014 if(det->LoMedium() > det->HiMedium()) {
1015 det->LoMedium() = 0;
1016 det->HiMedium() = 0;
1018 if(det->HiMedium() > fImedia->GetSize()) {
1019 Error("MediaTable","Increase fImedia from %d to %d",
1020 fImedia->GetSize(),det->HiMedium());
1023 // Tag all materials in rage as belonging to detector kz
1024 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
1031 // Print summary table
1032 printf(" Traking media ranges:\n");
1033 for(i=0;i<(fNdets-1)/6+1;i++) {
1034 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
1036 det=(AliModule*)dets[ind];
1038 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
1041 printf(" %6s: %3d -> %3d;","NULL",0,0);
1047 //____________________________________________________________________________
1048 void AliRun::SetGenerator(AliGenerator *generator)
1051 // Load the event generator
1053 if(!fGenerator) fGenerator = generator;
1056 //____________________________________________________________________________
1057 void AliRun::ResetGenerator(AliGenerator *generator)
1060 // Load the event generator
1064 Warning("ResetGenerator","Replacing generator %s with %s\n",
1065 fGenerator->GetName(),generator->GetName());
1067 Warning("ResetGenerator","Replacing generator %s with NULL\n",
1068 fGenerator->GetName());
1069 fGenerator = generator;
1072 //____________________________________________________________________________
1073 void AliRun::SetTransPar(char *filename)
1075 fTransParName = filename;
1078 //____________________________________________________________________________
1079 void AliRun::SetBaseFile(char *filename)
1081 fBaseFileName = filename;
1084 //____________________________________________________________________________
1085 void AliRun::ReadTransPar()
1088 // Read filename to set the transport parameters
1092 const Int_t kncuts=10;
1093 const Int_t knflags=11;
1094 const Int_t knpars=kncuts+knflags;
1095 const char kpars[knpars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
1096 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
1097 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
1098 "MULS","PAIR","PHOT","RAYL"};
1102 Float_t cut[kncuts];
1103 Int_t flag[knflags];
1104 Int_t i, itmed, iret, ktmed, kz;
1107 // See whether the file is there
1108 filtmp=gSystem->ExpandPathName(fTransParName.Data());
1109 lun=fopen(filtmp,"r");
1112 Warning("ReadTransPar","File %s does not exist!\n",fTransParName.Data());
1117 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1118 printf(" *%59s\n","*");
1119 printf(" * Please check carefully what you are doing!%10s\n","*");
1120 printf(" *%59s\n","*");
1124 // Initialise cuts and flags
1125 for(i=0;i<kncuts;i++) cut[i]=-99;
1126 for(i=0;i<knflags;i++) flag[i]=-99;
1128 for(i=0;i<256;i++) line[i]='\0';
1129 // Read up to the end of line excluded
1130 iret=fscanf(lun,"%[^\n]",line);
1135 printf(" *%59s\n","*");
1136 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1140 // Read the end of line
1143 if(line[0]=='*') continue;
1145 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",
1146 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
1147 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
1148 &flag[8],&flag[9],&flag[10]);
1152 Warning("ReadTransPar","Error reading file %s\n",fTransParName.Data());
1155 // Check that the module exist
1156 AliModule *mod = GetModule(detName);
1158 // Get the array of media numbers
1159 TArrayI &idtmed = *mod->GetIdtmed();
1160 // Check that the tracking medium code is valid
1161 if(0<=itmed && itmed < 100) {
1162 ktmed=idtmed[itmed];
1164 Warning("ReadTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
1167 // Set energy thresholds
1168 for(kz=0;kz<kncuts;kz++) {
1170 if(fDebug) printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
1171 kpars[kz],cut[kz],itmed,mod->GetName());
1172 gMC->Gstpar(ktmed,kpars[kz],cut[kz]);
1175 // Set transport mechanisms
1176 for(kz=0;kz<knflags;kz++) {
1178 if(fDebug) printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
1179 kpars[kncuts+kz],flag[kz],itmed,mod->GetName());
1180 gMC->Gstpar(ktmed,kpars[kncuts+kz],Float_t(flag[kz]));
1184 Warning("ReadTransPar","Invalid medium code %d *\n",itmed);
1188 if(fDebug) printf("%s::ReadTransParModule: %s not present\n",ClassName(),detName);
1195 //_____________________________________________________________________________
1196 void AliRun::MakeTree(Option_t *option, const char *file)
1199 // Create the ROOT trees
1200 // Loop on all detectors to create the Root branch (if any)
1206 const char *oK = strstr(option,"K");
1207 const char *oH = strstr(option,"H");
1208 const char *oE = strstr(option,"E");
1209 const char *oD = strstr(option,"D");
1210 const char *oR = strstr(option,"R");
1211 const char *oS = strstr(option,"S");
1214 TDirectory *cwd = gDirectory;
1216 TBranch *branch = 0;
1218 if (oK) fStack->MakeTree(fEvent, file);
1220 if (oE && !fTreeE) {
1221 fTreeE = new TTree("TE","Header");
1222 branch = fTreeE->Branch("Header", "AliHeader", &fHeader, 4000, 0);
1223 branch->SetAutoDelete(kFALSE);
1224 TFolder *folder = (TFolder *)gROOT->FindObjectAny("/Folders/RunMC/Event/Header");
1225 if (folder) folder->Add(fHeader);
1226 // branch = fTreeE->Branch("Stack","AliStack", &fStack, 4000, 0);
1227 // branch->SetAutoDelete(kFALSE);
1228 // if (folder) folder->Add(fStack);
1229 fTreeE->Write(0,TObject::kOverwrite);
1232 if (file && branch) {
1233 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
1234 sprintf(outFile,"%s/%s",GetBaseFile(),file);
1235 branch->SetFile(outFile);
1236 TIter next( branch->GetListOfBranches());
1237 while ((branch=(TBranch*)next())) {
1238 branch->SetFile(outFile);
1241 printf("* MakeBranch * Diverting Branch %s to file %s\n", branch->GetName(),file);
1246 if (oH && !fTreeH) {
1247 sprintf(hname,"TreeH%d",fEvent);
1248 fTreeH = new TTree(hname,"Hits");
1249 fTreeH->SetAutoSave(1000000000); //no autosave
1250 fTreeH->Write(0,TObject::kOverwrite);
1252 if (oD && !fTreeD) {
1253 sprintf(hname,"TreeD%d",fEvent);
1254 fTreeD = new TTree(hname,"Digits");
1255 fTreeD->Write(0,TObject::kOverwrite);
1257 if (oS && !fTreeS) {
1258 sprintf(hname,"TreeS%d",fEvent);
1259 fTreeS = new TTree(hname,"SDigits");
1260 fTreeS->Write(0,TObject::kOverwrite);
1262 if (oR && !fTreeR) {
1263 sprintf(hname,"TreeR%d",fEvent);
1264 fTreeR = new TTree(hname,"Reconstruction");
1265 fTreeR->Write(0,TObject::kOverwrite);
1269 // Create a branch for hits/digits for each detector
1270 // Each branch is a TClonesArray. Each data member of the Hits classes
1271 // will be in turn a subbranch of the detector master branch
1272 TIter next(fModules);
1273 AliModule *detector;
1274 while((detector = (AliModule*)next())) {
1275 if (oH) detector->MakeBranch(option,file);
1279 //_____________________________________________________________________________
1280 TParticle* AliRun::Particle(Int_t i)
1282 return fStack->Particle(i);
1285 //_____________________________________________________________________________
1286 void AliRun::BeginEvent()
1288 // Clean-up previous event
1290 fEventEnergy.Reset();
1291 // Clean detector information
1298 // Reset all Detectors & kinematics & trees
1302 // Initialise event header
1303 fHeader->Reset(fRun,fEvent);
1305 fStack->BeginEvent(fEvent);
1309 fLego->BeginEvent();
1322 sprintf(hname,"TreeH%d",fEvent);
1323 fTreeH->SetName(hname);
1327 sprintf(hname,"TreeD%d",fEvent);
1328 fTreeD->SetName(hname);
1329 fTreeD->Write(0,TObject::kOverwrite);
1333 sprintf(hname,"TreeS%d",fEvent);
1334 fTreeS->SetName(hname);
1335 fTreeS->Write(0,TObject::kOverwrite);
1339 sprintf(hname,"TreeR%d",fEvent);
1340 fTreeR->SetName(hname);
1341 fTreeR->Write(0,TObject::kOverwrite);
1344 //_____________________________________________________________________________
1345 void AliRun::ResetDigits()
1348 // Reset all Detectors digits
1350 TIter next(fModules);
1351 AliModule *detector;
1352 while((detector = (AliModule*)next())) {
1353 detector->ResetDigits();
1357 //_____________________________________________________________________________
1358 void AliRun::ResetSDigits()
1361 // Reset all Detectors digits
1363 TIter next(fModules);
1364 AliModule *detector;
1365 while((detector = (AliModule*)next())) {
1366 detector->ResetSDigits();
1370 //_____________________________________________________________________________
1371 void AliRun::ResetHits()
1374 // Reset all Detectors hits
1376 TIter next(fModules);
1377 AliModule *detector;
1378 while((detector = (AliModule*)next())) {
1379 detector->ResetHits();
1383 //_____________________________________________________________________________
1384 void AliRun::ResetPoints()
1387 // Reset all Detectors points
1389 TIter next(fModules);
1390 AliModule *detector;
1391 while((detector = (AliModule*)next())) {
1392 detector->ResetPoints();
1396 //_____________________________________________________________________________
1397 void AliRun::RunMC(Int_t nevent, const char *setup)
1400 // Main function to be called to process a galice run
1402 // Root > gAlice.Run();
1403 // a positive number of events will cause the finish routine
1407 // check if initialisation has been done
1408 if (!fInitDone) InitMC(setup);
1410 // Create the Root Tree with one branch per detector
1414 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1415 MakeTree("K","Kine.root");
1416 MakeTree("H","Hits.root");
1421 gMC->ProcessRun(nevent);
1423 // End of this run, close files
1424 if(nevent>0) FinishRun();
1427 //_____________________________________________________________________________
1428 void AliRun::RunReco(const char *selected)
1431 // Main function to be called to reconstruct Alice event
1433 for (Int_t nevent=0; nevent<gAlice->TreeE()->GetEntries(); nevent++) {
1436 Digits2Reco(selected);
1440 //_____________________________________________________________________________
1442 void AliRun::Hits2Digits(const char *selected)
1445 // Convert Hits to sumable digits
1447 for (Int_t nevent=0; nevent<gAlice->TreeE()->GetEntries(); nevent++) {
1450 Hits2SDigits(selected);
1451 SDigits2Digits(selected);
1456 //_____________________________________________________________________________
1458 void AliRun::Tree2Tree(Option_t *option, const char *selected)
1461 // Function to transform the content of
1463 // - TreeH to TreeS (option "S")
1464 // - TreeS to TreeD (option "D")
1465 // - TreeD to TreeR (option "R")
1467 // If multiple options are specified ("SDR"), transformation will be done in sequence for
1468 // selected detector and for all detectors if none is selected (detector string
1469 // can contain blank separated list of detector names).
1472 const char *oS = strstr(option,"S");
1473 const char *oD = strstr(option,"D");
1474 const char *oR = strstr(option,"R");
1476 TObjArray *detectors = Detectors();
1478 TIter next(detectors);
1480 AliDetector *detector = 0;
1482 TDirectory *cwd = gDirectory;
1486 while((detector = (AliDetector*)next())) {
1488 if (strcmp(detector->GetName(),selected)) continue;
1489 if (detector->IsActive()){
1490 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1492 sprintf(outFile,"SDigits.%s.root",detector->GetName());
1493 detector->MakeBranch("S",outFile);
1496 sprintf(outFile,"Digits.%s.root",detector->GetName());
1497 detector->MakeBranch("D",outFile);
1500 sprintf(outFile,"Reco.%s.root",detector->GetName());
1501 detector->MakeBranch("R",outFile);
1504 detector->MakeBranch(option);
1510 cout << "Hits2SDigits: Processing " << detector->GetName() << "..." << endl;
1511 detector->Hits2SDigits();
1514 cout << "SDigits2Digits: Processing " << detector->GetName() << "..." << endl;
1515 detector->SDigits2Digits();
1518 cout << "Digits2Reco: Processing " << detector->GetName() << "..." << endl;
1519 detector->Digits2Reco();
1528 //_____________________________________________________________________________
1529 void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min,
1530 Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max,
1531 Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener)
1534 // Generates lego plots of:
1535 // - radiation length map phi vs theta
1536 // - radiation length map phi vs eta
1537 // - interaction length map
1538 // - g/cm2 length map
1540 // ntheta bins in theta, eta
1541 // themin minimum angle in theta (degrees)
1542 // themax maximum angle in theta (degrees)
1544 // phimin minimum angle in phi (degrees)
1545 // phimax maximum angle in phi (degrees)
1546 // rmin minimum radius
1547 // rmax maximum radius
1550 // The number of events generated = ntheta*nphi
1551 // run input parameters in macro setup (default="Config.C")
1553 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1556 <img src="picts/AliRunLego1.gif">
1561 <img src="picts/AliRunLego2.gif">
1566 <img src="picts/AliRunLego3.gif">
1571 // check if initialisation has been done
1572 if (!fInitDone) InitMC(setup);
1573 //Save current generator
1574 AliGenerator *gen=Generator();
1576 // Set new generator
1577 if (!gener) gener = new AliLegoGenerator();
1578 ResetGenerator(gener);
1580 // Configure Generator
1581 gener->SetRadiusRange(rmin, rmax);
1582 gener->SetZMax(zmax);
1583 gener->SetCoor1Range(nc1, c1min, c1max);
1584 gener->SetCoor2Range(nc2, c2min, c2max);
1587 //Create Lego object
1588 fLego = new AliLego("lego",gener);
1590 //Prepare MC for Lego Run
1595 gMC->ProcessRun(nc1*nc2+1);
1597 // Create only the Root event Tree
1600 // End of this run, close files
1602 // Restore current generator
1603 ResetGenerator(gen);
1604 // Delete Lego Object
1605 delete fLego; fLego=0;
1608 //_____________________________________________________________________________
1609 void AliRun::SetConfigFunction(const char * config)
1612 // Set the signature of the function contained in Config.C to configure
1615 fConfigFunction=config;
1618 //_____________________________________________________________________________
1619 void AliRun::SetCurrentTrack(Int_t track)
1622 // Set current track number
1624 fStack->SetCurrentTrack(track);
1627 //_____________________________________________________________________________
1628 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1629 Float_t *vpos, Float_t *polar, Float_t tof,
1630 AliMCProcess mech, Int_t &ntr, Float_t weight)
1632 // Delegate to stack
1634 fStack->SetTrack(done, parent, pdg, pmom, vpos, polar, tof,
1638 //_____________________________________________________________________________
1639 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg,
1640 Double_t px, Double_t py, Double_t pz, Double_t e,
1641 Double_t vx, Double_t vy, Double_t vz, Double_t tof,
1642 Double_t polx, Double_t poly, Double_t polz,
1643 AliMCProcess mech, Int_t &ntr, Float_t weight)
1645 // Delegate to stack
1647 fStack->SetTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
1648 polx, poly, polz, mech, ntr, weight);
1652 //_____________________________________________________________________________
1653 void AliRun::SetHighWaterMark(const Int_t nt)
1656 // Set high water mark for last track in event
1657 fStack->SetHighWaterMark(nt);
1660 //_____________________________________________________________________________
1661 void AliRun::KeepTrack(const Int_t track)
1664 // Delegate to stack
1666 fStack->KeepTrack(track);
1669 //_____________________________________________________________________________
1670 void AliRun::StepManager(Int_t id)
1673 // Called at every step during transport
1677 // --- If lego option, do it and leave
1679 fLego->StepManager();
1682 //Update energy deposition tables
1683 AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
1685 //Call the appropriate stepping routine;
1686 AliModule *det = (AliModule*)fModules->At(id);
1688 fMCQA->StepManager(id);
1694 //_____________________________________________________________________________
1695 void AliRun::Streamer(TBuffer &R__b)
1697 // Stream an object of class AliRun.
1699 if (R__b.IsReading()) {
1700 if (!gAlice) gAlice = this;
1702 AliRun::Class()->ReadBuffer(R__b, this);
1704 gROOT->GetListOfBrowsables()->Add(this,"Run");
1706 fTreeE = (TTree*)gDirectory->Get("TE");
1708 fTreeE->SetBranchAddress("Header", &fHeader);
1711 else Error("Streamer","cannot find Header Tree\n");
1712 fTreeE->GetEntry(0);
1716 AliRun::Class()->WriteBuffer(R__b, this);
1721 //___________________________________________________________________________
1722 Int_t AliRun::CurrentTrack() const {
1724 // Returns current track
1726 return fStack->CurrentTrack();
1729 //___________________________________________________________________________
1730 Int_t AliRun::GetNtrack() const {
1732 // Returns number of tracks in stack
1734 return fStack->GetNtrack();
1737 //___________________________________________________________________________
1738 TObjArray* AliRun::Particles() {
1740 // Returns pointer to Particles array
1742 return fStack->Particles();
1745 //___________________________________________________________________________
1746 TTree* AliRun::TreeK() {
1748 // Returns pointer to the TreeK array
1750 return fStack->TreeK();