CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalGainRatiosPyWrapper.cc
Go to the documentation of this file.
4 #include "TH2F.h"
5 #include "TCanvas.h"
6 #include "TLine.h"
7 #include "TStyle.h"
8 #include "TPave.h"
9 #include "TPaveStats.h"
12 
15 
16 #include <string>
17 #include <fstream>
18 
20 
21 namespace cond {
22 
23  template<>
24  class ValueExtractor<EcalGainRatios>: public BaseValueExtractor<EcalGainRatios> {
25  public:
26 
29  static What what() { return What();}
30 
33  {
34  // here one can make stuff really complicated...
35  }
36  void compute(Class const & it){
37  }
38  private:
39 
40  };
41 
42 
43  template<>
44  std::string
46 
47 
48  std::stringstream ss;
50  ss<<EcalGainRatiosXMLTranslator::dumpXML(header,object());
51  return ss.str();
52 
53  }
54 
55  class EcalGainRatiosHelper: public EcalPyWrapperHelper<EcalMGPAGainRatio>{
56  public:
58  protected:
59 
60  //change me
62 
63  type_vValues getValues( const std::vector<EcalObject> & vItems)
64  {
65  //change me
66  //unsigned int totalValues = 2;
67 
68  type_vValues vValues(total_values);
69 
70  //change us
71  vValues[0].first = "gain12Over6";
72  vValues[1].first = "gain6Over1";
73 
74  vValues[0].second = .0;
75  vValues[1].second = .0;
76 
77  //get info:
78  for(std::vector<EcalObject>::const_iterator iItems = vItems.begin(); iItems != vItems.end(); ++iItems){
79  //change us
80  vValues[0].second += iItems->gain12Over6();
81  vValues[1].second += iItems->gain6Over1();
82  }
83  return vValues;
84  }
85  };
86 
87  template<>
89  std::stringstream ss;
90  EcalGainRatiosHelper helper;
91  ss << helper.printBarrelsEndcaps(object().barrelItems(), object().endcapItems());
92  return ss.str();
93  }
94 
95 
96  template<>
97  std::string PayLoadInspector<EcalGainRatios>::plot(std::string const & filename,
98  std::string const &,
99  std::vector<int> const&,
100  std::vector<float> const& ) const {
101  gStyle->SetPalette(1);
102  TCanvas canvas("CC map","CC map",840,600);
103  float xmi[3] = {0.0 , 0.22, 0.78};
104  float xma[3] = {0.22, 0.78, 1.00};
105  TPad*** pad = new TPad**[2];
106  for (int gId = 0; gId < 2; gId++) {
107  pad[gId] = new TPad*[3];
108  for (int obj = 0; obj < 3; obj++) {
109  float yma = 1.- (0.34 * gId);
110  float ymi = yma - 0.32;
111  pad[gId][obj] = new TPad(Form("p_%i_%i", obj, gId),Form("p_%i_%i", obj, gId),
112  xmi[obj], ymi, xma[obj], yma);
113  pad[gId][obj]->Draw();
114  }
115  }
116  TPad** pad1 = new TPad*[4];
117  for (int obj = 0; obj < 4; obj++) {
118  float xmi = 0.26 * obj;
119  float xma = xmi + 0.22;
120  pad1[obj] = new TPad(Form("p1_%i", obj),Form("p1_%i", obj),
121  xmi, 0.0, xma, 0.32);
122  pad1[obj]->Draw();
123  }
124  const int kSides = 2;
125  const int kBarlRings = EBDetId::MAX_IETA;
126  const int kBarlWedges = EBDetId::MAX_IPHI;
127  const int kEndcWedgesX = EEDetId::IX_MAX;
128  const int kEndcWedgesY = EEDetId::IY_MAX;
129 
130  TH2F* barrel_12O6 = new TH2F("EB_12O6","EB gain 12/6",360,0,360, 170, -85,85);
131  TH2F* endc_p_12O6 = new TH2F("EE+_12O6","EE+ gain 12/6",100,1,101,100,1,101);
132  TH2F* endc_m_12O6 = new TH2F("EE-_12O6","EE- gain 12/6",100,1,101,100,1,101);
133  TH2F* barrel_6O1 = new TH2F("EB_6O1","EB gain 6/1",360,0,360, 170, -85,85);
134  TH2F* endc_p_6O1 = new TH2F("EE+_6O1","EE+ gain 6/1",100,1,101,100,1,101);
135  TH2F* endc_m_6O1 = new TH2F("EE-_6O1","EE- gain 6/1",100,1,101,100,1,101);
136  TH1F* b_12O6 = new TH1F("b_12O6","EB gain 12/6", 50, 1.8, 2.1);
137  TH1F* e_12O6 = new TH1F("e_12O6","EE gain 12/6", 50, 1.8, 2.1);
138  TH1F* b_6O1 = new TH1F("b_6O1","EB gain 6/1", 100, 5.3, 6.3);
139  TH1F* e_6O1 = new TH1F("e_6O1","EE gain 6/1", 100, 5.3, 6.3);
140 
141  for (int sign=0; sign < kSides; sign++) {
142  int thesign = sign==1 ? 1:-1;
143 
144  for (int ieta=0; ieta<kBarlRings; ieta++) {
145  for (int iphi=0; iphi<kBarlWedges; iphi++) {
146  EBDetId id((ieta+1)*thesign, iphi+1);
147  float y = -1 - ieta;
148  if(sign == 1) y = ieta;
149  barrel_12O6->Fill(iphi, y, object()[id.rawId()].gain12Over6());
150  barrel_6O1->Fill(iphi, y, object()[id.rawId()].gain6Over1());
151  b_12O6->Fill(object()[id.rawId()].gain12Over6());
152  b_6O1->Fill(object()[id.rawId()].gain6Over1());
153  } // iphi
154  } // ieta
155 
156  for (int ix=0; ix<kEndcWedgesX; ix++) {
157  for (int iy=0; iy<kEndcWedgesY; iy++) {
158  if (! EEDetId::validDetId(ix+1,iy+1,thesign)) continue;
159  EEDetId id(ix+1,iy+1,thesign);
160  if (thesign==1) {
161  endc_p_12O6->Fill(ix+1,iy+1,object()[id.rawId()].gain12Over6());
162  endc_p_6O1->Fill(ix+1,iy+1,object()[id.rawId()].gain6Over1());
163  }
164  else{
165  endc_m_12O6->Fill(ix+1,iy+1,object()[id.rawId()].gain12Over6());
166  endc_m_6O1->Fill(ix+1,iy+1,object()[id.rawId()].gain6Over1());
167  }
168  e_12O6->Fill(object()[id.rawId()].gain12Over6());
169  e_6O1->Fill(object()[id.rawId()].gain6Over1());
170  } // iy
171  } // ix
172  } // side
173 
174  TLine* l = new TLine(0., 0., 0., 0.);
175  l->SetLineWidth(1);
176  int ixSectorsEE[202] = {
177  62, 62, 61, 61, 60, 60, 59, 59, 58, 58, 56, 56, 46, 46, 44, 44, 43, 43, 42, 42,
178  41, 41, 40, 40, 41, 41, 42, 42, 43, 43, 44, 44, 46, 46, 56, 56, 58, 58, 59, 59,
179  60, 60, 61, 61, 62, 62, 0,101,101, 98, 98, 96, 96, 93, 93, 88, 88, 86, 86, 81,
180  81, 76, 76, 66, 66, 61, 61, 41, 41, 36, 36, 26, 26, 21, 21, 16, 16, 14, 14, 9,
181  9, 6, 6, 4, 4, 1, 1, 4, 4, 6, 6, 9, 9, 14, 14, 16, 16, 21, 21, 26,
182  26, 36, 36, 41, 41, 61, 61, 66, 66, 76, 76, 81, 81, 86, 86, 88, 88, 93, 93, 96,
183  96, 98, 98,101,101, 0, 62, 66, 66, 71, 71, 81, 81, 91, 91, 93, 0, 62, 66, 66,
184  91, 91, 98, 0, 58, 61, 61, 66, 66, 71, 71, 76, 76, 81, 81, 0, 51, 51, 0, 44,
185  41, 41, 36, 36, 31, 31, 26, 26, 21, 21, 0, 40, 36, 36, 11, 11, 4, 0, 40, 36,
186  36, 31, 31, 21, 21, 11, 11, 9, 0, 46, 46, 41, 41, 36, 36, 0, 56, 56, 61, 61, 66, 66};
187 
188  int iySectorsEE[202] = {
189  51, 56, 56, 58, 58, 59, 59, 60, 60, 61, 61, 62, 62, 61, 61, 60, 60, 59, 59, 58,
190  58, 56, 56, 46, 46, 44, 44, 43, 43, 42, 42, 41, 41, 40, 40, 41, 41, 42, 42, 43,
191  43, 44, 44, 46, 46, 51, 0, 51, 61, 61, 66, 66, 76, 76, 81, 81, 86, 86, 88, 88,
192  93, 93, 96, 96, 98, 98,101,101, 98, 98, 96, 96, 93, 93, 88, 88, 86, 86, 81, 81,
193  76, 76, 66, 66, 61, 61, 41, 41, 36, 36, 26, 26, 21, 21, 16, 16, 14, 14, 9, 9,
194  6, 6, 4, 4, 1, 1, 4, 4, 6, 6, 9, 9, 14, 14, 16, 16, 21, 21, 26, 26,
195  36, 36, 41, 41, 51, 0, 46, 46, 41, 41, 36, 36, 31, 31, 26, 26, 0, 51, 51, 56,
196  56, 61, 61, 0, 61, 61, 66, 66, 71, 71, 76, 76, 86, 86, 88, 0, 62,101, 0, 61,
197  61, 66, 66, 71, 71, 76, 76, 86, 86, 88, 0, 51, 51, 56, 56, 61, 61, 0, 46, 46,
198  41, 41, 36, 36, 31, 31, 26, 26, 0, 40, 31, 31, 16, 16, 6, 0, 40, 31, 31, 16, 16, 6};
199 
200  float min12O6 = 1.8, max12O6 = 2.1, min6O1 = 5.3, max6O1 = 6.3;
201  pad[0][0]->cd();
202  endc_m_12O6->SetStats(0);
203  endc_m_12O6->SetMaximum(max12O6);
204  endc_m_12O6->SetMinimum(min12O6);
205  endc_m_12O6->Draw("colz");
206  for ( int i=0; i<201; i=i+1) {
207  if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
208  (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
209  l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
210  ixSectorsEE[i+1], iySectorsEE[i+1]);
211  l->SetLineWidth(0.2);
212  }
213  }
214  pad[0][1]->cd();
215  barrel_12O6->SetStats(0);
216  barrel_12O6->SetMaximum(max12O6);
217  barrel_12O6->SetMinimum(min12O6);
218  barrel_12O6->Draw("colz");
219  for(int i = 0; i <17; i++) {
220  Double_t x = 20.+ (i *20);
221  l = new TLine(x,-85.,x,86.);
222  l->Draw();
223  }
224  l = new TLine(0.,0.,360.,0.);
225  l->Draw();
226  pad[0][2]->cd();
227  endc_p_12O6->SetStats(0);
228  endc_p_12O6->SetMaximum(max12O6);
229  endc_p_12O6->SetMinimum(min12O6);
230  endc_p_12O6->Draw("colz");
231  for ( int i=0; i<201; i=i+1) {
232  if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
233  (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
234  l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
235  ixSectorsEE[i+1], iySectorsEE[i+1]);
236  l->SetLineWidth(0.2);
237  }
238  }
239  pad[1][0]->cd();
240  endc_m_6O1->SetStats(0);
241  endc_m_6O1->SetMaximum(max6O1);
242  endc_m_6O1->SetMinimum(min6O1);
243  endc_m_6O1->Draw("colz");
244  for ( int i=0; i<201; i=i+1) {
245  if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
246  (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
247  l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
248  ixSectorsEE[i+1], iySectorsEE[i+1]);
249  l->SetLineWidth(0.2);
250  }
251  }
252  pad[1][1]->cd();
253  barrel_6O1->SetStats(0);
254  barrel_6O1->SetMaximum(max6O1);
255  barrel_6O1->SetMinimum(min6O1);
256  barrel_6O1->Draw("colz");
257  for(int i = 0; i <17; i++) {
258  Double_t x = 20.+ (i *20);
259  l = new TLine(x,-85.,x,86.);
260  l->Draw();
261  }
262  l = new TLine(0.,0.,360.,0.);
263  l->Draw();
264  pad[1][2]->cd();
265  endc_p_6O1->SetStats(0);
266  endc_p_6O1->SetMaximum(max6O1);
267  endc_p_6O1->SetMinimum(min6O1);
268  endc_p_6O1->Draw("colz");
269  for ( int i=0; i<201; i=i+1) {
270  if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
271  (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
272  l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
273  ixSectorsEE[i+1], iySectorsEE[i+1]);
274  l->SetLineWidth(0.2);
275  }
276  }
277 
278  gStyle->SetOptStat(111110);
279  pad1[0]->cd();
280  b_12O6->Draw();
281  pad1[0]->Update();
282  TPaveStats *st = (TPaveStats*)b_12O6->FindObject("stats");
283  st->SetX1NDC(0.6); //new x start position
284  st->SetY1NDC(0.75); //new y start position
285  pad1[1]->cd();
286  e_12O6->Draw();
287  pad1[0]->Update();
288  st = (TPaveStats*)e_12O6->FindObject("stats");
289  st->SetX1NDC(0.6); //new x start position
290  st->SetY1NDC(0.75); //new y start position
291  pad1[2]->cd();
292  b_6O1->Draw();
293  pad1[0]->Update();
294  st = (TPaveStats*)b_6O1->FindObject("stats");
295  st->SetX1NDC(0.6); //new x start position
296  st->SetY1NDC(0.75); //new y start position
297  pad1[3]->cd();
298  e_6O1->Draw();
299  pad1[0]->Update();
300  st = (TPaveStats*)e_6O1->FindObject("stats");
301  st->SetX1NDC(0.6); //new x start position
302  st->SetY1NDC(0.75); //new y start position
303 
304  canvas.SaveAs(filename.c_str());
305  return filename;
306  }
307 
308 
309 }
310 
int i
Definition: DBlmapReader.cc:9
std::string plot(std::string const &, std::string const &, std::vector< int > const &, std::vector< float > const &) const
ExtractWhat< Class > What
static const int kBarlRings
std::vector< std::pair< std::string, float > > type_vValues
type_vValues getValues(const std::vector< EcalObject > &vItems)
#define PYTHON_WRAPPER(_class, _name)
static const int kSides
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.cc:562
def canvas
Definition: svgfig.py:481
static const int kBarlWedges
std::string summary() const
static const int kEndcWedgesX
static const int IX_MAX
Definition: EEDetId.h:279
static const int MAX_IPHI
Definition: EBDetId.h:123
static const int MAX_IETA
Definition: EBDetId.h:122
std::string printBarrelsEndcaps(const std::vector< T > &barrelItems, const std::vector< T > &endcapItems)
tuple filename
Definition: lut2db_cfg.py:20
static const int IY_MAX
Definition: EEDetId.h:283
static std::string dumpXML(const EcalCondHeader &header, const EcalGainRatios &record)
x
Definition: VDTMath.h:216
std::string dump() const
static const int kEndcWedgesY