16namespace ADD_CMODE(CP) {
20 std::unique_ptr<AxisHandler> AxisHandlerProvider::GetAxisHandler(
columnar::ColumnarTool<> * parent,
const TAxis * axisptr) {
21 if (axisptr !=
nullptr) {
22 std::string axis = axisptr->GetTitle();
23 axis = EraseWhiteSpaces(axis);
24 size_t Abs1 = axis.find(
"|");
26 if (Abs1 != std::string::npos) Abs2 = axis.find(
"|", Abs1 + 1);
27 bool AbsAxis = (Abs2 != std::string::npos) && (Abs2 != 0);
28 if (axis.find(
"pt") != std::string::npos || axis.find(
"pT") != std::string::npos || axis.find(
"p_{T}") != std::string::npos) {
29 return std::make_unique<PtAxisHandler>(parent);
30 }
else if (axis.find(
"phi") != std::string::npos) {
31 return std::make_unique<PhiAxisHandler>(parent);
32 }
else if (axis.find(
"q") != std::string::npos || axis.find(
"charge") != std::string::npos) {
33 return std::make_unique<ChargeAxisHandler>(parent);
34 }
else if (axis.find(
"eta") != std::string::npos) {
35 if (AbsAxis)
return std::make_unique<AbsEtaAxisHandler>(parent);
36 return std::make_unique<EtaAxisHandler>(parent);
37 }
else if (axis.find(
"dRJet") != std::string::npos || axis.find(
"#DeltaR (jet, #mu)") != std::string::npos) {
38 return std::make_unique<dRJetAxisHandler>(parent);
41 Error(
"AxisHandlerProvider",
"Can not interpret axis title '%s'", axis.c_str());
43 Error(
"AxisHandlerProvider",
"nullptr pointer passed");
45 return std::make_unique<UndefinedAxisHandler>(parent);
50 value = ptAcc(mu) / 1000.;
54 value = chargeAcc (mu);
62 value = std::abs(etaAcc(mu));
69 void dRJetAxisHandler::set_close_jet_decorator(
const std::string& decor_name){
70 s_close_jet_decor = decor_name;
73 void dRJetAxisHandler::set_use_2D_sf(
const bool in)
78 std::string dRJetAxisHandler::s_close_jet_decor =
"dRJet";
79 bool dRJetAxisHandler::s_use_2D_sf =
false;
82 m_use_2D_sf(s_use_2D_sf),
83 m_acc(*
this,s_close_jet_decor){}
87 static std::atomic<unsigned int> warned = {0};
89 if(!m_use_2D_sf) value = -2.;
90 else if (acc_dR_deriv.isAvailable(mu)){
91 value = acc_dR_deriv(mu);
92 }
else if( m_acc.isAvailable(mu) ) {
96 Warning(
"MuonEfficiencyCorrections::dRJetAxisHandler()",
"The DFCommonJetDr jet decoration is not available in the derivation will fall back to %s",s_close_jet_decor.c_str());
104 Warning(
"MuonEfficiencyCorrections::dRJetAxisHandler()",
"The %s decoration has not been found for the Muon. Isolation scale-factors are now also binned in #Delta R(jet,#mu)", s_close_jet_decor.c_str());
105 Warning(
"MuonEfficiencyCorrections::dRJetAxisHandler()",
"using the closest calibrated AntiKt4EMTopo jet with p_{T}>20~GeV and surving the standard OR criteria.");
106 Warning(
"MuonEfficiencyCorrections::dRJetAxisHandler()",
"You should decorate your muon appropiately before passing to the tool, and use dRJet = -1 in case there is no jet in an event.");
107 Warning(
"MuonEfficiencyCorrections::dRJetAxisHandler()",
"For the time being the inclusive scale-factor is going to be returned.");
108 Warning(
"MuonEfficiencyCorrections::dRJetAxisHandler()",
"In future derivations, muons will also be decorated centrally with DFCommonJetDr, for your benefit.");
109 Warning(
"MuonEfficiencyCorrections::dRJetAxisHandler()",
"You can define custom jet decorations via the 'CloseJetDRDecorator' property of the MuonEfficiencyCorrections tool");
138 HistHandler::~HistHandler() {
140 void HistHandler::SetBinContent(
int bin,
float val) {
142 m_H->SetBinContent(
bin, val);
145 void HistHandler::SetBinError(
int bin,
float val) {
147 m_H->SetBinError(
bin, val);
155 m_x_handler(
h ==
nullptr ? 0 : AxisHandlerProvider::GetAxisHandler(parent,
h->GetXaxis())) {
158 HistHandler_TH1::~HistHandler_TH1() {
160 int HistHandler_TH1::nBins()
const {
return GetHist()->GetNbinsX() + 2;}
161 int HistHandler_TH1::nOverFlowBins()
const {
return 2; }
162 bool HistHandler_TH1::isOverFlowBin(
int b)
const {
return b == 0 || b >= nBins() -1; }
163 std::string HistHandler_TH1::GetBinName(
unsigned int bin)
const {
164 TAxis* xAx = GetHist()->GetXaxis();
165 return Form(
"%s_%.2f_to_%.2f", xAx->GetTitle(), xAx->GetBinLowEdge(
bin), xAx->GetBinUpEdge(
bin));
176 bin = GetHist()->FindBin(par);
177 if (bin < 1 || bin > GetHist()->GetNbinsX()) {
189 m_x_handler(
h ==
nullptr ? 0 : AxisHandlerProvider::GetAxisHandler(parent,
h->GetXaxis())),
190 m_y_handler(
h ==
nullptr ? 0 : AxisHandlerProvider::GetAxisHandler(parent,
h->GetYaxis())) {
193 int HistHandler_TH2::nBins()
const {
194 return (GetHist()->GetNbinsX() + 2) * (GetHist()->GetNbinsY() + 2);
196 int HistHandler_TH2::nOverFlowBins()
const {
return 2*GetHist()->GetNbinsX() + 2*GetHist()->GetNbinsY() + 4; }
197 bool HistHandler_TH2::isOverFlowBin(
int b)
const {
198 int x(-1),
y(-1),
z(-1);
199 GetHist()->GetBinXYZ(b,
x,
y,
z);
200 return x == 0 ||
x == GetHist()->GetXaxis()->GetNbins() + 1 ||
y == 0 ||
y == GetHist()->GetYaxis()->GetNbins() + 1;
210 int binx = GetHist()->GetXaxis()->FindBin(parx);
211 int biny = GetHist()->GetYaxis()->FindBin(pary);
212 if (binx < 1 || binx > GetHist()->GetNbinsX() || biny < 1 || biny > GetHist()->GetNbinsY()) {
215 bin = GetHist()->GetBin(binx, biny);
219 HistHandler_TH2::~HistHandler_TH2() {
221 std::string HistHandler_TH2::GetBinName(
unsigned int bin)
const {
222 int x(0),
y(0),
z(0);
223 GetHist()->GetBinXYZ(
bin,
x,
y,
z);
224 TAxis* xAx = GetHist()->GetXaxis();
225 TAxis* yAx = GetHist()->GetYaxis();
226 return Form(
"%s_%.2f_to_%.2f_times_%s_%.2f_to_%.2f",
228 xAx->GetTitle(), xAx->GetBinLowEdge(
x), xAx->GetBinUpEdge(
x),
230 yAx->GetTitle(), yAx->GetBinLowEdge(
y), yAx->GetBinUpEdge(
y));
238 m_x_handler(GetHist() ==
nullptr ? 0 : AxisHandlerProvider::GetAxisHandler(parent,
h->GetXaxis())),
239 m_y_handler(GetHist() ==
nullptr ? 0 : AxisHandlerProvider::GetAxisHandler(parent,
h->GetYaxis())),
240 m_z_handler(GetHist() ==
nullptr ? 0 : AxisHandlerProvider::GetAxisHandler(parent,
h->GetZaxis())) {
243 HistHandler_TH3::~HistHandler_TH3() {
245 int HistHandler_TH3::nBins()
const {
246 return (GetHist()->GetNbinsX() + 2) * (GetHist()->GetNbinsY() + 2) * (GetHist()->GetNbinsZ() + 2);
248 int HistHandler_TH3::nOverFlowBins()
const {
return 2*(GetHist()->GetNbinsX()*GetHist()->GetNbinsY() +
249 GetHist()->GetNbinsX()*GetHist()->GetNbinsZ() +
250 GetHist()->GetNbinsY()*GetHist()->GetNbinsZ()) + 8; }
251 bool HistHandler_TH3::isOverFlowBin(
int b)
const {
252 int x(-1),
y(-1),
z(-1);
253 GetHist()->GetBinXYZ(b,
x,
y,
z);
254 return x == 0 ||
x == GetHist()->GetXaxis()->GetNbins() + 1 ||
255 y == 0 ||
y == GetHist()->GetYaxis()->GetNbins() + 1 ||
256 z == 0 ||
z == GetHist()->GetZaxis()->GetNbins() + 1;
267 int binx = GetHist()->GetXaxis()->FindBin(parx);
268 int biny = GetHist()->GetYaxis()->FindBin(pary);
269 int binz = GetHist()->GetZaxis()->FindBin(parz);
270 if (binx < 1 || binx > GetHist()->GetNbinsX() || biny < 1 || biny > GetHist()->GetNbinsY() || binz < 1 || binz > GetHist()->GetNbinsZ()) {
273 bin = GetHist()->GetBin(binx, biny, binz);
278 std::string HistHandler_TH3::GetBinName(
unsigned int bin)
const {
279 int x(0),
y(0),
z(0);
280 GetHist()->GetBinXYZ(
bin,
x,
y,
z);
281 TAxis* xAx = GetHist()->GetXaxis();
282 TAxis* yAx = GetHist()->GetYaxis();
283 TAxis* zAx = GetHist()->GetZaxis();
284 return Form(
"%s_%.2f_to_%.2f_times_%s_%.2f_to_%.2f_times_%s_%.2f_to_%.2f",
286 xAx->GetTitle(), xAx->GetBinLowEdge(
x), xAx->GetBinUpEdge(
x),
288 yAx->GetTitle(), yAx->GetBinLowEdge(
y), yAx->GetBinUpEdge(
y),
290 zAx->GetTitle(), zAx->GetBinLowEdge(
z), zAx->GetBinUpEdge(
z));
300 m_x_handler(GetHist() ==
nullptr ? 0 : AxisHandlerProvider::GetAxisHandler(parent,
h->GetXaxis())),
301 m_y_handler(GetHist() ==
nullptr ? 0 : AxisHandlerProvider::GetAxisHandler(parent,
h->GetYaxis())) {
305 HistHandler_TH2Poly::~HistHandler_TH2Poly() {
307 int HistHandler_TH2Poly::nBins()
const {
308 return m_h->GetNumberOfBins() + 1;
311 int HistHandler_TH2Poly::nOverFlowBins()
const {
return 10;}
312 bool HistHandler_TH2Poly::isOverFlowBin(
int b)
const {
return b < 1;}
321 bin = GetHist()->FindBin(parx, pary);
328 std::string HistHandler_TH2Poly::GetBinName(
unsigned int bin)
const {
329 int x(0),
y(0),
z(0);
330 GetHist()->GetBinXYZ(
bin,
x,
y,
z);
331 TAxis* xAx = GetHist()->GetXaxis();
332 TAxis* yAx = GetHist()->GetYaxis();
333 return Form(
"%s_%.2f_to_%.2f__times_%s_%.2f_to_%.2f",
334 xAx->GetTitle(), xAx->GetBinLowEdge(
x), xAx->GetBinUpEdge(
x),
335 yAx->GetTitle(), yAx->GetBinLowEdge(
y), yAx->GetBinUpEdge(
y));