]>
Commit | Line | Data |
---|---|---|
7a3e34f4 | 1 | /** |
2 | * @file MakeFMDMCTrackTrain.C | |
3 | * @author Christian Holm Christensen <cholm@nbi.dk> | |
4 | * @date Fri Jun 1 13:54:47 2012 | |
5 | * | |
6 | * @brief | |
7 | * | |
8 | * @ingroup pwglf_forward_trains_specific | |
9 | */ | |
10 | #include "TrainSetup.C" | |
11 | // #include "ParUtilities.C" | |
12 | ||
13 | //==================================================================== | |
14 | /** | |
15 | * Analysis train to make Forward and Central MC corrections | |
16 | * | |
17 | * | |
18 | * @ingroup pwglf_forward_mc | |
19 | * @ingroup pwglf_forward_trains_specific | |
20 | */ | |
21 | class MakeFMDMCTrackTrain : public TrainSetup | |
22 | { | |
23 | public: | |
24 | /** | |
25 | * Constructor. Date and time must be specified when running this | |
26 | * in Termiante mode on Grid | |
27 | * | |
28 | * @param name Name of train (free form) | |
29 | */ | |
30 | MakeFMDMCTrackTrain(const char* name) | |
31 | : TrainSetup(name) | |
32 | { | |
33 | fOptions.Add("use-tuple", "Whether to make an NTuple of hits"); | |
34 | fOptions.Add("max-strips", "NUMBER", "Max strips/cluster", 2); | |
35 | fOptions.Set("type", "ESD"); | |
36 | } | |
37 | protected: | |
38 | /** | |
39 | * Create the tasks | |
40 | * | |
41 | * @param mgr Analysis manager | |
42 | */ | |
43 | void CreateTasks(AliAnalysisManager* mgr) | |
44 | { | |
45 | // --- Output file name ------------------------------------------ | |
46 | AliAnalysisManager::SetCommonFileName("forward_mctracks.root"); | |
47 | ||
48 | ||
49 | // --- Load libraries/pars --------------------------------------- | |
78ac7e09 | 50 | fRailway->LoadLibrary("PWGLFforward2"); |
51 | // fRailway->LoadLibrary("Proof"); | |
52 | // fRailway->LoadLibrary("Gui"); // Sigh! CDB depends on GUI! | |
53 | // fRailway->LoadLibrary("CDB"); | |
54 | // fRailway->LoadLibrary("RAWDatabase"); | |
55 | // fRailway->LoadLibrary("STEER"); | |
56 | // fRailway->LoadLibrary("FMDbase"); | |
57 | // fRailway->LoadLibrary("FMDsim"); | |
58 | // fRailway->LoadLibrary("PWGLFforwardhit"); | |
7a3e34f4 | 59 | |
60 | // --- Set load path --------------------------------------------- | |
61 | gROOT->SetMacroPath(Form("%s:$(ALICE_ROOT)/PWGLF/FORWARD/analysis2", | |
62 | gROOT->GetMacroPath())); | |
63 | ||
64 | // --- Check if this is MC --------------------------------------- | |
65 | if (!mgr->GetMCtruthEventHandler()) | |
66 | Fatal("CreateTasks", "No MC truth handler"); | |
67 | ||
68 | Bool_t useTuple = fOptions.AsBool("use-tuple"); | |
69 | UShort_t maxStrips = fOptions.AsInt("max-strips"); | |
70 | Int_t verbose = fOptions.AsInt("verbose"); | |
71 | ||
72 | TString args = TString::Format("%d,%d,%d", | |
73 | useTuple, | |
74 | maxStrips, | |
75 | verbose); | |
78ac7e09 | 76 | if (!CoupleCar("AddTaskFMDMCTracks.C", args)) |
7a3e34f4 | 77 | Fatal("CreateTasks", "Couldn't add our task"); |
78 | } | |
79 | //__________________________________________________________________ | |
80 | /** | |
81 | * Create physics selection , and add to manager | |
82 | * | |
83 | * @param mc Whether this is for MC | |
84 | * @param mgr Manager | |
85 | */ | |
86 | void CreatePhysicsSelection(Bool_t mc, | |
87 | AliAnalysisManager* mgr) | |
88 | { | |
89 | TrainSetup::CreatePhysicsSelection(mc, mgr); | |
90 | ||
91 | // --- Get input event handler ----------------------------------- | |
92 | AliInputEventHandler* ih = | |
93 | dynamic_cast<AliInputEventHandler*>(mgr->GetInputEventHandler()); | |
94 | if (!ih) | |
95 | Fatal("CreatePhysicsSelection", "Couldn't get input handler (%p)", ih); | |
96 | ||
97 | // --- Get Physics selection ------------------------------------- | |
98 | AliPhysicsSelection* ps = | |
99 | dynamic_cast<AliPhysicsSelection*>(ih->GetEventSelection()); | |
100 | if (!ps) | |
101 | Fatal("CreatePhysicsSelection", "Couldn't get PhysicsSelection (%p)", ps); | |
102 | ||
103 | // --- Ignore trigger class when selecting events. This means --- | |
104 | // --- that we get offline+(A,C,E) events too -------------------- | |
105 | // ps->SetSkipTriggerClassSelection(true); | |
106 | } | |
107 | //__________________________________________________________________ | |
108 | /** | |
109 | * @return 0 - AOD disabled | |
110 | */ | |
111 | virtual AliVEventHandler* CreateOutputHandler(UShort_t) { return 0; } | |
112 | /** | |
113 | * Do not the centrality selection | |
114 | */ | |
78ac7e09 | 115 | // void CreateCentralitySelection(Bool_t) {} |
7a3e34f4 | 116 | //__________________________________________________________________ |
117 | const char* ClassName() const { return "MakeFMDMCTrackTrain"; } | |
118 | ||
119 | /** | |
120 | * Overloaded to create new dNdeta.C and dndeta.sh in the output | |
121 | * directory | |
122 | * | |
123 | * @param asShellScript | |
124 | */ | |
125 | void SaveSetup(Bool_t asShellScript) | |
126 | { | |
127 | TrainSetup::SaveSetup(asShellScript); | |
128 | SaveSummarize(); | |
2681f575 | 129 | SaveAnalyseNTuple(); |
130 | SaveReFit(); | |
131 | ||
9c6eaffb | 132 | |
133 | if (!fRailway || fRailway->Mode() != Railway::kGrid) return; | |
134 | ||
135 | SaveDownloadTrees(); | |
136 | ||
7a3e34f4 | 137 | } |
138 | /** | |
139 | * Write a ROOT script to draw summary | |
140 | * | |
141 | */ | |
142 | void SaveSummarize() | |
143 | { | |
144 | std::ofstream f("Summarize.C"); | |
145 | if (!f) { | |
146 | Error("SaveSummarize", "Failed to open Summarize.C script"); | |
147 | return; | |
148 | } | |
149 | f << "// Generated by " << ClassName() << "\n" | |
150 | << "// WHAT is a bit mask of\n" | |
151 | << "// 0x001 Event inspector\n" | |
152 | << "// 0x002 Track inspector\n" | |
153 | << "// 0x004 Energy loss fits\n" | |
154 | << "// 0x100 Landscape\n" | |
155 | << "// 0x200 Pause\n" | |
156 | << "//\n" | |
157 | << "void Summarize(const char* filename=\"forward_mctracks.root\",\n" | |
158 | << " UShort_t what=0x10F)\n" | |
159 | << "{\n" | |
160 | << " const char* fwd=\"$ALICE_ROOT/PWGLF/FORWARD/analysis2\";\n" | |
9c6eaffb | 161 | << " gROOT->LoadMacro(Form(\"%s/scripts/SummaryMCTrackDrawer.C+g\",fwd));\n" |
162 | << " SummaryMCTrackDrawer smd;\n" | |
7a3e34f4 | 163 | << " smd.Run(filename,what);\n" |
164 | << "}\n" | |
165 | << "// EOF" << std::endl; | |
166 | f.close(); | |
167 | } | |
9c6eaffb | 168 | /** |
169 | * Make a ROOT Script to download the generated AODs | |
170 | * | |
171 | */ | |
172 | void SaveDownloadTrees() | |
173 | { | |
174 | std::ofstream f("DownloadTrees.C"); | |
175 | if (!f) { | |
176 | Error("SaveDownloadTrees", "Failed to open DownloadTrees.C"); | |
177 | return; | |
178 | } | |
179 | f << "// Generated by " << ClassName() << "\n" | |
180 | << "void DownloadTrees(Bool_t force=false)\n" | |
181 | << "{\n" | |
182 | << " if (!TGrid::Connect(\"alien://\")) {\n" | |
183 | << " Error(\"DownloadTrees\",\"Failed to connect to AliEn\");\n" | |
184 | << " return;\n" | |
185 | << " }\n\n" | |
186 | << " TString dir(\"" << fRailway->OutputPath() << "\");\n" | |
187 | << " TString pat(\"*/forward_tuple.root\");\n" | |
188 | << " TGridResult* r = gGrid->Query(dir,pat);\n" | |
189 | << " if (!r) {\n" | |
190 | << " Error(\"DownloadTrees\",\"No result from query\");\n" | |
191 | << " return;\n" | |
192 | << " }\n\n" | |
193 | << " Int_t n = r->GetEntries();\n" | |
194 | << " Printf(\"=== Got a total of %d AOD files\",n);\n" | |
195 | << " for (Int_t i = 0; i < n; i++) {\n" | |
196 | << " TString path(r->GetKey(i, \"turl\"));\n" | |
197 | << " TString dir(gSystem->DirName(path));\n" | |
198 | << " TString sub(gSystem->BaseName(dir));\n" | |
199 | << " TString subsub(gSystem->BaseName(gSystem->DirName(dir)));\n" | |
200 | << " TString out = TString::Format(\"forward_tree_%s_%s.root\",\n" | |
201 | << " subsub.Data(),sub.Data());\n" | |
202 | << " if (!gSystem->AccessPathName(out.Data()) && !force) {\n" | |
203 | << " Printf(\"=== Already have %s\",out.Data());\n" | |
204 | << " continue;\n" | |
205 | << " }\n" | |
206 | << " Printf(\"=== Getting %s %s (%3d/%3d)\",\n" | |
207 | << " subsub.Data(),sub.Data(),i,n);\n" | |
208 | << " if (!TFile::Cp(path, out)) {\n" | |
209 | << " Warning(\"DownloadTrees\",\"Failed to copy %s -> %s\",\n" | |
210 | << " path.Data(), out.Data());\n" | |
211 | << " continue;\n" | |
212 | << " }\n" | |
213 | << " }\n" | |
214 | << "}\n" | |
215 | << "// EOF\n" | |
216 | << std::endl; | |
217 | f.close(); | |
218 | } | |
2681f575 | 219 | /** |
220 | * Make a ROOT Script to download the generated AODs | |
221 | * | |
222 | */ | |
223 | void SaveAnalyseNTuple() | |
224 | { | |
225 | std::ofstream f("AnalyseNTuple.C"); | |
226 | if (!f) { | |
227 | Error("SaveAnalyseNTuple", "Failed to open AnalyseNTuple.C"); | |
228 | return; | |
229 | } | |
230 | f << "// Generated by " << ClassName() << "\n" | |
231 | << "// Process with bare ROOT in ProofLite\n" | |
232 | << "void AnalyseNTuple(Bool_t proof=true,\n" | |
233 | << " Long64_t max=-1,\n" | |
234 | << " const char* opt=\"\")\n" | |
235 | << "{\n" | |
236 | << " const char* fwd=\"$ALICE_ROOT/PWGLF/FORWARD/analysis2\";\n" | |
237 | << " gSystem->AddIncludePath(\"-I${ALICE_ROOT}/include\");\n" | |
238 | << " gROOT->Macro(Form(\"%s/scripts/LoadLibs.C\",fwd));\n" | |
239 | << " gROOT->LoadMacro(Form(\"%s/scripts/TupleSelector.C+%s\",\n" | |
240 | << " fwd, opt));\n" | |
241 | << " if (proof) TupleSelector::Proof(maxEvents, opt);\n" | |
242 | << " else TupleSelector::Run(maxEvents);\n" | |
243 | << "}\n" | |
244 | << "// EOF" << std::endl; | |
245 | f.close(); | |
246 | } | |
247 | void SaveReFit() | |
248 | { | |
249 | std::ofstream f("ReFit.C"); | |
250 | if (!f) { | |
251 | Error("SaveRerun", "Failed to open ReFit.C script"); | |
252 | return; | |
253 | } | |
254 | f << std::boolalpha | |
255 | << "// Generated by " << ClassName() << "\n" | |
256 | << "// If force=true, then force set parameters\n" | |
257 | << "//\n" | |
258 | << "void ReFit(Bool_t force=false,\n" | |
259 | << " const char* filename=\"forward_mctracks.root\")\n" | |
260 | << "{\n" | |
261 | << " const char* fwd=\"$ALICE_ROOT/PWGLF/FORWARD/analysis2\";\n" | |
262 | << " gROOT->LoadMacro(Form(\"%s/corrs/RerunTrackELoss.C\",fwd));\n" | |
263 | << " RerunTrackELoss(force,filename);\n" | |
264 | << "}\n" | |
265 | << "// EOF" << std::endl; | |
266 | f.close(); | |
267 | } | |
268 | ||
9c6eaffb | 269 | void PostShellCode(std::ostream& f) |
270 | { | |
271 | f << " echo \"=== Summarizing results ...\"\n" | |
272 | << " aliroot -l -b -q ${prefix}Summarize.C\n" | |
273 | << std::endl; | |
274 | } | |
275 | ||
7a3e34f4 | 276 | }; |
277 | ||
278 | // | |
279 | // EOF | |
280 | // |