CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalDCSTowerStatusPyWrapper.cc
Go to the documentation of this file.
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(EcalDCSTowerStatus 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(EcalDCSTowerStatus const & cont, std::vector<int> const &, std::vector<float> & result) {
52  result.resize(1);
53  result[0] = bad(cont.endcapItems());
54  }
55  void extractAll(EcalDCSTowerStatus 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(EcalDCSTowerStatus const & cont, std::vector<int> const & which, std::vector<float> & result) {
61  // bho...
62  }
63 
64  void extractSingleChannel(EcalDCSTowerStatus 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(EcalDCSTowerStatus 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<EcalDCSTowerStatus>: public BaseValueExtractor<EcalDCSTowerStatus> {
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) override{
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<>
125  std::stringstream ss;
128  return ss.str();
129  }
130 
131  class EcalDCSTowerStatusHelper: public EcalPyWrapperHelper<EcalChannelStatusCode>{
132  public:
133  //change me
135  protected:
136 
137  //change me
139 
140  type_vValues getValues( const std::vector<EcalObject> & vItems) override
141  {
142  //change me
143  //unsigned int totalValues = 2;
144 
145  type_vValues vValues(total_values);
146 
147  //change us
148  vValues[0].first = "LVSTATUS(0)";
149  vValues[1].first = "LVNOMINALSTATUS(1)";
150  vValues[2].first = "HVSTATUS(2)";
151  vValues[3].first = "HVNOMINALSTATUS(3)";
152  vValues[4].first = "HVEEDSTATUS(4)";
153  vValues[5].first = "HVEEDNOMINALSTATUS(5)";
154 
155 
156  vValues[0].second = .0;
157  vValues[1].second = .0;
158  vValues[2].second = .0;
159  vValues[3].second = .0;
160  vValues[4].second = .0;
161  vValues[5].second = .0;
162 
163  //get info:
164  unsigned int shift = 0, mask = 1;
165  unsigned int statusCode;
166  for(std::vector<EcalObject>::const_iterator iItems = vItems.begin(); iItems != vItems.end(); ++iItems){
167  //change us
168  statusCode = iItems->getStatusCode();
169  for (shift = 0; shift < total_values; ++shift){
170  mask = 1 << (shift);
171  //std::cout << "; statuscode: " << statusCode;
172  if (statusCode & mask){
173  vValues[shift].second += 1;
174  }
175  }
176  }
177  return vValues;
178  }
179  };
180 
181  template<>
183  std::stringstream ss;
185  ss << helper.printBarrelsEndcaps(object().barrelItems(), object().endcapItems());
186  return ss.str();
187  }
188 
189 
190  // return the real name of the file including extension...
191  template<>
193  std::string const &,
194  std::vector<int> const&,
195  std::vector<float> const& ) const {
196  // std::string fname = filename + ".txt";
197  // EcalDCSTowerStatusXMLTranslator::plot(fname, object());
198  // return fname;
199 
200  // use David's palette
201  gStyle->SetPalette(1);
202 
203  const Int_t NRGBs = 5;
204  const Int_t NCont = 255;
205 
206  Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
207  Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 };
208  Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
209  Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 };
210  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
211  gStyle->SetNumberContours(NCont);
212 
213  TCanvas canvas("CC map","CC map",800,800);
214  TPad* padb = new TPad("padb","padb", 0., 0.55, 1., 1.);
215  padb->Draw();
216  TPad* padem = new TPad("padem","padem", 0., 0., 0.45, 0.45);
217  padem->Draw();
218  TPad* padep = new TPad("padep","padep", 0.55, 0., 1., 0.45);
219  padep->Draw();
220 
221  // TH2F* barrel = new TH2F("EB","EB Tower Status", 72, 0, 72, 35, -17, 18);
222  TH2F* barrel = new TH2F("EB","EB Tower Status", 72, 0, 72, 34, -17, 17);
223  TH2F* endc_p = new TH2F("EE+","EE+ Tower Status",22, 0, 22, 22, 0, 22);
224  TH2F* endc_m = new TH2F("EE-","EE- Tower Status",22, 0, 22, 22, 0, 22);
225  for(uint cellid = 0;
227  ++cellid) {
229  if (object().find(rawid) == object().end()) continue;
230  int ieta = rawid.ieta();
231  if(ieta > 0) ieta--; // 1 to 17
232  int iphi = rawid.iphi() - 1; // 0 to 71
233  barrel->Fill(iphi, ieta, object()[rawid].getStatusCode());
234  }
235  for(uint cellid = 0;
237  ++cellid) {
238  if(EcalScDetId::validHashIndex(cellid)) {
239  EcalScDetId rawid = EcalScDetId::unhashIndex(cellid);
240  int ix = rawid.ix(); // 1 to 20
241  int iy = rawid.iy(); // 1 to 20
242  int side = rawid.zside();
243  if(side == -1)
244  endc_m->Fill(ix, iy, object()[rawid].getStatusCode());
245  else
246  endc_p->Fill(ix, iy, object()[rawid].getStatusCode());
247  }
248  }
249  TLine* l = new TLine(0., 0., 0., 0.);
250  l->SetLineWidth(1);
251  padb->cd();
252  barrel->SetStats(0);
253  barrel->SetMaximum(14);
254  barrel->SetMinimum(0);
255  barrel->Draw("colz");
256  // barrel->Draw("col");
257  for(int i = 0; i <17; i++) {
258  Double_t x = 4.+ (i * 4);
259  l = new TLine(x, -17., x, 17.);
260  l->Draw();
261  }
262  l = new TLine(0., 0., 72., 0.);
263  l->Draw();
264 
265  int ixSectorsEE[133] = {
266  8,14,14,17,17,18,18,19,19,20,20,21,21,20,20,19,19,18,18,17,
267  17,14,14, 8, 8, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 2, 2, 3, 3, 4,
268  4, 5, 5, 8, 8, 8, 9, 9,10,10,12,12,13,13,12,12,10,10, 9, 9,
269  10,10, 0,11,11, 0,10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 0,12,13,
270  13,14,14,15,15,16,16,17,17, 0, 9, 8, 8, 3, 3, 1, 0,13,14,14,
271  19,19,21, 0, 9, 8, 8, 7, 7, 5, 5, 3, 3, 2, 0,13,14,14,15,15,
272  17,17,19,19,20, 0,14,14,13,13,12,12,0};
273  int iySectorsEE[133] = {
274  1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 8, 8,14,14,17,17,18,18,19,19,
275  20,20,21,21,20,20,19,19,18,18,17,17,14,14, 8, 8, 5, 5, 4, 4,
276  3, 3, 2, 2, 1, 4, 4, 7, 7, 9, 9,10,10,12,12,13,13,12,12,10,
277  10, 9, 0,13,21, 0,13,13,14,14,15,15,16,16,18,18,19, 0,13,13,
278  14,14,15,15,16,16,18,18,19, 0,11,11,12,12,13,13, 0,11,11,12,
279  12,13,13, 0,10,10, 9, 9, 8, 8, 7, 7, 6, 6, 0,10,10, 9, 9, 8,
280  8, 7, 7, 6, 6, 0, 2, 4, 4, 7, 7, 9, 0} ;
281  padem->cd();
282  endc_m->SetStats(0);
283  endc_m->SetMaximum(14);
284  endc_m->SetMinimum(0);
285  endc_m->Draw("colz");
286  for ( int i = 0; i < 132; i=i+1) {
287  if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
288  (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
289  l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
290  ixSectorsEE[i+1], iySectorsEE[i+1]);
291  }
292  }
293 
294  padep->cd();
295  endc_p->SetStats(0);
296  endc_p->SetMaximum(14);
297  endc_p->SetMinimum(0);
298  endc_p->Draw("colz");
299  for ( int i = 0; i < 132; i=i+1) {
300  if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
301  (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
302  l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
303  ixSectorsEE[i+1], iySectorsEE[i+1]);
304  }
305  }
306 
307  canvas.SaveAs(filename.c_str());
308  return filename;
309  }
310 }
311 
312 
313 namespace condPython {
314  template<>
316  using namespace boost::python;
317  enum_<cond::ecalcond::How>("How")
318  .value("singleChannel",cond::ecalcond::singleChannel)
319  .value("bySuperModule",cond::ecalcond::bySuperModule)
320  .value("all",cond::ecalcond::all)
321  ;
322 
324  class_<What>("What",init<>())
325  .def("set_how",&What::set_how)
326  .def("set_which",&What::set_which)
327  .def("how",&What::how, return_value_policy<copy_const_reference>())
328  .def("which",&What::which, return_value_policy<copy_const_reference>())
329  ;
330  }
331 }
332 
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)
def which
Definition: eostools.py:335
static ecalcond::CondExtractor & extractor(ecalcond::How how)
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
def canvas
Definition: svgfig.py:481
int bad(Items const &cont)
T x() const
Cartesian x coordinate.
std::string summary() const
int ix() const
Definition: EcalScDetId.h:71
tuple result
Definition: query.py:137
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
#define end
Definition: vmac.h:37
Container::value_type value_type
void swap(std::vector< float > &v)
type_vValues getValues(const std::vector< EcalObject > &vItems) override
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
static std::string dumpXML(const EcalCondHeader &header, const EcalDCSTowerStatus &record)
void extractBarrel(Container const &cont, std::vector< int > const &, std::vector< float > &result)
std::string dump() const
std::vector< int > const & which() 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)