CMS 3D CMS Logo

GenericBenchmarkAnalyzer.cc
Go to the documentation of this file.
2 // author: Mike Schmitt, University of Florida
3 // first version 11/7/2007
4 // extension: Leo Neuhaus & Joanna Weng 09.2008
5 // Performs matching and basic resolution plots of 2 candidate
6 // (or candidate based) collections
7 
10 
16 
19 
21 
24 
25 #include <algorithm>
26 #include <cmath>
27 #include <fstream>
28 #include <iostream>
29 #include <memory>
30 #include <ostream>
31 #include <vector>
32 
33 using namespace reco;
34 using namespace edm;
35 using namespace std;
36 
38  inputTruthLabel_ = iConfig.getParameter<edm::InputTag>("InputTruthLabel");
39  inputRecoLabel_ = iConfig.getParameter<edm::InputTag>("InputRecoLabel");
40  outputFile_ = iConfig.getUntrackedParameter<std::string>("OutputFile");
41  benchmarkLabel_ = iConfig.getParameter<std::string>("BenchmarkLabel");
42  startFromGen_ = iConfig.getParameter<bool>("StartFromGen");
43  plotAgainstRecoQuantities_ = iConfig.getParameter<bool>("PlotAgainstRecoQuantities");
44  onlyTwoJets_ = iConfig.getParameter<bool>("OnlyTwoJets");
45  recPt_cut = iConfig.getParameter<double>("recPt");
46  minEta_cut = iConfig.getParameter<double>("minEta");
47  maxEta_cut = iConfig.getParameter<double>("maxEta");
48  deltaR_cut = iConfig.getParameter<double>("deltaRMax");
49 
50  minDeltaEt_ = iConfig.getParameter<double>("minDeltaEt");
51  maxDeltaEt_ = iConfig.getParameter<double>("maxDeltaEt");
52  minDeltaPhi_ = iConfig.getParameter<double>("minDeltaPhi");
53  maxDeltaPhi_ = iConfig.getParameter<double>("maxDeltaPhi");
54  doMetPlots_ = iConfig.getParameter<bool>("doMetPlots");
55 
56  if (!outputFile_.empty())
57  edm::LogInfo("OutputInfo") << " ParticleFLow Task histograms will be saved to '" << outputFile_.c_str() << "'";
58  else
59  edm::LogInfo("OutputInfo") << " ParticleFlow Task histograms will NOT be saved";
60 
61  myTruth_ = consumes<edm::View<reco::Candidate>>(inputTruthLabel_);
62  myReco_ = consumes<edm::View<reco::Candidate>>(inputRecoLabel_);
63 }
64 
66 
68  // get ahold of back-end interface
70 
71  if (dbe_) {
72  // dbe_->setVerbose(1);
73  // string path = "PFTask/Benchmarks/" + benchmarkLabel_ + "/";
74  std::string path = "ParticleFlow/" + benchmarkLabel_ + "/";
75  if (plotAgainstRecoQuantities_)
76  path += "Reco";
77  else
78  path += "Gen";
79  dbe_->setCurrentFolder(path);
80  setup(dbe_, plotAgainstRecoQuantities_, minDeltaEt_, maxDeltaEt_, minDeltaPhi_, maxDeltaPhi_, doMetPlots_);
81  }
82 }
83 
85  // Typedefs to use views
86  typedef edm::View<reco::Candidate> candidateCollection;
87  typedef edm::View<reco::Candidate> candidateCollection;
88 
89  const candidateCollection *truth_candidates;
90  const candidateCollection *reco_candidates;
91 
92  // ==========================================================
93  // Retrieve!
94  // ==========================================================
95 
96  {
97  // Get Truth Candidates (GenCandidates, GenJets, etc.)
99  bool isGen = iEvent.getByToken(myTruth_, truth_hnd);
100 
101  if (!isGen) {
102  std::cout << "Warning : no Gen jets in input !" << std::endl;
103  return;
104  }
105 
106  truth_candidates = truth_hnd.product();
107 
108  // Get Reco Candidates (PFlow, CaloJet, etc.)
110  bool isReco = iEvent.getByToken(myReco_, reco_hnd);
111  if (!isReco) {
112  std::cout << "Warning : no Reco jets in input !" << std::endl;
113  return;
114  }
115  reco_candidates = reco_hnd.product();
116 
117  // no longer needed with template-ized Benchmark
118  // const PFCandidateCollection *pf_candidates = reco_hnd.product();
119  // static CandidateCollection reco_storage =
120  // algo_->makeCandidateCollection(pf_candidates); reco_candidates =
121  // &reco_storage;
122  }
123  if (!truth_candidates || !reco_candidates) {
124  edm::LogInfo("OutputInfo") << " failed to retrieve data required by ParticleFlow Task";
125  edm::LogInfo("OutputInfo") << " ParticleFlow Task cannot continue...!";
126  return;
127  }
128 
129  // ==========================================================
130  // Analyze!
131  // ==========================================================
132 
133  fill(reco_candidates,
134  truth_candidates,
135  startFromGen_,
136  plotAgainstRecoQuantities_,
137  onlyTwoJets_,
138  recPt_cut,
139  minEta_cut,
140  maxEta_cut,
141  deltaR_cut);
142 }
143 
145  // Store the DAQ Histograms
146  if (!outputFile_.empty())
147  dbe_->save(outputFile_);
148 }
GenericBenchmarkAnalyzer(const edm::ParameterSet &)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void analyze(const edm::Event &, const edm::EventSetup &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
int iEvent
Definition: GenABIO.cc:224
string benchmarkLabel_
DQMStore * dbe_
T const * product() const
Definition: Handle.h:74
fixed size matrix
HLT enums.