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());
108 "ESD:AliESDRun.,AliESDHeader.,AliMultiplicity.,"
109 "AliESDFMD.,SPDVertex.,PrimaryVertex.";
112 //____________________________________________________________________
113 AliForwardMCCorrectionsTask::AliForwardMCCorrectionsTask(const AliForwardMCCorrectionsTask& o)
114 : AliAnalysisTaskSE(o),
115 fInspector(o.fInspector),
119 fFirstEvent(o.fFirstEvent),
120 fHEvents(o.fHEvents),
121 fHEventsTr(o.fHEventsTr),
122 fHEventsTrVtx(o.fHEventsTrVtx),
131 // o Object to copy from
135 //____________________________________________________________________
136 AliForwardMCCorrectionsTask&
137 AliForwardMCCorrectionsTask::operator=(const AliForwardMCCorrectionsTask& o)
140 // Assignment operator
143 // o Object to assign from
146 // Reference to this object
148 if (&o == this) return *this;
149 fInspector = o.fInspector;
150 fTrackDensity = o.fTrackDensity;
152 fVtxBins = o.fVtxBins;
153 fFirstEvent = o.fFirstEvent;
154 fHEvents = o.fHEvents;
155 fHEventsTr = o.fHEventsTr;
156 fHEventsTrVtx = o.fHEventsTrVtx;
157 SetVertexAxis(o.fVtxAxis);
158 SetEtaAxis(o.fEtaAxis);
163 //____________________________________________________________________
165 AliForwardMCCorrectionsTask::Init()
168 // Initialize the task
173 //____________________________________________________________________
175 AliForwardMCCorrectionsTask::SetVertexAxis(Int_t nBin, Double_t min,
179 // Set the vertex axis to use
182 // nBins Number of bins
183 // vzMin Least @f$z@f$ coordinate of interation point
184 // vzMax Largest @f$z@f$ coordinate of interation point
193 AliWarning(Form("Minimum vertex %f < -10, make sure you want this",min));
195 AliWarning(Form("Minimum vertex %f > +10, make sure you want this",max));
197 fVtxAxis.Set(nBin, min, max);
199 //____________________________________________________________________
201 AliForwardMCCorrectionsTask::SetVertexAxis(const TAxis& axis)
204 // Set the vertex axis to use
209 SetVertexAxis(axis.GetNbins(),axis.GetXmin(),axis.GetXmax());
212 //____________________________________________________________________
214 AliForwardMCCorrectionsTask::SetEtaAxis(Int_t nBin, Double_t min, Double_t max)
217 // Set the eta axis to use
220 // nBins Number of bins
221 // vzMin Least @f$\eta@f$
222 // vzMax Largest @f$\eta@f$
230 AliWarning(Form("Minimum eta %f < -4, make sure you want this",min));
232 AliWarning(Form("Minimum eta %f > +6, make sure you want this",max));
233 fEtaAxis.Set(nBin, min, max);
235 //____________________________________________________________________
237 AliForwardMCCorrectionsTask::SetEtaAxis(const TAxis& axis)
240 // Set the eta axis to use
245 SetEtaAxis(axis.GetNbins(),axis.GetXmin(),axis.GetXmax());
248 //____________________________________________________________________
250 AliForwardMCCorrectionsTask::DefineBins(TList* l)
252 if (!fVtxBins) fVtxBins = new TObjArray(fVtxAxis.GetNbins(), 1);
253 if (fVtxBins->GetEntries() > 0) return;
255 fVtxBins->SetOwner();
256 for (Int_t i = 1; i <= fVtxAxis.GetNbins(); i++) {
257 Double_t low = fVtxAxis.GetBinLowEdge(i);
258 Double_t high = fVtxAxis.GetBinUpEdge(i);
259 VtxBin* bin = new VtxBin(low, high, fEtaAxis);
260 fVtxBins->AddAt(bin, i);
261 bin->CreateOutputObjects(l);
265 //____________________________________________________________________
267 AliForwardMCCorrectionsTask::UserCreateOutputObjects()
270 // Create output objects
275 fList->SetName(Form("%sSums", GetName()));
279 fHEvents = new TH1I(GetEventName(false,false),
280 "Number of all events",
284 fHEvents->SetXTitle("v_{z} [cm]");
285 fHEvents->SetYTitle("# of events");
286 fHEvents->SetFillColor(kBlue+1);
287 fHEvents->SetFillStyle(3001);
288 fHEvents->SetDirectory(0);
289 fList->Add(fHEvents);
291 fHEventsTr = new TH1I(GetEventName(true, false),
292 "Number of triggered events",
296 fHEventsTr->SetXTitle("v_{z} [cm]");
297 fHEventsTr->SetYTitle("# of events");
298 fHEventsTr->SetFillColor(kRed+1);
299 fHEventsTr->SetFillStyle(3001);
300 fHEventsTr->SetDirectory(0);
301 fList->Add(fHEventsTr);
303 fHEventsTrVtx = new TH1I(GetEventName(true,true),
304 "Number of events w/trigger and vertex",
308 fHEventsTrVtx->SetXTitle("v_{z} [cm]");
309 fHEventsTrVtx->SetYTitle("# of events");
310 fHEventsTrVtx->SetFillColor(kBlue+1);
311 fHEventsTrVtx->SetFillStyle(3001);
312 fHEventsTrVtx->SetDirectory(0);
313 fList->Add(fHEventsTrVtx);
315 // Copy axis objects to output
316 TH1* vtxAxis = new TH1D("vtxAxis", "Vertex axis",
320 TH1* etaAxis = new TH1D("etaAxis", "Eta axis",
327 AliInfo(Form("Initialising sub-routines: %p, %p",
328 &fInspector, &fTrackDensity));
329 fInspector.CreateOutputObjects(fList);
330 fTrackDensity.CreateOutputObjects(fList);
334 //____________________________________________________________________
336 AliForwardMCCorrectionsTask::UserExec(Option_t*)
339 // Process each event
345 // Get the input data - MC event
346 AliMCEvent* mcEvent = MCEvent();
348 AliWarning("No MC event found");
352 // Get the input data - ESD event
353 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
355 AliWarning("No ESD event found for input event");
359 // --- Read in the data --------------------------------------------
362 //--- Read run information -----------------------------------------
363 if (fFirstEvent && esd->GetESDRun()) {
364 fInspector.ReadRunDetails(esd);
366 AliInfo(Form("Initializing with parameters from the ESD:\n"
367 " AliESDEvent::GetBeamEnergy() ->%f\n"
368 " AliESDEvent::GetBeamType() ->%s\n"
369 " AliESDEvent::GetCurrentL3() ->%f\n"
370 " AliESDEvent::GetMagneticField()->%f\n"
371 " AliESDEvent::GetRunNumber() ->%d\n",
372 esd->GetBeamEnergy(),
375 esd->GetMagneticField(),
376 esd->GetRunNumber()));
378 fInspector.SetupForData(fVtxAxis);
385 UInt_t triggers = 0; // Trigger bits
386 Bool_t lowFlux = true; // Low flux flag
387 UShort_t iVz = 0; // Vertex bin from ESD
388 TVector3 ip(1024,1024,1000);
389 Double_t cent = -1; // Centrality
390 UShort_t iVzMc = 0; // Vertex bin from MC
391 Double_t vZMc = 1000; // Z coordinate of IP vertex from MC
392 Double_t b = -1; // Impact parameter
393 Double_t cMC = -1; // Centrality estimate from b
394 Int_t nPart = -1; // Number of participants
395 Int_t nBin = -1; // Number of binary collisions
396 Double_t phiR = 100; // Reaction plane from MC
397 UShort_t nClusters = 0; // Number of SPD clusters
399 UInt_t retESD = fInspector.Process(esd, triggers, lowFlux, iVz, ip,
401 fInspector.ProcessMC(mcEvent, triggers, iVzMc, vZMc,
402 b, cMC, nPart, nBin, phiR);
404 Bool_t isInel = triggers & AliAODForwardMult::kInel;
405 Bool_t hasVtx = retESD == AliFMDMCEventInspector::kOk;
407 // Fill the event count histograms
408 if (isInel) fHEventsTr->Fill(vZMc);
409 if (isInel && hasVtx) fHEventsTrVtx->Fill(vZMc);
410 fHEvents->Fill(vZMc);
412 // Now find our vertex bin object
414 if (iVzMc > 0 && iVzMc <= fVtxAxis.GetNbins())
415 bin = static_cast<VtxBin*>(fVtxBins->At(iVzMc));
417 // AliError(Form("No vertex bin object @ %d (%f)", iVzMc, vZMc));
421 // Clear our ESD object
425 AliESDFMD* esdFMD = esd->GetFMDData();
427 // Now process our input data and store in own ESD object
428 fTrackDensity.Calculate(*esdFMD, *mcEvent, vZMc, fESDFMD, bin->fPrimary);
429 bin->fCounts->Fill(0.5);
431 // And then bin the data in our vtxbin
432 for (UShort_t d=1; d<=3; d++) {
433 UShort_t nr = (d == 1 ? 1 : 2);
434 for (UShort_t q=0; q<nr; q++) {
435 Char_t r = (q == 0 ? 'I' : 'O');
436 UShort_t ns= (q == 0 ? 20 : 40);
437 UShort_t nt= (q == 0 ? 512 : 256);
438 TH2D* h = bin->fHists.Get(d,r);
440 for (UShort_t s=0; s<ns; s++) {
441 for (UShort_t t=0; t<nt; t++) {
442 Float_t mult = fESDFMD.Multiplicity(d,r,s,t);
444 if (mult == 0 || mult > 20) continue;
446 Float_t phi = fESDFMD.Phi(d,r,s,t) / 180 * TMath::Pi();
447 Float_t eta = fESDFMD.Eta(d,r,s,t);
448 h->Fill(eta,phi,mult);
456 //____________________________________________________________________
458 AliForwardMCCorrectionsTask::Terminate(Option_t*)
467 fList = dynamic_cast<TList*>(GetOutputData(1));
469 AliError("No output list defined");
476 TList* output = new TList;
478 output->SetName(Form("%sResults", GetName()));
480 // --- Fill correction object --------------------------------------
481 AliFMDCorrSecondaryMap* corr = new AliFMDCorrSecondaryMap;
482 corr->SetVertexAxis(fVtxAxis);
483 corr->SetEtaAxis(fEtaAxis);
485 TIter next(fVtxBins);
488 while ((bin = static_cast<VtxBin*>(next())))
489 bin->Terminate(fList, output, iVz++, corr);
496 //____________________________________________________________________
498 AliForwardMCCorrectionsTask::Print(Option_t* option) const
500 std::cout << ClassName() << "\n"
501 << " Vertex bins: " << fVtxAxis.GetNbins() << '\n'
502 << " Vertex range: [" << fVtxAxis.GetXmin()
503 << "," << fVtxAxis.GetXmax() << "]\n"
504 << " Eta bins: " << fEtaAxis.GetNbins() << '\n'
505 << " Eta range: [" << fEtaAxis.GetXmin()
506 << "," << fEtaAxis.GetXmax() << "]"
508 gROOT->IncreaseDirLevel();
509 fInspector.Print(option);
510 fTrackDensity.Print(option);
511 gROOT->DecreaseDirLevel();
514 //====================================================================
516 AliForwardMCCorrectionsTask::VtxBin::BinName(Double_t low,
520 buf = Form("vtx%+05.1f_%+05.1f", low, high);
521 buf.ReplaceAll("+", "p");
522 buf.ReplaceAll("-", "m");
523 buf.ReplaceAll(".", "d");
528 //____________________________________________________________________
529 AliForwardMCCorrectionsTask::VtxBin::VtxBin()
535 //____________________________________________________________________
536 AliForwardMCCorrectionsTask::VtxBin::VtxBin(Double_t low,
539 : TNamed(BinName(low, high),
540 Form("%+5.1fcm<v_{z}<%+5.1fcm", low, high)),
547 fPrimary = new TH2D("primary", "Primaries",
548 axis.GetNbins(), axis.GetXmin(), axis.GetXmax(),
549 40, 0, 2*TMath::Pi());
550 fPrimary->SetXTitle("#eta");
551 fPrimary->SetYTitle("#varphi [radians]");
553 fPrimary->SetDirectory(0);
555 fCounts = new TH1D("counts", "Counts", 1, 0, 1);
556 fCounts->SetXTitle("Events");
557 fCounts->SetYTitle("# of Events");
558 fCounts->SetDirectory(0);
561 //____________________________________________________________________
562 AliForwardMCCorrectionsTask::VtxBin::VtxBin(const VtxBin& o)
569 fPrimary = static_cast<TH2D*>(o.fPrimary->Clone());
570 fPrimary->SetDirectory(0);
573 fCounts = static_cast<TH1D*>(o.fCounts->Clone());
574 fCounts->SetDirectory(0);
578 //____________________________________________________________________
579 AliForwardMCCorrectionsTask::VtxBin&
580 AliForwardMCCorrectionsTask::VtxBin::operator=(const VtxBin& o)
582 if (&o == this) return *this;
583 TNamed::operator=(o);
588 fPrimary = static_cast<TH2D*>(o.fPrimary->Clone());
589 fPrimary->SetDirectory(0);
592 fCounts = static_cast<TH1D*>(o.fCounts->Clone());
593 fCounts->SetDirectory(0);
598 //____________________________________________________________________
600 AliForwardMCCorrectionsTask::VtxBin::CreateOutputObjects(TList* l)
602 TList* d = new TList;
603 d->SetName(GetName());
607 d->Add(fHists.fFMD1i);
608 d->Add(fHists.fFMD2i);
609 d->Add(fHists.fFMD2o);
610 d->Add(fHists.fFMD3i);
611 d->Add(fHists.fFMD3o);
617 //____________________________________________________________________
619 AliForwardMCCorrectionsTask::VtxBin::MakeBg(const TH2D* hits,
620 const TH2D* primary) const
622 TH2D* h = static_cast<TH2D*>(hits->Clone());
624 TString n(h->GetName());
625 n.ReplaceAll("_cache", "");
632 //____________________________________________________________________
634 AliForwardMCCorrectionsTask::VtxBin::Terminate(const TList* input,
637 AliFMDCorrSecondaryMap* map)
639 TList* out = new TList;
640 out->SetName(GetName());
644 TList* l = static_cast<TList*>(input->FindObject(GetName()));
646 AliError(Form("List %s not found in %s", GetName(), input->GetName()));
650 TH2D* fmd1i = static_cast<TH2D*>(l->FindObject("FMD1I_cache"));
651 TH2D* fmd2i = static_cast<TH2D*>(l->FindObject("FMD2I_cache"));
652 TH2D* fmd2o = static_cast<TH2D*>(l->FindObject("FMD2O_cache"));
653 TH2D* fmd3i = static_cast<TH2D*>(l->FindObject("FMD3I_cache"));
654 TH2D* fmd3o = static_cast<TH2D*>(l->FindObject("FMD3O_cache"));
655 TH2D* primO = static_cast<TH2D*>(l->FindObject("primary"));
656 if (!fmd1i || !fmd2i || !fmd2o || !fmd3i || !fmd3o || !primO) {
657 AliError(Form("Missing histogram(s): %p,%p,%p,%p,%p,%p",
658 fmd1i, fmd2i, fmd2o, fmd3i, fmd3o, primO));
662 // Half coverage in phi for inners
663 TH2D* primI = static_cast<TH2D*>(primO->Clone());
664 primI->SetDirectory(0);
667 TH2D* bg1i = MakeBg(fmd1i, primI);
668 TH2D* bg2i = MakeBg(fmd2i, primI);
669 TH2D* bg2o = MakeBg(fmd2o, primO);
670 TH2D* bg3i = MakeBg(fmd3i, primI);
671 TH2D* bg3o = MakeBg(fmd3o, primO);
672 map->SetCorrection(1, 'I', iVz, bg1i);
673 map->SetCorrection(2, 'I', iVz, bg2i);
674 map->SetCorrection(2, 'O', iVz, bg2o);
675 map->SetCorrection(3, 'I', iVz, bg3i);
676 map->SetCorrection(3, 'O', iVz, bg3o);