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);
81 std::vector<PuppiCandidate>
const &iParts,
83 const double iRCone) {
84 return var_within_R(iOpt, iParts, iPart, iRCone);
94 double const r2 =
R *
R;
121 if ((
var != 0.) and ((iId == 0)
or (iId == 3)
or (iId == 5)))
131 std::vector<PuppiCandidate>
const &iConstits,
132 std::vector<PuppiCandidate>
const &iParticles,
133 std::vector<PuppiCandidate>
const &iChargedParticles) {
134 for (
unsigned int i0 = 0; i0 < iConstits.size(); i0++) {
136 int pPupId = getPuppiId(iConstits[i0].
pt, iConstits[i0].
eta);
137 if (pPupId == -1 || fPuppiAlgo[pPupId].numAlgos() <= iOpt) {
142 int pAlgo = fPuppiAlgo[pPupId].algoId(iOpt);
143 bool pCharged = fPuppiAlgo[pPupId].isCharged(iOpt);
144 double pCone = fPuppiAlgo[pPupId].coneSize(iOpt);
149 bool const getsDefaultWgtIfApplyCHS = iConstits[i0].id == 1
or iConstits[i0].id == 2;
150 if (not((fApplyCHS and getsDefaultWgtIfApplyCHS)
or iConstits[i0].
id == 3)
or
151 (
std::abs(iConstits[i0].
eta) < fPuppiAlgo[pPupId].etaMaxExtrap() and getsDefaultWgtIfApplyCHS)) {
152 pVal = goodVar(iConstits[i0], pCharged ? iChargedParticles : iParticles, pAlgo, pCone);
154 fVals.push_back(pVal);
157 LogDebug(
"NotFound") <<
"====> Value is Nan " << pVal <<
" == " << iConstits[i0].pt <<
" -- " << iConstits[i0].eta
163 for (
int i1 = 0;
i1 < fNAlgos;
i1++) {
165 if (not(
std::abs(iConstits[i0].
eta) < fPuppiAlgo[
i1].etaMaxExtrap() and getsDefaultWgtIfApplyCHS))
171 pAlgo = fPuppiAlgo[
i1].algoId(iOpt);
172 pCharged = fPuppiAlgo[
i1].isCharged(iOpt);
173 pCone = fPuppiAlgo[
i1].coneSize(iOpt);
174 curVal = goodVar(iConstits[i0], pCharged ? iChargedParticles : iParticles, pAlgo, pCone);
177 fPuppiAlgo[
i1].add(iConstits[i0], curVal, iOpt);
181 for (
int i0 = 0; i0 < fNAlgos; i0++)
182 fPuppiAlgo[i0].computeMedRMS(iOpt);
187 std::vector<PuppiCandidate>
const &iConstits,
188 std::vector<PuppiCandidate>
const &iParticles,
189 std::vector<PuppiCandidate>
const &iChargedParticles) {
190 for (
int j0 = 0; j0 < fNAlgos; j0++) {
191 for (
unsigned int i0 = 0; i0 < iConstits.size(); i0++) {
193 int pAlgo = fPuppiAlgo[j0].algoId(iOpt);
194 bool pCharged = fPuppiAlgo[j0].isCharged(iOpt);
195 double pCone = fPuppiAlgo[j0].coneSize(iOpt);
197 double const pVal = goodVar(iConstits[i0], pCharged ? iChargedParticles : iParticles, pAlgo, pCone);
198 fRawAlphas.push_back(pVal);
200 LogDebug(
"NotFound") <<
"====> Value is Nan " << pVal <<
" == " << iConstits[i0].pt <<
" -- "
201 << iConstits[i0].eta << endl;
210 for (
int i0 = 0; i0 < fNAlgos; i0++) {
211 int nEtaBinsPerAlgo = fPuppiAlgo[i0].etaBins();
212 for (
int i1 = 0;
i1 < nEtaBinsPerAlgo;
i1++) {
214 fPuppiAlgo[i0].fixAlgoEtaBin(
i1);
215 if (iPt > fPuppiAlgo[i0].
ptMin()) {
230 double lProbLV = ROOT::Math::normal_cdf_c(
std::abs(iDZ), 1.) * 2.;
231 double lProbPU = 1 - lProbLV;
236 double lChi2PU = TMath::ChisquareQuantile(lProbPU, 1);
241 int lNParticles = fRecoParticles->size();
244 fWeights.reserve(lNParticles);
246 fVals.reserve(lNParticles);
247 for (
int i0 = 0; i0 < fNAlgos; i0++)
248 fPuppiAlgo[i0].
reset();
251 for (
int i0 = 0; i0 < fNAlgos; i0++)
252 lNMaxAlgo =
std::max(fPuppiAlgo[i0].numAlgos(), lNMaxAlgo);
254 for (
int i0 = 0; i0 < lNMaxAlgo; i0++) {
255 getRMSAvg(i0, fPFParticles, fPFParticlesForVar, fPFParticlesForVarChargedPV);
257 if (fPuppiDiagnostics)
258 getRawAlphas(0, fPFParticles, fPFParticlesForVar, fPFParticlesForVarChargedPV);
260 std::vector<double> pVals;
261 pVals.reserve(lNParticles);
262 for (
int i0 = 0; i0 < lNParticles; i0++) {
267 const auto &rParticle = (*fRecoParticles)[i0];
268 int pPupId = getPuppiId(rParticle.pt, rParticle.eta);
270 fWeights.push_back(0);
271 fAlphaMed.push_back(-10);
272 fAlphaRMS.push_back(-10);
280 pChi2 = getChi2FromdZ(rParticle.dZ);
282 if ((
std::abs(rParticle.pdgId) == 22) || (
std::abs(rParticle.pdgId) == 130))
286 int lNAlgos = fPuppiAlgo[pPupId].numAlgos();
287 for (
int i1 = 0;
i1 < lNAlgos;
i1++)
288 pVals.push_back(fVals[lNParticles *
i1 + i0]);
290 pWeight = fPuppiAlgo[pPupId].compute(pVals, pChi2);
292 if (rParticle.id == 1 && fApplyCHS)
294 if (rParticle.id == 2 && fApplyCHS)
297 if (rParticle.id == 3)
302 LogDebug(
"PuppiWeightError") <<
"====> Weight is nan : " << pWeight <<
" : pt " << rParticle.pt
303 <<
" -- eta : " << rParticle.eta <<
" -- Value" << fVals[i0]
304 <<
" -- id : " << rParticle.id <<
" -- NAlgos: " << lNAlgos << std::endl;
307 if (pWeight * fPFParticles[i0].
pt < fPuppiAlgo[pPupId].neutralPt(fNPV) && rParticle.id == 0)
310 if (fPtMaxPhotons > 0 && rParticle.pdgId == 22 &&
std::abs(fPFParticles[i0].eta) < fEtaMaxPhotons &&
311 fPFParticles[i0].pt > fPtMaxPhotons)
314 else if ((fPtMaxNeutrals > 0) && (rParticle.id == 0))
315 pWeight = std::clamp(
316 (fPFParticles[i0].
pt - fPtMaxNeutralsStartSlope) / (fPtMaxNeutrals - fPtMaxNeutralsStartSlope), pWeight, 1.);
317 if (pWeight < fPuppiWeightCut)
320 pWeight = 1. - pWeight;
323 fWeights.push_back(pWeight);
324 fAlphaMed.push_back(fPuppiAlgo[pPupId].
median());
325 fAlphaRMS.push_back(fPuppiAlgo[pPupId].
rms());