CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
PtAssignmentNNRegression Class Reference

#include <PtAssignmentNNRegression.h>

Inheritance diagram for PtAssignmentNNRegression:
PtAssignmentBase

Public Member Functions

std::vector< float > getPts (AlgoMuons::value_type &algoMuon, std::vector< std::unique_ptr< IOMTFEmulationObserver > > &observers) override
 
 PtAssignmentNNRegression (const edm::ParameterSet &edmCfg, const OMTFConfiguration *omtfConfig, std::string networkFile)
 
 ~PtAssignmentNNRegression () override=default
 
- Public Member Functions inherited from PtAssignmentBase
 PtAssignmentBase (const OMTFConfiguration *omtfConfig)
 
virtual ~PtAssignmentBase ()
 

Private Attributes

unique_ptr< lutNN::LutNetworkFixedPointRegressionBaselutNetworkFP
 

Additional Inherited Members

- Protected Attributes inherited from PtAssignmentBase
const OMTFConfigurationomtfConfig = nullptr
 

Detailed Description

Definition at line 14 of file PtAssignmentNNRegression.h.

Constructor & Destructor Documentation

◆ PtAssignmentNNRegression()

PtAssignmentNNRegression::PtAssignmentNNRegression ( const edm::ParameterSet edmCfg,
const OMTFConfiguration omtfConfig,
std::string  networkFile 
)

Definition at line 79 of file PtAssignmentNNRegression.cc.

References lutNetworkFP.

82  : PtAssignmentBase(omtfConfig), lutNetworkFP(make_unique<lutNN::LutNetworkFP>()) {
83  std::ifstream ifs(networkFile);
84 
85  edm::LogImportant("OMTFReconstruction")
86  << " " << __FUNCTION__ << ":" << __LINE__ << " networkFile " << networkFile << std::endl;
87 
88  lutNetworkFP->load(networkFile);
89 
90  edm::LogImportant("OMTFReconstruction") << " " << __FUNCTION__ << ":" << __LINE__ << std::endl;
91 }
const OMTFConfiguration * omtfConfig
PtAssignmentBase(const OMTFConfiguration *omtfConfig)
unique_ptr< lutNN::LutNetworkFixedPointRegressionBase > lutNetworkFP
Log< level::Error, true > LogImportant

◆ ~PtAssignmentNNRegression()

PtAssignmentNNRegression::~PtAssignmentNNRegression ( )
overridedefault

Member Function Documentation

◆ getPts()

std::vector< float > PtAssignmentNNRegression::getPts ( AlgoMuons::value_type &  algoMuon,
std::vector< std::unique_ptr< IOMTFEmulationObserver > > &  observers 
)
overridevirtual

Implements PtAssignmentBase.

Definition at line 169 of file PtAssignmentNNRegression.cc.

References CSCDetId::chamber(), MuonSubdetId::CSC, hcalRecHitTable_cff::detId, alignBH_cfg::fixed, OMTFConfiguration::getRefToLogicNumber(), mps_fire::i, PixelMapPlotter::inputs, createfilelist::int, OMTFConfiguration::isBendingLayer(), LogTrace, lutNetworkFP, PtAssignmentBase::omtfConfig, omtfHitToEventInput(), DiDispStaMuonMonitor_cfi::pt, RPCpg::pts, and hit::z.

170  {
171  LogTrace("l1tOmtfEventPrint") << " " << __FUNCTION__ << ":" << __LINE__ << std::endl;
172  auto& gpResult = algoMuon->getGpResultConstr();
173  //int pdfMiddle = 1<<(omtfConfig->nPdfAddrBits()-1);
174 
175  LogTrace("l1tOmtfEventPrint") << " " << __FUNCTION__ << ":" << __LINE__ << std::endl;
176  /*
177  edm::LogVerbatim("l1tOmtfEventPrint")<<"DataROOTDumper2:;observeEventEnd muonPt "<<event.muonPt<<" muonCharge "<<event.muonCharge
178  <<" omtfPt "<<event.omtfPt<<" RefLayer "<<event.omtfRefLayer<<" omtfPtCont "<<event.omtfPtCont
179  <<std::endl;
180 */
181 
182  unsigned int inputCnt = 18; //TDOO!!!!!
183  unsigned int outputCnt = 2;
184  const float noHitVal = 1023.;
185 
186  //edm::LogImportant("OMTFReconstruction") <<"\n----------------------"<<endl;
187  //edm::LogImportant("OMTFReconstruction") <<(*algoMuon)<<std::endl;
188 
189  std::vector<float> inputs(inputCnt, noHitVal);
190 
191  for (unsigned int iLogicLayer = 0; iLogicLayer < gpResult.getStubResults().size(); ++iLogicLayer) {
192  auto& stubResult = gpResult.getStubResults()[iLogicLayer];
193  if (stubResult.getMuonStub()) { //&& stubResult.getValid() //TODO!!!!!!!!!!!!!!!!1
194  int hitPhi = stubResult.getMuonStub()->phiHw;
195  unsigned int refLayerLogicNum = omtfConfig->getRefToLogicNumber()[algoMuon->getRefLayer()];
196  int phiRefHit = gpResult.getStubResults()[refLayerLogicNum].getMuonStub()->phiHw;
197 
198  if (omtfConfig->isBendingLayer(iLogicLayer)) {
199  hitPhi = stubResult.getMuonStub()->phiBHw;
200  phiRefHit = 0; //phi ref hit for the banding layer set to 0, since it should not be included in the phiDist
201  }
202 
203  OmtfHit hit(0);
204 
205  hit.layer = iLogicLayer;
206  hit.quality = stubResult.getMuonStub()->qualityHw;
207  hit.eta = stubResult.getMuonStub()->etaHw; //in which scale?
208  hit.valid = stubResult.getValid();
209 
210  //phiDist = hitPhi - phiRefHit;
211  hit.phiDist = hitPhi - phiRefHit;
212 
213  /*
214  LogTrace("l1tOmtfEventPrint") <<" muonPt "<<event.muonPt<<" omtfPt "<<event.omtfPt<<" RefLayer "<<event.omtfRefLayer
215  <<" layer "<<int(hit.layer)<<" PdfBin "<<stubResult.getPdfBin()<<" hit.phiDist "<<hit.phiDist<<" valid "<<stubResult.getValid()<<" " //<<" phiDist "<<phiDist
216  <<" getDistPhiBitShift "<<omtfCand->getGoldenPatern()->getDistPhiBitShift(iLogicLayer, omtfCand->getRefLayer())
217  <<" meanDistPhiValue "<<omtfCand->getGoldenPatern()->meanDistPhiValue(iLogicLayer, omtfCand->getRefLayer())//<<(phiDist != hit.phiDist? "!!!!!!!<<<<<" : "")
218  <<endl;*/
219 
220  if (hit.phiDist > 504 || hit.phiDist < -512) {
221  edm::LogVerbatim("l1tOmtfEventPrint")
222  //<<" muonPt "<<event.muonPt<<" omtfPt "<<event.omtfPt<<" RefLayer "<<event.omtfRefLayer
223  << " layer " << int(hit.layer) << " hit.phiDist " << hit.phiDist << " valid " << stubResult.getValid()
224  << " !!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
225  }
226 
227  DetId detId(stubResult.getMuonStub()->detId);
228  if (detId.subdetId() == MuonSubdetId::CSC) {
229  CSCDetId cscId(detId);
230  hit.z = cscId.chamber() % 2;
231  }
232 
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;
236 
237  omtfHitToEventInput(hit, inputs, algoMuon->getRefLayer(), false);
238  }
239  }
240 
241  LogTrace("l1tOmtfEventPrint") << " " << __FUNCTION__ << ":" << __LINE__ << std::endl;
242 
243  std::vector<double> nnResult(outputCnt);
244  lutNetworkFP->run(inputs, noHitVal, nnResult);
245 
246  LogTrace("l1tOmtfEventPrint") << " " << __FUNCTION__ << ":" << __LINE__ << std::endl;
247 
248  double pt = std::copysign(nnResult.at(0), nnResult.at(1));
249 
250  LogTrace("l1tOmtfEventPrint") << " " << __FUNCTION__ << ":" << __LINE__ << " nnResult.at(0) " << nnResult.at(0)
251  << " nnResult.at(1) " << nnResult.at(1) << " pt " << pt << std::endl;
252 
253  std::vector<float> pts;
254  pts.emplace_back(pt);
255 
256  //algoMuon->setPtNN(omtfConfig->ptGevToHw(nnResult.at(0)));
257  auto calibratedHwPt = lutNetworkFP->getCalibratedHwPt();
258  algoMuon->setPtNNConstr(calibratedHwPt);
259 
260  algoMuon->setChargeNNConstr(nnResult[1] >= 0 ? 1 : -1);
261 
262  //TODO add some if here, such that the property_tree is filled only when needed
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]);
268  }
269 
270  std::ostringstream ostr;
271  ostr << std::fixed << std::setprecision(19) << nnResult.at(0);
272  procDataTree.add("output0.<xmlattr>.val", ostr.str());
273 
274  ostr.str("");
275  ostr << std::fixed << std::setprecision(19) << nnResult.at(1);
276  procDataTree.add("output1.<xmlattr>.val", ostr.str());
277 
278  procDataTree.add("calibratedHwPt.<xmlattr>.val", calibratedHwPt);
279 
280  procDataTree.add("hwSign.<xmlattr>.val", algoMuon->getChargeNNConstr() < 0 ? 1 : 0);
281 
282  for (auto& obs : observers)
283  obs->addProcesorData("regressionNN", procDataTree);
284 
285  return pts;
286 
287  //event.print();
288  /*
289  std::vector<float> pts(classifierToRegressions.size(), 0);
290 
291  unsigned int i =0;
292  for(auto& classifierToRegression : classifierToRegressions) {
293  auto orgValue = classifierToRegression->getValue(&event);
294  auto absOrgValue = std::abs(orgValue);
295  pts.at(i) = classifierToRegression->getCalibratedValue(absOrgValue);
296  pts.at(i) = std::copysign(pts.at(i), orgValue);
297 
298  LogTrace("OMTFReconstruction") <<" "<<__FUNCTION__<<":"<<__LINE__<<" orgValue "<<orgValue<<" pts["<<i<<"] "<<pts[i]<<std::endl;
299  //std::cout<<"nn pts["<<i<<"] "<<pts[i]<< std::endl;
300  i++;
301  }
302 
303  return pts;*/
304 }
Log< level::Info, true > LogVerbatim
const OMTFConfiguration * omtfConfig
unique_ptr< lutNN::LutNetworkFixedPointRegressionBase > lutNetworkFP
bool omtfHitToEventInput(OmtfHit &hit, std::vector< float > &inputs, unsigned int omtfRefLayer, bool print)
#define LogTrace(id)
static const double pts[33]
Definition: Constants.h:30
const std::vector< int > & getRefToLogicNumber() const
Definition: DetId.h:17
static constexpr int CSC
Definition: MuonSubdetId.h:12
bool isBendingLayer(unsigned int iLayer) const override

Member Data Documentation

◆ lutNetworkFP

unique_ptr<lutNN::LutNetworkFixedPointRegressionBase> PtAssignmentNNRegression::lutNetworkFP
private

Definition at line 25 of file PtAssignmentNNRegression.h.

Referenced by getPts(), and PtAssignmentNNRegression().