CMS 3D CMS Logo

MTDThresholdClusterizer.cc
Go to the documentation of this file.
1 // Our own includes
4 
7 
11 
12 // STL
13 #include <stack>
14 #include <vector>
15 #include <iostream>
16 #include <atomic>
17 using namespace std;
18 
19 //#define DEBUG_ENABLED
20 #ifdef DEBUG_ENABLED
21 #define DEBUG(x) \
22  do { \
23  std::cout << x << std::endl; \
24  } while (0)
25 #else
26 #define DEBUG(x)
27 #endif
28 
29 //----------------------------------------------------------------------------
31 //----------------------------------------------------------------------------
33  : // Get energy thresholds
34  theHitThreshold(conf.getParameter<double>("HitThreshold")),
35  theSeedThreshold(conf.getParameter<double>("SeedThreshold")),
36  theClusterThreshold(conf.getParameter<double>("ClusterThreshold")),
37  theTimeThreshold(conf.getParameter<double>("TimeThreshold")),
38  theNumOfRows(0),
39  theNumOfCols(0),
40  theCurrentId(0),
41  theBuffer(theNumOfRows, theNumOfCols),
42  bufferAlreadySet(false) {}
45 
46 // Configuration descriptions
48  desc.add<double>("HitThreshold", 0.);
49  desc.add<double>("SeedThreshold", 0.);
50  desc.add<double>("ClusterThreshold", 0.);
51  desc.add<double>("TimeThreshold", 10.);
52 }
53 
54 //----------------------------------------------------------------------------
57 //----------------------------------------------------------------------------
58 bool MTDThresholdClusterizer::setup(const MTDGeometry* geom, const MTDTopology* topo, const DetId& id) {
59  theCurrentId = id;
60  //using geopraphicalId here
61  const auto& thedet = geom->idToDet(id);
62  if (thedet == nullptr) {
63  throw cms::Exception("MTDThresholdClusterizer")
64  << "GeographicalID: " << std::hex << id.rawId() << " is invalid!" << std::dec << std::endl;
65  return false;
66  }
67  const ProxyMTDTopology& topoproxy = static_cast<const ProxyMTDTopology&>(thedet->topology());
68  const RectangularMTDTopology& topol = static_cast<const RectangularMTDTopology&>(topoproxy.specificTopology());
69 
70  // Get the new sizes.
71  unsigned int nrows = topol.nrows(); // rows in x
72  unsigned int ncols = topol.ncolumns(); // cols in y
73 
74  theNumOfRows = nrows; // Set new sizes
76 
77  DEBUG("Buffer size [" << theNumOfRows + 1 << "," << theNumOfCols + 1 << "]");
78 
79  if (nrows > theBuffer.rows() || ncols > theBuffer.columns()) { // change only when a larger is needed
80  // Resize the buffer
81  theBuffer.setSize(nrows + 1, ncols + 1); // +1 needed for MTD
82  bufferAlreadySet = true;
83  }
84 
85  return true;
86 }
87 //----------------------------------------------------------------------------
93 //----------------------------------------------------------------------------
95  const MTDGeometry* geom,
96  const MTDTopology* topo,
100 
101  // Do not bother for empty detectors
102  if (begin == end) {
103  edm::LogInfo("MTDThresholdClusterizer") << "No hits to clusterize";
104  return;
105  }
106 
107  DEBUG("Input collection " << input.size());
108  assert(output.empty());
109 
110  std::set<unsigned> geoIds;
111  std::multimap<unsigned, unsigned> geoIdToIdx;
112 
113  unsigned index = 0;
114  for (const auto& hit : input) {
115  MTDDetId mtdId = MTDDetId(hit.detid());
116  if (mtdId.subDetector() != MTDDetId::FastTime) {
117  throw cms::Exception("MTDThresholdClusterizer")
118  << "MTDDetId: " << std::hex << mtdId.rawId() << " is invalid!" << std::dec << std::endl;
119  }
120 
121  if (mtdId.mtdSubDetector() == MTDDetId::BTL) {
122  BTLDetId hitId(hit.detid());
123  //for BTL topology gives different layout id
124  DetId geoId = hitId.geographicalId(MTDTopologyMode::crysLayoutFromTopoMode(topo->getMTDTopologyMode()));
125  geoIdToIdx.emplace(geoId, index);
126  geoIds.emplace(geoId);
127  ++index;
128  } else if (mtdId.mtdSubDetector() == MTDDetId::ETL) {
129  ETLDetId hitId(hit.detid());
130  DetId geoId = hitId.geographicalId();
131  geoIdToIdx.emplace(geoId, index);
132  geoIds.emplace(geoId);
133  ++index;
134  } else {
135  throw cms::Exception("MTDThresholdClusterizer")
136  << "MTDDetId: " << std::hex << mtdId.rawId() << " is invalid!" << std::dec << std::endl;
137  }
138  }
139 
140  //cluster hits within geoIds (modules)
141  for (unsigned id : geoIds) {
142  // Set up the clusterization on this DetId.
143  if (!setup(geom, topo, DetId(id)))
144  return;
145 
146  auto range = geoIdToIdx.equal_range(id);
147  DEBUG("Matching Ids for " << std::hex << id << std::dec << " [" << range.first->second << ","
148  << range.second->second << "]");
149 
150  // Copy MTDRecHits to the buffer array; select the seed hits
151  // on the way, and store them in theSeeds.
152  for (auto itr = range.first; itr != range.second; ++itr) {
153  const unsigned hitidx = itr->second;
154  copy_to_buffer(begin + hitidx);
155  }
156 
157  FTLClusterCollection::FastFiller clustersOnDet(output, id);
158 
159  for (unsigned int i = 0; i < theSeeds.size(); i++) {
160  if (theBuffer.energy(theSeeds[i]) > theSeedThreshold) { // Is this seed still valid?
161  // Make a cluster around this seed
162  const FTLCluster& cluster = make_cluster(theSeeds[i]);
163 
164  // Check if the cluster is above threshold
165  if (cluster.energy() > theClusterThreshold) {
166  DEBUG("putting in this cluster " << i << " #hits:" << cluster.size() << " E:" << cluster.energy()
167  << " T:" << cluster.time() << " X:" << cluster.x() << " Y:" << cluster.y());
168  clustersOnDet.push_back(cluster);
169  }
170  }
171  }
172 
173  // Erase the seeds.
174  theSeeds.clear();
175  // Need to clean unused hits from the buffer array.
176  for (auto itr = range.first; itr != range.second; ++itr) {
177  const unsigned hitidx = itr->second;
178  clear_buffer(begin + hitidx);
179  }
180  }
181 }
182 
183 //----------------------------------------------------------------------------
189 //----------------------------------------------------------------------------
191 
192 //----------------------------------------------------------------------------
194 //----------------------------------------------------------------------------
196  int row = itr->row();
197  int col = itr->column();
198  float energy = itr->energy();
199  float time = itr->time();
200  float timeError = itr->timeError();
201 
202  DEBUG("ROW " << row << " COL " << col << " ENERGY " << energy << " TIME " << time);
203  if (energy > theHitThreshold) {
204  theBuffer.set(row, col, energy, time, timeError);
205  if (energy > theSeedThreshold)
206  theSeeds.push_back(FTLCluster::FTLHitPos(row, col));
207  //sort seeds?
208  }
209 }
210 
211 //----------------------------------------------------------------------------
213 //----------------------------------------------------------------------------
215  //First we acquire the seeds for the clusters
216  float seed_energy = theBuffer.energy(hit.row(), hit.col());
217  float seed_time = theBuffer.time(hit.row(), hit.col());
218  float seed_time_error = theBuffer.time_error(hit.row(), hit.col());
220 
221  AccretionCluster acluster;
222  acluster.add(hit, seed_energy, seed_time, seed_time_error);
223 
224  bool stopClus = false;
225  //Here we search all hits adjacent to all hits in the cluster.
226  while (!acluster.empty() && !stopClus) {
227  //This is the standard algorithm to find and add a hit
228  auto curInd = acluster.top();
229  acluster.pop();
230  for (auto c = std::max(0, int(acluster.y[curInd] - 1));
231  c < std::min(int(acluster.y[curInd] + 2), int(theBuffer.columns())) && !stopClus;
232  ++c) {
233  for (auto r = std::max(0, int(acluster.x[curInd] - 1));
234  r < std::min(int(acluster.x[curInd] + 2), int(theBuffer.rows())) && !stopClus;
235  ++r) {
236  if (theBuffer.energy(r, c) > theHitThreshold) {
237  if (std::abs(theBuffer.time(r, c) - seed_time) >
239  sqrt(theBuffer.time_error(r, c) * theBuffer.time_error(r, c) + seed_time_error * seed_time_error))
240  continue;
241  FTLCluster::FTLHitPos newhit(r, c);
242  if (!acluster.add(newhit, theBuffer.energy(r, c), theBuffer.time(r, c), theBuffer.time_error(r, c))) {
243  stopClus = true;
244  break;
245  }
246  theBuffer.clear(newhit);
247  }
248  }
249  }
250  } // while accretion
251 
252  FTLCluster cluster(theCurrentId,
253  acluster.isize,
254  acluster.energy.data(),
255  acluster.time.data(),
256  acluster.timeError.data(),
257  acluster.x.data(),
258  acluster.y.data(),
259  acluster.xmin,
260  acluster.ymin);
261  return cluster;
262 }
MTDThresholdClusterizer::MTDThresholdClusterizer
MTDThresholdClusterizer(edm::ParameterSet const &conf)
Constructor:
Definition: MTDThresholdClusterizer.cc:32
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
BTLDetId.h
hgcalPlots.ncols
ncols
Definition: hgcalPlots.py:105
MTDThresholdClusterizer.h
mps_fire.i
i
Definition: mps_fire.py:355
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
edm::SortedCollection::const_iterator
std::vector< T >::const_iterator const_iterator
Definition: SortedCollection.h:80
input
static const std::string input
Definition: EdmProvDump.cc:48
MTDArrayBuffer::columns
uint columns() const
Definition: MTDArrayBuffer.h:33
funct::false
false
Definition: Factorize.h:34
MTDClusterizerBase::RecHitIterator
FTLRecHitCollection::const_iterator RecHitIterator
Definition: MTDClusterizerBase.h:21
MTDThresholdClusterizer::theClusterThreshold
float theClusterThreshold
Definition: MTDThresholdClusterizer.h:71
MTDThresholdClusterizer::clear_buffer
void clear_buffer(RecHitIterator itr)
Clear the internal buffer array.
Definition: MTDThresholdClusterizer.cc:190
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:32
MTDClusterizerBase::AccretionCluster::xmin
UShort xmin
Definition: MTDClusterizerBase.h:44
min
T min(T a, T b)
Definition: MathUtil.h:58
FTLCluster
Definition: FTLCluster.h:21
MTDArrayBuffer::set
void set(uint row, uint col, float energy, float time, float time_error)
Definition: MTDArrayBuffer.h:97
MTDClusterizerBase::AccretionCluster::x
std::array< UShort, MAXSIZE > x
Definition: MTDClusterizerBase.h:41
cuy.col
col
Definition: cuy.py:1010
edm::LogInfo
Definition: MessageLogger.h:254
FTLCluster::energy
float energy() const
Definition: FTLCluster.h:150
MTDClusterizerBase::AccretionCluster::add
bool add(FTLCluster::FTLHitPos const &p, float const ienergy, float const itime, float const itimeError)
Definition: MTDClusterizerBase.h:54
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
RectangularMTDTopology::nrows
int nrows() const override
Definition: RectangularMTDTopology.h:165
MTDClusterizerBase::AccretionCluster::y
std::array< UShort, MAXSIZE > y
Definition: MTDClusterizerBase.h:42
cms::cuda::assert
assert(be >=bs)
edm::SortedCollection
Definition: SortedCollection.h:49
ProxyMTDTopology::specificTopology
virtual const PixelTopology & specificTopology() const
Definition: ProxyMTDTopology.h:89
MTDArrayBuffer::rows
uint rows() const
Definition: MTDArrayBuffer.h:32
ETLDetId
Detector identifier class for the Endcap Timing Layer.
Definition: ETLDetId.h:15
edmNew::DetSetVector::FastFiller::push_back
void push_back(data_type const &d)
Definition: DetSetVectorNew.h:308
MTDTopologyMode.h
ETLDetId.h
MTDThresholdClusterizer::theCurrentId
DetId theCurrentId
Definition: MTDThresholdClusterizer.h:78
FTLCluster::FTLHitPos
Definition: FTLCluster.h:58
MTDTopology::getMTDTopologyMode
int getMTDTopologyMode() const
Definition: MTDTopology.h:73
end
#define end
Definition: vmac.h:39
MTDClusterizerBase::AccretionCluster::timeError
std::array< float, MAXSIZE > timeError
Definition: MTDClusterizerBase.h:40
MTDThresholdClusterizer::~MTDThresholdClusterizer
~MTDThresholdClusterizer() override
Definition: MTDThresholdClusterizer.cc:44
DEBUG
#define DEBUG(x)
Definition: MTDThresholdClusterizer.cc:26
FTLCluster::time
float time() const
Definition: FTLCluster.h:131
DetId
Definition: DetId.h:17
BTLDetId
Detector identifier class for the Barrel Timing Layer. The crystal count must start from 0,...
Definition: BTLDetId.h:18
MTDClusterizerBase::AccretionCluster::top
UShort top() const
Definition: MTDClusterizerBase.h:50
MTDClusterizerBase::AccretionCluster::time
std::array< float, MAXSIZE > time
Definition: MTDClusterizerBase.h:39
MTDThresholdClusterizer::theNumOfCols
int theNumOfCols
Definition: MTDThresholdClusterizer.h:76
MTDThresholdClusterizer::theSeeds
std::vector< FTLCluster::FTLHitPos > theSeeds
Definition: MTDThresholdClusterizer.h:65
MTDClusterizerBase::AccretionCluster::ymin
UShort ymin
Definition: MTDClusterizerBase.h:45
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
MTDThresholdClusterizer::copy_to_buffer
void copy_to_buffer(RecHitIterator itr)
Copy FTLRecHit into the buffer, identify seeds.
Definition: MTDThresholdClusterizer.cc:195
RectangularMTDTopology.h
relativeConstraints.geom
geom
Definition: relativeConstraints.py:72
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
MTDClusterizerBase::AccretionCluster::pop
void pop()
Definition: MTDClusterizerBase.h:51
MTDClusterizerBase::AccretionCluster::energy
std::array< float, MAXSIZE > energy
Definition: MTDClusterizerBase.h:38
MTDArrayBuffer::time
float time(uint row, uint col) const
Definition: MTDArrayBuffer.h:91
MTDThresholdClusterizer::make_cluster
FTLCluster make_cluster(const FTLCluster::FTLHitPos &hit)
The actual clustering algorithm: group the neighboring hits around the seed.
Definition: MTDThresholdClusterizer.cc:214
MTDDetId::mtdSubDetector
int mtdSubDetector() const
Definition: MTDDetId.h:56
MTDThresholdClusterizer::theNumOfRows
int theNumOfRows
Geometry-related information.
Definition: MTDThresholdClusterizer.h:75
MTDArrayBuffer::clear
void clear(uint row, uint col)
Definition: MTDArrayBuffer.h:37
MTDTopology
Definition: MTDTopology.h:16
edm::ParameterSet
Definition: ParameterSet.h:36
MTDThresholdClusterizer::theTimeThreshold
float theTimeThreshold
Definition: MTDThresholdClusterizer.h:72
MTDThresholdClusterizer::setup
bool setup(const MTDGeometry *geometry, const MTDTopology *topo, const DetId &id)
Definition: MTDThresholdClusterizer.cc:58
MTDTopologyMode::crysLayoutFromTopoMode
BTLDetId::CrysLayout crysLayoutFromTopoMode(const int &topoMode)
Definition: MTDTopologyMode.h:19
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
MTDArrayBuffer::energy
float energy(uint row, uint col) const
Definition: MTDArrayBuffer.h:88
MTDThresholdClusterizer::theBuffer
MTDArrayBuffer theBuffer
Data storage.
Definition: MTDThresholdClusterizer.h:81
MTDClusterizerBase::AccretionCluster::empty
bool empty()
Definition: MTDClusterizerBase.h:52
MTDThresholdClusterizer::fillDescriptions
static void fillDescriptions(edm::ParameterSetDescription &desc)
Definition: MTDThresholdClusterizer.cc:47
MTDArrayBuffer::setSize
void setSize(uint rows, uint cols)
Definition: MTDArrayBuffer.h:78
MTDThresholdClusterizer::theSeedThreshold
float theSeedThreshold
Definition: MTDThresholdClusterizer.h:70
MTDDetId::FastTime
Definition: MTDDetId.h:24
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
MTDArrayBuffer.h
itr
std::vector< std::pair< float, float > >::iterator itr
Definition: HGCDigitizer.cc:28
RectangularMTDTopology
Definition: RectangularMTDTopology.h:39
ProxyMTDTopology
Definition: ProxyMTDTopology.h:28
alignCSCRings.r
r
Definition: alignCSCRings.py:93
MTDClusterizerBase::AccretionCluster
Definition: MTDClusterizerBase.h:34
ProxyMTDTopology.h
MTDGeometry
Definition: MTDGeometry.h:14
edmNew::DetSetVector
Definition: DetSetNew.h:13
MTDDetId::BTL
Definition: MTDDetId.h:27
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
FTLCluster::size
int size() const
Definition: FTLCluster.h:142
FTLCluster::x
float x() const
Definition: FTLCluster.h:121
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
MTDClusterizerBase::AccretionCluster::isize
unsigned int isize
Definition: MTDClusterizerBase.h:46
MTDDetId::ETL
Definition: MTDDetId.h:27
MTDDetId
Detector identifier base class for the MIP Timing Layer.
Definition: MTDDetId.h:21
Exception
Definition: hltDiff.cc:246
FTLCluster::y
float y() const
Definition: FTLCluster.h:126
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
MTDThresholdClusterizer::clusterize
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 aroun...
Definition: MTDThresholdClusterizer.cc:94
edmNew::DetSetVector::FastFiller
Definition: DetSetVectorNew.h:236
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ntuplemaker.time
time
Definition: ntuplemaker.py:310
MTDThresholdClusterizer::theHitThreshold
float theHitThreshold
Clustering-related quantities:
Definition: MTDThresholdClusterizer.h:69
MTDDetId::subDetector
SubDetector subDetector() const
Definition: MTDDetId.h:53
MTDArrayBuffer::time_error
float time_error(uint row, uint col) const
Definition: MTDArrayBuffer.h:94
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
begin
#define begin
Definition: vmac.h:32
MTDThresholdClusterizer::bufferAlreadySet
bool bufferAlreadySet
Definition: MTDThresholdClusterizer.h:82
hit
Definition: SiStripHitEffFromCalibTree.cc:88