1 ///////////////////////////////////////////////////////////////////////////////
3 // Control class for Alice C++ //
4 // Only one single instance of this class exists. //
5 // The object is created in main program aliroot //
6 // and is pointed by the global gAlice. //
8 // -Supports the list of all Alice Detectors (fModules). //
9 // -Supports the list of particles (fParticles). //
10 // -Supports the Trees. //
11 // -Supports the geometry. //
12 // -Supports the event display. //
15 <img src="picts/AliRunClass.gif">
20 <img src="picts/alirun.gif">
24 ///////////////////////////////////////////////////////////////////////////////
33 #include "TParticle.h"
35 #include "AliDisplay.h"
37 #include "AliCallf77.h"
45 static AliHeader *header;
49 # define rxgtrak rxgtrak_
50 # define rxstrak rxstrak_
51 # define rxkeep rxkeep_
52 # define rxouth rxouth_
55 # define rxgtrak RXGTRAK
56 # define rxstrak RXSTRAK
57 # define rxkeep RXKEEP
58 # define rxouth RXOUTH
61 static TArrayF sEventEnergy;
62 static TArrayF sSummEnergy;
63 static TArrayF sSum2Energy;
67 //_____________________________________________________________________________
71 // Default constructor for AliRun
95 fPDGDB = 0; //Particle factory object!
98 //_____________________________________________________________________________
99 AliRun::AliRun(const char *name, const char *title)
103 // Constructor for the main processor.
104 // Creates the geometry
105 // Creates the list of Detectors.
106 // Creates the list of particles.
123 gROOT->GetListOfBrowsables()->Add(this,name);
125 // create the support list for the various Detectors
126 fModules = new TObjArray(77);
128 // Create the TNode geometry for the event display
130 BuildSimpleGeometry();
140 // Create the particle stack
141 fParticles = new TClonesArray("TParticle",100);
145 // Create default mag field
150 // Prepare the tracking medium lists
151 fImedia = new TArrayI(1000);
152 for(i=0;i<1000;i++) (*fImedia)[i]=-99;
155 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
158 //_____________________________________________________________________________
162 // Defaullt AliRun destructor
181 fParticles->Delete();
186 //_____________________________________________________________________________
187 void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
190 // Add a hit to detector id
192 TObjArray &dets = *fModules;
193 if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits);
196 //_____________________________________________________________________________
197 void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
200 // Add digit to detector id
202 TObjArray &dets = *fModules;
203 if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits);
206 //_____________________________________________________________________________
207 void AliRun::Browse(TBrowser *b)
210 // Called when the item "Run" is clicked on the left pane
211 // of the Root browser.
212 // It displays the Root Trees and all detectors.
214 if (fTreeK) b->Add(fTreeK,fTreeK->GetName());
215 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
216 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
217 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
218 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
220 TIter next(fModules);
222 while((detector = (AliModule*)next())) {
223 b->Add(detector,detector->GetName());
227 //_____________________________________________________________________________
231 // Initialize Alice geometry
236 //_____________________________________________________________________________
237 void AliRun::BuildSimpleGeometry()
240 // Create a simple TNode geometry used by Root display engine
242 // Initialise geometry
244 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
245 new TMaterial("void","Vacuum",0,0,0); //Everything is void
246 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
247 brik->SetVisibility(0);
248 new TNode("alice","alice","S_alice");
251 //_____________________________________________________________________________
252 void AliRun::CleanDetectors()
255 // Clean Detectors at the end of event
257 TIter next(fModules);
259 while((detector = (AliModule*)next())) {
260 detector->FinishEvent();
264 //_____________________________________________________________________________
265 void AliRun::CleanParents()
268 // Clean Particles stack.
269 // Set parent/daughter relations
271 TClonesArray &particles = *(gAlice->Particles());
274 for(i=0; i<fNtrack; i++) {
275 part = (TParticle *)particles.UncheckedAt(i);
276 if(!part->TestBit(Daughters_Bit)) {
277 part->SetFirstDaughter(-1);
278 part->SetLastDaughter(-1);
283 //_____________________________________________________________________________
284 Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
287 // Return the distance from the mouse to the AliRun object
293 //_____________________________________________________________________________
294 void AliRun::DumpPart (Int_t i)
297 // Dumps particle i in the stack
299 TClonesArray &particles = *fParticles;
300 ((TParticle*) particles[i])->Print();
303 //_____________________________________________________________________________
304 void AliRun::DumpPStack ()
307 // Dumps the particle stack
309 TClonesArray &particles = *fParticles;
311 "\n\n=======================================================================\n");
312 for (Int_t i=0;i<fNtrack;i++)
314 printf("-> %d ",i); ((TParticle*) particles[i])->Print();
315 printf("--------------------------------------------------------------\n");
318 "\n=======================================================================\n\n");
321 //_____________________________________________________________________________
322 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
323 Float_t maxField, char* filename)
326 // Set magnetic field parameters
327 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
328 // version Magnetic field map version (only 1 active now)
329 // scale Scale factor for the magnetic field
330 // maxField Maximum value for the magnetic field
333 // --- Sanity check on mag field flags
334 if(type<0 || type > 2) {
336 "Invalid magnetic field flag: %5d; Helix tracking chosen instead\n"
340 if(fField) delete fField;
342 fField = new AliMagFC("Map1"," ",type,version,scale,maxField);
343 } else if(version<=3) {
344 fField = new AliMagFCM("Map2-3",filename,type,version,scale,maxField);
347 Warning("SetField","Invalid map %d\n",version);
351 //_____________________________________________________________________________
352 void AliRun::FillTree()
355 // Fills all AliRun TTrees
357 if (fTreeK) fTreeK->Fill();
358 if (fTreeH) fTreeH->Fill();
359 if (fTreeD) fTreeD->Fill();
360 if (fTreeR) fTreeR->Fill();
363 //_____________________________________________________________________________
364 void AliRun::FinishPrimary()
367 // Called at the end of each primary track
370 // This primary is finished, purify stack
371 gAlice->PurifyKine();
373 // Write out hits if any
374 if (gAlice->TreeH()) {
375 gAlice->TreeH()->Fill();
382 //_____________________________________________________________________________
383 void AliRun::FinishEvent()
386 // Called at the end of the event.
389 //Update the energy deposit tables
391 for(i=0;i<sEventEnergy.GetSize();i++) {
392 sSummEnergy[i]+=sEventEnergy[i];
393 sSum2Energy[i]+=sEventEnergy[i]*sEventEnergy[i];
395 sEventEnergy.Reset();
397 // Clean detector information
400 // Write out the kinematics
406 // Write out the digits
412 // Write out reconstructed clusters
417 // Write out the event Header information
418 if (fTreeE) fTreeE->Fill();
423 // Write Tree headers
424 // Int_t ievent = fHeader.GetEvent();
426 // sprintf(hname,"TreeK%d",ievent);
427 if (fTreeK) fTreeK->Write();
428 // sprintf(hname,"TreeH%d",ievent);
429 if (fTreeH) fTreeH->Write();
430 // sprintf(hname,"TreeD%d",ievent);
431 if (fTreeD) fTreeD->Write();
432 // sprintf(hname,"TreeR%d",ievent);
433 if (fTreeR) fTreeR->Write();
436 //_____________________________________________________________________________
437 void AliRun::FinishRun()
440 // Called at the end of the run.
443 // Clean detector information
444 TIter next(fModules);
446 while((detector = (AliModule*)next())) {
447 detector->FinishRun();
450 //Output energy summary tables
453 // file is retrieved from whatever tree
455 if (fTreeK) File = fTreeK->GetCurrentFile();
456 if ((!File) && (fTreeH)) File = fTreeH->GetCurrentFile();
457 if ((!File) && (fTreeD)) File = fTreeD->GetCurrentFile();
458 if ((!File) && (fTreeE)) File = fTreeE->GetCurrentFile();
460 Error("FinishRun","There isn't root file!");
466 // Clean tree information
467 delete fTreeK; fTreeK = 0;
468 delete fTreeH; fTreeH = 0;
469 delete fTreeD; fTreeD = 0;
470 delete fTreeR; fTreeR = 0;
471 delete fTreeE; fTreeE = 0;
473 // Write AliRun info and all detectors parameters
481 //_____________________________________________________________________________
482 void AliRun::FlagTrack(Int_t track)
485 // Flags a track and all its family tree to be kept
492 particle=(TParticle*)fParticles->UncheckedAt(curr);
494 // If the particle is flagged the three from here upward is saved already
495 if(particle->TestBit(Keep_Bit)) return;
497 // Save this particle
498 particle->SetBit(Keep_Bit);
500 // Move to father if any
501 if((curr=particle->GetFirstMother())==-1) return;
505 //_____________________________________________________________________________
506 void AliRun::EnergySummary()
509 // Print summary of deposited energy
515 Int_t kn, i, left, j, id;
516 const Float_t zero=0;
517 Int_t ievent=fHeader.GetEvent()+1;
519 // Energy loss information
521 printf("***************** Energy Loss Information per event (GEV) *****************\n");
522 for(kn=1;kn<sEventEnergy.GetSize();kn++) {
525 sEventEnergy[ndep]=kn;
530 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,zero))/ed;
533 sSummEnergy[ndep]=ed;
534 sSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,zero));
539 for(kn=0;kn<(ndep-1)/3+1;kn++) {
541 for(i=0;i<(3<left?3:left);i++) {
543 id=Int_t (sEventEnergy[j]+0.1);
544 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),sSummEnergy[j],sSum2Energy[j]);
549 // Relative energy loss in different detectors
550 printf("******************** Relative Energy Loss per event ********************\n");
551 printf("Total energy loss per event %10.3f GeV\n",edtot);
552 for(kn=0;kn<(ndep-1)/5+1;kn++) {
554 for(i=0;i<(5<left?5:left);i++) {
556 id=Int_t (sEventEnergy[j]+0.1);
557 printf(" %s %10.3f%%;",gMC->VolName(id),100*sSummEnergy[j]/edtot);
561 for(kn=0;kn<75;kn++) printf("*");
565 // Reset the TArray's
571 //_____________________________________________________________________________
572 AliModule *AliRun::GetModule(const char *name)
575 // Return pointer to detector from name
577 return (AliModule*)fModules->FindObject(name);
580 //_____________________________________________________________________________
581 AliDetector *AliRun::GetDetector(const char *name)
584 // Return pointer to detector from name
586 return (AliDetector*)fModules->FindObject(name);
589 //_____________________________________________________________________________
590 Int_t AliRun::GetModuleID(const char *name)
593 // Return galice internal detector identifier from name
596 TObject *mod=fModules->FindObject(name);
597 if(mod) i=fModules->IndexOf(mod);
601 //_____________________________________________________________________________
602 Int_t AliRun::GetEvent(Int_t event)
605 // Connect the Trees Kinematics and Hits for event # event
606 // Set branch addresses
609 // Reset existing structures
614 // Delete Trees already connected
615 if (fTreeK) delete fTreeK;
616 if (fTreeH) delete fTreeH;
617 if (fTreeD) delete fTreeD;
618 if (fTreeR) delete fTreeR;
620 // Get header from file
621 if(fTreeE) fTreeE->GetEntry(event);
622 else Error("GetEvent","Cannot file Header Tree\n");
624 // Get Kine Tree from file
626 sprintf(treeName,"TreeK%d",event);
627 fTreeK = (TTree*)gDirectory->Get(treeName);
628 if (fTreeK) fTreeK->SetBranchAddress("Particles", &fParticles);
629 else Error("GetEvent","cannot find Kine Tree for event:%d\n",event);
631 // Get Hits Tree header from file
632 sprintf(treeName,"TreeH%d",event);
633 fTreeH = (TTree*)gDirectory->Get(treeName);
635 Error("GetEvent","cannot find Hits Tree for event:%d\n",event);
638 // Get Digits Tree header from file
639 sprintf(treeName,"TreeD%d",event);
640 fTreeD = (TTree*)gDirectory->Get(treeName);
642 printf("WARNING: cannot find Digits Tree for event:%d\n",event);
646 // Get Reconstruct Tree header from file
647 sprintf(treeName,"TreeR%d",event);
648 fTreeR = (TTree*)gDirectory->Get(treeName);
650 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
653 // Set Trees branch addresses
654 TIter next(fModules);
656 while((detector = (AliModule*)next())) {
657 detector->SetTreeAddress();
660 if (fTreeK) fTreeK->GetEvent(0);
661 fNtrack = Int_t (fParticles->GetEntries());
665 //_____________________________________________________________________________
666 TGeometry *AliRun::GetGeometry()
669 // Import Alice geometry from current file
670 // Return pointer to geometry object
672 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
674 // Unlink and relink nodes in detectors
675 // This is bad and there must be a better way...
677 TList *tnodes=fGeometry->GetListOfNodes();
678 TNode *alice=(TNode*)tnodes->At(0);
679 TList *gnodes=alice->GetListOfNodes();
681 TIter next(fModules);
683 while((detector = (AliModule*)next())) {
684 detector->SetTreeAddress();
685 TList *dnodes=detector->Nodes();
688 for ( j=0; j<dnodes->GetSize(); j++) {
689 node = (TNode*) dnodes->At(j);
690 node1 = (TNode*) gnodes->FindObject(node->GetName());
691 dnodes->Remove(node);
692 dnodes->AddAt(node1,j);
698 //_____________________________________________________________________________
699 void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
700 Float_t &e, Float_t *vpos, Float_t *polar,
704 // Return next track from stack of particles
709 for(Int_t i=fNtrack-1; i>=0; i--) {
710 track=(TParticle*) fParticles->UncheckedAt(i);
711 if(!track->TestBit(Done_Bit)) {
713 // The track has not yet been processed
715 ipart=track->GetPdgCode();
723 pol = track->GetPolarisation();
728 track->SetBit(Done_Bit);
734 // stop and start timer when we start a primary track
735 Int_t nprimaries = fHeader.GetNprimary();
736 if (fCurrent >= nprimaries) return;
737 if (fCurrent < nprimaries-1) {
739 track=(TParticle*) fParticles->UncheckedAt(fCurrent+1);
740 // track->SetProcessTime(fTimer.CpuTime());
745 //_____________________________________________________________________________
746 Int_t AliRun::GetPrimary(Int_t track)
749 // return number of primary that has generated track
757 part = (TParticle *)fParticles->UncheckedAt(current);
758 parent=part->GetFirstMother();
759 if(parent<0) return current;
763 //_____________________________________________________________________________
764 void AliRun::Init(const char *setup)
767 // Initialize the Alice setup
770 gROOT->LoadMacro(setup);
771 gInterpreter->ProcessLine("Config();");
773 gMC->DefineParticles(); //Create standard MC particles
775 TObject *objfirst, *objlast;
777 fNdets = fModules->GetLast()+1;
780 //=================Create Materials, geometry, histograms, etc
781 TIter next(fModules);
783 while((detector = (AliModule*)next())) {
784 detector->SetTreeAddress();
785 objlast = gDirectory->GetList()->Last();
787 // Initialise detector materials, geometry, histograms,etc
788 detector->CreateMaterials();
789 detector->CreateGeometry();
790 detector->BuildGeometry();
793 // Add Detector histograms in Detector list of histograms
794 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
795 else objfirst = gDirectory->GetList()->First();
797 detector->Histograms()->Add(objfirst);
798 objfirst = gDirectory->GetList()->After(objfirst);
801 SetTransPar(); //Read the cuts for all materials
803 MediaTable(); //Build the special IMEDIA table
805 //Close the geometry structure
808 //Initialise geometry deposition table
809 sEventEnergy.Set(gMC->NofVolumes()+1);
810 sSummEnergy.Set(gMC->NofVolumes()+1);
811 sSum2Energy.Set(gMC->NofVolumes()+1);
813 //Create the color table
816 //Compute cross-sections
819 //Write Geometry object to current file.
825 //_____________________________________________________________________________
826 void AliRun::MediaTable()
829 // Built media table to get from the media number to
832 Int_t kz, nz, idt, lz, i, k, ind;
834 TObjArray &dets = *gAlice->Detectors();
838 for (kz=0;kz<fNdets;kz++) {
839 // If detector is defined
840 if((det=(AliModule*) dets[kz])) {
841 TArrayI &idtmed = *(det->GetIdtmed());
842 for(nz=0;nz<100;nz++) {
843 // Find max and min material number
844 if((idt=idtmed[nz])) {
845 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
846 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
849 if(det->LoMedium() > det->HiMedium()) {
853 if(det->HiMedium() > fImedia->GetSize()) {
854 Error("MediaTable","Increase fImedia from %d to %d",
855 fImedia->GetSize(),det->HiMedium());
858 // Tag all materials in rage as belonging to detector kz
859 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
866 // Print summary table
867 printf(" Traking media ranges:\n");
868 for(i=0;i<(fNdets-1)/6+1;i++) {
869 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
871 det=(AliModule*)dets[ind];
873 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
876 printf(" %6s: %3d -> %3d;","NULL",0,0);
882 //____________________________________________________________________________
883 void AliRun::SetGenerator(AliGenerator *generator)
886 // Load the event generator
888 if(!fGenerator) fGenerator = generator;
891 //____________________________________________________________________________
892 void AliRun::SetTransPar(char* filename)
895 // Read filename to set the transport parameters
899 const Int_t ncuts=10;
900 const Int_t nflags=11;
901 const Int_t npars=ncuts+nflags;
902 const char pars[npars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
903 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
904 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
905 "MULS","PAIR","PHOT","RAYL"};
911 Int_t i, itmed, iret, ktmed, kz;
914 // See whether the file is there
915 filtmp=gSystem->ExpandPathName(filename);
916 lun=fopen(filtmp,"r");
919 Warning("SetTransPar","File %s does not exist!\n",filename);
923 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
924 printf(" *%59s\n","*");
925 printf(" * Please check carefully what you are doing!%10s\n","*");
926 printf(" *%59s\n","*");
929 // Initialise cuts and flags
930 for(i=0;i<ncuts;i++) cut[i]=-99;
931 for(i=0;i<nflags;i++) flag[i]=-99;
933 for(i=0;i<256;i++) line[i]='\0';
934 // Read up to the end of line excluded
935 iret=fscanf(lun,"%[^\n]",line);
939 printf(" *%59s\n","*");
940 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
943 // Read the end of line
946 if(line[0]=='*') continue;
948 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",
949 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
950 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
951 &flag[8],&flag[9],&flag[10]);
955 Warning("SetTransPar","Error reading file %s\n",filename);
958 // Check that the module exist
959 AliModule *mod = GetModule(detName);
961 // Get the array of media numbers
962 TArrayI &idtmed = *mod->GetIdtmed();
963 // Check that the tracking medium code is valid
964 if(0<=itmed && itmed < 100) {
967 Warning("SetTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
970 // Set energy thresholds
971 for(kz=0;kz<ncuts;kz++) {
973 printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
974 pars[kz],cut[kz],itmed,mod->GetName());
975 gMC->Gstpar(ktmed,pars[kz],cut[kz]);
978 // Set transport mechanisms
979 for(kz=0;kz<nflags;kz++) {
981 printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
982 pars[ncuts+kz],flag[kz],itmed,mod->GetName());
983 gMC->Gstpar(ktmed,pars[ncuts+kz],Float_t(flag[kz]));
987 Warning("SetTransPar","Invalid medium code %d *\n",itmed);
991 Warning("SetTransPar","Module %s not present\n",detName);
997 //_____________________________________________________________________________
998 void AliRun::MakeTree(Option_t *option)
1001 // Create the ROOT trees
1002 // Loop on all detectors to create the Root branch (if any)
1007 char *K = strstr(option,"K");
1008 char *H = strstr(option,"H");
1009 char *E = strstr(option,"E");
1010 char *D = strstr(option,"D");
1011 char *R = strstr(option,"R");
1013 if (K && !fTreeK) fTreeK = new TTree("TreeK0","Kinematics");
1014 if (H && !fTreeH) fTreeH = new TTree("TreeH0","Hits");
1015 if (D && !fTreeD) fTreeD = new TTree("TreeD0","Digits");
1016 if (E && !fTreeE) fTreeE = new TTree("TE","Header");
1017 if (R && !fTreeR) fTreeR = new TTree("TreeR0","Reconstruction");
1018 if (fTreeH) fTreeH->SetAutoSave(1000000000); //no autosave
1020 // Create a branch for hits/digits for each detector
1021 // Each branch is a TClonesArray. Each data member of the Hits classes
1022 // will be in turn a subbranch of the detector master branch
1023 TIter next(fModules);
1024 AliModule *detector;
1025 while((detector = (AliModule*)next())) {
1026 if (H || D || R) detector->MakeBranch(option);
1028 // Create a branch for particles
1029 if (fTreeK && K) fTreeK->Branch("Particles",&fParticles,4000);
1031 // Create a branch for Header
1032 if (fTreeE && E) fTreeE->Branch("Header","AliHeader",&header,4000);
1035 //_____________________________________________________________________________
1036 Int_t AliRun::PurifyKine(Int_t lastSavedTrack, Int_t nofTracks)
1039 // PurifyKine with external parameters
1041 fHgwmk = lastSavedTrack;
1042 fNtrack = nofTracks;
1047 //_____________________________________________________________________________
1048 void AliRun::PurifyKine()
1051 // Compress kinematic tree keeping only flagged particles
1052 // and renaming the particle id's in all the hits
1054 TClonesArray &particles = *fParticles;
1055 int nkeep=fHgwmk+1, parent, i;
1056 TParticle *part, *partnew, *father;
1058 int *map = new int[particles.GetEntries()];
1060 // Save in Header total number of tracks before compression
1061 fHeader.SetNtrack(fHeader.GetNtrack()+fNtrack-fHgwmk);
1063 // Preset map, to be removed later
1064 for(i=0; i<fNtrack; i++) {
1065 if(i<=fHgwmk) map[i]=i ; else map[i] = -99 ;}
1066 // Second pass, build map between old and new numbering
1067 for(i=fHgwmk+1; i<fNtrack; i++) {
1068 part = (TParticle *)particles.UncheckedAt(i);
1069 if(part->TestBit(Keep_Bit)) {
1071 // This particle has to be kept
1075 // Old and new are different, have to copy
1076 partnew = (TParticle *)particles.UncheckedAt(nkeep);
1078 } else partnew = part;
1080 // as the parent is always *before*, it must be already
1081 // in place. This is what we are checking anyway!
1082 if((parent=partnew->GetFirstMother())>fHgwmk) {
1083 if(map[parent]==-99) printf("map[%d] = -99!\n",parent);
1084 partnew->SetFirstMother(map[parent]);
1091 // Fix daughters information
1092 for (i=fHgwmk+1; i<fNtrack; i++) {
1093 part = (TParticle *)particles.UncheckedAt(i);
1094 parent = part->GetFirstMother();
1095 father = (TParticle *)particles.UncheckedAt(parent);
1096 if(father->TestBit(Daughters_Bit)) {
1098 if(i<father->GetFirstDaughter()) father->SetFirstDaughter(i);
1099 if(i>father->GetLastDaughter()) father->SetLastDaughter(i);
1101 // Iitialise daughters info for first pass
1102 father->SetFirstDaughter(i);
1103 father->SetLastDaughter(i);
1104 father->SetBit(Daughters_Bit);
1108 // Now loop on all detectors and reset the hits
1109 TIter next(fModules);
1110 AliModule *detector;
1111 while((detector = (AliModule*)next())) {
1112 if (!detector->Hits()) continue;
1113 TClonesArray &vHits=*(detector->Hits());
1114 if(vHits.GetEntries() != detector->GetNhits())
1115 printf("vHits.GetEntries()!=detector->GetNhits(): %d != %d\n",
1116 vHits.GetEntries(),detector->GetNhits());
1117 for (i=0; i<detector->GetNhits(); i++) {
1118 OneHit = (AliHit *)vHits.UncheckedAt(i);
1119 OneHit->SetTrack(map[OneHit->GetTrack()]);
1124 particles.SetLast(fHgwmk);
1128 //_____________________________________________________________________________
1129 void AliRun::Reset(Int_t run, Int_t idevent)
1132 // Reset all Detectors & kinematics & trees
1140 // Initialise event header
1141 fHeader.Reset(run,idevent);
1145 sprintf(hname,"TreeK%d",idevent);
1146 fTreeK->SetName(hname);
1150 sprintf(hname,"TreeH%d",idevent);
1151 fTreeH->SetName(hname);
1155 sprintf(hname,"TreeD%d",idevent);
1156 fTreeD->SetName(hname);
1160 sprintf(hname,"TreeR%d",idevent);
1161 fTreeR->SetName(hname);
1165 //_____________________________________________________________________________
1166 void AliRun::ResetDigits()
1169 // Reset all Detectors digits
1171 TIter next(fModules);
1172 AliModule *detector;
1173 while((detector = (AliModule*)next())) {
1174 detector->ResetDigits();
1178 //_____________________________________________________________________________
1179 void AliRun::ResetHits()
1182 // Reset all Detectors hits
1184 TIter next(fModules);
1185 AliModule *detector;
1186 while((detector = (AliModule*)next())) {
1187 detector->ResetHits();
1191 //_____________________________________________________________________________
1192 void AliRun::ResetPoints()
1195 // Reset all Detectors points
1197 TIter next(fModules);
1198 AliModule *detector;
1199 while((detector = (AliModule*)next())) {
1200 detector->ResetPoints();
1204 //_____________________________________________________________________________
1205 void AliRun::Run(Int_t nevent, const char *setup)
1208 // Main function to be called to process a galice run
1210 // Root > gAlice.Run();
1211 // a positive number of events will cause the finish routine
1216 // check if initialisation has been done
1217 if (!fInitDone) Init(setup);
1219 // Create the Root Tree with one branch per detector
1221 gAlice->MakeTree("KHDER");
1224 todo = TMath::Abs(nevent);
1225 for (i=0; i<todo; i++) {
1226 // Process one run (one run = one event)
1227 gAlice->Reset(fRun, fEvent);
1231 gAlice->FinishEvent();
1235 // End of this run, close files
1236 if(nevent>0) gAlice->FinishRun();
1239 //_____________________________________________________________________________
1240 void AliRun::RunLego(const char *setup,Int_t ntheta,Float_t themin,
1241 Float_t themax,Int_t nphi,Float_t phimin,Float_t phimax,
1242 Float_t rmin,Float_t rmax,Float_t zmax)
1245 // Generates lego plots of:
1246 // - radiation length map phi vs theta
1247 // - radiation length map phi vs eta
1248 // - interaction length map
1249 // - g/cm2 length map
1251 // ntheta bins in theta, eta
1252 // themin minimum angle in theta (degrees)
1253 // themax maximum angle in theta (degrees)
1255 // phimin minimum angle in phi (degrees)
1256 // phimax maximum angle in phi (degrees)
1257 // rmin minimum radius
1258 // rmax maximum radius
1261 // The number of events generated = ntheta*nphi
1262 // run input parameters in macro setup (default="Config.C")
1264 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1267 <img src="picts/AliRunLego1.gif">
1272 <img src="picts/AliRunLego2.gif">
1277 <img src="picts/AliRunLego3.gif">
1282 // check if initialisation has been done
1283 if (!fInitDone) Init(setup);
1285 fLego = new AliLego("lego","lego");
1286 fLego->Init(ntheta,themin,themax,nphi,phimin,phimax,rmin,rmax,zmax);
1289 // Create only the Root event Tree
1290 gAlice->MakeTree("E");
1292 // End of this run, close files
1293 gAlice->FinishRun();
1296 //_____________________________________________________________________________
1297 void AliRun::SetCurrentTrack(Int_t track)
1300 // Set current track number
1305 //_____________________________________________________________________________
1306 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1307 Float_t *vpos, Float_t *polar, Float_t tof,
1308 const char *mecha, Int_t &ntr, Float_t weight)
1311 // Load a track on the stack
1313 // done 0 if the track has to be transported
1315 // parent identifier of the parent track. -1 for a primary
1316 // pdg particle code
1317 // pmom momentum GeV/c
1319 // polar polarisation
1320 // tof time of flight in seconds
1321 // mecha production mechanism
1322 // ntr on output the number of the track stored
1324 TClonesArray &particles = *fParticles;
1325 TParticle *particle;
1327 const Int_t firstdaughter=-1;
1328 const Int_t lastdaughter=-1;
1330 // const Float_t tlife=0;
1333 // Here we get the static mass
1334 // For MC is ok, but a more sophisticated method could be necessary
1335 // if the calculated mass is required
1336 // also, this method is potentially dangerous if the mass
1337 // used in the MC is not the same of the PDG database
1339 mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
1340 Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+
1341 pmom[1]*pmom[1]+pmom[2]*pmom[2]);
1343 //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",
1344 //pname,mass,e,fNtrack,pdg,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],KS,mecha);
1346 particle=new(particles[fNtrack]) TParticle(pdg,KS,parent,-1,firstdaughter,
1347 lastdaughter,pmom[0],pmom[1],pmom[2],
1348 e,vpos[0],vpos[1],vpos[2],tof);
1349 // polar[0],polar[1],polar[2],tof,
1351 ((TParticle*)particles[fNtrack])->SetPolarisation(TVector3(polar[0],polar[1],polar[2]));
1352 ((TParticle*)particles[fNtrack])->SetWeight(weight);
1353 if(!done) particle->SetBit(Done_Bit);
1356 particle=(TParticle*) fParticles->UncheckedAt(parent);
1357 particle->SetLastDaughter(fNtrack);
1358 if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack);
1361 // This is a primary track. Set high water mark for this event
1364 // Set also number if primary tracks
1365 fHeader.SetNprimary(fHgwmk+1);
1366 fHeader.SetNtrack(fHgwmk+1);
1371 //_____________________________________________________________________________
1372 void AliRun::KeepTrack(const Int_t track)
1375 // flags a track to be kept
1377 TClonesArray &particles = *fParticles;
1378 ((TParticle*)particles[track])->SetBit(Keep_Bit);
1381 //_____________________________________________________________________________
1382 void AliRun::StepManager(Int_t id) const
1385 // Called at every step during transport
1390 // --- If lego option, do it and leave
1392 fLego->StepManager();
1395 //Update energy deposition tables
1396 sEventEnergy[gMC->CurrentVolID(copy)]+=gMC->Edep();
1398 //Call the appropriate stepping routine;
1399 AliModule *det = (AliModule*)fModules->At(id);
1400 if(det) det->StepManager();
1403 //_____________________________________________________________________________
1404 void AliRun::ReadEuclid(const char* filnam, const AliModule *det, const char* topvol)
1407 // read in the geometry of the detector in euclid file format
1409 // id_det : the detector identification (2=its,...)
1410 // topvol : return parameter describing the name of the top
1411 // volume of geometry.
1413 // author : m. maire
1416 // several changes have been made by miroslav helbich
1417 // subroutine is rewrited to follow the new established way of memory
1418 // booking for tracking medias and rotation matrices.
1419 // all used tracking media have to be defined first, for this you can use
1420 // subroutine greutmed.
1421 // top volume is searched as only volume not positioned into another
1424 Int_t i, nvol, iret, itmed, irot, numed, npar, ndiv, iaxe;
1425 Int_t ndvmx, nr, flag;
1426 char key[5], card[77], natmed[21];
1427 char name[5], mother[5], shape[5], konly[5], volst[7000][5];
1430 Float_t teta1, phi1, teta2, phi2, teta3, phi3, orig, step;
1432 Int_t idrot[5000],istop[7000];
1435 // *** The input filnam name will be with extension '.euc'
1436 filtmp=gSystem->ExpandPathName(filnam);
1437 lun=fopen(filtmp,"r");
1440 printf(" *** GREUCL *** Could not open file %s\n",filnam);
1443 //* --- definition of rotation matrix 0 ---
1444 TArrayI &idtmed = *(det->GetIdtmed());
1448 for(i=0;i<77;i++) card[i]=0;
1449 iret=fscanf(lun,"%77[^\n]",card);
1450 if(iret<=0) goto L20;
1453 strncpy(key,card,4);
1455 if (!strcmp(key,"TMED")) {
1456 sscanf(&card[5],"%d '%[^']'",&itmed,natmed);
1457 //Pad the string with blanks
1460 while(i<20) natmed[i++]=' ';
1463 gMC->Gckmat(idtmed[itmed],natmed);
1465 } else if (!strcmp(key,"ROTM")) {
1466 sscanf(&card[4],"%d %f %f %f %f %f %f",&irot,&teta1,&phi1,&teta2,&phi2,&teta3,&phi3);
1467 det->AliMatrix(idrot[irot],teta1,phi1,teta2,phi2,teta3,phi3);
1469 } else if (!strcmp(key,"VOLU")) {
1470 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, shape, &numed, &npar);
1472 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
1475 gMC->Gsvolu( name, shape, idtmed[numed], par, npar);
1476 //* save the defined volumes
1477 strcpy(volst[++nvol],name);
1480 } else if (!strcmp(key,"DIVN")) {
1481 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, mother, &ndiv, &iaxe);
1482 gMC->Gsdvn ( name, mother, ndiv, iaxe );
1484 } else if (!strcmp(key,"DVN2")) {
1485 sscanf(&card[5],"'%[^']' '%[^']' %d %d %f %d",name, mother, &ndiv, &iaxe, &orig, &numed);
1486 gMC->Gsdvn2( name, mother, ndiv, iaxe, orig,idtmed[numed]);
1488 } else if (!strcmp(key,"DIVT")) {
1489 sscanf(&card[5],"'%[^']' '%[^']' %f %d %d %d", name, mother, &step, &iaxe, &numed, &ndvmx);
1490 gMC->Gsdvt ( name, mother, step, iaxe, idtmed[numed], ndvmx);
1492 } else if (!strcmp(key,"DVT2")) {
1493 sscanf(&card[5],"'%[^']' '%[^']' %f %d %f %d %d", name, mother, &step, &iaxe, &orig, &numed, &ndvmx);
1494 gMC->Gsdvt2 ( name, mother, step, iaxe, orig, idtmed[numed], ndvmx );
1496 } else if (!strcmp(key,"POSI")) {
1497 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']'", name, &nr, mother, &xo, &yo, &zo, &irot, konly);
1498 //*** volume name cannot be the top volume
1499 for(i=1;i<=nvol;i++) {
1500 if (!strcmp(volst[i],name)) istop[i]=0;
1503 gMC->Gspos ( name, nr, mother, xo, yo, zo, idrot[irot], konly );
1505 } else if (!strcmp(key,"POSP")) {
1506 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']' %d", name, &nr, mother, &xo, &yo, &zo, &irot, konly, &npar);
1508 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
1511 //*** volume name cannot be the top volume
1512 for(i=1;i<=nvol;i++) {
1513 if (!strcmp(volst[i],name)) istop[i]=0;
1516 gMC->Gsposp ( name, nr, mother, xo,yo,zo, idrot[irot], konly, par, npar);
1519 if (strcmp(key,"END")) goto L10;
1520 //* find top volume in the geometry
1522 for(i=1;i<=nvol;i++) {
1523 if (istop[i] && flag) {
1524 printf(" *** GREUCL *** warning: %s is another possible top volume\n",volst[i]);
1526 if (istop[i] && !flag) {
1528 printf(" *** GREUCL *** volume %s taken as a top volume\n",topvol);
1533 printf("*** GREUCL *** warning: top volume not found\n");
1537 //* commented out only for the not cernlib version
1538 printf(" *** GREUCL *** file: %s is now read in\n",filnam);
1543 printf(" *** GREUCL *** reading error or premature end of file\n");
1546 //_____________________________________________________________________________
1547 void AliRun::ReadEuclidMedia(const char* filnam, const AliModule *det)
1550 // read in the materials and tracking media for the detector
1551 // in euclid file format
1553 // filnam: name of the input file
1554 // id_det: id_det is the detector identification (2=its,...)
1556 // author : miroslav helbich
1558 Float_t sxmgmx = gAlice->Field()->Max();
1559 Int_t isxfld = gAlice->Field()->Integ();
1560 Int_t end, i, iret, itmed;
1561 char key[5], card[130], natmed[21], namate[21];
1566 Int_t nwbuf, isvol, ifield, nmat;
1567 Float_t a, z, dens, radl, absl, fieldm, tmaxfd, stemax, deemax, epsil, stmin;
1570 for(i=0;i<end;i++) if(filnam[i]=='.') {
1575 // *** The input filnam name will be with extension '.euc'
1576 printf("The file name is %s\n",filnam); //Debug
1577 filtmp=gSystem->ExpandPathName(filnam);
1578 lun=fopen(filtmp,"r");
1581 Warning("ReadEuclidMedia","Could not open file %s\n",filnam);
1585 // Retrieve Mag Field parameters
1586 Int_t ISXFLD=gAlice->Field()->Integ();
1587 Float_t SXMGMX=gAlice->Field()->Max();
1588 // TArrayI &idtmed = *(det->GetIdtmed());
1591 for(i=0;i<130;i++) card[i]=0;
1592 iret=fscanf(lun,"%4s %[^\n]",key,card);
1593 if(iret<=0) goto L20;
1597 if (!strcmp(key,"MATE")) {
1598 sscanf(card,"%d '%[^']' %f %f %f %f %f %d",&imate,namate,&a,&z,&dens,&radl,&absl,&nwbuf);
1599 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
1600 //Pad the string with blanks
1603 while(i<20) namate[i++]=' ';
1606 det->AliMaterial(imate,namate,a,z,dens,radl,absl,ubuf,nwbuf);
1607 //* read tracking medium
1608 } else if (!strcmp(key,"TMED")) {
1609 sscanf(card,"%d '%[^']' %d %d %d %f %f %f %f %f %f %d",
1610 &itmed,natmed,&nmat,&isvol,&ifield,&fieldm,&tmaxfd,
1611 &stemax,&deemax,&epsil,&stmin,&nwbuf);
1612 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
1613 if (ifield<0) ifield=isxfld;
1614 if (fieldm<0) fieldm=sxmgmx;
1615 //Pad the string with blanks
1618 while(i<20) natmed[i++]=' ';
1621 det->AliMedium(itmed,natmed,nmat,isvol,ISXFLD,SXMGMX,tmaxfd,
1622 stemax,deemax,epsil,stmin,ubuf,nwbuf);
1623 // (*fImedia)[idtmed[itmed]-1]=id_det;
1627 if (strcmp(key,"END")) goto L10;
1630 //* commented out only for the not cernlib version
1631 Warning("ReadEuclidMedia","file: %s is now read in\n",filnam);
1636 Warning("ReadEuclidMedia","reading error or premature end of file\n");
1639 //_____________________________________________________________________________
1640 void AliRun::Streamer(TBuffer &R__b)
1643 // Stream an object of class AliRun.
1645 if (R__b.IsReading()) {
1646 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1647 TNamed::Streamer(R__b);
1648 if (!gAlice) gAlice = this;
1649 gROOT->GetListOfBrowsables()->Add(this,"Run");
1650 fTreeE = (TTree*)gDirectory->Get("TE");
1651 if (fTreeE) fTreeE->SetBranchAddress("Header", &header);
1652 else Error("Streamer","cannot find Header Tree\n");
1656 fHeader.Streamer(R__b);
1666 R__b >> fPDGDB; //Particle factory object!
1667 fTreeE->GetEntry(0);
1669 fHeader.SetEvent(0);
1670 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
1673 R__b.WriteVersion(AliRun::IsA());
1674 TNamed::Streamer(R__b);
1678 fHeader.Streamer(R__b);
1687 R__b << fPDGDB; //Particle factory object!
1692 //_____________________________________________________________________________
1694 // Interfaces to Fortran
1696 //_____________________________________________________________________________
1698 extern "C" void type_of_call rxgtrak (Int_t &mtrack, Int_t &ipart, Float_t *pmom,
1699 Float_t &e, Float_t *vpos, Float_t *polar,
1703 // Fetches next track from the ROOT stack for transport. Called by the
1704 // modified version of GTREVE.
1706 // Track number in the ROOT stack. If MTRACK=0 no
1707 // mtrack more tracks are left in the stack to be
1709 // ipart Particle code in the GEANT conventions.
1710 // pmom[3] Particle momentum in GeV/c
1711 // e Particle energy in GeV
1712 // vpos[3] Particle position
1713 // tof Particle time of flight in seconds
1716 gAlice->GetNextTrack(mtrack, pdg, pmom, e, vpos, polar, tof);
1717 ipart = gMC->IdFromPDG(pdg);
1721 //_____________________________________________________________________________
1722 extern "C" void type_of_call
1724 rxstrak (Int_t &keep, Int_t &parent, Int_t &ipart, Float_t *pmom,
1725 Float_t *vpos, Float_t &tof, const char* cmech, Int_t &ntr, const int cmlen)
1727 rxstrak (Int_t &keep, Int_t &parent, Int_t &ipart, Float_t *pmom,
1728 Float_t *vpos, Float_t &tof, const char* cmech, const int cmlen,
1733 // Fetches next track from the ROOT stack for transport. Called by GUKINE
1736 // Status of the track. If keep=0 the track is put
1737 // keep on the ROOT stack but it is not fetched for
1739 // parent Parent track. If parent=0 the track is a primary.
1740 // In GUSTEP the routine is normally called to store
1741 // secondaries generated by the current track whose
1742 // ROOT stack number is MTRACK (common SCKINE.
1743 // ipart Particle code in the GEANT conventions.
1744 // pmom[3] Particle momentum in GeV/c
1745 // vpos[3] Particle position
1746 // tof Particle time of flight in seconds
1748 // cmech (CHARACTER*10) Particle origin. This field is user
1749 // defined and it is not used inside the GALICE code.
1750 // ntr Number assigned to the particle in the ROOT stack.
1753 Float_t polar[3]={0.,0.,0.};
1754 for(int i=0; i<10 && i<cmlen; i++) mecha[i]=cmech[i];
1756 Int_t pdg=gMC->PDGFromId(ipart);
1757 gAlice->SetTrack(keep, parent-1, pdg, pmom, vpos, polar, tof, mecha, ntr);
1761 //_____________________________________________________________________________
1762 extern "C" void type_of_call rxkeep(const Int_t &n)
1764 if( NULL==gAlice ) exit(1);
1766 if( n<=0 || n>gAlice->Particles()->GetEntries() )
1768 printf(" Bad index n=%d must be 0<n<=%d\n",
1769 n,gAlice->Particles()->GetEntries());
1773 ((TParticle*)(gAlice->Particles()->UncheckedAt(n-1)))->SetBit(Keep_Bit);
1776 //_____________________________________________________________________________
1777 extern "C" void type_of_call rxouth ()
1780 // Called by Gtreve at the end of each primary track
1782 gAlice->FinishPrimary();