CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalPedestalsPyWrapper.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<HcalPedestals>: public BaseValueExtractor<HcalPedestals> {
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  HcalPedestals::tAllContWithNames::const_iterator iter;
62  std::vector<HcalPedestal>::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  value = (*contIter).getValue(id);
83  //logstatus = log2(1.*channelBits)+1;
84 
85  //FILLING GOES HERE:
86  graphData[depth-1].Fill(ieta,iphi, value);
87  }
88  }
89  }
90  };
91 
92  template<>
94  std::stringstream ss;
95  unsigned int totalValues = 8;
96  // get all containers with names
97  HcalPedestals::tAllContWithNames allContainers = object().getAllContainers();
98 
99  // initializing iterators
100  HcalPedestals::tAllContWithNames::const_iterator iter;
101  std::vector<HcalPedestal>::const_iterator contIter;
102 
103  ss << "Total HCAL containers: " << allContainers.size() << std::endl;
104 
105  typedef std::pair<std::pair< std::vector<float>, std::vector<float> >, int> tPora;
106 
107  std::vector<tPora> vec(allContainers.size());
108 
109  std::vector<tPora>::iterator iMaz = vec.begin();
110 
111  float sum = 0.0, average = 0.0, std_dev = 0.0, sqr_sum = 0.0;
112  int size = 0;
113 
114  //Run trough all 8 detector containers:
115  for (iter = allContainers.begin(), iMaz = vec.begin(); iter != allContainers.end(); ++iter, ++iMaz){
116  ss << "---------------------------------------------" << std::endl;
117  ss << "Detector: " << (*iter).first << "; Total values: "<< (*iter).second.size() << std::endl;
118  unsigned int j = 0;
119  iMaz->second = (*iter).second.size();
120  (iMaz->first).first = std::vector<float>(totalValues, 0.0);
121  (iMaz->first).second = std::vector<float>(totalValues, 0.0);
122  float capValue = 0.0;
123  //Run trough all values in container
124  for (contIter = (*iter).second.begin(); contIter != (*iter).second.end(); ++contIter){
125 
126  //Run trough all values (8) in object:
127  for (unsigned int i = 0; i < totalValues; ++i){
128  capValue = (*contIter).getValue(i);
129  (iMaz->first).first[i] += capValue;
130  (iMaz->first).second[i]+= (capValue * capValue);
131  //ss << "[" << i << "] " << capValue << ", " << (iMaz->first).first[i] << ", " << (iMaz->first).second[i] << "; ";
132  }
133  //ss << std::endl;
134  ++j;
135  }
136 
137  size = (*iMaz).second;
138  for (unsigned int i = 0; i < totalValues; ++i){
139  sum = ((*iMaz).first).first[i];
140  sqr_sum = ((*iMaz).first).second[i];
141  average = sum/size;
142  std_dev = sqrt( (sqr_sum/size) - (average * average) );
143  if (i >= 4){
144  ss << " PedestalWidth " << (i - 4) << " :"<< std::endl;
145  ss << " Average: " << average << "; "<< std::endl;
146  ss << " Standart deviation: " << std_dev << "; " << std::endl;
147  }
148  else {
149  ss << " Pedestal " << i << " :"<< std::endl;
150  ss << " Average: " << average << "; "<< std::endl;
151  ss << " Standart deviation: " << std_dev << "; " << std::endl;
152  }
153  }
154  }
155  //std::cout << ss.str();
156  return ss.str();
157  }
158 
159  template<>
161  std::string const &,
162  std::vector<int> const&,
163  std::vector<float> const& ) const
164  {
165 
166  //how much values are in container
167  unsigned int numOfValues = 8;
168 
169  //create object helper for making plots;
170  HcalPedestalsDataRepr datarepr(numOfValues, object().getAllContainers());
171 
172  datarepr.nr = 0;
173  datarepr.id = 0;
174  datarepr.rootname.str("_Pedestalrootvalue_");
175  datarepr.plotname.str("PedestalValue ");
176  datarepr.filename.str("");
177  datarepr.filename << filename << "_Pedestal_";
178 
179  typedef std::vector<TH2F> graphData;
180  std::vector< graphData > graphDataVec(numOfValues);
181  std::vector< graphData >::iterator imageIter;
182 
183  //create images:
184  for (imageIter = graphDataVec.begin(); imageIter != graphDataVec.end(); ++imageIter){
185  if (datarepr.nr == 4){
186  datarepr.nr = 0;
187  datarepr.rootname.str("_PedestalWidthrootname_");
188  datarepr.plotname.str("PedestalWidth ");
189  datarepr.filename.str("");
190  datarepr.filename << filename << "_PedestalWidth_";
191  }
192  //MAIN FUNCTION:
193  datarepr.fillOneGain((*imageIter));
194 
195  ++(datarepr.nr);
196  ++(datarepr.id);
197  }
198  return filename;
199  }
200 }
int i
Definition: DBlmapReader.cc:9
#define PYTHON_WRAPPER(_class, _name)
HcalPedestalsDataRepr(unsigned int total, HcalPedestals::tAllContWithNames const &allCont)
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:48
HcalPedestals::tAllContWithNames allContainers
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
void doFillIn(std::vector< TH2F > &graphData)
tuple size
Write out results.