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...

#include <ECAL2DPositionCalcWithDepthCorr.h>

Inheritance diagram for ECAL2DPositionCalcWithDepthCorr:
PFCPositionCalculatorBase

Public Member Functions

void calculateAndSetPosition (reco::PFCluster &) override
 
void calculateAndSetPositions (reco::PFClusterCollection &) override
 
 ECAL2DPositionCalcWithDepthCorr (const ECAL2DPositionCalcWithDepthCorr &)=delete
 
 ECAL2DPositionCalcWithDepthCorr (const edm::ParameterSet &conf)
 
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)
 
 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
 
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 17 of file ECAL2DPositionCalcWithDepthCorr.h.

Constructor & Destructor Documentation

◆ ECAL2DPositionCalcWithDepthCorr() [1/2]

ECAL2DPositionCalcWithDepthCorr::ECAL2DPositionCalcWithDepthCorr ( const edm::ParameterSet conf)
inline

Definition at line 19 of file ECAL2DPositionCalcWithDepthCorr.h.

21  _param_T0_EB(conf.getParameter<double>("T0_EB")),
22  _param_T0_EE(conf.getParameter<double>("T0_EE")),
23  _param_T0_ES(conf.getParameter<double>("T0_ES")),
24  _param_W0(conf.getParameter<double>("W0")),
25  _param_X0(conf.getParameter<double>("X0")),
26  _minAllowedNorm(conf.getParameter<double>("minAllowedNormalization")),
27  _ebGeom(nullptr),
28  _eeGeom(nullptr),
29  _esGeom(nullptr),
30  _esPlus(false),
31  _esMinus(false) {
32  _timeResolutionCalc.reset(nullptr);
33  if (conf.exists("timeResolutionCalc")) {
34  const edm::ParameterSet& timeResConf = conf.getParameterSet("timeResolutionCalc");
35  _timeResolutionCalc.reset(new CaloRecHitResolutionProvider(timeResConf));
36  }
37  }

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

◆ ECAL2DPositionCalcWithDepthCorr() [2/2]

ECAL2DPositionCalcWithDepthCorr::ECAL2DPositionCalcWithDepthCorr ( const ECAL2DPositionCalcWithDepthCorr )
delete

Member Function Documentation

◆ calculateAndSetPosition()

void ECAL2DPositionCalcWithDepthCorr::calculateAndSetPosition ( reco::PFCluster cluster)
overridevirtual

Implements PFCPositionCalculatorBase.

Definition at line 35 of file ECAL2DPositionCalcWithDepthCorr.cc.

35  {
37 }

References calculateAndSetPositionActual().

◆ calculateAndSetPositionActual()

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

Definition at line 45 of file ECAL2DPositionCalcWithDepthCorr.cc.

45  {
46  constexpr double preshowerStartEta = 1.653;
47  constexpr double preshowerEndEta = 2.6;
48  if (!cluster.seed()) {
49  throw cms::Exception("ClusterWithNoSeed") << " Found a cluster with no seed: " << cluster;
50  }
51  double cl_energy = 0;
52  double cl_energy_float = 0;
53  double cl_time = 0;
54  double cl_timeweight = 0.0;
55  double max_e = 0.0;
56  double clusterT0 = 0.0;
57  PFLayer::Layer max_e_layer = PFLayer::NONE;
58  reco::PFRecHitRef refmax;
59  // find the seed and max layer
60  for (const reco::PFRecHitFraction& rhf : cluster.recHitFractions()) {
61  const reco::PFRecHitRef& refhit = rhf.recHitRef();
62  const double rh_fraction = rhf.fraction();
63  const double rh_rawenergy = refhit->energy();
64  const double rh_energy = rh_rawenergy * rh_fraction;
65  const double rh_energyf = ((float)rh_rawenergy) * ((float)rh_fraction);
66  if (!edm::isFinite(rh_energy)) {
67  throw cms::Exception("PFClusterAlgo") << "rechit " << refhit->detId() << " has non-finite energy... "
68  << "The input of the particle flow clustering seems to be corrupted.";
69  }
70  cl_energy += rh_energy;
71  cl_energy_float += rh_energyf;
72  // If time resolution is given, calculate weighted average
73  if (_timeResolutionCalc) {
74  const double res2 = 1. / _timeResolutionCalc->timeResolution2(rh_rawenergy);
75  cl_time += rh_fraction * refhit->time() * res2;
76  cl_timeweight += rh_fraction * res2;
77  } else { // assume resolution ~ 1/E**2
78  const double rh_rawenergy2 = rh_rawenergy * rh_rawenergy;
79  cl_timeweight += rh_rawenergy2 * rh_fraction;
80  cl_time += rh_rawenergy2 * rh_fraction * refhit->time();
81  }
82  if (rh_energy > max_e) {
83  max_e = rh_energy;
84  max_e_layer = rhf.recHitRef()->layer();
85  refmax = refhit;
86  }
87  }
88  cluster.setEnergy(cl_energy);
89  cluster.setTime(cl_time / cl_timeweight);
90  if (_timeResolutionCalc) {
91  cluster.setTimeError(std::sqrt(1.0f / float(cl_timeweight)));
92  }
93  cluster.setLayer(max_e_layer);
94  const CaloSubdetectorGeometry* ecal_geom = nullptr;
95  // get seed geometry information
96  switch (max_e_layer) {
98  ecal_geom = _ebGeom;
99  clusterT0 = _param_T0_EB;
100  break;
102  ecal_geom = _eeGeom;
103  clusterT0 = _param_T0_EE;
104  break;
105  default:
106  throw cms::Exception("InvalidLayer") << "ECAL Position Calc only accepts ECAL_BARREL or ECAL_ENDCAP";
107  }
108 
109  auto center_cell = ecal_geom->getGeometry(refmax->detId());
110  const double ctreta = center_cell->etaPos();
111  const double actreta = std::abs(ctreta);
112  // need to change T0 if in ES
113  if (actreta > preshowerStartEta && actreta < preshowerEndEta) {
114  if (ctreta > 0 && _esPlus)
115  clusterT0 = _param_T0_ES;
116  if (ctreta < 0 && _esMinus)
117  clusterT0 = _param_T0_ES;
118  }
119  // floats to reproduce exactly the EGM code
120  const float maxDepth = _param_X0 * (clusterT0 + vdt::fast_log(cl_energy_float));
121  const float maxToFront = center_cell->getPosition().mag();
122  // calculate the position
123  const double logETot_inv = -vdt::fast_log(cl_energy_float);
124  double position_norm = 0.0;
125  double x(0.0), y(0.0), z(0.0);
126  for (const reco::PFRecHitFraction& rhf : cluster.recHitFractions()) {
127  double weight = 0.0;
128  const reco::PFRecHitRef& refhit = rhf.recHitRef();
129  const double rh_energy = ((float)refhit->energy()) * ((float)rhf.fraction());
130  if (rh_energy > 0.0)
131  weight = std::max(0.0, (_param_W0 + vdt::fast_log(rh_energy) + logETot_inv));
132  auto cell = ecal_geom->getGeometry(refhit->detId());
133  const float depth = maxDepth + maxToFront - cell->getPosition().mag();
134  const GlobalPoint pos = static_cast<const TruncatedPyramid*>(cell.get())->getPosition(depth);
135 
136  x += weight * pos.x();
137  y += weight * pos.y();
138  z += weight * pos.z();
139 
140  position_norm += weight;
141  }
142 
143  // FALL BACK to LINEAR WEIGHTS
144  if (position_norm == 0.) {
145  for (const reco::PFRecHitFraction& rhf : cluster.recHitFractions()) {
146  double weight = 0.0;
147  const reco::PFRecHitRef& refhit = rhf.recHitRef();
148  const double rh_energy = ((float)refhit->energy()) * ((float)rhf.fraction());
149  if (rh_energy > 0.0)
150  weight = rh_energy / cluster.energy();
151 
152  auto cell = ecal_geom->getGeometry(refhit->detId());
153  const float depth = maxDepth + maxToFront - cell->getPosition().mag();
154  const GlobalPoint pos = cell->getPosition(depth);
155 
156  x += weight * pos.x();
157  y += weight * pos.y();
158  z += weight * pos.z();
159 
160  position_norm += weight;
161  }
162  }
163 
164  if (position_norm < _minAllowedNorm) {
165  edm::LogError("WeirdClusterNormalization") << "PFCluster too far from seeding cell: set position to (0,0,0).";
166  cluster.setPosition(math::XYZPoint(0, 0, 0));
167  } else {
168  const double norm_inverse = 1.0 / position_norm;
169  x *= norm_inverse;
170  y *= norm_inverse;
171  z *= norm_inverse;
172 
173  cluster.setPosition(math::XYZPoint(x, y, z));
174  cluster.calculatePositionREP();
175  }
176 }

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(), LEDCalibrationChannels::depth, PFLayer::ECAL_BARREL, PFLayer::ECAL_ENDCAP, reco::PFCluster::energy(), Exception, f, dqmMemoryStats::float, CaloSubdetectorGeometry::getGeometry(), edm::isFinite(), SiStripPI::max, HLT_FULL_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().

◆ calculateAndSetPositions()

void ECAL2DPositionCalcWithDepthCorr::calculateAndSetPositions ( reco::PFClusterCollection clusters)
overridevirtual

Implements PFCPositionCalculatorBase.

Definition at line 39 of file ECAL2DPositionCalcWithDepthCorr.cc.

39  {
40  for (reco::PFCluster& cluster : clusters) {
42  }
43 }

References calculateAndSetPositionActual(), and bsc_activity_cfg::clusters.

◆ operator=()

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

◆ update()

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

Reimplemented from PFCPositionCalculatorBase.

Definition at line 18 of file ECAL2DPositionCalcWithDepthCorr.cc.

18  {
19  const CaloGeometryRecord& caloGeom = es.get<CaloGeometryRecord>();
21  caloGeom.get(geohandle);
22  _ebGeom = geohandle->getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
23  _eeGeom = geohandle->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
24  _esGeom = geohandle->getSubdetectorGeometry(DetId::Ecal, EcalPreshower);
25  if (_esGeom) {
26  // ripped from RecoEcal/EgammaCoreTools
27  for (uint32_t ic = 0; ic < _esGeom->getValidDetIds().size() && (!_esPlus || !_esMinus); ++ic) {
28  const double z = _esGeom->getGeometry(_esGeom->getValidDetIds()[ic])->getPosition().z();
29  _esPlus = _esPlus || (0 < z);
30  _esMinus = _esMinus || (0 > z);
31  }
32  }
33 }

References _ebGeom, _eeGeom, _esGeom, _esMinus, _esPlus, DetId::Ecal, EcalBarrel, EcalEndcap, EcalPreshower, edm::EventSetup::get(), edm::eventsetup::DependentRecordImplementation< RecordT, ListT >::get(), CaloSubdetectorGeometry::getGeometry(), CaloSubdetectorGeometry::getValidDetIds(), and z.

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

Member Data Documentation

◆ _ebGeom

const CaloSubdetectorGeometry* ECAL2DPositionCalcWithDepthCorr::_ebGeom
private

Definition at line 55 of file ECAL2DPositionCalcWithDepthCorr.h.

Referenced by calculateAndSetPositionActual(), and update().

◆ _eeGeom

const CaloSubdetectorGeometry* ECAL2DPositionCalcWithDepthCorr::_eeGeom
private

Definition at line 56 of file ECAL2DPositionCalcWithDepthCorr.h.

Referenced by calculateAndSetPositionActual(), and update().

◆ _esGeom

const CaloSubdetectorGeometry* ECAL2DPositionCalcWithDepthCorr::_esGeom
private

Definition at line 57 of file ECAL2DPositionCalcWithDepthCorr.h.

Referenced by update().

◆ _esMinus

bool ECAL2DPositionCalcWithDepthCorr::_esMinus
private

Definition at line 58 of file ECAL2DPositionCalcWithDepthCorr.h.

Referenced by calculateAndSetPositionActual(), and update().

◆ _esPlus

bool ECAL2DPositionCalcWithDepthCorr::_esPlus
private

Definition at line 58 of file ECAL2DPositionCalcWithDepthCorr.h.

Referenced by calculateAndSetPositionActual(), and update().

◆ _minAllowedNorm

const double ECAL2DPositionCalcWithDepthCorr::_minAllowedNorm
private

Definition at line 52 of file ECAL2DPositionCalcWithDepthCorr.h.

Referenced by calculateAndSetPositionActual().

◆ _param_T0_EB

const double ECAL2DPositionCalcWithDepthCorr::_param_T0_EB
private

Definition at line 47 of file ECAL2DPositionCalcWithDepthCorr.h.

Referenced by calculateAndSetPositionActual().

◆ _param_T0_EE

const double ECAL2DPositionCalcWithDepthCorr::_param_T0_EE
private

Definition at line 48 of file ECAL2DPositionCalcWithDepthCorr.h.

Referenced by calculateAndSetPositionActual().

◆ _param_T0_ES

const double ECAL2DPositionCalcWithDepthCorr::_param_T0_ES
private

Definition at line 49 of file ECAL2DPositionCalcWithDepthCorr.h.

Referenced by calculateAndSetPositionActual().

◆ _param_W0

const double ECAL2DPositionCalcWithDepthCorr::_param_W0
private

Definition at line 50 of file ECAL2DPositionCalcWithDepthCorr.h.

Referenced by calculateAndSetPositionActual().

◆ _param_X0

const double ECAL2DPositionCalcWithDepthCorr::_param_X0
private

Definition at line 51 of file ECAL2DPositionCalcWithDepthCorr.h.

Referenced by calculateAndSetPositionActual().

◆ _timeResolutionCalc

std::unique_ptr<CaloRecHitResolutionProvider> ECAL2DPositionCalcWithDepthCorr::_timeResolutionCalc
private
CaloRecHitResolutionProvider
Definition: CaloRecHitResolutionProvider.h:8
DDAxes::y
ECAL2DPositionCalcWithDepthCorr::_param_X0
const double _param_X0
Definition: ECAL2DPositionCalcWithDepthCorr.h:51
reco::PFCluster::setTime
void setTime(float time, float timeError=0)
Definition: PFCluster.h:84
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
ECAL2DPositionCalcWithDepthCorr::_minAllowedNorm
const double _minAllowedNorm
Definition: ECAL2DPositionCalcWithDepthCorr.h:52
ECAL2DPositionCalcWithDepthCorr::_timeResolutionCalc
std::unique_ptr< CaloRecHitResolutionProvider > _timeResolutionCalc
Definition: ECAL2DPositionCalcWithDepthCorr.h:60
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
reco::PFRecHitFraction
Fraction of a PFRecHit (rechits can be shared between several PFCluster's)
Definition: PFRecHitFraction.h:18
ECAL2DPositionCalcWithDepthCorr::_esPlus
bool _esPlus
Definition: ECAL2DPositionCalcWithDepthCorr.h:58
CaloGeometryRecord
Definition: CaloGeometryRecord.h:30
mps_merge.weight
weight
Definition: mps_merge.py:88
pos
Definition: PixelAliasList.h:18
reco::PFCluster::setLayer
void setLayer(PFLayer::Layer layer)
set layer
Definition: PFCluster.cc:49
reco::PFCluster::recHitFractions
const std::vector< reco::PFRecHitFraction > & recHitFractions() const
vector of rechit fractions
Definition: PFCluster.h:65
DDAxes::x
ECAL2DPositionCalcWithDepthCorr::_param_T0_EB
const double _param_T0_EB
Definition: ECAL2DPositionCalcWithDepthCorr.h:47
EcalBarrel
Definition: EcalSubdetector.h:10
HLT_FULL_cff.maxDepth
maxDepth
Definition: HLT_FULL_cff.py:8732
edm::Ref< PFRecHitCollection >
PFLayer::ECAL_BARREL
Definition: PFLayer.h:33
ECAL2DPositionCalcWithDepthCorr::_esMinus
bool _esMinus
Definition: ECAL2DPositionCalcWithDepthCorr.h:58
reco::PFCluster::energy
double energy() const
cluster energy
Definition: PFCluster.h:74
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
ECAL2DPositionCalcWithDepthCorr::_esGeom
const CaloSubdetectorGeometry * _esGeom
Definition: ECAL2DPositionCalcWithDepthCorr.h:57
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
DDAxes::z
edm::ESHandle< CaloGeometry >
PFLayer::NONE
Definition: PFLayer.h:34
Point3DBase< float, GlobalTag >
edm::eventsetup::DependentRecordImplementation::get
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
Definition: DependentRecordImplementation.h:103
CaloSubdetectorGeometry::getValidDetIds
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)
Definition: CaloSubdetectorGeometry.cc:32
ECAL2DPositionCalcWithDepthCorr::_ebGeom
const CaloSubdetectorGeometry * _ebGeom
Definition: ECAL2DPositionCalcWithDepthCorr.h:55
reco::CaloCluster::setPosition
void setPosition(const math::XYZPoint &p)
Definition: CaloCluster.h:140
LEDCalibrationChannels.depth
depth
Definition: LEDCalibrationChannels.py:65
PFLayer::Layer
Layer
layer definition
Definition: PFLayer.h:29
EcalEndcap
Definition: EcalSubdetector.h:10
bsc_activity_cfg.clusters
clusters
Definition: bsc_activity_cfg.py:36
edm::ParameterSet::exists
bool exists(std::string const &parameterName) const
checks if a parameter exists
Definition: ParameterSet.cc:681
edm::ParameterSet
Definition: ParameterSet.h:47
math::XYZPoint
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
reco::PFCluster::calculatePositionREP
void calculatePositionREP()
computes posrep_ once and for all
Definition: PFCluster.h:95
PFCPositionCalculatorBase::PFCPositionCalculatorBase
PFCPositionCalculatorBase(const edm::ParameterSet &conf)
Definition: PFCPositionCalculatorBase.h:18
ECAL2DPositionCalcWithDepthCorr::_param_T0_ES
const double _param_T0_ES
Definition: ECAL2DPositionCalcWithDepthCorr.h:49
CaloSubdetectorGeometry::getGeometry
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.
Definition: CaloSubdetectorGeometry.cc:36
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
DetId::Ecal
Definition: DetId.h:27
reco::CaloCluster::seed
DetId seed() const
return DetId of seed
Definition: CaloCluster.h:219
EcalPreshower
Definition: EcalSubdetector.h:10
ECAL2DPositionCalcWithDepthCorr::_eeGeom
const CaloSubdetectorGeometry * _eeGeom
Definition: ECAL2DPositionCalcWithDepthCorr.h:56
reco::CaloCluster::setEnergy
void setEnergy(double energy)
Definition: CaloCluster.h:136
ECAL2DPositionCalcWithDepthCorr::_param_T0_EE
const double _param_T0_EE
Definition: ECAL2DPositionCalcWithDepthCorr.h:48
Exception
Definition: hltDiff.cc:246
reco::PFCluster
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:42
reco::PFCluster::setTimeError
void setTimeError(float timeError)
Definition: PFCluster.h:88
CaloSubdetectorGeometry
Definition: CaloSubdetectorGeometry.h:22
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::isFinite
constexpr bool isFinite(T x)
PFLayer::ECAL_ENDCAP
Definition: PFLayer.h:32
ECAL2DPositionCalcWithDepthCorr::_param_W0
const double _param_W0
Definition: ECAL2DPositionCalcWithDepthCorr.h:50
weight
Definition: weight.py:1
edm::ParameterSet::getParameterSet
ParameterSet const & getParameterSet(std::string const &) const
Definition: ParameterSet.cc:2128
ECAL2DPositionCalcWithDepthCorr::calculateAndSetPositionActual
void calculateAndSetPositionActual(reco::PFCluster &) const
Definition: ECAL2DPositionCalcWithDepthCorr.cc:45