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
96 fPDGDB = 0; //Particle factory object!
99 //_____________________________________________________________________________
100 AliRun::AliRun(const char *name, const char *title)
104 // Constructor for the main processor.
105 // Creates the geometry
106 // Creates the list of Detectors.
107 // Creates the list of particles.
124 gROOT->GetListOfBrowsables()->Add(this,name);
126 // create the support list for the various Detectors
127 fModules = new TObjArray(77);
129 // Create the TNode geometry for the event display
131 BuildSimpleGeometry();
141 // Create the particle stack
142 fParticles = new TClonesArray("TParticle",100);
146 // Create default mag field
149 fMC = AliMC::GetMC();
151 //---------------Load detector names
154 strcpy(fDnames[0],"BODY");
155 strcpy(fDnames[1],"NULL");
156 strcpy(fDnames[2],"ITS");
157 strcpy(fDnames[3],"MAG");
158 strcpy(fDnames[4],"TPC");
159 strcpy(fDnames[5],"TOF");
160 strcpy(fDnames[6],"PMD");
161 strcpy(fDnames[7],"PHOS");
162 strcpy(fDnames[8],"ZDC");
163 strcpy(fDnames[9],"FMD");
164 strcpy(fDnames[10],"RICH");
165 strcpy(fDnames[11],"MUON");
166 strcpy(fDnames[12],"FRAME");
167 strcpy(fDnames[13],"TRD");
168 strcpy(fDnames[14],"NULL");
169 strcpy(fDnames[15],"CASTOR");
170 strcpy(fDnames[16],"ABSO");
171 strcpy(fDnames[17],"SHIL");
172 strcpy(fDnames[18],"DIPO");
173 strcpy(fDnames[19],"HALL");
174 strcpy(fDnames[20],"PIPE");
177 // Prepare the tracking medium lists
178 fImedia = new TArrayI(1000);
179 for(i=0;i<1000;i++) (*fImedia)[i]=-99;
180 fIdtmed = new Int_t[fNdets*100];
181 for(i=0;i<fNdets*100;i++) fIdtmed[i]=0;
184 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
187 //_____________________________________________________________________________
191 // Defaullt AliRun destructor
211 fParticles->Delete();
216 //_____________________________________________________________________________
217 void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
220 // Add a hit to detector id
222 TObjArray &dets = *fModules;
223 if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits);
226 //_____________________________________________________________________________
227 void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
230 // Add digit to detector id
232 TObjArray &dets = *fModules;
233 if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits);
236 //_____________________________________________________________________________
237 void AliRun::Browse(TBrowser *b)
240 // Called when the item "Run" is clicked on the left pane
241 // of the Root browser.
242 // It displays the Root Trees and all detectors.
244 if (fTreeK) b->Add(fTreeK,fTreeK->GetName());
245 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
246 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
247 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
248 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
250 TIter next(fModules);
252 while((detector = (AliModule*)next())) {
253 b->Add(detector,detector->GetName());
257 //_____________________________________________________________________________
261 // Initialize Alice geometry
266 //_____________________________________________________________________________
267 void AliRun::BuildSimpleGeometry()
270 // Create a simple TNode geometry used by Root display engine
272 // Initialise geometry
274 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
275 new TMaterial("void","Vacuum",0,0,0); //Everything is void
276 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
277 brik->SetVisibility(0);
278 new TNode("alice","alice","S_alice");
281 //_____________________________________________________________________________
282 void AliRun::CleanDetectors()
285 // Clean Detectors at the end of event
287 TIter next(fModules);
289 while((detector = (AliModule*)next())) {
290 detector->FinishEvent();
294 //_____________________________________________________________________________
295 void AliRun::CleanParents()
298 // Clean Particles stack.
299 // Set parent/daughter relations
301 TClonesArray &particles = *(gAlice->Particles());
304 for(i=0; i<fNtrack; i++) {
305 part = (TParticle *)particles.UncheckedAt(i);
306 if(!part->TestBit(Daughters_Bit)) {
307 part->SetFirstDaughter(-1);
308 part->SetLastDaughter(-1);
313 //_____________________________________________________________________________
314 Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
317 // Return the distance from the mouse to the AliRun object
323 //_____________________________________________________________________________
324 void AliRun::DumpPart (Int_t i)
327 // Dumps particle i in the stack
329 TClonesArray &particles = *fParticles;
330 ((TParticle*) particles[i])->Print();
333 //_____________________________________________________________________________
334 void AliRun::DumpPStack ()
337 // Dumps the particle stack
339 TClonesArray &particles = *fParticles;
341 "\n\n=======================================================================\n");
342 for (Int_t i=0;i<fNtrack;i++)
344 printf("-> %d ",i); ((TParticle*) particles[i])->Print();
345 printf("--------------------------------------------------------------\n");
348 "\n=======================================================================\n\n");
351 //_____________________________________________________________________________
352 void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
353 Float_t maxField, char* filename)
356 // Set magnetic field parameters
357 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
358 // version Magnetic field map version (only 1 active now)
359 // scale Scale factor for the magnetic field
360 // maxField Maximum value for the magnetic field
363 // --- Sanity check on mag field flags
364 if(type<0 || type > 2) {
365 printf(" Invalid magnetic field flag: %5d; Helix tracking chosen instead\n"
369 if(fField) delete fField;
371 fField = new AliMagFC("Map1"," ",type,version,scale,maxField);
372 } else if(version<=3) {
373 fField = new AliMagFCM("Map2-3",filename,type,version,scale,maxField);
376 printf("Invalid map %d\n",version);
380 //_____________________________________________________________________________
381 void AliRun::FillTree()
384 // Fills all AliRun TTrees
386 if (fTreeK) fTreeK->Fill();
387 if (fTreeH) fTreeH->Fill();
388 if (fTreeD) fTreeD->Fill();
389 if (fTreeR) fTreeR->Fill();
392 //_____________________________________________________________________________
393 void AliRun::FinishPrimary()
396 // Called at the end of each primary track
399 // This primary is finished, purify stack
400 gAlice->PurifyKine();
402 // Write out hits if any
403 if (gAlice->TreeH()) {
404 gAlice->TreeH()->Fill();
411 //_____________________________________________________________________________
412 void AliRun::FinishEvent()
415 // Called at the end of the event.
418 //Update the energy deposit tables
420 for(i=0;i<sEventEnergy.GetSize();i++) {
421 sSummEnergy[i]+=sEventEnergy[i];
422 sSum2Energy[i]+=sEventEnergy[i]*sEventEnergy[i];
424 sEventEnergy.Reset();
426 // Clean detector information
429 // Write out the kinematics
435 // Write out the digits
441 // Write out reconstructed clusters
446 // Write out the event Header information
447 if (fTreeE) fTreeE->Fill();
452 // Write Tree headers
453 Int_t ievent = fHeader.GetEvent();
455 sprintf(hname,"TreeK%d",ievent);
456 if (fTreeK) fTreeK->Write(hname);
457 sprintf(hname,"TreeH%d",ievent);
458 if (fTreeH) fTreeH->Write(hname);
459 sprintf(hname,"TreeD%d",ievent);
460 if (fTreeD) fTreeD->Write(hname);
461 sprintf(hname,"TreeR%d",ievent);
462 if (fTreeR) fTreeR->Write(hname);
465 //_____________________________________________________________________________
466 void AliRun::FinishRun()
469 // Called at the end of the run.
472 // Clean detector information
473 TIter next(fModules);
475 while((detector = (AliModule*)next())) {
476 detector->FinishRun();
479 //Output energy summary tables
482 // file is retrieved from whatever tree
484 if (fTreeK) File = fTreeK->GetCurrentFile();
485 if ((!File) && (fTreeH)) File = fTreeH->GetCurrentFile();
486 if ((!File) && (fTreeD)) File = fTreeD->GetCurrentFile();
487 if ((!File) && (fTreeE)) File = fTreeE->GetCurrentFile();
489 Error("FinishRun","There isn't root file!");
495 // Clean tree information
496 delete fTreeK; fTreeK = 0;
497 delete fTreeH; fTreeH = 0;
498 delete fTreeD; fTreeD = 0;
499 delete fTreeR; fTreeR = 0;
500 delete fTreeE; fTreeE = 0;
502 // Write AliRun info and all detectors parameters
510 //_____________________________________________________________________________
511 void AliRun::FlagTrack(Int_t track)
514 // Flags a track and all its family tree to be kept
521 particle=(TParticle*)fParticles->UncheckedAt(curr);
523 // If the particle is flagged the three from here upward is saved already
524 if(particle->TestBit(Keep_Bit)) return;
526 // Save this particle
527 particle->SetBit(Keep_Bit);
529 // Move to father if any
530 if((curr=particle->GetFirstMother())==-1) return;
534 //_____________________________________________________________________________
535 void AliRun::EnergySummary()
538 // Print summary of deposited energy
541 AliMC* pMC = AliMC::GetMC();
546 Int_t kn, i, left, j, id;
547 const Float_t zero=0;
548 Int_t ievent=fHeader.GetEvent()+1;
550 // Energy loss information
552 printf("***************** Energy Loss Information per event (GEV) *****************\n");
553 for(kn=1;kn<sEventEnergy.GetSize();kn++) {
556 sEventEnergy[ndep]=kn;
561 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,zero))/ed;
564 sSummEnergy[ndep]=ed;
565 sSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,zero));
570 for(kn=0;kn<(ndep-1)/3+1;kn++) {
572 for(i=0;i<(3<left?3:left);i++) {
574 id=Int_t (sEventEnergy[j]+0.1);
575 printf(" %s %10.3f +- %10.3f%%;",pMC->VolName(id),sSummEnergy[j],sSum2Energy[j]);
580 // Relative energy loss in different detectors
581 printf("******************** Relative Energy Loss per event ********************\n");
582 printf("Total energy loss per event %10.3f GeV\n",edtot);
583 for(kn=0;kn<(ndep-1)/5+1;kn++) {
585 for(i=0;i<(5<left?5:left);i++) {
587 id=Int_t (sEventEnergy[j]+0.1);
588 printf(" %s %10.3f%%;",pMC->VolName(id),100*sSummEnergy[j]/edtot);
592 for(kn=0;kn<75;kn++) printf("*");
596 // Reset the TArray's
602 //_____________________________________________________________________________
603 AliModule *AliRun::GetModule(const char *name)
606 // Return pointer to detector from name
608 return (AliModule*)fModules->FindObject(name);
611 //_____________________________________________________________________________
612 AliDetector *AliRun::GetDetector(const char *name)
615 // Return pointer to detector from name
617 return (AliDetector*)fModules->FindObject(name);
620 //_____________________________________________________________________________
621 Int_t AliRun::GetModuleID(const char *name)
624 // Return galice internal detector identifier from name
627 for(i=0;i<fNdets;i++) if(!strcmp(fDnames[i],name)) {
630 printf(" * GetDetectorID * Detector %s not found: returning -1\n",name);
634 //_____________________________________________________________________________
635 Int_t AliRun::GetEvent(Int_t event)
638 // Connect the Trees Kinematics and Hits for event # event
639 // Set branch addresses
641 fHeader.SetEvent(event);
643 // Reset existing structures
648 // Delete Trees already connected
649 if (fTreeK) delete fTreeK;
650 if (fTreeH) delete fTreeH;
651 if (fTreeD) delete fTreeD;
652 if (fTreeR) delete fTreeR;
654 // Get Kine Tree from file
656 sprintf(treeName,"TreeK%d",event);
657 fTreeK = (TTree*)gDirectory->Get(treeName);
658 if (fTreeK) fTreeK->SetBranchAddress("Particles", &fParticles);
659 else printf("ERROR: cannot find Kine Tree for event:%d\n",event);
661 // Get Hits Tree header from file
662 sprintf(treeName,"TreeH%d",event);
663 fTreeH = (TTree*)gDirectory->Get(treeName);
665 printf("ERROR: cannot find Hits Tree for event:%d\n",event);
669 // Get Digits Tree header from file
670 sprintf(treeName,"TreeD%d",event);
671 fTreeD = (TTree*)gDirectory->Get(treeName);
673 printf("WARNING: cannot find Digits Tree for event:%d\n",event);
677 // Get Reconstruct Tree header from file
678 sprintf(treeName,"TreeR%d",event);
679 fTreeR = (TTree*)gDirectory->Get(treeName);
681 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
684 // Set Trees branch addresses
685 TIter next(fModules);
687 while((detector = (AliModule*)next())) {
688 detector->SetTreeAddress();
691 if (fTreeK) fTreeK->GetEvent(0);
692 fNtrack = Int_t (fParticles->GetEntries());
696 //_____________________________________________________________________________
697 TGeometry *AliRun::GetGeometry()
700 // Import Alice geometry from current file
701 // Return pointer to geometry object
703 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
705 // Unlink and relink nodes in detectors
706 // This is bad and there must be a better way...
708 TList *tnodes=fGeometry->GetListOfNodes();
709 TNode *alice=(TNode*)tnodes->At(0);
710 TList *gnodes=alice->GetListOfNodes();
712 TIter next(fModules);
714 while((detector = (AliModule*)next())) {
715 detector->SetTreeAddress();
716 TList *dnodes=detector->Nodes();
719 for ( j=0; j<dnodes->GetSize(); j++) {
720 node = (TNode*) dnodes->At(j);
721 node1 = (TNode*) gnodes->FindObject(node->GetName());
722 dnodes->Remove(node);
723 dnodes->AddAt(node1,j);
729 //_____________________________________________________________________________
730 void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
731 Float_t &e, Float_t *vpos, Float_t *polar,
735 // Return next track from stack of particles
740 for(Int_t i=fNtrack-1; i>=0; i--) {
741 track=(TParticle*) fParticles->UncheckedAt(i);
742 if(!track->TestBit(Done_Bit)) {
744 // The track has not yet been processed
746 ipart=track->GetPdgCode();
754 pol = track->GetPolarisation();
759 track->SetBit(Done_Bit);
765 // stop and start timer when we start a primary track
766 Int_t nprimaries = fHeader.GetNprimary();
767 if (fCurrent >= nprimaries) return;
768 if (fCurrent < nprimaries-1) {
770 track=(TParticle*) fParticles->UncheckedAt(fCurrent+1);
771 // track->SetProcessTime(fTimer.CpuTime());
776 //_____________________________________________________________________________
777 Int_t AliRun::GetPrimary(Int_t track)
780 // return number of primary that has generated track
788 part = (TParticle *)fParticles->UncheckedAt(current);
789 parent=part->GetFirstMother();
790 if(parent<0) return current;
794 //_____________________________________________________________________________
795 void AliRun::Init(const char *setup)
798 // Initialize the Alice setup
801 gROOT->LoadMacro(setup);
802 gInterpreter->ProcessLine("Config();");
804 AliMC* pMC = AliMC::GetMC();
806 pMC->DefineParticles(); //Create standard MC particles
808 TObject *objfirst, *objlast;
811 //=================Create Materials, geometry, histograms, etc
812 TIter next(fModules);
814 while((detector = (AliModule*)next())) {
815 detector->SetTreeAddress();
816 objlast = gDirectory->GetList()->Last();
818 // Initialise detector materials, geometry, histograms,etc
819 detector->CreateMaterials();
820 detector->CreateGeometry();
821 detector->BuildGeometry();
824 // Add Detector histograms in Detector list of histograms
825 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
826 else objfirst = gDirectory->GetList()->First();
828 detector->Histograms()->Add(objfirst);
829 objfirst = gDirectory->GetList()->After(objfirst);
832 SetTransPar(); //Read the cuts for all materials
834 MediaTable(); //Build the special IMEDIA table
836 //Close the geometry structure
839 //Initialise geometry deposition table
840 sEventEnergy.Set(pMC->NofVolumes()+1);
841 sSummEnergy.Set(pMC->NofVolumes()+1);
842 sSum2Energy.Set(pMC->NofVolumes()+1);
844 //Create the color table
847 //Compute cross-sections
850 //Write Geometry object to current file.
856 //_____________________________________________________________________________
857 void AliRun::MediaTable()
860 // Built media table to get from the media number to
863 Int_t kz, ibeg, nz, idt, lz, i, k, ind;
864 TObjArray &dets = *gAlice->Detectors();
868 for (kz=0;kz<fNdets;kz++) {
869 // If detector is defined
870 if((det=(AliModule*) dets[kz])) {
872 for(nz=ibeg==-1?1:0;nz<100;nz++) {
873 // Find max and min material number
874 if((idt=fIdtmed[ibeg+nz])) {
875 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
876 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
879 if(det->LoMedium() > det->HiMedium()) {
883 if(det->HiMedium() > fImedia->GetSize()) {
884 Error("MediaTable","Increase fImedia");
887 // Tag all materials in rage as belonging to detector kz
888 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
895 // Print summary table
896 printf(" Traking media ranges:\n");
897 for(i=0;i<(fNdets-1)/6+1;i++) {
898 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
900 det=(AliModule*)dets[ind];
902 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
905 printf(" %6s: %3d -> %3d;","NULL",0,0);
911 //____________________________________________________________________________
912 void AliRun::SetGenerator(AliGenerator *generator)
915 // Load the event generator
917 if(!fGenerator) fGenerator = generator;
920 //____________________________________________________________________________
921 void AliRun::SetTransPar(char* filename)
924 // Read filename to set the transport parameters
927 AliMC* pMC = AliMC::GetMC();
929 const Int_t ncuts=10;
930 const Int_t nflags=11;
931 const Int_t npars=ncuts+nflags;
932 const char pars[npars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
933 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
934 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
935 "MULS","PAIR","PHOT","RAYL"};
940 Int_t i, itmed, iret, ktmed, kz;
943 // See whether the file is there
944 filtmp=gSystem->ExpandPathName(filename);
945 lun=fopen(filtmp,"r");
948 printf(" * AliRun::SetTransPar * file %s does not exist!\n",filename);
952 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
953 printf(" *%59s\n","*");
954 printf(" * Please check carefully what you are doing!%10s\n","*");
955 printf(" *%59s\n","*");
958 // Initialise cuts and flags
959 for(i=0;i<ncuts;i++) cut[i]=-99;
960 for(i=0;i<nflags;i++) flag[i]=-99;
962 for(i=0;i<256;i++) line[i]='\0';
963 // Read up to the end of line excluded
964 iret=fscanf(lun,"%[^\n]",line);
968 printf(" *%59s\n","*");
969 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
972 // Read the end of line
975 if(line[0]=='*') continue;
977 iret=sscanf(line,"%d %f %f %f %f %f %f %f %f %f %f %d %d %d %d %d %d %d %d %d %d %d",
978 &itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],&cut[9],
979 &flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],&flag[8],
984 printf(" * Error reading file %s\n",filename);
987 // Check that the tracking medium code is valid
988 if(0<itmed && itmed < 100*fNdets) {
989 ktmed=fIdtmed[itmed-1];
991 printf(" * Invalid tracking medium code %d *\n",itmed);
994 // Set energy thresholds
995 for(kz=0;kz<ncuts;kz++) {
997 printf(" * %-6s set to %10.3E for tracking medium code %4d *\n",pars[kz],cut[kz],itmed);
998 pMC->Gstpar(ktmed,pars[kz],cut[kz]);
1001 // Set transport mechanisms
1002 for(kz=0;kz<nflags;kz++) {
1004 printf(" * %-6s set to %10d for tracking medium code %4d *\n",pars[ncuts+kz],flag[kz],itmed);
1005 pMC->Gstpar(ktmed,pars[ncuts+kz],Float_t(flag[kz]));
1009 printf(" * Invalid tracking medium code %d *\n",itmed);
1015 //_____________________________________________________________________________
1016 void AliRun::MakeTree(Option_t *option)
1019 // Create the ROOT trees
1020 // Loop on all detectors to create the Root branch (if any)
1025 char *K = strstr(option,"K");
1026 char *H = strstr(option,"H");
1027 char *E = strstr(option,"E");
1028 char *D = strstr(option,"D");
1029 char *R = strstr(option,"R");
1031 if (K && !fTreeK) fTreeK = new TTree("TK","Kinematics");
1032 if (H && !fTreeH) fTreeH = new TTree("TH","Hits");
1033 if (D && !fTreeD) fTreeD = new TTree("TD","Digits");
1034 if (E && !fTreeE) fTreeE = new TTree("TE","Header");
1035 if (R && !fTreeR) fTreeR = new TTree("TR","Reconstruction");
1036 if (fTreeH) fTreeH->SetAutoSave(1000000000); //no autosave
1038 // Create a branch for hits/digits for each detector
1039 // Each branch is a TClonesArray. Each data member of the Hits classes
1040 // will be in turn a subbranch of the detector master branch
1041 TIter next(fModules);
1042 AliModule *detector;
1043 while((detector = (AliModule*)next())) {
1044 if (H || D || R) detector->MakeBranch(option);
1046 // Create a branch for particles
1047 if (fTreeK && K) fTreeK->Branch("Particles",&fParticles,4000);
1049 // Create a branch for Header
1050 if (fTreeE && E) fTreeE->Branch("Header","AliHeader",&header,4000);
1053 //_____________________________________________________________________________
1054 Int_t AliRun::PurifyKine(Int_t lastSavedTrack, Int_t nofTracks)
1057 // PurifyKine with external parameters
1059 fHgwmk = lastSavedTrack;
1060 fNtrack = nofTracks;
1065 //_____________________________________________________________________________
1066 void AliRun::PurifyKine()
1069 // Compress kinematic tree keeping only flagged particles
1070 // and renaming the particle id's in all the hits
1072 TClonesArray &particles = *fParticles;
1073 int nkeep=fHgwmk+1, parent, i;
1074 TParticle *part, *partnew, *father;
1076 int *map = new int[particles.GetEntries()];
1078 // Save in Header total number of tracks before compression
1079 fHeader.SetNtrack(fHeader.GetNtrack()+fNtrack-fHgwmk);
1081 // Preset map, to be removed later
1082 for(i=0; i<fNtrack; i++) {
1083 if(i<=fHgwmk) map[i]=i ; else map[i] = -99 ;}
1084 // Second pass, build map between old and new numbering
1085 for(i=fHgwmk+1; i<fNtrack; i++) {
1086 part = (TParticle *)particles.UncheckedAt(i);
1087 if(part->TestBit(Keep_Bit)) {
1089 // This particle has to be kept
1093 // Old and new are different, have to copy
1094 partnew = (TParticle *)particles.UncheckedAt(nkeep);
1096 } else partnew = part;
1098 // as the parent is always *before*, it must be already
1099 // in place. This is what we are checking anyway!
1100 if((parent=partnew->GetFirstMother())>fHgwmk) {
1101 if(map[parent]==-99) printf("map[%d] = -99!\n",parent);
1102 partnew->SetFirstMother(map[parent]);
1109 // Fix daughters information
1110 for (i=fHgwmk+1; i<fNtrack; i++) {
1111 part = (TParticle *)particles.UncheckedAt(i);
1112 parent = part->GetFirstMother();
1113 father = (TParticle *)particles.UncheckedAt(parent);
1114 if(father->TestBit(Daughters_Bit)) {
1116 if(i<father->GetFirstDaughter()) father->SetFirstDaughter(i);
1117 if(i>father->GetLastDaughter()) father->SetLastDaughter(i);
1119 // Iitialise daughters info for first pass
1120 father->SetFirstDaughter(i);
1121 father->SetLastDaughter(i);
1122 father->SetBit(Daughters_Bit);
1126 // Now loop on all detectors and reset the hits
1127 TIter next(fModules);
1128 AliModule *detector;
1129 while((detector = (AliModule*)next())) {
1130 if (!detector->Hits()) continue;
1131 TClonesArray &vHits=*(detector->Hits());
1132 if(vHits.GetEntries() != detector->GetNhits())
1133 printf("vHits.GetEntries()!=detector->GetNhits(): %d != %d\n",
1134 vHits.GetEntries(),detector->GetNhits());
1135 for (i=0; i<detector->GetNhits(); i++) {
1136 OneHit = (AliHit *)vHits.UncheckedAt(i);
1137 OneHit->SetTrack(map[OneHit->GetTrack()]);
1142 particles.SetLast(fHgwmk);
1146 //_____________________________________________________________________________
1147 void AliRun::Reset(Int_t run, Int_t idevent)
1150 // Reset all Detectors & kinematics & trees
1156 // Initialise event header
1157 fHeader.Reset(run,idevent);
1159 if(fTreeK) fTreeK->Reset();
1160 if(fTreeH) fTreeH->Reset();
1161 if(fTreeD) fTreeD->Reset();
1164 //_____________________________________________________________________________
1165 void AliRun::ResetDigits()
1168 // Reset all Detectors digits
1170 TIter next(fModules);
1171 AliModule *detector;
1172 while((detector = (AliModule*)next())) {
1173 detector->ResetDigits();
1177 //_____________________________________________________________________________
1178 void AliRun::ResetHits()
1181 // Reset all Detectors hits
1183 TIter next(fModules);
1184 AliModule *detector;
1185 while((detector = (AliModule*)next())) {
1186 detector->ResetHits();
1190 //_____________________________________________________________________________
1191 void AliRun::ResetPoints()
1194 // Reset all Detectors points
1196 TIter next(fModules);
1197 AliModule *detector;
1198 while((detector = (AliModule*)next())) {
1199 detector->ResetPoints();
1203 //_____________________________________________________________________________
1204 void AliRun::Run(Int_t nevent, const char *setup)
1207 // Main function to be called to process a galice run
1209 // Root > gAlice.Run();
1210 // a positive number of events will cause the finish routine
1215 // check if initialisation has been done
1216 if (!fInitDone) Init(setup);
1218 AliMC* pMC = AliMC::GetMC();
1220 // Create the Root Tree with one branch per detector
1222 gAlice->MakeTree("KHDER");
1225 todo = TMath::Abs(nevent);
1226 for (i=0; i<todo; i++) {
1227 // Process one run (one run = one event)
1228 gAlice->Reset(fRun, fEvent);
1232 gAlice->FinishEvent();
1236 // End of this run, close files
1237 if(nevent>0) gAlice->FinishRun();
1240 //_____________________________________________________________________________
1241 void AliRun::RunLego(const char *setup,Int_t ntheta,Float_t themin,
1242 Float_t themax,Int_t nphi,Float_t phimin,Float_t phimax,
1243 Float_t rmin,Float_t rmax,Float_t zmax)
1246 // Generates lego plots of:
1247 // - radiation length map phi vs theta
1248 // - radiation length map phi vs eta
1249 // - interaction length map
1250 // - g/cm2 length map
1252 // ntheta bins in theta, eta
1253 // themin minimum angle in theta (degrees)
1254 // themax maximum angle in theta (degrees)
1256 // phimin minimum angle in phi (degrees)
1257 // phimax maximum angle in phi (degrees)
1258 // rmin minimum radius
1259 // rmax maximum radius
1262 // The number of events generated = ntheta*nphi
1263 // run input parameters in macro setup (default="Config.C")
1265 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1268 <img src="picts/AliRunLego1.gif">
1273 <img src="picts/AliRunLego2.gif">
1278 <img src="picts/AliRunLego3.gif">
1283 // check if initialisation has been done
1284 if (!fInitDone) Init(setup);
1286 fLego = new AliLego("lego","lego");
1287 fLego->Init(ntheta,themin,themax,nphi,phimin,phimax,rmin,rmax,zmax);
1290 // Create only the Root event Tree
1291 gAlice->MakeTree("E");
1293 // End of this run, close files
1294 gAlice->FinishRun();
1297 //_____________________________________________________________________________
1298 void AliRun::SetCurrentTrack(Int_t track)
1301 // Set current track number
1306 //_____________________________________________________________________________
1307 void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
1308 Float_t *vpos, Float_t *polar, Float_t tof,
1309 const char *mecha, Int_t &ntr, Float_t weight)
1312 // Load a track on the stack
1314 // done 0 if the track has to be transported
1316 // parent identifier of the parent track. -1 for a primary
1317 // pdg particle code
1318 // pmom momentum GeV/c
1320 // polar polarisation
1321 // tof time of flight in seconds
1322 // mecha production mechanism
1323 // ntr on output the number of the track stored
1325 TClonesArray &particles = *fParticles;
1326 TParticle *particle;
1328 const Int_t firstdaughter=-1;
1329 const Int_t lastdaughter=-1;
1331 // const Float_t tlife=0;
1334 // Here we get the static mass
1335 // For MC is ok, but a more sophisticated method could be necessary
1336 // if the calculated mass is required
1337 // also, this method is potentially dangerous if the mass
1338 // used in the MC is not the same of the PDG database
1340 mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
1341 Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+
1342 pmom[1]*pmom[1]+pmom[2]*pmom[2]);
1344 //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",
1345 //pname,mass,e,fNtrack,pdg,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],KS,mecha);
1347 particle=new(particles[fNtrack]) TParticle(pdg,KS,parent,-1,firstdaughter,
1348 lastdaughter,pmom[0],pmom[1],pmom[2],
1349 e,vpos[0],vpos[1],vpos[2],tof);
1350 // polar[0],polar[1],polar[2],tof,
1352 ((TParticle*)particles[fNtrack])->SetPolarisation(TVector3(polar[0],polar[1],polar[2]));
1353 ((TParticle*)particles[fNtrack])->SetWeight(weight);
1354 if(!done) particle->SetBit(Done_Bit);
1357 particle=(TParticle*) fParticles->UncheckedAt(parent);
1358 particle->SetLastDaughter(fNtrack);
1359 if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack);
1362 // This is a primary track. Set high water mark for this event
1365 // Set also number if primary tracks
1366 fHeader.SetNprimary(fHgwmk+1);
1367 fHeader.SetNtrack(fHgwmk+1);
1372 //_____________________________________________________________________________
1373 void AliRun::KeepTrack(const Int_t track)
1376 // flags a track to be kept
1378 TClonesArray &particles = *fParticles;
1379 ((TParticle*)particles[track])->SetBit(Keep_Bit);
1382 //_____________________________________________________________________________
1383 void AliRun::StepManager(Int_t id) const
1386 // Called at every step during transport
1389 AliMC* pMC = AliMC::GetMC();
1393 // --- If lego option, do it and leave
1395 fLego->StepManager();
1398 //Update energy deposition tables
1399 sEventEnergy[pMC->CurrentVol(0,copy)]+=pMC->Edep();
1401 //Call the appropriate stepping routine;
1402 AliModule *det = (AliModule*)fModules->At(id);
1403 if(det) det->StepManager();
1406 //_____________________________________________________________________________
1407 void AliRun::ReadEuclid(const char* filnam, Int_t id_det, const char* topvol)
1410 // read in the geometry of the detector in euclid file format
1412 // id_det : the detector identification (2=its,...)
1413 // topvol : return parameter describing the name of the top
1414 // volume of geometry.
1416 // author : m. maire
1419 // several changes have been made by miroslav helbich
1420 // subroutine is rewrited to follow the new established way of memory
1421 // booking for tracking medias and rotation matrices.
1422 // all used tracking media have to be defined first, for this you can use
1423 // subroutine greutmed.
1424 // top volume is searched as only volume not positioned into another
1427 AliMC* pMC = AliMC::GetMC();
1429 Int_t i, nvol, iret, itmed, irot, numed, npar, ndiv, iaxe;
1430 Int_t ndvmx, nr, flag;
1431 char key[5], card[77], natmed[21];
1432 char name[5], mother[5], shape[5], konly[5], volst[7000][5];
1435 Float_t teta1, phi1, teta2, phi2, teta3, phi3, orig, step;
1437 Int_t idrot[5000],istop[7000];
1441 TObjArray &dets = *fModules;
1443 printf(" *** GREUTMED *** Detector %d not defined\n",id_det);
1446 det = (AliModule*) dets[id_det];
1449 // *** The input filnam name will be with extension '.euc'
1450 filtmp=gSystem->ExpandPathName(filnam);
1451 lun=fopen(filtmp,"r");
1454 printf(" *** GREUCL *** Could not open file %s\n",filnam);
1457 //* --- definition of rotation matrix 0 ---
1461 for(i=0;i<77;i++) card[i]=0;
1462 iret=fscanf(lun,"%77[^\n]",card);
1463 if(iret<=0) goto L20;
1466 strncpy(key,card,4);
1468 if (!strcmp(key,"TMED")) {
1469 sscanf(&card[5],"%d '%[^']'",&itmed,natmed);
1470 //Pad the string with blanks
1473 while(i<20) natmed[i++]=' ';
1476 pMC->Gckmat(fIdtmed[itmed+id_det*100-1],natmed);
1478 } else if (!strcmp(key,"ROTM")) {
1479 sscanf(&card[4],"%d %f %f %f %f %f %f",&irot,&teta1,&phi1,&teta2,&phi2,&teta3,&phi3);
1480 det->AliMatrix(idrot[irot],teta1,phi1,teta2,phi2,teta3,phi3);
1482 } else if (!strcmp(key,"VOLU")) {
1483 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, shape, &numed, &npar);
1485 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
1488 pMC->Gsvolu( name, shape, fIdtmed[numed+id_det*100-1], par, npar);
1489 //* save the defined volumes
1490 strcpy(volst[++nvol],name);
1493 } else if (!strcmp(key,"DIVN")) {
1494 sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, mother, &ndiv, &iaxe);
1495 pMC->Gsdvn ( name, mother, ndiv, iaxe );
1497 } else if (!strcmp(key,"DVN2")) {
1498 sscanf(&card[5],"'%[^']' '%[^']' %d %d %f %d",name, mother, &ndiv, &iaxe, &orig, &numed);
1499 pMC->Gsdvn2( name, mother, ndiv, iaxe, orig,fIdtmed[numed+id_det*100-1]);
1501 } else if (!strcmp(key,"DIVT")) {
1502 sscanf(&card[5],"'%[^']' '%[^']' %f %d %d %d", name, mother, &step, &iaxe, &numed, &ndvmx);
1503 pMC->Gsdvt ( name, mother, step, iaxe, fIdtmed[numed+id_det*100-1], ndvmx);
1505 } else if (!strcmp(key,"DVT2")) {
1506 sscanf(&card[5],"'%[^']' '%[^']' %f %d %f %d %d", name, mother, &step, &iaxe, &orig, &numed, &ndvmx);
1507 pMC->Gsdvt2 ( name, mother, step, iaxe, orig, fIdtmed[numed+id_det*100-1], ndvmx );
1509 } else if (!strcmp(key,"POSI")) {
1510 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']'", name, &nr, mother, &xo, &yo, &zo, &irot, konly);
1511 //*** volume name cannot be the top volume
1512 for(i=1;i<=nvol;i++) {
1513 if (!strcmp(volst[i],name)) istop[i]=0;
1516 pMC->Gspos ( name, nr, mother, xo, yo, zo, idrot[irot], konly );
1518 } else if (!strcmp(key,"POSP")) {
1519 sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']' %d", name, &nr, mother, &xo, &yo, &zo, &irot, konly, &npar);
1521 for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
1524 //*** volume name cannot be the top volume
1525 for(i=1;i<=nvol;i++) {
1526 if (!strcmp(volst[i],name)) istop[i]=0;
1529 pMC->Gsposp ( name, nr, mother, xo,yo,zo, idrot[irot], konly, par, npar);
1532 if (strcmp(key,"END")) goto L10;
1533 //* find top volume in the geometry
1535 for(i=1;i<=nvol;i++) {
1536 if (istop[i] && flag) {
1537 printf(" *** GREUCL *** warning: %s is another possible top volume\n",volst[i]);
1539 if (istop[i] && !flag) {
1541 printf(" *** GREUCL *** volume %s taken as a top volume\n",topvol);
1546 printf("*** GREUCL *** warning: top volume not found\n");
1550 //* commented out only for the not cernlib version
1551 printf(" *** GREUCL *** file: %s is now read in\n",filnam);
1556 printf(" *** GREUCL *** reading error or premature end of file\n");
1559 //_____________________________________________________________________________
1560 void AliRun::ReadEuclidMedia(const char* filnam, Int_t id_det)
1563 // read in the materials and tracking media for the detector
1564 // in euclid file format
1566 // filnam: name of the input file
1567 // id_det: id_det is the detector identification (2=its,...)
1569 // author : miroslav helbich
1571 Float_t sxmgmx = gAlice->Field()->Max();
1572 Int_t isxfld = gAlice->Field()->Integ();
1573 Int_t end, i, iret, itmed;
1574 char key[5], card[130], natmed[21], namate[21];
1579 Int_t nwbuf, isvol, ifield, nmat;
1580 Float_t a, z, dens, radl, absl, fieldm, tmaxfd, stemax, deemax, epsil, stmin;
1583 TObjArray &dets = *fModules;
1585 printf(" *** GREUTMED *** Detector %d not defined\n",id_det);
1588 det = (AliModule*) dets[id_det];
1591 for(i=0;i<end;i++) if(filnam[i]=='.') {
1596 // *** The input filnam name will be with extension '.euc'
1597 printf("The file name is %s\n",filnam); //Debug
1598 filtmp=gSystem->ExpandPathName(filnam);
1599 lun=fopen(filtmp,"r");
1602 printf(" *** GREUTMED *** Could not open file %s\n",filnam);
1606 // Retrieve Mag Field parameters
1607 Int_t ISXFLD=gAlice->Field()->Integ();
1608 Float_t SXMGMX=gAlice->Field()->Max();
1611 for(i=0;i<130;i++) card[i]=0;
1612 iret=fscanf(lun,"%4s %[^\n]",key,card);
1613 if(iret<=0) goto L20;
1617 if (!strcmp(key,"MATE")) {
1618 sscanf(card,"%d '%[^']' %f %f %f %f %f %d",&imate,namate,&a,&z,&dens,&radl,&absl,&nwbuf);
1619 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
1620 //Pad the string with blanks
1623 while(i<20) namate[i++]=' ';
1626 det->AliMaterial(imate,namate,a,z,dens,radl,absl,ubuf,nwbuf);
1627 //* read tracking medium
1628 } else if (!strcmp(key,"TMED")) {
1629 sscanf(card,"%d '%[^']' %d %d %d %f %f %f %f %f %f %d",
1630 &itmed,natmed,&nmat,&isvol,&ifield,&fieldm,&tmaxfd,
1631 &stemax,&deemax,&epsil,&stmin,&nwbuf);
1632 if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]);
1633 if (ifield<0) ifield=isxfld;
1634 if (fieldm<0) fieldm=sxmgmx;
1635 //Pad the string with blanks
1638 while(i<20) natmed[i++]=' ';
1641 det->AliMedium(itmed+id_det*100,natmed,nmat,isvol,ISXFLD,SXMGMX,tmaxfd,
1642 stemax,deemax,epsil,stmin,ubuf,nwbuf);
1643 (*fImedia)[fIdtmed[itmed+id_det*100-1]-1]=id_det;
1647 if (strcmp(key,"END")) goto L10;
1650 //* commented out only for the not cernlib version
1651 printf(" *** GREUTMED *** file: %s is now read in\n",filnam);
1656 printf(" *** GREUTMED *** reading error or premature end of file\n");
1659 //_____________________________________________________________________________
1660 void AliRun::Streamer(TBuffer &R__b)
1663 // Stream an object of class AliRun.
1665 if (R__b.IsReading()) {
1666 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1667 TNamed::Streamer(R__b);
1668 if (!gAlice) gAlice = this;
1669 gROOT->GetListOfBrowsables()->Add(this,"Run");
1673 fHeader.Streamer(R__b);
1682 R__b >> fPDGDB; //Particle factory object!
1684 R__b.WriteVersion(AliRun::IsA());
1685 TNamed::Streamer(R__b);
1689 fHeader.Streamer(R__b);
1698 R__b << fPDGDB; //Particle factory object!
1703 //_____________________________________________________________________________
1705 // Interfaces to Fortran
1707 //_____________________________________________________________________________
1709 extern "C" void type_of_call rxgtrak (Int_t &mtrack, Int_t &ipart, Float_t *pmom,
1710 Float_t &e, Float_t *vpos, Float_t &tof)
1713 // Fetches next track from the ROOT stack for transport. Called by the
1714 // modified version of GTREVE.
1716 // Track number in the ROOT stack. If MTRACK=0 no
1717 // mtrack more tracks are left in the stack to be
1719 // ipart Particle code in the GEANT conventions.
1720 // pmom[3] Particle momentum in GeV/c
1721 // e Particle energy in GeV
1722 // vpos[3] Particle position
1723 // tof Particle time of flight in seconds
1727 gAlice->GetNextTrack(mtrack, pdg, pmom, e, vpos, polar, tof);
1728 ipart = gMC->IdFromPDG(pdg);
1732 //_____________________________________________________________________________
1733 extern "C" void type_of_call
1735 rxstrak (Int_t &keep, Int_t &parent, Int_t &ipart, Float_t *pmom,
1736 Float_t *vpos, Float_t &tof, const char* cmech, Int_t &ntr, const int cmlen)
1738 rxstrak (Int_t &keep, Int_t &parent, Int_t &ipart, Float_t *pmom,
1739 Float_t *vpos, Float_t &tof, const char* cmech, const int cmlen,
1744 // Fetches next track from the ROOT stack for transport. Called by GUKINE
1747 // Status of the track. If keep=0 the track is put
1748 // keep on the ROOT stack but it is not fetched for
1750 // parent Parent track. If parent=0 the track is a primary.
1751 // In GUSTEP the routine is normally called to store
1752 // secondaries generated by the current track whose
1753 // ROOT stack number is MTRACK (common SCKINE.
1754 // ipart Particle code in the GEANT conventions.
1755 // pmom[3] Particle momentum in GeV/c
1756 // vpos[3] Particle position
1757 // tof Particle time of flight in seconds
1759 // cmech (CHARACTER*10) Particle origin. This field is user
1760 // defined and it is not used inside the GALICE code.
1761 // ntr Number assigned to the particle in the ROOT stack.
1764 Float_t polar[3]={0.,0.,0.};
1765 for(int i=0; i<10 && i<cmlen; i++) mecha[i]=cmech[i];
1767 Int_t pdg=gMC->PDGFromId(ipart);
1768 gAlice->SetTrack(keep, parent-1, pdg, pmom, vpos, polar, tof, mecha, ntr);
1772 //_____________________________________________________________________________
1773 extern "C" void type_of_call rxkeep(const Int_t &n)
1775 if( NULL==gAlice ) exit(1);
1777 if( n<=0 || n>gAlice->Particles()->GetEntries() )
1779 printf(" Bad index n=%d must be 0<n<=%d\n",
1780 n,gAlice->Particles()->GetEntries());
1784 ((TParticle*)(gAlice->Particles()->UncheckedAt(n-1)))->SetBit(Keep_Bit);
1787 //_____________________________________________________________________________
1788 extern "C" void type_of_call rxouth ()
1791 // Called by Gtreve at the end of each primary track
1793 gAlice->FinishPrimary();