CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ProjectionRouter.cc
Go to the documentation of this file.
7 
10 
11 using namespace std;
12 using namespace trklet;
13 
14 ProjectionRouter::ProjectionRouter(string name, Settings const& settings, Globals* global)
15  : ProcessBase(name, settings, global), rinvbendlut_(settings) {
17 
18  vmprojs_.resize(settings_.nvmme(layerdisk_), nullptr);
19 
20  nrbits_ = 5;
21  nphiderbits_ = 6;
22 
23  if (layerdisk_ >= N_LAYER) {
26  }
27 }
28 
30  if (settings_.writetrace()) {
31  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output "
32  << output;
33  }
34  if (output == "allprojout") {
35  auto* tmp = dynamic_cast<AllProjectionsMemory*>(memory);
36  assert(tmp != nullptr);
37  allproj_ = tmp;
38  return;
39  }
40 
41  unsigned int nproj = settings_.nallstubs(layerdisk_);
42  unsigned int nprojvm = settings_.nvmme(layerdisk_);
43 
44  for (unsigned int iproj = 0; iproj < nproj; iproj++) {
45  for (unsigned int iprojvm = 0; iprojvm < nprojvm; iprojvm++) {
46  std::string name = "vmprojoutPHI";
47  name += char(iproj + 'A');
48  name += std::to_string(iproj * nprojvm + iprojvm + 1);
49  if (output == name) {
50  auto* tmp = dynamic_cast<VMProjectionsMemory*>(memory);
51  assert(tmp != nullptr);
52  vmprojs_[iprojvm] = tmp;
53  return;
54  }
55  }
56  }
57 
58  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find output: " << output;
59 }
60 
62  if (settings_.writetrace()) {
63  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input "
64  << input;
65  }
66  if (input.substr(0, 4) == "proj" && input.substr(input.size() - 2, 2) == "in") {
67  auto* tmp = dynamic_cast<TrackletProjectionsMemory*>(memory);
68  assert(tmp != nullptr);
69  inputproj_.push_back(tmp);
70  return;
71  }
72  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find input: " << input;
73 }
74 
76  unsigned int allprojcount = 0;
77 
78  //These are just here to test that the order is correct. Does not affect the actual execution
79 
80  int lastTCID = -1;
81 
82  for (auto& iproj : inputproj_) {
83  for (unsigned int i = 0; i < iproj->nTracklets(); i++) {
84  if (allprojcount >= settings_.maxStep("PR"))
85  continue;
86 
87  Tracklet* tracklet = iproj->getTracklet(i);
88 
89  FPGAWord fpgaphi;
90 
91  if (layerdisk_ < N_LAYER) {
92  fpgaphi = tracklet->proj(layerdisk_).fpgaphiproj();
93  } else {
94  Projection& proj = tracklet->proj(layerdisk_);
95  fpgaphi = proj.fpgaphiproj();
96 
97  //The next lines looks up the predicted bend based on:
98  // 1 - r projections
99  // 2 - phi derivative
100  // 3 - the sign - i.e. if track is forward or backward
101 
102  int rindex = (proj.fpgarzproj().value() >> (proj.fpgarzproj().nbits() - nrbits_)) & ((1 << nrbits_) - 1);
103 
104  int phiderindex = (proj.fpgaphiprojder().value() >> (proj.fpgaphiprojder().nbits() - nphiderbits_)) &
105  ((1 << nphiderbits_) - 1);
106 
107  int signindex = (proj.fpgarzprojder().value() < 0);
108 
109  int bendindex = (signindex << (nphiderbits_ + nrbits_)) + (rindex << (nphiderbits_)) + phiderindex;
110 
111  int ibendproj = rinvbendlut_.lookup(bendindex);
112 
113  proj.setBendIndex(ibendproj);
114  }
115 
116  unsigned int iphivm =
119 
120  //This block of code just checks that the configuration is consistent
121  if (lastTCID >= tracklet->TCID()) {
122  edm::LogPrint("Tracklet") << "Wrong TCID ordering for projections in " << getName();
123  } else {
124  lastTCID = tracklet->TCID();
125  }
126 
127  allproj_->addTracklet(tracklet);
128 
129  vmprojs_[iphivm]->addTracklet(tracklet, allprojcount);
130 
131  if (settings_.debugTracklet()) {
132  edm::LogVerbatim("Tracklet") << getName() << " projection to " << vmprojs_[iphivm]->getName() << " iphivm "
133  << iphivm;
134  }
135 
136  allprojcount++;
137  }
138  }
139 
140  if (settings_.writeMonitorData("AP")) {
141  globals_->ofstream("allprojections.txt") << getName() << " " << allproj_->nTracklets() << endl;
142  }
143 
144  if (settings_.writeMonitorData("VMP")) {
145  ofstream& out = globals_->ofstream("chisq.txt");
146  for (unsigned int i = 0; i < 8; i++) {
147  if (vmprojs_[i] != nullptr) {
148  out << vmprojs_[i]->getName() << " " << vmprojs_[i]->nTracklets() << endl;
149  }
150  }
151  }
152 }
Log< level::Info, true > LogVerbatim
std::string name_
Definition: ProcessBase.h:38
const FPGAWord & fpgaphiproj() const
Definition: Projection.h:39
const FPGAWord & fpgaphiprojder() const
Definition: Projection.h:49
int nbits() const
Definition: FPGAWord.h:25
void initProjectionBend(double k_phider, unsigned int idisk, unsigned int nrbits, unsigned int nphiderbits)
Definition: TrackletLUT.cc:393
unsigned int nvmme(unsigned int layerdisk) const
Definition: Settings.h:104
Projection & proj(int layerdisk)
Definition: Tracklet.h:87
Settings const & settings_
Definition: ProcessBase.h:40
void addOutput(MemoryBase *memory, std::string output) override
Globals * globals_
Definition: ProcessBase.h:41
std::vector< VMProjectionsMemory * > vmprojs_
double K() const
Definition: imath.h:246
assert(be >=bs)
bool debugTracklet() const
Definition: Settings.h:182
void addTracklet(Tracklet *tracklet)
static std::string const input
Definition: EdmProvDump.cc:47
AllProjectionsMemory * allproj_
std::string const & getName() const
Definition: ProcessBase.h:22
std::string const & getName() const
Definition: MemoryBase.h:19
const FPGAWord & fpgarzprojder() const
Definition: Projection.h:54
int value() const
Definition: FPGAWord.h:24
int TCID() const
Definition: Tracklet.h:212
unsigned int bits(unsigned int lsb, unsigned int nbit) const
Definition: FPGAWord.cc:74
IMATH_TrackletCalculator * ITC_L1L2()
Definition: Globals.h:48
unsigned int nallstubs(unsigned int layerdisk) const
Definition: Settings.h:107
unsigned int maxStep(std::string module) const
Definition: Settings.h:116
Log< level::Warning, true > LogPrint
void initLayerDisk(unsigned int pos, int &layer, int &disk)
Definition: ProcessBase.cc:33
unsigned int nTracklets() const
int lookup(unsigned int index) const
Definition: TrackletLUT.cc:900
unsigned int nbitsallstubs(unsigned int layerdisk) const
Definition: Settings.h:106
const FPGAWord & fpgarzproj() const
Definition: Projection.h:44
void addInput(MemoryBase *memory, std::string input) override
std::ofstream & ofstream(std::string fname)
Definition: Globals.cc:44
void setBendIndex(int bendindex)
Definition: Projection.h:119
unsigned int nbitsvmme(unsigned int layerdisk) const
Definition: Settings.h:103
std::vector< TrackletProjectionsMemory * > inputproj_
tmp
align.sh
Definition: createJobs.py:716
bool writeMonitorData(std::string module) const
Definition: Settings.h:109
bool writetrace() const
Definition: Settings.h:183
constexpr int N_LAYER
Definition: Settings.h:21