CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalChannelQualityPyWrapper.cc
Go to the documentation of this file.
4 
5 #include <string>
6 #include <fstream>
7 #include <sstream>
8 
9 #include "TH1F.h"
10 #include "TH2F.h"
13 
14 #include "TROOT.h"
15 #include "TCanvas.h"
16 #include "TStyle.h"
17 #include "TColor.h"
18 #include "TLine.h"
19 
20 
21 //functions for correct representation of data in summary and plot:
23 using namespace HcalObjRepresent;
24 
25 namespace cond {
26 
27  template<>
28  class ValueExtractor<HcalChannelQuality>: public BaseValueExtractor<HcalChannelQuality> {
29  public:
32  static What what() { return What();}
33 
35 
36  ValueExtractor(What const & what)
37  {
38  // here one can make stuff really complicated...
39  }
40 
41  void compute(Class const & it){
42  }
43  private:
44 
45  };
46 
47  template<>
49  std::stringstream ss;
50 
51  //setting map for representing errors
52  std::string statusBitArray[20];
53  short unsigned int bitMap[9];
54  statusBitArray[0] = std::string("cell is off" );
55  statusBitArray[1] = std::string("cell is masked/to be masked at RecHit Level" );
56  statusBitArray[5] = std::string("cell is dead (from DQM algo)");
57  statusBitArray[6] = std::string("cell is hot (from DQM algo)" );
58  statusBitArray[7] = std::string("cell has stability error");
59  statusBitArray[8] = std::string("cell has timing error" );
60  statusBitArray[15] = std::string("cell is masked from the Trigger ");
61  statusBitArray[18] = std::string("cell is always excluded from the CaloTower regardless of other bit settings.");
62  statusBitArray[19] = std::string("cell is counted as problematic within the tower.");
63  bitMap[0] = 0; //{0, 1, 5, 6, 7, 8, 15, 18, 19};
64  bitMap[1] = 1;
65  bitMap[2] = 5;
66  bitMap[3] = 6;
67  bitMap[4] = 7;
68  bitMap[5] = 8;
69  bitMap[6] = 15;
70  bitMap[7] = 18;
71  bitMap[8] = 19;
72 
73  // get all containers with names
74  HcalChannelQuality::tAllContWithNames allContainers = object().getAllContainers();
75 
76  // initializing iterators
77  HcalChannelQuality::tAllContWithNames::const_iterator iter;
78  std::vector<HcalChannelStatus>::const_iterator contIter;
79  ss << "Total HCAL containers: " << allContainers.size() << std::endl;
80 
81  //run trough all pair containers, print error values if any.
82  for (iter = allContainers.begin(); iter != allContainers.end(); ++iter){
83  ss << "---------------------------------------------" << std::endl;
84  ss << "Detector: " << (*iter).first << "; Total values: "<< (*iter).second.size() << std::endl;
85  unsigned int j = 0;
86  for (contIter = (*iter).second.begin(); contIter != (*iter).second.end(); ++contIter){
87 
88  //if not 0, it have error, print it:
89  if ((*contIter).getValue() != 0){//HcalDetId::HcalDetId(uint32_t rawid)
90  ss << " Id["<< j << "]: " <<
91  " rawId: " << (uint32_t)(*contIter).rawId() << " "<< HcalDetId((uint32_t)(*contIter).rawId())<<"; Channel bits: " <<
92  (uint32_t)(*contIter).getValue()<< "; Binary format: " << IntToBinary((uint32_t)(*contIter).getValue()) << "; Errors: "
93  << getBitsSummary((uint32_t)((*contIter).getValue()), statusBitArray, bitMap);
94  }
95  ++j;
96  }
97  }
98  return ss.str();
99  }
100 
101  template<>
102  std::string PayLoadInspector<HcalChannelQuality>::plot(std::string const & filename,//
103  std::string const &,
104  std::vector<int> const&,
105  std::vector<float> const& ) const
106  {
107  std::vector<TH2F> graphData;
108  setup(graphData, "ChannelStatus");
109 
110  std::stringstream x;
111  // Change the titles of each individual histogram
112  for (unsigned int d=0;d < graphData.size();++d){
113  graphData[d].Reset();
114  x << "1+log2(status) for HCAL depth " << d+1;
115 
116  //BUG CAN BE HERE:
117  //if (ChannelStatus->depth[d])
118  graphData[d].SetTitle(x.str().c_str()); // replace "setTitle" with "SetTitle", since you are using TH2F objects instead of MonitorElements
119  x.str("");
120  }
121 
122  HcalDetId hcal_id;
123  int ieta, depth, iphi, channelBits;
124  double logstatus;
125 
126  //main loop
127  // get all containers with names
128  HcalChannelQuality::tAllContWithNames allContainers = object().getAllContainers();
129 
130  // initializing iterators
131  HcalChannelQuality::tAllContWithNames::const_iterator iter;
132  std::vector<HcalChannelStatus>::const_iterator contIter;
133 
134  //run trough all pair containers
135  for (iter = allContainers.begin(); iter != allContainers.end(); ++iter){
136  for (contIter = (*iter).second.begin(); contIter != (*iter).second.end(); ++contIter){
137  hcal_id = HcalDetId((uint32_t)(*contIter).rawId());
138 
139  channelBits = (uint32_t)(*contIter).getValue();
140  if (channelBits == 0)
141  continue;
142 
143  depth = hcal_id.depth();
144  if (depth<1 || depth>4)
145  continue;
146 
147  ieta=hcal_id.ieta();
148  iphi=hcal_id.iphi();
149 
150  if (hcal_id.subdet() == HcalForward)
151  ieta>0 ? ++ieta : --ieta;
152 
153  logstatus = log2(1.*channelBits)+1;
154  //FILLING GOES HERE:
155  graphData[depth-1].Fill(ieta,iphi,logstatus);
156 
157  //FOR DEBUGGING:
158  //std::cout << "ieta: " << ieta << "; iphi: " << iphi << "; logstatus: " << logstatus << "; channelBits: " << channelBits<< std::endl;
159  }
160  }
161  FillUnphysicalHEHFBins(graphData);
162 
163 
164 
165  //Drawing...
166  // use David's palette
167  gStyle->SetPalette(1);
168  const Int_t NCont = 999;
169  gStyle->SetNumberContours(NCont);
170  TCanvas canvas("CC map","CC map",840,369*4);
171 
172  TPad pad1("pad1","pad1", 0.0, 0.75, 1.0, 1.0);
173  pad1.Draw();
174  TPad pad2("pad2","pad2", 0.0, 0.5, 1.0, 0.75);
175  pad2.Draw();
176  TPad pad3("pad3","pad3", 0.0, 0.25, 1.0, 0.5);
177  pad3.Draw();
178  TPad pad4("pad4","pad4", 0.0, 0.0, 1.0, 0.25);
179  pad4.Draw();
180 
181 
182  pad1.cd();
183  graphData[0].SetStats(0);
184  graphData[0].Draw("colz");
185 
186  pad2.cd();
187  graphData[1].SetStats(0);
188  graphData[1].Draw("colz");
189 
190  pad3.cd();
191  graphData[2].SetStats(0);
192  graphData[2].Draw("colz");
193 
194  pad4.cd();
195  graphData[3].SetStats(0);
196  graphData[3].Draw("colz");
197 
198 
199  std::stringstream ss;
200  ss <<filename << ".png";
201 
202  canvas.SaveAs((ss.str()).c_str());
203 
204  return (ss.str()).c_str();
205  }
206 
207 
208 }
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:32
std::string getBitsSummary(uint32_t bits, std::string statusBitArray[], short unsigned int bitMap[])
#define PYTHON_WRAPPER(_class, _name)
std::string IntToBinary(unsigned int number)
def canvas
Definition: svgfig.py:481
int depth() const
get the tower depth
Definition: HcalDetId.h:42
int ieta() const
get the cell ieta
Definition: HcalDetId.h:38
int j
Definition: DBlmapReader.cc:9
int iphi() const
get the cell iphi
Definition: HcalDetId.h:40
void FillUnphysicalHEHFBins(std::vector< TH2F > &hh)
list object
Definition: dbtoconf.py:77
tuple filename
Definition: lut2db_cfg.py:20
x
Definition: VDTMath.h:216
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")