CMS 3D CMS Logo

VMStubsTEMemory.cc
Go to the documentation of this file.
3 #include <iomanip>
4 #include <filesystem>
5 
6 using namespace std;
7 using namespace trklet;
8 
9 VMStubsTEMemory::VMStubsTEMemory(string name, Settings const& settings, unsigned int iSector)
10  : MemoryBase(name, settings, iSector) {
11  //set the layer or disk that the memory is in
13 
14  //Pointer to other VMStub memory for creating stub pairs
15  other_ = nullptr;
16 
17  //What type of seeding is this memory used for
19 
20  string subname = name.substr(12, 2);
21  phibin_ = subname[0] - '0';
22  if (subname[1] != 'n') {
23  phibin_ = 10 * phibin_ + (subname[1] - '0');
24  }
25 
26  //set the bins used in the bend tabele
27  unsigned int nbins = 8;
28  if (layer_ >= 4)
29  nbins = 16;
30  if (disk_ == 1 && extended_ && overlap_)
31  nbins = 16;
32  for (unsigned int i = 0; i < nbins; i++) {
33  vmbendtable_.push_back(true);
34  }
35 
36  isinner_ = (layer_ % 2 == 1 or disk_ % 2 == 1);
37  // special cases with overlap seeding
38  if (overlap_ and layer_ == 2)
39  isinner_ = true;
40  if (overlap_ and layer_ == 3)
41  isinner_ = false;
42  if (overlap_ and disk_ == 1)
43  isinner_ = false;
44 
45  if (extra_ and layer_ == 2)
46  isinner_ = true;
47  if (extra_ and layer_ == 3)
48  isinner_ = false;
49  // more special cases for triplets
50  if (!overlap_ and extended_ and layer_ == 2)
51  isinner_ = true;
52  if (!overlap_ and extended_ and layer_ == 3)
53  isinner_ = false;
54  if (overlap_ and extended_ and layer_ == 2)
55  isinner_ = false;
56  if (overlap_ and extended_ and disk_ == 1)
57  isinner_ = false;
58 
60 }
61 
63  //If the pt of the stub is consistent with the allowed pt of tracklets
64  //in that can be formed in this VM and the other VM used in the TE.
65 
66  if (settings_.combined()) {
67  if (disk_ > 0) {
68  assert(vmstub.stub()->isPSmodule());
69  }
70  bool negdisk = vmstub.stub()->disk().value() < 0.0;
71  if (negdisk)
72  bin += 4;
73  assert(bin < (int)stubsbinnedvm_.size());
74  stubsbinnedvm_[bin].push_back(vmstub);
75  stubsvm_.push_back(vmstub);
76  return true;
77  }
78 
79  bool pass = passbend(vmstub.bend().value());
80 
81  if (!pass) {
83  edm::LogVerbatim("Tracklet") << getName() << " Stub failed bend cut. bend = "
84  << benddecode(vmstub.bend().value(), 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()->isBarrel()) {
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  bool pass = passbend(vmstub.bend().value());
142 
143  if (!pass) {
144  if (settings_.debugTracklet())
145  edm::LogVerbatim("Tracklet") << getName() << " Stub failed bend cut. bend = "
146  << benddecode(vmstub.bend().value(), vmstub.isPSmodule());
147  return false;
148  }
149 
150  bool negdisk = vmstub.stub()->disk().value() < 0.0;
151 
152  if (!extended_) {
153  if (overlap_) {
154  if (disk_ == 1) {
155  assert(bin < 4);
156  if (negdisk)
157  bin += 4;
158  stubsbinnedvm_[bin].push_back(vmstub);
159  if (settings_.debugTracklet()) {
160  edm::LogVerbatim("Tracklet") << getName() << " Stub with lookup = " << binlookup.value()
161  << " in disk = " << disk_ << " in bin = " << bin;
162  }
163  }
164  } else {
165  if (vmstub.stub()->isBarrel()) {
166  if (!isinner_) {
167  stubsbinnedvm_[bin].push_back(vmstub);
168  }
169 
170  } else {
171  if (disk_ % 2 == 0) {
172  assert(bin < 4);
173  if (negdisk)
174  bin += 4;
175  stubsbinnedvm_[bin].push_back(vmstub);
176  }
177  }
178  }
179  } else { //extended
180  if (!isinner_) {
181  if (layer_ > 0) {
182  stubsbinnedvm_[bin].push_back(vmstub);
183  } else {
184  if (overlap_) {
185  assert(disk_ == 1); // D1 from L2L3D1
186 
187  //bin 0 is PS, 1 through 3 is 2S
188  if (vmstub.stub()->isPSmodule()) {
189  bin = 0;
190  } else {
191  bin = vmstub.stub()->r().value(); // 0 to 9
192  bin = bin >> 2; // 0 to 2
193  bin += 1;
194  }
195  }
196  assert(bin < 4);
197  if (negdisk)
198  bin += 4;
199  stubsbinnedvm_[bin].push_back(vmstub);
200  }
201  }
202  }
203 
204  if (settings_.debugTracklet())
205  edm::LogVerbatim("Tracklet") << "Adding stubs to " << getName();
206  stubsvm_.push_back(vmstub);
207  return true;
208 }
209 
211  stubsvm_.clear();
212  for (auto& stubsbinnedvm : stubsbinnedvm_) {
213  stubsbinnedvm.clear();
214  }
215 }
216 
218  const string dirVM = settings_.memPath() + "VMStubsTE/";
219  openFile(first, dirVM, "VMStubs_");
220 
221  if (isinner_) { // inner VM for TE purpose
222  for (unsigned int j = 0; j < stubsvm_.size(); j++) {
223  out_ << "0x";
224  out_ << std::setfill('0') << std::setw(2);
225  out_ << hex << j << dec;
226  string stub = stubsvm_[j].str();
227  out_ << " " << stub << " " << trklet::hexFormat(stub) << endl;
228  }
229  } else { // outer VM for TE purpose
230  for (unsigned int i = 0; i < settings_.NLONGVMBINS(); i++) {
231  for (unsigned int j = 0; j < stubsbinnedvm_[i].size(); j++) {
232  string stub = stubsbinnedvm_[i][j].str();
233  out_ << hex << i << " " << j << dec << " " << stub << " " << trklet::hexFormat(stub) << endl;
234  }
235  }
236  }
237 
238  out_.close();
239 }
240 
241 void VMStubsTEMemory::getPhiRange(double& phimin, double& phimax, unsigned int iSeed, unsigned int inner) {
242  int nvm = -1;
243  if (overlap_) {
244  if (layer_ > 0) {
245  nvm = settings_.nallstubs(layer_ - 1) * settings_.nvmte(inner, iSeed);
246  }
247  if (disk_ > 0) {
248  nvm = settings_.nallstubs(disk_ + N_DISK) * settings_.nvmte(inner, iSeed);
249  }
250  } else {
251  if (layer_ > 0) {
252  nvm = settings_.nallstubs(layer_ - 1) * settings_.nvmte(inner, iSeed);
253  if (extra_) {
254  nvm = settings_.nallstubs(layer_ - 1) * settings_.nvmte(inner, iSeed);
255  }
256  }
257  if (disk_ > 0) {
258  nvm = settings_.nallstubs(disk_ + N_DISK) * settings_.nvmte(inner, iSeed);
259  }
260  }
261  assert(nvm > 0);
262  assert(nvm <= 32);
263  double dphi = settings_.dphisectorHG() / nvm;
264  phimax = phibin() * dphi;
265  phimin = phimax - dphi;
266 
267  return;
268 }
269 
270 void VMStubsTEMemory::setbendtable(std::vector<bool> vmbendtable) {
271  assert(vmbendtable_.size() == vmbendtable.size());
272  for (unsigned int i = 0; i < vmbendtable.size(); i++) {
273  vmbendtable_[i] = vmbendtable[i];
274  }
275 
276  if (iSector_ == 0 && settings_.writeTable())
278 }
279 
281  if (not std::filesystem::exists(settings_.tablePath())) {
282  int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str());
283  if (fail)
284  throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory "
285  << settings_.tablePath();
286  }
287 
288  const string fname = settings_.tablePath() + getName() + "_vmbendcut.tab";
289  ofstream outvmbendcut(fname);
290  if (outvmbendcut.fail())
291  throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname;
292 
293  outvmbendcut << "{" << endl;
294  unsigned int vmbendtableSize = vmbendtable_.size();
295  assert(vmbendtableSize == 16 || vmbendtableSize == 8);
296  for (unsigned int i = 0; i < vmbendtableSize; i++) {
297  if (i != 0)
298  outvmbendcut << "," << endl;
299  outvmbendcut << vmbendtable_[i];
300  }
301  outvmbendcut << endl << "};" << endl;
302  outvmbendcut.close();
303 }
trklet::MemoryBase::settings_
Settings const & settings_
Definition: MemoryBase.h:50
trklet::VMStubsTEMemory::setbendtable
void setbendtable(std::vector< bool > vmbendtable)
Definition: VMStubsTEMemory.cc:270
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
trklet::VMStubTE
Definition: VMStubTE.h:15
trklet::VMStubsTEMemory::vmbendtable_
std::vector< bool > vmbendtable_
Definition: VMStubsTEMemory.h:69
phimin
float phimin
Definition: ReggeGribovPartonMCHadronizer.h:107
trklet::Settings
Definition: Settings.h:31
trklet::Settings::memPath
std::string const & memPath() const
Definition: Settings.h:169
cms::cuda::assert
assert(be >=bs)
trklet::MemoryBase::out_
std::ofstream out_
Definition: MemoryBase.h:46
trklet::N_DISK
constexpr int N_DISK
Definition: Settings.h:20
trklet::MemoryBase::initLayerDisk
void initLayerDisk(unsigned int pos, int &layer, int &disk)
Definition: MemoryBase.cc:18
trklet::VMStubTE::isPSmodule
bool isPSmodule() const
Definition: VMStubTE.h:31
trklet::Stub::isBarrel
bool isBarrel() const
Definition: Stub.h:60
trklet::Stub::r
const FPGAWord & r() const
Definition: Stub.h:49
trklet::Settings::writeTable
bool writeTable() const
Definition: Settings.h:168
trklet::VMStubTE::bend
const FPGAWord & bend() const
Definition: VMStubTE.h:25
trklet::Settings::combined
bool combined() const
Definition: Settings.h:227
trklet::VMStubsTEMemory::writeVMBendTable
void writeVMBendTable()
Definition: VMStubsTEMemory.cc:280
trklet::Stub::disk
const FPGAWord & disk() const
Definition: Stub.h:57
trklet::MemoryBase::getName
std::string const & getName() const
Definition: MemoryBase.h:19
trklet::MemoryBase::openFile
void openFile(bool first, std::string dirName, std::string filebase)
Definition: MemoryBase.cc:73
trklet::VMStubsTEMemory::extra_
bool extra_
Definition: VMStubsTEMemory.h:65
trklet::Settings::dphisectorHG
double dphisectorHG() const
Definition: Settings.h:251
trklet::VMStubsTEMemory::disk_
int disk_
Definition: VMStubsTEMemory.h:61
SurfaceOrientation::inner
Definition: Surface.h:19
trklet::VMStubsTEMemory::isinner_
bool isinner_
Definition: VMStubsTEMemory.h:67
LaserClient_cfi.nbins
nbins
Definition: LaserClient_cfi.py:51
trklet::VMStubsTEMemory::extended_
bool extended_
Definition: VMStubsTEMemory.h:66
trklet::VMStubsTEMemory::layer_
int layer_
Definition: VMStubsTEMemory.h:60
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:112
trklet::FPGAWord
Definition: FPGAWord.h:9
trklet::MemoryBase
Definition: MemoryBase.h:13
trklet::Settings::NLONGVMBINS
unsigned int NLONGVMBINS() const
Definition: Settings.h:295
trklet::VMStubsTEMemory::addVMStub
bool addVMStub(VMStubTE vmstub, int bin)
Definition: VMStubsTEMemory.cc:62
trklet::VMStubTE::stub
const Stub * stub() const
Definition: VMStubTE.h:29
trklet::VMStubsTEMemory::other_
VMStubsTEMemory * other_
Definition: VMStubsTEMemory.h:63
trklet::VMStubsTEMemory::phibin
int phibin() const
Definition: VMStubsTEMemory.h:42
trklet::Settings::maxStubsPerBin
unsigned int maxStubsPerBin() const
Definition: Settings.h:201
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
trklet::VMStubsTEMemory::clean
void clean() override
Definition: VMStubsTEMemory.cc:210
VMStubsTEMemory.h
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
phimax
float phimax
Definition: ReggeGribovPartonMCHadronizer.h:106
alignmentValidation.fname
string fname
main script
Definition: alignmentValidation.py:959
std
Definition: JetResolutionObject.h:76
trklet::VMStubsTEMemory::passbend
bool passbend(unsigned int ibend) const
Definition: VMStubsTEMemory.h:52
trklet::Settings::tablePath
std::string const & tablePath() const
Definition: Settings.h:170
trklet::VMStubsTEMemory::writeStubs
void writeStubs(bool first)
Definition: VMStubsTEMemory.cc:217
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
trklet::VMStubsTEMemory::getPhiRange
void getPhiRange(double &phimin, double &phimax, unsigned int iSeed, unsigned int inner)
Definition: VMStubsTEMemory.cc:241
Exception
Definition: hltDiff.cc:245
trklet::Settings::nvmte
unsigned int nvmte(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:88
trklet::Settings::nallstubs
unsigned int nallstubs(unsigned int layerdisk) const
Definition: Settings.h:94
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
trklet::Settings::debugTracklet
bool debugTracklet() const
Definition: Settings.h:161
or
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
trklet::Stub::isPSmodule
bool isPSmodule() const
Definition: Stub.h:63
trklet::VMStubsTEMemory::stubsbinnedvm_
std::vector< std::vector< VMStubTE > > stubsbinnedvm_
Definition: VMStubsTEMemory.h:72
trklet::benddecode
double benddecode(int ibend, bool isPS)
Definition: Util.h:106
trklet::hexFormat
std::string hexFormat(const std::string &binary)
Definition: Util.h:15
cms::Exception
Definition: Exception.h:70
trklet::VMStubsTEMemory::phibin_
int phibin_
Definition: VMStubsTEMemory.h:62
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Log
Definition: MessageLogger.h:70
trklet::MemoryBase::initSpecialSeeding
void initSpecialSeeding(unsigned int pos, bool &overlap, bool &extra, bool &extended)
Definition: MemoryBase.cc:41
trklet::VMStubsTEMemory::stubsvm_
std::vector< VMStubTE > stubsvm_
Definition: VMStubsTEMemory.h:71
trklet::VMStubsTEMemory::overlap_
bool overlap_
Definition: VMStubsTEMemory.h:64
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
trklet::MemoryBase::iSector_
unsigned int iSector_
Definition: MemoryBase.h:44
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443