CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
LinearizedPuppiAlgo.cc
Go to the documentation of this file.
6 
7 #include "Math/ProbFunc.h"
8 
9 namespace {
10  std::vector<float> vd2vf(const std::vector<double> &vd) {
11  std::vector<float> ret;
12  ret.insert(ret.end(), vd.begin(), vd.end());
13  return ret;
14  }
15 } // namespace
16 
17 using namespace l1tpf_impl;
18 
20  : PuppiAlgo(iConfig),
21  puppiPriors_(vd2vf(iConfig.getParameter<std::vector<double>>("puppiPriors"))),
22  puppiPriorsPhotons_(vd2vf(iConfig.getParameter<std::vector<double>>("puppiPriorsPhotons"))),
23  puppiPtSlopes_(vd2vf(iConfig.getParameter<std::vector<double>>("puppiPtSlopes"))),
24  puppiPtSlopesPhotons_(vd2vf(iConfig.getParameter<std::vector<double>>("puppiPtSlopesPhotons"))),
25  puppiPtZeros_(vd2vf(iConfig.getParameter<std::vector<double>>("puppiPtZeros"))),
26  puppiPtZerosPhotons_(vd2vf(iConfig.getParameter<std::vector<double>>("puppiPtZerosPhotons"))),
27  puppiAlphaSlopes_(vd2vf(iConfig.getParameter<std::vector<double>>("puppiAlphaSlopes"))),
28  puppiAlphaSlopesPhotons_(vd2vf(iConfig.getParameter<std::vector<double>>("puppiAlphaSlopesPhotons"))),
29  puppiAlphaZeros_(vd2vf(iConfig.getParameter<std::vector<double>>("puppiAlphaZeros"))),
30  puppiAlphaZerosPhotons_(vd2vf(iConfig.getParameter<std::vector<double>>("puppiAlphaZerosPhotons"))),
31  puppiAlphaCrops_(vd2vf(iConfig.getParameter<std::vector<double>>("puppiAlphaCrops"))),
32  puppiAlphaCropsPhotons_(vd2vf(iConfig.getParameter<std::vector<double>>("puppiAlphaCropsPhotons"))) {
33  if (puppiPriors_.size() != puppiEtaCuts_.size())
34  throw cms::Exception("Configuration", "Mismatched lenght for puppiPriors\n");
35  if (puppiPtSlopes_.size() != puppiEtaCuts_.size())
36  throw cms::Exception("Configuration", "Mismatched lenght for puppiPtSlopes\n");
37  if (puppiPtZeros_.size() != puppiEtaCuts_.size())
38  throw cms::Exception("Configuration", "Mismatched lenght for puppiPtZeros\n");
39  if (puppiAlphaSlopes_.size() != puppiEtaCuts_.size())
40  throw cms::Exception("Configuration", "Mismatched lenght for puppiAlphaSlopes\n");
41  if (puppiAlphaZeros_.size() != puppiEtaCuts_.size())
42  throw cms::Exception("Configuration", "Mismatched lenght for puppiAlphaZeros\n");
43  if (puppiAlphaCrops_.size() != puppiEtaCuts_.size())
44  throw cms::Exception("Configuration", "Mismatched lenght for puppiAlphaCrops\n");
45  if (puppiPriorsPhotons_.size() != puppiEtaCuts_.size())
46  throw cms::Exception("Configuration", "Mismatched lenght for puppiPriorsPhotons\n");
47  if (puppiPtSlopesPhotons_.size() != puppiEtaCuts_.size())
48  throw cms::Exception("Configuration", "Mismatched lenght for puppiPtSlopesPhotons\n");
49  if (puppiPtZerosPhotons_.size() != puppiEtaCuts_.size())
50  throw cms::Exception("Configuration", "Mismatched lenght for puppiPtZerosPhotons\n");
51  if (puppiAlphaSlopesPhotons_.size() != puppiEtaCuts_.size())
52  throw cms::Exception("Configuration", "Mismatched lenght for puppiAlphaSlopesPhotons\n");
53  if (puppiAlphaZerosPhotons_.size() != puppiEtaCuts_.size())
54  throw cms::Exception("Configuration", "Mismatched lenght for puppiAlphaZerosPhotons\n");
55  if (puppiAlphaCropsPhotons_.size() != puppiEtaCuts_.size())
56  throw cms::Exception("Configuration", "Mismatched lenght for puppiAlphaCropsPhotons\n");
57 }
58 
60 
61 const std::vector<std::string> &LinearizedPuppiAlgo::puGlobalNames() const {
62  static const std::vector<std::string> names_{};
63  return names_;
64 }
65 void LinearizedPuppiAlgo::doPUGlobals(const std::vector<Region> &rs, float npu, std::vector<float> &globals) const {
66  globals.clear();
67 }
68 void LinearizedPuppiAlgo::runNeutralsPU(Region &r, float npu, const std::vector<float> &globals) const {
69  std::vector<float> alphaC, alphaF;
70  PuppiAlgo::computePuppiAlphas(r, alphaC, alphaF);
71  computePuppiWeights(r, npu, alphaC, alphaF);
73 }
74 
76  float npu,
77  const std::vector<float> &alphaC,
78  const std::vector<float> &alphaF) const {
79  if (debug_ && npu > 0)
80  dbgPrintf("LinPup\t npu estimate %7.2f --> log(npu/200) = %+6.2f \n", npu, std::log(npu / 200.f));
81  for (unsigned int ip = 0, np = r.pf.size(); ip < np; ++ip) {
82  PFParticle &p = r.pf[ip];
83  // charged
86  p.setPuppiW(p.chargedPV || p.hwId == l1t::PFCandidate::Muon ? 1.0 : 0);
87  if (debug_ == 2)
88  dbgPrintf(
89  "LinPup\t charged id %1d pt %7.2f eta %+5.2f phi %+5.2f fromPV %1d "
90  " --> puppi weight %.3f puppi pt %7.2f \n",
91  p.hwId,
92  p.floatPt(),
93  p.floatEta(),
94  p.floatPhi(),
95  p.chargedPV,
96  p.floatPuppiW(),
97  p.floatPt() * p.floatPuppiW());
98  continue;
99  }
100  // neutral
101  float absEta = r.relativeCoordinates ? r.globalAbsEta(p.floatEta()) : std::abs(p.floatEta());
102  bool central = absEta < etaCharged_; // FIXME could make a better integer implementation
103  bool photon = (p.hwId == l1t::PFCandidate::Photon);
104  // get alpha
105  float alpha = central ? alphaC[ip] : alphaF[ip];
106  alpha = (alpha > 0 ? std::log(alpha) : 0);
107  // get eta bin
108  unsigned int ietaBin = 0, lastBin = puppiEtaCuts_.size() - 1;
109  while (ietaBin < lastBin && absEta > puppiEtaCuts_[ietaBin]) {
110  ietaBin++;
111  }
112  float alphaZero = (photon ? puppiAlphaZerosPhotons_ : puppiAlphaZeros_)[ietaBin];
113  float alphaSlope = (photon ? puppiAlphaSlopesPhotons_ : puppiAlphaSlopes_)[ietaBin];
114  float alphaCrop = (photon ? puppiAlphaCropsPhotons_ : puppiAlphaCrops_)[ietaBin];
115  float x2a = std::clamp(alphaSlope * (alpha - alphaZero), -alphaCrop, alphaCrop);
116  // weight by pT
117  float ptZero = (photon ? puppiPtZerosPhotons_ : puppiPtZeros_)[ietaBin];
118  float ptSlope = (photon ? puppiPtSlopesPhotons_ : puppiPtSlopes_)[ietaBin];
119  float x2pt = ptSlope * (p.floatPt() - ptZero);
120  // weight by prior
121  float prior = (photon ? puppiPriorsPhotons_ : puppiPriors_)[ietaBin];
122  float x2prior = (npu > 0 ? std::log(npu / 200.f) : 0) + prior;
123  // total
124  float x2 = x2a + x2pt - x2prior;
125  p.setPuppiW(1.0 / (1.0 + std::exp(-x2)));
126  if (debug_ == 1 || debug_ == 2 || debug_ == int(10 + ietaBin))
127  dbgPrintf(
128  "LinPup\t neutral id %1d pt %7.2f eta %+5.2f phi %+5.2f alpha %+6.2f x2a %+5.2f x2pt %+6.2f x2prior "
129  "%+6.2f --> x2 %+6.2f --> puppi weight %.3f puppi pt %7.2f \n",
130  p.hwId,
131  p.floatPt(),
132  p.floatEta(),
133  p.floatPhi(),
134  alpha,
135  x2a,
136  x2pt,
137  -x2prior,
138  x2,
139  p.floatPuppiW(),
140  p.floatPt() * p.floatPuppiW());
141  }
142 }
tuple ret
prodAgent to be discontinued
float alpha
Definition: AMPTWrapper.h:105
const bool relativeCoordinates
Definition: Region.h:13
static std::vector< std::string > checklist log
std::vector< float > puppiPriorsPhotons_
std::vector< float > puppiAlphaZeros_
const std::vector< std::string > & puGlobalNames() const override
std::vector< float > puppiPtSlopesPhotons_
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
float globalAbsEta(float localEta) const
Definition: Region.h:86
void dbgPrintf(const char *formatString, Args &&...args)
Definition: dbgPrintf.h:5
void runNeutralsPU(Region &r, float npu, const std::vector< float > &globals) const override
int np
Definition: AMPTWrapper.h:43
virtual void fillPuppi(Region &r) const
Definition: PuppiAlgo.cc:236
void computePuppiWeights(Region &r, float npu, const std::vector< float > &alphaC, const std::vector< float > &alphaF) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< PFParticle > pf
Definition: Region.h:9
std::vector< DeviationSensor2D * > vd
std::vector< float > puppiAlphaSlopes_
std::vector< float > puppiAlphaSlopesPhotons_
void doPUGlobals(const std::vector< Region > &rs, float npu, std::vector< float > &globals) const override
std::vector< float > puppiAlphaCrops_
dictionary prior
LinearizedPuppiAlgo(const edm::ParameterSet &)
std::vector< float > puppiEtaCuts_
Definition: PuppiAlgo.h:31
std::vector< float > puppiAlphaZerosPhotons_
virtual void computePuppiAlphas(const Region &r, std::vector< float > &alphaC, std::vector< float > &alphaF) const
Definition: PuppiAlgo.cc:57
std::vector< float > puppiAlphaCropsPhotons_
std::vector< float > puppiPtZerosPhotons_