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 
28 
29 namespace cond {
30 
31  namespace ecalcond {
32 
35 
37 
38  int bad(Items const & cont) {
39  return std::count_if(cont.begin(),cont.end(),
40  boost::bind(std::greater<int>(),
41  boost::bind(&value_type::getStatusCode,_1),0)
42  );
43  }
44 
45  void extractBarrel(EcalDAQTowerStatus const & cont, std::vector<int> const &, std::vector<float> & result) {
46  result.resize(1);
47  result[0] = bad(cont.barrelItems());
48  }
49 
50  void extractEndcap(EcalDAQTowerStatus const & cont, std::vector<int> const &, std::vector<float> & result) {
51  result.resize(1);
52  result[0] = bad(cont.endcapItems());
53  }
54  void extractAll(EcalDAQTowerStatus const & cont, std::vector<int> const &, std::vector<float> & result) {
55  result.resize(1);
56  result[0] = bad(cont.barrelItems())+bad(cont.endcapItems());
57  }
58 
59  void extractSuperModules(EcalDAQTowerStatus const & cont, std::vector<int> const & which, std::vector<float> & result) {
60  // bho...
61  }
62 
63  void extractSingleChannel(EcalDAQTowerStatus const & cont, std::vector<int> const & which, std::vector<float> & result) {
64  result.reserve(which.size());
65  for (unsigned int i=0; i<which.size();i++) {
66  result.push_back(cont[which[i]].getStatusCode());
67  }
68  }
69 
70  typedef boost::function<void(EcalDAQTowerStatus const & cont, std::vector<int> const & which, std::vector<float> & result)> CondExtractor;
71  } // namespace ecalcond
72 
73  template<>
75 
77  std::vector<int> m_which;
78 
79  ecalcond::How const & how() const { return m_how;}
80  std::vector<int> const & which() const { return m_which;}
81 
82  void set_how(ecalcond::How i) {m_how=i;}
83  void set_which(std::vector<int> & i) { m_which.swap(i);}
84  };
85 
86 
87  template<>
88  class ValueExtractor<EcalDAQTowerStatus>: public BaseValueExtractor<EcalDAQTowerStatus> {
89  public:
90 
92  static ecalcond::CondExtractor fun[3] = {
96  };
97  return fun[how];
98  }
99 
102  static What what() { return What();}
103 
106  : m_what(what)
107  {
108  // here one can make stuff really complicated...
109  }
110 
111  void compute(Class const & it){
112  std::vector<float> res;
113  extractor(m_what.how())(it,m_what.which(),res);
114  swap(res);
115  }
116 
117  private:
119  };
120 
121 
122  template<>
124  std::stringstream ss;
127  return ss.str();
128  }
129 
130  class EcalDAQTowerStatusHelper: public EcalPyWrapperHelper<EcalDAQStatusCode>{
131  public:
132  //change me
134  protected:
135 
136  //change me
138 
139  type_vValues getValues( const std::vector<EcalObject> & vItems)
140  {
141  type_vValues vValues(total_values);
142 
143  //change us
144  vValues[0].first = "bit 0 -> towers excluded from the DAQ";
145 
146  vValues[0].second = .0;
147 
148  //get info:
149  for(std::vector<EcalObject>::const_iterator iItems = vItems.begin(); iItems != vItems.end(); ++iItems){
150  //change us
151  vValues[0].second += iItems->getStatusCode();
152  }
153  return vValues;
154  }
155  };
156 
157  template<>
159  std::stringstream ss;
161  ss << helper.printBarrelsEndcaps(object().barrelItems(), object().endcapItems());
162  return ss.str();
163  }
164 
165 
166  // return the real name of the file including extension...
167  template<>
168  std::string PayLoadInspector<EcalDAQTowerStatus>::plot(std::string const & filename,
169  std::string const &,
170  std::vector<int> const&,
171  std::vector<float> const& ) const {
172  // std::string fname = filename + ".txt";
173  // EcalDAQTowerStatusXMLTranslator::plot(fname, object());
174  // return fname;
175  TCanvas canvas("CC map","CC map",800,800);
176  TPad* padb = new TPad("padb","padb", 0., 0.55, 1., 1.);
177  padb->Draw();
178  TPad* padem = new TPad("padem","padem", 0., 0., 0.45, 0.45);
179  padem->Draw();
180  TPad* padep = new TPad("padep","padep", 0.55, 0., 1., 0.45);
181  padep->Draw();
182 
183  TH2F* barrel = new TH2F("EB","EB Tower Status", 72, 0, 72, 34, -17, 17);
184  TH2F* endc_p = new TH2F("EE+","EE+ Tower Status",22, 0, 22, 22, 0, 22);
185  TH2F* endc_m = new TH2F("EE-","EE- Tower Status",22, 0, 22, 22, 0, 22);
186  for(uint cellid = 0;
188  ++cellid) {
190  if (object().find(rawid) == object().end()) continue;
191  int ieta = rawid.ieta();
192  if(ieta > 0) ieta--; // 1 to 17
193  int iphi = rawid.iphi() - 1; // 0 to 71
194  barrel->Fill(iphi, ieta, object()[rawid].getStatusCode());
195  }
196  for(uint cellid = 0;
198  ++cellid) {
199  if(EcalScDetId::validHashIndex(cellid)) {
200  EcalScDetId rawid = EcalScDetId::unhashIndex(cellid);
201  int ix = rawid.ix(); // 1 to 20
202  int iy = rawid.iy(); // 1 to 20
203  int side = rawid.zside();
204  if(side == -1)
205  endc_m->Fill(ix, iy, object()[rawid].getStatusCode());
206  else
207  endc_p->Fill(ix, iy, object()[rawid].getStatusCode());
208  }
209  }
210  TLine* l = new TLine(0., 0., 0., 0.);
211  l->SetLineWidth(1);
212  padb->cd();
213  barrel->SetStats(0);
214  // barrel->SetMaximum(14);
215  // barrel->SetMinimum(0);
216  // barrel->Draw("colz");
217  barrel->Draw("col");
218  for(int i = 0; i <17; i++) {
219  Double_t x = 4.+ (i * 4);
220  l = new TLine(x, -17., x, 17.);
221  l->Draw();
222  }
223  l = new TLine(0., 0., 72., 0.);
224  l->Draw();
225 
226  int ixSectorsEE[133] = {
227  8,14,14,17,17,18,18,19,19,20,20,21,21,20,20,19,19,18,18,17,
228  17,14,14, 8, 8, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 2, 2, 3, 3, 4,
229  4, 5, 5, 8, 8, 8, 9, 9,10,10,12,12,13,13,12,12,10,10, 9, 9,
230  10,10, 0,11,11, 0,10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5, 0,12,13,
231  13,14,14,15,15,16,16,17,17, 0, 9, 8, 8, 3, 3, 1, 0,13,14,14,
232  19,19,21, 0, 9, 8, 8, 7, 7, 5, 5, 3, 3, 2, 0,13,14,14,15,15,
233  17,17,19,19,20, 0,14,14,13,13,12,12,0};
234  int iySectorsEE[133] = {
235  1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 8, 8,14,14,17,17,18,18,19,19,
236  20,20,21,21,20,20,19,19,18,18,17,17,14,14, 8, 8, 5, 5, 4, 4,
237  3, 3, 2, 2, 1, 4, 4, 7, 7, 9, 9,10,10,12,12,13,13,12,12,10,
238  10, 9, 0,13,21, 0,13,13,14,14,15,15,16,16,18,18,19, 0,13,13,
239  14,14,15,15,16,16,18,18,19, 0,11,11,12,12,13,13, 0,11,11,12,
240  12,13,13, 0,10,10, 9, 9, 8, 8, 7, 7, 6, 6, 0,10,10, 9, 9, 8,
241  8, 7, 7, 6, 6, 0, 2, 4, 4, 7, 7, 9, 0} ;
242  padem->cd();
243  endc_m->SetStats(0);
244  endc_m->Draw("col");
245  for ( int i = 0; i < 132; i=i+1) {
246  if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
247  (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
248  l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
249  ixSectorsEE[i+1], iySectorsEE[i+1]);
250  }
251  }
252 
253  padep->cd();
254  endc_p->SetStats(0);
255  endc_p->Draw("col");
256  for ( int i = 0; i < 132; i=i+1) {
257  if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
258  (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
259  l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
260  ixSectorsEE[i+1], iySectorsEE[i+1]);
261  }
262  }
263 
264  canvas.SaveAs(filename.c_str());
265  return filename;
266  }
267 }
268 
269 
270 namespace condPython {
271  template<>
273  using namespace boost::python;
274  enum_<cond::ecalcond::How>("How")
275  .value("singleChannel",cond::ecalcond::singleChannel)
276  .value("bySuperModule",cond::ecalcond::bySuperModule)
277  .value("all",cond::ecalcond::all)
278  ;
279 
281  class_<What>("What",init<>())
282  .def("set_how",&What::set_how)
283  .def("set_which",&What::set_which)
284  .def("how",&What::how, return_value_policy<copy_const_reference>())
285  .def("which",&What::which, return_value_policy<copy_const_reference>())
286  ;
287  }
288 }
289 
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
ExtractWhat< Class > What
std::vector< std::pair< std::string, float > > type_vValues
boost::function< void(Container const &cont, std::vector< int > const &which, std::vector< float > &result)> CondExtractor
static EcalScDetId unhashIndex(int hi)
Definition: EcalScDetId.h:119
#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)
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
Container::value_type value_type
void swap(std::vector< float > &v)
int iy() const
Definition: EcalScDetId.h:78
int iphi() const
get the tower iphi
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
int zside() const
Definition: EcalScDetId.h:66
int cont
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)
std::string printBarrelsEndcaps(const std::vector< T > &barrelItems, const std::vector< T > &endcapItems)
tuple filename
Definition: lut2db_cfg.py:20
type_vValues getValues(const std::vector< EcalObject > &vItems)
void extractBarrel(Container const &cont, std::vector< int > const &, std::vector< float > &result)
x
Definition: VDTMath.h:216
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)