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<>
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 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
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 

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 39 of file RecoTauGenericJetRegionProducer.cc.

Member Typedef Documentation

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

Definition at line 42 of file RecoTauGenericJetRegionProducer.cc.

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 43 of file RecoTauGenericJetRegionProducer.cc.

Constructor & Destructor Documentation

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

Definition at line 71 of file RecoTauGenericJetRegionProducer.cc.

References boostedElectronIsolation_cff::deltaR, RecoTauGenericJetRegionProducer< JetType, CandType >::deltaR2_, edm::ParameterSet::getParameter(), 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_.

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

Member Function Documentation

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

Definition at line 236 of file RecoTauGenericJetRegionProducer.cc.

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

236  {
237  // RecoTauGenericJetRegionProducer
238  RecoTauGenericJetRegionProducer::fillDescriptionsBase(descriptions, "RecoTauJetRegionProducer");
239 
240 }
static void fillDescriptionsBase(edm::ConfigurationDescriptions &descriptions, const std::string &name)
template<>
void RecoTauGenericJetRegionProducer< pat::Jet, pat::PackedCandidate >::fillDescriptions ( edm::ConfigurationDescriptions descriptions)

Definition at line 244 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)
template<class JetType , class CandType >
void RecoTauGenericJetRegionProducer< JetType, CandType >::fillDescriptionsBase ( edm::ConfigurationDescriptions descriptions,
const std::string &  name 
)
static

Definition at line 220 of file RecoTauGenericJetRegionProducer.cc.

References edm::ConfigurationDescriptions::add(), and edm::ParameterSetDescription::add().

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

220  {
221  // RecoTauGenericJetRegionProducer
223  desc.add<edm::InputTag>("src", edm::InputTag("ak4PFJets"));
224  desc.add<double>("deltaR", 0.8);
225  desc.add<edm::InputTag>("pfCandAssocMapSrc", edm::InputTag(""));
226  desc.add<int>("verbosity", 0);
227  desc.add<double>("maxJetAbsEta", 2.5);
228  desc.add<double>("minJetPt", 14.0);
229  desc.add<edm::InputTag>("pfCandSrc", edm::InputTag("particleFlow"));
230  descriptions.add(name, desc);
231 }
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
template<class JetType , class CandType >
void RecoTauGenericJetRegionProducer< JetType, CandType >::produce ( edm::Event evt,
const edm::EventSetup es 
)
override

Definition at line 94 of file RecoTauGenericJetRegionProducer.cc.

References funct::abs(), gather_cfg::cout, reco::deltaR2(), RecoTauGenericJetRegionProducer< JetType, CandType >::deltaR2_, MillePedeFileConverter_cfg::e, edm::AssociationMap< Tag >::end(), edm::AssociationMap< Tag >::find(), edm::Event::get(), edm::Event::getByToken(), edm::RefVector< C, T, F >::id(), training_settings::idx, RecoTauGenericJetRegionProducer< JetType, CandType >::inputJets_, edm::HandleBase::isValid(), fwrapper::jets, RecoTauGenericJetRegionProducer< JetType, CandType >::Jets_token, edm::Ref< C, T, F >::key(), edm::InputTag::label(), edm::makeRefToBaseProdFrom(), RecoTauGenericJetRegionProducer< JetType, CandType >::maxJetAbsEta_, RecoTauGenericJetRegionProducer< JetType, CandType >::minJetPt_, RecoTauGenericJetRegionProducer< JetType, CandType >::moduleLabel_, eostools::move(), RecoTauGenericJetRegionProducer< JetType, CandType >::pf_token, RecoTauGenericJetRegionProducer< JetType, CandType >::pfCandAssocMap_token, RecoTauGenericJetRegionProducer< JetType, CandType >::pfCandAssocMapSrc_, RecoTauGenericJetRegionProducer< JetType, CandType >::pfCandSrc_, edm::Event::put(), edm::RefVector< C, T, F >::size(), groupFilesInBlocks::temp, and RecoTauGenericJetRegionProducer< JetType, CandType >::verbosity_.

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

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

Member Data Documentation

template<class JetType , class CandType >
double RecoTauGenericJetRegionProducer< JetType, CandType >::deltaR2_
private
template<class JetType , class CandType >
edm::InputTag RecoTauGenericJetRegionProducer< JetType, CandType >::inputJets_
private
template<class JetType , class CandType >
edm::EDGetTokenT<reco::CandidateView> RecoTauGenericJetRegionProducer< JetType, CandType >::Jets_token
private
template<class JetType , class CandType >
double RecoTauGenericJetRegionProducer< JetType, CandType >::maxJetAbsEta_
private
template<class JetType , class CandType >
double RecoTauGenericJetRegionProducer< JetType, CandType >::minJetPt_
private
template<class JetType , class CandType >
std::string RecoTauGenericJetRegionProducer< JetType, CandType >::moduleLabel_
private
template<class JetType , class CandType >
edm::EDGetTokenT<std::vector<CandType> > RecoTauGenericJetRegionProducer< JetType, CandType >::pf_token
private
template<class JetType , class CandType >
edm::EDGetTokenT<JetToCandidateAssociation> RecoTauGenericJetRegionProducer< JetType, CandType >::pfCandAssocMap_token
private
template<class JetType , class CandType >
edm::InputTag RecoTauGenericJetRegionProducer< JetType, CandType >::pfCandAssocMapSrc_
private
template<class JetType , class CandType >
edm::InputTag RecoTauGenericJetRegionProducer< JetType, CandType >::pfCandSrc_
private
template<class JetType , class CandType >
int RecoTauGenericJetRegionProducer< JetType, CandType >::verbosity_
private