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" : ""));
43 const char* GetHitsName(UShort_t d, Char_t r)
45 return Form("hitsFMD%d%c", d, r);
47 const char* GetStripsName(UShort_t d, Char_t r)
49 return Form("stripsFMD%d%c", d, r);
51 const char* GetPrimaryName(Char_t r, Bool_t trVtx)
53 return Form("primaries%s%s",
54 ((r == 'I' || r == 'i') ? "Inner" : "Outer"),
55 (trVtx ? "TrVtx" : "All"));
59 //====================================================================
60 AliForwardMCCorrectionsTask::AliForwardMCCorrectionsTask()
61 : AliAnalysisTaskSE(),
82 //____________________________________________________________________
83 AliForwardMCCorrectionsTask::AliForwardMCCorrectionsTask(const char* name)
84 : AliAnalysisTaskSE(name),
85 fInspector("eventInspector"),
86 fTrackDensity("trackDensity"),
103 DefineOutput(1, TList::Class());
104 DefineOutput(2, TList::Class());
107 //____________________________________________________________________
108 AliForwardMCCorrectionsTask::AliForwardMCCorrectionsTask(const AliForwardMCCorrectionsTask& o)
109 : AliAnalysisTaskSE(o),
110 fInspector(o.fInspector),
114 fFirstEvent(o.fFirstEvent),
115 fHEvents(o.fHEvents),
116 fHEventsTr(o.fHEventsTr),
117 fHEventsTrVtx(o.fHEventsTrVtx),
126 // o Object to copy from
130 //____________________________________________________________________
131 AliForwardMCCorrectionsTask&
132 AliForwardMCCorrectionsTask::operator=(const AliForwardMCCorrectionsTask& o)
135 // Assignment operator
138 // o Object to assign from
141 // Reference to this object
143 fInspector = o.fInspector;
144 fTrackDensity = o.fTrackDensity;
146 fVtxBins = o.fVtxBins;
147 fFirstEvent = o.fFirstEvent;
148 fHEvents = o.fHEvents;
149 fHEventsTr = o.fHEventsTr;
150 fHEventsTrVtx = o.fHEventsTrVtx;
151 SetVertexAxis(o.fVtxAxis);
152 SetEtaAxis(o.fEtaAxis);
157 //____________________________________________________________________
159 AliForwardMCCorrectionsTask::Init()
162 // Initialize the task
167 //____________________________________________________________________
169 AliForwardMCCorrectionsTask::SetVertexAxis(Int_t nBin, Double_t min,
173 // Set the vertex axis to use
176 // nBins Number of bins
177 // vzMin Least @f$z@f$ coordinate of interation point
178 // vzMax Largest @f$z@f$ coordinate of interation point
180 if (max < min) max = -min;
187 AliWarning(Form("Minimum vertex %f < -10, make sure you want this",min));
189 AliWarning(Form("Minimum vertex %f > +10, make sure you want this",max));
190 fVtxAxis.Set(nBin, min, max);
192 //____________________________________________________________________
194 AliForwardMCCorrectionsTask::SetVertexAxis(const TAxis& axis)
197 // Set the vertex axis to use
202 SetVertexAxis(axis.GetNbins(),axis.GetXmin(),axis.GetXmax());
205 //____________________________________________________________________
207 AliForwardMCCorrectionsTask::SetEtaAxis(Int_t nBin, Double_t min, Double_t max)
210 // Set the eta axis to use
213 // nBins Number of bins
214 // vzMin Least @f$\eta@f$
215 // vzMax Largest @f$\eta@f$
217 if (max < min) max = -min;
224 AliWarning(Form("Minimum eta %f < -4, make sure you want this",min));
226 AliWarning(Form("Minimum eta %f > +6, make sure you want this",max));
227 fVtxAxis.Set(nBin, min, max);
229 //____________________________________________________________________
231 AliForwardMCCorrectionsTask::SetEtaAxis(const TAxis& axis)
234 // Set the eta axis to use
239 SetEtaAxis(axis.GetNbins(),axis.GetXmin(),axis.GetXmax());
242 //____________________________________________________________________
244 AliForwardMCCorrectionsTask::DefineBins(TList* l)
246 if (!fVtxBins) fVtxBins = new TObjArray(fVtxAxis.GetNbins(), 1);
247 if (fVtxBins->GetEntries() > 0) return;
249 fVtxBins->SetOwner();
250 for (Int_t i = 1; i <= fVtxAxis.GetNbins(); i++) {
251 Double_t low = fVtxAxis.GetBinLowEdge(i);
252 Double_t high = fVtxAxis.GetBinUpEdge(i);
253 VtxBin* bin = new VtxBin(low, high, fEtaAxis);
254 fVtxBins->AddAt(bin, i);
255 bin->DefineOutput(l);
259 //____________________________________________________________________
261 AliForwardMCCorrectionsTask::UserCreateOutputObjects()
264 // Create output objects
269 fList->SetName(Form("%sSums", GetName()));
273 fHEvents = new TH1I(GetEventName(false,false),
274 "Number of all events",
278 fHEvents->SetXTitle("v_{z} [cm]");
279 fHEvents->SetYTitle("# of events");
280 fHEvents->SetFillColor(kBlue+1);
281 fHEvents->SetFillStyle(3001);
282 fHEvents->SetDirectory(0);
283 fList->Add(fHEvents);
285 fHEventsTr = new TH1I(GetEventName(true, false),
286 "Number of triggered events",
290 fHEventsTr->SetXTitle("v_{z} [cm]");
291 fHEventsTr->SetYTitle("# of events");
292 fHEventsTr->SetFillColor(kRed+1);
293 fHEventsTr->SetFillStyle(3001);
294 fHEventsTr->SetDirectory(0);
295 fList->Add(fHEventsTr);
297 fHEventsTrVtx = new TH1I(GetEventName(true,true),
298 "Number of events w/trigger and vertex",
302 fHEventsTrVtx->SetXTitle("v_{z} [cm]");
303 fHEventsTrVtx->SetYTitle("# of events");
304 fHEventsTrVtx->SetFillColor(kBlue+1);
305 fHEventsTrVtx->SetFillStyle(3001);
306 fHEventsTrVtx->SetDirectory(0);
307 fList->Add(fHEventsTrVtx);
309 // Copy axis objects to output
310 TH1* vtxAxis = new TH1D("vtxAxis", "Vertex axis",
314 TH1* etaAxis = new TH1D("etaAxis", "Eta axis",
321 AliInfo(Form("Initialising sub-routines: %p, %p",
322 &fInspector, &fTrackDensity));
323 fInspector.DefineOutput(fList);
324 fInspector.Init(fVtxAxis);
325 fTrackDensity.DefineOutput(fList);
329 //____________________________________________________________________
331 AliForwardMCCorrectionsTask::UserExec(Option_t*)
334 // Process each event
340 // Get the input data - MC event
341 AliMCEvent* mcEvent = MCEvent();
343 AliWarning("No MC event found");
347 // Get the input data - ESD event
348 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
350 AliWarning("No ESD event found for input event");
354 //--- Read run information -----------------------------------------
355 if (fFirstEvent && esd->GetESDRun()) {
356 fInspector.ReadRunDetails(esd);
358 AliInfo(Form("Initializing with parameters from the ESD:\n"
359 " AliESDEvent::GetBeamEnergy() ->%f\n"
360 " AliESDEvent::GetBeamType() ->%s\n"
361 " AliESDEvent::GetCurrentL3() ->%f\n"
362 " AliESDEvent::GetMagneticField()->%f\n"
363 " AliESDEvent::GetRunNumber() ->%d\n",
364 esd->GetBeamEnergy(),
367 esd->GetMagneticField(),
368 esd->GetRunNumber()));
375 UInt_t triggers; // Trigger bits
376 Bool_t lowFlux; // Low flux flag
377 UShort_t iVz; // Vertex bin from ESD
378 Double_t vZ; // Z coordinate from ESD
379 Double_t cent; // Centrality
380 UShort_t iVzMc; // Vertex bin from MC
381 Double_t vZMc; // Z coordinate of IP vertex from MC
382 Double_t b; // Impact parameter
383 Int_t nPart; // Number of participants
384 Int_t nBin; // Number of binary collisions
385 Double_t phiR; // Reaction plane from MC
386 UShort_t nClusters;// Number of SPD clusters
388 UInt_t retESD = fInspector.Process(esd, triggers, lowFlux, iVz, vZ,
390 fInspector.ProcessMC(mcEvent, triggers, iVzMc, vZMc,
391 b, nPart, nBin, phiR);
393 Bool_t isInel = triggers & AliAODForwardMult::kInel;
394 Bool_t hasVtx = retESD == AliFMDMCEventInspector::kOk;
396 // Fill the event count histograms
397 if (isInel) fHEventsTr->Fill(vZMc);
398 if (isInel && hasVtx) fHEventsTrVtx->Fill(vZMc);
399 fHEvents->Fill(vZMc);
401 // Now find our vertex bin object
403 if (iVzMc > 0 && iVzMc <= fVtxAxis.GetNbins())
404 bin = static_cast<VtxBin*>(fVtxBins->At(iVzMc));
406 // AliError(Form("No vertex bin object @ %d (%f)", iVzMc, vZMc));
410 // Clear our ESD object
414 AliESDFMD* esdFMD = esd->GetFMDData();
416 // Now process our input data and store in own ESD object
417 fTrackDensity.Calculate(*esdFMD, *mcEvent, vZMc, fESDFMD, bin->fPrimary);
418 bin->fCounts->Fill(0.5);
420 // And then bin the data in our vtxbin
421 for (UShort_t d=1; d<=3; d++) {
422 UShort_t nr = (d == 1 ? 1 : 2);
423 for (UShort_t q=0; q<nr; q++) {
424 Char_t r = (q == 0 ? 'I' : 'O');
425 UShort_t ns= (q == 0 ? 20 : 40);
426 UShort_t nt= (q == 0 ? 512 : 256);
427 TH2D* h = bin->fHists.Get(d,r);
429 for (UShort_t s=0; s<ns; s++) {
430 for (UShort_t t=0; t<nt; t++) {
431 Float_t mult = fESDFMD.Multiplicity(d,r,s,t);
433 if (mult == 0 || mult > 20) continue;
435 Float_t phi = fESDFMD.Phi(d,r,s,t) / 180 * TMath::Pi();
436 Float_t eta = fESDFMD.Eta(d,r,s,t);
437 h->Fill(eta,phi,mult);
444 //____________________________________________________________________
446 AliForwardMCCorrectionsTask::Terminate(Option_t*)
455 fList = dynamic_cast<TList*>(GetOutputData(1));
457 AliError("No output list defined");
462 TList* output = new TList;
464 output->SetName(Form("%sResults", GetName()));
466 // --- Fill correction object --------------------------------------
467 AliFMDCorrSecondaryMap* corr = new AliFMDCorrSecondaryMap;
468 corr->SetVertexAxis(fVtxAxis);
469 corr->SetEtaAxis(fEtaAxis);
471 TIter next(fVtxBins);
474 while ((bin = static_cast<VtxBin*>(next())))
475 bin->Finish(fList, output, iVz++, corr);
482 //____________________________________________________________________
484 AliForwardMCCorrectionsTask::Print(Option_t* option) const
486 std::cout << ClassName() << "\n"
487 << " Vertex bins: " << fVtxAxis.GetNbins() << '\n'
488 << " Vertex range: [" << fVtxAxis.GetXmin()
489 << "," << fVtxAxis.GetXmax() << "]\n"
490 << " Eta bins: " << fEtaAxis.GetNbins() << '\n'
491 << " Eta range: [" << fEtaAxis.GetXmin()
492 << "," << fEtaAxis.GetXmax() << "]"
494 gROOT->IncreaseDirLevel();
495 fInspector.Print(option);
496 fTrackDensity.Print(option);
497 gROOT->DecreaseDirLevel();
500 //====================================================================
502 AliForwardMCCorrectionsTask::VtxBin::BinName(Double_t low,
506 buf = Form("vtx%+05.1f_%+05.1f", low, high);
507 buf.ReplaceAll("+", "p");
508 buf.ReplaceAll("-", "m");
509 buf.ReplaceAll(".", "d");
514 //____________________________________________________________________
515 AliForwardMCCorrectionsTask::VtxBin::VtxBin()
521 //____________________________________________________________________
522 AliForwardMCCorrectionsTask::VtxBin::VtxBin(Double_t low,
525 : TNamed(BinName(low, high),
526 Form("%+5.1fcm<v_{z}<%+5.1fcm", low, high)),
533 fPrimary = new TH2D("primary", "Primaries",
534 axis.GetNbins(), axis.GetXmin(), axis.GetXmax(),
535 40, 0, 2*TMath::Pi());
536 fPrimary->SetXTitle("#eta");
537 fPrimary->SetYTitle("#varphi [radians]");
539 fPrimary->SetDirectory(0);
541 fCounts = new TH1D("counts", "Counts", 1, 0, 1);
542 fCounts->SetXTitle("Events");
543 fCounts->SetYTitle("# of Events");
544 fCounts->SetDirectory(0);
547 //____________________________________________________________________
548 AliForwardMCCorrectionsTask::VtxBin::VtxBin(const VtxBin& o)
555 fPrimary = static_cast<TH2D*>(o.fPrimary->Clone());
556 fPrimary->SetDirectory(0);
559 fCounts = static_cast<TH1D*>(o.fCounts->Clone());
560 fCounts->SetDirectory(0);
564 //____________________________________________________________________
565 AliForwardMCCorrectionsTask::VtxBin&
566 AliForwardMCCorrectionsTask::VtxBin::operator=(const VtxBin& o)
568 TNamed::operator=(o);
573 fPrimary = static_cast<TH2D*>(o.fPrimary->Clone());
574 fPrimary->SetDirectory(0);
577 fCounts = static_cast<TH1D*>(o.fCounts->Clone());
578 fCounts->SetDirectory(0);
583 //____________________________________________________________________
585 AliForwardMCCorrectionsTask::VtxBin::DefineOutput(TList* l)
587 TList* d = new TList;
588 d->SetName(GetName());
592 d->Add(fHists.fFMD1i);
593 d->Add(fHists.fFMD2i);
594 d->Add(fHists.fFMD2o);
595 d->Add(fHists.fFMD3i);
596 d->Add(fHists.fFMD3o);
602 //____________________________________________________________________
604 AliForwardMCCorrectionsTask::VtxBin::MakeBg(const TH2D* hits,
605 const TH2D* primary) const
607 TH2D* h = static_cast<TH2D*>(hits->Clone());
609 TString n(h->GetName());
610 n.ReplaceAll("_cache", "");
617 //____________________________________________________________________
619 AliForwardMCCorrectionsTask::VtxBin::Finish(const TList* input,
622 AliFMDCorrSecondaryMap* map)
624 TList* out = new TList;
625 out->SetName(GetName());
629 TList* l = static_cast<TList*>(input->FindObject(GetName()));
631 AliError(Form("List %s not found in %s", GetName(), input->GetName()));
635 TH2D* fmd1i = static_cast<TH2D*>(l->FindObject("FMD1I_cache"));
636 TH2D* fmd2i = static_cast<TH2D*>(l->FindObject("FMD2I_cache"));
637 TH2D* fmd2o = static_cast<TH2D*>(l->FindObject("FMD2O_cache"));
638 TH2D* fmd3i = static_cast<TH2D*>(l->FindObject("FMD3I_cache"));
639 TH2D* fmd3o = static_cast<TH2D*>(l->FindObject("FMD3O_cache"));
640 TH2D* primO = static_cast<TH2D*>(l->FindObject("primary"));
641 if (!fmd1i || !fmd2i || !fmd2o || !fmd3i || !fmd3o || !primO) {
642 AliError(Form("Missing histogram(s): %p,%p,%p,%p,%p,%p",
643 fmd1i, fmd2i, fmd2o, fmd3i, fmd3o, primO));
647 // Half coverage in phi for inners
648 TH2D* primI = static_cast<TH2D*>(primO->Clone());
649 primI->SetDirectory(0);
652 TH2D* bg1i = MakeBg(fmd1i, primI);
653 TH2D* bg2i = MakeBg(fmd2i, primI);
654 TH2D* bg2o = MakeBg(fmd2o, primO);
655 TH2D* bg3i = MakeBg(fmd3i, primI);
656 TH2D* bg3o = MakeBg(fmd3o, primO);
657 map->SetCorrection(1, 'I', iVz, bg1i);
658 map->SetCorrection(2, 'I', iVz, bg2i);
659 map->SetCorrection(2, 'O', iVz, bg2o);
660 map->SetCorrection(3, 'I', iVz, bg3i);
661 map->SetCorrection(3, 'O', iVz, bg3o);