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.29 2000/04/07 11:12:34 fca
19 G4 compatibility changes
21 Revision 1.28 2000/04/05 06:51:06 fca
22 Workaround for an HP compiler problem
24 Revision 1.27 2000/03/22 18:08:07 fca
25 Rationalisation of the virtual MC interfaces
27 Revision 1.26 2000/03/22 13:42:26 fca
28 SetGenerator does not replace an existing generator, ResetGenerator does
30 Revision 1.25 2000/02/23 16:25:22 fca
31 AliVMC and AliGeant3 classes introduced
32 ReadEuclid moved from AliRun to AliModule
34 Revision 1.24 2000/01/19 17:17:20 fca
35 Introducing a list of lists of hits -- more hits allowed for detector now
37 Revision 1.23 1999/12/03 11:14:31 fca
38 Fixing previous wrong checking
40 Revision 1.21 1999/11/25 10:40:08 fca
41 Fixing daughters information also in primary tracks
43 Revision 1.20 1999/10/04 18:08:49 fca
44 Adding protection against inconsistent Euclid files
46 Revision 1.19 1999/09/29 07:50:40 fca
47 Introduction of the Copyright and cvs Log
51 ///////////////////////////////////////////////////////////////////////////////
53 // Control class for Alice C++ //
54 // Only one single instance of this class exists. //
55 // The object is created in main program aliroot //
56 // and is pointed by the global gAlice. //
58 // -Supports the list of all Alice Detectors (fModules). //
59 // -Supports the list of particles (fParticles). //
60 // -Supports the Trees. //
61 // -Supports the geometry. //
62 // -Supports the event display. //
65 <img src="picts/AliRunClass.gif">
70 <img src="picts/alirun.gif">
74 ///////////////////////////////////////////////////////////////////////////////
82 #include <TObjectTable.h>
84 #include "TParticle.h"
86 #include "AliDisplay.h"
95 static AliHeader *header;
99 //_____________________________________________________________________________
103 // Default constructor for AliRun
127 fPDGDB = 0; //Particle factory object!
129 fConfigFunction = "\0";
132 //_____________________________________________________________________________
133 AliRun::AliRun(const char *name, const char *title)
137 // Constructor for the main processor.
138 // Creates the geometry
139 // Creates the list of Detectors.
140 // Creates the list of particles.
156 fConfigFunction = "Config();";
158 gROOT->GetListOfBrowsables()->Add(this,name);
160 // create the support list for the various Detectors
161 fModules = new TObjArray(77);
163 // Create the TNode geometry for the event display
165 BuildSimpleGeometry();
175 // Create the particle stack
176 fParticles = new TClonesArray("TParticle",100);
180 // Create default mag field
185 // Prepare the tracking medium lists
186 fImedia = new TArrayI(1000);
187 for(i=0;i<1000;i++) (*fImedia)[i]=-99;
190 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
192 // Create HitLists list
193 fHitLists = new TList();
196 //_____________________________________________________________________________
200 // Defaullt AliRun destructor
219 fParticles->Delete();
225 //_____________________________________________________________________________
226 void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
229 // Add a hit to detector id
231 TObjArray &dets = *fModules;
232 if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits);
235 //_____________________________________________________________________________
236 void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
239 // Add digit to detector id
241 TObjArray &dets = *fModules;
242 if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits);
245 //_____________________________________________________________________________
246 void AliRun::Browse(TBrowser *b)
249 // Called when the item "Run" is clicked on the left pane
250 // of the Root browser.
251 // It displays the Root Trees and all detectors.
253 if (fTreeK) b->Add(fTreeK,fTreeK->GetName());
254 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
255 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
256 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
257 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
259 TIter next(fModules);
261 while((detector = (AliModule*)next())) {
262 b->Add(detector,detector->GetName());
266 //_____________________________________________________________________________
270 // Initialize Alice geometry
275 //_____________________________________________________________________________
276 void AliRun::BuildSimpleGeometry()
279 // Create a simple TNode geometry used by Root display engine
281 // Initialise geometry
283 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
284 new TMaterial("void","Vacuum",0,0,0); //Everything is void
285 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
286 brik->SetVisibility(0);
287 new TNode("alice","alice","S_alice");
290 //_____________________________________________________________________________
291 void AliRun::CleanDetectors()
294 // Clean Detectors at the end of event
296 TIter next(fModules);
298 while((detector = (AliModule*)next())) {
299 detector->FinishEvent();
303 //_____________________________________________________________________________
304 void AliRun::CleanParents()
307 // Clean Particles stack.
308 // Set parent/daughter relations
310 TClonesArray &particles = *(gAlice->Particles());
313 for(i=0; i<fNtrack; i++) {
314 part = (TParticle *)particles.UncheckedAt(i);
315 if(!part->TestBit(Daughters_Bit)) {
316 part->SetFirstDaughter(-1);
317 part->SetLastDaughter(-1);
322 //_____________________________________________________________________________
323 Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
326 // Return the distance from the mouse to the AliRun object
332 //_____________________________________________________________________________
333 void AliRun::DumpPart (Int_t i)
336 // Dumps particle i in the stack
338 TClonesArray &particles = *fParticles;
339 ((TParticle*) particles[i])->Print();
342 //_____________________________________________________________________________
343 void AliRun::DumpPStack ()
346 // Dumps the particle stack
348 TClonesArray &particles = *fParticles;
350 "\n\n=======================================================================\n");
351 for (Int_t i=0;i<fNtrack;i++)
353 printf("-> %d ",i); ((TParticle*) particles[i])->Print();
354 printf("--------------------------------------------------------------\n");
357 "\n=======================================================================\n\n");
360 //_____________________________________________________________________________
361 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
362 Float_t maxField, char* filename)
365 // Set magnetic field parameters
366 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
367 // version Magnetic field map version (only 1 active now)
368 // scale Scale factor for the magnetic field
369 // maxField Maximum value for the magnetic field
372 // --- Sanity check on mag field flags
373 if(type<0 || type > 2) {
375 "Invalid magnetic field flag: %5d; Helix tracking chosen instead\n"
379 if(fField) delete fField;
381 fField = new AliMagFC("Map1"," ",type,version,scale,maxField);
382 } else if(version<=3) {
383 fField = new AliMagFCM("Map2-3",filename,type,version,scale,maxField);
386 Warning("SetField","Invalid map %d\n",version);
390 //_____________________________________________________________________________
391 void AliRun::FillTree()
394 // Fills all AliRun TTrees
396 if (fTreeK) fTreeK->Fill();
397 if (fTreeH) fTreeH->Fill();
398 if (fTreeD) fTreeD->Fill();
399 if (fTreeR) fTreeR->Fill();
402 //_____________________________________________________________________________
403 void AliRun::FinishPrimary()
406 // Called at the end of each primary track
409 // static Int_t count=0;
410 // const Int_t times=10;
411 // This primary is finished, purify stack
414 // Write out hits if any
415 if (gAlice->TreeH()) {
416 gAlice->TreeH()->Fill();
423 // if(++count%times==1) gObjectTable->Print();
426 //_____________________________________________________________________________
427 void AliRun::FinishEvent()
430 // Called at the end of the event.
433 //Update the energy deposit tables
435 for(i=0;i<fEventEnergy.GetSize();i++) {
436 fSummEnergy[i]+=fEventEnergy[i];
437 fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
439 fEventEnergy.Reset();
441 // Clean detector information
444 // Write out the kinematics
450 // Write out the digits
456 // Write out reconstructed clusters
461 // Write out the event Header information
462 if (fTreeE) fTreeE->Fill();
467 // Write Tree headers
468 // Int_t ievent = fHeader.GetEvent();
470 // sprintf(hname,"TreeK%d",ievent);
471 if (fTreeK) fTreeK->Write();
472 // sprintf(hname,"TreeH%d",ievent);
473 if (fTreeH) fTreeH->Write();
474 // sprintf(hname,"TreeD%d",ievent);
475 if (fTreeD) fTreeD->Write();
476 // sprintf(hname,"TreeR%d",ievent);
477 if (fTreeR) fTreeR->Write();
482 //_____________________________________________________________________________
483 void AliRun::FinishRun()
486 // Called at the end of the run.
489 // Clean detector information
490 TIter next(fModules);
492 while((detector = (AliModule*)next())) {
493 detector->FinishRun();
496 //Output energy summary tables
499 // file is retrieved from whatever tree
501 if (fTreeK) File = fTreeK->GetCurrentFile();
502 if ((!File) && (fTreeH)) File = fTreeH->GetCurrentFile();
503 if ((!File) && (fTreeD)) File = fTreeD->GetCurrentFile();
504 if ((!File) && (fTreeE)) File = fTreeE->GetCurrentFile();
506 Error("FinishRun","There isn't root file!");
512 // Clean tree information
513 delete fTreeK; fTreeK = 0;
514 delete fTreeH; fTreeH = 0;
515 delete fTreeD; fTreeD = 0;
516 delete fTreeR; fTreeR = 0;
517 delete fTreeE; fTreeE = 0;
519 // Write AliRun info and all detectors parameters
526 //_____________________________________________________________________________
527 void AliRun::FlagTrack(Int_t track)
530 // Flags a track and all its family tree to be kept
537 particle=(TParticle*)fParticles->UncheckedAt(curr);
539 // If the particle is flagged the three from here upward is saved already
540 if(particle->TestBit(Keep_Bit)) return;
542 // Save this particle
543 particle->SetBit(Keep_Bit);
545 // Move to father if any
546 if((curr=particle->GetFirstMother())==-1) return;
550 //_____________________________________________________________________________
551 void AliRun::EnergySummary()
554 // Print summary of deposited energy
560 Int_t kn, i, left, j, id;
561 const Float_t zero=0;
562 Int_t ievent=fHeader.GetEvent()+1;
564 // Energy loss information
566 printf("***************** Energy Loss Information per event (GEV) *****************\n");
567 for(kn=1;kn<fEventEnergy.GetSize();kn++) {
570 fEventEnergy[ndep]=kn;
575 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,zero))/ed;
578 fSummEnergy[ndep]=ed;
579 fSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,zero));
584 for(kn=0;kn<(ndep-1)/3+1;kn++) {
586 for(i=0;i<(3<left?3:left);i++) {
588 id=Int_t (fEventEnergy[j]+0.1);
589 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]);
594 // Relative energy loss in different detectors
595 printf("******************** Relative Energy Loss per event ********************\n");
596 printf("Total energy loss per event %10.3f GeV\n",edtot);
597 for(kn=0;kn<(ndep-1)/5+1;kn++) {
599 for(i=0;i<(5<left?5:left);i++) {
601 id=Int_t (fEventEnergy[j]+0.1);
602 printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot);
606 for(kn=0;kn<75;kn++) printf("*");
610 // Reset the TArray's
611 // fEventEnergy.Set(0);
612 // fSummEnergy.Set(0);
613 // fSum2Energy.Set(0);
616 //_____________________________________________________________________________
617 AliModule *AliRun::GetModule(const char *name)
620 // Return pointer to detector from name
622 return (AliModule*)fModules->FindObject(name);
625 //_____________________________________________________________________________
626 AliDetector *AliRun::GetDetector(const char *name)
629 // Return pointer to detector from name
631 return (AliDetector*)fModules->FindObject(name);
634 //_____________________________________________________________________________
635 Int_t AliRun::GetModuleID(const char *name)
638 // Return galice internal detector identifier from name
641 TObject *mod=fModules->FindObject(name);
642 if(mod) i=fModules->IndexOf(mod);
646 //_____________________________________________________________________________
647 Int_t AliRun::GetEvent(Int_t event)
650 // Connect the Trees Kinematics and Hits for event # event
651 // Set branch addresses
654 // Reset existing structures
659 // Delete Trees already connected
660 if (fTreeK) delete fTreeK;
661 if (fTreeH) delete fTreeH;
662 if (fTreeD) delete fTreeD;
663 if (fTreeR) delete fTreeR;
665 // Get header from file
666 if(fTreeE) fTreeE->GetEntry(event);
667 else Error("GetEvent","Cannot file Header Tree\n");
669 // Get Kine Tree from file
671 sprintf(treeName,"TreeK%d",event);
672 fTreeK = (TTree*)gDirectory->Get(treeName);
673 if (fTreeK) fTreeK->SetBranchAddress("Particles", &fParticles);
674 else Error("GetEvent","cannot find Kine Tree for event:%d\n",event);
676 // Get Hits Tree header from file
677 sprintf(treeName,"TreeH%d",event);
678 fTreeH = (TTree*)gDirectory->Get(treeName);
680 Error("GetEvent","cannot find Hits Tree for event:%d\n",event);
683 // Get Digits Tree header from file
684 sprintf(treeName,"TreeD%d",event);
685 fTreeD = (TTree*)gDirectory->Get(treeName);
687 Warning("GetEvent","cannot find Digits Tree for event:%d\n",event);
691 // Get Reconstruct Tree header from file
692 sprintf(treeName,"TreeR%d",event);
693 fTreeR = (TTree*)gDirectory->Get(treeName);
695 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
698 // Set Trees branch addresses
699 TIter next(fModules);
701 while((detector = (AliModule*)next())) {
702 detector->SetTreeAddress();
705 if (fTreeK) fTreeK->GetEvent(0);
706 fNtrack = Int_t (fParticles->GetEntries());
710 //_____________________________________________________________________________
711 TGeometry *AliRun::GetGeometry()
714 // Import Alice geometry from current file
715 // Return pointer to geometry object
717 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
719 // Unlink and relink nodes in detectors
720 // This is bad and there must be a better way...
723 TIter next(fModules);
725 while((detector = (AliModule*)next())) {
726 detector->SetTreeAddress();
727 TList *dnodes=detector->Nodes();
730 for ( j=0; j<dnodes->GetSize(); j++) {
731 node = (TNode*) dnodes->At(j);
732 node1 = fGeometry->GetNode(node->GetName());
733 dnodes->Remove(node);
734 dnodes->AddAt(node1,j);
740 //_____________________________________________________________________________
741 void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
742 Float_t &e, Float_t *vpos, Float_t *polar,
746 // Return next track from stack of particles
751 for(Int_t i=fNtrack-1; i>=0; i--) {
752 track=(TParticle*) fParticles->UncheckedAt(i);
753 if(!track->TestBit(Done_Bit)) {
755 // The track has not yet been processed
757 ipart=track->GetPdgCode();
765 track->GetPolarisation(pol);
770 track->SetBit(Done_Bit);
776 // stop and start timer when we start a primary track
777 Int_t nprimaries = fHeader.GetNprimary();
778 if (fCurrent >= nprimaries) return;
779 if (fCurrent < nprimaries-1) {
781 track=(TParticle*) fParticles->UncheckedAt(fCurrent+1);
782 // track->SetProcessTime(fTimer.CpuTime());
787 //_____________________________________________________________________________
788 Int_t AliRun::GetPrimary(Int_t track)
791 // return number of primary that has generated track
799 part = (TParticle *)fParticles->UncheckedAt(current);
800 parent=part->GetFirstMother();
801 if(parent<0) return current;
805 //_____________________________________________________________________________
806 void AliRun::InitMC(const char *setup)
809 // Initialize the Alice setup
812 gROOT->LoadMacro(setup);
813 gInterpreter->ProcessLine(fConfigFunction.Data());
815 gMC->DefineParticles(); //Create standard MC particles
817 TObject *objfirst, *objlast;
819 fNdets = fModules->GetLast()+1;
822 //=================Create Materials and geometry
825 TIter next(fModules);
827 while((detector = (AliModule*)next())) {
828 detector->SetTreeAddress();
829 objlast = gDirectory->GetList()->Last();
831 // Add Detector histograms in Detector list of histograms
832 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
833 else objfirst = gDirectory->GetList()->First();
835 detector->Histograms()->Add(objfirst);
836 objfirst = gDirectory->GetList()->After(objfirst);
839 SetTransPar(); //Read the cuts for all materials
841 MediaTable(); //Build the special IMEDIA table
843 //Initialise geometry deposition table
844 fEventEnergy.Set(gMC->NofVolumes()+1);
845 fSummEnergy.Set(gMC->NofVolumes()+1);
846 fSum2Energy.Set(gMC->NofVolumes()+1);
848 //Compute cross-sections
851 //Write Geometry object to current file.
857 //_____________________________________________________________________________
858 void AliRun::MediaTable()
861 // Built media table to get from the media number to
864 Int_t kz, nz, idt, lz, i, k, ind;
866 TObjArray &dets = *gAlice->Detectors();
870 for (kz=0;kz<fNdets;kz++) {
871 // If detector is defined
872 if((det=(AliModule*) dets[kz])) {
873 TArrayI &idtmed = *(det->GetIdtmed());
874 for(nz=0;nz<100;nz++) {
875 // Find max and min material number
876 if((idt=idtmed[nz])) {
877 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
878 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
881 if(det->LoMedium() > det->HiMedium()) {
885 if(det->HiMedium() > fImedia->GetSize()) {
886 Error("MediaTable","Increase fImedia from %d to %d",
887 fImedia->GetSize(),det->HiMedium());
890 // Tag all materials in rage as belonging to detector kz
891 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
898 // Print summary table
899 printf(" Traking media ranges:\n");
900 for(i=0;i<(fNdets-1)/6+1;i++) {
901 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
903 det=(AliModule*)dets[ind];
905 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
908 printf(" %6s: %3d -> %3d;","NULL",0,0);
914 //____________________________________________________________________________
915 void AliRun::SetGenerator(AliGenerator *generator)
918 // Load the event generator
920 if(!fGenerator) fGenerator = generator;
923 //____________________________________________________________________________
924 void AliRun::ResetGenerator(AliGenerator *generator)
927 // Load the event generator
930 Warning("ResetGenerator","Replacing generator %s with %s\n",
931 fGenerator->GetName(),generator->GetName());
932 fGenerator = generator;
935 //____________________________________________________________________________
936 void AliRun::SetTransPar(char* filename)
939 // Read filename to set the transport parameters
943 const Int_t ncuts=10;
944 const Int_t nflags=11;
945 const Int_t npars=ncuts+nflags;
946 const char pars[npars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
947 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
948 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
949 "MULS","PAIR","PHOT","RAYL"};
955 Int_t i, itmed, iret, ktmed, kz;
958 // See whether the file is there
959 filtmp=gSystem->ExpandPathName(filename);
960 lun=fopen(filtmp,"r");
963 Warning("SetTransPar","File %s does not exist!\n",filename);
967 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
968 printf(" *%59s\n","*");
969 printf(" * Please check carefully what you are doing!%10s\n","*");
970 printf(" *%59s\n","*");
973 // Initialise cuts and flags
974 for(i=0;i<ncuts;i++) cut[i]=-99;
975 for(i=0;i<nflags;i++) flag[i]=-99;
977 for(i=0;i<256;i++) line[i]='\0';
978 // Read up to the end of line excluded
979 iret=fscanf(lun,"%[^\n]",line);
983 printf(" *%59s\n","*");
984 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
987 // Read the end of line
990 if(line[0]=='*') continue;
992 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",
993 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
994 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
995 &flag[8],&flag[9],&flag[10]);
999 Warning("SetTransPar","Error reading file %s\n",filename);
1002 // Check that the module exist
1003 AliModule *mod = GetModule(detName);
1005 // Get the array of media numbers
1006 TArrayI &idtmed = *mod->GetIdtmed();
1007 // Check that the tracking medium code is valid
1008 if(0<=itmed && itmed < 100) {
1009 ktmed=idtmed[itmed];
1011 Warning("SetTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
1014 // Set energy thresholds
1015 for(kz=0;kz<ncuts;kz++) {
1017 printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
1018 pars[kz],cut[kz],itmed,mod->GetName());
1019 gMC->Gstpar(ktmed,pars[kz],cut[kz]);
1022 // Set transport mechanisms
1023 for(kz=0;kz<nflags;kz++) {
1025 printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
1026 pars[ncuts+kz],flag[kz],itmed,mod->GetName());
1027 gMC->Gstpar(ktmed,pars[ncuts+kz],Float_t(flag[kz]));
1031 Warning("SetTransPar","Invalid medium code %d *\n",itmed);
1035 Warning("SetTransPar","Module %s not present\n",detName);
1041 //_____________________________________________________________________________
1042 void AliRun::MakeTree(Option_t *option)
1045 // Create the ROOT trees
1046 // Loop on all detectors to create the Root branch (if any)
1052 char *K = strstr(option,"K");
1053 char *H = strstr(option,"H");
1054 char *E = strstr(option,"E");
1055 char *D = strstr(option,"D");
1056 char *R = strstr(option,"R");
1059 sprintf(hname,"TreeK%d",fEvent);
1060 fTreeK = new TTree(hname,"Kinematics");
1061 // Create a branch for particles
1062 fTreeK->Branch("Particles",&fParticles,4000);
1065 sprintf(hname,"TreeH%d",fEvent);
1066 fTreeH = new TTree(hname,"Hits");
1067 fTreeH->SetAutoSave(1000000000); //no autosave
1070 sprintf(hname,"TreeD%d",fEvent);
1071 fTreeD = new TTree(hname,"Digits");
1074 sprintf(hname,"TreeR%d",fEvent);
1075 fTreeR = new TTree(hname,"Reconstruction");
1078 fTreeE = new TTree("TE","Header");
1079 // Create a branch for Header
1080 fTreeE->Branch("Header","AliHeader",&header,4000);
1083 // Create a branch for hits/digits for each detector
1084 // Each branch is a TClonesArray. Each data member of the Hits classes
1085 // will be in turn a subbranch of the detector master branch
1086 TIter next(fModules);
1087 AliModule *detector;
1088 while((detector = (AliModule*)next())) {
1089 if (H || D || R) detector->MakeBranch(option);
1093 //_____________________________________________________________________________
1094 Int_t AliRun::PurifyKine(Int_t lastSavedTrack, Int_t nofTracks)
1097 // PurifyKine with external parameters
1099 fHgwmk = lastSavedTrack;
1100 fNtrack = nofTracks;
1105 //_____________________________________________________________________________
1106 void AliRun::PurifyKine()
1109 // Compress kinematic tree keeping only flagged particles
1110 // and renaming the particle id's in all the hits
1112 TClonesArray &particles = *fParticles;
1113 int nkeep=fHgwmk+1, parent, i;
1114 TParticle *part, *partnew, *father;
1115 int *map = new int[particles.GetEntries()];
1117 // Save in Header total number of tracks before compression
1118 fHeader.SetNtrack(fHeader.GetNtrack()+fNtrack-fHgwmk);
1120 // Preset map, to be removed later
1121 for(i=0; i<fNtrack; i++) {
1122 if(i<=fHgwmk) map[i]=i ; else map[i] = -99 ;}
1123 // Second pass, build map between old and new numbering
1124 for(i=fHgwmk+1; i<fNtrack; i++) {
1125 part = (TParticle *)particles.UncheckedAt(i);
1126 if(part->TestBit(Keep_Bit)) {
1128 // This particle has to be kept
1132 // Old and new are different, have to copy
1133 partnew = (TParticle *)particles.UncheckedAt(nkeep);
1134 // Change due to a bug in the HP compiler
1135 // *partnew = *part;
1136 memcpy(partnew,part,sizeof(TParticle));
1137 } else partnew = part;
1139 // as the parent is always *before*, it must be already
1140 // in place. This is what we are checking anyway!
1141 if((parent=partnew->GetFirstMother())>fHgwmk) {
1142 if(map[parent]==-99) printf("map[%d] = -99!\n",parent);
1143 partnew->SetFirstMother(map[parent]);
1150 // Fix daughters information
1151 for (i=0; i<fNtrack; i++) {
1152 part = (TParticle *)particles.UncheckedAt(i);
1153 parent = part->GetFirstMother();
1155 father = (TParticle *)particles.UncheckedAt(parent);
1156 if(father->TestBit(Daughters_Bit)) {
1158 if(i<father->GetFirstDaughter()) father->SetFirstDaughter(i);
1159 if(i>father->GetLastDaughter()) father->SetLastDaughter(i);
1161 // Iitialise daughters info for first pass
1162 father->SetFirstDaughter(i);
1163 father->SetLastDaughter(i);
1164 father->SetBit(Daughters_Bit);
1170 // Now loop on all detectors and reset the hits
1172 TIter next(fModules);
1173 AliModule *detector;
1174 while((detector = (AliModule*)next())) {
1175 if (!detector->Hits()) continue;
1176 TClonesArray &vHits=*(detector->Hits());
1177 if(vHits.GetEntries() != detector->GetNhits())
1178 printf("vHits.GetEntries()!=detector->GetNhits(): %d != %d\n",
1179 vHits.GetEntries(),detector->GetNhits());
1180 for (i=0; i<detector->GetNhits(); i++) {
1181 OneHit = (AliHit *)vHits.UncheckedAt(i);
1182 OneHit->SetTrack(map[OneHit->GetTrack()]);
1187 // Now loop on all registered hit lists
1188 TIter next(fHitLists);
1189 TCollection *hitList;
1190 while((hitList = (TCollection*)next())) {
1191 TIter nexthit(hitList);
1193 while((hit = (AliHit*)nexthit())) {
1194 hit->SetTrack(map[hit->GetTrack()]);
1200 particles.SetLast(fHgwmk);
1204 //_____________________________________________________________________________
1205 void AliRun::Reset()
1208 // Reset all Detectors & kinematics & trees
1216 // Initialise event header
1217 fHeader.Reset(fRun,fEvent);
1221 sprintf(hname,"TreeK%d",fEvent);
1222 fTreeK->SetName(hname);
1226 sprintf(hname,"TreeH%d",fEvent);
1227 fTreeH->SetName(hname);
1231 sprintf(hname,"TreeD%d",fEvent);
1232 fTreeD->SetName(hname);
1236 sprintf(hname,"TreeR%d",fEvent);
1237 fTreeR->SetName(hname);
1241 //_____________________________________________________________________________
1242 void AliRun::ResetDigits()
1245 // Reset all Detectors digits
1247 TIter next(fModules);
1248 AliModule *detector;
1249 while((detector = (AliModule*)next())) {
1250 detector->ResetDigits();
1254 //_____________________________________________________________________________
1255 void AliRun::ResetHits()
1258 // Reset all Detectors hits
1260 TIter next(fModules);
1261 AliModule *detector;
1262 while((detector = (AliModule*)next())) {
1263 detector->ResetHits();
1267 //_____________________________________________________________________________
1268 void AliRun::ResetPoints()
1271 // Reset all Detectors points
1273 TIter next(fModules);
1274 AliModule *detector;
1275 while((detector = (AliModule*)next())) {
1276 detector->ResetPoints();
1280 //_____________________________________________________________________________
1281 void AliRun::RunMC(Int_t nevent, const char *setup)
1284 // Main function to be called to process a galice run
1286 // Root > gAlice.Run();
1287 // a positive number of events will cause the finish routine
1291 // check if initialisation has been done
1292 if (!fInitDone) InitMC(setup);
1294 // Create the Root Tree with one branch per detector
1297 gMC->ProcessRun(nevent);
1299 // End of this run, close files
1300 if(nevent>0) FinishRun();
1303 //_____________________________________________________________________________
1304 void AliRun::RunLego(const char *setup,Int_t ntheta,Float_t themin,
1305 Float_t themax,Int_t nphi,Float_t phimin,Float_t phimax,
1306 Float_t rmin,Float_t rmax,Float_t zmax)
1309 // Generates lego plots of:
1310 // - radiation length map phi vs theta
1311 // - radiation length map phi vs eta
1312 // - interaction length map
1313 // - g/cm2 length map
1315 // ntheta bins in theta, eta
1316 // themin minimum angle in theta (degrees)
1317 // themax maximum angle in theta (degrees)
1319 // phimin minimum angle in phi (degrees)
1320 // phimax maximum angle in phi (degrees)
1321 // rmin minimum radius
1322 // rmax maximum radius
1325 // The number of events generated = ntheta*nphi
1326 // run input parameters in macro setup (default="Config.C")
1328 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1331 <img src="picts/AliRunLego1.gif">
1336 <img src="picts/AliRunLego2.gif">
1341 <img src="picts/AliRunLego3.gif">
1346 // check if initialisation has been done
1347 if (!fInitDone) InitMC(setup);
1349 //Create Lego object
1350 fLego = new AliLego("lego",ntheta,themin,themax,nphi,phimin,phimax,rmin,rmax,zmax);
1355 // Create only the Root event Tree
1358 // End of this run, close files
1362 //_____________________________________________________________________________
1363 void AliRun::SetCurrentTrack(Int_t track)
1366 // Set current track number
1371 //_____________________________________________________________________________
1372 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1373 Float_t *vpos, Float_t *polar, Float_t tof,
1374 const char *mecha, Int_t &ntr, Float_t weight)
1377 // Load a track on the stack
1379 // done 0 if the track has to be transported
1381 // parent identifier of the parent track. -1 for a primary
1382 // pdg particle code
1383 // pmom momentum GeV/c
1385 // polar polarisation
1386 // tof time of flight in seconds
1387 // mecha production mechanism
1388 // ntr on output the number of the track stored
1390 TClonesArray &particles = *fParticles;
1391 TParticle *particle;
1393 const Int_t firstdaughter=-1;
1394 const Int_t lastdaughter=-1;
1396 // const Float_t tlife=0;
1399 // Here we get the static mass
1400 // For MC is ok, but a more sophisticated method could be necessary
1401 // if the calculated mass is required
1402 // also, this method is potentially dangerous if the mass
1403 // used in the MC is not the same of the PDG database
1405 mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
1406 Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+
1407 pmom[1]*pmom[1]+pmom[2]*pmom[2]);
1409 //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",
1410 //pname,mass,e,fNtrack,pdg,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],KS,mecha);
1412 particle=new(particles[fNtrack]) TParticle(pdg,KS,parent,-1,firstdaughter,
1413 lastdaughter,pmom[0],pmom[1],pmom[2],
1414 e,vpos[0],vpos[1],vpos[2],tof);
1415 // polar[0],polar[1],polar[2],tof,
1417 ((TParticle*)particles[fNtrack])->SetPolarisation(TVector3(polar[0],polar[1],polar[2]));
1418 ((TParticle*)particles[fNtrack])->SetWeight(weight);
1419 if(!done) particle->SetBit(Done_Bit);
1422 particle=(TParticle*) fParticles->UncheckedAt(parent);
1423 particle->SetLastDaughter(fNtrack);
1424 if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack);
1427 // This is a primary track. Set high water mark for this event
1430 // Set also number if primary tracks
1431 fHeader.SetNprimary(fHgwmk+1);
1432 fHeader.SetNtrack(fHgwmk+1);
1437 //_____________________________________________________________________________
1438 void AliRun::KeepTrack(const Int_t track)
1441 // flags a track to be kept
1443 TClonesArray &particles = *fParticles;
1444 ((TParticle*)particles[track])->SetBit(Keep_Bit);
1447 //_____________________________________________________________________________
1448 void AliRun::StepManager(Int_t id)
1451 // Called at every step during transport
1455 // --- If lego option, do it and leave
1457 fLego->StepManager();
1460 //Update energy deposition tables
1461 AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
1463 //Call the appropriate stepping routine;
1464 AliModule *det = (AliModule*)fModules->At(id);
1465 if(det) det->StepManager();
1469 //_____________________________________________________________________________
1470 void AliRun::Streamer(TBuffer &R__b)
1473 // Stream an object of class AliRun.
1475 if (R__b.IsReading()) {
1476 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1477 TNamed::Streamer(R__b);
1478 if (!gAlice) gAlice = this;
1479 gROOT->GetListOfBrowsables()->Add(this,"Run");
1480 fTreeE = (TTree*)gDirectory->Get("TE");
1481 if (fTreeE) fTreeE->SetBranchAddress("Header", &header);
1482 else Error("Streamer","cannot find Header Tree\n");
1486 fHeader.Streamer(R__b);
1496 R__b >> fPDGDB; //Particle factory object!
1497 fTreeE->GetEntry(0);
1499 fHeader.SetEvent(0);
1500 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
1503 fConfigFunction.Streamer(R__b);
1505 fConfigFunction="Config();";
1508 R__b.WriteVersion(AliRun::IsA());
1509 TNamed::Streamer(R__b);
1513 fHeader.Streamer(R__b);
1522 R__b << fPDGDB; //Particle factory object!
1523 fConfigFunction.Streamer(R__b);