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 
14  enum parameters {X,
15  Y,
16  Z,
17  sigmaX,
18  sigmaY,
19  sigmaZ,
20  dxdz,
21  dydz,
22  END_OF_TYPES};
23 
24  /************************************************/
25  std::string getStringFromParamEnum (const parameters &parameter){
26  switch(parameter){
27  case X : return "X";
28  case Y : return "Y";
29  case Z : return "Z";
30  case sigmaX : return "sigmaX";
31  case sigmaY : return "sigmaY";
32  case sigmaZ : return "sigmaZ";
33  case dxdz : return "dx/dz";
34  case dydz : return "dy/dz";
35  default: return "should never be here";
36  }
37  }
38 
39 
40  class BeamSpot_hx : public cond::payloadInspector::HistoryPlot<BeamSpotObjects,std::pair<double,double> > {
41  public:
43  }
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:
53  }
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:
62  }
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:
72  }
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> class BeamSpot_history : public cond::payloadInspector::HistoryPlot<BeamSpotObjects,std::pair<double,double> > {
84  public:
85  BeamSpot_history (): cond::payloadInspector::HistoryPlot<BeamSpotObjects,std::pair<double,double> >(getStringFromParamEnum(my_param)+" vs run number",getStringFromParamEnum(my_param)){
86  }
87 
88  std::pair<double,double> getFromPayload( BeamSpotObjects& payload ) override{
89 
90  auto ret = std::make_pair<double,double>(-9999.,-9999.);
91 
92  switch(my_param){
93  case X : return std::make_pair<double,double>(payload.GetX(), payload.GetXError());
94  case Y : return std::make_pair<double,double>(payload.GetY(), payload.GetYError());
95  case Z : return std::make_pair<double,double>(payload.GetZ(), payload.GetZError());
96  case sigmaX : return std::make_pair<double,double>(payload.GetBeamWidthX(),payload.GetBeamWidthXError());
97  case sigmaY : return std::make_pair<double,double>(payload.GetBeamWidthY(),payload.GetBeamWidthYError());
98  case sigmaZ : return std::make_pair<double,double>(payload.GetSigmaZ(), payload.GetSigmaZError());
99  case dxdz : return std::make_pair<double,double>(payload.Getdxdz(), payload.GetdxdzError());
100  case dydz : return std::make_pair<double,double>(payload.Getdydz(), payload.GetdydzError());
101  case END_OF_TYPES : return ret;
102  default : return ret;
103  }
104  }
105  };
106 
107  typedef BeamSpot_history<X> BeamSpot_HistoryX;
108  typedef BeamSpot_history<Y> BeamSpot_HistoryY;
109  typedef BeamSpot_history<Z> BeamSpot_HistoryZ;
110  typedef BeamSpot_history<sigmaX> BeamSpot_HistorySigmaX;
111  typedef BeamSpot_history<sigmaY> BeamSpot_HistorySigmaY;
112  typedef BeamSpot_history<sigmaZ> BeamSpot_HistorySigmaZ;
113  typedef BeamSpot_history<dxdz> BeamSpot_HistorydXdZ;
114  typedef BeamSpot_history<dydz> BeamSpot_HistorydYdZ;
115 
116  /************************************************
117  template classes (run history)
118  *************************************************/
119 
120  template<parameters my_param> class BeamSpot_runhistory : public cond::payloadInspector::RunHistoryPlot<BeamSpotObjects,std::pair<double,double> > {
121  public:
122  BeamSpot_runhistory (): cond::payloadInspector::RunHistoryPlot<BeamSpotObjects,std::pair<double,double> >(getStringFromParamEnum(my_param)+" vs run number",getStringFromParamEnum(my_param)){
123  }
124 
125  std::pair<double,double> getFromPayload( BeamSpotObjects& payload ) override{
126 
127  auto ret = std::make_pair<double,double>(-9999.,-9999.);
128 
129  switch(my_param){
130  case X : return std::make_pair<double,double>(payload.GetX(), payload.GetXError());
131  case Y : return std::make_pair<double,double>(payload.GetY(), payload.GetYError());
132  case Z : return std::make_pair<double,double>(payload.GetZ(), payload.GetZError());
133  case sigmaX : return std::make_pair<double,double>(payload.GetBeamWidthX(),payload.GetBeamWidthXError());
134  case sigmaY : return std::make_pair<double,double>(payload.GetBeamWidthY(),payload.GetBeamWidthYError());
135  case sigmaZ : return std::make_pair<double,double>(payload.GetSigmaZ(), payload.GetSigmaZError());
136  case dxdz : return std::make_pair<double,double>(payload.Getdxdz(), payload.GetdxdzError());
137  case dydz : return std::make_pair<double,double>(payload.Getdydz(), payload.GetdydzError());
138  case END_OF_TYPES : return ret;
139  default : return ret;
140  }
141  }
142  };
143 
144  typedef BeamSpot_runhistory<X> BeamSpot_RunHistoryX;
145  typedef BeamSpot_runhistory<Y> BeamSpot_RunHistoryY;
146  typedef BeamSpot_runhistory<Z> BeamSpot_RunHistoryZ;
147  typedef BeamSpot_runhistory<sigmaX> BeamSpot_RunHistorySigmaX;
148  typedef BeamSpot_runhistory<sigmaY> BeamSpot_RunHistorySigmaY;
149  typedef BeamSpot_runhistory<sigmaZ> BeamSpot_RunHistorySigmaZ;
150  typedef BeamSpot_runhistory<dxdz> BeamSpot_RunHistorydXdZ;
151  typedef BeamSpot_runhistory<dydz> BeamSpot_RunHistorydYdZ;
152 
153  /************************************************
154  template classes (time history)
155  *************************************************/
156 
157  template<parameters my_param> class BeamSpot_timehistory : public cond::payloadInspector::TimeHistoryPlot<BeamSpotObjects,std::pair<double,double> > {
158  public:
159  BeamSpot_timehistory (): cond::payloadInspector::TimeHistoryPlot<BeamSpotObjects,std::pair<double,double> >(getStringFromParamEnum(my_param)+" vs time",getStringFromParamEnum(my_param)){
160  }
161 
162  std::pair<double,double> getFromPayload( BeamSpotObjects& payload ) override{
163 
164  auto ret = std::make_pair<double,double>(-9999.,-9999.);
165 
166  switch(my_param){
167  case X : return std::make_pair<double,double>(payload.GetX(), payload.GetXError());
168  case Y : return std::make_pair<double,double>(payload.GetY(), payload.GetYError());
169  case Z : return std::make_pair<double,double>(payload.GetZ(), payload.GetZError());
170  case sigmaX : return std::make_pair<double,double>(payload.GetBeamWidthX(),payload.GetBeamWidthXError());
171  case sigmaY : return std::make_pair<double,double>(payload.GetBeamWidthY(),payload.GetBeamWidthYError());
172  case sigmaZ : return std::make_pair<double,double>(payload.GetSigmaZ(), payload.GetSigmaZError());
173  case dxdz : return std::make_pair<double,double>(payload.Getdxdz(), payload.GetdxdzError());
174  case dydz : return std::make_pair<double,double>(payload.Getdydz(), payload.GetdydzError());
175  case END_OF_TYPES : return ret;
176  default : return ret;
177  }
178  }
179  };
180 
181  typedef BeamSpot_timehistory<X> BeamSpot_TimeHistoryX;
182  typedef BeamSpot_timehistory<Y> BeamSpot_TimeHistoryY;
183  typedef BeamSpot_timehistory<Z> BeamSpot_TimeHistoryZ;
184  typedef BeamSpot_timehistory<sigmaX> BeamSpot_TimeHistorySigmaX;
185  typedef BeamSpot_timehistory<sigmaY> BeamSpot_TimeHistorySigmaY;
186  typedef BeamSpot_timehistory<sigmaZ> BeamSpot_TimeHistorySigmaZ;
187  typedef BeamSpot_timehistory<dxdz> BeamSpot_TimeHistorydXdZ;
188  typedef BeamSpot_timehistory<dydz> BeamSpot_TimeHistorydYdZ;
189 
190 
191  /************************************************
192  X-Y correlation plot
193  *************************************************/
194  class BeamSpot_xy : public cond::payloadInspector::ScatterPlot<BeamSpotObjects,double,double>{
195  public:
196  BeamSpot_xy(): cond::payloadInspector::ScatterPlot<BeamSpotObjects,double,double>("BeamSpot x vs y","x","y" ){
197  }
198 
199  std::tuple<double,double> getFromPayload( BeamSpotObjects& payload ) override{
200  return std::make_tuple( payload.GetX(), payload.GetY() );
201  }
202  };
203 
204  /************************************************
205  Display of Beam Spot parameters
206  *************************************************/
207  class BeamSpotParameters : public cond::payloadInspector::PlotImage<BeamSpotObjects> {
208  public:
209  BeamSpotParameters() : cond::payloadInspector::PlotImage<BeamSpotObjects>( "Display of BeamSpot parameters" ){
210  setSingleIov( true );
211  }
212 
213  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
214  auto iov = iovs.front();
215  std::shared_ptr<BeamSpotObjects> payload = fetchPayload( std::get<1>(iov) );
216 
217  TCanvas canvas("Beam Spot Parameters Summary","BeamSpot Parameters summary",1000,1000);
218  canvas.cd();
219 
220  canvas.SetTopMargin(0.07);
221  canvas.SetBottomMargin(0.06);
222  canvas.SetLeftMargin(0.15);
223  canvas.SetRightMargin(0.03);
224  canvas.Modified();
225  canvas.SetGrid();
226 
227  auto h2_BSParameters = std::unique_ptr<TH2F>(new TH2F("Parameters","BeamSpot parameters summary",2,0.0,2.0,8,0,8.));
228  h2_BSParameters->SetStats(false);
229 
230  std::function<double(parameters,bool)> cutFunctor = [&payload](parameters my_param,bool isError) {
231  double ret(-999.);
232  if(!isError){
233  switch(my_param){
234  case X : return payload->GetX();
235  case Y : return payload->GetY();
236  case Z : return payload->GetZ();
237  case sigmaX : return payload->GetBeamWidthX();
238  case sigmaY : return payload->GetBeamWidthY();
239  case sigmaZ : return payload->GetSigmaZ();
240  case dxdz : return payload->Getdxdz();
241  case dydz : return payload->Getdydz();
242  case END_OF_TYPES : return ret;
243  default : return ret;
244  }
245  } else {
246  switch(my_param){
247  case X : return payload->GetXError();
248  case Y : return payload->GetYError();
249  case Z : return payload->GetZError();
250  case sigmaX : return payload->GetBeamWidthXError();
251  case sigmaY : return payload->GetBeamWidthYError();
252  case sigmaZ : return payload->GetSigmaZError();
253  case dxdz : return payload->GetdxdzError();
254  case dydz : return payload->GetdydzError();
255  case END_OF_TYPES : return ret;
256  default : return ret;
257  }
258  }
259  };
260 
261  h2_BSParameters->GetXaxis()->SetBinLabel(1,"Value");
262  h2_BSParameters->GetXaxis()->SetBinLabel(2,"Error");
263 
264  unsigned int yBin=8;
265  for(int foo = parameters::X; foo != parameters::END_OF_TYPES; foo++ ){
266  parameters param = static_cast<parameters>(foo);
267  std::string theLabel = getStringFromTypeEnum(param);
268  h2_BSParameters->GetYaxis()->SetBinLabel(yBin,theLabel.c_str());
269  h2_BSParameters->SetBinContent(1,yBin,cutFunctor(param,false));
270  h2_BSParameters->SetBinContent(2,yBin,cutFunctor(param,true));
271  yBin--;
272  }
273 
274  h2_BSParameters->GetXaxis()->LabelsOption("h");
275 
276  h2_BSParameters->GetYaxis()->SetLabelSize(0.05);
277  h2_BSParameters->GetXaxis()->SetLabelSize(0.05);
278 
279  h2_BSParameters->SetMarkerSize(1.5);
280  h2_BSParameters->Draw("TEXT");
281 
282  std::string fileName(m_imageFileName);
283  canvas.SaveAs(fileName.c_str());
284 
285  return true;
286  }
287 
288  /************************************************/
289  std::string getStringFromTypeEnum (const parameters &parameter){
290  switch(parameter){
291  case X : return "X [cm]";
292  case Y : return "Y [cm]";
293  case Z : return "Z [cm]";
294  case sigmaX : return "#sigma_{X} [cm]";
295  case sigmaY : return "#sigma_{Y} [cm]";
296  case sigmaZ : return "#sigma_{Z} [cm]";
297  case dxdz : return "#frac{dX}{dZ} [rad]";
298  case dydz : return "#frac{dY}{dZ} [rad]";
299  default: return "should never be here";
300  }
301  }
302  };
303 
304 } // close namespace
305 
307  PAYLOAD_INSPECTOR_CLASS( BeamSpot_hx );
308  PAYLOAD_INSPECTOR_CLASS( BeamSpot_rhx );
309  PAYLOAD_INSPECTOR_CLASS( BeamSpot_x );
310  PAYLOAD_INSPECTOR_CLASS( BeamSpot_y );
311  PAYLOAD_INSPECTOR_CLASS( BeamSpot_xy );
312  PAYLOAD_INSPECTOR_CLASS( BeamSpotParameters );
313  PAYLOAD_INSPECTOR_CLASS( BeamSpot_HistoryX );
314  PAYLOAD_INSPECTOR_CLASS( BeamSpot_HistoryY );
315  PAYLOAD_INSPECTOR_CLASS( BeamSpot_HistoryZ );
316  PAYLOAD_INSPECTOR_CLASS( BeamSpot_HistorySigmaX );
317  PAYLOAD_INSPECTOR_CLASS( BeamSpot_HistorySigmaY );
318  PAYLOAD_INSPECTOR_CLASS( BeamSpot_HistorySigmaZ );
319  PAYLOAD_INSPECTOR_CLASS( BeamSpot_HistorydXdZ );
320  PAYLOAD_INSPECTOR_CLASS( BeamSpot_HistorydYdZ );
321  PAYLOAD_INSPECTOR_CLASS( BeamSpot_RunHistoryX );
322  PAYLOAD_INSPECTOR_CLASS( BeamSpot_RunHistoryY );
323  PAYLOAD_INSPECTOR_CLASS( BeamSpot_RunHistoryZ );
324  PAYLOAD_INSPECTOR_CLASS( BeamSpot_RunHistorySigmaX );
325  PAYLOAD_INSPECTOR_CLASS( BeamSpot_RunHistorySigmaY );
326  PAYLOAD_INSPECTOR_CLASS( BeamSpot_RunHistorySigmaZ );
327  PAYLOAD_INSPECTOR_CLASS( BeamSpot_RunHistorydXdZ );
328  PAYLOAD_INSPECTOR_CLASS( BeamSpot_RunHistorydYdZ );
329  PAYLOAD_INSPECTOR_CLASS( BeamSpot_TimeHistoryX );
330  PAYLOAD_INSPECTOR_CLASS( BeamSpot_TimeHistoryY );
331  PAYLOAD_INSPECTOR_CLASS( BeamSpot_TimeHistoryZ );
332  PAYLOAD_INSPECTOR_CLASS( BeamSpot_TimeHistorySigmaX );
333  PAYLOAD_INSPECTOR_CLASS( BeamSpot_TimeHistorySigmaY );
334  PAYLOAD_INSPECTOR_CLASS( BeamSpot_TimeHistorySigmaZ );
335  PAYLOAD_INSPECTOR_CLASS( BeamSpot_TimeHistorydXdZ );
336  PAYLOAD_INSPECTOR_CLASS( BeamSpot_TimeHistorydYdZ );
337 }
double Getdydz() const
get dydz slope, crossing angle in YZ
double GetY() const
get Y beam position
double GetSigmaZ() const
get sigma Z, RMS bunch length
#define X(str)
Definition: MuonsGrabber.cc:48
double GetBeamWidthX() const
get average transverse beam width
double GetYError() const
get Y beam position Error
double GetBeamWidthYError() const
get average transverse beam width error X = Y
double GetBeamWidthY() const
get average transverse beam width
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
double GetdydzError() const
get dydz slope, crossing angle in YZ Error
double GetZ() const
get Z beam position
std::string getStringFromTypeEnum(const parameters &parameter)
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
double Getdxdz() const
get dxdz slope, crossing angle in XZ
double GetdxdzError() const
get dxdz slope, crossing angle in XZ Error
double GetBeamWidthXError() const
get average transverse beam width error ASSUME the same for X and Y
virtual Y getFromPayload(PayloadType &payload)=0
double GetSigmaZError() const
get sigma Z, RMS bunch length Error
double GetX() const
get X beam position
double GetXError() const
get X beam position Error
def canvas(sub, attr)
Definition: svgfig.py:482
double GetZError() const
get Z beam position Error
yBin
Definition: cuy.py:893