CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalLutMetadataPyWrapper.cc
Go to the documentation of this file.
3 
6 
7 #include <string>
8 #include <fstream>
9 #include <sstream>
10 
11 #include "TH1F.h"
12 #include "TH2F.h"
15 
16 #include "TROOT.h"
17 #include "TCanvas.h"
18 #include "TStyle.h"
19 #include "TColor.h"
20 #include "TLine.h"
21 
22 #include "math.h"
23 //functions for correct representation of data in summary and plot:
25 using namespace HcalObjRepresent;
26 
27 namespace cond {
28  template<>
29  class ValueExtractor<HcalLutMetadata>: public BaseValueExtractor<HcalLutMetadata> {
30  public:
33  static What what() { return What();}
34 
36 
37  ValueExtractor(What const & what)
38  {
39  // here one can make stuff really complicated...
40  }
41 
42  void compute(Class const & it){
43  }
44  private:
45 
46  };
47 
49  {
50  public:
52  :ADataRepr(total), allContainers(allCont){}
53 
54 
55 
56  protected:
58 
59  void doFillIn(std::vector<TH2F> &graphData){
60  //ITERATORS AND VALUES:
61  HcalLutMetadata::tAllContWithNames::const_iterator iter;
62  std::vector<HcalLutMetadatum>::const_iterator contIter;
63  float value = 0.0;
64 
65  //run trough all pair containers
66  for (iter = allContainers.begin(); iter != allContainers.end(); ++iter){
67  //Run trough all values:
68  for (contIter = (*iter).second.begin(); contIter != (*iter).second.end(); ++contIter){
69  hcal_id = HcalDetId((uint32_t)(*contIter).rawId());
70 
71  depth = hcal_id.depth();
72  if (depth<1 || depth>4)
73  continue;
74 
75  ieta=hcal_id.ieta();
76  iphi=hcal_id.iphi();
77 
78  if (hcal_id.subdet() == HcalForward)
79  ieta>0 ? ++ieta : --ieta;
80 
81  //GET VALUE:
82  switch(id){
83  case 0:
84  value = (*contIter).getRCalib();
85  break;
86  case 1:
87  value = (*contIter).getLutGranularity();
88  break;
89  case 2:
90  value = (*contIter).getOutputLutThreshold();
91  break;
92  default:
93  throw("Trying to access not existing value!");
94 
95  }
96  //value = (*contIter).getValue(id);
97  //logstatus = log2(1.*channelBits)+1;
98 
99  //FILLING GOES HERE:
100  graphData[depth-1].Fill(ieta,iphi, value);
101  }
102  }
103  }
104  };
105 
106  template<>
108  std::stringstream ss;
109 
110  unsigned int totalValues = 3;
111 
112  // get all containers with names
113  HcalLutMetadata::tAllContWithNames allContainers = object().getAllContainers();
114 
115  // initializing iterators
116  HcalLutMetadata::tAllContWithNames::const_iterator iter;
117  std::vector<HcalLutMetadatum>::const_iterator contIter;
118 
119  ss << "Total HCAL containers: " << allContainers.size() << std::endl;
120 
121  typedef std::pair<std::pair< std::vector<float>, std::vector<float> >, int> tPora;
122 
123  std::vector<tPora> vec(allContainers.size());
124 
125  std::vector<tPora>::iterator iMaz = vec.begin();
126 
127  float sum = 0.0, average = 0.0, std_dev = 0.0, sqr_sum = 0.0;
128  int size = 0;
129 
130  //Run trough all 8 detector containers:
131  for (iter = allContainers.begin(), iMaz = vec.begin(); iter != allContainers.end(); ++iter, ++iMaz){
132  ss << "---------------------------------------------" << std::endl;
133  ss << "Detector: " << (*iter).first << "; Total values: "<< (*iter).second.size() << std::endl;
134  unsigned int j = 0;
135  iMaz->second = (*iter).second.size();
136  (iMaz->first).first = std::vector<float>(totalValues, 0.0);
137  (iMaz->first).second = std::vector<float>(totalValues, 0.0);
138  float capValue = 0.0;
139  //Run trough all values in container
140  for (contIter = (*iter).second.begin(); contIter != (*iter).second.end(); ++contIter){
141 
142  //Run trough all values in object:
143  for (unsigned int i = 0; i < totalValues; ++i){
144 
145  //GET VALUE:
146  switch(i){
147  case 0:
148  capValue = (*contIter).getRCalib();
149  break;
150  case 1:
151  capValue = (*contIter).getLutGranularity();
152  break;
153  case 2:
154  capValue = (*contIter).getOutputLutThreshold();
155  break;
156  default:
157  throw("Trying to access not existing value!");
158  }
159 
160  //capValue = (*contIter).getValue(i);
161  (iMaz->first).first[i] += capValue;
162  (iMaz->first).second[i]+= (capValue * capValue);
163  //ss << "[" << i << "] " << capValue << ", " << (iMaz->first).first[i] << ", " << (iMaz->first).second[i] << "; ";
164  }
165  //ss << std::endl;
166  ++j;
167  }
168 
169  size = (*iMaz).second;
170  for (unsigned int i = 0; i < totalValues; ++i){
171  sum = ((*iMaz).first).first[i];
172  sqr_sum = ((*iMaz).first).second[i];
173  average = sum/size;
174  //here needs to take absolute value for sqrt:
175  std_dev = sqrt( fabs((sqr_sum / size) - (average * average)) );
176 
177  switch(i){
178  case 0:
179  ss << " LutMetadata RecHit calibration:"<< std::endl;
180  break;
181  case 1:
182  ss << " LutMetadata LUT granularity:"<< std::endl;
183  break;
184  case 2:
185  ss << " LutMetadata output LUT threshold :"<< std::endl;
186  break;
187  default:
188  throw("Trying to access not existing value!");
189  }
190 
191  ss << " Average: " << average << "; "<< std::endl;
192  ss << " Standart deviation: " << std_dev << "; " << std::endl;
193  }
194  }
195  //std::cout << ss.str();
196  return ss.str();
197  }
198 
199  template<>
200  std::string PayLoadInspector<HcalLutMetadata>::plot(std::string const & filename,
201  std::string const &,
202  std::vector<int> const&,
203  std::vector<float> const& ) const
204  {
205 
206  //how much values are in container
207  unsigned int numOfValues = 3;
208 
209  //create object helper for making plots;
210  HcalLutMetadataDataRepr datarepr(numOfValues, object().getAllContainers());
211 
212  datarepr.nr = 0;
213  datarepr.id = 0;
214  datarepr.rootname.str("_LutMetadatumrootvalue_");
215  datarepr.plotname.str("LutMetadatumValue ");
216  datarepr.filename.str("");
217  datarepr.filename << filename << "_LutMetadatum_";
218 
219  typedef std::vector<TH2F> graphData;
220  std::vector< graphData > graphDataVec(numOfValues);
221  std::vector< graphData >::iterator imageIter;
222  //create images:
223  for (imageIter = graphDataVec.begin(); imageIter != graphDataVec.end(); ++imageIter){
224  switch(datarepr.id){
225  case 0:
226  datarepr.rootname.str("_RCalibrootvalue_");
227  datarepr.plotname.str("RCalib ");
228  datarepr.filename.str("");
229  datarepr.filename << filename << "_RCalib_";
230  break;
231  case 1:
232  datarepr.rootname.str("_LutGranularityrootvalue_");
233  datarepr.plotname.str("LutGranularity ");
234  datarepr.filename.str("");
235  datarepr.filename << filename << "_LutGranularity_";
236  break;
237  case 2:
238  datarepr.rootname.str("_OutputLutThresholdrootvalue_");
239  datarepr.plotname.str("OutputLutThreshold ");
240  datarepr.filename.str("");
241  datarepr.filename << filename << "_OutputLutThreshold_";
242  break;
243  default:
244  throw("Trying to access not existing value!");
245  }
246  //MAIN FUNCTION:
247  datarepr.fillOneGain((*imageIter));
248 
249  //++(datarepr.nr);
250  ++(datarepr.id);
251  }
252  return filename;
253  }
254 }
int i
Definition: DBlmapReader.cc:9
void doFillIn(std::vector< TH2F > &graphData)
#define PYTHON_WRAPPER(_class, _name)
U second(std::pair< T, U > const &p)
int depth() const
get the tower depth
Definition: HcalDetId.h:42
T sqrt(T t)
Definition: SSEVec.h:46
int j
Definition: DBlmapReader.cc:9
void fillOneGain(std::vector< TH2F > &graphData, std::string units="")
bool first
Definition: L1TdeRCT.cc:94
int average
Definition: PDRates.py:137
list object
Definition: dbtoconf.py:77
tuple filename
Definition: lut2db_cfg.py:20
HcalLutMetadata::tAllContWithNames allContainers
HcalLutMetadataDataRepr(unsigned int total, HcalLutMetadata::tAllContWithNames const &allCont)
tuple size
Write out results.