ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/DGele/PhysicsTools/PatAlgos/plugins/CandidateSummaryTable.cc
Revision: 1.1.1.1 (vendor branch)
Committed: Tue Oct 20 17:15:14 2009 UTC (15 years, 6 months ago) by dgele
Content type: text/plain
Branch: ANA
CVS Tags: start
Changes since 1.1: +0 -0 lines
Error occurred while calculating annotation data.
Log Message:
version CMSSW_2_2_10

File Contents

# Content
1 //
2 // $Id: CandidateSummaryTable.cc,v 1.1.2.1 2009/01/12 22:08:05 gpetrucc Exp $
3 //
4
5 /**
6 \class pat::CandidateSummaryTable CandidateSummaryTable.h "PhysicsTools/PatAlgos/interface/CandidateSummaryTable.h"
7 \brief Produce a summary table of some candidate collections
8
9 FIXME FIXME Move to CandAlgos
10
11 \author Giovanni Petrucciani
12 \version $Id: CandidateSummaryTable.cc,v 1.1.2.1 2009/01/12 22:08:05 gpetrucc Exp $
13 */
14
15
16 #include "FWCore/Framework/interface/EDAnalyzer.h"
17 #include "FWCore/Framework/interface/Event.h"
18 #include "FWCore/ParameterSet/interface/ParameterSet.h"
19 #include "FWCore/ParameterSet/interface/InputTag.h"
20 #include "FWCore/MessageService/interface/MessageLogger.h"
21 #include <iomanip>
22
23 #include "DataFormats/Common/interface/View.h"
24 #include "DataFormats/Candidate/interface/Candidate.h"
25
26 namespace pat {
27 class CandidateSummaryTable : public edm::EDAnalyzer {
28 public:
29 explicit CandidateSummaryTable(const edm::ParameterSet & iConfig);
30 ~CandidateSummaryTable();
31
32 virtual void analyze(const edm::Event & iEvent, const edm::EventSetup & iSetup);
33 virtual void endJob();
34
35 private:
36 struct Record {
37 edm::InputTag src;
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_;
55 bool perEvent_, perJob_;
56 std::string self_, logName_;
57 bool dumpItems_;
58 };
59
60 } // namespace
61
62 pat::CandidateSummaryTable::CandidateSummaryTable(const edm::ParameterSet & iConfig) :
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
76 pat::CandidateSummaryTable::~CandidateSummaryTable() {
77 }
78
79 void
80 pat::CandidateSummaryTable::analyze(const edm::Event & iEvent, const edm::EventSetup & iSetup) {
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
118 pat::CandidateSummaryTable::endJob() {
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
137 #include "FWCore/Framework/interface/MakerMacros.h"
138 using pat::CandidateSummaryTable;
139 DEFINE_FWK_MODULE(CandidateSummaryTable);