CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CandidateSummaryTable.cc
Go to the documentation of this file.
1 //
2 // $Id: CandidateSummaryTable.cc,v 1.5 2013/02/27 23:26:56 wmtan Exp $
3 //
4 
21 #include <iomanip>
22 
25 
26 namespace pat {
28  public:
29  explicit CandidateSummaryTable(const edm::ParameterSet & iConfig);
31 
32  virtual void analyze(const edm::Event & iEvent, const edm::EventSetup& iSetup) override;
33  virtual void endJob();
34 
35  private:
36  struct Record {
38  size_t present, empty, min, max, total;
39  Record(edm::InputTag tag) : src(tag), present(0), empty(0), min(0), max(0), total(0) {}
40 
41  void update(const edm::View<reco::Candidate> &items) {
42  present++;
43  size_t size = items.size();
44  if (size == 0) {
45  empty++;
46  } else {
47  if (min > size) min = size;
48  if (max < size) max = size;
49  }
50  total += size;
51  }
52  };
53  std::vector<Record> collections_;
54  size_t totalEvents_;
57  bool dumpItems_;
58  };
59 
60 } // namespace
61 
63  totalEvents_(0),
64  perEvent_(iConfig.getUntrackedParameter<bool>("perEvent", false)),
65  perJob_(iConfig.getUntrackedParameter<bool>("perJob", true)),
66  self_(iConfig.getParameter<std::string>("@module_label")),
67  logName_(iConfig.getUntrackedParameter<std::string>("logName")),
68  dumpItems_(iConfig.getUntrackedParameter<bool>("dumpItems", false))
69 {
70  std::vector<edm::InputTag> inputs = iConfig.getParameter<std::vector<edm::InputTag> >("candidates");
71  for (std::vector<edm::InputTag>::const_iterator it = inputs.begin(); it != inputs.end(); ++it) {
72  collections_.push_back(Record(*it));
73  }
74 }
75 
77 }
78 
79 void
81  using namespace edm;
82  using std::setw; using std::left; using std::right; using std::setprecision;
83 
84  Handle<View<reco::Candidate> > candidates;
85  if (perEvent_) {
86  LogInfo(logName_) << "Per Event Table " << logName_ <<
87  " (" << self_ << ", run:event " << iEvent.id().run() << ":" << iEvent.id().event() << ")";
88  }
89  totalEvents_++;
90  for (std::vector<Record>::iterator it = collections_.begin(), ed = collections_.end(); it != ed; ++it) {
91  iEvent.getByLabel(it->src, candidates);
92  if (!candidates.failedToGet()) it->update(*candidates);
93  if (perEvent_) {
94  LogVerbatim(logName_) << " " << setw(30) << left << it->src.encode() << right;
95  if (dumpItems_) {
96  size_t i = 0;
97  std::ostringstream oss;
98  for (View<reco::Candidate>::const_iterator cand = candidates->begin(), endc = candidates->end(); cand != endc; ++cand, ++i) {
99  oss << " [" << setw(3) << i << "]" <<
100  " pt " << setw(7) << setprecision(5) << cand->pt() <<
101  " eta " << setw(7) << setprecision(5) << cand->eta() <<
102  " phi " << setw(7) << setprecision(5) << cand->phi() <<
103  " et " << setw(7) << setprecision(5) << cand->et() <<
104  " phi " << setw(7) << setprecision(5) << cand->phi() <<
105  " charge " << setw(2) << cand->charge() <<
106  " id " << setw(7) << cand->pdgId() <<
107  " st " << setw(7) << cand->status() << "\n";
108  }
109  LogVerbatim(logName_) << oss.str();
110  }
111  }
112  }
113  if (perEvent_) LogInfo(logName_) << "" ; // add an empty line
114 }
115 
116 
117 void
119  using std::setw; using std::left; using std::right; using std::setprecision;
120  if (perJob_) {
121  std::ostringstream oss;
122  oss << "Summary Table " << logName_ << " (" << self_ << ", events total " << totalEvents_ << ")\n";
123  for (std::vector<Record>::iterator it = collections_.begin(), ed = collections_.end(); it != ed; ++it) {
124  oss << " " << setw(30) << left << it->src.encode() << right <<
125  " present " << setw(7) << it->present << " (" << setw(4) << setprecision(3) << (it->present*100.0/totalEvents_) << "%)" <<
126  " empty " << setw(7) << it->empty << " (" << setw(4) << setprecision(3) << (it->empty*100.0/totalEvents_) << "%)" <<
127  " min " << setw(7) << it->min <<
128  " max " << setw(7) << it->max <<
129  " total " << setw(7) << it->total <<
130  " avg " << setw(5) << setprecision(3) << (it->total/double(totalEvents_)) << "\n";
131  }
132  oss << "\n";
133  edm::LogVerbatim(logName_) << oss.str();
134  }
135 }
136 
RunNumber_t run() const
Definition: EventID.h:42
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:44
int i
Definition: DBlmapReader.cc:9
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
virtual void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
CandidateSummaryTable(const edm::ParameterSet &iConfig)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void update(const edm::View< reco::Candidate > &items)
int iEvent
Definition: GenABIO.cc:243
Produce a summary table of some candidate collections.
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
size_type size() const
edm::EventID id() const
Definition: EventBase.h:56
tuple size
Write out results.
std::vector< Record > collections_