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"
23 #include "AliHadCorrTask.h"
25 ClassImp(AliHadCorrTask)
27 //________________________________________________________________________
28 AliHadCorrTask::AliHadCorrTask() :
29 AliAnalysisTaskEmcal("AliHadCorrTask", kFALSE),
39 fHistNclusMatchvsCent(0),
44 fHistNClusMatchCent(0)
46 // Default constructor.
48 for(Int_t i=0; i<8; i++) {
50 fHistEsubPchRat[i] = 0;
53 fHistMatchEvsP[i] = 0;
54 fHistMatchdRvsEP[i] = 0;
55 fHistNMatchEnergy[i] = 0;
57 for(Int_t j=0; j<4; j++)
58 fHistNCellsEnergy[i][j] = 0;
61 for(Int_t j=0; j<9; j++) {
62 for(Int_t k=0; k<2; k++)
63 fHistMatchEtaPhi[i][j][k] = 0;
68 //________________________________________________________________________
69 AliHadCorrTask::AliHadCorrTask(const char *name, Bool_t histo) :
70 AliAnalysisTaskEmcal(name, histo),
71 fOutCaloName("CaloClustersCorr"),
80 fHistNclusMatchvsCent(0),
85 fHistNClusMatchCent(0)
87 // Standard constructor.
89 for(Int_t i=0; i<8; i++) {
91 fHistEsubPchRat[i] = 0;
94 fHistMatchEvsP[i] = 0;
95 fHistMatchdRvsEP[i] = 0;
96 fHistNMatchEnergy[i] = 0;
98 for(Int_t j=0; j<4; j++)
99 fHistNCellsEnergy[i][j] = 0;
102 for(Int_t j=0; j<9; j++) {
103 for(Int_t k=0; k<2; k++)
104 fHistMatchEtaPhi[i][j][k] = 0;
108 SetMakeGeneralHistograms(histo);
110 fBranchNames="ESD:AliESDRun.,AliESDHeader.,PrimaryVertex.";
113 //________________________________________________________________________
114 AliHadCorrTask::~AliHadCorrTask()
119 //________________________________________________________________________
120 Int_t AliHadCorrTask::GetMomBin(Double_t p) const
127 else if (p>=0.5 && p<1.0)
129 else if (p>=1.0 && p<1.5)
131 else if (p>=1.5 && p<2.)
133 else if (p>=2. && p<3.)
135 else if (p>=3. && p<4.)
137 else if (p>=4. && p<5.)
139 else if (p>=5. && p<8.)
147 //________________________________________________________________________
148 Double_t AliHadCorrTask::GetEtaSigma(Int_t pbin) const
152 Double_t EtaSigma[9]={0.0097,0.0075,0.0059,0.0055,0.0053,0.005,0.005,0.0045,0.0042};
153 return 2.0*EtaSigma[pbin];
156 //________________________________________________________________________
157 Double_t AliHadCorrTask::GetPhiMean(Int_t pbin, Int_t centbin) const
162 Double_t PhiMean[9]={0.036,
171 return PhiMean[pbin];
172 } else if (centbin==1) {
173 Double_t PhiMean[9]={0.036,
182 return PhiMean[pbin];
183 } else if (centbin==2) {
184 Double_t PhiMean[9]={0.036,
193 return PhiMean[pbin];
194 } else if (centbin==3) {
195 Double_t PhiMean[9]={0.036,
204 return PhiMean[pbin];
205 } else if (centbin==4) {
206 Double_t PhiMean[9]={0.036,
215 return PhiMean[pbin]*(-1.);
216 } else if (centbin==5) {
217 Double_t PhiMean[9]={0.036,
226 return PhiMean[pbin]*(-1.);
227 } else if (centbin==6) {
228 Double_t PhiMean[9]={0.036,
237 return PhiMean[pbin]*(-1.);
238 } else if (centbin==7) {
239 Double_t PhiMean[9]={0.036,
248 return PhiMean[pbin]*(-1.);
254 //________________________________________________________________________
255 Double_t AliHadCorrTask::GetPhiSigma(Int_t pbin, Int_t centbin) const
260 Double_t PhiSigma[9]={0.0221,
269 return 2.*PhiSigma[pbin];
270 } else if (centbin==1) {
271 Double_t PhiSigma[9]={0.0217,
280 return 2.*PhiSigma[pbin];
281 } else if (centbin==2) {
282 Double_t PhiSigma[9]={0.0211,
291 return 2.*PhiSigma[pbin];
292 } else if (centbin==3) {
293 Double_t PhiSigma[9]={0.0215,
302 return 2.*PhiSigma[pbin];
303 } else if (centbin==4) {
304 Double_t PhiSigma[9]={0.0199,
313 return 2.*PhiSigma[pbin];
314 } else if (centbin==5) {
315 Double_t PhiSigma[9]={0.0200,
324 return 2.*PhiSigma[pbin];
325 } else if (centbin==6) {
326 Double_t PhiSigma[9]={0.0202,
335 return 2.*PhiSigma[pbin];
336 } else if (centbin==7) {
337 Double_t PhiSigma[9]={0.0205,
346 return 2.*PhiSigma[pbin];
352 //________________________________________________________________________
353 void AliHadCorrTask::UserCreateOutputObjects()
355 // Create my user objects.
360 AliAnalysisTaskEmcal::UserCreateOutputObjects();
364 for(Int_t icent=0; icent<8; ++icent) {
365 for(Int_t ipt=0; ipt<9; ++ipt) {
366 for(Int_t ieta=0; ieta<2; ++ieta) {
367 name = Form("fHistMatchEtaPhi_%i_%i_%i",icent,ipt,ieta);
368 fHistMatchEtaPhi[icent][ipt][ieta] = new TH2F(name, name, 200, -0.1, 0.1, 400, -0.2, 0.2);
369 fOutput->Add(fHistMatchEtaPhi[icent][ipt][ieta]);
373 name = Form("fHistEsubPch_%i",icent);
374 fHistEsubPch[icent]=new TH1F(name, name, 400, 0., 100.);
375 fOutput->Add(fHistEsubPch[icent]);
377 name = Form("fHistEsubPchRat_%i",icent);
378 fHistEsubPchRat[icent]=new TH2F(name, name, 400, 0., 200., 1000, 0., 10.);
379 fOutput->Add(fHistEsubPchRat[icent]);
382 for(Int_t itrk=0; itrk<4; ++itrk) {
383 name = Form("fHistNCellsEnergy_%i_%i",icent,itrk);
384 fHistNCellsEnergy[icent][itrk] = new TH2F(name, name, 1000, 0, 100, 101, -0.5, 100.5);
385 fOutput->Add(fHistNCellsEnergy[icent][itrk]);
388 name = Form("fHistMatchEvsP_%i",icent);
389 fHistMatchEvsP[icent] = new TH2F(name, name, 400, 0., 200., 1000, 0., 10.);
390 fOutput->Add(fHistMatchEvsP[icent]);
392 name = Form("fHistMatchdRvsEP_%i",icent);
393 fHistMatchdRvsEP[icent] = new TH2F(name, name, 1000, 0., 1., 1000, 0., 10.);
394 fOutput->Add(fHistMatchdRvsEP[icent]);
396 name = Form("fHistNMatchEnergy_%i",icent);
397 fHistNMatchEnergy[icent] = new TH2F(name, name, 1000, 0, 100, 101, -0.5, 100.5);
398 fOutput->Add(fHistNMatchEnergy[icent]);
402 fHistNclusvsCent = new TH1F("Nclusvscent", "NclusVsCent", 100, 0, 100);
403 fHistNclusMatchvsCent = new TH1F("NclusMatchvscent", "NclusMatchVsCent", 100, 0, 100);
404 fHistEbefore = new TH1F("Ebefore", "Ebefore", 100, 0, 100);
405 fHistEafter = new TH1F("Eafter", "Eafter", 100, 0, 100);
406 fHistEoPCent = new TH2F("EoPCent", "EoPCent", 100, 0, 100, 1000, 0, 10);
407 fHistNMatchCent = new TH2F("NMatchesCent", "NMatchesCent", 100, 0, 100, 11, -0.5, 10.5);
408 fHistNClusMatchCent = new TH2F("NClusMatchesCent", "NClusMatchesCent", 100, 0, 100, 11, -0.5, 10.5);
410 fOutput->Add(fHistNclusMatchvsCent);
411 fOutput->Add(fHistNclusvsCent);
412 fOutput->Add(fHistEbefore);
413 fOutput->Add(fHistEafter);
414 fOutput->Add(fHistEoPCent);
415 fOutput->Add(fHistNMatchCent);
416 fOutput->Add(fHistNClusMatchCent);
418 PostData(1, fOutput);
421 //________________________________________________________________________
422 void AliHadCorrTask::ExecOnce()
424 // Init the analysis.
426 AliAnalysisTaskEmcal::ExecOnce();
431 if (dynamic_cast<AliAODEvent*>(InputEvent()))
434 if (fEsdMode) { // optimization in case autobranch loading is off
435 AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
436 if (fCaloName == "CaloClusters")
437 am->LoadBranch("CaloClusters");
438 if (fTracksName == "Tracks")
439 am->LoadBranch("Tracks");
440 am->LoadBranch("Centrality.");
444 fOutClusters = new TClonesArray("AliESDCaloCluster");
446 fOutClusters = new TClonesArray("AliAODCaloCluster");
448 fOutClusters->SetName(fOutCaloName);
450 // post output in event if not yet present
451 if (!(InputEvent()->FindListObject(fOutCaloName))) {
452 InputEvent()->AddObject(fOutClusters);
455 fInitialized = kFALSE;
456 AliFatal(Form("%s: Container with same name %s already present. Aborting", GetName(), fOutCaloName.Data()));
461 //________________________________________________________________________
462 void AliHadCorrTask::DoTrackLoop()
464 const Int_t Ntracks = fTracks->GetEntries();
465 for (Int_t iTrk = 0; iTrk < Ntracks; ++iTrk) {
466 Int_t NmatchClus = 0;
468 AliEmcalParticle *emctrack = static_cast<AliEmcalParticle*>(fTracks->At(iTrk));
471 if (!emctrack->IsEMCAL())
474 AliVTrack *track = emctrack->GetTrack();
477 if (!AcceptTrack(track))
480 if (track->GetTrackEtaOnEMCal() < fGeom->GetArm1EtaMin() + fEtaMatch ||
481 track->GetTrackEtaOnEMCal() > fGeom->GetArm1EtaMax() - fEtaMatch ||
482 track->GetTrackPhiOnEMCal() < fGeom->GetArm1PhiMin() * TMath::DegToRad() + fPhiMatch ||
483 track->GetTrackPhiOnEMCal() > fGeom->GetArm1PhiMax() * TMath::DegToRad() - fPhiMatch)
486 Int_t Nclus = emctrack->GetNumberOfMatchedObj();
488 for (Int_t iClus = 0; iClus < Nclus; ++iClus) {
489 AliEmcalParticle *emccluster = static_cast<AliEmcalParticle*>(fCaloClusters->At(iClus));
493 AliVCluster *cluster = emccluster->GetCluster();
496 if (!AcceptCluster(cluster))
499 Double_t etadiff = 999;
500 Double_t phidiff = 999;
501 AliPicoTrack::GetEtaPhiDiff(track, cluster, phidiff, etadiff);
503 if (TMath::Abs(phidiff) < fPhiMatch && TMath::Abs(etadiff) < fEtaMatch)
506 fHistNClusMatchCent->Fill(fCent, NmatchClus);
510 //________________________________________________________________________
511 void AliHadCorrTask::DoMatchedTracksLoop(AliEmcalParticle *emccluster, Double_t &totalTrkP, Int_t &Nmatches)
513 // Do the loop over matched tracks for cluster emccluster.
515 AliVCluster *cluster = emccluster->GetCluster();
516 Int_t iClus = emccluster->IdInCollection();
517 Double_t energyclus = cluster->E();
519 // loop over matched tracks
520 const Int_t Ntrks = emccluster->GetNumberOfMatchedObj();
521 for (Int_t i = 0; i < Ntrks; ++i) {
522 Int_t iTrack = emccluster->GetMatchedObjId(i);
523 Double_t dR = emccluster->GetMatchedObjDistance(i);
525 AliEmcalParticle *emctrack = static_cast<AliEmcalParticle*>(fTracks->At(iTrack));
528 AliVTrack *track = emctrack->GetTrack();
531 if (!AcceptTrack(track))
534 // check if track also points to cluster
535 if (fDoTrackClus && (track->GetEMCALcluster()) != iClus)
538 Double_t etadiff = 999;
539 Double_t phidiff = 999;
540 AliPicoTrack::GetEtaPhiDiff(track, cluster, phidiff, etadiff);
542 Double_t mom = track->P();
543 Int_t mombin = GetMomBin(mom);
544 Int_t centbinch = fCentBin;
545 if (track->Charge()<0)
550 if(track->Eta() > 0) etabin=1;
551 fHistMatchEtaPhi[centbinch][mombin][etabin]->Fill(etadiff, phidiff);
554 Double_t etaCut = 0.0;
555 Double_t phiCutlo = 0.0;
556 Double_t phiCuthi = 0.0;
559 phiCutlo = -fPhiMatch;
560 phiCuthi = +fPhiMatch;
562 phiCutlo = GetPhiMean(mombin, centbinch) - GetPhiSigma(mombin, fCentBin);
563 phiCuthi = GetPhiMean(mombin, centbinch) + GetPhiSigma(mombin, fCentBin);
569 etaCut = GetEtaSigma(mombin);
572 if ((phidiff < phiCuthi && phidiff > phiCutlo) && TMath::Abs(etadiff) < etaCut) {
574 totalTrkP += track->P();
577 if (fHadCorr > 1 && mombin > -1) {
578 fHistMatchdRvsEP[fCentBin]->Fill(dR, energyclus / mom);
585 //________________________________________________________________________
586 Bool_t AliHadCorrTask::Run()
588 // Run the hadronic correction
594 fOutClusters->Delete();
596 // loop over all clusters
597 const Int_t Nclus = fCaloClusters->GetEntries();
598 for (Int_t iClus = 0, clusCount=0; iClus < Nclus; ++iClus) {
599 AliEmcalParticle *emccluster = static_cast<AliEmcalParticle*>(fCaloClusters->At(iClus));
603 AliVCluster *cluster = emccluster->GetCluster();
606 if (!AcceptCluster(cluster))
609 Double_t energyclus = 0;
611 fHistEbefore->Fill(fCent, cluster->E());
613 // apply correction / subtraction
615 // to subtract only the closest track set fHadCor to a %
616 // to subtract all tracks within the cut set fHadCor to %+1
618 energyclus = ApplyHadCorrAllTracks(emccluster, fHadCorr - 1);
620 energyclus = ApplyHadCorrOneTrack(emccluster, fHadCorr);
626 if (energyclus > 0) { // create corrected cluster
629 AliESDCaloCluster *ec = dynamic_cast<AliESDCaloCluster*>(cluster);
632 oc = new ((*fOutClusters)[clusCount]) AliESDCaloCluster(*ec);
634 AliAODCaloCluster *ac = dynamic_cast<AliAODCaloCluster*>(cluster);
637 oc = new ((*fOutClusters)[clusCount]) AliAODCaloCluster(*ac);
639 oc->SetE(energyclus);
644 fHistEafter->Fill(fCent, energyclus);
651 //________________________________________________________________________
652 Double_t AliHadCorrTask::ApplyHadCorrOneTrack(AliEmcalParticle *emccluster, Double_t hadCorr)
654 // Apply the hadronic correction with one track only.
656 AliVCluster *cluster = emccluster->GetCluster();
657 Double_t energyclus = cluster->E();
658 Int_t iMin = emccluster->GetMatchedObjId();
662 AliEmcalParticle *emctrack = static_cast<AliEmcalParticle*>(fTracks->At(iMin));
666 // check if track also points to cluster
667 Int_t cid = emctrack->GetMatchedObjId();
668 if (fDoTrackClus && (cid!=emccluster->IdInCollection()))
671 AliVTrack *track = emctrack->GetTrack();
675 Double_t mom = track->P();
679 Double_t dRmin = emccluster->GetMatchedObjDistance();
680 Double_t dEtaMin = 1e9;
681 Double_t dPhiMin = 1e9;
682 AliPicoTrack::GetEtaPhiDiff(track, cluster, dPhiMin, dEtaMin);
684 Int_t mombin = GetMomBin(mom);
685 Int_t centbinch = fCentBin;
686 if (track->Charge()<0)
689 // plot some histograms if switched on
695 fHistMatchEtaPhi[centbinch][mombin][etabin]->Fill(dEtaMin, dPhiMin);
698 fHistMatchEvsP[fCentBin]->Fill(energyclus, energyclus / mom);
699 fHistEoPCent->Fill(fCent, energyclus / mom);
700 fHistMatchdRvsEP[fCentBin]->Fill(dRmin, energyclus / mom);
704 // define eta/phi cuts
705 Double_t etaCut = 0.0;
706 Double_t phiCutlo = 0.0;
707 Double_t phiCuthi = 0.0;
709 phiCutlo = -fPhiMatch;
710 phiCuthi = +fPhiMatch;
713 phiCutlo = GetPhiMean(mombin, centbinch) - GetPhiSigma(mombin, fCentBin);
714 phiCuthi = GetPhiMean(mombin, centbinch) + GetPhiSigma(mombin, fCentBin);
720 etaCut = GetEtaSigma(mombin);
723 // apply the correction if the track is in the eta/phi window
724 if ((dPhiMin < phiCuthi && dPhiMin > phiCutlo) && TMath::Abs(dEtaMin) < etaCut) {
725 energyclus -= hadCorr * mom;
731 //________________________________________________________________________
732 Double_t AliHadCorrTask::ApplyHadCorrAllTracks(AliEmcalParticle *emccluster, Double_t hadCorr)
734 // Apply the hadronic correction with all tracks.
736 AliVCluster *cluster = emccluster->GetCluster();
738 Double_t energyclus = cluster->E();
739 Double_t cNcells = cluster->GetNCells();
741 Double_t totalTrkP = 0.0; // count total track momentum
742 Int_t Nmatches = 0; // count total number of matches
744 // do the loop over the matched tracks and get the number of matches and the total momentum
745 DoMatchedTracksLoop(emccluster, totalTrkP, Nmatches);
747 Double_t Esub = hadCorr * totalTrkP;
749 if (Esub > energyclus)
752 // applying Peter's proposed algorithm
753 // never subtract the full energy of the cluster
754 Double_t clusEexcl = fEexclCell * cNcells;
755 if (energyclus < clusEexcl)
756 clusEexcl = energyclus;
757 if ((energyclus - Esub) < clusEexcl)
758 Esub = (energyclus - clusEexcl);
762 EoP = energyclus / totalTrkP;
764 // plot some histograms if switched on
766 fHistNclusvsCent->Fill(fCent);
767 fHistNMatchCent->Fill(fCent, Nmatches);
768 fHistNMatchEnergy[fCentBin]->Fill(energyclus, Nmatches);
771 fHistNclusMatchvsCent->Fill(fCent);
774 fHistNCellsEnergy[fCentBin][Nmatches]->Fill(energyclus, cNcells);
776 fHistNCellsEnergy[fCentBin][3]->Fill(energyclus, cNcells);
779 fHistEoPCent->Fill(fCent, EoP);
780 fHistMatchEvsP[fCentBin]->Fill(energyclus, EoP);
783 if (Nmatches == 1 && totalTrkP > 0) {
784 Int_t iMin = emccluster->GetMatchedObjId();
785 AliEmcalParticle *emctrack = static_cast<AliEmcalParticle*>(fTracks->At(iMin));
786 AliVTrack *track = emctrack->GetTrack();
787 Int_t centbinchm = fCentBin;
788 if (track->Charge()<0)
791 fHistEsubPchRat[centbinchm]->Fill(totalTrkP, Esub / totalTrkP);
792 fHistEsubPch[centbinchm]->Fill(totalTrkP, Esub);
796 // apply the correction