]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGJE/EMCALJetTasks/AliHadCorrTask.cxx
Removed depricated analysis framework, ie renamed
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / AliHadCorrTask.cxx
CommitLineData
d6f334b5 1// $Id$
2//
3// Hadronic correction task.
4//
1f6c8e39 5// Author: R.Reed, C.Loizides, S.Aiola
d6f334b5 6
7#include <TChain.h>
0b777a09 8#include <TClonesArray.h>
35789a2d 9#include <TH1F.h>
10#include <TH2F.h>
d6f334b5 11#include <TList.h>
bcf52e4a 12
3a385c49 13#include "AliAnalysisManager.h"
d6f334b5 14#include "AliAODEvent.h"
1f6c8e39 15#include "AliAODCaloCluster.h"
d6f334b5 16#include "AliESDCaloCluster.h"
1f6c8e39 17#include "AliVTrack.h"
0b777a09 18#include "AliPicoTrack.h"
35789a2d 19#include "AliVEventHandler.h"
1f6c8e39 20#include "AliEmcalParticle.h"
1b4db73a 21#include "AliEMCALGeometry.h"
7cd832c7 22#include "AliParticleContainer.h"
23#include "AliClusterContainer.h"
bcf52e4a 24
35789a2d 25#include "AliHadCorrTask.h"
0b777a09 26
27ClassImp(AliHadCorrTask)
28
29//________________________________________________________________________
d6f334b5 30AliHadCorrTask::AliHadCorrTask() :
9239b066 31 AliAnalysisTaskEmcal("AliHadCorrTask", kFALSE),
d6f334b5 32 fOutCaloName(),
a3f43e7e 33 fPhiMatch(0.05),
34 fEtaMatch(0.025),
32bf39af 35 fDoTrackClus(0),
f22cb876 36 fHadCorr(0),
1f6c8e39 37 fEexclCell(0),
8c0d179d 38 fDoExact(kFALSE),
1b4db73a 39 fEsdMode(kTRUE),
f22cb876 40 fOutClusters(0),
0b777a09 41 fHistNclusvsCent(0),
42 fHistNclusMatchvsCent(0),
f22cb876 43 fHistEbefore(0),
4711c521 44 fHistEafter(0),
45 fHistEoPCent(0),
32bf39af 46 fHistNMatchCent(0),
1b4db73a 47 fHistNClusMatchCent(0)
0b777a09 48{
d6f334b5 49 // Default constructor.
0b777a09 50
a3f43e7e 51 for(Int_t i=0; i<8; i++) {
9f52c61f 52 fHistEsubPch[i] = 0;
53 fHistEsubPchRat[i] = 0;
0c5f6f08 54 fHistEsubPchRatAll[i] = 0;
9f52c61f 55
a3f43e7e 56 if (i<4) {
1f6c8e39 57 fHistMatchEvsP[i] = 0;
58 fHistMatchdRvsEP[i] = 0;
59 fHistNMatchEnergy[i] = 0;
9f52c61f 60
8c0d179d 61 fHistEmbTrackMatchesOversub[i] = 0;
62 fHistNonEmbTrackMatchesOversub[i] = 0;
88646d1d 63 fHistOversubMCClusters[i] = 0;
64 fHistOversubNonMCClusters[i] = 0;
8c0d179d 65 fHistOversub[i] = 0;
8c0d179d 66
9f52c61f 67 for(Int_t j=0; j<4; j++)
68 fHistNCellsEnergy[i][j] = 0;
a3f43e7e 69 }
9f52c61f 70
fbc9afc4 71 for(Int_t j=0; j<9; j++) {
9f52c61f 72 for(Int_t k=0; k<2; k++)
1f6c8e39 73 fHistMatchEtaPhi[i][j][k] = 0;
a3f43e7e 74 }
75 }
0b777a09 76}
77
5d845887 78//________________________________________________________________________
79AliHadCorrTask::AliHadCorrTask(const char *name, Bool_t histo) :
9239b066 80 AliAnalysisTaskEmcal(name, histo),
5d845887 81 fOutCaloName("CaloClustersCorr"),
82 fPhiMatch(0.05),
83 fEtaMatch(0.025),
a89e2005 84 fDoTrackClus(1),
5d845887 85 fHadCorr(0),
1f6c8e39 86 fEexclCell(0),
8c0d179d 87 fDoExact(kFALSE),
1b4db73a 88 fEsdMode(kTRUE),
5d845887 89 fOutClusters(0),
5d845887 90 fHistNclusvsCent(0),
91 fHistNclusMatchvsCent(0),
92 fHistEbefore(0),
93 fHistEafter(0),
94 fHistEoPCent(0),
95 fHistNMatchCent(0),
1b4db73a 96 fHistNClusMatchCent(0)
5d845887 97{
98 // Standard constructor.
99
1b4db73a 100 for(Int_t i=0; i<8; i++) {
9f52c61f 101 fHistEsubPch[i] = 0;
102 fHistEsubPchRat[i] = 0;
0c5f6f08 103 fHistEsubPchRatAll[i] = 0;
9f52c61f 104
5d845887 105 if (i<4) {
9f52c61f 106 fHistMatchEvsP[i] = 0;
107 fHistMatchdRvsEP[i] = 0;
108 fHistNMatchEnergy[i] = 0;
109
8c0d179d 110 fHistEmbTrackMatchesOversub[i] = 0;
111 fHistNonEmbTrackMatchesOversub[i] = 0;
88646d1d 112 fHistOversubMCClusters[i] = 0;
113 fHistOversubNonMCClusters[i] = 0;
8c0d179d 114 fHistOversub[i] = 0;
8c0d179d 115
9f52c61f 116 for(Int_t j=0; j<4; j++)
1f6c8e39 117 fHistNCellsEnergy[i][j] = 0;
5d845887 118 }
9f52c61f 119
5d845887 120 for(Int_t j=0; j<9; j++) {
9f52c61f 121 for(Int_t k=0; k<2; k++)
1f6c8e39 122 fHistMatchEtaPhi[i][j][k] = 0;
5d845887 123 }
124 }
1b4db73a 125
126 SetMakeGeneralHistograms(histo);
5d845887 127
128 fBranchNames="ESD:AliESDRun.,AliESDHeader.,PrimaryVertex.";
d6f334b5 129}
0b777a09 130
131//________________________________________________________________________
132AliHadCorrTask::~AliHadCorrTask()
133{
134 // Destructor
135}
136
d6f334b5 137//________________________________________________________________________
b8b1b9e1 138UInt_t AliHadCorrTask::GetMomBin(Double_t p) const
d6f334b5 139{
140 // Get momenum bin.
141
b8b1b9e1 142 UInt_t pbin=0;
4f833c06 143 if (p<0.5)
d6f334b5 144 pbin=0;
fbc9afc4 145 else if (p>=0.5 && p<1.0)
d6f334b5 146 pbin=1;
fbc9afc4 147 else if (p>=1.0 && p<1.5)
d6f334b5 148 pbin=2;
fbc9afc4 149 else if (p>=1.5 && p<2.)
d6f334b5 150 pbin=3;
fbc9afc4 151 else if (p>=2. && p<3.)
d6f334b5 152 pbin=4;
fbc9afc4 153 else if (p>=3. && p<4.)
154 pbin=5;
155 else if (p>=4. && p<5.)
156 pbin=6;
157 else if (p>=5. && p<8.)
158 pbin=7;
b9a9ae7e 159 else
fbc9afc4 160 pbin=8;
d6f334b5 161
162 return pbin;
163}
164
f6e8a928 165//________________________________________________________________________
166Double_t AliHadCorrTask::GetEtaSigma(Int_t pbin) const
167{
4f833c06 168 // Get sigma in eta.
169
1f6c8e39 170 Double_t EtaSigma[9]={0.0097,0.0075,0.0059,0.0055,0.0053,0.005,0.005,0.0045,0.0042};
f6e8a928 171 return 2.0*EtaSigma[pbin];
172}
1f6c8e39 173
f6e8a928 174//________________________________________________________________________
175Double_t AliHadCorrTask::GetPhiMean(Int_t pbin, Int_t centbin) const
176{
4f833c06 177 // Get phi mean.
178
179 if (centbin==0) {
f6e8a928 180 Double_t PhiMean[9]={0.036,
181 0.021,
182 0.0121,
183 0.0084,
184 0.0060,
185 0.0041,
186 0.0031,
187 0.0022,
188 0.001};
189 return PhiMean[pbin];
4f833c06 190 } else if (centbin==1) {
f6e8a928 191 Double_t PhiMean[9]={0.036,
192 0.021,
193 0.0121,
194 0.0084,
195 0.0060,
196 0.0041,
197 0.0031,
198 0.0022,
199 0.001};
200 return PhiMean[pbin];
4f833c06 201 } else if (centbin==2) {
f6e8a928 202 Double_t PhiMean[9]={0.036,
203 0.021,
204 0.0121,
205 0.0084,
206 0.0060,
207 0.0041,
208 0.0031,
209 0.0022,
210 0.001};
211 return PhiMean[pbin];
4f833c06 212 } else if (centbin==3) {
f6e8a928 213 Double_t PhiMean[9]={0.036,
214 0.021,
215 0.0121,
216 0.0084,
217 0.0060,
218 0.0041,
219 0.0031,
220 0.0022,
221 0.001};
222 return PhiMean[pbin];
4f833c06 223 } else if (centbin==4) {
f6e8a928 224 Double_t PhiMean[9]={0.036,
225 0.021,
226 0.0127,
227 0.0089,
228 0.0068,
229 0.0049,
230 0.0038,
231 0.0028,
232 0.0018};
233 return PhiMean[pbin]*(-1.);
4f833c06 234 } else if (centbin==5) {
f6e8a928 235 Double_t PhiMean[9]={0.036,
236 0.021,
237 0.0127,
238 0.0089,
239 0.0068,
240 0.0048,
241 0.0038,
242 0.0028,
243 0.0018};
244 return PhiMean[pbin]*(-1.);
4f833c06 245 } else if (centbin==6) {
f6e8a928 246 Double_t PhiMean[9]={0.036,
247 0.021,
248 0.0127,
249 0.0089,
250 0.0068,
251 0.0045,
252 0.0035,
253 0.0028,
254 0.0018};
255 return PhiMean[pbin]*(-1.);
4f833c06 256 } else if (centbin==7) {
f6e8a928 257 Double_t PhiMean[9]={0.036,
258 0.021,
259 0.0127,
260 0.0089,
261 0.0068,
262 0.0043,
263 0.0035,
264 0.0028,
265 0.0018};
266 return PhiMean[pbin]*(-1.);
267 }
268
269 return 0;
f6e8a928 270}
1f6c8e39 271
f6e8a928 272//________________________________________________________________________
273Double_t AliHadCorrTask::GetPhiSigma(Int_t pbin, Int_t centbin) const
274{
4f833c06 275 // Get phi sigma.
276
277 if (centbin==0) {
f6e8a928 278 Double_t PhiSigma[9]={0.0221,
279 0.0128,
280 0.0074,
281 0.0064,
282 0.0059,
283 0.0055,
284 0.0052,
285 0.0049,
286 0.0045};
287 return 2.*PhiSigma[pbin];
4f833c06 288 } else if (centbin==1) {
f6e8a928 289 Double_t PhiSigma[9]={0.0217,
290 0.0120,
291 0.0076,
292 0.0066,
293 0.0062,
294 0.0058,
295 0.0054,
296 0.0054,
2970.0045};
298 return 2.*PhiSigma[pbin];
4f833c06 299 } else if (centbin==2) {
f6e8a928 300 Double_t PhiSigma[9]={0.0211,
301 0.0124,
302 0.0080,
303 0.0070,
304 0.0067,
305 0.0061,
306 0.0059,
307 0.0054,
308 0.0047};
309 return 2.*PhiSigma[pbin];
4f833c06 310 } else if (centbin==3) {
f6e8a928 311 Double_t PhiSigma[9]={0.0215,
312 0.0124,
313 0.0082,
314 0.0073,
315 0.0069,
316 0.0064,
317 0.0060,
318 0.0055,
319 0.0047};
320 return 2.*PhiSigma[pbin];
4f833c06 321 } else if (centbin==4) {
f6e8a928 322 Double_t PhiSigma[9]={0.0199,
323 0.0108,
324 0.0072,
325 0.0071,
326 0.0060,
327 0.0055,
328 0.0052,
329 0.0049,
330 0.0045};
331 return 2.*PhiSigma[pbin];
4f833c06 332 } else if (centbin==5) {
f6e8a928 333 Double_t PhiSigma[9]={0.0200,
334 0.0110,
335 0.0074,
336 0.0071,
337 0.0064,
338 0.0059,
339 0.0055,
340 0.0052,
341 0.0045};
342 return 2.*PhiSigma[pbin];
4f833c06 343 } else if (centbin==6) {
f6e8a928 344 Double_t PhiSigma[9]={0.0202,
345 0.0113,
346 0.0077,
347 0.0071,
348 0.0069,
349 0.0064,
350 0.0060,
351 0.0055,
352 0.0050};
353 return 2.*PhiSigma[pbin];
4f833c06 354 } else if (centbin==7) {
f6e8a928 355 Double_t PhiSigma[9]={0.0205,
356 0.0113,
357 0.0080,
358 0.0074,
359 0.0078,
360 0.0067,
361 0.0062,
362 0.0055,
363 0.0050};
364 return 2.*PhiSigma[pbin];
365 }
366
367 return 0;
f6e8a928 368}
369
0b777a09 370//________________________________________________________________________
371void AliHadCorrTask::UserCreateOutputObjects()
372{
d6f334b5 373 // Create my user objects.
0b777a09 374
7cd832c7 375 if (!fCreateHisto) return;
5d845887 376
9239b066 377 AliAnalysisTaskEmcal::UserCreateOutputObjects();
0b777a09 378
1f6c8e39 379 TString name;
bcf52e4a 380
8c0d179d 381 const Int_t nCentChBins = fNcentBins * 2;
382
383 for(Int_t icent=0; icent<nCentChBins; ++icent) {
fbc9afc4 384 for(Int_t ipt=0; ipt<9; ++ipt) {
1f6c8e39 385 for(Int_t ieta=0; ieta<2; ++ieta) {
1f6c8e39 386 name = Form("fHistMatchEtaPhi_%i_%i_%i",icent,ipt,ieta);
8c0d179d 387 fHistMatchEtaPhi[icent][ipt][ieta] = new TH2F(name, name, fNbins, -0.1, 0.1, fNbins, -0.1, 0.1);
1f6c8e39 388 fOutput->Add(fHistMatchEtaPhi[icent][ipt][ieta]);
389 }
4711c521 390 }
391
1f6c8e39 392 name = Form("fHistEsubPch_%i",icent);
8c0d179d 393 fHistEsubPch[icent]=new TH1F(name, name, fNbins, fMinBinPt, fMaxBinPt);
1f6c8e39 394 fOutput->Add(fHistEsubPch[icent]);
395
396 name = Form("fHistEsubPchRat_%i",icent);
8c0d179d 397 fHistEsubPchRat[icent]=new TH2F(name, name, fNbins, fMinBinPt, fMaxBinPt, fNbins*2, 0., 10.);
1f6c8e39 398 fOutput->Add(fHistEsubPchRat[icent]);
0c5f6f08 399
400 name = Form("fHistEsubPchRatAll_%i",icent);
8c0d179d 401 fHistEsubPchRatAll[icent]=new TH2F(name, name, fNbins, fMinBinPt, fMaxBinPt, fNbins*2, 0., 10.);
0c5f6f08 402 fOutput->Add(fHistEsubPchRatAll[icent]);
1f6c8e39 403
8c0d179d 404 if (icent<fNcentBins) {
1b4db73a 405 for(Int_t itrk=0; itrk<4; ++itrk) {
406 name = Form("fHistNCellsEnergy_%i_%i",icent,itrk);
8c0d179d 407 fHistNCellsEnergy[icent][itrk] = new TH2F(name, name, fNbins, fMinBinPt, fMaxBinPt, 101, -0.5, 100.5);
1b4db73a 408 fOutput->Add(fHistNCellsEnergy[icent][itrk]);
409 }
410
1f6c8e39 411 name = Form("fHistMatchEvsP_%i",icent);
8c0d179d 412 fHistMatchEvsP[icent] = new TH2F(name, name, fNbins, fMinBinPt, fMaxBinPt, fNbins*2, 0., 10.);
1f6c8e39 413 fOutput->Add(fHistMatchEvsP[icent]);
0b777a09 414
a3f43e7e 415 name = Form("fHistMatchdRvsEP_%i",icent);
8c0d179d 416 fHistMatchdRvsEP[icent] = new TH2F(name, name, fNbins, 0., 0.2, fNbins*2, 0., 10.);
1f6c8e39 417 fOutput->Add(fHistMatchdRvsEP[icent]);
418
419 name = Form("fHistNMatchEnergy_%i",icent);
8c0d179d 420 fHistNMatchEnergy[icent] = new TH2F(name, name, fNbins, fMinBinPt, fMaxBinPt, 101, -0.5, 100.5);
1f6c8e39 421 fOutput->Add(fHistNMatchEnergy[icent]);
a3f43e7e 422 }
d6f334b5 423 }
0b777a09 424
d6f334b5 425 fHistNclusvsCent = new TH1F("Nclusvscent", "NclusVsCent", 100, 0, 100);
426 fHistNclusMatchvsCent = new TH1F("NclusMatchvscent", "NclusMatchVsCent", 100, 0, 100);
faf21244 427 fHistEbefore = new TH1F("Ebefore", "Ebefore", 100, 0, 100);
428 fHistEafter = new TH1F("Eafter", "Eafter", 100, 0, 100);
8c0d179d 429 fHistEoPCent = new TH2F("EoPCent", "EoPCent", 100, 0, 100, fNbins*2, 0, 10);
430 fHistNMatchCent = new TH2F("NMatchesCent", "NMatchesCent", 100, 0, 100, 11, -0.5, 10.5);
431 fHistNClusMatchCent = new TH2F("NClusMatchesCent", "NClusMatchesCent", 100, 0, 100, 11, -0.5, 10.5);
1f6c8e39 432
433 fOutput->Add(fHistNclusMatchvsCent);
434 fOutput->Add(fHistNclusvsCent);
435 fOutput->Add(fHistEbefore);
436 fOutput->Add(fHistEafter);
437 fOutput->Add(fHistEoPCent);
438 fOutput->Add(fHistNMatchCent);
1b4db73a 439 fOutput->Add(fHistNClusMatchCent);
1f6c8e39 440
8c0d179d 441 if (fIsEmbedded) {
442 for(Int_t icent=0; icent<fNcentBins; ++icent) {
443 name = Form("fHistEmbTrackMatchesOversub_%d",icent);
88646d1d 444 fHistEmbTrackMatchesOversub[icent] = new TH2F(name, name, fNbins, fMinBinPt, fMaxBinPt, fNbins, 0, 1.2);
8c0d179d 445 fHistEmbTrackMatchesOversub[icent]->GetXaxis()->SetTitle("E_{clus}^{raw} (GeV)");
88646d1d 446 fHistEmbTrackMatchesOversub[icent]->GetYaxis()->SetTitle("E_{oversub} / E_{clus}^{raw}");
8c0d179d 447 fOutput->Add(fHistEmbTrackMatchesOversub[icent]);
448
449 name = Form("fHistNonEmbTrackMatchesOversub_%d",icent);
88646d1d 450 fHistNonEmbTrackMatchesOversub[icent] = new TH2F(name, name, fNbins, fMinBinPt, fMaxBinPt, fNbins, 0, 1.2);
8c0d179d 451 fHistNonEmbTrackMatchesOversub[icent]->GetXaxis()->SetTitle("E_{clus}^{raw} (GeV)");
88646d1d 452 fHistNonEmbTrackMatchesOversub[icent]->GetYaxis()->SetTitle("E_{oversub} / E_{clus}^{raw}");
8c0d179d 453 fOutput->Add(fHistNonEmbTrackMatchesOversub[icent]);
454
88646d1d 455 name = Form("fHistOversubMCClusters_%d",icent);
456 fHistOversubMCClusters[icent] = new TH2F(name, name, fNbins, fMinBinPt, fMaxBinPt, fNbins, 0, 1.2);
457 fHistOversubMCClusters[icent]->GetXaxis()->SetTitle("E_{clus}^{raw} (GeV)");
458 fHistOversubMCClusters[icent]->GetYaxis()->SetTitle("E_{oversub} / E_{clus}^{raw}");
459 fOutput->Add(fHistOversubMCClusters[icent]);
460
461 name = Form("fHistOversubNonMCClusters_%d",icent);
462 fHistOversubNonMCClusters[icent] = new TH2F(name, name, fNbins, fMinBinPt, fMaxBinPt, fNbins, 0, 1.2);
463 fHistOversubNonMCClusters[icent]->GetXaxis()->SetTitle("E_{clus}^{raw} (GeV)");
464 fHistOversubNonMCClusters[icent]->GetYaxis()->SetTitle("E_{oversub} / E_{clus}^{raw}");
465 fOutput->Add(fHistOversubNonMCClusters[icent]);
466
8c0d179d 467 name = Form("fHistOversub_%d",icent);
88646d1d 468 fHistOversub[icent] = new TH2F(name, name, fNbins, fMinBinPt, fMaxBinPt, fNbins, 0, 1.2);
8c0d179d 469 fHistOversub[icent]->GetXaxis()->SetTitle("E_{clus}^{raw} (GeV)");
88646d1d 470 fHistOversub[icent]->GetYaxis()->SetTitle("E_{oversub} / E_{clus}^{raw}");
8c0d179d 471 fOutput->Add(fHistOversub[icent]);
8c0d179d 472 }
473 }
474
1f6c8e39 475 PostData(1, fOutput);
0b777a09 476}
477
1b4db73a 478//________________________________________________________________________
479void AliHadCorrTask::ExecOnce()
480{
7cd832c7 481 // Initialize the analysis.
7030f36f 482
7cd832c7 483 if (fParticleCollArray.GetEntriesFast()<2) {
484 AliError(Form("Wrong number of particle collections (%d), required 2",fParticleCollArray.GetEntriesFast()));
7030f36f 485 return;
7cd832c7 486 }
7030f36f 487
7cd832c7 488 for (Int_t i = 0; i < 2; i++) {
489 AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
490 cont->SetClassName("AliEmcalParticle");
1b4db73a 491 }
492
7cd832c7 493 // Do base class initializations and if it fails -> bail out
9239b066 494 AliAnalysisTaskEmcal::ExecOnce();
7cd832c7 495 if (!fInitialized) return;
496
497 if (dynamic_cast<AliAODEvent*>(InputEvent())) fEsdMode = kFALSE;
498
1b4db73a 499 if (fEsdMode)
500 fOutClusters = new TClonesArray("AliESDCaloCluster");
501 else
502 fOutClusters = new TClonesArray("AliAODCaloCluster");
503
504 fOutClusters->SetName(fOutCaloName);
505
506 // post output in event if not yet present
507 if (!(InputEvent()->FindListObject(fOutCaloName))) {
508 InputEvent()->AddObject(fOutClusters);
509 }
510 else {
7030f36f 511 fInitialized = kFALSE;
1b4db73a 512 AliFatal(Form("%s: Container with same name %s already present. Aborting", GetName(), fOutCaloName.Data()));
513 return;
514 }
1b4db73a 515}
516
517//________________________________________________________________________
518void AliHadCorrTask::DoTrackLoop()
519{
7cd832c7 520 AliParticleContainer *tracks = static_cast<AliParticleContainer*>(fParticleCollArray.At(0));
521 AliParticleContainer *clusters = static_cast<AliParticleContainer*>(fParticleCollArray.At(1));
522
523 AliEmcalParticle *emctrack = 0;
524
525 tracks->ResetCurrentID();
526 while ((emctrack = static_cast<AliEmcalParticle*>(tracks->GetNextAcceptParticle()))) {
1b4db73a 527 Int_t NmatchClus = 0;
528
7cd832c7 529 if (!emctrack->IsEMCAL()) continue;
1b4db73a 530
531 AliVTrack *track = emctrack->GetTrack();
7cd832c7 532 if (!track) continue;
1b4db73a 533
43032ce2 534 if (track->GetTrackEtaOnEMCal() < fGeom->GetArm1EtaMin() - fEtaMatch ||
535 track->GetTrackEtaOnEMCal() > fGeom->GetArm1EtaMax() + fEtaMatch ||
536 track->GetTrackPhiOnEMCal() < fGeom->GetArm1PhiMin() * TMath::DegToRad() - fPhiMatch ||
537 track->GetTrackPhiOnEMCal() > fGeom->GetArm1PhiMax() * TMath::DegToRad() + fPhiMatch)
1b4db73a 538 continue;
539
540 Int_t Nclus = emctrack->GetNumberOfMatchedObj();
541
542 for (Int_t iClus = 0; iClus < Nclus; ++iClus) {
7cd832c7 543 AliEmcalParticle *emccluster = static_cast<AliEmcalParticle*>(clusters->GetAcceptParticle(emctrack->GetMatchedObjId(iClus)));
544 if (!emccluster) continue;
1b4db73a 545
546 AliVCluster *cluster = emccluster->GetCluster();
7cd832c7 547 if (!cluster->IsEMCAL()) continue;
548 if (!cluster) continue;
1b4db73a 549
550 Double_t etadiff = 999;
551 Double_t phidiff = 999;
552 AliPicoTrack::GetEtaPhiDiff(track, cluster, phidiff, etadiff);
553
7cd832c7 554 if (TMath::Abs(phidiff) < fPhiMatch && TMath::Abs(etadiff) < fEtaMatch) NmatchClus++;
1b4db73a 555 }
556 fHistNClusMatchCent->Fill(fCent, NmatchClus);
557 }
558}
559
1f6c8e39 560//________________________________________________________________________
8c0d179d 561void AliHadCorrTask::DoMatchedTracksLoop(AliEmcalParticle *emccluster, Double_t &totalTrkP, Int_t &Nmatches, Double_t &trkPMCfrac, Int_t &NMCmatches)
1f6c8e39 562{
c7d52659 563 // Do the loop over matched tracks for cluster emccluster.
1f6c8e39 564
7cd832c7 565 AliParticleContainer *tracks = static_cast<AliParticleContainer*>(fParticleCollArray.At(0));
566
1f6c8e39 567 AliVCluster *cluster = emccluster->GetCluster();
568 Int_t iClus = emccluster->IdInCollection();
569 Double_t energyclus = cluster->E();
570
571 // loop over matched tracks
c7d52659 572 const Int_t Ntrks = emccluster->GetNumberOfMatchedObj();
1f6c8e39 573 for (Int_t i = 0; i < Ntrks; ++i) {
574 Int_t iTrack = emccluster->GetMatchedObjId(i);
575 Double_t dR = emccluster->GetMatchedObjDistance(i);
576
7cd832c7 577 AliEmcalParticle *emctrack = static_cast<AliEmcalParticle*>(tracks->GetAcceptParticle(iTrack));
578 if (!emctrack) continue;
56bd3193 579
580 // check if track also points to cluster
7cd832c7 581 if (fDoTrackClus && (emctrack->GetMatchedObjId(0)) != iClus) continue;
56bd3193 582
1f6c8e39 583 AliVTrack *track = emctrack->GetTrack();
7cd832c7 584 if (!track) continue;
1f6c8e39 585
586 Double_t etadiff = 999;
587 Double_t phidiff = 999;
588 AliPicoTrack::GetEtaPhiDiff(track, cluster, phidiff, etadiff);
56bd3193 589
1f6c8e39 590 Double_t mom = track->P();
b8b1b9e1 591 UInt_t mombin = GetMomBin(mom);
1f6c8e39 592 Int_t centbinch = fCentBin;
c7d52659 593 if (track->Charge()<0)
8c0d179d 594 centbinch += fNcentBins;
1f6c8e39 595
596 if (fCreateHisto) {
597 Int_t etabin = 0;
598 if(track->Eta() > 0) etabin=1;
1f6c8e39 599 fHistMatchEtaPhi[centbinch][mombin][etabin]->Fill(etadiff, phidiff);
600 }
601
c7d52659 602 Double_t etaCut = 0.0;
603 Double_t phiCutlo = 0.0;
604 Double_t phiCuthi = 0.0;
1f6c8e39 605
4f833c06 606 if (fPhiMatch > 0) {
c7d52659 607 phiCutlo = -fPhiMatch;
875b35fc 608 phiCuthi = +fPhiMatch;
609 } else {
c7d52659 610 phiCutlo = GetPhiMean(mombin, centbinch) - GetPhiSigma(mombin, fCentBin);
611 phiCuthi = GetPhiMean(mombin, centbinch) + GetPhiSigma(mombin, fCentBin);
1f6c8e39 612 }
613
614 if (fEtaMatch > 0) {
c7d52659 615 etaCut = fEtaMatch;
875b35fc 616 } else {
c7d52659 617 etaCut = GetEtaSigma(mombin);
3a385c49 618 }
3a385c49 619
c7d52659 620 if ((phidiff < phiCuthi && phidiff > phiCutlo) && TMath::Abs(etadiff) < etaCut) {
8c0d179d 621 if (track->GetLabel() > fMinMCLabel) {
622 ++NMCmatches;
623 trkPMCfrac += track->P();
624 }
875b35fc 625 ++Nmatches;
626 totalTrkP += track->P();
627
628 if (fCreateHisto) {
b8b1b9e1 629 if (fHadCorr > 1) {
875b35fc 630 fHistMatchdRvsEP[fCentBin]->Fill(dR, energyclus / mom);
631 }
1f6c8e39 632 }
633 }
634 }
8c0d179d 635
636 if (totalTrkP > 0)
637 trkPMCfrac /= totalTrkP;
3a385c49 638}
639
0b777a09 640//________________________________________________________________________
1f6c8e39 641Bool_t AliHadCorrTask::Run()
0b777a09 642{
1f6c8e39 643 // Run the hadronic correction
7cd832c7 644
645 AliParticleContainer *clusters = static_cast<AliParticleContainer*>(fParticleCollArray.At(1));
646 AliEmcalParticle *emccluster = 0;
d6f334b5 647
1b4db73a 648 if (fCreateHisto)
649 DoTrackLoop();
650
d6f334b5 651 // delete output
652 fOutClusters->Delete();
0b777a09 653
7cd832c7 654 Int_t clusCount = 0;
655
85835c5b 656 // loop over all clusters
7cd832c7 657 clusters->ResetCurrentID();
658 while ((emccluster = static_cast<AliEmcalParticle*>(clusters->GetNextAcceptParticle()))) {
659 if (!emccluster->IsEMCAL()) continue;
d6f334b5 660
1f6c8e39 661 AliVCluster *cluster = emccluster->GetCluster();
7cd832c7 662 if (!cluster) continue;
d6f334b5 663
1f6c8e39 664 Double_t energyclus = 0;
8c0d179d 665 if (fCreateHisto) {
62206c47 666 fHistEbefore->Fill(fCent, cluster->E());
8c0d179d 667 fHistNclusvsCent->Fill(fCent);
668 }
32bf39af 669
d6f334b5 670 // apply correction / subtraction
0c5f6f08 671 // to subtract only the closest track set fHadCor to a %
672 // to subtract all tracks within the cut set fHadCor to %+1
673 if (fHadCorr > 1)
674 energyclus = ApplyHadCorrAllTracks(emccluster, fHadCorr - 1);
f9b8b4b8 675 else if (fHadCorr > 0)
0c5f6f08 676 energyclus = ApplyHadCorrOneTrack(emccluster, fHadCorr);
677 else
678 energyclus = cluster->E();
bcf52e4a 679
680 if (energyclus < 0)
d6f334b5 681 energyclus = 0;
d6f334b5 682
bcf52e4a 683 if (energyclus > 0) { // create corrected cluster
d6f334b5 684 AliVCluster *oc;
1b4db73a 685 if (fEsdMode) {
4f833c06 686 AliESDCaloCluster *ec = dynamic_cast<AliESDCaloCluster*>(cluster);
7cd832c7 687 if (!ec) continue;
4f833c06 688 oc = new ((*fOutClusters)[clusCount]) AliESDCaloCluster(*ec);
689 } else {
690 AliAODCaloCluster *ac = dynamic_cast<AliAODCaloCluster*>(cluster);
7cd832c7 691 if (!ac) continue;
4f833c06 692 oc = new ((*fOutClusters)[clusCount]) AliAODCaloCluster(*ac);
693 }
d6f334b5 694 oc->SetE(energyclus);
1f6c8e39 695
d6f334b5 696 ++clusCount;
1f6c8e39 697
7cd832c7 698 if (fCreateHisto) fHistEafter->Fill(fCent, energyclus);
d6f334b5 699 }
0b777a09 700 }
1f6c8e39 701
702 return kTRUE;
703}
bcf52e4a 704
1f6c8e39 705//________________________________________________________________________
706Double_t AliHadCorrTask::ApplyHadCorrOneTrack(AliEmcalParticle *emccluster, Double_t hadCorr)
707{
4f833c06 708 // Apply the hadronic correction with one track only.
709
1f6c8e39 710 AliVCluster *cluster = emccluster->GetCluster();
7cd832c7 711 if (!cluster) return 0;
712
181a0a09 713 Double_t energyclus = cluster->E();
714 Int_t iMin = emccluster->GetMatchedObjId();
1f6c8e39 715 if (iMin < 0)
716 return energyclus;
717
7cd832c7 718 AliParticleContainer *tracks = static_cast<AliParticleContainer*>(fParticleCollArray.At(0));
719 AliEmcalParticle *emctrack = static_cast<AliEmcalParticle*>(tracks->GetParticle(iMin));
720 if (!emctrack) return energyclus;
1f6c8e39 721
181a0a09 722 // check if track also points to cluster
723 Int_t cid = emctrack->GetMatchedObjId();
7cd832c7 724 if (fDoTrackClus && (cid!=emccluster->IdInCollection())) return energyclus;
c7d52659 725
1f6c8e39 726 AliVTrack *track = emctrack->GetTrack();
7cd832c7 727 if (!track) return energyclus;
1f6c8e39 728
729 Double_t mom = track->P();
7cd832c7 730 if (mom < 1e-6) return energyclus;
1f6c8e39 731
732 Double_t dRmin = emccluster->GetMatchedObjDistance();
733 Double_t dEtaMin = 1e9;
734 Double_t dPhiMin = 1e9;
735 AliPicoTrack::GetEtaPhiDiff(track, cluster, dPhiMin, dEtaMin);
736
b8b1b9e1 737 UInt_t mombin = GetMomBin(mom);
1f6c8e39 738 Int_t centbinch = fCentBin;
7cd832c7 739 if (track->Charge()<0) centbinch += fNcentBins;
1f6c8e39 740
181a0a09 741 // plot some histograms if switched on
1f6c8e39 742 if (fCreateHisto) {
743 Int_t etabin = 0;
744 if(track->Eta() > 0)
745 etabin = 1;
746
747 fHistMatchEtaPhi[centbinch][mombin][etabin]->Fill(dEtaMin, dPhiMin);
748
749 if (mom > 0) {
750 fHistMatchEvsP[fCentBin]->Fill(energyclus, energyclus / mom);
751 fHistEoPCent->Fill(fCent, energyclus / mom);
752 fHistMatchdRvsEP[fCentBin]->Fill(dRmin, energyclus / mom);
753 }
754 }
755
181a0a09 756 // define eta/phi cuts
c7d52659 757 Double_t etaCut = 0.0;
758 Double_t phiCutlo = 0.0;
759 Double_t phiCuthi = 0.0;
1f6c8e39 760 if (fPhiMatch > 0) {
c7d52659 761 phiCutlo = -fPhiMatch;
875b35fc 762 phiCuthi = +fPhiMatch;
1f6c8e39 763 }
764 else {
c7d52659 765 phiCutlo = GetPhiMean(mombin, centbinch) - GetPhiSigma(mombin, fCentBin);
766 phiCuthi = GetPhiMean(mombin, centbinch) + GetPhiSigma(mombin, fCentBin);
1f6c8e39 767 }
768 if(fEtaMatch > 0) {
c7d52659 769 etaCut = fEtaMatch;
1f6c8e39 770 }
771 else {
c7d52659 772 etaCut = GetEtaSigma(mombin);
1f6c8e39 773 }
774
181a0a09 775 // apply the correction if the track is in the eta/phi window
c7d52659 776 if ((dPhiMin < phiCuthi && dPhiMin > phiCutlo) && TMath::Abs(dEtaMin) < etaCut) {
875b35fc 777 energyclus -= hadCorr * mom;
1f6c8e39 778 }
779
780 return energyclus;
0b777a09 781}
4711c521 782
0b777a09 783//________________________________________________________________________
1f6c8e39 784Double_t AliHadCorrTask::ApplyHadCorrAllTracks(AliEmcalParticle *emccluster, Double_t hadCorr)
0b777a09 785{
4f833c06 786 // Apply the hadronic correction with all tracks.
787
7cd832c7 788 AliParticleContainer *tracks = static_cast<AliParticleContainer*>(fParticleCollArray.At(0));
789
1f6c8e39 790 AliVCluster *cluster = emccluster->GetCluster();
791
792 Double_t energyclus = cluster->E();
793 Double_t cNcells = cluster->GetNCells();
794
795 Double_t totalTrkP = 0.0; // count total track momentum
796 Int_t Nmatches = 0; // count total number of matches
8c0d179d 797
798 Double_t trkPMCfrac = 0.0; // count total track momentum
799 Int_t NMCmatches = 0; // count total number of matches
1f6c8e39 800
181a0a09 801 // do the loop over the matched tracks and get the number of matches and the total momentum
8c0d179d 802 DoMatchedTracksLoop(emccluster, totalTrkP, Nmatches, trkPMCfrac, NMCmatches);
1f6c8e39 803
804 Double_t Esub = hadCorr * totalTrkP;
62206c47 805
7cd832c7 806 if (Esub > energyclus) Esub = energyclus;
62206c47 807
181a0a09 808 // applying Peter's proposed algorithm
809 // never subtract the full energy of the cluster
1b4db73a 810 Double_t clusEexcl = fEexclCell * cNcells;
7cd832c7 811 if (energyclus < clusEexcl) clusEexcl = energyclus;
812 if ((energyclus - Esub) < clusEexcl) Esub = (energyclus - clusEexcl);
62206c47 813
1eafa82a 814 // embedding
815 Double_t EsubMC = 0;
816 Double_t EsubBkg = 0;
817 Double_t EclusMC = 0;
818 Double_t EclusBkg = 0;
819 Double_t EclusCorr = 0;
820 Double_t EclusMCcorr = 0;
821 Double_t EclusBkgcorr = 0;
822 Double_t overSub = 0;
823 if (fIsEmbedded) {
824 EsubMC = hadCorr * totalTrkP * trkPMCfrac;
825 EsubBkg = hadCorr * totalTrkP - EsubMC;
826 EclusMC = energyclus * cluster->GetMCEnergyFraction();
827 EclusBkg = energyclus - EclusMC;
828
829 if (energyclus > Esub)
830 EclusCorr = energyclus - Esub;
831
832 if (EclusMC > EsubMC)
833 EclusMCcorr = EclusMC - EsubMC;
834
835 if (EclusBkg > EsubBkg)
836 EclusBkgcorr = EclusBkg - EsubBkg;
837
838 overSub = EclusMCcorr + EclusBkgcorr - EclusCorr;
839 }
840
181a0a09 841 // plot some histograms if switched on
842 if (fCreateHisto) {
1f6c8e39 843 fHistNMatchCent->Fill(fCent, Nmatches);
844 fHistNMatchEnergy[fCentBin]->Fill(energyclus, Nmatches);
845
846 if(Nmatches > 0)
847 fHistNclusMatchvsCent->Fill(fCent);
1b4db73a 848
849 if(Nmatches < 3)
850 fHistNCellsEnergy[fCentBin][Nmatches]->Fill(energyclus, cNcells);
851 else
1f6c8e39 852 fHistNCellsEnergy[fCentBin][3]->Fill(energyclus, cNcells);
8c0d179d 853
854 if (totalTrkP>0) {
855 Double_t EoP = energyclus / totalTrkP;
1f6c8e39 856 fHistEoPCent->Fill(fCent, EoP);
857 fHistMatchEvsP[fCentBin]->Fill(energyclus, EoP);
8c0d179d 858
859 fHistEsubPchRatAll[fCentBin]->Fill(totalTrkP, Esub / totalTrkP);
860
861 if (Nmatches == 1) {
862 Int_t iMin = emccluster->GetMatchedObjId();
7cd832c7 863 AliEmcalParticle *emctrack = static_cast<AliEmcalParticle*>(tracks->GetParticle(iMin));
864 if (emctrack) {
865 AliVTrack *track = emctrack->GetTrack();
866 if (track) {
867 Int_t centbinchm = fCentBin;
868 if (track->Charge()<0) centbinchm += fNcentBins;
869
870 fHistEsubPchRat[centbinchm]->Fill(totalTrkP, Esub / totalTrkP);
871 fHistEsubPch[centbinchm]->Fill(totalTrkP, Esub);
872 }
873 }
8c0d179d 874 }
1f6c8e39 875
1eafa82a 876 if (fIsEmbedded) {
88646d1d 877 fHistOversub[fCentBin]->Fill(energyclus, overSub / energyclus);
878
879 if (cluster->GetMCEnergyFraction() > 0.95)
880 fHistOversubMCClusters[fCentBin]->Fill(energyclus, overSub / energyclus);
881 else if (cluster->GetMCEnergyFraction() < 0.05)
882 fHistOversubNonMCClusters[fCentBin]->Fill(energyclus, overSub / energyclus);
1eafa82a 883
884 if (trkPMCfrac < 0.05)
88646d1d 885 fHistNonEmbTrackMatchesOversub[fCentBin]->Fill(energyclus, overSub / energyclus);
1eafa82a 886 else if (trkPMCfrac > 0.95)
88646d1d 887 fHistEmbTrackMatchesOversub[fCentBin]->Fill(energyclus, overSub / energyclus);
56bd3193 888 }
0c5f6f08 889 }
1f6c8e39 890 }
1f6c8e39 891
1eafa82a 892 if (fIsEmbedded && fDoExact) {
893 Esub -= overSub;
894 if (EclusBkgcorr + EclusMCcorr > 0) {
895 Double_t newfrac = EclusMCcorr / (EclusBkgcorr + EclusMCcorr);
896 cluster->SetMCEnergyFraction(newfrac);
897 }
898 }
899
181a0a09 900 // apply the correction
1f6c8e39 901 energyclus -= Esub;
902
903 return energyclus;
0b777a09 904}