CMS 3D CMS Logo

MuCondition.cc
Go to the documentation of this file.
1 
16 // this class header
18 
19 // system include files
20 #include <iostream>
21 #include <iomanip>
22 
23 #include <string>
24 #include <vector>
25 #include <algorithm>
26 
27 // user include files
28 // base classes
31 
33 
35 
38 
39 // constructors
40 // default
43 
44  // empty
45 
46 }
47 
48 // from base template condition (from event setup usually)
50  const GlobalBoard* ptrGTL, const int nrL1Mu,
51  const int ifMuEtaNumberBits) :
53  m_gtMuonTemplate(static_cast<const MuonTemplate*>(muonTemplate)),
54  m_gtGTL(ptrGTL),
55  m_ifMuEtaNumberBits(ifMuEtaNumberBits)
56 {
58  m_condMaxNumberObjects = nrL1Mu;
59 }
60 
61 // copy constructor
63 
65  m_gtGTL = cp.gtGTL();
66 
69 
73 
75 
76 }
77 
80  copy(cp);
81 }
82 
83 // destructor
85 
86  // empty
87 
88 }
89 
90 // equal operator
92 {
93  copy(cp);
94  return *this;
95 }
96 
97 // methods
99 
100  m_gtMuonTemplate = muonTempl;
101 
102 }
103 
106 
107  m_gtGTL = ptrGTL;
108 
109 }
110 
111 
112 // set the number of bits for eta of muon objects
114  const int& ifMuEtaNumberBitsValue) {
115 
116  m_ifMuEtaNumberBits = ifMuEtaNumberBitsValue;
117 
118 }
119 
120 // set the maximum number of bins for the delta phi scales
122  const int& corrParDeltaPhiNrBins) {
123 
124  m_corrParDeltaPhiNrBins = corrParDeltaPhiNrBins;
125 
126 }
127 
128 
129 // try all object permutations and check spatial correlations, if required
130 const bool l1t::MuCondition::evaluateCondition(const int bxEval) const {
131 
132  // BLW Need to pass this as an argument
133  //const int bxEval=0; //BLW Change for BXVector
134 
135  // number of trigger objects in the condition
136  int nObjInCond = m_gtMuonTemplate->nrObjects();
137 
138  // the candidates
139  const BXVector<const l1t::Muon*>* candVec = m_gtGTL->getCandL1Mu(); //BLW Change for BXVector
140 
141  // Look at objects in bx = bx + relativeBx
142  int useBx = bxEval + m_gtMuonTemplate->condRelativeBx();
143 
144  // Fail condition if attempting to get Bx outside of range
145  if( ( useBx < candVec->getFirstBX() ) ||
146  ( useBx > candVec->getLastBX() ) ) {
147  return false;
148  }
149 
150  int numberObjects = candVec->size(useBx); //BLW Change for BXVector
151  //LogTrace("L1TGlobal") << " numberObjects: " << numberObjects
152  // << std::endl;
153  if (numberObjects < nObjInCond) {
154  return false;
155  }
156 
157  std::vector<int> index(numberObjects);
158 
159  for (int i = 0; i < numberObjects; ++i) {
160  index[i] = i;
161  }
162 
163  int numberForFactorial = numberObjects - nObjInCond;
164 
165  // TEMPORARY FIX UNTIL IMPLEMENT NEW MUON CONDITIONS
166  int myfactorial = 1;
167  for( int i=numberForFactorial; i>0; i-- ) myfactorial *= i;
168 
169  int jumpIndex = 1;
170  int jump = myfactorial;//factorial(numberObjects - nObjInCond);
171 
172  int totalLoops = 0;
173  int passLoops = 0;
174 
175  // condition result condResult set to true if at least one permutation
176  // passes all requirements
177  // all possible permutations are checked
178  bool condResult = false;
179 
180  // store the indices of the muon objects
181  // from the combination evaluated in the condition
182  SingleCombInCond objectsInComb;
183  objectsInComb.reserve(nObjInCond);
184 
185  // clear the m_combinationsInCond vector
186  combinationsInCond().clear();
187 
188  do {
189 
190  if (--jumpIndex)
191  continue;
192 
193  jumpIndex = jump;
194  totalLoops++;
195 
196  // clear the indices in the combination
197  objectsInComb.clear();
198 
199  bool tmpResult = true;
200 
201  bool passCondition = false;
202  // check if there is a permutation that matches object-parameter requirements
203  for (int i = 0; i < nObjInCond; i++) {
204 
205  passCondition = checkObjectParameter(i, *(candVec->at(useBx,index[i])), index[i] ); //BLW Change for BXVector
206  tmpResult &= passCondition;
207  if( passCondition )
208  LogDebug("L1TGlobal") << "===> MuCondition::evaluateCondition, CONGRATS!! This muon passed the condition." << std::endl;
209  else
210  LogDebug("L1TGlobal") << "===> MuCondition::evaluateCondition, FAIL!! This muon failed the condition." << std::endl;
211  objectsInComb.push_back(index[i]);
212 
213  }
214 
215 
216  // if permutation does not match particle conditions
217  // skip charge correlation and spatial correlations
218  if ( !tmpResult) {
219 
220  continue;
221 
222  }
223 
224  // get the correlation parameters (chargeCorrelation included here also)
227 
228  // charge_correlation consists of 3 relevant bits (D2, D1, D0)
229  unsigned int chargeCorr = corrPar.chargeCorrelation;
230 
231  // charge ignore bit (D0) not set?
232  if ((chargeCorr & 1) == 0) {
233 
234 
235  LogDebug("L1TGlobal") << "===> MuCondition:: Checking Charge Correlation" << std::endl;
236 
237  for (int i = 0; i < nObjInCond; i++) {
238  // check valid charge - skip if invalid charge
239  int chargeValid = (candVec->at(useBx,index[i]))->hwChargeValid(); //BLW Change for BXVector
240  tmpResult &= chargeValid;
241 
242  if ( chargeValid==0) { //BLW type change for New Muon Class
243  continue;
244  }
245  }
246 
247  if ( !tmpResult) {
248  LogDebug("L1TGlobal") << "===> MuCondition:: Charge Correlation Failed...No Valid Charges" << std::endl;
249  continue;
250  }
251 
252 
253  if( nObjInCond > 1 ){ // 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]))->hwCharge() != (candVec->at(useBx,index[i+1]))->hwCharge()) { //BLW Change for BXVector
259  equalSigns = false;
260  break;
261  }
262  }
263 
264 
265  LogDebug("L1TGlobal") << "===> MuCondition:: Checking Charge Correlation equalSigns = " << equalSigns << std::endl;
266 
267  // two or three particle condition
268  if (nObjInCond == 2 || nObjInCond == 3) {
269  if( !( ((chargeCorr & 2)!=0 && equalSigns) || ((chargeCorr & 4)!=0 && !equalSigns) ) ){
270  LogDebug("L1TGlobal") << "===> MuCondition:: 2/3 Muon Fail Charge Correlation Condition =" << chargeCorr << std::endl;
271  continue;
272  }
273  }
274  else if (nObjInCond == 4) {
275  //counter to count positive charges to determine if there are pairs
276  unsigned int posCount = 0;
277 
278  for (int i = 0; i < nObjInCond; i++) {
279  if ((candVec->at(useBx,index[i]))->hwCharge()> 0) { //BLW Change for BXVector
280  posCount++;
281  }
282  }
283 
284  if( !( ((chargeCorr & 2)!=0 && equalSigns) || ((chargeCorr & 4)!=0 && posCount==2) ) ){
285  LogDebug("L1TGlobal") << "===> MuCondition:: 4 Muon Fail Charge Correlation Condition = " << chargeCorr << " posCnt " << posCount << std::endl;
286  continue;
287  }
288  }
289  } // end require nObjInCond > 1
290  } // end signchecks
291 
292 
293  if (m_gtMuonTemplate->wsc()) {
294 
295  // wsc requirements have always nObjInCond = 2
296  // one can use directly index[0] and index[1] to compute
297  // eta and phi differences
298  const int ObjInWscComb = 2;
299  if (nObjInCond != ObjInWscComb) {
300 
301  edm::LogError("L1TGlobal") << "\n Error: "
302  << "number of particles in condition with spatial correlation = " << nObjInCond
303  << "\n it must be = " << ObjInWscComb << std::endl;
304  // TODO Perhaps I should throw here an exception,
305  // since something is really wrong if nObjInCond != ObjInWscComb (=2)
306  continue;
307  }
308 
309  // check delta eta
310  if( !checkRangeDeltaEta( (candVec->at(useBx,0))->hwEtaAtVtx(), (candVec->at(useBx,1))->hwEtaAtVtx(), corrPar.deltaEtaRangeLower, corrPar.deltaEtaRangeUpper, 8) ){
311  LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed checkRangeDeltaEta" << std::endl;
312  continue;
313  }
314 
315  // check delta phi
316  if( !checkRangeDeltaPhi( (candVec->at(useBx,0))->hwPhiAtVtx(), (candVec->at(useBx,1))->hwPhiAtVtx(),
317  corrPar.deltaPhiRangeLower, corrPar.deltaPhiRangeUpper) ){
318  LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed checkRangeDeltaPhi" << std::endl;
319  continue;
320  }
321 
322  } // end wsc check
323 
324  // if we get here all checks were successfull for this combination
325  // set the general result for evaluateCondition to "true"
326 
327  condResult = true;
328  passLoops++;
329  (combinationsInCond()).push_back(objectsInComb);
330 
331  } while (std::next_permutation(index.begin(), index.end()) );
332 
333  //LogTrace("L1TGlobal")
334  // << "\n MuCondition: total number of permutations found: " << totalLoops
335  // << "\n MuCondition: number of permutations passing requirements: " << passLoops
336  // << "\n" << std::endl;
337 
338  return condResult;
339 
340 }
341 
342 // load muon candidates
343 const l1t::Muon* l1t::MuCondition::getCandidate(const int bx, const int indexCand) const {
344 
345  return (m_gtGTL->getCandL1Mu())->at(bx,indexCand); //BLW Change for BXVector
346 }
347 
357 const bool l1t::MuCondition::checkObjectParameter(const int iCondition, const l1t::Muon& cand, const unsigned int index) const {
358 
359  // number of objects in condition
360  int nObjInCond = m_gtMuonTemplate->nrObjects();
361 
362  if (iCondition >= nObjInCond || iCondition < 0) {
363  return false;
364  }
365 
366 // // empty candidates can not be compared
367 // if (cand.empty()) {
368 // return false;
369 // }
370 
371  const MuonTemplate::ObjectParameter objPar =
372  ( *(m_gtMuonTemplate->objectParameter()) )[iCondition];
373 
374  // using the logic table from GTL-9U-module.pdf
375  // "Truth table for Isolation bit"
376 
377  // check thresholds:
378 
379  // value < low pt threshold
380  // fail trigger
381 
382  // low pt threshold <= value < high pt threshold & non-isolated muon:
383  // requestIso true: fail trigger
384  // requestIso false, enableIso true: fail trigger
385  // requestIso false, enableIso false: OK, trigger
386 
387  // low pt threshold <= value < high pt threshold & isolated muon:
388  // requestIso true: OK, trigger
389  // requestIso false, enableIso true: OK, trigger
390  // requestIso false, enableIso false: OK, trigger
391 
392  // value >= high pt threshold & non-isolated muon:
393  // requestIso true: fail trigger
394  // requestIso false: OK, trigger
395 
396  // value >= high pt threshold & isolated muon:
397  // OK, trigger
398 
399  LogDebug("L1TGlobal")
400  << "\n MuonTemplate::ObjectParameter : " << std::hex
401  << "\n\t ptHighThreshold = 0x " << objPar.ptHighThreshold
402  << "\n\t ptLowThreshold = 0x " << objPar.ptLowThreshold
403  << "\n\t indexHigh = 0x " << objPar.indexHigh
404  << "\n\t indexLow = 0x " << objPar.indexLow
405  << "\n\t requestIso = 0x " << objPar.requestIso
406  << "\n\t enableIso = 0x " << objPar.enableIso
407  << "\n\t etaRange = 0x " << objPar.etaRange
408  << "\n\t phiLow = 0x " << objPar.phiLow
409  << "\n\t phiHigh = 0x " << objPar.phiHigh
410  << "\n\t phiWindow1Lower = 0x " << objPar.phiWindow1Lower
411  << "\n\t phiWindow1Upper = 0x " << objPar.phiWindow1Upper
412  << "\n\t phiWindow2Lower = 0x " << objPar.phiWindow2Lower
413  << "\n\t phiWindow2Lower = 0x " << objPar.phiWindow2Lower
414  << "\n\t charge = 0x " << objPar.charge
415  << "\n\t qualityLUT = 0x " << objPar.qualityLUT
416  << "\n\t isolationLUT = 0x " << objPar.isolationLUT
417  << "\n\t enableMip = 0x " << objPar.enableMip
418  << std::endl;
419 
420  LogDebug("L1TGlobal")
421  << "\n l1t::Muon : "
422  << "\n\t hwPt = 0x " << cand.hwPt()
423  << "\n\t hwEtaAtVtx = 0x " << cand.hwEtaAtVtx()
424  << "\n\t hwPhiAtVtx = 0x " << cand.hwPhiAtVtx()
425  << "\n\t hwCharge = 0x " << cand.hwCharge()
426  << "\n\t hwQual = 0x " << cand.hwQual()
427  << "\n\t hwIso = 0x " << cand.hwIso() << std::dec
428  << std::endl;
429 
430 
431  if ( !checkThreshold(objPar.ptLowThreshold, objPar.ptHighThreshold, cand.hwPt(), m_gtMuonTemplate->condGEq()) ) {
432  LogDebug("L1TGlobal") << "\t\t Muon Failed checkThreshold " << std::endl;
433  return false;
434  }
435 
436  // check index
437  if ( !checkIndex(objPar.indexLow, objPar.indexHigh, index) ) {
438  LogDebug("L1TGlobal") << "\t\t Muon Failed checkIndex " << std::endl;
439  return false;
440  }
441 
442  // check eta
443  if( !checkRangeEta(cand.hwEtaAtVtx(), objPar.etaWindow1Lower, objPar.etaWindow1Upper, objPar.etaWindow2Lower, objPar.etaWindow2Upper, 8) ){
444  LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed checkRange(eta)" << std::endl;
445  return false;
446  }
447 
448  // check phi
449  if( !checkRangePhi(cand.hwPhiAtVtx(), objPar.phiWindow1Lower, objPar.phiWindow1Upper, objPar.phiWindow2Lower, objPar.phiWindow2Upper) ){
450  LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed checkRange(phi)" << std::endl;
451  return false;
452  }
453 
454  // check charge
455  if( objPar.charge>=0 ){
456  if( cand.hwCharge() != objPar.charge ){
457  LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed charge requirement" << std::endl;
458  return false;
459  }
460  }
461 
462 
463 
464  // check quality ( bit check ) with quality LUT
465  // sanity check on candidate quality
466  if( cand.hwQual()>16 ){
467  LogDebug("L1TGlobal") << "\t\t l1t::Candidate has out of range hwQual = " << cand.hwQual() << std::endl;
468  return false;
469  }
470  bool passQualLUT = ( (objPar.qualityLUT >> cand.hwQual()) & 1 );
471  if( !passQualLUT ){
472  LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed quality requirement" << std::endl;
473  return false;
474  }
475 
476 
477  // check isolation ( bit check ) with isolation LUT
478  // sanity check on candidate isolation
479  if( cand.hwIso()>4 ){
480  LogDebug("L1TGlobal") << "\t\t l1t::Candidate has out of range hwIso = " << cand.hwIso() << std::endl;
481  return false;
482  }
483  bool passIsoLUT = ( (objPar.isolationLUT >> cand.hwIso()) & 1 );
484  if( !passIsoLUT ){
485  LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed isolation requirement" << std::endl;
486  return false;
487  }
488 
489  // A number of values is required to trigger (at least one).
490  // "Don’t care" means that all values are allowed.
491  // Qual = 000 means then NO MUON (GTL module)
492 
493  // if (cand.hwQual() == 0) {
494  // LogDebug("L1TGlobal") << "\t\t Muon Failed hwQual() == 0" << std::endl;
495  // return false;
496  // }
497 
498  // if (objPar.qualityRange == 0) {
499  // LogDebug("L1TGlobal") << "\t\t Muon Failed qualityRange == 0" << std::endl;
500  // return false;
501  // }
502  // else {
503  // if (!checkBit(objPar.qualityRange, cand.hwQual())) {
504  // LogDebug("L1TGlobal") << "\t\t Muon Failed checkBit(qualityRange) " << std::endl;
505  // return false;
506  // }
507  // }
508 
509  // check mip
510  if (objPar.enableMip) {
511  // if (!cand.hwMip()) {
512  // LogDebug("L1TGlobal") << "\t\t Muon Failed enableMip" << std::endl;
513  // return false;
514  // }
515  }
516 
517  // particle matches if we get here
518  //LogTrace("L1TGlobal")
519  // << " checkObjectParameter: muon object OK, passes all requirements\n" << std::endl;
520 
521  return true;
522 }
523 
524 void l1t::MuCondition::print(std::ostream& myCout) const {
525 
526  m_gtMuonTemplate->print(myCout);
527 
528  myCout << " Number of bits for eta of muon objects = "
529  << m_ifMuEtaNumberBits << std::endl;
530  myCout << " Maximum number of bins for the delta phi scales = "
531  << m_corrParDeltaPhiNrBins << "\n " << std::endl;
532 
534 
535 }
536 
#define LogDebug(id)
const int nrObjects() const
get number of trigger objects
void setGtGTL(const GlobalBoard *)
set the pointer to GTL
Definition: MuCondition.cc:105
int hwPhiAtVtx() const
Definition: Muon.h:93
const bool evaluateCondition(const int bxEval) const override
the core function to check if the condition matches
Definition: MuCondition.cc:130
unsigned size(int bx) const
CombinationsInCond const & getCombinationsInCond() const
get all the object combinations evaluated to true in the condition
~MuCondition() override
Definition: MuCondition.cc:84
const bool checkRangeDeltaPhi(const unsigned int obj1Phi, const unsigned int obj2Phi, const Type1 &lowerR, const Type1 &upperR) const
check if a value is in a given range
void print(std::ostream &myCout) const override
print condition
Definition: MuCondition.cc:524
const MuonTemplate * gtMuonTemplate() const
get / set the pointer to a Condition
Definition: MuCondition.h:71
const bool checkRangeEta(const unsigned int bitNumber, const Type1 &W1beginR, const Type1 &W1endR, const Type1 &W2beginR, const Type1 &W2endR, const unsigned int nEtaBits) const
check if a value is in a given range and outside of a veto range
virtual void print(std::ostream &myCout) const
print condition
std::vector< int > SingleCombInCond
typedefs
const bool wsc() const
const bool condGEq() const
get / set condition GEq flag
const GlobalBoard * gtGTL() const
get / set the pointer to GTL
Definition: MuCondition.h:78
const GlobalBoard * m_gtGTL
pointer to GTL, to be able to get the trigger objects
Definition: MuCondition.h:119
const bool checkThreshold(const Type1 &thresholdL, const Type1 &thresholdH, const Type2 &value, bool condGEqValue) const
int hwIso() const
Definition: L1Candidate.h:52
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:86
const int & condRelativeBx() const
get / set the condition relative bx
int m_ifMuEtaNumberBits
number of bits for eta of muon objects
Definition: MuCondition.h:122
const std::vector< ObjectParameter > * objectParameter() const
Definition: MuonTemplate.h:114
unsigned long long etaRange
Definition: MuonTemplate.h:70
unsigned int m_corrParDeltaPhiNrBins
Definition: MuCondition.h:125
const MuonTemplate * m_gtMuonTemplate
pointer to a MuonTemplate
Definition: MuCondition.h:116
void setGtIfMuEtaNumberBits(const int &)
Definition: MuCondition.cc:113
CombinationsInCond m_combinationsInCond
store all the object combinations evaluated to true in the condition
int hwQual() const
Definition: L1Candidate.h:51
Definition: Muon.h:21
const BXVector< const l1t::Muon * > * getCandL1Mu() const
return global muon trigger candidate
Definition: GlobalBoard.h:143
void print(std::ostream &myCout) const override
print the condition
Definition: MuonTemplate.cc:98
int m_verbosity
verbosity level
int hwPt() const
Definition: L1Candidate.h:48
void setGtCorrParDeltaPhiNrBins(const int &)
Definition: MuCondition.cc:121
void copy(const MuCondition &cp)
copy function for copy constructor and operator=
Definition: MuCondition.cc:62
bool m_condLastResult
the last result of evaluateCondition()
int hwEtaAtVtx() const
Definition: Muon.h:92
void setGtMuonTemplate(const MuonTemplate *)
Definition: MuCondition.cc:98
const bool checkObjectParameter(const int iCondition, const l1t::Muon &cand, const unsigned int index) const
function to check a single object if it matches a condition
Definition: MuCondition.cc:357
int getLastBX() const
const CorrelationParameter * correlationParameter() const
Definition: MuonTemplate.h:119
const bool checkRangeDeltaEta(const unsigned int obj1Eta, const unsigned int obj2Eta, const Type1 &lowerR, const Type1 &upperR, const unsigned int nEtaBits) const
check if a value is in a given range
const l1t::Muon * getCandidate(const int bx, const int indexCand) const
load muon candidates
Definition: MuCondition.cc:343
const bool checkIndex(const Type1 &indexLo, const Type1 &indexHi, const unsigned int index) const
check if a index is in a given range
CombinationsInCond & combinationsInCond() const
get all the object combinations (to fill it...)
const bool checkRangePhi(const unsigned int bitNumber, const Type1 &W1beginR, const Type1 &W1endR, const Type1 &W2beginR, const Type1 &W2endR) const
check if a value is in a given range and outside of a veto range
MuCondition & operator=(const MuCondition &)
Definition: MuCondition.cc:91
int hwCharge() const
Definition: Muon.h:87
const T & at(int bx, unsigned i) const