CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 ( 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 getUntrackedParameter(std::string const &, T const &) const
std::vector< int16_t > intPuppiEtaCuts_
Definition: PuppiAlgo.h:32
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
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< float > puppiEtaCuts_
Definition: PuppiAlgo.h:31
std::vector< int16_t > intPuppiPtCuts_
Definition: PuppiAlgo.h:32
PuppiAlgo::~PuppiAlgo ( )
override

Definition at line 39 of file PuppiAlgo.cc.

39 {}

Member Function Documentation

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 l1tpf_impl::PFParticle::chargedPV, reco::deltaR2(), l1tpf_impl::PropagatedTrack::fromPV, l1tpf_impl::PFParticle::hwId, min(), np, AlCaHLTBitMon_ParallelJobs::p, fireworks::p2, l1tpf_impl::Region::pf, funct::pow(), puppiDr_, puppiDrMin_, puppiPtMax_, puppiUsingBareTracks_, l1tpf_impl::InputRegion::track, 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 }
const double w
Definition: UKUtility.cc:23
const TString p2
Definition: fwPaths.cc:13
int np
Definition: AMPTWrapper.h:43
std::vector< PFParticle > pf
Definition: Region.h:9
T min(T a, T b)
Definition: MathUtil.h:58
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
std::vector< PropagatedTrack > track
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
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, l1tpf_impl::PFParticle::chargedPV, dbgPrintf(), l1tpf_impl::PUAlgoBase::debug_, reco::deltaR2(), l1tpf_impl::PUAlgoBase::etaCharged_, l1tpf_impl::PropagatedTrack::fromPV, l1tpf_impl::PFParticle::hwEta, l1tpf_impl::PFParticle::hwId, log, min(), AlCaHLTBitMon_ParallelJobs::p, fireworks::p2, funct::pow(), puppiDr_, puppiDrMin_, puppiPtMax_, puppiUsingBareTracks_, alignCSCRings::r, 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
static std::vector< std::string > checklist log
const double w
Definition: UKUtility.cc:23
const TString p2
Definition: fwPaths.cc:13
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
T min(T a, T b)
Definition: MathUtil.h:58
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
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, l1tpf_impl::PFParticle::chargedPV, dbgPrintf(), l1tpf_impl::PUAlgoBase::debug_, l1t::PFCandidate::Electron, l1tpf_impl::PUAlgoBase::etaCharged_, l1tpf_impl::Region::globalAbsEta(), l1tpf_impl::PFParticle::hwEta, l1tpf_impl::PFParticle::hwId, log, l1t::PFCandidate::Muon, np, AlCaHLTBitMon_ParallelJobs::p, l1tpf_impl::Region::pf, funct::pow(), and l1tpf_impl::Region::relativeCoordinates.

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
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
const bool relativeCoordinates
Definition: Region.h:13
static std::vector< std::string > checklist log
float globalAbsEta(float localEta) const
Definition: Region.h:86
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
std::vector< PFParticle > pf
Definition: Region.h:9
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
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
void PuppiAlgo::fillPuppi ( Region r) const
protectedvirtual

Definition at line 236 of file PuppiAlgo.cc.

References funct::abs(), l1t::PFCandidate::ChargedHadron, l1t::PFCandidate::Electron, l1tpf_impl::Region::globalAbsEta(), l1tpf_impl::PFParticle::hwEta, l1tpf_impl::PFParticle::hwId, l1tpf_impl::PFParticle::hwPt, l1tpf_impl::PFParticle::hwPuppiWeight, intPuppiEtaCuts_, intPuppiPtCuts_, intPuppiPtCutsPhotons_, l1t::PFCandidate::Muon, AlCaHLTBitMon_ParallelJobs::p, l1tpf_impl::Region::pf, l1t::PFCandidate::Photon, l1tpf_impl::Region::puppi, and l1tpf_impl::Region::relativeCoordinates.

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 }
const bool relativeCoordinates
Definition: Region.h:13
std::vector< int16_t > intPuppiEtaCuts_
Definition: PuppiAlgo.h:32
float globalAbsEta(float localEta) const
Definition: Region.h:86
std::vector< int16_t > intPuppiPtCutsPhotons_
Definition: PuppiAlgo.h:32
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< PFParticle > puppi
Definition: Region.h:10
std::vector< PFParticle > pf
Definition: Region.h:9
std::vector< int16_t > intPuppiPtCuts_
Definition: PuppiAlgo.h:32
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 }
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(), and fillPuppi().

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
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
virtual void computePuppiAlphas(const Region &r, std::vector< float > &alphaC, std::vector< float > &alphaF) const
Definition: PuppiAlgo.cc:57

Member Data Documentation

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

Definition at line 32 of file PuppiAlgo.h.

Referenced by fillPuppi(), and PuppiAlgo().

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

Definition at line 32 of file PuppiAlgo.h.

Referenced by fillPuppi(), and PuppiAlgo().

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

Definition at line 32 of file PuppiAlgo.h.

Referenced by fillPuppi(), and PuppiAlgo().

float l1tpf_impl::PuppiAlgo::puppiDr_
protected

Definition at line 30 of file PuppiAlgo.h.

Referenced by computePuppiAlphas(), and computePuppiMedRMS().

float l1tpf_impl::PuppiAlgo::puppiDrMin_
protected

Definition at line 30 of file PuppiAlgo.h.

Referenced by computePuppiAlphas(), and computePuppiMedRMS().

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

Definition at line 31 of file PuppiAlgo.h.

Referenced by PuppiAlgo().

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

Definition at line 31 of file PuppiAlgo.h.

Referenced by PuppiAlgo().

float l1tpf_impl::PuppiAlgo::puppiPtMax_
protected

Definition at line 30 of file PuppiAlgo.h.

Referenced by computePuppiAlphas(), and computePuppiMedRMS().

bool l1tpf_impl::PuppiAlgo::puppiUsingBareTracks_
protected

Definition at line 33 of file PuppiAlgo.h.

Referenced by computePuppiAlphas(), and computePuppiMedRMS().