CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalTimeCorrsPyWrapper.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 "math.h"
17 //functions for correct representation of data in summary and plot:
19 using namespace HcalObjRepresent;
20 
21 namespace cond {
22  template<>
23  class ValueExtractor<HcalTimeCorrs>: public BaseValueExtractor<HcalTimeCorrs> {
24  public:
27  static What what() { return What();}
28 
30 
31  ValueExtractor(What const & what)
32  {
33  // here one can make stuff really complicated...
34  }
35 
36  void compute(Class const & it){
37  }
38  private:
39 
40  };
41 
43  {
44  public:
46  :ADataRepr(total), allContainers(allCont){}
47 
48 
49 
50  protected:
52 
53  void doFillIn(std::vector<TH2F> &graphData){
54  //ITERATORS AND VALUES:
55  HcalTimeCorrs::tAllContWithNames::const_iterator iter;
56  std::vector<HcalTimeCorr>::const_iterator contIter;
57  float value = 0.0;
58 
59  //run trough all pair containers
60  for (iter = allContainers.begin(); iter != allContainers.end(); ++iter){
61  //Run trough all values:
62  for (contIter = (*iter).second.begin(); contIter != (*iter).second.end(); ++contIter){
63  hcal_id = HcalDetId((uint32_t)(*contIter).rawId());
64 
65  depth = hcal_id.depth();
66  if (depth<1 || depth>4)
67  continue;
68 
69  ieta=hcal_id.ieta();
70  iphi=hcal_id.iphi();
71 
72  if (hcal_id.subdet() == HcalForward)
73  ieta>0 ? ++ieta : --ieta;
74 
75  //GET VALUE:
76  value = (*contIter).getValue();
77  //logstatus = log2(1.*channelBits)+1;
78 
79  //FILLING GOES HERE:
80  graphData[depth-1].Fill(ieta,iphi, value);
81  }
82  }
83  }
84  };
85 
86  template<>
88  std::stringstream ss;
89  unsigned int totalValues = 1;
90  // get all containers with names
91  HcalTimeCorrs::tAllContWithNames allContainers = object().getAllContainers();
92 
93  // initializing iterators
94  HcalTimeCorrs::tAllContWithNames::const_iterator iter;
95  std::vector<HcalTimeCorr>::const_iterator contIter;
96 
97  ss << "Total HCAL containers: " << allContainers.size() << std::endl;
98 
99  typedef std::pair<std::pair< std::vector<float>, std::vector<float> >, int> tPora;
100 
101  std::vector<tPora> vec(allContainers.size());
102 
103  std::vector<tPora>::iterator iMaz = vec.begin();
104 
105  float sum = 0.0, average = 0.0, std_dev = 0.0, sqr_sum = 0.0;
106  int size = 0;
107 
108  //Run trough all 8 detector containers:
109  for (iter = allContainers.begin(), iMaz = vec.begin(); iter != allContainers.end(); ++iter, ++iMaz){
110  ss << "---------------------------------------------" << std::endl;
111  ss << "Detector: " << (*iter).first << "; Total values: "<< (*iter).second.size() << std::endl;
112  unsigned int j = 0;
113  iMaz->second = (*iter).second.size();
114  (iMaz->first).first = std::vector<float>(totalValues, 0.0);
115  (iMaz->first).second = std::vector<float>(totalValues, 0.0);
116  float capValue = 0.0;
117  //Run trough all values in container
118  for (contIter = (*iter).second.begin(); contIter != (*iter).second.end(); ++contIter){
119 
120  //Run trough all values (8) in object:
121  for (unsigned int i = 0; i < totalValues; ++i){
122  capValue = (*contIter).getValue();
123  (iMaz->first).first[i] += capValue;
124  (iMaz->first).second[i]+= (capValue * capValue);
125  //ss << "[" << i << "] " << capValue << ", " << (iMaz->first).first[i] << ", " << (iMaz->first).second[i] << "; ";
126  }
127  //ss << std::endl;
128  ++j;
129  }
130 
131  size = (*iMaz).second;
132  for (unsigned int i = 0; i < totalValues; ++i){
133  sum = ((*iMaz).first).first[i];
134  sqr_sum = ((*iMaz).first).second[i];
135  average = sum/size;
136  //here needs to take absolute value for sqrt:
137  std_dev = sqrt( fabs((sqr_sum / size) - (average * average)) );
138 
139  ss << " TimeCorr " << " :"<< std::endl;
140  ss << " Average: " << average << "; "<< std::endl;
141  ss << " Standart deviation: " << std_dev << "; " << std::endl;
142 
143  }
144  }
145  //std::cout << ss.str();
146  return ss.str();
147  }
148 
149  template<>
150  std::string PayLoadInspector<HcalTimeCorrs>::plot(std::string const & filename,
151  std::string const &,
152  std::vector<int> const&,
153  std::vector<float> const& ) const
154  {
155 
156  //how much values are in container
157  unsigned int numOfValues = 1;
158 
159  //create object helper for making plots;
160  HcalTimeCorrsDataRepr datarepr(numOfValues, object().getAllContainers());
161 
162  datarepr.nr = 0;
163  datarepr.id = 0;
164  datarepr.rootname.str("_TimeCorrrootvalue_");
165  datarepr.plotname.str("TimeCorr ");
166  datarepr.filename.str("");
167  datarepr.filename << filename << "";
168 
169  typedef std::vector<TH2F> graphData;
170  std::vector< graphData > graphDataVec(numOfValues);
171  std::vector< graphData >::iterator imageIter;
172 
173  //create images:
174  for (imageIter = graphDataVec.begin(); imageIter != graphDataVec.end(); ++imageIter){
175  //MAIN FUNCTION:
176  datarepr.fillOneGain((*imageIter));
177 
178  ++(datarepr.nr);
179  ++(datarepr.id);
180  }
181  return filename;
182  }
183 }
int i
Definition: DBlmapReader.cc:9
#define PYTHON_WRAPPER(_class, _name)
HcalTimeCorrsDataRepr(unsigned int total, HcalTimeCorrs::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:46
int j
Definition: DBlmapReader.cc:9
void fillOneGain(std::vector< TH2F > &graphData, std::string units="")
bool first
Definition: L1TdeRCT.cc:94
HcalTimeCorrs::tAllContWithNames allContainers
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.