00001
00017
00018 #include "L1Trigger/GlobalTrigger/interface/L1GtCaloCondition.h"
00019
00020
00021 #include <iostream>
00022 #include <iomanip>
00023
00024 #include <string>
00025 #include <vector>
00026 #include <algorithm>
00027
00028
00029
00030 #include "CondFormats/L1TObjects/interface/L1GtCaloTemplate.h"
00031 #include "L1Trigger/GlobalTrigger/interface/L1GtConditionEvaluation.h"
00032
00033 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetupFwd.h"
00034
00035 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctCand.h"
00036 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctEmCand.h"
00037 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctJetCand.h"
00038
00039 #include "CondFormats/L1TObjects/interface/L1GtStableParameters.h"
00040 #include "CondFormats/DataRecord/interface/L1GtStableParametersRcd.h"
00041
00042 #include "L1Trigger/GlobalTrigger/interface/L1GlobalTriggerFunctions.h"
00043 #include "L1Trigger/GlobalTrigger/interface/L1GlobalTriggerPSB.h"
00044
00045 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00046 #include "FWCore/MessageLogger/interface/MessageDrop.h"
00047
00048
00049
00050 L1GtCaloCondition::L1GtCaloCondition() :
00051 L1GtConditionEvaluation() {
00052
00053 m_ifCaloEtaNumberBits = -1;
00054
00055 }
00056
00057
00058 L1GtCaloCondition::L1GtCaloCondition(const L1GtCondition* caloTemplate, const L1GlobalTriggerPSB* ptrPSB,
00059 const int nrL1NoIsoEG,
00060 const int nrL1IsoEG,
00061 const int nrL1CenJet,
00062 const int nrL1ForJet,
00063 const int nrL1TauJet,
00064 const int ifCaloEtaNumberBits) :
00065 L1GtConditionEvaluation(),
00066 m_gtCaloTemplate(static_cast<const L1GtCaloTemplate*>(caloTemplate)),
00067 m_gtPSB(ptrPSB),
00068 m_ifCaloEtaNumberBits(ifCaloEtaNumberBits)
00069 {
00070
00071
00072
00073
00074
00075
00076 switch ((m_gtCaloTemplate->objectType())[0]) {
00077 case NoIsoEG:
00078 m_condMaxNumberObjects = nrL1NoIsoEG;
00079 break;
00080 case IsoEG:
00081 m_condMaxNumberObjects = nrL1IsoEG;
00082 break;
00083 case CenJet:
00084 m_condMaxNumberObjects = nrL1CenJet;
00085 break;
00086 case ForJet:
00087 m_condMaxNumberObjects = nrL1ForJet;
00088 break;
00089 case TauJet:
00090 m_condMaxNumberObjects = nrL1TauJet;
00091 break;
00092 default:
00093 m_condMaxNumberObjects = 0;
00094 break;
00095 }
00096
00097 }
00098
00099
00100 void L1GtCaloCondition::copy(const L1GtCaloCondition &cp) {
00101
00102 m_gtCaloTemplate = cp.gtCaloTemplate();
00103 m_gtPSB = cp.gtPSB();
00104
00105 m_ifCaloEtaNumberBits = cp.gtIfCaloEtaNumberBits();
00106
00107 m_condMaxNumberObjects = cp.condMaxNumberObjects();
00108 m_condLastResult = cp.condLastResult();
00109 m_combinationsInCond = cp.getCombinationsInCond();
00110
00111 }
00112
00113 L1GtCaloCondition::L1GtCaloCondition(const L1GtCaloCondition& cp) :
00114 L1GtConditionEvaluation() {
00115
00116 copy(cp);
00117
00118 }
00119
00120
00121 L1GtCaloCondition::~L1GtCaloCondition() {
00122
00123
00124
00125 }
00126
00127
00128 L1GtCaloCondition& L1GtCaloCondition::operator= (const L1GtCaloCondition& cp)
00129 {
00130 copy(cp);
00131 return *this;
00132 }
00133
00134
00135 void L1GtCaloCondition::setGtCaloTemplate(const L1GtCaloTemplate* caloTempl) {
00136
00137 m_gtCaloTemplate = caloTempl;
00138
00139 }
00140
00141
00142 void L1GtCaloCondition::setGtIfCaloEtaNumberBits(const int& ifCaloEtaNumberBitsValue) {
00143
00144 m_ifCaloEtaNumberBits = ifCaloEtaNumberBitsValue;
00145
00146 }
00147
00149 void L1GtCaloCondition::setGtPSB(const L1GlobalTriggerPSB* ptrPSB) {
00150
00151 m_gtPSB = ptrPSB;
00152
00153 }
00154
00155
00156 const bool L1GtCaloCondition::evaluateCondition() const {
00157
00158
00159 int nObjInCond = m_gtCaloTemplate->nrObjects();
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 const std::vector<const L1GctCand*>* candVec;
00170
00171 switch ((m_gtCaloTemplate->objectType())[0]) {
00172 case NoIsoEG:
00173 candVec = m_gtPSB->getCandL1NoIsoEG();
00174 break;
00175 case IsoEG:
00176 candVec = m_gtPSB->getCandL1IsoEG();
00177 break;
00178 case CenJet:
00179 candVec = m_gtPSB->getCandL1CenJet();
00180 break;
00181 case ForJet:
00182 candVec = m_gtPSB->getCandL1ForJet();
00183 break;
00184 case TauJet:
00185 candVec = m_gtPSB->getCandL1TauJet();
00186 break;
00187 default:
00188 return false;
00189 break;
00190 }
00191
00192 int numberObjects = candVec->size();
00193
00194
00195 if (numberObjects < nObjInCond) {
00196 return false;
00197 }
00198
00199 std::vector<int> index(numberObjects);
00200
00201 for (int i = 0; i < numberObjects; ++i) {
00202 index[i] = i;
00203 }
00204
00205 int jumpIndex = 1;
00206 int jump = factorial(numberObjects - nObjInCond);
00207
00208 int totalLoops = 0;
00209 int passLoops = 0;
00210
00211
00212
00213
00214 bool condResult = false;
00215
00216
00217
00218 SingleCombInCond objectsInComb;
00219 objectsInComb.reserve(nObjInCond);
00220
00221
00222 (*m_combinationsInCond).clear();
00223
00224 do {
00225
00226 if (--jumpIndex)
00227 continue;
00228
00229 jumpIndex = jump;
00230 totalLoops++;
00231
00232
00233 objectsInComb.clear();
00234
00235 bool tmpResult = true;
00236
00237
00238 for (int i = 0; i < nObjInCond; i++) {
00239
00240 tmpResult &= checkObjectParameter(i, *(*candVec)[index[i]]);
00241 objectsInComb.push_back(index[i]);
00242
00243 }
00244
00245
00246
00247 if (!tmpResult) {
00248
00249 continue;
00250
00251 }
00252
00253 if (m_gtCaloTemplate->wsc()) {
00254
00255
00256
00257
00258 const int ObjInWscComb = 2;
00259 if (nObjInCond != ObjInWscComb) {
00260 edm::LogError("L1GtCaloCondition") << "\n Error: "
00261 << "number of particles in condition with spatial correlation = " << nObjInCond
00262 << "\n it must be = " << ObjInWscComb << std::endl;
00263
00264
00265 continue;
00266 }
00267
00268 L1GtCaloTemplate::CorrelationParameter corrPar =
00269 *(m_gtCaloTemplate->correlationParameter());
00270
00271 unsigned int candDeltaEta;
00272 unsigned int candDeltaPhi;
00273
00274
00275
00276
00277
00278 int signedEta[ObjInWscComb];
00279 int signBit[ObjInWscComb] = { 0, 0 };
00280
00281 int scaleEta = 1 << (m_ifCaloEtaNumberBits - 1);
00282
00283 for (int i = 0; i < ObjInWscComb; ++i) {
00284 signBit[i] = ((*candVec)[index[i]]->etaIndex() & scaleEta)
00285 >>(m_ifCaloEtaNumberBits - 1);
00286 signedEta[i] = ((*candVec)[index[i]]->etaIndex() )%scaleEta;
00287
00288 if (signBit[i] == 1) {
00289 signedEta[i] = (-1)*signedEta[i];
00290 }
00291
00292 }
00293
00294
00295 candDeltaEta = static_cast<int> (std::abs(signedEta[1] - signedEta[0]))
00296 + static_cast<int> (signBit[1]^signBit[0]);
00297
00298 if ( !checkBit(corrPar.deltaEtaRange, candDeltaEta) ) {
00299 continue;
00300 }
00301
00302
00303
00304
00305 if ((*candVec)[index[0]]->phiIndex()> (*candVec)[index[1]]->phiIndex()) {
00306 candDeltaPhi = (*candVec)[index[0]]->phiIndex() - (*candVec)[index[1]]->phiIndex();
00307 }
00308 else {
00309 candDeltaPhi = (*candVec)[index[1]]->phiIndex() - (*candVec)[index[0]]->phiIndex();
00310 }
00311
00312
00313
00314 while (candDeltaPhi> corrPar.deltaPhiMaxbits) {
00315
00316
00317 candDeltaPhi = (corrPar.deltaPhiMaxbits - 1)*2 - candDeltaPhi;
00318 LogTrace("L1GtCaloCondition") << " candDeltaPhi rescaled to: " << candDeltaPhi
00319 << std::endl;
00320 }
00321
00322 if (!checkBit(corrPar.deltaPhiRange, candDeltaPhi)) {
00323 continue;
00324 }
00325
00326 }
00327
00328
00329
00330
00331 condResult = true;
00332 passLoops++;
00333 (*m_combinationsInCond).push_back(objectsInComb);
00334
00335
00336 } while (std::next_permutation(index.begin(), index.end()) );
00337
00338
00339
00340
00341
00342
00343 return condResult;
00344
00345 }
00346
00347
00348 const L1GctCand* L1GtCaloCondition::getCandidate(const int indexCand) const {
00349
00350
00351
00352
00353 switch ((m_gtCaloTemplate->objectType())[0]) {
00354 case NoIsoEG:
00355 return (*(m_gtPSB->getCandL1NoIsoEG()))[indexCand];
00356 break;
00357 case IsoEG:
00358 return (*(m_gtPSB->getCandL1IsoEG()))[indexCand];
00359 break;
00360 case CenJet:
00361 return (*(m_gtPSB->getCandL1CenJet()))[indexCand];
00362 break;
00363 case ForJet:
00364 return (*(m_gtPSB->getCandL1ForJet()))[indexCand];
00365 break;
00366 case TauJet:
00367 return (*(m_gtPSB->getCandL1TauJet()))[indexCand];
00368 break;
00369 default:
00370 return 0;
00371 break;
00372 }
00373
00374 return 0;
00375 }
00376
00386 const bool L1GtCaloCondition::checkObjectParameter(const int iCondition, const L1GctCand& cand) const {
00387
00388
00389 int nObjInCond = m_gtCaloTemplate->nrObjects();
00390
00391 if (iCondition >= nObjInCond || iCondition < 0) {
00392 return false;
00393 }
00394
00395
00396 if (cand.empty()) {
00397 return false;
00398 }
00399
00400 const L1GtCaloTemplate::ObjectParameter objPar = ( *(m_gtCaloTemplate->objectParameter()) )[iCondition];
00401
00402
00403 if ( !checkThreshold(objPar.etThreshold, cand.rank(), m_gtCaloTemplate->condGEq()) ) {
00404 return false;
00405 }
00406
00407
00408 if (!checkBit(objPar.etaRange, cand.etaIndex())) {
00409 return false;
00410 }
00411
00412
00413
00414 if (!checkBit(objPar.phiRange, cand.phiIndex())) {
00415 return false;
00416 }
00417
00418
00419
00420
00421
00422
00423 return true;
00424 }
00425
00426 void L1GtCaloCondition::print(std::ostream& myCout) const {
00427
00428 m_gtCaloTemplate->print(myCout);
00429 L1GtConditionEvaluation::print(myCout);
00430
00431 }
00432