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.70 2001/06/29 08:01:36 morsch
19 Small correction to the previous.
21 Revision 1.69 2001/06/28 16:27:50 morsch
22 AliReco() with user control of event range.
24 Revision 1.68 2001/06/11 13:14:40 morsch
25 SetAliGenEventHeader() method added.
27 Revision 1.67 2001/06/07 18:24:50 buncic
28 Removed compilation warning in AliConfig initialisation.
30 Revision 1.66 2001/05/22 14:32:40 hristov
33 Revision 1.65 2001/05/21 17:22:51 buncic
34 Fixed problem with missing AliConfig while reading galice.root
36 Revision 1.64 2001/05/16 14:57:22 alibrary
37 New files for folders and Stack
39 Revision 1.62 2001/04/06 11:12:33 morsch
40 Clear fParticles after each event. (Ivana Hrivnacova)
42 Revision 1.61 2001/03/30 07:04:10 morsch
43 Call fGenerator->FinishRun() for final print-outs, cross-section and weight calculations.
45 Revision 1.60 2001/03/21 18:22:30 hristov
46 fParticleFileMap fix (I.Hrivnacova)
48 Revision 1.59 2001/03/12 17:47:03 hristov
49 Changes needed on Sun with CC 5.0
51 Revision 1.58 2001/03/09 14:27:26 morsch
52 Fix for multiple events per file: inhibit decrease of size of fParticleFileMap.
54 Revision 1.57 2001/02/23 17:40:23 buncic
55 All trees needed for simulation created in RunMC(). TreeR and its branches
56 are now created in new RunReco() method.
58 Revision 1.56 2001/02/14 15:45:20 hristov
59 Algorithmic way of getting entry index in fParticleMap. Protection of fParticleFileMap (I.Hrivnacova)
61 Revision 1.55 2001/02/12 15:52:54 buncic
62 Removed OpenBaseFile().
64 Revision 1.54 2001/02/07 10:39:05 hristov
65 Remove default value for argument
67 Revision 1.53 2001/02/06 11:02:26 hristov
68 New SetTrack interface added, added check for unfilled particles in FinishEvent (I.Hrivnacova)
70 Revision 1.52 2001/02/05 16:22:25 buncic
71 Added TreeS to GetEvent().
73 Revision 1.51 2001/02/02 15:16:20 morsch
74 SetHighWaterMark method added to mark last particle in event.
76 Revision 1.50 2001/01/27 10:32:00 hristov
77 Leave the loop when primaries are filled (I.Hrivnacova)
79 Revision 1.49 2001/01/26 19:58:48 hristov
80 Major upgrade of AliRoot code
82 Revision 1.48 2001/01/17 10:50:50 hristov
83 Corrections to destructors
85 Revision 1.47 2000/12/18 10:44:01 morsch
86 Possibility to set field map by passing pointer to objet of type AliMagF via
89 gAlice->SetField(new AliMagFCM("Map2", "$(ALICE_ROOT)/data/field01.dat",2,1.,10.));
91 Revision 1.46 2000/12/14 19:29:27 fca
92 galice.cuts was not read any more
94 Revision 1.45 2000/11/30 07:12:49 alibrary
95 Introducing new Rndm and QA classes
97 Revision 1.44 2000/10/26 13:58:59 morsch
98 Add possibility to choose the lego generator (of type AliGeneratorLego or derived) when running
99 RunLego(). Default is the base class AliGeneratorLego.
101 Revision 1.43 2000/10/09 09:43:17 fca
102 Special remapping of hits for TPC and TRD. End-of-primary action introduced
104 Revision 1.42 2000/10/02 21:28:14 fca
105 Removal of useless dependecies via forward declarations
107 Revision 1.41 2000/07/13 16:19:09 fca
108 Mainly coding conventions + some small bug fixes
110 Revision 1.40 2000/07/12 08:56:25 fca
111 Coding convention correction and warning removal
113 Revision 1.39 2000/07/11 18:24:59 fca
114 Coding convention corrections + few minor bug fixes
116 Revision 1.38 2000/06/20 13:05:45 fca
117 Writing down the TREE headers before job starts
119 Revision 1.37 2000/06/09 20:05:11 morsch
120 Introduce possibility to chose magnetic field version 3: AliMagFDM + field02.dat
122 Revision 1.36 2000/06/08 14:03:58 hristov
123 Only one initializer for a default argument
125 Revision 1.35 2000/06/07 10:13:14 hristov
126 Delete only existent objects.
128 Revision 1.34 2000/05/18 10:45:38 fca
129 Delete Particle Factory properly
131 Revision 1.33 2000/05/16 13:10:40 fca
132 New method IsNewTrack and fix for a problem in Father-Daughter relations
134 Revision 1.32 2000/04/27 10:38:21 fca
135 Correct termination of Lego Run and introduce Lego getter in AliRun
137 Revision 1.31 2000/04/26 10:17:32 fca
138 Changes in Lego for G4 compatibility
140 Revision 1.30 2000/04/18 19:11:40 fca
141 Introduce variable Config.C function signature
143 Revision 1.29 2000/04/07 11:12:34 fca
144 G4 compatibility changes
146 Revision 1.28 2000/04/05 06:51:06 fca
147 Workaround for an HP compiler problem
149 Revision 1.27 2000/03/22 18:08:07 fca
150 Rationalisation of the virtual MC interfaces
152 Revision 1.26 2000/03/22 13:42:26 fca
153 SetGenerator does not replace an existing generator, ResetGenerator does
155 Revision 1.25 2000/02/23 16:25:22 fca
156 AliVMC and AliGeant3 classes introduced
157 ReadEuclid moved from AliRun to AliModule
159 Revision 1.24 2000/01/19 17:17:20 fca
160 Introducing a list of lists of hits -- more hits allowed for detector now
162 Revision 1.23 1999/12/03 11:14:31 fca
163 Fixing previous wrong checking
165 Revision 1.21 1999/11/25 10:40:08 fca
166 Fixing daughters information also in primary tracks
168 Revision 1.20 1999/10/04 18:08:49 fca
169 Adding protection against inconsistent Euclid files
171 Revision 1.19 1999/09/29 07:50:40 fca
172 Introduction of the Copyright and cvs Log
176 ///////////////////////////////////////////////////////////////////////////////
178 // Control class for Alice C++ //
179 // Only one single instance of this class exists. //
180 // The object is created in main program aliroot //
181 // and is pointed by the global gAlice. //
183 // -Supports the list of all Alice Detectors (fModules). //
184 // -Supports the list of particles (fParticles). //
185 // -Supports the Trees. //
186 // -Supports the geometry. //
187 // -Supports the event display. //
190 <img src="picts/AliRunClass.gif">
195 <img src="picts/alirun.gif">
199 ///////////////////////////////////////////////////////////////////////////////
204 #include <iostream.h>
211 #include <TObjectTable.h>
213 #include <TGeometry.h>
215 #include <TBrowser.h>
219 #include "TParticle.h"
221 #include "AliDisplay.h"
224 #include "AliMagFC.h"
225 #include "AliMagFCM.h"
226 #include "AliMagFDM.h"
228 #include "TRandom3.h"
230 #include "AliGenerator.h"
231 #include "AliLegoGenerator.h"
232 #include "AliConfig.h"
233 #include "AliStack.h"
234 #include "AliGenEventHeader.h"
235 #include "AliHeader.h"
237 #include "AliDetector.h"
243 //_____________________________________________________________________________
247 // Default constructor for AliRun
270 fPDGDB = 0; //Particle factory object!
272 fConfigFunction = "\0";
275 fTransParName = "\0";
276 fBaseFileName = ".\0";
280 //_____________________________________________________________________________
281 AliRun::AliRun(const char *name, const char *title)
285 // Constructor for the main processor.
286 // Creates the geometry
287 // Creates the list of Detectors.
288 // Creates the list of particles.
304 fConfigFunction = "Config();";
306 // Set random number generator
307 gRandom = fRandom = new TRandom3();
309 if (gSystem->Getenv("CONFIG_SEED")) {
310 gRandom->SetSeed((UInt_t)atoi(gSystem->Getenv("CONFIG_SEED")));
313 gROOT->GetListOfBrowsables()->Add(this,name);
316 fStack = new AliStack(10000);
317 // create the support list for the various Detectors
318 fModules = new TObjArray(77);
320 // Create the TNode geometry for the event display
322 BuildSimpleGeometry();
324 fHeader = new AliHeader();
330 // Create default mag field
335 // Prepare the tracking medium lists
336 fImedia = new TArrayI(1000);
337 for(i=0;i<1000;i++) (*fImedia)[i]=-99;
340 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
342 AliConfig::Instance()->Add(fPDGDB);
344 // Create HitLists list
345 fHitLists = new TList();
348 fBaseFileName = ".\0";
354 //_____________________________________________________________________________
358 // Default AliRun destructor
383 //_____________________________________________________________________________
384 void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
387 // Add a hit to detector id
389 TObjArray &dets = *fModules;
390 if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits);
393 //_____________________________________________________________________________
394 void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
397 // Add digit to detector id
399 TObjArray &dets = *fModules;
400 if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits);
403 //_____________________________________________________________________________
404 void AliRun::Browse(TBrowser *b)
407 // Called when the item "Run" is clicked on the left pane
408 // of the Root browser.
409 // It displays the Root Trees and all detectors.
411 if(!fStack) fStack=fHeader->Stack();
412 TTree* pTreeK = fStack->TreeK();
414 if (pTreeK) b->Add(pTreeK,pTreeK->GetName());
415 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
416 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
417 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
418 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
419 if (fTreeS) b->Add(fTreeS,fTreeS->GetName());
421 TIter next(fModules);
423 while((detector = (AliModule*)next())) {
424 b->Add(detector,detector->GetName());
426 b->Add(fMCQA,"AliMCQA");
429 //_____________________________________________________________________________
433 // Initialize Alice geometry
438 //_____________________________________________________________________________
439 void AliRun::BuildSimpleGeometry()
442 // Create a simple TNode geometry used by Root display engine
444 // Initialise geometry
446 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
447 new TMaterial("void","Vacuum",0,0,0); //Everything is void
448 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
449 brik->SetVisibility(0);
450 new TNode("alice","alice","S_alice");
453 //_____________________________________________________________________________
454 void AliRun::CleanDetectors()
457 // Clean Detectors at the end of event
459 TIter next(fModules);
461 while((detector = (AliModule*)next())) {
462 detector->FinishEvent();
466 //_____________________________________________________________________________
467 Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
470 // Return the distance from the mouse to the AliRun object
476 //_____________________________________________________________________________
477 void AliRun::DumpPart (Int_t i) const
480 // Dumps particle i in the stack
485 //_____________________________________________________________________________
486 void AliRun::DumpPStack () const
489 // Dumps the particle stack
491 fStack->DumpPStack();
494 //_____________________________________________________________________________
495 void AliRun::SetField(AliMagF* magField)
497 // Set Magnetic Field Map
502 //_____________________________________________________________________________
503 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
504 Float_t maxField, char* filename)
507 // Set magnetic field parameters
508 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
509 // version Magnetic field map version (only 1 active now)
510 // scale Scale factor for the magnetic field
511 // maxField Maximum value for the magnetic field
514 // --- Sanity check on mag field flags
515 if(fField) delete fField;
517 fField = new AliMagFC("Map1"," ",type,scale,maxField);
518 } else if(version<=2) {
519 fField = new AliMagFCM("Map2-3",filename,type,scale,maxField);
521 } else if(version==3) {
522 fField = new AliMagFDM("Map4",filename,type,scale,maxField);
525 Warning("SetField","Invalid map %d\n",version);
529 //_____________________________________________________________________________
530 void AliRun::PreTrack()
532 TObjArray &dets = *fModules;
535 for(Int_t i=0; i<=fNdets; i++)
536 if((module = (AliModule*)dets[i]))
542 //_____________________________________________________________________________
543 void AliRun::PostTrack()
545 TObjArray &dets = *fModules;
548 for(Int_t i=0; i<=fNdets; i++)
549 if((module = (AliModule*)dets[i]))
553 //_____________________________________________________________________________
554 void AliRun::FinishPrimary()
557 // Called at the end of each primary track
560 // static Int_t count=0;
561 // const Int_t times=10;
562 // This primary is finished, purify stack
563 fStack->PurifyKine();
565 TIter next(fModules);
567 while((detector = (AliModule*)next())) {
568 detector->FinishPrimary();
571 // Write out hits if any
572 if (gAlice->TreeH()) {
573 gAlice->TreeH()->Fill();
577 // if(++count%times==1) gObjectTable->Print();
580 //_____________________________________________________________________________
581 void AliRun::BeginPrimary()
584 // Called at the beginning of each primary track
592 //_____________________________________________________________________________
593 void AliRun::FinishEvent()
596 // Called at the end of the event.
600 if(fLego) fLego->FinishEvent();
602 //Update the energy deposit tables
604 for(i=0;i<fEventEnergy.GetSize();i++) {
605 fSummEnergy[i]+=fEventEnergy[i];
606 fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
611 // Update Header information
613 fHeader->SetNprimary(fStack->GetNprimary());
614 fHeader->SetNtrack(fStack->GetNtrack());
617 // Write out the kinematics
618 fStack->FinishEvent();
620 // Write out the event Header information
622 fHeader->SetStack(fStack);
627 // Write Tree headers
628 TTree* pTreeK = fStack->TreeK();
629 if (pTreeK) pTreeK->Write(0,TObject::kOverwrite);
630 if (fTreeH) fTreeH->Write(0,TObject::kOverwrite);
635 //_____________________________________________________________________________
636 void AliRun::FinishRun()
639 // Called at the end of the run.
643 if(fLego) fLego->FinishRun();
645 // Clean detector information
646 TIter next(fModules);
648 while((detector = (AliModule*)next())) {
649 detector->FinishRun();
652 //Output energy summary tables
655 TFile *file = fTreeE->GetCurrentFile();
659 fTreeE->Write(0,TObject::kOverwrite);
661 // Write AliRun info and all detectors parameters
662 Write(0,TObject::kOverwrite);
664 // Clean tree information
669 delete fTreeH; fTreeH = 0;
672 delete fTreeD; fTreeD = 0;
675 delete fTreeR; fTreeR = 0;
678 delete fTreeE; fTreeE = 0;
681 delete fTreeS; fTreeS = 0;
688 //_____________________________________________________________________________
689 void AliRun::FlagTrack(Int_t track)
693 fStack->FlagTrack(track);
696 //_____________________________________________________________________________
697 void AliRun::EnergySummary()
700 // Print summary of deposited energy
706 Int_t kn, i, left, j, id;
707 const Float_t kzero=0;
708 Int_t ievent=fHeader->GetEvent()+1;
710 // Energy loss information
712 printf("***************** Energy Loss Information per event (GEV) *****************\n");
713 for(kn=1;kn<fEventEnergy.GetSize();kn++) {
716 fEventEnergy[ndep]=kn;
721 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,kzero))/ed;
724 fSummEnergy[ndep]=ed;
725 fSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,kzero));
730 for(kn=0;kn<(ndep-1)/3+1;kn++) {
732 for(i=0;i<(3<left?3:left);i++) {
734 id=Int_t (fEventEnergy[j]+0.1);
735 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]);
740 // Relative energy loss in different detectors
741 printf("******************** Relative Energy Loss per event ********************\n");
742 printf("Total energy loss per event %10.3f GeV\n",edtot);
743 for(kn=0;kn<(ndep-1)/5+1;kn++) {
745 for(i=0;i<(5<left?5:left);i++) {
747 id=Int_t (fEventEnergy[j]+0.1);
748 printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot);
752 for(kn=0;kn<75;kn++) printf("*");
756 // Reset the TArray's
757 // fEventEnergy.Set(0);
758 // fSummEnergy.Set(0);
759 // fSum2Energy.Set(0);
762 //_____________________________________________________________________________
763 AliModule *AliRun::GetModule(const char *name) const
766 // Return pointer to detector from name
768 return (AliModule*)fModules->FindObject(name);
771 //_____________________________________________________________________________
772 AliDetector *AliRun::GetDetector(const char *name) const
775 // Return pointer to detector from name
777 return (AliDetector*)fModules->FindObject(name);
780 //_____________________________________________________________________________
781 Int_t AliRun::GetModuleID(const char *name) const
784 // Return galice internal detector identifier from name
787 TObject *mod=fModules->FindObject(name);
788 if(mod) i=fModules->IndexOf(mod);
792 //_____________________________________________________________________________
793 Int_t AliRun::GetEvent(Int_t event)
796 // Connect the Trees Kinematics and Hits for event # event
797 // Set branch addresses
800 // Reset existing structures
805 // Delete Trees already connected
806 if (fTreeH) { delete fTreeH; fTreeH = 0;}
807 if (fTreeD) { delete fTreeD; fTreeD = 0;}
808 if (fTreeR) { delete fTreeR; fTreeR = 0;}
809 if (fTreeS) { delete fTreeS; fTreeS = 0;}
811 // Create the particle stack
812 if (fHeader) delete fHeader;
815 // Get header from file
817 fTreeE->SetBranchAddress("Header", &fHeader);
819 if (!fTreeE->GetEntry(event)) {
820 Error("GetEvent","Cannot find event:%d\n",event);
825 Error("GetEvent","Cannot find Header Tree (TE)\n");
829 // Get the stack from the header, set fStack to 0 if it
830 // fails to get event
831 if (fStack) delete fStack;
832 fStack = fHeader->Stack();
834 if (!fStack->GetEvent(event,0)) fStack = 0;
838 TFile *file = fTreeE->GetCurrentFile();
842 // Get Hits Tree header from file
843 sprintf(treeName,"TreeH%d",event);
844 fTreeH = (TTree*)gDirectory->Get(treeName);
846 Error("GetEvent","cannot find Hits Tree for event:%d\n",event);
849 // Get Digits Tree header from file
850 sprintf(treeName,"TreeD%d",event);
851 fTreeD = (TTree*)gDirectory->Get(treeName);
853 // Warning("GetEvent","cannot find Digits Tree for event:%d\n",event);
858 // Get SDigits Tree header from file
859 sprintf(treeName,"TreeS%d",event);
860 fTreeS = (TTree*)gDirectory->Get(treeName);
862 // Warning("GetEvent","cannot find SDigits Tree for event:%d\n",event);
867 // Get Reconstruct Tree header from file
868 sprintf(treeName,"TreeR%d",event);
869 fTreeR = (TTree*)gDirectory->Get(treeName);
871 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
876 // Set Trees branch addresses
877 TIter next(fModules);
879 while((detector = (AliModule*)next())) {
880 detector->SetTreeAddress();
883 return fStack->GetNtrack();
886 //_____________________________________________________________________________
887 TGeometry *AliRun::GetGeometry()
890 // Import Alice geometry from current file
891 // Return pointer to geometry object
893 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
895 // Unlink and relink nodes in detectors
896 // This is bad and there must be a better way...
899 TIter next(fModules);
901 while((detector = (AliModule*)next())) {
902 TList *dnodes=detector->Nodes();
905 for ( j=0; j<dnodes->GetSize(); j++) {
906 node = (TNode*) dnodes->At(j);
907 node1 = fGeometry->GetNode(node->GetName());
908 dnodes->Remove(node);
909 dnodes->AddAt(node1,j);
915 //_____________________________________________________________________________
916 void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
917 Float_t &e, Float_t *vpos, Float_t *polar,
922 fStack->GetNextTrack(mtrack, ipart, pmom, e, vpos, polar, tof);
925 //_____________________________________________________________________________
926 Int_t AliRun::GetPrimary(Int_t track) const
929 // return number of primary that has generated track
931 return fStack->GetPrimary(track);
934 //_____________________________________________________________________________
935 void AliRun::InitMC(const char *setup)
938 // Initialize the Alice setup
942 Warning("Init","Cannot initialise AliRun twice!\n");
946 gROOT->LoadMacro(setup);
947 gInterpreter->ProcessLine(fConfigFunction.Data());
950 gMC->DefineParticles(); //Create standard MC particles
952 TObject *objfirst, *objlast;
954 fNdets = fModules->GetLast()+1;
957 //=================Create Materials and geometry
960 // Added also after in case of interactive initialisation of modules
961 fNdets = fModules->GetLast()+1;
963 TIter next(fModules);
965 while((detector = (AliModule*)next())) {
966 detector->SetTreeAddress();
967 objlast = gDirectory->GetList()->Last();
969 // Add Detector histograms in Detector list of histograms
970 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
971 else objfirst = gDirectory->GetList()->First();
973 detector->Histograms()->Add(objfirst);
974 objfirst = gDirectory->GetList()->After(objfirst);
977 ReadTransPar(); //Read the cuts for all materials
979 MediaTable(); //Build the special IMEDIA table
981 //Initialise geometry deposition table
982 fEventEnergy.Set(gMC->NofVolumes()+1);
983 fSummEnergy.Set(gMC->NofVolumes()+1);
984 fSum2Energy.Set(gMC->NofVolumes()+1);
986 //Compute cross-sections
989 //Write Geometry object to current file.
994 fMCQA = new AliMCQA(fNdets);
996 AliConfig::Instance();
998 // Save stuff at the beginning of the file to avoid file corruption
1002 //_____________________________________________________________________________
1003 void AliRun::MediaTable()
1006 // Built media table to get from the media number to
1009 Int_t kz, nz, idt, lz, i, k, ind;
1011 TObjArray &dets = *gAlice->Detectors();
1014 // For all detectors
1015 for (kz=0;kz<fNdets;kz++) {
1016 // If detector is defined
1017 if((det=(AliModule*) dets[kz])) {
1018 TArrayI &idtmed = *(det->GetIdtmed());
1019 for(nz=0;nz<100;nz++) {
1020 // Find max and min material number
1021 if((idt=idtmed[nz])) {
1022 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
1023 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
1026 if(det->LoMedium() > det->HiMedium()) {
1027 det->LoMedium() = 0;
1028 det->HiMedium() = 0;
1030 if(det->HiMedium() > fImedia->GetSize()) {
1031 Error("MediaTable","Increase fImedia from %d to %d",
1032 fImedia->GetSize(),det->HiMedium());
1035 // Tag all materials in rage as belonging to detector kz
1036 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
1043 // Print summary table
1044 printf(" Traking media ranges:\n");
1045 for(i=0;i<(fNdets-1)/6+1;i++) {
1046 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
1048 det=(AliModule*)dets[ind];
1050 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
1053 printf(" %6s: %3d -> %3d;","NULL",0,0);
1059 //____________________________________________________________________________
1060 void AliRun::SetGenerator(AliGenerator *generator)
1063 // Load the event generator
1065 if(!fGenerator) fGenerator = generator;
1068 //____________________________________________________________________________
1069 void AliRun::ResetGenerator(AliGenerator *generator)
1072 // Load the event generator
1076 Warning("ResetGenerator","Replacing generator %s with %s\n",
1077 fGenerator->GetName(),generator->GetName());
1079 Warning("ResetGenerator","Replacing generator %s with NULL\n",
1080 fGenerator->GetName());
1081 fGenerator = generator;
1084 //____________________________________________________________________________
1085 void AliRun::SetTransPar(char *filename)
1087 fTransParName = filename;
1090 //____________________________________________________________________________
1091 void AliRun::SetBaseFile(char *filename)
1093 fBaseFileName = filename;
1096 //____________________________________________________________________________
1097 void AliRun::ReadTransPar()
1100 // Read filename to set the transport parameters
1104 const Int_t kncuts=10;
1105 const Int_t knflags=11;
1106 const Int_t knpars=kncuts+knflags;
1107 const char kpars[knpars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
1108 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
1109 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
1110 "MULS","PAIR","PHOT","RAYL"};
1114 Float_t cut[kncuts];
1115 Int_t flag[knflags];
1116 Int_t i, itmed, iret, ktmed, kz;
1119 // See whether the file is there
1120 filtmp=gSystem->ExpandPathName(fTransParName.Data());
1121 lun=fopen(filtmp,"r");
1124 Warning("ReadTransPar","File %s does not exist!\n",fTransParName.Data());
1129 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1130 printf(" *%59s\n","*");
1131 printf(" * Please check carefully what you are doing!%10s\n","*");
1132 printf(" *%59s\n","*");
1136 // Initialise cuts and flags
1137 for(i=0;i<kncuts;i++) cut[i]=-99;
1138 for(i=0;i<knflags;i++) flag[i]=-99;
1140 for(i=0;i<256;i++) line[i]='\0';
1141 // Read up to the end of line excluded
1142 iret=fscanf(lun,"%[^\n]",line);
1147 printf(" *%59s\n","*");
1148 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1152 // Read the end of line
1155 if(line[0]=='*') continue;
1157 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",
1158 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
1159 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
1160 &flag[8],&flag[9],&flag[10]);
1164 Warning("ReadTransPar","Error reading file %s\n",fTransParName.Data());
1167 // Check that the module exist
1168 AliModule *mod = GetModule(detName);
1170 // Get the array of media numbers
1171 TArrayI &idtmed = *mod->GetIdtmed();
1172 // Check that the tracking medium code is valid
1173 if(0<=itmed && itmed < 100) {
1174 ktmed=idtmed[itmed];
1176 Warning("ReadTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
1179 // Set energy thresholds
1180 for(kz=0;kz<kncuts;kz++) {
1182 if(fDebug) printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
1183 kpars[kz],cut[kz],itmed,mod->GetName());
1184 gMC->Gstpar(ktmed,kpars[kz],cut[kz]);
1187 // Set transport mechanisms
1188 for(kz=0;kz<knflags;kz++) {
1190 if(fDebug) printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
1191 kpars[kncuts+kz],flag[kz],itmed,mod->GetName());
1192 gMC->Gstpar(ktmed,kpars[kncuts+kz],Float_t(flag[kz]));
1196 Warning("ReadTransPar","Invalid medium code %d *\n",itmed);
1200 if(fDebug) printf("%s::ReadTransParModule: %s not present\n",ClassName(),detName);
1207 //_____________________________________________________________________________
1208 void AliRun::MakeTree(Option_t *option, const char *file)
1211 // Create the ROOT trees
1212 // Loop on all detectors to create the Root branch (if any)
1218 const char *oK = strstr(option,"K");
1219 const char *oH = strstr(option,"H");
1220 const char *oE = strstr(option,"E");
1221 const char *oD = strstr(option,"D");
1222 const char *oR = strstr(option,"R");
1223 const char *oS = strstr(option,"S");
1226 TDirectory *cwd = gDirectory;
1228 TBranch *branch = 0;
1230 if (oK) fStack->MakeTree(fEvent, file);
1232 if (oE && !fTreeE) {
1233 fTreeE = new TTree("TE","Header");
1234 branch = fTreeE->Branch("Header", "AliHeader", &fHeader, 4000, 0);
1235 branch->SetAutoDelete(kFALSE);
1236 TFolder *folder = (TFolder *)gROOT->FindObjectAny("/Folders/RunMC/Event/Header");
1237 if (folder) folder->Add(fHeader);
1238 // branch = fTreeE->Branch("Stack","AliStack", &fStack, 4000, 0);
1239 // branch->SetAutoDelete(kFALSE);
1240 // if (folder) folder->Add(fStack);
1241 fTreeE->Write(0,TObject::kOverwrite);
1244 if (file && branch) {
1245 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
1246 sprintf(outFile,"%s/%s",GetBaseFile(),file);
1247 branch->SetFile(outFile);
1248 TIter next( branch->GetListOfBranches());
1249 while ((branch=(TBranch*)next())) {
1250 branch->SetFile(outFile);
1253 printf("* MakeBranch * Diverting Branch %s to file %s\n", branch->GetName(),file);
1258 if (oH && !fTreeH) {
1259 sprintf(hname,"TreeH%d",fEvent);
1260 fTreeH = new TTree(hname,"Hits");
1261 fTreeH->SetAutoSave(1000000000); //no autosave
1262 fTreeH->Write(0,TObject::kOverwrite);
1264 if (oD && !fTreeD) {
1265 sprintf(hname,"TreeD%d",fEvent);
1266 fTreeD = new TTree(hname,"Digits");
1267 fTreeD->Write(0,TObject::kOverwrite);
1269 if (oS && !fTreeS) {
1270 sprintf(hname,"TreeS%d",fEvent);
1271 fTreeS = new TTree(hname,"SDigits");
1272 fTreeS->Write(0,TObject::kOverwrite);
1274 if (oR && !fTreeR) {
1275 sprintf(hname,"TreeR%d",fEvent);
1276 fTreeR = new TTree(hname,"Reconstruction");
1277 fTreeR->Write(0,TObject::kOverwrite);
1281 // Create a branch for hits/digits for each detector
1282 // Each branch is a TClonesArray. Each data member of the Hits classes
1283 // will be in turn a subbranch of the detector master branch
1284 TIter next(fModules);
1285 AliModule *detector;
1286 while((detector = (AliModule*)next())) {
1287 if (oH) detector->MakeBranch(option,file);
1291 //_____________________________________________________________________________
1292 TParticle* AliRun::Particle(Int_t i)
1294 return fStack->Particle(i);
1297 //_____________________________________________________________________________
1298 void AliRun::BeginEvent()
1300 // Clean-up previous event
1302 fEventEnergy.Reset();
1303 // Clean detector information
1310 // Reset all Detectors & kinematics & trees
1314 // Initialise event header
1315 fHeader->Reset(fRun,fEvent);
1317 fStack->BeginEvent(fEvent);
1321 fLego->BeginEvent();
1334 sprintf(hname,"TreeH%d",fEvent);
1335 fTreeH->SetName(hname);
1339 sprintf(hname,"TreeD%d",fEvent);
1340 fTreeD->SetName(hname);
1341 fTreeD->Write(0,TObject::kOverwrite);
1345 sprintf(hname,"TreeS%d",fEvent);
1346 fTreeS->SetName(hname);
1347 fTreeS->Write(0,TObject::kOverwrite);
1351 sprintf(hname,"TreeR%d",fEvent);
1352 fTreeR->SetName(hname);
1353 fTreeR->Write(0,TObject::kOverwrite);
1356 //_____________________________________________________________________________
1357 void AliRun::ResetDigits()
1360 // Reset all Detectors digits
1362 TIter next(fModules);
1363 AliModule *detector;
1364 while((detector = (AliModule*)next())) {
1365 detector->ResetDigits();
1369 //_____________________________________________________________________________
1370 void AliRun::ResetSDigits()
1373 // Reset all Detectors digits
1375 TIter next(fModules);
1376 AliModule *detector;
1377 while((detector = (AliModule*)next())) {
1378 detector->ResetSDigits();
1382 //_____________________________________________________________________________
1383 void AliRun::ResetHits()
1386 // Reset all Detectors hits
1388 TIter next(fModules);
1389 AliModule *detector;
1390 while((detector = (AliModule*)next())) {
1391 detector->ResetHits();
1395 //_____________________________________________________________________________
1396 void AliRun::ResetPoints()
1399 // Reset all Detectors points
1401 TIter next(fModules);
1402 AliModule *detector;
1403 while((detector = (AliModule*)next())) {
1404 detector->ResetPoints();
1408 //_____________________________________________________________________________
1409 void AliRun::RunMC(Int_t nevent, const char *setup)
1412 // Main function to be called to process a galice run
1414 // Root > gAlice.Run();
1415 // a positive number of events will cause the finish routine
1419 // check if initialisation has been done
1420 if (!fInitDone) InitMC(setup);
1422 // Create the Root Tree with one branch per detector
1426 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1427 MakeTree("K","Kine.root");
1428 MakeTree("H","Hits.root");
1433 gMC->ProcessRun(nevent);
1435 // End of this run, close files
1436 if(nevent>0) FinishRun();
1439 //_____________________________________________________________________________
1440 void AliRun::RunReco(const char *selected, Int_t first, Int_t last)
1443 // Main function to be called to reconstruct Alice event
1445 cout << "Found "<< gAlice->TreeE()->GetEntries() << "events" << endl;
1446 Int_t nFirst = first;
1447 Int_t nLast = (last < 0)? (Int_t) gAlice->TreeE()->GetEntries() : last;
1449 for (Int_t nevent = nFirst; nevent <= nLast; nevent++) {
1450 cout << "Processing event "<< nevent << endl;
1453 Digits2Reco(selected);
1457 //_____________________________________________________________________________
1459 void AliRun::Hits2Digits(const char *selected)
1462 // Convert Hits to sumable digits
1464 for (Int_t nevent=0; nevent<gAlice->TreeE()->GetEntries(); nevent++) {
1467 Hits2SDigits(selected);
1468 SDigits2Digits(selected);
1473 //_____________________________________________________________________________
1475 void AliRun::Tree2Tree(Option_t *option, const char *selected)
1478 // Function to transform the content of
1480 // - TreeH to TreeS (option "S")
1481 // - TreeS to TreeD (option "D")
1482 // - TreeD to TreeR (option "R")
1484 // If multiple options are specified ("SDR"), transformation will be done in sequence for
1485 // selected detector and for all detectors if none is selected (detector string
1486 // can contain blank separated list of detector names).
1489 const char *oS = strstr(option,"S");
1490 const char *oD = strstr(option,"D");
1491 const char *oR = strstr(option,"R");
1493 TObjArray *detectors = Detectors();
1495 TIter next(detectors);
1497 AliDetector *detector = 0;
1499 TDirectory *cwd = gDirectory;
1503 while((detector = (AliDetector*)next())) {
1505 if (strcmp(detector->GetName(),selected)) continue;
1506 if (detector->IsActive()){
1507 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1509 sprintf(outFile,"SDigits.%s.root",detector->GetName());
1510 detector->MakeBranch("S",outFile);
1513 sprintf(outFile,"Digits.%s.root",detector->GetName());
1514 detector->MakeBranch("D",outFile);
1517 sprintf(outFile,"Reco.%s.root",detector->GetName());
1518 detector->MakeBranch("R",outFile);
1521 detector->MakeBranch(option);
1527 cout << "Hits2SDigits: Processing " << detector->GetName() << "..." << endl;
1528 detector->Hits2SDigits();
1531 cout << "SDigits2Digits: Processing " << detector->GetName() << "..." << endl;
1532 detector->SDigits2Digits();
1535 cout << "Digits2Reco: Processing " << detector->GetName() << "..." << endl;
1536 detector->Digits2Reco();
1545 //_____________________________________________________________________________
1546 void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min,
1547 Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max,
1548 Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener)
1551 // Generates lego plots of:
1552 // - radiation length map phi vs theta
1553 // - radiation length map phi vs eta
1554 // - interaction length map
1555 // - g/cm2 length map
1557 // ntheta bins in theta, eta
1558 // themin minimum angle in theta (degrees)
1559 // themax maximum angle in theta (degrees)
1561 // phimin minimum angle in phi (degrees)
1562 // phimax maximum angle in phi (degrees)
1563 // rmin minimum radius
1564 // rmax maximum radius
1567 // The number of events generated = ntheta*nphi
1568 // run input parameters in macro setup (default="Config.C")
1570 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1573 <img src="picts/AliRunLego1.gif">
1578 <img src="picts/AliRunLego2.gif">
1583 <img src="picts/AliRunLego3.gif">
1588 // check if initialisation has been done
1589 if (!fInitDone) InitMC(setup);
1590 //Save current generator
1591 AliGenerator *gen=Generator();
1593 // Set new generator
1594 if (!gener) gener = new AliLegoGenerator();
1595 ResetGenerator(gener);
1597 // Configure Generator
1598 gener->SetRadiusRange(rmin, rmax);
1599 gener->SetZMax(zmax);
1600 gener->SetCoor1Range(nc1, c1min, c1max);
1601 gener->SetCoor2Range(nc2, c2min, c2max);
1604 //Create Lego object
1605 fLego = new AliLego("lego",gener);
1607 //Prepare MC for Lego Run
1612 gMC->ProcessRun(nc1*nc2+1);
1614 // Create only the Root event Tree
1617 // End of this run, close files
1619 // Restore current generator
1620 ResetGenerator(gen);
1621 // Delete Lego Object
1622 delete fLego; fLego=0;
1625 //_____________________________________________________________________________
1626 void AliRun::SetConfigFunction(const char * config)
1629 // Set the signature of the function contained in Config.C to configure
1632 fConfigFunction=config;
1635 //_____________________________________________________________________________
1636 void AliRun::SetCurrentTrack(Int_t track)
1639 // Set current track number
1641 fStack->SetCurrentTrack(track);
1644 //_____________________________________________________________________________
1645 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1646 Float_t *vpos, Float_t *polar, Float_t tof,
1647 AliMCProcess mech, Int_t &ntr, Float_t weight)
1649 // Delegate to stack
1651 fStack->SetTrack(done, parent, pdg, pmom, vpos, polar, tof,
1655 //_____________________________________________________________________________
1656 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg,
1657 Double_t px, Double_t py, Double_t pz, Double_t e,
1658 Double_t vx, Double_t vy, Double_t vz, Double_t tof,
1659 Double_t polx, Double_t poly, Double_t polz,
1660 AliMCProcess mech, Int_t &ntr, Float_t weight)
1662 // Delegate to stack
1664 fStack->SetTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
1665 polx, poly, polz, mech, ntr, weight);
1669 //_____________________________________________________________________________
1670 void AliRun::SetHighWaterMark(const Int_t nt)
1673 // Set high water mark for last track in event
1674 fStack->SetHighWaterMark(nt);
1677 //_____________________________________________________________________________
1678 void AliRun::KeepTrack(const Int_t track)
1681 // Delegate to stack
1683 fStack->KeepTrack(track);
1686 //_____________________________________________________________________________
1687 void AliRun::StepManager(Int_t id)
1690 // Called at every step during transport
1694 // --- If lego option, do it and leave
1696 fLego->StepManager();
1699 //Update energy deposition tables
1700 AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
1702 //Call the appropriate stepping routine;
1703 AliModule *det = (AliModule*)fModules->At(id);
1705 fMCQA->StepManager(id);
1711 //_____________________________________________________________________________
1712 void AliRun::Streamer(TBuffer &R__b)
1714 // Stream an object of class AliRun.
1716 if (R__b.IsReading()) {
1717 if (!gAlice) gAlice = this;
1719 AliRun::Class()->ReadBuffer(R__b, this);
1721 gROOT->GetListOfBrowsables()->Add(this,"Run");
1723 fTreeE = (TTree*)gDirectory->Get("TE");
1725 fTreeE->SetBranchAddress("Header", &fHeader);
1728 else Error("Streamer","cannot find Header Tree\n");
1729 fTreeE->GetEntry(0);
1733 AliRun::Class()->WriteBuffer(R__b, this);
1738 //___________________________________________________________________________
1739 Int_t AliRun::CurrentTrack() const {
1741 // Returns current track
1743 return fStack->CurrentTrack();
1746 //___________________________________________________________________________
1747 Int_t AliRun::GetNtrack() const {
1749 // Returns number of tracks in stack
1751 return fStack->GetNtrack();
1754 //___________________________________________________________________________
1755 TObjArray* AliRun::Particles() {
1757 // Returns pointer to Particles array
1759 return fStack->Particles();
1762 //___________________________________________________________________________
1763 TTree* AliRun::TreeK() {
1765 // Returns pointer to the TreeK array
1767 return fStack->TreeK();
1771 void AliRun::SetGenEventHeader(AliGenEventHeader* header)
1773 fHeader->SetGenEventHeader(header);