11 #include <boost/range/adaptor/reversed.hpp> 14 #include "TDirectory.h" 33 gp->setKeyNumber(
i++);
35 if (
gp->key().thePt == 0)
40 int statBinsCnt = 1024;
41 gp->iniStatisitics(statBinsCnt, 1);
44 edm::LogImportant(
"l1tOmtfEventPrint") <<
"PatternGenerator::initPatternGen():" << __LINE__
45 <<
" goldenPatterns.size() " <<
goldenPatterns.size() << std::endl;
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;
104 edm::LogImportant(
"l1tOmtfEventPrint") <<
":" << __LINE__ <<
" algoMuon is null" << std::endl;
105 throw runtime_error(
"algoMuon is null");
124 unsigned int refLayer = gpResult.getRefLayer();
126 if (gpResult.getFiredLayerCnt() >= 3) {
127 for (
unsigned int iLayer = 0; iLayer < gpResult.getStubResults().size(); iLayer++) {
131 if (gpResult.getStubResults()[iLayer].getMuonStub()) {
133 if (gpResult.getStubResults()[iLayer].getMuonStub()->qualityHw >= 4)
140 int phiDist = gpResult.getStubResults()[iLayer].getPdfBin();
152 phiDist += exptCandGp->
getStatistics()[iLayer][refLayer].size() / 2;
155 if (phiDist > 0 && phiDist < (
int)(exptCandGp->
getStatistics()[iLayer][refLayer].size())) {
158 exptCandGp->
updateStat(iLayer, refLayer, phiDist, 0, 1);
162 exptCandGp->
updateStat(iLayer, refLayer, phiDist, 0, 1);
170 std::unique_ptr<l1t::RegionalMuonCandBxCollection>& finalCandidates) {
194 TDirectory* curDir = (TDirectory*)inFile.Get(
"layerStats");
196 ostringstream ostrName;
198 if (
gp->key().thePt == 0)
201 int statBinsCnt = 1024;
202 gp->iniStatisitics(statBinsCnt, 1);
204 for (
unsigned int iLayer = 0; iLayer <
gp->getPdf().size(); ++iLayer) {
205 for (
unsigned int iRefLayer = 0; iRefLayer <
gp->getPdf()[iLayer].size(); ++iRefLayer) {
207 ostrName <<
"histLayerStat_PatNum_" <<
gp->key().theNumber <<
"_refLayer_" << iRefLayer <<
"_Layer_" 210 TH1I* histLayerStat = (TH1I*)curDir->Get(ostrName.str().c_str());
213 for (
int iBin = 0; iBin < statBinsCnt; iBin++) {
214 gp->updateStat(iLayer, iRefLayer, iBin, 0, histLayerStat->GetBinContent(iBin + 1));
218 <<
"PatternGenerator::endJob() - reading histLayerStat: histogram not found " << ostrName.str()
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));
229 <<
"PatternGenerator::endJob() - eventCntPerGp: iGp" << iGp <<
" - " <<
eventCntPerGp[iGp] << std::endl;
234 int indexInGroup = 0;
238 gp->key().setIndexInGroup(indexInGroup);
242 <<
"setGroup(group): group " <<
group <<
" indexInGroup " << indexInGroup << std::endl;
244 if (
gp->key().thePt <= 10 && indexInGroup == 2) {
249 if (
gp->key().thePt > 10 && indexInGroup == 4) {
271 if (
gp->key().thePt == 0)
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)) {
277 string(__FUNCTION__) +
":" +
to_string(__LINE__) +
278 "gp->getDistPhiBitShift(iLayer, iRefLayer) != 0 - cannot change DistPhiBitShift then!!!!");
281 if ((
gp->key().thePt <= 10) && (iLayer == 1 || iLayer == 3 || iLayer == 5)) {
282 gp->setDistPhiBitShift(1, iLayer, iRefLayer);
284 gp->setDistPhiBitShift(0, iLayer, iRefLayer);
305 double minHitCntThresh = 0.001;
308 if (
gp->key().thePt == 0)
313 <<
"PatternGenerator::upadatePdfs() Calculating meanDistPhi " <<
gp->key() <<
" eventCnt " 314 <<
eventCntPerGp[
gp->key().number()] <<
" minHitCnt " << minHitCnt << std::endl;
316 for (
unsigned int iLayer = 0; iLayer <
gp->getPdf().size(); ++iLayer) {
317 for (
unsigned int iRefLayer = 0; iRefLayer <
gp->getPdf()[iLayer].size(); ++iRefLayer) {
319 double meanDistPhi = 0;
321 for (
unsigned int iBin = 1; iBin <
gp->getStatistics()[iLayer][iRefLayer].size(); iBin++) {
323 meanDistPhi += iBin *
gp->getStatistics()[iLayer][iRefLayer][iBin][0];
324 count +=
gp->getStatistics()[iLayer][iRefLayer][iBin][0];
328 meanDistPhi /=
count;
330 meanDistPhi -= (
gp->getStatistics()[iLayer][iRefLayer].size() / 2);
332 if (
count < minHitCnt)
336 << __FUNCTION__ <<
": " << __LINE__ <<
" " <<
gp->key() <<
" iLayer " << iLayer <<
" iRefLayer " 337 << iRefLayer <<
" count " <<
count <<
" meanDistPhi " << meanDistPhi << endl;
339 gp->setMeanDistPhiValue(round(meanDistPhi), iLayer, iRefLayer);
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] <<
" ";
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) {
360 for (
unsigned int iGroup = 0; iGroup < patternGroups.size(); iGroup++) {
361 double meanDistPhi = 0;
363 for (
unsigned int i = 0;
i < patternGroups[iGroup].size();
i++) {
365 meanDistPhi +=
gp->meanDistPhiValue(iLayer, iRefLayer);
366 if (
gp->meanDistPhiValue(iLayer, iRefLayer) != 0)
371 meanDistPhi /= mergedCnt;
373 for (
unsigned int i = 0;
i < patternGroups[iGroup].size();
i++) {
375 gp->setMeanDistPhiValue(round(meanDistPhi), iLayer, iRefLayer);
377 << __FUNCTION__ <<
": " << __LINE__ <<
" iGroup " << iGroup <<
" numInGroup " <<
i <<
" " <<
gp->key()
378 <<
" iLayer " << iLayer <<
" iRefLayer " << iRefLayer <<
" meanDistPhi after averaging " 379 << meanDistPhi << endl;
389 if (
gp->key().thePt == 0)
393 int minHitCnt = 2 * minHitCntThresh *
eventCntPerGp[
gp->key().number()];
395 for (
unsigned int iLayer = 0; iLayer <
gp->getPdf().size(); ++iLayer) {
396 for (
unsigned int iRefLayer = 0; iRefLayer <
gp->getPdf()[iLayer].size(); ++iRefLayer) {
399 for (
unsigned int iBin = 0; iBin <
gp->getStatistics()[iLayer][iRefLayer].size();
401 norm +=
gp->getStatistics()[iLayer][iRefLayer][iBin][0];
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++) {
410 for (
int i = 0;
i < statBinGroupSize;
i++) {
412 statBinGroupSize * ((
int)(iBinPdf)-pdfMiddle) +
i +
gp->meanDistPhiValue(iLayer, iRefLayer);
414 iBinStat += (
gp->getStatistics()[iLayer][iRefLayer].size() / 2);
416 if (iBinStat >= 0 && iBinStat < (
int)
gp->getStatistics()[iLayer][iRefLayer].size()) {
417 pdfVal +=
gp->getStatistics()[iLayer][iRefLayer][iBinStat][0];
422 if (norm > minHitCnt) {
423 pdfVal /= (norm * statBinGroupSize);
433 pdfVal =
gp->getStatistics()[iLayer][iRefLayer][iBinStat][0] / norm;
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;
441 double minPdfValFactor = 1;
445 int digitisedVal = 0;
447 digitisedVal = rint(pdfMaxVal -
log(pdfVal) / minPlog * pdfMaxVal);
450 gp->setPdfValue(digitisedVal, iLayer, iRefLayer, iBinPdf);
460 outfile.mkdir(
"ptDeltaPhiHists")->cd();
472 edm::LogImportant(
"l1tOmtfEventPrint") << __FUNCTION__ <<
": " << __LINE__ <<
" Correcting P(C_k) " << std::endl;
474 for (
unsigned int iRefLayer = 0; iRefLayer <
goldenPatterns[0]->getPdf()[0].size(); ++iRefLayer) {
476 if (iRefLayer == 0 || iRefLayer == 2)
478 else if (iRefLayer == 5)
480 else if (iRefLayer == 1)
482 else if (iRefLayer == 3)
484 else if (iRefLayer == 5)
486 else if (iRefLayer == 6 || iRefLayer == 7)
490 << __FUNCTION__ <<
":" << __LINE__ <<
" RefLayer " << iRefLayer <<
" step " <<
step << std::endl;
493 if (
gp->key().thePt == 0 ||
gp->key().theCharge !=
sign)
499 double ptRange = ptTo - ptFrom;
501 double minPdfValFactor = 0.1;
515 int digitisedVal = rint(pdfMaxVal -
log(classProb) / minPlog * pdfMaxVal);
517 int newPdfVal = digitisedVal;
539 gp->setPdfValue(newPdfVal, refLayerLogicNumber, iRefLayer, iPdf);
544 <<
" ptRange " <<
ptRange <<
" RefLayer " << iRefLayer <<
" newPdfVal " << newPdfVal << std::endl;
551 edm::LogImportant(
"l1tOmtfEventPrint") << __FUNCTION__ <<
": " << __LINE__ <<
" reCalibratePt" << std::endl;
552 std::map<int, float> ptMap;
584 if (
gp->key().thePt == 0)
590 gp->key().setPt(newPt);
596 int indexInGroup = 0;
600 gp->key().setIndexInGroup(indexInGroup);
604 <<
"setGroup(group): group " <<
group <<
" indexInGroup " << indexInGroup << std::endl;
606 if (
gp->key().thePt <= 12 && indexInGroup == 2) {
611 if (
gp->key().thePt > 12 && indexInGroup == 4) {
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] <<
" ";
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) {
635 for (
unsigned int iGroup = 0; iGroup < patternGroups.size(); iGroup++) {
636 double meanDistPhi = 0;
638 for (
unsigned int i = 0;
i < patternGroups[iGroup].size();
i++) {
640 meanDistPhi +=
gp->meanDistPhiValue(iLayer, iRefLayer);
641 if (
gp->meanDistPhiValue(iLayer, iRefLayer) != 0)
644 << __FUNCTION__ <<
": " << __LINE__ <<
" iGroup " << iGroup <<
" numInGroup " <<
i <<
" " <<
gp->key()
645 <<
" iLayer " << iLayer <<
" iRefLayer " << iRefLayer <<
" old meanDistPhiValue " 646 <<
gp->meanDistPhiValue(iLayer, iRefLayer) << endl;
650 meanDistPhi /= mergedCnt;
651 meanDistPhi = (
int)meanDistPhi;
654 for (
unsigned int i = 0;
i < patternGroups[iGroup].size();
i++) {
657 if (refLayerLogicNum != iLayer) {
658 int shift = meanDistPhi -
gp->meanDistPhiValue(iLayer, iRefLayer);
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;
666 for (
int iBin = 1 -
shift; iBin < pdfBins;
668 auto pdfVal =
gp->pdfValue(iLayer, iRefLayer, iBin);
669 gp->setPdfValue(pdfVal, iLayer, iRefLayer, iBin +
shift);
671 <<
" iBin " << iBin <<
" iBin + shift " << iBin +
shift <<
" pdfVal " << pdfVal << endl;
673 for (
int iBin = pdfBins +
shift; iBin < pdfBins; iBin++) {
674 gp->setPdfValue(0, iLayer, iRefLayer, iBin);
676 }
else if (
shift > 0) {
677 for (
int iBin = pdfBins - 1 -
shift; iBin > 0;
679 auto pdfVal =
gp->pdfValue(iLayer, iRefLayer, iBin);
680 gp->setPdfValue(pdfVal, iLayer, iRefLayer, iBin +
shift);
682 <<
" iBin " << iBin <<
" iBin + shift " << iBin +
shift <<
" pdfVal " << pdfVal << endl;
684 for (
int iBin =
shift; iBin > 0; iBin--) {
685 gp->setPdfValue(0, iLayer, iRefLayer, iBin);
690 gp->setMeanDistPhiValue(round(meanDistPhi), iLayer, iRefLayer);
T getParameter(std::string const &) const
~PatternGenerator() override
virtual void updateStat(unsigned int iLayer, unsigned int iRefLayer, unsigned int iBin, unsigned int what, double value)
AlgoMuons::value_type omtfCand
std::string to_string(const V &value)
unsigned int getPatternNum(double pt, int charge) const
charge: -1 - negative, +1 - positive
static double vxIntegMuRate(double pt_GeV, double dpt, double etaFrom, double etaTo)
const math::XYZTLorentzVectorD & momentum() const
int type() const
particle type (HEP PDT convension)
std::vector< vector1D > vector2D
void observeEventEnd(const edm::Event &iEvent, std::unique_ptr< l1t::RegionalMuonCandBxCollection > &finalCandidates) override
void observeEventEnd(const edm::Event &iEvent, std::unique_ptr< l1t::RegionalMuonCandBxCollection > &finalCandidates) override
unsigned int nPdfAddrBits() const
resultsArrayType & getResults()
Abs< T >::type abs(const T &t)
PatternGenerator(const edm::ParameterSet &edmCfg, const OMTFConfiguration *omtfConfig, GoldenPatternVec< GoldenPatternWithStat > &gps)
Log< level::Error, true > LogImportant
const std::vector< int > & getRefToLogicNumber() const
int ptGevToHw(double ptGev) const override
uGMT pt scale conversion: [0GeV, 0.5GeV) = 1 [0.5GeV, 1 Gev) = 2
unsigned int candProcIndx
std::vector< std::unique_ptr< GoldenPatternType > > GoldenPatternVec
void modifyClassProb(double step)
GoldenPatternVec< GoldenPatternWithStat > & goldenPatterns
PatternPt getPatternPtRange(unsigned int patNum) const
std::vector< unsigned int > eventCntPerGp
static unsigned int const shift
int meanDistPhiValue(unsigned int iLayer, unsigned int iRefLayer) const
vector2D getPatternGroups(const std::vector< std::unique_ptr< GoldenPatternType > > &goldenPats) const
unsigned int nPdfBins() const
const OMTFConfiguration * omtfConfig
void saveHists(TFile &outfile) override
bool isBendingLayer(unsigned int iLayer) const override
const StatArrayType & getStatistics() const