2 /**************************************************************************
3 * Copyright(c) 2012, ALICE Experiment at CERN, All rights reserved. *
5 * Author: The ALICE Off-line Project. *
6 * Contributors are mentioned in the code where appropriate. *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
16 // $Id: AliAnalysisTaskLongRangeCorrelations.cxx 407 2014-03-21 11:55:57Z cmayer $
23 #include <THashList.h>
24 #include <THnSparse.h>
29 #include "AliEventPoolManager.h"
30 #include "AliAnalysisManager.h"
31 #include "AliAODEvent.h"
32 #include "AliAODMCHeader.h"
33 #include "AliAODMCParticle.h"
34 #include "AliMCEvent.h"
35 #include "AliInputEventHandler.h"
39 #include "AliMCEventHandler.h"
40 #include "AliMCEvent.h"
42 #include "AliAnalysisTaskLongRangeCorrelations.h"
45 ClassImp(AliAnalysisTaskLongRangeCorrelations);
46 ClassImp(LRCParticle);
48 AliAnalysisTaskLongRangeCorrelations::AliAnalysisTaskLongRangeCorrelations(const char *name)
49 : AliAnalysisTaskSE(name)
54 , fMixingTracks(50000)
56 , fCentMin(0), fCentMax(20)
57 , fPtMin(0.2), fPtMax(1e10)
58 , fPhiMin(0.), fPhiMax(TMath::TwoPi())
60 , fSelectPrimaryMCParticles(0)
61 , fSelectPrimaryMCDataParticles(0)
65 , fnBinsCent( 220), fnBinsPt(400), fnBinsPhi(4), fnBinsEta(120)
66 , fxMinCent( -5.0), fxMinPt( 0.0), fxMinPhi( 0.0), fxMinEta(-1.5)
67 , fxMaxCent(105.0), fxMaxPt( 4.0), fxMaxPhi( TMath::TwoPi()), fxMaxEta( 1.5) {
68 DefineInput(0, TChain::Class());
69 DefineOutput(1, TList::Class());
72 AliAnalysisTaskLongRangeCorrelations::~AliAnalysisTaskLongRangeCorrelations() {
73 if (NULL != fOutputList) {
79 void AliAnalysisTaskLongRangeCorrelations::UserCreateOutputObjects() {
80 fOutputList = new THashList;
81 fOutputList->SetOwner(kTRUE);
82 fOutputList->SetName(GetOutputListName());
84 const Double_t vertexBins[] = { // Zvtx bins
85 -10., -7., -5., -3., -1., 1., 3., 5., 7., 10.
87 const Int_t nVertexBins(sizeof(vertexBins)/sizeof(Double_t)-1);
88 fVertexZ = new TAxis(nVertexBins, vertexBins);
89 fVertexZ->SetName("VertexZAxis");
90 fOutputList->Add(fVertexZ);
92 fOutputList->Add(new TH1D("histVertexZ", ";vertex Z (cm)", nVertexBins, vertexBins));
95 const char* eventStatLabels[] = {
98 "Centrality Selection",
102 const size_t nEventStat(sizeof(eventStatLabels)/sizeof(const char*));
103 TH1* hStats(new TH1D("histEventStats", "histEventStats", nEventStat, -0.5, nEventStat-0.5));
104 for (size_t i(0); i<nEventStat; ++i)
105 hStats->GetXaxis()->SetBinLabel(1+i, eventStatLabels[i]);
106 fOutputList->Add(hStats);
109 fOutputList->Add(new TH2D("histQACentrality", ";centrality V0M(%);selected;",
110 fnBinsCent,fxMinCent,fxMaxCent, 2, -0.5, 1.5));
111 fOutputList->Add(new TH2D("histQAVertexZ", ";vertex-z (cm);selected;",
112 800, -40., 40., 2, -0.5, 1.5));
113 fOutputList->Add(new TH1D("histQAMultiplicityBeforeCuts",
114 ";tracks", 10000, 0, 10000));
115 fOutputList->Add(new TH1D("histQAMultiplicityAfterCuts",
116 ";selected tracks", 10000, 0, 10000));
117 fOutputList->Add(new TH3D("histQACentPt", ";charge;centrality V0M(%);p_{T} (GeV/c)",
118 2, -0.5, 1.5, fnBinsCent, fxMinCent, fxMaxCent, fnBinsPt, fxMinPt, fxMaxPt));
119 fOutputList->Add(new TH3D("histQAPhiEta", ";charge;#phi (rad);#eta",
120 2, -0.5, 1.5, 200, 0.0, TMath::TwoPi(), 300, -1.5, 1.5));
122 // N(eta) distributions with different binnings
123 fOutputList->Add(new TH2D("histNEta_120", ";#eta;N", 120, -1.5, 1.5, 1000, -.5, 1000-.5)); // 0.025
124 fOutputList->Add(new TH2D("histNEta__60", ";#eta;N", 60, -1.5, 1.5, 1000, -.5, 1000-.5)); // 0.05
125 fOutputList->Add(new TH2D("histNEta__30", ";#eta;N", 30, -1.5, 1.5, 1000, -.5, 1000-.5)); // 0.1
126 fOutputList->Add(new TH2D("histNEta__15", ";#eta;N", 15, -1.5, 1.5, 1000, -.5, 1000-.5)); // 0.2
129 fOutputList->Add(MakeHistPhiEta("histMoment1PhiEta_1"));
131 fOutputList->Add(MakeHistPhiEta("histMoment1PhiEta_2"));
132 fOutputList->Add(MakeHistPhiEtaPhiEta("histMoment2PhiEtaPhiEta_11"));
134 fOutputList->Add(MakeHistPhiEtaPhiEta("histMoment2PhiEtaPhiEta_12"));
135 fOutputList->Add(MakeHistPhiEtaPhiEta("histMoment2PhiEtaPhiEta_22"));
139 const Int_t N(fOutputList->GetEntries());
140 for (Int_t i(0); i<N; ++i)
141 fOutputList->Add(fOutputList->At(i)->Clone(TString("MC_") + fOutputList->At(i)->GetName()));
146 PostData(1, fOutputList);
149 void AliAnalysisTaskLongRangeCorrelations::UserExec(Option_t* ) {
150 AliAnalysisManager* pManager(AliAnalysisManager::GetAnalysisManager());
151 if (NULL == pManager) return;
153 AliInputEventHandler* pInputHandler(dynamic_cast<AliInputEventHandler*>(pManager->GetInputEventHandler()));
154 if (NULL == pInputHandler) return;
156 AliAODEvent* pAOD(dynamic_cast<AliAODEvent*>(InputEvent()));
157 if (NULL == pAOD) return;
159 AliAODHeader *pAODHeader = pAOD->GetHeader();
160 if (NULL == pAODHeader) return;
162 AliAODMCHeader *pAODMCHeader(dynamic_cast<AliAODMCHeader*>(pAOD->FindListObject(AliAODMCHeader::StdBranchName())));
163 const Bool_t isMC(NULL != pAODMCHeader);
165 TClonesArray *arrayMC(NULL);
167 arrayMC = dynamic_cast<TClonesArray*>(pAOD->GetList()->FindObject(AliAODMCParticle::StdBranchName()));
168 if (NULL == arrayMC) return;
171 // --- event cuts MC ---
173 Fill("MC_histEventStats", 0.); // all events
174 Fill("MC_histEventStats", 1.); // events passing physics selection
177 // --- event cuts data ---
178 Fill("histEventStats", 0.); // all events
181 if (!pInputHandler->IsEventSelected()) return;
182 Fill("histEventStats", 1.); // events passing physics selection
184 // centrality selection
185 const Double_t centrality(pAODHeader->GetCentralityP()->GetCentralityPercentile("V0M"));
186 AliDebug(3, Form("centrality=%f", centrality));
187 const Bool_t centralitySelected(centrality > fCentMin && centrality < fCentMax);
188 Fill("histQACentrality", centrality, centralitySelected);
189 if (!centralitySelected) return;
190 Fill("histEventStats", 2.); // events passing centrality selection
192 Fill("MC_histEventStats", 2.); // events passing centrality selection
194 // vertex selection -- data
195 const Int_t nVertex(pAOD->GetNumberOfVertices());
196 if (0 == nVertex) return;
197 const AliAODVertex* pVertex(pAOD->GetPrimaryVertex());
198 if (NULL == pVertex) return;
199 const Int_t nTracksPrimary(pVertex->GetNContributors());
200 if (nTracksPrimary < 1) return;
202 const Double_t zVertex(pVertex->GetZ());
203 const Bool_t vertexSelectedData(TMath::Abs(zVertex) < fMaxAbsVertexZ);
205 // vertex selection -- MC
206 Bool_t vertexSelectedMC(kTRUE);
208 vertexSelectedMC = (TMath::Abs(pAODMCHeader->GetVtxZ()) < fMaxAbsVertexZ);
210 // combined vertex selection (data and MC)
211 const Bool_t vertexSelected(vertexSelectedData && vertexSelectedMC);
212 Fill("histQAVertexZ", zVertex, vertexSelected);
214 Fill("MC_histQAVertexZ", pAODMCHeader->GetVtxZ(), vertexSelected);
215 if (!vertexSelected) return;
216 Fill("histEventStats", 3.); // events passing vertex selection
218 Fill("MC_histEventStats", 3.); // events passing vertex selection
220 // ------------------
222 // ------------------
224 TObjArray* tracksMain(GetAcceptedTracks(pAOD, arrayMC, centrality));
225 Fill("histQAMultiplicityBeforeCuts", pAOD->GetNumberOfTracks());
226 Fill("histQAMultiplicityAfterCuts", tracksMain->GetEntriesFast());
229 AliEventPool* pEventPool(fPoolMgr->GetEventPool(centrality, pAOD->GetPrimaryVertex()->GetZ()));
230 if (NULL == pEventPool)
231 AliFatal(Form("No pool found for centrality = %f, zVtx = %f", centrality, pAOD->GetPrimaryVertex()->GetZ()));
233 // pEventPool->PrintInfo();
234 if (pEventPool->IsReady()
235 || pEventPool->NTracksInPool() > fMixingTracks/10
236 || pEventPool->GetCurrentNEvents() >= 5) {
237 Fill("histEventStats", 4.); // analyzed events
238 Fill("histVertexZ", zVertex);
239 const Int_t nMix(pEventPool->GetCurrentNEvents());
240 for (Int_t i(0); i<nMix; ++i) {
241 TObjArray* tracksMixed(pEventPool->GetEvent(i));
242 CalculateMoments("", tracksMain, tracksMixed, zVertex, 1./nMix);
245 // Update the Event pool
246 pEventPool->UpdatePool(tracksMain);
247 } else { // no mixing
248 Fill("histEventStats", 4.); // analyzed events
249 Fill("histVertexZ", zVertex);
250 CalculateMoments("", tracksMain, tracksMain, zVertex, 1.);
255 TObjArray* tracksMC(GetAcceptedTracks(arrayMC, centrality));
256 const Double_t x[2] = {
257 arrayMC->GetEntriesFast(),
258 tracksMC->GetEntriesFast()
260 Fill("MC_histQAMultiplicity", x);
261 Fill("MC_histEventStats", 4.); // analyzed MC events
262 Fill("MC_histVertexZ", pAOD->GetPrimaryVertex()->GetZ());
263 CalculateMoments("MC_", tracksMC, tracksMC, zVertex, 1.);
268 void AliAnalysisTaskLongRangeCorrelations::Terminate(Option_t* ) {
270 fOutputList = dynamic_cast<TList*>(GetOutputData(1));
271 if (NULL == fOutputList) {
272 AliFatal("NULL == fOutputList");
273 return; // needed to avoid coverity warning
277 TString AliAnalysisTaskLongRangeCorrelations::GetOutputListName() const {
278 TString listName("listLRC");
279 listName += TString::Format("_%smix", fRunMixing ? "" : "no");
280 listName += TString::Format("_trackFilt%d", fTrackFilter);
281 listName += TString::Format("_cent%.0fT%.0f", fCentMin, fCentMax);
282 listName += TString::Format("_ptMin%.0fMeV", 1e3*fPtMin);
283 listName += TString::Format("_phi%.0fT%.0f", TMath::RadToDeg()*fPhiMin, TMath::RadToDeg()*fPhiMax);
284 if ( 1 == fSelectPrimaryMCParticles)
285 listName += "_selPrimMC";
286 if (-1 == fSelectPrimaryMCParticles)
287 listName += "_selNonPrimMC";
288 if ( 1 == fSelectPrimaryMCDataParticles)
289 listName += "_selPrimMCData";
290 if (-1 == fSelectPrimaryMCDataParticles)
291 listName += "_selNonPrimMCData";
293 listName += TString::Format("_nMin%d", fNMin);
295 listName += TString::Format("_nMax%d", fNMax);
297 listName += TString::Format("_deltaEta%02.0f", 10*fDeltaEta);
301 void AliAnalysisTaskLongRangeCorrelations::SetupForMixing() {
302 const Int_t trackDepth(fMixingTracks);
303 const Int_t poolsize(1000); // Maximum number of events
305 Double_t centralityBins[] = { fCentMin, fCentMax };
306 const Int_t nCentralityBins(sizeof(centralityBins)/sizeof(Double_t) - 1);
308 fPoolMgr = new AliEventPoolManager(poolsize, trackDepth,
309 nCentralityBins, centralityBins,
310 fVertexZ->GetNbins()+1,
311 const_cast<Double_t*>(fVertexZ->GetXbins()->GetArray()));
314 THnSparse* AliAnalysisTaskLongRangeCorrelations::MakeHistSparsePhiEta(const char* name) const {
315 const Int_t nVertexZBins=fVertexZ->GetNbins();
316 const Int_t nBinsM1[] = { fnBinsPhi, fnBinsEta, nVertexZBins };
317 const Double_t xMinM1[] = { fxMinPhi, fxMinEta, 0.5 };
318 const Double_t xMaxM1[] = { fxMaxPhi, fxMaxEta, nVertexZBins+0.5 };
319 const TString title(TString(name)
320 +";#phi;#eta;vertex Z (bin);");
321 return new THnSparseD(name, title.Data(), 3, nBinsM1, xMinM1, xMaxM1);
324 AliTHn* AliAnalysisTaskLongRangeCorrelations::MakeHistPhiEta(const char* name) const {
325 const Int_t nVertexZBins=fVertexZ->GetNbins();
326 const Int_t nBinsM1[] = { fnBinsPhi, fnBinsEta, nVertexZBins };
327 const Double_t xMinM1[] = { fxMinPhi, fxMinEta, 0.5 };
328 const Double_t xMaxM1[] = { fxMaxPhi, fxMaxEta, nVertexZBins+0.5 };
329 const TString title(TString(name)
330 +";#phi;#eta;vertex Z (bin);");
331 AliTHn* h(new AliTHn(name, title.Data(), 1, 3, nBinsM1));
332 for (Int_t i=0; i<3; ++i)
333 h->SetBinLimits(i, xMinM1[i], xMaxM1[i]);
337 AliTHn* AliAnalysisTaskLongRangeCorrelations::MakeHistPhiEtaPhiEta(const char* name) const {
338 const Int_t nVertexZBins=fVertexZ->GetNbins();
339 const Int_t nBinsM2[] = { fnBinsPhi, fnBinsEta, fnBinsPhi, fnBinsEta, nVertexZBins };
340 const Double_t xMinM2[] = { fxMinPhi, fxMinEta, fxMinPhi, fxMinEta, 0.5 };
341 const Double_t xMaxM2[] = { fxMaxPhi, fxMaxEta, fxMaxPhi, fxMaxEta, nVertexZBins+0.5 };
342 const TString title(TString(name)
343 +";#phi_{1};#eta_{1}"
344 +";#phi_{2};#eta_{2};vertex Z (bin);");
345 AliTHn* h(new AliTHn(name, title.Data(), 1, 5, nBinsM2));
346 for (Int_t i=0; i<5; ++i)
347 h->SetBinLimits(i, xMinM2[i], xMaxM2[i]);
351 TObjArray* AliAnalysisTaskLongRangeCorrelations::GetAcceptedTracks(AliAODEvent* pAOD,
352 TClonesArray* arrayMC,
353 Double_t centrality) {
354 TObjArray* tracks= new TObjArray;
355 tracks->SetOwner(kTRUE);
357 const Long64_t N(pAOD->GetNumberOfTracks());
358 AliDebug(5, Form("#tracks= %6lld %f", N, centrality));
359 for (Long64_t i(0); i<N; ++i) {
360 AliAODTrack* pAODTrack(dynamic_cast<AliAODTrack*>(pAOD->GetTrack(i)));
361 if (NULL == pAODTrack) continue;
363 // track filter selection
364 if (!pAODTrack->TestFilterBit(fTrackFilter)) continue;
366 // select only primary tracks
367 if (pAODTrack->GetType() != AliAODTrack::kPrimary) continue;
369 if (NULL != arrayMC) {
370 const Int_t label(pAODTrack->GetLabel());
371 AliAODMCParticle* mcParticle((label >= 0)
372 ? static_cast<AliAODMCParticle*>(arrayMC->At(label))
374 if (label >=0 && NULL == mcParticle)
375 AliFatal("MC particle not found");
377 // const Bool_t isPhysicalPrimary(mcParticle->IsPhysicalPrimary());
378 // Printf("mcParticle->IsPhysicalPrimary() %d", isPhysicalPrimary);
380 switch (fSelectPrimaryMCDataParticles) {
382 if (label < 0) continue;
383 if (kTRUE == mcParticle->IsPhysicalPrimary()) continue;
386 // NOP, take all tracks
389 if (label < 0) continue;
390 if (kFALSE == mcParticle->IsPhysicalPrimary()) continue;
393 AliFatal("fSelectPrimaryMCDataParticles != {-1,0,1}");
397 // select only charged tracks
398 if (pAODTrack->Charge() == 0) continue;
400 Fill("histQACentPt", pAODTrack->Charge()>0, centrality, pAODTrack->Pt());
401 Fill("histQAPhiEta", pAODTrack->Charge()>0, pAODTrack->Phi(), pAODTrack->Eta());
402 if (pAODTrack->Phi() < fPhiMin || pAODTrack->Phi() > fPhiMax) continue;
403 if (pAODTrack->Pt() < fPtMin || pAODTrack->Pt() > fPtMax) continue;
405 tracks->Add(new LRCParticle(pAODTrack->Eta(), pAODTrack->Phi()));
410 TObjArray* AliAnalysisTaskLongRangeCorrelations::GetAcceptedTracks(TClonesArray* tracksMC,
411 Double_t centrality) {
412 // for keeping track of MC labels
413 std::set<Int_t> labelSet;
415 TObjArray* tracks= new TObjArray;
416 tracks->SetOwner(kTRUE);
418 const Long64_t N(tracksMC->GetEntriesFast());
419 AliDebug(5, Form("#tracks= %6lld %f", N, centrality));
420 for (Long64_t i(0); i<N; ++i) {
421 AliAODMCParticle* pMCTrack(dynamic_cast<AliAODMCParticle*>(tracksMC->At(i)));
422 if (NULL == pMCTrack) continue;
424 // no track filter selection for MC tracks
426 if (labelSet.find(pMCTrack->Label()) != labelSet.end()) {
427 Printf("Duplicate Label= %3d", pMCTrack->Label());
430 labelSet.insert(pMCTrack->Label());
432 // Printf("isPrim = %d", pMCTrack->IsPhysicalPrimary());
434 switch (fSelectPrimaryMCParticles) {
436 if (kTRUE == pMCTrack->IsPhysicalPrimary()) continue;
439 // NOP, take all MC tracks
442 if (kFALSE == pMCTrack->IsPhysicalPrimary()) continue;
445 AliFatal("fSelectPrimaryMCParticles != {-1,0,1}");
448 // select only charged tracks
449 if (pMCTrack->Charge() == 0) continue;
451 Fill("MC_histQACentPt", pMCTrack->Charge()>0, centrality, pMCTrack->Pt());
452 Fill("MC_histQAPhiEta", pMCTrack->Charge()>0, pMCTrack->Phi(), pMCTrack->Eta());
454 if (pMCTrack->Phi() < fPhiMin || pMCTrack->Phi() > fPhiMax) continue;
455 if (pMCTrack->Pt() < fPtMin || pMCTrack->Pt() > fPtMax) continue;
457 tracks->Add(new LRCParticle(pMCTrack->Eta(), pMCTrack->Phi()));
462 Bool_t AddTHnSparseToAliTHn(AliTHn* h, THnSparse* hs, Double_t weight) {
463 if (h->GetNVar() != hs->GetNdimensions())
466 const size_t nDim(hs->GetNdimensions());
468 Int_t *coord = new Int_t[nDim];
469 Double_t *x = new Double_t[nDim];
471 const Long64_t N(hs->GetNbins());
472 for (Long64_t i(0); i<N; ++i) {
473 const Double_t n(hs->GetBinContent(i, coord));
474 for (size_t j=0; j<nDim; ++j)
475 x[j] = hs->GetAxis(j)->GetBinCenter(coord[j]);
476 h->Fill(x, 0, n*weight);
485 void AliAnalysisTaskLongRangeCorrelations::CalculateMoments(TString prefix,
490 THnSparse* hN1ForThisEvent(ComputeNForThisEvent(tracks1, "hN1", vertexZ));
492 if (fDeltaEta >= 0) {
493 hN1ForThisEvent->GetAxis(1)->SetRangeUser( fDeltaEta/2+0.00001, fDeltaEta/2+0.19999);
494 TH1 *hTemp = hN1ForThisEvent->Projection(0);
495 const Long64_t ncPlus = Long64_t(hTemp->GetEntries());
498 hN1ForThisEvent->GetAxis(1)->SetRangeUser(-fDeltaEta/2-0.19999, -fDeltaEta/2-0.00001);
499 hTemp = hN1ForThisEvent->Projection(0);
500 const Long64_t ncMinus = Long64_t(hTemp->GetEntries());
503 // restore full axis range
504 hN1ForThisEvent->GetAxis(1)->SetRange(0, -1);
506 if (fNMin != -1 && ncPlus < fNMin) return;
507 if (fNMax != -1 && ncPlus > fNMax) return;
509 if (fNMin != -1 && ncMinus < fNMin) return;
510 if (fNMax != -1 && ncMinus > fNMax) return;
513 AliTHn* hN1(dynamic_cast<AliTHn*>(fOutputList->FindObject(prefix+"histMoment1PhiEta_1")));
514 if (NULL == hN1) return;
517 AddTHnSparseToAliTHn(hN1,hN1ForThisEvent, weight);
518 // hN1->GetGrid(0)->GetGrid()->Add(hN1ForThisEvent, weight);
520 // n(eta) distributions
521 FillNEtaHist(prefix+"histNEta_300", hN1ForThisEvent, weight);
522 FillNEtaHist(prefix+"histNEta_120", hN1ForThisEvent, weight);
523 FillNEtaHist(prefix+"histNEta__30", hN1ForThisEvent, weight);
524 FillNEtaHist(prefix+"histNEta__15", hN1ForThisEvent, weight);
526 TObjArray* hNs(new TObjArray);
529 hNs->AddAt(hN1ForThisEvent, 0);
530 hNs->AddAt(hN1ForThisEvent, 1);
532 ComputeNXForThisEvent(hNs, prefix+"histMoment2PhiEtaPhiEta_11", vertexZ, weight);
535 AliTHn* hN2(dynamic_cast<AliTHn*>(fOutputList->FindObject(prefix+"histMoment1PhiEta_2")));
536 if (NULL == hN2) return;
538 THnSparse* hN2ForThisEvent(ComputeNForThisEvent(tracks2, "hN2", vertexZ));
539 AddTHnSparseToAliTHn(hN2,hN2ForThisEvent, weight);
540 // hN2->GetGrid(0)->GetGrid()->Add(hN2ForThisEvent, weight);
543 hNs->AddAt(hN2ForThisEvent, 1);
544 ComputeNXForThisEvent(hNs, prefix+"histMoment2PhiEtaPhiEta_12", vertexZ, weight);
547 hNs->AddAt(hN2ForThisEvent, 0);
548 ComputeNXForThisEvent(hNs, prefix+"histMoment2PhiEtaPhiEta_22", vertexZ, weight);
551 delete hN2ForThisEvent;
556 delete hN1ForThisEvent;
559 void AliAnalysisTaskLongRangeCorrelations::FillNEtaHist(TString name,
563 TH2* hSum(dynamic_cast<TH2*>(fOutputList->FindObject(name)));
564 if (NULL == hSum) return;
566 TH2* hPerEvent(dynamic_cast<TH2*>(hSum->Clone("hPerEvent")));
567 if (NULL == hPerEvent) return;
570 TH1* h1PerEvent(hPerEvent->ProjectionX());
573 const Long64_t N(hs->GetNbins());
574 for (Long64_t i(0); i<N; ++i) {
575 Int_t coord[2] = { 0, 0 };
576 const Double_t n(hs->GetBinContent(i, coord));
577 const Double_t eta(hs->GetAxis(1)->GetBinCenter(coord[1]));
578 h1PerEvent->Fill(eta, n);
581 for (Int_t i(1); i<=h1PerEvent->GetNbinsX(); ++i)
582 hPerEvent->Fill(h1PerEvent->GetXaxis()->GetBinCenter(i),
583 h1PerEvent->GetBinContent(i));
585 hSum->Add(hPerEvent, weight);
591 THnSparse* AliAnalysisTaskLongRangeCorrelations::ComputeNForThisEvent(TObjArray* tracks,
592 const char* histName,
593 Double_t vertexZ) const {
594 const Double_t vertexZBin(fVertexZ->FindBin(vertexZ));
595 THnSparse* hN(MakeHistSparsePhiEta(histName));
596 const Long64_t nTracks(tracks->GetEntriesFast());
597 for (Long64_t i(0); i<nTracks; ++i) {
598 const LRCParticle* p(dynamic_cast<LRCParticle*>(tracks->At(i)));
599 if (NULL == p) continue;
600 const Double_t x[] = { p->Phi(), p->Eta(), vertexZBin };
606 class MultiDimIterator {
608 MultiDimIterator(TObjArray* _fHs, Double_t vertexZBin)
610 , fN(fHs->GetEntriesFast())
616 for (Long64_t i=0; i<fN; ++i) {
617 THnSparse* hNi(reinterpret_cast<THnSparse*>(fHs->At(i)));
619 AliFatal("NULL == hNi");
620 fDims[i] = hNi->GetNbins();
621 AliDebug(3, Form("%lld %s %lld", i, hNi->GetName(), fDims[i]));
624 fX[2*fN] = vertexZBin;
627 const char* ClassName() const { return "MultiDimIterator"; }
628 const Double_t* GetX() const { return &fX.front(); }
629 Double_t GetN() const { // returns the product of all multiplicities
630 return std::accumulate(fNs.begin(), fNs.end(), Double_t(1), std::multiplies<Double_t>());
632 Bool_t end() const { return fj == fN; }
634 MultiDimIterator& operator++() {
639 if (fIdxs[j] < fDims[j]) break;
648 void update(Long64_t j) {
649 THnSparse* hs(reinterpret_cast<THnSparse*>(fHs->At(j)));
650 Int_t coord[] = { 0, 0 };
651 fNs[j] = hs->GetBinContent(fIdxs[j], coord);
652 for (Int_t k(0); k<2; ++k)
653 fX[2*j+k] = hs->GetAxis(k)->GetBinCenter(coord[k]);
656 MultiDimIterator(const MultiDimIterator&);
657 MultiDimIterator& operator=(const MultiDimIterator&);
659 TObjArray* fHs; // array of THnSparse histograms
660 const Long64_t fN; // number of histograms
661 std::vector<Long64_t> fDims; // number of filled bins for each THnSparse
662 std::vector<Long64_t> fIdxs; // indices
663 std::vector<Double_t> fNs; // number of tracks
664 std::vector<Double_t> fX; // coordinate
665 Long64_t fj; // state
668 void AliAnalysisTaskLongRangeCorrelations::ComputeNXForThisEvent(TObjArray* hNs,
669 const char* histName,
672 if (NULL == fOutputList) return;
674 AliTHn* hs(dynamic_cast<AliTHn*>(fOutputList->FindObject(histName)));
675 if (hs == NULL) return;
677 for (MultiDimIterator mdi(hNs, fVertexZ->FindBin(vertexZ)); !mdi.end(); ++mdi)
678 hs->Fill(mdi.GetX(), 0, mdi.GetN()*weight);
683 void AliAnalysisTaskLongRangeCorrelations::Fill(const char* histName, Double_t x) {
684 if (NULL == fOutputList) return;
685 TH1* h = dynamic_cast<TH1*>(fOutputList->FindObject(histName));
686 if (h == NULL) return;
689 void AliAnalysisTaskLongRangeCorrelations::Fill(const char* histName, Double_t x, Double_t y) {
690 if (NULL == fOutputList) return;
691 TH2* h = dynamic_cast<TH2*>(fOutputList->FindObject(histName));
692 if (h == NULL) return;
695 void AliAnalysisTaskLongRangeCorrelations::Fill(const char* histName, Double_t x, Double_t y, Double_t z) {
696 if (NULL == fOutputList) return;
697 TH3* h = dynamic_cast<TH3*>(fOutputList->FindObject(histName));
698 if (h == NULL) return;
701 void AliAnalysisTaskLongRangeCorrelations::Fill(const char* histName, const Double_t* x, Double_t w) {
702 if (NULL == fOutputList) return;
703 THnSparse* h = dynamic_cast<THnSparse*>(fOutputList->FindObject(histName));
704 if (h == NULL) return;