X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=STEER%2FAliRun.cxx;h=086bf4610e783b88b02a26108aea198c7132f9a8;hb=4d81e5e71462d9da2ef4ee054715df68ee5a850f;hp=8f4efd34b2ca3e318a0d9b91b89dc4ba01bd361c;hpb=b13db07708112d3e4e2a9bd74eef401898d18888;p=u%2Fmrichter%2FAliRoot.git diff --git a/STEER/AliRun.cxx b/STEER/AliRun.cxx index 8f4efd34b2c..086bf4610e7 100644 --- a/STEER/AliRun.cxx +++ b/STEER/AliRun.cxx @@ -13,24 +13,7 @@ * provided "as is" without express or implied warranty. * **************************************************************************/ -/* -$Log$ -Revision 1.24 2000/01/19 17:17:20 fca -Introducing a list of lists of hits -- more hits allowed for detector now - -Revision 1.23 1999/12/03 11:14:31 fca -Fixing previous wrong checking - -Revision 1.21 1999/11/25 10:40:08 fca -Fixing daughters information also in primary tracks - -Revision 1.20 1999/10/04 18:08:49 fca -Adding protection against inconsistent Euclid files - -Revision 1.19 1999/09/29 07:50:40 fca -Introduction of the Copyright and cvs Log - -*/ +/* $Id$ */ /////////////////////////////////////////////////////////////////////////////// // // @@ -57,68 +40,111 @@ Introduction of the Copyright and cvs Log // // /////////////////////////////////////////////////////////////////////////////// -#include -#include #include -#include #include +#include +#include +#include +#include +#include #include -#include - -#include "TParticle.h" -#include "AliRun.h" +#include +// +#include "AliLog.h" +#include "AliDetector.h" #include "AliDisplay.h" -#include "AliVMC.h" +#include "AliHeader.h" +#include "AliLego.h" +#include "AliLegoGenerator.h" +#include "AliMC.h" +#include "AliMagFC.h" +#include "AliMagFCM.h" +#include "AliMagFDM.h" +#include "AliPDG.h" +#include "AliRun.h" +#include "AliStack.h" +#ifdef __APPLE__ +#include "AliTPCTrackHitsInterfaces.h" +#endif -#include -#include -#include - AliRun *gAlice; -static AliHeader *header; - -static TArrayF sEventEnergy; -static TArrayF sSummEnergy; -static TArrayF sSum2Energy; - ClassImp(AliRun) -//_____________________________________________________________________________ -AliRun::AliRun() +//_______________________________________________________________________ +AliRun::AliRun(): + fRun(0), + fEvent(0), + fEventNrInRun(0), + fEventsPerRun(0), + fModules(0), + fGeometry(0), + fMCApp(0), + fDisplay(0), + fField(0), + fMC(0), + fNdets(0), + fInitDone(kFALSE), + fLego(0), + fPDGDB(0), //Particle factory object + fConfigFunction("\0"), + fRandom(0), + fRunLoader(0x0) { // // Default constructor for AliRun // - header=&fHeader; - fRun = 0; - fEvent = 0; - fCurrent = -1; - fModules = 0; - fGenerator = 0; - fTreeD = 0; - fTreeK = 0; - fTreeH = 0; - fTreeE = 0; - fTreeR = 0; - fParticles = 0; - fGeometry = 0; - fDisplay = 0; - fField = 0; - fMC = 0; - fNdets = 0; - fImedia = 0; - fTrRmax = 1.e10; - fTrZmax = 1.e10; - fInitDone = kFALSE; - fLego = 0; - fPDGDB = 0; //Particle factory object! - fHitLists = 0; -} - -//_____________________________________________________________________________ -AliRun::AliRun(const char *name, const char *title) - : TNamed(name,title) + AliConfig::Instance();//skowron 29 Feb 2002 + //ensures that the folder structure is build +} + +//_______________________________________________________________________ +AliRun::AliRun(const AliRun& arun): + TNamed(arun), + fRun(0), + fEvent(0), + fEventNrInRun(0), + fEventsPerRun(0), + fModules(0), + fGeometry(0), + fMCApp(0), + fDisplay(0), + fField(0), + fMC(0), + fNdets(0), + fInitDone(kFALSE), + fLego(0), + fPDGDB(0), //Particle factory object + fConfigFunction("\0"), + fRandom(0), + fRunLoader(0x0) +{ + // + // Copy constructor for AliRun + // + arun.Copy(*this); +} + +//_____________________________________________________________________________ +AliRun::AliRun(const char *name, const char *title): + TNamed(name,title), + fRun(0), + fEvent(0), + fEventNrInRun(0), + fEventsPerRun(0), + fModules(new TObjArray(77)), // Support list for the Detectors + fGeometry(0), + fMCApp(0), + fDisplay(0), + fField(0), + fMC(gMC), + fNdets(0), + fInitDone(kFALSE), + fLego(0), + fPDGDB(TDatabasePDG::Instance()), //Particle factory object! + fConfigFunction("Config();"), + fRandom(new TRandom3()), + fRunLoader(0x0) { // // Constructor for the main processor. @@ -126,130 +152,80 @@ AliRun::AliRun(const char *name, const char *title) // Creates the list of Detectors. // Creates the list of particles. // - Int_t i; - + gAlice = this; - fTreeD = 0; - fTreeK = 0; - fTreeH = 0; - fTreeE = 0; - fTreeR = 0; - fTrRmax = 1.e10; - fTrZmax = 1.e10; - fGenerator = 0; - fInitDone = kFALSE; - fLego = 0; - fField = 0; - + + // Set random number generator + gRandom = fRandom; + + if (gSystem->Getenv("CONFIG_SEED")) { + gRandom->SetSeed(static_cast(atoi(gSystem->Getenv("CONFIG_SEED")))); + } + + // Add to list of browsable gROOT->GetListOfBrowsables()->Add(this,name); - // - // create the support list for the various Detectors - fModules = new TObjArray(77); - // // Create the TNode geometry for the event display - BuildSimpleGeometry(); - - fNtrack=0; - fHgwmk=0; - fCurrent=-1; - header=&fHeader; - fRun = 0; - fEvent = 0; - // - // Create the particle stack - fParticles = new TClonesArray("TParticle",100); - - fDisplay = 0; - // // Create default mag field SetField(); - // - fMC = gMC; - // - // Prepare the tracking medium lists - fImedia = new TArrayI(1000); - for(i=0;i<1000;i++) (*fImedia)[i]=-99; - // - // Make particles - fPDGDB = TDatabasePDG::Instance(); //Particle factory object! - // - // Create HitLists list - fHitLists = new TList(); + + // Add particle list to configuration + AliConfig::Instance()->Add(fPDGDB); + +#ifdef __APPLE__ + // Terrible hack to avoid problem with the initialisation of + // static and globals on Mac OS X + AliClassAliTrackHitsInfo p1=galiclass____AliClassAliTrackHitsInfo; + AliClassAliTrackHitsParam p2=galiclass____AliTrackHitsParam; + AliClassAliHitInfo p3=galiclass____AliHitInfo; +#endif + } -//_____________________________________________________________________________ + +//_______________________________________________________________________ AliRun::~AliRun() { // - // Defaullt AliRun destructor + // Default AliRun destructor // - delete fImedia; + gROOT->GetListOfBrowsables()->Remove(this); + + if (fRunLoader) + { + TFolder* evfold = fRunLoader->GetEventFolder(); + TFolder* modfold = dynamic_cast(evfold->FindObjectAny(AliConfig::GetModulesFolderName())); + TIter next(fModules); + AliModule *mod; + while((mod = (AliModule*)next())) + { + modfold->Remove(mod); + } + } + + delete fField; - delete fMC; + delete fMCApp; + delete gMC; gMC=0; delete fGeometry; delete fDisplay; - delete fGenerator; delete fLego; - delete fTreeD; - delete fTreeK; - delete fTreeH; - delete fTreeE; - delete fTreeR; if (fModules) { fModules->Delete(); delete fModules; } - if (fParticles) { - fParticles->Delete(); - delete fParticles; - } - delete fHitLists; -} - -//_____________________________________________________________________________ -void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const -{ - // - // Add a hit to detector id - // - TObjArray &dets = *fModules; - if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits); -} - -//_____________________________________________________________________________ -void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const -{ - // - // Add digit to detector id - // - TObjArray &dets = *fModules; - if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits); + + delete fPDGDB; } -//_____________________________________________________________________________ -void AliRun::Browse(TBrowser *b) +//_______________________________________________________________________ +void AliRun::Copy(TObject &) const { - // - // Called when the item "Run" is clicked on the left pane - // of the Root browser. - // It displays the Root Trees and all detectors. - // - if (fTreeK) b->Add(fTreeK,fTreeK->GetName()); - if (fTreeH) b->Add(fTreeH,fTreeH->GetName()); - if (fTreeD) b->Add(fTreeD,fTreeD->GetName()); - if (fTreeE) b->Add(fTreeE,fTreeE->GetName()); - if (fTreeR) b->Add(fTreeR,fTreeR->GetName()); - - TIter next(fModules); - AliModule *detector; - while((detector = (AliModule*)next())) { - b->Add(detector,detector->GetName()); - } + AliFatal("Not implemented!"); } -//_____________________________________________________________________________ +//_______________________________________________________________________ void AliRun::Build() { // @@ -258,7 +234,7 @@ void AliRun::Build() // } -//_____________________________________________________________________________ +//_______________________________________________________________________ void AliRun::BuildSimpleGeometry() { // @@ -273,79 +249,40 @@ void AliRun::BuildSimpleGeometry() new TNode("alice","alice","S_alice"); } -//_____________________________________________________________________________ +//_______________________________________________________________________ void AliRun::CleanDetectors() { // // Clean Detectors at the end of event // - TIter next(fModules); - AliModule *detector; - while((detector = (AliModule*)next())) { - detector->FinishEvent(); - } + fRunLoader->CleanDetectors(); } -//_____________________________________________________________________________ -void AliRun::CleanParents() +//_______________________________________________________________________ +void AliRun::ResetHits() { - // - // Clean Particles stack. - // Set parent/daughter relations - // - TClonesArray &particles = *(gAlice->Particles()); - TParticle *part; - int i; - for(i=0; iTestBit(Daughters_Bit)) { - part->SetFirstDaughter(-1); - part->SetLastDaughter(-1); - } - } + fMCApp->ResetHits(); } -//_____________________________________________________________________________ -Int_t AliRun::DistancetoPrimitive(Int_t, Int_t) +//_______________________________________________________________________ +AliGenerator* AliRun::Generator() const { - // - // Return the distance from the mouse to the AliRun object - // Dummy routine - // - return 9999; + return fMCApp->Generator(); } -//_____________________________________________________________________________ -void AliRun::DumpPart (Int_t i) +//_______________________________________________________________________ +void AliRun::SetField(AliMagF* magField) { // - // Dumps particle i in the stack + // Set Magnetic Field Map // - TClonesArray &particles = *fParticles; - ((TParticle*) particles[i])->Print(); + fField = magField; + fField->ReadField(); } -//_____________________________________________________________________________ -void AliRun::DumpPStack () -{ - // - // Dumps the particle stack - // - TClonesArray &particles = *fParticles; - printf( - "\n\n=======================================================================\n"); - for (Int_t i=0;i %d ",i); ((TParticle*) particles[i])->Print(); - printf("--------------------------------------------------------------\n"); - } - printf( - "\n=======================================================================\n\n"); -} - -//_____________________________________________________________________________ +//_______________________________________________________________________ void AliRun::SetField(Int_t type, Int_t version, Float_t scale, - Float_t maxField, char* filename) + Float_t maxField, const char* filename) { // // Set magnetic field parameters @@ -356,267 +293,121 @@ void AliRun::SetField(Int_t type, Int_t version, Float_t scale, // // --- Sanity check on mag field flags - if(type<0 || type > 2) { - Warning("SetField", - "Invalid magnetic field flag: %5d; Helix tracking chosen instead\n" - ,type); - type=2; - } if(fField) delete fField; if(version==1) { - fField = new AliMagFC("Map1"," ",type,version,scale,maxField); - } else if(version<=3) { - fField = new AliMagFCM("Map2-3",filename,type,version,scale,maxField); + fField = new AliMagFC("Map1"," ",type,scale,maxField); + } else if(version<=2) { + fField = new AliMagFCM("Map2-3",filename,type,scale,maxField); + fField->ReadField(); + } else if(version==3) { + fField = new AliMagFDM("Map4",filename,type,scale,maxField); fField->ReadField(); } else { - Warning("SetField","Invalid map %d\n",version); + AliWarning(Form("Invalid map %d",version)); } } //_____________________________________________________________________________ -void AliRun::FillTree() -{ - // - // Fills all AliRun TTrees - // - if (fTreeK) fTreeK->Fill(); - if (fTreeH) fTreeH->Fill(); - if (fTreeD) fTreeD->Fill(); - if (fTreeR) fTreeR->Fill(); -} - -//_____________________________________________________________________________ -void AliRun::FinishPrimary() -{ - // - // Called at the end of each primary track - // - - // static Int_t count=0; - // const Int_t times=10; - // This primary is finished, purify stack - gAlice->PurifyKine(); - - // Write out hits if any - if (gAlice->TreeH()) { - gAlice->TreeH()->Fill(); - } - - // Reset Hits info - gAlice->ResetHits(); - - // - // if(++count%times==1) gObjectTable->Print(); -} -//_____________________________________________________________________________ -void AliRun::FinishEvent() +void AliRun::InitLoaders() { - // - // Called at the end of the event. - // - - //Update the energy deposit tables - Int_t i; - for(i=0;iFill(); - } - - // Write out the digits - if (fTreeD) { - fTreeD->Fill(); - ResetDigits(); - } - - // Write out reconstructed clusters - if (fTreeR) { - fTreeR->Fill(); - } - - // Write out the event Header information - if (fTreeE) fTreeE->Fill(); - - // Reset stack info - ResetStack(); - - // Write Tree headers - // Int_t ievent = fHeader.GetEvent(); - // char hname[30]; - // sprintf(hname,"TreeK%d",ievent); - if (fTreeK) fTreeK->Write(); - // sprintf(hname,"TreeH%d",ievent); - if (fTreeH) fTreeH->Write(); - // sprintf(hname,"TreeD%d",ievent); - if (fTreeD) fTreeD->Write(); - // sprintf(hname,"TreeR%d",ievent); - if (fTreeR) fTreeR->Write(); + //creates list of getters + AliDebug(1, ""); + TIter next(fModules); + AliModule *mod; + while((mod = (AliModule*)next())) + { + mod->SetRunLoader(fRunLoader); + AliDetector *det = dynamic_cast(mod); + if (det) + { + AliDebug(2, Form("Adding %s", det->GetName())); + fRunLoader->AddLoader(det); + } + } + AliDebug(1, "Done"); } - //_____________________________________________________________________________ + void AliRun::FinishRun() { // // Called at the end of the run. // - + + if(fLego) + { + AliDebug(1, "Finish Lego"); + fRunLoader->CdGAFile(); + fLego->FinishRun(); + } + // Clean detector information TIter next(fModules); AliModule *detector; - while((detector = (AliModule*)next())) { + while((detector = dynamic_cast(next()))) { + AliDebug(2, Form("%s->FinishRun()", detector->GetName())); detector->FinishRun(); } - //Output energy summary tables - 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 ) { - Error("FinishRun","There isn't root file!"); - exit(1); - } - File->cd(); - fTreeE->Write(); - - // Clean tree information - delete fTreeK; fTreeK = 0; - delete fTreeH; fTreeH = 0; - delete fTreeD; fTreeD = 0; - delete fTreeR; fTreeR = 0; - delete fTreeE; fTreeE = 0; - + AliDebug(1, "fRunLoader->WriteHeader(OVERWRITE)"); + fRunLoader->WriteHeader("OVERWRITE"); + // Write AliRun info and all detectors parameters - Write(); + fRunLoader->CdGAFile(); + Write(0,TObject::kOverwrite);//write AliRun + fRunLoader->Write(0,TObject::kOverwrite);//write RunLoader itself - // Close output file - File->Write(); -} + // Clean tree information + AliDebug(1, "fRunLoader->Stack()->FinishRun()"); + fRunLoader->Stack()->FinishRun(); -//_____________________________________________________________________________ -void AliRun::FlagTrack(Int_t track) -{ - // - // Flags a track and all its family tree to be kept - // - int curr; - TParticle *particle; + if(fMCApp) fMCApp->FinishRun(); - curr=track; - while(1) { - particle=(TParticle*)fParticles->UncheckedAt(curr); - - // If the particle is flagged the three from here upward is saved already - if(particle->TestBit(Keep_Bit)) return; - - // Save this particle - particle->SetBit(Keep_Bit); - - // Move to father if any - if((curr=particle->GetFirstMother())==-1) return; - } + fRunLoader->Synchronize(); } - -//_____________________________________________________________________________ -void AliRun::EnergySummary() + +//_______________________________________________________________________ +void AliRun::Announce() const { // - // Print summary of deposited energy + // Announce the current version of AliRoot // + printf("%70s", + "****************************************************************\n"); + printf("%6s","*");printf("%64s","*\n"); - Int_t ndep=0; - Float_t edtot=0; - Float_t ed, ed2; - Int_t kn, i, left, j, id; - const Float_t zero=0; - Int_t ievent=fHeader.GetEvent()+1; - // - // Energy loss information - if(ievent) { - printf("***************** Energy Loss Information per event (GEV) *****************\n"); - for(kn=1;kn0) { - sEventEnergy[ndep]=kn; - if(ievent>1) { - ed=ed/ievent; - ed2=sSum2Energy[kn]; - ed2=ed2/ievent; - ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,zero))/ed; - } else - ed2=99; - sSummEnergy[ndep]=ed; - sSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,zero)); - edtot+=ed; - ndep++; - } - } - for(kn=0;kn<(ndep-1)/3+1;kn++) { - left=ndep-kn*3; - for(i=0;i<(3VolName(id),sSummEnergy[j],sSum2Energy[j]); - } - printf("\n"); - } - // - // Relative energy loss in different detectors - printf("******************** Relative Energy Loss per event ********************\n"); - printf("Total energy loss per event %10.3f GeV\n",edtot); - for(kn=0;kn<(ndep-1)/5+1;kn++) { - left=ndep-kn*5; - for(i=0;i<(5VolName(id),100*sSummEnergy[j]/edtot); - } - printf("\n"); - } - for(kn=0;kn<75;kn++) printf("*"); - printf("\n"); - } - // - // Reset the TArray's - // sEventEnergy.Set(0); - // sSummEnergy.Set(0); - // sSum2Energy.Set(0); + printf("%6s","*"); + printf(" You are running AliRoot version NewIO\n"); + + printf("%6s","*"); + printf(" The cvs tag for the current program is $Name$\n"); + + printf("%6s","*");printf("%64s","*\n"); + printf("%70s", + "****************************************************************\n"); } -//_____________________________________________________________________________ -AliModule *AliRun::GetModule(const char *name) +//_______________________________________________________________________ +AliModule *AliRun::GetModule(const char *name) const { // // Return pointer to detector from name // - return (AliModule*)fModules->FindObject(name); + return dynamic_cast(fModules->FindObject(name)); } -//_____________________________________________________________________________ -AliDetector *AliRun::GetDetector(const char *name) +//_______________________________________________________________________ +AliDetector *AliRun::GetDetector(const char *name) const { // // Return pointer to detector from name // - return (AliDetector*)fModules->FindObject(name); + return dynamic_cast(fModules->FindObject(name)); } -//_____________________________________________________________________________ -Int_t AliRun::GetModuleID(const char *name) +//_______________________________________________________________________ +Int_t AliRun::GetModuleID(const char *name) const { // // Return galice internal detector identifier from name @@ -627,78 +418,56 @@ Int_t AliRun::GetModuleID(const char *name) return i; } -//_____________________________________________________________________________ +//_______________________________________________________________________ Int_t AliRun::GetEvent(Int_t event) { - // - // Connect the Trees Kinematics and Hits for event # event - // Set branch addresses - // - - // Reset existing structures - ResetStack(); - ResetHits(); +// +// Reloads data containers in folders # event +// Set branch addresses +// + if (fRunLoader == 0x0) + { + AliError("RunLoader is not set. Can not load data."); + return -1; + } +/*****************************************/ +/**** P R E R E L O A D I N G ****/ +/*****************************************/ +// Reset existing structures + fMCApp->ResetHits(); + fMCApp->ResetTrackReferences(); ResetDigits(); - - // Delete Trees already connected - if (fTreeK) delete fTreeK; - if (fTreeH) delete fTreeH; - if (fTreeD) delete fTreeD; - if (fTreeR) delete fTreeR; - - // Get header from file - if(fTreeE) fTreeE->GetEntry(event); - else Error("GetEvent","Cannot file Header Tree\n"); - - // Get Kine Tree from file - char treeName[20]; - sprintf(treeName,"TreeK%d",event); - fTreeK = (TTree*)gDirectory->Get(treeName); - if (fTreeK) fTreeK->SetBranchAddress("Particles", &fParticles); - else Error("GetEvent","cannot find Kine Tree for event:%d\n",event); - - // Get Hits Tree header from file - sprintf(treeName,"TreeH%d",event); - fTreeH = (TTree*)gDirectory->Get(treeName); - if (!fTreeH) { - Error("GetEvent","cannot find Hits Tree for event:%d\n",event); - } - - // Get Digits Tree header from file - sprintf(treeName,"TreeD%d",event); - fTreeD = (TTree*)gDirectory->Get(treeName); - if (!fTreeD) { - Warning("GetEvent","cannot find Digits Tree for event:%d\n",event); - } - - - // Get Reconstruct Tree header from file - sprintf(treeName,"TreeR%d",event); - fTreeR = (TTree*)gDirectory->Get(treeName); - if (!fTreeR) { - // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event); - } - + ResetSDigits(); + +/*****************************************/ +/**** R E L O A D ****/ +/*****************************************/ + + fRunLoader->GetEvent(event); + +/*****************************************/ +/**** P O S T R E L O A D I N G ****/ +/*****************************************/ + // Set Trees branch addresses TIter next(fModules); AliModule *detector; - while((detector = (AliModule*)next())) { - detector->SetTreeAddress(); - } - - if (fTreeK) fTreeK->GetEvent(0); - fNtrack = Int_t (fParticles->GetEntries()); - return fNtrack; + while((detector = dynamic_cast(next()))) + { + detector->SetTreeAddress(); + } + + return fRunLoader->GetHeader()->GetNtrack(); } -//_____________________________________________________________________________ +//_______________________________________________________________________ TGeometry *AliRun::GetGeometry() { // // Import Alice geometry from current file // Return pointer to geometry object // - if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom"); + if (!fGeometry) fGeometry = dynamic_cast(gDirectory->Get("AliceGeom")); // // Unlink and relink nodes in detectors // This is bad and there must be a better way... @@ -706,13 +475,12 @@ TGeometry *AliRun::GetGeometry() TIter next(fModules); AliModule *detector; - while((detector = (AliModule*)next())) { - detector->SetTreeAddress(); + while((detector = dynamic_cast(next()))) { TList *dnodes=detector->Nodes(); Int_t j; TNode *node, *node1; for ( j=0; jGetSize(); j++) { - node = (TNode*) dnodes->At(j); + node = dynamic_cast(dnodes->At(j)); node1 = fGeometry->GetNode(node->GetName()); dnodes->Remove(node); dnodes->AddAt(node1,j); @@ -721,578 +489,248 @@ TGeometry *AliRun::GetGeometry() return fGeometry; } -//_____________________________________________________________________________ -void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom, - Float_t &e, Float_t *vpos, Float_t *polar, - Float_t &tof) +//_______________________________________________________________________ +void AliRun::SetBaseFile(const char *filename) { - // - // Return next track from stack of particles - // - TVector3 pol; - fCurrent=-1; - TParticle *track; - for(Int_t i=fNtrack-1; i>=0; i--) { - track=(TParticle*) fParticles->UncheckedAt(i); - if(!track->TestBit(Done_Bit)) { - // - // The track has not yet been processed - fCurrent=i; - ipart=track->GetPdgCode(); - pmom[0]=track->Px(); - pmom[1]=track->Py(); - pmom[2]=track->Pz(); - e =track->Energy(); - vpos[0]=track->Vx(); - vpos[1]=track->Vy(); - vpos[2]=track->Vz(); - track->GetPolarisation(pol); - polar[0]=pol.X(); - polar[1]=pol.Y(); - polar[2]=pol.Z(); - tof=track->T(); - track->SetBit(Done_Bit); - break; - } - } - mtrack=fCurrent; - // - // stop and start timer when we start a primary track - Int_t nprimaries = fHeader.GetNprimary(); - if (fCurrent >= nprimaries) return; - if (fCurrent < nprimaries-1) { - fTimer.Stop(); - track=(TParticle*) fParticles->UncheckedAt(fCurrent+1); - // track->SetProcessTime(fTimer.CpuTime()); - } - fTimer.Start(); + fBaseFileName = filename; } -//_____________________________________________________________________________ -Int_t AliRun::GetPrimary(Int_t track) +//_______________________________________________________________________ +void AliRun::ResetDigits() { // - // return number of primary that has generated track - // - int current, parent; - TParticle *part; + // Reset all Detectors digits // - parent=track; - while (1) { - current=parent; - part = (TParticle *)fParticles->UncheckedAt(current); - parent=part->GetFirstMother(); - if(parent<0) return current; + TIter next(fModules); + AliModule *detector; + while((detector = dynamic_cast(next()))) { + detector->ResetDigits(); } } - -//_____________________________________________________________________________ -void AliRun::Init(const char *setup) -{ - // - // Initialize the Alice setup - // - - gROOT->LoadMacro(setup); - gInterpreter->ProcessLine("Config();"); - - gMC->DefineParticles(); //Create standard MC particles - - TObject *objfirst, *objlast; - - fNdets = fModules->GetLast()+1; - - // - //=================Create Materials, geometry, histograms, etc - TIter next(fModules); - AliModule *detector; - while((detector = (AliModule*)next())) { - detector->SetTreeAddress(); - objlast = gDirectory->GetList()->Last(); - - // Initialise detector materials, geometry, histograms,etc - detector->CreateMaterials(); - detector->CreateGeometry(); - detector->BuildGeometry(); - detector->Init(); - - // Add Detector histograms in Detector list of histograms - if (objlast) objfirst = gDirectory->GetList()->After(objlast); - else objfirst = gDirectory->GetList()->First(); - while (objfirst) { - detector->Histograms()->Add(objfirst); - objfirst = gDirectory->GetList()->After(objfirst); - } - } - SetTransPar(); //Read the cuts for all materials - - MediaTable(); //Build the special IMEDIA table - - //Terminate building of geometry - printf("%p\n",gVMC); - gVMC->FinishGeometry(); - - //Initialise geometry deposition table - sEventEnergy.Set(gMC->NofVolumes()+1); - sSummEnergy.Set(gMC->NofVolumes()+1); - sSum2Energy.Set(gMC->NofVolumes()+1); - - //Compute cross-sections - gVMC->BuildPhysics(); - - //Write Geometry object to current file. - fGeometry->Write(); - - fInitDone = kTRUE; -} -//_____________________________________________________________________________ -void AliRun::MediaTable() +//_______________________________________________________________________ +void AliRun::ResetSDigits() { // - // 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;kzGetIdtmed()); - 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; - } - } - } - } + // Reset all Detectors digits // - // Print summary table - printf(" Traking media ranges:\n"); - for(i=0;i<(fNdets-1)/6+1;i++) { - for(k=0;k< (6 %3d;",det->GetName(),det->LoMedium(), - det->HiMedium()); - else - printf(" %6s: %3d -> %3d;","NULL",0,0); - } - printf("\n"); + TIter next(fModules); + AliModule *detector; + while((detector = dynamic_cast(next()))) { + detector->ResetSDigits(); } } -//____________________________________________________________________________ -void AliRun::SetGenerator(AliGenerator *generator) -{ - // - // Load the event generator - // - if(fGenerator) - Warning("SetGenerator","Replacing generator %s with %s\n", - fGenerator->GetName(),generator->GetName()); - fGenerator = generator; -} - -//____________________________________________________________________________ -void AliRun::SetTransPar(char* filename) -{ - // - // Read filename to set the transport parameters - // +//_______________________________________________________________________ - 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", - "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]; - Int_t i, itmed, iret, ktmed, kz; - FILE *lun; - // - // See whether the file is there - filtmp=gSystem->ExpandPathName(filename); - lun=fopen(filtmp,"r"); - delete [] filtmp; - if(!lun) { - Warning("SetTransPar","File %s does not exist!\n",filename); - 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;iGetIdtmed(); - // Check that the tracking medium code is valid - if(0<=itmed && itmed < 100) { - ktmed=idtmed[itmed]; - if(!ktmed) { - Warning("SetTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName()); - continue; - } - // Set energy thresholds - for(kz=0;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]); - } - } - // Set transport mechanisms - for(kz=0;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])); - } - } - } else { - Warning("SetTransPar","Invalid medium code %d *\n",itmed); - continue; - } - } else { - Warning("SetTransPar","Module %s not present\n",detName); - continue; - } - } -} - -//_____________________________________________________________________________ -void AliRun::MakeTree(Option_t *option) +void AliRun::ResetPoints() { // - // Create the ROOT trees - // Loop on all detectors to create the Root branch (if any) - // - - 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"); - // - if (K && !fTreeK) { - sprintf(hname,"TreeK%d",fEvent); - fTreeK = new TTree(hname,"Kinematics"); - // Create a branch for particles - fTreeK->Branch("Particles",&fParticles,4000); - } - if (H && !fTreeH) { - sprintf(hname,"TreeH%d",fEvent); - fTreeH = new TTree(hname,"Hits"); - fTreeH->SetAutoSave(1000000000); //no autosave - } - if (D && !fTreeD) { - sprintf(hname,"TreeD%d",fEvent); - fTreeD = new TTree(hname,"Digits"); - } - if (R && !fTreeR) { - sprintf(hname,"TreeR%d",fEvent); - fTreeR = new TTree(hname,"Reconstruction"); - } - if (E && !fTreeE) { - fTreeE = new TTree("TE","Header"); - // Create a branch for Header - fTreeE->Branch("Header","AliHeader",&header,4000); - } + // Reset all Detectors points // - // 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 (H || D || R) detector->MakeBranch(option); + while((detector = dynamic_cast(next()))) { + detector->ResetPoints(); } } +//_______________________________________________________________________ -//_____________________________________________________________________________ -Int_t AliRun::PurifyKine(Int_t lastSavedTrack, Int_t nofTracks) +void AliRun::InitMC(const char *setup) { // - // PurifyKine with external parameters + // Initialize ALICE Simulation run // - fHgwmk = lastSavedTrack; - fNtrack = nofTracks; - PurifyKine(); - return fHgwmk; -} + Announce(); -//_____________________________________________________________________________ -void AliRun::PurifyKine() -{ - // - // Compress kinematic tree keeping only flagged particles - // and renaming the particle id's in all the hits - // - TClonesArray &particles = *fParticles; - int nkeep=fHgwmk+1, parent, i; - TParticle *part, *partnew, *father; - int *map = new int[particles.GetEntries()]; - - // Save in Header total number of tracks before compression - fHeader.SetNtrack(fHeader.GetNtrack()+fNtrack-fHgwmk); - - // Preset map, to be removed later - for(i=0; iTestBit(Keep_Bit)) { - - // This particle has to be kept - map[i]=nkeep; - if(i!=nkeep) { - - // Old and new are different, have to copy - partnew = (TParticle *)particles.UncheckedAt(nkeep); - *partnew = *part; - } else partnew = part; - - // as the parent is always *before*, it must be already - // in place. This is what we are checking anyway! - if((parent=partnew->GetFirstMother())>fHgwmk) { - if(map[parent]==-99) printf("map[%d] = -99!\n",parent); - partnew->SetFirstMother(map[parent]); - } - nkeep++; - } + if(fInitDone) { + AliWarning("Cannot initialise AliRun twice!"); + return; } - fNtrack=nkeep; - - // Fix daughters information - for (i=0; iGetFirstMother(); - if(parent>=0) { - father = (TParticle *)particles.UncheckedAt(parent); - if(father->TestBit(Daughters_Bit)) { + + if (!fMCApp) + fMCApp=new AliMC(GetName(),GetTitle()); + + gROOT->LoadMacro(setup); + gInterpreter->ProcessLine(fConfigFunction.Data()); + + fRunLoader->CdGAFile(); + + AliPDG::AddParticlesToPdgDataBase(); + + fNdets = fModules->GetLast()+1; + + TIter next(fModules); + for(Int_t i=0; i(fModules->At(i)); + objlast = gDirectory->GetList()->Last(); - if(iGetFirstDaughter()) father->SetFirstDaughter(i); - if(i>father->GetLastDaughter()) father->SetLastDaughter(i); - } else { - // Iitialise daughters info for first pass - father->SetFirstDaughter(i); - father->SetLastDaughter(i); - father->SetBit(Daughters_Bit); + // Add Detector histograms in Detector list of histograms + if (objlast) objfirst = gDirectory->GetList()->After(objlast); + else objfirst = gDirectory->GetList()->First(); + while (objfirst) + { + detector->Histograms()->Add(objfirst); + objfirst = gDirectory->GetList()->After(objfirst); } + } + + fMCApp->Init(); + + //Must be here because some MCs (G4) adds detectors here and not in Config.C + InitLoaders(); + fRunLoader->MakeTree("E"); + if (fLego == 0x0) + { + fRunLoader->LoadKinematics("RECREATE"); + fRunLoader->LoadTrackRefs("RECREATE"); + fRunLoader->LoadHits("all","RECREATE"); } - } - -#ifdef old - // Now loop on all detectors and reset the hits - AliHit *OneHit; - TIter next(fModules); - AliModule *detector; - while((detector = (AliModule*)next())) { - if (!detector->Hits()) continue; - TClonesArray &vHits=*(detector->Hits()); - if(vHits.GetEntries() != detector->GetNhits()) - printf("vHits.GetEntries()!=detector->GetNhits(): %d != %d\n", - vHits.GetEntries(),detector->GetNhits()); - for (i=0; iGetNhits(); i++) { - OneHit = (AliHit *)vHits.UncheckedAt(i); - OneHit->SetTrack(map[OneHit->GetTrack()]); - } - } -#else - - // 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()]); - } - } -#endif - - fHgwmk=nkeep-1; - particles.SetLast(fHgwmk); - delete [] map; + fInitDone = kTRUE; + // + // Save stuff at the beginning of the file to avoid file corruption + fRunLoader->CdGAFile(); + Write(); + fEventNrInRun = -1; //important - we start Begin event from increasing current number in run } -//_____________________________________________________________________________ -void AliRun::Reset(Int_t run, Int_t idevent) +//_______________________________________________________________________ + +void AliRun::RunMC(Int_t nevent, const char *setup) { // - // Reset all Detectors & kinematics & trees - // - char hname[30]; + // Main function to be called to process a galice run + // example + // Root > gAlice.Run(); + // a positive number of events will cause the finish routine + // to be called // - ResetStack(); - ResetHits(); - ResetDigits(); + fEventsPerRun = nevent; + // check if initialisation has been done + if (!fInitDone) InitMC(setup); + + // Create the Root Tree with one branch per detector + //Hits moved to begin event -> now we are crating separate tree for each event - // Initialise event header - fHeader.Reset(run,idevent); + gMC->ProcessRun(nevent); - if(fTreeK) { - fTreeK->Reset(); - sprintf(hname,"TreeK%d",idevent); - fTreeK->SetName(hname); - } - if(fTreeH) { - fTreeH->Reset(); - sprintf(hname,"TreeH%d",idevent); - fTreeH->SetName(hname); - } - if(fTreeD) { - fTreeD->Reset(); - sprintf(hname,"TreeD%d",idevent); - fTreeD->SetName(hname); - } - if(fTreeR) { - fTreeR->Reset(); - sprintf(hname,"TreeR%d",idevent); - fTreeR->SetName(hname); - } + // End of this run, close files + if(nevent>0) FinishRun(); } -//_____________________________________________________________________________ -void AliRun::ResetDigits() +//_______________________________________________________________________ +void AliRun::RunReco(const char *selected, Int_t first, Int_t last) { // - // Reset all Detectors digits - // - TIter next(fModules); - AliModule *detector; - while((detector = (AliModule*)next())) { - detector->ResetDigits(); - } + // Main function to be called to reconstruct Alice event + // + Int_t nev = fRunLoader->GetNumberOfEvents(); + AliDebug(1, Form("Found %d events", nev)); + Int_t nFirst = first; + Int_t nLast = (last < 0)? nev : last; + + for (Int_t nevent = nFirst; nevent <= nLast; nevent++) { + AliDebug(1, Form("Processing event %d", nevent)); + GetEvent(nevent); + Digits2Reco(selected); + } } -//_____________________________________________________________________________ -void AliRun::ResetHits() -{ - // - // Reset all Detectors hits - // - TIter next(fModules); - AliModule *detector; - while((detector = (AliModule*)next())) { - detector->ResetHits(); - } -} +//_______________________________________________________________________ -//_____________________________________________________________________________ -void AliRun::ResetPoints() +void AliRun::Hits2Digits(const char *selected) { - // - // Reset all Detectors points - // - TIter next(fModules); - AliModule *detector; - while((detector = (AliModule*)next())) { - detector->ResetPoints(); - } + + // Convert Hits to sumable digits + // + for (Int_t nevent=0; neventTreeE()->GetEntries(); nevent++) { + GetEvent(nevent); + Hits2SDigits(selected); + SDigits2Digits(selected); + } } -//_____________________________________________________________________________ -void AliRun::Run(Int_t nevent, const char *setup) + +//_______________________________________________________________________ + +void AliRun::Tree2Tree(Option_t *option, const char *selected) { // - // Main function to be called to process a galice run - // example - // Root > gAlice.Run(); - // a positive number of events will cause the finish routine - // to be called - // - - Int_t i, todo; - // check if initialisation has been done - if (!fInitDone) Init(setup); - - // Create the Root Tree with one branch per detector - gAlice->MakeTree("KHDER"); - - todo = TMath::Abs(nevent); - for (i=0; iReset(fRun, fEvent); - gVMC->ProcessEvent(); - gAlice->FinishEvent(); - fEvent++; - } - - // End of this run, close files - if(nevent>0) gAlice->FinishRun(); + // Function to transform the content of + // + // - TreeH to TreeS (option "S") + // - TreeS to TreeD (option "D") + // - TreeD to TreeR (option "R") + // + // If multiple options are specified ("SDR"), transformation will be done in sequence for + // selected detector and for all detectors if none is selected (detector string + // can contain blank separated list of detector names). + + + const char *oS = strstr(option,"S"); + const char *oD = strstr(option,"D"); + const char *oR = strstr(option,"R"); + + TObjArray *detectors = Detectors(); + + TIter next(detectors); + + AliDetector *detector = 0; + + while((detector = dynamic_cast(next()))) { + if (selected) + if (strcmp(detector->GetName(),selected)) continue; + if (detector->IsActive()) + { + + AliLoader* loader = detector->GetLoader(); + if (loader == 0x0) continue; + + if (oS) + { + AliDebug(1, Form("Processing Hits2SDigits for %s ...", detector->GetName())); + loader->LoadHits("read"); + if (loader->TreeS() == 0x0) loader->MakeTree("S"); + detector->MakeBranch(option); + detector->SetTreeAddress(); + detector->Hits2SDigits(); + loader->UnloadHits(); + loader->UnloadSDigits(); + } + if (oD) + { + AliDebug(1, Form("Processing SDigits2Digits for %s ...", detector->GetName())); + loader->LoadSDigits("read"); + if (loader->TreeD() == 0x0) loader->MakeTree("D"); + detector->MakeBranch(option); + detector->SetTreeAddress(); + detector->SDigits2Digits(); + loader->UnloadSDigits(); + loader->UnloadDigits(); + } + if (oR) + { + AliDebug(1, Form("Processing Digits2Reco for %s ...", detector->GetName())); + loader->LoadDigits("read"); + if (loader->TreeR() == 0x0) loader->MakeTree("R"); + detector->MakeBranch(option); + detector->SetTreeAddress(); + detector->Digits2Reco(); + loader->UnloadDigits(); + loader->UnloadRecPoints(); + + } + } + } } -//_____________________________________________________________________________ -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: @@ -1333,176 +771,210 @@ void AliRun::RunLego(const char *setup,Int_t ntheta,Float_t themin, // // check if initialisation has been done - if (!fInitDone) Init(setup); + // If runloader has been initialized, set the number of events per file to nc1 * nc2 + // Set new generator + if (!gener) gener = new AliLegoGenerator(); + // + // 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); - //Run Lego Object - fLego->Run(); + if (!fInitDone) InitMC(setup); + //Save current generator + + AliGenerator *gen=fMCApp->Generator(); + fMCApp->ResetGenerator(gener); + //Prepare MC for Lego Run + gMC->InitLego(); - // Create only the Root event Tree - gAlice->MakeTree("E"); + //Run Lego Object + + if (fRunLoader) fRunLoader->SetNumberOfEventsPerFile(nc1 * nc2); + //gMC->ProcessRun(nc1*nc2+1); + gMC->ProcessRun(nc1*nc2); // End of this run, close files - gAlice->FinishRun(); + FinishRun(); + // Restore current generator + fMCApp->ResetGenerator(gen); + // Delete Lego Object + delete fLego; fLego=0; } -//_____________________________________________________________________________ -void AliRun::SetCurrentTrack(Int_t track) -{ +//_______________________________________________________________________ +void AliRun::SetConfigFunction(const char * config) +{ // - // Set current track number + // Set the signature of the function contained in Config.C to configure + // the run // - fCurrent = track; + 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) -{ - // - // Load a track on the stack - // - // done 0 if the track has to be transported - // 1 if not - // parent identifier of the parent track. -1 for a primary - // pdg particle code - // pmom momentum GeV/c - // vpos position - // polar polarisation - // tof time of flight in seconds - // mecha production mechanism - // ntr on output the number of the track stored - // - TClonesArray &particles = *fParticles; - TParticle *particle; - Float_t mass; - const Int_t firstdaughter=-1; - const Int_t lastdaughter=-1; - const Int_t KS=0; - // const Float_t tlife=0; - + +// +// MC Application +// + +//_______________________________________________________________________ +void AliRun::Field(const Double_t* x, Double_t *b) const +{ // - // Here we get the static mass - // For MC is ok, but a more sophisticated method could be necessary - // if the calculated mass is required - // also, this method is potentially dangerous if the mass - // used in the MC is not the same of the PDG database + // Return the value of the magnetic field // - mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass(); - 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); + Float_t xfloat[3]; + for (Int_t i=0; i<3; i++) xfloat[i] = x[i]; - particle=new(particles[fNtrack]) TParticle(pdg,KS,parent,-1,firstdaughter, - lastdaughter,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(parent>=0) { - particle=(TParticle*) fParticles->UncheckedAt(parent); - particle->SetLastDaughter(fNtrack); - if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack); - } else { - // - // This is a primary track. Set high water mark for this event - fHgwmk=fNtrack; - // - // Set also number if primary tracks - fHeader.SetNprimary(fHgwmk+1); - fHeader.SetNtrack(fHgwmk+1); + if (Field()) { + Float_t bfloat[3]; + Field()->Field(xfloat,bfloat); + for (Int_t j=0; j<3; j++) b[j] = bfloat[j]; + } + else { + AliError("No mag field defined!"); + b[0]=b[1]=b[2]=0.; + } +} + +// +// End of MC Application +// + +//_______________________________________________________________________ +void AliRun::Streamer(TBuffer &R__b) +{ + // Stream an object of class AliRun. + + if (R__b.IsReading()) { + if (!gAlice) gAlice = this; + AliRun::Class()->ReadBuffer(R__b, this); + gROOT->GetListOfBrowsables()->Add(this,"Run"); + + gRandom = fRandom; + } else { + AliRun::Class()->WriteBuffer(R__b, this); } - ntr = fNtrack++; } +//_______________________________________________________________________ -//_____________________________________________________________________________ -void AliRun::KeepTrack(const Int_t track) +void AliRun::SetGenEventHeader(AliGenEventHeader* header) +{ + fRunLoader->GetHeader()->SetGenEventHeader(header); +} +//_______________________________________________________________________ + +Int_t AliRun::GetEvNumber() const { +//Returns number of current event + if (fRunLoader == 0x0) + { + AliError("RunLoader is not set. Can not load data."); + return -1; + } + + return fRunLoader->GetEventNumber(); +} +//_______________________________________________________________________ + +void AliRun::SetRunLoader(AliRunLoader* rloader) +{ // - // flags a track to be kept + // Set the loader of the run // - TClonesArray &particles = *fParticles; - ((TParticle*)particles[track])->SetBit(Keep_Bit); + fRunLoader = rloader; + if (fRunLoader == 0x0) return; + + TString evfoldname; + TFolder* evfold = fRunLoader->GetEventFolder(); + if (evfold) evfoldname = evfold->GetName(); + else AliWarning("Did not get Event Folder from Run Loader"); + + if ( fRunLoader->GetAliRun() ) + {//if alrun already exists in folder + if (fRunLoader->GetAliRun() != this ) + {//and is different than this - crash + AliFatal("AliRun is already in Folder and it is not this object"); + return;//pro forma + }//else do nothing + } + else + { + evfold->Add(this);//Post this AliRun to Folder + } + + TIter next(fModules); + AliModule *module; + while((module = (AliModule*)next())) + { + if (evfold) AliConfig::Instance()->Add(module,evfoldname); + module->SetRunLoader(fRunLoader); + AliDetector* detector = dynamic_cast(module); + if (detector) + { + AliLoader* loader = fRunLoader->GetLoader(detector); + if (loader == 0x0) + { + AliError(Form("Can not get loader for detector %s", detector->GetName())); + } + else + { + AliDebug(1, Form("Setting loader for detector %s", detector->GetName())); + detector->SetLoader(loader); + } + } + } } - -//_____________________________________________________________________________ -void AliRun::StepManager(Int_t id) const + +void AliRun::AddModule(AliModule* mod) { // - // Called at every step during transport + // Add a module to the module list // + if (mod == 0x0) return; + if (strlen(mod->GetName()) == 0) return; + if (GetModuleID(mod->GetName()) >= 0) return; + + AliDebug(1, mod->GetName()); + if (fRunLoader == 0x0) AliConfig::Instance()->Add(mod); + else AliConfig::Instance()->Add(mod,fRunLoader->GetEventFolder()->GetName()); - // - // --- If lego option, do it and leave - if (fLego) - fLego->StepManager(); - else { - Int_t copy; - //Update energy deposition tables - sEventEnergy[gMC->CurrentVolID(copy)]+=gMC->Edep(); + Modules()->Add(mod); - //Call the appropriate stepping routine; - AliModule *det = (AliModule*)fModules->At(id); - if(det) det->StepManager(); - } + fNdets++; +} + + +//_______________________________________________________________________ +Int_t AliRun::GetDebug() const +{ + AliWarning("Don't use this method any more, use AliDebug instead"); + return AliDebugLevel(); } +//_______________________________________________________________________ +void AliRun::SetDebug(Int_t level) +{ + AliWarning("Don't use this method any more, use AliLog instead"); + AliLog::SetClassDebugLevel("AliRun", level); +} + + +// added by Alberto Colla //_____________________________________________________________________________ -void AliRun::Streamer(TBuffer &R__b) +/*inline*/ Bool_t AliRun::IsFileAccessible(const char* fnam, EAccessMode mode) +{ return !gSystem->AccessPathName(fnam,mode);} + +//______________________________________________________ +/*inline*/ Bool_t AliRun::IsFileAccessible(Char_t* name,EAccessMode mode) { - // - // Stream an object of class AliRun. - // - if (R__b.IsReading()) { - Version_t R__v = R__b.ReadVersion(); if (R__v) { } - TNamed::Streamer(R__b); - if (!gAlice) gAlice = this; - gROOT->GetListOfBrowsables()->Add(this,"Run"); - fTreeE = (TTree*)gDirectory->Get("TE"); - if (fTreeE) fTreeE->SetBranchAddress("Header", &header); - else Error("Streamer","cannot find Header Tree\n"); - R__b >> fNtrack; - R__b >> fHgwmk; - R__b >> fDebug; - fHeader.Streamer(R__b); - R__b >> fModules; - R__b >> fParticles; - R__b >> fField; - // R__b >> fMC; - R__b >> fNdets; - R__b >> fTrRmax; - R__b >> fTrZmax; - R__b >> fGenerator; - if(R__v>1) { - R__b >> fPDGDB; //Particle factory object! - fTreeE->GetEntry(0); - } else { - fHeader.SetEvent(0); - fPDGDB = TDatabasePDG::Instance(); //Particle factory object! - } - } else { - R__b.WriteVersion(AliRun::IsA()); - TNamed::Streamer(R__b); - R__b << fNtrack; - R__b << fHgwmk; - R__b << fDebug; - fHeader.Streamer(R__b); - R__b << fModules; - R__b << fParticles; - R__b << fField; - // R__b << fMC; - R__b << fNdets; - R__b << fTrRmax; - R__b << fTrZmax; - R__b << fGenerator; - R__b << fPDGDB; //Particle factory object! - } -} + TString str = name; gSystem->ExpandPathName(str); + return !gSystem->AccessPathName(str.Data(),mode); +} + +