CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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;
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) {
102  return false;
103  stubsbinnedvm_[bin].push_back(vmstub);
104  }
105  } else {
106  if (vmstub.stub()->layerdisk() < N_LAYER) {
107  if (!isinner_) {
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;
119  return false;
120  stubsbinnedvm_[bin].push_back(vmstub);
121  }
122  }
123  }
124  if (settings_.debugTracklet())
125  edm::LogVerbatim("Tracklet") << "Adding stubs to " << getName();
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  out_ << "0x";
231  out_ << std::setfill('0') << std::setw(2);
232  out_ << hex << j << dec;
233  string stub = stubsvm_[j].str();
234  out_ << " " << stub << " " << trklet::hexFormat(stub) << endl;
235  }
236  } else { // outer VM for TE purpose
237  for (unsigned int i = 0; i < stubsbinnedvm_.size(); i++) {
238  for (unsigned int j = 0; j < stubsbinnedvm_[i].size(); j++) {
239  string stub = stubsbinnedvm_[i][j].str();
240  out_ << hex << i << " " << j << dec << " " << stub << " " << trklet::hexFormat(stub) << endl;
241  }
242  }
243  }
244 
245  out_.close();
246 }
247 
248 void VMStubsTEMemory::getPhiRange(double& phimin, double& phimax, unsigned int iSeed, unsigned int inner) {
249  int nvm = -1;
250  if (overlap_) {
251  if (layer_ > 0) {
252  nvm = settings_.nallstubs(layer_ - 1) * settings_.nvmte(inner, iSeed);
253  }
254  if (disk_ > 0) {
255  nvm = settings_.nallstubs(disk_ + N_DISK) * settings_.nvmte(inner, iSeed);
256  }
257  } else {
258  if (layer_ > 0) {
259  nvm = settings_.nallstubs(layer_ - 1) * settings_.nvmte(inner, iSeed);
260  if (extra_) {
261  nvm = settings_.nallstubs(layer_ - 1) * settings_.nvmte(inner, iSeed);
262  }
263  }
264  if (disk_ > 0) {
265  nvm = settings_.nallstubs(disk_ + N_DISK) * settings_.nvmte(inner, iSeed);
266  }
267  }
268  assert(nvm > 0);
269  assert(nvm <= 32);
270  double dphi = settings_.dphisectorHG() / nvm;
271  phimax = phibin() * dphi;
272  phimin = phimax - dphi;
273 
274  return;
275 }
276 
277 void VMStubsTEMemory::setbendtable(const TrackletLUT& bendtable) { bendtable_ = bendtable; }
Log< level::Info, true > LogVerbatim
const FPGAWord & disk() const
Definition: Stub.h:68
double dphisectorHG() const
Definition: Settings.h:281
void setbendtable(const TrackletLUT &bendtable)
constexpr int N_DISK
Definition: Settings.h:22
std::string memPath() const
Definition: Settings.h:192
std::vector< VMStubTE > stubsvm_
unsigned int iSector_
Definition: MemoryBase.h:44
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::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
void initSpecialSeeding(unsigned int pos, bool &overlap, bool &extra, bool &extended)
Definition: MemoryBase.cc:42
bool isPSmodule() const
Definition: Stub.h:71
void openFile(bool first, std::string dirName, std::string filebase)
Definition: MemoryBase.cc:74
constexpr unsigned int N_VMSTUBSMAX
Definition: Settings.h:38
assert(be >=bs)
bool debugTracklet() const
Definition: Settings.h:182
std::string hexFormat(const std::string &binary)
Definition: Util.h:19
std::string const & getName() const
Definition: MemoryBase.h:19
bool addVMStub(VMStubTE vmstub, int bin)
int value() const
Definition: FPGAWord.h:24
Settings const & settings_
Definition: MemoryBase.h:50
const FPGAWord & vmbits() const
Definition: VMStubTE.h:27
std::ofstream out_
Definition: MemoryBase.h:46
unsigned int NLONGVMBINS() const
Definition: Settings.h:329
unsigned int nvmte(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:101
unsigned int nallstubs(unsigned int layerdisk) const
Definition: Settings.h:107
bool isPSmodule() const
Definition: VMStubTE.h:31
const Stub * stub() const
Definition: VMStubTE.h:29
int lookup(unsigned int index) const
Definition: TrackletLUT.cc:900
void writeStubs(bool first, unsigned int iSector)
bool extended() const
Definition: Settings.h:248
std::vector< std::vector< VMStubTE > > stubsbinnedvm_
unsigned int layerdisk() const
Definition: Stub.cc:185
unsigned int size() const
Definition: TrackletLUT.h:77
const FPGAWord & r() const
Definition: Stub.h:60
double benddecode(int ibend, int layerdisk, bool isPSmodule) const
Definition: Settings.h:402
void getPhiRange(double &phimin, double &phimax, unsigned int iSeed, unsigned int inner)
VMStubsTEMemory * other_
const FPGAWord & bend() const
Definition: VMStubTE.h:25
tuple size
Write out results.
unsigned int maxStubsPerBin() const
Definition: Settings.h:224
void initLayerDisk(unsigned int pos, int &layer, int &disk)
Definition: MemoryBase.cc:19
bool combined() const
Definition: Settings.h:250
constexpr int N_LAYER
Definition: Settings.h:21