CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TrackletProjectionsMemory.cc
Go to the documentation of this file.
4 #include <iomanip>
5 #include <filesystem>
6 
7 using namespace std;
8 using namespace trklet;
9 
10 TrackletProjectionsMemory::TrackletProjectionsMemory(string name, Settings const& settings)
11  : MemoryBase(name, settings) {
12  size_t pos = find_nth(name, 0, "_", 1);
13  assert(pos != string::npos);
14  initLayerDisk(pos + 1, layer_, disk_);
15 }
16 
18  if (layer_ != 0 && disk_ == 0)
19  assert(tracklet->validProj(layer_ - 1));
20  if (layer_ == 0 && disk_ != 0)
21  assert(tracklet->validProj(N_LAYER + abs(disk_) - 1));
22  if (layer_ != 0 && disk_ != 0)
23  assert(tracklet->validProj(layer_ - 1) || tracklet->validProj(N_LAYER + abs(disk_) - 1));
24 
25  for (auto& itracklet : tracklets_) {
26  if (itracklet == tracklet) {
27  edm::LogPrint("Tracklet") << "Adding same tracklet " << tracklet << " twice in " << getName();
28  }
29  assert(itracklet != tracklet);
30  }
31 
32  tracklets_.push_back(tracklet);
33 }
34 
36 
37 void TrackletProjectionsMemory::writeTPROJ(bool first, unsigned int iSector) {
38  iSector_ = iSector;
39  const string dirTP = settings_.memPath() + "TrackletProjections/";
40 
41  std::ostringstream oss;
42  oss << dirTP << "TrackletProjections_" << getName() << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1)
43  << ".dat";
44  auto const& fname = oss.str();
45 
46  openfile(out_, first, dirTP, fname, __FILE__, __LINE__);
47 
48  out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl;
49 
50  for (unsigned int j = 0; j < tracklets_.size(); j++) {
51  string proj = (layer_ > 0 && tracklets_[j]->validProj(layer_ - 1)) ? tracklets_[j]->trackletprojstrlayer(layer_)
52  : tracklets_[j]->trackletprojstrdisk(disk_);
53  out_ << "0x";
54  out_ << std::setfill('0') << std::setw(2);
55  out_ << hex << j << dec;
56  out_ << " " << proj << " " << trklet::hexFormat(proj) << 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:103
std::string memPath() const
Definition: Settings.h:192
unsigned int iSector_
Definition: MemoryBase.h:44
void writeTPROJ(bool first, unsigned int iSector)
assert(be >=bs)
std::string hexFormat(const std::string &binary)
Definition: Util.h:19
bool validProj(int layerdisk) const
Definition: Tracklet.h:82
std::string const & getName() const
Definition: MemoryBase.h:19
Settings const & settings_
Definition: MemoryBase.h:50
std::ofstream out_
Definition: MemoryBase.h:46
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Log< level::Warning, true > LogPrint
string fname
main script
void initLayerDisk(unsigned int pos, int &layer, int &disk)
Definition: MemoryBase.cc:19
std::ofstream openfile(const std::string &dir, const std::string &fname, const char *file, int line)
Definition: Util.h:139
constexpr int N_LAYER
Definition: Settings.h:21