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(),
70 DGUARD(fDebug, 3,"Default CTOR of AliCentralMCCorrectionsTask");
73 //____________________________________________________________________
74 AliCentralMCCorrectionsTask::AliCentralMCCorrectionsTask(const char* name)
75 : AliAnalysisTaskSE(name),
76 fInspector("eventInspector"),
77 fTrackDensity("trackDensity"),
97 DGUARD(fDebug, 3,"Named CTOR of AliCentralMCCorrectionsTask: %s",name);
98 DefineOutput(1, TList::Class());
99 DefineOutput(2, TList::Class());
101 "ESD:AliESDRun.,AliESDHeader.,AliMultiplicity.,"
102 "SPDVertex.,PrimaryVertex.";
105 //____________________________________________________________________
106 AliCentralMCCorrectionsTask::AliCentralMCCorrectionsTask(const AliCentralMCCorrectionsTask& o)
107 : AliAnalysisTaskSE(o),
108 fInspector(o.fInspector),
111 fFirstEvent(o.fFirstEvent),
112 fHEvents(o.fHEvents),
113 fHEventsTr(o.fHEventsTr),
114 fHEventsTrVtx(o.fHEventsTrVtx),
118 fNPhiBins(o.fNPhiBins),
119 fEffectiveCorr(o.fEffectiveCorr),
127 // o Object to copy from
129 DGUARD(fDebug, 3,"Copy CTOR of AliCentralMCCorrectionsTask");
132 //____________________________________________________________________
133 AliCentralMCCorrectionsTask&
134 AliCentralMCCorrectionsTask::operator=(const AliCentralMCCorrectionsTask& o)
137 // Assignment operator
140 // o Object to assign from
143 // Reference to this object
145 DGUARD(fDebug,3,"Assignment of AliCentralMCCorrectionsTask");
146 if (&o == this) return *this;
147 fInspector = o.fInspector;
148 fTrackDensity = o.fTrackDensity;
149 fVtxBins = o.fVtxBins;
150 fFirstEvent = o.fFirstEvent;
151 fHEvents = o.fHEvents;
152 fHEventsTr = o.fHEventsTr;
153 fHEventsTrVtx = o.fHEventsTrVtx;
154 SetVertexAxis(o.fVtxAxis);
155 SetEtaAxis(o.fEtaAxis);
156 fNPhiBins = o.fNPhiBins;
157 fEffectiveCorr = o.fEffectiveCorr;
159 fCorrCut = o.fCorrCut;
164 //____________________________________________________________________
166 AliCentralMCCorrectionsTask::Init()
169 // Initialize the task
172 DGUARD(fDebug,1,"Initialize AliCentralMCCorrectionsTask");
175 //____________________________________________________________________
177 AliCentralMCCorrectionsTask::SetVertexAxis(Int_t nBin, Double_t min,
181 // Set the vertex axis to use
184 // nBins Number of bins
185 // vzMin Least @f$z@f$ coordinate of interation point
186 // vzMax Largest @f$z@f$ coordinate of interation point
188 DGUARD(fDebug,3,"Set vertex axis AliCentralMCCorrectionsTask [%d,%f,%f]",
196 AliWarning(Form("Minimum vertex %f < -10, make sure you want this",min));
198 AliWarning(Form("Minimum vertex %f > +10, make sure you want this",max));
199 fVtxAxis.Set(nBin, min, max);
201 //____________________________________________________________________
203 AliCentralMCCorrectionsTask::SetVertexAxis(const TAxis& axis)
206 // Set the vertex axis to use
211 SetVertexAxis(axis.GetNbins(),axis.GetXmin(),axis.GetXmax());
214 //____________________________________________________________________
216 AliCentralMCCorrectionsTask::SetEtaAxis(Int_t nBin, Double_t min, Double_t max)
219 // Set the eta axis to use
222 // nBins Number of bins
223 // vzMin Least @f$\eta@f$
224 // vzMax Largest @f$\eta@f$
226 DGUARD(fDebug,3,"Set eta axis AliCentralMCCorrectionsTask [%d,%f,%f]",
234 AliWarning(Form("Minimum eta %f < -4, make sure you want this",min));
236 AliWarning(Form("Minimum eta %f > +6, make sure you want this",max));
237 fEtaAxis.Set(nBin, min, max);
239 //____________________________________________________________________
241 AliCentralMCCorrectionsTask::SetEtaAxis(const TAxis& axis)
244 // Set the eta axis to use
249 SetEtaAxis(axis.GetNbins(),axis.GetXmin(),axis.GetXmax());
252 //____________________________________________________________________
254 AliCentralMCCorrectionsTask::DefineBins(TList* l)
256 DGUARD(fDebug,1,"Define bins in AliCentralMCCorrectionsTask");
257 if (!fVtxBins) fVtxBins = new TObjArray(fVtxAxis.GetNbins(), 1);
258 if (fVtxBins->GetEntries() > 0) return;
260 fVtxBins->SetOwner();
261 for (Int_t i = 1; i <= fVtxAxis.GetNbins(); i++) {
262 Double_t low = fVtxAxis.GetBinLowEdge(i);
263 Double_t high = fVtxAxis.GetBinUpEdge(i);
264 VtxBin* bin = new VtxBin(low, high, fEtaAxis, fNPhiBins);
265 fVtxBins->AddAt(bin, i);
266 bin->CreateOutputObjects(l);
270 //____________________________________________________________________
272 AliCentralMCCorrectionsTask::UserCreateOutputObjects()
275 // Create output objects
278 DGUARD(fDebug,1,"Create user output for AliCentralMCCorrectionsTask");
281 fList->SetName(Form("%sSums", GetName()));
285 fHEvents = new TH1I(GetEventName(false,false),
286 "Number of all events",
290 fHEvents->SetXTitle("v_{z} [cm]");
291 fHEvents->SetYTitle("# of events");
292 fHEvents->SetFillColor(kBlue+1);
293 fHEvents->SetFillStyle(3001);
294 fHEvents->SetDirectory(0);
295 fList->Add(fHEvents);
297 fHEventsTr = new TH1I(GetEventName(true, false),
298 "Number of triggered events",
302 fHEventsTr->SetXTitle("v_{z} [cm]");
303 fHEventsTr->SetYTitle("# of events");
304 fHEventsTr->SetFillColor(kRed+1);
305 fHEventsTr->SetFillStyle(3001);
306 fHEventsTr->SetDirectory(0);
307 fList->Add(fHEventsTr);
309 fHEventsTrVtx = new TH1I(GetEventName(true,true),
310 "Number of events w/trigger and vertex",
314 fHEventsTrVtx->SetXTitle("v_{z} [cm]");
315 fHEventsTrVtx->SetYTitle("# of events");
316 fHEventsTrVtx->SetFillColor(kBlue+1);
317 fHEventsTrVtx->SetFillStyle(3001);
318 fHEventsTrVtx->SetDirectory(0);
319 fList->Add(fHEventsTrVtx);
321 // Copy axis objects to output
322 TH1* vtxAxis = new TH1D("vtxAxis", "Vertex axis",
326 TH1* etaAxis = new TH1D("etaAxis", "Eta axis",
333 fList->Add(AliForwardUtil::MakeParameter("effective", fEffectiveCorr));
334 fList->Add(AliForwardUtil::MakeParameter("maxEta", fEtaCut));
335 fList->Add(AliForwardUtil::MakeParameter("accCut", fCorrCut));
337 AliInfo(Form("Initialising sub-routines: %p, %p",
338 &fInspector, &fTrackDensity));
339 fInspector.CreateOutputObjects(fList);
340 fTrackDensity.CreateOutputObjects(fList);
344 //____________________________________________________________________
346 AliCentralMCCorrectionsTask::UserExec(Option_t*)
349 // Process each event
355 DGUARD(fDebug,1,"AliCentralMCCorrectionsTask process an event");
356 // Get the input data - MC event
357 AliMCEvent* mcEvent = MCEvent();
359 AliWarning("No MC event found");
363 // Get the input data - ESD event
364 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
366 AliWarning("No ESD event found for input event");
370 //--- Read run information -----------------------------------------
371 if (fFirstEvent && esd->GetESDRun()) {
372 fInspector.ReadRunDetails(esd);
374 AliInfo(Form("Initializing with parameters from the ESD:\n"
375 " AliESDEvent::GetBeamEnergy() ->%f\n"
376 " AliESDEvent::GetBeamType() ->%s\n"
377 " AliESDEvent::GetCurrentL3() ->%f\n"
378 " AliESDEvent::GetMagneticField()->%f\n"
379 " AliESDEvent::GetRunNumber() ->%d\n",
380 esd->GetBeamEnergy(),
383 esd->GetMagneticField(),
384 esd->GetRunNumber()));
386 fInspector.SetupForData(fVtxAxis);
393 UInt_t triggers = 0; // Trigger bits
394 Bool_t lowFlux = true; // Low flux flag
395 UShort_t iVz = 0; // Vertex bin from ESD
396 TVector3 ip; // Z coordinate from ESD
397 Double_t cent = -1; // Centrality
398 UShort_t iVzMc = 0; // Vertex bin from MC
399 Double_t vZMc = 1000; // Z coordinate of IP vertex from MC
400 Double_t b = -1; // Impact parameter
401 Double_t cMC = -1; // Centrality estimate from b
402 Int_t nPart = -1; // Number of participants
403 Int_t nBin = -1; // Number of binary collisions
404 Double_t phiR = 1000; // Reaction plane from MC
405 UShort_t nClusters = 0; // Number of SPD clusters
407 UInt_t retESD = fInspector.Process(esd, triggers, lowFlux, iVz, ip,
409 fInspector.ProcessMC(mcEvent, triggers, iVzMc, vZMc,
410 b, cMC, nPart, nBin, phiR);
412 Bool_t isInel = triggers & AliAODForwardMult::kInel;
413 Bool_t hasVtx = retESD == AliFMDMCEventInspector::kOk;
415 // Fill the event count histograms
416 if (isInel) fHEventsTr->Fill(vZMc);
417 if (isInel && hasVtx) fHEventsTrVtx->Fill(vZMc);
418 fHEvents->Fill(vZMc);
420 // Now find our vertex bin object
422 if (iVzMc > 0 && iVzMc <= fVtxAxis.GetNbins())
423 bin = static_cast<VtxBin*>(fVtxBins->At(iVzMc));
425 // AliError(Form("No vertex bin object @ %d (%f)", iVzMc, vZMc));
429 // Now process our input data and store in own ESD object
430 fTrackDensity.Calculate(*mcEvent, vZMc, *bin->fHits, bin->fPrimary);
432 // Get the ESD object
433 const AliMultiplicity* spdmult = esd->GetMultiplicity();
435 // Count number of tracklets per bin
436 for(Int_t j = 0; j< spdmult->GetNumberOfTracklets();j++)
437 bin->fClusters->Fill(spdmult->GetEta(j),spdmult->GetPhi(j));
438 //...and then the unused clusters in layer 1
439 for(Int_t j = 0; j< spdmult->GetNumberOfSingleClusters();j++) {
440 Double_t eta = -TMath::Log(TMath::Tan(spdmult->GetThetaSingle(j)/2.));
441 bin->fClusters->Fill(eta, spdmult->GetPhiSingle(j));
445 bin->fCounts->Fill(0.5);
450 //____________________________________________________________________
452 AliCentralMCCorrectionsTask::Terminate(Option_t*)
460 DGUARD(fDebug,1,"AliCentralMCCorrectionsTask analyse merged output");
462 fList = dynamic_cast<TList*>(GetOutputData(1));
464 AliError("No output list defined");
471 TList* output = new TList;
473 output->SetName(Form("%sResults", GetName()));
475 // --- Fill correction object --------------------------------------
476 AliCentralCorrSecondaryMap* corr = new AliCentralCorrSecondaryMap;
477 corr->SetVertexAxis(fVtxAxis);
478 // corr->SetEtaAxis(fEtaAxis);
480 AliCentralCorrAcceptance* acorr = new AliCentralCorrAcceptance;
481 acorr->SetVertexAxis(fVtxAxis);
483 TIter next(fVtxBins);
486 while ((bin = static_cast<VtxBin*>(next())))
487 bin->Terminate(fList, output, iVz++, fEffectiveCorr,
488 fEtaCut, fCorrCut, corr,acorr);
496 //____________________________________________________________________
498 AliCentralMCCorrectionsTask::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() << "]\n"
507 << " # of phi bins: " << fNPhiBins << "\n"
508 << " Effective corr.: " << fEffectiveCorr << "\n"
509 << " Eta cut-off: " << fEtaCut << "\n"
510 << " Acceptance cut: " << fCorrCut
512 gROOT->IncreaseDirLevel();
513 fInspector.Print(option);
514 fTrackDensity.Print(option);
515 gROOT->DecreaseDirLevel();
518 //====================================================================
520 AliCentralMCCorrectionsTask::VtxBin::BinName(Double_t low,
524 buf = Form("vtx%+05.1f_%+05.1f", low, high);
525 buf.ReplaceAll("+", "p");
526 buf.ReplaceAll("-", "m");
527 buf.ReplaceAll(".", "d");
532 //____________________________________________________________________
533 AliCentralMCCorrectionsTask::VtxBin::VtxBin()
540 //____________________________________________________________________
541 AliCentralMCCorrectionsTask::VtxBin::VtxBin(Double_t low,
545 : TNamed(BinName(low, high),
546 Form("%+5.1fcm<v_{z}<%+5.1fcm", low, high)),
552 fPrimary = new TH2D("primary", "Primaries",
553 axis.GetNbins(), axis.GetXmin(), axis.GetXmax(),
554 nPhi, 0, 2*TMath::Pi());
555 fPrimary->SetXTitle("#eta");
556 fPrimary->SetYTitle("#varphi [radians]");
558 fPrimary->SetDirectory(0);
560 fHits = static_cast<TH2D*>(fPrimary->Clone("hits"));
561 fHits->SetTitle("Hits");
562 fHits->SetDirectory(0);
564 fClusters = static_cast<TH2D*>(fPrimary->Clone("clusters"));
565 fClusters->SetTitle("Clusters");
566 fClusters->SetDirectory(0);
568 fCounts = new TH1D("counts", "Counts", 1, 0, 1);
569 fCounts->SetXTitle("Events");
570 fCounts->SetYTitle("# of Events");
571 fCounts->SetDirectory(0);
574 //____________________________________________________________________
575 AliCentralMCCorrectionsTask::VtxBin::VtxBin(const VtxBin& o)
583 fHits = static_cast<TH2D*>(o.fHits->Clone());
584 fHits->SetDirectory(0);
587 fClusters = static_cast<TH2D*>(o.fClusters->Clone());
588 fClusters->SetDirectory(0);
591 fPrimary = static_cast<TH2D*>(o.fPrimary->Clone());
592 fPrimary->SetDirectory(0);
595 fCounts = static_cast<TH1D*>(o.fCounts->Clone());
596 fCounts->SetDirectory(0);
600 //____________________________________________________________________
601 AliCentralMCCorrectionsTask::VtxBin&
602 AliCentralMCCorrectionsTask::VtxBin::operator=(const VtxBin& o)
604 if (&o == this) return *this;
605 TNamed::operator=(o);
611 fHits = static_cast<TH2D*>(o.fHits->Clone());
612 fHits->SetDirectory(0);
615 fClusters = static_cast<TH2D*>(o.fClusters->Clone());
616 fClusters->SetDirectory(0);
619 fPrimary = static_cast<TH2D*>(o.fPrimary->Clone());
620 fPrimary->SetDirectory(0);
623 fCounts = static_cast<TH1D*>(o.fCounts->Clone());
624 fCounts->SetDirectory(0);
629 //____________________________________________________________________
631 AliCentralMCCorrectionsTask::VtxBin::CreateOutputObjects(TList* l)
633 TList* d = new TList;
634 d->SetName(GetName());
643 //____________________________________________________________________
645 AliCentralMCCorrectionsTask::VtxBin::Terminate(const TList* input,
648 Bool_t effectiveCorr,
651 AliCentralCorrSecondaryMap* map,
652 AliCentralCorrAcceptance* acorr)
654 TList* out = new TList;
655 out->SetName(GetName());
659 TList* l = static_cast<TList*>(input->FindObject(GetName()));
661 AliError(Form("List %s not found in %s", GetName(), input->GetName()));
666 TH2D* hits = static_cast<TH2D*>(l->FindObject("hits"));
667 TH2D* clus = static_cast<TH2D*>(l->FindObject("clusters"));
668 TH2D* prim = static_cast<TH2D*>(l->FindObject("primary"));
669 if (!hits || !prim) {
670 AliError(Form("Missing histograms: %p, %p", hits, prim));
674 // Clone cluster and hit map
675 TH2D* secMapEff = static_cast<TH2D*>(clus->Clone("secMapEff"));
676 TH2D* secMapHit = static_cast<TH2D*>(hits->Clone("secMapHit"));
677 secMapEff->SetTitle("2^{nd} map from clusters");
678 secMapEff->SetDirectory(0);
679 secMapHit->SetTitle("2^{nd} map from MC hits");
680 secMapHit->SetDirectory(0);
682 // Divide cluster and hit map with number of primaries
683 secMapEff->Divide(prim);
684 secMapHit->Divide(prim);
686 // Create acceptance histograms
687 TH1D* accEff = new TH1D("accEff",
688 "Acceptance correction for SPD (from 2^{nd} map)" ,
689 fPrimary->GetXaxis()->GetNbins(),
690 fPrimary->GetXaxis()->GetXmin(),
691 fPrimary->GetXaxis()->GetXmax());
692 TH1D* accHit = static_cast<TH1D*>(accEff->Clone("accHit"));
693 accHit->SetTitle("Acceptance correction for SPD (from clusters)");
695 // Diagnostics histogra,
696 TH2* dia = static_cast<TH2D*>(clus->Clone("diagnostics"));
697 dia->SetTitle("Scaled cluster density");
699 // Total number of channels along phi and # of eta bins
700 Int_t nTotal = secMapHit->GetNbinsY();
701 Int_t nEta = secMapHit->GetNbinsX();
703 for(Int_t xx = 1; xx <= nEta; xx++) {
704 Double_t eta = secMapHit->GetXaxis()->GetBinCenter(xx);
705 Bool_t ins = TMath::Abs(eta) <= etaCut;
708 // Find the maximum cluster signal in this phi range
709 for (Int_t yy = 1; yy <= nTotal; yy++) {
710 Double_t c = clus->GetBinContent(xx,yy);
711 mm = TMath::Max(mm, c);
714 // Count number of phi bins with enough clusters or high enough
718 for(Int_t yy = 1; yy <=nTotal; yy++) {
719 if (!ins) { // Not inside Eta cut
720 secMapEff->SetBinContent(xx,yy,0.);
721 secMapEff->SetBinError(xx,yy,0.);
722 secMapHit->SetBinContent(xx,yy,0.);
723 secMapHit->SetBinError(xx,yy,0.);
724 dia->SetBinContent(xx,yy,0);
728 // Check if the background correction is large enough, or zero map
729 if(secMapEff->GetBinContent(xx,yy) > 0.9) {
730 // acc->Fill(h->GetXaxis()->GetBinCenter(xx));
734 secMapEff->SetBinContent(xx,yy,0.);
735 secMapEff->SetBinError(xx,yy,0.);
738 // Check if the number of cluster is large enough, or zero map
739 Double_t c = clus->GetBinContent(xx,yy);
740 Double_t s = (mm < 1e-6) ? 0 : c / mm;
741 dia->SetBinContent(xx,yy,s);
746 secMapHit->SetBinContent(xx,yy,0);
747 secMapHit->SetBinError(xx,yy,0);
751 // Calculate acceptance as ratio of bins with enough clusters and
752 // total number of phi bins.
753 Double_t accXX = float(nOKHit) / nTotal;
754 if (accXX < 0.2) accXX = 0;
755 accHit->SetBinContent(xx, accXX);
757 // Calculate acceptance as ratio of bins with large enough
758 // correction and total number of phi bins.
759 accXX = float(nOKEff) / nTotal;
760 if (accXX < 0.2) accXX = 0;
761 accEff->SetBinContent(xx, accXX);
764 TH2D* secMap = (effectiveCorr ? secMapEff : secMapHit);
765 TH2D* secMapAlt = (effectiveCorr ? secMapHit : secMapEff);
766 TH1D* acc = (effectiveCorr ? accEff : accHit);
767 TH1D* accAlt = (effectiveCorr ? accHit : accEff);
768 out->Add(secMap->Clone("secMap"));
769 out->Add(secMapAlt->Clone());
770 out->Add(acc->Clone("acc"));
771 out->Add(accAlt->Clone());
772 out->Add(dia->Clone());
774 map->SetCorrection(iVz, secMap);
775 acorr->SetCorrection(iVz, acc);