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.32 2000/04/27 10:38:21 fca
19 Correct termination of Lego Run and introduce Lego getter in AliRun
21 Revision 1.31 2000/04/26 10:17:32 fca
22 Changes in Lego for G4 compatibility
24 Revision 1.30 2000/04/18 19:11:40 fca
25 Introduce variable Config.C function signature
27 Revision 1.29 2000/04/07 11:12:34 fca
28 G4 compatibility changes
30 Revision 1.28 2000/04/05 06:51:06 fca
31 Workaround for an HP compiler problem
33 Revision 1.27 2000/03/22 18:08:07 fca
34 Rationalisation of the virtual MC interfaces
36 Revision 1.26 2000/03/22 13:42:26 fca
37 SetGenerator does not replace an existing generator, ResetGenerator does
39 Revision 1.25 2000/02/23 16:25:22 fca
40 AliVMC and AliGeant3 classes introduced
41 ReadEuclid moved from AliRun to AliModule
43 Revision 1.24 2000/01/19 17:17:20 fca
44 Introducing a list of lists of hits -- more hits allowed for detector now
46 Revision 1.23 1999/12/03 11:14:31 fca
47 Fixing previous wrong checking
49 Revision 1.21 1999/11/25 10:40:08 fca
50 Fixing daughters information also in primary tracks
52 Revision 1.20 1999/10/04 18:08:49 fca
53 Adding protection against inconsistent Euclid files
55 Revision 1.19 1999/09/29 07:50:40 fca
56 Introduction of the Copyright and cvs Log
60 ///////////////////////////////////////////////////////////////////////////////
62 // Control class for Alice C++ //
63 // Only one single instance of this class exists. //
64 // The object is created in main program aliroot //
65 // and is pointed by the global gAlice. //
67 // -Supports the list of all Alice Detectors (fModules). //
68 // -Supports the list of particles (fParticles). //
69 // -Supports the Trees. //
70 // -Supports the geometry. //
71 // -Supports the event display. //
74 <img src="picts/AliRunClass.gif">
79 <img src="picts/alirun.gif">
83 ///////////////////////////////////////////////////////////////////////////////
91 #include <TObjectTable.h>
93 #include "TParticle.h"
95 #include "AliDisplay.h"
105 static AliHeader *header;
109 //_____________________________________________________________________________
113 // Default constructor for AliRun
137 fPDGDB = 0; //Particle factory object!
139 fConfigFunction = "\0";
142 //_____________________________________________________________________________
143 AliRun::AliRun(const char *name, const char *title)
147 // Constructor for the main processor.
148 // Creates the geometry
149 // Creates the list of Detectors.
150 // Creates the list of particles.
166 fConfigFunction = "Config();";
168 gROOT->GetListOfBrowsables()->Add(this,name);
170 // create the support list for the various Detectors
171 fModules = new TObjArray(77);
173 // Create the TNode geometry for the event display
175 BuildSimpleGeometry();
185 // Create the particle stack
186 fParticles = new TClonesArray("TParticle",100);
190 // Create default mag field
195 // Prepare the tracking medium lists
196 fImedia = new TArrayI(1000);
197 for(i=0;i<1000;i++) (*fImedia)[i]=-99;
200 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
202 // Create HitLists list
203 fHitLists = new TList();
206 //_____________________________________________________________________________
210 // Defaullt AliRun destructor
229 fParticles->Delete();
235 //_____________________________________________________________________________
236 void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
239 // Add a hit to detector id
241 TObjArray &dets = *fModules;
242 if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits);
245 //_____________________________________________________________________________
246 void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
249 // Add digit to detector id
251 TObjArray &dets = *fModules;
252 if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits);
255 //_____________________________________________________________________________
256 void AliRun::Browse(TBrowser *b)
259 // Called when the item "Run" is clicked on the left pane
260 // of the Root browser.
261 // It displays the Root Trees and all detectors.
263 if (fTreeK) b->Add(fTreeK,fTreeK->GetName());
264 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
265 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
266 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
267 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
269 TIter next(fModules);
271 while((detector = (AliModule*)next())) {
272 b->Add(detector,detector->GetName());
276 //_____________________________________________________________________________
280 // Initialize Alice geometry
285 //_____________________________________________________________________________
286 void AliRun::BuildSimpleGeometry()
289 // Create a simple TNode geometry used by Root display engine
291 // Initialise geometry
293 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
294 new TMaterial("void","Vacuum",0,0,0); //Everything is void
295 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
296 brik->SetVisibility(0);
297 new TNode("alice","alice","S_alice");
300 //_____________________________________________________________________________
301 void AliRun::CleanDetectors()
304 // Clean Detectors at the end of event
306 TIter next(fModules);
308 while((detector = (AliModule*)next())) {
309 detector->FinishEvent();
313 //_____________________________________________________________________________
314 void AliRun::CleanParents()
317 // Clean Particles stack.
318 // Set parent/daughter relations
320 TClonesArray &particles = *(gAlice->Particles());
323 for(i=0; i<fNtrack; i++) {
324 part = (TParticle *)particles.UncheckedAt(i);
325 if(!part->TestBit(Daughters_Bit)) {
326 part->SetFirstDaughter(-1);
327 part->SetLastDaughter(-1);
332 //_____________________________________________________________________________
333 Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
336 // Return the distance from the mouse to the AliRun object
342 //_____________________________________________________________________________
343 void AliRun::DumpPart (Int_t i)
346 // Dumps particle i in the stack
348 TClonesArray &particles = *fParticles;
349 ((TParticle*) particles[i])->Print();
352 //_____________________________________________________________________________
353 void AliRun::DumpPStack ()
356 // Dumps the particle stack
358 TClonesArray &particles = *fParticles;
360 "\n\n=======================================================================\n");
361 for (Int_t i=0;i<fNtrack;i++)
363 printf("-> %d ",i); ((TParticle*) particles[i])->Print();
364 printf("--------------------------------------------------------------\n");
367 "\n=======================================================================\n\n");
370 //_____________________________________________________________________________
371 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
372 Float_t maxField, char* filename)
375 // Set magnetic field parameters
376 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
377 // version Magnetic field map version (only 1 active now)
378 // scale Scale factor for the magnetic field
379 // maxField Maximum value for the magnetic field
382 // --- Sanity check on mag field flags
383 if(type<0 || type > 2) {
385 "Invalid magnetic field flag: %5d; Helix tracking chosen instead\n"
389 if(fField) delete fField;
391 fField = new AliMagFC("Map1"," ",type,version,scale,maxField);
392 } else if(version<=3) {
393 fField = new AliMagFCM("Map2-3",filename,type,version,scale,maxField);
396 Warning("SetField","Invalid map %d\n",version);
400 //_____________________________________________________________________________
401 void AliRun::FillTree()
404 // Fills all AliRun TTrees
406 if (fTreeK) fTreeK->Fill();
407 if (fTreeH) fTreeH->Fill();
408 if (fTreeD) fTreeD->Fill();
409 if (fTreeR) fTreeR->Fill();
412 //_____________________________________________________________________________
413 void AliRun::FinishPrimary()
416 // Called at the end of each primary track
419 // static Int_t count=0;
420 // const Int_t times=10;
421 // This primary is finished, purify stack
424 // Write out hits if any
425 if (gAlice->TreeH()) {
426 gAlice->TreeH()->Fill();
433 // if(++count%times==1) gObjectTable->Print();
436 //_____________________________________________________________________________
437 void AliRun::FinishEvent()
440 // Called at the end of the event.
444 if(fLego) fLego->FinishEvent();
446 //Update the energy deposit tables
448 for(i=0;i<fEventEnergy.GetSize();i++) {
449 fSummEnergy[i]+=fEventEnergy[i];
450 fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
452 fEventEnergy.Reset();
454 // Clean detector information
457 // Write out the kinematics
463 // Write out the digits
469 // Write out reconstructed clusters
474 // Write out the event Header information
475 if (fTreeE) fTreeE->Fill();
480 // Write Tree headers
481 // Int_t ievent = fHeader.GetEvent();
483 // sprintf(hname,"TreeK%d",ievent);
484 if (fTreeK) fTreeK->Write();
485 // sprintf(hname,"TreeH%d",ievent);
486 if (fTreeH) fTreeH->Write();
487 // sprintf(hname,"TreeD%d",ievent);
488 if (fTreeD) fTreeD->Write();
489 // sprintf(hname,"TreeR%d",ievent);
490 if (fTreeR) fTreeR->Write();
495 //_____________________________________________________________________________
496 void AliRun::FinishRun()
499 // Called at the end of the run.
503 if(fLego) fLego->FinishRun();
505 // Clean detector information
506 TIter next(fModules);
508 while((detector = (AliModule*)next())) {
509 detector->FinishRun();
512 //Output energy summary tables
515 // file is retrieved from whatever tree
517 if (fTreeK) File = fTreeK->GetCurrentFile();
518 if ((!File) && (fTreeH)) File = fTreeH->GetCurrentFile();
519 if ((!File) && (fTreeD)) File = fTreeD->GetCurrentFile();
520 if ((!File) && (fTreeE)) File = fTreeE->GetCurrentFile();
522 Error("FinishRun","There isn't root file!");
528 // Clean tree information
529 delete fTreeK; fTreeK = 0;
530 delete fTreeH; fTreeH = 0;
531 delete fTreeD; fTreeD = 0;
532 delete fTreeR; fTreeR = 0;
533 delete fTreeE; fTreeE = 0;
535 // Write AliRun info and all detectors parameters
542 //_____________________________________________________________________________
543 void AliRun::FlagTrack(Int_t track)
546 // Flags a track and all its family tree to be kept
553 particle=(TParticle*)fParticles->UncheckedAt(curr);
555 // If the particle is flagged the three from here upward is saved already
556 if(particle->TestBit(Keep_Bit)) return;
558 // Save this particle
559 particle->SetBit(Keep_Bit);
561 // Move to father if any
562 if((curr=particle->GetFirstMother())==-1) return;
566 //_____________________________________________________________________________
567 void AliRun::EnergySummary()
570 // Print summary of deposited energy
576 Int_t kn, i, left, j, id;
577 const Float_t zero=0;
578 Int_t ievent=fHeader.GetEvent()+1;
580 // Energy loss information
582 printf("***************** Energy Loss Information per event (GEV) *****************\n");
583 for(kn=1;kn<fEventEnergy.GetSize();kn++) {
586 fEventEnergy[ndep]=kn;
591 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,zero))/ed;
594 fSummEnergy[ndep]=ed;
595 fSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,zero));
600 for(kn=0;kn<(ndep-1)/3+1;kn++) {
602 for(i=0;i<(3<left?3:left);i++) {
604 id=Int_t (fEventEnergy[j]+0.1);
605 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]);
610 // Relative energy loss in different detectors
611 printf("******************** Relative Energy Loss per event ********************\n");
612 printf("Total energy loss per event %10.3f GeV\n",edtot);
613 for(kn=0;kn<(ndep-1)/5+1;kn++) {
615 for(i=0;i<(5<left?5:left);i++) {
617 id=Int_t (fEventEnergy[j]+0.1);
618 printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot);
622 for(kn=0;kn<75;kn++) printf("*");
626 // Reset the TArray's
627 // fEventEnergy.Set(0);
628 // fSummEnergy.Set(0);
629 // fSum2Energy.Set(0);
632 //_____________________________________________________________________________
633 AliModule *AliRun::GetModule(const char *name)
636 // Return pointer to detector from name
638 return (AliModule*)fModules->FindObject(name);
641 //_____________________________________________________________________________
642 AliDetector *AliRun::GetDetector(const char *name)
645 // Return pointer to detector from name
647 return (AliDetector*)fModules->FindObject(name);
650 //_____________________________________________________________________________
651 Int_t AliRun::GetModuleID(const char *name)
654 // Return galice internal detector identifier from name
657 TObject *mod=fModules->FindObject(name);
658 if(mod) i=fModules->IndexOf(mod);
662 //_____________________________________________________________________________
663 Int_t AliRun::GetEvent(Int_t event)
666 // Connect the Trees Kinematics and Hits for event # event
667 // Set branch addresses
670 // Reset existing structures
675 // Delete Trees already connected
676 if (fTreeK) delete fTreeK;
677 if (fTreeH) delete fTreeH;
678 if (fTreeD) delete fTreeD;
679 if (fTreeR) delete fTreeR;
681 // Get header from file
682 if(fTreeE) fTreeE->GetEntry(event);
683 else Error("GetEvent","Cannot file Header Tree\n");
685 // Get Kine Tree from file
687 sprintf(treeName,"TreeK%d",event);
688 fTreeK = (TTree*)gDirectory->Get(treeName);
689 if (fTreeK) fTreeK->SetBranchAddress("Particles", &fParticles);
690 else Error("GetEvent","cannot find Kine Tree for event:%d\n",event);
692 // Get Hits Tree header from file
693 sprintf(treeName,"TreeH%d",event);
694 fTreeH = (TTree*)gDirectory->Get(treeName);
696 Error("GetEvent","cannot find Hits Tree for event:%d\n",event);
699 // Get Digits Tree header from file
700 sprintf(treeName,"TreeD%d",event);
701 fTreeD = (TTree*)gDirectory->Get(treeName);
703 Warning("GetEvent","cannot find Digits Tree for event:%d\n",event);
707 // Get Reconstruct Tree header from file
708 sprintf(treeName,"TreeR%d",event);
709 fTreeR = (TTree*)gDirectory->Get(treeName);
711 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
714 // Set Trees branch addresses
715 TIter next(fModules);
717 while((detector = (AliModule*)next())) {
718 detector->SetTreeAddress();
721 if (fTreeK) fTreeK->GetEvent(0);
722 fNtrack = Int_t (fParticles->GetEntries());
726 //_____________________________________________________________________________
727 TGeometry *AliRun::GetGeometry()
730 // Import Alice geometry from current file
731 // Return pointer to geometry object
733 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
735 // Unlink and relink nodes in detectors
736 // This is bad and there must be a better way...
739 TIter next(fModules);
741 while((detector = (AliModule*)next())) {
742 detector->SetTreeAddress();
743 TList *dnodes=detector->Nodes();
746 for ( j=0; j<dnodes->GetSize(); j++) {
747 node = (TNode*) dnodes->At(j);
748 node1 = fGeometry->GetNode(node->GetName());
749 dnodes->Remove(node);
750 dnodes->AddAt(node1,j);
756 //_____________________________________________________________________________
757 void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
758 Float_t &e, Float_t *vpos, Float_t *polar,
762 // Return next track from stack of particles
767 for(Int_t i=fNtrack-1; i>=0; i--) {
768 track=(TParticle*) fParticles->UncheckedAt(i);
769 if(!track->TestBit(Done_Bit)) {
771 // The track has not yet been processed
773 ipart=track->GetPdgCode();
781 track->GetPolarisation(pol);
786 track->SetBit(Done_Bit);
792 // stop and start timer when we start a primary track
793 Int_t nprimaries = fHeader.GetNprimary();
794 if (fCurrent >= nprimaries) return;
795 if (fCurrent < nprimaries-1) {
797 track=(TParticle*) fParticles->UncheckedAt(fCurrent+1);
798 // track->SetProcessTime(fTimer.CpuTime());
803 //_____________________________________________________________________________
804 Int_t AliRun::GetPrimary(Int_t track)
807 // return number of primary that has generated track
815 part = (TParticle *)fParticles->UncheckedAt(current);
816 parent=part->GetFirstMother();
817 if(parent<0) return current;
821 //_____________________________________________________________________________
822 void AliRun::InitMC(const char *setup)
825 // Initialize the Alice setup
828 gROOT->LoadMacro(setup);
829 gInterpreter->ProcessLine(fConfigFunction.Data());
831 gMC->DefineParticles(); //Create standard MC particles
833 TObject *objfirst, *objlast;
835 fNdets = fModules->GetLast()+1;
838 //=================Create Materials and geometry
841 TIter next(fModules);
843 while((detector = (AliModule*)next())) {
844 detector->SetTreeAddress();
845 objlast = gDirectory->GetList()->Last();
847 // Add Detector histograms in Detector list of histograms
848 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
849 else objfirst = gDirectory->GetList()->First();
851 detector->Histograms()->Add(objfirst);
852 objfirst = gDirectory->GetList()->After(objfirst);
855 SetTransPar(); //Read the cuts for all materials
857 MediaTable(); //Build the special IMEDIA table
859 //Initialise geometry deposition table
860 fEventEnergy.Set(gMC->NofVolumes()+1);
861 fSummEnergy.Set(gMC->NofVolumes()+1);
862 fSum2Energy.Set(gMC->NofVolumes()+1);
864 //Compute cross-sections
867 //Write Geometry object to current file.
873 //_____________________________________________________________________________
874 void AliRun::MediaTable()
877 // Built media table to get from the media number to
880 Int_t kz, nz, idt, lz, i, k, ind;
882 TObjArray &dets = *gAlice->Detectors();
886 for (kz=0;kz<fNdets;kz++) {
887 // If detector is defined
888 if((det=(AliModule*) dets[kz])) {
889 TArrayI &idtmed = *(det->GetIdtmed());
890 for(nz=0;nz<100;nz++) {
891 // Find max and min material number
892 if((idt=idtmed[nz])) {
893 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
894 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
897 if(det->LoMedium() > det->HiMedium()) {
901 if(det->HiMedium() > fImedia->GetSize()) {
902 Error("MediaTable","Increase fImedia from %d to %d",
903 fImedia->GetSize(),det->HiMedium());
906 // Tag all materials in rage as belonging to detector kz
907 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
914 // Print summary table
915 printf(" Traking media ranges:\n");
916 for(i=0;i<(fNdets-1)/6+1;i++) {
917 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
919 det=(AliModule*)dets[ind];
921 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
924 printf(" %6s: %3d -> %3d;","NULL",0,0);
930 //____________________________________________________________________________
931 void AliRun::SetGenerator(AliGenerator *generator)
934 // Load the event generator
936 if(!fGenerator) fGenerator = generator;
939 //____________________________________________________________________________
940 void AliRun::ResetGenerator(AliGenerator *generator)
943 // Load the event generator
947 Warning("ResetGenerator","Replacing generator %s with %s\n",
948 fGenerator->GetName(),generator->GetName());
950 Warning("ResetGenerator","Replacing generator %s with NULL\n",
951 fGenerator->GetName());
952 fGenerator = generator;
955 //____________________________________________________________________________
956 void AliRun::SetTransPar(char* filename)
959 // Read filename to set the transport parameters
963 const Int_t ncuts=10;
964 const Int_t nflags=11;
965 const Int_t npars=ncuts+nflags;
966 const char pars[npars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
967 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
968 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
969 "MULS","PAIR","PHOT","RAYL"};
975 Int_t i, itmed, iret, ktmed, kz;
978 // See whether the file is there
979 filtmp=gSystem->ExpandPathName(filename);
980 lun=fopen(filtmp,"r");
983 Warning("SetTransPar","File %s does not exist!\n",filename);
987 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
988 printf(" *%59s\n","*");
989 printf(" * Please check carefully what you are doing!%10s\n","*");
990 printf(" *%59s\n","*");
993 // Initialise cuts and flags
994 for(i=0;i<ncuts;i++) cut[i]=-99;
995 for(i=0;i<nflags;i++) flag[i]=-99;
997 for(i=0;i<256;i++) line[i]='\0';
998 // Read up to the end of line excluded
999 iret=fscanf(lun,"%[^\n]",line);
1003 printf(" *%59s\n","*");
1004 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1007 // Read the end of line
1010 if(line[0]=='*') continue;
1012 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",
1013 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
1014 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
1015 &flag[8],&flag[9],&flag[10]);
1019 Warning("SetTransPar","Error reading file %s\n",filename);
1022 // Check that the module exist
1023 AliModule *mod = GetModule(detName);
1025 // Get the array of media numbers
1026 TArrayI &idtmed = *mod->GetIdtmed();
1027 // Check that the tracking medium code is valid
1028 if(0<=itmed && itmed < 100) {
1029 ktmed=idtmed[itmed];
1031 Warning("SetTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
1034 // Set energy thresholds
1035 for(kz=0;kz<ncuts;kz++) {
1037 printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
1038 pars[kz],cut[kz],itmed,mod->GetName());
1039 gMC->Gstpar(ktmed,pars[kz],cut[kz]);
1042 // Set transport mechanisms
1043 for(kz=0;kz<nflags;kz++) {
1045 printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
1046 pars[ncuts+kz],flag[kz],itmed,mod->GetName());
1047 gMC->Gstpar(ktmed,pars[ncuts+kz],Float_t(flag[kz]));
1051 Warning("SetTransPar","Invalid medium code %d *\n",itmed);
1055 Warning("SetTransPar","Module %s not present\n",detName);
1061 //_____________________________________________________________________________
1062 void AliRun::MakeTree(Option_t *option)
1065 // Create the ROOT trees
1066 // Loop on all detectors to create the Root branch (if any)
1072 char *K = strstr(option,"K");
1073 char *H = strstr(option,"H");
1074 char *E = strstr(option,"E");
1075 char *D = strstr(option,"D");
1076 char *R = strstr(option,"R");
1079 sprintf(hname,"TreeK%d",fEvent);
1080 fTreeK = new TTree(hname,"Kinematics");
1081 // Create a branch for particles
1082 fTreeK->Branch("Particles",&fParticles,4000);
1085 sprintf(hname,"TreeH%d",fEvent);
1086 fTreeH = new TTree(hname,"Hits");
1087 fTreeH->SetAutoSave(1000000000); //no autosave
1090 sprintf(hname,"TreeD%d",fEvent);
1091 fTreeD = new TTree(hname,"Digits");
1094 sprintf(hname,"TreeR%d",fEvent);
1095 fTreeR = new TTree(hname,"Reconstruction");
1098 fTreeE = new TTree("TE","Header");
1099 // Create a branch for Header
1100 fTreeE->Branch("Header","AliHeader",&header,4000);
1103 // Create a branch for hits/digits for each detector
1104 // Each branch is a TClonesArray. Each data member of the Hits classes
1105 // will be in turn a subbranch of the detector master branch
1106 TIter next(fModules);
1107 AliModule *detector;
1108 while((detector = (AliModule*)next())) {
1109 if (H || D || R) detector->MakeBranch(option);
1113 //_____________________________________________________________________________
1114 Int_t AliRun::PurifyKine(Int_t lastSavedTrack, Int_t nofTracks)
1117 // PurifyKine with external parameters
1119 fHgwmk = lastSavedTrack;
1120 fNtrack = nofTracks;
1125 //_____________________________________________________________________________
1126 void AliRun::PurifyKine()
1129 // Compress kinematic tree keeping only flagged particles
1130 // and renaming the particle id's in all the hits
1132 TClonesArray &particles = *fParticles;
1133 int nkeep=fHgwmk+1, parent, i;
1134 TParticle *part, *partnew, *father;
1135 int *map = new int[particles.GetEntries()];
1137 // Save in Header total number of tracks before compression
1138 fHeader.SetNtrack(fHeader.GetNtrack()+fNtrack-fHgwmk);
1140 // First pass, invalid Daughter information
1141 for(i=0; i<fNtrack; i++) {
1142 // Preset map, to be removed later
1143 if(i<=fHgwmk) map[i]=i ; else map[i] = -99;
1144 ((TParticle *)particles.UncheckedAt(i))->ResetBit(Daughters_Bit);
1146 // Second pass, build map between old and new numbering
1147 for(i=fHgwmk+1; i<fNtrack; i++) {
1148 part = (TParticle *)particles.UncheckedAt(i);
1149 if(part->TestBit(Keep_Bit)) {
1151 // This particle has to be kept
1155 // Old and new are different, have to copy
1156 partnew = (TParticle *)particles.UncheckedAt(nkeep);
1157 // Change due to a bug in the HP compiler
1158 // *partnew = *part;
1159 memcpy(partnew,part,sizeof(TParticle));
1160 } else partnew = part;
1162 // as the parent is always *before*, it must be already
1163 // in place. This is what we are checking anyway!
1164 if((parent=partnew->GetFirstMother())>fHgwmk) {
1165 if(map[parent]==-99) printf("map[%d] = -99!\n",parent);
1166 partnew->SetFirstMother(map[parent]);
1173 // Fix daughters information
1174 for (i=0; i<fNtrack; i++) {
1175 part = (TParticle *)particles.UncheckedAt(i);
1176 parent = part->GetFirstMother();
1178 father = (TParticle *)particles.UncheckedAt(parent);
1179 if(father->TestBit(Daughters_Bit)) {
1181 if(i<father->GetFirstDaughter()) father->SetFirstDaughter(i);
1182 if(i>father->GetLastDaughter()) father->SetLastDaughter(i);
1184 // Iitialise daughters info for first pass
1185 father->SetFirstDaughter(i);
1186 father->SetLastDaughter(i);
1187 father->SetBit(Daughters_Bit);
1193 // Now loop on all detectors and reset the hits
1195 TIter next(fModules);
1196 AliModule *detector;
1197 while((detector = (AliModule*)next())) {
1198 if (!detector->Hits()) continue;
1199 TClonesArray &vHits=*(detector->Hits());
1200 if(vHits.GetEntries() != detector->GetNhits())
1201 printf("vHits.GetEntries()!=detector->GetNhits(): %d != %d\n",
1202 vHits.GetEntries(),detector->GetNhits());
1203 for (i=0; i<detector->GetNhits(); i++) {
1204 OneHit = (AliHit *)vHits.UncheckedAt(i);
1205 OneHit->SetTrack(map[OneHit->GetTrack()]);
1210 // Now loop on all registered hit lists
1211 TIter next(fHitLists);
1212 TCollection *hitList;
1213 while((hitList = (TCollection*)next())) {
1214 TIter nexthit(hitList);
1216 while((hit = (AliHit*)nexthit())) {
1217 hit->SetTrack(map[hit->GetTrack()]);
1223 particles.SetLast(fHgwmk);
1227 //_____________________________________________________________________________
1228 void AliRun::BeginEvent()
1231 // Reset all Detectors & kinematics & trees
1238 fLego->BeginEvent();
1247 // Initialise event header
1248 fHeader.Reset(fRun,fEvent);
1252 sprintf(hname,"TreeK%d",fEvent);
1253 fTreeK->SetName(hname);
1257 sprintf(hname,"TreeH%d",fEvent);
1258 fTreeH->SetName(hname);
1262 sprintf(hname,"TreeD%d",fEvent);
1263 fTreeD->SetName(hname);
1267 sprintf(hname,"TreeR%d",fEvent);
1268 fTreeR->SetName(hname);
1272 //_____________________________________________________________________________
1273 void AliRun::ResetDigits()
1276 // Reset all Detectors digits
1278 TIter next(fModules);
1279 AliModule *detector;
1280 while((detector = (AliModule*)next())) {
1281 detector->ResetDigits();
1285 //_____________________________________________________________________________
1286 void AliRun::ResetHits()
1289 // Reset all Detectors hits
1291 TIter next(fModules);
1292 AliModule *detector;
1293 while((detector = (AliModule*)next())) {
1294 detector->ResetHits();
1298 //_____________________________________________________________________________
1299 void AliRun::ResetPoints()
1302 // Reset all Detectors points
1304 TIter next(fModules);
1305 AliModule *detector;
1306 while((detector = (AliModule*)next())) {
1307 detector->ResetPoints();
1311 //_____________________________________________________________________________
1312 void AliRun::RunMC(Int_t nevent, const char *setup)
1315 // Main function to be called to process a galice run
1317 // Root > gAlice.Run();
1318 // a positive number of events will cause the finish routine
1322 // check if initialisation has been done
1323 if (!fInitDone) InitMC(setup);
1325 // Create the Root Tree with one branch per detector
1328 gMC->ProcessRun(nevent);
1330 // End of this run, close files
1331 if(nevent>0) FinishRun();
1334 //_____________________________________________________________________________
1335 void AliRun::RunLego(const char *setup,Int_t ntheta,Float_t themin,
1336 Float_t themax,Int_t nphi,Float_t phimin,Float_t phimax,
1337 Float_t rmin,Float_t rmax,Float_t zmax)
1340 // Generates lego plots of:
1341 // - radiation length map phi vs theta
1342 // - radiation length map phi vs eta
1343 // - interaction length map
1344 // - g/cm2 length map
1346 // ntheta bins in theta, eta
1347 // themin minimum angle in theta (degrees)
1348 // themax maximum angle in theta (degrees)
1350 // phimin minimum angle in phi (degrees)
1351 // phimax maximum angle in phi (degrees)
1352 // rmin minimum radius
1353 // rmax maximum radius
1356 // The number of events generated = ntheta*nphi
1357 // run input parameters in macro setup (default="Config.C")
1359 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1362 <img src="picts/AliRunLego1.gif">
1367 <img src="picts/AliRunLego2.gif">
1372 <img src="picts/AliRunLego3.gif">
1377 // check if initialisation has been done
1378 if (!fInitDone) InitMC(setup);
1380 //Save current generator
1381 AliGenerator *gen=Generator();
1383 //Create Lego object
1384 fLego = new AliLego("lego",ntheta,themin,themax,nphi,phimin,phimax,rmin,rmax,zmax);
1386 //Prepare MC for Lego Run
1390 gMC->ProcessRun(ntheta*nphi+1);
1392 // Create only the Root event Tree
1395 // End of this run, close files
1398 // Delete Lego Object
1399 delete fLego; fLego=0;
1401 // Restore current generator
1405 //_____________________________________________________________________________
1406 void AliRun::SetCurrentTrack(Int_t track)
1409 // Set current track number
1414 //_____________________________________________________________________________
1415 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1416 Float_t *vpos, Float_t *polar, Float_t tof,
1417 const char *mecha, Int_t &ntr, Float_t weight)
1420 // Load a track on the stack
1422 // done 0 if the track has to be transported
1424 // parent identifier of the parent track. -1 for a primary
1425 // pdg particle code
1426 // pmom momentum GeV/c
1428 // polar polarisation
1429 // tof time of flight in seconds
1430 // mecha production mechanism
1431 // ntr on output the number of the track stored
1433 TClonesArray &particles = *fParticles;
1434 TParticle *particle;
1436 const Int_t firstdaughter=-1;
1437 const Int_t lastdaughter=-1;
1439 // const Float_t tlife=0;
1442 // Here we get the static mass
1443 // For MC is ok, but a more sophisticated method could be necessary
1444 // if the calculated mass is required
1445 // also, this method is potentially dangerous if the mass
1446 // used in the MC is not the same of the PDG database
1448 mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
1449 Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+
1450 pmom[1]*pmom[1]+pmom[2]*pmom[2]);
1452 //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",
1453 //pname,mass,e,fNtrack,pdg,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],KS,mecha);
1455 particle=new(particles[fNtrack]) TParticle(pdg,KS,parent,-1,firstdaughter,
1456 lastdaughter,pmom[0],pmom[1],pmom[2],
1457 e,vpos[0],vpos[1],vpos[2],tof);
1458 // polar[0],polar[1],polar[2],tof,
1460 ((TParticle*)particles[fNtrack])->SetPolarisation(TVector3(polar[0],polar[1],polar[2]));
1461 ((TParticle*)particles[fNtrack])->SetWeight(weight);
1462 if(!done) particle->SetBit(Done_Bit);
1463 //Declare that the daughter information is valid
1464 ((TParticle*)particles[fNtrack])->SetBit(Daughters_Bit);
1467 particle=(TParticle*) fParticles->UncheckedAt(parent);
1468 particle->SetLastDaughter(fNtrack);
1469 if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack);
1472 // This is a primary track. Set high water mark for this event
1475 // Set also number if primary tracks
1476 fHeader.SetNprimary(fHgwmk+1);
1477 fHeader.SetNtrack(fHgwmk+1);
1482 //_____________________________________________________________________________
1483 void AliRun::KeepTrack(const Int_t track)
1486 // flags a track to be kept
1488 TClonesArray &particles = *fParticles;
1489 ((TParticle*)particles[track])->SetBit(Keep_Bit);
1492 //_____________________________________________________________________________
1493 void AliRun::StepManager(Int_t id)
1496 // Called at every step during transport
1500 // --- If lego option, do it and leave
1502 fLego->StepManager();
1505 //Update energy deposition tables
1506 AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
1508 //Call the appropriate stepping routine;
1509 AliModule *det = (AliModule*)fModules->At(id);
1510 if(det) det->StepManager();
1514 //_____________________________________________________________________________
1515 void AliRun::Streamer(TBuffer &R__b)
1518 // Stream an object of class AliRun.
1520 if (R__b.IsReading()) {
1521 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1522 TNamed::Streamer(R__b);
1523 if (!gAlice) gAlice = this;
1524 gROOT->GetListOfBrowsables()->Add(this,"Run");
1525 fTreeE = (TTree*)gDirectory->Get("TE");
1526 if (fTreeE) fTreeE->SetBranchAddress("Header", &header);
1527 else Error("Streamer","cannot find Header Tree\n");
1531 fHeader.Streamer(R__b);
1541 R__b >> fPDGDB; //Particle factory object!
1542 fTreeE->GetEntry(0);
1544 fHeader.SetEvent(0);
1545 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
1548 fConfigFunction.Streamer(R__b);
1550 fConfigFunction="Config();";
1553 R__b.WriteVersion(AliRun::IsA());
1554 TNamed::Streamer(R__b);
1558 fHeader.Streamer(R__b);
1567 R__b << fPDGDB; //Particle factory object!
1568 fConfigFunction.Streamer(R__b);