1 #include "AliBaseAODTask.h"
2 #include "AliForwardUtil.h"
3 #include "AliAODForwardMult.h"
4 #include "AliAODCentralMult.h"
5 #include <AliAnalysisManager.h>
7 #include <AliAODEvent.h>
10 #include <TInterpreter.h>
12 //____________________________________________________________________
13 AliBaseAODTask::AliBaseAODTask()
14 : AliAnalysisTaskSE(),
15 fTriggerMask(0xFFFFFFFF),
31 //____________________________________________________________________
32 AliBaseAODTask::AliBaseAODTask(const char* name,
34 : AliAnalysisTaskSE(name),
35 fTriggerMask(0xFFFFFFFF),
50 SetTitle(title && title[0] != '\0' ? title : this->ClassName());
51 fCentAxis.SetName("centAxis");
52 fCentAxis.SetTitle("Centrality [%]");
53 DefineOutput(1, TList::Class());
54 DefineOutput(2, TList::Class());
57 //____________________________________________________________________
59 AliBaseAODTask::Configure(const char* macro)
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);
68 if (mac.EqualTo("-default-")) mac = DefaultConfig();
69 const char* config = gSystem->Which(gROOT->GetMacroPath(), mac.Data());
71 AliWarningF("%s not found in %s", mac.Data(), gROOT->GetMacroPath());
74 // if (gInterpreter->IsLoaded(config))
75 // gInterpreter->UnloadFile(config);
77 AliInfoF("Loading configuration of '%s' from %s", ClassName(), config);
78 gROOT->Macro(Form("%s((%s*)%p)", config, GetTitle(), this));
80 Info("Configure", "Unloading configuration script");
81 gInterpreter->UnloadFile(config);
87 //________________________________________________________________________
89 AliBaseAODTask::SetTriggerMask(const char* mask)
92 // Set the trigger maskl
97 DGUARD(fDebug,3,"Set the trigger mask: %s", mask);
98 SetTriggerMask(AliAODForwardMult::MakeTriggerMask(mask));
100 //________________________________________________________________________
102 AliBaseAODTask::SetTriggerMask(UShort_t mask)
104 DGUARD(fDebug,3,"Set the trigger mask: 0x%0x", mask);
106 // if (fTriggerString) delete fTriggerString;
107 // fTriggerString = AliForwardUtil::MakeParameter("trigger", fTriggerMask);
109 //________________________________________________________________________
111 AliBaseAODTask::SetCentralityAxis(UShort_t n, Short_t* bins)
113 DGUARD(fDebug,3,"Set centrality axis, %d bins", n);
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());
119 //________________________________________________________________________
121 AliBaseAODTask::SetCentralityAxis(Short_t low, Short_t high)
123 Short_t a[] = { low, high };
124 SetCentralityAxis(1, a);
127 //____________________________________________________________________
129 AliBaseAODTask::Connect(const char* sumFile,
132 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
134 Error("AddTaskForwardMult", "No analysis manager to connect to.");
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");
145 !AliForwardUtil::CheckForTask("AliForwardMultiplicityBase")) {
146 AliError("The relevant task wasn't added to the train");
150 // Add to the manager
153 // Create and connect output containers
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();
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);
174 //____________________________________________________________________
176 AliBaseAODTask::UserCreateOutputObjects()
179 // Create output objects
182 DGUARD(fDebug,1,"Create user ouput");
184 fSums->SetName(Form("%sSums", GetName()));
187 fTriggers = AliAODForwardMult::MakeTriggerHistogram("triggers",fTriggerMask);
188 fTriggers->SetDirectory(0);
190 fEventStatus = AliAODForwardMult::MakeStatusHistogram("status");
191 fEventStatus->SetDirectory(0);
193 fSums->Add(fTriggers);
194 fSums->Add(fEventStatus);
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);
206 fAccVertex = static_cast<TH1D*>(fVertex->Clone("vertexAcc"));
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);
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);
221 fAccCent = static_cast<TH1D*>(fCent->Clone("centAcc"));
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);
229 if (!Book()) AliFatalF("Failed to book output objects for %s", GetName());
231 // Store centrality axis as a histogram - which can be merged
233 if (fCentAxis.GetXbins() && fCentAxis.GetXbins()->GetSize() > 0)
234 cH = new TH1I(fCentAxis.GetName(), fCentAxis.GetTitle(),
235 fCentAxis.GetNbins(), fCentAxis.GetXbins()->GetArray());
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());
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()));
256 //____________________________________________________________________
258 AliBaseAODTask::GetForward(const AliAODEvent& aod, Bool_t mc, Bool_t verb)
260 // Get the forward object that contains our event selection stuff
262 if (mc) obj = aod.FindListObject("ForwardMC");
263 else obj = aod.FindListObject("Forward");
265 if (verb) AliWarning("No forward object found");
268 AliAODForwardMult* forward = static_cast<AliAODForwardMult*>(obj);
271 //____________________________________________________________________
273 AliBaseAODTask::GetCentral(const AliAODEvent& aod, Bool_t mc, Bool_t verb)
275 // Get the forward object that contains our event selection stuff
277 if (mc) obj = aod.FindListObject("CentralClustersMC");
278 else obj = aod.FindListObject("CentralClusters");
280 if (verb) AliWarning("No central object found");
283 AliAODCentralMult* central = static_cast<AliAODCentralMult*>(obj);
286 //____________________________________________________________________
288 AliBaseAODTask::GetPrimary(const AliAODEvent& aod)
290 TObject* obj = aod.FindListObject("primary");
291 // We should have a forward object at least
295 TH2D* ret = static_cast<TH2D*>(obj);
299 //____________________________________________________________________
301 AliBaseAODTask::UserExec(Option_t *)
304 // Process a single event
310 DGUARD(fDebug,1,"Analyse the AOD event");
311 if (!PreEvent()) return;
313 AliAODEvent* aod = AliForwardUtil::GetAODEvent(this);
316 // Get the forward object that contains our event selection stuff
317 AliAODForwardMult* forward = GetForward(*aod);
318 if (!forward) return;
321 if (!PreData()) return;
322 StoreInformation(*forward);
326 // Get our ip_z and centrality
327 Double_t vtx = forward->GetIpZ();
328 Float_t cent = forward->GetCentrality();
332 // Now check our event selectio up front
333 if (!CheckEvent(*forward)) return;
335 // Let user defined code do the job
336 Bool_t taken = Event(*aod);
338 // Fill our histograms
340 fAccVertex->Fill(vtx);
341 fAccCent->Fill(cent);
349 //____________________________________________________________________
351 AliBaseAODTask::CheckEvent(const AliAODForwardMult& forward)
354 return forward.CheckEvent(fTriggerMask, fMinIpZ, fMaxIpZ,
355 UShort_t(fCentAxis.GetXmin()),
356 UShort_t(fCentAxis.GetXmax()),
357 fTriggers, fEventStatus);
358 return forward.CheckEvent(fTriggerMask, fMinIpZ, fMaxIpZ,
359 0, 0, fTriggers, fEventStatus);
362 //____________________________________________________________________
364 AliBaseAODTask::StoreInformation(AliAODForwardMult& forward)
366 fSums->Add(AliForwardUtil::MakeParameter("sNN", forward.GetSNN()));
367 fSums->Add(AliForwardUtil::MakeParameter("sys", forward.GetSystem()));
370 //____________________________________________________________________
372 AliBaseAODTask::Terminate(Option_t*)
374 TList* list = dynamic_cast<TList*>(GetOutputData(1));
376 AliError(Form("No output list defined (%p)", GetOutputData(1)));
377 if (GetOutputData(1)) GetOutputData(1)->Print();
381 // Assign to our internal variable for use by sub-classes
384 // Create our output container
385 TString resName(Form("%sResults", GetName()));
387 fResults = static_cast<TList*>(fSums->Clone(resName));
389 fResults = new TList;
390 fResults->SetName(resName);
392 fResults->SetOwner();
394 // Now call user defined routines
396 AliErrorF("Failed to finalize this task (%s)", GetName());
400 PostData(2, fResults);
403 #define PF(N,V,...) \
404 AliForwardUtil::PrintField(N,V, ## __VA_ARGS__)
405 #define PFB(N,FLAG) \
407 AliForwardUtil::PrintName(N); \
408 std::cout << std::boolalpha << (FLAG) << std::noboolalpha << std::endl; \
410 #define PFV(N,VALUE) \
412 AliForwardUtil::PrintName(N); \
413 std::cout << (VALUE) << std::endl; } while(false)
415 //____________________________________________________________________
417 AliBaseAODTask::Print(Option_t* /*option=""*/) const
422 * @param option Not used
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;
436 gROOT->DecreaseDirLevel();