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 hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () 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_
 
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<>
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 34 of file PATJetUpdater.h.

Constructor & Destructor Documentation

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

Definition at line 27 of file PATJetUpdater.cc.

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

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

Definition at line 83 of file PATJetUpdater.cc.

83  {
84 
85 }

Member Function Documentation

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

Definition at line 224 of file PATJetUpdater.cc.

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

225 {
227  iDesc.setComment("PAT jet producer module");
228 
229  // input source
230  iDesc.add<edm::InputTag>("jetSource", edm::InputTag("no default"))->setComment("input collection");
231 
232  // sort inputs (by pt)
233  iDesc.add<bool>("sort", true);
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 88 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_, fwrapper::jets, jetsToken_, gen::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(), jetUpdater_cfi::sort, sort_, tagInfoLabels_, tagInfoTokens_, userDataHelper_, and useUserData_.

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

Member Data Documentation

bool pat::PATJetUpdater::addBTagInfo_
private

Definition at line 53 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

bool pat::PATJetUpdater::addDiscriminators_
private

Definition at line 54 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

bool pat::PATJetUpdater::addJetCorrFactors_
private

Definition at line 50 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

bool pat::PATJetUpdater::addTagInfos_
private

Definition at line 58 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

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

Definition at line 57 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

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

Definition at line 55 of file PATJetUpdater.h.

Referenced by PATJetUpdater().

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

Definition at line 56 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

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

Definition at line 51 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

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

Definition at line 48 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

bool pat::PATJetUpdater::printWarning_
private

Definition at line 68 of file PATJetUpdater.h.

Referenced by produce().

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

Definition at line 63 of file PATJetUpdater.h.

Referenced by produce().

bool pat::PATJetUpdater::sort_
private

Definition at line 49 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

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

Definition at line 61 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

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

Definition at line 59 of file PATJetUpdater.h.

Referenced by PATJetUpdater().

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

Definition at line 60 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

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

Definition at line 66 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

bool pat::PATJetUpdater::useUserData_
private

Definition at line 65 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().