CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalGainsPyWrapper.cc
Go to the documentation of this file.
2 
5 
6 #include <string>
7 #include <fstream>
8 #include <sstream>
9 
10 #include "TH1F.h"
11 #include "TH2F.h"
14 
15 #include "TROOT.h"
16 #include "TCanvas.h"
17 #include "TStyle.h"
18 #include "TColor.h"
19 #include "TLine.h"
20 
21 #include <cmath>
22 //functions for correct representation of data in summary and plot:
24 using namespace HcalObjRepresent;
25 
26 namespace cond {
27 
28  template<>
29  class ValueExtractor<HcalGains>: public BaseValueExtractor<HcalGains> {
30  public:
31  typedef HcalGains 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) override{
43  }
44  private:
45 
46  };
47 
48 
49  template<>
51  std::stringstream ss;
52 
53  // get all containers with names
54  HcalGains::tAllContWithNames allContainers = object().getAllContainers();
55 
56  // initializing iterators
57  HcalGains::tAllContWithNames::const_iterator iter;
58  std::vector<HcalGain>::const_iterator contIter;
59 
60  ss << "Total HCAL containers: " << allContainers.size() << std::endl;
61 
62  int capIdSize = 4;
63  float capValue = 0.0;
64  typedef std::pair<std::pair< std::vector<float>, std::vector<float> >, int> tPora;
65 
66  std::vector<tPora> vec(allContainers.size());
67 
68  std::vector<tPora>::iterator iMaz = vec.begin();
69 
70  float sum = 0.0, average = 0.0, std_dev = 0.0, sqr_sum = 0.0;
71  int size = 0;
72 
73  //Run trough all 8 detector containers:
74  for (iter = allContainers.begin(), iMaz = vec.begin(); iter != allContainers.end(); ++iter, ++iMaz){
75  ss << "---------------------------------------------" << std::endl;
76  ss << "Detector: " << (*iter).first << "; Total values: "<< (*iter).second.size() << std::endl;
77  unsigned int j = 0;
78  //ss << sizes.size() <<index;
79  //vec.push_back(std::pair<std::vector<float>(4, 0.0), 0>);
80  iMaz->second = (*iter).second.size();
81  (iMaz->first).first = std::vector<float>(4, 0.0);
82  (iMaz->first).second = std::vector<float>(4, 0.0);
83 
84  //Run trough all values in container
85  for (contIter = (*iter).second.begin(); contIter != (*iter).second.end(); ++contIter){
86 
87  //Run trough all values (4) in object:
88  for (int i = 0; i < capIdSize; ++i){
89  capValue = (*contIter).getValue(i);
90  (iMaz->first).first[i] += capValue;
91  (iMaz->first).second[i]+= (capValue * capValue);
92  //ss << "[" << i << "] " << capValue << ", " << (iMaz->first).first[i] << ", " << (iMaz->first).second[i] << "; ";
93  }
94  //ss << std::endl;
95  ++j;
96  }
97 
98  size = (*iMaz).second;
99  //ss << k++ << ": size = "<< size << "; ";
100  for (int i = 0; i < capIdSize; ++i){
101  sum = ((*iMaz).first).first[i];
102  sqr_sum = ((*iMaz).first).second[i];
103  average = sum/size;
104  std_dev = sqrt( (sqr_sum/size) - (average * average) );
105  ss << " Gain " << i << " :"<< std::endl;
106  ss << " Average: " << average << "; "<< std::endl;
107  ss << " Standart deviation: " << std_dev << "; " << std::endl;
108  }
109  }
110  return ss.str();
111  }
112 
113  void draw(std::vector<TH2F> &graphData, std::string filename) {
114  //Drawing...
115  // use David's palette
116  gStyle->SetPalette(1);
117  const Int_t NCont = 999;
118  gStyle->SetNumberContours(NCont);
119  TCanvas canvas("CC map","CC map",840,369*4);
120 
121  TPad pad1("pad1","pad1", 0.0, 0.75, 1.0, 1.0);
122  pad1.Draw();
123  TPad pad2("pad2","pad2", 0.0, 0.5, 1.0, 0.75);
124  pad2.Draw();
125  TPad pad3("pad3","pad3", 0.0, 0.25, 1.0, 0.5);
126  pad3.Draw();
127  TPad pad4("pad4","pad4", 0.0, 0.0, 1.0, 0.25);
128  pad4.Draw();
129 
130 
131  pad1.cd();
132  graphData[0].SetStats(0);
133  graphData[0].Draw("colz");
134 
135  pad2.cd();
136  graphData[1].SetStats(0);
137  graphData[1].Draw("colz");
138 
139  pad3.cd();
140  graphData[2].SetStats(0);
141  graphData[2].Draw("colz");
142 
143  pad4.cd();
144  graphData[3].SetStats(0);
145  graphData[3].Draw("colz");
146 
147  canvas.SaveAs(filename.c_str());
148  }
149 
150  template<>
152  std::string const &,
153  std::vector<int> const&,
154  std::vector<float> const& ) const
155  {
156  //void set(since, till, filename); {
157  unsigned int numOfValues = 4;
158  std::string plotname = "_Gain_";
159  //filename = filename + "_Gain";
160 
161 
162  typedef std::vector<TH2F> graphData;
163  std::vector< graphData > graphDataVec(numOfValues);
164  std::vector< graphData >::iterator bigIter;
165 
166  std::stringstream ss, plotname_i;
167  HcalGains::tAllContWithNames allContainers = object().getAllContainers();
168 
169  int i = 0;
170  for (bigIter = graphDataVec.begin(); bigIter != graphDataVec.end(); ++bigIter){
171  plotname_i << plotname << i ;
172  ss << filename << "_Gain_"<<i<<".png";
173  fillOneGain((*bigIter), allContainers, plotname_i.str(), i);
174  FillUnphysicalHEHFBins(*bigIter);
175  draw((*bigIter), ss.str());
176  ++i;
177  ss.str("");
178  plotname_i.str("");
179  }
180  return filename;
181  }
182 }
int i
Definition: DBlmapReader.cc:9
void draw(std::vector< TH2F > &graphData, std::string filename)
#define PYTHON_WRAPPER(_class, _name)
def canvas
Definition: svgfig.py:481
U second(std::pair< T, U > const &p)
T sqrt(T t)
Definition: SSEVec.h:48
int j
Definition: DBlmapReader.cc:9
bool first
Definition: L1TdeRCT.cc:79
void fillOneGain(std::vector< TH2F > &graphData, HcalGains::tAllContWithNames &allContainers, std::string name, int id, std::string units="")
void FillUnphysicalHEHFBins(std::vector< TH2F > &hh)
int average
Definition: PDRates.py:137
list object
Definition: dbtoconf.py:77
tuple filename
Definition: lut2db_cfg.py:20
tuple size
Write out results.
void compute(Class const &it) override