2 // Utility class to do jet-by-jet correction
3 // Based on templates of ptJet vs ptTrack vs r
12 #include "TLorentzVector.h"
13 #include "AliEmcalJet.h"
14 #include "AliVParticle.h"
16 #include "AliEmcalJetByJetCorrection.h"
18 ClassImp(AliEmcalJetByJetCorrection)
20 //__________________________________________________________________________
21 AliEmcalJetByJetCorrection::AliEmcalJetByJetCorrection() :
23 fh3JetPtDRTrackPt(0x0),
31 fpAppliedEfficiency(0)
34 fCollTemplates.SetOwner(kTRUE);
37 //__________________________________________________________________________
38 AliEmcalJetByJetCorrection::AliEmcalJetByJetCorrection(const char* name) :
40 fh3JetPtDRTrackPt(0x0),
48 fpAppliedEfficiency(0)
50 // Default constructor.
51 fCollTemplates.SetOwner(kTRUE);
53 const Int_t nBinPt = 118; //0-2: 20 bins; 2-100: 98 bins
54 Double_t binLimitsPt[nBinPt+1];
55 for(Int_t iPt = 0;iPt <= nBinPt;iPt++){
57 binLimitsPt[iPt] = 0. + (Double_t)iPt*0.15;
59 binLimitsPt[iPt] = binLimitsPt[iPt-1] + 1.0;
62 fpAppliedEfficiency = new TProfile("fpAppliedEfficiency","fpAppliedEfficiency",nBinPt,binLimitsPt);
65 //__________________________________________________________________________
66 AliEmcalJetByJetCorrection::AliEmcalJetByJetCorrection(const AliEmcalJetByJetCorrection &other) :
68 fh3JetPtDRTrackPt(other.fh3JetPtDRTrackPt),
69 fBinWidthJetPt(other.fBinWidthJetPt),
70 fJetPtMin(other.fJetPtMin),
71 fJetPtMax(other.fJetPtMax),
72 fCollTemplates(other.fCollTemplates),
73 fInitialized(other.fInitialized),
74 fEfficiencyFixed(other.fEfficiencyFixed),
75 fhEfficiency(other.fhEfficiency),
76 fpAppliedEfficiency(other.fpAppliedEfficiency)
81 //__________________________________________________________________________
82 AliEmcalJetByJetCorrection& AliEmcalJetByJetCorrection::operator=(const AliEmcalJetByJetCorrection &other)
85 if (&other == this) return *this;
86 TNamed::operator=(other);
87 fh3JetPtDRTrackPt = other.fh3JetPtDRTrackPt;
88 fBinWidthJetPt = other.fBinWidthJetPt;
89 fJetPtMin = other.fJetPtMin;
90 fJetPtMax = other.fJetPtMax;
91 fCollTemplates = other.fCollTemplates;
92 fInitialized = other.fInitialized;
93 fEfficiencyFixed = other.fEfficiencyFixed;
94 fhEfficiency = other.fhEfficiency;
95 fpAppliedEfficiency= other.fpAppliedEfficiency;
100 //__________________________________________________________________________
101 AliEmcalJet* AliEmcalJetByJetCorrection::Eval(const AliEmcalJet *jet, TClonesArray *fTracks) {
104 Printf("AliEmcalJetByJetCorrection %s not initialized",GetName());
108 Int_t bin = GetJetPtBin(jet->Pt());
109 if(bin<0 || bin>fCollTemplates.GetEntriesFast()) return NULL;
111 TH2D *hTemplate = static_cast<TH2D*>(fCollTemplates.At(bin));
113 Double_t meanPt = GetMeanPtConstituents(jet,fTracks);
114 Double_t eff = GetEfficiency(meanPt);
115 fpAppliedEfficiency->Fill(meanPt,eff);
117 Int_t np = TMath::FloorNint((double)jet->GetNumberOfTracks() * (1./eff -1.));
119 TLorentzVector corrVec; corrVec.SetPtEtaPhiM(jet->Pt(),jet->Eta(),jet->Phi(),jet->M());
121 Double_t mass = 0.13957; //pion mass
123 for(Int_t i = 0; i<np; i++) {
126 hTemplate->GetRandom2(r,pt);
127 Double_t t = TMath::TwoPi()*gRandom->Uniform(1.);
128 Double_t deta = r*TMath::Cos(t);
129 Double_t dphi = r*TMath::Sin(t);
130 TLorentzVector curVec;
131 curVec.SetPtEtaPhiM(pt,deta+jet->Eta(),dphi+jet->Phi(),mass);
135 AliEmcalJet *jetCorr = new AliEmcalJet(corrVec.Pt(),corrVec.Eta(),corrVec.Phi(),corrVec.M());
140 //__________________________________________________________________________
141 void AliEmcalJetByJetCorrection::Init() {
144 if(!fh3JetPtDRTrackPt) {
145 Printf("%s fh3JetPtDRTrackPt not known",GetName());
146 fInitialized = kFALSE;
150 if(fJetPtMax>fh3JetPtDRTrackPt->GetXaxis()->GetXmax())
151 fJetPtMax = fh3JetPtDRTrackPt->GetXaxis()->GetXmax();
153 if(fJetPtMin<fh3JetPtDRTrackPt->GetXaxis()->GetXmin())
154 fJetPtMin = fh3JetPtDRTrackPt->GetXaxis()->GetXmin();
156 Double_t eps = 0.00001;
158 for(Double_t ptmin = fJetPtMin; ptmin<fJetPtMax; ptmin+=fBinWidthJetPt) {
159 Int_t binMin = fh3JetPtDRTrackPt->GetXaxis()->FindBin(ptmin+eps);
160 Int_t binMax = fh3JetPtDRTrackPt->GetXaxis()->FindBin(ptmin+fBinWidthJetPt-eps);
161 // Printf("%d bins: %d - %d -> %f - %f",counter,binMin,binMax,fh3JetPtDRTrackPt->GetXaxis()->GetBinLowEdge(binMin),fh3JetPtDRTrackPt->GetXaxis()->GetBinUpEdge(binMax));
163 fh3JetPtDRTrackPt->GetXaxis()->SetRange(binMin,binMax);
164 TH2D *h2 = dynamic_cast<TH2D*>(fh3JetPtDRTrackPt->Project3D("zy"));
165 h2->SetName(Form("hPtR_%.0f_%.0f",fh3JetPtDRTrackPt->GetXaxis()->GetBinLowEdge(binMin),fh3JetPtDRTrackPt->GetXaxis()->GetBinUpEdge(binMax)));
166 fCollTemplates.Add(h2);
169 // Int_t nt = TMath::FloorNint((fJetPtMax-fJetPtMin)/fBinWidthJetPt);
170 // Printf("nt: %d entries fCollTemplates: %d",nt,fCollTemplates.GetEntriesFast());
172 fInitialized = kTRUE;
176 //__________________________________________________________________________
177 Int_t AliEmcalJetByJetCorrection::GetJetPtBin(const Double_t jetpt) const {
179 if(jetpt<fJetPtMin || jetpt>=fJetPtMax)
182 Int_t bin = TMath::FloorNint((jetpt - fJetPtMin)/fBinWidthJetPt);
187 //________________________________________________________________________
188 Double_t AliEmcalJetByJetCorrection::GetEfficiency(const Double_t pt) const {
190 if(fEfficiencyFixed<1.) return fEfficiencyFixed;
191 else if(fhEfficiency) {
192 Int_t bin = fhEfficiency->GetXaxis()->FindBin(pt);
193 eff = fhEfficiency->GetBinContent(bin);
198 //________________________________________________________________________
199 Double_t AliEmcalJetByJetCorrection::GetMeanPtConstituents(const AliEmcalJet *jet, TClonesArray *fTracks) const {
201 if(!jet || !fTracks) return -1.;
202 if(jet->GetNumberOfTracks()<1) return -1;
205 Double_t sumPtCh = 0.;
206 for(Int_t icc=0; icc<jet->GetNumberOfTracks(); icc++) {
207 vp = static_cast<AliVParticle*>(jet->TrackAt(icc, fTracks));
211 Double_t meanpt = sumPtCh/(double)(jet->GetNumberOfTracks());