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