CMS 3D CMS Logo

GenericBenchmark.h
Go to the documentation of this file.
1 #ifndef RecoParticleFlow_Benchmark_GenericBenchmark_h
2 #define RecoParticleFlow_Benchmark_GenericBenchmark_h
3 
4 //COLIN: necessary?
6 
11 
12 #include <string>
13 
14 #include <TH1F.h>
15 #include <TH2F.h>
16 #include <TFile.h>
17 
18 class BenchmarkTree;
19 
20 //COLIN: this class REALLY needs to be cleaned up and rationalized, on the model of PFCandidateBenchmark.
22 public:
25 
27  virtual ~GenericBenchmark() noexcept(false);
28 
29  void setup(DQMStore *DQM = nullptr,
30  bool PlotAgainstReco_ = true,
31  float minDeltaEt = -100.,
32  float maxDeltaEt = 50.,
33  float minDeltaPhi = -0.5,
34  float maxDeltaPhi = 0.5,
35  bool doMetPlots = false);
36 
37  template <typename C>
38  void fill(const C *RecoCollection,
39  const C *GenCollection,
40  bool startFromGen = false,
41  bool PlotAgainstReco = true,
42  bool onlyTwoJets = false,
43  double recPt_cut = -1.,
44  double minEta_cut = -1.,
45  double maxEta_cut = -1.,
46  double deltaR_cut = -1.);
47 
48  void write(std::string Filename);
49 
50  void setfile(TFile *file);
51 
52 private:
53  bool accepted(const reco::Candidate *particle, double ptCut, double minEtaCut, double maxEtaCut) const;
54 
55  void fillHistos(const reco::Candidate *genParticle,
56  const reco::Candidate *recParticle,
57  double deltaR_cut,
58  bool plotAgainstReco);
59 
60  TFile *file_;
61 
62  TH1F *hDeltaEt;
63  TH1F *hDeltaEx;
64  TH1F *hDeltaEy;
65  TH2F *hDeltaEtvsEt;
73 
74  TH2F *hEtRecvsEt;
76 
77  TH1F *hDeltaEta;
80 
81  TH1F *hDeltaPhi;
84 
85  TH1F *hDeltaR;
86  TH2F *hDeltaRvsEt;
87  TH2F *hDeltaRvsEta;
88 
89  TH1F *hNRec;
90 
91  TH1F *hEtGen;
92  TH1F *hEtaGen;
93  TH2F *hEtvsEtaGen;
94  TH2F *hEtvsPhiGen;
95  TH1F *hPhiGen;
96 
97  TH1F *hNGen;
98 
99  TH1F *hEtSeen;
100  TH1F *hEtaSeen;
101  TH1F *hPhiSeen;
104 
105  TH1F *hEtRec;
106  TH1F *hExRec;
107  TH1F *hEyRec;
108  TH1F *hPhiRec;
109 
110  TH1F *hSumEt;
111  TH1F *hTrueSumEt;
118 
120 
122 
123 protected:
126 };
127 
128 template <typename C>
130  const C *GenCollection,
131  bool startFromGen,
132  bool PlotAgainstReco,
133  bool onlyTwoJets,
134  double recPt_cut,
135  double minEta_cut,
136  double maxEta_cut,
137  double deltaR_cut) {
138  //if (doMetPlots_)
139  //{
140  // const reco::MET* met1=static_cast<const reco::MET*>(&((*RecoCollection)[0]));
141  // if (met1!=NULL) std::cout << "FL: met1.sumEt() = " << (*met1).sumEt() << std::endl;
142  //}
143 
144  // loop over reco particles
145 
146  if (!startFromGen) {
147  int nRec = 0;
148  for (unsigned int i = 0; i < RecoCollection->size(); i++) {
149  // generate histograms comparing the reco and truth candidate (truth = closest in delta-R)
150  const reco::Candidate *particle = &(*RecoCollection)[i];
151 
152  assert(particle != nullptr);
153  if (!accepted(particle, recPt_cut, minEta_cut, maxEta_cut))
154  continue;
155 
156  // Count the number of jets with a larger energy
157  if (onlyTwoJets) {
158  unsigned highJets = 0;
159  for (unsigned j = 0; j < RecoCollection->size(); j++) {
160  const reco::Candidate *otherParticle = &(*RecoCollection)[j];
161  if (j != i && otherParticle->pt() > particle->pt())
162  highJets++;
163  }
164  if (highJets > 1)
165  continue;
166  }
167  nRec++;
168 
169  const reco::Candidate *gen_particle = algo_->matchByDeltaR(particle, GenCollection);
170  if (gen_particle == nullptr)
171  continue;
172 
173  // fill histograms
174  fillHistos(gen_particle, particle, deltaR_cut, PlotAgainstReco);
175  }
176 
177  hNRec->Fill(nRec);
178  }
179 
180  // loop over gen particles
181 
182  // std::cout<<"Reco size = "<<RecoCollection->size()<<", ";
183  // std::cout<<"Gen size = "<<GenCollection->size()<<std::endl;
184 
185  int nGen = 0;
186  for (unsigned int i = 0; i < GenCollection->size(); i++) {
187  const reco::Candidate *gen_particle = &(*GenCollection)[i];
188 
189  if (!accepted(gen_particle, recPt_cut, minEta_cut, maxEta_cut)) {
190  continue;
191  }
192 
193  hEtaGen->Fill(gen_particle->eta());
194  hPhiGen->Fill(gen_particle->phi());
195  hEtGen->Fill(gen_particle->et());
196  hEtvsEtaGen->Fill(gen_particle->eta(), gen_particle->et());
197  hEtvsPhiGen->Fill(gen_particle->phi(), gen_particle->et());
198 
199  const reco::Candidate *rec_particle = algo_->matchByDeltaR(gen_particle, RecoCollection);
200  nGen++;
201  if (!rec_particle)
202  continue; // no match
203  // must make a cut on delta R - so let's do the cut
204 
205  double deltaR = algo_->deltaR(rec_particle, gen_particle);
206  if (deltaR > deltaR_cut && deltaR_cut != -1.)
207  continue;
208 
209  hEtaSeen->Fill(gen_particle->eta());
210  hPhiSeen->Fill(gen_particle->phi());
211  hEtSeen->Fill(gen_particle->et());
212  hEtvsEtaSeen->Fill(gen_particle->eta(), gen_particle->et());
213  hEtvsPhiSeen->Fill(gen_particle->phi(), gen_particle->et());
214 
215  hPhiRec->Fill(rec_particle->phi());
216  hEtRec->Fill(rec_particle->et());
217  hExRec->Fill(rec_particle->px());
218  hEyRec->Fill(rec_particle->py());
219 
220  hEtRecvsEt->Fill(gen_particle->et(), rec_particle->et());
221  if (gen_particle->et() != 0.0)
222  hEtRecOverTrueEtvsTrueEt->Fill(gen_particle->et(), rec_particle->et() / gen_particle->et());
223 
224  if (startFromGen)
225  fillHistos(gen_particle, rec_particle, deltaR_cut, PlotAgainstReco);
226  }
227  hNGen->Fill(nGen);
228 }
229 
230 #endif // RecoParticleFlow_Benchmark_GenericBenchmark_h
GenericBenchmark::hDeltaEy
TH1F * hDeltaEy
Definition: GenericBenchmark.h:64
GenericBenchmark::hDeltaR
TH1F * hDeltaR
Definition: GenericBenchmark.h:85
GenericBenchmark::hEtSeen
TH1F * hEtSeen
Definition: GenericBenchmark.h:99
PFBenchmarkAlgo::deltaR
static double deltaR(const T *, const U *)
Definition: PFBenchmarkAlgo.h:174
mps_fire.i
i
Definition: mps_fire.py:355
GenericBenchmark::file_
TFile * file_
Definition: GenericBenchmark.h:60
GenericBenchmark::hDeltaRvsEt
TH2F * hDeltaRvsEt
Definition: GenericBenchmark.h:86
funct::false
false
Definition: Factorize.h:34
GenericBenchmark::hDeltaEtOverEtvsEt
TH2F * hDeltaEtOverEtvsEt
Definition: GenericBenchmark.h:66
configurableAnalysis::Candidate
char Candidate[]
Definition: modules.cc:20
GenericBenchmark::hDeltaEtOverEtvsDeltaR
TH2F * hDeltaEtOverEtvsDeltaR
Definition: GenericBenchmark.h:72
reco::Candidate::eta
virtual double eta() const =0
momentum pseudorapidity
GenericBenchmark::hEyRec
TH1F * hEyRec
Definition: GenericBenchmark.h:107
GenericBenchmark
Definition: GenericBenchmark.h:21
GenericBenchmark::hEtvsPhiSeen
TH2F * hEtvsPhiSeen
Definition: GenericBenchmark.h:103
GenericBenchmark::hEtRecOverTrueEtvsTrueEt
TH2F * hEtRecOverTrueEtvsTrueEt
Definition: GenericBenchmark.h:75
GenericBenchmark::accepted
bool accepted(const reco::Candidate *particle, double ptCut, double minEtaCut, double maxEtaCut) const
Definition: GenericBenchmark.cc:238
GenericBenchmark::hDeltaRvsEta
TH2F * hDeltaRvsEta
Definition: GenericBenchmark.h:87
reco::Candidate::pt
virtual double pt() const =0
transverse momentum
cms::cuda::assert
assert(be >=bs)
DQMStore.h
GenericBenchmark::MonitorElement
dqm::legacy::MonitorElement MonitorElement
Definition: GenericBenchmark.h:24
dqm::legacy::MonitorElement
Definition: MonitorElement.h:461
GenericBenchmark::hPhiRec
TH1F * hPhiRec
Definition: GenericBenchmark.h:108
GenericBenchmark::hDeltaSetvsSet
TH2F * hDeltaSetvsSet
Definition: GenericBenchmark.h:112
GenericBenchmark::hDeltaMexvsSet
TH2F * hDeltaMexvsSet
Definition: GenericBenchmark.h:113
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
GenericBenchmark::hEtaGen
TH1F * hEtaGen
Definition: GenericBenchmark.h:92
watchdog.const
const
Definition: watchdog.py:83
GenericBenchmark::hDeltaEtavsEta
TH2F * hDeltaEtavsEta
Definition: GenericBenchmark.h:79
GenericBenchmark::hDeltaEtOverEtvsPhi
TH2F * hDeltaEtOverEtvsPhi
Definition: GenericBenchmark.h:70
GenericBenchmark::GenericBenchmark
GenericBenchmark()
Definition: GenericBenchmark.cc:33
onlyTwoJets
bool onlyTwoJets
Definition: PFJetBenchmarkAnalyzer.cc:72
GenericBenchmark::hSumEt
TH1F * hSumEt
Definition: GenericBenchmark.h:110
CandidateFwd.h
BenchmarkTree
Definition: BenchmarkTree.h:25
GenericBenchmark::hDeltaSetOverSetvsSet
TH2F * hDeltaSetOverSetvsSet
Definition: GenericBenchmark.h:114
GenericBenchmark::hTrueSumEt
TH1F * hTrueSumEt
Definition: GenericBenchmark.h:111
GenericBenchmark::hEtvsEtaGen
TH2F * hEtvsEtaGen
Definition: GenericBenchmark.h:93
GenericBenchmark::hDeltaEtOverEtvsEta
TH2F * hDeltaEtOverEtvsEta
Definition: GenericBenchmark.h:68
dqm::legacy::DQMStore
Definition: DQMStore.h:727
GenericBenchmark::fill
void fill(const C *RecoCollection, const C *GenCollection, bool startFromGen=false, bool PlotAgainstReco=true, bool onlyTwoJets=false, double recPt_cut=-1., double minEta_cut=-1., double maxEta_cut=-1., double deltaR_cut=-1.)
Definition: GenericBenchmark.h:129
GenericBenchmark::hEtGen
TH1F * hEtGen
Definition: GenericBenchmark.h:91
GenericBenchmark::setup
void setup(DQMStore *DQM=nullptr, bool PlotAgainstReco_=true, float minDeltaEt=-100., float maxDeltaEt=50., float minDeltaPhi=-0.5, float maxDeltaPhi=0.5, bool doMetPlots=false)
Definition: GenericBenchmark.cc:37
GenericBenchmark::hRecSetvsTrueSet
TH2F * hRecSetvsTrueSet
Definition: GenericBenchmark.h:115
GenericBenchmark::hDeltaEx
TH1F * hDeltaEx
Definition: GenericBenchmark.h:63
GenericBenchmark::fillHistos
void fillHistos(const reco::Candidate *genParticle, const reco::Candidate *recParticle, double deltaR_cut, bool plotAgainstReco)
Definition: GenericBenchmark.cc:255
GenericBenchmark::tree_
BenchmarkTree * tree_
Definition: GenericBenchmark.h:119
GenericBenchmark::write
void write(std::string Filename)
Definition: GenericBenchmark.cc:342
GenericBenchmark::hEtRecvsEt
TH2F * hEtRecvsEt
Definition: GenericBenchmark.h:74
GenericBenchmark::hDeltaEtavsEt
TH2F * hDeltaEtavsEt
Definition: GenericBenchmark.h:78
benchmark_cfg.minDeltaEt
minDeltaEt
Definition: benchmark_cfg.py:55
PbPb_ZMuSkimMuonDPG_cff.deltaR
deltaR
Definition: PbPb_ZMuSkimMuonDPG_cff.py:63
benchmark_cfg.doMetPlots
doMetPlots
Definition: benchmark_cfg.py:62
PFBenchmarkAlgo::matchByDeltaR
static const Collection::value_type * matchByDeltaR(const T *, const Collection *)
Definition: PFBenchmarkAlgo.h:183
GenericBenchmark::hDeltaEta
TH1F * hDeltaEta
Definition: GenericBenchmark.h:77
reco::Candidate::py
virtual double py() const =0
y coordinate of momentum vector
funct::true
true
Definition: Factorize.h:173
GenericBenchmark::hDeltaEtvsEt
TH2F * hDeltaEtvsEt
Definition: GenericBenchmark.h:65
GenericBenchmark::setfile
void setfile(TFile *file)
Definition: GenericBenchmark.cc:347
GenericBenchmark::hPhiSeen
TH1F * hPhiSeen
Definition: GenericBenchmark.h:101
jetfilter_cfi.ptCut
ptCut
Definition: jetfilter_cfi.py:6
GenericBenchmark::hDeltaEtvsPhi
TH2F * hDeltaEtvsPhi
Definition: GenericBenchmark.h:69
GenericBenchmark::hNGen
TH1F * hNGen
Definition: GenericBenchmark.h:97
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
GenericBenchmark::hEtaSeen
TH1F * hEtaSeen
Definition: GenericBenchmark.h:100
GenericBenchmark::dbe_
DQMStore * dbe_
Definition: GenericBenchmark.h:124
svgfig.template
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
PFBenchmarkAlgo.h
plotAgainstReco
bool plotAgainstReco
Definition: PFJetBenchmarkAnalyzer.cc:71
GenericBenchmark::DQMStore
dqm::legacy::DQMStore DQMStore
Definition: GenericBenchmark.h:23
GenericBenchmark::hExRec
TH1F * hExRec
Definition: GenericBenchmark.h:106
GenericBenchmark::hDeltaEtvsEta
TH2F * hDeltaEtvsEta
Definition: GenericBenchmark.h:67
GenericBenchmark::doMetPlots_
bool doMetPlots_
Definition: GenericBenchmark.h:121
reco::Candidate
Definition: Candidate.h:27
PFBenchmarkAlgo
Definition: PFBenchmarkAlgo.h:16
MET.h
DQM
Definition: DQM.py:1
GenericBenchmark::hEtvsPhiGen
TH2F * hEtvsPhiGen
Definition: GenericBenchmark.h:94
std
Definition: JetResolutionObject.h:76
GenericBenchmark::hDeltaPhi
TH1F * hDeltaPhi
Definition: GenericBenchmark.h:81
GenericBenchmark::hDeltaEtvsDeltaR
TH2F * hDeltaEtvsDeltaR
Definition: GenericBenchmark.h:71
gen::C
C
Definition: PomwigHadronizer.cc:76
GenericBenchmark::algo_
PFBenchmarkAlgo * algo_
Definition: GenericBenchmark.h:125
reco::Candidate::px
virtual double px() const =0
x coordinate of momentum vector
GenericBenchmark::hDeltaPhivsEta
TH2F * hDeltaPhivsEta
Definition: GenericBenchmark.h:83
GenericBenchmark::hTrueMexvsTrueSet
TH2F * hTrueMexvsTrueSet
Definition: GenericBenchmark.h:117
GenericBenchmark::hEtvsEtaSeen
TH2F * hEtvsEtaSeen
Definition: GenericBenchmark.h:102
CommPDSkim_cfg.maxDeltaPhi
maxDeltaPhi
Definition: CommPDSkim_cfg.py:74
GenericBenchmark::hPhiGen
TH1F * hPhiGen
Definition: GenericBenchmark.h:95
EgammaObjectsElectrons_cfi.RecoCollection
RecoCollection
Definition: EgammaObjectsElectrons_cfi.py:7
GenericBenchmark::hDeltaPhivsEt
TH2F * hDeltaPhivsEt
Definition: GenericBenchmark.h:82
GenericBenchmark::hEtRec
TH1F * hEtRec
Definition: GenericBenchmark.h:105
Candidate.h
GenericBenchmark::hNRec
TH1F * hNRec
Definition: GenericBenchmark.h:89
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
GenericBenchmark::~GenericBenchmark
virtual ~GenericBenchmark() noexcept(false)
Definition: GenericBenchmark.cc:35
GenericBenchmark::hDeltaEt
TH1F * hDeltaEt
Definition: GenericBenchmark.h:62
reco::Candidate::phi
virtual double phi() const =0
momentum azimuthal angle
benchmark_cfg.maxDeltaEt
maxDeltaEt
Definition: benchmark_cfg.py:59
GenericBenchmark::hRecSetOverTrueSetvsTrueSet
TH2F * hRecSetOverTrueSetvsTrueSet
Definition: GenericBenchmark.h:116
VBFGenJetFilter_cfi.minDeltaPhi
minDeltaPhi
Definition: VBFGenJetFilter_cfi.py:13
reco::Candidate::et
virtual double et() const =0
transverse energy