CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/L1TriggerConfig/L1GtConfigProducers/src/L1GtTriggerMenuTester.cc

Go to the documentation of this file.
00001 
00017 // this class header
00018 #include "L1TriggerConfig/L1GtConfigProducers/interface/L1GtTriggerMenuTester.h"
00019 
00020 // system include files
00021 #include <iomanip>
00022 #include <boost/algorithm/string/erase.hpp>
00023 
00024 // user include files
00025 //   base class
00026 #include "FWCore/Framework/interface/EDAnalyzer.h"
00027 
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00030 
00031 #include "FWCore/Framework/interface/EventSetup.h"
00032 #include "FWCore/Framework/interface/ESHandle.h"
00033 
00034 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenu.h"
00035 #include "CondFormats/DataRecord/interface/L1GtTriggerMenuRcd.h"
00036 
00037 #include "CondFormats/L1TObjects/interface/L1GtPrescaleFactors.h"
00038 
00039 #include "CondFormats/DataRecord/interface/L1GtPrescaleFactorsAlgoTrigRcd.h"
00040 #include "CondFormats/DataRecord/interface/L1GtPrescaleFactorsTechTrigRcd.h"
00041 
00042 #include "CondFormats/L1TObjects/interface/L1GtTriggerMask.h"
00043 
00044 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskAlgoTrigRcd.h"
00045 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskTechTrigRcd.h"
00046 
00047 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskVetoAlgoTrigRcd.h"
00048 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskVetoTechTrigRcd.h"
00049 
00050 #include "DataFormats/L1GlobalTrigger/interface/L1GtLogicParser.h"
00051 
00052 // forward declarations
00053 
00054 // constructor(s)
00055 L1GtTriggerMenuTester::L1GtTriggerMenuTester(const edm::ParameterSet& parSet) {
00056     // empty
00057 }
00058 
00059 // destructor
00060 L1GtTriggerMenuTester::~L1GtTriggerMenuTester() {
00061     // empty
00062 }
00063 
00064 // loop over events
00065 void L1GtTriggerMenuTester::analyze(const edm::Event& iEvent,
00066         const edm::EventSetup& evSetup) {
00067 
00068     edm::ESHandle< L1GtTriggerMenu> l1GtMenu;
00069     evSetup.get< L1GtTriggerMenuRcd>().get(l1GtMenu);
00070     (const_cast<L1GtTriggerMenu*>(l1GtMenu.product()))->buildGtConditionMap();
00071 
00072     // print with various level of verbosities
00073 
00074     int printVerbosity = 0;
00075     l1GtMenu->print(std::cout, printVerbosity);
00076     std::cout << std::flush << std::endl;
00077 
00078     printVerbosity = 1;
00079     l1GtMenu->print(std::cout, printVerbosity);
00080     std::cout << std::flush << std::endl;
00081 
00082     printVerbosity = 2;
00083     l1GtMenu->print(std::cout, printVerbosity);
00084     std::cout << std::flush << std::endl;
00085 
00086     //
00087     // print menu, prescale factors and trigger mask in wiki format
00088     //
00089 
00090     // L1 GT prescale factors for algorithm triggers
00091     edm::ESHandle< L1GtPrescaleFactors> l1GtPfAlgo;
00092     evSetup.get< L1GtPrescaleFactorsAlgoTrigRcd>().get(l1GtPfAlgo);
00093 
00094     int indexPfSet = 0; // FIXME
00095 
00096     std::vector<int> prescaleFactorsAlgoTrig =
00097         (l1GtPfAlgo->gtPrescaleFactors()).at(indexPfSet);
00098 
00099 
00100     // L1 GT prescale factors for technical triggers
00101     edm::ESHandle< L1GtPrescaleFactors> l1GtPfTech;
00102     evSetup.get< L1GtPrescaleFactorsTechTrigRcd>().get(l1GtPfTech);
00103 
00104     std::vector<int> prescaleFactorsTechTrig =
00105         (l1GtPfTech->gtPrescaleFactors()).at(indexPfSet);
00106 
00107 
00108     // L1 GT trigger masks for algorithm triggers
00109     edm::ESHandle< L1GtTriggerMask> l1GtTmAlgo;
00110     evSetup.get< L1GtTriggerMaskAlgoTrigRcd>().get(l1GtTmAlgo);
00111 
00112     std::vector<unsigned int> triggerMaskAlgoTrig = l1GtTmAlgo->gtTriggerMask();
00113 
00114 
00115     // L1 GT trigger masks for technical triggers
00116     edm::ESHandle< L1GtTriggerMask> l1GtTmTech;
00117     evSetup.get< L1GtTriggerMaskTechTrigRcd>().get(l1GtTmTech);
00118 
00119     std::vector<unsigned int> triggerMaskTechTrig = l1GtTmTech->gtTriggerMask();
00120 
00121 
00122     // L1 GT trigger veto masks for algorithm triggers
00123     edm::ESHandle< L1GtTriggerMask> l1GtTmVetoAlgo;
00124     evSetup.get< L1GtTriggerMaskVetoAlgoTrigRcd>().get(l1GtTmVetoAlgo);
00125 
00126     std::vector<unsigned int> triggerMaskVetoAlgoTrig = l1GtTmVetoAlgo->gtTriggerMask();
00127 
00128 
00129     // L1 GT trigger veto masks for technical triggers
00130     edm::ESHandle< L1GtTriggerMask> l1GtTmVetoTech;
00131     evSetup.get< L1GtTriggerMaskVetoTechTrigRcd>().get(l1GtTmVetoTech);
00132 
00133     std::vector<unsigned int> triggerMaskVetoTechTrig = l1GtTmVetoTech->gtTriggerMask();
00134 
00135     // set the index of physics DAQ partition TODO EventSetup?
00136     //int physicsDaqPartition = 0;
00137 
00138     // use another map <int, L1GtAlgorithm> to get the menu sorted after bit number
00139     // both algorithm and bit numbers are unique
00140     typedef std::map<int, const L1GtAlgorithm*>::const_iterator CItBit;
00141 
00142     //    algorithm triggers
00143     const AlgorithmMap& algorithmMap = l1GtMenu->gtAlgorithmMap();
00144 
00145 
00146     std::map<int, const L1GtAlgorithm*> algoBitToAlgo;
00147 
00148 
00149     std::map<std::string, const L1GtAlgorithm*> jetAlgoTrig;
00150     std::map<std::string, const L1GtAlgorithm*> egammaAlgoTrig;
00151     std::map<std::string, const L1GtAlgorithm*> esumAlgoTrig;
00152     std::map<std::string, const L1GtAlgorithm*> muonAlgoTrig;
00153     std::map<std::string, const L1GtAlgorithm*> crossAlgoTrig;
00154     std::map<std::string, const L1GtAlgorithm*> bkgdAlgoTrig;
00155 
00156     int algoTrigNumberTotal = 128; // FIXME take it from stable parameters
00157 
00158     int algoTrigNumber = 0;
00159     int freeAlgoTrigNumber = 0;
00160 
00161     int jetAlgoTrigNumber = 0;
00162     int egammaAlgoTrigNumber = 0;
00163     int esumAlgoTrigNumber = 0;
00164     int muonAlgoTrigNumber = 0;
00165     int crossAlgoTrigNumber = 0;
00166     int bkgdAlgoTrigNumber = 0;
00167 
00168     for (CItAlgo itAlgo = algorithmMap.begin(); itAlgo != algorithmMap.end(); itAlgo++) {
00169 
00170         const int bitNumber = (itAlgo->second).algoBitNumber();
00171         const std::string& algName = (itAlgo->second).algoName();
00172 
00173         algoBitToAlgo[bitNumber] = &(itAlgo->second);
00174 
00175         algoTrigNumber++;
00176 
00177         // per category
00178 
00179         const ConditionMap& conditionMap =
00180                 (l1GtMenu->gtConditionMap()).at((itAlgo->second).algoChipNumber());
00181 
00182         const std::vector<L1GtLogicParser::TokenRPN>& rpnVector = (itAlgo->second).algoRpnVector();
00183         const L1GtLogicParser::OperationType condOperand = L1GtLogicParser::OP_OPERAND;
00184 
00185         std::list<L1GtObject> listObjects;
00186 
00187         for (size_t i = 0; i < rpnVector.size(); ++i) {
00188 
00189             if ((rpnVector[i]).operation == condOperand) {
00190 
00191                 const std::string& cndName = (rpnVector[i]).operand;
00192 
00193                 // search the condition in the condition list
00194 
00195                 bool foundCond = false;
00196 
00197                 CItCond itCond = conditionMap.find(cndName);
00198                 if (itCond != conditionMap.end()) {
00199                     foundCond = true;
00200 
00201                     // loop through object types and add them to the list
00202 
00203                     const std::vector<L1GtObject>& objType =
00204                             (itCond->second)->objectType();
00205 
00206                     for (std::vector<L1GtObject>::const_iterator itObject =
00207                             objType.begin(); itObject != objType.end(); itObject++) {
00208                         listObjects.push_back(*itObject);
00209 
00210                         std::cout << (*itObject) << std::endl;
00211                     }
00212 
00213                     // FIXME
00214                     if ((itCond->second)->condCategory() == CondExternal) {
00215                         listObjects.push_back(GtExternal);
00216                     }
00217 
00218                 }
00219 
00220                 if (!foundCond) {
00221 
00222                     // it should never be happen, all conditions are in the maps
00223                     throw cms::Exception("FailModule") << "\nCondition "
00224                             << cndName << " not found in the condition map"
00225                             << " for chip number "
00226                             << ((itAlgo->second).algoChipNumber()) << std::endl;
00227                 }
00228 
00229             }
00230 
00231         }
00232 
00233         // eliminate duplicates
00234         listObjects.sort();
00235         listObjects.unique();
00236 
00237         // add the algorithm to the corresponding group
00238 
00239         bool jetGroup = false;
00240         bool egammaGroup = false;
00241         bool esumGroup = false;
00242         bool muonGroup = false;
00243         bool crossGroup = false;
00244         bool bkgdGroup = false;
00245 
00246         for (std::list<L1GtObject>::const_iterator itObj = listObjects.begin(); itObj != listObjects.end(); ++itObj) {
00247 
00248 
00249             switch (*itObj) {
00250                 case Mu: {
00251                     muonGroup = true;
00252                 }
00253 
00254                 break;
00255                 case NoIsoEG: {
00256                     egammaGroup = true;
00257                 }
00258 
00259                 break;
00260                 case IsoEG: {
00261                     egammaGroup = true;
00262                 }
00263 
00264                 break;
00265                 case CenJet: {
00266                     jetGroup = true;
00267                 }
00268 
00269                 break;
00270                 case ForJet: {
00271                     jetGroup = true;
00272                 }
00273 
00274                 break;
00275                 case TauJet: {
00276                     jetGroup = true;
00277                 }
00278 
00279                 break;
00280                 case ETM: {
00281                     esumGroup = true;
00282 
00283                 }
00284 
00285                 break;
00286                 case ETT: {
00287                     esumGroup = true;
00288 
00289                 }
00290 
00291                 break;
00292                 case HTT: {
00293                     esumGroup = true;
00294 
00295                 }
00296 
00297                 break;
00298                 case HTM: {
00299                     esumGroup = true;
00300 
00301                 }
00302 
00303                 break;
00304                 case JetCounts: {
00305                     // do nothing - not available
00306                 }
00307 
00308                 break;
00309                 case HfBitCounts: {
00310                     bkgdGroup = true;
00311                 }
00312 
00313                 break;
00314                 case HfRingEtSums: {
00315                     bkgdGroup = true;
00316                 }
00317 
00318                 break;
00319                 case GtExternal: {
00320                     bkgdGroup = true;
00321                 }
00322 
00323                 break;
00324                 case TechTrig:
00325                 case Castor:
00326                 case BPTX:
00327                 default: {
00328                     // should not arrive here
00329 
00330                     std::cout << "\n      Unknown object of type " << *itObj
00331                     << std::endl;
00332                 }
00333                 break;
00334             }
00335 
00336         }
00337 
00338 
00339         int sumGroup = jetGroup + egammaGroup + esumGroup + muonGroup
00340                 + crossGroup + bkgdGroup;
00341 
00342         if (sumGroup > 1) {
00343             crossAlgoTrig[algName] = &(itAlgo->second);
00344         } else {
00345 
00346             if (jetGroup) {
00347                 jetAlgoTrig[algName] = &(itAlgo->second);
00348 
00349             } else if (egammaGroup) {
00350                 egammaAlgoTrig[algName] = &(itAlgo->second);
00351 
00352             } else if (esumGroup && (listObjects.size() > 1)) {
00353                 crossAlgoTrig[algName] = &(itAlgo->second);
00354 
00355             } else if (esumGroup) {
00356                 esumAlgoTrig[algName] = &(itAlgo->second);
00357 
00358             } else if (muonGroup) {
00359                 muonAlgoTrig[algName] = &(itAlgo->second);
00360 
00361             } else if (bkgdGroup) {
00362                 bkgdAlgoTrig[algName] = &(itAlgo->second);
00363 
00364             } else {
00365                 // do nothing
00366             }
00367 
00368         }
00369 
00370         std::cout << algName << " sum: " << sumGroup << " size: " << listObjects.size() << std::endl;
00371 
00372     }
00373 
00374     freeAlgoTrigNumber = algoTrigNumberTotal - algoTrigNumber;
00375 
00376     jetAlgoTrigNumber = jetAlgoTrig.size();
00377     egammaAlgoTrigNumber = egammaAlgoTrig.size();
00378     esumAlgoTrigNumber = esumAlgoTrig.size();
00379     muonAlgoTrigNumber = muonAlgoTrig.size();
00380     crossAlgoTrigNumber = crossAlgoTrig.size();
00381     bkgdAlgoTrigNumber = bkgdAlgoTrig.size();
00382 
00383 
00384 
00385     //    technical triggers
00386     std::map<int, const L1GtAlgorithm*> techBitToAlgo;
00387     const AlgorithmMap& technicalTriggerMap = l1GtMenu->gtTechnicalTriggerMap();
00388 
00389     int techTrigNumberTotal = 64; // FIXME take it from stable parameters
00390 
00391     int techTrigNumber = 0;
00392     int freeTechTrigNumber = 0;
00393 
00394     for (CItAlgo itAlgo = technicalTriggerMap.begin(); itAlgo != technicalTriggerMap.end(); itAlgo++) {
00395 
00396         int bitNumber = (itAlgo->second).algoBitNumber();
00397         techBitToAlgo[bitNumber] = &(itAlgo->second);
00398 
00399         techTrigNumber++;
00400     }
00401 
00402     freeTechTrigNumber = techTrigNumberTotal - techTrigNumber;
00403 
00404     // name of the attached HTML file FIXME get it automatically from L1 Trigger Menu Implementation
00405     //m_htmlFile =  "%ATTACHURL%/L1Menu_Collisions2011_v6_L1T_Scales_20101224_Imp0_0x1024.html";
00406     //m_htmlFile =  "%ATTACHURL%/L1Menu_Collisions2012_v0_L1T_Scales_20101224_Imp0_0x1027.html";
00407     m_htmlFile =  "%ATTACHURL%/L1Menu_Collisions2012_v1_L1T_Scales_20101224_Imp0_0x1028.html";
00408 
00409 
00410     // header for printing algorithms
00411 
00412     std::cout << "\n   ********** L1 Trigger Menu - printing   ********** \n\n"
00413             << "\n---+++ L1 menu identification\n"
00414             << "\n|L1 Trigger Menu Interface: |!" << l1GtMenu->gtTriggerMenuInterface() << " |"
00415             << "\n|L1 Trigger Menu Name: |!" << l1GtMenu->gtTriggerMenuName() << " |"
00416             << "\n|L1 Trigger Menu Implementation: |!" << l1GtMenu->gtTriggerMenuImplementation() << " |"
00417             << "\n|Associated L1 scale DB key: |!" << l1GtMenu->gtScaleDbKey() << " |" << "\n\n"
00418             << std::flush << std::endl;
00419 
00420     // Overview page
00421     std::cout << "\n---+++ Summary\n" << std::endl;
00422     std::cout << "   * Number of algorithm triggers: " << algoTrigNumber << " defined, 128 possible." << std::endl;
00423     std::cout << "   * Number of technical triggers: " << techTrigNumber << " defined,  64 possible.<BR><BR>" << std::endl;
00424 
00425     std::cout << "   * Number of free bits for algorithm triggers: " << freeAlgoTrigNumber << std::endl;
00426     std::cout << "   * Number of free bits for technical triggers: " << freeTechTrigNumber << "<BR>" << std::endl;
00427 
00428     std::cout << "\nNumber of algorithm triggers per trigger group\n" << std::endl;
00429     std::cout << "    | *Trigger group* | *Number of bits used*|"<< std::endl;
00430     std::cout << "    | Jet algorithm triggers: |  " << jetAlgoTrigNumber << "|"<< std::endl;
00431     std::cout << "    | EGamma algorithm triggers: |  " << egammaAlgoTrigNumber << "|"<< std::endl;
00432     std::cout << "    | Energy sum algorithm triggers: |  " << esumAlgoTrigNumber << "|"<< std::endl;
00433     std::cout << "    | Muon algorithm triggers: |  " << muonAlgoTrigNumber << "|"<< std::endl;
00434     std::cout << "    | Cross algorithm triggers: |  " << crossAlgoTrigNumber << "|"<< std::endl;
00435     std::cout << "    | Background algorithm triggers: |  " << bkgdAlgoTrigNumber << "|"<< std::endl;
00436 
00437     // force a page break
00438     std::cout << "<p style=\"page-break-before: always\">&nbsp;</p>";
00439 
00440     std::cout << "\n---+++ List of algorithm triggers sorted by trigger groups\n" << std::endl;
00441 
00442     // Jet algorithm triggers
00443     printTriggerGroup("Jet algorithm triggers", jetAlgoTrig);
00444 
00445     // EGamma algorithm triggers
00446     printTriggerGroup("EGamma algorithm triggers", egammaAlgoTrig);
00447 
00448     // Energy sum algorithm triggers
00449     printTriggerGroup("Energy sum algorithm triggers", esumAlgoTrig);
00450 
00451     // Muon algorithm triggers
00452     printTriggerGroup("Muon algorithm triggers", muonAlgoTrig);
00453 
00454     // Cross algorithm triggers
00455     printTriggerGroup("Cross algorithm triggers", crossAlgoTrig);
00456 
00457     // Background algorithm triggers
00458     printTriggerGroup("Background algorithm triggers", bkgdAlgoTrig);
00459 
00460 
00461     // force a page break
00462     std::cout << "<p style=\"page-break-before: always\">&nbsp;</p>";
00463 
00464     std::cout << "\n---+++ List of algorithm triggers sorted by bits\n" << std::endl;
00465 
00466     std::cout
00467     << "| *Algorithm* | *Alias* | *Bit number* |"
00468     << std::endl;
00469 
00470     for (CItBit itBit = algoBitToAlgo.begin(); itBit != algoBitToAlgo.end(); itBit++) {
00471 
00472         int bitNumber = itBit->first;
00473         std::string aName = (itBit->second)->algoName();
00474         std::string aAlias = (itBit->second)->algoAlias();
00475 
00476         std::cout
00477         << "|" << std::left << aName << "  |" << aAlias << "  |  " << std::right << bitNumber
00478         << " |"
00479         << std::endl;
00480     }
00481 
00482 
00483     // force a page break
00484     std::cout << "<p style=\"page-break-before: always\">&nbsp;</p>";
00485     std::cout << "\n---+++ List of technical triggers\n" << std::endl;
00486 
00487     std::cout << "| *Technical trigger* | *Bit number* |" << std::endl;
00488 
00489     for (CItBit itBit = techBitToAlgo.begin(); itBit != techBitToAlgo.end(); itBit++) {
00490 
00491         int bitNumber = itBit->first;
00492         std::string aName = (itBit->second)->algoName();
00493         std::string aAlias = (itBit->second)->algoAlias();
00494 
00495         std::cout << "|!" << std::left << aName << "  |  " << std::right
00496                 << bitNumber << " |" << std::endl;
00497     }
00498 
00499 }
00500 
00501 
00502 // printing template for a trigger group
00503 void L1GtTriggerMenuTester::printTriggerGroup(const std::string& trigGroupName,
00504         const std::map<std::string, const L1GtAlgorithm*>& trigGroup) {
00505 
00506 
00507     // force a page break before each group
00508     std::cout << "<p style=\"page-break-before: always\">&nbsp;</p>";
00509 
00510     // FIXME get values - either read from a specific L1 menu file, or from
00511     std::string lumiVal1 = "5.0E33";
00512     std::string lumiVal2 = "7.0E33";
00513     std::string seedsHlt;
00514     std::string trigComment;
00515 
00516     int trigPfVal1 = 0;
00517     int trigPfVal2 = 0;
00518 
00519     int trigRateVal1 = 0;
00520     int trigRateVal2 = 0;
00521 
00522     std::cout << "\n---++++ " << trigGroupName << "\n" << std::endl;
00523 
00524     std::cout
00525             << "|  *Trigger Name*  |  *Trigger Alias*  |  *Bit*  |  *Luminosity*  ||||  *Seed for !HLT path(s)*  |  *Comments*  |"
00526             << std::endl;
00527 
00528     std::cout << "|^|^|^|  *" << lumiVal1 << "*  ||  *" << lumiVal2
00529             << "*  ||  **  |  **  |" << std::endl;
00530 
00531     std::cout << "|^|^|^|  *PF*  |  *Rate*  |  *PF*  |  *Rate*  |  ** |  **  |"
00532             << std::endl;
00533 
00534     for (CItAlgoP itAlgo = trigGroup.begin(); itAlgo != trigGroup.end(); itAlgo++) {
00535 
00536         const std::string& aName = (itAlgo->second)->algoName();
00537         const std::string& aAlias = (itAlgo->second)->algoAlias();
00538         const int& bitNumber = (itAlgo->second)->algoBitNumber();
00539 
00540         std::cout
00541                 << "|" << std::left << "[[" << (m_htmlFile + "#" + aName) << "][ " << aName << "]] " << "  |"
00542                 << aAlias << "  |  "
00543                 << bitNumber << "|  "
00544                 << ( (trigPfVal1 != 0) ? trigPfVal1 : 0) << "  |  "
00545                 << ( (trigRateVal1 != 0) ? trigRateVal1 : 0) << "  |  "
00546                 << ( (trigPfVal2 != 0) ? trigPfVal2 : 0) << "  |  "
00547                 << ( (trigRateVal2 != 0) ? trigRateVal2 : 0) << "  |  "
00548                 << seedsHlt << "  |  " << trigComment << "  |"<< std::endl;
00549     }
00550 
00551     std::cout << "\n" << trigGroupName << ": " << (trigGroup.size())
00552             << " bits defined." << std::endl;
00553 
00554 }
00555 
00556