/*
$Log$
+Revision 1.43 2000/10/09 09:43:17 fca
+Special remapping of hits for TPC and TRD. End-of-primary action introduced
+
+Revision 1.42 2000/10/02 21:28:14 fca
+Removal of useless dependecies via forward declarations
+
+Revision 1.41 2000/07/13 16:19:09 fca
+Mainly coding conventions + some small bug fixes
+
+Revision 1.40 2000/07/12 08:56:25 fca
+Coding convention correction and warning removal
+
+Revision 1.39 2000/07/11 18:24:59 fca
+Coding convention corrections + few minor bug fixes
+
+Revision 1.38 2000/06/20 13:05:45 fca
+Writing down the TREE headers before job starts
+
+Revision 1.37 2000/06/09 20:05:11 morsch
+Introduce possibility to chose magnetic field version 3: AliMagFDM + field02.dat
+
+Revision 1.36 2000/06/08 14:03:58 hristov
+Only one initializer for a default argument
+
+Revision 1.35 2000/06/07 10:13:14 hristov
+Delete only existent objects.
+
+Revision 1.34 2000/05/18 10:45:38 fca
+Delete Particle Factory properly
+
+Revision 1.33 2000/05/16 13:10:40 fca
+New method IsNewTrack and fix for a problem in Father-Daughter relations
+
+Revision 1.32 2000/04/27 10:38:21 fca
+Correct termination of Lego Run and introduce Lego getter in AliRun
+
+Revision 1.31 2000/04/26 10:17:32 fca
+Changes in Lego for G4 compatibility
+
+Revision 1.30 2000/04/18 19:11:40 fca
+Introduce variable Config.C function signature
+
Revision 1.29 2000/04/07 11:12:34 fca
G4 compatibility changes
// //
///////////////////////////////////////////////////////////////////////////////
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
#include <TFile.h>
#include <TRandom.h>
#include <TBRIK.h>
#include <TCint.h>
#include <TSystem.h>
#include <TObjectTable.h>
+#include <TTree.h>
+#include <TGeometry.h>
+#include <TROOT.h>
+#include "TBrowser.h"
#include "TParticle.h"
#include "AliRun.h"
#include "AliDisplay.h"
#include "AliMC.h"
+#include "AliLego.h"
+#include "AliMagFC.h"
+#include "AliMagFCM.h"
+#include "AliMagFDM.h"
+#include "AliHit.h"
+
+#include "AliDetector.h"
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
AliRun *gAlice;
-static AliHeader *header;
+static AliHeader *gAliHeader;
ClassImp(AliRun)
//
// Default constructor for AliRun
//
- header=&fHeader;
+ gAliHeader=&fHeader;
fRun = 0;
fEvent = 0;
fCurrent = -1;
fNtrack=0;
fHgwmk=0;
fCurrent=-1;
- header=&fHeader;
+ gAliHeader=&fHeader;
fRun = 0;
fEvent = 0;
//
fHitLists = new TList();
}
+
//_____________________________________________________________________________
AliRun::~AliRun()
{
delete fParticles;
}
delete fHitLists;
+ delete fPDGDB;
}
//_____________________________________________________________________________
int i;
for(i=0; i<fNtrack; i++) {
part = (TParticle *)particles.UncheckedAt(i);
- if(!part->TestBit(Daughters_Bit)) {
+ if(!part->TestBit(kDaughtersBit)) {
part->SetFirstDaughter(-1);
part->SetLastDaughter(-1);
}
}
//_____________________________________________________________________________
-void AliRun::DumpPart (Int_t i)
+void AliRun::DumpPart (Int_t i) const
{
//
// Dumps particle i in the stack
}
//_____________________________________________________________________________
-void AliRun::DumpPStack ()
+void AliRun::DumpPStack () const
{
//
// Dumps the particle stack
if(fField) delete fField;
if(version==1) {
fField = new AliMagFC("Map1"," ",type,version,scale,maxField);
- } else if(version<=3) {
+ } else if(version<=2) {
fField = new AliMagFCM("Map2-3",filename,type,version,scale,maxField);
fField->ReadField();
+ } else if(version==3) {
+ fField = new AliMagFDM("Map4",filename,type,version,scale,maxField);
+ fField->ReadField();
} else {
Warning("SetField","Invalid map %d\n",version);
}
// This primary is finished, purify stack
PurifyKine();
+ TIter next(fModules);
+ AliModule *detector;
+ while((detector = (AliModule*)next())) {
+ detector->FinishPrimary();
+ }
+
// Write out hits if any
if (gAlice->TreeH()) {
gAlice->TreeH()->Fill();
// Called at the end of the event.
//
+ //
+ if(fLego) fLego->FinishEvent();
+
//Update the energy deposit tables
Int_t i;
for(i=0;i<fEventEnergy.GetSize();i++) {
// Int_t ievent = fHeader.GetEvent();
// char hname[30];
// sprintf(hname,"TreeK%d",ievent);
- if (fTreeK) fTreeK->Write();
+ if (fTreeK) fTreeK->Write(0,TObject::kOverwrite);
// sprintf(hname,"TreeH%d",ievent);
- if (fTreeH) fTreeH->Write();
+ if (fTreeH) fTreeH->Write(0,TObject::kOverwrite);
// sprintf(hname,"TreeD%d",ievent);
- if (fTreeD) fTreeD->Write();
+ if (fTreeD) fTreeD->Write(0,TObject::kOverwrite);
// sprintf(hname,"TreeR%d",ievent);
- if (fTreeR) fTreeR->Write();
+ if (fTreeR) fTreeR->Write(0,TObject::kOverwrite);
++fEvent;
}
// Called at the end of the run.
//
+ //
+ if(fLego) fLego->FinishRun();
+
// Clean detector information
TIter next(fModules);
AliModule *detector;
EnergySummary();
// file is retrieved from whatever tree
- TFile *File = 0;
- if (fTreeK) File = fTreeK->GetCurrentFile();
- if ((!File) && (fTreeH)) File = fTreeH->GetCurrentFile();
- if ((!File) && (fTreeD)) File = fTreeD->GetCurrentFile();
- if ((!File) && (fTreeE)) File = fTreeE->GetCurrentFile();
- if( NULL==File ) {
+ TFile *file = 0;
+ if (fTreeK) file = fTreeK->GetCurrentFile();
+ if ((!file) && (fTreeH)) file = fTreeH->GetCurrentFile();
+ if ((!file) && (fTreeD)) file = fTreeD->GetCurrentFile();
+ if ((!file) && (fTreeE)) file = fTreeE->GetCurrentFile();
+ if( NULL==file ) {
Error("FinishRun","There isn't root file!");
exit(1);
}
- File->cd();
- fTreeE->Write();
+ file->cd();
+ fTreeE->Write(0,TObject::kOverwrite);
// Clean tree information
- delete fTreeK; fTreeK = 0;
- delete fTreeH; fTreeH = 0;
- delete fTreeD; fTreeD = 0;
- delete fTreeR; fTreeR = 0;
- delete fTreeE; fTreeE = 0;
+ if (fTreeK) {
+ delete fTreeK; fTreeK = 0;
+ }
+ if (fTreeH) {
+ delete fTreeH; fTreeH = 0;
+ }
+ if (fTreeD) {
+ delete fTreeD; fTreeD = 0;
+ }
+ if (fTreeR) {
+ delete fTreeR; fTreeR = 0;
+ }
+ if (fTreeE) {
+ delete fTreeE; fTreeE = 0;
+ }
// Write AliRun info and all detectors parameters
Write();
// Close output file
- File->Write();
+ file->Write();
}
//_____________________________________________________________________________
particle=(TParticle*)fParticles->UncheckedAt(curr);
// If the particle is flagged the three from here upward is saved already
- if(particle->TestBit(Keep_Bit)) return;
+ if(particle->TestBit(kKeepBit)) return;
// Save this particle
- particle->SetBit(Keep_Bit);
+ particle->SetBit(kKeepBit);
// Move to father if any
if((curr=particle->GetFirstMother())==-1) return;
Float_t edtot=0;
Float_t ed, ed2;
Int_t kn, i, left, j, id;
- const Float_t zero=0;
+ const Float_t kzero=0;
Int_t ievent=fHeader.GetEvent()+1;
//
// Energy loss information
ed=ed/ievent;
ed2=fSum2Energy[kn];
ed2=ed2/ievent;
- ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,zero))/ed;
+ ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,kzero))/ed;
} else
ed2=99;
fSummEnergy[ndep]=ed;
- fSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,zero));
+ fSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,kzero));
edtot+=ed;
ndep++;
}
}
//_____________________________________________________________________________
-AliModule *AliRun::GetModule(const char *name)
+AliModule *AliRun::GetModule(const char *name) const
{
//
// Return pointer to detector from name
}
//_____________________________________________________________________________
-AliDetector *AliRun::GetDetector(const char *name)
+AliDetector *AliRun::GetDetector(const char *name) const
{
//
// Return pointer to detector from name
}
//_____________________________________________________________________________
-Int_t AliRun::GetModuleID(const char *name)
+Int_t AliRun::GetModuleID(const char *name) const
{
//
// Return galice internal detector identifier from name
TParticle *track;
for(Int_t i=fNtrack-1; i>=0; i--) {
track=(TParticle*) fParticles->UncheckedAt(i);
- if(!track->TestBit(Done_Bit)) {
+ if(!track->TestBit(kDoneBit)) {
//
// The track has not yet been processed
fCurrent=i;
polar[1]=pol.Y();
polar[2]=pol.Z();
tof=track->T();
- track->SetBit(Done_Bit);
+ track->SetBit(kDoneBit);
break;
}
}
}
//_____________________________________________________________________________
-Int_t AliRun::GetPrimary(Int_t track)
+Int_t AliRun::GetPrimary(Int_t track) const
{
//
// return number of primary that has generated track
// Initialize the Alice setup
//
+ if(fInitDone) {
+ Warning("Init","Cannot initialise AliRun twice!\n");
+ return;
+ }
+
gROOT->LoadMacro(setup);
gInterpreter->ProcessLine(fConfigFunction.Data());
fGeometry->Write();
fInitDone = kTRUE;
+
+ //
+ // Save stuff at the beginning of the file to avoid file corruption
+ Write();
}
//_____________________________________________________________________________
// Load the event generator
//
if(fGenerator)
- Warning("ResetGenerator","Replacing generator %s with %s\n",
- fGenerator->GetName(),generator->GetName());
+ if(generator)
+ Warning("ResetGenerator","Replacing generator %s with %s\n",
+ fGenerator->GetName(),generator->GetName());
+ else
+ Warning("ResetGenerator","Replacing generator %s with NULL\n",
+ fGenerator->GetName());
fGenerator = generator;
}
//
- const Int_t ncuts=10;
- const Int_t nflags=11;
- const Int_t npars=ncuts+nflags;
- const char pars[npars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
+ const Int_t kncuts=10;
+ const Int_t knflags=11;
+ const Int_t knpars=kncuts+knflags;
+ const char kpars[knpars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
"BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
"BREM","COMP","DCAY","DRAY","HADR","LOSS",
"MULS","PAIR","PHOT","RAYL"};
char line[256];
char detName[7];
char* filtmp;
- Float_t cut[ncuts];
- Int_t flag[nflags];
+ Float_t cut[kncuts];
+ Int_t flag[knflags];
Int_t i, itmed, iret, ktmed, kz;
FILE *lun;
//
//
while(1) {
// Initialise cuts and flags
- for(i=0;i<ncuts;i++) cut[i]=-99;
- for(i=0;i<nflags;i++) flag[i]=-99;
+ for(i=0;i<kncuts;i++) cut[i]=-99;
+ for(i=0;i<knflags;i++) flag[i]=-99;
itmed=0;
for(i=0;i<256;i++) line[i]='\0';
// Read up to the end of line excluded
continue;
}
// Set energy thresholds
- for(kz=0;kz<ncuts;kz++) {
+ for(kz=0;kz<kncuts;kz++) {
if(cut[kz]>=0) {
printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
- pars[kz],cut[kz],itmed,mod->GetName());
- gMC->Gstpar(ktmed,pars[kz],cut[kz]);
+ kpars[kz],cut[kz],itmed,mod->GetName());
+ gMC->Gstpar(ktmed,kpars[kz],cut[kz]);
}
}
// Set transport mechanisms
- for(kz=0;kz<nflags;kz++) {
+ for(kz=0;kz<knflags;kz++) {
if(flag[kz]>=0) {
printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
- pars[ncuts+kz],flag[kz],itmed,mod->GetName());
- gMC->Gstpar(ktmed,pars[ncuts+kz],Float_t(flag[kz]));
+ kpars[kncuts+kz],flag[kz],itmed,mod->GetName());
+ gMC->Gstpar(ktmed,kpars[kncuts+kz],Float_t(flag[kz]));
}
}
} else {
char hname[30];
//
// Analyse options
- char *K = strstr(option,"K");
- char *H = strstr(option,"H");
- char *E = strstr(option,"E");
- char *D = strstr(option,"D");
- char *R = strstr(option,"R");
+ char *oK = strstr(option,"K");
+ char *oH = strstr(option,"H");
+ char *oE = strstr(option,"E");
+ char *oD = strstr(option,"D");
+ char *oR = strstr(option,"R");
//
- if (K && !fTreeK) {
+ if (oK && !fTreeK) {
sprintf(hname,"TreeK%d",fEvent);
fTreeK = new TTree(hname,"Kinematics");
// Create a branch for particles
fTreeK->Branch("Particles",&fParticles,4000);
+ fTreeK->Write();
}
- if (H && !fTreeH) {
+ if (oH && !fTreeH) {
sprintf(hname,"TreeH%d",fEvent);
fTreeH = new TTree(hname,"Hits");
fTreeH->SetAutoSave(1000000000); //no autosave
+ fTreeH->Write();
}
- if (D && !fTreeD) {
+ if (oD && !fTreeD) {
sprintf(hname,"TreeD%d",fEvent);
fTreeD = new TTree(hname,"Digits");
+ fTreeD->Write();
}
- if (R && !fTreeR) {
+ if (oR && !fTreeR) {
sprintf(hname,"TreeR%d",fEvent);
fTreeR = new TTree(hname,"Reconstruction");
+ fTreeR->Write();
}
- if (E && !fTreeE) {
+ if (oE && !fTreeE) {
fTreeE = new TTree("TE","Header");
// Create a branch for Header
- fTreeE->Branch("Header","AliHeader",&header,4000);
+ fTreeE->Branch("Header","AliHeader",&gAliHeader,4000);
+ fTreeE->Write();
}
//
// Create a branch for hits/digits for each detector
TIter next(fModules);
AliModule *detector;
while((detector = (AliModule*)next())) {
- if (H || D || R) detector->MakeBranch(option);
+ if (oH || oD || oR) detector->MakeBranch(option);
}
}
// Save in Header total number of tracks before compression
fHeader.SetNtrack(fHeader.GetNtrack()+fNtrack-fHgwmk);
- // Preset map, to be removed later
+ // First pass, invalid Daughter information
for(i=0; i<fNtrack; i++) {
- if(i<=fHgwmk) map[i]=i ; else map[i] = -99 ;}
+ // Preset map, to be removed later
+ if(i<=fHgwmk) map[i]=i ; else map[i] = -99;
+ ((TParticle *)particles.UncheckedAt(i))->ResetBit(kDaughtersBit);
+ }
// Second pass, build map between old and new numbering
for(i=fHgwmk+1; i<fNtrack; i++) {
part = (TParticle *)particles.UncheckedAt(i);
- if(part->TestBit(Keep_Bit)) {
+ if(part->TestBit(kKeepBit)) {
// This particle has to be kept
map[i]=nkeep;
parent = part->GetFirstMother();
if(parent>=0) {
father = (TParticle *)particles.UncheckedAt(parent);
- if(father->TestBit(Daughters_Bit)) {
+ if(father->TestBit(kDaughtersBit)) {
if(i<father->GetFirstDaughter()) father->SetFirstDaughter(i);
if(i>father->GetLastDaughter()) father->SetLastDaughter(i);
// Iitialise daughters info for first pass
father->SetFirstDaughter(i);
father->SetLastDaughter(i);
- father->SetBit(Daughters_Bit);
+ father->SetBit(kDaughtersBit);
}
}
}
}
#endif
+ //
+ // This for detectors which have a special mapping mechanism
+ // for hits, such as TPC and TRD
+ //
+
+ TIter nextmod(fModules);
+ AliModule *detector;
+ while((detector = (AliModule*)nextmod())) {
+ detector->RemapTrackHitIDs(map);
+ }
+
+
fHgwmk=nkeep-1;
particles.SetLast(fHgwmk);
delete [] map;
}
//_____________________________________________________________________________
-void AliRun::Reset()
+void AliRun::BeginEvent()
{
//
// Reset all Detectors & kinematics & trees
//
char hname[30];
+ //
+
+ //
+ if(fLego) {
+ fLego->BeginEvent();
+ return;
+ }
+
//
ResetStack();
ResetHits();
}
//_____________________________________________________________________________
-void AliRun::RunLego(const char *setup,Int_t ntheta,Float_t themin,
- Float_t themax,Int_t nphi,Float_t phimin,Float_t phimax,
- Float_t rmin,Float_t rmax,Float_t zmax)
+void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min,
+ Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max,
+ Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener)
{
//
// Generates lego plots of:
// check if initialisation has been done
if (!fInitDone) InitMC(setup);
-
+ //Save current generator
+ AliGenerator *gen=Generator();
+
+ // Set new generator
+ if (!gener) gener = new AliLegoGenerator();
+ ResetGenerator(gener);
+ //
+ // Configure Generator
+ gener->SetRadiusRange(rmin, rmax);
+ gener->SetZMax(zmax);
+ gener->SetCoor1Range(nc1, c1min, c1max);
+ gener->SetCoor2Range(nc2, c2min, c2max);
+
+
//Create Lego object
- fLego = new AliLego("lego",ntheta,themin,themax,nphi,phimin,phimax,rmin,rmax,zmax);
+ fLego = new AliLego("lego",gener);
+ //Prepare MC for Lego Run
+ gMC->InitLego();
+
//Run Lego Object
- fLego->Run();
+
+ gMC->ProcessRun(nc1*nc2+1);
// Create only the Root event Tree
MakeTree("E");
// End of this run, close files
FinishRun();
+ // Restore current generator
+ ResetGenerator(gen);
+ // Delete Lego Object
+ delete fLego; fLego=0;
+}
+
+//_____________________________________________________________________________
+void AliRun::SetConfigFunction(const char * config)
+{
+ //
+ // Set the signature of the function contained in Config.C to configure
+ // the run
+ //
+ fConfigFunction=config;
}
//_____________________________________________________________________________
//_____________________________________________________________________________
void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
Float_t *vpos, Float_t *polar, Float_t tof,
- const char *mecha, Int_t &ntr, Float_t weight)
+ const char* /* mecha */, Int_t &ntr, Float_t weight)
{
//
// Load a track on the stack
TClonesArray &particles = *fParticles;
TParticle *particle;
Float_t mass;
- const Int_t firstdaughter=-1;
- const Int_t lastdaughter=-1;
- const Int_t KS=0;
+ const Int_t kfirstdaughter=-1;
+ const Int_t klastdaughter=-1;
+ const Int_t kS=0;
// const Float_t tlife=0;
//
Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+
pmom[1]*pmom[1]+pmom[2]*pmom[2]);
- //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",
- //pname,mass,e,fNtrack,pdg,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],KS,mecha);
+ //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",
+ //pname,mass,e,fNtrack,pdg,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],kS,mecha);
- particle=new(particles[fNtrack]) TParticle(pdg,KS,parent,-1,firstdaughter,
- lastdaughter,pmom[0],pmom[1],pmom[2],
+ particle=new(particles[fNtrack]) TParticle(pdg,kS,parent,-1,kfirstdaughter,
+ klastdaughter,pmom[0],pmom[1],pmom[2],
e,vpos[0],vpos[1],vpos[2],tof);
// polar[0],polar[1],polar[2],tof,
// mecha,weight);
((TParticle*)particles[fNtrack])->SetPolarisation(TVector3(polar[0],polar[1],polar[2]));
((TParticle*)particles[fNtrack])->SetWeight(weight);
- if(!done) particle->SetBit(Done_Bit);
+ if(!done) particle->SetBit(kDoneBit);
+ //Declare that the daughter information is valid
+ ((TParticle*)particles[fNtrack])->SetBit(kDaughtersBit);
if(parent>=0) {
particle=(TParticle*) fParticles->UncheckedAt(parent);
// flags a track to be kept
//
TClonesArray &particles = *fParticles;
- ((TParticle*)particles[track])->SetBit(Keep_Bit);
+ ((TParticle*)particles[track])->SetBit(kKeepBit);
}
//_____________________________________________________________________________
if (!gAlice) gAlice = this;
gROOT->GetListOfBrowsables()->Add(this,"Run");
fTreeE = (TTree*)gDirectory->Get("TE");
- if (fTreeE) fTreeE->SetBranchAddress("Header", &header);
+ if (fTreeE) fTreeE->SetBranchAddress("Header", &gAliHeader);
else Error("Streamer","cannot find Header Tree\n");
R__b >> fNtrack;
R__b >> fHgwmk;