CMS 3D CMS Logo

VMStubsTEMemory.cc
Go to the documentation of this file.
4 #include <iomanip>
5 #include <filesystem>
6 
7 using namespace std;
8 using namespace trklet;
9 
10 VMStubsTEMemory::VMStubsTEMemory(string name, Settings const& settings)
11  : MemoryBase(name, settings), bendtable_(settings) {
12  //set the layer or disk that the memory is in
14 
16 
17  //Pointer to other VMStub memory for creating stub pairs
18  other_ = nullptr;
19 
20  //What type of seeding is this memory used for
22 
23  string subname = name.substr(12, 2);
24  phibin_ = subname[0] - '0';
25  if (subname[1] != 'n') {
26  phibin_ = 10 * phibin_ + (subname[1] - '0');
27  }
28 
29  isinner_ = (layer_ % 2 == 1 or disk_ % 2 == 1);
30  // special cases with overlap seeding
31  if (overlap_ and layer_ == 2)
32  isinner_ = true;
33  if (overlap_ and layer_ == 3)
34  isinner_ = false;
35  if (overlap_ and disk_ == 1)
36  isinner_ = false;
37 
38  if (extra_ and layer_ == 2)
39  isinner_ = true;
40  if (extra_ and layer_ == 3)
41  isinner_ = false;
42  // more special cases for triplets
43  if (!overlap_ and extended_ and layer_ == 2)
44  isinner_ = true;
45  if (!overlap_ and extended_ and layer_ == 3)
46  isinner_ = false;
47  if (overlap_ and extended_ and layer_ == 2)
48  isinner_ = false;
49  if (overlap_ and extended_ and disk_ == 1)
50  isinner_ = false;
51 
53 }
54 
56  //If the pt of the stub is consistent with the allowed pt of tracklets
57  //in that can be formed in this VM and the other VM used in the TE.
58 
59  if (settings_.combined()) {
60  if (disk_ > 0) {
61  assert(vmstub.stub()->isPSmodule());
62  }
63  bool negdisk = vmstub.stub()->disk().value() < 0.0;
64  if (negdisk)
65  bin += 4;
66  assert(bin < (int)stubsbinnedvm_.size());
67  if (stubsbinnedvm_[bin].size() < N_VMSTUBSMAX) {
68  stubsbinnedvm_[bin].push_back(vmstub);
69  stubsvm_.push_back(vmstub);
70  }
71  return true;
72  }
73 
74  bool pass = false;
75  if (settings_.extended() && bendtable_.size() == 0) {
76  pass = true;
77  } else {
78  pass = bendtable_.lookup(vmstub.bend().value());
79  }
80 
81  if (!pass) {
83  edm::LogVerbatim("Tracklet") << getName() << " Stub failed bend cut. bend = "
84  << settings_.benddecode(vmstub.bend().value(), layerdisk_, vmstub.isPSmodule());
85  return false;
86  }
87 
88  bool negdisk = vmstub.stub()->disk().value() < 0.0;
89 
90  if (overlap_) {
91  if (disk_ == 1) {
92  assert(bin < 4);
93  if (negdisk)
94  bin += 4;
95  if (stubsbinnedvm_[bin].size() >= settings_.maxStubsPerBin())
96  return false;
97  stubsbinnedvm_[bin].push_back(vmstub);
99  edm::LogVerbatim("Tracklet") << getName() << " Stub in disk = " << disk_ << " in bin = " << bin;
100  } else if (layer_ == 2) {
101  if (stubsbinnedvm_[bin].size() >= settings_.maxStubsPerBin())
102  return false;
103  stubsbinnedvm_[bin].push_back(vmstub);
104  }
105  } else {
106  if (vmstub.stub()->layerdisk() < N_LAYER) {
107  if (!isinner_) {
108  if (stubsbinnedvm_[bin].size() >= settings_.maxStubsPerBin())
109  return false;
110  stubsbinnedvm_[bin].push_back(vmstub);
111  }
112 
113  } else {
114  if (disk_ % 2 == 0) {
115  assert(bin < 4);
116  if (negdisk)
117  bin += 4;
118  if (stubsbinnedvm_[bin].size() >= settings_.maxStubsPerBin())
119  return false;
120  stubsbinnedvm_[bin].push_back(vmstub);
121  }
122  }
123  }
124  if (settings_.debugTracklet())
125  edm::LogVerbatim("Tracklet") << "Adding stubs to " << getName();
126  if (stubsbinnedvm_[bin].size() >= settings_.maxStubsPerBin())
127  return false;
128  stubsvm_.push_back(vmstub);
129  return true;
130 }
131 
132 // TODO - should migrate away from using this method for any binned memory
134  FPGAWord binlookup = vmstub.vmbits();
135 
136  assert(binlookup.value() >= 0);
137  int bin = (binlookup.value() / 8);
138 
139  //If the pt of the stub is consistent with the allowed pt of tracklets
140  //in that can be formed in this VM and the other VM used in the TE.
141 
142  bool pass = false;
143  if (settings_.extended() && bendtable_.size() == 0) {
144  pass = true;
145  } else {
146  pass = bendtable_.lookup(vmstub.bend().value());
147  }
148 
149  if (!pass) {
150  if (settings_.debugTracklet())
151  edm::LogVerbatim("Tracklet") << getName() << " Stub failed bend cut. bend = "
152  << settings_.benddecode(vmstub.bend().value(), layerdisk_, vmstub.isPSmodule());
153  return false;
154  }
155 
156  bool negdisk = vmstub.stub()->disk().value() < 0.0;
157 
158  if (!extended_) {
159  if (overlap_) {
160  if (disk_ == 1) {
161  assert(bin < 4);
162  if (negdisk)
163  bin += 4;
164  stubsbinnedvm_[bin].push_back(vmstub);
165  if (settings_.debugTracklet()) {
166  edm::LogVerbatim("Tracklet") << getName() << " Stub with lookup = " << binlookup.value()
167  << " in disk = " << disk_ << " in bin = " << bin;
168  }
169  }
170  } else {
171  if (vmstub.stub()->layerdisk() < N_LAYER) {
172  if (!isinner_) {
173  stubsbinnedvm_[bin].push_back(vmstub);
174  }
175 
176  } else {
177  if (disk_ % 2 == 0) {
178  assert(bin < 4);
179  if (negdisk)
180  bin += 4;
181  stubsbinnedvm_[bin].push_back(vmstub);
182  }
183  }
184  }
185  } else { //extended
186  if (!isinner_) {
187  if (layer_ > 0) {
188  stubsbinnedvm_[bin].push_back(vmstub);
189  } else {
190  if (overlap_) {
191  assert(disk_ == 1); // D1 from L2L3D1
192 
193  //bin 0 is PS, 1 through 3 is 2S
194  if (vmstub.stub()->isPSmodule()) {
195  bin = 0;
196  } else {
197  bin = vmstub.stub()->r().value(); // 0 to 9
198  bin = bin >> 2; // 0 to 2
199  bin += 1;
200  }
201  }
202  assert(bin < 4);
203  if (negdisk)
204  bin += 4;
205  stubsbinnedvm_[bin].push_back(vmstub);
206  }
207  }
208  }
209 
210  if (settings_.debugTracklet())
211  edm::LogVerbatim("Tracklet") << "Adding stubs to " << getName();
212  stubsvm_.push_back(vmstub);
213  return true;
214 }
215 
217  stubsvm_.clear();
218  for (auto& stubsbinnedvm : stubsbinnedvm_) {
219  stubsbinnedvm.clear();
220  }
221 }
222 
223 void VMStubsTEMemory::writeStubs(bool first, unsigned int iSector) {
224  iSector_ = iSector;
225  const string dirVM = settings_.memPath() + "VMStubsTE/";
226  openFile(first, dirVM, "VMStubs_");
227 
228  if (isinner_) { // inner VM for TE purpose
229  for (unsigned int j = 0; j < stubsvm_.size(); j++) {
230  string stub = stubsvm_[j].str();
231  out_ << hexstr(j) << " " << stub << " " << trklet::hexFormat(stub) << endl;
232  }
233  } else { // outer VM for TE purpose
234  for (unsigned int i = 0; i < stubsbinnedvm_.size(); i++) {
235  for (unsigned int j = 0; j < stubsbinnedvm_[i].size(); j++) {
236  string stub = stubsbinnedvm_[i][j].str();
237  out_ << hexstr(i) << " " << hexstr(j) << " " << stub << " " << trklet::hexFormat(stub) << endl;
238  }
239  }
240  }
241 
242  out_.close();
243 }
244 
245 void VMStubsTEMemory::getPhiRange(double& phimin, double& phimax, unsigned int iSeed, unsigned int inner) {
246  int nvm = -1;
247  if (overlap_) {
248  if (layer_ > 0) {
249  nvm = settings_.nallstubs(layer_ - 1) * settings_.nvmte(inner, iSeed);
250  }
251  if (disk_ > 0) {
252  nvm = settings_.nallstubs(disk_ + N_DISK) * settings_.nvmte(inner, iSeed);
253  }
254  } else {
255  if (layer_ > 0) {
256  nvm = settings_.nallstubs(layer_ - 1) * settings_.nvmte(inner, iSeed);
257  if (extra_) {
258  nvm = settings_.nallstubs(layer_ - 1) * settings_.nvmte(inner, iSeed);
259  }
260  }
261  if (disk_ > 0) {
262  nvm = settings_.nallstubs(disk_ + N_DISK) * settings_.nvmte(inner, iSeed);
263  }
264  }
265  assert(nvm > 0);
266  assert(nvm <= 32);
267  double dphi = settings_.dphisectorHG() / nvm;
268  phimax = phibin() * dphi;
269  phimin = phimax - dphi;
270 
271  return;
272 }
273 
274 void VMStubsTEMemory::setbendtable(const TrackletLUT& bendtable) { bendtable_ = bendtable; }
Log< level::Info, true > LogVerbatim
void setbendtable(const TrackletLUT &bendtable)
constexpr int N_DISK
Definition: Settings.h:26
bool isPSmodule() const
Definition: VMStubTE.h:31
const FPGAWord & r() const
Definition: Stub.h:65
std::vector< VMStubTE > stubsvm_
unsigned int iSector_
Definition: MemoryBase.h:47
void initSpecialSeeding(unsigned int pos, bool &overlap, bool &extra, bool &extended)
Definition: MemoryBase.cc:43
double benddecode(int ibend, int layerdisk, bool isPSmodule) const
Definition: Settings.h:443
const FPGAWord & bend() const
Definition: VMStubTE.h:25
bool combined() const
Definition: Settings.h:270
double dphisectorHG() const
Definition: Settings.h:320
void openFile(bool first, std::string dirName, std::string filebase)
Definition: MemoryBase.cc:75
int lookup(unsigned int index) const
constexpr unsigned int N_VMSTUBSMAX
Definition: Settings.h:42
assert(be >=bs)
std::string hexFormat(const std::string &binary)
Definition: Util.h:19
unsigned int NLONGVMBINS() const
Definition: Settings.h:369
const FPGAWord & disk() const
Definition: Stub.h:74
std::string memPath() const
Definition: Settings.h:204
const Stub * stub() const
Definition: VMStubTE.h:29
unsigned int size() const
Definition: TrackletLUT.h:117
bool addVMStub(VMStubTE vmstub, int bin)
Settings const & settings_
Definition: MemoryBase.h:53
std::ofstream out_
Definition: MemoryBase.h:49
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
const FPGAWord & vmbits() const
Definition: VMStubTE.h:27
int value() const
Definition: FPGAWord.h:24
std::string const & getName() const
Definition: MemoryBase.h:19
unsigned int layerdisk() const
Definition: Stub.cc:193
unsigned int nvmte(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:110
unsigned int nallstubs(unsigned int layerdisk) const
Definition: Settings.h:116
bool debugTracklet() const
Definition: Settings.h:194
void writeStubs(bool first, unsigned int iSector)
static std::string hexstr(unsigned int index)
Definition: MemoryBase.cc:111
std::vector< std::vector< VMStubTE > > stubsbinnedvm_
bool isPSmodule() const
Definition: Stub.h:77
bool extended() const
Definition: Settings.h:268
unsigned int maxStubsPerBin() const
Definition: Settings.h:236
void getPhiRange(double &phimin, double &phimax, unsigned int iSeed, unsigned int inner)
VMStubsTEMemory * other_
void initLayerDisk(unsigned int pos, int &layer, int &disk)
Definition: MemoryBase.cc:20
constexpr int N_LAYER
Definition: Settings.h:25