CMS 3D CMS Logo

PATMETProducer.cc
Go to the documentation of this file.
1 //
2 //
3 
8 
11 
12 #include <memory>
13 
14 
15 using namespace pat;
16 
17 
19  useUserData_(iConfig.exists("userData"))
20 {
21  // initialize the configurables
22  metSrc_ = iConfig.getParameter<edm::InputTag>("metSource");
23  metToken_ = consumes<edm::View<reco::MET> >(metSrc_);
24  addGenMET_ = iConfig.getParameter<bool> ("addGenMET");
25  genMETToken_ = mayConsume<edm::View<reco::GenMET> >(iConfig.getParameter<edm::InputTag>("genMETSource"));
26  addResolutions_ = iConfig.getParameter<bool> ("addResolutions");
27 
28  // Efficiency configurables
29  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
30  if (addEfficiencies_) {
31  efficiencyLoader_ = pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"), consumesCollector());
32  }
33 
34  // Resolution configurables
35  addResolutions_ = iConfig.getParameter<bool>("addResolutions");
36  if (addResolutions_) {
38  }
39 
40  // Check to see if the user wants to add user data
41  if ( useUserData_ ) {
42  userDataHelper_ = PATUserDataHelper<MET>(iConfig.getParameter<edm::ParameterSet>("userData"), consumesCollector());
43  }
44 
45  // MET Significance
46  calculateMETSignificance_ = iConfig.getParameter<bool>("computeMETSignificance");
47  if(calculateMETSignificance_)
48  {
49  metSigAlgo_ = new metsig::METSignificance(iConfig);
50  rhoToken_ = consumes<double>(iConfig.getParameter<edm::InputTag>("srcRho"));
51  jetSFType_ = iConfig.getParameter<std::string>("srcJetSF");
52  jetResPtType_ = iConfig.getParameter<std::string>("srcJetResPt");
53  jetResPhiType_ = iConfig.getParameter<std::string>("srcJetResPhi");
54  jetToken_ = consumes<edm::View<reco::Jet> >(iConfig.getParameter<edm::InputTag>("srcJets"));
55  pfCandToken_ = consumes<edm::View<reco::Candidate> >(iConfig.getParameter<edm::InputTag>("srcPFCands"));
56  std::vector<edm::InputTag> srcLeptonsTags = iConfig.getParameter< std::vector<edm::InputTag> >("srcLeptons");
57  for(std::vector<edm::InputTag>::const_iterator it=srcLeptonsTags.begin();it!=srcLeptonsTags.end();it++) {
58  lepTokens_.push_back( consumes<edm::View<reco::Candidate> >( *it ) );
59  }
60  }
61 
62  // produces vector of mets
63  produces<std::vector<MET> >();
64 }
65 
66 
68 }
69 
70 
72 
73  // Get the vector of MET's from the event
75  iEvent.getByToken(metToken_, mets);
76 
77  if (mets->size() != 1) throw cms::Exception("Corrupt Data") << "The input MET collection " << metSrc_.encode() << " has size " << mets->size() << " instead of 1 as it should.\n";
79  if (resolutionLoader_.enabled()) resolutionLoader_.newEvent(iEvent, iSetup);
80 
81  // Get the vector of generated met from the event if needed
83  if (addGenMET_) {
84  iEvent.getByToken(genMETToken_, genMETs);
85  }
86 
87  // loop over mets
88  std::vector<MET> * patMETs = new std::vector<MET>();
89  for (edm::View<reco::MET>::const_iterator itMET = mets->begin(); itMET != mets->end(); itMET++) {
90  // construct the MET from the ref -> save ref to original object
91  unsigned int idx = itMET - mets->begin();
92  edm::RefToBase<reco::MET> metsRef = mets->refAt(idx);
93  edm::Ptr<reco::MET> metsPtr = mets->ptrAt(idx);
94  MET amet(metsRef);
95  // add the generated MET
96  if (addGenMET_) amet.setGenMET((*genMETs)[idx]);
97 
98 
99  //add the MET significance
101  const reco::METCovMatrix& sigcov = getMETCovMatrix(iEvent, iSetup);
102  amet.setSignificanceMatrix(sigcov);
103  double metSig=metSigAlgo_->getSignificance(sigcov, amet);
104  amet.setMETSignificance(metSig);
105  }
106 
107  if (efficiencyLoader_.enabled()) {
108  efficiencyLoader_.setEfficiencies( amet, metsRef );
109  }
110 
111  if (resolutionLoader_.enabled()) {
113  }
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 
134 // ParameterSet description for module
136 {
138  iDesc.setComment("PAT MET producer module");
139 
140  // input source
141  iDesc.add<edm::InputTag>("metSource", edm::InputTag("no default"))->setComment("input collection");
142 
143  // MC configurations
144  iDesc.add<bool>("addGenMET", false);
145  iDesc.add<edm::InputTag>("genMETSource", edm::InputTag("genMetCalo"));
146 
148 
149  // Efficiency configurables
150  edm::ParameterSetDescription efficienciesPSet;
151  efficienciesPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
152  iDesc.add("efficiencies", efficienciesPSet);
153  iDesc.add<bool>("addEfficiencies", false);
154 
155  // Check to see if the user wants to add user data
156  edm::ParameterSetDescription userDataPSet;
158  iDesc.addOptional("userData", userDataPSet);
159 
160  // muon correction
161  iDesc.add<bool>("addMuonCorrections", false);
162  iDesc.add<edm::InputTag>("muonSource", edm::InputTag("muons"));
163 
164 }
165 
166 const reco::METCovMatrix
168  std::vector< edm::Handle<reco::CandidateView> > leptons;
169  for ( std::vector<edm::EDGetTokenT<edm::View<reco::Candidate> > >::const_iterator srcLeptons_i = lepTokens_.begin();
170  srcLeptons_i != lepTokens_.end(); ++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 
189 
190  //Compute the covariance matrix and fill it
191  reco::METCovMatrix cov = metSigAlgo_->getCovariance( *inputJets, leptons, inputCands,
192  *rho, resPtObj, resPhiObj, resSFObj, event.isRealData());
193 
194  return cov;
195 }
196 
197 
199 
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
Analysis-level MET class.
Definition: MET.h:43
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:137
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:579
void setAllowAnything()
allow any parameter label/value pairs
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
pat::PATUserDataHelper< pat::MET > userDataHelper_
void setSignificanceMatrix(const reco::METCovMatrix &matrix)
Definition: MET.cc:157
ROOT::Math::SMatrix< double, 2 > METCovMatrix
Definition: MET.h:40
std::string jetResPtType_
std::vector< edm::EDGetTokenT< edm::View< reco::Candidate > > > lepTokens_
std::string jetSFType_
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)
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:64
edm::EDGetTokenT< edm::View< reco::Candidate > > pfCandToken_
std::string encode() const
Definition: InputTag.cc:166
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
Definition: HeavyIon.h:7
const reco::METCovMatrix getMETCovMatrix(const edm::Event &event, const edm::EventSetup &iSetup) const
static void fillDescription(edm::ParameterSetDescription &iDesc)
void setComment(std::string const &value)
int iEvent
Definition: GenABIO.cc:230
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_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
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:115
PATMETProducer(const edm::ParameterSet &iConfig)
void setMETSignificance(const double &metSig)
Definition: MET.cc:122
def move(src, dest)
Definition: eostools.py:510
Definition: event.py:1
~PATMETProducer() override