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) {
362 "Invalid magnetic field flag: %5d; Helix tracking chosen instead\n"
366 if(fField) delete fField;
368 fField = new AliMagFC("Map1"," ",type,version,scale,maxField);
369 } else if(version<=3) {
370 fField = new AliMagFCM("Map2-3",filename,type,version,scale,maxField);
373 Warning("SetField","Invalid map %d\n",version);
377 //_____________________________________________________________________________
378 void AliRun::FillTree()
381 // Fills all AliRun TTrees
383 if (fTreeK) fTreeK->Fill();
384 if (fTreeH) fTreeH->Fill();
385 if (fTreeD) fTreeD->Fill();
386 if (fTreeR) fTreeR->Fill();
389 //_____________________________________________________________________________
390 void AliRun::FinishPrimary()
393 // Called at the end of each primary track
396 // This primary is finished, purify stack
397 gAlice->PurifyKine();
399 // Write out hits if any
400 if (gAlice->TreeH()) {
401 gAlice->TreeH()->Fill();
408 //_____________________________________________________________________________
409 void AliRun::FinishEvent()
412 // Called at the end of the event.
415 //Update the energy deposit tables
417 for(i=0;i<sEventEnergy.GetSize();i++) {
418 sSummEnergy[i]+=sEventEnergy[i];
419 sSum2Energy[i]+=sEventEnergy[i]*sEventEnergy[i];
421 sEventEnergy.Reset();
423 // Clean detector information
426 // Write out the kinematics
432 // Write out the digits
438 // Write out reconstructed clusters
443 // Write out the event Header information
444 if (fTreeE) fTreeE->Fill();
449 // Write Tree headers
450 Int_t ievent = fHeader.GetEvent();
452 sprintf(hname,"TreeK%d",ievent);
453 if (fTreeK) fTreeK->Write(hname);
454 sprintf(hname,"TreeH%d",ievent);
455 if (fTreeH) fTreeH->Write(hname);
456 sprintf(hname,"TreeD%d",ievent);
457 if (fTreeD) fTreeD->Write(hname);
458 sprintf(hname,"TreeR%d",ievent);
459 if (fTreeR) fTreeR->Write(hname);
462 //_____________________________________________________________________________
463 void AliRun::FinishRun()
466 // Called at the end of the run.
469 // Clean detector information
470 TIter next(fModules);
472 while((detector = (AliModule*)next())) {
473 detector->FinishRun();
476 //Output energy summary tables
479 // file is retrieved from whatever tree
481 if (fTreeK) File = fTreeK->GetCurrentFile();
482 if ((!File) && (fTreeH)) File = fTreeH->GetCurrentFile();
483 if ((!File) && (fTreeD)) File = fTreeD->GetCurrentFile();
484 if ((!File) && (fTreeE)) File = fTreeE->GetCurrentFile();
486 Error("FinishRun","There isn't root file!");
492 // Clean tree information
493 delete fTreeK; fTreeK = 0;
494 delete fTreeH; fTreeH = 0;
495 delete fTreeD; fTreeD = 0;
496 delete fTreeR; fTreeR = 0;
497 delete fTreeE; fTreeE = 0;
499 // Write AliRun info and all detectors parameters
507 //_____________________________________________________________________________
508 void AliRun::FlagTrack(Int_t track)
511 // Flags a track and all its family tree to be kept
518 particle=(TParticle*)fParticles->UncheckedAt(curr);
520 // If the particle is flagged the three from here upward is saved already
521 if(particle->TestBit(Keep_Bit)) return;
523 // Save this particle
524 particle->SetBit(Keep_Bit);
526 // Move to father if any
527 if((curr=particle->GetFirstMother())==-1) return;
531 //_____________________________________________________________________________
532 void AliRun::EnergySummary()
535 // Print summary of deposited energy
538 AliMC* pMC = AliMC::GetMC();
543 Int_t kn, i, left, j, id;
544 const Float_t zero=0;
545 Int_t ievent=fHeader.GetEvent()+1;
547 // Energy loss information
549 printf("***************** Energy Loss Information per event (GEV) *****************\n");
550 for(kn=1;kn<sEventEnergy.GetSize();kn++) {
553 sEventEnergy[ndep]=kn;
558 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,zero))/ed;
561 sSummEnergy[ndep]=ed;
562 sSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,zero));
567 for(kn=0;kn<(ndep-1)/3+1;kn++) {
569 for(i=0;i<(3<left?3:left);i++) {
571 id=Int_t (sEventEnergy[j]+0.1);
572 printf(" %s %10.3f +- %10.3f%%;",pMC->VolName(id),sSummEnergy[j],sSum2Energy[j]);
577 // Relative energy loss in different detectors
578 printf("******************** Relative Energy Loss per event ********************\n");
579 printf("Total energy loss per event %10.3f GeV\n",edtot);
580 for(kn=0;kn<(ndep-1)/5+1;kn++) {
582 for(i=0;i<(5<left?5:left);i++) {
584 id=Int_t (sEventEnergy[j]+0.1);
585 printf(" %s %10.3f%%;",pMC->VolName(id),100*sSummEnergy[j]/edtot);
589 for(kn=0;kn<75;kn++) printf("*");
593 // Reset the TArray's
599 //_____________________________________________________________________________
600 AliModule *AliRun::GetModule(const char *name)
603 // Return pointer to detector from name
605 return (AliModule*)fModules->FindObject(name);
608 //_____________________________________________________________________________
609 AliDetector *AliRun::GetDetector(const char *name)
612 // Return pointer to detector from name
614 return (AliDetector*)fModules->FindObject(name);
617 //_____________________________________________________________________________
618 Int_t AliRun::GetModuleID(const char *name)
621 // Return galice internal detector identifier from name
624 TObject *mod=fModules->FindObject(name);
625 if(mod) i=fModules->IndexOf(mod);
629 //_____________________________________________________________________________
630 Int_t AliRun::GetEvent(Int_t event)
633 // Connect the Trees Kinematics and Hits for event # event
634 // Set branch addresses
636 fHeader.SetEvent(event);
638 // Reset existing structures
643 // Delete Trees already connected
644 if (fTreeK) delete fTreeK;
645 if (fTreeH) delete fTreeH;
646 if (fTreeD) delete fTreeD;
647 if (fTreeR) delete fTreeR;
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 printf("WARNING: 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...
702 TList *tnodes=fGeometry->GetListOfNodes();
703 TNode *alice=(TNode*)tnodes->At(0);
704 TList *gnodes=alice->GetListOfNodes();
706 TIter next(fModules);
708 while((detector = (AliModule*)next())) {
709 detector->SetTreeAddress();
710 TList *dnodes=detector->Nodes();
713 for ( j=0; j<dnodes->GetSize(); j++) {
714 node = (TNode*) dnodes->At(j);
715 node1 = (TNode*) gnodes->FindObject(node->GetName());
716 dnodes->Remove(node);
717 dnodes->AddAt(node1,j);
723 //_____________________________________________________________________________
724 void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
725 Float_t &e, Float_t *vpos, Float_t *polar,
729 // Return next track from stack of particles
734 for(Int_t i=fNtrack-1; i>=0; i--) {
735 track=(TParticle*) fParticles->UncheckedAt(i);
736 if(!track->TestBit(Done_Bit)) {
738 // The track has not yet been processed
740 ipart=track->GetPdgCode();
748 pol = track->GetPolarisation();
753 track->SetBit(Done_Bit);
759 // stop and start timer when we start a primary track
760 Int_t nprimaries = fHeader.GetNprimary();
761 if (fCurrent >= nprimaries) return;
762 if (fCurrent < nprimaries-1) {
764 track=(TParticle*) fParticles->UncheckedAt(fCurrent+1);
765 // track->SetProcessTime(fTimer.CpuTime());
770 //_____________________________________________________________________________
771 Int_t AliRun::GetPrimary(Int_t track)
774 // return number of primary that has generated track
782 part = (TParticle *)fParticles->UncheckedAt(current);
783 parent=part->GetFirstMother();
784 if(parent<0) return current;
788 //_____________________________________________________________________________
789 void AliRun::Init(const char *setup)
792 // Initialize the Alice setup
795 gROOT->LoadMacro(setup);
796 gInterpreter->ProcessLine("Config();");
798 AliMC* pMC = AliMC::GetMC();
800 pMC->DefineParticles(); //Create standard MC particles
802 TObject *objfirst, *objlast;
804 fNdets = fModules->GetLast()+1;
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 for %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();
1172 if(fTreeR) fTreeR->Reset();
1175 //_____________________________________________________________________________
1176 void AliRun::ResetDigits()
1179 // Reset all Detectors digits
1181 TIter next(fModules);
1182 AliModule *detector;
1183 while((detector = (AliModule*)next())) {
1184 detector->ResetDigits();
1188 //_____________________________________________________________________________
1189 void AliRun::ResetHits()
1192 // Reset all Detectors hits
1194 TIter next(fModules);
1195 AliModule *detector;
1196 while((detector = (AliModule*)next())) {
1197 detector->ResetHits();
1201 //_____________________________________________________________________________
1202 void AliRun::ResetPoints()
1205 // Reset all Detectors points
1207 TIter next(fModules);
1208 AliModule *detector;
1209 while((detector = (AliModule*)next())) {
1210 detector->ResetPoints();
1214 //_____________________________________________________________________________
1215 void AliRun::Run(Int_t nevent, const char *setup)
1218 // Main function to be called to process a galice run
1220 // Root > gAlice.Run();
1221 // a positive number of events will cause the finish routine
1226 // check if initialisation has been done
1227 if (!fInitDone) Init(setup);
1229 AliMC* pMC = AliMC::GetMC();
1231 // Create the Root Tree with one branch per detector
1233 gAlice->MakeTree("KHDER");
1236 todo = TMath::Abs(nevent);
1237 for (i=0; i<todo; i++) {
1238 // Process one run (one run = one event)
1239 gAlice->Reset(fRun, fEvent);
1243 gAlice->FinishEvent();
1247 // End of this run, close files
1248 if(nevent>0) gAlice->FinishRun();
1251 //_____________________________________________________________________________
1252 void AliRun::RunLego(const char *setup,Int_t ntheta,Float_t themin,
1253 Float_t themax,Int_t nphi,Float_t phimin,Float_t phimax,
1254 Float_t rmin,Float_t rmax,Float_t zmax)
1257 // Generates lego plots of:
1258 // - radiation length map phi vs theta
1259 // - radiation length map phi vs eta
1260 // - interaction length map
1261 // - g/cm2 length map
1263 // ntheta bins in theta, eta
1264 // themin minimum angle in theta (degrees)
1265 // themax maximum angle in theta (degrees)
1267 // phimin minimum angle in phi (degrees)
1268 // phimax maximum angle in phi (degrees)
1269 // rmin minimum radius
1270 // rmax maximum radius
1273 // The number of events generated = ntheta*nphi
1274 // run input parameters in macro setup (default="Config.C")
1276 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1279 <img src="picts/AliRunLego1.gif">
1284 <img src="picts/AliRunLego2.gif">
1289 <img src="picts/AliRunLego3.gif">
1294 // check if initialisation has been done
1295 if (!fInitDone) Init(setup);
1297 fLego = new AliLego("lego","lego");
1298 fLego->Init(ntheta,themin,themax,nphi,phimin,phimax,rmin,rmax,zmax);
1301 // Create only the Root event Tree
1302 gAlice->MakeTree("E");
1304 // End of this run, close files
1305 gAlice->FinishRun();
1308 //_____________________________________________________________________________
1309 void AliRun::SetCurrentTrack(Int_t track)
1312 // Set current track number
1317 //_____________________________________________________________________________
1318 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1319 Float_t *vpos, Float_t *polar, Float_t tof,
1320 const char *mecha, Int_t &ntr, Float_t weight)
1323 // Load a track on the stack
1325 // done 0 if the track has to be transported
1327 // parent identifier of the parent track. -1 for a primary
1328 // pdg particle code
1329 // pmom momentum GeV/c
1331 // polar polarisation
1332 // tof time of flight in seconds
1333 // mecha production mechanism
1334 // ntr on output the number of the track stored
1336 TClonesArray &particles = *fParticles;
1337 TParticle *particle;
1339 const Int_t firstdaughter=-1;
1340 const Int_t lastdaughter=-1;
1342 // const Float_t tlife=0;
1345 // Here we get the static mass
1346 // For MC is ok, but a more sophisticated method could be necessary
1347 // if the calculated mass is required
1348 // also, this method is potentially dangerous if the mass
1349 // used in the MC is not the same of the PDG database
1351 mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
1352 Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+
1353 pmom[1]*pmom[1]+pmom[2]*pmom[2]);
1355 //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",
1356 //pname,mass,e,fNtrack,pdg,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],KS,mecha);
1358 particle=new(particles[fNtrack]) TParticle(pdg,KS,parent,-1,firstdaughter,
1359 lastdaughter,pmom[0],pmom[1],pmom[2],
1360 e,vpos[0],vpos[1],vpos[2],tof);
1361 // polar[0],polar[1],polar[2],tof,
1363 ((TParticle*)particles[fNtrack])->SetPolarisation(TVector3(polar[0],polar[1],polar[2]));
1364 ((TParticle*)particles[fNtrack])->SetWeight(weight);
1365 if(!done) particle->SetBit(Done_Bit);
1368 particle=(TParticle*) fParticles->UncheckedAt(parent);
1369 particle->SetLastDaughter(fNtrack);
1370 if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack);
1373 // This is a primary track. Set high water mark for this event
1376 // Set also number if primary tracks
1377 fHeader.SetNprimary(fHgwmk+1);
1378 fHeader.SetNtrack(fHgwmk+1);
1383 //_____________________________________________________________________________
1384 void AliRun::KeepTrack(const Int_t track)
1387 // flags a track to be kept
1389 TClonesArray &particles = *fParticles;
1390 ((TParticle*)particles[track])->SetBit(Keep_Bit);
1393 //_____________________________________________________________________________
1394 void AliRun::StepManager(Int_t id) const
1397 // Called at every step during transport
1400 AliMC* pMC = AliMC::GetMC();
1404 // --- If lego option, do it and leave
1406 fLego->StepManager();
1409 //Update energy deposition tables
1410 sEventEnergy[pMC->CurrentVol(0,copy)]+=pMC->Edep();
1412 //Call the appropriate stepping routine;
1413 AliModule *det = (AliModule*)fModules->At(id);
1414 if(det) det->StepManager();
1417 //_____________________________________________________________________________
1418 void AliRun::ReadEuclid(const char* filnam, const AliModule *det, const char* topvol)
1421 // read in the geometry of the detector in euclid file format
1423 // id_det : the detector identification (2=its,...)
1424 // topvol : return parameter describing the name of the top
1425 // volume of geometry.
1427 // author : m. maire
1430 // several changes have been made by miroslav helbich
1431 // subroutine is rewrited to follow the new established way of memory
1432 // booking for tracking medias and rotation matrices.
1433 // all used tracking media have to be defined first, for this you can use
1434 // subroutine greutmed.
1435 // top volume is searched as only volume not positioned into another
1438 AliMC* pMC = AliMC::GetMC();
1439 Int_t i, nvol, iret, itmed, irot, numed, npar, ndiv, iaxe;
1440 Int_t ndvmx, nr, flag;
1441 char key[5], card[77], natmed[21];
1442 char name[5], mother[5], shape[5], konly[5], volst[7000][5];
1445 Float_t teta1, phi1, teta2, phi2, teta3, phi3, orig, step;
1447 Int_t idrot[5000],istop[7000];
1450 // *** The input filnam name will be with extension '.euc'
1451 filtmp=gSystem->ExpandPathName(filnam);
1452 lun=fopen(filtmp,"r");
1455 printf(" *** GREUCL *** Could not open file %s\n",filnam);
1458 //* --- definition of rotation matrix 0 ---
1459 TArrayI &idtmed = *(det->GetIdtmed());
1463 for(i=0;i<77;i++) card[i]=0;
1464 iret=fscanf(lun,"%77[^\n]",card);
1465 if(iret<=0) goto L20;
1468 strncpy(key,card,4);
1470 if (!strcmp(key,"TMED")) {
1471 sscanf(&card[5],"%d '%[^']'",&itmed,natmed);
1472 //Pad the string with blanks
1475 while(i<20) natmed[i++]=' ';
1478 pMC->Gckmat(idtmed[itmed],natmed);
1480 } else if (!strcmp(key,"ROTM")) {
1481 sscanf(&card[4],"%d %f %f %f %f %f %f",&irot,&teta1,&phi1,&teta2,&phi2,&teta3,&phi3);
1482 det->AliMatrix(idrot[irot],teta1,phi1,teta2,phi2,teta3,phi3);
1484 } else if (!strcmp(key,"VOLU")) {
1485 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, shape, &numed, &npar);
1487 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
1490 pMC->Gsvolu( name, shape, idtmed[numed], par, npar);
1491 //* save the defined volumes
1492 strcpy(volst[++nvol],name);
1495 } else if (!strcmp(key,"DIVN")) {
1496 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, mother, &ndiv, &iaxe);
1497 pMC->Gsdvn ( name, mother, ndiv, iaxe );
1499 } else if (!strcmp(key,"DVN2")) {
1500 sscanf(&card[5],"'%[^']' '%[^']' %d %d %f %d",name, mother, &ndiv, &iaxe, &orig, &numed);
1501 pMC->Gsdvn2( name, mother, ndiv, iaxe, orig,idtmed[numed]);
1503 } else if (!strcmp(key,"DIVT")) {
1504 sscanf(&card[5],"'%[^']' '%[^']' %f %d %d %d", name, mother, &step, &iaxe, &numed, &ndvmx);
1505 pMC->Gsdvt ( name, mother, step, iaxe, idtmed[numed], ndvmx);
1507 } else if (!strcmp(key,"DVT2")) {
1508 sscanf(&card[5],"'%[^']' '%[^']' %f %d %f %d %d", name, mother, &step, &iaxe, &orig, &numed, &ndvmx);
1509 pMC->Gsdvt2 ( name, mother, step, iaxe, orig, idtmed[numed], ndvmx );
1511 } else if (!strcmp(key,"POSI")) {
1512 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']'", name, &nr, mother, &xo, &yo, &zo, &irot, konly);
1513 //*** volume name cannot be the top volume
1514 for(i=1;i<=nvol;i++) {
1515 if (!strcmp(volst[i],name)) istop[i]=0;
1518 pMC->Gspos ( name, nr, mother, xo, yo, zo, idrot[irot], konly );
1520 } else if (!strcmp(key,"POSP")) {
1521 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']' %d", name, &nr, mother, &xo, &yo, &zo, &irot, konly, &npar);
1523 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
1526 //*** volume name cannot be the top volume
1527 for(i=1;i<=nvol;i++) {
1528 if (!strcmp(volst[i],name)) istop[i]=0;
1531 pMC->Gsposp ( name, nr, mother, xo,yo,zo, idrot[irot], konly, par, npar);
1534 if (strcmp(key,"END")) goto L10;
1535 //* find top volume in the geometry
1537 for(i=1;i<=nvol;i++) {
1538 if (istop[i] && flag) {
1539 printf(" *** GREUCL *** warning: %s is another possible top volume\n",volst[i]);
1541 if (istop[i] && !flag) {
1543 printf(" *** GREUCL *** volume %s taken as a top volume\n",topvol);
1548 printf("*** GREUCL *** warning: top volume not found\n");
1552 //* commented out only for the not cernlib version
1553 printf(" *** GREUCL *** file: %s is now read in\n",filnam);
1558 printf(" *** GREUCL *** reading error or premature end of file\n");
1561 //_____________________________________________________________________________
1562 void AliRun::ReadEuclidMedia(const char* filnam, const AliModule *det)
1565 // read in the materials and tracking media for the detector
1566 // in euclid file format
1568 // filnam: name of the input file
1569 // id_det: id_det is the detector identification (2=its,...)
1571 // author : miroslav helbich
1573 Float_t sxmgmx = gAlice->Field()->Max();
1574 Int_t isxfld = gAlice->Field()->Integ();
1575 Int_t end, i, iret, itmed;
1576 char key[5], card[130], natmed[21], namate[21];
1581 Int_t nwbuf, isvol, ifield, nmat;
1582 Float_t a, z, dens, radl, absl, fieldm, tmaxfd, stemax, deemax, epsil, stmin;
1585 for(i=0;i<end;i++) if(filnam[i]=='.') {
1590 // *** The input filnam name will be with extension '.euc'
1591 printf("The file name is %s\n",filnam); //Debug
1592 filtmp=gSystem->ExpandPathName(filnam);
1593 lun=fopen(filtmp,"r");
1596 Warning("ReadEuclidMedia","Could not open file %s\n",filnam);
1600 // Retrieve Mag Field parameters
1601 Int_t ISXFLD=gAlice->Field()->Integ();
1602 Float_t SXMGMX=gAlice->Field()->Max();
1603 // TArrayI &idtmed = *(det->GetIdtmed());
1606 for(i=0;i<130;i++) card[i]=0;
1607 iret=fscanf(lun,"%4s %[^\n]",key,card);
1608 if(iret<=0) goto L20;
1612 if (!strcmp(key,"MATE")) {
1613 sscanf(card,"%d '%[^']' %f %f %f %f %f %d",&imate,namate,&a,&z,&dens,&radl,&absl,&nwbuf);
1614 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
1615 //Pad the string with blanks
1618 while(i<20) namate[i++]=' ';
1621 det->AliMaterial(imate,namate,a,z,dens,radl,absl,ubuf,nwbuf);
1622 //* read tracking medium
1623 } else if (!strcmp(key,"TMED")) {
1624 sscanf(card,"%d '%[^']' %d %d %d %f %f %f %f %f %f %d",
1625 &itmed,natmed,&nmat,&isvol,&ifield,&fieldm,&tmaxfd,
1626 &stemax,&deemax,&epsil,&stmin,&nwbuf);
1627 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
1628 if (ifield<0) ifield=isxfld;
1629 if (fieldm<0) fieldm=sxmgmx;
1630 //Pad the string with blanks
1633 while(i<20) natmed[i++]=' ';
1636 det->AliMedium(itmed,natmed,nmat,isvol,ISXFLD,SXMGMX,tmaxfd,
1637 stemax,deemax,epsil,stmin,ubuf,nwbuf);
1638 // (*fImedia)[idtmed[itmed]-1]=id_det;
1642 if (strcmp(key,"END")) goto L10;
1645 //* commented out only for the not cernlib version
1646 Warning("ReadEuclidMedia","file: %s is now read in\n",filnam);
1651 Warning("ReadEuclidMedia","reading error or premature end of file\n");
1654 //_____________________________________________________________________________
1655 void AliRun::Streamer(TBuffer &R__b)
1658 // Stream an object of class AliRun.
1660 if (R__b.IsReading()) {
1661 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1662 TNamed::Streamer(R__b);
1663 if (!gAlice) gAlice = this;
1664 gROOT->GetListOfBrowsables()->Add(this,"Run");
1668 fHeader.Streamer(R__b);
1677 R__b >> fPDGDB; //Particle factory object!
1679 R__b.WriteVersion(AliRun::IsA());
1680 TNamed::Streamer(R__b);
1684 fHeader.Streamer(R__b);
1693 R__b << fPDGDB; //Particle factory object!
1698 //_____________________________________________________________________________
1700 // Interfaces to Fortran
1702 //_____________________________________________________________________________
1704 extern "C" void type_of_call rxgtrak (Int_t &mtrack, Int_t &ipart, Float_t *pmom,
1705 Float_t &e, Float_t *vpos, Float_t &tof)
1708 // Fetches next track from the ROOT stack for transport. Called by the
1709 // modified version of GTREVE.
1711 // Track number in the ROOT stack. If MTRACK=0 no
1712 // mtrack more tracks are left in the stack to be
1714 // ipart Particle code in the GEANT conventions.
1715 // pmom[3] Particle momentum in GeV/c
1716 // e Particle energy in GeV
1717 // vpos[3] Particle position
1718 // tof Particle time of flight in seconds
1722 gAlice->GetNextTrack(mtrack, pdg, pmom, e, vpos, polar, tof);
1723 ipart = gMC->IdFromPDG(pdg);
1727 //_____________________________________________________________________________
1728 extern "C" void type_of_call
1730 rxstrak (Int_t &keep, Int_t &parent, Int_t &ipart, Float_t *pmom,
1731 Float_t *vpos, Float_t &tof, const char* cmech, Int_t &ntr, const int cmlen)
1733 rxstrak (Int_t &keep, Int_t &parent, Int_t &ipart, Float_t *pmom,
1734 Float_t *vpos, Float_t &tof, const char* cmech, const int cmlen,
1739 // Fetches next track from the ROOT stack for transport. Called by GUKINE
1742 // Status of the track. If keep=0 the track is put
1743 // keep on the ROOT stack but it is not fetched for
1745 // parent Parent track. If parent=0 the track is a primary.
1746 // In GUSTEP the routine is normally called to store
1747 // secondaries generated by the current track whose
1748 // ROOT stack number is MTRACK (common SCKINE.
1749 // ipart Particle code in the GEANT conventions.
1750 // pmom[3] Particle momentum in GeV/c
1751 // vpos[3] Particle position
1752 // tof Particle time of flight in seconds
1754 // cmech (CHARACTER*10) Particle origin. This field is user
1755 // defined and it is not used inside the GALICE code.
1756 // ntr Number assigned to the particle in the ROOT stack.
1759 Float_t polar[3]={0.,0.,0.};
1760 for(int i=0; i<10 && i<cmlen; i++) mecha[i]=cmech[i];
1762 Int_t pdg=gMC->PDGFromId(ipart);
1763 gAlice->SetTrack(keep, parent-1, pdg, pmom, vpos, polar, tof, mecha, ntr);
1767 //_____________________________________________________________________________
1768 extern "C" void type_of_call rxkeep(const Int_t &n)
1770 if( NULL==gAlice ) exit(1);
1772 if( n<=0 || n>gAlice->Particles()->GetEntries() )
1774 printf(" Bad index n=%d must be 0<n<=%d\n",
1775 n,gAlice->Particles()->GetEntries());
1779 ((TParticle*)(gAlice->Particles()->UncheckedAt(n-1)))->SetBit(Keep_Bit);
1782 //_____________________________________________________________________________
1783 extern "C" void type_of_call rxouth ()
1786 // Called by Gtreve at the end of each primary track
1788 gAlice->FinishPrimary();