CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
BasicGenParticleValidation Class Reference

#include <BasicGenParticleValidation.h>

Inheritance diagram for BasicGenParticleValidation:
edm::EDAnalyzer

Public Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
 
 BasicGenParticleValidation (const edm::ParameterSet &)
 
virtual void beginJob ()
 
virtual void beginRun (const edm::Run &, const edm::EventSetup &)
 
virtual void endJob ()
 
virtual void endRun (const edm::Run &, const edm::EventSetup &)
 
bool matchParticles (const HepMC::GenParticle *&, const reco::GenParticle *&)
 
virtual ~BasicGenParticleValidation ()
 
- Public Member Functions inherited from edm::EDAnalyzer
 EDAnalyzer ()
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 

Private Attributes

WeightManager _wmanager
 
DQMStoredbe
 ME's "container". More...
 
edm::ESHandle
< HepPDT::ParticleDataTable
fPDGTable
 PDT table. More...
 
MonitorElementgenJetCentral
 
edm::InputTag genjetCollection_
 
MonitorElementgenJetDeltaEtaMin
 
MonitorElementgenJetEnergy
 
MonitorElementgenJetEta
 
MonitorElementgenJetMult
 
MonitorElementgenJetPhi
 
MonitorElementgenJetPt
 
MonitorElementgenJetPto1
 
MonitorElementgenJetPto10
 
MonitorElementgenJetPto100
 
MonitorElementgenJetTotPt
 
MonitorElementgenMatched
 
edm::InputTag genparticleCollection_
 
MonitorElementgenPMultiplicity
 
edm::InputTag hepmcCollection_
 
MonitorElementmatchedResolution
 
double matchPr_
 
MonitorElementmultipleMatching
 
MonitorElementnEvt
 
unsigned int verbosity_
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
typedef WorkerT< EDAnalyzerWorkerType
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Member Functions inherited from edm::EDAnalyzer
CurrentProcessingContext const * currentContext () const
 

Detailed Description

Definition at line 39 of file BasicGenParticleValidation.h.

Constructor & Destructor Documentation

BasicGenParticleValidation::BasicGenParticleValidation ( const edm::ParameterSet iPSet)
explicit

Definition at line 16 of file BasicGenParticleValidation.cc.

References dbe, and cppFunctionSkipper::operator.

16  :
17  _wmanager(iPSet),
18  hepmcCollection_(iPSet.getParameter<edm::InputTag>("hepmcCollection")),
19  genparticleCollection_(iPSet.getParameter<edm::InputTag>("genparticleCollection")),
20  genjetCollection_(iPSet.getParameter<edm::InputTag>("genjetsCollection")),
21  matchPr_(iPSet.getParameter<double>("matchingPrecision")),
22  verbosity_(iPSet.getUntrackedParameter<unsigned int>("verbosity",0))
23 {
24  dbe = 0;
26 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
DQMStore * dbe
ME&#39;s &quot;container&quot;.
BasicGenParticleValidation::~BasicGenParticleValidation ( )
virtual

Definition at line 28 of file BasicGenParticleValidation.cc.

28 {}

Member Function Documentation

void BasicGenParticleValidation::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
virtual

Gathering the HepMCProduct information

Implements edm::EDAnalyzer.

Definition at line 77 of file BasicGenParticleValidation.cc.

References _wmanager, gather_cfg::cout, HLTFastRecoForTau_cff::deltaEta, eta(), MonitorElement::Fill(), genJetCentral, genjetCollection_, genJetDeltaEtaMin, genJetEnergy, genJetEta, genJetMult, genJetPhi, genJetPt, genJetPto1, genJetPto10, genJetPto100, genJetTotPt, genMatched, genparticleCollection_, genParticleCandidates2GenParticles_cfi::genParticles, genPMultiplicity, edm::Event::getByLabel(), hepmcCollection_, i, j, reco::btau::jetEta, matchedResolution, matchParticles(), min, multipleMatching, nEvt, rho, verbosity_, WeightManager::weight(), and CommonMethods::weight().

78 {
79 
80  unsigned int initSize = 1000;
81 
84  iEvent.getByLabel(hepmcCollection_, evt);
85 
86  //Get HepMC EVENT
87  HepMC::GenEvent *myGenEvent = new HepMC::GenEvent(*(evt->GetEvent()));
88 
89  double weight = _wmanager.weight(iEvent);
90 
91  nEvt->Fill(0.5, weight);
92 
93  std::vector<const HepMC::GenParticle*> hepmcGPCollection;
94  std::vector<int> barcodeList;
95  hepmcGPCollection.reserve(initSize);
96  barcodeList.reserve(initSize);
97 
98  //Looping through HepMC::GenParticle collection to search for status 1 particles
99  for (HepMC::GenEvent::particle_const_iterator iter = myGenEvent->particles_begin(); iter != myGenEvent->particles_end(); ++iter){
100  if ( (*iter)->status() == 1) {
101  hepmcGPCollection.push_back(*iter);
102  barcodeList.push_back((*iter)->barcode());
103  if ( verbosity_ > 0 ) {
104  std::cout << "HepMC " << std::setw(14) << std::fixed << (*iter)->pdg_id() << std::setw(14) << std::fixed << (*iter)->momentum().px() << std::setw(14) << std::fixed
105  << (*iter)->momentum().py() << std::setw(14) << std::fixed << (*iter)->momentum().pz() << std::endl;
106  }
107  }
108  }
109 
110 
111  // Gather information on the reco::GenParticle collection
113  iEvent.getByLabel(genparticleCollection_, genParticles );
114 
115  std::vector<const reco::GenParticle*> particles;
116  particles.reserve(initSize);
117  for (reco::GenParticleCollection::const_iterator iter=genParticles->begin();iter!=genParticles->end();++iter){
118  if ( (*iter).status() == 1) {
119  particles.push_back(&*iter);
120  if ( verbosity_ > 0 ) {
121  std::cout << "reco " << std::setw(14) << std::fixed << (*iter).pdgId() << std::setw(14) << std::fixed << (*iter).px()
122  << std::setw(14) << std::fixed << (*iter).py() << std::setw(14) << std::fixed << (*iter).pz() << std::endl;
123  }
124  }
125  }
126 
127  unsigned int nReco = particles.size();
128  unsigned int nHepMC = hepmcGPCollection.size();
129 
130  genPMultiplicity->Fill(std::log10(nReco), weight);
131 
132  // Define vector containing index of hepmc corresponding to the reco::GenParticle
133  std::vector<int> hepmcMatchIndex;
134  hepmcMatchIndex.reserve(initSize);
135 
136  // Matching procedure
137 
138  // Check array size consistency
139 
140  if ( nReco != nHepMC ) {
141  edm::LogWarning("CollectionSizeInconsistency") << "Collection size inconsistency: HepMC::GenParticle = " << nHepMC << " reco::GenParticle = " << nReco;
142  }
143 
144  // Match each HepMC with a reco
145 
146  for ( unsigned int i = 0; i < nReco; ++i ){
147  for ( unsigned int j = 0; j < nHepMC; ++j ){
148  if ( matchParticles( hepmcGPCollection[j], particles[i] ) ) {
149  hepmcMatchIndex.push_back((int)j);
150  if ( hepmcGPCollection[j]->momentum().rho() != 0. ) {
151  double reso = 1.-particles[i]->p()/hepmcGPCollection[j]->momentum().rho();
152  if ( verbosity_ > 0 ) {
153  std::cout << "Matching momentum: reco = " << particles[i]->p() << " HepMC = "
154  << hepmcGPCollection[j]->momentum().rho() << " resoultion = " << reso << std::endl;
155  }
156  matchedResolution->Fill(std::log10(std::fabs(reso)),weight); }
157  continue;
158  }
159  }
160  }
161 
162  // Check unicity of matching
163 
164  unsigned int nMatched = hepmcMatchIndex.size();
165 
166  if ( nMatched != nReco ) {
167  edm::LogWarning("IncorrectMatching") << "Incorrect number of matched indexes: GenParticle = " << nReco << " matched indexes = " << nMatched;
168  }
169  genMatched->Fill(int(nReco-nMatched),weight);
170 
171  unsigned int nWrMatch = 0;
172 
173  for ( unsigned int i = 0; i < nMatched; ++i ){
174  for (unsigned int j = i+1; j < nMatched; ++j ){
175  if ( hepmcMatchIndex[i] == hepmcMatchIndex[j] ) {
176  int theIndex = hepmcMatchIndex[i];
177  edm::LogWarning("DuplicatedMatching") << "Multiple matching occurencies for GenParticle barcode = " << barcodeList[theIndex];
178  nWrMatch++;
179  }
180  }
181  }
182  multipleMatching->Fill(int(nWrMatch),weight);
183 
184  // Gather information in the GenJet collection
186  iEvent.getByLabel(genjetCollection_, genJets );
187 
188  int nJets = 0;
189  int nJetso1 = 0;
190  int nJetso10 = 0;
191  int nJetso100 = 0;
192  int nJetsCentral = 0;
193  double totPt = 0.;
194 
195  std::vector<double> jetEta;
196  jetEta.reserve(initSize);
197 
198  for (reco::GenJetCollection::const_iterator iter=genJets->begin();iter!=genJets->end();++iter){
199  nJets++;
200  double pt = (*iter).pt();
201  totPt += pt;
202  if (pt > 1.) nJetso1++;
203  if (pt > 10.) nJetso10++;
204  if (pt > 100.) nJetso100++;
205  double eta = (*iter).eta();
206  if ( std::fabs(eta) < 2.5 ) nJetsCentral++;
207  jetEta.push_back(eta);
208 
209  genJetEnergy->Fill(std::log10((*iter).energy()),weight);
210  genJetPt->Fill(std::log10(pt),weight);
211  genJetEta->Fill(eta,weight);
212  genJetPhi->Fill((*iter).phi()/CLHEP::degree,weight);
213  }
214 
215  genJetMult->Fill(nJets,weight);
216  genJetPto1->Fill(nJetso1,weight);
217  genJetPto10->Fill(nJetso10,weight);
218  genJetPto100->Fill(nJetso100,weight);
219  genJetCentral->Fill(nJetsCentral,weight);
220 
221  genJetTotPt->Fill(std::log10(totPt),weight);
222 
223  double deltaEta = 999.;
224  if ( jetEta.size() > 1 ) {
225  for (unsigned int i = 0; i < jetEta.size(); i++){
226  for (unsigned int j = i+1; j < jetEta.size(); j++){
227  deltaEta = std::min(deltaEta,std::fabs(jetEta[i]-jetEta[j]));
228  }
229  }
230  }
231 
232  genJetDeltaEtaMin->Fill(deltaEta,weight);
233 
234  delete myGenEvent;
235 }//analyze
int i
Definition: DBlmapReader.cc:9
Definition: DDAxes.h:10
#define min(a, b)
Definition: mlp_lapack.h:161
bool matchParticles(const HepMC::GenParticle *&, const reco::GenParticle *&)
T eta() const
void Fill(long long x)
int j
Definition: DBlmapReader.cc:9
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
tuple cout
Definition: gather_cfg.py:121
double weight(const edm::Event &)
void BasicGenParticleValidation::beginJob ( void  )
virtual

Setting the DQM top directories

Booking the ME's

multiplicity

Reimplemented from edm::EDAnalyzer.

Definition at line 30 of file BasicGenParticleValidation.cc.

References DQMStore::book1D(), dbe, genJetCentral, genJetDeltaEtaMin, genJetEnergy, genJetEta, genJetMult, genJetPhi, genJetPt, genJetPto1, genJetPto10, genJetPto100, genJetTotPt, genMatched, genPMultiplicity, matchedResolution, multipleMatching, nEvt, and DQMStore::setCurrentFolder().

31 {
32  if(dbe){
34  dbe->setCurrentFolder("Generator/GenParticles");
35 
37 
38  // Number of analyzed events
39  nEvt = dbe->book1D("nEvt", "n analyzed Events", 1, 0., 1.);
40 
42  genPMultiplicity = dbe->book1D("genPMultiplicty", "Log(No. all GenParticles)", 50, -1, 5); //Log
43  //difference in HepMC and reco multiplicity
44  genMatched = dbe->book1D("genMatched", "Difference reco - matched", 50, -25, 25);
45  //multiple matching
46  multipleMatching = dbe->book1D("multipleMatching", "multiple reco HepMC matching", 50, 0, 50);
47  //momentum difference of matched particles
48  matchedResolution = dbe->book1D("matchedResolution", "log10(momentum difference of matched particles)", 70, -10., -3.);
49 
50  // GenJet general distributions
51  genJetMult = dbe->book1D("genJetMult", "GenJet multiplicity", 50, 0, 50);
52  genJetEnergy = dbe->book1D("genJetEnergy", "Log10(GenJet energy)", 60, -1, 5);
53  genJetPt = dbe->book1D("genJetPt", "Log10(GenJet pt)", 60, -1, 5);
54  genJetEta = dbe->book1D("genJetEta", "GenJet eta", 220, -11, 11);
55  genJetPhi = dbe->book1D("genJetPhi", "GenJet phi", 360, -180, 180);
56  genJetDeltaEtaMin = dbe->book1D("genJetDeltaEtaMin", "GenJet minimum rapidity gap", 30, 0, 30);
57 
58  genJetPto1 = dbe->book1D("genJetPto1", "GenJet multiplicity above 1 GeV", 50, 0, 50);
59  genJetPto10 = dbe->book1D("genJetPto10", "GenJet multiplicity above 10 GeV", 50, 0, 50);
60  genJetPto100 = dbe->book1D("genJetPto100", "GenJet multiplicity above 100 GeV", 50, 0, 50);
61  genJetCentral = dbe->book1D("genJetCentral", "GenJet multiplicity |eta|.lt.2.5", 50, 0, 50);
62 
63  genJetTotPt = dbe->book1D("genJetTotPt", "Log10(GenJet total pt)", 100, -5, 5);
64 
65  }
66  return;
67 }
DQMStore * dbe
ME&#39;s &quot;container&quot;.
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:717
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429
void BasicGenParticleValidation::beginRun ( const edm::Run iRun,
const edm::EventSetup iSetup 
)
virtual

Get PDT Table

Reimplemented from edm::EDAnalyzer.

Definition at line 70 of file BasicGenParticleValidation.cc.

References fPDGTable, and edm::EventSetup::getData().

71 {
73  iSetup.getData( fPDGTable );
74  return;
75 }
edm::ESHandle< HepPDT::ParticleDataTable > fPDGTable
PDT table.
void getData(T &iHolder) const
Definition: EventSetup.h:67
void BasicGenParticleValidation::endJob ( void  )
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 69 of file BasicGenParticleValidation.cc.

69 {return;}
void BasicGenParticleValidation::endRun ( const edm::Run iRun,
const edm::EventSetup iSetup 
)
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 76 of file BasicGenParticleValidation.cc.

76 {return;}
bool BasicGenParticleValidation::matchParticles ( const HepMC::GenParticle *&  hepmcP,
const reco::GenParticle *&  recoP 
)

Definition at line 237 of file BasicGenParticleValidation.cc.

References matchPr_, reco::LeafCandidate::pdgId(), reco::LeafCandidate::px(), reco::LeafCandidate::py(), reco::LeafCandidate::pz(), and evf::utils::state.

Referenced by analyze().

237  {
238 
239  bool state = false;
240 
241  if ( hepmcP->pdg_id() != recoP->pdgId() ) return state;
242  if ( std::fabs(hepmcP->momentum().px()-recoP->px()) < std::fabs(matchPr_*hepmcP->momentum().px()) &&
243  std::fabs(hepmcP->momentum().py()-recoP->py()) < std::fabs(matchPr_*hepmcP->momentum().py()) &&
244  std::fabs(hepmcP->momentum().pz()-recoP->pz()) < std::fabs(matchPr_*hepmcP->momentum().pz())) {
245  state = true; }
246 
247  return state;
248 
249 }
virtual int pdgId() const
PDG identifier.
virtual double px() const
x coordinate of momentum vector
virtual double pz() const
z coordinate of momentum vector
char state
Definition: procUtils.cc:75
virtual double py() const
y coordinate of momentum vector

Member Data Documentation

WeightManager BasicGenParticleValidation::_wmanager
private

Definition at line 54 of file BasicGenParticleValidation.h.

Referenced by analyze().

DQMStore* BasicGenParticleValidation::dbe
private

ME's "container".

Definition at line 67 of file BasicGenParticleValidation.h.

Referenced by BasicGenParticleValidation(), and beginJob().

edm::ESHandle<HepPDT::ParticleDataTable> BasicGenParticleValidation::fPDGTable
private

PDT table.

Definition at line 64 of file BasicGenParticleValidation.h.

Referenced by beginRun().

MonitorElement* BasicGenParticleValidation::genJetCentral
private

Definition at line 90 of file BasicGenParticleValidation.h.

Referenced by analyze(), and beginJob().

edm::InputTag BasicGenParticleValidation::genjetCollection_
private

Definition at line 58 of file BasicGenParticleValidation.h.

Referenced by analyze().

MonitorElement* BasicGenParticleValidation::genJetDeltaEtaMin
private

Definition at line 85 of file BasicGenParticleValidation.h.

Referenced by analyze(), and beginJob().

MonitorElement* BasicGenParticleValidation::genJetEnergy
private

Definition at line 81 of file BasicGenParticleValidation.h.

Referenced by analyze(), and beginJob().

MonitorElement* BasicGenParticleValidation::genJetEta
private

Definition at line 83 of file BasicGenParticleValidation.h.

Referenced by analyze(), and beginJob().

MonitorElement* BasicGenParticleValidation::genJetMult
private

Definition at line 80 of file BasicGenParticleValidation.h.

Referenced by analyze(), and beginJob().

MonitorElement* BasicGenParticleValidation::genJetPhi
private

Definition at line 84 of file BasicGenParticleValidation.h.

Referenced by analyze(), and beginJob().

MonitorElement* BasicGenParticleValidation::genJetPt
private

Definition at line 82 of file BasicGenParticleValidation.h.

Referenced by analyze(), and beginJob().

MonitorElement* BasicGenParticleValidation::genJetPto1
private

Definition at line 87 of file BasicGenParticleValidation.h.

Referenced by analyze(), and beginJob().

MonitorElement* BasicGenParticleValidation::genJetPto10
private

Definition at line 88 of file BasicGenParticleValidation.h.

Referenced by analyze(), and beginJob().

MonitorElement* BasicGenParticleValidation::genJetPto100
private

Definition at line 89 of file BasicGenParticleValidation.h.

Referenced by analyze(), and beginJob().

MonitorElement* BasicGenParticleValidation::genJetTotPt
private

Definition at line 92 of file BasicGenParticleValidation.h.

Referenced by analyze(), and beginJob().

MonitorElement* BasicGenParticleValidation::genMatched
private

Definition at line 74 of file BasicGenParticleValidation.h.

Referenced by analyze(), and beginJob().

edm::InputTag BasicGenParticleValidation::genparticleCollection_
private

Definition at line 57 of file BasicGenParticleValidation.h.

Referenced by analyze().

MonitorElement* BasicGenParticleValidation::genPMultiplicity
private

Definition at line 73 of file BasicGenParticleValidation.h.

Referenced by analyze(), and beginJob().

edm::InputTag BasicGenParticleValidation::hepmcCollection_
private

Definition at line 56 of file BasicGenParticleValidation.h.

Referenced by analyze().

MonitorElement* BasicGenParticleValidation::matchedResolution
private

Definition at line 76 of file BasicGenParticleValidation.h.

Referenced by analyze(), and beginJob().

double BasicGenParticleValidation::matchPr_
private

Definition at line 59 of file BasicGenParticleValidation.h.

Referenced by matchParticles().

MonitorElement* BasicGenParticleValidation::multipleMatching
private

Definition at line 75 of file BasicGenParticleValidation.h.

Referenced by analyze(), and beginJob().

MonitorElement* BasicGenParticleValidation::nEvt
private

Definition at line 69 of file BasicGenParticleValidation.h.

Referenced by analyze(), and beginJob().

unsigned int BasicGenParticleValidation::verbosity_
private

Definition at line 61 of file BasicGenParticleValidation.h.

Referenced by analyze().