CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalLaserAPDPNRatiosPyWrapper.cc
Go to the documentation of this file.
1 
3 
6 #include "TH2F.h"
7 #include "TCanvas.h"
8 #include "TLine.h"
9 #include "TStyle.h"
10 #include "TPave.h"
11 #include "TPaveStats.h"
14 
17 
18 
19 #include <time.h>
20 #include <string>
21 #include <fstream>
22 
24 
25 
26 
27 namespace cond {
28 
29  template<>
30  class ValueExtractor<EcalLaserAPDPNRatios>: public BaseValueExtractor<EcalLaserAPDPNRatios> {
31  public:
32 
35  static What what() { return What();}
36 
39  {
40  // here one can make stuff really complicated...
41  }
42  void compute(Class const & it) override{
43  }
44  private:
45 
46  };
47 
48 
49  template<>
52 
53  std::stringstream ss;
54  EcalCondHeader header;
55  ss<<EcalLaserAPDPNRatiosXMLTranslator::dumpXML(header,object());
56  return ss.str();
57 
58  }
59 
60 
61 
62  class EcalLaserAPDPNRatiosHelper: public EcalPyWrapperHelper<EcalLaserAPDPNRatios::EcalLaserAPDPNpair>{
63  public:
65  protected:
67  type_vValues getValues( const std::vector<EcalLaserAPDPNRatios::EcalLaserAPDPNpair> & vItems) override
68  {
69  //unsigned int totalValues = 6;
70  type_vValues vValues(total_values);
71 
72  vValues[0].first = "p1";
73  vValues[1].first = "p2";
74  vValues[2].first = "p3";
75 
76  vValues[0].second = .0;
77  vValues[1].second = .0;
78  vValues[2].second = .0;
79 
80 
81  //get info:
82  for(std::vector<EcalLaserAPDPNRatios::EcalLaserAPDPNpair>::const_iterator iItems = vItems.begin(); iItems != vItems.end(); ++iItems){
83  vValues[0].second += iItems->p1;
84  vValues[1].second += iItems->p2;
85  vValues[2].second += iItems->p3;
86 
87  }
88  return vValues;
89  }
90  };
91 
92 
93 
94 
95 
96  template<>
98  std::stringstream ss;
99 
100 
102  ss << helper.printBarrelsEndcaps(object().getLaserMap().barrelItems(), object().getLaserMap().endcapItems());
103  ss<< std::endl;
104 
105 
106  const EcalLaserAPDPNRatios::EcalLaserTimeStampMap& laserTimeMap =
107  object().getTimeMap();
108 
109 
110  for (int i=0; i<92; i++) {
112 
113 
114  unsigned int x1= ((timestamp.t1).value() >> 32) ;
115  std::time_t tt1 = x1;
116 
117 
118  ss<<"T1["<<i<<"]=" << timestamp.t1.value()<<" "<< x1<< std::ctime(&tt1) ;
119 
120  unsigned int x2= (timestamp.t2).value() >> 32;
121  std::time_t tt2 = x2;
122 
123  ss<<" T2["<<i<<"]=" << timestamp.t2.value()<< " "<<x2<<std::ctime(&tt2) ;
124 
125  unsigned int x3= (timestamp.t3).value() >> 32 ;
126  std::time_t tt3 = x3;
127 
128  ss <<" T3["<<i<<"]=" << timestamp.t3.value()<<" "<< x3<< std::ctime(&tt3) << std::endl;
129 
130  }
131 
132  return ss.str();
133  return ss.str();
134  }
135 
136 
137 
138  template<>
140  std::string const &,
141  std::vector<int> const&,
142  std::vector<float> const& ) const {
143  gStyle->SetPalette(1);
144  // TCanvas canvas("CC map","CC map",840,600);
145  TCanvas canvas("CC map","CC map",800,1200);
146 
147  float xmi[3] = {0.0 , 0.22, 0.78};
148  float xma[3] = {0.22, 0.78, 1.00};
149  TPad*** pad = new TPad**[3];
150  for (int gId = 0; gId < 3; gId++) {
151  pad[gId] = new TPad*[3];
152  for (int obj = 0; obj < 3; obj++) {
153  float yma = 1.- (0.32 * gId);
154  float ymi = yma - 0.30;
155  pad[gId][obj] = new TPad(Form("p_%i_%i", obj, gId),Form("p_%i_%i", obj, gId),
156  xmi[obj], ymi, xma[obj], yma);
157  pad[gId][obj]->Draw();
158  }
159  }
160 
161  const int kGains = 3;
162  const int gainValues[3] = {1, 2, 3};
163  const int kSides = 2;
164  const int kBarlRings = EBDetId::MAX_IETA;
165  const int kBarlWedges = EBDetId::MAX_IPHI;
166  const int kEndcWedgesX = EEDetId::IX_MAX;
167  const int kEndcWedgesY = EEDetId::IY_MAX;
168 
169  TH2F** barrel = new TH2F*[3];
170  TH2F** endc_p = new TH2F*[3];
171  TH2F** endc_m = new TH2F*[3];
172 
173  for (int gainId = 0; gainId < kGains; gainId++) {
174  barrel[gainId] = new TH2F(Form("EBp%i", gainValues[gainId]),Form("EBp%i", gainValues[gainId]),360,0,360, 170, -85,85);
175  endc_p[gainId] = new TH2F(Form("EE+p%i",gainValues[gainId]),Form("EE+p%i",gainValues[gainId]),100,1,101,100,1,101);
176  endc_m[gainId] = new TH2F(Form("EE-p%i",gainValues[gainId]),Form("EE-p%i",gainValues[gainId]),100,1,101,100,1,101);
177 
178  }
179 
180  for (int sign=0; sign < kSides; sign++) {
181  int thesign = sign==1 ? 1:-1;
182 
183  for (int ieta=0; ieta<kBarlRings; ieta++) {
184  for (int iphi=0; iphi<kBarlWedges; iphi++) {
185  EBDetId id((ieta+1)*thesign, iphi+1);
186  float y = -1 - ieta;
187  if(sign == 1) y = ieta;
188  barrel[0]->Fill(iphi, y, object().getLaserMap()[id.rawId()].p1);
189  barrel[1]->Fill(iphi, y, object().getLaserMap()[id.rawId()].p2);
190  barrel[2]->Fill(iphi, y, object().getLaserMap()[id.rawId()].p3);
191 
192  } // iphi
193  } // ieta
194 
195  for (int ix=0; ix<kEndcWedgesX; ix++) {
196  for (int iy=0; iy<kEndcWedgesY; iy++) {
197  if (! EEDetId::validDetId(ix+1,iy+1,thesign)) continue;
198  EEDetId id(ix+1,iy+1,thesign);
199  if (thesign==1) {
200  endc_p[0]->Fill(ix+1,iy+1,object().getLaserMap()[id.rawId()].p1);
201  endc_p[1]->Fill(ix+1,iy+1,object().getLaserMap()[id.rawId()].p2);
202  endc_p[2]->Fill(ix+1,iy+1,object().getLaserMap()[id.rawId()].p3);
203 
204  }
205  else{
206  endc_m[0]->Fill(ix+1,iy+1,object().getLaserMap()[id.rawId()].p1);
207  endc_m[1]->Fill(ix+1,iy+1,object().getLaserMap()[id.rawId()].p2);
208  endc_m[2]->Fill(ix+1,iy+1,object().getLaserMap()[id.rawId()].p3);
209 
210  }
211  } // iy
212  } // ix
213  } // side
214 
215  //canvas.cd(1);
216 
217  TLine* l = new TLine(0., 0., 0., 0.);
218  l->SetLineWidth(1);
219  int ixSectorsEE[202] = {
220  62, 62, 61, 61, 60, 60, 59, 59, 58, 58, 56, 56, 46, 46, 44, 44, 43, 43, 42, 42,
221  41, 41, 40, 40, 41, 41, 42, 42, 43, 43, 44, 44, 46, 46, 56, 56, 58, 58, 59, 59,
222  60, 60, 61, 61, 62, 62, 0,101,101, 98, 98, 96, 96, 93, 93, 88, 88, 86, 86, 81,
223  81, 76, 76, 66, 66, 61, 61, 41, 41, 36, 36, 26, 26, 21, 21, 16, 16, 14, 14, 9,
224  9, 6, 6, 4, 4, 1, 1, 4, 4, 6, 6, 9, 9, 14, 14, 16, 16, 21, 21, 26,
225  26, 36, 36, 41, 41, 61, 61, 66, 66, 76, 76, 81, 81, 86, 86, 88, 88, 93, 93, 96,
226  96, 98, 98,101,101, 0, 62, 66, 66, 71, 71, 81, 81, 91, 91, 93, 0, 62, 66, 66,
227  91, 91, 98, 0, 58, 61, 61, 66, 66, 71, 71, 76, 76, 81, 81, 0, 51, 51, 0, 44,
228  41, 41, 36, 36, 31, 31, 26, 26, 21, 21, 0, 40, 36, 36, 11, 11, 4, 0, 40, 36,
229  36, 31, 31, 21, 21, 11, 11, 9, 0, 46, 46, 41, 41, 36, 36, 0, 56, 56, 61, 61, 66, 66};
230 
231  int iySectorsEE[202] = {
232  51, 56, 56, 58, 58, 59, 59, 60, 60, 61, 61, 62, 62, 61, 61, 60, 60, 59, 59, 58,
233  58, 56, 56, 46, 46, 44, 44, 43, 43, 42, 42, 41, 41, 40, 40, 41, 41, 42, 42, 43,
234  43, 44, 44, 46, 46, 51, 0, 51, 61, 61, 66, 66, 76, 76, 81, 81, 86, 86, 88, 88,
235  93, 93, 96, 96, 98, 98,101,101, 98, 98, 96, 96, 93, 93, 88, 88, 86, 86, 81, 81,
236  76, 76, 66, 66, 61, 61, 41, 41, 36, 36, 26, 26, 21, 21, 16, 16, 14, 14, 9, 9,
237  6, 6, 4, 4, 1, 1, 4, 4, 6, 6, 9, 9, 14, 14, 16, 16, 21, 21, 26, 26,
238  36, 36, 41, 41, 51, 0, 46, 46, 41, 41, 36, 36, 31, 31, 26, 26, 0, 51, 51, 56,
239  56, 61, 61, 0, 61, 61, 66, 66, 71, 71, 76, 76, 86, 86, 88, 0, 62,101, 0, 61,
240  61, 66, 66, 71, 71, 76, 76, 86, 86, 88, 0, 51, 51, 56, 56, 61, 61, 0, 46, 46,
241  41, 41, 36, 36, 31, 31, 26, 26, 0, 40, 31, 31, 16, 16, 6, 0, 40, 31, 31, 16, 16, 6};
242 
243  for (int gId = 0; gId < 3; gId++) {
244  pad[gId][0]->cd();
245  endc_m[gId]->SetStats(0);
246 
247  endc_m[gId]->GetZaxis()->SetRangeUser(0.9,1.1);
248  endc_m[gId]->Draw("colz");
249  for ( int i=0; i<201; i=i+1) {
250  if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
251  (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
252  l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
253  ixSectorsEE[i+1], iySectorsEE[i+1]);
254  l->SetLineWidth(0.2);
255  }
256  }
257  pad[gId][1]->cd();
258  barrel[gId]->SetStats(0);
259  barrel[gId]->GetZaxis()->SetRangeUser(0.9,1.1);
260 
261  barrel[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 
270  //canvas.cd(3);
271  pad[gId][2]->cd();
272  endc_p[gId]->SetStats(0);
273  endc_p[gId]->GetZaxis()->SetRangeUser(0.9,1.1);
274 
275  endc_p[gId]->Draw("colz");
276  for ( int i=0; i<201; i=i+1) {
277  if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
278  (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
279  l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
280  ixSectorsEE[i+1], iySectorsEE[i+1]);
281  }
282  }
283  }
284 
285  canvas.SaveAs(filename.c_str());
286  return filename;
287  } // plot
288 
289 
290 
291 
292 
293 
294 }
295 
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)
static std::string dumpXML(const EcalCondHeader &header, const EcalLaserAPDPNRatios &record)
#define PYTHON_WRAPPER(_class, _name)
static const int kSides
EcalLaserAPDPNRatios::EcalLaserAPDPNpair EcalObject
def canvas
Definition: svgfig.py:481
static const int kBarlWedges
T x() const
Cartesian x coordinate.
std::string summary() const
static const int kEndcWedgesX
type_vValues getValues(const std::vector< EcalLaserAPDPNRatios::EcalLaserAPDPNpair > &vItems) override
double p2[4]
Definition: TauolaWrapper.h:90
static const int IX_MAX
Definition: EEDetId.h:302
static const int MAX_IPHI
Definition: EBDetId.h:144
std::vector< EcalLaserTimeStamp > EcalLaserTimeStampMap
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
static const int MAX_IETA
Definition: EBDetId.h:143
list object
Definition: dbtoconf.py:77
double p1[4]
Definition: TauolaWrapper.h:89
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
std::string dump() const
TimeValue_t value() const
Definition: Timestamp.h:56
double p3[4]
Definition: TauolaWrapper.h:91
static const int kEndcWedgesY