CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalPedestalsPyWrapper.cc
Go to the documentation of this file.
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 
24 #include <fstream>
25 
26 namespace {
27  struct Printer {
28  void doit(EcalPedestal const & item) {
29  for (int i=1; i<4; i++)
30  ss << item.mean(i) << "," << item.rms(i) <<";";
31  ss << " ";
32  }
33  std::stringstream ss;
34  };
35 }
36 
37 namespace cond {
38 
39  namespace ecalped {
40  enum Quantity { mean_x12=1, mean_x6=2, mean_x3=3 };
42 
43  float average(EcalPedestals const & peds, Quantity q) {
44  return std::accumulate(
45  boost::make_transform_iterator(peds.barrelItems().begin(),bind(&EcalPedestal::mean,_1,q)),
46  boost::make_transform_iterator(peds.barrelItems().end(),bind(&EcalPedestal::mean,_1,q)),
47  0.)/float(peds.barrelItems().size());
48  }
49 
50  void extractAverage(EcalPedestals const & peds, Quantity q, std::vector<int> const &, std::vector<float> & result) {
51  result.resize(1);
52  result[0] = average(peds,q);
53  }
54 
55  void extractSuperModules(EcalPedestals const & peds, Quantity q, std::vector<int> const & which, std::vector<float> & result) {
56  // bho...
57  }
58 
59  void extractSingleChannel(EcalPedestals const & peds, Quantity q, std::vector<int> const & which, std::vector<float> & result) {
60  for (unsigned int i=0; i<which.size();i++) {
61  // absolutely arbitraty
62  if ((unsigned int) (which[i])< peds.barrelItems().size())
63  result.push_back( peds.barrelItems()[which[i]].mean(q));
64  }
65  }
66 
67  typedef boost::function<void(EcalPedestals const & peds, Quantity q, std::vector<int> const & which, std::vector<float> & result)> PedExtractor;
68  }
69 
70  template<>
72 
75  std::vector<int> m_which;
76 
77  ecalped::Quantity const & quantity() const { return m_quantity;}
78  ecalped::How const & how() const { return m_how;}
79  std::vector<int> const & which() const { return m_which;}
80 
81 
82  void set_quantity( ecalped::Quantity i) { m_quantity=i;}
83  void set_how(ecalped::How i) {m_how=i;}
84  void set_which(std::vector<int> & i) { m_which.swap(i);}
85  };
86 
87 
88  template<>
89  class ValueExtractor<EcalPedestals>: public BaseValueExtractor<EcalPedestals> {
90  public:
91 
93  static ecalped::PedExtractor fun[3] = {
97  };
98  return fun[how];
99  }
100 
103  static What what() { return What();}
104 
107  : m_what(what)
108  {
109  // here one can make stuff really complicated... (select mean rms, 12,6,1)
110  // ask to make average on selected channels...
111  }
112 
113  void compute(Class const & it){
114  std::vector<float> res;
115  extractor(m_what.how())(it,m_what.quantity(),m_what.which(),res);
116  swap(res);
117  }
118 
119  private:
121 
122  };
123 
124 
125  template<>
126  std::string
128  std::stringstream ss;
129  EcalCondHeader header;
130  ss<<EcalPedestalsXMLTranslator::dumpXML(header,object());
131  return ss.str();
132  } // dump
133 
134  template<>
136  std::cout << "***************************************"<< std::endl;
137  std::stringstream ss;
138  ss << "sizes="
139  << object().barrelItems().size() <<","
140  << object().endcapItems().size() <<";";
141  ss << std::endl;
142  return ss.str();
143  } // summary
144 
145 
146  // return the real name of the file including extension...
147  template<>
148  std::string PayLoadInspector<EcalPedestals>::plot(std::string const & filename,
149  std::string const &,
150  std::vector<int> const&,
151  std::vector<float> const& ) const {
152  gStyle->SetPalette(1);
153  // TCanvas canvas("CC map","CC map",840,600);
154  TCanvas canvas("CC map","CC map",800,1200);
155 
156  float xmi[3] = {0.0 , 0.22, 0.78};
157  float xma[3] = {0.22, 0.78, 1.00};
158  TPad*** pad = new TPad**[6];
159  for (int gId = 0; gId < 6; gId++) {
160  pad[gId] = new TPad*[3];
161  for (int obj = 0; obj < 3; obj++) {
162  float yma = 1.- (0.17 * gId);
163  float ymi = yma - 0.15;
164  pad[gId][obj] = new TPad(Form("p_%i_%i", obj, gId),Form("p_%i_%i", obj, gId),
165  xmi[obj], ymi, xma[obj], yma);
166  pad[gId][obj]->Draw();
167  }
168  }
169 
170  const int kGains = 3;
171  const int gainValues[3] = {12, 6, 1};
172  const int kSides = 2;
173  const int kBarlRings = EBDetId::MAX_IETA;
174  const int kBarlWedges = EBDetId::MAX_IPHI;
175  const int kEndcWedgesX = EEDetId::IX_MAX;
176  const int kEndcWedgesY = EEDetId::IY_MAX;
177 
178  TH2F** barrel_m = new TH2F*[3];
179  TH2F** endc_p_m = new TH2F*[3];
180  TH2F** endc_m_m = new TH2F*[3];
181  TH2F** barrel_r = new TH2F*[3];
182  TH2F** endc_p_r = new TH2F*[3];
183  TH2F** endc_m_r = new TH2F*[3];
184  for (int gainId = 0; gainId < kGains; gainId++) {
185  barrel_m[gainId] = new TH2F(Form("EBm%i",gainId),Form("mean %i EB",gainValues[gainId]),360,0,360, 170, -85,85);
186  endc_p_m[gainId] = new TH2F(Form("EE+m%i",gainId),Form("mean %i EE+",gainValues[gainId]),100,1,101,100,1,101);
187  endc_m_m[gainId] = new TH2F(Form("EE-m%i",gainId),Form("mean %i EE-",gainValues[gainId]),100,1,101,100,1,101);
188  barrel_r[gainId] = new TH2F(Form("EBr%i",gainId),Form("rms %i EB",gainValues[gainId]),360,0,360, 170, -85,85);
189  endc_p_r[gainId] = new TH2F(Form("EE+r%i",gainId),Form("rms %i EE+",gainValues[gainId]),100,1,101,100,1,101);
190  endc_m_r[gainId] = new TH2F(Form("EE-r%i",gainId),Form("rms %i EE-",gainValues[gainId]),100,1,101,100,1,101);
191  }
192 
193  for (int sign=0; sign < kSides; sign++) {
194  int thesign = sign==1 ? 1:-1;
195 
196  for (int ieta=0; ieta<kBarlRings; ieta++) {
197  for (int iphi=0; iphi<kBarlWedges; iphi++) {
198  EBDetId id((ieta+1)*thesign, iphi+1);
199  float y = -1 - ieta;
200  if(sign == 1) y = ieta;
201  barrel_m[0]->Fill(iphi, y, object()[id.rawId()].mean_x12);
202  barrel_r[0]->Fill(iphi, y, object()[id.rawId()].rms_x12);
203  barrel_m[1]->Fill(iphi, y, object()[id.rawId()].mean_x6);
204  barrel_r[1]->Fill(iphi, y, object()[id.rawId()].rms_x6);
205  barrel_m[2]->Fill(iphi, y, object()[id.rawId()].mean_x1);
206  barrel_r[2]->Fill(iphi, y, object()[id.rawId()].rms_x1);
207  } // iphi
208  } // ieta
209 
210  for (int ix=0; ix<kEndcWedgesX; ix++) {
211  for (int iy=0; iy<kEndcWedgesY; iy++) {
212  if (! EEDetId::validDetId(ix+1,iy+1,thesign)) continue;
213  EEDetId id(ix+1,iy+1,thesign);
214  if (thesign==1) {
215  endc_p_m[0]->Fill(ix+1,iy+1,object()[id.rawId()].mean_x12);
216  endc_p_r[0]->Fill(ix+1,iy+1,object()[id.rawId()].rms_x12);
217  endc_p_m[1]->Fill(ix+1,iy+1,object()[id.rawId()].mean_x6);
218  endc_p_r[1]->Fill(ix+1,iy+1,object()[id.rawId()].rms_x6);
219  endc_p_m[2]->Fill(ix+1,iy+1,object()[id.rawId()].mean_x1);
220  endc_p_r[2]->Fill(ix+1,iy+1,object()[id.rawId()].rms_x1);
221  }
222  else{
223  endc_m_m[0]->Fill(ix+1,iy+1,object()[id.rawId()].mean_x12);
224  endc_m_r[0]->Fill(ix+1,iy+1,object()[id.rawId()].rms_x12);
225  endc_m_m[1]->Fill(ix+1,iy+1,object()[id.rawId()].mean_x6);
226  endc_m_r[1]->Fill(ix+1,iy+1,object()[id.rawId()].rms_x6);
227  endc_m_m[2]->Fill(ix+1,iy+1,object()[id.rawId()].mean_x1);
228  endc_m_r[2]->Fill(ix+1,iy+1,object()[id.rawId()].rms_x1);
229  }
230  } // iy
231  } // ix
232  } // side
233 
234  //canvas.cd(1);
235  float bmin[3] ={0.7, 0.5, 0.4};
236  float bmax[3] ={1.7, 1.0, 0.8};
237  float emin[3] ={1.5, 0.8, 0.4};
238  float emax[3] ={2.5, 1.5, 0.8};
239  TLine* l = new TLine(0., 0., 0., 0.);
240  l->SetLineWidth(1);
241  int ixSectorsEE[202] = {
242  62, 62, 61, 61, 60, 60, 59, 59, 58, 58, 56, 56, 46, 46, 44, 44, 43, 43, 42, 42,
243  41, 41, 40, 40, 41, 41, 42, 42, 43, 43, 44, 44, 46, 46, 56, 56, 58, 58, 59, 59,
244  60, 60, 61, 61, 62, 62, 0,101,101, 98, 98, 96, 96, 93, 93, 88, 88, 86, 86, 81,
245  81, 76, 76, 66, 66, 61, 61, 41, 41, 36, 36, 26, 26, 21, 21, 16, 16, 14, 14, 9,
246  9, 6, 6, 4, 4, 1, 1, 4, 4, 6, 6, 9, 9, 14, 14, 16, 16, 21, 21, 26,
247  26, 36, 36, 41, 41, 61, 61, 66, 66, 76, 76, 81, 81, 86, 86, 88, 88, 93, 93, 96,
248  96, 98, 98,101,101, 0, 62, 66, 66, 71, 71, 81, 81, 91, 91, 93, 0, 62, 66, 66,
249  91, 91, 98, 0, 58, 61, 61, 66, 66, 71, 71, 76, 76, 81, 81, 0, 51, 51, 0, 44,
250  41, 41, 36, 36, 31, 31, 26, 26, 21, 21, 0, 40, 36, 36, 11, 11, 4, 0, 40, 36,
251  36, 31, 31, 21, 21, 11, 11, 9, 0, 46, 46, 41, 41, 36, 36, 0, 56, 56, 61, 61, 66, 66};
252 
253  int iySectorsEE[202] = {
254  51, 56, 56, 58, 58, 59, 59, 60, 60, 61, 61, 62, 62, 61, 61, 60, 60, 59, 59, 58,
255  58, 56, 56, 46, 46, 44, 44, 43, 43, 42, 42, 41, 41, 40, 40, 41, 41, 42, 42, 43,
256  43, 44, 44, 46, 46, 51, 0, 51, 61, 61, 66, 66, 76, 76, 81, 81, 86, 86, 88, 88,
257  93, 93, 96, 96, 98, 98,101,101, 98, 98, 96, 96, 93, 93, 88, 88, 86, 86, 81, 81,
258  76, 76, 66, 66, 61, 61, 41, 41, 36, 36, 26, 26, 21, 21, 16, 16, 14, 14, 9, 9,
259  6, 6, 4, 4, 1, 1, 4, 4, 6, 6, 9, 9, 14, 14, 16, 16, 21, 21, 26, 26,
260  36, 36, 41, 41, 51, 0, 46, 46, 41, 41, 36, 36, 31, 31, 26, 26, 0, 51, 51, 56,
261  56, 61, 61, 0, 61, 61, 66, 66, 71, 71, 76, 76, 86, 86, 88, 0, 62,101, 0, 61,
262  61, 66, 66, 71, 71, 76, 76, 86, 86, 88, 0, 51, 51, 56, 56, 61, 61, 0, 46, 46,
263  41, 41, 36, 36, 31, 31, 26, 26, 0, 40, 31, 31, 16, 16, 6, 0, 40, 31, 31, 16, 16, 6};
264 
265  for (int gId = 0; gId < 3; gId++) {
266  pad[gId][0]->cd();
267  endc_m_m[gId]->SetStats(0);
268  endc_m_m[gId]->SetMaximum(225);
269  endc_m_m[gId]->SetMinimum(175);
270  endc_m_m[gId]->Draw("colz");
271  for ( int i=0; i<201; i=i+1) {
272  if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
273  (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
274  l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
275  ixSectorsEE[i+1], iySectorsEE[i+1]);
276  l->SetLineWidth(0.2);
277  }
278  }
279  pad[gId + 3][0]->cd();
280  endc_m_r[gId]->SetStats(0);
281  endc_m_r[gId]->SetMaximum(emax[gId]);
282  endc_m_r[gId]->SetMinimum(emin[gId]);
283  endc_m_r[gId]->Draw("colz");
284  for ( int i=0; i<201; i=i+1) {
285  if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
286  (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
287  l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
288  ixSectorsEE[i+1], iySectorsEE[i+1]);
289  }
290  }
291  //canvas.cd(2);
292  pad[gId][1]->cd();
293  barrel_m[gId]->SetStats(0);
294  barrel_m[gId]->SetMaximum(225);
295  barrel_m[gId]->SetMinimum(175);
296  barrel_m[gId]->Draw("colz");
297  for(int i = 0; i <17; i++) {
298  Double_t x = 20.+ (i *20);
299  l = new TLine(x,-85.,x,86.);
300  l->Draw();
301  }
302  l = new TLine(0.,0.,360.,0.);
303  l->Draw();
304  pad[gId + 3][1]->cd();
305  barrel_r[gId]->SetStats(0);
306  barrel_r[gId]->SetMaximum(bmax[gId]);
307  barrel_r[gId]->SetMinimum(bmin[gId]);
308  barrel_r[gId]->Draw("colz");
309  for(int i = 0; i <17; i++) {
310  Double_t x = 20.+ (i *20);
311  l = new TLine(x,-85.,x,86.);
312  l->Draw();
313  }
314  l = new TLine(0.,0.,360.,0.);
315  l->Draw();
316  //canvas.cd(3);
317  pad[gId][2]->cd();
318  endc_p_m[gId]->SetStats(0);
319  endc_p_m[gId]->SetMaximum(225);
320  endc_p_m[gId]->SetMinimum(175);
321  endc_p_m[gId]->Draw("colz");
322  for ( int i=0; i<201; i=i+1) {
323  if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
324  (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
325  l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
326  ixSectorsEE[i+1], iySectorsEE[i+1]);
327  }
328  }
329  pad[gId + 3][2]->cd();
330  endc_p_r[gId]->SetStats(0);
331  endc_p_r[gId]->SetMaximum(emax[gId]);
332  endc_p_r[gId]->SetMinimum(emin[gId]);
333  endc_p_r[gId]->Draw("colz");
334  for ( int i=0; i<201; i=i+1) {
335  if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
336  (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
337  l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
338  ixSectorsEE[i+1], iySectorsEE[i+1]);
339  }
340  }
341  }
342 
343  canvas.SaveAs(filename.c_str());
344  return filename;
345  } // plot
346 }
347 
348 namespace condPython {
349  template<>
351  using namespace boost::python;
352  enum_<cond::ecalped::Quantity>("Quantity")
353  .value("mean_x12",cond::ecalped::mean_x12)
354  .value("mean_x6", cond::ecalped::mean_x6)
355  .value("mean_x3", cond::ecalped::mean_x3)
356  ;
357  enum_<cond::ecalped::How>("How")
358  .value("singleChannel",cond::ecalped::singleChannel)
359  .value("bySuperModule",cond::ecalped::bySuperModule)
360  .value("all",cond::ecalped::all)
361  ;
362 
364  class_<What>("What",init<>())
365  .def("set_quantity",&What::set_quantity)
366  .def("set_how",&What::set_how)
367  .def("set_which",&What::set_which)
368  .def("quantity",&What::quantity, return_value_policy<copy_const_reference>())
369  .def("how",&What::how, return_value_policy<copy_const_reference>())
370  .def("which",&What::which, return_value_policy<copy_const_reference>())
371  ;
372  }
373 }
374 
375 
376 
int i
Definition: DBlmapReader.cc:9
std::string plot(std::string const &, std::string const &, std::vector< int > const &, std::vector< float > const &) const
float average(EcalPedestals const &peds, Quantity q)
int gainId(sample_type sample)
get the gainId (2 bits)
ExtractWhat< Class > What
static const int kBarlRings
const Items & barrelItems() const
static ecalped::PedExtractor & extractor(ecalped::How how)
ecalped::Quantity const & quantity() const
#define PYTHON_WRAPPER(_class, _name)
std::vector< int > const & which() const
static const int kSides
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.cc:562
boost::function< void(EcalPedestals const &peds, Quantity q, std::vector< int > const &which, std::vector< float > &result)> PedExtractor
ecalped::How const & how() const
def canvas
Definition: svgfig.py:481
static std::string dumpXML(const EcalCondHeader &header, const EcalPedestals &record)
static const int kBarlWedges
std::string summary() const
void extractAverage(EcalPedestals const &peds, Quantity q, std::vector< int > const &, std::vector< float > &result)
tuple obj
Example code starts here #.
Definition: VarParsing.py:655
static const int kEndcWedgesX
void set_which(std::vector< int > &i)
tuple result
Definition: query.py:137
float mean(int i) const
Definition: EcalPedestals.h:25
void swap(std::vector< float > &v)
static const int IX_MAX
Definition: EEDetId.h:279
float rms(int i) const
Definition: EcalPedestals.h:30
static const int MAX_IPHI
Definition: EBDetId.h:123
static const int MAX_IETA
Definition: EBDetId.h:122
void defineWhat< EcalPedestals >()
list object
Definition: dbtoconf.py:77
tuple filename
Definition: lut2db_cfg.py:20
tuple cout
Definition: gather_cfg.py:41
static const int IY_MAX
Definition: EEDetId.h:283
std::string dump() const
void extractSingleChannel(EcalPedestals const &peds, Quantity q, std::vector< int > const &which, std::vector< float > &result)
void extractSuperModules(EcalPedestals const &peds, Quantity q, std::vector< int > const &which, std::vector< float > &result)
static const int kEndcWedgesY