]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/trains/MakeFMDELossTrain.C
- For energy loss fits, add option to store residuals
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / trains / MakeFMDELossTrain.C
1 /**
2  * @file   MakeFMDELossTrain.C
3  * @author Christian Holm Christensen <cholm@master.hehi.nbi.dk>
4  * @date   Fri Jun  1 13:53:02 2012
5  * 
6  * @brief  
7  * 
8  * 
9  * @ingroup pwglf_forward_trains_specific
10  */
11 #include "TrainSetup.C"
12
13 //====================================================================
14 /**
15  * Analysis train to do energy loss fits
16  * 
17  * @ingroup pwglf_forward_trains_specific
18  * @ingroup pwglf_forward_eloss
19  */
20 class MakeFMDELossTrain : public TrainSetup
21 {
22 public:
23   /** 
24    * Constructor.  
25    * 
26    * @param name     Name of train 
27    */
28   MakeFMDELossTrain(const char* name  = "FMD Energy Loss")
29     : TrainSetup(name)
30   {
31     fOptions.Add("cent", "Use centrality");
32     fOptions.Add("residuals", "MODE", "Optional calculation of residuals", "");
33     fOptions.Set("type", "ESD");
34   }
35 protected:
36   //------------------------------------------------------------------
37   /** 
38    * Create the analysis manager 
39    * 
40    * @param name Name of the analysis 
41    * 
42    * @return Created analysis manager 
43    */
44   virtual AliAnalysisManager* CreateAnalysisManager(const char* name)
45   {
46     AliAnalysisManager* mgr = TrainSetup::CreateAnalysisManager(name);
47     // mgr->SetAutoBranchLoading(false);
48     return mgr;
49   }
50   //__________________________________________________________________
51   /** 
52    * Create the tasks 
53    * 
54    * @param mgr  Analysis manager 
55    */
56   void CreateTasks(AliAnalysisManager* mgr)
57   {
58     // --- Output file name ------------------------------------------
59     AliAnalysisManager::SetCommonFileName("forward_eloss.root");
60
61     // --- Load libraries/pars ---------------------------------------
62     fHelper->LoadLibrary("PWGLFforward2");
63     
64     // --- Set load path ---------------------------------------------
65     gROOT->SetMacroPath(Form("%s:$(ALICE_ROOT)/PWGLF/FORWARD/analysis2",
66                              gROOT->GetMacroPath()));
67
68     // --- Check if this is MC ---------------------------------------
69     Bool_t   mc   = mgr->GetMCtruthEventHandler() != 0;
70     Bool_t   cent = fOptions.Has("cent");
71     Int_t    verb = fOptions.AsInt("verbose");
72     TString  resi = "";
73     if (fOptions.Has("residuals")) resi = fOptions.Get("residuals"); 
74
75     // --- Add the task ----------------------------------------------
76     gROOT->Macro(Form("AddTaskFMDELoss.C(%d,%d,%d,\"%s\")", 
77                       mc, cent, verb, resi.Data()));
78   }
79   /** 
80    * Create entrality selection if enabled 
81    * 
82    * @param mc   Whether this is MC or not
83    * @param mgr  Analysis manager 
84    */
85   virtual void CreateCentralitySelection(Bool_t mc, AliAnalysisManager* mgr)
86   {
87     if (!fOptions.Has("cent")) return;
88
89     const char* name = "CentralitySelection";
90     gROOT->Macro("AddTaskCentrality.C");
91     AliCentralitySelectionTask* ctask = 
92       dynamic_cast<AliCentralitySelectionTask*>(mgr->GetTask(name));
93     if (!ctask) return;
94     // ctask->SetPass(fESDPass);
95     if (mc) ctask->SetMCInput();
96   }
97   /** 
98    * Crete output handler - we don't want one here. 
99    * 
100    * @return 0
101    */
102   AliVEventHandler* CreateOutputHandler(UShort_t) { return 0; }
103
104   //__________________________________________________________________
105   const char* ClassName() const { return "MakeFMDELossTrain"; }
106   //__________________________________________________________________
107   /** 
108    * Overloaded to create new Extract.C in the output 
109    * directory
110    * 
111    * @param asShellScript 
112    */
113   void SaveSetup(Bool_t asShellScript)
114   {
115     TrainSetup::SaveSetup(asShellScript);
116
117     std::ofstream f("Extract.C");
118     if (!f) { 
119       Error("SaveSetup", "Failed to open Extract.C");
120       return;
121     }
122     f << "// Generated by " << ClassName() << "\n"
123       << "void Extract()\n"
124       << "{\n"
125       << "  gROOT->LoadMacro(\"$ALICE_ROOT/PWGLF/FORWARD/analysis2/corrs/ExtractELoss.C\");\n"
126       << "  ExtractELoss(\"forward_eloss.root\"," 
127       <<  fHelper->IsMC() << ");\n"
128       << "}\n"
129       << "// EOF" << std::endl;
130     f.close();
131   }
132 };
133
134 //
135 // EOF
136 //