CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalDQMChannelStatusPyWrapper.cc
Go to the documentation of this file.
2 //#include "CondTools/Ecal/interface/EcalPedestalsXMLTranslator.h"
4 #include "TH2F.h"
5 #include "TCanvas.h"
6 #include "TStyle.h"
7 #include "TLine.h"
10 
13 
14 #include <string>
15 #include <sstream>
16 #include <algorithm>
17 #include <numeric>
18 #include <iterator>
19 #include <boost/ref.hpp>
20 #include <boost/bind.hpp>
21 #include <boost/function.hpp>
22 #include <boost/iterator/transform_iterator.hpp>
23 #include <fstream>
24 
26 namespace cond {
27 
28  namespace ecalcond {
29 
32 
34 
35  int bad(Items const & cont) {
36  return std::count_if(cont.begin(),cont.end(),
37  boost::bind(std::greater<int>(),
38  boost::bind(&value_type::getStatusCode,_1),0)
39  );
40  }
41 
42  void extractBarrel(EcalDQMChannelStatus const & cont, std::vector<int> const &, std::vector<float> & result) {
43  result.resize(1);
44  result[0] = bad(cont.barrelItems());
45  }
46 
47  void extractEndcap(EcalDQMChannelStatus const & cont, std::vector<int> const &, std::vector<float> & result) {
48  result.resize(1);
49  result[0] = bad(cont.endcapItems());
50  }
51  void extractAll(EcalDQMChannelStatus const & cont, std::vector<int> const &, std::vector<float> & result) {
52  result.resize(1);
53  result[0] = bad(cont.barrelItems())+bad(cont.endcapItems());
54  }
55 
56  void extractSuperModules(EcalDQMChannelStatus const & cont, std::vector<int> const & which, std::vector<float> & result) {
57  // bho...
58  }
59 
60  void extractSingleChannel(EcalDQMChannelStatus const & cont, std::vector<int> const & which, std::vector<float> & result) {
61  result.reserve(which.size());
62  for (unsigned int i=0; i<which.size();i++) {
63  result.push_back(cont[which[i]].getStatusCode());
64  }
65  }
66 
67  typedef boost::function<void(EcalDQMChannelStatus const & cont, std::vector<int> const & which, std::vector<float> & result)> CondExtractor;
68  } // namespace ecalcond
69 
70  template<>
72 
74  std::vector<int> m_which;
75 
76  ecalcond::How const & how() const { return m_how;}
77  std::vector<int> const & which() const { return m_which;}
78 
79  void set_how(ecalcond::How i) {m_how=i;}
80  void set_which(std::vector<int> & i) { m_which.swap(i);}
81  };
82 
83 
84  template<>
85  class ValueExtractor<EcalDQMChannelStatus>: public BaseValueExtractor<EcalDQMChannelStatus> {
86  public:
87 
89  static ecalcond::CondExtractor fun[3] = {
93  };
94  return fun[how];
95  }
96 
99  static What what() { return What();}
100 
103  : m_what(what)
104  {
105  // here one can make stuff really complicated...
106  }
107 
108  void compute(Class const & it){
109  std::vector<float> res;
110  extractor(m_what.how())(it,m_what.which(),res);
111  swap(res);
112  }
113 
114  private:
116  };
117 
118 
119  //template<>
120  //std::string PayLoadInspector<EcalDQMChannelStatus>::dump() const {
121  // std::stringstream ss;
122  // EcalCondHeader h;
123  // ss << EcalDQMChannelStatusXMLTranslator::dumpXML(h,object());
124  // return ss.str();
125  //}
126 
127  class EcalDQMChannelStatusHelper: public EcalPyWrapperHelper<EcalDQMStatusCode>{
128  public:
129  //change me
131  protected:
132 
133  //change me
135 
136  type_vValues getValues( const std::vector<EcalObject> & vItems)
137  {
138  //change me
139  //unsigned int totalValues = 2;
140 
141  type_vValues vValues(total_values);
142 
143  std::stringstream ss;
144 
145  std::string valueNames[] = {
146  "CH_ID_ERROR ",
147  "CH_GAIN_ZERO_ERROR ",
148  "CH_GAIN_SWITCH_ERROR ",
149  "TT_ID_ERROR ",
150  "TT_SIZE_ERROR ",
151  "PEDESTAL_LOW_GAIN_MEAN_ERROR ",
152  "PEDESTAL_MIDDLE_GAIN_MEAN_ERROR ",
153  "PEDESTAL_HIGH_GAIN_MEAN_ERROR ",
154  "PEDESTAL_LOW_GAIN_RMS_ERROR ",
155  "PEDESTAL_MIDDLE_GAIN_RMS_ERROR ",
156  "PEDESTAL_HIGH_GAIN_RMS_ERROR ",
157  "PEDESTAL_ONLINE_HIGH_GAIN_MEAN_ERROR ",
158  "PEDESTAL_ONLINE_HIGH_GAIN_RMS_ERROR ",
159  "TESTPULSE_LOW_GAIN_MEAN_ERROR ",
160  "TESTPULSE_MIDDLE_GAIN_MEAN_ERROR ",
161  "TESTPULSE_HIGH_GAIN_MEAN_ERROR ",
162  "TESTPULSE_LOW_GAIN_RMS_ERROR ",
163  "TESTPULSE_MIDDLE_GAIN_RMS_ERROR ",
164  "TESTPULSE_HIGH_GAIN_RMS_ERROR ",
165  "LASER_MEAN_ERROR ",
166  "LASER_RMS_ERROR ",
167  "LASER_TIMING_MEAN_ERROR ",
168  "LASER_TIMING_RMS_ERROR ",
169  "LED_MEAN_ERROR ",
170  "LED_RMS_ERROR ",
171  "LED_TIMING_MEAN_ERROR ",
172  "LED_TIMING_RMS_ERROR ",
173  "STATUS_FLAG_ERROR ",
174  "PHYSICS_BAD_CHANNEL_WARNING ",
175  "PHYSICS_BAD_CHANNEL_ERROR "
176  };
177  for (unsigned int i = 0; i < total_values; ++i){
178  ss.str(""); ss << "[" << i << "]" << valueNames[i];
179  vValues[i].first = ss.str();
180  vValues[i].second = .0;
181  }
182 
183  //get info:
184  unsigned int shift = 0, mask = 1;
185  unsigned int statusCode;
186  for(std::vector<EcalObject>::const_iterator iItems = vItems.begin(); iItems != vItems.end(); ++iItems){
187  //change us
188  statusCode = iItems->getStatusCode();
189  for (shift = 0; shift < total_values; ++shift){
190  mask = 1 << (shift);
191  //std::cout << "; statuscode: " << statusCode;
192  if (statusCode & mask){
193  vValues[shift].second += 1;
194  }
195  }
196  }
197  return vValues;
198  }
199  };
200 
201  template<>
203  std::stringstream ss;
205  ss << helper.printBarrelsEndcaps(object().barrelItems(), object().endcapItems());
206  return ss.str();
207  }
208 
209 
210  template<>
212  std::string const &,
213  std::vector<int> const&,
214  std::vector<float> const& ) const {
215  gStyle->SetPalette(1);
216  const int TOTAL_IMAGES = 1;
217  const int TOTAL_PADS = 3;
218 
219  const float IMG_SIZE = 1.5;
220  TCanvas canvas("CC map","CC map",800*IMG_SIZE, 200 * TOTAL_IMAGES*IMG_SIZE);//800, 1200
221 
222  float xmi[3] = {0.0 , 0.22, 0.78};
223  float xma[3] = {0.22, 0.78, 1.00};
224 
225 
226  TPad*** pad = new TPad**[TOTAL_IMAGES];
227  for (int gId = 0; gId < TOTAL_IMAGES; gId++) {
228  pad[gId] = new TPad*[TOTAL_PADS];
229  for (int obj = 0; obj < TOTAL_PADS; obj++) {
230  float yma = 1. - 0;//1.- (0.17 * gId);
231  float ymi = yma - 1;//0.15;
232  pad[gId][obj] = new TPad(Form("p_%i_%i", obj, gId),Form("p_%i_%i", obj, gId),
233  xmi[obj], ymi, xma[obj], yma);
234  pad[gId][obj]->Draw();
235  }
236  }
237 
238  const int kGains = 3;
239  const int gainValues[3] = {12, 6, 1};
240  const int kSides = 2;
241  const int kBarlRings = EBDetId::MAX_IETA;
242  const int kBarlWedges = EBDetId::MAX_IPHI;
243  const int kEndcWedgesX = EEDetId::IX_MAX;
244  const int kEndcWedgesY = EEDetId::IY_MAX;
245 
246  TH2F** barrel_m = new TH2F*[3];
247  TH2F** endc_p_m = new TH2F*[3];
248  TH2F** endc_m_m = new TH2F*[3];
249  std::string variableName = "DQMChannelStatus";
250  for (int gainId = 0; gainId < kGains; gainId++) {
251  barrel_m[gainId] = new TH2F(Form((variableName + " EBm%i").c_str(),gainId), Form((variableName + " EB").c_str(),gainValues[gainId]),360,0,360, 170, -85,85);
252  endc_p_m[gainId] = new TH2F(Form((variableName + " EE+m%i").c_str(),gainId), Form((variableName + " EE+").c_str(),gainValues[gainId]),100,1,101,100,1,101);
253  endc_m_m[gainId] = new TH2F(Form((variableName + " EE-m%i").c_str(),gainId), Form((variableName + " EE-").c_str(),gainValues[gainId]),100,1,101,100,1,101);
254  }
255 
256  for (int sign=0; sign < kSides; sign++) {
257  int thesign = sign==1 ? 1:-1;
258 
259  for (int ieta=0; ieta<kBarlRings; ieta++) {
260  for (int iphi=0; iphi<kBarlWedges; iphi++) {
261  EBDetId id((ieta+1)*thesign, iphi+1);
262  float y = -1 - ieta;
263  if(sign == 1) y = ieta;
264  barrel_m[0]->Fill(iphi, y, object()[id.rawId()].getStatusCode());
265  } // iphi
266  } // ieta
267 
268  for (int ix=0; ix<kEndcWedgesX; ix++) {
269  for (int iy=0; iy<kEndcWedgesY; iy++) {
270  if (! EEDetId::validDetId(ix+1,iy+1,thesign)) continue;
271  EEDetId id(ix+1,iy+1,thesign);
272  if (thesign==1) {
273  endc_p_m[0]->Fill(ix+1,iy+1,object()[id.rawId()].getStatusCode());
274  }
275  else{
276  endc_m_m[0]->Fill(ix+1,iy+1,object()[id.rawId()].getStatusCode());
277  }
278  } // iy
279  } // ix
280  } // side
281 
282  //canvas.cd(1);
283  TLine* l = new TLine(0., 0., 0., 0.);
284  l->SetLineWidth(1);
285  int ixSectorsEE[202] = {
286  62, 62, 61, 61, 60, 60, 59, 59, 58, 58, 56, 56, 46, 46, 44, 44, 43, 43, 42, 42,
287  41, 41, 40, 40, 41, 41, 42, 42, 43, 43, 44, 44, 46, 46, 56, 56, 58, 58, 59, 59,
288  60, 60, 61, 61, 62, 62, 0,101,101, 98, 98, 96, 96, 93, 93, 88, 88, 86, 86, 81,
289  81, 76, 76, 66, 66, 61, 61, 41, 41, 36, 36, 26, 26, 21, 21, 16, 16, 14, 14, 9,
290  9, 6, 6, 4, 4, 1, 1, 4, 4, 6, 6, 9, 9, 14, 14, 16, 16, 21, 21, 26,
291  26, 36, 36, 41, 41, 61, 61, 66, 66, 76, 76, 81, 81, 86, 86, 88, 88, 93, 93, 96,
292  96, 98, 98,101,101, 0, 62, 66, 66, 71, 71, 81, 81, 91, 91, 93, 0, 62, 66, 66,
293  91, 91, 98, 0, 58, 61, 61, 66, 66, 71, 71, 76, 76, 81, 81, 0, 51, 51, 0, 44,
294  41, 41, 36, 36, 31, 31, 26, 26, 21, 21, 0, 40, 36, 36, 11, 11, 4, 0, 40, 36,
295  36, 31, 31, 21, 21, 11, 11, 9, 0, 46, 46, 41, 41, 36, 36, 0, 56, 56, 61, 61, 66, 66};
296 
297  int iySectorsEE[202] = {
298  51, 56, 56, 58, 58, 59, 59, 60, 60, 61, 61, 62, 62, 61, 61, 60, 60, 59, 59, 58,
299  58, 56, 56, 46, 46, 44, 44, 43, 43, 42, 42, 41, 41, 40, 40, 41, 41, 42, 42, 43,
300  43, 44, 44, 46, 46, 51, 0, 51, 61, 61, 66, 66, 76, 76, 81, 81, 86, 86, 88, 88,
301  93, 93, 96, 96, 98, 98,101,101, 98, 98, 96, 96, 93, 93, 88, 88, 86, 86, 81, 81,
302  76, 76, 66, 66, 61, 61, 41, 41, 36, 36, 26, 26, 21, 21, 16, 16, 14, 14, 9, 9,
303  6, 6, 4, 4, 1, 1, 4, 4, 6, 6, 9, 9, 14, 14, 16, 16, 21, 21, 26, 26,
304  36, 36, 41, 41, 51, 0, 46, 46, 41, 41, 36, 36, 31, 31, 26, 26, 0, 51, 51, 56,
305  56, 61, 61, 0, 61, 61, 66, 66, 71, 71, 76, 76, 86, 86, 88, 0, 62,101, 0, 61,
306  61, 66, 66, 71, 71, 76, 76, 86, 86, 88, 0, 51, 51, 56, 56, 61, 61, 0, 46, 46,
307  41, 41, 36, 36, 31, 31, 26, 26, 0, 40, 31, 31, 16, 16, 6, 0, 40, 31, 31, 16, 16, 6};
308 
309  for (int gId = 0; gId < TOTAL_IMAGES; gId++) {//was 3
310  pad[gId][0]->cd();
311  endc_m_m[gId]->SetStats(0);
312  //endc_m_m[gId]->SetMaximum(225);
313  //endc_m_m[gId]->SetMinimum(175);
314  endc_m_m[gId]->Draw("colz");
315  for ( int i=0; i<201; i=i+1) {
316  if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
317  (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
318  l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
319  ixSectorsEE[i+1], iySectorsEE[i+1]);
320  l->SetLineWidth(0.2);
321  }
322  }
323 
324  //canvas.cd(2);
325  pad[gId][1]->cd();
326  barrel_m[gId]->SetStats(0);
327  //barrel_m[gId]->SetMaximum(225);
328  //barrel_m[gId]->SetMinimum(175);
329  barrel_m[gId]->Draw("colz");
330  for(int i = 0; i <17; i++) {
331  Double_t x = 20.+ (i *20);
332  l = new TLine(x,-85.,x,86.);
333  l->Draw();
334  }
335  l = new TLine(0.,0.,360.,0.);
336  l->Draw();
337 
338  //canvas.cd(3);
339  pad[gId][2]->cd();
340  endc_p_m[gId]->SetStats(0);
341  //endc_p_m[gId]->SetMaximum(225);
342  //endc_p_m[gId]->SetMinimum(175);
343  endc_p_m[gId]->Draw("colz");
344  for ( int i=0; i<201; i=i+1) {
345  if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
346  (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
347  l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
348  ixSectorsEE[i+1], iySectorsEE[i+1]);
349  }
350  }
351  }
352 
353  canvas.SaveAs(filename.c_str());
354  return filename;
355  } // plot
356 
357 
358 }
359 
360 
361 namespace condPython {
362  template<>
364  enum_<cond::ecalcond::How>("How")
365  .value("singleChannel",cond::ecalcond::singleChannel)
366  .value("bySuperModule",cond::ecalcond::bySuperModule)
367  .value("all",cond::ecalcond::all)
368  ;
369 
371  class_<What>("What",init<>())
372  .def("set_how",&What::set_how)
373  .def("set_which",&What::set_which)
374  .def("how",&What::how, return_value_policy<copy_const_reference>())
375  .def("which",&What::which, return_value_policy<copy_const_reference>())
376  ;
377  }
378 }
379 
void extractSuperModules(Container const &cont, std::vector< int > const &which, std::vector< float > &result)
int i
Definition: DBlmapReader.cc:9
std::string plot(std::string const &, std::string const &, std::vector< int > const &, std::vector< float > const &) const
int gainId(sample_type sample)
get the gainId (2 bits)
ExtractWhat< Class > What
static ecalcond::CondExtractor & extractor(ecalcond::How how)
static const int kBarlRings
const Items & barrelItems() const
std::vector< std::pair< std::string, float > > type_vValues
boost::function< void(Container const &cont, std::vector< int > const &which, std::vector< float > &result)> CondExtractor
#define PYTHON_WRAPPER(_class, _name)
static const int kSides
def canvas
Definition: svgfig.py:481
int bad(Items const &cont)
static const int kBarlWedges
std::string summary() const
static const int kEndcWedgesX
tuple result
Definition: query.py:137
Container::value_type value_type
void swap(std::vector< float > &v)
static const int IX_MAX
Definition: EEDetId.h:303
static const int MAX_IPHI
Definition: EBDetId.h:145
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:249
static const int MAX_IETA
Definition: EBDetId.h:144
int cont
void extractSingleChannel(Container const &cont, std::vector< int > const &which, std::vector< float > &result)
std::string printBarrelsEndcaps(const std::vector< T > &barrelItems, const std::vector< T > &endcapItems)
tuple filename
Definition: lut2db_cfg.py:20
static unsigned int const shift
static const int IY_MAX
Definition: EEDetId.h:307
type_vValues getValues(const std::vector< EcalObject > &vItems)
Definition: DDAxes.h:10
void extractBarrel(Container const &cont, std::vector< int > const &, std::vector< float > &result)
const Items & endcapItems() const
void extractEndcap(Container const &cont, std::vector< int > const &, std::vector< float > &result)
void extractAll(Container const &cont, std::vector< int > const &, std::vector< float > &result)
static const int kEndcWedgesY