CMS 3D CMS Logo

BeamSpot_PayloadInspector.cc
Go to the documentation of this file.
4 
6 
7 #include <memory>
8 #include <sstream>
9 #include "TCanvas.h"
10 #include "TH2F.h"
11 
12 namespace {
13 
15 
16  /************************************************/
17  std::string getStringFromParamEnum(const parameters& parameter) {
18  switch (parameter) {
19  case X:
20  return "X";
21  case Y:
22  return "Y";
23  case Z:
24  return "Z";
25  case sigmaX:
26  return "sigmaX";
27  case sigmaY:
28  return "sigmaY";
29  case sigmaZ:
30  return "sigmaZ";
31  case dxdz:
32  return "dx/dz";
33  case dydz:
34  return "dy/dz";
35  default:
36  return "should never be here";
37  }
38  }
39 
40  class BeamSpot_hx : public cond::payloadInspector::HistoryPlot<BeamSpotObjects, std::pair<double, double> > {
41  public:
42  BeamSpot_hx()
43  : cond::payloadInspector::HistoryPlot<BeamSpotObjects, std::pair<double, double> >("x vs run number", "x") {}
44 
45  std::pair<double, double> getFromPayload(BeamSpotObjects& payload) override {
46  return std::make_pair(payload.GetX(), payload.GetXError());
47  }
48  };
49 
50  class BeamSpot_rhx : public cond::payloadInspector::RunHistoryPlot<BeamSpotObjects, std::pair<double, double> > {
51  public:
52  BeamSpot_rhx()
53  : cond::payloadInspector::RunHistoryPlot<BeamSpotObjects, std::pair<double, double> >("x vs run number", "x") {}
54 
55  std::pair<double, double> getFromPayload(BeamSpotObjects& payload) override {
56  return std::make_pair(payload.GetX(), payload.GetXError());
57  }
58  };
59  class BeamSpot_x : public cond::payloadInspector::TimeHistoryPlot<BeamSpotObjects, std::pair<double, double> > {
60  public:
61  BeamSpot_x()
62  : cond::payloadInspector::TimeHistoryPlot<BeamSpotObjects, std::pair<double, double> >("x vs time", "x") {}
63 
64  std::pair<double, double> getFromPayload(BeamSpotObjects& payload) override {
65  return std::make_pair(payload.GetX(), payload.GetXError());
66  }
67  };
68 
69  class BeamSpot_y : public cond::payloadInspector::TimeHistoryPlot<BeamSpotObjects, std::pair<double, double> > {
70  public:
71  BeamSpot_y()
72  : cond::payloadInspector::TimeHistoryPlot<BeamSpotObjects, std::pair<double, double> >("y vs time", "y") {}
73 
74  std::pair<double, double> getFromPayload(BeamSpotObjects& payload) override {
75  return std::make_pair(payload.GetY(), payload.GetYError());
76  }
77  };
78 
79  /************************************************
80  template classes (history)
81  *************************************************/
82 
83  template <parameters my_param>
84  class BeamSpot_history : public cond::payloadInspector::HistoryPlot<BeamSpotObjects, std::pair<double, double> > {
85  public:
86  BeamSpot_history()
87  : cond::payloadInspector::HistoryPlot<BeamSpotObjects, std::pair<double, double> >(
88  getStringFromParamEnum(my_param) + " vs run number", getStringFromParamEnum(my_param)) {}
89 
90  std::pair<double, double> getFromPayload(BeamSpotObjects& payload) override {
91  auto ret = std::make_pair<double, double>(-9999., -9999.);
92 
93  switch (my_param) {
94  case X:
95  return std::make_pair<double, double>(payload.GetX(), payload.GetXError());
96  case Y:
97  return std::make_pair<double, double>(payload.GetY(), payload.GetYError());
98  case Z:
99  return std::make_pair<double, double>(payload.GetZ(), payload.GetZError());
100  case sigmaX:
101  return std::make_pair<double, double>(payload.GetBeamWidthX(), payload.GetBeamWidthXError());
102  case sigmaY:
103  return std::make_pair<double, double>(payload.GetBeamWidthY(), payload.GetBeamWidthYError());
104  case sigmaZ:
105  return std::make_pair<double, double>(payload.GetSigmaZ(), payload.GetSigmaZError());
106  case dxdz:
107  return std::make_pair<double, double>(payload.Getdxdz(), payload.GetdxdzError());
108  case dydz:
109  return std::make_pair<double, double>(payload.Getdydz(), payload.GetdydzError());
110  case END_OF_TYPES:
111  return ret;
112  default:
113  return ret;
114  }
115  }
116  };
117 
118  typedef BeamSpot_history<X> BeamSpot_HistoryX;
119  typedef BeamSpot_history<Y> BeamSpot_HistoryY;
120  typedef BeamSpot_history<Z> BeamSpot_HistoryZ;
121  typedef BeamSpot_history<sigmaX> BeamSpot_HistorySigmaX;
122  typedef BeamSpot_history<sigmaY> BeamSpot_HistorySigmaY;
123  typedef BeamSpot_history<sigmaZ> BeamSpot_HistorySigmaZ;
124  typedef BeamSpot_history<dxdz> BeamSpot_HistorydXdZ;
125  typedef BeamSpot_history<dydz> BeamSpot_HistorydYdZ;
126 
127  /************************************************
128  template classes (run history)
129  *************************************************/
130 
131  template <parameters my_param>
132  class BeamSpot_runhistory
133  : public cond::payloadInspector::RunHistoryPlot<BeamSpotObjects, std::pair<double, double> > {
134  public:
135  BeamSpot_runhistory()
136  : cond::payloadInspector::RunHistoryPlot<BeamSpotObjects, std::pair<double, double> >(
137  getStringFromParamEnum(my_param) + " vs run number", getStringFromParamEnum(my_param)) {}
138 
139  std::pair<double, double> getFromPayload(BeamSpotObjects& payload) override {
140  auto ret = std::make_pair<double, double>(-9999., -9999.);
141 
142  switch (my_param) {
143  case X:
144  return std::make_pair<double, double>(payload.GetX(), payload.GetXError());
145  case Y:
146  return std::make_pair<double, double>(payload.GetY(), payload.GetYError());
147  case Z:
148  return std::make_pair<double, double>(payload.GetZ(), payload.GetZError());
149  case sigmaX:
150  return std::make_pair<double, double>(payload.GetBeamWidthX(), payload.GetBeamWidthXError());
151  case sigmaY:
152  return std::make_pair<double, double>(payload.GetBeamWidthY(), payload.GetBeamWidthYError());
153  case sigmaZ:
154  return std::make_pair<double, double>(payload.GetSigmaZ(), payload.GetSigmaZError());
155  case dxdz:
156  return std::make_pair<double, double>(payload.Getdxdz(), payload.GetdxdzError());
157  case dydz:
158  return std::make_pair<double, double>(payload.Getdydz(), payload.GetdydzError());
159  case END_OF_TYPES:
160  return ret;
161  default:
162  return ret;
163  }
164  }
165  };
166 
167  typedef BeamSpot_runhistory<X> BeamSpot_RunHistoryX;
168  typedef BeamSpot_runhistory<Y> BeamSpot_RunHistoryY;
169  typedef BeamSpot_runhistory<Z> BeamSpot_RunHistoryZ;
170  typedef BeamSpot_runhistory<sigmaX> BeamSpot_RunHistorySigmaX;
171  typedef BeamSpot_runhistory<sigmaY> BeamSpot_RunHistorySigmaY;
172  typedef BeamSpot_runhistory<sigmaZ> BeamSpot_RunHistorySigmaZ;
173  typedef BeamSpot_runhistory<dxdz> BeamSpot_RunHistorydXdZ;
174  typedef BeamSpot_runhistory<dydz> BeamSpot_RunHistorydYdZ;
175 
176  /************************************************
177  template classes (time history)
178  *************************************************/
179 
180  template <parameters my_param>
181  class BeamSpot_timehistory
182  : public cond::payloadInspector::TimeHistoryPlot<BeamSpotObjects, std::pair<double, double> > {
183  public:
184  BeamSpot_timehistory()
185  : cond::payloadInspector::TimeHistoryPlot<BeamSpotObjects, std::pair<double, double> >(
186  getStringFromParamEnum(my_param) + " vs time", getStringFromParamEnum(my_param)) {}
187 
188  std::pair<double, double> getFromPayload(BeamSpotObjects& payload) override {
189  auto ret = std::make_pair<double, double>(-9999., -9999.);
190 
191  switch (my_param) {
192  case X:
193  return std::make_pair<double, double>(payload.GetX(), payload.GetXError());
194  case Y:
195  return std::make_pair<double, double>(payload.GetY(), payload.GetYError());
196  case Z:
197  return std::make_pair<double, double>(payload.GetZ(), payload.GetZError());
198  case sigmaX:
199  return std::make_pair<double, double>(payload.GetBeamWidthX(), payload.GetBeamWidthXError());
200  case sigmaY:
201  return std::make_pair<double, double>(payload.GetBeamWidthY(), payload.GetBeamWidthYError());
202  case sigmaZ:
203  return std::make_pair<double, double>(payload.GetSigmaZ(), payload.GetSigmaZError());
204  case dxdz:
205  return std::make_pair<double, double>(payload.Getdxdz(), payload.GetdxdzError());
206  case dydz:
207  return std::make_pair<double, double>(payload.Getdydz(), payload.GetdydzError());
208  case END_OF_TYPES:
209  return ret;
210  default:
211  return ret;
212  }
213  }
214  };
215 
216  typedef BeamSpot_timehistory<X> BeamSpot_TimeHistoryX;
217  typedef BeamSpot_timehistory<Y> BeamSpot_TimeHistoryY;
218  typedef BeamSpot_timehistory<Z> BeamSpot_TimeHistoryZ;
219  typedef BeamSpot_timehistory<sigmaX> BeamSpot_TimeHistorySigmaX;
220  typedef BeamSpot_timehistory<sigmaY> BeamSpot_TimeHistorySigmaY;
221  typedef BeamSpot_timehistory<sigmaZ> BeamSpot_TimeHistorySigmaZ;
222  typedef BeamSpot_timehistory<dxdz> BeamSpot_TimeHistorydXdZ;
223  typedef BeamSpot_timehistory<dydz> BeamSpot_TimeHistorydYdZ;
224 
225  /************************************************
226  X-Y correlation plot
227  *************************************************/
228  class BeamSpot_xy : public cond::payloadInspector::ScatterPlot<BeamSpotObjects, double, double> {
229  public:
230  BeamSpot_xy() : cond::payloadInspector::ScatterPlot<BeamSpotObjects, double, double>("BeamSpot x vs y", "x", "y") {}
231 
232  std::tuple<double, double> getFromPayload(BeamSpotObjects& payload) override {
233  return std::make_tuple(payload.GetX(), payload.GetY());
234  }
235  };
236 
237  /************************************************
238  Display of Beam Spot parameters
239  *************************************************/
240  class BeamSpotParameters : public cond::payloadInspector::PlotImage<BeamSpotObjects> {
241  public:
242  BeamSpotParameters() : cond::payloadInspector::PlotImage<BeamSpotObjects>("Display of BeamSpot parameters") {
243  setSingleIov(true);
244  }
245 
246  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
247  auto iov = iovs.front();
248  std::shared_ptr<BeamSpotObjects> payload = fetchPayload(std::get<1>(iov));
249 
250  TCanvas canvas("Beam Spot Parameters Summary", "BeamSpot Parameters summary", 1000, 1000);
251  canvas.cd();
252 
253  canvas.SetTopMargin(0.07);
254  canvas.SetBottomMargin(0.06);
255  canvas.SetLeftMargin(0.15);
256  canvas.SetRightMargin(0.03);
257  canvas.Modified();
258  canvas.SetGrid();
259 
260  auto h2_BSParameters =
261  std::unique_ptr<TH2F>(new TH2F("Parameters", "BeamSpot parameters summary", 2, 0.0, 2.0, 8, 0, 8.));
262  h2_BSParameters->SetStats(false);
263 
264  std::function<double(parameters, bool)> cutFunctor = [&payload](parameters my_param, bool isError) {
265  double ret(-999.);
266  if (!isError) {
267  switch (my_param) {
268  case X:
269  return payload->GetX();
270  case Y:
271  return payload->GetY();
272  case Z:
273  return payload->GetZ();
274  case sigmaX:
275  return payload->GetBeamWidthX();
276  case sigmaY:
277  return payload->GetBeamWidthY();
278  case sigmaZ:
279  return payload->GetSigmaZ();
280  case dxdz:
281  return payload->Getdxdz();
282  case dydz:
283  return payload->Getdydz();
284  case END_OF_TYPES:
285  return ret;
286  default:
287  return ret;
288  }
289  } else {
290  switch (my_param) {
291  case X:
292  return payload->GetXError();
293  case Y:
294  return payload->GetYError();
295  case Z:
296  return payload->GetZError();
297  case sigmaX:
298  return payload->GetBeamWidthXError();
299  case sigmaY:
300  return payload->GetBeamWidthYError();
301  case sigmaZ:
302  return payload->GetSigmaZError();
303  case dxdz:
304  return payload->GetdxdzError();
305  case dydz:
306  return payload->GetdydzError();
307  case END_OF_TYPES:
308  return ret;
309  default:
310  return ret;
311  }
312  }
313  };
314 
315  h2_BSParameters->GetXaxis()->SetBinLabel(1, "Value");
316  h2_BSParameters->GetXaxis()->SetBinLabel(2, "Error");
317 
318  unsigned int yBin = 8;
319  for (int foo = parameters::X; foo != parameters::END_OF_TYPES; foo++) {
320  parameters param = static_cast<parameters>(foo);
321  std::string theLabel = getStringFromTypeEnum(param);
322  h2_BSParameters->GetYaxis()->SetBinLabel(yBin, theLabel.c_str());
323  h2_BSParameters->SetBinContent(1, yBin, cutFunctor(param, false));
324  h2_BSParameters->SetBinContent(2, yBin, cutFunctor(param, true));
325  yBin--;
326  }
327 
328  h2_BSParameters->GetXaxis()->LabelsOption("h");
329 
330  h2_BSParameters->GetYaxis()->SetLabelSize(0.05);
331  h2_BSParameters->GetXaxis()->SetLabelSize(0.05);
332 
333  h2_BSParameters->SetMarkerSize(1.5);
334  h2_BSParameters->Draw("TEXT");
335 
336  std::string fileName(m_imageFileName);
337  canvas.SaveAs(fileName.c_str());
338 
339  return true;
340  }
341 
342  /************************************************/
344  switch (parameter) {
345  case X:
346  return "X [cm]";
347  case Y:
348  return "Y [cm]";
349  case Z:
350  return "Z [cm]";
351  case sigmaX:
352  return "#sigma_{X} [cm]";
353  case sigmaY:
354  return "#sigma_{Y} [cm]";
355  case sigmaZ:
356  return "#sigma_{Z} [cm]";
357  case dxdz:
358  return "#frac{dX}{dZ} [rad]";
359  case dydz:
360  return "#frac{dY}{dZ} [rad]";
361  default:
362  return "should never be here";
363  }
364  }
365  };
366 
367 } // namespace
368 
370  PAYLOAD_INSPECTOR_CLASS(BeamSpot_hx);
371  PAYLOAD_INSPECTOR_CLASS(BeamSpot_rhx);
372  PAYLOAD_INSPECTOR_CLASS(BeamSpot_x);
373  PAYLOAD_INSPECTOR_CLASS(BeamSpot_y);
374  PAYLOAD_INSPECTOR_CLASS(BeamSpot_xy);
375  PAYLOAD_INSPECTOR_CLASS(BeamSpotParameters);
376  PAYLOAD_INSPECTOR_CLASS(BeamSpot_HistoryX);
377  PAYLOAD_INSPECTOR_CLASS(BeamSpot_HistoryY);
378  PAYLOAD_INSPECTOR_CLASS(BeamSpot_HistoryZ);
379  PAYLOAD_INSPECTOR_CLASS(BeamSpot_HistorySigmaX);
380  PAYLOAD_INSPECTOR_CLASS(BeamSpot_HistorySigmaY);
381  PAYLOAD_INSPECTOR_CLASS(BeamSpot_HistorySigmaZ);
382  PAYLOAD_INSPECTOR_CLASS(BeamSpot_HistorydXdZ);
383  PAYLOAD_INSPECTOR_CLASS(BeamSpot_HistorydYdZ);
384  PAYLOAD_INSPECTOR_CLASS(BeamSpot_RunHistoryX);
385  PAYLOAD_INSPECTOR_CLASS(BeamSpot_RunHistoryY);
386  PAYLOAD_INSPECTOR_CLASS(BeamSpot_RunHistoryZ);
387  PAYLOAD_INSPECTOR_CLASS(BeamSpot_RunHistorySigmaX);
388  PAYLOAD_INSPECTOR_CLASS(BeamSpot_RunHistorySigmaY);
389  PAYLOAD_INSPECTOR_CLASS(BeamSpot_RunHistorySigmaZ);
390  PAYLOAD_INSPECTOR_CLASS(BeamSpot_RunHistorydXdZ);
391  PAYLOAD_INSPECTOR_CLASS(BeamSpot_RunHistorydYdZ);
392  PAYLOAD_INSPECTOR_CLASS(BeamSpot_TimeHistoryX);
393  PAYLOAD_INSPECTOR_CLASS(BeamSpot_TimeHistoryY);
394  PAYLOAD_INSPECTOR_CLASS(BeamSpot_TimeHistoryZ);
395  PAYLOAD_INSPECTOR_CLASS(BeamSpot_TimeHistorySigmaX);
396  PAYLOAD_INSPECTOR_CLASS(BeamSpot_TimeHistorySigmaY);
397  PAYLOAD_INSPECTOR_CLASS(BeamSpot_TimeHistorySigmaZ);
398  PAYLOAD_INSPECTOR_CLASS(BeamSpot_TimeHistorydXdZ);
399  PAYLOAD_INSPECTOR_CLASS(BeamSpot_TimeHistorydYdZ);
400 }
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:355
svgfig.canvas
def canvas(*sub, **attr)
Definition: svgfig.py:482
ScatterPlot
Definition: trackSplitPlot.h:33
BeamSpotFakeParameters_cfi.dxdz
dxdz
Definition: BeamSpotFakeParameters_cfi.py:12
align::BeamSpot
Definition: StructureType.h:89
X
#define X(str)
Definition: MuonsGrabber.cc:38
PayloadInspector.h
PAYLOAD_INSPECTOR_CLASS
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
Definition: PayloadInspectorModule.h:10
photonAnalyzer_cfi.yBin
yBin
Definition: photonAnalyzer_cfi.py:85
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
PayloadInspectorModule.h
parameters
parameters
Definition: BeamSpot_PayloadInspector.cc:14
PVValHelper::END_OF_TYPES
Definition: PVValidationHelpers.h:64
cond::payloadInspector::TimeHistoryPlot::getFromPayload
virtual Y getFromPayload(PayloadType &payload)=0
BeamSpotObjects.h
cond::payloadInspector::ScatterPlot
Definition: PayloadInspector.h:657
parameter
Definition: vlib.h:168
cond::payloadInspector::ScatterPlot::getFromPayload
virtual std::tuple< X, Y > getFromPayload(PayloadType &payload)=0
jets_cff.payload
payload
Definition: jets_cff.py:34
PAYLOAD_INSPECTOR_MODULE
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
Definition: PayloadInspectorModule.h:8
cond::payloadInspector::HistoryPlot
Definition: PayloadInspector.h:500
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cond
Definition: plugin.cc:23
Time.h
cond::payloadInspector::PlotImage::fetchPayload
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
Definition: PayloadInspector.h:840
cond::payloadInspector::RunHistoryPlot
Definition: PayloadInspector.h:524
DOFs::Z
Definition: AlignPCLThresholdsWriter.cc:37
cond::payloadInspector::TimeHistoryPlot
Definition: PayloadInspector.h:598
BeamSpotObjects
Definition: BeamSpotObjects.h:20
cond::payloadInspector::RunHistoryPlot::getFromPayload
virtual Y getFromPayload(PayloadType &payload)=0
BeamSpotFakeParameters_cfi.dydz
dydz
Definition: BeamSpotFakeParameters_cfi.py:13
cond::payloadInspector::HistoryPlot::getFromPayload
virtual Y getFromPayload(PayloadType &payload)=0
fftjetvertexadder_cfi.sigmaX
sigmaX
Definition: fftjetvertexadder_cfi.py:30
std
Definition: JetResolutionObject.h:76
fftjetvertexadder_cfi.sigmaY
sigmaY
Definition: fftjetvertexadder_cfi.py:31
DOFs::Y
Definition: AlignPCLThresholdsWriter.cc:37
cond::payloadInspector::PlotImpl::fill
virtual bool fill()=0
cond::payloadInspector::PlotImage
Definition: PayloadInspector.h:829
HiBiasedCentrality_cfi.function
function
Definition: HiBiasedCentrality_cfi.py:4
fftjetvertexadder_cfi.sigmaZ
sigmaZ
Definition: fftjetvertexadder_cfi.py:32
RunInfoPI::getStringFromTypeEnum
std::string getStringFromTypeEnum(const parameters &parameter)
Definition: RunInfoPayloadInspectoHelper.h:49