CMS 3D CMS Logo

Type0PFMETcorrInputProducer.cc
Go to the documentation of this file.
2 
10 
11 #include <TMath.h>
12 
14  : moduleLabel_(cfg.getParameter<std::string>("@module_label")),
15  correction_(nullptr)
16 {
17  pfCandidateToVertexAssociationsToken_ = consumes<PFCandToVertexAssMap>(cfg.getParameter<edm::InputTag>("srcPFCandidateToVertexAssociations"));
18  hardScatterVertexToken_ = consumes<reco::VertexCollection>(cfg.getParameter<edm::InputTag>("srcHardScatterVertex"));
19 
20  edm::ParameterSet cfgCorrection_function = cfg.getParameter<edm::ParameterSet>("correction");
21  std::string corrFunctionName = std::string(moduleLabel_).append("correction");
22  std::string corrFunctionFormula = cfgCorrection_function.getParameter<std::string>("formula");
23  correction_ = new TFormula(corrFunctionName.data(), corrFunctionFormula.data());
24  int numParameter = correction_->GetNpar();
25  for ( int iParameter = 0; iParameter < numParameter; ++iParameter ) {
26  std::string parName = Form("par%i", iParameter);
27  double parValue = cfgCorrection_function.getParameter<double>(parName);
28  correction_->SetParameter(iParameter, parValue);
29  }
30 
31  minDz_ = cfg.getParameter<double>("minDz");
32 
33  produces<CorrMETData>();
34 }
35 
37 {
38  delete correction_;
39 }
40 
42 {
43  edm::Handle<reco::VertexCollection> hardScatterVertex;
44  evt.getByToken(hardScatterVertexToken_, hardScatterVertex);
45 
46  edm::Handle<PFCandToVertexAssMap> pfCandidateToVertexAssociations;
47  evt.getByToken(pfCandidateToVertexAssociationsToken_, pfCandidateToVertexAssociations);
48 
49  std::unique_ptr<CorrMETData> pfMEtCorrection(new CorrMETData());
50 
51  for ( PFCandToVertexAssMap::const_iterator pfCandidateToVertexAssociation = pfCandidateToVertexAssociations->begin();
52  pfCandidateToVertexAssociation != pfCandidateToVertexAssociations->end(); ++pfCandidateToVertexAssociation ) {
53  reco::VertexRef vertex = pfCandidateToVertexAssociation->key;
54  const PFCandQualityPairVector& pfCandidates_vertex = pfCandidateToVertexAssociation->val;
55 
56  bool isHardScatterVertex = false;
57  for ( reco::VertexCollection::const_iterator hardScatterVertex_i = hardScatterVertex->begin();
58  hardScatterVertex_i != hardScatterVertex->end(); ++hardScatterVertex_i ) {
59  if ( TMath::Abs(vertex->position().z() - hardScatterVertex_i->position().z()) < minDz_ ) {
60  isHardScatterVertex = true;
61  break;
62  }
63  }
64 
65  if ( !isHardScatterVertex ) {
66  reco::Candidate::LorentzVector sumChargedPFCandP4_vertex;
67  for ( PFCandQualityPairVector::const_iterator pfCandidate_vertex = pfCandidates_vertex.begin();
68  pfCandidate_vertex != pfCandidates_vertex.end(); ++pfCandidate_vertex ) {
69  const reco::PFCandidate& pfCandidate = (*pfCandidate_vertex->first);
70  if ( pfCandidate.particleId() == reco::PFCandidate::h ||
71  pfCandidate.particleId() == reco::PFCandidate::e ||
72  pfCandidate.particleId() == reco::PFCandidate::mu ) {
73  sumChargedPFCandP4_vertex += pfCandidate.p4();
74  }
75  }
76 
77  double pt = sumChargedPFCandP4_vertex.pt();
78  double phi = sumChargedPFCandP4_vertex.phi();
79  double ptCorr = correction_->Eval(pt);
80  double pxCorr = TMath::Cos(phi)*ptCorr;
81  double pyCorr = TMath::Sin(phi)*ptCorr;
82 
83  pfMEtCorrection->mex += pxCorr;
84  pfMEtCorrection->mey += pyCorr;
85  }
86  }
87 
88  evt.put(std::move(pfMEtCorrection));
89 }
90 
92 
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
const_iterator end() const
last iterator over the map (read only)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
void produce(edm::Event &, const edm::EventSetup &) override
#define nullptr
key_type key() const
Accessor for product key.
Definition: Ref.h:263
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
T Abs(T a)
Definition: MathUtil.h:49
edm::EDGetTokenT< PFCandToVertexAssMap > pfCandidateToVertexAssociationsToken_
std::vector< PFCandQualityPair > PFCandQualityPairVector
const LorentzVector & p4() const final
four-momentum Lorentz vector
Definition: LeafCandidate.h:99
edm::EDGetTokenT< reco::VertexCollection > hardScatterVertexToken_
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
a MET correction term
Definition: CorrMETData.h:14
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
const_iterator begin() const
first iterator over the map (read only)
virtual ParticleType particleId() const
Definition: PFCandidate.h:374
def move(src, dest)
Definition: eostools.py:511
Type0PFMETcorrInputProducer(const edm::ParameterSet &)