CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalTPGPedestalsPyWrapper.cc
Go to the documentation of this file.
2 //#include "CondTools/Ecal/interface/EcalTPGPedestalsXMLTranslator.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<EcalTPGPedestals>: public BaseValueExtractor<EcalTPGPedestals> {
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  class EcalTPGPedestalsHelper: public EcalPyWrapperHelper<EcalTPGPedestal>{
43  public:
45  protected:
46 
47  //change me
49 
50  type_vValues getValues( const std::vector<EcalObject> & vItems)
51  {
52  type_vValues vValues(total_values);
53 
54  //change us
55  vValues[0].first = "mean_x12";
56  vValues[1].first = "mean_x6";
57  vValues[2].first = "mean_x1";
58 
59  vValues[0].second = .0;
60  vValues[1].second = .0;
61  vValues[2].second = .0;
62 
63  //get info:
64  for(std::vector<EcalObject>::const_iterator iItems = vItems.begin(); iItems != vItems.end(); ++iItems){
65  //change us
66  vValues[0].second += iItems->mean_x12;
67  vValues[1].second += iItems->mean_x6;
68  vValues[2].second += iItems->mean_x1;
69  }
70  return vValues;
71  }
72  };
73 
74  template<>
76  std::stringstream ss;
78  ss << helper.printBarrelsEndcaps(object().barrelItems(), object().endcapItems());
79  return ss.str();
80  }
81 
82  template<>
84  std::string const &,
85  std::vector<int> const&,
86  std::vector<float> const& ) const {
87  gStyle->SetPalette(1);
88  const int TOTAL_IMAGES = 3;
89  const int TOTAL_PADS = 3;
90 
91  // TCanvas canvas("CC map","CC map",840,600);
92  const float IMG_SIZE = 1.3;
93  TCanvas canvas("CC map","CC map",800*IMG_SIZE + 100, 200 * TOTAL_IMAGES*IMG_SIZE);//800, 1200
94 
95  float xmi[3] = {0.0 , 0.22, 0.78};
96  float xma[3] = {0.22, 0.78, 1.00};
97 
98 
99  TPad*** pad = new TPad**[TOTAL_IMAGES];
100  for (int gId = 0; gId < TOTAL_IMAGES; gId++) {
101  pad[gId] = new TPad*[TOTAL_PADS];
102  for (int obj = 0; obj < TOTAL_PADS; obj++) {
103  float yma = 1. - (0.33 * gId); //1.- (0.17 * gId);
104  float ymi = yma - 0.33; //yma - 0.15;
105  pad[gId][obj] = new TPad(Form("p_%i_%i", obj, gId),Form("p_%i_%i", obj, gId),
106  xmi[obj], ymi, xma[obj], yma);
107  pad[gId][obj]->Draw();
108  }
109  }
110 
111  const int kGains = 3;
112  const int gainValues[3] = {12, 6, 1};
113  const int kSides = 2;
114  const int kBarlRings = EBDetId::MAX_IETA;
115  const int kBarlWedges = EBDetId::MAX_IPHI;
116  const int kEndcWedgesX = EEDetId::IX_MAX;
117  const int kEndcWedgesY = EEDetId::IY_MAX;
118 
119  TH2F** barrel_m = new TH2F*[3];
120  TH2F** endc_p_m = new TH2F*[3];
121  TH2F** endc_m_m = new TH2F*[3];
122  //TH2F** barrel_r = new TH2F*[3];
123  //TH2F** endc_p_r = new TH2F*[3];
124  //TH2F** endc_m_r = new TH2F*[3];
125  std::string variableName = "mean_x";
126  for (int gainId = 0; gainId < kGains; gainId++) {
127  barrel_m[gainId] = new TH2F(Form((variableName + "EBm%i").c_str(),gainId),Form((variableName + "%i EB").c_str(),gainValues[gainId]),360,0,360, 170, -85,85);
128  endc_p_m[gainId] = new TH2F(Form((variableName + "EE+m%i").c_str(),gainId),Form((variableName + "%i EE+").c_str(),gainValues[gainId]),100,1,101,100,1,101);
129  endc_m_m[gainId] = new TH2F(Form((variableName + "EE-m%i").c_str(),gainId),Form((variableName + "%i EE-").c_str(),gainValues[gainId]),100,1,101,100,1,101);
130  //barrel_r[gainId] = new TH2F(Form("EBr%i",gainId),Form("rms %i EB",gainValues[gainId]),360,0,360, 170, -85,85);
131  //endc_p_r[gainId] = new TH2F(Form("EE+r%i",gainId),Form("rms %i EE+",gainValues[gainId]),100,1,101,100,1,101);
132  //endc_m_r[gainId] = new TH2F(Form("EE-r%i",gainId),Form("rms %i EE-",gainValues[gainId]),100,1,101,100,1,101);
133  }
134 
135  for (int sign=0; sign < kSides; sign++) {
136  int thesign = sign==1 ? 1:-1;
137 
138  for (int ieta=0; ieta<kBarlRings; ieta++) {
139  for (int iphi=0; iphi<kBarlWedges; iphi++) {
140  EBDetId id((ieta+1)*thesign, iphi+1);
141  float y = -1 - ieta;
142  if(sign == 1) y = ieta;
143  barrel_m[0]->Fill(iphi, y, object()[id.rawId()].mean_x12);
144  barrel_m[1]->Fill(iphi, y, object()[id.rawId()].mean_x6);
145  barrel_m[2]->Fill(iphi, y, object()[id.rawId()].mean_x1);
146  //barrel_r[0]->Fill(iphi, y, object()[id.rawId()].rms_x12);
147  //barrel_m[1]->Fill(iphi, y, object()[id.rawId()].mean_x6);
148  //barrel_r[1]->Fill(iphi, y, object()[id.rawId()].rms_x6);
149  //barrel_m[2]->Fill(iphi, y, object()[id.rawId()].mean_x1);
150  //barrel_r[2]->Fill(iphi, y, object()[id.rawId()].rms_x1);
151  } // iphi
152  } // ieta
153 
154  for (int ix=0; ix<kEndcWedgesX; ix++) {
155  for (int iy=0; iy<kEndcWedgesY; iy++) {
156  if (! EEDetId::validDetId(ix+1,iy+1,thesign)) continue;
157  EEDetId id(ix+1,iy+1,thesign);
158  if (thesign==1) {
159  endc_p_m[0]->Fill(ix+1,iy+1,object()[id.rawId()].mean_x12);
160  endc_p_m[1]->Fill(ix+1,iy+1,object()[id.rawId()].mean_x6);
161  endc_p_m[2]->Fill(ix+1,iy+1,object()[id.rawId()].mean_x1);
162  //endc_p_r[0]->Fill(ix+1,iy+1,object()[id.rawId()].rms_x12);
163  //endc_p_m[1]->Fill(ix+1,iy+1,object()[id.rawId()].mean_x6);
164  //endc_p_r[1]->Fill(ix+1,iy+1,object()[id.rawId()].rms_x6);
165  //endc_p_m[2]->Fill(ix+1,iy+1,object()[id.rawId()].mean_x1);
166  //endc_p_r[2]->Fill(ix+1,iy+1,object()[id.rawId()].rms_x1);
167  }
168  else{
169  endc_m_m[0]->Fill(ix+1,iy+1,object()[id.rawId()].mean_x12);
170  endc_m_m[1]->Fill(ix+1,iy+1,object()[id.rawId()].mean_x6);
171  endc_m_m[2]->Fill(ix+1,iy+1,object()[id.rawId()].mean_x1);
172  //endc_m_r[0]->Fill(ix+1,iy+1,object()[id.rawId()].rms_x12);
173  //endc_m_m[1]->Fill(ix+1,iy+1,object()[id.rawId()].mean_x6);
174  //endc_m_r[1]->Fill(ix+1,iy+1,object()[id.rawId()].rms_x6);
175  //endc_m_m[2]->Fill(ix+1,iy+1,object()[id.rawId()].mean_x1);
176  //endc_m_r[2]->Fill(ix+1,iy+1,object()[id.rawId()].rms_x1);
177  }
178  } // iy
179  } // ix
180  } // side
181 
182  //canvas.cd(1);
183  //float bmin[3] ={0.7, 0.5, 0.4};
184  //float bmax[3] ={1.7, 1.0, 0.8};
185  //float emin[3] ={1.5, 0.8, 0.4};
186  //float emax[3] ={2.5, 1.5, 0.8};
187  TLine* l = new TLine(0., 0., 0., 0.);
188  l->SetLineWidth(1);
189  int ixSectorsEE[202] = {
190  62, 62, 61, 61, 60, 60, 59, 59, 58, 58, 56, 56, 46, 46, 44, 44, 43, 43, 42, 42,
191  41, 41, 40, 40, 41, 41, 42, 42, 43, 43, 44, 44, 46, 46, 56, 56, 58, 58, 59, 59,
192  60, 60, 61, 61, 62, 62, 0,101,101, 98, 98, 96, 96, 93, 93, 88, 88, 86, 86, 81,
193  81, 76, 76, 66, 66, 61, 61, 41, 41, 36, 36, 26, 26, 21, 21, 16, 16, 14, 14, 9,
194  9, 6, 6, 4, 4, 1, 1, 4, 4, 6, 6, 9, 9, 14, 14, 16, 16, 21, 21, 26,
195  26, 36, 36, 41, 41, 61, 61, 66, 66, 76, 76, 81, 81, 86, 86, 88, 88, 93, 93, 96,
196  96, 98, 98,101,101, 0, 62, 66, 66, 71, 71, 81, 81, 91, 91, 93, 0, 62, 66, 66,
197  91, 91, 98, 0, 58, 61, 61, 66, 66, 71, 71, 76, 76, 81, 81, 0, 51, 51, 0, 44,
198  41, 41, 36, 36, 31, 31, 26, 26, 21, 21, 0, 40, 36, 36, 11, 11, 4, 0, 40, 36,
199  36, 31, 31, 21, 21, 11, 11, 9, 0, 46, 46, 41, 41, 36, 36, 0, 56, 56, 61, 61, 66, 66};
200 
201  int iySectorsEE[202] = {
202  51, 56, 56, 58, 58, 59, 59, 60, 60, 61, 61, 62, 62, 61, 61, 60, 60, 59, 59, 58,
203  58, 56, 56, 46, 46, 44, 44, 43, 43, 42, 42, 41, 41, 40, 40, 41, 41, 42, 42, 43,
204  43, 44, 44, 46, 46, 51, 0, 51, 61, 61, 66, 66, 76, 76, 81, 81, 86, 86, 88, 88,
205  93, 93, 96, 96, 98, 98,101,101, 98, 98, 96, 96, 93, 93, 88, 88, 86, 86, 81, 81,
206  76, 76, 66, 66, 61, 61, 41, 41, 36, 36, 26, 26, 21, 21, 16, 16, 14, 14, 9, 9,
207  6, 6, 4, 4, 1, 1, 4, 4, 6, 6, 9, 9, 14, 14, 16, 16, 21, 21, 26, 26,
208  36, 36, 41, 41, 51, 0, 46, 46, 41, 41, 36, 36, 31, 31, 26, 26, 0, 51, 51, 56,
209  56, 61, 61, 0, 61, 61, 66, 66, 71, 71, 76, 76, 86, 86, 88, 0, 62,101, 0, 61,
210  61, 66, 66, 71, 71, 76, 76, 86, 86, 88, 0, 51, 51, 56, 56, 61, 61, 0, 46, 46,
211  41, 41, 36, 36, 31, 31, 26, 26, 0, 40, 31, 31, 16, 16, 6, 0, 40, 31, 31, 16, 16, 6};
212 
213  for (int gId = 0; gId < TOTAL_IMAGES; gId++) {//was 3
214  pad[gId][0]->cd();
215  endc_m_m[gId]->SetStats(0);
216  //endc_m_m[gId]->SetMaximum(225);
217  //endc_m_m[gId]->SetMinimum(175);
218  endc_m_m[gId]->Draw("colz");
219  for ( int i=0; i<201; i=i+1) {
220  if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
221  (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
222  l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
223  ixSectorsEE[i+1], iySectorsEE[i+1]);
224  l->SetLineWidth(0.2);
225  }
226  }
227 
228  //pad[gId + 3][0]->cd();
229  //endc_m_r[gId]->SetStats(0);
230  //endc_m_r[gId]->SetMaximum(emax[gId]);
231  //endc_m_r[gId]->SetMinimum(emin[gId]);
232  //endc_m_r[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  // }
239  //}
240 
241  //canvas.cd(2);
242  pad[gId][1]->cd();
243  barrel_m[gId]->SetStats(0);
244  //barrel_m[gId]->SetMaximum(225);
245  //barrel_m[gId]->SetMinimum(175);
246  barrel_m[gId]->Draw("colz");
247  for(int i = 0; i <17; i++) {
248  Double_t x = 20.+ (i *20);
249  l = new TLine(x,-85.,x,86.);
250  l->Draw();
251  }
252  l = new TLine(0.,0.,360.,0.);
253  l->Draw();
254 
255  //pad[gId + 3][1]->cd();
256  //barrel_r[gId]->SetStats(0);
257  //barrel_r[gId]->SetMaximum(bmax[gId]);
258  //barrel_r[gId]->SetMinimum(bmin[gId]);
259  //barrel_r[gId]->Draw("colz");
260  //for(int i = 0; i <17; i++) {
261  // Double_t x = 20.+ (i *20);
262  // l = new TLine(x,-85.,x,86.);
263  // l->Draw();
264  //}
265  //l = new TLine(0.,0.,360.,0.);
266  //l->Draw();
267 
268  //canvas.cd(3);
269  pad[gId][2]->cd();
270  endc_p_m[gId]->SetStats(0);
271  //endc_p_m[gId]->SetMaximum(225);
272  //endc_p_m[gId]->SetMinimum(175);
273  endc_p_m[gId]->Draw("colz");
274  for ( int i=0; i<201; i=i+1) {
275  if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
276  (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
277  l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
278  ixSectorsEE[i+1], iySectorsEE[i+1]);
279  }
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
double sign(double x)
#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
type_vValues getValues(const std::vector< EcalObject > &vItems)
static const int IX_MAX
Definition: EEDetId.h:302
static const int MAX_IPHI
Definition: EBDetId.h:144
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
static const int MAX_IETA
Definition: EBDetId.h:143
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:306
Definition: DDAxes.h:10
static const int kEndcWedgesY