CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
trackerTFP::ZHoughTransform Class Reference

#include <ZHoughTransform.h>

Public Member Functions

void consume (const tt::StreamsStub &streams)
 
void produce (tt::StreamsStub &accepted, tt::StreamsStub &lost)
 
 ZHoughTransform (const edm::ParameterSet &iConfig, const tt::Setup *setup, const DataFormats *dataFormats, int region)
 
 ~ZHoughTransform ()
 

Private Member Functions

void fill (int channel, const std::deque< StubZHT *> &input, std::vector< std::deque< StubZHT *>> &output)
 
void merge (std::deque< StubZHT *> &stubs, tt::StreamStub &stream) const
 
template<class T >
Tpop_front (std::deque< T *> &ts) const
 
void slb (std::vector< std::deque< StubZHT *>> &inputs, std::deque< StubZHT *> &accepted, tt::StreamStub &lost) const
 

Private Attributes

const DataFormatsdataFormats_
 
bool enableTruncation_
 
std::vector< std::vector< StubZHT * > > input_
 
int region_
 
const tt::Setupsetup_
 
int stage_
 
std::vector< StubZHTstubsZHT_
 

Detailed Description

Definition at line 14 of file ZHoughTransform.h.

Constructor & Destructor Documentation

◆ ZHoughTransform()

trackerTFP::ZHoughTransform::ZHoughTransform ( const edm::ParameterSet iConfig,
const tt::Setup setup,
const DataFormats dataFormats,
int  region 
)

Definition at line 18 of file ZHoughTransform.cc.

References trackerTFP::mht.

22  : enableTruncation_(iConfig.getParameter<bool>("EnableTruncation")),
23  setup_(setup),
24  dataFormats_(dataFormats),
25  region_(region),
26  input_(dataFormats->numChannel(Process::mht)),
27  stage_(0) {}
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< std::vector< StubZHT * > > input_
const DataFormats * dataFormats_

◆ ~ZHoughTransform()

trackerTFP::ZHoughTransform::~ZHoughTransform ( )
inline

Definition at line 20 of file ZHoughTransform.h.

20 {}

Member Function Documentation

◆ consume()

void trackerTFP::ZHoughTransform::consume ( const tt::StreamsStub streams)

Definition at line 30 of file ZHoughTransform.cc.

References dataFormats_, amptDefault_cfi::frame, input_, trackerTFP::mht, trackerTFP::DataFormats::numChannel(), hltrates_dqm_sourceclient-live_cfg::offset, region_, setup_, cms::cuda::stream, HLT_2023v12_cff::streams, stubsZHT_, validateGeometry_cfg::valid, tt::Setup::zhtNumCells(), and tt::Setup::zhtNumStages().

30  {
31  auto valid = [](int sum, const FrameStub& frame) { return sum + (frame.first.isNonnull() ? 1 : 0); };
33  int nStubsMHT(0);
34  for (int channel = 0; channel < dataFormats_->numChannel(Process::mht); channel++) {
35  const StreamStub& stream = streams[offset + channel];
36  nStubsMHT += accumulate(stream.begin(), stream.end(), 0, valid);
37  }
38  stubsZHT_.reserve(nStubsMHT * (setup_->zhtNumCells() * setup_->zhtNumStages()));
39  for (int channel = 0; channel < dataFormats_->numChannel(Process::mht); channel++) {
40  const StreamStub& stream = streams[offset + channel];
41  vector<StubZHT*>& stubs = input_[channel];
42  stubs.reserve(stream.size());
43  // Store input stubs in vector, so rest of ZHT algo can work with pointers to them (saves CPU)
44  for (const FrameStub& frame : stream) {
45  StubZHT* stub = nullptr;
46  if (frame.first.isNonnull()) {
47  StubMHT stubMHT(frame, dataFormats_);
48  stubsZHT_.emplace_back(stubMHT);
49  stub = &stubsZHT_.back();
50  }
51  stubs.push_back(stub);
52  }
53  }
54  }
std::pair< TTStubRef, Frame > FrameStub
Definition: TTTypes.h:60
int zhtNumStages() const
Definition: Setup.h:467
std::vector< FrameStub > StreamStub
Definition: TTTypes.h:63
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
int numChannel(Process p) const
Definition: DataFormats.h:498
std::vector< StubZHT > stubsZHT_
std::vector< std::vector< StubZHT * > > input_
int zhtNumCells() const
Definition: Setup.h:475
const DataFormats * dataFormats_

◆ fill()

void trackerTFP::ZHoughTransform::fill ( int  channel,
const std::deque< StubZHT *> &  input,
std::vector< std::deque< StubZHT *>> &  output 
)
private

Definition at line 85 of file ZHoughTransform.cc.

References funct::abs(), trackerTFP::DataFormat::base(), trackerTFP::begin, hgcalTBTopologyTester_cfi::cells, tt::Setup::chosenRofPhi(), tt::Setup::chosenRofZ(), trackerTFP::cot, ztail::d, dataFormats_, change_name::diff, HLT_2023v12_cff::distance, tt::Setup::dZ(), trackerTFP::DataFormats::format(), l1ctLayer2EG_cff::id, createfilelist::int, hgcalTBTopologyTester_cfi::layers, tt::Setup::mhtMinLayers(), GetRecoTauVFromDQM_MC_cff::next, conifer::pow(), trackerTFP::r, alignCSCRings::s, tt::Setup::sectorCot(), EgammaValidation_Wenu_cff::sel, setup_, findQualityFiles::size, stage_, cms::cuda::stream, HLT_2023v12_cff::streams, stubsZHT_, HcalDetIdTransform::transform(), trackerTFP::zht, tt::Setup::zhtNumBinsZT(), tt::Setup::zhtNumCells(), tt::Setup::zhtNumStages(), and trackerTFP::zT.

Referenced by produce().

85  {
86  if (stubs.empty())
87  return;
88  const double baseZT =
90  const double baseCot =
92  int id;
93  auto different = [&id](StubZHT* stub) { return !stub || id != stub->trackId(); };
94  for (auto it = stubs.begin(); it != stubs.end();) {
95  if (!*it) {
96  const auto begin = find_if(it, stubs.end(), [](StubZHT* stub) { return stub; });
97  const int nGaps = distance(it, begin);
98  for (deque<StubZHT*>& stream : streams)
99  stream.insert(stream.end(), nGaps, nullptr);
100  it = begin;
101  continue;
102  }
103  const auto start = it;
104  const double cotGlobal = (*start)->cotf() + setup_->sectorCot((*start)->sectorEta());
105  id = (*it)->trackId();
106  it = find_if(it, stubs.end(), different);
107  const int size = distance(start, it);
108  // create finer track candidates stub container
109  vector<vector<StubZHT*>> mhtCells(setup_->zhtNumCells());
110  for (vector<StubZHT*>& mhtCell : mhtCells)
111  mhtCell.reserve(size);
112  // fill finer track candidates stub container
113  for (auto stub = start; stub != it; stub++) {
114  const double r = (*stub)->r() + setup_->chosenRofPhi() - setup_->chosenRofZ();
115  const double chi = (*stub)->chi();
116  const double dChi = setup_->dZ((*stub)->ttStubRef(), cotGlobal);
117  // identify finer track candidates for this stub
118  // 0 and 1 belong to the ZHT cells with smaller cot; 0 and 2 belong to those with smaller zT
119  vector<int> cells;
120  cells.reserve(setup_->zhtNumCells());
121  const bool compA = 2. * abs(chi) < baseZT + dChi;
122  const bool compB = 2. * abs(chi) < abs(r) * baseCot + dChi;
123  const bool compC = 2. * abs(chi) < dChi;
124  if (chi >= 0. && r >= 0.) {
125  cells.push_back(1);
126  if (compA)
127  cells.push_back(3);
128  if (compB)
129  cells.push_back(0);
130  if (compC)
131  cells.push_back(2);
132  }
133  if (chi >= 0. && r < 0.) {
134  cells.push_back(3);
135  if (compA)
136  cells.push_back(1);
137  if (compB)
138  cells.push_back(2);
139  if (compC)
140  cells.push_back(0);
141  }
142  if (chi < 0. && r >= 0.) {
143  cells.push_back(2);
144  if (compA)
145  cells.push_back(0);
146  if (compB)
147  cells.push_back(3);
148  if (compC)
149  cells.push_back(1);
150  }
151  if (chi < 0. && r < 0.) {
152  cells.push_back(0);
153  if (compA)
154  cells.push_back(2);
155  if (compB)
156  cells.push_back(1);
157  if (compC)
158  cells.push_back(3);
159  }
160  for (int cell : cells) {
161  const double cot = (cell / setup_->zhtNumBinsZT() - .5) * baseCot / 2.;
162  const double zT = (cell % setup_->zhtNumBinsZT() - .5) * baseZT / 2.;
163  stubsZHT_.emplace_back(**stub, zT, cot, cell);
164  mhtCells[cell].push_back(&stubsZHT_.back());
165  }
166  }
167  // perform pattern recognition
168  for (int sel = 0; sel < setup_->zhtNumCells(); sel++) {
169  deque<StubZHT*>& stream = streams[channel * setup_->zhtNumCells() + sel];
170  vector<StubZHT*>& mhtCell = mhtCells[sel];
171  set<int> layers;
172  auto toLayer = [](StubZHT* stub) { return stub->layer(); };
173  transform(mhtCell.begin(), mhtCell.end(), inserter(layers, layers.begin()), toLayer);
174  if ((int)layers.size() < setup_->mhtMinLayers())
175  mhtCell.clear();
176  for (StubZHT* stub : mhtCell)
177  stream.push_back(stub);
178  stream.insert(stream.end(), size - (int)mhtCell.size(), nullptr);
179  }
180  }
181  for (int sel = 0; sel < setup_->zhtNumCells(); sel++) {
182  deque<StubZHT*>& stream = streams[channel * setup_->zhtNumCells() + sel];
183  // remove all gaps between end and last stub
184  for (auto it = stream.end(); it != stream.begin();)
185  it = (*--it) ? stream.begin() : stream.erase(it);
186  // read out fine track cannot start before rough track has read in completely, add gaps to take this into account
187  int pos(0);
188  for (auto it = stream.begin(); it != stream.end();) {
189  if (!(*it)) {
190  it = stream.erase(it);
191  continue;
192  }
193  id = (*it)->trackId();
194  const int s = distance(it, find_if(it, stream.end(), different));
195  const int d = distance(stream.begin(), it);
196  pos += s;
197  if (d < pos) {
198  const int diff = pos - d;
199  it = stream.insert(it, diff, nullptr);
200  it = next(it, diff);
201  } else
202  it = stream.erase(remove(next(stream.begin(), pos), it, nullptr), it);
203  it = next(it, s);
204  }
205  // adjust stream start so that first output stub is in first place in case of quickest track
206  if (!stream.empty())
207  stream.erase(stream.begin(), next(stream.begin(), setup_->mhtMinLayers()));
208  }
209  }
size
Write out results.
Definition: start.py:1
double dZ(const TTStubRef &ttStubRef, double cot) const
Definition: Setup.cc:596
double base() const
Definition: DataFormats.h:117
double chosenRofZ() const
Definition: Setup.h:413
int zhtNumStages() const
Definition: Setup.h:467
constexpr int pow(int x)
Definition: conifer.h:24
double chosenRofPhi() const
Definition: Setup.h:213
int zhtNumBinsZT() const
Definition: Setup.h:463
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
int mhtMinLayers() const
Definition: Setup.h:456
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< StubZHT > stubsZHT_
d
Definition: ztail.py:151
int zhtNumCells() const
Definition: Setup.h:475
const DataFormats * dataFormats_
double sectorCot(int eta) const
Definition: Setup.h:428
const DataFormat & format(Variable v, Process p) const
Definition: DataFormats.h:506
unsigned transform(const HcalDetId &id, unsigned transformCode)

◆ merge()

void trackerTFP::ZHoughTransform::merge ( std::deque< StubZHT *> &  stubs,
tt::StreamStub stream 
) const
private

Definition at line 266 of file ZHoughTransform.cc.

References HLT_2023v12_cff::candidates, trackerTFP::cot, HLT_2023v12_cff::distance, trackerTFP::Stub< Ts >::frame(), l1ctLayer2EG_cff::id, createfilelist::int, visualization-live-secondInstance_cfg::m, SiStripPI::max, SiStripPI::min, conifer::pow(), alignCSCRings::s, setup_, findQualityFiles::size, cms::cuda::stream, HLT_2023v12_cff::track, pwdgSkimBPark_cfi::tracks, mps_merge::weight, tt::Setup::zhtNumCells(), tt::Setup::zhtNumStages(), and trackerTFP::zT.

Referenced by produce().

266  {
267  stubs.erase(remove(stubs.begin(), stubs.end(), nullptr), stubs.end());
268  /*stream.reserve(stubs.size());
269  transform(stubs.begin(), stubs.end(), back_inserter(stream), [](StubZHT* stub){ return stub->frame(); });
270  return;*/
271  map<int, set<pair<int, int>>> candidates;
272  const int weight = setup_->zhtNumCells() * pow(2, setup_->zhtNumStages());
273  for (const StubZHT* stub : stubs)
274  candidates[stub->trackId() / weight].emplace(stub->cot(), stub->zT());
275  vector<deque<FrameStub>> tracks(candidates.size());
276  for (auto it = stubs.begin(); it != stubs.end();) {
277  const auto start = it;
278  const int id = (*it)->trackId();
279  const int candId = id / weight;
280  const auto m = candidates.find(candId);
281  pair<int, int> cotp(9e9, -9e9);
282  pair<int, int> zTp(9e9, -9e9);
283  for (const pair<int, int>& para : m->second) {
284  cotp = {min(cotp.first, para.first), max(cotp.second, para.first)};
285  zTp = {min(zTp.first, para.second), max(zTp.second, para.second)};
286  }
287  const int cot = (cotp.first + cotp.second) / 2;
288  const int zT = (cotp.first + cotp.second) / 2;
289  const int pos = distance(candidates.begin(), m);
290  deque<FrameStub>& track = tracks[pos];
291  auto different = [id](const StubZHT* stub) { return id != stub->trackId(); };
292  it = find_if(it, stubs.end(), different);
293  for (auto s = start; s != it; s++) {
294  if (find_if(track.begin(), track.end(), [s](const FrameStub& stub) {
295  return (*s)->ttStubRef() == stub.first;
296  }) != track.end())
297  continue;
298  const StubZHT stub(**s, cot, zT);
299  track.push_back(stub.frame());
300  }
301  }
302  const int size = accumulate(tracks.begin(), tracks.end(), 0, [](int sum, const deque<FrameStub>& stubs) {
303  return sum + (int)stubs.size();
304  });
305  stream.reserve(size);
306  for (deque<FrameStub>& track : tracks)
307  for (const FrameStub& stub : track)
308  stream.push_back(stub);
309  }
size
Write out results.
Definition: start.py:1
std::pair< TTStubRef, Frame > FrameStub
Definition: TTTypes.h:60
int zhtNumStages() const
Definition: Setup.h:467
Definition: weight.py:1
constexpr int pow(int x)
Definition: conifer.h:24
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
int zhtNumCells() const
Definition: Setup.h:475

◆ pop_front()

template<class T >
T * trackerTFP::ZHoughTransform::pop_front ( std::deque< T *> &  ts) const
private

Definition at line 313 of file ZHoughTransform.cc.

References submitPVValidationJobs::t.

Referenced by slb().

313  {
314  T* t = nullptr;
315  if (!ts.empty()) {
316  t = ts.front();
317  ts.pop_front();
318  }
319  return t;
320  }
long double T

◆ produce()

void trackerTFP::ZHoughTransform::produce ( tt::StreamsStub accepted,
tt::StreamsStub lost 
)

Definition at line 57 of file ZHoughTransform.cc.

References trackerTFP::begin, dataFormats_, fill(), input_, dqmdumpme::k, merge(), trackerTFP::mht, trackerTFP::DataFormats::numChannel(), region_, setup_, slb(), stage_, cms::cuda::stream, HLT_2023v12_cff::streams, edm::swap(), createJobs::tmp, tt::Setup::zhtNumCells(), and tt::Setup::zhtNumStages().

57  {
58  vector<deque<StubZHT*>> streams(dataFormats_->numChannel(Process::mht));
59  for (int channel = 0; channel < dataFormats_->numChannel(Process::mht); channel++)
60  streams[channel] = deque<StubZHT*>(input_[channel].begin(), input_[channel].end());
61  vector<deque<StubZHT*>> stubsCells(dataFormats_->numChannel(Process::mht) * setup_->zhtNumCells());
62  for (stage_ = 0; stage_ < setup_->zhtNumStages(); stage_++) {
63  // fill ZHT cells
64  for (int channel = 0; channel < dataFormats_->numChannel(Process::mht); channel++)
65  fill(channel, streams[channel], stubsCells);
66  // perform static load balancing
67  for (int channel = 0; channel < dataFormats_->numChannel(Process::mht); channel++) {
68  vector<deque<StubZHT*>> tmp(setup_->zhtNumCells());
69  // gather streams to mux together: same ZHT cell of 4 adjacent ZHT input streams
70  for (int k = 0; k < setup_->zhtNumCells(); k++)
71  //swap(tmp[k], stubsCells[(channel / setup_->zhtNumCells()) * dataFormats_->numChannel(Process::mht) + channel % setup_->zhtNumCells() + k * setup_->zhtNumCells()]);
72  swap(tmp[k], stubsCells[channel * setup_->zhtNumCells() + k]);
73  slb(tmp, streams[channel], lost[channel]);
74  }
75  }
76  // fill output product
77  for (int channel = 0; channel < dataFormats_->numChannel(Process::mht); channel++) {
78  deque<StubZHT*>& stubs = streams[channel];
79  StreamStub& stream = accepted[region_ * dataFormats_->numChannel(Process::mht) + channel];
80  merge(stubs, stream);
81  }
82  }
void merge(std::deque< StubZHT *> &stubs, tt::StreamStub &stream) const
void slb(std::vector< std::deque< StubZHT *>> &inputs, std::deque< StubZHT *> &accepted, tt::StreamStub &lost) const
int zhtNumStages() const
Definition: Setup.h:467
std::vector< FrameStub > StreamStub
Definition: TTTypes.h:63
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:117
int numChannel(Process p) const
Definition: DataFormats.h:498
void fill(int channel, const std::deque< StubZHT *> &input, std::vector< std::deque< StubZHT *>> &output)
std::vector< std::vector< StubZHT * > > input_
int zhtNumCells() const
Definition: Setup.h:475
const DataFormats * dataFormats_
tmp
align.sh
Definition: createJobs.py:716

◆ slb()

void trackerTFP::ZHoughTransform::slb ( std::vector< std::deque< StubZHT *>> &  inputs,
std::deque< StubZHT *> &  accepted,
tt::StreamStub lost 
) const
private

Definition at line 212 of file ZHoughTransform.cc.

References ztail::d, relativeConstraints::empty, remoteMonitoring_LED_IterMethod_cfg::enable, enableTruncation_, PixelMapPlotter::inputs, remoteMonitoring_LASER_era2018_cfg::limit, GetRecoTauVFromDQM_MC_cff::next, tt::Setup::numFrames(), or, pop_front(), setup_, validateGeometry_cfg::valid, and tt::Setup::zhtNumCells().

Referenced by produce().

212  {
213  accepted.clear();
214  if (all_of(inputs.begin(), inputs.end(), [](const deque<StubZHT*>& stubs) { return stubs.empty(); }))
215  return;
216  // input fifos
217  vector<deque<StubZHT*>> stacks(setup_->zhtNumCells());
218  // helper for handshake
219  TTBV empty(-1, setup_->zhtNumCells(), true);
220  TTBV enable(0, setup_->zhtNumCells());
221  // clock accurate firmware emulation, each while trip describes one clock tick, one stub in and one stub out per tick
222  while (!all_of(inputs.begin(), inputs.end(), [](const deque<StubZHT*>& d) { return d.empty(); }) or
223  !all_of(stacks.begin(), stacks.end(), [](const deque<StubZHT*>& d) { return d.empty(); })) {
224  // store stub in fifo
225  for (int channel = 0; channel < setup_->zhtNumCells(); channel++) {
226  StubZHT* stub = pop_front(inputs[channel]);
227  if (stub)
228  stacks[channel].push_back(stub);
229  }
230  // identify empty fifos
231  for (int channel = 0; channel < setup_->zhtNumCells(); channel++)
232  empty[channel] = stacks[channel].empty();
233  // chose new fifo to read from if current fifo got empty
234  const int iEnableOld = enable.plEncode();
235  if (enable.none() || empty[iEnableOld]) {
236  enable.reset();
237  const int iNotEmpty = empty.plEncode(false);
238  if (iNotEmpty < setup_->zhtNumCells())
239  enable.set(iNotEmpty);
240  }
241  // read from chosen fifo
242  const int iEnable = enable.plEncode();
243  if (enable.any())
244  accepted.push_back(pop_front(stacks[iEnable]));
245  else
246  // gap if no fifo has been chosen
247  accepted.push_back(nullptr);
248  }
249  // perform truncation if desired
250  if (enableTruncation_ && (int)accepted.size() > setup_->numFrames()) {
251  const auto limit = next(accepted.begin(), setup_->numFrames());
252  auto valid = [](int sum, StubZHT* stub) { return sum + (stub ? 1 : 0); };
253  const int nLost = accumulate(limit, accepted.end(), 0, valid);
254  lost.reserve(nLost);
255  for (auto it = limit; it != accepted.end(); it++)
256  if (*it)
257  lost.emplace_back((*it)->frame());
258  accepted.erase(limit, accepted.end());
259  }
260  // cosmetics -- remove gaps at the end of stream
261  for (auto it = accepted.end(); it != accepted.begin();)
262  it = (*--it) == nullptr ? accepted.erase(it) : accepted.begin();
263  }
Bit vector used by Track Trigger emulators. Mainly used to convert integers into arbitrary (within ma...
Definition: TTBV.h:20
int numFrames() const
Definition: Setup.h:153
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
d
Definition: ztail.py:151
T * pop_front(std::deque< T *> &ts) const
int zhtNumCells() const
Definition: Setup.h:475

Member Data Documentation

◆ dataFormats_

const DataFormats* trackerTFP::ZHoughTransform::dataFormats_
private

Definition at line 43 of file ZHoughTransform.h.

Referenced by consume(), fill(), and produce().

◆ enableTruncation_

bool trackerTFP::ZHoughTransform::enableTruncation_
private

Definition at line 39 of file ZHoughTransform.h.

Referenced by slb().

◆ input_

std::vector<std::vector<StubZHT*> > trackerTFP::ZHoughTransform::input_
private

Definition at line 49 of file ZHoughTransform.h.

Referenced by consume(), and produce().

◆ region_

int trackerTFP::ZHoughTransform::region_
private

Definition at line 45 of file ZHoughTransform.h.

Referenced by consume(), and produce().

◆ setup_

const tt::Setup* trackerTFP::ZHoughTransform::setup_
private

◆ stage_

int trackerTFP::ZHoughTransform::stage_
private

Definition at line 51 of file ZHoughTransform.h.

Referenced by fill(), and produce().

◆ stubsZHT_

std::vector<StubZHT> trackerTFP::ZHoughTransform::stubsZHT_
private

Definition at line 47 of file ZHoughTransform.h.

Referenced by consume(), and fill().