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(OMTFConfiguration::nPdfAddrBits);
24  for(auto itHit: layerHits){
25  if(itHit>=(int)OMTFConfiguration::nPhiBins) continue;
26  if(abs(itHit-phiMean-phiRefHit)<abs(phiDist)) phiDist = itHit-phiMean-phiRefHit;
27  }
28 
30  phiDist+=exp2(OMTFConfiguration::nPdfAddrBits-1);
31 
35  if(phiDist<0 ||
36  phiDist>exp2(OMTFConfiguration::nPdfAddrBits)-1){
37  return aResult;
38  }
39 
40  int pdfVal = pdfAllRef[iLayer][iRefLayer][phiDist];
41  return GoldenPattern::layerResult(pdfVal,pdfVal>0);
42 }
45 int GoldenPattern::propagateRefPhi(int phiRef, int etaRef, unsigned int iRefLayer){
46 
47  unsigned int iLayer = 2; //MB2
48  //if(etaRef>101) iLayer = 7;//RE2
49  return phiRef + meanDistPhi[iLayer][iRefLayer];
50 
51 }
54 void GoldenPattern::addCount(unsigned int iRefLayer,
55  unsigned int iLayer,
56  const int phiRefHit,
57  const OMTFinput::vector1D & layerHits){
58 
59  int nHitsInLayer = 0;
60  int phiDist = exp2(OMTFConfiguration::nPdfAddrBits);
61 
62  for(auto itHit: layerHits){
63  if(itHit>=(int)OMTFConfiguration::nPhiBins) continue;
64  if(abs(itHit-phiRefHit)<phiDist) phiDist = itHit-phiRefHit;
65  ++nHitsInLayer;
66  }
68  if(nHitsInLayer>1 || nHitsInLayer==0) return;
69 
71  if(phiDist>=(int)OMTFConfiguration::nPhiBins/2) phiDist-=(int)OMTFConfiguration::nPhiBins;
72  if(phiDist<=-(int)OMTFConfiguration::nPhiBins/2) phiDist+=(int)OMTFConfiguration::nPhiBins;
73 
75  int phiDistShift=phiDist+exp2(OMTFConfiguration::nPdfAddrBits-1);
76 
80  if(phiDistShift<0 ||
81  phiDistShift>exp2(OMTFConfiguration::nPdfAddrBits)-1){
82  return;
83  }
84  if((int)iLayer==OMTFConfiguration::refToLogicNumber[iRefLayer]) ++meanDistPhiCounts[iLayer][iRefLayer];
85  ++pdfAllRef[iLayer][iRefLayer][phiDistShift];
86 }
89 std::ostream & operator << (std::ostream &out, const GoldenPattern & aPattern){
90 
91  out <<"GoldenPattern "<< aPattern.theKey <<std::endl;
92  out <<"Number of reference layers: "<<aPattern.meanDistPhi[0].size()
93  <<", number of measurement layers: "<<aPattern.pdfAllRef.size()
94  <<std::endl;
95 
96  if(!aPattern.meanDistPhi.size()) return out;
97  if(!aPattern.pdfAllRef.size()) 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.size()){
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  out<<"PDF per layer:"<<std::endl;
120  for (unsigned int iRefLayer=0;iRefLayer<aPattern.pdfAllRef[0].size();++iRefLayer){
121  out<<"Ref layer: "<<iRefLayer;
122  for (unsigned int iLayer=0;iLayer<aPattern.pdfAllRef.size();++iLayer){
123  out<<", measurement layer: "<<iLayer<<std::endl;
124  for (unsigned int iPdf=0;iPdf<exp2(OMTFConfiguration::nPdfAddrBits);++iPdf){
125  out<<std::setw(2)<<aPattern.pdfAllRef[iLayer][iRefLayer][iPdf]<<" ";
126  }
127  out<<std::endl;
128  }
129  }
130 */
131  return out;
132 }
136 
139  meanDistPhi2D.assign(OMTFConfiguration::nLayers, meanDistPhi1D);
140  meanDistPhi = meanDistPhi2D;
141  meanDistPhiCounts = meanDistPhi2D;
142 
146 
147  pdf2D.assign(OMTFConfiguration::nRefLayers,pdf1D);
149 
150 }
154 
155  for (unsigned int iRefLayer=0;iRefLayer<pdfAllRef[0].size();++iRefLayer){
156  for (unsigned int iLayer=0;iLayer<pdfAllRef.size();++iLayer){
157  for (unsigned int iPdf=0;iPdf<pdfAllRef[iLayer][iRefLayer].size();++iPdf){
158  float pVal = log((float)pdfAllRef[iLayer][iRefLayer][iPdf]/meanDistPhiCounts[OMTFConfiguration::refToLogicNumber[iRefLayer]][iRefLayer]);
159  if(pVal<log(OMTFConfiguration::minPdfVal)) continue;
160  meanDistPhi[iLayer][iRefLayer]+=(iPdf - exp2(OMTFConfiguration::nPdfAddrBits-1))*pdfAllRef[iLayer][iRefLayer][iPdf];
161  if((int)iLayer!=OMTFConfiguration::refToLogicNumber[iRefLayer]) meanDistPhiCounts[iLayer][iRefLayer]+=pdfAllRef[iLayer][iRefLayer][iPdf];
162  }
163  }
164  }
165 
167  for (unsigned int iRefLayer=0;iRefLayer<meanDistPhi[0].size();++iRefLayer){
168  for (unsigned int iLayer=0;iLayer<meanDistPhi.size();++iLayer){
169  if(meanDistPhiCounts.size() && meanDistPhiCounts[iLayer][iRefLayer]){
170  if (meanDistPhiCounts[iLayer][iRefLayer]<1000) meanDistPhi[iLayer][iRefLayer] = 0;
171  else meanDistPhi[iLayer][iRefLayer] = rint((float)meanDistPhi[iLayer][iRefLayer]/meanDistPhiCounts[iLayer][iRefLayer]);
172  }
173  }
174  }
175 
176  const float minPlog = log(OMTFConfiguration::minPdfVal);
177  const unsigned int nPdfValBits = OMTFConfiguration::nPdfValBits;
179  float pVal;
180  int digitisedVal, truncatedValue;
181  for (unsigned int iRefLayer=0;iRefLayer<pdfAllRef[0].size();++iRefLayer){
182  for (unsigned int iLayer=0;iLayer<pdfAllRef.size();++iLayer){
183  for (unsigned int iPdf=0;iPdf<pdfAllRef[iLayer][iRefLayer].size();++iPdf){
184  if(!meanDistPhiCounts[OMTFConfiguration::refToLogicNumber[iRefLayer]][iRefLayer] ||
185  !pdfAllRef[iLayer][iRefLayer][iPdf]) continue;
186  pVal = log((float)pdfAllRef[iLayer][iRefLayer][iPdf]/meanDistPhiCounts[OMTFConfiguration::refToLogicNumber[iRefLayer]][iRefLayer]);
188  if(pVal<minPlog || meanDistPhiCounts[iLayer][iRefLayer]<1000){
189  pdfAllRef[iLayer][iRefLayer][iPdf] = 0;
190  continue;
191  }
195  digitisedVal = rint((std::pow(2,nPdfValBits)-1) - (pVal/minPlog)*(std::pow(2,nPdfValBits)-1));
197  truncatedValue = 0 | (digitisedVal & ((int)pow(2,nPdfValBits)-1));
198  pdfAllRef[iLayer][iRefLayer][iPdf] = truncatedValue;
199  }
200  }
201  }
202 
203 
204  vector3D pdfAllRefTmp = pdfAllRef;
205 
206  const unsigned int nPdfAddrBits = 7;
207  for (unsigned int iRefLayer=0;iRefLayer<pdfAllRef[0].size();++iRefLayer){
208  for (unsigned int iLayer=0;iLayer<pdfAllRef.size();++iLayer){
209  for (unsigned int iPdf=0;iPdf<pdfAllRef[iLayer][iRefLayer].size();++iPdf){
210  pdfAllRef[iLayer][iRefLayer][iPdf] = 0;
212  int index = iPdf - exp2(OMTFConfiguration::nPdfAddrBits-1) - meanDistPhi[iLayer][iRefLayer] + exp2(nPdfAddrBits-1);
213  if(index<0 || index>exp2(nPdfAddrBits)-1) continue;
214  pdfAllRef[iLayer][iRefLayer][index] = pdfAllRefTmp[iLayer][iRefLayer][iPdf];
215  }
216  }
217  }
218 }
222 
223  for (unsigned int iRefLayer=0;iRefLayer<meanDistPhi[0].size();++iRefLayer){
224  for (unsigned int iLayer=0;iLayer<meanDistPhi.size();++iLayer){
225  if(meanDistPhiCounts.size() && meanDistPhiCounts[iLayer][iRefLayer]) return true;
226  }
227  }
228  return false;
229 }
static unsigned int nLayers
vector2D meanDistPhiCounts
std::vector< int > vector1D
Definition: GoldenPattern.h:49
static float minPdfVal
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
std::vector< int > vector1D
Definition: OMTFinput.h:14
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)
static unsigned int nPdfAddrBits
std::vector< vector1D > vector2D
Definition: GoldenPattern.h:50
std::vector< vector2D > vector3D
Definition: GoldenPattern.h:51
Key theKey
Pattern kinematical identification (iEta,iPt,iCharge)
vector3D pdfAllRef
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static unsigned int nPhiBins
std::pair< int, bool > layerResult
Definition: GoldenPattern.h:52
static std::vector< int > refToLogicNumber
void reset()
Reset contents of all data vectors, keeping the vectors size.
static unsigned int nRefLayers
int propagateRefPhi(int phiRef, int etaRef, unsigned int iRefLayer)
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.
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
static unsigned int nPdfValBits