CMS 3D CMS Logo

CorrCondition.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 
36 
38 
40 
43 
44 // constructors
45 // default
48 
49 }
50 
51 // from base template condition (from event setup usually)
53  const GlobalCondition* cond0Condition,
54  const GlobalCondition* cond1Condition,
55  const GlobalBoard* ptrGTB
56  ) :
58  m_gtCorrelationTemplate(static_cast<const CorrelationTemplate*>(corrTemplate)),
59  m_gtCond0(cond0Condition), m_gtCond1(cond1Condition),
60  m_uGtB(ptrGTB)
61 {
62 
63 
64 
65 }
66 
67 // copy constructor
69 
71  m_uGtB = cp.getuGtB();
72 
76 
78 
79 }
80 
83 
84  copy(cp);
85 
86 }
87 
88 // destructor
90 
91  // empty
92 
93 }
94 
95 // equal operator
97  copy(cp);
98  return *this;
99 }
100 
101 // methods
103 
104  m_gtCorrelationTemplate = caloTempl;
105 
106 }
107 
110 
111  m_uGtB = ptrGTB;
112 
113 }
114 
115 
117 {
118  m_gtScales = sc;
119 }
120 
121 
122 
123 // try all object permutations and check spatial correlations, if required
124 const bool l1t::CorrCondition::evaluateCondition(const int bxEval) const {
125 
126  // std::cout << "m_isDebugEnabled = " << m_isDebugEnabled << std::endl;
127  // std::cout << "m_verbosity = " << m_verbosity << std::endl;
128 
129 
130  //std::ostringstream myCout;
131  //m_gtCorrelationTemplate->print(myCout);
132  //LogDebug("L1TGlobal")
133  // << "Correlation Condition Evaluation \n" << myCout.str() << std::endl;
134 
135  bool condResult = false;
136  bool reqObjResult = false;
137 
138  // number of objects in condition (it is 2, no need to retrieve from
139  // condition template) and their type
140  int nObjInCond = 2;
141  std::vector<GlobalObject> cndObjTypeVec(nObjInCond);
142 
143  // evaluate first the two sub-conditions (Type1s)
144 
147 
148  //Decide if we have a mixed (muon + cal) condition
149  bool convertCaloScales = false;
150  if( (cond0Categ == CondMuon && (cond1Categ == CondCalo || cond1Categ == CondEnergySum) ) ||
151  (cond1Categ == CondMuon && (cond0Categ == CondCalo || cond0Categ == CondEnergySum) ) )
152  convertCaloScales = true;
153 
154  const MuonTemplate* corrMuon = nullptr;
155  const CaloTemplate* corrCalo = nullptr;
156  const EnergySumTemplate* corrEnergySum = nullptr;
157 
158  // FIXME copying is slow...
159  CombinationsInCond cond0Comb;
160  CombinationsInCond cond1Comb;
161 
162  int cond0bx(0);
163  int cond1bx(0);
164 
165  switch (cond0Categ) {
166  case CondMuon: {
167  corrMuon = static_cast<const MuonTemplate*>(m_gtCond0);
168  MuCondition muCondition(corrMuon, m_uGtB,
169  0,0); //BLW these are counts that don't seem to be used...perhaps remove
170 
171  muCondition.evaluateConditionStoreResult(bxEval);
172  reqObjResult = muCondition.condLastResult();
173 
174  cond0Comb = (muCondition.getCombinationsInCond());
175  cond0bx = bxEval + (corrMuon->condRelativeBx());
176  cndObjTypeVec[0] = (corrMuon->objectType())[0];
177 
178  if (m_verbosity ) {
179  std::ostringstream myCout;
180  muCondition.print(myCout);
181 
182  LogDebug("L1TGlobal") << myCout.str() << std::endl;
183  }
184  }
185  break;
186  case CondCalo: {
187  corrCalo = static_cast<const CaloTemplate*>(m_gtCond0);
188 
189  CaloCondition caloCondition(corrCalo, m_uGtB,
190  0, 0, 0, 0); //BLW these are counters that don't seem to be used...perhaps remove.
191 
192  caloCondition.evaluateConditionStoreResult(bxEval);
193  reqObjResult = caloCondition.condLastResult();
194 
195  cond0Comb = (caloCondition.getCombinationsInCond());
196  cond0bx = bxEval + (corrCalo->condRelativeBx());
197  cndObjTypeVec[0] = (corrCalo->objectType())[0];
198 
199  if (m_verbosity) {
200  std::ostringstream myCout;
201  caloCondition.print(myCout);
202 
203  LogDebug("L1TGlobal") << myCout.str() << std::endl;
204  }
205  }
206  break;
207  case CondEnergySum: {
208 
209  corrEnergySum = static_cast<const EnergySumTemplate*>(m_gtCond0);
210  EnergySumCondition eSumCondition(corrEnergySum, m_uGtB);
211 
212  eSumCondition.evaluateConditionStoreResult(bxEval);
213  reqObjResult = eSumCondition.condLastResult();
214 
215  cond0Comb = (eSumCondition.getCombinationsInCond());
216  cond0bx = bxEval + (corrEnergySum->condRelativeBx());
217  cndObjTypeVec[0] = (corrEnergySum->objectType())[0];
218 
219  if (m_verbosity ) {
220  std::ostringstream myCout;
221  eSumCondition.print(myCout);
222 
223  LogDebug("L1TGlobal") << myCout.str() << std::endl;
224  }
225  }
226  break;
227  default: {
228  // should not arrive here, there are no correlation conditions defined for this object
229  return false;
230  }
231  break;
232  }
233 
234  // return if first subcondition is false
235  if (!reqObjResult) {
236  LogDebug("L1TGlobal")
237  << "\n First sub-condition false, second sub-condition not evaluated and not printed."
238  << std::endl;
239  return false;
240  }
241 
242  // second object
243  reqObjResult = false;
244 
245  switch (cond1Categ) {
246  case CondMuon: {
247  corrMuon = static_cast<const MuonTemplate*>(m_gtCond1);
248  MuCondition muCondition(corrMuon, m_uGtB,
249  0,0); //BLW these are counts that don't seem to be used...perhaps remove
250 
251  muCondition.evaluateConditionStoreResult(bxEval);
252  reqObjResult = muCondition.condLastResult();
253 
254  cond1Comb = (muCondition.getCombinationsInCond());
255  cond1bx = bxEval + (corrMuon->condRelativeBx());
256 
257  cndObjTypeVec[1] = (corrMuon->objectType())[0];
258 
259  if (m_verbosity) {
260  std::ostringstream myCout;
261  muCondition.print(myCout);
262 
263  LogDebug("L1TGlobal") << myCout.str() << std::endl;
264  }
265  }
266  break;
267  case CondCalo: {
268  corrCalo = static_cast<const CaloTemplate*>(m_gtCond1);
269  CaloCondition caloCondition(corrCalo, m_uGtB,
270  0, 0, 0, 0); //BLW these are counters that don't seem to be used...perhaps remove.
271 
272  caloCondition.evaluateConditionStoreResult(bxEval);
273  reqObjResult = caloCondition.condLastResult();
274 
275  cond1Comb = (caloCondition.getCombinationsInCond());
276  cond1bx = bxEval + (corrCalo->condRelativeBx());
277  cndObjTypeVec[1] = (corrCalo->objectType())[0];
278 
279  if (m_verbosity ) {
280  std::ostringstream myCout;
281  caloCondition.print(myCout);
282 
283  LogDebug("L1TGlobal") << myCout.str() << std::endl;
284  }
285 
286  }
287  break;
288  case CondEnergySum: {
289  corrEnergySum = static_cast<const EnergySumTemplate*>(m_gtCond1);
290 
291  EnergySumCondition eSumCondition(corrEnergySum, m_uGtB);
292 
293  eSumCondition.evaluateConditionStoreResult(bxEval);
294  reqObjResult = eSumCondition.condLastResult();
295 
296  cond1Comb = (eSumCondition.getCombinationsInCond());
297  cond1bx = bxEval + (corrEnergySum->condRelativeBx());
298  cndObjTypeVec[1] = (corrEnergySum->objectType())[0];
299 
300  if (m_verbosity) {
301  std::ostringstream myCout;
302  eSumCondition.print(myCout);
303 
304  LogDebug("L1TGlobal") << myCout.str() << std::endl;
305  }
306  }
307  break;
308  default: {
309  // should not arrive here, there are no correlation conditions defined for this object
310  return false;
311  }
312  break;
313  }
314 
315  // return if second sub-condition is false
316  if (!reqObjResult) {
317  return false;
318  } else {
319  LogDebug("L1TGlobal") << "\n"
320  << " Both sub-conditions true for object requirements."
321  << " Evaluate correlation requirements.\n" << std::endl;
322 
323  }
324 
325  // since we have two good legs get the correlation parameters
328 
329 
330  // vector to store the indices of the calorimeter objects
331  // from the combination evaluated in the condition
332  SingleCombInCond objectsInComb;
333  objectsInComb.reserve(nObjInCond);
334 
335  // clear the m_combinationsInCond vector
337 
338  // pointers to objects
339  const BXVector<const l1t::Muon*>* candMuVec = nullptr;
340  const BXVector<const l1t::L1Candidate*>* candCaloVec = nullptr;
341  const BXVector<const l1t::EtSum*>* candEtSumVec = nullptr;
342 
343  bool etSumCond = false;
344 
345  // make the conversions of the indices, depending on the combination of objects involved
346  // (via pair index)
347 
348  int phiIndex0 = 0;
349  double phi0Phy = 0.;
350  int phiIndex1 = 0;
351  double phi1Phy = 0.;
352 
353  int etaIndex0 = 0;
354  double eta0Phy = 0.;
355  int etaIndex1 = 0;
356  double eta1Phy = 0.;
357  int etaBin0 = 0;
358  int etaBin1 = 0;
359 
360  int etIndex0 = 0;
361  int etBin0 = 0;
362  double et0Phy = 0.;
363  int etIndex1 = 0;
364  int etBin1 = 0;
365  double et1Phy = 0.;
366 
367  int chrg0 = -1;
368  int chrg1 = -1;
369 
370 // Determine the number of phi bins to get cutoff at pi
371  int phiBound = 0;
372  if(cond0Categ == CondMuon || cond1Categ == CondMuon) {
374  //phiBound = par.phiBins.size()/2;
375  phiBound = (int)((par.phiMax - par.phiMin)/par.phiStep)/2;
376  } else {
377  //Assumes all calorimeter objects are on same phi scale
379  //phiBound = par.phiBins.size()/2;
380  phiBound = (int)((par.phiMax - par.phiMin)/par.phiStep)/2;
381  }
382  LogDebug("L1TGlobal") << "Phi Bound = " << phiBound << std::endl;
383 
384 
385 // Keep track of objects for LUTS
386  std::string lutObj0 = "NULL";
387  std::string lutObj1 = "NULL";
388 
389 
390  LogTrace("L1TGlobal")
391  << " Sub-condition 0: std::vector<SingleCombInCond> size: "
392  << (cond0Comb.size()) << std::endl;
393  LogTrace("L1TGlobal")
394  << " Sub-condition 1: std::vector<SingleCombInCond> size: "
395  << (cond1Comb.size()) << std::endl;
396 
397 
398  // loop over all combinations which produced individually "true" as Type1s
399  //
400  // BLW: Optimization issue: potentially making the same comparison twice
401  // if both legs are the same object type.
402  for (std::vector<SingleCombInCond>::const_iterator it0Comb =
403  cond0Comb.begin(); it0Comb != cond0Comb.end(); it0Comb++) {
404 
405  // Type1s: there is 1 object only, no need for a loop, index 0 should be OK in (*it0Comb)[0]
406  // ... but add protection to not crash
407  int obj0Index = -1;
408 
409  if (!(*it0Comb).empty()) {
410  obj0Index = (*it0Comb)[0];
411  } else {
412  LogTrace("L1TGlobal")
413  << "\n SingleCombInCond (*it0Comb).size() "
414  << ((*it0Comb).size()) << std::endl;
415  return false;
416  }
417 
418 // Collect the information on the first leg of the correlation
419  switch (cond0Categ) {
420  case CondMuon: {
421  lutObj0 = "MU";
422  candMuVec = m_uGtB->getCandL1Mu();
423  phiIndex0 = (candMuVec->at(cond0bx,obj0Index))->hwPhiAtVtx(); //(*candMuVec)[obj0Index]->phiIndex();
424  etaIndex0 = (candMuVec->at(cond0bx,obj0Index))->hwEtaAtVtx();
425  etIndex0 = (candMuVec->at(cond0bx,obj0Index))->hwPt();
426  chrg0 = (candMuVec->at(cond0bx,obj0Index))->hwCharge();
427  int etaBin0 = etaIndex0;
428  if(etaBin0<0) etaBin0 = m_gtScales->getMUScales().etaBins.size() + etaBin0; //twos complement
429 // LogDebug("L1TGlobal") << "Muon phi" << phiIndex0 << " eta " << etaIndex0 << " etaBin0 = " << etaBin0 << " et " << etIndex0 << std::endl;
430 
431  etBin0 = etIndex0;
432  int ssize = m_gtScales->getMUScales().etBins.size();
433  if (etBin0 >= ssize){
434  etBin0 = ssize-1;
435  LogTrace("L1TGlobal")
436  << "muon0 hw et" << etBin0 << " out of scale range. Setting to maximum.";
437  }
438 
439  // Determine Floating Pt numbers for floating point caluclation
440  std::pair<double, double> binEdges = m_gtScales->getMUScales().phiBins.at(phiIndex0);
441  phi0Phy = 0.5*(binEdges.second + binEdges.first);
442  binEdges = m_gtScales->getMUScales().etaBins.at(etaBin0);
443  eta0Phy = 0.5*(binEdges.second + binEdges.first);
444  binEdges = m_gtScales->getMUScales().etBins.at(etBin0);
445  et0Phy = 0.5*(binEdges.second + binEdges.first);
446 
447  LogDebug("L1TGlobal") << "Found all quantities for the muon 0" << std::endl;
448  }
449  break;
450 
451 // Calorimeter Objects (EG, Jet, Tau)
452  case CondCalo: {
453 
454  switch(cndObjTypeVec[0]) {
455  case gtEG: {
456  lutObj0 = "EG";
457  candCaloVec = m_uGtB->getCandL1EG();
458  phiIndex0 = (candCaloVec->at(cond0bx,obj0Index))->hwPhi();
459  etaIndex0 = (candCaloVec->at(cond0bx,obj0Index))->hwEta();
460  etIndex0 = (candCaloVec->at(cond0bx,obj0Index))->hwPt();
461  etaBin0 = etaIndex0;
462  if(etaBin0<0) etaBin0 = m_gtScales->getEGScales().etaBins.size() + etaBin0;
463 // LogDebug("L1TGlobal") << "EG0 phi" << phiIndex0 << " eta " << etaIndex0 << " etaBin0 = " << etaBin0 << " et " << etIndex0 << std::endl;
464 
465  etBin0 = etIndex0;
466  int ssize = m_gtScales->getEGScales().etBins.size();
467  if (etBin0 >= ssize){
468  etBin0 = ssize-1;
469  LogTrace("L1TGlobal")
470  << "EG0 hw et" << etBin0 << " out of scale range. Setting to maximum.";
471  }
472 
473  // Determine Floating Pt numbers for floating point caluclation
474  std::pair<double, double> binEdges = m_gtScales->getEGScales().phiBins.at(phiIndex0);
475  phi0Phy = 0.5*(binEdges.second + binEdges.first);
476  binEdges = m_gtScales->getEGScales().etaBins.at(etaBin0);
477  eta0Phy = 0.5*(binEdges.second + binEdges.first);
478  binEdges = m_gtScales->getEGScales().etBins[etBin0];
479  et0Phy = 0.5*(binEdges.second + binEdges.first);
480 
481  }
482  break;
483  case gtJet: {
484  lutObj0 = "JET";
485  candCaloVec = m_uGtB->getCandL1Jet();
486  phiIndex0 = (candCaloVec->at(cond0bx,obj0Index))->hwPhi();
487  etaIndex0 = (candCaloVec->at(cond0bx,obj0Index))->hwEta();
488  etIndex0 = (candCaloVec->at(cond0bx,obj0Index))->hwPt();
489  etaBin0 = etaIndex0;
490  if(etaBin0<0) etaBin0 = m_gtScales->getJETScales().etaBins.size() + etaBin0;
491 
492  etBin0 = etIndex0;
493  int ssize = m_gtScales->getJETScales().etBins.size();
494  if (etBin0 >= ssize){
495  //edm::LogWarning("L1TGlobal")
496  //<< "jet0 hw et" << etBin0 << " out of scale range. Setting to maximum.";
497  etBin0 = ssize-1;
498  }
499 
500  // Determine Floating Pt numbers for floating point caluclation
501  std::pair<double, double> binEdges = m_gtScales->getJETScales().phiBins.at(phiIndex0);
502  phi0Phy = 0.5*(binEdges.second + binEdges.first);
503  binEdges = m_gtScales->getJETScales().etaBins.at(etaBin0);
504  eta0Phy = 0.5*(binEdges.second + binEdges.first);
505  binEdges = m_gtScales->getJETScales().etBins.at(etBin0);
506  et0Phy = 0.5*(binEdges.second + binEdges.first);
507 
508  }
509  break;
510  case gtTau: {
511  candCaloVec = m_uGtB->getCandL1Tau();
512  phiIndex0 = (candCaloVec->at(cond0bx,obj0Index))->hwPhi();
513  etaIndex0 = (candCaloVec->at(cond0bx,obj0Index))->hwEta();
514  etIndex0 = (candCaloVec->at(cond0bx,obj0Index))->hwPt();
515  etaBin0 = etaIndex0;
516  if(etaBin0<0) etaBin0 = m_gtScales->getTAUScales().etaBins.size() + etaBin0;
517 
518  etBin0 = etIndex0;
519  int ssize = m_gtScales->getTAUScales().etBins.size();
520  if (etBin0 >= ssize){
521  etBin0 = ssize-1;
522  LogTrace("L1TGlobal")
523  << "tau0 hw et" << etBin0 << " out of scale range. Setting to maximum.";
524  }
525 
526 
527  // Determine Floating Pt numbers for floating point caluclation
528  std::pair<double, double> binEdges = m_gtScales->getTAUScales().phiBins.at(phiIndex0);
529  phi0Phy = 0.5*(binEdges.second + binEdges.first);
530  binEdges = m_gtScales->getTAUScales().etaBins.at(etaBin0);
531  eta0Phy = 0.5*(binEdges.second + binEdges.first);
532  binEdges = m_gtScales->getTAUScales().etBins.at(etBin0);
533  et0Phy = 0.5*(binEdges.second + binEdges.first);
534  lutObj0 = "TAU";
535  }
536  break;
537  default: {
538  }
539  break;
540  } //end switch on calo type.
541 
542  //If needed convert calo scales to muon scales for comparison
543  if(convertCaloScales) {
544  std::string lutName = lutObj0;
545  lutName += "-MU";
546  long long tst = m_gtScales->getLUT_CalMuEta(lutName,etaBin0);
547  LogDebug("L1TGlobal") << lutName <<" EtaCal = " << etaIndex0 << " etaBin0 = " << etaBin0 << " EtaMu = " << tst << std::endl;
548  etaIndex0 = tst;
549 
550 
551  tst = m_gtScales->getLUT_CalMuPhi(lutName,phiIndex0);
552  LogDebug("L1TGlobal") << lutName <<" PhiCal = " << phiIndex0 << " PhiMu = " << tst << std::endl;
553  phiIndex0 = tst;
554 
555  }
556 
557  }
558  break;
559 
560 // Energy Sums
561  case CondEnergySum: {
562 
563  etSumCond = true;
564  //Stupid mapping between enum types for energy sums.
566  switch( cndObjTypeVec[0] ){
567  case gtETM:
569  lutObj0 = "ETM";
570  break;
571  case gtETT:
573  lutObj0 = "ETT";
574  break;
575  case gtETTem:
577  lutObj0 = "ETTem"; //should this be just ETT (share LUTs?) Can't be used for CorrCond anyway since now directional information
578  break;
579  case gtHTM:
581  lutObj0 = "HTM";
582  break;
583  case gtHTT:
585  lutObj0 = "HTT";
586  break;
587  case gtETMHF:
589  lutObj0 = "ETMHF";
590  break;
591  case gtMinBiasHFP0:
592  case gtMinBiasHFM0:
593  case gtMinBiasHFP1:
594  case gtMinBiasHFM1:
596  lutObj0 = "MinBias"; //??Fix?? Not a valid LUT type Can't be used for CorrCond anyway since now directional information
597  break;
598  default:
599  edm::LogError("L1TGlobal")
600  << "\n Error: "
601  << "Unmatched object type from template to EtSumType, cndObjTypeVec[0] = "
602  << cndObjTypeVec[0]
603  << std::endl;
605  break;
606  }
607 
608  candEtSumVec = m_uGtB->getCandL1EtSum();
609 
610  for( int iEtSum=0; iEtSum < (int)candEtSumVec->size(cond0bx); iEtSum++) {
611  if( (candEtSumVec->at(cond0bx,iEtSum))->getType() == type ) {
612  phiIndex0 = (candEtSumVec->at(cond0bx,iEtSum))->hwPhi();
613  etaIndex0 = (candEtSumVec->at(cond0bx,iEtSum))->hwEta();
614  etIndex0 = (candEtSumVec->at(cond0bx,iEtSum))->hwPt();
615 
616 
617 
618 
619 
620 
621  // Get the floating point numbers
622  if(cndObjTypeVec[0] == gtETM ) {
623  std::pair<double, double> binEdges = m_gtScales->getETMScales().phiBins.at(phiIndex0);
624  phi0Phy = 0.5*(binEdges.second + binEdges.first);
625  eta0Phy = 0.; //No Eta for Energy Sums
626 
627  etBin0 = etIndex0;
628  int ssize = m_gtScales->getETMScales().etBins.size();
629  assert(ssize > 0);
630  if (etBin0 >= ssize){ etBin0 = ssize-1; }
631 
632  binEdges = m_gtScales->getETMScales().etBins.at(etBin0);
633  et0Phy = 0.5*(binEdges.second + binEdges.first);
634  } else if (cndObjTypeVec[0] == gtHTM) {
635  std::pair<double, double> binEdges = m_gtScales->getHTMScales().phiBins.at(phiIndex0);
636  phi0Phy = 0.5*(binEdges.second + binEdges.first);
637  eta0Phy = 0.; //No Eta for Energy Sums
638 
639  etBin0 = etIndex0;
640  int ssize = m_gtScales->getHTMScales().etBins.size();
641  assert(ssize > 0);
642  if (etBin0 >= ssize){ etBin0 = ssize-1; }
643 
644  binEdges = m_gtScales->getHTMScales().etBins.at(etBin0);
645  et0Phy = 0.5*(binEdges.second + binEdges.first);
646  } else if (cndObjTypeVec[0] == gtETMHF) {
647  std::pair<double, double> binEdges = m_gtScales->getETMHFScales().phiBins.at(phiIndex0);
648  phi0Phy = 0.5*(binEdges.second + binEdges.first);
649  eta0Phy = 0.; //No Eta for Energy Sums
650 
651  etBin0 = etIndex0;
652  int ssize = m_gtScales->getETMHFScales().etBins.size();
653  assert(ssize > 0);
654  if (etBin0 >= ssize){ etBin0 = ssize-1; }
655 
656  binEdges = m_gtScales->getETMHFScales().etBins.at(etBin0);
657  et0Phy = 0.5*(binEdges.second + binEdges.first);
658  }
659 
660 
661  //If needed convert calo scales to muon scales for comparison (only phi for energy sums)
662  if(convertCaloScales) {
663 
664  std::string lutName = lutObj0;
665  lutName += "-MU";
666  long long tst = m_gtScales->getLUT_CalMuPhi(lutName,phiIndex0);
667  LogDebug("L1TGlobal") << lutName <<" PhiCal = " << phiIndex0 << " PhiMu = " << tst << std::endl;
668  phiIndex0 = tst;
669 
670  }
671 
672  } //check it is the EtSum we want
673  } // loop over Etsums
674 
675  }
676  break;
677 
678 
679  default: {
680  // should not arrive here, there are no correlation conditions defined for this object
681  LogDebug("L1TGlobal") << "Error could not find the Cond Category for Leg 0" << std::endl;
682  return false;
683  }
684  break;
685  } //end switch on first leg type
686 
687 // Now loop over the second leg to get its information
688  for (std::vector<SingleCombInCond>::const_iterator it1Comb =
689  cond1Comb.begin(); it1Comb != cond1Comb.end(); it1Comb++) {
690 
691  LogDebug("L1TGlobal") << "Looking at second Condition" << std::endl;
692  // Type1s: there is 1 object only, no need for a loop (*it1Comb)[0]
693  // ... but add protection to not crash
694  int obj1Index = -1;
695 
696  if (!(*it1Comb).empty()) {
697  obj1Index = (*it1Comb)[0];
698  } else {
699  LogTrace("L1TGlobal")
700  << "\n SingleCombInCond (*it1Comb).size() "
701  << ((*it1Comb).size()) << std::endl;
702  return false;
703  }
704 
705  //If we are dealing with the same object type avoid the two legs
706  // either being the same object
707  if( cndObjTypeVec[0] == cndObjTypeVec[1] &&
708  obj0Index == obj1Index &&
709  cond0bx == cond1bx) {
710 
711  LogDebug("L1TGlobal") << "Corr Condition looking at same leg...skip" << std::endl;
712  continue;
713  }
714 
715  switch (cond1Categ) {
716  case CondMuon: {
717  lutObj1 = "MU";
718  candMuVec = m_uGtB->getCandL1Mu();
719  phiIndex1 = (candMuVec->at(cond1bx,obj1Index))->hwPhiAtVtx(); //(*candMuVec)[obj0Index]->phiIndex();
720  etaIndex1 = (candMuVec->at(cond1bx,obj1Index))->hwEtaAtVtx();
721  etIndex1 = (candMuVec->at(cond1bx,obj1Index))->hwPt();
722  chrg1 = (candMuVec->at(cond1bx,obj1Index))->hwCharge();
723  etaBin1 = etaIndex1;
724  if(etaBin1<0) etaBin1 = m_gtScales->getMUScales().etaBins.size() + etaBin1;
725 // LogDebug("L1TGlobal") << "Muon phi" << phiIndex1 << " eta " << etaIndex1 << " etaBin1 = " << etaBin1 << " et " << etIndex1 << std::endl;
726 
727  etBin1 = etIndex1;
728  int ssize = m_gtScales->getMUScales().etBins.size();
729  if (etBin1 >= ssize){
730  LogTrace("L1TGlobal")
731  << "muon2 hw et" << etBin1 << " out of scale range. Setting to maximum.";
732  etBin1 = ssize-1;
733  }
734 
735  // Determine Floating Pt numbers for floating point caluclation
736  std::pair<double, double> binEdges = m_gtScales->getMUScales().phiBins.at(phiIndex1);
737  phi1Phy = 0.5*(binEdges.second + binEdges.first);
738  binEdges = m_gtScales->getMUScales().etaBins.at(etaBin1);
739  eta1Phy = 0.5*(binEdges.second + binEdges.first);
740  binEdges = m_gtScales->getMUScales().etBins.at(etBin1);
741  et1Phy = 0.5*(binEdges.second + binEdges.first);
742 
743  }
744  break;
745  case CondCalo: {
746  switch(cndObjTypeVec[1]) {
747  case gtEG: {
748  candCaloVec = m_uGtB->getCandL1EG();
749  phiIndex1 = (candCaloVec->at(cond1bx,obj1Index))->hwPhi();
750  etaIndex1 = (candCaloVec->at(cond1bx,obj1Index))->hwEta();
751  etIndex1 = (candCaloVec->at(cond1bx,obj1Index))->hwPt();
752  etaBin1 = etaIndex1;
753  if(etaBin1<0) etaBin1 = m_gtScales->getEGScales().etaBins.size() + etaBin1;
754 
755  etBin1 = etIndex1;
756  int ssize = m_gtScales->getEGScales().etBins.size();
757  if (etBin1 >= ssize){
758  LogTrace("L1TGlobal")
759  << "EG1 hw et" << etBin1 << " out of scale range. Setting to maximum.";
760  etBin1 = ssize-1;
761  }
762 
763  // Determine Floating Pt numbers for floating point caluclation
764  std::pair<double, double> binEdges = m_gtScales->getEGScales().phiBins.at(phiIndex1);
765  phi1Phy = 0.5*(binEdges.second + binEdges.first);
766  binEdges = m_gtScales->getEGScales().etaBins.at(etaBin1);
767  eta1Phy = 0.5*(binEdges.second + binEdges.first);
768  binEdges = m_gtScales->getEGScales().etBins.at(etBin1);
769  et1Phy = 0.5*(binEdges.second + binEdges.first);
770  lutObj1 = "EG";
771  }
772  break;
773  case gtJet: {
774  candCaloVec = m_uGtB->getCandL1Jet();
775  phiIndex1 = (candCaloVec->at(cond1bx,obj1Index))->hwPhi();
776  etaIndex1 = (candCaloVec->at(cond1bx,obj1Index))->hwEta();
777  etIndex1 = (candCaloVec->at(cond1bx,obj1Index))->hwPt();
778  etaBin1 = etaIndex1;
779  if(etaBin1<0) etaBin1 = m_gtScales->getJETScales().etaBins.size() + etaBin1;
780 
781  etBin1 = etIndex1;
782  int ssize = m_gtScales->getJETScales().etBins.size();
783  assert(ssize);
784  if (etBin1 >= ssize){
785  //edm::LogWarning("L1TGlobal")
786  //<< "jet2 hw et" << etBin1 << " out of scale range. Setting to maximum.";
787  etBin1 = ssize-1;
788  }
789 
790  // Determine Floating Pt numbers for floating point caluclation
791  std::pair<double, double> binEdges = m_gtScales->getJETScales().phiBins.at(phiIndex1);
792  phi1Phy = 0.5*(binEdges.second + binEdges.first);
793  binEdges = m_gtScales->getJETScales().etaBins.at(etaBin1);
794  eta1Phy = 0.5*(binEdges.second + binEdges.first);
795  //CRASHES HERE:
796  binEdges = m_gtScales->getJETScales().etBins.at(etBin1);
797  et1Phy = 0.5*(binEdges.second + binEdges.first);
798  lutObj1 = "JET";
799  }
800  break;
801  case gtTau: {
802  candCaloVec = m_uGtB->getCandL1Tau();
803  phiIndex1 = (candCaloVec->at(cond1bx,obj1Index))->hwPhi();
804  etaIndex1 = (candCaloVec->at(cond1bx,obj1Index))->hwEta();
805  etIndex1 = (candCaloVec->at(cond1bx,obj1Index))->hwPt();
806  etaBin1 = etaIndex1;
807  if(etaBin1<0) etaBin1 = m_gtScales->getTAUScales().etaBins.size() + etaBin1;
808 
809  etBin1 = etIndex1;
810  int ssize = m_gtScales->getTAUScales().etBins.size();
811  if (etBin1 >= ssize){
812  LogTrace("L1TGlobal")
813  << "tau2 hw et" << etBin1 << " out of scale range. Setting to maximum.";
814  etBin1 = ssize-1;
815  }
816 
817  // Determine Floating Pt numbers for floating point caluclation
818  std::pair<double, double> binEdges = m_gtScales->getTAUScales().phiBins.at(phiIndex1);
819  phi1Phy = 0.5*(binEdges.second + binEdges.first);
820  binEdges = m_gtScales->getTAUScales().etaBins.at(etaBin1);
821  eta1Phy = 0.5*(binEdges.second + binEdges.first);
822  binEdges = m_gtScales->getTAUScales().etBins.at(etBin1);
823  et1Phy = 0.5*(binEdges.second + binEdges.first);
824  lutObj1 = "TAU";
825  }
826  break;
827  default: {
828  }
829  break;
830  } //end switch on calo type.
831 
832 
833  //If needed convert calo scales to muon scales for comparison
834  if(convertCaloScales) {
835 
836  std::string lutName = lutObj1;
837  lutName += "-MU";
838  long long tst = m_gtScales->getLUT_CalMuEta(lutName,etaBin1);
839  LogDebug("L1TGlobal") << lutName <<" EtaCal = " << etaIndex1 << " EtaMu = " << tst << std::endl;
840  etaIndex1 = tst;
841 
842 
843  tst = m_gtScales->getLUT_CalMuPhi(lutName,phiIndex1);
844  LogDebug("L1TGlobal") << lutName <<" PhiCal = " << phiIndex1 << " PhiMu = " << tst << std::endl;
845  phiIndex1 = tst;
846 
847  }
848 
849 
850  }
851  break;
852  case CondEnergySum: {
853 
854  LogDebug("L1TGlobal") << "Looking at second Condition as Energy Sum: " << cndObjTypeVec[1] << std::endl;
855  etSumCond = true;
856 
857  //Stupid mapping between enum types for energy sums.
859  switch( cndObjTypeVec[1] ){
860  case gtETM:
862  lutObj1 = "ETM";
863  break;
864  case gtETT:
866  lutObj1 = "ETT";
867  break;
868  case gtETTem:
870  lutObj1 = "ETTem";
871  break;
872  case gtHTM:
874  lutObj1 = "HTM";
875  break;
876  case gtHTT:
878  lutObj1 = "HTT";
879  break;
880  case gtETMHF:
882  lutObj1 = "ETMHF";
883  break;
884  case gtMinBiasHFP0:
885  case gtMinBiasHFM0:
886  case gtMinBiasHFP1:
887  case gtMinBiasHFM1:
889  lutObj1 = "MinBias";
890  break;
891  default:
892  edm::LogError("L1TGlobal")
893  << "\n Error: "
894  << "Unmatched object type from template to EtSumType, cndObjTypeVec[1] = "
895  << cndObjTypeVec[1]
896  << std::endl;
898  break;
899  }
900 
901 
902  candEtSumVec = m_uGtB->getCandL1EtSum();
903 
904  LogDebug("L1TGlobal") << "obj " << lutObj1 << " Vector Size " << candEtSumVec->size(cond1bx) << std::endl;
905  for( int iEtSum=0; iEtSum < (int)candEtSumVec->size(cond1bx); iEtSum++) {
906  if( (candEtSumVec->at(cond1bx,iEtSum))->getType() == type ) {
907  phiIndex1 = (candEtSumVec->at(cond1bx,iEtSum))->hwPhi();
908  etaIndex1 = (candEtSumVec->at(cond1bx,iEtSum))->hwEta();
909  etIndex1 = (candEtSumVec->at(cond1bx,iEtSum))->hwPt();
910 
911  // Determine Floating Pt numbers for floating point caluclation
912 
913  if(cndObjTypeVec[1] == gtETM) {
914  std::pair<double, double> binEdges = m_gtScales->getETMScales().phiBins.at(phiIndex1);
915  phi1Phy = 0.5*(binEdges.second + binEdges.first);
916  eta1Phy = 0.; //No Eta for Energy Sums
917 
918  etBin1 = etIndex1;
919  int ssize = m_gtScales->getETMScales().etBins.size();
920  assert(ssize > 0);
921  if (etBin1 >= ssize){ etBin1 = ssize-1; }
922 
923  binEdges = m_gtScales->getETMScales().etBins.at(etBin1);
924  et1Phy = 0.5*(binEdges.second + binEdges.first);
925  } else if(cndObjTypeVec[1] == gtHTM) {
926  std::pair<double, double> binEdges = m_gtScales->getHTMScales().phiBins.at(phiIndex1);
927  phi1Phy = 0.5*(binEdges.second + binEdges.first);
928  eta1Phy = 0.; //No Eta for Energy Sums
929 
930  etBin1 = etIndex1;
931  int ssize = m_gtScales->getHTMScales().etBins.size();
932  assert(ssize > 0);
933  if (etBin1 >= ssize){ etBin1 = ssize-1; }
934 
935  binEdges = m_gtScales->getHTMScales().etBins.at(etBin1);
936  et1Phy = 0.5*(binEdges.second + binEdges.first);
937  } else if(cndObjTypeVec[1] == gtETMHF) {
938  std::pair<double, double> binEdges = m_gtScales->getETMHFScales().phiBins.at(phiIndex1);
939  phi1Phy = 0.5*(binEdges.second + binEdges.first);
940  eta1Phy = 0.; //No Eta for Energy Sums
941 
942  etBin1 = etIndex1;
943  int ssize = m_gtScales->getETMHFScales().etBins.size();
944  assert(ssize > 0);
945  if (etBin1 >= ssize){ etBin1 = ssize-1; }
946 
947  binEdges = m_gtScales->getETMHFScales().etBins.at(etBin1);
948  et1Phy = 0.5*(binEdges.second + binEdges.first);
949  }
950 
951 
952  //If needed convert calo scales to muon scales for comparison (only phi for energy sums)
953  if(convertCaloScales) {
954 
955  std::string lutName = lutObj1;
956  lutName += "-MU";
957  long long tst = m_gtScales->getLUT_CalMuPhi(lutName,phiIndex1);
958  LogDebug("L1TGlobal") << lutName <<" PhiCal = " << phiIndex1 << " PhiMu = " << tst << std::endl;
959  phiIndex1 = tst;
960 
961  }
962 
963 
964  } //check it is the EtSum we want
965  } // loop over Etsums
966 
967  }
968  break;
969  default: {
970  // should not arrive here, there are no correlation conditions defined for this object
971  LogDebug("L1TGlobal") << "Error could not find the Cond Category for Leg 0" << std::endl;
972  return false;
973  }
974  break;
975  } //end switch on second leg
976 
977  if (m_verbosity) {
978  LogDebug("L1TGlobal") << " Correlation pair ["
979  << l1TGtObjectEnumToString(cndObjTypeVec[0]) << ", "
980  << l1TGtObjectEnumToString(cndObjTypeVec[1])
981  << "] with collection indices [" << obj0Index << ", "
982  << obj1Index << "] " << " has: \n"
983  << " Et value = ["<< etIndex0 << ", " << etIndex1 << "]\n"
984  << " phi indices = ["<< phiIndex0 << ", " << phiIndex1 << "]\n"
985  << " eta indices = ["<< etaIndex0 << ", " << etaIndex1 << "]\n"
986  << " chrg = ["<< chrg0 << ", " << chrg1 << "]\n"<< std::endl;
987  }
988 
989 
990 // Now perform the desired correlation on these two objects. Assume true until we find a contradition
991  bool reqResult = true;
992 
993  // clear the indices in the combination
994  objectsInComb.clear();
995 
996  objectsInComb.push_back(obj0Index);
997  objectsInComb.push_back(obj1Index);
998 
999  // if we get here all checks were successful for this combination
1000  // set the general result for evaluateCondition to "true"
1001 
1002 
1003 // These all require some delta eta and phi calculations. Do them first...for now real calculation but need to
1004 // revise this to line up with firmware calculations.
1005  double deltaPhiPhy = fabs(phi1Phy - phi0Phy);
1006  if(deltaPhiPhy> M_PI) deltaPhiPhy = 2.*M_PI - deltaPhiPhy;
1007  double deltaEtaPhy = fabs(eta1Phy - eta0Phy);
1008 
1009 
1010 // Determine the integer based delta eta and delta phi
1011  int deltaPhiFW = abs(phiIndex0 - phiIndex1);
1012  if(deltaPhiFW>=phiBound) deltaPhiFW = 2*phiBound - deltaPhiFW;
1013  std::string lutName = lutObj0;
1014  lutName += "-";
1015  lutName += lutObj1;
1016  long long deltaPhiLUT = m_gtScales->getLUT_DeltaPhi(lutName,deltaPhiFW);
1017  unsigned int precDeltaPhiLUT = m_gtScales->getPrec_DeltaPhi(lutName);
1018 
1019  int deltaEtaFW = abs(etaIndex0 - etaIndex1);
1020  long long deltaEtaLUT = 0;
1021  unsigned int precDeltaEtaLUT = 0;
1022  if(!etSumCond) {
1023  deltaEtaLUT = m_gtScales->getLUT_DeltaEta(lutName,deltaEtaFW);
1024  precDeltaEtaLUT = m_gtScales->getPrec_DeltaEta(lutName);
1025  }
1026 
1027  //
1028  LogDebug("L1TGlobal") << "Obj0 phiFW = " << phiIndex0 << " Obj1 phiFW = " << phiIndex1 << "\n"
1029  << " DeltaPhiFW = " << deltaPhiFW << "\n"
1030  << " LUT Name = " << lutName << " Prec = " << precDeltaPhiLUT << " DeltaPhiLUT = " << deltaPhiLUT << "\n"
1031  << "Obj0 etaFW = " << etaIndex0 << " Obj1 etaFW = " << etaIndex1 << "\n"
1032  << " DeltaEtaFW = " << deltaEtaFW << "\n"
1033  << " LUT Name = " << lutName << " Prec = " << precDeltaEtaLUT << " DeltaEtaLUT = " << deltaEtaLUT << std::endl;
1034 
1035 
1036  // If there is a delta eta, check it.
1037  if(corrPar.corrCutType & 0x1) {
1038 
1039  unsigned int preShift = precDeltaEtaLUT - corrPar.precEtaCut;
1040  LogDebug("L1TGlobal") << " Testing Delta Eta Cut (" << lutObj0 << "," << lutObj1 << ") [" << (long long)(corrPar.minEtaCutValue*pow(10,preShift))
1041  << "," << (long long)(corrPar.maxEtaCutValue*pow(10,preShift)) << "] with precision = " << corrPar.precEtaCut <<"\n"
1042  << " deltaEtaLUT = " << deltaEtaLUT << "\n"
1043  << " Precision Shift = " << preShift << "\n"
1044  << " deltaEta (shift)= " << (deltaEtaLUT/pow(10,preShift+corrPar.precEtaCut)) << "\n"
1045  << " deltaEtaPhy = " << deltaEtaPhy << std::endl;
1046 
1047  //if(preShift>0) deltaEtaLUT /= pow(10,preShift);
1048  if( deltaEtaLUT >= (long long)(corrPar.minEtaCutValue*pow(10,preShift)) &&
1049  deltaEtaLUT <= (long long)(corrPar.maxEtaCutValue*pow(10,preShift)) ) {
1050 
1051  LogDebug("L1TGlobal") << " Passed Delta Eta Cut [" << (long long)(corrPar.minEtaCutValue*pow(10,preShift))
1052  << "," << (long long)(corrPar.maxEtaCutValue*pow(10,preShift)) << "]" << std::endl;
1053 
1054  } else {
1055 
1056  LogDebug("L1TGlobal") << " Failed Delta Eta Cut [" << (long long)(corrPar.minEtaCutValue*pow(10,preShift))
1057  << "," << (long long)(corrPar.maxEtaCutValue*pow(10,preShift)) << "]" << std::endl;
1058  reqResult = false;
1059  }
1060  }
1061 
1062  //if there is a delta phi check it.
1063  if(corrPar.corrCutType & 0x2) {
1064 
1065  unsigned int preShift = precDeltaPhiLUT - corrPar.precPhiCut;
1066  LogDebug("L1TGlobal") << " Testing Delta Phi Cut (" << lutObj0 << "," << lutObj1 << ") [" << (long long)(corrPar.minPhiCutValue*pow(10,preShift))
1067  << "," << (long long)(corrPar.maxPhiCutValue*pow(10,preShift)) << "] with precision = " << corrPar.precPhiCut <<"\n"
1068  << " deltaPhiLUT = " << deltaPhiLUT << "\n"
1069  << " Precision Shift = " << preShift << "\n"
1070  << " deltaPhi (shift)= " << (deltaPhiLUT/pow(10,preShift+corrPar.precPhiCut)) << "\n"
1071  << " deltaPhiPhy = " << deltaPhiPhy << std::endl;
1072 
1073  //if(preShift>0) deltaPhiLUT /= pow(10,preShift);
1074  if( deltaPhiLUT >= (long long)(corrPar.minPhiCutValue*pow(10,preShift)) &&
1075  deltaPhiLUT <= (long long)(corrPar.maxPhiCutValue*pow(10,preShift)) ) {
1076 
1077  LogDebug("L1TGlobal") << " Passed Delta Phi Cut [" << (long long)(corrPar.minPhiCutValue*pow(10,preShift))
1078  << "," << (long long)(corrPar.maxPhiCutValue*pow(10,preShift)) << "]" << std::endl;
1079 
1080  } else {
1081 
1082  LogDebug("L1TGlobal") << " Failed Delta Phi Cut [" << (long long)(corrPar.minPhiCutValue*pow(10,preShift))
1083  << "," << (long long)(corrPar.maxPhiCutValue*pow(10,preShift)) << "]" << std::endl;
1084  reqResult = false;
1085  }
1086  }
1087 
1088 
1089  if(corrPar.corrCutType & 0x4) {
1090 
1091  //Assumes Delta Eta and Delta Phi LUTs have the same precision
1092  unsigned int preShift = 2*precDeltaPhiLUT - corrPar.precDRCut;
1093  double deltaRSqPhy = deltaPhiPhy*deltaPhiPhy + deltaEtaPhy*deltaEtaPhy;
1094  long long deltaRSq = deltaEtaLUT*deltaEtaLUT + deltaPhiLUT*deltaPhiLUT;
1095 
1096  LogDebug("L1TGlobal") << " Testing Delta R Cut (" << lutObj0 << "," << lutObj1 << ") [" << (long long)(corrPar.minDRCutValue*pow(10,preShift))
1097  << "," << (long long)(corrPar.maxDRCutValue*pow(10,preShift)) << "] with precision = " << corrPar.precDRCut <<"\n"
1098  << " deltaPhiLUT = " << deltaPhiLUT << "\n"
1099  << " deltaEtaLUT = " << deltaEtaLUT << "\n"
1100  << " deltaRSqLUT = " << deltaRSq << "\n"
1101  << " Precision Shift = " << preShift << "\n"
1102  << " deltaRSqLUT (shift)= " << (deltaRSq/pow(10,preShift+corrPar.precDRCut)) << "\n"
1103  << " deltaRSqPhy = " << deltaRSqPhy << std::endl;
1104 
1105  //if(preShift>0) deltaRSq /= pow(10,preShift);
1106  if( deltaRSq >= (long long)(corrPar.minDRCutValue*pow(10,preShift)) &&
1107  deltaRSq <= (long long)(corrPar.maxDRCutValue*pow(10,preShift)) ) {
1108 
1109  LogDebug("L1TGlobal") << " Passed Delta R Cut [" << (long long)(corrPar.minDRCutValue*pow(10,preShift))
1110  << "," << (long long)(corrPar.maxDRCutValue*pow(10,preShift)) << "]" << deltaRSq << std::endl;
1111 
1112  } else {
1113 
1114  LogDebug("L1TGlobal") << " Failed Delta R Cut [" << (int)(corrPar.minDRCutValue*pow(10,preShift))
1115  << "," << (long long)(corrPar.maxDRCutValue*pow(10,preShift)) << "]" << deltaRSq << std::endl;
1116  reqResult = false;
1117  }
1118  }
1119 
1120  if(corrPar.corrCutType & 0x20) {
1121  // Two body pt: pt^2 = pt1^2+pt2^2+2*pt1*pt2*(cos(phi1)*cos(phi2)+sin(phi1)*sin(phi2)).
1122 
1123  LogDebug("L1TGlobal") << " corrPar.corrCutType: " << corrPar.corrCutType<< "\n";
1124 
1125  //calculate math sins and cosines for debugging
1126  double cosPhi1Phy = cos(phi0Phy);
1127  double sinPhi1Phy = sin(phi0Phy);
1128  double cosPhi2Phy = cos(phi1Phy);
1129  double sinPhi2Phy = sin(phi1Phy);
1130 
1131  double tbptSqPhy = et0Phy*et0Phy + et1Phy*et1Phy + 2*et0Phy*et1Phy*(cosPhi1Phy*cosPhi2Phy + sinPhi1Phy*sinPhi2Phy);
1132  // get values from LUT's
1133 
1134  const std::string& lutName0 = lutObj0;
1135  unsigned int precCosLUT0 = m_gtScales->getPrec_Cos(lutName0);
1136  unsigned int precSinLUT0 = m_gtScales->getPrec_Sin(lutName0);
1137 
1138  const std::string& lutName1 = lutObj1;
1139  unsigned int precCosLUT1 = m_gtScales->getPrec_Cos(lutName1);
1140  unsigned int precSinLUT1 = m_gtScales->getPrec_Sin(lutName1);
1141 
1142  if(precCosLUT0 - precCosLUT1 != 0) LogDebug("L1TGlobal") << "Warning: Cos LUTs for TwoBodyPt on different Precision" << std::endl;
1143  if(precSinLUT0 - precSinLUT1 != 0) LogDebug("L1TGlobal") << "Warning: Sin LUTs for TwoBodyPt on different Precision" << std::endl;
1144  if(precSinLUT0 - precCosLUT1 != 0) LogDebug("L1TGlobal") << "Warning: Sin and Cos LUTs for TwoBodyPt on different Precision" << std::endl;
1145  if(precSinLUT1 - precCosLUT0 != 0) LogDebug("L1TGlobal") << "Warning: Sin and Cos LUTs for TwoBodyPt on different Precision" << std::endl;
1146 
1147 
1148  long long cosPhi1LUT = m_gtScales->getLUT_Cos(lutName0,phiIndex0);
1149  long long sinPhi1LUT = m_gtScales->getLUT_Sin(lutName0,phiIndex0);
1150 
1151  long long cosPhi2LUT = m_gtScales->getLUT_Cos(lutName1,phiIndex1);
1152  long long sinPhi2LUT = m_gtScales->getLUT_Sin(lutName1,phiIndex1);
1153 
1154  // now get pt LUTs
1155  std::string lutName = lutObj0;
1156  lutName += "-ET";
1157  long long ptObj0 = m_gtScales->getLUT_Pt("TwoBody_" + lutName,etIndex0);
1158  unsigned int precPtLUTObj0 = m_gtScales->getPrec_Pt("TwoBody_" + lutName);
1159 
1160  lutName = lutObj1;
1161  lutName += "-ET";
1162  long long ptObj1 = m_gtScales->getLUT_Pt("TwoBody_" + lutName,etIndex1);
1163  unsigned int precPtLUTObj1 = m_gtScales->getPrec_Pt("TwoBody_" + lutName);
1164 
1165  LogTrace("L1TGlobal") << " TBPT Trig precisions:\t " << precCosLUT0 << "\t" << precCosLUT1 << "\t" << precSinLUT0 << "\t" << precSinLUT1;
1166  LogTrace("L1TGlobal") << " TBPT Pt precisions:\t " << precPtLUTObj0 << "\t" << precPtLUTObj1;
1167  LogTrace("L1TGlobal") << " TBPT Pt cut:\t " << corrPar.minTBPTCutValue << "\tPrecTBPTCut\t" << corrPar.precTBPTCut ;
1168  LogTrace("L1TGlobal") << " TBPT Pt1*Pt1 -- Phys:\t " << et0Phy*et0Phy << "\tHW:\t" << ptObj0*ptObj0*(pow(10,6));
1169  LogTrace("L1TGlobal") << " TBPT Pt2*Pt2 -- Phys:\t " << et1Phy*et1Phy << "\tHW:\t" << ptObj1*ptObj1*(pow(10,6));
1170  LogTrace("L1TGlobal") << " TBPT 2Pt1*Pt2 -- Phys:\t " << 2*et0Phy*et1Phy << "\tHW:\t" << 2*(ptObj0*pow(10,0))*(ptObj1*pow(10,0));
1171  LogTrace("L1TGlobal") << " TBPT Trig -- Phys:\t " << cosPhi1Phy*cosPhi2Phy + sinPhi1Phy*sinPhi2Phy << "\tHW:\t" << cosPhi1LUT*cosPhi2LUT + sinPhi1LUT*sinPhi2LUT;
1172 
1173  //double tbptSqPhy = et0Phy*et0Phy + et1Phy*et1Phy + 2*et0Phy*et1Phy*(cosPhi1Phy*cosPhi2Phy + sinPhi1Phy*sinPhi2Phy);
1174  long long tbptSqHW =
1175  ptObj0*ptObj0*(pow(10,2*precCosLUT0)) +
1176  ptObj1*ptObj1*(pow(10,2*precCosLUT0)) +
1177  2*ptObj0*ptObj1*(cosPhi1LUT*cosPhi2LUT + sinPhi1LUT*sinPhi2LUT);
1178 
1179  unsigned int preShift = precPtLUTObj0 + precPtLUTObj1 + 2*precCosLUT0;
1180 
1181  LogTrace("L1TGlobal") << "TBPT Result -- Phys: " << tbptSqPhy << "\tHW: " << tbptSqHW << "\tShifted\t" << tbptSqHW/pow(10,preShift) << std::endl;
1182 
1183  preShift=preShift - corrPar.precTBPTCut;
1184 
1185 
1186  LogDebug("L1TGlobal") << " Testing Two Body Pt Cut (" << lutObj0 << "," << lutObj1
1187  << ") [" << (long long)(corrPar.minTBPTCutValue*pow(10,preShift))
1188  << "," << (long long)(corrPar.maxTBPTCutValue*pow(10,preShift)) << "] with precision = " << corrPar.precTBPTCut <<"\n"
1189  << " etIndex0 = " << etIndex0 << " pt0LUT = " << ptObj0 << " PhyEt0 = " << et0Phy << "\n"
1190  << " etIndex1 = " << etIndex1 << " pt1LUT = " << ptObj1 << " PhyEt1 = " << et1Phy <<"\n"
1191  << " Precision Shift = " << preShift << "\n"
1192  << " Sin(phi1): LUT/Phys\t " << sinPhi1LUT << " / " << sinPhi1Phy << "\n"
1193  << " Sin(phi2): LUT/Phys\t " << sinPhi2LUT << " / " << sinPhi2Phy << "\n"
1194  << " Cos(phi1): LUT/Phys\t " << cosPhi1LUT << " / " << cosPhi1Phy << "\n"
1195  << " Cos(phi2): LUT/Phys\t " << cosPhi2LUT << " / " << cosPhi2Phy << "\n"
1196 
1197  // << " deltaPhiLUT = " << deltaPhiLUT << "\n"
1198  // << " deltaEtaLUT = " << deltaEtaLUT << "\n"
1199  // << " deltaRSqLUT = " << deltaRSq << "\n"
1200  // << " Precision Shift = " << preShift << "\n"
1201  // << " deltaRSqLUT (shift)= " << (deltaRSq/pow(10,preShift+corrPar.precDRCut)) << "\n"
1202  // << " deltaRSqPhy = " << deltaRSqPhy
1203  << std::endl;
1204 
1205  if( tbptSqHW > 0. &&
1206  tbptSqHW >= (long long)(corrPar.minTBPTCutValue*pow(10,preShift)) ) {
1207  LogDebug("L1TGlobal") << " Passed Two Body pT Cut [" << (long long)(corrPar.minTBPTCutValue*pow(10,preShift))
1208  << "]" << "\twith value: " << tbptSqHW << "\n"
1209  << "\tPhysics Cut[" << corrPar.minTBPTCutValue/pow(10,corrPar.precTBPTCut) << "]\tPhysics Value: " << tbptSqPhy
1210  << std::endl;
1211 
1212  } else {
1213 
1214  LogDebug("L1TGlobal") << " Failed Two Body pT Cut [" << (long long)(corrPar.minTBPTCutValue*pow(10,preShift))
1215  << "]" << "\t with value: " << tbptSqHW << "\n"
1216  << "\tPhysics Cut[" << corrPar.minTBPTCutValue/pow(10,corrPar.precTBPTCut) << "]\tPhysics Value: " << tbptSqPhy
1217  << std::endl;
1218  reqResult = false;
1219  }
1220  }
1221 
1222  if(corrPar.corrCutType & 0x8 || corrPar.corrCutType & 0x10) {
1223 
1224  //invariant mass calculation based on
1225  // M = sqrt(2*p1*p2(cosh(eta1-eta2) - cos(phi1 - phi2)))
1226  // but we calculate (1/2)M^2
1227  //
1228  double cosDeltaPhiPhy = cos(deltaPhiPhy);
1229  double coshDeltaEtaPhy = cosh(deltaEtaPhy);
1230  if (corrPar.corrCutType & 0x10) coshDeltaEtaPhy=1.;
1231  double massSqPhy = et0Phy*et1Phy*(coshDeltaEtaPhy - cosDeltaPhiPhy);
1232 
1233  long long cosDeltaPhiLUT = m_gtScales->getLUT_DeltaPhi_Cos(lutName,deltaPhiFW);
1234  unsigned int precCosLUT = m_gtScales->getPrec_DeltaPhi_Cos(lutName);
1235 
1236  long long coshDeltaEtaLUT;
1237  if (corrPar.corrCutType & 0x10) {
1238  coshDeltaEtaLUT=1*pow(10,precCosLUT);
1239  }else{
1240  coshDeltaEtaLUT = m_gtScales->getLUT_DeltaEta_Cosh(lutName,deltaEtaFW);
1241  unsigned int precCoshLUT = m_gtScales->getPrec_DeltaEta_Cosh(lutName);
1242  if(precCoshLUT - precCosLUT != 0) LogDebug("L1TGlobal") << "Warning: Cos and Cosh LUTs on different Precision" << std::endl;
1243  }
1244  // if (corrPar.corrCutType & 0x10) coshDeltaEtaLUT=1*pow(10,precCosLUT);
1245 
1246  std::string lutName = lutObj0;
1247  lutName += "-ET";
1248  long long ptObj0 = m_gtScales->getLUT_Pt("Mass_" + lutName,etIndex0);
1249  unsigned int precPtLUTObj0 = m_gtScales->getPrec_Pt("Mass_" + lutName);
1250 
1251  lutName = lutObj1;
1252  lutName += "-ET";
1253  long long ptObj1 = m_gtScales->getLUT_Pt("Mass_" + lutName,etIndex1);
1254  unsigned int precPtLUTObj1 = m_gtScales->getPrec_Pt("Mass_" + lutName);
1255 
1256  // Pt and Angles are at different precission.
1257  long long massSq = ptObj0*ptObj1*(coshDeltaEtaLUT - cosDeltaPhiLUT);
1258 
1259  //Note: There is an assumption here that Cos and Cosh have the same precission
1260  unsigned int preShift = precPtLUTObj0 + precPtLUTObj1 + precCosLUT - corrPar.precMassCut;
1261 
1262  LogDebug("L1TGlobal") << " Testing Invariant Mass (" << lutObj0 << "," << lutObj1 << ") [" << (long long)(corrPar.minMassCutValue*pow(10,preShift))
1263  << "," << (long long)(corrPar.maxMassCutValue*pow(10,preShift)) << "] with precision = " << corrPar.precMassCut <<"\n"
1264  << " deltaPhiLUT = " << deltaPhiLUT << " cosLUT = " << cosDeltaPhiLUT << "\n"
1265  << " deltaEtaLUT = " << deltaEtaLUT << " coshLUT = " << coshDeltaEtaLUT << "\n"
1266  << " etIndex0 = " << etIndex0 << " pt0LUT = " << ptObj0 << " PhyEt0 = " << et0Phy << "\n"
1267  << " etIndex1 = " << etIndex1 << " pt1LUT = " << ptObj1 << " PhyEt1 = " << et1Phy <<"\n"
1268  << " massSq/2 = " << massSq << "\n"
1269  << " Precision Shift = " << preShift << "\n"
1270  << " massSq (shift)= " << (massSq/pow(10,preShift+corrPar.precMassCut)) << "\n"
1271  << " deltaPhiPhy = " << deltaPhiPhy << " cos() = " << cosDeltaPhiPhy << "\n"
1272  << " deltaEtaPhy = " << deltaEtaPhy << " cosh()= " << coshDeltaEtaPhy << "\n"
1273  << " massSqPhy/2 = " << massSqPhy << " sqrt(|massSq|) = "<< sqrt(fabs(2.*massSqPhy)) << std::endl;
1274 
1275  //if(preShift>0) massSq /= pow(10,preShift);
1276  if( massSq >= 0 &&
1277  massSq >= (long long)(corrPar.minMassCutValue*pow(10,preShift)) &&
1278  massSq <= (long long)(corrPar.maxMassCutValue*pow(10,preShift)) ) {
1279  LogDebug("L1TGlobal") << " Passed Invariant Mass Cut [" << (long long)(corrPar.minMassCutValue*pow(10,preShift))
1280  << "," << (long long)(corrPar.maxMassCutValue*pow(10,preShift)) << "]" << std::endl;
1281 
1282  } else {
1283 
1284  LogDebug("L1TGlobal") << " Failed Invariant Mass Cut [" << (long long)(corrPar.minMassCutValue*pow(10,preShift))
1285  << "," << (long long)(corrPar.maxMassCutValue*pow(10,preShift)) << "]" << std::endl;
1286  reqResult = false;
1287  }
1288  }
1289 
1290 
1291 // For Muon-Muon Correlation Check the Charge Correlation if requested
1292  bool chrgCorrel = true;
1293  if(cond0Categ==CondMuon && cond1Categ==CondMuon) {
1294  // Check for like-sign
1295  if(corrPar.chargeCorrelation==2 && chrg0 != chrg1 ) chrgCorrel = false;
1296  // Check for opp-sign
1297  if(corrPar.chargeCorrelation==4 && chrg0 == chrg1 ) chrgCorrel = false;
1298  }
1299 
1300 
1301  if (reqResult & chrgCorrel) {
1302 
1303  condResult = true;
1304  (combinationsInCond()).push_back(objectsInComb);
1305 
1306  }
1307 
1308  } //end loop over second leg
1309 
1310  } //end loop over first leg
1311 
1312 
1313 
1314  if (m_verbosity && condResult) {
1315  LogDebug("L1TGlobal") << " pass(es) the correlation condition.\n"
1316  << std::endl;
1317  }
1318 
1319 
1320  return condResult;
1321 
1322 }
1323 
1324 // load calo candidates
1325 const l1t::L1Candidate* l1t::CorrCondition::getCandidate(const int bx, const int indexCand) const {
1326 
1327  // objectType() gives the type for nrObjects() only,
1328  // but in a CondCalo all objects have the same type
1329  // take type from the type of the first object
1330  switch ((m_gtCorrelationTemplate->objectType())[0]) {
1331  case gtEG:
1332  return (m_uGtB->getCandL1EG())->at(bx,indexCand);
1333  break;
1334 
1335  case gtJet:
1336  return (m_uGtB->getCandL1Jet())->at(bx,indexCand);
1337  break;
1338 
1339  case gtTau:
1340  return (m_uGtB->getCandL1Tau())->at(bx,indexCand);
1341  break;
1342  default:
1343  return nullptr;
1344  break;
1345  }
1346 
1347  return nullptr;
1348 }
1349 
1359 const bool l1t::CorrCondition::checkObjectParameter(const int iCondition, const l1t::L1Candidate& cand) const {
1360 
1361 
1362  return true;
1363 }
1364 
1365 void l1t::CorrCondition::print(std::ostream& myCout) const {
1366 
1367  myCout << "Dummy Print for CorrCondition" << std::endl;
1368  m_gtCorrelationTemplate->print(myCout);
1369 
1370 
1372 
1373 }
#define LogDebug(id)
type
Definition: HCALResponse.h:21
const GlobalCondition * m_gtCond0
void print(std::ostream &myCout) const override
print condition
const BXVector< const l1t::L1Candidate * > * getCandL1Tau() const
pointer to Tau data list
Definition: GlobalBoard.h:162
const ScaleParameters & getETMScales() const
Definition: GlobalScales.h:89
unsigned int getPrec_Cos(const std::string &lutName) const
const BXVector< const l1t::L1Candidate * > * getCandL1Jet() const
pointer to Jet data list
Definition: GlobalBoard.h:155
unsigned int getPrec_Pt(const std::string &lutName) const
unsigned size(int bx) const
CombinationsInCond const & getCombinationsInCond() const
get all the object combinations evaluated to true in the condition
void evaluateConditionStoreResult(const int bxEval)
call evaluateCondition and save last result
long long getLUT_Sin(const std::string &lutName, int element) const
void setGtCorrelationTemplate(const CorrelationTemplate *)
void print(std::ostream &myCout) const override
print condition
Definition: MuCondition.cc:524
const GlobalBoard * m_uGtB
pointer to uGt GlobalBoard, to be able to get the trigger objects
std::vector< std::pair< double, double > > etaBins
Definition: GlobalScales.h:54
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
std::vector< std::pair< double, double > > phiBins
Definition: GlobalScales.h:49
const l1t::GtConditionCategory cond0Category() const
get / set the category of the two sub-conditions
const GlobalCondition * m_gtCond1
void setuGtB(const GlobalBoard *)
set the pointer to uGT GlobalBoard
const ScaleParameters & getJETScales() const
Definition: GlobalScales.h:86
virtual void print(std::ostream &myCout) const
print condition
std::vector< int > SingleCombInCond
typedefs
unsigned int getPrec_DeltaEta_Cosh(const std::string &lutName) const
const ScaleParameters & getETMHFScales() const
Definition: GlobalScales.h:90
const ScaleParameters & getEGScales() const
Definition: GlobalScales.h:84
long long getLUT_DeltaEta(std::string lutName, int element) const
unsigned int getPrec_Sin(const std::string &lutName) const
std::string l1TGtObjectEnumToString(const GlobalObject &)
Definition: GlobalObject.cc:90
bool condLastResult() const
get the latest result for the condition
GtConditionCategory
condition categories
const int & condRelativeBx() const
get / set the condition relative bx
const BXVector< const l1t::L1Candidate * > * getCandL1EG() const
pointer to EG data list
Definition: GlobalBoard.h:149
const l1t::GtConditionCategory cond1Category() const
const bool evaluateCondition(const int bxEval) const override
the core function to check if the condition matches
long long getLUT_DeltaPhi_Cos(std::string lutName, int element) const
const std::vector< l1t::GlobalObject > & objectType() const
get / set the trigger object type(s) in the condition
long long getLUT_Cos(const std::string &lutName, int element) const
CorrCondition & operator=(const CorrCondition &)
T sqrt(T t)
Definition: SSEVec.h:18
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:167
void print(std::ostream &myCout) const override
print condition
long long getLUT_Pt(const std::string &lutName, int element) const
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
unsigned int getPrec_DeltaEta(const std::string &lutName) const
const BXVector< const l1t::EtSum * > * getCandL1EtSum() const
pointer to Tau data list
Definition: GlobalBoard.h:168
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void copy(const CorrCondition &cp)
copy function for copy constructor and operator=
void print(std::ostream &myCout) const override
print the condition
const CorrelationTemplate * m_gtCorrelationTemplate
pointer to a CorrelationTemplate
const ScaleParameters & getTAUScales() const
Definition: GlobalScales.h:85
long long getLUT_CalMuPhi(const std::string &lutName, int element) const
CombinationsInCond m_combinationsInCond
store all the object combinations evaluated to true in the condition
void setScales(const GlobalScales *)
#define LogTrace(id)
long long getLUT_CalMuEta(const std::string &lutName, int element) const
#define M_PI
const GlobalScales * m_gtScales
std::vector< std::pair< double, double > > etBins
Definition: GlobalScales.h:44
long long getLUT_DeltaEta_Cosh(std::string lutName, int element) const
const bool checkObjectParameter(const int iCondition, const l1t::L1Candidate &cand) const
function to check a single object if it matches a condition
const BXVector< const l1t::Muon * > * getCandL1Mu() const
return global muon trigger candidate
Definition: GlobalBoard.h:143
int m_verbosity
verbosity level
~CorrCondition() override
const CorrelationTemplate * gtCorrelationTemplate() const
get / set the pointer to a Condition
Definition: CorrCondition.h:75
long long getLUT_DeltaPhi(std::string lutName, int element) const
void print(std::ostream &myCout) const override
print condition
bool m_condLastResult
the last result of evaluateCondition()
const GlobalBoard * getuGtB() const
get / set the pointer to uGt GlobalBoard
Definition: CorrCondition.h:82
const l1t::L1Candidate * getCandidate(const int bx, const int indexCand) const
load candidates
typedef for a single object template
Definition: GlobalScales.h:39
unsigned int getPrec_DeltaPhi(const std::string &lutName) const
const CorrelationParameter * correlationParameter() const
get / set correlation parameters
const ScaleParameters & getMUScales() const
Definition: GlobalScales.h:83
typedef for correlation parameters
const ScaleParameters & getHTMScales() const
Definition: GlobalScales.h:92
std::vector< SingleCombInCond > CombinationsInCond
all the object combinations evaluated to true in the condition
EtSumType
Definition: EtSum.h:25
unsigned int getPrec_DeltaPhi_Cos(const std::string &lutName) const
CombinationsInCond & combinationsInCond() const
get all the object combinations (to fill it...)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
const T & at(int bx, unsigned i) const