CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalDAQTowerStatusPyWrapper.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 "TLine.h"
11 
14 
15 #include <string>
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 
25 #include <fstream>
26 
27 namespace cond {
28 
29  namespace ecalcond {
30 
33 
35 
36  int bad(Items const & cont) {
37  return std::count_if(cont.begin(),cont.end(),
38  boost::bind(std::greater<int>(),
39  boost::bind(&value_type::getStatusCode,_1),0)
40  );
41  }
42 
43  void extractBarrel(EcalDAQTowerStatus const & cont, std::vector<int> const &, std::vector<float> & result) {
44  result.resize(1);
45  result[0] = bad(cont.barrelItems());
46  }
47 
48  void extractEndcap(EcalDAQTowerStatus const & cont, std::vector<int> const &, std::vector<float> & result) {
49  result.resize(1);
50  result[0] = bad(cont.endcapItems());
51  }
52  void extractAll(EcalDAQTowerStatus const & cont, std::vector<int> const &, std::vector<float> & result) {
53  result.resize(1);
54  result[0] = bad(cont.barrelItems())+bad(cont.endcapItems());
55  }
56 
57  void extractSuperModules(EcalDAQTowerStatus const & cont, std::vector<int> const & which, std::vector<float> & result) {
58  // bho...
59  }
60 
61  void extractSingleChannel(EcalDAQTowerStatus const & cont, std::vector<int> const & which, std::vector<float> & result) {
62  result.reserve(which.size());
63  for (unsigned int i=0; i<which.size();i++) {
64  result.push_back(cont[which[i]].getStatusCode());
65  }
66  }
67 
68  typedef boost::function<void(EcalDAQTowerStatus const & cont, std::vector<int> const & which, std::vector<float> & result)> CondExtractor;
69  } // namespace ecalcond
70 
71  template<>
73 
75  std::vector<int> m_which;
76 
77  ecalcond::How const & how() const { return m_how;}
78  std::vector<int> const & which() const { return m_which;}
79 
80  void set_how(ecalcond::How i) {m_how=i;}
81  void set_which(std::vector<int> & i) { m_which.swap(i);}
82  };
83 
84 
85  template<>
86  class ValueExtractor<EcalDAQTowerStatus>: public BaseValueExtractor<EcalDAQTowerStatus> {
87  public:
88 
90  static ecalcond::CondExtractor fun[3] = {
94  };
95  return fun[how];
96  }
97 
100  static What what() { return What();}
101 
104  : m_what(what)
105  {
106  // here one can make stuff really complicated...
107  }
108 
109  void compute(Class const & it){
110  std::vector<float> res;
111  extractor(m_what.how())(it,m_what.which(),res);
112  swap(res);
113  }
114 
115  private:
117  };
118 
119 
120  template<>
122  std::stringstream ss;
125  return ss.str();
126  }
127 
128  template<>
130  std::cout << "***************************************"<< std::endl;
131  std::stringstream ss;
132  ss << "sizes="
133  << object().barrelItems().size() <<","
134  << object().endcapItems().size() <<";";
135  ss << std::endl;
136  return ss.str();
137  }
138 
139 
140  // return the real name of the file including extension...
141  template<>
142  std::string PayLoadInspector<EcalDAQTowerStatus>::plot(std::string const & filename,
143  std::string const &,
144  std::vector<int> const&,
145  std::vector<float> const& ) const {
146  // std::string fname = filename + ".txt";
147  // EcalDAQTowerStatusXMLTranslator::plot(fname, object());
148  // return fname;
149  TCanvas canvas("CC map","CC map",800,800);
150  TPad* padb = new TPad("padb","padb", 0., 0.55, 1., 1.);
151  padb->Draw();
152  TPad* padem = new TPad("padem","padem", 0., 0., 0.45, 0.45);
153  padem->Draw();
154  TPad* padep = new TPad("padep","padep", 0.55, 0., 1., 0.45);
155  padep->Draw();
156 
157  TH2F* barrel = new TH2F("EB","EB Tower Status", 72, 0, 72, 34, -17, 17);
158  TH2F* endc_p = new TH2F("EE+","EE+ Tower Status",22, 0, 22, 22, 0, 22);
159  TH2F* endc_m = new TH2F("EE-","EE- Tower Status",22, 0, 22, 22, 0, 22);
160  for(uint cellid = 0;
162  ++cellid) {
164  if (object().find(rawid) == object().end()) continue;
165  int ieta = rawid.ieta();
166  if(ieta > 0) ieta--; // 1 to 17
167  int iphi = rawid.iphi() - 1; // 0 to 71
168  barrel->Fill(iphi, ieta, object()[rawid].getStatusCode());
169  }
170  for(uint cellid = 0;
172  ++cellid) {
173  if(EcalScDetId::validHashIndex(cellid)) {
174  EcalScDetId rawid = EcalScDetId::unhashIndex(cellid);
175  int ix = rawid.ix(); // 1 to 20
176  int iy = rawid.iy(); // 1 to 20
177  int side = rawid.zside();
178  if(side == -1)
179  endc_m->Fill(ix, iy, object()[rawid].getStatusCode());
180  else
181  endc_p->Fill(ix, iy, object()[rawid].getStatusCode());
182  }
183  }
184  TLine* l = new TLine(0., 0., 0., 0.);
185  l->SetLineWidth(1);
186  padb->cd();
187  barrel->SetStats(0);
188  // barrel->SetMaximum(14);
189  // barrel->SetMinimum(0);
190  // barrel->Draw("colz");
191  barrel->Draw("col");
192  for(int i = 0; i <17; i++) {
193  Double_t x = 4.+ (i * 4);
194  l = new TLine(x, -17., x, 17.);
195  l->Draw();
196  }
197  l = new TLine(0., 0., 72., 0.);
198  l->Draw();
199 
200  int ixSectorsEE[136] = {
201  8,14,14,17,17,18,18,19,19,20,20,21,21,20,20,19,19,18,18,17,
202  17,14,14, 8, 8, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 2, 2, 3, 3, 4,
203  4, 5, 5, 8, 8, 8, 9, 9,10,10,12,12,13,13,12,12,10,10, 9, 9,
204  10,10, 0,11,11, 0,10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 0,12,13,
205  13,14,14,15,15,16,16,17,17, 0, 9, 8, 8, 3, 3, 1, 0,13,14,14,
206  19,19,21, 0, 9, 8, 8, 7, 7, 5, 5, 3, 3, 2, 0,13,14,14,15,15,
207  17,17,19,19,20, 0,14,14,13,13,12,12,0};
208  int iySectorsEE[136] = {
209  1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 8, 8,14,14,17,17,18,18,19,19,
210  20,20,21,21,20,20,19,19,18,18,17,17,14,14, 8, 8, 5, 5, 4, 4,
211  3, 3, 2, 2, 1, 4, 4, 7, 7, 9, 9,10,10,12,12,13,13,12,12,10,
212  10, 9, 0,13,21, 0,13,13,14,14,15,15,16,16,18,18,19, 0,13,13,
213  14,14,15,15,16,16,18,18,19, 0,11,11,12,12,13,13, 0,11,11,12,
214  12,13,13, 0,10,10, 9, 9, 8, 8, 7, 7, 6, 6, 0,10,10, 9, 9, 8,
215  8, 7, 7, 6, 6, 0, 2, 4, 4, 7, 7, 9, 0} ;
216  padem->cd();
217  endc_m->SetStats(0);
218  endc_m->Draw("col");
219  for ( int i = 0; i < 136; i=i+1) {
220  if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
221  (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
222  l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
223  ixSectorsEE[i+1], iySectorsEE[i+1]);
224  }
225  }
226 
227  padep->cd();
228  endc_p->SetStats(0);
229  endc_p->Draw("col");
230  for ( int i = 0; i < 136; i=i+1) {
231  if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
232  (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
233  l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
234  ixSectorsEE[i+1], iySectorsEE[i+1]);
235  }
236  }
237 
238  canvas.SaveAs(filename.c_str());
239  return filename;
240  }
241 }
242 
243 
244 namespace condPython {
245  template<>
247  using namespace boost::python;
248  enum_<cond::ecalcond::How>("How")
249  .value("singleChannel",cond::ecalcond::singleChannel)
250  .value("bySuperModule",cond::ecalcond::bySuperModule)
251  .value("all",cond::ecalcond::all)
252  ;
253 
255  class_<What>("What",init<>())
256  .def("set_how",&What::set_how)
257  .def("set_which",&What::set_which)
258  .def("how",&What::how, return_value_policy<copy_const_reference>())
259  .def("which",&What::which, return_value_policy<copy_const_reference>())
260  ;
261  }
262 }
263 
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)
boost::function< void(Container const &cont, std::vector< int > const &which, std::vector< float > &result)> CondExtractor
std::string plot(std::string const &, std::string const &, std::vector< int > const &, std::vector< float > const &) const
ExtractWhat< Class > What
static EcalScDetId unhashIndex(int hi)
Definition: EcalScDetId.h:119
#define PYTHON_WRAPPER(_class, _name)
Container::value_type value_type
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)
std::string summary() const
int ix() const
Definition: EcalScDetId.h:72
tuple result
Definition: query.py:137
std::vector< int > const & which() const
#define end
Definition: vmac.h:38
void swap(std::vector< float > &v)
int iy() const
Definition: EcalScDetId.h:78
int iphi() const
get the tower iphi
int zside() const
Definition: EcalScDetId.h:66
int cont
list object
Definition: dbtoconf.py:77
static bool validHashIndex(int hi)
Definition: EcalScDetId.h:141
void extractSingleChannel(Container const &cont, std::vector< int > const &which, std::vector< float > &result)
static std::string dumpXML(const EcalCondHeader &header, const EcalDAQTowerStatus &record)
tuple filename
Definition: lut2db_cfg.py:20
tuple cout
Definition: gather_cfg.py:41
void extractBarrel(Container const &cont, std::vector< int > const &, std::vector< float > &result)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
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 ecalcond::CondExtractor & extractor(ecalcond::How how)