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(hname);
428 sprintf(hname,"TreeH%d",ievent);
429 if (fTreeH) fTreeH->Write(hname);
430 sprintf(hname,"TreeD%d",ievent);
431 if (fTreeD) fTreeD->Write(hname);
432 sprintf(hname,"TreeR%d",ievent);
433 if (fTreeR) fTreeR->Write(hname);
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
608 fHeader.SetEvent(event);
610 // Reset existing structures
615 // Delete Trees already connected
616 if (fTreeK) delete fTreeK;
617 if (fTreeH) delete fTreeH;
618 if (fTreeD) delete fTreeD;
619 if (fTreeR) delete fTreeR;
621 // Get Kine Tree from file
623 sprintf(treeName,"TreeK%d",event);
624 fTreeK = (TTree*)gDirectory->Get(treeName);
625 if (fTreeK) fTreeK->SetBranchAddress("Particles", &fParticles);
626 else Error("GetEvent","cannot find Kine Tree for event:%d\n",event);
628 // Get Hits Tree header from file
629 sprintf(treeName,"TreeH%d",event);
630 fTreeH = (TTree*)gDirectory->Get(treeName);
632 Error("GetEvent","cannot find Hits Tree for event:%d\n",event);
635 // Get Digits Tree header from file
636 sprintf(treeName,"TreeD%d",event);
637 fTreeD = (TTree*)gDirectory->Get(treeName);
639 printf("WARNING: cannot find Digits Tree for event:%d\n",event);
643 // Get Reconstruct Tree header from file
644 sprintf(treeName,"TreeR%d",event);
645 fTreeR = (TTree*)gDirectory->Get(treeName);
647 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
650 // Set Trees branch addresses
651 TIter next(fModules);
653 while((detector = (AliModule*)next())) {
654 detector->SetTreeAddress();
657 if (fTreeK) fTreeK->GetEvent(0);
658 fNtrack = Int_t (fParticles->GetEntries());
662 //_____________________________________________________________________________
663 TGeometry *AliRun::GetGeometry()
666 // Import Alice geometry from current file
667 // Return pointer to geometry object
669 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
671 // Unlink and relink nodes in detectors
672 // This is bad and there must be a better way...
674 TList *tnodes=fGeometry->GetListOfNodes();
675 TNode *alice=(TNode*)tnodes->At(0);
676 TList *gnodes=alice->GetListOfNodes();
678 TIter next(fModules);
680 while((detector = (AliModule*)next())) {
681 detector->SetTreeAddress();
682 TList *dnodes=detector->Nodes();
685 for ( j=0; j<dnodes->GetSize(); j++) {
686 node = (TNode*) dnodes->At(j);
687 node1 = (TNode*) gnodes->FindObject(node->GetName());
688 dnodes->Remove(node);
689 dnodes->AddAt(node1,j);
695 //_____________________________________________________________________________
696 void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
697 Float_t &e, Float_t *vpos, Float_t *polar,
701 // Return next track from stack of particles
706 for(Int_t i=fNtrack-1; i>=0; i--) {
707 track=(TParticle*) fParticles->UncheckedAt(i);
708 if(!track->TestBit(Done_Bit)) {
710 // The track has not yet been processed
712 ipart=track->GetPdgCode();
720 pol = track->GetPolarisation();
725 track->SetBit(Done_Bit);
731 // stop and start timer when we start a primary track
732 Int_t nprimaries = fHeader.GetNprimary();
733 if (fCurrent >= nprimaries) return;
734 if (fCurrent < nprimaries-1) {
736 track=(TParticle*) fParticles->UncheckedAt(fCurrent+1);
737 // track->SetProcessTime(fTimer.CpuTime());
742 //_____________________________________________________________________________
743 Int_t AliRun::GetPrimary(Int_t track)
746 // return number of primary that has generated track
754 part = (TParticle *)fParticles->UncheckedAt(current);
755 parent=part->GetFirstMother();
756 if(parent<0) return current;
760 //_____________________________________________________________________________
761 void AliRun::Init(const char *setup)
764 // Initialize the Alice setup
767 gROOT->LoadMacro(setup);
768 gInterpreter->ProcessLine("Config();");
770 gMC->DefineParticles(); //Create standard MC particles
772 TObject *objfirst, *objlast;
774 fNdets = fModules->GetLast()+1;
777 //=================Create Materials, geometry, histograms, etc
778 TIter next(fModules);
780 while((detector = (AliModule*)next())) {
781 detector->SetTreeAddress();
782 objlast = gDirectory->GetList()->Last();
784 // Initialise detector materials, geometry, histograms,etc
785 detector->CreateMaterials();
786 detector->CreateGeometry();
787 detector->BuildGeometry();
790 // Add Detector histograms in Detector list of histograms
791 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
792 else objfirst = gDirectory->GetList()->First();
794 detector->Histograms()->Add(objfirst);
795 objfirst = gDirectory->GetList()->After(objfirst);
798 SetTransPar(); //Read the cuts for all materials
800 MediaTable(); //Build the special IMEDIA table
802 //Close the geometry structure
805 //Initialise geometry deposition table
806 sEventEnergy.Set(gMC->NofVolumes()+1);
807 sSummEnergy.Set(gMC->NofVolumes()+1);
808 sSum2Energy.Set(gMC->NofVolumes()+1);
810 //Create the color table
813 //Compute cross-sections
816 //Write Geometry object to current file.
822 //_____________________________________________________________________________
823 void AliRun::MediaTable()
826 // Built media table to get from the media number to
829 Int_t kz, nz, idt, lz, i, k, ind;
831 TObjArray &dets = *gAlice->Detectors();
835 for (kz=0;kz<fNdets;kz++) {
836 // If detector is defined
837 if((det=(AliModule*) dets[kz])) {
838 TArrayI &idtmed = *(det->GetIdtmed());
839 for(nz=0;nz<100;nz++) {
840 // Find max and min material number
841 if((idt=idtmed[nz])) {
842 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
843 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
846 if(det->LoMedium() > det->HiMedium()) {
850 if(det->HiMedium() > fImedia->GetSize()) {
851 Error("MediaTable","Increase fImedia from %d to %d",
852 fImedia->GetSize(),det->HiMedium());
855 // Tag all materials in rage as belonging to detector kz
856 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
863 // Print summary table
864 printf(" Traking media ranges:\n");
865 for(i=0;i<(fNdets-1)/6+1;i++) {
866 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
868 det=(AliModule*)dets[ind];
870 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
873 printf(" %6s: %3d -> %3d;","NULL",0,0);
879 //____________________________________________________________________________
880 void AliRun::SetGenerator(AliGenerator *generator)
883 // Load the event generator
885 if(!fGenerator) fGenerator = generator;
888 //____________________________________________________________________________
889 void AliRun::SetTransPar(char* filename)
892 // Read filename to set the transport parameters
896 const Int_t ncuts=10;
897 const Int_t nflags=11;
898 const Int_t npars=ncuts+nflags;
899 const char pars[npars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
900 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
901 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
902 "MULS","PAIR","PHOT","RAYL"};
908 Int_t i, itmed, iret, ktmed, kz;
911 // See whether the file is there
912 filtmp=gSystem->ExpandPathName(filename);
913 lun=fopen(filtmp,"r");
916 Warning("SetTransPar","File %s does not exist!\n",filename);
920 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
921 printf(" *%59s\n","*");
922 printf(" * Please check carefully what you are doing!%10s\n","*");
923 printf(" *%59s\n","*");
926 // Initialise cuts and flags
927 for(i=0;i<ncuts;i++) cut[i]=-99;
928 for(i=0;i<nflags;i++) flag[i]=-99;
930 for(i=0;i<256;i++) line[i]='\0';
931 // Read up to the end of line excluded
932 iret=fscanf(lun,"%[^\n]",line);
936 printf(" *%59s\n","*");
937 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
940 // Read the end of line
943 if(line[0]=='*') continue;
945 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",
946 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
947 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
948 &flag[8],&flag[9],&flag[10]);
952 Warning("SetTransPar","Error reading file %s\n",filename);
955 // Check that the module exist
956 AliModule *mod = GetModule(detName);
958 // Get the array of media numbers
959 TArrayI &idtmed = *mod->GetIdtmed();
960 // Check that the tracking medium code is valid
961 if(0<=itmed && itmed < 100) {
964 Warning("SetTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
967 // Set energy thresholds
968 for(kz=0;kz<ncuts;kz++) {
970 printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
971 pars[kz],cut[kz],itmed,mod->GetName());
972 gMC->Gstpar(ktmed,pars[kz],cut[kz]);
975 // Set transport mechanisms
976 for(kz=0;kz<nflags;kz++) {
978 printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
979 pars[ncuts+kz],flag[kz],itmed,mod->GetName());
980 gMC->Gstpar(ktmed,pars[ncuts+kz],Float_t(flag[kz]));
984 Warning("SetTransPar","Invalid medium code %d *\n",itmed);
988 Warning("SetTransPar","Module %s not present\n",detName);
994 //_____________________________________________________________________________
995 void AliRun::MakeTree(Option_t *option)
998 // Create the ROOT trees
999 // Loop on all detectors to create the Root branch (if any)
1004 char *K = strstr(option,"K");
1005 char *H = strstr(option,"H");
1006 char *E = strstr(option,"E");
1007 char *D = strstr(option,"D");
1008 char *R = strstr(option,"R");
1010 if (K && !fTreeK) fTreeK = new TTree("TK","Kinematics");
1011 if (H && !fTreeH) fTreeH = new TTree("TH","Hits");
1012 if (D && !fTreeD) fTreeD = new TTree("TD","Digits");
1013 if (E && !fTreeE) fTreeE = new TTree("TE","Header");
1014 if (R && !fTreeR) fTreeR = new TTree("TR","Reconstruction");
1015 if (fTreeH) fTreeH->SetAutoSave(1000000000); //no autosave
1017 // Create a branch for hits/digits for each detector
1018 // Each branch is a TClonesArray. Each data member of the Hits classes
1019 // will be in turn a subbranch of the detector master branch
1020 TIter next(fModules);
1021 AliModule *detector;
1022 while((detector = (AliModule*)next())) {
1023 if (H || D || R) detector->MakeBranch(option);
1025 // Create a branch for particles
1026 if (fTreeK && K) fTreeK->Branch("Particles",&fParticles,4000);
1028 // Create a branch for Header
1029 if (fTreeE && E) fTreeE->Branch("Header","AliHeader",&header,4000);
1032 //_____________________________________________________________________________
1033 Int_t AliRun::PurifyKine(Int_t lastSavedTrack, Int_t nofTracks)
1036 // PurifyKine with external parameters
1038 fHgwmk = lastSavedTrack;
1039 fNtrack = nofTracks;
1044 //_____________________________________________________________________________
1045 void AliRun::PurifyKine()
1048 // Compress kinematic tree keeping only flagged particles
1049 // and renaming the particle id's in all the hits
1051 TClonesArray &particles = *fParticles;
1052 int nkeep=fHgwmk+1, parent, i;
1053 TParticle *part, *partnew, *father;
1055 int *map = new int[particles.GetEntries()];
1057 // Save in Header total number of tracks before compression
1058 fHeader.SetNtrack(fHeader.GetNtrack()+fNtrack-fHgwmk);
1060 // Preset map, to be removed later
1061 for(i=0; i<fNtrack; i++) {
1062 if(i<=fHgwmk) map[i]=i ; else map[i] = -99 ;}
1063 // Second pass, build map between old and new numbering
1064 for(i=fHgwmk+1; i<fNtrack; i++) {
1065 part = (TParticle *)particles.UncheckedAt(i);
1066 if(part->TestBit(Keep_Bit)) {
1068 // This particle has to be kept
1072 // Old and new are different, have to copy
1073 partnew = (TParticle *)particles.UncheckedAt(nkeep);
1075 } else partnew = part;
1077 // as the parent is always *before*, it must be already
1078 // in place. This is what we are checking anyway!
1079 if((parent=partnew->GetFirstMother())>fHgwmk) {
1080 if(map[parent]==-99) printf("map[%d] = -99!\n",parent);
1081 partnew->SetFirstMother(map[parent]);
1088 // Fix daughters information
1089 for (i=fHgwmk+1; i<fNtrack; i++) {
1090 part = (TParticle *)particles.UncheckedAt(i);
1091 parent = part->GetFirstMother();
1092 father = (TParticle *)particles.UncheckedAt(parent);
1093 if(father->TestBit(Daughters_Bit)) {
1095 if(i<father->GetFirstDaughter()) father->SetFirstDaughter(i);
1096 if(i>father->GetLastDaughter()) father->SetLastDaughter(i);
1098 // Iitialise daughters info for first pass
1099 father->SetFirstDaughter(i);
1100 father->SetLastDaughter(i);
1101 father->SetBit(Daughters_Bit);
1105 // Now loop on all detectors and reset the hits
1106 TIter next(fModules);
1107 AliModule *detector;
1108 while((detector = (AliModule*)next())) {
1109 if (!detector->Hits()) continue;
1110 TClonesArray &vHits=*(detector->Hits());
1111 if(vHits.GetEntries() != detector->GetNhits())
1112 printf("vHits.GetEntries()!=detector->GetNhits(): %d != %d\n",
1113 vHits.GetEntries(),detector->GetNhits());
1114 for (i=0; i<detector->GetNhits(); i++) {
1115 OneHit = (AliHit *)vHits.UncheckedAt(i);
1116 OneHit->SetTrack(map[OneHit->GetTrack()]);
1121 particles.SetLast(fHgwmk);
1125 //_____________________________________________________________________________
1126 void AliRun::Reset(Int_t run, Int_t idevent)
1129 // Reset all Detectors & kinematics & trees
1135 // Initialise event header
1136 fHeader.Reset(run,idevent);
1138 if(fTreeK) fTreeK->Reset();
1139 if(fTreeH) fTreeH->Reset();
1140 if(fTreeD) fTreeD->Reset();
1141 if(fTreeR) fTreeR->Reset();
1144 //_____________________________________________________________________________
1145 void AliRun::ResetDigits()
1148 // Reset all Detectors digits
1150 TIter next(fModules);
1151 AliModule *detector;
1152 while((detector = (AliModule*)next())) {
1153 detector->ResetDigits();
1157 //_____________________________________________________________________________
1158 void AliRun::ResetHits()
1161 // Reset all Detectors hits
1163 TIter next(fModules);
1164 AliModule *detector;
1165 while((detector = (AliModule*)next())) {
1166 detector->ResetHits();
1170 //_____________________________________________________________________________
1171 void AliRun::ResetPoints()
1174 // Reset all Detectors points
1176 TIter next(fModules);
1177 AliModule *detector;
1178 while((detector = (AliModule*)next())) {
1179 detector->ResetPoints();
1183 //_____________________________________________________________________________
1184 void AliRun::Run(Int_t nevent, const char *setup)
1187 // Main function to be called to process a galice run
1189 // Root > gAlice.Run();
1190 // a positive number of events will cause the finish routine
1195 // check if initialisation has been done
1196 if (!fInitDone) Init(setup);
1198 // Create the Root Tree with one branch per detector
1200 gAlice->MakeTree("KHDER");
1203 todo = TMath::Abs(nevent);
1204 for (i=0; i<todo; i++) {
1205 // Process one run (one run = one event)
1206 gAlice->Reset(fRun, fEvent);
1210 gAlice->FinishEvent();
1214 // End of this run, close files
1215 if(nevent>0) gAlice->FinishRun();
1218 //_____________________________________________________________________________
1219 void AliRun::RunLego(const char *setup,Int_t ntheta,Float_t themin,
1220 Float_t themax,Int_t nphi,Float_t phimin,Float_t phimax,
1221 Float_t rmin,Float_t rmax,Float_t zmax)
1224 // Generates lego plots of:
1225 // - radiation length map phi vs theta
1226 // - radiation length map phi vs eta
1227 // - interaction length map
1228 // - g/cm2 length map
1230 // ntheta bins in theta, eta
1231 // themin minimum angle in theta (degrees)
1232 // themax maximum angle in theta (degrees)
1234 // phimin minimum angle in phi (degrees)
1235 // phimax maximum angle in phi (degrees)
1236 // rmin minimum radius
1237 // rmax maximum radius
1240 // The number of events generated = ntheta*nphi
1241 // run input parameters in macro setup (default="Config.C")
1243 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1246 <img src="picts/AliRunLego1.gif">
1251 <img src="picts/AliRunLego2.gif">
1256 <img src="picts/AliRunLego3.gif">
1261 // check if initialisation has been done
1262 if (!fInitDone) Init(setup);
1264 fLego = new AliLego("lego","lego");
1265 fLego->Init(ntheta,themin,themax,nphi,phimin,phimax,rmin,rmax,zmax);
1268 // Create only the Root event Tree
1269 gAlice->MakeTree("E");
1271 // End of this run, close files
1272 gAlice->FinishRun();
1275 //_____________________________________________________________________________
1276 void AliRun::SetCurrentTrack(Int_t track)
1279 // Set current track number
1284 //_____________________________________________________________________________
1285 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1286 Float_t *vpos, Float_t *polar, Float_t tof,
1287 const char *mecha, Int_t &ntr, Float_t weight)
1290 // Load a track on the stack
1292 // done 0 if the track has to be transported
1294 // parent identifier of the parent track. -1 for a primary
1295 // pdg particle code
1296 // pmom momentum GeV/c
1298 // polar polarisation
1299 // tof time of flight in seconds
1300 // mecha production mechanism
1301 // ntr on output the number of the track stored
1303 TClonesArray &particles = *fParticles;
1304 TParticle *particle;
1306 const Int_t firstdaughter=-1;
1307 const Int_t lastdaughter=-1;
1309 // const Float_t tlife=0;
1312 // Here we get the static mass
1313 // For MC is ok, but a more sophisticated method could be necessary
1314 // if the calculated mass is required
1315 // also, this method is potentially dangerous if the mass
1316 // used in the MC is not the same of the PDG database
1318 mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
1319 Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+
1320 pmom[1]*pmom[1]+pmom[2]*pmom[2]);
1322 //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",
1323 //pname,mass,e,fNtrack,pdg,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],KS,mecha);
1325 particle=new(particles[fNtrack]) TParticle(pdg,KS,parent,-1,firstdaughter,
1326 lastdaughter,pmom[0],pmom[1],pmom[2],
1327 e,vpos[0],vpos[1],vpos[2],tof);
1328 // polar[0],polar[1],polar[2],tof,
1330 ((TParticle*)particles[fNtrack])->SetPolarisation(TVector3(polar[0],polar[1],polar[2]));
1331 ((TParticle*)particles[fNtrack])->SetWeight(weight);
1332 if(!done) particle->SetBit(Done_Bit);
1335 particle=(TParticle*) fParticles->UncheckedAt(parent);
1336 particle->SetLastDaughter(fNtrack);
1337 if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack);
1340 // This is a primary track. Set high water mark for this event
1343 // Set also number if primary tracks
1344 fHeader.SetNprimary(fHgwmk+1);
1345 fHeader.SetNtrack(fHgwmk+1);
1350 //_____________________________________________________________________________
1351 void AliRun::KeepTrack(const Int_t track)
1354 // flags a track to be kept
1356 TClonesArray &particles = *fParticles;
1357 ((TParticle*)particles[track])->SetBit(Keep_Bit);
1360 //_____________________________________________________________________________
1361 void AliRun::StepManager(Int_t id) const
1364 // Called at every step during transport
1369 // --- If lego option, do it and leave
1371 fLego->StepManager();
1374 //Update energy deposition tables
1375 sEventEnergy[gMC->CurrentVol(0,copy)]+=gMC->Edep();
1377 //Call the appropriate stepping routine;
1378 AliModule *det = (AliModule*)fModules->At(id);
1379 if(det) det->StepManager();
1382 //_____________________________________________________________________________
1383 void AliRun::ReadEuclid(const char* filnam, const AliModule *det, const char* topvol)
1386 // read in the geometry of the detector in euclid file format
1388 // id_det : the detector identification (2=its,...)
1389 // topvol : return parameter describing the name of the top
1390 // volume of geometry.
1392 // author : m. maire
1395 // several changes have been made by miroslav helbich
1396 // subroutine is rewrited to follow the new established way of memory
1397 // booking for tracking medias and rotation matrices.
1398 // all used tracking media have to be defined first, for this you can use
1399 // subroutine greutmed.
1400 // top volume is searched as only volume not positioned into another
1403 Int_t i, nvol, iret, itmed, irot, numed, npar, ndiv, iaxe;
1404 Int_t ndvmx, nr, flag;
1405 char key[5], card[77], natmed[21];
1406 char name[5], mother[5], shape[5], konly[5], volst[7000][5];
1409 Float_t teta1, phi1, teta2, phi2, teta3, phi3, orig, step;
1411 Int_t idrot[5000],istop[7000];
1414 // *** The input filnam name will be with extension '.euc'
1415 filtmp=gSystem->ExpandPathName(filnam);
1416 lun=fopen(filtmp,"r");
1419 printf(" *** GREUCL *** Could not open file %s\n",filnam);
1422 //* --- definition of rotation matrix 0 ---
1423 TArrayI &idtmed = *(det->GetIdtmed());
1427 for(i=0;i<77;i++) card[i]=0;
1428 iret=fscanf(lun,"%77[^\n]",card);
1429 if(iret<=0) goto L20;
1432 strncpy(key,card,4);
1434 if (!strcmp(key,"TMED")) {
1435 sscanf(&card[5],"%d '%[^']'",&itmed,natmed);
1436 //Pad the string with blanks
1439 while(i<20) natmed[i++]=' ';
1442 gMC->Gckmat(idtmed[itmed],natmed);
1444 } else if (!strcmp(key,"ROTM")) {
1445 sscanf(&card[4],"%d %f %f %f %f %f %f",&irot,&teta1,&phi1,&teta2,&phi2,&teta3,&phi3);
1446 det->AliMatrix(idrot[irot],teta1,phi1,teta2,phi2,teta3,phi3);
1448 } else if (!strcmp(key,"VOLU")) {
1449 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, shape, &numed, &npar);
1451 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
1454 gMC->Gsvolu( name, shape, idtmed[numed], par, npar);
1455 //* save the defined volumes
1456 strcpy(volst[++nvol],name);
1459 } else if (!strcmp(key,"DIVN")) {
1460 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, mother, &ndiv, &iaxe);
1461 gMC->Gsdvn ( name, mother, ndiv, iaxe );
1463 } else if (!strcmp(key,"DVN2")) {
1464 sscanf(&card[5],"'%[^']' '%[^']' %d %d %f %d",name, mother, &ndiv, &iaxe, &orig, &numed);
1465 gMC->Gsdvn2( name, mother, ndiv, iaxe, orig,idtmed[numed]);
1467 } else if (!strcmp(key,"DIVT")) {
1468 sscanf(&card[5],"'%[^']' '%[^']' %f %d %d %d", name, mother, &step, &iaxe, &numed, &ndvmx);
1469 gMC->Gsdvt ( name, mother, step, iaxe, idtmed[numed], ndvmx);
1471 } else if (!strcmp(key,"DVT2")) {
1472 sscanf(&card[5],"'%[^']' '%[^']' %f %d %f %d %d", name, mother, &step, &iaxe, &orig, &numed, &ndvmx);
1473 gMC->Gsdvt2 ( name, mother, step, iaxe, orig, idtmed[numed], ndvmx );
1475 } else if (!strcmp(key,"POSI")) {
1476 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']'", name, &nr, mother, &xo, &yo, &zo, &irot, konly);
1477 //*** volume name cannot be the top volume
1478 for(i=1;i<=nvol;i++) {
1479 if (!strcmp(volst[i],name)) istop[i]=0;
1482 gMC->Gspos ( name, nr, mother, xo, yo, zo, idrot[irot], konly );
1484 } else if (!strcmp(key,"POSP")) {
1485 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']' %d", name, &nr, mother, &xo, &yo, &zo, &irot, konly, &npar);
1487 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
1490 //*** volume name cannot be the top volume
1491 for(i=1;i<=nvol;i++) {
1492 if (!strcmp(volst[i],name)) istop[i]=0;
1495 gMC->Gsposp ( name, nr, mother, xo,yo,zo, idrot[irot], konly, par, npar);
1498 if (strcmp(key,"END")) goto L10;
1499 //* find top volume in the geometry
1501 for(i=1;i<=nvol;i++) {
1502 if (istop[i] && flag) {
1503 printf(" *** GREUCL *** warning: %s is another possible top volume\n",volst[i]);
1505 if (istop[i] && !flag) {
1507 printf(" *** GREUCL *** volume %s taken as a top volume\n",topvol);
1512 printf("*** GREUCL *** warning: top volume not found\n");
1516 //* commented out only for the not cernlib version
1517 printf(" *** GREUCL *** file: %s is now read in\n",filnam);
1522 printf(" *** GREUCL *** reading error or premature end of file\n");
1525 //_____________________________________________________________________________
1526 void AliRun::ReadEuclidMedia(const char* filnam, const AliModule *det)
1529 // read in the materials and tracking media for the detector
1530 // in euclid file format
1532 // filnam: name of the input file
1533 // id_det: id_det is the detector identification (2=its,...)
1535 // author : miroslav helbich
1537 Float_t sxmgmx = gAlice->Field()->Max();
1538 Int_t isxfld = gAlice->Field()->Integ();
1539 Int_t end, i, iret, itmed;
1540 char key[5], card[130], natmed[21], namate[21];
1545 Int_t nwbuf, isvol, ifield, nmat;
1546 Float_t a, z, dens, radl, absl, fieldm, tmaxfd, stemax, deemax, epsil, stmin;
1549 for(i=0;i<end;i++) if(filnam[i]=='.') {
1554 // *** The input filnam name will be with extension '.euc'
1555 printf("The file name is %s\n",filnam); //Debug
1556 filtmp=gSystem->ExpandPathName(filnam);
1557 lun=fopen(filtmp,"r");
1560 Warning("ReadEuclidMedia","Could not open file %s\n",filnam);
1564 // Retrieve Mag Field parameters
1565 Int_t ISXFLD=gAlice->Field()->Integ();
1566 Float_t SXMGMX=gAlice->Field()->Max();
1567 // TArrayI &idtmed = *(det->GetIdtmed());
1570 for(i=0;i<130;i++) card[i]=0;
1571 iret=fscanf(lun,"%4s %[^\n]",key,card);
1572 if(iret<=0) goto L20;
1576 if (!strcmp(key,"MATE")) {
1577 sscanf(card,"%d '%[^']' %f %f %f %f %f %d",&imate,namate,&a,&z,&dens,&radl,&absl,&nwbuf);
1578 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
1579 //Pad the string with blanks
1582 while(i<20) namate[i++]=' ';
1585 det->AliMaterial(imate,namate,a,z,dens,radl,absl,ubuf,nwbuf);
1586 //* read tracking medium
1587 } else if (!strcmp(key,"TMED")) {
1588 sscanf(card,"%d '%[^']' %d %d %d %f %f %f %f %f %f %d",
1589 &itmed,natmed,&nmat,&isvol,&ifield,&fieldm,&tmaxfd,
1590 &stemax,&deemax,&epsil,&stmin,&nwbuf);
1591 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
1592 if (ifield<0) ifield=isxfld;
1593 if (fieldm<0) fieldm=sxmgmx;
1594 //Pad the string with blanks
1597 while(i<20) natmed[i++]=' ';
1600 det->AliMedium(itmed,natmed,nmat,isvol,ISXFLD,SXMGMX,tmaxfd,
1601 stemax,deemax,epsil,stmin,ubuf,nwbuf);
1602 // (*fImedia)[idtmed[itmed]-1]=id_det;
1606 if (strcmp(key,"END")) goto L10;
1609 //* commented out only for the not cernlib version
1610 Warning("ReadEuclidMedia","file: %s is now read in\n",filnam);
1615 Warning("ReadEuclidMedia","reading error or premature end of file\n");
1618 //_____________________________________________________________________________
1619 void AliRun::Streamer(TBuffer &R__b)
1622 // Stream an object of class AliRun.
1624 if (R__b.IsReading()) {
1625 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1626 TNamed::Streamer(R__b);
1627 if (!gAlice) gAlice = this;
1628 gROOT->GetListOfBrowsables()->Add(this,"Run");
1632 fHeader.Streamer(R__b);
1641 R__b >> fPDGDB; //Particle factory object!
1643 R__b.WriteVersion(AliRun::IsA());
1644 TNamed::Streamer(R__b);
1648 fHeader.Streamer(R__b);
1657 R__b << fPDGDB; //Particle factory object!
1662 //_____________________________________________________________________________
1664 // Interfaces to Fortran
1666 //_____________________________________________________________________________
1668 extern "C" void type_of_call rxgtrak (Int_t &mtrack, Int_t &ipart, Float_t *pmom,
1669 Float_t &e, Float_t *vpos, Float_t &tof)
1672 // Fetches next track from the ROOT stack for transport. Called by the
1673 // modified version of GTREVE.
1675 // Track number in the ROOT stack. If MTRACK=0 no
1676 // mtrack more tracks are left in the stack to be
1678 // ipart Particle code in the GEANT conventions.
1679 // pmom[3] Particle momentum in GeV/c
1680 // e Particle energy in GeV
1681 // vpos[3] Particle position
1682 // tof Particle time of flight in seconds
1686 gAlice->GetNextTrack(mtrack, pdg, pmom, e, vpos, polar, tof);
1687 ipart = gMC->IdFromPDG(pdg);
1691 //_____________________________________________________________________________
1692 extern "C" void type_of_call
1694 rxstrak (Int_t &keep, Int_t &parent, Int_t &ipart, Float_t *pmom,
1695 Float_t *vpos, Float_t &tof, const char* cmech, Int_t &ntr, const int cmlen)
1697 rxstrak (Int_t &keep, Int_t &parent, Int_t &ipart, Float_t *pmom,
1698 Float_t *vpos, Float_t &tof, const char* cmech, const int cmlen,
1703 // Fetches next track from the ROOT stack for transport. Called by GUKINE
1706 // Status of the track. If keep=0 the track is put
1707 // keep on the ROOT stack but it is not fetched for
1709 // parent Parent track. If parent=0 the track is a primary.
1710 // In GUSTEP the routine is normally called to store
1711 // secondaries generated by the current track whose
1712 // ROOT stack number is MTRACK (common SCKINE.
1713 // ipart Particle code in the GEANT conventions.
1714 // pmom[3] Particle momentum in GeV/c
1715 // vpos[3] Particle position
1716 // tof Particle time of flight in seconds
1718 // cmech (CHARACTER*10) Particle origin. This field is user
1719 // defined and it is not used inside the GALICE code.
1720 // ntr Number assigned to the particle in the ROOT stack.
1723 Float_t polar[3]={0.,0.,0.};
1724 for(int i=0; i<10 && i<cmlen; i++) mecha[i]=cmech[i];
1726 Int_t pdg=gMC->PDGFromId(ipart);
1727 gAlice->SetTrack(keep, parent-1, pdg, pmom, vpos, polar, tof, mecha, ntr);
1731 //_____________________________________________________________________________
1732 extern "C" void type_of_call rxkeep(const Int_t &n)
1734 if( NULL==gAlice ) exit(1);
1736 if( n<=0 || n>gAlice->Particles()->GetEntries() )
1738 printf(" Bad index n=%d must be 0<n<=%d\n",
1739 n,gAlice->Particles()->GetEntries());
1743 ((TParticle*)(gAlice->Particles()->UncheckedAt(n-1)))->SetBit(Keep_Bit);
1746 //_____________________________________________________________________________
1747 extern "C" void type_of_call rxouth ()
1750 // Called by Gtreve at the end of each primary track
1752 gAlice->FinishPrimary();