CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
trklet::MatchCalculator Class Reference

#include <MatchCalculator.h>

Inheritance diagram for trklet::MatchCalculator:
trklet::ProcessBase

Public Member Functions

void addInput (MemoryBase *memory, std::string input) override
 
void addOutput (MemoryBase *memory, std::string output) override
 
void execute (unsigned int iSector, double phioffset)
 
 MatchCalculator (std::string name, Settings const &settings, Globals *global)
 
std::vector< std::pair< std::pair< Tracklet *, int >, const Stub * > > mergeMatches (std::vector< CandidateMatchMemory *> &candmatch)
 
 ~MatchCalculator () override=default
 
- Public Member Functions inherited from trklet::ProcessBase
unsigned int getISeed (const std::string &name)
 
std::string const & getName () const
 
void initLayerDisk (unsigned int pos, int &layer, int &disk)
 
void initLayerDisk (unsigned int pos, int &layer, int &disk, int &layerdisk)
 
unsigned int initLayerDisk (unsigned int pos)
 
void initLayerDisksandISeed (unsigned int &layerdisk1, unsigned int &layerdisk2, unsigned int &iSeed)
 
unsigned int nbits (unsigned int power)
 
 ProcessBase (std::string name, Settings const &settings, Globals *global)
 
virtual ~ProcessBase ()=default
 

Private Attributes

AllProjectionsMemoryallprojs_
 
AllStubsMemoryallstubs_
 
int fact_
 
std::vector< FullMatchMemory * > fullMatches_
 
int ialphafactinner_ [N_DSS_MOD *2]
 
int ialphafactouter_ [N_DSS_MOD *2]
 
int icorrshift_
 
int icorzshift_
 
unsigned int layerdisk_
 
std::vector< CandidateMatchMemory * > matches_
 
int phi0shift_
 
TrackletLUT phimatchcuttable_
 
unsigned int phiregion_
 
TrackletLUT rcut2Stable_
 
TrackletLUT rcutPStable_
 
TrackletLUT rphicut2Stable_
 
TrackletLUT rphicutPStable_
 
TrackletLUT zmatchcuttable_
 

Additional Inherited Members

- Protected Attributes inherited from trklet::ProcessBase
Globalsglobals_
 
std::string name_
 
Settings const & settings_
 

Detailed Description

Definition at line 22 of file MatchCalculator.h.

Constructor & Destructor Documentation

◆ MatchCalculator()

MatchCalculator::MatchCalculator ( std::string  name,
Settings const &  settings,
Globals global 
)

Definition at line 22 of file MatchCalculator.cc.

References trklet::Settings::alphashift(), cms::cuda::assert(), fact_, fullMatches_, trklet::ProcessBase::getName(), trklet::Settings::half2SmoduleWidth(), mps_fire::i, ialphafactinner_, ialphafactouter_, icorrshift_, icorzshift_, trklet::ProcessBase::initLayerDisk(), trklet::TrackletLUT::initmatchcut(), trklet::Settings::kphi(), trklet::Settings::krprojshiftdisk(), layerdisk_, trklet::N_DSS_MOD, trklet::N_LAYER, trklet::N_PSLAYER, trklet::Settings::nallstubs(), Skims_PA_cff::name, trklet::Settings::nbitsalpha(), trklet::Settings::nrbitsstub(), trklet::Settings::nzbitsstub(), phi0shift_, phimatchcuttable_, phiregion_, trklet::Settings::PS_zderL_shift(), rcut2Stable_, rcutPStable_, trklet::Settings::rDSSinner(), trklet::Settings::rDSSouter(), HLT_2023v12_cff::region, rphicut2Stable_, rphicutPStable_, trklet::ProcessBase::settings_, trklet::Settings::SS_zderL_shift(), and zmatchcuttable_.

23  : ProcessBase(name, settings, global),
24  phimatchcuttable_(settings),
25  zmatchcuttable_(settings),
26  rphicutPStable_(settings),
27  rphicut2Stable_(settings),
28  rcutPStable_(settings),
29  rcut2Stable_(settings) {
30  phiregion_ = name[8] - 'A';
32 
33  fullMatches_.resize(12, nullptr);
34 
35  //TODO - need to sort out constants here
36  icorrshift_ = 7;
37 
38  if (layerdisk_ < N_PSLAYER) {
40  } else {
42  }
43  phi0shift_ = 3;
44  fact_ = 1;
45  if (layerdisk_ >= N_PSLAYER && layerdisk_ < N_LAYER) {
46  fact_ = (1 << (settings_.nzbitsstub(0) - settings_.nzbitsstub(5)));
50  phi0shift_ = 0;
51  }
52 
53  unsigned int region = getName()[8] - 'A';
55 
56  if (layerdisk_ < N_LAYER) {
57  phimatchcuttable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::barrelphi, region);
58  zmatchcuttable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::barrelz, region);
59  } else {
60  rphicutPStable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::diskPSphi, region);
61  rphicut2Stable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::disk2Sphi, region);
62  rcutPStable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::diskPSr, region);
63  rcut2Stable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::disk2Sr, region);
64  }
65 
66  for (unsigned int i = 0; i < N_DSS_MOD * 2; i++) {
68  (1 << (settings_.nbitsalpha() - 1)) / (settings_.rDSSinner(i) * settings_.rDSSinner(i)) /
69  settings_.kphi();
71  (1 << (settings_.nbitsalpha() - 1)) / (settings_.rDSSouter(i) * settings_.rDSSouter(i)) /
72  settings_.kphi();
73  }
74 }
int PS_zderL_shift() const
Definition: Settings.h:364
unsigned int nrbitsstub(unsigned int layerdisk) const
Definition: Settings.h:84
void initmatchcut(unsigned int layerdisk, MatchType type, unsigned int region)
Definition: TrackletLUT.cc:14
double rDSSinner(unsigned int iBin) const
Definition: Settings.h:171
Settings const & settings_
Definition: ProcessBase.h:40
constexpr unsigned int N_DSS_MOD
Definition: Settings.h:27
assert(be >=bs)
ProcessBase(std::string name, Settings const &settings, Globals *global)
Definition: ProcessBase.cc:14
double half2SmoduleWidth() const
Definition: Settings.h:131
unsigned int nzbitsstub(unsigned int layerdisk) const
Definition: Settings.h:82
double rDSSouter(unsigned int iBin) const
Definition: Settings.h:174
int alphashift() const
Definition: Settings.h:216
void initLayerDisk(unsigned int pos, int &layer, int &disk)
Definition: ProcessBase.cc:33
unsigned int nallstubs(unsigned int layerdisk) const
Definition: Settings.h:107
constexpr unsigned int N_PSLAYER
Definition: Settings.h:23
int ialphafactouter_[N_DSS_MOD *2]
int nbitsalpha() const
Definition: Settings.h:217
double krprojshiftdisk() const
Definition: Settings.h:413
int ialphafactinner_[N_DSS_MOD *2]
double kphi() const
Definition: Settings.h:310
std::string const & getName() const
Definition: ProcessBase.h:22
int SS_zderL_shift() const
Definition: Settings.h:365
std::vector< FullMatchMemory * > fullMatches_
constexpr int N_LAYER
Definition: Settings.h:21

◆ ~MatchCalculator()

trklet::MatchCalculator::~MatchCalculator ( )
overridedefault

Member Function Documentation

◆ addInput()

void MatchCalculator::addInput ( MemoryBase memory,
std::string  input 
)
overridevirtual

Implements trklet::ProcessBase.

Definition at line 91 of file MatchCalculator.cc.

References allprojs_, allstubs_, cms::cuda::assert(), Exception, input, matches_, mps_setup::memory, trklet::ProcessBase::name_, trklet::ProcessBase::settings_, createJobs::tmp, and trklet::Settings::writetrace().

91  {
92  if (settings_.writetrace()) {
93  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input "
94  << input;
95  }
96  if (input == "allstubin") {
97  auto* tmp = dynamic_cast<AllStubsMemory*>(memory);
98  assert(tmp != nullptr);
99  allstubs_ = tmp;
100  return;
101  }
102  if (input == "allprojin") {
103  auto* tmp = dynamic_cast<AllProjectionsMemory*>(memory);
104  assert(tmp != nullptr);
105  allprojs_ = tmp;
106  return;
107  }
108  if (input.substr(0, 5) == "match" && input.substr(input.size() - 2, 2) == "in") {
109  auto* tmp = dynamic_cast<CandidateMatchMemory*>(memory);
110  assert(tmp != nullptr);
111  matches_.push_back(tmp);
112  return;
113  }
114  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find input " << input;
115 }
Log< level::Info, true > LogVerbatim
std::string name_
Definition: ProcessBase.h:38
Settings const & settings_
Definition: ProcessBase.h:40
bool writetrace() const
Definition: Settings.h:183
assert(be >=bs)
static std::string const input
Definition: EdmProvDump.cc:50
AllStubsMemory * allstubs_
std::vector< CandidateMatchMemory * > matches_
AllProjectionsMemory * allprojs_
tmp
align.sh
Definition: createJobs.py:716

◆ addOutput()

void MatchCalculator::addOutput ( MemoryBase memory,
std::string  output 
)
overridevirtual

Implements trklet::ProcessBase.

Definition at line 76 of file MatchCalculator.cc.

References cms::cuda::assert(), Exception, fullMatches_, trklet::ProcessBase::getISeed(), mps_setup::memory, trklet::ProcessBase::name_, convertSQLitetoXML_cfg::output, trklet::ProcessBase::settings_, createJobs::tmp, and trklet::Settings::writetrace().

76  {
77  if (settings_.writetrace()) {
78  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output "
79  << output;
80  }
81  if (output.substr(0, 8) == "matchout") {
82  auto* tmp = dynamic_cast<FullMatchMemory*>(memory);
83  assert(tmp != nullptr);
84  unsigned int iSeed = getISeed(memory->getName());
85  fullMatches_[iSeed] = tmp;
86  return;
87  }
88  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find output " << output;
89 }
Log< level::Info, true > LogVerbatim
std::string name_
Definition: ProcessBase.h:38
Settings const & settings_
Definition: ProcessBase.h:40
bool writetrace() const
Definition: Settings.h:183
assert(be >=bs)
unsigned int getISeed(const std::string &name)
Definition: ProcessBase.cc:119
tmp
align.sh
Definition: createJobs.py:716
std::vector< FullMatchMemory * > fullMatches_

◆ execute()

void MatchCalculator::execute ( unsigned int  iSector,
double  phioffset 
)

Definition at line 117 of file MatchCalculator.cc.

References funct::abs(), trklet::Tracklet::addMatch(), trklet::Stub::alpha(), trklet::L1TStub::alphanorm(), trklet::Settings::alphashift(), cms::cuda::assert(), trklet::Settings::bfield(), trklet::Settings::bookHistos(), trklet::Settings::c(), trklet::Settings::debugTracklet(), trklet::Tracklet::disk(), trklet::Settings::doKF(), trklet::Settings::doMultipleMatches(), trklet::Settings::dphisectorHG(), trklet::Settings::drmax(), PVValHelper::dz, trklet::Settings::dzmax(), Exception, fact_, fullMatches_, trklet::Tracklet::getISeed(), trklet::ProcessBase::getName(), trklet::ProcessBase::globals_, trklet::Settings::half2SmoduleWidth(), trklet::Globals::histograms(), compare::hists, ialphafactinner_, ialphafactouter_, icorrshift_, icorzshift_, createfilelist::int, LEDCalibrationChannels::iphi, trklet::L1TStub::isPSmodule(), dqmiolumiharvest::j, runTheMatrix::keep, trklet::Settings::kphi(), trklet::Settings::kphi1(), trklet::Settings::kr(), trklet::Settings::krprojshiftdisk(), trklet::Settings::kz(), trklet::Stub::l1tstub(), trklet::Tracklet::layer(), layerdisk_, trklet::TrackletLUT::lookup(), M_PI, trklet::Tracklet::match(), matches_, trklet::Settings::maxStep(), mergeMatches(), SiStripPI::min, trklet::N_DSS_MOD, trklet::N_LAYER, trklet::ProcessBase::name_, trklet::Globals::ofstream(), trklet::Stub::phi(), trklet::L1TStub::phi(), trklet::Settings::phi0bitshift(), phi0shift_, trklet::Stub::phiapprox(), phimatchcuttable_, phiregion_, amptDefault_cfi::proj, trklet::Tracklet::proj(), DiDispStaMuonMonitor_cfi::pt, trklet::Stub::r(), trklet::L1TStub::r(), trklet::L1TStub::r2(), trklet::Stub::rapprox(), rcut2Stable_, rcutPStable_, trklet::Settings::rDSSinner(), trklet::Settings::rDSSouter(), reco::reduceRange(), trklet::Tracklet::resid(), trklet::Tracklet::rinv(), trklet::Settings::rmean(), rphicut2Stable_, rphicutPStable_, edm::second(), trklet::ProcessBase::settings_, Validation_hcalonly_cfi::sign, trklet::Stub::stubindex(), trklet::Tracklet::stubtruthmatch(), trklet::Tracklet::t(), trklet::Tracklet::TCID(), trklet::third, trklet::Settings::useapprox(), trklet::FPGAWord::value(), trklet::Settings::writeMonitorData(), trklet::L1TStub::z(), trklet::Stub::z(), trklet::Stub::zapprox(), zmatchcuttable_, and trklet::Settings::zmean().

117  {
118  unsigned int countall = 0;
119  unsigned int countsel = 0;
120 
121  //bool print = getName() == "MC_L4PHIC" && iSector == 3;
122 
123  Tracklet* oldTracklet = nullptr;
124 
125  std::vector<std::pair<std::pair<Tracklet*, int>, const Stub*> > mergedMatches = mergeMatches(matches_);
126 
127  // Number of clock cycles the pipeline in HLS takes to process the projection merging to
128  // produce the first projectio
129  unsigned int mergedepth = 3;
130 
131  unsigned int maxProc = std::min(settings_.maxStep("MC") - mergedepth, (unsigned int)mergedMatches.size());
132 
133  for (unsigned int j = 0; j < maxProc; j++) {
134  if (settings_.debugTracklet() && j == 0) {
135  edm::LogVerbatim("Tracklet") << getName() << " has " << mergedMatches.size() << " candidate matches";
136  }
137 
138  countall++;
139 
140  const Stub* fpgastub = mergedMatches[j].second;
141  Tracklet* tracklet = mergedMatches[j].first.first;
142  const L1TStub* stub = fpgastub->l1tstub();
143 
144  //check that the matches are orderd correctly
145  //allow equal here since we can have more than one cadidate match per tracklet projection
146  if (oldTracklet != nullptr) {
147  assert(oldTracklet->TCID() <= tracklet->TCID());
148  }
149  oldTracklet = tracklet;
150 
151  if (layerdisk_ < N_LAYER) {
152  //Integer calculation
153 
154  const Projection& proj = tracklet->proj(layerdisk_);
155 
156  int ir = fpgastub->r().value();
157  int iphi = proj.fpgaphiproj().value();
158  int icorr = (ir * proj.fpgaphiprojder().value()) >> icorrshift_;
159  iphi += icorr;
160 
161  int iz = proj.fpgarzproj().value();
162  int izcor = (ir * proj.fpgarzprojder().value() + (1 << (icorzshift_ - 1))) >> icorzshift_;
163  iz += izcor;
164 
165  int ideltaz = fpgastub->z().value() - iz;
166  int ideltaphi = (fpgastub->phi().value() << phi0shift_) - (iphi << (settings_.phi0bitshift() - 1 + phi0shift_));
167 
168  //Floating point calculations
169 
170  double phi = stub->phi() - phioffset;
171  double r = stub->r();
172  double z = stub->z();
173 
174  if (settings_.useapprox()) {
175  double dphi = reco::reduceRange(phi - fpgastub->phiapprox(0.0, 0.0));
176  assert(std::abs(dphi) < 0.001);
177  phi = fpgastub->phiapprox(0.0, 0.0);
178  z = fpgastub->zapprox();
179  r = fpgastub->rapprox();
180  }
181 
182  if (phi < 0)
183  phi += 2 * M_PI;
184 
185  double dr = r - settings_.rmean(layerdisk_);
187 
188  double dphi = reco::reduceRange(phi - (proj.phiproj() + dr * proj.phiprojder()));
189 
190  double dz = z - (proj.rzproj() + dr * proj.rzprojder());
191 
192  double dphiapprox = reco::reduceRange(phi - (proj.phiprojapprox() + dr * proj.phiprojderapprox()));
193 
194  double dzapprox = z - (proj.rzprojapprox() + dr * proj.rzprojderapprox());
195 
196  int seedindex = tracklet->getISeed();
197 
198  assert(phimatchcuttable_.lookup(seedindex) > 0);
199  assert(zmatchcuttable_.lookup(seedindex) > 0);
200 
201  if (settings_.bookHistos()) {
202  bool truthmatch = tracklet->stubtruthmatch(stub);
203 
205  hists->FillLayerResidual(layerdisk_ + 1,
206  seedindex,
207  dphiapprox * settings_.rmean(layerdisk_),
208  ideltaphi * settings_.kphi1() * settings_.rmean(layerdisk_),
209  ideltaz * fact_ * settings_.kz(),
210  dz,
211  truthmatch);
212  }
213 
214  //This would catch significant consistency problems in the configuration - helps to debug if there are problems.
215  if (std::abs(dphi) > 0.5 * settings_.dphisectorHG() || std::abs(dphiapprox) > 0.5 * settings_.dphisectorHG()) {
216  throw cms::Exception("LogicError")
217  << "WARNING dphi and/or dphiapprox too large : " << dphi << " " << dphiapprox << endl;
218  }
219 
220  if (settings_.writeMonitorData("Residuals")) {
221  double pt = 0.01 * settings_.c() * settings_.bfield() / std::abs(tracklet->rinv());
222 
223  globals_->ofstream("layerresiduals.txt")
224  << layerdisk_ + 1 << " " << seedindex << " " << pt << " "
225  << ideltaphi * settings_.kphi1() * settings_.rmean(layerdisk_) << " "
226  << dphiapprox * settings_.rmean(layerdisk_) << " "
227  << phimatchcuttable_.lookup(seedindex) * settings_.kphi1() * settings_.rmean(layerdisk_) << " "
228  << ideltaz * fact_ * settings_.kz() << " " << dz << " "
229  << zmatchcuttable_.lookup(seedindex) * settings_.kz() << endl;
230  }
231 
232  bool imatch = (std::abs(ideltaphi) <= (int)phimatchcuttable_.lookup(seedindex)) &&
233  (ideltaz * fact_ < (int)zmatchcuttable_.lookup(seedindex)) &&
234  (ideltaz * fact_ >= -(int)zmatchcuttable_.lookup(seedindex));
235 
236  bool keep = true;
237  if (!settings_.doKF() || !settings_.doMultipleMatches()) {
238  // Case of allowing only one stub per track per layer (or no KF which implies the same).
239  if (imatch && tracklet->match(layerdisk_)) {
240  // Veto match if is not the best one for this tracklet (in given layer)
241  auto res = tracklet->resid(layerdisk_);
242  keep = abs(ideltaphi) < abs(res.fpgaphiresid().value());
243  imatch = keep;
244  }
245  }
246 
247  if (settings_.debugTracklet()) {
248  edm::LogVerbatim("Tracklet") << getName() << " imatch = " << imatch << " keep = " << keep << " ideltaphi cut "
249  << ideltaphi << " " << phimatchcuttable_.lookup(seedindex) << " ideltaz*fact cut "
250  << ideltaz * fact_ << " " << zmatchcuttable_.lookup(seedindex);
251  }
252 
253  if (imatch) {
254  countsel++;
255 
256  // TO DO: storing the matches in both FullMatchMemory & Tracklet is ugly.
257  // Should clean this up, to avoid the need to store them in Tracklet.
258 
259  tracklet->addMatch(layerdisk_,
260  ideltaphi,
261  ideltaz,
262  dphi,
263  dz,
264  dphiapprox,
265  dzapprox,
266  (phiregion_ << 7) + fpgastub->stubindex().value(),
267  mergedMatches[j].second);
268 
269  if (settings_.debugTracklet()) {
270  edm::LogVerbatim("Tracklet") << "Accepted full match in layer " << getName() << " " << tracklet;
271  }
272 
273  fullMatches_[seedindex]->addMatch(tracklet, mergedMatches[j].second);
274  }
275  } else { //disk matches
276 
277  //check that stubs and projections in same half of detector
278  assert(stub->z() * tracklet->t() > 0.0);
279 
280  int sign = (tracklet->t() > 0.0) ? 1 : -1;
281  int disk = sign * (layerdisk_ - (N_LAYER - 1));
282  assert(disk != 0);
283 
284  //Perform integer calculations here
285 
286  const Projection& proj = tracklet->proj(layerdisk_);
287 
288  int iz = fpgastub->z().value();
289  int iphi = proj.fpgaphiproj().value();
290 
291  //TODO - need to express interms of constants
292  int shifttmp = 6;
293  int iphicorr = (iz * proj.fpgaphiprojder().value()) >> shifttmp;
294 
295  iphi += iphicorr;
296 
297  int ir = proj.fpgarzproj().value();
298 
299  //TODO - need to express interms of constants
300  int shifttmp2 = 7;
301  int ircorr = (iz * proj.fpgarzprojder().value()) >> shifttmp2;
302 
303  ir += ircorr;
304 
305  int ideltaphi = fpgastub->phi().value() * settings_.kphi() / settings_.kphi() - iphi;
306  int irstub = fpgastub->r().value();
307  int ialphafact = 0;
308  if (!stub->isPSmodule()) {
309  assert(irstub < (int)N_DSS_MOD * 2);
310  if (abs(disk) <= 2) {
311  ialphafact = ialphafactinner_[irstub];
312  irstub = settings_.rDSSinner(irstub) / settings_.kr();
313  } else {
314  ialphafact = ialphafactouter_[irstub];
315  irstub = settings_.rDSSouter(irstub) / settings_.kr();
316  }
317  }
318 
319  //TODO stub and projection r should not use different # bits...
320  int ideltar = (irstub >> 1) - ir;
321 
322  if (!stub->isPSmodule()) {
323  int ialpha = fpgastub->alpha().value();
324  int iphialphacor = ((ideltar * ialpha * ialphafact) >> settings_.alphashift());
325  ideltaphi += iphialphacor;
326  }
327 
328  //Perform floating point calculations here
329 
330  double phi = stub->phi() - phioffset;
331  double z = stub->z();
332  double r = stub->r();
333 
334  if (settings_.useapprox()) {
335  double dphi = reco::reduceRange(phi - fpgastub->phiapprox(0.0, 0.0));
336  assert(std::abs(dphi) < 0.001);
337  phi = fpgastub->phiapprox(0.0, 0.0);
338  z = fpgastub->zapprox();
339  r = fpgastub->rapprox();
340  }
341 
342  if (phi < 0)
343  phi += 2 * M_PI;
344 
345  double dz = z - sign * settings_.zmean(layerdisk_ - N_LAYER);
346 
347  if (std::abs(dz) > settings_.dzmax()) {
348  throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " " << name_ << " " << tracklet->getISeed()
349  << "\n stub " << stub->z() << " disk " << disk << " " << dz;
350  }
351 
352  double phiproj = proj.phiproj() + dz * proj.phiprojder();
353 
354  double rproj = proj.rzproj() + dz * proj.rzprojder();
355 
356  double deltar = r - rproj;
357 
358  double dr = stub->r() - rproj;
359 
360  double dphi = reco::reduceRange(phi - phiproj);
361 
362  double dphiapprox = reco::reduceRange(phi - (proj.phiprojapprox() + dz * proj.phiprojderapprox()));
363 
364  double drapprox = stub->r() - (proj.rzprojapprox() + dz * proj.rzprojderapprox());
365 
366  double drphi = dphi * stub->r();
367  double drphiapprox = dphiapprox * stub->r();
368 
369  if (!stub->isPSmodule()) {
370  double alphanorm = stub->alphanorm();
371  dphi += dr * alphanorm * settings_.half2SmoduleWidth() / stub->r2();
372  dphiapprox += drapprox * alphanorm * settings_.half2SmoduleWidth() / stub->r2();
373 
374  drphi += dr * alphanorm * settings_.half2SmoduleWidth() / stub->r();
375  drphiapprox += dr * alphanorm * settings_.half2SmoduleWidth() / stub->r();
376  }
377 
378  int seedindex = tracklet->getISeed();
379 
380  int idrphicut = rphicutPStable_.lookup(seedindex);
381  int idrcut = rcutPStable_.lookup(seedindex);
382  if (!stub->isPSmodule()) {
383  idrphicut = rphicut2Stable_.lookup(seedindex);
384  idrcut = rcut2Stable_.lookup(seedindex);
385  }
386 
387  double drphicut = idrphicut * settings_.kphi() * settings_.kr();
388  double drcut = idrcut * settings_.krprojshiftdisk();
389 
390  bool match, imatch;
391  if (std::abs(dphi) < third * settings_.dphisectorHG() &&
392  std::abs(dphiapprox) < third * settings_.dphisectorHG()) { //1/3 of sector size to catch errors
393  if (settings_.writeMonitorData("Residuals")) {
394  double pt = 0.01 * settings_.c() * settings_.bfield() / std::abs(tracklet->rinv());
395 
396  globals_->ofstream("diskresiduals.txt")
397  << disk << " " << stub->isPSmodule() << " " << tracklet->layer() << " " << abs(tracklet->disk()) << " "
398  << pt << " " << ideltaphi * settings_.kphi() * stub->r() << " " << drphiapprox << " " << drphicut << " "
399  << ideltar * settings_.krprojshiftdisk() << " " << deltar << " " << drcut << " " << endl;
400  }
401 
402  match = (std::abs(drphi) < drphicut) && (std::abs(deltar) < drcut);
403 
404  imatch = (std::abs(ideltaphi * irstub) < idrphicut) && (std::abs(ideltar) < idrcut);
405  } else {
406  edm::LogProblem("Tracklet") << "WARNING dphi and/or dphiapprox too large : " << dphi << " " << dphiapprox
407  << "dphi " << dphi << " Seed / ISeed " << tracklet->getISeed() << endl;
408  match = false;
409  imatch = false;
410  }
411 
412  bool keep = true;
413  if (!settings_.doKF() || !settings_.doMultipleMatches()) {
414  // Case of allowing only one stub per track per layer (or no KF which implies the same).
415  if (imatch && tracklet->match(layerdisk_)) {
416  // Veto match if is not the best one for this tracklet (in given layer)
417  auto res = tracklet->resid(layerdisk_);
418  keep = abs(ideltaphi) < abs(res.fpgaphiresid().value());
419  imatch = keep;
420  }
421  }
422  if (not keep)
423  match = false; // FIX: should calc keep with float point here.
424 
425  if (settings_.debugTracklet()) {
426  edm::LogVerbatim("Tracklet") << "imatch match disk: " << imatch << " " << match << " keep = " << keep << " "
427  << std::abs(ideltaphi) << " " << drphicut / (settings_.kphi() * stub->r()) << " "
428  << std::abs(ideltar) << " " << drcut / settings_.krprojshiftdisk()
429  << " r = " << stub->r();
430  }
431 
432  if (imatch) {
433  countsel++;
434 
435  if (settings_.debugTracklet()) {
436  edm::LogVerbatim("Tracklet") << "MatchCalculator found match in disk " << getName();
437  }
438 
439  tracklet->addMatch(layerdisk_,
440  ideltaphi,
441  ideltar,
442  drphi / stub->r(),
443  dr,
444  drphiapprox / stub->r(),
445  drapprox,
446  (phiregion_ << 7) + fpgastub->stubindex().value(),
447  fpgastub);
448 
449  if (settings_.debugTracklet()) {
450  edm::LogVerbatim("Tracklet") << "Accepted full match in disk " << getName() << " " << tracklet;
451  }
452 
453  fullMatches_[seedindex]->addMatch(tracklet, mergedMatches[j].second);
454  }
455  }
456  if (countall >= settings_.maxStep("MC"))
457  break;
458  }
459 
460  if (settings_.writeMonitorData("MC")) {
461  globals_->ofstream("matchcalculator.txt") << getName() << " " << countall << " " << countsel << endl;
462  }
463 }
Log< level::Info, true > LogVerbatim
double kz() const
Definition: Settings.h:314
double phi() const
Definition: L1TStub.h:65
double t() const
Definition: Tracklet.h:123
double zapprox() const
Definition: Stub.cc:158
unsigned int maxStep(std::string module) const
Definition: Settings.h:116
const FPGAWord & r() const
Definition: Stub.h:60
bool bookHistos() const
Definition: Settings.h:207
std::string name_
Definition: ProcessBase.h:38
const Residual & resid(unsigned int layerdisk)
Definition: Tracklet.h:110
int disk() const
Definition: Tracklet.cc:782
double kphi1() const
Definition: Settings.h:311
double rDSSinner(unsigned int iBin) const
Definition: Settings.h:171
constexpr T reduceRange(T x)
Definition: deltaPhi.h:18
double phiapprox(double phimin, double) const
Definition: Stub.cc:177
const FPGAWord & z() const
Definition: Stub.h:61
double dphisectorHG() const
Definition: Settings.h:292
Projection & proj(int layerdisk)
Definition: Tracklet.h:87
Settings const & settings_
Definition: ProcessBase.h:40
double z() const
Definition: L1TStub.h:59
Globals * globals_
Definition: ProcessBase.h:41
int lookup(unsigned int index) const
Definition: TrackletLUT.cc:904
double dzmax() const
Definition: Settings.h:129
constexpr unsigned int N_DSS_MOD
Definition: Settings.h:27
assert(be >=bs)
int TCID() const
Definition: Tracklet.h:214
Definition: Electron.h:6
constexpr double third
Definition: Settings.h:42
unsigned int isPSmodule() const
Definition: L1TStub.h:96
void addMatch(unsigned int layerdisk, int ideltaphi, int ideltarz, double dphi, double drz, double dphiapprox, double drzapprox, int stubid, const trklet::Stub *stubptr)
Definition: Tracklet.cc:295
U second(std::pair< T, U > const &p)
double half2SmoduleWidth() const
Definition: Settings.h:131
double rmean(unsigned int iLayer) const
Definition: Settings.h:164
double rinv() const
Definition: Tracklet.h:120
std::vector< CandidateMatchMemory * > matches_
double rDSSouter(unsigned int iBin) const
Definition: Settings.h:174
double bfield() const
Definition: Settings.h:263
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int value() const
Definition: FPGAWord.h:24
bool doMultipleMatches() const
Definition: Settings.h:242
int alphashift() const
Definition: Settings.h:216
L1TStub * l1tstub()
Definition: Stub.h:77
bool writeMonitorData(std::string module) const
Definition: Settings.h:109
double rapprox() const
Definition: Stub.cc:144
double zmean(unsigned int iDisk) const
Definition: Settings.h:167
const FPGAWord & stubindex() const
Definition: Stub.h:66
#define M_PI
bool debugTracklet() const
Definition: Settings.h:182
std::vector< std::pair< std::pair< Tracklet *, int >, const Stub * > > mergeMatches(std::vector< CandidateMatchMemory *> &candmatch)
double kr() const
Definition: Settings.h:316
double drmax() const
Definition: Settings.h:128
double alphanorm() const
Definition: L1TStub.cc:90
bool stubtruthmatch(const L1TStub *stub)
Definition: Tracklet.cc:138
Definition: deltar.py:1
int getISeed() const
Definition: Tracklet.cc:801
int ialphafactouter_[N_DSS_MOD *2]
double c() const
Definition: Settings.h:212
const FPGAWord & alpha() const
Definition: Stub.h:64
double r() const
Definition: L1TStub.h:60
bool match(unsigned int layerdisk)
Definition: Tracklet.h:105
std::ofstream & ofstream(std::string fname)
Definition: Globals.cc:44
HistBase *& histograms()
Definition: Globals.h:38
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
double krprojshiftdisk() const
Definition: Settings.h:413
const FPGAWord & phi() const
Definition: Stub.h:62
int ialphafactinner_[N_DSS_MOD *2]
int layer() const
Definition: Tracklet.cc:773
double kphi() const
Definition: Settings.h:310
bool doKF() const
Definition: Settings.h:241
double r2() const
Definition: L1TStub.h:62
std::string const & getName() const
Definition: ProcessBase.h:22
std::vector< FullMatchMemory * > fullMatches_
bool useapprox() const
Definition: Settings.h:235
Log< level::Error, true > LogProblem
int phi0bitshift() const
Definition: Settings.h:375
constexpr int N_LAYER
Definition: Settings.h:21

◆ mergeMatches()

std::vector< std::pair< std::pair< Tracklet *, int >, const Stub * > > MatchCalculator::mergeMatches ( std::vector< CandidateMatchMemory *> &  candmatch)

Definition at line 465 of file MatchCalculator.cc.

References funct::abs(), cms::cuda::assert(), relativeConstraints::error, dqmdumpme::first, trklet::ProcessBase::getName(), mps_fire::i, layerdisk_, trklet::N_LAYER, trklet::N_SECTOR, and createJobs::tmp.

Referenced by execute().

466  {
467  std::vector<std::pair<std::pair<Tracklet*, int>, const Stub*> > tmp;
468 
469  std::vector<unsigned int> indexArray;
470  indexArray.reserve(candmatch.size());
471  for (unsigned int i = 0; i < candmatch.size(); i++) {
472  indexArray.push_back(0);
473  }
474 
475  int bestIndex = -1;
476  do {
477  int bestSector = 100;
478  int bestTCID = -1;
479  bestIndex = -1;
480  for (unsigned int i = 0; i < candmatch.size(); i++) {
481  if (indexArray[i] >= candmatch[i]->nMatches()) {
482  // skip as we were at the end
483  continue;
484  }
485  int TCID = candmatch[i]->getMatch(indexArray[i]).first.first->TCID();
486  int dSector = 0;
487  if (dSector > 2)
488  dSector -= N_SECTOR;
489  if (dSector < -2)
490  dSector += N_SECTOR;
491  assert(abs(dSector) < 2);
492  if (dSector == -1)
493  dSector = 2;
494  if (dSector < bestSector) {
495  bestSector = dSector;
496  bestTCID = TCID;
497  bestIndex = i;
498  }
499  if (dSector == bestSector) {
500  if (TCID < bestTCID || bestTCID < 0) {
501  bestTCID = TCID;
502  bestIndex = i;
503  }
504  }
505  }
506  if (bestIndex != -1) {
507  tmp.push_back(candmatch[bestIndex]->getMatch(indexArray[bestIndex]));
508  indexArray[bestIndex]++;
509  }
510  } while (bestIndex != -1);
511 
512  if (layerdisk_ < N_LAYER) {
513  int lastTCID = -1;
514  bool error = false;
515 
516  //Allow equal TCIDs since we can have multiple candidate matches
517  for (unsigned int i = 1; i < tmp.size(); i++) {
518  if (lastTCID > tmp[i].first.first->TCID()) {
519  edm::LogProblem("Tracklet") << "Wrong TCID ordering for projections in " << getName() << " last " << lastTCID
520  << " " << tmp[i].first.first->TCID();
521  error = true;
522  } else {
523  lastTCID = tmp[i].first.first->TCID();
524  }
525  }
526 
527  if (error) {
528  for (unsigned int i = 1; i < tmp.size(); i++) {
529  edm::LogProblem("Tracklet") << "Wrong order for in " << getName() << " " << i << " " << tmp[i].first.first
530  << " " << tmp[i].first.first->TCID();
531  }
532  }
533  }
534 
535  for (unsigned int i = 0; i < tmp.size(); i++) {
536  if (i > 0) {
537  //This allows for equal TCIDs. This means that we can e.g. have a track seeded
538  //in L1L2 that projects to both L3 and D4. The algorithm will pick up the first hit and
539  //drop the second
540 
541  assert(tmp[i - 1].first.first->TCID() <= tmp[i].first.first->TCID());
542  }
543  }
544 
545  return tmp;
546 }
assert(be >=bs)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
constexpr unsigned int N_SECTOR
Definition: Settings.h:19
tmp
align.sh
Definition: createJobs.py:716
std::string const & getName() const
Definition: ProcessBase.h:22
Log< level::Error, true > LogProblem
constexpr int N_LAYER
Definition: Settings.h:21

Member Data Documentation

◆ allprojs_

AllProjectionsMemory* trklet::MatchCalculator::allprojs_
private

Definition at line 57 of file MatchCalculator.h.

Referenced by addInput().

◆ allstubs_

AllStubsMemory* trklet::MatchCalculator::allstubs_
private

Definition at line 56 of file MatchCalculator.h.

Referenced by addInput().

◆ fact_

int trklet::MatchCalculator::fact_
private

Definition at line 40 of file MatchCalculator.h.

Referenced by execute(), and MatchCalculator().

◆ fullMatches_

std::vector<FullMatchMemory*> trklet::MatchCalculator::fullMatches_
private

Definition at line 60 of file MatchCalculator.h.

Referenced by addOutput(), execute(), and MatchCalculator().

◆ ialphafactinner_

int trklet::MatchCalculator::ialphafactinner_[N_DSS_MOD *2]
private

Definition at line 53 of file MatchCalculator.h.

Referenced by execute(), and MatchCalculator().

◆ ialphafactouter_

int trklet::MatchCalculator::ialphafactouter_[N_DSS_MOD *2]
private

Definition at line 54 of file MatchCalculator.h.

Referenced by execute(), and MatchCalculator().

◆ icorrshift_

int trklet::MatchCalculator::icorrshift_
private

Definition at line 41 of file MatchCalculator.h.

Referenced by execute(), and MatchCalculator().

◆ icorzshift_

int trklet::MatchCalculator::icorzshift_
private

Definition at line 42 of file MatchCalculator.h.

Referenced by execute(), and MatchCalculator().

◆ layerdisk_

unsigned int trklet::MatchCalculator::layerdisk_
private

Definition at line 37 of file MatchCalculator.h.

Referenced by execute(), MatchCalculator(), and mergeMatches().

◆ matches_

std::vector<CandidateMatchMemory*> trklet::MatchCalculator::matches_
private

Definition at line 59 of file MatchCalculator.h.

Referenced by addInput(), and execute().

◆ phi0shift_

int trklet::MatchCalculator::phi0shift_
private

Definition at line 43 of file MatchCalculator.h.

Referenced by execute(), and MatchCalculator().

◆ phimatchcuttable_

TrackletLUT trklet::MatchCalculator::phimatchcuttable_
private

Definition at line 45 of file MatchCalculator.h.

Referenced by execute(), and MatchCalculator().

◆ phiregion_

unsigned int trklet::MatchCalculator::phiregion_
private

Definition at line 38 of file MatchCalculator.h.

Referenced by execute(), and MatchCalculator().

◆ rcut2Stable_

TrackletLUT trklet::MatchCalculator::rcut2Stable_
private

Definition at line 51 of file MatchCalculator.h.

Referenced by execute(), and MatchCalculator().

◆ rcutPStable_

TrackletLUT trklet::MatchCalculator::rcutPStable_
private

Definition at line 50 of file MatchCalculator.h.

Referenced by execute(), and MatchCalculator().

◆ rphicut2Stable_

TrackletLUT trklet::MatchCalculator::rphicut2Stable_
private

Definition at line 49 of file MatchCalculator.h.

Referenced by execute(), and MatchCalculator().

◆ rphicutPStable_

TrackletLUT trklet::MatchCalculator::rphicutPStable_
private

Definition at line 48 of file MatchCalculator.h.

Referenced by execute(), and MatchCalculator().

◆ zmatchcuttable_

TrackletLUT trklet::MatchCalculator::zmatchcuttable_
private

Definition at line 46 of file MatchCalculator.h.

Referenced by execute(), and MatchCalculator().