CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
HiFJRhoProducer Class Reference

#include <HiJetBackground/HiFJRhoProducer/plugins/HiFJRhoProducer.cc>

Inheritance diagram for HiFJRhoProducer:
edm::stream::EDProducer<>

Public Member Functions

 HiFJRhoProducer (const edm::ParameterSet &)
 
 ~HiFJRhoProducer () 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)
 

Private Member Functions

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

Private Attributes

bool checkJetCand
 
double etaMaxExcl2_
 
double etaMaxExcl_
 
std::vector< double > etaRanges
 
edm::EDGetTokenT< edm::View< reco::Jet > > jetsToken_
 
unsigned int nExcl2_
 
unsigned int nExcl_
 
double ptMinExcl2_
 
double ptMinExcl_
 
edm::InputTag src_
 
bool usingPackedCand
 

Additional Inherited Members

- 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
 

Detailed Description

Description: [one line class summary]

Implementation: [Notes on implementation]

Definition at line 26 of file HiFJRhoProducer.h.

Constructor & Destructor Documentation

◆ HiFJRhoProducer()

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

Definition at line 50 of file HiFJRhoProducer.cc.

References etaRanges, edm::ParameterSet::getParameter(), jetsToken_, and src_.

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

◆ ~HiFJRhoProducer()

HiFJRhoProducer::~HiFJRhoProducer ( )
override

Definition at line 72 of file HiFJRhoProducer.cc.

72  {
73  // do anything here that needs to be done at desctruction time
74  // (e.g. close files, deallocate resources etc.)
75 }

Member Function Documentation

◆ beginStream()

void HiFJRhoProducer::beginStream ( edm::StreamID  )
overrideprivate

Definition at line 174 of file HiFJRhoProducer.cc.

174 {}

◆ calcMd()

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

Definition at line 179 of file HiFJRhoProducer.cc.

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

Referenced by produce().

179  {
180  //
181  //get md as defined in http://arxiv.org/pdf/1211.2811.pdf
182  //
183 
184  //Loop over the jet constituents
185  double sum = 0.;
186  for (auto daughter : jet->getJetConstituentsQuick()) {
187  if (isPackedCandidate(daughter)) { //packed candidate situation
188  auto part = static_cast<const pat::PackedCandidate*>(daughter);
189  sum += sqrt(part->mass() * part->mass() + part->pt() * part->pt()) - part->pt();
190  } else {
191  auto part = static_cast<const reco::PFCandidate*>(daughter);
192  sum += sqrt(part->mass() * part->mass() + part->pt() * part->pt()) - part->pt();
193  }
194  }
195 
196  return sum;
197 }
bool isPackedCandidate(const reco::Candidate *candidate)
T sqrt(T t)
Definition: SSEVec.h:19
part
Definition: HCALResponse.h:20
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41

◆ calcMedian()

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

Definition at line 226 of file HiFJRhoProducer.cc.

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

Referenced by produce().

226  {
227  //post-condition: After returning, the elements in v may be reordered and the resulting order is implementation defined.
228  //works for even and odd collections
229  if (v.empty()) {
230  return 0.0;
231  }
232  auto n = v.size() / 2;
233  std::nth_element(v.begin(), v.begin() + n, v.end());
234  auto med = v[n];
235  if (!(v.size() & 1)) { //If the set size is even
236  auto max_it = std::max_element(v.begin(), v.begin() + n);
237  med = (*max_it + med) / 2.0;
238  }
239  return med;
240 }

◆ endStream()

void HiFJRhoProducer::endStream ( )
overrideprivate

Definition at line 177 of file HiFJRhoProducer.cc.

177 {}

◆ fillDescriptions()

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

Definition at line 212 of file HiFJRhoProducer.cc.

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

212  {
214  desc.add<edm::InputTag>("jetSource", edm::InputTag("kt4PFJets"));
215  desc.add<int>("nExcl", 2);
216  desc.add<double>("etaMaxExcl", 2.);
217  desc.add<double>("ptMinExcl", 20.);
218  desc.add<int>("nExcl2", 2);
219  desc.add<double>("etaMaxExcl2", 2.);
220  desc.add<double>("ptMinExcl2", 20.);
221  desc.add<std::vector<double>>("etaRanges", {});
222  descriptions.add("hiFJRhoProducer", desc);
223 }
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ isPackedCandidate()

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

Definition at line 199 of file HiFJRhoProducer.cc.

References checkJetCand, Exception, and usingPackedCand.

Referenced by calcMd().

199  {
200  if (checkJetCand) {
201  if (typeid(pat::PackedCandidate) == typeid(*candidate))
202  usingPackedCand = true;
203  else if (typeid(reco::PFCandidate) == typeid(*candidate))
204  usingPackedCand = false;
205  else
206  throw cms::Exception("WrongJetCollection", "Jet constituents are not particle flow candidates");
207  checkJetCand = false;
208  }
209  return usingPackedCand;
210 }
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41

◆ produce()

void HiFJRhoProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 78 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, LEDCalibrationChannels::ieta, iEvent, createfilelist::int, metsig::jet, PDWG_EXODelayedJetMET_cff::jets, jetsToken_, eostools::move(), neta, nExcl2_, nExcl_, BTaggingMonitoring_cff::njets, DiDispStaMuonMonitor_cfi::pt, ptMinExcl2_, ptMinExcl_, and CosmicsPD_Skims::radius.

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

Member Data Documentation

◆ checkJetCand

bool HiFJRhoProducer::checkJetCand
private

Definition at line 55 of file HiFJRhoProducer.h.

Referenced by isPackedCandidate().

◆ etaMaxExcl2_

double HiFJRhoProducer::etaMaxExcl2_
private

Definition at line 52 of file HiFJRhoProducer.h.

Referenced by produce().

◆ etaMaxExcl_

double HiFJRhoProducer::etaMaxExcl_
private

Definition at line 49 of file HiFJRhoProducer.h.

Referenced by produce().

◆ etaRanges

std::vector<double> HiFJRhoProducer::etaRanges
private

Definition at line 54 of file HiFJRhoProducer.h.

Referenced by HiFJRhoProducer(), and produce().

◆ jetsToken_

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

Definition at line 44 of file HiFJRhoProducer.h.

Referenced by HiFJRhoProducer(), and produce().

◆ nExcl2_

unsigned int HiFJRhoProducer::nExcl2_
private

Definition at line 51 of file HiFJRhoProducer.h.

Referenced by produce().

◆ nExcl_

unsigned int HiFJRhoProducer::nExcl_
private

Definition at line 48 of file HiFJRhoProducer.h.

Referenced by produce().

◆ ptMinExcl2_

double HiFJRhoProducer::ptMinExcl2_
private

Definition at line 53 of file HiFJRhoProducer.h.

Referenced by produce().

◆ ptMinExcl_

double HiFJRhoProducer::ptMinExcl_
private

Definition at line 50 of file HiFJRhoProducer.h.

Referenced by produce().

◆ src_

edm::InputTag HiFJRhoProducer::src_
private

Definition at line 47 of file HiFJRhoProducer.h.

Referenced by HiFJRhoProducer().

◆ usingPackedCand

bool HiFJRhoProducer::usingPackedCand
private

Definition at line 55 of file HiFJRhoProducer.h.

Referenced by isPackedCandidate().