test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFCandidateChecker.cc
Go to the documentation of this file.
5 
7 
11 
12 
13 using namespace std;
14 using namespace edm;
15 using namespace reco;
16 
18 
19 
20 
21  inputTagPFCandidatesReco_
22  = iConfig.getParameter<InputTag>("pfCandidatesReco");
23 
24  inputTagPFCandidatesReReco_
25  = iConfig.getParameter<InputTag>("pfCandidatesReReco");
26 
27  inputTagPFJetsReco_
28  = iConfig.getParameter<InputTag>("pfJetsReco");
29 
30  inputTagPFJetsReReco_
31  = iConfig.getParameter<InputTag>("pfJetsReReco");
32 
33  deltaEMax_
34  = iConfig.getParameter<double>("deltaEMax");
35 
36  deltaEtaMax_
37  = iConfig.getParameter<double>("deltaEtaMax");
38 
39  deltaPhiMax_
40  = iConfig.getParameter<double>("deltaPhiMax");
41 
42  verbose_ =
43  iConfig.getUntrackedParameter<bool>("verbose",false);
44 
45  printBlocks_ =
46  iConfig.getUntrackedParameter<bool>("printBlocks",false);
47 
48  rankByPt_ =
49  iConfig.getUntrackedParameter<bool>("rankByPt",false);
50 
51  entry_ = 0;
52 
53 
54  LogDebug("PFCandidateChecker")
55  <<" input collections : "<<inputTagPFCandidatesReco_<<" "<<inputTagPFCandidatesReReco_;
56 
57 }
58 
59 
60 
62 
63 
64 
65 void
67  const edm::EventSetup & es) { }
68 
69 
70 void
72  const EventSetup& iSetup) {
73 
74  LogDebug("PFCandidateChecker")<<"START event: "<<iEvent.id().event()
75  <<" in run "<<iEvent.id().run()<<endl;
76 
77 
78 
79  // get PFCandidates
80 
81  Handle<PFCandidateCollection> pfCandidatesReco;
82  iEvent.getByLabel(inputTagPFCandidatesReco_, pfCandidatesReco);
83 
84  Handle<PFCandidateCollection> pfCandidatesReReco;
85  iEvent.getByLabel(inputTagPFCandidatesReReco_, pfCandidatesReReco);
86 
87  Handle<PFJetCollection> pfJetsReco;
88  iEvent.getByLabel(inputTagPFJetsReco_, pfJetsReco);
89 
90  Handle<PFJetCollection> pfJetsReReco;
91  iEvent.getByLabel(inputTagPFJetsReReco_, pfJetsReReco);
92 
93  reco::PFCandidateCollection pfReco, pfReReco;
94 
95  // to sort, one needs to copy
96  if(rankByPt_)
97  {
98  pfReco=*pfCandidatesReco;
99  pfReReco=*pfCandidatesReReco;
100  sort(pfReco.begin(),pfReco.end(),greaterPt);
101  sort(pfReReco.begin(),pfReReco.end(),greaterPt);
102  }
103 
104  unsigned minSize = pfReco.size() < pfReReco.size() ? pfReco.size() : pfReReco.size();
105  bool differentCand = false;
106  bool differentSize = pfReco.size() != pfReReco.size();
107  if ( differentSize )
108  std::cout << "+++WARNING+++ PFCandidate size changed for entry "
109  << entry_ << " !" << endl
110  << " - RECO size : " << pfReco.size() << endl
111  << " - Re-RECO size : " << pfReReco.size() << endl;
112 
113  unsigned npr = 0;
114  for( unsigned i=0; i<minSize; i++ ) {
115 
116  const reco::PFCandidate & candReco = (rankByPt_) ? pfReco[i] : (*pfCandidatesReco)[i];
117  const reco::PFCandidate & candReReco = (rankByPt_) ? pfReReco[i] : (*pfCandidatesReReco)[i];
118 
119  double deltaE = (candReReco.energy()-candReco.energy())/(candReReco.energy()+candReco.energy());
120  double deltaEta = candReReco.eta()-candReco.eta();
121  double deltaPhi = candReReco.phi()-candReco.phi();
122  if ( fabs(deltaE) > deltaEMax_ ||
123  fabs(deltaEta) > deltaEtaMax_ ||
124  fabs(deltaPhi) > deltaPhiMax_ ) {
125  differentCand = true;
126  std::cout << "+++WARNING+++ PFCandidate " << i
127  << " changed for entry " << entry_ << " ! " << std::endl
128  << " - RECO : " << candReco << std::endl
129  << " - Re-RECO : " << candReReco << std::endl
130  << " DeltaE = : " << deltaE << std::endl
131  << " DeltaEta = : " << deltaEta << std::endl
132  << " DeltaPhi = : " << deltaPhi << std::endl << std::endl;
133  if (printBlocks_) {
134  std::cout << "Elements in Block for RECO: " <<std::endl;
135  printElementsInBlocks(candReco);
136  std::cout << "Elements in Block for Re-RECO: " <<std::endl;
137  printElementsInBlocks(candReReco);
138  }
139  if ( ++npr == 5 ) break;
140  }
141  }
142 
143  if ( differentSize || differentCand ) {
144  printJets(*pfJetsReco, *pfJetsReReco);
145  printMet(pfReco, pfReReco);
146  }
147 
148  ++entry_;
149  LogDebug("PFCandidateChecker")<<"STOP event: "<<iEvent.id().event()
150  <<" in run "<<iEvent.id().run()<<std::endl;
151 }
152 
153 
155  const PFCandidateCollection& pfReReco) const {
156 
157  double metX = 0.;
158  double metY = 0.;
159  for( unsigned i=0; i<pfReco.size(); i++ ) {
160  metX += pfReco[i].px();
161  metY += pfReco[i].py();
162  }
163  double met = std::sqrt(metX*metX + metY*metY);
164  std::cout << "MET RECO = " << metX << " " << metY << " " << met << std::endl;
165 
166  metX = 0.;
167  metY = 0.;
168  for( unsigned i=0; i<pfReReco.size(); i++ ) {
169  metX += pfReReco[i].px();
170  metY += pfReReco[i].py();
171  }
172  met = std::sqrt(metX*metX + metY*metY);
173  std::cout << "MET Re-RECO = " << metX << " " << metY << " " << met << std::endl;
174 
175 }
176 
178  const PFJetCollection& pfJetsReReco) const {
179 
180  bool differentSize = pfJetsReco.size() != pfJetsReReco.size();
181  if ( differentSize )
182  std::cout << "+++WARNING+++ PFJet size changed for entry "
183  << entry_ << " !" << endl
184  << " - RECO size : " << pfJetsReco.size() << endl
185  << " - Re-RECO size : " << pfJetsReReco.size() << endl;
186  unsigned minSize = pfJetsReco.size() < pfJetsReReco.size() ? pfJetsReco.size() : pfJetsReReco.size();
187  unsigned npr = 0;
188  for ( unsigned i = 0; i < minSize; ++i) {
189  const reco::PFJet & candReco = pfJetsReco[i];
190  const reco::PFJet & candReReco = pfJetsReReco[i];
191  if ( candReco.et() < 20. && candReReco.et() < 20. ) break;
192  double deltaE = (candReReco.et()-candReco.et())/(candReReco.et()+candReco.et());
193  double deltaEta = candReReco.eta()-candReco.eta();
194  double deltaPhi = candReReco.phi()-candReco.phi();
195  if ( fabs(deltaE) > deltaEMax_ ||
196  fabs(deltaEta) > deltaEtaMax_ ||
197  fabs(deltaPhi) > deltaPhiMax_ ) {
198  std::cout << "+++WARNING+++ PFJet " << i
199  << " changed for entry " << entry_ << " ! " << std::endl
200  << " - RECO : " << candReco.et() << " " << candReco.eta() << " " << candReco.phi() << std::endl
201  << " - Re-RECO : " << candReReco.et() << " " << candReReco.eta() << " " << candReReco.phi() << std::endl
202  << " DeltaE = : " << deltaE << std::endl
203  << " DeltaEta = : " << deltaEta << std::endl
204  << " DeltaPhi = : " << deltaPhi << std::endl << std::endl;
205  if ( ++npr == 5 ) break;
206  } else {
207  std::cout << "Jet " << i << " " << candReco.et() << std::endl;
208  }
209  }
210 
211 }
212 
213 
215  ostream& out) const {
216  if(!out) return;
217 
218  PFBlockRef firstRef;
219 
220  assert(!cand.elementsInBlocks().empty() );
221  for(unsigned i=0; i<cand.elementsInBlocks().size(); i++) {
222  PFBlockRef blockRef = cand.elementsInBlocks()[i].first;
223 
224  if(blockRef.isNull()) {
225  cerr<<"ERROR! no block ref!";
226  continue;
227  }
228 
229  if(!i) {
230  out<<(*blockRef);
231  firstRef = blockRef;
232  }
233  else if( blockRef!=firstRef) {
234  cerr<<"WARNING! This PFCandidate is not made from a single block"<<endl;
235  }
236 
237  out<<"\t"<<cand.elementsInBlocks()[i].second<<endl;
238  }
239 }
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:42
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:44
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
tuple met
____________________________________________________________________________||
Definition: CaloMET_cfi.py:4
virtual double et() const
transverse energy
virtual float phi() const
momentum azimuthal angle
Jets made from PFObjects.
Definition: PFJet.h:21
virtual double energy() const
energy
int iEvent
Definition: GenABIO.cc:230
bool isNull() const
Checks for null.
Definition: Ref.h:247
virtual float eta() const
momentum pseudorapidity
T sqrt(T t)
Definition: SSEVec.h:48
virtual void beginRun(const edm::Run &r, const edm::EventSetup &c)
virtual void analyze(const edm::Event &, const edm::EventSetup &)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
tuple out
Definition: dbtoconf.py:99
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
void printElementsInBlocks(const reco::PFCandidate &cand, std::ostream &out=std::cout) const
edm::EventID id() const
Definition: EventBase.h:56
std::vector< PFJet > PFJetCollection
collection of PFJet objects
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:38
tuple cout
Definition: gather_cfg.py:121
PFCandidateChecker(const edm::ParameterSet &)
const ElementsInBlocks & elementsInBlocks() const
Definition: PFCandidate.cc:675
Definition: Run.h:41
void printMet(const reco::PFCandidateCollection &pfReco, const reco::PFCandidateCollection &pfReReco) const
void printJets(const reco::PFJetCollection &pfJetsReco, const reco::PFJetCollection &pfJetsReReco) const