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 **************************************************************************/
20 ///////////////////////////////////////////////////////////////////////////////
22 // Control class for Alice C++ //
23 // Only one single instance of this class exists. //
24 // The object is created in main program aliroot //
25 // and is pointed by the global gAlice. //
27 // -Supports the list of all Alice Detectors (fModules). //
28 // -Supports the list of particles (fParticles). //
29 // -Supports the Trees. //
30 // -Supports the geometry. //
31 // -Supports the event display. //
34 <img src="picts/AliRunClass.gif">
39 <img src="picts/alirun.gif">
43 ///////////////////////////////////////////////////////////////////////////////
51 #include <TObjectTable.h>
53 #include "TParticle.h"
55 #include "AliDisplay.h"
57 #include "AliCallf77.h"
65 static AliHeader *header;
69 # define rxgtrak rxgtrak_
70 # define rxstrak rxstrak_
71 # define rxkeep rxkeep_
72 # define rxouth rxouth_
75 # define rxgtrak RXGTRAK
76 # define rxstrak RXSTRAK
77 # define rxkeep RXKEEP
78 # define rxouth RXOUTH
81 static TArrayF sEventEnergy;
82 static TArrayF sSummEnergy;
83 static TArrayF sSum2Energy;
87 //_____________________________________________________________________________
91 // Default constructor for AliRun
115 fPDGDB = 0; //Particle factory object!
118 //_____________________________________________________________________________
119 AliRun::AliRun(const char *name, const char *title)
123 // Constructor for the main processor.
124 // Creates the geometry
125 // Creates the list of Detectors.
126 // Creates the list of particles.
143 gROOT->GetListOfBrowsables()->Add(this,name);
145 // create the support list for the various Detectors
146 fModules = new TObjArray(77);
148 // Create the TNode geometry for the event display
150 BuildSimpleGeometry();
160 // Create the particle stack
161 fParticles = new TClonesArray("TParticle",100);
165 // Create default mag field
170 // Prepare the tracking medium lists
171 fImedia = new TArrayI(1000);
172 for(i=0;i<1000;i++) (*fImedia)[i]=-99;
175 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
178 //_____________________________________________________________________________
182 // Defaullt AliRun destructor
201 fParticles->Delete();
206 //_____________________________________________________________________________
207 void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
210 // Add a hit to detector id
212 TObjArray &dets = *fModules;
213 if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits);
216 //_____________________________________________________________________________
217 void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
220 // Add digit to detector id
222 TObjArray &dets = *fModules;
223 if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits);
226 //_____________________________________________________________________________
227 void AliRun::Browse(TBrowser *b)
230 // Called when the item "Run" is clicked on the left pane
231 // of the Root browser.
232 // It displays the Root Trees and all detectors.
234 if (fTreeK) b->Add(fTreeK,fTreeK->GetName());
235 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
236 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
237 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
238 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
240 TIter next(fModules);
242 while((detector = (AliModule*)next())) {
243 b->Add(detector,detector->GetName());
247 //_____________________________________________________________________________
251 // Initialize Alice geometry
256 //_____________________________________________________________________________
257 void AliRun::BuildSimpleGeometry()
260 // Create a simple TNode geometry used by Root display engine
262 // Initialise geometry
264 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
265 new TMaterial("void","Vacuum",0,0,0); //Everything is void
266 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
267 brik->SetVisibility(0);
268 new TNode("alice","alice","S_alice");
271 //_____________________________________________________________________________
272 void AliRun::CleanDetectors()
275 // Clean Detectors at the end of event
277 TIter next(fModules);
279 while((detector = (AliModule*)next())) {
280 detector->FinishEvent();
284 //_____________________________________________________________________________
285 void AliRun::CleanParents()
288 // Clean Particles stack.
289 // Set parent/daughter relations
291 TClonesArray &particles = *(gAlice->Particles());
294 for(i=0; i<fNtrack; i++) {
295 part = (TParticle *)particles.UncheckedAt(i);
296 if(!part->TestBit(Daughters_Bit)) {
297 part->SetFirstDaughter(-1);
298 part->SetLastDaughter(-1);
303 //_____________________________________________________________________________
304 Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
307 // Return the distance from the mouse to the AliRun object
313 //_____________________________________________________________________________
314 void AliRun::DumpPart (Int_t i)
317 // Dumps particle i in the stack
319 TClonesArray &particles = *fParticles;
320 ((TParticle*) particles[i])->Print();
323 //_____________________________________________________________________________
324 void AliRun::DumpPStack ()
327 // Dumps the particle stack
329 TClonesArray &particles = *fParticles;
331 "\n\n=======================================================================\n");
332 for (Int_t i=0;i<fNtrack;i++)
334 printf("-> %d ",i); ((TParticle*) particles[i])->Print();
335 printf("--------------------------------------------------------------\n");
338 "\n=======================================================================\n\n");
341 //_____________________________________________________________________________
342 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
343 Float_t maxField, char* filename)
346 // Set magnetic field parameters
347 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
348 // version Magnetic field map version (only 1 active now)
349 // scale Scale factor for the magnetic field
350 // maxField Maximum value for the magnetic field
353 // --- Sanity check on mag field flags
354 if(type<0 || type > 2) {
356 "Invalid magnetic field flag: %5d; Helix tracking chosen instead\n"
360 if(fField) delete fField;
362 fField = new AliMagFC("Map1"," ",type,version,scale,maxField);
363 } else if(version<=3) {
364 fField = new AliMagFCM("Map2-3",filename,type,version,scale,maxField);
367 Warning("SetField","Invalid map %d\n",version);
371 //_____________________________________________________________________________
372 void AliRun::FillTree()
375 // Fills all AliRun TTrees
377 if (fTreeK) fTreeK->Fill();
378 if (fTreeH) fTreeH->Fill();
379 if (fTreeD) fTreeD->Fill();
380 if (fTreeR) fTreeR->Fill();
383 //_____________________________________________________________________________
384 void AliRun::FinishPrimary()
387 // Called at the end of each primary track
390 // static Int_t count=0;
391 // const Int_t times=10;
392 // This primary is finished, purify stack
393 gAlice->PurifyKine();
395 // Write out hits if any
396 if (gAlice->TreeH()) {
397 gAlice->TreeH()->Fill();
404 // if(++count%times==1) gObjectTable->Print();
407 //_____________________________________________________________________________
408 void AliRun::FinishEvent()
411 // Called at the end of the event.
414 //Update the energy deposit tables
416 for(i=0;i<sEventEnergy.GetSize();i++) {
417 sSummEnergy[i]+=sEventEnergy[i];
418 sSum2Energy[i]+=sEventEnergy[i]*sEventEnergy[i];
420 sEventEnergy.Reset();
422 // Clean detector information
425 // Write out the kinematics
431 // Write out the digits
437 // Write out reconstructed clusters
442 // Write out the event Header information
443 if (fTreeE) fTreeE->Fill();
448 // Write Tree headers
449 // Int_t ievent = fHeader.GetEvent();
451 // sprintf(hname,"TreeK%d",ievent);
452 if (fTreeK) fTreeK->Write();
453 // sprintf(hname,"TreeH%d",ievent);
454 if (fTreeH) fTreeH->Write();
455 // sprintf(hname,"TreeD%d",ievent);
456 if (fTreeD) fTreeD->Write();
457 // sprintf(hname,"TreeR%d",ievent);
458 if (fTreeR) fTreeR->Write();
461 //_____________________________________________________________________________
462 void AliRun::FinishRun()
465 // Called at the end of the run.
468 // Clean detector information
469 TIter next(fModules);
471 while((detector = (AliModule*)next())) {
472 detector->FinishRun();
475 //Output energy summary tables
478 // file is retrieved from whatever tree
480 if (fTreeK) File = fTreeK->GetCurrentFile();
481 if ((!File) && (fTreeH)) File = fTreeH->GetCurrentFile();
482 if ((!File) && (fTreeD)) File = fTreeD->GetCurrentFile();
483 if ((!File) && (fTreeE)) File = fTreeE->GetCurrentFile();
485 Error("FinishRun","There isn't root file!");
491 // Clean tree information
492 delete fTreeK; fTreeK = 0;
493 delete fTreeH; fTreeH = 0;
494 delete fTreeD; fTreeD = 0;
495 delete fTreeR; fTreeR = 0;
496 delete fTreeE; fTreeE = 0;
498 // Write AliRun info and all detectors parameters
506 //_____________________________________________________________________________
507 void AliRun::FlagTrack(Int_t track)
510 // Flags a track and all its family tree to be kept
517 particle=(TParticle*)fParticles->UncheckedAt(curr);
519 // If the particle is flagged the three from here upward is saved already
520 if(particle->TestBit(Keep_Bit)) return;
522 // Save this particle
523 particle->SetBit(Keep_Bit);
525 // Move to father if any
526 if((curr=particle->GetFirstMother())==-1) return;
530 //_____________________________________________________________________________
531 void AliRun::EnergySummary()
534 // Print summary of deposited energy
540 Int_t kn, i, left, j, id;
541 const Float_t zero=0;
542 Int_t ievent=fHeader.GetEvent()+1;
544 // Energy loss information
546 printf("***************** Energy Loss Information per event (GEV) *****************\n");
547 for(kn=1;kn<sEventEnergy.GetSize();kn++) {
550 sEventEnergy[ndep]=kn;
555 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,zero))/ed;
558 sSummEnergy[ndep]=ed;
559 sSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,zero));
564 for(kn=0;kn<(ndep-1)/3+1;kn++) {
566 for(i=0;i<(3<left?3:left);i++) {
568 id=Int_t (sEventEnergy[j]+0.1);
569 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),sSummEnergy[j],sSum2Energy[j]);
574 // Relative energy loss in different detectors
575 printf("******************** Relative Energy Loss per event ********************\n");
576 printf("Total energy loss per event %10.3f GeV\n",edtot);
577 for(kn=0;kn<(ndep-1)/5+1;kn++) {
579 for(i=0;i<(5<left?5:left);i++) {
581 id=Int_t (sEventEnergy[j]+0.1);
582 printf(" %s %10.3f%%;",gMC->VolName(id),100*sSummEnergy[j]/edtot);
586 for(kn=0;kn<75;kn++) printf("*");
590 // Reset the TArray's
596 //_____________________________________________________________________________
597 AliModule *AliRun::GetModule(const char *name)
600 // Return pointer to detector from name
602 return (AliModule*)fModules->FindObject(name);
605 //_____________________________________________________________________________
606 AliDetector *AliRun::GetDetector(const char *name)
609 // Return pointer to detector from name
611 return (AliDetector*)fModules->FindObject(name);
614 //_____________________________________________________________________________
615 Int_t AliRun::GetModuleID(const char *name)
618 // Return galice internal detector identifier from name
621 TObject *mod=fModules->FindObject(name);
622 if(mod) i=fModules->IndexOf(mod);
626 //_____________________________________________________________________________
627 Int_t AliRun::GetEvent(Int_t event)
630 // Connect the Trees Kinematics and Hits for event # event
631 // Set branch addresses
634 // Reset existing structures
639 // Delete Trees already connected
640 if (fTreeK) delete fTreeK;
641 if (fTreeH) delete fTreeH;
642 if (fTreeD) delete fTreeD;
643 if (fTreeR) delete fTreeR;
645 // Get header from file
646 if(fTreeE) fTreeE->GetEntry(event);
647 else Error("GetEvent","Cannot file Header Tree\n");
649 // Get Kine Tree from file
651 sprintf(treeName,"TreeK%d",event);
652 fTreeK = (TTree*)gDirectory->Get(treeName);
653 if (fTreeK) fTreeK->SetBranchAddress("Particles", &fParticles);
654 else Error("GetEvent","cannot find Kine Tree for event:%d\n",event);
656 // Get Hits Tree header from file
657 sprintf(treeName,"TreeH%d",event);
658 fTreeH = (TTree*)gDirectory->Get(treeName);
660 Error("GetEvent","cannot find Hits Tree for event:%d\n",event);
663 // Get Digits Tree header from file
664 sprintf(treeName,"TreeD%d",event);
665 fTreeD = (TTree*)gDirectory->Get(treeName);
667 Warning("GetEvent","cannot find Digits Tree for event:%d\n",event);
671 // Get Reconstruct Tree header from file
672 sprintf(treeName,"TreeR%d",event);
673 fTreeR = (TTree*)gDirectory->Get(treeName);
675 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
678 // Set Trees branch addresses
679 TIter next(fModules);
681 while((detector = (AliModule*)next())) {
682 detector->SetTreeAddress();
685 if (fTreeK) fTreeK->GetEvent(0);
686 fNtrack = Int_t (fParticles->GetEntries());
690 //_____________________________________________________________________________
691 TGeometry *AliRun::GetGeometry()
694 // Import Alice geometry from current file
695 // Return pointer to geometry object
697 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
699 // Unlink and relink nodes in detectors
700 // This is bad and there must be a better way...
703 TIter next(fModules);
705 while((detector = (AliModule*)next())) {
706 detector->SetTreeAddress();
707 TList *dnodes=detector->Nodes();
710 for ( j=0; j<dnodes->GetSize(); j++) {
711 node = (TNode*) dnodes->At(j);
712 node1 = fGeometry->GetNode(node->GetName());
713 dnodes->Remove(node);
714 dnodes->AddAt(node1,j);
720 //_____________________________________________________________________________
721 void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
722 Float_t &e, Float_t *vpos, Float_t *polar,
726 // Return next track from stack of particles
731 for(Int_t i=fNtrack-1; i>=0; i--) {
732 track=(TParticle*) fParticles->UncheckedAt(i);
733 if(!track->TestBit(Done_Bit)) {
735 // The track has not yet been processed
737 ipart=track->GetPdgCode();
745 track->GetPolarisation(pol);
750 track->SetBit(Done_Bit);
756 // stop and start timer when we start a primary track
757 Int_t nprimaries = fHeader.GetNprimary();
758 if (fCurrent >= nprimaries) return;
759 if (fCurrent < nprimaries-1) {
761 track=(TParticle*) fParticles->UncheckedAt(fCurrent+1);
762 // track->SetProcessTime(fTimer.CpuTime());
767 //_____________________________________________________________________________
768 Int_t AliRun::GetPrimary(Int_t track)
771 // return number of primary that has generated track
779 part = (TParticle *)fParticles->UncheckedAt(current);
780 parent=part->GetFirstMother();
781 if(parent<0) return current;
785 //_____________________________________________________________________________
786 void AliRun::Init(const char *setup)
789 // Initialize the Alice setup
792 gROOT->LoadMacro(setup);
793 gInterpreter->ProcessLine("Config();");
795 gMC->DefineParticles(); //Create standard MC particles
797 TObject *objfirst, *objlast;
799 fNdets = fModules->GetLast()+1;
802 //=================Create Materials, geometry, histograms, etc
803 TIter next(fModules);
805 while((detector = (AliModule*)next())) {
806 detector->SetTreeAddress();
807 objlast = gDirectory->GetList()->Last();
809 // Initialise detector materials, geometry, histograms,etc
810 detector->CreateMaterials();
811 detector->CreateGeometry();
812 detector->BuildGeometry();
815 // Add Detector histograms in Detector list of histograms
816 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
817 else objfirst = gDirectory->GetList()->First();
819 detector->Histograms()->Add(objfirst);
820 objfirst = gDirectory->GetList()->After(objfirst);
823 SetTransPar(); //Read the cuts for all materials
825 MediaTable(); //Build the special IMEDIA table
827 //Close the geometry structure
830 //Initialise geometry deposition table
831 sEventEnergy.Set(gMC->NofVolumes()+1);
832 sSummEnergy.Set(gMC->NofVolumes()+1);
833 sSum2Energy.Set(gMC->NofVolumes()+1);
835 //Create the color table
838 //Compute cross-sections
841 //Write Geometry object to current file.
847 //_____________________________________________________________________________
848 void AliRun::MediaTable()
851 // Built media table to get from the media number to
854 Int_t kz, nz, idt, lz, i, k, ind;
856 TObjArray &dets = *gAlice->Detectors();
860 for (kz=0;kz<fNdets;kz++) {
861 // If detector is defined
862 if((det=(AliModule*) dets[kz])) {
863 TArrayI &idtmed = *(det->GetIdtmed());
864 for(nz=0;nz<100;nz++) {
865 // Find max and min material number
866 if((idt=idtmed[nz])) {
867 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
868 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
871 if(det->LoMedium() > det->HiMedium()) {
875 if(det->HiMedium() > fImedia->GetSize()) {
876 Error("MediaTable","Increase fImedia from %d to %d",
877 fImedia->GetSize(),det->HiMedium());
880 // Tag all materials in rage as belonging to detector kz
881 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
888 // Print summary table
889 printf(" Traking media ranges:\n");
890 for(i=0;i<(fNdets-1)/6+1;i++) {
891 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
893 det=(AliModule*)dets[ind];
895 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
898 printf(" %6s: %3d -> %3d;","NULL",0,0);
904 //____________________________________________________________________________
905 void AliRun::SetGenerator(AliGenerator *generator)
908 // Load the event generator
910 if(!fGenerator) fGenerator = generator;
913 //____________________________________________________________________________
914 void AliRun::SetTransPar(char* filename)
917 // Read filename to set the transport parameters
921 const Int_t ncuts=10;
922 const Int_t nflags=11;
923 const Int_t npars=ncuts+nflags;
924 const char pars[npars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
925 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
926 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
927 "MULS","PAIR","PHOT","RAYL"};
933 Int_t i, itmed, iret, ktmed, kz;
936 // See whether the file is there
937 filtmp=gSystem->ExpandPathName(filename);
938 lun=fopen(filtmp,"r");
941 Warning("SetTransPar","File %s does not exist!\n",filename);
945 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
946 printf(" *%59s\n","*");
947 printf(" * Please check carefully what you are doing!%10s\n","*");
948 printf(" *%59s\n","*");
951 // Initialise cuts and flags
952 for(i=0;i<ncuts;i++) cut[i]=-99;
953 for(i=0;i<nflags;i++) flag[i]=-99;
955 for(i=0;i<256;i++) line[i]='\0';
956 // Read up to the end of line excluded
957 iret=fscanf(lun,"%[^\n]",line);
961 printf(" *%59s\n","*");
962 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
965 // Read the end of line
968 if(line[0]=='*') continue;
970 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",
971 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
972 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
973 &flag[8],&flag[9],&flag[10]);
977 Warning("SetTransPar","Error reading file %s\n",filename);
980 // Check that the module exist
981 AliModule *mod = GetModule(detName);
983 // Get the array of media numbers
984 TArrayI &idtmed = *mod->GetIdtmed();
985 // Check that the tracking medium code is valid
986 if(0<=itmed && itmed < 100) {
989 Warning("SetTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
992 // Set energy thresholds
993 for(kz=0;kz<ncuts;kz++) {
995 printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
996 pars[kz],cut[kz],itmed,mod->GetName());
997 gMC->Gstpar(ktmed,pars[kz],cut[kz]);
1000 // Set transport mechanisms
1001 for(kz=0;kz<nflags;kz++) {
1003 printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
1004 pars[ncuts+kz],flag[kz],itmed,mod->GetName());
1005 gMC->Gstpar(ktmed,pars[ncuts+kz],Float_t(flag[kz]));
1009 Warning("SetTransPar","Invalid medium code %d *\n",itmed);
1013 Warning("SetTransPar","Module %s not present\n",detName);
1019 //_____________________________________________________________________________
1020 void AliRun::MakeTree(Option_t *option)
1023 // Create the ROOT trees
1024 // Loop on all detectors to create the Root branch (if any)
1029 char *K = strstr(option,"K");
1030 char *H = strstr(option,"H");
1031 char *E = strstr(option,"E");
1032 char *D = strstr(option,"D");
1033 char *R = strstr(option,"R");
1035 if (K && !fTreeK) fTreeK = new TTree("TreeK0","Kinematics");
1036 if (H && !fTreeH) fTreeH = new TTree("TreeH0","Hits");
1037 if (D && !fTreeD) fTreeD = new TTree("TreeD0","Digits");
1038 if (E && !fTreeE) fTreeE = new TTree("TE","Header");
1039 if (R && !fTreeR) fTreeR = new TTree("TreeR0","Reconstruction");
1040 if (fTreeH) fTreeH->SetAutoSave(1000000000); //no autosave
1042 // Create a branch for hits/digits for each detector
1043 // Each branch is a TClonesArray. Each data member of the Hits classes
1044 // will be in turn a subbranch of the detector master branch
1045 TIter next(fModules);
1046 AliModule *detector;
1047 while((detector = (AliModule*)next())) {
1048 if (H || D || R) detector->MakeBranch(option);
1050 // Create a branch for particles
1051 if (fTreeK && K) fTreeK->Branch("Particles",&fParticles,4000);
1053 // Create a branch for Header
1054 if (fTreeE && E) fTreeE->Branch("Header","AliHeader",&header,4000);
1057 //_____________________________________________________________________________
1058 Int_t AliRun::PurifyKine(Int_t lastSavedTrack, Int_t nofTracks)
1061 // PurifyKine with external parameters
1063 fHgwmk = lastSavedTrack;
1064 fNtrack = nofTracks;
1069 //_____________________________________________________________________________
1070 void AliRun::PurifyKine()
1073 // Compress kinematic tree keeping only flagged particles
1074 // and renaming the particle id's in all the hits
1076 TClonesArray &particles = *fParticles;
1077 int nkeep=fHgwmk+1, parent, i;
1078 TParticle *part, *partnew, *father;
1080 int *map = new int[particles.GetEntries()];
1082 // Save in Header total number of tracks before compression
1083 fHeader.SetNtrack(fHeader.GetNtrack()+fNtrack-fHgwmk);
1085 // Preset map, to be removed later
1086 for(i=0; i<fNtrack; i++) {
1087 if(i<=fHgwmk) map[i]=i ; else map[i] = -99 ;}
1088 // Second pass, build map between old and new numbering
1089 for(i=fHgwmk+1; i<fNtrack; i++) {
1090 part = (TParticle *)particles.UncheckedAt(i);
1091 if(part->TestBit(Keep_Bit)) {
1093 // This particle has to be kept
1097 // Old and new are different, have to copy
1098 partnew = (TParticle *)particles.UncheckedAt(nkeep);
1100 } else partnew = part;
1102 // as the parent is always *before*, it must be already
1103 // in place. This is what we are checking anyway!
1104 if((parent=partnew->GetFirstMother())>fHgwmk) {
1105 if(map[parent]==-99) printf("map[%d] = -99!\n",parent);
1106 partnew->SetFirstMother(map[parent]);
1113 // Fix daughters information
1114 for (i=fHgwmk+1; i<fNtrack; i++) {
1115 part = (TParticle *)particles.UncheckedAt(i);
1116 parent = part->GetFirstMother();
1117 father = (TParticle *)particles.UncheckedAt(parent);
1118 if(father->TestBit(Daughters_Bit)) {
1120 if(i<father->GetFirstDaughter()) father->SetFirstDaughter(i);
1121 if(i>father->GetLastDaughter()) father->SetLastDaughter(i);
1123 // Iitialise daughters info for first pass
1124 father->SetFirstDaughter(i);
1125 father->SetLastDaughter(i);
1126 father->SetBit(Daughters_Bit);
1130 // Now loop on all detectors and reset the hits
1131 TIter next(fModules);
1132 AliModule *detector;
1133 while((detector = (AliModule*)next())) {
1134 if (!detector->Hits()) continue;
1135 TClonesArray &vHits=*(detector->Hits());
1136 if(vHits.GetEntries() != detector->GetNhits())
1137 printf("vHits.GetEntries()!=detector->GetNhits(): %d != %d\n",
1138 vHits.GetEntries(),detector->GetNhits());
1139 for (i=0; i<detector->GetNhits(); i++) {
1140 OneHit = (AliHit *)vHits.UncheckedAt(i);
1141 OneHit->SetTrack(map[OneHit->GetTrack()]);
1146 particles.SetLast(fHgwmk);
1150 //_____________________________________________________________________________
1151 void AliRun::Reset(Int_t run, Int_t idevent)
1154 // Reset all Detectors & kinematics & trees
1162 // Initialise event header
1163 fHeader.Reset(run,idevent);
1167 sprintf(hname,"TreeK%d",idevent);
1168 fTreeK->SetName(hname);
1172 sprintf(hname,"TreeH%d",idevent);
1173 fTreeH->SetName(hname);
1177 sprintf(hname,"TreeD%d",idevent);
1178 fTreeD->SetName(hname);
1182 sprintf(hname,"TreeR%d",idevent);
1183 fTreeR->SetName(hname);
1187 //_____________________________________________________________________________
1188 void AliRun::ResetDigits()
1191 // Reset all Detectors digits
1193 TIter next(fModules);
1194 AliModule *detector;
1195 while((detector = (AliModule*)next())) {
1196 detector->ResetDigits();
1200 //_____________________________________________________________________________
1201 void AliRun::ResetHits()
1204 // Reset all Detectors hits
1206 TIter next(fModules);
1207 AliModule *detector;
1208 while((detector = (AliModule*)next())) {
1209 detector->ResetHits();
1213 //_____________________________________________________________________________
1214 void AliRun::ResetPoints()
1217 // Reset all Detectors points
1219 TIter next(fModules);
1220 AliModule *detector;
1221 while((detector = (AliModule*)next())) {
1222 detector->ResetPoints();
1226 //_____________________________________________________________________________
1227 void AliRun::Run(Int_t nevent, const char *setup)
1230 // Main function to be called to process a galice run
1232 // Root > gAlice.Run();
1233 // a positive number of events will cause the finish routine
1238 // check if initialisation has been done
1239 if (!fInitDone) Init(setup);
1241 // Create the Root Tree with one branch per detector
1243 gAlice->MakeTree("KHDER");
1246 todo = TMath::Abs(nevent);
1247 for (i=0; i<todo; i++) {
1248 // Process one run (one run = one event)
1249 gAlice->Reset(fRun, fEvent);
1253 gAlice->FinishEvent();
1257 // End of this run, close files
1258 if(nevent>0) gAlice->FinishRun();
1261 //_____________________________________________________________________________
1262 void AliRun::RunLego(const char *setup,Int_t ntheta,Float_t themin,
1263 Float_t themax,Int_t nphi,Float_t phimin,Float_t phimax,
1264 Float_t rmin,Float_t rmax,Float_t zmax)
1267 // Generates lego plots of:
1268 // - radiation length map phi vs theta
1269 // - radiation length map phi vs eta
1270 // - interaction length map
1271 // - g/cm2 length map
1273 // ntheta bins in theta, eta
1274 // themin minimum angle in theta (degrees)
1275 // themax maximum angle in theta (degrees)
1277 // phimin minimum angle in phi (degrees)
1278 // phimax maximum angle in phi (degrees)
1279 // rmin minimum radius
1280 // rmax maximum radius
1283 // The number of events generated = ntheta*nphi
1284 // run input parameters in macro setup (default="Config.C")
1286 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1289 <img src="picts/AliRunLego1.gif">
1294 <img src="picts/AliRunLego2.gif">
1299 <img src="picts/AliRunLego3.gif">
1304 // check if initialisation has been done
1305 if (!fInitDone) Init(setup);
1307 fLego = new AliLego("lego","lego");
1308 fLego->Init(ntheta,themin,themax,nphi,phimin,phimax,rmin,rmax,zmax);
1311 // Create only the Root event Tree
1312 gAlice->MakeTree("E");
1314 // End of this run, close files
1315 gAlice->FinishRun();
1318 //_____________________________________________________________________________
1319 void AliRun::SetCurrentTrack(Int_t track)
1322 // Set current track number
1327 //_____________________________________________________________________________
1328 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1329 Float_t *vpos, Float_t *polar, Float_t tof,
1330 const char *mecha, Int_t &ntr, Float_t weight)
1333 // Load a track on the stack
1335 // done 0 if the track has to be transported
1337 // parent identifier of the parent track. -1 for a primary
1338 // pdg particle code
1339 // pmom momentum GeV/c
1341 // polar polarisation
1342 // tof time of flight in seconds
1343 // mecha production mechanism
1344 // ntr on output the number of the track stored
1346 TClonesArray &particles = *fParticles;
1347 TParticle *particle;
1349 const Int_t firstdaughter=-1;
1350 const Int_t lastdaughter=-1;
1352 // const Float_t tlife=0;
1355 // Here we get the static mass
1356 // For MC is ok, but a more sophisticated method could be necessary
1357 // if the calculated mass is required
1358 // also, this method is potentially dangerous if the mass
1359 // used in the MC is not the same of the PDG database
1361 mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
1362 Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+
1363 pmom[1]*pmom[1]+pmom[2]*pmom[2]);
1365 //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",
1366 //pname,mass,e,fNtrack,pdg,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],KS,mecha);
1368 particle=new(particles[fNtrack]) TParticle(pdg,KS,parent,-1,firstdaughter,
1369 lastdaughter,pmom[0],pmom[1],pmom[2],
1370 e,vpos[0],vpos[1],vpos[2],tof);
1371 // polar[0],polar[1],polar[2],tof,
1373 ((TParticle*)particles[fNtrack])->SetPolarisation(TVector3(polar[0],polar[1],polar[2]));
1374 ((TParticle*)particles[fNtrack])->SetWeight(weight);
1375 if(!done) particle->SetBit(Done_Bit);
1378 particle=(TParticle*) fParticles->UncheckedAt(parent);
1379 particle->SetLastDaughter(fNtrack);
1380 if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack);
1383 // This is a primary track. Set high water mark for this event
1386 // Set also number if primary tracks
1387 fHeader.SetNprimary(fHgwmk+1);
1388 fHeader.SetNtrack(fHgwmk+1);
1393 //_____________________________________________________________________________
1394 void AliRun::KeepTrack(const Int_t track)
1397 // flags a track to be kept
1399 TClonesArray &particles = *fParticles;
1400 ((TParticle*)particles[track])->SetBit(Keep_Bit);
1403 //_____________________________________________________________________________
1404 void AliRun::StepManager(Int_t id) const
1407 // Called at every step during transport
1412 // --- If lego option, do it and leave
1414 fLego->StepManager();
1417 //Update energy deposition tables
1418 sEventEnergy[gMC->CurrentVolID(copy)]+=gMC->Edep();
1420 //Call the appropriate stepping routine;
1421 AliModule *det = (AliModule*)fModules->At(id);
1422 if(det) det->StepManager();
1425 //_____________________________________________________________________________
1426 void AliRun::ReadEuclid(const char* filnam, const AliModule *det, char* topvol)
1429 // read in the geometry of the detector in euclid file format
1431 // id_det : the detector identification (2=its,...)
1432 // topvol : return parameter describing the name of the top
1433 // volume of geometry.
1435 // author : m. maire
1438 // several changes have been made by miroslav helbich
1439 // subroutine is rewrited to follow the new established way of memory
1440 // booking for tracking medias and rotation matrices.
1441 // all used tracking media have to be defined first, for this you can use
1442 // subroutine greutmed.
1443 // top volume is searched as only volume not positioned into another
1446 Int_t i, nvol, iret, itmed, irot, numed, npar, ndiv, iaxe;
1447 Int_t ndvmx, nr, flag;
1448 char key[5], card[77], natmed[21];
1449 char name[5], mother[5], shape[5], konly[5], volst[7000][5];
1452 Float_t teta1, phi1, teta2, phi2, teta3, phi3, orig, step;
1454 Int_t idrot[5000],istop[7000];
1457 // *** The input filnam name will be with extension '.euc'
1458 filtmp=gSystem->ExpandPathName(filnam);
1459 lun=fopen(filtmp,"r");
1462 Error("ReadEuclid","Could not open file %s\n",filnam);
1465 //* --- definition of rotation matrix 0 ---
1466 TArrayI &idtmed = *(det->GetIdtmed());
1470 for(i=0;i<77;i++) card[i]=0;
1471 iret=fscanf(lun,"%77[^\n]",card);
1472 if(iret<=0) goto L20;
1475 strncpy(key,card,4);
1477 if (!strcmp(key,"TMED")) {
1478 sscanf(&card[5],"%d '%[^']'",&itmed,natmed);
1479 //Pad the string with blanks
1482 while(i<20) natmed[i++]=' ';
1485 gMC->Gckmat(idtmed[itmed],natmed);
1487 } else if (!strcmp(key,"ROTM")) {
1488 sscanf(&card[4],"%d %f %f %f %f %f %f",&irot,&teta1,&phi1,&teta2,&phi2,&teta3,&phi3);
1489 det->AliMatrix(idrot[irot],teta1,phi1,teta2,phi2,teta3,phi3);
1491 } else if (!strcmp(key,"VOLU")) {
1492 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, shape, &numed, &npar);
1494 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
1497 gMC->Gsvolu( name, shape, idtmed[numed], par, npar);
1498 //* save the defined volumes
1499 strcpy(volst[++nvol],name);
1502 } else if (!strcmp(key,"DIVN")) {
1503 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, mother, &ndiv, &iaxe);
1504 gMC->Gsdvn ( name, mother, ndiv, iaxe );
1506 } else if (!strcmp(key,"DVN2")) {
1507 sscanf(&card[5],"'%[^']' '%[^']' %d %d %f %d",name, mother, &ndiv, &iaxe, &orig, &numed);
1508 gMC->Gsdvn2( name, mother, ndiv, iaxe, orig,idtmed[numed]);
1510 } else if (!strcmp(key,"DIVT")) {
1511 sscanf(&card[5],"'%[^']' '%[^']' %f %d %d %d", name, mother, &step, &iaxe, &numed, &ndvmx);
1512 gMC->Gsdvt ( name, mother, step, iaxe, idtmed[numed], ndvmx);
1514 } else if (!strcmp(key,"DVT2")) {
1515 sscanf(&card[5],"'%[^']' '%[^']' %f %d %f %d %d", name, mother, &step, &iaxe, &orig, &numed, &ndvmx);
1516 gMC->Gsdvt2 ( name, mother, step, iaxe, orig, idtmed[numed], ndvmx );
1518 } else if (!strcmp(key,"POSI")) {
1519 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']'", name, &nr, mother, &xo, &yo, &zo, &irot, konly);
1520 //*** volume name cannot be the top volume
1521 for(i=1;i<=nvol;i++) {
1522 if (!strcmp(volst[i],name)) istop[i]=0;
1525 gMC->Gspos ( name, nr, mother, xo, yo, zo, idrot[irot], konly );
1527 } else if (!strcmp(key,"POSP")) {
1528 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']' %d", name, &nr, mother, &xo, &yo, &zo, &irot, konly, &npar);
1530 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
1533 //*** volume name cannot be the top volume
1534 for(i=1;i<=nvol;i++) {
1535 if (!strcmp(volst[i],name)) istop[i]=0;
1538 gMC->Gsposp ( name, nr, mother, xo,yo,zo, idrot[irot], konly, par, npar);
1541 if (strcmp(key,"END")) goto L10;
1542 //* find top volume in the geometry
1544 for(i=1;i<=nvol;i++) {
1545 if (istop[i] && flag) {
1546 Warning("ReadEuclid"," %s is another possible top volume\n",volst[i]);
1548 if (istop[i] && !flag) {
1549 strcpy(topvol,volst[i]);
1550 printf(" *** GREUCL *** volume %s taken as a top volume\n",topvol);
1555 Warning("ReadEuclid","top volume not found\n");
1559 //* commented out only for the not cernlib version
1560 printf(" *** GREUCL *** file: %s is now read in\n",filnam);
1565 Error("ReadEuclid","reading error or premature end of file\n");
1568 //_____________________________________________________________________________
1569 void AliRun::ReadEuclidMedia(const char* filnam, const AliModule *det)
1572 // read in the materials and tracking media for the detector
1573 // in euclid file format
1575 // filnam: name of the input file
1576 // id_det: id_det is the detector identification (2=its,...)
1578 // author : miroslav helbich
1580 Float_t sxmgmx = gAlice->Field()->Max();
1581 Int_t isxfld = gAlice->Field()->Integ();
1582 Int_t end, i, iret, itmed;
1583 char key[5], card[130], natmed[21], namate[21];
1588 Int_t nwbuf, isvol, ifield, nmat;
1589 Float_t a, z, dens, radl, absl, fieldm, tmaxfd, stemax, deemax, epsil, stmin;
1592 for(i=0;i<end;i++) if(filnam[i]=='.') {
1597 // *** The input filnam name will be with extension '.euc'
1598 printf("The file name is %s\n",filnam); //Debug
1599 filtmp=gSystem->ExpandPathName(filnam);
1600 lun=fopen(filtmp,"r");
1603 Warning("ReadEuclidMedia","Could not open file %s\n",filnam);
1607 // Retrieve Mag Field parameters
1608 Int_t ISXFLD=gAlice->Field()->Integ();
1609 Float_t SXMGMX=gAlice->Field()->Max();
1610 // TArrayI &idtmed = *(det->GetIdtmed());
1613 for(i=0;i<130;i++) card[i]=0;
1614 iret=fscanf(lun,"%4s %[^\n]",key,card);
1615 if(iret<=0) goto L20;
1619 if (!strcmp(key,"MATE")) {
1620 sscanf(card,"%d '%[^']' %f %f %f %f %f %d",&imate,namate,&a,&z,&dens,&radl,&absl,&nwbuf);
1621 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
1622 //Pad the string with blanks
1625 while(i<20) namate[i++]=' ';
1628 det->AliMaterial(imate,namate,a,z,dens,radl,absl,ubuf,nwbuf);
1629 //* read tracking medium
1630 } else if (!strcmp(key,"TMED")) {
1631 sscanf(card,"%d '%[^']' %d %d %d %f %f %f %f %f %f %d",
1632 &itmed,natmed,&nmat,&isvol,&ifield,&fieldm,&tmaxfd,
1633 &stemax,&deemax,&epsil,&stmin,&nwbuf);
1634 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
1635 if (ifield<0) ifield=isxfld;
1636 if (fieldm<0) fieldm=sxmgmx;
1637 //Pad the string with blanks
1640 while(i<20) natmed[i++]=' ';
1643 det->AliMedium(itmed,natmed,nmat,isvol,ISXFLD,SXMGMX,tmaxfd,
1644 stemax,deemax,epsil,stmin,ubuf,nwbuf);
1645 // (*fImedia)[idtmed[itmed]-1]=id_det;
1649 if (strcmp(key,"END")) goto L10;
1652 //* commented out only for the not cernlib version
1653 Warning("ReadEuclidMedia","file: %s is now read in\n",filnam);
1658 Warning("ReadEuclidMedia","reading error or premature end of file\n");
1661 //_____________________________________________________________________________
1662 void AliRun::Streamer(TBuffer &R__b)
1665 // Stream an object of class AliRun.
1667 if (R__b.IsReading()) {
1668 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1669 TNamed::Streamer(R__b);
1670 if (!gAlice) gAlice = this;
1671 gROOT->GetListOfBrowsables()->Add(this,"Run");
1672 fTreeE = (TTree*)gDirectory->Get("TE");
1673 if (fTreeE) fTreeE->SetBranchAddress("Header", &header);
1674 else Error("Streamer","cannot find Header Tree\n");
1678 fHeader.Streamer(R__b);
1688 R__b >> fPDGDB; //Particle factory object!
1689 fTreeE->GetEntry(0);
1691 fHeader.SetEvent(0);
1692 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
1695 R__b.WriteVersion(AliRun::IsA());
1696 TNamed::Streamer(R__b);
1700 fHeader.Streamer(R__b);
1709 R__b << fPDGDB; //Particle factory object!
1714 //_____________________________________________________________________________
1716 // Interfaces to Fortran
1718 //_____________________________________________________________________________
1720 extern "C" void type_of_call rxgtrak (Int_t &mtrack, Int_t &ipart, Float_t *pmom,
1721 Float_t &e, Float_t *vpos, Float_t *polar,
1725 // Fetches next track from the ROOT stack for transport. Called by the
1726 // modified version of GTREVE.
1728 // Track number in the ROOT stack. If MTRACK=0 no
1729 // mtrack more tracks are left in the stack to be
1731 // ipart Particle code in the GEANT conventions.
1732 // pmom[3] Particle momentum in GeV/c
1733 // e Particle energy in GeV
1734 // vpos[3] Particle position
1735 // tof Particle time of flight in seconds
1738 gAlice->GetNextTrack(mtrack, pdg, pmom, e, vpos, polar, tof);
1739 ipart = gMC->IdFromPDG(pdg);
1743 //_____________________________________________________________________________
1744 extern "C" void type_of_call
1746 rxstrak (Int_t &keep, Int_t &parent, Int_t &ipart, Float_t *pmom,
1747 Float_t *vpos, Float_t &tof, const char* cmech, Int_t &ntr, const int cmlen)
1749 rxstrak (Int_t &keep, Int_t &parent, Int_t &ipart, Float_t *pmom,
1750 Float_t *vpos, Float_t &tof, const char* cmech, const int cmlen,
1755 // Fetches next track from the ROOT stack for transport. Called by GUKINE
1758 // Status of the track. If keep=0 the track is put
1759 // keep on the ROOT stack but it is not fetched for
1761 // parent Parent track. If parent=0 the track is a primary.
1762 // In GUSTEP the routine is normally called to store
1763 // secondaries generated by the current track whose
1764 // ROOT stack number is MTRACK (common SCKINE.
1765 // ipart Particle code in the GEANT conventions.
1766 // pmom[3] Particle momentum in GeV/c
1767 // vpos[3] Particle position
1768 // tof Particle time of flight in seconds
1770 // cmech (CHARACTER*10) Particle origin. This field is user
1771 // defined and it is not used inside the GALICE code.
1772 // ntr Number assigned to the particle in the ROOT stack.
1775 Float_t polar[3]={0.,0.,0.};
1776 for(int i=0; i<10 && i<cmlen; i++) mecha[i]=cmech[i];
1778 Int_t pdg=gMC->PDGFromId(ipart);
1779 gAlice->SetTrack(keep, parent-1, pdg, pmom, vpos, polar, tof, mecha, ntr);
1783 //_____________________________________________________________________________
1784 extern "C" void type_of_call rxkeep(const Int_t &n)
1786 if( NULL==gAlice ) exit(1);
1788 if( n<=0 || n>gAlice->Particles()->GetEntries() )
1790 printf(" Bad index n=%d must be 0<n<=%d\n",
1791 n,gAlice->Particles()->GetEntries());
1795 ((TParticle*)(gAlice->Particles()->UncheckedAt(n-1)))->SetBit(Keep_Bit);
1798 //_____________________________________________________________________________
1799 extern "C" void type_of_call rxouth ()
1802 // Called by Gtreve at the end of each primary track
1804 gAlice->FinishPrimary();