]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliSimulation.cxx
Introducing event specie in QA (Yves)
[u/mrichter/AliRoot.git] / STEER / AliSimulation.cxx
index 5995677cfd19e307f7e6981ae44f8fa5a1a03558..a3881924a26ed024168dca16407edb0a40854fa8 100644 (file)
 ///////////////////////////////////////////////////////////////////////////////
 
 #include <TVirtualMCApplication.h>
+#include <TVirtualMC.h>
 #include <TGeoManager.h>
 #include <TObjString.h>
 #include <TSystem.h>
@@ -166,7 +167,6 @@ AliSimulation::AliSimulation(const char* configFileName,
   fDeleteIntermediateFiles(kFALSE),
   fWriteSelRawData(kFALSE),
   fStopOnError(kFALSE),
-
   fNEvents(1),
   fConfigFileName(configFileName),
   fGAliceFileName("galice.root"),
@@ -187,6 +187,7 @@ AliSimulation::AliSimulation(const char* configFileName,
   fQATasks("ALL"),     
   fQASteer(NULL), 
   fRunQA(kTRUE), 
+  fEventSpecie(AliRecoParam::kDefault),
   fRunHLT("default"),
   fWriteGRPEntry(kTRUE)
 {
@@ -201,76 +202,6 @@ AliSimulation::AliSimulation(const char* configFileName,
        fQASteer->SetTasks(fQATasks) ;  
 }
 
-//_____________________________________________________________________________
-AliSimulation::AliSimulation(const AliSimulation& sim) :
-  TNamed(sim),
-
-  fRunGeneration(sim.fRunGeneration),
-  fRunSimulation(sim.fRunSimulation),
-  fLoadAlignFromCDB(sim.fLoadAlignFromCDB),
-  fLoadAlObjsListOfDets(sim.fLoadAlObjsListOfDets),
-  fMakeSDigits(sim.fMakeSDigits),
-  fMakeDigits(sim.fMakeDigits),
-  fMakeTrigger(sim.fMakeTrigger),
-  fMakeDigitsFromHits(sim.fMakeDigitsFromHits),
-  fWriteRawData(sim.fWriteRawData),
-  fRawDataFileName(""),
-  fDeleteIntermediateFiles(kFALSE),
-  fWriteSelRawData(kFALSE),
-  fStopOnError(sim.fStopOnError),
-
-  fNEvents(sim.fNEvents),
-  fConfigFileName(sim.fConfigFileName),
-  fGAliceFileName(sim.fGAliceFileName),
-  fEventsPerFile(),
-  fBkgrdFileNames(NULL),
-  fAlignObjArray(NULL),
-  fUseBkgrdVertex(sim.fUseBkgrdVertex),
-  fRegionOfInterest(sim.fRegionOfInterest),
-  fCDBUri(sim.fCDBUri),
-  fSpecCDBUri(),
-  fRun(-1),
-  fSeed(0),
-  fInitCDBCalled(sim.fInitCDBCalled),
-  fInitRunNumberCalled(sim.fInitRunNumberCalled),
-  fSetRunNumberFromDataCalled(sim.fSetRunNumberFromDataCalled),
-  fEmbeddingFlag(sim.fEmbeddingFlag),
-  fQADetectors(sim.fQADetectors),                  
-       fQATasks(sim.fQATasks), 
-       fQASteer(sim.fQASteer), 
-  fRunQA(sim.fRunQA), 
-  fRunHLT(sim.fRunHLT),
-  fWriteGRPEntry(sim.fWriteGRPEntry)
-{
-// copy constructor
-
-  for (Int_t i = 0; i < sim.fEventsPerFile.GetEntriesFast(); i++) {
-    if (!sim.fEventsPerFile[i]) continue;
-    fEventsPerFile.Add(sim.fEventsPerFile[i]->Clone());
-  }
-
-  fBkgrdFileNames = new TObjArray;
-  for (Int_t i = 0; i < sim.fBkgrdFileNames->GetEntriesFast(); i++) {
-    if (!sim.fBkgrdFileNames->At(i)) continue;
-    fBkgrdFileNames->Add(sim.fBkgrdFileNames->At(i)->Clone());
-  }
-
-  for (Int_t i = 0; i < sim.fSpecCDBUri.GetEntriesFast(); i++) {
-    if (sim.fSpecCDBUri[i]) fSpecCDBUri.Add(sim.fSpecCDBUri[i]->Clone());
-  }
-  fgInstance = this;
-}
-
-//_____________________________________________________________________________
-AliSimulation& AliSimulation::operator = (const AliSimulation& sim)
-{
-// assignment operator
-
-  this->~AliSimulation();
-  new(this) AliSimulation(sim);
-  return *this;
-}
-
 //_____________________________________________________________________________
 AliSimulation::~AliSimulation()
 {
@@ -449,7 +380,7 @@ Bool_t AliSimulation::SetRunNumberFromData()
     AliRunLoader* runLoader = LoadRun("READ");
     if (!runLoader) return kFALSE;
     else {
-       runData = runLoader->GetAliRun()->GetHeader()->GetRun();
+       runData = runLoader->GetHeader()->GetRun();
        delete runLoader;
     }
   
@@ -850,7 +781,7 @@ Bool_t AliSimulation::RunSimulation(Int_t nEvents)
   // Set run number in CDBManager
   AliInfo(Form("Run number: %d",AliCDBManager::Instance()->GetRun()));
 
-  AliRunLoader* runLoader = gAlice->GetRunLoader();
+  AliRunLoader* runLoader = AliRunLoader::GetRunLoader();
   if (!runLoader) {
              AliError(Form("gAlice has no run loader object. "
                             "Check your config file: %s", fConfigFileName.Data()));
@@ -877,7 +808,7 @@ Bool_t AliSimulation::RunSimulation(Int_t nEvents)
   MisalignGeometry(runLoader);
 #endif
 
-//   AliRunLoader* runLoader = gAlice->GetRunLoader();
+//   AliRunLoader* runLoader = AliRunLoader::GetRunLoader();
 //   if (!runLoader) {
 //     AliError(Form("gAlice has no run loader object. "
 //                   "Check your config file: %s", fConfigFileName.Data()));
@@ -943,9 +874,17 @@ Bool_t AliSimulation::RunSimulation(Int_t nEvents)
 
   AliInfo("running gAlice");
   AliSysInfo::AddStamp("Start_simulation");
-  StdoutToAliInfo(StderrToAliError(
-    gAlice->Run(nEvents);
-  ););
+
+  gAlice->InitMC("Config.C");
+  
+  // 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(nEvents);
+
+  // End of this run, close files
+  if(nEvents>0) gAlice->FinishRun();
+
   AliSysInfo::AddStamp("Stop_simulation");
   delete runLoader;
 
@@ -1005,8 +944,8 @@ Bool_t AliSimulation::RunDigitization(const char* detectors,
   if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
   SetCDBLock();
   
-  while (AliRunLoader::GetRunLoader()) delete AliRunLoader::GetRunLoader();
-  if (gAlice) delete gAlice;
+  delete AliRunLoader::GetRunLoader();
+  delete gAlice;
   gAlice = NULL;
 
   Int_t nStreams = 1;
@@ -1261,6 +1200,11 @@ Bool_t AliSimulation::ConvertRawFilesToDate(const char* dateFileName,
          dateFileName, runLoader->GetNumberOfEvents(),runLoader->GetHeader()->GetRun());
   FILE* pipe = gSystem->OpenPipe(command, "w");
 
+  if (!pipe) {
+    AliError(Form("Cannot execute command: %s",command));
+    return kFALSE;
+  }
+
   Int_t selEvents = 0;
   for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
 
@@ -1444,7 +1388,7 @@ AliRunLoader* AliSimulation::LoadRun(const char* mode) const
 {
 // delete existing run loaders, open a new one and load gAlice
 
-  while (AliRunLoader::GetRunLoader()) delete AliRunLoader::GetRunLoader();
+  delete AliRunLoader::GetRunLoader();
   AliRunLoader* runLoader = 
     AliRunLoader::Open(fGAliceFileName.Data(), 
                       AliConfig::GetDefaultEventFolderName(), mode);
@@ -1578,7 +1522,7 @@ Bool_t AliSimulation::ConvertRaw2SDigits(const char* rawDirectory, const char* e
     Int_t iDet;
     //
     // Get the runloader
-    AliRunLoader* runLoader = gAlice->GetRunLoader();
+    AliRunLoader* runLoader = AliRunLoader::GetRunLoader();
     //
     // Open esd file if available
     TFile* esdFile = TFile::Open(esdFileName);
@@ -1736,12 +1680,14 @@ Bool_t AliSimulation::RunHLT()
   typedef void (*CompileInfo)( char*& date, char*& time);
   CompileInfo fctInfo=(CompileInfo)gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, "CompileInfo");
   if (fctInfo) {
-    char* date="";
-    char* time="";
-    (*fctInfo)(date, time);
-    if (!date) date="unknown";
-    if (!time) time="unknown";
+    Char_t* date=0;
+    Char_t* time=0;
+    (*fctInfo)(date,time);
+    if (!date) {date=new Char_t[8]; strcpy(date,"unknown");}
+    if (!time) {time=new Char_t[8]; strcpy(time,"unknown");}
     AliInfo(Form("%s build on %s (%s)", ALIHLTSIMULATION_LIBRARY, date, time));
+    delete date;
+    delete time;
   } else {
     AliInfo(Form("no build info available for %s", ALIHLTSIMULATION_LIBRARY));
   }
@@ -1799,15 +1745,14 @@ Bool_t AliSimulation::RunQA()
        // run the QA on summable hits, digits or digits
        
   if(!gAlice) return kFALSE;
-       fQASteer->SetRunLoader(gAlice->GetRunLoader()) ;
+       fQASteer->SetRunLoader(AliRunLoader::GetRunLoader()) ;
 
        TString detectorsw("") ;  
        Bool_t rv = kTRUE ; 
+  fQASteer->SetEventSpecie(fEventSpecie) ;
        detectorsw = fQASteer->Run(fQADetectors.Data()) ; 
        if ( detectorsw.IsNull() ) 
                rv = kFALSE ; 
-  else 
-    fQASteer->EndOfCycle(detectorsw) ; 
        return rv ; 
 }
 
@@ -1854,6 +1799,9 @@ Bool_t AliSimulation::SetRunQA(TString detAndAction)
        fRunQA = kTRUE ;
        fQASteer->SetActiveDetectors(fQADetectors) ; 
        fQASteer->SetTasks(fQATasks) ; 
+  for (Int_t det = 0 ; det < AliQA::kNDET ; det++) 
+    fQASteer->SetWriteExpert(AliQA::DETECTORINDEX_t(det)) ;
+  
        return kTRUE; 
 } 
 
@@ -1897,7 +1845,6 @@ void AliSimulation::ProcessEnvironmentVars()
 }
 
 //---------------------------------------------------------------------
-
 void AliSimulation::WriteGRPEntry()
 {
   // Get the necessary information from galice (generator, trigger etc) and
@@ -1922,15 +1869,25 @@ void AliSimulation::WriteGRPEntry()
     TString target;
     gen->GetTarget(target,a,z);
     TString beamType = projectile + "-" + target;
+    beamType.ReplaceAll(" ","");
     if (!beamType.CompareTo("-")) {
-
-       grpObj->SetBeamType("UNKNOWN");
+      grpObj->SetBeamType("UNKNOWN");
     }
     else {
-       grpObj->SetBeamType(beamType);
+      grpObj->SetBeamType(beamType);
+      // Heavy ion run, the event specie is set to kHighMult
+      fEventSpecie = AliRecoParam::kHighMult;
+      if ((strcmp(beamType,"p-p") == 0) ||
+          (strcmp(beamType,"p-")  == 0) ||
+          (strcmp(beamType,"-p")  == 0) ||
+          (strcmp(beamType,"P-P") == 0) ||
+          (strcmp(beamType,"P-")  == 0) ||
+          (strcmp(beamType,"-P")  == 0)) {
+        // Proton run, the event specie is set to kLowMult
+        fEventSpecie = AliRecoParam::kLowMult;
+      } 
     }
-  }
-  else {
+  } else {
     AliWarning("Unknown beam type and energy! Setting energy to 0");
     grpObj->SetBeamEnergy(0);
     grpObj->SetBeamType("UNKNOWN");
@@ -1945,6 +1902,10 @@ void AliSimulation::WriteGRPEntry()
       nDets++;
     }
   }
+  // CTP
+  if (!fMakeTrigger.IsNull() || strcmp(gAlice->GetTriggerDescriptor(),""))
+    detectorPattern |= (1 << AliDAQ::DetectorID("TRG"));
+
   // HLT
   if (!fRunHLT.IsNull())
     detectorPattern |= (1 << AliDAQ::kHLTId);
@@ -1983,7 +1944,7 @@ void AliSimulation::WriteGRPEntry()
   // Now store the entry in OCDB
   AliCDBManager* man = AliCDBManager::Instance();
 
-  AliCDBId id("GRP/GRP/Data", man->GetRun(), man->GetRun());
+  AliCDBId id("GRP/GRP/Data", man->GetRun(), man->GetRun(), 1, 1);
   AliCDBMetaData *metadata= new AliCDBMetaData();
 
   metadata->SetResponsible("alice-off@cern.ch");