CMS 3D CMS Logo

DiLeptonPlotHelpers.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 DiLepPlotHelp {
14 
15  enum flavour { MM = 0, EE = 1, UNDEF = -1 };
16 
17  //
18  // Ancillary class for plotting
19  //
21  public:
23 
24  //________________________________________________________________________________//
25  // overloaded constructor
27  : m_name(name), m_title(tt), m_ytitle(ytt), m_isBooked(false), m_flav(FLAV) {
28  if (m_flav < 0) {
29  edm::LogError("PlotsVsKinematics") << "The initialization flavour is not correct!" << std::endl;
30  }
31  }
32 
33  ~PlotsVsKinematics() = default;
34 
35  //________________________________________________________________________________//
36  inline void bookFromPSet(dqm::reco::DQMStore::IBooker& iBooker, const edm::ParameterSet& hpar) {
37  std::string namePostfix;
38  std::string titlePostfix;
39  float xmin, xmax;
40 
41  std::string sed = (m_flav ? "e" : "#mu");
42 
43  for (const auto& xAx : axisChoices) {
44  switch (xAx) {
45  case xAxis::Z_PHI:
46  xmin = -M_PI;
47  xmax = M_PI;
48  namePostfix = m_flav ? "EEPhi" : "MuMuPhi";
49  titlePostfix = fmt::sprintf("%s%s pair #phi;%s^{+}%s^{-} #phi", sed, sed, sed, sed);
50  break;
51  case xAxis::Z_ETA:
52  xmin = -3.5;
53  xmax = 3.5;
54  namePostfix = m_flav ? "EEEta" : "MuMuEta";
55  titlePostfix = fmt::sprintf("%s%s pair #eta;%s^{+}%s^{-} #eta", sed, sed, sed, sed);
56  break;
57  case xAxis::LP_PHI:
58  xmin = -M_PI;
59  xmax = M_PI;
60  namePostfix = m_flav ? "EPlusPhi" : "MuPlusPhi";
61  titlePostfix = fmt::sprintf("%s^{+} #phi;%s^{+} #phi [rad]", sed, sed);
62  break;
63  case xAxis::LP_ETA:
64  xmin = -2.4;
65  xmax = 2.4;
66  namePostfix = m_flav ? "EPlusEta" : "MuPlusEta";
67  titlePostfix = fmt::sprintf("%s^{+} #eta;%s^{+} #eta", sed, sed);
68  break;
69  case xAxis::LM_PHI:
70  xmin = -M_PI;
71  xmax = M_PI;
72  namePostfix = m_flav ? "EMinusPhi" : "MuMinusPhi";
73  titlePostfix = fmt::sprintf("%s^{-} #phi;%s^{-} #phi [rad]", sed, sed);
74  break;
75  case xAxis::LM_ETA:
76  xmin = -2.4;
77  xmax = 2.4;
78  namePostfix = m_flav ? "EMinusEta" : "MuMinusEta";
79  titlePostfix = fmt::sprintf("%s^{-} #eta;%s^{+} #eta", sed, sed);
80  break;
81  case xAxis::DELTA_ETA:
82  xmin = -hpar.getParameter<double>("maxDeltaEta");
83  xmax = hpar.getParameter<double>("maxDeltaEta");
84  namePostfix = m_flav ? "EEDeltEta" : "MuMuDeltaEta";
85  titlePostfix = fmt::sprintf("%s^{-}%s^{+} #Delta#eta;%s^{+}%s^{-} #Delta#eta", sed, sed, sed, sed);
86  break;
87  case xAxis::COSTHETACS:
88  xmin = -1.;
89  xmax = 1.;
90  namePostfix = "CosThetaCS";
91  titlePostfix =
92  fmt::sprintf("%s^{+}%s^{-} cos(#theta_{CS});%s^{+}%s^{-} cos(#theta_{CS})", sed, sed, sed, sed);
93  break;
94  default:
95  throw cms::Exception("LogicalError") << " there is not such Axis choice as " << xAx;
96  }
97 
98  const auto& h2name = fmt::sprintf("%sVs%s", hpar.getParameter<std::string>("name"), namePostfix);
99  const auto& h2title = fmt::sprintf("%s vs %s;%s% s",
100  hpar.getParameter<std::string>("title"),
101  titlePostfix,
102  hpar.getParameter<std::string>("title"),
103  hpar.getParameter<std::string>("yUnits"));
104 
105  m_h2_map[xAx] = iBooker.book2D(h2name.c_str(),
106  h2title.c_str(),
107  hpar.getParameter<int32_t>("NxBins"),
108  xmin,
109  xmax,
110  hpar.getParameter<int32_t>("NyBins"),
111  hpar.getParameter<double>("ymin"),
112  hpar.getParameter<double>("ymax"));
113  }
114 
115  // flip the is booked bit
116  m_isBooked = true;
117  }
118 
119  //________________________________________________________________________________//
121  const float valmin,
122  const float valmax,
123  const int nxbins,
124  const int nybins) {
125  if (m_name.empty() && m_title.empty() && m_ytitle.empty()) {
126  edm::LogError("PlotsVsKinematics")
127  << "In" << __FUNCTION__ << "," << __LINE__
128  << "trying to book plots without the right constructor being called!" << std::endl;
129  return;
130  }
131 
132  std::string dilep = (m_flav ? "e^{+}e^{-}" : "#mu^{+}#mu^{-}");
133  std::string lep = (m_flav ? "e^{+}" : "#mu^{+}");
134  std::string lem = (m_flav ? "e^{-}" : "#mu^{-}");
135 
136  static constexpr float maxMuEta = 2.4;
137  static constexpr float maxMuMuEta = 3.5;
138  TH1F::SetDefaultSumw2(kTRUE);
139 
140  // clang-format off
141  m_h2_map[xAxis::Z_ETA] = iBooker.book2D(fmt::sprintf("%sVsMuMuEta", m_name).c_str(),
142  fmt::sprintf("%s vs %s pair #eta;%s #eta;%s", m_title, dilep, dilep, m_ytitle).c_str(),
143  nxbins, -M_PI, M_PI,
144  nybins, valmin, valmax);
145 
146  m_h2_map[xAxis::Z_PHI] = iBooker.book2D(fmt::sprintf("%sVsMuMuPhi", m_name).c_str(),
147  fmt::sprintf("%s vs %s pair #phi;%s #phi [rad];%s", m_title, dilep, dilep, m_ytitle).c_str(),
148  nxbins, -maxMuMuEta, maxMuMuEta,
149  nybins, valmin, valmax);
150 
151  m_h2_map[xAxis::LP_ETA] = iBooker.book2D(fmt::sprintf("%sVsMuPlusEta", m_name).c_str(),
152  fmt::sprintf("%s vs %s #eta;%s #eta;%s", m_title, lep, lep, m_ytitle).c_str(),
153  nxbins, -maxMuEta, maxMuEta,
154  nybins, valmin, valmax);
155 
156  m_h2_map[xAxis::LP_PHI] = iBooker.book2D(fmt::sprintf("%sVsMuPlusPhi", m_name).c_str(),
157  fmt::sprintf("%s vs %s #phi;%s #phi [rad];%s", m_title, lep, lep, m_ytitle).c_str(),
158  nxbins, -M_PI, M_PI,
159  nybins, valmin, valmax);
160 
161  m_h2_map[xAxis::LM_ETA] = iBooker.book2D(fmt::sprintf("%sVsMuMinusEta", m_name).c_str(),
162  fmt::sprintf("%s vs %s #eta;%s #eta;%s", m_title, lem, lem, m_ytitle).c_str(),
163  nxbins, -maxMuEta, maxMuEta,
164  nybins, valmin, valmax);
165 
166  m_h2_map[xAxis::LM_PHI] = iBooker.book2D(fmt::sprintf("%sVsMuMinusPhi", m_name).c_str(),
167  fmt::sprintf("%s vs %s #phi;%s #phi [rad];%s", m_title, lem, lem, m_ytitle).c_str(),
168  nxbins, -M_PI, M_PI,
169  nybins, valmin, valmax);
170 
171  m_h2_map[xAxis::DELTA_ETA] = iBooker.book2D(fmt::sprintf("%sVsMuMuDeltaEta", m_name).c_str(),
172  fmt::sprintf("%s vs %s #Delta#eta;%s #Delta#eta;%s", m_title, dilep, dilep, m_ytitle).c_str(),
173  nxbins, -4., 4.,
174  nybins, valmin, valmax);
175 
176  m_h2_map[xAxis::COSTHETACS] = iBooker.book2D(fmt::sprintf("%sVsCosThetaCS", m_name).c_str(),
177  fmt::sprintf("%s vs %s cos(#theta_{CS});%s cos(#theta_{CS});%s", m_title, dilep, dilep, m_ytitle).c_str(),
178  nxbins, -1., 1.,
179  nybins, valmin, valmax);
180  // clang-format on
181 
182  // flip the is booked bit
183  m_isBooked = true;
184  }
185 
186  //________________________________________________________________________________//
187  inline void fillPlots(const float val, const std::pair<TLorentzVector, TLorentzVector>& momenta) {
188  if (!m_isBooked) {
189  edm::LogError("PlotsVsKinematics")
190  << "In" << __FUNCTION__ << "," << __LINE__ << "trying to fill a plot not booked!" << std::endl;
191  return;
192  }
193 
194  m_h2_map[xAxis::Z_ETA]->Fill((momenta.first + momenta.second).Eta(), val);
195  m_h2_map[xAxis::Z_PHI]->Fill((momenta.first + momenta.second).Phi(), val);
196  m_h2_map[xAxis::LP_ETA]->Fill((momenta.first).Eta(), val);
197  m_h2_map[xAxis::LP_PHI]->Fill((momenta.first).Phi(), val);
198  m_h2_map[xAxis::LM_ETA]->Fill((momenta.second).Eta(), val);
199  m_h2_map[xAxis::LM_PHI]->Fill((momenta.second).Phi(), val);
200 
201  // follows here kinematics
202  double deltaEta = (momenta.first).Eta() - (momenta.second).Eta();
203 
204  double muplus = 1. / sqrt(2.) * (momenta.first.E() + momenta.first.Z());
205  double muminus = 1. / sqrt(2.) * (momenta.first.E() - momenta.first.Z());
206  double mubarplus = 1. / sqrt(2.) * (momenta.second.E() + momenta.second.Z());
207  double mubarminus = 1. / sqrt(2.) * (momenta.second.E() - momenta.second.Z());
208 
209  const auto& mother = momenta.first + momenta.second;
210  double cosThetaCS = 2. / mother.Mag() / sqrt(pow(mother.Mag(), 2) + pow(mother.Pt(), 2)) *
211  (muplus * mubarminus - muminus * mubarplus);
212 
213  m_h2_map[xAxis::DELTA_ETA]->Fill(deltaEta, val);
214  m_h2_map[xAxis::COSTHETACS]->Fill(cosThetaCS, val);
215  }
216 
217  private:
219  const std::vector<xAxis> axisChoices = {xAxis::Z_PHI,
220  xAxis::Z_ETA,
221  xAxis::LP_PHI,
222  xAxis::LP_ETA,
223  xAxis::LM_PHI,
224  xAxis::LM_ETA,
225  xAxis::DELTA_ETA,
226  xAxis::COSTHETACS};
227 
231 
234 
235  std::map<xAxis, dqm::reco::MonitorElement*> m_h2_map;
236  };
237 } // namespace DiLepPlotHelp
238 #endif
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::map< xAxis, dqm::reco::MonitorElement * > m_h2_map
const std::vector< xAxis > axisChoices
constexpr int pow(int x)
Definition: conifer.h:24
Log< level::Error, false > LogError
static const double deltaEta
Definition: CaloConstants.h:8
Definition: TTTypes.h:54
T sqrt(T t)
Definition: SSEVec.h:19
void fillPlots(const float val, const std::pair< TLorentzVector, TLorentzVector > &momenta)
#define M_PI
void bookPlots(dqm::reco::DQMStore::IBooker &iBooker, const float valmin, const float valmax, const int nxbins, const int nybins)
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
void bookFromPSet(dqm::reco::DQMStore::IBooker &iBooker, const edm::ParameterSet &hpar)
PlotsVsKinematics(flavour FLAV, const std::string &name, const std::string &tt, const std::string &ytt)