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.26 2000/03/22 13:42:26 fca
19 SetGenerator does not replace an existing generator, ResetGenerator does
21 Revision 1.25 2000/02/23 16:25:22 fca
22 AliVMC and AliGeant3 classes introduced
23 ReadEuclid moved from AliRun to AliModule
25 Revision 1.24 2000/01/19 17:17:20 fca
26 Introducing a list of lists of hits -- more hits allowed for detector now
28 Revision 1.23 1999/12/03 11:14:31 fca
29 Fixing previous wrong checking
31 Revision 1.21 1999/11/25 10:40:08 fca
32 Fixing daughters information also in primary tracks
34 Revision 1.20 1999/10/04 18:08:49 fca
35 Adding protection against inconsistent Euclid files
37 Revision 1.19 1999/09/29 07:50:40 fca
38 Introduction of the Copyright and cvs Log
42 ///////////////////////////////////////////////////////////////////////////////
44 // Control class for Alice C++ //
45 // Only one single instance of this class exists. //
46 // The object is created in main program aliroot //
47 // and is pointed by the global gAlice. //
49 // -Supports the list of all Alice Detectors (fModules). //
50 // -Supports the list of particles (fParticles). //
51 // -Supports the Trees. //
52 // -Supports the geometry. //
53 // -Supports the event display. //
56 <img src="picts/AliRunClass.gif">
61 <img src="picts/alirun.gif">
65 ///////////////////////////////////////////////////////////////////////////////
73 #include <TObjectTable.h>
75 #include "TParticle.h"
77 #include "AliDisplay.h"
86 static AliHeader *header;
88 static TArrayF sEventEnergy;
89 static TArrayF sSummEnergy;
90 static TArrayF sSum2Energy;
94 //_____________________________________________________________________________
98 // Default constructor for AliRun
122 fPDGDB = 0; //Particle factory object!
126 //_____________________________________________________________________________
127 AliRun::AliRun(const char *name, const char *title)
131 // Constructor for the main processor.
132 // Creates the geometry
133 // Creates the list of Detectors.
134 // Creates the list of particles.
151 gROOT->GetListOfBrowsables()->Add(this,name);
153 // create the support list for the various Detectors
154 fModules = new TObjArray(77);
156 // Create the TNode geometry for the event display
158 BuildSimpleGeometry();
168 // Create the particle stack
169 fParticles = new TClonesArray("TParticle",100);
173 // Create default mag field
178 // Prepare the tracking medium lists
179 fImedia = new TArrayI(1000);
180 for(i=0;i<1000;i++) (*fImedia)[i]=-99;
183 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
185 // Create HitLists list
186 fHitLists = new TList();
189 //_____________________________________________________________________________
193 // Defaullt AliRun destructor
212 fParticles->Delete();
218 //_____________________________________________________________________________
219 void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
222 // Add a hit to detector id
224 TObjArray &dets = *fModules;
225 if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits);
228 //_____________________________________________________________________________
229 void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
232 // Add digit to detector id
234 TObjArray &dets = *fModules;
235 if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits);
238 //_____________________________________________________________________________
239 void AliRun::Browse(TBrowser *b)
242 // Called when the item "Run" is clicked on the left pane
243 // of the Root browser.
244 // It displays the Root Trees and all detectors.
246 if (fTreeK) b->Add(fTreeK,fTreeK->GetName());
247 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
248 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
249 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
250 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
252 TIter next(fModules);
254 while((detector = (AliModule*)next())) {
255 b->Add(detector,detector->GetName());
259 //_____________________________________________________________________________
263 // Initialize Alice geometry
268 //_____________________________________________________________________________
269 void AliRun::BuildSimpleGeometry()
272 // Create a simple TNode geometry used by Root display engine
274 // Initialise geometry
276 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
277 new TMaterial("void","Vacuum",0,0,0); //Everything is void
278 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
279 brik->SetVisibility(0);
280 new TNode("alice","alice","S_alice");
283 //_____________________________________________________________________________
284 void AliRun::CleanDetectors()
287 // Clean Detectors at the end of event
289 TIter next(fModules);
291 while((detector = (AliModule*)next())) {
292 detector->FinishEvent();
296 //_____________________________________________________________________________
297 void AliRun::CleanParents()
300 // Clean Particles stack.
301 // Set parent/daughter relations
303 TClonesArray &particles = *(gAlice->Particles());
306 for(i=0; i<fNtrack; i++) {
307 part = (TParticle *)particles.UncheckedAt(i);
308 if(!part->TestBit(Daughters_Bit)) {
309 part->SetFirstDaughter(-1);
310 part->SetLastDaughter(-1);
315 //_____________________________________________________________________________
316 Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
319 // Return the distance from the mouse to the AliRun object
325 //_____________________________________________________________________________
326 void AliRun::DumpPart (Int_t i)
329 // Dumps particle i in the stack
331 TClonesArray &particles = *fParticles;
332 ((TParticle*) particles[i])->Print();
335 //_____________________________________________________________________________
336 void AliRun::DumpPStack ()
339 // Dumps the particle stack
341 TClonesArray &particles = *fParticles;
343 "\n\n=======================================================================\n");
344 for (Int_t i=0;i<fNtrack;i++)
346 printf("-> %d ",i); ((TParticle*) particles[i])->Print();
347 printf("--------------------------------------------------------------\n");
350 "\n=======================================================================\n\n");
353 //_____________________________________________________________________________
354 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
355 Float_t maxField, char* filename)
358 // Set magnetic field parameters
359 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
360 // version Magnetic field map version (only 1 active now)
361 // scale Scale factor for the magnetic field
362 // maxField Maximum value for the magnetic field
365 // --- Sanity check on mag field flags
366 if(type<0 || type > 2) {
368 "Invalid magnetic field flag: %5d; Helix tracking chosen instead\n"
372 if(fField) delete fField;
374 fField = new AliMagFC("Map1"," ",type,version,scale,maxField);
375 } else if(version<=3) {
376 fField = new AliMagFCM("Map2-3",filename,type,version,scale,maxField);
379 Warning("SetField","Invalid map %d\n",version);
383 //_____________________________________________________________________________
384 void AliRun::FillTree()
387 // Fills all AliRun TTrees
389 if (fTreeK) fTreeK->Fill();
390 if (fTreeH) fTreeH->Fill();
391 if (fTreeD) fTreeD->Fill();
392 if (fTreeR) fTreeR->Fill();
395 //_____________________________________________________________________________
396 void AliRun::FinishPrimary()
399 // Called at the end of each primary track
402 // static Int_t count=0;
403 // const Int_t times=10;
404 // This primary is finished, purify stack
407 // Write out hits if any
408 if (gAlice->TreeH()) {
409 gAlice->TreeH()->Fill();
416 // if(++count%times==1) gObjectTable->Print();
419 //_____________________________________________________________________________
420 void AliRun::FinishEvent()
423 // Called at the end of the event.
426 //Update the energy deposit tables
428 for(i=0;i<sEventEnergy.GetSize();i++) {
429 sSummEnergy[i]+=sEventEnergy[i];
430 sSum2Energy[i]+=sEventEnergy[i]*sEventEnergy[i];
432 sEventEnergy.Reset();
434 // Clean detector information
437 // Write out the kinematics
443 // Write out the digits
449 // Write out reconstructed clusters
454 // Write out the event Header information
455 if (fTreeE) fTreeE->Fill();
460 // Write Tree headers
461 // Int_t ievent = fHeader.GetEvent();
463 // sprintf(hname,"TreeK%d",ievent);
464 if (fTreeK) fTreeK->Write();
465 // sprintf(hname,"TreeH%d",ievent);
466 if (fTreeH) fTreeH->Write();
467 // sprintf(hname,"TreeD%d",ievent);
468 if (fTreeD) fTreeD->Write();
469 // sprintf(hname,"TreeR%d",ievent);
470 if (fTreeR) fTreeR->Write();
473 //_____________________________________________________________________________
474 void AliRun::FinishRun()
477 // Called at the end of the run.
480 // Clean detector information
481 TIter next(fModules);
483 while((detector = (AliModule*)next())) {
484 detector->FinishRun();
487 //Output energy summary tables
490 // file is retrieved from whatever tree
492 if (fTreeK) File = fTreeK->GetCurrentFile();
493 if ((!File) && (fTreeH)) File = fTreeH->GetCurrentFile();
494 if ((!File) && (fTreeD)) File = fTreeD->GetCurrentFile();
495 if ((!File) && (fTreeE)) File = fTreeE->GetCurrentFile();
497 Error("FinishRun","There isn't root file!");
503 // Clean tree information
504 delete fTreeK; fTreeK = 0;
505 delete fTreeH; fTreeH = 0;
506 delete fTreeD; fTreeD = 0;
507 delete fTreeR; fTreeR = 0;
508 delete fTreeE; fTreeE = 0;
510 // Write AliRun info and all detectors parameters
517 //_____________________________________________________________________________
518 void AliRun::FlagTrack(Int_t track)
521 // Flags a track and all its family tree to be kept
528 particle=(TParticle*)fParticles->UncheckedAt(curr);
530 // If the particle is flagged the three from here upward is saved already
531 if(particle->TestBit(Keep_Bit)) return;
533 // Save this particle
534 particle->SetBit(Keep_Bit);
536 // Move to father if any
537 if((curr=particle->GetFirstMother())==-1) return;
541 //_____________________________________________________________________________
542 void AliRun::EnergySummary()
545 // Print summary of deposited energy
551 Int_t kn, i, left, j, id;
552 const Float_t zero=0;
553 Int_t ievent=fHeader.GetEvent()+1;
555 // Energy loss information
557 printf("***************** Energy Loss Information per event (GEV) *****************\n");
558 for(kn=1;kn<sEventEnergy.GetSize();kn++) {
561 sEventEnergy[ndep]=kn;
566 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,zero))/ed;
569 sSummEnergy[ndep]=ed;
570 sSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,zero));
575 for(kn=0;kn<(ndep-1)/3+1;kn++) {
577 for(i=0;i<(3<left?3:left);i++) {
579 id=Int_t (sEventEnergy[j]+0.1);
580 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),sSummEnergy[j],sSum2Energy[j]);
585 // Relative energy loss in different detectors
586 printf("******************** Relative Energy Loss per event ********************\n");
587 printf("Total energy loss per event %10.3f GeV\n",edtot);
588 for(kn=0;kn<(ndep-1)/5+1;kn++) {
590 for(i=0;i<(5<left?5:left);i++) {
592 id=Int_t (sEventEnergy[j]+0.1);
593 printf(" %s %10.3f%%;",gMC->VolName(id),100*sSummEnergy[j]/edtot);
597 for(kn=0;kn<75;kn++) printf("*");
601 // Reset the TArray's
602 // sEventEnergy.Set(0);
603 // sSummEnergy.Set(0);
604 // sSum2Energy.Set(0);
607 //_____________________________________________________________________________
608 AliModule *AliRun::GetModule(const char *name)
611 // Return pointer to detector from name
613 return (AliModule*)fModules->FindObject(name);
616 //_____________________________________________________________________________
617 AliDetector *AliRun::GetDetector(const char *name)
620 // Return pointer to detector from name
622 return (AliDetector*)fModules->FindObject(name);
625 //_____________________________________________________________________________
626 Int_t AliRun::GetModuleID(const char *name)
629 // Return galice internal detector identifier from name
632 TObject *mod=fModules->FindObject(name);
633 if(mod) i=fModules->IndexOf(mod);
637 //_____________________________________________________________________________
638 Int_t AliRun::GetEvent(Int_t event)
641 // Connect the Trees Kinematics and Hits for event # event
642 // Set branch addresses
645 // Reset existing structures
650 // Delete Trees already connected
651 if (fTreeK) delete fTreeK;
652 if (fTreeH) delete fTreeH;
653 if (fTreeD) delete fTreeD;
654 if (fTreeR) delete fTreeR;
656 // Get header from file
657 if(fTreeE) fTreeE->GetEntry(event);
658 else Error("GetEvent","Cannot file Header Tree\n");
660 // Get Kine Tree from file
662 sprintf(treeName,"TreeK%d",event);
663 fTreeK = (TTree*)gDirectory->Get(treeName);
664 if (fTreeK) fTreeK->SetBranchAddress("Particles", &fParticles);
665 else Error("GetEvent","cannot find Kine Tree for event:%d\n",event);
667 // Get Hits Tree header from file
668 sprintf(treeName,"TreeH%d",event);
669 fTreeH = (TTree*)gDirectory->Get(treeName);
671 Error("GetEvent","cannot find Hits Tree for event:%d\n",event);
674 // Get Digits Tree header from file
675 sprintf(treeName,"TreeD%d",event);
676 fTreeD = (TTree*)gDirectory->Get(treeName);
678 Warning("GetEvent","cannot find Digits Tree for event:%d\n",event);
682 // Get Reconstruct Tree header from file
683 sprintf(treeName,"TreeR%d",event);
684 fTreeR = (TTree*)gDirectory->Get(treeName);
686 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
689 // Set Trees branch addresses
690 TIter next(fModules);
692 while((detector = (AliModule*)next())) {
693 detector->SetTreeAddress();
696 if (fTreeK) fTreeK->GetEvent(0);
697 fNtrack = Int_t (fParticles->GetEntries());
701 //_____________________________________________________________________________
702 TGeometry *AliRun::GetGeometry()
705 // Import Alice geometry from current file
706 // Return pointer to geometry object
708 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
710 // Unlink and relink nodes in detectors
711 // This is bad and there must be a better way...
714 TIter next(fModules);
716 while((detector = (AliModule*)next())) {
717 detector->SetTreeAddress();
718 TList *dnodes=detector->Nodes();
721 for ( j=0; j<dnodes->GetSize(); j++) {
722 node = (TNode*) dnodes->At(j);
723 node1 = fGeometry->GetNode(node->GetName());
724 dnodes->Remove(node);
725 dnodes->AddAt(node1,j);
731 //_____________________________________________________________________________
732 void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
733 Float_t &e, Float_t *vpos, Float_t *polar,
737 // Return next track from stack of particles
742 for(Int_t i=fNtrack-1; i>=0; i--) {
743 track=(TParticle*) fParticles->UncheckedAt(i);
744 if(!track->TestBit(Done_Bit)) {
746 // The track has not yet been processed
748 ipart=track->GetPdgCode();
756 track->GetPolarisation(pol);
761 track->SetBit(Done_Bit);
767 // stop and start timer when we start a primary track
768 Int_t nprimaries = fHeader.GetNprimary();
769 if (fCurrent >= nprimaries) return;
770 if (fCurrent < nprimaries-1) {
772 track=(TParticle*) fParticles->UncheckedAt(fCurrent+1);
773 // track->SetProcessTime(fTimer.CpuTime());
778 //_____________________________________________________________________________
779 Int_t AliRun::GetPrimary(Int_t track)
782 // return number of primary that has generated track
790 part = (TParticle *)fParticles->UncheckedAt(current);
791 parent=part->GetFirstMother();
792 if(parent<0) return current;
796 //_____________________________________________________________________________
797 void AliRun::Init(const char *setup)
800 // Initialize the Alice setup
803 gROOT->LoadMacro(setup);
804 gInterpreter->ProcessLine("Config();");
806 gMC->DefineParticles(); //Create standard MC particles
808 TObject *objfirst, *objlast;
810 fNdets = fModules->GetLast()+1;
813 //=================Create Materials, geometry, histograms, etc
814 TIter next(fModules);
816 while((detector = (AliModule*)next())) {
817 detector->SetTreeAddress();
818 objlast = gDirectory->GetList()->Last();
820 // Initialise detector materials, geometry, histograms,etc
821 detector->CreateMaterials();
822 detector->CreateGeometry();
823 detector->BuildGeometry();
826 // Add Detector histograms in Detector list of histograms
827 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
828 else objfirst = gDirectory->GetList()->First();
830 detector->Histograms()->Add(objfirst);
831 objfirst = gDirectory->GetList()->After(objfirst);
834 SetTransPar(); //Read the cuts for all materials
836 MediaTable(); //Build the special IMEDIA table
838 //Terminate building of geometry
840 gVMC->FinishGeometry();
842 //Initialise geometry deposition table
843 sEventEnergy.Set(gMC->NofVolumes()+1);
844 sSummEnergy.Set(gMC->NofVolumes()+1);
845 sSum2Energy.Set(gMC->NofVolumes()+1);
847 //Compute cross-sections
848 gVMC->BuildPhysics();
850 //Write Geometry object to current file.
856 //_____________________________________________________________________________
857 void AliRun::MediaTable()
860 // Built media table to get from the media number to
863 Int_t kz, nz, idt, lz, i, k, ind;
865 TObjArray &dets = *gAlice->Detectors();
869 for (kz=0;kz<fNdets;kz++) {
870 // If detector is defined
871 if((det=(AliModule*) dets[kz])) {
872 TArrayI &idtmed = *(det->GetIdtmed());
873 for(nz=0;nz<100;nz++) {
874 // Find max and min material number
875 if((idt=idtmed[nz])) {
876 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
877 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
880 if(det->LoMedium() > det->HiMedium()) {
884 if(det->HiMedium() > fImedia->GetSize()) {
885 Error("MediaTable","Increase fImedia from %d to %d",
886 fImedia->GetSize(),det->HiMedium());
889 // Tag all materials in rage as belonging to detector kz
890 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
897 // Print summary table
898 printf(" Traking media ranges:\n");
899 for(i=0;i<(fNdets-1)/6+1;i++) {
900 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
902 det=(AliModule*)dets[ind];
904 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
907 printf(" %6s: %3d -> %3d;","NULL",0,0);
913 //____________________________________________________________________________
914 void AliRun::SetGenerator(AliGenerator *generator)
917 // Load the event generator
919 if(!fGenerator) fGenerator = generator;
922 //____________________________________________________________________________
923 void AliRun::ResetGenerator(AliGenerator *generator)
926 // Load the event generator
929 Warning("ResetGenerator","Replacing generator %s with %s\n",
930 fGenerator->GetName(),generator->GetName());
931 fGenerator = generator;
934 //____________________________________________________________________________
935 void AliRun::SetTransPar(char* filename)
938 // Read filename to set the transport parameters
942 const Int_t ncuts=10;
943 const Int_t nflags=11;
944 const Int_t npars=ncuts+nflags;
945 const char pars[npars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
946 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
947 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
948 "MULS","PAIR","PHOT","RAYL"};
954 Int_t i, itmed, iret, ktmed, kz;
957 // See whether the file is there
958 filtmp=gSystem->ExpandPathName(filename);
959 lun=fopen(filtmp,"r");
962 Warning("SetTransPar","File %s does not exist!\n",filename);
966 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
967 printf(" *%59s\n","*");
968 printf(" * Please check carefully what you are doing!%10s\n","*");
969 printf(" *%59s\n","*");
972 // Initialise cuts and flags
973 for(i=0;i<ncuts;i++) cut[i]=-99;
974 for(i=0;i<nflags;i++) flag[i]=-99;
976 for(i=0;i<256;i++) line[i]='\0';
977 // Read up to the end of line excluded
978 iret=fscanf(lun,"%[^\n]",line);
982 printf(" *%59s\n","*");
983 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
986 // Read the end of line
989 if(line[0]=='*') continue;
991 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",
992 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
993 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
994 &flag[8],&flag[9],&flag[10]);
998 Warning("SetTransPar","Error reading file %s\n",filename);
1001 // Check that the module exist
1002 AliModule *mod = GetModule(detName);
1004 // Get the array of media numbers
1005 TArrayI &idtmed = *mod->GetIdtmed();
1006 // Check that the tracking medium code is valid
1007 if(0<=itmed && itmed < 100) {
1008 ktmed=idtmed[itmed];
1010 Warning("SetTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
1013 // Set energy thresholds
1014 for(kz=0;kz<ncuts;kz++) {
1016 printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
1017 pars[kz],cut[kz],itmed,mod->GetName());
1018 gMC->Gstpar(ktmed,pars[kz],cut[kz]);
1021 // Set transport mechanisms
1022 for(kz=0;kz<nflags;kz++) {
1024 printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
1025 pars[ncuts+kz],flag[kz],itmed,mod->GetName());
1026 gMC->Gstpar(ktmed,pars[ncuts+kz],Float_t(flag[kz]));
1030 Warning("SetTransPar","Invalid medium code %d *\n",itmed);
1034 Warning("SetTransPar","Module %s not present\n",detName);
1040 //_____________________________________________________________________________
1041 void AliRun::MakeTree(Option_t *option)
1044 // Create the ROOT trees
1045 // Loop on all detectors to create the Root branch (if any)
1051 char *K = strstr(option,"K");
1052 char *H = strstr(option,"H");
1053 char *E = strstr(option,"E");
1054 char *D = strstr(option,"D");
1055 char *R = strstr(option,"R");
1058 sprintf(hname,"TreeK%d",fEvent);
1059 fTreeK = new TTree(hname,"Kinematics");
1060 // Create a branch for particles
1061 fTreeK->Branch("Particles",&fParticles,4000);
1064 sprintf(hname,"TreeH%d",fEvent);
1065 fTreeH = new TTree(hname,"Hits");
1066 fTreeH->SetAutoSave(1000000000); //no autosave
1069 sprintf(hname,"TreeD%d",fEvent);
1070 fTreeD = new TTree(hname,"Digits");
1073 sprintf(hname,"TreeR%d",fEvent);
1074 fTreeR = new TTree(hname,"Reconstruction");
1077 fTreeE = new TTree("TE","Header");
1078 // Create a branch for Header
1079 fTreeE->Branch("Header","AliHeader",&header,4000);
1082 // Create a branch for hits/digits for each detector
1083 // Each branch is a TClonesArray. Each data member of the Hits classes
1084 // will be in turn a subbranch of the detector master branch
1085 TIter next(fModules);
1086 AliModule *detector;
1087 while((detector = (AliModule*)next())) {
1088 if (H || D || R) detector->MakeBranch(option);
1092 //_____________________________________________________________________________
1093 Int_t AliRun::PurifyKine(Int_t lastSavedTrack, Int_t nofTracks)
1096 // PurifyKine with external parameters
1098 fHgwmk = lastSavedTrack;
1099 fNtrack = nofTracks;
1104 //_____________________________________________________________________________
1105 void AliRun::PurifyKine()
1108 // Compress kinematic tree keeping only flagged particles
1109 // and renaming the particle id's in all the hits
1111 TClonesArray &particles = *fParticles;
1112 int nkeep=fHgwmk+1, parent, i;
1113 TParticle *part, *partnew, *father;
1114 int *map = new int[particles.GetEntries()];
1116 // Save in Header total number of tracks before compression
1117 fHeader.SetNtrack(fHeader.GetNtrack()+fNtrack-fHgwmk);
1119 // Preset map, to be removed later
1120 for(i=0; i<fNtrack; i++) {
1121 if(i<=fHgwmk) map[i]=i ; else map[i] = -99 ;}
1122 // Second pass, build map between old and new numbering
1123 for(i=fHgwmk+1; i<fNtrack; i++) {
1124 part = (TParticle *)particles.UncheckedAt(i);
1125 if(part->TestBit(Keep_Bit)) {
1127 // This particle has to be kept
1131 // Old and new are different, have to copy
1132 partnew = (TParticle *)particles.UncheckedAt(nkeep);
1134 } else partnew = part;
1136 // as the parent is always *before*, it must be already
1137 // in place. This is what we are checking anyway!
1138 if((parent=partnew->GetFirstMother())>fHgwmk) {
1139 if(map[parent]==-99) printf("map[%d] = -99!\n",parent);
1140 partnew->SetFirstMother(map[parent]);
1147 // Fix daughters information
1148 for (i=0; i<fNtrack; i++) {
1149 part = (TParticle *)particles.UncheckedAt(i);
1150 parent = part->GetFirstMother();
1152 father = (TParticle *)particles.UncheckedAt(parent);
1153 if(father->TestBit(Daughters_Bit)) {
1155 if(i<father->GetFirstDaughter()) father->SetFirstDaughter(i);
1156 if(i>father->GetLastDaughter()) father->SetLastDaughter(i);
1158 // Iitialise daughters info for first pass
1159 father->SetFirstDaughter(i);
1160 father->SetLastDaughter(i);
1161 father->SetBit(Daughters_Bit);
1167 // Now loop on all detectors and reset the hits
1169 TIter next(fModules);
1170 AliModule *detector;
1171 while((detector = (AliModule*)next())) {
1172 if (!detector->Hits()) continue;
1173 TClonesArray &vHits=*(detector->Hits());
1174 if(vHits.GetEntries() != detector->GetNhits())
1175 printf("vHits.GetEntries()!=detector->GetNhits(): %d != %d\n",
1176 vHits.GetEntries(),detector->GetNhits());
1177 for (i=0; i<detector->GetNhits(); i++) {
1178 OneHit = (AliHit *)vHits.UncheckedAt(i);
1179 OneHit->SetTrack(map[OneHit->GetTrack()]);
1184 // Now loop on all registered hit lists
1185 TIter next(fHitLists);
1186 TCollection *hitList;
1187 while((hitList = (TCollection*)next())) {
1188 TIter nexthit(hitList);
1190 while((hit = (AliHit*)nexthit())) {
1191 hit->SetTrack(map[hit->GetTrack()]);
1197 particles.SetLast(fHgwmk);
1201 //_____________________________________________________________________________
1202 void AliRun::Reset(Int_t run, Int_t idevent)
1205 // Reset all Detectors & kinematics & trees
1213 // Initialise event header
1214 fHeader.Reset(run,idevent);
1218 sprintf(hname,"TreeK%d",idevent);
1219 fTreeK->SetName(hname);
1223 sprintf(hname,"TreeH%d",idevent);
1224 fTreeH->SetName(hname);
1228 sprintf(hname,"TreeD%d",idevent);
1229 fTreeD->SetName(hname);
1233 sprintf(hname,"TreeR%d",idevent);
1234 fTreeR->SetName(hname);
1238 //_____________________________________________________________________________
1239 void AliRun::ResetDigits()
1242 // Reset all Detectors digits
1244 TIter next(fModules);
1245 AliModule *detector;
1246 while((detector = (AliModule*)next())) {
1247 detector->ResetDigits();
1251 //_____________________________________________________________________________
1252 void AliRun::ResetHits()
1255 // Reset all Detectors hits
1257 TIter next(fModules);
1258 AliModule *detector;
1259 while((detector = (AliModule*)next())) {
1260 detector->ResetHits();
1264 //_____________________________________________________________________________
1265 void AliRun::ResetPoints()
1268 // Reset all Detectors points
1270 TIter next(fModules);
1271 AliModule *detector;
1272 while((detector = (AliModule*)next())) {
1273 detector->ResetPoints();
1277 //_____________________________________________________________________________
1278 void AliRun::Run(Int_t nevent, const char *setup)
1281 // Main function to be called to process a galice run
1283 // Root > gAlice.Run();
1284 // a positive number of events will cause the finish routine
1289 // check if initialisation has been done
1290 if (!fInitDone) Init(setup);
1292 // Create the Root Tree with one branch per detector
1295 todo = TMath::Abs(nevent);
1296 for (i=0; i<todo; i++) {
1297 // Process one run (one run = one event)
1298 Reset(fRun, fEvent);
1299 gVMC->ProcessEvent();
1304 // End of this run, close files
1305 if(nevent>0) FinishRun();
1308 //_____________________________________________________________________________
1309 void AliRun::RunLego(const char *setup,Int_t ntheta,Float_t themin,
1310 Float_t themax,Int_t nphi,Float_t phimin,Float_t phimax,
1311 Float_t rmin,Float_t rmax,Float_t zmax)
1314 // Generates lego plots of:
1315 // - radiation length map phi vs theta
1316 // - radiation length map phi vs eta
1317 // - interaction length map
1318 // - g/cm2 length map
1320 // ntheta bins in theta, eta
1321 // themin minimum angle in theta (degrees)
1322 // themax maximum angle in theta (degrees)
1324 // phimin minimum angle in phi (degrees)
1325 // phimax maximum angle in phi (degrees)
1326 // rmin minimum radius
1327 // rmax maximum radius
1330 // The number of events generated = ntheta*nphi
1331 // run input parameters in macro setup (default="Config.C")
1333 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1336 <img src="picts/AliRunLego1.gif">
1341 <img src="picts/AliRunLego2.gif">
1346 <img src="picts/AliRunLego3.gif">
1351 // check if initialisation has been done
1352 if (!fInitDone) Init(setup);
1354 //Create Lego object
1355 fLego = new AliLego("lego",ntheta,themin,themax,nphi,phimin,phimax,rmin,rmax,zmax);
1360 // Create only the Root event Tree
1363 // End of this run, close files
1367 //_____________________________________________________________________________
1368 void AliRun::SetCurrentTrack(Int_t track)
1371 // Set current track number
1376 //_____________________________________________________________________________
1377 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1378 Float_t *vpos, Float_t *polar, Float_t tof,
1379 const char *mecha, Int_t &ntr, Float_t weight)
1382 // Load a track on the stack
1384 // done 0 if the track has to be transported
1386 // parent identifier of the parent track. -1 for a primary
1387 // pdg particle code
1388 // pmom momentum GeV/c
1390 // polar polarisation
1391 // tof time of flight in seconds
1392 // mecha production mechanism
1393 // ntr on output the number of the track stored
1395 TClonesArray &particles = *fParticles;
1396 TParticle *particle;
1398 const Int_t firstdaughter=-1;
1399 const Int_t lastdaughter=-1;
1401 // const Float_t tlife=0;
1404 // Here we get the static mass
1405 // For MC is ok, but a more sophisticated method could be necessary
1406 // if the calculated mass is required
1407 // also, this method is potentially dangerous if the mass
1408 // used in the MC is not the same of the PDG database
1410 mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
1411 Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+
1412 pmom[1]*pmom[1]+pmom[2]*pmom[2]);
1414 //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",
1415 //pname,mass,e,fNtrack,pdg,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],KS,mecha);
1417 particle=new(particles[fNtrack]) TParticle(pdg,KS,parent,-1,firstdaughter,
1418 lastdaughter,pmom[0],pmom[1],pmom[2],
1419 e,vpos[0],vpos[1],vpos[2],tof);
1420 // polar[0],polar[1],polar[2],tof,
1422 ((TParticle*)particles[fNtrack])->SetPolarisation(TVector3(polar[0],polar[1],polar[2]));
1423 ((TParticle*)particles[fNtrack])->SetWeight(weight);
1424 if(!done) particle->SetBit(Done_Bit);
1427 particle=(TParticle*) fParticles->UncheckedAt(parent);
1428 particle->SetLastDaughter(fNtrack);
1429 if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack);
1432 // This is a primary track. Set high water mark for this event
1435 // Set also number if primary tracks
1436 fHeader.SetNprimary(fHgwmk+1);
1437 fHeader.SetNtrack(fHgwmk+1);
1442 //_____________________________________________________________________________
1443 void AliRun::KeepTrack(const Int_t track)
1446 // flags a track to be kept
1448 TClonesArray &particles = *fParticles;
1449 ((TParticle*)particles[track])->SetBit(Keep_Bit);
1452 //_____________________________________________________________________________
1453 void AliRun::StepManager(Int_t id) const
1456 // Called at every step during transport
1460 // --- If lego option, do it and leave
1462 fLego->StepManager();
1465 //Update energy deposition tables
1466 sEventEnergy[gMC->CurrentVolID(copy)]+=gMC->Edep();
1468 //Call the appropriate stepping routine;
1469 AliModule *det = (AliModule*)fModules->At(id);
1470 if(det) det->StepManager();
1474 //_____________________________________________________________________________
1475 void AliRun::Streamer(TBuffer &R__b)
1478 // Stream an object of class AliRun.
1480 if (R__b.IsReading()) {
1481 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1482 TNamed::Streamer(R__b);
1483 if (!gAlice) gAlice = this;
1484 gROOT->GetListOfBrowsables()->Add(this,"Run");
1485 fTreeE = (TTree*)gDirectory->Get("TE");
1486 if (fTreeE) fTreeE->SetBranchAddress("Header", &header);
1487 else Error("Streamer","cannot find Header Tree\n");
1491 fHeader.Streamer(R__b);
1501 R__b >> fPDGDB; //Particle factory object!
1502 fTreeE->GetEntry(0);
1504 fHeader.SetEvent(0);
1505 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
1508 R__b.WriteVersion(AliRun::IsA());
1509 TNamed::Streamer(R__b);
1513 fHeader.Streamer(R__b);
1522 R__b << fPDGDB; //Particle factory object!