CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GenericBenchmarkAnalyzer.cc
Go to the documentation of this file.
1 // author: Mike Schmitt, University of Florida
2 // first version 11/7/2007
3 // extension: Leo Neuhaus & Joanna Weng 09.2008
4 // Performs matching and basic resolution plots of 2 candidate
5 // (or candidate based) collections
6 
22 
23 #include <algorithm>
24 #include <cmath>
25 #include <fstream>
26 #include <iostream>
27 #include <map>
28 #include <memory>
29 #include <ostream>
30 #include <vector>
31 
33 public:
35  ~GenericBenchmarkAnalyzer() override;
36 
37  void analyze(const edm::Event &, const edm::EventSetup &) override;
38  void beginJob() override;
39  void endJob() override;
40 
41 private:
42  // Inputs from Configuration File
52  double recPt_cut;
53  double minEta_cut;
54  double maxEta_cut;
55  double deltaR_cut;
56  float minDeltaEt_;
57  float maxDeltaEt_;
58  float minDeltaPhi_;
59  float maxDeltaPhi_;
61 };
62 
65 
66 using namespace reco;
67 using namespace edm;
68 using namespace std;
69 
71  inputTruthLabel_ = iConfig.getParameter<edm::InputTag>("InputTruthLabel");
72  inputRecoLabel_ = iConfig.getParameter<edm::InputTag>("InputRecoLabel");
73  outputFile_ = iConfig.getUntrackedParameter<std::string>("OutputFile");
74  benchmarkLabel_ = iConfig.getParameter<std::string>("BenchmarkLabel");
75  startFromGen_ = iConfig.getParameter<bool>("StartFromGen");
76  plotAgainstRecoQuantities_ = iConfig.getParameter<bool>("PlotAgainstRecoQuantities");
77  onlyTwoJets_ = iConfig.getParameter<bool>("OnlyTwoJets");
78  recPt_cut = iConfig.getParameter<double>("recPt");
79  minEta_cut = iConfig.getParameter<double>("minEta");
80  maxEta_cut = iConfig.getParameter<double>("maxEta");
81  deltaR_cut = iConfig.getParameter<double>("deltaRMax");
82 
83  minDeltaEt_ = iConfig.getParameter<double>("minDeltaEt");
84  maxDeltaEt_ = iConfig.getParameter<double>("maxDeltaEt");
85  minDeltaPhi_ = iConfig.getParameter<double>("minDeltaPhi");
86  maxDeltaPhi_ = iConfig.getParameter<double>("maxDeltaPhi");
87  doMetPlots_ = iConfig.getParameter<bool>("doMetPlots");
88 
89  if (!outputFile_.empty())
90  edm::LogInfo("OutputInfo") << " ParticleFLow Task histograms will be saved to '" << outputFile_.c_str() << "'";
91  else
92  edm::LogInfo("OutputInfo") << " ParticleFlow Task histograms will NOT be saved";
93 
94  myTruth_ = consumes<edm::View<reco::Candidate>>(inputTruthLabel_);
95  myReco_ = consumes<edm::View<reco::Candidate>>(inputRecoLabel_);
96 }
97 
99 
101  // get ahold of back-end interface
103 
104  if (dbe_) {
105  // dbe_->setVerbose(1);
106  // string path = "PFTask/Benchmarks/" + benchmarkLabel_ + "/";
107  std::string path = "ParticleFlow/" + benchmarkLabel_ + "/";
108  if (plotAgainstRecoQuantities_)
109  path += "Reco";
110  else
111  path += "Gen";
112  dbe_->setCurrentFolder(path);
113  setup(dbe_, plotAgainstRecoQuantities_, minDeltaEt_, maxDeltaEt_, minDeltaPhi_, maxDeltaPhi_, doMetPlots_);
114  }
115 }
116 
118  // Typedefs to use views
119  typedef edm::View<reco::Candidate> candidateCollection;
120  typedef edm::View<reco::Candidate> candidateCollection;
121 
122  const candidateCollection *truth_candidates;
123  const candidateCollection *reco_candidates;
124 
125  // ==========================================================
126  // Retrieve!
127  // ==========================================================
128 
129  {
130  // Get Truth Candidates (GenCandidates, GenJets, etc.)
131  Handle<candidateCollection> truth_hnd;
132  bool isGen = iEvent.getByToken(myTruth_, truth_hnd);
133 
134  if (!isGen) {
135  std::cout << "Warning : no Gen jets in input !" << std::endl;
136  return;
137  }
138 
139  truth_candidates = truth_hnd.product();
140 
141  // Get Reco Candidates (PFlow, CaloJet, etc.)
143  bool isReco = iEvent.getByToken(myReco_, reco_hnd);
144  if (!isReco) {
145  std::cout << "Warning : no Reco jets in input !" << std::endl;
146  return;
147  }
148  reco_candidates = reco_hnd.product();
149 
150  // no longer needed with template-ized Benchmark
151  // const PFCandidateCollection *pf_candidates = reco_hnd.product();
152  // static CandidateCollection reco_storage =
153  // algo_->makeCandidateCollection(pf_candidates); reco_candidates =
154  // &reco_storage;
155  }
156  if (!truth_candidates || !reco_candidates) {
157  edm::LogInfo("OutputInfo") << " failed to retrieve data required by ParticleFlow Task";
158  edm::LogInfo("OutputInfo") << " ParticleFlow Task cannot continue...!";
159  return;
160  }
161 
162  // ==========================================================
163  // Analyze!
164  // ==========================================================
165 
166  fill(reco_candidates,
167  truth_candidates,
168  startFromGen_,
169  plotAgainstRecoQuantities_,
170  onlyTwoJets_,
171  recPt_cut,
172  minEta_cut,
173  maxEta_cut,
174  deltaR_cut);
175 }
176 
178  // Store the DAQ Histograms
179  if (!outputFile_.empty())
180  dbe_->save(outputFile_);
181 }
GenericBenchmarkAnalyzer(const edm::ParameterSet &)
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:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< edm::View< reco::Candidate > > myTruth_
int iEvent
Definition: GenABIO.cc:224
string benchmarkLabel_
Log< level::Info, false > LogInfo
void fill(std::map< std::string, TH1 * > &h, const std::string &s, double x)
T const * product() const
Definition: Handle.h:70
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< edm::View< reco::Candidate > > myReco_
tuple cout
Definition: gather_cfg.py:144