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(),
75 fUseESDVertexCoordinate(false),
76 fCalculateafterESDeventcuts(false)
86 //____________________________________________________________________
87 AliForwardMCCorrectionsTask::AliForwardMCCorrectionsTask(const char* name)
88 : AliAnalysisTaskSE(name),
89 fInspector("eventInspector"),
90 fTrackDensity("trackDensity"),
100 fUseESDVertexCoordinate(false),
101 fCalculateafterESDeventcuts(false)
110 DefineOutput(1, TList::Class());
111 DefineOutput(2, TList::Class());
113 "ESD:AliESDRun.,AliESDHeader.,AliMultiplicity.,"
114 "AliESDFMD.,SPDVertex.,PrimaryVertex.";
117 //____________________________________________________________________
118 AliForwardMCCorrectionsTask::AliForwardMCCorrectionsTask(const AliForwardMCCorrectionsTask& o)
119 : AliAnalysisTaskSE(o),
120 fInspector(o.fInspector),
124 fFirstEvent(o.fFirstEvent),
125 fHEvents(o.fHEvents),
126 fHEventsTr(o.fHEventsTr),
127 fHEventsTrVtx(o.fHEventsTrVtx),
131 fUseESDVertexCoordinate(o.fUseESDVertexCoordinate),
132 fCalculateafterESDeventcuts(o.fCalculateafterESDeventcuts)
139 // o Object to copy from
143 //____________________________________________________________________
144 AliForwardMCCorrectionsTask&
145 AliForwardMCCorrectionsTask::operator=(const AliForwardMCCorrectionsTask& o)
148 // Assignment operator
151 // o Object to assign from
154 // Reference to this object
156 if (&o == this) return *this;
157 fInspector = o.fInspector;
158 fTrackDensity = o.fTrackDensity;
160 fVtxBins = o.fVtxBins;
161 fFirstEvent = o.fFirstEvent;
162 fHEvents = o.fHEvents;
163 fHEventsTr = o.fHEventsTr;
164 fHEventsTrVtx = o.fHEventsTrVtx;
165 SetVertexAxis(o.fVtxAxis);
166 SetEtaAxis(o.fEtaAxis);
167 fUseESDVertexCoordinate=o.fUseESDVertexCoordinate;
168 fCalculateafterESDeventcuts=o.fCalculateafterESDeventcuts;
173 //____________________________________________________________________
175 AliForwardMCCorrectionsTask::Init()
178 // Initialize the task
183 //____________________________________________________________________
185 AliForwardMCCorrectionsTask::SetVertexAxis(Int_t nBin, Double_t min,
189 // Set the vertex axis to use
192 // nBins Number of bins
193 // vzMin Least @f$z@f$ coordinate of interation point
194 // vzMax Largest @f$z@f$ coordinate of interation point
203 AliWarning(Form("Minimum vertex %f < -10, make sure you want this",min));
205 AliWarning(Form("Minimum vertex %f > +10, make sure you want this",max));
207 fVtxAxis.Set(nBin, min, max);
209 //____________________________________________________________________
211 AliForwardMCCorrectionsTask::SetVertexAxis(const TAxis& axis)
214 // Set the vertex axis to use
219 SetVertexAxis(axis.GetNbins(),axis.GetXmin(),axis.GetXmax());
222 //____________________________________________________________________
224 AliForwardMCCorrectionsTask::SetEtaAxis(Int_t nBin, Double_t min, Double_t max)
227 // Set the eta axis to use
230 // nBins Number of bins
231 // vzMin Least @f$\eta@f$
232 // vzMax Largest @f$\eta@f$
240 AliWarning(Form("Minimum eta %f < -4, make sure you want this",min));
242 AliWarning(Form("Minimum eta %f > +6, make sure you want this",max));
243 fEtaAxis.Set(nBin, min, max);
245 //____________________________________________________________________
247 AliForwardMCCorrectionsTask::SetEtaAxis(const TAxis& axis)
250 // Set the eta axis to use
255 SetEtaAxis(axis.GetNbins(),axis.GetXmin(),axis.GetXmax());
258 //____________________________________________________________________
260 AliForwardMCCorrectionsTask::DefineBins(TList* l)
262 if (!fVtxBins) fVtxBins = new TObjArray(fVtxAxis.GetNbins(), 1);
263 if (fVtxBins->GetEntries() > 0) return;
265 fVtxBins->SetOwner();
266 for (Int_t i = 1; i <= fVtxAxis.GetNbins(); i++) {
267 Double_t low = fVtxAxis.GetBinLowEdge(i);
268 Double_t high = fVtxAxis.GetBinUpEdge(i);
269 VtxBin* bin = new VtxBin(low, high, fEtaAxis);
270 fVtxBins->AddAt(bin, i);
271 bin->CreateOutputObjects(l);
275 //____________________________________________________________________
277 AliForwardMCCorrectionsTask::UserCreateOutputObjects()
280 // Create output objects
285 fList->SetName(Form("%sSums", GetName()));
289 fHEvents = new TH1I(GetEventName(false,false),
290 "Number of all events",
294 fHEvents->SetXTitle("v_{z} [cm]");
295 fHEvents->SetYTitle("# of events");
296 fHEvents->SetFillColor(kBlue+1);
297 fHEvents->SetFillStyle(3001);
298 fHEvents->SetDirectory(0);
299 fList->Add(fHEvents);
301 fHEventsTr = new TH1I(GetEventName(true, false),
302 "Number of triggered events",
306 fHEventsTr->SetXTitle("v_{z} [cm]");
307 fHEventsTr->SetYTitle("# of events");
308 fHEventsTr->SetFillColor(kRed+1);
309 fHEventsTr->SetFillStyle(3001);
310 fHEventsTr->SetDirectory(0);
311 fList->Add(fHEventsTr);
313 fHEventsTrVtx = new TH1I(GetEventName(true,true),
314 "Number of events w/trigger and vertex",
318 fHEventsTrVtx->SetXTitle("v_{z} [cm]");
319 fHEventsTrVtx->SetYTitle("# of events");
320 fHEventsTrVtx->SetFillColor(kBlue+1);
321 fHEventsTrVtx->SetFillStyle(3001);
322 fHEventsTrVtx->SetDirectory(0);
323 fList->Add(fHEventsTrVtx);
325 // Copy axis objects to output
326 TH1* vtxAxis = new TH1D("vtxAxis", "Vertex axis",
330 TH1* etaAxis = new TH1D("etaAxis", "Eta axis",
337 AliInfo(Form("Initialising sub-routines: %p, %p",
338 &fInspector, &fTrackDensity));
339 fInspector.CreateOutputObjects(fList);
340 fTrackDensity.CreateOutputObjects(fList);
344 //____________________________________________________________________
346 AliForwardMCCorrectionsTask::UserExec(Option_t*)
349 // Process each event
355 // Get the input data - MC event
356 AliMCEvent* mcEvent = MCEvent();
358 AliWarning("No MC event found");
362 // Get the input data - ESD event
363 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
365 AliWarning("No ESD event found for input event");
369 // --- Read in the data --------------------------------------------
372 //--- Read run information -----------------------------------------
373 if (fFirstEvent && esd->GetESDRun()) {
374 fInspector.ReadRunDetails(esd);
376 AliInfo(Form("Initializing with parameters from the ESD:\n"
377 " AliESDEvent::GetBeamEnergy() ->%f\n"
378 " AliESDEvent::GetBeamType() ->%s\n"
379 " AliESDEvent::GetCurrentL3() ->%f\n"
380 " AliESDEvent::GetMagneticField()->%f\n"
381 " AliESDEvent::GetRunNumber() ->%d\n",
382 esd->GetBeamEnergy(),
385 esd->GetMagneticField(),
386 esd->GetRunNumber()));
388 fInspector.SetupForData(fVtxAxis);
395 UInt_t triggers = 0; // Trigger bits
396 Bool_t lowFlux = true; // Low flux flag
397 UShort_t iVz = 0; // Vertex bin from ESD
398 TVector3 ip(1024,1024,1000);
399 Double_t cent = -1; // Centrality
400 UShort_t iVzMc = 0; // Vertex bin from MC
401 Double_t vZMc = 1000; // Z coordinate of IP vertex from MC
402 Double_t b = -1; // Impact parameter
403 Double_t cMC = -1; // Centrality estimate from b
404 Int_t nPart = -1; // Number of participants
405 Int_t nBin = -1; // Number of binary collisions
406 Double_t phiR = 100; // Reaction plane from MC
407 UShort_t nClusters = 0; // Number of SPD clusters
409 UInt_t retESD = fInspector.Process(esd, triggers, lowFlux, iVz, ip,
412 Bool_t isAccepted = true;
413 if(fCalculateafterESDeventcuts) {
414 if (retESD & AliFMDEventInspector::kNoEvent) isAccepted = false;
415 if (retESD & AliFMDEventInspector::kNoTriggers) isAccepted = false;
416 if (retESD & AliFMDEventInspector::kNoVertex) isAccepted = false;
417 if (retESD & AliFMDEventInspector::kNoFMD) isAccepted = false;
418 if (!isAccepted) return;
419 // returns if there is not event , does not pass phys selection ,
420 // has no veretx and lack of FMD data.
421 // with good veretx outside z range it will continue
425 fInspector.ProcessMC(mcEvent, triggers, iVzMc, vZMc,
426 b, cMC, nPart, nBin, phiR);
428 Bool_t isInel = triggers & AliAODForwardMult::kInel;
429 Bool_t hasVtx = retESD == AliFMDMCEventInspector::kOk;
431 // Fill the event count histograms
432 if (isInel) fHEventsTr->Fill(vZMc);
433 if (isInel && hasVtx) fHEventsTrVtx->Fill(vZMc);
434 fHEvents->Fill(vZMc);
436 // Now find our vertex bin object
438 UShort_t usedZbin=iVzMc;
439 if(fUseESDVertexCoordinate)
443 if (usedZbin > 0 && usedZbin <= fVtxAxis.GetNbins())
444 bin = static_cast<VtxBin*>(fVtxBins->At(usedZbin));
446 // AliError(Form("No vertex bin object @ %d (%f)", iVzMc, vZMc));
450 // Clear our ESD object
454 AliESDFMD* esdFMD = esd->GetFMDData();
456 // Now process our input data and store in own ESD object
457 fTrackDensity.Calculate(*esdFMD, *mcEvent, vZMc, fESDFMD, bin->fPrimary);
458 bin->fCounts->Fill(0.5);
460 // And then bin the data in our vtxbin
461 for (UShort_t d=1; d<=3; d++) {
462 UShort_t nr = (d == 1 ? 1 : 2);
463 for (UShort_t q=0; q<nr; q++) {
464 Char_t r = (q == 0 ? 'I' : 'O');
465 UShort_t ns= (q == 0 ? 20 : 40);
466 UShort_t nt= (q == 0 ? 512 : 256);
467 TH2D* h = bin->fHists.Get(d,r);
469 for (UShort_t s=0; s<ns; s++) {
470 for (UShort_t t=0; t<nt; t++) {
471 Float_t mult = fESDFMD.Multiplicity(d,r,s,t);
473 if (mult == 0 || mult > 20) continue;
475 Float_t phi = fESDFMD.Phi(d,r,s,t) / 180 * TMath::Pi();
476 Float_t eta = fESDFMD.Eta(d,r,s,t);
477 h->Fill(eta,phi,mult);
485 //____________________________________________________________________
487 AliForwardMCCorrectionsTask::Terminate(Option_t*)
496 fList = dynamic_cast<TList*>(GetOutputData(1));
498 AliError("No output list defined");
505 TList* output = new TList;
507 output->SetName(Form("%sResults", GetName()));
509 // --- Fill correction object --------------------------------------
510 AliFMDCorrSecondaryMap* corr = new AliFMDCorrSecondaryMap;
511 corr->SetVertexAxis(fVtxAxis);
512 corr->SetEtaAxis(fEtaAxis);
514 TIter next(fVtxBins);
517 while ((bin = static_cast<VtxBin*>(next())))
518 bin->Terminate(fList, output, iVz++, corr);
525 //____________________________________________________________________
527 AliForwardMCCorrectionsTask::Print(Option_t* option) const
529 std::cout << ClassName() << "\n"
530 << " Vertex bins: " << fVtxAxis.GetNbins() << '\n'
531 << " Vertex range: [" << fVtxAxis.GetXmin()
532 << "," << fVtxAxis.GetXmax() << "]\n"
533 << " Eta bins: " << fEtaAxis.GetNbins() << '\n'
534 << " Eta range: [" << fEtaAxis.GetXmin()
535 << "," << fEtaAxis.GetXmax() << "]"
537 gROOT->IncreaseDirLevel();
538 fInspector.Print(option);
539 fTrackDensity.Print(option);
540 gROOT->DecreaseDirLevel();
543 //====================================================================
545 AliForwardMCCorrectionsTask::VtxBin::BinName(Double_t low,
549 buf = Form("vtx%+05.1f_%+05.1f", low, high);
550 buf.ReplaceAll("+", "p");
551 buf.ReplaceAll("-", "m");
552 buf.ReplaceAll(".", "d");
557 //____________________________________________________________________
558 AliForwardMCCorrectionsTask::VtxBin::VtxBin()
564 //____________________________________________________________________
565 AliForwardMCCorrectionsTask::VtxBin::VtxBin(Double_t low,
568 : TNamed(BinName(low, high),
569 Form("%+5.1fcm<v_{z}<%+5.1fcm", low, high)),
576 fPrimary = new TH2D("primary", "Primaries",
577 axis.GetNbins(), axis.GetXmin(), axis.GetXmax(),
578 40, 0, 2*TMath::Pi());
579 fPrimary->SetXTitle("#eta");
580 fPrimary->SetYTitle("#varphi [radians]");
582 fPrimary->SetDirectory(0);
584 fCounts = new TH1D("counts", "Counts", 1, 0, 1);
585 fCounts->SetXTitle("Events");
586 fCounts->SetYTitle("# of Events");
587 fCounts->SetDirectory(0);
590 //____________________________________________________________________
591 AliForwardMCCorrectionsTask::VtxBin::VtxBin(const VtxBin& o)
598 fPrimary = static_cast<TH2D*>(o.fPrimary->Clone());
599 fPrimary->SetDirectory(0);
602 fCounts = static_cast<TH1D*>(o.fCounts->Clone());
603 fCounts->SetDirectory(0);
607 //____________________________________________________________________
608 AliForwardMCCorrectionsTask::VtxBin&
609 AliForwardMCCorrectionsTask::VtxBin::operator=(const VtxBin& o)
611 if (&o == this) return *this;
612 TNamed::operator=(o);
617 fPrimary = static_cast<TH2D*>(o.fPrimary->Clone());
618 fPrimary->SetDirectory(0);
621 fCounts = static_cast<TH1D*>(o.fCounts->Clone());
622 fCounts->SetDirectory(0);
627 //____________________________________________________________________
629 AliForwardMCCorrectionsTask::VtxBin::CreateOutputObjects(TList* l)
631 TList* d = new TList;
632 d->SetName(GetName());
636 d->Add(fHists.fFMD1i);
637 d->Add(fHists.fFMD2i);
638 d->Add(fHists.fFMD2o);
639 d->Add(fHists.fFMD3i);
640 d->Add(fHists.fFMD3o);
646 //____________________________________________________________________
648 AliForwardMCCorrectionsTask::VtxBin::MakeBg(const TH2D* hits,
649 const TH2D* primary) const
651 TH2D* h = static_cast<TH2D*>(hits->Clone());
653 TString n(h->GetName());
654 n.ReplaceAll("_cache", "");
661 //____________________________________________________________________
663 AliForwardMCCorrectionsTask::VtxBin::Terminate(const TList* input,
666 AliFMDCorrSecondaryMap* map)
668 TList* out = new TList;
669 out->SetName(GetName());
673 TList* l = static_cast<TList*>(input->FindObject(GetName()));
675 AliError(Form("List %s not found in %s", GetName(), input->GetName()));
679 TH2D* fmd1i = static_cast<TH2D*>(l->FindObject("FMD1I_cache"));
680 TH2D* fmd2i = static_cast<TH2D*>(l->FindObject("FMD2I_cache"));
681 TH2D* fmd2o = static_cast<TH2D*>(l->FindObject("FMD2O_cache"));
682 TH2D* fmd3i = static_cast<TH2D*>(l->FindObject("FMD3I_cache"));
683 TH2D* fmd3o = static_cast<TH2D*>(l->FindObject("FMD3O_cache"));
684 TH2D* primO = static_cast<TH2D*>(l->FindObject("primary"));
685 if (!fmd1i || !fmd2i || !fmd2o || !fmd3i || !fmd3o || !primO) {
686 AliError(Form("Missing histogram(s): %p,%p,%p,%p,%p,%p",
687 fmd1i, fmd2i, fmd2o, fmd3i, fmd3o, primO));
691 // Half coverage in phi for inners
692 TH2D* primI = static_cast<TH2D*>(primO->Clone());
693 primI->SetDirectory(0);
696 TH2D* bg1i = MakeBg(fmd1i, primI);
697 TH2D* bg2i = MakeBg(fmd2i, primI);
698 TH2D* bg2o = MakeBg(fmd2o, primO);
699 TH2D* bg3i = MakeBg(fmd3i, primI);
700 TH2D* bg3o = MakeBg(fmd3o, primO);
701 map->SetCorrection(1, 'I', iVz, bg1i);
702 map->SetCorrection(2, 'I', iVz, bg2i);
703 map->SetCorrection(2, 'O', iVz, bg2o);
704 map->SetCorrection(3, 'I', iVz, bg3i);
705 map->SetCorrection(3, 'O', iVz, bg3o);