9 #include "CLHEP/Units/defs.h"
10 #include "CLHEP/Units/PhysicalConstants.h"
16 wmanager_(iPSet,consumesCollector()),
17 hepmcCollection_(iPSet.getParameter<edm::
InputTag>(
"hepmcCollection")),
18 genparticleCollection_(iPSet.getParameter<edm::
InputTag>(
"genparticleCollection")),
19 genjetCollection_(iPSet.getParameter<edm::
InputTag>(
"genjetsCollection")),
20 matchPr_(iPSet.getParameter<double>(
"matchingPrecision")),
21 verbosity_(iPSet.getUntrackedParameter<unsigned int>(
"verbosity",0))
72 unsigned int initSize = 1000;
79 HepMC::GenEvent *myGenEvent =
new HepMC::GenEvent(*(evt->GetEvent()));
85 std::vector<const HepMC::GenParticle*> hepmcGPCollection;
86 std::vector<int> barcodeList;
87 hepmcGPCollection.reserve(initSize);
88 barcodeList.reserve(initSize);
91 for (HepMC::GenEvent::particle_const_iterator
iter = myGenEvent->particles_begin();
iter != myGenEvent->particles_end(); ++
iter){
92 if ( (*iter)->status() == 1) {
93 hepmcGPCollection.push_back(*
iter);
94 barcodeList.push_back((*iter)->barcode());
96 std::cout <<
"HepMC " << std::setw(14) << std::fixed << (*iter)->pdg_id() << std::setw(14) << std::fixed << (*iter)->momentum().px() << std::setw(14) << std::fixed
97 << (*iter)->momentum().py() << std::setw(14) << std::fixed << (*iter)->momentum().pz() << std::endl;
107 std::vector<const reco::GenParticle*> particles;
108 particles.reserve(initSize);
109 for (reco::GenParticleCollection::const_iterator
iter=genParticles->begin();
iter!=genParticles->end();++
iter){
110 if ( (*iter).status() == 1) {
111 particles.push_back(&*
iter);
113 std::cout <<
"reco " << std::setw(14) << std::fixed << (*iter).pdgId() << std::setw(14) << std::fixed << (*iter).px()
114 << std::setw(14) << std::fixed << (*iter).py() << std::setw(14) << std::fixed << (*iter).pz() << std::endl;
119 unsigned int nReco = particles.size();
120 unsigned int nHepMC = hepmcGPCollection.size();
125 std::vector<int> hepmcMatchIndex;
126 hepmcMatchIndex.reserve(initSize);
132 if ( nReco != nHepMC ) {
133 edm::LogWarning(
"CollectionSizeInconsistency") <<
"Collection size inconsistency: HepMC::GenParticle = " << nHepMC <<
" reco::GenParticle = " << nReco;
138 for (
unsigned int i = 0;
i < nReco; ++
i ){
139 for (
unsigned int j = 0;
j < nHepMC; ++
j ){
141 hepmcMatchIndex.push_back((
int)j);
142 if ( hepmcGPCollection[j]->momentum().
rho() != 0. ) {
143 double reso = 1.-particles[
i]->p()/hepmcGPCollection[
j]->momentum().rho();
145 std::cout <<
"Matching momentum: reco = " << particles[
i]->p() <<
" HepMC = "
146 << hepmcGPCollection[
j]->momentum().rho() <<
" resoultion = " << reso << std::endl;
156 unsigned int nMatched = hepmcMatchIndex.size();
158 if ( nMatched != nReco ) {
159 edm::LogWarning(
"IncorrectMatching") <<
"Incorrect number of matched indexes: GenParticle = " << nReco <<
" matched indexes = " << nMatched;
163 unsigned int nWrMatch = 0;
165 for (
unsigned int i = 0;
i < nMatched; ++
i ){
166 for (
unsigned int j =
i+1;
j < nMatched; ++
j ){
167 if ( hepmcMatchIndex[
i] == hepmcMatchIndex[
j] ) {
169 edm::LogWarning(
"DuplicatedMatching") <<
"Multiple matching occurencies for GenParticle barcode = " << barcodeList[
theIndex];
184 int nJetsCentral = 0;
187 std::vector<double>
jetEta;
188 jetEta.reserve(initSize);
190 for (reco::GenJetCollection::const_iterator
iter=genJets->begin();
iter!=genJets->end();++
iter){
192 double pt = (*iter).pt();
194 if (pt > 1.) nJetso1++;
195 if (pt > 10.) nJetso10++;
196 if (pt > 100.) nJetso100++;
197 double eta = (*iter).eta();
198 if ( std::fabs(eta) < 2.5 ) nJetsCentral++;
199 jetEta.push_back(eta);
216 if ( jetEta.size() > 1 ) {
217 for (
unsigned int i = 0;
i < jetEta.size();
i++){
218 for (
unsigned int j =
i+1;
j < jetEta.size();
j++){
219 deltaEta =
std::min(deltaEta,std::fabs(jetEta[
i]-jetEta[
j]));
233 if ( hepmcP->pdg_id() != recoP->
pdgId() )
return state;
234 if ( std::fabs(hepmcP->momentum().px()-recoP->
px()) < std::fabs(
matchPr_*hepmcP->momentum().px()) &&
235 std::fabs(hepmcP->momentum().py()-recoP->
py()) < std::fabs(
matchPr_*hepmcP->momentum().py()) &&
236 std::fabs(hepmcP->momentum().pz()-recoP->
pz()) < std::fabs(
matchPr_*hepmcP->momentum().pz())) {
MonitorElement * genJetCentral
virtual int pdgId() const
PDG identifier.
MonitorElement * genMatched
MonitorElement * multipleMatching
bool getByToken(EDGetToken token, Handle< PROD > &result) const
MonitorElement * genJetEta
MonitorElement * genJetEnergy
MonitorElement * genJetTotPt
edm::InputTag genparticleCollection_
bool matchParticles(const HepMC::GenParticle *&, const reco::GenParticle *&)
virtual ~BasicGenParticleValidation()
MonitorElement * genJetMult
edm::InputTag hepmcCollection_
MonitorElement * genJetDeltaEtaMin
edm::EDGetTokenT< reco::GenJetCollection > genjetCollectionToken_
MonitorElement * genJetPto1
MonitorElement * genJetPt
edm::EDGetTokenT< edm::HepMCProduct > hepmcCollectionToken_
edm::InputTag genjetCollection_
void setCurrentFolder(const std::string &fullpath)
virtual double px() const
x coordinate of momentum vector
MonitorElement * matchedResolution
MonitorElement * book1dHisto(const std::string &name, const std::string &title, int n, double xmin, double xmax)
MonitorElement * genJetPto10
virtual double pz() const
z coordinate of momentum vector
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
virtual void bookHistograms(DQMStore::IBooker &i, edm::Run const &, edm::EventSetup const &) override
MonitorElement * genPMultiplicity
MonitorElement * genJetPhi
MonitorElement * genJetPto100
BasicGenParticleValidation(const edm::ParameterSet &)
double weight(const edm::Event &)
virtual double py() const
y coordinate of momentum vector
edm::EDGetTokenT< reco::GenParticleCollection > genparticleCollectionToken_