CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Attributes
l1tpf_calo::SingleCaloClusterer Class Reference

#include <CaloClusterer.h>

Public Member Functions

void add (const reco::Candidate &c)
 
void add (float pt, float eta, float phi)
 
void clear ()
 
const Clustercluster (int i) const
 
const std::vector< Cluster > & clusters () const
 
template<typename Corrector >
void correct (const Corrector &corrector)
 
std::unique_ptr< l1t::PFClusterCollectionfetch (float ptMin=0.) const
 
std::unique_ptr< l1t::PFClusterCollectionfetch (const edm::OrphanHandle< l1t::PFClusterCollection > &cells, float ptMin=0.) const
 
std::unique_ptr< l1t::PFClusterCollectionfetchCells (bool unclusteredOnly=false, float ptMin=0.) const
 
void grow ()
 possibly grow clusters by adding unclustered energy on the sides More...
 
const IndexGridindexGrid () const
 
const EtGridraw () const
 
EtGridraw ()
 non-const access to the energy: be careful to use it only before 'run()' More...
 
void run ()
 
 SingleCaloClusterer (const edm::ParameterSet &pset)
 
 ~SingleCaloClusterer ()
 

Private Types

enum  EnergyShareAlgo { EnergyShareAlgo::Fractions, EnergyShareAlgo::None, EnergyShareAlgo::Greedy, EnergyShareAlgo::Crude }
 

Private Attributes

IndexGrid cellKey_
 
IndexGrid clusterIndex_
 
std::vector< Clusterclusters_
 
EnergyShareAlgo energyShareAlgo_
 
bool energyWeightedPosition_
 
const Gridgrid_
 
float minClusterEt_
 
float minEtToGrow_
 
const Cluster nullCluster_
 
PreClusterGrid precluster_
 
EtGrid rawet_
 
float seedEt_
 
EtGrid unclustered_
 
float zsEt_
 

Detailed Description

Definition at line 180 of file CaloClusterer.h.

Member Enumeration Documentation

◆ EnergyShareAlgo

Enumerator
Fractions 
None 
Greedy 
Crude 

Definition at line 218 of file CaloClusterer.h.

218  {
219  Fractions, /* each local maximum neighbour takes a share proportional to its value */
220  None, /* each local maximum neighbour takes all the value (double counting!) */
221  Greedy, /* assing cell to the highest local maximum neighbour */
222  Crude
223  }; /* if there's more than one local maximum neighbour, they all take half of the value (no fp division) */

Constructor & Destructor Documentation

◆ SingleCaloClusterer()

l1tpf_calo::SingleCaloClusterer::SingleCaloClusterer ( const edm::ParameterSet pset)

Definition at line 166 of file CaloClusterer.cc.

References Crude, pfClustersFromCombinedCaloHCal_cfi::energyShareAlgo, energyShareAlgo_, Exception, Fractions, Greedy, None, muonDTDigis_cfi::pset, and AlCaHLTBitMon_QueryRunRegistry::string.

167  : grid_(getGrid(pset.getParameter<std::string>("grid"))),
168  rawet_(*grid_),
170  precluster_(*grid_),
172  cellKey_(*grid_),
173  clusters_(),
174  nullCluster_(),
175  zsEt_(pset.getParameter<double>("zsEt")),
176  seedEt_(pset.getParameter<double>("seedEt")),
177  minClusterEt_(pset.getParameter<double>("minClusterEt")),
178  minEtToGrow_(pset.existsAs<double>("minEtToGrow") ? pset.getParameter<double>("minEtToGrow") : -1),
179  energyWeightedPosition_(pset.getParameter<bool>("energyWeightedPosition")) {
180  std::string energyShareAlgo = pset.getParameter<std::string>("energyShareAlgo");
181  if (energyShareAlgo == "fractions")
183  else if (energyShareAlgo == "none")
185  else if (energyShareAlgo == "greedy")
187  else if (energyShareAlgo == "crude")
189  else
190  throw cms::Exception("Configuration") << "Unsupported energyShareAlgo '" << energyShareAlgo << "'\n";
191 }
std::vector< Cluster > clusters_
const Grid * getGrid(const std::string &type)

◆ ~SingleCaloClusterer()

l1tpf_calo::SingleCaloClusterer::~SingleCaloClusterer ( )

Definition at line 193 of file CaloClusterer.cc.

193 {}

Member Function Documentation

◆ add() [1/2]

void l1tpf_calo::SingleCaloClusterer::add ( const reco::Candidate c)
inline

◆ add() [2/2]

void l1tpf_calo::SingleCaloClusterer::add ( float  pt,
float  eta,
float  phi 
)
inline

◆ clear()

void l1tpf_calo::SingleCaloClusterer::clear ( void  )

Definition at line 195 of file CaloClusterer.cc.

Referenced by L1TPFCaloProducer::produce().

195  {
196  rawet_.zero();
197  clusters_.clear();
198  clusterIndex_.fill(-1);
199 }
void fill(const T &val)
std::vector< Cluster > clusters_

◆ cluster()

const Cluster& l1tpf_calo::SingleCaloClusterer::cluster ( int  i) const
inline

Definition at line 196 of file CaloClusterer.h.

References clusterIndex_, clusters_, mps_fire::i, and nullCluster_.

196  {
197  return (i == -1 || clusterIndex_[i] == -1) ? nullCluster_ : clusters_[clusterIndex_[i]];
198  }
std::vector< Cluster > clusters_

◆ clusters()

const std::vector<Cluster>& l1tpf_calo::SingleCaloClusterer::clusters ( ) const
inline

Definition at line 195 of file CaloClusterer.h.

References clusters_.

195 { return clusters_; }
std::vector< Cluster > clusters_

◆ correct()

template<typename Corrector >
void l1tpf_calo::SingleCaloClusterer::correct ( const Corrector &  corrector)
inline

◆ fetch() [1/2]

std::unique_ptr< l1t::PFClusterCollection > l1tpf_calo::SingleCaloClusterer::fetch ( float  ptMin = 0.) const

Definition at line 385 of file CaloClusterer.cc.

References ptMin, and runTheMatrix::ret.

Referenced by L1TPFCaloProducer::produce().

385  {
386  auto ret = std::make_unique<l1t::PFClusterCollection>();
387  for (const Cluster &cluster : clusters_) {
388  if (cluster.et > ptMin) {
389  ret->emplace_back(cluster.et, cluster.eta, cluster.phi);
390  }
391  }
392  return ret;
393 }
ret
prodAgent to be discontinued
constexpr float ptMin
std::vector< Cluster > clusters_
const Cluster & cluster(int i) const

◆ fetch() [2/2]

std::unique_ptr< l1t::PFClusterCollection > l1tpf_calo::SingleCaloClusterer::fetch ( const edm::OrphanHandle< l1t::PFClusterCollection > &  cells,
float  ptMin = 0. 
) const

Definition at line 395 of file CaloClusterer.cc.

References cells, ptMin, and runTheMatrix::ret.

396  {
397  auto ret = std::make_unique<l1t::PFClusterCollection>();
398  for (const Cluster &cluster : clusters_) {
399  if (cluster.et > ptMin) {
400  ret->emplace_back(cluster.et, cluster.eta, cluster.phi);
401  for (const auto &pair : cluster.constituents) {
402  edm::Ptr<l1t::PFCluster> ref(cells, cellKey_[pair.first]);
403  ret->back().addConstituent(ref, pair.second);
404  }
405  }
406  }
407  return ret;
408 }
ret
prodAgent to be discontinued
constexpr float ptMin
std::vector< Cluster > clusters_
std::vector< std::pair< int, float > > constituents
caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple const cms::cuda::AtomicPairCounter GPUCACell const *__restrict__ cells
const Cluster & cluster(int i) const

◆ fetchCells()

std::unique_ptr< l1t::PFClusterCollection > l1tpf_calo::SingleCaloClusterer::fetchCells ( bool  unclusteredOnly = false,
float  ptMin = 0. 
) const

Definition at line 368 of file CaloClusterer.cc.

References cms::cuda::assert(), mps_fire::i, ptMin, runTheMatrix::ret, and TrackRefitter_38T_cff::src.

Referenced by L1TPFCaloProducer::produce().

369  {
370  auto ret = std::make_unique<l1t::PFClusterCollection>();
371  const EtGrid &src = (unclusteredOnly ? unclustered_ : rawet_);
372  for (unsigned int i = 0, ncells = grid_->size(); i < ncells; ++i) {
373  if (src[i] <= ptMin)
374  continue;
375  if ((unclusteredOnly == false) && (ptMin == 0)) {
376  assert(cellKey_[i] == int(ret->size()));
377  }
378  ret->emplace_back(src[i], grid_->eta(i), grid_->phi(i));
379  ret->back().setHwEta(grid_->ieta(i));
380  ret->back().setHwPhi(grid_->iphi(i));
381  }
382  return ret;
383 }
int iphi(int icell) const
Definition: CaloClusterer.h:33
GridData< float > EtGrid
float eta(int icell) const
Definition: CaloClusterer.h:28
int ieta(int icell) const
Definition: CaloClusterer.h:32
ret
prodAgent to be discontinued
constexpr float ptMin
assert(be >=bs)
float phi(int icell) const
Definition: CaloClusterer.h:29
unsigned int size() const
Definition: CaloClusterer.h:25

◆ grow()

void l1tpf_calo::SingleCaloClusterer::grow ( )

possibly grow clusters by adding unclustered energy on the sides

Definition at line 341 of file CaloClusterer.cc.

References mps_fire::i, and recoMuon::in.

341  {
342  int selneighs[4] = {1, 3, 4, 6}; // -eta, -phi, +phi, +eta
343  std::vector<int> toreset;
344  for (Cluster &cluster : clusters_) {
345  if (cluster.et > minEtToGrow_) {
346  int i = cluster.constituents.front().first;
347  for (int side = 0; side < 4; ++side) {
348  int neigh = grid_->neighbour(i, selneighs[side]);
349  if (neigh == -1)
350  continue;
351  for (int in = 0; in < 8; ++in) {
352  int n2 = grid_->neighbour(neigh, in);
353  if (n2 == -1)
354  continue;
355  cluster.et += unclustered_[n2];
356  if (unclustered_[n2]) {
357  cluster.constituents.emplace_back(n2, 1.0);
358  toreset.push_back(n2);
359  }
360  }
361  }
362  }
363  }
364  for (int i : toreset)
365  unclustered_[i] = 0;
366 }
std::vector< Cluster > clusters_
int neighbour(int icell, unsigned int idx) const
Definition: CaloClusterer.h:27
std::vector< std::pair< int, float > > constituents
const Cluster & cluster(int i) const

◆ indexGrid()

const IndexGrid& l1tpf_calo::SingleCaloClusterer::indexGrid ( ) const
inline

Definition at line 194 of file CaloClusterer.h.

References clusterIndex_.

194 { return clusterIndex_; }

◆ raw() [1/2]

const EtGrid& l1tpf_calo::SingleCaloClusterer::raw ( ) const
inline

Definition at line 193 of file CaloClusterer.h.

References rawet_.

193 { return rawet_; }

◆ raw() [2/2]

EtGrid& l1tpf_calo::SingleCaloClusterer::raw ( )
inline

non-const access to the energy: be careful to use it only before 'run()'

Definition at line 201 of file CaloClusterer.h.

References rawet_.

201 { return rawet_; }

◆ run()

void l1tpf_calo::SingleCaloClusterer::run ( )

Definition at line 201 of file CaloClusterer.cc.

References l1tpf_calo::Cluster::clear(), l1tpf_calo::Cluster::constituents, SiPixelRawToDigiRegional_cfi::deltaPhi, l1tpf_calo::Cluster::et, l1tpf_calo::Cluster::eta, mps_fire::i, crabWrapper::key, SiStripPI::max, HiEvtPlane_cfi::maxet, None, contentValuesFiles::number, l1tpf_calo::Cluster::phi, reco::reduceRange(), and compareTotals::tot.

Referenced by L1TPFCaloProducer::produce().

201  {
202  unsigned int i, ncells = grid_->size();
203 
204  // kill zeros. count non-zeros, for linking later
205  cellKey_.fill(-1);
206  int key = 0;
207  for (i = 0; i < ncells; ++i) {
208  if (rawet_[i] < zsEt_) {
209  rawet_[i] = 0;
210  } else {
211  cellKey_[i] = key++;
212  }
213  }
214 
215  precluster_.clear();
216  // pre-cluster step 1: at each cell, set the value equal to itself if it's a local maxima, zero otherwise
217  // can be done in parallel on all cells
218  for (i = 0; i < ncells; ++i) {
219  if (rawet_[i] > seedEt_) {
220  precluster_[i].ptLocalMax = rawet_[i];
222  //printf(" candidate precluster pt %7.2f at %4d (ieta %+3d iphi %2d)\n", rawet_[i], i, grid_->ieta(i), grid_->iphi(i));
223  for (int ineigh = 0; ineigh <= 3; ++ineigh) {
224  if (rawet_.neigh(i, ineigh) > rawet_[i])
225  precluster_[i].ptLocalMax = 0;
227  //int ncell = grid_->neighbour(i,ineigh);
228  //if (ncell == -1) printf(" \t neigh %d is null\n", ineigh);
229  //else printf(" \t neigh %d at %4d (ieta %+3d iphi %2d) has pt %7.2f: comparison %1d \n", ineigh, ncell, grid_->ieta(ncell), grid_->iphi(ncell), rawet_[ncell], precluster_[i].ptLocalMax > 0);
230  }
231  for (int ineigh = 4; ineigh < 8; ++ineigh) {
232  if (rawet_.neigh(i, ineigh) >= rawet_[i])
233  precluster_[i].ptLocalMax = 0;
235  //int ncell = grid_->neighbour(i,ineigh);
236  //if (ncell == -1) printf(" \t neigh %d is null\n", ineigh);
237  //else printf(" \t neigh %d at %4d (ieta %+3d iphi %2d) has pt %7.2f: comparison %1d \n", ineigh, ncell, grid_->ieta(ncell), grid_->iphi(ncell), rawet_[ncell], precluster_[i].ptLocalMax > 0);
238  }
239  }
240  }
241  // pre-cluster step 2: compute information from neighbouring local max, for energy sharing purposes
242  for (i = 0; i < ncells; ++i) {
243  if (precluster_[i].ptLocalMax == 0) {
244  switch (energyShareAlgo_) {
246  float tot = 0;
247  for (int ineigh = 0; ineigh < 8; ++ineigh) {
248  tot += precluster_.neigh(i, ineigh).ptLocalMax;
249  }
250  precluster_[i].ptOverNeighLocalMaxSum = tot ? rawet_[i] / tot : 0;
251  } break;
253  precluster_[i].ptOverNeighLocalMaxSum = rawet_[i];
254  break;
256  float maxet = 0;
257  for (int ineigh = 0; ineigh < 8; ++ineigh) {
259  }
260  precluster_[i].ptOverNeighLocalMaxSum = maxet;
261  } break;
262  case EnergyShareAlgo::Crude: {
263  int number = 0;
264  for (int ineigh = 0; ineigh < 8; ++ineigh) {
265  number += (precluster_.neigh(i, ineigh).ptLocalMax > 0);
266  }
267  precluster_[i].ptOverNeighLocalMaxSum = (number > 1 ? 0.5 : 1.0) * rawet_[i];
268  } break;
269  }
270  }
271  }
272 
273  clusterIndex_.fill(-1);
274  clusters_.clear();
276  // cluster: at each localMax cell, take itself plus the weighted contributions of the neighbours
277  Cluster cluster;
278  for (i = 0; i < ncells; ++i) {
279  if (precluster_[i].ptLocalMax > 0) {
280  float myet = rawet_[i];
281  float tot = myet;
282  float avg_eta = 0;
283  float avg_phi = 0;
284  cluster.clear();
285  cluster.constituents.emplace_back(i, 1.0);
286  for (int ineigh = 0; ineigh < 8; ++ineigh) {
287  int ineighcell = grid_->neighbour(i, ineigh);
288  if (ineighcell == -1)
289  continue; // skip dummy cells
290  float fracet = 0;
291  switch (energyShareAlgo_) {
293  fracet = myet * precluster_.neigh(i, ineigh).ptOverNeighLocalMaxSum;
294  break;
296  fracet = precluster_.neigh(i, ineigh).ptOverNeighLocalMaxSum;
297  break;
299  fracet = (myet == precluster_.neigh(i, ineigh).ptOverNeighLocalMaxSum ? rawet_.neigh(i, ineigh) : 0);
300  break;
302  fracet = precluster_.neigh(i, ineigh).ptOverNeighLocalMaxSum;
303  break;
304  }
305  if (fracet == 0)
306  continue;
307  tot += fracet;
308  cluster.constituents.emplace_back(ineighcell, fracet / rawet_.neigh(i, ineigh));
310  avg_eta += fracet * (grid_->eta(ineighcell) - grid_->eta(i));
311  avg_phi += fracet * deltaPhi(grid_->phi(ineighcell), grid_->phi(i));
312  }
313  }
314  if (tot > minClusterEt_) {
315  cluster.et = tot;
316  unclustered_[i] = 0;
317  for (int ineigh = 0; ineigh < 8; ++ineigh) {
318  int ineighcell = grid_->neighbour(i, ineigh);
319  if (ineighcell == -1)
320  continue; // skip dummy cells
321  unclustered_[ineighcell] = 0;
322  }
324  cluster.eta = grid_->eta(i) + avg_eta / tot;
325  cluster.phi = grid_->phi(i) + avg_phi / tot;
326  // wrap around phi
328  } else {
329  cluster.eta = grid_->eta(i);
330  cluster.phi = grid_->phi(i);
331  }
332  clusterIndex_[i] = clusters_.size();
333  clusters_.push_back(cluster);
334  }
335  }
336  }
337  if (minEtToGrow_ > 0)
338  grow();
339 }
float eta(int icell) const
Definition: CaloClusterer.h:28
constexpr T reduceRange(T x)
Definition: deltaPhi.h:18
void fill(const T &val)
std::vector< Cluster > clusters_
int neighbour(int icell, unsigned int idx) const
Definition: CaloClusterer.h:27
float phi(int icell) const
Definition: CaloClusterer.h:29
std::vector< std::pair< int, float > > constituents
const T & neigh(int icell, unsigned int idx) const
void grow()
possibly grow clusters by adding unclustered energy on the sides
const Cluster & cluster(int i) const
unsigned int size() const
Definition: CaloClusterer.h:25

Member Data Documentation

◆ cellKey_

IndexGrid l1tpf_calo::SingleCaloClusterer::cellKey_
private

Definition at line 227 of file CaloClusterer.h.

◆ clusterIndex_

IndexGrid l1tpf_calo::SingleCaloClusterer::clusterIndex_
private

Definition at line 227 of file CaloClusterer.h.

Referenced by cluster(), and indexGrid().

◆ clusters_

std::vector<Cluster> l1tpf_calo::SingleCaloClusterer::clusters_
private

Definition at line 228 of file CaloClusterer.h.

Referenced by cluster(), clusters(), and correct().

◆ energyShareAlgo_

EnergyShareAlgo l1tpf_calo::SingleCaloClusterer::energyShareAlgo_
private

Definition at line 231 of file CaloClusterer.h.

Referenced by SingleCaloClusterer().

◆ energyWeightedPosition_

bool l1tpf_calo::SingleCaloClusterer::energyWeightedPosition_
private

Definition at line 232 of file CaloClusterer.h.

◆ grid_

const Grid* l1tpf_calo::SingleCaloClusterer::grid_
private

Definition at line 224 of file CaloClusterer.h.

◆ minClusterEt_

float l1tpf_calo::SingleCaloClusterer::minClusterEt_
private

Definition at line 230 of file CaloClusterer.h.

◆ minEtToGrow_

float l1tpf_calo::SingleCaloClusterer::minEtToGrow_
private

Definition at line 230 of file CaloClusterer.h.

◆ nullCluster_

const Cluster l1tpf_calo::SingleCaloClusterer::nullCluster_
private

Definition at line 229 of file CaloClusterer.h.

Referenced by cluster().

◆ precluster_

PreClusterGrid l1tpf_calo::SingleCaloClusterer::precluster_
private

Definition at line 226 of file CaloClusterer.h.

◆ rawet_

EtGrid l1tpf_calo::SingleCaloClusterer::rawet_
private

Definition at line 225 of file CaloClusterer.h.

Referenced by add(), and raw().

◆ seedEt_

float l1tpf_calo::SingleCaloClusterer::seedEt_
private

Definition at line 230 of file CaloClusterer.h.

◆ unclustered_

EtGrid l1tpf_calo::SingleCaloClusterer::unclustered_
private

Definition at line 225 of file CaloClusterer.h.

◆ zsEt_

float l1tpf_calo::SingleCaloClusterer::zsEt_
private

Definition at line 230 of file CaloClusterer.h.