3 #include "Math/ProbFunc.h"
13 fPuppiDiagnostics = iConfig.
getParameter<
bool>(
"puppiDiagnostics");
17 fPuppiWeightCut = iConfig.
getParameter<
double>(
"MinPuppiWeight");
18 fPtMaxPhotons = iConfig.
getParameter<
double>(
"PtMaxPhotons");
19 fEtaMaxPhotons = iConfig.
getParameter<
double>(
"EtaMaxPhotons");
20 fPtMaxNeutrals = iConfig.
getParameter<
double>(
"PtMaxNeutrals");
21 fPtMaxNeutralsStartSlope = iConfig.
getParameter<
double>(
"PtMaxNeutralsStartSlope");
22 std::vector<edm::ParameterSet> lAlgos = iConfig.
getParameter<std::vector<edm::ParameterSet> >(
"algos");
23 fNAlgos = lAlgos.size();
24 for (
unsigned int i0 = 0; i0 < lAlgos.size(); i0++) {
26 fPuppiAlgo.push_back(pPuppiConfig);
32 fPFParticles.resize(0);
33 fPFParticlesForVar.resize(0);
34 fPFParticlesForVarChargedPV.resize(0);
42 fRecoParticles = &iRecoObjects;
43 fPFParticles.reserve(iRecoObjects.size());
44 fPFParticlesForVar.reserve(iRecoObjects.size());
45 fPFParticlesForVarChargedPV.reserve(iRecoObjects.size());
46 for (
auto const &rParticle : *fRecoParticles) {
48 pCand.
id = rParticle.id;
50 pCand.
pt = rParticle.pt;
51 pCand.
eta = rParticle.eta;
53 pCand.
phi = rParticle.phi;
54 pCand.
m = rParticle.m;
63 fPFParticles.push_back(pCand);
70 fPFParticlesForVar.push_back(pCand);
73 fPFParticlesForVarChargedPV.push_back(pCand);
80 std::vector<PuppiCandidate>
const &iParts,
82 const double iRCone) {
83 return var_within_R(iOpt, iParts, iPart, iRCone);
93 double const r2 =
R *
R;
120 if ((
var != 0.) and ((iId == 0)
or (iId == 3)
or (iId == 5)))
130 std::vector<PuppiCandidate>
const &iConstits,
131 std::vector<PuppiCandidate>
const &iParticles,
132 std::vector<PuppiCandidate>
const &iChargedParticles) {
133 for (
unsigned int i0 = 0; i0 < iConstits.size(); i0++) {
135 int pPupId = getPuppiId(iConstits[i0].
pt, iConstits[i0].
eta);
136 if (pPupId == -1 || fPuppiAlgo[pPupId].numAlgos() <= iOpt) {
141 int pAlgo = fPuppiAlgo[pPupId].algoId(iOpt);
142 bool pCharged = fPuppiAlgo[pPupId].isCharged(iOpt);
143 double pCone = fPuppiAlgo[pPupId].coneSize(iOpt);
148 bool const getsDefaultWgtIfApplyCHS = iConstits[i0].id == 1
or iConstits[i0].id == 2;
149 if (not((fApplyCHS and getsDefaultWgtIfApplyCHS)
or iConstits[i0].
id == 3)
or
150 (
std::abs(iConstits[i0].
eta) < fPuppiAlgo[pPupId].etaMaxExtrap() and getsDefaultWgtIfApplyCHS)) {
151 pVal = goodVar(iConstits[i0], pCharged ? iChargedParticles : iParticles, pAlgo, pCone);
153 fVals.push_back(pVal);
156 LogDebug(
"NotFound") <<
"====> Value is Nan " << pVal <<
" == " << iConstits[i0].pt <<
" -- " << iConstits[i0].eta
162 for (
int i1 = 0;
i1 < fNAlgos;
i1++) {
164 if (not(
std::abs(iConstits[i0].
eta) < fPuppiAlgo[
i1].etaMaxExtrap() and getsDefaultWgtIfApplyCHS))
170 pAlgo = fPuppiAlgo[
i1].algoId(iOpt);
171 pCharged = fPuppiAlgo[
i1].isCharged(iOpt);
172 pCone = fPuppiAlgo[
i1].coneSize(iOpt);
173 curVal = goodVar(iConstits[i0], pCharged ? iChargedParticles : iParticles, pAlgo, pCone);
176 fPuppiAlgo[
i1].add(iConstits[i0], curVal, iOpt);
180 for (
int i0 = 0; i0 < fNAlgos; i0++)
181 fPuppiAlgo[i0].computeMedRMS(iOpt);
186 std::vector<PuppiCandidate>
const &iConstits,
187 std::vector<PuppiCandidate>
const &iParticles,
188 std::vector<PuppiCandidate>
const &iChargedParticles) {
189 for (
int j0 = 0; j0 < fNAlgos; j0++) {
190 for (
unsigned int i0 = 0; i0 < iConstits.size(); i0++) {
192 int pAlgo = fPuppiAlgo[j0].algoId(iOpt);
193 bool pCharged = fPuppiAlgo[j0].isCharged(iOpt);
194 double pCone = fPuppiAlgo[j0].coneSize(iOpt);
196 double const pVal = goodVar(iConstits[i0], pCharged ? iChargedParticles : iParticles, pAlgo, pCone);
197 fRawAlphas.push_back(pVal);
199 LogDebug(
"NotFound") <<
"====> Value is Nan " << pVal <<
" == " << iConstits[i0].pt <<
" -- "
200 << iConstits[i0].eta << endl;
209 for (
int i0 = 0; i0 < fNAlgos; i0++) {
210 int nEtaBinsPerAlgo = fPuppiAlgo[i0].etaBins();
211 for (
int i1 = 0;
i1 < nEtaBinsPerAlgo;
i1++) {
213 fPuppiAlgo[i0].fixAlgoEtaBin(
i1);
214 if (iPt > fPuppiAlgo[i0].
ptMin()) {
229 double lProbLV = ROOT::Math::normal_cdf_c(
std::abs(iDZ), 1.) * 2.;
230 double lProbPU = 1 - lProbLV;
235 double lChi2PU = TMath::ChisquareQuantile(lProbPU, 1);
240 int lNParticles = fRecoParticles->size();
243 fWeights.reserve(lNParticles);
245 fVals.reserve(lNParticles);
246 for (
int i0 = 0; i0 < fNAlgos; i0++)
247 fPuppiAlgo[i0].
reset();
250 for (
int i0 = 0; i0 < fNAlgos; i0++)
251 lNMaxAlgo =
std::max(fPuppiAlgo[i0].numAlgos(), lNMaxAlgo);
253 for (
int i0 = 0; i0 < lNMaxAlgo; i0++) {
254 getRMSAvg(i0, fPFParticles, fPFParticlesForVar, fPFParticlesForVarChargedPV);
256 if (fPuppiDiagnostics)
257 getRawAlphas(0, fPFParticles, fPFParticlesForVar, fPFParticlesForVarChargedPV);
259 std::vector<double> pVals;
260 pVals.reserve(lNParticles);
261 for (
int i0 = 0; i0 < lNParticles; i0++) {
266 const auto &rParticle = (*fRecoParticles)[i0];
267 int pPupId = getPuppiId(rParticle.pt, rParticle.eta);
269 fWeights.push_back(0);
270 fAlphaMed.push_back(-10);
271 fAlphaRMS.push_back(-10);
279 pChi2 = getChi2FromdZ(rParticle.dZ);
281 if ((
std::abs(rParticle.pdgId) == 22) || (
std::abs(rParticle.pdgId) == 130))
285 int lNAlgos = fPuppiAlgo[pPupId].numAlgos();
286 for (
int i1 = 0;
i1 < lNAlgos;
i1++)
287 pVals.push_back(fVals[lNParticles *
i1 + i0]);
289 pWeight = fPuppiAlgo[pPupId].compute(pVals, pChi2);
291 if (rParticle.id == 1 && fApplyCHS)
293 if (rParticle.id == 2 && fApplyCHS)
296 if (rParticle.id == 3)
301 LogDebug(
"PuppiWeightError") <<
"====> Weight is nan : " << pWeight <<
" : pt " << rParticle.pt
302 <<
" -- eta : " << rParticle.eta <<
" -- Value" << fVals[i0]
303 <<
" -- id : " << rParticle.id <<
" -- NAlgos: " << lNAlgos << std::endl;
306 if (pWeight * fPFParticles[i0].
pt < fPuppiAlgo[pPupId].neutralPt(fPUProxy) && rParticle.id == 0)
309 if (fPtMaxPhotons > 0 && rParticle.pdgId == 22 &&
std::abs(fPFParticles[i0].eta) < fEtaMaxPhotons &&
310 fPFParticles[i0].pt > fPtMaxPhotons)
313 else if ((fPtMaxNeutrals > 0) && (rParticle.id == 0))
314 pWeight = std::clamp(
315 (fPFParticles[i0].
pt - fPtMaxNeutralsStartSlope) / (fPtMaxNeutrals - fPtMaxNeutralsStartSlope), pWeight, 1.);
316 if (pWeight < fPuppiWeightCut)
319 pWeight = 1. - pWeight;
322 fWeights.push_back(pWeight);
323 fAlphaMed.push_back(fPuppiAlgo[pPupId].
median());
324 fAlphaRMS.push_back(fPuppiAlgo[pPupId].
rms());