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