CMS 3D CMS Logo

BeamSpotOnline_PayloadInspector.cc
Go to the documentation of this file.
6 
7 #include <TStyle.h>
8 
9 namespace {
10 
11  using namespace beamSpotPI;
12 
13  /************************************************
14  history plots
15  *************************************************/
16  typedef BeamSpot_history<X, BeamSpotOnlineObjects> BeamSpotOnline_HistoryX;
17  typedef BeamSpot_history<Y, BeamSpotOnlineObjects> BeamSpotOnline_HistoryY;
18  typedef BeamSpot_history<Z, BeamSpotOnlineObjects> BeamSpotOnline_HistoryZ;
19  typedef BeamSpot_history<sigmaX, BeamSpotOnlineObjects> BeamSpotOnline_HistorySigmaX;
20  typedef BeamSpot_history<sigmaY, BeamSpotOnlineObjects> BeamSpotOnline_HistorySigmaY;
21  typedef BeamSpot_history<sigmaZ, BeamSpotOnlineObjects> BeamSpotOnline_HistorySigmaZ;
22  typedef BeamSpot_history<dxdz, BeamSpotOnlineObjects> BeamSpotOnline_HistorydXdZ;
23  typedef BeamSpot_history<dydz, BeamSpotOnlineObjects> BeamSpotOnline_HistorydYdZ;
24 
25  /************************************************
26  run history plots
27  *************************************************/
28 
29  typedef BeamSpot_runhistory<X, BeamSpotOnlineObjects> BeamSpotOnline_RunHistoryX;
30  typedef BeamSpot_runhistory<Y, BeamSpotOnlineObjects> BeamSpotOnline_RunHistoryY;
31  typedef BeamSpot_runhistory<Z, BeamSpotOnlineObjects> BeamSpotOnline_RunHistoryZ;
32  typedef BeamSpot_runhistory<sigmaX, BeamSpotOnlineObjects> BeamSpotOnline_RunHistorySigmaX;
33  typedef BeamSpot_runhistory<sigmaY, BeamSpotOnlineObjects> BeamSpotOnline_RunHistorySigmaY;
34  typedef BeamSpot_runhistory<sigmaZ, BeamSpotOnlineObjects> BeamSpotOnline_RunHistorySigmaZ;
35  typedef BeamSpot_runhistory<dxdz, BeamSpotOnlineObjects> BeamSpotOnline_RunHistorydXdZ;
36  typedef BeamSpot_runhistory<dydz, BeamSpotOnlineObjects> BeamSpotOnline_RunHistorydYdZ;
37 
38  /************************************************
39  time history plots
40  *************************************************/
41 
42  typedef BeamSpot_timehistory<X, BeamSpotOnlineObjects> BeamSpotOnline_TimeHistoryX;
43  typedef BeamSpot_timehistory<Y, BeamSpotOnlineObjects> BeamSpotOnline_TimeHistoryY;
44  typedef BeamSpot_timehistory<Z, BeamSpotOnlineObjects> BeamSpotOnline_TimeHistoryZ;
45  typedef BeamSpot_timehistory<sigmaX, BeamSpotOnlineObjects> BeamSpotOnline_TimeHistorySigmaX;
46  typedef BeamSpot_timehistory<sigmaY, BeamSpotOnlineObjects> BeamSpotOnline_TimeHistorySigmaY;
47  typedef BeamSpot_timehistory<sigmaZ, BeamSpotOnlineObjects> BeamSpotOnline_TimeHistorySigmaZ;
48  typedef BeamSpot_timehistory<dxdz, BeamSpotOnlineObjects> BeamSpotOnline_TimeHistorydXdZ;
49  typedef BeamSpot_timehistory<dydz, BeamSpotOnlineObjects> BeamSpotOnline_TimeHistorydYdZ;
50 
51  /************************************************
52  X-Y correlation plot
53  *************************************************/
54 
55  typedef xyCorrelation<BeamSpotOnlineObjects> BeamSpotOnline_xy;
56 
57  /************************************************
58  Display of Beam Spot parameters
59  *************************************************/
60 
61  class BeamSpotOnlineParameters : public DisplayParameters<BeamSpotOnlineObjects> {
62  public:
63  std::shared_ptr<TH2F> fillTheExtraHistogram() const override {
64  gStyle->SetHistMinimumZero();
65 
66  const auto span = parameters::startTime - parameters::lastLumi;
67  edm::LogInfo("BeamSpotOnlineParameters") << "the span is" << span;
68 
69  auto h2_ExtraBSParameters =
70  std::make_shared<TH2F>("ExtraParameters", "", 1, 0.0, 1.0, span, 0, static_cast<float>(span));
71  h2_ExtraBSParameters->SetStats(false);
72 
73  //_____________________________________________________________________________
74  std::function<int(parameters)> myIntFunctor = [this](parameters my_param) {
75  int ret(-999);
76  switch (my_param) {
77  case lastLumi:
78  return this->m_payload->lastAnalyzedLumi();
79  case lastRun:
80  return this->m_payload->lastAnalyzedRun();
81  case lastFill:
82  return this->m_payload->lastAnalyzedFill();
83  case nTracks:
84  return this->m_payload->numTracks();
85  case nPVs:
86  return this->m_payload->numPVs();
87  case nUsedEvents:
88  return this->m_payload->usedEvents();
89  case maxPVs:
90  return this->m_payload->maxPVs();
91  default:
92  return ret;
93  }
94  };
95 
96  //_____________________________________________________________________________
97  std::function<float(parameters)> myFloatFunctor = [this](parameters my_param) {
98  float ret(-999.);
99  switch (my_param) {
100  case meanPV:
101  return this->m_payload->meanPV();
102  case meanErrorPV:
103  return this->m_payload->meanErrorPV();
104  case rmsPV:
105  return this->m_payload->rmsPV();
106  case rmsErrorPV:
107  return this->m_payload->rmsErrorPV();
108  default:
109  return ret;
110  }
111  };
112 
113  //_____________________________________________________________________________
114  std::function<std::string(parameters)> myStringFunctor = [this](parameters my_param) {
115  std::string ret("");
116  switch (my_param) {
117  case startTime:
118  return this->m_payload->startTime();
119  case endTime:
120  return this->m_payload->endTime();
121  case lumiRange:
122  return this->m_payload->lumiRange();
123  default:
124  return ret;
125  }
126  };
127 
128  //_____________________________________________________________________________
129  std::function<cond::Time_t(parameters)> myTimeFunctor = [this](parameters my_param) {
130  cond::Time_t ret(1);
131  switch (my_param) {
132  case creationTime:
133  return this->m_payload->creationTime();
134  case startTimeStamp:
135  return this->m_payload->startTimeStamp();
136  case endTimeStamp:
137  return this->m_payload->endTimeStamp();
138  default:
139  return ret;
140  }
141  };
142 
143  unsigned int yBin = span;
145  parameters param = static_cast<parameters>(foo);
146  std::string theLabel = this->getStringFromTypeEnum(param);
147  h2_ExtraBSParameters->GetYaxis()->SetBinLabel(yBin, theLabel.c_str());
148 
149  if (foo <= parameters::maxPVs) {
150  const auto output = try_<int, std::out_of_range>(std::bind(myIntFunctor, param), print_error);
151  edm::LogInfo("BeamSpotOnline_PayloadInspector") << theLabel.c_str() << " : " << output << std::endl;
152  h2_ExtraBSParameters->SetBinContent(1, yBin, output);
153  } else if (foo <= parameters::rmsErrorPV) {
154  const auto output = try_<float, std::out_of_range>(std::bind(myFloatFunctor, param), print_error);
155  edm::LogInfo("BeamSpotOnline_PayloadInspector") << theLabel.c_str() << " : " << output << std::endl;
156  h2_ExtraBSParameters->SetBinContent(1, yBin, output);
157  } else if (foo <= parameters::endTimeStamp) {
158  const auto output = try_<cond::Time_t, std::out_of_range>(std::bind(myTimeFunctor, param), print_error);
159  edm::LogInfo("BeamSpotOnline_PayloadInspector") << theLabel.c_str() << " : " << output << std::endl;
160  h2_ExtraBSParameters->SetBinContent(1, yBin, output);
161  //} else if( foo <=parameters::lumiRange){
162  // const auto output = try_<std::string,std::out_of_range>(std::bind(myStringFunctor, param), print_error);
163  //edm::LogInfo("BeamSpotOnline_PayloadInspector") << theLabel.c_str() << " : " << output << std::endl;
164  //h2_ExtraBSParameters->SetBinContent(1, yBin, output);
165  }
166  yBin--;
167  }
168 
169  h2_ExtraBSParameters->GetYaxis()->SetLabelSize(0.05);
170  h2_ExtraBSParameters->GetXaxis()->SetLabelSize(0.05);
171  h2_ExtraBSParameters->GetXaxis()->SetBinLabel(1, "Value");
172  h2_ExtraBSParameters->SetMarkerSize(2.);
173 
174  return h2_ExtraBSParameters;
175  }
176 
177  protected:
178  /************************************************/
179  std::string getStringFromTypeEnum(const parameters& parameter) const override {
180  switch (parameter) {
181  case X:
182  return "X [cm]";
183  case Y:
184  return "Y [cm]";
185  case Z:
186  return "Z [cm]";
187  case sigmaX:
188  return "#sigma_{X} [cm]";
189  case sigmaY:
190  return "#sigma_{Y} [cm]";
191  case sigmaZ:
192  return "#sigma_{Z} [cm]";
193  case dxdz:
194  return "#frac{dX}{dZ} [rad]";
195  case dydz:
196  return "#frac{dY}{dZ} [rad]";
197  case lastLumi:
198  return "last LS";
199  case lastRun:
200  return "last Run";
201  case lastFill:
202  return "last Fill";
203  case nTracks:
204  return "# tracks";
205  case nPVs:
206  return "# PVs";
207  case nUsedEvents:
208  return "# events";
209  case maxPVs:
210  return "max PVs";
211  case meanPV:
212  return "#LT # PV #GT";
213  case meanErrorPV:
214  return "#LT # PV #GT error";
215  case rmsPV:
216  return "RMS(# PV)";
217  case rmsErrorPV:
218  return "RMS(# PV) error";
219  case creationTime:
220  return "creation time";
221  case startTimeStamp:
222  return "start timestamp";
223  case endTimeStamp:
224  return "end timestamp";
225  case startTime:
226  return "startTime";
227  case endTime:
228  return "endTime";
229  case lumiRange:
230  return "lumiRange";
231  default:
232  return "should never be here";
233  }
234  }
235 
236  //slightly better error handler
237  static void print_error(const std::exception& e) { edm::LogError("BeamSpotOnlineParameters") << e.what() << '\n'; }
238 
239  // method to catch exceptions
240  template <typename T, class Except, class Func, class Response>
241  T try_(Func f, Response r) const {
242  try {
243  LogDebug("BeamSpotOnlineParameters") << "I have tried" << std::endl;
244  return f();
245  } catch (Except& e) {
246  LogDebug("BeamSpotOnlineParameters") << "I have caught!" << std::endl;
247  r(e);
248  return static_cast<T>(-999);
249  }
250  }
251  };
252 
253  /************************************************
254  Display of Beam Spot parameters Differences
255  *************************************************/
256 
258  BeamSpotOnlineParametersDiffSingleTag;
260  BeamSpotOnlineParametersDiffTwoTags;
261 
262 } // namespace
263 
265  PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_xy);
266  PAYLOAD_INSPECTOR_CLASS(BeamSpotOnlineParameters);
267  PAYLOAD_INSPECTOR_CLASS(BeamSpotOnlineParametersDiffSingleTag);
268  PAYLOAD_INSPECTOR_CLASS(BeamSpotOnlineParametersDiffTwoTags);
269  PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_HistoryX);
270  PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_HistoryY);
271  PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_HistoryZ);
272  PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_HistorySigmaX);
273  PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_HistorySigmaY);
274  PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_HistorySigmaZ);
275  PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_HistorydXdZ);
276  PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_HistorydYdZ);
277  PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_RunHistoryX);
278  PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_RunHistoryY);
279  PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_RunHistoryZ);
280  PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_RunHistorySigmaX);
281  PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_RunHistorySigmaY);
282  PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_RunHistorySigmaZ);
283  PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_RunHistorydXdZ);
284  PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_RunHistorydYdZ);
285  PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_TimeHistoryX);
286  PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_TimeHistoryY);
287  PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_TimeHistoryZ);
288  PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_TimeHistorySigmaX);
289  PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_TimeHistorySigmaY);
290  PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_TimeHistorySigmaZ);
291  PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_TimeHistorydXdZ);
292  PAYLOAD_INSPECTOR_CLASS(BeamSpotOnline_TimeHistorydYdZ);
293 }
ret
prodAgent to be discontinued
const std::string getStringFromTypeEnum(const types &type)
Log< level::Error, false > LogError
std::function< std::string(BSparameters, BeamSpotOnlineObjects)> myStringFunctor
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
unsigned long long Time_t
Definition: Time.h:14
T try_(Func f, Response r)
double f[11][100]
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
Log< level::Info, false > LogInfo
time_t endTimeStamp
static void print_error(const std::exception &e)
Definition: output.py:1
long double T
#define LogDebug(id)