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