]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/trains/MakeFMDELossTrain.C
Refactoring for AliFMDEnergyFitter to allow sub-classing
[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.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   cent   = fOptions.Has("cent");
72     Bool_t   onlyMB = fOptions.AsBool("only-mb");
73     Int_t    verb   = fOptions.AsInt("verbose");
74     TString  resi   = "";
75     if (fOptions.Has("residuals")) resi = fOptions.Get("residuals"); 
76
77     // --- Add the task ----------------------------------------------
78     AddTask("AddTaskFMDELoss.C", Form("%d,%d,%d,%d,\"%s\"", 
79                                       mc, cent, onlyMB, verb, resi.Data()));
80   }
81   /** 
82    * Create entrality selection if enabled 
83    * 
84    * @param mc   Whether this is MC or not
85    * @param mgr  Analysis manager 
86    */
87   virtual void CreateCentralitySelection(Bool_t mc, AliAnalysisManager* mgr)
88   {
89     if (!fOptions.Has("cent")) return;
90
91     const char* name = "CentralitySelection";
92     gROOT->Macro("AddTaskCentrality.C");
93     AliCentralitySelectionTask* ctask = 
94       dynamic_cast<AliCentralitySelectionTask*>(mgr->GetTask(name));
95     if (!ctask) return;
96     // ctask->SetPass(fESDPass);
97     if (mc) ctask->SetMCInput();
98   }
99   /** 
100    * Crete output handler - we don't want one here. 
101    * 
102    * @return 0
103    */
104   AliVEventHandler* CreateOutputHandler(UShort_t) { return 0; }
105
106   //__________________________________________________________________
107   const char* ClassName() const { return "MakeFMDELossTrain"; }
108   //__________________________________________________________________
109   /** 
110    * Overloaded to create new Extract.C in the output 
111    * directory
112    * 
113    * @param asShellScript 
114    */
115   void SaveSetup(Bool_t asShellScript)
116   {
117     TrainSetup::SaveSetup(asShellScript);
118     SaveExtract();
119     SaveSummarize();
120   }
121   void SaveExtract()
122   {
123     std::ofstream f("Extract.C");
124     if (!f) { 
125       Error("SaveSetup", "Failed to open Extract.C");
126       return;
127     }
128     f << "// Generated by " << ClassName() << "\n"
129       << "void Extract()\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(\"forward_eloss.root\"," 
134       <<  fHelper->IsMC() << ");\n"
135       << "}\n"
136       << "// EOF" << std::endl;
137     f.close();
138   }
139   void SaveSummarize()
140   {
141     std::ofstream f("Summarize.C");
142     if (!f) { 
143       Error("SaveSummarize", "Failed to open Summarize.C script");
144       return;
145     }
146     f << "// Generated by " << ClassName() << "\n"
147       << "//\n"
148       << "void Summarize(Bool_t mc=false,\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 PostShellCode(std::ostream& f)
159   {
160     Bool_t   mc   = HasMCHandler();
161     f << "  echo \"=== Extracting Corrections ...\"\n"
162       << "  aliroot -l -b -q ${prefix}Extract.C\n"
163       << "  echo \"=== Summarizing results ...\"\n"
164       << "  aliroot -l -b -q ${prefix}Summarize.C\\(" << mc << "\\)\n"
165       << "  if test x$dest = x ; then return ; fi\n"
166       << "  echo \"=== Uploading to ${dest} ...\"\n"
167       << "  aliroot -l -b -q Upload.C\\(\\\"${dest}\\\"\\);\n"
168       << std::endl;
169   }
170 };
171
172 //
173 // EOF
174 //