]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/trains/MakeFMDELossTrain.C
Merge branch 'feature-movesplit'
[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     fRailway->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     CoupleCar("AddTaskFMDELoss.C", Form("%d,%d,\"%s\",\"%s\"", 
78                                         mc, onlyMB,  
79                                         config.Data(), 
80                                         corrs.Data()));
81     fRailway->LoadAux(gSystem->Which(gROOT->GetMacroPath(), config), true);
82     if (!corrs.IsNull())
83       fRailway->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)
93   {
94     if (!fOptions.Has("cent")) return;
95     TrainSetup::CreateCentralitySelection(mc);    
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     SaveExtract();
117     SaveSummarize();
118     SaveReFit();
119   }
120   void SaveExtract()
121   {
122     std::ofstream f("Extract.C");
123     if (!f) { 
124       Error("SaveSetup", "Failed to open Extract.C");
125       return;
126     }
127     f << "// Generated by " << ClassName() << "\n"
128       << "void Extract(Bool_t mc=" << HasMCHandler() << ",\n"
129       << "             const char* file=\"forward_eloss.root\")\n"
130       << "{\n"
131       << "  const char* fwd=\"$ALICE_ROOT/PWGLF/FORWARD/analysis2\";\n"
132       << "  gROOT->LoadMacro(Form(\"%s/corrs/ExtractELoss.C\",fwd));\n"
133       << "  ExtractELoss(file,mc);\n" 
134       << "}\n"
135       << "// EOF" << std::endl;
136     f.close();
137   }
138   void SaveSummarize()
139   {
140     std::ofstream f("Summarize.C");
141     if (!f) { 
142       Error("SaveSummarize", "Failed to open Summarize.C script");
143       return;
144     }
145     f << std::boolalpha 
146       << "// Generated by " << ClassName() << "\n"
147       << "//\n"
148       << "void Summarize(Bool_t mc=" << HasMCHandler() << ",\n"
149       << "               const char* filename=\"forward_eloss.root\")\n"
150       << "{\n"
151       << "  const char* fwd=\"$ALICE_ROOT/PWGLF/FORWARD/analysis2\";\n"
152       << "  gROOT->LoadMacro(Form(\"%s/corrs/DrawCorrELoss.C\",fwd));\n"
153       << "  DrawCorrELoss(mc,filename);\n"
154       << "}\n"
155       << "// EOF" << std::endl;
156     f.close();
157   }
158   void SaveReFit()
159   {
160     std::ofstream f("ReFit.C");
161     if (!f) { 
162       Error("SaveRerun", "Failed to open ReFit.C script");
163       return;
164     }
165     f << std::boolalpha 
166       << "// Generated by " << ClassName() << "\n"
167       << "// If force=true, then force set parameters\n"
168       << "// If shift=true, enable extra shift in Delta from sigma/xi\n"
169       << "//\n"
170       << "void ReFit(Bool_t      force=false,\n"
171       << "           Bool_t      shift=true,\n"
172       << "           const char* filename=\"forward_eloss.root\")\n"
173       << "{\n"
174       << "  const char* fwd=\"$ALICE_ROOT/PWGLF/FORWARD/analysis2\";\n"
175       << "  gROOT->LoadMacro(Form(\"%s/corrs/RerunELossFits.C\",fwd));\n"
176       << "  RerunELossFits(force,filename);\n"
177       << "}\n"
178       << "// EOF" << std::endl;
179     f.close();
180   }
181   void PostShellCode(std::ostream& f)
182   {
183     f << "  mc=" << std::boolalpha << HasMCHandler() << "\n"
184       << "  echo \"=== Extracting Corrections ...\"\n"
185       << "  aliroot -l -b -q ${prefix}Extract.C\\($mc\\)\n"
186       << "  echo \"=== Summarizing results ...\"\n"
187       << "  aliroot -l -b -q ${prefix}Summarize.C\\($mc\\)\n"
188       << "  if test x$dest = x ; then return ; fi\n"
189       << "  echo \"=== Uploading to ${dest} ...\"\n"
190       << "  aliroot -l -b -q Upload.C\\(\\\"${dest}\\\"\\);\n"
191       << std::endl;
192   }
193 };
194
195 //
196 // EOF
197 //