CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Attributes
pat::PATJetUpdater Class Reference

Produces pat::Jet's. More...

Inheritance diagram for pat::PATJetUpdater:
edm::stream::EDProducer<>

Public Member Functions

 PATJetUpdater (const edm::ParameterSet &iConfig)
 
void produce (edm::Event &iEvent, const edm::EventSetup &iSetup) override
 
 ~PATJetUpdater () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Attributes

bool addBTagInfo_
 
bool addDiscriminators_
 
bool addJetCorrFactors_
 
bool addTagInfos_
 
std::vector< std::string > discriminatorLabels_
 
std::vector< edm::InputTagdiscriminatorTags_
 
std::vector< edm::EDGetTokenT< reco::JetFloatAssociation::Container > > discriminatorTokens_
 
std::vector< edm::EDGetTokenT< edm::ValueMap< JetCorrFactors > > > jetCorrFactorsTokens_
 
edm::EDGetTokenT< edm::View< reco::Jet > > jetsToken_
 
bool printWarning_
 
GreaterByPt< JetpTComparator_
 
bool sort_
 
std::vector< std::string > tagInfoLabels_
 
std::vector< edm::InputTagtagInfoTags_
 
std::vector< edm::EDGetTokenT< edm::View< reco::BaseTagInfo > > > tagInfoTokens_
 
pat::PATUserDataHelper< pat::JetuserDataHelper_
 
bool useUserData_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

Produces pat::Jet's.

The PATJetUpdater produces analysis-level pat::Jet's starting from a collection of pat::Jet's and updates information.

Author
Andreas Hinzmann
Version
Id
PATJetUpdater.h,v 1.00 2014/03/11 18:13:54 srappocc Exp

Definition at line 37 of file PATJetUpdater.cc.

Constructor & Destructor Documentation

◆ PATJetUpdater()

PATJetUpdater::PATJetUpdater ( const edm::ParameterSet iConfig)
explicit

Definition at line 75 of file PATJetUpdater.cc.

References addBTagInfo_, addDiscriminators_, addJetCorrFactors_, addTagInfos_, discriminatorLabels_, discriminatorTags_, discriminatorTokens_, edm::ParameterSet::getParameter(), jetCorrFactorsTokens_, jetsToken_, label, sort_, AlCaHLTBitMon_QueryRunRegistry::string, makeGlobalPositionRcd_cfg::tag, tagInfoLabels_, tagInfoTags_, tagInfoTokens_, userDataHelper_, useUserData_, and edm::vector_transform().

76  : useUserData_(iConfig.exists("userData")), printWarning_(iConfig.getParameter<bool>("printWarning")) {
77  // initialize configurables
78  jetsToken_ = consumes<edm::View<reco::Jet>>(iConfig.getParameter<edm::InputTag>("jetSource"));
79  sort_ = iConfig.getParameter<bool>("sort");
80  addJetCorrFactors_ = iConfig.getParameter<bool>("addJetCorrFactors");
81  if (addJetCorrFactors_) {
83  iConfig.getParameter<std::vector<edm::InputTag>>("jetCorrFactorsSource"),
84  [this](edm::InputTag const& tag) { return mayConsume<edm::ValueMap<JetCorrFactors>>(tag); });
85  }
86  addBTagInfo_ = iConfig.getParameter<bool>("addBTagInfo");
87  addDiscriminators_ = iConfig.getParameter<bool>("addDiscriminators");
88  discriminatorTags_ = iConfig.getParameter<std::vector<edm::InputTag>>("discriminatorSources");
90  return mayConsume<reco::JetFloatAssociation::Container>(tag);
91  });
92  addTagInfos_ = iConfig.getParameter<bool>("addTagInfos");
93  tagInfoTags_ = iConfig.getParameter<std::vector<edm::InputTag>>("tagInfoSources");
95  tagInfoTags_, [this](edm::InputTag const& tag) { return mayConsume<edm::View<reco::BaseTagInfo>>(tag); });
96  if (discriminatorTags_.empty()) {
97  addDiscriminators_ = false;
98  } else {
99  for (std::vector<edm::InputTag>::const_iterator it = discriminatorTags_.begin(), ed = discriminatorTags_.end();
100  it != ed;
101  ++it) {
102  std::string label = it->label();
103  std::string::size_type pos = label.find("JetTags");
104  if ((pos != std::string::npos) && (pos != label.length() - 7)) {
105  label.erase(pos + 7); // trim a tail after "JetTags"
106  }
107  if (!it->instance().empty()) {
108  label = (label + std::string(":") + it->instance());
109  }
110  discriminatorLabels_.push_back(label);
111  }
112  }
113  if (tagInfoTags_.empty()) {
114  addTagInfos_ = false;
115  } else {
116  for (std::vector<edm::InputTag>::const_iterator it = tagInfoTags_.begin(), ed = tagInfoTags_.end(); it != ed;
117  ++it) {
118  std::string label = it->label();
119  std::string::size_type pos = label.find("TagInfos");
120  if ((pos != std::string::npos) && (pos != label.length() - 8)) {
121  label.erase(pos + 8); // trim a tail after "TagInfos"
122  }
123  tagInfoLabels_.push_back(label);
124  }
125  }
126  if (!addBTagInfo_) {
127  addDiscriminators_ = false;
128  addTagInfos_ = false;
129  }
130  // Check to see if the user wants to add user data
131  if (useUserData_) {
132  userDataHelper_ = PATUserDataHelper<Jet>(iConfig.getParameter<edm::ParameterSet>("userData"), consumesCollector());
133  }
134  // produces vector of jets
135  produces<std::vector<Jet>>();
136  produces<edm::OwnVector<reco::BaseTagInfo>>("tagInfos");
137 }
Assists in assimilating all pat::UserData into pat objects.
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< edm::View< reco::Jet > > jetsToken_
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::vector< edm::InputTag > tagInfoTags_
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
uint16_t size_type
char const * label
std::vector< edm::EDGetTokenT< edm::View< reco::BaseTagInfo > > > tagInfoTokens_
std::vector< edm::EDGetTokenT< reco::JetFloatAssociation::Container > > discriminatorTokens_
std::vector< edm::InputTag > discriminatorTags_
std::vector< std::string > discriminatorLabels_
pat::PATUserDataHelper< pat::Jet > userDataHelper_
std::vector< std::string > tagInfoLabels_
std::vector< edm::EDGetTokenT< edm::ValueMap< JetCorrFactors > > > jetCorrFactorsTokens_

◆ ~PATJetUpdater()

PATJetUpdater::~PATJetUpdater ( )
override

Definition at line 139 of file PATJetUpdater.cc.

139 {}

Member Function Documentation

◆ fillDescriptions()

void PATJetUpdater::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 281 of file PATJetUpdater.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::add(), edm::ParameterSetDescription::addOptional(), pat::PATUserDataHelper< ObjectType >::fillDescription(), ProducerED_cfi::InputTag, and edm::ParameterSetDescription::setComment().

281  {
283  iDesc.setComment("PAT jet producer module");
284 
285  // input source
286  iDesc.add<edm::InputTag>("jetSource", edm::InputTag("no default"))->setComment("input collection");
287 
288  // sort inputs (by pt)
289  iDesc.add<bool>("sort", true);
290 
291  // tag info
292  iDesc.add<bool>("addTagInfos", true);
293  std::vector<edm::InputTag> emptyVInputTags;
294  iDesc.add<std::vector<edm::InputTag>>("tagInfoSources", emptyVInputTags);
295 
296  // jet energy corrections
297  iDesc.add<bool>("addJetCorrFactors", true);
298  iDesc.add<std::vector<edm::InputTag>>("jetCorrFactorsSource", emptyVInputTags);
299 
300  // btag discriminator tags
301  iDesc.add<bool>("addBTagInfo", true);
302  iDesc.add<bool>("addDiscriminators", true);
303  iDesc.add<std::vector<edm::InputTag>>("discriminatorSources", emptyVInputTags);
304 
305  // silent warning if false
306  iDesc.add<bool>("printWarning", true);
307 
308  // Check to see if the user wants to add user data
309  edm::ParameterSetDescription userDataPSet;
311  iDesc.addOptional("userData", userDataPSet);
312 
313  descriptions.add("PATJetUpdater", iDesc);
314 }
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
static void fillDescription(edm::ParameterSetDescription &iDesc)
void setComment(std::string const &value)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ produce()

void PATJetUpdater::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
override

Definition at line 141 of file PATJetUpdater.cc.

References pat::PATUserDataHelper< ObjectType >::add(), pat::Jet::addBDiscriminatorPair(), addBTagInfo_, addDiscriminators_, pat::Jet::addJECFactors(), addJetCorrFactors_, pat::Jet::addTagInfo(), addTagInfos_, edm::View< T >::begin(), edm::RefToBase< T >::castTo(), pat::Jet::correctedP4(), discriminatorLabels_, discriminatorTokens_, edm::View< T >::end(), spr::find(), mps_fire::i, heavyIonCSV_trainingSettings::idx, iEvent, pat::Jet::initializeJEC(), pat::Jet::jec_, metsig::jet, jetCorrFactorsTokens_, PDWG_EXODelayedJetMET_cff::jets, jetsToken_, dqmdumpme::k, GCP_tree_cfg::levels, eostools::move(), hemisphereProducer_cfi::patJets, printWarning_, pTComparator_, edm::View< T >::ptrAt(), pat::PATObject< ObjectType >::refToOrig_, reco::LeafCandidate::setP4(), edm::View< T >::size(), jetUpdater_cfi::sort, sort_, tagInfoLabels_, tagInfoTokens_, userDataHelper_, and useUserData_.

141  {
142  // Get the vector of jets
144  iEvent.getByToken(jetsToken_, jets);
145 
146  // read in the jet correction factors ValueMap
147  std::vector<edm::ValueMap<JetCorrFactors>> jetCorrs;
148  if (addJetCorrFactors_) {
149  for (size_t i = 0; i < jetCorrFactorsTokens_.size(); ++i) {
151  iEvent.getByToken(jetCorrFactorsTokens_[i], jetCorr);
152  jetCorrs.push_back(*jetCorr);
153  }
154  }
155 
156  // Get the vector of jet tags with b-tagging info
157  std::vector<edm::Handle<reco::JetFloatAssociation::Container>> jetDiscriminators;
159  jetDiscriminators.resize(discriminatorTokens_.size());
160  for (size_t i = 0; i < discriminatorTokens_.size(); ++i) {
161  iEvent.getByToken(discriminatorTokens_[i], jetDiscriminators[i]);
162  }
163  }
164  std::vector<edm::Handle<edm::View<reco::BaseTagInfo>>> jetTagInfos;
165  if (addBTagInfo_ && addTagInfos_) {
166  jetTagInfos.resize(tagInfoTokens_.size());
167  for (size_t i = 0; i < tagInfoTokens_.size(); ++i) {
168  iEvent.getByToken(tagInfoTokens_[i], jetTagInfos[i]);
169  }
170  }
171 
172  // loop over jets
173  auto patJets = std::make_unique<std::vector<Jet>>();
174 
175  auto tagInfosOut = std::make_unique<edm::OwnVector<reco::BaseTagInfo>>();
176 
178  iEvent.getRefBeforePut<edm::OwnVector<reco::BaseTagInfo>>("tagInfos");
179 
180  for (edm::View<reco::Jet>::const_iterator itJet = jets->begin(); itJet != jets->end(); itJet++) {
181  // construct the Jet from the ref -> save ref to original object
182  unsigned int idx = itJet - jets->begin();
183  const edm::RefToBase<reco::Jet> jetRef = jets->refAt(idx);
184  const edm::RefToBase<Jet> patJetRef(jetRef.castTo<JetRef>());
185  Jet ajet(patJetRef);
186 
187  if (addJetCorrFactors_) {
188  // undo previous jet energy corrections
189  ajet.setP4(ajet.correctedP4(0));
190  // clear previous JetCorrFactors
191  ajet.jec_.clear();
192  // add additional JetCorrs to the jet
193  for (unsigned int i = 0; i < jetCorrFactorsTokens_.size(); ++i) {
194  const JetCorrFactors& jcf = jetCorrs[i][jetRef];
195  // uncomment for debugging
196  // jcf.print();
197  ajet.addJECFactors(jcf);
198  }
199  std::vector<std::string> levels = jetCorrs[0][jetRef].correctionLabels();
200  if (std::find(levels.begin(), levels.end(), "L2L3Residual") != levels.end()) {
201  ajet.initializeJEC(jetCorrs[0][jetRef].jecLevel("L2L3Residual"));
202  } else if (std::find(levels.begin(), levels.end(), "L3Absolute") != levels.end()) {
203  ajet.initializeJEC(jetCorrs[0][jetRef].jecLevel("L3Absolute"));
204  } else {
205  ajet.initializeJEC(jetCorrs[0][jetRef].jecLevel("Uncorrected"));
206  if (printWarning_) {
207  edm::LogWarning("L3Absolute not found")
208  << "L2L3Residual and L3Absolute are not part of the jetCorrFactors\n"
209  << "of module " << jetCorrs[0][jetRef].jecSet() << ". Jets will remain"
210  << " uncorrected.";
211  printWarning_ = false;
212  }
213  }
214  }
215 
216  // add b-tag info if available & required
217  if (addBTagInfo_) {
218  if (addDiscriminators_) {
219  for (size_t k = 0; k < jetDiscriminators.size(); ++k) {
220  float value = (*jetDiscriminators[k])[jetRef];
221  ajet.addBDiscriminatorPair(std::make_pair(discriminatorLabels_[k], value));
222  }
223  }
224  if (addTagInfos_) {
225  for (size_t k = 0; k < jetTagInfos.size(); ++k) {
226  const edm::View<reco::BaseTagInfo>& taginfos = *jetTagInfos[k];
227  // This is not associative, so we have to search the jet
229  // Try first by 'same index'
230  if ((idx < taginfos.size()) && (taginfos[idx].jet() == jetRef)) {
231  match = taginfos.ptrAt(idx);
232  } else {
233  // otherwise fail back to a simple search
234  for (edm::View<reco::BaseTagInfo>::const_iterator itTI = taginfos.begin(), edTI = taginfos.end();
235  itTI != edTI;
236  ++itTI) {
237  if (itTI->jet() == jetRef) {
238  match = taginfos.ptrAt(itTI - taginfos.begin());
239  break;
240  }
241  }
242  }
243  if (match.isNonnull()) {
244  tagInfosOut->push_back(match->clone());
245  // set the "forward" ptr to the thinned collection
246  edm::Ptr<reco::BaseTagInfo> tagInfoForwardPtr(
247  h_tagInfosOut.id(), &tagInfosOut->back(), tagInfosOut->size() - 1);
248  // set the "backward" ptr to the original collection for association
249  const edm::Ptr<reco::BaseTagInfo>& tagInfoBackPtr(match);
250  // make FwdPtr
251  TagInfoFwdPtrCollection::value_type tagInfoFwdPtr(tagInfoForwardPtr, tagInfoBackPtr);
252  ajet.addTagInfo(tagInfoLabels_[k], tagInfoFwdPtr);
253  }
254  }
255  }
256  }
257 
258  if (useUserData_) {
259  userDataHelper_.add(ajet, iEvent, iSetup);
260  }
261 
262  // reassign the original object reference to preserve reference to the original jet the input PAT jet was derived from
263  // (this needs to be done at the end since cloning the input PAT jet would interfere with adding UserData)
264  ajet.refToOrig_ = patJetRef->originalObjectRef();
265 
266  patJets->push_back(ajet);
267  }
268 
269  // sort jets in pt
270  if (sort_) {
271  std::sort(patJets->begin(), patJets->end(), pTComparator_);
272  }
273 
274  // put genEvt in Event
275  iEvent.put(std::move(patJets));
276 
277  iEvent.put(std::move(tagInfosOut), "tagInfos");
278 }
GreaterByPt< Jet > pTComparator_
Ptr< value_type > ptrAt(size_type i) const
REF castTo() const
Definition: RefToBase.h:259
edm::EDGetTokenT< edm::View< reco::Jet > > jetsToken_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
size_type size() const
std::vector< edm::EDGetTokenT< edm::View< reco::BaseTagInfo > > > tagInfoTokens_
std::vector< edm::EDGetTokenT< reco::JetFloatAssociation::Container > > discriminatorTokens_
int iEvent
Definition: GenABIO.cc:224
Definition: Jet.py:1
Class for the storage of jet correction factors.
Definition: value.py:1
void add(ObjectType &patObject, edm::Event const &iEvent, edm::EventSetup const &iSetup)
std::vector< std::string > discriminatorLabels_
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
pat::PATUserDataHelper< pat::Jet > userDataHelper_
const_iterator begin() const
Log< level::Warning, false > LogWarning
std::vector< std::string > tagInfoLabels_
std::vector< edm::EDGetTokenT< edm::ValueMap< JetCorrFactors > > > jetCorrFactorsTokens_
const_iterator end() const
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

◆ addBTagInfo_

bool pat::PATJetUpdater::addBTagInfo_
private

Definition at line 53 of file PATJetUpdater.cc.

Referenced by PATJetUpdater(), and produce().

◆ addDiscriminators_

bool pat::PATJetUpdater::addDiscriminators_
private

Definition at line 54 of file PATJetUpdater.cc.

Referenced by PATJetUpdater(), and produce().

◆ addJetCorrFactors_

bool pat::PATJetUpdater::addJetCorrFactors_
private

Definition at line 50 of file PATJetUpdater.cc.

Referenced by PATJetUpdater(), and produce().

◆ addTagInfos_

bool pat::PATJetUpdater::addTagInfos_
private

Definition at line 58 of file PATJetUpdater.cc.

Referenced by PATJetUpdater(), and produce().

◆ discriminatorLabels_

std::vector<std::string> pat::PATJetUpdater::discriminatorLabels_
private

Definition at line 57 of file PATJetUpdater.cc.

Referenced by PATJetUpdater(), and produce().

◆ discriminatorTags_

std::vector<edm::InputTag> pat::PATJetUpdater::discriminatorTags_
private

Definition at line 55 of file PATJetUpdater.cc.

Referenced by PATJetUpdater().

◆ discriminatorTokens_

std::vector<edm::EDGetTokenT<reco::JetFloatAssociation::Container> > pat::PATJetUpdater::discriminatorTokens_
private

Definition at line 56 of file PATJetUpdater.cc.

Referenced by PATJetUpdater(), and produce().

◆ jetCorrFactorsTokens_

std::vector<edm::EDGetTokenT<edm::ValueMap<JetCorrFactors> > > pat::PATJetUpdater::jetCorrFactorsTokens_
private

Definition at line 51 of file PATJetUpdater.cc.

Referenced by PATJetUpdater(), and produce().

◆ jetsToken_

edm::EDGetTokenT<edm::View<reco::Jet> > pat::PATJetUpdater::jetsToken_
private

Definition at line 48 of file PATJetUpdater.cc.

Referenced by PATJetUpdater(), and produce().

◆ printWarning_

bool pat::PATJetUpdater::printWarning_
private

Definition at line 68 of file PATJetUpdater.cc.

Referenced by produce().

◆ pTComparator_

GreaterByPt<Jet> pat::PATJetUpdater::pTComparator_
private

Definition at line 63 of file PATJetUpdater.cc.

Referenced by produce().

◆ sort_

bool pat::PATJetUpdater::sort_
private

Definition at line 49 of file PATJetUpdater.cc.

Referenced by PATJetUpdater(), and produce().

◆ tagInfoLabels_

std::vector<std::string> pat::PATJetUpdater::tagInfoLabels_
private

Definition at line 61 of file PATJetUpdater.cc.

Referenced by PATJetUpdater(), and produce().

◆ tagInfoTags_

std::vector<edm::InputTag> pat::PATJetUpdater::tagInfoTags_
private

Definition at line 59 of file PATJetUpdater.cc.

Referenced by PATJetUpdater().

◆ tagInfoTokens_

std::vector<edm::EDGetTokenT<edm::View<reco::BaseTagInfo> > > pat::PATJetUpdater::tagInfoTokens_
private

Definition at line 60 of file PATJetUpdater.cc.

Referenced by PATJetUpdater(), and produce().

◆ userDataHelper_

pat::PATUserDataHelper<pat::Jet> pat::PATJetUpdater::userDataHelper_
private

Definition at line 66 of file PATJetUpdater.cc.

Referenced by PATJetUpdater(), and produce().

◆ useUserData_

bool pat::PATJetUpdater::useUserData_
private

Definition at line 65 of file PATJetUpdater.cc.

Referenced by PATJetUpdater(), and produce().