CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalGainWidthsPyWrapper.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<HcalGainWidths>: public BaseValueExtractor<HcalGainWidths> {
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  HcalGainWidths::tAllContWithNames::const_iterator iter;
62  std::vector<HcalGainWidth>::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 = 4;
96  // get all containers with names
97  HcalGainWidths::tAllContWithNames allContainers = object().getAllContainers();
98 
99  // initializing iterators
100  HcalGainWidths::tAllContWithNames::const_iterator iter;
101  std::vector<HcalGainWidth>::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 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  //here needs to take absolute value for sqrt:
143  std_dev = sqrt( fabs((sqr_sum / size) - (average * average)) );
144 
145  ss << " GainWidth " << i << " :"<< std::endl;
146  ss << " Average: " << average << "; "<< std::endl;
147  ss << " Standart deviation: " << std_dev << "; " << std::endl;
148  }
149  }
150  //std::cout << ss.str();
151  return ss.str();
152  }
153 
154  template<>
155  std::string PayLoadInspector<HcalGainWidths>::plot(std::string const & filename,
156  std::string const &,
157  std::vector<int> const&,
158  std::vector<float> const& ) const
159  {
160 
161  //how much values are in container
162  unsigned int numOfValues = 4;
163 
164  //create object helper for making plots;
165  HcalGainWidthsDataRepr datarepr(numOfValues, object().getAllContainers());
166 
167  datarepr.nr = 0;
168  datarepr.id = 0;
169  datarepr.rootname.str("_GainWidthrootvalue_");
170  datarepr.plotname.str("GainWidthValue ");
171  datarepr.filename.str("");
172  datarepr.filename << filename << "_GainWidth_";
173 
174  typedef std::vector<TH2F> graphData;
175  std::vector< graphData > graphDataVec(numOfValues);
176  std::vector< graphData >::iterator imageIter;
177 
178  //create images:
179  for (imageIter = graphDataVec.begin(); imageIter != graphDataVec.end(); ++imageIter){
180 
181  //MAIN FUNCTION:
182  datarepr.fillOneGain((*imageIter));
183 
184  ++(datarepr.nr);
185  ++(datarepr.id);
186  }
187  return filename;
188  }
189 }
int i
Definition: DBlmapReader.cc:9
void doFillIn(std::vector< TH2F > &graphData)
HcalGainWidthsDataRepr(unsigned int total, HcalGainWidths::tAllContWithNames const &allCont)
#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
HcalGainWidths::tAllContWithNames allContainers
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
tuple size
Write out results.