CMS 3D CMS Logo

CorrWithOverlapRemovalCondition.cc
Go to the documentation of this file.
1 
44 // this class header
46 
47 // system include files
48 #include <iostream>
49 #include <iomanip>
50 
51 #include <string>
52 #include <vector>
53 #include <algorithm>
54 
55 // user include files
56 // base classes
59 
67 
69 
71 
74 
75 // constructors
76 // default
79 
80 }
81 
82 // from base template condition (from event setup usually)
84  const GlobalCondition* cond0Condition,
85  const GlobalCondition* cond1Condition,
86  const GlobalCondition* cond2Condition,
87  const GlobalBoard* ptrGTB
88  ) :
91  m_gtCond0(cond0Condition), m_gtCond1(cond1Condition), m_gtCond2(cond2Condition),
92  m_uGtB(ptrGTB)
93 {
94 
95 
96 
97 }
98 
99 // copy constructor
101 
103  m_uGtB = cp.getuGtB();
104 
108 
110 
111 }
112 
115 
116  copy(cp);
117 
118 }
119 
120 // destructor
122 
123  // empty
124 
125 }
126 
127 // equal operator
129  copy(cp);
130  return *this;
131 }
132 
133 // methods
135 
137 
138 }
139 
142 
143  m_uGtB = ptrGTB;
144 
145 }
146 
147 
149 {
150  m_gtScales = sc;
151 }
152 
153 
154 
155 // try all object permutations and check spatial correlations, if required
157 
158  // std::cout << "m_isDebugEnabled = " << m_isDebugEnabled << std::endl;
159  // std::cout << "m_verbosity = " << m_verbosity << std::endl;
160 
161 
162  //std::ostringstream myCout;
163  //m_gtCorrelationWithOverlapRemovalTemplate->print(myCout);
164  //LogDebug("L1TGlobal")
165  // << "CorrelationWithOverlapRemoval Condition Evaluation \n" << myCout.str() << std::endl;
166 
167  bool condResult = false;
168  bool reqObjResult = false;
169 
170  // number of objects in condition (it is 3, no need to retrieve from
171  // condition template) and their type
172  int nObjInCond = 3;
173  std::vector<GlobalObject> cndObjTypeVec(nObjInCond);
174 
175  // evaluate first the two sub-conditions (Type1s)
176 
180 
181  //Decide if we have a mixed (muon + cal) condition
182  bool convertCaloScales = false;
183  if( (cond0Categ == CondMuon && (cond1Categ == CondCalo || cond1Categ == CondEnergySum) ) ||
184  (cond1Categ == CondMuon && (cond0Categ == CondCalo || cond0Categ == CondEnergySum) ) )
185  convertCaloScales = true;
186 
187  bool convertCaloScalesForOverlapRemovalFromLeg0 = false;
188  if( (cond0Categ == CondMuon && (cond2Categ == CondCalo || cond2Categ == CondEnergySum) ) ||
189  (cond2Categ == CondMuon && (cond0Categ == CondCalo || cond0Categ == CondEnergySum) ) )
190  convertCaloScalesForOverlapRemovalFromLeg0 = true;
191 
192  bool convertCaloScalesForOverlapRemovalFromLeg1 = false;
193  if( (cond1Categ == CondMuon && (cond2Categ == CondCalo || cond2Categ == CondEnergySum) ) ||
194  (cond2Categ == CondMuon && (cond1Categ == CondCalo || cond1Categ == CondEnergySum) ) )
195  convertCaloScalesForOverlapRemovalFromLeg1 = true;
196 
197  const MuonTemplate* corrMuon = nullptr;
198  const CaloTemplate* corrCalo = nullptr;
199  const EnergySumTemplate* corrEnergySum = nullptr;
200 
201  // FIXME copying is slow...
202  CombinationsInCond cond0Comb;
203  CombinationsInCond cond1Comb;
204  CombinationsInCond cond2Comb;
205 
206  int cond0bx(0);
207  int cond1bx(0);
208  int cond2bx(0);
209 
210  switch (cond0Categ) {
211  case CondMuon: {
212  corrMuon = static_cast<const MuonTemplate*>(m_gtCond0);
213  MuCondition muCondition(corrMuon, m_uGtB,
214  0,0); //BLW these are counts that don't seem to be used...perhaps remove
215 
216  muCondition.evaluateConditionStoreResult(bxEval);
217  reqObjResult = muCondition.condLastResult();
218 
219  cond0Comb = (muCondition.getCombinationsInCond());
220  cond0bx = bxEval + (corrMuon->condRelativeBx());
221 
222  cndObjTypeVec[0] = (corrMuon->objectType())[0];
223 
224  if (m_verbosity ) {
225  std::ostringstream myCout;
226  muCondition.print(myCout);
227 
228  LogDebug("L1TGlobal") << myCout.str() << std::endl;
229  }
230  }
231  break;
232  case CondCalo: {
233  corrCalo = static_cast<const CaloTemplate*>(m_gtCond0);
234 
235  CaloCondition caloCondition(corrCalo, m_uGtB,
236  0, 0, 0, 0); //BLW these are counters that don't seem to be used...perhaps remove.
237 
238  caloCondition.evaluateConditionStoreResult(bxEval);
239  reqObjResult = caloCondition.condLastResult();
240 
241  cond0Comb = (caloCondition.getCombinationsInCond());
242  cond0bx = bxEval + (corrCalo->condRelativeBx());
243 
244  cndObjTypeVec[0] = (corrCalo->objectType())[0];
245 
246  if (m_verbosity) {
247  std::ostringstream myCout;
248  caloCondition.print(myCout);
249 
250  LogDebug("L1TGlobal") << myCout.str() << std::endl;
251  }
252  }
253  break;
254  case CondEnergySum: {
255 
256  corrEnergySum = static_cast<const EnergySumTemplate*>(m_gtCond0);
257  EnergySumCondition eSumCondition(corrEnergySum, m_uGtB);
258 
259  eSumCondition.evaluateConditionStoreResult(bxEval);
260  reqObjResult = eSumCondition.condLastResult();
261 
262  cond0Comb = (eSumCondition.getCombinationsInCond());
263  cond0bx = bxEval + (corrEnergySum->condRelativeBx());
264 
265  cndObjTypeVec[0] = (corrEnergySum->objectType())[0];
266 
267  if (m_verbosity ) {
268  std::ostringstream myCout;
269  eSumCondition.print(myCout);
270 
271  LogDebug("L1TGlobal") << myCout.str() << std::endl;
272  }
273  }
274  break;
275  default: {
276  // should not arrive here, there are no correlation conditions defined for this object
277  return false;
278  }
279  break;
280  }
281 
282  // return if first subcondition is false
283  if (!reqObjResult) {
284  LogDebug("L1TGlobal")
285  << "\n First sub-condition false, second sub-condition not evaluated and not printed."
286  << std::endl;
287  return false;
288  }
289 
290  // second object
291  reqObjResult = false;
292 
293  switch (cond1Categ) {
294  case CondMuon: {
295  corrMuon = static_cast<const MuonTemplate*>(m_gtCond1);
296  MuCondition muCondition(corrMuon, m_uGtB,
297  0,0); //BLW these are counts that don't seem to be used...perhaps remove
298 
299  muCondition.evaluateConditionStoreResult(bxEval);
300  reqObjResult = muCondition.condLastResult();
301 
302  cond1Comb = (muCondition.getCombinationsInCond());
303  cond1bx = bxEval + (corrMuon->condRelativeBx());
304  cndObjTypeVec[1] = (corrMuon->objectType())[0];
305 
306  if (m_verbosity) {
307  std::ostringstream myCout;
308  muCondition.print(myCout);
309 
310  LogDebug("L1TGlobal") << myCout.str() << std::endl;
311  }
312  }
313  break;
314  case CondCalo: {
315  corrCalo = static_cast<const CaloTemplate*>(m_gtCond1);
316  CaloCondition caloCondition(corrCalo, m_uGtB,
317  0, 0, 0, 0); //BLW these are counters that don't seem to be used...perhaps remove.
318 
319  caloCondition.evaluateConditionStoreResult(bxEval);
320  reqObjResult = caloCondition.condLastResult();
321 
322  cond1Comb = (caloCondition.getCombinationsInCond());
323  cond1bx = bxEval + (corrCalo->condRelativeBx());
324 
325  cndObjTypeVec[1] = (corrCalo->objectType())[0];
326 
327  if (m_verbosity ) {
328  std::ostringstream myCout;
329  caloCondition.print(myCout);
330 
331  LogDebug("L1TGlobal") << myCout.str() << std::endl;
332  }
333 
334  }
335  break;
336  case CondEnergySum: {
337  corrEnergySum = static_cast<const EnergySumTemplate*>(m_gtCond1);
338 
339  EnergySumCondition eSumCondition(corrEnergySum, m_uGtB);
340 
341  eSumCondition.evaluateConditionStoreResult(bxEval);
342  reqObjResult = eSumCondition.condLastResult();
343 
344  cond1Comb = (eSumCondition.getCombinationsInCond());
345  cond1bx = bxEval + (corrEnergySum->condRelativeBx());
346  cndObjTypeVec[1] = (corrEnergySum->objectType())[0];
347 
348  if (m_verbosity) {
349  std::ostringstream myCout;
350  eSumCondition.print(myCout);
351 
352  LogDebug("L1TGlobal") << myCout.str() << std::endl;
353  }
354  }
355  break;
356  default: {
357  // should not arrive here, there are no correlation conditions defined for this object
358  return false;
359  }
360  break;
361  }
362 
363  // return if second sub-condition is false
364  if (!reqObjResult) {
365  return false;
366  } else {
367  LogDebug("L1TGlobal") << "\n"
368  << " Both sub-conditions true for object requirements."
369  << " Evaluate correlation requirements.\n" << std::endl;
370 
371  }
372 
373  // third object (used for overlap removal)
374  reqObjResult = false;
375 
376  switch (cond2Categ) {
377  case CondMuon: {
378  corrMuon = static_cast<const MuonTemplate*>(m_gtCond2);
379  MuCondition muCondition(corrMuon, m_uGtB,
380  0,0); //BLW these are counts that don't seem to be used...perhaps remove
381 
382  muCondition.evaluateConditionStoreResult(bxEval);
383  reqObjResult = muCondition.condLastResult();
384 
385  cond2Comb = (muCondition.getCombinationsInCond());
386  cond2bx = bxEval + (corrMuon->condRelativeBx());
387  cndObjTypeVec[2] = (corrMuon->objectType())[0];
388 
389  if (m_verbosity) {
390  std::ostringstream myCout;
391  muCondition.print(myCout);
392 
393  LogDebug("L1TGlobal") << myCout.str() << std::endl;
394  }
395  }
396  break;
397  case CondCalo: {
398  corrCalo = static_cast<const CaloTemplate*>(m_gtCond2);
399  CaloCondition caloCondition(corrCalo, m_uGtB,
400  0, 0, 0, 0); //BLW these are counters that don't seem to be used...perhaps remove.
401 
402  caloCondition.evaluateConditionStoreResult(bxEval);
403  reqObjResult = caloCondition.condLastResult();
404 
405  cond2Comb = (caloCondition.getCombinationsInCond());
406  cond2bx = bxEval + (corrCalo->condRelativeBx());
407  cndObjTypeVec[2] = (corrCalo->objectType())[0];
408 
409  if (m_verbosity ) {
410  std::ostringstream myCout;
411  caloCondition.print(myCout);
412 
413  LogDebug("L1TGlobal") << myCout.str() << std::endl;
414  }
415 
416  }
417  break;
418  case CondEnergySum: {
419  corrEnergySum = static_cast<const EnergySumTemplate*>(m_gtCond2);
420 
421  EnergySumCondition eSumCondition(corrEnergySum, m_uGtB);
422 
423  eSumCondition.evaluateConditionStoreResult(bxEval);
424  reqObjResult = eSumCondition.condLastResult();
425 
426  cond2Comb = (eSumCondition.getCombinationsInCond());
427  cond2bx = bxEval + (corrEnergySum->condRelativeBx());
428  cndObjTypeVec[2] = (corrEnergySum->objectType())[0];
429 
430  if (m_verbosity) {
431  std::ostringstream myCout;
432  eSumCondition.print(myCout);
433 
434  LogDebug("L1TGlobal") << myCout.str() << std::endl;
435  }
436  }
437  break;
438  default: {
439  // should not arrive here, there are no correlation conditions defined for this object
440  return false;
441  }
442  break;
443  }
444 
445  // if third sub-condition is false, effectively there will no overlap removal
446  if (!reqObjResult) {
447  LogDebug("L1TGlobal") << "\n"
448  << " Third sub-condtion false for object requirements."
449  << " Algorithm returning false.\n" << std::endl;
450  return false;
451  } else {
452  LogDebug("L1TGlobal") << "\n"
453  << " All three sub-conditions true for object requirements."
454  << " Evaluate correlation requirements and overlap removal.\n" << std::endl;
455 
456  }
457 
458  // since we have two good legs and overlap-removal let, get the correlation parameters
460 
461  // vector to store the indices of the calorimeter objects
462  // from the combination evaluated in the condition
463  SingleCombInCond objectsInComb;
464  objectsInComb.reserve(nObjInCond);
465 
466  // clear the m_combinationsInCond vector
468 
469  // pointers to objects
470  const BXVector<const l1t::Muon*>* candMuVec = nullptr;
471  const BXVector<const l1t::L1Candidate*>* candCaloVec = nullptr;
472  const BXVector<const l1t::EtSum*>* candEtSumVec = nullptr;
473 
474  bool etSumCond = false;
475 
476  // make the conversions of the indices, depending on the combination of objects involved
477  // (via pair index)
478 
479  int phiIndex0 = 0;
480  int phiIndex1 = 0;
481  int phiORIndex0 = 0; // hold phi index transformed in case of need with overlap-removal
482  int phiORIndex1 = 0; // hold phi index transformed in case of need with overlap-removal
483  double phi0Phy = 0.;
484  double phi1Phy = 0.;
485 
486  int etaIndex0 = 0;
487  int etaIndex1 = 0;
488  int etaORIndex0 = 0;
489  int etaORIndex1 = 0;
490  double eta0Phy = 0.;
491  double eta1Phy = 0.;
492  int etaBin0 = 0;
493  int etaBin1 = 0;
494 
495  int etIndex0 = 0;
496  int etIndex1 = 0;
497  int etBin0 = 0;
498  int etBin1 = 0;
499  double et0Phy = 0.;
500  double et1Phy = 0.;
501 
502  int chrg0 = -1;
503  int chrg1 = -1;
504 
505  // make the conversions of the indices, depending on the combination of objects involved in overlap-removal
506  int phiIndex2 = 0;
507  int etaIndex2 = 0;
508  double phi2Phy = 0.;
509  double eta2Phy = 0.;
510  int etaBin2 = 0;
511  //int etIndex2 = 0;
512  //int etBin2 = 0;
513 
514 // Determine the number of phi bins to get cutoff at pi
515  int phiBound = 0;
516  if(cond0Categ == CondMuon || cond1Categ == CondMuon || cond2Categ == CondMuon) {
518  //phiBound = par.phiBins.size()/2;
519  phiBound = (int)((par.phiMax - par.phiMin)/par.phiStep)/2;
520  } else {
521  //Assumes all calorimeter objects are on same phi scale
523  //phiBound = par.phiBins.size()/2;
524  phiBound = (int)((par.phiMax - par.phiMin)/par.phiStep)/2;
525  }
526  LogDebug("L1TGlobal") << "Phi Bound = " << phiBound << std::endl;
527 
528 
529 // Keep track of objects for LUTS
530  std::string lutObj0 = "NULL";
531  std::string lutObj1 = "NULL";
532  std::string lutObj2 = "NULL";
533 
534 
535  LogTrace("L1TGlobal")
536  << " Sub-condition 0: std::vector<SingleCombInCond> size: "
537  << (cond0Comb.size()) << std::endl;
538  LogTrace("L1TGlobal")
539  << " Sub-condition 1: std::vector<SingleCombInCond> size: "
540  << (cond1Comb.size()) << std::endl;
541  LogTrace("L1TGlobal")
542  << " Sub-condition 2: std::vector<SingleCombInCond> size: "
543  << (cond2Comb.size()) << std::endl;
544 
545 
546  // ///////////////////////////////////////////////////////////////////////////////////////////
547  // loop over all combinations which produced individually "true" as Type1s
548  // ///////////////////////////////////////////////////////////////////////////////////////////
549  // BLW: Optimization issue: potentially making the same comparison twice
550  // if both legs are the same object type.
551  // ///////////////////////////////////////////////////////////////////////////////////////////
552  for (std::vector<SingleCombInCond>::const_iterator it0Comb = cond0Comb.begin(); it0Comb != cond0Comb.end(); it0Comb++) {
553 
554  // Type1s: there is 1 object only, no need for a loop, index 0 should be OK in (*it0Comb)[0]
555  // ... but add protection to not crash
556  int obj0Index = -1;
557 
558  if (!(*it0Comb).empty()) {
559  obj0Index = (*it0Comb)[0];
560  } else {
561  LogTrace("L1TGlobal")
562  << "\n SingleCombInCond (*it0Comb).size() "
563  << ((*it0Comb).size()) << std::endl;
564  return false;
565  }
566 
567  // Collect the information on the first leg of the correlation
568  switch (cond0Categ) {
569  case CondMuon: {
570  lutObj0 = "MU";
571  candMuVec = m_uGtB->getCandL1Mu();
572  phiIndex0 = (candMuVec->at(cond0bx,obj0Index))->hwPhi(); //(*candMuVec)[obj0Index]->phiIndex();
573  etaIndex0 = (candMuVec->at(cond0bx,obj0Index))->hwEta();
574  etIndex0 = (candMuVec->at(cond0bx,obj0Index))->hwPt();
575  chrg0 = (candMuVec->at(cond0bx,obj0Index))->hwCharge();
576  int etaBin0 = etaIndex0;
577  if(etaBin0<0) etaBin0 = m_gtScales->getMUScales().etaBins.size() + etaBin0; //twos complement
578  // LogDebug("L1TGlobal") << "Muon phi" << phiIndex0 << " eta " << etaIndex0 << " etaBin0 = " << etaBin0 << " et " << etIndex0 << std::endl;
579  //
580 
581  etBin0 = etIndex0;
582  int ssize = m_gtScales->getMUScales().etBins.size();
583  if (etBin0 >= ssize){
584  etBin0 = ssize-1;
585  LogTrace("L1TGlobal")
586  << "muon0 hw et" << etBin0 << " out of scale range. Setting to maximum.";
587  }
588 
589  // Determine Floating Pt numbers for floating point caluclation
590  std::pair<double, double> binEdges = m_gtScales->getMUScales().phiBins.at(phiIndex0);
591  phi0Phy = 0.5*(binEdges.second + binEdges.first);
592  binEdges = m_gtScales->getMUScales().etaBins.at(etaBin0);
593  eta0Phy = 0.5*(binEdges.second + binEdges.first);
594  binEdges = m_gtScales->getMUScales().etBins.at(etBin0);
595  et0Phy = 0.5*(binEdges.second + binEdges.first);
596 
597  LogDebug("L1TGlobal") << "Found all quantities for the muon 0" << std::endl;
598  }
599  break;
600 
601  // Calorimeter Objects (EG, Jet, Tau)
602  case CondCalo: {
603  switch(cndObjTypeVec[0]) {
604  case gtEG: {
605  lutObj0 = "EG";
606  candCaloVec = m_uGtB->getCandL1EG();
607  phiIndex0 = (candCaloVec->at(cond0bx,obj0Index))->hwPhi();
608  etaIndex0 = (candCaloVec->at(cond0bx,obj0Index))->hwEta();
609  etIndex0 = (candCaloVec->at(cond0bx,obj0Index))->hwPt();
610  etaBin0 = etaIndex0;
611  if(etaBin0<0) etaBin0 = m_gtScales->getEGScales().etaBins.size() + etaBin0;
612  // LogDebug("L1TGlobal") << "EG0 phi" << phiIndex0 << " eta " << etaIndex0 << " etaBin0 = " << etaBin0 << " et " << etIndex0 << std::endl;
613 
614  etBin0 = etIndex0;
615  int ssize = m_gtScales->getEGScales().etBins.size();
616  if (etBin0 >= ssize){
617  etBin0 = ssize-1;
618  LogTrace("L1TGlobal")
619  << "EG0 hw et" << etBin0 << " out of scale range. Setting to maximum.";
620  }
621 
622  // Determine Floating Pt numbers for floating point caluclation
623  std::pair<double, double> binEdges = m_gtScales->getEGScales().phiBins.at(phiIndex0);
624  phi0Phy = 0.5*(binEdges.second + binEdges.first);
625  binEdges = m_gtScales->getEGScales().etaBins.at(etaBin0);
626  eta0Phy = 0.5*(binEdges.second + binEdges.first);
627  binEdges = m_gtScales->getEGScales().etBins[etBin0];
628  et0Phy = 0.5*(binEdges.second + binEdges.first);
629 
630  }
631  break;
632  case gtJet: {
633  lutObj0 = "JET";
634  candCaloVec = m_uGtB->getCandL1Jet();
635  phiIndex0 = (candCaloVec->at(cond0bx,obj0Index))->hwPhi();
636  etaIndex0 = (candCaloVec->at(cond0bx,obj0Index))->hwEta();
637  etIndex0 = (candCaloVec->at(cond0bx,obj0Index))->hwPt();
638  etaBin0 = etaIndex0;
639  if(etaBin0<0) etaBin0 = m_gtScales->getJETScales().etaBins.size() + etaBin0;
640 
641  etBin0 = etIndex0;
642  int ssize = m_gtScales->getJETScales().etBins.size();
643  if (etBin0 >= ssize){
644  //edm::LogWarning("L1TGlobal")
645  //<< "jet0 hw et" << etBin0 << " out of scale range. Setting to maximum.";
646  etBin0 = ssize-1;
647  }
648 
649  // Determine Floating Pt numbers for floating point caluclation
650  std::pair<double, double> binEdges = m_gtScales->getJETScales().phiBins.at(phiIndex0);
651  phi0Phy = 0.5*(binEdges.second + binEdges.first);
652  binEdges = m_gtScales->getJETScales().etaBins.at(etaBin0);
653  eta0Phy = 0.5*(binEdges.second + binEdges.first);
654  binEdges = m_gtScales->getJETScales().etBins.at(etBin0);
655  et0Phy = 0.5*(binEdges.second + binEdges.first);
656 
657  }
658  break;
659  case gtTau: {
660  candCaloVec = m_uGtB->getCandL1Tau();
661  phiIndex0 = (candCaloVec->at(cond0bx,obj0Index))->hwPhi();
662  etaIndex0 = (candCaloVec->at(cond0bx,obj0Index))->hwEta();
663  etIndex0 = (candCaloVec->at(cond0bx,obj0Index))->hwPt();
664  etaBin0 = etaIndex0;
665  if(etaBin0<0) etaBin0 = m_gtScales->getTAUScales().etaBins.size() + etaBin0;
666 
667  etBin0 = etIndex0;
668  int ssize = m_gtScales->getTAUScales().etBins.size();
669  if (etBin0 >= ssize){
670  etBin0 = ssize-1;
671  LogTrace("L1TGlobal")
672  << "tau0 hw et" << etBin0 << " out of scale range. Setting to maximum.";
673  }
674 
675  // Determine Floating Pt numbers for floating point caluclation
676  std::pair<double, double> binEdges = m_gtScales->getTAUScales().phiBins.at(phiIndex0);
677  phi0Phy = 0.5*(binEdges.second + binEdges.first);
678  binEdges = m_gtScales->getTAUScales().etaBins.at(etaBin0);
679  eta0Phy = 0.5*(binEdges.second + binEdges.first);
680  binEdges = m_gtScales->getTAUScales().etBins.at(etBin0);
681  et0Phy = 0.5*(binEdges.second + binEdges.first);
682  lutObj0 = "TAU";
683  }
684  break;
685  default: {
686  }
687  break;
688  } //end switch on calo type.
689 
690  phiORIndex0 = phiIndex0;
691  etaORIndex0 = etaIndex0;
692 
693  //If needed convert calo scales to muon scales for comparison
694  if(convertCaloScales) {
695  std::string lutName = lutObj0;
696  lutName += "-MU";
697  long long tst = m_gtScales->getLUT_CalMuEta(lutName,etaBin0);
698  LogDebug("L1TGlobal") << lutName <<" EtaCal = " << etaIndex0 << " etaBin0 = " << etaBin0 << " EtaMu = " << tst << std::endl;
699  etaIndex0 = tst;
700  tst = m_gtScales->getLUT_CalMuPhi(lutName,phiIndex0);
701  LogDebug("L1TGlobal") << lutName <<" PhiCal = " << phiIndex0 << " PhiMu = " << tst << std::endl;
702  phiIndex0 = tst;
703  }
704 
705  //If needed convert calo scales to muon scales for comparison
706  if(convertCaloScalesForOverlapRemovalFromLeg0) {
707  phiORIndex0 = phiIndex0;
708  etaORIndex0 = etaIndex0;
709 
710  }
711 
712  }
713  break;
714 
715  // Energy Sums
716  case CondEnergySum: {
717 
718  etSumCond = true;
719  //Stupid mapping between enum types for energy sums.
721 
722  switch( cndObjTypeVec[0] ){
723  case gtETM:
725  lutObj0 = "ETM";
726  break;
727  case gtETT:
729  lutObj0 = "ETT";
730  break;
731  case gtETTem:
733  lutObj0 = "ETTem"; //should this be just ETT (share LUTs?) Can't be used for CorrCond anyway since now directional information
734  break;
735  case gtHTM:
737  lutObj0 = "HTM";
738  break;
739  case gtHTT:
741  lutObj0 = "HTT";
742  break;
743  case gtETMHF:
745  lutObj0 = "ETMHF";
746  break;
747  case gtMinBiasHFP0:
748  case gtMinBiasHFM0:
749  case gtMinBiasHFP1:
750  case gtMinBiasHFM1:
752  lutObj0 = "MinBias"; //??Fix?? Not a valid LUT type Can't be used for CorrCond anyway since now directional information
753  break;
754  default:
755  edm::LogError("L1TGlobal")
756  << "\n Error: "
757  << "Unmatched object type from template to EtSumType, cndObjTypeVec[0] = "
758  << cndObjTypeVec[0]
759  << std::endl;
761  break;
762  }
763 
764  candEtSumVec = m_uGtB->getCandL1EtSum();
765 
766  for( int iEtSum=0; iEtSum < (int)candEtSumVec->size(cond0bx); iEtSum++) {
767  if( (candEtSumVec->at(cond0bx,iEtSum))->getType() == type ) {
768  phiIndex0 = (candEtSumVec->at(cond0bx,iEtSum))->hwPhi();
769  etaIndex0 = (candEtSumVec->at(cond0bx,iEtSum))->hwEta();
770  etIndex0 = (candEtSumVec->at(cond0bx,iEtSum))->hwPt();
771 
772  // Get the floating point numbers
773  if(cndObjTypeVec[0] == gtETM ) {
774  std::pair<double, double> binEdges = m_gtScales->getETMScales().phiBins.at(phiIndex0);
775  phi0Phy = 0.5*(binEdges.second + binEdges.first);
776  eta0Phy = 0.; //No Eta for Energy Sums
777 
778  etBin0 = etIndex0;
779  int ssize = m_gtScales->getETMScales().etBins.size();
780  assert(ssize > 0);
781  if (etBin0 >= ssize){ etBin0 = ssize-1; }
782 
783  binEdges = m_gtScales->getETMScales().etBins.at(etBin0);
784  et0Phy = 0.5*(binEdges.second + binEdges.first);
785  } else if (cndObjTypeVec[0] == gtHTM) {
786  std::pair<double, double> binEdges = m_gtScales->getHTMScales().phiBins.at(phiIndex0);
787  phi0Phy = 0.5*(binEdges.second + binEdges.first);
788  eta0Phy = 0.; //No Eta for Energy Sums
789 
790  etBin0 = etIndex0;
791  int ssize = m_gtScales->getHTMScales().etBins.size();
792  assert(ssize > 0);
793  if (etBin0 >= ssize){ etBin0 = ssize-1; }
794 
795  binEdges = m_gtScales->getHTMScales().etBins.at(etBin0);
796  et0Phy = 0.5*(binEdges.second + binEdges.first);
797  } else if (cndObjTypeVec[0] == gtETMHF) {
798  std::pair<double, double> binEdges = m_gtScales->getETMHFScales().phiBins.at(phiIndex0);
799  phi0Phy = 0.5*(binEdges.second + binEdges.first);
800  eta0Phy = 0.; //No Eta for Energy Sums
801 
802  etBin0 = etIndex0;
803  int ssize = m_gtScales->getETMHFScales().etBins.size();
804  assert(ssize > 0);
805  if (etBin0 >= ssize){ etBin0 = ssize-1; }
806 
807  binEdges = m_gtScales->getETMHFScales().etBins.at(etBin0);
808  et0Phy = 0.5*(binEdges.second + binEdges.first);
809  }
810 
811  phiORIndex0 = phiIndex0;
812  etaORIndex0 = etaIndex0;
813 
814  //If needed convert calo scales to muon scales for comparison (only phi for energy sums)
815  if(convertCaloScales) {
816  std::string lutName = lutObj0;
817  lutName += "-MU";
818  long long tst = m_gtScales->getLUT_CalMuPhi(lutName,phiIndex0);
819  LogDebug("L1TGlobal") << lutName <<" PhiCal = " << phiIndex0 << " PhiMu = " << tst << std::endl;
820  phiIndex0 = tst;
821  }
822 
823  //If needed convert calo scales to muon scales for comparison (only phi for energy sums)
824  if(convertCaloScalesForOverlapRemovalFromLeg0) {
825  phiORIndex0 = phiIndex0;
826 
827  }
828 
829  } //check it is the EtSum we want
830  } // loop over Etsums
831 
832  } // end case CondEnergySum
833  break;
834 
835 
836  default: {
837  // should not arrive here, there are no correlation conditions defined for this object
838  LogDebug("L1TGlobal") << "Error could not find the Cond Category for Leg 0" << std::endl;
839  return false;
840  }
841  break;
842  } //end switch on first leg type
843 
844  LogDebug("L1TGlobal") << "lutObj0 = " << lutObj0 << std::endl;
845 
846  unsigned int overlapRemovalMatchLeg1 = 0x0;
847 
848  // ///////////////////////////////////////////////////////////////////////////////////////////
849  // loop over overlap-removal leg combination which produced individually "true" as Type1s
850  // ///////////////////////////////////////////////////////////////////////////////////////////
851  for (std::vector<SingleCombInCond>::const_iterator it2Comb = cond2Comb.begin(); it2Comb != cond2Comb.end() && overlapRemovalMatchLeg1 != 0x1; it2Comb++) {
852 
853  // Type1s: there is 1 object only, no need for a loop, index 0 should be OK in (*it2Comb)[0]
854  // ... but add protection to not crash
855  int obj2Index = -1;
856 
857  if (!(*it2Comb).empty()) {
858  obj2Index = (*it2Comb)[0];
859  } else {
860  LogTrace("L1TGlobal")
861  << "\n SingleCombInCond (*it2Comb).size() "
862  << ((*it2Comb).size()) << std::endl;
863  return false;
864  }
865 
866  // Collect the information on the overlap-removal leg
867  switch (cond2Categ) {
868 
869  case CondMuon: {
870 
871  lutObj2 = "MU";
872  candMuVec = m_uGtB->getCandL1Mu();
873  phiIndex2 = (candMuVec->at(cond2bx,obj2Index))->hwPhi(); //(*candMuVec)[obj2Index]->phiIndex();
874  etaIndex2 = (candMuVec->at(cond2bx,obj2Index))->hwEta();
875  int etaBin2 = etaIndex2;
876  if(etaBin2<0) etaBin2 = m_gtScales->getMUScales().etaBins.size() + etaBin2; //twos complement
877  //LogDebug("L1TGlobal") << "Muon phi" << phiIndex2 << " eta " << etaIndex2 << " etaBin2 = " << etaBin2 << " et " << etIndex2 << std::endl;
878 
879  // Determine Floating Pt numbers for floating point caluclation
880  std::pair<double, double> binEdges = m_gtScales->getMUScales().phiBins.at(phiIndex2);
881  phi2Phy = 0.5*(binEdges.second + binEdges.first);
882  binEdges = m_gtScales->getMUScales().etaBins.at(etaBin2);
883  eta2Phy = 0.5*(binEdges.second + binEdges.first);
884 
885  LogDebug("L1TGlobal") << "Found all quantities for the muon 0" << std::endl;
886  }
887  break;
888 
889  // Calorimeter Objects (EG, Jet, Tau)
890  case CondCalo: {
891 
892  switch(cndObjTypeVec[2]) {
893 
894  case gtEG: {
895  lutObj2 = "EG";
896  candCaloVec = m_uGtB->getCandL1EG();
897  phiIndex2 = (candCaloVec->at(cond2bx,obj2Index))->hwPhi();
898  etaIndex2 = (candCaloVec->at(cond2bx,obj2Index))->hwEta();
899  if(etaBin2<0) etaBin2 = m_gtScales->getEGScales().etaBins.size() + etaBin2;
900  //LogDebug("L1TGlobal") << "EG0 phi" << phiIndex2 << " eta " << etaIndex2 << " etaBin2 = " << etaBin2 << " et " << etIndex2 << std::endl;
901 
902  // Determine Floating Pt numbers for floating point caluclation
903  std::pair<double, double> binEdges = m_gtScales->getEGScales().phiBins.at(phiIndex2);
904  phi2Phy = 0.5*(binEdges.second + binEdges.first);
905  binEdges = m_gtScales->getEGScales().etaBins.at(etaBin2);
906  eta2Phy = 0.5*(binEdges.second + binEdges.first);
907 
908  }
909  break;
910  case gtJet: {
911  lutObj2 = "JET";
912  candCaloVec = m_uGtB->getCandL1Jet();
913  phiIndex2 = (candCaloVec->at(cond2bx,obj2Index))->hwPhi();
914  etaIndex2 = (candCaloVec->at(cond2bx,obj2Index))->hwEta();
915  etaBin2 = etaIndex2;
916  if(etaBin2<0) etaBin2 = m_gtScales->getJETScales().etaBins.size() + etaBin2;
917 
918  // Determine Floating Pt numbers for floating point caluclation
919  std::pair<double, double> binEdges = m_gtScales->getJETScales().phiBins.at(phiIndex2);
920  phi2Phy = 0.5*(binEdges.second + binEdges.first);
921  binEdges = m_gtScales->getJETScales().etaBins.at(etaBin2);
922  eta2Phy = 0.5*(binEdges.second + binEdges.first);
923 
924  }
925  break;
926  case gtTau: {
927 
928  candCaloVec = m_uGtB->getCandL1Tau();
929  phiIndex2 = (candCaloVec->at(cond2bx,obj2Index))->hwPhi();
930  etaIndex2 = (candCaloVec->at(cond2bx,obj2Index))->hwEta();
931  if(etaBin2<0) etaBin2 = m_gtScales->getTAUScales().etaBins.size() + etaBin2;
932 
933  // Determine Floating Pt numbers for floating point caluclation
934  std::pair<double, double> binEdges = m_gtScales->getTAUScales().phiBins.at(phiIndex2);
935  phi2Phy = 0.5*(binEdges.second + binEdges.first);
936  binEdges = m_gtScales->getTAUScales().etaBins.at(etaBin2);
937  eta2Phy = 0.5*(binEdges.second + binEdges.first);
938  lutObj2 = "TAU";
939  }
940  break;
941  default: {
942  }
943  break;
944 
945  } //end switch on calo type.
946 
947  //If needed convert calo scales to muon scales for comparison
948  if(convertCaloScales) {
949 
950  std::string lutName = lutObj2;
951  lutName += "-MU";
952  long long tst = m_gtScales->getLUT_CalMuEta(lutName,etaBin2);
953  LogDebug("L1TGlobal") << lutName <<" EtaCal = " << etaIndex2 << " etaBin2 = " << etaBin2 << " EtaMu = " << tst << std::endl;
954  etaIndex2 = tst;
955 
956  tst = m_gtScales->getLUT_CalMuPhi(lutName,phiIndex2);
957  LogDebug("L1TGlobal") << lutName <<" PhiCal = " << phiIndex2 << " PhiMu = " << tst << std::endl;
958  phiIndex2 = tst;
959 
960  }
961 
962  } // end case CondCalo
963  break;
964 
965  // Energy Sums
966  case CondEnergySum: {
967 
968  etSumCond = true;
969  //Stupid mapping between enum types for energy sums.
971  switch( cndObjTypeVec[2] ){
972  case gtETM:
974  lutObj2 = "ETM";
975  break;
976  case gtETT:
978  lutObj2 = "ETT";
979  break;
980  case gtETTem:
982  lutObj2 = "ETTem"; //should this be just ETT (share LUTs?) Can't be used for CorrCond anyway since now directional information
983  break;
984  case gtHTM:
986  lutObj2 = "HTM";
987  break;
988  case gtHTT:
990  lutObj2 = "HTT";
991  break;
992  case gtETMHF:
994  lutObj2 = "ETMHF";
995  break;
996  case gtMinBiasHFP0:
997  case gtMinBiasHFM0:
998  case gtMinBiasHFP1:
999  case gtMinBiasHFM1:
1001  lutObj2 = "MinBias"; //??Fix?? Not a valid LUT type Can't be used for CorrCond anyway since now directional information
1002  break;
1003  default:
1004  edm::LogError("L1TGlobal")
1005  << "\n Error: "
1006  << "Unmatched object type from template to EtSumType, cndObjTypeVec[2] = "
1007  << cndObjTypeVec[2]
1008  << std::endl;
1010  break;
1011  }
1012 
1013  candEtSumVec = m_uGtB->getCandL1EtSum();
1014 
1015  for( int iEtSum=0; iEtSum < (int)candEtSumVec->size(cond2bx); iEtSum++) {
1016  if( (candEtSumVec->at(cond2bx,iEtSum))->getType() == type ) {
1017  phiIndex2 = (candEtSumVec->at(cond2bx,iEtSum))->hwPhi();
1018  etaIndex2 = (candEtSumVec->at(cond2bx,iEtSum))->hwEta();
1019 
1020  // Get the floating point numbers
1021  if(cndObjTypeVec[2] == gtETM ) {
1022  std::pair<double, double> binEdges = m_gtScales->getETMScales().phiBins.at(phiIndex2);
1023  phi2Phy = 0.5*(binEdges.second + binEdges.first);
1024  eta2Phy = 0.; //No Eta for Energy Sums
1025 
1026  } else if (cndObjTypeVec[2] == gtHTM) {
1027  std::pair<double, double> binEdges = m_gtScales->getHTMScales().phiBins.at(phiIndex2);
1028  phi2Phy = 0.5*(binEdges.second + binEdges.first);
1029  eta2Phy = 0.; //No Eta for Energy Sums
1030 
1031  } else if (cndObjTypeVec[2] == gtETMHF) {
1032  std::pair<double, double> binEdges = m_gtScales->getETMHFScales().phiBins.at(phiIndex2);
1033  phi2Phy = 0.5*(binEdges.second + binEdges.first);
1034  eta2Phy = 0.; //No Eta for Energy Sums
1035 
1036  }
1037 
1038  //If needed convert calo scales to muon scales for comparison (only phi for energy sums)
1039  if(convertCaloScales) {
1040 
1041  std::string lutName = lutObj2;
1042  lutName += "-MU";
1043  long long tst = m_gtScales->getLUT_CalMuPhi(lutName,phiIndex2);
1044  LogDebug("L1TGlobal") << lutName <<" PhiCal = " << phiIndex2 << " PhiMu = " << tst << std::endl;
1045  phiIndex2 = tst;
1046 
1047  }
1048 
1049  } //check it is the EtSum we want
1050  } // loop over Etsums
1051 
1052  }
1053  break;
1054 
1055  default: {
1056  // should not arrive here, there are no correlation conditions defined for this object
1057  LogDebug("L1TGlobal") << "Error could not find the Cond Category for Leg 3" << std::endl;
1058  return false;
1059  }
1060  break;
1061  } //end switch on overlap-removal leg type
1062 
1063  LogDebug("L1TGlobal") << "lutObj2 = " << lutObj2 << std::endl;
1064 
1065  // /////////////////////////////////////////////////////////////////////////////////////////
1066  //
1067  // here check if there is a match of 1st leg with overlap removal object, and store result
1068  //
1069  // /////////////////////////////////////////////////////////////////////////////////////////
1070  // These all require some delta eta and phi calculations. Do them first...for now real calculation but need to
1071  // revise this to line up with firmware calculations.
1072  double deltaPhiPhy = fabs(phi2Phy - phi0Phy);
1073  if(deltaPhiPhy> M_PI) deltaPhiPhy = 2.*M_PI - deltaPhiPhy;
1074  double deltaEtaPhy = fabs(eta2Phy - eta0Phy);
1075 
1076  // Deter the integer based delta eta and delta phi
1077  int deltaPhiFW = abs(phiORIndex0 - phiIndex2);
1078  if(deltaPhiFW>=phiBound) deltaPhiFW = 2*phiBound - deltaPhiFW;
1079  std::string lutName = lutObj0;
1080  lutName += "-";
1081  lutName += lutObj2;
1082  long long deltaPhiLUT = m_gtScales->getLUT_DeltaPhi(lutName,deltaPhiFW);
1083  unsigned int precDeltaPhiLUT = m_gtScales->getPrec_DeltaPhi(lutName);
1084 
1085  int deltaEtaFW = abs(etaORIndex0 - etaIndex2);
1086  long long deltaEtaLUT = 0;
1087  unsigned int precDeltaEtaLUT = 0;
1088  if(!etSumCond) {
1089  deltaEtaLUT = m_gtScales->getLUT_DeltaEta(lutName,deltaEtaFW);
1090  precDeltaEtaLUT = m_gtScales->getPrec_DeltaEta(lutName);
1091  }
1092 
1093  LogDebug("L1TGlobal") << "Obj0 phiFW = " << phiORIndex0 << " Obj2 phiFW = " << phiIndex2 << "\n"
1094  << " DeltaPhiFW = " << deltaPhiFW << "\n"
1095  << " LUT Name = " << lutName << " Prec = " << precDeltaPhiLUT << " DeltaPhiLUT = " << deltaPhiLUT << "\n"
1096  << "Obj0 etaFW = " << etaIndex0 << " Obj2 etaFW = " << etaIndex2 << "\n"
1097  << " DeltaEtaFW = " << deltaEtaFW << "\n"
1098  << " LUT Name = " << lutName << " Prec = " << precDeltaEtaLUT << " DeltaEtaLUT = " << deltaEtaLUT << std::endl;
1099 
1100  // If there is a OverlapRemovalDeltaEta cut, check it.
1101  if(corrPar.corrCutType & 0x10) {
1102 
1103  unsigned int preShift = precDeltaEtaLUT - corrPar.precOverlapRemovalEtaCut;
1104  LogDebug("L1TGlobal") << " Testing Leg1 Overlap Removal Delta Eta Cut (" << lutObj0 << "," << lutObj2 << ") [" << (long long)(corrPar.minOverlapRemovalEtaCutValue*pow(10,preShift))
1105  << "," << (long long)(corrPar.maxOverlapRemovalEtaCutValue*pow(10,preShift)) << "] with precision = " << corrPar.precOverlapRemovalEtaCut <<"\n"
1106  << " deltaEtaLUT = " << deltaEtaLUT << "\n"
1107  << " Precision Shift = " << preShift << "\n"
1108  << " deltaEta (shift)= " << (deltaEtaLUT/pow(10,preShift+corrPar.precOverlapRemovalEtaCut)) << "\n"
1109  << " deltaEtaPhy = " << deltaEtaPhy << std::endl;
1110 
1111  //if(preShift>0) deltaEtaLUT /= pow(10,preShift);
1112  if( deltaEtaLUT >= (long long)(corrPar.minOverlapRemovalEtaCutValue*pow(10,preShift)) &&
1113  deltaEtaLUT <= (long long)(corrPar.maxOverlapRemovalEtaCutValue*pow(10,preShift)) ) {
1114 
1115  overlapRemovalMatchLeg1 |= 0x1;
1116  LogDebug("L1TGlobal") << " Satified Leg1 Overlap Removal Delta Eta Cut [" << (long long)(corrPar.minOverlapRemovalEtaCutValue*pow(10,preShift))
1117  << "," << (long long)(corrPar.maxOverlapRemovalEtaCutValue*pow(10,preShift)) << "]" << std::endl;
1118  // next leg3 object
1119  continue;
1120 
1121  } else {
1122 
1123  LogDebug("L1TGlobal") << " Failed Leg1 Overlap Removal Delta Eta Cut [" << (long long)(corrPar.minOverlapRemovalEtaCutValue*pow(10,preShift))
1124  << "," << (long long)(corrPar.maxOverlapRemovalEtaCutValue*pow(10,preShift)) << "]" << std::endl;
1125  }
1126 
1127  }
1128 
1129  //if there is a OverlapRemovalDeltaPhi cut, check it.
1130  if(corrPar.corrCutType & 0x20) {
1131 
1132  unsigned int preShift = precDeltaPhiLUT - corrPar.precOverlapRemovalPhiCut;
1133  LogDebug("L1TGlobal") << " Testing Leg1 Overlap Removal Delta Phi Cut (" << lutObj0 << "," << lutObj2 << ") [" << (long long)(corrPar.minOverlapRemovalPhiCutValue*pow(10,preShift))
1134  << "," << (long long)(corrPar.maxOverlapRemovalPhiCutValue*pow(10,preShift)) << "] with precision = " << corrPar.precOverlapRemovalPhiCut <<"\n"
1135  << " deltaPhiLUT = " << deltaPhiLUT << "\n"
1136  << " Precision Shift = " << preShift << "\n"
1137  << " deltaPhi (shift)= " << (deltaPhiLUT/pow(10,preShift+corrPar.precOverlapRemovalPhiCut)) << "\n"
1138  << " deltaPhiPhy = " << deltaPhiPhy << std::endl;
1139 
1140  //if(preShift>0) deltaPhiLUT /= pow(10,preShift);
1141  if( deltaPhiLUT >= (long long)(corrPar.minOverlapRemovalPhiCutValue*pow(10,preShift)) &&
1142  deltaPhiLUT <= (long long)(corrPar.maxOverlapRemovalPhiCutValue*pow(10,preShift)) ) {
1143 
1144  overlapRemovalMatchLeg1 |= 0x1;
1145  LogDebug("L1TGlobal") << " Satisfied Leg1 Overlap Removal Delta Phi Cut [" << (long long)(corrPar.minOverlapRemovalPhiCutValue*pow(10,preShift))
1146  << "," << (long long)(corrPar.maxOverlapRemovalPhiCutValue*pow(10,preShift)) << "]" << std::endl;
1147  // next leg3 object
1148  continue;
1149 
1150  } else {
1151 
1152  LogDebug("L1TGlobal") << " Failed Leg1 Overlap Removal Delta Phi Cut [" << (long long)(corrPar.minOverlapRemovalPhiCutValue*pow(10,preShift))
1153  << "," << (long long)(corrPar.maxOverlapRemovalPhiCutValue*pow(10,preShift)) << "]" << std::endl;
1154  }
1155  }
1156 
1157  //if there is a OverlapRemovalDeltaR cut, check it.
1158  if(corrPar.corrCutType & 0x40) {
1159 
1160  //Assumes Delta Eta and Delta Phi LUTs have the same precision
1161  unsigned int preShift = 2*precDeltaPhiLUT - corrPar.precOverlapRemovalDRCut;
1162  double deltaRSqPhy = deltaPhiPhy*deltaPhiPhy + deltaEtaPhy*deltaEtaPhy;
1163  long long deltaRSq = deltaEtaLUT*deltaEtaLUT + deltaPhiLUT*deltaPhiLUT;
1164 
1165  LogDebug("L1TGlobal") << " Testing Leg1 Overlap Removal Delta R Cut (" << lutObj0 << "," << lutObj2 << ") [" << (long long)(corrPar.minOverlapRemovalDRCutValue*pow(10,preShift))
1166  << "," << (long long)(corrPar.maxOverlapRemovalDRCutValue*pow(10,preShift)) << "] with precision = " << corrPar.precOverlapRemovalDRCut <<"\n"
1167  << " deltaPhiLUT = " << deltaPhiLUT << "\n"
1168  << " deltaEtaLUT = " << deltaEtaLUT << "\n"
1169  << " deltaRSqLUT = " << deltaRSq << "\n"
1170  << " Precision Shift = " << preShift << "\n"
1171  << " deltaRSqLUT (shift)= " << (deltaRSq/pow(10,preShift+corrPar.precDRCut)) << "\n"
1172  << " deltaRSqPhy = " << deltaRSqPhy << std::endl;
1173 
1174  //if(preShift>0) deltaRSq /= pow(10,preShift);
1175  if( deltaRSq >= (long long)(corrPar.minOverlapRemovalDRCutValue*pow(10,preShift)) &&
1176  deltaRSq <= (long long)(corrPar.maxOverlapRemovalDRCutValue*pow(10,preShift)) ) {
1177 
1178  overlapRemovalMatchLeg1 |= 0x1;
1179  LogDebug("L1TGlobal") << " Satified Leg1 Overlap Removal Delta R Cut [" << (long long)(corrPar.minOverlapRemovalDRCutValue*pow(10,preShift))
1180  << "," << (long long)(corrPar.maxOverlapRemovalDRCutValue*pow(10,preShift)) << "]" << std::endl;
1181  // next leg3 object
1182  continue;
1183 
1184  } else {
1185 
1186  LogDebug("L1TGlobal") << " Failed Leg1 Overlap Removal Delta R Cut [" << (int)(corrPar.minOverlapRemovalDRCutValue*pow(10,preShift))
1187  << "," << (long long)(corrPar.maxOverlapRemovalDRCutValue*pow(10,preShift)) << "]" << std::endl;
1188 
1189  }
1190 
1191  }
1192 
1193  } // end loop over combinations in overlap-removal leg.
1194 
1195  // skip object leg1 if matched with overlap removal object
1196  // ///////////////////////////////////////////////////////
1197  if (overlapRemovalMatchLeg1 == 0x1) {
1198  LogDebug("L1TGlobal") << " Remove Object of Leg1: Satisfied Overlap Removal Cuts " << std::endl;
1199  continue;
1200  }
1201  else {
1202  LogDebug("L1TGlobal") << " Keep Object of Leg1: Failed Overlap Removal Cuts " << std::endl;
1203  }
1204 
1205 
1206  // ///////////////////////////////////////////////////////////////////////////////////////////
1207  // Now loop over the second leg to get its information
1208  // ///////////////////////////////////////////////////////////////////////////////////////////
1209  for (std::vector<SingleCombInCond>::const_iterator it1Comb = cond1Comb.begin(); it1Comb != cond1Comb.end(); it1Comb++) {
1210 
1211  LogDebug("L1TGlobal") << "Looking at second Condition" << std::endl;
1212  // Type1s: there is 1 object only, no need for a loop (*it1Comb)[0]
1213  // ... but add protection to not crash
1214  int obj1Index = -1;
1215 
1216  if (!(*it1Comb).empty()) {
1217  obj1Index = (*it1Comb)[0];
1218  } else {
1219  LogTrace("L1TGlobal")
1220  << "\n SingleCombInCond (*it1Comb).size() "
1221  << ((*it1Comb).size()) << std::endl;
1222  return false;
1223  }
1224 
1225  //If we are dealing with the same object type avoid the two legs
1226  // either being the same object
1227  if( cndObjTypeVec[0] == cndObjTypeVec[1] &&
1228  obj0Index == obj1Index &&
1229  cond0bx == cond1bx) {
1230 
1231  LogDebug("L1TGlobal") << "Corr Condition looking at same leg...skip" << std::endl;
1232  continue;
1233  }
1234 
1235  switch (cond1Categ) {
1236  case CondMuon: {
1237  lutObj1 = "MU";
1238  candMuVec = m_uGtB->getCandL1Mu();
1239  phiIndex1 = (candMuVec->at(cond1bx,obj1Index))->hwPhi(); //(*candMuVec)[obj0Index]->phiIndex();
1240  etaIndex1 = (candMuVec->at(cond1bx,obj1Index))->hwEta();
1241  etIndex1 = (candMuVec->at(cond1bx,obj1Index))->hwPt();
1242  chrg1 = (candMuVec->at(cond1bx,obj1Index))->hwCharge();
1243  etaBin1 = etaIndex1;
1244  if(etaBin1<0) etaBin1 = m_gtScales->getMUScales().etaBins.size() + etaBin1;
1245  // LogDebug("L1TGlobal") << "Muon phi" << phiIndex1 << " eta " << etaIndex1 << " etaBin1 = " << etaBin1 << " et " << etIndex1 << std::endl;
1246  etBin1 = etIndex1;
1247  int ssize = m_gtScales->getMUScales().etBins.size();
1248 
1249  if (etBin1 >= ssize){
1250  LogTrace("L1TGlobal")
1251  << "muon2 hw et" << etBin1 << " out of scale range. Setting to maximum.";
1252  etBin1 = ssize-1;
1253  }
1254 
1255  // Determine Floating Pt numbers for floating point caluclation
1256  std::pair<double, double> binEdges = m_gtScales->getMUScales().phiBins.at(phiIndex1);
1257  phi1Phy = 0.5*(binEdges.second + binEdges.first);
1258  binEdges = m_gtScales->getMUScales().etaBins.at(etaBin1);
1259  eta1Phy = 0.5*(binEdges.second + binEdges.first);
1260  binEdges = m_gtScales->getMUScales().etBins.at(etBin1);
1261  et1Phy = 0.5*(binEdges.second + binEdges.first);
1262 
1263  }
1264  break;
1265 
1266  case CondCalo: {
1267 
1268  switch(cndObjTypeVec[1]) {
1269 
1270  case gtEG: {
1271 
1272  candCaloVec = m_uGtB->getCandL1EG();
1273  phiIndex1 = (candCaloVec->at(cond1bx,obj1Index))->hwPhi();
1274  etaIndex1 = (candCaloVec->at(cond1bx,obj1Index))->hwEta();
1275  etIndex1 = (candCaloVec->at(cond1bx,obj1Index))->hwPt();
1276  etaBin1 = etaIndex1;
1277  if(etaBin1<0) etaBin1 = m_gtScales->getEGScales().etaBins.size() + etaBin1;
1278 
1279  etBin1 = etIndex1;
1280  int ssize = m_gtScales->getEGScales().etBins.size();
1281  if (etBin1 >= ssize){
1282  LogTrace("L1TGlobal")
1283  << "EG1 hw et" << etBin1 << " out of scale range. Setting to maximum.";
1284  etBin1 = ssize-1;
1285  }
1286 
1287  // Determine Floating Pt numbers for floating point caluclation
1288  std::pair<double, double> binEdges = m_gtScales->getEGScales().phiBins.at(phiIndex1);
1289  phi1Phy = 0.5*(binEdges.second + binEdges.first);
1290  binEdges = m_gtScales->getEGScales().etaBins.at(etaBin1);
1291  eta1Phy = 0.5*(binEdges.second + binEdges.first);
1292  binEdges = m_gtScales->getEGScales().etBins.at(etBin1);
1293  et1Phy = 0.5*(binEdges.second + binEdges.first);
1294  lutObj1 = "EG";
1295  }
1296  break;
1297 
1298  case gtJet: {
1299  candCaloVec = m_uGtB->getCandL1Jet();
1300  phiIndex1 = (candCaloVec->at(cond1bx,obj1Index))->hwPhi();
1301  etaIndex1 = (candCaloVec->at(cond1bx,obj1Index))->hwEta();
1302  etIndex1 = (candCaloVec->at(cond1bx,obj1Index))->hwPt();
1303  etaBin1 = etaIndex1;
1304  if(etaBin1<0) etaBin1 = m_gtScales->getJETScales().etaBins.size() + etaBin1;
1305  etBin1 = etIndex1;
1306  int ssize = m_gtScales->getJETScales().etBins.size();
1307  assert(ssize);
1308  if (etBin1 >= ssize){
1309  //edm::LogWarning("L1TGlobal")
1310  //<< "jet2 hw et" << etBin1 << " out of scale range. Setting to maximum.";
1311  etBin1 = ssize-1;
1312  }
1313 
1314  // Determine Floating Pt numbers for floating point caluclation
1315  std::pair<double, double> binEdges = m_gtScales->getJETScales().phiBins.at(phiIndex1);
1316  phi1Phy = 0.5*(binEdges.second + binEdges.first);
1317  binEdges = m_gtScales->getJETScales().etaBins.at(etaBin1);
1318  eta1Phy = 0.5*(binEdges.second + binEdges.first);
1319 
1320  binEdges = m_gtScales->getJETScales().etBins.at(etBin1);
1321  et1Phy = 0.5*(binEdges.second + binEdges.first);
1322  lutObj1 = "JET";
1323  }
1324  break;
1325 
1326  case gtTau: {
1327  candCaloVec = m_uGtB->getCandL1Tau();
1328  phiIndex1 = (candCaloVec->at(cond1bx,obj1Index))->hwPhi();
1329  etaIndex1 = (candCaloVec->at(cond1bx,obj1Index))->hwEta();
1330  etIndex1 = (candCaloVec->at(cond1bx,obj1Index))->hwPt();
1331  etaBin1 = etaIndex1;
1332  if(etaBin1<0) etaBin1 = m_gtScales->getTAUScales().etaBins.size() + etaBin1;
1333  etBin1 = etIndex1;
1334  int ssize = m_gtScales->getTAUScales().etBins.size();
1335  if (etBin1 >= ssize){
1336  LogTrace("L1TGlobal")
1337  << "tau2 hw et" << etBin1 << " out of scale range. Setting to maximum.";
1338  etBin1 = ssize-1;
1339  }
1340 
1341  // Determine Floating Pt numbers for floating point caluclation
1342  std::pair<double, double> binEdges = m_gtScales->getTAUScales().phiBins.at(phiIndex1);
1343  phi1Phy = 0.5*(binEdges.second + binEdges.first);
1344  binEdges = m_gtScales->getTAUScales().etaBins.at(etaBin1);
1345  eta1Phy = 0.5*(binEdges.second + binEdges.first);
1346  binEdges = m_gtScales->getTAUScales().etBins.at(etBin1);
1347  et1Phy = 0.5*(binEdges.second + binEdges.first);
1348  lutObj1 = "TAU";
1349  }
1350  break;
1351  default: {
1352  }
1353  break;
1354 
1355  } //end switch on calo type.
1356 
1357 
1358  phiORIndex1 = phiIndex1;
1359  etaORIndex1 = etaIndex1;
1360 
1361  //If needed convert calo scales to muon scales for comparison
1362  if(convertCaloScales) {
1363 
1364  std::string lutName = lutObj1;
1365  lutName += "-MU";
1366  long long tst = m_gtScales->getLUT_CalMuEta(lutName,etaBin1);
1367  LogDebug("L1TGlobal") << lutName <<" EtaCal = " << etaIndex1 << " EtaMu = " << tst << std::endl;
1368  etaIndex1 = tst;
1369  tst = m_gtScales->getLUT_CalMuPhi(lutName,phiIndex1);
1370  LogDebug("L1TGlobal") << lutName <<" PhiCal = " << phiIndex1 << " PhiMu = " << tst << std::endl;
1371  phiIndex1 = tst;
1372 
1373  }
1374 
1375  //If needed convert calo scales to muon scales for comparison
1376  if(convertCaloScalesForOverlapRemovalFromLeg1) {
1377  phiORIndex1 = phiIndex1;
1378  etaORIndex1 = etaIndex1;
1379 
1380  }
1381 
1382 
1383  } // end case CondCalo
1384  break;
1385  case CondEnergySum: {
1386 
1387  LogDebug("L1TGlobal") << "Looking at second Condition as Energy Sum: " << cndObjTypeVec[1] << std::endl;
1388  etSumCond = true;
1389 
1390  //Stupid mapping between enum types for energy sums.
1392 
1393  switch( cndObjTypeVec[1] ){
1394  case gtETM:
1396  lutObj1 = "ETM";
1397  break;
1398  case gtETT:
1400  lutObj1 = "ETT";
1401  break;
1402  case gtETTem:
1404  lutObj1 = "ETTem";
1405  break;
1406  case gtHTM:
1408  lutObj1 = "HTM";
1409  break;
1410  case gtHTT:
1412  lutObj1 = "HTT";
1413  break;
1414  case gtETMHF:
1416  lutObj1 = "ETMHF";
1417  break;
1418  case gtMinBiasHFP0:
1419  case gtMinBiasHFM0:
1420  case gtMinBiasHFP1:
1421  case gtMinBiasHFM1:
1423  lutObj1 = "MinBias";
1424  break;
1425  default:
1426  edm::LogError("L1TGlobal")
1427  << "\n Error: "
1428  << "Unmatched object type from template to EtSumType, cndObjTypeVec[1] = "
1429  << cndObjTypeVec[1]
1430  << std::endl;
1432  break;
1433  }
1434 
1435  candEtSumVec = m_uGtB->getCandL1EtSum();
1436 
1437  LogDebug("L1TGlobal") << "obj " << lutObj1 << " Vector Size " << candEtSumVec->size(cond1bx) << std::endl;
1438  for( int iEtSum=0; iEtSum < (int)candEtSumVec->size(cond1bx); iEtSum++) {
1439  if( (candEtSumVec->at(cond1bx,iEtSum))->getType() == type ) {
1440  phiIndex1 = (candEtSumVec->at(cond1bx,iEtSum))->hwPhi();
1441  etaIndex1 = (candEtSumVec->at(cond1bx,iEtSum))->hwEta();
1442  etIndex1 = (candEtSumVec->at(cond1bx,iEtSum))->hwPt();
1443 
1444  // Determine Floating Pt numbers for floating point caluclation
1445 
1446  if(cndObjTypeVec[1] == gtETM) {
1447  std::pair<double, double> binEdges = m_gtScales->getETMScales().phiBins.at(phiIndex1);
1448  phi1Phy = 0.5*(binEdges.second + binEdges.first);
1449  eta1Phy = 0.; //No Eta for Energy Sums
1450 
1451  etBin1 = etIndex1;
1452  int ssize = m_gtScales->getETMScales().etBins.size();
1453  assert(ssize > 0);
1454  if (etBin1 >= ssize){ etBin1 = ssize-1; }
1455 
1456  binEdges = m_gtScales->getETMScales().etBins.at(etBin1);
1457  et1Phy = 0.5*(binEdges.second + binEdges.first);
1458  } else if(cndObjTypeVec[1] == gtHTM) {
1459  std::pair<double, double> binEdges = m_gtScales->getHTMScales().phiBins.at(phiIndex1);
1460  phi1Phy = 0.5*(binEdges.second + binEdges.first);
1461  eta1Phy = 0.; //No Eta for Energy Sums
1462 
1463  etBin1 = etIndex1;
1464  int ssize = m_gtScales->getHTMScales().etBins.size();
1465  assert(ssize > 0);
1466  if (etBin1 >= ssize){ etBin1 = ssize-1; }
1467 
1468  binEdges = m_gtScales->getHTMScales().etBins.at(etBin1);
1469  et1Phy = 0.5*(binEdges.second + binEdges.first);
1470  } else if(cndObjTypeVec[1] == gtETMHF) {
1471  std::pair<double, double> binEdges = m_gtScales->getETMHFScales().phiBins.at(phiIndex1);
1472  phi1Phy = 0.5*(binEdges.second + binEdges.first);
1473  eta1Phy = 0.; //No Eta for Energy Sums
1474  etBin1 = etIndex1;
1475  int ssize = m_gtScales->getETMHFScales().etBins.size();
1476  assert(ssize > 0);
1477  if (etBin1 >= ssize){ etBin1 = ssize-1; }
1478  binEdges = m_gtScales->getETMHFScales().etBins.at(etBin1);
1479  et1Phy = 0.5*(binEdges.second + binEdges.first);
1480  }
1481 
1482  phiORIndex1 = phiIndex1;
1483  etaORIndex1 = etaIndex1;
1484 
1485  //If needed convert calo scales to muon scales for comparison (only phi for energy sums)
1486  if(convertCaloScales) {
1487 
1488  std::string lutName = lutObj1;
1489  lutName += "-MU";
1490  long long tst = m_gtScales->getLUT_CalMuPhi(lutName,phiIndex1);
1491  LogDebug("L1TGlobal") << lutName <<" PhiCal = " << phiIndex1 << " PhiMu = " << tst << std::endl;
1492  phiIndex1 = tst;
1493 
1494  }
1495 
1496  //If needed convert calo scales to muon scales for comparison (only phi for energy sums)
1497  if(convertCaloScalesForOverlapRemovalFromLeg1) {
1498  phiORIndex1 = phiIndex1;
1499  }
1500 
1501  } //check it is the EtSum we want
1502  } // loop over Etsums
1503 
1504  } // end case EnergySum
1505  break;
1506  default: {
1507  // should not arrive here, there are no correlation conditions defined for this object
1508  LogDebug("L1TGlobal") << "Error could not find the Cond Category for Leg 0" << std::endl;
1509  return false;
1510  }
1511  break;
1512  } //end switch on second leg
1513 
1514  unsigned int overlapRemovalMatchLeg2 = 0x0;
1515 
1516  // ///////////////////////////////////////////////////////////////////////////////////////////
1517  // loop over overlap-removal leg combination which produced individually "true" as Type1s
1518  // ///////////////////////////////////////////////////////////////////////////////////////////
1519  for (std::vector<SingleCombInCond>::const_iterator it2Comb = cond2Comb.begin(); it2Comb != cond2Comb.end() && overlapRemovalMatchLeg2 != 0x1; it2Comb++) {
1520 
1521  // Type1s: there is 1 object only, no need for a loop, index 0 should be OK in (*it2Comb)[0]
1522  // ... but add protection to not crash
1523  int obj2Index = -1;
1524 
1525  if (!(*it2Comb).empty()) {
1526  obj2Index = (*it2Comb)[0];
1527  } else {
1528  LogTrace("L1TGlobal")
1529  << "\n SingleCombInCond (*it2Comb).size() "
1530  << ((*it2Comb).size()) << std::endl;
1531  return false;
1532  }
1533 
1534  // Collect the information on the overlap-removal leg
1535  switch (cond2Categ) {
1536  case CondMuon: {
1537  lutObj2 = "MU";
1538  candMuVec = m_uGtB->getCandL1Mu();
1539  phiIndex2 = (candMuVec->at(cond2bx,obj2Index))->hwPhi(); //(*candMuVec)[obj2Index]->phiIndex();
1540  etaIndex2 = (candMuVec->at(cond2bx,obj2Index))->hwEta();
1541  int etaBin2 = etaIndex2;
1542  if(etaBin2<0) etaBin2 = m_gtScales->getMUScales().etaBins.size() + etaBin2; //twos complement
1543  //LogDebug("L1TGlobal") << "Muon phi" << phiIndex2 << " eta " << etaIndex2 << " etaBin2 = " << etaBin2 << " et " << etIndex2 << std::endl;
1544 
1545  // Determine Floating Pt numbers for floating point caluclation
1546  std::pair<double, double> binEdges = m_gtScales->getMUScales().phiBins.at(phiIndex2);
1547  phi2Phy = 0.5*(binEdges.second + binEdges.first);
1548  binEdges = m_gtScales->getMUScales().etaBins.at(etaBin2);
1549  eta2Phy = 0.5*(binEdges.second + binEdges.first);
1550 
1551  LogDebug("L1TGlobal") << "Found all quantities for the muon 0" << std::endl;
1552  }
1553  break;
1554 
1555  // Calorimeter Objects (EG, Jet, Tau)
1556  case CondCalo: {
1557 
1558  switch(cndObjTypeVec[2]) {
1559 
1560  case gtEG: {
1561  lutObj2 = "EG";
1562  candCaloVec = m_uGtB->getCandL1EG();
1563  phiIndex2 = (candCaloVec->at(cond2bx,obj2Index))->hwPhi();
1564  etaIndex2 = (candCaloVec->at(cond2bx,obj2Index))->hwEta();
1565  if(etaBin2<0) etaBin2 = m_gtScales->getEGScales().etaBins.size() + etaBin2;
1566  //LogDebug("L1TGlobal") << "EG0 phi" << phiIndex2 << " eta " << etaIndex2 << " etaBin2 = " << etaBin2 << " et " << etIndex2 << std::endl;
1567 
1568  // Determine Floating Pt numbers for floating point caluclation
1569  std::pair<double, double> binEdges = m_gtScales->getEGScales().phiBins.at(phiIndex2);
1570  phi2Phy = 0.5*(binEdges.second + binEdges.first);
1571  binEdges = m_gtScales->getEGScales().etaBins.at(etaBin2);
1572  eta2Phy = 0.5*(binEdges.second + binEdges.first);
1573  }
1574  break;
1575 
1576  case gtJet: {
1577  lutObj2 = "JET";
1578  candCaloVec = m_uGtB->getCandL1Jet();
1579  phiIndex2 = (candCaloVec->at(cond2bx,obj2Index))->hwPhi();
1580  etaIndex2 = (candCaloVec->at(cond2bx,obj2Index))->hwEta();
1581  etaBin2 = etaIndex2;
1582  if(etaBin2<0) etaBin2 = m_gtScales->getJETScales().etaBins.size() + etaBin2;
1583  // Determine Floating Pt numbers for floating point caluclation
1584  std::pair<double, double> binEdges = m_gtScales->getJETScales().phiBins.at(phiIndex2);
1585  phi2Phy = 0.5*(binEdges.second + binEdges.first);
1586  binEdges = m_gtScales->getJETScales().etaBins.at(etaBin2);
1587  eta2Phy = 0.5*(binEdges.second + binEdges.first);
1588  }
1589  break;
1590  case gtTau: {
1591  candCaloVec = m_uGtB->getCandL1Tau();
1592  phiIndex2 = (candCaloVec->at(cond2bx,obj2Index))->hwPhi();
1593  etaIndex2 = (candCaloVec->at(cond2bx,obj2Index))->hwEta();
1594  if(etaBin2<0) etaBin2 = m_gtScales->getTAUScales().etaBins.size() + etaBin2;
1595 
1596  // Determine Floating Pt numbers for floating point caluclation
1597  std::pair<double, double> binEdges = m_gtScales->getTAUScales().phiBins.at(phiIndex2);
1598  phi2Phy = 0.5*(binEdges.second + binEdges.first);
1599  binEdges = m_gtScales->getTAUScales().etaBins.at(etaBin2);
1600  eta2Phy = 0.5*(binEdges.second + binEdges.first);
1601  lutObj2 = "TAU";
1602  }
1603  break;
1604  default: {
1605  }
1606  break;
1607 
1608  } //end switch on calo type.
1609 
1610  //If needed convert calo scales to muon scales for comparison
1611  if(convertCaloScales) {
1612  std::string lutName = lutObj2;
1613  lutName += "-MU";
1614  long long tst = m_gtScales->getLUT_CalMuEta(lutName,etaBin2);
1615  LogDebug("L1TGlobal") << lutName <<" EtaCal = " << etaIndex2 << " etaBin2 = " << etaBin2 << " EtaMu = " << tst << std::endl;
1616  etaIndex2 = tst;
1617 
1618  tst = m_gtScales->getLUT_CalMuPhi(lutName,phiIndex2);
1619  LogDebug("L1TGlobal") << lutName <<" PhiCal = " << phiIndex2 << " PhiMu = " << tst << std::endl;
1620  phiIndex2 = tst;
1621 
1622  }
1623 
1624  }
1625  break;
1626 
1627  // Energy Sums
1628  case CondEnergySum: {
1629 
1630  etSumCond = true;
1631  //Stupid mapping between enum types for energy sums.
1633  switch( cndObjTypeVec[2] ){
1634  case gtETM:
1636  lutObj2 = "ETM";
1637  break;
1638  case gtETT:
1640  lutObj2 = "ETT";
1641  break;
1642  case gtETTem:
1644  lutObj2 = "ETTem"; //should this be just ETT (share LUTs?) Can't be used for CorrCond anyway since now directional information
1645  break;
1646  case gtHTM:
1648  lutObj2 = "HTM";
1649  break;
1650  case gtHTT:
1652  lutObj2 = "HTT";
1653  break;
1654  case gtETMHF:
1656  lutObj2 = "ETMHF";
1657  break;
1658  case gtMinBiasHFP0:
1659  case gtMinBiasHFM0:
1660  case gtMinBiasHFP1:
1661  case gtMinBiasHFM1:
1663  lutObj2 = "MinBias"; //??Fix?? Not a valid LUT type Can't be used for CorrCond anyway since now directional information
1664  break;
1665  default:
1666  edm::LogError("L1TGlobal")
1667  << "\n Error: "
1668  << "Unmatched object type from template to EtSumType, cndObjTypeVec[2] = "
1669  << cndObjTypeVec[2]
1670  << std::endl;
1672  break;
1673  }
1674 
1675  candEtSumVec = m_uGtB->getCandL1EtSum();
1676 
1677  for( int iEtSum=0; iEtSum < (int)candEtSumVec->size(cond2bx); iEtSum++) {
1678  if( (candEtSumVec->at(cond2bx,iEtSum))->getType() == type ) {
1679  phiIndex2 = (candEtSumVec->at(cond2bx,iEtSum))->hwPhi();
1680  etaIndex2 = (candEtSumVec->at(cond2bx,iEtSum))->hwEta();
1681 
1682  // Get the floating point numbers
1683  if(cndObjTypeVec[2] == gtETM ) {
1684  std::pair<double, double> binEdges = m_gtScales->getETMScales().phiBins.at(phiIndex2);
1685  phi2Phy = 0.5*(binEdges.second + binEdges.first);
1686  eta2Phy = 0.; //No Eta for Energy Sums
1687 
1688  } else if (cndObjTypeVec[2] == gtHTM) {
1689  std::pair<double, double> binEdges = m_gtScales->getHTMScales().phiBins.at(phiIndex2);
1690  phi2Phy = 0.5*(binEdges.second + binEdges.first);
1691  eta2Phy = 0.; //No Eta for Energy Sums
1692 
1693  } else if (cndObjTypeVec[2] == gtETMHF) {
1694  std::pair<double, double> binEdges = m_gtScales->getETMHFScales().phiBins.at(phiIndex2);
1695  phi2Phy = 0.5*(binEdges.second + binEdges.first);
1696  eta2Phy = 0.; //No Eta for Energy Sums
1697 
1698  }
1699 
1700  //If needed convert calo scales to muon scales for comparison (only phi for energy sums)
1701  if(convertCaloScales) {
1702  std::string lutName = lutObj2;
1703  lutName += "-MU";
1704  long long tst = m_gtScales->getLUT_CalMuPhi(lutName,phiIndex2);
1705  LogDebug("L1TGlobal") << lutName <<" PhiCal = " << phiIndex2 << " PhiMu = " << tst << std::endl;
1706  phiIndex2 = tst;
1707  }
1708 
1709  } //check it is the EtSum we want
1710  } // loop over Etsums
1711 
1712  } // end case CondEnerySum
1713  break;
1714  default: {
1715  // should not arrive here, there are no correlation conditions defined for this object
1716  LogDebug("L1TGlobal") << "Error could not find the Cond Category for Leg 3" << std::endl;
1717  return false;
1718  }
1719  break;
1720  } //end switch on overlap-removal leg type
1721 
1722  // /////////////////////////////////////////////////////////////////////////////////////////
1723  //
1724  // here check if there is a match of 2st leg with overlap removal object ...if yes, continue
1725  //
1726  // /////////////////////////////////////////////////////////////////////////////////////////
1727  // These all require some delta eta and phi calculations. Do them first...for now real calculation but need to
1728  // revise this to line up with firmware calculations.
1729  double deltaPhiPhy = fabs(phi2Phy - phi1Phy);
1730  if(deltaPhiPhy> M_PI) deltaPhiPhy = 2.*M_PI - deltaPhiPhy;
1731  double deltaEtaPhy = fabs(eta2Phy - eta1Phy);
1732 
1733  // Deter the integer based delta eta and delta phi
1734  int deltaPhiFW = abs(phiORIndex1 - phiIndex2);
1735  if(deltaPhiFW>=phiBound) deltaPhiFW = 2*phiBound - deltaPhiFW;
1736  std::string lutName = lutObj1;
1737  lutName += "-";
1738  lutName += lutObj2;
1739  long long deltaPhiLUT = m_gtScales->getLUT_DeltaPhi(lutName,deltaPhiFW);
1740  unsigned int precDeltaPhiLUT = m_gtScales->getPrec_DeltaPhi(lutName);
1741 
1742  int deltaEtaFW = abs(etaORIndex1 - etaIndex2);
1743  long long deltaEtaLUT = 0;
1744  unsigned int precDeltaEtaLUT = 0;
1745  if(!etSumCond) {
1746  deltaEtaLUT = m_gtScales->getLUT_DeltaEta(lutName,deltaEtaFW);
1747  precDeltaEtaLUT = m_gtScales->getPrec_DeltaEta(lutName);
1748  }
1749 
1750  LogDebug("L1TGlobal") << "Obj1 phiFW = " << phiORIndex1 << " Obj2 phiFW = " << phiIndex2 << "\n"
1751  << " DeltaPhiFW = " << deltaPhiFW << "\n"
1752  << " LUT Name = " << lutName << " Prec = " << precDeltaPhiLUT << " DeltaPhiLUT = " << deltaPhiLUT << "\n"
1753  << "Obj1 etaFW = " << etaIndex1 << " Obj1 etaFW = " << etaIndex1 << "\n"
1754  << " DeltaEtaFW = " << deltaEtaFW << "\n"
1755  << " LUT Name = " << lutName << " Prec = " << precDeltaEtaLUT << " DeltaEtaLUT = " << deltaEtaLUT << std::endl;
1756 
1757  // If there is a OverlapRemovalDeltaEta cut, check it.
1758  // /////////////////////////////////////////////////
1759  if(corrPar.corrCutType & 0x10) {
1760 
1761  unsigned int preShift = precDeltaEtaLUT - corrPar.precOverlapRemovalEtaCut;
1762  LogDebug("L1TGlobal") << " Testing Leg2 Overlap Removal Delta Eta Cut (" << lutObj1 << "," << lutObj2 << ") [" << (long long)(corrPar.minOverlapRemovalEtaCutValue*pow(10,preShift))
1763  << "," << (long long)(corrPar.maxOverlapRemovalEtaCutValue*pow(10,preShift)) << "] with precision = " << corrPar.precOverlapRemovalEtaCut <<"\n"
1764  << " deltaEtaLUT = " << deltaEtaLUT << "\n"
1765  << " Precision Shift = " << preShift << "\n"
1766  << " deltaEta (shift)= " << (deltaEtaLUT/pow(10,preShift+corrPar.precOverlapRemovalEtaCut)) << "\n"
1767  << " deltaEtaPhy = " << deltaEtaPhy << std::endl;
1768 
1769  //if(preShift>0) deltaEtaLUT /= pow(10,preShift);
1770  if( deltaEtaLUT >= (long long)(corrPar.minOverlapRemovalEtaCutValue*pow(10,preShift)) &&
1771  deltaEtaLUT <= (long long)(corrPar.maxOverlapRemovalEtaCutValue*pow(10,preShift)) ) {
1772 
1773  overlapRemovalMatchLeg2 |= 0x1;
1774  LogDebug("L1TGlobal") << " Satisfied Leg2 Overlap Removal Delta Eta Cut [" << (long long)(corrPar.minOverlapRemovalEtaCutValue*pow(10,preShift))
1775  << "," << (long long)(corrPar.maxOverlapRemovalEtaCutValue*pow(10,preShift)) << "]" << std::endl;
1776  // next leg3 object
1777  continue;
1778 
1779  } else {
1780 
1781  LogDebug("L1TGlobal") << " Failed Leg2 Overlap Removal Delta Eta Cut [" << (long long)(corrPar.minOverlapRemovalEtaCutValue*pow(10,preShift))
1782  << "," << (long long)(corrPar.maxOverlapRemovalEtaCutValue*pow(10,preShift)) << "]" << std::endl;
1783  }
1784  }
1785  // If there is a OverlapRemovalDeltaPhi cut, check it.
1786  // /////////////////////////////////////////////////
1787  if(corrPar.corrCutType & 0x20) {
1788 
1789  unsigned int preShift = precDeltaPhiLUT - corrPar.precOverlapRemovalPhiCut;
1790  LogDebug("L1TGlobal") << " Testing Delta Phi Cut (" << lutObj1 << "," << lutObj2 << ") [" << (long long)(corrPar.minOverlapRemovalPhiCutValue*pow(10,preShift))
1791  << "," << (long long)(corrPar.maxOverlapRemovalPhiCutValue*pow(10,preShift)) << "] with precision = " << corrPar.precOverlapRemovalPhiCut <<"\n"
1792  << " deltaPhiLUT = " << deltaPhiLUT << "\n"
1793  << " Precision Shift = " << preShift << "\n"
1794  << " deltaPhi (shift)= " << (deltaPhiLUT/pow(10,preShift+corrPar.precOverlapRemovalPhiCut)) << "\n"
1795  << " deltaPhiPhy = " << deltaPhiPhy << std::endl;
1796 
1797  //if(preShift>0) deltaPhiLUT /= pow(10,preShift);
1798  if( deltaPhiLUT >= (long long)(corrPar.minOverlapRemovalPhiCutValue*pow(10,preShift)) &&
1799  deltaPhiLUT <= (long long)(corrPar.maxOverlapRemovalPhiCutValue*pow(10,preShift)) ) {
1800 
1801  overlapRemovalMatchLeg2 |= 0x1;
1802  LogDebug("L1TGlobal") << " Satisfied Leg2 Overlap Removal Delta Phi Cut [" << (long long)(corrPar.minOverlapRemovalPhiCutValue*pow(10,preShift))
1803  << "," << (long long)(corrPar.maxOverlapRemovalPhiCutValue*pow(10,preShift)) << "]" << std::endl;
1804  // next leg3 object
1805  continue;
1806 
1807  } else {
1808 
1809  LogDebug("L1TGlobal") << " Failed Leg2 Overlap Removal Delta Phi Cut [" << (long long)(corrPar.minOverlapRemovalPhiCutValue*pow(10,preShift))
1810  << "," << (long long)(corrPar.maxOverlapRemovalPhiCutValue*pow(10,preShift)) << "]" << std::endl;
1811  }
1812  }
1813 
1814  //if there is a OverlapRemovalDeltaR cut, check it.
1815  // /////////////////////////////////////////////////
1816  if(corrPar.corrCutType & 0x40) {
1817 
1818  //Assumes Delta Eta and Delta Phi LUTs have the same precision
1819  unsigned int preShift = 2*precDeltaPhiLUT - corrPar.precOverlapRemovalDRCut;
1820  double deltaRSqPhy = deltaPhiPhy*deltaPhiPhy + deltaEtaPhy*deltaEtaPhy;
1821  long long deltaRSq = deltaEtaLUT*deltaEtaLUT + deltaPhiLUT*deltaPhiLUT;
1822 
1823  LogDebug("L1TGlobal") << " Testing Leg2 Overlap Removal Delta R Cut (" << lutObj1 << "," << lutObj2 << ") [" << (long long)(corrPar.minOverlapRemovalDRCutValue*pow(10,preShift))
1824  << "," << (long long)(corrPar.maxOverlapRemovalDRCutValue*pow(10,preShift)) << "] with precision = " << corrPar.precOverlapRemovalDRCut <<"\n"
1825  << " deltaPhiLUT = " << deltaPhiLUT << "\n"
1826  << " deltaEtaLUT = " << deltaEtaLUT << "\n"
1827  << " deltaRSqLUT = " << deltaRSq << "\n"
1828  << " Precision Shift = " << preShift << "\n"
1829  << " deltaRSqLUT (shift)= " << (deltaRSq/pow(10,preShift+corrPar.precDRCut)) << "\n"
1830  << " deltaRSqPhy = " << deltaRSqPhy << std::endl;
1831 
1832  //if(preShift>0) deltaRSq /= pow(10,preShift);
1833  if( deltaRSq >= (long long)(corrPar.minOverlapRemovalDRCutValue*pow(10,preShift)) &&
1834  deltaRSq <= (long long)(corrPar.maxOverlapRemovalDRCutValue*pow(10,preShift)) ) {
1835 
1836  overlapRemovalMatchLeg2 |= 0x1;
1837  LogDebug("L1TGlobal") << " Satisfied Leg2 Overlap Removal Delta R Cut [" << (long long)(corrPar.minOverlapRemovalDRCutValue*pow(10,preShift))
1838  << "," << (long long)(corrPar.maxOverlapRemovalDRCutValue*pow(10,preShift)) << "]" << std::endl;
1839  // next leg3 object
1840  continue;
1841 
1842  } else {
1843 
1844  LogDebug("L1TGlobal") << " Failed Leg2 Overlap Removal Delta R Cut [" << (int)(corrPar.minOverlapRemovalDRCutValue*pow(10,preShift))
1845  << "," << (long long)(corrPar.maxOverlapRemovalDRCutValue*pow(10,preShift)) << "]" << std::endl;
1846  }
1847  }
1848 
1849  } // end loop over combinations in overlap-removal leg.
1850 
1851  // skip object leg2 if matched with overlap removal object
1852  // ///////////////////////////////////////////////////////
1853  if (overlapRemovalMatchLeg2 == 0x1) {
1854  LogDebug("L1TGlobal") << " Remove Object of Leg2: Satisfied Overlap Removal Cuts" << std::endl;
1855  continue;
1856  }
1857  else {
1858  LogDebug("L1TGlobal") << " Keep Object of Leg2: Failed Overlap Removal Cuts " << std::endl;
1859  }
1860 
1861 
1862  // ///////////////////////////////////////////////////////
1863  // At this point, both correlation legs are cleared of overlaps
1864  // ///////////////////////////////////////////////////////
1865 
1866  if (m_verbosity) {
1867  LogDebug("L1TGlobal") << " Correlation pair ["
1868  << l1TGtObjectEnumToString(cndObjTypeVec[0]) << ", "
1869  << l1TGtObjectEnumToString(cndObjTypeVec[1])
1870  << "] with collection indices [" << obj0Index << ", "
1871  << obj1Index << "] " << " has: \n"
1872  << " Et value = ["<< etIndex0 << ", " << etIndex1 << "]\n"
1873  << " phi indices = ["<< phiIndex0 << ", " << phiIndex1 << "]\n"
1874  << " eta indices = ["<< etaIndex0 << ", " << etaIndex1 << "]\n"
1875  << " chrg = ["<< chrg0 << ", " << chrg1 << "]\n"<< std::endl;
1876  }
1877 
1878 
1879  // Now perform the desired correlation on these two objects. Assume true until we find a contradition
1880  bool reqResult = true;
1881 
1882  // clear the indices in the combination
1883  objectsInComb.clear();
1884 
1885  objectsInComb.push_back(obj0Index);
1886  objectsInComb.push_back(obj1Index);
1887 
1888  // if we get here all checks were successful for this combination
1889  // set the general result for evaluateCondition to "true"
1890 
1891 
1892  // These all require some delta eta and phi calculations. Do them first...for now real calculation but need to
1893  // revise this to line up with firmware calculations.
1894  double deltaPhiPhy = fabs(phi1Phy - phi0Phy);
1895  if(deltaPhiPhy> M_PI) deltaPhiPhy = 2.*M_PI - deltaPhiPhy;
1896  double deltaEtaPhy = fabs(eta1Phy - eta0Phy);
1897 
1898 
1899  // Determine the integer based delta eta and delta phi
1900  int deltaPhiFW = abs(phiIndex0 - phiIndex1);
1901  if(deltaPhiFW>=phiBound) deltaPhiFW = 2*phiBound - deltaPhiFW;
1902  std::string lutName = lutObj0;
1903  lutName += "-";
1904  lutName += lutObj1;
1905  long long deltaPhiLUT = m_gtScales->getLUT_DeltaPhi(lutName,deltaPhiFW);
1906  unsigned int precDeltaPhiLUT = m_gtScales->getPrec_DeltaPhi(lutName);
1907 
1908  int deltaEtaFW = abs(etaIndex0 - etaIndex1);
1909  long long deltaEtaLUT = 0;
1910  unsigned int precDeltaEtaLUT = 0;
1911  if(!etSumCond) {
1912  deltaEtaLUT = m_gtScales->getLUT_DeltaEta(lutName,deltaEtaFW);
1913  precDeltaEtaLUT = m_gtScales->getPrec_DeltaEta(lutName);
1914  }
1915 
1916  //
1917  LogDebug("L1TGlobal") << "Obj0 phiFW = " << phiIndex0 << " Obj1 phiFW = " << phiIndex1 << "\n"
1918  << " DeltaPhiFW = " << deltaPhiFW << "\n"
1919  << " LUT Name = " << lutName << " Prec = " << precDeltaPhiLUT << " DeltaPhiLUT = " << deltaPhiLUT << "\n"
1920  << "Obj0 etaFW = " << etaIndex0 << " Obj1 etaFW = " << etaIndex1 << "\n"
1921  << " DeltaEtaFW = " << deltaEtaFW << "\n"
1922  << " LUT Name = " << lutName << " Prec = " << precDeltaEtaLUT << " DeltaEtaLUT = " << deltaEtaLUT << std::endl;
1923 
1924 
1925  // If there is a delta eta, check it.
1926  if(corrPar.corrCutType & 0x1) {
1927 
1928  unsigned int preShift = precDeltaEtaLUT - corrPar.precEtaCut;
1929  LogDebug("L1TGlobal") << " Testing Delta Eta Cut (" << lutObj0 << "," << lutObj1 << ") [" << (long long)(corrPar.minEtaCutValue*pow(10,preShift))
1930  << "," << (long long)(corrPar.maxEtaCutValue*pow(10,preShift)) << "] with precision = " << corrPar.precEtaCut <<"\n"
1931  << " deltaEtaLUT = " << deltaEtaLUT << "\n"
1932  << " Precision Shift = " << preShift << "\n"
1933  << " deltaEta (shift)= " << (deltaEtaLUT/pow(10,preShift+corrPar.precEtaCut)) << "\n"
1934  << " deltaEtaPhy = " << deltaEtaPhy << std::endl;
1935 
1936  //if(preShift>0) deltaEtaLUT /= pow(10,preShift);
1937  if( deltaEtaLUT >= (long long)(corrPar.minEtaCutValue*pow(10,preShift)) &&
1938  deltaEtaLUT <= (long long)(corrPar.maxEtaCutValue*pow(10,preShift)) ) {
1939 
1940  LogDebug("L1TGlobal") << " Passed Delta Eta Cut [" << (long long)(corrPar.minEtaCutValue*pow(10,preShift))
1941  << "," << (long long)(corrPar.maxEtaCutValue*pow(10,preShift)) << "]" << std::endl;
1942 
1943  } else {
1944 
1945  LogDebug("L1TGlobal") << " Failed Delta Eta Cut [" << (long long)(corrPar.minEtaCutValue*pow(10,preShift))
1946  << "," << (long long)(corrPar.maxEtaCutValue*pow(10,preShift)) << "]" << std::endl;
1947  reqResult = false;
1948  }
1949  }
1950 
1951  //if there is a delta phi check it.
1952  if(corrPar.corrCutType & 0x2) {
1953 
1954  unsigned int preShift = precDeltaPhiLUT - corrPar.precPhiCut;
1955  LogDebug("L1TGlobal") << " Testing Delta Phi Cut (" << lutObj0 << "," << lutObj1 << ") [" << (long long)(corrPar.minPhiCutValue*pow(10,preShift))
1956  << "," << (long long)(corrPar.maxPhiCutValue*pow(10,preShift)) << "] with precision = " << corrPar.precPhiCut <<"\n"
1957  << " deltaPhiLUT = " << deltaPhiLUT << "\n"
1958  << " Precision Shift = " << preShift << "\n"
1959  << " deltaPhi (shift)= " << (deltaPhiLUT/pow(10,preShift+corrPar.precPhiCut)) << "\n"
1960  << " deltaPhiPhy = " << deltaPhiPhy << std::endl;
1961 
1962  //if(preShift>0) deltaPhiLUT /= pow(10,preShift);
1963  if( deltaPhiLUT >= (long long)(corrPar.minPhiCutValue*pow(10,preShift)) &&
1964  deltaPhiLUT <= (long long)(corrPar.maxPhiCutValue*pow(10,preShift)) ) {
1965 
1966  LogDebug("L1TGlobal") << " Passed Delta Phi Cut [" << (long long)(corrPar.minPhiCutValue*pow(10,preShift))
1967  << "," << (long long)(corrPar.maxPhiCutValue*pow(10,preShift)) << "]" << std::endl;
1968 
1969  } else {
1970 
1971  LogDebug("L1TGlobal") << " Failed Delta Phi Cut [" << (long long)(corrPar.minPhiCutValue*pow(10,preShift))
1972  << "," << (long long)(corrPar.maxPhiCutValue*pow(10,preShift)) << "]" << std::endl;
1973  reqResult = false;
1974 
1975  }
1976  }
1977 
1978  if(corrPar.corrCutType & 0x4) {
1979 
1980  //Assumes Delta Eta and Delta Phi LUTs have the same precision
1981  unsigned int preShift = 2*precDeltaPhiLUT - corrPar.precDRCut;
1982  double deltaRSqPhy = deltaPhiPhy*deltaPhiPhy + deltaEtaPhy*deltaEtaPhy;
1983  long long deltaRSq = deltaEtaLUT*deltaEtaLUT + deltaPhiLUT*deltaPhiLUT;
1984 
1985  LogDebug("L1TGlobal") << " Testing Delta R Cut (" << lutObj0 << "," << lutObj1 << ") [" << (long long)(corrPar.minDRCutValue*pow(10,preShift))
1986  << "," << (long long)(corrPar.maxDRCutValue*pow(10,preShift)) << "] with precision = " << corrPar.precDRCut <<"\n"
1987  << " deltaPhiLUT = " << deltaPhiLUT << "\n"
1988  << " deltaEtaLUT = " << deltaEtaLUT << "\n"
1989  << " deltaRSqLUT = " << deltaRSq << "\n"
1990  << " Precision Shift = " << preShift << "\n"
1991  << " deltaRSqLUT (shift)= " << (deltaRSq/pow(10,preShift+corrPar.precDRCut)) << "\n"
1992  << " deltaRSqPhy = " << deltaRSqPhy << std::endl;
1993 
1994  //if(preShift>0) deltaRSq /= pow(10,preShift);
1995  if( deltaRSq >= (long long)(corrPar.minDRCutValue*pow(10,preShift)) &&
1996  deltaRSq <= (long long)(corrPar.maxDRCutValue*pow(10,preShift)) ) {
1997 
1998  LogDebug("L1TGlobal") << " Passed Delta R Cut [" << (long long)(corrPar.minDRCutValue*pow(10,preShift))
1999  << "," << (long long)(corrPar.maxDRCutValue*pow(10,preShift)) << "]" << std::endl;
2000 
2001  } else {
2002 
2003  LogDebug("L1TGlobal") << " Failed Delta R Cut [" << (int)(corrPar.minDRCutValue*pow(10,preShift))
2004  << "," << (long long)(corrPar.maxDRCutValue*pow(10,preShift)) << "]" << std::endl;
2005  reqResult = false;
2006  }
2007 
2008  }
2009 
2010  if(corrPar.corrCutType & 0x20) {
2011  // Two body pt: pt^2 = pt1^2+pt2^2+2*pt1*pt2*(cos(phi1)*cos(phi2)+sin(phi1)*sin(phi2)).
2012 
2013  LogDebug("L1TGlobal") << " corrPar.corrCutType: " << corrPar.corrCutType<< "\n";
2014 
2015  //calculate math sins and cosines for debugging
2016  double cosPhi1Phy = cos(phi0Phy);
2017  double sinPhi1Phy = sin(phi0Phy);
2018  double cosPhi2Phy = cos(phi1Phy);
2019  double sinPhi2Phy = sin(phi1Phy);
2020 
2021  double tbptSqPhy = et0Phy*et0Phy + et1Phy*et1Phy + 2*et0Phy*et1Phy*(cosPhi1Phy*cosPhi2Phy + sinPhi1Phy*sinPhi2Phy);
2022  // get values from LUT's
2023 
2024  const std::string& lutName0 = lutObj0;
2025  unsigned int precCosLUT0 = m_gtScales->getPrec_Cos(lutName0);
2026  unsigned int precSinLUT0 = m_gtScales->getPrec_Sin(lutName0);
2027 
2028  const std::string& lutName1 = lutObj1;
2029  unsigned int precCosLUT1 = m_gtScales->getPrec_Cos(lutName1);
2030  unsigned int precSinLUT1 = m_gtScales->getPrec_Sin(lutName1);
2031 
2032  if(precCosLUT0 - precCosLUT1 != 0) LogDebug("L1TGlobal") << "Warning: Cos LUTs for TwoBodyPt on different Precision" << std::endl;
2033  if(precSinLUT0 - precSinLUT1 != 0) LogDebug("L1TGlobal") << "Warning: Sin LUTs for TwoBodyPt on different Precision" << std::endl;
2034  if(precSinLUT0 - precCosLUT1 != 0) LogDebug("L1TGlobal") << "Warning: Sin and Cos LUTs for TwoBodyPt on different Precision" << std::endl;
2035  if(precSinLUT1 - precCosLUT0 != 0) LogDebug("L1TGlobal") << "Warning: Sin and Cos LUTs for TwoBodyPt on different Precision" << std::endl;
2036 
2037 
2038  long long cosPhi1LUT = m_gtScales->getLUT_Cos(lutName0,phiIndex0);
2039  long long sinPhi1LUT = m_gtScales->getLUT_Sin(lutName0,phiIndex0);
2040 
2041  long long cosPhi2LUT = m_gtScales->getLUT_Cos(lutName1,phiIndex1);
2042  long long sinPhi2LUT = m_gtScales->getLUT_Sin(lutName1,phiIndex1);
2043 
2044  // now get pt LUTs
2045  std::string lutName = lutObj0;
2046  lutName += "-ET";
2047  long long ptObj0 = m_gtScales->getLUT_Pt("TwoBody_" + lutName,etIndex0);
2048  unsigned int precPtLUTObj0 = m_gtScales->getPrec_Pt("TwoBody_" + lutName);
2049 
2050  lutName = lutObj1;
2051  lutName += "-ET";
2052  long long ptObj1 = m_gtScales->getLUT_Pt("TwoBody_" + lutName,etIndex1);
2053  unsigned int precPtLUTObj1 = m_gtScales->getPrec_Pt("TwoBody_" + lutName);
2054 
2055  LogTrace("L1TGlobal") << " TBPT Trig precisions:\t " << precCosLUT0 << "\t" << precCosLUT1 << "\t" << precSinLUT0 << "\t" << precSinLUT1;
2056  LogTrace("L1TGlobal") << " TBPT Pt precisions:\t " << precPtLUTObj0 << "\t" << precPtLUTObj1;
2057  LogTrace("L1TGlobal") << " TBPT Pt cut:\t " << corrPar.minTBPTCutValue << "\tPrecTBPTCut\t" << corrPar.precTBPTCut ;
2058  LogTrace("L1TGlobal") << " TBPT Pt1*Pt1 -- Phys:\t " << et0Phy*et0Phy << "\tHW:\t" << ptObj0*ptObj0*(pow(10,6));
2059  LogTrace("L1TGlobal") << " TBPT Pt2*Pt2 -- Phys:\t " << et1Phy*et1Phy << "\tHW:\t" << ptObj1*ptObj1*(pow(10,6));
2060  LogTrace("L1TGlobal") << " TBPT 2Pt1*Pt2 -- Phys:\t " << 2*et0Phy*et1Phy << "\tHW:\t" << 2*(ptObj0*pow(10,0))*(ptObj1*pow(10,0));
2061  LogTrace("L1TGlobal") << " TBPT Trig -- Phys:\t " << cosPhi1Phy*cosPhi2Phy + sinPhi1Phy*sinPhi2Phy << "\tHW:\t" << cosPhi1LUT*cosPhi2LUT + sinPhi1LUT*sinPhi2LUT;
2062 
2063  //double tbptSqPhy = et0Phy*et0Phy + et1Phy*et1Phy + 2*et0Phy*et1Phy*(cosPhi1Phy*cosPhi2Phy + sinPhi1Phy*sinPhi2Phy);
2064  long long tbptSqHW =
2065  ptObj0*ptObj0*(pow(10,2*precCosLUT0)) +
2066  ptObj1*ptObj1*(pow(10,2*precCosLUT0)) +
2067  2*ptObj0*ptObj1*(cosPhi1LUT*cosPhi2LUT + sinPhi1LUT*sinPhi2LUT);
2068 
2069  unsigned int preShift = precPtLUTObj0 + precPtLUTObj1 + 2*precCosLUT0;
2070 
2071  LogTrace("L1TGlobal") << "TBPT Result -- Phys: " << tbptSqPhy << "\tHW: " << tbptSqHW << "\tShifted\t" << tbptSqHW/pow(10,preShift) << std::endl;
2072 
2073  preShift=preShift - corrPar.precTBPTCut;
2074 
2075 
2076  LogDebug("L1TGlobal") << " Testing Two Body Pt Cut (" << lutObj0 << "," << lutObj1
2077  << ") [" << (long long)(corrPar.minTBPTCutValue*pow(10,preShift))
2078  << "," << (long long)(corrPar.maxTBPTCutValue*pow(10,preShift)) << "] with precision = " << corrPar.precTBPTCut <<"\n"
2079  << " etIndex0 = " << etIndex0 << " pt0LUT = " << ptObj0 << " PhyEt0 = " << et0Phy << "\n"
2080  << " etIndex1 = " << etIndex1 << " pt1LUT = " << ptObj1 << " PhyEt1 = " << et1Phy <<"\n"
2081  << " Precision Shift = " << preShift << "\n"
2082  << " Sin(phi1): LUT/Phys\t " << sinPhi1LUT << " / " << sinPhi1Phy << "\n"
2083  << " Sin(phi2): LUT/Phys\t " << sinPhi2LUT << " / " << sinPhi2Phy << "\n"
2084  << " Cos(phi1): LUT/Phys\t " << cosPhi1LUT << " / " << cosPhi1Phy << "\n"
2085  << " Cos(phi2): LUT/Phys\t " << cosPhi2LUT << " / " << cosPhi2Phy << "\n"
2086 
2087  // << " deltaPhiLUT = " << deltaPhiLUT << "\n"
2088  // << " deltaEtaLUT = " << deltaEtaLUT << "\n"
2089  // << " deltaRSqLUT = " << deltaRSq << "\n"
2090  // << " Precision Shift = " << preShift << "\n"
2091  // << " deltaRSqLUT (shift)= " << (deltaRSq/pow(10,preShift+corrPar.precDRCut)) << "\n"
2092  // << " deltaRSqPhy = " << deltaRSqPhy
2093  << std::endl;
2094 
2095  if( tbptSqHW > 0. &&
2096  tbptSqHW >= (long long)(corrPar.minTBPTCutValue*pow(10,preShift)) ) {
2097  LogDebug("L1TGlobal") << " Passed Two Body pT Cut [" << (long long)(corrPar.minTBPTCutValue*pow(10,preShift))
2098  << "]" << "\twith value: " << tbptSqHW << "\n"
2099  << "\tPhysics Cut[" << corrPar.minTBPTCutValue/pow(10,corrPar.precTBPTCut) << "]\tPhysics Value: " << tbptSqPhy
2100  << std::endl;
2101 
2102  } else {
2103 
2104  LogDebug("L1TGlobal") << " Failed Two Body pT Cut [" << (long long)(corrPar.minTBPTCutValue*pow(10,preShift))
2105  << "]" << "\t with value: " << tbptSqHW << "\n"
2106  << "\tPhysics Cut[" << corrPar.minTBPTCutValue/pow(10,corrPar.precTBPTCut) << "]\tPhysics Value: " << tbptSqPhy
2107  << std::endl;
2108  reqResult = false;
2109  }
2110  }
2111 
2112  if(corrPar.corrCutType & 0x8 || corrPar.corrCutType & 0x10) {
2113 
2114  //invariant mass calculation based on
2115  // M = sqrt(2*p1*p2(cosh(eta1-eta2) - cos(phi1 - phi2)))
2116  // but we calculate (1/2)M^2
2117  //
2118  double cosDeltaPhiPhy = cos(deltaPhiPhy);
2119  double coshDeltaEtaPhy = cosh(deltaEtaPhy);
2120  if (corrPar.corrCutType & 0x10) coshDeltaEtaPhy=1.;
2121  double massSqPhy = et0Phy*et1Phy*(coshDeltaEtaPhy - cosDeltaPhiPhy);
2122 
2123  long long cosDeltaPhiLUT = m_gtScales->getLUT_DeltaPhi_Cos(lutName,deltaPhiFW);
2124  unsigned int precCosLUT = m_gtScales->getPrec_DeltaPhi_Cos(lutName);
2125 
2126  long long coshDeltaEtaLUT;
2127  if (corrPar.corrCutType & 0x10) {
2128  coshDeltaEtaLUT=1*pow(10,precCosLUT);
2129  }else{
2130  coshDeltaEtaLUT = m_gtScales->getLUT_DeltaEta_Cosh(lutName,deltaEtaFW);
2131  unsigned int precCoshLUT = m_gtScales->getPrec_DeltaEta_Cosh(lutName);
2132  if(precCoshLUT - precCosLUT != 0) LogDebug("L1TGlobal") << "Warning: Cos and Cosh LUTs on different Precision" << std::endl;
2133  }
2134 
2135  std::string lutName = lutObj0;
2136  lutName += "-ET";
2137  long long ptObj0 = m_gtScales->getLUT_Pt("Mass_" + lutName,etIndex0);
2138  unsigned int precPtLUTObj0 = m_gtScales->getPrec_Pt("Mass_" + lutName);
2139 
2140  lutName = lutObj1;
2141  lutName += "-ET";
2142  long long ptObj1 = m_gtScales->getLUT_Pt("Mass_" + lutName,etIndex1);
2143  unsigned int precPtLUTObj1 = m_gtScales->getPrec_Pt("Mass_" + lutName);
2144 
2145  // Pt and Angles are at different precission.
2146  long long massSq = ptObj0*ptObj1*(coshDeltaEtaLUT - cosDeltaPhiLUT);
2147 
2148  //Note: There is an assumption here that Cos and Cosh have the same precission
2149  unsigned int preShift = precPtLUTObj0 + precPtLUTObj1 + precCosLUT - corrPar.precMassCut;
2150 
2151  LogDebug("L1TGlobal") << " Testing Invariant Mass (" << lutObj0 << "," << lutObj1 << ") [" << (long long)(corrPar.minMassCutValue*pow(10,preShift))
2152  << "," << (long long)(corrPar.maxMassCutValue*pow(10,preShift)) << "] with precision = " << corrPar.precMassCut <<"\n"
2153  << " deltaPhiLUT = " << deltaPhiLUT << " cosLUT = " << cosDeltaPhiLUT << "\n"
2154  << " deltaEtaLUT = " << deltaEtaLUT << " coshLUT = " << coshDeltaEtaLUT << "\n"
2155  << " etIndex0 = " << etIndex0 << " pt0LUT = " << ptObj0 << " PhyEt0 = " << et0Phy << "\n"
2156  << " etIndex1 = " << etIndex1 << " pt1LUT = " << ptObj1 << " PhyEt1 = " << et1Phy <<"\n"
2157  << " massSq/2 = " << massSq << "\n"
2158  << " Precision Shift = " << preShift << "\n"
2159  << " massSq (shift)= " << (massSq/pow(10,preShift+corrPar.precMassCut)) << "\n"
2160  << " deltaPhiPhy = " << deltaPhiPhy << " cos() = " << cosDeltaPhiPhy << "\n"
2161  << " deltaEtaPhy = " << deltaEtaPhy << " cosh()= " << coshDeltaEtaPhy << "\n"
2162  << " massSqPhy/2 = " << massSqPhy << " sqrt(|massSq|) = "<< sqrt(fabs(2.*massSqPhy)) << std::endl;
2163 
2164  //if(preShift>0) massSq /= pow(10,preShift);
2165  if( massSq >= 0 &&
2166  massSq >= (long long)(corrPar.minMassCutValue*pow(10,preShift)) &&
2167  massSq <= (long long)(corrPar.maxMassCutValue*pow(10,preShift)) ) {
2168 
2169  LogDebug("L1TGlobal") << " Passed Invariant Mass Cut [" << (long long)(corrPar.minMassCutValue*pow(10,preShift))
2170  << "," << (long long)(corrPar.maxMassCutValue*pow(10,preShift)) << "]" << std::endl;
2171 
2172  } else {
2173 
2174  LogDebug("L1TGlobal") << " Failed Invariant Mass Cut [" << (long long)(corrPar.minMassCutValue*pow(10,preShift))
2175  << "," << (long long)(corrPar.maxMassCutValue*pow(10,preShift)) << "]" << std::endl;
2176  reqResult = false;
2177  }
2178 
2179  }
2180 
2181  // For Muon-Muon Correlation Check the Charge Correlation if requested
2182  bool chrgCorrel = true;
2183  if(cond0Categ==CondMuon && cond1Categ==CondMuon) {
2184  // Check for like-sign
2185  if(corrPar.chargeCorrelation==2 && chrg0 != chrg1 ) chrgCorrel = false;
2186  // Check for opp-sign
2187  if(corrPar.chargeCorrelation==4 && chrg0 == chrg1 ) chrgCorrel = false;
2188  }
2189 
2190 
2191  if (reqResult & chrgCorrel) {
2192 
2193  condResult = true;
2194  (combinationsInCond()).push_back(objectsInComb);
2195 
2196  }
2197 
2198  } //end loop over second leg
2199 
2200  } //end loop over first leg
2201 
2202 
2203 
2204  if (m_verbosity && condResult) {
2205  LogDebug("L1TGlobal") << " pass(es) the correlation condition.\n" << std::endl;
2206  }
2207 
2208  return condResult;
2209 
2210 }
2211 
2212 // load calo candidates
2213 const l1t::L1Candidate* l1t::CorrWithOverlapRemovalCondition::getCandidate(const int bx, const int indexCand) const {
2214 
2215  // objectType() gives the type for nrObjects() only,
2216  // but in a CondCalo all objects have the same type
2217  // take type from the type of the first object
2219  case gtEG:
2220  return (m_uGtB->getCandL1EG())->at(bx,indexCand);
2221  break;
2222 
2223  case gtJet:
2224  return (m_uGtB->getCandL1Jet())->at(bx,indexCand);
2225  break;
2226 
2227  case gtTau:
2228  return (m_uGtB->getCandL1Tau())->at(bx,indexCand);
2229  break;
2230  default:
2231  return nullptr;
2232  break;
2233  }
2234 
2235  return nullptr;
2236 }
2237 
2248 
2249 
2250  return true;
2251 }
2252 
2253 void l1t::CorrWithOverlapRemovalCondition::print(std::ostream& myCout) const {
2254 
2255  myCout << "Dummy Print for CorrWithOverlapRemovalCondition" << std::endl;
2257 
2258 
2260 
2261 }
#define LogDebug(id)
type
Definition: HCALResponse.h:21
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 print(std::ostream &myCout) const override
print condition
Definition: MuCondition.cc:524
void setGtCorrelationWithOverlapRemovalTemplate(const CorrelationWithOverlapRemovalTemplate *)
std::vector< std::pair< double, double > > etaBins
Definition: GlobalScales.h:54
const CorrelationWithOverlapRemovalTemplate * gtCorrelationWithOverlapRemovalTemplate() const
get / set the pointer to a Condition
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 cond1Category() const
void print(std::ostream &myCout) const override
print the condition
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
void copy(const CorrWithOverlapRemovalCondition &cp)
copy function for copy constructor and operator=
const l1t::L1Candidate * getCandidate(const int bx, const int indexCand) const
load candidates
std::string l1TGtObjectEnumToString(const GlobalObject &)
Definition: GlobalObject.cc:90
bool condLastResult() const
get the latest result for the condition
const CorrelationWithOverlapRemovalTemplate * m_gtCorrelationWithOverlapRemovalTemplate
pointer to a CorrelationWithOverlapRemovalTemplate
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
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
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
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
const GlobalBoard * m_uGtB
pointer to uGt GlobalBoard, to be able to get the trigger objects
const bool checkObjectParameter(const int iCondition, const l1t::L1Candidate &cand) const
function to check a single object if it matches a condition
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
#define LogTrace(id)
long long getLUT_CalMuEta(const std::string &lutName, int element) const
const l1t::GtConditionCategory cond0Category() const
get / set the category of the thre sub-conditions
#define M_PI
std::vector< std::pair< double, double > > etBins
Definition: GlobalScales.h:44
long long getLUT_DeltaEta_Cosh(std::string lutName, int element) const
const BXVector< const l1t::Muon * > * getCandL1Mu() const
return global muon trigger candidate
Definition: GlobalBoard.h:143
int m_verbosity
verbosity level
long long getLUT_DeltaPhi(std::string lutName, int element) const
void print(std::ostream &myCout) const override
print condition
const CorrelationWithOverlapRemovalParameter * correlationParameter() const
get / set correlation parameters
bool m_condLastResult
the last result of evaluateCondition()
typedef for a single object template
Definition: GlobalScales.h:39
unsigned int getPrec_DeltaPhi(const std::string &lutName) const
const l1t::GtConditionCategory cond2Category() const
CorrWithOverlapRemovalCondition & operator=(const CorrWithOverlapRemovalCondition &)
void print(std::ostream &myCout) const override
print condition
const ScaleParameters & getMUScales() const
Definition: GlobalScales.h:83
const GlobalBoard * getuGtB() const
get / set the pointer to uGt GlobalBoard
const bool evaluateCondition(const int bxEval) const override
the core function to check if the condition matches
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...)
void setuGtB(const GlobalBoard *)
set the pointer to uGT GlobalBoard
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
const T & at(int bx, unsigned i) const