2 // Calculate the corrections in the central regions
14 #include "AliCentralMCCorrectionsTask.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 "AliCentralCorrSecondaryMap.h"
28 #include "AliCentralCorrAcceptance.h"
29 #include "AliForwardUtil.h"
30 #include "AliMultiplicity.h"
33 #include <TDirectory.h>
38 //====================================================================
40 const char* GetEventName(Bool_t tr, Bool_t vtx)
42 return Form("nEvents%s%s", (tr ? "Tr" : ""), (vtx ? "Vtx" : ""));
46 //====================================================================
47 AliCentralMCCorrectionsTask::AliCentralMCCorrectionsTask()
48 : AliAnalysisTaskSE(),
68 DGUARD(fDebug,0,"Default construction of AliCentralMCCorrectionsTask");
71 //____________________________________________________________________
72 AliCentralMCCorrectionsTask::AliCentralMCCorrectionsTask(const char* name)
73 : AliAnalysisTaskSE(name),
74 fInspector("eventInspector"),
75 fTrackDensity("trackDensity"),
93 DGUARD(fDebug,0,"Named construction of AliCentralMCCorrectionsTask: %s",name);
94 DefineOutput(1, TList::Class());
95 DefineOutput(2, TList::Class());
98 //____________________________________________________________________
99 AliCentralMCCorrectionsTask::AliCentralMCCorrectionsTask(const AliCentralMCCorrectionsTask& o)
100 : AliAnalysisTaskSE(o),
101 fInspector(o.fInspector),
104 fFirstEvent(o.fFirstEvent),
105 fHEvents(o.fHEvents),
106 fHEventsTr(o.fHEventsTr),
107 fHEventsTrVtx(o.fHEventsTrVtx),
111 fNPhiBins(o.fNPhiBins),
112 fEffectiveCorr(o.fEffectiveCorr)
118 // o Object to copy from
120 DGUARD(fDebug,0,"Copy construction of AliCentralMCCorrectionsTask");
123 //____________________________________________________________________
124 AliCentralMCCorrectionsTask&
125 AliCentralMCCorrectionsTask::operator=(const AliCentralMCCorrectionsTask& o)
128 // Assignment operator
131 // o Object to assign from
134 // Reference to this object
136 DGUARD(fDebug,3,"Assignment of AliCentralMCCorrectionsTask");
137 if (&o == this) return *this;
138 fInspector = o.fInspector;
139 fTrackDensity = o.fTrackDensity;
140 fVtxBins = o.fVtxBins;
141 fFirstEvent = o.fFirstEvent;
142 fHEvents = o.fHEvents;
143 fHEventsTr = o.fHEventsTr;
144 fHEventsTrVtx = o.fHEventsTrVtx;
145 SetVertexAxis(o.fVtxAxis);
146 SetEtaAxis(o.fEtaAxis);
147 fNPhiBins = o.fNPhiBins;
148 fEffectiveCorr = o.fEffectiveCorr;
153 //____________________________________________________________________
155 AliCentralMCCorrectionsTask::Init()
158 // Initialize the task
161 DGUARD(fDebug,1,"Initialize AliCentralMCCorrectionsTask");
164 //____________________________________________________________________
166 AliCentralMCCorrectionsTask::SetVertexAxis(Int_t nBin, Double_t min,
170 // Set the vertex axis to use
173 // nBins Number of bins
174 // vzMin Least @f$z@f$ coordinate of interation point
175 // vzMax Largest @f$z@f$ coordinate of interation point
177 DGUARD(fDebug,3,"Set vertex axis AliCentralMCCorrectionsTask [%d,%f,%f]",
185 AliWarning(Form("Minimum vertex %f < -10, make sure you want this",min));
187 AliWarning(Form("Minimum vertex %f > +10, make sure you want this",max));
188 fVtxAxis.Set(nBin, min, max);
190 //____________________________________________________________________
192 AliCentralMCCorrectionsTask::SetVertexAxis(const TAxis& axis)
195 // Set the vertex axis to use
200 SetVertexAxis(axis.GetNbins(),axis.GetXmin(),axis.GetXmax());
203 //____________________________________________________________________
205 AliCentralMCCorrectionsTask::SetEtaAxis(Int_t nBin, Double_t min, Double_t max)
208 // Set the eta axis to use
211 // nBins Number of bins
212 // vzMin Least @f$\eta@f$
213 // vzMax Largest @f$\eta@f$
215 DGUARD(fDebug,3,"Set eta axis AliCentralMCCorrectionsTask [%d,%f,%f]",
223 AliWarning(Form("Minimum eta %f < -4, make sure you want this",min));
225 AliWarning(Form("Minimum eta %f > +6, make sure you want this",max));
226 fEtaAxis.Set(nBin, min, max);
228 //____________________________________________________________________
230 AliCentralMCCorrectionsTask::SetEtaAxis(const TAxis& axis)
233 // Set the eta axis to use
238 SetEtaAxis(axis.GetNbins(),axis.GetXmin(),axis.GetXmax());
241 //____________________________________________________________________
243 AliCentralMCCorrectionsTask::DefineBins(TList* l)
245 DGUARD(fDebug,1,"Define bins in AliCentralMCCorrectionsTask");
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, fNPhiBins);
254 fVtxBins->AddAt(bin, i);
255 bin->DefineOutput(l);
259 //____________________________________________________________________
261 AliCentralMCCorrectionsTask::UserCreateOutputObjects()
264 // Create output objects
267 DGUARD(fDebug,1,"Create user output for AliCentralMCCorrectionsTask");
270 fList->SetName(Form("%sSums", GetName()));
274 fHEvents = new TH1I(GetEventName(false,false),
275 "Number of all events",
279 fHEvents->SetXTitle("v_{z} [cm]");
280 fHEvents->SetYTitle("# of events");
281 fHEvents->SetFillColor(kBlue+1);
282 fHEvents->SetFillStyle(3001);
283 fHEvents->SetDirectory(0);
284 fList->Add(fHEvents);
286 fHEventsTr = new TH1I(GetEventName(true, false),
287 "Number of triggered events",
291 fHEventsTr->SetXTitle("v_{z} [cm]");
292 fHEventsTr->SetYTitle("# of events");
293 fHEventsTr->SetFillColor(kRed+1);
294 fHEventsTr->SetFillStyle(3001);
295 fHEventsTr->SetDirectory(0);
296 fList->Add(fHEventsTr);
298 fHEventsTrVtx = new TH1I(GetEventName(true,true),
299 "Number of events w/trigger and vertex",
303 fHEventsTrVtx->SetXTitle("v_{z} [cm]");
304 fHEventsTrVtx->SetYTitle("# of events");
305 fHEventsTrVtx->SetFillColor(kBlue+1);
306 fHEventsTrVtx->SetFillStyle(3001);
307 fHEventsTrVtx->SetDirectory(0);
308 fList->Add(fHEventsTrVtx);
310 // Copy axis objects to output
311 TH1* vtxAxis = new TH1D("vtxAxis", "Vertex axis",
315 TH1* etaAxis = new TH1D("etaAxis", "Eta axis",
322 AliInfo(Form("Initialising sub-routines: %p, %p",
323 &fInspector, &fTrackDensity));
324 fInspector.DefineOutput(fList);
325 fTrackDensity.DefineOutput(fList);
329 //____________________________________________________________________
331 AliCentralMCCorrectionsTask::UserExec(Option_t*)
334 // Process each event
340 DGUARD(fDebug,1,"AliCentralMCCorrectionsTask process an event");
341 // Get the input data - MC event
342 AliMCEvent* mcEvent = MCEvent();
344 AliWarning("No MC event found");
348 // Get the input data - ESD event
349 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
351 AliWarning("No ESD event found for input event");
355 //--- Read run information -----------------------------------------
356 if (fFirstEvent && esd->GetESDRun()) {
357 fInspector.ReadRunDetails(esd);
359 AliInfo(Form("Initializing with parameters from the ESD:\n"
360 " AliESDEvent::GetBeamEnergy() ->%f\n"
361 " AliESDEvent::GetBeamType() ->%s\n"
362 " AliESDEvent::GetCurrentL3() ->%f\n"
363 " AliESDEvent::GetMagneticField()->%f\n"
364 " AliESDEvent::GetRunNumber() ->%d\n",
365 esd->GetBeamEnergy(),
368 esd->GetMagneticField(),
369 esd->GetRunNumber()));
371 fInspector.Init(fVtxAxis);
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 Double_t cMC; // Centrality estimate from b
387 Int_t nPart; // Number of participants
388 Int_t nBin; // Number of binary collisions
389 Double_t phiR; // Reaction plane from MC
390 UShort_t nClusters;// Number of SPD clusters
392 UInt_t retESD = fInspector.Process(esd, triggers, lowFlux, iVz, vZ,
394 fInspector.ProcessMC(mcEvent, triggers, iVzMc, vZMc,
395 b, cMC, nPart, nBin, phiR);
397 Bool_t isInel = triggers & AliAODForwardMult::kInel;
398 Bool_t hasVtx = retESD == AliFMDMCEventInspector::kOk;
400 // Fill the event count histograms
401 if (isInel) fHEventsTr->Fill(vZMc);
402 if (isInel && hasVtx) fHEventsTrVtx->Fill(vZMc);
403 fHEvents->Fill(vZMc);
405 // Now find our vertex bin object
407 if (iVzMc > 0 && iVzMc <= fVtxAxis.GetNbins())
408 bin = static_cast<VtxBin*>(fVtxBins->At(iVzMc));
410 // AliError(Form("No vertex bin object @ %d (%f)", iVzMc, vZMc));
414 // Now process our input data and store in own ESD object
415 fTrackDensity.Calculate(*mcEvent, vZMc, *bin->fHits, bin->fPrimary);
417 // Get the ESD object
418 const AliMultiplicity* spdmult = esd->GetMultiplicity();
420 // Count number of tracklets per bin
421 for(Int_t j = 0; j< spdmult->GetNumberOfTracklets();j++)
422 bin->fClusters->Fill(spdmult->GetEta(j),spdmult->GetPhi(j));
423 //...and then the unused clusters in layer 1
424 for(Int_t j = 0; j< spdmult->GetNumberOfSingleClusters();j++) {
425 Double_t eta = -TMath::Log(TMath::Tan(spdmult->GetThetaSingle(j)/2.));
426 bin->fClusters->Fill(eta, spdmult->GetPhiSingle(j));
430 bin->fCounts->Fill(0.5);
435 //____________________________________________________________________
437 AliCentralMCCorrectionsTask::Terminate(Option_t*)
445 DGUARD(fDebug,1,"AliCentralMCCorrectionsTask analyse merged output");
447 fList = dynamic_cast<TList*>(GetOutputData(1));
449 AliError("No output list defined");
456 TList* output = new TList;
458 output->SetName(Form("%sResults", GetName()));
460 // --- Fill correction object --------------------------------------
461 AliCentralCorrSecondaryMap* corr = new AliCentralCorrSecondaryMap;
462 corr->SetVertexAxis(fVtxAxis);
463 // corr->SetEtaAxis(fEtaAxis);
465 AliCentralCorrAcceptance* acorr = new AliCentralCorrAcceptance;
466 acorr->SetVertexAxis(fVtxAxis);
468 TIter next(fVtxBins);
471 while ((bin = static_cast<VtxBin*>(next())))
472 bin->Finish(fList, output, iVz++, fEffectiveCorr, corr,acorr);
480 //____________________________________________________________________
482 AliCentralMCCorrectionsTask::Print(Option_t* option) const
484 std::cout << ClassName() << "\n"
485 << " Vertex bins: " << fVtxAxis.GetNbins() << '\n'
486 << " Vertex range: [" << fVtxAxis.GetXmin()
487 << "," << fVtxAxis.GetXmax() << "]\n"
488 << " Eta bins: " << fEtaAxis.GetNbins() << '\n'
489 << " Eta range: [" << fEtaAxis.GetXmin()
490 << "," << fEtaAxis.GetXmax() << "]\n"
491 << " # of phi bins: " << fNPhiBins
493 gROOT->IncreaseDirLevel();
494 fInspector.Print(option);
495 fTrackDensity.Print(option);
496 gROOT->DecreaseDirLevel();
499 //====================================================================
501 AliCentralMCCorrectionsTask::VtxBin::BinName(Double_t low,
505 buf = Form("vtx%+05.1f_%+05.1f", low, high);
506 buf.ReplaceAll("+", "p");
507 buf.ReplaceAll("-", "m");
508 buf.ReplaceAll(".", "d");
513 //____________________________________________________________________
514 AliCentralMCCorrectionsTask::VtxBin::VtxBin()
521 //____________________________________________________________________
522 AliCentralMCCorrectionsTask::VtxBin::VtxBin(Double_t low,
526 : TNamed(BinName(low, high),
527 Form("%+5.1fcm<v_{z}<%+5.1fcm", low, high)),
533 fPrimary = new TH2D("primary", "Primaries",
534 axis.GetNbins(), axis.GetXmin(), axis.GetXmax(),
535 nPhi, 0, 2*TMath::Pi());
536 fPrimary->SetXTitle("#eta");
537 fPrimary->SetYTitle("#varphi [radians]");
539 fPrimary->SetDirectory(0);
541 fHits = static_cast<TH2D*>(fPrimary->Clone("hits"));
542 fHits->SetTitle("Hits");
543 fHits->SetDirectory(0);
545 fClusters = static_cast<TH2D*>(fPrimary->Clone("clusters"));
546 fClusters->SetTitle("Clusters");
547 fClusters->SetDirectory(0);
549 fCounts = new TH1D("counts", "Counts", 1, 0, 1);
550 fCounts->SetXTitle("Events");
551 fCounts->SetYTitle("# of Events");
552 fCounts->SetDirectory(0);
555 //____________________________________________________________________
556 AliCentralMCCorrectionsTask::VtxBin::VtxBin(const VtxBin& o)
564 fHits = static_cast<TH2D*>(o.fHits->Clone());
565 fHits->SetDirectory(0);
568 fClusters = static_cast<TH2D*>(o.fClusters->Clone());
569 fClusters->SetDirectory(0);
572 fPrimary = static_cast<TH2D*>(o.fPrimary->Clone());
573 fPrimary->SetDirectory(0);
576 fCounts = static_cast<TH1D*>(o.fCounts->Clone());
577 fCounts->SetDirectory(0);
581 //____________________________________________________________________
582 AliCentralMCCorrectionsTask::VtxBin&
583 AliCentralMCCorrectionsTask::VtxBin::operator=(const VtxBin& o)
585 if (&o == this) return *this;
586 TNamed::operator=(o);
592 fHits = static_cast<TH2D*>(o.fHits->Clone());
593 fHits->SetDirectory(0);
596 fClusters = static_cast<TH2D*>(o.fClusters->Clone());
597 fClusters->SetDirectory(0);
600 fPrimary = static_cast<TH2D*>(o.fPrimary->Clone());
601 fPrimary->SetDirectory(0);
604 fCounts = static_cast<TH1D*>(o.fCounts->Clone());
605 fCounts->SetDirectory(0);
610 //____________________________________________________________________
612 AliCentralMCCorrectionsTask::VtxBin::DefineOutput(TList* l)
614 TList* d = new TList;
615 d->SetName(GetName());
624 //____________________________________________________________________
626 AliCentralMCCorrectionsTask::VtxBin::Finish(const TList* input,
629 Bool_t effectiveCorr,
630 AliCentralCorrSecondaryMap* map,
631 AliCentralCorrAcceptance* acorr)
633 TList* out = new TList;
634 out->SetName(GetName());
638 TList* l = static_cast<TList*>(input->FindObject(GetName()));
640 AliError(Form("List %s not found in %s", GetName(), input->GetName()));
645 TH2D* hits = static_cast<TH2D*>(l->FindObject("hits"));
646 TH2D* clus = static_cast<TH2D*>(l->FindObject("clusters"));
647 TH2D* prim = static_cast<TH2D*>(l->FindObject("primary"));
648 if (!hits || !prim) {
649 AliError(Form("Missing histograms: %p, %p", hits, prim));
654 if (effectiveCorr) h = static_cast<TH2D*>(clus->Clone("bgCorr"));
655 else h = static_cast<TH2D*>(hits->Clone("bgCorr"));
659 TH1D* acc = new TH1D(Form("SPDacc_vrtbin_%d",iVz),
660 "Acceptance correction for SPD" ,
661 fPrimary->GetXaxis()->GetNbins(),
662 fPrimary->GetXaxis()->GetXmin(),
663 fPrimary->GetXaxis()->GetXmax());
664 TH1F* accden = static_cast<TH1F*>(acc->Clone(Form("%s_den",
667 for(Int_t xx = 1; xx <=h->GetNbinsX(); xx++) {
668 for(Int_t yy = 1; yy <=h->GetNbinsY(); yy++) {
669 if(TMath::Abs(h->GetXaxis()->GetBinCenter(xx)) > 1.9) {
670 h->SetBinContent(xx,yy,0.);
671 h->SetBinError(xx,yy,0.);
673 if(h->GetBinContent(xx,yy) > 0.9)
674 acc->Fill(h->GetXaxis()->GetBinCenter(xx));
676 h->SetBinContent(xx,yy,0.);
677 h->SetBinError(xx,yy,0.);
679 accden->Fill(h->GetXaxis()->GetBinCenter(xx));
685 map->SetCorrection(iVz, h);
686 acorr->SetCorrection(iVz, acc);