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 
218  // if permutation does not match particle conditions
219  // skip charge correlation and spatial correlations
220  if ( !tmpResult) {
221 
222  continue;
223 
224  }
225 
226  // get the correlation parameters (chargeCorrelation included here also)
228  *(m_gtMuonTemplate->correlationParameter());
229 
230  // charge_correlation consists of 3 relevant bits (D2, D1, D0)
231  unsigned int chargeCorr = corrPar.chargeCorrelation;
232 
233  // charge ignore bit (D0) not set?
234  if ((chargeCorr & 1) == 0) {
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  continue;
248  }
249 
250 
251  if( nObjInCond > 1 ){ // more objects condition
252 
253  // find out if signs are equal
254  bool equalSigns = true;
255  for (int i = 0; i < nObjInCond-1; i++) {
256  if ((candVec->at(useBx,index[i]))->charge() != (candVec->at(useBx,index[i+1]))->charge()) { //BLW Change for BXVector
257  equalSigns = false;
258  break;
259  }
260  }
261 
262  // two or three particle condition
263  if (nObjInCond == 2 || nObjInCond == 3) {
264  if( !( ((chargeCorr & 2)!=0 && equalSigns) || ((chargeCorr & 4)!=0 && !equalSigns) ) ){
265  continue;
266  }
267  }
268  else if (nObjInCond == 4) {
269  //counter to count positive charges to determine if there are pairs
270  unsigned int posCount = 0;
271 
272  for (int i = 0; i < nObjInCond; i++) {
273  if ((candVec->at(useBx,index[i]))->charge()> 0) { //BLW Change for BXVector
274  posCount++;
275  }
276  }
277 
278  if( !( ((chargeCorr & 2)!=0 && equalSigns) || ((chargeCorr & 4)!=0 && posCount==2) ) ){
279  continue;
280  }
281  }
282  } // end require nObjInCond > 1
283  } // end signchecks
284 
285 
286  if (m_gtMuonTemplate->wsc()) {
287 
288  // wsc requirements have always nObjInCond = 2
289  // one can use directly index[0] and index[1] to compute
290  // eta and phi differences
291  const int ObjInWscComb = 2;
292  if (nObjInCond != ObjInWscComb) {
293 
294  edm::LogError("l1t|Global") << "\n Error: "
295  << "number of particles in condition with spatial correlation = " << nObjInCond
296  << "\n it must be = " << ObjInWscComb << std::endl;
297  // TODO Perhaps I should throw here an exception,
298  // since something is really wrong if nObjInCond != ObjInWscComb (=2)
299  continue;
300  }
301 
302  // check delta eta
303  if( !checkRangeDeltaEta( (candVec->at(useBx,0))->hwEta(), (candVec->at(useBx,1))->hwEta(), corrPar.deltaEtaRangeLower, corrPar.deltaEtaRangeUpper, 8) ){
304  LogDebug("l1t|Global") << "\t\t l1t::Candidate failed checkRangeDeltaEta" << std::endl;
305  continue;
306  }
307 
308  // check delta phi
309  if( !checkRangeDeltaPhi( (candVec->at(useBx,0))->hwPhi(), (candVec->at(useBx,1))->hwPhi(),
310  corrPar.deltaPhiRangeLower, corrPar.deltaPhiRangeUpper) ){
311  LogDebug("l1t|Global") << "\t\t l1t::Candidate failed checkRangeDeltaPhi" << std::endl;
312  continue;
313  }
314 
315  } // end wsc check
316 
317  // if we get here all checks were successfull for this combination
318  // set the general result for evaluateCondition to "true"
319 
320  condResult = true;
321  passLoops++;
322  (combinationsInCond()).push_back(objectsInComb);
323 
324  } while (std::next_permutation(index.begin(), index.end()) );
325 
326  //LogTrace("l1t|Global")
327  // << "\n MuCondition: total number of permutations found: " << totalLoops
328  // << "\n MuCondition: number of permutations passing requirements: " << passLoops
329  // << "\n" << std::endl;
330 
331  return condResult;
332 
333 }
334 
335 // load muon candidates
336 const l1t::Muon* l1t::MuCondition::getCandidate(const int bx, const int indexCand) const {
337 
338  return (m_gtGTL->getCandL1Mu())->at(bx,indexCand); //BLW Change for BXVector
339 }
340 
350 const bool l1t::MuCondition::checkObjectParameter(const int iCondition, const l1t::Muon& cand) const {
351 
352  // number of objects in condition
353  int nObjInCond = m_gtMuonTemplate->nrObjects();
354 
355  if (iCondition >= nObjInCond || iCondition < 0) {
356  return false;
357  }
358 
359 // // empty candidates can not be compared
360 // if (cand.empty()) {
361 // return false;
362 // }
363 
364  const MuonTemplate::ObjectParameter objPar =
365  ( *(m_gtMuonTemplate->objectParameter()) )[iCondition];
366 
367  // using the logic table from GTL-9U-module.pdf
368  // "Truth table for Isolation bit"
369 
370  // check thresholds:
371 
372  // value < low pt threshold
373  // fail trigger
374 
375  // low pt threshold <= value < high pt threshold & non-isolated muon:
376  // requestIso true: fail trigger
377  // requestIso false, enableIso true: fail trigger
378  // requestIso false, enableIso false: OK, trigger
379 
380  // low pt threshold <= value < high pt threshold & isolated muon:
381  // requestIso true: OK, trigger
382  // requestIso false, enableIso true: OK, trigger
383  // requestIso false, enableIso false: OK, trigger
384 
385  // value >= high pt threshold & non-isolated muon:
386  // requestIso true: fail trigger
387  // requestIso false: OK, trigger
388 
389  // value >= high pt threshold & isolated muon:
390  // OK, trigger
391 
392  LogDebug("l1t|Global")
393  << "\n MuonTemplate::ObjectParameter : "
394  << "\n\t ptHighThreshold = " << objPar.ptHighThreshold
395  << "\n\t ptLowThreshold = " << objPar.ptLowThreshold
396  << "\n\t requestIso = " << objPar.requestIso
397  << "\n\t enableIso = " << objPar.enableIso
398  << "\n\t etaRange = " << objPar.etaRange
399  << "\n\t phiLow = " << objPar.phiLow
400  << "\n\t phiHigh = " << objPar.phiHigh
401  << "\n\t phiWindowLower = " << objPar.phiWindowLower
402  << "\n\t phiWindowUpper = " << objPar.phiWindowUpper
403  << "\n\t phiWindowVetoLower = " << objPar.phiWindowVetoLower
404  << "\n\t phiWindowVetoLower = " << objPar.phiWindowVetoLower
405  << "\n\t charge = " << objPar.charge
406  << "\n\t qualityLUT = " << objPar.qualityLUT
407  << "\n\t isolationLUT = " << objPar.isolationLUT
408  << "\n\t enableMip = " << objPar.enableMip
409  << std::endl;
410 
411  LogDebug("l1t|Global")
412  << "\n l1t::Muon : "
413  << "\n\t hwPt = " << cand.hwPt()
414  << "\n\t hwEta = " << cand.hwEta()
415  << "\n\t hwPhi = " << cand.hwPhi()
416  << "\n\t hwCharge = " << cand.hwCharge()
417  << "\n\t hwQual = " << cand.hwQual()
418  << "\n\t hwIso = " << cand.hwIso()
419  << std::endl;
420 
421 
422  if ( !checkThreshold(objPar.ptHighThreshold, cand.hwPt(), m_gtMuonTemplate->condGEq()) ) {
423  if ( !checkThreshold(objPar.ptLowThreshold, cand.hwPt(), m_gtMuonTemplate->condGEq()) ) {
424  LogDebug("l1t|Global") << "\t\t Muon Failed checkThreshold " << std::endl;
425  return false;
426  }
427  }
428 
429 
430  // check eta
431  if( !checkRangeEta(cand.hwEta(), objPar.etaWindowLower, objPar.etaWindowUpper, objPar.etaWindowVetoLower, objPar.etaWindowVetoLower, 8) ){
432  LogDebug("l1t|Global") << "\t\t l1t::Candidate failed checkRange(eta)" << std::endl;
433  return false;
434  }
435 
436  // check phi
437  if( !checkRangePhi(cand.hwPhi(), objPar.phiWindowLower, objPar.phiWindowUpper, objPar.phiWindowVetoLower, objPar.phiWindowVetoLower) ){
438  LogDebug("l1t|Global") << "\t\t l1t::Candidate failed checkRange(phi)" << std::endl;
439  return false;
440  }
441 
442  // check charge
443  if( objPar.charge>=0 ){
444  if( cand.hwCharge() != objPar.charge ){
445  LogDebug("l1t|Global") << "\t\t l1t::Candidate failed charge requirement" << std::endl;
446  return false;
447  }
448  }
449 
450 
451 
452  // check quality ( bit check ) with quality LUT
453  // sanity check on candidate quality
454  if( cand.hwQual()>16 ){
455  LogDebug("l1t|Global") << "\t\t l1t::Candidate has out of range hwQual = " << cand.hwQual() << std::endl;
456  return false;
457  }
458  bool passQualLUT = ( (objPar.qualityLUT >> cand.hwQual()) & 1 );
459  if( !passQualLUT ){
460  LogDebug("l1t|Global") << "\t\t l1t::Candidate failed quality requirement" << std::endl;
461  return false;
462  }
463 
464 
465  // check isolation ( bit check ) with isolation LUT
466  // sanity check on candidate isolation
467  if( cand.hwIso()>4 ){
468  LogDebug("l1t|Global") << "\t\t l1t::Candidate has out of range hwIso = " << cand.hwIso() << std::endl;
469  return false;
470  }
471  bool passIsoLUT = ( (objPar.isolationLUT >> cand.hwIso()) & 1 );
472  if( !passIsoLUT ){
473  LogDebug("l1t|Global") << "\t\t l1t::Candidate failed isolation requirement" << std::endl;
474  return false;
475  }
476 
477  // A number of values is required to trigger (at least one).
478  // "Don’t care" means that all values are allowed.
479  // Qual = 000 means then NO MUON (GTL module)
480 
481  // if (cand.hwQual() == 0) {
482  // LogDebug("l1t|Global") << "\t\t Muon Failed hwQual() == 0" << std::endl;
483  // return false;
484  // }
485 
486  // if (objPar.qualityRange == 0) {
487  // LogDebug("l1t|Global") << "\t\t Muon Failed qualityRange == 0" << std::endl;
488  // return false;
489  // }
490  // else {
491  // if (!checkBit(objPar.qualityRange, cand.hwQual())) {
492  // LogDebug("l1t|Global") << "\t\t Muon Failed checkBit(qualityRange) " << std::endl;
493  // return false;
494  // }
495  // }
496 
497  // check mip
498  if (objPar.enableMip) {
499  // if (!cand.hwMip()) {
500  // LogDebug("l1t|Global") << "\t\t Muon Failed enableMip" << std::endl;
501  // return false;
502  // }
503  }
504 
505  // particle matches if we get here
506  //LogTrace("l1t|Global")
507  // << " checkObjectParameter: muon object OK, passes all requirements\n" << std::endl;
508 
509  return true;
510 }
511 
512 void l1t::MuCondition::print(std::ostream& myCout) const {
513 
514  m_gtMuonTemplate->print(myCout);
515 
516  myCout << " Number of bits for eta of muon objects = "
517  << m_ifMuEtaNumberBits << std::endl;
518  myCout << " Maximum number of bins for the delta phi scales = "
519  << m_corrParDeltaPhiNrBins << "\n " << std::endl;
520 
522 
523 }
524 
#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:512
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:350
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 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:115
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: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
int getLastBX() const
const l1t::Muon * getCandidate(const int bx, const int indexCand) const
load muon candidates
Definition: MuCondition.cc:336
MuCondition & operator=(const MuCondition &)
Definition: MuCondition.cc:93
const GtBoard * gtGTL() const
get / set the pointer to GTL
Definition: MuCondition.h:77
int hwCharge() const
Definition: Muon.cc:106
const T & at(int bx, unsigned i) const