CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
Basic2DGenericPFlowClusterizer Class Reference
Inheritance diagram for Basic2DGenericPFlowClusterizer:
PFClusterBuilderBase

Public Member Functions

 Basic2DGenericPFlowClusterizer (const edm::ParameterSet &conf, edm::ConsumesCollector &cc)
 
 Basic2DGenericPFlowClusterizer (const B2DGPF &)=delete
 
void buildClusters (const reco::PFClusterCollection &, const std::vector< bool > &, reco::PFClusterCollection &outclus) override
 
B2DGPFoperator= (const B2DGPF &)=delete
 
void update (const edm::EventSetup &es) override
 
 ~Basic2DGenericPFlowClusterizer () override=default
 
- Public Member Functions inherited from PFClusterBuilderBase
std::ostream & operator<< (std::ostream &o) const
 
PFCBBoperator= (const PFCBB &)=delete
 
 PFClusterBuilderBase (const edm::ParameterSet &conf, edm::ConsumesCollector &cc)
 
 PFClusterBuilderBase (const PFCBB &)=delete
 
void reset ()
 
virtual ~PFClusterBuilderBase ()=default
 

Private Types

typedef Basic2DGenericPFlowClusterizer B2DGPF
 

Private Member Functions

void growPFClusters (const reco::PFCluster &, const std::vector< bool > &, const unsigned toleranceScaling, const unsigned iter, double dist, reco::PFClusterCollection &) const
 
void prunePFClusters (reco::PFClusterCollection &) const
 
void seedPFClustersFromTopo (const reco::PFCluster &, const std::vector< bool > &, reco::PFClusterCollection &) const
 

Private Attributes

std::unique_ptr< PFCPositionCalculatorBase_allCellsPosCalc
 
std::unique_ptr< PFCPositionCalculatorBase_convergencePosCalc
 
const bool _excludeOtherSeeds
 
const std::unordered_map< std::string, int > _layerMap
 
const unsigned _maxIterations
 
const double _minFracTot
 
std::unordered_map< int, std::pair< std::vector< int >, std::vector< double > > > _recHitEnergyNorms
 
const double _showerSigma2
 
const double _stoppingTolerance
 

Additional Inherited Members

- Public Types inherited from PFClusterBuilderBase
typedef PFCPositionCalculatorBase PosCalc
 
- Protected Attributes inherited from PFClusterBuilderBase
const float _minFractionToKeep
 
unsigned _nClustersFound
 
unsigned _nSeeds
 
std::unique_ptr< PosCalc_positionCalc
 

Detailed Description

Definition at line 14 of file Basic2DGenericPFlowClusterizer.cc.

Member Typedef Documentation

◆ B2DGPF

Definition at line 15 of file Basic2DGenericPFlowClusterizer.cc.

Constructor & Destructor Documentation

◆ Basic2DGenericPFlowClusterizer() [1/2]

Basic2DGenericPFlowClusterizer::Basic2DGenericPFlowClusterizer ( const edm::ParameterSet conf,
edm::ConsumesCollector cc 
)

Definition at line 74 of file Basic2DGenericPFlowClusterizer.cc.

References PFLayer::ECAL_BARREL, PFLayer::ECAL_ENDCAP, PFLayer::HCAL_BARREL1, PFLayer::HCAL_BARREL2, PFLayer::HCAL_ENDCAP, PFLayer::HF_EM, PFLayer::HF_HAD, createfilelist::int, PFLayer::NONE, PFLayer::PS1, and PFLayer::PS2.

76  : PFClusterBuilderBase(conf, cc),
77  _maxIterations(conf.getParameter<unsigned>("maxIterations")),
78  _stoppingTolerance(conf.getParameter<double>("stoppingTolerance")),
79  _showerSigma2(std::pow(conf.getParameter<double>("showerSigma"), 2.0)),
80  _excludeOtherSeeds(conf.getParameter<bool>("excludeOtherSeeds")),
81  _minFracTot(conf.getParameter<double>("minFracTot")),
82  _layerMap({{"PS2", (int)PFLayer::PS2},
83  {"PS1", (int)PFLayer::PS1},
84  {"ECAL_ENDCAP", (int)PFLayer::ECAL_ENDCAP},
85  {"ECAL_BARREL", (int)PFLayer::ECAL_BARREL},
86  {"NONE", (int)PFLayer::NONE},
87  {"HCAL_BARREL1", (int)PFLayer::HCAL_BARREL1},
88  {"HCAL_BARREL2_RING0", (int)PFLayer::HCAL_BARREL2},
89  {"HCAL_BARREL2_RING1", 100 * (int)PFLayer::HCAL_BARREL2},
90  {"HCAL_ENDCAP", (int)PFLayer::HCAL_ENDCAP},
91  {"HF_EM", (int)PFLayer::HF_EM},
92  {"HF_HAD", (int)PFLayer::HF_HAD}}) {
93  const std::vector<edm::ParameterSet>& thresholds = conf.getParameterSetVector("recHitEnergyNorms");
94  for (const auto& pset : thresholds) {
95  const std::string& det = pset.getParameter<std::string>("detector");
96 
97  std::vector<int> depths;
98  std::vector<double> rhE_norm;
99 
100  if (det == std::string("HCAL_BARREL1") || det == std::string("HCAL_ENDCAP")) {
101  depths = pset.getParameter<std::vector<int> >("depths");
102  rhE_norm = pset.getParameter<std::vector<double> >("recHitEnergyNorm");
103  } else {
104  depths.push_back(0);
105  rhE_norm.push_back(pset.getParameter<double>("recHitEnergyNorm"));
106  }
107 
108  if (rhE_norm.size() != depths.size()) {
109  throw cms::Exception("InvalidPFRecHitThreshold")
110  << "PFlowClusterizerThreshold mismatch with the numbers of depths";
111  }
112 
113  auto entry = _layerMap.find(det);
114  if (entry == _layerMap.end()) {
115  throw cms::Exception("InvalidDetectorLayer") << "Detector layer : " << det << " is not in the list of recognized"
116  << " detector layers!";
117  }
118  _recHitEnergyNorms.emplace(_layerMap.find(det)->second, std::make_pair(depths, rhE_norm));
119  }
120 
121  if (conf.exists("allCellsPositionCalc")) {
122  const edm::ParameterSet& acConf = conf.getParameterSet("allCellsPositionCalc");
123  const std::string& algoac = acConf.getParameter<std::string>("algoName");
124  _allCellsPosCalc = PFCPositionCalculatorFactory::get()->create(algoac, acConf, cc);
125  }
126  // if necessary a third pos calc for convergence testing
127  if (conf.exists("positionCalcForConvergence")) {
128  const edm::ParameterSet& convConf = conf.getParameterSet("positionCalcForConvergence");
129  const std::string& algoconv = convConf.getParameter<std::string>("algoName");
130  _convergencePosCalc = PFCPositionCalculatorFactory::get()->create(algoconv, convConf, cc);
131  }
132 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
bool exists(std::string const &parameterName) const
checks if a parameter exists
ParameterSet const & getParameterSet(std::string const &) const
const std::unordered_map< std::string, int > _layerMap
std::unique_ptr< PFCPositionCalculatorBase > _convergencePosCalc
std::unique_ptr< PFCPositionCalculatorBase > _allCellsPosCalc
std::unordered_map< int, std::pair< std::vector< int >, std::vector< double > > > _recHitEnergyNorms
VParameterSet const & getParameterSetVector(std::string const &name) const
PFClusterBuilderBase(const edm::ParameterSet &conf, edm::ConsumesCollector &cc)
#define get
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ ~Basic2DGenericPFlowClusterizer()

Basic2DGenericPFlowClusterizer::~Basic2DGenericPFlowClusterizer ( )
overridedefault

◆ Basic2DGenericPFlowClusterizer() [2/2]

Basic2DGenericPFlowClusterizer::Basic2DGenericPFlowClusterizer ( const B2DGPF )
delete

Member Function Documentation

◆ buildClusters()

void Basic2DGenericPFlowClusterizer::buildClusters ( const reco::PFClusterCollection input,
const std::vector< bool > &  seedable,
reco::PFClusterCollection outclus 
)
overridevirtual

Implements PFClusterBuilderBase.

Definition at line 134 of file Basic2DGenericPFlowClusterizer.cc.

References _allCellsPosCalc, _convergencePosCalc, PFClusterBuilderBase::_positionCalc, growPFClusters(), input, SiStripPI::max, eostools::move(), convertSQLitetoXML_cfg::output, funct::pow(), prunePFClusters(), and seedPFClustersFromTopo().

136  {
137  reco::PFClusterCollection clustersInTopo;
138  for (const auto& topocluster : input) {
139  clustersInTopo.clear();
140  seedPFClustersFromTopo(topocluster, seedable, clustersInTopo);
141  const unsigned tolScal = std::pow(std::max(1.0, clustersInTopo.size() - 1.0), 2.0);
142  growPFClusters(topocluster, seedable, tolScal, 0, tolScal, clustersInTopo);
143  // step added by Josh Bendavid, removes low-fraction clusters
144  // did not impact position resolution with fraction cut of 1e-7
145  // decreases the size of each pf cluster considerably
146  prunePFClusters(clustersInTopo);
147  // recalculate the positions of the pruned clusters
148  if (_convergencePosCalc) {
149  // if defined, use the special position calculation for convergence tests
150  _convergencePosCalc->calculateAndSetPositions(clustersInTopo);
151  } else {
152  if (clustersInTopo.size() == 1 && _allCellsPosCalc) {
153  _allCellsPosCalc->calculateAndSetPosition(clustersInTopo.back());
154  } else {
155  _positionCalc->calculateAndSetPositions(clustersInTopo);
156  }
157  }
158  for (auto& clusterout : clustersInTopo) {
159  output.insert(output.end(), std::move(clusterout));
160  }
161  }
162 }
void growPFClusters(const reco::PFCluster &, const std::vector< bool > &, const unsigned toleranceScaling, const unsigned iter, double dist, reco::PFClusterCollection &) const
std::unique_ptr< PosCalc > _positionCalc
std::unique_ptr< PFCPositionCalculatorBase > _convergencePosCalc
static std::string const input
Definition: EdmProvDump.cc:47
std::unique_ptr< PFCPositionCalculatorBase > _allCellsPosCalc
void prunePFClusters(reco::PFClusterCollection &) const
void seedPFClustersFromTopo(const reco::PFCluster &, const std::vector< bool > &, reco::PFClusterCollection &) const
std::vector< PFCluster > PFClusterCollection
collection of PFCluster objects
Definition: PFClusterFwd.h:9
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
def move(src, dest)
Definition: eostools.py:511

◆ growPFClusters()

void Basic2DGenericPFlowClusterizer::growPFClusters ( const reco::PFCluster topo,
const std::vector< bool > &  seedable,
const unsigned  toleranceScaling,
const unsigned  iter,
double  dist,
reco::PFClusterCollection clusters 
) const
private

Definition at line 183 of file Basic2DGenericPFlowClusterizer.cc.

References _allCellsPosCalc, _convergencePosCalc, _excludeOtherSeeds, _maxIterations, _minFracTot, PFClusterBuilderBase::_positionCalc, _recHitEnergyNorms, _showerSigma2, _stoppingTolerance, funct::abs(), bsc_activity_cfg::clusters, reco::deltaR2(), LEDCalibrationChannels::depth, change_name::diff, myMath::fast_expf(), DivergingColor::frac, HLT_2022v11_cff::fraction, PFLayer::HCAL_BARREL1, PFLayer::HCAL_BARREL2, PFLayer::HCAL_ENDCAP, mps_fire::i, createfilelist::int, dqmiolumiharvest::j, edm::Ref< C, T, F >::key(), LOGDRESSED, HLT_2022v11_cff::recHitEnergyNorm, reco::PFCluster::recHitFractions(), and mathSSE::sqrt().

Referenced by buildClusters().

188  {
189  if (iter >= _maxIterations) {
190  LOGDRESSED("Basic2DGenericPFlowClusterizer:growAndStabilizePFClusters")
191  << "reached " << _maxIterations << " iterations, terminated position "
192  << "fit with diff = " << diff;
193  }
194  if (iter >= _maxIterations || diff <= _stoppingTolerance * toleranceScaling)
195  return;
196  // reset the rechits in this cluster, keeping the previous position
197  std::vector<reco::PFCluster::REPPoint> clus_prev_pos;
198  for (auto& cluster : clusters) {
199  const reco::PFCluster::REPPoint& repp = cluster.positionREP();
200  clus_prev_pos.emplace_back(repp.rho(), repp.eta(), repp.phi());
201  if (_convergencePosCalc) {
202  if (clusters.size() == 1 && _allCellsPosCalc) {
203  _allCellsPosCalc->calculateAndSetPosition(cluster);
204  } else {
205  _positionCalc->calculateAndSetPosition(cluster);
206  }
207  }
208  cluster.resetHitsAndFractions();
209  }
210  // loop over topo cluster and grow current PFCluster hypothesis
211  std::vector<double> dist2, frac;
212  double fractot = 0;
213  for (const reco::PFRecHitFraction& rhf : topo.recHitFractions()) {
214  const reco::PFRecHitRef& refhit = rhf.recHitRef();
215  int cell_layer = (int)refhit->layer();
216  if (cell_layer == PFLayer::HCAL_BARREL2 && std::abs(refhit->positionREP().eta()) > 0.34) {
217  cell_layer *= 100;
218  }
219 
220  math::XYZPoint topocellpos_xyz(refhit->position());
221  dist2.clear();
222  frac.clear();
223  fractot = 0;
224 
225  double recHitEnergyNorm = 0.;
226  auto const& recHitEnergyNormDepthPair = _recHitEnergyNorms.find(cell_layer)->second;
227 
228  for (unsigned int j = 0; j < recHitEnergyNormDepthPair.second.size(); ++j) {
229  int depth = recHitEnergyNormDepthPair.first[j];
230 
231  if ((cell_layer == PFLayer::HCAL_BARREL1 && refhit->depth() == depth) ||
232  (cell_layer == PFLayer::HCAL_ENDCAP && refhit->depth() == depth) ||
233  (cell_layer != PFLayer::HCAL_ENDCAP && cell_layer != PFLayer::HCAL_BARREL1))
234  recHitEnergyNorm = recHitEnergyNormDepthPair.second[j];
235  }
236 
237  // add rechits to clusters, calculating fraction based on distance
238  for (auto& cluster : clusters) {
239  const math::XYZPoint& clusterpos_xyz = cluster.position();
240  const math::XYZVector deltav = clusterpos_xyz - topocellpos_xyz;
241  const double d2 = deltav.Mag2() / _showerSigma2;
242  dist2.emplace_back(d2);
243  if (d2 > 100) {
244  LOGDRESSED("Basic2DGenericPFlowClusterizer:growAndStabilizePFClusters")
245  << "Warning! :: pfcluster-topocell distance is too large! d= " << d2;
246  }
247 
248  // fraction assignment logic
249  double fraction;
250  if (refhit->detId() == cluster.seed() && _excludeOtherSeeds) {
251  fraction = 1.0;
252  } else if (seedable[refhit.key()] && _excludeOtherSeeds) {
253  fraction = 0.0;
254  } else {
255  fraction = cluster.energy() / recHitEnergyNorm * vdt::fast_expf(-0.5 * d2);
256  }
257  fractot += fraction;
258  frac.emplace_back(fraction);
259  }
260  for (unsigned i = 0; i < clusters.size(); ++i) {
261  if (fractot > _minFracTot || (refhit->detId() == clusters[i].seed() && fractot > 0.0)) {
262  frac[i] /= fractot;
263  } else {
264  continue;
265  }
266  // if the fraction has been set to 0, the cell
267  // is now added to the cluster - careful ! (PJ, 19/07/08)
268  // BUT KEEP ONLY CLOSE CELLS OTHERWISE MEMORY JUST EXPLOSES
269  // (PJ, 15/09/08 <- similar to what existed before the
270  // previous bug fix, but keeps the close seeds inside,
271  // even if their fraction was set to zero.)
272  // Also add a protection to keep the seed in the cluster
273  // when the latter gets far from the former. These cases
274  // (about 1% of the clusters) need to be studied, as
275  // they create fake photons, in general.
276  // (PJ, 16/09/08)
277  if (dist2[i] < 100.0 || frac[i] > 0.9999) {
278  clusters[i].addRecHitFraction(reco::PFRecHitFraction(refhit, frac[i]));
279  }
280  }
281  }
282  // recalculate positions and calculate convergence parameter
283  double diff2 = 0.0;
284  for (unsigned i = 0; i < clusters.size(); ++i) {
285  if (_convergencePosCalc) {
286  _convergencePosCalc->calculateAndSetPosition(clusters[i]);
287  } else {
288  if (clusters.size() == 1 && _allCellsPosCalc) {
289  _allCellsPosCalc->calculateAndSetPosition(clusters[i]);
290  } else {
291  _positionCalc->calculateAndSetPosition(clusters[i]);
292  }
293  }
294  const double delta2 = reco::deltaR2(clusters[i].positionREP(), clus_prev_pos[i]);
295  if (delta2 > diff2)
296  diff2 = delta2;
297  }
298  diff = std::sqrt(diff2);
299  dist2.clear();
300  frac.clear();
301  clus_prev_pos.clear(); // avoid badness
302  growPFClusters(topo, seedable, toleranceScaling, iter + 1, diff, clusters);
303 }
void growPFClusters(const reco::PFCluster &, const std::vector< bool > &, const unsigned toleranceScaling, const unsigned iter, double dist, reco::PFClusterCollection &) const
std::unique_ptr< PosCalc > _positionCalc
Fraction of a PFRecHit (rechits can be shared between several PFCluster&#39;s)
const std::vector< reco::PFRecHitFraction > & recHitFractions() const
vector of rechit fractions
Definition: PFCluster.h:65
std::unique_ptr< PFCPositionCalculatorBase > _convergencePosCalc
#define LOGDRESSED(x)
key_type key() const
Accessor for product key.
Definition: Ref.h:250
std::unique_ptr< PFCPositionCalculatorBase > _allCellsPosCalc
T sqrt(T t)
Definition: SSEVec.h:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
std::unordered_map< int, std::pair< std::vector< int >, std::vector< double > > > _recHitEnergyNorms
float fast_expf(float x)
ROOT::Math::PositionVector3D< ROOT::Math::CylindricalEta3D< double > > REPPoint
Definition: PFCluster.h:48

◆ operator=()

B2DGPF& Basic2DGenericPFlowClusterizer::operator= ( const B2DGPF )
delete

◆ prunePFClusters()

void Basic2DGenericPFlowClusterizer::prunePFClusters ( reco::PFClusterCollection clusters) const
private

Definition at line 305 of file Basic2DGenericPFlowClusterizer.cc.

References PFClusterBuilderBase::_minFractionToKeep, bsc_activity_cfg::clusters, and reco::PFRecHitFraction::fraction().

Referenced by buildClusters().

305  {
306  for (auto& cluster : clusters) {
307  cluster.pruneUsing([&](const reco::PFRecHitFraction& rhf) { return rhf.fraction() > _minFractionToKeep; });
308  }
309 }
Fraction of a PFRecHit (rechits can be shared between several PFCluster&#39;s)

◆ seedPFClustersFromTopo()

void Basic2DGenericPFlowClusterizer::seedPFClustersFromTopo ( const reco::PFCluster topo,
const std::vector< bool > &  seedable,
reco::PFClusterCollection initialPFClusters 
) const
private

Definition at line 164 of file Basic2DGenericPFlowClusterizer.cc.

References _convergencePosCalc, PFClusterBuilderBase::_positionCalc, reco::PFCluster::addRecHitFraction(), reco::PFCluster::recHitFractions(), and reco::CaloCluster::setSeed().

Referenced by buildClusters().

166  {
167  const auto& recHitFractions = topo.recHitFractions();
168  for (const auto& rhf : recHitFractions) {
169  if (!seedable[rhf.recHitRef().key()])
170  continue;
171  initialPFClusters.push_back(reco::PFCluster());
172  reco::PFCluster& current = initialPFClusters.back();
173  current.addRecHitFraction(rhf);
174  current.setSeed(rhf.recHitRef()->detId());
175  if (_convergencePosCalc) {
176  _convergencePosCalc->calculateAndSetPosition(current);
177  } else {
178  _positionCalc->calculateAndSetPosition(current);
179  }
180  }
181 }
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
Definition: PFCluster.h:42
std::unique_ptr< PosCalc > _positionCalc
const std::vector< reco::PFRecHitFraction > & recHitFractions() const
vector of rechit fractions
Definition: PFCluster.h:65
std::unique_ptr< PFCPositionCalculatorBase > _convergencePosCalc
void setSeed(const DetId &id)
Definition: CaloCluster.h:146
void addRecHitFraction(const reco::PFRecHitFraction &frac)
add a given fraction of the rechit
Definition: PFCluster.cc:33

◆ update()

void Basic2DGenericPFlowClusterizer::update ( const edm::EventSetup es)
inlineoverridevirtual

Member Data Documentation

◆ _allCellsPosCalc

std::unique_ptr<PFCPositionCalculatorBase> Basic2DGenericPFlowClusterizer::_allCellsPosCalc
private

Definition at line 45 of file Basic2DGenericPFlowClusterizer.cc.

Referenced by buildClusters(), growPFClusters(), and update().

◆ _convergencePosCalc

std::unique_ptr<PFCPositionCalculatorBase> Basic2DGenericPFlowClusterizer::_convergencePosCalc
private

◆ _excludeOtherSeeds

const bool Basic2DGenericPFlowClusterizer::_excludeOtherSeeds
private

Definition at line 40 of file Basic2DGenericPFlowClusterizer.cc.

Referenced by growPFClusters().

◆ _layerMap

const std::unordered_map<std::string, int> Basic2DGenericPFlowClusterizer::_layerMap
private

Definition at line 42 of file Basic2DGenericPFlowClusterizer.cc.

◆ _maxIterations

const unsigned Basic2DGenericPFlowClusterizer::_maxIterations
private

Definition at line 37 of file Basic2DGenericPFlowClusterizer.cc.

Referenced by growPFClusters().

◆ _minFracTot

const double Basic2DGenericPFlowClusterizer::_minFracTot
private

Definition at line 41 of file Basic2DGenericPFlowClusterizer.cc.

Referenced by growPFClusters().

◆ _recHitEnergyNorms

std::unordered_map<int, std::pair<std::vector<int>, std::vector<double> > > Basic2DGenericPFlowClusterizer::_recHitEnergyNorms
private

Definition at line 44 of file Basic2DGenericPFlowClusterizer.cc.

Referenced by growPFClusters().

◆ _showerSigma2

const double Basic2DGenericPFlowClusterizer::_showerSigma2
private

Definition at line 39 of file Basic2DGenericPFlowClusterizer.cc.

Referenced by growPFClusters().

◆ _stoppingTolerance

const double Basic2DGenericPFlowClusterizer::_stoppingTolerance
private

Definition at line 38 of file Basic2DGenericPFlowClusterizer.cc.

Referenced by growPFClusters().