CMS 3D CMS Logo

TrackletEngine.cc
Go to the documentation of this file.
7 
10 
11 using namespace trklet;
12 using namespace std;
13 
14 TrackletEngine::TrackletEngine(string name, Settings const& settings, Globals* global, unsigned int iSector)
15  : ProcessBase(name, settings, global, iSector) {
16  stubpairs_ = nullptr;
17  innervmstubs_ = nullptr;
18  outervmstubs_ = nullptr;
19 
21 
22  innerphibits_ = settings.nfinephi(0, iSeed_);
23  outerphibits_ = settings.nfinephi(1, iSeed_);
24 }
25 
27  if (settings_.writetrace()) {
28  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output "
29  << output;
30  }
31  if (output == "stubpairout") {
32  StubPairsMemory* tmp = dynamic_cast<StubPairsMemory*>(memory);
33  assert(tmp != nullptr);
34  stubpairs_ = tmp;
35  return;
36  }
37  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output;
38 }
39 
41  if (settings_.writetrace()) {
42  edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input "
43  << input;
44  }
45  if (input == "innervmstubin") {
46  VMStubsTEMemory* tmp = dynamic_cast<VMStubsTEMemory*>(memory);
47  assert(tmp != nullptr);
49  setVMPhiBin();
50  return;
51  }
52  if (input == "outervmstubin") {
53  VMStubsTEMemory* tmp = dynamic_cast<VMStubsTEMemory*>(memory);
54  assert(tmp != nullptr);
56  setVMPhiBin();
57  return;
58  }
59  throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input;
60 }
61 
63  if (!settings_.useSeed(iSeed_))
64  return;
65 
66  unsigned int countall = 0;
67  unsigned int countpass = 0;
68 
69  assert(innervmstubs_ != nullptr);
70  assert(outervmstubs_ != nullptr);
71 
72  for (unsigned int i = 0; i < innervmstubs_->nVMStubs(); i++) {
73  const VMStubTE& innervmstub = innervmstubs_->getVMStubTE(i);
74  FPGAWord lookupbits = innervmstub.vmbits();
75 
76  unsigned int nbits = 7;
77  if (iSeed_ == 4 || iSeed_ == 5)
78  nbits = 6;
79  int rzdiffmax = lookupbits.bits(nbits, lookupbits.nbits() - nbits);
80  int rzbinfirst = lookupbits.bits(0, 3);
81  int start = lookupbits.bits(4, nbits - 4);
82  int next = lookupbits.bits(3, 1);
83 
84  if ((iSeed_ == 4 || iSeed_ == 5) && innervmstub.stub()->disk().value() < 0) { //TODO - need to store negative disk
85  start += 4;
86  }
87  int last = start + next;
88 
89  for (int ibin = start; ibin <= last; ibin++) {
90  for (unsigned int j = 0; j < outervmstubs_->nVMStubsBinned(ibin); j++) {
91  if (countall >= settings_.maxStep("TE"))
92  break;
93  countall++;
94  const VMStubTE& outervmstub = outervmstubs_->getVMStubTEBinned(ibin, j);
95 
96  int rzbin = outervmstub.vmbits().bits(0, 3);
97 
98  FPGAWord iphiinnerbin = innervmstub.finephi();
99  FPGAWord iphiouterbin = outervmstub.finephi();
100 
101  unsigned int index = (iphiinnerbin.value() << outerphibits_) + iphiouterbin.value();
102 
103  if (iSeed_ >= 4) { //Also use r-position
104  int ir = ((ibin & 3) << 1) + (rzbin >> 2);
105  index = (index << 3) + ir;
106  }
107 
108  if (start != ibin)
109  rzbin += 8;
110  if ((rzbin < rzbinfirst) || (rzbin - rzbinfirst > rzdiffmax)) {
111  continue;
112  }
113 
114  FPGAWord innerbend = innervmstub.bend();
115  FPGAWord outerbend = outervmstub.bend();
116 
117  int ptinnerindex = (index << innerbend.nbits()) + innerbend.value();
118  int ptouterindex = (index << outerbend.nbits()) + outerbend.value();
119 
120  if (!(pttableinner_[ptinnerindex] && pttableouter_[ptouterindex])) {
121  if (settings_.debugTracklet()) {
122  edm::LogVerbatim("Tracklet") << "Stub pair rejected because of stub pt cut bends : "
123  << benddecode(innervmstub.bend().value(), innervmstub.isPSmodule()) << " "
124  << benddecode(outervmstub.bend().value(), outervmstub.isPSmodule());
125  }
126  continue;
127  }
128 
129  if (settings_.debugTracklet())
130  edm::LogVerbatim("Tracklet") << "Adding stub pair in " << getName();
131 
132  stubpairs_->addStubPair(innervmstub, outervmstub);
133  countpass++;
134  }
135  }
136  }
137 
138  if (settings_.writeMonitorData("TE")) {
139  globals_->ofstream("trackletengine.txt") << getName() << " " << countall << " " << countpass << endl;
140  }
141 }
142 
144  if (innervmstubs_ == nullptr || outervmstubs_ == nullptr)
145  return;
146 
149 
150  int outerrbits = 3;
151  if (iSeed_ < 4) {
152  outerrbits = 0;
153  }
154 
155  int outerrbins = (1 << outerrbits);
156  int innerphibins = (1 << innerphibits_);
157  int outerphibins = (1 << outerphibits_);
158 
159  double innerphimin, innerphimax;
160  innervmstubs_->getPhiRange(innerphimin, innerphimax, iSeed_, 0);
161 
162  double outerphimin, outerphimax;
163  outervmstubs_->getPhiRange(outerphimin, outerphimax, iSeed_, 1);
164 
165  double phiinner[2];
166  double phiouter[2];
167  double router[2];
168 
169  unsigned int nbendbitsinner = 3;
170  unsigned int nbendbitsouter = 3;
171  if (iSeed_ == 2) {
172  nbendbitsouter = 4;
173  }
174  if (iSeed_ == 3) {
175  nbendbitsinner = 4;
176  nbendbitsouter = 4;
177  }
178 
179  std::vector<bool> vmbendinner((1 << nbendbitsinner), false);
180  std::vector<bool> vmbendouter((1 << nbendbitsouter), false);
181 
182  for (int iphiinnerbin = 0; iphiinnerbin < innerphibins; iphiinnerbin++) {
183  phiinner[0] = innerphimin + iphiinnerbin * (innerphimax - innerphimin) / innerphibins;
184  phiinner[1] = innerphimin + (iphiinnerbin + 1) * (innerphimax - innerphimin) / innerphibins;
185  for (int iphiouterbin = 0; iphiouterbin < outerphibins; iphiouterbin++) {
186  phiouter[0] = outerphimin + iphiouterbin * (outerphimax - outerphimin) / outerphibins;
187  phiouter[1] = outerphimin + (iphiouterbin + 1) * (outerphimax - outerphimin) / outerphibins;
188  for (int irouterbin = 0; irouterbin < outerrbins; irouterbin++) {
189  if (iSeed_ >= 4) {
190  router[0] =
191  settings_.rmindiskvm() + irouterbin * (settings_.rmaxdiskvm() - settings_.rmindiskvm()) / outerrbins;
192  router[1] = settings_.rmindiskvm() +
193  (irouterbin + 1) * (settings_.rmaxdiskvm() - settings_.rmindiskvm()) / outerrbins;
194  } else {
195  router[0] = settings_.rmean(layerdisk2_);
196  router[1] = settings_.rmean(layerdisk2_);
197  }
198 
199  double bendinnermin = 20.0;
200  double bendinnermax = -20.0;
201  double bendoutermin = 20.0;
202  double bendoutermax = -20.0;
203  double rinvmin = 1.0;
204  for (int i1 = 0; i1 < 2; i1++) {
205  for (int i2 = 0; i2 < 2; i2++) {
206  for (int i3 = 0; i3 < 2; i3++) {
207  double rinner = 0.0;
208  if (iSeed_ == 4 || iSeed_ == 5) {
210  } else {
211  rinner = settings_.rmean(layerdisk1_);
212  }
213  double rinv1 = rinv(phiinner[i1], phiouter[i2], rinner, router[i3]);
214  double pitchinner =
215  (rinner < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false);
216  double pitchouter =
217  (router[i3] < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false);
218  double abendinner = -bend(rinner, rinv1, pitchinner);
219  double abendouter = -bend(router[i3], rinv1, pitchouter);
220  if (abendinner < bendinnermin)
221  bendinnermin = abendinner;
222  if (abendinner > bendinnermax)
223  bendinnermax = abendinner;
224  if (abendouter < bendoutermin)
225  bendoutermin = abendouter;
226  if (abendouter > bendoutermax)
227  bendoutermax = abendouter;
228  if (std::abs(rinv1) < rinvmin) {
229  rinvmin = std::abs(rinv1);
230  }
231  }
232  }
233  }
234 
235  bool passptcut = rinvmin < settings_.rinvcutte();
236 
237  for (int ibend = 0; ibend < (1 << nbendbitsinner); ibend++) {
238  double bend = benddecode(ibend, nbendbitsinner == 3);
239 
240  bool passinner = bend - bendinnermin > -settings_.bendcutte(0, iSeed_) &&
241  bend - bendinnermax < settings_.bendcutte(0, iSeed_);
242  if (passinner)
243  vmbendinner[ibend] = true;
244  pttableinner_.push_back(passinner && passptcut);
245  }
246 
247  for (int ibend = 0; ibend < (1 << nbendbitsouter); ibend++) {
248  double bend = benddecode(ibend, nbendbitsouter == 3);
249 
250  bool passouter = bend - bendoutermin > -settings_.bendcutte(1, iSeed_) &&
251  bend - bendoutermax < settings_.bendcutte(1, iSeed_);
252  if (passouter)
253  vmbendouter[ibend] = true;
254  pttableouter_.push_back(passouter && passptcut);
255  }
256  }
257  }
258  }
259 
260  innervmstubs_->setbendtable(vmbendinner);
261  outervmstubs_->setbendtable(vmbendouter);
262 
263  if (iSector_ == 0 && settings_.writeTable())
264  writeTETable();
265 }
266 
268  ofstream outstubptinnercut;
269  outstubptinnercut.open(getName() + "_stubptinnercut.tab");
270  outstubptinnercut << "{" << endl;
271  for (unsigned int i = 0; i < pttableinner_.size(); i++) {
272  if (i != 0)
273  outstubptinnercut << "," << endl;
274  outstubptinnercut << pttableinner_[i];
275  }
276  outstubptinnercut << endl << "};" << endl;
277  outstubptinnercut.close();
278 
279  ofstream outstubptoutercut;
280  outstubptoutercut.open(getName() + "_stubptoutercut.tab");
281  outstubptoutercut << "{" << endl;
282  for (unsigned int i = 0; i < pttableouter_.size(); i++) {
283  if (i != 0)
284  outstubptoutercut << "," << endl;
285  outstubptoutercut << pttableouter_[i];
286  }
287  outstubptoutercut << endl << "};" << endl;
288  outstubptoutercut.close();
289 }
Settings.h
trklet::VMStubsTEMemory::setother
void setother(VMStubsTEMemory *other)
Definition: VMStubsTEMemory.h:42
Util.h
trklet::VMStubsTEMemory::setbendtable
void setbendtable(std::vector< bool > vmbendtable)
Definition: VMStubsTEMemory.cc:254
testProducerWithPsetDescEmpty_cfi.i2
i2
Definition: testProducerWithPsetDescEmpty_cfi.py:46
testProducerWithPsetDescEmpty_cfi.i3
i3
Definition: testProducerWithPsetDescEmpty_cfi.py:47
trklet::Settings::rmindiskvm
double rmindiskvm() const
Definition: Settings.h:260
trklet::TrackletEngine::innerphibits_
unsigned int innerphibits_
Definition: TrackletEngine.h:50
mps_fire.i
i
Definition: mps_fire.py:355
trklet::Settings::writetrace
bool writetrace() const
Definition: Settings.h:147
start
Definition: start.py:1
input
static const std::string input
Definition: EdmProvDump.cc:48
trklet::StubPairsMemory
Definition: StubPairsMemory.h:13
MessageLogger.h
trklet::VMStubTE
Definition: VMStubTE.h:15
trklet::TrackletEngine::addInput
void addInput(MemoryBase *memory, std::string input) override
Definition: TrackletEngine.cc:40
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:32
trklet::TrackletEngine::outerphibits_
unsigned int outerphibits_
Definition: TrackletEngine.h:51
trklet::VMStubsTEMemory::getVMStubTEBinned
const VMStubTE & getVMStubTEBinned(unsigned int bin, unsigned int i) const
Definition: VMStubsTEMemory.h:32
testProducerWithPsetDescEmpty_cfi.i1
i1
Definition: testProducerWithPsetDescEmpty_cfi.py:45
trklet::Settings
Definition: Settings.h:26
trklet::TrackletEngine::layerdisk2_
unsigned int layerdisk2_
Definition: TrackletEngine.h:36
trklet::VMStubsTEMemory
Definition: VMStubsTEMemory.h:16
trklet::StubPairsMemory::addStubPair
void addStubPair(const VMStubTE &stub1, const VMStubTE &stub2, const unsigned index=0, const std::string &tedName="")
Definition: StubPairsMemory.h:19
cms::cuda::assert
assert(be >=bs)
trklet::Settings::rmean
double rmean(unsigned int iLayer) const
Definition: Settings.h:128
trklet::ProcessBase::nbits
unsigned int nbits(unsigned int power)
Definition: ProcessBase.cc:29
trklet::ProcessBase::settings_
Settings const & settings_
Definition: ProcessBase.h:44
trklet::TrackletEngine::outervmstubs_
VMStubsTEMemory * outervmstubs_
Definition: TrackletEngine.h:40
trklet::FPGAWord::nbits
int nbits() const
Definition: FPGAWord.h:25
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
trklet::Globals
Definition: Globals.h:32
trklet::VMStubTE::isPSmodule
bool isPSmodule() const
Definition: VMStubTE.h:31
trklet::TrackletEngine::setVMPhiBin
void setVMPhiBin()
Definition: TrackletEngine.cc:143
trklet::Settings::writeTable
bool writeTable() const
Definition: Settings.h:153
trklet::TrackletEngine::pttableinner_
std::vector< bool > pttableinner_
Definition: TrackletEngine.h:46
trklet::VMStubTE::bend
const FPGAWord & bend() const
Definition: VMStubTE.h:25
trklet::VMStubsTEMemory::nVMStubs
unsigned int nVMStubs() const
Definition: VMStubsTEMemory.h:26
trklet::TrackletEngine::writeTETable
void writeTETable()
Definition: TrackletEngine.cc:267
trklet::TrackletEngine::pttableouter_
std::vector< bool > pttableouter_
Definition: TrackletEngine.h:47
dqmdumpme.last
last
Definition: dqmdumpme.py:56
trklet::Stub::disk
const FPGAWord & disk() const
Definition: Stub.h:57
trklet::FPGAWord::bits
unsigned int bits(unsigned int lsb, unsigned int nbit) const
Definition: FPGAWord.cc:74
trklet::TrackletEngine::iSeed_
unsigned int iSeed_
Definition: TrackletEngine.h:34
trklet::N_LAYER
constexpr int N_LAYER
Definition: Settings.h:19
trklet::Settings::zmean
double zmean(unsigned int iDisk) const
Definition: Settings.h:131
trklet::ProcessBase::initLayerDisksandISeed
void initLayerDisksandISeed(unsigned int &layerdisk1, unsigned int &layerdisk2, unsigned int &iSeed)
Definition: ProcessBase.cc:75
trklet::VMStubsTEMemory::getVMStubTE
const VMStubTE & getVMStubTE(unsigned int i) const
Definition: VMStubsTEMemory.h:30
trklet::FPGAWord
Definition: FPGAWord.h:9
trklet::MemoryBase
Definition: MemoryBase.h:13
trklet::TrackletEngine::execute
void execute()
Definition: TrackletEngine.cc:62
trklet::rinv
double rinv(double phi1, double phi2, double r1, double r2)
Definition: Util.h:167
trklet::VMStubTE::stub
const Stub * stub() const
Definition: VMStubTE.h:29
trklet::Settings::bendcutte
double bendcutte(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:110
trklet::TrackletEngine::layerdisk1_
unsigned int layerdisk1_
Definition: TrackletEngine.h:35
StubPairsMemory.h
Globals.h
edm::LogVerbatim
Definition: MessageLogger.h:297
trklet::Settings::rinvcutte
double rinvcutte() const
Definition: Settings.h:258
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
VMStubsTEMemory.h
trklet::Settings::stripPitch
double stripPitch(bool isPSmodule) const
Definition: Settings.h:219
trklet::Settings::writeMonitorData
bool writeMonitorData(std::string module) const
Definition: Settings.h:86
trklet::TrackletEngine::addOutput
void addOutput(MemoryBase *memory, std::string output) override
Definition: TrackletEngine.cc:26
std
Definition: JetResolutionObject.h:76
trklet::ProcessBase
Definition: ProcessBase.h:12
trklet::Globals::ofstream
std::ofstream & ofstream(std::string fname)
Definition: Globals.cc:44
trklet::TrackletEngine::TrackletEngine
TrackletEngine(std::string name, Settings const &settings, Globals *global, unsigned int iSector)
Definition: TrackletEngine.cc:14
trklet::TrackletEngine::innervmstubs_
VMStubsTEMemory * innervmstubs_
Definition: TrackletEngine.h:39
trklet::bend
double bend(double r, double rinv, double stripPitch)
Definition: Util.h:160
trklet::VMStubsTEMemory::getPhiRange
void getPhiRange(double &phimin, double &phimax, unsigned int iSeed, unsigned int inner)
Definition: VMStubsTEMemory.cc:225
trklet::TrackletEngine::stubpairs_
StubPairsMemory * stubpairs_
Definition: TrackletEngine.h:43
Exception
Definition: hltDiff.cc:246
trklet::ProcessBase::getName
std::string const & getName() const
Definition: ProcessBase.h:22
trklet::ProcessBase::name_
std::string name_
Definition: ProcessBase.h:38
trklet::VMStubTE::finephi
const FPGAWord & finephi() const
Definition: VMStubTE.h:23
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
trklet::ProcessBase::iSector_
unsigned int iSector_
Definition: ProcessBase.h:39
trklet::Settings::debugTracklet
bool debugTracklet() const
Definition: Settings.h:146
trklet::Settings::rcrit
double rcrit() const
Definition: Settings.h:236
Exception.h
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
trklet::Settings::maxStep
unsigned int maxStep(std::string module) const
Definition: Settings.h:93
trklet::Settings::nfinephi
double nfinephi(unsigned int inner, unsigned int iSeed) const
Definition: Settings.h:112
trklet::benddecode
double benddecode(int ibend, bool isPS)
Definition: Util.h:100
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
trklet::ProcessBase::globals_
Globals * globals_
Definition: ProcessBase.h:45
trklet::Settings::useSeed
bool useSeed(unsigned int iSeed) const
Definition: Settings.h:76
trklet::VMStubsTEMemory::nVMStubsBinned
unsigned int nVMStubsBinned(unsigned int bin) const
Definition: VMStubsTEMemory.h:28
memory
Definition: vlib.h:178
GetRecoTauVFromDQM_MC_cff.next
next
Definition: GetRecoTauVFromDQM_MC_cff.py:31
TrackletEngine.h
trklet::Settings::rmaxdiskvm
double rmaxdiskvm() const
Definition: Settings.h:261