CMS 3D CMS Logo

PATMETProducer.cc
Go to the documentation of this file.
1 
28 
29 #include <memory>
30 
31 namespace pat {
32 
34  public:
35  explicit PATMETProducer(const edm::ParameterSet& iConfig);
36  ~PATMETProducer() override;
37 
38  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
39 
40  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
41 
42  private:
43  // configurables
46  bool addGenMET_;
52  // tools
54 
57 
60 
61  //MET Significance
66  std::vector<edm::EDGetTokenT<edm::View<reco::Candidate>>> lepTokens_;
72 
74  const edm::EventSetup& iSetup,
75  const reco::MET& met,
76  double& sumPtUnclustered) const;
77  };
78 
79 } // namespace pat
80 
81 using namespace pat;
82 
83 PATMETProducer::PATMETProducer(const edm::ParameterSet& iConfig) : useUserData_(iConfig.exists("userData")) {
84  // initialize the configurables
85  metSrc_ = iConfig.getParameter<edm::InputTag>("metSource");
86  metToken_ = consumes<edm::View<reco::MET>>(metSrc_);
87  addGenMET_ = iConfig.getParameter<bool>("addGenMET");
88  genMETToken_ = mayConsume<edm::View<reco::GenMET>>(iConfig.getParameter<edm::InputTag>("genMETSource"));
89  addResolutions_ = iConfig.getParameter<bool>("addResolutions");
90 
91  // Efficiency configurables
92  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
93  if (addEfficiencies_) {
95  pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"), consumesCollector());
96  }
97 
98  // Resolution configurables
99  addResolutions_ = iConfig.getParameter<bool>("addResolutions");
100  if (addResolutions_) {
102  }
103 
104  // Check to see if the user wants to add user data
105  if (useUserData_) {
106  userDataHelper_ = PATUserDataHelper<MET>(iConfig.getParameter<edm::ParameterSet>("userData"), consumesCollector());
107  }
108 
109  // MET Significance
110  calculateMETSignificance_ = iConfig.getParameter<bool>("computeMETSignificance");
112  edm::InputTag srcWeights = iConfig.getParameter<edm::InputTag>("srcWeights");
113  if (!srcWeights.label().empty())
115  metSigAlgo_ = new metsig::METSignificance(iConfig);
116  rhoToken_ = consumes<double>(iConfig.getParameter<edm::InputTag>("srcRho"));
117  jetSFType_ = iConfig.getParameter<std::string>("srcJetSF");
118  jetResPtType_ = iConfig.getParameter<std::string>("srcJetResPt");
119  jetResPhiType_ = iConfig.getParameter<std::string>("srcJetResPhi");
120  jetToken_ = consumes<edm::View<reco::Jet>>(iConfig.getParameter<edm::InputTag>("srcJets"));
121  pfCandToken_ = consumes<edm::View<reco::Candidate>>(iConfig.getParameter<edm::InputTag>("srcPFCands"));
122  std::vector<edm::InputTag> srcLeptonsTags = iConfig.getParameter<std::vector<edm::InputTag>>("srcLeptons");
123  for (std::vector<edm::InputTag>::const_iterator it = srcLeptonsTags.begin(); it != srcLeptonsTags.end(); it++) {
124  lepTokens_.push_back(consumes<edm::View<reco::Candidate>>(*it));
125  }
126  }
127 
128  // produces vector of mets
129  produces<std::vector<MET>>();
130 }
131 
133 
135  // Get the vector of MET's from the event
137  iEvent.getByToken(metToken_, mets);
138 
139  if (mets->size() != 1)
140  throw cms::Exception("Corrupt Data") << "The input MET collection " << metSrc_.encode() << " has size "
141  << mets->size() << " instead of 1 as it should.\n";
146 
147  // Get the vector of generated met from the event if needed
149  if (addGenMET_) {
150  iEvent.getByToken(genMETToken_, genMETs);
151  }
152 
153  // loop over mets
154  std::vector<MET>* patMETs = new std::vector<MET>();
155  for (edm::View<reco::MET>::const_iterator itMET = mets->begin(); itMET != mets->end(); itMET++) {
156  // construct the MET from the ref -> save ref to original object
157  unsigned int idx = itMET - mets->begin();
158  edm::RefToBase<reco::MET> metsRef = mets->refAt(idx);
159  edm::Ptr<reco::MET> metsPtr = mets->ptrAt(idx);
160  MET amet(metsRef);
161  // add the generated MET
162  if (addGenMET_)
163  amet.setGenMET((*genMETs)[idx]);
164 
165  //add the MET significance
167  double sumPtUnclustered = 0;
168  const reco::METCovMatrix& sigcov = getMETCovMatrix(iEvent, iSetup, amet, sumPtUnclustered);
169  amet.setSignificanceMatrix(sigcov);
170  double metSig = metSigAlgo_->getSignificance(sigcov, amet);
171  amet.setMETSignificance(metSig);
173  }
174 
175  if (efficiencyLoader_.enabled()) {
176  efficiencyLoader_.setEfficiencies(amet, metsRef);
177  }
178 
179  if (resolutionLoader_.enabled()) {
181  }
182 
183  if (useUserData_) {
184  userDataHelper_.add(amet, iEvent, iSetup);
185  }
186 
187  // correct for muons if demanded... never more: it's now done by JetMETCorrections
188  // add the MET to the vector of METs
189  patMETs->push_back(amet);
190  }
191 
192  // sort MET in ET .. don't mess with this
193  // std::sort(patMETs->begin(), patMETs->end(), eTComparator_);
194 
195  // put genEvt object in Event
196  std::unique_ptr<std::vector<MET>> myMETs(patMETs);
197  iEvent.put(std::move(myMETs));
198 }
199 
200 // ParameterSet description for module
203  iDesc.setComment("PAT MET producer module");
204 
205  // input source
206  iDesc.add<edm::InputTag>("metSource", edm::InputTag("no default"))->setComment("input collection");
207 
208  // MC configurations
209  iDesc.add<bool>("addGenMET", false);
210  iDesc.add<edm::InputTag>("genMETSource", edm::InputTag("genMetCalo"));
211 
213 
214  // Efficiency configurables
215  edm::ParameterSetDescription efficienciesPSet;
216  efficienciesPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
217  iDesc.add("efficiencies", efficienciesPSet);
218  iDesc.add<bool>("addEfficiencies", false);
219 
220  // Check to see if the user wants to add user data
221  edm::ParameterSetDescription userDataPSet;
223  iDesc.addOptional("userData", userDataPSet);
224 
225  // muon correction
226  iDesc.add<bool>("addMuonCorrections", false);
227  iDesc.add<edm::InputTag>("muonSource", edm::InputTag("muons"));
228 }
229 
231  const edm::EventSetup& iSetup,
232  const reco::MET& met,
233  double& sumPtUnclustered) const {
234  std::vector<edm::Handle<reco::CandidateView>> leptons;
235  for (std::vector<edm::EDGetTokenT<edm::View<reco::Candidate>>>::const_iterator srcLeptons_i = lepTokens_.begin();
236  srcLeptons_i != lepTokens_.end();
237  ++srcLeptons_i) {
239  event.getByToken(*srcLeptons_i, leptons_i);
240  leptons.push_back(leptons_i);
241  }
242  // jets
244  event.getByToken(jetToken_, inputJets);
245 
246  //candidates
248  event.getByToken(pfCandToken_, inputCands);
249 
251  event.getByToken(rhoToken_, rho);
252 
255  event.getByToken(weightsToken_, weights);
256 
260 
261  //Compute the covariance matrix and fill it
262  const edm::ValueMap<float>* weightsPtr = nullptr;
263  if (met.isWeighted()) {
265  throw cms::Exception("InvalidInput") << "MET is weighted (e.g. PUPPI), but no weights given in PATMETProducer\n";
266  weightsPtr = &*weights;
267  }
269  leptons,
270  inputCands,
271  *rho,
272  resPtObj,
273  resPhiObj,
274  resSFObj,
275  event.isRealData(),
277  weightsPtr);
278 
279  return cov;
280 }
281 
ConfigurationDescriptions.h
met_cff.sumPtUnclustered
sumPtUnclustered
Definition: met_cff.py:19
JME::JetResolution
Definition: JetResolution.h:17
pat::PATMETProducer::jetSFType_
std::string jetSFType_
Definition: PATMETProducer.cc:70
pat::PATUserDataHelper< pat::MET >
metProducer_cfi.patMETs
patMETs
Definition: metProducer_cfi.py:6
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
MessageLogger.h
pat::MET::setMETSignificance
void setMETSignificance(const double &metSig)
Definition: MET.cc:124
HLT_FULL_cff.inputJets
inputJets
Definition: HLT_FULL_cff.py:98489
pat::PATMETProducer::eTComparator_
GreaterByEt< MET > eTComparator_
Definition: PATMETProducer.cc:53
pat::PATMETProducer::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: PATMETProducer.cc:134
HLT_FULL_cff.leptons
leptons
Definition: HLT_FULL_cff.py:26294
pat::helper::EfficiencyLoader
Definition: EfficiencyLoader.h:16
pat::PATMETProducer::genMETToken_
edm::EDGetTokenT< edm::View< reco::GenMET > > genMETToken_
Definition: PATMETProducer.cc:47
pat::PATMETProducer
Produces the pat::MET.
Definition: PATMETProducer.cc:33
pat::PATMETProducer::muonSrc_
edm::InputTag muonSrc_
Definition: PATMETProducer.cc:51
edm::EDGetTokenT
Definition: EDGetToken.h:33
pat::PATUserDataHelper::fillDescription
static void fillDescription(edm::ParameterSetDescription &iDesc)
Definition: PATUserDataHelper.h:135
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
pat::helper::EfficiencyLoader::enabled
bool enabled() const
'true' if this there is at least one efficiency configured
Definition: EfficiencyLoader.h:25
edm::EDGetTokenT::isUninitialized
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:99
EDProducer.h
singleTopDQM_cfi.mets
mets
Definition: singleTopDQM_cfi.py:43
METSignificance_cfi.METSignificance
METSignificance
____________________________________________________________________________||
Definition: METSignificance_cfi.py:6
edm::Handle
Definition: AssociativeIterator.h:50
edm::ParameterSetDescription::addOptional
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:105
EfficiencyLoader.h
pat::helper::KinResolutionsLoader::enabled
bool enabled() const
'true' if this there is at least one efficiency configured
Definition: KinResolutionsLoader.h:27
pat::PATMETProducer::lepTokens_
std::vector< edm::EDGetTokenT< edm::View< reco::Candidate > > > lepTokens_
Definition: PATMETProducer.cc:66
BTaggingMonitor_cfi.met
met
Definition: BTaggingMonitor_cfi.py:84
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
GreaterByEt
Definition: EtComparator.h:23
reco::MET::setSignificanceMatrix
void setSignificanceMatrix(const reco::METCovMatrix &matrix)
Definition: MET.cc:142
reco::MET
Definition: MET.h:41
MakerMacros.h
pat::PATMETProducer::metSigAlgo_
metsig::METSignificance * metSigAlgo_
Definition: PATMETProducer.cc:63
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
pat::PATUserDataHelper::add
void add(ObjectType &patObject, edm::Event const &iEvent, edm::EventSetup const &iSetup)
Definition: PATUserDataHelper.h:114
pat::helper::EfficiencyLoader::newEvent
void newEvent(const edm::Event &event)
To be called for each new event, reads in the ValueMaps for efficiencies.
Definition: EfficiencyLoader.cc:21
HLT_FULL_cff.weights
weights
Definition: HLT_FULL_cff.py:99207
pat::helper::KinResolutionsLoader
Definition: KinResolutionsLoader.h:18
pat::PATMETProducer::userDataHelper_
pat::PATUserDataHelper< pat::MET > userDataHelper_
Definition: PATMETProducer.cc:59
KinResolutionsLoader.h
pat::PATMETProducer::addMuonCorr_
bool addMuonCorr_
Definition: PATMETProducer.cc:50
ParameterSetDescription.h
metsig::METSignificance
Definition: METSignificance.h:33
pat::PATMETProducer::calculateMETSignificance_
bool calculateMETSignificance_
Definition: PATMETProducer.cc:62
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
FileInPath.h
pat::helper::KinResolutionsLoader::setResolutions
void setResolutions(pat::PATObject< T > &obj) const
Sets the efficiencies for this object, using the reference to the original objects.
Definition: KinResolutionsLoader.h:49
pat::MET::setGenMET
void setGenMET(const reco::GenMET &gm)
set the associated GenMET
Definition: MET.cc:118
edm::View
Definition: CaloClusterFwd.h:14
pat::PATMETProducer::~PATMETProducer
~PATMETProducer() override
Definition: PATMETProducer.cc:132
EtComparator.h
pat::PATMETProducer::addResolutions_
bool addResolutions_
Definition: PATMETProducer.cc:48
edm::ParameterSet
Definition: ParameterSet.h:47
edm::ParameterSetDescription::setComment
void setComment(std::string const &value)
Definition: ParameterSetDescription.cc:33
METSignificance.h
Event.h
pat::helper::KinResolutionsLoader::fillDescription
static void fillDescription(edm::ParameterSetDescription &iDesc)
Method for documentation and validation of PSet.
Definition: KinResolutionsLoader.cc:34
pat::PATMETProducer::weightsToken_
edm::EDGetTokenT< edm::ValueMap< float > > weightsToken_
Definition: PATMETProducer.cc:71
UserData.h
pat::PATMETProducer::addEfficiencies_
bool addEfficiencies_
Definition: PATMETProducer.cc:55
iEvent
int iEvent
Definition: GenABIO.cc:224
pat::PATMETProducer::pfCandToken_
edm::EDGetTokenT< edm::View< reco::Candidate > > pfCandToken_
Definition: PATMETProducer.cc:65
pat::PATMETProducer::PATMETProducer
PATMETProducer(const edm::ParameterSet &iConfig)
Definition: PATMETProducer.cc:83
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
pat::MET
Analysis-level MET class.
Definition: MET.h:40
edm::stream::EDProducer
Definition: EDProducer.h:36
edm::InputTag::encode
std::string encode() const
Definition: InputTag.cc:159
pat::PATMETProducer::useUserData_
bool useUserData_
Definition: PATMETProducer.cc:58
edm::EventSetup
Definition: EventSetup.h:58
pat
Definition: HeavyIon.h:7
edm::ParameterSetDescription::setAllowAnything
void setAllowAnything()
allow any parameter label/value pairs
Definition: ParameterSetDescription.cc:37
MET.h
pat::helper::KinResolutionsLoader::newEvent
void newEvent(const edm::Event &event, const edm::EventSetup &setup)
To be called for each new event, reads in the EventSetup object.
Definition: KinResolutionsLoader.cc:27
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
JME::JetResolutionScaleFactor
Definition: JetResolution.h:40
HLT_FULL_cff.srcWeights
srcWeights
Definition: HLT_FULL_cff.py:8709
edm::Ptr< reco::MET >
pat::PATMETProducer::jetResPtType_
std::string jetResPtType_
Definition: PATMETProducer.cc:68
pat::PATMETProducer::getMETCovMatrix
const reco::METCovMatrix getMETCovMatrix(const edm::Event &event, const edm::EventSetup &iSetup, const reco::MET &met, double &sumPtUnclustered) const
Definition: PATMETProducer.cc:230
pat::PATMETProducer::metSrc_
edm::InputTag metSrc_
Definition: PATMETProducer.cc:44
JME::JetResolutionScaleFactor::get
static const JetResolutionScaleFactor get(const edm::EventSetup &, const std::string &)
Definition: JetResolution.cc:48
eostools.move
def move(src, dest)
Definition: eostools.py:511
pat::PATMETProducer::jetToken_
edm::EDGetTokenT< edm::View< reco::Jet > > jetToken_
Definition: PATMETProducer.cc:64
pat::helper::EfficiencyLoader::setEfficiencies
void setEfficiencies(pat::PATObject< T > &obj, const R &originalRef) const
Sets the efficiencies for this object, using the reference to the original objects.
Definition: EfficiencyLoader.h:41
pat::PATMETProducer::addGenMET_
bool addGenMET_
Definition: PATMETProducer.cc:46
pat::PATMETProducer::resolutionLoader_
pat::helper::KinResolutionsLoader resolutionLoader_
Definition: PATMETProducer.cc:49
pat::PATMETProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: PATMETProducer.cc:201
edm::ValueMap< float >
metsig::METSignificance::getCovariance
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, edm::ValueMap< float > const *weights=nullptr)
Definition: METSignificance.cc:46
PATUserDataHelper.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::RefToBase
Definition: AssociativeIterator.h:54
pat::PATMETProducer::efficiencyLoader_
pat::helper::EfficiencyLoader efficiencyLoader_
Definition: PATMETProducer.cc:56
metsig::METSignificance::getSignificance
static double getSignificance(const reco::METCovMatrix &cov, const reco::MET &met)
Definition: METSignificance.cc:183
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
pat::PATMETProducer::rhoToken_
edm::EDGetTokenT< double > rhoToken_
Definition: PATMETProducer.cc:67
JME::JetResolution::get
static const JetResolution get(const edm::EventSetup &, const std::string &)
Definition: JetResolution.cc:23
cms::Exception
Definition: Exception.h:70
Candidate.h
View.h
ParameterSet.h
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
pat::PATMETProducer::metToken_
edm::EDGetTokenT< edm::View< reco::MET > > metToken_
Definition: PATMETProducer.cc:45
pat::PATMETProducer::jetResPhiType_
std::string jetResPhiType_
Definition: PATMETProducer.cc:69
edm::InputTag
Definition: InputTag.h:15
reco::METCovMatrix
ROOT::Math::SMatrix< double, 2 > METCovMatrix
Definition: MET.h:39
pat::MET::setMETSumPtUnclustered
void setMETSumPtUnclustered(const double &sumPtUnclustered)
Definition: MET.cc:128