CMS 3D CMS Logo

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

#include <PuppiAlgo.h>

Public Member Functions

void add (const fastjet::PseudoJet &iParticle, const double &iVal, const unsigned int iAlgo)
 
int algoId (unsigned int iAlgo) const
 
double compute (std::vector< double > const &iVals, double iChi2) const
 
void computeMedRMS (const unsigned int &iAlgo, const double &iPVFrac)
 
double coneSize (unsigned int iAlgo) const
 
double etaMax () const
 
double etaMin () const
 
bool isCharged (unsigned int iAlgo) const
 
double neutralPt (int iNPV) const
 
int numAlgos () const
 
double ptMin () const
 
 PuppiAlgo (edm::ParameterSet &iConfig)
 
void reset ()
 
 ~PuppiAlgo ()
 

Private Attributes

std::vector< bool > fAdjust
 
std::vector< int > fAlgoId
 
std::vector< bool > fCharged
 
std::vector< int > fCombId
 
std::vector< double > fConeSize
 
float fEtaMax
 
float fEtaMin
 
std::vector< double > fMean
 
std::vector< double > fMedian
 
unsigned int fNAlgos
 
std::vector< int > fNCount
 
double fNeutralPtMin
 
double fNeutralPtSlope
 
float fPtMin
 
std::vector< float > fPups
 
std::vector< float > fPupsPV
 
std::vector< double > fRMS
 
std::vector< double > fRMSPtMin
 
std::vector< double > fRMSScaleFactor
 

Detailed Description

Definition at line 9 of file PuppiAlgo.h.

Constructor & Destructor Documentation

PuppiAlgo::PuppiAlgo ( edm::ParameterSet iConfig)

Definition at line 11 of file PuppiAlgo.cc.

References fAdjust, fAlgoId, fCharged, fCombId, fConeSize, fEtaMax, fEtaMin, fMean, fMedian, fNAlgos, fNCount, fNeutralPtMin, fNeutralPtSlope, fPtMin, fRMS, fRMSPtMin, fRMSScaleFactor, and edm::ParameterSet::getParameter().

11  {
12  fEtaMin = iConfig.getParameter<double>("etaMin");
13  fEtaMax = iConfig.getParameter<double>("etaMax");
14  fPtMin = iConfig.getParameter<double>("ptMin");
15  fNeutralPtMin = iConfig.getParameter<double>("MinNeutralPt"); // Weighted Neutral Pt Cut
16  fNeutralPtSlope = iConfig.getParameter<double>("MinNeutralPtSlope"); // Slope vs #pv
17 
18  std::vector<edm::ParameterSet> lAlgos = iConfig.getParameter<std::vector<edm::ParameterSet> >("puppiAlgos");
19  fNAlgos = lAlgos.size();
20  //Uber Configurable Puppi
21  for(unsigned int i0 = 0; i0 < lAlgos.size(); i0++) {
22  int pAlgoId = lAlgos[i0].getParameter<int > ("algoId");
23  bool pCharged = lAlgos[i0].getParameter<bool> ("useCharged");
24  bool pWeight0 = lAlgos[i0].getParameter<bool> ("applyLowPUCorr");
25  int pComb = lAlgos[i0].getParameter<int> ("combOpt"); // 0=> add in chi2/1=>Multiply p-values
26  double pConeSize = lAlgos[i0].getParameter<double>("cone"); // Min Pt when computing pt and rms
27  double pRMSPtMin = lAlgos[i0].getParameter<double>("rmsPtMin"); // Min Pt when computing pt and rms
28  double pRMSSF = lAlgos[i0].getParameter<double>("rmsScaleFactor"); // Additional Tuning parameter for Jokers
29  fAlgoId .push_back(pAlgoId);
30  fCharged .push_back(pCharged);
31  fAdjust .push_back(pWeight0);
32  fCombId .push_back(pComb);
33  fConeSize .push_back(pConeSize);
34  fRMSPtMin .push_back(pRMSPtMin);
35  fRMSScaleFactor.push_back(pRMSSF);
36  double pRMS = 0;
37  double pMed = 0;
38  double pMean = 0;
39  int pNCount = 0;
40  fRMS .push_back(pRMS);
41  fMedian.push_back(pMed);
42  fMean .push_back(pMean);
43  fNCount.push_back(pNCount);
44  }
45 }
T getParameter(std::string const &) const
double fNeutralPtMin
Definition: PuppiAlgo.h:34
float fPtMin
Definition: PuppiAlgo.h:33
std::vector< bool > fAdjust
Definition: PuppiAlgo.h:40
float fEtaMin
Definition: PuppiAlgo.h:32
std::vector< double > fConeSize
Definition: PuppiAlgo.h:42
std::vector< double > fRMS
Definition: PuppiAlgo.h:45
std::vector< double > fMean
Definition: PuppiAlgo.h:47
std::vector< int > fAlgoId
Definition: PuppiAlgo.h:38
std::vector< double > fRMSPtMin
Definition: PuppiAlgo.h:43
std::vector< int > fCombId
Definition: PuppiAlgo.h:41
std::vector< double > fRMSScaleFactor
Definition: PuppiAlgo.h:44
double fNeutralPtSlope
Definition: PuppiAlgo.h:35
std::vector< bool > fCharged
Definition: PuppiAlgo.h:39
unsigned int fNAlgos
Definition: PuppiAlgo.h:30
float fEtaMax
Definition: PuppiAlgo.h:31
std::vector< int > fNCount
Definition: PuppiAlgo.h:48
std::vector< double > fMedian
Definition: PuppiAlgo.h:46
PuppiAlgo::~PuppiAlgo ( )

Definition at line 46 of file PuppiAlgo.cc.

References fPups, and fPupsPV.

46  {
47  fPups .clear();
48  fPupsPV.clear();
49 }
std::vector< float > fPupsPV
Definition: PuppiAlgo.h:37
std::vector< float > fPups
Definition: PuppiAlgo.h:36

Member Function Documentation

void PuppiAlgo::add ( const fastjet::PseudoJet &  iParticle,
const double &  iVal,
const unsigned int  iAlgo 
)

Definition at line 60 of file PuppiAlgo.cc.

References funct::abs(), edm::hlt::Exception, fCharged, fNCount, fPups, fPupsPV, fRMSPtMin, and PuppiContainer::PuppiUserInfo::puppi_register().

Referenced by counter.Counter::register().

60  {
61  if(iParticle.pt() < fRMSPtMin[iAlgo]) return;
62  // Change from SRR : Previously used fastjet::PseudoJet::user_index to decide the particle type.
63  // In CMSSW we use the user_index to specify the index in the input collection, so I invented
64  // a new mechanism using the fastjet UserInfo functionality. Of course, it's still just an integer
65  // but that interface could be changed (or augmented) if desired / needed.
66  int puppi_register = std::numeric_limits<int>::lowest();
67  if ( iParticle.has_user_info() ) {
68  PuppiContainer::PuppiUserInfo const * pInfo = dynamic_cast<PuppiContainer::PuppiUserInfo const *>( iParticle.user_info_ptr() );
69  if ( pInfo != 0 ) {
70  puppi_register = pInfo->puppi_register();
71  }
72  }
73  if ( puppi_register == std::numeric_limits<int>::lowest() ) {
74  throw cms::Exception("PuppiRegisterNotSet") << "The puppi register is not set. This must be set before use.\n";
75  }
76  if(fCharged[iAlgo] && std::abs(puppi_register) < 1) return;
77  if(fCharged[iAlgo] && (std::abs(puppi_register) >=1 && std::abs(puppi_register) <=2)) fPupsPV.push_back(iVal);
78  if(fCharged[iAlgo] && std::abs(puppi_register) < 3) return;
79  fPups.push_back(iVal);
80  fNCount[iAlgo]++;
81 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< float > fPupsPV
Definition: PuppiAlgo.h:37
std::vector< float > fPups
Definition: PuppiAlgo.h:36
std::vector< double > fRMSPtMin
Definition: PuppiAlgo.h:43
std::vector< bool > fCharged
Definition: PuppiAlgo.h:39
std::vector< int > fNCount
Definition: PuppiAlgo.h:48
int PuppiAlgo::algoId ( unsigned int  iAlgo) const
inline

Definition at line 24 of file PuppiAlgo.h.

References fAlgoId.

24 { return fAlgoId.at(iAlgo); }
std::vector< int > fAlgoId
Definition: PuppiAlgo.h:38
double PuppiAlgo::compute ( std::vector< double > const &  iVals,
double  iChi2 
) const

Definition at line 124 of file PuppiAlgo.cc.

References fAlgoId, fCombId, fMedian, fNAlgos, fNCount, and fRMS.

124  {
125  if(fAlgoId[0] == -1) return 1;
126  double lVal = 0.;
127  double lPVal = 1.;
128  int lNDOF = 0;
129  for(unsigned int i0 = 0; i0 < fNAlgos; i0++) {
130  if(fNCount[i0] == 0) return 1.; //in the NoPU case return 1.
131  if(fCombId[i0] == 1 && i0 > 0) { //Compute the previous p-value so that p-values can be multiplieed
132  double pPVal = ROOT::Math::chisquared_cdf(lVal,lNDOF);
133  lPVal *= pPVal;
134  lNDOF = 0;
135  lVal = 0;
136  }
137  double pVal = iVals[i0];
138  //Special Check for any algo with log(0)
139  if(fAlgoId[i0] == 0 && iVals[i0] == 0) pVal = fMedian[i0];
140  if(fAlgoId[i0] == 3 && iVals[i0] == 0) pVal = fMedian[i0];
141  if(fAlgoId[i0] == 5 && iVals[i0] == 0) pVal = fMedian[i0];
142  lVal += (pVal-fMedian[i0])*(fabs(pVal-fMedian[i0]))/fRMS[i0]/fRMS[i0];
143  lNDOF++;
144  if(i0 == 0 && iChi2 != 0) lNDOF++; //Add external Chi2 to first element
145  if(i0 == 0 && iChi2 != 0) lVal+=iChi2; //Add external Chi2 to first element
146  }
147  //Top it off with the last calc
148  lPVal *= ROOT::Math::chisquared_cdf(lVal,lNDOF);
149  return lPVal;
150 }
std::vector< double > fRMS
Definition: PuppiAlgo.h:45
std::vector< int > fAlgoId
Definition: PuppiAlgo.h:38
std::vector< int > fCombId
Definition: PuppiAlgo.h:41
unsigned int fNAlgos
Definition: PuppiAlgo.h:30
std::vector< int > fNCount
Definition: PuppiAlgo.h:48
std::vector< double > fMedian
Definition: PuppiAlgo.h:46
void PuppiAlgo::computeMedRMS ( const unsigned int &  iAlgo,
const double &  iPVFrac 
)

Definition at line 82 of file PuppiAlgo.cc.

References alignCSCRings::e, fAdjust, fCharged, fMean, fMedian, fNAlgos, fNCount, fPups, fPupsPV, fRMS, fRMSScaleFactor, python.multivaluedict::sort(), and mathSSE::sqrt().

82  {
83  if(iAlgo >= fNAlgos ) return;
84  if(fNCount[iAlgo] == 0) return;
85  int lNBefore = 0;
86  for(unsigned int i0 = 0; i0 < iAlgo; i0++) lNBefore += fNCount[i0];
87  std::sort(fPups.begin()+lNBefore,fPups.begin()+lNBefore+fNCount[iAlgo]);
88  double lCorr = 1.;
89  //if(!fCharged[iAlgo] && fAdjust[iAlgo]) lCorr *= 1. - iPVFrac;
90  if(fAdjust[iAlgo]) lCorr *= 1. - iPVFrac;
91  int lNum0 = 0;
92  for(int i0 = lNBefore; i0 < lNBefore+fNCount[iAlgo]; i0++) {
93  if(fPups[i0] == 0) lNum0 = i0-lNBefore;
94  }
95  //lNum0 = 0;
96  int lNHalfway = lNBefore + lNum0 + int( double( fNCount[iAlgo]-lNum0 )*0.50*lCorr);
97  fMedian[iAlgo] = fPups[lNHalfway];
98  double lMed = fMedian[iAlgo]; //Just to make the readability easier
99 
100  int lNRMS = 0;
101  for(int i0 = lNBefore; i0 < lNBefore+fNCount[iAlgo]; i0++) {
102  fMean[iAlgo] += fPups[i0];
103  if(fPups[i0] == 0) continue;
104  if(!fCharged[iAlgo] && fAdjust[iAlgo] && fPups[i0] > lMed) continue;
105  //if(fAdjust[iAlgo] && fPups[i0] > lMed) continue;
106  lNRMS++;
107  fRMS [iAlgo] += (fPups[i0]-lMed)*(fPups[i0]-lMed);
108  }
109  fMean[iAlgo]/=fNCount[iAlgo];
110  if(lNRMS > 0) fRMS [iAlgo]/=lNRMS;
111  if(fRMS[iAlgo] == 0) fRMS[iAlgo] = 1e-5;
112 
113  fRMS [iAlgo] = sqrt(fRMS[iAlgo]);
114  fRMS [iAlgo] *= fRMSScaleFactor[iAlgo];
115  //if(!fCharged[iAlgo]) std::cout << " Process : " << iAlgo << " Median : " << fMedian[iAlgo] << " +/- " << fRMS[iAlgo] << " -- Begin : " << lNBefore << " -- Total : " << fNCount[iAlgo] << " -- 50% " << lNHalfway << " Fraction less than @ Median : " << std::endl;
116  if(!fAdjust[iAlgo]) return;
117  //Adjust the p-value to correspond to the median
118  std::sort(fPupsPV.begin(),fPupsPV.end());
119  int lNPV = 0; for(unsigned int i0 = 0; i0 < fPupsPV.size(); i0++) if(fPupsPV[i0] <= lMed ) lNPV++;
120  double lAdjust = 1.5*double(lNPV)/double(fPupsPV.size()+fNCount[iAlgo]);
121  if(lAdjust > 0) fMedian[iAlgo] -= sqrt(ROOT::Math::chisquared_quantile(lAdjust,1.)*fRMS[iAlgo]);
122 }
std::vector< bool > fAdjust
Definition: PuppiAlgo.h:40
T sqrt(T t)
Definition: SSEVec.h:48
std::vector< double > fRMS
Definition: PuppiAlgo.h:45
std::vector< float > fPupsPV
Definition: PuppiAlgo.h:37
std::vector< float > fPups
Definition: PuppiAlgo.h:36
std::vector< double > fMean
Definition: PuppiAlgo.h:47
std::vector< double > fRMSScaleFactor
Definition: PuppiAlgo.h:44
std::vector< bool > fCharged
Definition: PuppiAlgo.h:39
unsigned int fNAlgos
Definition: PuppiAlgo.h:30
std::vector< int > fNCount
Definition: PuppiAlgo.h:48
std::vector< double > fMedian
Definition: PuppiAlgo.h:46
double PuppiAlgo::coneSize ( unsigned int  iAlgo) const
inline

Definition at line 26 of file PuppiAlgo.h.

References fConeSize.

26 { return fConeSize.at(iAlgo); }
std::vector< double > fConeSize
Definition: PuppiAlgo.h:42
double PuppiAlgo::etaMax ( ) const
inline

Definition at line 22 of file PuppiAlgo.h.

References fEtaMax.

22 { return fEtaMax; }
float fEtaMax
Definition: PuppiAlgo.h:31
double PuppiAlgo::etaMin ( ) const
inline

Definition at line 21 of file PuppiAlgo.h.

References fEtaMin.

21 { return fEtaMin; }
float fEtaMin
Definition: PuppiAlgo.h:32
bool PuppiAlgo::isCharged ( unsigned int  iAlgo) const
inline

Definition at line 25 of file PuppiAlgo.h.

References fCharged.

25 { return fCharged.at(iAlgo); }
std::vector< bool > fCharged
Definition: PuppiAlgo.h:39
double PuppiAlgo::neutralPt ( int  iNPV) const
inline

Definition at line 27 of file PuppiAlgo.h.

References fNeutralPtMin, and fNeutralPtSlope.

27 { return fNeutralPtMin + iNPV * fNeutralPtSlope; }
double fNeutralPtMin
Definition: PuppiAlgo.h:34
double fNeutralPtSlope
Definition: PuppiAlgo.h:35
int PuppiAlgo::numAlgos ( ) const
inline

Definition at line 23 of file PuppiAlgo.h.

References fNAlgos.

23 { return fNAlgos;}
unsigned int fNAlgos
Definition: PuppiAlgo.h:30
double PuppiAlgo::ptMin ( ) const
inline

Definition at line 20 of file PuppiAlgo.h.

References fPtMin.

20 { return fPtMin; }
float fPtMin
Definition: PuppiAlgo.h:33
void PuppiAlgo::reset ( void  )

Definition at line 50 of file PuppiAlgo.cc.

References fMean, fMedian, fNAlgos, fNCount, fPups, fPupsPV, and fRMS.

Referenced by MatrixReader.MatrixReader::__init__(), and MatrixReader.MatrixReader::showRaw().

50  {
51  fPups .clear();
52  fPupsPV.clear();
53  for(unsigned int i0 = 0; i0 < fNAlgos; i0++) {
54  fMedian[i0] = 0;
55  fRMS [i0] = 0;
56  fMean [i0] = 0;
57  fNCount[i0] = 0;
58  }
59 }
std::vector< double > fRMS
Definition: PuppiAlgo.h:45
std::vector< float > fPupsPV
Definition: PuppiAlgo.h:37
std::vector< float > fPups
Definition: PuppiAlgo.h:36
std::vector< double > fMean
Definition: PuppiAlgo.h:47
unsigned int fNAlgos
Definition: PuppiAlgo.h:30
std::vector< int > fNCount
Definition: PuppiAlgo.h:48
std::vector< double > fMedian
Definition: PuppiAlgo.h:46

Member Data Documentation

std::vector<bool> PuppiAlgo::fAdjust
private

Definition at line 40 of file PuppiAlgo.h.

Referenced by computeMedRMS(), and PuppiAlgo().

std::vector<int> PuppiAlgo::fAlgoId
private

Definition at line 38 of file PuppiAlgo.h.

Referenced by algoId(), compute(), and PuppiAlgo().

std::vector<bool> PuppiAlgo::fCharged
private

Definition at line 39 of file PuppiAlgo.h.

Referenced by add(), computeMedRMS(), isCharged(), and PuppiAlgo().

std::vector<int> PuppiAlgo::fCombId
private

Definition at line 41 of file PuppiAlgo.h.

Referenced by compute(), and PuppiAlgo().

std::vector<double> PuppiAlgo::fConeSize
private

Definition at line 42 of file PuppiAlgo.h.

Referenced by coneSize(), and PuppiAlgo().

float PuppiAlgo::fEtaMax
private

Definition at line 31 of file PuppiAlgo.h.

Referenced by etaMax(), and PuppiAlgo().

float PuppiAlgo::fEtaMin
private

Definition at line 32 of file PuppiAlgo.h.

Referenced by etaMin(), and PuppiAlgo().

std::vector<double> PuppiAlgo::fMean
private

Definition at line 47 of file PuppiAlgo.h.

Referenced by computeMedRMS(), PuppiAlgo(), and reset().

std::vector<double> PuppiAlgo::fMedian
private

Definition at line 46 of file PuppiAlgo.h.

Referenced by compute(), computeMedRMS(), PuppiAlgo(), and reset().

unsigned int PuppiAlgo::fNAlgos
private

Definition at line 30 of file PuppiAlgo.h.

Referenced by compute(), computeMedRMS(), numAlgos(), PuppiAlgo(), and reset().

std::vector<int> PuppiAlgo::fNCount
private

Definition at line 48 of file PuppiAlgo.h.

Referenced by add(), compute(), computeMedRMS(), PuppiAlgo(), and reset().

double PuppiAlgo::fNeutralPtMin
private

Definition at line 34 of file PuppiAlgo.h.

Referenced by neutralPt(), and PuppiAlgo().

double PuppiAlgo::fNeutralPtSlope
private

Definition at line 35 of file PuppiAlgo.h.

Referenced by neutralPt(), and PuppiAlgo().

float PuppiAlgo::fPtMin
private

Definition at line 33 of file PuppiAlgo.h.

Referenced by ptMin(), and PuppiAlgo().

std::vector<float> PuppiAlgo::fPups
private

Definition at line 36 of file PuppiAlgo.h.

Referenced by add(), computeMedRMS(), reset(), and ~PuppiAlgo().

std::vector<float> PuppiAlgo::fPupsPV
private

Definition at line 37 of file PuppiAlgo.h.

Referenced by add(), computeMedRMS(), reset(), and ~PuppiAlgo().

std::vector<double> PuppiAlgo::fRMS
private

Definition at line 45 of file PuppiAlgo.h.

Referenced by compute(), computeMedRMS(), PuppiAlgo(), and reset().

std::vector<double> PuppiAlgo::fRMSPtMin
private

Definition at line 43 of file PuppiAlgo.h.

Referenced by add(), and PuppiAlgo().

std::vector<double> PuppiAlgo::fRMSScaleFactor
private

Definition at line 44 of file PuppiAlgo.h.

Referenced by computeMedRMS(), and PuppiAlgo().