9 #include "CLHEP/Units/defs.h"
10 #include "CLHEP/Units/PhysicalConstants.h"
15 wmanager_(iPSet,consumesCollector()),
16 hepmcCollection_(iPSet.getParameter<edm::
InputTag>(
"hepmcCollection")),
17 genparticleCollection_(iPSet.getParameter<edm::
InputTag>(
"genparticleCollection")),
18 genjetCollection_(iPSet.getParameter<edm::
InputTag>(
"genjetsCollection")),
19 matchPr_(iPSet.getParameter<double>(
"matchingPrecision")),
20 verbosity_(iPSet.getUntrackedParameter<unsigned int>(
"verbosity",0))
83 unsigned int initSize = 1000;
90 HepMC::GenEvent *myGenEvent =
new HepMC::GenEvent(*(evt->GetEvent()));
96 std::vector<const HepMC::GenParticle*> hepmcGPCollection;
97 std::vector<int> barcodeList;
98 hepmcGPCollection.reserve(initSize);
99 barcodeList.reserve(initSize);
102 for (HepMC::GenEvent::particle_const_iterator iter = myGenEvent->particles_begin(); iter != myGenEvent->particles_end(); ++iter){
103 if ( (*iter)->status() == 1) {
104 hepmcGPCollection.push_back(*iter);
105 barcodeList.push_back((*iter)->barcode());
107 std::cout <<
"HepMC " << std::setw(14) << std::fixed << (*iter)->pdg_id() << std::setw(14) << std::fixed << (*iter)->momentum().px() << std::setw(14) << std::fixed
108 << (*iter)->momentum().py() << std::setw(14) << std::fixed << (*iter)->momentum().pz() << std::endl;
118 std::vector<const reco::GenParticle*> particles;
119 particles.reserve(initSize);
120 for (reco::GenParticleCollection::const_iterator iter=genParticles->begin();iter!=genParticles->end();++iter){
121 if ( (*iter).status() == 1) {
122 particles.push_back(&*iter);
124 std::cout <<
"reco " << std::setw(14) << std::fixed << (*iter).pdgId() << std::setw(14) << std::fixed << (*iter).px()
125 << std::setw(14) << std::fixed << (*iter).py() << std::setw(14) << std::fixed << (*iter).pz() << std::endl;
130 unsigned int nReco = particles.size();
131 unsigned int nHepMC = hepmcGPCollection.size();
136 std::vector<int> hepmcMatchIndex;
137 hepmcMatchIndex.reserve(initSize);
143 if ( nReco != nHepMC ) {
144 edm::LogWarning(
"CollectionSizeInconsistency") <<
"Collection size inconsistency: HepMC::GenParticle = " << nHepMC <<
" reco::GenParticle = " << nReco;
149 for (
unsigned int i = 0;
i < nReco; ++
i ){
150 for (
unsigned int j = 0;
j < nHepMC; ++
j ){
152 hepmcMatchIndex.push_back((
int)j);
153 if ( hepmcGPCollection[j]->momentum().
rho() != 0. ) {
154 double reso = 1.-particles[
i]->p()/hepmcGPCollection[
j]->momentum().rho();
156 std::cout <<
"Matching momentum: reco = " << particles[
i]->p() <<
" HepMC = "
157 << hepmcGPCollection[
j]->momentum().rho() <<
" resoultion = " << reso << std::endl;
167 unsigned int nMatched = hepmcMatchIndex.size();
169 if ( nMatched != nReco ) {
170 edm::LogWarning(
"IncorrectMatching") <<
"Incorrect number of matched indexes: GenParticle = " << nReco <<
" matched indexes = " << nMatched;
174 unsigned int nWrMatch = 0;
176 for (
unsigned int i = 0;
i < nMatched; ++
i ){
177 for (
unsigned int j =
i+1;
j < nMatched; ++
j ){
178 if ( hepmcMatchIndex[
i] == hepmcMatchIndex[
j] ) {
179 int theIndex = hepmcMatchIndex[
i];
180 edm::LogWarning(
"DuplicatedMatching") <<
"Multiple matching occurencies for GenParticle barcode = " << barcodeList[theIndex];
195 int nJetsCentral = 0;
198 std::vector<double>
jetEta;
199 jetEta.reserve(initSize);
201 for (reco::GenJetCollection::const_iterator iter=genJets->begin();iter!=genJets->end();++iter){
203 double pt = (*iter).pt();
205 if (pt > 1.) nJetso1++;
206 if (pt > 10.) nJetso10++;
207 if (pt > 100.) nJetso100++;
208 double eta = (*iter).eta();
209 if ( std::fabs(eta) < 2.5 ) nJetsCentral++;
210 jetEta.push_back(eta);
227 if ( jetEta.size() > 1 ) {
228 for (
unsigned int i = 0;
i < jetEta.size();
i++){
229 for (
unsigned int j =
i+1;
j < jetEta.size();
j++){
230 deltaEta =
std::min(deltaEta,std::fabs(jetEta[
i]-jetEta[
j]));
244 if ( hepmcP->pdg_id() != recoP->
pdgId() )
return state;
245 if ( std::fabs(hepmcP->momentum().px()-recoP->
px()) < std::fabs(
matchPr_*hepmcP->momentum().px()) &&
246 std::fabs(hepmcP->momentum().py()-recoP->
py()) < std::fabs(
matchPr_*hepmcP->momentum().py()) &&
247 std::fabs(hepmcP->momentum().pz()-recoP->
pz()) < std::fabs(
matchPr_*hepmcP->momentum().pz())) {
virtual void beginRun(const edm::Run &, const edm::EventSetup &)
MonitorElement * genJetCentral
edm::ESHandle< HepPDT::ParticleDataTable > fPDGTable
PDT table.
MonitorElement * genMatched
DQMStore * dbe
ME's "container".
MonitorElement * multipleMatching
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
virtual int pdgId() const GCC11_FINAL
PDG identifier.
virtual void analyze(const edm::Event &, const edm::EventSetup &)
MonitorElement * genJetEta
MonitorElement * genJetEnergy
MonitorElement * genJetTotPt
edm::InputTag genparticleCollection_
bool matchParticles(const HepMC::GenParticle *&, const reco::GenParticle *&)
virtual ~BasicGenParticleValidation()
virtual double pz() const GCC11_FINAL
z coordinate of momentum vector
virtual double py() const GCC11_FINAL
y coordinate of momentum vector
void getData(T &iHolder) const
MonitorElement * genJetMult
edm::InputTag hepmcCollection_
MonitorElement * genJetDeltaEtaMin
edm::EDGetTokenT< reco::GenJetCollection > genjetCollectionToken_
MonitorElement * genJetPto1
virtual double px() const GCC11_FINAL
x coordinate of momentum vector
MonitorElement * genJetPt
edm::EDGetTokenT< edm::HepMCProduct > hepmcCollectionToken_
edm::InputTag genjetCollection_
MonitorElement * matchedResolution
MonitorElement * genJetPto10
MonitorElement * genPMultiplicity
MonitorElement * genJetPhi
MonitorElement * genJetPto100
BasicGenParticleValidation(const edm::ParameterSet &)
double weight(const edm::Event &)
virtual void endRun(const edm::Run &, const edm::EventSetup &)
edm::EDGetTokenT< reco::GenParticleCollection > genparticleCollectionToken_
void setCurrentFolder(const std::string &fullpath)