-//_____________________________________________________________________________
-void AliRun::MediaTable()
-{
- //
- // Built media table to get from the media number to
- // the detector id
- //
- Int_t kz, nz, idt, lz, i, k, ind;
- // Int_t ibeg;
- TObjArray &dets = *gAlice->Detectors();
- AliModule *det;
- //
- // For all detectors
- for (kz=0;kz<fNdets;kz++) {
- // If detector is defined
- if((det=(AliModule*) dets[kz])) {
- TArrayI &idtmed = *(det->GetIdtmed());
- for(nz=0;nz<100;nz++) {
- // Find max and min material number
- if((idt=idtmed[nz])) {
- det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
- det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
- }
- }
- if(det->LoMedium() > det->HiMedium()) {
- det->LoMedium() = 0;
- det->HiMedium() = 0;
- } else {
- if(det->HiMedium() > fImedia->GetSize()) {
- Error("MediaTable","Increase fImedia from %d to %d",
- fImedia->GetSize(),det->HiMedium());
- return;
- }
- // Tag all materials in rage as belonging to detector kz
- for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
- (*fImedia)[lz]=kz;
- }
- }
- }
- }
- //
- // Print summary table
- printf(" Traking media ranges:\n");
- for(i=0;i<(fNdets-1)/6+1;i++) {
- for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
- ind=i*6+k;
- det=(AliModule*)dets[ind];
- if(det)
- printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
- det->HiMedium());
- else
- printf(" %6s: %3d -> %3d;","NULL",0,0);
- }
- printf("\n");
- }
-}
-
-//____________________________________________________________________________
-void AliRun::SetGenerator(AliGenerator *generator)
-{
- //
- // Load the event generator
- //
- if(!fGenerator) fGenerator = generator;
-}
-
-//____________________________________________________________________________
-void AliRun::ResetGenerator(AliGenerator *generator)
-{
- //
- // Load the event generator
- //
- if(fGenerator)
- 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;
-}
-
-//____________________________________________________________________________
-void AliRun::SetTransPar(char *filename)
-{
- fTransParName = filename;
-}
-
-//____________________________________________________________________________
-void AliRun::SetBaseFile(char *filename)
-{
- fBaseFileName = *filename;
-}
-
-//____________________________________________________________________________
-void AliRun::OpenBaseFile(const char *option)
-{
- if(!strlen(fBaseFileName.Data())) {
- const char *filename;
- if ((filename=gSystem->Getenv("CONFIG_FILE"))) {
- fBaseFileName=filename;
- } else {
- fBaseFileName="galice.root";
- }
- }
- TFile *rootfile = new TFile(fBaseFileName.Data(),option);
- rootfile->SetCompressionLevel(2);
-}
-
-//____________________________________________________________________________
-void AliRun::ReadTransPar()
-{
- //
- // Read filename to set the transport parameters
- //
-
-
- 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[kncuts];
- Int_t flag[knflags];
- Int_t i, itmed, iret, ktmed, kz;
- FILE *lun;
- //
- // See whether the file is there
- filtmp=gSystem->ExpandPathName(fTransParName.Data());
- lun=fopen(filtmp,"r");
- delete [] filtmp;
- if(!lun) {
- Warning("ReadTransPar","File %s does not exist!\n",fTransParName.Data());
- return;
- }
- //
- printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
- printf(" *%59s\n","*");
- printf(" * Please check carefully what you are doing!%10s\n","*");
- printf(" *%59s\n","*");
- //
- while(1) {
- // Initialise cuts and flags
- 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
- iret=fscanf(lun,"%[^\n]",line);
- if(iret<0) {
- //End of file
- fclose(lun);
- printf(" *%59s\n","*");
- printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
- return;
- }
- // Read the end of line
- fscanf(lun,"%*c");
- if(!iret) continue;
- if(line[0]=='*') continue;
- // Read the numbers
- 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",
- detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
- &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
- &flag[8],&flag[9],&flag[10]);
- if(!iret) continue;
- if(iret<0) {
- //reading error
- Warning("ReadTransPar","Error reading file %s\n",fTransParName.Data());
- continue;
- }
- // Check that the module exist
- AliModule *mod = GetModule(detName);
- if(mod) {
- // Get the array of media numbers
- TArrayI &idtmed = *mod->GetIdtmed();
- // Check that the tracking medium code is valid
- if(0<=itmed && itmed < 100) {
- ktmed=idtmed[itmed];
- if(!ktmed) {
- Warning("ReadTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
- continue;
- }
- // Set energy thresholds
- for(kz=0;kz<kncuts;kz++) {
- if(cut[kz]>=0) {
- printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
- kpars[kz],cut[kz],itmed,mod->GetName());
- gMC->Gstpar(ktmed,kpars[kz],cut[kz]);
- }
- }
- // Set transport mechanisms
- for(kz=0;kz<knflags;kz++) {
- if(flag[kz]>=0) {
- printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
- kpars[kncuts+kz],flag[kz],itmed,mod->GetName());
- gMC->Gstpar(ktmed,kpars[kncuts+kz],Float_t(flag[kz]));
- }
- }
- } else {
- Warning("ReadTransPar","Invalid medium code %d *\n",itmed);
- continue;
- }
- } else {
- Warning("ReadTransPar","Module %s not present\n",detName);
- continue;
- }
- }
-}
-
-//_____________________________________________________________________________
-void AliRun::MakeBranchInTree(TTree *tree, const char* name, void* address, Int_t size, char *file)
-{
- if (GetDebug()>1)
- printf("* MakeBranch * Making Branch %s \n",name);
-
- TBranch *branch = tree->Branch(name,address,size);
-
- if (file) {
- TDirectory *cwd = gDirectory;
- branch->SetFile(file);
- TIter next( branch->GetListOfBranches());
- while ((branch=(TBranch*)next())) {
- branch->SetFile(file);
- }
- if (GetDebug()>1)
- printf("* MakeBranch * Diverting Branch %s to file %s\n",name,file);
- cwd->cd();
- }
-}
-
-//_____________________________________________________________________________
-void AliRun::MakeBranchInTree(TTree *tree, const char* name, const char *classname, void* address, Int_t size, Int_t splitlevel, char *file)
-{
- TDirectory *cwd = gDirectory;
- TBranch *branch = tree->Branch(name,classname,address,size,splitlevel);
- if (GetDebug()>1)
- printf("* MakeBranch * Making Branch %s \n",name);
- if (file) {
- branch->SetFile(file);
- TIter next( branch->GetListOfBranches());
- while ((branch=(TBranch*)next())) {
- branch->SetFile(file);
- }
- if (GetDebug()>1)
- printf("* MakeBranch * Diverting Branch %s to file %s\n",name,file);
- cwd->cd();
- }
-}
-//_____________________________________________________________________________
-void AliRun::MakeTree(Option_t *option, char *file)
-{
- //
- // Create the ROOT trees
- // Loop on all detectors to create the Root branch (if any)
- //
-
- char hname[30];
- //
- // Analyse options
- 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");
- char *oS = strstr(option,"S");
- //
-
- if (oK && !fTreeK) {
- sprintf(hname,"TreeK%d",fEvent);
- fTreeK = new TTree(hname,"Kinematics");
- // Create a branch for particles
- MakeBranchInTree(fTreeK,
- "Particles", "TParticle", &fParticleBuffer, 4000, 1, file) ;
- fTreeK->Write();
- }
- if (oH && !fTreeH) {
- sprintf(hname,"TreeH%d",fEvent);
- fTreeH = new TTree(hname,"Hits");
- fTreeH->SetAutoSave(1000000000); //no autosave
- fTreeH->Write();
- }
- if (oD && !fTreeD) {
- sprintf(hname,"TreeD%d",fEvent);
- fTreeD = new TTree(hname,"Digits");
- fTreeD->Write();
- }
- if (oS && !fTreeS) {
- sprintf(hname,"TreeS%d",fEvent);
- fTreeS = new TTree(hname,"SDigits");
- fTreeS->Write();
- }
- if (oR && !fTreeR) {
- sprintf(hname,"TreeR%d",fEvent);
- fTreeR = new TTree(hname,"Reconstruction");
- fTreeR->Write();
- }
- if (oE && !fTreeE) {
- fTreeE = new TTree("TE","Header");
- // Create a branch for Header
- MakeBranchInTree(fTreeE,
- "Header", "AliHeader", &gAliHeader, 4000, 1, file) ;
- fTreeE->Write();
- }
-
- //
- // Create a branch for hits/digits for each detector
- // Each branch is a TClonesArray. Each data member of the Hits classes
- // will be in turn a subbranch of the detector master branch
- TIter next(fModules);
- AliModule *detector;
- while((detector = (AliModule*)next())) {
- if (oH || oR) detector->MakeBranch(option,file);
- }
-}
-
-//_____________________________________________________________________________
-Int_t AliRun::PurifyKine(Int_t lastSavedTrack, Int_t nofTracks)
-{
- //
- // PurifyKine with external parameters
- //
- fHgwmk = lastSavedTrack;
- fNtrack = nofTracks;
- PurifyKine();
- return fHgwmk;
-}
-
-//_____________________________________________________________________________
-TParticle* AliRun::Particle(Int_t i)
-{
- if(!(*fParticleMap)[i]) {
- Int_t nentries = fParticles->GetEntries();
- fTreeK->GetEntry(fParticleFileMap[i]);
- new ((*fParticles)[nentries]) TParticle(*fParticleBuffer);
- fParticleMap->AddAt((*fParticles)[nentries],i);
- }
- return (TParticle *) (*fParticleMap)[i];
-}
-
-//_____________________________________________________________________________
-void AliRun::PurifyKine()
-{
- //
- // Compress kinematic tree keeping only flagged particles
- // and renaming the particle id's in all the hits
- //
- // TClonesArray &particles = *fParticles;
- TObjArray &particles = *fParticleMap;
- int nkeep=fHgwmk+1, parent, i;
- TParticle *part, *father;
- TArrayI map(particles.GetLast()+1);
-
- // Save in Header total number of tracks before compression
- fHeader.SetNtrack(fHeader.GetNtrack()+fNtrack-fHgwmk);
-
- // If no tracks generated return now
- if(fHgwmk+1 == fNtrack) return;
-
- Int_t toshrink = fNtrack-fHgwmk-1;
-
- // First pass, invalid Daughter information
- for(i=0; i<fNtrack; i++) {
- // Preset map, to be removed later
- if(i<=fHgwmk) map[i]=i ;
- else {
- map[i] = -99;
- // particles.UncheckedAt(i)->ResetBit(kDaughtersBit);
- if((part=(TParticle*) particles.At(i))) part->ResetBit(kDaughtersBit);
- }
- }
- // Invalid daughter information for the parent of the first particle
- // generated. This may or may not be the current primary according to
- // whether decays have been recorded among the primaries
- part = (TParticle *)particles.At(fHgwmk+1);
- particles.At(part->GetFirstMother())->ResetBit(kDaughtersBit);
- // Second pass, build map between old and new numbering
- for(i=fHgwmk+1; i<fNtrack; i++) {
- if(particles.At(i)->TestBit(kKeepBit)) {
-
- // This particle has to be kept
- map[i]=nkeep;
- // If old and new are different, have to move the pointer
- if(i!=nkeep) particles[nkeep]=particles.At(i);
- part = (TParticle*) particles.At(nkeep);
-
- // as the parent is always *before*, it must be already
- // in place. This is what we are checking anyway!
- if((parent=part->GetFirstMother())>fHgwmk)
- if(map[parent]==-99) Fatal("PurifyKine","map[%d] = -99!\n",parent);
- else part->SetFirstMother(map[parent]);
-
- nkeep++;
- }
- }
-
- // Fix daughters information
- for (i=fHgwmk+1; i<nkeep; i++) {
- part = (TParticle *)particles.At(i);
- parent = part->GetFirstMother();
- if(parent>=0) {
- father = (TParticle *)particles.At(parent);
- if(father->TestBit(kDaughtersBit)) {
-
- if(i<father->GetFirstDaughter()) father->SetFirstDaughter(i);
- if(i>father->GetLastDaughter()) father->SetLastDaughter(i);
- } else {
- // Initialise daughters info for first pass
- father->SetFirstDaughter(i);
- father->SetLastDaughter(i);
- father->SetBit(kDaughtersBit);
- }
- }
- }
-
- // Now loop on all registered hit lists
- TIter next(fHitLists);
- TCollection *hitList;
- while((hitList = (TCollection*)next())) {
- TIter nexthit(hitList);
- AliHit *hit;
- while((hit = (AliHit*)nexthit())) {
- hit->SetTrack(map[hit->GetTrack()]);
- }
- }
-
- //
- // 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.GetArray());
- }
-
- // Now the output bit, from fHgwmk to nkeep we write everything and we erase
- if(nkeep>fParticleFileMap.GetSize()) fParticleFileMap.Set(Int_t (nkeep*1.5));
-
-
- for (i=fHgwmk+1; i<nkeep; ++i) {
- fParticleBuffer = (TParticle*) particles.At(i);
- fParticleFileMap[i]=(Int_t) fTreeK->GetEntries();
- fTreeK->Fill();
- particles[i]=0;
- }
-
- for (i=nkeep; i<fNtrack; ++i) particles[i]=0;
-
- fLoadPoint-=toshrink;
- for(i=fLoadPoint; i<fLoadPoint+toshrink; ++i) fParticles->RemoveAt(i);
-
- fNtrack=nkeep;
- fHgwmk=nkeep-1;
- // delete [] map;
-}
-
-//_____________________________________________________________________________
-void AliRun::BeginEvent()
-{
- //
- // Reset all Detectors & kinematics & trees
- //
- char hname[30];
- //
-
- //
- if(fLego) {
- fLego->BeginEvent();
- return;
- }
-
- //
- ResetStack();
- ResetHits();
- ResetDigits();
- ResetSDigits();
-
- // Initialise event header
- fHeader.Reset(fRun,fEvent);
-
- if(fTreeK) {
- fTreeK->Reset();
- sprintf(hname,"TreeK%d",fEvent);
- fTreeK->SetName(hname);
- }
- if(fTreeH) {
- fTreeH->Reset();
- sprintf(hname,"TreeH%d",fEvent);
- fTreeH->SetName(hname);
- }
- if(fTreeD) {
- fTreeD->Reset();
- sprintf(hname,"TreeD%d",fEvent);
- fTreeD->SetName(hname);
- }
- if(fTreeS) {
- fTreeS->Reset();
- sprintf(hname,"TreeS%d",fEvent);
- fTreeS->SetName(hname);
- }
- if(fTreeR) {
- fTreeR->Reset();
- sprintf(hname,"TreeR%d",fEvent);
- fTreeR->SetName(hname);
- }
-}
-//_____________________________________________________________________________
-void AliRun::ResetDigits()
-{
- //
- // Reset all Detectors digits
- //
- TIter next(fModules);
- AliModule *detector;
- while((detector = (AliModule*)next())) {
- detector->ResetDigits();
- }
-}
-
-//_____________________________________________________________________________
-void AliRun::ResetSDigits()
-{
- //
- // Reset all Detectors digits
- //
- TIter next(fModules);
- AliModule *detector;
- while((detector = (AliModule*)next())) {
- detector->ResetSDigits();
- }
-}
-
-//_____________________________________________________________________________
-void AliRun::ResetHits()
-{
- //
- // Reset all Detectors hits
- //
- TIter next(fModules);
- AliModule *detector;
- while((detector = (AliModule*)next())) {
- detector->ResetHits();
- }
-}
-
-//_____________________________________________________________________________
-void AliRun::ResetPoints()
-{
- //
- // Reset all Detectors points
- //
- TIter next(fModules);
- AliModule *detector;
- while((detector = (AliModule*)next())) {
- detector->ResetPoints();
- }
-}