CMS 3D CMS Logo

DiLeptonVertexHelpers.h
Go to the documentation of this file.
1 #ifndef Alignment_OfflineValidation_DiLeptonVertexHelpers_h
2 #define Alignment_OfflineValidation_DiLeptonVertexHelpers_h
3 
4 #include <vector>
5 #include <string>
6 #include <fmt/printf.h>
7 #include "TH2F.h"
8 #include "TLorentzVector.h"
12 
13 namespace DiLeptonHelp {
14 
15  //
16  // Ancillary struct for counting
17  //
18  struct Counts {
19  unsigned int eventsTotal;
20  unsigned int eventsAfterMult;
21  unsigned int eventsAfterPt;
22  unsigned int eventsAfterEta;
23  unsigned int eventsAfterVtx;
24  unsigned int eventsAfterDist;
25 
26  public:
27  void printCounts() {
28  edm::LogInfo("DiLeptonHelpCounts") << " Total Events: " << eventsTotal << "\n"
29  << " After multiplicity: " << eventsAfterMult << "\n"
30  << " After pT cut: " << eventsAfterPt << "\n"
31  << " After eta cut: " << eventsAfterEta << "\n"
32  << " After Vtx: " << eventsAfterVtx << "\n"
33  << " After VtxDist: " << eventsAfterDist << std::endl;
34  }
35 
36  void zeroAll() {
37  eventsTotal = 0;
38  eventsAfterMult = 0;
39  eventsAfterPt = 0;
40  eventsAfterEta = 0;
41  eventsAfterVtx = 0;
42  eventsAfterDist = 0;
43  }
44  };
45 
46  enum flavour { MM = 0, EE = 1, UNDEF = -1 };
47 
48  //
49  // Ancillary class for plotting
50  //
52  public:
54 
55  //________________________________________________________________________________//
56  // overloaded constructor
58  : m_name(name), m_title(tt), m_ytitle(ytt), m_isBooked(false), m_flav(FLAV) {
59  if (m_flav < 0) {
60  edm::LogError("PlotsVsKinematics") << "The initialization flavour is not correct!" << std::endl;
61  }
62  }
63 
64  ~PlotsVsKinematics() = default;
65 
66  //________________________________________________________________________________//
67  inline void bookFromPSet(const TFileDirectory& fs, const edm::ParameterSet& hpar) {
68  std::string namePostfix;
69  std::string titlePostfix;
70  float xmin, xmax;
71 
72  std::string sed = (m_flav ? "e" : "#mu");
73 
74  for (const auto& xAx : axisChoices) {
75  switch (xAx) {
76  case xAxis::Z_PHI:
77  xmin = -M_PI;
78  xmax = M_PI;
79  namePostfix = m_flav ? "EEPhi" : "MMPhi";
80  titlePostfix = fmt::sprintf("%s%s pair #phi;%s^{+}%s^{-} #phi", sed, sed, sed, sed);
81  break;
82  case xAxis::Z_ETA:
83  xmin = -3.5;
84  xmax = 3.5;
85  namePostfix = m_flav ? "EEEta" : "MuMuEta";
86  titlePostfix = fmt::sprintf("%s%s pair #eta;%s^{+}%s^{-} #eta", sed, sed, sed, sed);
87  break;
88  case xAxis::LP_PHI:
89  xmin = -M_PI;
90  xmax = M_PI;
91  namePostfix = m_flav ? "EPlusPhi" : "MuPlusPhi";
92  titlePostfix = fmt::sprintf("%s^{+} #phi;%s^{+} #phi [rad]", sed, sed);
93  break;
94  case xAxis::LP_ETA:
95  xmin = -2.4;
96  xmax = 2.4;
97  namePostfix = m_flav ? "EPlusEta" : "MuPlusEta";
98  titlePostfix = fmt::sprintf("%s^{+} #eta;%s^{+} #eta", sed, sed);
99  break;
100  case xAxis::LM_PHI:
101  xmin = -M_PI;
102  xmax = M_PI;
103  namePostfix = m_flav ? "EMinusPhi" : "MuMinusPhi";
104  titlePostfix = fmt::sprintf("%s^{-} #phi;%s^{-} #phi [rad]", sed, sed);
105  break;
106  case xAxis::LM_ETA:
107  xmin = -2.4;
108  xmax = 2.4;
109  namePostfix = m_flav ? "EMinusEta" : "MuMinusEta";
110  titlePostfix = fmt::sprintf("%s^{-} #eta;%s^{+} #eta", sed, sed);
111  break;
112  default:
113  throw cms::Exception("LogicalError") << " there is not such Axis choice as " << xAx;
114  }
115 
116  const auto& h2name = fmt::sprintf("%sVs%s", hpar.getParameter<std::string>("name"), namePostfix);
117  const auto& h2title = fmt::sprintf("%s vs %s;%s% s",
118  hpar.getParameter<std::string>("title"),
119  titlePostfix,
120  hpar.getParameter<std::string>("title"),
121  hpar.getParameter<std::string>("yUnits"));
122 
123  m_h2_map[xAx] = fs.make<TH2F>(h2name.c_str(),
124  h2title.c_str(),
125  hpar.getParameter<int32_t>("NxBins"),
126  xmin,
127  xmax,
128  hpar.getParameter<int32_t>("NyBins"),
129  hpar.getParameter<double>("ymin"),
130  hpar.getParameter<double>("ymax"));
131  }
132 
133  // flip the is booked bit
134  m_isBooked = true;
135  }
136 
137  //________________________________________________________________________________//
138  inline void bookPlots(
139  TFileDirectory& fs, const float valmin, const float valmax, const int nxbins, const int nybins) {
140  if (m_name.empty() && m_title.empty() && m_ytitle.empty()) {
141  edm::LogError("PlotsVsKinematics")
142  << "In" << __FUNCTION__ << "," << __LINE__
143  << "trying to book plots without the right constructor being called!" << std::endl;
144  return;
145  }
146 
147  std::string dilep = (m_flav ? "e^{+}e^{-}" : "#mu^{+}#mu^{-}");
148  std::string lep = (m_flav ? "e^{+}" : "#mu^{+}");
149  std::string lem = (m_flav ? "e^{-}" : "#mu^{-}");
150 
151  static constexpr float maxMuEta = 2.4;
152  static constexpr float maxMuMuEta = 3.5;
153  TH1F::SetDefaultSumw2(kTRUE);
154 
155  // clang-format off
156  m_h2_map[xAxis::Z_ETA] = fs.make<TH2F>(fmt::sprintf("%sVsMuMuEta", m_name).c_str(),
157  fmt::sprintf("%s vs %s pair #eta;%s #eta;%s", m_title, dilep, dilep, m_ytitle).c_str(),
158  nxbins, -M_PI, M_PI,
159  nybins, valmin, valmax);
160 
161  m_h2_map[xAxis::Z_PHI] = fs.make<TH2F>(fmt::sprintf("%sVsMuMuPhi", m_name).c_str(),
162  fmt::sprintf("%s vs %s pair #phi;%s #phi [rad];%s", m_title, dilep, dilep, m_ytitle).c_str(),
163  nxbins, -maxMuMuEta, maxMuMuEta,
164  nybins, valmin, valmax);
165 
166  m_h2_map[xAxis::LP_ETA] = fs.make<TH2F>(fmt::sprintf("%sVsMuPlusEta", m_name).c_str(),
167  fmt::sprintf("%s vs %s #eta;%s #eta;%s", m_title, lep, lep, m_ytitle).c_str(),
168  nxbins, -maxMuEta, maxMuEta,
169  nybins, valmin, valmax);
170 
171  m_h2_map[xAxis::LP_PHI] = fs.make<TH2F>(fmt::sprintf("%sVsMuPlusPhi", m_name).c_str(),
172  fmt::sprintf("%s vs %s #phi;%s #phi [rad];%s", m_title, lep, lep, m_ytitle).c_str(),
173  nxbins, -M_PI, M_PI,
174  nybins, valmin, valmax);
175 
176  m_h2_map[xAxis::LM_ETA] = fs.make<TH2F>(fmt::sprintf("%sVsMuMinusEta", m_name).c_str(),
177  fmt::sprintf("%s vs %s #eta;%s #eta;%s", m_title, lem, lem, m_ytitle).c_str(),
178  nxbins, -maxMuEta, maxMuEta,
179  nybins, valmin, valmax);
180 
181  m_h2_map[xAxis::LM_PHI] = fs.make<TH2F>(fmt::sprintf("%sVsMuMinusPhi", m_name).c_str(),
182  fmt::sprintf("%s vs %s #phi;%s #phi [rad];%s", m_title, lem, lem, m_ytitle).c_str(),
183  nxbins, -M_PI, M_PI,
184  nybins, valmin, valmax);
185  // clang-format on
186 
187  // flip the is booked bit
188  m_isBooked = true;
189  }
190 
191  //________________________________________________________________________________//
192  inline void fillPlots(const float val, const std::pair<TLorentzVector, TLorentzVector>& momenta) {
193  if (!m_isBooked) {
194  edm::LogError("PlotsVsKinematics")
195  << "In" << __FUNCTION__ << "," << __LINE__ << "trying to fill a plot not booked!" << std::endl;
196  return;
197  }
198 
199  m_h2_map[xAxis::Z_ETA]->Fill((momenta.first + momenta.second).Eta(), val);
200  m_h2_map[xAxis::Z_PHI]->Fill((momenta.first + momenta.second).Phi(), val);
201  m_h2_map[xAxis::LP_ETA]->Fill((momenta.first).Eta(), val);
202  m_h2_map[xAxis::LP_PHI]->Fill((momenta.first).Phi(), val);
203  m_h2_map[xAxis::LM_ETA]->Fill((momenta.second).Eta(), val);
204  m_h2_map[xAxis::LM_PHI]->Fill((momenta.second).Phi(), val);
205  }
206 
207  private:
209  const std::vector<xAxis> axisChoices = {
210  xAxis::Z_PHI, xAxis::Z_ETA, xAxis::LP_PHI, xAxis::LP_ETA, xAxis::LM_PHI, xAxis::LM_ETA};
211 
215 
218 
219  std::map<xAxis, TH2F*> m_h2_map;
220  };
221 } // namespace DiLeptonHelp
222 #endif
DiLeptonHelp::EE
Definition: DiLeptonVertexHelpers.h:46
DiLeptonHelp::PlotsVsKinematics::LP_PHI
Definition: DiLeptonVertexHelpers.h:208
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
DiLeptonHelp::UNDEF
Definition: DiLeptonVertexHelpers.h:46
groupFilesInBlocks.tt
int tt
Definition: groupFilesInBlocks.py:144
DiLeptonHelp::Counts::eventsTotal
unsigned int eventsTotal
Definition: DiLeptonVertexHelpers.h:19
DiLeptonHelp::PlotsVsKinematics::~PlotsVsKinematics
~PlotsVsKinematics()=default
DiLeptonHelp::Counts::eventsAfterMult
unsigned int eventsAfterMult
Definition: DiLeptonVertexHelpers.h:20
DiLeptonHelp::PlotsVsKinematics::PlotsVsKinematics
PlotsVsKinematics(flavour FLAV)
Definition: DiLeptonVertexHelpers.h:53
TFileDirectory
Definition: TFileDirectory.h:24
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
DiLeptonHelp::Counts::zeroAll
void zeroAll()
Definition: DiLeptonVertexHelpers.h:36
DiLeptonHelp::PlotsVsKinematics
Definition: DiLeptonVertexHelpers.h:51
DiLeptonHelp::Counts::eventsAfterVtx
unsigned int eventsAfterVtx
Definition: DiLeptonVertexHelpers.h:23
DiLeptonHelp::PlotsVsKinematics::PlotsVsKinematics
PlotsVsKinematics(flavour FLAV, const std::string &name, const std::string &tt, const std::string &ytt)
Definition: DiLeptonVertexHelpers.h:57
DiLeptonHelp::PlotsVsKinematics::bookFromPSet
void bookFromPSet(const TFileDirectory &fs, const edm::ParameterSet &hpar)
Definition: DiLeptonVertexHelpers.h:67
DiLeptonHelp::PlotsVsKinematics::axisChoices
const std::vector< xAxis > axisChoices
Definition: DiLeptonVertexHelpers.h:209
DiLeptonHelp::PlotsVsKinematics::LM_ETA
Definition: DiLeptonVertexHelpers.h:208
DiLeptonHelp::PlotsVsKinematics::xAxis
xAxis
Definition: DiLeptonVertexHelpers.h:208
TFileService.h
DiLeptonHelp::PlotsVsKinematics::m_ytitle
const std::string m_ytitle
Definition: DiLeptonVertexHelpers.h:214
DiLeptonHelp::Counts
Definition: DiLeptonVertexHelpers.h:18
edm::ParameterSet
Definition: ParameterSet.h:47
DiLeptonHelp::MM
Definition: DiLeptonVertexHelpers.h:46
DiLeptonHelp::Counts::eventsAfterEta
unsigned int eventsAfterEta
Definition: DiLeptonVertexHelpers.h:22
DiLeptonHelp
Definition: DiLeptonVertexHelpers.h:13
DiLeptonHelp::PlotsVsKinematics::m_h2_map
std::map< xAxis, TH2F * > m_h2_map
Definition: DiLeptonVertexHelpers.h:219
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:49
DiLeptonHelp::Counts::eventsAfterPt
unsigned int eventsAfterPt
Definition: DiLeptonVertexHelpers.h:21
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
DiLeptonHelp::PlotsVsKinematics::m_isBooked
bool m_isBooked
Definition: DiLeptonVertexHelpers.h:216
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DiLeptonHelp::PlotsVsKinematics::fillPlots
void fillPlots(const float val, const std::pair< TLorentzVector, TLorentzVector > &momenta)
Definition: DiLeptonVertexHelpers.h:192
DiLeptonHelp::PlotsVsKinematics::bookPlots
void bookPlots(TFileDirectory &fs, const float valmin, const float valmax, const int nxbins, const int nybins)
Definition: DiLeptonVertexHelpers.h:138
heppy_batch.val
val
Definition: heppy_batch.py:351
TrackerOfflineValidation_Dqm_cff.xmax
xmax
Definition: TrackerOfflineValidation_Dqm_cff.py:11
Exception
Definition: hltDiff.cc:245
DiLeptonHelp::PlotsVsKinematics::m_title
const std::string m_title
Definition: DiLeptonVertexHelpers.h:213
TFileDirectory::make
T * make(const Args &...args) const
make new ROOT object
Definition: TFileDirectory.h:53
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
DiLeptonHelp::PlotsVsKinematics::m_name
const std::string m_name
Definition: DiLeptonVertexHelpers.h:212
DiLeptonHelp::PlotsVsKinematics::Z_ETA
Definition: DiLeptonVertexHelpers.h:208
DiLeptonHelp::PlotsVsKinematics::LP_ETA
Definition: DiLeptonVertexHelpers.h:208
ParameterSet.h
TrackerOfflineValidation_Dqm_cff.xmin
xmin
Definition: TrackerOfflineValidation_Dqm_cff.py:10
DiLeptonHelp::PlotsVsKinematics::m_flav
flavour m_flav
Definition: DiLeptonVertexHelpers.h:217
DiLeptonHelp::PlotsVsKinematics::Z_PHI
Definition: DiLeptonVertexHelpers.h:208
DiLeptonHelp::flavour
flavour
Definition: DiLeptonVertexHelpers.h:46
DiLeptonHelp::Counts::printCounts
void printCounts()
Definition: DiLeptonVertexHelpers.h:27
DiLeptonHelp::Counts::eventsAfterDist
unsigned int eventsAfterDist
Definition: DiLeptonVertexHelpers.h:24
DiLeptonHelp::PlotsVsKinematics::LM_PHI
Definition: DiLeptonVertexHelpers.h:208