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 
62 
64  if (settings_.writetrace()) {
65  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output "
66  << output;
67  }
68  if (output == "stubpairout") {
69  StubPairsMemory* tmp = dynamic_cast<StubPairsMemory*>(memory);
70  assert(tmp != nullptr);
71  stubpairs_.push_back(tmp);
72  return;
73  }
74  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output;
75 }
76 
78  if (settings_.writetrace()) {
79  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input "
80  << input;
81  }
82  if (input == "firstvmstubin") {
83  VMStubsTEMemory* tmp = dynamic_cast<VMStubsTEMemory*>(memory);
84  assert(tmp != nullptr);
85  firstvmstubs_.push_back(tmp);
86  return;
87  }
88  if (input == "secondvmstubin") {
89  VMStubsTEMemory* tmp = dynamic_cast<VMStubsTEMemory*>(memory);
90  assert(tmp != nullptr);
92  return;
93  }
94  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input;
95 }
96 
98  if (!settings_.useSeed(iSeed_))
99  return;
100 
102  readTables();
103 
104  unsigned int countall = 0;
105  unsigned int countpass = 0;
106  unsigned int nInnerStubs = 0;
107 
108  for (unsigned int iInnerMem = 0; iInnerMem < firstvmstubs_.size();
109  nInnerStubs += firstvmstubs_.at(iInnerMem)->nVMStubs(), iInnerMem++)
110  ;
111 
112  assert(!firstvmstubs_.empty());
113  assert(secondvmstubs_ != nullptr);
114 
115  for (auto& iInnerMem : firstvmstubs_) {
116  assert(iInnerMem->nVMStubs() == iInnerMem->nVMStubs());
117  for (unsigned int i = 0; i < iInnerMem->nVMStubs(); i++) {
118  const VMStubTE& firstvmstub = iInnerMem->getVMStubTE(i);
119  if (settings_.debugTracklet()) {
120  edm::LogVerbatim("Tracklet") << "In " << getName() << " have first stub";
121  }
122 
123  if ((layer1_ == 3 && layer2_ == 4) || (layer1_ == 5 && layer2_ == 6)) {
124  int lookupbits = firstvmstub.vmbits().value() & 1023;
125  int zdiffmax = (lookupbits >> 7);
126  int newbin = (lookupbits & 127);
127  int bin = newbin / 8;
128 
129  int zbinfirst = newbin & 7;
130 
131  int start = (bin >> 1);
132  int last = start + (bin & 1);
133 
134  assert(last < 8);
135 
136  if (settings_.debugTracklet()) {
137  edm::LogVerbatim("Tracklet") << "Will look in zbins " << start << " to " << last;
138  }
139  for (int ibin = start; ibin <= last; ibin++) {
140  for (unsigned int j = 0; j < secondvmstubs_->nVMStubsBinned(ibin); j++) {
141  if (settings_.debugTracklet()) {
142  edm::LogVerbatim("Tracklet") << "In " << getName() << " have second stub(1) " << ibin << " " << j;
143  }
144 
145  if (countall >= settings_.maxStep("TE"))
146  break;
147  countall++;
148  const VMStubTE& secondvmstub = secondvmstubs_->getVMStubTEBinned(ibin, j);
149 
150  int zbin = (secondvmstub.vmbits().value() & 7);
151  if (start != ibin)
152  zbin += 8;
153  if (zbin < zbinfirst || zbin - zbinfirst > zdiffmax) {
154  if (settings_.debugTracklet()) {
155  edm::LogVerbatim("Tracklet") << "Stubpair rejected because of wrong zbin";
156  }
157  continue;
158  }
159 
160  assert(firstphibits_ != -1);
161  assert(secondphibits_ != -1);
162 
163  FPGAWord iphifirstbin = firstvmstub.finephi();
164  FPGAWord iphisecondbin = secondvmstub.finephi();
165 
166  unsigned int index = (iphifirstbin.value() << secondphibits_) + iphisecondbin.value();
167 
168  FPGAWord firstbend = firstvmstub.bend();
169  FPGAWord secondbend = secondvmstub.bend();
170 
171  index = (index << firstbend.nbits()) + firstbend.value();
172  index = (index << secondbend.nbits()) + secondbend.value();
173 
175  (index >= table_.size() || table_.at(index).empty())) {
176  if (settings_.debugTracklet()) {
177  edm::LogVerbatim("Tracklet") << "Stub pair rejected because of stub pt cut bends : "
178  << benddecode(firstvmstub.bend().value(), firstvmstub.isPSmodule()) << " "
179  << benddecode(secondvmstub.bend().value(), secondvmstub.isPSmodule());
180  }
181  continue;
182  }
183 
184  if (settings_.debugTracklet())
185  edm::LogVerbatim("Tracklet") << "Adding layer-layer pair in " << getName();
186  for (unsigned int isp = 0; isp < stubpairs_.size(); ++isp) {
188  (index < table_.size() && table_.at(index).count(isp))) {
189  if (settings_.writeMonitorData("Seeds")) {
190  ofstream fout("seeds.txt", ofstream::app);
191  fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << 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") << "Stub pair rejected because of stub pt cut bends : "
258  << benddecode(firstvmstub.bend().value(), firstvmstub.isPSmodule()) << " "
259  << benddecode(secondvmstub.bend().value(), secondvmstub.isPSmodule());
260  }
261  continue;
262  }
263 
264  if (settings_.debugTracklet())
265  edm::LogVerbatim("Tracklet") << "Adding layer-layer pair in " << getName();
266  for (unsigned int isp = 0; isp < stubpairs_.size(); ++isp) {
268  (index < table_.size() && table_.at(index).count(isp))) {
269  if (settings_.writeMonitorData("Seeds")) {
270  ofstream fout("seeds.txt", ofstream::app);
271  fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << iSeed_ << endl;
272  fout.close();
273  }
274  stubpairs_.at(isp)->addStubPair(firstvmstub, secondvmstub, index, getName());
275  }
276  }
277 
278  countpass++;
279  }
280  }
281 
282  } else if (disk1_ == 1 && disk2_ == 2) {
283  if (settings_.debugTracklet())
284  edm::LogVerbatim("Tracklet") << getName() << "[" << iSector_ << "] Disk-disk pair";
285 
286  int lookupbits = firstvmstub.vmbits().value() & 511;
287  bool negdisk = firstvmstub.stub()->disk().value() < 0;
288  int rdiffmax = (lookupbits >> 6);
289  int newbin = (lookupbits & 63);
290  int bin = newbin / 8;
291 
292  int rbinfirst = newbin & 7;
293 
294  int start = (bin >> 1);
295  if (negdisk)
296  start += 4;
297  int last = start + (bin & 1);
298  assert(last < 8);
299  for (int ibin = start; ibin <= last; ibin++) {
300  if (settings_.debugTracklet()) {
301  edm::LogVerbatim("Tracklet") << getName() << " looking for matching stub in " << secondvmstubs_->getName()
302  << " in bin = " << ibin << " with " << secondvmstubs_->nVMStubsBinned(ibin)
303  << " stubs";
304  }
305  for (unsigned int j = 0; j < secondvmstubs_->nVMStubsBinned(ibin); j++) {
306  if (countall >= settings_.maxStep("TE"))
307  break;
308  countall++;
309 
310  const VMStubTE& secondvmstub = secondvmstubs_->getVMStubTEBinned(ibin, j);
311 
312  int rbin = (secondvmstub.vmbits().value() & 7);
313  if (start != ibin)
314  rbin += 8;
315  if (rbin < rbinfirst)
316  continue;
317  if (rbin - rbinfirst > rdiffmax)
318  continue;
319 
320  unsigned int irsecondbin = secondvmstub.vmbits().value() >> 2;
321 
322  FPGAWord iphifirstbin = firstvmstub.finephi();
323  FPGAWord iphisecondbin = secondvmstub.finephi();
324 
325  unsigned int index = (irsecondbin << (secondphibits_ + firstphibits_)) +
326  (iphifirstbin.value() << secondphibits_) + iphisecondbin.value();
327 
328  FPGAWord firstbend = firstvmstub.bend();
329  FPGAWord secondbend = secondvmstub.bend();
330 
331  index = (index << firstbend.nbits()) + firstbend.value();
332  index = (index << secondbend.nbits()) + secondbend.value();
333 
335  (index >= table_.size() || table_.at(index).empty())) {
336  if (settings_.debugTracklet()) {
337  edm::LogVerbatim("Tracklet") << "Stub pair rejected because of stub pt cut bends : "
338  << benddecode(firstvmstub.bend().value(), firstvmstub.isPSmodule()) << " "
339  << benddecode(secondvmstub.bend().value(), secondvmstub.isPSmodule());
340  }
341  continue;
342  }
343 
344  if (settings_.debugTracklet())
345  edm::LogVerbatim("Tracklet") << "Adding disk-disk pair in " << getName();
346 
347  for (unsigned int isp = 0; isp < stubpairs_.size(); ++isp) {
349  (index < table_.size() && table_.at(index).count(isp))) {
350  if (settings_.writeMonitorData("Seeds")) {
351  ofstream fout("seeds.txt", ofstream::app);
352  fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << iSeed_ << endl;
353  fout.close();
354  }
355  stubpairs_.at(isp)->addStubPair(firstvmstub, secondvmstub, index, getName());
356  }
357  }
358  countpass++;
359  }
360  }
361  }
362  }
363  }
364  if (countall > 5000) {
365  edm::LogVerbatim("Tracklet") << "In TrackletEngineDisplaced::execute : " << getName() << " " << nInnerStubs << " "
366  << secondvmstubs_->nVMStubs() << " " << countall << " " << countpass;
367  for (auto& iInnerMem : firstvmstubs_) {
368  for (unsigned int i = 0; i < iInnerMem->nVMStubs(); i++) {
369  const VMStubTE& firstvmstub = iInnerMem->getVMStubTE(i);
370  edm::LogVerbatim("Tracklet") << "In TrackletEngineDisplaced::execute first stub : "
371  << firstvmstub.stub()->l1tstub()->r() << " "
372  << firstvmstub.stub()->l1tstub()->phi() << " "
373  << firstvmstub.stub()->l1tstub()->r() * firstvmstub.stub()->l1tstub()->phi() << " "
374  << firstvmstub.stub()->l1tstub()->z();
375  }
376  }
377  for (unsigned int i = 0; i < secondvmstubs_->nVMStubs(); i++) {
378  const VMStubTE& secondvmstub = secondvmstubs_->getVMStubTE(i);
379  edm::LogVerbatim("Tracklet") << "In TrackletEngineDisplaced::execute second stub : "
380  << secondvmstub.stub()->l1tstub()->r() << " "
381  << secondvmstub.stub()->l1tstub()->phi() << " "
382  << secondvmstub.stub()->l1tstub()->r() * secondvmstub.stub()->l1tstub()->phi() << " "
383  << secondvmstub.stub()->l1tstub()->z();
384  }
385  }
386 
387  if (settings_.writeMonitorData("TED")) {
388  globals_->ofstream("trackletenginedisplaces.txt") << getName() << " " << countall << " " << countpass << endl;
389  }
390 }
391 
393  ifstream fin;
394  string tableName, line, word;
395 
396  string tablePath = settings_.tableTEDFile();
397  unsigned int finddir = tablePath.find("table_TED_");
398  tableName = tablePath.substr(0, finddir) + "table_" + name_ + ".txt";
399 
400  fin.open(tableName, ifstream::in);
401  if (!fin) {
402  throw cms::Exception("BadConfig") << "TripletEngine::readTables, file " << tableName << " not known";
403  }
404 
405  while (getline(fin, line)) {
406  istringstream iss(line);
407  table_.resize(table_.size() + 1);
408 
409  while (iss >> word)
410  table_[table_.size() - 1].insert(memNameToIndex(word));
411  }
412  fin.close();
413 }
414 
415 const short TrackletEngineDisplaced::memNameToIndex(const string& name) {
416  for (unsigned int isp = 0; isp < stubpairs_.size(); ++isp)
417  if (stubpairs_.at(isp)->getName() == name)
418  return isp;
419  return -1;
420 }
Settings.h
TrackletEngineDisplaced.h
mps_fire.i
i
Definition: mps_fire.py:428
trklet::Settings::writetrace
bool writetrace() const
Definition: Settings.h:162
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:180
trklet::VMStubTE
Definition: VMStubTE.h:15
trklet::TrackletEngineDisplaced::disk2_
int disk2_
Definition: TrackletEngineDisplaced.h:39
trklet::TrackletEngineDisplaced::iSeed_
int iSeed_
Definition: TrackletEngineDisplaced.h:51
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
trklet::TrackletEngineDisplaced::readTables
void readTables()
Definition: TrackletEngineDisplaced.cc:392
memory
Definition: HGCRecHitSoA.h:20
trklet::VMStubsTEMemory::getVMStubTEBinned
const VMStubTE & getVMStubTEBinned(unsigned int bin, unsigned int i) const
Definition: VMStubsTEMemory.h:36
trklet::TrackletEngineDisplaced::~TrackletEngineDisplaced
~TrackletEngineDisplaced() override
Definition: TrackletEngineDisplaced.cc:61
trklet::Settings
Definition: Settings.h:31
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:97
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:44
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:28
word
uint64_t word
Definition: CTPPSTotemDataFormatter.cc:29
dqmdumpme.last
last
Definition: dqmdumpme.py:56
trklet::Settings::enableTripletTables
bool enableTripletTables() const
Definition: Settings.h:179
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:52
trklet::TrackletEngineDisplaced::addInput
void addInput(MemoryBase *memory, std::string input) override
Definition: TrackletEngineDisplaced.cc:77
trklet::VMStubsTEMemory::getVMStubTE
const VMStubTE & getVMStubTE(unsigned int i) const
Definition: VMStubsTEMemory.h:34
trklet::FPGAWord
Definition: FPGAWord.h:9
trklet::TrackletEngineDisplaced::firstvmstubs_
std::vector< VMStubsTEMemory * > firstvmstubs_
Definition: TrackletEngineDisplaced.h:41
trklet::TrackletEngineDisplaced::secondphibits_
int secondphibits_
Definition: TrackletEngineDisplaced.h:49
trklet::TrackletEngineDisplaced::layer1_
int layer1_
Definition: TrackletEngineDisplaced.h:36
trklet::MemoryBase
Definition: MemoryBase.h:13
trklet::Settings::nfinephi
int nfinephi(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:122
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::memNameToIndex
const short memNameToIndex(const std::string &name)
Definition: TrackletEngineDisplaced.cc:415
trklet::TrackletEngineDisplaced::secondvmstubs_
VMStubsTEMemory * secondvmstubs_
Definition: TrackletEngineDisplaced.h:42
StubPairsMemory.h
Globals.h
trklet::TrackletEngineDisplaced::firstphibits_
int firstphibits_
Definition: TrackletEngineDisplaced.h:48
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:37
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
trklet::Settings::writeMonitorData
bool writeMonitorData(std::string module) const
Definition: Settings.h:96
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::TrackletEngineDisplaced::table_
std::vector< std::set< short > > table_
Definition: TrackletEngineDisplaced.h:46
trklet::Stub::l1tstub
L1TStub * l1tstub()
Definition: Stub.h:69
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
Exception
Definition: hltDiff.cc:245
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::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:161
Exception.h
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
trklet::Settings::maxStep
unsigned int maxStep(std::string module) const
Definition: Settings.h:103
trklet::L1TStub::r
double r() const
Definition: L1TStub.h:57
trklet::benddecode
double benddecode(int ibend, bool isPS)
Definition: Util.h:106
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:81
trklet::TrackletEngineDisplaced::disk1_
int disk1_
Definition: TrackletEngineDisplaced.h:38
mps_splice.line
line
Definition: mps_splice.py:76
trklet::VMStubsTEMemory::nVMStubsBinned
unsigned int nVMStubsBinned(unsigned int bin) const
Definition: VMStubsTEMemory.h:30
edm::Log
Definition: MessageLogger.h:70
trklet::TrackletEngineDisplaced::addOutput
void addOutput(MemoryBase *memory, std::string output) override
Definition: TrackletEngineDisplaced.cc:63
trklet::L1TStub::phi
double phi() const
Definition: L1TStub.h:62