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.73 2001/07/27 12:34:30 jchudoba
19 remove the dummy argument in fStack->GetEvent call
21 Revision 1.72 2001/07/03 08:10:57 hristov
22 J.Chudoba's changes merged correctly with the HEAD
24 Revision 1.70 2001/06/29 08:01:36 morsch
25 Small correction to the previous.
27 Revision 1.69 2001/06/28 16:27:50 morsch
28 AliReco() with user control of event range.
30 Revision 1.68 2001/06/11 13:14:40 morsch
31 SetAliGenEventHeader() method added.
33 Revision 1.67 2001/06/07 18:24:50 buncic
34 Removed compilation warning in AliConfig initialisation.
36 Revision 1.66 2001/05/22 14:32:40 hristov
39 Revision 1.65 2001/05/21 17:22:51 buncic
40 Fixed problem with missing AliConfig while reading galice.root
42 Revision 1.64 2001/05/16 14:57:22 alibrary
43 New files for folders and Stack
45 Revision 1.62 2001/04/06 11:12:33 morsch
46 Clear fParticles after each event. (Ivana Hrivnacova)
48 Revision 1.61 2001/03/30 07:04:10 morsch
49 Call fGenerator->FinishRun() for final print-outs, cross-section and weight calculations.
51 Revision 1.60 2001/03/21 18:22:30 hristov
52 fParticleFileMap fix (I.Hrivnacova)
54 Revision 1.59 2001/03/12 17:47:03 hristov
55 Changes needed on Sun with CC 5.0
57 Revision 1.58 2001/03/09 14:27:26 morsch
58 Fix for multiple events per file: inhibit decrease of size of fParticleFileMap.
60 Revision 1.57 2001/02/23 17:40:23 buncic
61 All trees needed for simulation created in RunMC(). TreeR and its branches
62 are now created in new RunReco() method.
64 Revision 1.56 2001/02/14 15:45:20 hristov
65 Algorithmic way of getting entry index in fParticleMap. Protection of fParticleFileMap (I.Hrivnacova)
67 Revision 1.55 2001/02/12 15:52:54 buncic
68 Removed OpenBaseFile().
70 Revision 1.54 2001/02/07 10:39:05 hristov
71 Remove default value for argument
73 Revision 1.53 2001/02/06 11:02:26 hristov
74 New SetTrack interface added, added check for unfilled particles in FinishEvent (I.Hrivnacova)
76 Revision 1.52 2001/02/05 16:22:25 buncic
77 Added TreeS to GetEvent().
79 Revision 1.51 2001/02/02 15:16:20 morsch
80 SetHighWaterMark method added to mark last particle in event.
82 Revision 1.50 2001/01/27 10:32:00 hristov
83 Leave the loop when primaries are filled (I.Hrivnacova)
85 Revision 1.49 2001/01/26 19:58:48 hristov
86 Major upgrade of AliRoot code
88 Revision 1.48 2001/01/17 10:50:50 hristov
89 Corrections to destructors
91 Revision 1.47 2000/12/18 10:44:01 morsch
92 Possibility to set field map by passing pointer to objet of type AliMagF via
95 gAlice->SetField(new AliMagFCM("Map2", "$(ALICE_ROOT)/data/field01.dat",2,1.,10.));
97 Revision 1.46 2000/12/14 19:29:27 fca
98 galice.cuts was not read any more
100 Revision 1.45 2000/11/30 07:12:49 alibrary
101 Introducing new Rndm and QA classes
103 Revision 1.44 2000/10/26 13:58:59 morsch
104 Add possibility to choose the lego generator (of type AliGeneratorLego or derived) when running
105 RunLego(). Default is the base class AliGeneratorLego.
107 Revision 1.43 2000/10/09 09:43:17 fca
108 Special remapping of hits for TPC and TRD. End-of-primary action introduced
110 Revision 1.42 2000/10/02 21:28:14 fca
111 Removal of useless dependecies via forward declarations
113 Revision 1.41 2000/07/13 16:19:09 fca
114 Mainly coding conventions + some small bug fixes
116 Revision 1.40 2000/07/12 08:56:25 fca
117 Coding convention correction and warning removal
119 Revision 1.39 2000/07/11 18:24:59 fca
120 Coding convention corrections + few minor bug fixes
122 Revision 1.38 2000/06/20 13:05:45 fca
123 Writing down the TREE headers before job starts
125 Revision 1.37 2000/06/09 20:05:11 morsch
126 Introduce possibility to chose magnetic field version 3: AliMagFDM + field02.dat
128 Revision 1.36 2000/06/08 14:03:58 hristov
129 Only one initializer for a default argument
131 Revision 1.35 2000/06/07 10:13:14 hristov
132 Delete only existent objects.
134 Revision 1.34 2000/05/18 10:45:38 fca
135 Delete Particle Factory properly
137 Revision 1.33 2000/05/16 13:10:40 fca
138 New method IsNewTrack and fix for a problem in Father-Daughter relations
140 Revision 1.32 2000/04/27 10:38:21 fca
141 Correct termination of Lego Run and introduce Lego getter in AliRun
143 Revision 1.31 2000/04/26 10:17:32 fca
144 Changes in Lego for G4 compatibility
146 Revision 1.30 2000/04/18 19:11:40 fca
147 Introduce variable Config.C function signature
149 Revision 1.29 2000/04/07 11:12:34 fca
150 G4 compatibility changes
152 Revision 1.28 2000/04/05 06:51:06 fca
153 Workaround for an HP compiler problem
155 Revision 1.27 2000/03/22 18:08:07 fca
156 Rationalisation of the virtual MC interfaces
158 Revision 1.26 2000/03/22 13:42:26 fca
159 SetGenerator does not replace an existing generator, ResetGenerator does
161 Revision 1.25 2000/02/23 16:25:22 fca
162 AliVMC and AliGeant3 classes introduced
163 ReadEuclid moved from AliRun to AliModule
165 Revision 1.24 2000/01/19 17:17:20 fca
166 Introducing a list of lists of hits -- more hits allowed for detector now
168 Revision 1.23 1999/12/03 11:14:31 fca
169 Fixing previous wrong checking
171 Revision 1.21 1999/11/25 10:40:08 fca
172 Fixing daughters information also in primary tracks
174 Revision 1.20 1999/10/04 18:08:49 fca
175 Adding protection against inconsistent Euclid files
177 Revision 1.19 1999/09/29 07:50:40 fca
178 Introduction of the Copyright and cvs Log
182 ///////////////////////////////////////////////////////////////////////////////
184 // Control class for Alice C++ //
185 // Only one single instance of this class exists. //
186 // The object is created in main program aliroot //
187 // and is pointed by the global gAlice. //
189 // -Supports the list of all Alice Detectors (fModules). //
190 // -Supports the list of particles (fParticles). //
191 // -Supports the Trees. //
192 // -Supports the geometry. //
193 // -Supports the event display. //
196 <img src="picts/AliRunClass.gif">
201 <img src="picts/alirun.gif">
205 ///////////////////////////////////////////////////////////////////////////////
210 #include <iostream.h>
217 #include <TObjectTable.h>
219 #include <TGeometry.h>
221 #include <TBrowser.h>
226 #include "TParticle.h"
228 #include "AliDisplay.h"
231 #include "AliMagFC.h"
232 #include "AliMagFCM.h"
233 #include "AliMagFDM.h"
235 #include "TRandom3.h"
237 #include "AliGenerator.h"
238 #include "AliLegoGenerator.h"
239 #include "AliConfig.h"
240 #include "AliStack.h"
241 #include "AliGenEventHeader.h"
242 #include "AliHeader.h"
244 #include "AliDetector.h"
250 //_____________________________________________________________________________
254 // Default constructor for AliRun
277 fPDGDB = 0; //Particle factory object!
279 fConfigFunction = "\0";
282 fTransParName = "\0";
283 fBaseFileName = ".\0";
287 //_____________________________________________________________________________
288 AliRun::AliRun(const char *name, const char *title)
292 // Constructor for the main processor.
293 // Creates the geometry
294 // Creates the list of Detectors.
295 // Creates the list of particles.
311 fConfigFunction = "Config();";
313 // Set random number generator
314 gRandom = fRandom = new TRandom3();
316 if (gSystem->Getenv("CONFIG_SEED")) {
317 gRandom->SetSeed((UInt_t)atoi(gSystem->Getenv("CONFIG_SEED")));
320 gROOT->GetListOfBrowsables()->Add(this,name);
323 fStack = new AliStack(10000);
324 // create the support list for the various Detectors
325 fModules = new TObjArray(77);
327 // Create the TNode geometry for the event display
329 BuildSimpleGeometry();
331 fHeader = new AliHeader();
337 // Create default mag field
342 // Prepare the tracking medium lists
343 fImedia = new TArrayI(1000);
344 for(i=0;i<1000;i++) (*fImedia)[i]=-99;
347 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
349 AliConfig::Instance()->Add(fPDGDB);
351 // Create HitLists list
352 fHitLists = new TList();
355 fBaseFileName = ".\0";
361 //_____________________________________________________________________________
365 // Default AliRun destructor
390 //_____________________________________________________________________________
391 void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
394 // Add a hit to detector id
396 TObjArray &dets = *fModules;
397 if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits);
400 //_____________________________________________________________________________
401 void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
404 // Add digit to detector id
406 TObjArray &dets = *fModules;
407 if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits);
410 //_____________________________________________________________________________
411 void AliRun::Browse(TBrowser *b)
414 // Called when the item "Run" is clicked on the left pane
415 // of the Root browser.
416 // It displays the Root Trees and all detectors.
418 if(!fStack) fStack=fHeader->Stack();
419 TTree* pTreeK = fStack->TreeK();
421 if (pTreeK) b->Add(pTreeK,pTreeK->GetName());
422 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
423 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
424 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
425 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
426 if (fTreeS) b->Add(fTreeS,fTreeS->GetName());
428 TIter next(fModules);
430 while((detector = (AliModule*)next())) {
431 b->Add(detector,detector->GetName());
433 b->Add(fMCQA,"AliMCQA");
436 //_____________________________________________________________________________
440 // Initialize Alice geometry
445 //_____________________________________________________________________________
446 void AliRun::BuildSimpleGeometry()
449 // Create a simple TNode geometry used by Root display engine
451 // Initialise geometry
453 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
454 new TMaterial("void","Vacuum",0,0,0); //Everything is void
455 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
456 brik->SetVisibility(0);
457 new TNode("alice","alice","S_alice");
460 //_____________________________________________________________________________
461 void AliRun::CleanDetectors()
464 // Clean Detectors at the end of event
466 TIter next(fModules);
468 while((detector = (AliModule*)next())) {
469 detector->FinishEvent();
473 //_____________________________________________________________________________
474 Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
477 // Return the distance from the mouse to the AliRun object
483 //_____________________________________________________________________________
484 void AliRun::DumpPart (Int_t i) const
487 // Dumps particle i in the stack
492 //_____________________________________________________________________________
493 void AliRun::DumpPStack () const
496 // Dumps the particle stack
498 fStack->DumpPStack();
501 //_____________________________________________________________________________
502 void AliRun::SetField(AliMagF* magField)
504 // Set Magnetic Field Map
509 //_____________________________________________________________________________
510 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
511 Float_t maxField, char* filename)
514 // Set magnetic field parameters
515 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
516 // version Magnetic field map version (only 1 active now)
517 // scale Scale factor for the magnetic field
518 // maxField Maximum value for the magnetic field
521 // --- Sanity check on mag field flags
522 if(fField) delete fField;
524 fField = new AliMagFC("Map1"," ",type,scale,maxField);
525 } else if(version<=2) {
526 fField = new AliMagFCM("Map2-3",filename,type,scale,maxField);
528 } else if(version==3) {
529 fField = new AliMagFDM("Map4",filename,type,scale,maxField);
532 Warning("SetField","Invalid map %d\n",version);
536 //_____________________________________________________________________________
537 void AliRun::PreTrack()
539 TObjArray &dets = *fModules;
542 for(Int_t i=0; i<=fNdets; i++)
543 if((module = (AliModule*)dets[i]))
549 //_____________________________________________________________________________
550 void AliRun::PostTrack()
552 TObjArray &dets = *fModules;
555 for(Int_t i=0; i<=fNdets; i++)
556 if((module = (AliModule*)dets[i]))
560 //_____________________________________________________________________________
561 void AliRun::FinishPrimary()
564 // Called at the end of each primary track
567 // static Int_t count=0;
568 // const Int_t times=10;
569 // This primary is finished, purify stack
570 fStack->PurifyKine();
572 TIter next(fModules);
574 while((detector = (AliModule*)next())) {
575 detector->FinishPrimary();
578 // Write out hits if any
579 if (gAlice->TreeH()) {
580 gAlice->TreeH()->Fill();
584 // if(++count%times==1) gObjectTable->Print();
587 //_____________________________________________________________________________
588 void AliRun::BeginPrimary()
591 // Called at the beginning of each primary track
599 //_____________________________________________________________________________
600 void AliRun::FinishEvent()
603 // Called at the end of the event.
607 if(fLego) fLego->FinishEvent();
609 //Update the energy deposit tables
611 for(i=0;i<fEventEnergy.GetSize();i++) {
612 fSummEnergy[i]+=fEventEnergy[i];
613 fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
618 // Update Header information
620 fHeader->SetNprimary(fStack->GetNprimary());
621 fHeader->SetNtrack(fStack->GetNtrack());
624 // Write out the kinematics
625 fStack->FinishEvent();
627 // Write out the event Header information
629 fHeader->SetStack(fStack);
634 // Write Tree headers
635 TTree* pTreeK = fStack->TreeK();
636 if (pTreeK) pTreeK->Write(0,TObject::kOverwrite);
637 if (fTreeH) fTreeH->Write(0,TObject::kOverwrite);
642 //_____________________________________________________________________________
643 void AliRun::FinishRun()
646 // Called at the end of the run.
650 if(fLego) fLego->FinishRun();
652 // Clean detector information
653 TIter next(fModules);
655 while((detector = (AliModule*)next())) {
656 detector->FinishRun();
659 //Output energy summary tables
662 TFile *file = fTreeE->GetCurrentFile();
666 fTreeE->Write(0,TObject::kOverwrite);
668 // Write AliRun info and all detectors parameters
669 Write(0,TObject::kOverwrite);
671 // Clean tree information
676 delete fTreeH; fTreeH = 0;
679 delete fTreeD; fTreeD = 0;
682 delete fTreeR; fTreeR = 0;
685 delete fTreeE; fTreeE = 0;
688 delete fTreeS; fTreeS = 0;
690 fGenerator->FinishRun();
696 //_____________________________________________________________________________
697 void AliRun::FlagTrack(Int_t track)
701 fStack->FlagTrack(track);
704 //_____________________________________________________________________________
705 void AliRun::EnergySummary()
708 // Print summary of deposited energy
714 Int_t kn, i, left, j, id;
715 const Float_t kzero=0;
716 Int_t ievent=fHeader->GetEvent()+1;
718 // Energy loss information
720 printf("***************** Energy Loss Information per event (GEV) *****************\n");
721 for(kn=1;kn<fEventEnergy.GetSize();kn++) {
724 fEventEnergy[ndep]=kn;
729 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,kzero))/ed;
732 fSummEnergy[ndep]=ed;
733 fSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,kzero));
738 for(kn=0;kn<(ndep-1)/3+1;kn++) {
740 for(i=0;i<(3<left?3:left);i++) {
742 id=Int_t (fEventEnergy[j]+0.1);
743 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]);
748 // Relative energy loss in different detectors
749 printf("******************** Relative Energy Loss per event ********************\n");
750 printf("Total energy loss per event %10.3f GeV\n",edtot);
751 for(kn=0;kn<(ndep-1)/5+1;kn++) {
753 for(i=0;i<(5<left?5:left);i++) {
755 id=Int_t (fEventEnergy[j]+0.1);
756 printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot);
760 for(kn=0;kn<75;kn++) printf("*");
764 // Reset the TArray's
765 // fEventEnergy.Set(0);
766 // fSummEnergy.Set(0);
767 // fSum2Energy.Set(0);
770 //_____________________________________________________________________________
771 AliModule *AliRun::GetModule(const char *name) const
774 // Return pointer to detector from name
776 return (AliModule*)fModules->FindObject(name);
779 //_____________________________________________________________________________
780 AliDetector *AliRun::GetDetector(const char *name) const
783 // Return pointer to detector from name
785 return (AliDetector*)fModules->FindObject(name);
788 //_____________________________________________________________________________
789 Int_t AliRun::GetModuleID(const char *name) const
792 // Return galice internal detector identifier from name
795 TObject *mod=fModules->FindObject(name);
796 if(mod) i=fModules->IndexOf(mod);
800 //_____________________________________________________________________________
801 Int_t AliRun::GetEvent(Int_t event)
804 // Connect the Trees Kinematics and Hits for event # event
805 // Set branch addresses
808 // Reset existing structures
813 // Delete Trees already connected
814 if (fTreeH) { delete fTreeH; fTreeH = 0;}
815 if (fTreeD) { delete fTreeD; fTreeD = 0;}
816 if (fTreeR) { delete fTreeR; fTreeR = 0;}
817 if (fTreeS) { delete fTreeS; fTreeS = 0;}
819 // Create the particle stack
820 if (fHeader) delete fHeader;
823 // Get header from file
825 fTreeE->SetBranchAddress("Header", &fHeader);
827 if (!fTreeE->GetEntry(event)) {
828 Error("GetEvent","Cannot find event:%d\n",event);
833 Error("GetEvent","Cannot find Header Tree (TE)\n");
837 // Get the stack from the header, set fStack to 0 if it
838 // fails to get event
839 if (fStack) delete fStack;
840 fStack = fHeader->Stack();
842 if (!fStack->GetEvent(event)) fStack = 0;
846 TFile *file = fTreeE->GetCurrentFile();
849 static TIter Iter(gDirectory->GetListOfKeys());
853 // Get Hits Tree header from file
854 sprintf(treeName,"TreeH%d",event);
855 while ((currentKey = (TKey *) Iter.Next())) {
856 if (strcmp(treeName,currentKey->GetName()) == 0) {
857 fTreeH = (TTree*)currentKey->ReadObj();
859 {Error("GetEvent","cannot find Hits Tree for event:%d\n",event);}
864 // Get Digits Tree header from file
865 sprintf(treeName,"TreeD%d",event);
866 fTreeD = (TTree*)gDirectory->Get(treeName);
868 // Warning("GetEvent","cannot find Digits Tree for event:%d\n",event);
873 // Get SDigits Tree header from file
874 sprintf(treeName,"TreeS%d",event);
875 fTreeS = (TTree*)gDirectory->Get(treeName);
877 // Warning("GetEvent","cannot find SDigits Tree for event:%d\n",event);
882 // Get Reconstruct Tree header from file
883 sprintf(treeName,"TreeR%d",event);
884 fTreeR = (TTree*)gDirectory->Get(treeName);
886 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
891 // Set Trees branch addresses
892 TIter next(fModules);
894 while((detector = (AliModule*)next())) {
895 detector->SetTreeAddress();
898 return fStack->GetNtrack();
901 //_____________________________________________________________________________
902 TGeometry *AliRun::GetGeometry()
905 // Import Alice geometry from current file
906 // Return pointer to geometry object
908 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
910 // Unlink and relink nodes in detectors
911 // This is bad and there must be a better way...
914 TIter next(fModules);
916 while((detector = (AliModule*)next())) {
917 TList *dnodes=detector->Nodes();
920 for ( j=0; j<dnodes->GetSize(); j++) {
921 node = (TNode*) dnodes->At(j);
922 node1 = fGeometry->GetNode(node->GetName());
923 dnodes->Remove(node);
924 dnodes->AddAt(node1,j);
930 //_____________________________________________________________________________
931 void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
932 Float_t &e, Float_t *vpos, Float_t *polar,
937 fStack->GetNextTrack(mtrack, ipart, pmom, e, vpos, polar, tof);
940 //_____________________________________________________________________________
941 Int_t AliRun::GetPrimary(Int_t track) const
944 // return number of primary that has generated track
946 return fStack->GetPrimary(track);
949 //_____________________________________________________________________________
950 void AliRun::InitMC(const char *setup)
953 // Initialize the Alice setup
957 Warning("Init","Cannot initialise AliRun twice!\n");
961 gROOT->LoadMacro(setup);
962 gInterpreter->ProcessLine(fConfigFunction.Data());
965 gMC->DefineParticles(); //Create standard MC particles
967 TObject *objfirst, *objlast;
969 fNdets = fModules->GetLast()+1;
972 //=================Create Materials and geometry
975 // Added also after in case of interactive initialisation of modules
976 fNdets = fModules->GetLast()+1;
978 TIter next(fModules);
980 while((detector = (AliModule*)next())) {
981 detector->SetTreeAddress();
982 objlast = gDirectory->GetList()->Last();
984 // Add Detector histograms in Detector list of histograms
985 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
986 else objfirst = gDirectory->GetList()->First();
988 detector->Histograms()->Add(objfirst);
989 objfirst = gDirectory->GetList()->After(objfirst);
992 ReadTransPar(); //Read the cuts for all materials
994 MediaTable(); //Build the special IMEDIA table
996 //Initialise geometry deposition table
997 fEventEnergy.Set(gMC->NofVolumes()+1);
998 fSummEnergy.Set(gMC->NofVolumes()+1);
999 fSum2Energy.Set(gMC->NofVolumes()+1);
1001 //Compute cross-sections
1002 gMC->BuildPhysics();
1004 //Write Geometry object to current file.
1009 fMCQA = new AliMCQA(fNdets);
1011 AliConfig::Instance();
1013 // Save stuff at the beginning of the file to avoid file corruption
1017 //_____________________________________________________________________________
1018 void AliRun::MediaTable()
1021 // Built media table to get from the media number to
1024 Int_t kz, nz, idt, lz, i, k, ind;
1026 TObjArray &dets = *gAlice->Detectors();
1029 // For all detectors
1030 for (kz=0;kz<fNdets;kz++) {
1031 // If detector is defined
1032 if((det=(AliModule*) dets[kz])) {
1033 TArrayI &idtmed = *(det->GetIdtmed());
1034 for(nz=0;nz<100;nz++) {
1035 // Find max and min material number
1036 if((idt=idtmed[nz])) {
1037 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
1038 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
1041 if(det->LoMedium() > det->HiMedium()) {
1042 det->LoMedium() = 0;
1043 det->HiMedium() = 0;
1045 if(det->HiMedium() > fImedia->GetSize()) {
1046 Error("MediaTable","Increase fImedia from %d to %d",
1047 fImedia->GetSize(),det->HiMedium());
1050 // Tag all materials in rage as belonging to detector kz
1051 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
1058 // Print summary table
1059 printf(" Traking media ranges:\n");
1060 for(i=0;i<(fNdets-1)/6+1;i++) {
1061 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
1063 det=(AliModule*)dets[ind];
1065 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
1068 printf(" %6s: %3d -> %3d;","NULL",0,0);
1074 //____________________________________________________________________________
1075 void AliRun::SetGenerator(AliGenerator *generator)
1078 // Load the event generator
1080 if(!fGenerator) fGenerator = generator;
1083 //____________________________________________________________________________
1084 void AliRun::ResetGenerator(AliGenerator *generator)
1087 // Load the event generator
1091 Warning("ResetGenerator","Replacing generator %s with %s\n",
1092 fGenerator->GetName(),generator->GetName());
1094 Warning("ResetGenerator","Replacing generator %s with NULL\n",
1095 fGenerator->GetName());
1096 fGenerator = generator;
1099 //____________________________________________________________________________
1100 void AliRun::SetTransPar(char *filename)
1102 fTransParName = filename;
1105 //____________________________________________________________________________
1106 void AliRun::SetBaseFile(char *filename)
1108 fBaseFileName = filename;
1111 //____________________________________________________________________________
1112 void AliRun::ReadTransPar()
1115 // Read filename to set the transport parameters
1119 const Int_t kncuts=10;
1120 const Int_t knflags=11;
1121 const Int_t knpars=kncuts+knflags;
1122 const char kpars[knpars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
1123 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
1124 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
1125 "MULS","PAIR","PHOT","RAYL"};
1129 Float_t cut[kncuts];
1130 Int_t flag[knflags];
1131 Int_t i, itmed, iret, ktmed, kz;
1134 // See whether the file is there
1135 filtmp=gSystem->ExpandPathName(fTransParName.Data());
1136 lun=fopen(filtmp,"r");
1139 Warning("ReadTransPar","File %s does not exist!\n",fTransParName.Data());
1144 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1145 printf(" *%59s\n","*");
1146 printf(" * Please check carefully what you are doing!%10s\n","*");
1147 printf(" *%59s\n","*");
1151 // Initialise cuts and flags
1152 for(i=0;i<kncuts;i++) cut[i]=-99;
1153 for(i=0;i<knflags;i++) flag[i]=-99;
1155 for(i=0;i<256;i++) line[i]='\0';
1156 // Read up to the end of line excluded
1157 iret=fscanf(lun,"%[^\n]",line);
1162 printf(" *%59s\n","*");
1163 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1167 // Read the end of line
1170 if(line[0]=='*') continue;
1172 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",
1173 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
1174 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
1175 &flag[8],&flag[9],&flag[10]);
1179 Warning("ReadTransPar","Error reading file %s\n",fTransParName.Data());
1182 // Check that the module exist
1183 AliModule *mod = GetModule(detName);
1185 // Get the array of media numbers
1186 TArrayI &idtmed = *mod->GetIdtmed();
1187 // Check that the tracking medium code is valid
1188 if(0<=itmed && itmed < 100) {
1189 ktmed=idtmed[itmed];
1191 Warning("ReadTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
1194 // Set energy thresholds
1195 for(kz=0;kz<kncuts;kz++) {
1197 if(fDebug) printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
1198 kpars[kz],cut[kz],itmed,mod->GetName());
1199 gMC->Gstpar(ktmed,kpars[kz],cut[kz]);
1202 // Set transport mechanisms
1203 for(kz=0;kz<knflags;kz++) {
1205 if(fDebug) printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
1206 kpars[kncuts+kz],flag[kz],itmed,mod->GetName());
1207 gMC->Gstpar(ktmed,kpars[kncuts+kz],Float_t(flag[kz]));
1211 Warning("ReadTransPar","Invalid medium code %d *\n",itmed);
1215 if(fDebug) printf("%s::ReadTransParModule: %s not present\n",ClassName(),detName);
1222 //_____________________________________________________________________________
1223 void AliRun::MakeTree(Option_t *option, const char *file)
1226 // Create the ROOT trees
1227 // Loop on all detectors to create the Root branch (if any)
1233 const char *oK = strstr(option,"K");
1234 const char *oH = strstr(option,"H");
1235 const char *oE = strstr(option,"E");
1236 const char *oD = strstr(option,"D");
1237 const char *oR = strstr(option,"R");
1238 const char *oS = strstr(option,"S");
1241 TDirectory *cwd = gDirectory;
1243 TBranch *branch = 0;
1245 if (oK) fStack->MakeTree(fEvent, file);
1247 if (oE && !fTreeE) {
1248 fTreeE = new TTree("TE","Header");
1249 branch = fTreeE->Branch("Header", "AliHeader", &fHeader, 4000, 0);
1250 branch->SetAutoDelete(kFALSE);
1251 TFolder *folder = (TFolder *)gROOT->FindObjectAny("/Folders/RunMC/Event/Header");
1252 if (folder) folder->Add(fHeader);
1253 // branch = fTreeE->Branch("Stack","AliStack", &fStack, 4000, 0);
1254 // branch->SetAutoDelete(kFALSE);
1255 // if (folder) folder->Add(fStack);
1256 fTreeE->Write(0,TObject::kOverwrite);
1259 if (file && branch) {
1260 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
1261 sprintf(outFile,"%s/%s",GetBaseFile(),file);
1262 branch->SetFile(outFile);
1263 TIter next( branch->GetListOfBranches());
1264 while ((branch=(TBranch*)next())) {
1265 branch->SetFile(outFile);
1268 printf("* MakeBranch * Diverting Branch %s to file %s\n", branch->GetName(),file);
1273 if (oH && !fTreeH) {
1274 sprintf(hname,"TreeH%d",fEvent);
1275 fTreeH = new TTree(hname,"Hits");
1276 fTreeH->SetAutoSave(1000000000); //no autosave
1277 fTreeH->Write(0,TObject::kOverwrite);
1279 if (oD && !fTreeD) {
1280 sprintf(hname,"TreeD%d",fEvent);
1281 fTreeD = new TTree(hname,"Digits");
1282 fTreeD->Write(0,TObject::kOverwrite);
1284 if (oS && !fTreeS) {
1285 sprintf(hname,"TreeS%d",fEvent);
1286 fTreeS = new TTree(hname,"SDigits");
1287 fTreeS->Write(0,TObject::kOverwrite);
1289 if (oR && !fTreeR) {
1290 sprintf(hname,"TreeR%d",fEvent);
1291 fTreeR = new TTree(hname,"Reconstruction");
1292 fTreeR->Write(0,TObject::kOverwrite);
1296 // Create a branch for hits/digits for each detector
1297 // Each branch is a TClonesArray. Each data member of the Hits classes
1298 // will be in turn a subbranch of the detector master branch
1299 TIter next(fModules);
1300 AliModule *detector;
1301 while((detector = (AliModule*)next())) {
1302 if (oH) detector->MakeBranch(option,file);
1306 //_____________________________________________________________________________
1307 TParticle* AliRun::Particle(Int_t i)
1309 return fStack->Particle(i);
1312 //_____________________________________________________________________________
1313 void AliRun::BeginEvent()
1315 // Clean-up previous event
1317 fEventEnergy.Reset();
1318 // Clean detector information
1325 // Reset all Detectors & kinematics & trees
1329 // Initialise event header
1330 fHeader->Reset(fRun,fEvent);
1332 fStack->BeginEvent(fEvent);
1336 fLego->BeginEvent();
1349 sprintf(hname,"TreeH%d",fEvent);
1350 fTreeH->SetName(hname);
1354 sprintf(hname,"TreeD%d",fEvent);
1355 fTreeD->SetName(hname);
1356 fTreeD->Write(0,TObject::kOverwrite);
1360 sprintf(hname,"TreeS%d",fEvent);
1361 fTreeS->SetName(hname);
1362 fTreeS->Write(0,TObject::kOverwrite);
1366 sprintf(hname,"TreeR%d",fEvent);
1367 fTreeR->SetName(hname);
1368 fTreeR->Write(0,TObject::kOverwrite);
1371 //_____________________________________________________________________________
1372 void AliRun::ResetDigits()
1375 // Reset all Detectors digits
1377 TIter next(fModules);
1378 AliModule *detector;
1379 while((detector = (AliModule*)next())) {
1380 detector->ResetDigits();
1384 //_____________________________________________________________________________
1385 void AliRun::ResetSDigits()
1388 // Reset all Detectors digits
1390 TIter next(fModules);
1391 AliModule *detector;
1392 while((detector = (AliModule*)next())) {
1393 detector->ResetSDigits();
1397 //_____________________________________________________________________________
1398 void AliRun::ResetHits()
1401 // Reset all Detectors hits
1403 TIter next(fModules);
1404 AliModule *detector;
1405 while((detector = (AliModule*)next())) {
1406 detector->ResetHits();
1410 //_____________________________________________________________________________
1411 void AliRun::ResetPoints()
1414 // Reset all Detectors points
1416 TIter next(fModules);
1417 AliModule *detector;
1418 while((detector = (AliModule*)next())) {
1419 detector->ResetPoints();
1423 //_____________________________________________________________________________
1424 void AliRun::RunMC(Int_t nevent, const char *setup)
1427 // Main function to be called to process a galice run
1429 // Root > gAlice.Run();
1430 // a positive number of events will cause the finish routine
1433 fEventsPerRun = nevent;
1434 // check if initialisation has been done
1435 if (!fInitDone) InitMC(setup);
1437 // Create the Root Tree with one branch per detector
1441 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1442 MakeTree("K","Kine.root");
1443 MakeTree("H","Hits.root");
1448 gMC->ProcessRun(nevent);
1450 // End of this run, close files
1451 if(nevent>0) FinishRun();
1454 //_____________________________________________________________________________
1455 void AliRun::RunReco(const char *selected, Int_t first, Int_t last)
1458 // Main function to be called to reconstruct Alice event
1460 cout << "Found "<< gAlice->TreeE()->GetEntries() << "events" << endl;
1461 Int_t nFirst = first;
1462 Int_t nLast = (last < 0)? (Int_t) gAlice->TreeE()->GetEntries() : last;
1464 for (Int_t nevent = nFirst; nevent <= nLast; nevent++) {
1465 cout << "Processing event "<< nevent << endl;
1468 Digits2Reco(selected);
1472 //_____________________________________________________________________________
1474 void AliRun::Hits2Digits(const char *selected)
1477 // Convert Hits to sumable digits
1479 for (Int_t nevent=0; nevent<gAlice->TreeE()->GetEntries(); nevent++) {
1482 Hits2SDigits(selected);
1483 SDigits2Digits(selected);
1488 //_____________________________________________________________________________
1490 void AliRun::Tree2Tree(Option_t *option, const char *selected)
1493 // Function to transform the content of
1495 // - TreeH to TreeS (option "S")
1496 // - TreeS to TreeD (option "D")
1497 // - TreeD to TreeR (option "R")
1499 // If multiple options are specified ("SDR"), transformation will be done in sequence for
1500 // selected detector and for all detectors if none is selected (detector string
1501 // can contain blank separated list of detector names).
1504 const char *oS = strstr(option,"S");
1505 const char *oD = strstr(option,"D");
1506 const char *oR = strstr(option,"R");
1508 TObjArray *detectors = Detectors();
1510 TIter next(detectors);
1512 AliDetector *detector = 0;
1514 TDirectory *cwd = gDirectory;
1518 while((detector = (AliDetector*)next())) {
1520 if (strcmp(detector->GetName(),selected)) continue;
1521 if (detector->IsActive()){
1522 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1524 sprintf(outFile,"SDigits.%s.root",detector->GetName());
1525 detector->MakeBranch("S",outFile);
1528 sprintf(outFile,"Digits.%s.root",detector->GetName());
1529 detector->MakeBranch("D",outFile);
1532 sprintf(outFile,"Reco.%s.root",detector->GetName());
1533 detector->MakeBranch("R",outFile);
1536 detector->MakeBranch(option);
1542 cout << "Hits2SDigits: Processing " << detector->GetName() << "..." << endl;
1543 detector->Hits2SDigits();
1546 cout << "SDigits2Digits: Processing " << detector->GetName() << "..." << endl;
1547 detector->SDigits2Digits();
1550 cout << "Digits2Reco: Processing " << detector->GetName() << "..." << endl;
1551 detector->Digits2Reco();
1560 //_____________________________________________________________________________
1561 void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min,
1562 Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max,
1563 Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener)
1566 // Generates lego plots of:
1567 // - radiation length map phi vs theta
1568 // - radiation length map phi vs eta
1569 // - interaction length map
1570 // - g/cm2 length map
1572 // ntheta bins in theta, eta
1573 // themin minimum angle in theta (degrees)
1574 // themax maximum angle in theta (degrees)
1576 // phimin minimum angle in phi (degrees)
1577 // phimax maximum angle in phi (degrees)
1578 // rmin minimum radius
1579 // rmax maximum radius
1582 // The number of events generated = ntheta*nphi
1583 // run input parameters in macro setup (default="Config.C")
1585 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1588 <img src="picts/AliRunLego1.gif">
1593 <img src="picts/AliRunLego2.gif">
1598 <img src="picts/AliRunLego3.gif">
1603 // check if initialisation has been done
1604 if (!fInitDone) InitMC(setup);
1605 //Save current generator
1606 AliGenerator *gen=Generator();
1608 // Set new generator
1609 if (!gener) gener = new AliLegoGenerator();
1610 ResetGenerator(gener);
1612 // Configure Generator
1613 gener->SetRadiusRange(rmin, rmax);
1614 gener->SetZMax(zmax);
1615 gener->SetCoor1Range(nc1, c1min, c1max);
1616 gener->SetCoor2Range(nc2, c2min, c2max);
1619 //Create Lego object
1620 fLego = new AliLego("lego",gener);
1622 //Prepare MC for Lego Run
1627 gMC->ProcessRun(nc1*nc2+1);
1629 // Create only the Root event Tree
1632 // End of this run, close files
1634 // Restore current generator
1635 ResetGenerator(gen);
1636 // Delete Lego Object
1637 delete fLego; fLego=0;
1640 //_____________________________________________________________________________
1641 void AliRun::SetConfigFunction(const char * config)
1644 // Set the signature of the function contained in Config.C to configure
1647 fConfigFunction=config;
1650 //_____________________________________________________________________________
1651 void AliRun::SetCurrentTrack(Int_t track)
1654 // Set current track number
1656 fStack->SetCurrentTrack(track);
1659 //_____________________________________________________________________________
1660 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1661 Float_t *vpos, Float_t *polar, Float_t tof,
1662 AliMCProcess mech, Int_t &ntr, Float_t weight)
1664 // Delegate to stack
1666 fStack->SetTrack(done, parent, pdg, pmom, vpos, polar, tof,
1670 //_____________________________________________________________________________
1671 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg,
1672 Double_t px, Double_t py, Double_t pz, Double_t e,
1673 Double_t vx, Double_t vy, Double_t vz, Double_t tof,
1674 Double_t polx, Double_t poly, Double_t polz,
1675 AliMCProcess mech, Int_t &ntr, Float_t weight)
1677 // Delegate to stack
1679 fStack->SetTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
1680 polx, poly, polz, mech, ntr, weight);
1684 //_____________________________________________________________________________
1685 void AliRun::SetHighWaterMark(const Int_t nt)
1688 // Set high water mark for last track in event
1689 fStack->SetHighWaterMark(nt);
1692 //_____________________________________________________________________________
1693 void AliRun::KeepTrack(const Int_t track)
1696 // Delegate to stack
1698 fStack->KeepTrack(track);
1701 //_____________________________________________________________________________
1702 void AliRun::StepManager(Int_t id)
1705 // Called at every step during transport
1709 // --- If lego option, do it and leave
1711 fLego->StepManager();
1714 //Update energy deposition tables
1715 AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
1717 //Call the appropriate stepping routine;
1718 AliModule *det = (AliModule*)fModules->At(id);
1720 fMCQA->StepManager(id);
1726 //_____________________________________________________________________________
1727 void AliRun::Streamer(TBuffer &R__b)
1729 // Stream an object of class AliRun.
1731 if (R__b.IsReading()) {
1732 if (!gAlice) gAlice = this;
1734 AliRun::Class()->ReadBuffer(R__b, this);
1736 gROOT->GetListOfBrowsables()->Add(this,"Run");
1738 fTreeE = (TTree*)gDirectory->Get("TE");
1740 fTreeE->SetBranchAddress("Header", &fHeader);
1743 else Error("Streamer","cannot find Header Tree\n");
1744 fTreeE->GetEntry(0);
1748 AliRun::Class()->WriteBuffer(R__b, this);
1753 //___________________________________________________________________________
1754 Int_t AliRun::CurrentTrack() const {
1756 // Returns current track
1758 return fStack->CurrentTrack();
1761 //___________________________________________________________________________
1762 Int_t AliRun::GetNtrack() const {
1764 // Returns number of tracks in stack
1766 return fStack->GetNtrack();
1769 //___________________________________________________________________________
1770 TObjArray* AliRun::Particles() {
1772 // Returns pointer to Particles array
1774 return fStack->Particles();
1777 //___________________________________________________________________________
1778 TTree* AliRun::TreeK() {
1780 // Returns pointer to the TreeK array
1782 return fStack->TreeK();
1786 void AliRun::SetGenEventHeader(AliGenEventHeader* header)
1788 fHeader->SetGenEventHeader(header);