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 
54 
55 }
56 
57 // from base template condition (from event setup usually)
59  const int nrL1NoIsoEG,
60  const int nrL1IsoEG,
61  const int nrL1CenJet,
62  const int nrL1ForJet,
63  const int nrL1TauJet,
64  const int ifCaloEtaNumberBits) :
66  m_gtCaloTemplate(static_cast<const L1GtCaloTemplate*>(caloTemplate)),
67  m_gtPSB(ptrPSB),
68  m_ifCaloEtaNumberBits(ifCaloEtaNumberBits)
69 {
70 
71  // maximum number of objects received for the evaluation of the condition
72  // retrieved before from event setup
73  // for a CondCalo, all objects ar of same type, hence it is enough to get the
74  // type for the first object
75 
76  switch ((m_gtCaloTemplate->objectType())[0]) {
77  case NoIsoEG:
78  m_condMaxNumberObjects = nrL1NoIsoEG;
79  break;
80  case IsoEG:
81  m_condMaxNumberObjects = nrL1IsoEG;
82  break;
83  case CenJet:
84  m_condMaxNumberObjects = nrL1CenJet;
85  break;
86  case ForJet:
87  m_condMaxNumberObjects = nrL1ForJet;
88  break;
89  case TauJet:
90  m_condMaxNumberObjects = nrL1TauJet;
91  break;
92  default:
94  break;
95  }
96 
97 }
98 
99 // copy constructor
101 
103  m_gtPSB = cp.gtPSB();
104 
106 
110 
112 
113 }
114 
117 
118  copy(cp);
119 
120 }
121 
122 // destructor
124 
125  // empty
126 
127 }
128 
129 // equal operator
131 {
132  copy(cp);
133  return *this;
134 }
135 
136 // methods
138 
139  m_gtCaloTemplate = caloTempl;
140 
141 }
142 
143 // set the number of bits for eta of calorimeter objects
144 void L1GtCaloCondition::setGtIfCaloEtaNumberBits(const int& ifCaloEtaNumberBitsValue) {
145 
146  m_ifCaloEtaNumberBits = ifCaloEtaNumberBitsValue;
147 
148 }
149 
152 
153  m_gtPSB = ptrPSB;
154 
155 }
156 
157 // try all object permutations and check spatial correlations, if required
159 
160  // number of trigger objects in the condition
161  int nObjInCond = m_gtCaloTemplate->nrObjects();
162  //LogTrace("L1GtCaloCondition") << " nObjInCond: " << nObjInCond
163  // << std::endl;
164 
165  // the candidates
166 
167  // objectType() gives the type for nrObjects() only,
168  // but in a CondCalo all objects have the same type
169  // take type from the type of the first object
170 
171  const std::vector<const L1GctCand*>* candVec;
172 
173  switch ((m_gtCaloTemplate->objectType())[0]) {
174  case NoIsoEG:
175  candVec = m_gtPSB->getCandL1NoIsoEG();
176  break;
177  case IsoEG:
178  candVec = m_gtPSB->getCandL1IsoEG();
179  break;
180  case CenJet:
181  candVec = m_gtPSB->getCandL1CenJet();
182  break;
183  case ForJet:
184  candVec = m_gtPSB->getCandL1ForJet();
185  break;
186  case TauJet:
187  candVec = m_gtPSB->getCandL1TauJet();
188  break;
189  default:
190  return false;
191  break;
192  }
193 
194  int numberObjects = candVec->size();
195  //LogTrace("L1GtCaloCondition") << " 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 jumpIndex = 1;
208  int jump = factorial(numberObjects - nObjInCond);
209 
210  int totalLoops = 0;
211  int passLoops = 0;
212 
213  // condition result condResult set to true if at least one permutation
214  // passes all requirements
215  // all possible permutations are checked
216  bool condResult = false;
217 
218  // store the indices of the calorimeter objects
219  // from the combination evaluated in the condition
220  SingleCombInCond objectsInComb;
221  objectsInComb.reserve(nObjInCond);
222 
223  // clear the m_combinationsInCond vector
224  (*m_combinationsInCond).clear();
225 
226  do {
227 
228  if (--jumpIndex)
229  continue;
230 
231  jumpIndex = jump;
232  totalLoops++;
233 
234  // clear the indices in the combination
235  objectsInComb.clear();
236 
237  bool tmpResult = true;
238 
239  // check if there is a permutation that matches object-parameter requirements
240  for (int i = 0; i < nObjInCond; i++) {
241 
242  tmpResult &= checkObjectParameter(i, *(*candVec)[index[i]]);
243  objectsInComb.push_back(index[i]);
244 
245  }
246 
247  // if permutation does not match particle conditions
248  // skip spatial correlations
249  if (!tmpResult) {
250 
251  continue;
252 
253  }
254 
255  if (m_gtCaloTemplate->wsc()) {
256 
257  // wsc requirements have always nObjInCond = 2
258  // one can use directly index[0] and index[1] to compute
259  // eta and phi differences
260  const int ObjInWscComb = 2;
261  if (nObjInCond != ObjInWscComb) {
262 
263  if (m_verbosity) {
264  edm::LogError("L1GtCaloCondition")
265  << "\n Error: "
266  << "number of particles in condition with spatial correlation = "
267  << nObjInCond << "\n it must be = " << ObjInWscComb
268  << std::endl;
269  }
270 
271  continue;
272  }
273 
276 
277  unsigned int candDeltaEta;
278  unsigned int candDeltaPhi;
279 
280  // check candDeltaEta
281 
282  // get eta index and the sign bit of the eta index (MSB is the sign)
283  // signedEta[i] is the signed eta index of candVec[index[i]]
284  int signedEta[ObjInWscComb];
285  int signBit[ObjInWscComb] = { 0, 0 };
286 
287  int scaleEta = 1 << (m_ifCaloEtaNumberBits - 1);
288 
289  for (int i = 0; i < ObjInWscComb; ++i) {
290  signBit[i] = ((*candVec)[index[i]]->etaIndex() & scaleEta)
291  >>(m_ifCaloEtaNumberBits - 1);
292  signedEta[i] = ((*candVec)[index[i]]->etaIndex() )%scaleEta;
293 
294  if (signBit[i] == 1) {
295  signedEta[i] = (-1)*signedEta[i];
296  }
297 
298  }
299 
300  // compute candDeltaEta - add 1 if signs are different (due to +0/-0 indices)
301  candDeltaEta = static_cast<int> (std::abs(signedEta[1] - signedEta[0]))
302  + static_cast<int> (signBit[1]^signBit[0]);
303 
304  if ( !checkBit(corrPar.deltaEtaRange, candDeltaEta) ) {
305  continue;
306  }
307 
308  // check candDeltaPhi
309 
310  // calculate absolute value of candDeltaPhi
311  if ((*candVec)[index[0]]->phiIndex()> (*candVec)[index[1]]->phiIndex()) {
312  candDeltaPhi = (*candVec)[index[0]]->phiIndex() - (*candVec)[index[1]]->phiIndex();
313  }
314  else {
315  candDeltaPhi = (*candVec)[index[1]]->phiIndex() - (*candVec)[index[0]]->phiIndex();
316  }
317 
318  // check if candDeltaPhi > 180 (via delta_phi_maxbits)
319  // delta_phi contains bits for 0..180 (0 and 180 included)
320  while (candDeltaPhi> corrPar.deltaPhiMaxbits) {
321 
322  // candDeltaPhi > 180 ==> take 360 - candDeltaPhi
323  candDeltaPhi = (corrPar.deltaPhiMaxbits - 1)*2 - candDeltaPhi;
324  if (m_verbosity) {
325  LogTrace("L1GtCaloCondition")
326  << " candDeltaPhi rescaled to: " << candDeltaPhi
327  << std::endl;
328  }
329  }
330 
331  if (!checkBit(corrPar.deltaPhiRange, candDeltaPhi)) {
332  continue;
333  }
334 
335  } // end wsc check
336 
337  // if we get here all checks were successfull for this combination
338  // set the general result for evaluateCondition to "true"
339 
340  condResult = true;
341  passLoops++;
342  (*m_combinationsInCond).push_back(objectsInComb);
343 
344  // } while ( std::next_permutation(index, index + nObj) );
345  } while (std::next_permutation(index.begin(), index.end()) );
346 
347  //LogTrace("L1GtCaloCondition")
348  // << "\n L1GtCaloCondition: total number of permutations found: " << totalLoops
349  // << "\n L1GtCaloCondition: number of permutations passing requirements: " << passLoops
350  // << "\n" << std::endl;
351 
352  return condResult;
353 
354 }
355 
356 // load calo candidates
357 const L1GctCand* L1GtCaloCondition::getCandidate(const int indexCand) const {
358 
359  // objectType() gives the type for nrObjects() only,
360  // but in a CondCalo all objects have the same type
361  // take type from the type of the first object
362  switch ((m_gtCaloTemplate->objectType())[0]) {
363  case NoIsoEG:
364  return (*(m_gtPSB->getCandL1NoIsoEG()))[indexCand];
365  break;
366  case IsoEG:
367  return (*(m_gtPSB->getCandL1IsoEG()))[indexCand];
368  break;
369  case CenJet:
370  return (*(m_gtPSB->getCandL1CenJet()))[indexCand];
371  break;
372  case ForJet:
373  return (*(m_gtPSB->getCandL1ForJet()))[indexCand];
374  break;
375  case TauJet:
376  return (*(m_gtPSB->getCandL1TauJet()))[indexCand];
377  break;
378  default:
379  return 0;
380  break;
381  }
382 
383  return 0;
384 }
385 
395 const bool L1GtCaloCondition::checkObjectParameter(const int iCondition, const L1GctCand& cand) const {
396 
397  // number of objects in condition
398  int nObjInCond = m_gtCaloTemplate->nrObjects();
399 
400  if (iCondition >= nObjInCond || iCondition < 0) {
401  return false;
402  }
403 
404  // empty candidates can not be compared
405  if (cand.empty()) {
406  return false;
407  }
408 
409  const L1GtCaloTemplate::ObjectParameter objPar = ( *(m_gtCaloTemplate->objectParameter()) )[iCondition];
410 
411  // check energy threshold
412  if ( !checkThreshold(objPar.etThreshold, cand.rank(), m_gtCaloTemplate->condGEq()) ) {
413  return false;
414  }
415 
416  // check eta
417  if (!checkBit(objPar.etaRange, cand.etaIndex())) {
418  return false;
419  }
420 
421  // check phi
422 
423  if (!checkBit(objPar.phiRange, cand.phiIndex())) {
424  return false;
425  }
426 
427  // particle matches if we get here
428  //LogTrace("L1GtCaloCondition")
429  // << " checkObjectParameter: calorimeter object OK, passes all requirements\n"
430  // << std::endl;
431 
432  return true;
433 }
434 
435 void L1GtCaloCondition::print(std::ostream& myCout) const {
436 
437  m_gtCaloTemplate->print(myCout);
439 
440 }
441 
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
CombinationsInCond * m_combinationsInCond
store all the object combinations evaluated to true in the condition
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
CombinationsInCond * getCombinationsInCond() const
get all the object combinations evaluated to true in the condition
bool m_condLastResult
the last result of evaluateCondition()
const int gtIfCaloEtaNumberBits() const
get / set the number of bits for eta of calorimeter objects
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
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)
bool condLastResult() const
get the latest result for the condition