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.62 2001/04/06 11:12:33 morsch
19 Clear fParticles after each event. (Ivana Hrivnacova)
21 Revision 1.61 2001/03/30 07:04:10 morsch
22 Call fGenerator->FinishRun() for final print-outs, cross-section and weight calculations.
24 Revision 1.60 2001/03/21 18:22:30 hristov
25 fParticleFileMap fix (I.Hrivnacova)
27 Revision 1.59 2001/03/12 17:47:03 hristov
28 Changes needed on Sun with CC 5.0
30 Revision 1.58 2001/03/09 14:27:26 morsch
31 Fix for multiple events per file: inhibit decrease of size of fParticleFileMap.
33 Revision 1.57 2001/02/23 17:40:23 buncic
34 All trees needed for simulation created in RunMC(). TreeR and its branches
35 are now created in new RunReco() method.
37 Revision 1.56 2001/02/14 15:45:20 hristov
38 Algorithmic way of getting entry index in fParticleMap. Protection of fParticleFileMap (I.Hrivnacova)
40 Revision 1.55 2001/02/12 15:52:54 buncic
41 Removed OpenBaseFile().
43 Revision 1.54 2001/02/07 10:39:05 hristov
44 Remove default value for argument
46 Revision 1.53 2001/02/06 11:02:26 hristov
47 New SetTrack interface added, added check for unfilled particles in FinishEvent (I.Hrivnacova)
49 Revision 1.52 2001/02/05 16:22:25 buncic
50 Added TreeS to GetEvent().
52 Revision 1.51 2001/02/02 15:16:20 morsch
53 SetHighWaterMark method added to mark last particle in event.
55 Revision 1.50 2001/01/27 10:32:00 hristov
56 Leave the loop when primaries are filled (I.Hrivnacova)
58 Revision 1.49 2001/01/26 19:58:48 hristov
59 Major upgrade of AliRoot code
61 Revision 1.48 2001/01/17 10:50:50 hristov
62 Corrections to destructors
64 Revision 1.47 2000/12/18 10:44:01 morsch
65 Possibility to set field map by passing pointer to objet of type AliMagF via
68 gAlice->SetField(new AliMagFCM("Map2", "$(ALICE_ROOT)/data/field01.dat",2,1.,10.));
70 Revision 1.46 2000/12/14 19:29:27 fca
71 galice.cuts was not read any more
73 Revision 1.45 2000/11/30 07:12:49 alibrary
74 Introducing new Rndm and QA classes
76 Revision 1.44 2000/10/26 13:58:59 morsch
77 Add possibility to choose the lego generator (of type AliGeneratorLego or derived) when running
78 RunLego(). Default is the base class AliGeneratorLego.
80 Revision 1.43 2000/10/09 09:43:17 fca
81 Special remapping of hits for TPC and TRD. End-of-primary action introduced
83 Revision 1.42 2000/10/02 21:28:14 fca
84 Removal of useless dependecies via forward declarations
86 Revision 1.41 2000/07/13 16:19:09 fca
87 Mainly coding conventions + some small bug fixes
89 Revision 1.40 2000/07/12 08:56:25 fca
90 Coding convention correction and warning removal
92 Revision 1.39 2000/07/11 18:24:59 fca
93 Coding convention corrections + few minor bug fixes
95 Revision 1.38 2000/06/20 13:05:45 fca
96 Writing down the TREE headers before job starts
98 Revision 1.37 2000/06/09 20:05:11 morsch
99 Introduce possibility to chose magnetic field version 3: AliMagFDM + field02.dat
101 Revision 1.36 2000/06/08 14:03:58 hristov
102 Only one initializer for a default argument
104 Revision 1.35 2000/06/07 10:13:14 hristov
105 Delete only existent objects.
107 Revision 1.34 2000/05/18 10:45:38 fca
108 Delete Particle Factory properly
110 Revision 1.33 2000/05/16 13:10:40 fca
111 New method IsNewTrack and fix for a problem in Father-Daughter relations
113 Revision 1.32 2000/04/27 10:38:21 fca
114 Correct termination of Lego Run and introduce Lego getter in AliRun
116 Revision 1.31 2000/04/26 10:17:32 fca
117 Changes in Lego for G4 compatibility
119 Revision 1.30 2000/04/18 19:11:40 fca
120 Introduce variable Config.C function signature
122 Revision 1.29 2000/04/07 11:12:34 fca
123 G4 compatibility changes
125 Revision 1.28 2000/04/05 06:51:06 fca
126 Workaround for an HP compiler problem
128 Revision 1.27 2000/03/22 18:08:07 fca
129 Rationalisation of the virtual MC interfaces
131 Revision 1.26 2000/03/22 13:42:26 fca
132 SetGenerator does not replace an existing generator, ResetGenerator does
134 Revision 1.25 2000/02/23 16:25:22 fca
135 AliVMC and AliGeant3 classes introduced
136 ReadEuclid moved from AliRun to AliModule
138 Revision 1.24 2000/01/19 17:17:20 fca
139 Introducing a list of lists of hits -- more hits allowed for detector now
141 Revision 1.23 1999/12/03 11:14:31 fca
142 Fixing previous wrong checking
144 Revision 1.21 1999/11/25 10:40:08 fca
145 Fixing daughters information also in primary tracks
147 Revision 1.20 1999/10/04 18:08:49 fca
148 Adding protection against inconsistent Euclid files
150 Revision 1.19 1999/09/29 07:50:40 fca
151 Introduction of the Copyright and cvs Log
155 ///////////////////////////////////////////////////////////////////////////////
157 // Control class for Alice C++ //
158 // Only one single instance of this class exists. //
159 // The object is created in main program aliroot //
160 // and is pointed by the global gAlice. //
162 // -Supports the list of all Alice Detectors (fModules). //
163 // -Supports the list of particles (fParticles). //
164 // -Supports the Trees. //
165 // -Supports the geometry. //
166 // -Supports the event display. //
169 <img src="picts/AliRunClass.gif">
174 <img src="picts/alirun.gif">
178 ///////////////////////////////////////////////////////////////////////////////
183 #include <iostream.h>
191 #include <TObjectTable.h>
193 #include <TGeometry.h>
195 #include "TBrowser.h"
197 #include "TParticle.h"
199 #include "AliDisplay.h"
202 #include "AliMagFC.h"
203 #include "AliMagFCM.h"
204 #include "AliMagFDM.h"
206 #include "TRandom3.h"
208 #include "AliGenerator.h"
209 #include "AliLegoGenerator.h"
211 #include "AliDetector.h"
215 static AliHeader *gAliHeader;
219 //_____________________________________________________________________________
221 : fParticleFileMap(fHeader.GetParticleFileMap())
224 // Default constructor for AliRun
249 fPDGDB = 0; //Particle factory object!
251 fConfigFunction = "\0";
254 fTransParName = "\0";
255 fBaseFileName = ".\0";
257 fParticleMap = new TObjArray(10000);
260 //_____________________________________________________________________________
261 AliRun::AliRun(const char *name, const char *title)
262 : TNamed(name,title),
263 fParticleFileMap(fHeader.GetParticleFileMap())
267 // Constructor for the main processor.
268 // Creates the geometry
269 // Creates the list of Detectors.
270 // Creates the list of particles.
287 fConfigFunction = "Config();";
289 // Set random number generator
290 gRandom = fRandom = new TRandom3();
292 if (gSystem->Getenv("CONFIG_SEED")) {
293 gRandom->SetSeed((UInt_t)atoi(gSystem->Getenv("CONFIG_SEED")));
296 gROOT->GetListOfBrowsables()->Add(this,name);
298 // create the support list for the various Detectors
299 fModules = new TObjArray(77);
301 // Create the TNode geometry for the event display
303 BuildSimpleGeometry();
313 // Create the particle stack
314 fParticles = new TClonesArray("TParticle",1000);
318 // Create default mag field
323 // Prepare the tracking medium lists
324 fImedia = new TArrayI(1000);
325 for(i=0;i<1000;i++) (*fImedia)[i]=-99;
328 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
330 // Create HitLists list
331 fHitLists = new TList();
334 fBaseFileName = ".\0";
336 fParticleMap = new TObjArray(10000);
340 //_____________________________________________________________________________
344 // Default AliRun destructor
364 fParticles->Delete();
372 //_____________________________________________________________________________
373 void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
376 // Add a hit to detector id
378 TObjArray &dets = *fModules;
379 if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits);
382 //_____________________________________________________________________________
383 void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
386 // Add digit to detector id
388 TObjArray &dets = *fModules;
389 if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits);
392 //_____________________________________________________________________________
393 void AliRun::Browse(TBrowser *b)
396 // Called when the item "Run" is clicked on the left pane
397 // of the Root browser.
398 // It displays the Root Trees and all detectors.
400 if (fTreeK) b->Add(fTreeK,fTreeK->GetName());
401 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
402 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
403 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
404 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
405 if (fTreeS) b->Add(fTreeS,fTreeS->GetName());
407 TIter next(fModules);
409 while((detector = (AliModule*)next())) {
410 b->Add(detector,detector->GetName());
412 b->Add(fMCQA,"AliMCQA");
415 //_____________________________________________________________________________
419 // Initialize Alice geometry
424 //_____________________________________________________________________________
425 void AliRun::BuildSimpleGeometry()
428 // Create a simple TNode geometry used by Root display engine
430 // Initialise geometry
432 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
433 new TMaterial("void","Vacuum",0,0,0); //Everything is void
434 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
435 brik->SetVisibility(0);
436 new TNode("alice","alice","S_alice");
439 //_____________________________________________________________________________
440 void AliRun::CleanDetectors()
443 // Clean Detectors at the end of event
445 TIter next(fModules);
447 while((detector = (AliModule*)next())) {
448 detector->FinishEvent();
452 //_____________________________________________________________________________
453 void AliRun::CleanParents()
456 // Clean Particles stack.
457 // Set parent/daughter relations
459 TObjArray &particles = *fParticleMap;
462 for(i=0; i<fHgwmk+1; i++) {
463 part = (TParticle *)particles.At(i);
464 if(part) if(!part->TestBit(kDaughtersBit)) {
465 part->SetFirstDaughter(-1);
466 part->SetLastDaughter(-1);
471 //_____________________________________________________________________________
472 Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
475 // Return the distance from the mouse to the AliRun object
481 //_____________________________________________________________________________
482 void AliRun::DumpPart (Int_t i) const
485 // Dumps particle i in the stack
487 ((TParticle*) (*fParticleMap)[i])->Print();
490 //_____________________________________________________________________________
491 void AliRun::DumpPStack () const
494 // Dumps the particle stack
496 TObjArray &particles = *fParticleMap;
498 "\n\n=======================================================================\n");
499 for (Int_t i=0;i<fNtrack;i++)
501 printf("-> %d ",i); ((TParticle*) particles[i])->Print();
502 printf("--------------------------------------------------------------\n");
505 "\n=======================================================================\n\n");
508 void AliRun::SetField(AliMagF* magField)
510 // Set Magnetic Field Map
515 //_____________________________________________________________________________
516 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
517 Float_t maxField, char* filename)
520 // Set magnetic field parameters
521 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
522 // version Magnetic field map version (only 1 active now)
523 // scale Scale factor for the magnetic field
524 // maxField Maximum value for the magnetic field
527 // --- Sanity check on mag field flags
528 if(fField) delete fField;
530 fField = new AliMagFC("Map1"," ",type,scale,maxField);
531 } else if(version<=2) {
532 fField = new AliMagFCM("Map2-3",filename,type,scale,maxField);
534 } else if(version==3) {
535 fField = new AliMagFDM("Map4",filename,type,scale,maxField);
538 Warning("SetField","Invalid map %d\n",version);
542 //_____________________________________________________________________________
543 void AliRun::PreTrack()
545 TObjArray &dets = *fModules;
548 for(Int_t i=0; i<=fNdets; i++)
549 if((module = (AliModule*)dets[i]))
555 //_____________________________________________________________________________
556 void AliRun::PostTrack()
558 TObjArray &dets = *fModules;
561 for(Int_t i=0; i<=fNdets; i++)
562 if((module = (AliModule*)dets[i]))
566 //_____________________________________________________________________________
567 void AliRun::FinishPrimary()
570 // Called at the end of each primary track
573 // static Int_t count=0;
574 // const Int_t times=10;
575 // This primary is finished, purify stack
578 TIter next(fModules);
580 while((detector = (AliModule*)next())) {
581 detector->FinishPrimary();
584 // Write out hits if any
585 if (gAlice->TreeH()) {
586 gAlice->TreeH()->Fill();
593 // if(++count%times==1) gObjectTable->Print();
596 //_____________________________________________________________________________
597 void AliRun::FinishEvent()
600 // Called at the end of the event.
604 if(fLego) fLego->FinishEvent();
606 //Update the energy deposit tables
608 for(i=0;i<fEventEnergy.GetSize();i++) {
609 fSummEnergy[i]+=fEventEnergy[i];
610 fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
612 fEventEnergy.Reset();
614 // Clean detector information
617 // Write out the kinematics
620 if(fTreeK->GetEntries() ==0) {
621 // set the fParticleFileMap size for the first time
622 if (fHgwmk+1 > fParticleFileMap.GetSize())
623 fParticleFileMap.Set(fHgwmk+1);
626 Bool_t allFilled = kFALSE;
628 for(i=0; i<fHgwmk+1; ++i) if((part=fParticleMap->At(i))) {
629 fParticleBuffer = (TParticle*) part;
630 fParticleFileMap[i]= (Int_t) fTreeK->GetEntries();
632 (*fParticleMap)[i]=0;
634 // When all primaries were filled no particle!=0
635 // should be left => to be removed later.
636 if (allFilled) printf("Why != 0 part # %d?\n",i);
639 // // printf("Why = 0 part # %d?\n",i); => We know.
641 // we don't break now in order to be sure there is no
642 // particle !=0 left.
643 // To be removed later and replaced with break.
644 if(!allFilled) allFilled = kTRUE;
648 // Set number of tracks to event header
649 fHeader.SetNtrack(fNtrack);
651 // Write out the digits
662 // Write out reconstructed clusters
667 // Write out the event Header information
668 if (fTreeE) fTreeE->Fill();
673 // Write Tree headers
674 if (fTreeK) fTreeK->Write(0,TObject::kOverwrite);
675 if (fTreeH) fTreeH->Write(0,TObject::kOverwrite);
676 if (fTreeD) fTreeD->Write(0,TObject::kOverwrite);
677 if (fTreeR) fTreeR->Write(0,TObject::kOverwrite);
678 if (fTreeS) fTreeS->Write(0,TObject::kOverwrite);
683 //_____________________________________________________________________________
684 void AliRun::FinishRun()
687 // Called at the end of the run.
691 if(fLego) fLego->FinishRun();
693 if(fGenerator) fGenerator->FinishRun();
695 // Clean detector information
696 TIter next(fModules);
698 while((detector = (AliModule*)next())) {
699 detector->FinishRun();
702 //Output energy summary tables
705 TFile *file = fTreeE->GetCurrentFile();
709 fTreeE->Write(0,TObject::kOverwrite);
711 // Write AliRun info and all detectors parameters
712 Write(0,TObject::kOverwrite);
714 // Clean tree information
716 delete fTreeK; fTreeK = 0;
719 delete fTreeH; fTreeH = 0;
722 delete fTreeD; fTreeD = 0;
725 delete fTreeR; fTreeR = 0;
728 delete fTreeE; fTreeE = 0;
735 //_____________________________________________________________________________
736 void AliRun::FlagTrack(Int_t track)
739 // Flags a track and all its family tree to be kept
746 particle=(TParticle*)fParticleMap->At(curr);
748 // If the particle is flagged the three from here upward is saved already
749 if(particle->TestBit(kKeepBit)) return;
751 // Save this particle
752 particle->SetBit(kKeepBit);
754 // Move to father if any
755 if((curr=particle->GetFirstMother())==-1) return;
759 //_____________________________________________________________________________
760 void AliRun::EnergySummary()
763 // Print summary of deposited energy
769 Int_t kn, i, left, j, id;
770 const Float_t kzero=0;
771 Int_t ievent=fHeader.GetEvent()+1;
773 // Energy loss information
775 printf("***************** Energy Loss Information per event (GEV) *****************\n");
776 for(kn=1;kn<fEventEnergy.GetSize();kn++) {
779 fEventEnergy[ndep]=kn;
784 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,kzero))/ed;
787 fSummEnergy[ndep]=ed;
788 fSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,kzero));
793 for(kn=0;kn<(ndep-1)/3+1;kn++) {
795 for(i=0;i<(3<left?3:left);i++) {
797 id=Int_t (fEventEnergy[j]+0.1);
798 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]);
803 // Relative energy loss in different detectors
804 printf("******************** Relative Energy Loss per event ********************\n");
805 printf("Total energy loss per event %10.3f GeV\n",edtot);
806 for(kn=0;kn<(ndep-1)/5+1;kn++) {
808 for(i=0;i<(5<left?5:left);i++) {
810 id=Int_t (fEventEnergy[j]+0.1);
811 printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot);
815 for(kn=0;kn<75;kn++) printf("*");
819 // Reset the TArray's
820 // fEventEnergy.Set(0);
821 // fSummEnergy.Set(0);
822 // fSum2Energy.Set(0);
825 //_____________________________________________________________________________
826 AliModule *AliRun::GetModule(const char *name) const
829 // Return pointer to detector from name
831 return (AliModule*)fModules->FindObject(name);
834 //_____________________________________________________________________________
835 AliDetector *AliRun::GetDetector(const char *name) const
838 // Return pointer to detector from name
840 return (AliDetector*)fModules->FindObject(name);
843 //_____________________________________________________________________________
844 Int_t AliRun::GetModuleID(const char *name) const
847 // Return galice internal detector identifier from name
850 TObject *mod=fModules->FindObject(name);
851 if(mod) i=fModules->IndexOf(mod);
855 //_____________________________________________________________________________
856 Int_t AliRun::GetEvent(Int_t event)
859 // Connect the Trees Kinematics and Hits for event # event
860 // Set branch addresses
863 // Reset existing structures
869 // Delete Trees already connected
870 if (fTreeK) delete fTreeK;
871 if (fTreeH) delete fTreeH;
872 if (fTreeD) delete fTreeD;
873 if (fTreeR) delete fTreeR;
874 if (fTreeS) delete fTreeS;
876 // Get header from file
877 if(fTreeE) fTreeE->GetEntry(event);
878 else Error("GetEvent","Cannot file Header Tree\n");
879 TFile *file = fTreeE->GetCurrentFile();
883 // Get Kine Tree from file
885 sprintf(treeName,"TreeK%d",event);
886 fTreeK = (TTree*)gDirectory->Get(treeName);
887 if (fTreeK) fTreeK->SetBranchAddress("Particles", &fParticleBuffer);
888 else Error("GetEvent","cannot find Kine Tree for event:%d\n",event);
889 // Create the particle stack
894 fParticles = new TClonesArray("TParticle",1000);
896 // Build the pointer list
898 fParticleMap->Clear();
899 fParticleMap->Expand(fTreeK->GetEntries());
901 fParticleMap = new TObjArray(fTreeK->GetEntries());
905 // Get Hits Tree header from file
906 sprintf(treeName,"TreeH%d",event);
907 fTreeH = (TTree*)gDirectory->Get(treeName);
909 Error("GetEvent","cannot find Hits Tree for event:%d\n",event);
914 // Get Digits Tree header from file
915 sprintf(treeName,"TreeD%d",event);
916 fTreeD = (TTree*)gDirectory->Get(treeName);
918 // Warning("GetEvent","cannot find Digits Tree for event:%d\n",event);
923 // Get SDigits Tree header from file
924 sprintf(treeName,"TreeS%d",event);
925 fTreeS = (TTree*)gDirectory->Get(treeName);
927 // Warning("GetEvent","cannot find SDigits Tree for event:%d\n",event);
932 // Get Reconstruct Tree header from file
933 sprintf(treeName,"TreeR%d",event);
934 fTreeR = (TTree*)gDirectory->Get(treeName);
936 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
941 // Set Trees branch addresses
942 TIter next(fModules);
944 while((detector = (AliModule*)next())) {
945 detector->SetTreeAddress();
948 fNtrack = Int_t (fTreeK->GetEntries());
952 //_____________________________________________________________________________
953 TGeometry *AliRun::GetGeometry()
956 // Import Alice geometry from current file
957 // Return pointer to geometry object
959 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
961 // Unlink and relink nodes in detectors
962 // This is bad and there must be a better way...
965 TIter next(fModules);
967 while((detector = (AliModule*)next())) {
968 TList *dnodes=detector->Nodes();
971 for ( j=0; j<dnodes->GetSize(); j++) {
972 node = (TNode*) dnodes->At(j);
973 node1 = fGeometry->GetNode(node->GetName());
974 dnodes->Remove(node);
975 dnodes->AddAt(node1,j);
981 //_____________________________________________________________________________
982 void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
983 Float_t &e, Float_t *vpos, Float_t *polar,
987 // Return next track from stack of particles
992 for(Int_t i=fNtrack-1; i>=0; i--) {
993 track=(TParticle*) fParticleMap->At(i);
994 if(track) if(!track->TestBit(kDoneBit)) {
996 // The track exists and has not yet been processed
998 ipart=track->GetPdgCode();
1000 pmom[1]=track->Py();
1001 pmom[2]=track->Pz();
1003 vpos[0]=track->Vx();
1004 vpos[1]=track->Vy();
1005 vpos[2]=track->Vz();
1006 track->GetPolarisation(pol);
1011 track->SetBit(kDoneBit);
1017 // stop and start timer when we start a primary track
1018 Int_t nprimaries = fHeader.GetNprimary();
1019 if (fCurrent >= nprimaries) return;
1020 if (fCurrent < nprimaries-1) {
1022 track=(TParticle*) fParticleMap->At(fCurrent+1);
1023 // track->SetProcessTime(fTimer.CpuTime());
1028 //_____________________________________________________________________________
1029 Int_t AliRun::GetPrimary(Int_t track)
1032 // return number of primary that has generated track
1034 int current, parent;
1040 part = (TParticle *)fParticleMap->At(current);
1041 if(!part) part = Particle(current);
1042 parent=part->GetFirstMother();
1043 if(parent<0) return current;
1047 //_____________________________________________________________________________
1048 void AliRun::InitMC(const char *setup)
1051 // Initialize the Alice setup
1055 Warning("Init","Cannot initialise AliRun twice!\n");
1059 gROOT->LoadMacro(setup);
1060 gInterpreter->ProcessLine(fConfigFunction.Data());
1063 gMC->DefineParticles(); //Create standard MC particles
1065 TObject *objfirst, *objlast;
1067 fNdets = fModules->GetLast()+1;
1070 //=================Create Materials and geometry
1073 // Added also after in case of interactive initialisation of modules
1074 fNdets = fModules->GetLast()+1;
1076 TIter next(fModules);
1077 AliModule *detector;
1078 while((detector = (AliModule*)next())) {
1079 detector->SetTreeAddress();
1080 objlast = gDirectory->GetList()->Last();
1082 // Add Detector histograms in Detector list of histograms
1083 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
1084 else objfirst = gDirectory->GetList()->First();
1086 detector->Histograms()->Add(objfirst);
1087 objfirst = gDirectory->GetList()->After(objfirst);
1090 ReadTransPar(); //Read the cuts for all materials
1092 MediaTable(); //Build the special IMEDIA table
1094 //Initialise geometry deposition table
1095 fEventEnergy.Set(gMC->NofVolumes()+1);
1096 fSummEnergy.Set(gMC->NofVolumes()+1);
1097 fSum2Energy.Set(gMC->NofVolumes()+1);
1099 //Compute cross-sections
1100 gMC->BuildPhysics();
1102 //Write Geometry object to current file.
1107 fMCQA = new AliMCQA(fNdets);
1110 // Save stuff at the beginning of the file to avoid file corruption
1114 //_____________________________________________________________________________
1115 void AliRun::MediaTable()
1118 // Built media table to get from the media number to
1121 Int_t kz, nz, idt, lz, i, k, ind;
1123 TObjArray &dets = *gAlice->Detectors();
1126 // For all detectors
1127 for (kz=0;kz<fNdets;kz++) {
1128 // If detector is defined
1129 if((det=(AliModule*) dets[kz])) {
1130 TArrayI &idtmed = *(det->GetIdtmed());
1131 for(nz=0;nz<100;nz++) {
1132 // Find max and min material number
1133 if((idt=idtmed[nz])) {
1134 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
1135 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
1138 if(det->LoMedium() > det->HiMedium()) {
1139 det->LoMedium() = 0;
1140 det->HiMedium() = 0;
1142 if(det->HiMedium() > fImedia->GetSize()) {
1143 Error("MediaTable","Increase fImedia from %d to %d",
1144 fImedia->GetSize(),det->HiMedium());
1147 // Tag all materials in rage as belonging to detector kz
1148 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
1155 // Print summary table
1156 printf(" Traking media ranges:\n");
1157 for(i=0;i<(fNdets-1)/6+1;i++) {
1158 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
1160 det=(AliModule*)dets[ind];
1162 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
1165 printf(" %6s: %3d -> %3d;","NULL",0,0);
1171 //____________________________________________________________________________
1172 void AliRun::SetGenerator(AliGenerator *generator)
1175 // Load the event generator
1177 if(!fGenerator) fGenerator = generator;
1180 //____________________________________________________________________________
1181 void AliRun::ResetGenerator(AliGenerator *generator)
1184 // Load the event generator
1188 Warning("ResetGenerator","Replacing generator %s with %s\n",
1189 fGenerator->GetName(),generator->GetName());
1191 Warning("ResetGenerator","Replacing generator %s with NULL\n",
1192 fGenerator->GetName());
1193 fGenerator = generator;
1196 //____________________________________________________________________________
1197 void AliRun::SetTransPar(char *filename)
1199 fTransParName = filename;
1202 //____________________________________________________________________________
1203 void AliRun::SetBaseFile(char *filename)
1205 fBaseFileName = filename;
1208 //____________________________________________________________________________
1209 void AliRun::ReadTransPar()
1212 // Read filename to set the transport parameters
1216 const Int_t kncuts=10;
1217 const Int_t knflags=11;
1218 const Int_t knpars=kncuts+knflags;
1219 const char kpars[knpars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
1220 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
1221 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
1222 "MULS","PAIR","PHOT","RAYL"};
1226 Float_t cut[kncuts];
1227 Int_t flag[knflags];
1228 Int_t i, itmed, iret, ktmed, kz;
1231 // See whether the file is there
1232 filtmp=gSystem->ExpandPathName(fTransParName.Data());
1233 lun=fopen(filtmp,"r");
1236 Warning("ReadTransPar","File %s does not exist!\n",fTransParName.Data());
1240 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1241 printf(" *%59s\n","*");
1242 printf(" * Please check carefully what you are doing!%10s\n","*");
1243 printf(" *%59s\n","*");
1246 // Initialise cuts and flags
1247 for(i=0;i<kncuts;i++) cut[i]=-99;
1248 for(i=0;i<knflags;i++) flag[i]=-99;
1250 for(i=0;i<256;i++) line[i]='\0';
1251 // Read up to the end of line excluded
1252 iret=fscanf(lun,"%[^\n]",line);
1256 printf(" *%59s\n","*");
1257 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1260 // Read the end of line
1263 if(line[0]=='*') continue;
1265 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",
1266 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
1267 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
1268 &flag[8],&flag[9],&flag[10]);
1272 Warning("ReadTransPar","Error reading file %s\n",fTransParName.Data());
1275 // Check that the module exist
1276 AliModule *mod = GetModule(detName);
1278 // Get the array of media numbers
1279 TArrayI &idtmed = *mod->GetIdtmed();
1280 // Check that the tracking medium code is valid
1281 if(0<=itmed && itmed < 100) {
1282 ktmed=idtmed[itmed];
1284 Warning("ReadTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
1287 // Set energy thresholds
1288 for(kz=0;kz<kncuts;kz++) {
1290 printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
1291 kpars[kz],cut[kz],itmed,mod->GetName());
1292 gMC->Gstpar(ktmed,kpars[kz],cut[kz]);
1295 // Set transport mechanisms
1296 for(kz=0;kz<knflags;kz++) {
1298 printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
1299 kpars[kncuts+kz],flag[kz],itmed,mod->GetName());
1300 gMC->Gstpar(ktmed,kpars[kncuts+kz],Float_t(flag[kz]));
1304 Warning("ReadTransPar","Invalid medium code %d *\n",itmed);
1308 Warning("ReadTransPar","Module %s not present\n",detName);
1314 //_____________________________________________________________________________
1315 TBranch* AliRun::MakeBranchInTree(TTree *tree, const char* name, void* address, Int_t size, char *file)
1318 // Makes branch in given tree and diverts them to a separate file
1321 printf("* MakeBranch * Making Branch %s \n",name);
1323 TBranch *branch = tree->Branch(name,address,size);
1326 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
1327 sprintf(outFile,"%s/%s",gAlice->GetBaseFile(),file);
1328 TDirectory *cwd = gDirectory;
1329 branch->SetFile(outFile);
1330 TIter next( branch->GetListOfBranches());
1331 while ((branch=(TBranch*)next())) {
1332 branch->SetFile(outFile);
1335 printf("* MakeBranch * Diverting Branch %s to file %s\n",name,file);
1343 //_____________________________________________________________________________
1344 TBranch* AliRun::MakeBranchInTree(TTree *tree, const char* name, const char *classname, void* address, Int_t size, Int_t splitlevel, char *file)
1347 // Makes branch in given tree and diverts them to a separate file
1349 TDirectory *cwd = gDirectory;
1350 TBranch *branch = tree->Branch(name,classname,address,size,splitlevel);
1353 printf("* MakeBranch * Making Branch %s \n",name);
1355 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
1356 sprintf(outFile,"%s/%s",gAlice->GetBaseFile(),file);
1357 branch->SetFile(outFile);
1358 TIter next( branch->GetListOfBranches());
1359 while ((branch=(TBranch*)next())) {
1360 branch->SetFile(outFile);
1363 printf("* MakeBranch * Diverting Branch %s to file %s\n",name,file);
1369 //_____________________________________________________________________________
1370 void AliRun::MakeTree(Option_t *option, char *file)
1373 // Create the ROOT trees
1374 // Loop on all detectors to create the Root branch (if any)
1380 const char *oK = strstr(option,"K");
1381 const char *oH = strstr(option,"H");
1382 const char *oE = strstr(option,"E");
1383 const char *oD = strstr(option,"D");
1384 const char *oR = strstr(option,"R");
1385 const char *oS = strstr(option,"S");
1388 if (oK && !fTreeK) {
1389 sprintf(hname,"TreeK%d",fEvent);
1390 fTreeK = new TTree(hname,"Kinematics");
1391 // Create a branch for particles
1392 MakeBranchInTree(fTreeK,
1393 "Particles", "TParticle", &fParticleBuffer, 4000, 1, file) ;
1396 if (oH && !fTreeH) {
1397 sprintf(hname,"TreeH%d",fEvent);
1398 fTreeH = new TTree(hname,"Hits");
1399 fTreeH->SetAutoSave(1000000000); //no autosave
1402 if (oD && !fTreeD) {
1403 sprintf(hname,"TreeD%d",fEvent);
1404 fTreeD = new TTree(hname,"Digits");
1407 if (oS && !fTreeS) {
1408 sprintf(hname,"TreeS%d",fEvent);
1409 fTreeS = new TTree(hname,"SDigits");
1412 if (oR && !fTreeR) {
1413 sprintf(hname,"TreeR%d",fEvent);
1414 fTreeR = new TTree(hname,"Reconstruction");
1417 if (oE && !fTreeE) {
1418 fTreeE = new TTree("TE","Header");
1420 = MakeBranchInTree(fTreeE,
1421 "Header", "AliHeader", &gAliHeader, 4000, 0, file) ;
1422 branch->SetAutoDelete(kFALSE);
1427 // Create a branch for hits/digits for each detector
1428 // Each branch is a TClonesArray. Each data member of the Hits classes
1429 // will be in turn a subbranch of the detector master branch
1430 TIter next(fModules);
1431 AliModule *detector;
1432 while((detector = (AliModule*)next())) {
1433 if (oH) detector->MakeBranch(option,file);
1437 //_____________________________________________________________________________
1438 Int_t AliRun::PurifyKine(Int_t lastSavedTrack, Int_t nofTracks)
1441 // PurifyKine with external parameters
1443 fHgwmk = lastSavedTrack;
1444 fNtrack = nofTracks;
1449 //_____________________________________________________________________________
1450 TParticle* AliRun::Particle(Int_t i)
1452 if(!(*fParticleMap)[i]) {
1453 Int_t nentries = fParticles->GetEntries();
1455 // algorithmic way of getting entry index
1456 // (primary particles are filled after secondaries)
1458 if (i<fHeader.GetNprimary())
1459 entry = i+fHeader.GetNsecondary();
1461 entry = i-fHeader.GetNprimary();
1463 // only check the algorithmic way and give
1464 // the fatal error if it is wrong
1465 if (entry != fParticleFileMap[i]) {
1467 "!!!! The algorithmic way is WRONG: !!!\n entry: %d map: %d",
1468 entry, fParticleFileMap[i]);
1471 fTreeK->GetEntry(fParticleFileMap[i]);
1472 //fTreeK->GetEntry(entry);
1473 new ((*fParticles)[nentries]) TParticle(*fParticleBuffer);
1474 fParticleMap->AddAt((*fParticles)[nentries],i);
1476 return (TParticle *) (*fParticleMap)[i];
1479 //_____________________________________________________________________________
1480 void AliRun::PurifyKine()
1483 // Compress kinematic tree keeping only flagged particles
1484 // and renaming the particle id's in all the hits
1486 // TClonesArray &particles = *fParticles;
1487 TObjArray &particles = *fParticleMap;
1488 int nkeep=fHgwmk+1, parent, i;
1489 TParticle *part, *father;
1490 TArrayI map(particles.GetLast()+1);
1492 // Save in Header total number of tracks before compression
1493 fHeader.SetNtrack(fHeader.GetNtrack()+fNtrack-fHgwmk);
1495 // If no tracks generated return now
1496 if(fHgwmk+1 == fNtrack) return;
1498 Int_t toshrink = fNtrack-fHgwmk-1;
1500 // First pass, invalid Daughter information
1501 for(i=0; i<fNtrack; i++) {
1502 // Preset map, to be removed later
1503 if(i<=fHgwmk) map[i]=i ;
1506 // particles.UncheckedAt(i)->ResetBit(kDaughtersBit);
1507 if((part=(TParticle*) particles.At(i))) part->ResetBit(kDaughtersBit);
1510 // Invalid daughter information for the parent of the first particle
1511 // generated. This may or may not be the current primary according to
1512 // whether decays have been recorded among the primaries
1513 part = (TParticle *)particles.At(fHgwmk+1);
1514 particles.At(part->GetFirstMother())->ResetBit(kDaughtersBit);
1515 // Second pass, build map between old and new numbering
1516 for(i=fHgwmk+1; i<fNtrack; i++) {
1517 if(particles.At(i)->TestBit(kKeepBit)) {
1519 // This particle has to be kept
1521 // If old and new are different, have to move the pointer
1522 if(i!=nkeep) particles[nkeep]=particles.At(i);
1523 part = (TParticle*) particles.At(nkeep);
1525 // as the parent is always *before*, it must be already
1526 // in place. This is what we are checking anyway!
1527 if((parent=part->GetFirstMother())>fHgwmk)
1528 if(map[parent]==-99) Fatal("PurifyKine","map[%d] = -99!\n",parent);
1529 else part->SetFirstMother(map[parent]);
1535 // Fix daughters information
1536 for (i=fHgwmk+1; i<nkeep; i++) {
1537 part = (TParticle *)particles.At(i);
1538 parent = part->GetFirstMother();
1540 father = (TParticle *)particles.At(parent);
1541 if(father->TestBit(kDaughtersBit)) {
1543 if(i<father->GetFirstDaughter()) father->SetFirstDaughter(i);
1544 if(i>father->GetLastDaughter()) father->SetLastDaughter(i);
1546 // Initialise daughters info for first pass
1547 father->SetFirstDaughter(i);
1548 father->SetLastDaughter(i);
1549 father->SetBit(kDaughtersBit);
1554 // Now loop on all registered hit lists
1555 TIter next(fHitLists);
1556 TCollection *hitList;
1557 while((hitList = (TCollection*)next())) {
1558 TIter nexthit(hitList);
1560 while((hit = (AliHit*)nexthit())) {
1561 hit->SetTrack(map[hit->GetTrack()]);
1566 // This for detectors which have a special mapping mechanism
1567 // for hits, such as TPC and TRD
1570 TIter nextmod(fModules);
1571 AliModule *detector;
1572 while((detector = (AliModule*)nextmod())) {
1573 detector->RemapTrackHitIDs(map.GetArray());
1576 // Now the output bit, from fHgwmk to nkeep we write everything and we erase
1577 if(nkeep>fParticleFileMap.GetSize()) fParticleFileMap.Set(Int_t (nkeep*1.5));
1580 for (i=fHgwmk+1; i<nkeep; ++i) {
1581 fParticleBuffer = (TParticle*) particles.At(i);
1582 fParticleFileMap[i]=(Int_t) fTreeK->GetEntries();
1587 for (i=nkeep; i<fNtrack; ++i) particles[i]=0;
1589 fLoadPoint-=toshrink;
1590 for(i=fLoadPoint; i<fLoadPoint+toshrink; ++i) fParticles->RemoveAt(i);
1597 //_____________________________________________________________________________
1598 void AliRun::BeginEvent()
1601 // Reset all Detectors & kinematics & trees
1608 fLego->BeginEvent();
1618 // Initialise event header
1619 fHeader.Reset(fRun,fEvent);
1623 sprintf(hname,"TreeK%d",fEvent);
1624 fTreeK->SetName(hname);
1628 sprintf(hname,"TreeH%d",fEvent);
1629 fTreeH->SetName(hname);
1633 sprintf(hname,"TreeD%d",fEvent);
1634 fTreeD->SetName(hname);
1638 sprintf(hname,"TreeS%d",fEvent);
1639 fTreeS->SetName(hname);
1643 sprintf(hname,"TreeR%d",fEvent);
1644 fTreeR->SetName(hname);
1647 //_____________________________________________________________________________
1648 void AliRun::ResetDigits()
1651 // Reset all Detectors digits
1653 TIter next(fModules);
1654 AliModule *detector;
1655 while((detector = (AliModule*)next())) {
1656 detector->ResetDigits();
1660 //_____________________________________________________________________________
1661 void AliRun::ResetSDigits()
1664 // Reset all Detectors digits
1666 TIter next(fModules);
1667 AliModule *detector;
1668 while((detector = (AliModule*)next())) {
1669 detector->ResetSDigits();
1673 //_____________________________________________________________________________
1674 void AliRun::ResetHits()
1677 // Reset all Detectors hits
1679 TIter next(fModules);
1680 AliModule *detector;
1681 while((detector = (AliModule*)next())) {
1682 detector->ResetHits();
1686 //_____________________________________________________________________________
1687 void AliRun::ResetPoints()
1690 // Reset all Detectors points
1692 TIter next(fModules);
1693 AliModule *detector;
1694 while((detector = (AliModule*)next())) {
1695 detector->ResetPoints();
1699 //_____________________________________________________________________________
1700 void AliRun::RunMC(Int_t nevent, const char *setup)
1703 // Main function to be called to process a galice run
1705 // Root > gAlice.Run();
1706 // a positive number of events will cause the finish routine
1710 // check if initialisation has been done
1711 if (!fInitDone) InitMC(setup);
1713 // Create the Root Tree with one branch per detector
1717 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1718 MakeTree("K","Kine.root");
1719 MakeTree("H","Hits.root");
1724 gMC->ProcessRun(nevent);
1726 // End of this run, close files
1727 if(nevent>0) FinishRun();
1730 //_____________________________________________________________________________
1731 void AliRun::RunReco(const char *detector)
1734 // Main function to be called to reconstruct Alice event
1738 Digits2Reco(detector);
1741 //_____________________________________________________________________________
1743 void AliRun::Hits2Digits(const char *selected)
1745 // Convert Hits to sumable digits
1747 Hits2SDigits(selected);
1748 SDigits2Digits(selected);
1752 //_____________________________________________________________________________
1754 void AliRun::Tree2Tree(Option_t *option, const char *selected)
1757 // Function to transform the content of
1759 // - TreeH to TreeS (option "S")
1760 // - TreeS to TreeD (option "D")
1761 // - TreeD to TreeR (option "R")
1763 // If multiple options are specified ("SDR"), transformation will be done in sequence for
1764 // selected detector and for all detectors if none is selected (detector string
1765 // can contain blank separated list of detector names).
1768 const char *oS = strstr(option,"S");
1769 const char *oD = strstr(option,"D");
1770 const char *oR = strstr(option,"R");
1772 gAlice->GetEvent(0);
1774 TObjArray *detectors = gAlice->Detectors();
1776 TIter next(detectors);
1778 AliDetector *detector = 0;
1780 TDirectory *cwd = gDirectory;
1784 while((detector = (AliDetector*)next())) {
1786 if (strcmp(detector->GetName(),selected)) continue;
1787 if (detector->IsActive()){
1789 cout << "Processing " << detector->GetName() << "..." << endl;
1790 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1792 sprintf(outFile,"SDigits.%s.root",detector->GetName());
1793 detector->MakeBranch("S",outFile);
1796 sprintf(outFile,"Digits.%s.root",detector->GetName());
1797 detector->MakeBranch("D",outFile);
1800 sprintf(outFile,"Reco.%s.root",detector->GetName());
1801 detector->MakeBranch("R",outFile);
1804 detector->MakeBranch(option);
1810 detector->Hits2SDigits();
1812 detector->SDigits2Digits();
1814 detector->Digits2Reco();
1823 //_____________________________________________________________________________
1824 void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min,
1825 Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max,
1826 Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener)
1829 // Generates lego plots of:
1830 // - radiation length map phi vs theta
1831 // - radiation length map phi vs eta
1832 // - interaction length map
1833 // - g/cm2 length map
1835 // ntheta bins in theta, eta
1836 // themin minimum angle in theta (degrees)
1837 // themax maximum angle in theta (degrees)
1839 // phimin minimum angle in phi (degrees)
1840 // phimax maximum angle in phi (degrees)
1841 // rmin minimum radius
1842 // rmax maximum radius
1845 // The number of events generated = ntheta*nphi
1846 // run input parameters in macro setup (default="Config.C")
1848 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1851 <img src="picts/AliRunLego1.gif">
1856 <img src="picts/AliRunLego2.gif">
1861 <img src="picts/AliRunLego3.gif">
1866 // check if initialisation has been done
1867 if (!fInitDone) InitMC(setup);
1868 //Save current generator
1869 AliGenerator *gen=Generator();
1871 // Set new generator
1872 if (!gener) gener = new AliLegoGenerator();
1873 ResetGenerator(gener);
1875 // Configure Generator
1876 gener->SetRadiusRange(rmin, rmax);
1877 gener->SetZMax(zmax);
1878 gener->SetCoor1Range(nc1, c1min, c1max);
1879 gener->SetCoor2Range(nc2, c2min, c2max);
1882 //Create Lego object
1883 fLego = new AliLego("lego",gener);
1885 //Prepare MC for Lego Run
1890 gMC->ProcessRun(nc1*nc2+1);
1892 // Create only the Root event Tree
1895 // End of this run, close files
1897 // Restore current generator
1898 ResetGenerator(gen);
1899 // Delete Lego Object
1900 delete fLego; fLego=0;
1903 //_____________________________________________________________________________
1904 void AliRun::SetConfigFunction(const char * config)
1907 // Set the signature of the function contained in Config.C to configure
1910 fConfigFunction=config;
1913 //_____________________________________________________________________________
1914 void AliRun::SetCurrentTrack(Int_t track)
1917 // Set current track number
1922 //_____________________________________________________________________________
1923 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1924 Float_t *vpos, Float_t *polar, Float_t tof,
1925 AliMCProcess mech, Int_t &ntr, Float_t weight)
1928 // Load a track on the stack
1930 // done 0 if the track has to be transported
1932 // parent identifier of the parent track. -1 for a primary
1933 // pdg particle code
1934 // pmom momentum GeV/c
1936 // polar polarisation
1937 // tof time of flight in seconds
1938 // mecha production mechanism
1939 // ntr on output the number of the track stored
1941 TClonesArray &particles = *fParticles;
1942 TParticle *particle;
1944 const Int_t kfirstdaughter=-1;
1945 const Int_t klastdaughter=-1;
1947 // const Float_t tlife=0;
1950 // Here we get the static mass
1951 // For MC is ok, but a more sophisticated method could be necessary
1952 // if the calculated mass is required
1953 // also, this method is potentially dangerous if the mass
1954 // used in the MC is not the same of the PDG database
1956 mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
1957 Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+
1958 pmom[1]*pmom[1]+pmom[2]*pmom[2]);
1960 //printf("Loading particle %s mass %f ene %f No %d ip %d pos %f %f %f mom %f %f %f kS %d m %s\n",
1961 //pname,mass,e,fNtrack,pdg,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],kS,mecha);
1963 particle=new(particles[fLoadPoint++]) TParticle(pdg,kS,parent,-1,kfirstdaughter,
1964 klastdaughter,pmom[0],pmom[1],pmom[2],
1965 e,vpos[0],vpos[1],vpos[2],tof);
1966 particle->SetPolarisation(TVector3(polar[0],polar[1],polar[2]));
1967 particle->SetWeight(weight);
1968 particle->SetUniqueID(mech);
1969 if(!done) particle->SetBit(kDoneBit);
1970 // Declare that the daughter information is valid
1971 particle->SetBit(kDaughtersBit);
1972 // Add the particle to the stack
1973 fParticleMap->AddAtAndExpand(particle,fNtrack);
1976 particle=(TParticle*) fParticleMap->At(parent);
1977 particle->SetLastDaughter(fNtrack);
1978 if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack);
1981 // This is a primary track. Set high water mark for this event
1984 // Set also number if primary tracks
1985 fHeader.SetNprimary(fHgwmk+1);
1986 fHeader.SetNtrack(fHgwmk+1);
1992 // Here we get the static mass
1993 // For MC is ok, but a more sophisticated method could be necessary
1994 // if the calculated mass is required
1995 // also, this method is potentially dangerous if the mass
1996 // used in the MC is not the same of the PDG database
1998 Float_t mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
1999 Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+
2000 pmom[1]*pmom[1]+pmom[2]*pmom[2]);
2002 SetTrack(done, parent, pdg, pmom[0], pmom[1], pmom[2], e,
2003 vpos[0], vpos[1], vpos[2], tof, polar[0],polar[1],polar[2],
2008 //_____________________________________________________________________________
2009 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg,
2010 Double_t px, Double_t py, Double_t pz, Double_t e,
2011 Double_t vx, Double_t vy, Double_t vz, Double_t tof,
2012 Double_t polx, Double_t poly, Double_t polz,
2013 AliMCProcess mech, Int_t &ntr, Float_t weight)
2016 // Load a track on the stack
2018 // done 0 if the track has to be transported
2020 // parent identifier of the parent track. -1 for a primary
2021 // pdg particle code
2022 // kS generation status code
2023 // px, py, pz momentum GeV/c
2024 // vx, vy, vz position
2025 // polar polarisation
2026 // tof time of flight in seconds
2027 // mech production mechanism
2028 // ntr on output the number of the track stored
2030 // New method interface:
2031 // arguments were changed to be in correspondence with TParticle
2033 // Note: the energy is not calculated from the static mass but
2034 // it is passed by argument e.
2036 TClonesArray &particles = *fParticles;
2039 const Int_t kFirstDaughter=-1;
2040 const Int_t kLastDaughter=-1;
2043 = new(particles[fLoadPoint++]) TParticle(pdg, kS, parent, -1,
2044 kFirstDaughter, kLastDaughter,
2045 px, py, pz, e, vx, vy, vz, tof);
2047 particle->SetPolarisation(polx, poly, polz);
2048 particle->SetWeight(weight);
2049 particle->SetUniqueID(mech);
2051 if(!done) particle->SetBit(kDoneBit);
2053 // Declare that the daughter information is valid
2054 particle->SetBit(kDaughtersBit);
2055 // Add the particle to the stack
2056 fParticleMap->AddAtAndExpand(particle,fNtrack);
2059 particle=(TParticle*) fParticleMap->At(parent);
2060 particle->SetLastDaughter(fNtrack);
2061 if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack);
2064 // This is a primary track. Set high water mark for this event
2067 // Set also number if primary tracks
2068 fHeader.SetNprimary(fHgwmk+1);
2069 fHeader.SetNtrack(fHgwmk+1);
2074 //_____________________________________________________________________________
2075 void AliRun::SetHighWaterMark(const Int_t nt)
2078 // Set high water mark for last track in event
2081 // Set also number if primary tracks
2082 fHeader.SetNprimary(fHgwmk+1);
2083 fHeader.SetNtrack(fHgwmk+1);
2086 //_____________________________________________________________________________
2087 void AliRun::KeepTrack(const Int_t track)
2090 // flags a track to be kept
2092 fParticleMap->At(track)->SetBit(kKeepBit);
2095 //_____________________________________________________________________________
2096 void AliRun::StepManager(Int_t id)
2099 // Called at every step during transport
2103 // --- If lego option, do it and leave
2105 fLego->StepManager();
2108 //Update energy deposition tables
2109 AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
2111 //Call the appropriate stepping routine;
2112 AliModule *det = (AliModule*)fModules->At(id);
2114 fMCQA->StepManager(id);
2120 //_____________________________________________________________________________
2121 void AliRun::Streamer(TBuffer &R__b)
2123 // Stream an object of class AliRun.
2125 if (R__b.IsReading()) {
2126 if (!gAlice) gAlice = this;
2128 AliRun::Class()->ReadBuffer(R__b, this);
2130 gROOT->GetListOfBrowsables()->Add(this,"Run");
2132 fTreeE = (TTree*)gDirectory->Get("TE");
2133 if (fTreeE) fTreeE->SetBranchAddress("Header", &gAliHeader);
2134 else Error("Streamer","cannot find Header Tree\n");
2135 fTreeE->GetEntry(0);
2139 AliRun::Class()->WriteBuffer(R__b, this);