test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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){
17 
19 
20  int phiMean = meanDistPhi[iLayer][iRefLayer];
21  int phiDist = exp2(myOmtfConfig->nPdfAddrBits());
24  for(auto itHit: layerHits){
25  if(itHit>=(int)myOmtfConfig->nPhiBins()) continue;
26  if(abs(itHit-phiMean-phiRefHit)<abs(phiDist)) phiDist = itHit-phiMean-phiRefHit;
27  }
28 
30  if(abs(phiDist)>(exp2(myOmtfConfig->nPdfAddrBits()-1) -1)) return aResult;
31 
33  phiDist+=exp2(myOmtfConfig->nPdfAddrBits()-1);
34 
35  int pdfVal = pdfAllRef[iLayer][iRefLayer][phiDist];
36 
37  return GoldenPattern::layerResult(pdfVal,pdfVal>0);
38 }
41 int GoldenPattern::propagateRefPhi(int phiRef, int etaRef, unsigned int iRefLayer){
42 
43  unsigned int iLayer = 2; //MB2
44  //if(etaRef>101) iLayer = 7;//RE2
45  return phiRef + meanDistPhi[iLayer][iRefLayer];
46 
47 }
50 void GoldenPattern::addCount(unsigned int iRefLayer,
51  unsigned int iLayer,
52  const int phiRefHit,
53  const OMTFinput::vector1D & layerHits){
54 
55  int nHitsInLayer = 0;
56  int phiDist = exp2(myOmtfConfig->nPdfAddrBits());
57  for(auto itHit: layerHits){
58  if(itHit>=(int)myOmtfConfig->nPhiBins()) continue;
59  if(abs(itHit-phiRefHit)<phiDist) phiDist = itHit-phiRefHit;
60  ++nHitsInLayer;
61  }
63  if(nHitsInLayer>1 || nHitsInLayer==0) return;
64 
66  if(phiDist>=(int)myOmtfConfig->nPhiBins()/2) phiDist-=(int)myOmtfConfig->nPhiBins();
67  if(phiDist<=-(int)myOmtfConfig->nPhiBins()/2) phiDist+=(int)myOmtfConfig->nPhiBins();
68 
70  int phiDistShift=phiDist+exp2(myOmtfConfig->nPdfAddrBits()-1);
71 
75  if(phiDistShift<0 ||
76  phiDistShift>exp2(myOmtfConfig->nPdfAddrBits())-1){
77  return;
78  }
79 
80  if((int)iLayer==myOmtfConfig->getRefToLogicNumber()[iRefLayer]) ++meanDistPhiCounts[iLayer][iRefLayer];
81  ++pdfAllRef[iLayer][iRefLayer][phiDistShift];
82 }
85 std::ostream & operator << (std::ostream &out, const GoldenPattern & aPattern){
86 
87  out <<"GoldenPattern "<< aPattern.theKey <<std::endl;
88  out <<"Number of reference layers: "<<aPattern.meanDistPhi[0].size()
89  <<", number of measurement layers: "<<aPattern.pdfAllRef.size()
90  <<std::endl;
91 
92  if(!aPattern.meanDistPhi.size()) return out;
93  if(!aPattern.pdfAllRef.size()) return out;
94 
95  out<<"Mean dist phi per layer:"<<std::endl;
96  for (unsigned int iRefLayer=0;iRefLayer<aPattern.meanDistPhi[0].size();++iRefLayer){
97  out<<"Ref layer: "<<iRefLayer<<" (";
98  for (unsigned int iLayer=0;iLayer<aPattern.meanDistPhi.size();++iLayer){
99  out<<std::setw(3)<<aPattern.meanDistPhi[iLayer][iRefLayer]<<"\t";
100  }
101  out<<")"<<std::endl;
102  }
103 
104  if(aPattern.meanDistPhiCounts.size()){
105  out<<"Counts number per layer:"<<std::endl;
106  for (unsigned int iRefLayer=0;iRefLayer<aPattern.meanDistPhi[0].size();++iRefLayer){
107  out<<"Ref layer: "<<iRefLayer<<" (";
108  for (unsigned int iLayer=0;iLayer<aPattern.meanDistPhi.size();++iLayer){
109  out<<aPattern.meanDistPhiCounts[iLayer][iRefLayer]<<"\t";
110  }
111  out<<")"<<std::endl;
112  }
113  }
114 
115  unsigned int nPdfAddrBits = 7;
116  out<<"PDF per layer:"<<std::endl;
117  for (unsigned int iRefLayer=0;iRefLayer<aPattern.pdfAllRef[0].size();++iRefLayer){
118  out<<"Ref layer: "<<iRefLayer;
119  for (unsigned int iLayer=0;iLayer<aPattern.pdfAllRef.size();++iLayer){
120  out<<", measurement layer: "<<iLayer<<std::endl;
121  for (unsigned int iPdf=0;iPdf<exp2(nPdfAddrBits);++iPdf){
122  out<<std::setw(2)<<aPattern.pdfAllRef[iLayer][iRefLayer][iPdf]<<" ";
123  }
124  out<<std::endl;
125  }
126  }
127 
128  return out;
129 }
133 
135  GoldenPattern::vector2D meanDistPhi2D(myOmtfConfig->nLayers());
136  meanDistPhi2D.assign(myOmtfConfig->nLayers(), meanDistPhi1D);
137  meanDistPhi = meanDistPhi2D;
138  meanDistPhiCounts = meanDistPhi2D;
139 
143 
144  pdf2D.assign(myOmtfConfig->nRefLayers(),pdf1D);
145  pdfAllRef.assign(myOmtfConfig->nLayers(),pdf2D);
146 }
149 void GoldenPattern::normalise(unsigned int nPdfAddrBits){
150 
151  for (unsigned int iRefLayer=0;iRefLayer<pdfAllRef[0].size();++iRefLayer){
152  for (unsigned int iLayer=0;iLayer<pdfAllRef.size();++iLayer){
153  for (unsigned int iPdf=0;iPdf<pdfAllRef[iLayer][iRefLayer].size();++iPdf){
154  float pVal = log((float)pdfAllRef[iLayer][iRefLayer][iPdf]/meanDistPhiCounts[myOmtfConfig->getRefToLogicNumber()[iRefLayer]][iRefLayer]);
155  if(pVal<log(myOmtfConfig->minPdfVal())) continue;
156  meanDistPhi[iLayer][iRefLayer]+=(iPdf - exp2(myOmtfConfig->nPdfAddrBits()-1))*pdfAllRef[iLayer][iRefLayer][iPdf];
157  if((int)iLayer!=myOmtfConfig->getRefToLogicNumber()[iRefLayer]) meanDistPhiCounts[iLayer][iRefLayer]+=pdfAllRef[iLayer][iRefLayer][iPdf];
158  }
159  }
160  }
161 
163  for (unsigned int iRefLayer=0;iRefLayer<meanDistPhi[0].size();++iRefLayer){
164  for (unsigned int iLayer=0;iLayer<meanDistPhi.size();++iLayer){
165  if(meanDistPhiCounts.size() && meanDistPhiCounts[iLayer][iRefLayer]){
166  if(meanDistPhiCounts[iLayer][iRefLayer]<1000) meanDistPhi[iLayer][iRefLayer] = 0;
167  else meanDistPhi[iLayer][iRefLayer] = rint((float)meanDistPhi[iLayer][iRefLayer]/meanDistPhiCounts[iLayer][iRefLayer]);
168  }
169  }
170  }
171  const float minPlog = log(myOmtfConfig->minPdfVal());
172  const unsigned int nPdfValBits = myOmtfConfig->nPdfValBits();
174  float pVal;
175  int digitisedVal, truncatedValue;
176  for (unsigned int iRefLayer=0;iRefLayer<pdfAllRef[0].size();++iRefLayer){
177  for (unsigned int iLayer=0;iLayer<pdfAllRef.size();++iLayer){
178  for (unsigned int iPdf=0;iPdf<pdfAllRef[iLayer][iRefLayer].size();++iPdf){
179  if(!meanDistPhiCounts[myOmtfConfig->getRefToLogicNumber()[iRefLayer]][iRefLayer] ||
180  !pdfAllRef[iLayer][iRefLayer][iPdf]) continue;
181  pVal = log((float)pdfAllRef[iLayer][iRefLayer][iPdf]/meanDistPhiCounts[myOmtfConfig->getRefToLogicNumber()[iRefLayer]][iRefLayer]);
183  if((pVal<minPlog || meanDistPhiCounts[iLayer][iRefLayer]<1000)){
184  pdfAllRef[iLayer][iRefLayer][iPdf] = 0;
185  continue;
186  }
190  digitisedVal = rint((std::pow(2,nPdfValBits)-1) - (pVal/minPlog)*(std::pow(2,nPdfValBits)-1));
192  truncatedValue = 0 | (digitisedVal & ((int)pow(2,nPdfValBits)-1));
193  pdfAllRef[iLayer][iRefLayer][iPdf] = truncatedValue;
194  }
195  }
196  }
197 
198  vector3D pdfAllRefTmp = pdfAllRef;
199  for (unsigned int iRefLayer=0;iRefLayer<pdfAllRef[0].size();++iRefLayer){
200  for (unsigned int iLayer=0;iLayer<pdfAllRef.size();++iLayer){
201  for (unsigned int iPdf=0;iPdf<pdfAllRef[iLayer][iRefLayer].size();++iPdf){
202  pdfAllRef[iLayer][iRefLayer][iPdf] = 0;
204  int index = iPdf - exp2(myOmtfConfig->nPdfAddrBits()-1) - meanDistPhi[iLayer][iRefLayer] + exp2(nPdfAddrBits-1);
205  if(index<0 || index>exp2(nPdfAddrBits)-1) continue;
206  pdfAllRef[iLayer][iRefLayer][index] = pdfAllRefTmp[iLayer][iRefLayer][iPdf];
207  }
208  }
209  }
210 }
214 
215  for (unsigned int iRefLayer=0;iRefLayer<meanDistPhi[0].size();++iRefLayer){
216  for (unsigned int iLayer=0;iLayer<meanDistPhi.size();++iLayer){
217  if(meanDistPhiCounts.size() && meanDistPhiCounts[iLayer][iRefLayer]) return true;
218  }
219  }
220  return false;
221 }
unsigned int nRefLayers() const
vector2D meanDistPhiCounts
std::vector< int > vector1D
Definition: GoldenPattern.h:48
unsigned int nLayers() const
unsigned int nPhiBins() const
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:188
std::vector< int > vector1D
Definition: OMTFinput.h:15
const OMTFConfiguration * myOmtfConfig
vector2D meanDistPhi
bool hasCounts()
Check if the GP has any counts in any of referecne layers;.
GoldenPattern::layerResult process1Layer1RefLayer(unsigned int iRefLayer, unsigned int iLayer, const int refPhi, const OMTFinput::vector1D &layerHits)
void normalise(unsigned int nPdfAddrBits)
std::vector< vector1D > vector2D
Definition: GoldenPattern.h:49
std::vector< vector2D > vector3D
Definition: GoldenPattern.h:50
Key theKey
Pattern kinematical identification (iEta,iPt,iCharge)
unsigned int nPdfAddrBits() const
vector3D pdfAllRef
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::pair< int, bool > layerResult
Definition: GoldenPattern.h:51
float minPdfVal() const
void reset()
Reset contents of all data vectors, keeping the vectors size.
int propagateRefPhi(int phiRef, int etaRef, unsigned int iRefLayer)
const std::vector< int > & getRefToLogicNumber() const
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.
unsigned int nPdfValBits() const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40