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.25 2000/02/23 16:25:22 fca
19 AliVMC and AliGeant3 classes introduced
20 ReadEuclid moved from AliRun to AliModule
22 Revision 1.24 2000/01/19 17:17:20 fca
23 Introducing a list of lists of hits -- more hits allowed for detector now
25 Revision 1.23 1999/12/03 11:14:31 fca
26 Fixing previous wrong checking
28 Revision 1.21 1999/11/25 10:40:08 fca
29 Fixing daughters information also in primary tracks
31 Revision 1.20 1999/10/04 18:08:49 fca
32 Adding protection against inconsistent Euclid files
34 Revision 1.19 1999/09/29 07:50:40 fca
35 Introduction of the Copyright and cvs Log
39 ///////////////////////////////////////////////////////////////////////////////
41 // Control class for Alice C++ //
42 // Only one single instance of this class exists. //
43 // The object is created in main program aliroot //
44 // and is pointed by the global gAlice. //
46 // -Supports the list of all Alice Detectors (fModules). //
47 // -Supports the list of particles (fParticles). //
48 // -Supports the Trees. //
49 // -Supports the geometry. //
50 // -Supports the event display. //
53 <img src="picts/AliRunClass.gif">
58 <img src="picts/alirun.gif">
62 ///////////////////////////////////////////////////////////////////////////////
70 #include <TObjectTable.h>
72 #include "TParticle.h"
74 #include "AliDisplay.h"
83 static AliHeader *header;
85 static TArrayF sEventEnergy;
86 static TArrayF sSummEnergy;
87 static TArrayF sSum2Energy;
91 //_____________________________________________________________________________
95 // Default constructor for AliRun
119 fPDGDB = 0; //Particle factory object!
123 //_____________________________________________________________________________
124 AliRun::AliRun(const char *name, const char *title)
128 // Constructor for the main processor.
129 // Creates the geometry
130 // Creates the list of Detectors.
131 // Creates the list of particles.
148 gROOT->GetListOfBrowsables()->Add(this,name);
150 // create the support list for the various Detectors
151 fModules = new TObjArray(77);
153 // Create the TNode geometry for the event display
155 BuildSimpleGeometry();
165 // Create the particle stack
166 fParticles = new TClonesArray("TParticle",100);
170 // Create default mag field
175 // Prepare the tracking medium lists
176 fImedia = new TArrayI(1000);
177 for(i=0;i<1000;i++) (*fImedia)[i]=-99;
180 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
182 // Create HitLists list
183 fHitLists = new TList();
186 //_____________________________________________________________________________
190 // Defaullt AliRun destructor
209 fParticles->Delete();
215 //_____________________________________________________________________________
216 void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
219 // Add a hit to detector id
221 TObjArray &dets = *fModules;
222 if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits);
225 //_____________________________________________________________________________
226 void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
229 // Add digit to detector id
231 TObjArray &dets = *fModules;
232 if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits);
235 //_____________________________________________________________________________
236 void AliRun::Browse(TBrowser *b)
239 // Called when the item "Run" is clicked on the left pane
240 // of the Root browser.
241 // It displays the Root Trees and all detectors.
243 if (fTreeK) b->Add(fTreeK,fTreeK->GetName());
244 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
245 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
246 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
247 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
249 TIter next(fModules);
251 while((detector = (AliModule*)next())) {
252 b->Add(detector,detector->GetName());
256 //_____________________________________________________________________________
260 // Initialize Alice geometry
265 //_____________________________________________________________________________
266 void AliRun::BuildSimpleGeometry()
269 // Create a simple TNode geometry used by Root display engine
271 // Initialise geometry
273 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
274 new TMaterial("void","Vacuum",0,0,0); //Everything is void
275 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
276 brik->SetVisibility(0);
277 new TNode("alice","alice","S_alice");
280 //_____________________________________________________________________________
281 void AliRun::CleanDetectors()
284 // Clean Detectors at the end of event
286 TIter next(fModules);
288 while((detector = (AliModule*)next())) {
289 detector->FinishEvent();
293 //_____________________________________________________________________________
294 void AliRun::CleanParents()
297 // Clean Particles stack.
298 // Set parent/daughter relations
300 TClonesArray &particles = *(gAlice->Particles());
303 for(i=0; i<fNtrack; i++) {
304 part = (TParticle *)particles.UncheckedAt(i);
305 if(!part->TestBit(Daughters_Bit)) {
306 part->SetFirstDaughter(-1);
307 part->SetLastDaughter(-1);
312 //_____________________________________________________________________________
313 Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
316 // Return the distance from the mouse to the AliRun object
322 //_____________________________________________________________________________
323 void AliRun::DumpPart (Int_t i)
326 // Dumps particle i in the stack
328 TClonesArray &particles = *fParticles;
329 ((TParticle*) particles[i])->Print();
332 //_____________________________________________________________________________
333 void AliRun::DumpPStack ()
336 // Dumps the particle stack
338 TClonesArray &particles = *fParticles;
340 "\n\n=======================================================================\n");
341 for (Int_t i=0;i<fNtrack;i++)
343 printf("-> %d ",i); ((TParticle*) particles[i])->Print();
344 printf("--------------------------------------------------------------\n");
347 "\n=======================================================================\n\n");
350 //_____________________________________________________________________________
351 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
352 Float_t maxField, char* filename)
355 // Set magnetic field parameters
356 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
357 // version Magnetic field map version (only 1 active now)
358 // scale Scale factor for the magnetic field
359 // maxField Maximum value for the magnetic field
362 // --- Sanity check on mag field flags
363 if(type<0 || type > 2) {
365 "Invalid magnetic field flag: %5d; Helix tracking chosen instead\n"
369 if(fField) delete fField;
371 fField = new AliMagFC("Map1"," ",type,version,scale,maxField);
372 } else if(version<=3) {
373 fField = new AliMagFCM("Map2-3",filename,type,version,scale,maxField);
376 Warning("SetField","Invalid map %d\n",version);
380 //_____________________________________________________________________________
381 void AliRun::FillTree()
384 // Fills all AliRun TTrees
386 if (fTreeK) fTreeK->Fill();
387 if (fTreeH) fTreeH->Fill();
388 if (fTreeD) fTreeD->Fill();
389 if (fTreeR) fTreeR->Fill();
392 //_____________________________________________________________________________
393 void AliRun::FinishPrimary()
396 // Called at the end of each primary track
399 // static Int_t count=0;
400 // const Int_t times=10;
401 // This primary is finished, purify stack
402 gAlice->PurifyKine();
404 // Write out hits if any
405 if (gAlice->TreeH()) {
406 gAlice->TreeH()->Fill();
413 // if(++count%times==1) gObjectTable->Print();
416 //_____________________________________________________________________________
417 void AliRun::FinishEvent()
420 // Called at the end of the event.
423 //Update the energy deposit tables
425 for(i=0;i<sEventEnergy.GetSize();i++) {
426 sSummEnergy[i]+=sEventEnergy[i];
427 sSum2Energy[i]+=sEventEnergy[i]*sEventEnergy[i];
429 sEventEnergy.Reset();
431 // Clean detector information
434 // Write out the kinematics
440 // Write out the digits
446 // Write out reconstructed clusters
451 // Write out the event Header information
452 if (fTreeE) fTreeE->Fill();
457 // Write Tree headers
458 // Int_t ievent = fHeader.GetEvent();
460 // sprintf(hname,"TreeK%d",ievent);
461 if (fTreeK) fTreeK->Write();
462 // sprintf(hname,"TreeH%d",ievent);
463 if (fTreeH) fTreeH->Write();
464 // sprintf(hname,"TreeD%d",ievent);
465 if (fTreeD) fTreeD->Write();
466 // sprintf(hname,"TreeR%d",ievent);
467 if (fTreeR) fTreeR->Write();
470 //_____________________________________________________________________________
471 void AliRun::FinishRun()
474 // Called at the end of the run.
477 // Clean detector information
478 TIter next(fModules);
480 while((detector = (AliModule*)next())) {
481 detector->FinishRun();
484 //Output energy summary tables
487 // file is retrieved from whatever tree
489 if (fTreeK) File = fTreeK->GetCurrentFile();
490 if ((!File) && (fTreeH)) File = fTreeH->GetCurrentFile();
491 if ((!File) && (fTreeD)) File = fTreeD->GetCurrentFile();
492 if ((!File) && (fTreeE)) File = fTreeE->GetCurrentFile();
494 Error("FinishRun","There isn't root file!");
500 // Clean tree information
501 delete fTreeK; fTreeK = 0;
502 delete fTreeH; fTreeH = 0;
503 delete fTreeD; fTreeD = 0;
504 delete fTreeR; fTreeR = 0;
505 delete fTreeE; fTreeE = 0;
507 // Write AliRun info and all detectors parameters
514 //_____________________________________________________________________________
515 void AliRun::FlagTrack(Int_t track)
518 // Flags a track and all its family tree to be kept
525 particle=(TParticle*)fParticles->UncheckedAt(curr);
527 // If the particle is flagged the three from here upward is saved already
528 if(particle->TestBit(Keep_Bit)) return;
530 // Save this particle
531 particle->SetBit(Keep_Bit);
533 // Move to father if any
534 if((curr=particle->GetFirstMother())==-1) return;
538 //_____________________________________________________________________________
539 void AliRun::EnergySummary()
542 // Print summary of deposited energy
548 Int_t kn, i, left, j, id;
549 const Float_t zero=0;
550 Int_t ievent=fHeader.GetEvent()+1;
552 // Energy loss information
554 printf("***************** Energy Loss Information per event (GEV) *****************\n");
555 for(kn=1;kn<sEventEnergy.GetSize();kn++) {
558 sEventEnergy[ndep]=kn;
563 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,zero))/ed;
566 sSummEnergy[ndep]=ed;
567 sSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,zero));
572 for(kn=0;kn<(ndep-1)/3+1;kn++) {
574 for(i=0;i<(3<left?3:left);i++) {
576 id=Int_t (sEventEnergy[j]+0.1);
577 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),sSummEnergy[j],sSum2Energy[j]);
582 // Relative energy loss in different detectors
583 printf("******************** Relative Energy Loss per event ********************\n");
584 printf("Total energy loss per event %10.3f GeV\n",edtot);
585 for(kn=0;kn<(ndep-1)/5+1;kn++) {
587 for(i=0;i<(5<left?5:left);i++) {
589 id=Int_t (sEventEnergy[j]+0.1);
590 printf(" %s %10.3f%%;",gMC->VolName(id),100*sSummEnergy[j]/edtot);
594 for(kn=0;kn<75;kn++) printf("*");
598 // Reset the TArray's
599 // sEventEnergy.Set(0);
600 // sSummEnergy.Set(0);
601 // sSum2Energy.Set(0);
604 //_____________________________________________________________________________
605 AliModule *AliRun::GetModule(const char *name)
608 // Return pointer to detector from name
610 return (AliModule*)fModules->FindObject(name);
613 //_____________________________________________________________________________
614 AliDetector *AliRun::GetDetector(const char *name)
617 // Return pointer to detector from name
619 return (AliDetector*)fModules->FindObject(name);
622 //_____________________________________________________________________________
623 Int_t AliRun::GetModuleID(const char *name)
626 // Return galice internal detector identifier from name
629 TObject *mod=fModules->FindObject(name);
630 if(mod) i=fModules->IndexOf(mod);
634 //_____________________________________________________________________________
635 Int_t AliRun::GetEvent(Int_t event)
638 // Connect the Trees Kinematics and Hits for event # event
639 // Set branch addresses
642 // Reset existing structures
647 // Delete Trees already connected
648 if (fTreeK) delete fTreeK;
649 if (fTreeH) delete fTreeH;
650 if (fTreeD) delete fTreeD;
651 if (fTreeR) delete fTreeR;
653 // Get header from file
654 if(fTreeE) fTreeE->GetEntry(event);
655 else Error("GetEvent","Cannot file Header Tree\n");
657 // Get Kine Tree from file
659 sprintf(treeName,"TreeK%d",event);
660 fTreeK = (TTree*)gDirectory->Get(treeName);
661 if (fTreeK) fTreeK->SetBranchAddress("Particles", &fParticles);
662 else Error("GetEvent","cannot find Kine Tree for event:%d\n",event);
664 // Get Hits Tree header from file
665 sprintf(treeName,"TreeH%d",event);
666 fTreeH = (TTree*)gDirectory->Get(treeName);
668 Error("GetEvent","cannot find Hits Tree for event:%d\n",event);
671 // Get Digits Tree header from file
672 sprintf(treeName,"TreeD%d",event);
673 fTreeD = (TTree*)gDirectory->Get(treeName);
675 Warning("GetEvent","cannot find Digits Tree for event:%d\n",event);
679 // Get Reconstruct Tree header from file
680 sprintf(treeName,"TreeR%d",event);
681 fTreeR = (TTree*)gDirectory->Get(treeName);
683 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
686 // Set Trees branch addresses
687 TIter next(fModules);
689 while((detector = (AliModule*)next())) {
690 detector->SetTreeAddress();
693 if (fTreeK) fTreeK->GetEvent(0);
694 fNtrack = Int_t (fParticles->GetEntries());
698 //_____________________________________________________________________________
699 TGeometry *AliRun::GetGeometry()
702 // Import Alice geometry from current file
703 // Return pointer to geometry object
705 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
707 // Unlink and relink nodes in detectors
708 // This is bad and there must be a better way...
711 TIter next(fModules);
713 while((detector = (AliModule*)next())) {
714 detector->SetTreeAddress();
715 TList *dnodes=detector->Nodes();
718 for ( j=0; j<dnodes->GetSize(); j++) {
719 node = (TNode*) dnodes->At(j);
720 node1 = fGeometry->GetNode(node->GetName());
721 dnodes->Remove(node);
722 dnodes->AddAt(node1,j);
728 //_____________________________________________________________________________
729 void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
730 Float_t &e, Float_t *vpos, Float_t *polar,
734 // Return next track from stack of particles
739 for(Int_t i=fNtrack-1; i>=0; i--) {
740 track=(TParticle*) fParticles->UncheckedAt(i);
741 if(!track->TestBit(Done_Bit)) {
743 // The track has not yet been processed
745 ipart=track->GetPdgCode();
753 track->GetPolarisation(pol);
758 track->SetBit(Done_Bit);
764 // stop and start timer when we start a primary track
765 Int_t nprimaries = fHeader.GetNprimary();
766 if (fCurrent >= nprimaries) return;
767 if (fCurrent < nprimaries-1) {
769 track=(TParticle*) fParticles->UncheckedAt(fCurrent+1);
770 // track->SetProcessTime(fTimer.CpuTime());
775 //_____________________________________________________________________________
776 Int_t AliRun::GetPrimary(Int_t track)
779 // return number of primary that has generated track
787 part = (TParticle *)fParticles->UncheckedAt(current);
788 parent=part->GetFirstMother();
789 if(parent<0) return current;
793 //_____________________________________________________________________________
794 void AliRun::Init(const char *setup)
797 // Initialize the Alice setup
800 gROOT->LoadMacro(setup);
801 gInterpreter->ProcessLine("Config();");
803 gMC->DefineParticles(); //Create standard MC particles
805 TObject *objfirst, *objlast;
807 fNdets = fModules->GetLast()+1;
810 //=================Create Materials, geometry, histograms, etc
811 TIter next(fModules);
813 while((detector = (AliModule*)next())) {
814 detector->SetTreeAddress();
815 objlast = gDirectory->GetList()->Last();
817 // Initialise detector materials, geometry, histograms,etc
818 detector->CreateMaterials();
819 detector->CreateGeometry();
820 detector->BuildGeometry();
823 // Add Detector histograms in Detector list of histograms
824 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
825 else objfirst = gDirectory->GetList()->First();
827 detector->Histograms()->Add(objfirst);
828 objfirst = gDirectory->GetList()->After(objfirst);
831 SetTransPar(); //Read the cuts for all materials
833 MediaTable(); //Build the special IMEDIA table
835 //Terminate building of geometry
837 gVMC->FinishGeometry();
839 //Initialise geometry deposition table
840 sEventEnergy.Set(gMC->NofVolumes()+1);
841 sSummEnergy.Set(gMC->NofVolumes()+1);
842 sSum2Energy.Set(gMC->NofVolumes()+1);
844 //Compute cross-sections
845 gVMC->BuildPhysics();
847 //Write Geometry object to current file.
853 //_____________________________________________________________________________
854 void AliRun::MediaTable()
857 // Built media table to get from the media number to
860 Int_t kz, nz, idt, lz, i, k, ind;
862 TObjArray &dets = *gAlice->Detectors();
866 for (kz=0;kz<fNdets;kz++) {
867 // If detector is defined
868 if((det=(AliModule*) dets[kz])) {
869 TArrayI &idtmed = *(det->GetIdtmed());
870 for(nz=0;nz<100;nz++) {
871 // Find max and min material number
872 if((idt=idtmed[nz])) {
873 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
874 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
877 if(det->LoMedium() > det->HiMedium()) {
881 if(det->HiMedium() > fImedia->GetSize()) {
882 Error("MediaTable","Increase fImedia from %d to %d",
883 fImedia->GetSize(),det->HiMedium());
886 // Tag all materials in rage as belonging to detector kz
887 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
894 // Print summary table
895 printf(" Traking media ranges:\n");
896 for(i=0;i<(fNdets-1)/6+1;i++) {
897 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
899 det=(AliModule*)dets[ind];
901 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
904 printf(" %6s: %3d -> %3d;","NULL",0,0);
910 //____________________________________________________________________________
911 void AliRun::SetGenerator(AliGenerator *generator)
914 // Load the event generator
916 if(!fGenerator) fGenerator = generator;
919 //____________________________________________________________________________
920 void AliRun::ResetGenerator(AliGenerator *generator)
923 // Load the event generator
926 Warning("ResetGenerator","Replacing generator %s with %s\n",
927 fGenerator->GetName(),generator->GetName());
928 fGenerator = generator;
931 //____________________________________________________________________________
932 void AliRun::SetTransPar(char* filename)
935 // Read filename to set the transport parameters
939 const Int_t ncuts=10;
940 const Int_t nflags=11;
941 const Int_t npars=ncuts+nflags;
942 const char pars[npars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
943 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
944 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
945 "MULS","PAIR","PHOT","RAYL"};
951 Int_t i, itmed, iret, ktmed, kz;
954 // See whether the file is there
955 filtmp=gSystem->ExpandPathName(filename);
956 lun=fopen(filtmp,"r");
959 Warning("SetTransPar","File %s does not exist!\n",filename);
963 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
964 printf(" *%59s\n","*");
965 printf(" * Please check carefully what you are doing!%10s\n","*");
966 printf(" *%59s\n","*");
969 // Initialise cuts and flags
970 for(i=0;i<ncuts;i++) cut[i]=-99;
971 for(i=0;i<nflags;i++) flag[i]=-99;
973 for(i=0;i<256;i++) line[i]='\0';
974 // Read up to the end of line excluded
975 iret=fscanf(lun,"%[^\n]",line);
979 printf(" *%59s\n","*");
980 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
983 // Read the end of line
986 if(line[0]=='*') continue;
988 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",
989 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
990 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
991 &flag[8],&flag[9],&flag[10]);
995 Warning("SetTransPar","Error reading file %s\n",filename);
998 // Check that the module exist
999 AliModule *mod = GetModule(detName);
1001 // Get the array of media numbers
1002 TArrayI &idtmed = *mod->GetIdtmed();
1003 // Check that the tracking medium code is valid
1004 if(0<=itmed && itmed < 100) {
1005 ktmed=idtmed[itmed];
1007 Warning("SetTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
1010 // Set energy thresholds
1011 for(kz=0;kz<ncuts;kz++) {
1013 printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
1014 pars[kz],cut[kz],itmed,mod->GetName());
1015 gMC->Gstpar(ktmed,pars[kz],cut[kz]);
1018 // Set transport mechanisms
1019 for(kz=0;kz<nflags;kz++) {
1021 printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
1022 pars[ncuts+kz],flag[kz],itmed,mod->GetName());
1023 gMC->Gstpar(ktmed,pars[ncuts+kz],Float_t(flag[kz]));
1027 Warning("SetTransPar","Invalid medium code %d *\n",itmed);
1031 Warning("SetTransPar","Module %s not present\n",detName);
1037 //_____________________________________________________________________________
1038 void AliRun::MakeTree(Option_t *option)
1041 // Create the ROOT trees
1042 // Loop on all detectors to create the Root branch (if any)
1048 char *K = strstr(option,"K");
1049 char *H = strstr(option,"H");
1050 char *E = strstr(option,"E");
1051 char *D = strstr(option,"D");
1052 char *R = strstr(option,"R");
1055 sprintf(hname,"TreeK%d",fEvent);
1056 fTreeK = new TTree(hname,"Kinematics");
1057 // Create a branch for particles
1058 fTreeK->Branch("Particles",&fParticles,4000);
1061 sprintf(hname,"TreeH%d",fEvent);
1062 fTreeH = new TTree(hname,"Hits");
1063 fTreeH->SetAutoSave(1000000000); //no autosave
1066 sprintf(hname,"TreeD%d",fEvent);
1067 fTreeD = new TTree(hname,"Digits");
1070 sprintf(hname,"TreeR%d",fEvent);
1071 fTreeR = new TTree(hname,"Reconstruction");
1074 fTreeE = new TTree("TE","Header");
1075 // Create a branch for Header
1076 fTreeE->Branch("Header","AliHeader",&header,4000);
1079 // Create a branch for hits/digits for each detector
1080 // Each branch is a TClonesArray. Each data member of the Hits classes
1081 // will be in turn a subbranch of the detector master branch
1082 TIter next(fModules);
1083 AliModule *detector;
1084 while((detector = (AliModule*)next())) {
1085 if (H || D || R) detector->MakeBranch(option);
1089 //_____________________________________________________________________________
1090 Int_t AliRun::PurifyKine(Int_t lastSavedTrack, Int_t nofTracks)
1093 // PurifyKine with external parameters
1095 fHgwmk = lastSavedTrack;
1096 fNtrack = nofTracks;
1101 //_____________________________________________________________________________
1102 void AliRun::PurifyKine()
1105 // Compress kinematic tree keeping only flagged particles
1106 // and renaming the particle id's in all the hits
1108 TClonesArray &particles = *fParticles;
1109 int nkeep=fHgwmk+1, parent, i;
1110 TParticle *part, *partnew, *father;
1111 int *map = new int[particles.GetEntries()];
1113 // Save in Header total number of tracks before compression
1114 fHeader.SetNtrack(fHeader.GetNtrack()+fNtrack-fHgwmk);
1116 // Preset map, to be removed later
1117 for(i=0; i<fNtrack; i++) {
1118 if(i<=fHgwmk) map[i]=i ; else map[i] = -99 ;}
1119 // Second pass, build map between old and new numbering
1120 for(i=fHgwmk+1; i<fNtrack; i++) {
1121 part = (TParticle *)particles.UncheckedAt(i);
1122 if(part->TestBit(Keep_Bit)) {
1124 // This particle has to be kept
1128 // Old and new are different, have to copy
1129 partnew = (TParticle *)particles.UncheckedAt(nkeep);
1131 } else partnew = part;
1133 // as the parent is always *before*, it must be already
1134 // in place. This is what we are checking anyway!
1135 if((parent=partnew->GetFirstMother())>fHgwmk) {
1136 if(map[parent]==-99) printf("map[%d] = -99!\n",parent);
1137 partnew->SetFirstMother(map[parent]);
1144 // Fix daughters information
1145 for (i=0; i<fNtrack; i++) {
1146 part = (TParticle *)particles.UncheckedAt(i);
1147 parent = part->GetFirstMother();
1149 father = (TParticle *)particles.UncheckedAt(parent);
1150 if(father->TestBit(Daughters_Bit)) {
1152 if(i<father->GetFirstDaughter()) father->SetFirstDaughter(i);
1153 if(i>father->GetLastDaughter()) father->SetLastDaughter(i);
1155 // Iitialise daughters info for first pass
1156 father->SetFirstDaughter(i);
1157 father->SetLastDaughter(i);
1158 father->SetBit(Daughters_Bit);
1164 // Now loop on all detectors and reset the hits
1166 TIter next(fModules);
1167 AliModule *detector;
1168 while((detector = (AliModule*)next())) {
1169 if (!detector->Hits()) continue;
1170 TClonesArray &vHits=*(detector->Hits());
1171 if(vHits.GetEntries() != detector->GetNhits())
1172 printf("vHits.GetEntries()!=detector->GetNhits(): %d != %d\n",
1173 vHits.GetEntries(),detector->GetNhits());
1174 for (i=0; i<detector->GetNhits(); i++) {
1175 OneHit = (AliHit *)vHits.UncheckedAt(i);
1176 OneHit->SetTrack(map[OneHit->GetTrack()]);
1181 // Now loop on all registered hit lists
1182 TIter next(fHitLists);
1183 TCollection *hitList;
1184 while((hitList = (TCollection*)next())) {
1185 TIter nexthit(hitList);
1187 while((hit = (AliHit*)nexthit())) {
1188 hit->SetTrack(map[hit->GetTrack()]);
1194 particles.SetLast(fHgwmk);
1198 //_____________________________________________________________________________
1199 void AliRun::Reset(Int_t run, Int_t idevent)
1202 // Reset all Detectors & kinematics & trees
1210 // Initialise event header
1211 fHeader.Reset(run,idevent);
1215 sprintf(hname,"TreeK%d",idevent);
1216 fTreeK->SetName(hname);
1220 sprintf(hname,"TreeH%d",idevent);
1221 fTreeH->SetName(hname);
1225 sprintf(hname,"TreeD%d",idevent);
1226 fTreeD->SetName(hname);
1230 sprintf(hname,"TreeR%d",idevent);
1231 fTreeR->SetName(hname);
1235 //_____________________________________________________________________________
1236 void AliRun::ResetDigits()
1239 // Reset all Detectors digits
1241 TIter next(fModules);
1242 AliModule *detector;
1243 while((detector = (AliModule*)next())) {
1244 detector->ResetDigits();
1248 //_____________________________________________________________________________
1249 void AliRun::ResetHits()
1252 // Reset all Detectors hits
1254 TIter next(fModules);
1255 AliModule *detector;
1256 while((detector = (AliModule*)next())) {
1257 detector->ResetHits();
1261 //_____________________________________________________________________________
1262 void AliRun::ResetPoints()
1265 // Reset all Detectors points
1267 TIter next(fModules);
1268 AliModule *detector;
1269 while((detector = (AliModule*)next())) {
1270 detector->ResetPoints();
1274 //_____________________________________________________________________________
1275 void AliRun::Run(Int_t nevent, const char *setup)
1278 // Main function to be called to process a galice run
1280 // Root > gAlice.Run();
1281 // a positive number of events will cause the finish routine
1286 // check if initialisation has been done
1287 if (!fInitDone) Init(setup);
1289 // Create the Root Tree with one branch per detector
1290 gAlice->MakeTree("KHDER");
1292 todo = TMath::Abs(nevent);
1293 for (i=0; i<todo; i++) {
1294 // Process one run (one run = one event)
1295 gAlice->Reset(fRun, fEvent);
1296 gVMC->ProcessEvent();
1297 gAlice->FinishEvent();
1301 // End of this run, close files
1302 if(nevent>0) gAlice->FinishRun();
1305 //_____________________________________________________________________________
1306 void AliRun::RunLego(const char *setup,Int_t ntheta,Float_t themin,
1307 Float_t themax,Int_t nphi,Float_t phimin,Float_t phimax,
1308 Float_t rmin,Float_t rmax,Float_t zmax)
1311 // Generates lego plots of:
1312 // - radiation length map phi vs theta
1313 // - radiation length map phi vs eta
1314 // - interaction length map
1315 // - g/cm2 length map
1317 // ntheta bins in theta, eta
1318 // themin minimum angle in theta (degrees)
1319 // themax maximum angle in theta (degrees)
1321 // phimin minimum angle in phi (degrees)
1322 // phimax maximum angle in phi (degrees)
1323 // rmin minimum radius
1324 // rmax maximum radius
1327 // The number of events generated = ntheta*nphi
1328 // run input parameters in macro setup (default="Config.C")
1330 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1333 <img src="picts/AliRunLego1.gif">
1338 <img src="picts/AliRunLego2.gif">
1343 <img src="picts/AliRunLego3.gif">
1348 // check if initialisation has been done
1349 if (!fInitDone) Init(setup);
1351 //Create Lego object
1352 fLego = new AliLego("lego",ntheta,themin,themax,nphi,phimin,phimax,rmin,rmax,zmax);
1357 // Create only the Root event Tree
1358 gAlice->MakeTree("E");
1360 // End of this run, close files
1361 gAlice->FinishRun();
1364 //_____________________________________________________________________________
1365 void AliRun::SetCurrentTrack(Int_t track)
1368 // Set current track number
1373 //_____________________________________________________________________________
1374 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1375 Float_t *vpos, Float_t *polar, Float_t tof,
1376 const char *mecha, Int_t &ntr, Float_t weight)
1379 // Load a track on the stack
1381 // done 0 if the track has to be transported
1383 // parent identifier of the parent track. -1 for a primary
1384 // pdg particle code
1385 // pmom momentum GeV/c
1387 // polar polarisation
1388 // tof time of flight in seconds
1389 // mecha production mechanism
1390 // ntr on output the number of the track stored
1392 TClonesArray &particles = *fParticles;
1393 TParticle *particle;
1395 const Int_t firstdaughter=-1;
1396 const Int_t lastdaughter=-1;
1398 // const Float_t tlife=0;
1401 // Here we get the static mass
1402 // For MC is ok, but a more sophisticated method could be necessary
1403 // if the calculated mass is required
1404 // also, this method is potentially dangerous if the mass
1405 // used in the MC is not the same of the PDG database
1407 mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
1408 Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+
1409 pmom[1]*pmom[1]+pmom[2]*pmom[2]);
1411 //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",
1412 //pname,mass,e,fNtrack,pdg,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],KS,mecha);
1414 particle=new(particles[fNtrack]) TParticle(pdg,KS,parent,-1,firstdaughter,
1415 lastdaughter,pmom[0],pmom[1],pmom[2],
1416 e,vpos[0],vpos[1],vpos[2],tof);
1417 // polar[0],polar[1],polar[2],tof,
1419 ((TParticle*)particles[fNtrack])->SetPolarisation(TVector3(polar[0],polar[1],polar[2]));
1420 ((TParticle*)particles[fNtrack])->SetWeight(weight);
1421 if(!done) particle->SetBit(Done_Bit);
1424 particle=(TParticle*) fParticles->UncheckedAt(parent);
1425 particle->SetLastDaughter(fNtrack);
1426 if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack);
1429 // This is a primary track. Set high water mark for this event
1432 // Set also number if primary tracks
1433 fHeader.SetNprimary(fHgwmk+1);
1434 fHeader.SetNtrack(fHgwmk+1);
1439 //_____________________________________________________________________________
1440 void AliRun::KeepTrack(const Int_t track)
1443 // flags a track to be kept
1445 TClonesArray &particles = *fParticles;
1446 ((TParticle*)particles[track])->SetBit(Keep_Bit);
1449 //_____________________________________________________________________________
1450 void AliRun::StepManager(Int_t id) const
1453 // Called at every step during transport
1457 // --- If lego option, do it and leave
1459 fLego->StepManager();
1462 //Update energy deposition tables
1463 sEventEnergy[gMC->CurrentVolID(copy)]+=gMC->Edep();
1465 //Call the appropriate stepping routine;
1466 AliModule *det = (AliModule*)fModules->At(id);
1467 if(det) det->StepManager();
1471 //_____________________________________________________________________________
1472 void AliRun::Streamer(TBuffer &R__b)
1475 // Stream an object of class AliRun.
1477 if (R__b.IsReading()) {
1478 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1479 TNamed::Streamer(R__b);
1480 if (!gAlice) gAlice = this;
1481 gROOT->GetListOfBrowsables()->Add(this,"Run");
1482 fTreeE = (TTree*)gDirectory->Get("TE");
1483 if (fTreeE) fTreeE->SetBranchAddress("Header", &header);
1484 else Error("Streamer","cannot find Header Tree\n");
1488 fHeader.Streamer(R__b);
1498 R__b >> fPDGDB; //Particle factory object!
1499 fTreeE->GetEntry(0);
1501 fHeader.SetEvent(0);
1502 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
1505 R__b.WriteVersion(AliRun::IsA());
1506 TNamed::Streamer(R__b);
1510 fHeader.Streamer(R__b);
1519 R__b << fPDGDB; //Particle factory object!