CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
Basic2DGenericPFlowPositionCalc Class Reference
Inheritance diagram for Basic2DGenericPFlowPositionCalc:
PFCPositionCalculatorBase

Public Member Functions

 Basic2DGenericPFlowPositionCalc (const edm::ParameterSet &conf, edm::ConsumesCollector &cc)
 
 Basic2DGenericPFlowPositionCalc (const Basic2DGenericPFlowPositionCalc &)=delete
 
void calculateAndSetPosition (reco::PFCluster &) override
 
void calculateAndSetPositions (reco::PFClusterCollection &) override
 
Basic2DGenericPFlowPositionCalcoperator= (const Basic2DGenericPFlowPositionCalc &)=delete
 
- 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 void update (const edm::EventSetup &)
 
virtual ~PFCPositionCalculatorBase ()=default
 

Private Member Functions

void calculateAndSetPositionActual (reco::PFCluster &) const
 

Private Attributes

std::tuple< std::vector< int >, std::vector< int >, std::vector< float > > _logWeightDenom
 
const float _minAllowedNorm
 
const int _posCalcNCrystals
 
std::unique_ptr< CaloRecHitResolutionProvider_timeResolutionCalcBarrel
 
std::unique_ptr< CaloRecHitResolutionProvider_timeResolutionCalcEndcap
 

Additional Inherited Members

- Protected Attributes inherited from PFCPositionCalculatorBase
const float _minFractionInCalc
 

Detailed Description

Definition at line 19 of file Basic2DGenericPFlowPositionCalc.cc.

Constructor & Destructor Documentation

◆ Basic2DGenericPFlowPositionCalc() [1/2]

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

Definition at line 21 of file Basic2DGenericPFlowPositionCalc.cc.

References _logWeightDenom, _posCalcNCrystals, _timeResolutionCalcBarrel, _timeResolutionCalcEndcap, cms::cuda::assert(), HLT_2022v15_cff::depths, HLT_2022v15_cff::detectorEnum, Exception, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterSet(), edm::ParameterSet::getParameterSetVector(), mps_fire::i, muonDTDigis_cfi::pset, and AlCaHLTBitMon_QueryRunRegistry::string.

23  _posCalcNCrystals(conf.getParameter<int>("posCalcNCrystals")),
24  _minAllowedNorm(conf.getParameter<double>("minAllowedNormalization")) {
25  std::vector<int> detectorEnum;
26  std::vector<int> depths;
27  std::vector<double> logWeightDenom;
28  std::vector<float> logWeightDenomInv;
29 
30  if (conf.exists("logWeightDenominatorByDetector")) {
31  const std::vector<edm::ParameterSet>& logWeightDenominatorByDetectorPSet =
32  conf.getParameterSetVector("logWeightDenominatorByDetector");
33 
34  for (const auto& pset : logWeightDenominatorByDetectorPSet) {
35  if (!pset.exists("detector")) {
36  throw cms::Exception("logWeightDenominatorByDetectorPSet") << "logWeightDenominator : detector not specified";
37  }
38 
39  const std::string& det = pset.getParameter<std::string>("detector");
40 
41  if (det == std::string("HCAL_BARREL1") || det == std::string("HCAL_ENDCAP")) {
42  std::vector<int> depthsT = pset.getParameter<std::vector<int> >("depths");
43  std::vector<double> logWeightDenomT = pset.getParameter<std::vector<double> >("logWeightDenominator");
44  if (logWeightDenomT.size() != depthsT.size()) {
45  throw cms::Exception("logWeightDenominator") << "logWeightDenominator mismatch with the numbers of depths";
46  }
47  for (unsigned int i = 0; i < depthsT.size(); ++i) {
48  if (det == std::string("HCAL_BARREL1"))
49  detectorEnum.push_back(1);
50  if (det == std::string("HCAL_ENDCAP"))
51  detectorEnum.push_back(2);
52  depths.push_back(depthsT[i]);
53  logWeightDenom.push_back(logWeightDenomT[i]);
54  }
55  }
56  }
57  } else {
58  detectorEnum.push_back(0);
59  depths.push_back(0);
60  logWeightDenom.push_back(conf.getParameter<double>("logWeightDenominator"));
61  }
62 
63  for (unsigned int i = 0; i < depths.size(); ++i) {
64  logWeightDenomInv.push_back(1. / logWeightDenom[i]);
65  }
66 
67  // _logWeightDenom = std::make_pair(depths,logWeightDenomInv);
68  _logWeightDenom = std::make_tuple(detectorEnum, depths, logWeightDenomInv);
69 
70  _timeResolutionCalcBarrel.reset(nullptr);
71  if (conf.exists("timeResolutionCalcBarrel")) {
72  const edm::ParameterSet& timeResConf = conf.getParameterSet("timeResolutionCalcBarrel");
73  _timeResolutionCalcBarrel = std::make_unique<CaloRecHitResolutionProvider>(timeResConf);
74  }
75  _timeResolutionCalcEndcap.reset(nullptr);
76  if (conf.exists("timeResolutionCalcEndcap")) {
77  const edm::ParameterSet& timeResConf = conf.getParameterSet("timeResolutionCalcEndcap");
78  _timeResolutionCalcEndcap = std::make_unique<CaloRecHitResolutionProvider>(timeResConf);
79  }
80 
81  switch (_posCalcNCrystals) {
82  case 5:
83  case 9:
84  case -1:
85  break;
86  default:
87  edm::LogError("Basic2DGenericPFlowPositionCalc") << "posCalcNCrystals not valid";
88  assert(0); // bug
89  }
90  }
PFCPositionCalculatorBase(const edm::ParameterSet &conf, edm::ConsumesCollector &cc)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
bool exists(std::string const &parameterName) const
checks if a parameter exists
ParameterSet const & getParameterSet(std::string const &) const
Log< level::Error, false > LogError
assert(be >=bs)
std::unique_ptr< CaloRecHitResolutionProvider > _timeResolutionCalcBarrel
std::tuple< std::vector< int >, std::vector< int >, std::vector< float > > _logWeightDenom
std::unique_ptr< CaloRecHitResolutionProvider > _timeResolutionCalcEndcap
VParameterSet const & getParameterSetVector(std::string const &name) const

◆ Basic2DGenericPFlowPositionCalc() [2/2]

Basic2DGenericPFlowPositionCalc::Basic2DGenericPFlowPositionCalc ( const Basic2DGenericPFlowPositionCalc )
delete

Member Function Documentation

◆ calculateAndSetPosition()

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

Implements PFCPositionCalculatorBase.

Definition at line 118 of file Basic2DGenericPFlowPositionCalc.cc.

References calculateAndSetPositionActual().

118  {
120 }
void calculateAndSetPositionActual(reco::PFCluster &) const

◆ calculateAndSetPositionActual()

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

Definition at line 128 of file Basic2DGenericPFlowPositionCalc.cc.

References _logWeightDenom, _minAllowedNorm, PFCPositionCalculatorBase::_minFractionInCalc, _posCalcNCrystals, _timeResolutionCalcBarrel, _timeResolutionCalcEndcap, a, b, electrons_cff::bool, reco::PFCluster::calculatePositionREP(), bookConverter::compute(), declareDynArray, LEDCalibrationChannels::depth, reco::PFRecHit::depth(), HLT_2022v15_cff::detectorEnum, reco::PFRecHit::detId(), HCALHighEnergyHPDFilter_cfi::energy, Exception, f, myMath::fast_logf(), dqmMemoryStats::float, HLT_2022v15_cff::fraction, PFLayer::HCAL_BARREL1, PFLayer::HCAL_ENDCAP, photonIsolationHIProducer_cfi::hf, hfClusterShapes_cfi::hits, mps_fire::i, createfilelist::int, PixelPluginsPhase0_cfi::isBarrel, edm::isNotFinite(), dqmiolumiharvest::j, dqmdumpme::k, reco::PFRecHit::layer(), SiStripPI::max, ecalTB2006H4_GenSimDigiReco_cfg::mySeed, nhits, PFLayer::NONE, AlCaHLTBitMon_ParallelJobs::p, reco::PFRecHit::position(), reco::PFCluster::recHitFractions(), reco::CaloCluster::seed(), DBoxMetadataHelper::set_intersection(), reco::PFCluster::setDepth(), reco::CaloCluster::setEnergy(), reco::PFCluster::setLayer(), reco::CaloCluster::setPosition(), reco::PFCluster::setTime(), reco::PFCluster::setTimeError(), jetUpdater_cfi::sort, mathSSE::sqrt(), remoteMonitoring_LASER_era2018_cfg::threshold, reco::PFRecHit::time(), mitigatedMETSequence_cff::U, unInitDynArray, UNLIKELY, x, y, and z.

Referenced by calculateAndSetPosition(), and calculateAndSetPositions().

128  {
129  if (!cluster.seed()) {
130  throw cms::Exception("ClusterWithNoSeed") << " Found a cluster with no seed: " << cluster;
131  }
132  double cl_energy = 0;
133  double cl_time = 0;
134  double cl_timeweight = 0.0;
135  double max_e = 0.0;
136  PFLayer::Layer max_e_layer = PFLayer::NONE;
137  // find the seed and max layer and also calculate time
138  //Michalis : Even if we dont use timing in clustering here we should fill
139  //the time information for the cluster. This should use the timing resolution(1/E)
140  //so the weight should be fraction*E^2
141  //calculate a simplistic depth now. The log weighted will be done
142  //in different stage
143 
144  auto const recHitCollection =
145  &(*cluster.recHitFractions()[0].recHitRef()) - cluster.recHitFractions()[0].recHitRef().key();
146  auto nhits = cluster.recHitFractions().size();
147  struct LHit {
148  reco::PFRecHit const* hit;
149  float energy;
150  float fraction;
151  };
152  declareDynArray(LHit, nhits, hits);
153  for (auto i = 0U; i < nhits; ++i) {
154  auto const& hf = cluster.recHitFractions()[i];
155  auto k = hf.recHitRef().key();
156  auto p = recHitCollection + k;
157  hits[i] = {p, (*p).energy(), float(hf.fraction())};
158  }
159 
161  LHit mySeed = {};
162  for (auto const& rhf : hits) {
163  const reco::PFRecHit& refhit = *rhf.hit;
164  if (refhit.detId() == cluster.seed())
165  mySeed = rhf;
166  const auto rh_fraction = rhf.fraction;
167  const auto rh_rawenergy = rhf.energy;
168  const auto rh_energy = rh_rawenergy * rh_fraction;
169 #ifdef PF_DEBUG
170  if UNLIKELY (edm::isNotFinite(rh_energy)) {
171  throw cms::Exception("PFClusterAlgo") << "rechit " << refhit.detId() << " has a NaN energy... "
172  << "The input of the particle flow clustering seems to be corrupted.";
173  }
174 #endif
175  cl_energy += rh_energy;
176  // If time resolution is given, calculated weighted average
177  if (resGiven) {
178  double res2 = 1.e-4;
179  int cell_layer = (int)refhit.layer();
180  res2 = isBarrel(cell_layer) ? 1. / _timeResolutionCalcBarrel->timeResolution2(rh_rawenergy)
181  : 1. / _timeResolutionCalcEndcap->timeResolution2(rh_rawenergy);
182  cl_time += rh_fraction * refhit.time() * res2;
183  cl_timeweight += rh_fraction * res2;
184  } else { // assume resolution = 1/E**2
185  const double rh_rawenergy2 = rh_rawenergy * rh_rawenergy;
186  cl_timeweight += rh_rawenergy2 * rh_fraction;
187  cl_time += rh_rawenergy2 * rh_fraction * refhit.time();
188  }
189 
190  if (rh_energy > max_e) {
191  max_e = rh_energy;
192  max_e_layer = refhit.layer();
193  }
194  }
195 
196  cluster.setEnergy(cl_energy);
197  cluster.setTime(cl_time / cl_timeweight);
198  if (resGiven) {
199  cluster.setTimeError(std::sqrt(1.0f / float(cl_timeweight)));
200  }
201  cluster.setLayer(max_e_layer);
202 
203  // calculate the position
204  bool single_depth = true;
205  int ref_depth = -1;
206  double depth = 0.0;
207  double position_norm = 0.0;
208  double x(0.0), y(0.0), z(0.0);
209  if (nullptr != mySeed.hit) {
210  auto seedNeighbours = mySeed.hit->neighbours();
211  switch (_posCalcNCrystals) {
212  case 5:
213  seedNeighbours = mySeed.hit->neighbours4();
214  break;
215  case 9:
216  seedNeighbours = mySeed.hit->neighbours8();
217  break;
218  default:
219  break;
220  }
221 
222  auto compute = [&](LHit const& rhf) {
223  const reco::PFRecHit& refhit = *rhf.hit;
224 
225  int cell_layer = (int)refhit.layer();
226  float threshold = 0;
227 
228  for (unsigned int j = 0; j < (std::get<2>(_logWeightDenom)).size(); ++j) {
229  // barrel is detecor type1
230  int detectorEnum = std::get<0>(_logWeightDenom)[j];
231  int depth = std::get<1>(_logWeightDenom)[j];
232 
233  if ((cell_layer == PFLayer::HCAL_BARREL1 && detectorEnum == 1 && refhit.depth() == depth) ||
234  (cell_layer == PFLayer::HCAL_ENDCAP && detectorEnum == 2 && refhit.depth() == depth) || detectorEnum == 0)
235  threshold = std::get<2>(_logWeightDenom)[j];
236  }
237 
238  if (ref_depth < 0)
239  ref_depth = refhit.depth(); // Initialize reference depth
240  else if (refhit.depth() != ref_depth) {
241  // Found a rechit with a different depth
242  single_depth = false;
243  }
244  const auto rh_energy = rhf.energy * rhf.fraction;
245  const auto norm =
246  (rhf.fraction < _minFractionInCalc ? 0.0f : std::max(0.0f, vdt::fast_logf(rh_energy * threshold)));
247  const auto rhpos_xyz = refhit.position() * norm;
248  x += rhpos_xyz.x();
249  y += rhpos_xyz.y();
250  z += rhpos_xyz.z();
251  depth += refhit.depth() * norm;
252  position_norm += norm;
253  };
254 
255  if (_posCalcNCrystals != -1) // sorted to make neighbour search faster (maybe)
256  std::sort(hits.begin(), hits.end(), [](LHit const& a, LHit const& b) { return a.hit < b.hit; });
257 
258  if (_posCalcNCrystals == -1)
259  for (auto const& rhf : hits)
260  compute(rhf);
261  else { // only seed and its neighbours
262  compute(mySeed);
263  // search seedNeighbours to find energy fraction in cluster (sic)
264  unInitDynArray(reco::PFRecHit const*, seedNeighbours.size(), nei);
265  for (auto k : seedNeighbours) {
266  nei.push_back(recHitCollection + k);
267  }
268  std::sort(nei.begin(), nei.end());
269  struct LHitLess {
270  auto operator()(LHit const& a, reco::PFRecHit const* b) const { return a.hit < b; }
271  auto operator()(reco::PFRecHit const* b, LHit const& a) const { return b < a.hit; }
272  };
274  hits.begin(), hits.end(), nei.begin(), nei.end(), boost::make_function_output_iterator(compute), LHitLess());
275  }
276  } else {
277  throw cms::Exception("Basic2DGenerticPFlowPositionCalc")
278  << "Cluster seed hit is null, something is wrong with PFlow RecHit!";
279  }
280 
281  if (position_norm < _minAllowedNorm) {
282  edm::LogError("WeirdClusterNormalization") << "PFCluster too far from seeding cell: set position to (0,0,0).";
283  cluster.setPosition(math::XYZPoint(0, 0, 0));
284  cluster.calculatePositionREP();
285  } else {
286  const double norm_inverse = 1.0 / position_norm;
287  x *= norm_inverse;
288  y *= norm_inverse;
289  z *= norm_inverse;
290  if (single_depth)
291  depth = ref_depth;
292  else
293  depth *= norm_inverse;
294  cluster.setPosition(math::XYZPoint(x, y, z));
295  cluster.setDepth(depth);
296  cluster.calculatePositionREP();
297  }
298 }
void setLayer(PFLayer::Layer layer)
set layer
Definition: PFCluster.cc:49
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
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
PFLayer::Layer layer() const
rechit layer
Definition: PFRecHit.h:96
const std::vector< reco::PFRecHitFraction > & recHitFractions() const
vector of rechit fractions
Definition: PFCluster.h:65
void setEnergy(double energy)
Definition: CaloCluster.h:136
float time() const
timing for cleaned hits
Definition: PFRecHit.h:102
Log< level::Error, false > LogError
PositionType const & position() const
rechit cell centre x, y, z
Definition: PFRecHit.h:117
unsigned detId() const
rechit detId
Definition: PFRecHit.h:93
Particle flow rechit (rechit + geometry and topology information). See clustering algorithm in PFClus...
Definition: PFRecHit.h:31
void calculatePositionREP()
computes posrep_ once and for all
Definition: PFCluster.h:95
T sqrt(T t)
Definition: SSEVec.h:19
#define unInitDynArray(T, n, x)
Definition: DynArray.h:88
double f[11][100]
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
def compute(min, max)
std::unique_ptr< CaloRecHitResolutionProvider > _timeResolutionCalcBarrel
double b
Definition: hdecay.h:118
std::tuple< std::vector< int >, std::vector< int >, std::vector< float > > _logWeightDenom
std::unique_ptr< CaloRecHitResolutionProvider > _timeResolutionCalcEndcap
double a
Definition: hdecay.h:119
void setDepth(double depth)
Definition: PFCluster.h:89
#define declareDynArray(T, n, x)
Definition: DynArray.h:91
int depth() const
depth for segemntation
Definition: PFRecHit.h:105
#define UNLIKELY(x)
Definition: Likely.h:21
float fast_logf(float x)
std::vector< std::string > set_intersection(std::vector< std::string > const &v1, std::vector< std::string > const &v2)

◆ calculateAndSetPositions()

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

Implements PFCPositionCalculatorBase.

Definition at line 122 of file Basic2DGenericPFlowPositionCalc.cc.

References calculateAndSetPositionActual(), and bsc_activity_cfg::clusters.

122  {
123  for (reco::PFCluster& cluster : clusters) {
125  }
126 }
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:42
void calculateAndSetPositionActual(reco::PFCluster &) const

◆ operator=()

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

Member Data Documentation

◆ _logWeightDenom

std::tuple<std::vector<int>, std::vector<int>, std::vector<float> > Basic2DGenericPFlowPositionCalc::_logWeightDenom
private

◆ _minAllowedNorm

const float Basic2DGenericPFlowPositionCalc::_minAllowedNorm
private

Definition at line 101 of file Basic2DGenericPFlowPositionCalc.cc.

Referenced by calculateAndSetPositionActual().

◆ _posCalcNCrystals

const int Basic2DGenericPFlowPositionCalc::_posCalcNCrystals
private

◆ _timeResolutionCalcBarrel

std::unique_ptr<CaloRecHitResolutionProvider> Basic2DGenericPFlowPositionCalc::_timeResolutionCalcBarrel
private

◆ _timeResolutionCalcEndcap

std::unique_ptr<CaloRecHitResolutionProvider> Basic2DGenericPFlowPositionCalc::_timeResolutionCalcEndcap
private