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:303
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:303
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 594 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().

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

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

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

Referenced by endJob().

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

References timingPdfMaker::outfile.

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

◆ 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 cond::impl::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  int groupedBins = 0;
410  for (int i = 0; i < statBinGroupSize; i++) {
411  int iBinStat =
412  statBinGroupSize * ((int)(iBinPdf)-pdfMiddle) + i + gp->meanDistPhiValue(iLayer, iRefLayer);
413 
414  iBinStat += (gp->getStatistics()[iLayer][iRefLayer].size() / 2);
415 
416  if (iBinStat >= 0 && iBinStat < (int)gp->getStatistics()[iLayer][iRefLayer].size()) {
417  pdfVal += gp->getStatistics()[iLayer][iRefLayer][iBinStat][0];
418  groupedBins++;
419  //cout<<__FUNCTION__<<": "<<__LINE__<<" "<<gp->key()<<" iLayer "<<iLayer<<" iBinStat "<<iBinStat<<" iBinPdf "<<iBinPdf<<" statVal "<<gp->getStatistics()[iLayer][iRefLayer][iBinStat][0]<<endl;
420  }
421  }
422  if (norm > minHitCnt) {
423  pdfVal /= (norm * statBinGroupSize);
424  } else
425  pdfVal = 0;
426  /*edm::LogImportant("l1tOmtfEventPrint")
427  << __FUNCTION__ << ": " << __LINE__ << " " << gp->key() << "calculating pdf: iLayer " << iLayer
428  << " iRefLayer " << iRefLayer //<< " norm " << std::setw(5) << norm
429  << " pdfVal " << pdfVal << endl;*/
430  } else { //iBinPdf == 0 i.e. no hit
431  int iBinStat = 0;
432  if (norm > 0) {
433  pdfVal = gp->getStatistics()[iLayer][iRefLayer][iBinStat][0] / norm;
434  }
435  edm::LogImportant("l1tOmtfEventPrint")
436  << __FUNCTION__ << ": " << __LINE__ << " " << gp->key() << "calculating pdf: iLayer " << iLayer
437  << " iRefLayer " << iRefLayer << " norm " << std::setw(5) << norm << " no hits cnt " << std::setw(5)
438  << gp->getStatistics()[iLayer][iRefLayer][iBinStat][0] << " pdfVal " << pdfVal << endl;
439  }
440 
441  double minPdfValFactor = 1;
442  const double minPlog = log(omtfConfig->minPdfVal() * minPdfValFactor);
443  const double pdfMaxVal = omtfConfig->pdfMaxValue();
444 
445  int digitisedVal = 0;
446  if (pdfVal >= omtfConfig->minPdfVal() * minPdfValFactor) {
447  digitisedVal = rint(pdfMaxVal - log(pdfVal) / minPlog * pdfMaxVal);
448  }
449 
450  gp->setPdfValue(digitisedVal, iLayer, iRefLayer, iBinPdf);
451  //cout<<__FUNCTION__<<": "<<__LINE__<<" "<<gp->key()<<" iLayer "<<iLayer<<" iBinPdf "<<iBinPdf<<" pdfVal "<<pdfVal<<" digitisedVal "<<digitisedVal<<endl;
452  }
453  }
454  }
455  }
456  }
457 }
std::string to_string(const V &value)
Definition: OMSAccess.h:77
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.