]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/trains/MakeFMDELossTrain.C
Merge remote-tracking branch 'origin/master' into flatdev
[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("only-mb", "Only collect statistics from MB events");
33     fOptions.Add("residuals", "MODE", "Optional calculation of residuals", "");
34     fOptions.Add("corr", "DIR", "Corrections dir", "");
35     fOptions.Set("type", "ESD");
36   }
37 protected:
38   //------------------------------------------------------------------
39   /** 
40    * Create the analysis manager 
41    * 
42    * @param name Name of the analysis 
43    * 
44    * @return Created analysis manager 
45    */
46   virtual AliAnalysisManager* CreateAnalysisManager(const char* name)
47   {
48     AliAnalysisManager* mgr = TrainSetup::CreateAnalysisManager(name);
49     // mgr->SetAutoBranchLoading(false);
50     return mgr;
51   }
52   //__________________________________________________________________
53   /** 
54    * Create the tasks 
55    * 
56    * @param mgr  Analysis manager 
57    */
58   void CreateTasks(AliAnalysisManager* mgr)
59   {
60     // --- Output file name ------------------------------------------
61     AliAnalysisManager::SetCommonFileName("forward_eloss.root");
62
63     // --- Load libraries/pars ---------------------------------------
64     fHelper->LoadLibrary("PWGLFforward2");
65     
66     // --- Set load path ---------------------------------------------
67     gROOT->SetMacroPath(Form("%s:$(ALICE_ROOT)/PWGLF/FORWARD/analysis2",
68                              gROOT->GetMacroPath()));
69
70     // --- Check if this is MC ---------------------------------------
71     Bool_t   mc     = HasMCHandler();
72     Bool_t   cent   = fOptions.Has("cent");
73     Bool_t   onlyMB = fOptions.AsBool("only-mb");
74     Int_t    verb   = fOptions.AsInt("verbose");
75     TString  corrs  = "";
76     if (fOptions.Has("corr")) {
77       corrs = fOptions.Get("corr"); 
78     }
79     TString  resi   = "";
80     if (fOptions.Has("residuals")) resi = fOptions.Get("residuals"); 
81
82     // --- Add the task ----------------------------------------------
83     AddTask("AddTaskFMDELoss.C", Form("%d,%d,%d,%d,\"%s\",\"%s\"", 
84                                       mc, cent, onlyMB, verb, 
85                                       resi.Data(), corrs.Data()));
86
87     if (!corrs.IsNull()) {
88       fHelper->LoadAux(Form("%s/fmd_corrections.root",corrs.Data()), true);
89     }
90   }
91   /** 
92    * Create entrality selection if enabled 
93    * 
94    * @param mc   Whether this is MC or not
95    * @param mgr  Analysis manager 
96    */
97   virtual void CreateCentralitySelection(Bool_t mc, AliAnalysisManager* mgr)
98   {
99     if (!fOptions.Has("cent")) return;
100
101     const char* name = "CentralitySelection";
102     gROOT->Macro("AddTaskCentrality.C");
103     AliCentralitySelectionTask* ctask = 
104       dynamic_cast<AliCentralitySelectionTask*>(mgr->GetTask(name));
105     if (!ctask) return;
106     // ctask->SetPass(fESDPass);
107     if (mc) ctask->SetMCInput();
108   }
109   /** 
110    * Crete output handler - we don't want one here. 
111    * 
112    * @return 0
113    */
114   AliVEventHandler* CreateOutputHandler(UShort_t) { return 0; }
115
116   //__________________________________________________________________
117   const char* ClassName() const { return "MakeFMDELossTrain"; }
118   //__________________________________________________________________
119   /** 
120    * Overloaded to create new Extract.C in the output 
121    * directory
122    * 
123    * @param asShellScript 
124    */
125   void SaveSetup(Bool_t asShellScript)
126   {
127     TrainSetup::SaveSetup(asShellScript);
128     SaveExtract();
129     SaveSummarize();
130     SaveReFit();
131   }
132   void SaveExtract()
133   {
134     std::ofstream f("Extract.C");
135     if (!f) { 
136       Error("SaveSetup", "Failed to open Extract.C");
137       return;
138     }
139     f << "// Generated by " << ClassName() << "\n"
140       << "void Extract(Bool_t mc=" << HasMCHandler() << ",\n"
141       << "             const char* file=\"forward_eloss.root\")\n"
142       << "{\n"
143       << "  const char* fwd=\"$ALICE_ROOT/PWGLF/FORWARD/analysis2\";\n"
144       << "  gROOT->LoadMacro(Form(\"%s/corrs/ExtractELoss.C\",fwd));\n"
145       << "  ExtractELoss(file,mc);\n" 
146       << "}\n"
147       << "// EOF" << std::endl;
148     f.close();
149   }
150   void SaveSummarize()
151   {
152     std::ofstream f("Summarize.C");
153     if (!f) { 
154       Error("SaveSummarize", "Failed to open Summarize.C script");
155       return;
156     }
157     f << std::boolalpha 
158       << "// Generated by " << ClassName() << "\n"
159       << "//\n"
160       << "void Summarize(Bool_t mc=" << HasMCHandler() << ",\n"
161       << "               const char* filename=\"forward_eloss.root\")\n"
162       << "{\n"
163       << "  const char* fwd=\"$ALICE_ROOT/PWGLF/FORWARD/analysis2\";\n"
164       << "  gROOT->LoadMacro(Form(\"%s/corrs/DrawCorrELoss.C\",fwd));\n"
165       << "  DrawCorrELoss(mc,filename);\n"
166       << "}\n"
167       << "// EOF" << std::endl;
168     f.close();
169   }
170   void SaveReFit()
171   {
172     std::ofstream f("ReFit.C");
173     if (!f) { 
174       Error("SaveRerun", "Failed to open ReFit.C script");
175       return;
176     }
177     f << std::boolalpha 
178       << "// Generated by " << ClassName() << "\n"
179       << "// If force=true, then force set parameters\n"
180       << "// If shift=true, enable extra shift in Delta from sigma/xi\n"
181       << "//\n"
182       << "void ReFit(Bool_t      force=false,\n"
183       << "           Bool_t      shift=true,\n"
184       << "           const char* filename=\"forward_eloss.root\")\n"
185       << "{\n"
186       << "  const char* fwd=\"$ALICE_ROOT/PWGLF/FORWARD/analysis2\";\n"
187       << "  gROOT->LoadMacro(Form(\"%s/corrs/RerunELossFits.C\",fwd));\n"
188       << "  RerunELossFits(force,filename);\n"
189       << "}\n"
190       << "// EOF" << std::endl;
191     f.close();
192   }
193   void PostShellCode(std::ostream& f)
194   {
195     f << "  mc=" << std::boolalpha << HasMCHandler() << "\n"
196       << "  echo \"=== Extracting Corrections ...\"\n"
197       << "  aliroot -l -b -q ${prefix}Extract.C\\($mc\\)\n"
198       << "  echo \"=== Summarizing results ...\"\n"
199       << "  aliroot -l -b -q ${prefix}Summarize.C\\($mc\\)\n"
200       << "  if test x$dest = x ; then return ; fi\n"
201       << "  echo \"=== Uploading to ${dest} ...\"\n"
202       << "  aliroot -l -b -q Upload.C\\(\\\"${dest}\\\"\\);\n"
203       << std::endl;
204   }
205 };
206
207 //
208 // EOF
209 //