]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG2/FORWARD/analysis2/TrainSetup.C
Fixes
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / TrainSetup.C
index 693e16b6ac09973152ac8178122d77a5baeded21..b6dbfa276f27eb3d61d91d4002ffa14ebf60cc7f 100644 (file)
@@ -11,6 +11,7 @@
 
 #ifndef __CINT__
 #include <fstream>
+#include <iostream>
 
 #include <TAlienCollection.h>
 #include <TArrayI.h>
@@ -324,51 +325,57 @@ struct TrainSetup
   /** 
    * Set ROOT version to use 
    * 
-   * @param v 
+   * @param v Version string of ROOT 
    */
   void SetROOTVersion(const char* v)    { fRootVersion = v; }
   //__________________________________________________________________
   /** 
    * Set AliROOT version to use 
    * 
-   * @param v 
+   * @param v Version string of AliROOT 
    */
   void SetAliROOTVersion(const char* v) { fAliRootVersion = v; }
   //__________________________________________________________________
   /** 
-   * Set the proof server URL
+   * Set the PROOF server URL
    * 
-   * @param s 
+   * @param s PROOF server URL 
    */
   void SetProofServer(const char* s)    { fProofServer = s; }
   //__________________________________________________________________
   /** 
    * Set the GRID/Local data dir 
    * 
-   * @param d 
+   * @param d Directory with data 
    */
-  void SetDataDir(const char* d)        { fDataDir = d; }
+  void SetDataDir(const char* d) { fDataDir = d; }
   //__________________________________________________________________
   /** 
    * Set the PROOF data set 
    * 
-   * @param d 
+   * @param d PROOF registered data set 
    */
-  void SetDataSet(const char* d)        { fDataSet = d; }
+  void SetDataSet(const char* d) { fDataSet = d; }
   //__________________________________________________________________
   /** 
    * Set the XML file to use 
    * 
-   * @param x 
+   * @param x XML file 
    */
-  void SetXML(const char* x)            { fXML = x; }
+  void SetXML(const char* x) { fXML = x; }
   //__________________________________________________________________
   /** 
    * Set how many replicas of the output we want 
    * 
-   * @param n 
+   * @param n Number of replicas requested 
    */
-  void SetNReplica(Int_t n)             { fNReplica = n; }
+  void SetNReplica(Int_t n) { fNReplica = n; }
+  /** 
+   * Set the ESD pass to use 
+   * 
+   * @param pass Pass number 
+   */
+  void SetESDPass(Int_t pass) { fESDPass = pass; }
   //__________________________________________________________________
   /** 
    * Add a source file to be copied and byte compiled on slaves 
@@ -650,8 +657,8 @@ protected:
     gROOT->SetMacroPath(Form("%s:$ALICE_ROOT/ANALYSIS/macros",
                             gROOT->GetMacroPath()));
 
-    // --- Physics selction ------------------------------------------
-    CreatePhysicsSelection(mc, mgr);
+    // --- Physics selction - only for ESD ---------------------------
+    if (type == kESD) CreatePhysicsSelection(mc, mgr);
     
     // --- Create tasks ----------------------------------------------
     CreateTasks(mode, usePar, mgr);
@@ -745,7 +752,8 @@ protected:
    * 
    * @return Grid handler 
    */
-  virtual AliAnalysisAlien* CreateGridHandler(EType type, EMode mode, EOper oper)
+  virtual AliAnalysisAlien* 
+  CreateGridHandler(EType type, EMode mode, EOper oper)
   {
     if (mode != kGrid) return 0;
 
@@ -946,13 +954,14 @@ protected:
    */
   virtual AliVEventHandler* CreateOutputHandler(EType type)
   {
+    AliAODHandler* ret = new AliAODHandler();
     switch (type) { 
-    case kESD: // Fall through 
-    case kAOD: { 
-      AliAODHandler* ret = new AliAODHandler();
+    case kESD: 
       ret->SetOutputFileName("AliAOD.root");
-      return ret;
-    }
+      break;
+    case kAOD: 
+      ret->SetOutputFileName("AliAOD.pass2.root");
+      break;
     }
     return 0;
   }
@@ -961,6 +970,7 @@ protected:
    * Create physics selection , and add to manager
    * 
    * @param mc Whether this is for MC 
+   * @param mgr Manager
    */
   virtual void CreatePhysicsSelection(Bool_t mc,
                                      AliAnalysisManager* mgr)
@@ -1264,7 +1274,7 @@ protected:
   //__________________________________________________________________
   /** 
    * Scan directory @a dir (possibly recursive) for tree files to add
-   * to the chain.  
+   * to the chain.    This does not follow sym-links
    * 
    * @param dir        Directory to scan
    * @param chain      Chain to add to
@@ -1290,8 +1300,10 @@ protected:
     // Get list of files, and go back to old working directory
     TString oldDir(gSystem->WorkingDirectory());
     TList* files = dir->GetListOfFiles();
-    gSystem->ChangeDirectory(oldDir);
-    if (!files) return false;
+    if (!files) { 
+      gSystem->ChangeDirectory(oldDir);
+      return false;
+    }
 
     // Sort list of files and check if we should add it 
     files->Sort();
@@ -1299,16 +1311,27 @@ protected:
     TSystemFile* file = 0;
     while ((file = static_cast<TSystemFile*>(next()))) {
       TString name(file->GetName());
-    
+      TString title(file->GetTitle());
+      TString full(gSystem->ConcatFileName(file->GetTitle(), name.Data()));
       // Ignore special links 
-      if (name == "." || name == "..") continue;
+      if (name == "." || name == "..") { 
+       // Info("ScanDirectory", "Ignoring %s", name.Data());
+       continue;
+      }
 
+      Info("ScanDirectory", "Looking at %s", full.Data());
       // Check if this is a directory 
-      if (file->IsDirectory()) { 
-       if (recursive) 
+      if (file->IsDirectory(full.Data())) { 
+       Info("ScanDirectory", "%s is a directory", full.Data());
+       if (recursive) {
           if (ScanDirectory(static_cast<TSystemDirectory*>(file),
                            chain,type,recursive))
-           ret = true;;
+           ret = true;
+       }
+       else 
+         Info("ScanDirectory", 
+              "%s is a directory but we're not scanning recusively",   
+              name.Data());
         continue;
       }
     
@@ -1316,7 +1339,11 @@ protected:
       if (!name.EndsWith(".root")) continue;
 
       // If this file does not contain AliESDs, ignore 
-      if (!name.Contains(fnPattern)) continue;
+      if (!name.Contains(fnPattern)) { 
+       Info("ScanDirectory", "%s does not match pattern %s", 
+            name.Data(), fnPattern.Data());
+       continue;
+      }
     
       // Get the path 
       TString fn(Form("%s/%s", file->GetTitle(), name.Data()));
@@ -1326,6 +1353,7 @@ protected:
       chain->Add(fn);
       ret = true;
     }
+    gSystem->ChangeDirectory(oldDir);
     return ret;
   }
   //__________________________________________________________________
@@ -1423,29 +1451,34 @@ protected:
  * 
  * @ingroup pwg2_forward_scripts_makers
  */
-class ForwardELoss : public TrainSetup
+class FMDELossTrain : public TrainSetup
 {
 public:
   /** 
    * Constructor.  Date and time must be specified when running this
    * in Termiante mode on Grid
    * 
-   * @param dateTime Append date and time to name 
+   * @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
    */
-  ForwardELoss(Bool_t   dateTime, 
-              UShort_t year  = 0, 
-              UShort_t month = 0, 
-              UShort_t day   = 0, 
-              UShort_t hour  = 0, 
-              UShort_t min   = 0) 
-    : TrainSetup("Forward energy loss", dateTime, 
-                year, month, day, hour, min) 
+  FMDELossTrain(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 
    * 
@@ -1457,11 +1490,9 @@ public:
   void Run(const char* mode, const char* oper, 
           Int_t nEvents=-1, Bool_t mc=false)
   {
-    EMode eMode = ParseMode(mode);
-    EOper eOper = ParseOperation(oper);
-    
-    Run(eMode, eOper, nEvents, mc);
+    Exec("ESD", mode, oper, nEvents, mc);
   }
+  //__________________________________________________________________
   /** 
    * Run this analysis 
    * 
@@ -1474,6 +1505,8 @@ public:
   {
     Exec(kESD, mode, oper, nEvents, mc, true);
   }
+protected:
+  //__________________________________________________________________
   /** 
    * Create the tasks 
    * 
@@ -1497,14 +1530,33 @@ public:
     Bool_t mc = mgr->GetMCtruthEventHandler() != 0;
 
     // --- Add the task ----------------------------------------------
-    gROOT->Macro(Form("AddTaskForwardMultEloss.C(%d)", mc));
+    gROOT->Macro(Form("AddTaskFMDEloss.C(%d,%d)", mc, fUseCent));
   }
+  /** 
+   * Crete output handler - we don't want one here. 
+   * 
+   * @return 0
+   */
+  AliVEventHandler* CreateOutputHandler(EType) { return 0; }
+  Bool_t fUseCent;
 };
 
 //====================================================================
 /**
  * Analysis train to make Forward and Central multiplicity
  * 
+ * To run, do 
+ * @code 
+ * gROOT->LoadMacro("TrainSetup.C");
+ * // Make train 
+ * MakeAODTrain t("My Analysis");
+ * // Set variaous parameters on the train 
+ * t.SetDataDir("/home/of/data");
+ * t.AddRun(118506)
+ * // Run it 
+ * t.Run("LOCAL", "FULL", -1, false, false);
+ * @endcode 
+ *
  * @ingroup pwg2_forward_scripts_makers
  * @ingroup pwg2_forward_aod
  */
@@ -1515,10 +1567,12 @@ public:
    * Constructor.  Date and time must be specified when running this
    * in Termiante mode on Grid
    * 
-   * @param dateTime Append date and time to name 
+   * @param name     Name of train (free form)
    * @param sys      Collision system (1: pp, 2: PbPb)
    * @param sNN      Center of mass energy [GeV]
    * @param field    L3 magnetic field - one of {-5,0,+5} kG
+   * @param useCent  Whether to use centrality 
+   * @param dateTime Append date and time to name 
    * @param year     Year     - if not specified, current year
    * @param month    Month    - if not specified, current month
    * @param day      Day      - if not specified, current day
@@ -1546,8 +1600,8 @@ public:
   /** 
    * Run this analysis 
    * 
-   * @param mode     Mode
-   * @param oper     Operation
+   * @param mode     Mode - see TrainSetup::EMode
+   * @param oper     Operation - see TrainSetup::EOperation
    * @param nEvents  Number of events (negative means all)
    * @param mc       If true, assume simulated events 
    * @param usePar   If true, use PARs 
@@ -1561,8 +1615,8 @@ public:
   /** 
    * Run this analysis 
    * 
-   * @param mode     Mode
-   * @param oper     Operation
+   * @param mode     Mode - see TrainSetup::EMode
+   * @param oper     Operation - see TrainSetup::EOperation
    * @param nEvents  Number of events (negative means all)
    * @param mc       If true, assume simulated events 
    * @param usePar   If true, use PARs 
@@ -1612,20 +1666,24 @@ protected:
    * Create physics selection , and add to manager
    * 
    * @param mc Whether this is for MC 
+   * @param mgr Manager 
    */
   void CreatePhysicsSelection(Bool_t mc,
                              AliAnalysisManager* mgr)
   {
-    gROOT->Macro(Form("AddTaskPhysicsSelection.C(%d)", mc));
-    mgr->RegisterExtraFile("event_stat.root");
+    TrainSetup::CreatePhysicsSelection(mc, mgr);
 
     // --- Get input event handler -----------------------------------
     AliInputEventHandler* ih =
-      static_cast<AliInputEventHandler*>(mgr->GetInputEventHandler());
+      dynamic_cast<AliInputEventHandler*>(mgr->GetInputEventHandler());
+    if (!ih) 
+      Fatal("CreatePhysicsSelection", "Couldn't get input handler (%p)", ih);
     
     // --- Get Physics selection -------------------------------------
     AliPhysicsSelection* ps = 
-      static_cast<AliPhysicsSelection*>(ih->GetEventSelection());
+      dynamic_cast<AliPhysicsSelection*>(ih->GetEventSelection());
+    if (!ps) 
+      Fatal("CreatePhysicsSelection", "Couldn't get PhysicsSelection (%p)", ps);
 
     // --- Ignore trigger class when selecting events.  This means ---
     // --- that we get offline+(A,C,E) events too --------------------
@@ -1640,6 +1698,18 @@ protected:
 /**
  * Analysis train to make @f$ dN/d\eta@f$
  * 
+ * To run, do 
+ * @code 
+ * gROOT->LoadMacro("TrainSetup.C");
+ * // Make train 
+ * MakedNdetaTrain t("My Analysis");
+ * // Set variaous parameters on the train 
+ * t.SetDataDir("/home/of/data");
+ * t.AddRun(118506)
+ * // Run it 
+ * t.Run("LOCAL", "FULL", -1, false, false);
+ * @endcode 
+ *
  * @ingroup pwg2_forward_scripts_makers
  * @ingroup pwg2_forward_dndeta
  */
@@ -1650,6 +1720,7 @@ public:
    * Constructor.  Date and time must be specified when running this
    * in Termiante mode on Grid
    * 
+   * @param name     Name of train (free form)
    * @param trig     Trigger to use 
    * @param vzMin    Least @f$ v_z@f$
    * @param vzMax    Largest @f$ v_z@f$
@@ -1684,10 +1755,9 @@ public:
   /** 
    * Run this analysis 
    * 
-   * @param mode     Mode
-   * @param oper     Operation
+   * @param mode     Mode - see TrainSetup::EMode
+   * @param oper     Operation - see TrainSetup::EOperation
    * @param nEvents  Number of events (negative means all)
-   * @param mc       If true, assume simulated events 
    * @param usePar   If true, use PARs 
    */
   void Run(const char* mode, const char* oper, 
@@ -1698,10 +1768,9 @@ public:
   /** 
    * Run this analysis 
    * 
-   * @param mode     Mode
-   * @param oper     Operation
+   * @param mode     Mode - see TrainSetup::EMode
+   * @param oper     Operation - see TrainSetup::EOperation
    * @param nEvents  Number of events (negative means all)
-   * @param mc       If true, assume simulated events 
    * @param usePar   If true, use PARs 
    */
   void Run(EMode mode, EOper oper, Int_t nEvents=-1, 
@@ -1740,7 +1809,6 @@ protected:
    * 
    * @param mode Processing mode
    * @param par  Whether to use par files 
-   * @param mgr  Analysis manager 
    */
   void CreateTasks(EMode mode, Bool_t par, AliAnalysisManager*)
   {
@@ -1761,12 +1829,6 @@ protected:
     gROOT->Macro(Form("AddTaskCentraldNdeta.C(\"%s\",%f,%f,%d,\"%s\")",
                      fTrig.Data(), fVzMin, fVzMax, fUseCent, fScheme.Data()));
   }
-  //__________________________________________________________________
-  /** 
-   * Do nothing 
-   * 
-   */
-  void CreatePhysicsSelection(Bool_t,AliAnalysisManager*) {}
   /** 
    * Crete output handler - we don't want one here. 
    *