Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:22:54

0001 ///
0002 /// \class L1TUtmTriggerMenuESProducer
0003 ///
0004 /// Description: Produces L1T Trigger Menu Condition Format
0005 ///
0006 /// Implementation:
0007 ///    Dummy producer for L1T uGT Trigger Menu
0008 ///
0009 
0010 // system include files
0011 #include <memory>
0012 #include <iostream>
0013 #include <fstream>
0014 #include <unistd.h>
0015 #include <cstdio>
0016 #include <cstdlib>
0017 
0018 #include "tmEventSetup/tmEventSetup.hh"
0019 #include "tmEventSetup/esTriggerMenu.hh"
0020 #include "tmEventSetup/esAlgorithm.hh"
0021 #include "tmEventSetup/esCondition.hh"
0022 #include "tmEventSetup/esObject.hh"
0023 #include "tmEventSetup/esCut.hh"
0024 #include "tmEventSetup/esScale.hh"
0025 #include "tmGrammar/Algorithm.hh"
0026 
0027 #include "FWCore/Framework/interface/ModuleFactory.h"
0028 #include "FWCore/Framework/interface/ESProducer.h"
0029 #include "FWCore/Framework/interface/ESProducts.h"
0030 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0031 #include "FWCore/ParameterSet/interface/FileInPath.h"
0032 
0033 #include "CondFormats/L1TObjects/interface/L1TUtmTriggerMenu.h"
0034 #include "CondFormats/DataRecord/interface/L1TUtmTriggerMenuRcd.h"
0035 
0036 using namespace std;
0037 using namespace edm;
0038 
0039 //
0040 // class declaration
0041 //
0042 
0043 class L1TUtmTriggerMenuESProducer : public edm::ESProducer {
0044 public:
0045   L1TUtmTriggerMenuESProducer(const edm::ParameterSet&);
0046   ~L1TUtmTriggerMenuESProducer() override;
0047 
0048   using ReturnType = std::unique_ptr<const L1TUtmTriggerMenu>;
0049 
0050   ReturnType produce(const L1TUtmTriggerMenuRcd&);
0051 
0052 private:
0053   std::string m_L1TriggerMenuFile;
0054 };
0055 
0056 //
0057 // constants, enums and typedefs
0058 //
0059 
0060 //
0061 // static data member definitions
0062 //
0063 
0064 //
0065 // constructors and destructor
0066 //
0067 L1TUtmTriggerMenuESProducer::L1TUtmTriggerMenuESProducer(const edm::ParameterSet& conf) {
0068   //the following line is needed to tell the framework what
0069   // data is being produced
0070   setWhatProduced(this);
0071   //setWhatProduced(this, conf.getParameter<std::string>("label"));
0072 
0073   // def.xml file
0074   std::string L1TriggerMenuFile = conf.getParameter<std::string>("L1TriggerMenuFile");
0075 
0076   edm::FileInPath f1("L1Trigger/L1TGlobal/data/Luminosity/startup/" + L1TriggerMenuFile);
0077 
0078   m_L1TriggerMenuFile = f1.fullPath();
0079 }
0080 
0081 L1TUtmTriggerMenuESProducer::~L1TUtmTriggerMenuESProducer() {
0082   // do anything here that needs to be done at desctruction time
0083   // (e.g. close files, deallocate resources etc.)
0084 }
0085 
0086 //
0087 // member functions
0088 //
0089 
0090 // ------------ method called to produce the data  ------------
0091 L1TUtmTriggerMenuESProducer::ReturnType L1TUtmTriggerMenuESProducer::produce(const L1TUtmTriggerMenuRcd& iRecord) {
0092   //const L1TUtmTriggerMenu * cmenu = reinterpret_cast<const L1TUtmTriggerMenu *>(tmeventsetup::getTriggerMenu("/afs/cern.ch/user/t/tmatsush/public/tmGui/test-menu.xml"));
0093   const L1TUtmTriggerMenu* cmenu =
0094       reinterpret_cast<const L1TUtmTriggerMenu*>(tmeventsetup::getTriggerMenu(m_L1TriggerMenuFile));
0095   return ReturnType(cmenu);
0096 }
0097 
0098 //define this as a plug-in
0099 DEFINE_FWK_EVENTSETUP_MODULE(L1TUtmTriggerMenuESProducer);
0100 
0101 /*
0102 
0103 
0104 
0105 
0106 int
0107 main(int argc, char *argv[])
0108 {
0109   int opt;
0110   const char* file = 0;
0111   while ((opt = getopt(argc, argv, "f:")) != -1)
0112   {
0113     switch (opt)
0114     {
0115       case 'f':
0116         file = optarg;
0117         break;
0118     }
0119   }
0120 
0121   if (not file)
0122   {
0123     fprintf(stderr, "Usage: %s -f file\n", argv[0]);
0124     exit(EXIT_FAILURE);
0125   }
0126 
0127   using namespace tmeventsetup;
0128   const esTriggerMenu* menu = tmeventsetup::getTriggerMenu(file);
0129 
0130   const std::map<std::string, esAlgorithm>& algoMap = menu->getAlgorithmMap();
0131   const std::map<std::string, esCondition>& condMap = menu->getConditionMap();
0132   const std::map<std::string, esScale>& scaleMap = menu->getScaleMap();
0133 
0134   bool hasPrecision = false;
0135   std::map<std::string, unsigned int> precisions;
0136   getPrecisions(precisions, scaleMap);
0137   for (std::map<std::string, unsigned int>::const_iterator cit = precisions.begin(); cit != precisions.end(); cit++)
0138   {
0139     std::cout << cit->first << " = " << cit->second << "\n";
0140     hasPrecision = true;
0141   }
0142 
0143 
0144   if (hasPrecision)
0145   {
0146     std::map<std::string, esScale>::iterator it1, it2;
0147     const esScale* scale1 = &scaleMap.find("EG-ETA")->second;
0148     const esScale* scale2 = &scaleMap.find("MU-ETA")->second;
0149 
0150     std::vector<long long> lut_eg_2_mu_eta;
0151     getCaloMuonEtaConversionLut(lut_eg_2_mu_eta, scale1, scale2);
0152 
0153 
0154     scale1 = &scaleMap.find("EG-PHI")->second;
0155     scale2 = &scaleMap.find("MU-PHI")->second;
0156 
0157     std::vector<long long> lut_eg_2_mu_phi;
0158     getCaloMuonPhiConversionLut(lut_eg_2_mu_phi, scale1, scale2);
0159 
0160 
0161     scale1 = &scaleMap.find("EG-ETA")->second;
0162     scale2 = &scaleMap.find("MU-ETA")->second;
0163 
0164     std::vector<double> eg_mu_delta_eta;
0165     std::vector<long long> lut_eg_mu_delta_eta;
0166     size_t n = getDeltaVector(eg_mu_delta_eta, scale1, scale2);
0167     setLut(lut_eg_mu_delta_eta, eg_mu_delta_eta, precisions["PRECISION-EG-MU-Delta"]);
0168 
0169     std::vector<long long> lut_eg_mu_cosh;
0170     applyCosh(eg_mu_delta_eta, n);
0171     setLut(lut_eg_mu_cosh, eg_mu_delta_eta, precisions["PRECISION-EG-MU-Math"]);
0172 
0173 
0174     scale1 = &scaleMap.find("EG-PHI")->second;
0175     scale2 = &scaleMap.find("MU-PHI")->second;
0176 
0177     std::vector<double> eg_mu_delta_phi;
0178     std::vector<long long> lut_eg_mu_delta_phi;
0179     n = getDeltaVector(eg_mu_delta_phi, scale1, scale2);
0180     setLut(lut_eg_mu_delta_phi, eg_mu_delta_phi, precisions["PRECISION-EG-MU-Delta"]);
0181 
0182     std::vector<long long> lut_eg_mu_cos;
0183     applyCos(eg_mu_delta_phi, n);
0184     setLut(lut_eg_mu_cos, eg_mu_delta_phi, precisions["PRECISION-EG-MU-Math"]);
0185 
0186 
0187     scale1 = &scaleMap.find("EG-ET")->second;
0188     std::vector<long long> lut_eg_et;
0189     getLut(lut_eg_et, scale1, precisions["PRECISION-EG-MU-MassPt"]);
0190 
0191 
0192     scale1 = &scaleMap.find("MU-ET")->second;
0193     std::vector<long long> lut_mu_et;
0194     getLut(lut_mu_et, scale1, precisions["PRECISION-EG-MU-MassPt"]);
0195     for (size_t ii = 0; ii < lut_mu_et.size(); ii++)
0196     {
0197       std::cout << lut_mu_et.at(ii) << "\n";
0198     }
0199   }
0200 
0201 
0202   for (std::map<std::string, esAlgorithm>::const_iterator cit = algoMap.begin();
0203        cit != algoMap.end(); cit++)
0204   {
0205     const esAlgorithm& algo = cit->second;
0206     std::cout << "algo name = " << algo.getName() << "\n";
0207     std::cout << "algo exp. = " << algo.getExpression() << "\n";
0208     std::cout << "algo exp. in cond. = " << algo.getExpressionInCondition() << "\n";
0209 
0210     const std::vector<std::string>& rpn_vec = algo.getRpnVector();
0211     for (size_t ii = 0; ii < rpn_vec.size(); ii++)
0212     {
0213       const std::string& token = rpn_vec.at(ii);
0214       if (Algorithm::isGate(token)) continue;
0215       const esCondition& condition = condMap.find(token)->second;
0216       std::cout << "  cond type = " << condition.getType() << "\n";
0217 
0218       const std::vector<esCut>& cuts = condition.getCuts();
0219       for (size_t jj = 0; jj < cuts.size(); jj++)
0220       {
0221         const esCut& cut = cuts.at(jj);
0222         std::cout << "    cut name = " << cut.getName() << "\n";
0223         std::cout << "    cut target = " << cut.getObjectType() << "\n";
0224         std::cout << "    cut type = " << cut.getCutType() << "\n";
0225         std::cout << "    cut min. value  index = " << cut.getMinimum().value << " " << cut.getMinimum().index << "\n";
0226         std::cout << "    cut max. value  index = " << cut.getMaximum().value << " " << cut.getMaximum().index << "\n";
0227         std::cout << "    cut data = " << cut.getData() << "\n";
0228       }
0229 
0230       const std::vector<esObject>& objects = condition.getObjects();
0231       for (size_t jj = 0; jj < objects.size(); jj++)
0232       {
0233         const esObject& object = objects.at(jj);
0234         std::cout << "      obj name = " << object.getName() << "\n";
0235         std::cout << "      obj type = " << object.getType() << "\n";
0236         std::cout << "      obj op = " << object.getComparisonOperator() << "\n";
0237         std::cout << "      obj bx = " << object.getBxOffset() << "\n";
0238         if (object.getType() == esObjectType::EXT)
0239         {
0240           std::cout << "      ext name  = " << object.getExternalSignalName() << "\n";
0241           std::cout << "      ext ch id = " << object.getExternalChannelId() << "\n";
0242         }
0243 
0244         const std::vector<esCut>& cuts = object.getCuts();
0245         for (size_t kk = 0; kk < cuts.size(); kk++)
0246         {
0247           const esCut& cut = cuts.at(kk);
0248           std::cout << "        cut name = " << cut.getName() << "\n";
0249           std::cout << "        cut target = " << cut.getObjectType() << "\n";
0250           std::cout << "        cut type = " << cut.getCutType() << "\n";
0251           std::cout << "        cut min. value  index = " << cut.getMinimum().value << " " << cut.getMinimum().index << "\n";
0252           std::cout << "        cut max. value  index = " << cut.getMaximum().value << " " << cut.getMaximum().index << "\n";
0253           std::cout << "        cut data = " << cut.getData() << "\n";
0254         }
0255       }
0256     }
0257   }
0258 
0259   return 0;
0260 }
0261 
0262 */