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 fInspector.Init(fVtxAxis);
326 fTrackDensity.DefineOutput(fList);
330 //____________________________________________________________________
332 AliCentralMCCorrectionsTask::UserExec(Option_t*)
335 // Process each event
341 DGUARD(fDebug,1,"AliCentralMCCorrectionsTask process an event");
342 // Get the input data - MC event
343 AliMCEvent* mcEvent = MCEvent();
345 AliWarning("No MC event found");
349 // Get the input data - ESD event
350 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
352 AliWarning("No ESD event found for input event");
356 //--- Read run information -----------------------------------------
357 if (fFirstEvent && esd->GetESDRun()) {
358 fInspector.ReadRunDetails(esd);
360 AliInfo(Form("Initializing with parameters from the ESD:\n"
361 " AliESDEvent::GetBeamEnergy() ->%f\n"
362 " AliESDEvent::GetBeamType() ->%s\n"
363 " AliESDEvent::GetCurrentL3() ->%f\n"
364 " AliESDEvent::GetMagneticField()->%f\n"
365 " AliESDEvent::GetRunNumber() ->%d\n",
366 esd->GetBeamEnergy(),
369 esd->GetMagneticField(),
370 esd->GetRunNumber()));
377 UInt_t triggers; // Trigger bits
378 Bool_t lowFlux; // Low flux flag
379 UShort_t iVz; // Vertex bin from ESD
380 Double_t vZ; // Z coordinate from ESD
381 Double_t cent; // Centrality
382 UShort_t iVzMc; // Vertex bin from MC
383 Double_t vZMc; // Z coordinate of IP vertex from MC
384 Double_t b; // Impact parameter
385 Double_t cMC; // Centrality estimate from b
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, cMC, 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 // Now process our input data and store in own ESD object
414 fTrackDensity.Calculate(*mcEvent, vZMc, *bin->fHits, bin->fPrimary);
416 // Get the ESD object
417 const AliMultiplicity* spdmult = esd->GetMultiplicity();
419 // Count number of tracklets per bin
420 for(Int_t j = 0; j< spdmult->GetNumberOfTracklets();j++)
421 bin->fClusters->Fill(spdmult->GetEta(j),spdmult->GetPhi(j));
422 //...and then the unused clusters in layer 1
423 for(Int_t j = 0; j< spdmult->GetNumberOfSingleClusters();j++) {
424 Double_t eta = -TMath::Log(TMath::Tan(spdmult->GetThetaSingle(j)/2.));
425 bin->fClusters->Fill(eta, spdmult->GetPhiSingle(j));
429 bin->fCounts->Fill(0.5);
434 //____________________________________________________________________
436 AliCentralMCCorrectionsTask::Terminate(Option_t*)
444 DGUARD(fDebug,1,"AliCentralMCCorrectionsTask analyse merged output");
446 fList = dynamic_cast<TList*>(GetOutputData(1));
448 AliError("No output list defined");
455 TList* output = new TList;
457 output->SetName(Form("%sResults", GetName()));
459 // --- Fill correction object --------------------------------------
460 AliCentralCorrSecondaryMap* corr = new AliCentralCorrSecondaryMap;
461 corr->SetVertexAxis(fVtxAxis);
462 // corr->SetEtaAxis(fEtaAxis);
464 AliCentralCorrAcceptance* acorr = new AliCentralCorrAcceptance;
465 acorr->SetVertexAxis(fVtxAxis);
467 TIter next(fVtxBins);
470 while ((bin = static_cast<VtxBin*>(next())))
471 bin->Finish(fList, output, iVz++, fEffectiveCorr, corr,acorr);
479 //____________________________________________________________________
481 AliCentralMCCorrectionsTask::Print(Option_t* option) const
483 std::cout << ClassName() << "\n"
484 << " Vertex bins: " << fVtxAxis.GetNbins() << '\n'
485 << " Vertex range: [" << fVtxAxis.GetXmin()
486 << "," << fVtxAxis.GetXmax() << "]\n"
487 << " Eta bins: " << fEtaAxis.GetNbins() << '\n'
488 << " Eta range: [" << fEtaAxis.GetXmin()
489 << "," << fEtaAxis.GetXmax() << "]\n"
490 << " # of phi bins: " << fNPhiBins
492 gROOT->IncreaseDirLevel();
493 fInspector.Print(option);
494 fTrackDensity.Print(option);
495 gROOT->DecreaseDirLevel();
498 //====================================================================
500 AliCentralMCCorrectionsTask::VtxBin::BinName(Double_t low,
504 buf = Form("vtx%+05.1f_%+05.1f", low, high);
505 buf.ReplaceAll("+", "p");
506 buf.ReplaceAll("-", "m");
507 buf.ReplaceAll(".", "d");
512 //____________________________________________________________________
513 AliCentralMCCorrectionsTask::VtxBin::VtxBin()
520 //____________________________________________________________________
521 AliCentralMCCorrectionsTask::VtxBin::VtxBin(Double_t low,
525 : TNamed(BinName(low, high),
526 Form("%+5.1fcm<v_{z}<%+5.1fcm", low, high)),
532 fPrimary = new TH2D("primary", "Primaries",
533 axis.GetNbins(), axis.GetXmin(), axis.GetXmax(),
534 nPhi, 0, 2*TMath::Pi());
535 fPrimary->SetXTitle("#eta");
536 fPrimary->SetYTitle("#varphi [radians]");
538 fPrimary->SetDirectory(0);
540 fHits = static_cast<TH2D*>(fPrimary->Clone("hits"));
541 fHits->SetTitle("Hits");
542 fHits->SetDirectory(0);
544 fClusters = static_cast<TH2D*>(fPrimary->Clone("clusters"));
545 fClusters->SetTitle("Clusters");
546 fClusters->SetDirectory(0);
548 fCounts = new TH1D("counts", "Counts", 1, 0, 1);
549 fCounts->SetXTitle("Events");
550 fCounts->SetYTitle("# of Events");
551 fCounts->SetDirectory(0);
554 //____________________________________________________________________
555 AliCentralMCCorrectionsTask::VtxBin::VtxBin(const VtxBin& o)
563 fHits = static_cast<TH2D*>(o.fHits->Clone());
564 fHits->SetDirectory(0);
567 fClusters = static_cast<TH2D*>(o.fClusters->Clone());
568 fClusters->SetDirectory(0);
571 fPrimary = static_cast<TH2D*>(o.fPrimary->Clone());
572 fPrimary->SetDirectory(0);
575 fCounts = static_cast<TH1D*>(o.fCounts->Clone());
576 fCounts->SetDirectory(0);
580 //____________________________________________________________________
581 AliCentralMCCorrectionsTask::VtxBin&
582 AliCentralMCCorrectionsTask::VtxBin::operator=(const VtxBin& o)
584 if (&o == this) return *this;
585 TNamed::operator=(o);
591 fHits = static_cast<TH2D*>(o.fHits->Clone());
592 fHits->SetDirectory(0);
595 fClusters = static_cast<TH2D*>(o.fClusters->Clone());
596 fClusters->SetDirectory(0);
599 fPrimary = static_cast<TH2D*>(o.fPrimary->Clone());
600 fPrimary->SetDirectory(0);
603 fCounts = static_cast<TH1D*>(o.fCounts->Clone());
604 fCounts->SetDirectory(0);
609 //____________________________________________________________________
611 AliCentralMCCorrectionsTask::VtxBin::DefineOutput(TList* l)
613 TList* d = new TList;
614 d->SetName(GetName());
623 //____________________________________________________________________
625 AliCentralMCCorrectionsTask::VtxBin::Finish(const TList* input,
628 Bool_t effectiveCorr,
629 AliCentralCorrSecondaryMap* map,
630 AliCentralCorrAcceptance* acorr)
632 TList* out = new TList;
633 out->SetName(GetName());
637 TList* l = static_cast<TList*>(input->FindObject(GetName()));
639 AliError(Form("List %s not found in %s", GetName(), input->GetName()));
644 TH2D* hits = static_cast<TH2D*>(l->FindObject("hits"));
645 TH2D* clus = static_cast<TH2D*>(l->FindObject("clusters"));
646 TH2D* prim = static_cast<TH2D*>(l->FindObject("primary"));
647 if (!hits || !prim) {
648 AliError(Form("Missing histograms: %p, %p", hits, prim));
653 if (effectiveCorr) h = static_cast<TH2D*>(clus->Clone("bgCorr"));
654 else h = static_cast<TH2D*>(hits->Clone("bgCorr"));
658 TH1D* acc = new TH1D(Form("SPDacc_vrtbin_%d",iVz),
659 "Acceptance correction for SPD" ,
660 fPrimary->GetXaxis()->GetNbins(),
661 fPrimary->GetXaxis()->GetXmin(),
662 fPrimary->GetXaxis()->GetXmax());
663 TH1F* accden = static_cast<TH1F*>(acc->Clone(Form("%s_den",
666 for(Int_t xx = 1; xx <=h->GetNbinsX(); xx++) {
667 for(Int_t yy = 1; yy <=h->GetNbinsY(); yy++) {
668 if(TMath::Abs(h->GetXaxis()->GetBinCenter(xx)) > 1.9) {
669 h->SetBinContent(xx,yy,0.);
670 h->SetBinError(xx,yy,0.);
672 if(h->GetBinContent(xx,yy) > 0.9)
673 acc->Fill(h->GetXaxis()->GetBinCenter(xx));
675 h->SetBinContent(xx,yy,0.);
676 h->SetBinError(xx,yy,0.);
678 accden->Fill(h->GetXaxis()->GetBinCenter(xx));
684 map->SetCorrection(iVz, h);
685 acorr->SetCorrection(iVz, acc);