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