CMS 3D CMS Logo

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