CMS 3D CMS Logo

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

#include <Basic2DGenericPFlowPositionCalc.h>

Inheritance diagram for Basic2DGenericPFlowPositionCalc:
PFCPositionCalculatorBase

Public Member Functions

 Basic2DGenericPFlowPositionCalc (const edm::ParameterSet &conf)
 
 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)
 
 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 13 of file Basic2DGenericPFlowPositionCalc.h.

Constructor & Destructor Documentation

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

Definition at line 15 of file Basic2DGenericPFlowPositionCalc.h.

References _logWeightDenom, _posCalcNCrystals, _timeResolutionCalcBarrel, _timeResolutionCalcEndcap, calculateAndSetPosition(), calculateAndSetPositions(), customizeHLTforCMSSW::depths, HLT_2018_cff::detectorEnum, Exception, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterSet(), edm::ParameterSet::getParameterSetVector(), mps_fire::i, operator=(), muonDTDigis_cfi::pset, and AlCaHLTBitMon_QueryRunRegistry::string.

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

Member Function Documentation

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

Implements PFCPositionCalculatorBase.

Definition at line 20 of file Basic2DGenericPFlowPositionCalc.cc.

References calculateAndSetPositionActual().

Referenced by Basic2DGenericPFlowPositionCalc().

20  {
22 }
void calculateAndSetPositionActual(reco::PFCluster &) const
void Basic2DGenericPFlowPositionCalc::calculateAndSetPositionActual ( reco::PFCluster cluster) const
private

Definition at line 30 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_2018_cff::detectorEnum, reco::PFRecHit::detId(), HCALHighEnergyHPDFilter_cfi::energy, Exception, f, myMath::fast_logf(), dqmMemoryStats::float, HLT_2018_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(), reco::PFCluster::setDepth(), reco::CaloCluster::setEnergy(), reco::PFCluster::setLayer(), reco::CaloCluster::setPosition(), reco::PFCluster::setTime(), reco::PFCluster::setTimeError(), mathSSE::sqrt(), MessageLogger_cff::threshold, reco::PFRecHit::time(), mitigatedMETSequence_cff::U, unInitDynArray, UNLIKELY, x, y, and z.

Referenced by calculateAndSetPosition(), and calculateAndSetPositions().

30  {
31  if (!cluster.seed()) {
32  throw cms::Exception("ClusterWithNoSeed") << " Found a cluster with no seed: " << cluster;
33  }
34  double cl_energy = 0;
35  double cl_time = 0;
36  double cl_timeweight = 0.0;
37  double max_e = 0.0;
38  PFLayer::Layer max_e_layer = PFLayer::NONE;
39  // find the seed and max layer and also calculate time
40  //Michalis : Even if we dont use timing in clustering here we should fill
41  //the time information for the cluster. This should use the timing resolution(1/E)
42  //so the weight should be fraction*E^2
43  //calculate a simplistic depth now. The log weighted will be done
44  //in different stage
45 
46  auto const recHitCollection =
47  &(*cluster.recHitFractions()[0].recHitRef()) - cluster.recHitFractions()[0].recHitRef().key();
48  auto nhits = cluster.recHitFractions().size();
49  struct LHit {
50  reco::PFRecHit const* hit;
51  float energy;
52  float fraction;
53  };
54  declareDynArray(LHit, nhits, hits);
55  for (auto i = 0U; i < nhits; ++i) {
56  auto const& hf = cluster.recHitFractions()[i];
57  auto k = hf.recHitRef().key();
58  auto p = recHitCollection + k;
59  hits[i] = {p, (*p).energy(), float(hf.fraction())};
60  }
61 
63  LHit mySeed = {};
64  for (auto const& rhf : hits) {
65  const reco::PFRecHit& refhit = *rhf.hit;
66  if (refhit.detId() == cluster.seed())
67  mySeed = rhf;
68  const auto rh_fraction = rhf.fraction;
69  const auto rh_rawenergy = rhf.energy;
70  const auto rh_energy = rh_rawenergy * rh_fraction;
71 #ifdef PF_DEBUG
72  if
73  UNLIKELY(edm::isNotFinite(rh_energy)) {
74  throw cms::Exception("PFClusterAlgo") << "rechit " << refhit.detId() << " has a NaN energy... "
75  << "The input of the particle flow clustering seems to be corrupted.";
76  }
77 #endif
78  cl_energy += rh_energy;
79  // If time resolution is given, calculated weighted average
80  if (resGiven) {
81  double res2 = 1.e-4;
82  int cell_layer = (int)refhit.layer();
83  res2 = isBarrel(cell_layer) ? 1. / _timeResolutionCalcBarrel->timeResolution2(rh_rawenergy)
84  : 1. / _timeResolutionCalcEndcap->timeResolution2(rh_rawenergy);
85  cl_time += rh_fraction * refhit.time() * res2;
86  cl_timeweight += rh_fraction * res2;
87  } else { // assume resolution = 1/E**2
88  const double rh_rawenergy2 = rh_rawenergy * rh_rawenergy;
89  cl_timeweight += rh_rawenergy2 * rh_fraction;
90  cl_time += rh_rawenergy2 * rh_fraction * refhit.time();
91  }
92 
93  if (rh_energy > max_e) {
94  max_e = rh_energy;
95  max_e_layer = refhit.layer();
96  }
97  }
98 
99  cluster.setEnergy(cl_energy);
100  cluster.setTime(cl_time / cl_timeweight);
101  if (resGiven) {
102  cluster.setTimeError(std::sqrt(1.0f / float(cl_timeweight)));
103  }
104  cluster.setLayer(max_e_layer);
105 
106  // calculate the position
107  double depth = 0.0;
108  double position_norm = 0.0;
109  double x(0.0), y(0.0), z(0.0);
110  if (nullptr != mySeed.hit) {
111  auto seedNeighbours = mySeed.hit->neighbours();
112  switch (_posCalcNCrystals) {
113  case 5:
114  seedNeighbours = mySeed.hit->neighbours4();
115  break;
116  case 9:
117  seedNeighbours = mySeed.hit->neighbours8();
118  break;
119  default:
120  break;
121  }
122 
123  auto compute = [&](LHit const& rhf) {
124  const reco::PFRecHit& refhit = *rhf.hit;
125 
126  int cell_layer = (int)refhit.layer();
127  float threshold = 0;
128 
129  for (unsigned int j = 0; j < (std::get<2>(_logWeightDenom)).size(); ++j) {
130  // barrel is detecor type1
131  int detectorEnum = std::get<0>(_logWeightDenom)[j];
132  int depth = std::get<1>(_logWeightDenom)[j];
133 
134  if ((cell_layer == PFLayer::HCAL_BARREL1 && detectorEnum == 1 && refhit.depth() == depth) ||
135  (cell_layer == PFLayer::HCAL_ENDCAP && detectorEnum == 2 && refhit.depth() == depth) || detectorEnum == 0)
136  threshold = std::get<2>(_logWeightDenom)[j];
137  }
138 
139  const auto rh_energy = rhf.energy * rhf.fraction;
140  const auto norm =
141  (rhf.fraction < _minFractionInCalc ? 0.0f : std::max(0.0f, vdt::fast_logf(rh_energy * threshold)));
142  const auto rhpos_xyz = refhit.position() * norm;
143  x += rhpos_xyz.x();
144  y += rhpos_xyz.y();
145  z += rhpos_xyz.z();
146  depth += refhit.depth() * norm;
147  position_norm += norm;
148  };
149 
150  if (_posCalcNCrystals != -1) // sorted to make neighbour search faster (maybe)
151  std::sort(hits.begin(), hits.end(), [](LHit const& a, LHit const& b) { return a.hit < b.hit; });
152 
153  if (_posCalcNCrystals == -1)
154  for (auto const& rhf : hits)
155  compute(rhf);
156  else { // only seed and its neighbours
157  compute(mySeed);
158  // search seedNeighbours to find energy fraction in cluster (sic)
159  unInitDynArray(reco::PFRecHit const*, seedNeighbours.size(), nei);
160  for (auto k : seedNeighbours) {
161  nei.push_back(recHitCollection + k);
162  }
163  std::sort(nei.begin(), nei.end());
164  struct LHitLess {
165  auto operator()(LHit const& a, reco::PFRecHit const* b) const { return a.hit < b; }
166  auto operator()(reco::PFRecHit const* b, LHit const& a) const { return b < a.hit; }
167  };
168  std::set_intersection(
169  hits.begin(), hits.end(), nei.begin(), nei.end(), boost::make_function_output_iterator(compute), LHitLess());
170  }
171  } else {
172  throw cms::Exception("Basic2DGenerticPFlowPositionCalc")
173  << "Cluster seed hit is null, something is wrong with PFlow RecHit!";
174  }
175 
176  if (position_norm < _minAllowedNorm) {
177  edm::LogError("WeirdClusterNormalization") << "PFCluster too far from seeding cell: set position to (0,0,0).";
178  cluster.setPosition(math::XYZPoint(0, 0, 0));
179  cluster.calculatePositionREP();
180  } else {
181  const double norm_inverse = 1.0 / position_norm;
182  x *= norm_inverse;
183  y *= norm_inverse;
184  z *= norm_inverse;
185  depth *= norm_inverse;
186  cluster.setPosition(math::XYZPoint(x, y, z));
187  cluster.setDepth(depth);
188  cluster.calculatePositionREP();
189  }
190 }
#define declareDynArray(T, n, x)
Definition: DynArray.h:91
void setLayer(PFLayer::Layer layer)
set layer
Definition: PFCluster.cc:93
float time() const
timing for cleaned hits
Definition: PFRecHit.h:98
unsigned detId() const
rechit detId
Definition: PFRecHit.h:89
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
void setPosition(const math::XYZPoint &p)
Definition: CaloCluster.h:139
void setTime(float time, float timeError=0)
Definition: PFCluster.h:88
void setEnergy(double energy)
Definition: CaloCluster.h:135
PositionType const & position() const
rechit cell centre x, y, z
Definition: PFRecHit.h:107
int depth() const
depth for segemntation
Definition: PFRecHit.h:101
PFLayer::Layer layer() const
rechit layer
Definition: PFRecHit.h:92
#define unInitDynArray(T, n, x)
Definition: DynArray.h:88
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:99
T sqrt(T t)
Definition: SSEVec.h:19
double f[11][100]
Layer
layer definition
Definition: PFLayer.h:29
void setTimeError(float timeError)
Definition: PFCluster.h:92
DetId seed() const
return DetId of seed
Definition: CaloCluster.h:218
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
const std::vector< reco::PFRecHitFraction > & recHitFractions() const
vector of rechit fractions
Definition: PFCluster.h:69
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:93
#define UNLIKELY(x)
Definition: Likely.h:21
float fast_logf(float x)
void Basic2DGenericPFlowPositionCalc::calculateAndSetPositions ( reco::PFClusterCollection clusters)
overridevirtual

Implements PFCPositionCalculatorBase.

Definition at line 24 of file Basic2DGenericPFlowPositionCalc.cc.

References calculateAndSetPositionActual().

Referenced by Basic2DGenericPFlowPositionCalc().

24  {
25  for (reco::PFCluster& cluster : clusters) {
27  }
28 }
void calculateAndSetPositionActual(reco::PFCluster &) const
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:46
Basic2DGenericPFlowPositionCalc& Basic2DGenericPFlowPositionCalc::operator= ( const Basic2DGenericPFlowPositionCalc )
delete

Member Data Documentation

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

Definition at line 95 of file Basic2DGenericPFlowPositionCalc.h.

Referenced by calculateAndSetPositionActual().

const int Basic2DGenericPFlowPositionCalc::_posCalcNCrystals
private
std::unique_ptr<CaloRecHitResolutionProvider> Basic2DGenericPFlowPositionCalc::_timeResolutionCalcBarrel
private
std::unique_ptr<CaloRecHitResolutionProvider> Basic2DGenericPFlowPositionCalc::_timeResolutionCalcEndcap
private