CMS 3D CMS Logo

TrackletEngineDisplaced.cc
Go to the documentation of this file.
8 
11 
12 using namespace std;
13 using namespace trklet;
14 
15 TrackletEngineDisplaced::TrackletEngineDisplaced(string name, Settings const& settings, Globals* global)
16  : ProcessBase(name, settings, global) {
17  stubpairs_.clear();
18  firstvmstubs_.clear();
19  secondvmstubs_ = nullptr;
20  layer1_ = 0;
21  layer2_ = 0;
22  disk1_ = 0;
23  disk2_ = 0;
24  string name1 = name.substr(1); //this is to correct for "TED" having one more letter then "TE"
25  if (name1[3] == 'L') {
26  layer1_ = name1[4] - '0';
27  }
28  if (name1[3] == 'D') {
29  disk1_ = name1[4] - '0';
30  }
31  if (name1[11] == 'L') {
32  layer2_ = name1[12] - '0';
33  }
34  if (name1[11] == 'D') {
35  disk2_ = name1[12] - '0';
36  }
37  if (name1[12] == 'L') {
38  layer2_ = name1[13] - '0';
39  }
40  if (name1[12] == 'D') {
41  disk2_ = name1[13] - '0';
42  }
43 
44  iSeed_ = -1;
45  if (layer1_ == 3 && layer2_ == 4)
46  iSeed_ = 8;
47  if (layer1_ == 5 && layer2_ == 6)
48  iSeed_ = 9;
49  if (layer1_ == 2 && layer2_ == 3)
50  iSeed_ = 10;
51  if (disk1_ == 1 && disk2_ == 2)
52  iSeed_ = 11;
53 
56 }
57 
59 
61  if (settings_.writetrace()) {
62  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output "
63  << output;
64  }
65  if (output == "stubpairout") {
66  StubPairsMemory* tmp = dynamic_cast<StubPairsMemory*>(memory);
67  assert(tmp != nullptr);
68  stubpairs_.push_back(tmp);
69  return;
70  }
71  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output;
72 }
73 
75  if (settings_.writetrace()) {
76  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input "
77  << input;
78  }
79  if (input == "firstvmstubin") {
80  VMStubsTEMemory* tmp = dynamic_cast<VMStubsTEMemory*>(memory);
81  assert(tmp != nullptr);
82  firstvmstubs_.push_back(tmp);
83  return;
84  }
85  if (input == "secondvmstubin") {
86  VMStubsTEMemory* tmp = dynamic_cast<VMStubsTEMemory*>(memory);
87  assert(tmp != nullptr);
89  return;
90  }
91  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input;
92 }
93 
95  if (!settings_.useSeed(iSeed_))
96  return;
97 
99  readTables();
100 
101  unsigned int countall = 0;
102  unsigned int countpass = 0;
103  unsigned int nInnerStubs = 0;
104 
105  for (unsigned int iInnerMem = 0; iInnerMem < firstvmstubs_.size();
106  nInnerStubs += firstvmstubs_.at(iInnerMem)->nVMStubs(), iInnerMem++)
107  ;
108 
109  assert(!firstvmstubs_.empty());
110  assert(secondvmstubs_ != nullptr);
111 
112  for (auto& iInnerMem : firstvmstubs_) {
113  assert(iInnerMem->nVMStubs() == iInnerMem->nVMStubs());
114  for (unsigned int i = 0; i < iInnerMem->nVMStubs(); i++) {
115  const VMStubTE& firstvmstub = iInnerMem->getVMStubTE(i);
116  if (settings_.debugTracklet()) {
117  edm::LogVerbatim("Tracklet") << "In " << getName() << " have first stub";
118  }
119 
120  if ((layer1_ == 3 && layer2_ == 4) || (layer1_ == 5 && layer2_ == 6)) {
121  int lookupbits = firstvmstub.vmbits().value() & 1023;
122  int zdiffmax = (lookupbits >> 7);
123  int newbin = (lookupbits & 127);
124  int bin = newbin / 8;
125 
126  int zbinfirst = newbin & 7;
127 
128  int start = (bin >> 1);
129  int last = start + (bin & 1);
130 
131  assert(last < 8);
132 
133  if (settings_.debugTracklet()) {
134  edm::LogVerbatim("Tracklet") << "Will look in zbins " << start << " to " << last;
135  }
136  for (int ibin = start; ibin <= last; ibin++) {
137  for (unsigned int j = 0; j < secondvmstubs_->nVMStubsBinned(ibin); j++) {
138  if (settings_.debugTracklet()) {
139  edm::LogVerbatim("Tracklet") << "In " << getName() << " have second stub(1) " << ibin << " " << j;
140  }
141 
142  if (countall >= settings_.maxStep("TE"))
143  break;
144  countall++;
145  const VMStubTE& secondvmstub = secondvmstubs_->getVMStubTEBinned(ibin, j);
146 
147  int zbin = (secondvmstub.vmbits().value() & 7);
148  if (start != ibin)
149  zbin += 8;
150  if (zbin < zbinfirst || zbin - zbinfirst > zdiffmax) {
151  if (settings_.debugTracklet()) {
152  edm::LogVerbatim("Tracklet") << "Stubpair rejected because of wrong zbin";
153  }
154  continue;
155  }
156 
157  assert(firstphibits_ != -1);
158  assert(secondphibits_ != -1);
159 
160  FPGAWord iphifirstbin = firstvmstub.finephi();
161  FPGAWord iphisecondbin = secondvmstub.finephi();
162 
163  unsigned int index = (iphifirstbin.value() << secondphibits_) + iphisecondbin.value();
164 
165  FPGAWord firstbend = firstvmstub.bend();
166  FPGAWord secondbend = secondvmstub.bend();
167 
168  index = (index << firstbend.nbits()) + firstbend.value();
169  index = (index << secondbend.nbits()) + secondbend.value();
170 
172  (index >= table_.size() || table_.at(index).empty())) {
173  if (settings_.debugTracklet()) {
174  edm::LogVerbatim("Tracklet")
175  << "Stub pair rejected because of stub pt cut bends : "
176  << settings_.benddecode(firstvmstub.bend().value(), layer1_ - 1, firstvmstub.isPSmodule()) << " "
177  << settings_.benddecode(secondvmstub.bend().value(), layer2_ - 1, secondvmstub.isPSmodule());
178  }
179 
180  //FIXME temporarily commented out until stub bend table fixed
181  //if (!settings_.writeTripletTables())
182  // continue;
183  }
184 
185  if (settings_.debugTracklet())
186  edm::LogVerbatim("Tracklet") << "Adding layer-layer pair in " << getName();
187  for (unsigned int isp = 0; isp < stubpairs_.size(); ++isp) {
188  if (!settings_.enableTripletTables() || settings_.writeTripletTables() || table_.at(index).count(isp)) {
189  if (settings_.writeMonitorData("Seeds")) {
190  ofstream fout("seeds.txt", ofstream::app);
191  fout << __FILE__ << ":" << __LINE__ << " " << name_ << " " << iSeed_ << endl;
192  fout.close();
193  }
194  stubpairs_.at(isp)->addStubPair(firstvmstub, secondvmstub, index, getName());
195  }
196  }
197 
198  countpass++;
199  }
200  }
201 
202  } else if (layer1_ == 2 && layer2_ == 3) {
203  int lookupbits = firstvmstub.vmbits().value() & 1023;
204  int zdiffmax = (lookupbits >> 7);
205  int newbin = (lookupbits & 127);
206  int bin = newbin / 8;
207 
208  int zbinfirst = newbin & 7;
209 
210  int start = (bin >> 1);
211  int last = start + (bin & 1);
212 
213  assert(last < 8);
214 
215  if (settings_.debugTracklet()) {
216  edm::LogVerbatim("Tracklet") << "Will look in zbins " << start << " to " << last;
217  }
218  for (int ibin = start; ibin <= last; ibin++) {
219  for (unsigned int j = 0; j < secondvmstubs_->nVMStubsBinned(ibin); j++) {
220  if (settings_.debugTracklet()) {
221  edm::LogVerbatim("Tracklet") << "In " << getName() << " have second stub(2) ";
222  }
223 
224  if (countall >= settings_.maxStep("TE"))
225  break;
226  countall++;
227 
228  const VMStubTE& secondvmstub = secondvmstubs_->getVMStubTEBinned(ibin, j);
229 
230  int zbin = (secondvmstub.vmbits().value() & 7);
231  if (start != ibin)
232  zbin += 8;
233  if (zbin < zbinfirst || zbin - zbinfirst > zdiffmax) {
234  if (settings_.debugTracklet()) {
235  edm::LogVerbatim("Tracklet") << "Stubpair rejected because of wrong zbin";
236  }
237  continue;
238  }
239 
240  assert(firstphibits_ != -1);
241  assert(secondphibits_ != -1);
242 
243  FPGAWord iphifirstbin = firstvmstub.finephi();
244  FPGAWord iphisecondbin = secondvmstub.finephi();
245 
246  unsigned int index = (iphifirstbin.value() << secondphibits_) + iphisecondbin.value();
247 
248  FPGAWord firstbend = firstvmstub.bend();
249  FPGAWord secondbend = secondvmstub.bend();
250 
251  index = (index << firstbend.nbits()) + firstbend.value();
252  index = (index << secondbend.nbits()) + secondbend.value();
253 
255  (index >= table_.size() || table_.at(index).empty())) {
256  if (settings_.debugTracklet()) {
257  edm::LogVerbatim("Tracklet")
258  << "Stub pair rejected because of stub pt cut bends : "
259  << settings_.benddecode(firstvmstub.bend().value(), layer1_ - 1, firstvmstub.isPSmodule()) << " "
260  << settings_.benddecode(secondvmstub.bend().value(), layer2_ - 1, secondvmstub.isPSmodule());
261  }
262  continue;
263  }
264 
265  if (settings_.debugTracklet())
266  edm::LogVerbatim("Tracklet") << "Adding layer-layer pair in " << getName();
267  for (unsigned int isp = 0; isp < stubpairs_.size(); ++isp) {
269  (index < table_.size() && table_.at(index).count(isp))) {
270  if (settings_.writeMonitorData("Seeds")) {
271  ofstream fout("seeds.txt", ofstream::app);
272  fout << __FILE__ << ":" << __LINE__ << " " << name_ << " " << iSeed_ << endl;
273  fout.close();
274  }
275  stubpairs_.at(isp)->addStubPair(firstvmstub, secondvmstub, index, getName());
276  }
277  }
278 
279  countpass++;
280  }
281  }
282 
283  } else if (disk1_ == 1 && disk2_ == 2) {
284  if (settings_.debugTracklet())
285  edm::LogVerbatim("Tracklet") << getName() << " Disk-disk pair";
286 
287  int lookupbits = firstvmstub.vmbits().value() & 511;
288  bool negdisk = firstvmstub.stub()->disk().value() < 0;
289  int rdiffmax = (lookupbits >> 6);
290  int newbin = (lookupbits & 63);
291  int bin = newbin / 8;
292 
293  int rbinfirst = newbin & 7;
294 
295  int start = (bin >> 1);
296  if (negdisk)
297  start += 4;
298  int last = start + (bin & 1);
299  assert(last < 8);
300  for (int ibin = start; ibin <= last; ibin++) {
301  if (settings_.debugTracklet()) {
302  edm::LogVerbatim("Tracklet") << getName() << " looking for matching stub in " << secondvmstubs_->getName()
303  << " in bin = " << ibin << " with " << secondvmstubs_->nVMStubsBinned(ibin)
304  << " stubs";
305  }
306  for (unsigned int j = 0; j < secondvmstubs_->nVMStubsBinned(ibin); j++) {
307  if (countall >= settings_.maxStep("TE"))
308  break;
309  countall++;
310 
311  const VMStubTE& secondvmstub = secondvmstubs_->getVMStubTEBinned(ibin, j);
312 
313  int rbin = (secondvmstub.vmbits().value() & 7);
314  if (start != ibin)
315  rbin += 8;
316  if (rbin < rbinfirst)
317  continue;
318  if (rbin - rbinfirst > rdiffmax)
319  continue;
320 
321  unsigned int irsecondbin = secondvmstub.vmbits().value() >> 2;
322 
323  FPGAWord iphifirstbin = firstvmstub.finephi();
324  FPGAWord iphisecondbin = secondvmstub.finephi();
325 
326  unsigned int index = (irsecondbin << (secondphibits_ + firstphibits_)) +
327  (iphifirstbin.value() << secondphibits_) + iphisecondbin.value();
328 
329  FPGAWord firstbend = firstvmstub.bend();
330  FPGAWord secondbend = secondvmstub.bend();
331 
332  index = (index << firstbend.nbits()) + firstbend.value();
333  index = (index << secondbend.nbits()) + secondbend.value();
334 
336  (index >= table_.size() || table_.at(index).empty())) {
337  if (settings_.debugTracklet()) {
338  edm::LogVerbatim("Tracklet")
339  << "Stub pair rejected because of stub pt cut bends : "
340  << settings_.benddecode(firstvmstub.bend().value(), disk1_ + 5, firstvmstub.isPSmodule()) << " "
341  << settings_.benddecode(secondvmstub.bend().value(), disk2_ + 5, secondvmstub.isPSmodule());
342  }
343  continue;
344  }
345 
346  if (settings_.debugTracklet())
347  edm::LogVerbatim("Tracklet") << "Adding disk-disk pair in " << getName();
348 
349  for (unsigned int isp = 0; isp < stubpairs_.size(); ++isp) {
351  (index < table_.size() && table_.at(index).count(isp))) {
352  if (settings_.writeMonitorData("Seeds")) {
353  ofstream fout("seeds.txt", ofstream::app);
354  fout << __FILE__ << ":" << __LINE__ << " " << name_ << " " << iSeed_ << endl;
355  fout.close();
356  }
357  stubpairs_.at(isp)->addStubPair(firstvmstub, secondvmstub, index, getName());
358  }
359  }
360  countpass++;
361  }
362  }
363  }
364  }
365  }
366  if (countall > 5000) {
367  edm::LogVerbatim("Tracklet") << "In TrackletEngineDisplaced::execute : " << getName() << " " << nInnerStubs << " "
368  << secondvmstubs_->nVMStubs() << " " << countall << " " << countpass;
369  for (auto& iInnerMem : firstvmstubs_) {
370  for (unsigned int i = 0; i < iInnerMem->nVMStubs(); i++) {
371  const VMStubTE& firstvmstub = iInnerMem->getVMStubTE(i);
372  edm::LogVerbatim("Tracklet") << "In TrackletEngineDisplaced::execute first stub : "
373  << firstvmstub.stub()->l1tstub()->r() << " "
374  << firstvmstub.stub()->l1tstub()->phi() << " "
375  << firstvmstub.stub()->l1tstub()->r() * firstvmstub.stub()->l1tstub()->phi() << " "
376  << firstvmstub.stub()->l1tstub()->z();
377  }
378  }
379  for (unsigned int i = 0; i < secondvmstubs_->nVMStubs(); i++) {
380  const VMStubTE& secondvmstub = secondvmstubs_->getVMStubTE(i);
381  edm::LogVerbatim("Tracklet") << "In TrackletEngineDisplaced::execute second stub : "
382  << secondvmstub.stub()->l1tstub()->r() << " "
383  << secondvmstub.stub()->l1tstub()->phi() << " "
384  << secondvmstub.stub()->l1tstub()->r() * secondvmstub.stub()->l1tstub()->phi() << " "
385  << secondvmstub.stub()->l1tstub()->z();
386  }
387  }
388 
389  if (settings_.writeMonitorData("TED")) {
390  globals_->ofstream("trackletenginedisplaces.txt") << getName() << " " << countall << " " << countpass << endl;
391  }
392 }
393 
395  ifstream fin;
396  string tableName, line, word;
397 
398  string tablePath = settings_.tableTEDFile();
399  unsigned int finddir = tablePath.find("table_TED_");
400  tableName = tablePath.substr(0, finddir) + "table_" + name_ + ".txt";
401 
402  fin.open(tableName, ifstream::in);
403  if (!fin) {
404  throw cms::Exception("BadConfig") << "TripletEngine::readTables, file " << tableName << " not known";
405  }
406 
407  while (getline(fin, line)) {
408  istringstream iss(line);
409  table_.resize(table_.size() + 1);
410 
411  while (iss >> word)
412  table_[table_.size() - 1].insert(memNameToIndex(word));
413  }
414  fin.close();
415 }
416 
418  for (unsigned int isp = 0; isp < stubpairs_.size(); ++isp)
419  if (stubpairs_.at(isp)->getName() == name)
420  return isp;
421  return -1;
422 }
Definition: start.py:1
Log< level::Info, true > LogVerbatim
const VMStubTE & getVMStubTEBinned(unsigned int bin, unsigned int i) const
double phi() const
Definition: L1TStub.h:65
short memNameToIndex(const std::string &name)
unsigned int maxStep(std::string module) const
Definition: Settings.h:123
bool isPSmodule() const
Definition: VMStubTE.h:31
std::string name_
Definition: ProcessBase.h:38
double benddecode(int ibend, int layerdisk, bool isPSmodule) const
Definition: Settings.h:437
void addOutput(MemoryBase *memory, std::string output) override
bool enableTripletTables() const
Definition: Settings.h:212
const FPGAWord & bend() const
Definition: VMStubTE.h:25
Settings const & settings_
Definition: ProcessBase.h:40
double z() const
Definition: L1TStub.h:59
Globals * globals_
Definition: ProcessBase.h:41
bool writetrace() const
Definition: Settings.h:193
assert(be >=bs)
void addInput(MemoryBase *memory, std::string input) override
std::string const & tableTEDFile() const
Definition: Settings.h:77
static std::string const input
Definition: EdmProvDump.cc:50
const FPGAWord & disk() const
Definition: Stub.h:68
const Stub * stub() const
Definition: VMStubTE.h:29
uint64_t word
const FPGAWord & vmbits() const
Definition: VMStubTE.h:27
int value() const
Definition: FPGAWord.h:24
L1TStub * l1tstub()
Definition: Stub.h:77
std::string const & getName() const
Definition: MemoryBase.h:19
bool writeMonitorData(std::string module) const
Definition: Settings.h:116
const FPGAWord & finephi() const
Definition: VMStubTE.h:23
bool debugTracklet() const
Definition: Settings.h:192
const VMStubTE & getVMStubTE(unsigned int i) const
unsigned int nVMStubs() const
std::vector< VMStubsTEMemory * > firstvmstubs_
int nbits() const
Definition: FPGAWord.h:25
int nfinephi(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:140
std::vector< std::set< short > > table_
bool useSeed(unsigned int iSeed) const
Definition: Settings.h:101
unsigned int nVMStubsBinned(unsigned int bin) const
double r() const
Definition: L1TStub.h:60
std::ofstream & ofstream(std::string fname)
Definition: Globals.cc:44
std::vector< StubPairsMemory * > stubpairs_
tmp
align.sh
Definition: createJobs.py:716
std::string const & getName() const
Definition: ProcessBase.h:22
bool writeTripletTables() const
Definition: Settings.h:213