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