CMS 3D CMS Logo

BeamSpotPayloadInspectorHelper.h
Go to the documentation of this file.
1 #ifndef CONDCORE_BEAMSPOTPLUGINS_BEAMSPOTPAYLOADINSPECTORHELPER_H
2 #define CONDCORE_BEAMSPOTPLUGINS_BEAMSPOTPAYLOADINSPECTORHELPER_H
3 
4 // User includes
5 
11 
12 // ROOT includes
13 
14 #include <memory>
15 #include <sstream>
16 #include "TCanvas.h"
17 #include "TH2F.h"
18 #include "TLatex.h"
19 
20 namespace BeamSpotPI {
21 
22  std::pair<unsigned int, unsigned int> unpack(cond::Time_t since) {
23  auto kLowMask = 0XFFFFFFFF;
24  auto run = (since >> 32);
25  auto lumi = (since & kLowMask);
26  return std::make_pair(run, lumi);
27  }
28 
29  enum parameters {
30  X,
31  Y,
32  Z,
45  };
46 
47  /************************************************/
49  switch (parameter) {
50  case X:
51  return "X";
52  case Y:
53  return "Y";
54  case Z:
55  return "Z";
56  case sigmaX:
57  return "sigmaX";
58  case sigmaY:
59  return "sigmaY";
60  case sigmaZ:
61  return "sigmaZ";
62  case dxdz:
63  return "dx/dz";
64  case dydz:
65  return "dy/dz";
66  default:
67  return "should never be here";
68  }
69  }
70 
71  /************************************************
72  template classes (history)
73  *************************************************/
74 
75  template <parameters my_param, class PayloadType>
76  class BeamSpot_history : public cond::payloadInspector::HistoryPlot<PayloadType, std::pair<double, double> > {
77  public:
79  : cond::payloadInspector::HistoryPlot<PayloadType, std::pair<double, double> >(
80  getStringFromParamEnum(my_param) + " vs run number", getStringFromParamEnum(my_param)) {}
81 
82  std::pair<double, double> getFromPayload(PayloadType& payload) override {
83  auto ret = std::make_pair<double, double>(-9999., -9999.);
84 
85  switch (my_param) {
86  case X:
87  return std::make_pair<double, double>(payload.GetX(), payload.GetXError());
88  case Y:
89  return std::make_pair<double, double>(payload.GetY(), payload.GetYError());
90  case Z:
91  return std::make_pair<double, double>(payload.GetZ(), payload.GetZError());
92  case sigmaX:
93  return std::make_pair<double, double>(payload.GetBeamWidthX(), payload.GetBeamWidthXError());
94  case sigmaY:
95  return std::make_pair<double, double>(payload.GetBeamWidthY(), payload.GetBeamWidthYError());
96  case sigmaZ:
97  return std::make_pair<double, double>(payload.GetSigmaZ(), payload.GetSigmaZError());
98  case dxdz:
99  return std::make_pair<double, double>(payload.Getdxdz(), payload.GetdxdzError());
100  case dydz:
101  return std::make_pair<double, double>(payload.Getdydz(), payload.GetdydzError());
102  case END_OF_TYPES:
103  return ret;
104  default:
105  return ret;
106  }
107  }
108  };
109 
110  /************************************************
111  template classes (run history)
112  *************************************************/
113 
114  template <parameters my_param, class PayloadType>
115  class BeamSpot_runhistory : public cond::payloadInspector::RunHistoryPlot<PayloadType, std::pair<double, double> > {
116  public:
118  : cond::payloadInspector::RunHistoryPlot<PayloadType, std::pair<double, double> >(
119  getStringFromParamEnum(my_param) + " vs run number", getStringFromParamEnum(my_param)) {}
120 
121  std::pair<double, double> getFromPayload(PayloadType& payload) override {
122  auto ret = std::make_pair<double, double>(-9999., -9999.);
123 
124  switch (my_param) {
125  case X:
126  return std::make_pair<double, double>(payload.GetX(), payload.GetXError());
127  case Y:
128  return std::make_pair<double, double>(payload.GetY(), payload.GetYError());
129  case Z:
130  return std::make_pair<double, double>(payload.GetZ(), payload.GetZError());
131  case sigmaX:
132  return std::make_pair<double, double>(payload.GetBeamWidthX(), payload.GetBeamWidthXError());
133  case sigmaY:
134  return std::make_pair<double, double>(payload.GetBeamWidthY(), payload.GetBeamWidthYError());
135  case sigmaZ:
136  return std::make_pair<double, double>(payload.GetSigmaZ(), payload.GetSigmaZError());
137  case dxdz:
138  return std::make_pair<double, double>(payload.Getdxdz(), payload.GetdxdzError());
139  case dydz:
140  return std::make_pair<double, double>(payload.Getdydz(), payload.GetdydzError());
141  case END_OF_TYPES:
142  return ret;
143  default:
144  return ret;
145  }
146  }
147  };
148 
149  /************************************************
150  template classes (time history)
151  *************************************************/
152 
153  template <parameters my_param, class PayloadType>
154  class BeamSpot_timehistory : public cond::payloadInspector::TimeHistoryPlot<PayloadType, std::pair<double, double> > {
155  public:
158  getStringFromParamEnum(my_param) + " vs time", getStringFromParamEnum(my_param)) {}
159 
160  std::pair<double, double> getFromPayload(PayloadType& payload) override {
161  auto ret = std::make_pair<double, double>(-9999., -9999.);
162 
163  switch (my_param) {
164  case X:
165  return std::make_pair<double, double>(payload.GetX(), payload.GetXError());
166  case Y:
167  return std::make_pair<double, double>(payload.GetY(), payload.GetYError());
168  case Z:
169  return std::make_pair<double, double>(payload.GetZ(), payload.GetZError());
170  case sigmaX:
171  return std::make_pair<double, double>(payload.GetBeamWidthX(), payload.GetBeamWidthXError());
172  case sigmaY:
173  return std::make_pair<double, double>(payload.GetBeamWidthY(), payload.GetBeamWidthYError());
174  case sigmaZ:
175  return std::make_pair<double, double>(payload.GetSigmaZ(), payload.GetSigmaZError());
176  case dxdz:
177  return std::make_pair<double, double>(payload.Getdxdz(), payload.GetdxdzError());
178  case dydz:
179  return std::make_pair<double, double>(payload.Getdydz(), payload.GetdydzError());
180  case END_OF_TYPES:
181  return ret;
182  default:
183  return ret;
184  }
185  }
186  };
187 
188  /************************************************
189  X-Y correlation plot
190  *************************************************/
191  template <class PayloadType>
192  class xyCorrelation : public cond::payloadInspector::ScatterPlot<PayloadType, double, double> {
193  public:
194  xyCorrelation() : cond::payloadInspector::ScatterPlot<PayloadType, double, double>("BeamSpot x vs y", "x", "y") {}
195 
196  std::tuple<double, double> getFromPayload(PayloadType& payload) override {
197  return std::make_tuple(payload.GetX(), payload.GetY());
198  }
199  };
200 
201  /************************************************
202  Display of Beam Spot parameters
203  *************************************************/
204  template <class PayloadType>
205  class DisplayParameters : public cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV> {
206  public:
209  "Display of BeamSpot parameters") {
210  if constexpr (std::is_same_v<PayloadType, BeamSpotOnlineObjects>) {
211  isOnline_ = true;
212  } else {
213  isOnline_ = false;
214  }
215  }
216 
217  bool fill() override {
218  auto tag = cond::payloadInspector::PlotBase::getTag<0>();
219  auto tagname = tag.name;
220  auto iov = tag.iovs.front();
221 
222  m_payload = this->fetchPayload(std::get<1>(iov));
223 
224  TCanvas canvas("Beam Spot Parameters Summary", "BeamSpot Parameters summary", isOnline_ ? 1500 : 1000, 1000);
225  if (isOnline_) {
226  canvas.Divide(2, 1);
227  }
228  canvas.cd(1);
229 
230  canvas.cd(1)->SetTopMargin(0.05);
231  canvas.cd(1)->SetBottomMargin(0.06);
232  canvas.cd(1)->SetLeftMargin(0.15);
233  canvas.cd(1)->SetRightMargin(0.03);
234  canvas.cd(1)->Modified();
235  canvas.cd(1)->SetGrid();
236 
237  auto h2_BSParameters = std::unique_ptr<TH2F>(new TH2F("Parameters", "", 2, 0.0, 2.0, 8, 0, 8.));
238  h2_BSParameters->SetStats(false);
239 
240  std::function<double(parameters, bool)> cutFunctor = [this](parameters my_param, bool isError) {
241  double ret(-999.);
242  if (!isError) {
243  switch (my_param) {
244  case X:
245  return m_payload->GetX();
246  case Y:
247  return m_payload->GetY();
248  case Z:
249  return m_payload->GetZ();
250  case sigmaX:
251  return m_payload->GetBeamWidthX();
252  case sigmaY:
253  return m_payload->GetBeamWidthY();
254  case sigmaZ:
255  return m_payload->GetSigmaZ();
256  case dxdz:
257  return m_payload->Getdxdz();
258  case dydz:
259  return m_payload->Getdydz();
260  case END_OF_TYPES:
261  return ret;
262  default:
263  return ret;
264  }
265  } else {
266  switch (my_param) {
267  case X:
268  return m_payload->GetXError();
269  case Y:
270  return m_payload->GetYError();
271  case Z:
272  return m_payload->GetZError();
273  case sigmaX:
274  return m_payload->GetBeamWidthXError();
275  case sigmaY:
276  return m_payload->GetBeamWidthYError();
277  case sigmaZ:
278  return m_payload->GetSigmaZError();
279  case dxdz:
280  return m_payload->GetdxdzError();
281  case dydz:
282  return m_payload->GetdydzError();
283  case END_OF_TYPES:
284  return ret;
285  default:
286  return ret;
287  }
288  }
289  };
290 
291  h2_BSParameters->GetXaxis()->SetBinLabel(1, "Value");
292  h2_BSParameters->GetXaxis()->SetBinLabel(2, "Error");
293 
294  unsigned int yBin = 8;
295  for (int foo = parameters::X; foo <= parameters::dydz; foo++) {
296  parameters param = static_cast<parameters>(foo);
297  std::string theLabel = getStringFromTypeEnum(param);
298  h2_BSParameters->GetYaxis()->SetBinLabel(yBin, theLabel.c_str());
299  h2_BSParameters->SetBinContent(1, yBin, cutFunctor(param, false));
300  h2_BSParameters->SetBinContent(2, yBin, cutFunctor(param, true));
301  yBin--;
302  }
303 
304  h2_BSParameters->GetXaxis()->LabelsOption("h");
305  h2_BSParameters->GetYaxis()->SetLabelSize(0.05);
306  h2_BSParameters->GetXaxis()->SetLabelSize(0.05);
307  h2_BSParameters->SetMarkerSize(1.5);
308  h2_BSParameters->Draw("TEXT");
309 
310  auto ltx = TLatex();
311  ltx.SetTextFont(62);
312  if (isOnline_) {
313  ltx.SetTextSize(0.040);
314  } else {
315  ltx.SetTextSize(0.032);
316  }
317  ltx.SetTextAlign(11);
318 
319  auto runLS = BeamSpotPI::unpack(std::get<0>(iov));
320 
321  ltx.DrawLatexNDC(
322  gPad->GetLeftMargin(),
323  1 - gPad->GetTopMargin() + 0.01,
324  (tagname + " IOV: #color[4]{" + std::to_string(runLS.first) + "," + std::to_string(runLS.second) + "}")
325  .c_str());
326 
327  if (isOnline_) {
328  canvas.cd(2);
329  canvas.cd(2)->SetTopMargin(0.05);
330  canvas.cd(2)->SetBottomMargin(0.06);
331  canvas.cd(2)->SetLeftMargin(0.15);
332  canvas.cd(2)->SetRightMargin(0.03);
333  canvas.cd(2)->Modified();
334  canvas.cd(2)->SetGrid();
335 
336  auto extras = fillTheExtraHistogram();
337  if (extras) {
338  for (int bin = 1; bin <= extras->GetNbinsY(); bin++) {
339  edm::LogVerbatim("BeamSpotPayloadInspectorHelper")
340  << extras->GetYaxis()->GetBinLabel(bin) << ": " << extras->GetBinContent(1, bin) << "\n";
341  }
342  }
343  extras->Draw("TEXT");
344 
345  ltx.DrawLatexNDC(
346  gPad->GetLeftMargin(),
347  1 - gPad->GetTopMargin() + 0.01,
348  (tagname + " IOV: #color[4]{" + std::to_string(runLS.first) + "," + std::to_string(runLS.second) + "}")
349  .c_str());
350 
352  canvas.SaveAs(fileName.c_str());
353 
354  return true;
355  } else {
357  canvas.SaveAs(fileName.c_str());
358 
359  return true;
360  }
361  }
362 
363  public:
364  virtual std::shared_ptr<TH2F> fillTheExtraHistogram() const { return nullptr; }
365 
366  protected:
367  bool isOnline_;
368  std::shared_ptr<PayloadType> m_payload;
369 
370  /************************************************/
371  virtual std::string getStringFromTypeEnum(const parameters& parameter) const {
372  switch (parameter) {
373  case X:
374  return "X [cm]";
375  case Y:
376  return "Y [cm]";
377  case Z:
378  return "Z [cm]";
379  case sigmaX:
380  return "#sigma_{X} [cm]";
381  case sigmaY:
382  return "#sigma_{Y} [cm]";
383  case sigmaZ:
384  return "#sigma_{Z} [cm]";
385  case dxdz:
386  return "#frac{dX}{dZ} [rad]";
387  case dydz:
388  return "#frac{dY}{dZ} [rad]";
389  default:
390  return "should never be here";
391  }
392  }
393  };
394 } // namespace BeamSpotPI
395 
396 #endif
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:367
svgfig.canvas
def canvas(*sub, **attr)
Definition: svgfig.py:482
BeamSpotPI::nPVs
Definition: BeamSpotPayloadInspectorHelper.h:42
BeamSpotPI::parameters
parameters
Definition: BeamSpotPayloadInspectorHelper.h:29
cond::payloadInspector::PlotImage< PayloadType, cond::payloadInspector::SINGLE_IOV >::m_imageFileName
std::string m_imageFileName
Definition: PayloadInspector.h:868
BeamSpotPI::DisplayParameters::fillTheExtraHistogram
virtual std::shared_ptr< TH2F > fillTheExtraHistogram() const
Definition: BeamSpotPayloadInspectorHelper.h:360
BeamSpotPI::sigmaX
Definition: BeamSpotPayloadInspectorHelper.h:33
MessageLogger.h
pfMETsysShiftCorrections_cfi.parameter
parameter
Definition: pfMETsysShiftCorrections_cfi.py:118
BeamSpotPI::X
Definition: BeamSpotPayloadInspectorHelper.h:30
BeamSpotPI::BeamSpot_runhistory::getFromPayload
std::pair< double, double > getFromPayload(PayloadType &payload) override
Definition: BeamSpotPayloadInspectorHelper.h:120
BeamSpotPI::BeamSpot_timehistory::getFromPayload
std::pair< double, double > getFromPayload(PayloadType &payload) override
Definition: BeamSpotPayloadInspectorHelper.h:158
BeamSpotPI::sigmaZ
Definition: BeamSpotPayloadInspectorHelper.h:35
X
#define X(str)
Definition: MuonsGrabber.cc:38
PayloadInspector.h
BeamSpotPI::xyCorrelation::xyCorrelation
xyCorrelation()
Definition: BeamSpotPayloadInspectorHelper.h:191
photonAnalyzer_cfi.yBin
yBin
Definition: photonAnalyzer_cfi.py:85
BeamSpotPI::BeamSpot_history::getFromPayload
std::pair< double, double > getFromPayload(PayloadType &payload) override
Definition: BeamSpotPayloadInspectorHelper.h:82
BeamSpotPI::DisplayParameters::isOnline_
bool isOnline_
Definition: BeamSpotPayloadInspectorHelper.h:363
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
cond::payloadInspector::RunHistoryPlot< PayloadType, std::pair< double, double > >::RunHistoryPlot
RunHistoryPlot(const std::string &title, const std::string &yLabel)
Definition: PayloadInspector.h:551
BeamSpotPI::nTracks
Definition: BeamSpotPayloadInspectorHelper.h:41
PayloadInspectorModule.h
BeamSpotPI::DisplayParameters::getStringFromTypeEnum
virtual std::string getStringFromTypeEnum(const parameters &parameter) const
Definition: BeamSpotPayloadInspectorHelper.h:367
BeamSpotPI::lastLumi
Definition: BeamSpotPayloadInspectorHelper.h:38
BeamSpotPI::BeamSpot_runhistory::BeamSpot_runhistory
BeamSpot_runhistory()
Definition: BeamSpotPayloadInspectorHelper.h:116
BeamSpotPI::lastFill
Definition: BeamSpotPayloadInspectorHelper.h:40
cond::payloadInspector::ScatterPlot
Definition: PayloadInspector.h:680
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
writeEcalDQMStatus.since
since
Definition: writeEcalDQMStatus.py:53
BeamSpotPI::dxdz
Definition: BeamSpotPayloadInspectorHelper.h:36
jets_cff.payload
payload
Definition: jets_cff.py:32
cond::payloadInspector::HistoryPlot
Definition: PayloadInspector.h:524
BeamSpotPI::sigmaY
Definition: BeamSpotPayloadInspectorHelper.h:34
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
BeamSpotPI::lastRun
Definition: BeamSpotPayloadInspectorHelper.h:39
cond
Definition: plugin.cc:23
BeamSpotPI::END_OF_TYPES
Definition: BeamSpotPayloadInspectorHelper.h:44
Time.h
cond::payloadInspector::ScatterPlot< PayloadType, double, double >::ScatterPlot
ScatterPlot(const std::string &title, const std::string &xLabel, const std::string &yLabel)
Definition: PayloadInspector.h:684
BeamSpotPI::getStringFromParamEnum
std::string getStringFromParamEnum(const parameters &parameter)
Definition: BeamSpotPayloadInspectorHelper.h:48
cond::time::kLowMask
const Time_t kLowMask(0xFFFFFFFF)
cond::payloadInspector::PlotImage< PayloadType, cond::payloadInspector::SINGLE_IOV >::fetchPayload
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
Definition: PayloadInspector.h:863
cond::Time_t
unsigned long long Time_t
Definition: Time.h:14
cond::payloadInspector::RunHistoryPlot
Definition: PayloadInspector.h:547
BeamSpotPI::DisplayParameters::DisplayParameters
DisplayParameters()
Definition: BeamSpotPayloadInspectorHelper.h:203
BeamSpotPI::dydz
Definition: BeamSpotPayloadInspectorHelper.h:37
BeamSpotPI::DisplayParameters::m_payload
std::shared_ptr< PayloadType > m_payload
Definition: BeamSpotPayloadInspectorHelper.h:364
BeamSpotPI::xyCorrelation
Definition: BeamSpotPayloadInspectorHelper.h:188
cond::payloadInspector::HistoryPlot< PayloadType, std::pair< double, double > >::HistoryPlot
HistoryPlot(const std::string &title, const std::string &yLabel)
Definition: PayloadInspector.h:528
cond::payloadInspector::TimeHistoryPlot
Definition: PayloadInspector.h:621
BeamSpotPI::creationTime
Definition: BeamSpotPayloadInspectorHelper.h:43
BeamSpotPI::xyCorrelation::getFromPayload
std::tuple< double, double > getFromPayload(PayloadType &payload) override
Definition: BeamSpotPayloadInspectorHelper.h:193
BeamSpotPI::BeamSpot_history
Definition: BeamSpotPayloadInspectorHelper.h:75
BeamSpotPI::BeamSpot_history::BeamSpot_history
BeamSpot_history()
Definition: BeamSpotPayloadInspectorHelper.h:78
BeamSpotPI::DisplayParameters::fill
bool fill() override
Definition: BeamSpotPayloadInspectorHelper.h:213
createPayload.tagname
tagname
Definition: createPayload.py:183
BeamSpotPI::BeamSpot_runhistory
Definition: BeamSpotPayloadInspectorHelper.h:113
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
BeamSpotPI::DisplayParameters
Definition: BeamSpotPayloadInspectorHelper.h:200
std
Definition: JetResolutionObject.h:76
writedatasetfile.run
run
Definition: writedatasetfile.py:27
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
BeamSpotPI::BeamSpot_timehistory::BeamSpot_timehistory
BeamSpot_timehistory()
Definition: BeamSpotPayloadInspectorHelper.h:154
cond::payloadInspector::PlotImage
Definition: PayloadInspector.h:852
HiBiasedCentrality_cfi.function
function
Definition: HiBiasedCentrality_cfi.py:4
BeamSpotPI::unpack
std::pair< unsigned int, unsigned int > unpack(cond::Time_t since)
Definition: BeamSpotPayloadInspectorHelper.h:22
BeamSpotPI::Y
Definition: BeamSpotPayloadInspectorHelper.h:31
BeamSpotPI::BeamSpot_timehistory
Definition: BeamSpotPayloadInspectorHelper.h:151
BeamSpotOnlineObjects.h
BeamSpotPI::Z
Definition: BeamSpotPayloadInspectorHelper.h:32
lumi
Definition: LumiSectionData.h:20
BeamSpotPI
Definition: BeamSpotPayloadInspectorHelper.h:20