CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TrackletConfigBuilder.cc
Go to the documentation of this file.
1 #include <vector>
2 #include <utility>
3 #include <set>
4 #include <cmath>
5 #include <iostream>
6 #include <fstream>
7 #include <cstdlib>
8 #include <cassert>
9 
12 
13 using namespace std;
14 using namespace trklet;
15 
16 TrackletConfigBuilder::TrackletConfigBuilder(const Settings& settings) : settings_(settings) {
18  rcrit_ = settings.rcrit();
19 
20  combinedmodules_ = settings.combined();
21 
22  extended_ = settings.extended();
23 
24  rinvmax_ = settings.rinvmax();
25 
26  rmaxdisk_ = settings.rmaxdisk();
27  zlength_ = settings.zlength();
28 
29  for (int i = 0; i < N_LAYER; i++) {
30  rmean_[i] = settings.rmean(i);
31  }
32 
33  for (int i = 0; i < N_DISK; i++) {
34  zmean_[i] = settings.zmean(i);
35  }
36 
37  dphisectorHG_ = settings.dphisectorHG();
38 
39  for (int layerdisk = 0; layerdisk < N_LAYER + N_DISK; layerdisk++) {
40  NRegions_[layerdisk] = settings.nallstubs(layerdisk);
41  NVMME_[layerdisk] = settings.nvmme(layerdisk);
42  }
43 
44  for (unsigned int iseed = 0; iseed < N_SEED_PROMPT; iseed++) {
45  NVMTE_[iseed] = std::pair<unsigned int, unsigned int>(settings.nvmte(0, iseed), settings.nvmte(1, iseed));
46  NTC_[iseed] = settings.NTC(iseed);
47  }
48 
49  initGeom();
50 
51  buildTE();
52 
53  buildTC();
54 
56 }
57 
58 std::pair<unsigned int, unsigned int> TrackletConfigBuilder::seedLayers(unsigned int iSeed) {
59  return std::pair<unsigned int, unsigned int>(settings_.seedlayers(0, iSeed), settings_.seedlayers(1, iSeed));
60 }
61 
63  for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) {
64  double dphi = dphisectorHG_ / NRegions_[ilayer];
65  for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) {
66  std::vector<std::pair<unsigned int, unsigned int> > emptyVec;
67  projections_[ilayer].push_back(emptyVec);
68  double phimin = dphi * iReg;
69  double phimax = phimin + dphi;
70  std::pair<double, double> tmp(phimin, phimax);
71  allStubs_[ilayer].push_back(tmp);
72  double dphiVM = dphi / NVMME_[ilayer];
73  for (unsigned int iVM = 0; iVM < NVMME_[ilayer]; iVM++) {
74  double phivmmin = phimin + iVM * dphiVM;
75  double phivmmax = phivmmin + dphiVM;
76  std::pair<double, double> tmp(phivmmin, phivmmax);
77  VMStubsME_[ilayer].push_back(tmp);
78  }
79  }
80  }
81  for (unsigned int iseed = 0; iseed < N_SEED_PROMPT; iseed++) {
82  unsigned int l1 = seedLayers(iseed).first;
83  unsigned int l2 = seedLayers(iseed).second;
84  unsigned int nVM1 = NVMTE_[iseed].first;
85  unsigned int nVM2 = NVMTE_[iseed].second;
86  double dphiVM = dphisectorHG_ / (nVM1 * NRegions_[l1]);
87  for (unsigned int iVM = 0; iVM < nVM1 * NRegions_[l1]; iVM++) {
88  double phivmmin = iVM * dphiVM;
89  double phivmmax = phivmmin + dphiVM;
90  std::pair<double, double> tmp(phivmmin, phivmmax);
91  VMStubsTE_[iseed].first.push_back(tmp);
92  }
93  dphiVM = dphisectorHG_ / (nVM2 * NRegions_[l2]);
94  for (unsigned int iVM = 0; iVM < nVM2 * NRegions_[l2]; iVM++) {
95  double phivmmin = iVM * dphiVM;
96  double phivmmax = phivmmin + dphiVM;
97  std::pair<double, double> tmp(phivmmin, phivmmax);
98  VMStubsTE_[iseed].second.push_back(tmp);
99  }
100  }
101 }
102 
103 std::pair<double, double> TrackletConfigBuilder::seedRadii(unsigned int iseed) {
104  std::pair<unsigned int, unsigned int> seedlayers = seedLayers(iseed);
105 
106  unsigned int l1 = seedlayers.first;
107  unsigned int l2 = seedlayers.second;
108 
109  double r1, r2;
110 
111  if (iseed < 4) { //barrel seeding
112  r1 = rmean_[l1];
113  r2 = rmean_[l2];
114  } else if (iseed < 6) { //disk seeding
115  r1 = rmean_[0] + 40.0; //Somwwhat of a hack - but allows finding all the regions
116  //when projecting to L1
117  r2 = r1 * zmean_[l2 - 6] / zmean_[l1 - 6];
118  } else { //overlap seeding
119  r1 = rmean_[l1];
120  r2 = r1 * zmean_[l2 - 6] / zlength_;
121  }
122 
123  return std::pair<double, double>(r1, r2);
124 }
125 
126 bool TrackletConfigBuilder::validTEPair(unsigned int iseed, unsigned int iTE1, unsigned int iTE2) {
127  double rinvmin = 999.9;
128  double rinvmax = -999.9;
129 
130  double phi1[2] = {VMStubsTE_[iseed].first[iTE1].first, VMStubsTE_[iseed].first[iTE1].second};
131  double phi2[2] = {VMStubsTE_[iseed].second[iTE2].first, VMStubsTE_[iseed].second[iTE2].second};
132 
133  std::pair<double, double> seedradii = seedRadii(iseed);
134 
135  for (unsigned int i1 = 0; i1 < 2; i1++) {
136  for (unsigned int i2 = 0; i2 < 2; i2++) {
137  double arinv = rinv(seedradii.first, phi1[i1], seedradii.second, phi2[i2]);
138  if (arinv < rinvmin)
139  rinvmin = arinv;
140  if (arinv > rinvmax)
141  rinvmax = arinv;
142  }
143  }
144 
145  if (rinvmin > rinvmax_)
146  return false;
147  if (rinvmax < -rinvmax_)
148  return false;
149 
150  return true;
151 }
152 
154  for (unsigned int iseed = 0; iseed < N_SEED_PROMPT; iseed++) {
155  for (unsigned int i1 = 0; i1 < VMStubsTE_[iseed].first.size(); i1++) {
156  for (unsigned int i2 = 0; i2 < VMStubsTE_[iseed].second.size(); i2++) {
157  if (validTEPair(iseed, i1, i2)) {
158  std::pair<unsigned int, unsigned int> tmp(i1, i2);
159  TE_[iseed].push_back(tmp);
160  }
161  }
162  }
163  }
164 }
165 
167  for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) {
168  unsigned int nTC = NTC_[iSeed];
169  std::vector<std::pair<unsigned int, unsigned int> >& TEs = TE_[iSeed];
170  std::vector<std::vector<unsigned int> >& TCs = TC_[iSeed];
171 
172  //Very naive method to group TEs in TC
173 
174  double invnTC = nTC * (1.0 / TEs.size());
175 
176  for (unsigned int iTE = 0; iTE < TEs.size(); iTE++) {
177  int iTC = invnTC * iTE;
178  assert(iTC < (int)nTC);
179  if (iTC >= (int)TCs.size()) {
180  std::vector<unsigned int> tmp;
181  tmp.push_back(iTE);
182  TCs.push_back(tmp);
183  } else {
184  TCs[iTC].push_back(iTE);
185  }
186  }
187  }
188 }
189 
190 std::pair<double, double> TrackletConfigBuilder::seedPhiRange(double rproj, unsigned int iSeed, unsigned int iTC) {
191  std::vector<std::vector<unsigned int> >& TCs = TC_[iSeed];
192 
193  std::pair<double, double> seedradii = seedRadii(iSeed);
194 
195  double phimin = 999.0;
196  double phimax = -999.0;
197  for (unsigned int iTE = 0; iTE < TCs[iTC].size(); iTE++) {
198  unsigned int theTE = TCs[iTC][iTE];
199  unsigned int l1TE = TE_[iSeed][theTE].first;
200  unsigned int l2TE = TE_[iSeed][theTE].second;
201  double phi1[2] = {VMStubsTE_[iSeed].first[l1TE].first, VMStubsTE_[iSeed].first[l1TE].second};
202  double phi2[2] = {VMStubsTE_[iSeed].second[l2TE].first, VMStubsTE_[iSeed].second[l2TE].second};
203  for (unsigned int i1 = 0; i1 < 2; i1++) {
204  for (unsigned int i2 = 0; i2 < 2; i2++) {
205  double aphi = phi(seedradii.first, phi1[i1], seedradii.second, phi2[i2], rproj);
206  if (aphi < phimin)
207  phimin = aphi;
208  if (aphi > phimax)
209  phimax = aphi;
210  }
211  }
212  }
213  return std::pair<double, double>(phimin, phimax);
214 }
215 
217  for (unsigned int iseed = 0; iseed < N_SEED_PROMPT; iseed++) {
218  std::vector<std::vector<unsigned int> >& TCs = TC_[iseed];
219 
220  for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) {
221  if (matchport_[iseed][ilayer] == -1)
222  continue;
223  for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) {
224  for (unsigned int iTC = 0; iTC < TCs.size(); iTC++) {
225  double rproj = rmaxdisk_;
226  if (ilayer < 6)
227  rproj = rmean_[ilayer];
228  std::pair<double, double> phiRange = seedPhiRange(rproj, iseed, iTC);
229  if (phiRange.first < allStubs_[ilayer][iReg].second && phiRange.second > allStubs_[ilayer][iReg].first) {
230  std::pair<unsigned int, unsigned int> tmp(iseed, iTC); //seedindex and TC
231  projections_[ilayer][iReg].push_back(tmp);
232  }
233  }
234  }
235  }
236  }
237 }
238 
239 double TrackletConfigBuilder::phi(double r1, double phi1, double r2, double phi2, double r) {
240  double rhoinv = rinv(r1, phi1, r2, phi2);
241  if (fabs(rhoinv) > rinvmax_) {
242  rhoinv = rinvmax_ * rhoinv / fabs(rhoinv);
243  }
244  return phi1 + asin(0.5 * r * rhoinv) - asin(0.5 * r1 * rhoinv);
245 }
246 
247 double TrackletConfigBuilder::rinv(double r1, double phi1, double r2, double phi2) {
248  double deltaphi = phi1 - phi2;
249  return 2 * sin(deltaphi) / sqrt(r2 * r2 + r1 * r1 - 2 * r1 * r2 * cos(deltaphi));
250 }
251 
253  static std::string name[8] = {"L1L2", "L2L3", "L3L4", "L5L6", "D1D2", "D3D4", "L1D1", "L2D1"};
254 
255  assert(iSeed < 8);
256  return name[iSeed];
257 }
258 
260  static std::string num[32] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11",
261  "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22",
262  "23", "24", "25", "26", "27", "28", "29", "30", "31", "32"};
263  assert(i < 32);
264  return num[i];
265 }
266 
268  static std::string name[12] = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"};
269 
270  assert(iTC < 12);
271  return name[iTC];
272 }
273 
274 std::string TrackletConfigBuilder::iRegStr(unsigned int iReg, unsigned int iSeed) {
275  static std::string name[8] = {"A", "B", "C", "D", "E", "F", "G", "H"};
276 
277  static std::string nameOverlap[8] = {"X", "Y", "Z", "W", "Q", "R", "S", "T"};
278 
279  static std::string nameL2L3[4] = {"I", "J", "K", "L"};
280 
281  if (iSeed == Seed::L2L3) {
282  assert(iReg < 4);
283  return nameL2L3[iReg];
284  }
285  if (iSeed == Seed::L1D1 || iSeed == Seed::L2D1) {
286  assert(iReg < 8);
287  return nameOverlap[iReg];
288  }
289  assert(iReg < 8);
290  return name[iReg];
291 }
292 
293 std::string TrackletConfigBuilder::TCName(unsigned int iSeed, unsigned int iTC) {
294  if (combinedmodules_) {
295  return "TP_" + iSeedStr(iSeed) + iTCStr(iTC);
296  } else {
297  return "TC_" + iSeedStr(iSeed) + iTCStr(iTC);
298  }
299 }
300 
302  return ilayer < 6 ? ("L" + numStr(ilayer)) : ("D" + numStr(ilayer - 6));
303 }
304 
306  unsigned int iTC,
307  unsigned int ilayer,
308  unsigned int ireg) {
309  return "TPROJ_" + iSeedStr(iSeed) + iTCStr(iTC) + "_" + LayerName(ilayer) + "PHI" + iTCStr(ireg);
310 }
311 
312 std::string TrackletConfigBuilder::PRName(unsigned int ilayer, unsigned int ireg) {
313  if (combinedmodules_) {
314  return "MP_" + LayerName(ilayer) + "PHI" + iTCStr(ireg);
315  } else {
316  return "PR_" + LayerName(ilayer) + "PHI" + iTCStr(ireg);
317  }
318 }
319 
320 void TrackletConfigBuilder::writeProjectionMemories(std::ostream& os, std::ostream& memories, std::ostream&) {
321  for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) {
322  for (unsigned int ireg = 0; ireg < projections_[ilayer].size(); ireg++) {
323  for (unsigned int imem = 0; imem < projections_[ilayer][ireg].size(); imem++) {
324  unsigned int iSeed = projections_[ilayer][ireg][imem].first;
325  unsigned int iTC = projections_[ilayer][ireg][imem].second;
326 
327  memories << "TrackletProjections: " + TPROJName(iSeed, iTC, ilayer, ireg) + " [54]" << std::endl;
328 
329  os << TPROJName(iSeed, iTC, ilayer, ireg) << " input=> " << TCName(iSeed, iTC) << ".projout"
330  << LayerName(ilayer) << "PHI" << iTCStr(ireg) << " output=> " << PRName(ilayer, ireg) << ".projin"
331  << std::endl;
332  }
333  }
334  }
335 }
336 
338  unsigned int ireg1,
339  unsigned int ivm1,
340  unsigned int l2,
341  unsigned int ireg2,
342  unsigned int ivm2,
343  unsigned int iseed) {
344  return "SP_" + LayerName(l1) + "PHI" + iRegStr(ireg1, iseed) + numStr(ivm1) + "_" + LayerName(l2) + "PHI" +
345  iRegStr(ireg2, iseed) + numStr(ivm2);
346 }
347 
349  unsigned int ireg1,
350  unsigned int ivm1,
351  unsigned int l2,
352  unsigned int ireg2,
353  unsigned int ivm2,
354  unsigned int l3,
355  unsigned int ireg3,
356  unsigned int ivm3,
357  unsigned int iseed) {
358  return "SPD_" + LayerName(l1) + "PHI" + iRegStr(ireg1, iseed) + numStr(ivm1) + "_" + LayerName(l2) + "PHI" +
359  iRegStr(ireg2, iseed) + numStr(ivm2) + "_" + LayerName(l3) + "PHI" + iRegStr(ireg3, iseed) + numStr(ivm3);
360 }
361 
363  unsigned int ireg1,
364  unsigned int ivm1,
365  unsigned int l2,
366  unsigned int ireg2,
367  unsigned int ivm2,
368  unsigned int iseed) {
369  return "TE_" + LayerName(l1) + "PHI" + iRegStr(ireg1, iseed) + numStr(ivm1) + "_" + LayerName(l2) + "PHI" +
370  iRegStr(ireg2, iseed) + numStr(ivm2);
371 }
372 
374  unsigned int ireg1,
375  unsigned int ivm1,
376  unsigned int l2,
377  unsigned int ireg2,
378  unsigned int ivm2,
379  unsigned int iseed) {
380  return "TED_" + LayerName(l1) + "PHI" + iRegStr(ireg1, iseed) + numStr(ivm1) + "_" + LayerName(l2) + "PHI" +
381  iRegStr(ireg2, iseed) + numStr(ivm2);
382 }
383 
384 std::string TrackletConfigBuilder::TParName(unsigned int l1, unsigned int l2, unsigned int l3, unsigned int itc) {
385  return "TPAR_" + LayerName(l1) + LayerName(l2) + LayerName(l3) + iTCStr(itc);
386 }
387 
388 std::string TrackletConfigBuilder::TCDName(unsigned int l1, unsigned int l2, unsigned int l3, unsigned int itc) {
389  return "TCD_" + LayerName(l1) + LayerName(l2) + LayerName(l3) + iTCStr(itc);
390 }
391 
393  unsigned int l1, unsigned int l2, unsigned int l3, unsigned int itc, unsigned int projlayer, unsigned int projreg) {
394  return "TPROJ_" + LayerName(l1) + LayerName(l2) + LayerName(l3) + iTCStr(itc) + "_" + LayerName(projlayer) + "PHI" +
395  iTCStr(projreg);
396 }
397 
398 std::string TrackletConfigBuilder::FTName(unsigned int l1, unsigned int l2, unsigned int l3) {
399  return "FT_" + LayerName(l1) + LayerName(l2) + LayerName(l3);
400 }
401 
403  unsigned int l1, unsigned int ireg1, unsigned int l2, unsigned int ireg2, unsigned int iseed, unsigned int count) {
404  return "TRE_" + LayerName(l1) + iRegStr(ireg1, iseed) + LayerName(l2) + iRegStr(ireg2, iseed) + "_" + numStr(count);
405 }
406 
408  unsigned int ireg1,
409  unsigned int l2,
410  unsigned int ireg2,
411  unsigned int l3,
412  unsigned int ireg3,
413  unsigned int iseed,
414  unsigned int count) {
415  return "ST_" + LayerName(l1) + iRegStr(ireg1, iseed) + LayerName(l2) + iRegStr(ireg2, iseed) + "_" + LayerName(l3) +
416  iRegStr(ireg3, iseed) + "_" + numStr(count);
417 }
418 
419 std::string TrackletConfigBuilder::TCNAme(unsigned int iseed, unsigned int iTC) {
420  return "TC_" + iSeedStr(iseed) + iTCStr(iTC);
421 }
422 
423 void TrackletConfigBuilder::writeSPMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) {
424  if (combinedmodules_)
425  return;
426 
427  for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) {
428  for (unsigned int iTC = 0; iTC < TC_[iSeed].size(); iTC++) {
429  for (unsigned int iTE = 0; iTE < TC_[iSeed][iTC].size(); iTE++) {
430  unsigned int theTE = TC_[iSeed][iTC][iTE];
431 
432  unsigned int TE1 = TE_[iSeed][theTE].first;
433  unsigned int TE2 = TE_[iSeed][theTE].second;
434 
435  unsigned int l1 = seedLayers(iSeed).first;
436  unsigned int l2 = seedLayers(iSeed).second;
437 
438  memories << "StubPairs: "
439  << SPName(l1, TE1 / NVMTE_[iSeed].first, TE1, l2, TE2 / NVMTE_[iSeed].second, TE2, iSeed) << " [12]"
440  << std::endl;
441  modules << "TrackletEngine: "
442  << TEName(l1, TE1 / NVMTE_[iSeed].first, TE1, l2, TE2 / NVMTE_[iSeed].second, TE2, iSeed) << std::endl;
443 
444  os << SPName(l1, TE1 / NVMTE_[iSeed].first, TE1, l2, TE2 / NVMTE_[iSeed].second, TE2, iSeed) << " input=> "
445  << TEName(l1, TE1 / NVMTE_[iSeed].first, TE1, l2, TE2 / NVMTE_[iSeed].second, TE2, iSeed)
446  << ".stubpairout output=> " << TCNAme(iSeed, iTC) << ".stubpairin" << std::endl;
447  }
448  }
449  }
450 }
451 
452 void TrackletConfigBuilder::writeSPDMemories(std::ostream& wires, std::ostream& memories, std::ostream& modules) {
453  if (!extended_)
454  return;
455 
456  vector<string> stubTriplets[N_SEED];
457 
458  for (unsigned int iSeed = N_SEED_PROMPT; iSeed < N_SEED; iSeed++) {
459  int layerdisk1 = settings_.seedlayers(0, iSeed);
460  int layerdisk2 = settings_.seedlayers(1, iSeed);
461  int layerdisk3 = settings_.seedlayers(2, iSeed);
462 
463  unsigned int nallstub1 = settings_.nallstubs(layerdisk1);
464  unsigned int nallstub2 = settings_.nallstubs(layerdisk2);
465  unsigned int nallstub3 = settings_.nallstubs(layerdisk3);
466 
467  unsigned int nvm1 = settings_.nvmte(0, iSeed);
468  unsigned int nvm2 = settings_.nvmte(1, iSeed);
469  unsigned int nvm3 = settings_.nvmte(2, iSeed);
470 
471  int count = 0;
472  for (unsigned int ireg1 = 0; ireg1 < nallstub1; ireg1++) {
473  for (unsigned int ireg2 = 0; ireg2 < nallstub2; ireg2++) {
474  for (unsigned int ireg3 = 0; ireg3 < nallstub3; ireg3++) {
475  count++;
476  memories << "StubTriplets: " << STName(layerdisk1, ireg1, layerdisk2, ireg2, layerdisk3, ireg3, iSeed, count)
477  << " [18]" << std::endl;
478  stubTriplets[iSeed].push_back(STName(layerdisk1, ireg1, layerdisk2, ireg2, layerdisk3, ireg3, iSeed, count));
479  }
480  }
481  }
482 
483  for (unsigned int ireg1 = 0; ireg1 < nallstub1; ireg1++) {
484  for (unsigned int ivm1 = 0; ivm1 < nvm1; ivm1++) {
485  for (unsigned int ireg2 = 0; ireg2 < nallstub2; ireg2++) {
486  for (unsigned int ivm2 = 0; ivm2 < nvm2; ivm2++) {
487  int count = 0;
488 
489  modules << "TrackletEngineDisplaced: "
490  << TEDName(layerdisk1, ireg1, ireg1 * nvm1 + ivm1, layerdisk2, ireg2, ireg2 * nvm2 + ivm2, iSeed)
491  << std::endl;
492 
493  for (unsigned int ireg3 = 0; ireg3 < nallstub3; ireg3++) {
494  for (unsigned int ivm3 = 0; ivm3 < nvm3; ivm3++) {
495  count++;
496 
497  memories << "StubPairsDisplaced: "
498  << SPDName(layerdisk1,
499  ireg1,
500  ireg1 * nvm1 + ivm1,
501  layerdisk2,
502  ireg2,
503  ireg2 * nvm2 + ivm2,
504  layerdisk3,
505  ireg3,
506  ireg3 * nvm3 + ivm3,
507  iSeed)
508  << " [12]" << std::endl;
509 
510  modules << "TripletEngine: " << TREName(layerdisk1, ireg1, layerdisk2, ireg2, iSeed, count)
511  << std::endl;
512 
513  wires << SPDName(layerdisk1,
514  ireg1,
515  ireg1 * nvm1 + ivm1,
516  layerdisk2,
517  ireg2,
518  ireg2 * nvm2 + ivm2,
519  layerdisk3,
520  ireg3,
521  ireg3 * nvm3 + ivm3,
522  iSeed)
523  << " input=> "
524  << TEDName(layerdisk1, ireg1, ireg1 * nvm1 + ivm1, layerdisk2, ireg2, ireg2 * nvm2 + ivm2, iSeed)
525  << ".stubpairout output=> " << TREName(layerdisk1, ireg1, layerdisk2, ireg2, iSeed, count)
526  << ".stubpair"
527  << "1"
528  << "in" << std::endl;
529  }
530  }
531  }
532  }
533  }
534  }
535 
536  unsigned int nTC = 10;
537  for (unsigned int itc = 0; itc < nTC; itc++) {
538  for (int iproj = 0; iproj < 4; iproj++) {
539  int ilay = settings_.projlayers(iSeed, iproj);
540  if (ilay > 0) {
541  unsigned int nallstub = settings_.nallstubs(ilay - 1);
542  for (unsigned int ireg = 0; ireg < nallstub; ireg++) {
543  memories << "TrackletProjections: " << TPROJName(layerdisk1, layerdisk2, layerdisk3, itc, ilay - 1, ireg)
544  << " [54]" << std::endl;
545  }
546  }
547 
548  int idisk = settings_.projdisks(iSeed, iproj);
549  if (idisk > 0) {
550  unsigned int nallstub = settings_.nallstubs(idisk + 5);
551  for (unsigned int ireg = 0; ireg < nallstub; ireg++) {
552  memories << "TrackletProjections: " << TPROJName(layerdisk1, layerdisk2, layerdisk3, itc, idisk + 5, ireg)
553  << " [54]" << std::endl;
554 
555  wires << TPROJName(layerdisk1, layerdisk2, layerdisk3, itc, idisk + 5, ireg) << " input=> "
556  << TCDName(layerdisk1, layerdisk2, layerdisk3, itc) << ".projout" << LayerName(idisk + 1) << "PHI"
557  << iTCStr(ireg) << " output=> "
558  << "PR_" << LayerName(idisk + 1) << "PHI" << iTCStr(ireg) << ".projin" << std::endl;
559  }
560  }
561  }
562 
563  memories << "TrackletParameters: " << TParName(layerdisk1, layerdisk2, layerdisk3, itc) << " [56]" << std::endl;
564 
565  modules << "TrackletCalculatorDisplaced: " << TCDName(layerdisk1, layerdisk2, layerdisk3, itc) << std::endl;
566  }
567 
568  unsigned int nST = stubTriplets[iSeed].size();
569  for (unsigned int iST = 0; iST < nST; iST++) {
570  unsigned int iTC = (iST * nTC) / nST;
571  assert(iTC < nTC);
572  string stname = stubTriplets[iSeed][iST];
573  string trename = "TRE_" + stname.substr(3, 6) + "_";
574  unsigned int stlen = stname.size();
575  if (stname[stlen - 2] == '_')
576  trename += stname.substr(stlen - 1, 1);
577  if (stname[stlen - 3] == '_')
578  trename += stname.substr(stlen - 2, 2);
579  wires << stname << " input=> " << trename << ".stubtripout output=> "
580  << TCDName(layerdisk1, layerdisk2, layerdisk3, iTC) << ".stubtriplet" << ((iST * nTC) % nST) << "in"
581  << std::endl;
582  }
583 
584  modules << "FitTrack: " << FTName(layerdisk1, layerdisk2, layerdisk3) << std::endl;
585  }
586 }
587 
588 void TrackletConfigBuilder::writeAPMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) {
589  if (combinedmodules_)
590  return;
591 
592  for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) {
593  for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) {
594  memories << "AllProj: AP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << " [56]" << std::endl;
595  modules << "ProjectionRouter: PR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl;
596 
597  os << "AP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << " input=> PR_" << LayerName(ilayer) << "PHI"
598  << iTCStr(iReg) << ".allprojout output=> MC_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allprojin"
599  << std::endl;
600  }
601  }
602 }
603 
604 void TrackletConfigBuilder::writeCMMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) {
605  if (combinedmodules_)
606  return;
607 
608  for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) {
609  for (unsigned int iME = 0; iME < NVMME_[ilayer] * NRegions_[ilayer]; iME++) {
610  memories << "CandidateMatch: CM_" << LayerName(ilayer) << "PHI" << iTCStr(iME / NVMME_[ilayer]) << iME + 1
611  << " [12]" << std::endl;
612  modules << "MatchEngine: ME_" << LayerName(ilayer) << "PHI" << iTCStr(iME / NVMME_[ilayer]) << iME + 1
613  << std::endl;
614 
615  os << "CM_" << LayerName(ilayer) << "PHI" << iTCStr(iME / NVMME_[ilayer]) << iME + 1 << " input=> ME_"
616  << LayerName(ilayer) << "PHI" << iTCStr(iME / NVMME_[ilayer]) << iME + 1 << ".matchout output=> MC_"
617  << LayerName(ilayer) << "PHI" << iTCStr(iME / NVMME_[ilayer]) << ".matchin" << std::endl;
618  }
619  }
620 }
621 
622 void TrackletConfigBuilder::writeVMPROJMemories(std::ostream& os, std::ostream& memories, std::ostream&) {
623  if (combinedmodules_)
624  return;
625 
626  for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) {
627  for (unsigned int iME = 0; iME < NVMME_[ilayer] * NRegions_[ilayer]; iME++) {
628  memories << "VMProjections: VMPROJ_" << LayerName(ilayer) << "PHI" << iTCStr(iME / NVMME_[ilayer]) << iME + 1
629  << " [13]" << std::endl;
630 
631  os << "VMPROJ_" << LayerName(ilayer) << "PHI" << iTCStr(iME / NVMME_[ilayer]) << iME + 1 << " input=> PR_"
632  << LayerName(ilayer) << "PHI" << iTCStr(iME / NVMME_[ilayer]) << ".vmprojout"
633  << "PHI" << iTCStr(iME / NVMME_[ilayer]) << iME + 1 << " output=> ME_" << LayerName(ilayer) << "PHI"
634  << iTCStr(iME / NVMME_[ilayer]) << iME + 1 << ".vmprojin" << std::endl;
635  }
636  }
637 }
638 
639 void TrackletConfigBuilder::writeFMMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) {
640  if (combinedmodules_) {
641  for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) {
642  for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) {
643  modules << "MatchProcessor: MP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl;
644  for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) {
645  if (matchport_[iSeed][ilayer] == -1)
646  continue;
647  memories << "FullMatch: FM_" << iSeedStr(iSeed) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg)
648  << " [36]" << std::endl;
649  os << "FM_" << iSeedStr(iSeed) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << " input=> MP_"
650  << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".matchout1 output=> FT_" << iSeedStr(iSeed)
651  << ".fullmatch" << matchport_[iSeed][ilayer] << "in" << iReg + 1 << std::endl;
652  }
653  }
654  }
655  } else {
656  for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) {
657  for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) {
658  modules << "MatchCalculator: MC_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl;
659  for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) {
660  if (matchport_[iSeed][ilayer] == -1)
661  continue;
662  memories << "FullMatch: FM_" << iSeedStr(iSeed) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg)
663  << " [36]" << std::endl;
664  os << "FM_" << iSeedStr(iSeed) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << " input=> MC_"
665  << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".matchout1 output=> FT_" << iSeedStr(iSeed)
666  << ".fullmatch" << matchport_[iSeed][ilayer] << "in" << iReg + 1 << std::endl;
667  }
668  }
669  }
670  }
671 }
672 
673 void TrackletConfigBuilder::writeASMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) {
674  if (combinedmodules_) {
675  //First write AS memories used by MatchProcessor
676  for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) {
677  for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) {
678  memories << "AllStubs: AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1"
679  << " [42]" << std::endl;
680  if (combinedmodules_) {
681  modules << "VMRouterCM: VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl;
682  } else {
683  modules << "VMRouter: VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl;
684  }
685  os << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1"
686  << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubout output=> MP_"
687  << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubin" << std::endl;
688  }
689  }
690 
691  //Next write AS memories used by TrackletProcessor
692  for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) {
693  for (int iReg = 0; iReg < (int)NRegions_[ilayer]; iReg++) {
694  unsigned int nmem = 1;
695 
696  for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) {
697  unsigned int l1 = seedLayers(iSeed).first;
698  unsigned int l2 = seedLayers(iSeed).second;
699 
700  if (ilayer != l1 && ilayer != l2)
701  continue;
702 
703  bool inner = ilayer == l1;
704 
705  for (unsigned int iTC = 0; iTC < TC_[iSeed].size(); iTC++) {
706  int nTCReg = TC_[iSeed].size() / NRegions_[l2];
707 
708  int iTCReg = iTC / nTCReg;
709 
710  int jTCReg = iTC % nTCReg;
711 
712  if (ilayer == l2) {
713  if (iTCReg != iReg)
714  continue;
715  }
716 
717  string ext = "";
718 
719  if (ilayer == l1) {
720  int ratio = NRegions_[l1] / NRegions_[l2];
721  int min = iTCReg * ratio - 1 + jTCReg;
722  int max = (iTCReg + 1) * ratio - (nTCReg - jTCReg - 1);
723  if ((int)iReg < min || (int)iReg > max)
724  continue;
725 
726  if (max - min >= 2) {
727  ext = "M";
728  if (iReg == min)
729  ext = "R";
730  if (iReg == max)
731  ext = "L";
732  }
733 
734  if (max - min == 1) {
735  if (nTCReg == 2) {
736  assert(0);
737  if (jTCReg == 0) {
738  if (iReg == min)
739  ext = "R";
740  if (iReg == max)
741  ext = "B";
742  }
743  if (jTCReg == 1) {
744  if (iReg == min)
745  ext = "A";
746  if (iReg == max)
747  ext = "L";
748  }
749  }
750  if (nTCReg == 3) {
751  if (jTCReg == 0) {
752  if (iReg == min)
753  ext = "A";
754  if (iReg == max)
755  ext = "F";
756  }
757  if (jTCReg == 1) {
758  if (iReg == min)
759  ext = "E";
760  if (iReg == max)
761  ext = "D";
762  }
763  if (jTCReg == 2) {
764  if (iReg == min)
765  ext = "C";
766  if (iReg == max)
767  ext = "B";
768  }
769  }
770  }
771  assert(!ext.empty());
772  }
773 
774  if (ext.empty()) {
775  ext = "_" + LayerName(l1) + iTCStr(iTC);
776  }
777 
778  if (iSeed < 4) { //Barrel seeding
779  ext = "_B" + ext;
780  } else if (iSeed > 5) {
781  ext = "_O" + ext;
782  } else {
783  ext = "_D" + ext;
784  }
785 
786  nmem++;
787  if (inner) {
788  memories << "AllInnerStubs: ";
789  } else {
790  memories << "AllStubs: ";
791  }
792  memories << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ext << " [42]" << std::endl;
793  os << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ext << " input=> VMR_" << LayerName(ilayer)
794  << "PHI" << iTCStr(iReg) << ".all" << (inner ? "inner" : "") << "stubout output=> TP_" << iSeedStr(iSeed)
795  << iTCStr(iTC);
796  if (inner) {
797  os << ".innerallstubin" << std::endl;
798  } else {
799  os << ".outerallstubin" << std::endl;
800  }
801  }
802  }
803  }
804  }
805  } else {
806  //First write AS memories used by MatchCalculator
807  for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) {
808  for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) {
809  memories << "AllStubs: AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1"
810  << " [42]" << std::endl;
811  if (combinedmodules_) {
812  modules << "VMRouterCM: VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl;
813  } else {
814  modules << "VMRouter: VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl;
815  }
816  os << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1"
817  << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubout output=> MC_"
818  << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubin" << std::endl;
819  }
820  }
821 
822  //Next write AS memories used by TrackletCalculator
823  for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) {
824  for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) {
825  unsigned int nmem = 1;
826 
827  for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) {
828  unsigned int l1 = seedLayers(iSeed).first;
829  unsigned int l2 = seedLayers(iSeed).second;
830 
831  if (ilayer != l1 && ilayer != l2)
832  continue;
833 
834  for (unsigned int iTC = 0; iTC < TC_[iSeed].size(); iTC++) {
835  bool used = false;
836  for (unsigned int iTE = 0; iTE < TC_[iSeed][iTC].size(); iTE++) {
837  unsigned int theTE = TC_[iSeed][iTC][iTE];
838 
839  unsigned int TE1 = TE_[iSeed][theTE].first;
840  unsigned int TE2 = TE_[iSeed][theTE].second;
841 
842  if (l1 == ilayer && iReg == TE1 / NVMTE_[iSeed].first)
843  used = true;
844  if (l2 == ilayer && iReg == TE2 / NVMTE_[iSeed].second)
845  used = true;
846  }
847 
848  if (used) {
849  nmem++;
850  memories << "AllStubs: AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n" << nmem << " [42]"
851  << std::endl;
852  os << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n" << nmem << " input=> VMR_"
853  << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubout output=> TC_" << iSeedStr(iSeed)
854  << iTCStr(iTC);
855  if (ilayer == l1) {
856  os << ".innerallstubin" << std::endl;
857  } else {
858  os << ".outerallstubin" << std::endl;
859  }
860  }
861  }
862  }
863  }
864  }
865  }
866 }
867 
868 void TrackletConfigBuilder::writeVMSMemories(std::ostream& os, std::ostream& memories, std::ostream&) {
869  if (combinedmodules_) {
870  //First write VMS memories used by MatchProcessor
871  for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) {
872  for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) {
873  memories << "VMStubsME: VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1 [18]" << std::endl;
874  os << "VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1"
875  << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstuboutPHI" << iTCStr(iReg)
876  << " output=> MP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstubin" << std::endl;
877  }
878  }
879 
880  //Next write VMS memories used by TrackletProcessor
881  for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) {
882  //FIXME - code could be cleaner
883  unsigned int l1 = seedLayers(iSeed).first;
884  unsigned int l2 = seedLayers(iSeed).second;
885 
886  unsigned int ilayer = seedLayers(iSeed).second;
887 
888  //for(unsigned int iReg=0;iReg<NRegions_[ilayer];iReg++){
889 
890  unsigned int nTCReg = TC_[iSeed].size() / NRegions_[l2];
891 
892  for (unsigned int iReg = 0; iReg < NRegions_[l2]; iReg++) {
893  unsigned int nmem = 0;
894  //Hack since we use same module twice
895  if (iSeed == Seed::L2D1) {
896  nmem = 2;
897  }
898 
899  for (unsigned iTC = 0; iTC < nTCReg; iTC++) {
900  nmem++;
901  memories << "VMStubsTE: VMSTE_" << LayerName(ilayer) << "PHI" << iRegStr(iReg, iSeed) << "n" << nmem
902  << " [18]" << std::endl;
903  os << "VMSTE_" << LayerName(ilayer) << "PHI" << iRegStr(iReg, iSeed) << "n" << nmem << " input=> VMR_"
904  << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstubout_seed_" << iSeed << " output=> TP_"
905  << LayerName(l1) << LayerName(l2) << iTCStr(iReg * nTCReg + iTC) << ".outervmstubin" << std::endl;
906  }
907  }
908  }
909  } else {
910  //First write VMS memories used by MatchEngine
911  for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) {
912  for (unsigned int iVMME = 0; iVMME < NVMME_[ilayer] * NRegions_[ilayer]; iVMME++) {
913  unsigned int iReg = iVMME / NVMME_[ilayer];
914  memories << "VMStubsME: VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << iVMME + 1 << "n1 [18]"
915  << std::endl;
916  os << "VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << iVMME + 1 << "n1"
917  << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstuboutMEPHI" << iTCStr(iReg)
918  << iVMME + 1 << " output=> ME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << iVMME + 1 << ".vmstubin"
919  << std::endl;
920  }
921  }
922 
923  //Next write VMS memories used by TrackletEngine
924  for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) {
925  for (unsigned int innerouterseed = 0; innerouterseed < 2; innerouterseed++) {
926  //FIXME - code could be cleaner
927  unsigned int l1 = seedLayers(iSeed).first;
928  unsigned int l2 = seedLayers(iSeed).second;
929 
930  unsigned int NVMTE1 = NVMTE_[iSeed].first;
931  unsigned int NVMTE2 = NVMTE_[iSeed].second;
932 
933  unsigned int ilayer = seedLayers(iSeed).first;
934  unsigned int NVMTE = NVMTE_[iSeed].first;
935  if (innerouterseed == 1) {
936  ilayer = seedLayers(iSeed).second;
937  NVMTE = NVMTE_[iSeed].second;
938  }
939 
940  for (unsigned int iVMTE = 0; iVMTE < NVMTE * NRegions_[ilayer]; iVMTE++) {
941  unsigned int iReg = iVMTE / NVMTE;
942 
943  unsigned int nmem = 0;
944 
945  if (iSeed == Seed::L2D1) {
946  nmem = 4;
947  }
948 
949  for (unsigned int iTE = 0; iTE < TE_[iSeed].size(); iTE++) {
950  unsigned int TE1 = TE_[iSeed][iTE].first;
951  unsigned int TE2 = TE_[iSeed][iTE].second;
952 
953  bool used = false;
954 
955  if (innerouterseed == 0 && iVMTE == TE1)
956  used = true;
957  if (innerouterseed == 1 && iVMTE == TE2)
958  used = true;
959 
960  if (!used)
961  continue;
962 
963  string inorout = "I";
964  if (innerouterseed == 1)
965  inorout = "O";
966 
967  nmem++;
968  memories << "VMStubsTE: VMSTE_" << LayerName(ilayer) << "PHI" << iRegStr(iReg, iSeed) << iVMTE + 1 << "n"
969  << nmem << " [18]" << std::endl;
970  os << "VMSTE_" << LayerName(ilayer) << "PHI" << iRegStr(iReg, iSeed) << iVMTE + 1 << "n" << nmem
971  << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstuboutTE" << inorout << "PHI"
972  << iRegStr(iReg, iSeed) << iVMTE + 1 << " output=> TE_" << LayerName(l1) << "PHI"
973  << iRegStr(TE1 / NVMTE1, iSeed) << TE1 + 1 << "_" << LayerName(l2) << "PHI"
974  << iRegStr(TE2 / NVMTE2, iSeed) << TE2 + 1;
975  if (innerouterseed == 0) {
976  os << ".innervmstubin" << std::endl;
977  } else {
978  os << ".outervmstubin" << std::endl;
979  }
980  }
981  }
982  }
983  }
984  }
985 }
986 
987 void TrackletConfigBuilder::writeTPARMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) {
988  if (combinedmodules_) {
989  for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) {
990  for (unsigned int iTP = 0; iTP < TC_[iSeed].size(); iTP++) {
991  memories << "TrackletParameters: TPAR_" << iSeedStr(iSeed) << iTCStr(iTP) << " [56]" << std::endl;
992  modules << "TrackletProcessor: TP_" << iSeedStr(iSeed) << iTCStr(iTP) << std::endl;
993  os << "TPAR_" << iSeedStr(iSeed) << iTCStr(iTP) << " input=> TP_" << iSeedStr(iSeed) << iTCStr(iTP)
994  << ".trackpar output=> FT_" << iSeedStr(iSeed) << ".tparin" << std::endl;
995  }
996  }
997  } else {
998  for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) {
999  for (unsigned int iTC = 0; iTC < TC_[iSeed].size(); iTC++) {
1000  memories << "TrackletParameters: TPAR_" << iSeedStr(iSeed) << iTCStr(iTC) << " [56]" << std::endl;
1001  modules << "TrackletCalculator: TC_" << iSeedStr(iSeed) << iTCStr(iTC) << std::endl;
1002  os << "TPAR_" << iSeedStr(iSeed) << iTCStr(iTC) << " input=> TC_" << iSeedStr(iSeed) << iTCStr(iTC)
1003  << ".trackpar output=> FT_" << iSeedStr(iSeed) << ".tparin" << std::endl;
1004  }
1005  }
1006  }
1007 }
1008 
1009 void TrackletConfigBuilder::writeTFMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) {
1010  for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) {
1011  memories << "TrackFit: TF_" << iSeedStr(iSeed) << " [126]" << std::endl;
1012  modules << "FitTrack: FT_" << iSeedStr(iSeed) << std::endl;
1013  os << "TF_" << iSeedStr(iSeed) << " input=> FT_" << iSeedStr(iSeed) << ".trackout output=> PD.trackin" << std::endl;
1014  }
1015 }
1016 
1017 void TrackletConfigBuilder::writeCTMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) {
1018  modules << "PurgeDuplicate: PD" << std::endl;
1019 
1020  for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) {
1021  memories << "CleanTrack: CT_" << iSeedStr(iSeed) << " [126]" << std::endl;
1022  os << "CT_" << iSeedStr(iSeed) << " input=> PD.trackout output=>" << std::endl;
1023  }
1024 }
1025 
1026 void TrackletConfigBuilder::writeILMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) {
1027  //FIXME these should not be hardcoded - but for now wanted to avoid reading file
1028  string dtcname[52];
1029  unsigned int layerdisk[52];
1030  double phimin[52];
1031  double phimax[52];
1032 
1033  dtcname[0] = "PS10G_1";
1034  layerdisk[0] = 0;
1035  phimin[0] = 0.304273;
1036  phimax[0] = 0.742925;
1037  dtcname[1] = "PS10G_1";
1038  layerdisk[1] = 6;
1039  phimin[1] = -0.185672;
1040  phimax[1] = 0.883803;
1041  dtcname[2] = "PS10G_1";
1042  layerdisk[2] = 8;
1043  phimin[2] = -0.132414;
1044  phimax[2] = 0.830545;
1045  dtcname[3] = "PS10G_1";
1046  layerdisk[3] = 10;
1047  phimin[3] = -0.132414;
1048  phimax[3] = 0.830545;
1049  dtcname[4] = "PS10G_2";
1050  layerdisk[4] = 0;
1051  phimin[4] = -0.0133719;
1052  phimax[4] = 0.715599;
1053  dtcname[5] = "PS10G_2";
1054  layerdisk[5] = 7;
1055  phimin[5] = -0.110089;
1056  phimax[5] = 0.808221;
1057  dtcname[6] = "PS10G_2";
1058  layerdisk[6] = 9;
1059  phimin[6] = -0.132414;
1060  phimax[6] = 0.830545;
1061  dtcname[7] = "PS10G_3";
1062  layerdisk[7] = 1;
1063  phimin[7] = -0.11381;
1064  phimax[7] = 0.822812;
1065  dtcname[8] = "PS10G_3";
1066  layerdisk[8] = 7;
1067  phimin[8] = -0.185672;
1068  phimax[8] = 0.883803;
1069  dtcname[9] = "PS10G_4";
1070  layerdisk[9] = 6;
1071  phimin[9] = -0.0823971;
1072  phimax[9] = 0.780529;
1073  dtcname[10] = "PS10G_4";
1074  layerdisk[10] = 8;
1075  phimin[10] = -0.0963091;
1076  phimax[10] = 0.794441;
1077  dtcname[11] = "PS10G_4";
1078  layerdisk[11] = 10;
1079  phimin[11] = -0.0963091;
1080  phimax[11] = 0.794441;
1081  dtcname[12] = "PS_1";
1082  layerdisk[12] = 2;
1083  phimin[12] = 0.0827748;
1084  phimax[12] = 0.615357;
1085  dtcname[13] = "PS_1";
1086  layerdisk[13] = 7;
1087  phimin[13] = -0.0823971;
1088  phimax[13] = 0.780529;
1089  dtcname[14] = "PS_2";
1090  layerdisk[14] = 2;
1091  phimin[14] = -0.0917521;
1092  phimax[14] = 0.614191;
1093  dtcname[15] = "PS_2";
1094  layerdisk[15] = 9;
1095  phimin[15] = -0.0963091;
1096  phimax[15] = 0.794441;
1097  dtcname[16] = "2S_1";
1098  layerdisk[16] = 3;
1099  phimin[16] = -0.0246209;
1100  phimax[16] = 0.763311;
1101  dtcname[17] = "2S_1";
1102  layerdisk[17] = 4;
1103  phimin[17] = 0.261875;
1104  phimax[17] = 0.403311;
1105  dtcname[18] = "2S_2";
1106  layerdisk[18] = 4;
1107  phimin[18] = -0.0542445;
1108  phimax[18] = 0.715509;
1109  dtcname[19] = "2S_3";
1110  layerdisk[19] = 5;
1111  phimin[19] = 0.0410126;
1112  phimax[19] = 0.730605;
1113  dtcname[20] = "2S_4";
1114  layerdisk[20] = 5;
1115  phimin[20] = -0.0428961;
1116  phimax[20] = 0.693862;
1117  dtcname[21] = "2S_4";
1118  layerdisk[21] = 8;
1119  phimin[21] = -0.0676705;
1120  phimax[21] = 0.765802;
1121  dtcname[22] = "2S_5";
1122  layerdisk[22] = 6;
1123  phimin[22] = -0.0648206;
1124  phimax[22] = 0.762952;
1125  dtcname[23] = "2S_5";
1126  layerdisk[23] = 9;
1127  phimin[23] = -0.0676705;
1128  phimax[23] = 0.765802;
1129  dtcname[24] = "2S_6";
1130  layerdisk[24] = 7;
1131  phimin[24] = -0.0648206;
1132  phimax[24] = 0.762952;
1133  dtcname[25] = "2S_6";
1134  layerdisk[25] = 10;
1135  phimin[25] = -0.0676705;
1136  phimax[25] = 0.765802;
1137  dtcname[26] = "negPS10G_1";
1138  layerdisk[26] = 0;
1139  phimin[26] = -0.023281;
1140  phimax[26] = 0.372347;
1141  dtcname[27] = "negPS10G_1";
1142  layerdisk[27] = 6;
1143  phimin[27] = -0.185672;
1144  phimax[27] = 0.883803;
1145  dtcname[28] = "negPS10G_1";
1146  layerdisk[28] = 8;
1147  phimin[28] = -0.132414;
1148  phimax[28] = 0.830545;
1149  dtcname[29] = "negPS10G_1";
1150  layerdisk[29] = 10;
1151  phimin[29] = -0.132414;
1152  phimax[29] = 0.830545;
1153  dtcname[30] = "negPS10G_2";
1154  layerdisk[30] = 0;
1155  phimin[30] = -0.0133719;
1156  phimax[30] = 0.715599;
1157  dtcname[31] = "negPS10G_2";
1158  layerdisk[31] = 7;
1159  phimin[31] = -0.110089;
1160  phimax[31] = 0.808221;
1161  dtcname[32] = "negPS10G_2";
1162  layerdisk[32] = 9;
1163  phimin[32] = -0.132414;
1164  phimax[32] = 0.830545;
1165  dtcname[33] = "negPS10G_3";
1166  layerdisk[33] = 1;
1167  phimin[33] = -0.115834;
1168  phimax[33] = 0.813823;
1169  dtcname[34] = "negPS10G_3";
1170  layerdisk[34] = 7;
1171  phimin[34] = -0.185672;
1172  phimax[34] = 0.883803;
1173  dtcname[35] = "negPS10G_4";
1174  layerdisk[35] = 6;
1175  phimin[35] = -0.0823971;
1176  phimax[35] = 0.780529;
1177  dtcname[36] = "negPS10G_4";
1178  layerdisk[36] = 8;
1179  phimin[36] = -0.0963091;
1180  phimax[36] = 0.794441;
1181  dtcname[37] = "negPS10G_4";
1182  layerdisk[37] = 10;
1183  phimin[37] = -0.0963091;
1184  phimax[37] = 0.794441;
1185  dtcname[38] = "negPS_1";
1186  layerdisk[38] = 2;
1187  phimin[38] = -0.0961318;
1188  phimax[38] = 0.445198;
1189  dtcname[39] = "negPS_1";
1190  layerdisk[39] = 7;
1191  phimin[39] = -0.0823971;
1192  phimax[39] = 0.780529;
1193  dtcname[40] = "negPS_2";
1194  layerdisk[40] = 2;
1195  phimin[40] = -0.0917521;
1196  phimax[40] = 0.614191;
1197  dtcname[41] = "negPS_2";
1198  layerdisk[41] = 9;
1199  phimin[41] = -0.0963091;
1200  phimax[41] = 0.794441;
1201  dtcname[42] = "neg2S_1";
1202  layerdisk[42] = 3;
1203  phimin[42] = -0.0246209;
1204  phimax[42] = 0.763311;
1205  dtcname[43] = "neg2S_1";
1206  layerdisk[43] = 4;
1207  phimin[43] = 0.261875;
1208  phimax[43] = 0.403311;
1209  dtcname[44] = "neg2S_2";
1210  layerdisk[44] = 4;
1211  phimin[44] = -0.0542445;
1212  phimax[44] = 0.715509;
1213  dtcname[45] = "neg2S_3";
1214  layerdisk[45] = 5;
1215  phimin[45] = 0.0410126;
1216  phimax[45] = 0.730605;
1217  dtcname[46] = "neg2S_4";
1218  layerdisk[46] = 5;
1219  phimin[46] = -0.0428961;
1220  phimax[46] = 0.693862;
1221  dtcname[47] = "neg2S_4";
1222  layerdisk[47] = 8;
1223  phimin[47] = -0.06767;
1224  phimax[47] = 0.765802;
1225  dtcname[48] = "neg2S_5";
1226  layerdisk[48] = 6;
1227  phimin[48] = -0.0648201;
1228  phimax[48] = 0.762952;
1229  dtcname[49] = "neg2S_5";
1230  layerdisk[49] = 9;
1231  phimin[49] = -0.06767;
1232  phimax[49] = 0.765802;
1233  dtcname[50] = "neg2S_6";
1234  layerdisk[50] = 7;
1235  phimin[50] = -0.0648201;
1236  phimax[50] = 0.762952;
1237  dtcname[51] = "neg2S_6";
1238  layerdisk[51] = 10;
1239  phimin[51] = -0.06767;
1240  phimax[51] = 0.765802;
1241 
1242  double dphi = 0.5 * dphisectorHG_ - M_PI / NSector_;
1243 
1244  string olddtc = "";
1245  for (unsigned int i = 0; i < 52; i++) {
1246  if (olddtc != dtcname[i]) {
1247  modules << "InputRouter: IR_" << dtcname[i] << "_A" << std::endl;
1248  modules << "InputRouter: IR_" << dtcname[i] << "_B" << std::endl;
1249  memories << "DTCLink: DL_" << dtcname[i] << "_A [36]" << std::endl;
1250  memories << "DTCLink: DL_" << dtcname[i] << "_B [36]" << std::endl;
1251  os << "DL_" << dtcname[i] << "_A"
1252  << " input=> output=> IR_" << dtcname[i] << "_A.stubin" << std::endl;
1253  os << "DL_" << dtcname[i] << "_B"
1254  << " input=> output=> IR_" << dtcname[i] << "_B.stubin" << std::endl;
1255  }
1256  olddtc = dtcname[i];
1257  }
1258 
1259  for (unsigned int i = 0; i < 52; i++) {
1260  double phimintmp = phimin[i] + dphi;
1261  double phimaxtmp = phimax[i] + dphi;
1262 
1263  for (unsigned int iReg = 0; iReg < NRegions_[layerdisk[i]]; iReg++) {
1264  if (allStubs_[layerdisk[i]][iReg].first > phimaxtmp && allStubs_[layerdisk[i]][iReg].second < phimintmp)
1265  continue;
1266 
1267  if (allStubs_[layerdisk[i]][iReg].second < phimaxtmp) {
1268  memories << "InputLink: IL_" << LayerName(layerdisk[i]) << "PHI" << iTCStr(iReg) << "_" << dtcname[i] << "_A"
1269  << " [36]" << std::endl;
1270  os << "IL_" << LayerName(layerdisk[i]) << "PHI" << iTCStr(iReg) << "_" << dtcname[i] << "_A"
1271  << " input=> IR_" << dtcname[i] << "_A.stubout output=> VMR_" << LayerName(layerdisk[i]) << "PHI"
1272  << iTCStr(iReg) << ".stubin" << std::endl;
1273  }
1274 
1275  if (allStubs_[layerdisk[i]][iReg].first > phimintmp) {
1276  memories << "InputLink: IL_" << LayerName(layerdisk[i]) << "PHI" << iTCStr(iReg) << "_" << dtcname[i] << "_B"
1277  << " [36]" << std::endl;
1278  os << "IL_" << LayerName(layerdisk[i]) << "PHI" << iTCStr(iReg) << "_" << dtcname[i] << "_B"
1279  << " input=> IR_" << dtcname[i] << "_B.stubout output=> VMR_" << LayerName(layerdisk[i]) << "PHI"
1280  << iTCStr(iReg) << ".stubin" << std::endl;
1281  }
1282  }
1283  }
1284 }
1285 
1286 void TrackletConfigBuilder::writeAll(std::ostream& wires, std::ostream& memories, std::ostream& modules) {
1287  writeILMemories(wires, memories, modules);
1288  writeASMemories(wires, memories, modules);
1289  writeVMSMemories(wires, memories, modules);
1290  writeSPMemories(wires, memories, modules);
1291  writeSPDMemories(wires, memories, modules);
1292  writeProjectionMemories(wires, memories, modules);
1293  writeTPARMemories(wires, memories, modules);
1294  writeVMPROJMemories(wires, memories, modules);
1295  writeAPMemories(wires, memories, modules);
1296  writeCMMemories(wires, memories, modules);
1297  writeFMMemories(wires, memories, modules);
1298  writeTFMemories(wires, memories, modules);
1299  writeCTMemories(wires, memories, modules);
1300 }
double dphisectorHG() const
Definition: Settings.h:281
void writeProjectionMemories(std::ostream &os, std::ostream &memories, std::ostream &modules)
std::vector< std::vector< std::pair< unsigned int, unsigned int > > > projections_[N_LAYER+N_DISK]
constexpr int N_DISK
Definition: Settings.h:22
std::string SPName(unsigned int l1, unsigned int ireg1, unsigned int ivm1, unsigned int l2, unsigned int ireg2, unsigned int ivm2, unsigned int iseed)
unsigned int projlayers(unsigned int iSeed, unsigned int i) const
Definition: Settings.h:155
std::string iTCStr(unsigned int iTC)
static std::string numStr(unsigned int i)
std::string TParName(unsigned int l1, unsigned int l2, unsigned int l3, unsigned int itc)
constexpr unsigned int N_SEED
Definition: Settings.h:24
double rinvmax() const
Definition: Settings.h:214
std::string TEDName(unsigned int l1, unsigned int ireg1, unsigned int ivm1, unsigned int l2, unsigned int ireg2, unsigned int ivm2, unsigned int iseed)
void writeAll(std::ostream &wires, std::ostream &memories, std::ostream &modules)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
unsigned int nvmme(unsigned int layerdisk) const
Definition: Settings.h:104
double rmaxdisk() const
Definition: Settings.h:125
double zlength() const
Definition: Settings.h:124
static std::string LayerName(unsigned int ilayer)
void writeASMemories(std::ostream &os, std::ostream &memories, std::ostream &modules)
double rcrit() const
Definition: Settings.h:288
std::string TEName(unsigned int l1, unsigned int ireg1, unsigned int ivm1, unsigned int l2, unsigned int ireg2, unsigned int ivm2, unsigned int iseed)
unsigned int projdisks(unsigned int iSeed, unsigned int i) const
Definition: Settings.h:156
void writeILMemories(std::ostream &os, std::ostream &memories, std::ostream &modules)
void writeFMMemories(std::ostream &os, std::ostream &memories, std::ostream &modules)
std::vector< std::pair< double, double > > VMStubsME_[N_LAYER+N_DISK]
std::vector< std::pair< unsigned int, unsigned int > > TE_[N_SEED_PROMPT]
std::string TPROJName(unsigned int iSeed, unsigned int iTC, unsigned int ilayer, unsigned int ireg)
assert(be >=bs)
std::string STName(unsigned int l1, unsigned int ireg1, unsigned int l2, unsigned int ireg2, unsigned int l3, unsigned int ireg3, unsigned int iseed, unsigned int count)
std::string TCName(unsigned int iSeed, unsigned int iTC)
std::string TREName(unsigned int l1, unsigned int ireg1, unsigned int l2, unsigned int ireg2, unsigned int iseed, unsigned int count)
double rmean(unsigned int iLayer) const
Definition: Settings.h:164
U second(std::pair< T, U > const &p)
double zmean(unsigned int iDisk) const
Definition: Settings.h:167
unsigned int NTC_[N_SEED_PROMPT]
void writeTPARMemories(std::ostream &os, std::ostream &memories, std::ostream &modules)
std::string PRName(unsigned int ilayer, unsigned int ireg)
T sqrt(T t)
Definition: SSEVec.h:19
unsigned int nvmte(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:101
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
std::vector< std::vector< unsigned int > > TC_[N_SEED_PROMPT]
unsigned int nallstubs(unsigned int layerdisk) const
Definition: Settings.h:107
T min(T a, T b)
Definition: MathUtil.h:58
void writeSPMemories(std::ostream &os, std::ostream &memories, std::ostream &modules)
std::pair< std::vector< std::pair< double, double > >, std::vector< std::pair< double, double > > > VMStubsTE_[N_SEED_PROMPT]
#define M_PI
constexpr unsigned int N_SECTOR
Definition: Settings.h:19
unsigned int NVMME_[N_LAYER+N_DISK]
double rinv(double r1, double phi1, double r2, double phi2)
int iseed
Definition: AMPTWrapper.h:134
std::pair< double, double > seedRadii(unsigned int iseed)
void writeCMMemories(std::ostream &os, std::ostream &memories, std::ostream &modules)
unsigned int seedlayers(int inner, int seed) const
Definition: Settings.h:145
bool extended() const
Definition: Settings.h:248
unsigned int NRegions_[N_LAYER+N_DISK]
bool validTEPair(unsigned int iseed, unsigned int iTE1, unsigned int iTE2)
void writeVMPROJMemories(std::ostream &os, std::ostream &memories, std::ostream &modules)
std::string SPDName(unsigned int l1, unsigned int ireg1, unsigned int ivm1, unsigned int l2, unsigned int ireg2, unsigned int ivm2, unsigned int l3, unsigned int ireg3, unsigned int ivm3, unsigned int iseed)
void writeTFMemories(std::ostream &os, std::ostream &memories, std::ostream &modules)
std::string TCDName(unsigned int l1, unsigned int l2, unsigned int l3, unsigned int itc)
std::string iRegStr(unsigned int iReg, unsigned int iSeed)
std::string FTName(unsigned int l1, unsigned int l2, unsigned int l3)
std::vector< std::pair< double, double > > allStubs_[N_LAYER+N_DISK]
void writeCTMemories(std::ostream &os, std::ostream &memories, std::ostream &modules)
std::pair< unsigned int, unsigned int > seedLayers(unsigned int iSeed)
int matchport_[N_SEED_PROMPT][N_LAYER+N_DISK]
std::string TCNAme(unsigned int iseed, unsigned int iTC)
tuple wires
Definition: DigiDM_cff.py:33
std::pair< double, double > seedPhiRange(double rproj, unsigned int iSeed, unsigned int iTC)
std::string iSeedStr(unsigned int iSeed)
tmp
align.sh
Definition: createJobs.py:716
void writeAPMemories(std::ostream &os, std::ostream &memories, std::ostream &modules)
void writeSPDMemories(std::ostream &os, std::ostream &memories, std::ostream &modules)
void writeVMSMemories(std::ostream &os, std::ostream &memories, std::ostream &modules)
bool combined() const
Definition: Settings.h:250
double phi(double r1, double phi1, double r2, double phi2, double r)
constexpr unsigned int N_SEED_PROMPT
Definition: Settings.h:25
std::pair< unsigned int, unsigned int > NVMTE_[N_SEED_PROMPT]
constexpr int N_LAYER
Definition: Settings.h:21
unsigned int NTC(int seed) const
Definition: Settings.h:153