CMS 3D CMS Logo

CaloCondition.cc
Go to the documentation of this file.
1 
14 // this class header
16 
17 // system include files
18 #include <iostream>
19 #include <iomanip>
20 
21 #include <string>
22 #include <vector>
23 #include <algorithm>
24 
25 // user include files
26 // base classes
29 
31 
33 
36 
37 // constructors
38 // default
42 }
43 
44 // from base template condition (from event setup usually)
46  const GlobalBoard* ptrGTB,
47  const int nrL1EG,
48  const int nrL1Jet,
49  const int nrL1Tau,
50  const int ifCaloEtaNumberBits)
52  m_gtCaloTemplate(static_cast<const CaloTemplate*>(caloTemplate)),
53  m_uGtB(ptrGTB),
54  m_ifCaloEtaNumberBits(ifCaloEtaNumberBits) {
56 
57  // maximum number of objects received for the evaluation of the condition
58  // retrieved before from event setup
59  // for a CondCalo, all objects ar of same type, hence it is enough to get the
60  // type for the first object
61 
62  switch ((m_gtCaloTemplate->objectType())[0]) {
63  case gtEG:
64  m_condMaxNumberObjects = nrL1EG;
65  break;
66 
67  case gtJet:
68  m_condMaxNumberObjects = nrL1Jet;
69  break;
70 
71  case gtTau:
72  m_condMaxNumberObjects = nrL1Tau;
73  break;
74  default:
76  break;
77  }
78 }
79 
80 // copy constructor
82  m_gtCaloTemplate = cp.gtCaloTemplate();
83  m_uGtB = cp.getuGtB();
84 
85  m_ifCaloEtaNumberBits = cp.gtIfCaloEtaNumberBits();
86  m_corrParDeltaPhiNrBins = cp.m_corrParDeltaPhiNrBins;
87 
88  m_condMaxNumberObjects = cp.condMaxNumberObjects();
89  m_condLastResult = cp.condLastResult();
90  m_combinationsInCond = cp.getCombinationsInCond();
91 
92  m_verbosity = cp.m_verbosity;
93 }
94 
96 
97 // destructor
99  // empty
100 }
101 
102 // equal operator
104  copy(cp);
105  return *this;
106 }
107 
108 // methods
109 void l1t::CaloCondition::setGtCaloTemplate(const CaloTemplate* caloTempl) { m_gtCaloTemplate = caloTempl; }
110 
112 void l1t::CaloCondition::setuGtB(const GlobalBoard* ptrGTB) { m_uGtB = ptrGTB; }
113 
114 // set the number of bits for eta of calorimeter objects
115 void l1t::CaloCondition::setGtIfCaloEtaNumberBits(const int& ifCaloEtaNumberBitsValue) {
116  m_ifCaloEtaNumberBits = ifCaloEtaNumberBitsValue;
117 }
118 
119 // set the maximum number of bins for the delta phi scales
120 void l1t::CaloCondition::setGtCorrParDeltaPhiNrBins(const int& corrParDeltaPhiNrBins) {
121  m_corrParDeltaPhiNrBins = corrParDeltaPhiNrBins;
122 }
123 
124 // try all object permutations and check spatial correlations, if required
125 const bool l1t::CaloCondition::evaluateCondition(const int bxEval) const {
126  // number of trigger objects in the condition
127  int nObjInCond = m_gtCaloTemplate->nrObjects();
128  //LogTrace("L1TGlobal") << " nObjInCond: " << nObjInCond
129  // << std::endl;
130 
131  // the candidates
132 
133  // objectType() gives the type for nrObjects() only,
134  // but in a CondCalo all objects have the same type
135  // take type from the type of the first object
136 
137  const BXVector<const l1t::L1Candidate*>* candVec;
138 
139  switch ((m_gtCaloTemplate->objectType())[0]) {
140  case gtEG:
141  candVec = m_uGtB->getCandL1EG();
142  break;
143 
144  case gtJet:
145  candVec = m_uGtB->getCandL1Jet();
146  break;
147 
148  case gtTau:
149  candVec = m_uGtB->getCandL1Tau();
150  break;
151 
152  default:
153  return false;
154  break;
155  }
156 
157  // Look at objects in bx = bx + relativeBx
158  int useBx = bxEval + m_gtCaloTemplate->condRelativeBx();
159 
160  // Fail condition if attempting to get Bx outside of range
161  if ((useBx < candVec->getFirstBX()) || (useBx > candVec->getLastBX())) {
162  return false;
163  }
164 
165  int numberObjects = candVec->size(useBx);
166  //LogTrace("L1TGlobal") << " numberObjects: " << numberObjects
167  // << std::endl;
168  if (numberObjects < nObjInCond) {
169  return false;
170  }
171 
172  std::vector<int> index(numberObjects);
173 
174  for (int i = 0; i < numberObjects; ++i) {
175  index[i] = i;
176  }
177 
178  int totalLoops = 0;
179  int passLoops = 0;
180 
181  // condition result condResult set to true if at least one permutation
182  // passes all requirements
183  // all possible permutations are checked
184  bool condResult = false;
185 
186  // store the indices of the calorimeter objects
187  // from the combination evaluated in the condition
188  SingleCombInCond objectsInComb;
189  objectsInComb.reserve(nObjInCond);
190 
191  // clear the m_combinationsInCond vector
192  combinationsInCond().clear();
193 
195  if (nObjInCond == 1) {
196  // clear the indices in the combination
197  //objectsInComb.clear();
198 
199  for (int i = 0; i < numberObjects; i++) {
200  // clear the indices in the combination
201  objectsInComb.clear();
202 
203  totalLoops++;
204  bool passCondition = checkObjectParameter(0, *(candVec->at(useBx, i)), index[i]);
205  if (passCondition) {
206  objectsInComb.push_back(i);
207  condResult = true;
208  passLoops++;
209  combinationsInCond().push_back(objectsInComb);
210  }
211  }
212  } else if (nObjInCond == 2) {
213  for (int i = 0; i < numberObjects; i++) {
214  bool passCondition0i = checkObjectParameter(0, *(candVec->at(useBx, i)), index[i]);
215  bool passCondition1i = checkObjectParameter(1, *(candVec->at(useBx, i)), index[i]);
216 
217  if (!(passCondition0i || passCondition1i))
218  continue;
219 
220  for (int j = 0; j < numberObjects; j++) {
221  if (i == j)
222  continue;
223  totalLoops++;
224 
225  bool passCondition0j = checkObjectParameter(0, *(candVec->at(useBx, j)), index[i]);
226  bool passCondition1j = checkObjectParameter(1, *(candVec->at(useBx, j)), index[i]);
227 
228  bool pass = ((passCondition0i && passCondition1j) || (passCondition0j && passCondition1i));
229 
230  if (pass) {
231  if (m_gtCaloTemplate->wsc()) {
232  // wsc requirements have always nObjInCond = 2
233  // one can use directly 0] and 1] to compute
234  // eta and phi differences
235  const int ObjInWscComb = 2;
236  if (nObjInCond != ObjInWscComb) {
237  if (m_verbosity) {
238  edm::LogError("L1TGlobal")
239  << "\n Error: "
240  << "number of particles in condition with spatial correlation = " << nObjInCond
241  << "\n it must be = " << ObjInWscComb << std::endl;
242  }
243 
244  continue;
245  }
246 
247  CaloTemplate::CorrelationParameter corrPar = *(m_gtCaloTemplate->correlationParameter());
248 
249  // check delta eta
250  if (!checkRangeDeltaEta((candVec->at(useBx, i))->hwEta(),
251  (candVec->at(useBx, j))->hwEta(),
252  corrPar.deltaEtaRangeLower,
253  corrPar.deltaEtaRangeUpper,
254  7)) {
255  LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed checkRangeDeltaEta" << std::endl;
256  continue;
257  }
258 
259  // check delta phi
260  if (!checkRangeDeltaPhi((candVec->at(useBx, i))->hwPhi(),
261  (candVec->at(useBx, j))->hwPhi(),
262  corrPar.deltaPhiRangeLower,
263  corrPar.deltaPhiRangeUpper)) {
264  LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed checkRangeDeltaPhi" << std::endl;
265  continue;
266  }
267 
268  } // end wsc check
269 
270  objectsInComb.clear();
271  objectsInComb.push_back(i);
272  objectsInComb.push_back(j);
273  condResult = true;
274  passLoops++;
275  combinationsInCond().push_back(objectsInComb);
276  }
277  }
278  }
279  } else if (nObjInCond == 3) {
280  for (int i = 0; i < numberObjects; i++) {
281  bool passCondition0i = checkObjectParameter(0, *(candVec->at(useBx, i)), index[i]);
282  bool passCondition1i = checkObjectParameter(1, *(candVec->at(useBx, i)), index[i]);
283  bool passCondition2i = checkObjectParameter(2, *(candVec->at(useBx, i)), index[i]);
284 
285  if (!(passCondition0i || passCondition1i || passCondition2i))
286  continue;
287 
288  for (int j = 0; j < numberObjects; j++) {
289  if (i == j)
290  continue;
291 
292  bool passCondition0j = checkObjectParameter(0, *(candVec->at(useBx, j)), index[i]);
293  bool passCondition1j = checkObjectParameter(1, *(candVec->at(useBx, j)), index[i]);
294  bool passCondition2j = checkObjectParameter(2, *(candVec->at(useBx, j)), index[i]);
295 
296  if (!(passCondition0j || passCondition1j || passCondition2j))
297  continue;
298 
299  for (int k = 0; k < numberObjects; k++) {
300  if (k == i || k == j)
301  continue;
302  totalLoops++;
303 
304  bool passCondition0k = checkObjectParameter(0, *(candVec->at(useBx, k)), index[i]);
305  bool passCondition1k = checkObjectParameter(1, *(candVec->at(useBx, k)), index[i]);
306  bool passCondition2k = checkObjectParameter(2, *(candVec->at(useBx, k)), index[i]);
307 
308  bool pass = ((passCondition0i && passCondition1j && passCondition2k) ||
309  (passCondition0i && passCondition1k && passCondition2j) ||
310  (passCondition0j && passCondition1k && passCondition2i) ||
311  (passCondition0j && passCondition1i && passCondition2k) ||
312  (passCondition0k && passCondition1i && passCondition2j) ||
313  (passCondition0k && passCondition1j && passCondition2i));
314  if (pass) {
315  condResult = true;
316  passLoops++;
317  objectsInComb.clear();
318  objectsInComb.push_back(i);
319  objectsInComb.push_back(j);
320  objectsInComb.push_back(k);
321  combinationsInCond().push_back(objectsInComb);
322  }
323  } // end loop on k
324  } // end loop on j
325  } // end loop on i
326  } // end if condition has 3 objects
327  else if (nObjInCond == 4) {
328  for (int i = 0; i < numberObjects; i++) {
329  bool passCondition0i = checkObjectParameter(0, *(candVec->at(useBx, i)), index[i]);
330  bool passCondition1i = checkObjectParameter(1, *(candVec->at(useBx, i)), index[i]);
331  bool passCondition2i = checkObjectParameter(2, *(candVec->at(useBx, i)), index[i]);
332  bool passCondition3i = checkObjectParameter(3, *(candVec->at(useBx, i)), index[i]);
333 
334  if (!(passCondition0i || passCondition1i || passCondition2i || passCondition3i))
335  continue;
336 
337  for (int j = 0; j < numberObjects; j++) {
338  if (j == i)
339  continue;
340 
341  bool passCondition0j = checkObjectParameter(0, *(candVec->at(useBx, j)), index[i]);
342  bool passCondition1j = checkObjectParameter(1, *(candVec->at(useBx, j)), index[i]);
343  bool passCondition2j = checkObjectParameter(2, *(candVec->at(useBx, j)), index[i]);
344  bool passCondition3j = checkObjectParameter(3, *(candVec->at(useBx, j)), index[i]);
345 
346  if (!(passCondition0j || passCondition1j || passCondition2j || passCondition3j))
347  continue;
348 
349  for (int k = 0; k < numberObjects; k++) {
350  if (k == i || k == j)
351  continue;
352 
353  bool passCondition0k = checkObjectParameter(0, *(candVec->at(useBx, k)), index[i]);
354  bool passCondition1k = checkObjectParameter(1, *(candVec->at(useBx, k)), index[i]);
355  bool passCondition2k = checkObjectParameter(2, *(candVec->at(useBx, k)), index[i]);
356  bool passCondition3k = checkObjectParameter(3, *(candVec->at(useBx, k)), index[i]);
357 
358  if (!(passCondition0k || passCondition1k || passCondition2k || passCondition3k))
359  continue;
360 
361  for (int m = 0; m < numberObjects; m++) {
362  if (m == i || m == j || m == k)
363  continue;
364  totalLoops++;
365 
366  bool passCondition0m = checkObjectParameter(0, *(candVec->at(useBx, m)), index[i]);
367  bool passCondition1m = checkObjectParameter(1, *(candVec->at(useBx, m)), index[i]);
368  bool passCondition2m = checkObjectParameter(2, *(candVec->at(useBx, m)), index[i]);
369  bool passCondition3m = checkObjectParameter(3, *(candVec->at(useBx, m)), index[i]);
370 
371  bool pass = ((passCondition0i && passCondition1j && passCondition2k && passCondition3m) ||
372  (passCondition0i && passCondition1j && passCondition2m && passCondition3k) ||
373  (passCondition0i && passCondition1k && passCondition2j && passCondition3m) ||
374  (passCondition0i && passCondition1k && passCondition2m && passCondition3j) ||
375  (passCondition0i && passCondition1m && passCondition2j && passCondition3k) ||
376  (passCondition0i && passCondition1m && passCondition2k && passCondition3j) ||
377  (passCondition0j && passCondition1i && passCondition2k && passCondition3m) ||
378  (passCondition0j && passCondition1i && passCondition2m && passCondition3k) ||
379  (passCondition0j && passCondition1k && passCondition2i && passCondition3m) ||
380  (passCondition0j && passCondition1k && passCondition2m && passCondition3i) ||
381  (passCondition0j && passCondition1m && passCondition2i && passCondition3k) ||
382  (passCondition0j && passCondition1m && passCondition2k && passCondition3i) ||
383  (passCondition0k && passCondition1i && passCondition2j && passCondition3m) ||
384  (passCondition0k && passCondition1i && passCondition2m && passCondition3j) ||
385  (passCondition0k && passCondition1j && passCondition2i && passCondition3m) ||
386  (passCondition0k && passCondition1j && passCondition2m && passCondition3i) ||
387  (passCondition0k && passCondition1m && passCondition2i && passCondition3j) ||
388  (passCondition0k && passCondition1m && passCondition2j && passCondition3i) ||
389  (passCondition0m && passCondition1i && passCondition2j && passCondition3k) ||
390  (passCondition0m && passCondition1i && passCondition2k && passCondition3j) ||
391  (passCondition0m && passCondition1j && passCondition2i && passCondition3k) ||
392  (passCondition0m && passCondition1j && passCondition2k && passCondition3i) ||
393  (passCondition0m && passCondition1k && passCondition2i && passCondition3j) ||
394  (passCondition0m && passCondition1k && passCondition2j && passCondition3i));
395  if (pass) {
396  objectsInComb.clear();
397  objectsInComb.push_back(i);
398  objectsInComb.push_back(j);
399  objectsInComb.push_back(k);
400  objectsInComb.push_back(m);
401  condResult = true;
402  passLoops++;
403  combinationsInCond().push_back(objectsInComb);
404  }
405  } // end loop on m
406  } // end loop on k
407  } // end loop on j
408  } // end loop on i
409  } // end if condition has 4 objects
410 
411  LogTrace("L1TGlobal") << "\n CaloCondition: total number of permutations found: " << totalLoops
412  << "\n CaloCondition: number of permutations passing requirements: " << passLoops << "\n"
413  << std::endl;
414 
415  return condResult;
416 }
417 
418 // load calo candidates
419 const l1t::L1Candidate* l1t::CaloCondition::getCandidate(const int bx, const int indexCand) const {
420  // objectType() gives the type for nrObjects() only,
421  // but in a CondCalo all objects have the same type
422  // take type from the type of the first object
423  switch ((m_gtCaloTemplate->objectType())[0]) {
424  case gtEG:
425  return (m_uGtB->getCandL1EG())->at(bx, indexCand);
426  break;
427 
428  case gtJet:
429  return (m_uGtB->getCandL1Jet())->at(bx, indexCand);
430  break;
431 
432  case gtTau:
433  return (m_uGtB->getCandL1Tau())->at(bx, indexCand);
434  break;
435  default:
436  return nullptr;
437  break;
438  }
439 
440  return nullptr;
441 }
442 
452 const bool l1t::CaloCondition::checkObjectParameter(const int iCondition,
453  const l1t::L1Candidate& cand,
454  unsigned int index) const {
455  // number of objects in condition
456  int nObjInCond = m_gtCaloTemplate->nrObjects();
457 
458  if (iCondition >= nObjInCond || iCondition < 0) {
459  return false;
460  }
461 
462  // empty candidates can not be compared
463  // if (cand.empty()) {
464  // return false;
465  // }
466 
467  const CaloTemplate::ObjectParameter objPar = (*(m_gtCaloTemplate->objectParameter()))[iCondition];
468 
469  LogDebug("L1TGlobal") << "\n CaloTemplate: "
470  << "\n\t condRelativeBx = " << m_gtCaloTemplate->condRelativeBx() << "\n ObjectParameter : "
471  << "\n\t etThreshold = " << objPar.etLowThreshold << " - " << objPar.etHighThreshold
472  << "\n\t indexRange = " << objPar.indexLow << " - " << objPar.indexHigh
473  << "\n\t etaRange = " << objPar.etaRange << "\n\t phiRange = " << objPar.phiRange
474  << "\n\t isolationLUT= " << objPar.isolationLUT << std::endl;
475 
476  LogDebug("L1TGlobal") << "\n l1t::Candidate : "
477  << "\n\t hwPt = " << cand.hwPt() << "\n\t hwEta = " << cand.hwEta()
478  << "\n\t hwPhi = " << cand.hwPhi() << std::endl;
479 
480  // check energy threshold
481  if (!checkThreshold(objPar.etLowThreshold, objPar.etHighThreshold, cand.hwPt(), m_gtCaloTemplate->condGEq())) {
482  LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed checkThreshold" << std::endl;
483  return false;
484  }
485 
486  // check index
487  if (!checkIndex(objPar.indexLow, objPar.indexHigh, index)) {
488  LogDebug("L1TGlobal") << "\t\t ilt::Candidate Failed checkIndex " << std::endl;
489  return false;
490  }
491 
492  // check eta
493  if (!checkRangeEta(cand.hwEta(),
494  objPar.etaWindow1Lower,
495  objPar.etaWindow1Upper,
496  objPar.etaWindow2Lower,
497  objPar.etaWindow2Upper,
498  7)) {
499  LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed checkRange(eta)" << std::endl;
500  return false;
501  }
502 
503  // if (!checkBit(objPar.etaRange, cand.hwEta())) {
504  // return false;
505  // }
506 
507  // check phi
508  if (!checkRangePhi(cand.hwPhi(),
509  objPar.phiWindow1Lower,
510  objPar.phiWindow1Upper,
511  objPar.phiWindow2Lower,
512  objPar.phiWindow2Upper)) {
513  LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed checkRange(phi)" << std::endl;
514  return false;
515  }
516 
517  // check isolation ( bit check ) with isolation LUT
518  // sanity check on candidate isolation
519  if (cand.hwIso() > 4) {
520  LogDebug("L1TGlobal") << "\t\t l1t::Candidate has out of range hwIso = " << cand.hwIso() << std::endl;
521  return false;
522  }
523  bool passIsoLUT = ((objPar.isolationLUT >> cand.hwIso()) & 1);
524  if (!passIsoLUT) {
525  LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed isolation requirement" << std::endl;
526  return false;
527  }
528 
529  // sanity check for hwQual ( 3-bit wide check corresponding to bits 27-28-29 in the L1T Jet Word ).
530  // note that this check includes the entire 3-bit width of hwQual, of which only the least significant bit
531  // is currently defined (the other two bits are not yet defined).
532  if (cand.hwQual() > 7) {
533  LogDebug("L1TGlobal") << "\t\t l1t::Candidate has out of range hwQual = " << cand.hwQual() << std::endl;
534  return false;
535  }
536 
537  bool hasDisplacedLUT =
538  objPar.displacedLUT & 1; // Does this algorithm have an LLP cut defined for the algo in the menu?
539  bool passDisplacedLUT = (objPar.displacedLUT & cand.hwQual()); // Did this candidate pass the LLP cut?
540  if (hasDisplacedLUT &&
541  !passDisplacedLUT) { // Require an inclusive trigger: if LLP cut is not part of algo, ignore cut.
542  LogDebug("L1TGlobal") << "\t\t l1t::Candidate failed displaced requirement" << std::endl;
543  return false;
544  }
545 
546  // if (!checkBit(objPar.phiRange, cand.hwPhi())) {
547  // return false;
548  // }
549 
550  // particle matches if we get here
551  //LogTrace("L1TGlobal")
552  // << " checkObjectParameter: calorimeter object OK, passes all requirements\n"
553  // << std::endl;
554 
555  return true;
556 }
557 
558 void l1t::CaloCondition::print(std::ostream& myCout) const {
559  m_gtCaloTemplate->print(myCout);
560 
561  myCout << " Number of bits for eta of calorimeter objects = " << m_ifCaloEtaNumberBits << std::endl;
562  myCout << " Maximum number of bins for the delta phi scales = " << m_corrParDeltaPhiNrBins << "\n " << std::endl;
563 
565 }
int getLastBX() const
unsigned int m_corrParDeltaPhiNrBins
void print(std::ostream &myCout) const override
print condition
void setGtCorrParDeltaPhiNrBins(const int &)
void setGtIfCaloEtaNumberBits(const int &)
std::vector< int > SingleCombInCond
typedefs
Log< level::Error, false > LogError
typedef for a single object template
Definition: CaloTemplate.h:61
void setGtCaloTemplate(const CaloTemplate *)
#define LogTrace(id)
unsigned size(int bx) const
const std::vector< l1t::GlobalObject > & objectType() const
get / set the trigger object type(s) in the condition
const T & at(int bx, unsigned i) const
void setuGtB(const GlobalBoard *)
set the pointer to uGT GlobalBoard
~CaloCondition() override
virtual void print(std::ostream &myCout) const
print condition
CaloCondition & operator=(const CaloCondition &)
const l1t::L1Candidate * getCandidate(const int bx, const int indexCand) const
load calo candidates
typedef for correlation parameters
Definition: CaloTemplate.h:85
void copy(const CaloCondition &cp)
copy function for copy constructor and operator=
int m_ifCaloEtaNumberBits
number of bits for eta of calorimeter objects
const bool evaluateCondition(const int bxEval) const override
the core function to check if the condition matches
const CaloTemplate * m_gtCaloTemplate
pointer to a CaloTemplate
const bool checkObjectParameter(const int iCondition, const l1t::L1Candidate &cand, const unsigned int index) const
function to check a single object if it matches a condition
#define LogDebug(id)