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
148 fMC = AliMC::GetMC();
150 //---------------Load detector names
153 strcpy(fDnames[0],"BODY");
154 strcpy(fDnames[1],"NULL");
155 strcpy(fDnames[2],"ITS");
156 strcpy(fDnames[3],"MAG");
157 strcpy(fDnames[4],"TPC");
158 strcpy(fDnames[5],"TOF");
159 strcpy(fDnames[6],"PMD");
160 strcpy(fDnames[7],"PHOS");
161 strcpy(fDnames[8],"ZDC");
162 strcpy(fDnames[9],"FMD");
163 strcpy(fDnames[10],"RICH");
164 strcpy(fDnames[11],"MUON");
165 strcpy(fDnames[12],"FRAME");
166 strcpy(fDnames[13],"TRD");
167 strcpy(fDnames[14],"NULL");
168 strcpy(fDnames[15],"CASTOR");
169 strcpy(fDnames[16],"ABSO");
170 strcpy(fDnames[17],"SHIL");
171 strcpy(fDnames[18],"DIPO");
172 strcpy(fDnames[19],"HALL");
173 strcpy(fDnames[20],"PIPE");
176 // Prepare the tracking medium lists
177 fImedia = new TArrayI(1000);
178 for(i=0;i<1000;i++) (*fImedia)[i]=-99;
181 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
184 //_____________________________________________________________________________
188 // Defaullt AliRun destructor
207 fParticles->Delete();
212 //_____________________________________________________________________________
213 void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
216 // Add a hit to detector id
218 TObjArray &dets = *fModules;
219 if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits);
222 //_____________________________________________________________________________
223 void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
226 // Add digit to detector id
228 TObjArray &dets = *fModules;
229 if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits);
232 //_____________________________________________________________________________
233 void AliRun::Browse(TBrowser *b)
236 // Called when the item "Run" is clicked on the left pane
237 // of the Root browser.
238 // It displays the Root Trees and all detectors.
240 if (fTreeK) b->Add(fTreeK,fTreeK->GetName());
241 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
242 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
243 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
244 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
246 TIter next(fModules);
248 while((detector = (AliModule*)next())) {
249 b->Add(detector,detector->GetName());
253 //_____________________________________________________________________________
257 // Initialize Alice geometry
262 //_____________________________________________________________________________
263 void AliRun::BuildSimpleGeometry()
266 // Create a simple TNode geometry used by Root display engine
268 // Initialise geometry
270 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
271 new TMaterial("void","Vacuum",0,0,0); //Everything is void
272 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
273 brik->SetVisibility(0);
274 new TNode("alice","alice","S_alice");
277 //_____________________________________________________________________________
278 void AliRun::CleanDetectors()
281 // Clean Detectors at the end of event
283 TIter next(fModules);
285 while((detector = (AliModule*)next())) {
286 detector->FinishEvent();
290 //_____________________________________________________________________________
291 void AliRun::CleanParents()
294 // Clean Particles stack.
295 // Set parent/daughter relations
297 TClonesArray &particles = *(gAlice->Particles());
300 for(i=0; i<fNtrack; i++) {
301 part = (TParticle *)particles.UncheckedAt(i);
302 if(!part->TestBit(Daughters_Bit)) {
303 part->SetFirstDaughter(-1);
304 part->SetLastDaughter(-1);
309 //_____________________________________________________________________________
310 Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
313 // Return the distance from the mouse to the AliRun object
319 //_____________________________________________________________________________
320 void AliRun::DumpPart (Int_t i)
323 // Dumps particle i in the stack
325 TClonesArray &particles = *fParticles;
326 ((TParticle*) particles[i])->Print();
329 //_____________________________________________________________________________
330 void AliRun::DumpPStack ()
333 // Dumps the particle stack
335 TClonesArray &particles = *fParticles;
337 "\n\n=======================================================================\n");
338 for (Int_t i=0;i<fNtrack;i++)
340 printf("-> %d ",i); ((TParticle*) particles[i])->Print();
341 printf("--------------------------------------------------------------\n");
344 "\n=======================================================================\n\n");
347 //_____________________________________________________________________________
348 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
349 Float_t maxField, char* filename)
352 // Set magnetic field parameters
353 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
354 // version Magnetic field map version (only 1 active now)
355 // scale Scale factor for the magnetic field
356 // maxField Maximum value for the magnetic field
359 // --- Sanity check on mag field flags
360 if(type<0 || type > 2) {
361 printf(" Invalid magnetic field flag: %5d; Helix tracking chosen instead\n"
365 if(fField) delete fField;
367 fField = new AliMagFC("Map1"," ",type,version,scale,maxField);
368 } else if(version<=3) {
369 fField = new AliMagFCM("Map2-3",filename,type,version,scale,maxField);
372 printf("Invalid map %d\n",version);
376 //_____________________________________________________________________________
377 void AliRun::FillTree()
380 // Fills all AliRun TTrees
382 if (fTreeK) fTreeK->Fill();
383 if (fTreeH) fTreeH->Fill();
384 if (fTreeD) fTreeD->Fill();
385 if (fTreeR) fTreeR->Fill();
388 //_____________________________________________________________________________
389 void AliRun::FinishPrimary()
392 // Called at the end of each primary track
395 // This primary is finished, purify stack
396 gAlice->PurifyKine();
398 // Write out hits if any
399 if (gAlice->TreeH()) {
400 gAlice->TreeH()->Fill();
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(hname);
453 sprintf(hname,"TreeH%d",ievent);
454 if (fTreeH) fTreeH->Write(hname);
455 sprintf(hname,"TreeD%d",ievent);
456 if (fTreeD) fTreeD->Write(hname);
457 sprintf(hname,"TreeR%d",ievent);
458 if (fTreeR) fTreeR->Write(hname);
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
537 AliMC* pMC = AliMC::GetMC();
542 Int_t kn, i, left, j, id;
543 const Float_t zero=0;
544 Int_t ievent=fHeader.GetEvent()+1;
546 // Energy loss information
548 printf("***************** Energy Loss Information per event (GEV) *****************\n");
549 for(kn=1;kn<sEventEnergy.GetSize();kn++) {
552 sEventEnergy[ndep]=kn;
557 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,zero))/ed;
560 sSummEnergy[ndep]=ed;
561 sSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,zero));
566 for(kn=0;kn<(ndep-1)/3+1;kn++) {
568 for(i=0;i<(3<left?3:left);i++) {
570 id=Int_t (sEventEnergy[j]+0.1);
571 printf(" %s %10.3f +- %10.3f%%;",pMC->VolName(id),sSummEnergy[j],sSum2Energy[j]);
576 // Relative energy loss in different detectors
577 printf("******************** Relative Energy Loss per event ********************\n");
578 printf("Total energy loss per event %10.3f GeV\n",edtot);
579 for(kn=0;kn<(ndep-1)/5+1;kn++) {
581 for(i=0;i<(5<left?5:left);i++) {
583 id=Int_t (sEventEnergy[j]+0.1);
584 printf(" %s %10.3f%%;",pMC->VolName(id),100*sSummEnergy[j]/edtot);
588 for(kn=0;kn<75;kn++) printf("*");
592 // Reset the TArray's
598 //_____________________________________________________________________________
599 AliModule *AliRun::GetModule(const char *name)
602 // Return pointer to detector from name
604 return (AliModule*)fModules->FindObject(name);
607 //_____________________________________________________________________________
608 AliDetector *AliRun::GetDetector(const char *name)
611 // Return pointer to detector from name
613 return (AliDetector*)fModules->FindObject(name);
616 //_____________________________________________________________________________
617 Int_t AliRun::GetModuleID(const char *name)
620 // Return galice internal detector identifier from name
623 for(i=0;i<fNdets;i++) if(!strcmp(fDnames[i],name)) {
626 printf(" * GetDetectorID * Detector %s not found: returning -1\n",name);
630 //_____________________________________________________________________________
631 Int_t AliRun::GetEvent(Int_t event)
634 // Connect the Trees Kinematics and Hits for event # event
635 // Set branch addresses
637 fHeader.SetEvent(event);
639 // Reset existing structures
644 // Delete Trees already connected
645 if (fTreeK) delete fTreeK;
646 if (fTreeH) delete fTreeH;
647 if (fTreeD) delete fTreeD;
648 if (fTreeR) delete fTreeR;
650 // Get Kine Tree from file
652 sprintf(treeName,"TreeK%d",event);
653 fTreeK = (TTree*)gDirectory->Get(treeName);
654 if (fTreeK) fTreeK->SetBranchAddress("Particles", &fParticles);
655 else printf("ERROR: cannot find Kine Tree for event:%d\n",event);
657 // Get Hits Tree header from file
658 sprintf(treeName,"TreeH%d",event);
659 fTreeH = (TTree*)gDirectory->Get(treeName);
661 printf("ERROR: cannot find Hits Tree for event:%d\n",event);
665 // Get Digits Tree header from file
666 sprintf(treeName,"TreeD%d",event);
667 fTreeD = (TTree*)gDirectory->Get(treeName);
669 printf("WARNING: cannot find Digits Tree for event:%d\n",event);
673 // Get Reconstruct Tree header from file
674 sprintf(treeName,"TreeR%d",event);
675 fTreeR = (TTree*)gDirectory->Get(treeName);
677 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
680 // Set Trees branch addresses
681 TIter next(fModules);
683 while((detector = (AliModule*)next())) {
684 detector->SetTreeAddress();
687 if (fTreeK) fTreeK->GetEvent(0);
688 fNtrack = Int_t (fParticles->GetEntries());
692 //_____________________________________________________________________________
693 TGeometry *AliRun::GetGeometry()
696 // Import Alice geometry from current file
697 // Return pointer to geometry object
699 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
701 // Unlink and relink nodes in detectors
702 // This is bad and there must be a better way...
704 TList *tnodes=fGeometry->GetListOfNodes();
705 TNode *alice=(TNode*)tnodes->At(0);
706 TList *gnodes=alice->GetListOfNodes();
708 TIter next(fModules);
710 while((detector = (AliModule*)next())) {
711 detector->SetTreeAddress();
712 TList *dnodes=detector->Nodes();
715 for ( j=0; j<dnodes->GetSize(); j++) {
716 node = (TNode*) dnodes->At(j);
717 node1 = (TNode*) gnodes->FindObject(node->GetName());
718 dnodes->Remove(node);
719 dnodes->AddAt(node1,j);
725 //_____________________________________________________________________________
726 void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
727 Float_t &e, Float_t *vpos, Float_t *polar,
731 // Return next track from stack of particles
736 for(Int_t i=fNtrack-1; i>=0; i--) {
737 track=(TParticle*) fParticles->UncheckedAt(i);
738 if(!track->TestBit(Done_Bit)) {
740 // The track has not yet been processed
742 ipart=track->GetPdgCode();
750 pol = track->GetPolarisation();
755 track->SetBit(Done_Bit);
761 // stop and start timer when we start a primary track
762 Int_t nprimaries = fHeader.GetNprimary();
763 if (fCurrent >= nprimaries) return;
764 if (fCurrent < nprimaries-1) {
766 track=(TParticle*) fParticles->UncheckedAt(fCurrent+1);
767 // track->SetProcessTime(fTimer.CpuTime());
772 //_____________________________________________________________________________
773 Int_t AliRun::GetPrimary(Int_t track)
776 // return number of primary that has generated track
784 part = (TParticle *)fParticles->UncheckedAt(current);
785 parent=part->GetFirstMother();
786 if(parent<0) return current;
790 //_____________________________________________________________________________
791 void AliRun::Init(const char *setup)
794 // Initialize the Alice setup
797 gROOT->LoadMacro(setup);
798 gInterpreter->ProcessLine("Config();");
800 AliMC* pMC = AliMC::GetMC();
802 pMC->DefineParticles(); //Create standard MC particles
804 TObject *objfirst, *objlast;
807 //=================Create Materials, geometry, histograms, etc
808 TIter next(fModules);
810 while((detector = (AliModule*)next())) {
811 detector->SetTreeAddress();
812 objlast = gDirectory->GetList()->Last();
814 // Initialise detector materials, geometry, histograms,etc
815 detector->CreateMaterials();
816 detector->CreateGeometry();
817 detector->BuildGeometry();
820 // Add Detector histograms in Detector list of histograms
821 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
822 else objfirst = gDirectory->GetList()->First();
824 detector->Histograms()->Add(objfirst);
825 objfirst = gDirectory->GetList()->After(objfirst);
828 SetTransPar(); //Read the cuts for all materials
830 MediaTable(); //Build the special IMEDIA table
832 //Close the geometry structure
835 //Initialise geometry deposition table
836 sEventEnergy.Set(pMC->NofVolumes()+1);
837 sSummEnergy.Set(pMC->NofVolumes()+1);
838 sSum2Energy.Set(pMC->NofVolumes()+1);
840 //Create the color table
843 //Compute cross-sections
846 //Write Geometry object to current file.
852 //_____________________________________________________________________________
853 void AliRun::MediaTable()
856 // Built media table to get from the media number to
859 Int_t kz, nz, idt, lz, i, k, ind;
861 TObjArray &dets = *gAlice->Detectors();
865 for (kz=0;kz<fNdets;kz++) {
866 // If detector is defined
867 if((det=(AliModule*) dets[kz])) {
868 TArrayI &idtmed = *(det->GetIdtmed());
869 for(nz=0;nz<100;nz++) {
870 // Find max and min material number
871 if((idt=idtmed[nz])) {
872 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
873 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
876 if(det->LoMedium() > det->HiMedium()) {
880 if(det->HiMedium() > fImedia->GetSize()) {
881 Error("MediaTable","Increase fImedia from %d to %d",
882 fImedia->GetSize(),det->HiMedium());
885 // Tag all materials in rage as belonging to detector kz
886 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
893 // Print summary table
894 printf(" Traking media ranges:\n");
895 for(i=0;i<(fNdets-1)/6+1;i++) {
896 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
898 det=(AliModule*)dets[ind];
900 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
903 printf(" %6s: %3d -> %3d;","NULL",0,0);
909 //____________________________________________________________________________
910 void AliRun::SetGenerator(AliGenerator *generator)
913 // Load the event generator
915 if(!fGenerator) fGenerator = generator;
918 //____________________________________________________________________________
919 void AliRun::SetTransPar(char* filename)
922 // Read filename to set the transport parameters
926 AliMC* pMC = AliMC::GetMC();
927 const Int_t ncuts=10;
928 const Int_t nflags=11;
929 const Int_t npars=ncuts+nflags;
930 const char pars[npars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
931 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
932 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
933 "MULS","PAIR","PHOT","RAYL"};
939 Int_t i, itmed, iret, ktmed, kz;
942 // See whether the file is there
943 filtmp=gSystem->ExpandPathName(filename);
944 lun=fopen(filtmp,"r");
947 Warning("SetTransPar","File %s does not exist!\n",filename);
951 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
952 printf(" *%59s\n","*");
953 printf(" * Please check carefully what you are doing!%10s\n","*");
954 printf(" *%59s\n","*");
957 // Initialise cuts and flags
958 for(i=0;i<ncuts;i++) cut[i]=-99;
959 for(i=0;i<nflags;i++) flag[i]=-99;
961 for(i=0;i<256;i++) line[i]='\0';
962 // Read up to the end of line excluded
963 iret=fscanf(lun,"%[^\n]",line);
967 printf(" *%59s\n","*");
968 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
971 // Read the end of line
974 if(line[0]=='*') continue;
976 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",
977 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
978 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
979 &flag[8],&flag[9],&flag[10]);
983 Warning("SetTransPar","Error reading file %s\n",filename);
986 // Check that the module exist
987 AliModule *mod = GetModule(detName);
989 // Get the array of media numbers
990 TArrayI &idtmed = *mod->GetIdtmed();
991 // Check that the tracking medium code is valid
992 if(0<=itmed && itmed < 100) {
995 Warning("SetTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
998 // Set energy thresholds
999 for(kz=0;kz<ncuts;kz++) {
1001 printf(" * %-6s set to %10.3E for tracking medium code %4d %s\n",
1002 pars[kz],cut[kz],itmed,mod->GetName());
1003 pMC->Gstpar(ktmed,pars[kz],cut[kz]);
1006 // Set transport mechanisms
1007 for(kz=0;kz<nflags;kz++) {
1009 printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
1010 pars[ncuts+kz],flag[kz],itmed,mod->GetName());
1011 pMC->Gstpar(ktmed,pars[ncuts+kz],Float_t(flag[kz]));
1015 Warning("SetTransPar","Invalid medium code %d *\n",itmed);
1019 Warning("SetTransPar","Module %s not present\n",detName);
1025 //_____________________________________________________________________________
1026 void AliRun::MakeTree(Option_t *option)
1029 // Create the ROOT trees
1030 // Loop on all detectors to create the Root branch (if any)
1035 char *K = strstr(option,"K");
1036 char *H = strstr(option,"H");
1037 char *E = strstr(option,"E");
1038 char *D = strstr(option,"D");
1039 char *R = strstr(option,"R");
1041 if (K && !fTreeK) fTreeK = new TTree("TK","Kinematics");
1042 if (H && !fTreeH) fTreeH = new TTree("TH","Hits");
1043 if (D && !fTreeD) fTreeD = new TTree("TD","Digits");
1044 if (E && !fTreeE) fTreeE = new TTree("TE","Header");
1045 if (R && !fTreeR) fTreeR = new TTree("TR","Reconstruction");
1046 if (fTreeH) fTreeH->SetAutoSave(1000000000); //no autosave
1048 // Create a branch for hits/digits for each detector
1049 // Each branch is a TClonesArray. Each data member of the Hits classes
1050 // will be in turn a subbranch of the detector master branch
1051 TIter next(fModules);
1052 AliModule *detector;
1053 while((detector = (AliModule*)next())) {
1054 if (H || D || R) detector->MakeBranch(option);
1056 // Create a branch for particles
1057 if (fTreeK && K) fTreeK->Branch("Particles",&fParticles,4000);
1059 // Create a branch for Header
1060 if (fTreeE && E) fTreeE->Branch("Header","AliHeader",&header,4000);
1063 //_____________________________________________________________________________
1064 Int_t AliRun::PurifyKine(Int_t lastSavedTrack, Int_t nofTracks)
1067 // PurifyKine with external parameters
1069 fHgwmk = lastSavedTrack;
1070 fNtrack = nofTracks;
1075 //_____________________________________________________________________________
1076 void AliRun::PurifyKine()
1079 // Compress kinematic tree keeping only flagged particles
1080 // and renaming the particle id's in all the hits
1082 TClonesArray &particles = *fParticles;
1083 int nkeep=fHgwmk+1, parent, i;
1084 TParticle *part, *partnew, *father;
1086 int *map = new int[particles.GetEntries()];
1088 // Save in Header total number of tracks before compression
1089 fHeader.SetNtrack(fHeader.GetNtrack()+fNtrack-fHgwmk);
1091 // Preset map, to be removed later
1092 for(i=0; i<fNtrack; i++) {
1093 if(i<=fHgwmk) map[i]=i ; else map[i] = -99 ;}
1094 // Second pass, build map between old and new numbering
1095 for(i=fHgwmk+1; i<fNtrack; i++) {
1096 part = (TParticle *)particles.UncheckedAt(i);
1097 if(part->TestBit(Keep_Bit)) {
1099 // This particle has to be kept
1103 // Old and new are different, have to copy
1104 partnew = (TParticle *)particles.UncheckedAt(nkeep);
1106 } else partnew = part;
1108 // as the parent is always *before*, it must be already
1109 // in place. This is what we are checking anyway!
1110 if((parent=partnew->GetFirstMother())>fHgwmk) {
1111 if(map[parent]==-99) printf("map[%d] = -99!\n",parent);
1112 partnew->SetFirstMother(map[parent]);
1119 // Fix daughters information
1120 for (i=fHgwmk+1; i<fNtrack; i++) {
1121 part = (TParticle *)particles.UncheckedAt(i);
1122 parent = part->GetFirstMother();
1123 father = (TParticle *)particles.UncheckedAt(parent);
1124 if(father->TestBit(Daughters_Bit)) {
1126 if(i<father->GetFirstDaughter()) father->SetFirstDaughter(i);
1127 if(i>father->GetLastDaughter()) father->SetLastDaughter(i);
1129 // Iitialise daughters info for first pass
1130 father->SetFirstDaughter(i);
1131 father->SetLastDaughter(i);
1132 father->SetBit(Daughters_Bit);
1136 // Now loop on all detectors and reset the hits
1137 TIter next(fModules);
1138 AliModule *detector;
1139 while((detector = (AliModule*)next())) {
1140 if (!detector->Hits()) continue;
1141 TClonesArray &vHits=*(detector->Hits());
1142 if(vHits.GetEntries() != detector->GetNhits())
1143 printf("vHits.GetEntries()!=detector->GetNhits(): %d != %d\n",
1144 vHits.GetEntries(),detector->GetNhits());
1145 for (i=0; i<detector->GetNhits(); i++) {
1146 OneHit = (AliHit *)vHits.UncheckedAt(i);
1147 OneHit->SetTrack(map[OneHit->GetTrack()]);
1152 particles.SetLast(fHgwmk);
1156 //_____________________________________________________________________________
1157 void AliRun::Reset(Int_t run, Int_t idevent)
1160 // Reset all Detectors & kinematics & trees
1166 // Initialise event header
1167 fHeader.Reset(run,idevent);
1169 if(fTreeK) fTreeK->Reset();
1170 if(fTreeH) fTreeH->Reset();
1171 if(fTreeD) fTreeD->Reset();
1174 //_____________________________________________________________________________
1175 void AliRun::ResetDigits()
1178 // Reset all Detectors digits
1180 TIter next(fModules);
1181 AliModule *detector;
1182 while((detector = (AliModule*)next())) {
1183 detector->ResetDigits();
1187 //_____________________________________________________________________________
1188 void AliRun::ResetHits()
1191 // Reset all Detectors hits
1193 TIter next(fModules);
1194 AliModule *detector;
1195 while((detector = (AliModule*)next())) {
1196 detector->ResetHits();
1200 //_____________________________________________________________________________
1201 void AliRun::ResetPoints()
1204 // Reset all Detectors points
1206 TIter next(fModules);
1207 AliModule *detector;
1208 while((detector = (AliModule*)next())) {
1209 detector->ResetPoints();
1213 //_____________________________________________________________________________
1214 void AliRun::Run(Int_t nevent, const char *setup)
1217 // Main function to be called to process a galice run
1219 // Root > gAlice.Run();
1220 // a positive number of events will cause the finish routine
1225 // check if initialisation has been done
1226 if (!fInitDone) Init(setup);
1228 AliMC* pMC = AliMC::GetMC();
1230 // Create the Root Tree with one branch per detector
1232 gAlice->MakeTree("KHDER");
1235 todo = TMath::Abs(nevent);
1236 for (i=0; i<todo; i++) {
1237 // Process one run (one run = one event)
1238 gAlice->Reset(fRun, fEvent);
1242 gAlice->FinishEvent();
1246 // End of this run, close files
1247 if(nevent>0) gAlice->FinishRun();
1250 //_____________________________________________________________________________
1251 void AliRun::RunLego(const char *setup,Int_t ntheta,Float_t themin,
1252 Float_t themax,Int_t nphi,Float_t phimin,Float_t phimax,
1253 Float_t rmin,Float_t rmax,Float_t zmax)
1256 // Generates lego plots of:
1257 // - radiation length map phi vs theta
1258 // - radiation length map phi vs eta
1259 // - interaction length map
1260 // - g/cm2 length map
1262 // ntheta bins in theta, eta
1263 // themin minimum angle in theta (degrees)
1264 // themax maximum angle in theta (degrees)
1266 // phimin minimum angle in phi (degrees)
1267 // phimax maximum angle in phi (degrees)
1268 // rmin minimum radius
1269 // rmax maximum radius
1272 // The number of events generated = ntheta*nphi
1273 // run input parameters in macro setup (default="Config.C")
1275 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1278 <img src="picts/AliRunLego1.gif">
1283 <img src="picts/AliRunLego2.gif">
1288 <img src="picts/AliRunLego3.gif">
1293 // check if initialisation has been done
1294 if (!fInitDone) Init(setup);
1296 fLego = new AliLego("lego","lego");
1297 fLego->Init(ntheta,themin,themax,nphi,phimin,phimax,rmin,rmax,zmax);
1300 // Create only the Root event Tree
1301 gAlice->MakeTree("E");
1303 // End of this run, close files
1304 gAlice->FinishRun();
1307 //_____________________________________________________________________________
1308 void AliRun::SetCurrentTrack(Int_t track)
1311 // Set current track number
1316 //_____________________________________________________________________________
1317 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1318 Float_t *vpos, Float_t *polar, Float_t tof,
1319 const char *mecha, Int_t &ntr, Float_t weight)
1322 // Load a track on the stack
1324 // done 0 if the track has to be transported
1326 // parent identifier of the parent track. -1 for a primary
1327 // pdg particle code
1328 // pmom momentum GeV/c
1330 // polar polarisation
1331 // tof time of flight in seconds
1332 // mecha production mechanism
1333 // ntr on output the number of the track stored
1335 TClonesArray &particles = *fParticles;
1336 TParticle *particle;
1338 const Int_t firstdaughter=-1;
1339 const Int_t lastdaughter=-1;
1341 // const Float_t tlife=0;
1344 // Here we get the static mass
1345 // For MC is ok, but a more sophisticated method could be necessary
1346 // if the calculated mass is required
1347 // also, this method is potentially dangerous if the mass
1348 // used in the MC is not the same of the PDG database
1350 mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
1351 Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+
1352 pmom[1]*pmom[1]+pmom[2]*pmom[2]);
1354 //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",
1355 //pname,mass,e,fNtrack,pdg,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],KS,mecha);
1357 particle=new(particles[fNtrack]) TParticle(pdg,KS,parent,-1,firstdaughter,
1358 lastdaughter,pmom[0],pmom[1],pmom[2],
1359 e,vpos[0],vpos[1],vpos[2],tof);
1360 // polar[0],polar[1],polar[2],tof,
1362 ((TParticle*)particles[fNtrack])->SetPolarisation(TVector3(polar[0],polar[1],polar[2]));
1363 ((TParticle*)particles[fNtrack])->SetWeight(weight);
1364 if(!done) particle->SetBit(Done_Bit);
1367 particle=(TParticle*) fParticles->UncheckedAt(parent);
1368 particle->SetLastDaughter(fNtrack);
1369 if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack);
1372 // This is a primary track. Set high water mark for this event
1375 // Set also number if primary tracks
1376 fHeader.SetNprimary(fHgwmk+1);
1377 fHeader.SetNtrack(fHgwmk+1);
1382 //_____________________________________________________________________________
1383 void AliRun::KeepTrack(const Int_t track)
1386 // flags a track to be kept
1388 TClonesArray &particles = *fParticles;
1389 ((TParticle*)particles[track])->SetBit(Keep_Bit);
1392 //_____________________________________________________________________________
1393 void AliRun::StepManager(Int_t id) const
1396 // Called at every step during transport
1399 AliMC* pMC = AliMC::GetMC();
1403 // --- If lego option, do it and leave
1405 fLego->StepManager();
1408 //Update energy deposition tables
1409 sEventEnergy[pMC->CurrentVol(0,copy)]+=pMC->Edep();
1411 //Call the appropriate stepping routine;
1412 AliModule *det = (AliModule*)fModules->At(id);
1413 if(det) det->StepManager();
1416 //_____________________________________________________________________________
1417 void AliRun::ReadEuclid(const char* filnam, Int_t id_det, const char* topvol)
1420 // read in the geometry of the detector in euclid file format
1422 // id_det : the detector identification (2=its,...)
1423 // topvol : return parameter describing the name of the top
1424 // volume of geometry.
1426 // author : m. maire
1429 // several changes have been made by miroslav helbich
1430 // subroutine is rewrited to follow the new established way of memory
1431 // booking for tracking medias and rotation matrices.
1432 // all used tracking media have to be defined first, for this you can use
1433 // subroutine greutmed.
1434 // top volume is searched as only volume not positioned into another
1437 AliMC* pMC = AliMC::GetMC();
1438 Int_t i, nvol, iret, itmed, irot, numed, npar, ndiv, iaxe;
1439 Int_t ndvmx, nr, flag;
1440 char key[5], card[77], natmed[21];
1441 char name[5], mother[5], shape[5], konly[5], volst[7000][5];
1444 Float_t teta1, phi1, teta2, phi2, teta3, phi3, orig, step;
1446 Int_t idrot[5000],istop[7000];
1450 TObjArray &dets = *fModules;
1452 printf(" *** GREUTMED *** Detector %d not defined\n",id_det);
1455 det = (AliModule*) dets[id_det];
1458 // *** The input filnam name will be with extension '.euc'
1459 filtmp=gSystem->ExpandPathName(filnam);
1460 lun=fopen(filtmp,"r");
1463 printf(" *** GREUCL *** Could not open file %s\n",filnam);
1466 //* --- definition of rotation matrix 0 ---
1467 TArrayI &idtmed = *(det->GetIdtmed());
1471 for(i=0;i<77;i++) card[i]=0;
1472 iret=fscanf(lun,"%77[^\n]",card);
1473 if(iret<=0) goto L20;
1476 strncpy(key,card,4);
1478 if (!strcmp(key,"TMED")) {
1479 sscanf(&card[5],"%d '%[^']'",&itmed,natmed);
1480 //Pad the string with blanks
1483 while(i<20) natmed[i++]=' ';
1486 // pMC->Gckmat(idtmed[itmed+id_det*100-1],natmed);
1487 pMC->Gckmat(idtmed[itmed],natmed);
1489 } else if (!strcmp(key,"ROTM")) {
1490 sscanf(&card[4],"%d %f %f %f %f %f %f",&irot,&teta1,&phi1,&teta2,&phi2,&teta3,&phi3);
1491 det->AliMatrix(idrot[irot],teta1,phi1,teta2,phi2,teta3,phi3);
1493 } else if (!strcmp(key,"VOLU")) {
1494 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, shape, &numed, &npar);
1496 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
1499 pMC->Gsvolu( name, shape, idtmed[numed], par, npar);
1500 //* save the defined volumes
1501 strcpy(volst[++nvol],name);
1504 } else if (!strcmp(key,"DIVN")) {
1505 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, mother, &ndiv, &iaxe);
1506 pMC->Gsdvn ( name, mother, ndiv, iaxe );
1508 } else if (!strcmp(key,"DVN2")) {
1509 sscanf(&card[5],"'%[^']' '%[^']' %d %d %f %d",name, mother, &ndiv, &iaxe, &orig, &numed);
1510 pMC->Gsdvn2( name, mother, ndiv, iaxe, orig,idtmed[numed]);
1512 } else if (!strcmp(key,"DIVT")) {
1513 sscanf(&card[5],"'%[^']' '%[^']' %f %d %d %d", name, mother, &step, &iaxe, &numed, &ndvmx);
1514 pMC->Gsdvt ( name, mother, step, iaxe, idtmed[numed], ndvmx);
1516 } else if (!strcmp(key,"DVT2")) {
1517 sscanf(&card[5],"'%[^']' '%[^']' %f %d %f %d %d", name, mother, &step, &iaxe, &orig, &numed, &ndvmx);
1518 pMC->Gsdvt2 ( name, mother, step, iaxe, orig, idtmed[numed], ndvmx );
1520 } else if (!strcmp(key,"POSI")) {
1521 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']'", name, &nr, mother, &xo, &yo, &zo, &irot, konly);
1522 //*** volume name cannot be the top volume
1523 for(i=1;i<=nvol;i++) {
1524 if (!strcmp(volst[i],name)) istop[i]=0;
1527 pMC->Gspos ( name, nr, mother, xo, yo, zo, idrot[irot], konly );
1529 } else if (!strcmp(key,"POSP")) {
1530 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']' %d", name, &nr, mother, &xo, &yo, &zo, &irot, konly, &npar);
1532 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
1535 //*** volume name cannot be the top volume
1536 for(i=1;i<=nvol;i++) {
1537 if (!strcmp(volst[i],name)) istop[i]=0;
1540 pMC->Gsposp ( name, nr, mother, xo,yo,zo, idrot[irot], konly, par, npar);
1543 if (strcmp(key,"END")) goto L10;
1544 //* find top volume in the geometry
1546 for(i=1;i<=nvol;i++) {
1547 if (istop[i] && flag) {
1548 printf(" *** GREUCL *** warning: %s is another possible top volume\n",volst[i]);
1550 if (istop[i] && !flag) {
1552 printf(" *** GREUCL *** volume %s taken as a top volume\n",topvol);
1557 printf("*** GREUCL *** warning: top volume not found\n");
1561 //* commented out only for the not cernlib version
1562 printf(" *** GREUCL *** file: %s is now read in\n",filnam);
1567 printf(" *** GREUCL *** reading error or premature end of file\n");
1570 //_____________________________________________________________________________
1571 void AliRun::ReadEuclidMedia(const char* filnam, Int_t id_det)
1574 // read in the materials and tracking media for the detector
1575 // in euclid file format
1577 // filnam: name of the input file
1578 // id_det: id_det is the detector identification (2=its,...)
1580 // author : miroslav helbich
1582 Float_t sxmgmx = gAlice->Field()->Max();
1583 Int_t isxfld = gAlice->Field()->Integ();
1584 Int_t end, i, iret, itmed;
1585 char key[5], card[130], natmed[21], namate[21];
1590 Int_t nwbuf, isvol, ifield, nmat;
1591 Float_t a, z, dens, radl, absl, fieldm, tmaxfd, stemax, deemax, epsil, stmin;
1594 TObjArray &dets = *fModules;
1596 printf(" *** GREUTMED *** Detector %d not defined\n",id_det);
1599 det = (AliModule*) dets[id_det];
1602 for(i=0;i<end;i++) if(filnam[i]=='.') {
1607 // *** The input filnam name will be with extension '.euc'
1608 printf("The file name is %s\n",filnam); //Debug
1609 filtmp=gSystem->ExpandPathName(filnam);
1610 lun=fopen(filtmp,"r");
1613 printf(" *** GREUTMED *** Could not open file %s\n",filnam);
1617 // Retrieve Mag Field parameters
1618 Int_t ISXFLD=gAlice->Field()->Integ();
1619 Float_t SXMGMX=gAlice->Field()->Max();
1620 TArrayI &idtmed = *(det->GetIdtmed());
1623 for(i=0;i<130;i++) card[i]=0;
1624 iret=fscanf(lun,"%4s %[^\n]",key,card);
1625 if(iret<=0) goto L20;
1629 if (!strcmp(key,"MATE")) {
1630 sscanf(card,"%d '%[^']' %f %f %f %f %f %d",&imate,namate,&a,&z,&dens,&radl,&absl,&nwbuf);
1631 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
1632 //Pad the string with blanks
1635 while(i<20) namate[i++]=' ';
1638 det->AliMaterial(imate,namate,a,z,dens,radl,absl,ubuf,nwbuf);
1639 //* read tracking medium
1640 } else if (!strcmp(key,"TMED")) {
1641 sscanf(card,"%d '%[^']' %d %d %d %f %f %f %f %f %f %d",
1642 &itmed,natmed,&nmat,&isvol,&ifield,&fieldm,&tmaxfd,
1643 &stemax,&deemax,&epsil,&stmin,&nwbuf);
1644 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
1645 if (ifield<0) ifield=isxfld;
1646 if (fieldm<0) fieldm=sxmgmx;
1647 //Pad the string with blanks
1650 while(i<20) natmed[i++]=' ';
1653 det->AliMedium(itmed,natmed,nmat,isvol,ISXFLD,SXMGMX,tmaxfd,
1654 stemax,deemax,epsil,stmin,ubuf,nwbuf);
1655 (*fImedia)[idtmed[itmed]-1]=id_det;
1659 if (strcmp(key,"END")) goto L10;
1662 //* commented out only for the not cernlib version
1663 printf(" *** GREUTMED *** file: %s is now read in\n",filnam);
1668 printf(" *** GREUTMED *** reading error or premature end of file\n");
1671 //_____________________________________________________________________________
1672 void AliRun::Streamer(TBuffer &R__b)
1675 // Stream an object of class AliRun.
1677 if (R__b.IsReading()) {
1678 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1679 TNamed::Streamer(R__b);
1680 if (!gAlice) gAlice = this;
1681 gROOT->GetListOfBrowsables()->Add(this,"Run");
1685 fHeader.Streamer(R__b);
1694 R__b >> fPDGDB; //Particle factory object!
1696 R__b.WriteVersion(AliRun::IsA());
1697 TNamed::Streamer(R__b);
1701 fHeader.Streamer(R__b);
1710 R__b << fPDGDB; //Particle factory object!
1715 //_____________________________________________________________________________
1717 // Interfaces to Fortran
1719 //_____________________________________________________________________________
1721 extern "C" void type_of_call rxgtrak (Int_t &mtrack, Int_t &ipart, Float_t *pmom,
1722 Float_t &e, Float_t *vpos, Float_t &tof)
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
1739 gAlice->GetNextTrack(mtrack, pdg, pmom, e, vpos, polar, tof);
1740 ipart = gMC->IdFromPDG(pdg);
1744 //_____________________________________________________________________________
1745 extern "C" void type_of_call
1747 rxstrak (Int_t &keep, Int_t &parent, Int_t &ipart, Float_t *pmom,
1748 Float_t *vpos, Float_t &tof, const char* cmech, Int_t &ntr, const int cmlen)
1750 rxstrak (Int_t &keep, Int_t &parent, Int_t &ipart, Float_t *pmom,
1751 Float_t *vpos, Float_t &tof, const char* cmech, const int cmlen,
1756 // Fetches next track from the ROOT stack for transport. Called by GUKINE
1759 // Status of the track. If keep=0 the track is put
1760 // keep on the ROOT stack but it is not fetched for
1762 // parent Parent track. If parent=0 the track is a primary.
1763 // In GUSTEP the routine is normally called to store
1764 // secondaries generated by the current track whose
1765 // ROOT stack number is MTRACK (common SCKINE.
1766 // ipart Particle code in the GEANT conventions.
1767 // pmom[3] Particle momentum in GeV/c
1768 // vpos[3] Particle position
1769 // tof Particle time of flight in seconds
1771 // cmech (CHARACTER*10) Particle origin. This field is user
1772 // defined and it is not used inside the GALICE code.
1773 // ntr Number assigned to the particle in the ROOT stack.
1776 Float_t polar[3]={0.,0.,0.};
1777 for(int i=0; i<10 && i<cmlen; i++) mecha[i]=cmech[i];
1779 Int_t pdg=gMC->PDGFromId(ipart);
1780 gAlice->SetTrack(keep, parent-1, pdg, pmom, vpos, polar, tof, mecha, ntr);
1784 //_____________________________________________________________________________
1785 extern "C" void type_of_call rxkeep(const Int_t &n)
1787 if( NULL==gAlice ) exit(1);
1789 if( n<=0 || n>gAlice->Particles()->GetEntries() )
1791 printf(" Bad index n=%d must be 0<n<=%d\n",
1792 n,gAlice->Particles()->GetEntries());
1796 ((TParticle*)(gAlice->Particles()->UncheckedAt(n-1)))->SetBit(Keep_Bit);
1799 //_____________________________________________________________________________
1800 extern "C" void type_of_call rxouth ()
1803 // Called by Gtreve at the end of each primary track
1805 gAlice->FinishPrimary();