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);
43 fRecoParticles = &iRecoObjects;
44 for (
auto const &rParticle : *fRecoParticles) {
50 curPseudoJet.reset_PtYPhiM(rParticle.pt, rParticle.rapidity, rParticle.phi, rParticle.m);
52 curPseudoJet.reset_PtYPhiM(0, 99., 0, 0);
58 fPFParticles.push_back(curPseudoJet);
61 fChargedPV.push_back(curPseudoJet);
69 std::vector<PuppiCandidate>
const &iParts,
71 const double iRCone) {
72 return var_within_R(iOpt, iParts, iPart, iRCone);
89 vector<double> near_dR2s;
91 vector<double> near_pts;
93 const double r2 =
R *
R;
95 if (
part.puppi_register() == 3)
100 near_pts.push_back(
part.pt());
106 auto nParts = near_dR2s.size();
107 for (
auto i = 0UL;
i < nParts; ++
i) {
108 auto dr2 = near_dR2s[
i];
109 auto pt = near_pts[
i];
127 else if (iId == 0 &&
var != 0)
129 else if (iId == 3 &&
var != 0)
131 else if (iId == 5 &&
var != 0)
137 std::vector<PuppiCandidate>
const &iConstits,
138 std::vector<PuppiCandidate>
const &iParticles,
139 std::vector<PuppiCandidate>
const &iChargedParticles) {
140 for (
unsigned int i0 = 0; i0 < iConstits.size(); i0++) {
143 int pPupId = getPuppiId(iConstits[i0].
pt(), iConstits[i0].
eta());
144 if (pPupId == -1 || fPuppiAlgo[pPupId].numAlgos() <= iOpt) {
149 int pAlgo = fPuppiAlgo[pPupId].algoId(iOpt);
150 bool pCharged = fPuppiAlgo[pPupId].isCharged(iOpt);
151 double pCone = fPuppiAlgo[pPupId].coneSize(iOpt);
154 pVal = goodVar(iConstits[i0], iParticles, pAlgo, pCone);
156 pVal = goodVar(iConstits[i0], iChargedParticles, pAlgo, pCone);
157 fVals.push_back(pVal);
160 LogDebug(
"NotFound") <<
"====> Value is Nan " << pVal <<
" == " << iConstits[i0].pt() <<
" -- "
161 << iConstits[i0].eta() << endl;
167 for (
int i1 = 0;
i1 < fNAlgos;
i1++) {
168 pAlgo = fPuppiAlgo[
i1].algoId(iOpt);
169 pCharged = fPuppiAlgo[
i1].isCharged(iOpt);
170 pCone = fPuppiAlgo[
i1].coneSize(iOpt);
174 curVal = goodVar(iConstits[i0], iParticles, pAlgo, pCone);
176 curVal = goodVar(iConstits[i0], iChargedParticles, pAlgo, pCone);
181 fPuppiAlgo[
i1].add(iConstits[i0], curVal, iOpt);
184 for (
int i0 = 0; i0 < fNAlgos; i0++)
185 fPuppiAlgo[i0].computeMedRMS(iOpt);
189 std::vector<PuppiCandidate>
const &iConstits,
190 std::vector<PuppiCandidate>
const &iParticles,
191 std::vector<PuppiCandidate>
const &iChargedParticles) {
192 for (
int j0 = 0; j0 < fNAlgos; j0++) {
193 for (
unsigned int i0 = 0; i0 < iConstits.size(); i0++) {
196 int pAlgo = fPuppiAlgo[j0].algoId(iOpt);
197 bool pCharged = fPuppiAlgo[j0].isCharged(iOpt);
198 double pCone = fPuppiAlgo[j0].coneSize(iOpt);
201 pVal = goodVar(iConstits[i0], iParticles, pAlgo, pCone);
203 pVal = goodVar(iConstits[i0], iChargedParticles, pAlgo, pCone);
204 fRawAlphas.push_back(pVal);
206 LogDebug(
"NotFound") <<
"====> Value is Nan " << pVal <<
" == " << iConstits[i0].pt() <<
" -- "
207 << iConstits[i0].eta() << endl;
215 for (
int i0 = 0; i0 < fNAlgos; i0++) {
216 int nEtaBinsPerAlgo = fPuppiAlgo[i0].etaBins();
217 for (
int i1 = 0;
i1 < nEtaBinsPerAlgo;
i1++) {
219 fPuppiAlgo[i0].fixAlgoEtaBin(
i1);
220 if (iPt > fPuppiAlgo[i0].
ptMin()) {
235 double lProbLV = ROOT::Math::normal_cdf_c(
std::abs(iDZ), 1.) * 2.;
236 double lProbPU = 1 - lProbLV;
241 double lChi2PU = TMath::ChisquareQuantile(lProbPU, 1);
246 int lNParticles = fRecoParticles->size();
249 fWeights.reserve(lNParticles);
251 fVals.reserve(lNParticles);
252 for (
int i0 = 0; i0 < fNAlgos; i0++)
253 fPuppiAlgo[i0].
reset();
256 for (
int i0 = 0; i0 < fNAlgos; i0++)
257 lNMaxAlgo =
std::max(fPuppiAlgo[i0].numAlgos(), lNMaxAlgo);
259 for (
int i0 = 0; i0 < lNMaxAlgo; i0++) {
260 getRMSAvg(i0, fPFParticles, fPFParticles, fChargedPV);
262 if (fPuppiDiagnostics)
263 getRawAlphas(0, fPFParticles, fPFParticles, fChargedPV);
265 std::vector<double> pVals;
266 pVals.reserve(lNParticles);
267 for (
int i0 = 0; i0 < lNParticles; i0++) {
272 const auto &rParticle = (*fRecoParticles)[i0];
273 int pPupId = getPuppiId(rParticle.pt, rParticle.eta);
275 fWeights.push_back(0);
276 fAlphaMed.push_back(-10);
277 fAlphaRMS.push_back(-10);
285 pChi2 = getChi2FromdZ(rParticle.dZ);
287 if ((
std::abs(rParticle.pdgId) == 22) || (
std::abs(rParticle.pdgId) == 130))
291 int lNAlgos = fPuppiAlgo[pPupId].numAlgos();
292 for (
int i1 = 0;
i1 < lNAlgos;
i1++)
293 pVals.push_back(fVals[lNParticles *
i1 + i0]);
295 pWeight = fPuppiAlgo[pPupId].compute(pVals, pChi2);
297 if (rParticle.id == 1 && fApplyCHS)
299 if (rParticle.id == 2 && fApplyCHS)
302 if (rParticle.id == 3)
307 LogDebug(
"PuppiWeightError") <<
"====> Weight is nan : " << pWeight <<
" : pt " << rParticle.pt
308 <<
" -- eta : " << rParticle.eta <<
" -- Value" << fVals[i0]
309 <<
" -- id : " << rParticle.id <<
" -- NAlgos: " << lNAlgos << std::endl;
312 if (pWeight * fPFParticles[i0].
pt() < fPuppiAlgo[pPupId].neutralPt(fNPV) && rParticle.id == 0)
315 if ((fPtMaxPhotons > 0) && (rParticle.pdgId == 22) && (
std::abs(fPFParticles[i0].eta()) < fEtaMaxPhotons) &&
316 (fPFParticles[i0].pt() > fPtMaxPhotons))
319 else if ((fPtMaxNeutrals > 0) && (rParticle.id == 0))
321 std::clamp((fPFParticles[i0].
pt() - fPtMaxNeutralsStartSlope) / (fPtMaxNeutrals - fPtMaxNeutralsStartSlope),
324 if (pWeight < fPuppiWeightCut)
327 pWeight = 1. - pWeight;
330 fWeights.push_back(pWeight);
331 fAlphaMed.push_back(fPuppiAlgo[pPupId].
median());
332 fAlphaRMS.push_back(fPuppiAlgo[pPupId].
rms());