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...

#include "PhysicsTools/PatAlgos/interface/PATJetUpdater.h"

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
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndRuns () const final
 

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_
 
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<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache 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 33 of file PATJetUpdater.h.

Constructor & Destructor Documentation

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

Definition at line 25 of file PATJetUpdater.cc.

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

26  : useUserData_(iConfig.exists("userData")), printWarning_(iConfig.getParameter<bool>("printWarning")) {
27  // initialize configurables
28  jetsToken_ = consumes<edm::View<reco::Jet>>(iConfig.getParameter<edm::InputTag>("jetSource"));
29  addJetCorrFactors_ = iConfig.getParameter<bool>("addJetCorrFactors");
30  if (addJetCorrFactors_) {
32  iConfig.getParameter<std::vector<edm::InputTag>>("jetCorrFactorsSource"),
33  [this](edm::InputTag const& tag) { return mayConsume<edm::ValueMap<JetCorrFactors>>(tag); });
34  }
35  addBTagInfo_ = iConfig.getParameter<bool>("addBTagInfo");
36  addDiscriminators_ = iConfig.getParameter<bool>("addDiscriminators");
37  discriminatorTags_ = iConfig.getParameter<std::vector<edm::InputTag>>("discriminatorSources");
38  discriminatorTokens_ = edm::vector_transform(discriminatorTags_, [this](edm::InputTag const& tag) {
39  return mayConsume<reco::JetFloatAssociation::Container>(tag);
40  });
41  addTagInfos_ = iConfig.getParameter<bool>("addTagInfos");
42  tagInfoTags_ = iConfig.getParameter<std::vector<edm::InputTag>>("tagInfoSources");
44  tagInfoTags_, [this](edm::InputTag const& tag) { return mayConsume<edm::View<reco::BaseTagInfo>>(tag); });
45  if (discriminatorTags_.empty()) {
46  addDiscriminators_ = false;
47  } else {
48  for (std::vector<edm::InputTag>::const_iterator it = discriminatorTags_.begin(), ed = discriminatorTags_.end();
49  it != ed;
50  ++it) {
51  std::string label = it->label();
52  std::string::size_type pos = label.find("JetTags");
53  if ((pos != std::string::npos) && (pos != label.length() - 7)) {
54  label.erase(pos + 7); // trim a tail after "JetTags"
55  }
56  if (!it->instance().empty()) {
57  label = (label + std::string(":") + it->instance());
58  }
59  discriminatorLabels_.push_back(label);
60  }
61  }
62  if (tagInfoTags_.empty()) {
63  addTagInfos_ = false;
64  } else {
65  for (std::vector<edm::InputTag>::const_iterator it = tagInfoTags_.begin(), ed = tagInfoTags_.end(); it != ed;
66  ++it) {
67  std::string label = it->label();
68  std::string::size_type pos = label.find("TagInfos");
69  if ((pos != std::string::npos) && (pos != label.length() - 8)) {
70  label.erase(pos + 8); // trim a tail after "TagInfos"
71  }
72  tagInfoLabels_.push_back(label);
73  }
74  }
75  if (!addBTagInfo_) {
76  addDiscriminators_ = false;
77  addTagInfos_ = false;
78  }
79  // Check to see if the user wants to add user data
80  if (useUserData_) {
81  userDataHelper_ = PATUserDataHelper<Jet>(iConfig.getParameter<edm::ParameterSet>("userData"), consumesCollector());
82  }
83  // produces vector of jets
84  produces<std::vector<Jet>>();
85  produces<edm::OwnVector<reco::BaseTagInfo>>("tagInfos");
86 }
T getParameter(std::string const &) const
Assists in assimilating all pat::UserData into pat objects.
edm::EDGetTokenT< edm::View< reco::Jet > > jetsToken_
Definition: PATJetUpdater.h:44
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::vector< edm::InputTag > tagInfoTags_
Definition: PATJetUpdater.h:54
uint16_t size_type
char const * label
std::vector< edm::EDGetTokenT< edm::View< reco::BaseTagInfo > > > tagInfoTokens_
Definition: PATJetUpdater.h:55
std::vector< edm::EDGetTokenT< reco::JetFloatAssociation::Container > > discriminatorTokens_
Definition: PATJetUpdater.h:51
std::vector< edm::InputTag > discriminatorTags_
Definition: PATJetUpdater.h:50
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
std::vector< std::string > discriminatorLabels_
Definition: PATJetUpdater.h:52
pat::PATUserDataHelper< pat::Jet > userDataHelper_
Definition: PATJetUpdater.h:61
std::vector< std::string > tagInfoLabels_
Definition: PATJetUpdater.h:56
std::vector< edm::EDGetTokenT< edm::ValueMap< JetCorrFactors > > > jetCorrFactorsTokens_
Definition: PATJetUpdater.h:46
PATJetUpdater::~PATJetUpdater ( )
override

Definition at line 88 of file PATJetUpdater.cc.

88 {}

Member Function Documentation

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

Definition at line 228 of file PATJetUpdater.cc.

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

228  {
230  iDesc.setComment("PAT jet producer module");
231 
232  // input source
233  iDesc.add<edm::InputTag>("jetSource", edm::InputTag("no default"))->setComment("input collection");
234 
235  // tag info
236  iDesc.add<bool>("addTagInfos", true);
237  std::vector<edm::InputTag> emptyVInputTags;
238  iDesc.add<std::vector<edm::InputTag>>("tagInfoSources", emptyVInputTags);
239 
240  // jet energy corrections
241  iDesc.add<bool>("addJetCorrFactors", true);
242  iDesc.add<std::vector<edm::InputTag>>("jetCorrFactorsSource", emptyVInputTags);
243 
244  // btag discriminator tags
245  iDesc.add<bool>("addBTagInfo", true);
246  iDesc.add<bool>("addDiscriminators", true);
247  iDesc.add<std::vector<edm::InputTag>>("discriminatorSources", emptyVInputTags);
248 
249  // silent warning if false
250  iDesc.add<bool>("printWarning", true);
251 
252  // Check to see if the user wants to add user data
253  edm::ParameterSetDescription userDataPSet;
255  iDesc.addOptional("userData", userDataPSet);
256 
257  descriptions.add("PATJetUpdater", iDesc);
258 }
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)
void PATJetUpdater::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
override

Definition at line 90 of file PATJetUpdater.cc.

References pat::Jet::addBDiscriminatorPair(), addBTagInfo_, addDiscriminators_, pat::Jet::addJECFactors(), addJetCorrFactors_, pat::Jet::addTagInfo(), addTagInfos_, edm::View< T >::begin(), edm::RefToBase< T >::castTo(), reco::BaseTagInfo::clone(), pat::Jet::correctedP4(), discriminatorLabels_, discriminatorTokens_, edm::View< T >::end(), spr::find(), edm::Event::getByToken(), edm::Event::getRefBeforePut(), mps_fire::i, training_settings::idx, pat::Jet::initializeJEC(), edm::Ptr< T >::isNonnull(), pat::Jet::jec_, metsig::jet, jetCorrFactorsTokens_, singleTopDQM_cfi::jets, jetsToken_, dqmdumpme::k, jets_cff::levels, match(), eostools::move(), hemisphereProducer_cfi::patJets, printWarning_, pTComparator_, edm::View< T >::ptrAt(), edm::Event::put(), pat::PATObject< ObjectType >::refToOrig_, reco::LeafCandidate::setP4(), edm::View< T >::size(), tagInfoLabels_, tagInfoTokens_, userDataHelper_, and useUserData_.

90  {
91  // Get the vector of jets
93  iEvent.getByToken(jetsToken_, jets);
94 
95  // read in the jet correction factors ValueMap
96  std::vector<edm::ValueMap<JetCorrFactors>> jetCorrs;
97  if (addJetCorrFactors_) {
98  for (size_t i = 0; i < jetCorrFactorsTokens_.size(); ++i) {
100  iEvent.getByToken(jetCorrFactorsTokens_[i], jetCorr);
101  jetCorrs.push_back(*jetCorr);
102  }
103  }
104 
105  // Get the vector of jet tags with b-tagging info
106  std::vector<edm::Handle<reco::JetFloatAssociation::Container>> jetDiscriminators;
108  jetDiscriminators.resize(discriminatorTokens_.size());
109  for (size_t i = 0; i < discriminatorTokens_.size(); ++i) {
110  iEvent.getByToken(discriminatorTokens_[i], jetDiscriminators[i]);
111  }
112  }
113  std::vector<edm::Handle<edm::View<reco::BaseTagInfo>>> jetTagInfos;
114  if (addBTagInfo_ && addTagInfos_) {
115  jetTagInfos.resize(tagInfoTokens_.size());
116  for (size_t i = 0; i < tagInfoTokens_.size(); ++i) {
117  iEvent.getByToken(tagInfoTokens_[i], jetTagInfos[i]);
118  }
119  }
120 
121  // loop over jets
122  auto patJets = std::make_unique<std::vector<Jet>>();
123 
124  auto tagInfosOut = std::make_unique<edm::OwnVector<reco::BaseTagInfo>>();
125 
128 
129  for (edm::View<reco::Jet>::const_iterator itJet = jets->begin(); itJet != jets->end(); itJet++) {
130  // construct the Jet from the ref -> save ref to original object
131  unsigned int idx = itJet - jets->begin();
132  const edm::RefToBase<reco::Jet> jetRef = jets->refAt(idx);
133  const edm::RefToBase<Jet> patJetRef(jetRef.castTo<JetRef>());
134  Jet ajet(patJetRef);
135 
136  if (addJetCorrFactors_) {
137  // undo previous jet energy corrections
138  ajet.setP4(ajet.correctedP4(0));
139  // clear previous JetCorrFactors
140  ajet.jec_.clear();
141  // add additional JetCorrs to the jet
142  for (unsigned int i = 0; i < jetCorrFactorsTokens_.size(); ++i) {
143  const JetCorrFactors& jcf = jetCorrs[i][jetRef];
144  // uncomment for debugging
145  // jcf.print();
146  ajet.addJECFactors(jcf);
147  }
148  std::vector<std::string> levels = jetCorrs[0][jetRef].correctionLabels();
149  if (std::find(levels.begin(), levels.end(), "L2L3Residual") != levels.end()) {
150  ajet.initializeJEC(jetCorrs[0][jetRef].jecLevel("L2L3Residual"));
151  } else if (std::find(levels.begin(), levels.end(), "L3Absolute") != levels.end()) {
152  ajet.initializeJEC(jetCorrs[0][jetRef].jecLevel("L3Absolute"));
153  } else {
154  ajet.initializeJEC(jetCorrs[0][jetRef].jecLevel("Uncorrected"));
155  if (printWarning_) {
156  edm::LogWarning("L3Absolute not found")
157  << "L2L3Residual and L3Absolute are not part of the jetCorrFactors\n"
158  << "of module " << jetCorrs[0][jetRef].jecSet() << ". Jets will remain"
159  << " uncorrected.";
160  printWarning_ = false;
161  }
162  }
163  }
164 
165  // add b-tag info if available & required
166  if (addBTagInfo_) {
167  if (addDiscriminators_) {
168  for (size_t k = 0; k < jetDiscriminators.size(); ++k) {
169  float value = (*jetDiscriminators[k])[jetRef];
170  ajet.addBDiscriminatorPair(std::make_pair(discriminatorLabels_[k], value));
171  }
172  }
173  if (addTagInfos_) {
174  for (size_t k = 0; k < jetTagInfos.size(); ++k) {
175  const edm::View<reco::BaseTagInfo>& taginfos = *jetTagInfos[k];
176  // This is not associative, so we have to search the jet
178  // Try first by 'same index'
179  if ((idx < taginfos.size()) && (taginfos[idx].jet() == jetRef)) {
180  match = taginfos.ptrAt(idx);
181  } else {
182  // otherwise fail back to a simple search
183  for (edm::View<reco::BaseTagInfo>::const_iterator itTI = taginfos.begin(), edTI = taginfos.end();
184  itTI != edTI;
185  ++itTI) {
186  if (itTI->jet() == jetRef) {
187  match = taginfos.ptrAt(itTI - taginfos.begin());
188  break;
189  }
190  }
191  }
192  if (match.isNonnull()) {
193  tagInfosOut->push_back(match->clone());
194  // set the "forward" ptr to the thinned collection
195  edm::Ptr<reco::BaseTagInfo> tagInfoForwardPtr(
196  h_tagInfosOut.id(), &tagInfosOut->back(), tagInfosOut->size() - 1);
197  // set the "backward" ptr to the original collection for association
198  const edm::Ptr<reco::BaseTagInfo>& tagInfoBackPtr(match);
199  // make FwdPtr
200  TagInfoFwdPtrCollection::value_type tagInfoFwdPtr(tagInfoForwardPtr, tagInfoBackPtr);
201  ajet.addTagInfo(tagInfoLabels_[k], tagInfoFwdPtr);
202  }
203  }
204  }
205  }
206 
207  if (useUserData_) {
208  userDataHelper_.add(ajet, iEvent, iSetup);
209  }
210 
211  // reassign the original object reference to preserve reference to the original jet the input PAT jet was derived from
212  // (this needs to be done at the end since cloning the input PAT jet would interfere with adding UserData)
213  ajet.refToOrig_ = patJetRef->originalObjectRef();
214 
215  patJets->push_back(ajet);
216  }
217 
218  // sort jets in pt
219  std::sort(patJets->begin(), patJets->end(), pTComparator_);
220 
221  // put genEvt in Event
222  iEvent.put(std::move(patJets));
223 
224  iEvent.put(std::move(tagInfosOut), "tagInfos");
225 }
GreaterByPt< Jet > pTComparator_
Definition: PATJetUpdater.h:58
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
virtual BaseTagInfo * clone(void) const
clone
Definition: BaseTagInfo.h:19
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
Ptr< value_type > ptrAt(size_type i) const
edm::EDGetTokenT< edm::View< reco::Jet > > jetsToken_
Definition: PATJetUpdater.h:44
size_type size() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
std::vector< edm::EDGetTokenT< edm::View< reco::BaseTagInfo > > > tagInfoTokens_
Definition: PATJetUpdater.h:55
std::vector< edm::EDGetTokenT< reco::JetFloatAssociation::Container > > discriminatorTokens_
Definition: PATJetUpdater.h:51
const_iterator begin() const
Definition: Jet.py:1
Class for the storage of jet correction factors.
Definition: value.py:1
RefProd< PROD > getRefBeforePut()
Definition: Event.h:156
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:146
std::vector< std::string > discriminatorLabels_
Definition: PATJetUpdater.h:52
REF castTo() const
Definition: RefToBase.h:257
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
const_iterator end() const
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
pat::PATUserDataHelper< pat::Jet > userDataHelper_
Definition: PATJetUpdater.h:61
std::vector< std::string > tagInfoLabels_
Definition: PATJetUpdater.h:56
std::vector< edm::EDGetTokenT< edm::ValueMap< JetCorrFactors > > > jetCorrFactorsTokens_
Definition: PATJetUpdater.h:46
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

bool pat::PATJetUpdater::addBTagInfo_
private

Definition at line 48 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

bool pat::PATJetUpdater::addDiscriminators_
private

Definition at line 49 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

bool pat::PATJetUpdater::addJetCorrFactors_
private

Definition at line 45 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

bool pat::PATJetUpdater::addTagInfos_
private

Definition at line 53 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

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

Definition at line 52 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

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

Definition at line 50 of file PATJetUpdater.h.

Referenced by PATJetUpdater().

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

Definition at line 51 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

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

Definition at line 46 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

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

Definition at line 44 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

bool pat::PATJetUpdater::printWarning_
private

Definition at line 63 of file PATJetUpdater.h.

Referenced by produce().

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

Definition at line 58 of file PATJetUpdater.h.

Referenced by produce().

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

Definition at line 56 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

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

Definition at line 54 of file PATJetUpdater.h.

Referenced by PATJetUpdater().

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

Definition at line 55 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

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

Definition at line 61 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

bool pat::PATJetUpdater::useUserData_
private

Definition at line 60 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().