3 // Hadronic correction task.
5 // Author: R.Reed, C.Loizides, S.Aiola
8 #include <TClonesArray.h>
13 #include "AliAnalysisManager.h"
14 #include "AliAODEvent.h"
15 #include "AliAODCaloCluster.h"
16 #include "AliESDCaloCluster.h"
17 #include "AliVTrack.h"
18 #include "AliPicoTrack.h"
19 #include "AliVEventHandler.h"
20 #include "AliEmcalParticle.h"
21 #include "AliEMCALGeometry.h"
22 #include "AliParticleContainer.h"
23 #include "AliClusterContainer.h"
25 #include "AliHadCorrTask.h"
27 ClassImp(AliHadCorrTask)
29 //________________________________________________________________________
30 AliHadCorrTask::AliHadCorrTask() :
31 AliAnalysisTaskEmcal("AliHadCorrTask", kFALSE),
41 fHistMatchEtaPhiAll(0),
42 fHistMatchEtaPhiAllTr(0),
43 fHistMatchEtaPhiAllCl(0),
45 fHistNclusMatchvsCent(0),
50 fHistNClusMatchCent(0)
52 // Default constructor.
54 for(Int_t i=0; i<8; i++) {
56 fHistEsubPchRat[i] = 0;
57 fHistEsubPchRatAll[i] = 0;
60 fHistMatchEvsP[i] = 0;
61 fHistMatchdRvsEP[i] = 0;
62 fHistNMatchEnergy[i] = 0;
64 fHistEmbTrackMatchesOversub[i] = 0;
65 fHistNonEmbTrackMatchesOversub[i] = 0;
66 fHistOversubMCClusters[i] = 0;
67 fHistOversubNonMCClusters[i] = 0;
70 for(Int_t j=0; j<4; j++)
71 fHistNCellsEnergy[i][j] = 0;
74 for(Int_t j=0; j<9; j++) {
75 for(Int_t k=0; k<2; k++)
76 fHistMatchEtaPhi[i][j][k] = 0;
81 //________________________________________________________________________
82 AliHadCorrTask::AliHadCorrTask(const char *name, Bool_t histo) :
83 AliAnalysisTaskEmcal(name, histo),
84 fOutCaloName("CaloClustersCorr"),
93 fHistMatchEtaPhiAll(0),
94 fHistMatchEtaPhiAllTr(0),
95 fHistMatchEtaPhiAllCl(0),
97 fHistNclusMatchvsCent(0),
102 fHistNClusMatchCent(0)
104 // Standard constructor.
106 for(Int_t i=0; i<8; i++) {
108 fHistEsubPchRat[i] = 0;
109 fHistEsubPchRatAll[i] = 0;
112 fHistMatchEvsP[i] = 0;
113 fHistMatchdRvsEP[i] = 0;
114 fHistNMatchEnergy[i] = 0;
116 fHistEmbTrackMatchesOversub[i] = 0;
117 fHistNonEmbTrackMatchesOversub[i] = 0;
118 fHistOversubMCClusters[i] = 0;
119 fHistOversubNonMCClusters[i] = 0;
122 for(Int_t j=0; j<4; j++)
123 fHistNCellsEnergy[i][j] = 0;
126 for(Int_t j=0; j<9; j++) {
127 for(Int_t k=0; k<2; k++)
128 fHistMatchEtaPhi[i][j][k] = 0;
132 SetMakeGeneralHistograms(histo);
134 fBranchNames="ESD:AliESDRun.,AliESDHeader.,PrimaryVertex.";
137 //________________________________________________________________________
138 AliHadCorrTask::~AliHadCorrTask()
143 //________________________________________________________________________
144 UInt_t AliHadCorrTask::GetMomBin(Double_t p) const
151 else if (p>=0.5 && p<1.0)
153 else if (p>=1.0 && p<1.5)
155 else if (p>=1.5 && p<2.)
157 else if (p>=2. && p<3.)
159 else if (p>=3. && p<4.)
161 else if (p>=4. && p<5.)
163 else if (p>=5. && p<8.)
171 //________________________________________________________________________
172 Double_t AliHadCorrTask::GetEtaSigma(Int_t pbin) const
176 Double_t EtaSigma[9]={0.0097,0.0075,0.0059,0.0055,0.0053,0.005,0.005,0.0045,0.0042};
177 return 2.0*EtaSigma[pbin];
180 //________________________________________________________________________
181 Double_t AliHadCorrTask::GetPhiMean(Int_t pbin, Int_t centbin) const
186 Double_t PhiMean[9]={0.036,
195 return PhiMean[pbin];
196 } else if (centbin==1) {
197 Double_t PhiMean[9]={0.036,
206 return PhiMean[pbin];
207 } else if (centbin==2) {
208 Double_t PhiMean[9]={0.036,
217 return PhiMean[pbin];
218 } else if (centbin==3) {
219 Double_t PhiMean[9]={0.036,
228 return PhiMean[pbin];
229 } else if (centbin==4) {
230 Double_t PhiMean[9]={0.036,
239 return PhiMean[pbin]*(-1.);
240 } else if (centbin==5) {
241 Double_t PhiMean[9]={0.036,
250 return PhiMean[pbin]*(-1.);
251 } else if (centbin==6) {
252 Double_t PhiMean[9]={0.036,
261 return PhiMean[pbin]*(-1.);
262 } else if (centbin==7) {
263 Double_t PhiMean[9]={0.036,
272 return PhiMean[pbin]*(-1.);
278 //________________________________________________________________________
279 Double_t AliHadCorrTask::GetPhiSigma(Int_t pbin, Int_t centbin) const
284 Double_t PhiSigma[9]={0.0221,
293 return 2.*PhiSigma[pbin];
294 } else if (centbin==1) {
295 Double_t PhiSigma[9]={0.0217,
304 return 2.*PhiSigma[pbin];
305 } else if (centbin==2) {
306 Double_t PhiSigma[9]={0.0211,
315 return 2.*PhiSigma[pbin];
316 } else if (centbin==3) {
317 Double_t PhiSigma[9]={0.0215,
326 return 2.*PhiSigma[pbin];
327 } else if (centbin==4) {
328 Double_t PhiSigma[9]={0.0199,
337 return 2.*PhiSigma[pbin];
338 } else if (centbin==5) {
339 Double_t PhiSigma[9]={0.0200,
348 return 2.*PhiSigma[pbin];
349 } else if (centbin==6) {
350 Double_t PhiSigma[9]={0.0202,
359 return 2.*PhiSigma[pbin];
360 } else if (centbin==7) {
361 Double_t PhiSigma[9]={0.0205,
370 return 2.*PhiSigma[pbin];
376 //________________________________________________________________________
377 void AliHadCorrTask::UserCreateOutputObjects()
379 // Create my user objects.
381 AliAnalysisTaskEmcal::UserCreateOutputObjects();
383 if (!fCreateHisto) return;
388 const Int_t nCentChBins = fNcentBins * 2;
390 fHistMatchEtaPhiAll = new TH2F("fHistMatchEtaPhiAll", "fHistMatchEtaPhiAll;#Delta#eta;#Delta#phi", fNbins, -0.1, 0.1, fNbins, -0.1, 0.1);
391 fOutput->Add(fHistMatchEtaPhiAll);
393 fHistMatchEtaPhiAllTr = new TH2F("fHistMatchEtaPhiAllTr", "fHistMatchEtaPhiAllTr;#Delta#eta;#Delta#phi", fNbins, -0.1, 0.1, fNbins, -0.1, 0.1);
394 fOutput->Add(fHistMatchEtaPhiAllTr);
396 fHistMatchEtaPhiAllCl = new TH2F("fHistMatchEtaPhiAllCl", "fHistMatchEtaPhiAllCl;#Delta#eta;#Delta#phi", fNbins, -0.1, 0.1, fNbins, -0.1, 0.1);
397 fOutput->Add(fHistMatchEtaPhiAllCl);
399 for(Int_t icent=0; icent<nCentChBins; ++icent) {
400 for(Int_t ipt=0; ipt<9; ++ipt) {
401 for(Int_t ieta=0; ieta<2; ++ieta) {
402 name = Form("fHistMatchEtaPhi_%i_%i_%i",icent,ipt,ieta);
403 fHistMatchEtaPhi[icent][ipt][ieta] = new TH2F(name, name, fNbins, -0.1, 0.1, fNbins, -0.1, 0.1);
404 fHistMatchEtaPhi[icent][ipt][ieta]->SetXTitle("#Delta#eta");
405 fHistMatchEtaPhi[icent][ipt][ieta]->SetYTitle("#Delta#phi");
406 fOutput->Add(fHistMatchEtaPhi[icent][ipt][ieta]);
410 name = Form("fHistEsubPch_%i",icent);
411 temp = Form("%s (Nmatches==1)",name.Data());
412 fHistEsubPch[icent]=new TH1F(name, temp, fNbins, fMinBinPt, fMaxBinPt);
413 fHistEsubPch[icent]->SetXTitle("#sum p (GeV) weighted with E_{sub}");
414 fOutput->Add(fHistEsubPch[icent]);
416 name = Form("fHistEsubPchRat_%i",icent);
417 temp = Form("%s (Nmatches==1)",name.Data());
418 fHistEsubPchRat[icent]=new TH2F(name, temp, fNbins, fMinBinPt, fMaxBinPt, fNbins*2, 0., 10.);
419 fHistEsubPchRat[icent]->SetXTitle("#Sigma p (GeV)");
420 fHistEsubPchRat[icent]->SetYTitle("E_{sub} / #sum p");
421 fOutput->Add(fHistEsubPchRat[icent]);
423 name = Form("fHistEsubPchRatAll_%i",icent);
424 temp = Form("%s (all Nmatches)",name.Data());
425 fHistEsubPchRatAll[icent]=new TH2F(name, temp, fNbins, fMinBinPt, fMaxBinPt, fNbins*2, 0., 10.);
426 fHistEsubPchRatAll[icent]->SetXTitle("#Sigma p (GeV)");
427 fHistEsubPchRatAll[icent]->SetYTitle("E_{sub} / #sum p");
428 fOutput->Add(fHistEsubPchRatAll[icent]);
430 if (icent<fNcentBins) {
431 for(Int_t itrk=0; itrk<4; ++itrk) {
432 name = Form("fHistNCellsEnergy_%i_%i",icent,itrk);
433 temp = Form("%s (Nmatches==%d);N_{cells};E_{clus} (GeV)",name.Data(),itrk);
434 fHistNCellsEnergy[icent][itrk] = new TH2F(name, temp, fNbins, fMinBinPt, fMaxBinPt, 101, -0.5, 100.5);
435 fOutput->Add(fHistNCellsEnergy[icent][itrk]);
438 name = Form("fHistMatchEvsP_%i",icent);
439 temp = Form("%s (all Nmatches)",name.Data());
440 fHistMatchEvsP[icent] = new TH2F(name, name, fNbins, fMinBinPt, fMaxBinPt, fNbins*2, 0., 10.);
441 fHistMatchEvsP[icent]->SetXTitle("E_{clus} (GeV)");
442 fHistMatchEvsP[icent]->SetYTitle("E_{clus} / #sum p");
443 fOutput->Add(fHistMatchEvsP[icent]);
445 name = Form("fHistMatchdRvsEP_%i",icent);
446 temp = Form("%s (all Nmatches)",name.Data());
447 fHistMatchdRvsEP[icent] = new TH2F(name, temp, fNbins, 0., 0.2, fNbins*2, 0., 10.);
448 fHistMatchdRvsEP[icent]->SetXTitle("#Delta R between track and cluster");
449 fHistMatchdRvsEP[icent]->SetYTitle("E_{clus} / p");
450 fOutput->Add(fHistMatchdRvsEP[icent]);
452 name = Form("fHistNMatchEnergy_%i",icent);
453 fHistNMatchEnergy[icent] = new TH2F(name, name, fNbins, fMinBinPt, fMaxBinPt, 101, -0.5, 100.5);
454 fHistNMatchEnergy[icent]->SetXTitle("E_{clus} (GeV)");
455 fHistNMatchEnergy[icent]->SetYTitle("N_{matches}");
456 fOutput->Add(fHistNMatchEnergy[icent]);
460 fHistNclusvsCent = new TH1F("Nclusvscent", "NclusVsCent; Cent (%)", 100, 0, 100);
461 fHistNclusMatchvsCent = new TH1F("NclusMatchvscent", "NclusMatchVsCent (all Nmatches); Cent (%)", 100, 0, 100);
462 fHistEbefore = new TH1F("Ebefore", "Ebefore; Cent (%); E_{clus} (GeV)", 100, 0, 100);
463 fHistEafter = new TH1F("Eafter", "Eafter; Cent (%); E_{clus} (GeV)", 100, 0, 100);
464 fHistEoPCent = new TH2F("EoPCent", "EoPCent; Cent (%); E_{clus} / #sum p", 100, 0, 100, fNbins*2, 0, 10);
465 fHistNMatchCent = new TH2F("NMatchesCent", "NMatchesCent; Cent (%); Nmatches", 100, 0, 100, 11, -0.5, 10.5);
466 fHistNClusMatchCent = new TH2F("NClusMatchesCent", "NClusMatchesCent; Cent (%); Nmatches", 100, 0, 100, 11, -0.5, 10.5);
468 fOutput->Add(fHistNclusMatchvsCent);
469 fOutput->Add(fHistNclusvsCent);
470 fOutput->Add(fHistEbefore);
471 fOutput->Add(fHistEafter);
472 fOutput->Add(fHistEoPCent);
473 fOutput->Add(fHistNMatchCent);
474 fOutput->Add(fHistNClusMatchCent);
477 for(Int_t icent=0; icent<fNcentBins; ++icent) {
478 name = Form("fHistEmbTrackMatchesOversub_%d",icent);
479 fHistEmbTrackMatchesOversub[icent] = new TH2F(name, name, fNbins, fMinBinPt, fMaxBinPt, fNbins, 0, 1.2);
480 fHistEmbTrackMatchesOversub[icent]->GetXaxis()->SetTitle("E_{clus}^{raw} (GeV)");
481 fHistEmbTrackMatchesOversub[icent]->GetYaxis()->SetTitle("E_{oversub} / E_{clus}^{raw}");
482 fOutput->Add(fHistEmbTrackMatchesOversub[icent]);
484 name = Form("fHistNonEmbTrackMatchesOversub_%d",icent);
485 fHistNonEmbTrackMatchesOversub[icent] = new TH2F(name, name, fNbins, fMinBinPt, fMaxBinPt, fNbins, 0, 1.2);
486 fHistNonEmbTrackMatchesOversub[icent]->GetXaxis()->SetTitle("E_{clus}^{raw} (GeV)");
487 fHistNonEmbTrackMatchesOversub[icent]->GetYaxis()->SetTitle("E_{oversub} / E_{clus}^{raw}");
488 fOutput->Add(fHistNonEmbTrackMatchesOversub[icent]);
490 name = Form("fHistOversubMCClusters_%d",icent);
491 fHistOversubMCClusters[icent] = new TH2F(name, name, fNbins, fMinBinPt, fMaxBinPt, fNbins, 0, 1.2);
492 fHistOversubMCClusters[icent]->GetXaxis()->SetTitle("E_{clus}^{raw} (GeV)");
493 fHistOversubMCClusters[icent]->GetYaxis()->SetTitle("E_{oversub} / E_{clus}^{raw}");
494 fOutput->Add(fHistOversubMCClusters[icent]);
496 name = Form("fHistOversubNonMCClusters_%d",icent);
497 fHistOversubNonMCClusters[icent] = new TH2F(name, name, fNbins, fMinBinPt, fMaxBinPt, fNbins, 0, 1.2);
498 fHistOversubNonMCClusters[icent]->GetXaxis()->SetTitle("E_{clus}^{raw} (GeV)");
499 fHistOversubNonMCClusters[icent]->GetYaxis()->SetTitle("E_{oversub} / E_{clus}^{raw}");
500 fOutput->Add(fHistOversubNonMCClusters[icent]);
502 name = Form("fHistOversub_%d",icent);
503 fHistOversub[icent] = new TH2F(name, name, fNbins, fMinBinPt, fMaxBinPt, fNbins, 0, 1.2);
504 fHistOversub[icent]->GetXaxis()->SetTitle("E_{clus}^{raw} (GeV)");
505 fHistOversub[icent]->GetYaxis()->SetTitle("E_{oversub} / E_{clus}^{raw}");
506 fOutput->Add(fHistOversub[icent]);
510 PostData(1, fOutput);
513 //________________________________________________________________________
514 void AliHadCorrTask::ExecOnce()
516 // Initialize the analysis.
518 if (fParticleCollArray.GetEntriesFast()<2) {
519 AliError(Form("Wrong number of particle collections (%d), required 2",fParticleCollArray.GetEntriesFast()));
523 for (Int_t i = 0; i < 2; i++) {
524 AliParticleContainer *cont = static_cast<AliParticleContainer*>(fParticleCollArray.At(i));
525 cont->SetClassName("AliEmcalParticle");
528 // Do base class initializations and if it fails -> bail out
529 AliAnalysisTaskEmcal::ExecOnce();
530 if (!fInitialized) return;
532 if (dynamic_cast<AliAODEvent*>(InputEvent())) fEsdMode = kFALSE;
535 fOutClusters = new TClonesArray("AliESDCaloCluster");
537 fOutClusters = new TClonesArray("AliAODCaloCluster");
539 fOutClusters->SetName(fOutCaloName);
541 // post output in event if not yet present
542 if (!(InputEvent()->FindListObject(fOutCaloName))) {
543 InputEvent()->AddObject(fOutClusters);
546 fInitialized = kFALSE;
547 AliFatal(Form("%s: Container with same name %s already present. Aborting", GetName(), fOutCaloName.Data()));
552 //________________________________________________________________________
553 void AliHadCorrTask::DoTrackLoop()
555 // Loop over tracks to provide some QA
557 AliParticleContainer *tracks = static_cast<AliParticleContainer*>(fParticleCollArray.At(0));
558 AliParticleContainer *clusters = static_cast<AliParticleContainer*>(fParticleCollArray.At(1));
560 AliEmcalParticle *emctrack = 0;
562 tracks->ResetCurrentID();
563 while ((emctrack = static_cast<AliEmcalParticle*>(tracks->GetNextAcceptParticle()))) {
564 Int_t NmatchClus = 0;
566 if (!emctrack->IsEMCAL()) continue;
568 AliVTrack *track = emctrack->GetTrack();
569 if (!track) continue;
571 if (track->GetTrackEtaOnEMCal() < fGeom->GetArm1EtaMin() - fEtaMatch ||
572 track->GetTrackEtaOnEMCal() > fGeom->GetArm1EtaMax() + fEtaMatch ||
573 track->GetTrackPhiOnEMCal() < fGeom->GetArm1PhiMin() * TMath::DegToRad() - fPhiMatch ||
574 track->GetTrackPhiOnEMCal() > fGeom->GetArm1PhiMax() * TMath::DegToRad() + fPhiMatch)
577 Int_t Nclus = emctrack->GetNumberOfMatchedObj();
579 for (Int_t iClus = 0; iClus < Nclus; ++iClus) {
580 AliEmcalParticle *emccluster =
581 static_cast<AliEmcalParticle*>(clusters->GetAcceptParticle(emctrack->GetMatchedObjId(iClus)));
582 if (!emccluster) continue;
584 AliVCluster *cluster = emccluster->GetCluster();
585 if (!cluster) continue;
586 if (!cluster->IsEMCAL()) continue;
588 Double_t etadiff = 999;
589 Double_t phidiff = 999;
590 AliPicoTrack::GetEtaPhiDiff(track, cluster, phidiff, etadiff);
591 fHistMatchEtaPhiAllTr->Fill(etadiff,phidiff);
593 if (TMath::Abs(phidiff) < fPhiMatch && TMath::Abs(etadiff) < fEtaMatch) NmatchClus++;
595 fHistNClusMatchCent->Fill(fCent, NmatchClus);
599 //________________________________________________________________________
600 void AliHadCorrTask::DoMatchedTracksLoop(AliEmcalParticle *emccluster,
601 Double_t &totalTrkP, Int_t &Nmatches, Double_t &trkPMCfrac, Int_t &NMCmatches)
603 // Do the loop over matched tracks for cluster emccluster.
605 AliParticleContainer *tracks = static_cast<AliParticleContainer*>(fParticleCollArray.At(0));
606 AliVCluster *cluster = emccluster->GetCluster();
607 Int_t iClus = emccluster->IdInCollection();
609 // loop over matched tracks
610 const Int_t Ntrks = emccluster->GetNumberOfMatchedObj();
611 for (Int_t i = 0; i < Ntrks; ++i) {
612 Int_t iTrack = emccluster->GetMatchedObjId(i);
614 AliEmcalParticle *emctrack = static_cast<AliEmcalParticle*>(tracks->GetAcceptParticle(iTrack));
615 if (!emctrack) continue;
617 AliVTrack *track = emctrack->GetTrack();
618 if (!track) continue;
620 Double_t etadiff = 999;
621 Double_t phidiff = 999;
622 AliPicoTrack::GetEtaPhiDiff(track, cluster, phidiff, etadiff);
624 fHistMatchEtaPhiAllCl->Fill(etadiff, phidiff);
626 // check if track also points to cluster
627 if (fDoTrackClus && (emctrack->GetMatchedObjId(0)) != iClus) continue;
629 Double_t mom = track->P();
630 UInt_t mombin = GetMomBin(mom);
631 Int_t centbinch = fCentBin;
632 if (track->Charge()<0)
633 centbinch += fNcentBins;
637 if(track->Eta() > 0) etabin=1;
638 fHistMatchEtaPhi[centbinch][mombin][etabin]->Fill(etadiff, phidiff);
639 fHistMatchEtaPhiAll->Fill(etadiff, phidiff);
642 Double_t etaCut = 0.0;
643 Double_t phiCutlo = 0.0;
644 Double_t phiCuthi = 0.0;
647 phiCutlo = -fPhiMatch;
648 phiCuthi = +fPhiMatch;
650 phiCutlo = GetPhiMean(mombin, centbinch) - GetPhiSigma(mombin, fCentBin);
651 phiCuthi = GetPhiMean(mombin, centbinch) + GetPhiSigma(mombin, fCentBin);
657 etaCut = GetEtaSigma(mombin);
660 if ((phidiff < phiCuthi && phidiff > phiCutlo) && TMath::Abs(etadiff) < etaCut) {
661 if (track->GetLabel() > fMinMCLabel) {
670 Double_t dR = emccluster->GetMatchedObjDistance(i);
671 Double_t energyclus = cluster->E();
672 fHistMatchdRvsEP[fCentBin]->Fill(dR, energyclus / mom);
679 trkPMCfrac /= totalTrkP;
682 //________________________________________________________________________
683 Bool_t AliHadCorrTask::Run()
685 // Run the hadronic correction
687 AliParticleContainer *clusters = static_cast<AliParticleContainer*>(fParticleCollArray.At(1));
688 AliEmcalParticle *emccluster = 0;
690 // provide some additional histograms
695 fOutClusters->Delete();
699 // loop over all clusters
700 clusters->ResetCurrentID();
701 while ((emccluster = static_cast<AliEmcalParticle*>(clusters->GetNextAcceptParticle()))) {
702 if (!emccluster->IsEMCAL()) continue;
704 AliVCluster *cluster = emccluster->GetCluster();
705 if (!cluster) continue;
707 Double_t energyclus = 0;
709 fHistEbefore->Fill(fCent, cluster->E());
710 fHistNclusvsCent->Fill(fCent);
713 // apply correction / subtraction
714 // to subtract only the closest track set fHadCor to a %
715 // to subtract all tracks within the cut set fHadCor to %+1
717 energyclus = ApplyHadCorrAllTracks(emccluster, fHadCorr - 1);
718 else if (fHadCorr > 0)
719 energyclus = ApplyHadCorrOneTrack(emccluster, fHadCorr);
721 energyclus = cluster->E();
726 if (energyclus > 0) { // create corrected cluster
729 AliESDCaloCluster *ec = dynamic_cast<AliESDCaloCluster*>(cluster);
731 oc = new ((*fOutClusters)[clusCount]) AliESDCaloCluster(*ec);
733 AliAODCaloCluster *ac = dynamic_cast<AliAODCaloCluster*>(cluster);
735 oc = new ((*fOutClusters)[clusCount]) AliAODCaloCluster(*ac);
737 oc->SetE(energyclus);
741 if (fCreateHisto) fHistEafter->Fill(fCent, energyclus);
748 //________________________________________________________________________
749 Double_t AliHadCorrTask::ApplyHadCorrOneTrack(AliEmcalParticle *emccluster, Double_t hadCorr)
751 // Apply the hadronic correction with one track only.
753 AliVCluster *cluster = emccluster->GetCluster();
754 if (!cluster) return 0;
756 Double_t energyclus = cluster->E();
757 Int_t iMin = emccluster->GetMatchedObjId();
761 AliParticleContainer *tracks = static_cast<AliParticleContainer*>(fParticleCollArray.At(0));
762 AliEmcalParticle *emctrack = static_cast<AliEmcalParticle*>(tracks->GetParticle(iMin));
763 if (!emctrack) return energyclus;
765 AliVTrack *track = emctrack->GetTrack();
766 if (!track) return energyclus;
768 Double_t mom = track->P();
769 if (mom < 1e-6) return energyclus;
771 Double_t dEtaMin = 1e9;
772 Double_t dPhiMin = 1e9;
773 AliPicoTrack::GetEtaPhiDiff(track, cluster, dPhiMin, dEtaMin);
775 fHistMatchEtaPhiAllCl->Fill(dEtaMin, dPhiMin);
777 // check if track also points to cluster
778 Int_t cid = emctrack->GetMatchedObjId();
779 if (fDoTrackClus && (cid!=emccluster->IdInCollection())) return energyclus;
781 UInt_t mombin = GetMomBin(mom);
782 Int_t centbinch = fCentBin;
783 if (track->Charge()<0) centbinch += fNcentBins;
785 // plot some histograms if switched on
791 fHistMatchEtaPhi[centbinch][mombin][etabin]->Fill(dEtaMin, dPhiMin);
792 fHistMatchEtaPhiAll->Fill(dEtaMin, dPhiMin);
795 Double_t dRmin = emccluster->GetMatchedObjDistance();
796 fHistMatchEvsP[fCentBin]->Fill(energyclus, energyclus / mom);
797 fHistEoPCent->Fill(fCent, energyclus / mom);
798 fHistMatchdRvsEP[fCentBin]->Fill(dRmin, energyclus / mom);
802 // define eta/phi cuts
803 Double_t etaCut = 0.0;
804 Double_t phiCutlo = 0.0;
805 Double_t phiCuthi = 0.0;
807 phiCutlo = -fPhiMatch;
808 phiCuthi = +fPhiMatch;
811 phiCutlo = GetPhiMean(mombin, centbinch) - GetPhiSigma(mombin, fCentBin);
812 phiCuthi = GetPhiMean(mombin, centbinch) + GetPhiSigma(mombin, fCentBin);
818 etaCut = GetEtaSigma(mombin);
821 // apply the correction if the track is in the eta/phi window
822 if ((dPhiMin < phiCuthi && dPhiMin > phiCutlo) && TMath::Abs(dEtaMin) < etaCut) {
823 energyclus -= hadCorr * mom;
829 //________________________________________________________________________
830 Double_t AliHadCorrTask::ApplyHadCorrAllTracks(AliEmcalParticle *emccluster, Double_t hadCorr)
832 // Apply the hadronic correction with all tracks.
834 AliParticleContainer *tracks = static_cast<AliParticleContainer*>(fParticleCollArray.At(0));
836 AliVCluster *cluster = emccluster->GetCluster();
838 Double_t energyclus = cluster->E();
839 Double_t cNcells = cluster->GetNCells();
841 Double_t totalTrkP = 0.0; // count total track momentum
842 Int_t Nmatches = 0; // count total number of matches
844 Double_t trkPMCfrac = 0.0; // count total track momentum
845 Int_t NMCmatches = 0; // count total number of matches
847 // do the loop over the matched tracks and get the number of matches and the total momentum
848 DoMatchedTracksLoop(emccluster, totalTrkP, Nmatches, trkPMCfrac, NMCmatches);
850 Double_t Esub = hadCorr * totalTrkP;
852 if (Esub > energyclus) Esub = energyclus;
854 // applying Peter's proposed algorithm
855 // never subtract the full energy of the cluster
856 Double_t clusEexcl = fEexclCell * cNcells;
857 if (energyclus < clusEexcl) clusEexcl = energyclus;
858 if ((energyclus - Esub) < clusEexcl) Esub = (energyclus - clusEexcl);
862 Double_t EsubBkg = 0;
863 Double_t EclusMC = 0;
864 Double_t EclusBkg = 0;
865 Double_t EclusCorr = 0;
866 Double_t EclusMCcorr = 0;
867 Double_t EclusBkgcorr = 0;
868 Double_t overSub = 0;
870 EsubMC = hadCorr * totalTrkP * trkPMCfrac;
871 EsubBkg = hadCorr * totalTrkP - EsubMC;
872 EclusMC = energyclus * cluster->GetMCEnergyFraction();
873 EclusBkg = energyclus - EclusMC;
875 if (energyclus > Esub)
876 EclusCorr = energyclus - Esub;
878 if (EclusMC > EsubMC)
879 EclusMCcorr = EclusMC - EsubMC;
881 if (EclusBkg > EsubBkg)
882 EclusBkgcorr = EclusBkg - EsubBkg;
884 overSub = EclusMCcorr + EclusBkgcorr - EclusCorr;
887 // plot some histograms if switched on
889 fHistNMatchCent->Fill(fCent, Nmatches);
890 fHistNMatchEnergy[fCentBin]->Fill(energyclus, Nmatches);
893 fHistNclusMatchvsCent->Fill(fCent);
896 fHistNCellsEnergy[fCentBin][Nmatches]->Fill(energyclus, cNcells);
898 fHistNCellsEnergy[fCentBin][3]->Fill(energyclus, cNcells);
901 Double_t EoP = energyclus / totalTrkP;
902 fHistEoPCent->Fill(fCent, EoP);
903 fHistMatchEvsP[fCentBin]->Fill(energyclus, EoP);
905 fHistEsubPchRatAll[fCentBin]->Fill(totalTrkP, Esub / totalTrkP);
908 Int_t iMin = emccluster->GetMatchedObjId();
909 AliEmcalParticle *emctrack = static_cast<AliEmcalParticle*>(tracks->GetParticle(iMin));
911 AliVTrack *track = emctrack->GetTrack();
913 Int_t centbinchm = fCentBin;
914 if (track->Charge()<0) centbinchm += fNcentBins;
915 fHistEsubPchRat[centbinchm]->Fill(totalTrkP, Esub / totalTrkP);
916 fHistEsubPch[centbinchm]->Fill(totalTrkP, Esub);
922 fHistOversub[fCentBin]->Fill(energyclus, overSub / energyclus);
924 if (cluster->GetMCEnergyFraction() > 0.95)
925 fHistOversubMCClusters[fCentBin]->Fill(energyclus, overSub / energyclus);
926 else if (cluster->GetMCEnergyFraction() < 0.05)
927 fHistOversubNonMCClusters[fCentBin]->Fill(energyclus, overSub / energyclus);
929 if (trkPMCfrac < 0.05)
930 fHistNonEmbTrackMatchesOversub[fCentBin]->Fill(energyclus, overSub / energyclus);
931 else if (trkPMCfrac > 0.95)
932 fHistEmbTrackMatchesOversub[fCentBin]->Fill(energyclus, overSub / energyclus);
937 if (fIsEmbedded && fDoExact) {
939 if (EclusBkgcorr + EclusMCcorr > 0) {
940 Double_t newfrac = EclusMCcorr / (EclusBkgcorr + EclusMCcorr);
941 cluster->SetMCEnergyFraction(newfrac);
945 // apply the correction