CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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_) {
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_ ) {
43  }
44 
45  // MET Significance
46  calculateMETSignificance_ = iConfig.getParameter<bool>("computeMETSignificance");
48  {
49  metSigAlgo_ = new metsig::METSignificance(iConfig);
50  jetToken_ = mayConsume<edm::View<reco::Jet> >(iConfig.getParameter<edm::InputTag>("srcJets"));
51  pfCandToken_ = mayConsume<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( mayConsume<edm::View<reco::Candidate> >( *it ) );
55  }
56  }
57 
58  // produces vector of mets
59  produces<std::vector<MET> >();
60 }
61 
62 
64 }
65 
66 
68 
69  // Get the vector of MET's from the event
71  iEvent.getByToken(metToken_, mets);
72 
73  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";
75  if (resolutionLoader_.enabled()) 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_) amet.setGenMET((*genMETs)[idx]);
93 
94  //add the MET significance
96  const reco::METCovMatrix& sigcov = getMETCovMatrix(iEvent);
97  amet.setSignificanceMatrix(sigcov);
98  double metSig=metSigAlgo_->getSignificance(sigcov, amet);
99  amet.setMETSignificance(metSig);
100  }
101 
102  if (efficiencyLoader_.enabled()) {
103  efficiencyLoader_.setEfficiencies( amet, metsRef );
104  }
105 
106  if (resolutionLoader_.enabled()) {
108  }
109 
110 
111  if ( useUserData_ ) {
112  userDataHelper_.add( amet, iEvent, iSetup );
113  }
114 
115 
116  // correct for muons if demanded... never more: it's now done by JetMETCorrections
117  // add the MET to the vector of METs
118  patMETs->push_back(amet);
119  }
120 
121  // sort MET in ET .. don't mess with this
122  // std::sort(patMETs->begin(), patMETs->end(), eTComparator_);
123 
124  // put genEvt object in Event
125  std::auto_ptr<std::vector<MET> > myMETs(patMETs);
126  iEvent.put(myMETs);
127 
128 }
129 
130 // ParameterSet description for module
132 {
134  iDesc.setComment("PAT MET producer module");
135 
136  // input source
137  iDesc.add<edm::InputTag>("metSource", edm::InputTag("no default"))->setComment("input collection");
138 
139  // MC configurations
140  iDesc.add<bool>("addGenMET", false);
141  iDesc.add<edm::InputTag>("genMETSource", edm::InputTag("genMetCalo"));
142 
144 
145  // Efficiency configurables
146  edm::ParameterSetDescription efficienciesPSet;
147  efficienciesPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
148  iDesc.add("efficiencies", efficienciesPSet);
149  iDesc.add<bool>("addEfficiencies", false);
150 
151  // Check to see if the user wants to add user data
152  edm::ParameterSetDescription userDataPSet;
154  iDesc.addOptional("userData", userDataPSet);
155 
156  // muon correction
157  iDesc.add<bool>("addMuonCorrections", false);
158  iDesc.add<edm::InputTag>("muonSource", edm::InputTag("muons"));
159 
160 }
161 
162 const reco::METCovMatrix
164  std::vector< edm::Handle<reco::CandidateView> > leptons;
165  for ( std::vector<edm::EDGetTokenT<edm::View<reco::Candidate> > >::const_iterator srcLeptons_i = lepTokens_.begin();
166  srcLeptons_i != lepTokens_.end(); ++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 
179  //Compute the covariance matrix and fill it
180  reco::METCovMatrix cov = metSigAlgo_->getCovariance( *inputJets, leptons, *inputCands);
181  return cov;
182 }
183 
184 
186 
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.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
metsig::METSignificance * metSigAlgo_
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
Produces the pat::MET.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
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::vector< edm::EDGetTokenT< edm::View< reco::Candidate > > > lepTokens_
void setResolutions(pat::PATObject< T > &obj) const
Sets the efficiencies for this object, using the reference to the original objects.
edm::InputTag metSrc_
edm::EDGetTokenT< edm::View< reco::Candidate > > pfCandToken_
std::string encode() const
Definition: InputTag.cc:164
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
static void fillDescription(edm::ParameterSetDescription &iDesc)
tuple METSignificance
____________________________________________________________________________||
void setComment(std::string const &value)
int iEvent
Definition: GenABIO.cc:230
edm::EDGetTokenT< edm::View< reco::Jet > > jetToken_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
edm::EDGetTokenT< edm::View< reco::MET > > metToken_
pat::helper::EfficiencyLoader efficiencyLoader_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
reco::METCovMatrix getCovariance(const edm::View< reco::Jet > &jets, const std::vector< edm::Handle< reco::CandidateView > > &leptons, const edm::View< reco::Candidate > &pfCandidates)
pat::helper::KinResolutionsLoader resolutionLoader_
edm::EDGetTokenT< edm::View< reco::GenMET > > genMETToken_
static void fillDescription(edm::ParameterSetDescription &iDesc)
Method for documentation and validation of PSet.
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
void setEfficiencies(pat::PATObject< T > &obj, const R &originalRef) const
Sets the efficiencies for this object, using the reference to the original objects.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
const reco::METCovMatrix getMETCovMatrix(const edm::Event &event) const
double getSignificance(const reco::METCovMatrix &cov, const reco::MET &met) const
void setGenMET(const reco::GenMET &gm)
set the associated GenMET
Definition: MET.cc:114
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
void newEvent(const edm::Event &event, const edm::EventSetup &setup) const
To be called for each new event, reads in the EventSetup object.
PATMETProducer(const edm::ParameterSet &iConfig)
void setMETSignificance(const double &metSig)
Definition: MET.cc:121
void newEvent(const edm::Event &event) const
To be called for each new event, reads in the ValueMaps for efficiencies.