DAS  3.0
Das Analysis System
common.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cassert>
4 #include <iostream>
5 #include <regex>
6 #include <string>
7 #include <sstream>
8 
10 
11 #include <boost/algorithm/string.hpp>
12 
13 #include <darwin.h>
14 
15 namespace DAS::JetEnergy {
16 
17 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};
18 inline static const int nPtJERCbins = pt_JERC_edges.size()-1;
19 
22 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 };
23 inline static const int nAbsEtaBins = abseta_edges.size()-1;
24 inline static const std::vector<TString> absetaBins = MakeTitle(abseta_edges, "|#eta|", false, true, [](double v) { return Form("%.3f", v);});
25 
26 inline static const std::map<int,std::vector<double>> rho_edges = {
27  { 2016, {0, 6.69, 12.39, 18.09, 23.79, 29.49, 35.19, 40.9, 999} }, // EOY16
28  { 2017, {0, 7.47, 13.49, 19.52, 25.54, 31.57, 37.59, 999} }, // UL17
29  { 2018, {0, 7.35, 13.26, 19.17, 25.08, 30.99, 36.9, 999} } // UL18
30 };
31 
32 inline static const std::map<int,int> nRhoBins = {
33  {2016, rho_edges.at(2016).size()-1 },
34  {2017, rho_edges.at(2017).size()-1 },
35  {2018, rho_edges.at(2018).size()-1 }
36 };
37 
38 inline static const std::map<int,std::vector<TString>> rhoBins = {
39  { 2016, MakeTitle(rho_edges.at(2016), "#rho", false, false, [](double v) { return Form("%.2f", v);}) },
40  { 2017, MakeTitle(rho_edges.at(2017), "#rho", false, false, [](double v) { return Form("%.2f", v);}) },
41  { 2018, MakeTitle(rho_edges.at(2018), "#rho", false, false, [](double v) { return Form("%.2f", v);}) }
42 };
43 
46 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};
47 inline static const int nEtaUncBins = eta_unc_edges.size()-1;
48 
49 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"};
50 
51 inline static const float w = 0.8;
52 
53 inline std::vector<double> getBinning (int nBins, float first, float last)
54 {
55  std::vector<double> bins(nBins+1);
56  for(int i = 0; i <= nBins; ++i)
57  bins[i] = first + ((last-first)/nBins) * i;
58  return bins;
59 }
60 
61 inline void assertValidBinning (const std::vector<double>& v)
62 {
63  assert(v.size() > 1);
64  for (size_t i = 1; i<v.size(); ++i) {
65  if (v[i] > v[i-1]) continue;
66  std::cerr << i << ' ' << v[i] << ' ' << v[i-1] << '\n';
67  }
68 }
69 
72 inline std::vector<float> GetLogBinning (float minpt, float maxpt, int nbins)
73 {
74  assert(maxpt > minpt);
75  assert(minpt > 0);
76  assert(nbins > 1);
77 
78  std::vector<float> edges;
79 
80  float R = pow(maxpt/minpt,1./nbins);
81  for (float pt = minpt; pt <= maxpt; pt *= R) edges.push_back(pt);
83  std::cout << edges.size() << std::endl;
84 
85  return edges;
86 }
87 
90 inline std::string GetAlgo (const Darwin::Tools::UserInfo& metainfo)
91 {
92  if (metainfo.Find("flags", "labels", "CHS" )) return "chs";
93  if (metainfo.Find("flags", "labels", "PUPPI")) return "Puppi";
94 
95  std::cerr << orange << "Couldn't identify CHS or PUPPI. Running default "
96  "CHS for Run 2 (PUPPI foir Run 3)\n" << def;
97 
98  auto year = metainfo.Get<int>("flags", "year");
99  if (year > 2019) return "Puppi"; // run 3
100  if (year > 2014) return "chs"; // run 2
101  return ""; // run 1
102 }
103 
106 std::string GetShortCampaign (const std::string& campaign)
107 {
108  using namespace std;
109  regex r("^(Summer|Fall|Autumn|Winter|Spring)[0-9]{2}[A-Za-z0-9]*");
110  smatch campaign_short;
111  if (!regex_search(campaign, campaign_short, r))
112  BOOST_THROW_EXCEPTION( invalid_argument("The campaign could not be identified"));
113  return campaign_short.str();
114 }
115 
119 std::string ScanCorrections (const auto& corrections,
120  const std::string& key = "")
121 {
122  std::stringstream s;
123  s << "Available corrections:";
124  for (const auto& correction: corrections) {
125  bool found = correction.first == key;
126  if (found) s << bold << green;
127  s << ' ' << correction.first;
128  if (found) s << def;
129  }
130  return s.str();
131 }
132 
135 template<typename CorrectionType>
136 CorrectionType GetCorrection (const auto& corrections,
137  const std::string& campaign,
138  const std::string& type,
139  const std::string& level,
140  const std::string& suffix)
141 {
142  namespace al = boost::algorithm;
143  for (const auto& correction: corrections) {
144  if (!al::starts_with(correction.first, campaign) ||
145  !al::contains (correction.first, type) ||
146  !al::contains (correction.first, level) ||
147  !al::ends_with (correction.first, suffix))
148  continue;
149 
150  return correction.second;
151  }
152  using namespace std;
153  BOOST_THROW_EXCEPTION(
154  invalid_argument(
155  "No `"s + campaign + "*"s + type + "*" + level + "*"s + suffix
156  + "` correction can be found in the given tables."s
157  + ScanCorrections(corrections)
158  )
159  );
160 }
161 
164 int GetR (const Darwin::Tools::UserInfo& metainfo)
165 {
166  auto year = metainfo.Get<int>("flags", "year"),
167  R = metainfo.Get<int>("flags", "R");
168 
169  std::string warning = "Not a standard jet size.\n";
170  if (year > 2014) { // run 2 and run 3
171  if (R != 4 && R != 8)
172  std::cerr << orange << warning << def;
173  return R < 6 ? 4 : 8;
174  }
175  else { // run 1
176  if (R != 5 && R != 7)
177  std::cerr << orange << warning << def;
178  return R < 6 ? 5 : 7;
179  }
180 }
181 
182 } // end of DAS::JetEnergy namespace
Ntupliser_cfg.cerr
cerr
Definition: Ntupliser_cfg.py:93
metPhiCorrectionExample.bins
bins
Definition: metPhiCorrectionExample.py:89
DAS::JetEnergy::rho_edges
static const std::map< int, std::vector< double > > rho_edges
Definition: common.h:26
jmarExample.pt
pt
Definition: jmarExample.py:19
Step::def
static const char * def
Definition: Step.h:36
DAS::JetEnergy::eta_unc_edges
static const std::vector< double > eta_unc_edges
binning for JES uncertainties (taken from JES files)
Definition: common.h:46
Darwin::Tools::UserInfo::Get
T Get(TList *mother, const char *key) const
Definition: UserInfo.h:75
Ntupliser_cfg.year
int year
Definition: Ntupliser_cfg.py:63
DAS::MakeTitle
std::vector< TString > MakeTitle(const std::vector< double > &edges, const char *v, bool lowEdge, bool highEdge, std::function< const char *(double)> format)
Make a vector of properly formated titles from bin edges.
Definition: binnings.h:13
DAS::JetEnergy::pt_JERC_edges
static const std::vector< double > pt_JERC_edges
Definition: common.h:17
DAS::JetEnergy::ScanCorrections
std::string ScanCorrections(const auto &corrections, const std::string &key="")
Definition: common.h:119
jercExample.key
string key
Definition: jercExample.py:109
DAS::JetEnergy::getBinning
std::vector< double > getBinning(int nBins, float first, float last)
Definition: common.h:53
DAS::JetEnergy::w
static const float w
Definition: common.h:51
DAS::JetEnergy::GetShortCampaign
std::string GetShortCampaign(const std::string &campaign)
Extracts for isntance Summer19UL18 from Summer19UL18_RunA
Definition: common.h:106
DAS::JetEnergy::absetaBins
static const std::vector< TString > absetaBins
Definition: common.h:24
DAS::MN::minpt
static const double minpt
Definition: getMNobservables.cc:42
DAS::JetEnergy::JES_variations
static const std::vector< std::string > JES_variations
Definition: common.h:49
binnings.h
DAS::JetEnergy::assertValidBinning
void assertValidBinning(const std::vector< double > &v)
Definition: common.h:61
DAS::MN::maxpt
static const double maxpt
Definition: getMNobservables.cc:42
orange
static const char * orange
Definition: colours.h:6
Darwin::Tools::UserInfo::Find
bool Find(TList *mother, const char *key) const
Recursive finder.
Definition: UserInfo.h:107
DAS::JetEnergy::nEtaUncBins
static const int nEtaUncBins
Definition: common.h:47
DAS::JetEnergy::abseta_edges
static const std::vector< double > abseta_edges
JERC binning (taken from JERCProtoLab repo, /macros/common_info/common_binning.hpp)
Definition: common.h:22
DAS::JetEnergy::rhoBins
static const std::map< int, std::vector< TString > > rhoBins
Definition: common.h:38
Step::green
static const char * green
Definition: Step.h:33
DAS::JetEnergy::GetR
int GetR(const Darwin::Tools::UserInfo &metainfo)
Determine the R values for which JetMET provides corrections.
Definition: common.h:164
DAS::JetEnergy::GetCorrection
CorrectionType GetCorrection(const auto &corrections, const std::string &campaign, const std::string &type, const std::string &level, const std::string &suffix)
Returns the correction corresponding to a key.
Definition: common.h:136
DAS::JetEnergy::GetLogBinning
std::vector< float > GetLogBinning(float minpt, float maxpt, int nbins)
Make equidistant binning in log pt.
Definition: common.h:72
DAS::JetEnergy::nRhoBins
static const std::map< int, int > nRhoBins
Definition: common.h:32
DAS::JetEnergy::nPtJERCbins
static const int nPtJERCbins
Definition: common.h:18
generate_html.campaign
campaign
Definition: generate_html.py:86
Darwin::Tools::UserInfo
Generic meta-information for n-tuple (can be used out of Darwin).
Definition: UserInfo.h:52
DAS::JetEnergy::GetAlgo
std::string GetAlgo(const Darwin::Tools::UserInfo &metainfo)
Determine from metainfo if CHS or PUPPI has been used to reconstruct the jets.
Definition: common.h:90
DAS::JetEnergy
Definition: applyJERsmearing.cc:41
DAS::JetEnergy::nAbsEtaBins
static const int nAbsEtaBins
Definition: common.h:23
Step::bold
static const char * bold
Definition: Step.h:35