CMS 3D CMS Logo

TrackletProcessorDisplaced.cc
Go to the documentation of this file.
10 
14 
15 #include <utility>
16 #include <tuple>
17 
18 using namespace std;
19 using namespace trklet;
20 
21 // TrackletProcessorDisplaced
22 //
23 // This module takes in collections of stubs within a phi region and a
24 // displaced seed name and tries to create that displaced seed out of the stubs
25 //
26 // Update: Claire Savard, Oct. 2024
27 
28 TrackletProcessorDisplaced::TrackletProcessorDisplaced(string name, Settings const& settings, Globals* globals)
29  : TrackletCalculatorDisplaced(name, settings, globals), innerTable_(settings), innerThirdTable_(settings) {
30  innerallstubs_.clear();
31  middleallstubs_.clear();
32  outerallstubs_.clear();
33  innervmstubs_.clear();
34  outervmstubs_.clear();
35 
36  // set layer/disk types based on input seed name
38 
39  // get projection tables
40  unsigned int region = name.back() - 'A';
42  layerdisk1_, TrackletLUT::VMRTableType::inner, region, false); //projection to next layer/disk
44  layerdisk1_, TrackletLUT::VMRTableType::innerthird, region, false); //projection to third layer/disk
45 
48 
49  for (unsigned int ilayer = 0; ilayer < N_LAYER; ilayer++) {
50  vector<TrackletProjectionsMemory*> tmp(settings_.nallstubs(ilayer), nullptr);
51  trackletprojlayers_.push_back(tmp);
52  }
53 
54  for (unsigned int idisk = 0; idisk < N_DISK; idisk++) {
55  vector<TrackletProjectionsMemory*> tmp(settings_.nallstubs(idisk + N_LAYER), nullptr);
56  trackletprojdisks_.push_back(tmp);
57  }
58 
59  // set TC index
60  iTC_ = region;
61  constexpr int TCIndexMin = 128;
62  constexpr int TCIndexMax = 191;
63  TCIndex_ = (iSeed_ << 4) + iTC_;
64  assert(TCIndex_ >= TCIndexMin && TCIndex_ < TCIndexMax);
65 }
66 
68  outputProj = dynamic_cast<TrackletProjectionsMemory*>(memory);
69  assert(outputProj != nullptr);
70 }
71 
73  if (settings_.writetrace()) {
74  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output "
75  << output;
76  }
77 
78  if (output == "trackpar") {
79  auto* tmp = dynamic_cast<TrackletParametersMemory*>(memory);
80  assert(tmp != nullptr);
82  return;
83  }
84 
85  if (output.substr(0, 7) == "projout") {
86  //output is on the form 'projoutL2PHIC' or 'projoutD3PHIB'
87  auto* tmp = dynamic_cast<TrackletProjectionsMemory*>(memory);
88  assert(tmp != nullptr);
89 
90  constexpr unsigned layerdiskPosInprojout = 8;
91  constexpr unsigned phiPosInprojout = 12;
92 
93  unsigned int layerdisk = output[layerdiskPosInprojout] - '1'; //layer or disk counting from 0
94  unsigned int phiregion = output[phiPosInprojout] - 'A'; //phiregion counting from 0
95 
96  if (output[7] == 'L') {
97  assert(layerdisk < N_LAYER);
98  assert(phiregion < trackletprojlayers_[layerdisk].size());
99  //check that phiregion not already initialized
100  assert(trackletprojlayers_[layerdisk][phiregion] == nullptr);
101  trackletprojlayers_[layerdisk][phiregion] = tmp;
102  return;
103  }
104 
105  if (output[7] == 'D') {
106  assert(layerdisk < N_DISK);
107  assert(phiregion < trackletprojdisks_[layerdisk].size());
108  //check that phiregion not already initialized
109  assert(trackletprojdisks_[layerdisk][phiregion] == nullptr);
110  trackletprojdisks_[layerdisk][phiregion] = tmp;
111  return;
112  }
113  }
114 
115  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output;
116 }
117 
119  if (settings_.writetrace()) {
120  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input "
121  << input;
122  }
123 
124  if (input == "thirdallstubin") {
125  auto* tmp = dynamic_cast<AllStubsMemory*>(memory);
126  assert(tmp != nullptr);
127  innerallstubs_.push_back(tmp);
128  return;
129  }
130  if (input == "firstallstubin") {
131  auto* tmp = dynamic_cast<AllStubsMemory*>(memory);
132  assert(tmp != nullptr);
133  middleallstubs_.push_back(tmp);
134  return;
135  }
136  if (input == "secondallstubin") {
137  auto* tmp = dynamic_cast<AllStubsMemory*>(memory);
138  assert(tmp != nullptr);
139  outerallstubs_.push_back(tmp);
140  return;
141  }
142  if (input == "thirdvmstubin") {
143  auto* tmp = dynamic_cast<VMStubsTEMemory*>(memory);
144  assert(tmp != nullptr);
145  innervmstubs_.push_back(tmp);
146  return;
147  }
148  if (input == "secondvmstubin") {
149  auto* tmp = dynamic_cast<VMStubsTEMemory*>(memory);
150  assert(tmp != nullptr);
151  outervmstubs_.push_back(tmp);
152  return;
153  }
154 
155  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input;
156 }
157 
158 void TrackletProcessorDisplaced::execute(unsigned int iSector, double phimin, double phimax) {
159  unsigned int countall = 0;
160  unsigned int countsel = 0;
161 
162  phimin_ = phimin;
163  phimax_ = phimax;
164  iSector_ = iSector;
165 
166  // loop over the middle stubs in the potential seed
167  for (unsigned int midmem = 0; midmem < middleallstubs_.size(); midmem++) {
168  for (unsigned int i = 0; i < middleallstubs_[midmem]->nStubs(); i++) {
169  const Stub* midallstub = middleallstubs_[midmem]->getStub(i);
170 
171  if (settings_.debugTracklet()) {
172  edm::LogVerbatim("Tracklet") << "In " << getName() << " have middle stub";
173  }
174 
175  // get r/z index of the middle stub
176  int indexz = (((1 << (midallstub->z().nbits() - 1)) + midallstub->z().value()) >>
177  (midallstub->z().nbits() - nbitszfinebintable_));
178  int indexr = -1;
179  bool negdisk = (midallstub->disk().value() < 0); // check if disk in negative z region
180  if (layerdisk1_ >= LayerDisk::D1) { // if a disk
181  if (negdisk)
182  indexz = (1 << nbitszfinebintable_) - indexz;
183  indexr = midallstub->r().value();
184  if (midallstub->isPSmodule()) {
185  indexr = midallstub->r().value() >> (midallstub->r().nbits() - nbitsrfinebintable_);
186  }
187  } else { // else a layer
188  indexr = (((1 << (midallstub->r().nbits() - 1)) + midallstub->r().value()) >>
189  (midallstub->r().nbits() - nbitsrfinebintable_));
190  }
191 
192  assert(indexz >= 0);
193  assert(indexr >= 0);
194  assert(indexz < (1 << nbitszfinebintable_));
195  assert(indexr < (1 << nbitsrfinebintable_));
196 
197  // create lookupbits that define projections from middle stub
198  unsigned int lutwidth = settings_.lutwidthtabextended(0, iSeed_);
199  int lutval = -1;
200  const auto& lutshift = innerTable_.nbits();
201  lutval = innerTable_.lookup((indexz << nbitsrfinebintable_) + indexr);
202  int lutval2 = innerThirdTable_.lookup((indexz << nbitsrfinebintable_) + indexr);
203  if (lutval != -1 && lutval2 != -1)
204  lutval += (lutval2 << lutshift);
205  if (lutval == -1)
206  continue;
207  FPGAWord lookupbits(lutval, lutwidth, true, __LINE__, __FILE__);
208 
209  // get r/z bins for projection into outer layer/disk
210  int nbitsrzbin = N_RZBITS;
211  if (iSeed_ == Seed::D1D2L2)
212  nbitsrzbin--;
213  int rzbinfirst = lookupbits.bits(0, NFINERZBITS);
214  int next = lookupbits.bits(NFINERZBITS, 1);
215  int rzdiffmax = lookupbits.bits(NFINERZBITS + 1 + nbitsrzbin, NFINERZBITS);
216 
217  int start = lookupbits.bits(NFINERZBITS + 1, nbitsrzbin); // first rz bin projection
218  if (iSeed_ == Seed::D1D2L2 && negdisk) // if projecting into disk
219  start += (1 << nbitsrzbin);
220  int last = start + next; // last rz bin projection
221 
222  if (settings_.debugTracklet()) {
223  edm::LogVerbatim("Tracklet") << "Will look in r/z bins for outer stub " << start << " to " << last << endl;
224  }
225 
226  // loop over outer stubs that the middle stub can project to
227  for (int ibin = start; ibin <= last; ibin++) {
228  for (unsigned int outmem = 0; outmem < outervmstubs_.size(); outmem++) {
229  for (unsigned int j = 0; j < outervmstubs_[outmem]->nVMStubsBinned(ibin); j++) {
230  if (settings_.debugTracklet())
231  edm::LogVerbatim("Tracklet") << "In " << getName() << " have outer stub" << endl;
232 
233  const VMStubTE& outvmstub = outervmstubs_[outmem]->getVMStubTEBinned(ibin, j);
234 
235  // check if r/z of outer stub is within projection range
236  int rzbin = (outvmstub.vmbits().value() & (settings_.NLONGVMBINS() - 1));
237  if (start != ibin)
238  rzbin += 8;
239  if (rzbin < rzbinfirst || rzbin - rzbinfirst > rzdiffmax) {
240  if (settings_.debugTracklet()) {
241  edm::LogVerbatim("Tracklet") << "Outer stub rejected because of wrong r/z bin";
242  }
243  continue;
244  }
245 
246  // get r/z bins for projection into third layer/disk
247  int nbitsrzbin_ = N_RZBITS;
248  int next_ = lookupbits.bits(lutshift + NFINERZBITS, 1);
249 
250  int start_ = lookupbits.bits(lutshift + NFINERZBITS + 1, nbitsrzbin_); // first rz bin projection
251  if (iSeed_ == Seed::D1D2L2 && negdisk) // if projecting from disk into layer
252  start_ = settings_.NLONGVMBINS() - 1 - start_ - next_;
253  int last_ = start_ + next_; // last rz bin projection
254 
255  if (settings_.debugTracklet()) {
256  edm::LogVerbatim("Tracklet")
257  << "Will look in rz bins for inner stub " << start_ << " to " << last_ << endl;
258  }
259 
260  // loop over inner stubs that the middle stub can project to
261  for (int ibin_ = start_; ibin_ <= last_; ibin_++) {
262  for (unsigned int inmem = 0; inmem < innervmstubs_.size(); inmem++) {
263  for (unsigned int k = 0; k < innervmstubs_[inmem]->nVMStubsBinned(ibin_); k++) {
264  if (settings_.debugTracklet())
265  edm::LogVerbatim("Tracklet") << "In " << getName() << " have inner stub" << endl;
266 
267  const VMStubTE& invmstub = innervmstubs_[inmem]->getVMStubTEBinned(ibin_, k);
268 
269  countall++;
270 
271  const Stub* innerFPGAStub = invmstub.stub();
272  const Stub* middleFPGAStub = midallstub;
273  const Stub* outerFPGAStub = outvmstub.stub();
274 
275  const L1TStub* innerStub = innerFPGAStub->l1tstub();
276  const L1TStub* middleStub = middleFPGAStub->l1tstub();
277  const L1TStub* outerStub = outerFPGAStub->l1tstub();
278 
279  if (settings_.debugTracklet()) {
280  edm::LogVerbatim("Tracklet")
281  << "triplet seeding\n"
282  << innerFPGAStub->strbare() << middleFPGAStub->strbare() << outerFPGAStub->strbare()
283  << innerStub->stubword() << middleStub->stubword() << outerStub->stubword()
284  << innerFPGAStub->layerdisk() << middleFPGAStub->layerdisk() << outerFPGAStub->layerdisk();
285  edm::LogVerbatim("Tracklet")
286  << "TrackletCalculatorDisplaced execute " << getName() << "[" << iSector_ << "]";
287  }
288 
289  // check if the seed made from the 3 stubs is valid
290  bool accept = false;
291  if (iSeed_ == Seed::L2L3L4 || iSeed_ == Seed::L4L5L6)
292  accept = LLLSeeding(innerFPGAStub, innerStub, middleFPGAStub, middleStub, outerFPGAStub, outerStub);
293  else if (iSeed_ == Seed::L2L3D1)
294  accept = LLDSeeding(innerFPGAStub, innerStub, middleFPGAStub, middleStub, outerFPGAStub, outerStub);
295  else if (iSeed_ == Seed::D1D2L2)
296  accept = DDLSeeding(innerFPGAStub, innerStub, middleFPGAStub, middleStub, outerFPGAStub, outerStub);
297 
298  if (accept)
299  countsel++;
300 
301  if (settings_.debugTracklet()) {
302  edm::LogVerbatim("Tracklet") << "TrackletCalculatorDisplaced execute done";
303  }
304  if (countall >= settings_.maxStep("TPD"))
305  break;
306  }
307  if (countall >= settings_.maxStep("TPD"))
308  break;
309  }
310  if (countall >= settings_.maxStep("TPD"))
311  break;
312  }
313  if (countall >= settings_.maxStep("TPD"))
314  break;
315  }
316  if (countall >= settings_.maxStep("TPD"))
317  break;
318  }
319  if (countall >= settings_.maxStep("TPD"))
320  break;
321  }
322  if (countall >= settings_.maxStep("TPD"))
323  break;
324  }
325  if (countall >= settings_.maxStep("TPD"))
326  break;
327  }
328 
329  if (settings_.writeMonitorData("TPD")) {
330  globals_->ofstream("trackletprocessordisplaced.txt") << getName() << " " << countall << " " << countsel << endl;
331  }
332 }
Definition: start.py:1
unsigned int vmrlutrbits(unsigned int layerdisk) const
Definition: Settings.h:191
Log< level::Info, true > LogVerbatim
constexpr unsigned int N_RZBITS
Definition: Settings.h:39
std::vector< AllStubsMemory * > middleallstubs_
constexpr int N_DISK
Definition: Settings.h:26
unsigned int maxStep(std::string module) const
Definition: Settings.h:125
const FPGAWord & r() const
Definition: Stub.h:65
std::string name_
Definition: ProcessBase.h:42
unsigned int nbits() const
Definition: TrackletLUT.h:119
std::vector< AllStubsMemory * > innerallstubs_
const FPGAWord & z() const
Definition: Stub.h:66
std::string strbare() const
Definition: Stub.h:40
Settings const & settings_
Definition: ProcessBase.h:44
void initLayerDisksandISeedDisp(unsigned int &layerdisk1, unsigned int &layerdisk2, unsigned int &layerdisk3, unsigned int &iSeed)
Definition: ProcessBase.cc:119
Globals * globals_
Definition: ProcessBase.h:45
int lookup(unsigned int index) const
bool writetrace() const
Definition: Settings.h:195
std::vector< VMStubsTEMemory * > innervmstubs_
assert(be >=bs)
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:31
static std::string const input
Definition: EdmProvDump.cc:50
unsigned int NLONGVMBINS() const
Definition: Settings.h:376
const FPGAWord & disk() const
Definition: Stub.h:74
bool LLDSeeding(const Stub *innerFPGAStub, const L1TStub *innerStub, const Stub *middleFPGAStub, const L1TStub *middleStub, const Stub *outerFPGAStub, const L1TStub *outerStub)
const Stub * stub() const
Definition: VMStubTE.h:29
std::vector< std::vector< TrackletProjectionsMemory * > > trackletprojlayers_
void initVMRTable(unsigned int layerdisk, VMRTableType type, int region=-1, bool combined=true)
Definition: TrackletLUT.cc:998
void execute(unsigned int iSector, double phimin, double phimax)
Divides< A, C > D1
Definition: Factorize.h:136
bool LLLSeeding(const Stub *innerFPGAStub, const L1TStub *innerStub, const Stub *middleFPGAStub, const L1TStub *middleStub, const Stub *outerFPGAStub, const L1TStub *outerStub)
const FPGAWord & vmbits() const
Definition: VMStubTE.h:27
int value() const
Definition: FPGAWord.h:24
double lutwidthtabextended(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:150
L1TStub * l1tstub()
Definition: Stub.h:83
std::vector< std::vector< TrackletProjectionsMemory * > > trackletprojdisks_
bool writeMonitorData(std::string module) const
Definition: Settings.h:118
unsigned int layerdisk() const
Definition: Stub.cc:193
constexpr unsigned int NFINERZBITS
Definition: Settings.h:37
unsigned int nallstubs(unsigned int layerdisk) const
Definition: Settings.h:116
bool debugTracklet() const
Definition: Settings.h:194
bool DDLSeeding(const Stub *innerFPGAStub, const L1TStub *innerStub, const Stub *middleFPGAStub, const L1TStub *middleStub, const Stub *outerFPGAStub, const L1TStub *outerStub)
int nbits() const
Definition: FPGAWord.h:25
const std::string & stubword() const
Definition: L1TStub.h:123
bool isPSmodule() const
Definition: Stub.h:77
std::ofstream & ofstream(std::string fname)
Definition: Globals.cc:44
Definition: output.py:1
std::vector< AllStubsMemory * > outerallstubs_
void addOutput(MemoryBase *memory, std::string output) override
unsigned int bits(unsigned int lsb, unsigned int nbit) const
Definition: FPGAWord.cc:74
tmp
align.sh
Definition: createJobs.py:716
std::vector< VMStubsTEMemory * > outervmstubs_
std::string const & getName() const
Definition: ProcessBase.h:22
void addOutputProjection(TrackletProjectionsMemory *&outputProj, MemoryBase *memory)
void addInput(MemoryBase *memory, std::string input) override
unsigned int vmrlutzbits(unsigned int layerdisk) const
Definition: Settings.h:190
constexpr int N_LAYER
Definition: Settings.h:25