ATLAS Offline Software
Puppi.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 #include "Math/ProbFunc.h"
5 #include "TMath.h"
6 #include "fastjet/Selector.hh"
7 
8 #include "JetRecTools/Puppi.h"
9 
10 using namespace std;
11 
12 //PuppiUserInfo can be used to include additional information in algorithm
13 PuppiUserInfo::PuppiUserInfo(): otherChi2Vec(std::vector<double>()) {}
14 PuppiUserInfo::PuppiUserInfo(const std::vector<double>& v): otherChi2Vec(v) {}
15 PuppiUserInfo::PuppiUserInfo(double v): otherChi2Vec(std::vector<double>({v})) {}
16 
17 //=================================================================================================================================
18 
19 Puppi::Puppi(double R0, double Rmin, double beta, double centralPTCutOffset, double centralPTCutSlope, double forwardPTCutOffset, double forwardPTCutSlope, double etaBoundary):
20  m_R0(R0), m_Rmin(Rmin), m_beta(beta), m_centralPTCutOffset(centralPTCutOffset), m_centralPTCutSlope(centralPTCutSlope), m_forwardPTCutOffset(forwardPTCutOffset), m_forwardPTCutSlope(forwardPTCutSlope), m_etaBoundary(etaBoundary)
21 {}
22 
23 //---------------------------------------------------------------------------------------------------------------------------------
24 
25 //Sets the particles used for calculations, and calculates the median and RMS for the PU distribution
26 void Puppi::setParticles(const std::vector<fastjet::PseudoJet>& chargedHS, const std::vector<fastjet::PseudoJet>& chargedPU, const std::vector<fastjet::PseudoJet>& neutral, const std::vector<fastjet::PseudoJet>& forward, int nPV){
27 
28  m_chargedHS=chargedHS;
29  m_chargedPU=chargedPU;
31  m_forward=forward;
32 
33  m_nPV=nPV;
34 
36 
38 }
39 
40 //---------------------------------------------------------------------------------------------------------------------------------
41 
42 double Puppi::getChi2(const fastjet::PseudoJet& pfo){
43  double chi=(getAlpha(pfo)-m_median)/m_rms;
44  return chi*fabs(chi);
45 }
46 
47 //---------------------------------------------------------------------------------------------------------------------------------
48 
49 double Puppi::getWeight(const fastjet::PseudoJet& pfo){
50 
51  double chi2Total=getChi2(pfo);
52  int nDF=1;
53 
54  if(pfo.has_user_info<PuppiUserInfo>()){
55  //This is untested!!!!
56  //Need to think about how to handle sign of chi2 - for now just throw it away
57  chi2Total=fabs(chi2Total);
58  for(auto v: pfo.user_info<PuppiUserInfo>().otherChi2Vec) {
59  chi2Total+=v;
60  nDF+=1;
61  }
62  }
63 
64  double w = ROOT::Math::chisquared_cdf(chi2Total, nDF);
65 
66  double offset,slope;
67  if( fabs(pfo.eta()) < m_etaBoundary) {
69  slope=m_centralPTCutSlope;
70  }
71  else {
73  slope=m_forwardPTCutSlope;
74  }
75 
76  w*=(pfo.pt()>offset+m_nPV*slope);
77 
78  return w;
79 }
80 
81 //---------------------------------------------------------------------------------------------------------------------------------
82 
83 double Puppi::getAlpha(const fastjet::PseudoJet& pfo){
84  fastjet::Selector sel = fastjet::SelectorCircle(m_R0);
85  sel.set_reference(pfo);
86 
87  double sum=0;
88  int nNeighbors=0;
89 
90  if (fabs(pfo.eta())<m_etaBoundary+m_R0){
91  vector<fastjet::PseudoJet> chargedHSNeighbors = sel(m_chargedHS);
92  for (const auto& p: chargedHSNeighbors){
93  float dR=pfo.delta_R(p);
94  if (dR>m_Rmin){
95  sum+=p.pt()/pow(dR, m_beta);
96  nNeighbors+=1;
97  }
98  }
99  }
100 
102  if (fabs(pfo.eta())<m_etaBoundary+m_R0){
103  vector<fastjet::PseudoJet> neutralNeighbors = sel(m_neutral);
104  for (const auto& p: neutralNeighbors){
105  float dR=pfo.delta_R(p);
106  if (dR>m_Rmin){
107  sum+=pow(p.pt()/dR, m_beta);
108  nNeighbors+=1;
109  }
110  }
111  }
112  }
113 
114  if (fabs(pfo.eta())>m_etaBoundary-m_R0){
115  vector<fastjet::PseudoJet> forwardNeighbors = sel(m_forward);
116  for (const auto& p: forwardNeighbors){
117  float dR=pfo.delta_R(p);
118  if (dR>m_Rmin){
119  sum+=pow(p.pt()/dR, m_beta);
120  nNeighbors+=1;
121  }
122  }
123  }
124 
125  if (sum<=FLT_MIN) return -99999;
126  if (nNeighbors!=0) return log(sum);
127  return -9999;
128 }
129 
130 //---------------------------------------------------------------------------------------------------------------------------------
131 
132 //Finds the median and LHS RMS for the charged PU distribution (done each event)
134  vector<double> values;
135 
136  for(const auto& p: m_chargedPU){
137 
138  // Don't want to include particles on the boundary
139  if( fabs(p.eta()) > m_etaBoundary-m_R0) continue;
140 
141  double value = getAlpha(p);
142  if(value > -999) values.push_back(value); //-9999 is the value assigned to pfo with zero neighbors
143  }
144 
145  std::sort(values.begin(),values.end());
146 
147  if(!values.empty()) m_median=values[int(values.size()*0.5)];
148  else m_median=-9999;
149 
150  // now compute the LHS RMS
151  double sum=0;
152  int n = 0;
153  for(auto value: values){
154  if (value - m_median > 0) continue;
155  sum += (value - m_median)*(value - m_median);
156  ++n;
157  }
158 
159  if(n > 0) m_rms = TMath::Sqrt(sum/n);
160  else m_rms=-9999;
161 }
162 
164  return m_median;
165 }
166 double Puppi::getRMS(){
167  return m_rms;
168 }
Puppi::m_includeCentralNeutralsInAlpha
bool m_includeCentralNeutralsInAlpha
Definition: Puppi.h:59
Puppi::getMedian
double getMedian()
Definition: Puppi.cxx:163
Puppi::m_forwardPTCutOffset
double m_forwardPTCutOffset
Definition: Puppi.h:56
Puppi::m_Rmin
double m_Rmin
Definition: Puppi.h:52
Puppi::m_beta
double m_beta
Definition: Puppi.h:53
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
PuppiUserInfo::PuppiUserInfo
PuppiUserInfo()
Definition: Puppi.cxx:13
Puppi::setParticles
void setParticles(const std::vector< fastjet::PseudoJet > &chargedHS, const std::vector< fastjet::PseudoJet > &chargedPU, const std::vector< fastjet::PseudoJet > &neutral, const std::vector< fastjet::PseudoJet > &forward, int nPU)
Definition: Puppi.cxx:26
Puppi::m_nPV
double m_nPV
Definition: Puppi.h:64
athena.value
value
Definition: athena.py:124
Puppi::m_forwardPTCutSlope
double m_forwardPTCutSlope
Definition: Puppi.h:57
Puppi::m_neutral
std::vector< fastjet::PseudoJet > m_neutral
Definition: Puppi.h:46
Puppi::getChi2
double getChi2(const fastjet::PseudoJet &pfo)
Definition: Puppi.cxx:42
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:805
Puppi::m_centralPTCutSlope
double m_centralPTCutSlope
Definition: Puppi.h:55
Puppi.h
Puppi::m_R0
double m_R0
Definition: Puppi.h:51
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
beamspotman.n
n
Definition: beamspotman.py:731
Puppi::getAlpha
double getAlpha(const fastjet::PseudoJet &pfo)
Definition: Puppi.cxx:83
Puppi::m_rms
double m_rms
Definition: Puppi.h:62
sel
sel
Definition: SUSYToolsTester.cxx:97
Puppi::m_etaBoundary
double m_etaBoundary
Definition: Puppi.h:58
Puppi::m_allParticles
std::vector< std::vector< fastjet::PseudoJet > * > m_allParticles
Definition: Puppi.h:49
PuppiUserInfo::otherChi2Vec
std::vector< double > otherChi2Vec
Definition: Puppi.h:17
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
Puppi::m_forward
std::vector< fastjet::PseudoJet > m_forward
Definition: Puppi.h:47
PuppiUserInfo
Definition: Puppi.h:11
CP::neutral
@ neutral
Definition: Reconstruction/PFlow/PFlowUtils/PFlowUtils/PFODefs.h:11
Puppi::getRMS
double getRMS()
Definition: Puppi.cxx:166
python.PyAthena.v
v
Definition: PyAthena.py:154
Puppi::m_chargedPU
std::vector< fastjet::PseudoJet > m_chargedPU
Definition: Puppi.h:45
std::sort
void sort(typename std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, typename std::reverse_iterator< DataModel_detail::iterator< DVL > > end, const Compare &comp)
Specialization of sort for DataVector/List.
Definition: DVL_algorithms.h:623
Puppi::getWeight
double getWeight(const fastjet::PseudoJet &pfo)
Definition: Puppi.cxx:49
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
Puppi::m_chargedHS
std::vector< fastjet::PseudoJet > m_chargedHS
Definition: Puppi.h:44
Rmin
double Rmin
Definition: LArDetectorConstructionTBEC.cxx:56
Puppi::findAlphaMedianAndRMS
void findAlphaMedianAndRMS()
Definition: Puppi.cxx:133
Puppi::m_centralPTCutOffset
double m_centralPTCutOffset
Definition: Puppi.h:54
Puppi::Puppi
Puppi(double R0, double Rmin, double beta, double centralPTCutOffset, double centralPTCutSlope, double forwardPTCutOffset, double forwardPTCutSlope, double etaBoundary)
Definition: Puppi.cxx:19
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
MuonParameters::beta
@ beta
Definition: MuonParamDefs.h:144
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
Puppi::m_median
double m_median
Definition: Puppi.h:61