CMS 3D CMS Logo

SiStripApvGain_PayloadInspector.cc
Go to the documentation of this file.
1 
12 
13 // the data format of the condition to be inspected
18 
19 // needed for the tracker map
21 
22 // auxilliary functions
25 
26 #include <memory>
27 #include <sstream>
28 #include <iostream>
29 
30 // include ROOT
31 #include "TProfile.h"
32 #include "TH2F.h"
33 #include "TLegend.h"
34 #include "TCanvas.h"
35 #include "TLine.h"
36 #include "TStyle.h"
37 #include "TLatex.h"
38 #include "TPave.h"
39 #include "TPaveStats.h"
40 
41 namespace {
42 
43  /************************************************
44  1d histogram of SiStripApvGains of 1 IOV
45  *************************************************/
46 
47  // inherit from one of the predefined plot class: Histogram1D
48  class SiStripApvGainsValue : public cond::payloadInspector::Histogram1D<SiStripApvGain> {
49 
50  public:
51  SiStripApvGainsValue() : cond::payloadInspector::Histogram1D<SiStripApvGain>("SiStripApv Gains values",
52  "SiStripApv Gains values", 200,0.0,2.0){
53  Base::setSingleIov( true );
54  }
55 
56  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
57  for ( auto const & iov: iovs) {
58  std::shared_ptr<SiStripApvGain> payload = Base::fetchPayload( std::get<1>(iov) );
59  if( payload.get() ){
60 
61  std::vector<uint32_t> detid;
62  payload->getDetIds(detid);
63 
64  for (const auto & d : detid) {
65  SiStripApvGain::Range range=payload->getRange(d);
66  for(int it=0;it<range.second-range.first;it++){
67 
68  // to be used to fill the histogram
69  fillWithValue(payload->getApvGain(it,range));
70 
71  }// loop over APVs
72  } // loop over detIds
73  }// payload
74  }// iovs
75  return true;
76  }// fill
77  };
78 
79  /************************************************
80  1d histogram of means of SiStripApvGains
81  for Tracker Barrel of 1 IOV
82  *************************************************/
83 
84  // inherit from one of the predefined plot class: Histogram1D
85  class SiStripApvBarrelGainsByLayer : public cond::payloadInspector::Histogram1D<SiStripApvGain> {
86 
87  public:
88  SiStripApvBarrelGainsByLayer() : cond::payloadInspector::Histogram1D<SiStripApvGain>("SiStripApv Gains averages by Barrel layer",
89  "Barrel layer (0-3: TIB), (4-9: TOB)",10,0,10,"average SiStripApv Gain"){
90  Base::setSingleIov( true );
91  }
92 
93  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
94  for ( auto const & iov: iovs) {
95  std::shared_ptr<SiStripApvGain> payload = Base::fetchPayload( std::get<1>(iov) );
96  if( payload.get() ){
97 
98  TrackerTopology tTopo = StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath());
99 
100  std::vector<uint32_t> detid;
101  payload->getDetIds(detid);
102 
103  std::map<int,std::pair<float,float> > sumOfGainsByLayer;
104 
105  for (const auto & d : detid) {
106 
107  int subid = DetId(d).subdetId();
108  int layer(-1);
109  if(subid!=StripSubdetector::TIB && subid!=StripSubdetector::TOB) continue;
110  if(subid==StripSubdetector::TIB){
111  layer = tTopo.tibLayer(d);
112  } else if(subid==StripSubdetector::TOB){
113  // layers of TOB start at 5th bin
114  layer = tTopo.tobLayer(d);
115  layer+=4;
116  }
117 
118  SiStripApvGain::Range range=payload->getRange(d);
119  for(int it=0;it<range.second-range.first;it++){
120  sumOfGainsByLayer[layer].first+=payload->getApvGain(it,range);
121  sumOfGainsByLayer[layer].second+=1.;
122  }// loop over APVs
123  } // loop over detIds
124 
125  // loop on the map to fill the plot
126  for (auto& data : sumOfGainsByLayer){
127 
128  fillWithBinAndValue(data.first-1,(data.second.first/data.second.second));
129  }
130 
131  }// payload
132  }// iovs
133  return true;
134  }// fill
135  };
136 
137  /************************************************
138  2d histogram of absolute (i.e. not average)
139  SiStripApvGains for Tracker Barrel of 1 IOV
140  *************************************************/
141 
142  class SiStripApvAbsoluteBarrelGainsByLayer : public cond::payloadInspector::Histogram2D<SiStripApvGain> {
143  public:
144  SiStripApvAbsoluteBarrelGainsByLayer() : cond::payloadInspector::Histogram2D<SiStripApvGain>("SiStripApv Gains by Barrel layer", "Barrel layer (0-3: TIB), (4-9: TOB)", 10, 0, 10, "SiStripApv Gain", 200, 0.0, 2.0){
145  Base::setSingleIov(true);
146  }
147 
148 
149  bool fill (const std::vector< std::tuple<cond::Time_t,cond::Hash> >& iovs) override{
150  for (auto const& iov: iovs){
151  std::shared_ptr<SiStripApvGain> payload = Base::fetchPayload (std::get<1>(iov));
152  if (payload.get()){
153 
154  TrackerTopology tTopo = StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath());
155 
156  std::vector<uint32_t> detid;
157  payload->getDetIds(detid);
158  for (const auto & d : detid){
159  int subid = DetId(d).subdetId();
160  if (subid!=3 && subid!=5) continue;
161 
162  SiStripApvGain::Range range = payload->getRange(d);
163  for (int it=0;it<range.second-range.first;it++){
164  float gain = payload->getApvGain(it, range);
165  fillWithValue(static_cast<float>((subid == 5) ? tTopo.tobLayer(d)+3 : tTopo.tibLayer(d)-1),
166  (gain > 2.0)?2.0:gain);
167  }
168  }//loop over detIds
169  }// loop over payloads
170  }// loop over iovs
171  return true;
172  }// fill
173  };
174 
175 
176  /************************************************
177  1d histogram of means of SiStripApvGains
178  for Tracker Endcaps (minus side) of 1 IOV
179  *************************************************/
180 
181  // inherit from one of the predefined plot class: Histogram1D
182  class SiStripApvEndcapMinusGainsByDisk : public cond::payloadInspector::Histogram1D<SiStripApvGain> {
183 
184  public:
185  SiStripApvEndcapMinusGainsByDisk() : cond::payloadInspector::Histogram1D<SiStripApvGain>("SiStripApv Gains averages by Endcap (minus) disk",
186  "Endcap (minus) disk (0-2: TID), (3-11: TEC)",12,0,12,"average SiStripApv Gain"){
187  Base::setSingleIov( true );
188  }
189 
190  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
191  for ( auto const & iov: iovs) {
192  std::shared_ptr<SiStripApvGain> payload = Base::fetchPayload( std::get<1>(iov) );
193  if( payload.get() ){
194 
195  TrackerTopology tTopo = StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath());
196 
197  std::vector<uint32_t> detid;
198  payload->getDetIds(detid);
199 
200  std::map<int,std::pair<float,float> > sumOfGainsByDisk;
201 
202  for (const auto & d : detid) {
203 
204  int disk=-1;
205  int side=-1;
206  int subid = DetId(d).subdetId();
207  if(subid!=StripSubdetector::TID && subid!=StripSubdetector::TEC) continue;
208 
209  if(subid==StripSubdetector::TID){
210  side = tTopo.tidSide(d);
211  disk = tTopo.tidWheel(d);
212  } else {
213  side = tTopo.tecSide(d);
214  disk = tTopo.tecWheel(d);
215  // disks of TEC start at 4th bin
216  disk+=3;
217  }
218 
219  // only negative side
220  if(side!=1) continue;
221 
222  SiStripApvGain::Range range=payload->getRange(d);
223  for(int it=0;it<range.second-range.first;it++){
224  sumOfGainsByDisk[disk].first+=payload->getApvGain(it,range);
225  sumOfGainsByDisk[disk].second+=1.;
226  }// loop over APVs
227  } // loop over detIds
228 
229  // loop on the map to fill the plot
230  for (auto& data : sumOfGainsByDisk){
231  fillWithBinAndValue(data.first-1,(data.second.first/data.second.second));
232  }
233 
234  }// payload
235  }// iovs
236  return true;
237  }// fill
238  };
239 
240  /************************************************
241  1d histogram of means of SiStripApvGains
242  for Tracker Endcaps (plus side) of 1 IOV
243  *************************************************/
244 
245  // inherit from one of the predefined plot class: Histogram1D
246  class SiStripApvEndcapPlusGainsByDisk : public cond::payloadInspector::Histogram1D<SiStripApvGain> {
247 
248  public:
249  SiStripApvEndcapPlusGainsByDisk() : cond::payloadInspector::Histogram1D<SiStripApvGain>("SiStripApv Gains averages by Endcap (plus) disk",
250  "Endcap (plus) disk (0-2: TID), (3-11: TEC)",12,0,12,"average SiStripApv Gain"){
251  Base::setSingleIov( true );
252  }
253 
254  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
255  for ( auto const & iov: iovs) {
256  std::shared_ptr<SiStripApvGain> payload = Base::fetchPayload( std::get<1>(iov) );
257  if( payload.get() ){
258 
259  TrackerTopology tTopo = StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath());
260 
261  std::vector<uint32_t> detid;
262  payload->getDetIds(detid);
263 
264  std::map<int,std::pair<float,float> > sumOfGainsByDisk;
265 
266  for (const auto & d : detid) {
267 
268  int disk=-1;
269  int side=-1;
270  int subid = DetId(d).subdetId();
271  if(subid!=StripSubdetector::TID && subid!=StripSubdetector::TEC) continue;
272 
273  if(subid==StripSubdetector::TID){
274  side = tTopo.tidSide(d);
275  disk = tTopo.tidWheel(d);;
276  } else {
277  side = tTopo.tecSide(d);
278  disk = tTopo.tecWheel(d);
279  // disks of TEC start at 4th bin
280  disk+=3;
281  }
282 
283  // only positive side
284  if(side!=2) continue;
285 
286  SiStripApvGain::Range range=payload->getRange(d);
287  for(int it=0;it<range.second-range.first;it++){
288  sumOfGainsByDisk[disk].first+=payload->getApvGain(it,range);
289  sumOfGainsByDisk[disk].second+=1.;
290  }// loop over APVs
291  } // loop over detIds
292 
293  // loop on the map to fill the plot
294  for (auto& data : sumOfGainsByDisk){
295  fillWithBinAndValue(data.first-1,(data.second.first/data.second.second));
296  }
297 
298  }// payload
299  }// iovs
300  return true;
301  }// fill
302  };
303 
304  /************************************************
305  2D histogram of absolute (i.e. not average)
306  SiStripApv Gains on the Endcap- for 1 IOV
307  ************************************************/
308  class SiStripApvAbsoluteEndcapMinusGainsByDisk : public cond::payloadInspector::Histogram2D<SiStripApvGain> {
309  public:
310  SiStripApvAbsoluteEndcapMinusGainsByDisk() : cond::payloadInspector::Histogram2D<SiStripApvGain>(
311  "SiStripApv Gains averages by Endcap (minus) disk",
312  "Endcap (minus) disk (0-2: TID), (3-11: TEC)",12,0,12,
313  "SiStripApv Gain", 200, 0.0, 2.0){
314  Base::setSingleIov(true);
315  }
316 
317  bool fill (const std::vector< std::tuple<cond::Time_t,cond::Hash> >& iovs) override{
318  for (auto const& iov: iovs) {
319  std::shared_ptr<SiStripApvGain> payload = Base::fetchPayload( std::get<1>(iov) );
320  if( payload.get() ){
321 
322  TrackerTopology tTopo = StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath());
323 
324  std::vector<uint32_t> detid;
325  payload->getDetIds(detid);
326 
327  for (const auto & d : detid){
328  int subid = DetId(d).subdetId(),
329  side = -1,
330  disk = -1;
331 
332  switch (subid){
333  case 4: side = tTopo.tidSide(d); disk = tTopo.tidWheel(d) ; break;
334  case 6: side = tTopo.tecSide(d); disk = tTopo.tecWheel(d) + 4 ; break;
335  default: continue;
336  }
337 
338  if (side!=1) continue;
339  SiStripApvGain::Range range = payload->getRange(d);
340  for (int it=0;it<range.second-range.first;it++){
341  float gain = payload->getApvGain(it, range);
342  fillWithValue((float) disk-1, (gain>2.0)?2.0:gain);
343  }// apvs
344  }// detids
345  }
346  }// iovs
347  return true;
348  }// fill
349  };
350 
351  /************************************************
352  2D histogram of absolute (i.e. not average)
353  SiStripApv Gains on the Endcap+ for 1 IOV
354  ************************************************/
355  class SiStripApvAbsoluteEndcapPlusGainsByDisk : public cond::payloadInspector::Histogram2D<SiStripApvGain> {
356  public:
357  SiStripApvAbsoluteEndcapPlusGainsByDisk() : cond::payloadInspector::Histogram2D<SiStripApvGain>(
358  "SiStripApv Gains averages by Endcap (plus) disk",
359  "Endcap (plus) disk (0-2: TID), (3-11: TEC)",12,0,12,
360  "SiStripApv Gain", 200, 0.0, 2.0){
361  Base::setSingleIov(true);
362  }
363 
364  bool fill (const std::vector< std::tuple<cond::Time_t,cond::Hash> >& iovs) override{
365  for (auto const& iov: iovs) {
366  std::shared_ptr<SiStripApvGain> payload = Base::fetchPayload( std::get<1>(iov) );
367  if( payload.get() ){
368 
369  TrackerTopology tTopo = StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath());
370 
371  std::vector<uint32_t> detid;
372  payload->getDetIds(detid);
373 
374  for (const auto & d : detid){
375  int subid = DetId(d).subdetId(),
376  side = -1,
377  disk = -1;
378 
379  switch (subid){
380  case 4: side = tTopo.tidSide(d); disk = tTopo.tidWheel(d) ; break;
381  case 6: side = tTopo.tecSide(d); disk = tTopo.tecWheel(d) + 4 ; break;
382  default: continue;
383  }
384 
385  if (side!=2) continue;
386  SiStripApvGain::Range range = payload->getRange(d);
387  for (int it=0;it<range.second-range.first;it++){
388  float gain = payload->getApvGain(it, range);
389  fillWithValue((float) disk-1, (gain>2.0)?2.0:gain);
390  }//apvs
391  }//detids
392  }
393  }// iovs
394  return true;
395  }// fill
396  };
397 
398  /************************************************
399  TrackerMap of SiStripApvGains (average gain per detid)
400  *************************************************/
401  class SiStripApvGainsAverageTrackerMap : public cond::payloadInspector::PlotImage<SiStripApvGain> {
402  public:
403  SiStripApvGainsAverageTrackerMap() : cond::payloadInspector::PlotImage<SiStripApvGain>( "Tracker Map of average SiStripGains" ){
404  setSingleIov( true );
405  }
406 
407  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
408  auto iov = iovs.front();
409  std::shared_ptr<SiStripApvGain> payload = fetchPayload( std::get<1>(iov) );
410 
411  std::string titleMap = "SiStrip APV Gain average per module (payload : "+std::get<1>(iov)+")";
412 
413  std::unique_ptr<TrackerMap> tmap = std::unique_ptr<TrackerMap>(new TrackerMap("SiStripApvGains"));
414  tmap->setTitle(titleMap);
415  tmap->setPalette(1);
416 
417  std::vector<uint32_t> detid;
418  payload->getDetIds(detid);
419 
420  std::map<uint32_t,float> store;
421 
422  for (const auto & d : detid) {
423  SiStripApvGain::Range range=payload->getRange(d);
424  float sumOfGains=0;
425  float nAPVsPerModule=0.;
426  for(int it=0;it<range.second-range.first;it++){
427  nAPVsPerModule+=1;
428  sumOfGains+=payload->getApvGain(it,range);
429  } // loop over APVs
430  // fill the tracker map taking the average gain on a single DetId
431  store[d]=(sumOfGains/nAPVsPerModule);
432  tmap->fill(d,(sumOfGains/nAPVsPerModule));
433  } // loop over detIds
434 
435  //=========================
436  // saturate at 2 std deviations
437  auto range = SiStripPI::getTheRange(store,2);
438 
439  std::string fileName(m_imageFileName);
440  tmap->save(true,range.first,range.second,fileName);
441 
442  return true;
443  }
444  };
445 
446  /************************************************
447  TrackerMap of SiStripApvGains (module with default)
448  *************************************************/
449  class SiStripApvGainsDefaultTrackerMap : public cond::payloadInspector::PlotImage<SiStripApvGain> {
450  public:
451  SiStripApvGainsDefaultTrackerMap() : cond::payloadInspector::PlotImage<SiStripApvGain>( "Tracker Map of SiStripGains to default" ){
452  setSingleIov( true );
453  }
454 
455  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
456  auto iov = iovs.front();
457  std::shared_ptr<SiStripApvGain> payload = fetchPayload( std::get<1>(iov) );
458 
459  std::unique_ptr<TrackerMap> tmap = std::unique_ptr<TrackerMap>(new TrackerMap("SiStripApvGains"));
460 
461  tmap->setPalette(1);
462 
463  std::vector<uint32_t> detid;
464  payload->getDetIds(detid);
465 
466  /*
467  the defaul G1 value comes from the ratio of DefaultTickHeight/GainNormalizationFactor
468  as defined in the default of the O2O producer: OnlineDB/SiStripESSources/src/SiStripCondObjBuilderFromDb.cc
469  */
470 
471  float G1default = 690./640.;
472  float G2default = 1.;
473 
474  int totalG1DefaultAPVs=0;
475  int totalG2DefaultAPVs=0;
476 
477  for (const auto & d : detid) {
478  SiStripApvGain::Range range=payload->getRange(d);
479  float sumOfGains=0;
480  float nAPVsPerModule=0.;
481  int countDefaults=0;
482  for(int it=0;it<range.second-range.first;it++){
483  nAPVsPerModule+=1;
484  sumOfGains+=payload->getApvGain(it,range);
485  if( (payload->getApvGain(it,range))==G1default || (payload->getApvGain(it,range))==G2default) countDefaults++;
486  } // loop over APVs
487  // fill the tracker map taking the average gain on a single DetId
488  if(countDefaults>0.){
489  tmap->fill(d,countDefaults);
490 
491  if( std::fmod((sumOfGains/countDefaults),G1default)==0.){
492  totalG1DefaultAPVs+=countDefaults;
493  } else if ( std::fmod((sumOfGains/countDefaults),G2default)==0.){
494  totalG2DefaultAPVs+=countDefaults;
495  }
496  }
497  } // loop over detIds
498 
499  //=========================
500 
501  std::string gainType = totalG1DefaultAPVs==0 ? "G2 value (=1)" : "G1 value (=690./640.)";
502 
503  std::string titleMap = "# of APVs/module w/ default "+gainType+" (payload : "+std::get<1>(iov)+")";
504  tmap->setTitle(titleMap);
505 
506  std::string fileName(m_imageFileName);
507  tmap->save(true,0,0,fileName);
508 
509  return true;
510  }
511  };
512 
513  /************************************************
514  TrackerMap of SiStripApvGains (ratio with previous gain per detid)
515  *************************************************/
516  template<int nsigma> class SiStripApvGainsRatioWithPreviousIOVTrackerMap : public cond::payloadInspector::PlotImage<SiStripApvGain> {
517  public:
518  SiStripApvGainsRatioWithPreviousIOVTrackerMap() : cond::payloadInspector::PlotImage<SiStripApvGain>( "Tracker Map of ratio of SiStripGains with previous IOV" ){
519  setSingleIov( false );
520  }
521 
522  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
523 
524  std::vector<std::tuple<cond::Time_t,cond::Hash> > sorted_iovs = iovs;
525 
526  // make absolute sure the IOVs are sortd by since
527  std::sort(begin(sorted_iovs), end(sorted_iovs), [](auto const &t1, auto const &t2) {
528  return std::get<0>(t1) < std::get<0>(t2);
529  });
530 
531  auto firstiov = sorted_iovs.front();
532  auto lastiov = sorted_iovs.back();
533 
534  std::shared_ptr<SiStripApvGain> last_payload = fetchPayload( std::get<1>(lastiov) );
535  std::shared_ptr<SiStripApvGain> first_payload = fetchPayload( std::get<1>(firstiov) );
536 
537  std::string titleMap = "SiStrip APV Gain ratio per module average (IOV: ";
538 
539  titleMap+=std::to_string(std::get<0>(firstiov));
540  titleMap+="/ IOV:";
541  titleMap+=std::to_string(std::get<0>(lastiov));
542  titleMap+=")";
543 
544  titleMap+=+" "+std::to_string(nsigma)+" std. dev. saturation";
545 
546  std::unique_ptr<TrackerMap> tmap = std::unique_ptr<TrackerMap>(new TrackerMap("SiStripApvGains"));
547  tmap->setTitle(titleMap);
548  tmap->setPalette(1);
549 
550  std::map<uint32_t,float> lastmap,firstmap;
551 
552  std::vector<uint32_t> detid;
553  last_payload->getDetIds(detid);
554 
555  // cache the last IOV
556  for (const auto & d : detid) {
557  SiStripApvGain::Range range=last_payload->getRange(d);
558  float Gain=0;
559  float nAPV=0;
560  for(int it=0;it<range.second-range.first;it++){
561  nAPV+=1;
562  Gain+=last_payload->getApvGain(it,range);
563  } // loop over APVs
564  lastmap[d]=(Gain/nAPV);
565  } // loop over detIds
566 
567  detid.clear();
568 
569  first_payload->getDetIds(detid);
570 
571  // cache the first IOV
572  for (const auto & d : detid) {
573  SiStripApvGain::Range range=first_payload->getRange(d);
574  float Gain=0;
575  float nAPV=0;
576  for(int it=0;it<range.second-range.first;it++){
577  nAPV+=1;
578  Gain+=first_payload->getApvGain(it,range);
579  } // loop over APVs
580  firstmap[d]=(Gain/nAPV);
581  } // loop over detIds
582 
583 
584  std::map<uint32_t,float> cachedRatio;
585  for(const auto &d : detid){
586  float ratio = firstmap[d]/lastmap[d];
587  tmap->fill(d,ratio);
588  cachedRatio[d] = ratio;
589  }
590 
591  //=========================
592  auto range = SiStripPI::getTheRange(cachedRatio,nsigma);
593 
594  std::string fileName(m_imageFileName);
595  tmap->save(true,range.first,range.second,fileName);
596 
597  return true;
598  }
599  };
600 
601  typedef SiStripApvGainsRatioWithPreviousIOVTrackerMap<1> SiStripApvGainsAvgDeviationRatio1sigmaTrackerMap;
602  typedef SiStripApvGainsRatioWithPreviousIOVTrackerMap<2> SiStripApvGainsAvgDeviationRatio2sigmaTrackerMap;
603  typedef SiStripApvGainsRatioWithPreviousIOVTrackerMap<3> SiStripApvGainsAvgDeviationRatio3sigmaTrackerMap;
604 
605  /************************************************
606  TrackerMap of SiStripApvGains (ratio for largest deviation with previous gain per detid)
607  *************************************************/
608  template<int nsigma> class SiStripApvGainsRatioMaxDeviationWithPreviousIOVTrackerMap : public cond::payloadInspector::PlotImage<SiStripApvGain> {
609  public:
610  SiStripApvGainsRatioMaxDeviationWithPreviousIOVTrackerMap() : cond::payloadInspector::PlotImage<SiStripApvGain>( "Tracker Map of ratio (for largest deviation) of SiStripGains with previous IOV" ){
611  setSingleIov( false );
612  }
613 
614  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
615 
616  std::vector<std::tuple<cond::Time_t,cond::Hash> > sorted_iovs = iovs;
617 
618  // make absolute sure the IOVs are sortd by since
619  std::sort(begin(sorted_iovs), end(sorted_iovs), [](auto const &t1, auto const &t2) {
620  return std::get<0>(t1) < std::get<0>(t2);
621  });
622 
623  auto firstiov = sorted_iovs.front();
624  auto lastiov = sorted_iovs.back();
625 
626  std::shared_ptr<SiStripApvGain> last_payload = fetchPayload( std::get<1>(lastiov) );
627  std::shared_ptr<SiStripApvGain> first_payload = fetchPayload( std::get<1>(firstiov) );
628 
629  std::string titleMap = "SiStrip APV Gain ratio for largest deviation per module (IOV: ";
630 
631  titleMap+=std::to_string(std::get<0>(firstiov));
632  titleMap+="/ IOV:";
633  titleMap+=std::to_string(std::get<0>(lastiov));
634  titleMap+=") ";
635 
636  titleMap+=+" - "+std::to_string(nsigma)+" std. dev. saturation";
637 
638  std::unique_ptr<TrackerMap> tmap = std::unique_ptr<TrackerMap>(new TrackerMap("SiStripApvGains"));
639  tmap->setTitle(titleMap);
640  tmap->setPalette(1);
641 
642  std::map<std::pair<uint32_t,int>,float> lastmap,firstmap;
643 
644  std::vector<uint32_t> detid;
645  last_payload->getDetIds(detid);
646 
647  // cache the last IOV
648  for (const auto & d : detid) {
649  SiStripApvGain::Range range=last_payload->getRange(d);
650  float nAPV=0;
651  for(int it=0;it<range.second-range.first;it++){
652  nAPV+=1;
653  float Gain=last_payload->getApvGain(it,range);
654  std::pair<uint32_t,int> index = std::make_pair(d,nAPV);
655  lastmap[index]=Gain;
656  } // loop over APVs
657  } // loop over detIds
658 
659  detid.clear();
660 
661  first_payload->getDetIds(detid);
662 
663  // cache the first IOV
664  for (const auto & d : detid) {
665  SiStripApvGain::Range range=first_payload->getRange(d);
666  float nAPV=0;
667  for(int it=0;it<range.second-range.first;it++){
668  nAPV+=1;
669  float Gain=first_payload->getApvGain(it,range);
670  std::pair<uint32_t,int> index = std::make_pair(d,nAPV);
671  firstmap[index]=Gain;
672  } // loop over APVs
673  } // loop over detIds
674 
675  // find the largest deviation
676  std::map<uint32_t,float> cachedRatio;
677 
678  for(const auto &item : firstmap ){
679 
680  // packed index (detid,APV)
681  auto index = item.first;
682  auto mod = item.first.first;
683 
684  float ratio = firstmap[index]/lastmap[index];
685  // if we have already cached something
686  if(cachedRatio[mod]){
687  // if the discrepancy with 1 of ratio is larger than the cached value
688  if(std::abs(ratio-1.)>std::abs(cachedRatio[mod]-1.)){
689  cachedRatio[mod]=ratio;
690  }
691  } else {
692  cachedRatio[mod]=ratio;
693  }
694  }
695 
696  for (const auto &element : cachedRatio){
697  tmap->fill(element.first,element.second);
698  }
699 
700  // get the range of the TrackerMap (saturate at +/-n std deviations)
701  auto range = SiStripPI::getTheRange(cachedRatio,nsigma);
702 
703  //=========================
704 
705  std::string fileName(m_imageFileName);
706  tmap->save(true,range.first,range.second,fileName);
707 
708  return true;
709  }
710  };
711 
712  typedef SiStripApvGainsRatioMaxDeviationWithPreviousIOVTrackerMap<1> SiStripApvGainsMaxDeviationRatio1sigmaTrackerMap;
713  typedef SiStripApvGainsRatioMaxDeviationWithPreviousIOVTrackerMap<2> SiStripApvGainsMaxDeviationRatio2sigmaTrackerMap;
714  typedef SiStripApvGainsRatioMaxDeviationWithPreviousIOVTrackerMap<3> SiStripApvGainsMaxDeviationRatio3sigmaTrackerMap;
715 
716  /************************************************
717  TrackerMap of SiStripApvGains (maximum gain per detid)
718  *************************************************/
719  class SiStripApvGainsMaximumTrackerMap : public cond::payloadInspector::PlotImage<SiStripApvGain> {
720  public:
721  SiStripApvGainsMaximumTrackerMap() : cond::payloadInspector::PlotImage<SiStripApvGain>( "Tracker Map of SiStripAPVGains (maximum per DetId)" ){
722  setSingleIov( true );
723  }
724 
725  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
726  auto iov = iovs.front();
727  std::shared_ptr<SiStripApvGain> payload = fetchPayload( std::get<1>(iov) );
728 
729  std::string titleMap = "SiStrip APV Gain maximum per module (payload : "+std::get<1>(iov)+")";
730 
731  std::unique_ptr<TrackerMap> tmap = std::unique_ptr<TrackerMap>(new TrackerMap("SiStripApvGains"));
732  tmap->setTitle(titleMap);
733  tmap->setPalette(1);
734 
735  std::vector<uint32_t> detid;
736  payload->getDetIds(detid);
737 
738  for (const auto & d : detid) {
739  SiStripApvGain::Range range=payload->getRange(d);
740  float theMaxGain=0;
741  for(int it=0;it<range.second-range.first;it++){
742 
743  float currentGain = payload->getApvGain(it,range);
744  if(currentGain > theMaxGain){
745  theMaxGain=currentGain;
746  }
747  } // loop over APVs
748  // fill the tracker map taking the maximum gain on a single DetId
749  tmap->fill(d,theMaxGain);
750  } // loop over detIds
751 
752  //=========================
753 
754  std::pair<float,float> extrema = tmap->getAutomaticRange();
755 
756  std::string fileName(m_imageFileName);
757 
758  // protect against uniform values (gains are defined positive)
759  if (extrema.first!=extrema.second){
760  tmap->save(true,0,0,fileName);
761  } else {
762  tmap->save(true,extrema.first*0.95,extrema.first*1.05,fileName);
763  }
764 
765  return true;
766  }
767  };
768 
769  /************************************************
770  TrackerMap of SiStripApvGains (minimum gain per detid)
771  *************************************************/
772  class SiStripApvGainsMinimumTrackerMap : public cond::payloadInspector::PlotImage<SiStripApvGain> {
773  public:
774  SiStripApvGainsMinimumTrackerMap() : cond::payloadInspector::PlotImage<SiStripApvGain>( "Tracker Map of SiStripAPVGains (minimum per DetId)" ){
775  setSingleIov( true );
776  }
777 
778  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
779  auto iov = iovs.front();
780  std::shared_ptr<SiStripApvGain> payload = fetchPayload( std::get<1>(iov) );
781 
782  std::string titleMap = "SiStrip APV Gain minumum per module (payload : "+std::get<1>(iov)+")";
783 
784  std::unique_ptr<TrackerMap> tmap = std::unique_ptr<TrackerMap>(new TrackerMap("SiStripApvGains"));
785  tmap->setTitle(titleMap);
786  tmap->setPalette(1);
787 
788  std::vector<uint32_t> detid;
789  payload->getDetIds(detid);
790 
791  for (const auto & d : detid) {
792  SiStripApvGain::Range range=payload->getRange(d);
793  float theMinGain=999.;
794  for(int it=0;it<range.second-range.first;it++){
795  float currentGain = payload->getApvGain(it,range);
796  if(currentGain < theMinGain){
797  theMinGain=currentGain;
798  }
799  } // loop over APVs
800  // fill the tracker map taking the minimum gain on a single DetId
801  tmap->fill(d,theMinGain);
802  } // loop over detIds
803 
804  //=========================
805 
806  std::pair<float,float> extrema = tmap->getAutomaticRange();
807 
808  std::string fileName(m_imageFileName);
809 
810  // protect against uniform values (gains are defined positive)
811  if (extrema.first!=extrema.second){
812  tmap->save(true,0,0,fileName);
813  } else {
814  tmap->save(true,extrema.first*0.95,extrema.first*1.05,fileName);
815  }
816 
817  return true;
818  }
819  };
820 
821  /************************************************
822  time history histogram of SiStripApvGains
823  *************************************************/
824 
825  class SiStripApvGainByRunMeans : public cond::payloadInspector::HistoryPlot<SiStripApvGain,float> {
826  public:
827  SiStripApvGainByRunMeans() : cond::payloadInspector::HistoryPlot<SiStripApvGain,float>( "SiStripApv Gains average","average Strip APV gain value"){}
828  ~SiStripApvGainByRunMeans() override = default;
829 
830  float getFromPayload( SiStripApvGain& payload ) override{
831 
832  std::vector<uint32_t> detid;
833  payload.getDetIds(detid);
834 
835  float nAPVs=0;
836  float sumOfGains=0;
837 
838  for (const auto & d : detid) {
839  SiStripApvGain::Range range=payload.getRange(d);
840  for(int it=0;it<range.second-range.first;it++){
841  nAPVs+=1;
842  sumOfGains+=payload.getApvGain(it,range);
843  } // loop over APVs
844  } // loop over detIds
845 
846  return sumOfGains/nAPVs;
847  } // payload
848  };
849 
850  /************************************************
851  time history of SiStripApvGains properties
852  *************************************************/
853 
854  template<SiStripPI::estimator est> class SiStripApvGainProperties : public cond::payloadInspector::HistoryPlot<SiStripApvGain,float> {
855  public:
856  SiStripApvGainProperties() : cond::payloadInspector::HistoryPlot<SiStripApvGain,float>( "SiStripApv Gains "+estimatorType(est),estimatorType(est)+" Strip APV gain value"){}
857  ~SiStripApvGainProperties() override = default;
858 
859  float getFromPayload( SiStripApvGain& payload ) override{
860 
861  std::vector<uint32_t> detid;
862  payload.getDetIds(detid);
863 
864  float nAPVs=0;
865  float sumOfGains=0;
866  float meanOfGains=0;
867  float rmsOfGains=0;
868  float min(0.),max(0.);
869 
870  for (const auto & d : detid) {
871  SiStripApvGain::Range range=payload.getRange(d);
872  for(int it=0;it<range.second-range.first;it++){
873  nAPVs+=1;
874  float gain=payload.getApvGain(it,range);
875  if(gain<min) min=gain;
876  if(gain>max) max=gain;
877  sumOfGains+=gain;
878  rmsOfGains+=(gain*gain);
879  } // loop over APVs
880  } // loop over detIds
881 
882 
883  meanOfGains=sumOfGains/nAPVs;
884 
885  switch(est){
886  case SiStripPI::min:
887  return min;
888  break;
889  case SiStripPI::max:
890  return max;
891  break;
892  case SiStripPI::mean:
893  return meanOfGains;
894  break;
895  case SiStripPI::rms:
896  if((rmsOfGains/nAPVs-meanOfGains*meanOfGains)>0.){
897  return sqrt(rmsOfGains/nAPVs-meanOfGains*meanOfGains);
898  } else {
899  return 0.;
900  }
901  break;
902  default:
903  edm::LogWarning("LogicError") << "Unknown estimator: " << est;
904  break;
905  }
906 
907  } // payload
908  };
909 
910  typedef SiStripApvGainProperties<SiStripPI::min> SiStripApvGainMin_History;
911  typedef SiStripApvGainProperties<SiStripPI::max> SiStripApvGainMax_History;
912  typedef SiStripApvGainProperties<SiStripPI::mean> SiStripApvGainMean_History;
913  typedef SiStripApvGainProperties<SiStripPI::rms> SiStripApvGainRMS_History;
914 
915 
916  /************************************************
917  time history histogram of TIB SiStripApvGains
918  *************************************************/
919 
920  class SiStripApvTIBGainByRunMeans : public cond::payloadInspector::HistoryPlot<SiStripApvGain,float> {
921  public:
922  SiStripApvTIBGainByRunMeans() : cond::payloadInspector::HistoryPlot<SiStripApvGain,float>( "SiStripApv Gains average","average Tracker Inner Barrel APV gain value"){}
923  ~SiStripApvTIBGainByRunMeans() override = default;
924 
925  float getFromPayload( SiStripApvGain& payload ) override{
926 
927  std::vector<uint32_t> detid;
928  payload.getDetIds(detid);
929 
930  float nAPVs=0;
931  float sumOfGains=0;
932 
933  for (const auto & d : detid) {
934 
935  int subid = DetId(d).subdetId();
936  if(subid!=StripSubdetector::TIB) continue;
937 
938  SiStripApvGain::Range range=payload.getRange(d);
939  for(int it=0;it<range.second-range.first;it++){
940  nAPVs+=1;
941  sumOfGains+=payload.getApvGain(it,range);
942  } // loop over APVs
943  } // loop over detIds
944 
945  return sumOfGains/nAPVs;
946 
947  } // payload
948  };
949 
950  /************************************************
951  time history histogram of TOB SiStripApvGains
952  *************************************************/
953 
954  class SiStripApvTOBGainByRunMeans : public cond::payloadInspector::HistoryPlot<SiStripApvGain,float> {
955  public:
956  SiStripApvTOBGainByRunMeans() : cond::payloadInspector::HistoryPlot<SiStripApvGain,float>( "SiStripApv Gains average","average Tracker Outer Barrel gain value"){}
957  ~SiStripApvTOBGainByRunMeans() override = default;
958 
959  float getFromPayload( SiStripApvGain& payload ) override{
960 
961  std::vector<uint32_t> detid;
962  payload.getDetIds(detid);
963 
964  float nAPVs=0;
965  float sumOfGains=0;
966 
967  for (const auto & d : detid) {
968 
969  int subid = DetId(d).subdetId();
970  if(subid!=StripSubdetector::TOB) continue;
971 
972  SiStripApvGain::Range range=payload.getRange(d);
973  for(int it=0;it<range.second-range.first;it++){
974  nAPVs+=1;
975  sumOfGains+=payload.getApvGain(it,range);
976  } // loop over APVs
977  } // loop over detIds
978 
979  return sumOfGains/nAPVs;
980 
981  } // payload
982  };
983 
984  /************************************************
985  time history histogram of TID SiStripApvGains
986  *************************************************/
987 
988  class SiStripApvTIDGainByRunMeans : public cond::payloadInspector::HistoryPlot<SiStripApvGain,float> {
989  public:
990  SiStripApvTIDGainByRunMeans() : cond::payloadInspector::HistoryPlot<SiStripApvGain,float>( "SiStripApv Gains average","average Tracker Inner Disks APV gain value"){}
991  ~SiStripApvTIDGainByRunMeans() override = default;
992 
993  float getFromPayload( SiStripApvGain& payload ) override{
994 
995  std::vector<uint32_t> detid;
996  payload.getDetIds(detid);
997 
998  float nAPVs=0;
999  float sumOfGains=0;
1000  for (const auto & d : detid) {
1001 
1002  int subid = DetId(d).subdetId();
1003  if(subid!=StripSubdetector::TID) continue;
1004 
1005  SiStripApvGain::Range range=payload.getRange(d);
1006  for(int it=0;it<range.second-range.first;it++){
1007  nAPVs+=1;
1008  sumOfGains+=payload.getApvGain(it,range);
1009  } // loop over APVs
1010  } // loop over detIds
1011 
1012  return sumOfGains/nAPVs;
1013 
1014  } // payload
1015  };
1016 
1017  /************************************************
1018  time history histogram of TEC SiStripApvGains
1019  *************************************************/
1020 
1021  class SiStripApvTECGainByRunMeans : public cond::payloadInspector::HistoryPlot<SiStripApvGain,float> {
1022  public:
1023  SiStripApvTECGainByRunMeans() : cond::payloadInspector::HistoryPlot<SiStripApvGain,float>( "SiStripApv Gains average in TEC","average Tracker Endcaps APV gain value"){}
1024  ~SiStripApvTECGainByRunMeans() override = default;
1025 
1026  float getFromPayload( SiStripApvGain& payload ) override{
1027 
1028  std::vector<uint32_t> detid;
1029  payload.getDetIds(detid);
1030 
1031  float nAPVs=0;
1032  float sumOfGains=0;
1033 
1034  for (const auto & d : detid) {
1035 
1036  int subid = DetId(d).subdetId();
1037  if(subid!=StripSubdetector::TEC) continue;
1038 
1039  SiStripApvGain::Range range=payload.getRange(d);
1040  for(int it=0;it<range.second-range.first;it++){
1041  nAPVs+=1;
1042  sumOfGains+=payload.getApvGain(it,range);
1043  } // loop over APVs
1044  } // loop over detIds
1045 
1046  return sumOfGains/nAPVs;
1047 
1048  } // payload
1049  };
1050 
1051  /************************************************
1052  test class
1053  *************************************************/
1054 
1055  class SiStripApvGainsTest : public cond::payloadInspector::Histogram1D<SiStripApvGain> {
1056 
1057  public:
1058  SiStripApvGainsTest() : cond::payloadInspector::Histogram1D<SiStripApvGain>("SiStripApv Gains test",
1059  "SiStripApv Gains test", 10,0.0,10.0),
1060  m_trackerTopo{StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath())}
1061  {
1062  Base::setSingleIov( true );
1063  }
1064 
1065  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
1066  for ( auto const & iov: iovs) {
1067  std::shared_ptr<SiStripApvGain> payload = Base::fetchPayload( std::get<1>(iov) );
1068  if( payload.get() ){
1069 
1070  std::vector<uint32_t> detid;
1071  payload->getDetIds(detid);
1072 
1073  SiStripDetSummary summaryGain{&m_trackerTopo};
1074 
1075  for (const auto & d : detid) {
1076  SiStripApvGain::Range range=payload->getRange(d);
1077  for( int it=0; it < range.second - range.first; ++it ) {
1078  summaryGain.add(d,payload->getApvGain(it, range));
1079  fillWithValue(payload->getApvGain(it,range));
1080  }
1081  }
1082  std::map<unsigned int, SiStripDetSummary::Values> map = summaryGain.getCounts();
1083 
1084  //SiStripPI::printSummary(map);
1085 
1086  std::stringstream ss;
1087  ss << "Summary of gain values:" << std::endl;
1088  summaryGain.print(ss, true);
1089  std::cout<<ss.str()<<std::endl;
1090 
1091  }// payload
1092  }// iovs
1093  return true;
1094  }// fill
1095  private:
1096  TrackerTopology m_trackerTopo;
1097  };
1098 
1099  /************************************************
1100  Compare Gains from 2 IOVs, 2 pads canvas, firsr for ratio, second for scatter plot
1101  *************************************************/
1102 
1103  class SiStripApvGainsComparator : public cond::payloadInspector::PlotImage<SiStripApvGain> {
1104  public:
1105  SiStripApvGainsComparator () : cond::payloadInspector::PlotImage<SiStripApvGain>( "SiStripGains Comparison" ){
1106  setSingleIov( false );
1107  }
1108 
1109  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
1110 
1111  std::vector<std::tuple<cond::Time_t,cond::Hash> > sorted_iovs = iovs;
1112 
1113  // make absolute sure the IOVs are sortd by since
1114  std::sort(begin(sorted_iovs), end(sorted_iovs), [](auto const &t1, auto const &t2) {
1115  return std::get<0>(t1) < std::get<0>(t2);
1116  });
1117 
1118  auto firstiov = sorted_iovs.front();
1119  auto lastiov = sorted_iovs.back();
1120 
1121  std::shared_ptr<SiStripApvGain> last_payload = fetchPayload( std::get<1>(lastiov) );
1122  std::shared_ptr<SiStripApvGain> first_payload = fetchPayload( std::get<1>(firstiov) );
1123 
1124  std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
1125  std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
1126 
1127  std::vector<uint32_t> detid;
1128  last_payload->getDetIds(detid);
1129 
1130  std::map<std::pair<uint32_t,int>,float> lastmap,firstmap;
1131 
1132  // loop on the last payload
1133  for (const auto & d : detid) {
1134  SiStripApvGain::Range range=last_payload->getRange(d);
1135  float Gain=0;
1136  float nAPV=0;
1137  for( int it=0; it < range.second - range.first; ++it ) {
1138  nAPV+=1;
1139  Gain=last_payload->getApvGain(it,range);
1140  std::pair<uint32_t,int> index = std::make_pair(d,nAPV);
1141  lastmap[index]=Gain;
1142  } // end loop on APVs
1143  } // end loop on detids
1144 
1145  detid.clear();
1146  first_payload->getDetIds(detid);
1147 
1148  // loop on the first payload
1149  for (const auto & d : detid) {
1150  SiStripApvGain::Range range=first_payload->getRange(d);
1151  float Gain=0;
1152  float nAPV=0;
1153  for( int it=0; it < range.second - range.first; ++it ) {
1154  nAPV+=1;
1155  Gain=first_payload->getApvGain(it,range);
1156  std::pair<uint32_t,int> index = std::make_pair(d,nAPV);
1157  firstmap[index]=Gain;
1158  } // end loop on APVs
1159  } // end loop on detids
1160 
1161  TCanvas canvas("Payload comparison","payload comparison",1400,1000);
1162  canvas.Divide(2,1);
1163 
1164  std::map<std::string,std::shared_ptr<TH1F>> ratios;
1165  std::map<std::string,std::shared_ptr<TH2F>> scatters;
1166  std::map<std::string,int> colormap;
1167  std::map<std::string,int> markermap;
1168  colormap["TIB"] = kRed; markermap["TIB"] = kFullCircle;
1169  colormap["TOB"] = kGreen; markermap["TOB"] = kFullTriangleUp;
1170  colormap["TID"] = kBlack; markermap["TID"] = kFullSquare;
1171  colormap["TEC"] = kBlue; markermap["TEC"] = kFullTriangleDown;
1172 
1173  std::vector<std::string> parts = {"TEC","TOB","TIB","TID"};
1174 
1175  for ( const auto &part : parts){
1176  ratios[part] = std::make_shared<TH1F>(Form("hRatio_%s",part.c_str()),Form("Gains ratio IOV: %s/ IOV: %s ;Previous Gain (%s) / New Gain (%s);Number of APV",firstIOVsince.c_str(),lastIOVsince.c_str(),firstIOVsince.c_str(),lastIOVsince.c_str()),200,0.,2.);
1177  scatters[part] = std::make_shared<TH2F>(Form("hScatter_%s",part.c_str()),Form("new Gain (%s) vs previous Gain (%s);Previous Gain (%s);New Gain (%s)",lastIOVsince.c_str(),firstIOVsince.c_str(),firstIOVsince.c_str(),lastIOVsince.c_str()),100,0.5,1.8,100,0.5,1.8);
1178  }
1179 
1180  // now loop on the cached maps
1181  for(const auto &item : firstmap ) {
1182 
1183  // packed index (detid,APV)
1184  auto index = item.first;
1185  auto mod = item.first.first;
1186 
1187  int subid = DetId(mod).subdetId();
1188  float ratio = firstmap[index]/lastmap[index];
1189 
1190  if(subid==StripSubdetector::TIB){
1191  ratios["TIB"]->Fill(ratio);
1192  scatters["TIB"]->Fill(lastmap[index],firstmap[index]);
1193  }
1194 
1195  if(subid==StripSubdetector::TOB){
1196  ratios["TOB"]->Fill(ratio);
1197  scatters["TOB"]->Fill(lastmap[index],firstmap[index]);
1198  }
1199 
1200  if(subid==StripSubdetector::TID){
1201  ratios["TID"]->Fill(ratio);
1202  scatters["TID"]->Fill(lastmap[index],firstmap[index]);
1203  }
1204 
1205  if(subid==StripSubdetector::TEC){
1206  ratios["TEC"]->Fill(ratio);
1207  scatters["TEC"]->Fill(lastmap[index],firstmap[index]);
1208  }
1209 
1210  }
1211 
1212  auto legend = TLegend(0.60,0.8,0.92,0.95);
1213  legend.SetTextSize(0.05);
1214  canvas.cd(1)->SetLogy();
1215  canvas.cd(1)->SetTopMargin(0.05);
1216  canvas.cd(1)->SetLeftMargin(0.13);
1217  canvas.cd(1)->SetRightMargin(0.08);
1218 
1219  for (const auto &part : parts){
1220  SiStripPI::makeNicePlotStyle(ratios[part].get());
1221  ratios[part]->SetMinimum(1.);
1222  ratios[part]->SetStats(false);
1223  ratios[part]->SetLineWidth(2);
1224  ratios[part]->SetLineColor(colormap[part]);
1225  if(part =="TEC")
1226  ratios[part]->Draw();
1227  else
1228  ratios[part]->Draw("same");
1229  legend.AddEntry(ratios[part].get(),part.c_str(),"L");
1230  }
1231 
1232  legend.Draw("same");
1233  SiStripPI::drawStatBox(ratios,colormap,parts);
1234 
1235  auto legend2 = TLegend(0.60,0.8,0.92,0.95);
1236  legend2.SetTextSize(0.05);
1237  canvas.cd(2);
1238  canvas.cd(2)->SetTopMargin(0.05);
1239  canvas.cd(2)->SetLeftMargin(0.13);
1240  canvas.cd(2)->SetRightMargin(0.08);
1241 
1242  for (const auto &part : parts){
1243  SiStripPI::makeNicePlotStyle(scatters[part].get());
1244  scatters[part]->SetStats(false);
1245  scatters[part]->SetMarkerColor(colormap[part]);
1246  scatters[part]->SetMarkerStyle(markermap[part]);
1247  scatters[part]->SetMarkerSize(0.5);
1248 
1249  auto temp = (TH2F*)(scatters[part]->Clone());
1250  temp->SetMarkerSize(1.3);
1251 
1252  if(part =="TEC")
1253  scatters[part]->Draw("P");
1254  else
1255  scatters[part]->Draw("Psame");
1256 
1257  legend2.AddEntry(temp,part.c_str(),"P");
1258  }
1259 
1260  TLine diagonal(0.5,0.5,1.8,1.8);
1261  diagonal.SetLineWidth(3);
1262  diagonal.SetLineStyle(2);
1263  diagonal.Draw("same");
1264 
1265  legend2.Draw("same");
1266 
1267  std::string fileName(m_imageFileName);
1268  canvas.SaveAs(fileName.c_str());
1269 
1270  return true;
1271 
1272  }
1273  };
1274 
1275  //*******************************************//
1276  // Compare Gains from 2 IOVs
1277  //******************************************//
1278 
1279  class SiStripApvGainsValuesComparator : public cond::payloadInspector::PlotImage<SiStripApvGain> {
1280  public:
1281  SiStripApvGainsValuesComparator () : cond::payloadInspector::PlotImage<SiStripApvGain>( "Comparison of SiStrip APV gains values" ){
1282  setSingleIov( false );
1283  }
1284 
1285  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
1286 
1287  TH1F::SetDefaultSumw2(true);
1288 
1289  std::vector<std::tuple<cond::Time_t,cond::Hash> > sorted_iovs = iovs;
1290 
1291  // make absolute sure the IOVs are sortd by since
1292  std::sort(begin(sorted_iovs), end(sorted_iovs), [](auto const &t1, auto const &t2) {
1293  return std::get<0>(t1) < std::get<0>(t2);
1294  });
1295 
1296  auto firstiov = sorted_iovs.front();
1297  auto lastiov = sorted_iovs.back();
1298 
1299  std::shared_ptr<SiStripApvGain> last_payload = fetchPayload( std::get<1>(lastiov) );
1300  std::shared_ptr<SiStripApvGain> first_payload = fetchPayload( std::get<1>(firstiov) );
1301 
1302  std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
1303  std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
1304 
1305  std::vector<uint32_t> detid;
1306  last_payload->getDetIds(detid);
1307 
1308  std::map<std::pair<uint32_t,int>,float> lastmap,firstmap;
1309 
1310  // loop on the last payload
1311  for (const auto & d : detid) {
1312  SiStripApvGain::Range range=last_payload->getRange(d);
1313  float nAPV=0;
1314  for( int it=0; it < range.second - range.first; ++it ) {
1315  nAPV+=1;
1316  auto index = std::make_pair(d,nAPV);
1317  lastmap[index]=last_payload->getApvGain(it,range);
1318  } // end loop on APVs
1319  } // end loop on detids
1320 
1321  detid.clear();
1322  first_payload->getDetIds(detid);
1323 
1324  // loop on the first payload
1325  for (const auto & d : detid) {
1326  SiStripApvGain::Range range=first_payload->getRange(d);
1327  float nAPV=0;
1328  for( int it=0; it < range.second - range.first; ++it ) {
1329  nAPV+=1;
1330  auto index = std::make_pair(d,nAPV);
1331  firstmap[index]=last_payload->getApvGain(it,range);
1332  } // end loop on APVs
1333  } // end loop on detids
1334 
1335  TCanvas canvas("Payload comparison","payload comparison",1000,1000);
1336  canvas.cd();
1337 
1338  TPad pad1("pad1", "pad1", 0, 0.3, 1, 1.0);
1339  pad1.SetBottomMargin(0.02); // Upper and lower plot are joined
1340  pad1.SetTopMargin(0.07);
1341  pad1.SetRightMargin(0.05);
1342  pad1.SetLeftMargin(0.15);
1343  pad1.Draw(); // Draw the upper pad: pad1
1344  pad1.cd(); // pad1 becomes the current pad
1345 
1346  auto h_firstGains = std::make_shared<TH1F>("hFirstGains","SiStrip APV gains values; APV Gains;n. APVs",200,0.2,1.8);
1347  auto h_lastGains = std::make_shared<TH1F>("hLastGains","SiStrip APV gains values; APV Gains;n. APVs",200,0.2,1.8);
1348 
1349  for(const auto &item : firstmap ) {
1350  h_firstGains->Fill(item.second);
1351  }
1352 
1353  for(const auto &item : lastmap ) {
1354  h_lastGains->Fill(item.second);
1355  }
1356 
1357  SiStripPI::makeNicePlotStyle(h_lastGains.get());
1358  SiStripPI::makeNicePlotStyle(h_firstGains.get());
1359 
1360  TH1F *hratio = (TH1F*)h_firstGains->Clone("hratio");
1361 
1362  h_firstGains->SetLineColor(kRed);
1363  h_lastGains->SetLineColor(kBlue);
1364 
1365  h_firstGains->SetMarkerColor(kRed);
1366  h_lastGains->SetMarkerColor(kBlue);
1367 
1368  h_firstGains->SetMarkerSize(1.);
1369  h_lastGains->SetMarkerSize(1.);
1370 
1371  h_firstGains->SetLineWidth(1);
1372  h_lastGains->SetLineWidth(1);
1373 
1374  h_firstGains->SetMarkerStyle(20);
1375  h_lastGains->SetMarkerStyle(21);
1376 
1377  h_firstGains->GetXaxis()->SetLabelOffset(2.);
1378  h_lastGains->GetXaxis()->SetLabelOffset(2.);
1379 
1380  h_firstGains->Draw("HIST");
1381  h_lastGains->Draw("HISTsame");
1382 
1383  TLegend legend = TLegend(0.70,0.7,0.95,0.9);
1384  legend.SetHeader("Gain Comparison","C"); // option "C" allows to center the header
1385  legend.AddEntry(h_firstGains.get(),("IOV: "+std::to_string(std::get<0>(firstiov))).c_str(),"PL");
1386  legend.AddEntry(h_lastGains.get() ,("IOV: "+std::to_string(std::get<0>(lastiov))).c_str(),"PL");
1387  legend.Draw("same");
1388 
1389  // lower plot will be in pad
1390  canvas.cd(); // Go back to the main canvas before defining pad2
1391  TPad pad2("pad2", "pad2", 0, 0.005, 1, 0.3);
1392  pad2.SetTopMargin(0.01);
1393  pad2.SetBottomMargin(0.2);
1394  pad2.SetRightMargin(0.05);
1395  pad2.SetLeftMargin(0.15);
1396  pad2.SetGridy(); // horizontal grid
1397  pad2.Draw();
1398  pad2.cd(); // pad2 becomes the current pad
1399 
1400  // Define the ratio plot
1401  hratio->SetLineColor(kBlack);
1402  hratio->SetMarkerColor(kBlack);
1403  hratio->SetTitle("");
1404  hratio->SetMinimum(0.55); // Define Y ..
1405  hratio->SetMaximum(1.55); // .. range
1406  hratio->SetStats(false); // No statistics on lower plot
1407  hratio->Divide(h_lastGains.get());
1408  hratio->SetMarkerStyle(20);
1409  hratio->Draw("ep"); // Draw the ratio plot
1410 
1411  // Y axis ratio plot settings
1412  hratio->GetYaxis()->SetTitle(("ratio "+std::to_string(std::get<0>(firstiov))+" / "+std::to_string(std::get<0>(lastiov))).c_str());
1413 
1414  hratio->GetYaxis()->SetNdivisions(505);
1415 
1417 
1418  hratio->GetYaxis()->SetTitleSize(25);
1419  hratio->GetXaxis()->SetLabelSize(25);
1420 
1421  hratio->GetYaxis()->SetTitleFont(43);
1422  hratio->GetYaxis()->SetTitleOffset(2.5);
1423  hratio->GetYaxis()->SetLabelFont(43); // Absolute font size in pixel (precision 3)
1424  hratio->GetYaxis()->SetLabelSize(25);
1425 
1426  // X axis ratio plot settings
1427  hratio->GetXaxis()->SetTitleSize(30);
1428  hratio->GetXaxis()->SetTitleFont(43);
1429  hratio->GetXaxis()->SetTitle("SiStrip APV Gains");
1430  hratio->GetXaxis()->SetLabelFont(43); // Absolute font size in pixel (precision 3)
1431  hratio->GetXaxis()->SetTitleOffset(3.);
1432 
1433  std::string fileName(m_imageFileName);
1434  canvas.SaveAs(fileName.c_str());
1435 
1436  return true;
1437  }
1438  };
1439 
1440  //*******************************************//
1441  // Compare Gains ratio from 2 IOVs, region by region
1442  //******************************************//
1443 
1444  class SiStripApvGainsRatioComparatorByRegion : public cond::payloadInspector::PlotImage<SiStripApvGain> {
1445  public:
1446  SiStripApvGainsRatioComparatorByRegion () : cond::payloadInspector::PlotImage<SiStripApvGain>( "Module by Module Comparison of SiStrip APV gains" ),
1447  m_trackerTopo{StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath())}
1448  {
1449  setSingleIov( false );
1450  }
1451 
1452  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
1453 
1454  //gStyle->SetPalette(5);
1456 
1457  std::vector<std::tuple<cond::Time_t,cond::Hash> > sorted_iovs = iovs;
1458 
1459  // make absolute sure the IOVs are sortd by since
1460  std::sort(begin(sorted_iovs), end(sorted_iovs), [](auto const &t1, auto const &t2) {
1461  return std::get<0>(t1) < std::get<0>(t2);
1462  });
1463 
1464  auto firstiov = sorted_iovs.front();
1465  auto lastiov = sorted_iovs.back();
1466 
1467  std::shared_ptr<SiStripApvGain> last_payload = fetchPayload( std::get<1>(lastiov) );
1468  std::shared_ptr<SiStripApvGain> first_payload = fetchPayload( std::get<1>(firstiov) );
1469 
1470  std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
1471  std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
1472 
1473  std::vector<uint32_t> detid;
1474  last_payload->getDetIds(detid);
1475 
1476  std::map<std::pair<uint32_t,int>,float> lastmap,firstmap;
1477 
1478  // loop on the last payload
1479  for (const auto & d : detid) {
1480  SiStripApvGain::Range range=last_payload->getRange(d);
1481  float Gain=0;
1482  float nAPV=0;
1483  for( int it=0; it < range.second - range.first; ++it ) {
1484  nAPV+=1;
1485  Gain=last_payload->getApvGain(it,range);
1486  std::pair<uint32_t,int> index = std::make_pair(d,nAPV);
1487  lastmap[index]=Gain;
1488  } // end loop on APVs
1489  } // end loop on detids
1490 
1491  detid.clear();
1492  first_payload->getDetIds(detid);
1493 
1494  // loop on the first payload
1495  for (const auto & d : detid) {
1496  SiStripApvGain::Range range=first_payload->getRange(d);
1497  float Gain=0;
1498  float nAPV=0;
1499  for( int it=0; it < range.second - range.first; ++it ) {
1500  nAPV+=1;
1501  Gain=first_payload->getApvGain(it,range);
1502  std::pair<uint32_t,int> index = std::make_pair(d,nAPV);
1503  firstmap[index]=Gain;
1504  } // end loop on APVs
1505  } // end loop on detids
1506 
1507  TCanvas canvas("Payload comparison by Tracker Region","payload comparison by Tracker Region",1800,800);
1508  canvas.Divide(2,1);
1509 
1510  auto h2first = std::unique_ptr<TH2F>(new TH2F("byRegion1","SiStrip APV Gain values by region;; average SiStrip Gain",38,1.,39.,100.,0.,2.));
1511  auto h2last = std::unique_ptr<TH2F>(new TH2F("byRegion2","SiStrip APV Gain values by region;; average SiStrip Gain",38,1.,39.,100.,0.,2.));
1512 
1513  auto h2ratio = std::unique_ptr<TH2F>(new TH2F("byRegionRatio",
1514  Form("SiStrip APV Gains ratio by region;; Gains ratio IOV: %s/ IOV %s",lastIOVsince.c_str(),firstIOVsince.c_str())
1515  ,38,1.,39.,100.,0.85,1.15));
1516 
1517  h2first->SetStats(false);
1518  h2last->SetStats(false);
1519  h2ratio->SetStats(false);
1520 
1521  canvas.cd(1)->SetBottomMargin(0.18);
1522  canvas.cd(1)->SetLeftMargin(0.12);
1523  canvas.cd(1)->SetRightMargin(0.05);
1524  canvas.Modified();
1525 
1526  std::vector<int> boundaries;
1528  std::string currentDetector;
1529 
1530  for (const auto &element : lastmap){
1531  auto region = this->getTheRegion(element.first.first);
1532  auto bin = SiStripPI::regionType(region).first;
1533  auto label = SiStripPI::regionType(region).second;
1534 
1535  h2last->Fill(bin,element.second);
1536  h2last->GetXaxis()->SetBinLabel(bin,label);
1537  h2ratio->Fill(bin,element.second/firstmap[element.first]);
1538  h2ratio->GetXaxis()->SetBinLabel(bin,label);
1539  }
1540 
1541  for (const auto &element : firstmap){
1542  auto region = this->getTheRegion(element.first.first);
1543  auto bin = SiStripPI::regionType(region).first;
1544  auto label = SiStripPI::regionType(region).second;
1545 
1546  h2first->Fill(bin,element.second);
1547  h2first->GetXaxis()->SetBinLabel(bin,label);
1548  }
1549 
1550  h2first->GetXaxis()->LabelsOption("v");
1551  h2last->GetXaxis()->LabelsOption("v");
1552  h2ratio->GetXaxis()->LabelsOption("v");
1553 
1554  h2last->SetLineColor(kBlue);
1555  h2first->SetLineColor(kRed);
1556  h2first->SetFillColor(kRed);
1557 
1558  h2first->SetMarkerStyle(20);
1559  h2last->SetMarkerStyle(21);
1560 
1561  h2first->SetMarkerColor(kRed);
1562  h2last->SetMarkerColor(kBlue);
1563 
1564  canvas.cd(1);
1565  h2first->Draw("BOX");
1566  h2last->Draw("BOXsame");
1567 
1568  TLegend legend = TLegend(0.70,0.8,0.95,0.9);
1569  legend.SetHeader("Gain Comparison","C"); // option "C" allows to center the header
1570  legend.AddEntry(h2first.get(),("IOV: "+std::to_string(std::get<0>(firstiov))).c_str(),"F");
1571  legend.AddEntry(h2last.get() ,("IOV: "+std::to_string(std::get<0>(lastiov))).c_str(),"F");
1572  legend.Draw("same");
1573 
1574  canvas.cd(2);
1575  canvas.cd(2)->SetBottomMargin(0.18);
1576  canvas.cd(2)->SetLeftMargin(0.12);
1577  canvas.cd(2)->SetRightMargin(0.12);
1578 
1579  h2ratio->Draw("COLZ");
1580  auto hpfx_tmp = (TProfile*)(h2ratio->ProfileX("_pfx",1,-1,"o"));
1581  hpfx_tmp->SetStats(kFALSE);
1582  hpfx_tmp->SetMarkerColor(kRed);
1583  hpfx_tmp->SetLineColor(kRed);
1584  hpfx_tmp->SetMarkerSize(1.2);
1585  hpfx_tmp->SetMarkerStyle(20);
1586  hpfx_tmp->Draw("same");
1587 
1588  std::string fileName(m_imageFileName);
1589  canvas.SaveAs(fileName.c_str());
1590 
1591  delete hpfx_tmp;
1592  return true;
1593  }
1594  private:
1595  TrackerTopology m_trackerTopo;
1596 
1597  SiStripPI::TrackerRegion getTheRegion(DetId detid){
1598 
1599  int layer = 0;
1600  int stereo = 0;
1601  int detNum = 0;
1602 
1603  switch (detid.subdetId()) {
1604  case StripSubdetector::TIB:
1605  layer = m_trackerTopo.tibLayer(detid);
1606  stereo = m_trackerTopo.tibStereo(detid);
1607  detNum = 1000;
1608  break;
1609  case StripSubdetector::TOB:
1610  layer = m_trackerTopo.tobLayer(detid);
1611  stereo = m_trackerTopo.tobStereo(detid);
1612  detNum = 2000;
1613  break;
1614  case StripSubdetector::TEC:
1615  // is this module in TEC+ or TEC-?
1616  layer = m_trackerTopo.tecWheel(detid);
1617  stereo = m_trackerTopo.tecStereo(detid);
1618  detNum = 3000;
1619  break;
1620  case StripSubdetector::TID:
1621  // is this module in TID+ or TID-?
1622  layer = m_trackerTopo.tidWheel(detid);
1623  stereo = m_trackerTopo.tidStereo(detid);
1624  detNum = 4000;
1625  break;
1626  }
1627 
1628  detNum += layer*10 + stereo;
1629  return static_cast<SiStripPI::TrackerRegion>(detNum);
1630  }
1631 
1632  };
1633 
1634  /************************************************
1635  Compare Gains for each tracker region
1636  *************************************************/
1637 
1638  class SiStripApvGainsComparatorByRegion : public cond::payloadInspector::PlotImage<SiStripApvGain> {
1639  public:
1640  SiStripApvGainsComparatorByRegion() : cond::payloadInspector::PlotImage<SiStripApvGain>( "SiStripGains Comparison By Region" ),
1641  m_trackerTopo{StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath())}
1642  {
1643  setSingleIov( false );
1644  }
1645 
1646  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
1647 
1648  std::vector<std::tuple<cond::Time_t,cond::Hash> > sorted_iovs = iovs;
1649 
1650  // make absolute sure the IOVs are sortd by since
1651  std::sort(begin(sorted_iovs), end(sorted_iovs), [](auto const &t1, auto const &t2) {
1652  return std::get<0>(t1) < std::get<0>(t2);
1653  });
1654 
1655  auto firstiov = sorted_iovs.front();
1656  auto lastiov = sorted_iovs.back();
1657 
1658  std::shared_ptr<SiStripApvGain> last_payload = fetchPayload( std::get<1>(lastiov) );
1659  std::shared_ptr<SiStripApvGain> first_payload = fetchPayload( std::get<1>(firstiov) );
1660 
1661  std::vector<uint32_t> detid;
1662  last_payload->getDetIds(detid);
1663 
1664  SiStripDetSummary summaryLastGain{&m_trackerTopo};
1665 
1666  for (const auto & d : detid) {
1667  SiStripApvGain::Range range=last_payload->getRange(d);
1668  for( int it=0; it < range.second - range.first; ++it ) {
1669  summaryLastGain.add(d,last_payload->getApvGain(it, range));
1670  }
1671  }
1672 
1673  SiStripDetSummary summaryFirstGain{&m_trackerTopo};
1674 
1675  for (const auto & d : detid) {
1676  SiStripApvGain::Range range=first_payload->getRange(d);
1677  for( int it=0; it < range.second - range.first; ++it ) {
1678  summaryFirstGain.add(d,first_payload->getApvGain(it, range));
1679  }
1680  }
1681 
1682  std::map<unsigned int, SiStripDetSummary::Values> firstmap = summaryFirstGain.getCounts();
1683  std::map<unsigned int, SiStripDetSummary::Values> lastmap = summaryLastGain.getCounts();
1684  //=========================
1685 
1686  TCanvas canvas("Region summary","region summary",1200,1000);
1687  canvas.cd();
1688 
1689  auto hfirst = std::unique_ptr<TH1F>(new TH1F("byRegion1","SiStrip APV Gain average by region;; average SiStrip Gain",firstmap.size(),0.,firstmap.size()));
1690  auto hlast = std::unique_ptr<TH1F>(new TH1F("byRegion2","SiStrip APV Gain average by region;; average SiStrip Gain",lastmap.size(),0.,lastmap.size()));
1691 
1692  hfirst->SetStats(false);
1693  hlast->SetStats(false);
1694 
1695  canvas.SetBottomMargin(0.18);
1696  canvas.SetLeftMargin(0.12);
1697  canvas.SetRightMargin(0.05);
1698  canvas.Modified();
1699 
1700  std::vector<int> boundaries;
1701  unsigned int iBin=0;
1702 
1704  std::string currentDetector;
1705 
1706  for (const auto &element : lastmap){
1707  iBin++;
1708  int count = element.second.count;
1709  double mean = (element.second.mean)/count;
1710 
1711  if(currentDetector.empty()) currentDetector="TIB";
1712 
1713  switch ((element.first)/1000)
1714  {
1715  case 1:
1716  detector = "TIB";
1717  break;
1718  case 2:
1719  detector = "TOB";
1720  break;
1721  case 3:
1722  detector = "TEC";
1723  break;
1724  case 4:
1725  detector = "TID";
1726  break;
1727  }
1728 
1729  hlast->SetBinContent(iBin,mean);
1730  hlast->SetBinError(iBin,mean/10000.);
1731  hlast->GetXaxis()->SetBinLabel(iBin,SiStripPI::regionType(element.first).second);
1732  hlast->GetXaxis()->LabelsOption("v");
1733 
1734  if(detector!=currentDetector) {
1735  boundaries.push_back(iBin);
1736  currentDetector=detector;
1737  }
1738  }
1739 
1740  // reset the count
1741  iBin=0;
1742 
1743  for (const auto &element : firstmap){
1744  iBin++;
1745  int count = element.second.count;
1746  double mean = (element.second.mean)/count;
1747 
1748  hfirst->SetBinContent(iBin,mean);
1749  hfirst->SetBinError(iBin,mean/10000.);
1750  hfirst->GetXaxis()->SetBinLabel(iBin,SiStripPI::regionType(element.first).second);
1751  hfirst->GetXaxis()->LabelsOption("v");
1752  }
1753 
1754  auto extrema = SiStripPI::getExtrema(hfirst.get(),hlast.get());
1755  hlast->GetYaxis()->SetRangeUser(extrema.first,extrema.second);
1756 
1757  hlast->SetMarkerStyle(20);
1758  hlast->SetMarkerSize(1);
1759  hlast->Draw("E1");
1760  hlast->Draw("Psame");
1761 
1762  hfirst->SetMarkerStyle(18);
1763  hfirst->SetMarkerSize(1);
1764  hfirst->SetLineColor(kBlue);
1765  hfirst->SetMarkerColor(kBlue);
1766  hfirst->Draw("E1same");
1767  hfirst->Draw("Psame");
1768 
1769  canvas.Update();
1770  canvas.cd();
1771 
1772  TLine l[boundaries.size()];
1773  unsigned int i=0;
1774  for (const auto & line : boundaries){
1775  l[i] = TLine(hfirst->GetBinLowEdge(line),canvas.cd()->GetUymin(),hfirst->GetBinLowEdge(line),canvas.cd()->GetUymax());
1776  l[i].SetLineWidth(1);
1777  l[i].SetLineStyle(9);
1778  l[i].SetLineColor(2);
1779  l[i].Draw("same");
1780  i++;
1781  }
1782 
1783  TLegend legend = TLegend(0.70,0.8,0.95,0.9);
1784  legend.SetHeader("Gain Comparison","C"); // option "C" allows to center the header
1785  legend.AddEntry(hfirst.get(),("IOV: "+std::to_string(std::get<0>(firstiov))).c_str(),"PL");
1786  legend.AddEntry(hlast.get() ,("IOV: "+std::to_string(std::get<0>(lastiov))).c_str(),"PL");
1787  legend.Draw("same");
1788 
1789  std::string fileName(m_imageFileName);
1790  canvas.SaveAs(fileName.c_str());
1791 
1792  return true;
1793  }
1794  private:
1795  TrackerTopology m_trackerTopo;
1796  };
1797 
1798  /************************************************
1799  Plot gain averages by region
1800  *************************************************/
1801 
1802  class SiStripApvGainsByRegion : public cond::payloadInspector::PlotImage<SiStripApvGain> {
1803  public:
1804  SiStripApvGainsByRegion() : cond::payloadInspector::PlotImage<SiStripApvGain>( "SiStripGains By Region" ),
1805  m_trackerTopo{StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath())}
1806  {
1807  setSingleIov( true );
1808  }
1809 
1810  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
1811  auto iov = iovs.front();
1812  std::shared_ptr<SiStripApvGain> payload = fetchPayload( std::get<1>(iov) );
1813 
1814  std::vector<uint32_t> detid;
1815  payload->getDetIds(detid);
1816 
1817  SiStripDetSummary summaryGain{&m_trackerTopo};
1818 
1819  for (const auto & d : detid) {
1820  SiStripApvGain::Range range=payload->getRange(d);
1821  for( int it=0; it < range.second - range.first; ++it ) {
1822  summaryGain.add(d,payload->getApvGain(it, range));
1823  }
1824  }
1825 
1826  std::map<unsigned int, SiStripDetSummary::Values> map = summaryGain.getCounts();
1827  //=========================
1828 
1829  TCanvas canvas("Region summary","region summary",1200,1000);
1830  canvas.cd();
1831  auto h1 = std::unique_ptr<TH1F>(new TH1F("byRegion","SiStrip Gain average by region;; average SiStrip Gain",map.size(),0.,map.size()));
1832  h1->SetStats(false);
1833  canvas.SetBottomMargin(0.18);
1834  canvas.SetLeftMargin(0.12);
1835  canvas.SetRightMargin(0.05);
1836  canvas.Modified();
1837 
1838  std::vector<int> boundaries;
1839  unsigned int iBin=0;
1840 
1842  std::string currentDetector;
1843 
1844  for (const auto &element : map){
1845  iBin++;
1846  int count = element.second.count;
1847  double mean = (element.second.mean)/count;
1848 
1849  if(currentDetector.empty()) currentDetector="TIB";
1850 
1851  switch ((element.first)/1000)
1852  {
1853  case 1:
1854  detector = "TIB";
1855  break;
1856  case 2:
1857  detector = "TOB";
1858  break;
1859  case 3:
1860  detector = "TEC";
1861  break;
1862  case 4:
1863  detector = "TID";
1864  break;
1865  }
1866 
1867  h1->SetBinContent(iBin,mean);
1868  h1->GetXaxis()->SetBinLabel(iBin,SiStripPI::regionType(element.first).second);
1869  h1->GetXaxis()->LabelsOption("v");
1870 
1871  if(detector!=currentDetector) {
1872  boundaries.push_back(iBin);
1873  currentDetector=detector;
1874  }
1875  }
1876 
1877  h1->SetMarkerStyle(20);
1878  h1->SetMarkerSize(1);
1879  h1->Draw("HIST");
1880  h1->Draw("Psame");
1881 
1882  canvas.Update();
1883 
1884  TLine l[boundaries.size()];
1885  unsigned int i=0;
1886  for (const auto & line : boundaries){
1887  l[i] = TLine(h1->GetBinLowEdge(line),canvas.GetUymin(),h1->GetBinLowEdge(line),canvas.GetUymax());
1888  l[i].SetLineWidth(1);
1889  l[i].SetLineStyle(9);
1890  l[i].SetLineColor(2);
1891  l[i].Draw("same");
1892  i++;
1893  }
1894 
1895  TLegend legend = TLegend(0.52,0.82,0.95,0.9);
1896  legend.SetHeader((std::get<1>(iov)).c_str(),"C"); // option "C" allows to center the header
1897  legend.AddEntry(h1.get(),("IOV: "+std::to_string(std::get<0>(iov))).c_str(),"PL");
1898  legend.SetTextSize(0.025);
1899  legend.Draw("same");
1900 
1901  std::string fileName(m_imageFileName);
1902  canvas.SaveAs(fileName.c_str());
1903 
1904  return true;
1905  }
1906  private:
1907  TrackerTopology m_trackerTopo;
1908  };
1909 
1910 } // close namespace
1911 
1912 // Register the classes as boost python plugin
1914  PAYLOAD_INSPECTOR_CLASS(SiStripApvGainsValue);
1915  PAYLOAD_INSPECTOR_CLASS(SiStripApvGainsTest);
1916  PAYLOAD_INSPECTOR_CLASS(SiStripApvGainsByRegion);
1917  PAYLOAD_INSPECTOR_CLASS(SiStripApvGainsComparator);
1918  PAYLOAD_INSPECTOR_CLASS(SiStripApvGainsValuesComparator);
1919  PAYLOAD_INSPECTOR_CLASS(SiStripApvGainsComparatorByRegion);
1920  PAYLOAD_INSPECTOR_CLASS(SiStripApvGainsRatioComparatorByRegion);
1921  PAYLOAD_INSPECTOR_CLASS(SiStripApvBarrelGainsByLayer);
1922  PAYLOAD_INSPECTOR_CLASS(SiStripApvAbsoluteBarrelGainsByLayer);
1923  PAYLOAD_INSPECTOR_CLASS(SiStripApvEndcapMinusGainsByDisk);
1924  PAYLOAD_INSPECTOR_CLASS(SiStripApvEndcapPlusGainsByDisk);
1925  PAYLOAD_INSPECTOR_CLASS(SiStripApvAbsoluteEndcapMinusGainsByDisk);
1926  PAYLOAD_INSPECTOR_CLASS(SiStripApvAbsoluteEndcapPlusGainsByDisk);
1927  PAYLOAD_INSPECTOR_CLASS(SiStripApvGainsAverageTrackerMap);
1928  PAYLOAD_INSPECTOR_CLASS(SiStripApvGainsDefaultTrackerMap);
1929  PAYLOAD_INSPECTOR_CLASS(SiStripApvGainsMaximumTrackerMap);
1930  PAYLOAD_INSPECTOR_CLASS(SiStripApvGainsMinimumTrackerMap);
1931  PAYLOAD_INSPECTOR_CLASS(SiStripApvGainsAvgDeviationRatio1sigmaTrackerMap);
1932  PAYLOAD_INSPECTOR_CLASS(SiStripApvGainsAvgDeviationRatio2sigmaTrackerMap);
1933  PAYLOAD_INSPECTOR_CLASS(SiStripApvGainsAvgDeviationRatio3sigmaTrackerMap);
1934  PAYLOAD_INSPECTOR_CLASS(SiStripApvGainsMaxDeviationRatio1sigmaTrackerMap);
1935  PAYLOAD_INSPECTOR_CLASS(SiStripApvGainsMaxDeviationRatio2sigmaTrackerMap);
1936  PAYLOAD_INSPECTOR_CLASS(SiStripApvGainsMaxDeviationRatio3sigmaTrackerMap);
1937  PAYLOAD_INSPECTOR_CLASS(SiStripApvGainByRunMeans);
1938  PAYLOAD_INSPECTOR_CLASS(SiStripApvGainMin_History);
1939  PAYLOAD_INSPECTOR_CLASS(SiStripApvGainMax_History);
1940  PAYLOAD_INSPECTOR_CLASS(SiStripApvGainMean_History);
1941  PAYLOAD_INSPECTOR_CLASS(SiStripApvGainRMS_History);
1942  PAYLOAD_INSPECTOR_CLASS(SiStripApvTIBGainByRunMeans);
1943  PAYLOAD_INSPECTOR_CLASS(SiStripApvTIDGainByRunMeans);
1944  PAYLOAD_INSPECTOR_CLASS(SiStripApvTOBGainByRunMeans);
1945  PAYLOAD_INSPECTOR_CLASS(SiStripApvTECGainByRunMeans);
1946 }
unsigned int tibLayer(const DetId &id) const
static float getApvGain(uint16_t apv, const Range &range)
uint32_t tobStereo(const DetId &id) const
unsigned int tidWheel(const DetId &id) const
void setPaletteStyle(SiStripPI::palette palette)
void getDetIds(std::vector< uint32_t > &DetIds_) const
char const * label
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
unsigned int tidSide(const DetId &id) const
std::pair< float, float > getTheRange(std::map< uint32_t, float > values, const float nsigma)
void drawStatBox(std::map< std::string, std::shared_ptr< TH1F >> histos, std::map< std::string, int > colormap, std::vector< std::string > legend, double X=0.15, double Y=0.93, double W=0.15, double H=0.10)
uint32_t tidStereo(const DetId &id) const
T sqrt(T t)
Definition: SSEVec.h:18
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::pair< ContainerIterator, ContainerIterator > Range
std::pair< float, float > getExtrema(TH1 *h1, TH1 *h2)
void add(DetId detid, float value)
Used to compute the mean value of the value variable divided by subdetector, layer and mono/stereo...
void makeNicePlotStyle(TH1 *hist)
#define end
Definition: vmac.h:39
void fillWithValue(float value, float weight=1)
T min(T a, T b)
Definition: MathUtil.h:58
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
std::string estimatorType(SiStripPI::estimator e)
std::pair< int, const char * > regionType(int index)
bin
set the eta bin as selection string.
Definition: DetId.h:18
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
part
Definition: HCALResponse.h:20
Definition: plugin.cc:24
#define begin
Definition: vmac.h:32
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs) override
uint32_t tecStereo(const DetId &id) const
TrackerTopology fromTrackerParametersXMLFile(const std::string &xmlFileName)
def canvas(sub, attr)
Definition: svgfig.py:482
const Range getRange(const uint32_t detID) const
uint32_t tibStereo(const DetId &id) const
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
unsigned int tecWheel(const DetId &id) const
unsigned int tobLayer(const DetId &id) const
unsigned int tecSide(const DetId &id) const