3 #include "Math/ProbFunc.h" 10 #include "fastjet/PseudoJet.hh" 15 fPuppiDiagnostics = iConfig.
getParameter<
bool>(
"puppiDiagnostics");
19 fPuppiWeightCut = iConfig.
getParameter<
double>(
"MinPuppiWeight");
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 fChargedPV .resize(0);
34 fPupParticles .resize(0);
43 fRecoParticles = &iRecoObjects;
44 fPFParticles.reserve(iRecoObjects.size());
45 fChargedPV.reserve(iRecoObjects.size());
47 fRecoToPup.reserve(fRecoParticles->size());
48 for (
auto const& rParticle : *fRecoParticles){
51 fastjet::PseudoJet curPseudoJet;
53 curPseudoJet.reset_PtYPhiM(rParticle.pt,rParticle.rapidity,rParticle.phi,rParticle.m);
55 curPseudoJet.reset_PtYPhiM(0, 99., 0, 0);
57 int puppi_register = 0;
58 if(rParticle.id == 0
or rParticle.charge == 0) puppi_register = 0;
59 if(rParticle.id == 1 and rParticle.charge != 0) puppi_register = rParticle.charge;
60 if(rParticle.id == 2 and rParticle.charge != 0) puppi_register = rParticle.charge+5;
62 pCand.
id = rParticle.id;
64 pCand.
pt = curPseudoJet.pt();
66 pCand.
eta = curPseudoJet.eta();
67 pCand.
phi = curPseudoJet.phi();
68 pCand.
m = curPseudoJet.m();
69 pCand.
px = curPseudoJet.px();
70 pCand.
py = curPseudoJet.py();
71 pCand.
pz = curPseudoJet.pz();
72 pCand.
e = curPseudoJet.E();
74 fPFParticles.push_back(pCand);
76 if(
std::abs(rParticle.id) == 1) fChargedPV.push_back(pCand);
77 if(
std::abs(rParticle.id) >= 1 ) fPVFrac+=1.;
79 if (fPVFrac != 0) fPVFrac = double(fChargedPV.size())/fPVFrac;
85 return var_within_R(iOpt,iParts,iPart,iRCone);
92 double const r2 = R *
R;
95 for (
auto const &
cand : particles) {
104 var += (
pt *
pt / dr2);
119 if ((var != 0.) and ((iId == 0)
or (iId == 3)
or (iId == 5)))
128 void PuppiContainer::getRMSAvg(
int iOpt,std::vector<PuppiCandidate>
const &iConstits,std::vector<PuppiCandidate>
const &iParticles,std::vector<PuppiCandidate>
const &iChargedParticles) {
129 for(
unsigned int i0 = 0; i0 < iConstits.size(); i0++ ) {
131 int pPupId = getPuppiId(iConstits[i0].
pt,iConstits[i0].
eta);
132 if(pPupId == -1 || fPuppiAlgo[pPupId].numAlgos() <= iOpt){
137 int pAlgo = fPuppiAlgo[pPupId].algoId (iOpt);
138 bool pCharged = fPuppiAlgo[pPupId].isCharged(iOpt);
139 double pCone = fPuppiAlgo[pPupId].coneSize (iOpt);
144 if (not(fApplyCHS and (iConstits[i0].
id == 1
or iConstits[i0].
id == 2))
145 or (
std::abs(iConstits[i0].eta) < fPuppiAlgo[pPupId].etaMaxExtrap() and iConstits[i0].puppi_register != 0)) {
146 pVal = goodVar(iConstits[i0],pCharged ? iChargedParticles : iParticles,pAlgo,pCone);
148 fVals.push_back(pVal);
151 LogDebug(
"NotFound" ) <<
"====> Value is Nan " << pVal <<
" == " << iConstits[i0].pt <<
" -- " << iConstits[i0].eta << endl;
156 for(
int i1 = 0; i1 < fNAlgos; i1++){
158 if(not(
std::abs(iConstits[i0].eta) < fPuppiAlgo[i1].etaMaxExtrap() and iConstits[i0].puppi_register != 0))
164 pAlgo = fPuppiAlgo[i1].algoId (iOpt);
165 pCharged = fPuppiAlgo[i1].isCharged(iOpt);
166 pCone = fPuppiAlgo[i1].coneSize (iOpt);
167 curVal = goodVar(iConstits[i0],pCharged ? iChargedParticles : iParticles,pAlgo,pCone);
170 fPuppiAlgo[i1].add(iConstits[i0],curVal,iOpt);
173 for(
int i0 = 0; i0 < fNAlgos; i0++) fPuppiAlgo[i0].computeMedRMS(iOpt,fPVFrac);
177 void PuppiContainer::getRawAlphas(
int iOpt,std::vector<PuppiCandidate>
const &iConstits,std::vector<PuppiCandidate>
const &iParticles,std::vector<PuppiCandidate>
const &iChargedParticles) {
178 for(
int j0 = 0; j0 < fNAlgos; j0++){
179 for(
unsigned int i0 = 0; i0 < iConstits.size(); i0++ ) {
181 int pAlgo = fPuppiAlgo[j0].algoId (iOpt);
182 bool pCharged = fPuppiAlgo[j0].isCharged(iOpt);
183 double pCone = fPuppiAlgo[j0].coneSize (iOpt);
185 double const pVal = goodVar(iConstits[i0],pCharged ? iChargedParticles : iParticles,pAlgo,pCone);
186 fRawAlphas.push_back(pVal);
188 LogDebug(
"NotFound" ) <<
"====> Value is Nan " << pVal <<
" == " << iConstits[i0].pt <<
" -- " << iConstits[i0].eta << endl;
196 for(
int i0 = 0; i0 < fNAlgos; i0++) {
197 int nEtaBinsPerAlgo = fPuppiAlgo[i0].etaBins();
198 for (
int i1 = 0; i1 < nEtaBinsPerAlgo; i1++){
200 fPuppiAlgo[i0].fixAlgoEtaBin( i1 );
201 if(iPt > fPuppiAlgo[i0].
ptMin()){
216 double lProbLV = ROOT::Math::normal_cdf_c(
std::abs(iDZ),1.)*2.;
217 double lProbPU = 1-lProbLV;
218 if(lProbPU <= 0) lProbPU = 1
e-16;
219 if(lProbPU >= 0) lProbPU = 1-1
e-16;
220 double lChi2PU = TMath::ChisquareQuantile(lProbPU,1);
225 int lNParticles = fRecoParticles->size();
227 fPupParticles .clear();
228 fPupParticles.reserve(lNParticles);
230 fWeights.reserve(lNParticles);
232 fVals.reserve(lNParticles);
233 for(
int i0 = 0; i0 < fNAlgos; i0++) fPuppiAlgo[i0].
reset();
236 for(
int i0 = 0; i0 < fNAlgos; i0++) lNMaxAlgo =
std::max(fPuppiAlgo[i0].numAlgos(),lNMaxAlgo);
238 for(
int i0 = 0; i0 < lNMaxAlgo; i0++) {
239 getRMSAvg(i0,fPFParticles,fPFParticles,fChargedPV);
241 if (fPuppiDiagnostics) getRawAlphas(0,fPFParticles,fPFParticles,fChargedPV);
243 std::vector<double> pVals;
244 pVals.reserve(lNParticles);
245 for(
int i0 = 0; i0 < lNParticles; i0++) {
250 const auto& rParticle = (*fRecoParticles)[i0];
251 int pPupId = getPuppiId(rParticle.pt,rParticle.eta);
253 fWeights .push_back(pWeight);
254 fAlphaMed.push_back(-10);
255 fAlphaRMS.push_back(-10);
256 fRecoToPup.push_back(-1);
259 fRecoToPup.push_back(fPupParticles.size());
265 pChi2 = getChi2FromdZ(rParticle.dZ);
267 if(rParticle.pfType > 3) pChi2 = 0;
270 int lNAlgos = fPuppiAlgo[pPupId].numAlgos();
271 for(
int i1 = 0; i1 < lNAlgos; i1++) pVals.push_back(fVals[lNParticles*i1+i0]);
273 pWeight = fPuppiAlgo[pPupId].compute(pVals,pChi2);
275 if(rParticle.id == 1 && fApplyCHS ) pWeight = 1;
276 if(rParticle.id == 2 && fApplyCHS ) pWeight = 0;
280 LogDebug(
"PuppiWeightError") <<
"====> Weight is nan : " << pWeight <<
" : pt " << rParticle.pt <<
" -- eta : " << rParticle.eta <<
" -- Value" << fVals[i0] <<
" -- id : " << rParticle.id <<
" -- NAlgos: " << lNAlgos << std::endl;
283 if(pWeight*fPFParticles[i0].
pt < fPuppiAlgo[pPupId].neutralPt(fNPV) && rParticle.id == 0 ) pWeight = 0;
284 if((fPtMax>0) && (rParticle.id == 0))
285 pWeight = std::clamp((fPFParticles[i0].
pt - fPtMaxNeutralsStartSlope) / (fPtMax - fPtMaxNeutralsStartSlope),
288 if(pWeight < fPuppiWeightCut) pWeight = 0;
289 if(fInvert) pWeight = 1.-pWeight;
292 fWeights .push_back(pWeight);
293 fAlphaMed.push_back(fPuppiAlgo[pPupId].
median());
294 fAlphaRMS.push_back(fPuppiAlgo[pPupId].
rms());
303 curjet.
pt *= pWeight;
305 curjet.
px *= pWeight;
306 curjet.
py *= pWeight;
307 curjet.
pz *= pWeight;
310 fPupParticles.push_back(curjet);
T getParameter(std::string const &) const
std::vector< double > const & puppiWeights()
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)
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])