3 #include "fastjet/internal/base.hh" 4 #include "fastjet/FunctionOfPseudoJet.hh" 5 #include "Math/ProbFunc.h" 16 fPuppiDiagnostics = iConfig.
getParameter<
bool>(
"puppiDiagnostics");
20 fPuppiWeightCut = iConfig.
getParameter<
double>(
"MinPuppiWeight");
21 std::vector<edm::ParameterSet> lAlgos = iConfig.
getParameter<std::vector<edm::ParameterSet> >(
"algos");
22 fNAlgos = lAlgos.size();
23 for(
unsigned int i0 = 0; i0 < lAlgos.size(); i0++) {
25 fPuppiAlgo.push_back(pPuppiConfig);
31 fRecoParticles.resize(0);
32 fPFParticles .resize(0);
33 fChargedPV .resize(0);
34 fPupParticles .resize(0);
44 fRecoParticles = iRecoObjects;
45 for (
unsigned int i = 0;
i < fRecoParticles.size();
i++){
46 fastjet::PseudoJet curPseudoJet;
47 auto fRecoParticle = fRecoParticles[
i];
52 curPseudoJet.reset_PtYPhiM(fRecoParticle.pt,fRecoParticle.rapidity,fRecoParticle.phi,fRecoParticle.m);
54 curPseudoJet.reset_PtYPhiM(0, 99., 0, 0);
57 int puppi_register = 0;
58 if(fRecoParticle.id == 0
or fRecoParticle.charge == 0) puppi_register = 0;
59 if(fRecoParticle.id == 1 and fRecoParticle.charge != 0) puppi_register = fRecoParticle.charge;
60 if(fRecoParticle.id == 2 and fRecoParticle.charge != 0) puppi_register = fRecoParticle.charge+5;
61 curPseudoJet.set_user_info(
new PuppiUserInfo( puppi_register ) );
63 fPFParticles.push_back(curPseudoJet);
65 if(
std::abs(fRecoParticle.id) == 1) fChargedPV.push_back(curPseudoJet);
66 if(
std::abs(fRecoParticle.id) >= 1 ) fPVFrac+=1.;
72 if (fPVFrac != 0) fPVFrac = double(fChargedPV.size())/fPVFrac;
77 double PuppiContainer::goodVar(PseudoJet
const &iPart,std::vector<PseudoJet>
const &iParts,
int iOpt,
const double iRCone) {
79 lPup = var_within_R(iOpt,iParts,iPart,iRCone);
83 if(iId == -1)
return 1;
92 vector<double > near_dR2s; near_dR2s.reserve(
std::min(50UL, particles.size()));
93 vector<double > near_pts; near_pts.reserve(
std::min(50UL, particles.size()));
94 for (
auto const&
part : particles){
95 if (
part.squared_distance(centre) < R*
R ){
97 near_pts.push_back(
part.pt());
103 auto nParts = near_dR2s.size();
104 for(
auto i = 0UL;
i < nParts; ++
i){
105 auto dr2 = near_dR2s[
i];
106 auto pt = near_pts[
i];
107 if(dr2 < 0.0001)
continue;
108 if(iId == 0) var += (
pt/dr2);
109 else if(iId == 1) var +=
pt;
110 else if(iId == 2) var += (1./dr2);
111 else if(iId == 3) var += (1./dr2);
112 else if(iId == 4) var +=
pt;
113 else if(iId == 5) var += (
pt *
pt/dr2);
115 if(iId == 1) var += centre.pt();
116 else if(iId == 0 && var != 0) var =
log(var);
117 else if(iId == 3 && var != 0) var =
log(var);
118 else if(iId == 5 && var != 0) var =
log(var);
122 void PuppiContainer::getRMSAvg(
int iOpt,std::vector<fastjet::PseudoJet>
const &iConstits,std::vector<fastjet::PseudoJet>
const &iParticles,std::vector<fastjet::PseudoJet>
const &iChargedParticles) {
123 for(
unsigned int i0 = 0; i0 < iConstits.size(); i0++ ) {
126 int pPupId = getPuppiId(iConstits[i0].
pt(),iConstits[i0].
eta());
127 if(pPupId == -1 || fPuppiAlgo[pPupId].numAlgos() <= iOpt){
132 int pAlgo = fPuppiAlgo[pPupId].algoId (iOpt);
133 bool pCharged = fPuppiAlgo[pPupId].isCharged(iOpt);
134 double pCone = fPuppiAlgo[pPupId].coneSize (iOpt);
136 if(!pCharged) pVal = goodVar(iConstits[i0],iParticles ,pAlgo,pCone);
137 if( pCharged) pVal = goodVar(iConstits[i0],iChargedParticles,pAlgo,pCone);
138 fVals.push_back(pVal);
141 LogDebug(
"NotFound" ) <<
"====> Value is Nan " << pVal <<
" == " << iConstits[i0].pt() <<
" -- " << iConstits[i0].eta() << endl;
147 for(
int i1 = 0; i1 < fNAlgos; i1++){
148 pAlgo = fPuppiAlgo[i1].algoId (iOpt);
149 pCharged = fPuppiAlgo[i1].isCharged(iOpt);
150 pCone = fPuppiAlgo[i1].coneSize (iOpt);
152 if(!pCharged) curVal = goodVar(iConstits[i0],iParticles ,pAlgo,pCone);
153 if( pCharged) curVal = goodVar(iConstits[i0],iChargedParticles,pAlgo,pCone);
155 fPuppiAlgo[i1].add(iConstits[i0],curVal,iOpt);
159 for(
int i0 = 0; i0 < fNAlgos; i0++) fPuppiAlgo[i0].computeMedRMS(iOpt,fPVFrac);
162 void PuppiContainer::getRawAlphas(
int iOpt,std::vector<fastjet::PseudoJet>
const &iConstits,std::vector<fastjet::PseudoJet>
const &iParticles,std::vector<fastjet::PseudoJet>
const &iChargedParticles) {
163 for(
int j0 = 0; j0 < fNAlgos; j0++){
164 for(
unsigned int i0 = 0; i0 < iConstits.size(); i0++ ) {
167 int pAlgo = fPuppiAlgo[j0].algoId (iOpt);
168 bool pCharged = fPuppiAlgo[j0].isCharged(iOpt);
169 double pCone = fPuppiAlgo[j0].coneSize (iOpt);
171 if(!pCharged) pVal = goodVar(iConstits[i0],iParticles ,pAlgo,pCone);
172 if( pCharged) pVal = goodVar(iConstits[i0],iChargedParticles,pAlgo,pCone);
173 fRawAlphas.push_back(pVal);
175 LogDebug(
"NotFound" ) <<
"====> Value is Nan " << pVal <<
" == " << iConstits[i0].pt() <<
" -- " << iConstits[i0].eta() << endl;
183 for(
int i0 = 0; i0 < fNAlgos; i0++) {
184 int nEtaBinsPerAlgo = fPuppiAlgo[i0].etaBins();
185 for (
int i1 = 0; i1 < nEtaBinsPerAlgo; i1++){
187 fPuppiAlgo[i0].fixAlgoEtaBin( i1 );
188 if(iPt > fPuppiAlgo[i0].
ptMin()){
203 double lProbLV = ROOT::Math::normal_cdf_c(
std::abs(iDZ),1.)*2.;
204 double lProbPU = 1-lProbLV;
205 if(lProbPU <= 0) lProbPU = 1
e-16;
206 if(lProbPU >= 0) lProbPU = 1-1
e-16;
207 double lChi2PU = TMath::ChisquareQuantile(lProbPU,1);
212 fPupParticles .resize(0);
215 for(
int i0 = 0; i0 < fNAlgos; i0++) fPuppiAlgo[i0].
reset();
218 for(
int i0 = 0; i0 < fNAlgos; i0++) lNMaxAlgo =
std::max(fPuppiAlgo[i0].numAlgos(),lNMaxAlgo);
220 int lNParticles = fRecoParticles.size();
221 for(
int i0 = 0; i0 < lNMaxAlgo; i0++) {
222 getRMSAvg(i0,fPFParticles,fPFParticles,fChargedPV);
224 if (fPuppiDiagnostics) getRawAlphas(0,fPFParticles,fPFParticles,fChargedPV);
226 std::vector<double> pVals;
227 for(
int i0 = 0; i0 < lNParticles; i0++) {
232 int pPupId = getPuppiId(fRecoParticles[i0].
pt,fRecoParticles[i0].
eta);
234 fWeights .push_back(pWeight);
235 fAlphaMed.push_back(-10);
236 fAlphaRMS.push_back(-10);
243 pChi2 = getChi2FromdZ(fRecoParticles[i0].dZ);
245 if(fRecoParticles[i0].pfType > 3) pChi2 = 0;
248 int lNAlgos = fPuppiAlgo[pPupId].numAlgos();
249 for(
int i1 = 0; i1 < lNAlgos; i1++) pVals.push_back(fVals[lNParticles*i1+i0]);
251 pWeight = fPuppiAlgo[pPupId].compute(pVals,pChi2);
253 if(fRecoParticles[i0].
id == 1 && fApplyCHS ) pWeight = 1;
254 if(fRecoParticles[i0].
id == 2 && fApplyCHS ) pWeight = 0;
258 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;
261 if(pWeight < fPuppiWeightCut) pWeight = 0;
262 if(pWeight*fPFParticles[i0].
pt() < fPuppiAlgo[pPupId].neutralPt(fNPV) && fRecoParticles[i0].
id == 0 ) pWeight = 0;
263 if(fInvert) pWeight = 1.-pWeight;
266 fWeights .push_back(pWeight);
267 fAlphaMed.push_back(fPuppiAlgo[pPupId].median());
268 fAlphaRMS.push_back(fPuppiAlgo[pPupId].
rms());
276 PseudoJet curjet( pWeight*fPFParticles[i0].px(), pWeight*fPFParticles[i0].py(), pWeight*fPFParticles[i0].pz(), pWeight*fPFParticles[i0].
e() );
277 curjet.set_user_index(i0);
278 fPupParticles.push_back(curjet);
T getParameter(std::string const &) const
std::vector< double > const & puppiWeights()
double getChi2FromdZ(double iDZ)
void getRMSAvg(int iOpt, std::vector< fastjet::PseudoJet > const &iConstits, std::vector< fastjet::PseudoJet > const &iParticles, std::vector< fastjet::PseudoJet > 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)
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 var_within_R(int iId, const std::vector< fastjet::PseudoJet > &particles, const fastjet::PseudoJet ¢re, const double R)
int getPuppiId(float iPt, float iEta)
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
double goodVar(fastjet::PseudoJet const &iPart, std::vector< fastjet::PseudoJet > const &iParts, int iOpt, const double iRCone)
void initialize(const std::vector< RecoObj > &iRecoObjects)
void reset(double vett[256])