2 #include "fastjet/internal/base.hh"
3 #include "fastjet/FunctionOfPseudoJet.hh"
4 #include "Math/ProbFunc.h"
12 using namespace fastjet;
15 fPuppiDiagnostics = iConfig.
getParameter<
bool>(
"puppiDiagnostics");
19 fPuppiWeightCut = iConfig.
getParameter<
double>(
"MinPuppiWeight");
20 std::vector<edm::ParameterSet> lAlgos = iConfig.
getParameter<std::vector<edm::ParameterSet> >(
"algos");
21 fNAlgos = lAlgos.size();
22 for(
unsigned int i0 = 0; i0 < lAlgos.size(); i0++) {
24 fPuppiAlgo.push_back(pPuppiConfig);
30 fRecoParticles.resize(0);
31 fPFParticles .resize(0);
32 fChargedPV .resize(0);
33 fPupParticles .resize(0);
43 fRecoParticles = iRecoObjects;
44 for (
unsigned int i = 0;
i < fRecoParticles.size();
i++){
45 fastjet::PseudoJet curPseudoJet;
46 auto fRecoParticle = fRecoParticles[
i];
50 curPseudoJet.reset_PtYPhiM(fRecoParticle.pt,fRecoParticle.rapidity,fRecoParticle.phi,fRecoParticle.m);
52 int puppi_register = 0;
53 if(fRecoParticle.id == 0
or fRecoParticle.charge == 0) puppi_register = 0;
54 if(fRecoParticle.id == 1 and fRecoParticle.charge != 0) puppi_register = fRecoParticle.charge;
55 if(fRecoParticle.id == 2 and fRecoParticle.charge != 0) puppi_register = fRecoParticle.charge+5;
56 curPseudoJet.set_user_info(
new PuppiUserInfo( puppi_register ) );
58 fPFParticles.push_back(curPseudoJet);
60 if(
std::abs(fRecoParticle.id) == 1) fChargedPV.push_back(curPseudoJet);
61 if(
std::abs(fRecoParticle.id) >= 1 ) fPVFrac+=1.;
67 if (fPVFrac != 0) fPVFrac = double(fChargedPV.size())/fPVFrac;
74 lPup = var_within_R(iOpt,iParts,iPart,iRCone);
78 if(iId == -1)
return 1;
79 fastjet::Selector
sel = fastjet::SelectorCircle(R);
80 sel.set_reference(centre);
81 vector<PseudoJet> near_particles =
sel(particles);
85 for(
unsigned int i=0;
i<near_particles.size();
i++){
86 double pDEta = near_particles[
i].eta()-centre.eta();
87 double pDPhi =
std::abs(near_particles[
i].
phi()-centre.phi());
88 if(pDPhi > 2.*
M_PI-pDPhi) pDPhi = 2.*
M_PI-pDPhi;
89 double pDR2 = pDEta*pDEta+pDPhi*pDPhi;
90 if(
std::abs(pDR2) < 0.0001)
continue;
91 if(iId == 0) var += (near_particles[
i].pt()/pDR2);
92 if(iId == 1) var += near_particles[
i].pt();
93 if(iId == 2) var += (1./pDR2);
94 if(iId == 3) var += (1./pDR2);
95 if(iId == 4) var += near_particles[
i].pt();
96 if(iId == 5) var += (near_particles[
i].pt() * near_particles[
i].pt()/pDR2);
98 if(iId == 1) var += centre.pt();
99 if(iId == 0 && var != 0) var =
log(var);
100 if(iId == 3 && var != 0) var =
log(var);
101 if(iId == 5 && var != 0) var =
log(var);
105 void PuppiContainer::getRMSAvg(
int iOpt,std::vector<fastjet::PseudoJet>
const &iConstits,std::vector<fastjet::PseudoJet>
const &iParticles,std::vector<fastjet::PseudoJet>
const &iChargedParticles) {
106 for(
unsigned int i0 = 0; i0 < iConstits.size(); i0++ ) {
109 int pPupId = getPuppiId(iConstits[i0].
pt(),iConstits[i0].
eta());
110 if(pPupId == -1 || fPuppiAlgo[pPupId].numAlgos() <= iOpt){
115 int pAlgo = fPuppiAlgo[pPupId].algoId (iOpt);
116 bool pCharged = fPuppiAlgo[pPupId].isCharged(iOpt);
117 double pCone = fPuppiAlgo[pPupId].coneSize (iOpt);
119 if(!pCharged) pVal = goodVar(iConstits[i0],iParticles ,pAlgo,pCone);
120 if( pCharged) pVal = goodVar(iConstits[i0],iChargedParticles,pAlgo,pCone);
121 fVals.push_back(pVal);
124 LogDebug(
"NotFound" ) <<
"====> Value is Nan " << pVal <<
" == " << iConstits[i0].pt() <<
" -- " << iConstits[i0].eta() << endl;
130 for(
int i1 = 0; i1 < fNAlgos; i1++){
131 pAlgo = fPuppiAlgo[i1].algoId (iOpt);
132 pCharged = fPuppiAlgo[i1].isCharged(iOpt);
133 pCone = fPuppiAlgo[i1].coneSize (iOpt);
135 if(!pCharged) curVal = goodVar(iConstits[i0],iParticles ,pAlgo,pCone);
136 if( pCharged) curVal = goodVar(iConstits[i0],iChargedParticles,pAlgo,pCone);
138 fPuppiAlgo[i1].add(iConstits[i0],curVal,iOpt);
142 for(
int i0 = 0; i0 < fNAlgos; i0++) fPuppiAlgo[i0].computeMedRMS(iOpt,fPVFrac);
145 void PuppiContainer::getRawAlphas(
int iOpt,std::vector<fastjet::PseudoJet>
const &iConstits,std::vector<fastjet::PseudoJet>
const &iParticles,std::vector<fastjet::PseudoJet>
const &iChargedParticles) {
146 for(
int j0 = 0; j0 < fNAlgos; j0++){
147 for(
unsigned int i0 = 0; i0 < iConstits.size(); i0++ ) {
150 int pAlgo = fPuppiAlgo[j0].algoId (iOpt);
151 bool pCharged = fPuppiAlgo[j0].isCharged(iOpt);
152 double pCone = fPuppiAlgo[j0].coneSize (iOpt);
154 if(!pCharged) pVal = goodVar(iConstits[i0],iParticles ,pAlgo,pCone);
155 if( pCharged) pVal = goodVar(iConstits[i0],iChargedParticles,pAlgo,pCone);
156 fRawAlphas.push_back(pVal);
158 LogDebug(
"NotFound" ) <<
"====> Value is Nan " << pVal <<
" == " << iConstits[i0].pt() <<
" -- " << iConstits[i0].eta() << endl;
166 for(
int i0 = 0; i0 < fNAlgos; i0++) {
169 if(iPt < fPuppiAlgo[i0].
ptMin())
continue;
181 double lProbLV = ROOT::Math::normal_cdf_c(
std::abs(iDZ),1.)*2.;
182 double lProbPU = 1-lProbLV;
183 if(lProbPU <= 0) lProbPU = 1
e-16;
184 if(lProbPU >= 0) lProbPU = 1-1
e-16;
185 double lChi2PU = TMath::ChisquareQuantile(lProbPU,1);
190 fPupParticles .resize(0);
193 for(
int i0 = 0; i0 < fNAlgos; i0++) fPuppiAlgo[i0].
reset();
196 for(
int i0 = 0; i0 < fNAlgos; i0++) lNMaxAlgo =
std::max(fPuppiAlgo[i0].numAlgos(),lNMaxAlgo);
198 int lNParticles = fRecoParticles.size();
199 for(
int i0 = 0; i0 < lNMaxAlgo; i0++) {
200 getRMSAvg(i0,fPFParticles,fPFParticles,fChargedPV);
202 if (fPuppiDiagnostics) getRawAlphas(0,fPFParticles,fPFParticles,fChargedPV);
204 std::vector<double> pVals;
205 for(
int i0 = 0; i0 < lNParticles; i0++) {
210 int pPupId = getPuppiId(fRecoParticles[i0].
pt,fRecoParticles[i0].
eta);
212 fWeights .push_back(pWeight);
213 fAlphaMed.push_back(-10);
214 fAlphaRMS.push_back(-10);
221 pChi2 = getChi2FromdZ(fRecoParticles[i0].dZ);
223 if(fRecoParticles[i0].pfType > 3) pChi2 = 0;
226 int lNAlgos = fPuppiAlgo[pPupId].numAlgos();
227 for(
int i1 = 0; i1 < lNAlgos; i1++) pVals.push_back(fVals[lNParticles*i1+i0]);
229 pWeight = fPuppiAlgo[pPupId].compute(pVals,pChi2);
231 if(fRecoParticles[i0].
id == 1 && fApplyCHS ) pWeight = 1;
232 if(fRecoParticles[i0].
id == 2 && fApplyCHS ) pWeight = 0;
236 LogDebug(
"PuppiWeightError") <<
"====> Weight is nan : " << pWeight <<
" : pt " << fRecoParticles[i0].pt <<
" -- eta : " << fRecoParticles[i0].eta <<
" -- Value" << fVals[i0] <<
" -- id : " << fRecoParticles[i0].id <<
" -- NAlgos: " << lNAlgos << std::endl;
239 if(pWeight < fPuppiWeightCut) pWeight = 0;
240 if(pWeight*fPFParticles[i0].
pt() < fPuppiAlgo[pPupId].neutralPt(fNPV) && fRecoParticles[i0].
id == 0 ) pWeight = 0;
241 if(fInvert) pWeight = 1.-pWeight;
244 fWeights .push_back(pWeight);
245 fAlphaMed.push_back(fPuppiAlgo[pPupId].median(0));
246 fAlphaRMS.push_back(fPuppiAlgo[pPupId].
rms(0));
254 PseudoJet curjet( pWeight*fPFParticles[i0].px(), pWeight*fPFParticles[i0].py(), pWeight*fPFParticles[i0].pz(), pWeight*fPFParticles[i0].
e());
255 curjet.set_user_index(i0);
256 fPupParticles.push_back(curjet);
T getParameter(std::string const &) const
std::vector< double > const & puppiWeights()
double getChi2FromdZ(double iDZ)
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::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
double var_within_R(int iId, const std::vector< fastjet::PseudoJet > &particles, const fastjet::PseudoJet ¢re, double R)
void getRMSAvg(int iOpt, std::vector< fastjet::PseudoJet > const &iConstits, std::vector< fastjet::PseudoJet > const &iParticles, std::vector< fastjet::PseudoJet > const &iChargeParticles)
PuppiContainer(const edm::ParameterSet &iConfig)
void getRawAlphas(int iOpt, std::vector< fastjet::PseudoJet > const &iConstits, std::vector< fastjet::PseudoJet > const &iParticles, std::vector< fastjet::PseudoJet > const &iChargeParticles)
Abs< T >::type abs(const T &t)
double goodVar(fastjet::PseudoJet const &iPart, std::vector< fastjet::PseudoJet > const &iParts, int iOpt, double iRCone)
int getPuppiId(float iPt, float iEta)
void initialize(const std::vector< RecoObj > &iRecoObjects)
void reset(double vett[256])