CMS 3D CMS Logo

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

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

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

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

Public Member Functions

 PATJetProducer (const edm::ParameterSet &iConfig)
 
void produce (edm::Event &iEvent, const edm::EventSetup &iSetup) override
 
 ~PATJetProducer () 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 addAssociatedTracks_
 
bool addBTagInfo_
 
bool addDiscriminators_
 
bool addEfficiencies_
 
bool addGenJetMatch_
 
bool addGenPartonMatch_
 
bool addJetCharge_
 
bool addJetCorrFactors_
 
bool addJetFlavourInfo_
 
bool addJetID_
 
bool addPartonJetMatch_
 
bool addResolutions_
 
bool addTagInfos_
 
GreaterByPt< CaloTowercaloPTComparator_
 
std::vector< std::string > discriminatorLabels_
 
std::vector< edm::InputTagdiscriminatorTags_
 
std::vector< edm::EDGetTokenT< reco::JetFloatAssociation::Container > > discriminatorTokens_
 
pat::helper::EfficiencyLoader efficiencyLoader_
 
bool embedCaloTowers_
 
bool embedGenJetMatch_
 
bool embedGenPartonMatch_
 
bool embedPFCandidates_
 
edm::EDGetTokenT< edm::Association< reco::GenJetCollection > > genJetToken_
 
edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > genPartonToken_
 
bool getJetMCFlavour_
 
edm::EDGetTokenT< reco::JetFloatAssociation::ContainerjetChargeToken_
 
std::vector< edm::EDGetTokenT< edm::ValueMap< JetCorrFactors > > > jetCorrFactorsTokens_
 
edm::EDGetTokenT< reco::JetFlavourInfoMatchingCollectionjetFlavourInfoToken_
 
edm::EDGetTokenT< reco::JetIDValueMapjetIDMapToken_
 
edm::EDGetTokenT< reco::JetFlavourMatchingCollectionjetPartonMapToken_
 
edm::EDGetTokenT< edm::View< reco::Jet > > jetsToken_
 
bool printWarning_
 
GreaterByPt< JetpTComparator_
 
pat::helper::KinResolutionsLoader resolutionLoader_
 
std::vector< std::string > tagInfoLabels_
 
std::vector< edm::InputTagtagInfoTags_
 
std::vector< edm::EDGetTokenT< edm::View< reco::BaseTagInfo > > > tagInfoTokens_
 
edm::EDGetTokenT< reco::JetTracksAssociation::ContainertrackAssociationToken_
 
bool useLegacyJetMCFlavour_
 
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 PATJetProducer produces analysis-level pat::Jet's starting from a collection of objects of JetType.

Author
Steven Lowette, Jeremy Andrea
Version
Id
PATJetProducer.h,v 1.26 2010/08/09 18:13:54 srappocc Exp

Definition at line 47 of file PATJetProducer.h.

Constructor & Destructor Documentation

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

Definition at line 42 of file PATJetProducer.cc.

References addAssociatedTracks_, addBTagInfo_, addDiscriminators_, addEfficiencies_, addGenJetMatch_, addGenPartonMatch_, addJetCharge_, addJetCorrFactors_, addJetFlavourInfo_, addJetID_, addPartonJetMatch_, addResolutions_, addTagInfos_, discriminatorLabels_, discriminatorTags_, discriminatorTokens_, efficiencyLoader_, embedCaloTowers_, embedGenJetMatch_, embedGenPartonMatch_, embedPFCandidates_, edm::ParameterSet::exists(), genJetToken_, genPartonToken_, getJetMCFlavour_, edm::ParameterSet::getParameter(), jetChargeToken_, jetCorrFactorsTokens_, jetFlavourInfoToken_, jetIDMapToken_, jetPartonMapToken_, jetsToken_, diffTwoXMLs::label, resolutionLoader_, AlCaHLTBitMon_QueryRunRegistry::string, GlobalPosition_Frontier_DevDB_cff::tag, tagInfoLabels_, tagInfoTags_, tagInfoTokens_, trackAssociationToken_, useLegacyJetMCFlavour_, userDataHelper_, useUserData_, and edm::vector_transform().

42  :
43  useUserData_(iConfig.exists("userData")),
44  printWarning_(true)
45 {
46  // initialize configurables
47  jetsToken_ = consumes<edm::View<reco::Jet> >(iConfig.getParameter<edm::InputTag>( "jetSource" ));
48  embedCaloTowers_ = false; // parameter is optional
49  if ( iConfig.exists("embedCaloTowers") ) {
50  embedCaloTowers_ = iConfig.getParameter<bool>( "embedCaloTowers" );
51  }
52  embedPFCandidates_ = iConfig.getParameter<bool>( "embedPFCandidates" );
53  getJetMCFlavour_ = iConfig.getParameter<bool>( "getJetMCFlavour" );
54  useLegacyJetMCFlavour_ = iConfig.getParameter<bool>( "useLegacyJetMCFlavour" );
55  addJetFlavourInfo_ = ( useLegacyJetMCFlavour_ ? false : iConfig.getParameter<bool>( "addJetFlavourInfo" ) );
56  if (getJetMCFlavour_ && useLegacyJetMCFlavour_)
57  jetPartonMapToken_ = consumes<reco::JetFlavourMatchingCollection>(iConfig.getParameter<edm::InputTag>( "JetPartonMapSource" ));
58  else if (getJetMCFlavour_ && !useLegacyJetMCFlavour_)
59  jetFlavourInfoToken_ = consumes<reco::JetFlavourInfoMatchingCollection>(iConfig.getParameter<edm::InputTag>( "JetFlavourInfoSource" ));
60  addGenPartonMatch_ = iConfig.getParameter<bool>( "addGenPartonMatch" );
61  embedGenPartonMatch_ = iConfig.getParameter<bool>( "embedGenPartonMatch" );
63  genPartonToken_ = consumes<edm::Association<reco::GenParticleCollection> >(iConfig.getParameter<edm::InputTag>( "genPartonMatch" ));
64  addGenJetMatch_ = iConfig.getParameter<bool>( "addGenJetMatch" );
65  embedGenJetMatch_ = iConfig.getParameter<bool>( "embedGenJetMatch" );
66  if (addGenJetMatch_)
67  genJetToken_ = consumes<edm::Association<reco::GenJetCollection> >(iConfig.getParameter<edm::InputTag>( "genJetMatch" ));
68  addPartonJetMatch_ = iConfig.getParameter<bool>( "addPartonJetMatch" );
69 // partonJetToken_ = mayConsume<reco::SomePartonJetType>(iConfig.getParameter<edm::InputTag>( "partonJetSource" ));
70  addJetCorrFactors_ = iConfig.getParameter<bool>( "addJetCorrFactors" );
71  if( addJetCorrFactors_ ) {
72  jetCorrFactorsTokens_ = edm::vector_transform(iConfig.getParameter<std::vector<edm::InputTag> >( "jetCorrFactorsSource" ), [this](edm::InputTag const & tag){return consumes<edm::ValueMap<JetCorrFactors> >(tag);});
73  }
74  addBTagInfo_ = iConfig.getParameter<bool>( "addBTagInfo" );
75  addDiscriminators_ = iConfig.getParameter<bool>( "addDiscriminators" );
76  discriminatorTags_ = iConfig.getParameter<std::vector<edm::InputTag> >( "discriminatorSources" );
77  discriminatorTokens_ = edm::vector_transform(discriminatorTags_, [this](edm::InputTag const & tag){return mayConsume<reco::JetFloatAssociation::Container>(tag);});
78  addTagInfos_ = iConfig.getParameter<bool>( "addTagInfos" );
79  tagInfoTags_ = iConfig.getParameter<std::vector<edm::InputTag> >( "tagInfoSources" );
80  tagInfoTokens_ =edm::vector_transform(tagInfoTags_, [this](edm::InputTag const & tag){return mayConsume<edm::View<reco::BaseTagInfo> >(tag);});
81  addAssociatedTracks_ = iConfig.getParameter<bool>( "addAssociatedTracks" );
82  if (addAssociatedTracks_)
83  trackAssociationToken_ = consumes<reco::JetTracksAssociation::Container>(iConfig.getParameter<edm::InputTag>( "trackAssociationSource" ));
84  addJetCharge_ = iConfig.getParameter<bool>( "addJetCharge" );
85  if (addJetCharge_)
86  jetChargeToken_ = consumes<reco::JetFloatAssociation::Container>(iConfig.getParameter<edm::InputTag>( "jetChargeSource" ));
87  addJetID_ = iConfig.getParameter<bool>( "addJetID");
88  if (addJetID_)
89  jetIDMapToken_ = consumes<reco::JetIDValueMap>(iConfig.getParameter<edm::InputTag>( "jetIDMap"));
90  // Efficiency configurables
91  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
92  if (addEfficiencies_) {
93  efficiencyLoader_ = pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"), consumesCollector());
94  }
95  // Resolution configurables
96  addResolutions_ = iConfig.getParameter<bool>("addResolutions");
97  if (addResolutions_) {
99  }
100  if (discriminatorTags_.empty()) {
101  addDiscriminators_ = false;
102  } else {
103  for (std::vector<edm::InputTag>::const_iterator it = discriminatorTags_.begin(), ed = discriminatorTags_.end(); it != ed; ++it) {
104  std::string label = it->label();
105  std::string::size_type pos = label.find("JetTags");
106  if ((pos != std::string::npos) && (pos != label.length() - 7)) {
107  label.erase(pos+7); // trim a tail after "JetTags"
108  }
109  if(!it->instance().empty()) {
110  label = (label+std::string(":")+it->instance());
111  }
112  discriminatorLabels_.push_back(label);
113  }
114  }
115  if (tagInfoTags_.empty()) {
116  addTagInfos_ = false;
117  } else {
118  for (std::vector<edm::InputTag>::const_iterator it = tagInfoTags_.begin(), ed = tagInfoTags_.end(); it != ed; ++it) {
119  std::string label = it->label();
120  std::string::size_type pos = label.find("TagInfos");
121  if ((pos != std::string::npos) && (pos != label.length() - 8)) {
122  label.erase(pos+8); // trim a tail after "TagInfos"
123  }
124  tagInfoLabels_.push_back(label);
125  }
126  }
127  if (!addBTagInfo_) { addDiscriminators_ = false; addTagInfos_ = false; }
128  // Check to see if the user wants to add user data
129  if ( useUserData_ ) {
130  userDataHelper_ = PATUserDataHelper<Jet>(iConfig.getParameter<edm::ParameterSet>("userData"), consumesCollector());
131  }
132  // produces vector of jets
133  produces<std::vector<Jet> >();
134  produces<reco::GenJetCollection> ("genJets");
135  produces<std::vector<CaloTower> > ("caloTowers");
136  produces<reco::PFCandidateCollection > ("pfCandidates");
137  produces<edm::OwnVector<reco::BaseTagInfo> > ("tagInfos");
138 }
T getParameter(std::string const &) const
pat::helper::EfficiencyLoader efficiencyLoader_
Assists in assimilating all pat::UserData into pat objects.
edm::EDGetTokenT< edm::View< reco::Jet > > jetsToken_
std::vector< edm::EDGetTokenT< edm::View< reco::BaseTagInfo > > > tagInfoTokens_
edm::EDGetTokenT< reco::JetTracksAssociation::Container > trackAssociationToken_
std::vector< std::string > tagInfoLabels_
std::vector< edm::EDGetTokenT< edm::ValueMap< JetCorrFactors > > > jetCorrFactorsTokens_
std::vector< edm::InputTag > tagInfoTags_
pat::helper::KinResolutionsLoader resolutionLoader_
std::vector< std::string > discriminatorLabels_
bool exists(std::string const &parameterName) const
checks if a parameter exists
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
edm::EDGetTokenT< reco::JetFlavourInfoMatchingCollection > jetFlavourInfoToken_
uint16_t size_type
edm::EDGetTokenT< reco::JetFloatAssociation::Container > jetChargeToken_
edm::EDGetTokenT< reco::JetIDValueMap > jetIDMapToken_
std::vector< edm::InputTag > discriminatorTags_
pat::PATUserDataHelper< pat::Jet > userDataHelper_
edm::EDGetTokenT< reco::JetFlavourMatchingCollection > jetPartonMapToken_
edm::EDGetTokenT< edm::Association< reco::GenJetCollection > > genJetToken_
std::vector< edm::EDGetTokenT< reco::JetFloatAssociation::Container > > discriminatorTokens_
edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > genPartonToken_
PATJetProducer::~PATJetProducer ( )
override

Definition at line 141 of file PATJetProducer.cc.

141  {
142 
143 }

Member Function Documentation

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

Definition at line 431 of file PATJetProducer.cc.

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

432 {
434  iDesc.setComment("PAT jet producer module");
435 
436  // input source
437  iDesc.add<edm::InputTag>("jetSource", edm::InputTag("no default"))->setComment("input collection");
438 
439  // embedding
440  iDesc.addOptional<bool>("embedCaloTowers", false)->setComment("embed external CaloTowers (not to be used on AOD input)");
441  iDesc.add<bool>("embedPFCandidates", true)->setComment("embed external PFCandidates");
442 
443  // MC matching configurables
444  iDesc.add<bool>("addGenPartonMatch", true)->setComment("add MC matching");
445  iDesc.add<bool>("embedGenPartonMatch", false)->setComment("embed MC matched MC information");
446  iDesc.add<edm::InputTag>("genPartonMatch", edm::InputTag())->setComment("input with MC match information");
447 
448  iDesc.add<bool>("addGenJetMatch", true)->setComment("add MC matching");
449  iDesc.add<bool>("embedGenJetMatch", false)->setComment("embed MC matched MC information");
450  iDesc.add<edm::InputTag>("genJetMatch", edm::InputTag())->setComment("input with MC match information");
451 
452  iDesc.add<bool>("addJetCharge", true);
453  iDesc.add<edm::InputTag>("jetChargeSource", edm::InputTag("patJetCharge"));
454 
455  // jet id
456  iDesc.add<bool>("addJetID", true)->setComment("Add jet ID information");
457  iDesc.add<edm::InputTag>("jetIDMap", edm::InputTag())->setComment("jet id map");
458 
459  iDesc.add<bool>("addPartonJetMatch", false);
460  iDesc.add<edm::InputTag>("partonJetSource", edm::InputTag("NOT IMPLEMENTED"));
461 
462  // track association
463  iDesc.add<bool>("addAssociatedTracks", true);
464  iDesc.add<edm::InputTag>("trackAssociationSource", edm::InputTag("ak4JTA"));
465 
466  // tag info
467  iDesc.add<bool>("addTagInfos", true);
468  std::vector<edm::InputTag> emptyVInputTags;
469  iDesc.add<std::vector<edm::InputTag> >("tagInfoSources", emptyVInputTags);
470 
471  // jet energy corrections
472  iDesc.add<bool>("addJetCorrFactors", true);
473  iDesc.add<std::vector<edm::InputTag> >("jetCorrFactorsSource", emptyVInputTags);
474 
475  // btag discriminator tags
476  iDesc.add<bool>("addBTagInfo",true);
477  iDesc.add<bool>("addDiscriminators", true);
478  iDesc.add<std::vector<edm::InputTag> >("discriminatorSources", emptyVInputTags);
479 
480  // jet flavour idetification configurables
481  iDesc.add<bool>("getJetMCFlavour", true);
482  iDesc.add<bool>("useLegacyJetMCFlavour", false);
483  iDesc.add<bool>("addJetFlavourInfo", false);
484  iDesc.add<edm::InputTag>("JetPartonMapSource", edm::InputTag("jetFlavourAssociationLegacy"));
485  iDesc.add<edm::InputTag>("JetFlavourInfoSource", edm::InputTag("jetFlavourAssociation"));
486 
488 
489  // Efficiency configurables
490  edm::ParameterSetDescription efficienciesPSet;
491  efficienciesPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
492  iDesc.add("efficiencies", efficienciesPSet);
493  iDesc.add<bool>("addEfficiencies", false);
494 
495  // Check to see if the user wants to add user data
496  edm::ParameterSetDescription userDataPSet;
498  iDesc.addOptional("userData", userDataPSet);
499 
500  descriptions.add("PATJetProducer", iDesc);
501 }
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
void setAllowAnything()
allow any parameter label/value pairs
static void fillDescription(edm::ParameterSetDescription &iDesc)
void setComment(std::string const &value)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static void fillDescription(edm::ParameterSetDescription &iDesc)
Method for documentation and validation of PSet.
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void PATJetProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
override

Definition at line 146 of file PATJetProducer.cc.

References addAssociatedTracks_, pat::Jet::addBDiscriminatorPair(), addBTagInfo_, addDiscriminators_, addGenJetMatch_, addGenPartonMatch_, pat::Jet::addJECFactors(), addJetCharge_, addJetCorrFactors_, addJetFlavourInfo_, addJetID_, addPartonJetMatch_, pat::Jet::addTagInfo(), addTagInfos_, edm::View< T >::begin(), reco::BaseTagInfo::clone(), discriminatorLabels_, discriminatorTokens_, efficiencyLoader_, embedCaloTowers_, embedGenPartonMatch_, embedPFCandidates_, pat::helper::EfficiencyLoader::enabled(), pat::helper::KinResolutionsLoader::enabled(), edm::View< T >::end(), spr::find(), jetProducer_cfi::genJetMatch, genJetToken_, genPartonToken_, edm::RefToBase< T >::get(), edm::Event::getByToken(), reco::CaloJet::getCaloConstituents(), reco::JPTJet::getCaloJetRef(), getJetMCFlavour_, reco::PFJet::getPFConstituents(), edm::Event::getRefBeforePut(), mps_fire::i, training_settings::idx, pat::Jet::initializeJEC(), edm::Ref< C, T, F >::isAvailable(), pat::Jet::isCaloJet(), pat::Jet::isJPTJet(), edm::Ptr< T >::isNonnull(), edm::Ref< C, T, F >::isNonnull(), pat::Jet::isPFJet(), edm::EventBase::isRealData(), metsig::jet, jetChargeToken_, jetCorrFactorsTokens_, jetFlavourInfoToken_, jets_cff::jetId, jetIDMapToken_, jetPartonMapToken_, fwrapper::jets, jetsToken_, gen::k, jets_cff::levels, match(), eostools::move(), pat::helper::EfficiencyLoader::newEvent(), pat::helper::KinResolutionsLoader::newEvent(), hemisphereProducer_cfi::patJets, printWarning_, pTComparator_, edm::View< T >::ptrAt(), edm::Event::put(), resolutionLoader_, pat::Jet::setAssociatedTracks(), pat::Jet::setCaloTowers(), pat::helper::EfficiencyLoader::setEfficiencies(), pat::Jet::setGenJetRef(), pat::Jet::setGenParton(), pat::Jet::setHadronFlavour(), pat::Jet::setJetCharge(), pat::Jet::setJetFlavourInfo(), pat::Jet::setJetID(), pat::Jet::setPartonFlavour(), pat::Jet::setPFCandidates(), pat::helper::KinResolutionsLoader::setResolutions(), edm::View< T >::size(), tagInfoLabels_, tagInfoTokens_, trackAssociationToken_, useLegacyJetMCFlavour_, userDataHelper_, and useUserData_.

147 {
148  // check whether dealing with MC or real data
149  if (iEvent.isRealData()){
150  getJetMCFlavour_ = false;
151  useLegacyJetMCFlavour_ = false;
152  addJetFlavourInfo_ = false;
153  addGenPartonMatch_ = false;
154  addGenJetMatch_ = false;
155  addPartonJetMatch_ = false;
156  }
157 
158  // Get the vector of jets
160  iEvent.getByToken(jetsToken_, jets);
161 
163  if (resolutionLoader_.enabled()) resolutionLoader_.newEvent(iEvent, iSetup);
164 
165  // for jet flavour
169  else if (getJetMCFlavour_ && !useLegacyJetMCFlavour_) iEvent.getByToken (jetFlavourInfoToken_, jetFlavInfoMatch);
170 
171  // Get the vector of generated particles from the event if needed
173  if (addGenPartonMatch_) iEvent.getByToken(genPartonToken_, partonMatch);
174  // Get the vector of GenJets from the event if needed
176  if (addGenJetMatch_) iEvent.getByToken(genJetToken_, genJetMatch);
177 /* TO BE IMPLEMENTED FOR >= 1_5_X
178  // Get the vector of PartonJets from the event if needed
179  edm::Handle<edm::View<reco::SomePartonJetType> > partonJets;
180  if (addPartonJetMatch_) iEvent.getByToken(partonJetToken_, partonJets);
181 */
182 
183  // read in the jet correction factors ValueMap
184  std::vector<edm::ValueMap<JetCorrFactors> > jetCorrs;
185  if (addJetCorrFactors_) {
186  for ( size_t i = 0; i < jetCorrFactorsTokens_.size(); ++i ) {
188  iEvent.getByToken(jetCorrFactorsTokens_[i], jetCorr);
189  jetCorrs.push_back( *jetCorr );
190  }
191  }
192 
193  // Get the vector of jet tags with b-tagging info
194  std::vector<edm::Handle<reco::JetFloatAssociation::Container> > jetDiscriminators;
196  jetDiscriminators.resize(discriminatorTokens_.size());
197  for (size_t i = 0; i < discriminatorTokens_.size(); ++i) {
198  iEvent.getByToken(discriminatorTokens_[i], jetDiscriminators[i]);
199  }
200  }
201  std::vector<edm::Handle<edm::View<reco::BaseTagInfo> > > jetTagInfos;
202  if (addBTagInfo_ && addTagInfos_) {
203  jetTagInfos.resize(tagInfoTokens_.size());
204  for (size_t i = 0; i < tagInfoTokens_.size(); ++i) {
205  iEvent.getByToken(tagInfoTokens_[i], jetTagInfos[i]);
206  }
207  }
208 
209  // tracks Jet Track Association
213  if (addJetCharge_) iEvent.getByToken(jetChargeToken_, hJetChargeAss);
214 
215  // jet ID handle
217  if ( addJetID_ ) iEvent.getByToken( jetIDMapToken_, hJetIDMap );
218 
219  // loop over jets
220  auto patJets = std::make_unique<std::vector<Jet>>();
221 
222  auto genJetsOut = std::make_unique<reco::GenJetCollection>();
223  auto caloTowersOut = std::make_unique<std::vector<CaloTower>>();
224  auto pfCandidatesOut = std::make_unique<reco::PFCandidateCollection>();
225  auto tagInfosOut = std::make_unique<edm::OwnVector<reco::BaseTagInfo>>();
226 
227 
229  edm::RefProd<std::vector<CaloTower> > h_caloTowersOut = iEvent.getRefBeforePut<std::vector<CaloTower> > ( "caloTowers" );
230  edm::RefProd<reco::PFCandidateCollection > h_pfCandidatesOut = iEvent.getRefBeforePut<reco::PFCandidateCollection > ( "pfCandidates" );
232 
233  for (edm::View<reco::Jet>::const_iterator itJet = jets->begin(); itJet != jets->end(); itJet++) {
234 
235  // construct the Jet from the ref -> save ref to original object
236  unsigned int idx = itJet - jets->begin();
237  edm::RefToBase<reco::Jet> jetRef = jets->refAt(idx);
238  edm::Ptr<reco::Jet> jetPtr = jets->ptrAt(idx);
239  Jet ajet(jetRef);
240 
241  // add the FwdPtrs to the CaloTowers
242  if ( (ajet.isCaloJet() || ajet.isJPTJet() ) && embedCaloTowers_) {
243  const reco::CaloJet *cj = nullptr;
244  const reco::JPTJet * jptj = nullptr;
245  if ( ajet.isCaloJet()) cj = dynamic_cast<const reco::CaloJet *>(jetRef.get());
246  else {
247  jptj = dynamic_cast<const reco::JPTJet *>(jetRef.get() );
248  cj = dynamic_cast<const reco::CaloJet *>(jptj->getCaloJetRef().get() );
249  }
251  std::vector< CaloTowerPtr > itowers = cj->getCaloConstituents();
252  for ( std::vector<CaloTowerPtr>::const_iterator towBegin = itowers.begin(), towEnd = itowers.end(), itow = towBegin; itow != towEnd; ++itow ) {
253  if( itow->isAvailable() && itow->isNonnull() ){
254  caloTowersOut->push_back( **itow );
255  // set the "forward" ref to the thinned collection
256  edm::Ref<std::vector<CaloTower> > caloTowerRef( h_caloTowersOut, caloTowersOut->size() - 1);
257  edm::Ptr<CaloTower> caloForwardRef ( h_caloTowersOut.id(), caloTowerRef.key(), h_caloTowersOut.productGetter() );
258  // set the "backward" ref to the original collection for association
259  edm::Ptr<CaloTower> caloBackRef ( *itow );
260  // add to the list of FwdPtr's
261  itowersRef.push_back( pat::CaloTowerFwdPtrCollection::value_type ( caloForwardRef, caloBackRef ) );
262  }
263  }
264  ajet.setCaloTowers( itowersRef );
265  }
266 
267  // add the FwdPtrs to the PFCandidates
268  if (ajet.isPFJet() && embedPFCandidates_) {
269  const reco::PFJet *cj = dynamic_cast<const reco::PFJet *>(jetRef.get());
270  pat::PFCandidateFwdPtrCollection iparticlesRef;
271  std::vector< reco::PFCandidatePtr > iparticles = cj->getPFConstituents();
272  for ( std::vector<reco::PFCandidatePtr>::const_iterator partBegin = iparticles.begin(),
273  partEnd = iparticles.end(), ipart = partBegin;
274  ipart != partEnd; ++ipart ) {
275  pfCandidatesOut->push_back( **ipart );
276  // set the "forward" ref to the thinned collection
277  edm::Ref<reco::PFCandidateCollection> pfCollectionRef( h_pfCandidatesOut, pfCandidatesOut->size() - 1);
278  edm::Ptr<reco::PFCandidate> pfForwardRef ( h_pfCandidatesOut.id(), pfCollectionRef.key(), h_pfCandidatesOut.productGetter() );
279  // set the "backward" ref to the original collection for association
280  edm::Ptr<reco::PFCandidate> pfBackRef ( *ipart );
281  // add to the list of FwdPtr's
282  iparticlesRef.push_back( pat::PFCandidateFwdPtrCollection::value_type ( pfForwardRef, pfBackRef ) );
283  }
284  ajet.setPFCandidates( iparticlesRef );
285  }
286 
287  if (addJetCorrFactors_) {
288  // add additional JetCorrs to the jet
289  for ( unsigned int i=0; i<jetCorrFactorsTokens_.size(); ++i ) {
290  const JetCorrFactors& jcf = jetCorrs[i][jetRef];
291  // uncomment for debugging
292  // jcf.print();
293  ajet.addJECFactors(jcf);
294  }
295  std::vector<std::string> levels = jetCorrs[0][jetRef].correctionLabels();
296  if(std::find(levels.begin(), levels.end(), "L2L3Residual")!=levels.end()){
297  ajet.initializeJEC(jetCorrs[0][jetRef].jecLevel("L2L3Residual"));
298  }
299  else if(std::find(levels.begin(), levels.end(), "L3Absolute")!=levels.end()){
300  ajet.initializeJEC(jetCorrs[0][jetRef].jecLevel("L3Absolute"));
301  }
302  else{
303  ajet.initializeJEC(jetCorrs[0][jetRef].jecLevel("Uncorrected"));
304  if(printWarning_){
305  edm::LogWarning("L3Absolute not found") << "L2L3Residual and L3Absolute are not part of the jetCorrFactors\n"
306  << "of module " << jetCorrs[0][jetRef].jecSet() << ". Jets will remain"
307  << " uncorrected."; printWarning_=false;
308  }
309  }
310  }
311 
312  // get the MC flavour information for this jet
314  ajet.setPartonFlavour( (*jetFlavMatch)[edm::RefToBase<reco::Jet>(jetRef)].getFlavour() );
315  }
317  if ( addJetFlavourInfo_ ) ajet.setJetFlavourInfo( (*jetFlavInfoMatch)[edm::RefToBase<reco::Jet>(jetRef)] );
318  else
319  {
320  ajet.setPartonFlavour( (*jetFlavInfoMatch)[edm::RefToBase<reco::Jet>(jetRef)].getPartonFlavour() );
321  ajet.setHadronFlavour( (*jetFlavInfoMatch)[edm::RefToBase<reco::Jet>(jetRef)].getHadronFlavour() );
322  }
323  }
324  // store the match to the generated partons
325  if (addGenPartonMatch_) {
326  reco::GenParticleRef parton = (*partonMatch)[jetRef];
327  if (parton.isNonnull() && parton.isAvailable()) {
328  ajet.setGenParton(parton, embedGenPartonMatch_);
329  } // leave empty if no match found
330  }
331  // store the match to the GenJets
332  if (addGenJetMatch_) {
333  reco::GenJetRef genjet = (*genJetMatch)[jetRef];
334  if (genjet.isNonnull() && genjet.isAvailable()) {
335  genJetsOut->push_back( *genjet );
336  // set the "forward" ref to the thinned collection
337  edm::Ref<reco::GenJetCollection > genForwardRef ( h_genJetsOut, genJetsOut->size() - 1 );
338  // set the "backward" ref to the original collection
339  const edm::Ref<reco::GenJetCollection >& genBackRef ( genjet );
340  // make the FwdPtr
341  edm::FwdRef<reco::GenJetCollection > genjetFwdRef ( genForwardRef, genBackRef );
342  ajet.setGenJetRef(genjetFwdRef );
343  } // leave empty if no match found
344  }
345 
346  if (efficiencyLoader_.enabled()) {
347  efficiencyLoader_.setEfficiencies( ajet, jetRef );
348  }
349 
350  // IMPORTANT: DO THIS AFTER JES CORRECTIONS
351  if (resolutionLoader_.enabled()) {
353  }
354 
355  // TO BE IMPLEMENTED FOR >=1_5_X: do the PartonJet matching
356  if (addPartonJetMatch_) {
357  }
358 
359  // add b-tag info if available & required
360  if (addBTagInfo_) {
361  if (addDiscriminators_) {
362  for (size_t k=0; k<jetDiscriminators.size(); ++k) {
363  float value = (*jetDiscriminators[k])[jetRef];
364  ajet.addBDiscriminatorPair(std::make_pair(discriminatorLabels_[k], value));
365  }
366  }
367  if (addTagInfos_) {
368  for (size_t k=0; k<jetTagInfos.size(); ++k) {
369  const edm::View<reco::BaseTagInfo> & taginfos = *jetTagInfos[k];
370  // This is not associative, so we have to search the jet
372  // Try first by 'same index'
373  if ((idx < taginfos.size()) && (taginfos[idx].jet() == jetRef)) {
374  match = taginfos.ptrAt(idx);
375  } else {
376  // otherwise fail back to a simple search
377  for (edm::View<reco::BaseTagInfo>::const_iterator itTI = taginfos.begin(), edTI = taginfos.end(); itTI != edTI; ++itTI) {
378  if (itTI->jet() == jetRef) { match = taginfos.ptrAt( itTI - taginfos.begin() ); break; }
379  }
380  }
381  if (match.isNonnull()) {
382  tagInfosOut->push_back( match->clone() );
383  // set the "forward" ptr to the thinned collection
384  edm::Ptr<reco::BaseTagInfo> tagInfoForwardPtr ( h_tagInfosOut.id(), &tagInfosOut->back(), tagInfosOut->size() - 1 );
385  // set the "backward" ptr to the original collection for association
386  const edm::Ptr<reco::BaseTagInfo>& tagInfoBackPtr ( match );
387  // make FwdPtr
388  TagInfoFwdPtrCollection::value_type tagInfoFwdPtr( tagInfoForwardPtr, tagInfoBackPtr ) ;
389  ajet.addTagInfo(tagInfoLabels_[k], tagInfoFwdPtr );
390  }
391  }
392  }
393  }
394 
395  if (addAssociatedTracks_) ajet.setAssociatedTracks( (*hTrackAss)[jetRef] );
396 
397  if (addJetCharge_) ajet.setJetCharge( (*hJetChargeAss)[jetRef] );
398 
399  // add jet ID for calo jets
400  if (addJetID_ && ajet.isCaloJet() ) {
401  reco::JetID jetId = (*hJetIDMap)[ jetRef ];
402  ajet.setJetID( jetId );
403  }
404  // add jet ID jpt jets
405  else if ( addJetID_ && ajet.isJPTJet() ){
406  const reco::JPTJet *jptj = dynamic_cast<const reco::JPTJet *>(jetRef.get());
407  reco::JetID jetId = (*hJetIDMap)[ jptj->getCaloJetRef() ];
408  ajet.setJetID( jetId );
409  }
410  if ( useUserData_ ) {
411  userDataHelper_.add( ajet, iEvent, iSetup );
412  }
413  patJets->push_back(ajet);
414  }
415 
416  // sort jets in pt
417  std::sort(patJets->begin(), patJets->end(), pTComparator_);
418 
419  // put genEvt in Event
420  iEvent.put(std::move(patJets));
421 
422  iEvent.put(std::move(genJetsOut), "genJets" );
423  iEvent.put(std::move(caloTowersOut), "caloTowers" );
424  iEvent.put(std::move(pfCandidatesOut), "pfCandidates" );
425  iEvent.put(std::move(tagInfosOut), "tagInfos" );
426 
427 
428 }
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
bool isAvailable() const
Definition: Ref.h:577
value_type const * get() const
Definition: RefToBase.h:234
pat::helper::EfficiencyLoader efficiencyLoader_
void newEvent(const edm::Event &event)
To be called for each new event, reads in the ValueMaps for efficiencies.
edm::EDGetTokenT< edm::View< reco::Jet > > jetsToken_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
std::vector< edm::EDGetTokenT< edm::View< reco::BaseTagInfo > > > tagInfoTokens_
edm::EDGetTokenT< reco::JetTracksAssociation::Container > trackAssociationToken_
Jets made from CaloTowers.
Definition: CaloJet.h:29
virtual BaseTagInfo * clone(void) const
clone
Definition: BaseTagInfo.h:19
std::vector< std::string > tagInfoLabels_
std::vector< edm::EDGetTokenT< edm::ValueMap< JetCorrFactors > > > jetCorrFactorsTokens_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
Ptr< value_type > ptrAt(size_type i) const
pat::helper::KinResolutionsLoader resolutionLoader_
std::vector< GenJet > GenJetCollection
collection of GenJet objects
std::vector< std::string > discriminatorLabels_
size_type size() const
const edm::RefToBase< reco::Jet > & getCaloJetRef() const
Definition: JPTJet.h:130
Jet ID object.
Definition: JetID.h:16
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
virtual std::vector< CaloTowerPtr > getCaloConstituents() const
get all constituents
Definition: CaloJet.cc:93
void setResolutions(pat::PATObject< T > &obj) const
Sets the efficiencies for this object, using the reference to the original objects.
edm::EDGetTokenT< reco::JetFlavourInfoMatchingCollection > jetFlavourInfoToken_
bool isRealData() const
Definition: EventBase.h:64
Jets made from PFObjects.
Definition: PFJet.h:21
GreaterByPt< Jet > pTComparator_
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
edm::EDGetTokenT< reco::JetFloatAssociation::Container > jetChargeToken_
const_iterator begin() const
Definition: Jet.py:1
void newEvent(const edm::Event &event, const edm::EventSetup &setup)
To be called for each new event, reads in the EventSetup object.
Jets made from CaloJets corrected for ZSP and tracks.
Definition: JPTJet.h:29
Class for the storage of jet correction factors.
vector< PseudoJet > jets
edm::EDGetTokenT< reco::JetIDValueMap > jetIDMapToken_
genJetMatch
switch on/off embedding of matched genJet&#39;s
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]
pat::PATUserDataHelper< pat::Jet > userDataHelper_
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
edm::EDGetTokenT< reco::JetFlavourMatchingCollection > jetPartonMapToken_
std::vector< edm::FwdPtr< CaloTower > > CaloTowerFwdPtrCollection
Definition: Jet.h:76
std::vector< edm::FwdPtr< reco::PFCandidate > > PFCandidateFwdPtrCollection
Definition: Jet.h:75
void setEfficiencies(pat::PATObject< T > &obj, const R &originalRef) const
Sets the efficiencies for this object, using the reference to the original objects.
edm::EDGetTokenT< edm::Association< reco::GenJetCollection > > genJetToken_
std::vector< edm::EDGetTokenT< reco::JetFloatAssociation::Container > > discriminatorTokens_
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > genPartonToken_
virtual std::vector< reco::PFCandidatePtr > getPFConstituents() const
get all constituents
Definition: PFJet.cc:52
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
def move(src, dest)
Definition: eostools.py:510

Member Data Documentation

bool pat::PATJetProducer::addAssociatedTracks_
private

Definition at line 89 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

bool pat::PATJetProducer::addBTagInfo_
private

Definition at line 80 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

bool pat::PATJetProducer::addDiscriminators_
private

Definition at line 81 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

bool pat::PATJetProducer::addEfficiencies_
private

Definition at line 99 of file PATJetProducer.h.

Referenced by PATJetProducer().

bool pat::PATJetProducer::addGenJetMatch_
private

Definition at line 72 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

bool pat::PATJetProducer::addGenPartonMatch_
private

Definition at line 69 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

bool pat::PATJetProducer::addJetCharge_
private

Definition at line 91 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

bool pat::PATJetProducer::addJetCorrFactors_
private

Definition at line 77 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

bool pat::PATJetProducer::addJetFlavourInfo_
private

Definition at line 66 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

bool pat::PATJetProducer::addJetID_
private

Definition at line 93 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

bool pat::PATJetProducer::addPartonJetMatch_
private

Definition at line 75 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

bool pat::PATJetProducer::addResolutions_
private

Definition at line 102 of file PATJetProducer.h.

Referenced by PATJetProducer().

bool pat::PATJetProducer::addTagInfos_
private

Definition at line 85 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

GreaterByPt<CaloTower> pat::PATJetProducer::caloPTComparator_
private

Definition at line 97 of file PATJetProducer.h.

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

Definition at line 84 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

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

Definition at line 82 of file PATJetProducer.h.

Referenced by PATJetProducer().

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

Definition at line 83 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

pat::helper::EfficiencyLoader pat::PATJetProducer::efficiencyLoader_
private

Definition at line 100 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

bool pat::PATJetProducer::embedCaloTowers_
private

Definition at line 62 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

bool pat::PATJetProducer::embedGenJetMatch_
private

Definition at line 73 of file PATJetProducer.h.

Referenced by PATJetProducer().

bool pat::PATJetProducer::embedGenPartonMatch_
private

Definition at line 70 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

bool pat::PATJetProducer::embedPFCandidates_
private

Definition at line 63 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

edm::EDGetTokenT<edm::Association<reco::GenJetCollection> > pat::PATJetProducer::genJetToken_
private

Definition at line 74 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

edm::EDGetTokenT<edm::Association<reco::GenParticleCollection> > pat::PATJetProducer::genPartonToken_
private

Definition at line 71 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

bool pat::PATJetProducer::getJetMCFlavour_
private

Definition at line 64 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

edm::EDGetTokenT<reco::JetFloatAssociation::Container> pat::PATJetProducer::jetChargeToken_
private

Definition at line 92 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

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

Definition at line 78 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

edm::EDGetTokenT<reco::JetFlavourInfoMatchingCollection> pat::PATJetProducer::jetFlavourInfoToken_
private

Definition at line 68 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

edm::EDGetTokenT<reco::JetIDValueMap> pat::PATJetProducer::jetIDMapToken_
private

Definition at line 94 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

edm::EDGetTokenT<reco::JetFlavourMatchingCollection> pat::PATJetProducer::jetPartonMapToken_
private

Definition at line 67 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

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

Definition at line 61 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

bool pat::PATJetProducer::printWarning_
private

Definition at line 108 of file PATJetProducer.h.

Referenced by produce().

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

Definition at line 96 of file PATJetProducer.h.

Referenced by produce().

pat::helper::KinResolutionsLoader pat::PATJetProducer::resolutionLoader_
private

Definition at line 103 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

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

Definition at line 88 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

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

Definition at line 86 of file PATJetProducer.h.

Referenced by PATJetProducer().

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

Definition at line 87 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

edm::EDGetTokenT<reco::JetTracksAssociation::Container> pat::PATJetProducer::trackAssociationToken_
private

Definition at line 90 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

bool pat::PATJetProducer::useLegacyJetMCFlavour_
private

Definition at line 65 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

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

Definition at line 106 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().

bool pat::PATJetProducer::useUserData_
private

Definition at line 105 of file PATJetProducer.h.

Referenced by PATJetProducer(), and produce().