CMS 3D CMS Logo

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

An explicit threshold-based clustering algorithm. More...

#include <MTDThresholdClusterizer.h>

Inheritance diagram for MTDThresholdClusterizer:
MTDClusterizerBase

Public Member Functions

void clusterize (const FTLRecHitCollection &input, const MTDGeometry *geom, const MTDTopology *topo, FTLClusterCollection &output) override
 Cluster hits. This method operates on a matrix of hits and finds the largest contiguous cluster around each seed hit. Input and output data stored in DetSet. More...
 
 MTDThresholdClusterizer (edm::ParameterSet const &conf)
 Constructor: More...
 
 ~MTDThresholdClusterizer () override
 
- Public Member Functions inherited from MTDClusterizerBase
virtual ~MTDClusterizerBase ()
 

Static Public Member Functions

static void fillDescriptions (edm::ParameterSetDescription &desc)
 

Private Member Functions

void clear_buffer (RecHitIterator itr)
 Clear the internal buffer array. More...
 
void copy_to_buffer (RecHitIterator itr)
 Copy FTLRecHit into the buffer, identify seeds. More...
 
FTLCluster make_cluster (const FTLCluster::FTLHitPos &hit)
 The actual clustering algorithm: group the neighboring hits around the seed. More...
 
bool setup (const MTDGeometry *geometry, const MTDTopology *topo, const DetId &id)
 

Private Attributes

bool bufferAlreadySet
 
MTDArrayBuffer theBuffer
 Data storage. More...
 
std::vector< FTLClustertheClusters
 
float theClusterThreshold
 
DetId theCurrentId
 
float theHitThreshold
 Clustering-related quantities: More...
 
int theNumOfCols
 
int theNumOfRows
 Geometry-related information. More...
 
std::vector< FTLCluster::FTLHitPostheSeeds
 
float theSeedThreshold
 
float theTimeThreshold
 

Additional Inherited Members

- Public Types inherited from MTDClusterizerBase
typedef FTLClusterCollection::const_iterator ClusterIterator
 
typedef FTLRecHitCollection::const_iterator RecHitIterator
 

Detailed Description

An explicit threshold-based clustering algorithm.

A threshold-based clustering algorithm which clusters FTLRecHits into FTLClusters for each DetUnit. The algorithm is straightforward and purely topological: the clustering process starts with seed hits and continues by adding adjacent hits above the hit threshold. Once the cluster is made, it has to be above the cluster threshold as well.

The clusterization is performed on a matrix with size equal to the size of the MTD detector, each cell containing the cahrge and time of the corresponding hit The matrix is reset after each clusterization.

The search starts from seed hits, i.e. hits with sufficiently large amplitudes

FTLCluster contains a barycenter, but it should be noted that that information is largely useless. One must use a PositionEstimator class to compute the RecHit position and its error for every given cluster.

Sets the MTDArrayBuffer dimensions and pixel thresholds. Makes clusters and stores them in theCache if the option useCache has been set.

Definition at line 51 of file MTDThresholdClusterizer.h.

Constructor & Destructor Documentation

MTDThresholdClusterizer::MTDThresholdClusterizer ( edm::ParameterSet const &  conf)

Constructor:

Definition at line 29 of file MTDThresholdClusterizer.cc.

29  :
30  // Get energy thresholds
31  theHitThreshold( conf.getParameter<double>("HitThreshold") ),
32  theSeedThreshold( conf.getParameter<double>("SeedThreshold") ),
33  theClusterThreshold( conf.getParameter<double>("ClusterThreshold") ),
34  theTimeThreshold( conf.getParameter<double>("TimeThreshold") ),
37  bufferAlreadySet(false)
38 {
39 }
float theHitThreshold
Clustering-related quantities:
int theNumOfRows
Geometry-related information.
MTDArrayBuffer theBuffer
Data storage.
MTDThresholdClusterizer::~MTDThresholdClusterizer ( )
override

Definition at line 41 of file MTDThresholdClusterizer.cc.

41 {}

Member Function Documentation

void MTDThresholdClusterizer::clear_buffer ( RecHitIterator  itr)
private

Clear the internal buffer array.

MTDs which are not part of recognized clusters are NOT ERASED during the cluster finding. Erase them now.

Definition at line 211 of file MTDThresholdClusterizer.cc.

212 {
213  theBuffer.clear( itr->row(), itr->column() );
214 }
MTDArrayBuffer theBuffer
Data storage.
void clear(uint row, uint col)
void MTDThresholdClusterizer::clusterize ( const FTLRecHitCollection input,
const MTDGeometry geom,
const MTDTopology topo,
FTLClusterCollection output 
)
overridevirtual

Cluster hits. This method operates on a matrix of hits and finds the largest contiguous cluster around each seed hit. Input and output data stored in DetSet.

Implements MTDClusterizerBase.

Definition at line 98 of file MTDThresholdClusterizer.cc.

References begin, edm::SortedCollection< T, SORT >::begin(), MTDDetId::BTL, DEBUG, TauDecayModes::dec, edmNew::DetSetVector< T >::empty(), end, edm::SortedCollection< T, SORT >::end(), FTLCluster::energy(), MTDDetId::ETL, Exception, MTDDetId::FastTime, MTDTopology::getMTDTopologyMode(), mps_fire::i, MTDDetId::mtdSubDetector(), edmNew::DetSetVector< T >::FastFiller::push_back(), DetId::rawId(), GeneralSetup::setup(), edm::SortedCollection< T, SORT >::size(), FTLCluster::size(), MTDDetId::subDetector(), FTLCluster::time(), FTLCluster::x(), and FTLCluster::y().

101  {
102 
105 
106  // Do not bother for empty detectors
107  if (begin == end)
108  {
109  edm::LogInfo("MTDThresholdClusterizer") << "No hits to clusterize";
110  return;
111  }
112 
113  DEBUG("Input collection " << input.size());
114  assert(output.empty());
115 
116  std::set<unsigned> geoIds;
117  std::multimap<unsigned, unsigned> geoIdToIdx;
118 
119  unsigned index = 0;
120  for(const auto& hit : input)
121  {
122  MTDDetId mtdId=MTDDetId(hit.detid());
123  if (mtdId.subDetector() != MTDDetId::FastTime)
124  {
125  throw cms::Exception("MTDThresholdClusterizer") << "MTDDetId: " << std::hex
126  << mtdId.rawId()
127  << " is invalid!" << std::dec
128  << std::endl;
129  }
130 
131  if ( mtdId.mtdSubDetector() == MTDDetId::BTL )
132  {
133  BTLDetId hitId(hit.detid());
134  DetId geoId = hitId.geographicalId( (BTLDetId::CrysLayout) topo->getMTDTopologyMode() ); //for BTL topology gives different layout id
135  geoIdToIdx.emplace(geoId,index);
136  geoIds.emplace(geoId);
137  ++index;
138  }
139  else if ( mtdId.mtdSubDetector() == MTDDetId::ETL )
140  {
141  ETLDetId hitId(hit.detid());
142  DetId geoId = hitId.geographicalId();
143  geoIdToIdx.emplace(geoId,index);
144  geoIds.emplace(geoId);
145  ++index;
146  }
147  else
148  {
149  throw cms::Exception("MTDThresholdClusterizer") << "MTDDetId: " << std::hex
150  << mtdId.rawId()
151  << " is invalid!" << std::dec
152  << std::endl;
153  }
154  }
155 
156  //cluster hits within geoIds (modules)
157  for(unsigned id : geoIds) {
158  // Set up the clusterization on this DetId.
159  if ( !setup(geom,topo,DetId(id)) )
160  return;
161 
162  auto range = geoIdToIdx.equal_range(id);
163  DEBUG("Matching Ids for " << std::hex << id << std::dec << " [" << range.first->second << "," << range.second->second << "]");
164 
165  // Copy MTDRecHits to the buffer array; select the seed hits
166  // on the way, and store them in theSeeds.
167  for(auto itr = range.first; itr != range.second; ++itr) {
168  const unsigned hitidx = itr->second;
169  copy_to_buffer(begin+hitidx);
170  }
171 
172  FTLClusterCollection::FastFiller clustersOnDet(output,id);
173 
174  for (unsigned int i = 0; i < theSeeds.size(); i++)
175  {
177  { // Is this seed still valid?
178  // Make a cluster around this seed
179  const FTLCluster & cluster = make_cluster( theSeeds[i] );
180 
181  // Check if the cluster is above threshold
182  if ( cluster.energy() > theClusterThreshold)
183  {
184  DEBUG("putting in this cluster " << i << " #hits:" << cluster.size()
185  << " E:" << cluster.energy()
186  << " T:" << cluster.time()
187  << " X:" << cluster.x()
188  << " Y:" << cluster.y());
189  clustersOnDet.push_back( cluster );
190  }
191  }
192  }
193 
194  // Erase the seeds.
195  theSeeds.clear();
196  // Need to clean unused hits from the buffer array.
197  for(auto itr = range.first; itr != range.second; ++itr) {
198  const unsigned hitidx = itr->second;
199  clear_buffer(begin+hitidx);
200  }
201  }
202 }
float y() const
Definition: FTLCluster.h:113
CrysLayout
Definition: BTLDetId.h:66
int getMTDTopologyMode() const
Definition: MTDTopology.h:74
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
std::vector< T >::const_iterator const_iterator
float time() const
Definition: FTLCluster.h:118
Detector identifier base class for the MIP Timing Layer.
Definition: MTDDetId.h:21
bool setup(const MTDGeometry *geometry, const MTDTopology *topo, const DetId &id)
float x() const
Definition: FTLCluster.h:108
float energy(uint row, uint col) const
#define end
Definition: vmac.h:39
std::vector< FTLCluster::FTLHitPos > theSeeds
void copy_to_buffer(RecHitIterator itr)
Copy FTLRecHit into the buffer, identify seeds.
int size() const
Definition: FTLCluster.h:129
const_iterator end() const
Definition: DetId.h:18
float energy() const
Definition: FTLCluster.h:138
#define DEBUG(x)
MTDArrayBuffer theBuffer
Data storage.
SubDetector subDetector() const
Definition: MTDDetId.h:55
FTLCluster make_cluster(const FTLCluster::FTLHitPos &hit)
The actual clustering algorithm: group the neighboring hits around the seed.
Detector identifier class for the Endcap Timing Layer.
Definition: ETLDetId.h:15
#define begin
Definition: vmac.h:32
size_type size() const
Detector identifier class for the Barrel Timing Layer. The crystal count must start from 0...
Definition: BTLDetId.h:18
int mtdSubDetector() const
Definition: MTDDetId.h:58
void clear_buffer(RecHitIterator itr)
Clear the internal buffer array.
const_iterator begin() const
void MTDThresholdClusterizer::copy_to_buffer ( RecHitIterator  itr)
private

Copy FTLRecHit into the buffer, identify seeds.

Definition at line 219 of file MTDThresholdClusterizer.cc.

References cuy::col, DEBUG, and protons_cff::time.

220 {
221  int row = itr->row();
222  int col = itr->column();
223  float energy = itr->energy();
224  float time = itr->time();
225  float timeError = itr->timeError();
226 
227  DEBUG("ROW " << row << " COL " << col << " ENERGY " << energy << " TIME " << time);
228  if ( energy > theHitThreshold) {
229  theBuffer.set( row, col, energy , time, timeError);
230  if ( energy > theSeedThreshold) theSeeds.push_back( FTLCluster::FTLHitPos(row,col));
231  //sort seeds?
232  }
233 }
float theHitThreshold
Clustering-related quantities:
std::vector< FTLCluster::FTLHitPos > theSeeds
#define DEBUG(x)
MTDArrayBuffer theBuffer
Data storage.
void set(uint row, uint col, float energy, float time, float time_error)
col
Definition: cuy.py:1010
void MTDThresholdClusterizer::fillDescriptions ( edm::ParameterSetDescription desc)
static

Definition at line 46 of file MTDThresholdClusterizer.cc.

References edm::ParameterSetDescription::add().

Referenced by MTDClusterProducer::fillDescriptions().

46  {
47  desc.add<double>("HitThreshold", 0.);
48  desc.add<double>("SeedThreshold", 0.);
49  desc.add<double>("ClusterThreshold", 0.);
50  desc.add<double>("TimeThreshold", 10.);
51 }
ParameterDescriptionBase * add(U const &iLabel, T const &value)
FTLCluster MTDThresholdClusterizer::make_cluster ( const FTLCluster::FTLHitPos hit)
private

The actual clustering algorithm: group the neighboring hits around the seed.

Definition at line 240 of file MTDThresholdClusterizer.cc.

References funct::abs(), MTDClusterizerBase::AccretionCluster::add(), EnergyCorrector::c, FTLCluster::FTLHitPos::col(), MTDClusterizerBase::AccretionCluster::empty(), MTDClusterizerBase::AccretionCluster::energy, FTLCluster::energy(), MTDClusterizerBase::AccretionCluster::isize, SiStripPI::max, min(), MTDClusterizerBase::AccretionCluster::pop(), alignCSCRings::r, FTLCluster::FTLHitPos::row(), mathSSE::sqrt(), MTDClusterizerBase::AccretionCluster::time, MTDClusterizerBase::AccretionCluster::timeError, MTDClusterizerBase::AccretionCluster::top(), MTDClusterizerBase::AccretionCluster::x, MTDClusterizerBase::AccretionCluster::xmin, MTDClusterizerBase::AccretionCluster::y, and MTDClusterizerBase::AccretionCluster::ymin.

241 {
242 
243  //First we acquire the seeds for the clusters
244  float seed_energy= theBuffer.energy(hit.row(), hit.col());
245  float seed_time= theBuffer.time(hit.row(), hit.col());
246  float seed_time_error= theBuffer.time_error(hit.row(), hit.col());
247  theBuffer.clear(hit);
248 
249  AccretionCluster acluster;
250  acluster.add(hit, seed_energy, seed_time, seed_time_error);
251 
252  bool stopClus=false;
253  //Here we search all hits adjacent to all hits in the cluster.
254  while ( ! acluster.empty() && ! stopClus)
255  {
256  //This is the standard algorithm to find and add a hit
257  auto curInd = acluster.top(); acluster.pop();
258  for ( auto c = std::max(0,int(acluster.y[curInd]-1)); c < std::min(int(acluster.y[curInd]+2),int(theBuffer.columns())) && !stopClus; ++c) {
259  for ( auto r = std::max(0,int(acluster.x[curInd]-1)); r < std::min(int(acluster.x[curInd]+2),int(theBuffer.rows())) && !stopClus; ++r) {
260  if ( theBuffer.energy(r,c) > theHitThreshold) {
261  if (std::abs(theBuffer.time(r,c) - seed_time) > theTimeThreshold*sqrt( theBuffer.time_error(r,c)*theBuffer.time_error(r,c) + seed_time_error*seed_time_error))
262  continue;
263  FTLCluster::FTLHitPos newhit(r,c);
264  if (!acluster.add( newhit, theBuffer.energy(r,c), theBuffer.time(r,c), theBuffer.time_error(r,c)))
265  {
266  stopClus=true;
267  break;
268  }
269  theBuffer.clear(newhit);
270  }
271  }
272  }
273  } // while accretion
274 
275  FTLCluster cluster( theCurrentId, acluster.isize,
276  acluster.energy.data(), acluster.time.data(), acluster.timeError.data(),
277  acluster.x.data(), acluster.y.data(),
278  acluster.xmin, acluster.ymin);
279  return cluster;
280 }
float time_error(uint row, uint col) const
uint rows() const
float theHitThreshold
Clustering-related quantities:
uint columns() const
float time(uint row, uint col) const
T sqrt(T t)
Definition: SSEVec.h:18
constexpr int row() const
Definition: FTLCluster.h:61
float energy(uint row, uint col) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
T min(T a, T b)
Definition: MathUtil.h:58
MTDArrayBuffer theBuffer
Data storage.
constexpr int col() const
Definition: FTLCluster.h:62
void clear(uint row, uint col)
bool MTDThresholdClusterizer::setup ( const MTDGeometry geom,
const MTDTopology topo,
const DetId id 
)
private

Prepare the Clusterizer to work on a particular DetUnit. Re-init the size of the panel/plaquette (so update nrows and ncols),

Definition at line 57 of file MTDThresholdClusterizer.cc.

References DEBUG, TauDecayModes::dec, Exception, triggerObjects_cff::id, MTDGeometry::idToDet(), hgcalPlots::ncols, RectangularMTDTopology::ncolumns(), RectangularMTDTopology::nrows(), and ProxyMTDTopology::specificTopology().

58 {
60  //using geopraphicalId here
61  const auto& thedet = geom->idToDet(id);
62  if( thedet == nullptr ) {
63  throw cms::Exception("MTDThresholdClusterizer") << "GeographicalID: " << std::hex
64  << id.rawId()
65  << " is invalid!" << std::dec
66  << std::endl;
67  return false;
68  }
69  const ProxyMTDTopology& topoproxy = static_cast<const ProxyMTDTopology&>(thedet->topology());
70  const RectangularMTDTopology& topol = static_cast<const RectangularMTDTopology&>(topoproxy.specificTopology());
71 
72  // Get the new sizes.
73  unsigned int nrows = topol.nrows(); // rows in x
74  unsigned int ncols = topol.ncolumns(); // cols in y
75 
76  theNumOfRows = nrows; // Set new sizes
78 
79  DEBUG("Buffer size [" << theNumOfRows+1 << "," << theNumOfCols+1 << "]");
80 
81  if ( nrows > theBuffer.rows() ||
82  ncols > theBuffer.columns() )
83  { // change only when a larger is needed
84  // Resize the buffer
85  theBuffer.setSize(nrows+1,ncols+1); // +1 needed for MTD
86  bufferAlreadySet = true;
87  }
88 
89  return true;
90 }
uint rows() const
uint columns() const
int ncolumns() const override
int theNumOfRows
Geometry-related information.
int nrows() const override
const MTDGeomDet * idToDet(DetId) const override
Definition: MTDGeometry.cc:184
virtual const PixelTopology & specificTopology() const
#define DEBUG(x)
MTDArrayBuffer theBuffer
Data storage.
void setSize(uint rows, uint cols)

Member Data Documentation

bool MTDThresholdClusterizer::bufferAlreadySet
private

Definition at line 84 of file MTDThresholdClusterizer.h.

MTDArrayBuffer MTDThresholdClusterizer::theBuffer
private

Data storage.

Definition at line 83 of file MTDThresholdClusterizer.h.

std::vector<FTLCluster> MTDThresholdClusterizer::theClusters
private

Definition at line 68 of file MTDThresholdClusterizer.h.

float MTDThresholdClusterizer::theClusterThreshold
private

Definition at line 73 of file MTDThresholdClusterizer.h.

DetId MTDThresholdClusterizer::theCurrentId
private

Definition at line 80 of file MTDThresholdClusterizer.h.

float MTDThresholdClusterizer::theHitThreshold
private

Clustering-related quantities:

Definition at line 71 of file MTDThresholdClusterizer.h.

int MTDThresholdClusterizer::theNumOfCols
private

Definition at line 78 of file MTDThresholdClusterizer.h.

int MTDThresholdClusterizer::theNumOfRows
private

Geometry-related information.

Definition at line 77 of file MTDThresholdClusterizer.h.

std::vector<FTLCluster::FTLHitPos> MTDThresholdClusterizer::theSeeds
private

Definition at line 67 of file MTDThresholdClusterizer.h.

float MTDThresholdClusterizer::theSeedThreshold
private

Definition at line 72 of file MTDThresholdClusterizer.h.

float MTDThresholdClusterizer::theTimeThreshold
private

Definition at line 74 of file MTDThresholdClusterizer.h.