CMS 3D CMS Logo

AlignPCLThresholds_PayloadInspector.cc
Go to the documentation of this file.
1 
12 
13 // the data format of the condition to be inspected
15 
16 #include <memory>
17 #include <sstream>
18 #include <iostream>
19 #include <functional>
20 
21 // include ROOT
22 #include "TH2F.h"
23 #include "TLegend.h"
24 #include "TCanvas.h"
25 #include "TLine.h"
26 #include "TStyle.h"
27 
28 namespace {
29 
30  enum types {DELTA,
31  SIG,
32  MAXMOVE,
33  MAXERR,
34  END_OF_TYPES};
35 
36  /************************************************
37  Display of AlignPCLThresholds
38  *************************************************/
39  class AlignPCLThresholds_Display : public cond::payloadInspector::PlotImage<AlignPCLThresholds> {
40  public:
41  AlignPCLThresholds_Display() : cond::payloadInspector::PlotImage<AlignPCLThresholds>( "Display of threshold parameters for SiPixelAli PCL" ){
42  setSingleIov( true );
43  }
44 
45  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
46  auto iov = iovs.front();
47  std::shared_ptr<AlignPCLThresholds> payload = fetchPayload( std::get<1>(iov) );
48  auto alignables = payload->getAlignableList();
49 
50  TCanvas canvas("Alignment PCL thresholds summary","Alignment PCL thresholds summary",1500,800);
51  canvas.cd();
52 
53  canvas.SetTopMargin(0.07);
54  canvas.SetBottomMargin(0.06);
55  canvas.SetLeftMargin(0.11);
56  canvas.SetRightMargin(0.05);
57  canvas.Modified();
58  canvas.SetGrid();
59 
60  auto Thresholds = std::unique_ptr<TH2F>(new TH2F("Thresholds","Alignment parameter thresholds",alignables.size(),0,alignables.size(),24,0,24));
61  Thresholds->SetStats(false);
62 
63  std::function<float(types,std::string,AlignPCLThresholds::coordType)> cutFunctor = [&payload](types my_type,std::string alignable,AlignPCLThresholds::coordType coord) {
64  float ret(-999.);
65  switch(my_type){
66  case DELTA : return payload->getCut(alignable,coord);
67  case SIG : return payload->getSigCut(alignable,coord);
68  case MAXMOVE : return payload->getMaxMoveCut(alignable,coord);
69  case MAXERR : return payload->getMaxErrorCut(alignable,coord);
70  case END_OF_TYPES : return ret;
71  default : return ret;
72  }
73  };
74 
75  unsigned int xBin=0;
76  for(const auto &alignable : alignables){
77  xBin++;
78 
79  auto xLabel = replaceAll(replaceAll(alignable,"minus","(-)"),"plus","(+)");
80  Thresholds->GetXaxis()->SetBinLabel(xBin,(xLabel).c_str());
81  unsigned int yBin=24;
82  for(int foo = AlignPCLThresholds::X; foo != AlignPCLThresholds::extra_DOF; foo++ ){
84  for(int bar = types::DELTA; bar != types::END_OF_TYPES; bar++ ){
85  types type = static_cast<types>(bar);
86  std::string theLabel = getStringFromTypeEnum(type)+getStringFromCoordEnum(coord);
87  if(xBin==1){
88  Thresholds->GetYaxis()->SetBinLabel(yBin,theLabel.c_str());
89  }
90 
91  Thresholds->SetBinContent(xBin,yBin,cutFunctor(type,alignable,coord));
92 
93  yBin--;
94  }// loop on types
95  }// loop on coordinates
96  } // loop on alignables
97 
98 
99  Thresholds->GetXaxis()->LabelsOption("h");
100  Thresholds->Draw("TEXT");
101 
102  std::string fileName(m_imageFileName);
103  canvas.SaveAs(fileName.c_str());
104 
105  return true;
106  }
107 
108  /************************************************/
109  std::string getStringFromCoordEnum (const AlignPCLThresholds::coordType &coord){
110  switch(coord){
111  case AlignPCLThresholds::X : return "X";
112  case AlignPCLThresholds::Y : return "Y";
113  case AlignPCLThresholds::Z : return "Z";
114  case AlignPCLThresholds::theta_X : return "#theta_{X}";
115  case AlignPCLThresholds::theta_Y : return "#theta_{Y}";
116  case AlignPCLThresholds::theta_Z : return "#theta_{Z}";
117  default : return "should never be here";
118  }
119  }
120 
121  /************************************************/
123  switch(type){
124  case types::DELTA : return "#Delta";
125  case types::SIG : return "#Delta/#sigma ";
126  case types::MAXMOVE : return "max. move ";
127  case types::MAXERR : return "max. err ";
128  default: return "should never be here";
129  }
130  }
131 
132  /************************************************/
133  std::string replaceAll(const std::string& str, const std::string& from, const std::string& to) {
134  std::string out(str);
135 
136  if(from.empty())
137  return out;
138  size_t start_pos = 0;
139  while((start_pos = out.find(from, start_pos)) != std::string::npos) {
140  out.replace(start_pos, from.length(), to);
141  start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx'
142  }
143  return out;
144  }
145 
146  };
147 } // close namespace
148 
149 // Register the classes as boost python plugin
151  PAYLOAD_INSPECTOR_CLASS(AlignPCLThresholds_Display);
152 }
type
Definition: HCALResponse.h:21
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
virtual bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs)=0
std::string getStringFromTypeEnum(const parameters &parameter)
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
double const DELTA
Definition: Constants.h:21
def canvas(sub, attr)
Definition: svgfig.py:481
#define str(s)
yBin
Definition: cuy.py:893