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("l1t|Global") << " 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 numberForFactorial = numberObjects - nObjInCond;
166 
167  // TEMPORARY FIX UNTIL IMPLEMENT NEW MUON CONDITIONS
168  int myfactorial = 1;
169  for( int i=numberForFactorial; i>0; i-- ) myfactorial *= i;
170 
171  int jumpIndex = 1;
172  int jump = myfactorial;//factorial(numberObjects - nObjInCond);
173 
174  int totalLoops = 0;
175  int passLoops = 0;
176 
177  // condition result condResult set to true if at least one permutation
178  // passes all requirements
179  // all possible permutations are checked
180  bool condResult = false;
181 
182  // store the indices of the muon objects
183  // from the combination evaluated in the condition
184  SingleCombInCond objectsInComb;
185  objectsInComb.reserve(nObjInCond);
186 
187  // clear the m_combinationsInCond vector
188  (combinationsInCond()).clear();
189 
190  do {
191 
192  if (--jumpIndex)
193  continue;
194 
195  jumpIndex = jump;
196  totalLoops++;
197 
198  // clear the indices in the combination
199  objectsInComb.clear();
200 
201  bool tmpResult = true;
202 
203  bool passCondition = false;
204  // check if there is a permutation that matches object-parameter requirements
205  for (int i = 0; i < nObjInCond; i++) {
206 
207  passCondition = checkObjectParameter(i, *(candVec->at(useBx,index[i]) )); //BLW Change for BXVector
208  tmpResult &= passCondition;
209  if( passCondition )
210  LogDebug("l1t|Global") << "===> MuCondition::evaluateCondition, CONGRATS!! This muon passed the condition." << std::endl;
211  else
212  LogDebug("l1t|Global") << "===> MuCondition::evaluateCondition, FAIL!! This muon failed the condition." << std::endl;
213  objectsInComb.push_back(index[i]);
214 
215  }
216 
217  // if permutation does not match particle conditions
218  // skip charge correlation and spatial correlations
219  if ( !tmpResult) {
220 
221  continue;
222 
223  }
224 
225  // get the correlation parameters (chargeCorrelation included here also)
227  *(m_gtMuonTemplate->correlationParameter());
228 
229  // charge_correlation consists of 3 relevant bits (D2, D1, D0)
230  unsigned int chargeCorr = corrPar.chargeCorrelation;
231 
232  // charge ignore bit (D0) not set?
233  if ((chargeCorr & 1) == 0) {
234 
235  for (int i = 0; i < nObjInCond; i++) {
236  // check valid charge - skip if invalid charge
237  int chargeValid = (candVec->at(useBx,index[i]))->hwChargeValid(); //BLW Change for BXVector
238  tmpResult &= chargeValid;
239 
240  if ( chargeValid==0) { //BLW type change for New Muon Class
241  continue;
242  }
243  }
244 
245  if ( !tmpResult) {
246  continue;
247  }
248 
249  if (nObjInCond == 1) { // one object condition
250 
251  // D2..enable pos, D1..enable neg
252  if ( ! ( ( (chargeCorr & 4) != 0 && (candVec->at(useBx,index[0]))->charge()> 0 ) //BLW Change for BXVector
253  || ( (chargeCorr & 2) != 0 && (candVec->at(useBx,index[0]))->charge() < 0 ) )) { //BLW Change for BXVector
254 
255  continue;
256  }
257 
258  }
259  else { // more objects condition
260 
261  // find out if signs are equal
262  bool equalSigns = true;
263  for (int i = 0; i < nObjInCond-1; i++) {
264  if ((candVec->at(useBx,index[i]))->charge() != (candVec->at(useBx,index[i+1]))->charge()) { //BLW Change for BXVector
265  equalSigns = false;
266  break;
267  }
268  }
269 
270  // two or three particle condition
271  if (nObjInCond == 2 || nObjInCond == 3) {
272  // D2..enable equal, D1..enable not equal
273  if ( ! ( ( (chargeCorr & 4) != 0 && equalSigns ) || ( (chargeCorr & 2) != 0
274  && !equalSigns ) )) {
275 
276  continue;
277  }
278  }
279 
280  // four particle condition
281  if (nObjInCond == 4) {
282  //counter to count positive charges to determine if there are pairs
283  unsigned int posCount = 0;
284 
285  for (int i = 0; i < nObjInCond; i++) {
286  if ((candVec->at(useBx,index[i]))->charge()> 0) { //BLW Change for BXVector
287  posCount++;
288  }
289  }
290 
291  // D2..enable equal, D1..enable pairs
292  if ( ! ( ( (chargeCorr & 4) != 0 && equalSigns ) || ( (chargeCorr & 2) != 0
293  && posCount == 2 ) )) {
294 
295  continue;
296  }
297  }
298  }
299  } // end signchecks
300 
301 
302  if (m_gtMuonTemplate->wsc()) {
303 
304  // wsc requirements have always nObjInCond = 2
305  // one can use directly index[0] and index[1] to compute
306  // eta and phi differences
307  const int ObjInWscComb = 2;
308  if (nObjInCond != ObjInWscComb) {
309 
310  edm::LogError("l1t|Global") << "\n Error: "
311  << "number of particles in condition with spatial correlation = " << nObjInCond
312  << "\n it must be = " << ObjInWscComb << std::endl;
313  // TODO Perhaps I should throw here an exception,
314  // since something is really wrong if nObjInCond != ObjInWscComb (=2)
315  continue;
316  }
317 
318  unsigned int candDeltaEta;
319  unsigned int candDeltaPhi;
320 
321  // check candDeltaEta
322 
323  // get eta index and the sign bit of the eta index (MSB is the sign)
324  // signedEta[i] is the signed eta index of (*candVec)[index[i]]
325  int signedEta[ObjInWscComb];
326  int signBit[ObjInWscComb] = { 0, 0 };
327 
328  int scaleEta = 1 << (m_ifMuEtaNumberBits - 1);
329 
330  for (int i = 0; i < ObjInWscComb; ++i) {
331  signBit[i] = ((candVec->at(useBx,index[i]))->hwEta() & scaleEta)>>(m_ifMuEtaNumberBits - 1); //BLW Change for BXVector
332  signedEta[i] = ((candVec->at(useBx,index[i]))->hwEta() )%scaleEta; //BLW Change for BXVector
333 
334  if (signBit[i] == 1) {
335  signedEta[i] = (-1)*signedEta[i];
336  }
337 
338  }
339 
340  // compute candDeltaEta - add 1 if signs are different (due to +0/-0 indices)
341  candDeltaEta = static_cast<int> (std::abs(signedEta[1] - signedEta[0]))
342  + static_cast<int> (signBit[1]^signBit[0]);
343 
344  if ( !checkBit(corrPar.deltaEtaRange, candDeltaEta) ) {
345  continue;
346  }
347 
348  // check candDeltaPhi
349 
350  // calculate absolute value of candDeltaPhi
351  if ((candVec->at(useBx,index[0]))->hwPhi()> (candVec->at(useBx,index[1]))->hwPhi()) { //BLW Change for BXVector
352  candDeltaPhi = (candVec->at(useBx,index[0]))->hwPhi() - (candVec->at(useBx,index[1]))->hwPhi(); //BLW Change for BXVector
353  }
354  else {
355  candDeltaPhi = (candVec->at(useBx,index[1]))->hwPhi() - (candVec->at(useBx,index[0]))->hwPhi(); //BLW Change for BXVector
356  }
357 
358  // check if candDeltaPhi > 180 (via delta_phi_maxbits)
359  // delta_phi contains bits for 0..180 (0 and 180 included)
360  // protect also against infinite loop...
361 
362  int nMaxLoop = 10;
363  int iLoop = 0;
364 
365  while (candDeltaPhi >= m_corrParDeltaPhiNrBins) {
366 
367  unsigned int candDeltaPhiInitial = candDeltaPhi;
368 
369  // candDeltaPhi > 180 ==> take 360 - candDeltaPhi
370  candDeltaPhi = (m_corrParDeltaPhiNrBins - 1) * 2 - candDeltaPhi;
371  if (m_verbosity) {
372  LogTrace("l1t|Global")
373  << " Initial candDeltaPhi = "
374  << candDeltaPhiInitial
375  << " > m_corrParDeltaPhiNrBins = "
376  << m_corrParDeltaPhiNrBins
377  << " ==> candDeltaPhi rescaled to: "
378  << candDeltaPhi << " [ loop index " << iLoop
379  << "; breaks after " << nMaxLoop << " loops ]\n"
380  << std::endl;
381  }
382 
383  iLoop++;
384  if (iLoop > nMaxLoop) {
385  return false;
386  }
387  }
388 
389  // delta_phi bitmask is saved in two boost::uint64_t words
390  if (candDeltaPhi < 64) {
391  if (!checkBit(corrPar.deltaPhiRange0Word, candDeltaPhi) ) {
392  continue;
393  }
394  }
395  else {
396  if (!checkBit(corrPar.deltaPhiRange1Word, (candDeltaPhi - 64))) {
397  continue;
398  }
399  }
400 
401  } // end wsc check
402 
403  // if we get here all checks were successfull for this combination
404  // set the general result for evaluateCondition to "true"
405 
406  condResult = true;
407  passLoops++;
408  (combinationsInCond()).push_back(objectsInComb);
409 
410  } while (std::next_permutation(index.begin(), index.end()) );
411 
412  //LogTrace("l1t|Global")
413  // << "\n MuCondition: total number of permutations found: " << totalLoops
414  // << "\n MuCondition: number of permutations passing requirements: " << passLoops
415  // << "\n" << std::endl;
416 
417  return condResult;
418 
419 }
420 
421 // load muon candidates
422 const l1t::Muon* l1t::MuCondition::getCandidate(const int bx, const int indexCand) const {
423 
424  return (m_gtGTL->getCandL1Mu())->at(bx,indexCand); //BLW Change for BXVector
425 }
426 
436 const bool l1t::MuCondition::checkObjectParameter(const int iCondition, const l1t::Muon& cand) const {
437 
438  // number of objects in condition
439  int nObjInCond = m_gtMuonTemplate->nrObjects();
440 
441  if (iCondition >= nObjInCond || iCondition < 0) {
442  return false;
443  }
444 
445 // // empty candidates can not be compared
446 // if (cand.empty()) {
447 // return false;
448 // }
449 
450  const MuonTemplate::ObjectParameter objPar =
451  ( *(m_gtMuonTemplate->objectParameter()) )[iCondition];
452 
453  // using the logic table from GTL-9U-module.pdf
454  // "Truth table for Isolation bit"
455 
456  // check thresholds:
457 
458  // value < low pt threshold
459  // fail trigger
460 
461  // low pt threshold <= value < high pt threshold & non-isolated muon:
462  // requestIso true: fail trigger
463  // requestIso false, enableIso true: fail trigger
464  // requestIso false, enableIso false: OK, trigger
465 
466  // low pt threshold <= value < high pt threshold & isolated muon:
467  // requestIso true: OK, trigger
468  // requestIso false, enableIso true: OK, trigger
469  // requestIso false, enableIso false: OK, trigger
470 
471  // value >= high pt threshold & non-isolated muon:
472  // requestIso true: fail trigger
473  // requestIso false: OK, trigger
474 
475  // value >= high pt threshold & isolated muon:
476  // OK, trigger
477 
478  LogDebug("l1t|Global")
479  << "\n MuonTemplate::ObjectParameter : "
480  << "\n\t ptHighThreshold = " << objPar.ptHighThreshold
481  << "\n\t ptLowThreshold = " << objPar.ptLowThreshold
482  << "\n\t requestIso = " << objPar.requestIso
483  << "\n\t enableIso = " << objPar.enableIso
484  << "\n\t etaRange = " << objPar.etaRange
485  << "\n\t phiLow = " << objPar.phiLow
486  << "\n\t phiHigh = " << objPar.phiHigh
487  << "\n\t qualityRange = " << objPar.qualityRange
488  << "\n\t enableMip = " << objPar.enableMip
489  << std::endl;
490 
491  LogDebug("l1t|Global")
492  << "\n l1t::Muon : "
493  << "\n\t hwPt = " << cand.hwPt()
494  << "\n\t hwEta = " << cand.hwEta()
495  << "\n\t hwPhi = " << cand.hwPhi()
496  << "\n\t hwQual = " << cand.hwQual()
497  << "\n\t hwIso = " << cand.hwIso()
498  << "\n\t hwMip = " << cand.hwMip()
499  << std::endl;
500 
501 
502  if ( !checkThreshold(objPar.ptHighThreshold, cand.hwPt(), m_gtMuonTemplate->condGEq()) ) {
503 
504  if ( !checkThreshold(objPar.ptLowThreshold, cand.hwPt(), m_gtMuonTemplate->condGEq()) ) {
505  LogDebug("l1t|Global") << "\t\t Muon Failed checkThreshold " << std::endl;
506  return false;
507  }
508  else {
509  // check isolation
510  if ( !cand.hwIso() ) {
511  if (objPar.requestIso || objPar.enableIso) {
512  LogDebug("l1t|Global") << "\t\t Muon Failed hwIso " << std::endl;
513  return false;
514  }
515  }
516  }
517  }
518  else {
519 
520  if ( !cand.hwIso() ) {
521  if (objPar.requestIso) {
522  LogDebug("l1t|Global") << "\t\t Muon Failed hwIso " << std::endl;
523  return false;
524  }
525  }
526  }
527 
528  // check eta
529  // DP - Enable once muon conditions mature
530 // if( !checkRange(cand.hwEta(), objPar.etaRangeBegin, objPar.etaRangeEnd, objPar.etaRangeVetoBegin, objPar.etaRangeVetoEnd) ){
531 // return false;
532 // }
533 
534 // // check phi
535 // if( !checkRange(cand.hwPhi(), objPar.phiRangeBegin, objPar.phiRangeEnd, objPar.phiRangeVetoBegin, objPar.phiRangeVetoEnd) ){
536 // return false;
537 // }
538 
540 // if (!checkBit(objPar.etaRange, cand.hwEta())) {
541 // LogDebug("l1t|Global") << "\t\t Muon Failed checkBit(etaRange) " << std::endl;
542 // return false;
543 // }
544 
545 // // check phi - in the requested range (no LUT used - LUT too big for hw chip)
546 // // for phiLow <= phiHigh takes [phiLow, phiHigh]
547 // // for phiLow >= phiHigh takes [phiLow, phiHigh] over zero angle!
548 // if (objPar.phiHigh >= objPar.phiLow) {
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 // else { // go over zero angle!!
555 // if (! ( (objPar.phiLow <= (unsigned int)cand.hwPhi()) || ((unsigned int)cand.hwPhi() <= objPar.phiHigh ) )) {
556 // LogDebug("l1t|Global") << "\t\t Muon Failed checkBit(phiRange) " << std::endl;
557 // return false;
558 // }
559 // }
560 
561  // check quality ( bit check )
562 
563  // A number of values is required to trigger (at least one).
564  // "Don’t care" means that all values are allowed.
565  // Qual = 000 means then NO MUON (GTL module)
566 
567  if (cand.hwQual() == 0) {
568  LogDebug("l1t|Global") << "\t\t Muon Failed hwQual() == 0" << std::endl;
569  return false;
570  }
571 
572  if (objPar.qualityRange == 0) {
573  LogDebug("l1t|Global") << "\t\t Muon Failed qualityRange == 0" << std::endl;
574  return false;
575  }
576  else {
577  if (!checkBit(objPar.qualityRange, cand.hwQual())) {
578  LogDebug("l1t|Global") << "\t\t Muon Failed checkBit(qualityRange) " << std::endl;
579  return false;
580  }
581  }
582 
583  // check mip
584  if (objPar.enableMip) {
585  if (!cand.hwMip()) {
586  LogDebug("l1t|Global") << "\t\t Muon Failed enableMip" << std::endl;
587  return false;
588  }
589  }
590 
591  // particle matches if we get here
592  //LogTrace("l1t|Global")
593  // << " checkObjectParameter: muon object OK, passes all requirements\n" << std::endl;
594 
595  return true;
596 }
597 
598 void l1t::MuCondition::print(std::ostream& myCout) const {
599 
600  m_gtMuonTemplate->print(myCout);
601 
602  myCout << " Number of bits for eta of muon objects = "
603  << m_ifMuEtaNumberBits << std::endl;
604  myCout << " Maximum number of bins for the delta phi scales = "
605  << m_corrParDeltaPhiNrBins << "\n " << std::endl;
606 
608 
609 }
610 
#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:598
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:436
virtual void print(std::ostream &myCout) const
print condition
std::vector< int > SingleCombInCond
typedefs
int hwPhi() const
Definition: L1Candidate.cc:79
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:89
#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:90
unsigned long long deltaEtaRange
Definition: MuonTemplate.h:93
int getLastBX() const
const l1t::Muon * getCandidate(const int bx, const int indexCand) const
load muon candidates
Definition: MuCondition.cc:422
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
const T & at(int bx, unsigned i) const