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.69 2001/06/28 16:27:50 morsch
19 AliReco() with user control of event range.
21 Revision 1.68 2001/06/11 13:14:40 morsch
22 SetAliGenEventHeader() method added.
24 Revision 1.67 2001/06/07 18:24:50 buncic
25 Removed compilation warning in AliConfig initialisation.
27 Revision 1.66 2001/05/22 14:32:40 hristov
30 Revision 1.65 2001/05/21 17:22:51 buncic
31 Fixed problem with missing AliConfig while reading galice.root
33 Revision 1.64 2001/05/16 14:57:22 alibrary
34 New files for folders and Stack
36 Revision 1.62 2001/04/06 11:12:33 morsch
37 Clear fParticles after each event. (Ivana Hrivnacova)
39 Revision 1.61 2001/03/30 07:04:10 morsch
40 Call fGenerator->FinishRun() for final print-outs, cross-section and weight calculations.
42 Revision 1.60 2001/03/21 18:22:30 hristov
43 fParticleFileMap fix (I.Hrivnacova)
45 Revision 1.59 2001/03/12 17:47:03 hristov
46 Changes needed on Sun with CC 5.0
48 Revision 1.58 2001/03/09 14:27:26 morsch
49 Fix for multiple events per file: inhibit decrease of size of fParticleFileMap.
51 Revision 1.57 2001/02/23 17:40:23 buncic
52 All trees needed for simulation created in RunMC(). TreeR and its branches
53 are now created in new RunReco() method.
55 Revision 1.56 2001/02/14 15:45:20 hristov
56 Algorithmic way of getting entry index in fParticleMap. Protection of fParticleFileMap (I.Hrivnacova)
58 Revision 1.55 2001/02/12 15:52:54 buncic
59 Removed OpenBaseFile().
61 Revision 1.54 2001/02/07 10:39:05 hristov
62 Remove default value for argument
64 Revision 1.53 2001/02/06 11:02:26 hristov
65 New SetTrack interface added, added check for unfilled particles in FinishEvent (I.Hrivnacova)
67 Revision 1.52 2001/02/05 16:22:25 buncic
68 Added TreeS to GetEvent().
70 Revision 1.51 2001/02/02 15:16:20 morsch
71 SetHighWaterMark method added to mark last particle in event.
73 Revision 1.50 2001/01/27 10:32:00 hristov
74 Leave the loop when primaries are filled (I.Hrivnacova)
76 Revision 1.49 2001/01/26 19:58:48 hristov
77 Major upgrade of AliRoot code
79 Revision 1.48 2001/01/17 10:50:50 hristov
80 Corrections to destructors
82 Revision 1.47 2000/12/18 10:44:01 morsch
83 Possibility to set field map by passing pointer to objet of type AliMagF via
86 gAlice->SetField(new AliMagFCM("Map2", "$(ALICE_ROOT)/data/field01.dat",2,1.,10.));
88 Revision 1.46 2000/12/14 19:29:27 fca
89 galice.cuts was not read any more
91 Revision 1.45 2000/11/30 07:12:49 alibrary
92 Introducing new Rndm and QA classes
94 Revision 1.44 2000/10/26 13:58:59 morsch
95 Add possibility to choose the lego generator (of type AliGeneratorLego or derived) when running
96 RunLego(). Default is the base class AliGeneratorLego.
98 Revision 1.43 2000/10/09 09:43:17 fca
99 Special remapping of hits for TPC and TRD. End-of-primary action introduced
101 Revision 1.42 2000/10/02 21:28:14 fca
102 Removal of useless dependecies via forward declarations
104 Revision 1.41 2000/07/13 16:19:09 fca
105 Mainly coding conventions + some small bug fixes
107 Revision 1.40 2000/07/12 08:56:25 fca
108 Coding convention correction and warning removal
110 Revision 1.39 2000/07/11 18:24:59 fca
111 Coding convention corrections + few minor bug fixes
113 Revision 1.38 2000/06/20 13:05:45 fca
114 Writing down the TREE headers before job starts
116 Revision 1.37 2000/06/09 20:05:11 morsch
117 Introduce possibility to chose magnetic field version 3: AliMagFDM + field02.dat
119 Revision 1.36 2000/06/08 14:03:58 hristov
120 Only one initializer for a default argument
122 Revision 1.35 2000/06/07 10:13:14 hristov
123 Delete only existent objects.
125 Revision 1.34 2000/05/18 10:45:38 fca
126 Delete Particle Factory properly
128 Revision 1.33 2000/05/16 13:10:40 fca
129 New method IsNewTrack and fix for a problem in Father-Daughter relations
131 Revision 1.32 2000/04/27 10:38:21 fca
132 Correct termination of Lego Run and introduce Lego getter in AliRun
134 Revision 1.31 2000/04/26 10:17:32 fca
135 Changes in Lego for G4 compatibility
137 Revision 1.30 2000/04/18 19:11:40 fca
138 Introduce variable Config.C function signature
140 Revision 1.29 2000/04/07 11:12:34 fca
141 G4 compatibility changes
143 Revision 1.28 2000/04/05 06:51:06 fca
144 Workaround for an HP compiler problem
146 Revision 1.27 2000/03/22 18:08:07 fca
147 Rationalisation of the virtual MC interfaces
149 Revision 1.26 2000/03/22 13:42:26 fca
150 SetGenerator does not replace an existing generator, ResetGenerator does
152 Revision 1.25 2000/02/23 16:25:22 fca
153 AliVMC and AliGeant3 classes introduced
154 ReadEuclid moved from AliRun to AliModule
156 Revision 1.24 2000/01/19 17:17:20 fca
157 Introducing a list of lists of hits -- more hits allowed for detector now
159 Revision 1.23 1999/12/03 11:14:31 fca
160 Fixing previous wrong checking
162 Revision 1.21 1999/11/25 10:40:08 fca
163 Fixing daughters information also in primary tracks
165 Revision 1.20 1999/10/04 18:08:49 fca
166 Adding protection against inconsistent Euclid files
168 Revision 1.19 1999/09/29 07:50:40 fca
169 Introduction of the Copyright and cvs Log
173 ///////////////////////////////////////////////////////////////////////////////
175 // Control class for Alice C++ //
176 // Only one single instance of this class exists. //
177 // The object is created in main program aliroot //
178 // and is pointed by the global gAlice. //
180 // -Supports the list of all Alice Detectors (fModules). //
181 // -Supports the list of particles (fParticles). //
182 // -Supports the Trees. //
183 // -Supports the geometry. //
184 // -Supports the event display. //
187 <img src="picts/AliRunClass.gif">
192 <img src="picts/alirun.gif">
196 ///////////////////////////////////////////////////////////////////////////////
201 #include <iostream.h>
208 #include <TObjectTable.h>
210 #include <TGeometry.h>
212 #include <TBrowser.h>
216 #include "TParticle.h"
218 #include "AliDisplay.h"
221 #include "AliMagFC.h"
222 #include "AliMagFCM.h"
223 #include "AliMagFDM.h"
225 #include "TRandom3.h"
227 #include "AliGenerator.h"
228 #include "AliLegoGenerator.h"
229 #include "AliConfig.h"
230 #include "AliStack.h"
231 #include "AliGenEventHeader.h"
232 #include "AliHeader.h"
234 #include "AliDetector.h"
240 //_____________________________________________________________________________
244 // Default constructor for AliRun
267 fPDGDB = 0; //Particle factory object!
269 fConfigFunction = "\0";
272 fTransParName = "\0";
273 fBaseFileName = ".\0";
277 //_____________________________________________________________________________
278 AliRun::AliRun(const char *name, const char *title)
282 // Constructor for the main processor.
283 // Creates the geometry
284 // Creates the list of Detectors.
285 // Creates the list of particles.
301 fConfigFunction = "Config();";
303 // Set random number generator
304 gRandom = fRandom = new TRandom3();
306 if (gSystem->Getenv("CONFIG_SEED")) {
307 gRandom->SetSeed((UInt_t)atoi(gSystem->Getenv("CONFIG_SEED")));
310 gROOT->GetListOfBrowsables()->Add(this,name);
313 fStack = new AliStack(10000);
314 // create the support list for the various Detectors
315 fModules = new TObjArray(77);
317 // Create the TNode geometry for the event display
319 BuildSimpleGeometry();
321 fHeader = new AliHeader();
327 // Create default mag field
332 // Prepare the tracking medium lists
333 fImedia = new TArrayI(1000);
334 for(i=0;i<1000;i++) (*fImedia)[i]=-99;
337 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
339 AliConfig::Instance()->Add(fPDGDB);
341 // Create HitLists list
342 fHitLists = new TList();
345 fBaseFileName = ".\0";
351 //_____________________________________________________________________________
355 // Default AliRun destructor
380 //_____________________________________________________________________________
381 void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
384 // Add a hit to detector id
386 TObjArray &dets = *fModules;
387 if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits);
390 //_____________________________________________________________________________
391 void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
394 // Add digit to detector id
396 TObjArray &dets = *fModules;
397 if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits);
400 //_____________________________________________________________________________
401 void AliRun::Browse(TBrowser *b)
404 // Called when the item "Run" is clicked on the left pane
405 // of the Root browser.
406 // It displays the Root Trees and all detectors.
408 if(!fStack) fStack=fHeader->Stack();
409 TTree* pTreeK = fStack->TreeK();
411 if (pTreeK) b->Add(pTreeK,pTreeK->GetName());
412 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
413 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
414 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
415 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
416 if (fTreeS) b->Add(fTreeS,fTreeS->GetName());
418 TIter next(fModules);
420 while((detector = (AliModule*)next())) {
421 b->Add(detector,detector->GetName());
423 b->Add(fMCQA,"AliMCQA");
426 //_____________________________________________________________________________
430 // Initialize Alice geometry
435 //_____________________________________________________________________________
436 void AliRun::BuildSimpleGeometry()
439 // Create a simple TNode geometry used by Root display engine
441 // Initialise geometry
443 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
444 new TMaterial("void","Vacuum",0,0,0); //Everything is void
445 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
446 brik->SetVisibility(0);
447 new TNode("alice","alice","S_alice");
450 //_____________________________________________________________________________
451 void AliRun::CleanDetectors()
454 // Clean Detectors at the end of event
456 TIter next(fModules);
458 while((detector = (AliModule*)next())) {
459 detector->FinishEvent();
463 //_____________________________________________________________________________
464 Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
467 // Return the distance from the mouse to the AliRun object
473 //_____________________________________________________________________________
474 void AliRun::DumpPart (Int_t i) const
477 // Dumps particle i in the stack
482 //_____________________________________________________________________________
483 void AliRun::DumpPStack () const
486 // Dumps the particle stack
488 fStack->DumpPStack();
491 //_____________________________________________________________________________
492 void AliRun::SetField(AliMagF* magField)
494 // Set Magnetic Field Map
499 //_____________________________________________________________________________
500 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
501 Float_t maxField, char* filename)
504 // Set magnetic field parameters
505 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
506 // version Magnetic field map version (only 1 active now)
507 // scale Scale factor for the magnetic field
508 // maxField Maximum value for the magnetic field
511 // --- Sanity check on mag field flags
512 if(fField) delete fField;
514 fField = new AliMagFC("Map1"," ",type,scale,maxField);
515 } else if(version<=2) {
516 fField = new AliMagFCM("Map2-3",filename,type,scale,maxField);
518 } else if(version==3) {
519 fField = new AliMagFDM("Map4",filename,type,scale,maxField);
522 Warning("SetField","Invalid map %d\n",version);
526 //_____________________________________________________________________________
527 void AliRun::PreTrack()
529 TObjArray &dets = *fModules;
532 for(Int_t i=0; i<=fNdets; i++)
533 if((module = (AliModule*)dets[i]))
539 //_____________________________________________________________________________
540 void AliRun::PostTrack()
542 TObjArray &dets = *fModules;
545 for(Int_t i=0; i<=fNdets; i++)
546 if((module = (AliModule*)dets[i]))
550 //_____________________________________________________________________________
551 void AliRun::FinishPrimary()
554 // Called at the end of each primary track
557 // static Int_t count=0;
558 // const Int_t times=10;
559 // This primary is finished, purify stack
560 fStack->PurifyKine();
562 TIter next(fModules);
564 while((detector = (AliModule*)next())) {
565 detector->FinishPrimary();
568 // Write out hits if any
569 if (gAlice->TreeH()) {
570 gAlice->TreeH()->Fill();
574 // if(++count%times==1) gObjectTable->Print();
577 //_____________________________________________________________________________
578 void AliRun::BeginPrimary()
581 // Called at the beginning of each primary track
589 //_____________________________________________________________________________
590 void AliRun::FinishEvent()
593 // Called at the end of the event.
597 if(fLego) fLego->FinishEvent();
599 //Update the energy deposit tables
601 for(i=0;i<fEventEnergy.GetSize();i++) {
602 fSummEnergy[i]+=fEventEnergy[i];
603 fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
608 // Update Header information
610 fHeader->SetNprimary(fStack->GetNprimary());
611 fHeader->SetNtrack(fStack->GetNtrack());
614 // Write out the kinematics
615 fStack->FinishEvent();
617 // Write out the event Header information
619 fHeader->SetStack(fStack);
624 // Write Tree headers
625 TTree* pTreeK = fStack->TreeK();
626 if (pTreeK) pTreeK->Write(0,TObject::kOverwrite);
627 if (fTreeH) fTreeH->Write(0,TObject::kOverwrite);
632 //_____________________________________________________________________________
633 void AliRun::FinishRun()
636 // Called at the end of the run.
640 if(fLego) fLego->FinishRun();
642 // Clean detector information
643 TIter next(fModules);
645 while((detector = (AliModule*)next())) {
646 detector->FinishRun();
649 //Output energy summary tables
652 TFile *file = fTreeE->GetCurrentFile();
656 fTreeE->Write(0,TObject::kOverwrite);
658 // Write AliRun info and all detectors parameters
659 Write(0,TObject::kOverwrite);
661 // Clean tree information
666 delete fTreeH; fTreeH = 0;
669 delete fTreeD; fTreeD = 0;
672 delete fTreeR; fTreeR = 0;
675 delete fTreeE; fTreeE = 0;
678 delete fTreeS; fTreeS = 0;
685 //_____________________________________________________________________________
686 void AliRun::FlagTrack(Int_t track)
690 fStack->FlagTrack(track);
693 //_____________________________________________________________________________
694 void AliRun::EnergySummary()
697 // Print summary of deposited energy
703 Int_t kn, i, left, j, id;
704 const Float_t kzero=0;
705 Int_t ievent=fHeader->GetEvent()+1;
707 // Energy loss information
709 printf("***************** Energy Loss Information per event (GEV) *****************\n");
710 for(kn=1;kn<fEventEnergy.GetSize();kn++) {
713 fEventEnergy[ndep]=kn;
718 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,kzero))/ed;
721 fSummEnergy[ndep]=ed;
722 fSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,kzero));
727 for(kn=0;kn<(ndep-1)/3+1;kn++) {
729 for(i=0;i<(3<left?3:left);i++) {
731 id=Int_t (fEventEnergy[j]+0.1);
732 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]);
737 // Relative energy loss in different detectors
738 printf("******************** Relative Energy Loss per event ********************\n");
739 printf("Total energy loss per event %10.3f GeV\n",edtot);
740 for(kn=0;kn<(ndep-1)/5+1;kn++) {
742 for(i=0;i<(5<left?5:left);i++) {
744 id=Int_t (fEventEnergy[j]+0.1);
745 printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot);
749 for(kn=0;kn<75;kn++) printf("*");
753 // Reset the TArray's
754 // fEventEnergy.Set(0);
755 // fSummEnergy.Set(0);
756 // fSum2Energy.Set(0);
759 //_____________________________________________________________________________
760 AliModule *AliRun::GetModule(const char *name) const
763 // Return pointer to detector from name
765 return (AliModule*)fModules->FindObject(name);
768 //_____________________________________________________________________________
769 AliDetector *AliRun::GetDetector(const char *name) const
772 // Return pointer to detector from name
774 return (AliDetector*)fModules->FindObject(name);
777 //_____________________________________________________________________________
778 Int_t AliRun::GetModuleID(const char *name) const
781 // Return galice internal detector identifier from name
784 TObject *mod=fModules->FindObject(name);
785 if(mod) i=fModules->IndexOf(mod);
789 //_____________________________________________________________________________
790 Int_t AliRun::GetEvent(Int_t event)
793 // Connect the Trees Kinematics and Hits for event # event
794 // Set branch addresses
797 // Reset existing structures
802 // Delete Trees already connected
803 if (fTreeH) delete fTreeH;
804 if (fTreeD) delete fTreeD;
805 if (fTreeR) delete fTreeR;
806 if (fTreeS) delete fTreeS;
808 // Create the particle stack
809 if (fHeader) delete fHeader;
812 // Get header from file
814 fTreeE->SetBranchAddress("Header", &fHeader);
815 fTreeE->GetEntry(event);
818 Error("GetEvent","Cannot find Header Tree (TE)\n");
820 // Get the stack from the header
821 if (fStack) delete fStack;
822 fStack = fHeader->Stack();
823 fStack->GetEvent(event);
825 TFile *file = fTreeE->GetCurrentFile();
829 // Get Hits Tree header from file
830 sprintf(treeName,"TreeH%d",event);
831 fTreeH = (TTree*)gDirectory->Get(treeName);
833 Error("GetEvent","cannot find Hits Tree for event:%d\n",event);
836 // Get Digits Tree header from file
837 sprintf(treeName,"TreeD%d",event);
838 fTreeD = (TTree*)gDirectory->Get(treeName);
840 // Warning("GetEvent","cannot find Digits Tree for event:%d\n",event);
845 // Get SDigits Tree header from file
846 sprintf(treeName,"TreeS%d",event);
847 fTreeS = (TTree*)gDirectory->Get(treeName);
849 // Warning("GetEvent","cannot find SDigits Tree for event:%d\n",event);
854 // Get Reconstruct Tree header from file
855 sprintf(treeName,"TreeR%d",event);
856 fTreeR = (TTree*)gDirectory->Get(treeName);
858 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
863 // Set Trees branch addresses
864 TIter next(fModules);
866 while((detector = (AliModule*)next())) {
867 detector->SetTreeAddress();
870 return fStack->GetNtrack();
873 //_____________________________________________________________________________
874 TGeometry *AliRun::GetGeometry()
877 // Import Alice geometry from current file
878 // Return pointer to geometry object
880 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
882 // Unlink and relink nodes in detectors
883 // This is bad and there must be a better way...
886 TIter next(fModules);
888 while((detector = (AliModule*)next())) {
889 TList *dnodes=detector->Nodes();
892 for ( j=0; j<dnodes->GetSize(); j++) {
893 node = (TNode*) dnodes->At(j);
894 node1 = fGeometry->GetNode(node->GetName());
895 dnodes->Remove(node);
896 dnodes->AddAt(node1,j);
902 //_____________________________________________________________________________
903 void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
904 Float_t &e, Float_t *vpos, Float_t *polar,
909 fStack->GetNextTrack(mtrack, ipart, pmom, e, vpos, polar, tof);
912 //_____________________________________________________________________________
913 Int_t AliRun::GetPrimary(Int_t track) const
916 // return number of primary that has generated track
918 return fStack->GetPrimary(track);
921 //_____________________________________________________________________________
922 void AliRun::InitMC(const char *setup)
925 // Initialize the Alice setup
929 Warning("Init","Cannot initialise AliRun twice!\n");
933 gROOT->LoadMacro(setup);
934 gInterpreter->ProcessLine(fConfigFunction.Data());
937 gMC->DefineParticles(); //Create standard MC particles
939 TObject *objfirst, *objlast;
941 fNdets = fModules->GetLast()+1;
944 //=================Create Materials and geometry
947 // Added also after in case of interactive initialisation of modules
948 fNdets = fModules->GetLast()+1;
950 TIter next(fModules);
952 while((detector = (AliModule*)next())) {
953 detector->SetTreeAddress();
954 objlast = gDirectory->GetList()->Last();
956 // Add Detector histograms in Detector list of histograms
957 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
958 else objfirst = gDirectory->GetList()->First();
960 detector->Histograms()->Add(objfirst);
961 objfirst = gDirectory->GetList()->After(objfirst);
964 ReadTransPar(); //Read the cuts for all materials
966 MediaTable(); //Build the special IMEDIA table
968 //Initialise geometry deposition table
969 fEventEnergy.Set(gMC->NofVolumes()+1);
970 fSummEnergy.Set(gMC->NofVolumes()+1);
971 fSum2Energy.Set(gMC->NofVolumes()+1);
973 //Compute cross-sections
976 //Write Geometry object to current file.
981 fMCQA = new AliMCQA(fNdets);
983 AliConfig::Instance();
985 // Save stuff at the beginning of the file to avoid file corruption
989 //_____________________________________________________________________________
990 void AliRun::MediaTable()
993 // Built media table to get from the media number to
996 Int_t kz, nz, idt, lz, i, k, ind;
998 TObjArray &dets = *gAlice->Detectors();
1001 // For all detectors
1002 for (kz=0;kz<fNdets;kz++) {
1003 // If detector is defined
1004 if((det=(AliModule*) dets[kz])) {
1005 TArrayI &idtmed = *(det->GetIdtmed());
1006 for(nz=0;nz<100;nz++) {
1007 // Find max and min material number
1008 if((idt=idtmed[nz])) {
1009 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
1010 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
1013 if(det->LoMedium() > det->HiMedium()) {
1014 det->LoMedium() = 0;
1015 det->HiMedium() = 0;
1017 if(det->HiMedium() > fImedia->GetSize()) {
1018 Error("MediaTable","Increase fImedia from %d to %d",
1019 fImedia->GetSize(),det->HiMedium());
1022 // Tag all materials in rage as belonging to detector kz
1023 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
1030 // Print summary table
1031 printf(" Traking media ranges:\n");
1032 for(i=0;i<(fNdets-1)/6+1;i++) {
1033 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
1035 det=(AliModule*)dets[ind];
1037 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
1040 printf(" %6s: %3d -> %3d;","NULL",0,0);
1046 //____________________________________________________________________________
1047 void AliRun::SetGenerator(AliGenerator *generator)
1050 // Load the event generator
1052 if(!fGenerator) fGenerator = generator;
1055 //____________________________________________________________________________
1056 void AliRun::ResetGenerator(AliGenerator *generator)
1059 // Load the event generator
1063 Warning("ResetGenerator","Replacing generator %s with %s\n",
1064 fGenerator->GetName(),generator->GetName());
1066 Warning("ResetGenerator","Replacing generator %s with NULL\n",
1067 fGenerator->GetName());
1068 fGenerator = generator;
1071 //____________________________________________________________________________
1072 void AliRun::SetTransPar(char *filename)
1074 fTransParName = filename;
1077 //____________________________________________________________________________
1078 void AliRun::SetBaseFile(char *filename)
1080 fBaseFileName = filename;
1083 //____________________________________________________________________________
1084 void AliRun::ReadTransPar()
1087 // Read filename to set the transport parameters
1091 const Int_t kncuts=10;
1092 const Int_t knflags=11;
1093 const Int_t knpars=kncuts+knflags;
1094 const char kpars[knpars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
1095 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
1096 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
1097 "MULS","PAIR","PHOT","RAYL"};
1101 Float_t cut[kncuts];
1102 Int_t flag[knflags];
1103 Int_t i, itmed, iret, ktmed, kz;
1106 // See whether the file is there
1107 filtmp=gSystem->ExpandPathName(fTransParName.Data());
1108 lun=fopen(filtmp,"r");
1111 Warning("ReadTransPar","File %s does not exist!\n",fTransParName.Data());
1116 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1117 printf(" *%59s\n","*");
1118 printf(" * Please check carefully what you are doing!%10s\n","*");
1119 printf(" *%59s\n","*");
1123 // Initialise cuts and flags
1124 for(i=0;i<kncuts;i++) cut[i]=-99;
1125 for(i=0;i<knflags;i++) flag[i]=-99;
1127 for(i=0;i<256;i++) line[i]='\0';
1128 // Read up to the end of line excluded
1129 iret=fscanf(lun,"%[^\n]",line);
1134 printf(" *%59s\n","*");
1135 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1139 // Read the end of line
1142 if(line[0]=='*') continue;
1144 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",
1145 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
1146 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
1147 &flag[8],&flag[9],&flag[10]);
1151 Warning("ReadTransPar","Error reading file %s\n",fTransParName.Data());
1154 // Check that the module exist
1155 AliModule *mod = GetModule(detName);
1157 // Get the array of media numbers
1158 TArrayI &idtmed = *mod->GetIdtmed();
1159 // Check that the tracking medium code is valid
1160 if(0<=itmed && itmed < 100) {
1161 ktmed=idtmed[itmed];
1163 Warning("ReadTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
1166 // Set energy thresholds
1167 for(kz=0;kz<kncuts;kz++) {
1169 if(fDebug) printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
1170 kpars[kz],cut[kz],itmed,mod->GetName());
1171 gMC->Gstpar(ktmed,kpars[kz],cut[kz]);
1174 // Set transport mechanisms
1175 for(kz=0;kz<knflags;kz++) {
1177 if(fDebug) printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
1178 kpars[kncuts+kz],flag[kz],itmed,mod->GetName());
1179 gMC->Gstpar(ktmed,kpars[kncuts+kz],Float_t(flag[kz]));
1183 Warning("ReadTransPar","Invalid medium code %d *\n",itmed);
1187 if(fDebug) printf("%s::ReadTransParModule: %s not present\n",ClassName(),detName);
1194 //_____________________________________________________________________________
1195 void AliRun::MakeTree(Option_t *option, const char *file)
1198 // Create the ROOT trees
1199 // Loop on all detectors to create the Root branch (if any)
1205 const char *oK = strstr(option,"K");
1206 const char *oH = strstr(option,"H");
1207 const char *oE = strstr(option,"E");
1208 const char *oD = strstr(option,"D");
1209 const char *oR = strstr(option,"R");
1210 const char *oS = strstr(option,"S");
1213 TDirectory *cwd = gDirectory;
1215 TBranch *branch = 0;
1217 if (oK) fStack->MakeTree(fEvent, file);
1219 if (oE && !fTreeE) {
1220 fTreeE = new TTree("TE","Header");
1221 branch = fTreeE->Branch("Header", "AliHeader", &fHeader, 4000, 0);
1222 branch->SetAutoDelete(kFALSE);
1223 TFolder *folder = (TFolder *)gROOT->FindObjectAny("/Folders/RunMC/Event/Header");
1224 if (folder) folder->Add(fHeader);
1225 // branch = fTreeE->Branch("Stack","AliStack", &fStack, 4000, 0);
1226 // branch->SetAutoDelete(kFALSE);
1227 // if (folder) folder->Add(fStack);
1228 fTreeE->Write(0,TObject::kOverwrite);
1231 if (file && branch) {
1232 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
1233 sprintf(outFile,"%s/%s",GetBaseFile(),file);
1234 branch->SetFile(outFile);
1235 TIter next( branch->GetListOfBranches());
1236 while ((branch=(TBranch*)next())) {
1237 branch->SetFile(outFile);
1240 printf("* MakeBranch * Diverting Branch %s to file %s\n", branch->GetName(),file);
1245 if (oH && !fTreeH) {
1246 sprintf(hname,"TreeH%d",fEvent);
1247 fTreeH = new TTree(hname,"Hits");
1248 fTreeH->SetAutoSave(1000000000); //no autosave
1249 fTreeH->Write(0,TObject::kOverwrite);
1251 if (oD && !fTreeD) {
1252 sprintf(hname,"TreeD%d",fEvent);
1253 fTreeD = new TTree(hname,"Digits");
1254 fTreeD->Write(0,TObject::kOverwrite);
1256 if (oS && !fTreeS) {
1257 sprintf(hname,"TreeS%d",fEvent);
1258 fTreeS = new TTree(hname,"SDigits");
1259 fTreeS->Write(0,TObject::kOverwrite);
1261 if (oR && !fTreeR) {
1262 sprintf(hname,"TreeR%d",fEvent);
1263 fTreeR = new TTree(hname,"Reconstruction");
1264 fTreeR->Write(0,TObject::kOverwrite);
1268 // Create a branch for hits/digits for each detector
1269 // Each branch is a TClonesArray. Each data member of the Hits classes
1270 // will be in turn a subbranch of the detector master branch
1271 TIter next(fModules);
1272 AliModule *detector;
1273 while((detector = (AliModule*)next())) {
1274 if (oH) detector->MakeBranch(option,file);
1278 //_____________________________________________________________________________
1279 TParticle* AliRun::Particle(Int_t i)
1281 return fStack->Particle(i);
1284 //_____________________________________________________________________________
1285 void AliRun::BeginEvent()
1287 // Clean-up previous event
1289 fEventEnergy.Reset();
1290 // Clean detector information
1297 // Reset all Detectors & kinematics & trees
1301 // Initialise event header
1302 fHeader->Reset(fRun,fEvent);
1304 fStack->BeginEvent(fEvent);
1308 fLego->BeginEvent();
1321 sprintf(hname,"TreeH%d",fEvent);
1322 fTreeH->SetName(hname);
1326 sprintf(hname,"TreeD%d",fEvent);
1327 fTreeD->SetName(hname);
1328 fTreeD->Write(0,TObject::kOverwrite);
1332 sprintf(hname,"TreeS%d",fEvent);
1333 fTreeS->SetName(hname);
1334 fTreeS->Write(0,TObject::kOverwrite);
1338 sprintf(hname,"TreeR%d",fEvent);
1339 fTreeR->SetName(hname);
1340 fTreeR->Write(0,TObject::kOverwrite);
1343 //_____________________________________________________________________________
1344 void AliRun::ResetDigits()
1347 // Reset all Detectors digits
1349 TIter next(fModules);
1350 AliModule *detector;
1351 while((detector = (AliModule*)next())) {
1352 detector->ResetDigits();
1356 //_____________________________________________________________________________
1357 void AliRun::ResetSDigits()
1360 // Reset all Detectors digits
1362 TIter next(fModules);
1363 AliModule *detector;
1364 while((detector = (AliModule*)next())) {
1365 detector->ResetSDigits();
1369 //_____________________________________________________________________________
1370 void AliRun::ResetHits()
1373 // Reset all Detectors hits
1375 TIter next(fModules);
1376 AliModule *detector;
1377 while((detector = (AliModule*)next())) {
1378 detector->ResetHits();
1382 //_____________________________________________________________________________
1383 void AliRun::ResetPoints()
1386 // Reset all Detectors points
1388 TIter next(fModules);
1389 AliModule *detector;
1390 while((detector = (AliModule*)next())) {
1391 detector->ResetPoints();
1395 //_____________________________________________________________________________
1396 void AliRun::RunMC(Int_t nevent, const char *setup)
1399 // Main function to be called to process a galice run
1401 // Root > gAlice.Run();
1402 // a positive number of events will cause the finish routine
1406 // check if initialisation has been done
1407 if (!fInitDone) InitMC(setup);
1409 // Create the Root Tree with one branch per detector
1413 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1414 MakeTree("K","Kine.root");
1415 MakeTree("H","Hits.root");
1420 gMC->ProcessRun(nevent);
1422 // End of this run, close files
1423 if(nevent>0) FinishRun();
1426 //_____________________________________________________________________________
1427 void AliRun::RunReco(const char *selected, Int_t first, Int_t last)
1430 // Main function to be called to reconstruct Alice event
1432 cout << "Found "<< gAlice->TreeE()->GetEntries() << "events" << endl;
1433 Int_t nFirst = first;
1434 Int_t nLast = (last < 0)? (Int_t) gAlice->TreeE()->GetEntries() : last;
1436 for (Int_t nevent = nFirst; nevent <= nLast; nevent++) {
1437 cout << "Processing event "<< nevent << endl;
1440 Digits2Reco(selected);
1444 //_____________________________________________________________________________
1446 void AliRun::Hits2Digits(const char *selected)
1449 // Convert Hits to sumable digits
1451 for (Int_t nevent=0; nevent<gAlice->TreeE()->GetEntries(); nevent++) {
1454 Hits2SDigits(selected);
1455 SDigits2Digits(selected);
1460 //_____________________________________________________________________________
1462 void AliRun::Tree2Tree(Option_t *option, const char *selected)
1465 // Function to transform the content of
1467 // - TreeH to TreeS (option "S")
1468 // - TreeS to TreeD (option "D")
1469 // - TreeD to TreeR (option "R")
1471 // If multiple options are specified ("SDR"), transformation will be done in sequence for
1472 // selected detector and for all detectors if none is selected (detector string
1473 // can contain blank separated list of detector names).
1476 const char *oS = strstr(option,"S");
1477 const char *oD = strstr(option,"D");
1478 const char *oR = strstr(option,"R");
1480 TObjArray *detectors = Detectors();
1482 TIter next(detectors);
1484 AliDetector *detector = 0;
1486 TDirectory *cwd = gDirectory;
1490 while((detector = (AliDetector*)next())) {
1492 if (strcmp(detector->GetName(),selected)) continue;
1493 if (detector->IsActive()){
1494 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1496 sprintf(outFile,"SDigits.%s.root",detector->GetName());
1497 detector->MakeBranch("S",outFile);
1500 sprintf(outFile,"Digits.%s.root",detector->GetName());
1501 detector->MakeBranch("D",outFile);
1504 sprintf(outFile,"Reco.%s.root",detector->GetName());
1505 detector->MakeBranch("R",outFile);
1508 detector->MakeBranch(option);
1514 cout << "Hits2SDigits: Processing " << detector->GetName() << "..." << endl;
1515 detector->Hits2SDigits();
1518 cout << "SDigits2Digits: Processing " << detector->GetName() << "..." << endl;
1519 detector->SDigits2Digits();
1522 cout << "Digits2Reco: Processing " << detector->GetName() << "..." << endl;
1523 detector->Digits2Reco();
1532 //_____________________________________________________________________________
1533 void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min,
1534 Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max,
1535 Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener)
1538 // Generates lego plots of:
1539 // - radiation length map phi vs theta
1540 // - radiation length map phi vs eta
1541 // - interaction length map
1542 // - g/cm2 length map
1544 // ntheta bins in theta, eta
1545 // themin minimum angle in theta (degrees)
1546 // themax maximum angle in theta (degrees)
1548 // phimin minimum angle in phi (degrees)
1549 // phimax maximum angle in phi (degrees)
1550 // rmin minimum radius
1551 // rmax maximum radius
1554 // The number of events generated = ntheta*nphi
1555 // run input parameters in macro setup (default="Config.C")
1557 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1560 <img src="picts/AliRunLego1.gif">
1565 <img src="picts/AliRunLego2.gif">
1570 <img src="picts/AliRunLego3.gif">
1575 // check if initialisation has been done
1576 if (!fInitDone) InitMC(setup);
1577 //Save current generator
1578 AliGenerator *gen=Generator();
1580 // Set new generator
1581 if (!gener) gener = new AliLegoGenerator();
1582 ResetGenerator(gener);
1584 // Configure Generator
1585 gener->SetRadiusRange(rmin, rmax);
1586 gener->SetZMax(zmax);
1587 gener->SetCoor1Range(nc1, c1min, c1max);
1588 gener->SetCoor2Range(nc2, c2min, c2max);
1591 //Create Lego object
1592 fLego = new AliLego("lego",gener);
1594 //Prepare MC for Lego Run
1599 gMC->ProcessRun(nc1*nc2+1);
1601 // Create only the Root event Tree
1604 // End of this run, close files
1606 // Restore current generator
1607 ResetGenerator(gen);
1608 // Delete Lego Object
1609 delete fLego; fLego=0;
1612 //_____________________________________________________________________________
1613 void AliRun::SetConfigFunction(const char * config)
1616 // Set the signature of the function contained in Config.C to configure
1619 fConfigFunction=config;
1622 //_____________________________________________________________________________
1623 void AliRun::SetCurrentTrack(Int_t track)
1626 // Set current track number
1628 fStack->SetCurrentTrack(track);
1631 //_____________________________________________________________________________
1632 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1633 Float_t *vpos, Float_t *polar, Float_t tof,
1634 AliMCProcess mech, Int_t &ntr, Float_t weight)
1636 // Delegate to stack
1638 fStack->SetTrack(done, parent, pdg, pmom, vpos, polar, tof,
1642 //_____________________________________________________________________________
1643 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg,
1644 Double_t px, Double_t py, Double_t pz, Double_t e,
1645 Double_t vx, Double_t vy, Double_t vz, Double_t tof,
1646 Double_t polx, Double_t poly, Double_t polz,
1647 AliMCProcess mech, Int_t &ntr, Float_t weight)
1649 // Delegate to stack
1651 fStack->SetTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
1652 polx, poly, polz, mech, ntr, weight);
1656 //_____________________________________________________________________________
1657 void AliRun::SetHighWaterMark(const Int_t nt)
1660 // Set high water mark for last track in event
1661 fStack->SetHighWaterMark(nt);
1664 //_____________________________________________________________________________
1665 void AliRun::KeepTrack(const Int_t track)
1668 // Delegate to stack
1670 fStack->KeepTrack(track);
1673 //_____________________________________________________________________________
1674 void AliRun::StepManager(Int_t id)
1677 // Called at every step during transport
1681 // --- If lego option, do it and leave
1683 fLego->StepManager();
1686 //Update energy deposition tables
1687 AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
1689 //Call the appropriate stepping routine;
1690 AliModule *det = (AliModule*)fModules->At(id);
1692 fMCQA->StepManager(id);
1698 //_____________________________________________________________________________
1699 void AliRun::Streamer(TBuffer &R__b)
1701 // Stream an object of class AliRun.
1703 if (R__b.IsReading()) {
1704 if (!gAlice) gAlice = this;
1706 AliRun::Class()->ReadBuffer(R__b, this);
1708 gROOT->GetListOfBrowsables()->Add(this,"Run");
1710 fTreeE = (TTree*)gDirectory->Get("TE");
1712 fTreeE->SetBranchAddress("Header", &fHeader);
1715 else Error("Streamer","cannot find Header Tree\n");
1716 fTreeE->GetEntry(0);
1720 AliRun::Class()->WriteBuffer(R__b, this);
1725 //___________________________________________________________________________
1726 Int_t AliRun::CurrentTrack() const {
1728 // Returns current track
1730 return fStack->CurrentTrack();
1733 //___________________________________________________________________________
1734 Int_t AliRun::GetNtrack() const {
1736 // Returns number of tracks in stack
1738 return fStack->GetNtrack();
1741 //___________________________________________________________________________
1742 TObjArray* AliRun::Particles() {
1744 // Returns pointer to Particles array
1746 return fStack->Particles();
1749 //___________________________________________________________________________
1750 TTree* AliRun::TreeK() {
1752 // Returns pointer to the TreeK array
1754 return fStack->TreeK();
1758 void AliRun::SetGenEventHeader(AliGenEventHeader* header)
1760 fHeader->SetGenEventHeader(header);