CMS 3D CMS Logo

GoldenPattern.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <cmath>
4 
6 
10 
14  unsigned int iLayer,
15  const int phiRefHit,
16  const OMTFinput::vector1D &layerHits) {
18 
19  int phiMean = meanDistPhi[iLayer][iRefLayer];
20  int phiDist = exp2(myOmtfConfig->nPdfAddrBits());
23  for (auto itHit : layerHits) {
24  if (itHit >= (int)myOmtfConfig->nPhiBins())
25  continue;
26  if (abs(itHit - phiMean - phiRefHit) < abs(phiDist))
27  phiDist = itHit - phiMean - phiRefHit;
28  }
29 
31  if (abs(phiDist) > (exp2(myOmtfConfig->nPdfAddrBits() - 1) - 1))
32  return aResult;
33 
35  phiDist += exp2(myOmtfConfig->nPdfAddrBits() - 1);
36 
37  int pdfVal = pdfAllRef[iLayer][iRefLayer][phiDist];
38 
39  return GoldenPattern::layerResult(pdfVal, pdfVal > 0);
40 }
43 int GoldenPattern::propagateRefPhi(int phiRef, int etaRef, unsigned int iRefLayer) {
44  unsigned int iLayer = 2; //MB2
45  //if(etaRef>101) iLayer = 7;//RE2
46  return phiRef + meanDistPhi[iLayer][iRefLayer];
47 }
50 void GoldenPattern::addCount(unsigned int iRefLayer,
51  unsigned int iLayer,
52  const int phiRefHit,
53  const OMTFinput::vector1D &layerHits) {
54  int nHitsInLayer = 0;
55  int phiDist = exp2(myOmtfConfig->nPdfAddrBits());
56  for (auto itHit : layerHits) {
57  if (itHit >= (int)myOmtfConfig->nPhiBins())
58  continue;
59  if (abs(itHit - phiRefHit) < phiDist)
60  phiDist = itHit - phiRefHit;
61  ++nHitsInLayer;
62  }
64  if (nHitsInLayer > 1 || nHitsInLayer == 0)
65  return;
66 
68  if (phiDist >= (int)myOmtfConfig->nPhiBins() / 2)
69  phiDist -= (int)myOmtfConfig->nPhiBins();
70  if (phiDist <= -(int)myOmtfConfig->nPhiBins() / 2)
71  phiDist += (int)myOmtfConfig->nPhiBins();
72 
74  int phiDistShift = phiDist + exp2(myOmtfConfig->nPdfAddrBits() - 1);
75 
79  if (phiDistShift < 0 || phiDistShift > exp2(myOmtfConfig->nPdfAddrBits()) - 1) {
80  return;
81  }
82 
83  if ((int)iLayer == myOmtfConfig->getRefToLogicNumber()[iRefLayer])
84  ++meanDistPhiCounts[iLayer][iRefLayer];
85  ++pdfAllRef[iLayer][iRefLayer][phiDistShift];
86 }
89 std::ostream &operator<<(std::ostream &out, const GoldenPattern &aPattern) {
90  out << "GoldenPattern " << aPattern.theKey << std::endl;
91  out << "Number of reference layers: " << aPattern.meanDistPhi[0].size()
92  << ", number of measurement layers: " << aPattern.pdfAllRef.size() << std::endl;
93 
94  if (aPattern.meanDistPhi.empty())
95  return out;
96  if (aPattern.pdfAllRef.empty())
97  return out;
98 
99  out << "Mean dist phi per layer:" << std::endl;
100  for (unsigned int iRefLayer = 0; iRefLayer < aPattern.meanDistPhi[0].size(); ++iRefLayer) {
101  out << "Ref layer: " << iRefLayer << " (";
102  for (unsigned int iLayer = 0; iLayer < aPattern.meanDistPhi.size(); ++iLayer) {
103  out << std::setw(3) << aPattern.meanDistPhi[iLayer][iRefLayer] << "\t";
104  }
105  out << ")" << std::endl;
106  }
107 
108  if (!aPattern.meanDistPhiCounts.empty()) {
109  out << "Counts number per layer:" << std::endl;
110  for (unsigned int iRefLayer = 0; iRefLayer < aPattern.meanDistPhi[0].size(); ++iRefLayer) {
111  out << "Ref layer: " << iRefLayer << " (";
112  for (unsigned int iLayer = 0; iLayer < aPattern.meanDistPhi.size(); ++iLayer) {
113  out << aPattern.meanDistPhiCounts[iLayer][iRefLayer] << "\t";
114  }
115  out << ")" << std::endl;
116  }
117  }
118 
119  unsigned int nPdfAddrBits = 7;
120  out << "PDF per layer:" << std::endl;
121  for (unsigned int iRefLayer = 0; iRefLayer < aPattern.pdfAllRef[0].size(); ++iRefLayer) {
122  out << "Ref layer: " << iRefLayer;
123  for (unsigned int iLayer = 0; iLayer < aPattern.pdfAllRef.size(); ++iLayer) {
124  out << ", measurement layer: " << iLayer << std::endl;
125  for (unsigned int iPdf = 0; iPdf < exp2(nPdfAddrBits); ++iPdf) {
126  out << std::setw(2) << aPattern.pdfAllRef[iLayer][iRefLayer][iPdf] << " ";
127  }
128  out << std::endl;
129  }
130  }
131 
132  return out;
133 }
138  GoldenPattern::vector2D meanDistPhi2D(myOmtfConfig->nLayers());
139  meanDistPhi2D.assign(myOmtfConfig->nLayers(), meanDistPhi1D);
140  meanDistPhi = meanDistPhi2D;
141  meanDistPhiCounts = meanDistPhi2D;
142 
146 
147  pdf2D.assign(myOmtfConfig->nRefLayers(), pdf1D);
148  pdfAllRef.assign(myOmtfConfig->nLayers(), pdf2D);
149 }
152 void GoldenPattern::normalise(unsigned int nPdfAddrBits) {
153  for (unsigned int iRefLayer = 0; iRefLayer < pdfAllRef[0].size(); ++iRefLayer) {
154  for (unsigned int iLayer = 0; iLayer < pdfAllRef.size(); ++iLayer) {
155  for (unsigned int iPdf = 0; iPdf < pdfAllRef[iLayer][iRefLayer].size(); ++iPdf) {
156  float pVal = log((float)pdfAllRef[iLayer][iRefLayer][iPdf] /
157  meanDistPhiCounts[myOmtfConfig->getRefToLogicNumber()[iRefLayer]][iRefLayer]);
158  if (pVal < log(myOmtfConfig->minPdfVal()))
159  continue;
160  meanDistPhi[iLayer][iRefLayer] +=
161  (iPdf - exp2(myOmtfConfig->nPdfAddrBits() - 1)) * pdfAllRef[iLayer][iRefLayer][iPdf];
162  if ((int)iLayer != myOmtfConfig->getRefToLogicNumber()[iRefLayer])
163  meanDistPhiCounts[iLayer][iRefLayer] += pdfAllRef[iLayer][iRefLayer][iPdf];
164  }
165  }
166  }
167 
169  for (unsigned int iRefLayer = 0; iRefLayer < meanDistPhi[0].size(); ++iRefLayer) {
170  for (unsigned int iLayer = 0; iLayer < meanDistPhi.size(); ++iLayer) {
171  if (!meanDistPhiCounts.empty() && meanDistPhiCounts[iLayer][iRefLayer]) {
172  if (meanDistPhiCounts[iLayer][iRefLayer] < 1000)
173  meanDistPhi[iLayer][iRefLayer] = 0;
174  else
175  meanDistPhi[iLayer][iRefLayer] =
176  rint((float)meanDistPhi[iLayer][iRefLayer] / meanDistPhiCounts[iLayer][iRefLayer]);
177  }
178  }
179  }
180  const float minPlog = log(myOmtfConfig->minPdfVal());
181  const unsigned int nPdfValBits = myOmtfConfig->nPdfValBits();
183  float pVal;
184  int digitisedVal, truncatedValue;
185  for (unsigned int iRefLayer = 0; iRefLayer < pdfAllRef[0].size(); ++iRefLayer) {
186  for (unsigned int iLayer = 0; iLayer < pdfAllRef.size(); ++iLayer) {
187  for (unsigned int iPdf = 0; iPdf < pdfAllRef[iLayer][iRefLayer].size(); ++iPdf) {
188  if (!meanDistPhiCounts[myOmtfConfig->getRefToLogicNumber()[iRefLayer]][iRefLayer] ||
189  !pdfAllRef[iLayer][iRefLayer][iPdf])
190  continue;
191  pVal = log((float)pdfAllRef[iLayer][iRefLayer][iPdf] /
192  meanDistPhiCounts[myOmtfConfig->getRefToLogicNumber()[iRefLayer]][iRefLayer]);
194  if ((pVal < minPlog || meanDistPhiCounts[iLayer][iRefLayer] < 1000)) {
195  pdfAllRef[iLayer][iRefLayer][iPdf] = 0;
196  continue;
197  }
201  digitisedVal = rint((std::pow(2, nPdfValBits) - 1) - (pVal / minPlog) * (std::pow(2, nPdfValBits) - 1));
203  truncatedValue = 0 | (digitisedVal & ((int)pow(2, nPdfValBits) - 1));
204  pdfAllRef[iLayer][iRefLayer][iPdf] = truncatedValue;
205  }
206  }
207  }
208 
209  vector3D pdfAllRefTmp = pdfAllRef;
210  for (unsigned int iRefLayer = 0; iRefLayer < pdfAllRef[0].size(); ++iRefLayer) {
211  for (unsigned int iLayer = 0; iLayer < pdfAllRef.size(); ++iLayer) {
212  for (unsigned int iPdf = 0; iPdf < pdfAllRef[iLayer][iRefLayer].size(); ++iPdf) {
213  pdfAllRef[iLayer][iRefLayer][iPdf] = 0;
215  int index =
216  iPdf - exp2(myOmtfConfig->nPdfAddrBits() - 1) - meanDistPhi[iLayer][iRefLayer] + exp2(nPdfAddrBits - 1);
217  if (index < 0 || index > exp2(nPdfAddrBits) - 1)
218  continue;
219  pdfAllRef[iLayer][iRefLayer][index] = pdfAllRefTmp[iLayer][iRefLayer][iPdf];
220  }
221  }
222  }
223 }
227  for (unsigned int iRefLayer = 0; iRefLayer < meanDistPhi[0].size(); ++iRefLayer) {
228  for (unsigned int iLayer = 0; iLayer < meanDistPhi.size(); ++iLayer) {
229  if (!meanDistPhiCounts.empty() && meanDistPhiCounts[iLayer][iRefLayer])
230  return true;
231  }
232  }
233  return false;
234 }
MessageLogger.h
OMTFConfiguration::nPdfValBits
unsigned int nPdfValBits() const
Definition: OMTFConfiguration.h:92
GoldenPattern::meanDistPhi
vector2D meanDistPhi
Definition: GoldenPattern.h:114
GoldenPattern::addCount
void addCount(unsigned int iRefLayer, unsigned int iLayer, const int refPhi, const OMTFinput::vector1D &layerHits)
Add a single count to the relevant pdf bin in three dimensions.
Definition: GoldenPattern.cc:50
GoldenPattern::propagateRefPhi
int propagateRefPhi(int phiRef, int etaRef, unsigned int iRefLayer)
Definition: GoldenPattern.cc:43
GoldenPattern::vector1D
std::vector< int > vector1D
Definition: GoldenPattern.h:46
OMTFConfiguration::nPhiBins
unsigned int nPhiBins() const
Definition: OMTFConfiguration.h:93
GoldenPattern::hasCounts
bool hasCounts()
Check if the GP has any counts in any of referecne layers;.
Definition: GoldenPattern.cc:226
OMTFConfiguration.h
GoldenPattern::vector3D
std::vector< vector2D > vector3D
Definition: GoldenPattern.h:48
operator<<
std::ostream & operator<<(std::ostream &out, const GoldenPattern &aPattern)
Definition: GoldenPattern.cc:89
GoldenPattern::pdfAllRef
vector3D pdfAllRef
Definition: GoldenPattern.h:109
OMTFConfiguration::nPdfAddrBits
unsigned int nPdfAddrBits() const
Definition: OMTFConfiguration.h:91
GoldenPattern::process1Layer1RefLayer
GoldenPattern::layerResult process1Layer1RefLayer(unsigned int iRefLayer, unsigned int iLayer, const int refPhi, const OMTFinput::vector1D &layerHits)
Definition: GoldenPattern.cc:13
OMTFConfiguration::minPdfVal
float minPdfVal() const
Definition: OMTFConfiguration.h:86
GoldenPattern::theKey
Key theKey
Pattern kinematical identification (iEta,iPt,iCharge)
Definition: GoldenPattern.h:103
OMTFConfiguration::nLayers
unsigned int nLayers() const
Definition: OMTFConfiguration.h:87
OMTFConfiguration::getRefToLogicNumber
const std::vector< int > & getRefToLogicNumber() const
Definition: OMTFConfiguration.h:105
OMTFinput::vector1D
std::vector< int > vector1D
Definition: OMTFinput.h:13
createfilelist.int
int
Definition: createfilelist.py:10
GoldenPattern::myOmtfConfig
const OMTFConfiguration * myOmtfConfig
Definition: GoldenPattern.h:120
GoldenPattern::meanDistPhiCounts
vector2D meanDistPhiCounts
Definition: GoldenPattern.h:118
GoldenPattern
Definition: GoldenPattern.h:44
GoldenPattern::reset
void reset()
Reset contents of all data vectors, keeping the vectors size.
Definition: GoldenPattern.cc:136
OMTFConfiguration::nRefLayers
unsigned int nRefLayers() const
Definition: OMTFConfiguration.h:89
GoldenPattern::layerResult
std::pair< int, bool > layerResult
Definition: GoldenPattern.h:49
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
GoldenPattern.h
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
GoldenPattern::normalise
void normalise(unsigned int nPdfAddrBits)
Definition: GoldenPattern.cc:152
OMTFinput.h
GoldenPattern::vector2D
std::vector< vector1D > vector2D
Definition: GoldenPattern.h:47