CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Protected Member Functions | Protected Attributes
PuppiContainer Class Reference

#include <PuppiContainer.h>

Classes

class  PuppiUserInfo
 

Public Member Functions

void initialize (const std::vector< RecoObj > &iRecoObjects)
 
std::vector
< fastjet::PseudoJet > const & 
pfParticles () const
 
 PuppiContainer (const edm::ParameterSet &iConfig)
 
std::vector
< fastjet::PseudoJet > const & 
puppiParticles () const
 
std::vector< double > const & puppiWeights ()
 
std::vector
< fastjet::PseudoJet > const & 
pvParticles () const
 
 ~PuppiContainer ()
 

Protected Member Functions

double getChi2FromdZ (double iDZ)
 
int getPuppiId (float iPt, float iEta)
 
void getRMSAvg (int iOpt, std::vector< fastjet::PseudoJet > const &iConstits, std::vector< fastjet::PseudoJet > const &iParticles, std::vector< fastjet::PseudoJet > const &iChargeParticles)
 
double goodVar (fastjet::PseudoJet const &iPart, std::vector< fastjet::PseudoJet > const &iParts, int iOpt, double iRCone)
 
double var_within_R (int iId, const std::vector< fastjet::PseudoJet > &particles, const fastjet::PseudoJet &centre, double R)
 

Protected Attributes

bool fApplyCHS
 
std::vector< fastjet::PseudoJet > fChargedPV
 
int fNAlgos
 
double fNeutralMinPt
 
double fNeutralSlope
 
int fNPV
 
std::vector< fastjet::PseudoJet > fPFParticles
 
std::vector< fastjet::PseudoJet > fPupParticles
 
std::vector< PuppiAlgofPuppiAlgo
 
double fPuppiWeightCut
 
double fPVFrac
 
std::vector< RecoObjfRecoParticles
 
bool fUseExp
 
std::vector< double > fVals
 
std::vector< double > fWeights
 

Detailed Description

Definition at line 13 of file PuppiContainer.h.

Constructor & Destructor Documentation

PuppiContainer::PuppiContainer ( const edm::ParameterSet iConfig)

Definition at line 14 of file PuppiContainer.cc.

References edm::ParameterSet::getParameter().

14  {
15  fApplyCHS = iConfig.getParameter<bool>("applyCHS");
16  fUseExp = iConfig.getParameter<bool>("useExp");
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++) {
21  PuppiAlgo pPuppiConfig(lAlgos[i0]);
22  fPuppiAlgo.push_back(pPuppiConfig);
23  }
24 }
T getParameter(std::string const &) const
double fPuppiWeightCut
std::vector< PuppiAlgo > fPuppiAlgo
PuppiContainer::~PuppiContainer ( )

Definition at line 61 of file PuppiContainer.cc.

61 {}

Member Function Documentation

double PuppiContainer::getChi2FromdZ ( double  iDZ)
protected

Definition at line 134 of file PuppiContainer.cc.

References funct::abs(), and alignCSCRings::e.

134  {
135  //We need to obtain prob of PU + (1-Prob of LV)
136  // Prob(LV) = Gaus(dZ,sigma) where sigma = 1.5mm (its really more like 1mm)
137  //double lProbLV = ROOT::Math::normal_cdf_c(std::abs(iDZ),0.2)*2.; //*2 is to do it double sided
138  //Take iDZ to be corrected by sigma already
139  double lProbLV = ROOT::Math::normal_cdf_c(std::abs(iDZ),1.)*2.; //*2 is to do it double sided
140  double lProbPU = 1-lProbLV;
141  if(lProbPU <= 0) lProbPU = 1e-16; //Quick Trick to through out infs
142  if(lProbPU >= 0) lProbPU = 1-1e-16; //Ditto
143  double lChi2PU = TMath::ChisquareQuantile(lProbPU,1);
144  lChi2PU*=lChi2PU;
145  return lChi2PU;
146 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int PuppiContainer::getPuppiId ( float  iPt,
float  iEta 
)
protected

Definition at line 122 of file PuppiContainer.cc.

References funct::abs(), HLT_25ns14e33_v1_cff::etaMax, HLT_25ns14e33_v1_cff::etaMin, and PtMinSelector_cfg::ptMin.

122  {
123  int lId = -1;
124  for(int i0 = 0; i0 < fNAlgos; i0++) {
125  if(std::abs(iEta) < fPuppiAlgo[i0].etaMin()) continue;
126  if(std::abs(iEta) > fPuppiAlgo[i0].etaMax()) continue;
127  if(iPt < fPuppiAlgo[i0].ptMin()) continue;
128  lId = i0;
129  break;
130  }
131  //if(lId == -1) std::cerr << "Error : Full fiducial range is not defined " << std::endl;
132  return lId;
133 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< PuppiAlgo > fPuppiAlgo
void PuppiContainer::getRMSAvg ( int  iOpt,
std::vector< fastjet::PseudoJet > const &  iConstits,
std::vector< fastjet::PseudoJet > const &  iParticles,
std::vector< fastjet::PseudoJet > const &  iChargeParticles 
)
protected

Definition at line 96 of file PuppiContainer.cc.

References eta(), edm::isFinite(), LogDebug, and EnergyCorrector::pt.

96  {
97  for(unsigned int i0 = 0; i0 < iConstits.size(); i0++ ) {
98  double pVal = -1;
99  //Calculate the Puppi Algo to use
100  int pPupId = getPuppiId(iConstits[i0].pt(),iConstits[i0].eta());
101  if(pPupId == -1 || fPuppiAlgo[pPupId].numAlgos() <= iOpt){
102  fVals.push_back(-1);
103  continue;
104  }
105  //Get the Puppi Sub Algo (given iteration)
106  int pAlgo = fPuppiAlgo[pPupId].algoId (iOpt);
107  bool pCharged = fPuppiAlgo[pPupId].isCharged(iOpt);
108  double pCone = fPuppiAlgo[pPupId].coneSize (iOpt);
109  //Compute the Puppi Metric
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);
113  //if(std::isnan(pVal) || std::isinf(pVal)) cerr << "====> Value is Nan " << pVal << " == " << iConstits[i0].pt() << " -- " << iConstits[i0].eta() << endl;
114  if( ! edm::isFinite(pVal)) {
115  LogDebug( "NotFound" ) << "====> Value is Nan " << pVal << " == " << iConstits[i0].pt() << " -- " << iConstits[i0].eta() << endl;
116  continue;
117  }
118  fPuppiAlgo[pPupId].add(iConstits[i0],pVal,iOpt);
119  }
120  for(int i0 = 0; i0 < fNAlgos; i0++) fPuppiAlgo[i0].computeMedRMS(iOpt,fPVFrac);
121 }
#define LogDebug(id)
std::vector< double > fVals
T eta() const
bool isFinite(T x)
double goodVar(fastjet::PseudoJet const &iPart, std::vector< fastjet::PseudoJet > const &iParts, int iOpt, double iRCone)
int getPuppiId(float iPt, float iEta)
std::vector< PuppiAlgo > fPuppiAlgo
double PuppiContainer::goodVar ( fastjet::PseudoJet const &  iPart,
std::vector< fastjet::PseudoJet > const &  iParts,
int  iOpt,
double  iRCone 
)
protected

Definition at line 63 of file PuppiContainer.cc.

63  {
64  double lPup = 0;
65  lPup = var_within_R(iOpt,iParts,iPart,iRCone);
66  return lPup;
67 }
double var_within_R(int iId, const std::vector< fastjet::PseudoJet > &particles, const fastjet::PseudoJet &centre, double R)
void PuppiContainer::initialize ( const std::vector< RecoObj > &  iRecoObjects)

Definition at line 26 of file PuppiContainer.cc.

References funct::abs(), i, and or.

26  {
27  //Clear everything
28  fRecoParticles.resize(0);
29  fPFParticles .resize(0);
30  fChargedPV .resize(0);
31  fPupParticles .resize(0);
32  fWeights .resize(0);
33  fVals.resize(0);
34  //fChargedNoPV.resize(0);
35  //Link to the RecoObjects
36  fPVFrac = 0.;
37  fNPV = 1.;
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; // zero is neutral hadron
45  if(fRecoParticle.id == 1 and fRecoParticle.charge != 0) puppi_register = fRecoParticle.charge; // from PV use the
46  if(fRecoParticle.id == 2 and fRecoParticle.charge != 0) puppi_register = fRecoParticle.charge+5; // from NPV use the charge as key +5 as key
47  curPseudoJet.set_user_info( new PuppiUserInfo( puppi_register ) );
48  // fill vector of pseudojets for internal references
49  fPFParticles.push_back(curPseudoJet);
50  //Take Charged particles associated to PV
51  if(std::abs(fRecoParticle.id) == 1) fChargedPV.push_back(curPseudoJet);
52  if(std::abs(fRecoParticle.id) >= 1 ) fPVFrac+=1.;
53  //if((fRecoParticle.id == 0) && (inParticles[i].id == 2)) _genParticles.push_back( curPseudoJet);
54  //if(fRecoParticle.id <= 2 && !(inParticles[i].pt < fNeutralMinE && fRecoParticle.id < 2)) _pfchsParticles.push_back(curPseudoJet);
55  //if(fRecoParticle.id == 3) _chargedNoPV.push_back(curPseudoJet);
56  if(fNPV < fRecoParticle.vtxId) fNPV = fRecoParticle.vtxId;
57  }
58  if (fPVFrac != 0) fPVFrac = double(fChargedPV.size())/fPVFrac;
59  else fPVFrac = 0;
60 }
int i
Definition: DBlmapReader.cc:9
std::vector< fastjet::PseudoJet > fPupParticles
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
Definition: Activities.doc:12
std::vector< fastjet::PseudoJet > fChargedPV
std::vector< double > fVals
std::vector< fastjet::PseudoJet > fPFParticles
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< double > fWeights
std::vector< RecoObj > fRecoParticles
std::vector<fastjet::PseudoJet> const& PuppiContainer::pfParticles ( ) const
inline

Definition at line 40 of file PuppiContainer.h.

References fPFParticles.

40 { return fPFParticles; }
std::vector< fastjet::PseudoJet > fPFParticles
std::vector<fastjet::PseudoJet> const& PuppiContainer::puppiParticles ( ) const
inline

Definition at line 43 of file PuppiContainer.h.

References fPupParticles.

43 { return fPupParticles;}
std::vector< fastjet::PseudoJet > fPupParticles
std::vector< double > const & PuppiContainer::puppiWeights ( )

Definition at line 147 of file PuppiContainer.cc.

References funct::abs(), alignCSCRings::e, eta(), edm::isFinite(), LogDebug, bookConverter::max, EnergyCorrector::pt, and reset().

147  {
148  fPupParticles .resize(0);
149  fWeights .resize(0);
150  fVals .resize(0);
151  for(int i0 = 0; i0 < fNAlgos; i0++) fPuppiAlgo[i0].reset();
152 
153  int lNMaxAlgo = 1;
154  for(int i0 = 0; i0 < fNAlgos; i0++) lNMaxAlgo = std::max(fPuppiAlgo[i0].numAlgos(),lNMaxAlgo);
155  //Run through all compute mean and RMS
156  int lNParticles = fRecoParticles.size();
157  for(int i0 = 0; i0 < lNMaxAlgo; i0++) {
159  }
160  std::vector<double> pVals;
161  for(int i0 = 0; i0 < lNParticles; i0++) {
162  //Refresh
163  pVals.clear();
164  double pWeight = 1;
165  //Get the Puppi Id and if ill defined move on
166  int pPupId = getPuppiId(fRecoParticles[i0].pt,fRecoParticles[i0].eta);
167  if(pPupId == -1) {
168  fWeights .push_back(pWeight);
169  continue;
170  }
171  // fill the p-values
172  double pChi2 = 0;
173  if(fUseExp){
174  //Compute an Experimental Puppi Weight with delta Z info (very simple example)
175  pChi2 = getChi2FromdZ(fRecoParticles[i0].dZ);
176  //Now make sure Neutrals are not set
177  if(fRecoParticles[i0].pfType > 3) pChi2 = 0;
178  }
179  //Fill and compute the PuppiWeight
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);
183  //Apply the CHS weights
184  if(fRecoParticles[i0].id == 1 && fApplyCHS ) pWeight = 1;
185  if(fRecoParticles[i0].id == 2 && fApplyCHS ) pWeight = 0;
186  //Basic Weight Checks
187  if( ! edm::isFinite(pWeight)) {
188  pWeight = 0.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;
190  }
191  //Basic Cuts
192  if(pWeight < fPuppiWeightCut) pWeight = 0; //==> Elminate the low Weight stuff
193  if(pWeight*fPFParticles[i0].pt() < fPuppiAlgo[pPupId].neutralPt(fNPV) && fRecoParticles[i0].id == 0 ) pWeight = 0; //threshold cut on the neutral Pt
194  fWeights .push_back(pWeight);
195  //Now get rid of the thrown out weights for the particle collection
196  if(std::abs(pWeight) < std::numeric_limits<double>::denorm_min() ) continue;
197  //Produce
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);
201  }
202  return fWeights;
203 }
#define LogDebug(id)
std::vector< fastjet::PseudoJet > fPupParticles
double getChi2FromdZ(double iDZ)
std::vector< fastjet::PseudoJet > fChargedPV
std::vector< double > fVals
T eta() const
std::vector< fastjet::PseudoJet > fPFParticles
bool isFinite(T x)
void getRMSAvg(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)
Definition: Abs.h:22
double fPuppiWeightCut
int getPuppiId(float iPt, float iEta)
std::vector< double > fWeights
std::vector< RecoObj > fRecoParticles
std::vector< PuppiAlgo > fPuppiAlgo
void reset(double vett[256])
Definition: TPedValues.cc:11
std::vector<fastjet::PseudoJet> const& PuppiContainer::pvParticles ( ) const
inline

Definition at line 41 of file PuppiContainer.h.

References fChargedPV.

41 { return fChargedPV; }
std::vector< fastjet::PseudoJet > fChargedPV
double PuppiContainer::var_within_R ( int  iId,
const std::vector< fastjet::PseudoJet > &  particles,
const fastjet::PseudoJet &  centre,
double  R 
)
protected

Definition at line 68 of file PuppiContainer.cc.

References funct::abs(), i, cmsBatch::log, M_PI, phi, EgammaValidation_Wenu_cff::sel, and MetTreeProducer::var().

68  {
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);
73  double var = 0;
74  //double lSumPt = 0;
75  //if(iId == 1) for(unsigned int i=0; i<near_particles.size(); i++) lSumPt += near_particles[i].pt();
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);
88  }
89  if(iId == 1) var += centre.pt(); //Sum in a cone
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);
93  return var;
94 }
int i
Definition: DBlmapReader.cc:9
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define M_PI
tuple log
Definition: cmsBatch.py:347
Definition: DDAxes.h:10

Member Data Documentation

bool PuppiContainer::fApplyCHS
protected

Definition at line 58 of file PuppiContainer.h.

std::vector<fastjet::PseudoJet> PuppiContainer::fChargedPV
protected

Definition at line 54 of file PuppiContainer.h.

Referenced by pvParticles().

int PuppiContainer::fNAlgos
protected

Definition at line 63 of file PuppiContainer.h.

double PuppiContainer::fNeutralMinPt
protected

Definition at line 60 of file PuppiContainer.h.

double PuppiContainer::fNeutralSlope
protected

Definition at line 61 of file PuppiContainer.h.

int PuppiContainer::fNPV
protected

Definition at line 64 of file PuppiContainer.h.

std::vector<fastjet::PseudoJet> PuppiContainer::fPFParticles
protected

Definition at line 53 of file PuppiContainer.h.

Referenced by pfParticles().

std::vector<fastjet::PseudoJet> PuppiContainer::fPupParticles
protected

Definition at line 55 of file PuppiContainer.h.

Referenced by puppiParticles().

std::vector<PuppiAlgo> PuppiContainer::fPuppiAlgo
protected

Definition at line 66 of file PuppiContainer.h.

double PuppiContainer::fPuppiWeightCut
protected

Definition at line 62 of file PuppiContainer.h.

double PuppiContainer::fPVFrac
protected

Definition at line 65 of file PuppiContainer.h.

std::vector<RecoObj> PuppiContainer::fRecoParticles
protected

Definition at line 52 of file PuppiContainer.h.

bool PuppiContainer::fUseExp
protected

Definition at line 59 of file PuppiContainer.h.

std::vector<double> PuppiContainer::fVals
protected

Definition at line 57 of file PuppiContainer.h.

std::vector<double> PuppiContainer::fWeights
protected

Definition at line 56 of file PuppiContainer.h.