]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWGLF/FORWARD/analysis2/trains/MakeFMDELossTrain.C
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / trains / MakeFMDELossTrain.C
index fc8eab12ee4d9ce7c9b3cfa670fbae750fefa3bd..867ff5f9758f63cfc8e2b6947668953703641439 100644 (file)
@@ -1,92 +1,87 @@
+/**
+ * @file   MakeFMDELossTrain.C
+ * @author Christian Holm Christensen <cholm@master.hehi.nbi.dk>
+ * @date   Fri Jun  1 13:53:02 2012
+ * 
+ * @brief  
+ * 
+ * 
+ * @ingroup pwglf_forward_trains_specific
+ */
+#include "TrainSetup.C"
+
 //====================================================================
 /**
  * Analysis train to do energy loss fits
  * 
- * @ingroup pwglf_forward_trains
+ * @ingroup pwglf_forward_trains_specific
+ * @ingroup pwglf_forward_eloss
  */
 class MakeFMDELossTrain : public TrainSetup
 {
 public:
   /** 
-   * Constructor.  Date and time must be specified when running this
-   * in Termiante mode on Grid
+   * Constructor.  
    * 
    * @param name     Name of train 
-   * @param useCent  Whether to use centrality or not 
-   * @param dateTime Append date and time to name
-   * @param year     Year
-   * @param month    Month 
-   * @param day      Day
-   * @param hour     Hour 
-   * @param min      Minutes
-   */
-  MakeFMDELossTrain(const char* name  = "FMD Energy Loss",
-                   Bool_t   useCent  = false,
-                   Bool_t   dateTime = false, 
-                   UShort_t year     = 0, 
-                   UShort_t month    = 0, 
-                   UShort_t day      = 0, 
-                   UShort_t hour     = 0, 
-                   UShort_t min      = 0) 
-    : TrainSetup(name, dateTime, year, month, day, hour, min), 
-      fUseCent(useCent)
-  {}
-  //__________________________________________________________________
-  /** 
-   * Run this analysis 
-   * 
-   * @param mode     Mode
-   * @param oper     Operation
-   * @param nEvents  Number of events (negative means all)
-   * @param mc       If true, assume simulated events 
-   * @param par      IF true, use par files 
    */
-  void Run(const char* mode, const char* oper, 
-          Int_t nEvents=-1, Bool_t mc=false, Bool_t par=false)
+  MakeFMDELossTrain(const char* name  = "FMD Energy Loss")
+    : TrainSetup(name)
   {
-    Exec("ESD", mode, oper, nEvents, mc, par);
+    fOptions.Add("only-mb", "Only collect statistics from MB events");
+    fOptions.Add("config",  "FILE", "Configuration", "elossFitConfig.C");
+    fOptions.Add("corr",    "DIR",  "Corrections dir", "");
+    fOptions.Set("type", "ESD");
   }
-  //__________________________________________________________________
+protected:
+  //------------------------------------------------------------------
   /** 
-   * Run this analysis 
+   * Create the analysis manager 
    * 
-   * @param mode     Mode
-   * @param oper     Operation
-   * @param nEvents  Number of events (negative means all)
-   * @param mc       If true, assume simulated events 
-   * @param par      IF true, use par files 
+   * @param name Name of the analysis 
+   * 
+   * @return Created analysis manager 
    */
-  void Run(EMode mode, EOper oper, Int_t nEvents=-1, Bool_t mc=false,
-          Bool_t par=false)
+  virtual AliAnalysisManager* CreateAnalysisManager(const char* name)
   {
-    Exec(kESD, mode, oper, nEvents, mc, par);
+    AliAnalysisManager* mgr = TrainSetup::CreateAnalysisManager(name);
+    // mgr->SetAutoBranchLoading(false);
+    return mgr;
   }
-protected:
   //__________________________________________________________________
   /** 
    * Create the tasks 
    * 
-   * @param mode Processing mode
-   * @param par  Whether to use par files 
    * @param mgr  Analysis manager 
    */
-  void CreateTasks(EMode mode, Bool_t par, AliAnalysisManager* mgr)
+  void CreateTasks(AliAnalysisManager* mgr)
   {
     // --- Output file name ------------------------------------------
     AliAnalysisManager::SetCommonFileName("forward_eloss.root");
 
     // --- Load libraries/pars ---------------------------------------
-    LoadLibrary("PWGLFforward2", mode, par, true);
+    fRailway->LoadLibrary("PWGLFforward2");
     
     // --- Set load path ---------------------------------------------
     gROOT->SetMacroPath(Form("%s:$(ALICE_ROOT)/PWGLF/FORWARD/analysis2",
                             gROOT->GetMacroPath()));
 
     // --- Check if this is MC ---------------------------------------
-    Bool_t mc = mgr->GetMCtruthEventHandler() != 0;
+    Bool_t   mc     = HasMCHandler();
+    Bool_t   onlyMB = fOptions.AsBool("only-mb");
+    TString  config = fOptions.Get("config"); 
+    TString  corrs  = "";
+    if (fOptions.Has("corr")) corrs = fOptions.Get("corr"); 
 
     // --- Add the task ----------------------------------------------
-    gROOT->Macro(Form("AddTaskFMDELoss.C(%d,%d)", mc, fUseCent));
+    CoupleCar("AddTaskFMDELoss.C", Form("%d,%d,\"%s\",\"%s\"", 
+                                       mc, onlyMB,  
+                                       config.Data(), 
+                                       corrs.Data()));
+    fRailway->LoadAux(gSystem->Which(gROOT->GetMacroPath(), config), true);
+    if (!corrs.IsNull())
+      fRailway->LoadAux(Form("%s/fmd_corrections.root",corrs.Data()), true);
+    
   }
   /** 
    * Create entrality selection if enabled 
@@ -94,24 +89,107 @@ protected:
    * @param mc   Whether this is MC or not
    * @param mgr  Analysis manager 
    */
-  virtual void CreateCentralitySelection(Bool_t mc, AliAnalysisManager* mgr)
+  virtual void CreateCentralitySelection(Bool_t mc)
   {
-    if (!fUseCent) return;
-
-    gROOT->Macro("AddTaskCentrality.C");
-    AliCentralitySelectionTask* ctask = 
-      dynamic_cast<AliCentralitySelectionTask*>(mgr->GetTask("CentralitySelection"));
-    if (!ctask) return;
-    ctask->SetPass(fESDPass);
-    if (mc) ctask->SetMCInput();
+    if (!fOptions.Has("cent")) return;
+    TrainSetup::CreateCentralitySelection(mc);    
   }
   /** 
    * Crete output handler - we don't want one here. 
    * 
    * @return 0
    */
-  AliVEventHandler* CreateOutputHandler(EType) { return 0; }
-  Bool_t fUseCent; // Whether to use centrality or not 
+  AliVEventHandler* CreateOutputHandler(UShort_t) { return 0; }
+
+  //__________________________________________________________________
+  const char* ClassName() const { return "MakeFMDELossTrain"; }
+  //__________________________________________________________________
+  /** 
+   * Overloaded to create new Extract.C in the output 
+   * directory
+   * 
+   * @param asShellScript 
+   */
+  void SaveSetup(Bool_t asShellScript)
+  {
+    TrainSetup::SaveSetup(asShellScript);
+    SaveExtract();
+    SaveSummarize();
+    SaveReFit();
+  }
+  void SaveExtract()
+  {
+    std::ofstream f("Extract.C");
+    if (!f) { 
+      Error("SaveSetup", "Failed to open Extract.C");
+      return;
+    }
+    f << "// Generated by " << ClassName() << "\n"
+      << "void Extract(Bool_t mc=" << HasMCHandler() << ",\n"
+      << "             const char* file=\"forward_eloss.root\")\n"
+      << "{\n"
+      << "  const char* fwd=\"$ALICE_ROOT/PWGLF/FORWARD/analysis2\";\n"
+      << "  gROOT->LoadMacro(Form(\"%s/corrs/ExtractELoss.C\",fwd));\n"
+      << "  ExtractELoss(file,mc);\n" 
+      << "}\n"
+      << "// EOF" << std::endl;
+    f.close();
+  }
+  void SaveSummarize()
+  {
+    std::ofstream f("Summarize.C");
+    if (!f) { 
+      Error("SaveSummarize", "Failed to open Summarize.C script");
+      return;
+    }
+    f << std::boolalpha 
+      << "// Generated by " << ClassName() << "\n"
+      << "//\n"
+      << "void Summarize(Bool_t mc=" << HasMCHandler() << ",\n"
+      << "               const char* filename=\"forward_eloss.root\")\n"
+      << "{\n"
+      << "  const char* fwd=\"$ALICE_ROOT/PWGLF/FORWARD/analysis2\";\n"
+      << "  gROOT->LoadMacro(Form(\"%s/corrs/DrawCorrELoss.C\",fwd));\n"
+      << "  DrawCorrELoss(mc,filename);\n"
+      << "}\n"
+      << "// EOF" << std::endl;
+    f.close();
+  }
+  void SaveReFit()
+  {
+    std::ofstream f("ReFit.C");
+    if (!f) { 
+      Error("SaveRerun", "Failed to open ReFit.C script");
+      return;
+    }
+    f << std::boolalpha 
+      << "// Generated by " << ClassName() << "\n"
+      << "// If force=true, then force set parameters\n"
+      << "// If shift=true, enable extra shift in Delta from sigma/xi\n"
+      << "//\n"
+      << "void ReFit(Bool_t      force=false,\n"
+      << "           Bool_t      shift=true,\n"
+      << "           const char* filename=\"forward_eloss.root\")\n"
+      << "{\n"
+      << "  const char* fwd=\"$ALICE_ROOT/PWGLF/FORWARD/analysis2\";\n"
+      << "  gROOT->LoadMacro(Form(\"%s/corrs/RerunELossFits.C\",fwd));\n"
+      << "  RerunELossFits(force,filename);\n"
+      << "}\n"
+      << "// EOF" << std::endl;
+    f.close();
+  }
+  void PostShellCode(std::ostream& f)
+  {
+    f << "  mc=" << std::boolalpha << HasMCHandler() << "\n"
+      << "  echo \"=== Extracting Corrections ...\"\n"
+      << "  aliroot -l -b -q ${prefix}Extract.C\\($mc\\)\n"
+      << "  echo \"=== Summarizing results ...\"\n"
+      << "  aliroot -l -b -q ${prefix}Summarize.C\\($mc\\)\n"
+      << "  if test x$dest = x ; then return ; fi\n"
+      << "  echo \"=== Uploading to ${dest} ...\"\n"
+      << "  aliroot -l -b -q Upload.C\\(\\\"${dest}\\\"\\);\n"
+      << std::endl;
+  }
 };
 
 //