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,
16  Settings const& settings,
17  Globals* global,
18  unsigned int iSector)
19  : ProcessBase(name, settings, global, iSector) {
20  stubpairs_.clear();
21  firstvmstubs_.clear();
22  secondvmstubs_ = nullptr;
23  layer1_ = 0;
24  layer2_ = 0;
25  disk1_ = 0;
26  disk2_ = 0;
27  string name1 = name.substr(1); //this is to correct for "TED" having one more letter then "TE"
28  if (name1[3] == 'L') {
29  layer1_ = name1[4] - '0';
30  }
31  if (name1[3] == 'D') {
32  disk1_ = name1[4] - '0';
33  }
34  if (name1[11] == 'L') {
35  layer2_ = name1[12] - '0';
36  }
37  if (name1[11] == 'D') {
38  disk2_ = name1[12] - '0';
39  }
40  if (name1[12] == 'L') {
41  layer2_ = name1[13] - '0';
42  }
43  if (name1[12] == 'D') {
44  disk2_ = name1[13] - '0';
45  }
46 
47  iSeed_ = -1;
48  if (layer1_ == 3 && layer2_ == 4)
49  iSeed_ = 8;
50  if (layer1_ == 5 && layer2_ == 6)
51  iSeed_ = 9;
52  if (layer1_ == 2 && layer2_ == 3)
53  iSeed_ = 10;
54  if (disk1_ == 1 && disk2_ == 2)
55  iSeed_ = 11;
56 
59 
60  readTables();
61 }
62 
64 
66  if (settings_.writetrace()) {
67  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output "
68  << output;
69  }
70  if (output == "stubpairout") {
71  StubPairsMemory* tmp = dynamic_cast<StubPairsMemory*>(memory);
72  assert(tmp != nullptr);
73  stubpairs_.push_back(tmp);
74  return;
75  }
76  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output;
77 }
78 
80  if (settings_.writetrace()) {
81  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input "
82  << input;
83  }
84  if (input == "firstvmstubin") {
85  VMStubsTEMemory* tmp = dynamic_cast<VMStubsTEMemory*>(memory);
86  assert(tmp != nullptr);
87  firstvmstubs_.push_back(tmp);
88  return;
89  }
90  if (input == "secondvmstubin") {
91  VMStubsTEMemory* tmp = dynamic_cast<VMStubsTEMemory*>(memory);
92  assert(tmp != nullptr);
94  return;
95  }
96  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input;
97 }
98 
100  if (!settings_.useSeed(iSeed_))
101  return;
102 
103  unsigned int countall = 0;
104  unsigned int countpass = 0;
105  unsigned int nInnerStubs = 0;
106 
107  for (unsigned int iInnerMem = 0; iInnerMem < firstvmstubs_.size();
108  nInnerStubs += firstvmstubs_.at(iInnerMem)->nVMStubs(), iInnerMem++)
109  ;
110 
111  assert(!firstvmstubs_.empty());
112  assert(secondvmstubs_ != nullptr);
113 
114  for (auto& iInnerMem : firstvmstubs_) {
115  assert(iInnerMem->nVMStubs() == iInnerMem->nVMStubs());
116  for (unsigned int i = 0; i < iInnerMem->nVMStubs(); i++) {
117  const VMStubTE& firstvmstub = iInnerMem->getVMStubTE(i);
118  if (settings_.debugTracklet()) {
119  edm::LogVerbatim("Tracklet") << "In " << getName() << " have first stub";
120  }
121 
122  if ((layer1_ == 3 && layer2_ == 4) || (layer1_ == 5 && layer2_ == 6)) {
123  int lookupbits = firstvmstub.vmbits().value() & 1023;
124  int zdiffmax = (lookupbits >> 7);
125  int newbin = (lookupbits & 127);
126  int bin = newbin / 8;
127 
128  int zbinfirst = newbin & 7;
129 
130  int start = (bin >> 1);
131  int last = start + (bin & 1);
132 
133  assert(last < 8);
134 
135  if (settings_.debugTracklet()) {
136  edm::LogVerbatim("Tracklet") << "Will look in zbins " << start << " to " << last;
137  }
138  for (int ibin = start; ibin <= last; ibin++) {
139  for (unsigned int j = 0; j < secondvmstubs_->nVMStubsBinned(ibin); j++) {
140  if (settings_.debugTracklet()) {
141  edm::LogVerbatim("Tracklet") << "In " << getName() << " have second stub(1) " << ibin << " " << j;
142  }
143 
144  if (countall >= settings_.maxStep("TE"))
145  break;
146  countall++;
147  const VMStubTE& secondvmstub = secondvmstubs_->getVMStubTEBinned(ibin, j);
148 
149  int zbin = (secondvmstub.vmbits().value() & 7);
150  if (start != ibin)
151  zbin += 8;
152  if (zbin < zbinfirst || zbin - zbinfirst > zdiffmax) {
153  if (settings_.debugTracklet()) {
154  edm::LogVerbatim("Tracklet") << "Stubpair rejected because of wrong zbin";
155  }
156  continue;
157  }
158 
159  assert(firstphibits_ != -1);
160  assert(secondphibits_ != -1);
161 
162  FPGAWord iphifirstbin = firstvmstub.finephi();
163  FPGAWord iphisecondbin = secondvmstub.finephi();
164 
165  unsigned int index = (iphifirstbin.value() << secondphibits_) + iphisecondbin.value();
166 
167  FPGAWord firstbend = firstvmstub.bend();
168  FPGAWord secondbend = secondvmstub.bend();
169 
170  index = (index << firstbend.nbits()) + firstbend.value();
171  index = (index << secondbend.nbits()) + secondbend.value();
172 
173  if (index >= table_.size())
174  table_.resize(index + 1);
175 
176  if (table_.at(index).empty()) {
177  if (settings_.debugTracklet()) {
178  edm::LogVerbatim("Tracklet") << "Stub pair rejected because of stub pt cut bends : "
179  << benddecode(firstvmstub.bend().value(), firstvmstub.isPSmodule()) << " "
180  << benddecode(secondvmstub.bend().value(), secondvmstub.isPSmodule());
181  }
183  continue;
184  }
185 
186  if (settings_.debugTracklet())
187  edm::LogVerbatim("Tracklet") << "Adding layer-layer pair in " << getName();
188  for (unsigned int isp = 0; isp < stubpairs_.size(); ++isp) {
189  if (settings_.writeTripletTables() || table_.at(index).count(stubpairs_.at(isp)->getName())) {
190  if (settings_.writeMonitorData("Seeds")) {
191  ofstream fout("seeds.txt", ofstream::app);
192  fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << iSeed_ << endl;
193  fout.close();
194  }
195  stubpairs_.at(isp)->addStubPair(firstvmstub, secondvmstub, index, getName());
196  }
197  }
198 
199  countpass++;
200  }
201  }
202 
203  } else if (layer1_ == 2 && layer2_ == 3) {
204  int lookupbits = firstvmstub.vmbits().value() & 1023;
205  int zdiffmax = (lookupbits >> 7);
206  int newbin = (lookupbits & 127);
207  int bin = newbin / 8;
208 
209  int zbinfirst = newbin & 7;
210 
211  int start = (bin >> 1);
212  int last = start + (bin & 1);
213 
214  assert(last < 8);
215 
216  if (settings_.debugTracklet()) {
217  edm::LogVerbatim("Tracklet") << "Will look in zbins " << start << " to " << last;
218  }
219  for (int ibin = start; ibin <= last; ibin++) {
220  for (unsigned int j = 0; j < secondvmstubs_->nVMStubsBinned(ibin); j++) {
221  if (settings_.debugTracklet()) {
222  edm::LogVerbatim("Tracklet") << "In " << getName() << " have second stub(2) ";
223  }
224 
225  if (countall >= settings_.maxStep("TE"))
226  break;
227  countall++;
228 
229  const VMStubTE& secondvmstub = secondvmstubs_->getVMStubTEBinned(ibin, j);
230 
231  int zbin = (secondvmstub.vmbits().value() & 7);
232  if (start != ibin)
233  zbin += 8;
234  if (zbin < zbinfirst || zbin - zbinfirst > zdiffmax) {
235  if (settings_.debugTracklet()) {
236  edm::LogVerbatim("Tracklet") << "Stubpair rejected because of wrong zbin";
237  }
238  continue;
239  }
240 
241  assert(firstphibits_ != -1);
242  assert(secondphibits_ != -1);
243 
244  FPGAWord iphifirstbin = firstvmstub.finephi();
245  FPGAWord iphisecondbin = secondvmstub.finephi();
246 
247  unsigned int index = (iphifirstbin.value() << secondphibits_) + iphisecondbin.value();
248 
249  FPGAWord firstbend = firstvmstub.bend();
250  FPGAWord secondbend = secondvmstub.bend();
251 
252  index = (index << firstbend.nbits()) + firstbend.value();
253  index = (index << secondbend.nbits()) + secondbend.value();
254 
255  if (index >= table_.size())
256  table_.resize(index + 1);
257 
258  if (table_.at(index).empty()) {
259  if (settings_.debugTracklet()) {
260  edm::LogVerbatim("Tracklet") << "Stub pair rejected because of stub pt cut bends : "
261  << benddecode(firstvmstub.bend().value(), firstvmstub.isPSmodule()) << " "
262  << benddecode(secondvmstub.bend().value(), secondvmstub.isPSmodule());
263  }
264  }
265 
266  if (settings_.debugTracklet())
267  edm::LogVerbatim("Tracklet") << "Adding layer-layer pair in " << getName();
268  for (unsigned int isp = 0; isp < stubpairs_.size(); ++isp) {
269  if (settings_.writeTripletTables() || table_.at(index).count(stubpairs_.at(isp)->getName()) || true) {
270  if (settings_.writeMonitorData("Seeds")) {
271  ofstream fout("seeds.txt", ofstream::app);
272  fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << 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() << "[" << iSector_ << "] 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 
335  if (index >= table_.size())
336  table_.resize(index + 1);
337 
338  if (table_.at(index).empty()) {
339  if (settings_.debugTracklet()) {
340  edm::LogVerbatim("Tracklet") << "Stub pair rejected because of stub pt cut bends : "
341  << benddecode(firstvmstub.bend().value(), firstvmstub.isPSmodule()) << " "
342  << benddecode(secondvmstub.bend().value(), secondvmstub.isPSmodule());
343  }
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) {
350  if (settings_.writeTripletTables() || table_.at(index).count(stubpairs_.at(isp)->getName()) || true) {
351  if (settings_.writeMonitorData("Seeds")) {
352  ofstream fout("seeds.txt", ofstream::app);
353  fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << iSeed_ << endl;
354  fout.close();
355  }
356  stubpairs_.at(isp)->addStubPair(firstvmstub, secondvmstub, index, getName());
357  }
358  }
359  countpass++;
360  }
361  }
362  }
363  }
364  }
365  if (countall > 5000) {
366  edm::LogVerbatim("Tracklet") << "In TrackletEngineDisplaced::execute : " << getName() << " " << nInnerStubs << " "
367  << secondvmstubs_->nVMStubs() << " " << countall << " " << countpass;
368  for (auto& iInnerMem : firstvmstubs_) {
369  for (unsigned int i = 0; i < iInnerMem->nVMStubs(); i++) {
370  const VMStubTE& firstvmstub = iInnerMem->getVMStubTE(i);
371  edm::LogVerbatim("Tracklet") << "In TrackletEngineDisplaced::execute first stub : "
372  << firstvmstub.stub()->l1tstub()->r() << " "
373  << firstvmstub.stub()->l1tstub()->phi() << " "
374  << firstvmstub.stub()->l1tstub()->r() * firstvmstub.stub()->l1tstub()->phi() << " "
375  << firstvmstub.stub()->l1tstub()->z();
376  }
377  }
378  for (unsigned int i = 0; i < secondvmstubs_->nVMStubs(); i++) {
379  const VMStubTE& secondvmstub = secondvmstubs_->getVMStubTE(i);
380  edm::LogVerbatim("Tracklet") << "In TrackletEngineDisplaced::execute second stub : "
381  << secondvmstub.stub()->l1tstub()->r() << " "
382  << secondvmstub.stub()->l1tstub()->phi() << " "
383  << secondvmstub.stub()->l1tstub()->r() * secondvmstub.stub()->l1tstub()->phi() << " "
384  << secondvmstub.stub()->l1tstub()->z();
385  }
386  }
387 
388  if (settings_.writeMonitorData("TED")) {
389  globals_->ofstream("trackletenginedisplaces.txt") << getName() << " " << countall << " " << countpass << endl;
390  }
391 }
392 
394  ifstream fin;
395  string tableName, line, word;
396 
397  string tablePath = settings_.tableTEDFile();
398  unsigned int finddir = tablePath.find("table_TED_");
399  tableName = tablePath.substr(0, finddir) + "table_" + name_ + ".txt";
400 
401  fin.open(tableName, ifstream::in);
402  if (!fin) {
403  throw cms::Exception("BadConfig") << "TripletEngine::readTables, file " << tableName << " not known";
404  }
405 
406  while (getline(fin, line)) {
407  istringstream iss(line);
408  table_.resize(table_.size() + 1);
409 
410  while (iss >> word)
411  table_[table_.size() - 1].insert(word);
412  }
413  fin.close();
414 }
Settings.h
TrackletEngineDisplaced.h
mps_fire.i
i
Definition: mps_fire.py:428
trklet::Settings::writetrace
bool writetrace() const
Definition: Settings.h:147
start
Definition: start.py:1
input
static const std::string input
Definition: EdmProvDump.cc:48
trklet::StubPairsMemory
Definition: StubPairsMemory.h:13
MessageLogger.h
trklet::Settings::writeTripletTables
bool writeTripletTables() const
Definition: Settings.h:162
trklet::VMStubTE
Definition: VMStubTE.h:15
trklet::TrackletEngineDisplaced::disk2_
int disk2_
Definition: TrackletEngineDisplaced.h:37
trklet::TrackletEngineDisplaced::iSeed_
int iSeed_
Definition: TrackletEngineDisplaced.h:49
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
trklet::TrackletEngineDisplaced::readTables
void readTables()
Definition: TrackletEngineDisplaced.cc:393
trklet::VMStubsTEMemory::getVMStubTEBinned
const VMStubTE & getVMStubTEBinned(unsigned int bin, unsigned int i) const
Definition: VMStubsTEMemory.h:32
trklet::TrackletEngineDisplaced::~TrackletEngineDisplaced
~TrackletEngineDisplaced() override
Definition: TrackletEngineDisplaced.cc:63
trklet::Settings
Definition: Settings.h:26
trklet::L1TStub::z
double z() const
Definition: L1TStub.h:56
trklet::VMStubsTEMemory
Definition: VMStubsTEMemory.h:16
cms::cuda::assert
assert(be >=bs)
trklet::ProcessBase::settings_
Settings const & settings_
Definition: ProcessBase.h:44
trklet::TrackletEngineDisplaced::execute
void execute()
Definition: TrackletEngineDisplaced.cc:99
trklet::FPGAWord::nbits
int nbits() const
Definition: FPGAWord.h:25
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
trklet::Globals
Definition: Globals.h:32
trklet::VMStubTE::isPSmodule
bool isPSmodule() const
Definition: VMStubTE.h:31
trklet::TrackletEngineDisplaced::stubpairs_
std::vector< StubPairsMemory * > stubpairs_
Definition: TrackletEngineDisplaced.h:42
HLT_Fake1_cff.tableName
tableName
Definition: HLT_Fake1_cff.py:10
FPGAWord.h
trklet::VMStubTE::bend
const FPGAWord & bend() const
Definition: VMStubTE.h:25
trklet::VMStubsTEMemory::nVMStubs
unsigned int nVMStubs() const
Definition: VMStubsTEMemory.h:26
word
uint64_t word
Definition: CTPPSTotemDataFormatter.cc:29
dqmdumpme.last
last
Definition: dqmdumpme.py:56
trklet::Stub::disk
const FPGAWord & disk() const
Definition: Stub.h:57
trklet::MemoryBase::getName
std::string const & getName() const
Definition: MemoryBase.h:19
groupFilesInBlocks.fin
fin
Definition: groupFilesInBlocks.py:94
trklet::Settings::tableTEDFile
std::string const & tableTEDFile() const
Definition: Settings.h:47
trklet::TrackletEngineDisplaced::addInput
void addInput(MemoryBase *memory, std::string input) override
Definition: TrackletEngineDisplaced.cc:79
trklet::VMStubsTEMemory::getVMStubTE
const VMStubTE & getVMStubTE(unsigned int i) const
Definition: VMStubsTEMemory.h:30
trklet::FPGAWord
Definition: FPGAWord.h:9
trklet::TrackletEngineDisplaced::firstvmstubs_
std::vector< VMStubsTEMemory * > firstvmstubs_
Definition: TrackletEngineDisplaced.h:39
trklet::TrackletEngineDisplaced::secondphibits_
int secondphibits_
Definition: TrackletEngineDisplaced.h:47
trklet::TrackletEngineDisplaced::layer1_
int layer1_
Definition: TrackletEngineDisplaced.h:34
trklet::MemoryBase
Definition: MemoryBase.h:13
trklet::VMStubTE::stub
const Stub * stub() const
Definition: VMStubTE.h:29
recoMuon::in
Definition: RecoMuonEnumerators.h:6
groupFilesInBlocks.fout
fout
Definition: groupFilesInBlocks.py:162
trklet::TrackletEngineDisplaced::secondvmstubs_
VMStubsTEMemory * secondvmstubs_
Definition: TrackletEngineDisplaced.h:40
StubPairsMemory.h
Globals.h
trklet::TrackletEngineDisplaced::firstphibits_
int firstphibits_
Definition: TrackletEngineDisplaced.h:46
trklet::VMStubTE::vmbits
const FPGAWord & vmbits() const
Definition: VMStubTE.h:27
trklet
Definition: AllProjectionsMemory.h:9
trklet::FPGAWord::value
int value() const
Definition: FPGAWord.h:24
VMStubsTEMemory.h
trklet::TrackletEngineDisplaced::layer2_
int layer2_
Definition: TrackletEngineDisplaced.h:35
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
trklet::Settings::writeMonitorData
bool writeMonitorData(std::string module) const
Definition: Settings.h:86
std
Definition: JetResolutionObject.h:76
trklet::ProcessBase
Definition: ProcessBase.h:12
trklet::Globals::ofstream
std::ofstream & ofstream(std::string fname)
Definition: Globals.cc:44
trklet::Stub::l1tstub
L1TStub * l1tstub()
Definition: Stub.h:69
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
mps_setup.memory
memory
Definition: mps_setup.py:156
Exception
Definition: hltDiff.cc:246
trklet::ProcessBase::getName
std::string const & getName() const
Definition: ProcessBase.h:22
trklet::ProcessBase::name_
std::string name_
Definition: ProcessBase.h:38
MemoryBase.h
trklet::TrackletEngineDisplaced::table_
std::vector< std::set< std::string > > table_
Definition: TrackletEngineDisplaced.h:44
trklet::VMStubTE::finephi
const FPGAWord & finephi() const
Definition: VMStubTE.h:23
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
trklet::ProcessBase::iSector_
unsigned int iSector_
Definition: ProcessBase.h:39
trklet::Settings::debugTracklet
bool debugTracklet() const
Definition: Settings.h:146
Exception.h
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
trklet::Settings::maxStep
unsigned int maxStep(std::string module) const
Definition: Settings.h:93
trklet::L1TStub::r
double r() const
Definition: L1TStub.h:57
trklet::Settings::nfinephi
double nfinephi(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:112
trklet::benddecode
double benddecode(int ibend, bool isPS)
Definition: Util.h:100
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
trklet::ProcessBase::globals_
Globals * globals_
Definition: ProcessBase.h:45
trklet::Settings::useSeed
bool useSeed(unsigned int iSeed) const
Definition: Settings.h:76
trklet::TrackletEngineDisplaced::disk1_
int disk1_
Definition: TrackletEngineDisplaced.h:36
mps_splice.line
line
Definition: mps_splice.py:76
trklet::VMStubsTEMemory::nVMStubsBinned
unsigned int nVMStubsBinned(unsigned int bin) const
Definition: VMStubsTEMemory.h:28
edm::Log
Definition: MessageLogger.h:70
trklet::TrackletEngineDisplaced::addOutput
void addOutput(MemoryBase *memory, std::string output) override
Definition: TrackletEngineDisplaced.cc:65
trklet::L1TStub::phi
double phi() const
Definition: L1TStub.h:62