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
GoldenPatternVec< GoldenPatternWithStat > & goldenPatterns
 
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 336 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.

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

772  {
773  int group = 0;
774  int indexInGroup = 0;
775  for (auto& gp : goldenPatterns) {
776  indexInGroup++;
777  gp->key().setGroup(group);
778  gp->key().setIndexInGroup(indexInGroup);
779  //indexInGroup is counted from 1
780 
781  edm::LogImportant("l1tOmtfEventPrint")
782  << "setGroup(group): group " << group << " indexInGroup " << indexInGroup << std::endl;
783 
784  if (gp->key().thePt <= 12 && indexInGroup == 2) { //TODO
785  indexInGroup = 0;
786  group++;
787  }
788 
789  if (gp->key().thePt > 12 && indexInGroup == 4) { //TODO
790  indexInGroup = 0;
791  group++;
792  }
793  }
794 
796  edm::LogImportant("l1tOmtfEventPrint") << "patternGroups:" << std::endl;
797  for (unsigned int iGroup = 0; iGroup < patternGroups.size(); iGroup++) {
798  edm::LogImportant("l1tOmtfEventPrint") << "patternGroup " << std::setw(2) << iGroup << " ";
799  for (unsigned int i = 0; i < patternGroups[iGroup].size(); i++) {
800  edm::LogImportant("l1tOmtfEventPrint") << i << " patNum " << patternGroups[iGroup][i] << " ";
801  }
802  edm::LogImportant("l1tOmtfEventPrint") << std::endl;
803  }
804 
805  int pdfBins = exp2(omtfConfig->nPdfAddrBits());
806 
807  for (unsigned int iLayer = 0; iLayer < goldenPatterns.at(0)->getPdf().size(); ++iLayer) {
808  for (unsigned int iRefLayer = 0; iRefLayer < goldenPatterns.at(0)->getPdf()[iLayer].size(); ++iRefLayer) {
809  //unsigned int refLayerLogicNum = omtfConfig->getRefToLogicNumber()[iRefLayer];
810  //if(refLayerLogicNum == iLayer)
811  {
812  //averaging the meanDistPhi for the gp belonging to the same group
813  for (unsigned int iGroup = 0; iGroup < patternGroups.size(); iGroup++) {
814  double meanDistPhi = 0;
815  int mergedCnt = 0;
816  for (unsigned int i = 0; i < patternGroups[iGroup].size(); i++) {
817  auto gp = goldenPatterns.at(patternGroups[iGroup][i]).get();
818  meanDistPhi += gp->meanDistPhiValue(iLayer, iRefLayer);
819  if (gp->meanDistPhiValue(iLayer, iRefLayer) != 0)
820  mergedCnt++;
821  edm::LogImportant("l1tOmtfEventPrint")
822  << __FUNCTION__ << ": " << __LINE__ << " iGroup " << iGroup << " numInGroup " << i << " " << gp->key()
823  << " iLayer " << iLayer << " iRefLayer " << iRefLayer << " old meanDistPhiValue "
824  << gp->meanDistPhiValue(iLayer, iRefLayer) << endl;
825  }
826 
827  if (mergedCnt) {
828  meanDistPhi /= mergedCnt;
829  meanDistPhi = (int)meanDistPhi;
830 
831  //because for some gps the statistics can be too low, and then the meanDistPhiValue is 0, so it should not contribute
832  for (unsigned int i = 0; i < patternGroups[iGroup].size(); i++) {
833  auto gp = goldenPatterns.at(patternGroups[iGroup][i]).get();
834  unsigned int refLayerLogicNum = omtfConfig->getRefToLogicNumber()[iRefLayer];
835  if (refLayerLogicNum != iLayer) {
836  int shift = meanDistPhi - gp->meanDistPhiValue(iLayer, iRefLayer);
837  edm::LogImportant("l1tOmtfEventPrint")
838  << __FUNCTION__ << ": " << __LINE__ << " iGroup " << iGroup << " numInGroup " << i << " "
839  << gp->key() << " iLayer " << iLayer << " iRefLayer " << iRefLayer
840  << " new meanDistPhi after averaging " << meanDistPhi << " old meanDistPhiValue "
841  << gp->meanDistPhiValue(iLayer, iRefLayer) << " shift " << shift << endl;
842 
843  if (shift < 0) {
844  for (int iBin = 1 - shift; iBin < pdfBins;
845  iBin++) { //iBin = 0 i.e. no hit is included here, to have the proper norm
846  auto pdfVal = gp->pdfValue(iLayer, iRefLayer, iBin);
847  gp->setPdfValue(pdfVal, iLayer, iRefLayer, iBin + shift);
848  edm::LogImportant("l1tOmtfEventPrint")
849  << " iBin " << iBin << " iBin + shift " << iBin + shift << " pdfVal " << pdfVal << endl;
850  }
851  for (int iBin = pdfBins + shift; iBin < pdfBins; iBin++) {
852  gp->setPdfValue(0, iLayer, iRefLayer, iBin);
853  }
854  } else if (shift > 0) {
855  for (int iBin = pdfBins - 1 - shift; iBin > 0;
856  iBin--) { //iBin = 0 i.e. no hit is included here, to have the proper norm
857  auto pdfVal = gp->pdfValue(iLayer, iRefLayer, iBin);
858  gp->setPdfValue(pdfVal, iLayer, iRefLayer, iBin + shift);
859  edm::LogImportant("l1tOmtfEventPrint")
860  << " iBin " << iBin << " iBin + shift " << iBin + shift << " pdfVal " << pdfVal << endl;
861  }
862  for (int iBin = shift; iBin > 0; iBin--) {
863  gp->setPdfValue(0, iLayer, iRefLayer, iBin);
864  }
865  }
866  }
867 
868  gp->setMeanDistPhiValue(round(meanDistPhi), iLayer, iRefLayer);
869  }
870  }
871  }
872  }
873  }
874  }
875 }
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 649 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().

649  {
650  edm::LogImportant("l1tOmtfEventPrint") << __FUNCTION__ << ": " << __LINE__ << " Correcting P(C_k) " << std::endl;
651  unsigned int iPdf = omtfConfig->nPdfBins() / 2; // <<(omtfConfig->nPdfAddrBits()-1);
652  for (unsigned int iRefLayer = 0; iRefLayer < goldenPatterns[0]->getPdf()[0].size(); ++iRefLayer) {
653  unsigned int refLayerLogicNumber = omtfConfig->getRefToLogicNumber()[iRefLayer];
654  if (iRefLayer == 0 || iRefLayer == 2) //DT
655  step = 1.5;
656  else if (iRefLayer == 5) //DT
657  step = 1.5;
658  else if (iRefLayer == 1) //CSC
659  step = 1.5;
660  else if (iRefLayer == 3) //CSC
661  step = 1.5;
662  else if (iRefLayer == 5) //RE2/3
663  step = 1.5;
664  else if (iRefLayer == 6 || iRefLayer == 7) //bRPC
665  step = 1.5;
666 
667  edm::LogImportant("l1tOmtfEventPrint")
668  << __FUNCTION__ << ":" << __LINE__ << " RefLayer " << iRefLayer << " step " << step << std::endl;
669  for (int sign = -1; sign <= 1; sign++) {
671  if (gp->key().thePt == 0 || gp->key().theCharge != sign)
672  continue;
673 
674  double ptFrom = omtfConfig->getPatternPtRange(gp->key().theNumber).ptFrom;
675  double ptTo = omtfConfig->getPatternPtRange(gp->key().theNumber).ptTo;
676 
677  double ptRange = ptTo - ptFrom;
678 
679  double minPdfValFactor = 0.1;
680  double minPlog = log(omtfConfig->minPdfVal() * minPdfValFactor);
681  double pdfMaxVal = omtfConfig->pdfMaxValue();
682 
683  pdfMaxVal /= 3.;
684  minPlog *= 2;
685 
686  //last bin of the ptRange goes to 10000, so here we change it to 1000
687  if (ptRange > 800)
688  ptRange = 800;
689 
690  double norm = 0.001;
691  double classProb = vxIntegMuRate(ptFrom, ptRange, 0.82, 1.24) * norm;
692 
693  int digitisedVal = rint(pdfMaxVal - log(classProb) / minPlog * pdfMaxVal);
694 
695  int newPdfVal = digitisedVal; //gp->getPdf()[refLayerLogicNumber][iRefLayer][iPdf]
696 
697  if (ptFrom == 0)
698  newPdfVal += 15;
699  if (ptFrom == 3.5)
700  newPdfVal += 15;
701  if (ptFrom == 4)
702  newPdfVal += 12;
703  if (ptFrom == 4.5)
704  newPdfVal += 9;
705  if (ptFrom == 5)
706  newPdfVal += 7;
707  if (ptFrom == 6)
708  newPdfVal += 4;
709  if (ptFrom == 7)
710  newPdfVal += 2;
711 
712  if (ptFrom == 100)
713  newPdfVal = 16;
714  if (ptFrom == 200)
715  newPdfVal = 22;
716 
717  gp->setPdfValue(newPdfVal, refLayerLogicNumber, iRefLayer, iPdf);
718 
719  edm::LogImportant("l1tOmtfEventPrint")
720  << gp->key() << " " << omtfConfig->getPatternPtRange(gp->key().theNumber).ptFrom << " - "
721  << omtfConfig->getPatternPtRange(gp->key().theNumber).ptTo << " GeV"
722  << " ptRange " << ptRange << " RefLayer " << iRefLayer << " newPdfVal " << newPdfVal << std::endl;
723  }
724  }
725  }
726 }
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 321 of file PatternGenerator.cc.

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

322  {
323  if (simMuon == nullptr || omtfCand->getGoldenPatern() == nullptr) //no sim muon or empty candidate
324  return;
325 
326  if (abs(simMuon->momentum().eta()) < 0.8 || abs(simMuon->momentum().eta()) > 1.24)
327  return;
328 
330 
331  //updateStat();
332  //updateStatUsingMatcher2();
334 }
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 728 of file PatternGenerator.cc.

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

Referenced by endJob().

728  {
729  edm::LogImportant("l1tOmtfEventPrint") << __FUNCTION__ << ": " << __LINE__ << " reCalibratePt" << std::endl;
730  std::map<int, float> ptMap;
731  //for Patterns_0x0009_oldSample_3_10Files_classProb2.xml
732  ptMap[7] = 4.0;
733  ptMap[8] = 4.5;
734  ptMap[9] = 5.0;
735  ptMap[10] = 5.5;
736  ptMap[11] = 6.0;
737  ptMap[13] = 7.0;
738  ptMap[15] = 8.5;
739  ptMap[17] = 10.0;
740  ptMap[21] = 12.0;
741  ptMap[25] = 14.0;
742  ptMap[29] = 16.0;
743  ptMap[33] = 18.5;
744  ptMap[37] = 21.0;
745  ptMap[41] = 23.0;
746  ptMap[45] = 26.0;
747  ptMap[49] = 28.0;
748  ptMap[53] = 30.0;
749  ptMap[57] = 32.0;
750  ptMap[61] = 36.0;
751  ptMap[71] = 40.0;
752  ptMap[81] = 48.0;
753  ptMap[91] = 54.0;
754  ptMap[101] = 60.0;
755  ptMap[121] = 70.0;
756  ptMap[141] = 82.0;
757  ptMap[161] = 96.0;
758  ptMap[201] = 114.0;
759  ptMap[401] = 200.0;
760 
761  for (auto& gp : goldenPatterns) {
762  if (gp->key().thePt == 0)
763  continue;
764 
765  int newPt = omtfConfig->ptGevToHw(ptMap[gp->key().thePt]);
766  edm::LogImportant("l1tOmtfEventPrint") << gp->key().thePt << " -> " << newPt << std::endl;
767 
768  gp->key().setPt(newPt);
769  }
770 }
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 637 of file PatternGenerator.cc.

References timingPdfMaker::outfile.

637  {
638  outfile.mkdir("ptDeltaPhiHists")->cd();
639  //TODO uncomment if ptDeltaPhiHists are needed
640  /* for(unsigned int iCharge = 0; iCharge <= 1; iCharge++) {
641  for(unsigned int iLayer = 0; iLayer < omtfConfig->nLayers(); ++iLayer) { //for the moment filing only ref layer, remove whe
642  if(ptDeltaPhiHists[iCharge][iLayer]) {
643  ptDeltaPhiHists[iCharge][iLayer]->Write();
644  }
645  }
646  }*/
647 }

◆ upadatePdfs()

void PatternGenerator::upadatePdfs ( )
protected

weighted average, weight is 1/pt

Definition at line 433 of file PatternGenerator.cc.

References funct::abs(), 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().

433  {
434  //TODO setting the DistPhiBitShift i.e. grouping of the pdfBins
435  for (auto& gp : goldenPatterns) {
436  if (gp->key().thePt == 0)
437  continue;
438  for (unsigned int iLayer = 0; iLayer < gp->getPdf().size(); ++iLayer) {
439  for (unsigned int iRefLayer = 0; iRefLayer < gp->getPdf()[iLayer].size(); ++iRefLayer) {
440  if (gp->getDistPhiBitShift(iLayer, iRefLayer)) {
441  throw runtime_error(
442  string(__FUNCTION__) + ":" + to_string(__LINE__) +
443  "gp->getDistPhiBitShift(iLayer, iRefLayer) != 0 - cannot change DistPhiBitShift then!!!!");
444  }
445 
446  //watch out - the pt here is the hardware pt before the recalibration
447  //the shift for given pattern and layer should be the same same for all refLayers
448  //otherwise the firmware does not compile - at least the phase-1
449  if ((gp->key().thePt <= 10) &&
450  (iLayer == 1 || iLayer == 3 || iLayer == 5)) { //iRefLayer: MB2, iLayer: MB1 and MB2 phiB
451  gp->setDistPhiBitShift(2, iLayer, iRefLayer);
452  } else if ((gp->key().thePt <= 10) && (iLayer == 10)) { //iRefLayer: MB2, iLayer: RB1_in
453  gp->setDistPhiBitShift(1, iLayer, iRefLayer);
454  } else if ((gp->key().thePt >= 11 && gp->key().thePt <= 17) && (iLayer == 1)) { //MB1 phiB
455  //due to grouping the patterns 4-7, the pdfs for the layer 1 in the pattern go outside of the range
456  //so the shift must be increased (or the group should be divided into to 2 groups, but it will increase fw occupancy
457  gp->setDistPhiBitShift(2, iLayer, iRefLayer);
458  } else if ((gp->key().thePt >= 11 && gp->key().thePt <= 17) && (iLayer == 3 || iLayer == 5)) { //MB1 phiB
459  //due to grouping the patterns 4-7, the pdfs for the layer 1 in the pattern go outside of the range
460  //so the shift must be increased (or the group should be divided into to 2 groups, but it will increase fw occupancy
461  gp->setDistPhiBitShift(1, iLayer, iRefLayer);
462  } else
463  gp->setDistPhiBitShift(0, iLayer, iRefLayer);
464  }
465  }
466  }
467 
468  double minHitCntThresh = 0.001;
469  //Calculating meanDistPhi
470  for (auto& gp : goldenPatterns) {
471  if (gp->key().thePt == 0)
472  continue;
473 
474  int minHitCnt = minHitCntThresh * eventCntPerGp[gp->key().number()]; // //TODO tune threshold <<<<<<<<<<<<<<<<<<
475  edm::LogImportant("l1tOmtfEventPrint")
476  << "PatternGenerator::upadatePdfs() Calculating meanDistPhi " << gp->key() << " eventCnt "
477  << eventCntPerGp[gp->key().number()] << " minHitCnt " << minHitCnt << std::endl;
478 
479  for (unsigned int iLayer = 0; iLayer < gp->getPdf().size(); ++iLayer) {
480  for (unsigned int iRefLayer = 0; iRefLayer < gp->getPdf()[iLayer].size(); ++iRefLayer) {
481  //calculate meanDistPhi
482  double meanDistPhi = 0;
483  double count = 0;
484  for (unsigned int iBin = 1; iBin < gp->getStatistics()[iLayer][iRefLayer].size(); iBin++) {
485  //iBin = 0 is reserved for the no hit
486  meanDistPhi += iBin * gp->getStatistics()[iLayer][iRefLayer][iBin][0];
487  count += gp->getStatistics()[iLayer][iRefLayer][iBin][0];
488  }
489 
490  if (count != 0) {
491  meanDistPhi /= count;
492 
493  meanDistPhi -= (gp->getStatistics()[iLayer][iRefLayer].size() / 2);
494 
495  if (count < minHitCnt)
496  meanDistPhi = 0;
497  else
498  edm::LogImportant("l1tOmtfEventPrint")
499  << __FUNCTION__ << ": " << __LINE__ << " " << gp->key() << " iLayer " << iLayer << " iRefLayer "
500  << iRefLayer << " count " << count << " meanDistPhi " << meanDistPhi << endl;
501  }
502  gp->setMeanDistPhiValue(round(meanDistPhi), iLayer, iRefLayer);
503  }
504  }
505  }
506 
508  edm::LogImportant("l1tOmtfEventPrint") << "patternGroups:" << std::endl;
509  for (unsigned int iGroup = 0; iGroup < patternGroups.size(); iGroup++) {
510  edm::LogImportant("l1tOmtfEventPrint") << "patternGroup " << std::setw(2) << iGroup << " ";
511  for (unsigned int i = 0; i < patternGroups[iGroup].size(); i++) {
512  edm::LogImportant("l1tOmtfEventPrint") << i << " patNum " << patternGroups[iGroup][i] << " ";
513  }
514  edm::LogImportant("l1tOmtfEventPrint") << std::endl;
515  }
516 
517  //averaging the meanDistPhi for the gp belonging to the same group
518  for (unsigned int iLayer = 0; iLayer < goldenPatterns.at(0)->getPdf().size(); ++iLayer) {
519  for (unsigned int iRefLayer = 0; iRefLayer < goldenPatterns.at(0)->getPdf()[iLayer].size(); ++iRefLayer) {
520  //unsigned int refLayerLogicNum = omtfConfig->getRefToLogicNumber()[iRefLayer];
521  //if(refLayerLogicNum == iLayer)
522  {
523  for (unsigned int iGroup = 0; iGroup < patternGroups.size(); iGroup++) {
524  double meanDistPhi = 0;
525  int mergedCnt = 0;
526  double norm = 0;
527  for (unsigned int i = 0; i < patternGroups[iGroup].size(); i++) {
528  auto gp = goldenPatterns.at(patternGroups[iGroup][i]).get();
529  if (gp->meanDistPhiValue(iLayer, iRefLayer) != 0) {
530  double weight = 1. / gp->key().thePt;
531  meanDistPhi += weight * gp->meanDistPhiValue(iLayer, iRefLayer);
532  mergedCnt++;
533  norm += weight;
534  }
535  }
536 
537  if (mergedCnt) {
538  //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
539  //meanDistPhi /= mergedCnt;
541  //for low pT patterns it shifts the pdf of the pattern with bigger width (i.e. lower pt) towards the center of LUT
542  //then higher value of shift can be avoided (sometimes). So this is just a simple trick
543  meanDistPhi /= norm;
544 
545  //setting the meanDistPhi to 0 if it is already small - this should save logic in FPGA
546  if (iLayer == 2) {
547  //the meanDistPhi for the iLayer == 2 i.e. MB2 is used to calculate the algoMuon output phi
548  //therefore it is not zero-ed, as it will affect this output phi, phi and thus e.g. ghostbusting
549  } else if (abs(round(meanDistPhi)) <= 3)
550  meanDistPhi = 0;
551  else if (goldenPatterns.at(patternGroups[iGroup][0]).get()->key().thePt >= 13) {
552  //RPC layers, one strip is 4.7 units, the minimal possinle spacing between two RPC hits is 2 strips
553  if (iLayer >= 10 && abs(round(meanDistPhi)) <= 8)
554  meanDistPhi = 0;
555  else if (abs(round(meanDistPhi)) <= 5)
556  meanDistPhi = 0;
557  }
558 
559  for (unsigned int i = 0; i < patternGroups[iGroup].size(); i++) {
560  auto gp = goldenPatterns.at(patternGroups[iGroup][i]).get();
561  gp->setMeanDistPhiValue(round(meanDistPhi), iLayer, iRefLayer);
562  edm::LogImportant("l1tOmtfEventPrint")
563  << __FUNCTION__ << ": " << __LINE__ << " iGroup " << iGroup << " numInGroup " << i << " " << gp->key()
564  << " iLayer " << iLayer << " iRefLayer " << iRefLayer << " meanDistPhi after averaging "
565  << meanDistPhi << endl;
566  }
567  }
568  }
569  }
570  }
571  }
572 
573  //calculating the pdfs
574  for (auto& gp : goldenPatterns) {
575  if (gp->key().thePt == 0)
576  continue;
577 
578  //TODO tune threshold <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
579  int minHitCnt = 2 * minHitCntThresh * eventCntPerGp[gp->key().number()];
580 
581  for (unsigned int iLayer = 0; iLayer < gp->getPdf().size(); ++iLayer) {
582  for (unsigned int iRefLayer = 0; iRefLayer < gp->getPdf()[iLayer].size(); ++iRefLayer) {
583  {
584  double norm = 0;
585  for (unsigned int iBin = 0; iBin < gp->getStatistics()[iLayer][iRefLayer].size();
586  iBin++) { //iBin = 0 i.e. no hit is included here, to have the proper norm
587  norm += gp->getStatistics()[iLayer][iRefLayer][iBin][0];
588  }
589 
590  int pdfMiddle = gp->getPdf()[iLayer][iRefLayer].size() / 2;
591  int statBinGroupSize = 1 << gp->getDistPhiBitShift(iLayer, iRefLayer);
592  for (unsigned int iBinPdf = 0; iBinPdf < gp->getPdf()[iLayer][iRefLayer].size(); iBinPdf++) {
593  double pdfVal = 0;
594  if (iBinPdf > 0) {
595  for (int i = 0; i < statBinGroupSize; i++) {
596  int iBinStat =
597  statBinGroupSize * ((int)(iBinPdf)-pdfMiddle) + i + gp->meanDistPhiValue(iLayer, iRefLayer);
598 
599  iBinStat += (gp->getStatistics()[iLayer][iRefLayer].size() / 2);
600 
601  if (iBinStat >= 0 && iBinStat < (int)gp->getStatistics()[iLayer][iRefLayer].size()) {
602  pdfVal += gp->getStatistics()[iLayer][iRefLayer][iBinStat][0];
603  }
604  }
605  if (norm > minHitCnt) {
606  pdfVal /= (norm * statBinGroupSize);
607  } else
608  pdfVal = 0;
609  } else { //iBinPdf == 0 i.e. no hit
610  int iBinStat = 0;
611  if (norm > 0) {
612  pdfVal = gp->getStatistics()[iLayer][iRefLayer][iBinStat][0] / norm;
613  }
614  edm::LogImportant("l1tOmtfEventPrint")
615  << __FUNCTION__ << ": " << __LINE__ << " " << gp->key() << "calculating pdf: iLayer " << iLayer
616  << " iRefLayer " << iRefLayer << " norm " << std::setw(5) << norm << " no hits cnt " << std::setw(5)
617  << gp->getStatistics()[iLayer][iRefLayer][iBinStat][0] << " pdfVal " << pdfVal << endl;
618  }
619 
620  double minPdfValFactor = 1;
621  const double minPlog = log(omtfConfig->minPdfVal() * minPdfValFactor);
622  const double pdfMaxVal = omtfConfig->pdfMaxValue();
623 
624  int digitisedVal = 0;
625  if (pdfVal >= omtfConfig->minPdfVal() * minPdfValFactor) {
626  digitisedVal = rint(pdfMaxVal - log(pdfVal) / minPlog * pdfMaxVal);
627  }
628 
629  gp->setPdfValue(digitisedVal, iLayer, iRefLayer, iBinPdf);
630  }
631  }
632  }
633  }
634  }
635 }
int pdfMaxValue() const
Definition: weight.py:1
static std::string to_string(const XMLCh *ch)
std::vector< vector1D > vector2D
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
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(), EmulationObserverBase::candProcIndx, eventCntPerGp, OMTFConfiguration::getPatternNum(), GoldenPatternBase::getResults(), GoldenPatternWithStat::getStatistics(), PatternOptimizerBase::goldenPatterns, OMTFConfiguration::isBendingLayer(), GoldenPattern::meanDistPhiValue(), CoreSimTrack::momentum(), OMTFConfiguration::nPdfAddrBits(), EmulationObserverBase::omtfCand, EmulationObserverBase::omtfConfig, 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  double ptSim = simMuon->momentum().pt();
136  int chargeSim = (abs(simMuon->type()) == 13) ? simMuon->type() / -13 : 0;
137 
138  unsigned int exptPatNum = omtfConfig->getPatternNum(ptSim, chargeSim);
139  GoldenPatternWithStat* exptCandGp = goldenPatterns.at(exptPatNum).get(); // expected pattern
140 
141  eventCntPerGp[exptPatNum]++;
142 
143  //edm::LogImportant("l1tOmtfEventPrint")<<"\n" <<__FUNCTION__<<": "<<__LINE__<<" exptCandGp "<<exptCandGp->key()<<" candProcIndx "<<candProcIndx<<" ptSim "<<ptSim<<" chargeSim "<<chargeSim<<std::endl;
144 
145  int pdfMiddle = 1 << (omtfConfig->nPdfAddrBits() - 1);
146 
147  //iRefHit is the index of the hit
148  for (unsigned int iRefHit = 0; iRefHit < exptCandGp->getResults()[candProcIndx].size(); ++iRefHit) {
149  auto& gpResult = exptCandGp->getResults()[candProcIndx][iRefHit];
150 
151  unsigned int refLayer = gpResult.getRefLayer();
152 
153  if (gpResult.getFiredLayerCnt() >= 3) {
154  for (unsigned int iLayer = 0; iLayer < gpResult.getStubResults().size(); iLayer++) {
155  //updating statistic for the gp which should have fired
156 
157  bool fired = false;
158  if (gpResult.getStubResults()[iLayer].getMuonStub()) {
159  if (omtfConfig->isBendingLayer(iLayer)) {
160  if (gpResult.getStubResults()[iLayer].getMuonStub()->qualityHw >= 4) //TODO change quality cut if needed
161  fired = true;
162  } else
163  fired = true;
164  }
165 
166  if (fired) { //the result is not empty
167  int phiDist = gpResult.getStubResults()[iLayer].getPdfBin();
168  phiDist += exptCandGp->meanDistPhiValue(iLayer, refLayer) - pdfMiddle;
169  //removing the shift applied in the GoldenPatternBase::process1Layer1RefLayer
170 
171  //TODO uncomment if filling ptDeltaPhiHists is needed
172  /*
173  unsigned int refLayerLogicNum = omtfConfig->getRefToLogicNumber()[iRefHit];
174  if(ptDeltaPhiHists[iCharge][iLayer] != nullptr &&
175  (iLayer == refLayerLogicNum || omtfConfig->getLogicToLogic().at(iLayer) == (int)refLayerLogicNum) )
176  ptDeltaPhiHists[iCharge][iLayer]->Fill(ttAlgoMuon->getPt(), phiDist); //TODO correct
177  */
178 
179  phiDist += exptCandGp->getStatistics()[iLayer][refLayer].size() / 2;
180 
181  //edm::LogImportant("l1tOmtfEventPrint")<<__FUNCTION__<<":"<<__LINE__<<" refLayer "<<refLayer<<" iLayer "<<iLayer<<" phiDist "<<phiDist<<" getPdfBin "<<gpResult.getStubResults()[iLayer].getPdfBin()<<std::endl;
182  if (phiDist > 0 && phiDist < (int)(exptCandGp->getStatistics()[iLayer][refLayer].size())) {
183  //updating statistic for the gp which found the candidate
184  //edm::LogImportant("l1tOmtfEventPrint")<<__FUNCTION__<<":"<<__LINE__<<" updating statistic "<<std::endl;
185  exptCandGp->updateStat(iLayer, refLayer, phiDist, 0, 1);
186  }
187  } else { //if there is no hit at all in a given layer, the bin = 0 is filled
188  int phiDist = 0;
189  exptCandGp->updateStat(iLayer, refLayer, phiDist, 0, 1);
190  }
191  }
192  }
193  }
194 }
virtual void updateStat(unsigned int iLayer, unsigned int iRefLayer, unsigned int iBin, unsigned int what, double value)
AlgoMuons::value_type omtfCand
unsigned int getPatternNum(double pt, int charge) const
charge: -1 - negative, +1 - positive
const math::XYZTLorentzVectorD & momentum() const
Definition: CoreSimTrack.h:19
int type() const
particle type (HEP PDT convension)
Definition: CoreSimTrack.h:22
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 196 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::simMuPtVsDispl, PatternOptimizerBase::simMuPtVsRho, and GoldenPatternWithStat::updateStat().

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