CMS 3D CMS Logo

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