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

Definition at line 82 of file PATJetUpdater.cc.

82  {
83 
84 }

Member Function Documentation

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

Definition at line 221 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().

222 {
224  iDesc.setComment("PAT jet producer module");
225 
226  // input source
227  iDesc.add<edm::InputTag>("jetSource", edm::InputTag("no default"))->setComment("input collection");
228 
229  // tag info
230  iDesc.add<bool>("addTagInfos", true);
231  std::vector<edm::InputTag> emptyVInputTags;
232  iDesc.add<std::vector<edm::InputTag> >("tagInfoSources", emptyVInputTags);
233 
234  // jet energy corrections
235  iDesc.add<bool>("addJetCorrFactors", true);
236  iDesc.add<std::vector<edm::InputTag> >("jetCorrFactorsSource", emptyVInputTags);
237 
238  // btag discriminator tags
239  iDesc.add<bool>("addBTagInfo",true);
240  iDesc.add<bool>("addDiscriminators", true);
241  iDesc.add<std::vector<edm::InputTag> >("discriminatorSources", emptyVInputTags);
242 
243  // silent warning if false
244  iDesc.add<bool>("printWarning",true);
245 
246  // Check to see if the user wants to add user data
247  edm::ParameterSetDescription userDataPSet;
249  iDesc.addOptional("userData", userDataPSet);
250 
251  descriptions.add("PATJetUpdater", iDesc);
252 }
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 87 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(), tagInfoLabels_, tagInfoTokens_, userDataHelper_, and useUserData_.

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

Member Data Documentation

bool pat::PATJetUpdater::addBTagInfo_
private

Definition at line 52 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

bool pat::PATJetUpdater::addDiscriminators_
private

Definition at line 53 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

bool pat::PATJetUpdater::addJetCorrFactors_
private

Definition at line 49 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

bool pat::PATJetUpdater::addTagInfos_
private

Definition at line 57 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

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

Definition at line 56 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

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

Definition at line 54 of file PATJetUpdater.h.

Referenced by PATJetUpdater().

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

Definition at line 55 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

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

Definition at line 50 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 67 of file PATJetUpdater.h.

Referenced by produce().

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

Definition at line 62 of file PATJetUpdater.h.

Referenced by produce().

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

Definition at line 60 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

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

Definition at line 58 of file PATJetUpdater.h.

Referenced by PATJetUpdater().

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

Definition at line 59 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

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

Definition at line 65 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().

bool pat::PATJetUpdater::useUserData_
private

Definition at line 64 of file PATJetUpdater.h.

Referenced by PATJetUpdater(), and produce().