]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG/muondep/AliMuonAccEffSubmitter.cxx
Non-implemented method are commented out or moved to the private part of the class
[u/mrichter/AliRoot.git] / PWG / muondep / AliMuonAccEffSubmitter.cxx
index 8a53d49e63a0f89151fe083eeace503115e49b06..ab391e8a5f7ffd33f6f75095f97c283521155982 100644 (file)
@@ -38,7 +38,7 @@
 //
 // Basic usage
 //
-// AliMuonAccEffSubmitter a;
+// AliMuonAccEffSubmitter a; // (1)
 // a.UseOCDBSnapshots(kFALSE);
 // a.SetRemoteDir("/alice/cern.ch/user/l/laphecet/Analysis/LHC13d/simjpsi/pp503z0");
 // a.ShouldOverwriteFiles(true);
 // a.Run("test"); // will do everything but the submit
 // a.Submit(false); // actual submission
 //
+// (1) note that for this to work in the Root prompt you need to load (for instance
+// in your rootlogon.C) all the chain of libraries up to libPWGmuondep. As
+// the time of this writing (March 2014), this means :
 //
-// author: Laurent Aphecetche (Subatech
+// gSystem->Load("libVMC");
+// gSystem->Load("libTree");
+// gSystem->Load("libProofPlayer");
+// gSystem->Load("libPhysics");
+// gSystem->Load("libMatrix");
+// gSystem->Load("libMinuit");
+// gSystem->Load("libXMLParser");
+// gSystem->Load("libGui");
+// gSystem->Load("libSTEERBase");
+// gSystem->Load("libESD");
+// gSystem->Load("libAOD");
+// gSystem->Load("libANALYSIS");
+// gSystem->Load("libRAWDatabase");
+// gSystem->Load("libCDB");
+// gSystem->Load("libSTEER");
+// gSystem->Load("libANALYSISalice");
+// gSystem->Load("libCORRFW");
+// gSystem->Load("libPWGmuon");
+// gSystem->Load("libMUONcore");
+// gSystem->Load("libMUONmapping");
+// gSystem->Load("libMUONcalib");
+// gSystem->Load("libMUONgeometry");
+// gSystem->Load("libMUONtrigger");
+// gSystem->Load("libRAWDatabase");
+// gSystem->Load("libMUONraw");
+// gSystem->Load("libMUONbase");
+// gSystem->Load("libMUONshuttle");
+// gSystem->Load("libMUONrec");
+// gSystem->Load("libPWGmuondep");
+//
+// author: Laurent Aphecetche (Subatech)
 //
 
 #include "AliMuonAccEffSubmitter.h"
@@ -77,7 +110,8 @@ namespace
 ClassImp(AliMuonAccEffSubmitter)
 
 //______________________________________________________________________________
-AliMuonAccEffSubmitter::AliMuonAccEffSubmitter(const char* generator, Bool_t localOnly)
+AliMuonAccEffSubmitter::AliMuonAccEffSubmitter(const char* generator, Bool_t localOnly,
+                                               const char* generatorVersion)
 : AliMuonGridSubmitter(AliMuonGridSubmitter::kAccEff,localOnly),
 fRatio(-1.0),
 fFixedNofEvents(10000),
@@ -91,6 +125,17 @@ fSnapshotDir(""),
 fUseAODMerging(kFALSE)
 {
   // ctor
+  //
+  // if generator contains "pythia8" and generatorVersion is given then
+  // the pythiaversion must represent the integer part XXX of the
+  // include directory $ALICE_ROOT/PYTHI8/pythiaXXX/include where the file
+  // Analysis.h is to be found.
+  //
+  // if generator contains "pythia6" then generatorVersion should be the
+  // X.YY part of libpythia6.X.YY.so
+  //
+  
+  AddIncludePath("-I$ALICE_ROOT/STEER/STEER -I$ALICE_ROOT/PYTHIA6 -I$ALICE_ROOT/LHAPDF -I$ALICE_ROOT/PWG/muon -I$ALICE_ROOT/PWG/muondep -I$ALICE_ROOT/MUON -I$ALICE_ROOT/include -I$ALICE_ROOT/EVGEN -I$ALICE_ROOT/FASTSIM");
   
   TString ocdbPath("raw://");
   
@@ -104,7 +149,7 @@ fUseAODMerging(kFALSE)
   
   SetVar("VAR_OCDB_PATH",Form("\"%s\"",ocdbPath.Data()));
 
-  SetVar("VAR_GENPARAM_INCLUDE","AliGenMUONLib.h");
+  SetVar("VAR_GENPARAM_INCLUDE","AliGenMUONlib.h");
   SetVar("VAR_GENPARAM_NPART","1");
   SetVar("VAR_GENPARAM_GENLIB_TYPE","AliGenMUONlib::kJpsi");
   SetVar("VAR_GENPARAM_GENLIB_PARNAME","\"pPb 5.03\"");
@@ -137,17 +182,118 @@ fUseAODMerging(kFALSE)
   SetVar("VAR_GENPARAMCUSTOMSINGLE_Y_P2","0.141776");
   SetVar("VAR_GENPARAMCUSTOMSINGLE_Y_P3","0.0130173");
 
+  // some default values for GenBox
+  
+  SetVar("VAR_GENMUBOX_PTMIN","0");
+  SetVar("VAR_GENMUBOX_PTMAX","20");
+  SetVar("VAR_GENMUBOX_YMIN","-4.1");
+  SetVar("VAR_GENMUBOX_YMAX","-2.4");
+
+  SetVar("VAR_PYTHIA8_CMS_ENERGY","8000");
+  SetVar("VAR_PYTHIA6_CMS_ENERGY","8000");
+  
   SetVar("VAR_PURELY_LOCAL",Form("%d",localOnly));
   
   SetVar("VAR_SIM_ALIGNDATA","\"alien://folder=/alice/simulation/2008/v4-15-Release/Ideal\"");
   
   SetVar("VAR_REC_ALIGNDATA","\"alien://folder=/alice/simulation/2008/v4-15-Release/Residual\"");
   
+  SetVar("VAR_USE_ITS_RECO","0");
+  
   UseOCDBSnapshots(fUseOCDBSnapshots);
+
+  gSystem->Load("libEVGEN");
+
+  SetVar("VAR_TRIGGER_CONFIGURATION","");
+  
+  SetVar("VAR_PYTHIA8_INCLUDES","");
+  SetVar("VAR_PYTHIA8_SETENV","");
+
+  SetVar("VAR_PYTHIA6_INCLUDES","");
+  SetVar("VAR_PYTHIA6_SETENV","");
+  
+  SetVar("VAR_LHAPDF","liblhapdf");
+  SetVar("VAR_MUONMCMODE","1");
+  
+  if ( TString(generator).Contains("pythia8",TString::kIgnoreCase) )
+  {
+    fMaxEventsPerChunk =  500; // 5000 is not reasonable with Pythia8 (and ITS+MUON...)
+    
+    fCompactMode = 2; // keep AOD as for the time being the filtering driven from AODtrain.C cannot
+    // add SPD tracklets to muon AODs.
+    
+    SetVar("VAR_USE_ITS_RECO","1");
+
+    if (gSystem->AccessPathName(gSystem->ExpandPathName(Form("$ALICE_ROOT/PYTHIA8/pythia%s",generatorVersion))))
+    {
+      AliError(Form("Directory -I$ALICE_ROOT/PYTHIA8/pythia%s/include not found",generatorVersion));
+      Invalidate();
+      return;
+    }
+    AddIncludePath(Form("-I$ALICE_ROOT/PYTHIA8 -I$ALICE_ROOT/PYTHIA8/pythia%s/include",generatorVersion));
+//    SetVar("VAR_PYTHIA8_VERSION",Form("\"%d\"",pythia8version));
+    
+    SetVar("VAR_PYTHIA8_INCLUDES",Form("gSystem->AddIncludePath(\"-I$ALICE_ROOT/PYTHIA6 -I$ALICE_ROOT/STEER/STEER -I$ALICE_ROOT/LHAPDF -I$ALICE_ROOT/PYTHIA8 -I$ALICE_ROOT/PYTHIA8/pythia%s/include\");\n",generatorVersion));
+  
+    TString p8env;
+    
+    p8env += Form("  gSystem->Setenv(\"PYTHIA8DATA\", gSystem->ExpandPathName(\"$ALICE_ROOT/PYTHIA8/pythia%s/xmldoc\"));\n",generatorVersion);
+    
+    p8env += "  gSystem->Setenv(\"LHAPDF\",gSystem->ExpandPathName(\"$ALICE_ROOT/LHAPDF\"));\n";
+    
+    p8env +=  "  gSystem->Setenv(\"LHAPATH\",gSystem->ExpandPathName(\"$ALICE_ROOT/LHAPDF/PDFsets\"));\n";
+    
+    SetVar("VAR_PYTHIA8_SETENV",p8env.Data());
+    
+    gSystem->Load("libFASTSIM");
+    gSystem->Load("liblhapdf");      // Parton density functions
+    gSystem->Load("libEGPythia6");   // TGenerator interface
+//    gSystem->Load("libpythia6");     // Pythia 6.2
+    gSystem->Load("libAliPythia6");  // ALICE specific implementations
+    gSystem->Load("libpythia8");
+    gSystem->Load("libAliPythia8");
+    
+    SetVar("VAR_PYTHIA8_SETUP_STRINGS","\"\"");
+    
+    SetVar("VAR_TRIGGER_CONFIGURATION","p-p");
+  }
   
+  if ( TString(generator).Contains("pythia6",TString::kIgnoreCase) )
+  {
+    fMaxEventsPerChunk =  500; // 5000 is not reasonable with Pythia6 (and ITS+MUON...)
+
+    fCompactMode = 2; // keep AOD as for the time being the filtering driven from AODtrain.C cannot
+    // add SPD tracklets to muon AODs.
+
+    gSystem->Load("libFASTSIM");
+    gSystem->Load("liblhapdf");      // Parton density functions
+    gSystem->Load("libEGPythia6");   // TGenerator interface
+    gSystem->Load(Form("libpythia6.%s",generatorVersion));
+    gSystem->Load("libAliPythia6");
+    
+    SetVar("VAR_PYTHIA6_INCLUDES","gSystem->AddIncludePath(\"-I$ALICE_ROOT/PYTHIA6 -I$ALICE_ROOT/STEER/STEER -I$ALICE_ROOT/STEER/STEERBase -I$ALICE_ROOT/LHAPDF -I$ALICE_ROOT/FASTSIM\");");
+    
+    TString p6env;
+    
+    p6env += Form("gSystem->Load(\"libpythia6.%s\");",generatorVersion);
+    
+    SetVar("VAR_PYTHIA6_SETENV",p6env.Data());
+    
+    SetVar("VAR_USE_ITS_RECO","1");
+    
+    SetVar("VAR_TRIGGER_CONFIGURATION","p-p");
+  }
+
   SetGenerator(generator);
   
-  MakeNofEventsPropToTriggerCount();
+  if (localOnly)
+  {
+    MakeNofEventsFixed(10);
+  }
+  else
+  {
+    MakeNofEventsPropToTriggerCount();
+  }
   
   AddToTemplateFileList("CheckESD.C");
   AddToTemplateFileList("CheckAOD.C");
@@ -227,8 +373,8 @@ Bool_t AliMuonAccEffSubmitter::GenerateMergeJDL(const char* name) const
   
   OutputToJDL(*os,"Validationcommand",Form("%s/validation_merge.sh",RemoteDir().Data()));
   
-  OutputToJDL(*os,"TTL","7200");
-
+  OutputToJDL(*os,"TTL","14400");
+  
   OutputToJDL(*os,"OutputArchive",
     "log_archive.zip:stderr,stdout@disk=1",
     "root_archive.zip:AliAOD.root,AliAOD.Muons.root,AnalysisResults.root@disk=3"
@@ -318,9 +464,15 @@ Bool_t AliMuonAccEffSubmitter::GenerateRunJDL(const char* name) const
   else if ( CompactMode() == 1 )
   {
     // keep only muon AODs and QA
-    OutputToJDL(*os,"OutputArchive",  "log_archive.zip:stderr,stdout,aod.log,checkaod.log,checkesd.log,rec.log,sim.log@disk=1",
+    OutputToJDL(*os,"OutputArchive",  "log_archive.zip:stderr,stdout,*.log@disk=1",
            "root_archive.zip:galice*.root,AliAOD.Muons.root,Merged.QA.Data.root@disk=2");
   }
+  else if ( CompactMode() == 2 )
+  {
+    // keep only AODs and QA
+    OutputToJDL(*os,"OutputArchive",  "log_archive.zip:stderr,stdout,aod.log,checkaod.log,checkesd.log,rec.log,sim.log@disk=1",
+                "root_archive.zip:galice*.root,AliAOD.root,Merged.QA.Data.root@disk=2");
+  }
   else
   {
     AliError(Form("Unknown CompactMode %d",CompactMode()));
@@ -336,7 +488,14 @@ Bool_t AliMuonAccEffSubmitter::GenerateRunJDL(const char* name) const
 
   OutputToJDL(*os,"Validationcommand",Form("%s/validation.sh",RemoteDir().Data()));
 
-  OutputToJDL(*os,"TTL","72000");
+  if ( GetVar("VAR_GENERATOR").Contains("pythia",TString::kIgnoreCase) )
+  {
+    OutputToJDL(*os,"TTL","36000");
+  }
+  else
+  {
+    OutputToJDL(*os,"TTL","14400");
+  }
   
   return kTRUE;
 }
@@ -432,7 +591,7 @@ Bool_t AliMuonAccEffSubmitter::Merge(Int_t stage, Bool_t dryRun)
   if (runs.empty())
   {
     AliError("No run to work with");
-    return kFALSE;
+    return 0;
   }
 
   TString currRun;
@@ -568,17 +727,17 @@ void AliMuonAccEffSubmitter::Print(Option_t* opt) const
 
   if ( fRatio > 0 )
   {
-    std::cout << Form("For each run, will generate %5.2f times the number of real events for trigger %s",
+    std::cout << std::endl << Form("-- For each run, will generate %5.2f times the number of real events for trigger %s",
                       fRatio,ReferenceTrigger().Data()) << std::endl;
   }
   else
   {
-    std::cout << Form("For each run, will generate %10d events",fFixedNofEvents) << std::endl;
+    std::cout << std::endl <<  Form("-- For each run, will generate %10d events",fFixedNofEvents) << std::endl;
   }
   
-  std::cout << "MaxEventsPerChunk = " << fMaxEventsPerChunk << std::endl;
+  std::cout << "-- MaxEventsPerChunk = " << fMaxEventsPerChunk << std::endl;
   
-  std::cout << "Will" << (fUseOCDBSnapshots ? "" : " NOT") << " use OCDB snaphosts" << std::endl;
+  std::cout << "-- Will" << (fUseOCDBSnapshots ? "" : " NOT") << " use OCDB snaphosts" << std::endl;
 }
 
 //______________________________________________________________________________
@@ -777,23 +936,139 @@ Int_t AliMuonAccEffSubmitter::LocalTest()
   
   const std::vector<int>& runs = RunList();
 
+  if ( runs.empty() )
+  {
+    AliError("No run to work with");
+    return 0;
+  }
+  
   std::cout << "Generating script to execute : ./simrun.sh" << std::endl;
-
+  
   std::ofstream out("simrun.sh");
   
   out << "#!/bin/bash" << std::endl;
 //  root.exe -b -q simrun.C  --run <x> --chunk <y> --event <n>
   out << "root.exe -b -q simrun.C --run "<< runs[0] <<" --event " << fFixedNofEvents << std::endl;
+
+  out.close();
+
   gSystem->Exec("chmod +x simrun.sh");
+
+  std::cout << "Cleaning up left-over files from previous simulation/reconstructions" << std::endl;
   
+  gSystem->Exec("rm -rf TrackRefs.root *.SDigits*.root Kinematics.root *.Hits.root geometry.root gphysi.dat Run*.tag.root HLT*.root *.ps *.Digits.root *.RecPoints.root galice.root *QA*.root Trigger.root *.log AliESD* AliAOD* *.d *.so *.stat");
+
   std::cout << "Executing the script : ./simrun.sh" << std::endl;
 
+
   gSystem->Exec("./simrun.sh");
   
   return 1;
 }
 
+namespace  {
+
+  void OutputRunList(const char* filename, const std::vector<int>& runlist)
+  {
+    /// output a runlist to ASCII file
+    
+    std::ofstream out(filename);
+
+    for ( std::vector<int>::size_type j = 0; j < runlist.size(); ++j )
+    {
+      out << runlist[j] << std::endl;
+    }
+  }
+}
+
+//______________________________________________________________________________
+Int_t AliMuonAccEffSubmitter::SplitRunList(const char* inputList, int maxJobs)
+{
+  /// In order to be able to submit, split a given runlist into chunks that will
+  /// fit within maxJobs (1500 for a typical user)
+
+  std::vector<int> runs;
+  
+  AliAnalysisTriggerScalers tmp(inputList);
+  runs = tmp.GetRunList();
+  
+  AliAnalysisTriggerScalers* ts(0x0);
+  std::vector<int> currentRunList;
+  
+  int nJobs(0);
+  int nTotalJobs(0);
+  int nEvts(0);
+  int nFiles(0);
+  
+  for (std::vector<int>::size_type i=0; i < runs.size(); ++i)
+  {
+    Int_t runNumber = runs[i];
+  
+    Int_t nEvtRun(fFixedNofEvents);
+    
+    if ( fRatio > 0 )
+    {
+      if (!ts)
+      {
+        AliInfo(Form("Creating AliAnalysisTriggerScalers from OCDB=%s",OCDBPath().Data()));
+        ts = new AliAnalysisTriggerScalers(runs,OCDBPath().Data());
+      }
+      
+      AliAnalysisTriggerScalerItem* trigger = ts->GetTriggerScaler(runNumber, "L2A", ReferenceTrigger().Data());
+      
+      if (!trigger)
+      {
+        AliError(Form("Could not get trigger %s for run %09d",ReferenceTrigger().Data(),runNumber));
+        continue;
+      }
+      nEvtRun = TMath::Nint(fRatio * trigger->Value());
+    }
+    
+    Int_t nChunk = 1;
+    
+    while (nEvtRun/nChunk+0.5 > MaxEventsPerChunk())
+    {
+      ++nChunk;
+    }
+    
+    Int_t nEvtChunk = TMath::Nint(nEvtRun/nChunk + 0.5);
+    
+    nJobs += nChunk;
+    
+    nTotalJobs += nChunk;
+    
+    nEvts += nChunk*nEvtChunk;
+
+    if ( nJobs > maxJobs )
+    {
+      ++nFiles;
+      
+      OutputRunList(Form("%s.%d",inputList,nFiles),currentRunList);
+      nJobs = 0;
+      currentRunList.clear();
+    }
+    
+    
+    currentRunList.push_back(runNumber);
+    
+  }
+  
+  if ( !currentRunList.empty() )
+  {
+    ++nFiles;
+    OutputRunList(Form("%s.%d",inputList,nFiles),currentRunList);
+
+  }
+  
+  delete ts;
+  
+  std::cout << Form("input run list was split into %d files. Total number of jobs %d. Total number of events %d",
+                    nFiles,nTotalJobs,nEvts) << std::endl;
+  
+  return nFiles;
+}
+
+
 //______________________________________________________________________________
 Int_t AliMuonAccEffSubmitter::Submit(Bool_t dryRun)
 {
@@ -986,6 +1261,11 @@ void AliMuonAccEffSubmitter::UseOCDBSnapshots(Bool_t flag)
   if ( flag )
   {
     SetVar("VAR_OCDB_SNAPSHOT","kTRUE");
+    
+    // for some reason must include ITS objects in the snapshot
+    // (to be able to instantiante the vertexer later on ?)
+    
+    SetVar("VAR_USE_ITS_RECO","1");
   }
   else
   {