CMS 3D CMS Logo

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

Public Member Functions

 HiFJRhoProducer (const edm::ParameterSet &)
 
 ~HiFJRhoProducer () override=default
 
- Public Member Functions inherited from edm::global::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
 
EDProduceroperator= (const EDProducer &)=delete
 
bool wantsGlobalLuminosityBlocks () const noexcept final
 
bool wantsGlobalRuns () const noexcept final
 
bool wantsInputProcessBlocks () const noexcept final
 
bool wantsProcessBlocks () const noexcept final
 
bool wantsStreamLuminosityBlocks () const noexcept final
 
bool wantsStreamRuns () const noexcept 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
 
std::vector< bool > const & recordProvenanceList () 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)
 
TypeLabelList const & typeLabelList () const
 used by the fwk to register the list of products of this module More...
 
 ~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
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (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::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, 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
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices 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

double calcMd (reco::Jet const &jet) const
 
double calcMedian (std::vector< double > &v) const
 
bool isPackedCandidate (reco::Candidate const *candidate) const
 
void produce (edm::StreamID, edm::Event &, edm::EventSetup const &) const override
 

Private Attributes

std::once_flag checkJetCand_
 
const double etaMaxExcl2_
 
const double etaMaxExcl_
 
const std::vector< double > etaRanges_
 
const edm::EDGetTokenT< edm::View< reco::Jet > > jetsToken_
 
const unsigned int nExcl2_
 
const unsigned int nExcl_
 
const double ptMinExcl2_
 
const double ptMinExcl_
 
bool usingPackedCand_ = false
 

Additional Inherited Members

- Public Types inherited from edm::global::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
template<typename T >
using BranchAliasSetterT = ProductRegistryHelper::BranchAliasSetterT< T >
 
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
template<Transition Tr = Transition::Event>
auto produces (std::string instanceName) noexcept
 declare what type of product will make and with which optional label More...
 
template<Transition B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<BranchType B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces ()
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces ()
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces ()
 
template<Transition Tr = Transition::Event>
auto produces () noexcept
 
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
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)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

Definition at line 24 of file HiFJRhoProducer.cc.

Constructor & Destructor Documentation

◆ HiFJRhoProducer()

HiFJRhoProducer::HiFJRhoProducer ( const edm::ParameterSet iConfig)
explicit

Definition at line 54 of file HiFJRhoProducer.cc.

56  nExcl_(iConfig.getParameter<int>("nExcl")),
57  nExcl2_(iConfig.getParameter<int>("nExcl2")),
58  etaMaxExcl_(iConfig.getParameter<double>("etaMaxExcl")),
59  ptMinExcl_(iConfig.getParameter<double>("ptMinExcl")),
60  etaMaxExcl2_(iConfig.getParameter<double>("etaMaxExcl2")),
61  ptMinExcl2_(iConfig.getParameter<double>("ptMinExcl2")),
62  etaRanges_(iConfig.getParameter<std::vector<double>>("etaRanges")) {
63  // register your products
64  produces<std::vector<double>>("mapEtaEdges");
65  produces<std::vector<double>>("mapToRho");
66  produces<std::vector<double>>("mapToRhoM");
67  produces<std::vector<double>>("ptJets");
68  produces<std::vector<double>>("areaJets");
69  produces<std::vector<double>>("etaJets");
70 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
const double etaMaxExcl2_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
const unsigned int nExcl2_
const double etaMaxExcl_
const std::vector< double > etaRanges_
const double ptMinExcl2_
const double ptMinExcl_
const unsigned int nExcl_
const edm::EDGetTokenT< edm::View< reco::Jet > > jetsToken_

◆ ~HiFJRhoProducer()

HiFJRhoProducer::~HiFJRhoProducer ( )
overridedefault

Member Function Documentation

◆ calcMd()

double HiFJRhoProducer::calcMd ( reco::Jet const &  jet) const
private

Definition at line 162 of file HiFJRhoProducer.cc.

References Options::const, isPackedCandidate(), metsig::jet, and mathSSE::sqrt().

Referenced by produce().

162  {
163  // compute md as defined in http://arxiv.org/pdf/1211.2811.pdf
164 
165  // loop over the jet constituents
166  double sum = 0.;
167  for (auto const* daughter : jet.getJetConstituentsQuick()) {
168  if (isPackedCandidate(daughter)) { // packed candidate situation
169  auto part = static_cast<pat::PackedCandidate const*>(daughter);
170  sum += sqrt(part->mass() * part->mass() + part->pt() * part->pt()) - part->pt();
171  } else {
172  auto part = static_cast<reco::PFCandidate const*>(daughter);
173  sum += sqrt(part->mass() * part->mass() + part->pt() * part->pt()) - part->pt();
174  }
175  }
176 
177  return sum;
178 }
T sqrt(T t)
Definition: SSEVec.h:23
bool isPackedCandidate(reco::Candidate const *candidate) const
part
Definition: HCALResponse.h:20
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41

◆ calcMedian()

double HiFJRhoProducer::calcMedian ( std::vector< double > &  v) const
private

Definition at line 207 of file HiFJRhoProducer.cc.

References create_idmaps::n, and findQualityFiles::v.

Referenced by produce().

207  {
208  // post-condition: After returning, the elements in v may be reordered and the resulting order is implementation defined.
209  // works for even and odd collections
210  if (v.empty()) {
211  return 0.0;
212  }
213  auto n = v.size() / 2;
214  std::nth_element(v.begin(), v.begin() + n, v.end());
215  auto med = v[n];
216  if (!(v.size() & 1)) { // if the set size is even
217  auto max_it = std::max_element(v.begin(), v.begin() + n);
218  med = (*max_it + med) / 2.0;
219  }
220  return med;
221 }

◆ fillDescriptions()

void HiFJRhoProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 193 of file HiFJRhoProducer.cc.

References edm::ConfigurationDescriptions::add(), submitPVResolutionJobs::desc, and ProducerED_cfi::InputTag.

193  {
195  desc.add<edm::InputTag>("jetSource", edm::InputTag("kt4PFJets"));
196  desc.add<int>("nExcl", 2);
197  desc.add<double>("etaMaxExcl", 2.);
198  desc.add<double>("ptMinExcl", 20.);
199  desc.add<int>("nExcl2", 2);
200  desc.add<double>("etaMaxExcl2", 2.);
201  desc.add<double>("ptMinExcl2", 20.);
202  desc.add<std::vector<double>>("etaRanges", {});
203  descriptions.add("hiFJRhoProducer", desc);
204 }
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ isPackedCandidate()

bool HiFJRhoProducer::isPackedCandidate ( reco::Candidate const *  candidate) const
private

Definition at line 180 of file HiFJRhoProducer.cc.

References checkJetCand_, Exception, and usingPackedCand_.

Referenced by calcMd().

180  {
181  // check if using packed candidates on the first call and cache the information
182  std::call_once(checkJetCand_, [&]() {
183  if (typeid(pat::PackedCandidate) == typeid(*candidate))
184  usingPackedCand_ = true;
185  else if (typeid(reco::PFCandidate) == typeid(*candidate))
186  usingPackedCand_ = false;
187  else
188  throw cms::Exception("WrongJetCollection", "Jet constituents are not particle flow candidates");
189  });
190  return usingPackedCand_;
191 }
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
std::once_flag checkJetCand_

◆ produce()

void HiFJRhoProducer::produce ( edm::StreamID  ,
edm::Event iEvent,
edm::EventSetup const &  iSetup 
) const
overrideprivatevirtual

Implements edm::global::EDProducerBase.

Definition at line 73 of file HiFJRhoProducer.cc.

References custom_jme_cff::area, calcMd(), calcMedian(), MillePedeFileConverter_cfg::e, PVValHelper::eta, ALCARECOTkAlBeamHalo_cff::etaMax, etaMaxExcl2_, etaMaxExcl_, ALCARECOTkAlBeamHalo_cff::etaMin, etaRanges_, mps_fire::i, hcalRecHitTable_cff::ieta, iEvent, metsig::jet, PDWG_EXODelayedJetMET_cff::jets, jetsToken_, eostools::move(), neta, nExcl2_, nExcl_, BTaggingMonitoring_cff::njets, DiDispStaMuonMonitor_cfi::pt, ptMinExcl2_, ptMinExcl_, and CosmicsPD_Skims::radius.

73  {
74  // get the inputs jets
76  iEvent.getByToken(jetsToken_, jets);
77 
78  int neta = static_cast<int>(etaRanges_.size());
79  auto mapEtaRangesOut = std::make_unique<std::vector<double>>(neta, -999.);
80 
81  for (int ieta = 0; ieta < neta; ieta++) {
82  mapEtaRangesOut->at(ieta) = etaRanges_[ieta];
83  }
84  auto mapToRhoOut = std::make_unique<std::vector<double>>(neta - 1, 1e-6);
85  auto mapToRhoMOut = std::make_unique<std::vector<double>>(neta - 1, 1e-6);
86 
87  int njets = static_cast<int>(jets->size());
88 
89  auto ptJetsOut = std::make_unique<std::vector<double>>();
90  ptJetsOut->reserve(njets);
91  auto areaJetsOut = std::make_unique<std::vector<double>>();
92  areaJetsOut->reserve(njets);
93  auto etaJetsOut = std::make_unique<std::vector<double>>();
94  etaJetsOut->reserve(njets);
95 
96  std::vector<double> rhoVec;
97  rhoVec.reserve(njets);
98  std::vector<double> rhomVec;
99  rhomVec.reserve(njets);
100 
101  int nacc = 0;
102  unsigned int njetsEx = 0;
103  unsigned int njetsEx2 = 0;
104  for (auto const& jet : *jets) {
105  if (njetsEx < nExcl_ and fabs(jet.eta()) < etaMaxExcl_ and jet.pt() > ptMinExcl_) {
106  ++njetsEx;
107  continue;
108  }
109  if (njetsEx2 < nExcl2_ and fabs(jet.eta()) < etaMaxExcl2_ and fabs(jet.eta()) > etaMaxExcl_ and
110  jet.pt() > ptMinExcl2_) {
111  ++njetsEx2;
112  continue;
113  }
114  float pt = jet.pt();
115  float area = jet.jetArea();
116  float eta = jet.eta();
117 
118  if (eta < mapEtaRangesOut->at(0) || eta > mapEtaRangesOut->at(neta - 1))
119  continue;
120  if (area > 0.) {
121  rhoVec.push_back(pt / area);
122  rhomVec.push_back(calcMd(jet) / area);
123  ptJetsOut->push_back(pt);
124  areaJetsOut->push_back(area);
125  etaJetsOut->push_back(eta);
126  ++nacc;
127  }
128  }
129 
130  // calculate rho and rhom in eta ranges
131  const double radius = 0.2; // distance kt clusters needs to be from edge
132  for (int ieta = 0; ieta < (neta - 1); ++ieta) {
133  std::vector<double> rhoVecCur;
134  rhoVecCur.reserve(nacc);
135  std::vector<double> rhomVecCur;
136  rhomVecCur.reserve(nacc);
137 
138  double etaMin = mapEtaRangesOut->at(ieta) + radius;
139  double etaMax = mapEtaRangesOut->at(ieta + 1) - radius;
140 
141  for (int i = 0; i < nacc; ++i) {
142  if ((*etaJetsOut)[i] >= etaMin and (*etaJetsOut)[i] < etaMax) {
143  rhoVecCur.push_back(rhoVec[i]);
144  rhomVecCur.push_back(rhomVec[i]);
145  } // eta selection
146  } // accepted jet loop
147 
148  if (not rhoVecCur.empty()) {
149  mapToRhoOut->at(ieta) = calcMedian(rhoVecCur);
150  mapToRhoMOut->at(ieta) = calcMedian(rhomVecCur);
151  }
152  } // eta ranges
153 
154  iEvent.put(std::move(mapEtaRangesOut), "mapEtaEdges");
155  iEvent.put(std::move(mapToRhoOut), "mapToRho");
156  iEvent.put(std::move(mapToRhoMOut), "mapToRhoM");
157  iEvent.put(std::move(ptJetsOut), "ptJets");
158  iEvent.put(std::move(areaJetsOut), "areaJets");
159  iEvent.put(std::move(etaJetsOut), "etaJets");
160 }
double calcMedian(std::vector< double > &v) const
const double etaMaxExcl2_
const unsigned int nExcl2_
int iEvent
Definition: GenABIO.cc:224
const double etaMaxExcl_
const int neta
const std::vector< double > etaRanges_
double calcMd(reco::Jet const &jet) const
const double ptMinExcl2_
const double ptMinExcl_
const unsigned int nExcl_
def move(src, dest)
Definition: eostools.py:511
const edm::EDGetTokenT< edm::View< reco::Jet > > jetsToken_

Member Data Documentation

◆ checkJetCand_

std::once_flag HiFJRhoProducer::checkJetCand_
mutableprivate

Definition at line 47 of file HiFJRhoProducer.cc.

Referenced by isPackedCandidate().

◆ etaMaxExcl2_

const double HiFJRhoProducer::etaMaxExcl2_
private

Definition at line 44 of file HiFJRhoProducer.cc.

Referenced by produce().

◆ etaMaxExcl_

const double HiFJRhoProducer::etaMaxExcl_
private

Definition at line 42 of file HiFJRhoProducer.cc.

Referenced by produce().

◆ etaRanges_

const std::vector<double> HiFJRhoProducer::etaRanges_
private

Definition at line 46 of file HiFJRhoProducer.cc.

Referenced by produce().

◆ jetsToken_

const edm::EDGetTokenT<edm::View<reco::Jet> > HiFJRhoProducer::jetsToken_
private

Definition at line 39 of file HiFJRhoProducer.cc.

Referenced by produce().

◆ nExcl2_

const unsigned int HiFJRhoProducer::nExcl2_
private

Definition at line 41 of file HiFJRhoProducer.cc.

Referenced by produce().

◆ nExcl_

const unsigned int HiFJRhoProducer::nExcl_
private

Definition at line 40 of file HiFJRhoProducer.cc.

Referenced by produce().

◆ ptMinExcl2_

const double HiFJRhoProducer::ptMinExcl2_
private

Definition at line 45 of file HiFJRhoProducer.cc.

Referenced by produce().

◆ ptMinExcl_

const double HiFJRhoProducer::ptMinExcl_
private

Definition at line 43 of file HiFJRhoProducer.cc.

Referenced by produce().

◆ usingPackedCand_

bool HiFJRhoProducer::usingPackedCand_ = false
mutableprivate

Definition at line 48 of file HiFJRhoProducer.cc.

Referenced by isPackedCandidate().