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)
 
 ~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 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 beginRun (edm::EventSetup const &eventSetup)
 
 IOMTFEmulationObserver ()
 
virtual ~IOMTFEmulationObserver ()
 

Protected Member Functions

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

Protected Attributes

std::vector< unsigned int > eventCntPerGp
 
std::vector< std::vector< TH2I * > > ptDeltaPhiHists
 
- Protected Attributes inherited from PatternOptimizerBase
GoldenPatternVec< GoldenPatternWithStat > & goldenPatterns
 
TH1I * simMuFoundByOmtfPt
 
TH1I * simMuPt
 
TH1F * simMuPtSpectrum
 
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 13 of file PatternGenerator.h.

Constructor & Destructor Documentation

◆ PatternGenerator()

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

Definition at line 16 of file PatternGenerator.cc.

References EmulationObserverBase::edmCfg, edm::ParameterSet::getParameter(), and initPatternGen().

19  : PatternOptimizerBase(edmCfg, omtfConfig, gps), eventCntPerGp(gps.size(), 0) {
20  edm::LogImportant("l1tOmtfEventPrint") << "constructing PatternGenerator, type: "
21  << edmCfg.getParameter<string>("patternGenerator") << std::endl;
22 
23  if (edmCfg.getParameter<string>("patternGenerator") == "patternGen")
25 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
Log< level::Error, true > LogImportant
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 27 of file PatternGenerator.cc.

27 {}

Member Function Documentation

◆ endJob()

void PatternGenerator::endJob ( void  )
overridevirtual

Implements IOMTFEmulationObserver.

Definition at line 182 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.

182  {
183  if (edmCfg.getParameter<string>("patternGenerator") == "modifyClassProb")
184  modifyClassProb(1);
185  else if (edmCfg.getParameter<string>("patternGenerator") == "groupPatterns")
186  groupPatterns();
187  else if (edmCfg.getParameter<string>("patternGenerator") == "patternGen") {
188  upadatePdfs();
189  writeLayerStat = true;
190  } else if (edmCfg.getParameter<string>("patternGenerator") == "patternGenFromStat") {
192  edm::LogImportant("l1tOmtfEventPrint") << "PatternGenerator::endJob() rootFileName " << rootFileName << std::endl;
193  TFile inFile(rootFileName.c_str());
194  TDirectory* curDir = (TDirectory*)inFile.Get("layerStats");
195 
196  ostringstream ostrName;
197  for (auto& gp : goldenPatterns) {
198  if (gp->key().thePt == 0)
199  continue;
200 
201  int statBinsCnt = 1024; //= gp->getPdf()[0][0].size() * 8; //TODO should be big enough to comprise the pdf tails
202  gp->iniStatisitics(statBinsCnt, 1); //TODO
203 
204  for (unsigned int iLayer = 0; iLayer < gp->getPdf().size(); ++iLayer) {
205  for (unsigned int iRefLayer = 0; iRefLayer < gp->getPdf()[iLayer].size(); ++iRefLayer) {
206  ostrName.str("");
207  ostrName << "histLayerStat_PatNum_" << gp->key().theNumber << "_refLayer_" << iRefLayer << "_Layer_"
208  << iLayer;
209 
210  TH1I* histLayerStat = (TH1I*)curDir->Get(ostrName.str().c_str());
211 
212  if (histLayerStat) {
213  for (int iBin = 0; iBin < statBinsCnt; iBin++) {
214  gp->updateStat(iLayer, iRefLayer, iBin, 0, histLayerStat->GetBinContent(iBin + 1));
215  }
216  } else {
217  edm::LogImportant("l1tOmtfEventPrint")
218  << "PatternGenerator::endJob() - reading histLayerStat: histogram not found " << ostrName.str()
219  << std::endl;
220  }
221  }
222  }
223  }
224 
225  TH1* simMuFoundByOmtfPt_fromFile = (TH1*)inFile.Get("simMuFoundByOmtfPt");
226  for (unsigned int iGp = 0; iGp < eventCntPerGp.size(); iGp++) {
227  eventCntPerGp[iGp] = simMuFoundByOmtfPt_fromFile->GetBinContent(simMuFoundByOmtfPt_fromFile->FindBin(iGp));
228  edm::LogImportant("l1tOmtfEventPrint")
229  << "PatternGenerator::endJob() - eventCntPerGp: iGp" << iGp << " - " << eventCntPerGp[iGp] << std::endl;
230  }
231 
232  //TODO chose the desired grouping ///////////////
233  int group = 0;
234  int indexInGroup = 0;
235  for (auto& gp : goldenPatterns) {
236  indexInGroup++;
237  gp->key().setGroup(group);
238  gp->key().setIndexInGroup(indexInGroup);
239  //indexInGroup is counted from 1
240 
241  edm::LogImportant("l1tOmtfEventPrint")
242  << "setGroup(group): group " << group << " indexInGroup " << indexInGroup << std::endl;
243 
244  if (gp->key().thePt <= 10 && indexInGroup == 2) { //TODO
245  indexInGroup = 0;
246  group++;
247  }
248 
249  if (gp->key().thePt > 10 && indexInGroup == 4) { //TODO
250  indexInGroup = 0;
251  group++;
252  }
253  }
254 
255  upadatePdfs();
256 
257  modifyClassProb(1);
258 
259  //groupPatterns(); IMPORTANT don't call grouping here, just set the groups above!!!!
260 
261  reCalibratePt();
262  this->writeLayerStat = true;
263  }
264 
266 }
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 592 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().

592  {
593  int group = 0;
594  int indexInGroup = 0;
595  for (auto& gp : goldenPatterns) {
596  indexInGroup++;
597  gp->key().setGroup(group);
598  gp->key().setIndexInGroup(indexInGroup);
599  //indexInGroup is counted from 1
600 
601  edm::LogImportant("l1tOmtfEventPrint")
602  << "setGroup(group): group " << group << " indexInGroup " << indexInGroup << std::endl;
603 
604  if (gp->key().thePt <= 12 && indexInGroup == 2) { //TODO
605  indexInGroup = 0;
606  group++;
607  }
608 
609  if (gp->key().thePt > 12 && indexInGroup == 4) { //TODO
610  indexInGroup = 0;
611  group++;
612  }
613  }
614 
616  edm::LogImportant("l1tOmtfEventPrint") << "patternGroups:" << std::endl;
617  for (unsigned int iGroup = 0; iGroup < patternGroups.size(); iGroup++) {
618  edm::LogImportant("l1tOmtfEventPrint") << "patternGroup " << std::setw(2) << iGroup << " ";
619  for (unsigned int i = 0; i < patternGroups[iGroup].size(); i++) {
620  edm::LogImportant("l1tOmtfEventPrint") << i << " patNum " << patternGroups[iGroup][i] << " ";
621  }
622  edm::LogImportant("l1tOmtfEventPrint") << std::endl;
623  }
624 
625  int pdfBins = exp2(omtfConfig->nPdfAddrBits());
626 
627  for (unsigned int iLayer = 0; iLayer < goldenPatterns.at(0)->getPdf().size(); ++iLayer) {
628  for (unsigned int iRefLayer = 0; iRefLayer < goldenPatterns.at(0)->getPdf()[iLayer].size(); ++iRefLayer) {
629  //unsigned int refLayerLogicNum = omtfConfig->getRefToLogicNumber()[iRefLayer];
630  //if(refLayerLogicNum == iLayer)
631  {
632  //averaging the meanDistPhi for the gp belonging to the same group
633  for (unsigned int iGroup = 0; iGroup < patternGroups.size(); iGroup++) {
634  double meanDistPhi = 0;
635  int mergedCnt = 0;
636  for (unsigned int i = 0; i < patternGroups[iGroup].size(); i++) {
637  auto gp = goldenPatterns.at(patternGroups[iGroup][i]).get();
638  meanDistPhi += gp->meanDistPhiValue(iLayer, iRefLayer);
639  if (gp->meanDistPhiValue(iLayer, iRefLayer) != 0)
640  mergedCnt++;
641  edm::LogImportant("l1tOmtfEventPrint")
642  << __FUNCTION__ << ": " << __LINE__ << " iGroup " << iGroup << " numInGroup " << i << " " << gp->key()
643  << " iLayer " << iLayer << " iRefLayer " << iRefLayer << " old meanDistPhiValue "
644  << gp->meanDistPhiValue(iLayer, iRefLayer) << endl;
645  }
646 
647  if (mergedCnt) {
648  meanDistPhi /= mergedCnt;
649  meanDistPhi = (int)meanDistPhi;
650 
651  //because for some gps the statistics can be too low, and then the meanDistPhiValue is 0, so it should not contribute
652  for (unsigned int i = 0; i < patternGroups[iGroup].size(); i++) {
653  auto gp = goldenPatterns.at(patternGroups[iGroup][i]).get();
654  unsigned int refLayerLogicNum = omtfConfig->getRefToLogicNumber()[iRefLayer];
655  if (refLayerLogicNum != iLayer) {
656  int shift = meanDistPhi - gp->meanDistPhiValue(iLayer, iRefLayer);
657  edm::LogImportant("l1tOmtfEventPrint")
658  << __FUNCTION__ << ": " << __LINE__ << " iGroup " << iGroup << " numInGroup " << i << " "
659  << gp->key() << " iLayer " << iLayer << " iRefLayer " << iRefLayer
660  << " new meanDistPhi after averaging " << meanDistPhi << " old meanDistPhiValue "
661  << gp->meanDistPhiValue(iLayer, iRefLayer) << " shift " << shift << endl;
662 
663  if (shift < 0) {
664  for (int iBin = 1 - shift; iBin < pdfBins;
665  iBin++) { //iBin = 0 i.e. no hit is included here, to have the proper norm
666  auto pdfVal = gp->pdfValue(iLayer, iRefLayer, iBin);
667  gp->setPdfValue(pdfVal, iLayer, iRefLayer, iBin + shift);
668  edm::LogImportant("l1tOmtfEventPrint")
669  << " iBin " << iBin << " iBin + shift " << iBin + shift << " pdfVal " << pdfVal << endl;
670  }
671  for (int iBin = pdfBins + shift; iBin < pdfBins; iBin++) {
672  gp->setPdfValue(0, iLayer, iRefLayer, iBin);
673  }
674  } else if (shift > 0) {
675  for (int iBin = pdfBins - 1 - shift; iBin > 0;
676  iBin--) { //iBin = 0 i.e. no hit is included here, to have the proper norm
677  auto pdfVal = gp->pdfValue(iLayer, iRefLayer, iBin);
678  gp->setPdfValue(pdfVal, iLayer, iRefLayer, iBin + shift);
679  edm::LogImportant("l1tOmtfEventPrint")
680  << " iBin " << iBin << " iBin + shift " << iBin + shift << " pdfVal " << pdfVal << endl;
681  }
682  for (int iBin = shift; iBin > 0; iBin--) {
683  gp->setPdfValue(0, iLayer, iRefLayer, iBin);
684  }
685  }
686  }
687 
688  gp->setMeanDistPhiValue(round(meanDistPhi), iLayer, iRefLayer);
689  }
690  }
691  }
692  }
693  }
694  }
695 }
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 29 of file PatternGenerator.cc.

References PatternOptimizerBase::goldenPatterns, runTauDisplay::gp, and mps_fire::i.

Referenced by PatternGenerator().

29  {
30  //reseting the golden patterns
31  unsigned int i = 0;
32  for (auto& gp : goldenPatterns) {
33  gp->setKeyNumber(i++); //needed if patterns were added
34 
35  if (gp->key().thePt == 0)
36  continue;
37 
38  gp->reset();
39 
40  int statBinsCnt = 1024; //gp->getPdf()[0][0].size() * 8; //TODO should be big enough to comprise the pdf tails
41  gp->iniStatisitics(statBinsCnt, 1); //TODO
42  }
43 
44  edm::LogImportant("l1tOmtfEventPrint") << "PatternGenerator::initPatternGen():" << __LINE__
45  << " goldenPatterns.size() " << goldenPatterns.size() << std::endl;
46 
47  //GoldenPatternResult::setFinalizeFunction(3); TODO why it was this one????
48  // edm::LogImportant("l1tOmtfEventPrint") << "reseting golden pattern !!!!!" << std::endl;
49 
50  //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,
51  //and then the omtfCand will come from the processor that has the biggest number of fired layers
52  //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)
53  // - the below does not matter
54  for (auto& gp : goldenPatterns) {
55  for (unsigned int iLayer = 0; iLayer < gp->getPdf().size(); ++iLayer) {
56  for (unsigned int iRefLayer = 0; iRefLayer < gp->getPdf()[iLayer].size(); ++iRefLayer) {
57  for (unsigned int iBin = 0; iBin < gp->getPdf()[iLayer][iRefLayer].size(); iBin++) {
58  gp->pdfAllRef[iLayer][iRefLayer][iBin] = 1;
59  }
60  }
61  }
62  }
63 
64  //TODO uncomment if filling the ptDeltaPhiHist is needed
65  /* ptDeltaPhiHists.resize(2);
66  for(unsigned int iCharge = 0; iCharge <= 1; iCharge++) {
67  for(unsigned int iLayer = 0; iLayer < omtfConfig->nLayers(); ++iLayer) { //for the moment filing only ref layer, remove whe
68  if(iLayer == 0 || iLayer == 2 || iLayer == 4 || iLayer == 6 || iLayer == 7 || iLayer == 10 || iLayer == 11 || iLayer == 16 || //refLayars
69  iLayer == 1 || iLayer == 3 || iLayer == 5 ) //bending layers
70  {
71  ostringstream name;
72  name<<"ptDeltaPhiHist_ch_"<<iCharge<<"_Layer_"<<iLayer;
73  int phiFrom = -10;
74  int phiTo = 300; //TODO
75  int phiBins = phiTo - phiFrom;
76 
77  if(iCharge == 1) {
78  phiFrom = -300; //TODO
79  phiTo = 10;
80  }
81 
82  TH2I* ptDeltaPhiHist = new TH2I(name.str().c_str(), name.str().c_str(), 400, 0, 200, phiBins, phiFrom -0.5, phiTo -0.5);
83  //cout<<"BinLowEdge "<<ptDeltaPhiHist->GetYaxis()->GetBinLowEdge(100)<<" BinUpEdge "<<ptDeltaPhiHist->GetYaxis()->GetBinUpEdge(100);
84  ptDeltaPhiHists[iCharge].push_back(ptDeltaPhiHist);
85  }
86  else
87  ptDeltaPhiHists[iCharge].push_back(nullptr);
88  }
89  }*/
90 
91  /* cannot be called here, will cause crash
92  edm::LogImportant("OMTFReconstruction")<<" PatternGenerator constructor - patterns after modification "<<std::endl;
93  for(auto& gp : goldenPatterns) {
94  edm::LogImportant("OMTFReconstruction")<<gp->key()<<" "
95  <<omtfConfig->getPatternPtRange(gp->key().theNumber).ptFrom
96  <<" - "<<omtfConfig->getPatternPtRange(gp->key().theNumber).ptTo<<" GeV"<<std::endl;
97  }*/
98 }
Log< level::Error, true > LogImportant
GoldenPatternVec< GoldenPatternWithStat > & goldenPatterns

◆ modifyClassProb()

void PatternGenerator::modifyClassProb ( double  step)
protected

Definition at line 469 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().

469  {
470  edm::LogImportant("l1tOmtfEventPrint") << __FUNCTION__ << ": " << __LINE__ << " Correcting P(C_k) " << std::endl;
471  unsigned int iPdf = omtfConfig->nPdfBins() / 2; // <<(omtfConfig->nPdfAddrBits()-1);
472  for (unsigned int iRefLayer = 0; iRefLayer < goldenPatterns[0]->getPdf()[0].size(); ++iRefLayer) {
473  unsigned int refLayerLogicNumber = omtfConfig->getRefToLogicNumber()[iRefLayer];
474  if (iRefLayer == 0 || iRefLayer == 2) //DT
475  step = 1.5;
476  else if (iRefLayer == 5) //DT
477  step = 1.5;
478  else if (iRefLayer == 1) //CSC
479  step = 1.5;
480  else if (iRefLayer == 3) //CSC
481  step = 1.5;
482  else if (iRefLayer == 5) //RE2/3
483  step = 1.5;
484  else if (iRefLayer == 6 || iRefLayer == 7) //bRPC
485  step = 1.5;
486 
487  edm::LogImportant("l1tOmtfEventPrint")
488  << __FUNCTION__ << ":" << __LINE__ << " RefLayer " << iRefLayer << " step " << step << std::endl;
489  for (int sign = -1; sign <= 1; sign++) {
491  if (gp->key().thePt == 0 || gp->key().theCharge != sign)
492  continue;
493 
494  double ptFrom = omtfConfig->getPatternPtRange(gp->key().theNumber).ptFrom;
495  double ptTo = omtfConfig->getPatternPtRange(gp->key().theNumber).ptTo;
496 
497  double ptRange = ptTo - ptFrom;
498 
499  double minPdfValFactor = 0.1;
500  double minPlog = log(omtfConfig->minPdfVal() * minPdfValFactor);
501  double pdfMaxVal = omtfConfig->pdfMaxValue();
502 
503  pdfMaxVal /= 3.;
504  minPlog *= 2;
505 
506  //last bin of the ptRange goes to 10000, so here we change it to 1000
507  if (ptRange > 800)
508  ptRange = 800;
509 
510  double norm = 0.001;
511  double classProb = vxIntegMuRate(ptFrom, ptRange, 0.82, 1.24) * norm;
512 
513  int digitisedVal = rint(pdfMaxVal - log(classProb) / minPlog * pdfMaxVal);
514 
515  int newPdfVal = digitisedVal; //gp->getPdf()[refLayerLogicNumber][iRefLayer][iPdf]
516 
517  if (ptFrom == 0)
518  newPdfVal += 15;
519  if (ptFrom == 3.5)
520  newPdfVal += 15;
521  if (ptFrom == 4)
522  newPdfVal += 12;
523  if (ptFrom == 4.5)
524  newPdfVal += 9;
525  if (ptFrom == 5)
526  newPdfVal += 7;
527  if (ptFrom == 6)
528  newPdfVal += 4;
529  if (ptFrom == 7)
530  newPdfVal += 2;
531 
532  if (ptFrom == 100)
533  newPdfVal = 16;
534  if (ptFrom == 200)
535  newPdfVal = 22;
536 
537  gp->setPdfValue(newPdfVal, refLayerLogicNumber, iRefLayer, iPdf);
538 
539  edm::LogImportant("l1tOmtfEventPrint")
540  << gp->key() << " " << omtfConfig->getPatternPtRange(gp->key().theNumber).ptFrom << " - "
541  << omtfConfig->getPatternPtRange(gp->key().theNumber).ptTo << " GeV"
542  << " ptRange " << ptRange << " RefLayer " << iRefLayer << " newPdfVal " << newPdfVal << std::endl;
543  }
544  }
545  }
546 }
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 169 of file PatternGenerator.cc.

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

170  {
171  if (simMuon == nullptr || omtfCand->getGoldenPatern() == nullptr) //no sim muon or empty candidate
172  return;
173 
174  if (abs(simMuon->momentum().eta()) < 0.8 || abs(simMuon->momentum().eta()) > 1.24)
175  return;
176 
178 
179  updateStat();
180 }
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

◆ reCalibratePt()

void PatternGenerator::reCalibratePt ( )
protected

Definition at line 548 of file PatternGenerator.cc.

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

Referenced by endJob().

548  {
549  edm::LogImportant("l1tOmtfEventPrint") << __FUNCTION__ << ": " << __LINE__ << " reCalibratePt" << std::endl;
550  std::map<int, float> ptMap;
551  //for Patterns_0x0009_oldSample_3_10Files_classProb2.xml
552  ptMap[7] = 4.0;
553  ptMap[8] = 4.5;
554  ptMap[9] = 5.0;
555  ptMap[10] = 5.5;
556  ptMap[11] = 6.0;
557  ptMap[13] = 7.0;
558  ptMap[15] = 8.5;
559  ptMap[17] = 10.0;
560  ptMap[21] = 12.0;
561  ptMap[25] = 14.0;
562  ptMap[29] = 16.0;
563  ptMap[33] = 18.5;
564  ptMap[37] = 21.0;
565  ptMap[41] = 23.0;
566  ptMap[45] = 26.0;
567  ptMap[49] = 28.0;
568  ptMap[53] = 30.0;
569  ptMap[57] = 32.0;
570  ptMap[61] = 36.0;
571  ptMap[71] = 40.0;
572  ptMap[81] = 48.0;
573  ptMap[91] = 54.0;
574  ptMap[101] = 60.0;
575  ptMap[121] = 70.0;
576  ptMap[141] = 82.0;
577  ptMap[161] = 96.0;
578  ptMap[201] = 114.0;
579  ptMap[401] = 200.0;
580 
581  for (auto& gp : goldenPatterns) {
582  if (gp->key().thePt == 0)
583  continue;
584 
585  int newPt = omtfConfig->ptGevToHw(ptMap[gp->key().thePt]);
586  edm::LogImportant("l1tOmtfEventPrint") << gp->key().thePt << " -> " << newPt << std::endl;
587 
588  gp->key().setPt(newPt);
589  }
590 }
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 457 of file PatternGenerator.cc.

References timingPdfMaker::outfile.

457  {
458  outfile.mkdir("ptDeltaPhiHists")->cd();
459  //TODO uncomment if ptDeltaPhiHists are needed
460  /* for(unsigned int iCharge = 0; iCharge <= 1; iCharge++) {
461  for(unsigned int iLayer = 0; iLayer < omtfConfig->nLayers(); ++iLayer) { //for the moment filing only ref layer, remove whe
462  if(ptDeltaPhiHists[iCharge][iLayer]) {
463  ptDeltaPhiHists[iCharge][iLayer]->Write();
464  }
465  }
466  }*/
467 }

◆ upadatePdfs()

void PatternGenerator::upadatePdfs ( )
protected

Definition at line 268 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(), and to_string().

Referenced by endJob().

268  {
269  //TODO setting the DistPhiBitShift i.e. grouping of the pdfBins
270  for (auto& gp : goldenPatterns) {
271  if (gp->key().thePt == 0)
272  continue;
273  for (unsigned int iLayer = 0; iLayer < gp->getPdf().size(); ++iLayer) {
274  for (unsigned int iRefLayer = 0; iRefLayer < gp->getPdf()[iLayer].size(); ++iRefLayer) {
275  if (gp->getDistPhiBitShift(iLayer, iRefLayer)) {
276  throw runtime_error(
277  string(__FUNCTION__) + ":" + to_string(__LINE__) +
278  "gp->getDistPhiBitShift(iLayer, iRefLayer) != 0 - cannot change DistPhiBitShift then!!!!");
279  }
280 
281  if ((gp->key().thePt <= 10) && (iLayer == 1 || iLayer == 3 || iLayer == 5)) {
282  gp->setDistPhiBitShift(1, iLayer, iRefLayer);
283  } else
284  gp->setDistPhiBitShift(0, iLayer, iRefLayer);
285 
286  //watch out: the shift in a given layer must be the same for patterns in one group
287  //todo make the setting of the shift on the group base
288  //TODO set the DistPhiBitShift
289  /*if( (gp->key().thePt <= 10) && (iLayer == 3 || iLayer == 5 ) && (iRefLayer == 0 || iRefLayer == 2 || iRefLayer == 6 || iRefLayer == 7)) {
290  gp->setDistPhiBitShift(3, iLayer, iRefLayer);
291  }
292  else if( (gp->key().thePt <= 10) && ( iLayer == 1 || iLayer == 3 || iLayer == 5 ) ) {
293  gp->setDistPhiBitShift(2, iLayer, iRefLayer);
294  }
295  else if( ( (gp->key().thePt <= 10) && (iLayer == 7 ||iLayer == 8 || iLayer == 17 ) ) ) {
296  gp->setDistPhiBitShift(1, iLayer, iRefLayer);
297  }
298  else if( (gp->key().thePt <= 10) && (iLayer == 10 || iLayer == 11 || iLayer == 12 || iLayer == 13) && (iRefLayer == 1)) {
299  gp->setDistPhiBitShift(1, iLayer, iRefLayer);
300  }*/
301  }
302  }
303  }
304 
305  double minHitCntThresh = 0.001;
306  //Calculating meanDistPhi
307  for (auto& gp : goldenPatterns) {
308  if (gp->key().thePt == 0)
309  continue;
310 
311  int minHitCnt = minHitCntThresh * eventCntPerGp[gp->key().number()]; // //TODO tune threshold <<<<<<<<<<<<<<<<<<
312  edm::LogImportant("l1tOmtfEventPrint")
313  << "PatternGenerator::upadatePdfs() Calculating meanDistPhi " << gp->key() << " eventCnt "
314  << eventCntPerGp[gp->key().number()] << " minHitCnt " << minHitCnt << std::endl;
315 
316  for (unsigned int iLayer = 0; iLayer < gp->getPdf().size(); ++iLayer) {
317  for (unsigned int iRefLayer = 0; iRefLayer < gp->getPdf()[iLayer].size(); ++iRefLayer) {
318  //calculate meanDistPhi
319  double meanDistPhi = 0;
320  double count = 0;
321  for (unsigned int iBin = 1; iBin < gp->getStatistics()[iLayer][iRefLayer].size(); iBin++) {
322  //iBin = 0 is reserved for the no hit
323  meanDistPhi += iBin * gp->getStatistics()[iLayer][iRefLayer][iBin][0];
324  count += gp->getStatistics()[iLayer][iRefLayer][iBin][0];
325  }
326 
327  if (count != 0) {
328  meanDistPhi /= count;
329 
330  meanDistPhi -= (gp->getStatistics()[iLayer][iRefLayer].size() / 2);
331 
332  if (count < minHitCnt)
333  meanDistPhi = 0;
334  else
335  edm::LogImportant("l1tOmtfEventPrint")
336  << __FUNCTION__ << ": " << __LINE__ << " " << gp->key() << " iLayer " << iLayer << " iRefLayer "
337  << iRefLayer << " count " << count << " meanDistPhi " << meanDistPhi << endl;
338  }
339  gp->setMeanDistPhiValue(round(meanDistPhi), iLayer, iRefLayer);
340  }
341  }
342  }
343 
345  edm::LogImportant("l1tOmtfEventPrint") << "patternGroups:" << std::endl;
346  for (unsigned int iGroup = 0; iGroup < patternGroups.size(); iGroup++) {
347  edm::LogImportant("l1tOmtfEventPrint") << "patternGroup " << std::setw(2) << iGroup << " ";
348  for (unsigned int i = 0; i < patternGroups[iGroup].size(); i++) {
349  edm::LogImportant("l1tOmtfEventPrint") << i << " patNum " << patternGroups[iGroup][i] << " ";
350  }
351  edm::LogImportant("l1tOmtfEventPrint") << std::endl;
352  }
353 
354  //averaging the meanDistPhi for the gp belonging to the same group
355  for (unsigned int iLayer = 0; iLayer < goldenPatterns.at(0)->getPdf().size(); ++iLayer) {
356  for (unsigned int iRefLayer = 0; iRefLayer < goldenPatterns.at(0)->getPdf()[iLayer].size(); ++iRefLayer) {
357  //unsigned int refLayerLogicNum = omtfConfig->getRefToLogicNumber()[iRefLayer];
358  //if(refLayerLogicNum == iLayer)
359  {
360  for (unsigned int iGroup = 0; iGroup < patternGroups.size(); iGroup++) {
361  double meanDistPhi = 0;
362  int mergedCnt = 0;
363  for (unsigned int i = 0; i < patternGroups[iGroup].size(); i++) {
364  auto gp = goldenPatterns.at(patternGroups[iGroup][i]).get();
365  meanDistPhi += gp->meanDistPhiValue(iLayer, iRefLayer);
366  if (gp->meanDistPhiValue(iLayer, iRefLayer) != 0)
367  mergedCnt++;
368  }
369 
370  if (mergedCnt) {
371  meanDistPhi /= mergedCnt;
372  //because for some gps the statistics can be too low, and then the meanDistPhiValue is 0, so it should not contribute
373  for (unsigned int i = 0; i < patternGroups[iGroup].size(); i++) {
374  auto gp = goldenPatterns.at(patternGroups[iGroup][i]).get();
375  gp->setMeanDistPhiValue(round(meanDistPhi), iLayer, iRefLayer);
376  edm::LogImportant("l1tOmtfEventPrint")
377  << __FUNCTION__ << ": " << __LINE__ << " iGroup " << iGroup << " numInGroup " << i << " " << gp->key()
378  << " iLayer " << iLayer << " iRefLayer " << iRefLayer << " meanDistPhi after averaging "
379  << meanDistPhi << endl;
380  }
381  }
382  }
383  }
384  }
385  }
386 
387  //calculating the pdfs
388  for (auto& gp : goldenPatterns) {
389  if (gp->key().thePt == 0)
390  continue;
391 
392  //TODO tune threshold <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
393  int minHitCnt = 2 * minHitCntThresh * eventCntPerGp[gp->key().number()];
394 
395  for (unsigned int iLayer = 0; iLayer < gp->getPdf().size(); ++iLayer) {
396  for (unsigned int iRefLayer = 0; iRefLayer < gp->getPdf()[iLayer].size(); ++iRefLayer) {
397  {
398  double norm = 0;
399  for (unsigned int iBin = 0; iBin < gp->getStatistics()[iLayer][iRefLayer].size();
400  iBin++) { //iBin = 0 i.e. no hit is included here, to have the proper norm
401  norm += gp->getStatistics()[iLayer][iRefLayer][iBin][0];
402  }
403 
404  int pdfMiddle = gp->getPdf()[iLayer][iRefLayer].size() / 2;
405  int statBinGroupSize = 1 << gp->getDistPhiBitShift(iLayer, iRefLayer);
406  for (unsigned int iBinPdf = 0; iBinPdf < gp->getPdf()[iLayer][iRefLayer].size(); iBinPdf++) {
407  double pdfVal = 0;
408  if (iBinPdf > 0) {
409  for (int i = 0; i < statBinGroupSize; i++) {
410  int iBinStat =
411  statBinGroupSize * ((int)(iBinPdf)-pdfMiddle) + i + gp->meanDistPhiValue(iLayer, iRefLayer);
412 
413  iBinStat += (gp->getStatistics()[iLayer][iRefLayer].size() / 2);
414 
415  if (iBinStat >= 0 && iBinStat < (int)gp->getStatistics()[iLayer][iRefLayer].size()) {
416  pdfVal += gp->getStatistics()[iLayer][iRefLayer][iBinStat][0];
417  //cout<<__FUNCTION__<<": "<<__LINE__<<" "<<gp->key()<<" iLayer "<<iLayer<<" iBinStat "<<iBinStat<<" iBinPdf "<<iBinPdf<<" statVal "<<gp->getStatistics()[iLayer][iRefLayer][iBinStat][0]<<endl;
418  }
419  }
420  if (norm > minHitCnt) {
421  pdfVal /= (norm * statBinGroupSize);
422  } else
423  pdfVal = 0;
424  /*edm::LogImportant("l1tOmtfEventPrint")
425  << __FUNCTION__ << ": " << __LINE__ << " " << gp->key() << "calculating pdf: iLayer " << iLayer
426  << " iRefLayer " << iRefLayer //<< " norm " << std::setw(5) << norm
427  << " pdfVal " << pdfVal << endl;*/
428  } else { //iBinPdf == 0 i.e. no hit
429  int iBinStat = 0;
430  if (norm > 0) {
431  pdfVal = gp->getStatistics()[iLayer][iRefLayer][iBinStat][0] / norm;
432  }
433  edm::LogImportant("l1tOmtfEventPrint")
434  << __FUNCTION__ << ": " << __LINE__ << " " << gp->key() << "calculating pdf: iLayer " << iLayer
435  << " iRefLayer " << iRefLayer << " norm " << std::setw(5) << norm << " no hits cnt " << std::setw(5)
436  << gp->getStatistics()[iLayer][iRefLayer][iBinStat][0] << " pdfVal " << pdfVal << endl;
437  }
438 
439  double minPdfValFactor = 1;
440  const double minPlog = log(omtfConfig->minPdfVal() * minPdfValFactor);
441  const double pdfMaxVal = omtfConfig->pdfMaxValue();
442 
443  int digitisedVal = 0;
444  if (pdfVal >= omtfConfig->minPdfVal() * minPdfValFactor) {
445  digitisedVal = rint(pdfMaxVal - log(pdfVal) / minPlog * pdfMaxVal);
446  }
447 
448  gp->setPdfValue(digitisedVal, iLayer, iRefLayer, iBinPdf);
449  //cout<<__FUNCTION__<<": "<<__LINE__<<" "<<gp->key()<<" iLayer "<<iLayer<<" iBinPdf "<<iBinPdf<<" pdfVal "<<pdfVal<<" digitisedVal "<<digitisedVal<<endl;
450  }
451  }
452  }
453  }
454  }
455 }
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 100 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 observeEventEnd().

100  {
101  //cout<<__FUNCTION__<<":"<<__LINE__<<" omtfCand "<<*omtfCand<<std::endl;;
102  AlgoMuon* algoMuon = omtfCand.get();
103  if (!algoMuon) {
104  edm::LogImportant("l1tOmtfEventPrint") << ":" << __LINE__ << " algoMuon is null" << std::endl;
105  throw runtime_error("algoMuon is null");
106  }
107 
108  double ptSim = simMuon->momentum().pt();
109  int chargeSim = (abs(simMuon->type()) == 13) ? simMuon->type() / -13 : 0;
110 
111  unsigned int exptPatNum = omtfConfig->getPatternNum(ptSim, chargeSim);
112  GoldenPatternWithStat* exptCandGp = goldenPatterns.at(exptPatNum).get(); // expected pattern
113 
114  eventCntPerGp[exptPatNum]++;
115 
116  //edm::LogImportant("l1tOmtfEventPrint")<<"\n" <<__FUNCTION__<<": "<<__LINE__<<" exptCandGp "<<exptCandGp->key()<<" candProcIndx "<<candProcIndx<<" ptSim "<<ptSim<<" chargeSim "<<chargeSim<<std::endl;
117 
118  int pdfMiddle = 1 << (omtfConfig->nPdfAddrBits() - 1);
119 
120  //iRefHit is the index of the hit
121  for (unsigned int iRefHit = 0; iRefHit < exptCandGp->getResults()[candProcIndx].size(); ++iRefHit) {
122  auto& gpResult = exptCandGp->getResults()[candProcIndx][iRefHit];
123 
124  unsigned int refLayer = gpResult.getRefLayer();
125 
126  if (gpResult.getFiredLayerCnt() >= 3) {
127  for (unsigned int iLayer = 0; iLayer < gpResult.getStubResults().size(); iLayer++) {
128  //updating statistic for the gp which should have fired
129 
130  bool fired = false;
131  if (gpResult.getStubResults()[iLayer].getMuonStub()) {
132  if (omtfConfig->isBendingLayer(iLayer)) {
133  if (gpResult.getStubResults()[iLayer].getMuonStub()->qualityHw >= 4) //TODO change quality cut if needed
134  fired = true;
135  } else
136  fired = true;
137  }
138 
139  if (fired) { //the result is not empty
140  int phiDist = gpResult.getStubResults()[iLayer].getPdfBin();
141  phiDist += exptCandGp->meanDistPhiValue(iLayer, refLayer) - pdfMiddle;
142  //removing the shift applied in the GoldenPatternBase::process1Layer1RefLayer
143 
144  //TODO uncomment if filling ptDeltaPhiHists is needed
145  /*
146  unsigned int refLayerLogicNum = omtfConfig->getRefToLogicNumber()[iRefHit];
147  if(ptDeltaPhiHists[iCharge][iLayer] != nullptr &&
148  (iLayer == refLayerLogicNum || omtfConfig->getLogicToLogic().at(iLayer) == (int)refLayerLogicNum) )
149  ptDeltaPhiHists[iCharge][iLayer]->Fill(ttAlgoMuon->getPt(), phiDist); //TODO correct
150  */
151 
152  phiDist += exptCandGp->getStatistics()[iLayer][refLayer].size() / 2;
153 
154  //edm::LogImportant("l1tOmtfEventPrint")<<__FUNCTION__<<":"<<__LINE__<<" refLayer "<<refLayer<<" iLayer "<<iLayer<<" phiDist "<<phiDist<<" getPdfBin "<<gpResult.getStubResults()[iLayer].getPdfBin()<<std::endl;
155  if (phiDist > 0 && phiDist < (int)(exptCandGp->getStatistics()[iLayer][refLayer].size())) {
156  //updating statistic for the gp which found the candidate
157  //edm::LogImportant("l1tOmtfEventPrint")<<__FUNCTION__<<":"<<__LINE__<<" updating statistic "<<std::endl;
158  exptCandGp->updateStat(iLayer, refLayer, phiDist, 0, 1);
159  }
160  } else { //if there is no hit at all in a given layer, the bin = 0 is filled
161  int phiDist = 0;
162  exptCandGp->updateStat(iLayer, refLayer, phiDist, 0, 1);
163  }
164  }
165  }
166  }
167 }
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

Member Data Documentation

◆ eventCntPerGp

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

Definition at line 44 of file PatternGenerator.h.

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

◆ ptDeltaPhiHists

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

Definition at line 42 of file PatternGenerator.h.