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.30 2000/04/18 19:11:40 fca
19 Introduce variable Config.C function signature
21 Revision 1.29 2000/04/07 11:12:34 fca
22 G4 compatibility changes
24 Revision 1.28 2000/04/05 06:51:06 fca
25 Workaround for an HP compiler problem
27 Revision 1.27 2000/03/22 18:08:07 fca
28 Rationalisation of the virtual MC interfaces
30 Revision 1.26 2000/03/22 13:42:26 fca
31 SetGenerator does not replace an existing generator, ResetGenerator does
33 Revision 1.25 2000/02/23 16:25:22 fca
34 AliVMC and AliGeant3 classes introduced
35 ReadEuclid moved from AliRun to AliModule
37 Revision 1.24 2000/01/19 17:17:20 fca
38 Introducing a list of lists of hits -- more hits allowed for detector now
40 Revision 1.23 1999/12/03 11:14:31 fca
41 Fixing previous wrong checking
43 Revision 1.21 1999/11/25 10:40:08 fca
44 Fixing daughters information also in primary tracks
46 Revision 1.20 1999/10/04 18:08:49 fca
47 Adding protection against inconsistent Euclid files
49 Revision 1.19 1999/09/29 07:50:40 fca
50 Introduction of the Copyright and cvs Log
54 ///////////////////////////////////////////////////////////////////////////////
56 // Control class for Alice C++ //
57 // Only one single instance of this class exists. //
58 // The object is created in main program aliroot //
59 // and is pointed by the global gAlice. //
61 // -Supports the list of all Alice Detectors (fModules). //
62 // -Supports the list of particles (fParticles). //
63 // -Supports the Trees. //
64 // -Supports the geometry. //
65 // -Supports the event display. //
68 <img src="picts/AliRunClass.gif">
73 <img src="picts/alirun.gif">
77 ///////////////////////////////////////////////////////////////////////////////
85 #include <TObjectTable.h>
87 #include "TParticle.h"
89 #include "AliDisplay.h"
99 static AliHeader *header;
103 //_____________________________________________________________________________
107 // Default constructor for AliRun
131 fPDGDB = 0; //Particle factory object!
133 fConfigFunction = "\0";
136 //_____________________________________________________________________________
137 AliRun::AliRun(const char *name, const char *title)
141 // Constructor for the main processor.
142 // Creates the geometry
143 // Creates the list of Detectors.
144 // Creates the list of particles.
160 fConfigFunction = "Config();";
162 gROOT->GetListOfBrowsables()->Add(this,name);
164 // create the support list for the various Detectors
165 fModules = new TObjArray(77);
167 // Create the TNode geometry for the event display
169 BuildSimpleGeometry();
179 // Create the particle stack
180 fParticles = new TClonesArray("TParticle",100);
184 // Create default mag field
189 // Prepare the tracking medium lists
190 fImedia = new TArrayI(1000);
191 for(i=0;i<1000;i++) (*fImedia)[i]=-99;
194 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
196 // Create HitLists list
197 fHitLists = new TList();
200 //_____________________________________________________________________________
204 // Defaullt AliRun destructor
223 fParticles->Delete();
229 //_____________________________________________________________________________
230 void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
233 // Add a hit to detector id
235 TObjArray &dets = *fModules;
236 if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits);
239 //_____________________________________________________________________________
240 void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
243 // Add digit to detector id
245 TObjArray &dets = *fModules;
246 if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits);
249 //_____________________________________________________________________________
250 void AliRun::Browse(TBrowser *b)
253 // Called when the item "Run" is clicked on the left pane
254 // of the Root browser.
255 // It displays the Root Trees and all detectors.
257 if (fTreeK) b->Add(fTreeK,fTreeK->GetName());
258 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
259 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
260 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
261 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
263 TIter next(fModules);
265 while((detector = (AliModule*)next())) {
266 b->Add(detector,detector->GetName());
270 //_____________________________________________________________________________
274 // Initialize Alice geometry
279 //_____________________________________________________________________________
280 void AliRun::BuildSimpleGeometry()
283 // Create a simple TNode geometry used by Root display engine
285 // Initialise geometry
287 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
288 new TMaterial("void","Vacuum",0,0,0); //Everything is void
289 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
290 brik->SetVisibility(0);
291 new TNode("alice","alice","S_alice");
294 //_____________________________________________________________________________
295 void AliRun::CleanDetectors()
298 // Clean Detectors at the end of event
300 TIter next(fModules);
302 while((detector = (AliModule*)next())) {
303 detector->FinishEvent();
307 //_____________________________________________________________________________
308 void AliRun::CleanParents()
311 // Clean Particles stack.
312 // Set parent/daughter relations
314 TClonesArray &particles = *(gAlice->Particles());
317 for(i=0; i<fNtrack; i++) {
318 part = (TParticle *)particles.UncheckedAt(i);
319 if(!part->TestBit(Daughters_Bit)) {
320 part->SetFirstDaughter(-1);
321 part->SetLastDaughter(-1);
326 //_____________________________________________________________________________
327 Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
330 // Return the distance from the mouse to the AliRun object
336 //_____________________________________________________________________________
337 void AliRun::DumpPart (Int_t i)
340 // Dumps particle i in the stack
342 TClonesArray &particles = *fParticles;
343 ((TParticle*) particles[i])->Print();
346 //_____________________________________________________________________________
347 void AliRun::DumpPStack ()
350 // Dumps the particle stack
352 TClonesArray &particles = *fParticles;
354 "\n\n=======================================================================\n");
355 for (Int_t i=0;i<fNtrack;i++)
357 printf("-> %d ",i); ((TParticle*) particles[i])->Print();
358 printf("--------------------------------------------------------------\n");
361 "\n=======================================================================\n\n");
364 //_____________________________________________________________________________
365 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
366 Float_t maxField, char* filename)
369 // Set magnetic field parameters
370 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
371 // version Magnetic field map version (only 1 active now)
372 // scale Scale factor for the magnetic field
373 // maxField Maximum value for the magnetic field
376 // --- Sanity check on mag field flags
377 if(type<0 || type > 2) {
379 "Invalid magnetic field flag: %5d; Helix tracking chosen instead\n"
383 if(fField) delete fField;
385 fField = new AliMagFC("Map1"," ",type,version,scale,maxField);
386 } else if(version<=3) {
387 fField = new AliMagFCM("Map2-3",filename,type,version,scale,maxField);
390 Warning("SetField","Invalid map %d\n",version);
394 //_____________________________________________________________________________
395 void AliRun::FillTree()
398 // Fills all AliRun TTrees
400 if (fTreeK) fTreeK->Fill();
401 if (fTreeH) fTreeH->Fill();
402 if (fTreeD) fTreeD->Fill();
403 if (fTreeR) fTreeR->Fill();
406 //_____________________________________________________________________________
407 void AliRun::FinishPrimary()
410 // Called at the end of each primary track
413 // static Int_t count=0;
414 // const Int_t times=10;
415 // This primary is finished, purify stack
418 // Write out hits if any
419 if (gAlice->TreeH()) {
420 gAlice->TreeH()->Fill();
427 // if(++count%times==1) gObjectTable->Print();
430 //_____________________________________________________________________________
431 void AliRun::FinishEvent()
434 // Called at the end of the event.
438 if(fLego) fLego->FinishEvent();
440 //Update the energy deposit tables
442 for(i=0;i<fEventEnergy.GetSize();i++) {
443 fSummEnergy[i]+=fEventEnergy[i];
444 fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
446 fEventEnergy.Reset();
448 // Clean detector information
451 // Write out the kinematics
457 // Write out the digits
463 // Write out reconstructed clusters
468 // Write out the event Header information
469 if (fTreeE) fTreeE->Fill();
474 // Write Tree headers
475 // Int_t ievent = fHeader.GetEvent();
477 // sprintf(hname,"TreeK%d",ievent);
478 if (fTreeK) fTreeK->Write();
479 // sprintf(hname,"TreeH%d",ievent);
480 if (fTreeH) fTreeH->Write();
481 // sprintf(hname,"TreeD%d",ievent);
482 if (fTreeD) fTreeD->Write();
483 // sprintf(hname,"TreeR%d",ievent);
484 if (fTreeR) fTreeR->Write();
489 //_____________________________________________________________________________
490 void AliRun::FinishRun()
493 // Called at the end of the run.
497 if(fLego) fLego->FinishRun();
499 // Clean detector information
500 TIter next(fModules);
502 while((detector = (AliModule*)next())) {
503 detector->FinishRun();
506 //Output energy summary tables
509 // file is retrieved from whatever tree
511 if (fTreeK) File = fTreeK->GetCurrentFile();
512 if ((!File) && (fTreeH)) File = fTreeH->GetCurrentFile();
513 if ((!File) && (fTreeD)) File = fTreeD->GetCurrentFile();
514 if ((!File) && (fTreeE)) File = fTreeE->GetCurrentFile();
516 Error("FinishRun","There isn't root file!");
522 // Clean tree information
523 delete fTreeK; fTreeK = 0;
524 delete fTreeH; fTreeH = 0;
525 delete fTreeD; fTreeD = 0;
526 delete fTreeR; fTreeR = 0;
527 delete fTreeE; fTreeE = 0;
529 // Write AliRun info and all detectors parameters
536 //_____________________________________________________________________________
537 void AliRun::FlagTrack(Int_t track)
540 // Flags a track and all its family tree to be kept
547 particle=(TParticle*)fParticles->UncheckedAt(curr);
549 // If the particle is flagged the three from here upward is saved already
550 if(particle->TestBit(Keep_Bit)) return;
552 // Save this particle
553 particle->SetBit(Keep_Bit);
555 // Move to father if any
556 if((curr=particle->GetFirstMother())==-1) return;
560 //_____________________________________________________________________________
561 void AliRun::EnergySummary()
564 // Print summary of deposited energy
570 Int_t kn, i, left, j, id;
571 const Float_t zero=0;
572 Int_t ievent=fHeader.GetEvent()+1;
574 // Energy loss information
576 printf("***************** Energy Loss Information per event (GEV) *****************\n");
577 for(kn=1;kn<fEventEnergy.GetSize();kn++) {
580 fEventEnergy[ndep]=kn;
585 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,zero))/ed;
588 fSummEnergy[ndep]=ed;
589 fSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,zero));
594 for(kn=0;kn<(ndep-1)/3+1;kn++) {
596 for(i=0;i<(3<left?3:left);i++) {
598 id=Int_t (fEventEnergy[j]+0.1);
599 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]);
604 // Relative energy loss in different detectors
605 printf("******************** Relative Energy Loss per event ********************\n");
606 printf("Total energy loss per event %10.3f GeV\n",edtot);
607 for(kn=0;kn<(ndep-1)/5+1;kn++) {
609 for(i=0;i<(5<left?5:left);i++) {
611 id=Int_t (fEventEnergy[j]+0.1);
612 printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot);
616 for(kn=0;kn<75;kn++) printf("*");
620 // Reset the TArray's
621 // fEventEnergy.Set(0);
622 // fSummEnergy.Set(0);
623 // fSum2Energy.Set(0);
626 //_____________________________________________________________________________
627 AliModule *AliRun::GetModule(const char *name)
630 // Return pointer to detector from name
632 return (AliModule*)fModules->FindObject(name);
635 //_____________________________________________________________________________
636 AliDetector *AliRun::GetDetector(const char *name)
639 // Return pointer to detector from name
641 return (AliDetector*)fModules->FindObject(name);
644 //_____________________________________________________________________________
645 Int_t AliRun::GetModuleID(const char *name)
648 // Return galice internal detector identifier from name
651 TObject *mod=fModules->FindObject(name);
652 if(mod) i=fModules->IndexOf(mod);
656 //_____________________________________________________________________________
657 Int_t AliRun::GetEvent(Int_t event)
660 // Connect the Trees Kinematics and Hits for event # event
661 // Set branch addresses
664 // Reset existing structures
669 // Delete Trees already connected
670 if (fTreeK) delete fTreeK;
671 if (fTreeH) delete fTreeH;
672 if (fTreeD) delete fTreeD;
673 if (fTreeR) delete fTreeR;
675 // Get header from file
676 if(fTreeE) fTreeE->GetEntry(event);
677 else Error("GetEvent","Cannot file Header Tree\n");
679 // Get Kine Tree from file
681 sprintf(treeName,"TreeK%d",event);
682 fTreeK = (TTree*)gDirectory->Get(treeName);
683 if (fTreeK) fTreeK->SetBranchAddress("Particles", &fParticles);
684 else Error("GetEvent","cannot find Kine Tree for event:%d\n",event);
686 // Get Hits Tree header from file
687 sprintf(treeName,"TreeH%d",event);
688 fTreeH = (TTree*)gDirectory->Get(treeName);
690 Error("GetEvent","cannot find Hits Tree for event:%d\n",event);
693 // Get Digits Tree header from file
694 sprintf(treeName,"TreeD%d",event);
695 fTreeD = (TTree*)gDirectory->Get(treeName);
697 Warning("GetEvent","cannot find Digits Tree for event:%d\n",event);
701 // Get Reconstruct Tree header from file
702 sprintf(treeName,"TreeR%d",event);
703 fTreeR = (TTree*)gDirectory->Get(treeName);
705 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
708 // Set Trees branch addresses
709 TIter next(fModules);
711 while((detector = (AliModule*)next())) {
712 detector->SetTreeAddress();
715 if (fTreeK) fTreeK->GetEvent(0);
716 fNtrack = Int_t (fParticles->GetEntries());
720 //_____________________________________________________________________________
721 TGeometry *AliRun::GetGeometry()
724 // Import Alice geometry from current file
725 // Return pointer to geometry object
727 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
729 // Unlink and relink nodes in detectors
730 // This is bad and there must be a better way...
733 TIter next(fModules);
735 while((detector = (AliModule*)next())) {
736 detector->SetTreeAddress();
737 TList *dnodes=detector->Nodes();
740 for ( j=0; j<dnodes->GetSize(); j++) {
741 node = (TNode*) dnodes->At(j);
742 node1 = fGeometry->GetNode(node->GetName());
743 dnodes->Remove(node);
744 dnodes->AddAt(node1,j);
750 //_____________________________________________________________________________
751 void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
752 Float_t &e, Float_t *vpos, Float_t *polar,
756 // Return next track from stack of particles
761 for(Int_t i=fNtrack-1; i>=0; i--) {
762 track=(TParticle*) fParticles->UncheckedAt(i);
763 if(!track->TestBit(Done_Bit)) {
765 // The track has not yet been processed
767 ipart=track->GetPdgCode();
775 track->GetPolarisation(pol);
780 track->SetBit(Done_Bit);
786 // stop and start timer when we start a primary track
787 Int_t nprimaries = fHeader.GetNprimary();
788 if (fCurrent >= nprimaries) return;
789 if (fCurrent < nprimaries-1) {
791 track=(TParticle*) fParticles->UncheckedAt(fCurrent+1);
792 // track->SetProcessTime(fTimer.CpuTime());
797 //_____________________________________________________________________________
798 Int_t AliRun::GetPrimary(Int_t track)
801 // return number of primary that has generated track
809 part = (TParticle *)fParticles->UncheckedAt(current);
810 parent=part->GetFirstMother();
811 if(parent<0) return current;
815 //_____________________________________________________________________________
816 void AliRun::InitMC(const char *setup)
819 // Initialize the Alice setup
822 gROOT->LoadMacro(setup);
823 gInterpreter->ProcessLine(fConfigFunction.Data());
825 gMC->DefineParticles(); //Create standard MC particles
827 TObject *objfirst, *objlast;
829 fNdets = fModules->GetLast()+1;
832 //=================Create Materials and geometry
835 TIter next(fModules);
837 while((detector = (AliModule*)next())) {
838 detector->SetTreeAddress();
839 objlast = gDirectory->GetList()->Last();
841 // Add Detector histograms in Detector list of histograms
842 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
843 else objfirst = gDirectory->GetList()->First();
845 detector->Histograms()->Add(objfirst);
846 objfirst = gDirectory->GetList()->After(objfirst);
849 SetTransPar(); //Read the cuts for all materials
851 MediaTable(); //Build the special IMEDIA table
853 //Initialise geometry deposition table
854 fEventEnergy.Set(gMC->NofVolumes()+1);
855 fSummEnergy.Set(gMC->NofVolumes()+1);
856 fSum2Energy.Set(gMC->NofVolumes()+1);
858 //Compute cross-sections
861 //Write Geometry object to current file.
867 //_____________________________________________________________________________
868 void AliRun::MediaTable()
871 // Built media table to get from the media number to
874 Int_t kz, nz, idt, lz, i, k, ind;
876 TObjArray &dets = *gAlice->Detectors();
880 for (kz=0;kz<fNdets;kz++) {
881 // If detector is defined
882 if((det=(AliModule*) dets[kz])) {
883 TArrayI &idtmed = *(det->GetIdtmed());
884 for(nz=0;nz<100;nz++) {
885 // Find max and min material number
886 if((idt=idtmed[nz])) {
887 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
888 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
891 if(det->LoMedium() > det->HiMedium()) {
895 if(det->HiMedium() > fImedia->GetSize()) {
896 Error("MediaTable","Increase fImedia from %d to %d",
897 fImedia->GetSize(),det->HiMedium());
900 // Tag all materials in rage as belonging to detector kz
901 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
908 // Print summary table
909 printf(" Traking media ranges:\n");
910 for(i=0;i<(fNdets-1)/6+1;i++) {
911 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
913 det=(AliModule*)dets[ind];
915 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
918 printf(" %6s: %3d -> %3d;","NULL",0,0);
924 //____________________________________________________________________________
925 void AliRun::SetGenerator(AliGenerator *generator)
928 // Load the event generator
930 if(!fGenerator) fGenerator = generator;
933 //____________________________________________________________________________
934 void AliRun::ResetGenerator(AliGenerator *generator)
937 // Load the event generator
940 Warning("ResetGenerator","Replacing generator %s with %s\n",
941 fGenerator->GetName(),generator->GetName());
942 fGenerator = generator;
945 //____________________________________________________________________________
946 void AliRun::SetTransPar(char* filename)
949 // Read filename to set the transport parameters
953 const Int_t ncuts=10;
954 const Int_t nflags=11;
955 const Int_t npars=ncuts+nflags;
956 const char pars[npars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
957 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
958 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
959 "MULS","PAIR","PHOT","RAYL"};
965 Int_t i, itmed, iret, ktmed, kz;
968 // See whether the file is there
969 filtmp=gSystem->ExpandPathName(filename);
970 lun=fopen(filtmp,"r");
973 Warning("SetTransPar","File %s does not exist!\n",filename);
977 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
978 printf(" *%59s\n","*");
979 printf(" * Please check carefully what you are doing!%10s\n","*");
980 printf(" *%59s\n","*");
983 // Initialise cuts and flags
984 for(i=0;i<ncuts;i++) cut[i]=-99;
985 for(i=0;i<nflags;i++) flag[i]=-99;
987 for(i=0;i<256;i++) line[i]='\0';
988 // Read up to the end of line excluded
989 iret=fscanf(lun,"%[^\n]",line);
993 printf(" *%59s\n","*");
994 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
997 // Read the end of line
1000 if(line[0]=='*') continue;
1002 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",
1003 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
1004 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
1005 &flag[8],&flag[9],&flag[10]);
1009 Warning("SetTransPar","Error reading file %s\n",filename);
1012 // Check that the module exist
1013 AliModule *mod = GetModule(detName);
1015 // Get the array of media numbers
1016 TArrayI &idtmed = *mod->GetIdtmed();
1017 // Check that the tracking medium code is valid
1018 if(0<=itmed && itmed < 100) {
1019 ktmed=idtmed[itmed];
1021 Warning("SetTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
1024 // Set energy thresholds
1025 for(kz=0;kz<ncuts;kz++) {
1027 printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
1028 pars[kz],cut[kz],itmed,mod->GetName());
1029 gMC->Gstpar(ktmed,pars[kz],cut[kz]);
1032 // Set transport mechanisms
1033 for(kz=0;kz<nflags;kz++) {
1035 printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
1036 pars[ncuts+kz],flag[kz],itmed,mod->GetName());
1037 gMC->Gstpar(ktmed,pars[ncuts+kz],Float_t(flag[kz]));
1041 Warning("SetTransPar","Invalid medium code %d *\n",itmed);
1045 Warning("SetTransPar","Module %s not present\n",detName);
1051 //_____________________________________________________________________________
1052 void AliRun::MakeTree(Option_t *option)
1055 // Create the ROOT trees
1056 // Loop on all detectors to create the Root branch (if any)
1062 char *K = strstr(option,"K");
1063 char *H = strstr(option,"H");
1064 char *E = strstr(option,"E");
1065 char *D = strstr(option,"D");
1066 char *R = strstr(option,"R");
1069 sprintf(hname,"TreeK%d",fEvent);
1070 fTreeK = new TTree(hname,"Kinematics");
1071 // Create a branch for particles
1072 fTreeK->Branch("Particles",&fParticles,4000);
1075 sprintf(hname,"TreeH%d",fEvent);
1076 fTreeH = new TTree(hname,"Hits");
1077 fTreeH->SetAutoSave(1000000000); //no autosave
1080 sprintf(hname,"TreeD%d",fEvent);
1081 fTreeD = new TTree(hname,"Digits");
1084 sprintf(hname,"TreeR%d",fEvent);
1085 fTreeR = new TTree(hname,"Reconstruction");
1088 fTreeE = new TTree("TE","Header");
1089 // Create a branch for Header
1090 fTreeE->Branch("Header","AliHeader",&header,4000);
1093 // Create a branch for hits/digits for each detector
1094 // Each branch is a TClonesArray. Each data member of the Hits classes
1095 // will be in turn a subbranch of the detector master branch
1096 TIter next(fModules);
1097 AliModule *detector;
1098 while((detector = (AliModule*)next())) {
1099 if (H || D || R) detector->MakeBranch(option);
1103 //_____________________________________________________________________________
1104 Int_t AliRun::PurifyKine(Int_t lastSavedTrack, Int_t nofTracks)
1107 // PurifyKine with external parameters
1109 fHgwmk = lastSavedTrack;
1110 fNtrack = nofTracks;
1115 //_____________________________________________________________________________
1116 void AliRun::PurifyKine()
1119 // Compress kinematic tree keeping only flagged particles
1120 // and renaming the particle id's in all the hits
1122 TClonesArray &particles = *fParticles;
1123 int nkeep=fHgwmk+1, parent, i;
1124 TParticle *part, *partnew, *father;
1125 int *map = new int[particles.GetEntries()];
1127 // Save in Header total number of tracks before compression
1128 fHeader.SetNtrack(fHeader.GetNtrack()+fNtrack-fHgwmk);
1130 // Preset map, to be removed later
1131 for(i=0; i<fNtrack; i++) {
1132 if(i<=fHgwmk) map[i]=i ; else map[i] = -99 ;}
1133 // Second pass, build map between old and new numbering
1134 for(i=fHgwmk+1; i<fNtrack; i++) {
1135 part = (TParticle *)particles.UncheckedAt(i);
1136 if(part->TestBit(Keep_Bit)) {
1138 // This particle has to be kept
1142 // Old and new are different, have to copy
1143 partnew = (TParticle *)particles.UncheckedAt(nkeep);
1144 // Change due to a bug in the HP compiler
1145 // *partnew = *part;
1146 memcpy(partnew,part,sizeof(TParticle));
1147 } else partnew = part;
1149 // as the parent is always *before*, it must be already
1150 // in place. This is what we are checking anyway!
1151 if((parent=partnew->GetFirstMother())>fHgwmk) {
1152 if(map[parent]==-99) printf("map[%d] = -99!\n",parent);
1153 partnew->SetFirstMother(map[parent]);
1160 // Fix daughters information
1161 for (i=0; i<fNtrack; i++) {
1162 part = (TParticle *)particles.UncheckedAt(i);
1163 parent = part->GetFirstMother();
1165 father = (TParticle *)particles.UncheckedAt(parent);
1166 if(father->TestBit(Daughters_Bit)) {
1168 if(i<father->GetFirstDaughter()) father->SetFirstDaughter(i);
1169 if(i>father->GetLastDaughter()) father->SetLastDaughter(i);
1171 // Iitialise daughters info for first pass
1172 father->SetFirstDaughter(i);
1173 father->SetLastDaughter(i);
1174 father->SetBit(Daughters_Bit);
1180 // Now loop on all detectors and reset the hits
1182 TIter next(fModules);
1183 AliModule *detector;
1184 while((detector = (AliModule*)next())) {
1185 if (!detector->Hits()) continue;
1186 TClonesArray &vHits=*(detector->Hits());
1187 if(vHits.GetEntries() != detector->GetNhits())
1188 printf("vHits.GetEntries()!=detector->GetNhits(): %d != %d\n",
1189 vHits.GetEntries(),detector->GetNhits());
1190 for (i=0; i<detector->GetNhits(); i++) {
1191 OneHit = (AliHit *)vHits.UncheckedAt(i);
1192 OneHit->SetTrack(map[OneHit->GetTrack()]);
1197 // Now loop on all registered hit lists
1198 TIter next(fHitLists);
1199 TCollection *hitList;
1200 while((hitList = (TCollection*)next())) {
1201 TIter nexthit(hitList);
1203 while((hit = (AliHit*)nexthit())) {
1204 hit->SetTrack(map[hit->GetTrack()]);
1210 particles.SetLast(fHgwmk);
1214 //_____________________________________________________________________________
1215 void AliRun::BeginEvent()
1218 // Reset all Detectors & kinematics & trees
1225 fLego->BeginEvent();
1234 // Initialise event header
1235 fHeader.Reset(fRun,fEvent);
1239 sprintf(hname,"TreeK%d",fEvent);
1240 fTreeK->SetName(hname);
1244 sprintf(hname,"TreeH%d",fEvent);
1245 fTreeH->SetName(hname);
1249 sprintf(hname,"TreeD%d",fEvent);
1250 fTreeD->SetName(hname);
1254 sprintf(hname,"TreeR%d",fEvent);
1255 fTreeR->SetName(hname);
1259 //_____________________________________________________________________________
1260 void AliRun::ResetDigits()
1263 // Reset all Detectors digits
1265 TIter next(fModules);
1266 AliModule *detector;
1267 while((detector = (AliModule*)next())) {
1268 detector->ResetDigits();
1272 //_____________________________________________________________________________
1273 void AliRun::ResetHits()
1276 // Reset all Detectors hits
1278 TIter next(fModules);
1279 AliModule *detector;
1280 while((detector = (AliModule*)next())) {
1281 detector->ResetHits();
1285 //_____________________________________________________________________________
1286 void AliRun::ResetPoints()
1289 // Reset all Detectors points
1291 TIter next(fModules);
1292 AliModule *detector;
1293 while((detector = (AliModule*)next())) {
1294 detector->ResetPoints();
1298 //_____________________________________________________________________________
1299 void AliRun::RunMC(Int_t nevent, const char *setup)
1302 // Main function to be called to process a galice run
1304 // Root > gAlice.Run();
1305 // a positive number of events will cause the finish routine
1309 // check if initialisation has been done
1310 if (!fInitDone) InitMC(setup);
1312 // Create the Root Tree with one branch per detector
1315 gMC->ProcessRun(nevent);
1317 // End of this run, close files
1318 if(nevent>0) FinishRun();
1321 //_____________________________________________________________________________
1322 void AliRun::RunLego(const char *setup,Int_t ntheta,Float_t themin,
1323 Float_t themax,Int_t nphi,Float_t phimin,Float_t phimax,
1324 Float_t rmin,Float_t rmax,Float_t zmax)
1327 // Generates lego plots of:
1328 // - radiation length map phi vs theta
1329 // - radiation length map phi vs eta
1330 // - interaction length map
1331 // - g/cm2 length map
1333 // ntheta bins in theta, eta
1334 // themin minimum angle in theta (degrees)
1335 // themax maximum angle in theta (degrees)
1337 // phimin minimum angle in phi (degrees)
1338 // phimax maximum angle in phi (degrees)
1339 // rmin minimum radius
1340 // rmax maximum radius
1343 // The number of events generated = ntheta*nphi
1344 // run input parameters in macro setup (default="Config.C")
1346 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1349 <img src="picts/AliRunLego1.gif">
1354 <img src="picts/AliRunLego2.gif">
1359 <img src="picts/AliRunLego3.gif">
1364 // check if initialisation has been done
1365 if (!fInitDone) InitMC(setup);
1367 //Create Lego object
1368 fLego = new AliLego("lego",ntheta,themin,themax,nphi,phimin,phimax,rmin,rmax,zmax);
1370 //Prepare MC for Lego Run
1374 gMC->ProcessRun(ntheta*nphi+1);
1376 // Create only the Root event Tree
1379 // End of this run, close files
1383 //_____________________________________________________________________________
1384 void AliRun::SetCurrentTrack(Int_t track)
1387 // Set current track number
1392 //_____________________________________________________________________________
1393 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1394 Float_t *vpos, Float_t *polar, Float_t tof,
1395 const char *mecha, Int_t &ntr, Float_t weight)
1398 // Load a track on the stack
1400 // done 0 if the track has to be transported
1402 // parent identifier of the parent track. -1 for a primary
1403 // pdg particle code
1404 // pmom momentum GeV/c
1406 // polar polarisation
1407 // tof time of flight in seconds
1408 // mecha production mechanism
1409 // ntr on output the number of the track stored
1411 TClonesArray &particles = *fParticles;
1412 TParticle *particle;
1414 const Int_t firstdaughter=-1;
1415 const Int_t lastdaughter=-1;
1417 // const Float_t tlife=0;
1420 // Here we get the static mass
1421 // For MC is ok, but a more sophisticated method could be necessary
1422 // if the calculated mass is required
1423 // also, this method is potentially dangerous if the mass
1424 // used in the MC is not the same of the PDG database
1426 mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
1427 Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+
1428 pmom[1]*pmom[1]+pmom[2]*pmom[2]);
1430 //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",
1431 //pname,mass,e,fNtrack,pdg,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],KS,mecha);
1433 particle=new(particles[fNtrack]) TParticle(pdg,KS,parent,-1,firstdaughter,
1434 lastdaughter,pmom[0],pmom[1],pmom[2],
1435 e,vpos[0],vpos[1],vpos[2],tof);
1436 // polar[0],polar[1],polar[2],tof,
1438 ((TParticle*)particles[fNtrack])->SetPolarisation(TVector3(polar[0],polar[1],polar[2]));
1439 ((TParticle*)particles[fNtrack])->SetWeight(weight);
1440 if(!done) particle->SetBit(Done_Bit);
1443 particle=(TParticle*) fParticles->UncheckedAt(parent);
1444 particle->SetLastDaughter(fNtrack);
1445 if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack);
1448 // This is a primary track. Set high water mark for this event
1451 // Set also number if primary tracks
1452 fHeader.SetNprimary(fHgwmk+1);
1453 fHeader.SetNtrack(fHgwmk+1);
1458 //_____________________________________________________________________________
1459 void AliRun::KeepTrack(const Int_t track)
1462 // flags a track to be kept
1464 TClonesArray &particles = *fParticles;
1465 ((TParticle*)particles[track])->SetBit(Keep_Bit);
1468 //_____________________________________________________________________________
1469 void AliRun::StepManager(Int_t id)
1472 // Called at every step during transport
1476 // --- If lego option, do it and leave
1478 fLego->StepManager();
1481 //Update energy deposition tables
1482 AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
1484 //Call the appropriate stepping routine;
1485 AliModule *det = (AliModule*)fModules->At(id);
1486 if(det) det->StepManager();
1490 //_____________________________________________________________________________
1491 void AliRun::Streamer(TBuffer &R__b)
1494 // Stream an object of class AliRun.
1496 if (R__b.IsReading()) {
1497 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1498 TNamed::Streamer(R__b);
1499 if (!gAlice) gAlice = this;
1500 gROOT->GetListOfBrowsables()->Add(this,"Run");
1501 fTreeE = (TTree*)gDirectory->Get("TE");
1502 if (fTreeE) fTreeE->SetBranchAddress("Header", &header);
1503 else Error("Streamer","cannot find Header Tree\n");
1507 fHeader.Streamer(R__b);
1517 R__b >> fPDGDB; //Particle factory object!
1518 fTreeE->GetEntry(0);
1520 fHeader.SetEvent(0);
1521 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
1524 fConfigFunction.Streamer(R__b);
1526 fConfigFunction="Config();";
1529 R__b.WriteVersion(AliRun::IsA());
1530 TNamed::Streamer(R__b);
1534 fHeader.Streamer(R__b);
1543 R__b << fPDGDB; //Particle factory object!
1544 fConfigFunction.Streamer(R__b);