6namespace ADD_CMODE(CP) {
15 return mu(ptAcc) / 1.e3;
18 return std::abs(mu(etaAcc));
21 IKinematicSystHandler::KinVariable IKinematicSystHandler::GetMuonVariableToUse(
const std::string &name) {
22 if (name ==
"pt")
return &IKinematicSystHandler::Pt;
23 if (name ==
"ptGeV")
return &IKinematicSystHandler::PtGeV;
24 if (name ==
"eta")
return &IKinematicSystHandler::Eta;
25 if (name ==
"AbsEta")
return &IKinematicSystHandler::AbsEta;
32 PtKinematicSystHandler::PtKinematicSystHandler(std::unique_ptr<HistHandler> pt_flatnesss, std::unique_ptr<HistHandler> energy_loss):
36 m_flatness.swap(pt_flatnesss);
37 m_loss.swap(energy_loss);
41 int bin_flat(-1), bin_loss(-1);
44 CP::CorrectionCode cc_eloss = mu(ptAcc) > 200.e3 ? m_loss->FindBin(mu, bin_loss) : cc_flat;
46 float eloss_syst = bin_loss < 1 ? 1.e6 : std::abs( m_loss->GetBinContent(bin_loss) * mu(ptAcc)/1.0e6);
52 eff *= 1 + m_SystWeight * std::abs(syst);
54 }
else return cc_flat;
57 float abs_error = std::abs( m_flatness->GetBinError(bin_flat));
58 if (cc_eloss ==
CP::CorrectionCode::Ok && mu(ptAcc) > 200.e3 && (eloss_syst < abs_error || abs_error == 0 || mu(ptAcc) > 500.e3)){
62 syst = m_flatness->GetBinContent(bin_flat);
65 eff *= 1 + m_SystWeight * std::abs(syst);
69 void PtKinematicSystHandler::SetSystematicWeight(
float syst_weight) {
70 m_SystWeight = syst_weight;
73 bool PtKinematicSystHandler::initialize(){
74 return m_flatness.get() !=
nullptr && m_loss.get() !=
nullptr;
79 TTVAClosureSysHandler::TTVAClosureSysHandler(std::unique_ptr<HistHandler>
HistHandler):
84 void TTVAClosureSysHandler::SetSystematicWeight(
float SystWeight){m_SystWeight = SystWeight;}
85 bool TTVAClosureSysHandler::initialize() {
return m_Handler.get() !=
nullptr; }
92 Eff *= (1. + m_SystWeight * std::abs(m_Handler->GetBinContent(binsys)));
98 PrimodialPtSystematic::PrimodialPtSystematic(std::unique_ptr<HistHandler>
Handler) :
113 Eff *= (1. + m_SystWeight * std::abs(m_Handler->GetBinContent(binsys)) * mu(ptAcc) / 1.0e6);
116 void PrimodialPtSystematic::SetSystematicWeight(
float SystWeight) {
117 m_SystWeight = SystWeight;
119 bool PrimodialPtSystematic::initialize() {
120 return m_Handler.get() !=
nullptr;
125 BadMuonVetoSystHandler::BadMuonVetoSystHandler(TDirectory* InDir_3Stations, TDirectory* InDir_2Stations) :
128 m_uncertVar(
nullptr),
129 m_polySelVar(
nullptr),
131 fillMap(InDir_3Stations, m_syst3Stations);
132 if (InDir_2Stations && InDir_2Stations!= InDir_3Stations) {
133 fillMap(InDir_2Stations,m_syst2Stations);
137 void BadMuonVetoSystHandler::fillMap(TDirectory* InDir, std::map<Ranges, std::unique_ptr<TF1>>& systPolynomials){
139 Error(
"BadMuonSysVetoHandler()",
"No TDirectory is given");
142 TIter next(InDir->GetListOfKeys());
143 while (TObject* obj = next()) {
144 std::string ObjName = obj->GetName();
145 float lowRange(-1.e20), highRange(1.e20);
146 if (ObjName.find(
"TF1") == std::string::npos) {
150 InDir->GetObject(ObjName.c_str(), TF);
155 getNextProperty(ObjName);
156 if (!m_uncertVar) {m_uncertVar = GetMuonVariableToUse(getNextProperty(ObjName));}
158 else {getNextProperty(ObjName);}
159 if (!m_polySelVar) {m_polySelVar = GetMuonVariableToUse(getNextProperty(ObjName));}
160 else {getNextProperty(ObjName);}
162 std::string LowRange_str = getNextProperty(ObjName);
163 std::string HighRange_str = getNextProperty(ObjName);
164 if (!LowRange_str.empty()) {
165 lowRange = atof(LowRange_str.c_str()) / std::pow(10, LowRange_str.size() -1);
167 if (!HighRange_str.empty()) {
168 highRange = atof(HighRange_str.c_str()) / std::pow(10, LowRange_str.size() -1);
170 systPolynomials.insert(std::pair<Ranges, std::unique_ptr<TF1>>(Ranges(lowRange, highRange), std::unique_ptr<TF1>(TF)));
175 if (m_SystWeight == 0.) {
180 float RelHighPtSys = 0.;
181 if (mu(ptAcc) >= 100.e3) {
186 RelHighPtSys = Poly->Eval((this->*m_uncertVar)(mu.getXAODObject()));
190 RelHighPtSys = 0.005;
192 Eff = 1 + m_SystWeight * std::sqrt(std::pow(Eff - 1,2) + RelHighPtSys * RelHighPtSys);
196 void BadMuonVetoSystHandler::SetSystematicWeight(
float SystWeight) {
197 m_SystWeight = SystWeight;
200 bool BadMuonVetoSystHandler::initialize() {
201 if (m_syst3Stations.empty()) {
202 Error(
"BadMuonVetoSystHandler::initialize()",
"No polynomials");
205 if (!m_uncertVar || !m_polySelVar) {
210 BadMuonVetoSystHandler::~BadMuonVetoSystHandler() {
215 Error(
"BadMuonVetoSystHandler()",
"Something went wrong with the initialization");
218 uint8_t nprecisionLayers=0;
220 Error(
"BadMuonSysVetoHandler()",
"Precisionlayers unkown");
222 }
else if (nprecisionLayers >= 3) {
223 for (
const auto& BinnedPoly : m_syst3Stations) {
224 if (BinnedPoly.first.first <= (this->*m_polySelVar)(mu) && (this->*m_polySelVar)(mu) < BinnedPoly.first.second) {
225 Poly = BinnedPoly.second.get();
229 }
else if (nprecisionLayers == 2) {
230 for (
const auto& BinnedPoly : m_syst2Stations) {
231 if (BinnedPoly.first.first <= (this->*m_polySelVar)(mu) && (this->*m_polySelVar)(mu) < BinnedPoly.first.second) {
232 Poly = BinnedPoly.second.get();
239 std::string BadMuonVetoSystHandler::getNextProperty(std::string &sstr)
const {
241 while (!sstr.empty() && sstr[0] ==
'_') {
244 size_t pos = sstr.find(
"_");
245 std::string
Property = pos != std::string::npos ? sstr.substr(0, pos) : sstr;
246 if (pos != std::string::npos) {
247 sstr = sstr.substr(
Property.size() + 1, sstr.size());