test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiPixelPhase1TrackEfficiencyHarvester.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiPixelPhase1TrackEfficiencyHarvester
4 // Class: SiPixelPhase1TrackEfficiencyHarvester
5 //
6 
7 // Original Author: Marcel Schneider
8 
11 
13  SiPixelPhase1Harvester(iConfig)
14 {
15  // We collect _all_ (all specs/all custom calls) histos from missing/valid in our table
16  histo[VALID ].setCustomHandler([&] (SummationStep& s, HistogramManager::Table& t,
18  valid [s.arg].insert(t.begin(), t.end());
19  });
20  histo[MISSING ].setCustomHandler([&] (SummationStep& s, HistogramManager::Table& t,
22  missing[s.arg].insert(t.begin(), t.end());
23  });
24 
25  // ... and then take those that we need to fill the EFFICIENCY
26  // note: we don't need the iBooker here, since the eff. histograms are booked with a HistogramManager
27  histo[EFFICIENCY].setCustomHandler([&] (SummationStep& s, HistogramManager::Table& t,
29  doHarvesting(s, t);
30  });
31 }
32 
34  for (auto const& e : efficiency) {
35  GeometryInterface::Values const& values = e.first;
36  auto missing_it = missing[s.arg].find(values);
37  auto valid_it = valid [s.arg].find(values);
38  if (missing_it == missing[s.arg].end() || valid_it == valid[s.arg].end()) {
39  edm::LogError("SiPixelPhase1TrackEfficiencyHarvester") << "Want to do Efficiencies but 'valid' or 'missing' counts are missing.";
40  continue;
41  }
42  auto num = missing_it->second.th1;
43  auto denom = valid_it->second.th1;
44  assert(num);
45  assert(denom);
46  assert(num->GetDimension() == denom->GetDimension());
47 
48  auto& out = efficiency[values];
49  assert(out.th1);
50  assert(out.th1->GetDimension() == num->GetDimension());
51 
52  if (num->GetDimension() == 1) {
53  auto xbins = num->GetXaxis()->GetNbins();
54  assert(denom->GetXaxis()->GetNbins() == xbins || out.th1->GetXaxis()->GetNbins());
55 
56  for (int x = 1; x <= xbins; x++) {
57  auto sum = num->GetBinContent(x) + denom->GetBinContent(x);
58  if (sum == 0.0) continue; // avoid div by zero
59  out.th1->SetBinContent(x, 1 - (num->GetBinContent(x) / sum));
60  }
61 
62  } else /* 2D */ {
63  auto xbins = num->GetXaxis()->GetNbins();
64  auto ybins = num->GetYaxis()->GetNbins();
65  assert(denom->GetXaxis()->GetNbins() == xbins || out.th1->GetXaxis()->GetNbins());
66  assert(denom->GetYaxis()->GetNbins() == ybins || out.th1->GetYaxis()->GetNbins());
67 
68  for (int y = 1; y <= ybins; y++) {
69  for (int x = 1; x <= xbins; x++) {
70  auto sum = num->GetBinContent(x,y) + denom->GetBinContent(x,y);
71  if (sum == 0.0) continue; // avoid div by zero
72  out.th1->SetBinContent(x, y, 1 - (num->GetBinContent(x,y) / sum));
73  }
74  }
75  }
76  }
77 }
78 
80 
const double xbins[]
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
assert(m_qm.get())
void doHarvesting(SummationStep &s, HistogramManager::Table &efficiency)
std::map< std::string, HistogramManager::Table > missing
SiPixelPhase1TrackEfficiencyHarvester(const edm::ParameterSet &conf)
std::map< GeometryInterface::Values, AbstractHistogram > Table
std::vector< HistogramManager > histo
std::map< std::string, HistogramManager::Table > valid