Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-10 01:53:47

0001 // -*- C++ -*-
0002 //
0003 // L1TUtmTriggerMenuDumper:  Dump the menu to screen...
0004 //
0005 
0006 #include <iostream>
0007 #include <unistd.h>
0008 #include <cstdio>
0009 #include <cstdlib>
0010 
0011 #include "tmEventSetup/tmEventSetup.hh"
0012 #include "tmEventSetup/esTriggerMenu.hh"
0013 #include "tmEventSetup/esAlgorithm.hh"
0014 #include "tmEventSetup/esCondition.hh"
0015 #include "tmEventSetup/esObject.hh"
0016 #include "tmEventSetup/esCut.hh"
0017 #include "tmEventSetup/esScale.hh"
0018 #include "tmGrammar/Algorithm.hh"
0019 
0020 #include "FWCore/Framework/interface/Event.h"
0021 #include "FWCore/Framework/interface/EventSetup.h"
0022 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0023 #include "FWCore/Framework/interface/MakerMacros.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0025 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0026 #include "FWCore/Framework/interface/ESHandle.h"
0027 #include "FWCore/Utilities/interface/ESGetToken.h"
0028 
0029 #include "CondFormats/L1TObjects/interface/L1TUtmTriggerMenu.h"
0030 #include "CondFormats/DataRecord/interface/L1TUtmTriggerMenuRcd.h"
0031 
0032 using namespace edm;
0033 using namespace std;
0034 using namespace tmeventsetup;
0035 
0036 class L1TUtmTriggerMenuDumper : public one::EDAnalyzer<edm::one::WatchLuminosityBlocks, edm::one::WatchRuns> {
0037 public:
0038   explicit L1TUtmTriggerMenuDumper(const ParameterSet&);
0039   ~L1TUtmTriggerMenuDumper() override;
0040 
0041   static void fillDescriptions(ConfigurationDescriptions& descriptions);
0042 
0043 private:
0044   void beginJob() override;
0045   void analyze(Event const&, EventSetup const&) override;
0046   void endJob() override;
0047 
0048   void beginRun(Run const&, EventSetup const&) override;
0049   void endRun(Run const&, EventSetup const&) override;
0050   void beginLuminosityBlock(LuminosityBlock const&, EventSetup const&) override;
0051   void endLuminosityBlock(LuminosityBlock const&, EventSetup const&) override;
0052   edm::ESGetToken<L1TUtmTriggerMenu, L1TUtmTriggerMenuRcd> m_l1TriggerMenuToken;
0053 };
0054 
0055 L1TUtmTriggerMenuDumper::L1TUtmTriggerMenuDumper(const ParameterSet& iConfig)
0056     : m_l1TriggerMenuToken(esConsumes<L1TUtmTriggerMenu, L1TUtmTriggerMenuRcd, edm::Transition::BeginRun>()) {}
0057 
0058 L1TUtmTriggerMenuDumper::~L1TUtmTriggerMenuDumper() {}
0059 
0060 void L1TUtmTriggerMenuDumper::analyze(Event const& iEvent, EventSetup const& iSetup) {}
0061 
0062 void L1TUtmTriggerMenuDumper::beginJob() { cout << "INFO:  L1TUtmTriggerMenuDumper module beginJob called.\n"; }
0063 
0064 void L1TUtmTriggerMenuDumper::endJob() { cout << "INFO:  L1TUtmTriggerMenuDumper module endJob called.\n"; }
0065 
0066 void L1TUtmTriggerMenuDumper::beginRun(Run const& run, EventSetup const& iSetup) {
0067   edm::ESHandle<L1TUtmTriggerMenu> hmenu = iSetup.getHandle(m_l1TriggerMenuToken);
0068   const esTriggerMenu* menu = reinterpret_cast<const esTriggerMenu*>(hmenu.product());
0069 
0070   const std::map<std::string, esAlgorithm>& algoMap = menu->getAlgorithmMap();
0071   const std::map<std::string, esCondition>& condMap = menu->getConditionMap();
0072   const std::map<std::string, esScale>& scaleMap = menu->getScaleMap();
0073 
0074   bool hasPrecision = false;
0075   std::map<std::string, unsigned int> precisions;
0076   getPrecisions(precisions, scaleMap);
0077   for (std::map<std::string, unsigned int>::const_iterator cit = precisions.begin(); cit != precisions.end(); cit++) {
0078     std::cout << cit->first << " = " << cit->second << "\n";
0079     hasPrecision = true;
0080   }
0081 
0082   if (hasPrecision) {
0083     std::map<std::string, esScale>::iterator it1, it2;
0084     const esScale* scale1 = &scaleMap.find("EG-ETA")->second;
0085     const esScale* scale2 = &scaleMap.find("MU-ETA")->second;
0086 
0087     std::vector<long long> lut_eg_2_mu_eta;
0088     getCaloMuonEtaConversionLut(lut_eg_2_mu_eta, scale1, scale2);
0089 
0090     scale1 = &scaleMap.find("EG-PHI")->second;
0091     scale2 = &scaleMap.find("MU-PHI")->second;
0092 
0093     std::vector<long long> lut_eg_2_mu_phi;
0094     getCaloMuonPhiConversionLut(lut_eg_2_mu_phi, scale1, scale2);
0095 
0096     scale1 = &scaleMap.find("EG-ETA")->second;
0097     scale2 = &scaleMap.find("MU-ETA")->second;
0098 
0099     std::vector<double> eg_mu_delta_eta;
0100     std::vector<long long> lut_eg_mu_delta_eta;
0101     size_t n = getDeltaVector(eg_mu_delta_eta, scale1, scale2);
0102     setLut(lut_eg_mu_delta_eta, eg_mu_delta_eta, precisions["PRECISION-EG-MU-Delta"]);
0103 
0104     std::vector<long long> lut_eg_mu_cosh;
0105     applyCosh(eg_mu_delta_eta, n);
0106     setLut(lut_eg_mu_cosh, eg_mu_delta_eta, precisions["PRECISION-EG-MU-Math"]);
0107 
0108     scale1 = &scaleMap.find("EG-PHI")->second;
0109     scale2 = &scaleMap.find("MU-PHI")->second;
0110 
0111     std::vector<double> eg_mu_delta_phi;
0112     std::vector<long long> lut_eg_mu_delta_phi;
0113     n = getDeltaVector(eg_mu_delta_phi, scale1, scale2);
0114     setLut(lut_eg_mu_delta_phi, eg_mu_delta_phi, precisions["PRECISION-EG-MU-Delta"]);
0115 
0116     std::vector<long long> lut_eg_mu_cos;
0117     applyCos(eg_mu_delta_phi, n);
0118     setLut(lut_eg_mu_cos, eg_mu_delta_phi, precisions["PRECISION-EG-MU-Math"]);
0119 
0120     scale1 = &scaleMap.find("EG-ET")->second;
0121     std::vector<long long> lut_eg_et;
0122     getLut(lut_eg_et, scale1, precisions["PRECISION-EG-MU-MassPt"]);
0123 
0124     scale1 = &scaleMap.find("MU-ET")->second;
0125     std::vector<long long> lut_mu_et;
0126     getLut(lut_mu_et, scale1, precisions["PRECISION-EG-MU-MassPt"]);
0127     for (size_t ii = 0; ii < lut_mu_et.size(); ii++) {
0128       std::cout << lut_mu_et.at(ii) << "\n";
0129     }
0130   }
0131 
0132   for (std::map<std::string, esAlgorithm>::const_iterator cit = algoMap.begin(); cit != algoMap.end(); cit++) {
0133     const esAlgorithm& algo = cit->second;
0134     std::cout << "algo name = " << algo.getName() << "\n";
0135     std::cout << "algo exp. = " << algo.getExpression() << "\n";
0136     std::cout << "algo exp. in cond. = " << algo.getExpressionInCondition() << "\n";
0137 
0138     const std::vector<std::string>& rpn_vec = algo.getRpnVector();
0139     for (size_t ii = 0; ii < rpn_vec.size(); ii++) {
0140       const std::string& token = rpn_vec.at(ii);
0141       if (Algorithm::isGate(token))
0142         continue;
0143       const esCondition& condition = condMap.find(token)->second;
0144       std::cout << "  cond type = " << condition.getType() << "\n";
0145 
0146       const std::vector<esCut>& cuts = condition.getCuts();
0147       for (size_t jj = 0; jj < cuts.size(); jj++) {
0148         const esCut& cut = cuts.at(jj);
0149         std::cout << "    cut name = " << cut.getName() << "\n";
0150         std::cout << "    cut target = " << cut.getObjectType() << "\n";
0151         std::cout << "    cut type = " << cut.getCutType() << "\n";
0152         std::cout << "    cut min. value  index = " << cut.getMinimum().value << " " << cut.getMinimum().index << "\n";
0153         std::cout << "    cut max. value  index = " << cut.getMaximum().value << " " << cut.getMaximum().index << "\n";
0154         std::cout << "    cut data = " << cut.getData() << "\n";
0155       }
0156 
0157       const std::vector<esObject>& objects = condition.getObjects();
0158       for (size_t jj = 0; jj < objects.size(); jj++) {
0159         const esObject& object = objects.at(jj);
0160         std::cout << "      obj name = " << object.getName() << "\n";
0161         std::cout << "      obj type = " << object.getType() << "\n";
0162         std::cout << "      obj op = " << object.getComparisonOperator() << "\n";
0163         std::cout << "      obj bx = " << object.getBxOffset() << "\n";
0164         if (object.getType() == esObjectType::EXT) {
0165           std::cout << "      ext name  = " << object.getExternalSignalName() << "\n";
0166           std::cout << "      ext ch id = " << object.getExternalChannelId() << "\n";
0167         }
0168 
0169         const std::vector<esCut>& cuts = object.getCuts();
0170         for (size_t kk = 0; kk < cuts.size(); kk++) {
0171           const esCut& cut = cuts.at(kk);
0172           std::cout << "        cut name = " << cut.getName() << "\n";
0173           std::cout << "        cut target = " << cut.getObjectType() << "\n";
0174           std::cout << "        cut type = " << cut.getCutType() << "\n";
0175           std::cout << "        cut min. value  index = " << cut.getMinimum().value << " " << cut.getMinimum().index
0176                     << "\n";
0177           std::cout << "        cut max. value  index = " << cut.getMaximum().value << " " << cut.getMaximum().index
0178                     << "\n";
0179           std::cout << "        cut data = " << cut.getData() << "\n";
0180         }
0181       }
0182     }
0183   }
0184 }
0185 
0186 void L1TUtmTriggerMenuDumper::endRun(Run const&, EventSetup const&) {}
0187 
0188 void L1TUtmTriggerMenuDumper::beginLuminosityBlock(LuminosityBlock const&, EventSetup const&) {}
0189 
0190 void L1TUtmTriggerMenuDumper::endLuminosityBlock(LuminosityBlock const&, EventSetup const&) {}
0191 
0192 void L1TUtmTriggerMenuDumper::fillDescriptions(ConfigurationDescriptions& descriptions) {
0193   //The following says we do not know what parameters are allowed so do no validation
0194   // Please change this to state exactly what you do use, even if it is no parameters
0195   ParameterSetDescription desc;
0196   desc.setUnknown();
0197   descriptions.addDefault(desc);
0198 }
0199 
0200 DEFINE_FWK_MODULE(L1TUtmTriggerMenuDumper);