CMS 3D CMS Logo

TrackletEngine.cc
Go to the documentation of this file.
7 
10 
11 #include <filesystem>
12 
13 using namespace trklet;
14 using namespace std;
15 
16 TrackletEngine::TrackletEngine(string name, Settings const& settings, Globals* global)
17  : ProcessBase(name, settings, global), innerptlut_(settings), outerptlut_(settings) {
18  stubpairs_ = nullptr;
19  innervmstubs_ = nullptr;
20  outervmstubs_ = nullptr;
21 
23 
24  innerphibits_ = settings.nfinephi(0, iSeed_);
25  outerphibits_ = settings.nfinephi(1, iSeed_);
26 }
27 
29  if (settings_.writetrace()) {
30  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output "
31  << output;
32  }
33  if (output == "stubpairout") {
34  StubPairsMemory* tmp = dynamic_cast<StubPairsMemory*>(memory);
35  assert(tmp != nullptr);
36  stubpairs_ = tmp;
37  return;
38  }
39  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output;
40 }
41 
43  if (settings_.writetrace()) {
44  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input "
45  << input;
46  }
47  if (input == "innervmstubin") {
48  VMStubsTEMemory* tmp = dynamic_cast<VMStubsTEMemory*>(memory);
49  assert(tmp != nullptr);
51  setVMPhiBin();
52  return;
53  }
54  if (input == "outervmstubin") {
55  VMStubsTEMemory* tmp = dynamic_cast<VMStubsTEMemory*>(memory);
56  assert(tmp != nullptr);
58  setVMPhiBin();
59  return;
60  }
61  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input;
62 }
63 
65  if (!settings_.useSeed(iSeed_))
66  return;
67 
68  unsigned int countall = 0;
69  unsigned int countpass = 0;
70 
71  assert(innervmstubs_ != nullptr);
72  assert(outervmstubs_ != nullptr);
73 
74  for (unsigned int i = 0; i < innervmstubs_->nVMStubs(); i++) {
75  const VMStubTE& innervmstub = innervmstubs_->getVMStubTE(i);
76  FPGAWord lookupbits = innervmstub.vmbits();
77 
78  unsigned int nbits = 7;
79  if (iSeed_ == 4 || iSeed_ == 5)
80  nbits = 6;
81  int rzdiffmax = lookupbits.bits(nbits, lookupbits.nbits() - nbits);
82  int rzbinfirst = lookupbits.bits(0, 3);
83  int start = lookupbits.bits(4, nbits - 4);
84  int next = lookupbits.bits(3, 1);
85 
86  if ((iSeed_ == 4 || iSeed_ == 5) && innervmstub.stub()->disk().value() < 0) { //TODO - need to store negative disk
87  start += 4;
88  }
89  int last = start + next;
90 
91  for (int ibin = start; ibin <= last; ibin++) {
92  for (unsigned int j = 0; j < outervmstubs_->nVMStubsBinned(ibin); j++) {
93  if (countall >= settings_.maxStep("TE"))
94  break;
95  countall++;
96  const VMStubTE& outervmstub = outervmstubs_->getVMStubTEBinned(ibin, j);
97 
98  int rzbin = outervmstub.vmbits().bits(0, N_RZBITS);
99 
100  FPGAWord iphiinnerbin = innervmstub.finephi();
101  FPGAWord iphiouterbin = outervmstub.finephi();
102 
103  unsigned int index = (iphiinnerbin.value() << outerphibits_) + iphiouterbin.value();
104 
105  if (iSeed_ >= 4) { //Also use r-position
106 
107  int nrbits = 3; // Number of bits used for r position in disk LUT
108  int ibinmask = (1 << (nrbits - 1)) - 1; // Mask of two least significant bits
109 
110  int ir = ((ibin & ibinmask) << 1) + (rzbin >> (N_RZBITS - 1));
111  index += (ir << (outerphibits_ + innerphibits_));
112  }
113 
114  if (start != ibin)
115  rzbin += (1 << N_RZBITS);
116  if ((rzbin < rzbinfirst) || (rzbin - rzbinfirst > rzdiffmax)) {
117  continue;
118  }
119 
120  FPGAWord innerbend = innervmstub.bend();
121  FPGAWord outerbend = outervmstub.bend();
122 
123  int ptinnerindex = (index << innerbend.nbits()) + innerbend.value();
124  int ptouterindex = (index << outerbend.nbits()) + outerbend.value();
125 
126  if (!(innerptlut_.lookup(ptinnerindex) && outerptlut_.lookup(ptouterindex))) {
127  if (settings_.debugTracklet()) {
128  edm::LogVerbatim("Tracklet") << "Stub pair rejected because of stub pt cut bends : "
130  innervmstub.bend().value(), layerdisk1_, innervmstub.isPSmodule())
131  << " "
133  outervmstub.bend().value(), layerdisk2_, outervmstub.isPSmodule());
134  }
135  continue;
136  }
137 
138  if (settings_.debugTracklet())
139  edm::LogVerbatim("Tracklet") << "Adding stub pair in " << getName();
140 
141  assert(stubpairs_ != nullptr);
142  stubpairs_->addStubPair(innervmstub, outervmstub);
143  countpass++;
144  }
145  }
146  }
147 
148  if (settings_.writeMonitorData("TE")) {
149  globals_->ofstream("trackletengine.txt") << getName() << " " << countall << " " << countpass << endl;
150  }
151 }
152 
154  if (innervmstubs_ == nullptr || outervmstubs_ == nullptr)
155  return;
156 
159 
160  double innerphimin, innerphimax;
161  innervmstubs_->getPhiRange(innerphimin, innerphimax, iSeed_, 0);
162 
163  double outerphimin, outerphimax;
164  outervmstubs_->getPhiRange(outerphimin, outerphimax, iSeed_, 1);
165 
166  string innermem = innervmstubs_->getName().substr(6);
167  string outermem = outervmstubs_->getName().substr(6);
168 
170  false,
171  iSeed_,
172  layerdisk1_,
173  layerdisk2_,
176  innerphimin,
177  innerphimax,
178  outerphimin,
179  outerphimax,
180  innermem,
181  outermem);
182 
183  outerptlut_.initteptlut(false,
184  false,
185  iSeed_,
186  layerdisk1_,
187  layerdisk2_,
190  innerphimin,
191  innerphimax,
192  outerphimin,
193  outerphimax,
194  innermem,
195  outermem);
196 
197  TrackletLUT innertememlut(settings_);
198  TrackletLUT outertememlut(settings_);
199 
200  innertememlut.initteptlut(true,
201  true,
202  iSeed_,
203  layerdisk1_,
204  layerdisk2_,
207  innerphimin,
208  innerphimax,
209  outerphimin,
210  outerphimax,
211  innermem,
212  outermem);
213 
214  outertememlut.initteptlut(false,
215  true,
216  iSeed_,
217  layerdisk1_,
218  layerdisk2_,
221  innerphimin,
222  innerphimax,
223  outerphimin,
224  outerphimax,
225  innermem,
226  outermem);
227 
228  innervmstubs_->setbendtable(innertememlut);
229  outervmstubs_->setbendtable(outertememlut);
230 }
Definition: start.py:1
Log< level::Info, true > LogVerbatim
constexpr unsigned int N_RZBITS
Definition: Settings.h:39
const VMStubTE & getVMStubTEBinned(unsigned int bin, unsigned int i) const
unsigned int layerdisk2_
void setbendtable(const TrackletLUT &bendtable)
unsigned int maxStep(std::string module) const
Definition: Settings.h:125
bool isPSmodule() const
Definition: VMStubTE.h:31
void setother(VMStubsTEMemory *other)
std::string name_
Definition: ProcessBase.h:38
VMStubsTEMemory * outervmstubs_
double benddecode(int ibend, int layerdisk, bool isPSmodule) const
Definition: Settings.h:443
const FPGAWord & bend() const
Definition: VMStubTE.h:25
void addStubPair(const VMStubTE &stub1, const VMStubTE &stub2, const unsigned index=0, const std::string &tedName="")
void initteptlut(bool fillInner, bool fillTEMem, unsigned int iSeed, unsigned int layerdisk1, unsigned int layerdisk2, unsigned int innerphibits, unsigned int outerphibits, double innerphimin, double innerphimax, double outerphimin, double outerphimax, const std::string &innermem, const std::string &outermem)
Definition: TrackletLUT.cc:559
void initLayerDisksandISeed(unsigned int &layerdisk1, unsigned int &layerdisk2, unsigned int &iSeed)
Definition: ProcessBase.cc:63
Settings const & settings_
Definition: ProcessBase.h:40
Globals * globals_
Definition: ProcessBase.h:41
int lookup(unsigned int index) const
bool writetrace() const
Definition: Settings.h:195
unsigned int outerphibits_
assert(be >=bs)
static std::string const input
Definition: EdmProvDump.cc:50
const FPGAWord & disk() const
Definition: Stub.h:74
const Stub * stub() const
Definition: VMStubTE.h:29
unsigned int nbits(unsigned int power)
Definition: ProcessBase.cc:17
unsigned int layerdisk1_
const FPGAWord & vmbits() const
Definition: VMStubTE.h:27
int value() const
Definition: FPGAWord.h:24
std::string const & getName() const
Definition: MemoryBase.h:19
bool writeMonitorData(std::string module) const
Definition: Settings.h:118
const FPGAWord & finephi() const
Definition: VMStubTE.h:23
bool debugTracklet() const
Definition: Settings.h:194
const VMStubTE & getVMStubTE(unsigned int i) const
StubPairsMemory * stubpairs_
unsigned int nVMStubs() const
int nbits() const
Definition: FPGAWord.h:25
int nfinephi(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:142
bool useSeed(unsigned int iSeed) const
Definition: Settings.h:103
unsigned int nVMStubsBinned(unsigned int bin) const
std::ofstream & ofstream(std::string fname)
Definition: Globals.cc:44
unsigned int innerphibits_
Definition: output.py:1
void addInput(MemoryBase *memory, std::string input) override
unsigned int bits(unsigned int lsb, unsigned int nbit) const
Definition: FPGAWord.cc:74
tmp
align.sh
Definition: createJobs.py:716
void getPhiRange(double &phimin, double &phimax, unsigned int iSeed, unsigned int inner)
TrackletEngine(std::string name, Settings const &settings, Globals *global)
std::string const & getName() const
Definition: ProcessBase.h:22
VMStubsTEMemory * innervmstubs_
void addOutput(MemoryBase *memory, std::string output) override