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.42 2000/10/02 21:28:14 fca
19 Removal of useless dependecies via forward declarations
21 Revision 1.41 2000/07/13 16:19:09 fca
22 Mainly coding conventions + some small bug fixes
24 Revision 1.40 2000/07/12 08:56:25 fca
25 Coding convention correction and warning removal
27 Revision 1.39 2000/07/11 18:24:59 fca
28 Coding convention corrections + few minor bug fixes
30 Revision 1.38 2000/06/20 13:05:45 fca
31 Writing down the TREE headers before job starts
33 Revision 1.37 2000/06/09 20:05:11 morsch
34 Introduce possibility to chose magnetic field version 3: AliMagFDM + field02.dat
36 Revision 1.36 2000/06/08 14:03:58 hristov
37 Only one initializer for a default argument
39 Revision 1.35 2000/06/07 10:13:14 hristov
40 Delete only existent objects.
42 Revision 1.34 2000/05/18 10:45:38 fca
43 Delete Particle Factory properly
45 Revision 1.33 2000/05/16 13:10:40 fca
46 New method IsNewTrack and fix for a problem in Father-Daughter relations
48 Revision 1.32 2000/04/27 10:38:21 fca
49 Correct termination of Lego Run and introduce Lego getter in AliRun
51 Revision 1.31 2000/04/26 10:17:32 fca
52 Changes in Lego for G4 compatibility
54 Revision 1.30 2000/04/18 19:11:40 fca
55 Introduce variable Config.C function signature
57 Revision 1.29 2000/04/07 11:12:34 fca
58 G4 compatibility changes
60 Revision 1.28 2000/04/05 06:51:06 fca
61 Workaround for an HP compiler problem
63 Revision 1.27 2000/03/22 18:08:07 fca
64 Rationalisation of the virtual MC interfaces
66 Revision 1.26 2000/03/22 13:42:26 fca
67 SetGenerator does not replace an existing generator, ResetGenerator does
69 Revision 1.25 2000/02/23 16:25:22 fca
70 AliVMC and AliGeant3 classes introduced
71 ReadEuclid moved from AliRun to AliModule
73 Revision 1.24 2000/01/19 17:17:20 fca
74 Introducing a list of lists of hits -- more hits allowed for detector now
76 Revision 1.23 1999/12/03 11:14:31 fca
77 Fixing previous wrong checking
79 Revision 1.21 1999/11/25 10:40:08 fca
80 Fixing daughters information also in primary tracks
82 Revision 1.20 1999/10/04 18:08:49 fca
83 Adding protection against inconsistent Euclid files
85 Revision 1.19 1999/09/29 07:50:40 fca
86 Introduction of the Copyright and cvs Log
90 ///////////////////////////////////////////////////////////////////////////////
92 // Control class for Alice C++ //
93 // Only one single instance of this class exists. //
94 // The object is created in main program aliroot //
95 // and is pointed by the global gAlice. //
97 // -Supports the list of all Alice Detectors (fModules). //
98 // -Supports the list of particles (fParticles). //
99 // -Supports the Trees. //
100 // -Supports the geometry. //
101 // -Supports the event display. //
104 <img src="picts/AliRunClass.gif">
109 <img src="picts/alirun.gif">
113 ///////////////////////////////////////////////////////////////////////////////
125 #include <TObjectTable.h>
127 #include <TGeometry.h>
129 #include "TBrowser.h"
131 #include "TParticle.h"
133 #include "AliDisplay.h"
136 #include "AliMagFC.h"
137 #include "AliMagFCM.h"
138 #include "AliMagFDM.h"
141 #include "AliDetector.h"
145 static AliHeader *gAliHeader;
149 //_____________________________________________________________________________
153 // Default constructor for AliRun
177 fPDGDB = 0; //Particle factory object!
179 fConfigFunction = "\0";
182 //_____________________________________________________________________________
183 AliRun::AliRun(const char *name, const char *title)
187 // Constructor for the main processor.
188 // Creates the geometry
189 // Creates the list of Detectors.
190 // Creates the list of particles.
206 fConfigFunction = "Config();";
208 gROOT->GetListOfBrowsables()->Add(this,name);
210 // create the support list for the various Detectors
211 fModules = new TObjArray(77);
213 // Create the TNode geometry for the event display
215 BuildSimpleGeometry();
225 // Create the particle stack
226 fParticles = new TClonesArray("TParticle",100);
230 // Create default mag field
235 // Prepare the tracking medium lists
236 fImedia = new TArrayI(1000);
237 for(i=0;i<1000;i++) (*fImedia)[i]=-99;
240 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
242 // Create HitLists list
243 fHitLists = new TList();
247 //_____________________________________________________________________________
251 // Defaullt AliRun destructor
270 fParticles->Delete();
277 //_____________________________________________________________________________
278 void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
281 // Add a hit to detector id
283 TObjArray &dets = *fModules;
284 if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits);
287 //_____________________________________________________________________________
288 void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
291 // Add digit to detector id
293 TObjArray &dets = *fModules;
294 if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits);
297 //_____________________________________________________________________________
298 void AliRun::Browse(TBrowser *b)
301 // Called when the item "Run" is clicked on the left pane
302 // of the Root browser.
303 // It displays the Root Trees and all detectors.
305 if (fTreeK) b->Add(fTreeK,fTreeK->GetName());
306 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
307 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
308 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
309 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
311 TIter next(fModules);
313 while((detector = (AliModule*)next())) {
314 b->Add(detector,detector->GetName());
318 //_____________________________________________________________________________
322 // Initialize Alice geometry
327 //_____________________________________________________________________________
328 void AliRun::BuildSimpleGeometry()
331 // Create a simple TNode geometry used by Root display engine
333 // Initialise geometry
335 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
336 new TMaterial("void","Vacuum",0,0,0); //Everything is void
337 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
338 brik->SetVisibility(0);
339 new TNode("alice","alice","S_alice");
342 //_____________________________________________________________________________
343 void AliRun::CleanDetectors()
346 // Clean Detectors at the end of event
348 TIter next(fModules);
350 while((detector = (AliModule*)next())) {
351 detector->FinishEvent();
355 //_____________________________________________________________________________
356 void AliRun::CleanParents()
359 // Clean Particles stack.
360 // Set parent/daughter relations
362 TClonesArray &particles = *(gAlice->Particles());
365 for(i=0; i<fNtrack; i++) {
366 part = (TParticle *)particles.UncheckedAt(i);
367 if(!part->TestBit(kDaughtersBit)) {
368 part->SetFirstDaughter(-1);
369 part->SetLastDaughter(-1);
374 //_____________________________________________________________________________
375 Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
378 // Return the distance from the mouse to the AliRun object
384 //_____________________________________________________________________________
385 void AliRun::DumpPart (Int_t i) const
388 // Dumps particle i in the stack
390 TClonesArray &particles = *fParticles;
391 ((TParticle*) particles[i])->Print();
394 //_____________________________________________________________________________
395 void AliRun::DumpPStack () const
398 // Dumps the particle stack
400 TClonesArray &particles = *fParticles;
402 "\n\n=======================================================================\n");
403 for (Int_t i=0;i<fNtrack;i++)
405 printf("-> %d ",i); ((TParticle*) particles[i])->Print();
406 printf("--------------------------------------------------------------\n");
409 "\n=======================================================================\n\n");
412 //_____________________________________________________________________________
413 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
414 Float_t maxField, char* filename)
417 // Set magnetic field parameters
418 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
419 // version Magnetic field map version (only 1 active now)
420 // scale Scale factor for the magnetic field
421 // maxField Maximum value for the magnetic field
424 // --- Sanity check on mag field flags
425 if(type<0 || type > 2) {
427 "Invalid magnetic field flag: %5d; Helix tracking chosen instead\n"
431 if(fField) delete fField;
433 fField = new AliMagFC("Map1"," ",type,version,scale,maxField);
434 } else if(version<=2) {
435 fField = new AliMagFCM("Map2-3",filename,type,version,scale,maxField);
437 } else if(version==3) {
438 fField = new AliMagFDM("Map4",filename,type,version,scale,maxField);
441 Warning("SetField","Invalid map %d\n",version);
445 //_____________________________________________________________________________
446 void AliRun::FillTree()
449 // Fills all AliRun TTrees
451 if (fTreeK) fTreeK->Fill();
452 if (fTreeH) fTreeH->Fill();
453 if (fTreeD) fTreeD->Fill();
454 if (fTreeR) fTreeR->Fill();
457 //_____________________________________________________________________________
458 void AliRun::FinishPrimary()
461 // Called at the end of each primary track
464 // static Int_t count=0;
465 // const Int_t times=10;
466 // This primary is finished, purify stack
469 TIter next(fModules);
471 while((detector = (AliModule*)next())) {
472 detector->FinishPrimary();
475 // Write out hits if any
476 if (gAlice->TreeH()) {
477 gAlice->TreeH()->Fill();
484 // if(++count%times==1) gObjectTable->Print();
487 //_____________________________________________________________________________
488 void AliRun::FinishEvent()
491 // Called at the end of the event.
495 if(fLego) fLego->FinishEvent();
497 //Update the energy deposit tables
499 for(i=0;i<fEventEnergy.GetSize();i++) {
500 fSummEnergy[i]+=fEventEnergy[i];
501 fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
503 fEventEnergy.Reset();
505 // Clean detector information
508 // Write out the kinematics
514 // Write out the digits
520 // Write out reconstructed clusters
525 // Write out the event Header information
526 if (fTreeE) fTreeE->Fill();
531 // Write Tree headers
532 // Int_t ievent = fHeader.GetEvent();
534 // sprintf(hname,"TreeK%d",ievent);
535 if (fTreeK) fTreeK->Write(0,TObject::kOverwrite);
536 // sprintf(hname,"TreeH%d",ievent);
537 if (fTreeH) fTreeH->Write(0,TObject::kOverwrite);
538 // sprintf(hname,"TreeD%d",ievent);
539 if (fTreeD) fTreeD->Write(0,TObject::kOverwrite);
540 // sprintf(hname,"TreeR%d",ievent);
541 if (fTreeR) fTreeR->Write(0,TObject::kOverwrite);
546 //_____________________________________________________________________________
547 void AliRun::FinishRun()
550 // Called at the end of the run.
554 if(fLego) fLego->FinishRun();
556 // Clean detector information
557 TIter next(fModules);
559 while((detector = (AliModule*)next())) {
560 detector->FinishRun();
563 //Output energy summary tables
566 // file is retrieved from whatever tree
568 if (fTreeK) file = fTreeK->GetCurrentFile();
569 if ((!file) && (fTreeH)) file = fTreeH->GetCurrentFile();
570 if ((!file) && (fTreeD)) file = fTreeD->GetCurrentFile();
571 if ((!file) && (fTreeE)) file = fTreeE->GetCurrentFile();
573 Error("FinishRun","There isn't root file!");
577 fTreeE->Write(0,TObject::kOverwrite);
579 // Clean tree information
581 delete fTreeK; fTreeK = 0;
584 delete fTreeH; fTreeH = 0;
587 delete fTreeD; fTreeD = 0;
590 delete fTreeR; fTreeR = 0;
593 delete fTreeE; fTreeE = 0;
596 // Write AliRun info and all detectors parameters
603 //_____________________________________________________________________________
604 void AliRun::FlagTrack(Int_t track)
607 // Flags a track and all its family tree to be kept
614 particle=(TParticle*)fParticles->UncheckedAt(curr);
616 // If the particle is flagged the three from here upward is saved already
617 if(particle->TestBit(kKeepBit)) return;
619 // Save this particle
620 particle->SetBit(kKeepBit);
622 // Move to father if any
623 if((curr=particle->GetFirstMother())==-1) return;
627 //_____________________________________________________________________________
628 void AliRun::EnergySummary()
631 // Print summary of deposited energy
637 Int_t kn, i, left, j, id;
638 const Float_t kzero=0;
639 Int_t ievent=fHeader.GetEvent()+1;
641 // Energy loss information
643 printf("***************** Energy Loss Information per event (GEV) *****************\n");
644 for(kn=1;kn<fEventEnergy.GetSize();kn++) {
647 fEventEnergy[ndep]=kn;
652 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,kzero))/ed;
655 fSummEnergy[ndep]=ed;
656 fSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,kzero));
661 for(kn=0;kn<(ndep-1)/3+1;kn++) {
663 for(i=0;i<(3<left?3:left);i++) {
665 id=Int_t (fEventEnergy[j]+0.1);
666 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]);
671 // Relative energy loss in different detectors
672 printf("******************** Relative Energy Loss per event ********************\n");
673 printf("Total energy loss per event %10.3f GeV\n",edtot);
674 for(kn=0;kn<(ndep-1)/5+1;kn++) {
676 for(i=0;i<(5<left?5:left);i++) {
678 id=Int_t (fEventEnergy[j]+0.1);
679 printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot);
683 for(kn=0;kn<75;kn++) printf("*");
687 // Reset the TArray's
688 // fEventEnergy.Set(0);
689 // fSummEnergy.Set(0);
690 // fSum2Energy.Set(0);
693 //_____________________________________________________________________________
694 AliModule *AliRun::GetModule(const char *name) const
697 // Return pointer to detector from name
699 return (AliModule*)fModules->FindObject(name);
702 //_____________________________________________________________________________
703 AliDetector *AliRun::GetDetector(const char *name) const
706 // Return pointer to detector from name
708 return (AliDetector*)fModules->FindObject(name);
711 //_____________________________________________________________________________
712 Int_t AliRun::GetModuleID(const char *name) const
715 // Return galice internal detector identifier from name
718 TObject *mod=fModules->FindObject(name);
719 if(mod) i=fModules->IndexOf(mod);
723 //_____________________________________________________________________________
724 Int_t AliRun::GetEvent(Int_t event)
727 // Connect the Trees Kinematics and Hits for event # event
728 // Set branch addresses
731 // Reset existing structures
736 // Delete Trees already connected
737 if (fTreeK) delete fTreeK;
738 if (fTreeH) delete fTreeH;
739 if (fTreeD) delete fTreeD;
740 if (fTreeR) delete fTreeR;
742 // Get header from file
743 if(fTreeE) fTreeE->GetEntry(event);
744 else Error("GetEvent","Cannot file Header Tree\n");
746 // Get Kine Tree from file
748 sprintf(treeName,"TreeK%d",event);
749 fTreeK = (TTree*)gDirectory->Get(treeName);
750 if (fTreeK) fTreeK->SetBranchAddress("Particles", &fParticles);
751 else Error("GetEvent","cannot find Kine Tree for event:%d\n",event);
753 // Get Hits Tree header from file
754 sprintf(treeName,"TreeH%d",event);
755 fTreeH = (TTree*)gDirectory->Get(treeName);
757 Error("GetEvent","cannot find Hits Tree for event:%d\n",event);
760 // Get Digits Tree header from file
761 sprintf(treeName,"TreeD%d",event);
762 fTreeD = (TTree*)gDirectory->Get(treeName);
764 Warning("GetEvent","cannot find Digits Tree for event:%d\n",event);
768 // Get Reconstruct Tree header from file
769 sprintf(treeName,"TreeR%d",event);
770 fTreeR = (TTree*)gDirectory->Get(treeName);
772 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
775 // Set Trees branch addresses
776 TIter next(fModules);
778 while((detector = (AliModule*)next())) {
779 detector->SetTreeAddress();
782 if (fTreeK) fTreeK->GetEvent(0);
783 fNtrack = Int_t (fParticles->GetEntries());
787 //_____________________________________________________________________________
788 TGeometry *AliRun::GetGeometry()
791 // Import Alice geometry from current file
792 // Return pointer to geometry object
794 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
796 // Unlink and relink nodes in detectors
797 // This is bad and there must be a better way...
800 TIter next(fModules);
802 while((detector = (AliModule*)next())) {
803 detector->SetTreeAddress();
804 TList *dnodes=detector->Nodes();
807 for ( j=0; j<dnodes->GetSize(); j++) {
808 node = (TNode*) dnodes->At(j);
809 node1 = fGeometry->GetNode(node->GetName());
810 dnodes->Remove(node);
811 dnodes->AddAt(node1,j);
817 //_____________________________________________________________________________
818 void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
819 Float_t &e, Float_t *vpos, Float_t *polar,
823 // Return next track from stack of particles
828 for(Int_t i=fNtrack-1; i>=0; i--) {
829 track=(TParticle*) fParticles->UncheckedAt(i);
830 if(!track->TestBit(kDoneBit)) {
832 // The track has not yet been processed
834 ipart=track->GetPdgCode();
842 track->GetPolarisation(pol);
847 track->SetBit(kDoneBit);
853 // stop and start timer when we start a primary track
854 Int_t nprimaries = fHeader.GetNprimary();
855 if (fCurrent >= nprimaries) return;
856 if (fCurrent < nprimaries-1) {
858 track=(TParticle*) fParticles->UncheckedAt(fCurrent+1);
859 // track->SetProcessTime(fTimer.CpuTime());
864 //_____________________________________________________________________________
865 Int_t AliRun::GetPrimary(Int_t track) const
868 // return number of primary that has generated track
876 part = (TParticle *)fParticles->UncheckedAt(current);
877 parent=part->GetFirstMother();
878 if(parent<0) return current;
882 //_____________________________________________________________________________
883 void AliRun::InitMC(const char *setup)
886 // Initialize the Alice setup
890 Warning("Init","Cannot initialise AliRun twice!\n");
894 gROOT->LoadMacro(setup);
895 gInterpreter->ProcessLine(fConfigFunction.Data());
897 gMC->DefineParticles(); //Create standard MC particles
899 TObject *objfirst, *objlast;
901 fNdets = fModules->GetLast()+1;
904 //=================Create Materials and geometry
907 TIter next(fModules);
909 while((detector = (AliModule*)next())) {
910 detector->SetTreeAddress();
911 objlast = gDirectory->GetList()->Last();
913 // Add Detector histograms in Detector list of histograms
914 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
915 else objfirst = gDirectory->GetList()->First();
917 detector->Histograms()->Add(objfirst);
918 objfirst = gDirectory->GetList()->After(objfirst);
921 SetTransPar(); //Read the cuts for all materials
923 MediaTable(); //Build the special IMEDIA table
925 //Initialise geometry deposition table
926 fEventEnergy.Set(gMC->NofVolumes()+1);
927 fSummEnergy.Set(gMC->NofVolumes()+1);
928 fSum2Energy.Set(gMC->NofVolumes()+1);
930 //Compute cross-sections
933 //Write Geometry object to current file.
939 // Save stuff at the beginning of the file to avoid file corruption
943 //_____________________________________________________________________________
944 void AliRun::MediaTable()
947 // Built media table to get from the media number to
950 Int_t kz, nz, idt, lz, i, k, ind;
952 TObjArray &dets = *gAlice->Detectors();
956 for (kz=0;kz<fNdets;kz++) {
957 // If detector is defined
958 if((det=(AliModule*) dets[kz])) {
959 TArrayI &idtmed = *(det->GetIdtmed());
960 for(nz=0;nz<100;nz++) {
961 // Find max and min material number
962 if((idt=idtmed[nz])) {
963 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
964 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
967 if(det->LoMedium() > det->HiMedium()) {
971 if(det->HiMedium() > fImedia->GetSize()) {
972 Error("MediaTable","Increase fImedia from %d to %d",
973 fImedia->GetSize(),det->HiMedium());
976 // Tag all materials in rage as belonging to detector kz
977 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
984 // Print summary table
985 printf(" Traking media ranges:\n");
986 for(i=0;i<(fNdets-1)/6+1;i++) {
987 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
989 det=(AliModule*)dets[ind];
991 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
994 printf(" %6s: %3d -> %3d;","NULL",0,0);
1000 //____________________________________________________________________________
1001 void AliRun::SetGenerator(AliGenerator *generator)
1004 // Load the event generator
1006 if(!fGenerator) fGenerator = generator;
1009 //____________________________________________________________________________
1010 void AliRun::ResetGenerator(AliGenerator *generator)
1013 // Load the event generator
1017 Warning("ResetGenerator","Replacing generator %s with %s\n",
1018 fGenerator->GetName(),generator->GetName());
1020 Warning("ResetGenerator","Replacing generator %s with NULL\n",
1021 fGenerator->GetName());
1022 fGenerator = generator;
1025 //____________________________________________________________________________
1026 void AliRun::SetTransPar(char* filename)
1029 // Read filename to set the transport parameters
1033 const Int_t kncuts=10;
1034 const Int_t knflags=11;
1035 const Int_t knpars=kncuts+knflags;
1036 const char kpars[knpars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
1037 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
1038 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
1039 "MULS","PAIR","PHOT","RAYL"};
1043 Float_t cut[kncuts];
1044 Int_t flag[knflags];
1045 Int_t i, itmed, iret, ktmed, kz;
1048 // See whether the file is there
1049 filtmp=gSystem->ExpandPathName(filename);
1050 lun=fopen(filtmp,"r");
1053 Warning("SetTransPar","File %s does not exist!\n",filename);
1057 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1058 printf(" *%59s\n","*");
1059 printf(" * Please check carefully what you are doing!%10s\n","*");
1060 printf(" *%59s\n","*");
1063 // Initialise cuts and flags
1064 for(i=0;i<kncuts;i++) cut[i]=-99;
1065 for(i=0;i<knflags;i++) flag[i]=-99;
1067 for(i=0;i<256;i++) line[i]='\0';
1068 // Read up to the end of line excluded
1069 iret=fscanf(lun,"%[^\n]",line);
1073 printf(" *%59s\n","*");
1074 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1077 // Read the end of line
1080 if(line[0]=='*') continue;
1082 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",
1083 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
1084 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
1085 &flag[8],&flag[9],&flag[10]);
1089 Warning("SetTransPar","Error reading file %s\n",filename);
1092 // Check that the module exist
1093 AliModule *mod = GetModule(detName);
1095 // Get the array of media numbers
1096 TArrayI &idtmed = *mod->GetIdtmed();
1097 // Check that the tracking medium code is valid
1098 if(0<=itmed && itmed < 100) {
1099 ktmed=idtmed[itmed];
1101 Warning("SetTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
1104 // Set energy thresholds
1105 for(kz=0;kz<kncuts;kz++) {
1107 printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
1108 kpars[kz],cut[kz],itmed,mod->GetName());
1109 gMC->Gstpar(ktmed,kpars[kz],cut[kz]);
1112 // Set transport mechanisms
1113 for(kz=0;kz<knflags;kz++) {
1115 printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
1116 kpars[kncuts+kz],flag[kz],itmed,mod->GetName());
1117 gMC->Gstpar(ktmed,kpars[kncuts+kz],Float_t(flag[kz]));
1121 Warning("SetTransPar","Invalid medium code %d *\n",itmed);
1125 Warning("SetTransPar","Module %s not present\n",detName);
1131 //_____________________________________________________________________________
1132 void AliRun::MakeTree(Option_t *option)
1135 // Create the ROOT trees
1136 // Loop on all detectors to create the Root branch (if any)
1142 char *oK = strstr(option,"K");
1143 char *oH = strstr(option,"H");
1144 char *oE = strstr(option,"E");
1145 char *oD = strstr(option,"D");
1146 char *oR = strstr(option,"R");
1148 if (oK && !fTreeK) {
1149 sprintf(hname,"TreeK%d",fEvent);
1150 fTreeK = new TTree(hname,"Kinematics");
1151 // Create a branch for particles
1152 fTreeK->Branch("Particles",&fParticles,4000);
1155 if (oH && !fTreeH) {
1156 sprintf(hname,"TreeH%d",fEvent);
1157 fTreeH = new TTree(hname,"Hits");
1158 fTreeH->SetAutoSave(1000000000); //no autosave
1161 if (oD && !fTreeD) {
1162 sprintf(hname,"TreeD%d",fEvent);
1163 fTreeD = new TTree(hname,"Digits");
1166 if (oR && !fTreeR) {
1167 sprintf(hname,"TreeR%d",fEvent);
1168 fTreeR = new TTree(hname,"Reconstruction");
1171 if (oE && !fTreeE) {
1172 fTreeE = new TTree("TE","Header");
1173 // Create a branch for Header
1174 fTreeE->Branch("Header","AliHeader",&gAliHeader,4000);
1178 // Create a branch for hits/digits for each detector
1179 // Each branch is a TClonesArray. Each data member of the Hits classes
1180 // will be in turn a subbranch of the detector master branch
1181 TIter next(fModules);
1182 AliModule *detector;
1183 while((detector = (AliModule*)next())) {
1184 if (oH || oD || oR) detector->MakeBranch(option);
1188 //_____________________________________________________________________________
1189 Int_t AliRun::PurifyKine(Int_t lastSavedTrack, Int_t nofTracks)
1192 // PurifyKine with external parameters
1194 fHgwmk = lastSavedTrack;
1195 fNtrack = nofTracks;
1200 //_____________________________________________________________________________
1201 void AliRun::PurifyKine()
1204 // Compress kinematic tree keeping only flagged particles
1205 // and renaming the particle id's in all the hits
1207 TClonesArray &particles = *fParticles;
1208 int nkeep=fHgwmk+1, parent, i;
1209 TParticle *part, *partnew, *father;
1210 int *map = new int[particles.GetEntries()];
1212 // Save in Header total number of tracks before compression
1213 fHeader.SetNtrack(fHeader.GetNtrack()+fNtrack-fHgwmk);
1215 // First pass, invalid Daughter information
1216 for(i=0; i<fNtrack; i++) {
1217 // Preset map, to be removed later
1218 if(i<=fHgwmk) map[i]=i ; else map[i] = -99;
1219 ((TParticle *)particles.UncheckedAt(i))->ResetBit(kDaughtersBit);
1221 // Second pass, build map between old and new numbering
1222 for(i=fHgwmk+1; i<fNtrack; i++) {
1223 part = (TParticle *)particles.UncheckedAt(i);
1224 if(part->TestBit(kKeepBit)) {
1226 // This particle has to be kept
1230 // Old and new are different, have to copy
1231 partnew = (TParticle *)particles.UncheckedAt(nkeep);
1232 // Change due to a bug in the HP compiler
1233 // *partnew = *part;
1234 memcpy(partnew,part,sizeof(TParticle));
1235 } else partnew = part;
1237 // as the parent is always *before*, it must be already
1238 // in place. This is what we are checking anyway!
1239 if((parent=partnew->GetFirstMother())>fHgwmk) {
1240 if(map[parent]==-99) printf("map[%d] = -99!\n",parent);
1241 partnew->SetFirstMother(map[parent]);
1248 // Fix daughters information
1249 for (i=0; i<fNtrack; i++) {
1250 part = (TParticle *)particles.UncheckedAt(i);
1251 parent = part->GetFirstMother();
1253 father = (TParticle *)particles.UncheckedAt(parent);
1254 if(father->TestBit(kDaughtersBit)) {
1256 if(i<father->GetFirstDaughter()) father->SetFirstDaughter(i);
1257 if(i>father->GetLastDaughter()) father->SetLastDaughter(i);
1259 // Iitialise daughters info for first pass
1260 father->SetFirstDaughter(i);
1261 father->SetLastDaughter(i);
1262 father->SetBit(kDaughtersBit);
1268 // Now loop on all detectors and reset the hits
1270 TIter next(fModules);
1271 AliModule *detector;
1272 while((detector = (AliModule*)next())) {
1273 if (!detector->Hits()) continue;
1274 TClonesArray &vHits=*(detector->Hits());
1275 if(vHits.GetEntries() != detector->GetNhits())
1276 printf("vHits.GetEntries()!=detector->GetNhits(): %d != %d\n",
1277 vHits.GetEntries(),detector->GetNhits());
1278 for (i=0; i<detector->GetNhits(); i++) {
1279 OneHit = (AliHit *)vHits.UncheckedAt(i);
1280 OneHit->SetTrack(map[OneHit->GetTrack()]);
1285 // Now loop on all registered hit lists
1286 TIter next(fHitLists);
1287 TCollection *hitList;
1288 while((hitList = (TCollection*)next())) {
1289 TIter nexthit(hitList);
1291 while((hit = (AliHit*)nexthit())) {
1292 hit->SetTrack(map[hit->GetTrack()]);
1298 // This for detectors which have a special mapping mechanism
1299 // for hits, such as TPC and TRD
1302 TIter nextmod(fModules);
1303 AliModule *detector;
1304 while((detector = (AliModule*)nextmod())) {
1305 detector->RemapTrackHitIDs(map);
1310 particles.SetLast(fHgwmk);
1314 //_____________________________________________________________________________
1315 void AliRun::BeginEvent()
1318 // Reset all Detectors & kinematics & trees
1325 fLego->BeginEvent();
1334 // Initialise event header
1335 fHeader.Reset(fRun,fEvent);
1339 sprintf(hname,"TreeK%d",fEvent);
1340 fTreeK->SetName(hname);
1344 sprintf(hname,"TreeH%d",fEvent);
1345 fTreeH->SetName(hname);
1349 sprintf(hname,"TreeD%d",fEvent);
1350 fTreeD->SetName(hname);
1354 sprintf(hname,"TreeR%d",fEvent);
1355 fTreeR->SetName(hname);
1359 //_____________________________________________________________________________
1360 void AliRun::ResetDigits()
1363 // Reset all Detectors digits
1365 TIter next(fModules);
1366 AliModule *detector;
1367 while((detector = (AliModule*)next())) {
1368 detector->ResetDigits();
1372 //_____________________________________________________________________________
1373 void AliRun::ResetHits()
1376 // Reset all Detectors hits
1378 TIter next(fModules);
1379 AliModule *detector;
1380 while((detector = (AliModule*)next())) {
1381 detector->ResetHits();
1385 //_____________________________________________________________________________
1386 void AliRun::ResetPoints()
1389 // Reset all Detectors points
1391 TIter next(fModules);
1392 AliModule *detector;
1393 while((detector = (AliModule*)next())) {
1394 detector->ResetPoints();
1398 //_____________________________________________________________________________
1399 void AliRun::RunMC(Int_t nevent, const char *setup)
1402 // Main function to be called to process a galice run
1404 // Root > gAlice.Run();
1405 // a positive number of events will cause the finish routine
1409 // check if initialisation has been done
1410 if (!fInitDone) InitMC(setup);
1412 // Create the Root Tree with one branch per detector
1415 gMC->ProcessRun(nevent);
1417 // End of this run, close files
1418 if(nevent>0) FinishRun();
1421 //_____________________________________________________________________________
1422 void AliRun::RunLego(const char *setup,Int_t ntheta,Float_t themin,
1423 Float_t themax,Int_t nphi,Float_t phimin,Float_t phimax,
1424 Float_t rmin,Float_t rmax,Float_t zmax)
1427 // Generates lego plots of:
1428 // - radiation length map phi vs theta
1429 // - radiation length map phi vs eta
1430 // - interaction length map
1431 // - g/cm2 length map
1433 // ntheta bins in theta, eta
1434 // themin minimum angle in theta (degrees)
1435 // themax maximum angle in theta (degrees)
1437 // phimin minimum angle in phi (degrees)
1438 // phimax maximum angle in phi (degrees)
1439 // rmin minimum radius
1440 // rmax maximum radius
1443 // The number of events generated = ntheta*nphi
1444 // run input parameters in macro setup (default="Config.C")
1446 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1449 <img src="picts/AliRunLego1.gif">
1454 <img src="picts/AliRunLego2.gif">
1459 <img src="picts/AliRunLego3.gif">
1464 // check if initialisation has been done
1465 if (!fInitDone) InitMC(setup);
1467 //Save current generator
1468 AliGenerator *gen=Generator();
1470 //Create Lego object
1471 fLego = new AliLego("lego",ntheta,themin,themax,nphi,phimin,phimax,rmin,rmax,zmax);
1473 //Prepare MC for Lego Run
1477 gMC->ProcessRun(ntheta*nphi+1);
1479 // Create only the Root event Tree
1482 // End of this run, close files
1485 // Delete Lego Object
1486 delete fLego; fLego=0;
1488 // Restore current generator
1492 //_____________________________________________________________________________
1493 void AliRun::SetConfigFunction(const char * config)
1496 // Set the signature of the function contained in Config.C to configure
1499 fConfigFunction=config;
1502 //_____________________________________________________________________________
1503 void AliRun::SetCurrentTrack(Int_t track)
1506 // Set current track number
1511 //_____________________________________________________________________________
1512 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1513 Float_t *vpos, Float_t *polar, Float_t tof,
1514 const char* /* mecha */, Int_t &ntr, Float_t weight)
1517 // Load a track on the stack
1519 // done 0 if the track has to be transported
1521 // parent identifier of the parent track. -1 for a primary
1522 // pdg particle code
1523 // pmom momentum GeV/c
1525 // polar polarisation
1526 // tof time of flight in seconds
1527 // mecha production mechanism
1528 // ntr on output the number of the track stored
1530 TClonesArray &particles = *fParticles;
1531 TParticle *particle;
1533 const Int_t kfirstdaughter=-1;
1534 const Int_t klastdaughter=-1;
1536 // const Float_t tlife=0;
1539 // Here we get the static mass
1540 // For MC is ok, but a more sophisticated method could be necessary
1541 // if the calculated mass is required
1542 // also, this method is potentially dangerous if the mass
1543 // used in the MC is not the same of the PDG database
1545 mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
1546 Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+
1547 pmom[1]*pmom[1]+pmom[2]*pmom[2]);
1549 //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",
1550 //pname,mass,e,fNtrack,pdg,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],kS,mecha);
1552 particle=new(particles[fNtrack]) TParticle(pdg,kS,parent,-1,kfirstdaughter,
1553 klastdaughter,pmom[0],pmom[1],pmom[2],
1554 e,vpos[0],vpos[1],vpos[2],tof);
1555 // polar[0],polar[1],polar[2],tof,
1557 ((TParticle*)particles[fNtrack])->SetPolarisation(TVector3(polar[0],polar[1],polar[2]));
1558 ((TParticle*)particles[fNtrack])->SetWeight(weight);
1559 if(!done) particle->SetBit(kDoneBit);
1560 //Declare that the daughter information is valid
1561 ((TParticle*)particles[fNtrack])->SetBit(kDaughtersBit);
1564 particle=(TParticle*) fParticles->UncheckedAt(parent);
1565 particle->SetLastDaughter(fNtrack);
1566 if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack);
1569 // This is a primary track. Set high water mark for this event
1572 // Set also number if primary tracks
1573 fHeader.SetNprimary(fHgwmk+1);
1574 fHeader.SetNtrack(fHgwmk+1);
1579 //_____________________________________________________________________________
1580 void AliRun::KeepTrack(const Int_t track)
1583 // flags a track to be kept
1585 TClonesArray &particles = *fParticles;
1586 ((TParticle*)particles[track])->SetBit(kKeepBit);
1589 //_____________________________________________________________________________
1590 void AliRun::StepManager(Int_t id)
1593 // Called at every step during transport
1597 // --- If lego option, do it and leave
1599 fLego->StepManager();
1602 //Update energy deposition tables
1603 AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
1605 //Call the appropriate stepping routine;
1606 AliModule *det = (AliModule*)fModules->At(id);
1607 if(det) det->StepManager();
1611 //_____________________________________________________________________________
1612 void AliRun::Streamer(TBuffer &R__b)
1615 // Stream an object of class AliRun.
1617 if (R__b.IsReading()) {
1618 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1619 TNamed::Streamer(R__b);
1620 if (!gAlice) gAlice = this;
1621 gROOT->GetListOfBrowsables()->Add(this,"Run");
1622 fTreeE = (TTree*)gDirectory->Get("TE");
1623 if (fTreeE) fTreeE->SetBranchAddress("Header", &gAliHeader);
1624 else Error("Streamer","cannot find Header Tree\n");
1628 fHeader.Streamer(R__b);
1638 R__b >> fPDGDB; //Particle factory object!
1639 fTreeE->GetEntry(0);
1641 fHeader.SetEvent(0);
1642 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
1645 fConfigFunction.Streamer(R__b);
1647 fConfigFunction="Config();";
1650 R__b.WriteVersion(AliRun::IsA());
1651 TNamed::Streamer(R__b);
1655 fHeader.Streamer(R__b);
1664 R__b << fPDGDB; //Particle factory object!
1665 fConfigFunction.Streamer(R__b);