CMS 3D CMS Logo

PATMETProducer.cc
Go to the documentation of this file.
1 //
2 //
3 
8 
11 
12 #include <memory>
13 
14 using namespace pat;
15 
16 PATMETProducer::PATMETProducer(const edm::ParameterSet& iConfig) : useUserData_(iConfig.exists("userData")) {
17  // initialize the configurables
18  metSrc_ = iConfig.getParameter<edm::InputTag>("metSource");
19  metToken_ = consumes<edm::View<reco::MET> >(metSrc_);
20  addGenMET_ = iConfig.getParameter<bool>("addGenMET");
21  genMETToken_ = mayConsume<edm::View<reco::GenMET> >(iConfig.getParameter<edm::InputTag>("genMETSource"));
22  addResolutions_ = iConfig.getParameter<bool>("addResolutions");
23 
24  // Efficiency configurables
25  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
26  if (addEfficiencies_) {
28  pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"), consumesCollector());
29  }
30 
31  // Resolution configurables
32  addResolutions_ = iConfig.getParameter<bool>("addResolutions");
33  if (addResolutions_) {
35  }
36 
37  // Check to see if the user wants to add user data
38  if (useUserData_) {
39  userDataHelper_ = PATUserDataHelper<MET>(iConfig.getParameter<edm::ParameterSet>("userData"), consumesCollector());
40  }
41 
42  // MET Significance
43  calculateMETSignificance_ = iConfig.getParameter<bool>("computeMETSignificance");
44  if (calculateMETSignificance_) {
45  metSigAlgo_ = new metsig::METSignificance(iConfig);
46  rhoToken_ = consumes<double>(iConfig.getParameter<edm::InputTag>("srcRho"));
47  jetSFType_ = iConfig.getParameter<std::string>("srcJetSF");
48  jetResPtType_ = iConfig.getParameter<std::string>("srcJetResPt");
49  jetResPhiType_ = iConfig.getParameter<std::string>("srcJetResPhi");
50  jetToken_ = consumes<edm::View<reco::Jet> >(iConfig.getParameter<edm::InputTag>("srcJets"));
51  pfCandToken_ = consumes<edm::View<reco::Candidate> >(iConfig.getParameter<edm::InputTag>("srcPFCands"));
52  std::vector<edm::InputTag> srcLeptonsTags = iConfig.getParameter<std::vector<edm::InputTag> >("srcLeptons");
53  for (std::vector<edm::InputTag>::const_iterator it = srcLeptonsTags.begin(); it != srcLeptonsTags.end(); it++) {
54  lepTokens_.push_back(consumes<edm::View<reco::Candidate> >(*it));
55  }
56  }
57 
58  // produces vector of mets
59  produces<std::vector<MET> >();
60 }
61 
63 
65  // Get the vector of MET's from the event
67  iEvent.getByToken(metToken_, mets);
68 
69  if (mets->size() != 1)
70  throw cms::Exception("Corrupt Data") << "The input MET collection " << metSrc_.encode() << " has size "
71  << mets->size() << " instead of 1 as it should.\n";
75  resolutionLoader_.newEvent(iEvent, iSetup);
76 
77  // Get the vector of generated met from the event if needed
79  if (addGenMET_) {
80  iEvent.getByToken(genMETToken_, genMETs);
81  }
82 
83  // loop over mets
84  std::vector<MET>* patMETs = new std::vector<MET>();
85  for (edm::View<reco::MET>::const_iterator itMET = mets->begin(); itMET != mets->end(); itMET++) {
86  // construct the MET from the ref -> save ref to original object
87  unsigned int idx = itMET - mets->begin();
88  edm::RefToBase<reco::MET> metsRef = mets->refAt(idx);
89  edm::Ptr<reco::MET> metsPtr = mets->ptrAt(idx);
90  MET amet(metsRef);
91  // add the generated MET
92  if (addGenMET_)
93  amet.setGenMET((*genMETs)[idx]);
94 
95  //add the MET significance
97  double sumPtUnclustered = 0;
98  const reco::METCovMatrix& sigcov = getMETCovMatrix(iEvent, iSetup, sumPtUnclustered);
99  amet.setSignificanceMatrix(sigcov);
100  double metSig = metSigAlgo_->getSignificance(sigcov, amet);
101  amet.setMETSignificance(metSig);
102  amet.setMETSumPtUnclustered(sumPtUnclustered);
103  }
104 
105  if (efficiencyLoader_.enabled()) {
106  efficiencyLoader_.setEfficiencies(amet, metsRef);
107  }
108 
109  if (resolutionLoader_.enabled()) {
111  }
112 
113  if (useUserData_) {
114  userDataHelper_.add(amet, iEvent, iSetup);
115  }
116 
117  // correct for muons if demanded... never more: it's now done by JetMETCorrections
118  // add the MET to the vector of METs
119  patMETs->push_back(amet);
120  }
121 
122  // sort MET in ET .. don't mess with this
123  // std::sort(patMETs->begin(), patMETs->end(), eTComparator_);
124 
125  // put genEvt object in Event
126  std::unique_ptr<std::vector<MET> > myMETs(patMETs);
127  iEvent.put(std::move(myMETs));
128 }
129 
130 // ParameterSet description for module
133  iDesc.setComment("PAT MET producer module");
134 
135  // input source
136  iDesc.add<edm::InputTag>("metSource", edm::InputTag("no default"))->setComment("input collection");
137 
138  // MC configurations
139  iDesc.add<bool>("addGenMET", false);
140  iDesc.add<edm::InputTag>("genMETSource", edm::InputTag("genMetCalo"));
141 
143 
144  // Efficiency configurables
145  edm::ParameterSetDescription efficienciesPSet;
146  efficienciesPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
147  iDesc.add("efficiencies", efficienciesPSet);
148  iDesc.add<bool>("addEfficiencies", false);
149 
150  // Check to see if the user wants to add user data
151  edm::ParameterSetDescription userDataPSet;
153  iDesc.addOptional("userData", userDataPSet);
154 
155  // muon correction
156  iDesc.add<bool>("addMuonCorrections", false);
157  iDesc.add<edm::InputTag>("muonSource", edm::InputTag("muons"));
158 }
159 
161  const edm::EventSetup& iSetup,
162  double& sumPtUnclustered) const {
163  std::vector<edm::Handle<reco::CandidateView> > leptons;
164  for (std::vector<edm::EDGetTokenT<edm::View<reco::Candidate> > >::const_iterator srcLeptons_i = lepTokens_.begin();
165  srcLeptons_i != lepTokens_.end();
166  ++srcLeptons_i) {
168  event.getByToken(*srcLeptons_i, leptons_i);
169  leptons.push_back(leptons_i);
170  }
171  // jets
173  event.getByToken(jetToken_, inputJets);
174 
175  //candidates
177  event.getByToken(pfCandToken_, inputCands);
178 
180  event.getByToken(rhoToken_, rho);
181 
185 
186  //Compute the covariance matrix and fill it
188  *inputJets, leptons, inputCands, *rho, resPtObj, resPhiObj, resSFObj, event.isRealData(), sumPtUnclustered);
189 
190  return cov;
191 }
192 
194 
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
Analysis-level MET class.
Definition: MET.h:40
T getParameter(std::string const &) const
Assists in assimilating all pat::UserData into pat objects.
void newEvent(const edm::Event &event)
To be called for each new event, reads in the ValueMaps for efficiencies.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
metsig::METSignificance * metSigAlgo_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
Produces the pat::MET.
static double getSignificance(const reco::METCovMatrix &cov, const reco::MET &met)
static const JetResolution get(const edm::EventSetup &, const std::string &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
void setAllowAnything()
allow any parameter label/value pairs
pat::PATUserDataHelper< pat::MET > userDataHelper_
const reco::METCovMatrix getMETCovMatrix(const edm::Event &event, const edm::EventSetup &iSetup, double &sumPtUnclustered) const
ROOT::Math::SMatrix< double, 2 > METCovMatrix
Definition: MET.h:39
void setSignificanceMatrix(const reco::METCovMatrix &matrix)
Definition: MET.cc:137
std::vector< edm::EDGetTokenT< edm::View< reco::Candidate > > > lepTokens_
std::string jetResPtType_
std::string jetSFType_
void setResolutions(pat::PATObject< T > &obj) const
Sets the efficiencies for this object, using the reference to the original objects.
edm::InputTag metSrc_
bool isRealData() const
Definition: EventBase.h:62
edm::EDGetTokenT< edm::View< reco::Candidate > > pfCandToken_
std::string encode() const
Definition: InputTag.cc:159
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
Definition: HeavyIon.h:7
static void fillDescription(edm::ParameterSetDescription &iDesc)
void setComment(std::string const &value)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< double > rhoToken_
edm::EDGetTokenT< edm::View< reco::Jet > > jetToken_
void newEvent(const edm::Event &event, const edm::EventSetup &setup)
To be called for each new event, reads in the EventSetup object.
edm::EDGetTokenT< edm::View< reco::MET > > metToken_
pat::helper::EfficiencyLoader efficiencyLoader_
reco::METCovMatrix getCovariance(const edm::View< reco::Jet > &jets, const std::vector< edm::Handle< reco::CandidateView > > &leptons, const edm::Handle< edm::View< reco::Candidate > > &pfCandidates, double rho, JME::JetResolution &resPtObj, JME::JetResolution &resPhiObj, JME::JetResolutionScaleFactor &resSFObj, bool isRealData, double &sumPtUnclustered)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void setMETSumPtUnclustered(const double &sumPtUnclustered)
Definition: MET.cc:128
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
pat::helper::KinResolutionsLoader resolutionLoader_
edm::EDGetTokenT< edm::View< reco::GenMET > > genMETToken_
METSignificance
____________________________________________________________________________||
static void fillDescription(edm::ParameterSetDescription &iDesc)
Method for documentation and validation of PSet.
std::string jetResPhiType_
void setEfficiencies(pat::PATObject< T > &obj, const R &originalRef) const
Sets the efficiencies for this object, using the reference to the original objects.
static const JetResolutionScaleFactor get(const edm::EventSetup &, const std::string &)
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
void setGenMET(const reco::GenMET &gm)
set the associated GenMET
Definition: MET.cc:118
PATMETProducer(const edm::ParameterSet &iConfig)
void setMETSignificance(const double &metSig)
Definition: MET.cc:124
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
~PATMETProducer() override