CMS 3D CMS Logo

GoldenPatternResult.cc
Go to the documentation of this file.
3 
5 
6 #include <iostream>
7 #include <ostream>
8 #include <iomanip>
9 #include <cmath>
10 
13 
17  : finalise([this]() { finalise0(); }), omtfConfig(omtfConfig) {
18  if (omtfConfig)
20 }
21 
24 
25 void GoldenPatternResult::set(int refLayer_, int phi, int eta, int refHitPhi) {
26  if (isValid() && this->refLayer != refLayer_) {
27  std::cout << __FUNCTION__ << " " << __LINE__ << " this->refLayer " << this->refLayer << " refLayer_ " << refLayer_
28  << std::endl;
29  }
30  assert(!isValid() || this->refLayer == refLayer_);
31 
32  this->refLayer = refLayer_;
33  this->phi = phi;
34  this->eta = eta;
35  this->refHitPhi = refHitPhi;
36 }
37 
38 void GoldenPatternResult::setStubResult(float pdfVal, bool valid, int pdfBin, int layer, MuonStubPtr stub) {
39  if (valid) {
40  //pdfSum and firedLayerBits is calculated in finaliseX()
41  firedLayerBits |= (1 << layer);
42  }
43  stubResults[layer] = StubResult(pdfVal, valid, pdfBin, layer, stub);
44 
45  //stub result is added even thought it is not valid since this might be needed for debugging or optimization
46 }
47 
49  if (stubResult.getValid()) {
50  //pdfSum and firedLayerBits is calculated in finaliseX()
51  firedLayerBits |= (1 << layer);
52  }
53  stubResults[layer] = stubResult;
54 
55  //stub result is added even thought it is not valid since this might be needed for debugging or optimization
56 }
57 
61  this->omtfConfig = omtfConfig;
62 
64 
65  if (finalizeFunction == 1)
66  finalise = [this]() { finalise1(); };
67  else if (finalizeFunction == 2)
68  finalise = [this]() { finalise2(); };
69  else if (finalizeFunction == 3)
70  finalise = [this]() { finalise3(); };
71  else if (finalizeFunction == 5)
72  finalise = [this]() { finalise5(); };
73  else if (finalizeFunction == 6)
74  finalise = [this]() { finalise6(); };
75  else if (finalizeFunction == 7)
76  finalise = [this]() { finalise7(); };
77  else if (finalizeFunction == 8)
78  finalise = [this]() { finalise8(); };
79  else if (finalizeFunction == 9)
80  finalise = [this]() { finalise9(); };
81  else
82  finalise = [this]() { finalise0(); };
83 
85  reset();
86 }
87 
89  for (auto& stubResult : stubResults) {
90  stubResult.reset();
91  }
92  valid = false;
93  refLayer = -1;
94  phi = 0;
95  eta = 0;
96  pdfSum = 0;
97  firedLayerCnt = 0;
98  firedLayerBits = 0;
99  refHitPhi = 0;
100  gpProbability1 = 0;
101  gpProbability2 = 0;
102 }
103 
106 //default version
108  for (unsigned int iLogicLayer = 0; iLogicLayer < stubResults.size(); ++iLogicLayer) {
109  unsigned int connectedLayer = omtfConfig->getLogicToLogic().at(iLogicLayer);
110  //here we require that in case of the DT layers, both phi and phiB is fired
111  if (firedLayerBits & (1 << connectedLayer)) {
112  if (firedLayerBits & (1 << iLogicLayer)) {
113  //now in the GoldenPattern::process1Layer1RefLayer the pdf bin 0 is returned when the layer is not fired, so this is 'if' is to assured that this pdf val is not added here
114  pdfSum += stubResults[iLogicLayer].getPdfVal();
115 
116  if (omtfConfig->fwVersion() <= 4) {
117  if (!omtfConfig->getBendingLayers().count(iLogicLayer))
118  //in DT case, the phi and phiB layers are threaded as one, so the firedLayerCnt is increased only for the phi layer
119  firedLayerCnt++;
120  } else
121  firedLayerCnt++;
122  }
123  } else {
124  firedLayerBits &= ~(1 << iLogicLayer);
125  }
126  }
127 
128  valid = true;
129  //by default result becomes valid here, but can be overwritten later
130 }
131 
134 //for the algo version with thresholds
136  //cout<<__FUNCTION__<<":"<<__LINE__<<endl;
137  for (unsigned int iLogicLayer = 0; iLogicLayer < stubResults.size(); ++iLogicLayer) {
138  //in this version we do not require that both phi and phiB is fired (non-zero), we thread them just independent
139  //watch out that then the number of fired layers is bigger, and the cut on the minimal number of fired layers does not work in the same way as when the dt chamber is counted as one layer
140  //TODO check if it affects performance
141  pdfSum += stubResults[iLogicLayer].getPdfVal();
142  firedLayerCnt += ((firedLayerBits & (1 << iLogicLayer)) != 0);
143  }
144 
145  valid = true;
146  //by default result becomes valid here, but can be overwritten later
147 }
148 
151 //multiplication of PDF values instead of sum
153  pdfSum = 1.;
154  firedLayerCnt = 0;
155  for (unsigned int iLogicLayer = 0; iLogicLayer < stubResults.size(); ++iLogicLayer) {
156  unsigned int connectedLayer = omtfConfig->getLogicToLogic().at(iLogicLayer);
157  //here we require that in case of the DT layers, both phi and phiB is fired
158  if (firedLayerBits & (1 << connectedLayer)) {
159  //now in the GoldenPattern::process1Layer1RefLayer the pdf bin 0 is returned when the layer is not fired, so this is 'if' is to assured that this pdf val is not added here
160  if (firedLayerBits & (1 << iLogicLayer)) {
161  pdfSum *= stubResults[iLogicLayer].getPdfVal();
162  //in DT case, the phi and phiB layers are threaded as one, so the firedLayerCnt is increased only for the phi layer
163  if (!omtfConfig->getBendingLayers().count(iLogicLayer))
164  firedLayerCnt++;
165  }
166  } else {
167  firedLayerBits &= ~(1 << iLogicLayer);
168  }
169  }
170 
171  if (firedLayerCnt < 3)
172  pdfSum = 0;
173 
174  valid = true;
175  //by default result becomes valid here, but can be overwritten later
176 }
177 
180 //for patterns generation
182  firedLayerCnt = 0;
183  for (unsigned int iLogicLayer = 0; iLogicLayer < stubResults.size(); ++iLogicLayer) {
184  //in this version we do not require that both phi and phiB is fired (non-zero), we thread them just independent
185  //watch out that then the number of fired layers is bigger, and the cut on the minimal number of fired layers dies not work in the same way as when the dt chamber is counted as one layer
186  //TODO check if it affects performance
187  pdfSum += stubResults[iLogicLayer].getPdfVal();
188 
189  if (stubResults[iLogicLayer].getMuonStub())
190  firedLayerCnt++;
191  }
192 
193  valid = true;
194  //by default result becomes valid here, but can be overwritten later
195 }
196 
198  for (unsigned int iLogicLayer = 0; iLogicLayer < stubResults.size(); ++iLogicLayer) {
199  unsigned int connectedLayer = omtfConfig->getLogicToLogic().at(iLogicLayer);
200 
201  if (omtfConfig->isBendingLayer(iLogicLayer)) { //the DT phiB layer is counted only when the phi layer is fired
202  if ((firedLayerBits & (1 << iLogicLayer)) && (firedLayerBits & (1 << connectedLayer))) {
203  pdfSum += stubResults[iLogicLayer].getPdfVal();
204  firedLayerCnt++;
205  } else {
206  firedLayerBits &= ~(1 << iLogicLayer);
207  stubResults[iLogicLayer].setValid(false);
208  //in principle the stun should be also removed from the stubResults[iLogicLayer], on the other hand ini this way can be used e.g. for debug
209  }
210  } else if (firedLayerBits & (1 << iLogicLayer)) {
211  pdfSum += stubResults[iLogicLayer].getPdfVal();
212  firedLayerCnt++;
213  }
214  }
215 
216  valid = true;
217  //by default result becomes valid here, but can be overwritten later
218 }
219 
221  for (unsigned int iLogicLayer = 0; iLogicLayer < stubResults.size(); ++iLogicLayer) {
222  unsigned int connectedLayer = omtfConfig->getLogicToLogic().at(iLogicLayer);
223 
224  if (omtfConfig->isBendingLayer(iLogicLayer)) { //the DT phiB layer is counted only when the phi layer is fired
225  if ((firedLayerBits & (1 << iLogicLayer)) && (firedLayerBits & (1 << connectedLayer)) &&
226  (stubResults[iLogicLayer].getMuonStub()->qualityHw >= 4)) {
227  pdfSum += stubResults[iLogicLayer].getPdfVal();
228  firedLayerCnt++;
229  } else {
230  firedLayerBits &= ~(1 << iLogicLayer);
231  stubResults[iLogicLayer].setValid(false);
232  //in principle the stun should be also removed from the stubResults[iLogicLayer], on the other hand ini this way can be used e.g. for debug
233  }
234  } else if (firedLayerBits & (1 << iLogicLayer)) {
235  pdfSum += stubResults[iLogicLayer].getPdfVal();
236  firedLayerCnt++;
237  }
238  }
239 
240  valid = true;
241  //by default result becomes valid here, but can be overwritten later
242 }
243 
245  for (unsigned int iLogicLayer = 0; iLogicLayer < stubResults.size(); ++iLogicLayer) {
246  pdfSum += stubResults[iLogicLayer].getPdfVal();
247  if (firedLayerBits & (1 << iLogicLayer)) {
248  firedLayerCnt++;
249  }
250  }
251 
252  valid = true;
253  //by default result becomes valid here, but can be overwritten later
254 }
255 
257  for (unsigned int iLogicLayer = 0; iLogicLayer < stubResults.size(); ++iLogicLayer) {
258  pdfSum += stubResults[iLogicLayer].getPdfVal(); //pdfSum is counted always
259 
260  unsigned int connectedLayer = omtfConfig->getLogicToLogic().at(iLogicLayer);
261  if (omtfConfig->isBendingLayer(iLogicLayer)) { //the DT phiB layer is counted only when the phi layer is fired
262  if ((firedLayerBits & (1 << iLogicLayer)) && (firedLayerBits & (1 << connectedLayer))) {
263  // && (stubResults[iLogicLayer].getMuonStub()->qualityHw >= 4) this is not needed, as the rejecting the low quality phiB hits is on the input of the algorithm
264  firedLayerCnt++;
265  } else {
266  firedLayerBits &= ~(1 << iLogicLayer);
267  stubResults[iLogicLayer].setValid(false);
268  //in principle the stub should be also removed from the stubResults[iLogicLayer], on the other hand in this way can be used e.g. for debug
269  }
270  } else if (firedLayerBits & (1 << iLogicLayer)) {
271  firedLayerCnt++;
272  }
273  }
274 
275  valid = true;
276  //by default result becomes valid here, but can be overwritten later
277 }
278 
280  for (unsigned int iLogicLayer = 0; iLogicLayer < stubResults.size(); ++iLogicLayer) {
281  unsigned int connectedLayer = omtfConfig->getLogicToLogic().at(iLogicLayer);
282 
283  if (omtfConfig->isBendingLayer(iLogicLayer)) { //the DT phiB layer is counted only when the phi layer is fired
284  if (firedLayerBits & (1 << iLogicLayer)) {
285  if (firedLayerBits & (1 << connectedLayer)) {
286  firedLayerCnt++;
287  pdfSum += stubResults[iLogicLayer].getPdfVal();
288  } else {
289  firedLayerBits &= ~(1 << iLogicLayer);
290  stubResults[iLogicLayer].setValid(false);
291  //there was hit, but it did not fit to the pdf - this is not possible here, since the bending layer is fired here
292  //therefore the below line is has no sense
293  //if(stubResults[iLogicLayer].getPdfVal() == 0) pdfSum -= 64;;
294  //so in this case simply:
295  //pdfSum += 0;
296  }
297  } else {
298  //bending layer fired, but not fits to the pdf, N.B works only with the patterns having "no hit value" and with noHitValueInPdf = True
299  if (stubResults[iLogicLayer].getPdfVal() == 0)
300  pdfSum -= 32;
301  else
302  pdfSum += stubResults[iLogicLayer].getPdfVal(); //bending layer not fired at all
303  }
304  } else {
305  if (iLogicLayer < 10 && stubResults[iLogicLayer].getPdfVal() == 0)
306  pdfSum -= 32;
307  else
308  pdfSum += stubResults[iLogicLayer].getPdfVal();
309  if (firedLayerBits & (1 << iLogicLayer)) { //pdfSum is counted always
310  firedLayerCnt++;
311  }
312  }
313  }
314 
315  valid = true;
316  //by default result becomes valid here, but can be overwritten later
317 }
318 
321 std::ostream& operator<<(std::ostream& out, const GoldenPatternResult& gpResult) {
322  unsigned int refLayerLogicNum = gpResult.omtfConfig->getRefToLogicNumber()[gpResult.getRefLayer()];
323 
324  unsigned int sumOverFiredLayers = 0;
325  for (unsigned int iLogicLayer = 0; iLogicLayer < gpResult.stubResults.size(); ++iLogicLayer) {
326  out << " layer: " << std::setw(2) << iLogicLayer << " hit: ";
327  if (gpResult.stubResults[iLogicLayer].getMuonStub()) {
328  out << std::setw(4)
329  << (gpResult.omtfConfig->isBendingLayer(iLogicLayer)
330  ? gpResult.stubResults[iLogicLayer].getMuonStub()->phiBHw
331  : gpResult.stubResults[iLogicLayer].getMuonStub()->phiHw);
332 
333  out << " pdfBin: " << std::setw(4) << gpResult.stubResults[iLogicLayer].getPdfBin() << " pdfVal: " << std::setw(3)
334  << gpResult.stubResults[iLogicLayer].getPdfVal() << " fired " << gpResult.isLayerFired(iLogicLayer)
335  << (iLogicLayer == refLayerLogicNum ? " <<< refLayer" : "");
336 
337  if (gpResult.isLayerFired(iLogicLayer))
338  sumOverFiredLayers += gpResult.stubResults[iLogicLayer].getPdfVal();
339  } else if (gpResult.stubResults[iLogicLayer].getPdfVal()) {
340  out << " pdfVal: " << std::setw(3) << gpResult.stubResults[iLogicLayer].getPdfVal();
341  }
342  out << std::endl;
343  }
344 
345  out << " refLayer: ";
346  out << gpResult.getRefLayer() << "\t";
347 
348  out << " Sum over layers: ";
349  out << gpResult.getPdfSum() << "\t";
350 
351  out << " sumOverFiredLayers: ";
352  out << sumOverFiredLayers << "\t";
353 
354  out << " Number of hits: ";
355  out << gpResult.getFiredLayerCnt() << "\t";
356 
357  out << " GpProbability1: ";
358  out << gpResult.getGpProbability1() << "\t";
359 
360  out << " GpProbability2: ";
361  out << gpResult.getGpProbability2() << "\t";
362 
363  out << std::endl;
364 
365  return out;
366 }
std::ostream & operator<<(std::ostream &out, const GoldenPatternResult &gpResult)
unsigned int firedLayerBits
bits representing fired logicLayers (including bending layers),
double getGpProbability1() const
void set(int refLayer, int phi, int eta, int refHitPhi)
const OMTFConfiguration * omtfConfig
std::function< void()> finalise
assert(be >=bs)
int getGoldenPatternResultFinalizeFunction() const
unsigned int fwVersion() const
double getGpProbability2() const
bool getValid() const
Definition: StubResult.h:27
void init(const OMTFConfiguration *omtfConfig)
void setStubResult(float pdfVal, bool valid, int pdfBin, int layer, MuonStubPtr stub)
unsigned int nLayers() const
std::shared_ptr< MuonStub > MuonStubPtr
Definition: MuonStub.h:65
const std::vector< int > & getRefToLogicNumber() const
const std::map< int, int > & getLogicToLogic() const
bool isLayerFired(unsigned int iLayer) const
unsigned int getFiredLayerCnt() const
int eta
eta at the 2nd muon station
const std::set< int > & getBendingLayers() const
PdfValueType getPdfSum() const
double pdfSum
Sum of pdfValues.
unsigned int firedLayerCnt
Number of fired layers - excluding bending layers.
bool isBendingLayer(unsigned int iLayer) const override
int phi
phi at the 2nd muon station (propagated refHitPhi)
int refHitPhi
phi of the reference hits