2 // Calculate the corrections in the forward regions
14 #include "AliForwardMCCorrectionsTask.h"
15 #include "AliTriggerAnalysis.h"
16 #include "AliPhysicsSelection.h"
18 #include "AliHeader.h"
19 #include "AliGenEventHeader.h"
20 #include "AliESDEvent.h"
21 #include "AliAODHandler.h"
22 #include "AliMultiplicity.h"
23 #include "AliInputEventHandler.h"
25 #include "AliMCEvent.h"
26 #include "AliAODForwardMult.h"
27 #include "AliFMDStripIndex.h"
28 #include "AliFMDCorrSecondaryMap.h"
31 #include <TDirectory.h>
37 //====================================================================
39 const char* GetEventName(Bool_t tr, Bool_t vtx)
41 return Form("nEvents%s%s", (tr ? "Tr" : ""), (vtx ? "Vtx" : ""));
44 const char* GetHitsName(UShort_t d, Char_t r)
46 return Form("hitsFMD%d%c", d, r);
48 const char* GetStripsName(UShort_t d, Char_t r)
50 return Form("stripsFMD%d%c", d, r);
52 const char* GetPrimaryName(Char_t r, Bool_t trVtx)
54 return Form("primaries%s%s",
55 ((r == 'I' || r == 'i') ? "Inner" : "Outer"),
56 (trVtx ? "TrVtx" : "All"));
61 //====================================================================
62 AliForwardMCCorrectionsTask::AliForwardMCCorrectionsTask()
63 : AliAnalysisTaskSE(),
84 //____________________________________________________________________
85 AliForwardMCCorrectionsTask::AliForwardMCCorrectionsTask(const char* name)
86 : AliAnalysisTaskSE(name),
87 fInspector("eventInspector"),
88 fTrackDensity("trackDensity"),
105 DefineOutput(1, TList::Class());
106 DefineOutput(2, TList::Class());
109 //____________________________________________________________________
110 AliForwardMCCorrectionsTask::AliForwardMCCorrectionsTask(const AliForwardMCCorrectionsTask& o)
111 : AliAnalysisTaskSE(o),
112 fInspector(o.fInspector),
116 fFirstEvent(o.fFirstEvent),
117 fHEvents(o.fHEvents),
118 fHEventsTr(o.fHEventsTr),
119 fHEventsTrVtx(o.fHEventsTrVtx),
128 // o Object to copy from
132 //____________________________________________________________________
133 AliForwardMCCorrectionsTask&
134 AliForwardMCCorrectionsTask::operator=(const AliForwardMCCorrectionsTask& o)
137 // Assignment operator
140 // o Object to assign from
143 // Reference to this object
145 if (&o == this) return *this;
146 fInspector = o.fInspector;
147 fTrackDensity = o.fTrackDensity;
149 fVtxBins = o.fVtxBins;
150 fFirstEvent = o.fFirstEvent;
151 fHEvents = o.fHEvents;
152 fHEventsTr = o.fHEventsTr;
153 fHEventsTrVtx = o.fHEventsTrVtx;
154 SetVertexAxis(o.fVtxAxis);
155 SetEtaAxis(o.fEtaAxis);
160 //____________________________________________________________________
162 AliForwardMCCorrectionsTask::Init()
165 // Initialize the task
170 //____________________________________________________________________
172 AliForwardMCCorrectionsTask::SetVertexAxis(Int_t nBin, Double_t min,
176 // Set the vertex axis to use
179 // nBins Number of bins
180 // vzMin Least @f$z@f$ coordinate of interation point
181 // vzMax Largest @f$z@f$ coordinate of interation point
190 AliWarning(Form("Minimum vertex %f < -10, make sure you want this",min));
192 AliWarning(Form("Minimum vertex %f > +10, make sure you want this",max));
194 fVtxAxis.Set(nBin, min, max);
196 //____________________________________________________________________
198 AliForwardMCCorrectionsTask::SetVertexAxis(const TAxis& axis)
201 // Set the vertex axis to use
206 SetVertexAxis(axis.GetNbins(),axis.GetXmin(),axis.GetXmax());
209 //____________________________________________________________________
211 AliForwardMCCorrectionsTask::SetEtaAxis(Int_t nBin, Double_t min, Double_t max)
214 // Set the eta axis to use
217 // nBins Number of bins
218 // vzMin Least @f$\eta@f$
219 // vzMax Largest @f$\eta@f$
227 AliWarning(Form("Minimum eta %f < -4, make sure you want this",min));
229 AliWarning(Form("Minimum eta %f > +6, make sure you want this",max));
230 fEtaAxis.Set(nBin, min, max);
232 //____________________________________________________________________
234 AliForwardMCCorrectionsTask::SetEtaAxis(const TAxis& axis)
237 // Set the eta axis to use
242 SetEtaAxis(axis.GetNbins(),axis.GetXmin(),axis.GetXmax());
245 //____________________________________________________________________
247 AliForwardMCCorrectionsTask::DefineBins(TList* l)
249 if (!fVtxBins) fVtxBins = new TObjArray(fVtxAxis.GetNbins(), 1);
250 if (fVtxBins->GetEntries() > 0) return;
252 fVtxBins->SetOwner();
253 for (Int_t i = 1; i <= fVtxAxis.GetNbins(); i++) {
254 Double_t low = fVtxAxis.GetBinLowEdge(i);
255 Double_t high = fVtxAxis.GetBinUpEdge(i);
256 VtxBin* bin = new VtxBin(low, high, fEtaAxis);
257 fVtxBins->AddAt(bin, i);
258 bin->DefineOutput(l);
262 //____________________________________________________________________
264 AliForwardMCCorrectionsTask::UserCreateOutputObjects()
267 // Create output objects
272 fList->SetName(Form("%sSums", GetName()));
276 fHEvents = new TH1I(GetEventName(false,false),
277 "Number of all events",
281 fHEvents->SetXTitle("v_{z} [cm]");
282 fHEvents->SetYTitle("# of events");
283 fHEvents->SetFillColor(kBlue+1);
284 fHEvents->SetFillStyle(3001);
285 fHEvents->SetDirectory(0);
286 fList->Add(fHEvents);
288 fHEventsTr = new TH1I(GetEventName(true, false),
289 "Number of triggered events",
293 fHEventsTr->SetXTitle("v_{z} [cm]");
294 fHEventsTr->SetYTitle("# of events");
295 fHEventsTr->SetFillColor(kRed+1);
296 fHEventsTr->SetFillStyle(3001);
297 fHEventsTr->SetDirectory(0);
298 fList->Add(fHEventsTr);
300 fHEventsTrVtx = new TH1I(GetEventName(true,true),
301 "Number of events w/trigger and vertex",
305 fHEventsTrVtx->SetXTitle("v_{z} [cm]");
306 fHEventsTrVtx->SetYTitle("# of events");
307 fHEventsTrVtx->SetFillColor(kBlue+1);
308 fHEventsTrVtx->SetFillStyle(3001);
309 fHEventsTrVtx->SetDirectory(0);
310 fList->Add(fHEventsTrVtx);
312 // Copy axis objects to output
313 TH1* vtxAxis = new TH1D("vtxAxis", "Vertex axis",
317 TH1* etaAxis = new TH1D("etaAxis", "Eta axis",
324 AliInfo(Form("Initialising sub-routines: %p, %p",
325 &fInspector, &fTrackDensity));
326 fInspector.DefineOutput(fList);
327 fInspector.Init(fVtxAxis);
328 fTrackDensity.DefineOutput(fList);
332 //____________________________________________________________________
334 AliForwardMCCorrectionsTask::UserExec(Option_t*)
337 // Process each event
343 // Get the input data - MC event
344 AliMCEvent* mcEvent = MCEvent();
346 AliWarning("No MC event found");
350 // Get the input data - ESD event
351 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
353 AliWarning("No ESD event found for input event");
357 //--- Read run information -----------------------------------------
358 if (fFirstEvent && esd->GetESDRun()) {
359 fInspector.ReadRunDetails(esd);
361 AliInfo(Form("Initializing with parameters from the ESD:\n"
362 " AliESDEvent::GetBeamEnergy() ->%f\n"
363 " AliESDEvent::GetBeamType() ->%s\n"
364 " AliESDEvent::GetCurrentL3() ->%f\n"
365 " AliESDEvent::GetMagneticField()->%f\n"
366 " AliESDEvent::GetRunNumber() ->%d\n",
367 esd->GetBeamEnergy(),
370 esd->GetMagneticField(),
371 esd->GetRunNumber()));
378 UInt_t triggers; // Trigger bits
379 Bool_t lowFlux; // Low flux flag
380 UShort_t iVz; // Vertex bin from ESD
381 Double_t vZ; // Z coordinate from ESD
382 Double_t cent; // Centrality
383 UShort_t iVzMc; // Vertex bin from MC
384 Double_t vZMc; // Z coordinate of IP vertex from MC
385 Double_t b; // Impact parameter
386 Int_t nPart; // Number of participants
387 Int_t nBin; // Number of binary collisions
388 Double_t phiR; // Reaction plane from MC
389 UShort_t nClusters;// Number of SPD clusters
391 UInt_t retESD = fInspector.Process(esd, triggers, lowFlux, iVz, vZ,
393 fInspector.ProcessMC(mcEvent, triggers, iVzMc, vZMc,
394 b, nPart, nBin, phiR);
396 Bool_t isInel = triggers & AliAODForwardMult::kInel;
397 Bool_t hasVtx = retESD == AliFMDMCEventInspector::kOk;
399 // Fill the event count histograms
400 if (isInel) fHEventsTr->Fill(vZMc);
401 if (isInel && hasVtx) fHEventsTrVtx->Fill(vZMc);
402 fHEvents->Fill(vZMc);
404 // Now find our vertex bin object
406 if (iVzMc > 0 && iVzMc <= fVtxAxis.GetNbins())
407 bin = static_cast<VtxBin*>(fVtxBins->At(iVzMc));
409 // AliError(Form("No vertex bin object @ %d (%f)", iVzMc, vZMc));
413 // Clear our ESD object
417 AliESDFMD* esdFMD = esd->GetFMDData();
419 // Now process our input data and store in own ESD object
420 fTrackDensity.Calculate(*esdFMD, *mcEvent, vZMc, fESDFMD, bin->fPrimary);
421 bin->fCounts->Fill(0.5);
423 // And then bin the data in our vtxbin
424 for (UShort_t d=1; d<=3; d++) {
425 UShort_t nr = (d == 1 ? 1 : 2);
426 for (UShort_t q=0; q<nr; q++) {
427 Char_t r = (q == 0 ? 'I' : 'O');
428 UShort_t ns= (q == 0 ? 20 : 40);
429 UShort_t nt= (q == 0 ? 512 : 256);
430 TH2D* h = bin->fHists.Get(d,r);
432 for (UShort_t s=0; s<ns; s++) {
433 for (UShort_t t=0; t<nt; t++) {
434 Float_t mult = fESDFMD.Multiplicity(d,r,s,t);
436 if (mult == 0 || mult > 20) continue;
438 Float_t phi = fESDFMD.Phi(d,r,s,t) / 180 * TMath::Pi();
439 Float_t eta = fESDFMD.Eta(d,r,s,t);
440 h->Fill(eta,phi,mult);
448 //____________________________________________________________________
450 AliForwardMCCorrectionsTask::Terminate(Option_t*)
459 fList = dynamic_cast<TList*>(GetOutputData(1));
461 AliError("No output list defined");
468 TList* output = new TList;
470 output->SetName(Form("%sResults", GetName()));
472 // --- Fill correction object --------------------------------------
473 AliFMDCorrSecondaryMap* corr = new AliFMDCorrSecondaryMap;
474 corr->SetVertexAxis(fVtxAxis);
475 corr->SetEtaAxis(fEtaAxis);
477 TIter next(fVtxBins);
480 while ((bin = static_cast<VtxBin*>(next())))
481 bin->Finish(fList, output, iVz++, corr);
488 //____________________________________________________________________
490 AliForwardMCCorrectionsTask::Print(Option_t* option) const
492 std::cout << ClassName() << "\n"
493 << " Vertex bins: " << fVtxAxis.GetNbins() << '\n'
494 << " Vertex range: [" << fVtxAxis.GetXmin()
495 << "," << fVtxAxis.GetXmax() << "]\n"
496 << " Eta bins: " << fEtaAxis.GetNbins() << '\n'
497 << " Eta range: [" << fEtaAxis.GetXmin()
498 << "," << fEtaAxis.GetXmax() << "]"
500 gROOT->IncreaseDirLevel();
501 fInspector.Print(option);
502 fTrackDensity.Print(option);
503 gROOT->DecreaseDirLevel();
506 //====================================================================
508 AliForwardMCCorrectionsTask::VtxBin::BinName(Double_t low,
512 buf = Form("vtx%+05.1f_%+05.1f", low, high);
513 buf.ReplaceAll("+", "p");
514 buf.ReplaceAll("-", "m");
515 buf.ReplaceAll(".", "d");
520 //____________________________________________________________________
521 AliForwardMCCorrectionsTask::VtxBin::VtxBin()
527 //____________________________________________________________________
528 AliForwardMCCorrectionsTask::VtxBin::VtxBin(Double_t low,
531 : TNamed(BinName(low, high),
532 Form("%+5.1fcm<v_{z}<%+5.1fcm", low, high)),
539 fPrimary = new TH2D("primary", "Primaries",
540 axis.GetNbins(), axis.GetXmin(), axis.GetXmax(),
541 40, 0, 2*TMath::Pi());
542 fPrimary->SetXTitle("#eta");
543 fPrimary->SetYTitle("#varphi [radians]");
545 fPrimary->SetDirectory(0);
547 fCounts = new TH1D("counts", "Counts", 1, 0, 1);
548 fCounts->SetXTitle("Events");
549 fCounts->SetYTitle("# of Events");
550 fCounts->SetDirectory(0);
553 //____________________________________________________________________
554 AliForwardMCCorrectionsTask::VtxBin::VtxBin(const VtxBin& o)
561 fPrimary = static_cast<TH2D*>(o.fPrimary->Clone());
562 fPrimary->SetDirectory(0);
565 fCounts = static_cast<TH1D*>(o.fCounts->Clone());
566 fCounts->SetDirectory(0);
570 //____________________________________________________________________
571 AliForwardMCCorrectionsTask::VtxBin&
572 AliForwardMCCorrectionsTask::VtxBin::operator=(const VtxBin& o)
574 if (&o == this) return *this;
575 TNamed::operator=(o);
580 fPrimary = static_cast<TH2D*>(o.fPrimary->Clone());
581 fPrimary->SetDirectory(0);
584 fCounts = static_cast<TH1D*>(o.fCounts->Clone());
585 fCounts->SetDirectory(0);
590 //____________________________________________________________________
592 AliForwardMCCorrectionsTask::VtxBin::DefineOutput(TList* l)
594 TList* d = new TList;
595 d->SetName(GetName());
599 d->Add(fHists.fFMD1i);
600 d->Add(fHists.fFMD2i);
601 d->Add(fHists.fFMD2o);
602 d->Add(fHists.fFMD3i);
603 d->Add(fHists.fFMD3o);
609 //____________________________________________________________________
611 AliForwardMCCorrectionsTask::VtxBin::MakeBg(const TH2D* hits,
612 const TH2D* primary) const
614 TH2D* h = static_cast<TH2D*>(hits->Clone());
616 TString n(h->GetName());
617 n.ReplaceAll("_cache", "");
624 //____________________________________________________________________
626 AliForwardMCCorrectionsTask::VtxBin::Finish(const TList* input,
629 AliFMDCorrSecondaryMap* map)
631 TList* out = new TList;
632 out->SetName(GetName());
636 TList* l = static_cast<TList*>(input->FindObject(GetName()));
638 AliError(Form("List %s not found in %s", GetName(), input->GetName()));
642 TH2D* fmd1i = static_cast<TH2D*>(l->FindObject("FMD1I_cache"));
643 TH2D* fmd2i = static_cast<TH2D*>(l->FindObject("FMD2I_cache"));
644 TH2D* fmd2o = static_cast<TH2D*>(l->FindObject("FMD2O_cache"));
645 TH2D* fmd3i = static_cast<TH2D*>(l->FindObject("FMD3I_cache"));
646 TH2D* fmd3o = static_cast<TH2D*>(l->FindObject("FMD3O_cache"));
647 TH2D* primO = static_cast<TH2D*>(l->FindObject("primary"));
648 if (!fmd1i || !fmd2i || !fmd2o || !fmd3i || !fmd3o || !primO) {
649 AliError(Form("Missing histogram(s): %p,%p,%p,%p,%p,%p",
650 fmd1i, fmd2i, fmd2o, fmd3i, fmd3o, primO));
654 // Half coverage in phi for inners
655 TH2D* primI = static_cast<TH2D*>(primO->Clone());
656 primI->SetDirectory(0);
659 TH2D* bg1i = MakeBg(fmd1i, primI);
660 TH2D* bg2i = MakeBg(fmd2i, primI);
661 TH2D* bg2o = MakeBg(fmd2o, primO);
662 TH2D* bg3i = MakeBg(fmd3i, primI);
663 TH2D* bg3o = MakeBg(fmd3o, primO);
664 map->SetCorrection(1, 'I', iVz, bg1i);
665 map->SetCorrection(2, 'I', iVz, bg2i);
666 map->SetCorrection(2, 'O', iVz, bg2o);
667 map->SetCorrection(3, 'I', iVz, bg3i);
668 map->SetCorrection(3, 'O', iVz, bg3o);