]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGLF/FORWARD/analysis2/AliForwardMultiplicityBase.cxx
Cleaned up error handling when missing corrections. Previously
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / AliForwardMultiplicityBase.cxx
CommitLineData
1a26066e 1//====================================================================
7984e5f7 2//
3// Base class for classes that calculate the multiplicity in the
4// forward regions event-by-event
5//
6// Inputs:
7// - AliESDEvent
8//
9// Outputs:
10// - AliAODForwardMult
11//
12// Histograms
13//
14// Corrections used
1a26066e 15#include "AliForwardMultiplicityBase.h"
1174780f 16#include "AliForwardCorrectionManager.h"
fb3430ac 17#include "AliForwardUtil.h"
1a26066e 18#include "AliLog.h"
19#include "AliAODHandler.h"
20#include "AliInputEventHandler.h"
21#include "AliAnalysisManager.h"
1174780f 22#include "AliFMDEventInspector.h"
1174780f 23#include "AliFMDSharingFilter.h"
24#include "AliFMDDensityCalculator.h"
72cc12cd 25#include "AliFMDCorrector.h"
1174780f 26#include "AliFMDHistCollector.h"
2b556440 27#include "AliFMDEventPlaneFinder.h"
7ec4d843 28#include "AliESDEvent.h"
1a26066e 29#include <TROOT.h>
2a276c75 30#include <TSystem.h>
fb3430ac 31#include <TAxis.h>
5bb5d1f6 32#include <THStack.h>
3c5497d0 33#include <iostream>
34#include <iomanip>
1a26066e 35
36//====================================================================
19abe41d 37AliForwardMultiplicityBase::AliForwardMultiplicityBase(const char* name)
38 : AliAnalysisTaskSE(name),
9d05ffeb 39 fEnableLowFlux(false),
19abe41d 40 fFirstEvent(true),
41 fCorrManager(0)
42{
f53fb4f6 43 DGUARD(0,0,"Named Construction of AliForwardMultiplicityBase %s",name);
19abe41d 44 // Set our persistent pointer
45 fCorrManager = &AliForwardCorrectionManager::Instance();
331c3502 46 fBranchNames =
47 "ESD:AliESDRun.,AliESDHeader.,AliMultiplicity.,"
48 "AliESDFMD.,SPDVertex.,PrimaryVertex.";
19abe41d 49}
50
fb3430ac 51//____________________________________________________________________
52AliForwardMultiplicityBase&
53AliForwardMultiplicityBase::operator=(const AliForwardMultiplicityBase& o)
54{
f53fb4f6 55 DGUARD(fDebug,2,"Assignment to AliForwardMultiplicityBase");
d015ecfe 56 if (&o == this) return *this;
fb3430ac 57 fEnableLowFlux = o.fEnableLowFlux;
58 fFirstEvent = o.fFirstEvent;
59 fCorrManager = o.fCorrManager;
60 return *this;
61}
2a276c75 62//____________________________________________________________________
63Bool_t
64AliForwardMultiplicityBase::Configure(const char* macro)
65{
66 // --- Configure the task ------------------------------------------
67 TString macroPath(gROOT->GetMacroPath());
68 if (!macroPath.Contains("$(ALICE_ROOT)/PWGLF/FORWARD/analysis2")) {
69 macroPath.Append(":$(ALICE_ROOT)/PWGLF/FORWARD/analysis2");
70 gROOT->SetMacroPath(macroPath);
71 }
72 const char* config = gSystem->Which(gROOT->GetMacroPath(), macro);
73 if (!config) {
74 AliWarningF("%s not found in %s", macro, gROOT->GetMacroPath());
75 return false;
76 }
77
78 AliInfoF("Loading configuration of '%s' from %s", ClassName(), config);
79 gROOT->Macro(Form("%s((AliForwardMultiplicityBase*)%p)", config, this));
80 delete config;
81
82 return true;
83}
fb3430ac 84
19abe41d 85//____________________________________________________________________
1174780f 86Bool_t
87AliForwardMultiplicityBase::CheckCorrections(UInt_t what) const
88{
89 //
90 // Check if all needed corrections are there and accounted for. If not,
91 // do a Fatal exit
92 //
93 // Parameters:
94 // what Which corrections is needed
95 //
96 // Return:
97 // true if all present, false otherwise
98 //
f53fb4f6 99 DGUARD(fDebug,1,"Checking corrections 0x%x", what);
1174780f 100
101 AliForwardCorrectionManager& fcm = AliForwardCorrectionManager::Instance();
102 // Check that we have the energy loss fits, needed by
103 // AliFMDSharingFilter
104 // AliFMDDensityCalculator
105 if (what & AliForwardCorrectionManager::kELossFits && !fcm.GetELossFit()) {
106 AliFatal(Form("No energy loss fits"));
107 return false;
108 }
109 // Check that we have the double hit correction - (optionally) used by
110 // AliFMDDensityCalculator
111 if (what & AliForwardCorrectionManager::kDoubleHit && !fcm.GetDoubleHit()) {
112 AliFatal("No double hit corrections");
113 return false;
114 }
115 // Check that we have the secondary maps, needed by
72cc12cd 116 // AliFMDCorrector
1174780f 117 // AliFMDHistCollector
118 if (what & AliForwardCorrectionManager::kSecondaryMap &&
119 !fcm.GetSecondaryMap()) {
120 AliFatal("No secondary corrections");
121 return false;
122 }
123 // Check that we have the vertex bias correction, needed by
72cc12cd 124 // AliFMDCorrector
1174780f 125 if (what & AliForwardCorrectionManager::kVertexBias &&
126 !fcm.GetVertexBias()) {
127 AliFatal("No event vertex bias corrections");
128 return false;
129 }
130 // Check that we have the merging efficiencies, optionally used by
72cc12cd 131 // AliFMDCorrector
1174780f 132 if (what & AliForwardCorrectionManager::kMergingEfficiency &&
133 !fcm.GetMergingEfficiency()) {
134 AliFatal("No merging efficiencies");
135 return false;
136 }
cc83fca2 137 // Check that we have the acceptance correction, needed by
138 // AliFMDCorrector
139 if (what & AliForwardCorrectionManager::kAcceptance &&
140 !fcm.GetAcceptance()) {
141 AliFatal("No acceptance corrections");
142 return false;
143 }
1174780f 144 return true;
145}
7ec4d843 146//____________________________________________________________________
147Bool_t
19abe41d 148AliForwardMultiplicityBase::ReadCorrections(const TAxis*& pe,
149 const TAxis*& pv,
150 Bool_t mc)
7ec4d843 151{
fb3430ac 152 //
153 // Read corrections
154 //
155 //
f53fb4f6 156
7ec4d843 157 UInt_t what = AliForwardCorrectionManager::kAll;
158 if (!fEnableLowFlux)
159 what ^= AliForwardCorrectionManager::kDoubleHit;
7ec4d843 160 if (!GetCorrections().IsUseVertexBias())
161 what ^= AliForwardCorrectionManager::kVertexBias;
162 if (!GetCorrections().IsUseAcceptance())
163 what ^= AliForwardCorrectionManager::kAcceptance;
164 if (!GetCorrections().IsUseMergingEfficiency())
165 what ^= AliForwardCorrectionManager::kMergingEfficiency;
f53fb4f6 166 DGUARD(fDebug,1,"Read corrections 0x%x", what);
7ec4d843 167
168 AliForwardCorrectionManager& fcm = AliForwardCorrectionManager::Instance();
169 if (!fcm.Init(GetEventInspector().GetCollisionSystem(),
19abe41d 170 GetEventInspector().GetEnergy(),
171 GetEventInspector().GetField(),
172 mc,
6ff251d8 173 what)) {
174 AliWarning("Failed to read in some corrections, making task zombie");
175 return false;
176 }
7ec4d843 177 if (!CheckCorrections(what)) return false;
178
19abe41d 179 // Sett our persistency pointer
180 // fCorrManager = &fcm;
181
7ec4d843 182 // Get the eta axis from the secondary maps - if read in
183 if (!pe) {
184 pe = fcm.GetEtaAxis();
185 if (!pe) AliFatal("No eta axis defined");
186 }
187 // Get the vertex axis from the secondary maps - if read in
188 if (!pv) {
189 pv = fcm.GetVertexAxis();
190 if (!pv) AliFatal("No vertex axis defined");
191 }
192
193 return true;
194}
195//____________________________________________________________________
196AliESDEvent*
197AliForwardMultiplicityBase::GetESDEvent()
198{
fb3430ac 199 //
200 // Get the ESD event. IF this is the first event, initialise
201 //
f53fb4f6 202 DGUARD(fDebug,1,"Get the ESD event");
6ff251d8 203 if (IsZombie()) return 0;
7ec4d843 204 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
205 if (!esd) {
206 AliWarning("No ESD event found for input event");
207 return 0;
208 }
1174780f 209
7ec4d843 210 // On the first event, initialize the parameters
211 if (fFirstEvent && esd->GetESDRun()) {
212 GetEventInspector().ReadRunDetails(esd);
213
214 AliInfo(Form("Initializing with parameters from the ESD:\n"
215 " AliESDEvent::GetBeamEnergy() ->%f\n"
216 " AliESDEvent::GetBeamType() ->%s\n"
217 " AliESDEvent::GetCurrentL3() ->%f\n"
218 " AliESDEvent::GetMagneticField()->%f\n"
6ff251d8 219 " AliESDEvent::GetRunNumber() ->%d",
7ec4d843 220 esd->GetBeamEnergy(),
221 esd->GetBeamType(),
222 esd->GetCurrentL3(),
223 esd->GetMagneticField(),
224 esd->GetRunNumber()));
225
226 fFirstEvent = false;
227
2b556440 228 GetEventPlaneFinder().SetRunNumber(esd->GetRunNumber());
6ff251d8 229 if (!InitializeSubs()) {
230 AliError("Failed to initialize sub-algorithms, making this a zombie");
231 esd = 0; // Make sure we do nothing on this event
232 Info("GetESDEvent", "ESD event pointer %p", esd);
233 SetZombie(true);
234 // return 0;
235 }
7ec4d843 236 }
237 return esd;
238}
1174780f 239//____________________________________________________________________
1a26066e 240void
241AliForwardMultiplicityBase::MarkEventForStore() const
242{
243 // Make sure the AOD tree is filled
f53fb4f6 244 DGUARD(fDebug,3,"Mark AOD event for storage");
1a26066e 245 AliAnalysisManager* am = AliAnalysisManager::GetAnalysisManager();
246 AliAODHandler* ah =
247 dynamic_cast<AliAODHandler*>(am->GetOutputEventHandler());
248 if (!ah)
249 AliFatal("No AOD output handler set in analysis manager");
250
251 ah->SetFillAOD(kTRUE);
252}
253
5bb5d1f6 254//____________________________________________________________________
255void
256AliForwardMultiplicityBase::MakeRingdNdeta(const TList* input,
257 const char* inName,
258 TList* output,
259 const char* outName,
260 Int_t style) const
261{
262 // Make dN/deta for each ring found in the input list.
263 //
264 // A stack of all the dN/deta is also made for easy drawing.
265 //
266 // Note, that the distributions are normalised to the number of
267 // observed events only - they should be corrected for
f53fb4f6 268 DGUARD(fDebug,3,"Make first-shot ring dN/deta");
269
5bb5d1f6 270 if (!input) return;
271 TList* list = static_cast<TList*>(input->FindObject(inName));
272 if (!list) {
273 AliWarning(Form("No list %s found in %s", inName, input->GetName()));
274 return;
275 }
276
277 TList* out = new TList;
278 out->SetName(outName);
279 out->SetOwner();
280 output->Add(out);
281
282 THStack* dndetaRings = new THStack("all", "dN/d#eta per ring");
283 const char* names[] = { "FMD1I", "FMD2I", "FMD2O", "FMD3I", "FMD3O", 0 };
284 const char** ptr = names;
285
286 while (*ptr) {
287 TList* thisList = new TList;
288 thisList->SetOwner();
289 thisList->SetName(*ptr);
290 out->Add(thisList);
291
292 TH2D* h = static_cast<TH2D*>(list->FindObject(Form("%s_cache", *ptr)));
293 if (!h) {
294 AliWarning(Form("Didn't find %s_cache in %s", *ptr, list->GetName()));
295 ptr++;
296 continue;
297 }
298 TH2D* copy = static_cast<TH2D*>(h->Clone("sum"));
299 copy->SetDirectory(0);
300 thisList->Add(copy);
301
302 TH1D* norm =static_cast<TH1D*>(h->ProjectionX("norm", 0, 0, ""));
303 for (Int_t i = 1; i <= copy->GetNbinsX(); i++) {
304 for (Int_t j = 1; j <= copy->GetNbinsY(); j++) {
305 Double_t c = copy->GetBinContent(i, j);
306 Double_t e = copy->GetBinError(i, j);
307 Double_t a = norm->GetBinContent(i);
308 copy->SetBinContent(i, j, a <= 0 ? 0 : c / a);
309 copy->SetBinError(i, j, a <= 0 ? 0 : e / a);
310 }
311 }
312
313 TH1D* res =static_cast<TH1D*>(copy->ProjectionX("dndeta",1,
314 h->GetNbinsY(),"e"));
315 TH1D* proj =static_cast<TH1D*>(h->ProjectionX("proj",1,h->GetNbinsY(),"e"));
316 res->SetTitle(*ptr);
317 res->Scale(1., "width");
318 copy->Scale(1., "width");
65abd48b 319
320 if(norm->GetMaximum() > 0) {
321 proj->Scale(1. / norm->GetMaximum(), "width");
322 norm->Scale(1. / norm->GetMaximum());
323 }
324
5bb5d1f6 325 res->SetMarkerStyle(style);
326 norm->SetDirectory(0);
327 res->SetDirectory(0);
328 proj->SetDirectory(0);
329 thisList->Add(norm);
330 thisList->Add(res);
331 thisList->Add(proj);
332 dndetaRings->Add(res);
333 ptr++;
334 }
335 out->Add(dndetaRings);
336}
337
1a26066e 338//____________________________________________________________________
339void
340AliForwardMultiplicityBase::Print(Option_t* option) const
341{
7984e5f7 342 //
343 // Print information
344 //
345 // Parameters:
346 // option Not used
347 //
3c5497d0 348
1f480471 349 std::cout << ClassName() << ": " << GetName() << "\n"
9bff843b 350 << " Enable low flux code: " << (fEnableLowFlux ? "yes" : "no")
351 << "\n"
3c5497d0 352 << " Off-line trigger mask: 0x"
353 << std::hex << std::setfill('0')
354 << std::setw (8) << fOfflineTriggerMask
355 << std::dec << std::setfill (' ') << std::endl;
1174780f 356 gROOT->IncreaseDirLevel();
3c5497d0 357 if (fCorrManager) fCorrManager->Print();
9bff843b 358 else
359 std::cout << " Correction manager not set yet" << std::endl;
1174780f 360 GetEventInspector() .Print(option);
1174780f 361 GetSharingFilter() .Print(option);
362 GetDensityCalculator().Print(option);
363 GetCorrections() .Print(option);
364 GetHistCollector() .Print(option);
2b556440 365 GetEventPlaneFinder() .Print(option);
1174780f 366 gROOT->DecreaseDirLevel();
1a26066e 367}
368
1174780f 369
1a26066e 370//
371// EOF
372//