CMS 3D CMS Logo

NanoAODDQM.cc
Go to the documentation of this file.
9 
10 #include <memory>
11 
12 #include <numeric>
13 #include <regex>
14 #include <sstream>
15 
16 namespace {
17  std::string replaceStringsToColumGets(const std::string &expr, const nanoaod::FlatTable &table) {
18  std::regex token("\\w+");
19  std::sregex_iterator tbegin(expr.begin(), expr.end(), token), tend;
20  if (tbegin == tend)
21  return expr;
22  std::stringstream out;
23  std::sregex_iterator last;
24  for (std::sregex_iterator i = tbegin; i != tend; last = i, ++i) {
25  std::smatch match = *i;
26  out << match.prefix().str();
27  if (table.columnIndex(match.str()) != -1) {
28  out << "getAnyValue(\"" << match.str() << "\")";
29  } else {
30  out << match.str();
31  }
32  }
33  out << last->suffix().str();
34  return out.str();
35  };
36 } // namespace
37 
38 class NanoAODDQM : public DQMEDAnalyzer {
39 public:
41 
43  void analyze(const edm::Event &, const edm::EventSetup &) override;
44 
45 protected:
46  //Book histograms
47  void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
48 
49 private:
50  class Plot {
51  public:
53  virtual ~Plot() {}
54  virtual void fill(const FlatTable &table, const std::vector<bool> &rowsel) = 0;
55  const std::string &name() const { return plot_->getName(); }
56 
57  protected:
59  };
60  class Count1D : public Plot {
61  public:
63  : Plot(booker.book1D(cfg.getParameter<std::string>("name"),
64  cfg.getParameter<std::string>("title"),
65  cfg.getParameter<uint32_t>("nbins"),
66  cfg.getParameter<double>("min"),
67  cfg.getParameter<double>("max"))) {}
68  ~Count1D() override {}
69  void fill(const FlatTable &table, const std::vector<bool> &rowsel) override {
70  plot_->Fill(std::accumulate(rowsel.begin(), rowsel.end(), 0u));
71  }
72  };
73 
74  class Plot1D : public Plot {
75  public:
77  : Plot(booker.book1D(cfg.getParameter<std::string>("name"),
78  cfg.getParameter<std::string>("title"),
79  cfg.getParameter<uint32_t>("nbins"),
80  cfg.getParameter<double>("min"),
81  cfg.getParameter<double>("max"))),
82  col_(cfg.getParameter<std::string>("column")) {}
83  ~Plot1D() override {}
84  void fill(const FlatTable &table, const std::vector<bool> &rowsel) override {
85  int icol = table.columnIndex(col_);
86  if (icol == -1)
87  return; // columns may be missing (e.g. mc-only)
88  switch (table.columnType(icol)) {
90  vfill<float>(table, icol, rowsel);
91  break;
93  vfill<int>(table, icol, rowsel);
94  break;
96  vfill<uint8_t>(table, icol, rowsel);
97  break;
99  vfill<bool>(table, icol, rowsel);
100  break;
101  default:
102  throw cms::Exception("LogicError", "Unsupported type");
103  }
104  }
105 
106  protected:
108  template <typename T>
109  void vfill(const FlatTable &table, int icol, const std::vector<bool> &rowsel) {
110  const auto &data = table.columnData<T>(icol);
111  for (unsigned int i = 0, n = data.size(); i < n; ++i) {
112  if (rowsel[i])
113  plot_->Fill(data[i]);
114  }
115  }
116  };
117  class Profile1D : public Plot {
118  public:
120  : Plot(booker.bookProfile(cfg.getParameter<std::string>("name"),
121  cfg.getParameter<std::string>("title"),
122  cfg.getParameter<uint32_t>("nbins"),
123  cfg.getParameter<double>("min"),
124  cfg.getParameter<double>("max"),
125  0.,
126  0.,
127  "")),
128  ycol_(cfg.getParameter<std::string>("ycolumn")),
129  xcol_(cfg.getParameter<std::string>("xcolumn")) {}
130  ~Profile1D() override {}
131  void fill(const FlatTable &table, const std::vector<bool> &rowsel) override {
132  int icolx = table.columnIndex(xcol_);
133  int icoly = table.columnIndex(ycol_);
134  if (icolx == -1)
135  throw cms::Exception("LogicError", "Missing " + xcol_);
136  if (icoly == -1)
137  throw cms::Exception("LogicError", "Missing " + ycol_);
138  for (unsigned int irow = 0, n = table.size(); irow < n; ++irow) {
139  if (rowsel[irow])
140  plot_->Fill(table.getAnyValue(irow, icolx), table.getAnyValue(irow, icoly));
141  }
142  }
143 
144  protected:
146  };
147 
148  static std::unique_ptr<Plot> makePlot(DQMStore::IBooker &booker, const edm::ParameterSet &cfg) {
149  const std::string &kind = cfg.getParameter<std::string>("kind");
150  if (kind == "none")
151  return nullptr;
152  if (kind == "count1d")
153  return std::make_unique<Count1D>(booker, cfg);
154  if (kind == "hist1d")
155  return std::make_unique<Plot1D>(booker, cfg);
156  if (kind == "prof1d")
157  return std::make_unique<Profile1D>(booker, cfg);
158  throw cms::Exception("Configuration", "Unsupported plot kind '" + kind + "'");
159  }
160 
161  struct SelGroupConfig {
165  std::unique_ptr<StringCutObjectSelector<FlatTable::RowView>> cutptr;
166  std::vector<std::unique_ptr<Plot>> plots;
168  SelGroupConfig(const std::string &nam, const std::string &cut) : name(nam), cutstr(cut), cutptr(), plots() {}
169  bool nullCut() const { return cutstr.empty(); }
170  void fillSel(const FlatTable &table, std::vector<bool> &out) {
171  out.resize(table.size());
172  if (nullCut()) {
173  std::fill(out.begin(), out.end(), true);
174  } else {
175  if (!cutptr) {
176  cutptr = std::make_unique<Selector>(replaceStringsToColumGets(cutstr, table));
177  }
178  for (unsigned int i = 0, n = table.size(); i < n; ++i) {
179  out[i] = (*cutptr)(table.row(i));
180  }
181  }
182  }
183  };
184  struct GroupConfig {
185  std::vector<edm::ParameterSet> plotPSets;
186  std::vector<SelGroupConfig> selGroups;
187  };
188  std::map<std::string, GroupConfig> groups_;
189 };
190 
192  const edm::ParameterSet &vplots = iConfig.getParameter<edm::ParameterSet>("vplots");
193  for (const std::string &name : vplots.getParameterNamesForType<edm::ParameterSet>()) {
194  auto &group = groups_[name];
195  const auto &pset = vplots.getParameter<edm::ParameterSet>(name);
196  group.plotPSets = pset.getParameter<std::vector<edm::ParameterSet>>("plots");
197  group.selGroups.emplace_back(); // no selection (all entries)
198  const auto &cuts = pset.getParameter<edm::ParameterSet>("sels");
199  for (const std::string &cname : cuts.getParameterNamesForType<std::string>()) {
200  group.selGroups.emplace_back(cname, cuts.getParameter<std::string>(cname));
201  }
202  }
203  consumesMany<FlatTable>();
204 }
205 
207  booker.setCurrentFolder("Physics/NanoAODDQM");
208 
209  for (auto &pair : groups_) {
210  booker.setCurrentFolder("Physics/NanoAODDQM/" + pair.first);
211  for (auto &sels : pair.second.selGroups) {
212  std::string dir("Physics/NanoAODDQM/" + pair.first);
213  if (!sels.nullCut())
214  dir += "/" + sels.name;
215  booker.setCurrentFolder(dir);
216  auto &plots = sels.plots;
217  plots.clear();
218  plots.reserve(pair.second.plotPSets.size());
219  for (const auto &cfg : pair.second.plotPSets) {
220  auto plot = makePlot(booker, cfg);
221  if (plot)
222  plots.push_back(std::move(plot));
223  }
224  }
225  }
226 }
227 
229  std::vector<edm::Handle<FlatTable>> alltables;
230  iEvent.getManyByType(alltables);
231  std::map<std::string, std::pair<const FlatTable *, std::vector<const FlatTable *>>> maintables;
232 
233  for (const auto &htab : alltables) {
234  if (htab->extension())
235  continue;
236  maintables[htab->name()] = std::make_pair(htab.product(), std::vector<const FlatTable *>());
237  }
238  for (const auto &htab : alltables) {
239  if (htab->extension()) {
240  if (maintables.find(htab->name()) == maintables.end())
241  throw cms::Exception("LogicError", "Missing main table for " + htab->name());
242  maintables[htab->name()].second.push_back(htab.product());
243  }
244  }
245 
246  FlatTable merged;
247  for (auto &pair : groups_) {
248  const std::string &name = pair.first;
249  if (maintables.find(name) == maintables.end())
250  continue; // may happen for missing collections
251  auto &tables = maintables[name];
252  const FlatTable *table = tables.first;
253  if (!tables.second.empty()) {
254  merged = *tables.first;
255  for (auto *other : tables.second) {
256  merged.addExtension(*other);
257  }
258  table = &merged;
259  }
260  std::vector<bool> selbits;
261  for (auto &sel : pair.second.selGroups) {
262  sel.fillSel(*table, selbits);
263 
264  for (auto &plot : sel.plots) {
265  plot->fill(*table, selbits);
266  }
267  }
268  }
269 }
270 
NanoAODDQM::Plot1D::Plot1D
Plot1D(DQMStore::IBooker &booker, const edm::ParameterSet &cfg)
Definition: NanoAODDQM.cc:76
dqm::impl::MonitorElement
Definition: MonitorElement.h:98
nanoaod::FlatTable::ColumnType::Float
nanoDQM_cff.vplots
vplots
Definition: nanoDQM_cff.py:22
mps_fire.i
i
Definition: mps_fire.py:428
NanoAODDQM::Count1D
Definition: NanoAODDQM.cc:60
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
cuts
const TkSoA *__restrict__ CAHitNtupletGeneratorKernelsGPU::QualityCuts cuts
Definition: CAHitNtupletGeneratorKernelsImpl.h:416
NanoAODDQM::SelGroupConfig
Definition: NanoAODDQM.cc:161
NanoAODDQM::Plot1D
Definition: NanoAODDQM.cc:74
NanoAODDQM::Plot::Plot
Plot(MonitorElement *me)
Definition: NanoAODDQM.cc:52
edm::Run
Definition: Run.h:45
NanoAODDQM::Plot::name
const std::string & name() const
Definition: NanoAODDQM.cc:55
NanoAODDQM::Plot1D::col_
std::string col_
Definition: NanoAODDQM.cc:107
NanoAODDQM::Plot1D::fill
void fill(const FlatTable &table, const std::vector< bool > &rowsel) override
Definition: NanoAODDQM.cc:84
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
DQMStore.h
NanoAODDQM::GroupConfig
Definition: NanoAODDQM.cc:184
NanoAODDQM::SelGroupConfig::cutptr
std::unique_ptr< StringCutObjectSelector< FlatTable::RowView > > cutptr
Definition: NanoAODDQM.cc:165
postprocess-scan-build.tables
tables
Definition: postprocess-scan-build.py:11
plotFactory.plot
plot
Definition: plotFactory.py:109
NanoAODDQM::Profile1D::ycol_
std::string ycol_
Definition: NanoAODDQM.cc:145
NanoAODDQM::Profile1D::Profile1D
Profile1D(DQMStore::IBooker &booker, const edm::ParameterSet &cfg)
Definition: NanoAODDQM.cc:119
MakerMacros.h
dqmdumpme.last
last
Definition: dqmdumpme.py:56
NanoAODDQM::SelGroupConfig::cutstr
std::string cutstr
Definition: NanoAODDQM.cc:164
NanoAODDQM::Plot::plot_
MonitorElement * plot_
Definition: NanoAODDQM.cc:58
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
NanoAODDQM::GroupConfig::selGroups
std::vector< SelGroupConfig > selGroups
Definition: NanoAODDQM.cc:186
NanoAODDQM::Count1D::fill
void fill(const FlatTable &table, const std::vector< bool > &rowsel) override
Definition: NanoAODDQM.cc:69
dqm::impl::MonitorElement::Fill
void Fill(long long x)
Definition: MonitorElement.h:290
NanoAODDQM::Plot
Definition: NanoAODDQM.cc:50
trackingPlots.other
other
Definition: trackingPlots.py:1464
nanoaod::FlatTable::ColumnType::UInt8
NanoAODDQM::bookHistograms
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: NanoAODDQM.cc:206
DQMEDAnalyzer.h
DQMEDAnalyzer
Definition: DQMEDAnalyzer.py:1
ntuplemaker.fill
fill
Definition: ntuplemaker.py:304
nanoaod::FlatTable::addExtension
void addExtension(const FlatTable &extension)
Definition: FlatTable.cc:11
NanoAODDQM::Plot1D::~Plot1D
~Plot1D() override
Definition: NanoAODDQM.cc:83
edm::ParameterSet
Definition: ParameterSet.h:47
HLTObjectsMonitor_cfi.plots
plots
Definition: HLTObjectsMonitor_cfi.py:17
Event.h
NanoAODDQM::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: NanoAODDQM.cc:228
NanoAODDQM::Plot1D::vfill
void vfill(const FlatTable &table, int icol, const std::vector< bool > &rowsel)
Definition: NanoAODDQM.cc:109
match
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
NanoAODDQM::Profile1D::fill
void fill(const FlatTable &table, const std::vector< bool > &rowsel) override
Definition: NanoAODDQM.cc:131
iEvent
int iEvent
Definition: GenABIO.cc:224
NanoAODDQM::GroupConfig::plotPSets
std::vector< edm::ParameterSet > plotPSets
Definition: NanoAODDQM.cc:185
NanoAODDQM::Count1D::Count1D
Count1D(DQMStore::IBooker &booker, const edm::ParameterSet &cfg)
Definition: NanoAODDQM.cc:62
edm::EventSetup
Definition: EventSetup.h:58
NanoAODDQM::SelGroupConfig::SelGroupConfig
SelGroupConfig(const std::string &nam, const std::string &cut)
Definition: NanoAODDQM.cc:168
NanoAODDQM::SelGroupConfig::plots
std::vector< std::unique_ptr< Plot > > plots
Definition: NanoAODDQM.cc:166
CalibrationSummaryClient_cfi.kind
kind
Definition: CalibrationSummaryClient_cfi.py:37
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
FlatTable.h
InputTag.h
NanoAODDQM::FlatTable
nanoaod::FlatTable FlatTable
Definition: NanoAODDQM.cc:40
looper.cfg
cfg
Definition: looper.py:296
nanoaod::FlatTable::ColumnType::Int
nanoaod::FlatTable
Definition: FlatTable.h:38
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
StringCutObjectSelector.h
NanoAODDQM::SelGroupConfig::nullCut
bool nullCut() const
Definition: NanoAODDQM.cc:169
jets_cff.expr
expr
Definition: jets_cff.py:497
Frameworkfwd.h
T
long double T
Definition: Basic3DVectorLD.h:48
PA_MinBiasSkim_cff.cut
cut
Definition: PA_MinBiasSkim_cff.py:13
StringCutObjectSelector
Definition: StringCutObjectSelector.h:16
Exception
Definition: hltDiff.cc:245
NanoAODDQM::makePlot
static std::unique_ptr< Plot > makePlot(DQMStore::IBooker &booker, const edm::ParameterSet &cfg)
Definition: NanoAODDQM.cc:148
NanoAODDQM::SelGroupConfig::name
std::string name
Definition: NanoAODDQM.cc:163
NanoAODDQM::SelGroupConfig::Selector
StringCutObjectSelector< FlatTable::RowView > Selector
Definition: NanoAODDQM.cc:162
NanoAODDQM::groups_
std::map< std::string, GroupConfig > groups_
Definition: NanoAODDQM.cc:188
dqm::impl::MonitorElement::getName
const std::string & getName() const
get name of ME
Definition: MonitorElement.h:250
NanoAODDQM::NanoAODDQM
NanoAODDQM(const edm::ParameterSet &)
Definition: NanoAODDQM.cc:191
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
dqm::implementation::IBooker
Definition: DQMStore.h:43
NanoAODDQM::Count1D::~Count1D
~Count1D() override
Definition: NanoAODDQM.cc:68
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
cms::Exception
Definition: Exception.h:70
NanoAODDQM::Profile1D::xcol_
std::string xcol_
Definition: NanoAODDQM.cc:145
EgammaValidation_Wenu_cff.sel
sel
Definition: EgammaValidation_Wenu_cff.py:33
hlt_dqm_clientPB-live_cfg.me
me
Definition: hlt_dqm_clientPB-live_cfg.py:61
TableParser.table
table
Definition: TableParser.py:111
nanoDQM_cfi.sels
sels
Definition: nanoDQM_cfi.py:9
edm::Event
Definition: Event.h:73
nanoaod::FlatTable::ColumnType::Bool
NanoAODDQM
Definition: NanoAODDQM.cc:38
NanoAODDQM::SelGroupConfig::SelGroupConfig
SelGroupConfig()
Definition: NanoAODDQM.cc:167
NanoAODDQM::SelGroupConfig::fillSel
void fillSel(const FlatTable &table, std::vector< bool > &out)
Definition: NanoAODDQM.cc:170
NanoAODDQM::Plot::fill
virtual void fill(const FlatTable &table, const std::vector< bool > &rowsel)=0
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
NanoAODDQM::Profile1D::~Profile1D
~Profile1D() override
Definition: NanoAODDQM.cc:130
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23
NanoAODDQM::Plot::~Plot
virtual ~Plot()
Definition: NanoAODDQM.cc:53
watchdog.group
group
Definition: watchdog.py:82
NanoAODDQM::Profile1D
Definition: NanoAODDQM.cc:117
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:316