CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Static Public Member Functions | Private Attributes
RecoTauGenericJetRegionProducer< JetType, CandType > Class Template Reference
Inheritance diagram for RecoTauGenericJetRegionProducer< JetType, CandType >:
edm::stream::EDProducer<>

Public Types

typedef edm::AssociationMap< edm::OneToOne< reco::JetView, reco::JetView > > JetMatchMap
 
typedef edm::AssociationMap< edm::OneToMany< std::vector< JetType >, std::vector< CandType >, unsigned int > > JetToCandidateAssociation
 
- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Public Member Functions

template<>
void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
template<>
void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
void produce (edm::Event &evt, const edm::EventSetup &es) override
 
 RecoTauGenericJetRegionProducer (const edm::ParameterSet &pset)
 
 ~RecoTauGenericJetRegionProducer () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
static void fillDescriptionsBase (edm::ConfigurationDescriptions &descriptions, const std::string &name)
 

Private Attributes

double deltaR2_
 
edm::InputTag inputJets_
 
edm::EDGetTokenT< reco::CandidateViewJets_token
 
double maxJetAbsEta_
 
double minJetPt_
 
std::string moduleLabel_
 
edm::EDGetTokenT< std::vector< CandType > > pf_token
 
edm::EDGetTokenT< JetToCandidateAssociationpfCandAssocMap_token
 
edm::InputTag pfCandAssocMapSrc_
 
edm::InputTag pfCandSrc_
 
int verbosity_
 

Detailed Description

template<class JetType, class CandType>
class RecoTauGenericJetRegionProducer< JetType, CandType >

Definition at line 36 of file RecoTauGenericJetRegionProducer.cc.

Member Typedef Documentation

◆ JetMatchMap

template<class JetType , class CandType >
typedef edm::AssociationMap<edm::OneToOne<reco::JetView, reco::JetView> > RecoTauGenericJetRegionProducer< JetType, CandType >::JetMatchMap

Definition at line 38 of file RecoTauGenericJetRegionProducer.cc.

◆ JetToCandidateAssociation

template<class JetType , class CandType >
typedef edm::AssociationMap<edm::OneToMany<std::vector<JetType>, std::vector<CandType>, unsigned int> > RecoTauGenericJetRegionProducer< JetType, CandType >::JetToCandidateAssociation

Definition at line 40 of file RecoTauGenericJetRegionProducer.cc.

Constructor & Destructor Documentation

◆ RecoTauGenericJetRegionProducer()

template<class JetType , class CandType >
RecoTauGenericJetRegionProducer< JetType, CandType >::RecoTauGenericJetRegionProducer ( const edm::ParameterSet pset)
explicit

Definition at line 68 of file RecoTauGenericJetRegionProducer.cc.

References looper::cfg, PbPb_ZMuSkimMuonDPG_cff::deltaR, RecoTauGenericJetRegionProducer< JetType, CandType >::deltaR2_, RecoTauGenericJetRegionProducer< JetType, CandType >::inputJets_, RecoTauGenericJetRegionProducer< JetType, CandType >::Jets_token, RecoTauGenericJetRegionProducer< JetType, CandType >::maxJetAbsEta_, RecoTauGenericJetRegionProducer< JetType, CandType >::minJetPt_, RecoTauGenericJetRegionProducer< JetType, CandType >::pf_token, RecoTauGenericJetRegionProducer< JetType, CandType >::pfCandAssocMap_token, RecoTauGenericJetRegionProducer< JetType, CandType >::pfCandAssocMapSrc_, RecoTauGenericJetRegionProducer< JetType, CandType >::pfCandSrc_, and RecoTauGenericJetRegionProducer< JetType, CandType >::verbosity_.

69  : moduleLabel_(cfg.getParameter<std::string>("@module_label")) {
70  inputJets_ = cfg.getParameter<edm::InputTag>("src");
71  pfCandSrc_ = cfg.getParameter<edm::InputTag>("pfCandSrc");
72  pfCandAssocMapSrc_ = cfg.getParameter<edm::InputTag>("pfCandAssocMapSrc");
73 
74  pf_token = consumes<std::vector<CandType> >(pfCandSrc_);
75  Jets_token = consumes<reco::CandidateView>(inputJets_);
76  pfCandAssocMap_token = consumes<JetToCandidateAssociation>(pfCandAssocMapSrc_);
77 
78  double deltaR = cfg.getParameter<double>("deltaR");
80  minJetPt_ = cfg.getParameter<double>("minJetPt");
81  maxJetAbsEta_ = cfg.getParameter<double>("maxJetAbsEta");
82 
83  verbosity_ = cfg.getParameter<int>("verbosity");
84 
85  produces<std::vector<JetType> >("jets");
86  produces<JetMatchMap>();
87 }
edm::EDGetTokenT< JetToCandidateAssociation > pfCandAssocMap_token
edm::EDGetTokenT< reco::CandidateView > Jets_token
edm::EDGetTokenT< std::vector< CandType > > pf_token

◆ ~RecoTauGenericJetRegionProducer()

template<class JetType , class CandType >
RecoTauGenericJetRegionProducer< JetType, CandType >::~RecoTauGenericJetRegionProducer ( )
inlineoverride

Definition at line 42 of file RecoTauGenericJetRegionProducer.cc.

42 {}

Member Function Documentation

◆ fillDescriptions() [1/3]

template<class JetType , class CandType >
static void RecoTauGenericJetRegionProducer< JetType, CandType >::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

◆ fillDescriptions() [2/3]

template<>
void RecoTauGenericJetRegionProducer< reco::PFJet, reco::PFCandidate >::fillDescriptions ( edm::ConfigurationDescriptions descriptions)

Definition at line 236 of file RecoTauGenericJetRegionProducer.cc.

References RecoTauGenericJetRegionProducer< JetType, CandType >::fillDescriptionsBase().

237  {
238  // RecoTauGenericJetRegionProducer
239  RecoTauGenericJetRegionProducer::fillDescriptionsBase(descriptions, "RecoTauJetRegionProducer");
240 }
static void fillDescriptionsBase(edm::ConfigurationDescriptions &descriptions, const std::string &name)

◆ fillDescriptions() [3/3]

template<>
void RecoTauGenericJetRegionProducer< pat::Jet, pat::PackedCandidate >::fillDescriptions ( edm::ConfigurationDescriptions descriptions)

Definition at line 243 of file RecoTauGenericJetRegionProducer.cc.

References RecoTauGenericJetRegionProducer< JetType, CandType >::fillDescriptionsBase().

244  {
245  // RecoTauGenericJetRegionProducer
246  RecoTauGenericJetRegionProducer::fillDescriptionsBase(descriptions, "RecoTauPatJetRegionProducer");
247 }
static void fillDescriptionsBase(edm::ConfigurationDescriptions &descriptions, const std::string &name)

◆ fillDescriptionsBase()

template<class JetType , class CandType >
void RecoTauGenericJetRegionProducer< JetType, CandType >::fillDescriptionsBase ( edm::ConfigurationDescriptions descriptions,
const std::string &  name 
)
static

Definition at line 221 of file RecoTauGenericJetRegionProducer.cc.

References edm::ConfigurationDescriptions::add(), submitPVResolutionJobs::desc, HLT_2022v12_cff::InputTag, and Skims_PA_cff::name.

Referenced by RecoTauGenericJetRegionProducer< JetType, CandType >::fillDescriptions().

222  {
223  // RecoTauGenericJetRegionProducer
225  desc.add<edm::InputTag>("src", edm::InputTag("ak4PFJets"));
226  desc.add<double>("deltaR", 0.8);
227  desc.add<edm::InputTag>("pfCandAssocMapSrc", edm::InputTag(""));
228  desc.add<int>("verbosity", 0);
229  desc.add<double>("maxJetAbsEta", 2.5);
230  desc.add<double>("minJetPt", 14.0);
231  desc.add<edm::InputTag>("pfCandSrc", edm::InputTag("particleFlow"));
232  descriptions.add(name, desc);
233 }
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ produce()

template<class JetType , class CandType >
void RecoTauGenericJetRegionProducer< JetType, CandType >::produce ( edm::Event evt,
const edm::EventSetup es 
)
override

Definition at line 90 of file RecoTauGenericJetRegionProducer.cc.

References funct::abs(), gather_cfg::cout, reco::deltaR2(), MillePedeFileConverter_cfg::e, edm::Event::get(), edm::Event::getByToken(), heavyIonCSV_trainingSettings::idx, edm::HandleBase::isValid(), PDWG_EXODelayedJetMET_cff::jets, edm::Ref< C, T, F >::key(), edm::makeRefToBaseProdFrom(), TtSemiLepJetCombMVATrainer_cfi::matching, eostools::move(), edm::Event::put(), and groupFilesInBlocks::temp.

90  {
91  if (verbosity_) {
92  std::cout << "<RecoTauJetRegionProducer::produce (moduleLabel = " << moduleLabel_ << ")>:" << std::endl;
93  std::cout << " inputJets = " << inputJets_ << std::endl;
94  std::cout << " pfCandSrc = " << pfCandSrc_ << std::endl;
95  std::cout << " pfCandAssocMapSrc_ = " << pfCandAssocMapSrc_ << std::endl;
96  }
97 
98  edm::Handle<std::vector<CandType> > pfCandsHandle;
99  evt.getByToken(pf_token, pfCandsHandle);
100 
101  // Build Ptrs for all the PFCandidates
102  typedef edm::Ptr<CandType> CandPtr;
103  std::vector<CandPtr> pfCands;
104  pfCands.reserve(pfCandsHandle->size());
105  for (size_t icand = 0; icand < pfCandsHandle->size(); ++icand) {
106  pfCands.push_back(CandPtr(pfCandsHandle, icand));
107  }
108 
109  // Get the jets
111  evt.getByToken(Jets_token, jetView);
112  // Convert to a vector of JetRefs
113  edm::RefVector<std::vector<JetType> > jets = reco::tau::castView<edm::RefVector<std::vector<JetType> > >(jetView);
114  size_t nJets = jets.size();
115 
116  // Get the association map matching jets to Candidates
117  // (needed for reconstruction of boosted taus)
119  std::vector<std::unordered_set<unsigned> > fastJetToPFCandMap;
120  if (!pfCandAssocMapSrc_.label().empty()) {
121  evt.getByToken(pfCandAssocMap_token, jetToPFCandMap);
122  fastJetToPFCandMap.resize(nJets);
123  for (size_t ijet = 0; ijet < nJets; ++ijet) {
124  // Get a ref to jet
125  const edm::Ref<std::vector<JetType> >& jetRef = jets[ijet];
126  const auto& pfCandsMappedToJet = (*jetToPFCandMap)[jetRef];
127  for (const auto& pfCandMappedToJet : pfCandsMappedToJet) {
128  fastJetToPFCandMap[ijet].emplace(pfCandMappedToJet.key());
129  }
130  }
131  }
132 
133  // Get the original product, so we can match against it - otherwise the
134  // indices don't match up.
135  edm::ProductID originalId = jets.id();
136  edm::Handle<std::vector<JetType> > originalJets;
137  size_t nOriginalJets = 0;
138  // We have to make sure that we have some selected jets, otherwise we don't
139  // actually have a valid product ID to the original jets.
140  if (nJets) {
141  try {
142  evt.get(originalId, originalJets);
143  } catch (const cms::Exception& e) {
144  edm::LogError("MissingOriginalCollection") << "Can't get the original jets that made: " << inputJets_
145  << " that have product ID: " << originalId << " from the event!!";
146  throw e;
147  }
148  nOriginalJets = originalJets->size();
149  }
150 
151  auto newJets = std::make_unique<std::vector<JetType> >();
152 
153  // Keep track of the indices of the current jet and the old (original) jet
154  // -1 indicates no match.
155  std::vector<int> matchInfo(nOriginalJets, -1);
156  newJets->reserve(nJets);
157  size_t nNewJets = 0;
158  for (size_t ijet = 0; ijet < nJets; ++ijet) {
159  // Get a ref to jet
160  const edm::Ref<std::vector<JetType> >& jetRef = jets[ijet];
161  if (jetRef->pt() - minJetPt_ < 1e-5)
162  continue;
163  if (std::abs(jetRef->eta()) - maxJetAbsEta_ > -1e-5)
164  continue;
165  // Make an initial copy.
166  newJets->emplace_back(*jetRef);
167  JetType& newJet = newJets->back();
168  // Clear out all the constituents
169  newJet.clearDaughters();
170  // Loop over all the PFCands
171  for (const auto& pfCand : pfCands) {
172  bool isMappedToJet = false;
173  if (jetToPFCandMap.isValid()) {
174  auto temp = jetToPFCandMap->find(jetRef);
175  if (temp == jetToPFCandMap->end()) {
176  edm::LogWarning("WeirdCandidateMap") << "Candidate map for jet " << jetRef.key() << " is empty!";
177  continue;
178  }
179  isMappedToJet = fastJetToPFCandMap[ijet].count(pfCand.key());
180  } else {
181  isMappedToJet = true;
182  }
183  if (reco::deltaR2(*jetRef, *pfCand) < deltaR2_ && isMappedToJet)
184  newJet.addDaughter(pfCand);
185  }
186  if (verbosity_) {
187  std::cout << "jet #" << ijet << ": Pt = " << jetRef->pt() << ", eta = " << jetRef->eta()
188  << ", phi = " << jetRef->eta() << ","
189  << " mass = " << jetRef->mass() << ", area = " << jetRef->jetArea() << std::endl;
190  auto jetConstituents = newJet.daughterPtrVector();
191  int idx = 0;
192  for (const auto& jetConstituent : jetConstituents) {
193  std::cout << " constituent #" << idx << ": Pt = " << jetConstituent->pt() << ", eta = " << jetConstituent->eta()
194  << ", phi = " << jetConstituent->phi() << std::endl;
195  ++idx;
196  }
197  }
198  // Match the index of the jet we just made to the index into the original
199  // collection.
200  //matchInfo[jetRef.key()] = ijet;
201  matchInfo[jetRef.key()] = nNewJets;
202  nNewJets++;
203  }
204 
205  // Put our new jets into the event
206  edm::OrphanHandle<std::vector<JetType> > newJetsInEvent = evt.put(std::move(newJets), "jets");
207 
208  // Create a matching between original jets -> extra collection
209  auto matching = (nJets != 0)
210  ? std::make_unique<JetMatchMap>(
212  : std::make_unique<JetMatchMap>();
213  for (size_t ijet = 0; ijet < nJets; ++ijet) {
214  matching->insert(edm::RefToBase<reco::Jet>(jets[ijet]),
215  edm::RefToBase<reco::Jet>(edm::Ref<std::vector<JetType> >(newJetsInEvent, matchInfo[ijet])));
216  }
217  evt.put(std::move(matching));
218 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:346
edm::EDGetTokenT< JetToCandidateAssociation > pfCandAssocMap_token
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
std::string const & label() const
Definition: InputTag.h:36
Log< level::Error, false > LogError
key_type key() const
Accessor for product key.
Definition: Ref.h:250
const_iterator find(const key_type &k) const
find element with specified reference key
const_iterator end() const
last iterator over the map (read only)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::EDGetTokenT< reco::CandidateView > Jets_token
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
bool isValid() const
Definition: HandleBase.h:70
edm::EDGetTokenT< std::vector< CandType > > pf_token
RefToBaseProd< T > makeRefToBaseProdFrom(RefToBase< T > const &iRef, Event const &iEvent)
Log< level::Warning, false > LogWarning
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

◆ deltaR2_

template<class JetType , class CandType >
double RecoTauGenericJetRegionProducer< JetType, CandType >::deltaR2_
private

◆ inputJets_

template<class JetType , class CandType >
edm::InputTag RecoTauGenericJetRegionProducer< JetType, CandType >::inputJets_
private

◆ Jets_token

template<class JetType , class CandType >
edm::EDGetTokenT<reco::CandidateView> RecoTauGenericJetRegionProducer< JetType, CandType >::Jets_token
private

◆ maxJetAbsEta_

template<class JetType , class CandType >
double RecoTauGenericJetRegionProducer< JetType, CandType >::maxJetAbsEta_
private

◆ minJetPt_

template<class JetType , class CandType >
double RecoTauGenericJetRegionProducer< JetType, CandType >::minJetPt_
private

◆ moduleLabel_

template<class JetType , class CandType >
std::string RecoTauGenericJetRegionProducer< JetType, CandType >::moduleLabel_
private

◆ pf_token

template<class JetType , class CandType >
edm::EDGetTokenT<std::vector<CandType> > RecoTauGenericJetRegionProducer< JetType, CandType >::pf_token
private

◆ pfCandAssocMap_token

template<class JetType , class CandType >
edm::EDGetTokenT<JetToCandidateAssociation> RecoTauGenericJetRegionProducer< JetType, CandType >::pfCandAssocMap_token
private

◆ pfCandAssocMapSrc_

template<class JetType , class CandType >
edm::InputTag RecoTauGenericJetRegionProducer< JetType, CandType >::pfCandAssocMapSrc_
private

◆ pfCandSrc_

template<class JetType , class CandType >
edm::InputTag RecoTauGenericJetRegionProducer< JetType, CandType >::pfCandSrc_
private

◆ verbosity_

template<class JetType , class CandType >
int RecoTauGenericJetRegionProducer< JetType, CandType >::verbosity_
private