CMS 3D CMS Logo

FullMatchMemory.cc
Go to the documentation of this file.
6 #include <iomanip>
7 #include <filesystem>
8 
9 using namespace std;
10 using namespace trklet;
11 
12 FullMatchMemory::FullMatchMemory(string name, Settings const& settings) : MemoryBase(name, settings) {
13  size_t pos = find_nth(name, 0, "_", 1);
14  assert(pos != string::npos);
16 }
17 
18 void FullMatchMemory::addMatch(Tracklet* tracklet, const Stub* stub) {
20  // When allowing only one stub per track per layer (or no KF implying same).
21  for (auto& match : matches_) {
22  if (match.first == tracklet) { //Better match: replace existing one
23  match.second = stub;
24  return;
25  }
26  }
27  }
28  std::pair<Tracklet*, const Stub*> tmp(tracklet, stub);
29  //Check that we have the right TCID order
30  if (!matches_.empty()) {
31  if ((!settings_.doKF() && matches_[matches_.size() - 1].first->TCID() >= tracklet->TCID()) ||
32  (settings_.doKF() && matches_[matches_.size() - 1].first->TCID() > tracklet->TCID())) {
33  edm::LogPrint("Tracklet") << "Wrong TCID ordering in " << getName() << " : "
34  << matches_[matches_.size() - 1].first->TCID() << " " << tracklet->TCID() << " "
35  << matches_[matches_.size() - 1].first->trackletIndex() << " "
36  << tracklet->trackletIndex();
37  }
38  }
39  matches_.push_back(tmp);
40 }
41 
42 void FullMatchMemory::writeMC(bool first, unsigned int iSector) {
43  iSector_ = iSector;
44  const string dirM = settings_.memPath() + "Matches/";
45 
46  std::ostringstream oss;
47  oss << dirM << "FullMatches_" << getName() << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat";
48  auto const& fname = oss.str();
49 
50  openfile(out_, first, dirM, fname, __FILE__, __LINE__);
51 
52  out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl;
53 
54  for (unsigned int j = 0; j < matches_.size(); j++) {
55  string match = (layer_ > 0) ? matches_[j].first->fullmatchstr(layer_) : matches_[j].first->fullmatchdiskstr(disk_);
56  out_ << hexstr(j) << " " << match << " " << trklet::hexFormat(match) << endl;
57  }
58  out_.close();
59 
60  bx_++;
61  event_++;
62  if (bx_ > 7)
63  bx_ = 0;
64 }
static size_t find_nth(const std::string &haystack, size_t pos, const std::string &needle, size_t nth)
Definition: MemoryBase.cc:104
unsigned int iSector_
Definition: MemoryBase.h:47
std::vector< std::pair< Tracklet *, const Stub * > > matches_
assert(be >=bs)
int TCID() const
Definition: Tracklet.h:214
std::string hexFormat(const std::string &binary)
Definition: Util.h:19
std::string memPath() const
Definition: Settings.h:192
int trackletIndex() const
Definition: Tracklet.h:208
Settings const & settings_
Definition: MemoryBase.h:53
std::ofstream out_
Definition: MemoryBase.h:49
void addMatch(Tracklet *tracklet, const Stub *stub)
bool doMultipleMatches() const
Definition: Settings.h:242
std::string const & getName() const
Definition: MemoryBase.h:19
Log< level::Warning, true > LogPrint
static std::string hexstr(unsigned int index)
Definition: MemoryBase.cc:111
string fname
main script
void writeMC(bool first, unsigned int iSector)
tmp
align.sh
Definition: createJobs.py:716
bool doKF() const
Definition: Settings.h:241
void initLayerDisk(unsigned int pos, int &layer, int &disk)
Definition: MemoryBase.cc:20
std::ofstream openfile(const std::string &dir, const std::string &fname, const char *file, int line)
Definition: Util.h:137