CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalFloatCondObjectContainerPyWrapper.cc
Go to the documentation of this file.
1 
2 
4 #include "TH2F.h"
5 #include "TCanvas.h"
6 #include "TStyle.h"
12 
13 #include <string>
14 
15 #include <fstream>
16 #include <sstream>
17 #include <algorithm>
18 #include <numeric>
19 #include <iterator>
20 #include <boost/ref.hpp>
21 #include <boost/bind.hpp>
22 #include <boost/function.hpp>
23 #include <boost/iterator/transform_iterator.hpp>
24 #include <algorithm>
25 
26 namespace {
27  struct Printer {
28  Printer() : i(0){}
29  void reset() { i=0;}
30  void doB(float const & item) {
31  ss << i <<":"<< item << "\n";
32  i++;
33  }
34  void doE(float const & item) {
35  ss << i <<":"<< item << "\n";
36  i++;
37  }
38  int i;
39  std::stringstream ss;
40  };
41 }
42 
43 
44 namespace cond {
45 
46  // migrate to a common trait (when fully understood)
47  namespace ecalcond {
48 
51 
53 
54 
55  void extractBarrel(Container const & cont, std::vector<int> const &, std::vector<float> & result) {
56  result.resize(cont.barrelItems().size());
57  std::copy(cont.barrelItems().begin(),cont.barrelItems().end(),result.begin());
58  }
59 
60  void extractEndcap(Container const & cont, std::vector<int> const &, std::vector<float> & result) {
61  result.resize(cont.endcapItems().size());
62  std::copy(cont.endcapItems().begin(),cont.endcapItems().end(),result.begin());
63  }
64 
65  void extractAll(Container const & cont, std::vector<int> const &, std::vector<float> & result) {
66 
67  // EcalCondObjectContainer does not have a real iterator ...
68  result.resize(cont.barrelItems().size()+ cont.endcapItems().size());
69 
70  std::copy(cont.barrelItems().begin(),cont.barrelItems().end(),result.begin());
71  std::copy(cont.endcapItems().begin(),cont.endcapItems().end(),result.end());
72  }
73 
74  void extractSuperModules(Container const & cont, std::vector<int> const & which, std::vector<float> & result) {
75  // bho...
76  }
77 
78  void extractSingleChannel(Container const & cont, std::vector<int> const & which, std::vector<float> & result) {
79  result.reserve(which.size());
80  for (unsigned int i=0; i<which.size();i++) {
81  result.push_back(cont[which[i]]);
82  }
83  }
84 
85  typedef boost::function<void(Container const & cont, std::vector<int> const & which, std::vector<float> & result)> CondExtractor;
86 
87  } // ecalcond
88 
89  template<>
90  struct ExtractWhat<ecalcond::Container> {
91 
92  ecalcond::How m_how;
93  std::vector<int> m_which;
94 
95  ecalcond::How const & how() const { return m_how;}
96  std::vector<int> const & which() const { return m_which;}
97 
98  void set_how(ecalcond::How i) {m_how=i;}
99  void set_which(std::vector<int> & i) { m_which.swap(i);}
100  };
101 
102 
103 
104 
105  template<>
106  class ValueExtractor<ecalcond::Container>: public BaseValueExtractor<ecalcond::Container> {
107  public:
108 
110  static ecalcond::CondExtractor fun[5] = {
116  };
117  return fun[how];
118  }
119 
120 
123  static What what() { return What();}
124 
127  : m_what(what)
128  {
129  // here one can make stuff really complicated...
130  // ask to make average on selected channels...
131  }
132 
133  void compute(Class const & it) override{
134  std::vector<float> res;
135  extractor(m_what.how())(it,m_what.which(),res);
136  swap(res);
137  }
138 
139  private:
140  What m_what;
141 
142  };
143 
144 
145  template<>
148 
149  std::stringstream ss;
150  EcalCondHeader header;
152  return ss.str();
153 
154  // Printer p;
155 // std::for_each(object().barrelItems().begin(),object().barrelItems().end(),boost::bind(&Printer::doB,boost::ref(p),_1));
156 // p.ss <<"\n";
157 // p.reset();
158 // std::for_each(object().endcapItems().begin(),object().endcapItems().end(),boost::bind(&Printer::doE,boost::ref(p),_1));
159 // p.ss << std::endl;
160 // return p.ss.str();
161  }
162 
163  template<>
165 
166  std::stringstream ss;
167 
168  const int kSides = 2;
169  const int kBarlRings = EBDetId::MAX_IETA;
170  const int kBarlWedges = EBDetId::MAX_IPHI;
171  const int kEndcWedgesX = EEDetId::IX_MAX;
172  const int kEndcWedgesY = EEDetId::IY_MAX;
173 
175 
176  float mean_x_EB=0;
177  float mean_xx_EB=0;
178  int num_x_EB=0;
179 
180  float mean_x_EE=0;
181  float mean_xx_EE=0;
182  int num_x_EE=0;
183 
184 
185  for (int sign=0; sign<kSides; sign++) {
186 
187  int thesign = sign==1 ? 1:-1;
188 
189  for (int ieta=0; ieta<kBarlRings; ieta++) {
190  for (int iphi=0; iphi<kBarlWedges; iphi++) {
191  EBDetId id((ieta+1)*thesign, iphi+1);
192  float x= object()[id.rawId()];
193  num_x_EB++;
194  mean_x_EB=mean_x_EB+x;
195  mean_xx_EB=mean_xx_EB+x*x;
196  }
197  }
198 
199  for (int ix=0; ix<kEndcWedgesX; ix++) {
200  for (int iy=0; iy<kEndcWedgesY; iy++) {
201  if (! EEDetId::validDetId(ix+1,iy+1,thesign)) continue;
202  EEDetId id(ix+1,iy+1,thesign);
203  float x=object()[id.rawId()];
204  num_x_EE++;
205  mean_x_EE=mean_x_EE+x;
206  mean_xx_EE=mean_xx_EE+x*x;
207 
208  }//iy
209  }//ix
210 
211 
212  }
213 
214  mean_x_EB=mean_x_EB/num_x_EB;
215  mean_x_EE=mean_x_EE/num_x_EE;
216  mean_xx_EB=mean_xx_EB/num_x_EB;
217  mean_xx_EE=mean_xx_EE/num_x_EE;
218  float rms_EB=(mean_xx_EB-mean_x_EB*mean_x_EB);
219  float rms_EE=(mean_xx_EE-mean_x_EE*mean_x_EE);
220 
221  ss << "ECAL BARREL Mean: "<< mean_x_EB <<" RMS: "<< rms_EB << " Nchan: "<< num_x_EB<< std::endl
222  << "ECAL Endcap Mean: "<< mean_x_EE <<" RMS: "<< rms_EE << " Nchan: "<< num_x_EE<< std::endl ;
223 
224 
225  return ss.str();
226  }
227 
228 
229 
230  template<>
232  std::string const &,
233  std::vector<int> const&,
234  std::vector<float> const& ) const {
235 
236  gStyle->SetPalette(1);
237  TCanvas canvas("CC map","CC map",840,280);
238  //canvas.Divide(3,1);
239 
240  TPad pad1("p1","p1", 0.0, 0.0, 0.2, 1.0);
241  TPad pad2("p2","p2", 0.2, 0.0, 0.8, 1.0);
242  TPad pad3("p3","p3", 0.8, 0.0, 1.0, 1.0);
243  pad1.Draw();
244  pad2.Draw();
245  pad3.Draw();
246 
247  TH2F barrelmap("EB","EB",360,1,360, 171, -85,86);
248  TH2F endcmap_p("EE+","EE+",100,1,101,100,1,101);
249  TH2F endcmap_m("EE-","EE-",100,1,101,100,1,101);
250 
251  const int kSides = 2;
252  const int kBarlRings = EBDetId::MAX_IETA;
253  const int kBarlWedges = EBDetId::MAX_IPHI;
254  const int kEndcWedgesX = EEDetId::IX_MAX;
255  const int kEndcWedgesY = EEDetId::IY_MAX;
256 
258  for (int sign=0; sign<kSides; sign++) {
259 
260  int thesign = sign==1 ? 1:-1;
261 
262  for (int ieta=0; ieta<kBarlRings; ieta++) {
263  for (int iphi=0; iphi<kBarlWedges; iphi++) {
264  EBDetId id((ieta+1)*thesign, iphi+1);
265  barrelmap.Fill(iphi+1,ieta*thesign + thesign, object()[id.rawId()]);
266  }
267  }
268 
269  for (int ix=0; ix<kEndcWedgesX; ix++) {
270  for (int iy=0; iy<kEndcWedgesY; iy++) {
271  if (! EEDetId::validDetId(ix+1,iy+1,thesign)) continue;
272  EEDetId id(ix+1,iy+1,thesign);
273 
274  if (thesign==1) {
275  endcmap_p.Fill(ix+1,iy+1,object()[id.rawId()]);
276  }
277  else{
278  endcmap_m.Fill(ix+1,iy+1,object()[id.rawId()]);
279 
280  }
281  }//iy
282  }//ix
283 
284 
285 
286  }
287 
288 
289  //canvas.cd(1);
290  pad1.cd();
291  endcmap_m.SetStats(0);
292  endcmap_m.Draw("colz");
293  //canvas.cd(2);
294  pad2.cd();
295  barrelmap.SetStats(0);
296  barrelmap.Draw("colz");
297  //canvas.cd(3);
298  pad3.cd();
299  endcmap_p.SetStats(0);
300  endcmap_p.Draw("colz");
301 
302  canvas.SaveAs(filename.c_str());
303  return filename;
304  }
305 
306 
307 }
308 
309 namespace condPython {
310  template<>
311  void defineWhat<cond::ecalcond::Container>() {
312  using namespace boost::python;
313  enum_<cond::ecalcond::How>("How")
314  .value("singleChannel",cond::ecalcond::singleChannel)
315  .value("bySuperModule",cond::ecalcond::bySuperModule)
316  .value("barrel",cond::ecalcond::barrel)
317  .value("endcap",cond::ecalcond::endcap)
318  .value("all",cond::ecalcond::all)
319  ;
320 
322  class_<What>("What",init<>())
323  .def("set_how",&What::set_how)
324  .def("set_which",&What::set_which)
325  .def("how",&What::how, return_value_policy<copy_const_reference>())
326  .def("which",&What::which, return_value_policy<copy_const_reference>())
327  ;
328  }
329 }
330 
331 
332 
333 
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
EcalChannelStatus Container
static ecalcond::CondExtractor & extractor(ecalcond::How how)
ExtractWhat< Class > What
static const int kBarlRings
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
static const int kBarlWedges
std::string summary() const
static const int kEndcWedgesX
static std::string dumpXML(const EcalCondHeader &header, const EcalFloatCondObjectContainer &record)
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:302
static const int MAX_IPHI
Definition: EBDetId.h:144
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
static const int MAX_IETA
Definition: EBDetId.h:143
int cont
list object
Definition: dbtoconf.py:77
void extractSingleChannel(Container const &cont, std::vector< int > const &which, std::vector< float > &result)
tuple filename
Definition: lut2db_cfg.py:20
static const int IY_MAX
Definition: EEDetId.h:306
Definition: DDAxes.h:10
void extractBarrel(Container const &cont, std::vector< int > const &, std::vector< float > &result)
void reset(double vett[256])
Definition: TPedValues.cc:11
std::string dump() 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