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.36 2000/06/08 14:03:58 hristov
19 Only one initializer for a default argument
21 Revision 1.35 2000/06/07 10:13:14 hristov
22 Delete only existent objects.
24 Revision 1.34 2000/05/18 10:45:38 fca
25 Delete Particle Factory properly
27 Revision 1.33 2000/05/16 13:10:40 fca
28 New method IsNewTrack and fix for a problem in Father-Daughter relations
30 Revision 1.32 2000/04/27 10:38:21 fca
31 Correct termination of Lego Run and introduce Lego getter in AliRun
33 Revision 1.31 2000/04/26 10:17:32 fca
34 Changes in Lego for G4 compatibility
36 Revision 1.30 2000/04/18 19:11:40 fca
37 Introduce variable Config.C function signature
39 Revision 1.29 2000/04/07 11:12:34 fca
40 G4 compatibility changes
42 Revision 1.28 2000/04/05 06:51:06 fca
43 Workaround for an HP compiler problem
45 Revision 1.27 2000/03/22 18:08:07 fca
46 Rationalisation of the virtual MC interfaces
48 Revision 1.26 2000/03/22 13:42:26 fca
49 SetGenerator does not replace an existing generator, ResetGenerator does
51 Revision 1.25 2000/02/23 16:25:22 fca
52 AliVMC and AliGeant3 classes introduced
53 ReadEuclid moved from AliRun to AliModule
55 Revision 1.24 2000/01/19 17:17:20 fca
56 Introducing a list of lists of hits -- more hits allowed for detector now
58 Revision 1.23 1999/12/03 11:14:31 fca
59 Fixing previous wrong checking
61 Revision 1.21 1999/11/25 10:40:08 fca
62 Fixing daughters information also in primary tracks
64 Revision 1.20 1999/10/04 18:08:49 fca
65 Adding protection against inconsistent Euclid files
67 Revision 1.19 1999/09/29 07:50:40 fca
68 Introduction of the Copyright and cvs Log
72 ///////////////////////////////////////////////////////////////////////////////
74 // Control class for Alice C++ //
75 // Only one single instance of this class exists. //
76 // The object is created in main program aliroot //
77 // and is pointed by the global gAlice. //
79 // -Supports the list of all Alice Detectors (fModules). //
80 // -Supports the list of particles (fParticles). //
81 // -Supports the Trees. //
82 // -Supports the geometry. //
83 // -Supports the event display. //
86 <img src="picts/AliRunClass.gif">
91 <img src="picts/alirun.gif">
95 ///////////////////////////////////////////////////////////////////////////////
103 #include <TObjectTable.h>
105 #include "TParticle.h"
107 #include "AliDisplay.h"
117 static AliHeader *header;
121 //_____________________________________________________________________________
125 // Default constructor for AliRun
149 fPDGDB = 0; //Particle factory object!
151 fConfigFunction = "\0";
154 //_____________________________________________________________________________
155 AliRun::AliRun(const char *name, const char *title)
159 // Constructor for the main processor.
160 // Creates the geometry
161 // Creates the list of Detectors.
162 // Creates the list of particles.
178 fConfigFunction = "Config();";
180 gROOT->GetListOfBrowsables()->Add(this,name);
182 // create the support list for the various Detectors
183 fModules = new TObjArray(77);
185 // Create the TNode geometry for the event display
187 BuildSimpleGeometry();
197 // Create the particle stack
198 fParticles = new TClonesArray("TParticle",100);
202 // Create default mag field
207 // Prepare the tracking medium lists
208 fImedia = new TArrayI(1000);
209 for(i=0;i<1000;i++) (*fImedia)[i]=-99;
212 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
214 // Create HitLists list
215 fHitLists = new TList();
218 //_____________________________________________________________________________
222 // Defaullt AliRun destructor
241 fParticles->Delete();
248 //_____________________________________________________________________________
249 void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
252 // Add a hit to detector id
254 TObjArray &dets = *fModules;
255 if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits);
258 //_____________________________________________________________________________
259 void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
262 // Add digit to detector id
264 TObjArray &dets = *fModules;
265 if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits);
268 //_____________________________________________________________________________
269 void AliRun::Browse(TBrowser *b)
272 // Called when the item "Run" is clicked on the left pane
273 // of the Root browser.
274 // It displays the Root Trees and all detectors.
276 if (fTreeK) b->Add(fTreeK,fTreeK->GetName());
277 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
278 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
279 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
280 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
282 TIter next(fModules);
284 while((detector = (AliModule*)next())) {
285 b->Add(detector,detector->GetName());
289 //_____________________________________________________________________________
293 // Initialize Alice geometry
298 //_____________________________________________________________________________
299 void AliRun::BuildSimpleGeometry()
302 // Create a simple TNode geometry used by Root display engine
304 // Initialise geometry
306 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
307 new TMaterial("void","Vacuum",0,0,0); //Everything is void
308 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
309 brik->SetVisibility(0);
310 new TNode("alice","alice","S_alice");
313 //_____________________________________________________________________________
314 void AliRun::CleanDetectors()
317 // Clean Detectors at the end of event
319 TIter next(fModules);
321 while((detector = (AliModule*)next())) {
322 detector->FinishEvent();
326 //_____________________________________________________________________________
327 void AliRun::CleanParents()
330 // Clean Particles stack.
331 // Set parent/daughter relations
333 TClonesArray &particles = *(gAlice->Particles());
336 for(i=0; i<fNtrack; i++) {
337 part = (TParticle *)particles.UncheckedAt(i);
338 if(!part->TestBit(Daughters_Bit)) {
339 part->SetFirstDaughter(-1);
340 part->SetLastDaughter(-1);
345 //_____________________________________________________________________________
346 Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
349 // Return the distance from the mouse to the AliRun object
355 //_____________________________________________________________________________
356 void AliRun::DumpPart (Int_t i)
359 // Dumps particle i in the stack
361 TClonesArray &particles = *fParticles;
362 ((TParticle*) particles[i])->Print();
365 //_____________________________________________________________________________
366 void AliRun::DumpPStack ()
369 // Dumps the particle stack
371 TClonesArray &particles = *fParticles;
373 "\n\n=======================================================================\n");
374 for (Int_t i=0;i<fNtrack;i++)
376 printf("-> %d ",i); ((TParticle*) particles[i])->Print();
377 printf("--------------------------------------------------------------\n");
380 "\n=======================================================================\n\n");
383 //_____________________________________________________________________________
384 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
385 Float_t maxField, char* filename)
388 // Set magnetic field parameters
389 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
390 // version Magnetic field map version (only 1 active now)
391 // scale Scale factor for the magnetic field
392 // maxField Maximum value for the magnetic field
395 // --- Sanity check on mag field flags
396 if(type<0 || type > 2) {
398 "Invalid magnetic field flag: %5d; Helix tracking chosen instead\n"
402 if(fField) delete fField;
404 fField = new AliMagFC("Map1"," ",type,version,scale,maxField);
405 } else if(version<=2) {
406 fField = new AliMagFCM("Map2-3",filename,type,version,scale,maxField);
408 } else if(version==3) {
409 fField = new AliMagFDM("Map4",filename,type,version,scale,maxField);
412 Warning("SetField","Invalid map %d\n",version);
416 //_____________________________________________________________________________
417 void AliRun::FillTree()
420 // Fills all AliRun TTrees
422 if (fTreeK) fTreeK->Fill();
423 if (fTreeH) fTreeH->Fill();
424 if (fTreeD) fTreeD->Fill();
425 if (fTreeR) fTreeR->Fill();
428 //_____________________________________________________________________________
429 void AliRun::FinishPrimary()
432 // Called at the end of each primary track
435 // static Int_t count=0;
436 // const Int_t times=10;
437 // This primary is finished, purify stack
440 // Write out hits if any
441 if (gAlice->TreeH()) {
442 gAlice->TreeH()->Fill();
449 // if(++count%times==1) gObjectTable->Print();
452 //_____________________________________________________________________________
453 void AliRun::FinishEvent()
456 // Called at the end of the event.
460 if(fLego) fLego->FinishEvent();
462 //Update the energy deposit tables
464 for(i=0;i<fEventEnergy.GetSize();i++) {
465 fSummEnergy[i]+=fEventEnergy[i];
466 fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
468 fEventEnergy.Reset();
470 // Clean detector information
473 // Write out the kinematics
479 // Write out the digits
485 // Write out reconstructed clusters
490 // Write out the event Header information
491 if (fTreeE) fTreeE->Fill();
496 // Write Tree headers
497 // Int_t ievent = fHeader.GetEvent();
499 // sprintf(hname,"TreeK%d",ievent);
500 if (fTreeK) fTreeK->Write();
501 // sprintf(hname,"TreeH%d",ievent);
502 if (fTreeH) fTreeH->Write();
503 // sprintf(hname,"TreeD%d",ievent);
504 if (fTreeD) fTreeD->Write();
505 // sprintf(hname,"TreeR%d",ievent);
506 if (fTreeR) fTreeR->Write();
511 //_____________________________________________________________________________
512 void AliRun::FinishRun()
515 // Called at the end of the run.
519 if(fLego) fLego->FinishRun();
521 // Clean detector information
522 TIter next(fModules);
524 while((detector = (AliModule*)next())) {
525 detector->FinishRun();
528 //Output energy summary tables
531 // file is retrieved from whatever tree
533 if (fTreeK) File = fTreeK->GetCurrentFile();
534 if ((!File) && (fTreeH)) File = fTreeH->GetCurrentFile();
535 if ((!File) && (fTreeD)) File = fTreeD->GetCurrentFile();
536 if ((!File) && (fTreeE)) File = fTreeE->GetCurrentFile();
538 Error("FinishRun","There isn't root file!");
544 // Clean tree information
546 delete fTreeK; fTreeK = 0;
549 delete fTreeH; fTreeH = 0;
552 delete fTreeD; fTreeD = 0;
555 delete fTreeR; fTreeR = 0;
558 delete fTreeE; fTreeE = 0;
561 // Write AliRun info and all detectors parameters
568 //_____________________________________________________________________________
569 void AliRun::FlagTrack(Int_t track)
572 // Flags a track and all its family tree to be kept
579 particle=(TParticle*)fParticles->UncheckedAt(curr);
581 // If the particle is flagged the three from here upward is saved already
582 if(particle->TestBit(Keep_Bit)) return;
584 // Save this particle
585 particle->SetBit(Keep_Bit);
587 // Move to father if any
588 if((curr=particle->GetFirstMother())==-1) return;
592 //_____________________________________________________________________________
593 void AliRun::EnergySummary()
596 // Print summary of deposited energy
602 Int_t kn, i, left, j, id;
603 const Float_t zero=0;
604 Int_t ievent=fHeader.GetEvent()+1;
606 // Energy loss information
608 printf("***************** Energy Loss Information per event (GEV) *****************\n");
609 for(kn=1;kn<fEventEnergy.GetSize();kn++) {
612 fEventEnergy[ndep]=kn;
617 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,zero))/ed;
620 fSummEnergy[ndep]=ed;
621 fSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,zero));
626 for(kn=0;kn<(ndep-1)/3+1;kn++) {
628 for(i=0;i<(3<left?3:left);i++) {
630 id=Int_t (fEventEnergy[j]+0.1);
631 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]);
636 // Relative energy loss in different detectors
637 printf("******************** Relative Energy Loss per event ********************\n");
638 printf("Total energy loss per event %10.3f GeV\n",edtot);
639 for(kn=0;kn<(ndep-1)/5+1;kn++) {
641 for(i=0;i<(5<left?5:left);i++) {
643 id=Int_t (fEventEnergy[j]+0.1);
644 printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot);
648 for(kn=0;kn<75;kn++) printf("*");
652 // Reset the TArray's
653 // fEventEnergy.Set(0);
654 // fSummEnergy.Set(0);
655 // fSum2Energy.Set(0);
658 //_____________________________________________________________________________
659 AliModule *AliRun::GetModule(const char *name)
662 // Return pointer to detector from name
664 return (AliModule*)fModules->FindObject(name);
667 //_____________________________________________________________________________
668 AliDetector *AliRun::GetDetector(const char *name)
671 // Return pointer to detector from name
673 return (AliDetector*)fModules->FindObject(name);
676 //_____________________________________________________________________________
677 Int_t AliRun::GetModuleID(const char *name)
680 // Return galice internal detector identifier from name
683 TObject *mod=fModules->FindObject(name);
684 if(mod) i=fModules->IndexOf(mod);
688 //_____________________________________________________________________________
689 Int_t AliRun::GetEvent(Int_t event)
692 // Connect the Trees Kinematics and Hits for event # event
693 // Set branch addresses
696 // Reset existing structures
701 // Delete Trees already connected
702 if (fTreeK) delete fTreeK;
703 if (fTreeH) delete fTreeH;
704 if (fTreeD) delete fTreeD;
705 if (fTreeR) delete fTreeR;
707 // Get header from file
708 if(fTreeE) fTreeE->GetEntry(event);
709 else Error("GetEvent","Cannot file Header Tree\n");
711 // Get Kine Tree from file
713 sprintf(treeName,"TreeK%d",event);
714 fTreeK = (TTree*)gDirectory->Get(treeName);
715 if (fTreeK) fTreeK->SetBranchAddress("Particles", &fParticles);
716 else Error("GetEvent","cannot find Kine Tree for event:%d\n",event);
718 // Get Hits Tree header from file
719 sprintf(treeName,"TreeH%d",event);
720 fTreeH = (TTree*)gDirectory->Get(treeName);
722 Error("GetEvent","cannot find Hits Tree for event:%d\n",event);
725 // Get Digits Tree header from file
726 sprintf(treeName,"TreeD%d",event);
727 fTreeD = (TTree*)gDirectory->Get(treeName);
729 Warning("GetEvent","cannot find Digits Tree for event:%d\n",event);
733 // Get Reconstruct Tree header from file
734 sprintf(treeName,"TreeR%d",event);
735 fTreeR = (TTree*)gDirectory->Get(treeName);
737 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
740 // Set Trees branch addresses
741 TIter next(fModules);
743 while((detector = (AliModule*)next())) {
744 detector->SetTreeAddress();
747 if (fTreeK) fTreeK->GetEvent(0);
748 fNtrack = Int_t (fParticles->GetEntries());
752 //_____________________________________________________________________________
753 TGeometry *AliRun::GetGeometry()
756 // Import Alice geometry from current file
757 // Return pointer to geometry object
759 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
761 // Unlink and relink nodes in detectors
762 // This is bad and there must be a better way...
765 TIter next(fModules);
767 while((detector = (AliModule*)next())) {
768 detector->SetTreeAddress();
769 TList *dnodes=detector->Nodes();
772 for ( j=0; j<dnodes->GetSize(); j++) {
773 node = (TNode*) dnodes->At(j);
774 node1 = fGeometry->GetNode(node->GetName());
775 dnodes->Remove(node);
776 dnodes->AddAt(node1,j);
782 //_____________________________________________________________________________
783 void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
784 Float_t &e, Float_t *vpos, Float_t *polar,
788 // Return next track from stack of particles
793 for(Int_t i=fNtrack-1; i>=0; i--) {
794 track=(TParticle*) fParticles->UncheckedAt(i);
795 if(!track->TestBit(Done_Bit)) {
797 // The track has not yet been processed
799 ipart=track->GetPdgCode();
807 track->GetPolarisation(pol);
812 track->SetBit(Done_Bit);
818 // stop and start timer when we start a primary track
819 Int_t nprimaries = fHeader.GetNprimary();
820 if (fCurrent >= nprimaries) return;
821 if (fCurrent < nprimaries-1) {
823 track=(TParticle*) fParticles->UncheckedAt(fCurrent+1);
824 // track->SetProcessTime(fTimer.CpuTime());
829 //_____________________________________________________________________________
830 Int_t AliRun::GetPrimary(Int_t track)
833 // return number of primary that has generated track
841 part = (TParticle *)fParticles->UncheckedAt(current);
842 parent=part->GetFirstMother();
843 if(parent<0) return current;
847 //_____________________________________________________________________________
848 void AliRun::InitMC(const char *setup)
851 // Initialize the Alice setup
854 gROOT->LoadMacro(setup);
855 gInterpreter->ProcessLine(fConfigFunction.Data());
857 gMC->DefineParticles(); //Create standard MC particles
859 TObject *objfirst, *objlast;
861 fNdets = fModules->GetLast()+1;
864 //=================Create Materials and geometry
867 TIter next(fModules);
869 while((detector = (AliModule*)next())) {
870 detector->SetTreeAddress();
871 objlast = gDirectory->GetList()->Last();
873 // Add Detector histograms in Detector list of histograms
874 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
875 else objfirst = gDirectory->GetList()->First();
877 detector->Histograms()->Add(objfirst);
878 objfirst = gDirectory->GetList()->After(objfirst);
881 SetTransPar(); //Read the cuts for all materials
883 MediaTable(); //Build the special IMEDIA table
885 //Initialise geometry deposition table
886 fEventEnergy.Set(gMC->NofVolumes()+1);
887 fSummEnergy.Set(gMC->NofVolumes()+1);
888 fSum2Energy.Set(gMC->NofVolumes()+1);
890 //Compute cross-sections
893 //Write Geometry object to current file.
899 //_____________________________________________________________________________
900 void AliRun::MediaTable()
903 // Built media table to get from the media number to
906 Int_t kz, nz, idt, lz, i, k, ind;
908 TObjArray &dets = *gAlice->Detectors();
912 for (kz=0;kz<fNdets;kz++) {
913 // If detector is defined
914 if((det=(AliModule*) dets[kz])) {
915 TArrayI &idtmed = *(det->GetIdtmed());
916 for(nz=0;nz<100;nz++) {
917 // Find max and min material number
918 if((idt=idtmed[nz])) {
919 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
920 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
923 if(det->LoMedium() > det->HiMedium()) {
927 if(det->HiMedium() > fImedia->GetSize()) {
928 Error("MediaTable","Increase fImedia from %d to %d",
929 fImedia->GetSize(),det->HiMedium());
932 // Tag all materials in rage as belonging to detector kz
933 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
940 // Print summary table
941 printf(" Traking media ranges:\n");
942 for(i=0;i<(fNdets-1)/6+1;i++) {
943 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
945 det=(AliModule*)dets[ind];
947 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
950 printf(" %6s: %3d -> %3d;","NULL",0,0);
956 //____________________________________________________________________________
957 void AliRun::SetGenerator(AliGenerator *generator)
960 // Load the event generator
962 if(!fGenerator) fGenerator = generator;
965 //____________________________________________________________________________
966 void AliRun::ResetGenerator(AliGenerator *generator)
969 // Load the event generator
973 Warning("ResetGenerator","Replacing generator %s with %s\n",
974 fGenerator->GetName(),generator->GetName());
976 Warning("ResetGenerator","Replacing generator %s with NULL\n",
977 fGenerator->GetName());
978 fGenerator = generator;
981 //____________________________________________________________________________
982 void AliRun::SetTransPar(char* filename)
985 // Read filename to set the transport parameters
989 const Int_t ncuts=10;
990 const Int_t nflags=11;
991 const Int_t npars=ncuts+nflags;
992 const char pars[npars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
993 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
994 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
995 "MULS","PAIR","PHOT","RAYL"};
1001 Int_t i, itmed, iret, ktmed, kz;
1004 // See whether the file is there
1005 filtmp=gSystem->ExpandPathName(filename);
1006 lun=fopen(filtmp,"r");
1009 Warning("SetTransPar","File %s does not exist!\n",filename);
1013 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1014 printf(" *%59s\n","*");
1015 printf(" * Please check carefully what you are doing!%10s\n","*");
1016 printf(" *%59s\n","*");
1019 // Initialise cuts and flags
1020 for(i=0;i<ncuts;i++) cut[i]=-99;
1021 for(i=0;i<nflags;i++) flag[i]=-99;
1023 for(i=0;i<256;i++) line[i]='\0';
1024 // Read up to the end of line excluded
1025 iret=fscanf(lun,"%[^\n]",line);
1029 printf(" *%59s\n","*");
1030 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1033 // Read the end of line
1036 if(line[0]=='*') continue;
1038 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",
1039 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
1040 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
1041 &flag[8],&flag[9],&flag[10]);
1045 Warning("SetTransPar","Error reading file %s\n",filename);
1048 // Check that the module exist
1049 AliModule *mod = GetModule(detName);
1051 // Get the array of media numbers
1052 TArrayI &idtmed = *mod->GetIdtmed();
1053 // Check that the tracking medium code is valid
1054 if(0<=itmed && itmed < 100) {
1055 ktmed=idtmed[itmed];
1057 Warning("SetTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
1060 // Set energy thresholds
1061 for(kz=0;kz<ncuts;kz++) {
1063 printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
1064 pars[kz],cut[kz],itmed,mod->GetName());
1065 gMC->Gstpar(ktmed,pars[kz],cut[kz]);
1068 // Set transport mechanisms
1069 for(kz=0;kz<nflags;kz++) {
1071 printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
1072 pars[ncuts+kz],flag[kz],itmed,mod->GetName());
1073 gMC->Gstpar(ktmed,pars[ncuts+kz],Float_t(flag[kz]));
1077 Warning("SetTransPar","Invalid medium code %d *\n",itmed);
1081 Warning("SetTransPar","Module %s not present\n",detName);
1087 //_____________________________________________________________________________
1088 void AliRun::MakeTree(Option_t *option)
1091 // Create the ROOT trees
1092 // Loop on all detectors to create the Root branch (if any)
1098 char *K = strstr(option,"K");
1099 char *H = strstr(option,"H");
1100 char *E = strstr(option,"E");
1101 char *D = strstr(option,"D");
1102 char *R = strstr(option,"R");
1105 sprintf(hname,"TreeK%d",fEvent);
1106 fTreeK = new TTree(hname,"Kinematics");
1107 // Create a branch for particles
1108 fTreeK->Branch("Particles",&fParticles,4000);
1111 sprintf(hname,"TreeH%d",fEvent);
1112 fTreeH = new TTree(hname,"Hits");
1113 fTreeH->SetAutoSave(1000000000); //no autosave
1116 sprintf(hname,"TreeD%d",fEvent);
1117 fTreeD = new TTree(hname,"Digits");
1120 sprintf(hname,"TreeR%d",fEvent);
1121 fTreeR = new TTree(hname,"Reconstruction");
1124 fTreeE = new TTree("TE","Header");
1125 // Create a branch for Header
1126 fTreeE->Branch("Header","AliHeader",&header,4000);
1129 // Create a branch for hits/digits for each detector
1130 // Each branch is a TClonesArray. Each data member of the Hits classes
1131 // will be in turn a subbranch of the detector master branch
1132 TIter next(fModules);
1133 AliModule *detector;
1134 while((detector = (AliModule*)next())) {
1135 if (H || D || R) detector->MakeBranch(option);
1139 //_____________________________________________________________________________
1140 Int_t AliRun::PurifyKine(Int_t lastSavedTrack, Int_t nofTracks)
1143 // PurifyKine with external parameters
1145 fHgwmk = lastSavedTrack;
1146 fNtrack = nofTracks;
1151 //_____________________________________________________________________________
1152 void AliRun::PurifyKine()
1155 // Compress kinematic tree keeping only flagged particles
1156 // and renaming the particle id's in all the hits
1158 TClonesArray &particles = *fParticles;
1159 int nkeep=fHgwmk+1, parent, i;
1160 TParticle *part, *partnew, *father;
1161 int *map = new int[particles.GetEntries()];
1163 // Save in Header total number of tracks before compression
1164 fHeader.SetNtrack(fHeader.GetNtrack()+fNtrack-fHgwmk);
1166 // First pass, invalid Daughter information
1167 for(i=0; i<fNtrack; i++) {
1168 // Preset map, to be removed later
1169 if(i<=fHgwmk) map[i]=i ; else map[i] = -99;
1170 ((TParticle *)particles.UncheckedAt(i))->ResetBit(Daughters_Bit);
1172 // Second pass, build map between old and new numbering
1173 for(i=fHgwmk+1; i<fNtrack; i++) {
1174 part = (TParticle *)particles.UncheckedAt(i);
1175 if(part->TestBit(Keep_Bit)) {
1177 // This particle has to be kept
1181 // Old and new are different, have to copy
1182 partnew = (TParticle *)particles.UncheckedAt(nkeep);
1183 // Change due to a bug in the HP compiler
1184 // *partnew = *part;
1185 memcpy(partnew,part,sizeof(TParticle));
1186 } else partnew = part;
1188 // as the parent is always *before*, it must be already
1189 // in place. This is what we are checking anyway!
1190 if((parent=partnew->GetFirstMother())>fHgwmk) {
1191 if(map[parent]==-99) printf("map[%d] = -99!\n",parent);
1192 partnew->SetFirstMother(map[parent]);
1199 // Fix daughters information
1200 for (i=0; i<fNtrack; i++) {
1201 part = (TParticle *)particles.UncheckedAt(i);
1202 parent = part->GetFirstMother();
1204 father = (TParticle *)particles.UncheckedAt(parent);
1205 if(father->TestBit(Daughters_Bit)) {
1207 if(i<father->GetFirstDaughter()) father->SetFirstDaughter(i);
1208 if(i>father->GetLastDaughter()) father->SetLastDaughter(i);
1210 // Iitialise daughters info for first pass
1211 father->SetFirstDaughter(i);
1212 father->SetLastDaughter(i);
1213 father->SetBit(Daughters_Bit);
1219 // Now loop on all detectors and reset the hits
1221 TIter next(fModules);
1222 AliModule *detector;
1223 while((detector = (AliModule*)next())) {
1224 if (!detector->Hits()) continue;
1225 TClonesArray &vHits=*(detector->Hits());
1226 if(vHits.GetEntries() != detector->GetNhits())
1227 printf("vHits.GetEntries()!=detector->GetNhits(): %d != %d\n",
1228 vHits.GetEntries(),detector->GetNhits());
1229 for (i=0; i<detector->GetNhits(); i++) {
1230 OneHit = (AliHit *)vHits.UncheckedAt(i);
1231 OneHit->SetTrack(map[OneHit->GetTrack()]);
1236 // Now loop on all registered hit lists
1237 TIter next(fHitLists);
1238 TCollection *hitList;
1239 while((hitList = (TCollection*)next())) {
1240 TIter nexthit(hitList);
1242 while((hit = (AliHit*)nexthit())) {
1243 hit->SetTrack(map[hit->GetTrack()]);
1249 particles.SetLast(fHgwmk);
1253 //_____________________________________________________________________________
1254 void AliRun::BeginEvent()
1257 // Reset all Detectors & kinematics & trees
1264 fLego->BeginEvent();
1273 // Initialise event header
1274 fHeader.Reset(fRun,fEvent);
1278 sprintf(hname,"TreeK%d",fEvent);
1279 fTreeK->SetName(hname);
1283 sprintf(hname,"TreeH%d",fEvent);
1284 fTreeH->SetName(hname);
1288 sprintf(hname,"TreeD%d",fEvent);
1289 fTreeD->SetName(hname);
1293 sprintf(hname,"TreeR%d",fEvent);
1294 fTreeR->SetName(hname);
1298 //_____________________________________________________________________________
1299 void AliRun::ResetDigits()
1302 // Reset all Detectors digits
1304 TIter next(fModules);
1305 AliModule *detector;
1306 while((detector = (AliModule*)next())) {
1307 detector->ResetDigits();
1311 //_____________________________________________________________________________
1312 void AliRun::ResetHits()
1315 // Reset all Detectors hits
1317 TIter next(fModules);
1318 AliModule *detector;
1319 while((detector = (AliModule*)next())) {
1320 detector->ResetHits();
1324 //_____________________________________________________________________________
1325 void AliRun::ResetPoints()
1328 // Reset all Detectors points
1330 TIter next(fModules);
1331 AliModule *detector;
1332 while((detector = (AliModule*)next())) {
1333 detector->ResetPoints();
1337 //_____________________________________________________________________________
1338 void AliRun::RunMC(Int_t nevent, const char *setup)
1341 // Main function to be called to process a galice run
1343 // Root > gAlice.Run();
1344 // a positive number of events will cause the finish routine
1348 // check if initialisation has been done
1349 if (!fInitDone) InitMC(setup);
1351 // Create the Root Tree with one branch per detector
1354 gMC->ProcessRun(nevent);
1356 // End of this run, close files
1357 if(nevent>0) FinishRun();
1360 //_____________________________________________________________________________
1361 void AliRun::RunLego(const char *setup,Int_t ntheta,Float_t themin,
1362 Float_t themax,Int_t nphi,Float_t phimin,Float_t phimax,
1363 Float_t rmin,Float_t rmax,Float_t zmax)
1366 // Generates lego plots of:
1367 // - radiation length map phi vs theta
1368 // - radiation length map phi vs eta
1369 // - interaction length map
1370 // - g/cm2 length map
1372 // ntheta bins in theta, eta
1373 // themin minimum angle in theta (degrees)
1374 // themax maximum angle in theta (degrees)
1376 // phimin minimum angle in phi (degrees)
1377 // phimax maximum angle in phi (degrees)
1378 // rmin minimum radius
1379 // rmax maximum radius
1382 // The number of events generated = ntheta*nphi
1383 // run input parameters in macro setup (default="Config.C")
1385 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1388 <img src="picts/AliRunLego1.gif">
1393 <img src="picts/AliRunLego2.gif">
1398 <img src="picts/AliRunLego3.gif">
1403 // check if initialisation has been done
1404 if (!fInitDone) InitMC(setup);
1406 //Save current generator
1407 AliGenerator *gen=Generator();
1409 //Create Lego object
1410 fLego = new AliLego("lego",ntheta,themin,themax,nphi,phimin,phimax,rmin,rmax,zmax);
1412 //Prepare MC for Lego Run
1416 gMC->ProcessRun(ntheta*nphi+1);
1418 // Create only the Root event Tree
1421 // End of this run, close files
1424 // Delete Lego Object
1425 delete fLego; fLego=0;
1427 // Restore current generator
1431 //_____________________________________________________________________________
1432 void AliRun::SetCurrentTrack(Int_t track)
1435 // Set current track number
1440 //_____________________________________________________________________________
1441 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1442 Float_t *vpos, Float_t *polar, Float_t tof,
1443 const char *mecha, Int_t &ntr, Float_t weight)
1446 // Load a track on the stack
1448 // done 0 if the track has to be transported
1450 // parent identifier of the parent track. -1 for a primary
1451 // pdg particle code
1452 // pmom momentum GeV/c
1454 // polar polarisation
1455 // tof time of flight in seconds
1456 // mecha production mechanism
1457 // ntr on output the number of the track stored
1459 TClonesArray &particles = *fParticles;
1460 TParticle *particle;
1462 const Int_t firstdaughter=-1;
1463 const Int_t lastdaughter=-1;
1465 // const Float_t tlife=0;
1468 // Here we get the static mass
1469 // For MC is ok, but a more sophisticated method could be necessary
1470 // if the calculated mass is required
1471 // also, this method is potentially dangerous if the mass
1472 // used in the MC is not the same of the PDG database
1474 mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
1475 Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+
1476 pmom[1]*pmom[1]+pmom[2]*pmom[2]);
1478 //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",
1479 //pname,mass,e,fNtrack,pdg,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],KS,mecha);
1481 particle=new(particles[fNtrack]) TParticle(pdg,KS,parent,-1,firstdaughter,
1482 lastdaughter,pmom[0],pmom[1],pmom[2],
1483 e,vpos[0],vpos[1],vpos[2],tof);
1484 // polar[0],polar[1],polar[2],tof,
1486 ((TParticle*)particles[fNtrack])->SetPolarisation(TVector3(polar[0],polar[1],polar[2]));
1487 ((TParticle*)particles[fNtrack])->SetWeight(weight);
1488 if(!done) particle->SetBit(Done_Bit);
1489 //Declare that the daughter information is valid
1490 ((TParticle*)particles[fNtrack])->SetBit(Daughters_Bit);
1493 particle=(TParticle*) fParticles->UncheckedAt(parent);
1494 particle->SetLastDaughter(fNtrack);
1495 if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack);
1498 // This is a primary track. Set high water mark for this event
1501 // Set also number if primary tracks
1502 fHeader.SetNprimary(fHgwmk+1);
1503 fHeader.SetNtrack(fHgwmk+1);
1508 //_____________________________________________________________________________
1509 void AliRun::KeepTrack(const Int_t track)
1512 // flags a track to be kept
1514 TClonesArray &particles = *fParticles;
1515 ((TParticle*)particles[track])->SetBit(Keep_Bit);
1518 //_____________________________________________________________________________
1519 void AliRun::StepManager(Int_t id)
1522 // Called at every step during transport
1526 // --- If lego option, do it and leave
1528 fLego->StepManager();
1531 //Update energy deposition tables
1532 AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
1534 //Call the appropriate stepping routine;
1535 AliModule *det = (AliModule*)fModules->At(id);
1536 if(det) det->StepManager();
1540 //_____________________________________________________________________________
1541 void AliRun::Streamer(TBuffer &R__b)
1544 // Stream an object of class AliRun.
1546 if (R__b.IsReading()) {
1547 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1548 TNamed::Streamer(R__b);
1549 if (!gAlice) gAlice = this;
1550 gROOT->GetListOfBrowsables()->Add(this,"Run");
1551 fTreeE = (TTree*)gDirectory->Get("TE");
1552 if (fTreeE) fTreeE->SetBranchAddress("Header", &header);
1553 else Error("Streamer","cannot find Header Tree\n");
1557 fHeader.Streamer(R__b);
1567 R__b >> fPDGDB; //Particle factory object!
1568 fTreeE->GetEntry(0);
1570 fHeader.SetEvent(0);
1571 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
1574 fConfigFunction.Streamer(R__b);
1576 fConfigFunction="Config();";
1579 R__b.WriteVersion(AliRun::IsA());
1580 TNamed::Streamer(R__b);
1584 fHeader.Streamer(R__b);
1593 R__b << fPDGDB; //Particle factory object!
1594 fConfigFunction.Streamer(R__b);