14 #include <boost/algorithm/string.hpp>
15 #include <boost/assert/source_location.hpp>
17 #include <correction.h>
22 inline static const std::vector<double>
pt_JERC_edges = {15, 17, 20, 23, 27, 30, 35, 40, 45, 57, 72, 90, 120, 150, 200, 300, 400, 550, 750, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000, 5500, 6000, 6500, 7000, 7500, 8000, 8500, 9000, 9500};
27 inline static const std::vector<double>
abseta_edges = { 0.000, 0.261, 0.522, 0.783, 1.044, 1.305, 1.566, 1.740, 1.930, 2.043, 2.172, 2.322, 2.500, 2.650, 2.853, 2.964, 3.139, 3.489, 3.839, 5.191 };
31 inline static const std::map<int,std::vector<double>>
rho_edges = {
32 { 2016, {0, 6.69, 12.39, 18.09, 23.79, 29.49, 35.19, 40.9, 999} },
33 { 2017, {0, 7.47, 13.49, 19.52, 25.54, 31.57, 37.59, 999} },
34 { 2018, {0, 7.35, 13.26, 19.17, 25.08, 30.99, 36.9, 999} },
36 { 2024, {0.0, 8.23, 14.49, 20.75, 27.01, 33.27, 39.53, 45.79, 52.05, 999} },
43 [](
double v) { return Form(
"%.2f", v); });
48 inline static const std::vector<double>
eta_unc_edges = {-5.4, -5.0, -4.4, -4.0, -3.5, -3.0, -2.8, -2.6, -2.4, -2.2, -2.0, -1.8, -1.6, -1.4, -1.2, -1.0, -0.8, -0.6, -0.4, -0.2, 0.0 , 0.2 , 0.4 , 0.6 , 0.8 , 1.0 , 1.2 , 1.4 , 1.6 , 1.8 , 2.0 , 2.2 , 2.4 , 2.6 , 2.8 , 3.0, 3.5 , 4.0 , 4.4 , 5.0 , 5.4};
51 inline static const std::vector<std::string>
JES_variations {
"AbsoluteStat",
"AbsoluteScale",
"AbsoluteMPFBias",
"Fragmentation",
"SinglePionECAL",
"SinglePionHCAL",
"FlavorQCD",
"RelativeJEREC1",
"RelativeJEREC2",
"RelativeJERHF",
"RelativePtBB",
"RelativePtEC1",
"RelativePtEC2",
"RelativePtHF",
"RelativeBal",
"RelativeSample",
"RelativeFSR",
"RelativeStatFSR",
"RelativeStatEC",
"RelativeStatHF",
"PileUpDataMC",
"PileUpPtRef",
"PileUpPtBB",
"PileUpPtEC1",
"PileUpPtEC2",
"PileUpPtHF"};
53 inline static const float w = 0.8;
55 inline std::vector<double>
getBinning (
int nBins,
float first,
float last)
57 std::vector<double>
bins(nBins+1);
58 for(
int i = 0; i <= nBins; ++i)
59 bins[i] = first + ((last-first)/nBins) * i;
66 for (
size_t i = 1; i<v.size(); ++i) {
67 if (v[i] > v[i-1])
continue;
68 std::cerr << i <<
' ' << v[i] <<
' ' << v[i-1] <<
'\n';
80 std::vector<float> edges;
85 std::cout << edges.size() << std::endl;
94 if (metainfo.
Find(
"flags",
"labels",
"CHS" ))
return "chs";
95 if (metainfo.
Find(
"flags",
"labels",
"PUPPI"))
return "Puppi";
97 std::cerr <<
orange <<
"Couldn't identify CHS or PUPPI. Running default "
98 "CHS for Run 2 (PUPPI foir Run 3)\n" <<
def;
100 auto year = metainfo.
Get<
int>(
"flags",
"year");
101 if (
year > 2019)
return "Puppi";
102 if (
year > 2014)
return "chs";
111 regex r(
"^(Summer|Fall|Autumn|Winter|Spring)[0-9]{2}[A-Za-z0-9]*");
112 smatch campaign_short;
113 if (!regex_search(
campaign, campaign_short, r))
114 BOOST_THROW_EXCEPTION( invalid_argument(
"The campaign could not be identified"));
115 return campaign_short.str();
122 const std::string&
key =
"")
125 s <<
"Available corrections:";
126 for (
const auto& correction: corrections) {
127 bool found = correction.first ==
key;
129 s <<
' ' << correction.first;
137 template<
typename CorrectionType>
140 const std::string& type,
141 const std::string& level,
142 const std::string& suffix)
144 namespace al = boost::algorithm;
145 for (
const auto& correction: corrections) {
146 if (!al::starts_with(correction.first,
campaign) ||
147 !al::contains (correction.first, type) ||
148 !al::contains (correction.first, level) ||
149 !al::ends_with (correction.first, suffix))
152 return correction.second;
155 BOOST_THROW_EXCEPTION(
157 "No `"s +
campaign +
"*"s + type +
"*" + level +
"*"s + suffix
158 +
"` correction can be found in the given tables. "s
175 const std::optional<float>&
rho = {},
176 const std::optional<GenJet>& genJet = {},
177 const std::optional<RecEvent>& recEvt = {},
178 const std::optional<std::string>& systematic = {},
179 const std::optional<float>& JER = {},
180 const std::optional<float>& JERSF = {}
185 cout << correction->name();
186 vector<correction::Variable::Type>
inputs;
189 auto push_back = [&cout,&
inputs](
const auto& v) {
194 for (
const correction::Variable&
input: correction->inputs()) {
195 const string& n =
input.name();
197 if (n ==
"JetPt" ) push_back(recJet.
CorrPt());
198 else if (n ==
"JetEta" ) push_back(recJet.
p4.Eta());
199 else if (n ==
"JetPhi" ) push_back(recJet.
p4.Phi());
200 else if (n ==
"JetEta" ) push_back(recJet.
p4.Phi());
201 else if (n ==
"JetA" ) push_back(recJet.
area);
202 else if (n ==
"Rho" ) push_back(*
rho);
203 else if (n ==
"systematic") push_back(*systematic);
204 else if (n ==
"GenPt" ) push_back(genJet ? genJet->CorrPt() : -1);
205 else if (n ==
"EventID" ) push_back((
int) recEvt->evtNo);
206 else if (n ==
"run" ) push_back((
float) recEvt->runNo);
207 else if (n ==
"JER" ) push_back(*JER);
208 else if (n ==
"JERSF" ) push_back(*JERSF);
209 else BOOST_THROW_EXCEPTION( invalid_argument(
"`"s + n +
"` is needed by "s
210 + correction->name() +
" but not recognized."s) );
215 auto corr = correction->evaluate(
inputs);
216 cout <<
" -> " << corr << endl;
219 catch (std::runtime_error& e) {
220 const char *
name =
typeid(*correction).name();
222 auto location = boost::source_location(__FILE__, __LINE__,
name);
223 boost::throw_exception(e, location);
230 auto year = metainfo.
Get<
int>(
"flags",
"year"),
231 R = metainfo.
Get<
int>(
"flags",
"R");
233 std::string warning =
"Not a standard jet size.\n";
235 if (R != 4 && R != 8)
237 return R < 6 ? 4 : 8;
240 if (R != 5 && R != 7)
242 return R < 6 ? 5 : 7;