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  class BeamSpot_hx : public cond::payloadInspector::HistoryPlot<BeamSpotObjects,std::pair<double,double> > {
25  public:
27  }
28 
29  std::pair<double,double> getFromPayload( BeamSpotObjects& payload ) override{
30  return std::make_pair(payload.GetX(),payload.GetXError());
31  }
32  };
33 
34  class BeamSpot_rhx : public cond::payloadInspector::RunHistoryPlot<BeamSpotObjects,std::pair<double,double> > {
35  public:
37  }
38 
39  std::pair<double,double> getFromPayload( BeamSpotObjects& payload ) override{
40  return std::make_pair(payload.GetX(),payload.GetXError());
41  }
42  };
43  class BeamSpot_x : public cond::payloadInspector::TimeHistoryPlot<BeamSpotObjects,std::pair<double,double> > {
44  public:
46  }
47 
48  std::pair<double,double> getFromPayload( BeamSpotObjects& payload ) override{
49  return std::make_pair(payload.GetX(),payload.GetXError());
50  }
51  };
52 
53  class BeamSpot_y : public cond::payloadInspector::TimeHistoryPlot<BeamSpotObjects,std::pair<double,double> >{
54  public:
56  }
57 
58  std::pair<double,double> getFromPayload( BeamSpotObjects& payload ) override{
59  return std::make_pair(payload.GetY(),payload.GetYError());
60  }
61  };
62 
63  class BeamSpot_xy : public cond::payloadInspector::ScatterPlot<BeamSpotObjects,double,double>{
64  public:
65  BeamSpot_xy(): cond::payloadInspector::ScatterPlot<BeamSpotObjects,double,double>("BeamSpot x vs y","x","y" ){
66  }
67 
68  std::tuple<double,double> getFromPayload( BeamSpotObjects& payload ) override{
69  return std::make_tuple( payload.GetX(), payload.GetY() );
70  }
71  };
72 
73  /************************************************
74  Display of Beam Spot parameters
75  *************************************************/
76  class BeamSpotParameters : public cond::payloadInspector::PlotImage<BeamSpotObjects> {
77  public:
78  BeamSpotParameters() : cond::payloadInspector::PlotImage<BeamSpotObjects>( "Display of BeamSpot parameters" ){
79  setSingleIov( true );
80  }
81 
82  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
83  auto iov = iovs.front();
84  std::shared_ptr<BeamSpotObjects> payload = fetchPayload( std::get<1>(iov) );
85 
86  TCanvas canvas("Beam Spot Parameters Summary","BeamSpot Parameters summary",1000,1000);
87  canvas.cd();
88 
89  canvas.SetTopMargin(0.07);
90  canvas.SetBottomMargin(0.06);
91  canvas.SetLeftMargin(0.15);
92  canvas.SetRightMargin(0.03);
93  canvas.Modified();
94  canvas.SetGrid();
95 
96  auto h2_BSParameters = std::unique_ptr<TH2F>(new TH2F("Parameters","BeamSpot parameters summary",2,0.0,2.0,8,0,8.));
97  h2_BSParameters->SetStats(false);
98 
99  std::function<double(parameters,bool)> cutFunctor = [&payload](parameters my_param,bool isError) {
100  double ret(-999.);
101  if(!isError){
102  switch(my_param){
103  case X : return payload->GetX();
104  case Y : return payload->GetY();
105  case Z : return payload->GetZ();
106  case sigmaX : return payload->GetBeamWidthX();
107  case sigmaY : return payload->GetBeamWidthY();
108  case sigmaZ : return payload->GetSigmaZ();
109  case dxdz : return payload->Getdxdz();
110  case dydz : return payload->Getdydz();
111  case END_OF_TYPES : return ret;
112  default : return ret;
113  }
114  } else {
115  switch(my_param){
116  case X : return payload->GetXError();
117  case Y : return payload->GetYError();
118  case Z : return payload->GetZError();
119  case sigmaX : return payload->GetBeamWidthXError();
120  case sigmaY : return payload->GetBeamWidthYError();
121  case sigmaZ : return payload->GetSigmaZError();
122  case dxdz : return payload->GetdxdzError();
123  case dydz : return payload->GetdydzError();
124  case END_OF_TYPES : return ret;
125  default : return ret;
126  }
127  }
128  };
129 
130  h2_BSParameters->GetXaxis()->SetBinLabel(1,"Value");
131  h2_BSParameters->GetXaxis()->SetBinLabel(2,"Error");
132 
133  unsigned int yBin=8;
134  for(int foo = parameters::X; foo != parameters::END_OF_TYPES; foo++ ){
135  parameters param = static_cast<parameters>(foo);
136  std::string theLabel = getStringFromTypeEnum(param);
137  h2_BSParameters->GetYaxis()->SetBinLabel(yBin,theLabel.c_str());
138  h2_BSParameters->SetBinContent(1,yBin,cutFunctor(param,false));
139  h2_BSParameters->SetBinContent(2,yBin,cutFunctor(param,true));
140  yBin--;
141  }
142 
143  h2_BSParameters->GetXaxis()->LabelsOption("h");
144 
145  h2_BSParameters->GetYaxis()->SetLabelSize(0.05);
146  h2_BSParameters->GetXaxis()->SetLabelSize(0.05);
147 
148  h2_BSParameters->SetMarkerSize(1.5);
149  h2_BSParameters->Draw("TEXT");
150 
151  std::string fileName(m_imageFileName);
152  canvas.SaveAs(fileName.c_str());
153 
154  return true;
155  }
156 
157  /************************************************/
159  switch(parameter){
160  case X : return "X [cm]";
161  case Y : return "Y [cm]";
162  case Z : return "Z [cm]";
163  case sigmaX : return "#sigma_{X} [cm]";
164  case sigmaY : return "#sigma_{Y} [cm]";
165  case sigmaZ : return "#sigma_{Z} [cm]";
166  case dxdz : return "#frac{dX}{dZ} [rad]";
167  case dydz : return "#frac{dY}{dZ} [rad]";
168  default: return "should never be here";
169  }
170  }
171  };
172 
173 } // close namespace
174 
176  PAYLOAD_INSPECTOR_CLASS( BeamSpot_hx );
177  PAYLOAD_INSPECTOR_CLASS( BeamSpot_rhx );
178  PAYLOAD_INSPECTOR_CLASS( BeamSpot_x );
179  PAYLOAD_INSPECTOR_CLASS( BeamSpot_y );
180  PAYLOAD_INSPECTOR_CLASS( BeamSpot_xy );
181  PAYLOAD_INSPECTOR_CLASS( BeamSpotParameters );
182 }
double GetY() const
get Y beam position
#define X(str)
Definition: MuonsGrabber.cc:48
double GetYError() const
get Y beam position Error
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
std::string getStringFromTypeEnum(const parameters &parameter)
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
virtual Y getFromPayload(PayloadType &payload)=0
double GetX() const
get X beam position
double GetXError() const
get X beam position Error
def canvas(sub, attr)
Definition: svgfig.py:481
yBin
Definition: cuy.py:892