CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Attributes
RecoTauJetRegionProducer Class Reference
Inheritance diagram for RecoTauJetRegionProducer:
edm::stream::EDProducer<> edm::stream::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Types

typedef edm::AssociationMap< edm::OneToMany< std::vector< reco::PFJet >, std::vector< reco::PFCandidate >, unsigned int > > JetToPFCandidateAssociation
 
typedef edm::Association< reco::PFJetCollectionPFJetMatchMap
 
- 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
 
- Public Types inherited from edm::stream::EDProducerBase
typedef EDProducerAdaptorBase ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 

Public Member Functions

void produce (edm::Event &evt, const edm::EventSetup &es) override
 
 RecoTauJetRegionProducer (const edm::ParameterSet &pset)
 
 ~RecoTauJetRegionProducer () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
- Public Member Functions inherited from edm::stream::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducerBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
virtual ~ProducerBase () noexcept(false)
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Attributes

double deltaR2_
 
edm::InputTag inputJets_
 
edm::EDGetTokenT< reco::CandidateViewJets_token
 
double maxJetAbsEta_
 
double minJetPt_
 
std::string moduleLabel_
 
edm::EDGetTokenT< reco::PFCandidateCollectionpf_token
 
edm::EDGetTokenT< JetToPFCandidateAssociationpfCandAssocMap_token
 
edm::InputTag pfCandAssocMapSrc_
 
edm::InputTag pfCandSrc_
 
int verbosity_
 

Additional Inherited Members

- Static Public Member Functions inherited from edm::stream::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 32 of file RecoTauJetRegionProducer.cc.

Member Typedef Documentation

Definition at line 36 of file RecoTauJetRegionProducer.cc.

Definition at line 35 of file RecoTauJetRegionProducer.cc.

Constructor & Destructor Documentation

RecoTauJetRegionProducer::RecoTauJetRegionProducer ( const edm::ParameterSet pset)
explicit

Definition at line 60 of file RecoTauJetRegionProducer.cc.

References deltaR(), deltaR2_, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), inputJets_, Jets_token, maxJetAbsEta_, minJetPt_, pf_token, pfCandAssocMap_token, pfCandAssocMapSrc_, pfCandSrc_, and verbosity_.

61  : moduleLabel_(cfg.getParameter<std::string>("@module_label"))
62 {
63  inputJets_ = cfg.getParameter<edm::InputTag>("src");
64  pfCandSrc_ = cfg.getParameter<edm::InputTag>("pfCandSrc");
65  pfCandAssocMapSrc_ = cfg.getParameter<edm::InputTag>("pfCandAssocMapSrc");
66 
67  pf_token = consumes<reco::PFCandidateCollection>(pfCandSrc_);
68  Jets_token = consumes<reco::CandidateView>(inputJets_);
69  pfCandAssocMap_token = consumes<JetToPFCandidateAssociation>(pfCandAssocMapSrc_);
70 
71  double deltaR = cfg.getParameter<double>("deltaR");
72  deltaR2_ = deltaR*deltaR;
73  minJetPt_ = ( cfg.exists("minJetPt") ) ? cfg.getParameter<double>("minJetPt") : -1.0;
74  maxJetAbsEta_ = ( cfg.exists("maxJetAbsEta") ) ? cfg.getParameter<double>("maxJetAbsEta") : 99.0;
75 
76  verbosity_ = ( cfg.exists("verbosity") ) ?
77  cfg.getParameter<int>("verbosity") : 0;
78 
79  produces<reco::PFJetCollection>("jets");
80  produces<PFJetMatchMap>();
81 }
edm::EDGetTokenT< reco::PFCandidateCollection > pf_token
edm::EDGetTokenT< reco::CandidateView > Jets_token
edm::EDGetTokenT< JetToPFCandidateAssociation > pfCandAssocMap_token
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
RecoTauJetRegionProducer::~RecoTauJetRegionProducer ( )
inlineoverride

Definition at line 38 of file RecoTauJetRegionProducer.cc.

References produce().

38 {}

Member Function Documentation

void RecoTauJetRegionProducer::produce ( edm::Event evt,
const edm::EventSetup es 
)
override

Definition at line 83 of file RecoTauJetRegionProducer.cc.

References funct::abs(), reco::CompositePtrCandidate::addDaughter(), reco::CompositePtrCandidate::clearDaughters(), gather_cfg::cout, DEFINE_FWK_MODULE, reco::deltaR2(), deltaR2_, MillePedeFileConverter_cfg::e, edm::AssociationMap< Tag >::end(), edm::helper::Filler< Map >::fill(), objects.autophobj::filler, edm::AssociationMap< Tag >::find(), edm::Event::get(), edm::Event::getByToken(), reco::PFJet::getPFConstituents(), edm::RefVector< C, T, F >::id(), training_settings::idx, inputJets_, edm::helper::Filler< Map >::insert(), edm::HandleBase::isValid(), fwrapper::jets, Jets_token, edm::Ref< C, T, F >::key(), edm::InputTag::label(), maxJetAbsEta_, minJetPt_, moduleLabel_, eostools::move(), pf_token, pfCandAssocMap_token, pfCandAssocMapSrc_, pfCandSrc_, edm::Event::put(), edm::RefVector< C, T, F >::size(), groupFilesInBlocks::temp, and verbosity_.

Referenced by ~RecoTauJetRegionProducer().

84 {
85  if ( verbosity_ ) {
86  std::cout << "<RecoTauJetRegionProducer::produce (moduleLabel = " << moduleLabel_ << ")>:" << std::endl;
87  std::cout << " inputJets = " << inputJets_ << std::endl;
88  std::cout << " pfCandSrc = " << pfCandSrc_ << std::endl;
89  std::cout << " pfCandAssocMapSrc_ = " << pfCandAssocMapSrc_ << std::endl;
90  }
91 
93  evt.getByToken(pf_token, pfCandsHandle);
94 
95  // Build Ptrs for all the PFCandidates
96  typedef edm::Ptr<reco::PFCandidate> PFCandPtr;
97  std::vector<PFCandPtr> pfCands;
98  pfCands.reserve(pfCandsHandle->size());
99  for ( size_t icand = 0; icand < pfCandsHandle->size(); ++icand ) {
100  pfCands.push_back(PFCandPtr(pfCandsHandle, icand));
101  }
102 
103  // Get the jets
105  evt.getByToken(Jets_token, jetView);
106  // Convert to a vector of PFJetRefs
107  reco::PFJetRefVector jets = reco::tau::castView<reco::PFJetRefVector>(jetView);
108  size_t nJets = jets.size();
109 
110  // Get the association map matching jets to PFCandidates
111  // (needed for recinstruction of boosted taus)
113  std::vector<std::unordered_set<unsigned> > fastJetToPFCandMap;
114  if ( pfCandAssocMapSrc_.label() != "" ) {
115  evt.getByToken(pfCandAssocMap_token, jetToPFCandMap);
116  fastJetToPFCandMap.resize(nJets);
117  for ( size_t ijet = 0; ijet < nJets; ++ijet ) {
118  // Get a ref to jet
119  const reco::PFJetRef& jetRef = jets[ijet];
120  const auto& pfCandsMappedToJet = (*jetToPFCandMap)[jetRef];
121  for ( const auto& pfCandMappedToJet : pfCandsMappedToJet ) {
122  fastJetToPFCandMap[ijet].emplace(pfCandMappedToJet.key());
123  }
124  }
125  }
126 
127  // Get the original product, so we can match against it - otherwise the
128  // indices don't match up.
129  edm::ProductID originalId = jets.id();
131  size_t nOriginalJets = 0;
132  // We have to make sure that we have some selected jets, otherwise we don't
133  // actually have a valid product ID to the original jets.
134  if ( nJets ) {
135  try {
136  evt.get(originalId, originalJets);
137  } catch(const cms::Exception &e) {
138  edm::LogError("MissingOriginalCollection")
139  << "Can't get the original jets that made: " << inputJets_
140  << " that have product ID: " << originalId
141  << " from the event!!";
142  throw e;
143  }
144  nOriginalJets = originalJets->size();
145  }
146 
147  auto newJets = std::make_unique<reco::PFJetCollection>();
148 
149  // Keep track of the indices of the current jet and the old (original) jet
150  // -1 indicates no match.
151  std::vector<int> matchInfo(nOriginalJets, -1);
152  newJets->reserve(nJets);
153  size_t nNewJets = 0;
154  for ( size_t ijet = 0; ijet < nJets; ++ijet ) {
155  // Get a ref to jet
156  const reco::PFJetRef& jetRef = jets[ijet];
157  if(jetRef->pt() - minJetPt_ < 1e-5) continue;
158  if(std::abs(jetRef->eta()) - maxJetAbsEta_ > -1e-5) continue;
159  // Make an initial copy.
160  newJets->emplace_back(*jetRef);
161  reco::PFJet& newJet = newJets->back();
162  // Clear out all the constituents
163  newJet.clearDaughters();
164  // Loop over all the PFCands
165  for ( const auto& pfCand : pfCands ) {
166  bool isMappedToJet = false;
167  if ( jetToPFCandMap.isValid() ) {
168  auto temp = jetToPFCandMap->find(jetRef);
169  if( temp == jetToPFCandMap->end() ) {
170  edm::LogWarning("WeirdCandidateMap") << "Candidate map for jet " << jetRef.key() << " is empty!";
171  continue;
172  }
173  isMappedToJet = fastJetToPFCandMap[ijet].count(pfCand.key());
174  } else {
175  isMappedToJet = true;
176  }
177  if ( reco::deltaR2(*jetRef, *pfCand) < deltaR2_ && isMappedToJet ) newJet.addDaughter(pfCand);
178  }
179  if ( verbosity_ ) {
180  std::cout << "jet #" << ijet << ": Pt = " << jetRef->pt() << ", eta = " << jetRef->eta() << ", phi = " << jetRef->eta() << ","
181  << " mass = " << jetRef->mass() << ", area = " << jetRef->jetArea() << std::endl;
182  std::vector<reco::PFCandidatePtr> jetConstituents = newJet.getPFConstituents();
183  int idx = 0;
184  for ( std::vector<reco::PFCandidatePtr>::const_iterator jetConstituent = jetConstituents.begin();
185  jetConstituent != jetConstituents.end(); ++jetConstituent ) {
186  std::cout << " constituent #" << idx << ": Pt = " << (*jetConstituent)->pt() << ", eta = " << (*jetConstituent)->eta() << ", phi = " << (*jetConstituent)->phi() << std::endl;
187  }
188  }
189  // Match the index of the jet we just made to the index into the original
190  // collection.
191  //matchInfo[jetRef.key()] = ijet;
192  matchInfo[jetRef.key()] = nNewJets;
193  nNewJets++;
194  }
195 
196  // Put our new jets into the event
197  edm::OrphanHandle<reco::PFJetCollection> newJetsInEvent = evt.put(std::move(newJets), "jets");
198 
199  // Create a matching between original jets -> extra collection
200  auto matching = std::make_unique<PFJetMatchMap>(newJetsInEvent);
201  if ( nJets ) {
203  filler.insert(originalJets, matchInfo.begin(), matchInfo.end());
204  filler.fill();
205  }
206  evt.put(std::move(matching));
207 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
const_iterator end() const
last iterator over the map (read only)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
edm::EDGetTokenT< reco::PFCandidateCollection > pf_token
const_iterator find(const key_type &k) const
find element with specified reference key
key_type key() const
Accessor for product key.
Definition: Ref.h:265
Jets made from PFObjects.
Definition: PFJet.h:21
ProductID id() const
Accessor for product ID.
Definition: RefVector.h:122
edm::EDGetTokenT< reco::CandidateView > Jets_token
vector< PseudoJet > jets
edm::EDGetTokenT< JetToPFCandidateAssociation > pfCandAssocMap_token
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:341
bool isValid() const
Definition: HandleBase.h:74
helper::Filler< ValueMap< int > > Filler
Definition: ValueMap.h:169
void clearDaughters()
clear daughter references
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
Definition: deltaR.h:36
std::string const & label() const
Definition: InputTag.h:36
void addDaughter(const CandidatePtr &)
add a daughter via a reference
virtual std::vector< reco::PFCandidatePtr > getPFConstituents() const
get all constituents
Definition: PFJet.cc:52
size_type size() const
Size of the RefVector.
Definition: RefVector.h:107
def move(src, dest)
Definition: eostools.py:510

Member Data Documentation

double RecoTauJetRegionProducer::deltaR2_
private

Definition at line 55 of file RecoTauJetRegionProducer.cc.

Referenced by produce(), and RecoTauJetRegionProducer().

edm::InputTag RecoTauJetRegionProducer::inputJets_
private

Definition at line 45 of file RecoTauJetRegionProducer.cc.

Referenced by produce(), and RecoTauJetRegionProducer().

edm::EDGetTokenT<reco::CandidateView> RecoTauJetRegionProducer::Jets_token
private

Definition at line 50 of file RecoTauJetRegionProducer.cc.

Referenced by produce(), and RecoTauJetRegionProducer().

double RecoTauJetRegionProducer::maxJetAbsEta_
private

Definition at line 54 of file RecoTauJetRegionProducer.cc.

Referenced by produce(), and RecoTauJetRegionProducer().

double RecoTauJetRegionProducer::minJetPt_
private

Definition at line 53 of file RecoTauJetRegionProducer.cc.

Referenced by produce(), and RecoTauJetRegionProducer().

std::string RecoTauJetRegionProducer::moduleLabel_
private
edm::EDGetTokenT<reco::PFCandidateCollection> RecoTauJetRegionProducer::pf_token
private

Definition at line 49 of file RecoTauJetRegionProducer.cc.

Referenced by produce(), and RecoTauJetRegionProducer().

edm::EDGetTokenT<JetToPFCandidateAssociation> RecoTauJetRegionProducer::pfCandAssocMap_token
private

Definition at line 51 of file RecoTauJetRegionProducer.cc.

Referenced by produce(), and RecoTauJetRegionProducer().

edm::InputTag RecoTauJetRegionProducer::pfCandAssocMapSrc_
private

Definition at line 47 of file RecoTauJetRegionProducer.cc.

Referenced by produce(), and RecoTauJetRegionProducer().

edm::InputTag RecoTauJetRegionProducer::pfCandSrc_
private

Definition at line 46 of file RecoTauJetRegionProducer.cc.

Referenced by produce(), and RecoTauJetRegionProducer().

int RecoTauJetRegionProducer::verbosity_
private

Definition at line 57 of file RecoTauJetRegionProducer.cc.

Referenced by produce(), and RecoTauJetRegionProducer().