CMS 3D CMS Logo

PFCandidateChecker.cc
Go to the documentation of this file.
1 
17 
18 namespace edm {
19  class EventSetup;
20  class Run;
21 } // namespace edm
22 
24 public:
25  explicit PFCandidateChecker(const edm::ParameterSet&);
26 
27  void analyze(const edm::Event&, const edm::EventSetup&) override;
28 
29 private:
30  void printJets(const reco::PFJetCollection& pfJetsReco, const reco::PFJetCollection& pfJetsReReco) const;
31 
32  void printMet(const reco::PFCandidateCollection& pfReco, const reco::PFCandidateCollection& pfReReco) const;
33 
34  void printElementsInBlocks(const reco::PFCandidate& cand, std::ostream& out = std::cout) const;
35 
41 
43  double deltaEMax_;
44  double deltaEtaMax_;
45  double deltaPhiMax_;
46 
48  bool verbose_;
49 
52 
54  bool rankByPt_;
55 
57  unsigned entry_;
58 
59  static bool greaterPt(const reco::PFCandidate& a, const reco::PFCandidate& b) { return (a.pt() > b.pt()); }
60 };
61 
63 
64 using namespace std;
65 using namespace edm;
66 using namespace reco;
67 
69  inputTagPFCandidatesReco_ = iConfig.getParameter<InputTag>("pfCandidatesReco");
70 
71  inputTagPFCandidatesReReco_ = iConfig.getParameter<InputTag>("pfCandidatesReReco");
72 
73  inputTagPFJetsReco_ = iConfig.getParameter<InputTag>("pfJetsReco");
74 
75  inputTagPFJetsReReco_ = iConfig.getParameter<InputTag>("pfJetsReReco");
76 
77  deltaEMax_ = iConfig.getParameter<double>("deltaEMax");
78 
79  deltaEtaMax_ = iConfig.getParameter<double>("deltaEtaMax");
80 
81  deltaPhiMax_ = iConfig.getParameter<double>("deltaPhiMax");
82 
83  verbose_ = iConfig.getUntrackedParameter<bool>("verbose", false);
84 
85  printBlocks_ = iConfig.getUntrackedParameter<bool>("printBlocks", false);
86 
87  rankByPt_ = iConfig.getUntrackedParameter<bool>("rankByPt", false);
88 
89  entry_ = 0;
90 
91  LogDebug("PFCandidateChecker") << " input collections : " << inputTagPFCandidatesReco_ << " "
92  << inputTagPFCandidatesReReco_;
93 }
94 
95 void PFCandidateChecker::analyze(const Event& iEvent, const EventSetup& iSetup) {
96  LogDebug("PFCandidateChecker") << "START event: " << iEvent.id().event() << " in run " << iEvent.id().run() << endl;
97 
98  // get PFCandidates
99 
100  Handle<PFCandidateCollection> pfCandidatesReco;
101  iEvent.getByLabel(inputTagPFCandidatesReco_, pfCandidatesReco);
102 
103  Handle<PFCandidateCollection> pfCandidatesReReco;
104  iEvent.getByLabel(inputTagPFCandidatesReReco_, pfCandidatesReReco);
105 
106  Handle<PFJetCollection> pfJetsReco;
107  iEvent.getByLabel(inputTagPFJetsReco_, pfJetsReco);
108 
109  Handle<PFJetCollection> pfJetsReReco;
110  iEvent.getByLabel(inputTagPFJetsReReco_, pfJetsReReco);
111 
112  reco::PFCandidateCollection pfReco, pfReReco;
113 
114  // to sort, one needs to copy
115  if (rankByPt_) {
116  pfReco = *pfCandidatesReco;
117  pfReReco = *pfCandidatesReReco;
118  sort(pfReco.begin(), pfReco.end(), greaterPt);
119  sort(pfReReco.begin(), pfReReco.end(), greaterPt);
120  }
121 
122  unsigned minSize = pfReco.size() < pfReReco.size() ? pfReco.size() : pfReReco.size();
123  bool differentCand = false;
124  bool differentSize = pfReco.size() != pfReReco.size();
125  if (differentSize)
126  std::cout << "+++WARNING+++ PFCandidate size changed for entry " << entry_ << " !" << endl
127  << " - RECO size : " << pfReco.size() << endl
128  << " - Re-RECO size : " << pfReReco.size() << endl;
129 
130  unsigned npr = 0;
131  for (unsigned i = 0; i < minSize; i++) {
132  const reco::PFCandidate& candReco = (rankByPt_) ? pfReco[i] : (*pfCandidatesReco)[i];
133  const reco::PFCandidate& candReReco = (rankByPt_) ? pfReReco[i] : (*pfCandidatesReReco)[i];
134 
135  double deltaE = (candReReco.energy() - candReco.energy()) / (candReReco.energy() + candReco.energy());
136  double deltaEta = candReReco.eta() - candReco.eta();
137  double deltaPhi = candReReco.phi() - candReco.phi();
138  if (fabs(deltaE) > deltaEMax_ || fabs(deltaEta) > deltaEtaMax_ || fabs(deltaPhi) > deltaPhiMax_) {
139  differentCand = true;
140  std::cout << "+++WARNING+++ PFCandidate " << i << " changed for entry " << entry_ << " ! " << std::endl
141  << " - RECO : " << candReco << std::endl
142  << " - Re-RECO : " << candReReco << std::endl
143  << " DeltaE = : " << deltaE << std::endl
144  << " DeltaEta = : " << deltaEta << std::endl
145  << " DeltaPhi = : " << deltaPhi << std::endl
146  << std::endl;
147  if (printBlocks_) {
148  std::cout << "Elements in Block for RECO: " << std::endl;
149  printElementsInBlocks(candReco);
150  std::cout << "Elements in Block for Re-RECO: " << std::endl;
151  printElementsInBlocks(candReReco);
152  }
153  if (++npr == 5)
154  break;
155  }
156  }
157 
158  if (differentSize || differentCand) {
159  printJets(*pfJetsReco, *pfJetsReReco);
160  printMet(pfReco, pfReReco);
161  }
162 
163  ++entry_;
164  LogDebug("PFCandidateChecker") << "STOP event: " << iEvent.id().event() << " in run " << iEvent.id().run()
165  << std::endl;
166 }
167 
169  double metX = 0.;
170  double metY = 0.;
171  for (unsigned i = 0; i < pfReco.size(); i++) {
172  metX += pfReco[i].px();
173  metY += pfReco[i].py();
174  }
175  double met = std::sqrt(metX * metX + metY * metY);
176  std::cout << "MET RECO = " << metX << " " << metY << " " << met << std::endl;
177 
178  metX = 0.;
179  metY = 0.;
180  for (unsigned i = 0; i < pfReReco.size(); i++) {
181  metX += pfReReco[i].px();
182  metY += pfReReco[i].py();
183  }
184  met = std::sqrt(metX * metX + metY * metY);
185  std::cout << "MET Re-RECO = " << metX << " " << metY << " " << met << std::endl;
186 }
187 
188 void PFCandidateChecker::printJets(const PFJetCollection& pfJetsReco, const PFJetCollection& pfJetsReReco) const {
189  bool differentSize = pfJetsReco.size() != pfJetsReReco.size();
190  if (differentSize)
191  std::cout << "+++WARNING+++ PFJet size changed for entry " << entry_ << " !" << endl
192  << " - RECO size : " << pfJetsReco.size() << endl
193  << " - Re-RECO size : " << pfJetsReReco.size() << endl;
194  unsigned minSize = pfJetsReco.size() < pfJetsReReco.size() ? pfJetsReco.size() : pfJetsReReco.size();
195  unsigned npr = 0;
196  for (unsigned i = 0; i < minSize; ++i) {
197  const reco::PFJet& candReco = pfJetsReco[i];
198  const reco::PFJet& candReReco = pfJetsReReco[i];
199  if (candReco.et() < 20. && candReReco.et() < 20.)
200  break;
201  double deltaE = (candReReco.et() - candReco.et()) / (candReReco.et() + candReco.et());
202  double deltaEta = candReReco.eta() - candReco.eta();
203  double deltaPhi = candReReco.phi() - candReco.phi();
204  if (fabs(deltaE) > deltaEMax_ || fabs(deltaEta) > deltaEtaMax_ || fabs(deltaPhi) > deltaPhiMax_) {
205  std::cout << "+++WARNING+++ PFJet " << i << " changed for entry " << entry_ << " ! " << std::endl
206  << " - RECO : " << candReco.et() << " " << candReco.eta() << " " << candReco.phi() << std::endl
207  << " - Re-RECO : " << candReReco.et() << " " << candReReco.eta() << " " << candReReco.phi()
208  << std::endl
209  << " DeltaE = : " << deltaE << std::endl
210  << " DeltaEta = : " << deltaEta << std::endl
211  << " DeltaPhi = : " << deltaPhi << std::endl
212  << std::endl;
213  if (++npr == 5)
214  break;
215  } else {
216  std::cout << "Jet " << i << " " << candReco.et() << std::endl;
217  }
218  }
219 }
220 
222  if (!out)
223  return;
224 
225  PFBlockRef firstRef;
226 
227  assert(!cand.elementsInBlocks().empty());
228  for (unsigned i = 0; i < cand.elementsInBlocks().size(); i++) {
229  PFBlockRef blockRef = cand.elementsInBlocks()[i].first;
230 
231  if (blockRef.isNull()) {
232  cerr << "ERROR! no block ref!";
233  continue;
234  }
235 
236  if (!i) {
237  out << (*blockRef);
238  firstRef = blockRef;
239  } else if (blockRef != firstRef) {
240  cerr << "WARNING! This PFCandidate is not made from a single block" << endl;
241  }
242 
243  out << "\t" << cand.elementsInBlocks()[i].second << endl;
244  }
245 }
void analyze(const edm::Event &, const edm::EventSetup &) override
static bool greaterPt(const reco::PFCandidate &a, const reco::PFCandidate &b)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
void printMet(const reco::PFCandidateCollection &pfReco, const reco::PFCandidateCollection &pfReReco) const
void printJets(const reco::PFJetCollection &pfJetsReco, const reco::PFJetCollection &pfJetsReReco) const
unsigned entry_
Counter.
void printElementsInBlocks(const reco::PFCandidate &cand, std::ostream &out=std::cout) const
double deltaEMax_
Cuts for comparison.
assert(be >=bs)
Jets made from PFObjects.
Definition: PFJet.h:20
static const double deltaEta
Definition: CaloConstants.h:8
T getUntrackedParameter(std::string const &, T const &) const
Checks what a re-reco changes in PFCandidates.
int iEvent
Definition: GenABIO.cc:224
T sqrt(T t)
Definition: SSEVec.h:19
bool verbose_
verbose ?
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool isNull() const
Checks for null.
Definition: Ref.h:235
edm::InputTag inputTagPFJetsReReco_
bool rankByPt_
rank the candidates by Pt
edm::InputTag inputTagPFJetsReco_
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
double b
Definition: hdecay.h:120
std::vector< PFJet > PFJetCollection
collection of PFJet objects
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
fixed size matrix
double et() const final
transverse energy
HLT enums.
edm::InputTag inputTagPFCandidatesReco_
PFCandidates in which we&#39;ll look for pile up particles.
double a
Definition: hdecay.h:121
bool printBlocks_
print the blocks associated to a given candidate ?
PFCandidateChecker(const edm::ParameterSet &)
double phi() const final
momentum azimuthal angle
edm::InputTag inputTagPFCandidatesReReco_
Definition: Run.h:45
#define LogDebug(id)
double energy() const final
energy
double eta() const final
momentum pseudorapidity