]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliSimulation.cxx
Propagating the detector pattern from simulation to dateStream, so that it finally...
[u/mrichter/AliRoot.git] / STEER / AliSimulation.cxx
index 3422106893c4d3e091c860e33acab548c695f6c5..06e8b8a716d8f111aa627f6a3dc6ad9cb2af3f1b 100644 (file)
 #include <TObjString.h>
 #include <TSystem.h>
 #include <TFile.h>
+#include <TROOT.h>
 
 #include "AliCodeTimer.h"
 #include "AliCDBStorage.h"
 #include "AliHLTSimulation.h"
 #include "AliQADataMakerSteer.h"
 #include "AliSysInfo.h"
+#include "AliMagF.h"
 
 ClassImp(AliSimulation)
 
@@ -183,8 +185,10 @@ AliSimulation::AliSimulation(const char* configFileName,
   fEmbeddingFlag(kFALSE),
   fQADetectors("ALL"),                  
   fQATasks("ALL"),     
+  fQASteer(NULL), 
   fRunQA(kTRUE), 
-  fRunHLT("default")
+  fRunHLT("default"),
+  fWriteGRPEntry(kTRUE)
 {
 // create simulation object with default parameters
   fgInstance = this;
@@ -192,7 +196,11 @@ AliSimulation::AliSimulation(const char* configFileName,
   
 // for QA
    for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) 
-       fQACycles[iDet] = 999999;
+                fQACycles[iDet] = 999999;
+       fQASteer = new AliQADataMakerSteer("sim") ; 
+       fQASteer->SetActiveDetectors(fQADetectors) ; 
+       fQATasks = Form("%d %d %d", AliQA::kHITS, AliQA::kSDIGITS, AliQA::kDIGITS) ; 
+       fQASteer->SetTasks(fQATasks) ;  
 }
 
 //_____________________________________________________________________________
@@ -230,9 +238,11 @@ AliSimulation::AliSimulation(const AliSimulation& sim) :
   fSetRunNumberFromDataCalled(sim.fSetRunNumberFromDataCalled),
   fEmbeddingFlag(sim.fEmbeddingFlag),
   fQADetectors(sim.fQADetectors),                  
-  fQATasks(sim.fQATasks),      
+       fQATasks(sim.fQATasks), 
+       fQASteer(sim.fQASteer), 
   fRunQA(sim.fRunQA), 
-  fRunHLT(sim.fRunHLT)
+  fRunHLT(sim.fRunHLT),
+  fWriteGRPEntry(sim.fWriteGRPEntry)
 {
 // copy constructor
 
@@ -284,6 +294,8 @@ AliSimulation::~AliSimulation()
   fSpecCDBUri.Delete();
   if (fgInstance==this) fgInstance = 0;
 
+       delete fQASteer ; 
+       
   AliCodeTimer::Instance()->Print();
 }
 
@@ -884,6 +896,11 @@ Bool_t AliSimulation::RunSimulation(Int_t nEvents)
                   "Check your config file: %s", fConfigFileName.Data()));
     return kFALSE;
   }
+
+  // Write GRP entry corresponding to the setting found in Cofig.C
+  if (fWriteGRPEntry)
+    WriteGRPEntry();
+
   if (nEvents <= 0) nEvents = fNEvents;
 
   // get vertex from background file in case of merging
@@ -1246,23 +1263,29 @@ Bool_t AliSimulation::ConvertRawFilesToDate(const char* dateFileName,
 
   Int_t selEvents = 0;
   for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
-    fprintf(pipe, "GDC\n");
-    Float_t ldc = 0;
-    Int_t prevLDC = -1;
 
-    if (selrawdata) {
+    UInt_t detectorPattern = 0;
+    runLoader->GetEvent(iEvent);
+    if (!runLoader->LoadTrigger()) {
+      AliCentralTrigger *aCTP = runLoader->GetTrigger();
+      detectorPattern = aCTP->GetClusterMask();
       // Check if the event was triggered by CTP
-      runLoader->GetEvent(iEvent);
-      if (!runLoader->LoadTrigger()) {
-       AliCentralTrigger *aCTP = runLoader->GetTrigger();
+      if (selrawdata) {
        if (aCTP->GetClassMask()) selEvents++;
       }
-      else {
+    }
+    else {
+      AliWarning("No trigger can be loaded! Some fields in the event header will be empty !");
+      if (selrawdata) {
        AliWarning("No trigger can be loaded! Writing of selected raw data is abandoned !");
        selrawdata = kFALSE;
       }
     }
 
+    fprintf(pipe, "GDC DetectorPattern %u\n", detectorPattern);
+    Float_t ldc = 0;
+    Int_t prevLDC = -1;
+
     // loop over detectors and DDLs
     for (Int_t iDet = 0; iDet < AliDAQ::kNDetectors; iDet++) {
       for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls(iDet); iDDL++) {
@@ -1308,16 +1331,18 @@ Bool_t AliSimulation::ConvertRawFilesToDate(const char* dateFileName,
   for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
 
     // Get the trigger decision and cluster
+    UInt_t detectorPattern = 0;
     TString detClust;
     runLoader->GetEvent(iEvent);
     if (!runLoader->LoadTrigger()) {
       AliCentralTrigger *aCTP = runLoader->GetTrigger();
       if (aCTP->GetClassMask() == 0) continue;
-      detClust = aCTP->GetTriggeredDetectors();
+      detectorPattern = aCTP->GetClusterMask();
+      detClust = AliDAQ::ListOfTriggeredDetectors(detectorPattern);
       AliInfo(Form("List of detectors to be read out: %s",detClust.Data()));
     }
 
-    fprintf(pipe2, "GDC\n");
+    fprintf(pipe2, "GDC DetectorPattern %u\n", detectorPattern);
     Float_t ldc = 0;
     Int_t prevLDC = -1;
 
@@ -1579,7 +1604,6 @@ Bool_t AliSimulation::ConvertRaw2SDigits(const char* rawDirectory, const char* e
       rawReader = new AliRawReaderRoot(fileName);
     } else if (!fileName.IsNull()) {
       rawReader = new AliRawReaderDate(fileName);
-      rawReader->SelectEvents(7);
     }
 //     if (!fEquipIdMap.IsNull() && fRawReader)
 //       fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
@@ -1760,21 +1784,12 @@ Bool_t AliSimulation::RunHLT()
 Bool_t AliSimulation::RunQA()
 {
        // run the QA on summable hits, digits or digits
-
-       AliQADataMakerSteer qas ; 
-    qas.SetRunLoader(gAlice->GetRunLoader()) ;
+       
+       fQASteer->SetRunLoader(gAlice->GetRunLoader()) ;
 
        TString detectorsw("") ;  
        Bool_t rv = kTRUE ; 
-       if (fQATasks.Contains(Form("%d", AliQA::kHITS))) 
-               detectorsw =  qas.Run(fQADetectors.Data(), AliQA::kHITS) ; 
-//     qas.Reset() ; 
-       if (fQATasks.Contains(Form("%d", AliQA::kSDIGITS))) 
-               detectorsw += qas.Run(fQADetectors.Data(), AliQA::kSDIGITS) ;   
-//     qas.Reset() ; 
-       if (fQATasks.Contains(Form("%d", AliQA::kDIGITS))) 
-               detectorsw += qas.Run(fQADetectors.Data(), AliQA::kDIGITS) ;    
-
+       detectorsw = fQASteer->Run(fQADetectors.Data()) ; 
        if ( detectorsw.IsNull() ) 
                rv = kFALSE ; 
        return rv ; 
@@ -1796,7 +1811,7 @@ Bool_t AliSimulation::SetRunQA(TString detAndAction)
        fQADetectors = detAndAction(0, colon) ; 
        if (fQADetectors.Contains("ALL") )
                fQADetectors = Form("%s %s", fMakeDigits.Data(), fMakeDigitsFromHits.Data()) ; 
-       fQATasks   = detAndAction(colon+1, detAndAction.Sizeof() ) ; 
+               fQATasks   = detAndAction(colon+1, detAndAction.Sizeof() ) ; 
        if (fQATasks.Contains("ALL") ) {
                fQATasks = Form("%d %d %d", AliQA::kHITS, AliQA::kSDIGITS, AliQA::kDIGITS) ; 
        } else {
@@ -1821,6 +1836,8 @@ Bool_t AliSimulation::SetRunQA(TString detAndAction)
     tempo.ReplaceAll(Form("%d", AliQA::kDIGITS), AliQA::GetTaskName(AliQA::kDIGITS)) ;         
        AliInfo( Form("QA will be done on \"%s\" for \"%s\"\n", fQADetectors.Data(), tempo.Data()) ) ;  
        fRunQA = kTRUE ;
+       fQASteer->SetActiveDetectors(fQADetectors) ; 
+       fQASteer->SetTasks(fQATasks) ; 
        return kTRUE; 
 } 
 
@@ -1863,4 +1880,96 @@ void AliSimulation::ProcessEnvironmentVars()
     AliInfo(Form("Run number = %d", fRun)); 
 }
 
+//_____________________________________________________________________________
+void AliSimulation::WriteGRPEntry()
+{
+  // Get the necessary information from galice (generator, trigger etc) and
+  // write a GRP entry corresponding to the settings in the Config.C used
+  AliInfo("Writing global run parameters entry into the OCDB");
+
+  TMap *grpMap = new TMap();
+  grpMap->SetName("MONTECARLO");
+
+  grpMap->Add(new TObjString("fRunType"),new TObjString("PHYSICS"));
+  grpMap->Add(new TObjString("fAliceStartTime"),new TObjString("0"));
+  grpMap->Add(new TObjString("fAliceStopTime"),new TObjString("9999"));
+
+  const AliGenerator *gen = gAlice->Generator();
+  if (gen) {
+    grpMap->Add(new TObjString("fAliceBeamEnergy"),new TObjString(Form("%f",gen->GetEnergyCMS())));
+    TString projectile;
+    Int_t a,z;
+    gen->GetProjectile(projectile,a,z);
+    TString target;
+    gen->GetTarget(target,a,z);
+    TString beamType = projectile + "-" + target;
+    if (!beamType.CompareTo("-")) {
+      grpMap->Add(new TObjString("fAliceBeamType"),new TObjString("UNKNOWN"));
+    }
+    else {
+      grpMap->Add(new TObjString("fAliceBeamType"),new TObjString(beamType.Data()));
+    }
+  }
+  else {
+    AliWarning("Unknown beam type and energy!");
+    grpMap->Add(new TObjString("fAliceBeamEnergy"),new TObjString("UNKNOWN"));
+    grpMap->Add(new TObjString("fAliceBeamType"),new TObjString("0"));
+  }
 
+  UInt_t detectorPattern  = 0;
+  Int_t nDets = 0;
+  TObjArray *detArray = gAlice->Detectors();
+  for (Int_t iDet = 0; iDet < AliDAQ::kNDetectors-1; iDet++) {
+    if (detArray->FindObject(AliDAQ::OfflineModuleName(iDet))) {
+      detectorPattern |= (1 << iDet);
+      nDets++;
+    }
+  }
+  // HLT
+  if (!fRunHLT.IsNull())
+    detectorPattern |= (1 << AliDAQ::kHLTId);
+
+  grpMap->Add(new TObjString("fNumberOfDetectors"),new TObjString(Form("%d",nDets)));
+  grpMap->Add(new TObjString("fDetectorMask"),new TObjString(Form("%u",detectorPattern)));
+  grpMap->Add(new TObjString("fLHCPeriod"),new TObjString("LHC08c"));
+
+  grpMap->Add(new TObjString("fLHCState"),new TObjString("STABLE BEAMS"));
+  grpMap->Add(new TObjString("fLHCCondition"),new TObjString("0"));
+  grpMap->Add(new TObjString("fLHCLuminosity"),new TObjString("0"));
+  grpMap->Add(new TObjString("fBeamIntensity"),new TObjString("0"));
+
+  AliMagF *field = gAlice->Field();
+  Float_t solenoidField = TMath::Abs(field->SolenoidField());
+  Float_t factor = field->Factor();
+  Float_t l3current = TMath::Abs(factor)*solenoidField*30000./5.;
+  grpMap->Add(new TObjString("fL3Current"),new TObjString(Form("%f",l3current)));
+  
+  if (factor > 0) {
+    grpMap->Add(new TObjString("fL3Polarity"),new TObjString("0"));
+    grpMap->Add(new TObjString("fDipolePolarity"),new TObjString("0"));
+  }
+  else {
+    grpMap->Add(new TObjString("fL3Polarity"),new TObjString("1"));
+    grpMap->Add(new TObjString("fDipolePolarity"),new TObjString("1"));
+  }
+
+  if (TMath::Abs(factor) != 0)
+    grpMap->Add(new TObjString("fDipoleCurrent"),new TObjString("6000"));
+  else 
+    grpMap->Add(new TObjString("fDipoleCurrent"),new TObjString("0"));
+
+  grpMap->Add(new TObjString("fCavernTemperature"),new TObjString("0"));
+  grpMap->Add(new TObjString("fCavernPressure"),new TObjString("0"));
+
+  // Now store the entry in OCDB
+  AliCDBManager* man = AliCDBManager::Instance();
+
+  AliCDBId id("GRP/GRP/Data", man->GetRun(), man->GetRun());
+  AliCDBMetaData *metadata= new AliCDBMetaData();
+
+  metadata->SetResponsible("alice-off@cern.ch");
+  metadata->SetComment("Automatically produced GRP entry for Monte Carlo");
+  man->Put(grpMap,id,metadata);
+}