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) {
105 var += (
pt *
pt / dr2);
127 if ((var != 0.) and ((iId == 0)
or (iId == 3)
or (iId == 5)))
136 void PuppiContainer::getRMSAvg(
int iOpt,std::vector<PuppiCandidate>
const &iConstits,std::vector<PuppiCandidate>
const &iParticles,std::vector<PuppiCandidate>
const &iChargedParticles) {
137 for(
unsigned int i0 = 0; i0 < iConstits.size(); i0++ ) {
139 int pPupId = getPuppiId(iConstits[i0].
pt,iConstits[i0].
eta);
140 if(pPupId == -1 || fPuppiAlgo[pPupId].numAlgos() <= iOpt){
145 int pAlgo = fPuppiAlgo[pPupId].algoId (iOpt);
146 bool pCharged = fPuppiAlgo[pPupId].isCharged(iOpt);
147 double pCone = fPuppiAlgo[pPupId].coneSize (iOpt);
152 if (not(fApplyCHS and (iConstits[i0].
id == 1
or iConstits[i0].
id == 2))
153 or (
std::abs(iConstits[i0].eta) < fPuppiAlgo[pPupId].etaMaxExtrap() and iConstits[i0].puppi_register != 0)) {
154 pVal = goodVar(iConstits[i0],pCharged ? iChargedParticles : iParticles,pAlgo,pCone);
156 fVals.push_back(pVal);
159 LogDebug(
"NotFound" ) <<
"====> Value is Nan " << pVal <<
" == " << iConstits[i0].pt <<
" -- " << iConstits[i0].eta << endl;
164 for(
int i1 = 0; i1 < fNAlgos; i1++){
166 if(not(
std::abs(iConstits[i0].eta) < fPuppiAlgo[i1].etaMaxExtrap() and iConstits[i0].puppi_register != 0))
172 pAlgo = fPuppiAlgo[i1].algoId (iOpt);
173 pCharged = fPuppiAlgo[i1].isCharged(iOpt);
174 pCone = fPuppiAlgo[i1].coneSize (iOpt);
175 curVal = goodVar(iConstits[i0],pCharged ? iChargedParticles : iParticles,pAlgo,pCone);
178 fPuppiAlgo[i1].add(iConstits[i0],curVal,iOpt);
181 for(
int i0 = 0; i0 < fNAlgos; i0++) fPuppiAlgo[i0].computeMedRMS(iOpt,fPVFrac);
185 void PuppiContainer::getRawAlphas(
int iOpt,std::vector<PuppiCandidate>
const &iConstits,std::vector<PuppiCandidate>
const &iParticles,std::vector<PuppiCandidate>
const &iChargedParticles) {
186 for(
int j0 = 0; j0 < fNAlgos; j0++){
187 for(
unsigned int i0 = 0; i0 < iConstits.size(); i0++ ) {
189 int pAlgo = fPuppiAlgo[j0].algoId (iOpt);
190 bool pCharged = fPuppiAlgo[j0].isCharged(iOpt);
191 double pCone = fPuppiAlgo[j0].coneSize (iOpt);
193 double const pVal = goodVar(iConstits[i0],pCharged ? iChargedParticles : iParticles,pAlgo,pCone);
194 fRawAlphas.push_back(pVal);
196 LogDebug(
"NotFound" ) <<
"====> Value is Nan " << pVal <<
" == " << iConstits[i0].pt <<
" -- " << iConstits[i0].eta << endl;
204 for(
int i0 = 0; i0 < fNAlgos; i0++) {
205 int nEtaBinsPerAlgo = fPuppiAlgo[i0].etaBins();
206 for (
int i1 = 0; i1 < nEtaBinsPerAlgo; i1++){
208 fPuppiAlgo[i0].fixAlgoEtaBin( i1 );
209 if(iPt > fPuppiAlgo[i0].
ptMin()){
224 double lProbLV = ROOT::Math::normal_cdf_c(
std::abs(iDZ),1.)*2.;
225 double lProbPU = 1-lProbLV;
226 if(lProbPU <= 0) lProbPU = 1
e-16;
227 if(lProbPU >= 0) lProbPU = 1-1
e-16;
228 double lChi2PU = TMath::ChisquareQuantile(lProbPU,1);
233 int lNParticles = fRecoParticles->size();
235 fPupParticles .clear();
236 fPupParticles.reserve(lNParticles);
238 fWeights.reserve(lNParticles);
240 fVals.reserve(lNParticles);
241 for(
int i0 = 0; i0 < fNAlgos; i0++) fPuppiAlgo[i0].
reset();
244 for(
int i0 = 0; i0 < fNAlgos; i0++) lNMaxAlgo =
std::max(fPuppiAlgo[i0].numAlgos(),lNMaxAlgo);
246 for(
int i0 = 0; i0 < lNMaxAlgo; i0++) {
247 getRMSAvg(i0,fPFParticles,fPFParticles,fChargedPV);
249 if (fPuppiDiagnostics) getRawAlphas(0,fPFParticles,fPFParticles,fChargedPV);
251 std::vector<double> pVals;
252 pVals.reserve(lNParticles);
253 for(
int i0 = 0; i0 < lNParticles; i0++) {
258 const auto& rParticle = (*fRecoParticles)[i0];
259 int pPupId = getPuppiId(rParticle.pt,rParticle.eta);
261 fWeights .push_back(pWeight);
262 fAlphaMed.push_back(-10);
263 fAlphaRMS.push_back(-10);
264 fRecoToPup.push_back(-1);
267 fRecoToPup.push_back(fPupParticles.size());
273 pChi2 = getChi2FromdZ(rParticle.dZ);
275 if(rParticle.pfType > 3) pChi2 = 0;
278 int lNAlgos = fPuppiAlgo[pPupId].numAlgos();
279 for(
int i1 = 0; i1 < lNAlgos; i1++) pVals.push_back(fVals[lNParticles*i1+i0]);
281 pWeight = fPuppiAlgo[pPupId].compute(pVals,pChi2);
283 if(rParticle.id == 1 && fApplyCHS ) pWeight = 1;
284 if(rParticle.id == 2 && fApplyCHS ) pWeight = 0;
288 LogDebug(
"PuppiWeightError") <<
"====> Weight is nan : " << pWeight <<
" : pt " << rParticle.pt <<
" -- eta : " << rParticle.eta <<
" -- Value" << fVals[i0] <<
" -- id : " << rParticle.id <<
" -- NAlgos: " << lNAlgos << std::endl;
291 if(pWeight*fPFParticles[i0].
pt < fPuppiAlgo[pPupId].neutralPt(fNPV) && rParticle.id == 0 ) pWeight = 0;
292 if((fPtMax>0) && (rParticle.id == 0))
293 pWeight = std::clamp((fPFParticles[i0].
pt - fPtMaxNeutralsStartSlope) / (fPtMax - fPtMaxNeutralsStartSlope),
296 if(pWeight < fPuppiWeightCut) pWeight = 0;
297 if(fInvert) pWeight = 1.-pWeight;
300 fWeights .push_back(pWeight);
301 fAlphaMed.push_back(fPuppiAlgo[pPupId].
median());
302 fAlphaRMS.push_back(fPuppiAlgo[pPupId].
rms());
311 curjet.
pt *= pWeight;
313 curjet.
px *= pWeight;
314 curjet.
py *= pWeight;
315 curjet.
pz *= pWeight;
318 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])