CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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::XYZVector
layerCentroids_
 
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::RecHitTools
recHitTools_
 
DetId::Detector subDet_
 

Detailed Description

Definition at line 72 of file HGCalShowerShapeHelper.h.

Constructor & Destructor Documentation

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 12 of file HGCalShowerShapeHelper.cc.

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

22  : recHitTools_(recHitTools),
23  pfRecHitPtrMap_(pfRecHitPtrMap),
24  rawEnergy_(rawEnergy),
25  minHitE_(minHitE),
26  minHitET_(minHitET),
27  minHitET2_(minHitET * minHitET),
29  maxLayer_(maxLayer <= 0 ? recHitTools_->lastLayerEE() : maxLayer),
31  subDet_(subDet) {
32  assert(nLayer_ > 0);
33  setFilteredHitsAndFractions(hitsAndFracs);
35 }
std::shared_ptr< const hgcal::RecHitTools > recHitTools_
assert(be >=bs)
void setFilteredHitsAndFractions(const std::vector< std::pair< DetId, float > > &hitsAndFracs)
std::shared_ptr< const std::unordered_map< uint32_t, const reco::PFRecHit * > > pfRecHitPtrMap_

Member Function Documentation

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

Definition at line 37 of file HGCalShowerShapeHelper.cc.

References HGCalShowerShapeHelper::kHDWaferCellSize_, HGCalShowerShapeHelper::kLDWaferCellSize_, and HGCalShowerShapeHelper::recHitTools_.

37  {
38  return recHitTools_->getSiThickIndex(detId) == 0 ? kHDWaferCellSize_ : kLDWaferCellSize_;
39 }
std::shared_ptr< const hgcal::RecHitTools > recHitTools_
static const double kHDWaferCellSize_
static const double kLDWaferCellSize_
std::vector< double > HGCalShowerShapeHelper::ShowerShapeCalc::getEnergyHighestHits ( unsigned int  nrHits,
bool  useFractions = true 
) const

Definition at line 198 of file HGCalShowerShapeHelper.cc.

199  {
200  std::vector<double> sortedEnergies(nrHits, 0.);
201  const auto &hits = useFractions ? hitEnergiesWithFracs_ : hitEnergies_;
202  std::partial_sort_copy(
203  hits.begin(), hits.end(), sortedEnergies.begin(), sortedEnergies.end(), std::greater<double>());
204  return sortedEnergies;
205 }
HGCalShowerShapeHelper::ShowerWidths HGCalShowerShapeHelper::ShowerShapeCalc::getPCAWidths ( double  cylinderR,
bool  useFractions = false 
) const

Definition at line 92 of file HGCalShowerShapeHelper.cc.

References BeamSpotPI::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 histoStyle::weight.

Referenced by SCEnergyCorrectorSemiParm::getRegDataHGCALV1().

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

Definition at line 41 of file HGCalShowerShapeHelper.cc.

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

41  {
42  if (hitsAndFracs_.empty()) {
43  return 0.0;
44  }
45 
46  if (rawEnergy_ <= 0.0) {
47  edm::LogWarning("HGCalShowerShapeHelper")
48  << "Encountered negative or zero energy for HGCal R-variable denominator: " << rawEnergy_ << std::endl;
49  }
50 
51  double cylinderR2 = cylinderR * cylinderR;
52 
53  double rVar = 0.0;
54 
55  auto hitEnergyIter = useFractions ? hitEnergiesWithFracs_.begin() : hitEnergies_.begin();
56 
57  hitEnergyIter--;
58 
59  for (const auto &hnf : hitsAndFracs_) {
60  hitEnergyIter++;
61 
62  DetId hitId = hnf.first;
63 
64  int hitLayer = recHitTools_->getLayer(hitId) - 1;
65 
66  const auto &hitPos = recHitTools_->getPosition(hitId);
67  ROOT::Math::XYZVector hitXYZ(hitPos.x(), hitPos.y(), hitPos.z());
68 
69  auto distXYZ = hitXYZ - layerCentroids_[hitLayer];
70 
71  double r2 = distXYZ.x() * distXYZ.x() + distXYZ.y() * distXYZ.y();
72 
73  // Including the cell size seems to make the variable less sensitive to the HD/LD transition region
74  if (useCellSize) {
75  if (std::sqrt(r2) > cylinderR + getCellSize(hitId)) {
76  continue;
77  }
78  }
79 
80  else if (r2 > cylinderR2) {
81  continue;
82  }
83 
84  rVar += *hitEnergyIter;
85  }
86 
87  rVar /= rawEnergy_;
88 
89  return rVar;
90 }
std::vector< std::pair< DetId, float > > hitsAndFracs_
std::shared_ptr< const hgcal::RecHitTools > recHitTools_
T sqrt(T t)
Definition: SSEVec.h:19
std::vector< ROOT::Math::XYZVector > layerCentroids_
Definition: DetId.h:17
Transform3DPJ::Vector XYZVector
Log< level::Warning, false > LogWarning
void HGCalShowerShapeHelper::ShowerShapeCalc::setFilteredHitsAndFractions ( const std::vector< std::pair< DetId, float > > &  hitsAndFracs)
private

Definition at line 207 of file HGCalShowerShapeHelper.cc.

References DetId::det(), reco::PFRecHit::energy(), HGCalShowerShapeHelper::pfRecHitPtrMap_, reco::PFRecHit::pt2(), DetId::rawId(), and HGCalShowerShapeHelper::recHitTools_.

Referenced by ShowerShapeCalc().

208  {
209  hitsAndFracs_.clear();
210  hitEnergies_.clear();
211  hitEnergiesWithFracs_.clear();
212 
213  for (const auto &hnf : hitsAndFracs) {
214  DetId hitId = hnf.first;
215  float hitEfrac = hnf.second;
216 
217  int hitLayer = recHitTools_->getLayer(hitId);
218 
219  if (hitLayer > nLayer_) {
220  continue;
221  }
222 
223  if (hitId.det() != subDet_) {
224  continue;
225  }
226  auto hitIt = pfRecHitPtrMap_->find(hitId.rawId());
227  if (hitIt == pfRecHitPtrMap_->end()) {
228  continue;
229  }
230 
231  const reco::PFRecHit &recHit = *hitIt->second;
232 
233  if (recHit.energy() < minHitE_) {
234  continue;
235  }
236 
237  if (recHit.pt2() < minHitET2_) {
238  continue;
239  }
240 
241  // Fill the vectors
242  hitsAndFracs_.push_back(hnf);
243  hitEnergies_.push_back(recHit.energy());
244  hitEnergiesWithFracs_.push_back(recHit.energy() * hitEfrac);
245  }
246 }
std::vector< std::pair< DetId, float > > hitsAndFracs_
std::shared_ptr< const hgcal::RecHitTools > recHitTools_
double pt2() const
rechit momentum transverse to the beam, squared.
Definition: PFRecHit.h:108
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
Particle flow rechit (rechit + geometry and topology information). See clustering algorithm in PFClus...
Definition: PFRecHit.h:31
std::shared_ptr< const std::unordered_map< uint32_t, const reco::PFRecHit * > > pfRecHitPtrMap_
float energy() const
rechit energy
Definition: PFRecHit.h:99
Definition: DetId.h:17
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
void HGCalShowerShapeHelper::ShowerShapeCalc::setLayerWiseInfo ( )
private

Definition at line 248 of file HGCalShowerShapeHelper.cc.

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

Referenced by ShowerShapeCalc().

248  {
249  layerEnergies_.clear();
250  layerEnergies_.resize(nLayer_);
251 
252  layerCentroids_.clear();
253  layerCentroids_.resize(nLayer_);
254 
255  centroid_.SetXYZ(0, 0, 0);
256 
257  int iHit = -1;
258  double totalW = 0.0;
259 
260  // Compute the centroid per layer
261  for (const auto &hnf : hitsAndFracs_) {
262  iHit++;
263 
264  DetId hitId = hnf.first;
265 
266  double weight = hitEnergies_[iHit];
267  totalW += weight;
268 
269  const auto &hitPos = recHitTools_->getPosition(hitId);
270  ROOT::Math::XYZVector hitXYZ(hitPos.x(), hitPos.y(), hitPos.z());
271 
272  centroid_ += weight * hitXYZ;
273 
274  int hitLayer = recHitTools_->getLayer(hitId) - 1;
275 
276  layerEnergies_[hitLayer] += weight;
277  layerCentroids_[hitLayer] += weight * hitXYZ;
278  }
279 
280  int iLayer = -1;
281 
282  for (auto &centroid : layerCentroids_) {
283  iLayer++;
284 
285  if (layerEnergies_[iLayer]) {
286  centroid /= layerEnergies_[iLayer];
287  }
288  }
289 
290  if (totalW) {
291  centroid_ /= totalW;
292  }
293 }
std::vector< std::pair< DetId, float > > hitsAndFracs_
std::shared_ptr< const hgcal::RecHitTools > recHitTools_
std::vector< ROOT::Math::XYZVector > layerCentroids_
Definition: DetId.h:17
Transform3DPJ::Vector XYZVector
int weight
Definition: histoStyle.py:51

Member Data Documentation

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

Definition at line 114 of file HGCalShowerShapeHelper.h.

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

Definition at line 111 of file HGCalShowerShapeHelper.h.

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

Definition at line 112 of file HGCalShowerShapeHelper.h.

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

Definition at line 110 of file HGCalShowerShapeHelper.h.

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

Definition at line 116 of file HGCalShowerShapeHelper.h.

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

Definition at line 115 of file HGCalShowerShapeHelper.h.

int HGCalShowerShapeHelper::ShowerShapeCalc::maxLayer_
private

Definition at line 106 of file HGCalShowerShapeHelper.h.

double HGCalShowerShapeHelper::ShowerShapeCalc::minHitE_
private

Definition at line 102 of file HGCalShowerShapeHelper.h.

double HGCalShowerShapeHelper::ShowerShapeCalc::minHitET2_
private

Definition at line 104 of file HGCalShowerShapeHelper.h.

double HGCalShowerShapeHelper::ShowerShapeCalc::minHitET_
private

Definition at line 103 of file HGCalShowerShapeHelper.h.

int HGCalShowerShapeHelper::ShowerShapeCalc::minLayer_
private

Definition at line 105 of file HGCalShowerShapeHelper.h.

int HGCalShowerShapeHelper::ShowerShapeCalc::nLayer_
private

Definition at line 107 of file HGCalShowerShapeHelper.h.

Referenced by ShowerShapeCalc().

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

Definition at line 99 of file HGCalShowerShapeHelper.h.

double HGCalShowerShapeHelper::ShowerShapeCalc::rawEnergy_
private

Definition at line 100 of file HGCalShowerShapeHelper.h.

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

Definition at line 98 of file HGCalShowerShapeHelper.h.

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

Definition at line 108 of file HGCalShowerShapeHelper.h.