CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Member Functions | Protected Attributes
PatternGenerator Class Reference

#include <PatternGenerator.h>

Inheritance diagram for PatternGenerator:
PatternOptimizerBase EmulationObserverBase IOMTFEmulationObserver

Public Member Functions

void endJob () override
 
void observeEventEnd (const edm::Event &iEvent, std::unique_ptr< l1t::RegionalMuonCandBxCollection > &finalCandidates) override
 
 PatternGenerator (const edm::ParameterSet &edmCfg, const OMTFConfiguration *omtfConfig, GoldenPatternVec< GoldenPatternWithStat > &gps, CandidateSimMuonMatcher *candidateSimMuonMatcher)
 
 ~PatternGenerator () override
 
- Public Member Functions inherited from PatternOptimizerBase
void endJob () override
 
void observeEventEnd (const edm::Event &iEvent, std::unique_ptr< l1t::RegionalMuonCandBxCollection > &finalCandidates) override
 
 PatternOptimizerBase (const edm::ParameterSet &edmCfg, const OMTFConfiguration *omtfConfig, GoldenPatternVec< GoldenPatternWithStat > &gps)
 
 ~PatternOptimizerBase () override
 
- Public Member Functions inherited from EmulationObserverBase
 EmulationObserverBase (const edm::ParameterSet &edmCfg, const OMTFConfiguration *omtfConfig)
 
const std::vector< const reco::GenParticle * > findGenMuon (const edm::Event &event)
 
const SimTrackfindSimMuon (const edm::Event &event, const SimTrack *previous=nullptr)
 
void observeEventBegin (const edm::Event &iEvent) override
 
void observeProcesorEmulation (unsigned int iProcessor, l1t::tftype mtfType, const std::shared_ptr< OMTFinput > &input, const AlgoMuons &algoCandidates, const AlgoMuons &gbCandidates, const std::vector< l1t::RegionalMuonCand > &candMuons) override
 
 ~EmulationObserverBase () override
 
- Public Member Functions inherited from IOMTFEmulationObserver
virtual void addProcesorData (std::string key, boost::property_tree::ptree &procDataTree)
 
virtual void beginRun (edm::EventSetup const &eventSetup)
 
 IOMTFEmulationObserver ()
 
virtual void observeProcesorBegin (unsigned int iProcessor, l1t::tftype mtfType)
 
virtual ~IOMTFEmulationObserver ()
 

Protected Member Functions

void groupPatterns ()
 
void initPatternGen ()
 
void modifyClassProb (double step)
 
void reCalibratePt ()
 
void saveHists (TFile &outfile) override
 
void upadatePdfs ()
 
void updateStat ()
 
void updateStatUsingMatcher2 ()
 
- Protected Member Functions inherited from PatternOptimizerBase
virtual double getEventRateWeight (double pt)
 
void printPatterns ()
 
void savePatternsInRoot (std::string rootFileName)
 

Protected Attributes

CandidateSimMuonMatchercandidateSimMuonMatcher = nullptr
 
std::vector< unsigned int > eventCntPerGp
 
std::vector< std::vector< TH2I * > > ptDeltaPhiHists
 
std::function< void()> updateStatFunction
 
- Protected Attributes inherited from PatternOptimizerBase
TH1I * candEta = nullptr
 
GoldenPatternVec< GoldenPatternWithStat > & goldenPatterns
 
TH1I * simMuEta = nullptr
 
TH1I * simMuFoundByOmtfPt = nullptr
 
TH1I * simMuPt = nullptr
 
TH1F * simMuPtSpectrum = nullptr
 
TH2I * simMuPtVsDispl = nullptr
 
TH2I * simMuPtVsRho = nullptr
 
bool writeLayerStat = false
 
- Protected Attributes inherited from EmulationObserverBase
unsigned int candProcIndx = 0
 
edm::ParameterSet edmCfg
 
AlgoMuons::value_type omtfCand
 
const OMTFConfigurationomtfConfig
 
l1t::RegionalMuonCand regionalMuonCand
 
const SimTracksimMuon = nullptr
 

Additional Inherited Members

- Static Public Member Functions inherited from PatternOptimizerBase
static double vxIntegMuRate (double pt_GeV, double dpt, double etaFrom, double etaTo)
 
static double vxMuRate (double pt_GeV)
 

Detailed Description

Definition at line 14 of file PatternGenerator.h.

Constructor & Destructor Documentation

◆ PatternGenerator()

PatternGenerator::PatternGenerator ( const edm::ParameterSet edmCfg,
const OMTFConfiguration omtfConfig,
GoldenPatternVec< GoldenPatternWithStat > &  gps,
CandidateSimMuonMatcher candidateSimMuonMatcher 
)

Definition at line 16 of file PatternGenerator.cc.

References updateStat().

21  updateStatFunction([this]() { updateStat(); }),
23  eventCntPerGp(gps.size(), 0) {
24  edm::LogImportant("l1tOmtfEventPrint") << "constructing PatternGenerator, type: "
25  << edmCfg.getParameter<string>("patternGenerator") << std::endl;
26 
27  if (edmCfg.getParameter<string>("patternGenerator") == "patternGen" ||
28  edmCfg.getParameter<string>("patternGenerator") == "2DHists" ||
29  edmCfg.getParameter<string>("patternGenerator") == "deltaPhiVsPhiRef")
31 
32  //2DHists are done for the displaced muons, then using the propagation for the matching is needed
33  if (edmCfg.getParameter<string>("patternGenerator") == "2DHists" ||
34  edmCfg.getParameter<string>("patternGenerator") == "deltaPhiVsPhiRef")
36 
37  if (edmCfg.exists("simTracksTag") == false)
38  throw cms::Exception("PatternGenerator::PatternGenerator(): no simTracksTag !!!!!!!!!!!!!!!!!");
39 
41  edm::LogImportant("l1tOmtfEventPrint") << "PatternGenerator: candidateSimMuonMatcher is null!!!!!!" << std::endl;
42  }
43 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
CandidateSimMuonMatcher * candidateSimMuonMatcher
bool exists(std::string const &parameterName) const
checks if a parameter exists
Log< level::Error, true > LogImportant
std::function< void()> updateStatFunction
PatternOptimizerBase(const edm::ParameterSet &edmCfg, const OMTFConfiguration *omtfConfig, GoldenPatternVec< GoldenPatternWithStat > &gps)
std::vector< unsigned int > eventCntPerGp
const OMTFConfiguration * omtfConfig

◆ ~PatternGenerator()

PatternGenerator::~PatternGenerator ( )
override

Definition at line 45 of file PatternGenerator.cc.

45 {}

Member Function Documentation

◆ endJob()

void PatternGenerator::endJob ( void  )
overridevirtual

Implements IOMTFEmulationObserver.

Definition at line 341 of file PatternGenerator.cc.

References EmulationObserverBase::edmCfg, PatternOptimizerBase::endJob(), eventCntPerGp, contentValuesFiles::fullPath, edm::ParameterSet::getParameter(), PatternOptimizerBase::goldenPatterns, runTauDisplay::gp, watchdog::group, groupPatterns(), testHGCalDigi_cfg::inFile, modifyClassProb(), reCalibratePt(), CSCSkim_cfi::rootFileName, AlCaHLTBitMon_QueryRunRegistry::string, upadatePdfs(), and PatternOptimizerBase::writeLayerStat.

341  {
342  if (edmCfg.getParameter<string>("patternGenerator") == "modifyClassProb")
343  modifyClassProb(1);
344  else if (edmCfg.getParameter<string>("patternGenerator") == "groupPatterns")
345  groupPatterns();
346  else if (edmCfg.getParameter<string>("patternGenerator") == "patternGen") {
347  upadatePdfs();
348  writeLayerStat = true;
349  } else if (edmCfg.getParameter<string>("patternGenerator") == "2DHists") {
350  upadatePdfs();
351  writeLayerStat = true;
352  } else if (edmCfg.getParameter<string>("patternGenerator") == "deltaPhiVsPhiRef") {
353  upadatePdfs();
354  writeLayerStat = true;
355  } else if (edmCfg.getParameter<string>("patternGenerator") == "patternGenFromStat") {
357  edm::LogImportant("l1tOmtfEventPrint") << "PatternGenerator::endJob() rootFileName " << rootFileName << std::endl;
358  TFile inFile(rootFileName.c_str());
359  TDirectory* curDir = (TDirectory*)inFile.Get("layerStats");
360 
361  ostringstream ostrName;
362  for (auto& gp : goldenPatterns) {
363  if (gp->key().thePt == 0)
364  continue;
365 
366  for (unsigned int iLayer = 0; iLayer < gp->getPdf().size(); ++iLayer) {
367  for (unsigned int iRefLayer = 0; iRefLayer < gp->getPdf()[iLayer].size(); ++iRefLayer) {
368  ostrName.str("");
369  ostrName << "histLayerStat_PatNum_" << gp->key().theNumber << "_refLayer_" << iRefLayer << "_Layer_"
370  << iLayer;
371 
372  TH1I* histLayerStat = (TH1I*)curDir->Get(ostrName.str().c_str());
373 
374  if (histLayerStat) {
375  int statBinsCnt = 1024 * 2;
376  if ((int)(gp->getStatistics()[iLayer][iRefLayer].size()) != histLayerStat->GetNbinsX()) {
377  statBinsCnt = histLayerStat->GetNbinsX();
378  gp->iniStatisitics(statBinsCnt, 1); //TODO
379  edm::LogImportant("l1tOmtfEventPrint")
380  << "PatternGenerator::endJob() - " << ostrName.str() << "statBinsCnt = " << statBinsCnt << std::endl;
381  }
382 
383  for (int iBin = 0; iBin < statBinsCnt; iBin++) {
384  gp->updateStat(iLayer, iRefLayer, iBin, 0, histLayerStat->GetBinContent(iBin + 1));
385  }
386  } else {
387  edm::LogImportant("l1tOmtfEventPrint")
388  << "PatternGenerator::endJob() - reading histLayerStat: histogram not found " << ostrName.str()
389  << std::endl;
390  }
391  }
392  }
393  }
394 
395  TH1* simMuFoundByOmtfPt_fromFile = (TH1*)inFile.Get("simMuFoundByOmtfPt");
396  for (unsigned int iGp = 0; iGp < eventCntPerGp.size(); iGp++) {
397  eventCntPerGp[iGp] = simMuFoundByOmtfPt_fromFile->GetBinContent(simMuFoundByOmtfPt_fromFile->FindBin(iGp));
398  edm::LogImportant("l1tOmtfEventPrint")
399  << "PatternGenerator::endJob() - eventCntPerGp: iGp" << iGp << " - " << eventCntPerGp[iGp] << std::endl;
400  }
401 
402  //TODO chose the desired grouping ///////////////
403  int group = 0;
404  int indexInGroup = 0;
405  for (auto& gp : goldenPatterns) {
406  indexInGroup++;
407  gp->key().setGroup(group);
408  gp->key().setIndexInGroup(indexInGroup);
409  //indexInGroup is counted from 1
410 
411  edm::LogImportant("l1tOmtfEventPrint")
412  << "setGroup(group): group " << group << " indexInGroup " << indexInGroup << std::endl;
413 
414  if (gp->key().thePt <= 10 && indexInGroup == 2) { //TODO
415  indexInGroup = 0;
416  group++;
417  }
418 
419  if (gp->key().thePt > 10 && indexInGroup == 4) { //TODO
420  indexInGroup = 0;
421  group++;
422  }
423  }
424 
425  upadatePdfs();
426 
427  modifyClassProb(1);
428 
429  //groupPatterns(); IMPORTANT don't call grouping here, just set the groups above!!!!
430 
431  reCalibratePt();
432  this->writeLayerStat = true;
433  }
434 
436 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
Log< level::Error, true > LogImportant
void modifyClassProb(double step)
GoldenPatternVec< GoldenPatternWithStat > & goldenPatterns
std::vector< unsigned int > eventCntPerGp

◆ groupPatterns()

void PatternGenerator::groupPatterns ( )
protected

Definition at line 806 of file PatternGenerator.cc.

References OMTFConfiguration::getPatternGroups(), OMTFConfiguration::getRefToLogicNumber(), PatternOptimizerBase::goldenPatterns, runTauDisplay::gp, watchdog::group, mps_fire::i, createfilelist::int, OMTFConfiguration::nPdfAddrBits(), EmulationObserverBase::omtfConfig, and edm::shift.

Referenced by endJob().

806  {
807  int group = 0;
808  int indexInGroup = 0;
809  for (auto& gp : goldenPatterns) {
810  indexInGroup++;
811  gp->key().setGroup(group);
812  gp->key().setIndexInGroup(indexInGroup);
813  //indexInGroup is counted from 1
814 
815  edm::LogImportant("l1tOmtfEventPrint")
816  << "setGroup(group): group " << group << " indexInGroup " << indexInGroup << std::endl;
817 
818  if (gp->key().thePt <= 12 && indexInGroup == 2) { //TODO
819  indexInGroup = 0;
820  group++;
821  }
822 
823  if (gp->key().thePt > 12 && indexInGroup == 4) { //TODO
824  indexInGroup = 0;
825  group++;
826  }
827  }
828 
830  edm::LogImportant("l1tOmtfEventPrint") << "patternGroups:" << std::endl;
831  for (unsigned int iGroup = 0; iGroup < patternGroups.size(); iGroup++) {
832  edm::LogImportant("l1tOmtfEventPrint") << "patternGroup " << std::setw(2) << iGroup << " ";
833  for (unsigned int i = 0; i < patternGroups[iGroup].size(); i++) {
834  edm::LogImportant("l1tOmtfEventPrint") << i << " patNum " << patternGroups[iGroup][i] << " ";
835  }
836  edm::LogImportant("l1tOmtfEventPrint") << std::endl;
837  }
838 
839  int pdfBins = exp2(omtfConfig->nPdfAddrBits());
840 
841  for (unsigned int iLayer = 0; iLayer < goldenPatterns.at(0)->getPdf().size(); ++iLayer) {
842  for (unsigned int iRefLayer = 0; iRefLayer < goldenPatterns.at(0)->getPdf()[iLayer].size(); ++iRefLayer) {
843  //unsigned int refLayerLogicNum = omtfConfig->getRefToLogicNumber()[iRefLayer];
844  //if(refLayerLogicNum == iLayer)
845  {
846  //averaging the meanDistPhi for the gp belonging to the same group
847  for (unsigned int iGroup = 0; iGroup < patternGroups.size(); iGroup++) {
848  double meanDistPhi = 0;
849  int mergedCnt = 0;
850  for (unsigned int i = 0; i < patternGroups[iGroup].size(); i++) {
851  auto gp = goldenPatterns.at(patternGroups[iGroup][i]).get();
852  meanDistPhi += gp->meanDistPhiValue(iLayer, iRefLayer);
853  if (gp->meanDistPhiValue(iLayer, iRefLayer) != 0)
854  mergedCnt++;
855  edm::LogImportant("l1tOmtfEventPrint")
856  << __FUNCTION__ << ": " << __LINE__ << " iGroup " << iGroup << " numInGroup " << i << " " << gp->key()
857  << " iLayer " << iLayer << " iRefLayer " << iRefLayer << " old meanDistPhiValue "
858  << gp->meanDistPhiValue(iLayer, iRefLayer) << endl;
859  }
860 
861  if (mergedCnt) {
862  meanDistPhi /= mergedCnt;
863  meanDistPhi = (int)meanDistPhi;
864 
865  //because for some gps the statistics can be too low, and then the meanDistPhiValue is 0, so it should not contribute
866  for (unsigned int i = 0; i < patternGroups[iGroup].size(); i++) {
867  auto gp = goldenPatterns.at(patternGroups[iGroup][i]).get();
868  unsigned int refLayerLogicNum = omtfConfig->getRefToLogicNumber()[iRefLayer];
869  if (refLayerLogicNum != iLayer) {
870  int shift = meanDistPhi - gp->meanDistPhiValue(iLayer, iRefLayer);
871  edm::LogImportant("l1tOmtfEventPrint")
872  << __FUNCTION__ << ": " << __LINE__ << " iGroup " << iGroup << " numInGroup " << i << " "
873  << gp->key() << " iLayer " << iLayer << " iRefLayer " << iRefLayer
874  << " new meanDistPhi after averaging " << meanDistPhi << " old meanDistPhiValue "
875  << gp->meanDistPhiValue(iLayer, iRefLayer) << " shift " << shift << endl;
876 
877  if (shift < 0) {
878  for (int iBin = 1 - shift; iBin < pdfBins;
879  iBin++) { //iBin = 0 i.e. no hit is included here, to have the proper norm
880  auto pdfVal = gp->pdfValue(iLayer, iRefLayer, iBin);
881  gp->setPdfValue(pdfVal, iLayer, iRefLayer, iBin + shift);
882  edm::LogImportant("l1tOmtfEventPrint")
883  << " iBin " << iBin << " iBin + shift " << iBin + shift << " pdfVal " << pdfVal << endl;
884  }
885  for (int iBin = pdfBins + shift; iBin < pdfBins; iBin++) {
886  gp->setPdfValue(0, iLayer, iRefLayer, iBin);
887  }
888  } else if (shift > 0) {
889  for (int iBin = pdfBins - 1 - shift; iBin > 0;
890  iBin--) { //iBin = 0 i.e. no hit is included here, to have the proper norm
891  auto pdfVal = gp->pdfValue(iLayer, iRefLayer, iBin);
892  gp->setPdfValue(pdfVal, iLayer, iRefLayer, iBin + shift);
893  edm::LogImportant("l1tOmtfEventPrint")
894  << " iBin " << iBin << " iBin + shift " << iBin + shift << " pdfVal " << pdfVal << endl;
895  }
896  for (int iBin = shift; iBin > 0; iBin--) {
897  gp->setPdfValue(0, iLayer, iRefLayer, iBin);
898  }
899  }
900  }
901 
902  gp->setMeanDistPhiValue(round(meanDistPhi), iLayer, iRefLayer);
903  }
904  }
905  }
906  }
907  }
908  }
909 }
std::vector< vector1D > vector2D
unsigned int nPdfAddrBits() const
Log< level::Error, true > LogImportant
const std::vector< int > & getRefToLogicNumber() const
GoldenPatternVec< GoldenPatternWithStat > & goldenPatterns
static unsigned int const shift
vector2D getPatternGroups(const std::vector< std::unique_ptr< GoldenPatternType > > &goldenPats) const
const OMTFConfiguration * omtfConfig

◆ initPatternGen()

void PatternGenerator::initPatternGen ( )
protected

Definition at line 47 of file PatternGenerator.cc.

References EmulationObserverBase::edmCfg, Exception, edm::ParameterSet::getParameter(), PatternOptimizerBase::goldenPatterns, runTauDisplay::gp, mps_fire::i, OMTFConfiguration::nPhiBins(), OMTFConfiguration::nProcessors(), and EmulationObserverBase::omtfConfig.

47  {
48  //reseting the golden patterns
49  unsigned int i = 0;
50  for (auto& gp : goldenPatterns) {
51  gp->setKeyNumber(i++); //needed if patterns were added
52 
53  if (gp->key().thePt == 0)
54  continue;
55 
56  gp->reset();
57 
58  //1024 x 2048 is the maximum size that fits into 64GB of memory!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
59  int statBinsCnt1 = 1024 * 2; //TODO should be big enough to comprise the pdf tails
60 
61  int statBinsCnt2 = 1; //for normal pattern generation
62 
63  if (edmCfg.getParameter<string>("patternGenerator") == "2DHists")
64  statBinsCnt2 = 1024 * 2;
65  //for 2D distribution, phiB vs phiDist, but if done for 8 ref layers, consumes too much memory
66  else if (edmCfg.getParameter<string>("patternGenerator") == "deltaPhiVsPhiRef")
67  statBinsCnt2 = omtfConfig->nPhiBins() / omtfConfig->nProcessors();
68  //for 2D distribution, phiB vs phiDist, but if done for 8 ref layers, consumes too much memory
69  //if(statBinsCnt2 > 10 && omtfConfig->nRefLayers() > 2)
70  // throw cms::Exception("PatternGenerator::initPatternGen(): statBinsCnt2 and omtfConfig->nRefLayers() too big, will consume too much memory");
71 
72  gp->iniStatisitics(statBinsCnt1, statBinsCnt2);
73 
74  if (statBinsCnt2 < 10 && sizeof(gp->getStatistics()[0][0][0][0]) < 4) {
75  edm::LogImportant("l1tOmtfEventPrint")
76  << "PatternGenerator::initPatternGen():" << __LINE__ << "sizeof gp statistics "
77  << sizeof(gp->getStatistics()[0][0][0][0]) << std::endl;
78  throw cms::Exception("PatternGenerator::initPatternGen(): getStatistics type is short!!!!");
79  }
80  }
81 
82  edm::LogImportant("l1tOmtfEventPrint") << "PatternGenerator::initPatternGen():" << __LINE__
83  << " goldenPatterns.size() " << goldenPatterns.size() << std::endl;
84 
85  //setting all pdf to 1, this will cause that when the OmtfProcessor process the input, the result will be based only on the number of fired layers,
86  //and then the omtfCand will come from the processor that has the biggest number of fired layers
87  //however, if the GoldenPatternResult::finalise3() is used - which just count the number of muonStubs (but do not check if it is valid, i.e. fired the pdf)
88  // - the below does not matter
89  for (auto& gp : goldenPatterns) {
90  for (unsigned int iLayer = 0; iLayer < gp->getPdf().size(); ++iLayer) {
91  for (unsigned int iRefLayer = 0; iRefLayer < gp->getPdf()[iLayer].size(); ++iRefLayer) {
92  for (unsigned int iBin = 0; iBin < gp->getPdf()[iLayer][iRefLayer].size(); iBin++) {
93  gp->pdfAllRef[iLayer][iRefLayer][iBin] = 1;
94  }
95  }
96  }
97  }
98 
99  //TODO uncomment if filling the ptDeltaPhiHist is needed
100  /* ptDeltaPhiHists.resize(2);
101  for(unsigned int iCharge = 0; iCharge <= 1; iCharge++) {
102  for(unsigned int iLayer = 0; iLayer < omtfConfig->nLayers(); ++iLayer) { //for the moment filing only ref layer, remove whe
103  if(iLayer == 0 || iLayer == 2 || iLayer == 4 || iLayer == 6 || iLayer == 7 || iLayer == 10 || iLayer == 11 || iLayer == 16 || //refLayars
104  iLayer == 1 || iLayer == 3 || iLayer == 5 ) //bending layers
105  {
106  ostringstream name;
107  name<<"ptDeltaPhiHist_ch_"<<iCharge<<"_Layer_"<<iLayer;
108  int phiFrom = -10;
109  int phiTo = 300; //TODO
110  int phiBins = phiTo - phiFrom;
111 
112  if(iCharge == 1) {
113  phiFrom = -300; //TODO
114  phiTo = 10;
115  }
116 
117  TH2I* ptDeltaPhiHist = new TH2I(name.str().c_str(), name.str().c_str(), 400, 0, 200, phiBins, phiFrom -0.5, phiTo -0.5);
118  //cout<<"BinLowEdge "<<ptDeltaPhiHist->GetYaxis()->GetBinLowEdge(100)<<" BinUpEdge "<<ptDeltaPhiHist->GetYaxis()->GetBinUpEdge(100);
119  ptDeltaPhiHists[iCharge].push_back(ptDeltaPhiHist);
120  }
121  else
122  ptDeltaPhiHists[iCharge].push_back(nullptr);
123  }
124  }*/
125 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
unsigned int nPhiBins() const
Log< level::Error, true > LogImportant
GoldenPatternVec< GoldenPatternWithStat > & goldenPatterns
unsigned int nProcessors() const
const OMTFConfiguration * omtfConfig

◆ modifyClassProb()

void PatternGenerator::modifyClassProb ( double  step)
protected

Definition at line 676 of file PatternGenerator.cc.

References OMTFConfiguration::getPatternPtRange(), OMTFConfiguration::getRefToLogicNumber(), PatternOptimizerBase::goldenPatterns, runTauDisplay::gp, dqm-mbProfile::log, OMTFConfiguration::minPdfVal(), OMTFConfiguration::nPdfBins(), EmulationObserverBase::omtfConfig, OMTFConfiguration::pdfMaxValue(), MuonErrorMatrixValues_cff::ptRange, groupFilesInBlocks::reverse, Validation_hcalonly_cfi::sign, and PatternOptimizerBase::vxIntegMuRate().

Referenced by endJob().

676  {
677  edm::LogImportant("l1tOmtfEventPrint") << __FUNCTION__ << ": " << __LINE__ << " Correcting P(C_k) " << std::endl;
678  unsigned int iPdf = omtfConfig->nPdfBins() / 2; // <<(omtfConfig->nPdfAddrBits()-1);
679  for (unsigned int iRefLayer = 0; iRefLayer < goldenPatterns[0]->getPdf()[0].size(); ++iRefLayer) {
680  unsigned int refLayerLogicNumber = omtfConfig->getRefToLogicNumber()[iRefLayer];
681  if (iRefLayer == 0 || iRefLayer == 2) //DT
682  step = 1.5;
683  else if (iRefLayer == 5) //DT
684  step = 1.5;
685  else if (iRefLayer == 1) //CSC
686  step = 1.5;
687  else if (iRefLayer == 3) //CSC
688  step = 1.5;
689  else if (iRefLayer == 5) //RE2/3
690  step = 1.5;
691  else if (iRefLayer == 6 || iRefLayer == 7) //bRPC
692  step = 1.5;
693 
694  edm::LogImportant("l1tOmtfEventPrint")
695  << __FUNCTION__ << ":" << __LINE__ << " RefLayer " << iRefLayer << " step " << step << std::endl;
696  for (int sign = -1; sign <= 1; sign++) {
698  if (gp->key().thePt == 0 || gp->key().theCharge != sign)
699  continue;
700 
701  double ptFrom = omtfConfig->getPatternPtRange(gp->key().theNumber).ptFrom;
702  double ptTo = omtfConfig->getPatternPtRange(gp->key().theNumber).ptTo;
703 
704  double ptRange = ptTo - ptFrom;
705 
706  double minPdfValFactor = 0.1;
707  double minPlog = log(omtfConfig->minPdfVal() * minPdfValFactor);
708  double pdfMaxVal = omtfConfig->pdfMaxValue();
709 
710  pdfMaxVal /= 3.;
711  minPlog *= 2;
712 
713  //last bin of the ptRange goes to 10000, so here we change it to 1000
714  if (ptRange > 800)
715  ptRange = 800;
716 
717  double norm = 0.001;
718  double classProb = vxIntegMuRate(ptFrom, ptRange, 0.82, 1.24) * norm;
719 
720  int digitisedVal = rint(pdfMaxVal - log(classProb) / minPlog * pdfMaxVal);
721 
722  int newPdfVal = digitisedVal; //gp->getPdf()[refLayerLogicNumber][iRefLayer][iPdf]
723  //watch out - the pt here is before re-calibration
724  if (ptFrom == 0)
725  newPdfVal += 15;
726  if (ptFrom == 3.5)
727  newPdfVal += 15;
728  if (ptFrom == 4)
729  newPdfVal += 12;
730  if (ptFrom == 4.5)
731  newPdfVal += 9;
732  if (ptFrom == 5)
733  newPdfVal += 7;
734  if (ptFrom == 6)
735  newPdfVal += 4;
736  if (ptFrom == 7)
737  newPdfVal += 2;
738 
739  //if (ptFrom == 20) //pattern Key_13
740  // newPdfVal += 1;
741  if (ptFrom >= 22 && ptFrom <= 26)
742  newPdfVal += 2;
743  if (ptFrom == 28) //pattern Key_17
744  newPdfVal += 1;
745 
746  if (ptFrom == 100)
747  newPdfVal = 16;
748  if (ptFrom == 200)
749  newPdfVal = 22;
750 
751  gp->setPdfValue(newPdfVal, refLayerLogicNumber, iRefLayer, iPdf);
752 
753  edm::LogImportant("l1tOmtfEventPrint")
754  << gp->key() << " " << omtfConfig->getPatternPtRange(gp->key().theNumber).ptFrom << " - "
755  << omtfConfig->getPatternPtRange(gp->key().theNumber).ptTo << " GeV"
756  << " ptRange " << ptRange << " RefLayer " << iRefLayer << " newPdfVal " << newPdfVal << std::endl;
757  }
758  }
759  }
760 }
int pdfMaxValue() const
static double vxIntegMuRate(double pt_GeV, double dpt, double etaFrom, double etaTo)
Log< level::Error, true > LogImportant
const std::vector< int > & getRefToLogicNumber() const
float minPdfVal() const
GoldenPatternVec< GoldenPatternWithStat > & goldenPatterns
PatternPt getPatternPtRange(unsigned int patNum) const
step
Definition: StallMonitor.cc:83
unsigned int nPdfBins() const
const OMTFConfiguration * omtfConfig

◆ observeEventEnd()

void PatternGenerator::observeEventEnd ( const edm::Event iEvent,
std::unique_ptr< l1t::RegionalMuonCandBxCollection > &  finalCandidates 
)
overridevirtual

Reimplemented from IOMTFEmulationObserver.

Definition at line 326 of file PatternGenerator.cc.

References funct::abs(), iEvent, CoreSimTrack::momentum(), PatternOptimizerBase::observeEventEnd(), EmulationObserverBase::omtfCand, EmulationObserverBase::simMuon, and updateStatFunction.

327  {
328  if (simMuon == nullptr || omtfCand->getGoldenPatern() == nullptr) //no sim muon or empty candidate
329  return;
330 
331  if (abs(simMuon->momentum().eta()) < 0.8 || abs(simMuon->momentum().eta()) > 1.24)
332  return;
333 
335 
336  //updateStat();
337  //updateStatUsingMatcher2();
339 }
AlgoMuons::value_type omtfCand
const math::XYZTLorentzVectorD & momentum() const
Definition: CoreSimTrack.h:19
int iEvent
Definition: GenABIO.cc:224
void observeEventEnd(const edm::Event &iEvent, std::unique_ptr< l1t::RegionalMuonCandBxCollection > &finalCandidates) override
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::function< void()> updateStatFunction

◆ reCalibratePt()

void PatternGenerator::reCalibratePt ( )
protected

Definition at line 762 of file PatternGenerator.cc.

References PatternOptimizerBase::goldenPatterns, runTauDisplay::gp, EmulationObserverBase::omtfConfig, and OMTFConfiguration::ptGevToHw().

Referenced by endJob().

762  {
763  edm::LogImportant("l1tOmtfEventPrint") << __FUNCTION__ << ": " << __LINE__ << " reCalibratePt" << std::endl;
764  std::map<int, float> ptMap;
765  //for Patterns_0x0009_oldSample_3_10Files_classProb2.xml
766  ptMap[7] = 4.0;
767  ptMap[8] = 4.5;
768  ptMap[9] = 5.0;
769  ptMap[10] = 5.5;
770  ptMap[11] = 6.0;
771  ptMap[13] = 7.0;
772  ptMap[15] = 8.5;
773  ptMap[17] = 10.0;
774  ptMap[21] = 12.0;
775  ptMap[25] = 14.0;
776  ptMap[29] = 16.0;
777  ptMap[33] = 18.5;
778  ptMap[37] = 21.0;
779  ptMap[41] = 23.0;
780  ptMap[45] = 26.0;
781  ptMap[49] = 28.0;
782  ptMap[53] = 30.0;
783  ptMap[57] = 32.0;
784  ptMap[61] = 36.0;
785  ptMap[71] = 40.0;
786  ptMap[81] = 48.0;
787  ptMap[91] = 54.0;
788  ptMap[101] = 60.0;
789  ptMap[121] = 70.0;
790  ptMap[141] = 82.0;
791  ptMap[161] = 96.0;
792  ptMap[201] = 114.0;
793  ptMap[401] = 200.0;
794 
795  for (auto& gp : goldenPatterns) {
796  if (gp->key().thePt == 0)
797  continue;
798 
799  int newPt = omtfConfig->ptGevToHw(ptMap[gp->key().thePt]);
800  edm::LogImportant("l1tOmtfEventPrint") << gp->key().thePt << " -> " << newPt << std::endl;
801 
802  gp->key().setPt(newPt);
803  }
804 }
Log< level::Error, true > LogImportant
int ptGevToHw(double ptGev) const override
uGMT pt scale conversion: [0GeV, 0.5GeV) = 1 [0.5GeV, 1 Gev) = 2
GoldenPatternVec< GoldenPatternWithStat > & goldenPatterns
const OMTFConfiguration * omtfConfig

◆ saveHists()

void PatternGenerator::saveHists ( TFile &  outfile)
overrideprotectedvirtual

Reimplemented from PatternOptimizerBase.

Definition at line 664 of file PatternGenerator.cc.

References timingPdfMaker::outfile.

664  {
665  outfile.mkdir("ptDeltaPhiHists")->cd();
666  //TODO uncomment if ptDeltaPhiHists are needed
667  /* for(unsigned int iCharge = 0; iCharge <= 1; iCharge++) {
668  for(unsigned int iLayer = 0; iLayer < omtfConfig->nLayers(); ++iLayer) { //for the moment filing only ref layer, remove whe
669  if(ptDeltaPhiHists[iCharge][iLayer]) {
670  ptDeltaPhiHists[iCharge][iLayer]->Write();
671  }
672  }
673  }*/
674 }

◆ upadatePdfs()

void PatternGenerator::upadatePdfs ( )
protected

weighted average, weight is 1/pt

Definition at line 438 of file PatternGenerator.cc.

References submitPVResolutionJobs::count, eventCntPerGp, OMTFConfiguration::getPatternGroups(), PatternOptimizerBase::goldenPatterns, runTauDisplay::gp, mps_fire::i, createfilelist::int, dqm-mbProfile::log, OMTFConfiguration::minPdfVal(), EmulationObserverBase::omtfConfig, OMTFConfiguration::pdfMaxValue(), to_string(), and mps_merge::weight.

Referenced by endJob().

438  {
439  //TODO setting the DistPhiBitShift i.e. grouping of the pdfBins
440  for (auto& gp : goldenPatterns) {
441  if (gp->key().thePt == 0)
442  continue;
443  for (unsigned int iLayer = 0; iLayer < gp->getPdf().size(); ++iLayer) {
444  for (unsigned int iRefLayer = 0; iRefLayer < gp->getPdf()[iLayer].size(); ++iRefLayer) {
445  if (gp->getDistPhiBitShift(iLayer, iRefLayer)) {
446  throw runtime_error(
447  string(__FUNCTION__) + ":" + to_string(__LINE__) +
448  "gp->getDistPhiBitShift(iLayer, iRefLayer) != 0 - cannot change DistPhiBitShift then!!!!");
449  }
450 
451  //watch out - the pt here is the hardware pt before the recalibration
452  //the shift for given pattern and layer should be the same same for all refLayers
453  //otherwise the firmware does not compile - at least the phase-1
454  //for phase2
455  /*if ((gp->key().thePt <= 10) &&
456  (iLayer == 1 || iLayer == 3 || iLayer == 5)) { //iRefLayer: MB2, iLayer: MB1 and MB2 phiB
457  gp->setDistPhiBitShift(2, iLayer, iRefLayer);
458  } else if ((gp->key().thePt <= 10) && (iLayer == 10)) { //iRefLayer: MB2, iLayer: RB1_in
459  gp->setDistPhiBitShift(1, iLayer, iRefLayer);
460  } else if ((gp->key().thePt >= 11 && gp->key().thePt <= 17) && (iLayer == 1)) { //MB1 phiB
461  //due to grouping the patterns 4-7, the pdfs for the layer 1 in the pattern go outside of the range
462  //so the shift must be increased (or the group should be divided into to 2 groups, but it will increase fw occupancy
463  gp->setDistPhiBitShift(2, iLayer, iRefLayer);
464  } else if ((gp->key().thePt >= 11 && gp->key().thePt <= 17) && (iLayer == 3 || iLayer == 5)) { //MB1 phiB
465  //due to grouping the patterns 4-7, the pdfs for the layer 1 in the pattern go outside of the range
466  //so the shift must be increased (or the group should be divided into to 2 groups, but it will increase fw occupancy
467  gp->setDistPhiBitShift(1, iLayer, iRefLayer);
468  } else
469  gp->setDistPhiBitShift(0, iLayer, iRefLayer);*/
470 
471  //for phase1
472  if ((gp->key().thePt <= 8) &&
473  (iLayer == 1 || iLayer == 3 || iLayer == 5)) { //iRefLayer: MB2, iLayer: MB1 and MB2 phiB
474  gp->setDistPhiBitShift(2, iLayer, iRefLayer);
475  } else if ((gp->key().thePt <= 10) && (iLayer == 10)) { //iRefLayer: MB2, iLayer: RB1_in
476  gp->setDistPhiBitShift(1, iLayer, iRefLayer);
477  } else if ((gp->key().thePt <= 10) &&
478  (iLayer == 1 || iLayer == 3 || iLayer == 5)) { //iRefLayer: MB2, iLayer: MB1 and MB2 phiB
479  gp->setDistPhiBitShift(1, iLayer, iRefLayer);
480  } else if ((gp->key().thePt <= 17) && (iLayer == 1)) { //MB1 phiB
481  //due to grouping the patterns 4-7, the pdfs for the layer 1 in the pattern go outside of the range
482  //so the shift must be increased (or the group should be divided into to 2 groups, but it will increase fw occupancy
483  gp->setDistPhiBitShift(1, iLayer, iRefLayer);
484  } else if ((gp->key().thePt >= 11 && gp->key().thePt <= 17) && (iLayer == 3 || iLayer == 5)) { //MB1 phiB
485  //due to grouping the patterns 4-7, the pdfs for the layer 1 in the pattern go outside of the range
486  //so the shift must be increased (or the group should be divided into to 2 groups, but it will increase fw occupancy
487  gp->setDistPhiBitShift(0, iLayer, iRefLayer);
488  } else
489  gp->setDistPhiBitShift(0, iLayer, iRefLayer);
490  }
491  }
492  }
493 
494  double minHitCntThresh = 0.001;
495  //Calculating meanDistPhi
496  for (auto& gp : goldenPatterns) {
497  if (gp->key().thePt == 0)
498  continue;
499 
500  int minHitCnt = minHitCntThresh * eventCntPerGp[gp->key().number()]; // //TODO tune threshold <<<<<<<<<<<<<<<<<<
501  edm::LogImportant("l1tOmtfEventPrint")
502  << "PatternGenerator::upadatePdfs() Calculating meanDistPhi " << gp->key() << " eventCnt "
503  << eventCntPerGp[gp->key().number()] << " minHitCnt " << minHitCnt << std::endl;
504 
505  for (unsigned int iLayer = 0; iLayer < gp->getPdf().size(); ++iLayer) {
506  for (unsigned int iRefLayer = 0; iRefLayer < gp->getPdf()[iLayer].size(); ++iRefLayer) {
507  //calculate meanDistPhi
508  double meanDistPhi = 0;
509  double count = 0;
510  for (unsigned int iBin = 1; iBin < gp->getStatistics()[iLayer][iRefLayer].size(); iBin++) {
511  //iBin = 0 is reserved for the no hit
512  meanDistPhi += iBin * gp->getStatistics()[iLayer][iRefLayer][iBin][0];
513  count += gp->getStatistics()[iLayer][iRefLayer][iBin][0];
514  }
515 
516  if (count != 0) {
517  meanDistPhi /= count;
518 
519  meanDistPhi -= (gp->getStatistics()[iLayer][iRefLayer].size() / 2);
520 
521  if (count < minHitCnt)
522  meanDistPhi = 0;
523  else
524  edm::LogImportant("l1tOmtfEventPrint")
525  << __FUNCTION__ << ": " << __LINE__ << " " << gp->key() << " iLayer " << iLayer << " iRefLayer "
526  << iRefLayer << " count " << count << " meanDistPhi " << meanDistPhi << endl;
527  }
528  gp->setMeanDistPhiValue(round(meanDistPhi), iLayer, iRefLayer);
529  }
530  }
531  }
532 
534  edm::LogImportant("l1tOmtfEventPrint") << "patternGroups:" << std::endl;
535  for (unsigned int iGroup = 0; iGroup < patternGroups.size(); iGroup++) {
536  edm::LogImportant("l1tOmtfEventPrint") << "patternGroup " << std::setw(2) << iGroup << " ";
537  for (unsigned int i = 0; i < patternGroups[iGroup].size(); i++) {
538  edm::LogImportant("l1tOmtfEventPrint") << i << " patNum " << patternGroups[iGroup][i] << " ";
539  }
540  edm::LogImportant("l1tOmtfEventPrint") << std::endl;
541  }
542 
543  //averaging the meanDistPhi for the gp belonging to the same group
544  for (unsigned int iLayer = 0; iLayer < goldenPatterns.at(0)->getPdf().size(); ++iLayer) {
545  for (unsigned int iRefLayer = 0; iRefLayer < goldenPatterns.at(0)->getPdf()[iLayer].size(); ++iRefLayer) {
546  //unsigned int refLayerLogicNum = omtfConfig->getRefToLogicNumber()[iRefLayer];
547  //if(refLayerLogicNum == iLayer)
548  {
549  for (unsigned int iGroup = 0; iGroup < patternGroups.size(); iGroup++) {
550  double meanDistPhi = 0;
551  int mergedCnt = 0;
552  double norm = 0;
553  for (unsigned int i = 0; i < patternGroups[iGroup].size(); i++) {
554  auto gp = goldenPatterns.at(patternGroups[iGroup][i]).get();
555  if (gp->meanDistPhiValue(iLayer, iRefLayer) != 0) {
556  double weight = 1. / gp->key().thePt;
557  meanDistPhi += weight * gp->meanDistPhiValue(iLayer, iRefLayer);
558  mergedCnt++;
559  norm += weight;
560  }
561  }
562 
563  if (mergedCnt) {
564  //because for some gps the statistics can be too low, and then the meanDistPhiValue is 0, so it should not contribute to meanDistPhi, therefore it is divide by mergedCnt
565  //meanDistPhi /= mergedCnt;
567  //for low pT patterns it shifts the pdf of the pattern with bigger width (i.e. lower pt) towards the center of LUT
568  //then higher value of shift can be avoided (sometimes). So this is just a simple trick
569  meanDistPhi /= norm;
570 
571  /*
572  //setting the meanDistPhi to 0 if it is already small - this should save logic in FPGA - but seems it does not
573  if (iLayer == 2) {
574  //the meanDistPhi for the iLayer == 2 i.e. MB2 is used to calculate the algoMuon output phi
575  //therefore it is not zero-ed, as it will affect this output phi, phi and thus e.g. ghostbusting
576  } else if (abs(round(meanDistPhi)) <= 3)
577  meanDistPhi = 0;
578  else if (goldenPatterns.at(patternGroups[iGroup][0]).get()->key().thePt >= 13) {
579  //RPC layers, one strip is 4.7 units, the minimal possible spacing between two RPC hits is 2 strips
580  if (iLayer >= 10 && abs(round(meanDistPhi)) <= 8)
581  meanDistPhi = 0;
582  else if (abs(round(meanDistPhi)) <= 5)
583  meanDistPhi = 0;
584  } */
585 
586  for (unsigned int i = 0; i < patternGroups[iGroup].size(); i++) {
587  auto gp = goldenPatterns.at(patternGroups[iGroup][i]).get();
588  gp->setMeanDistPhiValue(round(meanDistPhi), iLayer, iRefLayer);
589  edm::LogImportant("l1tOmtfEventPrint")
590  << __FUNCTION__ << ": " << __LINE__ << " iGroup " << iGroup << " numInGroup " << i << " " << gp->key()
591  << " iLayer " << iLayer << " iRefLayer " << iRefLayer << " meanDistPhi after averaging "
592  << meanDistPhi << endl;
593  }
594  }
595  }
596  }
597  }
598  }
599 
600  //calculating the pdfs
601  for (auto& gp : goldenPatterns) {
602  if (gp->key().thePt == 0)
603  continue;
604 
605  //TODO tune threshold <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
606  int minHitCnt = 2 * minHitCntThresh * eventCntPerGp[gp->key().number()];
607 
608  for (unsigned int iLayer = 0; iLayer < gp->getPdf().size(); ++iLayer) {
609  for (unsigned int iRefLayer = 0; iRefLayer < gp->getPdf()[iLayer].size(); ++iRefLayer) {
610  {
611  double norm = 0;
612  for (unsigned int iBin = 0; iBin < gp->getStatistics()[iLayer][iRefLayer].size();
613  iBin++) { //iBin = 0 i.e. no hit is included here, to have the proper norm
614  norm += gp->getStatistics()[iLayer][iRefLayer][iBin][0];
615  }
616 
617  int pdfMiddle = gp->getPdf()[iLayer][iRefLayer].size() / 2;
618  int statBinGroupSize = 1 << gp->getDistPhiBitShift(iLayer, iRefLayer);
619  for (unsigned int iBinPdf = 0; iBinPdf < gp->getPdf()[iLayer][iRefLayer].size(); iBinPdf++) {
620  double pdfVal = 0;
621  if (iBinPdf > 0) {
622  for (int i = 0; i < statBinGroupSize; i++) {
623  int iBinStat =
624  statBinGroupSize * ((int)(iBinPdf)-pdfMiddle) + i + gp->meanDistPhiValue(iLayer, iRefLayer);
625 
626  iBinStat += (gp->getStatistics()[iLayer][iRefLayer].size() / 2);
627 
628  if (iBinStat >= 0 && iBinStat < (int)gp->getStatistics()[iLayer][iRefLayer].size()) {
629  pdfVal += gp->getStatistics()[iLayer][iRefLayer][iBinStat][0];
630  }
631  }
632  if (norm > minHitCnt) {
633  pdfVal /= (norm * statBinGroupSize);
634  } else
635  pdfVal = 0;
636  } else { //iBinPdf == 0 i.e. no hit
637  int iBinStat = 0;
638  if (norm > 0) {
639  pdfVal = gp->getStatistics()[iLayer][iRefLayer][iBinStat][0] / norm;
640  }
641  edm::LogImportant("l1tOmtfEventPrint")
642  << __FUNCTION__ << ": " << __LINE__ << " " << gp->key() << "calculating pdf: iLayer " << iLayer
643  << " iRefLayer " << iRefLayer << " norm " << std::setw(5) << norm << " no hits cnt " << std::setw(5)
644  << gp->getStatistics()[iLayer][iRefLayer][iBinStat][0] << " pdfVal " << pdfVal << endl;
645  }
646 
647  double minPdfValFactor = 1;
648  const double minPlog = log(omtfConfig->minPdfVal() * minPdfValFactor);
649  const double pdfMaxVal = omtfConfig->pdfMaxValue();
650 
651  int digitisedVal = 0;
652  if (pdfVal >= omtfConfig->minPdfVal() * minPdfValFactor) {
653  digitisedVal = rint(pdfMaxVal - log(pdfVal) / minPlog * pdfMaxVal);
654  }
655 
656  gp->setPdfValue(digitisedVal, iLayer, iRefLayer, iBinPdf);
657  }
658  }
659  }
660  }
661  }
662 }
int pdfMaxValue() const
Definition: weight.py:1
static std::string to_string(const XMLCh *ch)
std::vector< vector1D > vector2D
Log< level::Error, true > LogImportant
float minPdfVal() const
GoldenPatternVec< GoldenPatternWithStat > & goldenPatterns
std::vector< unsigned int > eventCntPerGp
vector2D getPatternGroups(const std::vector< std::unique_ptr< GoldenPatternType > > &goldenPats) const
const OMTFConfiguration * omtfConfig

◆ updateStat()

void PatternGenerator::updateStat ( )
protected

Definition at line 127 of file PatternGenerator.cc.

References funct::abs(), PatternOptimizerBase::candEta, EmulationObserverBase::candProcIndx, eventCntPerGp, OMTFConfiguration::getPatternNum(), GoldenPatternBase::getResults(), GoldenPatternWithStat::getStatistics(), PatternOptimizerBase::goldenPatterns, l1t::RegionalMuonCand::hwEta(), OMTFConfiguration::hwEtaToEta(), OMTFConfiguration::isBendingLayer(), GoldenPattern::meanDistPhiValue(), CoreSimTrack::momentum(), OMTFConfiguration::nPdfAddrBits(), EmulationObserverBase::omtfCand, EmulationObserverBase::omtfConfig, EmulationObserverBase::regionalMuonCand, PatternOptimizerBase::simMuEta, EmulationObserverBase::simMuon, CoreSimTrack::type(), and GoldenPatternWithStat::updateStat().

Referenced by PatternGenerator().

127  {
128  //cout<<__FUNCTION__<<":"<<__LINE__<<" omtfCand "<<*omtfCand<<std::endl;;
129  AlgoMuon* algoMuon = omtfCand.get();
130  if (!algoMuon) {
131  edm::LogImportant("l1tOmtfEventPrint") << ":" << __LINE__ << " algoMuon is null" << std::endl;
132  throw runtime_error("algoMuon is null");
133  }
134 
135  simMuEta->Fill(simMuon->momentum().eta());
137 
138  double ptSim = simMuon->momentum().pt();
139  int chargeSim = (abs(simMuon->type()) == 13) ? simMuon->type() / -13 : 0;
140 
141  unsigned int exptPatNum = omtfConfig->getPatternNum(ptSim, chargeSim);
142  GoldenPatternWithStat* exptCandGp = goldenPatterns.at(exptPatNum).get(); // expected pattern
143 
144  eventCntPerGp[exptPatNum]++;
145 
146  //edm::LogImportant("l1tOmtfEventPrint")<<"\n" <<__FUNCTION__<<": "<<__LINE__<<" exptCandGp "<<exptCandGp->key()<<" candProcIndx "<<candProcIndx<<" ptSim "<<ptSim<<" chargeSim "<<chargeSim<<std::endl;
147 
148  int pdfMiddle = 1 << (omtfConfig->nPdfAddrBits() - 1);
149 
150  //iRefHit is the index of the hit
151  for (unsigned int iRefHit = 0; iRefHit < exptCandGp->getResults()[candProcIndx].size(); ++iRefHit) {
152  auto& gpResult = exptCandGp->getResults()[candProcIndx][iRefHit];
153 
154  unsigned int refLayer = gpResult.getRefLayer();
155 
156  if (gpResult.getFiredLayerCnt() >= 3) {
157  for (unsigned int iLayer = 0; iLayer < gpResult.getStubResults().size(); iLayer++) {
158  //updating statistic for the gp which should have fired
159 
160  bool fired = false;
161  if (gpResult.getStubResults()[iLayer].getMuonStub()) {
162  if (omtfConfig->isBendingLayer(iLayer)) {
163  if (gpResult.getStubResults()[iLayer].getMuonStub()->qualityHw >= 4) //TODO change quality cut if needed
164  fired = true;
165  } else
166  fired = true;
167  }
168 
169  if (fired) { //the result is not empty
170  int phiDist = gpResult.getStubResults()[iLayer].getPdfBin();
171  phiDist += exptCandGp->meanDistPhiValue(iLayer, refLayer) - pdfMiddle;
172  //removing the shift applied in the GoldenPatternBase::process1Layer1RefLayer
173 
174  //TODO uncomment if filling ptDeltaPhiHists is needed
175  /*
176  unsigned int refLayerLogicNum = omtfConfig->getRefToLogicNumber()[iRefHit];
177  if(ptDeltaPhiHists[iCharge][iLayer] != nullptr &&
178  (iLayer == refLayerLogicNum || omtfConfig->getLogicToLogic().at(iLayer) == (int)refLayerLogicNum) )
179  ptDeltaPhiHists[iCharge][iLayer]->Fill(ttAlgoMuon->getPt(), phiDist); //TODO correct
180  */
181 
182  phiDist += exptCandGp->getStatistics()[iLayer][refLayer].size() / 2;
183 
184  //edm::LogImportant("l1tOmtfEventPrint")<<__FUNCTION__<<":"<<__LINE__<<" refLayer "<<refLayer<<" iLayer "<<iLayer<<" phiDist "<<phiDist<<" getPdfBin "<<gpResult.getStubResults()[iLayer].getPdfBin()<<std::endl;
185  if (phiDist > 0 && phiDist < (int)(exptCandGp->getStatistics()[iLayer][refLayer].size())) {
186  //updating statistic for the gp which found the candidate
187  //edm::LogImportant("l1tOmtfEventPrint")<<__FUNCTION__<<":"<<__LINE__<<" updating statistic "<<std::endl;
188  exptCandGp->updateStat(iLayer, refLayer, phiDist, 0, 1);
189  }
190  } else { //if there is no hit at all in a given layer, the bin = 0 is filled
191  int phiDist = 0;
192  exptCandGp->updateStat(iLayer, refLayer, phiDist, 0, 1);
193  }
194  }
195  }
196  }
197 }
virtual void updateStat(unsigned int iLayer, unsigned int iRefLayer, unsigned int iBin, unsigned int what, double value)
AlgoMuons::value_type omtfCand
virtual double hwEtaToEta(int hwEta) const
center of eta bin
unsigned int getPatternNum(double pt, int charge) const
charge: -1 - negative, +1 - positive
const math::XYZTLorentzVectorD & momentum() const
Definition: CoreSimTrack.h:19
const int hwEta() const
Get compressed eta (returned int * 0.010875 = eta)
int type() const
particle type (HEP PDT convension)
Definition: CoreSimTrack.h:22
l1t::RegionalMuonCand regionalMuonCand
unsigned int nPdfAddrBits() const
resultsArrayType & getResults()
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Log< level::Error, true > LogImportant
GoldenPatternVec< GoldenPatternWithStat > & goldenPatterns
std::vector< unsigned int > eventCntPerGp
int meanDistPhiValue(unsigned int iLayer, unsigned int iRefLayer) const
Definition: GoldenPattern.h:66
const OMTFConfiguration * omtfConfig
bool isBendingLayer(unsigned int iLayer) const override
const StatArrayType & getStatistics() const

◆ updateStatUsingMatcher2()

void PatternGenerator::updateStatUsingMatcher2 ( )
protected

Definition at line 199 of file PatternGenerator.cc.

References funct::abs(), candidateSimMuonMatcher, EmulationObserverBase::candProcIndx, EmulationObserverBase::edmCfg, eventCntPerGp, CandidateSimMuonMatcher::getMatchingResults(), edm::ParameterSet::getParameter(), OMTFConfiguration::getPatternNum(), OMTFConfiguration::getProcIndx(), OMTFConfiguration::getRefToLogicNumber(), GoldenPatternBase::getResults(), GoldenPatternWithStat::getStatistics(), PatternOptimizerBase::goldenPatterns, OMTFConfiguration::isBendingLayer(), LogTrace, OMTFConfiguration::nPdfAddrBits(), EmulationObserverBase::omtfConfig, PatternOptimizerBase::simMuEta, PatternOptimizerBase::simMuPtVsDispl, PatternOptimizerBase::simMuPtVsRho, and GoldenPatternWithStat::updateStat().

199  {
200  //cout<<__FUNCTION__<<":"<<__LINE__<<" omtfCand "<<*omtfCand<<std::endl;;
201 
202  std::vector<MatchingResult> matchingResults = candidateSimMuonMatcher->getMatchingResults();
203  LogTrace("l1tOmtfEventPrint") << "matchingResults.size() " << matchingResults.size() << std::endl;
204 
205  //candidateSimMuonMatcher should use the trackingParticles, because the simTracks are not stored for the pile-up events
206  for (auto& matchingResult : matchingResults) {
207  if (matchingResult.muonCand && matchingResult.simTrack) {
208  //&& matchingResult.muonCand->hwQual() >= 12 &&
209  //matchingResult.muonCand->hwPt() > 38
210 
211  AlgoMuon* algoMuon = matchingResult.procMuon.get();
212  if (!algoMuon) {
213  edm::LogImportant("l1tOmtfEventPrint") << ":" << __LINE__ << " algoMuon is null" << std::endl;
214  throw runtime_error("algoMuon is null");
215  }
216 
217  double ptSim = matchingResult.simTrack->momentum().pt();
218  int chargeSim = (abs(matchingResult.simTrack->type()) == 13) ? matchingResult.simTrack->type() / -13 : 0;
219 
220  double muDxy = (-1 * matchingResult.simVertex->position().x() * matchingResult.simTrack->momentum().py() +
221  matchingResult.simVertex->position().y() * matchingResult.simTrack->momentum().px()) /
222  matchingResult.simTrack->momentum().pt();
223 
224  simMuEta->Fill(matchingResult.simTrack->momentum().eta());
225 
226  simMuPtVsDispl->Fill(matchingResult.simTrack->momentum().pt(), muDxy);
227  simMuPtVsRho->Fill(matchingResult.simTrack->momentum().pt(), matchingResult.simVertex->position().rho());
228 
229  unsigned int exptPatNum = omtfConfig->getPatternNum(ptSim, chargeSim);
230  GoldenPatternWithStat* exptCandGp = goldenPatterns.at(exptPatNum).get(); // expected pattern
231 
232  eventCntPerGp[exptPatNum]++;
233 
234  candProcIndx =
235  omtfConfig->getProcIndx(matchingResult.muonCand->processor(), matchingResult.muonCand->trackFinderType());
236 
237  //edm::LogImportant("l1tOmtfEventPrint")<<"\n" <<__FUNCTION__<<": "<<__LINE__<<" exptCandGp "<<exptCandGp->key()<<" candProcIndx "<<candProcIndx<<" ptSim "<<ptSim<<" chargeSim "<<chargeSim<<std::endl;
238 
239  int pdfMiddle = 1 << (omtfConfig->nPdfAddrBits() - 1);
240  LogTrace("l1tOmtfEventPrint") << "updateStatUsingMatcher2 " << __LINE__ << std::endl;
241  //iRefHit is the index of the hit
242  for (unsigned int iRefHit = 0; iRefHit < exptCandGp->getResults()[candProcIndx].size(); ++iRefHit) {
243  auto& gpResult = exptCandGp->getResults()[candProcIndx][iRefHit];
244 
245  if (gpResult.getFiredLayerCnt() >= 3) {
246  int refLayer = gpResult.getRefLayer();
247 
248  if (refLayer < 0 || !gpResult.isValid())
249  LogTrace("l1tOmtfEventPrint") << "updateStatUsingMatcher2 " << __LINE__ << " refLayer " << refLayer
250  << " gpResult.isValid() " << gpResult.isValid() << std::endl;
251 
252  int refLayerLogicNumber = omtfConfig->getRefToLogicNumber()[refLayer];
253 
254  LogTrace("l1tOmtfEventPrint") << __FUNCTION__ << ":" << __LINE__ << " updating statistic: candProcIndx "
255  << candProcIndx << " iRefHit " << iRefHit << " refLayer " << refLayer
256  << " exptPatNum " << exptPatNum << " ptSim " << ptSim << " chargeSim "
257  << chargeSim << " muDxy " << muDxy << " muRho "
258  << matchingResult.simVertex->position().rho() << " x "
259  << matchingResult.simVertex->position().x() << " y "
260  << matchingResult.simVertex->position().y() << " z "
261  << matchingResult.simVertex->position().z() << std::endl;
262 
263  int refPhiB = 0;
264 
265  if (omtfConfig->isBendingLayer(refLayerLogicNumber + 1))
266  //if(refLayerLogicNumber < 5)
267  refPhiB = gpResult.getStubResults()[refLayerLogicNumber].getMuonStub()->phiBHw;
268 
269  int refPhiBShifted = refPhiB + exptCandGp->getStatistics()[0][refLayer][0].size() / 2;
270 
271  if (edmCfg.getParameter<string>("patternGenerator") == "deltaPhiVsPhiRef") {
272  refPhiBShifted = gpResult.getStubResults()[refLayerLogicNumber].getMuonStub()->phiHw;
273  }
274 
275  if (refPhiBShifted < 0 || refPhiBShifted >= (int)exptCandGp->getStatistics()[0][refLayer][0].size()) {
276  edm::LogImportant("l1tOmtfEventPrint") << "\n"
277  << __FUNCTION__ << ": " << __LINE__ << " wrong refPhiB " << refPhiB
278  << " refPhiBShifted " << refPhiBShifted;
279  continue;
280  }
281 
282  for (unsigned int iLayer = 0; iLayer < gpResult.getStubResults().size(); iLayer++) {
283  //updating statistic for the gp which should have fired
284 
285  bool fired = false;
286  if (gpResult.getStubResults()[iLayer].getMuonStub()) {
287  fired = true;
288  }
289 
290  if (fired) { //the result is not empty
291  int meanDistPhi = 0; //exptCandGp->meanDistPhiValue(iLayer, refLayer, refPhiB); //should be 0 here
292 
293  int phiDist = gpResult.getStubResults()[iLayer].getPdfBin() + meanDistPhi - pdfMiddle;
294  //removing the shift applied in the GoldenPatternBase::process1Layer1RefLayer
295 
296  int lutMiddle = exptCandGp->getStatistics()[iLayer][refLayer].size() / 2;
297 
298  LogTrace("l1tOmtfEventPrint")
299  << __FUNCTION__ << ":" << __LINE__ << " refLayer " << refLayer << " iLayer " << iLayer << " phiDist "
300  << phiDist << " getPdfBin " << gpResult.getStubResults()[iLayer].getPdfBin() << " phiMean "
301  << meanDistPhi << " refPhiB " << refPhiB << std::endl;
302 
303  //updating statistic for the gp which found the candidate
304  //edm::LogImportant("l1tOmtfEventPrint")<<__FUNCTION__<<":"<<__LINE__<<" updating statistic "<<std::endl;
305 
306  int phiDistCorr = phiDist + lutMiddle;
307 
308  if (phiDistCorr > 0 && phiDistCorr < (int)(exptCandGp->getStatistics()[iLayer][refLayer].size())) {
309  LogTrace("l1tOmtfEventPrint") << __FUNCTION__ << ":" << __LINE__ << " phiDistCorr "
310  << phiDistCorr
311  //<< " phiDistCorr + lutMiddle "<< phiDistCorr + lutMiddle
312  << " refPhiBShifted " << refPhiBShifted << std::endl;
313  exptCandGp->updateStat(iLayer, refLayer, phiDistCorr, refPhiBShifted, 1);
314  }
315  } else { //if there is no hit at all in a given layer, the bin = 0 is filled
316  int phiDist = 0;
317  exptCandGp->updateStat(iLayer, refLayer, phiDist, refPhiBShifted, 1);
318  }
319  }
320  }
321  }
322  }
323  }
324 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
CandidateSimMuonMatcher * candidateSimMuonMatcher
virtual void updateStat(unsigned int iLayer, unsigned int iRefLayer, unsigned int iBin, unsigned int what, double value)
unsigned int getPatternNum(double pt, int charge) const
charge: -1 - negative, +1 - positive
#define LogTrace(id)
unsigned int nPdfAddrBits() const
resultsArrayType & getResults()
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Log< level::Error, true > LogImportant
const std::vector< int > & getRefToLogicNumber() const
std::vector< MatchingResult > getMatchingResults()
GoldenPatternVec< GoldenPatternWithStat > & goldenPatterns
unsigned int getProcIndx(unsigned int iProcessor, l1t::tftype mtfType) const
input phi should be in the hardware scale (nPhiBins units for 2pi), can be in range -nPhiBins ...
std::vector< unsigned int > eventCntPerGp
const OMTFConfiguration * omtfConfig
bool isBendingLayer(unsigned int iLayer) const override
const StatArrayType & getStatistics() const

Member Data Documentation

◆ candidateSimMuonMatcher

CandidateSimMuonMatcher* PatternGenerator::candidateSimMuonMatcher = nullptr
protected

Definition at line 47 of file PatternGenerator.h.

Referenced by updateStatUsingMatcher2().

◆ eventCntPerGp

std::vector<unsigned int> PatternGenerator::eventCntPerGp
protected

Definition at line 52 of file PatternGenerator.h.

Referenced by endJob(), upadatePdfs(), updateStat(), and updateStatUsingMatcher2().

◆ ptDeltaPhiHists

std::vector<std::vector<TH2I*> > PatternGenerator::ptDeltaPhiHists
protected

Definition at line 50 of file PatternGenerator.h.

◆ updateStatFunction

std::function<void()> PatternGenerator::updateStatFunction
protected

Definition at line 35 of file PatternGenerator.h.

Referenced by observeEventEnd().