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