Go to the documentation of this file.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 m_verbosity = cp.m_verbosity;
00112
00113 }
00114
00115 L1GtCaloCondition::L1GtCaloCondition(const L1GtCaloCondition& cp) :
00116 L1GtConditionEvaluation() {
00117
00118 copy(cp);
00119
00120 }
00121
00122
00123 L1GtCaloCondition::~L1GtCaloCondition() {
00124
00125
00126
00127 }
00128
00129
00130 L1GtCaloCondition& L1GtCaloCondition::operator= (const L1GtCaloCondition& cp)
00131 {
00132 copy(cp);
00133 return *this;
00134 }
00135
00136
00137 void L1GtCaloCondition::setGtCaloTemplate(const L1GtCaloTemplate* caloTempl) {
00138
00139 m_gtCaloTemplate = caloTempl;
00140
00141 }
00142
00143
00144 void L1GtCaloCondition::setGtIfCaloEtaNumberBits(const int& ifCaloEtaNumberBitsValue) {
00145
00146 m_ifCaloEtaNumberBits = ifCaloEtaNumberBitsValue;
00147
00148 }
00149
00151 void L1GtCaloCondition::setGtPSB(const L1GlobalTriggerPSB* ptrPSB) {
00152
00153 m_gtPSB = ptrPSB;
00154
00155 }
00156
00157
00158 const bool L1GtCaloCondition::evaluateCondition() const {
00159
00160
00161 int nObjInCond = m_gtCaloTemplate->nrObjects();
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171 const std::vector<const L1GctCand*>* candVec;
00172
00173 switch ((m_gtCaloTemplate->objectType())[0]) {
00174 case NoIsoEG:
00175 candVec = m_gtPSB->getCandL1NoIsoEG();
00176 break;
00177 case IsoEG:
00178 candVec = m_gtPSB->getCandL1IsoEG();
00179 break;
00180 case CenJet:
00181 candVec = m_gtPSB->getCandL1CenJet();
00182 break;
00183 case ForJet:
00184 candVec = m_gtPSB->getCandL1ForJet();
00185 break;
00186 case TauJet:
00187 candVec = m_gtPSB->getCandL1TauJet();
00188 break;
00189 default:
00190 return false;
00191 break;
00192 }
00193
00194 int numberObjects = candVec->size();
00195
00196
00197 if (numberObjects < nObjInCond) {
00198 return false;
00199 }
00200
00201 std::vector<int> index(numberObjects);
00202
00203 for (int i = 0; i < numberObjects; ++i) {
00204 index[i] = i;
00205 }
00206
00207 int jumpIndex = 1;
00208 int jump = factorial(numberObjects - nObjInCond);
00209
00210 int totalLoops = 0;
00211 int passLoops = 0;
00212
00213
00214
00215
00216 bool condResult = false;
00217
00218
00219
00220 SingleCombInCond objectsInComb;
00221 objectsInComb.reserve(nObjInCond);
00222
00223
00224 (*m_combinationsInCond).clear();
00225
00226 do {
00227
00228 if (--jumpIndex)
00229 continue;
00230
00231 jumpIndex = jump;
00232 totalLoops++;
00233
00234
00235 objectsInComb.clear();
00236
00237 bool tmpResult = true;
00238
00239
00240 for (int i = 0; i < nObjInCond; i++) {
00241
00242 tmpResult &= checkObjectParameter(i, *(*candVec)[index[i]]);
00243 objectsInComb.push_back(index[i]);
00244
00245 }
00246
00247
00248
00249 if (!tmpResult) {
00250
00251 continue;
00252
00253 }
00254
00255 if (m_gtCaloTemplate->wsc()) {
00256
00257
00258
00259
00260 const int ObjInWscComb = 2;
00261 if (nObjInCond != ObjInWscComb) {
00262
00263 if (m_verbosity) {
00264 edm::LogError("L1GtCaloCondition")
00265 << "\n Error: "
00266 << "number of particles in condition with spatial correlation = "
00267 << nObjInCond << "\n it must be = " << ObjInWscComb
00268 << std::endl;
00269 }
00270
00271 continue;
00272 }
00273
00274 L1GtCaloTemplate::CorrelationParameter corrPar =
00275 *(m_gtCaloTemplate->correlationParameter());
00276
00277 unsigned int candDeltaEta;
00278 unsigned int candDeltaPhi;
00279
00280
00281
00282
00283
00284 int signedEta[ObjInWscComb];
00285 int signBit[ObjInWscComb] = { 0, 0 };
00286
00287 int scaleEta = 1 << (m_ifCaloEtaNumberBits - 1);
00288
00289 for (int i = 0; i < ObjInWscComb; ++i) {
00290 signBit[i] = ((*candVec)[index[i]]->etaIndex() & scaleEta)
00291 >>(m_ifCaloEtaNumberBits - 1);
00292 signedEta[i] = ((*candVec)[index[i]]->etaIndex() )%scaleEta;
00293
00294 if (signBit[i] == 1) {
00295 signedEta[i] = (-1)*signedEta[i];
00296 }
00297
00298 }
00299
00300
00301 candDeltaEta = static_cast<int> (std::abs(signedEta[1] - signedEta[0]))
00302 + static_cast<int> (signBit[1]^signBit[0]);
00303
00304 if ( !checkBit(corrPar.deltaEtaRange, candDeltaEta) ) {
00305 continue;
00306 }
00307
00308
00309
00310
00311 if ((*candVec)[index[0]]->phiIndex()> (*candVec)[index[1]]->phiIndex()) {
00312 candDeltaPhi = (*candVec)[index[0]]->phiIndex() - (*candVec)[index[1]]->phiIndex();
00313 }
00314 else {
00315 candDeltaPhi = (*candVec)[index[1]]->phiIndex() - (*candVec)[index[0]]->phiIndex();
00316 }
00317
00318
00319
00320 while (candDeltaPhi> corrPar.deltaPhiMaxbits) {
00321
00322
00323 candDeltaPhi = (corrPar.deltaPhiMaxbits - 1)*2 - candDeltaPhi;
00324 if (m_verbosity) {
00325 LogTrace("L1GtCaloCondition")
00326 << " candDeltaPhi rescaled to: " << candDeltaPhi
00327 << std::endl;
00328 }
00329 }
00330
00331 if (!checkBit(corrPar.deltaPhiRange, candDeltaPhi)) {
00332 continue;
00333 }
00334
00335 }
00336
00337
00338
00339
00340 condResult = true;
00341 passLoops++;
00342 (*m_combinationsInCond).push_back(objectsInComb);
00343
00344
00345 } while (std::next_permutation(index.begin(), index.end()) );
00346
00347
00348
00349
00350
00351
00352 return condResult;
00353
00354 }
00355
00356
00357 const L1GctCand* L1GtCaloCondition::getCandidate(const int indexCand) const {
00358
00359
00360
00361
00362 switch ((m_gtCaloTemplate->objectType())[0]) {
00363 case NoIsoEG:
00364 return (*(m_gtPSB->getCandL1NoIsoEG()))[indexCand];
00365 break;
00366 case IsoEG:
00367 return (*(m_gtPSB->getCandL1IsoEG()))[indexCand];
00368 break;
00369 case CenJet:
00370 return (*(m_gtPSB->getCandL1CenJet()))[indexCand];
00371 break;
00372 case ForJet:
00373 return (*(m_gtPSB->getCandL1ForJet()))[indexCand];
00374 break;
00375 case TauJet:
00376 return (*(m_gtPSB->getCandL1TauJet()))[indexCand];
00377 break;
00378 default:
00379 return 0;
00380 break;
00381 }
00382
00383 return 0;
00384 }
00385
00395 const bool L1GtCaloCondition::checkObjectParameter(const int iCondition, const L1GctCand& cand) const {
00396
00397
00398 int nObjInCond = m_gtCaloTemplate->nrObjects();
00399
00400 if (iCondition >= nObjInCond || iCondition < 0) {
00401 return false;
00402 }
00403
00404
00405 if (cand.empty()) {
00406 return false;
00407 }
00408
00409 const L1GtCaloTemplate::ObjectParameter objPar = ( *(m_gtCaloTemplate->objectParameter()) )[iCondition];
00410
00411
00412 if ( !checkThreshold(objPar.etThreshold, cand.rank(), m_gtCaloTemplate->condGEq()) ) {
00413 return false;
00414 }
00415
00416
00417 if (!checkBit(objPar.etaRange, cand.etaIndex())) {
00418 return false;
00419 }
00420
00421
00422
00423 if (!checkBit(objPar.phiRange, cand.phiIndex())) {
00424 return false;
00425 }
00426
00427
00428
00429
00430
00431
00432 return true;
00433 }
00434
00435 void L1GtCaloCondition::print(std::ostream& myCout) const {
00436
00437 m_gtCaloTemplate->print(myCout);
00438 L1GtConditionEvaluation::print(myCout);
00439
00440 }
00441