]>
Commit | Line | Data |
---|---|---|
c8b1a7db | 1 | #include "AliBaseAODTask.h" |
2 | #include "AliForwardUtil.h" | |
3 | #include "AliAODForwardMult.h" | |
4 | #include "AliAODCentralMult.h" | |
5 | #include <AliAnalysisManager.h> | |
6 | #include <AliLog.h> | |
7 | #include <AliAODEvent.h> | |
8 | #include <TROOT.h> | |
dc1adf8d | 9 | #include <TSystem.h> |
10 | #include <TInterpreter.h> | |
c8b1a7db | 11 | |
12 | //____________________________________________________________________ | |
13 | AliBaseAODTask::AliBaseAODTask() | |
14 | : AliAnalysisTaskSE(), | |
15 | fTriggerMask(0xFFFFFFFF), | |
16 | fMinIpZ(0), | |
17 | fMaxIpZ(-1), | |
18 | fCentAxis(0, 0, -1), | |
19 | fTriggers(0), | |
20 | fEventStatus(0), | |
21 | fVertex(0), | |
22 | fCent(0), | |
23 | fAccVertex(0), | |
24 | fAccCent(0), | |
25 | fFirstEvent(true), | |
26 | fCloneList(false), | |
27 | fSums(0), | |
28 | fResults(0) | |
29 | { | |
30 | } | |
31 | //____________________________________________________________________ | |
dc1adf8d | 32 | AliBaseAODTask::AliBaseAODTask(const char* name, |
33 | const char* title) | |
c8b1a7db | 34 | : AliAnalysisTaskSE(name), |
35 | fTriggerMask(0xFFFFFFFF), | |
36 | fMinIpZ(0), | |
37 | fMaxIpZ(-1), | |
38 | fCentAxis(0, 0, -1), | |
39 | fTriggers(0), | |
40 | fEventStatus(0), | |
41 | fVertex(0), | |
42 | fCent(0), | |
43 | fAccVertex(0), | |
44 | fAccCent(0), | |
45 | fFirstEvent(true), | |
46 | fCloneList(false), | |
47 | fSums(0), | |
48 | fResults(0) | |
49 | { | |
dc1adf8d | 50 | SetTitle(title && title[0] != '\0' ? title : this->ClassName()); |
c8b1a7db | 51 | fCentAxis.SetName("centAxis"); |
52 | fCentAxis.SetTitle("Centrality [%]"); | |
53 | DefineOutput(1, TList::Class()); | |
54 | DefineOutput(2, TList::Class()); | |
55 | } | |
dc1adf8d | 56 | |
57 | //____________________________________________________________________ | |
58 | Bool_t | |
59 | AliBaseAODTask::Configure(const char* macro) | |
60 | { | |
61 | // --- Configure the task ------------------------------------------ | |
62 | TString macroPath(gROOT->GetMacroPath()); | |
63 | if (!macroPath.Contains("$(ALICE_ROOT)/PWGLF/FORWARD/analysis2")) { | |
64 | macroPath.Append(":$(ALICE_ROOT)/PWGLF/FORWARD/analysis2"); | |
65 | gROOT->SetMacroPath(macroPath); | |
66 | } | |
67 | TString mac(macro); | |
5f1a3318 | 68 | if (mac.EqualTo("-default-")) mac = DefaultConfig(); |
dc1adf8d | 69 | const char* config = gSystem->Which(gROOT->GetMacroPath(), mac.Data()); |
70 | if (!config) { | |
71 | AliWarningF("%s not found in %s", mac.Data(), gROOT->GetMacroPath()); | |
72 | return false; | |
73 | } | |
74 | // if (gInterpreter->IsLoaded(config)) | |
75 | // gInterpreter->UnloadFile(config); | |
76 | ||
77 | AliInfoF("Loading configuration of '%s' from %s", ClassName(), config); | |
78 | gROOT->Macro(Form("%s((%s*)%p)", config, GetTitle(), this)); | |
79 | ||
80 | Info("Configure", "Unloading configuration script"); | |
81 | gInterpreter->UnloadFile(config); | |
82 | delete config; | |
83 | ||
84 | return true; | |
85 | } | |
86 | ||
c8b1a7db | 87 | //________________________________________________________________________ |
88 | void | |
89 | AliBaseAODTask::SetTriggerMask(const char* mask) | |
90 | { | |
91 | // | |
92 | // Set the trigger maskl | |
93 | // | |
94 | // Parameters: | |
95 | // mask Trigger mask | |
96 | // | |
97 | DGUARD(fDebug,3,"Set the trigger mask: %s", mask); | |
98 | SetTriggerMask(AliAODForwardMult::MakeTriggerMask(mask)); | |
99 | } | |
100 | //________________________________________________________________________ | |
101 | void | |
102 | AliBaseAODTask::SetTriggerMask(UShort_t mask) | |
103 | { | |
104 | DGUARD(fDebug,3,"Set the trigger mask: 0x%0x", mask); | |
105 | fTriggerMask = mask; | |
106 | // if (fTriggerString) delete fTriggerString; | |
107 | // fTriggerString = AliForwardUtil::MakeParameter("trigger", fTriggerMask); | |
108 | } | |
109 | //________________________________________________________________________ | |
110 | void | |
111 | AliBaseAODTask::SetCentralityAxis(UShort_t n, Short_t* bins) | |
112 | { | |
113 | DGUARD(fDebug,3,"Set centrality axis, %d bins", n); | |
114 | TArrayD dbins(n+1); | |
115 | for (UShort_t i = 0; i <= n; i++) | |
116 | dbins[i] = (bins[i] == 100 ? 100.1 : bins[i]); | |
117 | fCentAxis.Set(n, dbins.GetArray()); | |
118 | } | |
119 | //________________________________________________________________________ | |
120 | void | |
121 | AliBaseAODTask::SetCentralityAxis(Short_t low, Short_t high) | |
122 | { | |
123 | Short_t a[] = { low, high }; | |
124 | SetCentralityAxis(1, a); | |
125 | } | |
126 | ||
127 | //____________________________________________________________________ | |
128 | Bool_t | |
129 | AliBaseAODTask::Connect(const char* sumFile, | |
130 | const char* resFile) | |
131 | { | |
132 | AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager(); | |
133 | if (!mgr) { | |
134 | Error("AddTaskForwardMult", "No analysis manager to connect to."); | |
135 | return false; | |
136 | } | |
137 | ||
138 | // --- Check that we have an AOD input handler --------------------- | |
139 | UShort_t aodInput = 0; | |
140 | if (!(aodInput = AliForwardUtil::CheckForAOD())) { | |
141 | AliError("Cannot proceed without and AOD handler"); | |
142 | return false; | |
143 | } | |
144 | if (aodInput == 2 && | |
145 | !AliForwardUtil::CheckForTask("AliForwardMultiplicityBase")) { | |
146 | AliError("The relevant task wasn't added to the train"); | |
147 | return false; | |
148 | } | |
149 | ||
150 | // Add to the manager | |
151 | mgr->AddTask(this); | |
152 | ||
153 | // Create and connect output containers | |
154 | TString sumOut; | |
155 | TString resOut; | |
156 | if (sumFile && sumFile[0] != '\0') sumOut = sumFile; | |
157 | if (resFile && resFile[0] != '\0') resOut = resFile; | |
158 | else if (sumFile && sumFile[0] != '\0') resOut = sumFile; | |
159 | if (sumOut.IsNull()) sumOut = AliAnalysisManager::GetCommonFileName(); | |
160 | if (resOut.IsNull()) resOut = AliAnalysisManager::GetCommonFileName(); | |
161 | ||
162 | AliAnalysisDataContainer* sumCon = | |
163 | mgr->CreateContainer(Form("%sSums", GetName()), TList::Class(), | |
164 | AliAnalysisManager::kOutputContainer, sumOut); | |
165 | AliAnalysisDataContainer* resCon = | |
166 | mgr->CreateContainer(Form("%sResults", GetName()), TList::Class(), | |
167 | AliAnalysisManager::kParamContainer, resOut); | |
168 | mgr->ConnectInput(this, 0, mgr->GetCommonInputContainer()); | |
169 | mgr->ConnectOutput(this, 1, sumCon); | |
170 | mgr->ConnectOutput(this, 2, resCon); | |
171 | ||
172 | return true; | |
173 | } | |
174 | //____________________________________________________________________ | |
175 | void | |
176 | AliBaseAODTask::UserCreateOutputObjects() | |
177 | { | |
178 | // | |
179 | // Create output objects | |
180 | // | |
181 | // | |
182 | DGUARD(fDebug,1,"Create user ouput"); | |
183 | fSums = new TList; | |
184 | fSums->SetName(Form("%sSums", GetName())); | |
185 | fSums->SetOwner(); | |
186 | ||
187 | fTriggers = AliAODForwardMult::MakeTriggerHistogram("triggers",fTriggerMask); | |
188 | fTriggers->SetDirectory(0); | |
189 | ||
190 | fEventStatus = AliAODForwardMult::MakeStatusHistogram("status"); | |
191 | fEventStatus->SetDirectory(0); | |
192 | ||
193 | fSums->Add(fTriggers); | |
194 | fSums->Add(fEventStatus); | |
195 | ||
196 | TAxis* vA = AliForwardUtil::MakeFullIpZAxis(20); | |
197 | fVertex = new TH1D("vertex", "IP_{z} of all events", | |
198 | vA->GetNbins(), vA->GetXbins()->GetArray()); | |
199 | fVertex->SetXTitle("IP_{z} [cm]"); | |
200 | fVertex->SetYTitle("Events"); | |
201 | fVertex->SetDirectory(0); | |
202 | fVertex->SetFillColor(kRed+2); | |
203 | fVertex->SetFillStyle(3001); | |
204 | fVertex->SetLineColor(kRed+2); | |
205 | fSums->Add(fVertex); | |
dc1adf8d | 206 | fAccVertex = static_cast<TH1D*>(fVertex->Clone("vertexAcc")); |
c8b1a7db | 207 | fAccVertex->SetTitle("IP_{z} of accepted events"); |
208 | fAccVertex->SetDirectory(0); | |
209 | fAccVertex->SetFillColor(kGreen+2); | |
210 | fAccVertex->SetLineColor(kGreen+2); | |
211 | fSums->Add(fAccVertex); | |
212 | ||
213 | fCent = new TH1D("cent","Centrality of all events",100, 0, 100); | |
214 | fCent->SetXTitle("Centrality [%]"); | |
215 | fCent->SetYTitle("Events"); | |
216 | fCent->SetFillColor(kRed+2); | |
217 | fCent->SetFillStyle(3001); | |
218 | fCent->SetLineColor(kRed+2); | |
219 | fCent->SetDirectory(0); | |
220 | fSums->Add(fCent); | |
dc1adf8d | 221 | fAccCent = static_cast<TH1D*>(fCent->Clone("centAcc")); |
c8b1a7db | 222 | fAccCent->SetTitle("Centrality of accepted events"); |
223 | fAccCent->SetDirectory(0); | |
224 | fAccCent->SetFillColor(kGreen+2); | |
225 | fAccCent->SetLineColor(kGreen+2); | |
226 | fSums->Add(fAccCent); | |
227 | ||
228 | ||
229 | if (!Book()) AliFatalF("Failed to book output objects for %s", GetName()); | |
230 | ||
231 | // Store centrality axis as a histogram - which can be merged | |
a06cd88d | 232 | TH1* cH = 0; |
233 | if (fCentAxis.GetXbins() && fCentAxis.GetXbins()->GetSize() > 0) | |
234 | cH = new TH1I(fCentAxis.GetName(), fCentAxis.GetTitle(), | |
235 | fCentAxis.GetNbins(), fCentAxis.GetXbins()->GetArray()); | |
236 | else | |
237 | cH = new TH1I(fCentAxis.GetName(), fCentAxis.GetTitle(), | |
238 | fCentAxis.GetNbins(), fCentAxis.GetXmin(), | |
239 | fCentAxis.GetXmax()); | |
240 | cH->GetXaxis()->SetTitle(fCentAxis.GetTitle()); | |
241 | cH->GetXaxis()->SetName(fCentAxis.GetName()); | |
242 | ||
243 | fSums->Add(cH); | |
c8b1a7db | 244 | fSums->Add(AliForwardUtil::MakeParameter("trigger", ULong_t(fTriggerMask))); |
245 | fSums->Add(AliForwardUtil::MakeParameter("count", 1)); | |
246 | fSums->Add(AliForwardUtil::MakeParameter("alirootRev", | |
247 | AliForwardUtil::AliROOTRevision())); | |
248 | fSums->Add(AliForwardUtil::MakeParameter("alirootBranch", | |
249 | AliForwardUtil::AliROOTBranch())); | |
250 | ||
251 | Print(); | |
252 | ||
253 | PostData(1, fSums); | |
254 | } | |
255 | ||
256 | //____________________________________________________________________ | |
257 | AliAODForwardMult* | |
258 | AliBaseAODTask::GetForward(const AliAODEvent& aod, Bool_t mc, Bool_t verb) | |
259 | { | |
260 | // Get the forward object that contains our event selection stuff | |
261 | TObject* obj = 0; | |
262 | if (mc) obj = aod.FindListObject("ForwardMC"); | |
263 | else obj = aod.FindListObject("Forward"); | |
264 | if (!obj) { | |
265 | if (verb) AliWarning("No forward object found"); | |
266 | return 0; | |
267 | } | |
268 | AliAODForwardMult* forward = static_cast<AliAODForwardMult*>(obj); | |
269 | return forward; | |
270 | } | |
271 | //____________________________________________________________________ | |
272 | AliAODCentralMult* | |
273 | AliBaseAODTask::GetCentral(const AliAODEvent& aod, Bool_t mc, Bool_t verb) | |
274 | { | |
275 | // Get the forward object that contains our event selection stuff | |
276 | TObject* obj = 0; | |
277 | if (mc) obj = aod.FindListObject("CentralClustersMC"); | |
278 | else obj = aod.FindListObject("CentralClusters"); | |
279 | if (!obj) { | |
280 | if (verb) AliWarning("No central object found"); | |
281 | return 0; | |
282 | } | |
283 | AliAODCentralMult* central = static_cast<AliAODCentralMult*>(obj); | |
284 | return central; | |
285 | } | |
286 | //____________________________________________________________________ | |
287 | TH2D* | |
288 | AliBaseAODTask::GetPrimary(const AliAODEvent& aod) | |
289 | { | |
290 | TObject* obj = aod.FindListObject("primary"); | |
291 | // We should have a forward object at least | |
292 | if (!obj) { | |
293 | return 0; | |
294 | } | |
295 | TH2D* ret = static_cast<TH2D*>(obj); | |
296 | return ret; | |
297 | } | |
298 | ||
299 | //____________________________________________________________________ | |
300 | void | |
301 | AliBaseAODTask::UserExec(Option_t *) | |
302 | { | |
303 | // | |
304 | // Process a single event | |
305 | // | |
306 | // Parameters: | |
307 | // option Not used | |
308 | // | |
309 | // Main loop | |
310 | DGUARD(fDebug,1,"Analyse the AOD event"); | |
311 | if (!PreEvent()) return; | |
312 | ||
313 | AliAODEvent* aod = AliForwardUtil::GetAODEvent(this); | |
314 | if (!aod) return; | |
315 | ||
316 | // Get the forward object that contains our event selection stuff | |
317 | AliAODForwardMult* forward = GetForward(*aod); | |
318 | if (!forward) return; | |
319 | ||
320 | if (fFirstEvent) { | |
321 | if (!PreData()) return; | |
322 | StoreInformation(*forward); | |
323 | fFirstEvent = false; | |
324 | } | |
325 | ||
326 | // Get our ip_z and centrality | |
327 | Double_t vtx = forward->GetIpZ(); | |
328 | Float_t cent = forward->GetCentrality(); | |
329 | fVertex->Fill(vtx); | |
330 | fCent->Fill(cent); | |
331 | ||
332 | // Now check our event selectio up front | |
333 | if (!CheckEvent(*forward)) return; | |
334 | ||
335 | // Let user defined code do the job | |
336 | Bool_t taken = Event(*aod); | |
337 | ||
338 | // Fill our histograms | |
339 | if (taken) { | |
340 | fAccVertex->Fill(vtx); | |
341 | fAccCent->Fill(cent); | |
342 | } | |
343 | ||
344 | PostData(1, fSums); | |
345 | ||
346 | PostEvent(); | |
347 | } | |
348 | ||
349 | //____________________________________________________________________ | |
350 | Bool_t | |
351 | AliBaseAODTask::CheckEvent(const AliAODForwardMult& forward) | |
352 | { | |
353 | if (HasCentrality()) | |
354 | return forward.CheckEvent(fTriggerMask, fMinIpZ, fMaxIpZ, | |
77f97e3f CHC |
355 | UShort_t(fCentAxis.GetXmin()), |
356 | UShort_t(fCentAxis.GetXmax()), | |
c8b1a7db | 357 | fTriggers, fEventStatus); |
358 | return forward.CheckEvent(fTriggerMask, fMinIpZ, fMaxIpZ, | |
359 | 0, 0, fTriggers, fEventStatus); | |
360 | } | |
361 | ||
362 | //____________________________________________________________________ | |
363 | void | |
364 | AliBaseAODTask::StoreInformation(AliAODForwardMult& forward) | |
365 | { | |
366 | fSums->Add(AliForwardUtil::MakeParameter("sNN", forward.GetSNN())); | |
367 | fSums->Add(AliForwardUtil::MakeParameter("sys", forward.GetSystem())); | |
368 | } | |
369 | ||
370 | //____________________________________________________________________ | |
371 | void | |
372 | AliBaseAODTask::Terminate(Option_t*) | |
373 | { | |
374 | TList* list = dynamic_cast<TList*>(GetOutputData(1)); | |
375 | if (!list) { | |
376 | AliError(Form("No output list defined (%p)", GetOutputData(1))); | |
377 | if (GetOutputData(1)) GetOutputData(1)->Print(); | |
378 | return; | |
379 | } | |
380 | ||
381 | // Assign to our internal variable for use by sub-classes | |
382 | fSums = list; | |
383 | ||
384 | // Create our output container | |
385 | TString resName(Form("%sResults", GetName())); | |
386 | if (fCloneList) | |
387 | fResults = static_cast<TList*>(fSums->Clone(resName)); | |
388 | else { | |
389 | fResults = new TList; | |
390 | fResults->SetName(resName); | |
391 | } | |
392 | fResults->SetOwner(); | |
393 | ||
394 | // Now call user defined routines | |
395 | if (!Finalize()) { | |
396 | AliErrorF("Failed to finalize this task (%s)", GetName()); | |
397 | return; | |
398 | } | |
399 | ||
400 | PostData(2, fResults); | |
401 | } | |
402 | ||
403 | #define PF(N,V,...) \ | |
404 | AliForwardUtil::PrintField(N,V, ## __VA_ARGS__) | |
405 | #define PFB(N,FLAG) \ | |
406 | do { \ | |
407 | AliForwardUtil::PrintName(N); \ | |
408 | std::cout << std::boolalpha << (FLAG) << std::noboolalpha << std::endl; \ | |
409 | } while(false) | |
410 | #define PFV(N,VALUE) \ | |
411 | do { \ | |
412 | AliForwardUtil::PrintName(N); \ | |
413 | std::cout << (VALUE) << std::endl; } while(false) | |
414 | ||
415 | //____________________________________________________________________ | |
416 | void | |
417 | AliBaseAODTask::Print(Option_t* /*option=""*/) const | |
418 | { | |
419 | /** | |
420 | * Print this task | |
421 | * | |
422 | * @param option Not used | |
423 | */ | |
424 | AliForwardUtil::PrintTask(*this); | |
425 | gROOT->IncreaseDirLevel(); | |
426 | PFV("Trigger mask", AliAODForwardMult::GetTriggerString(fTriggerMask)); | |
427 | PF("IP z range", "%++6.1f - %+6.1f", fMinIpZ, fMaxIpZ); | |
428 | PFV("Centrality bins", (HasCentrality() ? "" : "none")); | |
429 | if (HasCentrality()) { | |
430 | Int_t nBins = fCentAxis.GetNbins(); | |
431 | const Double_t* bins = fCentAxis.GetXbins()->GetArray(); | |
432 | for (Int_t i = 0; i <= nBins; i++) | |
433 | std::cout << (i==0 ? "" : "-") << bins[i]; | |
434 | std::cout << std::endl; | |
435 | } | |
436 | gROOT->DecreaseDirLevel(); | |
437 | } | |
438 | // | |
439 | // EOF | |
440 | // |