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");
45  edm::InputTag srcWeights = iConfig.getParameter<edm::InputTag>("srcWeights");
46  if (!srcWeights.label().empty())
48  metSigAlgo_ = new metsig::METSignificance(iConfig);
49  rhoToken_ = consumes<double>(iConfig.getParameter<edm::InputTag>("srcRho"));
50  jetSFType_ = iConfig.getParameter<std::string>("srcJetSF");
51  jetResPtType_ = iConfig.getParameter<std::string>("srcJetResPt");
52  jetResPhiType_ = iConfig.getParameter<std::string>("srcJetResPhi");
53  jetToken_ = consumes<edm::View<reco::Jet>>(iConfig.getParameter<edm::InputTag>("srcJets"));
54  pfCandToken_ = consumes<edm::View<reco::Candidate>>(iConfig.getParameter<edm::InputTag>("srcPFCands"));
55  std::vector<edm::InputTag> srcLeptonsTags = iConfig.getParameter<std::vector<edm::InputTag>>("srcLeptons");
56  for (std::vector<edm::InputTag>::const_iterator it = srcLeptonsTags.begin(); it != srcLeptonsTags.end(); it++) {
57  lepTokens_.push_back(consumes<edm::View<reco::Candidate>>(*it));
58  }
59  }
60 
61  // produces vector of mets
62  produces<std::vector<MET>>();
63 }
64 
66 
68  // Get the vector of MET's from the event
70  iEvent.getByToken(metToken_, mets);
71 
72  if (mets->size() != 1)
73  throw cms::Exception("Corrupt Data") << "The input MET collection " << metSrc_.encode() << " has size "
74  << mets->size() << " instead of 1 as it should.\n";
79 
80  // Get the vector of generated met from the event if needed
82  if (addGenMET_) {
83  iEvent.getByToken(genMETToken_, genMETs);
84  }
85 
86  // loop over mets
87  std::vector<MET>* patMETs = new std::vector<MET>();
88  for (edm::View<reco::MET>::const_iterator itMET = mets->begin(); itMET != mets->end(); itMET++) {
89  // construct the MET from the ref -> save ref to original object
90  unsigned int idx = itMET - mets->begin();
91  edm::RefToBase<reco::MET> metsRef = mets->refAt(idx);
92  edm::Ptr<reco::MET> metsPtr = mets->ptrAt(idx);
93  MET amet(metsRef);
94  // add the generated MET
95  if (addGenMET_)
96  amet.setGenMET((*genMETs)[idx]);
97 
98  //add the MET significance
100  double sumPtUnclustered = 0;
101  const reco::METCovMatrix& sigcov = getMETCovMatrix(iEvent, iSetup, amet, sumPtUnclustered);
102  amet.setSignificanceMatrix(sigcov);
103  double metSig = metSigAlgo_->getSignificance(sigcov, amet);
104  amet.setMETSignificance(metSig);
106  }
107 
108  if (efficiencyLoader_.enabled()) {
109  efficiencyLoader_.setEfficiencies(amet, metsRef);
110  }
111 
112  if (resolutionLoader_.enabled()) {
114  }
115 
116  if (useUserData_) {
117  userDataHelper_.add(amet, iEvent, iSetup);
118  }
119 
120  // correct for muons if demanded... never more: it's now done by JetMETCorrections
121  // add the MET to the vector of METs
122  patMETs->push_back(amet);
123  }
124 
125  // sort MET in ET .. don't mess with this
126  // std::sort(patMETs->begin(), patMETs->end(), eTComparator_);
127 
128  // put genEvt object in Event
129  std::unique_ptr<std::vector<MET>> myMETs(patMETs);
130  iEvent.put(std::move(myMETs));
131 }
132 
133 // ParameterSet description for module
136  iDesc.setComment("PAT MET producer module");
137 
138  // input source
139  iDesc.add<edm::InputTag>("metSource", edm::InputTag("no default"))->setComment("input collection");
140 
141  // MC configurations
142  iDesc.add<bool>("addGenMET", false);
143  iDesc.add<edm::InputTag>("genMETSource", edm::InputTag("genMetCalo"));
144 
146 
147  // Efficiency configurables
148  edm::ParameterSetDescription efficienciesPSet;
149  efficienciesPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
150  iDesc.add("efficiencies", efficienciesPSet);
151  iDesc.add<bool>("addEfficiencies", false);
152 
153  // Check to see if the user wants to add user data
154  edm::ParameterSetDescription userDataPSet;
156  iDesc.addOptional("userData", userDataPSet);
157 
158  // muon correction
159  iDesc.add<bool>("addMuonCorrections", false);
160  iDesc.add<edm::InputTag>("muonSource", edm::InputTag("muons"));
161 }
162 
164  const edm::EventSetup& iSetup,
165  const reco::MET& met,
166  double& sumPtUnclustered) const {
167  std::vector<edm::Handle<reco::CandidateView>> leptons;
168  for (std::vector<edm::EDGetTokenT<edm::View<reco::Candidate>>>::const_iterator srcLeptons_i = lepTokens_.begin();
169  srcLeptons_i != lepTokens_.end();
170  ++srcLeptons_i) {
172  event.getByToken(*srcLeptons_i, leptons_i);
173  leptons.push_back(leptons_i);
174  }
175  // jets
177  event.getByToken(jetToken_, inputJets);
178 
179  //candidates
181  event.getByToken(pfCandToken_, inputCands);
182 
184  event.getByToken(rhoToken_, rho);
185 
188  event.getByToken(weightsToken_, weights);
189 
193 
194  //Compute the covariance matrix and fill it
195  const edm::ValueMap<float>* weightsPtr = nullptr;
196  if (met.isWeighted()) {
198  throw cms::Exception("InvalidInput") << "MET is weighted (e.g. PUPPI), but no weights given in PATMETProducer\n";
199  weightsPtr = &*weights;
200  }
202  leptons,
203  inputCands,
204  *rho,
205  resPtObj,
206  resPhiObj,
207  resSFObj,
208  event.isRealData(),
210  weightsPtr);
211 
212  return cov;
213 }
214 
216 
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.h:73
pat::PATUserDataHelper
Assists in assimilating all pat::UserData into pat objects.
Definition: PATUserDataHelper.h:49
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:98468
pat::PATMETProducer::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: PATMETProducer.cc:67
HLT_FULL_cff.leptons
leptons
Definition: HLT_FULL_cff.py:26277
pat::helper::EfficiencyLoader
Definition: EfficiencyLoader.h:16
pat::PATMETProducer::genMETToken_
edm::EDGetTokenT< edm::View< reco::GenMET > > genMETToken_
Definition: PATMETProducer.h:50
pat::PATMETProducer
Produces the pat::MET.
Definition: PATMETProducer.h:36
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:89281
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
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
pat::helper::KinResolutionsLoader::enabled
bool enabled() const
'true' if this there is at least one efficiency configured
Definition: KinResolutionsLoader.h:27
FileInPath.h
pat::PATMETProducer::lepTokens_
std::vector< edm::EDGetTokenT< edm::View< reco::Candidate > > > lepTokens_
Definition: PATMETProducer.h:69
BTaggingMonitor_cfi.met
met
Definition: BTaggingMonitor_cfi.py:84
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
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.h:66
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:99166
pat::helper::KinResolutionsLoader
Definition: KinResolutionsLoader.h:18
pat::PATMETProducer::userDataHelper_
pat::PATUserDataHelper< pat::MET > userDataHelper_
Definition: PATMETProducer.h:62
ParameterSetDescription.h
pat::PATMETProducer::calculateMETSignificance_
bool calculateMETSignificance_
Definition: PATMETProducer.h:65
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
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:65
pat::PATMETProducer::addResolutions_
bool addResolutions_
Definition: PATMETProducer.h:51
edm::ParameterSet
Definition: ParameterSet.h:47
edm::ParameterSetDescription::setComment
void setComment(std::string const &value)
Definition: ParameterSetDescription.cc:33
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.h:74
PATMETProducer.h
pat::PATMETProducer::addEfficiencies_
bool addEfficiencies_
Definition: PATMETProducer.h:58
iEvent
int iEvent
Definition: GenABIO.cc:224
pat::PATMETProducer::pfCandToken_
edm::EDGetTokenT< edm::View< reco::Candidate > > pfCandToken_
Definition: PATMETProducer.h:68
pat::PATMETProducer::PATMETProducer
PATMETProducer(const edm::ParameterSet &iConfig)
Definition: PATMETProducer.cc:16
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
pat::MET
Analysis-level MET class.
Definition: MET.h:40
edm::InputTag::encode
std::string encode() const
Definition: InputTag.cc:159
pat::PATMETProducer::useUserData_
bool useUserData_
Definition: PATMETProducer.h:61
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
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
JME::JetResolutionScaleFactor
Definition: JetResolution.h:40
HLT_FULL_cff.srcWeights
srcWeights
Definition: HLT_FULL_cff.py:8647
edm::Ptr< reco::MET >
pat::PATMETProducer::jetResPtType_
std::string jetResPtType_
Definition: PATMETProducer.h:71
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:163
pat::PATMETProducer::metSrc_
edm::InputTag metSrc_
Definition: PATMETProducer.h:47
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.h:67
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.h:49
pat::PATMETProducer::resolutionLoader_
pat::helper::KinResolutionsLoader resolutionLoader_
Definition: PATMETProducer.h:52
pat::PATMETProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: PATMETProducer.cc:134
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
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.h:59
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.h:70
JME::JetResolution::get
static const JetResolution get(const edm::EventSetup &, const std::string &)
Definition: JetResolution.cc:23
cms::Exception
Definition: Exception.h:70
View.h
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
pat::PATMETProducer::metToken_
edm::EDGetTokenT< edm::View< reco::MET > > metToken_
Definition: PATMETProducer.h:48
pat::PATMETProducer::jetResPhiType_
std::string jetResPhiType_
Definition: PATMETProducer.h:72
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