test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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::PFJetCollection
PFJetMatchMap
 
- 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, GlobalCache
LuminosityBlockContext
 
typedef
CacheTypes::LuminosityBlockSummaryCache 
LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache,
GlobalCache
RunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 
- Public Types inherited from edm::stream::EDProducerBase
typedef EDProducerAdaptorBase ModuleType
 
- Public Types inherited from edm::ProducerBase
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 ()
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
- Public Member Functions inherited from edm::stream::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducerBase ()
 
- 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 ()
 
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, std::unordered_multimap< std::string, edm::ProductResolverIndex > const &iIndicies, std::string const &moduleLabel)
 
virtual ~ProducerBase () noexcept(false)
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 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 & 
itemsToGetFromEvent () 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
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Attributes

double deltaR2_
 
edm::InputTag inputJets_
 
edm::EDGetTokenT
< reco::CandidateView
Jets_token
 
std::string moduleLabel_
 
edm::EDGetTokenT
< reco::PFCandidateCollection
pf_token
 
edm::EDGetTokenT
< JetToPFCandidateAssociation
pfCandAssocMap_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 58 of file RecoTauJetRegionProducer.cc.

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

59  : moduleLabel_(cfg.getParameter<std::string>("@module_label"))
60 {
61  inputJets_ = cfg.getParameter<edm::InputTag>("src");
62  pfCandSrc_ = cfg.getParameter<edm::InputTag>("pfCandSrc");
63  pfCandAssocMapSrc_ = cfg.getParameter<edm::InputTag>("pfCandAssocMapSrc");
64 
65  pf_token = consumes<reco::PFCandidateCollection>(pfCandSrc_);
66  Jets_token = consumes<reco::CandidateView>(inputJets_);
67  pfCandAssocMap_token = consumes<JetToPFCandidateAssociation>(pfCandAssocMapSrc_);
68 
69  double deltaR = cfg.getParameter<double>("deltaR");
70  deltaR2_ = deltaR*deltaR;
71 
72  verbosity_ = ( cfg.exists("verbosity") ) ?
73  cfg.getParameter<int>("verbosity") : 0;
74 
75  produces<reco::PFJetCollection>("jets");
76  produces<PFJetMatchMap>();
77 }
tuple cfg
Definition: looper.py:293
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 ( )
inline

Definition at line 38 of file RecoTauJetRegionProducer.cc.

38 {}

Member Function Documentation

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

Implements edm::stream::EDProducerBase.

Definition at line 79 of file RecoTauJetRegionProducer.cc.

References reco::CompositePtrCandidate::addDaughter(), edm::RefVector< C, T, F >::begin(), reco::CompositePtrCandidate::clearDaughters(), gather_cfg::cout, reco::deltaR2(), deltaR2_, alignCSCRings::e, edm::RefVector< C, T, F >::end(), edm::helper::Filler< Map >::fill(), edm::Event::get(), edm::Event::getByToken(), reco::PFJet::getPFConstituents(), edm::RefVector< C, T, F >::id(), inputJets_, edm::helper::Filler< Map >::insert(), fwrapper::jets, Jets_token, edm::Ref< C, T, F >::key(), edm::InputTag::label(), moduleLabel_, eostools::move(), pf_token, pfCandAssocMap_token, pfCandAssocMapSrc_, pfCandSrc_, edm::Event::put(), edm::RefVector< C, T, F >::size(), groupFilesInBlocks::temp, and verbosity_.

80 {
81  if ( verbosity_ ) {
82  std::cout << "<RecoTauJetRegionProducer::produce (moduleLabel = " << moduleLabel_ << ")>:" << std::endl;
83  std::cout << " inputJets = " << inputJets_ << std::endl;
84  std::cout << " pfCandSrc = " << pfCandSrc_ << std::endl;
85  std::cout << " pfCandAssocMapSrc_ = " << pfCandAssocMapSrc_ << std::endl;
86  }
87 
89  evt.getByToken(pf_token, pfCandsHandle);
90 
91  // Build Ptrs for all the PFCandidates
92  typedef edm::Ptr<reco::PFCandidate> PFCandPtr;
93  std::vector<PFCandPtr> pfCands;
94  pfCands.reserve(pfCandsHandle->size());
95  for ( size_t icand = 0; icand < pfCandsHandle->size(); ++icand ) {
96  pfCands.push_back(PFCandPtr(pfCandsHandle, icand));
97  }
98 
99  // Get the jets
101  evt.getByToken(Jets_token, jetView);
102  // Convert to a vector of PFJetRefs
103  reco::PFJetRefVector jets = reco::tau::castView<reco::PFJetRefVector>(jetView);
104  size_t nJets = jets.size();
105 
106  // Get the association map matching jets to PFCandidates
107  // (needed for recinstruction of boosted taus)
109  if ( pfCandAssocMapSrc_.label() != "" ) {
110  evt.getByToken(pfCandAssocMap_token, jetToPFCandMap);
111  }
112 
113  // Get the original product, so we can match against it - otherwise the
114  // indices don't match up.
115  edm::ProductID originalId = jets.id();
117  size_t nOriginalJets = 0;
118  // We have to make sure that we have some selected jets, otherwise we don't
119  // actually have a valid product ID to the original jets.
120  if ( nJets ) {
121  try {
122  evt.get(originalId, originalJets);
123  } catch(const cms::Exception &e) {
124  edm::LogError("MissingOriginalCollection")
125  << "Can't get the original jets that made: " << inputJets_
126  << " that have product ID: " << originalId
127  << " from the event!!";
128  throw e;
129  }
130  nOriginalJets = originalJets->size();
131  }
132 
133  auto newJets = std::make_unique<reco::PFJetCollection>();
134 
135  // Keep track of the indices of the current jet and the old (original) jet
136  // -1 indicates no match.
137  std::vector<int> matchInfo(nOriginalJets, -1);
138  newJets->reserve(nJets);
139  for ( size_t ijet = 0; ijet < nJets; ++ijet ) {
140  // Get a ref to jet
141  reco::PFJetRef jetRef = jets[ijet];
142  // Make an initial copy.
143  newJets->emplace_back(*jetRef);
144  reco::PFJet& newJet = newJets->back();
145  // Clear out all the constituents
146  newJet.clearDaughters();
147  // Loop over all the PFCands
148  for ( std::vector<PFCandPtr>::const_iterator pfCand = pfCands.begin();
149  pfCand != pfCands.end(); ++pfCand ) {
150  bool isMappedToJet = false;
151  if ( pfCandAssocMapSrc_.label() != "" ) {
152  auto temp = jetToPFCandMap->find(jetRef);
153  if( temp == jetToPFCandMap->end() ) {
154  edm::LogWarning("WeirdCandidateMap") << "Candidate map for jet " << jetRef.key() << " is empty!";
155  continue;
156  }
157  edm::RefVector<reco::PFCandidateCollection> pfCandsMappedToJet = (*jetToPFCandMap)[jetRef];
158  for ( edm::RefVector<reco::PFCandidateCollection>::const_iterator pfCandMappedToJet = pfCandsMappedToJet.begin();
159  pfCandMappedToJet != pfCandsMappedToJet.end(); ++pfCandMappedToJet ) {
160  if ( reco::deltaR2(**pfCandMappedToJet, **pfCand) < 1.e-8 ) {
161  isMappedToJet = true;
162  break;
163  }
164  }
165  } else {
166  isMappedToJet = true;
167  }
168  if ( reco::deltaR2(*jetRef, **pfCand) < deltaR2_ && isMappedToJet ) newJet.addDaughter(*pfCand);
169  }
170  if ( verbosity_ ) {
171  std::cout << "jet #" << ijet << ": Pt = " << jetRef->pt() << ", eta = " << jetRef->eta() << ", phi = " << jetRef->eta() << ","
172  << " mass = " << jetRef->mass() << ", area = " << jetRef->jetArea() << std::endl;
173  std::vector<reco::PFCandidatePtr> jetConstituents = newJet.getPFConstituents();
174  int idx = 0;
175  for ( std::vector<reco::PFCandidatePtr>::const_iterator jetConstituent = jetConstituents.begin();
176  jetConstituent != jetConstituents.end(); ++jetConstituent ) {
177  std::cout << " constituent #" << idx << ": Pt = " << (*jetConstituent)->pt() << ", eta = " << (*jetConstituent)->eta() << ", phi = " << (*jetConstituent)->phi() << std::endl;
178  }
179  }
180  // Match the index of the jet we just made to the index into the original
181  // collection.
182  matchInfo[jetRef.key()] = ijet;
183  }
184 
185  // Put our new jets into the event
186  edm::OrphanHandle<reco::PFJetCollection> newJetsInEvent = evt.put(std::move(newJets), "jets");
187 
188  // Create a matching between original jets -> extra collection
189  auto matching = std::make_unique<PFJetMatchMap>(newJetsInEvent);
190  if ( nJets ) {
191  PFJetMatchMap::Filler filler(*matching);
192  filler.insert(originalJets, matchInfo.begin(), matchInfo.end());
193  filler.fill();
194  }
195  evt.put(std::move(matching));
196 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
edm::EDGetTokenT< reco::PFCandidateCollection > pf_token
key_type key() const
Accessor for product key.
Definition: Ref.h:264
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:253
Jets made from PFObjects.
Definition: PFJet.h:21
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:248
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
def move
Definition: eostools.py:510
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:331
helper::Filler< ValueMap< int > > Filler
Definition: ValueMap.h:168
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
tuple cout
Definition: gather_cfg.py:145

Member Data Documentation

double RecoTauJetRegionProducer::deltaR2_
private

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

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 55 of file RecoTauJetRegionProducer.cc.

Referenced by produce(), and RecoTauJetRegionProducer().