CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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>
129 void GenericBenchmark::fill(const C *RecoCollection,
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
void fillHistos(const reco::Candidate *genParticle, const reco::Candidate *recParticle, double deltaR_cut, bool plotAgainstReco)
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.)
bool onlyTwoJets
virtual double et() const =0
transverse energy
virtual double pt() const =0
transverse momentum
void setfile(TFile *file)
PFBenchmarkAlgo * algo_
dqm::legacy::DQMStore DQMStore
assert(be >=bs)
bool accepted(const reco::Candidate *particle, double ptCut, double minEtaCut, double maxEtaCut) const
virtual ~GenericBenchmark() noexcept(false)
TH2F * hRecSetOverTrueSetvsTrueSet
static double deltaR(const T *, const U *)
TH2F * hDeltaEtOverEtvsDeltaR
virtual double py() const =0
y coordinate of momentum vector
virtual double px() const =0
x coordinate of momentum vector
bool plotAgainstReco
static const Collection::value_type * matchByDeltaR(const T *, const Collection *)
TH2F * hEtRecOverTrueEtvsTrueEt
void write(std::string Filename)
dqm::legacy::MonitorElement MonitorElement
BenchmarkTree * tree_
def template
Definition: svgfig.py:521
virtual double phi() const =0
momentum azimuthal angle
virtual double eta() const =0
momentum pseudorapidity
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)