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 (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 21 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_2022v14_cff::region, rphicut2Stable_, rphicutPStable_, trklet::ProcessBase::settings_, trklet::Settings::SS_zderL_shift(), and zmatchcuttable_.

22  : ProcessBase(name, settings, global),
23  phimatchcuttable_(settings),
24  zmatchcuttable_(settings),
25  rphicutPStable_(settings),
26  rphicut2Stable_(settings),
27  rcutPStable_(settings),
28  rcut2Stable_(settings) {
29  phiregion_ = name[8] - 'A';
31 
32  fullMatches_.resize(12, nullptr);
33 
34  //TODO - need to sort out constants here
35  icorrshift_ = 7;
36 
37  if (layerdisk_ < N_PSLAYER) {
39  } else {
41  }
42  phi0shift_ = 3;
43  fact_ = 1;
44  if (layerdisk_ >= N_PSLAYER && layerdisk_ < N_LAYER) {
45  fact_ = (1 << (settings_.nzbitsstub(0) - settings_.nzbitsstub(5)));
49  phi0shift_ = 0;
50  }
51 
52  unsigned int region = getName()[8] - 'A';
54 
55  if (layerdisk_ < N_LAYER) {
56  phimatchcuttable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::barrelphi, region);
57  zmatchcuttable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::barrelz, region);
58  } else {
59  rphicutPStable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::diskPSphi, region);
60  rphicut2Stable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::disk2Sphi, region);
61  rcutPStable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::diskPSr, region);
62  rcut2Stable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::disk2Sr, region);
63  }
64 
65  for (unsigned int i = 0; i < N_DSS_MOD * 2; i++) {
67  (1 << (settings_.nbitsalpha() - 1)) / (settings_.rDSSinner(i) * settings_.rDSSinner(i)) /
68  settings_.kphi();
70  (1 << (settings_.nbitsalpha() - 1)) / (settings_.rDSSouter(i) * settings_.rDSSouter(i)) /
71  settings_.kphi();
72  }
73 }
int PS_zderL_shift() const
Definition: Settings.h:352
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:400
int ialphafactinner_[N_DSS_MOD *2]
double kphi() const
Definition: Settings.h:298
std::string const & getName() const
Definition: ProcessBase.h:22
int SS_zderL_shift() const
Definition: Settings.h:353
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 90 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().

90  {
91  if (settings_.writetrace()) {
92  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input "
93  << input;
94  }
95  if (input == "allstubin") {
96  auto* tmp = dynamic_cast<AllStubsMemory*>(memory);
97  assert(tmp != nullptr);
98  allstubs_ = tmp;
99  return;
100  }
101  if (input == "allprojin") {
102  auto* tmp = dynamic_cast<AllProjectionsMemory*>(memory);
103  assert(tmp != nullptr);
104  allprojs_ = tmp;
105  return;
106  }
107  if (input.substr(0, 5) == "match" && input.substr(input.size() - 2, 2) == "in") {
108  auto* tmp = dynamic_cast<CandidateMatchMemory*>(memory);
109  assert(tmp != nullptr);
110  matches_.push_back(tmp);
111  return;
112  }
113  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find input " << input;
114 }
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 75 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().

75  {
76  if (settings_.writetrace()) {
77  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output "
78  << output;
79  }
80  if (output.substr(0, 8) == "matchout") {
81  auto* tmp = dynamic_cast<FullMatchMemory*>(memory);
82  assert(tmp != nullptr);
83  unsigned int iSeed = getISeed(memory->getName());
84  fullMatches_[iSeed] = tmp;
85  return;
86  }
87  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find output " << output;
88 }
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 ( double  phioffset)

Definition at line 116 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::dphisectorHG(), l1ctLayer1_cff::dr, 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, 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, match(), matches_, trklet::Settings::maxStep(), mergeMatches(), 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::L1TStub::r(), trklet::Stub::r(), alignCSCRings::r, trklet::L1TStub::r2(), trklet::Stub::rapprox(), rcut2Stable_, rcutPStable_, trklet::Settings::rDSSinner(), trklet::Settings::rDSSouter(), reco::reduceRange(), 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().

116  {
117  unsigned int countall = 0;
118  unsigned int countsel = 0;
119 
120  Tracklet* oldTracklet = nullptr;
121 
122  std::vector<std::pair<std::pair<Tracklet*, int>, const Stub*> > mergedMatches = mergeMatches(matches_);
123 
124  for (unsigned int j = 0; j < mergedMatches.size(); j++) {
125  if (settings_.debugTracklet() && j == 0) {
126  edm::LogVerbatim("Tracklet") << getName() << " has " << mergedMatches.size() << " candidate matches";
127  }
128 
129  countall++;
130 
131  const Stub* fpgastub = mergedMatches[j].second;
132  Tracklet* tracklet = mergedMatches[j].first.first;
133  const L1TStub* stub = fpgastub->l1tstub();
134 
135  //check that the matches are orderd correctly
136  //allow equal here since we can have more than one cadidate match per tracklet projection
137  if (oldTracklet != nullptr) {
138  assert(oldTracklet->TCID() <= tracklet->TCID());
139  }
140  oldTracklet = tracklet;
141 
142  if (layerdisk_ < N_LAYER) {
143  //Integer calculation
144 
145  const Projection& proj = tracklet->proj(layerdisk_);
146 
147  int ir = fpgastub->r().value();
148  int iphi = proj.fpgaphiproj().value();
149  int icorr = (ir * proj.fpgaphiprojder().value()) >> icorrshift_;
150  iphi += icorr;
151 
152  int iz = proj.fpgarzproj().value();
153  int izcor = (ir * proj.fpgarzprojder().value() + (1 << (icorzshift_ - 1))) >> icorzshift_;
154  iz += izcor;
155 
156  int ideltaz = fpgastub->z().value() - iz;
157  int ideltaphi = (fpgastub->phi().value() << phi0shift_) - (iphi << (settings_.phi0bitshift() - 1 + phi0shift_));
158 
159  //Floating point calculations
160 
161  double phi = stub->phi() - phioffset;
162  double r = stub->r();
163  double z = stub->z();
164 
165  if (settings_.useapprox()) {
166  double dphi = reco::reduceRange(phi - fpgastub->phiapprox(0.0, 0.0));
167  assert(std::abs(dphi) < 0.001);
168  phi = fpgastub->phiapprox(0.0, 0.0);
169  z = fpgastub->zapprox();
170  r = fpgastub->rapprox();
171  }
172 
173  if (phi < 0)
174  phi += 2 * M_PI;
175 
176  double dr = r - settings_.rmean(layerdisk_);
178 
179  double dphi = reco::reduceRange(phi - (proj.phiproj() + dr * proj.phiprojder()));
180 
181  double dz = z - (proj.rzproj() + dr * proj.rzprojder());
182 
183  double dphiapprox = reco::reduceRange(phi - (proj.phiprojapprox() + dr * proj.phiprojderapprox()));
184 
185  double dzapprox = z - (proj.rzprojapprox() + dr * proj.rzprojderapprox());
186 
187  int seedindex = tracklet->getISeed();
188 
189  assert(phimatchcuttable_.lookup(seedindex) > 0);
190  assert(zmatchcuttable_.lookup(seedindex) > 0);
191 
192  if (settings_.bookHistos()) {
193  bool truthmatch = tracklet->stubtruthmatch(stub);
194 
196  hists->FillLayerResidual(layerdisk_ + 1,
197  seedindex,
198  dphiapprox * settings_.rmean(layerdisk_),
199  ideltaphi * settings_.kphi1() * settings_.rmean(layerdisk_),
200  ideltaz * fact_ * settings_.kz(),
201  dz,
202  truthmatch);
203  }
204 
205  //This would catch significant consistency problems in the configuration - helps to debug if there are problems.
206  if (std::abs(dphi) > 0.5 * settings_.dphisectorHG() || std::abs(dphiapprox) > 0.5 * settings_.dphisectorHG()) {
207  throw cms::Exception("LogicError")
208  << "WARNING dphi and/or dphiapprox too large : " << dphi << " " << dphiapprox << endl;
209  }
210 
211  if (settings_.writeMonitorData("Residuals")) {
212  double pt = 0.01 * settings_.c() * settings_.bfield() / std::abs(tracklet->rinv());
213 
214  globals_->ofstream("layerresiduals.txt")
215  << layerdisk_ + 1 << " " << seedindex << " " << pt << " "
216  << ideltaphi * settings_.kphi1() * settings_.rmean(layerdisk_) << " "
217  << dphiapprox * settings_.rmean(layerdisk_) << " "
218  << phimatchcuttable_.lookup(seedindex) * settings_.kphi1() * settings_.rmean(layerdisk_) << " "
219  << ideltaz * fact_ * settings_.kz() << " " << dz << " "
220  << zmatchcuttable_.lookup(seedindex) * settings_.kz() << endl;
221  }
222 
223  bool imatch = (std::abs(ideltaphi) <= (int)phimatchcuttable_.lookup(seedindex)) &&
224  (std::abs(ideltaz * fact_) <= (int)zmatchcuttable_.lookup(seedindex));
225 
226  if (settings_.debugTracklet()) {
227  edm::LogVerbatim("Tracklet") << getName() << " imatch = " << imatch << " ideltaphi cut " << ideltaphi << " "
228  << phimatchcuttable_.lookup(seedindex) << " ideltaz*fact cut " << ideltaz * fact_
229  << " " << zmatchcuttable_.lookup(seedindex);
230  }
231 
232  if (imatch) {
233  countsel++;
234 
235  tracklet->addMatch(layerdisk_,
236  ideltaphi,
237  ideltaz,
238  dphi,
239  dz,
240  dphiapprox,
241  dzapprox,
242  (phiregion_ << 7) + fpgastub->stubindex().value(),
243  mergedMatches[j].second);
244 
245  if (settings_.debugTracklet()) {
246  edm::LogVerbatim("Tracklet") << "Accepted full match in layer " << getName() << " " << tracklet;
247  }
248 
249  fullMatches_[seedindex]->addMatch(tracklet, mergedMatches[j].second);
250  }
251  } else { //disk matches
252 
253  //check that stubs and projections in same half of detector
254  assert(stub->z() * tracklet->t() > 0.0);
255 
256  int sign = (tracklet->t() > 0.0) ? 1 : -1;
257  int disk = sign * (layerdisk_ - (N_LAYER - 1));
258  assert(disk != 0);
259 
260  //Perform integer calculations here
261 
262  const Projection& proj = tracklet->proj(layerdisk_);
263 
264  int iz = fpgastub->z().value();
265  int iphi = proj.fpgaphiproj().value();
266 
267  //TODO - need to express interms of constants
268  int shifttmp = 6;
269  int iphicorr = (iz * proj.fpgaphiprojder().value()) >> shifttmp;
270 
271  iphi += iphicorr;
272 
273  int ir = proj.fpgarzproj().value();
274 
275  //TODO - need to express interms of constants
276  int shifttmp2 = 7;
277  int ircorr = (iz * proj.fpgarzprojder().value()) >> shifttmp2;
278 
279  ir += ircorr;
280 
281  int ideltaphi = fpgastub->phi().value() * settings_.kphi() / settings_.kphi() - iphi;
282 
283  int irstub = fpgastub->r().value();
284  int ialphafact = 0;
285  if (!stub->isPSmodule()) {
286  assert(irstub < (int)N_DSS_MOD * 2);
287  if (abs(disk) <= 2) {
288  ialphafact = ialphafactinner_[irstub];
289  irstub = settings_.rDSSinner(irstub) / settings_.kr();
290  } else {
291  ialphafact = ialphafactouter_[irstub];
292  irstub = settings_.rDSSouter(irstub) / settings_.kr();
293  }
294  }
295 
296  //TODO stub and projection r should not use different # bits...
297  int ideltar = (irstub >> 1) - ir;
298 
299  if (!stub->isPSmodule()) {
300  int ialpha = fpgastub->alpha().value();
301  int iphialphacor = ((ideltar * ialpha * ialphafact) >> settings_.alphashift());
302  ideltaphi += iphialphacor;
303  }
304 
305  //Perform floating point calculations here
306 
307  double phi = stub->phi() - phioffset;
308  double z = stub->z();
309  double r = stub->r();
310 
311  if (settings_.useapprox()) {
312  double dphi = reco::reduceRange(phi - fpgastub->phiapprox(0.0, 0.0));
313  assert(std::abs(dphi) < 0.001);
314  phi = fpgastub->phiapprox(0.0, 0.0);
315  z = fpgastub->zapprox();
316  r = fpgastub->rapprox();
317  }
318 
319  if (phi < 0)
320  phi += 2 * M_PI;
321 
322  double dz = z - sign * settings_.zmean(layerdisk_ - N_LAYER);
323 
324  if (std::abs(dz) > settings_.dzmax()) {
325  throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " " << name_ << " " << tracklet->getISeed()
326  << "\n stub " << stub->z() << " disk " << disk << " " << dz;
327  }
328 
329  double phiproj = proj.phiproj() + dz * proj.phiprojder();
330 
331  double rproj = proj.rzproj() + dz * proj.rzprojder();
332 
333  double deltar = r - rproj;
334 
335  double dr = stub->r() - rproj;
336 
337  double dphi = reco::reduceRange(phi - phiproj);
338 
339  double dphiapprox = reco::reduceRange(phi - (proj.phiprojapprox() + dz * proj.phiprojderapprox()));
340 
341  double drapprox = stub->r() - (proj.rzprojapprox() + dz * proj.rzprojderapprox());
342 
343  double drphi = dphi * stub->r();
344  double drphiapprox = dphiapprox * stub->r();
345 
346  if (!stub->isPSmodule()) {
347  double alphanorm = stub->alphanorm();
348  dphi += dr * alphanorm * settings_.half2SmoduleWidth() / stub->r2();
349  dphiapprox += drapprox * alphanorm * settings_.half2SmoduleWidth() / stub->r2();
350 
351  drphi += dr * alphanorm * settings_.half2SmoduleWidth() / stub->r();
352  drphiapprox += dr * alphanorm * settings_.half2SmoduleWidth() / stub->r();
353  }
354 
355  int seedindex = tracklet->getISeed();
356 
357  int idrphicut = rphicutPStable_.lookup(seedindex);
358  int idrcut = rcutPStable_.lookup(seedindex);
359  if (!stub->isPSmodule()) {
360  idrphicut = rphicut2Stable_.lookup(seedindex);
361  idrcut = rcut2Stable_.lookup(seedindex);
362  }
363 
364  double drphicut = idrphicut * settings_.kphi() * settings_.kr();
365  double drcut = idrcut * settings_.krprojshiftdisk();
366 
367  bool match, imatch;
368  if (std::abs(dphi) < third * settings_.dphisectorHG() &&
369  std::abs(dphiapprox) < third * settings_.dphisectorHG()) { //1/3 of sector size to catch errors
370  if (settings_.writeMonitorData("Residuals")) {
371  double pt = 0.01 * settings_.c() * settings_.bfield() / std::abs(tracklet->rinv());
372 
373  globals_->ofstream("diskresiduals.txt")
374  << disk << " " << stub->isPSmodule() << " " << tracklet->layer() << " " << abs(tracklet->disk()) << " "
375  << pt << " " << ideltaphi * settings_.kphi() * stub->r() << " " << drphiapprox << " " << drphicut << " "
376  << ideltar * settings_.krprojshiftdisk() << " " << deltar << " " << drcut << " " << endl;
377  }
378 
379  match = (std::abs(drphi) < drphicut) && (std::abs(deltar) < drcut);
380 
381  imatch = (std::abs(ideltaphi * irstub) < idrphicut) && (std::abs(ideltar) < idrcut);
382  } else {
383  edm::LogProblem("Tracklet") << "WARNING dphi and/or dphiapprox too large : " << dphi << " " << dphiapprox
384  << "dphi " << dphi << " Seed / ISeed " << tracklet->getISeed() << endl;
385  match = false;
386  imatch = false;
387  }
388  if (settings_.debugTracklet()) {
389  edm::LogVerbatim("Tracklet") << "imatch match disk: " << imatch << " " << match << " " << std::abs(ideltaphi)
390  << " " << drphicut / (settings_.kphi() * stub->r()) << " " << std::abs(ideltar)
391  << " " << drcut / settings_.krprojshiftdisk() << " r = " << stub->r();
392  }
393 
394  if (imatch) {
395  countsel++;
396 
397  if (settings_.debugTracklet()) {
398  edm::LogVerbatim("Tracklet") << "MatchCalculator found match in disk " << getName();
399  }
400 
401  tracklet->addMatch(layerdisk_,
402  ideltaphi,
403  ideltar,
404  drphi / stub->r(),
405  dr,
406  drphiapprox / stub->r(),
407  drapprox,
408  (phiregion_ << 7) + fpgastub->stubindex().value(),
409  fpgastub);
410 
411  if (settings_.debugTracklet()) {
412  edm::LogVerbatim("Tracklet") << "Accepted full match in disk " << getName() << " " << tracklet;
413  }
414 
415  fullMatches_[seedindex]->addMatch(tracklet, mergedMatches[j].second);
416  }
417  }
418  if (countall >= settings_.maxStep("MC"))
419  break;
420  }
421 
422  if (settings_.writeMonitorData("MC")) {
423  globals_->ofstream("matchcalculator.txt") << getName() << " " << countall << " " << countsel << endl;
424  }
425 }
Log< level::Info, true > LogVerbatim
double kz() const
Definition: Settings.h:302
double phi() const
Definition: L1TStub.h:63
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
int disk() const
Definition: Tracklet.cc:779
double kphi1() const
Definition: Settings.h:299
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:281
Projection & proj(int layerdisk)
Definition: Tracklet.h:87
Settings const & settings_
Definition: ProcessBase.h:40
double z() const
Definition: L1TStub.h:57
Globals * globals_
Definition: ProcessBase.h:41
int lookup(unsigned int index) const
Definition: TrackletLUT.cc:901
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:212
constexpr double third
Definition: Settings.h:42
unsigned int isPSmodule() const
Definition: L1TStub.h:94
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:253
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int value() const
Definition: FPGAWord.h:24
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:304
double drmax() const
Definition: Settings.h:128
double alphanorm() const
Definition: L1TStub.cc:85
bool stubtruthmatch(const L1TStub *stub)
Definition: Tracklet.cc:138
Definition: deltar.py:1
int getISeed() const
Definition: Tracklet.cc:798
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:58
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:400
const FPGAWord & phi() const
Definition: Stub.h:62
int ialphafactinner_[N_DSS_MOD *2]
int layer() const
Definition: Tracklet.cc:770
double kphi() const
Definition: Settings.h:298
double r2() const
Definition: L1TStub.h:60
std::string const & getName() const
Definition: ProcessBase.h:22
std::vector< FullMatchMemory * > fullMatches_
bool useapprox() const
Definition: Settings.h:234
Log< level::Error, true > LogProblem
int phi0bitshift() const
Definition: Settings.h:363
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 427 of file MatchCalculator.cc.

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

Referenced by execute().

428  {
429  std::vector<std::pair<std::pair<Tracklet*, int>, const Stub*> > tmp;
430 
431  std::vector<unsigned int> indexArray;
432  indexArray.reserve(candmatch.size());
433  for (unsigned int i = 0; i < candmatch.size(); i++) {
434  indexArray.push_back(0);
435  }
436 
437  int bestIndex = -1;
438  do {
439  int bestSector = 100;
440  int bestTCID = -1;
441  bestIndex = -1;
442  for (unsigned int i = 0; i < candmatch.size(); i++) {
443  if (indexArray[i] >= candmatch[i]->nMatches()) {
444  // skip as we were at the end
445  continue;
446  }
447  int TCID = candmatch[i]->getMatch(indexArray[i]).first.first->TCID();
448  int dSector = 0;
449  if (dSector > 2)
450  dSector -= N_SECTOR;
451  if (dSector < -2)
452  dSector += N_SECTOR;
453  assert(abs(dSector) < 2);
454  if (dSector == -1)
455  dSector = 2;
456  if (dSector < bestSector) {
457  bestSector = dSector;
458  bestTCID = TCID;
459  bestIndex = i;
460  }
461  if (dSector == bestSector) {
462  if (TCID < bestTCID || bestTCID < 0) {
463  bestTCID = TCID;
464  bestIndex = i;
465  }
466  }
467  }
468  if (bestIndex != -1) {
469  tmp.push_back(candmatch[bestIndex]->getMatch(indexArray[bestIndex]));
470  indexArray[bestIndex]++;
471  }
472  } while (bestIndex != -1);
473 
474  if (layerdisk_ < N_LAYER) {
475  int lastTCID = -1;
476  bool error = false;
477 
478  //Allow equal TCIDs since we can have multiple candidate matches
479  for (unsigned int i = 1; i < tmp.size(); i++) {
480  if (lastTCID > tmp[i].first.first->TCID()) {
481  edm::LogProblem("Tracklet") << "Wrong TCID ordering for projections in " << getName() << " last " << lastTCID
482  << " " << tmp[i].first.first->TCID();
483  error = true;
484  } else {
485  lastTCID = tmp[i].first.first->TCID();
486  }
487  }
488 
489  if (error) {
490  for (unsigned int i = 1; i < tmp.size(); i++) {
491  edm::LogProblem("Tracklet") << "Wrong order for in " << getName() << " " << i << " " << tmp[i].first.first
492  << " " << tmp[i].first.first->TCID();
493  }
494  }
495  }
496 
497  for (unsigned int i = 0; i < tmp.size(); i++) {
498  if (i > 0) {
499  //This allows for equal TCIDs. This means that we can e.g. have a track seeded
500  //in L1L2 that projects to both L3 and D4. The algorithm will pick up the first hit and
501  //drop the second
502 
503  assert(tmp[i - 1].first.first->TCID() <= tmp[i].first.first->TCID());
504  }
505  }
506 
507  return tmp;
508 }
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().