CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalTPGLinearizationConstPyWrapper.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<EcalTPGLinearizationConst>: public BaseValueExtractor<EcalTPGLinearizationConst> {
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  template<>
44 
45  std::stringstream ss;
46  EcalCondHeader header;
48  return ss.str();
49 
50  }
51 
52  class EcalTPGLinearizationConstHelper: public EcalPyWrapperHelper<EcalTPGLinearizationConstant>{
53  public:
54  //change me
56  protected:
57 
58  //change me
60 
61  type_vValues getValues( const std::vector<EcalObject> & vItems)
62  {
63 
64  type_vValues vValues(total_values);
65 
66  vValues[0].second = .0;
67  vValues[1].second = .0;
68  vValues[2].second = .0;
69  vValues[3].second = .0;
70  vValues[4].second = .0;
71  vValues[5].second = .0;
72 
73 
74  //change us
75  vValues[0].first = "mult_x12";
76  vValues[1].first = "mult_x6";
77  vValues[2].first = "mult_x1";
78  vValues[3].first = "shift_x12";
79  vValues[4].first = "shift_x6";
80  vValues[5].first = "shift_x1";
81 
82 
83 
84 
85  for(std::vector<EcalObject>::const_iterator iItems = vItems.begin(); iItems != vItems.end(); ++iItems){
86  //change us
87  vValues[0].second += iItems->mult_x12;
88  vValues[1].second += iItems->mult_x6;
89  vValues[2].second += iItems->mult_x1;
90  vValues[3].second += iItems->shift_x12;
91  vValues[4].second += iItems->shift_x6;
92  vValues[5].second += iItems->shift_x1;
93 
94  }
95  return vValues;
96  }
97  };
98 
99  template<>
101  std::stringstream ss;
103  ss << helper.printBarrelsEndcaps(object().barrelItems(), object().endcapItems());
104  return ss.str();
105  }
106 
107  // return the real name of the file including extension...
108  template<>
110  std::string const &,
111  std::vector<int> const&,
112  std::vector<float> const& ) const {
113  gStyle->SetPalette(1);
114 
115  const float IMG_SIZE = 1.5;
116  TCanvas canvas("CC map","CC map",800 * IMG_SIZE,1200 * IMG_SIZE);
117 
118  float xmi[3] = {0.0 , 0.22, 0.78};
119  float xma[3] = {0.22, 0.78, 1.00};
120  TPad*** pad = new TPad**[6];
121  for (int gId = 0; gId < 6; gId++) {
122  pad[gId] = new TPad*[3];
123  for (int obj = 0; obj < 3; obj++) {
124  float yma = 1.- (0.17 * gId);
125  float ymi = yma - 0.15;
126  pad[gId][obj] = new TPad(Form("p_%i_%i", obj, gId),Form("p_%i_%i", obj, gId),
127  xmi[obj], ymi, xma[obj], yma);
128  pad[gId][obj]->Draw();
129  }
130  }
131 
132  const int kGains = 3;
133  const int gainValues[3] = {12, 6, 1};
134  const int kSides = 2;
135  const int kBarlRings = EBDetId::MAX_IETA;
136  const int kBarlWedges = EBDetId::MAX_IPHI;
137  const int kEndcWedgesX = EEDetId::IX_MAX;
138  const int kEndcWedgesY = EEDetId::IY_MAX;
139 
140  TH2F** barrel_m = new TH2F*[3];
141  TH2F** endc_p_m = new TH2F*[3];
142  TH2F** endc_m_m = new TH2F*[3];
143  TH2F** barrel_r = new TH2F*[3];
144  TH2F** endc_p_r = new TH2F*[3];
145  TH2F** endc_m_r = new TH2F*[3];
146  for (int gainId = 0; gainId < kGains; gainId++) {
147  barrel_m[gainId] = new TH2F(Form("mult_x12 EBm%i",gainId),Form("mult_x%i EB",gainValues[gainId]),360,0,360, 170, -85,85);
148  endc_p_m[gainId] = new TH2F(Form("mult_x12 EE+m%i",gainId),Form("mult_x%i EE+",gainValues[gainId]),100,1,101,100,1,101);
149  endc_m_m[gainId] = new TH2F(Form("mult_x12 EE-m%i",gainId),Form("mult_x%i EE-",gainValues[gainId]),100,1,101,100,1,101);
150  barrel_r[gainId] = new TH2F(Form("shift_x12 EBr%i",gainId),Form("shift_x%i EB",gainValues[gainId]),360,0,360, 170, -85,85);
151  endc_p_r[gainId] = new TH2F(Form("shift_x12 EE+r%i",gainId),Form("shift_x%i EE+",gainValues[gainId]),100,1,101,100,1,101);
152  endc_m_r[gainId] = new TH2F(Form("shift_x12 EE-r%i",gainId),Form("shift_x%i EE-",gainValues[gainId]),100,1,101,100,1,101);
153  }
154 
155  for (int sign=0; sign < kSides; sign++) {
156  int thesign = sign==1 ? 1:-1;
157 
158  for (int ieta=0; ieta<kBarlRings; ieta++) {
159  for (int iphi=0; iphi<kBarlWedges; iphi++) {
160  EBDetId id((ieta+1)*thesign, iphi+1);
161  float y = -1 - ieta;
162  if(sign == 1) y = ieta;
163  barrel_m[0]->Fill(iphi, y, object()[id.rawId()].mult_x12);
164  barrel_r[0]->Fill(iphi, y, object()[id.rawId()].shift_x12);
165  barrel_m[1]->Fill(iphi, y, object()[id.rawId()].mult_x6);
166  barrel_r[1]->Fill(iphi, y, object()[id.rawId()].shift_x6);
167  barrel_m[2]->Fill(iphi, y, object()[id.rawId()].mult_x1);
168  barrel_r[2]->Fill(iphi, y, object()[id.rawId()].shift_x1);
169  } // iphi
170  } // ieta
171 
172  for (int ix=0; ix<kEndcWedgesX; ix++) {
173  for (int iy=0; iy<kEndcWedgesY; iy++) {
174  if (! EEDetId::validDetId(ix+1,iy+1,thesign)) continue;
175  EEDetId id(ix+1,iy+1,thesign);
176  if (thesign==1) {
177  endc_p_m[0]->Fill(ix+1,iy+1,object()[id.rawId()].mult_x12);
178  endc_p_r[0]->Fill(ix+1,iy+1,object()[id.rawId()].shift_x12);
179  endc_p_m[1]->Fill(ix+1,iy+1,object()[id.rawId()].mult_x6);
180  endc_p_r[1]->Fill(ix+1,iy+1,object()[id.rawId()].shift_x6);
181  endc_p_m[2]->Fill(ix+1,iy+1,object()[id.rawId()].mult_x1);
182  endc_p_r[2]->Fill(ix+1,iy+1,object()[id.rawId()].shift_x1);
183  }
184  else{
185  endc_m_m[0]->Fill(ix+1,iy+1,object()[id.rawId()].mult_x12);
186  endc_m_r[0]->Fill(ix+1,iy+1,object()[id.rawId()].shift_x12);
187  endc_m_m[1]->Fill(ix+1,iy+1,object()[id.rawId()].mult_x6);
188  endc_m_r[1]->Fill(ix+1,iy+1,object()[id.rawId()].shift_x6);
189  endc_m_m[2]->Fill(ix+1,iy+1,object()[id.rawId()].mult_x1);
190  endc_m_r[2]->Fill(ix+1,iy+1,object()[id.rawId()].shift_x1);
191  }
192  } // iy
193  } // ix
194  } // side
195 
196  //canvas.cd(1);
197  //float bmin[3] ={0.7, 0.5, 0.4};
198  //float bmax[3] ={1.7, 1.0, 0.8};
199  //float emin[3] ={1.5, 0.8, 0.4};
200  //float emax[3] ={2.5, 1.5, 0.8};
201  TLine* l = new TLine(0., 0., 0., 0.);
202  l->SetLineWidth(1);
203  int ixSectorsEE[202] = {
204  62, 62, 61, 61, 60, 60, 59, 59, 58, 58, 56, 56, 46, 46, 44, 44, 43, 43, 42, 42,
205  41, 41, 40, 40, 41, 41, 42, 42, 43, 43, 44, 44, 46, 46, 56, 56, 58, 58, 59, 59,
206  60, 60, 61, 61, 62, 62, 0,101,101, 98, 98, 96, 96, 93, 93, 88, 88, 86, 86, 81,
207  81, 76, 76, 66, 66, 61, 61, 41, 41, 36, 36, 26, 26, 21, 21, 16, 16, 14, 14, 9,
208  9, 6, 6, 4, 4, 1, 1, 4, 4, 6, 6, 9, 9, 14, 14, 16, 16, 21, 21, 26,
209  26, 36, 36, 41, 41, 61, 61, 66, 66, 76, 76, 81, 81, 86, 86, 88, 88, 93, 93, 96,
210  96, 98, 98,101,101, 0, 62, 66, 66, 71, 71, 81, 81, 91, 91, 93, 0, 62, 66, 66,
211  91, 91, 98, 0, 58, 61, 61, 66, 66, 71, 71, 76, 76, 81, 81, 0, 51, 51, 0, 44,
212  41, 41, 36, 36, 31, 31, 26, 26, 21, 21, 0, 40, 36, 36, 11, 11, 4, 0, 40, 36,
213  36, 31, 31, 21, 21, 11, 11, 9, 0, 46, 46, 41, 41, 36, 36, 0, 56, 56, 61, 61, 66, 66};
214 
215  int iySectorsEE[202] = {
216  51, 56, 56, 58, 58, 59, 59, 60, 60, 61, 61, 62, 62, 61, 61, 60, 60, 59, 59, 58,
217  58, 56, 56, 46, 46, 44, 44, 43, 43, 42, 42, 41, 41, 40, 40, 41, 41, 42, 42, 43,
218  43, 44, 44, 46, 46, 51, 0, 51, 61, 61, 66, 66, 76, 76, 81, 81, 86, 86, 88, 88,
219  93, 93, 96, 96, 98, 98,101,101, 98, 98, 96, 96, 93, 93, 88, 88, 86, 86, 81, 81,
220  76, 76, 66, 66, 61, 61, 41, 41, 36, 36, 26, 26, 21, 21, 16, 16, 14, 14, 9, 9,
221  6, 6, 4, 4, 1, 1, 4, 4, 6, 6, 9, 9, 14, 14, 16, 16, 21, 21, 26, 26,
222  36, 36, 41, 41, 51, 0, 46, 46, 41, 41, 36, 36, 31, 31, 26, 26, 0, 51, 51, 56,
223  56, 61, 61, 0, 61, 61, 66, 66, 71, 71, 76, 76, 86, 86, 88, 0, 62,101, 0, 61,
224  61, 66, 66, 71, 71, 76, 76, 86, 86, 88, 0, 51, 51, 56, 56, 61, 61, 0, 46, 46,
225  41, 41, 36, 36, 31, 31, 26, 26, 0, 40, 31, 31, 16, 16, 6, 0, 40, 31, 31, 16, 16, 6};
226 
227  for (int gId = 0; gId < 3; gId++) {
228  pad[gId][0]->cd();
229  endc_m_m[gId]->SetStats(0);
230  //endc_m_m[gId]->SetMaximum(225);
231  //endc_m_m[gId]->SetMinimum(175);
232  endc_m_m[gId]->Draw("colz");
233  for ( int i=0; i<201; i=i+1) {
234  if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
235  (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
236  l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
237  ixSectorsEE[i+1], iySectorsEE[i+1]);
238  l->SetLineWidth(0.2);
239  }
240  }
241  pad[gId + 3][0]->cd();
242  endc_m_r[gId]->SetStats(0);
243  //endc_m_r[gId]->SetMaximum(emax[gId]);
244  //endc_m_r[gId]->SetMinimum(emin[gId]);
245  endc_m_r[gId]->Draw("colz");
246  for ( int i=0; i<201; i=i+1) {
247  if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
248  (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
249  l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
250  ixSectorsEE[i+1], iySectorsEE[i+1]);
251  }
252  }
253  //canvas.cd(2);
254  pad[gId][1]->cd();
255  barrel_m[gId]->SetStats(0);
256  //barrel_m[gId]->SetMaximum(225);
257  //barrel_m[gId]->SetMinimum(175);
258  barrel_m[gId]->Draw("colz");
259  for(int i = 0; i <17; i++) {
260  Double_t x = 20.+ (i *20);
261  l = new TLine(x,-85.,x,86.);
262  l->Draw();
263  }
264  l = new TLine(0.,0.,360.,0.);
265  l->Draw();
266  pad[gId + 3][1]->cd();
267  barrel_r[gId]->SetStats(0);
268  //barrel_r[gId]->SetMaximum(bmax[gId]);
269  //barrel_r[gId]->SetMinimum(bmin[gId]);
270  barrel_r[gId]->Draw("colz");
271  for(int i = 0; i <17; i++) {
272  Double_t x = 20.+ (i *20);
273  l = new TLine(x,-85.,x,86.);
274  l->Draw();
275  }
276  l = new TLine(0.,0.,360.,0.);
277  l->Draw();
278  //canvas.cd(3);
279  pad[gId][2]->cd();
280  endc_p_m[gId]->SetStats(0);
281  //endc_p_m[gId]->SetMaximum(225);
282  //endc_p_m[gId]->SetMinimum(175);
283  endc_p_m[gId]->Draw("colz");
284  for ( int i=0; i<201; i=i+1) {
285  if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
286  (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
287  l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
288  ixSectorsEE[i+1], iySectorsEE[i+1]);
289  }
290  }
291  pad[gId + 3][2]->cd();
292  endc_p_r[gId]->SetStats(0);
293  //endc_p_r[gId]->SetMaximum(emax[gId]);
294  //endc_p_r[gId]->SetMinimum(emin[gId]);
295  endc_p_r[gId]->Draw("colz");
296  for ( int i=0; i<201; i=i+1) {
297  if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
298  (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
299  l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
300  ixSectorsEE[i+1], iySectorsEE[i+1]);
301  }
302  }
303  }
304 
305  canvas.SaveAs(filename.c_str());
306  return filename;
307  } // plot
308 
309 }
310 
int i
Definition: DBlmapReader.cc:9
static std::string dumpXML(const EcalCondHeader &header, const EcalTPGLinearizationConst &record)
std::string plot(std::string const &, std::string const &, std::vector< int > const &, std::vector< float > const &) const
int gainId(sample_type sample)
get the gainId (2 bits)
ExtractWhat< Class > What
static const int kBarlRings
std::vector< std::pair< std::string, float > > type_vValues
#define PYTHON_WRAPPER(_class, _name)
static const int kSides
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:303
type_vValues getValues(const std::vector< EcalObject > &vItems)
static const int MAX_IPHI
Definition: EBDetId.h:145
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:249
static const int MAX_IETA
Definition: EBDetId.h:144
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:307
Definition: DDAxes.h:10
std::string dump() const
static const int kEndcWedgesY