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.28 2000/04/05 06:51:06 fca
19 Workaround for an HP compiler problem
21 Revision 1.27 2000/03/22 18:08:07 fca
22 Rationalisation of the virtual MC interfaces
24 Revision 1.26 2000/03/22 13:42:26 fca
25 SetGenerator does not replace an existing generator, ResetGenerator does
27 Revision 1.25 2000/02/23 16:25:22 fca
28 AliVMC and AliGeant3 classes introduced
29 ReadEuclid moved from AliRun to AliModule
31 Revision 1.24 2000/01/19 17:17:20 fca
32 Introducing a list of lists of hits -- more hits allowed for detector now
34 Revision 1.23 1999/12/03 11:14:31 fca
35 Fixing previous wrong checking
37 Revision 1.21 1999/11/25 10:40:08 fca
38 Fixing daughters information also in primary tracks
40 Revision 1.20 1999/10/04 18:08:49 fca
41 Adding protection against inconsistent Euclid files
43 Revision 1.19 1999/09/29 07:50:40 fca
44 Introduction of the Copyright and cvs Log
48 ///////////////////////////////////////////////////////////////////////////////
50 // Control class for Alice C++ //
51 // Only one single instance of this class exists. //
52 // The object is created in main program aliroot //
53 // and is pointed by the global gAlice. //
55 // -Supports the list of all Alice Detectors (fModules). //
56 // -Supports the list of particles (fParticles). //
57 // -Supports the Trees. //
58 // -Supports the geometry. //
59 // -Supports the event display. //
62 <img src="picts/AliRunClass.gif">
67 <img src="picts/alirun.gif">
71 ///////////////////////////////////////////////////////////////////////////////
79 #include <TObjectTable.h>
81 #include "TParticle.h"
83 #include "AliDisplay.h"
92 static AliHeader *header;
96 //_____________________________________________________________________________
100 // Default constructor for AliRun
124 fPDGDB = 0; //Particle factory object!
128 //_____________________________________________________________________________
129 AliRun::AliRun(const char *name, const char *title)
133 // Constructor for the main processor.
134 // Creates the geometry
135 // Creates the list of Detectors.
136 // Creates the list of particles.
153 gROOT->GetListOfBrowsables()->Add(this,name);
155 // create the support list for the various Detectors
156 fModules = new TObjArray(77);
158 // Create the TNode geometry for the event display
160 BuildSimpleGeometry();
170 // Create the particle stack
171 fParticles = new TClonesArray("TParticle",100);
175 // Create default mag field
180 // Prepare the tracking medium lists
181 fImedia = new TArrayI(1000);
182 for(i=0;i<1000;i++) (*fImedia)[i]=-99;
185 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
187 // Create HitLists list
188 fHitLists = new TList();
191 //_____________________________________________________________________________
195 // Defaullt AliRun destructor
214 fParticles->Delete();
220 //_____________________________________________________________________________
221 void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
224 // Add a hit to detector id
226 TObjArray &dets = *fModules;
227 if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits);
230 //_____________________________________________________________________________
231 void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
234 // Add digit to detector id
236 TObjArray &dets = *fModules;
237 if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits);
240 //_____________________________________________________________________________
241 void AliRun::Browse(TBrowser *b)
244 // Called when the item "Run" is clicked on the left pane
245 // of the Root browser.
246 // It displays the Root Trees and all detectors.
248 if (fTreeK) b->Add(fTreeK,fTreeK->GetName());
249 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
250 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
251 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
252 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
254 TIter next(fModules);
256 while((detector = (AliModule*)next())) {
257 b->Add(detector,detector->GetName());
261 //_____________________________________________________________________________
265 // Initialize Alice geometry
270 //_____________________________________________________________________________
271 void AliRun::BuildSimpleGeometry()
274 // Create a simple TNode geometry used by Root display engine
276 // Initialise geometry
278 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
279 new TMaterial("void","Vacuum",0,0,0); //Everything is void
280 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
281 brik->SetVisibility(0);
282 new TNode("alice","alice","S_alice");
285 //_____________________________________________________________________________
286 void AliRun::CleanDetectors()
289 // Clean Detectors at the end of event
291 TIter next(fModules);
293 while((detector = (AliModule*)next())) {
294 detector->FinishEvent();
298 //_____________________________________________________________________________
299 void AliRun::CleanParents()
302 // Clean Particles stack.
303 // Set parent/daughter relations
305 TClonesArray &particles = *(gAlice->Particles());
308 for(i=0; i<fNtrack; i++) {
309 part = (TParticle *)particles.UncheckedAt(i);
310 if(!part->TestBit(Daughters_Bit)) {
311 part->SetFirstDaughter(-1);
312 part->SetLastDaughter(-1);
317 //_____________________________________________________________________________
318 Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
321 // Return the distance from the mouse to the AliRun object
327 //_____________________________________________________________________________
328 void AliRun::DumpPart (Int_t i)
331 // Dumps particle i in the stack
333 TClonesArray &particles = *fParticles;
334 ((TParticle*) particles[i])->Print();
337 //_____________________________________________________________________________
338 void AliRun::DumpPStack ()
341 // Dumps the particle stack
343 TClonesArray &particles = *fParticles;
345 "\n\n=======================================================================\n");
346 for (Int_t i=0;i<fNtrack;i++)
348 printf("-> %d ",i); ((TParticle*) particles[i])->Print();
349 printf("--------------------------------------------------------------\n");
352 "\n=======================================================================\n\n");
355 //_____________________________________________________________________________
356 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
357 Float_t maxField, char* filename)
360 // Set magnetic field parameters
361 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
362 // version Magnetic field map version (only 1 active now)
363 // scale Scale factor for the magnetic field
364 // maxField Maximum value for the magnetic field
367 // --- Sanity check on mag field flags
368 if(type<0 || type > 2) {
370 "Invalid magnetic field flag: %5d; Helix tracking chosen instead\n"
374 if(fField) delete fField;
376 fField = new AliMagFC("Map1"," ",type,version,scale,maxField);
377 } else if(version<=3) {
378 fField = new AliMagFCM("Map2-3",filename,type,version,scale,maxField);
381 Warning("SetField","Invalid map %d\n",version);
385 //_____________________________________________________________________________
386 void AliRun::FillTree()
389 // Fills all AliRun TTrees
391 if (fTreeK) fTreeK->Fill();
392 if (fTreeH) fTreeH->Fill();
393 if (fTreeD) fTreeD->Fill();
394 if (fTreeR) fTreeR->Fill();
397 //_____________________________________________________________________________
398 void AliRun::FinishPrimary()
401 // Called at the end of each primary track
404 // static Int_t count=0;
405 // const Int_t times=10;
406 // This primary is finished, purify stack
409 // Write out hits if any
410 if (gAlice->TreeH()) {
411 gAlice->TreeH()->Fill();
418 // if(++count%times==1) gObjectTable->Print();
421 //_____________________________________________________________________________
422 void AliRun::FinishEvent()
425 // Called at the end of the event.
428 //Update the energy deposit tables
430 for(i=0;i<fEventEnergy.GetSize();i++) {
431 fSummEnergy[i]+=fEventEnergy[i];
432 fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
434 fEventEnergy.Reset();
436 // Clean detector information
439 // Write out the kinematics
445 // Write out the digits
451 // Write out reconstructed clusters
456 // Write out the event Header information
457 if (fTreeE) fTreeE->Fill();
462 // Write Tree headers
463 // Int_t ievent = fHeader.GetEvent();
465 // sprintf(hname,"TreeK%d",ievent);
466 if (fTreeK) fTreeK->Write();
467 // sprintf(hname,"TreeH%d",ievent);
468 if (fTreeH) fTreeH->Write();
469 // sprintf(hname,"TreeD%d",ievent);
470 if (fTreeD) fTreeD->Write();
471 // sprintf(hname,"TreeR%d",ievent);
472 if (fTreeR) fTreeR->Write();
477 //_____________________________________________________________________________
478 void AliRun::FinishRun()
481 // Called at the end of the run.
484 // Clean detector information
485 TIter next(fModules);
487 while((detector = (AliModule*)next())) {
488 detector->FinishRun();
491 //Output energy summary tables
494 // file is retrieved from whatever tree
496 if (fTreeK) File = fTreeK->GetCurrentFile();
497 if ((!File) && (fTreeH)) File = fTreeH->GetCurrentFile();
498 if ((!File) && (fTreeD)) File = fTreeD->GetCurrentFile();
499 if ((!File) && (fTreeE)) File = fTreeE->GetCurrentFile();
501 Error("FinishRun","There isn't root file!");
507 // Clean tree information
508 delete fTreeK; fTreeK = 0;
509 delete fTreeH; fTreeH = 0;
510 delete fTreeD; fTreeD = 0;
511 delete fTreeR; fTreeR = 0;
512 delete fTreeE; fTreeE = 0;
514 // Write AliRun info and all detectors parameters
521 //_____________________________________________________________________________
522 void AliRun::FlagTrack(Int_t track)
525 // Flags a track and all its family tree to be kept
532 particle=(TParticle*)fParticles->UncheckedAt(curr);
534 // If the particle is flagged the three from here upward is saved already
535 if(particle->TestBit(Keep_Bit)) return;
537 // Save this particle
538 particle->SetBit(Keep_Bit);
540 // Move to father if any
541 if((curr=particle->GetFirstMother())==-1) return;
545 //_____________________________________________________________________________
546 void AliRun::EnergySummary()
549 // Print summary of deposited energy
555 Int_t kn, i, left, j, id;
556 const Float_t zero=0;
557 Int_t ievent=fHeader.GetEvent()+1;
559 // Energy loss information
561 printf("***************** Energy Loss Information per event (GEV) *****************\n");
562 for(kn=1;kn<fEventEnergy.GetSize();kn++) {
565 fEventEnergy[ndep]=kn;
570 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,zero))/ed;
573 fSummEnergy[ndep]=ed;
574 fSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,zero));
579 for(kn=0;kn<(ndep-1)/3+1;kn++) {
581 for(i=0;i<(3<left?3:left);i++) {
583 id=Int_t (fEventEnergy[j]+0.1);
584 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]);
589 // Relative energy loss in different detectors
590 printf("******************** Relative Energy Loss per event ********************\n");
591 printf("Total energy loss per event %10.3f GeV\n",edtot);
592 for(kn=0;kn<(ndep-1)/5+1;kn++) {
594 for(i=0;i<(5<left?5:left);i++) {
596 id=Int_t (fEventEnergy[j]+0.1);
597 printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot);
601 for(kn=0;kn<75;kn++) printf("*");
605 // Reset the TArray's
606 // fEventEnergy.Set(0);
607 // fSummEnergy.Set(0);
608 // fSum2Energy.Set(0);
611 //_____________________________________________________________________________
612 AliModule *AliRun::GetModule(const char *name)
615 // Return pointer to detector from name
617 return (AliModule*)fModules->FindObject(name);
620 //_____________________________________________________________________________
621 AliDetector *AliRun::GetDetector(const char *name)
624 // Return pointer to detector from name
626 return (AliDetector*)fModules->FindObject(name);
629 //_____________________________________________________________________________
630 Int_t AliRun::GetModuleID(const char *name)
633 // Return galice internal detector identifier from name
636 TObject *mod=fModules->FindObject(name);
637 if(mod) i=fModules->IndexOf(mod);
641 //_____________________________________________________________________________
642 Int_t AliRun::GetEvent(Int_t event)
645 // Connect the Trees Kinematics and Hits for event # event
646 // Set branch addresses
649 // Reset existing structures
654 // Delete Trees already connected
655 if (fTreeK) delete fTreeK;
656 if (fTreeH) delete fTreeH;
657 if (fTreeD) delete fTreeD;
658 if (fTreeR) delete fTreeR;
660 // Get header from file
661 if(fTreeE) fTreeE->GetEntry(event);
662 else Error("GetEvent","Cannot file Header Tree\n");
664 // Get Kine Tree from file
666 sprintf(treeName,"TreeK%d",event);
667 fTreeK = (TTree*)gDirectory->Get(treeName);
668 if (fTreeK) fTreeK->SetBranchAddress("Particles", &fParticles);
669 else Error("GetEvent","cannot find Kine Tree for event:%d\n",event);
671 // Get Hits Tree header from file
672 sprintf(treeName,"TreeH%d",event);
673 fTreeH = (TTree*)gDirectory->Get(treeName);
675 Error("GetEvent","cannot find Hits Tree for event:%d\n",event);
678 // Get Digits Tree header from file
679 sprintf(treeName,"TreeD%d",event);
680 fTreeD = (TTree*)gDirectory->Get(treeName);
682 Warning("GetEvent","cannot find Digits Tree for event:%d\n",event);
686 // Get Reconstruct Tree header from file
687 sprintf(treeName,"TreeR%d",event);
688 fTreeR = (TTree*)gDirectory->Get(treeName);
690 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
693 // Set Trees branch addresses
694 TIter next(fModules);
696 while((detector = (AliModule*)next())) {
697 detector->SetTreeAddress();
700 if (fTreeK) fTreeK->GetEvent(0);
701 fNtrack = Int_t (fParticles->GetEntries());
705 //_____________________________________________________________________________
706 TGeometry *AliRun::GetGeometry()
709 // Import Alice geometry from current file
710 // Return pointer to geometry object
712 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
714 // Unlink and relink nodes in detectors
715 // This is bad and there must be a better way...
718 TIter next(fModules);
720 while((detector = (AliModule*)next())) {
721 detector->SetTreeAddress();
722 TList *dnodes=detector->Nodes();
725 for ( j=0; j<dnodes->GetSize(); j++) {
726 node = (TNode*) dnodes->At(j);
727 node1 = fGeometry->GetNode(node->GetName());
728 dnodes->Remove(node);
729 dnodes->AddAt(node1,j);
735 //_____________________________________________________________________________
736 void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
737 Float_t &e, Float_t *vpos, Float_t *polar,
741 // Return next track from stack of particles
746 for(Int_t i=fNtrack-1; i>=0; i--) {
747 track=(TParticle*) fParticles->UncheckedAt(i);
748 if(!track->TestBit(Done_Bit)) {
750 // The track has not yet been processed
752 ipart=track->GetPdgCode();
760 track->GetPolarisation(pol);
765 track->SetBit(Done_Bit);
771 // stop and start timer when we start a primary track
772 Int_t nprimaries = fHeader.GetNprimary();
773 if (fCurrent >= nprimaries) return;
774 if (fCurrent < nprimaries-1) {
776 track=(TParticle*) fParticles->UncheckedAt(fCurrent+1);
777 // track->SetProcessTime(fTimer.CpuTime());
782 //_____________________________________________________________________________
783 Int_t AliRun::GetPrimary(Int_t track)
786 // return number of primary that has generated track
794 part = (TParticle *)fParticles->UncheckedAt(current);
795 parent=part->GetFirstMother();
796 if(parent<0) return current;
800 //_____________________________________________________________________________
801 void AliRun::InitMC(const char *setup)
804 // Initialize the Alice setup
807 gROOT->LoadMacro(setup);
808 gInterpreter->ProcessLine("Config();");
810 gMC->DefineParticles(); //Create standard MC particles
812 TObject *objfirst, *objlast;
814 fNdets = fModules->GetLast()+1;
817 //=================Create Materials and geometry
820 TIter next(fModules);
822 while((detector = (AliModule*)next())) {
823 detector->SetTreeAddress();
824 objlast = gDirectory->GetList()->Last();
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 //Initialise geometry deposition table
839 fEventEnergy.Set(gMC->NofVolumes()+1);
840 fSummEnergy.Set(gMC->NofVolumes()+1);
841 fSum2Energy.Set(gMC->NofVolumes()+1);
843 //Compute cross-sections
846 //Write Geometry object to current file.
852 //_____________________________________________________________________________
853 void AliRun::MediaTable()
856 // Built media table to get from the media number to
859 Int_t kz, nz, idt, lz, i, k, ind;
861 TObjArray &dets = *gAlice->Detectors();
865 for (kz=0;kz<fNdets;kz++) {
866 // If detector is defined
867 if((det=(AliModule*) dets[kz])) {
868 TArrayI &idtmed = *(det->GetIdtmed());
869 for(nz=0;nz<100;nz++) {
870 // Find max and min material number
871 if((idt=idtmed[nz])) {
872 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
873 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
876 if(det->LoMedium() > det->HiMedium()) {
880 if(det->HiMedium() > fImedia->GetSize()) {
881 Error("MediaTable","Increase fImedia from %d to %d",
882 fImedia->GetSize(),det->HiMedium());
885 // Tag all materials in rage as belonging to detector kz
886 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
893 // Print summary table
894 printf(" Traking media ranges:\n");
895 for(i=0;i<(fNdets-1)/6+1;i++) {
896 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
898 det=(AliModule*)dets[ind];
900 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
903 printf(" %6s: %3d -> %3d;","NULL",0,0);
909 //____________________________________________________________________________
910 void AliRun::SetGenerator(AliGenerator *generator)
913 // Load the event generator
915 if(!fGenerator) fGenerator = generator;
918 //____________________________________________________________________________
919 void AliRun::ResetGenerator(AliGenerator *generator)
922 // Load the event generator
925 Warning("ResetGenerator","Replacing generator %s with %s\n",
926 fGenerator->GetName(),generator->GetName());
927 fGenerator = generator;
930 //____________________________________________________________________________
931 void AliRun::SetTransPar(char* filename)
934 // Read filename to set the transport parameters
938 const Int_t ncuts=10;
939 const Int_t nflags=11;
940 const Int_t npars=ncuts+nflags;
941 const char pars[npars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
942 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
943 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
944 "MULS","PAIR","PHOT","RAYL"};
950 Int_t i, itmed, iret, ktmed, kz;
953 // See whether the file is there
954 filtmp=gSystem->ExpandPathName(filename);
955 lun=fopen(filtmp,"r");
958 Warning("SetTransPar","File %s does not exist!\n",filename);
962 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
963 printf(" *%59s\n","*");
964 printf(" * Please check carefully what you are doing!%10s\n","*");
965 printf(" *%59s\n","*");
968 // Initialise cuts and flags
969 for(i=0;i<ncuts;i++) cut[i]=-99;
970 for(i=0;i<nflags;i++) flag[i]=-99;
972 for(i=0;i<256;i++) line[i]='\0';
973 // Read up to the end of line excluded
974 iret=fscanf(lun,"%[^\n]",line);
978 printf(" *%59s\n","*");
979 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
982 // Read the end of line
985 if(line[0]=='*') continue;
987 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",
988 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
989 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
990 &flag[8],&flag[9],&flag[10]);
994 Warning("SetTransPar","Error reading file %s\n",filename);
997 // Check that the module exist
998 AliModule *mod = GetModule(detName);
1000 // Get the array of media numbers
1001 TArrayI &idtmed = *mod->GetIdtmed();
1002 // Check that the tracking medium code is valid
1003 if(0<=itmed && itmed < 100) {
1004 ktmed=idtmed[itmed];
1006 Warning("SetTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
1009 // Set energy thresholds
1010 for(kz=0;kz<ncuts;kz++) {
1012 printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
1013 pars[kz],cut[kz],itmed,mod->GetName());
1014 gMC->Gstpar(ktmed,pars[kz],cut[kz]);
1017 // Set transport mechanisms
1018 for(kz=0;kz<nflags;kz++) {
1020 printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
1021 pars[ncuts+kz],flag[kz],itmed,mod->GetName());
1022 gMC->Gstpar(ktmed,pars[ncuts+kz],Float_t(flag[kz]));
1026 Warning("SetTransPar","Invalid medium code %d *\n",itmed);
1030 Warning("SetTransPar","Module %s not present\n",detName);
1036 //_____________________________________________________________________________
1037 void AliRun::MakeTree(Option_t *option)
1040 // Create the ROOT trees
1041 // Loop on all detectors to create the Root branch (if any)
1047 char *K = strstr(option,"K");
1048 char *H = strstr(option,"H");
1049 char *E = strstr(option,"E");
1050 char *D = strstr(option,"D");
1051 char *R = strstr(option,"R");
1054 sprintf(hname,"TreeK%d",fEvent);
1055 fTreeK = new TTree(hname,"Kinematics");
1056 // Create a branch for particles
1057 fTreeK->Branch("Particles",&fParticles,4000);
1060 sprintf(hname,"TreeH%d",fEvent);
1061 fTreeH = new TTree(hname,"Hits");
1062 fTreeH->SetAutoSave(1000000000); //no autosave
1065 sprintf(hname,"TreeD%d",fEvent);
1066 fTreeD = new TTree(hname,"Digits");
1069 sprintf(hname,"TreeR%d",fEvent);
1070 fTreeR = new TTree(hname,"Reconstruction");
1073 fTreeE = new TTree("TE","Header");
1074 // Create a branch for Header
1075 fTreeE->Branch("Header","AliHeader",&header,4000);
1078 // Create a branch for hits/digits for each detector
1079 // Each branch is a TClonesArray. Each data member of the Hits classes
1080 // will be in turn a subbranch of the detector master branch
1081 TIter next(fModules);
1082 AliModule *detector;
1083 while((detector = (AliModule*)next())) {
1084 if (H || D || R) detector->MakeBranch(option);
1088 //_____________________________________________________________________________
1089 Int_t AliRun::PurifyKine(Int_t lastSavedTrack, Int_t nofTracks)
1092 // PurifyKine with external parameters
1094 fHgwmk = lastSavedTrack;
1095 fNtrack = nofTracks;
1100 //_____________________________________________________________________________
1101 void AliRun::PurifyKine()
1104 // Compress kinematic tree keeping only flagged particles
1105 // and renaming the particle id's in all the hits
1107 TClonesArray &particles = *fParticles;
1108 int nkeep=fHgwmk+1, parent, i;
1109 TParticle *part, *partnew, *father;
1110 int *map = new int[particles.GetEntries()];
1112 // Save in Header total number of tracks before compression
1113 fHeader.SetNtrack(fHeader.GetNtrack()+fNtrack-fHgwmk);
1115 // Preset map, to be removed later
1116 for(i=0; i<fNtrack; i++) {
1117 if(i<=fHgwmk) map[i]=i ; else map[i] = -99 ;}
1118 // Second pass, build map between old and new numbering
1119 for(i=fHgwmk+1; i<fNtrack; i++) {
1120 part = (TParticle *)particles.UncheckedAt(i);
1121 if(part->TestBit(Keep_Bit)) {
1123 // This particle has to be kept
1127 // Old and new are different, have to copy
1128 partnew = (TParticle *)particles.UncheckedAt(nkeep);
1129 // Change due to a bug in the HP compiler
1130 // *partnew = *part;
1131 memcpy(partnew,part,sizeof(TParticle));
1132 } else partnew = part;
1134 // as the parent is always *before*, it must be already
1135 // in place. This is what we are checking anyway!
1136 if((parent=partnew->GetFirstMother())>fHgwmk) {
1137 if(map[parent]==-99) printf("map[%d] = -99!\n",parent);
1138 partnew->SetFirstMother(map[parent]);
1145 // Fix daughters information
1146 for (i=0; i<fNtrack; i++) {
1147 part = (TParticle *)particles.UncheckedAt(i);
1148 parent = part->GetFirstMother();
1150 father = (TParticle *)particles.UncheckedAt(parent);
1151 if(father->TestBit(Daughters_Bit)) {
1153 if(i<father->GetFirstDaughter()) father->SetFirstDaughter(i);
1154 if(i>father->GetLastDaughter()) father->SetLastDaughter(i);
1156 // Iitialise daughters info for first pass
1157 father->SetFirstDaughter(i);
1158 father->SetLastDaughter(i);
1159 father->SetBit(Daughters_Bit);
1165 // Now loop on all detectors and reset the hits
1167 TIter next(fModules);
1168 AliModule *detector;
1169 while((detector = (AliModule*)next())) {
1170 if (!detector->Hits()) continue;
1171 TClonesArray &vHits=*(detector->Hits());
1172 if(vHits.GetEntries() != detector->GetNhits())
1173 printf("vHits.GetEntries()!=detector->GetNhits(): %d != %d\n",
1174 vHits.GetEntries(),detector->GetNhits());
1175 for (i=0; i<detector->GetNhits(); i++) {
1176 OneHit = (AliHit *)vHits.UncheckedAt(i);
1177 OneHit->SetTrack(map[OneHit->GetTrack()]);
1182 // Now loop on all registered hit lists
1183 TIter next(fHitLists);
1184 TCollection *hitList;
1185 while((hitList = (TCollection*)next())) {
1186 TIter nexthit(hitList);
1188 while((hit = (AliHit*)nexthit())) {
1189 hit->SetTrack(map[hit->GetTrack()]);
1195 particles.SetLast(fHgwmk);
1199 //_____________________________________________________________________________
1200 void AliRun::Reset()
1203 // Reset all Detectors & kinematics & trees
1211 // Initialise event header
1212 fHeader.Reset(fRun,fEvent);
1216 sprintf(hname,"TreeK%d",fEvent);
1217 fTreeK->SetName(hname);
1221 sprintf(hname,"TreeH%d",fEvent);
1222 fTreeH->SetName(hname);
1226 sprintf(hname,"TreeD%d",fEvent);
1227 fTreeD->SetName(hname);
1231 sprintf(hname,"TreeR%d",fEvent);
1232 fTreeR->SetName(hname);
1236 //_____________________________________________________________________________
1237 void AliRun::ResetDigits()
1240 // Reset all Detectors digits
1242 TIter next(fModules);
1243 AliModule *detector;
1244 while((detector = (AliModule*)next())) {
1245 detector->ResetDigits();
1249 //_____________________________________________________________________________
1250 void AliRun::ResetHits()
1253 // Reset all Detectors hits
1255 TIter next(fModules);
1256 AliModule *detector;
1257 while((detector = (AliModule*)next())) {
1258 detector->ResetHits();
1262 //_____________________________________________________________________________
1263 void AliRun::ResetPoints()
1266 // Reset all Detectors points
1268 TIter next(fModules);
1269 AliModule *detector;
1270 while((detector = (AliModule*)next())) {
1271 detector->ResetPoints();
1275 //_____________________________________________________________________________
1276 void AliRun::RunMC(Int_t nevent, const char *setup)
1279 // Main function to be called to process a galice run
1281 // Root > gAlice.Run();
1282 // a positive number of events will cause the finish routine
1286 // check if initialisation has been done
1287 if (!fInitDone) InitMC(setup);
1289 // Create the Root Tree with one branch per detector
1292 gMC->ProcessRun(nevent);
1294 // End of this run, close files
1295 if(nevent>0) FinishRun();
1298 //_____________________________________________________________________________
1299 void AliRun::RunLego(const char *setup,Int_t ntheta,Float_t themin,
1300 Float_t themax,Int_t nphi,Float_t phimin,Float_t phimax,
1301 Float_t rmin,Float_t rmax,Float_t zmax)
1304 // Generates lego plots of:
1305 // - radiation length map phi vs theta
1306 // - radiation length map phi vs eta
1307 // - interaction length map
1308 // - g/cm2 length map
1310 // ntheta bins in theta, eta
1311 // themin minimum angle in theta (degrees)
1312 // themax maximum angle in theta (degrees)
1314 // phimin minimum angle in phi (degrees)
1315 // phimax maximum angle in phi (degrees)
1316 // rmin minimum radius
1317 // rmax maximum radius
1320 // The number of events generated = ntheta*nphi
1321 // run input parameters in macro setup (default="Config.C")
1323 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1326 <img src="picts/AliRunLego1.gif">
1331 <img src="picts/AliRunLego2.gif">
1336 <img src="picts/AliRunLego3.gif">
1341 // check if initialisation has been done
1342 if (!fInitDone) InitMC(setup);
1344 //Create Lego object
1345 fLego = new AliLego("lego",ntheta,themin,themax,nphi,phimin,phimax,rmin,rmax,zmax);
1350 // Create only the Root event Tree
1353 // End of this run, close files
1357 //_____________________________________________________________________________
1358 void AliRun::SetCurrentTrack(Int_t track)
1361 // Set current track number
1366 //_____________________________________________________________________________
1367 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1368 Float_t *vpos, Float_t *polar, Float_t tof,
1369 const char *mecha, Int_t &ntr, Float_t weight)
1372 // Load a track on the stack
1374 // done 0 if the track has to be transported
1376 // parent identifier of the parent track. -1 for a primary
1377 // pdg particle code
1378 // pmom momentum GeV/c
1380 // polar polarisation
1381 // tof time of flight in seconds
1382 // mecha production mechanism
1383 // ntr on output the number of the track stored
1385 TClonesArray &particles = *fParticles;
1386 TParticle *particle;
1388 const Int_t firstdaughter=-1;
1389 const Int_t lastdaughter=-1;
1391 // const Float_t tlife=0;
1394 // Here we get the static mass
1395 // For MC is ok, but a more sophisticated method could be necessary
1396 // if the calculated mass is required
1397 // also, this method is potentially dangerous if the mass
1398 // used in the MC is not the same of the PDG database
1400 mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
1401 Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+
1402 pmom[1]*pmom[1]+pmom[2]*pmom[2]);
1404 //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",
1405 //pname,mass,e,fNtrack,pdg,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],KS,mecha);
1407 particle=new(particles[fNtrack]) TParticle(pdg,KS,parent,-1,firstdaughter,
1408 lastdaughter,pmom[0],pmom[1],pmom[2],
1409 e,vpos[0],vpos[1],vpos[2],tof);
1410 // polar[0],polar[1],polar[2],tof,
1412 ((TParticle*)particles[fNtrack])->SetPolarisation(TVector3(polar[0],polar[1],polar[2]));
1413 ((TParticle*)particles[fNtrack])->SetWeight(weight);
1414 if(!done) particle->SetBit(Done_Bit);
1417 particle=(TParticle*) fParticles->UncheckedAt(parent);
1418 particle->SetLastDaughter(fNtrack);
1419 if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack);
1422 // This is a primary track. Set high water mark for this event
1425 // Set also number if primary tracks
1426 fHeader.SetNprimary(fHgwmk+1);
1427 fHeader.SetNtrack(fHgwmk+1);
1432 //_____________________________________________________________________________
1433 void AliRun::KeepTrack(const Int_t track)
1436 // flags a track to be kept
1438 TClonesArray &particles = *fParticles;
1439 ((TParticle*)particles[track])->SetBit(Keep_Bit);
1442 //_____________________________________________________________________________
1443 void AliRun::StepManager(Int_t id)
1446 // Called at every step during transport
1450 // --- If lego option, do it and leave
1452 fLego->StepManager();
1455 //Update energy deposition tables
1456 AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
1458 //Call the appropriate stepping routine;
1459 AliModule *det = (AliModule*)fModules->At(id);
1460 if(det) det->StepManager();
1464 //_____________________________________________________________________________
1465 void AliRun::Streamer(TBuffer &R__b)
1468 // Stream an object of class AliRun.
1470 if (R__b.IsReading()) {
1471 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1472 TNamed::Streamer(R__b);
1473 if (!gAlice) gAlice = this;
1474 gROOT->GetListOfBrowsables()->Add(this,"Run");
1475 fTreeE = (TTree*)gDirectory->Get("TE");
1476 if (fTreeE) fTreeE->SetBranchAddress("Header", &header);
1477 else Error("Streamer","cannot find Header Tree\n");
1481 fHeader.Streamer(R__b);
1491 R__b >> fPDGDB; //Particle factory object!
1492 fTreeE->GetEntry(0);
1494 fHeader.SetEvent(0);
1495 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
1498 R__b.WriteVersion(AliRun::IsA());
1499 TNamed::Streamer(R__b);
1503 fHeader.Streamer(R__b);
1512 R__b << fPDGDB; //Particle factory object!