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