CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
HGCalShowerShapeHelper::ShowerShapeCalc Class Reference

#include <HGCalShowerShapeHelper.h>

Public Member Functions

double getCellSize (DetId detId) const
 
std::vector< double > getEnergyHighestHits (unsigned int nrHits, bool useFractions=true) const
 
ShowerWidths getPCAWidths (double cylinderR, bool useFractions=false) const
 
double getRvar (double cylinderR, bool useFractions=true, bool useCellSize=true) const
 
 ShowerShapeCalc (std::shared_ptr< const hgcal::RecHitTools > recHitTools, std::shared_ptr< const std::unordered_map< uint32_t, const reco::PFRecHit * > > pfRecHitPtrMap, const std::vector< std::pair< DetId, float > > &hitsAndFracs, const double rawEnergy, const double minHitE=0, const double minHitET=0, const int minLayer=1, const int maxLayer=-1, DetId::Detector subDet=DetId::HGCalEE)
 

Private Member Functions

void setFilteredHitsAndFractions (const std::vector< std::pair< DetId, float > > &hitsAndFracs)
 
void setLayerWiseInfo ()
 

Private Attributes

ROOT::Math::XYZVector centroid_
 
std::vector< double > hitEnergies_
 
std::vector< double > hitEnergiesWithFracs_
 
std::vector< std::pair< DetId, float > > hitsAndFracs_
 
std::vector< ROOT::Math::XYZVectorlayerCentroids_
 
std::vector< double > layerEnergies_
 
int maxLayer_
 
double minHitE_
 
double minHitET2_
 
double minHitET_
 
int minLayer_
 
int nLayer_
 
std::shared_ptr< const std::unordered_map< uint32_t, const reco::PFRecHit * > > pfRecHitPtrMap_
 
double rawEnergy_
 
std::shared_ptr< const hgcal::RecHitToolsrecHitTools_
 
DetId::Detector subDet_
 

Detailed Description

Definition at line 88 of file HGCalShowerShapeHelper.h.

Constructor & Destructor Documentation

◆ ShowerShapeCalc()

HGCalShowerShapeHelper::ShowerShapeCalc::ShowerShapeCalc ( std::shared_ptr< const hgcal::RecHitTools recHitTools,
std::shared_ptr< const std::unordered_map< uint32_t, const reco::PFRecHit * > >  pfRecHitPtrMap,
const std::vector< std::pair< DetId, float > > &  hitsAndFracs,
const double  rawEnergy,
const double  minHitE = 0,
const double  minHitET = 0,
const int  minLayer = 1,
const int  maxLayer = -1,
DetId::Detector  subDet = DetId::HGCalEE 
)

Definition at line 6 of file HGCalShowerShapeHelper.cc.

16  : recHitTools_(recHitTools),
17  pfRecHitPtrMap_(pfRecHitPtrMap),
18  rawEnergy_(rawEnergy),
19  minHitE_(minHitE),
20  minHitET_(minHitET),
21  minHitET2_(minHitET * minHitET),
23  maxLayer_(maxLayer <= 0 ? recHitTools_->lastLayerEE() : maxLayer),
25  subDet_(subDet) {
26  assert(nLayer_ > 0);
27  setFilteredHitsAndFractions(hitsAndFracs);
29 }

References cms::cuda::assert(), nLayer_, setFilteredHitsAndFractions(), and setLayerWiseInfo().

Member Function Documentation

◆ getCellSize()

double HGCalShowerShapeHelper::ShowerShapeCalc::getCellSize ( DetId  detId) const

◆ getEnergyHighestHits()

std::vector< double > HGCalShowerShapeHelper::ShowerShapeCalc::getEnergyHighestHits ( unsigned int  nrHits,
bool  useFractions = true 
) const

Definition at line 192 of file HGCalShowerShapeHelper.cc.

193  {
194  std::vector<double> sortedEnergies(nrHits, 0.);
195  const auto &hits = useFractions ? hitEnergiesWithFracs_ : hitEnergies_;
196  std::partial_sort_copy(
197  hits.begin(), hits.end(), sortedEnergies.begin(), sortedEnergies.end(), std::greater<double>());
198  return sortedEnergies;
199 }

References hfClusterShapes_cfi::hits.

◆ getPCAWidths()

HGCalShowerShapeHelper::ShowerWidths HGCalShowerShapeHelper::ShowerShapeCalc::getPCAWidths ( double  cylinderR,
bool  useFractions = false 
) const

Definition at line 86 of file HGCalShowerShapeHelper.cc.

87  {
88  if (hitsAndFracs_.empty()) {
89  return ShowerWidths();
90  }
91 
92  double cylinderR2 = cylinderR * cylinderR;
93 
94  TMatrixD covMat(3, 3);
95 
96  double dxdx = 0.0;
97  double dydy = 0.0;
98  double dzdz = 0.0;
99 
100  double dxdy = 0.0;
101  double dydz = 0.0;
102  double dzdx = 0.0;
103 
104  double totalW = 0.0;
105 
106  auto hitEnergyIter = useFractions ? hitEnergiesWithFracs_.begin() : hitEnergies_.begin();
107 
108  int nHit = 0;
109  hitEnergyIter--;
110 
111  for (const auto &hnf : hitsAndFracs_) {
112  hitEnergyIter++;
113 
114  DetId hitId = hnf.first;
115 
116  const auto &hitPos = recHitTools_->getPosition(hitId);
117  ROOT::Math::XYZVector hitXYZ(hitPos.x(), hitPos.y(), hitPos.z());
118 
119  int hitLayer = recHitTools_->getLayer(hitId) - 1;
120 
121  ROOT::Math::XYZVector radXYZ = hitXYZ - layerCentroids_[hitLayer];
122 
123  double r2 = radXYZ.x() * radXYZ.x() + radXYZ.y() * radXYZ.y();
124 
125  if (r2 > cylinderR2) {
126  continue;
127  }
128 
129  ROOT::Math::XYZVector dXYZ = hitXYZ - centroid_;
130 
131  double weight = *hitEnergyIter;
132  totalW += weight;
133 
134  dxdx += weight * dXYZ.x() * dXYZ.x();
135  dydy += weight * dXYZ.y() * dXYZ.y();
136  dzdz += weight * dXYZ.z() * dXYZ.z();
137 
138  dxdy += weight * dXYZ.x() * dXYZ.y();
139  dydz += weight * dXYZ.y() * dXYZ.z();
140  dzdx += weight * dXYZ.z() * dXYZ.x();
141 
142  nHit++;
143  }
144 
145  if (!totalW || nHit < 2) {
146  return ShowerWidths();
147  }
148 
149  dxdx /= totalW;
150  dydy /= totalW;
151  dzdz /= totalW;
152 
153  dxdy /= totalW;
154  dydz /= totalW;
155  dzdx /= totalW;
156 
157  covMat(0, 0) = dxdx;
158  covMat(1, 1) = dydy;
159  covMat(2, 2) = dzdz;
160 
161  covMat(0, 1) = covMat(1, 0) = dxdy;
162  covMat(0, 2) = covMat(2, 0) = dzdx;
163  covMat(1, 2) = covMat(2, 1) = dydz;
164 
165  if (!covMat.Sum()) {
166  return ShowerWidths();
167  }
168 
169  // Get eigen values and vectors
170  TVectorD eigVals(3);
171  TMatrixD eigVecMat(3, 3);
172 
173  eigVecMat = covMat.EigenVectors(eigVals);
174 
175  ShowerWidths returnWidths;
176 
177  returnWidths.sigma2xx = dxdx;
178  returnWidths.sigma2yy = dydy;
179  returnWidths.sigma2zz = dzdz;
180 
181  returnWidths.sigma2xy = dxdy;
182  returnWidths.sigma2yz = dydz;
183  returnWidths.sigma2zx = dzdx;
184 
185  returnWidths.sigma2uu = eigVals(1);
186  returnWidths.sigma2vv = eigVals(2);
187  returnWidths.sigma2ww = eigVals(0);
188 
189  return returnWidths;
190 }

References BeamSpotFakeParameters_cfi::dydz, diffTwoXMLs::r2, HGCalShowerShapeHelper::recHitTools_, HGCalShowerShapeHelper::ShowerWidths::sigma2uu, HGCalShowerShapeHelper::ShowerWidths::sigma2vv, HGCalShowerShapeHelper::ShowerWidths::sigma2ww, HGCalShowerShapeHelper::ShowerWidths::sigma2xx, HGCalShowerShapeHelper::ShowerWidths::sigma2xy, HGCalShowerShapeHelper::ShowerWidths::sigma2yy, HGCalShowerShapeHelper::ShowerWidths::sigma2yz, HGCalShowerShapeHelper::ShowerWidths::sigma2zx, HGCalShowerShapeHelper::ShowerWidths::sigma2zz, and mps_merge::weight.

Referenced by SCEnergyCorrectorSemiParm::getRegDataHGCALV1().

◆ getRvar()

double HGCalShowerShapeHelper::ShowerShapeCalc::getRvar ( double  cylinderR,
bool  useFractions = true,
bool  useCellSize = true 
) const

Definition at line 35 of file HGCalShowerShapeHelper.cc.

35  {
36  if (hitsAndFracs_.empty()) {
37  return 0.0;
38  }
39 
40  if (rawEnergy_ <= 0.0) {
41  edm::LogWarning("HGCalShowerShapeHelper")
42  << "Encountered negative or zero energy for HGCal R-variable denominator: " << rawEnergy_ << std::endl;
43  }
44 
45  double cylinderR2 = cylinderR * cylinderR;
46 
47  double rVar = 0.0;
48 
49  auto hitEnergyIter = useFractions ? hitEnergiesWithFracs_.begin() : hitEnergies_.begin();
50 
51  hitEnergyIter--;
52 
53  for (const auto &hnf : hitsAndFracs_) {
54  hitEnergyIter++;
55 
56  DetId hitId = hnf.first;
57 
58  int hitLayer = recHitTools_->getLayer(hitId) - 1;
59 
60  const auto &hitPos = recHitTools_->getPosition(hitId);
61  ROOT::Math::XYZVector hitXYZ(hitPos.x(), hitPos.y(), hitPos.z());
62 
63  auto distXYZ = hitXYZ - layerCentroids_[hitLayer];
64 
65  double r2 = distXYZ.x() * distXYZ.x() + distXYZ.y() * distXYZ.y();
66 
67  // Including the cell size seems to make the variable less sensitive to the HD/LD transition region
68  if (useCellSize) {
69  if (std::sqrt(r2) > cylinderR + getCellSize(hitId)) {
70  continue;
71  }
72  }
73 
74  else if (r2 > cylinderR2) {
75  continue;
76  }
77 
78  rVar += *hitEnergyIter;
79  }
80 
81  rVar /= rawEnergy_;
82 
83  return rVar;
84 }

References diffTwoXMLs::r2, HGCalShowerShapeHelper::recHitTools_, and mathSSE::sqrt().

◆ setFilteredHitsAndFractions()

void HGCalShowerShapeHelper::ShowerShapeCalc::setFilteredHitsAndFractions ( const std::vector< std::pair< DetId, float > > &  hitsAndFracs)
private

Definition at line 201 of file HGCalShowerShapeHelper.cc.

202  {
203  hitsAndFracs_.clear();
204  hitEnergies_.clear();
205  hitEnergiesWithFracs_.clear();
206 
207  for (const auto &hnf : hitsAndFracs) {
208  DetId hitId = hnf.first;
209  float hitEfrac = hnf.second;
210 
211  int hitLayer = recHitTools_->getLayer(hitId);
212 
213  if (hitLayer > nLayer_) {
214  continue;
215  }
216 
217  if (hitId.det() != subDet_) {
218  continue;
219  }
220  auto hitIt = pfRecHitPtrMap_->find(hitId.rawId());
221  if (hitIt == pfRecHitPtrMap_->end()) {
222  continue;
223  }
224 
225  const reco::PFRecHit &recHit = *hitIt->second;
226 
227  if (recHit.energy() < minHitE_) {
228  continue;
229  }
230 
231  if (recHit.pt2() < minHitET2_) {
232  continue;
233  }
234 
235  // Fill the vectors
236  hitsAndFracs_.push_back(hnf);
237  hitEnergies_.push_back(recHit.energy());
238  hitEnergiesWithFracs_.push_back(recHit.energy() * hitEfrac);
239  }
240 }

References DetId::det(), HGCalShowerShapeHelper::pfRecHitPtrMap_, DetId::rawId(), rpcPointValidation_cfi::recHit, and HGCalShowerShapeHelper::recHitTools_.

Referenced by ShowerShapeCalc().

◆ setLayerWiseInfo()

void HGCalShowerShapeHelper::ShowerShapeCalc::setLayerWiseInfo ( )
private

Definition at line 242 of file HGCalShowerShapeHelper.cc.

242  {
243  layerEnergies_.clear();
244  layerEnergies_.resize(nLayer_);
245 
246  layerCentroids_.clear();
247  layerCentroids_.resize(nLayer_);
248 
249  centroid_.SetXYZ(0, 0, 0);
250 
251  int iHit = -1;
252  double totalW = 0.0;
253 
254  // Compute the centroid per layer
255  for (const auto &hnf : hitsAndFracs_) {
256  iHit++;
257 
258  DetId hitId = hnf.first;
259 
260  double weight = hitEnergies_[iHit];
261  totalW += weight;
262 
263  const auto &hitPos = recHitTools_->getPosition(hitId);
264  ROOT::Math::XYZVector hitXYZ(hitPos.x(), hitPos.y(), hitPos.z());
265 
266  centroid_ += weight * hitXYZ;
267 
268  int hitLayer = recHitTools_->getLayer(hitId) - 1;
269 
270  layerEnergies_[hitLayer] += weight;
271  layerCentroids_[hitLayer] += weight * hitXYZ;
272  }
273 
274  int iLayer = -1;
275 
276  for (auto &centroid : layerCentroids_) {
277  iLayer++;
278 
279  if (layerEnergies_[iLayer]) {
280  centroid /= layerEnergies_[iLayer];
281  }
282  }
283 
284  if (totalW) {
285  centroid_ /= totalW;
286  }
287 }

References HGCalShowerShapeHelper::recHitTools_, and mps_merge::weight.

Referenced by ShowerShapeCalc().

Member Data Documentation

◆ centroid_

ROOT::Math::XYZVector HGCalShowerShapeHelper::ShowerShapeCalc::centroid_
private

Definition at line 130 of file HGCalShowerShapeHelper.h.

◆ hitEnergies_

std::vector<double> HGCalShowerShapeHelper::ShowerShapeCalc::hitEnergies_
private

Definition at line 127 of file HGCalShowerShapeHelper.h.

◆ hitEnergiesWithFracs_

std::vector<double> HGCalShowerShapeHelper::ShowerShapeCalc::hitEnergiesWithFracs_
private

Definition at line 128 of file HGCalShowerShapeHelper.h.

◆ hitsAndFracs_

std::vector<std::pair<DetId, float> > HGCalShowerShapeHelper::ShowerShapeCalc::hitsAndFracs_
private

Definition at line 126 of file HGCalShowerShapeHelper.h.

◆ layerCentroids_

std::vector<ROOT::Math::XYZVector> HGCalShowerShapeHelper::ShowerShapeCalc::layerCentroids_
private

Definition at line 132 of file HGCalShowerShapeHelper.h.

◆ layerEnergies_

std::vector<double> HGCalShowerShapeHelper::ShowerShapeCalc::layerEnergies_
private

Definition at line 131 of file HGCalShowerShapeHelper.h.

◆ maxLayer_

int HGCalShowerShapeHelper::ShowerShapeCalc::maxLayer_
private

Definition at line 122 of file HGCalShowerShapeHelper.h.

◆ minHitE_

double HGCalShowerShapeHelper::ShowerShapeCalc::minHitE_
private

Definition at line 118 of file HGCalShowerShapeHelper.h.

◆ minHitET2_

double HGCalShowerShapeHelper::ShowerShapeCalc::minHitET2_
private

Definition at line 120 of file HGCalShowerShapeHelper.h.

◆ minHitET_

double HGCalShowerShapeHelper::ShowerShapeCalc::minHitET_
private

Definition at line 119 of file HGCalShowerShapeHelper.h.

◆ minLayer_

int HGCalShowerShapeHelper::ShowerShapeCalc::minLayer_
private

Definition at line 121 of file HGCalShowerShapeHelper.h.

◆ nLayer_

int HGCalShowerShapeHelper::ShowerShapeCalc::nLayer_
private

Definition at line 123 of file HGCalShowerShapeHelper.h.

Referenced by ShowerShapeCalc().

◆ pfRecHitPtrMap_

std::shared_ptr<const std::unordered_map<uint32_t, const reco::PFRecHit *> > HGCalShowerShapeHelper::ShowerShapeCalc::pfRecHitPtrMap_
private

Definition at line 115 of file HGCalShowerShapeHelper.h.

◆ rawEnergy_

double HGCalShowerShapeHelper::ShowerShapeCalc::rawEnergy_
private

Definition at line 116 of file HGCalShowerShapeHelper.h.

◆ recHitTools_

std::shared_ptr<const hgcal::RecHitTools> HGCalShowerShapeHelper::ShowerShapeCalc::recHitTools_
private

Definition at line 114 of file HGCalShowerShapeHelper.h.

◆ subDet_

DetId::Detector HGCalShowerShapeHelper::ShowerShapeCalc::subDet_
private

Definition at line 124 of file HGCalShowerShapeHelper.h.

HGCalShowerShapeHelper::ShowerShapeCalc::hitsAndFracs_
std::vector< std::pair< DetId, float > > hitsAndFracs_
Definition: HGCalShowerShapeHelper.h:126
HGCalShowerShapeHelper::ShowerShapeCalc::minLayer_
int minLayer_
Definition: HGCalShowerShapeHelper.h:121
HGCalShowerShapeHelper::ShowerShapeCalc::recHitTools_
std::shared_ptr< const hgcal::RecHitTools > recHitTools_
Definition: HGCalShowerShapeHelper.h:114
HGCalShowerShapeHelper::ShowerShapeCalc::nLayer_
int nLayer_
Definition: HGCalShowerShapeHelper.h:123
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
mps_merge.weight
weight
Definition: mps_merge.py:88
DetId::det
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
HGCalShowerShapeHelper::ShowerShapeCalc::subDet_
DetId::Detector subDet_
Definition: HGCalShowerShapeHelper.h:124
cms::cuda::assert
assert(be >=bs)
rpcPointValidation_cfi.recHit
recHit
Definition: rpcPointValidation_cfi.py:7
HGCalShowerShapeHelper::ShowerShapeCalc::hitEnergies_
std::vector< double > hitEnergies_
Definition: HGCalShowerShapeHelper.h:127
DetId
Definition: DetId.h:17
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
HGCalShowerShapeHelper::ShowerShapeCalc::setFilteredHitsAndFractions
void setFilteredHitsAndFractions(const std::vector< std::pair< DetId, float > > &hitsAndFracs)
Definition: HGCalShowerShapeHelper.cc:201
HGCalShowerShapeHelper::ShowerShapeCalc::minHitE_
double minHitE_
Definition: HGCalShowerShapeHelper.h:118
HGCalShowerShapeHelper::ShowerShapeCalc::minHitET_
double minHitET_
Definition: HGCalShowerShapeHelper.h:119
HGCalShowerShapeHelper::ShowerShapeCalc::pfRecHitPtrMap_
std::shared_ptr< const std::unordered_map< uint32_t, const reco::PFRecHit * > > pfRecHitPtrMap_
Definition: HGCalShowerShapeHelper.h:115
HGCalShowerShapeHelper::ShowerShapeCalc::layerCentroids_
std::vector< ROOT::Math::XYZVector > layerCentroids_
Definition: HGCalShowerShapeHelper.h:132
edm::LogWarning
Definition: MessageLogger.h:141
diffTwoXMLs.r2
r2
Definition: diffTwoXMLs.py:73
HGCalShowerShapeHelper::ShowerShapeCalc::centroid_
ROOT::Math::XYZVector centroid_
Definition: HGCalShowerShapeHelper.h:130
HGCalShowerShapeHelper::ShowerShapeCalc::maxLayer_
int maxLayer_
Definition: HGCalShowerShapeHelper.h:122
BeamSpotFakeParameters_cfi.dydz
dydz
Definition: BeamSpotFakeParameters_cfi.py:13
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
HGCalShowerShapeHelper::ShowerShapeCalc::rawEnergy_
double rawEnergy_
Definition: HGCalShowerShapeHelper.h:116
HGCalShowerShapeHelper::kHDWaferCellSize_
static const double kHDWaferCellSize_
Definition: HGCalShowerShapeHelper.h:61
ROOT::Math::XYZVector
Transform3DPJ::Vector XYZVector
Definition: Transform3DPJ.cc:34
reco::PFRecHit
Particle flow rechit (rechit + geometry and topology information). See clustering algorithm in PFClus...
Definition: PFRecHit.h:31
HGCalShowerShapeHelper::ShowerShapeCalc::getCellSize
double getCellSize(DetId detId) const
Definition: HGCalShowerShapeHelper.cc:31
HGCalShowerShapeHelper::ShowerShapeCalc::layerEnergies_
std::vector< double > layerEnergies_
Definition: HGCalShowerShapeHelper.h:131
HGCalShowerShapeHelper::ShowerShapeCalc::minHitET2_
double minHitET2_
Definition: HGCalShowerShapeHelper.h:120
HLT_2018_cff.minLayer
minLayer
Definition: HLT_2018_cff.py:51501
HGCalShowerShapeHelper::ShowerShapeCalc::setLayerWiseInfo
void setLayerWiseInfo()
Definition: HGCalShowerShapeHelper.cc:242
HGCalShowerShapeHelper::kLDWaferCellSize_
static const double kLDWaferCellSize_
Definition: HGCalShowerShapeHelper.h:60
weight
Definition: weight.py:1
HGCalShowerShapeHelper::ShowerShapeCalc::hitEnergiesWithFracs_
std::vector< double > hitEnergiesWithFracs_
Definition: HGCalShowerShapeHelper.h:128