16 #include <boost/archive/text_oarchive.hpp> 17 #include <boost/archive/text_iarchive.hpp> 18 #include <boost/algorithm/string/replace.hpp> 83 std::ifstream ifs(networkFile);
86 <<
" " << __FUNCTION__ <<
":" << __LINE__ <<
" networkFile " << networkFile << std::endl;
90 edm::LogImportant(
"OMTFReconstruction") <<
" " << __FUNCTION__ <<
":" << __LINE__ << std::endl;
111 float offset = (omtfRefLayer << 7) + 64;
114 if ((
hit.layer == 1 ||
hit.layer == 3 ||
hit.layer == 5) &&
hit.quality < 4)
118 if (
hit.layer == 1) {
124 else if (
hit.layer == 3) {
126 }
else if (
hit.layer == 9) {
138 <<
" RefLayer " << omtfRefLayer <<
" layer " <<
int(
hit.layer) <<
" hit.phiDist " <<
hit.phiDist <<
" valid " 139 << ((short)
hit.valid) <<
" !!!!!!!!!!!!!!!!!!!!!!!!" << endl;
140 hit.phiDist = copysign(63 * rangeFactor,
hit.phiDist);
153 <<
" phiDist " <<
hit.phiDist <<
" inputVal " <<
inputs.at(
hit.layer) <<
" hit.z " <<
int(
hit.
z) <<
" valid " 154 << ((short)
hit.valid) <<
" quality " << (short)
hit.quality <<
" omtfRefLayer " << omtfRefLayer;
156 edm::LogImportant(
"OMTFReconstruction") <<
" event->inputs.at(hit.layer) < 0 !!!!!!!!!!!!!!!!!" << endl;
161 edm::LogImportant(
"OMTFReconstruction") <<
" event->inputs[hit.layer] >= 1024 !!!!!!!!!!!!!!!!!" << endl;
170 std::vector<std::unique_ptr<IOMTFEmulationObserver>>& observers) {
171 LogTrace(
"l1tOmtfEventPrint") <<
" " << __FUNCTION__ <<
":" << __LINE__ << std::endl;
172 auto& gpResult = algoMuon->getGpResultConstr();
175 LogTrace(
"l1tOmtfEventPrint") <<
" " << __FUNCTION__ <<
":" << __LINE__ << std::endl;
182 unsigned int inputCnt = 18;
183 unsigned int outputCnt = 2;
184 const float noHitVal = 1023.;
189 std::vector<float>
inputs(inputCnt, noHitVal);
191 for (
unsigned int iLogicLayer = 0; iLogicLayer < gpResult.getStubResults().size(); ++iLogicLayer) {
192 auto& stubResult = gpResult.getStubResults()[iLogicLayer];
193 if (stubResult.getMuonStub()) {
194 int hitPhi = stubResult.getMuonStub()->phiHw;
196 int phiRefHit = gpResult.getStubResults()[refLayerLogicNum].getMuonStub()->phiHw;
199 hitPhi = stubResult.getMuonStub()->phiBHw;
205 hit.layer = iLogicLayer;
206 hit.quality = stubResult.getMuonStub()->qualityHw;
207 hit.eta = stubResult.getMuonStub()->etaHw;
208 hit.valid = stubResult.getValid();
211 hit.phiDist = hitPhi - phiRefHit;
220 if (
hit.phiDist > 504 ||
hit.phiDist < -512) {
223 <<
" layer " <<
int(
hit.layer) <<
" hit.phiDist " <<
hit.phiDist <<
" valid " << stubResult.getValid()
224 <<
" !!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
233 LogTrace(
"l1tOmtfEventPrint") <<
"hit: layer " << (
int)
hit.layer <<
" quality " << (
int)
hit.quality <<
" eta " 234 << (
int)
hit.eta <<
" valid " << (
int)
hit.valid <<
" phiDist " << (
int)
hit.phiDist
235 <<
" z " << (
int)
hit.
z << std::endl;
241 LogTrace(
"l1tOmtfEventPrint") <<
" " << __FUNCTION__ <<
":" << __LINE__ << std::endl;
243 std::vector<double> nnResult(outputCnt);
246 LogTrace(
"l1tOmtfEventPrint") <<
" " << __FUNCTION__ <<
":" << __LINE__ << std::endl;
248 double pt = std::copysign(nnResult.at(0), nnResult.at(1));
250 LogTrace(
"l1tOmtfEventPrint") <<
" " << __FUNCTION__ <<
":" << __LINE__ <<
" nnResult.at(0) " << nnResult.at(0)
251 <<
" nnResult.at(1) " << nnResult.at(1) <<
" pt " <<
pt << std::endl;
253 std::vector<float>
pts;
254 pts.emplace_back(
pt);
257 auto calibratedHwPt =
lutNetworkFP->getCalibratedHwPt();
258 algoMuon->setPtNNConstr(calibratedHwPt);
260 algoMuon->setChargeNNConstr(nnResult[1] >= 0 ? 1 : -1);
263 boost::property_tree::ptree procDataTree;
264 for (
unsigned int i = 0;
i <
inputs.size();
i++) {
265 auto& inputTree = procDataTree.add(
"input",
"");
266 inputTree.add(
"<xmlattr>.num",
i);
267 inputTree.add(
"<xmlattr>.val",
inputs[
i]);
270 std::ostringstream ostr;
271 ostr <<
std::fixed << std::setprecision(19) << nnResult.at(0);
272 procDataTree.add(
"output0.<xmlattr>.val", ostr.str());
275 ostr <<
std::fixed << std::setprecision(19) << nnResult.at(1);
276 procDataTree.add(
"output1.<xmlattr>.val", ostr.str());
278 procDataTree.add(
"calibratedHwPt.<xmlattr>.val", calibratedHwPt);
280 procDataTree.add(
"hwSign.<xmlattr>.val", algoMuon->getChargeNNConstr() < 0 ? 1 : 0);
282 for (
auto& obs : observers)
283 obs->addProcesorData(
"regressionNN", procDataTree);
Log< level::Info, true > LogVerbatim
static constexpr int output1_F
const OMTFConfiguration * omtfConfig
std::vector< float > getPts(AlgoMuons::value_type &algoMuon, std::vector< std::unique_ptr< IOMTFEmulationObserver > > &observers) override
static constexpr int layer3_1_inputCnt
unique_ptr< lutNN::LutNetworkFixedPointRegressionBase > lutNetworkFP
static constexpr int layer1_neurons
static constexpr int output1_I
static constexpr int layer2_lut_I
bool omtfHitToEventInput(OmtfHit &hit, std::vector< float > &inputs, unsigned int omtfRefLayer, bool print)
static constexpr int layer1_lut_F
static const double pts[33]
static constexpr int layer3_0_lut_I
Container::value_type value_type
static constexpr int layer3_1_lut_I
OmtfHit(unsigned long rawData)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Abs< T >::type abs(const T &t)
Log< level::Error, true > LogImportant
const std::vector< int > & getRefToLogicNumber() const
static constexpr int input_I
static constexpr int layer3_0_lut_F
static constexpr int layer1_output_I
PtAssignmentNNRegression(const edm::ParameterSet &edmCfg, const OMTFConfiguration *omtfConfig, std::string networkFile)
LutNetworkFixedPointRegression2Outputs< input_I, input_F, networkInputSize, layer1_lut_I, layer1_lut_F, layer1_neurons, layer1_output_I, layer2_input_I, layer2_lut_I, layer2_lut_F, layer2_neurons, layer3_input_I, layer3_0_inputCnt, layer3_0_lut_I, layer3_0_lut_F, output0_I, output0_F, layer3_1_inputCnt, layer3_1_lut_I, layer3_1_lut_F, output1_I, output1_F > LutNetworkFP
static constexpr int layer2_input_I
static constexpr int layer2_neurons
static constexpr int layer1_lut_I
static constexpr int input_F
static constexpr int layer3_input_I
static constexpr int layer3_0_inputCnt
static constexpr int output0_I
static constexpr int layer2_lut_F
static constexpr int output0_F
static constexpr int layer3_1_lut_F
if(threadIdxLocalY==0 &&threadIdxLocalX==0)
static constexpr std::size_t networkInputSize
bool isBendingLayer(unsigned int iLayer) const override