CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Member Functions | Protected Attributes
l1tpf_impl::PuppiAlgo Class Reference

#include <PuppiAlgo.h>

Inheritance diagram for l1tpf_impl::PuppiAlgo:
l1tpf_impl::PUAlgoBase l1tpf_impl::LinearizedPuppiAlgo

Public Member Functions

void doPUGlobals (const std::vector< Region > &rs, float npu, std::vector< float > &globals) const override
 
const std::vector< std::string > & puGlobalNames () const override
 
 PuppiAlgo (const edm::ParameterSet &)
 
void runNeutralsPU (Region &r, float npu, const std::vector< float > &globals) const override
 
 ~PuppiAlgo () override
 
- Public Member Functions inherited from l1tpf_impl::PUAlgoBase
virtual void doVertexing (std::vector< Region > &rs, VertexAlgo algo, float &vz) const
 
 PUAlgoBase (const edm::ParameterSet &)
 
virtual void runChargedPV (Region &r, float z0) const
 
virtual ~PUAlgoBase ()
 

Protected Member Functions

virtual void computePuppiAlphas (const Region &r, std::vector< float > &alphaC, std::vector< float > &alphaF) const
 
virtual void computePuppiMedRMS (const std::vector< Region > &rs, float &alphaCMed, float &alphaCRms, float &alphaFMed, float &alphaFRms) const
 
void computePuppiWeights (Region &r, const std::vector< float > &alphaC, const std::vector< float > &alphaF, float alphaCMed, float alphaCRms, float alphaFMed, float alphaFRms) const
 
virtual void fillPuppi (Region &r) const
 

Protected Attributes

std::vector< int16_t > intPuppiEtaCuts_
 
std::vector< int16_t > intPuppiPtCuts_
 
std::vector< int16_t > intPuppiPtCutsPhotons_
 
float puppiDr_
 
float puppiDrMin_
 
std::vector< float > puppiEtaCuts_
 
std::vector< float > puppiPtCuts_
 
std::vector< float > puppiPtCutsPhotons_
 
float puppiPtMax_
 
bool puppiUsingBareTracks_
 
- Protected Attributes inherited from l1tpf_impl::PUAlgoBase
int debug_
 
float etaCharged_
 
bool vtxAdaptiveCut_
 
float vtxRes_
 

Additional Inherited Members

- Public Types inherited from l1tpf_impl::PUAlgoBase
enum  VertexAlgo { VertexAlgo::Old, VertexAlgo::TP, VertexAlgo::External }
 global operations More...
 

Detailed Description

Definition at line 8 of file PuppiAlgo.h.

Constructor & Destructor Documentation

◆ PuppiAlgo()

PuppiAlgo::PuppiAlgo ( const edm::ParameterSet iConfig)

Definition at line 19 of file PuppiAlgo.cc.

References l1tpf_impl::PUAlgoBase::debug_, Exception, edm::ParameterSet::getUntrackedParameter(), mps_fire::i, intPuppiEtaCuts_, intPuppiPtCuts_, intPuppiPtCutsPhotons_, dqmiodumpmetadata::n, puppiEtaCuts_, puppiPtCuts_, and puppiPtCutsPhotons_.

20  : PUAlgoBase(iConfig),
21  puppiDr_(iConfig.getParameter<double>("puppiDr")),
22  puppiDrMin_(iConfig.getParameter<double>("puppiDrMin")),
23  puppiPtMax_(iConfig.getParameter<double>("puppiPtMax")),
24  puppiEtaCuts_(vd2vf(iConfig.getParameter<std::vector<double>>("puppiEtaCuts"))),
25  puppiPtCuts_(vd2vf(iConfig.getParameter<std::vector<double>>("puppiPtCuts"))),
26  puppiPtCutsPhotons_(vd2vf(iConfig.getParameter<std::vector<double>>("puppiPtCutsPhotons"))),
27  puppiUsingBareTracks_(iConfig.getParameter<bool>("puppiUsingBareTracks")) {
28  debug_ = iConfig.getUntrackedParameter<int>("puppiDebug", debug_);
29  if (puppiEtaCuts_.size() != puppiPtCuts_.size() || puppiPtCuts_.size() != puppiPtCutsPhotons_.size()) {
30  throw cms::Exception("Configuration", "Bad PUPPI config");
31  }
32  for (unsigned int i = 0, n = puppiEtaCuts_.size(); i < n; ++i) {
33  intPuppiEtaCuts_.push_back(std::round(puppiEtaCuts_[i] * CaloCluster::ETAPHI_SCALE));
34  intPuppiPtCuts_.push_back(std::round(puppiPtCuts_[i] * CaloCluster::PT_SCALE));
35  intPuppiPtCutsPhotons_.push_back(std::round(puppiPtCutsPhotons_[i] * CaloCluster::PT_SCALE));
36  }
37 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< int16_t > intPuppiEtaCuts_
Definition: PuppiAlgo.h:32
T getUntrackedParameter(std::string const &, T const &) const
PUAlgoBase(const edm::ParameterSet &)
Definition: PUAlgoBase.cc:7
std::vector< int16_t > intPuppiPtCutsPhotons_
Definition: PuppiAlgo.h:32
std::vector< float > puppiPtCutsPhotons_
Definition: PuppiAlgo.h:31
std::vector< float > puppiPtCuts_
Definition: PuppiAlgo.h:31
std::vector< float > puppiEtaCuts_
Definition: PuppiAlgo.h:31
std::vector< int16_t > intPuppiPtCuts_
Definition: PuppiAlgo.h:32

◆ ~PuppiAlgo()

PuppiAlgo::~PuppiAlgo ( )
override

Definition at line 39 of file PuppiAlgo.cc.

39 {}

Member Function Documentation

◆ computePuppiAlphas()

void PuppiAlgo::computePuppiAlphas ( const Region r,
std::vector< float > &  alphaC,
std::vector< float > &  alphaF 
) const
protectedvirtual

Definition at line 57 of file PuppiAlgo.cc.

References HLTMuonOfflineAnalyzer_cfi::deltaR2, SiStripPI::min, np, AlCaHLTBitMon_ParallelJobs::p, SiStripOfflineCRack_cfg::p2, funct::pow(), puppiDr_, puppiDrMin_, puppiPtMax_, puppiUsingBareTracks_, alignCSCRings::r, and w().

Referenced by runNeutralsPU(), and l1tpf_impl::LinearizedPuppiAlgo::runNeutralsPU().

57  {
58  alphaC.resize(r.pf.size());
59  alphaF.resize(r.pf.size());
60  float puppiDr2 = std::pow(puppiDr_, 2), puppiDr2min = std::pow(puppiDrMin_, 2);
61  for (unsigned int ip = 0, np = r.pf.size(); ip < np; ++ip) {
62  const PFParticle &p = r.pf[ip];
63  if (p.hwId <= 1)
64  continue;
65  // neutral
66  alphaC[ip] = 0;
67  alphaF[ip] = 0;
68  for (const PFParticle &p2 : r.pf) {
69  float dr2 = ::deltaR2(p.floatEta(), p.floatPhi(), p2.floatEta(), p2.floatPhi());
70  if (dr2 > 0 && dr2 < puppiDr2) {
71  float w = std::pow(std::min(p2.floatPt(), puppiPtMax_), 2) / std::max<float>(puppiDr2min, dr2);
72  alphaF[ip] += w;
73  if (p2.chargedPV)
74  alphaC[ip] += w;
75  }
76  }
78  alphaC[ip] = 0;
79  for (const PropagatedTrack &p2 : r.track) {
80  if (!p2.fromPV)
81  continue;
82  float dr2 = ::deltaR2(p.floatEta(), p.floatPhi(), p2.floatEta(), p2.floatPhi());
83  if (dr2 > 0 && dr2 < puppiDr2) {
84  alphaC[ip] += std::pow(std::min(p2.floatPt(), puppiPtMax_), 2) / std::max<float>(puppiDr2min, dr2);
85  }
86  }
87  }
88  }
89 }
T w() const
int np
Definition: AMPTWrapper.h:43
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ computePuppiMedRMS()

void PuppiAlgo::computePuppiMedRMS ( const std::vector< Region > &  rs,
float &  alphaCMed,
float &  alphaCRms,
float &  alphaFMed,
float &  alphaFRms 
) const
protectedvirtual

Definition at line 157 of file PuppiAlgo.cc.

References funct::abs(), alpha, central, dbgPrintf(), l1tpf_impl::PUAlgoBase::debug_, HLTMuonOfflineAnalyzer_cfi::deltaR2, l1tpf_impl::PUAlgoBase::etaCharged_, dqm-mbProfile::log, SiStripPI::min, AlCaHLTBitMon_ParallelJobs::p, SiStripOfflineCRack_cfg::p2, funct::pow(), puppiDr_, puppiDrMin_, puppiPtMax_, puppiUsingBareTracks_, alignCSCRings::r, jetUpdater_cfi::sort, mathSSE::sqrt(), and w().

Referenced by doPUGlobals().

158  {
159  std::vector<float> alphaFs;
160  std::vector<float> alphaCs;
161  int16_t ietacut = std::round(etaCharged_ * CaloCluster::ETAPHI_SCALE);
162  float puppiDr2 = std::pow(puppiDr_, 2), puppiDr2min = std::pow(puppiDrMin_, 2);
163  for (const Region &r : rs) {
164  for (const PFParticle &p : r.pf) {
165  bool central = std::abs(p.hwEta) < ietacut;
166  if (r.relativeCoordinates)
167  central = (r.globalAbsEta(p.floatEta()) < etaCharged_); // FIXME could make a better integer implementation
168  if (central) {
169  if (p.hwId > 1 || p.chargedPV)
170  continue;
171  }
172  float alphaC = 0, alphaF = 0;
173  for (const PFParticle &p2 : r.pf) {
174  float dr2 = ::deltaR2(p.floatEta(), p.floatPhi(), p2.floatEta(), p2.floatPhi());
175  if (dr2 > 0 && dr2 < puppiDr2) {
176  float w = std::pow(std::min(p2.floatPt(), puppiPtMax_), 2) / std::max<float>(puppiDr2min, dr2);
177  alphaF += w;
178  if (p2.chargedPV)
179  alphaC += w;
180  }
181  }
182  if (puppiUsingBareTracks_) {
183  alphaC = 0;
184  for (const PropagatedTrack &p2 : r.track) {
185  if (!p2.fromPV)
186  continue;
187  float dr2 = ::deltaR2(p.floatEta(), p.floatPhi(), p2.floatEta(), p2.floatPhi());
188  if (dr2 > 0 && dr2 < puppiDr2) {
189  alphaC += std::pow(std::min(p2.floatPt(), puppiPtMax_), 2) / std::max<float>(puppiDr2min, dr2);
190  }
191  }
192  }
193  if (central) {
194  if (alphaC > 0)
195  alphaCs.push_back(std::log(alphaC));
196  } else {
197  if (alphaF > 0)
198  alphaFs.push_back(std::log(alphaF));
199  }
200  }
201  }
202  std::sort(alphaCs.begin(), alphaCs.end());
203  std::sort(alphaFs.begin(), alphaFs.end());
204 
205  if (alphaCs.size() > 1) {
206  alphaCMed = alphaCs[alphaCs.size() / 2 + 1];
207  double sum = 0.0;
208  for (float alpha : alphaCs)
209  sum += std::pow(alpha - alphaCMed, 2);
210  alphaCRms = std::sqrt(float(sum) / alphaCs.size());
211  } else {
212  alphaCMed = 8.;
213  alphaCRms = 8.;
214  }
215 
216  if (alphaFs.size() > 1) {
217  alphaFMed = alphaFs[alphaFs.size() / 2 + 1];
218  double sum = 0.0;
219  for (float alpha : alphaFs)
220  sum += std::pow(alpha - alphaFMed, 2);
221  alphaFRms = std::sqrt(float(sum) / alphaFs.size());
222  } else {
223  alphaFMed = 6.;
224  alphaFRms = 6.;
225  }
226  if (debug_)
227  dbgPrintf("PUPPI \t alphaC = %+6.2f +- %6.2f (%4lu), alphaF = %+6.2f +- %6.2f (%4lu)\n",
228  alphaCMed,
229  alphaCRms,
230  alphaCs.size(),
231  alphaFMed,
232  alphaFRms,
233  alphaFs.size());
234 }
float alpha
Definition: AMPTWrapper.h:105
T w() const
void dbgPrintf(const char *formatString, Args &&...args)
Definition: dbgPrintf.h:5
T sqrt(T t)
Definition: SSEVec.h:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ computePuppiWeights()

void PuppiAlgo::computePuppiWeights ( Region r,
const std::vector< float > &  alphaC,
const std::vector< float > &  alphaF,
float  alphaCMed,
float  alphaCRms,
float  alphaFMed,
float  alphaFRms 
) const
protected

Definition at line 91 of file PuppiAlgo.cc.

References funct::abs(), alpha, central, l1t::PFCandidate::ChargedHadron, dbgPrintf(), l1tpf_impl::PUAlgoBase::debug_, l1t::PFCandidate::Electron, l1tpf_impl::PUAlgoBase::etaCharged_, dqm-mbProfile::log, l1t::PFCandidate::Muon, np, AlCaHLTBitMon_ParallelJobs::p, funct::pow(), alignCSCRings::r, and testProducerWithPsetDescEmpty_cfi::x2.

Referenced by runNeutralsPU().

97  {
98  int16_t ietacut = std::round(etaCharged_ * CaloCluster::ETAPHI_SCALE);
99  for (unsigned int ip = 0, np = r.pf.size(); ip < np; ++ip) {
100  PFParticle &p = r.pf[ip];
101  // charged
103  p.hwId == l1t::PFCandidate::Muon) {
104  p.setPuppiW(p.chargedPV || p.hwId == l1t::PFCandidate::Muon ? 1.0 : 0);
105  if (debug_)
106  dbgPrintf(
107  "PUPPI \t charged id %1d pt %7.2f eta %+5.2f phi %+5.2f alpha %+7.2f x2 %+7.2f --> puppi weight %.3f "
108  "puppi pt %7.2f \n",
109  p.hwId,
110  p.floatPt(),
111  p.floatEta(),
112  p.floatPhi(),
113  0.,
114  0.,
115  p.floatPuppiW(),
116  p.floatPt() * p.floatPuppiW());
117  continue;
118  }
119  // neutral
120  float alpha = -99, x2 = -99;
121  bool central = std::abs(p.hwEta) < ietacut;
122  if (r.relativeCoordinates)
123  central =
124  (std::abs(r.globalAbsEta(p.floatEta())) < etaCharged_); // FIXME could make a better integer implementation
125  if (central) {
126  if (alphaC[ip] > 0) {
127  alpha = std::log(alphaC[ip]);
128  x2 = (alpha - alphaCMed) * std::abs(alpha - alphaCMed) / std::pow(alphaCRms, 2);
129  p.setPuppiW(ROOT::Math::chisquared_cdf(x2, 1));
130  } else {
131  p.setPuppiW(0);
132  }
133  } else {
134  if (alphaF[ip] > 0) {
135  alpha = std::log(alphaF[ip]);
136  x2 = (alpha - alphaFMed) * std::abs(alpha - alphaFMed) / std::pow(alphaFRms, 2);
137  p.setPuppiW(ROOT::Math::chisquared_cdf(x2, 1));
138  } else {
139  p.setPuppiW(0);
140  }
141  }
142  if (debug_)
143  dbgPrintf(
144  "PUPPI \t neutral id %1d pt %7.2f eta %+5.2f phi %+5.2f alpha %+7.2f x2 %+7.2f --> puppi weight %.3f "
145  "puppi pt %7.2f \n",
146  p.hwId,
147  p.floatPt(),
148  p.floatEta(),
149  p.floatPhi(),
150  alpha,
151  x2,
152  p.floatPuppiW(),
153  p.floatPt() * p.floatPuppiW());
154  }
155 }
float alpha
Definition: AMPTWrapper.h:105
void dbgPrintf(const char *formatString, Args &&...args)
Definition: dbgPrintf.h:5
int np
Definition: AMPTWrapper.h:43
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ doPUGlobals()

void PuppiAlgo::doPUGlobals ( const std::vector< Region > &  rs,
float  npu,
std::vector< float > &  globals 
) const
overridevirtual

Implements l1tpf_impl::PUAlgoBase.

Definition at line 45 of file PuppiAlgo.cc.

References computePuppiMedRMS().

45  {
46  globals.resize(4);
47  computePuppiMedRMS(rs, globals[0], globals[1], globals[2], globals[3]);
48 }
virtual void computePuppiMedRMS(const std::vector< Region > &rs, float &alphaCMed, float &alphaCRms, float &alphaFMed, float &alphaFRms) const
Definition: PuppiAlgo.cc:157

◆ fillPuppi()

void PuppiAlgo::fillPuppi ( Region r) const
protectedvirtual

Definition at line 236 of file PuppiAlgo.cc.

References funct::abs(), l1t::PFCandidate::ChargedHadron, l1t::PFCandidate::Electron, dqmMemoryStats::float, intPuppiEtaCuts_, intPuppiPtCuts_, intPuppiPtCutsPhotons_, l1t::PFCandidate::Muon, seedmultiplicitymonitor_newtracking_cfi::nBins, AlCaHLTBitMon_ParallelJobs::p, l1t::PFCandidate::Photon, and alignCSCRings::r.

Referenced by runNeutralsPU(), and l1tpf_impl::LinearizedPuppiAlgo::runNeutralsPU().

236  {
237  uint16_t PUPPIW_0p01 = std::round(0.01 * PFParticle::PUPPI_SCALE);
238  r.puppi.clear();
239  for (PFParticle &p : r.pf) {
241  p.hwId == l1t::PFCandidate::Muon) { // charged
242  if (p.hwPuppiWeight > 0) {
243  r.puppi.push_back(p);
244  }
245  } else { // neutral
246  if (p.hwPuppiWeight > PUPPIW_0p01) {
247  // FIXME would work better with PUPPI_SCALE being a power of two, to do the shift
248  // FIXME done with floats
249  int16_t hwPt = (float(p.hwPt) * float(p.hwPuppiWeight) / float(PFParticle::PUPPI_SCALE));
250  int16_t hwPtCut = 0, hwAbsEta = r.relativeCoordinates
251  ? round(r.globalAbsEta(p.floatEta()) * CaloCluster::ETAPHI_SCALE)
252  : std::abs(p.hwEta);
253  for (unsigned int ietaBin = 0, nBins = intPuppiEtaCuts_.size(); ietaBin < nBins; ++ietaBin) {
254  if (hwAbsEta < intPuppiEtaCuts_[ietaBin]) {
255  hwPtCut = (p.hwId == l1t::PFCandidate::Photon ? intPuppiPtCutsPhotons_[ietaBin] : intPuppiPtCuts_[ietaBin]);
256  break;
257  }
258  }
259  if (hwPt > hwPtCut) {
260  r.puppi.push_back(p);
261  r.puppi.back().hwPt = hwPt;
262  }
263  }
264  }
265  }
266 }
std::vector< int16_t > intPuppiEtaCuts_
Definition: PuppiAlgo.h:32
std::vector< int16_t > intPuppiPtCutsPhotons_
Definition: PuppiAlgo.h:32
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< int16_t > intPuppiPtCuts_
Definition: PuppiAlgo.h:32

◆ puGlobalNames()

const std::vector< std::string > & PuppiAlgo::puGlobalNames ( ) const
overridevirtual

Reimplemented from l1tpf_impl::PUAlgoBase.

Definition at line 41 of file PuppiAlgo.cc.

41  {
42  static const std::vector<std::string> names_{"alphaCMed", "alphaCRms", "alphaFMed", "alphaFRms"};
43  return names_;
44 }

◆ runNeutralsPU()

void PuppiAlgo::runNeutralsPU ( Region r,
float  npu,
const std::vector< float > &  globals 
) const
overridevirtual

Implements l1tpf_impl::PUAlgoBase.

Definition at line 50 of file PuppiAlgo.cc.

References computePuppiAlphas(), computePuppiWeights(), fillPuppi(), and alignCSCRings::r.

50  {
51  std::vector<float> alphaC, alphaF;
52  computePuppiAlphas(r, alphaC, alphaF);
53  computePuppiWeights(r, alphaC, alphaF, globals[0], globals[1], globals[2], globals[3]);
54  fillPuppi(r);
55 }
virtual void fillPuppi(Region &r) const
Definition: PuppiAlgo.cc:236
virtual void computePuppiAlphas(const Region &r, std::vector< float > &alphaC, std::vector< float > &alphaF) const
Definition: PuppiAlgo.cc:57
void computePuppiWeights(Region &r, const std::vector< float > &alphaC, const std::vector< float > &alphaF, float alphaCMed, float alphaCRms, float alphaFMed, float alphaFRms) const
Definition: PuppiAlgo.cc:91

Member Data Documentation

◆ intPuppiEtaCuts_

std::vector<int16_t> l1tpf_impl::PuppiAlgo::intPuppiEtaCuts_
protected

Definition at line 32 of file PuppiAlgo.h.

Referenced by fillPuppi(), and PuppiAlgo().

◆ intPuppiPtCuts_

std::vector<int16_t> l1tpf_impl::PuppiAlgo::intPuppiPtCuts_
protected

Definition at line 32 of file PuppiAlgo.h.

Referenced by fillPuppi(), and PuppiAlgo().

◆ intPuppiPtCutsPhotons_

std::vector<int16_t> l1tpf_impl::PuppiAlgo::intPuppiPtCutsPhotons_
protected

Definition at line 32 of file PuppiAlgo.h.

Referenced by fillPuppi(), and PuppiAlgo().

◆ puppiDr_

float l1tpf_impl::PuppiAlgo::puppiDr_
protected

Definition at line 30 of file PuppiAlgo.h.

Referenced by computePuppiAlphas(), and computePuppiMedRMS().

◆ puppiDrMin_

float l1tpf_impl::PuppiAlgo::puppiDrMin_
protected

Definition at line 30 of file PuppiAlgo.h.

Referenced by computePuppiAlphas(), and computePuppiMedRMS().

◆ puppiEtaCuts_

std::vector<float> l1tpf_impl::PuppiAlgo::puppiEtaCuts_
protected

◆ puppiPtCuts_

std::vector<float> l1tpf_impl::PuppiAlgo::puppiPtCuts_
protected

Definition at line 31 of file PuppiAlgo.h.

Referenced by PuppiAlgo().

◆ puppiPtCutsPhotons_

std::vector<float> l1tpf_impl::PuppiAlgo::puppiPtCutsPhotons_
protected

Definition at line 31 of file PuppiAlgo.h.

Referenced by PuppiAlgo().

◆ puppiPtMax_

float l1tpf_impl::PuppiAlgo::puppiPtMax_
protected

Definition at line 30 of file PuppiAlgo.h.

Referenced by computePuppiAlphas(), and computePuppiMedRMS().

◆ puppiUsingBareTracks_

bool l1tpf_impl::PuppiAlgo::puppiUsingBareTracks_
protected

Definition at line 33 of file PuppiAlgo.h.

Referenced by computePuppiAlphas(), and computePuppiMedRMS().