CMS 3D CMS Logo

COEFile.cc
Go to the documentation of this file.
2 
3 using namespace l1tpf_impl;
4 
6  : file(nullptr),
7  coeFileName(iConfig.getUntrackedParameter<std::string>("coeFileName", "")),
8  bset_string_(""),
9  ntracksmax(iConfig.getUntrackedParameter<unsigned int>("ntracksmax")),
10  phiSlices(iConfig.getParameter<std::vector<edm::ParameterSet>>("regions")[0].getParameter<uint32_t>("phiSlices")),
11  debug_(iConfig.getUntrackedParameter<int>("debug", 0)) {
12  file = fopen(coeFileName.c_str(), "w");
14  bset_.resize(tracksize);
15 }
16 
18 
20  char depth_width[256];
21  snprintf(depth_width,
22  255,
23  "; of depth=%i, and width=%i. In this case, values are specified\n",
24  ntracksmax,
26  std::vector<std::string> vheader = {"; Sample memory initialization file for Dual Port Block Memory,\n",
27  "; v3.0 or later.\n",
28  "; Board: VCU118\n",
29  "; tmux: 1\n",
30  ";\n",
31  "; This .COE file specifies the contents for a block memory\n",
32  std::string(depth_width),
33  "; in binary format.\n",
34  "memory_initialization_radix=2;\n",
35  "memory_initialization_vector=\n"};
36  for (uint32_t i = 0; i < vheader.size(); ++i)
37  fprintf(file, "%s", vheader[i].c_str());
38 }
39 
40 void COEFile::writeTracksToFile(const std::vector<Region>& regions, bool print) {
41  PropagatedTrack current_track;
42  bool has_track = false;
43  for (unsigned int irow = 0; irow < ntracksmax; irow++) {
44  for (unsigned int icol = 0; icol < regions.size(); icol++) {
45  if (regions[icol].track.size() <= irow)
46  has_track = false;
47  else
48  has_track = true;
49 
50  if (has_track) {
51  // select the track that will be converted to a bit string
52  current_track = regions[icol].track[irow];
53 
54  // convert the values in a PropogatedTrack to a 96-bit track word
55  for (unsigned int iblock = 0; iblock < track_word_block_sizes.size(); iblock++) {
56  for (unsigned int ibit = 0; ibit < track_word_block_sizes[iblock]; ibit++) {
57  int offset = std::accumulate(track_word_block_sizes.begin(), track_word_block_sizes.begin() + iblock, 0);
58  switch (iblock) {
59  case 0:
60  bset_.set(ibit + offset, getBit<uint16_t>(current_track.hwPt, ibit));
61  break;
62  case 1:
63  bset_.set(ibit + offset, current_track.hwCharge);
64  break;
65  case 2:
66  bset_.set(ibit + offset, getBit<uint16_t>(current_track.hwVtxPhi, ibit));
67  break;
68  case 3:
69  bset_.set(ibit + offset, getBit<uint16_t>(current_track.hwVtxEta, ibit));
70  break;
71  case 4:
72  bset_.set(ibit + offset, getBit<uint16_t>(current_track.hwZ0, ibit));
73  break;
74  case 5:
75  bset_.set(ibit + offset, false);
76  break;
77  case 6:
78  bset_.set(ibit + offset, getBit<uint16_t>(current_track.hwChi2, ibit));
79  break;
80  case 7:
81  bset_.set(ibit + offset, false);
82  break;
83  case 8:
84  bset_.set(ibit + offset, getBit<uint16_t>(current_track.hwStubs, ibit));
85  break;
86  case 9:
87  bset_.set(ibit + offset, false);
88  break;
89  }
90  }
91  }
92 
93  // print the track word to the COE file
94  boost::to_string(bset_, bset_string_);
95  fprintf(file, "%s", bset_string_.c_str());
96 
97  // print some debugging information
98  if (debug_ && print && irow == 0 && icol == 0) {
99  printf("region: eta=[%f,%f] phi=%f+/-%f\n",
100  regions[icol].etaMin,
101  regions[icol].etaMax,
102  regions[icol].phiCenter,
103  regions[icol].phiHalfWidth);
104  printf("l1t::PFTrack (pT,eta,phi) [float] = (%f,%f,%f)\n",
105  current_track.src->p4().Pt(),
106  current_track.src->p4().Eta(),
107  current_track.src->p4().Phi());
108  printf("l1t::PFTrack (pT,eta,phi) [int] = (%i,%i,%i)\n",
109  current_track.src->hwPt(),
110  current_track.src->hwEta(),
111  current_track.src->hwPhi());
112  printf("l1tpf_impl::PropagatedTrack (1/pT,eta,phi) [int,10] = (%i,%i,%i)\n",
113  current_track.hwPt,
114  current_track.hwVtxEta,
115  current_track.hwVtxPhi);
116  printf("l1tpf_impl::PropagatedTrack (1/pT,eta,phi) [int,2] = (%s,%s,%s)\n",
117  std::bitset<16>(current_track.hwPt).to_string().c_str(),
118  std::bitset<32>(current_track.hwVtxEta).to_string().c_str(),
119  std::bitset<32>(current_track.hwVtxPhi).to_string().c_str());
120  printf("bitset = %s\n", bset_string_.c_str());
121  }
122  } else {
123  bset_.reset();
124  boost::to_string(bset_, bset_string_);
125  fprintf(file, "%s", bset_string_.c_str());
126  }
127  }
128  fprintf(file, (irow == ntracksmax - 1) ? ";\n" : ",\n");
129  }
130 }
l1tpf_impl::COEFile::phiSlices
unsigned int phiSlices
Definition: COEFile.h:36
ALCARECOTkAlBeamHalo_cff.etaMin
etaMin
GeV.
Definition: ALCARECOTkAlBeamHalo_cff.py:32
mps_fire.i
i
Definition: mps_fire.py:428
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11724
l1t::L1Candidate::hwPhi
int hwPhi() const
Definition: L1Candidate.h:37
l1tpf_impl::InputTrack::src
const l1t::PFTrack * src
Definition: DiscretePFInputs.h:90
l1tpf_impl::PropagatedTrack
Definition: DiscretePFInputs.h:119
l1tpf_impl
Definition: BitwisePFAlgo.h:8
l1tpf_impl::InputTrack::hwCharge
bool hwCharge
Definition: DiscretePFInputs.h:86
edm
HLT enums.
Definition: AlignableModifier.h:19
l1tpf_impl::COEFile::debug_
int debug_
Definition: COEFile.h:40
COEFile.h
l1tpf_impl::COEFile::writeTracksToFile
void writeTracksToFile(const std::vector< Region > &regions, bool print=false)
Definition: COEFile.cc:40
l1tpf_impl::COEFile::coeFileName
std::string coeFileName
Definition: COEFile.h:35
l1tpf_impl::PropagatedTrack::hwPt
int16_t hwPt
Definition: DiscretePFInputs.h:120
l1t::L1Candidate::hwEta
int hwEta() const
Definition: L1Candidate.h:36
l1tpf_impl::COEFile::~COEFile
~COEFile()
Definition: COEFile.cc:17
l1tpf_impl::InputTrack::hwChi2
uint16_t hwChi2
Definition: DiscretePFInputs.h:88
l1tpf_impl::COEFile::track_word_block_sizes
const std::vector< uint32_t > track_word_block_sizes
Definition: COEFile.h:39
geometryDiff.file
file
Definition: geometryDiff.py:13
edm::ParameterSet
Definition: ParameterSet.h:47
l1tpf_impl::COEFile::file
FILE * file
Definition: COEFile.h:34
ParameterSet
Definition: Functions.h:16
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
createfilelist.int
int
Definition: createfilelist.py:10
reco::LeafCandidate::p4
const LorentzVector & p4() const final
four-momentum Lorentz vector
Definition: LeafCandidate.h:114
l1tpf_impl::InputTrack::hwVtxEta
int32_t hwVtxEta
Definition: DiscretePFInputs.h:84
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
l1tpf_impl::InputTrack::hwVtxPhi
int32_t hwVtxPhi
Definition: DiscretePFInputs.h:85
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
l1tpf_impl::COEFile::COEFile
COEFile(const edm::ParameterSet &)
Definition: COEFile.cc:5
l1tpf_impl::COEFile::tracksize
static constexpr unsigned int tracksize
Definition: COEFile.h:37
l1tpf_impl::InputTrack::hwStubs
uint16_t hwStubs
Definition: DiscretePFInputs.h:88
std
Definition: JetResolutionObject.h:76
l1ParticleFlow_cff.phiSlices
phiSlices
Definition: l1ParticleFlow_cff.py:125
ALCARECOTkAlBeamHalo_cff.etaMax
etaMax
Definition: ALCARECOTkAlBeamHalo_cff.py:33
l1t::L1Candidate::hwPt
int hwPt() const
Definition: L1Candidate.h:35
l1tpf_impl::COEFile::ntracksmax
unsigned int ntracksmax
Definition: COEFile.h:36
AlignmentPI::regions
regions
Definition: AlignmentPayloadInspectorHelper.h:78
l1tpf_impl::COEFile::writeHeaderToFile
void writeHeaderToFile()
Definition: COEFile.cc:19
l1tpf_impl::COEFile::bset_string_
std::string bset_string_
Definition: COEFile.h:35
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
l1tpf_impl::COEFile::bset_
boost::dynamic_bitset bset_
Definition: COEFile.h:38
l1tpf_impl::InputTrack::hwZ0
int16_t hwZ0
Definition: DiscretePFInputs.h:87