CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalDQMTowerStatusPyWrapper.cc
Go to the documentation of this file.
2 //#include "CondTools/Ecal/interface/EcalDQMTowerStatusXMLTranslator.h"
4 #include "TROOT.h"
5 #include "TH2F.h"
6 #include "TCanvas.h"
7 #include "TStyle.h"
8 #include "TColor.h"
9 #include "TLine.h"
12 
15 
16 #include <string>
17 #include <sstream>
18 #include <algorithm>
19 #include <numeric>
20 #include <iterator>
21 #include <boost/ref.hpp>
22 #include <boost/bind.hpp>
23 #include <boost/function.hpp>
24 #include <boost/iterator/transform_iterator.hpp>
25 
26 #include <fstream>
27 
29 
30 namespace cond {
31 
32  namespace ecalcond {
33 
36 
38 
39  int bad(Items const & cont) {
40  return std::count_if(cont.begin(),cont.end(),
41  boost::bind(std::greater<int>(),
42  boost::bind(&value_type::getStatusCode,_1),0)
43  );
44  }
45 
46  void extractBarrel(EcalDQMTowerStatus const & cont, std::vector<int> const &, std::vector<float> & result) {
47  result.resize(1);
48  result[0] = bad(cont.barrelItems());
49  }
50 
51  void extractEndcap(EcalDQMTowerStatus const & cont, std::vector<int> const &, std::vector<float> & result) {
52  result.resize(1);
53  result[0] = bad(cont.endcapItems());
54  }
55  void extractAll(EcalDQMTowerStatus const & cont, std::vector<int> const &, std::vector<float> & result) {
56  result.resize(1);
57  result[0] = bad(cont.barrelItems())+bad(cont.endcapItems());
58  }
59 
60  void extractSuperModules(EcalDQMTowerStatus const & cont, std::vector<int> const & which, std::vector<float> & result) {
61  // bho...
62  }
63 
64  void extractSingleChannel(EcalDQMTowerStatus const & cont, std::vector<int> const & which, std::vector<float> & result) {
65  result.reserve(which.size());
66  for (unsigned int i=0; i<which.size();i++) {
67  result.push_back(cont[which[i]].getStatusCode());
68  }
69  }
70 
71  typedef boost::function<void(EcalDQMTowerStatus const & cont, std::vector<int> const & which, std::vector<float> & result)> CondExtractor;
72  } // namespace ecalcond
73 
74  template<>
76 
78  std::vector<int> m_which;
79 
80  ecalcond::How const & how() const { return m_how;}
81  std::vector<int> const & which() const { return m_which;}
82 
83  void set_how(ecalcond::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<EcalDQMTowerStatus>: public BaseValueExtractor<EcalDQMTowerStatus> {
90  public:
91 
93  static ecalcond::CondExtractor 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...
110  }
111 
112  void compute(Class const & it){
113  std::vector<float> res;
114  extractor(m_what.how())(it,m_what.which(),res);
115  swap(res);
116  }
117 
118  private:
120  };
121 
122 
123  //template<>
124  //std::string PayLoadInspector<EcalDQMTowerStatus>::dump() const {
125  // std::stringstream ss;
126  // EcalCondHeader h;
127  // ss << EcalDQMTowerStatusXMLTranslator::dumpXML(h,object());
128  // return ss.str();
129  //}
130 
131  class EcalDQMTowerStatusHelper: public EcalPyWrapperHelper<EcalDQMStatusCode>{
132  public:
133  //change me
135  protected:
136 
137  //change me
139 
140  type_vValues getValues( const std::vector<EcalObject> & vItems)
141  {
142  //change me
143  //unsigned int totalValues = 2;
144 
145  type_vValues vValues(total_values);
146 
147  std::stringstream ss;
148 
149  std::string valueNames[] = {
150  "CH_ID_ERROR ",
151  "CH_GAIN_ZERO_ERROR ",
152  "CH_GAIN_SWITCH_ERROR ",
153  "TT_ID_ERROR ",
154  "TT_SIZE_ERROR ",
155  "PEDESTAL_LOW_GAIN_MEAN_ERROR ",
156  "PEDESTAL_MIDDLE_GAIN_MEAN_ERROR ",
157  "PEDESTAL_HIGH_GAIN_MEAN_ERROR ",
158  "PEDESTAL_LOW_GAIN_RMS_ERROR ",
159  "PEDESTAL_MIDDLE_GAIN_RMS_ERROR ",
160  "PEDESTAL_HIGH_GAIN_RMS_ERROR ",
161  "PEDESTAL_ONLINE_HIGH_GAIN_MEAN_ERROR ",
162  "PEDESTAL_ONLINE_HIGH_GAIN_RMS_ERROR ",
163  "TESTPULSE_LOW_GAIN_MEAN_ERROR ",
164  "TESTPULSE_MIDDLE_GAIN_MEAN_ERROR ",
165  "TESTPULSE_HIGH_GAIN_MEAN_ERROR ",
166  "TESTPULSE_LOW_GAIN_RMS_ERROR ",
167  "TESTPULSE_MIDDLE_GAIN_RMS_ERROR ",
168  "TESTPULSE_HIGH_GAIN_RMS_ERROR ",
169  "LASER_MEAN_ERROR ",
170  "LASER_RMS_ERROR ",
171  "LASER_TIMING_MEAN_ERROR ",
172  "LASER_TIMING_RMS_ERROR ",
173  "LED_MEAN_ERROR ",
174  "LED_RMS_ERROR ",
175  "LED_TIMING_MEAN_ERROR ",
176  "LED_TIMING_RMS_ERROR ",
177  "STATUS_FLAG_ERROR ",
178  "PHYSICS_BAD_CHANNEL_WARNING ",
179  "PHYSICS_BAD_CHANNEL_ERROR "
180  };
181  for (unsigned int i = 0; i < total_values; ++i){
182  ss.str(""); ss << "[" << i << "]" << valueNames[i];
183  vValues[i].first = ss.str();
184  vValues[i].second = .0;
185  }
186 
187  //get info:
188  unsigned int shift = 0, mask = 1;
189  unsigned int statusCode;
190  for(std::vector<EcalObject>::const_iterator iItems = vItems.begin(); iItems != vItems.end(); ++iItems){
191  //change us
192  statusCode = iItems->getStatusCode();
193  for (shift = 0; shift < total_values; ++shift){
194  mask = 1 << (shift);
195  //std::cout << "; statuscode: " << statusCode;
196  if (statusCode & mask){
197  vValues[shift].second += 1;
198  }
199  }
200  }
201  return vValues;
202  }
203  };
204 
205  template<>
207  std::stringstream ss;
209  ss << helper.printBarrelsEndcaps(object().barrelItems(), object().endcapItems());
210  return ss.str();
211  }
212 
213  // return the real name of the file including extension...
214  template<>
216  std::string const &,
217  std::vector<int> const&,
218  std::vector<float> const& ) const {
219  // std::string fname = filename + ".txt";
220  // EcalDAQTowerStatusXMLTranslator::plot(fname, object());
221  // return fname;
222  TCanvas canvas("CC map","CC map",800,800);
223  TPad* padb = new TPad("padb","padb", 0., 0.55, 1., 1.);
224  padb->Draw();
225  TPad* padem = new TPad("padem","padem", 0., 0., 0.45, 0.45);
226  padem->Draw();
227  TPad* padep = new TPad("padep","padep", 0.55, 0., 1., 0.45);
228  padep->Draw();
229 
230  TH2F* barrel = new TH2F("EB","EB Tower Status", 72, 0, 72, 34, -17, 17);
231  TH2F* endc_p = new TH2F("EE+","EE+ Tower Status",22, 0, 22, 22, 0, 22);
232  TH2F* endc_m = new TH2F("EE-","EE- Tower Status",22, 0, 22, 22, 0, 22);
233  for(uint cellid = 0;
235  ++cellid) {
237  if (object().find(rawid) == object().end()) continue;
238  int ieta = rawid.ieta();
239  if(ieta > 0) ieta--; // 1 to 17
240  int iphi = rawid.iphi() - 1; // 0 to 71
241  barrel->Fill(iphi, ieta, object()[rawid].getStatusCode());
242  }
243  for(uint cellid = 0;
245  ++cellid) {
246  if(EcalScDetId::validHashIndex(cellid)) {
247  EcalScDetId rawid = EcalScDetId::unhashIndex(cellid);
248  int ix = rawid.ix(); // 1 to 20
249  int iy = rawid.iy(); // 1 to 20
250  int side = rawid.zside();
251  if(side == -1)
252  endc_m->Fill(ix, iy, object()[rawid].getStatusCode());
253  else
254  endc_p->Fill(ix, iy, object()[rawid].getStatusCode());
255  }
256  }
257  TLine* l = new TLine(0., 0., 0., 0.);
258  l->SetLineWidth(1);
259  padb->cd();
260  barrel->SetStats(0);
261  // barrel->SetMaximum(14);
262  // barrel->SetMinimum(0);
263  // barrel->Draw("colz");
264  barrel->Draw("col");
265  for(int i = 0; i <17; i++) {
266  Double_t x = 4.+ (i * 4);
267  l = new TLine(x, -17., x, 17.);
268  l->Draw();
269  }
270  l = new TLine(0., 0., 72., 0.);
271  l->Draw();
272 
273  int ixSectorsEE[136] = {
274  8,14,14,17,17,18,18,19,19,20,20,21,21,20,20,19,19,18,18,17,
275  17,14,14, 8, 8, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 2, 2, 3, 3, 4,
276  4, 5, 5, 8, 8, 8, 9, 9,10,10,12,12,13,13,12,12,10,10, 9, 9,
277  10,10, 0,11,11, 0,10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 0,12,13,
278  13,14,14,15,15,16,16,17,17, 0, 9, 8, 8, 3, 3, 1, 0,13,14,14,
279  19,19,21, 0, 9, 8, 8, 7, 7, 5, 5, 3, 3, 2, 0,13,14,14,15,15,
280  17,17,19,19,20, 0,14,14,13,13,12,12,0};
281  int iySectorsEE[136] = {
282  1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 8, 8,14,14,17,17,18,18,19,19,
283  20,20,21,21,20,20,19,19,18,18,17,17,14,14, 8, 8, 5, 5, 4, 4,
284  3, 3, 2, 2, 1, 4, 4, 7, 7, 9, 9,10,10,12,12,13,13,12,12,10,
285  10, 9, 0,13,21, 0,13,13,14,14,15,15,16,16,18,18,19, 0,13,13,
286  14,14,15,15,16,16,18,18,19, 0,11,11,12,12,13,13, 0,11,11,12,
287  12,13,13, 0,10,10, 9, 9, 8, 8, 7, 7, 6, 6, 0,10,10, 9, 9, 8,
288  8, 7, 7, 6, 6, 0, 2, 4, 4, 7, 7, 9, 0} ;
289  padem->cd();
290  endc_m->SetStats(0);
291  endc_m->Draw("col");
292  for ( int i = 0; i < 136; i=i+1) {
293  if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
294  (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
295  l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
296  ixSectorsEE[i+1], iySectorsEE[i+1]);
297  }
298  }
299 
300  padep->cd();
301  endc_p->SetStats(0);
302  endc_p->Draw("col");
303  for ( int i = 0; i < 136; i=i+1) {
304  if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
305  (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
306  l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
307  ixSectorsEE[i+1], iySectorsEE[i+1]);
308  }
309  }
310 
311  canvas.SaveAs(filename.c_str());
312  return filename;
313  }
314 }
315 
316 
317 namespace condPython {
318  template<>
320  enum_<cond::ecalcond::How>("How")
321  .value("singleChannel",cond::ecalcond::singleChannel)
322  .value("bySuperModule",cond::ecalcond::bySuperModule)
323  .value("all",cond::ecalcond::all)
324  ;
325 
327  class_<What>("What",init<>())
328  .def("set_how",&What::set_how)
329  .def("set_which",&What::set_which)
330  .def("how",&What::how, return_value_policy<copy_const_reference>())
331  .def("which",&What::which, return_value_policy<copy_const_reference>())
332  ;
333  }
334 }
335 
void extractSuperModules(Container const &cont, std::vector< int > const &which, std::vector< float > &result)
int i
Definition: DBlmapReader.cc:9
static EcalTrigTowerDetId detIdFromDenseIndex(uint32_t di)
std::string plot(std::string const &, std::string const &, std::vector< int > const &, std::vector< float > const &) const
tuple cont
load Luminosity info ##
Definition: generateEDF.py:622
ExtractWhat< Class > What
std::vector< std::pair< std::string, float > > type_vValues
Code getStatusCode() const
return decoded status
boost::function< void(Container const &cont, std::vector< int > const &which, std::vector< float > &result)> CondExtractor
static EcalScDetId unhashIndex(int hi)
Definition: EcalScDetId.h:118
#define PYTHON_WRAPPER(_class, _name)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
int ieta() const
get the tower ieta
static ecalcond::CondExtractor & extractor(ecalcond::How how)
def canvas
Definition: svgfig.py:481
int bad(Items const &cont)
std::string summary() const
std::vector< int > const & which() const
int ix() const
Definition: EcalScDetId.h:71
tuple result
Definition: query.py:137
#define end
Definition: vmac.h:37
Container::value_type value_type
void swap(std::vector< float > &v)
int iy() const
Definition: EcalScDetId.h:77
int iphi() const
get the tower iphi
int zside() const
Definition: EcalScDetId.h:65
static bool validHashIndex(int hi)
Definition: EcalScDetId.h:140
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
Definition: DDAxes.h:10
type_vValues getValues(const std::vector< EcalObject > &vItems)
void extractBarrel(Container const &cont, std::vector< int > const &, std::vector< float > &result)
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)