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"
30 #include <TDirectory.h>
35 //====================================================================
37 const char* GetEventName(Bool_t tr, Bool_t vtx)
39 return Form("nEvents%s%s", (tr ? "Tr" : ""), (vtx ? "Vtx" : ""));
41 /*const char* GetHitsName(UShort_t d, Char_t r)
43 return Form("hitsSPD%d%c", d, r);
45 const char* GetStripsName(UShort_t d, Char_t r)
47 return Form("stripsSPD%d%c", d, r);
49 const char* GetPrimaryName(Char_t r, Bool_t trVtx)
51 return Form("primaries%s%s",
52 ((r == 'I' || r == 'i') ? "Inner" : "Outer"),
53 (trVtx ? "TrVtx" : "All"));
58 //====================================================================
59 AliCentralMCCorrectionsTask::AliCentralMCCorrectionsTask()
60 : AliAnalysisTaskSE(),
81 //____________________________________________________________________
82 AliCentralMCCorrectionsTask::AliCentralMCCorrectionsTask(const char* name)
83 : AliAnalysisTaskSE(name),
84 fInspector("eventInspector"),
85 fTrackDensity("trackDensity"),
102 DefineOutput(1, TList::Class());
103 DefineOutput(2, TList::Class());
106 //____________________________________________________________________
107 AliCentralMCCorrectionsTask::AliCentralMCCorrectionsTask(const AliCentralMCCorrectionsTask& o)
108 : AliAnalysisTaskSE(o),
109 fInspector(o.fInspector),
112 fFirstEvent(o.fFirstEvent),
113 fHEvents(o.fHEvents),
114 fHEventsTr(o.fHEventsTr),
115 fHEventsTrVtx(o.fHEventsTrVtx),
119 fNPhiBins(o.fNPhiBins)
125 // o Object to copy from
129 //____________________________________________________________________
130 AliCentralMCCorrectionsTask&
131 AliCentralMCCorrectionsTask::operator=(const AliCentralMCCorrectionsTask& o)
134 // Assignment operator
137 // o Object to assign from
140 // Reference to this object
142 if (&o == this) return *this;
143 fInspector = o.fInspector;
144 fTrackDensity = o.fTrackDensity;
145 fVtxBins = o.fVtxBins;
146 fFirstEvent = o.fFirstEvent;
147 fHEvents = o.fHEvents;
148 fHEventsTr = o.fHEventsTr;
149 fHEventsTrVtx = o.fHEventsTrVtx;
150 SetVertexAxis(o.fVtxAxis);
151 SetEtaAxis(o.fEtaAxis);
152 fNPhiBins = o.fNPhiBins;
157 //____________________________________________________________________
159 AliCentralMCCorrectionsTask::Init()
162 // Initialize the task
167 //____________________________________________________________________
169 AliCentralMCCorrectionsTask::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 AliCentralMCCorrectionsTask::SetVertexAxis(const TAxis& axis)
197 // Set the vertex axis to use
202 SetVertexAxis(axis.GetNbins(),axis.GetXmin(),axis.GetXmax());
205 //____________________________________________________________________
207 AliCentralMCCorrectionsTask::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 AliCentralMCCorrectionsTask::SetEtaAxis(const TAxis& axis)
234 // Set the eta axis to use
239 SetEtaAxis(axis.GetNbins(),axis.GetXmin(),axis.GetXmax());
242 //____________________________________________________________________
244 AliCentralMCCorrectionsTask::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, fNPhiBins);
254 fVtxBins->AddAt(bin, i);
255 bin->DefineOutput(l);
259 //____________________________________________________________________
261 AliCentralMCCorrectionsTask::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 AliCentralMCCorrectionsTask::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 // Now process our input data and store in own ESD object
411 fTrackDensity.Calculate(*mcEvent, vZMc, *bin->fHits, bin->fPrimary);
412 bin->fCounts->Fill(0.5);
415 //____________________________________________________________________
417 AliCentralMCCorrectionsTask::Terminate(Option_t*)
426 fList = dynamic_cast<TList*>(GetOutputData(1));
428 AliError("No output list defined");
433 TList* output = new TList;
435 output->SetName(Form("%sResults", GetName()));
437 // --- Fill correction object --------------------------------------
438 AliCentralCorrSecondaryMap* corr = new AliCentralCorrSecondaryMap;
439 corr->SetVertexAxis(fVtxAxis);
440 // corr->SetEtaAxis(fEtaAxis);
442 TIter next(fVtxBins);
445 while ((bin = static_cast<VtxBin*>(next())))
446 bin->Finish(fList, output, iVz++, corr);
453 //____________________________________________________________________
455 AliCentralMCCorrectionsTask::Print(Option_t* option) const
457 std::cout << ClassName() << "\n"
458 << " Vertex bins: " << fVtxAxis.GetNbins() << '\n'
459 << " Vertex range: [" << fVtxAxis.GetXmin()
460 << "," << fVtxAxis.GetXmax() << "]\n"
461 << " Eta bins: " << fEtaAxis.GetNbins() << '\n'
462 << " Eta range: [" << fEtaAxis.GetXmin()
463 << "," << fEtaAxis.GetXmax() << "]\n"
464 << " # of phi bins: " << fNPhiBins
466 gROOT->IncreaseDirLevel();
467 fInspector.Print(option);
468 fTrackDensity.Print(option);
469 gROOT->DecreaseDirLevel();
472 //====================================================================
474 AliCentralMCCorrectionsTask::VtxBin::BinName(Double_t low,
478 buf = Form("vtx%+05.1f_%+05.1f", low, high);
479 buf.ReplaceAll("+", "p");
480 buf.ReplaceAll("-", "m");
481 buf.ReplaceAll(".", "d");
486 //____________________________________________________________________
487 AliCentralMCCorrectionsTask::VtxBin::VtxBin()
493 //____________________________________________________________________
494 AliCentralMCCorrectionsTask::VtxBin::VtxBin(Double_t low,
498 : TNamed(BinName(low, high),
499 Form("%+5.1fcm<v_{z}<%+5.1fcm", low, high)),
504 fPrimary = new TH2D("primary", "Primaries",
505 axis.GetNbins(), axis.GetXmin(), axis.GetXmax(),
506 nPhi, 0, 2*TMath::Pi());
507 fPrimary->SetXTitle("#eta");
508 fPrimary->SetYTitle("#varphi [radians]");
510 fPrimary->SetDirectory(0);
512 fHits = static_cast<TH2D*>(fPrimary->Clone("hits"));
513 fHits->SetTitle("Hits");
514 fHits->SetDirectory(0);
516 fCounts = new TH1D("counts", "Counts", 1, 0, 1);
517 fCounts->SetXTitle("Events");
518 fCounts->SetYTitle("# of Events");
519 fCounts->SetDirectory(0);
522 //____________________________________________________________________
523 AliCentralMCCorrectionsTask::VtxBin::VtxBin(const VtxBin& o)
530 fHits = static_cast<TH2D*>(o.fHits->Clone());
531 fHits->SetDirectory(0);
534 fPrimary = static_cast<TH2D*>(o.fPrimary->Clone());
535 fPrimary->SetDirectory(0);
538 fCounts = static_cast<TH1D*>(o.fCounts->Clone());
539 fCounts->SetDirectory(0);
543 //____________________________________________________________________
544 AliCentralMCCorrectionsTask::VtxBin&
545 AliCentralMCCorrectionsTask::VtxBin::operator=(const VtxBin& o)
547 if (&o == this) return *this;
548 TNamed::operator=(o);
553 fHits = static_cast<TH2D*>(o.fHits->Clone());
554 fHits->SetDirectory(0);
557 fPrimary = static_cast<TH2D*>(o.fPrimary->Clone());
558 fPrimary->SetDirectory(0);
561 fCounts = static_cast<TH1D*>(o.fCounts->Clone());
562 fCounts->SetDirectory(0);
567 //____________________________________________________________________
569 AliCentralMCCorrectionsTask::VtxBin::DefineOutput(TList* l)
571 TList* d = new TList;
572 d->SetName(GetName());
580 //____________________________________________________________________
582 AliCentralMCCorrectionsTask::VtxBin::Finish(const TList* input,
585 AliCentralCorrSecondaryMap* map)
587 TList* out = new TList;
588 out->SetName(GetName());
592 TList* l = static_cast<TList*>(input->FindObject(GetName()));
594 AliError(Form("List %s not found in %s", GetName(), input->GetName()));
599 TH2D* hits = static_cast<TH2D*>(l->FindObject("hits"));
600 TH2D* prim = static_cast<TH2D*>(l->FindObject("primary"));
601 if (!hits || !prim) {
602 AliError(Form("Missing histograms: %p, %p", hits, prim));
606 TH2D* h = static_cast<TH2D*>(hits->Clone("bgCorr"));
610 map->SetCorrection(iVz, h);