CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalQIEDataPyWrapper.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<HcalQIEData>: public BaseValueExtractor<HcalQIEData> {
30  public:
31  typedef HcalQIEData Class;
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  protected:
52  public:
53  unsigned int fCapId;
54  unsigned int fRange;
56 
58  :ADataRepr(total), allContainers(allCont), fCapId(0), fRange(0), slopeOrOffset(false){}
59 
60 
61 
62 
63  protected:
64  void doFillIn(std::vector<TH2F> &graphData){
65  //ITERATORS AND VALUES:
66  HcalQIEData::tAllContWithNames::const_iterator iter;
67  std::vector<HcalQIECoder>::const_iterator contIter;
68  float value = 0.0;
69 
70  //run trough all pair containers
71  for (iter = allContainers.begin(); iter != allContainers.end(); ++iter){
72  //Run trough all values:
73  for (contIter = (*iter).second.begin(); contIter != (*iter).second.end(); ++contIter){
74  hcal_id = HcalDetId((uint32_t)(*contIter).rawId());
75 
76  depth = hcal_id.depth();
77  if (depth<1 || depth>4)
78  continue;
79 
80  ieta=hcal_id.ieta();
81  iphi=hcal_id.iphi();
82 
83  if (hcal_id.subdet() == HcalForward)
84  ieta>0 ? ++ieta : --ieta;
85 
86  //GET VALUE:
87  //unsigned fCapId, unsigned fRange;
88  if (slopeOrOffset){
89  value = (*contIter).slope(fCapId, fRange);
90  } else {
91  value = (*contIter).offset(fCapId, fRange);
92  }
93  //logstatus = log2(1.*channelBits)+1;
94 
95  //FILLING GOES HERE:
96  graphData[depth-1].Fill(ieta,iphi, value);
97  }
98  }
99  }
100  };
101 
102  std::string QIEDataCounter(const int nr, unsigned int &formated_nr, int base = 4){
103  int numer = nr;
104  int tens = 0, ones = 0;
105  if (numer >= 16){
106  numer = numer -16;
107  }
108  tens = numer / base;
109  ones = numer - (tens*base);
110  formated_nr = tens*10 + ones;
111  std::stringstream ss;
112  ss << tens << ones;
113  return ss.str();
114  }
115 
116  template<>
118  std::stringstream ss;
119  // get all containers with names
120  HcalQIEData::tAllContWithNames allContainers = object().getAllContainers();
121 
122  // initializing iterators
123  HcalQIEData::tAllContWithNames::const_iterator iter;
124  std::vector<HcalQIECoder>::const_iterator contIter;
125 
126  ss << "Total HCAL containers: " << allContainers.size() << std::endl;
127 
128  typedef std::pair<std::pair< float, float >, int> tPora;
129 
130  //std::vector<tPora> vMaz(allContainers.size());
131  //std::vector<tPora>::iterator iMaz = vMaz.begin();
132 
133  std::vector<tPora> vOffsets(allContainers.size());// for each container (total 8)
134  std::vector<tPora> vSlopes(allContainers.size());// for each container (total 8)
135 
136  std::vector<tPora>::iterator iOffset = vOffsets.begin();
137  std::vector<tPora>::iterator iSlope = vSlopes.begin();
138 
139  float offset = .0;
140  float slope = .0;
141 
142 
143  //Run trough all 8 detector containers:
144  for (iter = allContainers.begin(); iter != allContainers.end(); ++iter, ++iOffset, ++iSlope){
145  iOffset->second = (*iter).second.size();// total number of values in detector
146  iSlope->second = (*iter).second.size();// total number of values in detector
147 
148  (iOffset->first).first = .0;
149  (iOffset->first).second = .0;
150  (iSlope->first).first = .0;
151  (iSlope->first).second = .0;
152 
153  //Run trough all values in container
154  unsigned int i = 0;
155  for (contIter = (*iter).second.begin(); contIter != (*iter).second.end(); ++contIter){
156 
157  //Run trough all values in object:
158  for (unsigned int fCapId = 0; fCapId < 4; ++fCapId){
159  for (unsigned int fRange = 0; fRange < 4; ++fRange){
160  offset = (*contIter).offset (fCapId, fRange);
161  (iOffset->first).first += offset;
162  (iOffset->first).second+= (offset * offset);
163 
164  slope = (*contIter).slope (fCapId, fRange);
165  (iSlope->first).first += slope;
166  (iSlope->first).second+= (slope * slope);
167  }
168  }
169  ++i;
170  //ss << "[" << i << "] " << capValue << ", " << (iMaz->first).first[i] << ", " << (iMaz->first).second[i] << "; ";
171  }
172  }
173  //ss << std::endl;
174 
175  //got all the values, now do the work:
176  iOffset = vOffsets.begin();
177  iSlope = vSlopes.begin();
178  float sumOffset = 0.0, averageOffset = 0.0, std_devOffset = 0.0, sqr_sumOffset = 0.0;
179  int sizeOffset = 0;
180 
181  float sumSlope = 0.0, averageSlope = 0.0, std_devSlope = 0.0, sqr_sumSlope = 0.0;
182  int sizeSlope = 0;
183 
184  sizeOffset = (*iOffset).second;
185  sizeSlope = (*iSlope).second;
186 
187 
188 
189  unsigned int i = 0;
190  for (iter = allContainers.begin(); iter != allContainers.end(); ++iter, ++i, ++iSlope, ++iOffset){
191 
192  ss << "---------------------------------------------" << std::endl;
193  ss << "Detector: " << (*iter).first << "; Total values: "<< (*iter).second.size() << std::endl;
194  sumOffset = ((*iOffset).first).first;
195  sqr_sumOffset = ((*iOffset).first).second;
196  averageOffset = sumOffset/sizeOffset;
197  //here needs to take absolute value for sqrt:
198  std_devOffset = sqrt( fabs((sqr_sumOffset / sizeOffset) - (averageOffset * averageOffset)) );
199 
200  sumSlope = ((*iSlope).first).first;
201  sqr_sumSlope = ((*iSlope).first).second;
202  averageSlope = sumSlope/sizeSlope;
203  //here needs to take absolute value for sqrt:
204  std_devSlope = sqrt( fabs((sqr_sumSlope / sizeSlope) - (averageSlope * averageSlope)) );
205 
206  ss << " Offset: " << std::endl;
207  ss << " Average: " << averageOffset << "; "<< std::endl;
208  ss << " Standart deviation: " << std_devOffset << "; " << std::endl;
209  ss << " Slope: " << std::endl;
210  ss << " Average: " << averageSlope << "; "<< std::endl;
211  ss << " Standart deviation: " << std_devSlope << "; " << std::endl;
212  }
213  //std::cout << ss.str();
214  return ss.str();
215  }
216 
217  template<>
219  std::string const &,
220  std::vector<int> const&,
221  std::vector<float> const& ) const
222  {
223 
224  //how much values are in container
225  unsigned int numOfValues = 32;
226 
227  //create object helper for making plots;
228  HcalQIEDataDataRepr datarepr(numOfValues, object().getAllContainers());
229 
230  typedef std::vector<TH2F> graphData;
231  std::vector< graphData > graphDataVec(numOfValues);
232  std::vector< graphData >::iterator imageIter;
233  imageIter = graphDataVec.begin();
234 
235 
236 
237  std::string name = "_Offset_";
238  datarepr.nr = 0;
239  datarepr.id = 0;
240  datarepr.rootname.str("_Offsetrootvalue_");
241  datarepr.plotname.str("Offset ");
242  datarepr.filename.str("");
243  datarepr.filename << filename << name;
244  //Run trough all values in object:
245  datarepr.slopeOrOffset = false;
246 
247  for (unsigned int fCapId = 0; fCapId < 4; ++fCapId){
248  for (unsigned int fRange = 0; fRange < 4; ++fRange){
249  datarepr.fCapId = fCapId;
250  datarepr.fRange = fRange;
251 
252  QIEDataCounter(datarepr.id, datarepr.nr);
253 
254  if (datarepr.nr == 0){
255  datarepr.filename.str("");
256  datarepr.filename << filename << name <<"0";
257  } else if ( datarepr.nr == 10)
258  {
259  datarepr.filename.str("");
260  datarepr.filename << filename << name;
261  }
262 
263 
264 
265  datarepr.fillOneGain((*imageIter));
266 
267 
268  ++(datarepr.id);
269  ++(datarepr.nr);
270  ++(imageIter);
271  }
272  }
274  name = "_Slope_";
275  datarepr.rootname.str("_Sloperootname_");
276  datarepr.plotname.str("Slope ");
277  datarepr.filename.str("");
278  datarepr.filename << filename << name;
279 
280  datarepr.slopeOrOffset = true;
281  datarepr.nr = 0;
282  datarepr.id = 0;
283 
284  for (unsigned int fCapId = 0; fCapId < 4; ++fCapId){
285  for (unsigned int fRange = 0; fRange < 4; ++fRange){
286  datarepr.fCapId = fCapId;
287  datarepr.fRange = fRange;
288 
289  QIEDataCounter(datarepr.id, datarepr.nr);
290 
291  if (datarepr.nr == 0){
292  datarepr.filename.str("");
293  datarepr.filename << filename << name <<"0";
294  } else if ( datarepr.nr == 10)
295  {
296  datarepr.filename.str("");
297  datarepr.filename << filename << name;
298  }
299 
300  datarepr.fillOneGain((*imageIter));
301 
302  ++(datarepr.id);
303  ++(datarepr.nr);
304  ++(imageIter);
305  }
306  }
307 
308 
309  return filename;
310  }
311 }
312 
tuple base
Main Program
Definition: newFWLiteAna.py:92
int i
Definition: DBlmapReader.cc:9
static const double slope[3]
#define PYTHON_WRAPPER(_class, _name)
HcalQIEDataDataRepr(unsigned int total, HcalQIEData::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
unsigned int offset(bool)
void doFillIn(std::vector< TH2F > &graphData)
void fillOneGain(std::vector< TH2F > &graphData, std::string units="")
bool first
Definition: L1TdeRCT.cc:94
list object
Definition: dbtoconf.py:77
tuple filename
Definition: lut2db_cfg.py:20
HcalQIEData::tAllContWithNames allContainers
std::string QIEDataCounter(const int nr, unsigned int &formated_nr, int base=4)