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;
128 if ((
var != 0.) and ((iId == 0)
or (iId == 3)
or (iId == 5)))
138 std::vector<PuppiCandidate>
const &iConstits,
139 std::vector<PuppiCandidate>
const &iParticles,
140 std::vector<PuppiCandidate>
const &iChargedParticles) {
141 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);
156 bool const getsDefaultWgtIfApplyCHS = iConstits[i0].id == 1
or iConstits[i0].id == 2;
157 if (not((fApplyCHS and getsDefaultWgtIfApplyCHS)
or iConstits[i0].
id == 3)
or 158 (
std::abs(iConstits[i0].
eta) < fPuppiAlgo[pPupId].etaMaxExtrap() and getsDefaultWgtIfApplyCHS)) {
159 pVal = goodVar(iConstits[i0], pCharged ? iChargedParticles : iParticles, pAlgo, pCone);
161 fVals.push_back(pVal);
164 LogDebug(
"NotFound") <<
"====> Value is Nan " << pVal <<
" == " << iConstits[i0].pt <<
" -- " << iConstits[i0].eta
170 for (
int i1 = 0;
i1 < fNAlgos;
i1++) {
172 if (not(
std::abs(iConstits[i0].
eta) < fPuppiAlgo[
i1].etaMaxExtrap() and getsDefaultWgtIfApplyCHS))
178 pAlgo = fPuppiAlgo[
i1].algoId(iOpt);
179 pCharged = fPuppiAlgo[
i1].isCharged(iOpt);
180 pCone = fPuppiAlgo[
i1].coneSize(iOpt);
181 curVal = goodVar(iConstits[i0], pCharged ? iChargedParticles : iParticles, pAlgo, pCone);
184 fPuppiAlgo[
i1].add(iConstits[i0], curVal, iOpt);
188 for (
int i0 = 0; i0 < fNAlgos; i0++)
189 fPuppiAlgo[i0].computeMedRMS(iOpt);
194 std::vector<PuppiCandidate>
const &iConstits,
195 std::vector<PuppiCandidate>
const &iParticles,
196 std::vector<PuppiCandidate>
const &iChargedParticles) {
197 for (
int j0 = 0; j0 < fNAlgos; j0++) {
198 for (
unsigned int i0 = 0; i0 < iConstits.size(); i0++) {
200 int pAlgo = fPuppiAlgo[j0].algoId(iOpt);
201 bool pCharged = fPuppiAlgo[j0].isCharged(iOpt);
202 double pCone = fPuppiAlgo[j0].coneSize(iOpt);
204 double const pVal = goodVar(iConstits[i0], pCharged ? iChargedParticles : iParticles, pAlgo, pCone);
205 fRawAlphas.push_back(pVal);
207 LogDebug(
"NotFound") <<
"====> Value is Nan " << pVal <<
" == " << iConstits[i0].pt <<
" -- " 208 << iConstits[i0].eta << endl;
217 for (
int i0 = 0; i0 < fNAlgos; i0++) {
218 int nEtaBinsPerAlgo = fPuppiAlgo[i0].etaBins();
219 for (
int i1 = 0;
i1 < nEtaBinsPerAlgo;
i1++) {
221 fPuppiAlgo[i0].fixAlgoEtaBin(
i1);
222 if (iPt > fPuppiAlgo[i0].
ptMin()) {
237 double lProbLV = ROOT::Math::normal_cdf_c(
std::abs(iDZ), 1.) * 2.;
238 double lProbPU = 1 - lProbLV;
243 double lChi2PU = TMath::ChisquareQuantile(lProbPU, 1);
248 int lNParticles = fRecoParticles->size();
251 fWeights.reserve(lNParticles);
253 fVals.reserve(lNParticles);
254 for (
int i0 = 0; i0 < fNAlgos; i0++)
255 fPuppiAlgo[i0].
reset();
258 for (
int i0 = 0; i0 < fNAlgos; i0++)
259 lNMaxAlgo =
std::max(fPuppiAlgo[i0].numAlgos(), lNMaxAlgo);
261 for (
int i0 = 0; i0 < lNMaxAlgo; i0++) {
262 getRMSAvg(i0, fPFParticles, fPFParticlesForVar, fPFParticlesForVarChargedPV);
264 if (fPuppiDiagnostics)
265 getRawAlphas(0, fPFParticles, fPFParticlesForVar, fPFParticlesForVarChargedPV);
267 std::vector<double> pVals;
268 pVals.reserve(lNParticles);
269 for (
int i0 = 0; i0 < lNParticles; i0++) {
274 const auto &rParticle = (*fRecoParticles)[i0];
275 int pPupId = getPuppiId(rParticle.pt, rParticle.eta);
277 fWeights.push_back(0);
278 fAlphaMed.push_back(-10);
279 fAlphaRMS.push_back(-10);
287 pChi2 = getChi2FromdZ(rParticle.dZ);
289 if ((
std::abs(rParticle.pdgId) == 22) || (
std::abs(rParticle.pdgId) == 130))
293 int lNAlgos = fPuppiAlgo[pPupId].numAlgos();
294 for (
int i1 = 0;
i1 < lNAlgos;
i1++)
295 pVals.push_back(fVals[lNParticles *
i1 + i0]);
297 pWeight = fPuppiAlgo[pPupId].compute(pVals, pChi2);
299 if (rParticle.id == 1 && fApplyCHS)
301 if (rParticle.id == 2 && fApplyCHS)
304 if (rParticle.id == 3)
309 LogDebug(
"PuppiWeightError") <<
"====> Weight is nan : " << pWeight <<
" : pt " << rParticle.pt
310 <<
" -- eta : " << rParticle.eta <<
" -- Value" << fVals[i0]
311 <<
" -- id : " << rParticle.id <<
" -- NAlgos: " << lNAlgos << std::endl;
314 if (pWeight * fPFParticles[i0].
pt < fPuppiAlgo[pPupId].neutralPt(fPUProxy) && rParticle.id == 0)
317 if (fPtMaxPhotons > 0 && rParticle.pdgId == 22 &&
std::abs(fPFParticles[i0].eta) < fEtaMaxPhotons &&
318 fPFParticles[i0].pt > fPtMaxPhotons)
321 else if ((fPtMaxNeutrals > 0) && (rParticle.id == 0))
322 pWeight = std::clamp(
323 (fPFParticles[i0].
pt - fPtMaxNeutralsStartSlope) / (fPtMaxNeutrals - fPtMaxNeutralsStartSlope), pWeight, 1.);
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());
T getParameter(std::string const &) const
double var_within_R(int iId, const std::vector< PuppiCandidate > &particles, const PuppiCandidate ¢re, const double R)
double getChi2FromdZ(double iDZ)
constexpr bool isFinite(T x)
void getRMSAvg(int iOpt, std::vector< PuppiCandidate > const &iConstits, std::vector< PuppiCandidate > const &iParticles, std::vector< PuppiCandidate > const &iChargeParticles)
void getRawAlphas(int iOpt, std::vector< PuppiCandidate > const &iConstits, std::vector< PuppiCandidate > const &iParticles, std::vector< PuppiCandidate > const &iChargeParticles)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
PuppiContainer(const edm::ParameterSet &iConfig)
Abs< T >::type abs(const T &t)
std::vector< double > const & puppiWeights()
int getPuppiId(float iPt, float iEta)
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
double goodVar(PuppiCandidate const &iPart, std::vector< PuppiCandidate > const &iParts, int iOpt, const double iRCone)
void initialize(const std::vector< RecoObj > &iRecoObjects)
void reset(double vett[256])