2 #include "fastjet/internal/base.hh"
3 #include "fastjet/FunctionOfPseudoJet.hh"
4 #include "Math/ProbFunc.h"
12 using namespace fastjet;
17 fPuppiWeightCut = iConfig.
getParameter<
double>(
"MinPuppiWeight");
18 std::vector<edm::ParameterSet> lAlgos = iConfig.
getParameter<std::vector<edm::ParameterSet> >(
"algos");
19 fNAlgos = lAlgos.size();
20 for(
unsigned int i0 = 0; i0 < lAlgos.size(); i0++) {
22 fPuppiAlgo.push_back(pPuppiConfig);
28 fRecoParticles.resize(0);
29 fPFParticles .resize(0);
30 fChargedPV .resize(0);
31 fPupParticles .resize(0);
38 fRecoParticles = iRecoObjects;
39 for (
unsigned int i = 0;
i < fRecoParticles.size();
i++){
40 fastjet::PseudoJet curPseudoJet;
41 auto fRecoParticle = fRecoParticles[
i];
42 curPseudoJet.reset_PtYPhiM(fRecoParticle.pt,fRecoParticle.eta,fRecoParticle.phi,fRecoParticle.m);
43 int puppi_register = 0;
44 if(fRecoParticle.id == 0
or fRecoParticle.charge == 0) puppi_register = 0;
45 if(fRecoParticle.id == 1 and fRecoParticle.charge != 0) puppi_register = fRecoParticle.charge;
46 if(fRecoParticle.id == 2 and fRecoParticle.charge != 0) puppi_register = fRecoParticle.charge+5;
47 curPseudoJet.set_user_info(
new PuppiUserInfo( puppi_register ) );
49 fPFParticles.push_back(curPseudoJet);
51 if(
std::abs(fRecoParticle.id) == 1) fChargedPV.push_back(curPseudoJet);
52 if(
std::abs(fRecoParticle.id) >= 1 ) fPVFrac+=1.;
56 if(fNPV < fRecoParticle.vtxId) fNPV = fRecoParticle.vtxId;
58 if (fPVFrac != 0) fPVFrac = double(fChargedPV.size())/fPVFrac;
65 lPup = var_within_R(iOpt,iParts,iPart,iRCone);
69 if(iId == -1)
return 1;
70 fastjet::Selector
sel = fastjet::SelectorCircle(R);
71 sel.set_reference(centre);
72 vector<PseudoJet> near_particles =
sel(particles);
76 for(
unsigned int i=0;
i<near_particles.size();
i++){
77 double pDEta = near_particles[
i].eta()-centre.eta();
78 double pDPhi =
std::abs(near_particles[
i].
phi()-centre.phi());
79 if(pDPhi > 2.*
M_PI-pDPhi) pDPhi = 2.*
M_PI-pDPhi;
80 double pDR2 = pDEta*pDEta+pDPhi*pDPhi;
81 if(
std::abs(pDR2) < 0.0001)
continue;
82 if(iId == 0) var += (near_particles[
i].pt()/pDR2);
83 if(iId == 1) var += near_particles[
i].pt();
84 if(iId == 2) var += (1./pDR2);
85 if(iId == 3) var += (1./pDR2);
86 if(iId == 4) var += near_particles[
i].pt();
87 if(iId == 5) var += (near_particles[
i].pt() * near_particles[
i].pt()/pDR2);
89 if(iId == 1) var += centre.pt();
90 if(iId == 0 && var != 0) var =
log(var);
91 if(iId == 3 && var != 0) var =
log(var);
92 if(iId == 5 && var != 0) var =
log(var);
96 void PuppiContainer::getRMSAvg(
int iOpt,std::vector<fastjet::PseudoJet>
const &iConstits,std::vector<fastjet::PseudoJet>
const &iParticles,std::vector<fastjet::PseudoJet>
const &iChargedParticles) {
97 for(
unsigned int i0 = 0; i0 < iConstits.size(); i0++ ) {
100 int pPupId = getPuppiId(iConstits[i0].
pt(),iConstits[i0].
eta());
101 if(pPupId == -1 || fPuppiAlgo[pPupId].numAlgos() <= iOpt){
106 int pAlgo = fPuppiAlgo[pPupId].algoId (iOpt);
107 bool pCharged = fPuppiAlgo[pPupId].isCharged(iOpt);
108 double pCone = fPuppiAlgo[pPupId].coneSize (iOpt);
110 if(!pCharged) pVal = goodVar(iConstits[i0],iParticles ,pAlgo,pCone);
111 if( pCharged) pVal = goodVar(iConstits[i0],iChargedParticles,pAlgo,pCone);
112 fVals.push_back(pVal);
115 LogDebug(
"NotFound" ) <<
"====> Value is Nan " << pVal <<
" == " << iConstits[i0].pt() <<
" -- " << iConstits[i0].eta() << endl;
118 fPuppiAlgo[pPupId].add(iConstits[i0],pVal,iOpt);
120 for(
int i0 = 0; i0 < fNAlgos; i0++) fPuppiAlgo[i0].computeMedRMS(iOpt,fPVFrac);
124 for(
int i0 = 0; i0 < fNAlgos; i0++) {
127 if(iPt < fPuppiAlgo[i0].
ptMin())
continue;
139 double lProbLV = ROOT::Math::normal_cdf_c(
std::abs(iDZ),1.)*2.;
140 double lProbPU = 1-lProbLV;
141 if(lProbPU <= 0) lProbPU = 1
e-16;
142 if(lProbPU >= 0) lProbPU = 1-1
e-16;
143 double lChi2PU = TMath::ChisquareQuantile(lProbPU,1);
148 fPupParticles .resize(0);
151 for(
int i0 = 0; i0 < fNAlgos; i0++) fPuppiAlgo[i0].
reset();
154 for(
int i0 = 0; i0 < fNAlgos; i0++) lNMaxAlgo =
std::max(fPuppiAlgo[i0].numAlgos(),lNMaxAlgo);
156 int lNParticles = fRecoParticles.size();
157 for(
int i0 = 0; i0 < lNMaxAlgo; i0++) {
158 getRMSAvg(i0,fPFParticles,fPFParticles,fChargedPV);
160 std::vector<double> pVals;
161 for(
int i0 = 0; i0 < lNParticles; i0++) {
166 int pPupId = getPuppiId(fRecoParticles[i0].
pt,fRecoParticles[i0].
eta);
168 fWeights .push_back(pWeight);
175 pChi2 = getChi2FromdZ(fRecoParticles[i0].dZ);
177 if(fRecoParticles[i0].pfType > 3) pChi2 = 0;
180 int lNAlgos = fPuppiAlgo[pPupId].numAlgos();
181 for(
int i1 = 0; i1 < lNAlgos; i1++) pVals.push_back(fVals[lNParticles*i1+i0]);
182 pWeight = fPuppiAlgo[pPupId].compute(pVals,pChi2);
184 if(fRecoParticles[i0].
id == 1 && fApplyCHS ) pWeight = 1;
185 if(fRecoParticles[i0].
id == 2 && fApplyCHS ) pWeight = 0;
189 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;
192 if(pWeight < fPuppiWeightCut) pWeight = 0;
193 if(pWeight*fPFParticles[i0].
pt() < fPuppiAlgo[pPupId].neutralPt(fNPV) && fRecoParticles[i0].
id == 0 ) pWeight = 0;
194 fWeights .push_back(pWeight);
196 if(
std::abs(pWeight) < std::numeric_limits<double>::denorm_min() )
continue;
198 PseudoJet curjet( pWeight*fPFParticles[i0].px(), pWeight*fPFParticles[i0].py(), pWeight*fPFParticles[i0].pz(), pWeight*fPFParticles[i0].
e());
199 curjet.set_user_index(i0);
200 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)
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])