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::instance()->nPdfAddrBits);
24  for(auto itHit: layerHits){
25  if(itHit>=(int)OMTFConfiguration::instance()->nPhiBins) continue;
26  if(abs(itHit-phiMean-phiRefHit)<abs(phiDist)) phiDist = itHit-phiMean-phiRefHit;
27  }
28 
30  phiDist+=exp2(OMTFConfiguration::instance()->nPdfAddrBits-1);
31 
35  if(phiDist<0 ||
36  phiDist>exp2(OMTFConfiguration::instance()->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::instance()->nPdfAddrBits);
61 
62  for(auto itHit: layerHits){
63  if(itHit>=(int)OMTFConfiguration::instance()->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::instance()->nPhiBins/2) phiDist-=(int)OMTFConfiguration::instance()->nPhiBins;
72  if(phiDist<=-(int)OMTFConfiguration::instance()->nPhiBins/2) phiDist+=(int)OMTFConfiguration::instance()->nPhiBins;
73 
75  int phiDistShift=phiDist+exp2(OMTFConfiguration::instance()->nPdfAddrBits-1);
76 
80  if(phiDistShift<0 ||
81  phiDistShift>exp2(OMTFConfiguration::instance()->nPdfAddrBits)-1){
82  return;
83  }
84 
85  if((int)iLayer==OMTFConfiguration::instance()->refToLogicNumber[iRefLayer]) ++meanDistPhiCounts[iLayer][iRefLayer];
86  ++pdfAllRef[iLayer][iRefLayer][phiDistShift];
87 }
90 std::ostream & operator << (std::ostream &out, const GoldenPattern & aPattern){
91 
92  out <<"GoldenPattern "<< aPattern.theKey <<std::endl;
93  out <<"Number of reference layers: "<<aPattern.meanDistPhi[0].size()
94  <<", number of measurement layers: "<<aPattern.pdfAllRef.size()
95  <<std::endl;
96 
97  if(!aPattern.meanDistPhi.size()) return out;
98  if(!aPattern.pdfAllRef.size()) return out;
99 
100  out<<"Mean dist phi per layer:"<<std::endl;
101  for (unsigned int iRefLayer=0;iRefLayer<aPattern.meanDistPhi[0].size();++iRefLayer){
102  out<<"Ref layer: "<<iRefLayer<<" (";
103  for (unsigned int iLayer=0;iLayer<aPattern.meanDistPhi.size();++iLayer){
104  out<<std::setw(3)<<aPattern.meanDistPhi[iLayer][iRefLayer]<<"\t";
105  }
106  out<<")"<<std::endl;
107  }
108 
109  if(aPattern.meanDistPhiCounts.size()){
110  out<<"Counts number per layer:"<<std::endl;
111  for (unsigned int iRefLayer=0;iRefLayer<aPattern.meanDistPhi[0].size();++iRefLayer){
112  out<<"Ref layer: "<<iRefLayer<<" (";
113  for (unsigned int iLayer=0;iLayer<aPattern.meanDistPhi.size();++iLayer){
114  out<<aPattern.meanDistPhiCounts[iLayer][iRefLayer]<<"\t";
115  }
116  out<<")"<<std::endl;
117  }
118  }
119 /*
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(OMTFConfiguration::instance()->nPdfAddrBits);++iPdf){
126  out<<std::setw(2)<<aPattern.pdfAllRef[iLayer][iRefLayer][iPdf]<<" ";
127  }
128  out<<std::endl;
129  }
130  }
131 */
132  return out;
133 }
137 
138  GoldenPattern::vector1D meanDistPhi1D(OMTFConfiguration::instance()->nRefLayers);
139  GoldenPattern::vector2D meanDistPhi2D(OMTFConfiguration::instance()->nLayers);
140  meanDistPhi2D.assign(OMTFConfiguration::instance()->nLayers, meanDistPhi1D);
141  meanDistPhi = meanDistPhi2D;
142  meanDistPhiCounts = meanDistPhi2D;
143 
144  GoldenPattern::vector1D pdf1D(exp2(OMTFConfiguration::instance()->nPdfAddrBits));
147 
148  pdf2D.assign(OMTFConfiguration::instance()->nRefLayers,pdf1D);
149  pdfAllRef.assign(OMTFConfiguration::instance()->nLayers,pdf2D);
150 
151 }
155 
156  for (unsigned int iRefLayer=0;iRefLayer<pdfAllRef[0].size();++iRefLayer){
157  for (unsigned int iLayer=0;iLayer<pdfAllRef.size();++iLayer){
158  for (unsigned int iPdf=0;iPdf<pdfAllRef[iLayer][iRefLayer].size();++iPdf){
159  float pVal = log((float)pdfAllRef[iLayer][iRefLayer][iPdf]/meanDistPhiCounts[OMTFConfiguration::instance()->refToLogicNumber[iRefLayer]][iRefLayer]);
160  if(pVal<log(OMTFConfiguration::instance()->minPdfVal)) continue;
161  meanDistPhi[iLayer][iRefLayer]+=(iPdf - exp2(OMTFConfiguration::instance()->nPdfAddrBits-1))*pdfAllRef[iLayer][iRefLayer][iPdf];
162  if((int)iLayer!=OMTFConfiguration::instance()->refToLogicNumber[iRefLayer]) meanDistPhiCounts[iLayer][iRefLayer]+=pdfAllRef[iLayer][iRefLayer][iPdf];
163  }
164  }
165  }
166 
168  for (unsigned int iRefLayer=0;iRefLayer<meanDistPhi[0].size();++iRefLayer){
169  for (unsigned int iLayer=0;iLayer<meanDistPhi.size();++iLayer){
170  if(meanDistPhiCounts.size() && meanDistPhiCounts[iLayer][iRefLayer]){
171  if(meanDistPhiCounts[iLayer][iRefLayer]<1000) meanDistPhi[iLayer][iRefLayer] = 0;
172  else meanDistPhi[iLayer][iRefLayer] = rint((float)meanDistPhi[iLayer][iRefLayer]/meanDistPhiCounts[iLayer][iRefLayer]);
173  }
174  }
175  }
176 
177  const float minPlog = log(OMTFConfiguration::instance()->minPdfVal);
178  const unsigned int nPdfValBits = OMTFConfiguration::instance()->nPdfValBits;
180  float pVal;
181  int digitisedVal, truncatedValue;
182  for (unsigned int iRefLayer=0;iRefLayer<pdfAllRef[0].size();++iRefLayer){
183  for (unsigned int iLayer=0;iLayer<pdfAllRef.size();++iLayer){
184  for (unsigned int iPdf=0;iPdf<pdfAllRef[iLayer][iRefLayer].size();++iPdf){
185  if(!meanDistPhiCounts[OMTFConfiguration::instance()->refToLogicNumber[iRefLayer]][iRefLayer] ||
186  !pdfAllRef[iLayer][iRefLayer][iPdf]) continue;
187  pVal = log((float)pdfAllRef[iLayer][iRefLayer][iPdf]/meanDistPhiCounts[OMTFConfiguration::instance()->refToLogicNumber[iRefLayer]][iRefLayer]);
189  if(pVal<minPlog || meanDistPhiCounts[iLayer][iRefLayer]<1000){
190  pdfAllRef[iLayer][iRefLayer][iPdf] = 0;
191  continue;
192  }
196  digitisedVal = rint((std::pow(2,nPdfValBits)-1) - (pVal/minPlog)*(std::pow(2,nPdfValBits)-1));
198  truncatedValue = 0 | (digitisedVal & ((int)pow(2,nPdfValBits)-1));
199  pdfAllRef[iLayer][iRefLayer][iPdf] = truncatedValue;
200  }
201  }
202  }
203 
204 
205  vector3D pdfAllRefTmp = pdfAllRef;
206 
207  const unsigned int nPdfAddrBits = 7;
208  for (unsigned int iRefLayer=0;iRefLayer<pdfAllRef[0].size();++iRefLayer){
209  for (unsigned int iLayer=0;iLayer<pdfAllRef.size();++iLayer){
210  for (unsigned int iPdf=0;iPdf<pdfAllRef[iLayer][iRefLayer].size();++iPdf){
211  pdfAllRef[iLayer][iRefLayer][iPdf] = 0;
213  int index = iPdf - exp2(OMTFConfiguration::instance()->nPdfAddrBits-1) - meanDistPhi[iLayer][iRefLayer] + exp2(nPdfAddrBits-1);
214  if(index<0 || index>exp2(nPdfAddrBits)-1) continue;
215  pdfAllRef[iLayer][iRefLayer][index] = pdfAllRefTmp[iLayer][iRefLayer][iPdf];
216  }
217  }
218  }
219 }
223 
224  for (unsigned int iRefLayer=0;iRefLayer<meanDistPhi[0].size();++iRefLayer){
225  for (unsigned int iLayer=0;iLayer<meanDistPhi.size();++iLayer){
226  if(meanDistPhiCounts.size() && meanDistPhiCounts[iLayer][iRefLayer]) return true;
227  }
228  }
229  return false;
230 }
vector2D meanDistPhiCounts
std::vector< int > vector1D
Definition: GoldenPattern.h:49
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;.
std::vector< int > refToLogicNumber
GoldenPattern::layerResult process1Layer1RefLayer(unsigned int iRefLayer, unsigned int iLayer, const int refPhi, const OMTFinput::vector1D &layerHits)
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
unsigned int nPhiBins
std::pair< int, bool > layerResult
Definition: GoldenPattern.h:52
void reset()
Reset contents of all data vectors, keeping the vectors size.
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 const OMTFConfiguration * instance()
unsigned int nPdfValBits