CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
ECAL2DPositionCalcWithDepthCorr Class Reference

This is EGM version of the ECAL position + depth correction calculation. More...

Inheritance diagram for ECAL2DPositionCalcWithDepthCorr:
PFCPositionCalculatorBase

Public Member Functions

void calculateAndSetPosition (reco::PFCluster &, const HcalPFCuts *) override
 
void calculateAndSetPositions (reco::PFClusterCollection &, const HcalPFCuts *) override
 
 ECAL2DPositionCalcWithDepthCorr (const edm::ParameterSet &conf, edm::ConsumesCollector &cc)
 
 ECAL2DPositionCalcWithDepthCorr (const ECAL2DPositionCalcWithDepthCorr &)=delete
 
ECAL2DPositionCalcWithDepthCorroperator= (const ECAL2DPositionCalcWithDepthCorr &)=delete
 
void update (const edm::EventSetup &es) override
 
- Public Member Functions inherited from PFCPositionCalculatorBase
const std::string & name () const
 
PosCalcoperator= (const PosCalc &)=delete
 
 PFCPositionCalculatorBase (const edm::ParameterSet &conf, edm::ConsumesCollector &cc)
 
 PFCPositionCalculatorBase (const PosCalc &)=delete
 
virtual ~PFCPositionCalculatorBase ()=default
 

Private Member Functions

void calculateAndSetPositionActual (reco::PFCluster &) const
 

Private Attributes

const CaloSubdetectorGeometry_ebGeom
 
const CaloSubdetectorGeometry_eeGeom
 
const CaloSubdetectorGeometry_esGeom
 
bool _esMinus
 
bool _esPlus
 
edm::ESGetToken< CaloGeometry, CaloGeometryRecord_geomToken
 
const double _minAllowedNorm
 
const double _param_T0_EB
 
const double _param_T0_EE
 
const double _param_T0_ES
 
const double _param_W0
 
const double _param_X0
 
std::unique_ptr< CaloRecHitResolutionProvider_timeResolutionCalc
 

Additional Inherited Members

- Protected Attributes inherited from PFCPositionCalculatorBase
const float _minFractionInCalc
 

Detailed Description

This is EGM version of the ECAL position + depth correction calculation.

Definition at line 24 of file ECAL2DPositionCalcWithDepthCorr.cc.

Constructor & Destructor Documentation

◆ ECAL2DPositionCalcWithDepthCorr() [1/2]

ECAL2DPositionCalcWithDepthCorr::ECAL2DPositionCalcWithDepthCorr ( const edm::ParameterSet conf,
edm::ConsumesCollector cc 
)
inline

Definition at line 26 of file ECAL2DPositionCalcWithDepthCorr.cc.

References _timeResolutionCalc, and edm::ParameterSet::getParameterSet().

28  _param_T0_EB(conf.getParameter<double>("T0_EB")),
29  _param_T0_EE(conf.getParameter<double>("T0_EE")),
30  _param_T0_ES(conf.getParameter<double>("T0_ES")),
31  _param_W0(conf.getParameter<double>("W0")),
32  _param_X0(conf.getParameter<double>("X0")),
33  _minAllowedNorm(conf.getParameter<double>("minAllowedNormalization")),
34  _ebGeom(nullptr),
35  _eeGeom(nullptr),
36  _esGeom(nullptr),
37  _esPlus(false),
38  _esMinus(false),
39  _geomToken(cc.esConsumes<edm::Transition::BeginRun>()) {
40  _timeResolutionCalc.reset(nullptr);
41  const auto& timeResConf = conf.getParameterSet("timeResolutionCalc");
42  if (!timeResConf.empty())
43  _timeResolutionCalc = std::make_unique<CaloRecHitResolutionProvider>(timeResConf);
44  }
PFCPositionCalculatorBase(const edm::ParameterSet &conf, edm::ConsumesCollector &cc)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
ParameterSet const & getParameterSet(std::string const &) const
std::unique_ptr< CaloRecHitResolutionProvider > _timeResolutionCalc
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > _geomToken

◆ ECAL2DPositionCalcWithDepthCorr() [2/2]

ECAL2DPositionCalcWithDepthCorr::ECAL2DPositionCalcWithDepthCorr ( const ECAL2DPositionCalcWithDepthCorr )
delete

Member Function Documentation

◆ calculateAndSetPosition()

void ECAL2DPositionCalcWithDepthCorr::calculateAndSetPosition ( reco::PFCluster cluster,
const HcalPFCuts  
)
overridevirtual

Implements PFCPositionCalculatorBase.

Definition at line 94 of file ECAL2DPositionCalcWithDepthCorr.cc.

References calculateAndSetPositionActual().

94  {
96 }
void calculateAndSetPositionActual(reco::PFCluster &) const

◆ calculateAndSetPositionActual()

void ECAL2DPositionCalcWithDepthCorr::calculateAndSetPositionActual ( reco::PFCluster cluster) const
private

Definition at line 104 of file ECAL2DPositionCalcWithDepthCorr.cc.

References _ebGeom, _eeGeom, _esMinus, _esPlus, _minAllowedNorm, _param_T0_EB, _param_T0_EE, _param_T0_ES, _param_W0, _param_X0, _timeResolutionCalc, funct::abs(), reco::PFCluster::calculatePositionREP(), ALPAKA_ACCELERATOR_NAMESPACE::brokenline::constexpr(), hcalRecHitTable_cff::depth, PFLayer::ECAL_BARREL, PFLayer::ECAL_ENDCAP, reco::PFCluster::energy(), Exception, f, nano_mu_digi_cff::float, CaloSubdetectorGeometry::getGeometry(), edm::isFinite(), SiStripPI::max, HLT_2024v13_cff::maxDepth, PFLayer::NONE, reco::PFCluster::recHitFractions(), reco::CaloCluster::seed(), reco::CaloCluster::setEnergy(), reco::PFCluster::setLayer(), reco::CaloCluster::setPosition(), reco::PFCluster::setTime(), reco::PFCluster::setTimeError(), mathSSE::sqrt(), mps_merge::weight, x, y, and z.

Referenced by calculateAndSetPosition(), and calculateAndSetPositions().

104  {
105  constexpr double preshowerStartEta = 1.653;
106  constexpr double preshowerEndEta = 2.6;
107  if (!cluster.seed()) {
108  throw cms::Exception("ClusterWithNoSeed") << " Found a cluster with no seed: " << cluster;
109  }
110  double cl_energy = 0;
111  double cl_energy_float = 0;
112  double cl_time = 0;
113  double cl_timeweight = 0.0;
114  double max_e = 0.0;
115  double clusterT0 = 0.0;
116  PFLayer::Layer max_e_layer = PFLayer::NONE;
117  reco::PFRecHitRef refmax;
118  // find the seed and max layer
119  for (const reco::PFRecHitFraction& rhf : cluster.recHitFractions()) {
120  const reco::PFRecHitRef& refhit = rhf.recHitRef();
121  const double rh_fraction = rhf.fraction();
122  const double rh_rawenergy = refhit->energy();
123  const double rh_energy = rh_rawenergy * rh_fraction;
124  const double rh_energyf = ((float)rh_rawenergy) * ((float)rh_fraction);
125  if (!edm::isFinite(rh_energy)) {
126  throw cms::Exception("PFClusterAlgo") << "rechit " << refhit->detId() << " has non-finite energy... "
127  << "The input of the particle flow clustering seems to be corrupted.";
128  }
129  cl_energy += rh_energy;
130  cl_energy_float += rh_energyf;
131  // If time resolution is given, calculate weighted average
132  if (_timeResolutionCalc) {
133  const double res2 = 1. / _timeResolutionCalc->timeResolution2(rh_rawenergy);
134  cl_time += rh_fraction * refhit->time() * res2;
135  cl_timeweight += rh_fraction * res2;
136  } else { // assume resolution ~ 1/E**2
137  const double rh_rawenergy2 = rh_rawenergy * rh_rawenergy;
138  cl_timeweight += rh_rawenergy2 * rh_fraction;
139  cl_time += rh_rawenergy2 * rh_fraction * refhit->time();
140  }
141  if (rh_energy > max_e) {
142  max_e = rh_energy;
143  max_e_layer = rhf.recHitRef()->layer();
144  refmax = refhit;
145  }
146  }
147  cluster.setEnergy(cl_energy);
148  cluster.setTime(cl_time / cl_timeweight);
149  if (_timeResolutionCalc) {
150  cluster.setTimeError(std::sqrt(1.0f / float(cl_timeweight)));
151  }
152  cluster.setLayer(max_e_layer);
153  const CaloSubdetectorGeometry* ecal_geom = nullptr;
154  // get seed geometry information
155  switch (max_e_layer) {
157  ecal_geom = _ebGeom;
158  clusterT0 = _param_T0_EB;
159  break;
161  ecal_geom = _eeGeom;
162  clusterT0 = _param_T0_EE;
163  break;
164  default:
165  throw cms::Exception("InvalidLayer") << "ECAL Position Calc only accepts ECAL_BARREL or ECAL_ENDCAP";
166  }
167 
168  auto center_cell = ecal_geom->getGeometry(refmax->detId());
169  const double ctreta = center_cell->etaPos();
170  const double actreta = std::abs(ctreta);
171  // need to change T0 if in ES
172  if (actreta > preshowerStartEta && actreta < preshowerEndEta) {
173  if (ctreta > 0 && _esPlus)
174  clusterT0 = _param_T0_ES;
175  if (ctreta < 0 && _esMinus)
176  clusterT0 = _param_T0_ES;
177  }
178  // floats to reproduce exactly the EGM code
179  const float maxDepth = _param_X0 * (clusterT0 + vdt::fast_log(cl_energy_float));
180  const float maxToFront = center_cell->getPosition().mag();
181  // calculate the position
182  const double logETot_inv = -vdt::fast_log(cl_energy_float);
183  double position_norm = 0.0;
184  double x(0.0), y(0.0), z(0.0);
185  for (const reco::PFRecHitFraction& rhf : cluster.recHitFractions()) {
186  double weight = 0.0;
187  const reco::PFRecHitRef& refhit = rhf.recHitRef();
188  const double rh_energy = ((float)refhit->energy()) * ((float)rhf.fraction());
189  if (rh_energy > 0.0)
190  weight = std::max(0.0, (_param_W0 + vdt::fast_log(rh_energy) + logETot_inv));
191  auto cell = ecal_geom->getGeometry(refhit->detId());
192  const float depth = maxDepth + maxToFront - cell->getPosition().mag();
193  const GlobalPoint pos = static_cast<const TruncatedPyramid*>(cell.get())->getPosition(depth);
194 
195  x += weight * pos.x();
196  y += weight * pos.y();
197  z += weight * pos.z();
198 
199  position_norm += weight;
200  }
201 
202  // FALL BACK to LINEAR WEIGHTS
203  if (position_norm == 0.) {
204  for (const reco::PFRecHitFraction& rhf : cluster.recHitFractions()) {
205  double weight = 0.0;
206  const reco::PFRecHitRef& refhit = rhf.recHitRef();
207  const double rh_energy = ((float)refhit->energy()) * ((float)rhf.fraction());
208  if (rh_energy > 0.0)
209  weight = rh_energy / cluster.energy();
210 
211  auto cell = ecal_geom->getGeometry(refhit->detId());
212  const float depth = maxDepth + maxToFront - cell->getPosition().mag();
213  const GlobalPoint pos = cell->getPosition(depth);
214 
215  x += weight * pos.x();
216  y += weight * pos.y();
217  z += weight * pos.z();
218 
219  position_norm += weight;
220  }
221  }
222 
223  if (position_norm < _minAllowedNorm) {
224  edm::LogError("WeirdClusterNormalization") << "PFCluster too far from seeding cell: set position to (0,0,0).";
225  cluster.setPosition(math::XYZPoint(0, 0, 0));
226  } else {
227  const double norm_inverse = 1.0 / position_norm;
228  x *= norm_inverse;
229  y *= norm_inverse;
230  z *= norm_inverse;
231 
232  cluster.setPosition(math::XYZPoint(x, y, z));
233  cluster.calculatePositionREP();
234  }
235 }
void setLayer(PFLayer::Layer layer)
set layer
Definition: PFCluster.cc:49
void setPosition(const math::XYZPoint &p)
Definition: CaloCluster.h:140
DetId seed() const
return DetId of seed
Definition: CaloCluster.h:219
void setTime(float time, float timeError=0)
Definition: PFCluster.h:84
Fraction of a PFRecHit (rechits can be shared between several PFCluster&#39;s)
std::unique_ptr< CaloRecHitResolutionProvider > _timeResolutionCalc
const std::vector< reco::PFRecHitFraction > & recHitFractions() const
vector of rechit fractions
Definition: PFCluster.h:65
void setEnergy(double energy)
Definition: CaloCluster.h:136
Definition: weight.py:1
Log< level::Error, false > LogError
constexpr bool isFinite(T x)
void calculatePositionREP()
computes posrep_ once and for all
Definition: PFCluster.h:95
T sqrt(T t)
Definition: SSEVec.h:23
double energy() const
cluster energy
Definition: PFCluster.h:74
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
virtual std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
Layer
layer definition
Definition: PFLayer.h:29
void setTimeError(float timeError)
Definition: PFCluster.h:88
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
A base class to handle the particular shape of Ecal Xtals. Taken from ORCA Calorimetry Code...

◆ calculateAndSetPositions()

void ECAL2DPositionCalcWithDepthCorr::calculateAndSetPositions ( reco::PFClusterCollection clusters,
const HcalPFCuts  
)
overridevirtual

Implements PFCPositionCalculatorBase.

Definition at line 98 of file ECAL2DPositionCalcWithDepthCorr.cc.

References calculateAndSetPositionActual(), and bsc_activity_cfg::clusters.

98  {
99  for (reco::PFCluster& cluster : clusters) {
101  }
102 }
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:42
void calculateAndSetPositionActual(reco::PFCluster &) const

◆ operator=()

ECAL2DPositionCalcWithDepthCorr& ECAL2DPositionCalcWithDepthCorr::operator= ( const ECAL2DPositionCalcWithDepthCorr )
delete

◆ update()

void ECAL2DPositionCalcWithDepthCorr::update ( const edm::EventSetup es)
overridevirtual

Reimplemented from PFCPositionCalculatorBase.

Definition at line 79 of file ECAL2DPositionCalcWithDepthCorr.cc.

References _ebGeom, _eeGeom, _esGeom, _esMinus, _esPlus, _geomToken, DetId::Ecal, EcalBarrel, EcalEndcap, EcalPreshower, CaloSubdetectorGeometry::getGeometry(), edm::EventSetup::getHandle(), CaloGeometry::getSubdetectorGeometry(), CaloSubdetectorGeometry::getValidDetIds(), and z.

Referenced by progressbar.ProgressBar::__next__(), MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), progressbar.ProgressBar::finish(), and MatrixUtil.Steps::overwrite().

79  {
84  if (_esGeom) {
85  // ripped from RecoEcal/EgammaCoreTools
86  for (uint32_t ic = 0; ic < _esGeom->getValidDetIds().size() && (!_esPlus || !_esMinus); ++ic) {
87  const double z = _esGeom->getGeometry(_esGeom->getValidDetIds()[ic])->getPosition().z();
88  _esPlus = _esPlus || (0 < z);
89  _esMinus = _esMinus || (0 > z);
90  }
91  }
92 }
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > _geomToken
virtual const std::vector< DetId > & getValidDetIds(DetId::Detector det=DetId::Detector(0), int subdet=0) const
Get a list of valid detector ids (for the given subdetector)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
virtual std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34

Member Data Documentation

◆ _ebGeom

const CaloSubdetectorGeometry* ECAL2DPositionCalcWithDepthCorr::_ebGeom
private

Definition at line 62 of file ECAL2DPositionCalcWithDepthCorr.cc.

Referenced by calculateAndSetPositionActual(), and update().

◆ _eeGeom

const CaloSubdetectorGeometry* ECAL2DPositionCalcWithDepthCorr::_eeGeom
private

Definition at line 63 of file ECAL2DPositionCalcWithDepthCorr.cc.

Referenced by calculateAndSetPositionActual(), and update().

◆ _esGeom

const CaloSubdetectorGeometry* ECAL2DPositionCalcWithDepthCorr::_esGeom
private

Definition at line 64 of file ECAL2DPositionCalcWithDepthCorr.cc.

Referenced by update().

◆ _esMinus

bool ECAL2DPositionCalcWithDepthCorr::_esMinus
private

Definition at line 65 of file ECAL2DPositionCalcWithDepthCorr.cc.

Referenced by calculateAndSetPositionActual(), and update().

◆ _esPlus

bool ECAL2DPositionCalcWithDepthCorr::_esPlus
private

Definition at line 65 of file ECAL2DPositionCalcWithDepthCorr.cc.

Referenced by calculateAndSetPositionActual(), and update().

◆ _geomToken

edm::ESGetToken<CaloGeometry, CaloGeometryRecord> ECAL2DPositionCalcWithDepthCorr::_geomToken
private

Definition at line 71 of file ECAL2DPositionCalcWithDepthCorr.cc.

Referenced by update().

◆ _minAllowedNorm

const double ECAL2DPositionCalcWithDepthCorr::_minAllowedNorm
private

Definition at line 59 of file ECAL2DPositionCalcWithDepthCorr.cc.

Referenced by calculateAndSetPositionActual().

◆ _param_T0_EB

const double ECAL2DPositionCalcWithDepthCorr::_param_T0_EB
private

Definition at line 54 of file ECAL2DPositionCalcWithDepthCorr.cc.

Referenced by calculateAndSetPositionActual().

◆ _param_T0_EE

const double ECAL2DPositionCalcWithDepthCorr::_param_T0_EE
private

Definition at line 55 of file ECAL2DPositionCalcWithDepthCorr.cc.

Referenced by calculateAndSetPositionActual().

◆ _param_T0_ES

const double ECAL2DPositionCalcWithDepthCorr::_param_T0_ES
private

Definition at line 56 of file ECAL2DPositionCalcWithDepthCorr.cc.

Referenced by calculateAndSetPositionActual().

◆ _param_W0

const double ECAL2DPositionCalcWithDepthCorr::_param_W0
private

Definition at line 57 of file ECAL2DPositionCalcWithDepthCorr.cc.

Referenced by calculateAndSetPositionActual().

◆ _param_X0

const double ECAL2DPositionCalcWithDepthCorr::_param_X0
private

Definition at line 58 of file ECAL2DPositionCalcWithDepthCorr.cc.

Referenced by calculateAndSetPositionActual().

◆ _timeResolutionCalc

std::unique_ptr<CaloRecHitResolutionProvider> ECAL2DPositionCalcWithDepthCorr::_timeResolutionCalc
private