]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGLF/FORWARD/analysis2/AliForwardMCMultiplicityTask.cxx
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / AliForwardMCMultiplicityTask.cxx
CommitLineData
7984e5f7 1//
2// Calculate the multiplicity in the forward regions event-by-event
3//
4// Inputs:
5// - AliESDEvent
6// - Kinematics
7// - Track references
8//
9// Outputs:
10// - AliAODForwardMult
11//
12// Histograms
13//
14// Corrections used
15//
285e7b27 16#include "AliForwardMCMultiplicityTask.h"
17#include "AliTriggerAnalysis.h"
18#include "AliPhysicsSelection.h"
19#include "AliLog.h"
285e7b27 20#include "AliESDEvent.h"
21#include "AliAODHandler.h"
22#include "AliMultiplicity.h"
23#include "AliInputEventHandler.h"
24#include "AliForwardCorrectionManager.h"
25#include "AliAnalysisManager.h"
26#include <TH1.h>
27#include <TDirectory.h>
28#include <TTree.h>
29#include <TROOT.h>
a19faec0 30#define MCAOD_SLOT 4
31#define PRIMARY_SLOT 5
32#ifdef POST_AOD
33# define DEFINE(N,C) DefineOutput(N,C)
34# define POST(N,O) PostData(N,O)
35#else
36# define DEFINE(N,C) do { } while(false)
37# define POST(N,O) do { } while(false)
38#endif
285e7b27 39
40//====================================================================
41AliForwardMCMultiplicityTask::AliForwardMCMultiplicityTask()
42 : AliForwardMultiplicityBase(),
285e7b27 43 fESDFMD(),
285e7b27 44 fMCESDFMD(),
45 fMCHistos(),
46 fMCAODFMD(),
5bb5d1f6 47 fMCRingSums(),
4cbdf467 48 fPrimary(0),
285e7b27 49 fEventInspector(),
0ccdab7b 50 fESDFixer(),
285e7b27 51 fSharingFilter(),
52 fDensityCalculator(),
53 fCorrections(),
54 fHistCollector(),
8449e3e0 55 fEventPlaneFinder()
285e7b27 56{
7984e5f7 57 //
58 // Constructor
59 //
285e7b27 60}
61
62//____________________________________________________________________
63AliForwardMCMultiplicityTask::AliForwardMCMultiplicityTask(const char* name)
64 : AliForwardMultiplicityBase(name),
285e7b27 65 fESDFMD(),
285e7b27 66 fMCESDFMD(),
67 fMCHistos(),
68 fMCAODFMD(kTRUE),
5bb5d1f6 69 fMCRingSums(),
4cbdf467 70 fPrimary(0),
285e7b27 71 fEventInspector("event"),
0ccdab7b 72 fESDFixer("esdFizer"),
285e7b27 73 fSharingFilter("sharing"),
74 fDensityCalculator("density"),
75 fCorrections("corrections"),
76 fHistCollector("collector"),
8449e3e0 77 fEventPlaneFinder("eventplane")
285e7b27 78{
7984e5f7 79 //
80 // Constructor
81 //
82 // Parameters:
83 // name Name of task
84 //
f71c22f5
CHC
85 fPrimary = new TH2D("primary", "MC Primaries", 1,0,1,20,0,TMath::TwoPi());
86 fPrimary->SetXTitle("#eta");
87 fPrimary->SetYTitle("#varphi [radians]");
88 fPrimary->SetZTitle("d^{2}N_{ch}/d#etad#phi");
89 fPrimary->Sumw2();
90 fPrimary->SetStats(0);
91 fPrimary->SetDirectory(0);
a19faec0 92 DEFINE(MCAOD_SLOT,AliAODForwardMult::Class());
93 DEFINE(PRIM_SLOT, TH2D::Class());
285e7b27 94}
95
285e7b27 96//____________________________________________________________________
97void
8449e3e0 98AliForwardMCMultiplicityTask::SetOnlyPrimary(Bool_t use)
285e7b27 99{
8449e3e0 100 fSharingFilter.GetTrackDensity().SetUseOnlyPrimary(use);
101 fCorrections.SetSecondaryForMC(!use);
285e7b27 102}
8449e3e0 103
5bb5d1f6 104//____________________________________________________________________
105void
8449e3e0 106AliForwardMCMultiplicityTask::CreateBranches(AliAODHandler* ah)
5bb5d1f6 107{
8449e3e0 108 //
109 // Create output objects
110 //
111 //
112 AliForwardMultiplicityBase::CreateBranches(ah);
113
114 TObject* mcobj = &fMCAODFMD;
f71c22f5 115 ah->AddBranch("AliAODForwardMult", &mcobj);
8449e3e0 116 ah->AddBranch("TH2D", &fPrimary);
5bb5d1f6 117}
118
a19faec0 119//____________________________________________________________________
120Bool_t
121AliForwardMCMultiplicityTask::Book()
122{
0ccdab7b 123 // We do this to explicitly disable the noise corrector for MC
124 GetESDFixer().SetRecoNoiseFactor(5);
125
a19faec0 126 Bool_t ret = AliForwardMultiplicityBase::Book();
127 POST(MCAOD_SLOT, &fMCAODFMD);
128 POST(PRIM_SLOT, fPrimary);
129 return ret;
130}
8449e3e0 131
285e7b27 132//____________________________________________________________________
8449e3e0 133void
c8b1a7db 134AliForwardMCMultiplicityTask::InitMembers(const TAxis& eta, const TAxis& vertex)
285e7b27 135{
7984e5f7 136 //
137 // Initialise the sub objects and stuff. Called on first event
138 //
139 //
c8b1a7db 140 AliForwardMultiplicityBase::InitMembers(eta, vertex);
1174780f 141
c8b1a7db 142 fMCHistos.Init(eta);
143 fMCAODFMD.Init(eta);
144 fMCRingSums.Init(eta);
145
146 AliForwardUtil::Histos::RebinEta(fPrimary, eta);
147 DMSG(fDebug,0,"Primary histogram rebinned to %d,%f,%f eta axis %d,%f,%f",
148 fPrimary->GetXaxis()->GetNbins(),
149 fPrimary->GetXaxis()->GetXmin(),
150 fPrimary->GetXaxis()->GetXmax(),
151 eta.GetNbins(),
152 eta.GetXmin(),
153 eta.GetXmax());
285e7b27 154
5bb5d1f6 155
156 TList* mcRings = new TList;
157 mcRings->SetName("mcRingSums");
158 mcRings->SetOwner();
159 fList->Add(mcRings);
160
161 mcRings->Add(fMCRingSums.Get(1, 'I'));
162 mcRings->Add(fMCRingSums.Get(2, 'I'));
163 mcRings->Add(fMCRingSums.Get(2, 'O'));
164 mcRings->Add(fMCRingSums.Get(3, 'I'));
165 mcRings->Add(fMCRingSums.Get(3, 'O'));
166 fMCRingSums.Get(1, 'I')->SetMarkerColor(AliForwardUtil::RingColor(1, 'I'));
167 fMCRingSums.Get(2, 'I')->SetMarkerColor(AliForwardUtil::RingColor(2, 'I'));
168 fMCRingSums.Get(2, 'O')->SetMarkerColor(AliForwardUtil::RingColor(2, 'O'));
169 fMCRingSums.Get(3, 'I')->SetMarkerColor(AliForwardUtil::RingColor(3, 'I'));
170 fMCRingSums.Get(3, 'O')->SetMarkerColor(AliForwardUtil::RingColor(3, 'O'));
285e7b27 171}
172
285e7b27 173//____________________________________________________________________
c8b1a7db 174Bool_t
175AliForwardMCMultiplicityTask::PreEvent()
176{
177 if (fFirstEvent)
178 fEventInspector.ReadProductionDetails(MCEvent());
179 // Clear stuff
180 fHistos.Clear();
181 fESDFMD.Clear();
182 fAODFMD.Clear();
183 fAODEP.Clear();
184 fMCHistos.Clear();
185 fMCESDFMD.Clear();
186 fMCAODFMD.Clear();
187 fPrimary->Reset();
188 return true;
189}
190//____________________________________________________________________
191Bool_t
192AliForwardMCMultiplicityTask::Event(AliESDEvent& esd)
285e7b27 193{
7984e5f7 194 //
195 // Process each event
196 //
197 // Parameters:
198 // option Not used
199 //
200
f7cfc454 201 // Read production details
f7cfc454 202
285e7b27 203 // Get the input data
e1f47419 204 AliMCEvent* mcEvent = MCEvent();
c8b1a7db 205 if (!mcEvent) return false;
285e7b27 206
5bb5d1f6 207 Bool_t lowFlux = kFALSE;
208 UInt_t triggers = 0;
209 UShort_t ivz = 0;
5ca83fee 210 TVector3 ip(1024, 1024, 0);
21d778b1 211 Double_t cent = -1;
5bb5d1f6 212 UShort_t nClusters = 0;
c8b1a7db 213 UInt_t found = fEventInspector.Process(&esd, triggers, lowFlux,
5ca83fee 214 ivz, ip, cent, nClusters);
e1f47419 215 UShort_t ivzMC = 0;
216 Double_t vzMC = 0;
217 Double_t phiR = 0;
218 Double_t b = 0;
241cca4d 219 Double_t cMC = 0;
e308a636 220 Int_t npart = 0;
221 Int_t nbin = 0;
e1f47419 222 // UInt_t foundMC =
241cca4d 223 fEventInspector.ProcessMC(mcEvent, triggers, ivzMC, vzMC, b, cMC,
e308a636 224 npart, nbin, phiR);
73b32206 225 fEventInspector.CompareResults(ip.Z(), vzMC, cent, cMC, b, npart, nbin);
1dbfc345 226
e333578d 227 //Store all events
148c39de 228 MarkEventForStore();
e333578d 229
230 Bool_t isAccepted = true;
231 if (found & AliFMDEventInspector::kNoEvent) isAccepted = false; // return;
232 if (found & AliFMDEventInspector::kNoTriggers) isAccepted = false; // return;
148c39de 233 //MarkEventForStore();
b30dee70 234 // Always set the B trigger - each MC event _is_ a collision
235 triggers |= AliAODForwardMult::kB;
285e7b27 236 // Set trigger bits, and mark this event for storage
237 fAODFMD.SetTriggerBits(triggers);
e308a636 238 fAODFMD.SetSNN(fEventInspector.GetEnergy());
239 fAODFMD.SetSystem(fEventInspector.GetCollisionSystem());
e58000b7 240 fAODFMD.SetCentrality(cent);
5bb5d1f6 241 fAODFMD.SetNClusters(nClusters);
e308a636 242
243 fMCAODFMD.SetTriggerBits(triggers);
244 fMCAODFMD.SetSNN(fEventInspector.GetEnergy());
245 fMCAODFMD.SetSystem(fEventInspector.GetCollisionSystem());
246 fMCAODFMD.SetCentrality(cent);
5bb5d1f6 247 fMCAODFMD.SetNClusters(nClusters);
e58000b7 248
e1f47419 249 // Disable this check on SPD - will bias data
250 // if (found & AliFMDEventInspector::kNoSPD) isAccepted = false; // return;
e333578d 251 if (found & AliFMDEventInspector::kNoFMD) isAccepted = false; // return;
252 if (found & AliFMDEventInspector::kNoVertex) isAccepted = false; // return;
253
254 if (isAccepted) {
5ca83fee 255 fAODFMD.SetIpZ(ip.Z());
256 fMCAODFMD.SetIpZ(ip.Z());
e333578d 257 }
258 if (found & AliFMDEventInspector::kBadVertex) isAccepted = false; // return;
285e7b27 259
260 // We we do not want to use low flux specific code, we disable it here.
261 if (!fEnableLowFlux) lowFlux = false;
148c39de 262
263
285e7b27 264
265 // Get FMD data
c8b1a7db 266 AliESDFMD* esdFMD = esd.GetFMDData();
0ccdab7b 267
268 // Fix up the the ESD
269 GetESDFixer().Fix(*esdFMD, ip.Z());
e1f47419 270
285e7b27 271 // Apply the sharing filter (or hit merging or clustering if you like)
c8b1a7db 272 if (isAccepted && !fSharingFilter.Filter(*esdFMD, lowFlux, fESDFMD,ip.Z())){
285e7b27 273 AliWarning("Sharing filter failed!");
c8b1a7db 274 return false;
285e7b27 275 }
c8b1a7db 276 if (!fSharingFilter.FilterMC(*esdFMD, *mcEvent, ip.Z(),fMCESDFMD,fPrimary)){
285e7b27 277 AliWarning("MC Sharing filter failed!");
c8b1a7db 278 return false;
285e7b27 279 }
dd556bcd 280
281 // Store some MC parameters in corners of histogram :-)
282 fPrimary->SetBinContent(0, 0, vzMC);
283 fPrimary->SetBinContent(fPrimary->GetNbinsX()+1,0, phiR);
284 fPrimary->SetBinContent(fPrimary->GetNbinsX()+1,fPrimary->GetNbinsY(),cMC);
285
286
c8b1a7db 287 if (!isAccepted)
288 // Exit on MC event w/o trigger, vertex, data - since there's no more
289 // to be done for MC
290 return false;
1dbfc345 291
148c39de 292 //MarkEventForStore();
285e7b27 293 fSharingFilter.CompareResults(fESDFMD, fMCESDFMD);
294
285e7b27 295 // Calculate the inclusive charged particle density
5934a3e3 296 if (!fDensityCalculator.Calculate(fESDFMD, fHistos, lowFlux, cent, ip)) {
285e7b27 297 AliWarning("Density calculator failed!");
c8b1a7db 298 return false;
285e7b27 299 }
300 if (!fDensityCalculator.CalculateMC(fMCESDFMD, fMCHistos)) {
301 AliWarning("MC Density calculator failed!");
c8b1a7db 302 return false;
285e7b27 303 }
304 fDensityCalculator.CompareResults(fHistos, fMCHistos);
305
2b556440 306 if (fEventInspector.GetCollisionSystem() == AliFMDEventInspector::kPbPb) {
c8b1a7db 307 if (!fEventPlaneFinder.FindEventplane(&esd, fAODEP,
308 &(fAODFMD.GetHistogram()), &fHistos))
2b556440 309 AliWarning("Eventplane finder failed!");
310 }
311
285e7b27 312 // Do the secondary and other corrections.
313 if (!fCorrections.Correct(fHistos, ivz)) {
314 AliWarning("Corrections failed");
c8b1a7db 315 return false;
285e7b27 316 }
317 if (!fCorrections.CorrectMC(fMCHistos, ivz)) {
318 AliWarning("MC Corrections failed");
c8b1a7db 319 return false;
285e7b27 320 }
321 fCorrections.CompareResults(fHistos, fMCHistos);
64d35c05 322
323 Bool_t add = fAODFMD.IsTriggerBits(AliAODForwardMult::kInel);
324 if (!fHistCollector.Collect(fHistos,
325 fRingSums,
326 ivz,
327 fAODFMD.GetHistogram(),
328 fAODFMD.GetCentrality(),
329 false,
330 add)) {
285e7b27 331 AliWarning("Histogram collector failed");
c8b1a7db 332 return false;
285e7b27 333 }
64d35c05 334 if (!fHistCollector.Collect(fMCHistos,
335 fMCRingSums,
336 ivz,
337 fMCAODFMD.GetHistogram(),
338 -1,
339 true,
340 add)) {
285e7b27 341 AliWarning("MC Histogram collector failed");
c8b1a7db 342 return false;
285e7b27 343 }
c8b1a7db 344#if 0
29132080 345 // Copy underflow bins to overflow bins - always full phi coverage
bfab35d9 346 TH2& hMC = fMCAODFMD.GetHistogram();
29132080 347 Int_t nEta = hMC.GetNbinsX();
348 Int_t nY = hMC.GetNbinsY();
349 for (Int_t iEta = 1; iEta <= nEta; iEta++) {
350 hMC.SetBinContent(iEta, nY+1, hMC.GetBinContent(iEta, 0));
351 }
c8b1a7db 352#endif
285e7b27 353
64d35c05 354 if (add)
285e7b27 355 fHData->Add(&(fAODFMD.GetHistogram()));
356
c8b1a7db 357 return true;
285e7b27 358}
359
a19faec0 360//____________________________________________________________________
361Bool_t
362AliForwardMCMultiplicityTask::PostEvent()
363{
364 Bool_t ret = AliForwardMultiplicityBase::PostEvent();
365 POST(MCAOD_SLOT, &fMCAODFMD);
366 POST(PRIMARY_SLOT, fPrimary);
367 return ret;
368}
369
285e7b27 370//____________________________________________________________________
371void
8449e3e0 372AliForwardMCMultiplicityTask::EstimatedNdeta(const TList* input,
373 TList* output) const
285e7b27 374{
8449e3e0 375 AliForwardMultiplicityBase::EstimatedNdeta(input, output);
376 MakeRingdNdeta(input, "mcRingSums", output, "mcRingResults", 24);
285e7b27 377}
378
285e7b27 379
8449e3e0 380
285e7b27 381//
382// EOF
383//