CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MixedGenMEtProducer.cc
Go to the documentation of this file.
2 
4 
12 
14 {
15  srcGenParticles1_ = cfg.getParameter<edm::InputTag>("srcGenParticles1");
16  srcGenParticles2_ = cfg.getParameter<edm::InputTag>("srcGenParticles2");
17 
18  srcRemovedMuons_ = cfg.getParameter<edm::InputTag>("srcRemovedMuons");
19 
20  std::string type_string = cfg.getParameter<std::string>("type");
21  if ( type_string == "pf" ) type_ = kPF;
22  else if ( type_string == "calo" ) type_ = kCalo;
23  else throw cms::Exception("Configuration")
24  << "Invalid Configuration Parameter 'type' = " << type_string << " !!\n";
25 
26  isMC_ = cfg.getParameter<bool>("isMC");
27  int numCollections = 0;
28  if ( srcGenParticles1_.label() != "" ) ++numCollections;
29  if ( srcGenParticles2_.label() != "" ) ++numCollections;
30  if ( numCollections != 2 && isMC_ )
31  throw cms::Exception("Configuration")
32  << "Collections 'srcGenParticles1' and 'srcGenParticles2' must both be specified in case Embedding is run on Monte Carlo !!\n";
33  if ( numCollections != 1 && !isMC_ )
34  throw cms::Exception("Configuration")
35  << "Either collection 'srcGenParticles1' or 'srcGenParticles2' must be specified in case Embedding is run on Data !!\n";
36 
37  produces<reco::GenMETCollection>();
38 }
39 
40 namespace
41 {
42  void sumNeutrinoP4s(const reco::GenParticleCollection& genParticles, bool isCaloMEt, reco::Candidate::LorentzVector& sumNeutrinoP4, double& sumEt)
43  {
44  int idx = 0;
45  for ( reco::GenParticleCollection::const_iterator genParticle = genParticles.begin();
46  genParticle != genParticles.end(); ++genParticle ) {
47  if ( genParticle->status() == 1 ) {
48  int absPdgId = TMath::Abs(genParticle->pdgId());
49  if ( absPdgId == 12 || absPdgId == 14 || absPdgId == 16 ) sumNeutrinoP4 += genParticle->p4();
50  else if ( isCaloMEt && absPdgId == 13 ) sumNeutrinoP4 += genParticle->p4();
51  else sumEt += genParticle->et();
52  }
53  ++idx;
54  }
55  }
56 }
57 
59 {
61  double genSumEt = 0.;
62 
63  if ( srcGenParticles1_.label() != "" ) {
65  evt.getByLabel(srcGenParticles1_, genParticles1);
66  sumNeutrinoP4s(*genParticles1, type_ == kCalo, genMEtP4, genSumEt);
67  }
68  if ( srcGenParticles2_.label() != "" ) {
70  evt.getByLabel(srcGenParticles2_, genParticles2);
71  sumNeutrinoP4s(*genParticles2, type_ == kCalo, genMEtP4, genSumEt);
72  }
73 
74  if ( isMC_ ) {
76  edm::Handle<CandidateView> removedMuons;
77  evt.getByLabel(srcRemovedMuons_, removedMuons);
78  for ( CandidateView::const_iterator removedMuon = removedMuons->begin();
79  removedMuon != removedMuons->end(); ++removedMuon ) {
80  if ( type_ == kCalo ) genMEtP4 -= removedMuon->p4();
81  genSumEt -= removedMuon->et();
82  }
83  }
84 
85  std::auto_ptr<reco::GenMETCollection> genMETs(new reco::GenMETCollection());
86  SpecificGenMETData genMEtData; // WARNING: not filled
87  genMEtData.NeutralEMEtFraction = 0.;
88  genMEtData.NeutralHadEtFraction = 0.;
89  genMEtData.ChargedEMEtFraction = 0.;
90  genMEtData.ChargedHadEtFraction = 0.;
91  genMEtData.MuonEtFraction = 0.;
92  genMEtData.InvisibleEtFraction = 0.;
93  reco::Candidate::Point vtx(0.0, 0.0, 0.0);
94  genMETs->push_back(reco::GenMET(genMEtData, genSumEt, genMEtP4, vtx));
95 
96  evt.put(genMETs);
97 }
98 
100 
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
T getParameter(std::string const &) const
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
edm::InputTag srcRemovedMuons_
std::vector< reco::GenMET > GenMETCollection
collection of GenMET objects
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void produce(edm::Event &, const edm::EventSetup &)
edm::View< reco::Candidate > CandidateView
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
edm::InputTag srcGenParticles2_
MixedGenMEtProducer(const edm::ParameterSet &)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:41
std::string const & label() const
Definition: InputTag.h:42
math::XYZPoint Point
point in the space
Definition: Candidate.h:45
edm::InputTag srcGenParticles1_