CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
BetaStarVarProducer< T > Class Template Reference

#include <PhysicsTools/NanoAOD/plugins/BetaStarVarProducer.cc>

Inheritance diagram for BetaStarVarProducer< T >:
edm::global::EDProducer<> edm::global::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 BetaStarVarProducer (const edm::ParameterSet &iConfig)
 
 ~BetaStarVarProducer () override
 
- Public Member Functions inherited from edm::global::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsStreamLuminosityBlocks () const final
 
bool wantsStreamRuns () const final
 
- Public Member Functions inherited from edm::global::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)
 
 ~ProducerBase () noexcept(false) override
 
- 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
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
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)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::global::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Member Functions

std::tuple< float, float > calculateCHSEnergies (edm::Ptr< pat::Jet > const &jet, edm::View< T > const &cands) const
 
void produce (edm::StreamID, edm::Event &, const edm::EventSetup &) const override
 

Private Attributes

double maxDR_
 
edm::EDGetTokenT< edm::View< pat::Jet > > srcJet_
 
edm::EDGetTokenT< edm::View< T > > srcPF_
 

Additional Inherited Members

- Public Types inherited from edm::global::EDProducerBase
typedef EDProducerBase 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
 
- Protected Member Functions inherited from edm::ProducerBase
ProducesCollector producesCollector ()
 
- 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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
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

template<typename T>
class BetaStarVarProducer< T >

Description: This produces value maps to store CHS-related variables for JERC. This includes the charged hadrons associated to CHS jets, and those associated to PU that are within the CHS jet.

Implementation: This uses a ValueMap producer functionality, and loops over the input candidates (usually PackedCandidates) that are associated to each jet, counting the candidates associated to the PV and those not.

Definition at line 44 of file BetaStarVarProducer.cc.

Constructor & Destructor Documentation

template<typename T >
BetaStarVarProducer< T >::BetaStarVarProducer ( const edm::ParameterSet iConfig)
inlineexplicit

Definition at line 46 of file BetaStarVarProducer.cc.

46  :
49  maxDR_( iConfig.getParameter<double>("maxDR") )
50  {
51  produces<edm::ValueMap<float>>("chargedHadronPUEnergyFraction");
52  produces<edm::ValueMap<float>>("chargedHadronCHSEnergyFraction");
53  }
T getParameter(std::string const &) const
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< edm::View< pat::Jet > > srcJet_
edm::EDGetTokenT< edm::View< T > > srcPF_
template<typename T >
BetaStarVarProducer< T >::~BetaStarVarProducer ( )
inlineoverride

Member Function Documentation

template<typename T >
std::tuple< float, float > BetaStarVarProducer< T >::calculateCHSEnergies ( edm::Ptr< pat::Jet > const &  jet,
edm::View< T > const &  cands 
) const
private

Definition at line 108 of file BetaStarVarProducer.cc.

References pat::Jet::correctedP4(), pat::Jet::daughterPtrVector(), reco::deltaR(), HGC3DClusterGenMatchSelector_cfi::dR, pat::PackedCandidate::energy(), spr::find(), and BetaStarVarProducer< T >::maxDR_.

Referenced by BetaStarVarProducer< T >::produce(), and BetaStarVarProducer< T >::~BetaStarVarProducer().

108  {
109 
110  auto rawP4 = ijet->correctedP4(0);
111  std::vector<unsigned int> jet2pu;
112 
113  // Get all of the PF candidates within a cone of dR to the jet that
114  // do NOT belong to the primary vertex.
115  // Store their indices.
116  for ( unsigned int icand = 0; icand < cands.size(); ++icand ) {
117  auto cand = cands.ptrAt(icand);
118  if (cand->fromPV()!=0) continue;
119  float dR = reco::deltaR(*ijet,*cand);
120  if (dR<maxDR_) {
121  jet2pu.emplace_back( cand.key() );
122  }
123  }
124 
125  // Keep track of energy for PU stuff
126  double che = 0.0;
127  double pue = 0.0;
128 
129  // Loop through the PF candidates within the jet.
130  // Store the sum of their energy, and their indices.
131  std::vector<unsigned int> used;
132  auto jetConstituents = ijet->daughterPtrVector();
133  for (auto const & ic : jetConstituents ) {
134  auto icpc = dynamic_cast<pat::PackedCandidate const *>(ic.get());
135  if ( icpc->charge()!=0) {
136  che += icpc->energy();
137  if (icpc->fromPV()==0) {
138  used.push_back( ic.key() );
139  }
140  }
141  }
142  // Loop through the pileup PF candidates within the jet.
143  for (auto pidx : jet2pu) {
144  auto const & dtr = cands.ptrAt(pidx);
145  // We take the candidates that have not appeared before: these were removed by CHS
146  if (dtr->charge()!=0 and std::find(used.begin(),used.end(),dtr.key() )==used.end())
147  pue += dtr->energy();
148  }
149 
150  // Now get the fractions relative to the raw jet.
151  auto puf = pue / rawP4.energy();
152  auto chf = che / rawP4.energy();
153 
154  return std::tuple<float,float>(puf,chf);
155 }
Ptr< value_type > ptrAt(size_type i) const
size_type size() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
double energy() const override
energy
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
template<typename T >
void BetaStarVarProducer< T >::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 159 of file BetaStarVarProducer.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::add(), timingPdfMaker::modname, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by BetaStarVarProducer< T >::~BetaStarVarProducer().

159  {
161  desc.add<edm::InputTag>("srcJet")->setComment("jet input collection");
162  desc.add<edm::InputTag>("srcPF")->setComment("PF candidate input collection");
163  desc.add<double>("maxDR")->setComment("Maximum DR to consider for jet-->pf cand association");
164  std::string modname ("BetaStarVarProducer");
165  descriptions.add(modname,desc);
166 }
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
template<typename T >
void BetaStarVarProducer< T >::produce ( edm::StreamID  streamID,
edm::Event iEvent,
const edm::EventSetup iSetup 
) const
overrideprivate

Definition at line 70 of file BetaStarVarProducer.cc.

References BetaStarVarProducer< T >::calculateCHSEnergies(), edm::helper::Filler< Map >::fill(), edm::Event::getByToken(), edm::helper::Filler< Map >::insert(), metsig::jet, eostools::move(), edm::Event::put(), electrons_cff::srcJet, BetaStarVarProducer< T >::srcJet_, jets_cff::srcPF, and BetaStarVarProducer< T >::srcPF_.

Referenced by BetaStarVarProducer< T >::~BetaStarVarProducer().

71 {
72 
74  iEvent.getByToken(srcJet_, srcJet);
76  iEvent.getByToken(srcPF_, srcPF);
77 
78  unsigned int nJet = srcJet->size();
79 
80  std::vector<float> chargedHadronPUEnergyFraction(nJet,-1);
81  std::vector<float> chargedHadronCHSEnergyFraction(nJet,-1);
82 
83  for ( unsigned int ij = 0; ij < nJet; ++ij ) {
84  auto jet = srcJet->ptrAt(ij);
85  std::tuple<float,float> vals = calculateCHSEnergies( jet, *srcPF );
86  auto chpuf = std::get<0>(vals);
87  auto chef = std::get<1>(vals);
88  chargedHadronPUEnergyFraction[ij] = chpuf;
89  chargedHadronCHSEnergyFraction[ij] = chef;
90  }
91 
92  std::unique_ptr<edm::ValueMap<float>> chargedHadronPUEnergyFractionV(new edm::ValueMap<float>());
93  edm::ValueMap<float>::Filler fillerPU(*chargedHadronPUEnergyFractionV);
94  fillerPU.insert(srcJet,chargedHadronPUEnergyFraction.begin(),chargedHadronPUEnergyFraction.end());
95  fillerPU.fill();
96  iEvent.put(std::move(chargedHadronPUEnergyFractionV),"chargedHadronPUEnergyFraction");
97 
98  std::unique_ptr<edm::ValueMap<float>> chargedHadronCHSEnergyFractionV(new edm::ValueMap<float>());
99  edm::ValueMap<float>::Filler fillerCHE(*chargedHadronCHSEnergyFractionV);
100  fillerCHE.insert(srcJet,chargedHadronCHSEnergyFraction.begin(),chargedHadronCHSEnergyFraction.end());
101  fillerCHE.fill();
102  iEvent.put(std::move(chargedHadronCHSEnergyFractionV),"chargedHadronCHSEnergyFraction");
103 
104 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
edm::EDGetTokenT< edm::View< pat::Jet > > srcJet_
edm::EDGetTokenT< edm::View< T > > srcPF_
std::tuple< float, float > calculateCHSEnergies(edm::Ptr< pat::Jet > const &jet, edm::View< T > const &cands) const
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

template<typename T >
double BetaStarVarProducer< T >::maxDR_
private
template<typename T >
edm::EDGetTokenT<edm::View<pat::Jet> > BetaStarVarProducer< T >::srcJet_
private

Definition at line 63 of file BetaStarVarProducer.cc.

Referenced by BetaStarVarProducer< T >::produce().

template<typename T >
edm::EDGetTokenT<edm::View<T> > BetaStarVarProducer< T >::srcPF_
private

Definition at line 64 of file BetaStarVarProducer.cc.

Referenced by BetaStarVarProducer< T >::produce().