CMS 3D CMS Logo

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
85  p.hwId == l1t::PFCandidate::Muon) {
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 }
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:355
l1t::PFCandidate::Photon
Definition: PFCandidate.h:15
PFCandidate.h
muons2muons_cfi.photon
photon
Definition: muons2muons_cfi.py:28
l1tpf_impl::PUAlgoBase::debug_
int debug_
Definition: PUAlgoBase.h:27
l1tpf_impl::LinearizedPuppiAlgo::puGlobalNames
const std::vector< std::string > & puGlobalNames() const override
Definition: LinearizedPuppiAlgo.cc:61
l1tpf_impl::LinearizedPuppiAlgo::puppiAlphaSlopesPhotons_
std::vector< float > puppiAlphaSlopesPhotons_
Definition: LinearizedPuppiAlgo.h:26
l1tpf_impl::PuppiAlgo::fillPuppi
virtual void fillPuppi(Region &r) const
Definition: PuppiAlgo.cc:236
l1tpf_impl
Definition: BitwisePFAlgo.h:8
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
zMuMuMuonUserData.alpha
alpha
zGenParticlesMatch = cms.InputTag(""),
Definition: zMuMuMuonUserData.py:9
l1tpf_impl::LinearizedPuppiAlgo::puppiAlphaCropsPhotons_
std::vector< float > puppiAlphaCropsPhotons_
Definition: LinearizedPuppiAlgo.h:28
testProducerWithPsetDescEmpty_cfi.x2
x2
Definition: testProducerWithPsetDescEmpty_cfi.py:28
l1tpf_impl::LinearizedPuppiAlgo::doPUGlobals
void doPUGlobals(const std::vector< Region > &rs, float npu, std::vector< float > &globals) const override
Definition: LinearizedPuppiAlgo.cc:65
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
np
int np
Definition: AMPTWrapper.h:43
central
Definition: L1ECALPrefiringWeightProducer.cc:36
vd
std::vector< DeviationSensor2D * > vd
Definition: DeviationsFromFileSensor2D.h:21
l1tpf_impl::LinearizedPuppiAlgo::puppiPriorsPhotons_
std::vector< float > puppiPriorsPhotons_
Definition: LinearizedPuppiAlgo.h:23
l1t::PFCandidate::Electron
Definition: PFCandidate.h:15
l1tpf_impl::LinearizedPuppiAlgo::puppiAlphaCrops_
std::vector< float > puppiAlphaCrops_
Definition: LinearizedPuppiAlgo.h:28
l1tpf_impl::LinearizedPuppiAlgo::puppiAlphaZerosPhotons_
std::vector< float > puppiAlphaZerosPhotons_
Definition: LinearizedPuppiAlgo.h:27
l1tpf_impl::PFParticle
Definition: DiscretePFInputs.h:184
deltaR.h
l1tpf_impl::LinearizedPuppiAlgo::puppiPtZeros_
std::vector< float > puppiPtZeros_
Definition: LinearizedPuppiAlgo.h:25
l1tpf_impl::PuppiAlgo
Definition: PuppiAlgo.h:8
l1tpf_impl::LinearizedPuppiAlgo::puppiAlphaSlopes_
std::vector< float > puppiAlphaSlopes_
Definition: LinearizedPuppiAlgo.h:26
l1tpf_impl::LinearizedPuppiAlgo::puppiPtZerosPhotons_
std::vector< float > puppiPtZerosPhotons_
Definition: LinearizedPuppiAlgo.h:25
l1tpf_impl::Region
Definition: Region.h:8
edm::ParameterSet
Definition: ParameterSet.h:36
l1tpf_impl::PUAlgoBase::etaCharged_
float etaCharged_
Definition: PUAlgoBase.h:28
l1t::PFCandidate::ChargedHadron
Definition: PFCandidate.h:15
l1tpf_impl::LinearizedPuppiAlgo::LinearizedPuppiAlgo
LinearizedPuppiAlgo(const edm::ParameterSet &)
Definition: LinearizedPuppiAlgo.cc:19
l1tpf_impl::LinearizedPuppiAlgo::puppiPriors_
std::vector< float > puppiPriors_
Definition: LinearizedPuppiAlgo.h:23
alignCSCRings.r
r
Definition: alignCSCRings.py:93
l1tpf_impl::PuppiAlgo::puppiEtaCuts_
std::vector< float > puppiEtaCuts_
Definition: PuppiAlgo.h:31
dbgPrintf
void dbgPrintf(const char *formatString, Args &&... args)
Definition: dbgPrintf.h:5
l1t::PFCandidate::Muon
Definition: PFCandidate.h:15
l1tpf_impl::PuppiAlgo::computePuppiAlphas
virtual void computePuppiAlphas(const Region &r, std::vector< float > &alphaC, std::vector< float > &alphaF) const
Definition: PuppiAlgo.cc:57
std
Definition: JetResolutionObject.h:76
LinearizedPuppiAlgo.h
l1tpf_impl::LinearizedPuppiAlgo::puppiPtSlopesPhotons_
std::vector< float > puppiPtSlopesPhotons_
Definition: LinearizedPuppiAlgo.h:24
l1tpf_impl::LinearizedPuppiAlgo::puppiPtSlopes_
std::vector< float > puppiPtSlopes_
Definition: LinearizedPuppiAlgo.h:24
dbgPrintf.h
Exception.h
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
bookConverter.prior
prior
Definition: bookConverter.py:146
cms::Exception
Definition: Exception.h:70
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
l1tpf_impl::LinearizedPuppiAlgo::computePuppiWeights
void computePuppiWeights(Region &r, float npu, const std::vector< float > &alphaC, const std::vector< float > &alphaF) const
Definition: LinearizedPuppiAlgo.cc:75
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
l1tpf_impl::LinearizedPuppiAlgo::puppiAlphaZeros_
std::vector< float > puppiAlphaZeros_
Definition: LinearizedPuppiAlgo.h:27
l1tpf_impl::LinearizedPuppiAlgo::~LinearizedPuppiAlgo
~LinearizedPuppiAlgo() override
Definition: LinearizedPuppiAlgo.cc:59
l1tpf_impl::LinearizedPuppiAlgo::runNeutralsPU
void runNeutralsPU(Region &r, float npu, const std::vector< float > &globals) const override
Definition: LinearizedPuppiAlgo.cc:68