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