test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuCondition.cc
Go to the documentation of this file.
1 
15 // this class header
17 
18 // system include files
19 #include <iostream>
20 #include <iomanip>
21 
22 #include <string>
23 #include <vector>
24 #include <algorithm>
25 
26 // user include files
27 // base classes
30 
32 
34 
37 
40 
41 // constructors
42 // default
45 
46  // empty
47 
48 }
49 
50 // from base template condition (from event setup usually)
52  const GtBoard* ptrGTL, const int nrL1Mu,
53  const int ifMuEtaNumberBits) :
55  m_gtMuonTemplate(static_cast<const MuonTemplate*>(muonTemplate)),
56  m_gtGTL(ptrGTL),
57  m_ifMuEtaNumberBits(ifMuEtaNumberBits)
58 {
60  m_condMaxNumberObjects = nrL1Mu;
61 }
62 
63 // copy constructor
65 
66  m_gtMuonTemplate = cp.gtMuonTemplate();
67  m_gtGTL = cp.gtGTL();
68 
69  m_ifMuEtaNumberBits = cp.gtIfMuEtaNumberBits();
70  m_corrParDeltaPhiNrBins = cp.m_corrParDeltaPhiNrBins;
71 
72  m_condMaxNumberObjects = cp.condMaxNumberObjects();
73  m_condLastResult = cp.condLastResult();
74  m_combinationsInCond = cp.getCombinationsInCond();
75 
76  m_verbosity = cp.m_verbosity;
77 
78 }
79 
82  copy(cp);
83 }
84 
85 // destructor
87 
88  // empty
89 
90 }
91 
92 // equal operator
94 {
95  copy(cp);
96  return *this;
97 }
98 
99 // methods
101 
102  m_gtMuonTemplate = muonTempl;
103 
104 }
105 
107 void l1t::MuCondition::setGtGTL(const GtBoard* ptrGTL) {
108 
109  m_gtGTL = ptrGTL;
110 
111 }
112 
113 
114 // set the number of bits for eta of muon objects
116  const int& ifMuEtaNumberBitsValue) {
117 
118  m_ifMuEtaNumberBits = ifMuEtaNumberBitsValue;
119 
120 }
121 
122 // set the maximum number of bins for the delta phi scales
124  const int& corrParDeltaPhiNrBins) {
125 
126  m_corrParDeltaPhiNrBins = corrParDeltaPhiNrBins;
127 
128 }
129 
130 
131 // try all object permutations and check spatial correlations, if required
132 const bool l1t::MuCondition::evaluateCondition(const int bxEval) const {
133 
134  // BLW Need to pass this as an argument
135  //const int bxEval=0; //BLW Change for BXVector
136 
137  // number of trigger objects in the condition
138  int nObjInCond = m_gtMuonTemplate->nrObjects();
139 
140  // the candidates
141  const BXVector<const l1t::Muon*>* candVec = m_gtGTL->getCandL1Mu(); //BLW Change for BXVector
142 
143  // Look at objects in bx = bx + relativeBx
144  int useBx = bxEval + m_gtMuonTemplate->condRelativeBx();
145 
146  // Fail condition if attempting to get Bx outside of range
147  if( ( useBx < candVec->getFirstBX() ) ||
148  ( useBx > candVec->getLastBX() ) ) {
149  return false;
150  }
151 
152  int numberObjects = candVec->size(useBx); //BLW Change for BXVector
153  //LogTrace("L1GlobalTrigger") << " numberObjects: " << numberObjects
154  // << std::endl;
155  if (numberObjects < nObjInCond) {
156  return false;
157  }
158 
159  std::vector<int> index(numberObjects);
160 
161  for (int i = 0; i < numberObjects; ++i) {
162  index[i] = i;
163  }
164 
165  int jumpIndex = 1;
166  int jump = factorial(numberObjects - nObjInCond);
167 
168  int totalLoops = 0;
169  int passLoops = 0;
170 
171  // condition result condResult set to true if at least one permutation
172  // passes all requirements
173  // all possible permutations are checked
174  bool condResult = false;
175 
176  // store the indices of the muon objects
177  // from the combination evaluated in the condition
178  SingleCombInCond objectsInComb;
179  objectsInComb.reserve(nObjInCond);
180 
181  // clear the m_combinationsInCond vector
182  (combinationsInCond()).clear();
183 
184  do {
185 
186  if (--jumpIndex)
187  continue;
188 
189  jumpIndex = jump;
190  totalLoops++;
191 
192  // clear the indices in the combination
193  objectsInComb.clear();
194 
195  bool tmpResult = true;
196 
197  bool passCondition = false;
198  // check if there is a permutation that matches object-parameter requirements
199  for (int i = 0; i < nObjInCond; i++) {
200 
201  passCondition = checkObjectParameter(i, *(candVec->at(useBx,index[i]) )); //BLW Change for BXVector
202  tmpResult &= passCondition;
203  if( passCondition )
204  LogDebug("l1t|Global") << "===> MuCondition::evaluateCondition, CONGRATS!! This muon passed the condition." << std::endl;
205  else
206  LogDebug("l1t|Global") << "===> MuCondition::evaluateCondition, FAIL!! This muon failed the condition." << std::endl;
207  objectsInComb.push_back(index[i]);
208 
209  }
210 
211  // if permutation does not match particle conditions
212  // skip charge correlation and spatial correlations
213  if ( !tmpResult) {
214 
215  continue;
216 
217  }
218 
219  // get the correlation parameters (chargeCorrelation included here also)
221  *(m_gtMuonTemplate->correlationParameter());
222 
223  // charge_correlation consists of 3 relevant bits (D2, D1, D0)
224  unsigned int chargeCorr = corrPar.chargeCorrelation;
225 
226  // charge ignore bit (D0) not set?
227  if ((chargeCorr & 1) == 0) {
228 
229  for (int i = 0; i < nObjInCond; i++) {
230  // check valid charge - skip if invalid charge
231  int chargeValid = (candVec->at(useBx,index[i]))->hwChargeValid(); //BLW Change for BXVector
232  tmpResult &= chargeValid;
233 
234  if ( chargeValid==0) { //BLW type change for New Muon Class
235  continue;
236  }
237  }
238 
239  if ( !tmpResult) {
240  continue;
241  }
242 
243  if (nObjInCond == 1) { // one object condition
244 
245  // D2..enable pos, D1..enable neg
246  if ( ! ( ( (chargeCorr & 4) != 0 && (candVec->at(useBx,index[0]))->charge()> 0 ) //BLW Change for BXVector
247  || ( (chargeCorr & 2) != 0 && (candVec->at(useBx,index[0]))->charge() < 0 ) )) { //BLW Change for BXVector
248 
249  continue;
250  }
251 
252  }
253  else { // more objects condition
254 
255  // find out if signs are equal
256  bool equalSigns = true;
257  for (int i = 0; i < nObjInCond-1; i++) {
258  if ((candVec->at(useBx,index[i]))->charge() != (candVec->at(useBx,index[i+1]))->charge()) { //BLW Change for BXVector
259  equalSigns = false;
260  break;
261  }
262  }
263 
264  // two or three particle condition
265  if (nObjInCond == 2 || nObjInCond == 3) {
266  // D2..enable equal, D1..enable not equal
267  if ( ! ( ( (chargeCorr & 4) != 0 && equalSigns ) || ( (chargeCorr & 2) != 0
268  && !equalSigns ) )) {
269 
270  continue;
271  }
272  }
273 
274  // four particle condition
275  if (nObjInCond == 4) {
276  //counter to count positive charges to determine if there are pairs
277  unsigned int posCount = 0;
278 
279  for (int i = 0; i < nObjInCond; i++) {
280  if ((candVec->at(useBx,index[i]))->charge()> 0) { //BLW Change for BXVector
281  posCount++;
282  }
283  }
284 
285  // D2..enable equal, D1..enable pairs
286  if ( ! ( ( (chargeCorr & 4) != 0 && equalSigns ) || ( (chargeCorr & 2) != 0
287  && posCount == 2 ) )) {
288 
289  continue;
290  }
291  }
292  }
293  } // end signchecks
294 
295 
296  if (m_gtMuonTemplate->wsc()) {
297 
298  // wsc requirements have always nObjInCond = 2
299  // one can use directly index[0] and index[1] to compute
300  // eta and phi differences
301  const int ObjInWscComb = 2;
302  if (nObjInCond != ObjInWscComb) {
303 
304  edm::LogError("L1GlobalTrigger") << "\n Error: "
305  << "number of particles in condition with spatial correlation = " << nObjInCond
306  << "\n it must be = " << ObjInWscComb << std::endl;
307  // TODO Perhaps I should throw here an exception,
308  // since something is really wrong if nObjInCond != ObjInWscComb (=2)
309  continue;
310  }
311 
312  unsigned int candDeltaEta;
313  unsigned int candDeltaPhi;
314 
315  // check candDeltaEta
316 
317  // get eta index and the sign bit of the eta index (MSB is the sign)
318  // signedEta[i] is the signed eta index of (*candVec)[index[i]]
319  int signedEta[ObjInWscComb];
320  int signBit[ObjInWscComb] = { 0, 0 };
321 
322  int scaleEta = 1 << (m_ifMuEtaNumberBits - 1);
323 
324  for (int i = 0; i < ObjInWscComb; ++i) {
325  signBit[i] = ((candVec->at(useBx,index[i]))->hwEta() & scaleEta)>>(m_ifMuEtaNumberBits - 1); //BLW Change for BXVector
326  signedEta[i] = ((candVec->at(useBx,index[i]))->hwEta() )%scaleEta; //BLW Change for BXVector
327 
328  if (signBit[i] == 1) {
329  signedEta[i] = (-1)*signedEta[i];
330  }
331 
332  }
333 
334  // compute candDeltaEta - add 1 if signs are different (due to +0/-0 indices)
335  candDeltaEta = static_cast<int> (std::abs(signedEta[1] - signedEta[0]))
336  + static_cast<int> (signBit[1]^signBit[0]);
337 
338  if ( !checkBit(corrPar.deltaEtaRange, candDeltaEta) ) {
339  continue;
340  }
341 
342  // check candDeltaPhi
343 
344  // calculate absolute value of candDeltaPhi
345  if ((candVec->at(useBx,index[0]))->hwPhi()> (candVec->at(useBx,index[1]))->hwPhi()) { //BLW Change for BXVector
346  candDeltaPhi = (candVec->at(useBx,index[0]))->hwPhi() - (candVec->at(useBx,index[1]))->hwPhi(); //BLW Change for BXVector
347  }
348  else {
349  candDeltaPhi = (candVec->at(useBx,index[1]))->hwPhi() - (candVec->at(useBx,index[0]))->hwPhi(); //BLW Change for BXVector
350  }
351 
352  // check if candDeltaPhi > 180 (via delta_phi_maxbits)
353  // delta_phi contains bits for 0..180 (0 and 180 included)
354  // protect also against infinite loop...
355 
356  int nMaxLoop = 10;
357  int iLoop = 0;
358 
359  while (candDeltaPhi >= m_corrParDeltaPhiNrBins) {
360 
361  unsigned int candDeltaPhiInitial = candDeltaPhi;
362 
363  // candDeltaPhi > 180 ==> take 360 - candDeltaPhi
364  candDeltaPhi = (m_corrParDeltaPhiNrBins - 1) * 2 - candDeltaPhi;
365  if (m_verbosity) {
366  LogTrace("L1GlobalTrigger")
367  << " Initial candDeltaPhi = "
368  << candDeltaPhiInitial
369  << " > m_corrParDeltaPhiNrBins = "
370  << m_corrParDeltaPhiNrBins
371  << " ==> candDeltaPhi rescaled to: "
372  << candDeltaPhi << " [ loop index " << iLoop
373  << "; breaks after " << nMaxLoop << " loops ]\n"
374  << std::endl;
375  }
376 
377  iLoop++;
378  if (iLoop > nMaxLoop) {
379  return false;
380  }
381  }
382 
383  // delta_phi bitmask is saved in two boost::uint64_t words
384  if (candDeltaPhi < 64) {
385  if (!checkBit(corrPar.deltaPhiRange0Word, candDeltaPhi) ) {
386  continue;
387  }
388  }
389  else {
390  if (!checkBit(corrPar.deltaPhiRange1Word, (candDeltaPhi - 64))) {
391  continue;
392  }
393  }
394 
395  } // end wsc check
396 
397  // if we get here all checks were successfull for this combination
398  // set the general result for evaluateCondition to "true"
399 
400  condResult = true;
401  passLoops++;
402  (combinationsInCond()).push_back(objectsInComb);
403 
404  } while (std::next_permutation(index.begin(), index.end()) );
405 
406  //LogTrace("L1GlobalTrigger")
407  // << "\n MuCondition: total number of permutations found: " << totalLoops
408  // << "\n MuCondition: number of permutations passing requirements: " << passLoops
409  // << "\n" << std::endl;
410 
411  return condResult;
412 
413 }
414 
415 // load muon candidates
416 const l1t::Muon* l1t::MuCondition::getCandidate(const int bx, const int indexCand) const {
417 
418  return (m_gtGTL->getCandL1Mu())->at(bx,indexCand); //BLW Change for BXVector
419 }
420 
430 const bool l1t::MuCondition::checkObjectParameter(const int iCondition, const l1t::Muon& cand) const {
431 
432  // number of objects in condition
433  int nObjInCond = m_gtMuonTemplate->nrObjects();
434 
435  if (iCondition >= nObjInCond || iCondition < 0) {
436  return false;
437  }
438 
439 // // empty candidates can not be compared
440 // if (cand.empty()) {
441 // return false;
442 // }
443 
444  const MuonTemplate::ObjectParameter objPar =
445  ( *(m_gtMuonTemplate->objectParameter()) )[iCondition];
446 
447  // using the logic table from GTL-9U-module.pdf
448  // "Truth table for Isolation bit"
449 
450  // check thresholds:
451 
452  // value < low pt threshold
453  // fail trigger
454 
455  // low pt threshold <= value < high pt threshold & non-isolated muon:
456  // requestIso true: fail trigger
457  // requestIso false, enableIso true: fail trigger
458  // requestIso false, enableIso false: OK, trigger
459 
460  // low pt threshold <= value < high pt threshold & isolated muon:
461  // requestIso true: OK, trigger
462  // requestIso false, enableIso true: OK, trigger
463  // requestIso false, enableIso false: OK, trigger
464 
465  // value >= high pt threshold & non-isolated muon:
466  // requestIso true: fail trigger
467  // requestIso false: OK, trigger
468 
469  // value >= high pt threshold & isolated muon:
470  // OK, trigger
471 
472  LogDebug("l1t|Global")
473  << "\n MuonTemplate::ObjectParameter : "
474  << "\n\t ptHighThreshold = " << objPar.ptHighThreshold
475  << "\n\t ptLowThreshold = " << objPar.ptLowThreshold
476  << "\n\t requestIso = " << objPar.requestIso
477  << "\n\t enableIso = " << objPar.enableIso
478  << "\n\t etaRange = " << objPar.etaRange
479  << "\n\t phiLow = " << objPar.phiLow
480  << "\n\t phiHigh = " << objPar.phiHigh
481  << "\n\t qualityRange = " << objPar.qualityRange
482  << "\n\t enableMip = " << objPar.enableMip
483  << std::endl;
484 
485  LogDebug("l1t|Global")
486  << "\n l1t::Muon : "
487  << "\n\t hwPt = " << cand.hwPt()
488  << "\n\t hwEta = " << cand.hwEta()
489  << "\n\t hwPhi = " << cand.hwPhi()
490  << "\n\t hwQual = " << cand.hwQual()
491  << "\n\t hwIso = " << cand.hwIso()
492  << "\n\t hwMip = " << cand.hwMip()
493  << std::endl;
494 
495 
496  if ( !checkThreshold(objPar.ptHighThreshold, cand.hwPt(), m_gtMuonTemplate->condGEq()) ) {
497 
498  if ( !checkThreshold(objPar.ptLowThreshold, cand.hwPt(), m_gtMuonTemplate->condGEq()) ) {
499  LogDebug("l1t|Global") << "\t\t Muon Failed checkThreshold " << std::endl;
500  return false;
501  }
502  else {
503  // check isolation
504  if ( !cand.hwIso() ) {
505  if (objPar.requestIso || objPar.enableIso) {
506  LogDebug("l1t|Global") << "\t\t Muon Failed hwIso " << std::endl;
507  return false;
508  }
509  }
510  }
511  }
512  else {
513 
514  if ( !cand.hwIso() ) {
515  if (objPar.requestIso) {
516  LogDebug("l1t|Global") << "\t\t Muon Failed hwIso " << std::endl;
517  return false;
518  }
519  }
520  }
521 
522  // check eta
523  // DP - Enable once muon conditions mature
524 // if( !checkRange(cand.hwEta(), objPar.etaRangeBegin, objPar.etaRangeEnd, objPar.etaRangeVetoBegin, objPar.etaRangeVetoEnd) ){
525 // return false;
526 // }
527 
528 // // check phi
529 // if( !checkRange(cand.hwPhi(), objPar.phiRangeBegin, objPar.phiRangeEnd, objPar.phiRangeVetoBegin, objPar.phiRangeVetoEnd) ){
530 // return false;
531 // }
532 
534 // if (!checkBit(objPar.etaRange, cand.hwEta())) {
535 // LogDebug("l1t|Global") << "\t\t Muon Failed checkBit(etaRange) " << std::endl;
536 // return false;
537 // }
538 
539 // // check phi - in the requested range (no LUT used - LUT too big for hw chip)
540 // // for phiLow <= phiHigh takes [phiLow, phiHigh]
541 // // for phiLow >= phiHigh takes [phiLow, phiHigh] over zero angle!
542 // if (objPar.phiHigh >= objPar.phiLow) {
543 // if (! ( (objPar.phiLow <= (unsigned int)cand.hwPhi()) && ((unsigned int)cand.hwPhi() <= objPar.phiHigh ) )) {
544 // LogDebug("l1t|Global") << "\t\t Muon Failed checkBit(phiRange) " << std::endl;
545 // return false;
546 // }
547 // }
548 // else { // go over zero angle!!
549 // if (! ( (objPar.phiLow <= (unsigned int)cand.hwPhi()) || ((unsigned int)cand.hwPhi() <= objPar.phiHigh ) )) {
550 // LogDebug("l1t|Global") << "\t\t Muon Failed checkBit(phiRange) " << std::endl;
551 // return false;
552 // }
553 // }
554 
555  // check quality ( bit check )
556 
557  // A number of values is required to trigger (at least one).
558  // "Don’t care" means that all values are allowed.
559  // Qual = 000 means then NO MUON (GTL module)
560 
561  if (cand.hwQual() == 0) {
562  LogDebug("l1t|Global") << "\t\t Muon Failed hwQual() == 0" << std::endl;
563  return false;
564  }
565 
566  if (objPar.qualityRange == 0) {
567  LogDebug("l1t|Global") << "\t\t Muon Failed qualityRange == 0" << std::endl;
568  return false;
569  }
570  else {
571  if (!checkBit(objPar.qualityRange, cand.hwQual())) {
572  LogDebug("l1t|Global") << "\t\t Muon Failed checkBit(qualityRange) " << std::endl;
573  return false;
574  }
575  }
576 
577  // check mip
578  if (objPar.enableMip) {
579  if (!cand.hwMip()) {
580  LogDebug("l1t|Global") << "\t\t Muon Failed enableMip" << std::endl;
581  return false;
582  }
583  }
584 
585  // particle matches if we get here
586  //LogTrace("L1GlobalTrigger")
587  // << " checkObjectParameter: muon object OK, passes all requirements\n" << std::endl;
588 
589  return true;
590 }
591 
592 void l1t::MuCondition::print(std::ostream& myCout) const {
593 
594  m_gtMuonTemplate->print(myCout);
595 
596  myCout << " Number of bits for eta of muon objects = "
597  << m_ifMuEtaNumberBits << std::endl;
598  myCout << " Maximum number of bins for the delta phi scales = "
599  << m_corrParDeltaPhiNrBins << "\n " << std::endl;
600 
602 
603 }
604 
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
unsigned size(int bx) const
CombinationsInCond const & getCombinationsInCond() const
get all the object combinations evaluated to true in the condition
const MuonTemplate * gtMuonTemplate() const
get / set the pointer to a Condition
Definition: MuCondition.h:70
virtual ~MuCondition()
Definition: MuCondition.cc:86
void print(std::ostream &myCout) const
print condition
Definition: MuCondition.cc:592
const bool checkObjectParameter(const int iCondition, const l1t::Muon &cand) const
function to check a single object if it matches a condition
Definition: MuCondition.cc:430
virtual void print(std::ostream &myCout) const
print condition
std::vector< int > SingleCombInCond
typedefs
int hwPhi() const
Definition: L1Candidate.cc:79
double charge(const std::vector< uint8_t > &Ampls)
const bool evaluateCondition(const int bxEval) const
the core function to check if the condition matches
Definition: MuCondition.cc:132
int hwMip() const
Definition: Muon.cc:59
int hwIso() const
Definition: L1Candidate.cc:84
bool condLastResult() const
get the latest result for the condition
const int gtIfMuEtaNumberBits() const
get / set the number of bits for eta of muon objects
Definition: MuCondition.h:85
unsigned long long etaRange
Definition: MuonTemplate.h:66
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:167
unsigned int m_corrParDeltaPhiNrBins
Definition: MuCondition.h:124
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void setGtIfMuEtaNumberBits(const int &)
Definition: MuCondition.cc:115
int hwEta() const
Definition: L1Candidate.cc:74
int hwQual() const
Definition: L1Candidate.cc:89
unsigned long long deltaPhiRange0Word
Definition: MuonTemplate.h:79
#define LogTrace(id)
void setGtGTL(const GtBoard *)
set the pointer to GTL
Definition: MuCondition.cc:107
Definition: Muon.h:12
int m_verbosity
verbosity level
int hwPt() const
Definition: L1Candidate.cc:69
void setGtCorrParDeltaPhiNrBins(const int &)
Definition: MuCondition.cc:123
void copy(const MuCondition &cp)
copy function for copy constructor and operator=
Definition: MuCondition.cc:64
void setGtMuonTemplate(const MuonTemplate *)
Definition: MuCondition.cc:100
string const
Definition: compareJSON.py:14
unsigned long long deltaPhiRange1Word
Definition: MuonTemplate.h:80
unsigned long long deltaEtaRange
Definition: MuonTemplate.h:77
int getLastBX() const
int factorial(int n)
factorial function
const l1t::Muon * getCandidate(const int bx, const int indexCand) const
load muon candidates
Definition: MuCondition.cc:416
const T & at(int bx, int i) const
MuCondition & operator=(const MuCondition &)
Definition: MuCondition.cc:93
const GtBoard * gtGTL() const
get / set the pointer to GTL
Definition: MuCondition.h:77
list at
Definition: asciidump.py:428