3 #include "Math/ProbFunc.h" 13 fPuppiDiagnostics = iConfig.
getParameter<
bool>(
"puppiDiagnostics");
17 fPuppiWeightCut = iConfig.
getParameter<
double>(
"MinPuppiWeight");
19 std::vector<edm::ParameterSet> lAlgos = iConfig.
getParameter<std::vector<edm::ParameterSet> >(
"algos");
20 fNAlgos = lAlgos.size();
21 for(
unsigned int i0 = 0; i0 < lAlgos.size(); i0++) {
23 fPuppiAlgo.push_back(pPuppiConfig);
29 fPFParticles .resize(0);
30 fChargedPV .resize(0);
31 fPupParticles .resize(0);
41 fRecoParticles = &iRecoObjects;
43 fRecoToPup.reserve(fRecoParticles->size());
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);
55 int puppi_register = 0;
56 if(rParticle.id == 0
or rParticle.charge == 0) puppi_register = 0;
57 if(rParticle.id == 1 and rParticle.charge != 0) puppi_register = rParticle.charge;
58 if(rParticle.id == 2 and rParticle.charge != 0) puppi_register = rParticle.charge+5;
59 curPseudoJet.
set_info( puppi_register );
61 fPFParticles.push_back(curPseudoJet);
63 if(
std::abs(rParticle.id) == 1) fChargedPV.push_back(curPseudoJet);
64 if(
std::abs(rParticle.id) >= 1 ) fPVFrac+=1.;
68 if (fPVFrac != 0) fPVFrac = double(fChargedPV.size())/fPVFrac;
74 return var_within_R(iOpt,iParts,iPart,iRCone);
78 if(iId == -1)
return 1;
87 vector<double > near_dR2s; near_dR2s.reserve(
std::min(50UL, particles.size()));
88 vector<double > near_pts; near_pts.reserve(
std::min(50UL, particles.size()));
89 const double r2 = R*
R;
90 for (
auto const&
part : particles){
94 near_pts.push_back(
part.pt());
100 auto nParts = near_dR2s.size();
101 for(
auto i = 0UL;
i < nParts; ++
i){
102 auto dr2 = near_dR2s[
i];
103 auto pt = near_pts[
i];
104 if(dr2 < 0.0001)
continue;
105 if(iId == 0) var += (
pt/dr2);
106 else if(iId == 1) var +=
pt;
107 else if(iId == 2) var += (1./dr2);
108 else if(iId == 3) var += (1./dr2);
109 else if(iId == 4) var +=
pt;
110 else if(iId == 5) var += (
pt *
pt/dr2);
112 if(iId == 1) var += centre.pt();
113 else if(iId == 0 && var != 0) var =
log(var);
114 else if(iId == 3 && var != 0) var =
log(var);
115 else if(iId == 5 && var != 0) var =
log(var);
119 void PuppiContainer::getRMSAvg(
int iOpt,std::vector<PuppiCandidate>
const &iConstits,std::vector<PuppiCandidate>
const &iParticles,std::vector<PuppiCandidate>
const &iChargedParticles) {
120 for(
unsigned int i0 = 0; i0 < iConstits.size(); i0++ ) {
123 int pPupId = getPuppiId(iConstits[i0].
pt(),iConstits[i0].
eta());
124 if(pPupId == -1 || fPuppiAlgo[pPupId].numAlgos() <= iOpt){
129 int pAlgo = fPuppiAlgo[pPupId].algoId (iOpt);
130 bool pCharged = fPuppiAlgo[pPupId].isCharged(iOpt);
131 double pCone = fPuppiAlgo[pPupId].coneSize (iOpt);
133 if(!pCharged) pVal = goodVar(iConstits[i0],iParticles ,pAlgo,pCone);
134 if( pCharged) pVal = goodVar(iConstits[i0],iChargedParticles,pAlgo,pCone);
135 fVals.push_back(pVal);
138 LogDebug(
"NotFound" ) <<
"====> Value is Nan " << pVal <<
" == " << iConstits[i0].pt() <<
" -- " << iConstits[i0].eta() << endl;
144 for(
int i1 = 0; i1 < fNAlgos; i1++){
145 pAlgo = fPuppiAlgo[i1].algoId (iOpt);
146 pCharged = fPuppiAlgo[i1].isCharged(iOpt);
147 pCone = fPuppiAlgo[i1].coneSize (iOpt);
150 if(!pCharged) curVal = goodVar(iConstits[i0],iParticles ,pAlgo,pCone);
151 if( pCharged) curVal = goodVar(iConstits[i0],iChargedParticles,pAlgo,pCone);
156 fPuppiAlgo[i1].add(iConstits[i0],curVal,iOpt);
160 for(
int i0 = 0; i0 < fNAlgos; i0++) fPuppiAlgo[i0].computeMedRMS(iOpt,fPVFrac);
163 void PuppiContainer::getRawAlphas(
int iOpt,std::vector<PuppiCandidate>
const &iConstits,std::vector<PuppiCandidate>
const &iParticles,std::vector<PuppiCandidate>
const &iChargedParticles) {
164 for(
int j0 = 0; j0 < fNAlgos; j0++){
165 for(
unsigned int i0 = 0; i0 < iConstits.size(); i0++ ) {
168 int pAlgo = fPuppiAlgo[j0].algoId (iOpt);
169 bool pCharged = fPuppiAlgo[j0].isCharged(iOpt);
170 double pCone = fPuppiAlgo[j0].coneSize (iOpt);
172 if(!pCharged) pVal = goodVar(iConstits[i0],iParticles ,pAlgo,pCone);
173 if( pCharged) pVal = goodVar(iConstits[i0],iChargedParticles,pAlgo,pCone);
174 fRawAlphas.push_back(pVal);
176 LogDebug(
"NotFound" ) <<
"====> Value is Nan " << pVal <<
" == " << iConstits[i0].pt() <<
" -- " << iConstits[i0].eta() << endl;
184 for(
int i0 = 0; i0 < fNAlgos; i0++) {
185 int nEtaBinsPerAlgo = fPuppiAlgo[i0].etaBins();
186 for (
int i1 = 0; i1 < nEtaBinsPerAlgo; i1++){
188 fPuppiAlgo[i0].fixAlgoEtaBin( i1 );
189 if(iPt > fPuppiAlgo[i0].
ptMin()){
204 double lProbLV = ROOT::Math::normal_cdf_c(
std::abs(iDZ),1.)*2.;
205 double lProbPU = 1-lProbLV;
206 if(lProbPU <= 0) lProbPU = 1
e-16;
207 if(lProbPU >= 0) lProbPU = 1-1
e-16;
208 double lChi2PU = TMath::ChisquareQuantile(lProbPU,1);
213 int lNParticles = fRecoParticles->size();
215 fPupParticles .clear();
216 fPupParticles.reserve(lNParticles);
218 fWeights.reserve(lNParticles);
220 fVals.reserve(lNParticles);
221 for(
int i0 = 0; i0 < fNAlgos; i0++) fPuppiAlgo[i0].
reset();
224 for(
int i0 = 0; i0 < fNAlgos; i0++) lNMaxAlgo =
std::max(fPuppiAlgo[i0].numAlgos(),lNMaxAlgo);
226 for(
int i0 = 0; i0 < lNMaxAlgo; i0++) {
227 getRMSAvg(i0,fPFParticles,fPFParticles,fChargedPV);
229 if (fPuppiDiagnostics) getRawAlphas(0,fPFParticles,fPFParticles,fChargedPV);
231 std::vector<double> pVals;
232 pVals.reserve(lNParticles);
233 for(
int i0 = 0; i0 < lNParticles; i0++) {
238 const auto& rParticle = (*fRecoParticles)[i0];
239 int pPupId = getPuppiId(rParticle.pt,rParticle.eta);
241 fWeights .push_back(pWeight);
242 fAlphaMed.push_back(-10);
243 fAlphaRMS.push_back(-10);
244 fRecoToPup.push_back(-1);
247 fRecoToPup.push_back(fPupParticles.size());
253 pChi2 = getChi2FromdZ(rParticle.dZ);
255 if(rParticle.pfType > 3) pChi2 = 0;
258 int lNAlgos = fPuppiAlgo[pPupId].numAlgos();
259 for(
int i1 = 0; i1 < lNAlgos; i1++) pVals.push_back(fVals[lNParticles*i1+i0]);
261 pWeight = fPuppiAlgo[pPupId].compute(pVals,pChi2);
263 if(rParticle.id == 1 && fApplyCHS ) pWeight = 1;
264 if(rParticle.id == 2 && fApplyCHS ) pWeight = 0;
268 LogDebug(
"PuppiWeightError") <<
"====> Weight is nan : " << pWeight <<
" : pt " << rParticle.pt <<
" -- eta : " << rParticle.eta <<
" -- Value" << fVals[i0] <<
" -- id : " << rParticle.id <<
" -- NAlgos: " << lNAlgos << std::endl;
271 if(pWeight*fPFParticles[i0].
pt() < fPuppiAlgo[pPupId].neutralPt(fNPV) && rParticle.id == 0 ) pWeight = 0;
272 if((fPtMax>0) && (rParticle.id == 0)) pWeight=
min(
max(pWeight,fPFParticles[i0].
pt()/fPtMax),1.);
273 if(pWeight < fPuppiWeightCut) pWeight = 0;
274 if(fInvert) pWeight = 1.-pWeight;
277 fWeights .push_back(pWeight);
278 fAlphaMed.push_back(fPuppiAlgo[pPupId].
median());
279 fAlphaRMS.push_back(fPuppiAlgo[pPupId].
rms());
287 PuppiCandidate curjet( pWeight*fPFParticles[i0].px(), pWeight*fPFParticles[i0].py(), pWeight*fPFParticles[i0].pz(), pWeight*fPFParticles[i0].
e() );
288 curjet.set_user_index(i0);
289 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 set_info(int puppi_register)
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])