CMS 3D CMS Logo

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

#include <PatternOptimizerBase.h>

Inheritance diagram for PatternOptimizerBase:
EmulationObserverBase IOMTFEmulationObserver PatternGenerator

Public Member Functions

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 ()
 

Static Public Member Functions

static double vxIntegMuRate (double pt_GeV, double dpt, double etaFrom, double etaTo)
 
static double vxMuRate (double pt_GeV)
 

Protected Member Functions

virtual double getEventRateWeight (double pt)
 
void printPatterns ()
 
virtual void saveHists (TFile &outfile)
 
void savePatternsInRoot (std::string rootFileName)
 

Protected Attributes

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
 

Detailed Description

Definition at line 25 of file PatternOptimizerBase.h.

Constructor & Destructor Documentation

◆ PatternOptimizerBase()

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

Definition at line 64 of file PatternOptimizerBase.cc.

References EmulationObserverBase::edmCfg, edm::ParameterSet::exists(), goldenPatterns, simMuFoundByOmtfPt, simMuPt, and simMuPtSpectrum.

68  // TODO Auto-generated constructor stub
69 
70  simMuPt = new TH1I("simMuPt", "simMuPt", goldenPatterns.size(), -0.5, goldenPatterns.size() - 0.5);
72  new TH1I("simMuFoundByOmtfPt", "simMuFoundByOmtfPt", goldenPatterns.size(), -0.5, goldenPatterns.size() - 0.5);
73 
74  simMuPtSpectrum = new TH1F("simMuPtSpectrum", "simMuPtSpectrum", 800, 0, 400);
75 
76  if (edmCfg.exists("simTracksTag") == false)
77  edm::LogError("l1tOmtfEventPrint") << "simTracksTag not found !!!" << std::endl;
78 }
EmulationObserverBase(const edm::ParameterSet &edmCfg, const OMTFConfiguration *omtfConfig)
bool exists(std::string const &parameterName) const
checks if a parameter exists
GoldenPatternVec< GoldenPatternWithStat > & goldenPatterns
const OMTFConfiguration * omtfConfig

◆ ~PatternOptimizerBase()

PatternOptimizerBase::~PatternOptimizerBase ( )
override

Definition at line 80 of file PatternOptimizerBase.cc.

80 {}

Member Function Documentation

◆ endJob()

void PatternOptimizerBase::endJob ( void  )
overridevirtual

Implements IOMTFEmulationObserver.

Definition at line 115 of file PatternOptimizerBase.cc.

References EmulationObserverBase::edmCfg, MainPageGenerator::fName, edm::ParameterSet::getParameter(), goldenPatterns, EmulationObserverBase::omtfConfig, savePatternsInRoot(), AlCaHLTBitMon_QueryRunRegistry::string, and XMLConfigWriter::writeGPs().

Referenced by PatternGenerator::endJob().

115  {
116  std::string fName = edmCfg.getParameter<std::string>("optimisedPatsXmlFile");
117  edm::LogImportant("PatternOptimizer") << " Writing optimized patterns to " << fName << std::endl;
118  XMLConfigWriter xmlWriter(omtfConfig, false, false);
119  xmlWriter.writeGPs(goldenPatterns, fName);
120 
121  fName.replace(fName.find('.'), fName.length(), ".root");
123 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Log< level::Error, true > LogImportant
GoldenPatternVec< GoldenPatternWithStat > & goldenPatterns
void savePatternsInRoot(std::string rootFileName)
const OMTFConfiguration * omtfConfig

◆ getEventRateWeight()

virtual double PatternOptimizerBase::getEventRateWeight ( double  pt)
inlineprotectedvirtual

Definition at line 46 of file PatternOptimizerBase.h.

Referenced by observeEventEnd().

46 { return 1; }

◆ observeEventEnd()

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

Reimplemented from IOMTFEmulationObserver.

Definition at line 100 of file PatternOptimizerBase.cc.

References funct::abs(), getEventRateWeight(), OMTFConfiguration::getPatternNum(), goldenPatterns, GoldenPattern::key(), CoreSimTrack::momentum(), EmulationObserverBase::omtfCand, EmulationObserverBase::omtfConfig, simMuFoundByOmtfPt, EmulationObserverBase::simMuon, simMuPtSpectrum, Key::theNumber, and CoreSimTrack::type().

Referenced by PatternGenerator::observeEventEnd().

101  {
102  if (simMuon == nullptr || omtfCand->getGoldenPatern() == nullptr) //no sim muon or empty candidate
103  return;
104 
105  double ptSim = simMuon->momentum().pt();
106  int chargeSim = (abs(simMuon->type()) == 13) ? simMuon->type() / -13 : 0;
107 
108  unsigned int exptPatNum = omtfConfig->getPatternNum(ptSim, chargeSim);
109  GoldenPatternWithStat* exptCandGp = goldenPatterns.at(exptPatNum).get(); // expected pattern
110  simMuFoundByOmtfPt->Fill(exptCandGp->key().theNumber); //TODO add weight of the muons pt spectrum
111 
112  simMuPtSpectrum->Fill(ptSim, getEventRateWeight(ptSim));
113 }
unsigned int theNumber
Definition: GoldenPattern.h:37
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
Key key() const
Definition: GoldenPattern.h:56
virtual double getEventRateWeight(double pt)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
GoldenPatternVec< GoldenPatternWithStat > & goldenPatterns
const OMTFConfiguration * omtfConfig

◆ printPatterns()

void PatternOptimizerBase::printPatterns ( )
protected

Definition at line 82 of file PatternOptimizerBase.cc.

References OMTFConfiguration::getPatternPtRange(), goldenPatterns, RPCConst::iptFromPt(), crabWrapper::key, EmulationObserverBase::omtfConfig, DiDispStaMuonMonitor_cfi::pt, and OMTFConfiguration::PatternPt::ptFrom.

82  {
83  edm::LogVerbatim("l1tOmtfEventPrint") << __FUNCTION__ << ": " << __LINE__ << " called!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! "
84  << std::endl;
85  for (int patNum = goldenPatterns.size() - 1; patNum >= 0; patNum--) {
86  double pt = omtfConfig->getPatternPtRange(patNum).ptFrom;
87  if (pt > 0) {
88  edm::LogVerbatim("l1tOmtfEventPrint")
89  << "cmsRun runThresholdCalc.py " << patNum << " " << (patNum + 1) << " _" << RPCConst::iptFromPt(pt) << "_";
90  if (goldenPatterns[patNum]->key().theCharge == -1)
91  edm::LogVerbatim("l1tOmtfEventPrint") << "m_";
92  else
93  edm::LogVerbatim("l1tOmtfEventPrint") << "p_";
94 
95  edm::LogVerbatim("l1tOmtfEventPrint") << " > out" << patNum << ".txt" << std::endl;
96  }
97  }
98 }
Log< level::Info, true > LogVerbatim
GoldenPatternVec< GoldenPatternWithStat > & goldenPatterns
PatternPt getPatternPtRange(unsigned int patNum) const
static int iptFromPt(const double pt)
Definition: RPCConst.cc:10
const OMTFConfiguration * omtfConfig

◆ saveHists()

virtual void PatternOptimizerBase::saveHists ( TFile &  outfile)
inlineprotectedvirtual

Reimplemented in PatternGenerator.

Definition at line 48 of file PatternOptimizerBase.h.

Referenced by savePatternsInRoot().

48 {};

◆ savePatternsInRoot()

void PatternOptimizerBase::savePatternsInRoot ( std::string  rootFileName)
protected

Definition at line 125 of file PatternOptimizerBase.cc.

References svgfig::canvas(), OMTFConfiguration::getPatternPtRange(), OMTFConfiguration::getRefToLogicNumber(), goldenPatterns, runTauDisplay::gp, compareTotals::hist, OMTFConfiguration::nPdfBins(), EmulationObserverBase::omtfConfig, timingPdfMaker::outfile, OMTFConfiguration::pdfMaxValue(), OMTFConfiguration::PatternPt::ptFrom, OMTFConfiguration::PatternPt::ptTo, CSCSkim_cfi::rootFileName, saveHists(), simMuFoundByOmtfPt, simMuPtSpectrum, and writeLayerStat.

Referenced by endJob().

125  {
126  gStyle->SetOptStat(111111);
127  TFile outfile(rootFileName.c_str(), "RECREATE");
128  edm::LogVerbatim("l1tOmtfEventPrint") << __FUNCTION__ << ": " << __LINE__ << " out fileName " << rootFileName
129  << " outfile->GetName() " << outfile.GetName() << " writeLayerStat "
130  << writeLayerStat << endl;
131 
132  outfile.cd();
133  simMuFoundByOmtfPt->Write();
134 
135  simMuPtSpectrum->Write();
136 
137  outfile.mkdir("patternsPdfs")->cd();
138  outfile.mkdir("patternsPdfs/canvases");
139  outfile.mkdir("layerStats");
140  ostringstream ostrName;
141  ostringstream ostrTtle;
142  vector<TH1F*> classProbHists;
143  for (unsigned int iRefLayer = 0; iRefLayer < goldenPatterns[0]->getPdf()[0].size(); ++iRefLayer) {
144  ostrName.str("");
145  ostrName << "Neg_RefLayer_" << iRefLayer;
146  ostrTtle.str("");
147  ostrTtle << "Neg_RefLayer_" << iRefLayer;
148  classProbHists.push_back(new TH1F(
149  ostrName.str().c_str(), ostrTtle.str().c_str(), goldenPatterns.size(), -0.5, goldenPatterns.size() - 0.5));
150 
151  ostrName.str("");
152  ostrName << "Pos_RefLayer_" << iRefLayer;
153  ostrTtle.str("");
154  ostrTtle << "Pos_RefLayer_" << iRefLayer;
155  classProbHists.push_back(new TH1F(
156  ostrName.str().c_str(), ostrTtle.str().c_str(), goldenPatterns.size(), -0.5, goldenPatterns.size() - 0.5));
157  }
158 
159  for (auto& gp : goldenPatterns) {
160  OMTFConfiguration::PatternPt patternPt = omtfConfig->getPatternPtRange(gp->key().theNumber);
161  if (gp->key().thePt == 0)
162  continue;
163  //edm::LogVerbatim("l1tOmtfEventPrint") <<__FUNCTION__<<": "<<__LINE__<<" "<<gp->key()<<std::endl;
164  ostrName.str("");
165  ostrName << "PatNum_" << gp->key().theNumber;
166  ostrTtle.str("");
167  ostrTtle << "PatNum_" << gp->key().theNumber << "_ptCode_" << gp->key().thePt << "_Pt_" << patternPt.ptFrom << "_"
168  << patternPt.ptTo << "_GeV";
169  TCanvas* canvas = new TCanvas(ostrName.str().c_str(), ostrTtle.str().c_str(), 1200, 1000);
170  canvas->Divide(gp->getPdf().size(), gp->getPdf()[0].size(), 0, 0);
171 
172  for (unsigned int iLayer = 0; iLayer < gp->getPdf().size(); ++iLayer) {
173  for (unsigned int iRefLayer = 0; iRefLayer < gp->getPdf()[iLayer].size(); ++iRefLayer) {
174  canvas->cd(1 + iLayer + iRefLayer * gp->getPdf().size());
175  ostrName.str("");
176  ostrName << "PatNum_" << gp->key().theNumber << "_refLayer_" << iRefLayer << "_Layer_" << iLayer;
177  ostrTtle.str("");
178  ostrTtle << "PatNum " << gp->key().theNumber << " ptCode " << gp->key().thePt << " refLayer " << iRefLayer
179  << " Layer " << iLayer << " meanDistPhi " << gp->meanDistPhi[iLayer][iRefLayer][0]
180  << " distPhiBitShift "
181  << gp->getDistPhiBitShift(iLayer, iRefLayer); //"_Pt_"<<patternPt.ptFrom<<"_"<<patternPt.ptTo<<"_GeV
182  //edm::LogVerbatim("l1tOmtfEventPrint") <<__FUNCTION__<<": "<<__LINE__<<" creating hist "<<ostrTtle.str()<<std::endl;
183  TH1F* hist = new TH1F(
184  ostrName.str().c_str(), ostrTtle.str().c_str(), omtfConfig->nPdfBins(), -0.5, omtfConfig->nPdfBins() - 0.5);
185  for (unsigned int iPdf = 0; iPdf < gp->getPdf()[iLayer][iRefLayer].size(); iPdf++) {
186  hist->Fill(iPdf, gp->pdfAllRef[iLayer][iRefLayer][iPdf]);
187  }
188  if ((int)iLayer == (omtfConfig->getRefToLogicNumber()[iRefLayer]))
189  hist->SetLineColor(kGreen);
190 
191  hist->GetYaxis()->SetRangeUser(0, omtfConfig->pdfMaxValue() + 1);
192  hist->Draw("hist");
193 
194  outfile.cd("patternsPdfs");
195  hist->Write();
196 
198  if (writeLayerStat) {
199  string histName = "histLayerStat_" + ostrName.str();
200  unsigned int binCnt = gp->getStatistics()[iLayer][iRefLayer].size();
201  TH1I* histLayerStat = new TH1I(histName.c_str(), histName.c_str(), binCnt, -0.5, binCnt - 0.5);
202  for (unsigned int iBin = 0; iBin < binCnt; iBin++) {
203  histLayerStat->Fill(iBin, gp->getStatistics()[iLayer][iRefLayer][iBin][0]);
204  }
205 
206  outfile.cd("layerStats");
207  histLayerStat->Write();
208  }
209  }
210  }
211  outfile.cd("patternsPdfs/canvases");
212  canvas->Write();
213  delete canvas;
214 
215  unsigned int iPdf = omtfConfig->nPdfBins() / 2;
216  for (unsigned int iRefLayer = 0; iRefLayer < gp->getPdf()[0].size(); ++iRefLayer) {
217  unsigned int refLayerLogicNumber = omtfConfig->getRefToLogicNumber()[iRefLayer];
218  if (gp->key().theCharge == -1) {
219  classProbHists[2 * iRefLayer]->Fill(gp->key().theNumber, gp->pdfAllRef[refLayerLogicNumber][iRefLayer][iPdf]);
220  } else
221  classProbHists[2 * iRefLayer + 1]->Fill(gp->key().theNumber,
222  gp->pdfAllRef[refLayerLogicNumber][iRefLayer][iPdf]);
223  }
224  }
225 
226  outfile.cd();
227  for (auto& classProbHist : classProbHists) {
228  classProbHist->Write();
229  }
230 
232 
233  outfile.Close();
234 }
Log< level::Info, true > LogVerbatim
pattern pt range in Gev
const std::vector< int > & getRefToLogicNumber() const
virtual void saveHists(TFile &outfile)
GoldenPatternVec< GoldenPatternWithStat > & goldenPatterns
PatternPt getPatternPtRange(unsigned int patNum) const
def canvas(sub, attr)
Definition: svgfig.py:482
unsigned int nPdfBins() const
const OMTFConfiguration * omtfConfig

◆ vxIntegMuRate()

double PatternOptimizerBase::vxIntegMuRate ( double  pt_GeV,
double  dpt,
double  etaFrom,
double  etaTo 
)
static

Definition at line 55 of file PatternOptimizerBase.cc.

References RPCpg::rate(), and vxMuRate().

Referenced by PatternGenerator::modifyClassProb().

55  {
56  //integration using trapeze method - not exact but good enough
57  double rate = 0.5 * (vxMuRate(pt_GeV) + vxMuRate(pt_GeV + dpt)) * dpt;
58 
59  rate = rate * (etaTo - etaFrom);
60  //edm::LogError("l1tOmtfEventPrint")<<ptCode<<" "<<rate;//<<<<<<<<<<<<<<<<<<<<<<<<
61  return rate;
62 }
static double vxMuRate(double pt_GeV)
double rate(double x)
Definition: Constants.cc:3

◆ vxMuRate()

double PatternOptimizerBase::vxMuRate ( double  pt_GeV)
static

Definition at line 35 of file PatternOptimizerBase.cc.

References a, JetChargeProducer_cfi::exp, amptDefaultParameters_cff::mu, and RPCpg::rate().

Referenced by vxIntegMuRate().

35  {
36  if (pt_GeV == 0)
37  return 0.0;
38  const double lum = 2.0e34; //defoult is 1.0e34;
39  const double dabseta = 1.0;
40  const double dpt = 1.0;
41  const double afactor = 1.0e-34 * lum * dabseta * dpt;
42  const double a = 2 * 1.3084E6;
43  const double mu = -0.725;
44  const double sigma = 0.4333;
45  const double s2 = 2 * sigma * sigma;
46 
47  double ptlog10;
48  ptlog10 = log10(pt_GeV);
49  double ex = (ptlog10 - mu) * (ptlog10 - mu) / s2;
50  double rate = (a * exp(-ex) * afactor);
51  //edm::LogError("l1tOmtfEventPrint")<<ptCode<<" "<<rate;//<<<<<<<<<<<<<<<<<<<<<<<<
52  return rate;
53 }
double rate(double x)
Definition: Constants.cc:3
double a
Definition: hdecay.h:119

Member Data Documentation

◆ goldenPatterns

GoldenPatternVec<GoldenPatternWithStat>& PatternOptimizerBase::goldenPatterns
protected

◆ simMuFoundByOmtfPt

TH1I* PatternOptimizerBase::simMuFoundByOmtfPt
protected

◆ simMuPt

TH1I* PatternOptimizerBase::simMuPt
protected

Definition at line 52 of file PatternOptimizerBase.h.

Referenced by PatternOptimizerBase().

◆ simMuPtSpectrum

TH1F* PatternOptimizerBase::simMuPtSpectrum
protected

◆ writeLayerStat

bool PatternOptimizerBase::writeLayerStat = false
protected

Definition at line 57 of file PatternOptimizerBase.h.

Referenced by PatternGenerator::endJob(), and savePatternsInRoot().