CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndRuns () const final
 

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<>
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
 

Detailed Description

Description: [one line class summary]

Implementation: [Notes on implementation]

Definition at line 26 of file HiFJRhoProducer.h.

Constructor & Destructor Documentation

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
edm::InputTag src_
std::vector< double > etaRanges
unsigned int nExcl_
edm::EDGetTokenT< edm::View< reco::Jet > > jetsToken_
unsigned int nExcl2_
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

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

Definition at line 179 of file HiFJRhoProducer.cc.

179 {}
double HiFJRhoProducer::calcMd ( const reco::Jet jet)
private

Definition at line 184 of file HiFJRhoProducer.cc.

References reco::Jet::getJetConstituentsQuick(), isPackedCandidate(), and mathSSE::sqrt().

Referenced by produce().

184  {
185  //
186  //get md as defined in http://arxiv.org/pdf/1211.2811.pdf
187  //
188 
189  //Loop over the jet constituents
190  double sum = 0.;
191  for (auto daughter : jet->getJetConstituentsQuick()) {
192  if (isPackedCandidate(daughter)) { //packed candidate situation
193  auto part = static_cast<const pat::PackedCandidate*>(daughter);
194  sum += sqrt(part->mass() * part->mass() + part->pt() * part->pt()) - part->pt();
195  } else {
196  auto part = static_cast<const reco::PFCandidate*>(daughter);
197  sum += sqrt(part->mass() * part->mass() + part->pt() * part->pt()) - part->pt();
198  }
199  }
200 
201  return sum;
202 }
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:40
virtual std::vector< const reco::Candidate * > getJetConstituentsQuick() const
quick list of constituents
double HiFJRhoProducer::calcMedian ( std::vector< double > &  v)
private

Definition at line 231 of file HiFJRhoProducer.cc.

References DEFINE_FWK_MODULE, and dqmiodumpmetadata::n.

Referenced by produce().

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

Definition at line 182 of file HiFJRhoProducer.cc.

182 {}
void HiFJRhoProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 217 of file HiFJRhoProducer.cc.

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

217  {
219  desc.add<edm::InputTag>("jetSource", edm::InputTag("kt4PFJets"));
220  desc.add<int>("nExcl", 2);
221  desc.add<double>("etaMaxExcl", 2.);
222  desc.add<double>("ptMinExcl", 20.);
223  desc.add<int>("nExcl2", 2);
224  desc.add<double>("etaMaxExcl2", 2.);
225  desc.add<double>("ptMinExcl2", 20.);
226  desc.add<std::vector<double>>("etaRanges", {});
227  descriptions.add("hiFJRhoProducer", desc);
228 }
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool HiFJRhoProducer::isPackedCandidate ( const reco::Candidate candidate)
private

Definition at line 204 of file HiFJRhoProducer.cc.

References checkJetCand, Exception, and usingPackedCand.

Referenced by calcMd().

204  {
205  if (checkJetCand) {
206  if (typeid(pat::PackedCandidate) == typeid(*candidate))
207  usingPackedCand = true;
208  else if (typeid(reco::PFCandidate) == typeid(*candidate))
209  usingPackedCand = false;
210  else
211  throw cms::Exception("WrongJetCollection", "Jet constituents are not particle flow candidates");
212  checkJetCand = false;
213  }
214  return usingPackedCand;
215 }
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
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, edm::Event::getByToken(), mps_fire::i, LEDCalibrationChannels::ieta, createfilelist::int, metsig::jet, singleTopDQM_cfi::jets, jetsToken_, eostools::move(), nExcl2_, nExcl_, BTaggingMonitoring_cff::njets, DiDispStaMuonMonitor_cfi::pt, ptMinExcl2_, ptMinExcl_, edm::Event::put(), 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  double rhoCurSum = 0.;
147  double rhomCurSum = 0.;
148  for (int i = 0; i < nacc; i++) {
149  if (etaVec[i] >= etaMin && etaVec[i] < etaMax) {
150  rhoVecCur.push_back(rhoVec[i]);
151  rhomVecCur.push_back(rhomVec[i]);
152 
153  rhoCurSum += rhoVec[i];
154  rhomCurSum += rhomVec[i];
155  ++naccCur;
156  } //eta selection
157  } //accepted jet loop
158 
159  if (naccCur > 0) {
160  double rhoCur = calcMedian(rhoVecCur);
161  double rhomCur = calcMedian(rhomVecCur);
162  mapToRhoOut->at(ieta) = rhoCur;
163  mapToRhoMOut->at(ieta) = rhomCur;
164  }
165  } //eta ranges
166 
167  iEvent.put(std::move(mapEtaRangesOut), "mapEtaEdges");
168  iEvent.put(std::move(mapToRhoOut), "mapToRho");
169  iEvent.put(std::move(mapToRhoMOut), "mapToRhoM");
170 
171  iEvent.put(std::move(ptJetsOut), "ptJets");
172  iEvent.put(std::move(areaJetsOut), "areaJets");
173  iEvent.put(std::move(etaJetsOut), "etaJets");
174 
175  return;
176 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
double calcMedian(std::vector< double > &v)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
std::vector< double > etaRanges
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

bool HiFJRhoProducer::checkJetCand
private

Definition at line 55 of file HiFJRhoProducer.h.

Referenced by isPackedCandidate().

double HiFJRhoProducer::etaMaxExcl2_
private

Definition at line 52 of file HiFJRhoProducer.h.

Referenced by produce().

double HiFJRhoProducer::etaMaxExcl_
private

Definition at line 49 of file HiFJRhoProducer.h.

Referenced by produce().

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

Definition at line 54 of file HiFJRhoProducer.h.

Referenced by HiFJRhoProducer(), and produce().

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

Definition at line 44 of file HiFJRhoProducer.h.

Referenced by HiFJRhoProducer(), and produce().

unsigned int HiFJRhoProducer::nExcl2_
private

Definition at line 51 of file HiFJRhoProducer.h.

Referenced by produce().

unsigned int HiFJRhoProducer::nExcl_
private

Definition at line 48 of file HiFJRhoProducer.h.

Referenced by produce().

double HiFJRhoProducer::ptMinExcl2_
private

Definition at line 53 of file HiFJRhoProducer.h.

Referenced by produce().

double HiFJRhoProducer::ptMinExcl_
private

Definition at line 50 of file HiFJRhoProducer.h.

Referenced by produce().

edm::InputTag HiFJRhoProducer::src_
private

Definition at line 47 of file HiFJRhoProducer.h.

Referenced by HiFJRhoProducer().

bool HiFJRhoProducer::usingPackedCand
private

Definition at line 55 of file HiFJRhoProducer.h.

Referenced by isPackedCandidate().