CMS 3D CMS Logo

L1GtCaloCondition.cc

Go to the documentation of this file.
00001 
00017 // this class header
00018 #include "L1Trigger/GlobalTrigger/interface/L1GtCaloCondition.h"
00019 
00020 // system include files
00021 #include <iostream>
00022 #include <iomanip>
00023 
00024 #include <string>
00025 #include <vector>
00026 #include <algorithm>
00027 
00028 // user include files
00029 //   base classes
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 // constructors
00049 //     default
00050 L1GtCaloCondition::L1GtCaloCondition() :
00051     L1GtConditionEvaluation() {
00052 
00053     m_ifCaloEtaNumberBits = -1;
00054 
00055 }
00056 
00057 //     from base template condition (from event setup usually)
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     // maximum number of objects received for the evaluation of the condition
00072     // retrieved before from event setup
00073     // for a CondCalo, all objects ar of same type, hence it is enough to get the
00074     // type for the first object
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 // copy constructor
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 // destructor
00121 L1GtCaloCondition::~L1GtCaloCondition() {
00122 
00123     // empty
00124 
00125 }
00126 
00127 // equal operator
00128 L1GtCaloCondition& L1GtCaloCondition::operator= (const L1GtCaloCondition& cp)
00129 {
00130     copy(cp);
00131     return *this;
00132 }
00133 
00134 // methods
00135 void L1GtCaloCondition::setGtCaloTemplate(const L1GtCaloTemplate* caloTempl) {
00136 
00137     m_gtCaloTemplate = caloTempl;
00138 
00139 }
00140 
00141 //   set the number of bits for eta of calorimeter objects
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 // try all object permutations and check spatial correlations, if required
00156 const bool L1GtCaloCondition::evaluateCondition() const {
00157 
00158     // number of trigger objects in the condition
00159     int nObjInCond = m_gtCaloTemplate->nrObjects();
00160     //LogTrace("L1GtCaloCondition") << "  nObjInCond: " << nObjInCond
00161     //    << std::endl;
00162 
00163     // the candidates
00164 
00165     // objectType() gives the type for nrObjects() only,
00166     // but in a CondCalo all objects have the same type
00167     // take type from the type of the first object
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     //LogTrace("L1GtCaloCondition") << "  numberObjects: " << numberObjects
00194     //    << std::endl;
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     // condition result condResult set to true if at least one permutation
00212     //     passes all requirements
00213     // all possible permutations are checked
00214     bool condResult = false;
00215 
00216     // store the indices of the calorimeter objects
00217     // from the combination evaluated in the condition
00218     SingleCombInCond objectsInComb;
00219     objectsInComb.reserve(nObjInCond);
00220 
00221     // clear the m_combinationsInCond vector
00222     (*m_combinationsInCond).clear();
00223 
00224     do {
00225 
00226         if (--jumpIndex)
00227             continue;
00228 
00229         jumpIndex = jump;
00230         totalLoops++;
00231 
00232         // clear the indices in the combination
00233         objectsInComb.clear();
00234 
00235         bool tmpResult = true;
00236 
00237         // check if there is a permutation that matches object-parameter requirements
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         // if permutation does not match particle conditions
00246         // skip spatial correlations
00247         if (!tmpResult) {
00248 
00249             continue;
00250 
00251         }
00252 
00253         if (m_gtCaloTemplate->wsc()) {
00254 
00255             // wsc requirements have always nObjInCond = 2
00256             // one can use directly index[0] and index[1] to compute
00257             // eta and phi differences
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                 // TODO Perhaps I should throw here an exception,
00264                 // since something is really wrong if nObjInCond != ObjInWscComb (=2)
00265                 continue;
00266             }
00267 
00268             L1GtCaloTemplate::CorrelationParameter corrPar =
00269                 *(m_gtCaloTemplate->correlationParameter());
00270 
00271             unsigned int candDeltaEta;
00272             unsigned int candDeltaPhi;
00273 
00274             // check candDeltaEta
00275 
00276             // get eta index and the sign bit of the eta index (MSB is the sign)
00277             //   signedEta[i] is the signed eta index of candVec[index[i]]
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             // compute candDeltaEta - add 1 if signs are different (due to +0/-0 indices)
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             // check candDeltaPhi
00303 
00304             // calculate absolute value of candDeltaPhi
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             // check if candDeltaPhi > 180 (via delta_phi_maxbits)
00313             // delta_phi contains bits for 0..180 (0 and 180 included)
00314             while (candDeltaPhi> corrPar.deltaPhiMaxbits) {
00315 
00316                 // candDeltaPhi > 180 ==> take 360 - candDeltaPhi
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         } // end wsc check
00327 
00328         // if we get here all checks were successfull for this combination
00329         // set the general result for evaluateCondition to "true"
00330 
00331         condResult = true;
00332         passLoops++;
00333         (*m_combinationsInCond).push_back(objectsInComb);
00334 
00335         //    } while ( std::next_permutation(index, index + nObj) );
00336     } while (std::next_permutation(index.begin(), index.end()) );
00337 
00338     //LogTrace("L1GtCaloCondition")
00339     //    << "\n  L1GtCaloCondition: total number of permutations found:          " << totalLoops
00340     //    << "\n  L1GtCaloCondition: number of permutations passing requirements: " << passLoops
00341     //    << "\n" << std::endl;
00342 
00343     return condResult;
00344 
00345 }
00346 
00347 // load calo candidates
00348 const L1GctCand* L1GtCaloCondition::getCandidate(const int indexCand) const {
00349 
00350     // objectType() gives the type for nrObjects() only,
00351     // but in a CondCalo all objects have the same type
00352     // take type from the type of the first object
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     // number of objects in condition
00389     int nObjInCond = m_gtCaloTemplate->nrObjects();
00390 
00391     if (iCondition >= nObjInCond || iCondition < 0) {
00392         return false;
00393     }
00394 
00395     // empty candidates can not be compared
00396     if (cand.empty()) {
00397         return false;
00398     }
00399 
00400     const L1GtCaloTemplate::ObjectParameter objPar = ( *(m_gtCaloTemplate->objectParameter()) )[iCondition];
00401 
00402     // check energy threshold
00403     if ( !checkThreshold(objPar.etThreshold, cand.rank(), m_gtCaloTemplate->condGEq()) ) {
00404         return false;
00405     }
00406 
00407     // check eta
00408     if (!checkBit(objPar.etaRange, cand.etaIndex())) {
00409         return false;
00410     }
00411 
00412     // check phi
00413 
00414     if (!checkBit(objPar.phiRange, cand.phiIndex())) {
00415         return false;
00416     }
00417 
00418     // particle matches if we get here
00419     //LogTrace("L1GtCaloCondition")
00420     //    << "  checkObjectParameter: calorimeter object OK, passes all requirements\n" 
00421     //    << std::endl;
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 

Generated on Tue Jun 9 17:40:14 2009 for CMSSW by  doxygen 1.5.4