-//_______________________________________________________________________
-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;
- }
- //
- if(fDebug) {
- 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);
- if(fDebug){
- 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) {
- if(fDebug) 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) {
- if(fDebug) 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 {
- if(fDebug) printf("%s::ReadTransParModule: %s not present\n",ClassName(),detName);
- continue;
- }
- }
-}
-//_____________________________________________________________________________
-
-void AliRun::BeginEvent()
-{
- //
- // Clean-up previous event
- // Energy scores
- if (GetDebug())
- {
- Info("BeginEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
- Info("BeginEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
- Info("BeginEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
- Info("BeginEvent"," BEGINNING EVENT ");
- Info("BeginEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
- Info("BeginEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
- Info("BeginEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
- }
-
- /*******************************/
- /* Clean after eventual */
- /* previous event */
- /*******************************/
-
-
- //Set the next event in Run Loader -> Cleans trees (TreeK and all trees in detectors),
- fRunLoader->SetEventNumber(++fEventNrInRun);// sets new files, cleans the previous event stuff, if necessary, etc.,
- if (GetDebug()) Info("BeginEvent","EventNr is %d",fEventNrInRun);
-
- fEventEnergy.Reset();
- // Clean detector information
-
- if (fRunLoader->Stack())
- fRunLoader->Stack()->Reset();//clean stack -> tree is unloaded
- else
- fRunLoader->MakeStack();//or make a new one
-
- if (GetDebug()) Info("BeginEvent"," fRunLoader->MakeTree(K)");
- fRunLoader->MakeTree("K");
- if (GetDebug()) Info("BeginEvent"," gMC->SetStack(fRunLoader->Stack())");
- gMC->SetStack(fRunLoader->Stack());//Was in InitMC - but was moved here
- //because we don't have guarantee that
- //stack pointer is not going to change from event to event
- //since it bellobgs to header and is obtained via RunLoader
- //
- // Reset all Detectors & kinematics & make/reset trees
- //
-
- fRunLoader->GetHeader()->Reset(fRun,fEvent,fEventNrInRun);
-// fRunLoader->WriteKinematics("OVERWRITE"); is there any reason to rewrite here since MakeTree does so
-
- if (GetDebug()) Info("BeginEvent"," fRunLoader->MakeTrackRefsContainer()");
- fRunLoader->MakeTrackRefsContainer();//for insurance
-
- if (GetDebug()) Info("BeginEvent"," ResetHits()");
- ResetHits();
- if (GetDebug()) Info("BeginEvent"," fRunLoader->MakeTree(H)");
- fRunLoader->MakeTree("H");
-
- //
- if(fLego)
- {
- fLego->BeginEvent();
- return;
- }
-
- //create new branches and SetAdresses
- TIter next(fModules);
- AliModule *detector;
- while((detector = (AliModule*)next()))
- {
- if (GetDebug()) Info("BeginEvent"," %s->MakeBranch(H)",detector->GetName());
- detector->MakeBranch("H");
- if (GetDebug()) Info("BeginEvent"," %s->MakeBranchTR()",detector->GetName());
- detector->MakeBranchTR();
- if (GetDebug()) Info("BeginEvent"," %s->SetTreeAddress()",detector->GetName());
- detector->SetTreeAddress();
- }
-}
-
-//_______________________________________________________________________
-TParticle* AliRun::Particle(Int_t i) const
-{
- if (fRunLoader)
- if (fRunLoader->Stack())
- return fRunLoader->Stack()->Particle(i);
- return 0x0;
-}
-
-//_______________________________________________________________________
-void AliRun::ResetDigits()
-{
- //
- // Reset all Detectors digits
- //
- TIter next(fModules);
- AliModule *detector;
- while((detector = dynamic_cast<AliModule*>(next()))) {
- detector->ResetDigits();
- }
-}
-
-//_______________________________________________________________________
-void AliRun::ResetSDigits()
-{
- //
- // Reset all Detectors digits
- //
- TIter next(fModules);
- AliModule *detector;
- while((detector = dynamic_cast<AliModule*>(next()))) {
- detector->ResetSDigits();
- }
-}
-
-//_______________________________________________________________________
-void AliRun::ResetHits()
-{
- //
- // Reset all Detectors hits
- //
- TIter next(fModules);
- AliModule *detector;
- while((detector = dynamic_cast<AliModule*>(next()))) {
- detector->ResetHits();
- }
-}
-//_______________________________________________________________________
-
-void AliRun::ResetTrackReferences()
-{
- //
- // Reset all Detectors hits
- //
- TIter next(fModules);
- AliModule *detector;
- while((detector = dynamic_cast<AliModule*>(next()))) {
- detector->ResetTrackReferences();
- }
-}
-//_______________________________________________________________________
-
-void AliRun::ResetPoints()
-{
- //
- // Reset all Detectors points
- //
- TIter next(fModules);
- AliModule *detector;
- while((detector = dynamic_cast<AliModule*>(next()))) {
- detector->ResetPoints();
- }
-}
-//_______________________________________________________________________
-
-void AliRun::InitMC(const char *setup)
-{
- //
- // Initialize the Alice setup
- //
- Announce();
-
- if(fInitDone) {
- Warning("Init","Cannot initialise AliRun twice!\n");
- return;
- }
-
- gROOT->LoadMacro(setup);
- gInterpreter->ProcessLine(fConfigFunction.Data());
-
- // Register MC in configuration
- AliConfig::Instance()->Add(gMC);
-
- InitLoaders();
-
- fRunLoader->MakeTree("E");
- fRunLoader->LoadKinematics("RECREATE");
- fRunLoader->LoadTrackRefs("RECREATE");
- fRunLoader->LoadHits("all","RECREATE");
-
-
- fRunLoader->CdGAFile();
-
- gMC->DefineParticles(); //Create standard MC particles
- AliPDG::AddParticlesToPdgDataBase();
-
- TObject *objfirst, *objlast;
-
- fNdets = fModules->GetLast()+1;
-
- //
- //=================Create Materials and geometry
- gMC->Init();
-
- // Added also after in case of interactive initialisation of modules
- fNdets = fModules->GetLast()+1;
-
- TIter next(fModules);
- AliModule *detector;
- while((detector = dynamic_cast<AliModule*>(next())))
- {
- objlast = gDirectory->GetList()->Last();
-
- // 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);
- }
- }
- ReadTransPar(); //Read the cuts for all materials
-
- MediaTable(); //Build the special IMEDIA table
-
- //Initialise geometry deposition table
- fEventEnergy.Set(gMC->NofVolumes()+1);
- fSummEnergy.Set(gMC->NofVolumes()+1);
- fSum2Energy.Set(gMC->NofVolumes()+1);
-
- //Compute cross-sections
- gMC->BuildPhysics();
-
- //Write Geometry object to current file.
- fRunLoader->WriteGeometry();
-
- fInitDone = kTRUE;
-
- fMCQA = new AliMCQA(fNdets);
-
- //
- // Save stuff at the beginning of the file to avoid file corruption
- Write();
- fEventNrInRun = -1; //important - we start Begin event from increasing current number in run
-}
-
-//_______________________________________________________________________
-
-void AliRun::RunMC(Int_t nevent, const char *setup)
-{
- //
- // 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
- //
- 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
-
- gMC->ProcessRun(nevent);
-
- // End of this run, close files
- if(nevent>0) FinishRun();
-}