CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1GtCaloCondition.cc
Go to the documentation of this file.
1 
17 // this class header
19 
20 // system include files
21 #include <iostream>
22 #include <iomanip>
23 
24 #include <string>
25 #include <vector>
26 #include <algorithm>
27 
28 // user include files
29 // base classes
32 
34 
38 
41 
44 
47 
48 // constructors
49 // default
52 
55 
56 }
57 
58 // from base template condition (from event setup usually)
60  const int nrL1NoIsoEG,
61  const int nrL1IsoEG,
62  const int nrL1CenJet,
63  const int nrL1ForJet,
64  const int nrL1TauJet,
65  const int ifCaloEtaNumberBits) :
67  m_gtCaloTemplate(static_cast<const L1GtCaloTemplate*>(caloTemplate)),
68  m_gtPSB(ptrPSB),
69  m_ifCaloEtaNumberBits(ifCaloEtaNumberBits)
70 {
71 
73 
74  // maximum number of objects received for the evaluation of the condition
75  // retrieved before from event setup
76  // for a CondCalo, all objects ar of same type, hence it is enough to get the
77  // type for the first object
78 
79  switch ((m_gtCaloTemplate->objectType())[0]) {
80  case NoIsoEG:
81  m_condMaxNumberObjects = nrL1NoIsoEG;
82  break;
83  case IsoEG:
84  m_condMaxNumberObjects = nrL1IsoEG;
85  break;
86  case CenJet:
87  m_condMaxNumberObjects = nrL1CenJet;
88  break;
89  case ForJet:
90  m_condMaxNumberObjects = nrL1ForJet;
91  break;
92  case TauJet:
93  m_condMaxNumberObjects = nrL1TauJet;
94  break;
95  default:
97  break;
98  }
99 
100 }
101 
102 // copy constructor
104 
106  m_gtPSB = cp.gtPSB();
107 
110 
114 
116 
117 }
118 
121 
122  copy(cp);
123 
124 }
125 
126 // destructor
128 
129  // empty
130 
131 }
132 
133 // equal operator
135  copy(cp);
136  return *this;
137 }
138 
139 // methods
141 
142  m_gtCaloTemplate = caloTempl;
143 
144 }
145 
148 
149  m_gtPSB = ptrPSB;
150 
151 }
152 
153 // set the number of bits for eta of calorimeter objects
154 void L1GtCaloCondition::setGtIfCaloEtaNumberBits(const int& ifCaloEtaNumberBitsValue) {
155 
156  m_ifCaloEtaNumberBits = ifCaloEtaNumberBitsValue;
157 
158 }
159 
160 // set the maximum number of bins for the delta phi scales
162  const int& corrParDeltaPhiNrBins) {
163 
164  m_corrParDeltaPhiNrBins = corrParDeltaPhiNrBins;
165 
166 }
167 
168 // try all object permutations and check spatial correlations, if required
170 
171  // number of trigger objects in the condition
172  int nObjInCond = m_gtCaloTemplate->nrObjects();
173  //LogTrace("L1GlobalTrigger") << " nObjInCond: " << nObjInCond
174  // << std::endl;
175 
176  // the candidates
177 
178  // objectType() gives the type for nrObjects() only,
179  // but in a CondCalo all objects have the same type
180  // take type from the type of the first object
181 
182  const std::vector<const L1GctCand*>* candVec;
183 
184  switch ((m_gtCaloTemplate->objectType())[0]) {
185  case NoIsoEG:
186  candVec = m_gtPSB->getCandL1NoIsoEG();
187  break;
188  case IsoEG:
189  candVec = m_gtPSB->getCandL1IsoEG();
190  break;
191  case CenJet:
192  candVec = m_gtPSB->getCandL1CenJet();
193  break;
194  case ForJet:
195  candVec = m_gtPSB->getCandL1ForJet();
196  break;
197  case TauJet:
198  candVec = m_gtPSB->getCandL1TauJet();
199  break;
200  default:
201  return false;
202  break;
203  }
204 
205  int numberObjects = candVec->size();
206  //LogTrace("L1GlobalTrigger") << " numberObjects: " << numberObjects
207  // << std::endl;
208  if (numberObjects < nObjInCond) {
209  return false;
210  }
211 
212  std::vector<int> index(numberObjects);
213 
214  for (int i = 0; i < numberObjects; ++i) {
215  index[i] = i;
216  }
217 
218  int jumpIndex = 1;
219  int jump = factorial(numberObjects - nObjInCond);
220 
221  int totalLoops = 0;
222  int passLoops = 0;
223 
224  // condition result condResult set to true if at least one permutation
225  // passes all requirements
226  // all possible permutations are checked
227  bool condResult = false;
228 
229  // store the indices of the calorimeter objects
230  // from the combination evaluated in the condition
231  SingleCombInCond objectsInComb;
232  objectsInComb.reserve(nObjInCond);
233 
234  // clear the m_combinationsInCond vector
235  combinationsInCond().clear();
236 
237  do {
238 
239  if (--jumpIndex)
240  continue;
241 
242  jumpIndex = jump;
243  totalLoops++;
244 
245  // clear the indices in the combination
246  objectsInComb.clear();
247 
248  bool tmpResult = true;
249 
250  // check if there is a permutation that matches object-parameter requirements
251  for (int i = 0; i < nObjInCond; i++) {
252 
253  tmpResult &= checkObjectParameter(i, *(*candVec)[index[i]]);
254  objectsInComb.push_back(index[i]);
255 
256  }
257 
258  // if permutation does not match particle conditions
259  // skip spatial correlations
260  if (!tmpResult) {
261 
262  continue;
263 
264  }
265 
266  if (m_gtCaloTemplate->wsc()) {
267 
268  // wsc requirements have always nObjInCond = 2
269  // one can use directly index[0] and index[1] to compute
270  // eta and phi differences
271  const int ObjInWscComb = 2;
272  if (nObjInCond != ObjInWscComb) {
273 
274  if (m_verbosity) {
275  edm::LogError("L1GlobalTrigger")
276  << "\n Error: "
277  << "number of particles in condition with spatial correlation = "
278  << nObjInCond << "\n it must be = " << ObjInWscComb
279  << std::endl;
280  }
281 
282  continue;
283  }
284 
287 
288  unsigned int candDeltaEta;
289  unsigned int candDeltaPhi;
290 
291  // check candDeltaEta
292 
293  // get eta index and the sign bit of the eta index (MSB is the sign)
294  // signedEta[i] is the signed eta index of candVec[index[i]]
295  int signedEta[ObjInWscComb];
296  int signBit[ObjInWscComb] = { 0, 0 };
297 
298  int scaleEta = 1 << (m_ifCaloEtaNumberBits - 1);
299 
300  for (int i = 0; i < ObjInWscComb; ++i) {
301  signBit[i] = ((*candVec)[index[i]]->etaIndex() & scaleEta)
302  >>(m_ifCaloEtaNumberBits - 1);
303  signedEta[i] = ((*candVec)[index[i]]->etaIndex() )%scaleEta;
304 
305  if (signBit[i] == 1) {
306  signedEta[i] = (-1)*signedEta[i];
307  }
308 
309  }
310 
311  // compute candDeltaEta - add 1 if signs are different (due to +0/-0 indices)
312  candDeltaEta = static_cast<int> (std::abs(signedEta[1] - signedEta[0]))
313  + static_cast<int> (signBit[1]^signBit[0]);
314 
315  if ( !checkBit(corrPar.deltaEtaRange, candDeltaEta) ) {
316  continue;
317  }
318 
319  // check candDeltaPhi
320 
321  // calculate absolute value of candDeltaPhi
322  if ((*candVec)[index[0]]->phiIndex()> (*candVec)[index[1]]->phiIndex()) {
323  candDeltaPhi = (*candVec)[index[0]]->phiIndex() - (*candVec)[index[1]]->phiIndex();
324  }
325  else {
326  candDeltaPhi = (*candVec)[index[1]]->phiIndex() - (*candVec)[index[0]]->phiIndex();
327  }
328 
329  // check if candDeltaPhi > 180 (via delta_phi_maxbits)
330  // delta_phi contains bits for 0..180 (0 and 180 included)
331  // protect also against infinite loop...
332 
333  int nMaxLoop = 10;
334  int iLoop = 0;
335 
336  while (candDeltaPhi >= m_corrParDeltaPhiNrBins) {
337 
338  unsigned int candDeltaPhiInitial = candDeltaPhi;
339 
340  // candDeltaPhi > 180 ==> take 360 - candDeltaPhi
341  candDeltaPhi = (m_corrParDeltaPhiNrBins - 1) * 2 - candDeltaPhi;
342  if (m_verbosity) {
343  LogTrace("L1GlobalTrigger")
344  << " Initial candDeltaPhi = "
345  << candDeltaPhiInitial
346  << " > m_corrParDeltaPhiNrBins = "
348  << " ==> candDeltaPhi rescaled to: "
349  << candDeltaPhi << " [ loop index " << iLoop
350  << "; breaks after " << nMaxLoop << " loops ]\n"
351  << std::endl;
352  }
353 
354  iLoop++;
355  if (iLoop > nMaxLoop) {
356  return false;
357  }
358  }
359 
360 
361  if (!checkBit(corrPar.deltaPhiRange, candDeltaPhi)) {
362  continue;
363  }
364 
365  } // end wsc check
366 
367  // if we get here all checks were successful for this combination
368  // set the general result for evaluateCondition to "true"
369 
370  condResult = true;
371  passLoops++;
372  combinationsInCond().push_back(objectsInComb);
373 
374  // } while ( std::next_permutation(index, index + nObj) );
375  } while (std::next_permutation(index.begin(), index.end()) );
376 
377  //LogTrace("L1GlobalTrigger")
378  // << "\n L1GtCaloCondition: total number of permutations found: " << totalLoops
379  // << "\n L1GtCaloCondition: number of permutations passing requirements: " << passLoops
380  // << "\n" << std::endl;
381 
382  return condResult;
383 
384 }
385 
386 // load calo candidates
387 const L1GctCand* L1GtCaloCondition::getCandidate(const int indexCand) const {
388 
389  // objectType() gives the type for nrObjects() only,
390  // but in a CondCalo all objects have the same type
391  // take type from the type of the first object
392  switch ((m_gtCaloTemplate->objectType())[0]) {
393  case NoIsoEG:
394  return (*(m_gtPSB->getCandL1NoIsoEG()))[indexCand];
395  break;
396  case IsoEG:
397  return (*(m_gtPSB->getCandL1IsoEG()))[indexCand];
398  break;
399  case CenJet:
400  return (*(m_gtPSB->getCandL1CenJet()))[indexCand];
401  break;
402  case ForJet:
403  return (*(m_gtPSB->getCandL1ForJet()))[indexCand];
404  break;
405  case TauJet:
406  return (*(m_gtPSB->getCandL1TauJet()))[indexCand];
407  break;
408  default:
409  return 0;
410  break;
411  }
412 
413  return 0;
414 }
415 
425 const bool L1GtCaloCondition::checkObjectParameter(const int iCondition, const L1GctCand& cand) const {
426 
427  // number of objects in condition
428  int nObjInCond = m_gtCaloTemplate->nrObjects();
429 
430  if (iCondition >= nObjInCond || iCondition < 0) {
431  return false;
432  }
433 
434  // empty candidates can not be compared
435  if (cand.empty()) {
436  return false;
437  }
438 
439  const L1GtCaloTemplate::ObjectParameter objPar = ( *(m_gtCaloTemplate->objectParameter()) )[iCondition];
440 
441  // check energy threshold
442  if ( !checkThreshold(objPar.etThreshold, cand.rank(), m_gtCaloTemplate->condGEq()) ) {
443  return false;
444  }
445 
446  // check eta
447  if (!checkBit(objPar.etaRange, cand.etaIndex())) {
448  return false;
449  }
450 
451  // check phi
452 
453  if (!checkBit(objPar.phiRange, cand.phiIndex())) {
454  return false;
455  }
456 
457  // particle matches if we get here
458  //LogTrace("L1GlobalTrigger")
459  // << " checkObjectParameter: calorimeter object OK, passes all requirements\n"
460  // << std::endl;
461 
462  return true;
463 }
464 
465 void L1GtCaloCondition::print(std::ostream& myCout) const {
466 
467  m_gtCaloTemplate->print(myCout);
468 
469  myCout << " Number of bits for eta of calorimeter objects = "
470  << m_ifCaloEtaNumberBits << std::endl;
471  myCout << " Maximum number of bins for the delta phi scales = "
472  << m_corrParDeltaPhiNrBins << "\n " << std::endl;
473 
475 
476 }
477 
virtual bool empty() const =0
empty candidate - true if object not initialized
int i
Definition: DBlmapReader.cc:9
int m_ifCaloEtaNumberBits
number of bits for eta of calorimeter objects
const std::vector< const L1GctCand * > * getCandL1TauJet() const
pointer to TauJet data list
void print(std::ostream &myCout) const
print condition
const int nrObjects() const
get number of trigger objects
const bool checkBit(const Type1 &mask, const unsigned int bitNumber) const
check if a bit with a given number is set in a mask
const std::vector< const L1GctCand * > * getCandL1CenJet() const
pointer to CenJet data list
bool m_condLastResult
the last result of evaluateCondition()
const int gtIfCaloEtaNumberBits() const
get / set the number of bits for eta of calorimeter objects
CombinationsInCond m_combinationsInCond
store all the object combinations evaluated to true in the condition
CombinationsInCond & combinationsInCond() const
get all the object combinations (to fill it...)
const std::vector< const L1GctCand * > * getCandL1NoIsoEG() const
pointer to NoIsoEG data list
const std::vector< const L1GctCand * > * getCandL1ForJet() const
pointer to ForJet data list
#define abs(x)
Definition: mlp_lapack.h:159
std::vector< int > SingleCombInCond
typedefs
const L1GlobalTriggerPSB * m_gtPSB
pointer to PSB, to be able to get the trigger objects
const std::vector< L1GtObject > & objectType() const
get / set the trigger object type(s) in the condition
Definition: L1GtCondition.h:88
const L1GctCand * getCandidate(const int indexCand) const
load calo candidates
void setGtCaloTemplate(const L1GtCaloTemplate *)
const bool checkObjectParameter(const int iCondition, const L1GctCand &cand) const
function to check a single object if it matches a condition
const L1GlobalTriggerPSB * gtPSB() const
get / set the pointer to PSB
const std::vector< const L1GctCand * > * getCandL1IsoEG() const
pointer to IsoEG data list
const L1GtCaloTemplate * m_gtCaloTemplate
pointer to a L1GtCaloTemplate
L1GtCaloCondition & operator=(const L1GtCaloCondition &)
virtual unsigned etaIndex() const =0
get eta index (bit 3 is sign, 1 for -ve Z, 0 for +ve Z)
const bool wsc() const
const bool checkThreshold(const Type1 &threshold, const Type2 &value, const bool condGEqValue) const
const L1GtCaloTemplate * gtCaloTemplate() const
get / set the pointer to a L1GtCondition
void setGtIfCaloEtaNumberBits(const int &)
void copy(const L1GtCaloCondition &cp)
copy function for copy constructor and operator=
typedef for a single object template
unsigned int m_corrParDeltaPhiNrBins
typedef for correlation parameters
#define LogTrace(id)
virtual void print(std::ostream &myCout) const
print the condition
const bool evaluateCondition() const
the core function to check if the condition matches
virtual unsigned phiIndex() const =0
get phi index (0-17)
void setGtPSB(const L1GlobalTriggerPSB *)
set the pointer to PSB
string const
Definition: compareJSON.py:14
const CorrelationParameter * correlationParameter() const
ABC for GCT EM and jet candidates.
Definition: L1GctCand.h:12
int factorial(int n)
factorial function
virtual void print(std::ostream &myCout) const
print condition
const bool condGEq() const
get / set condition GEq flag
Definition: L1GtCondition.h:99
const std::vector< ObjectParameter > * objectParameter() const
virtual unsigned rank() const =0
get the rank code (6 bits)
CombinationsInCond const & getCombinationsInCond() const
get all the object combinations evaluated to true in the condition
bool condLastResult() const
get the latest result for the condition
void setGtCorrParDeltaPhiNrBins(const int &)