Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:23:13

0001 // -*- C++ -*-
0002 //
0003 // Class:      L1TMuonBarrelParamsESProducer
0004 //
0005 // Original Author:  Giannis Flouris
0006 //         Created:
0007 //
0008 //
0009 
0010 // system include files
0011 #include <memory>
0012 
0013 // user include files
0014 #include "FWCore/Framework/interface/ModuleFactory.h"
0015 #include "FWCore/Framework/interface/ESProducer.h"
0016 #include "FWCore/Framework/interface/ESHandle.h"
0017 #include "FWCore/Framework/interface/ESProducts.h"
0018 
0019 #include "CondFormats/L1TObjects/interface/L1TMuonBarrelParams.h"
0020 #include "CondFormats/DataRecord/interface/L1TMuonBarrelParamsRcd.h"
0021 #include "L1Trigger/L1TMuon/interface/MicroGMTLUTFactories.h"
0022 
0023 #include "FWCore/ParameterSet/interface/FileInPath.h"
0024 #include "CondFormats/L1TObjects/interface/L1TriggerLutFile.h"
0025 #include "CondFormats/L1TObjects/interface/DTTFBitArray.h"
0026 
0027 #include "L1Trigger/L1TCommon/interface/XmlConfigParser.h"
0028 #include "L1Trigger/L1TCommon/interface/TriggerSystem.h"
0029 #include "L1Trigger/L1TCommon/interface/Parameter.h"
0030 #include "L1Trigger/L1TCommon/interface/Mask.h"
0031 
0032 #include "L1Trigger/L1TMuonBarrel/interface/L1TMuonBarrelParamsHelper.h"
0033 
0034 // class declaration
0035 //
0036 typedef std::map<short, short, std::less<short> > LUT;
0037 
0038 class L1TMuonBarrelParamsESProducer : public edm::ESProducer {
0039 public:
0040   L1TMuonBarrelParamsESProducer(const edm::ParameterSet&);
0041   ~L1TMuonBarrelParamsESProducer() override;
0042   int load_pt(std::vector<LUT>&, std::vector<int>&, unsigned short int, std::string);
0043   int load_phi(std::vector<LUT>&, unsigned short int, unsigned short int, std::string);
0044   int load_ext(std::vector<L1TMuonBarrelParams::LUTParams::extLUT>&, unsigned short int, unsigned short int);
0045   //void print(std::vector<LUT>& , std::vector<int>& ) const;
0046   int getPtLutThreshold(int, std::vector<int>&) const;
0047   using ReturnType = std::unique_ptr<L1TMuonBarrelParams>;
0048 
0049   ReturnType produce(const L1TMuonBarrelParamsRcd&);
0050 
0051 private:
0052   //L1TMuonBarrelParams m_params;
0053   L1TMuonBarrelParamsHelper m_params_helper;
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 L1TMuonBarrelParamsESProducer::L1TMuonBarrelParamsESProducer(const edm::ParameterSet& iConfig) {
0068   //the following line is needed to tell the framework what
0069   // data is being produced
0070   setWhatProduced(this);
0071   // Firmware version
0072   unsigned fwVersion = iConfig.getParameter<unsigned>("fwVersion");
0073   std::string AssLUTpath = iConfig.getParameter<std::string>("AssLUTPath");
0074   //m_params.setAssLUTPath(AssLUTpath);
0075 
0076   // int PT_Assignment_nbits_Phi = iConfig.getParameter<int>("PT_Assignment_nbits_Phi");
0077   // int PT_Assignment_nbits_PhiB = iConfig.getParameter<int>("PT_Assignment_nbits_PhiB");
0078   // int PHI_Assignment_nbits_Phi = iConfig.getParameter<int>("PHI_Assignment_nbits_Phi");
0079   // int PHI_Assignment_nbits_PhiB = iConfig.getParameter<int>("PHI_Assignment_nbits_PhiB");
0080   // int Extrapolation_nbits_Phi = iConfig.getParameter<int>("Extrapolation_nbits_Phi");
0081   // int Extrapolation_nbits_PhiB = iConfig.getParameter<int>("Extrapolation_nbits_PhiB");
0082   // int BX_min = iConfig.getParameter<int>("BX_min");
0083   // int BX_max = iConfig.getParameter<int>("BX_max");
0084   // int Extrapolation_Filter = iConfig.getParameter<int>("Extrapolation_Filter");
0085   // int OutOfTime_Filter_Window = iConfig.getParameter<int>("OutOfTime_Filter_Window");
0086   // bool OutOfTime_Filter = iConfig.getParameter<bool>("OutOfTime_Filter");
0087   // bool Open_LUTs = iConfig.getParameter<bool>("Open_LUTs");
0088   // bool EtaTrackFinder = iConfig.getParameter<bool>("EtaTrackFinder");
0089   // bool Extrapolation_21 = iConfig.getParameter<bool>("Extrapolation_21");
0090   bool configFromXML = iConfig.getParameter<bool>("configFromXML");
0091   // bool DisableNewAlgo = iConfig.getParameter<bool>("DisableNewAlgo");
0092 
0093   std::map<std::string, int> allInts;
0094   std::map<std::string, bool> allBools;
0095   std::map<std::string, std::vector<std::string> > allMasks;
0096 
0097   allInts["PT_Assignment_nbits_Phi"] = iConfig.getParameter<int>("PT_Assignment_nbits_Phi");
0098   allInts["PT_Assignment_nbits_PhiB"] = iConfig.getParameter<int>("PT_Assignment_nbits_PhiB");
0099   allInts["PHI_Assignment_nbits_Phi"] = iConfig.getParameter<int>("PHI_Assignment_nbits_Phi");
0100   allInts["PHI_Assignment_nbits_PhiB"] = iConfig.getParameter<int>("PHI_Assignment_nbits_PhiB");
0101   allInts["Extrapolation_nbits_Phi"] = iConfig.getParameter<int>("Extrapolation_nbits_Phi");
0102   allInts["Extrapolation_nbits_PhiB"] = iConfig.getParameter<int>("Extrapolation_nbits_PhiB");
0103   allInts["BX_min"] = iConfig.getParameter<int>("BX_min");
0104   allInts["BX_max"] = iConfig.getParameter<int>("BX_max");
0105   allInts["Extrapolation_Filter"] = iConfig.getParameter<int>("Extrapolation_Filter");
0106   allInts["OutOfTime_Filter_Window"] = iConfig.getParameter<int>("OutOfTime_Filter_Window");
0107   allBools["OutOfTime_Filter"] = iConfig.getParameter<bool>("OutOfTime_Filter");
0108   allBools["Open_LUTs"] = iConfig.getParameter<bool>("Open_LUTs");
0109   allBools["EtaTrackFinder"] = iConfig.getParameter<bool>("EtaTrackFinder");
0110   allBools["Extrapolation_21"] = iConfig.getParameter<bool>("Extrapolation_21");
0111   allBools["configFromXML"] = iConfig.getParameter<bool>("configFromXML");
0112   allBools["DisableNewAlgo"] = iConfig.getParameter<bool>("DisableNewAlgo");
0113 
0114   allMasks["mask_phtf_st1"] = iConfig.getParameter<std::vector<string> >("mask_phtf_st1");
0115   allMasks["mask_phtf_st2"] = iConfig.getParameter<std::vector<string> >("mask_phtf_st2");
0116   allMasks["mask_phtf_st3"] = iConfig.getParameter<std::vector<string> >("mask_phtf_st3");
0117   allMasks["mask_phtf_st4"] = iConfig.getParameter<std::vector<string> >("mask_phtf_st4");
0118 
0119   allMasks["mask_ettf_st1"] = iConfig.getParameter<std::vector<string> >("mask_ettf_st1");
0120   allMasks["mask_ettf_st2"] = iConfig.getParameter<std::vector<string> >("mask_ettf_st2");
0121   allMasks["mask_ettf_st3"] = iConfig.getParameter<std::vector<string> >("mask_ettf_st3");
0122 
0123   /*
0124        m_params.set_PT_Assignment_nbits_Phi(PT_Assignment_nbits_Phi);
0125        m_params.set_PT_Assignment_nbits_PhiB(PT_Assignment_nbits_PhiB);
0126        m_params.set_PHI_Assignment_nbits_Phi(PHI_Assignment_nbits_Phi);
0127        m_params.set_PHI_Assignment_nbits_PhiB(PHI_Assignment_nbits_PhiB);
0128        m_params.set_Extrapolation_nbits_Phi(Extrapolation_nbits_Phi);
0129        m_params.set_Extrapolation_nbits_PhiB(Extrapolation_nbits_PhiB);
0130        m_params.set_BX_min(BX_min);
0131        m_params.set_BX_max(BX_max);
0132        m_params.set_Extrapolation_Filter(Extrapolation_Filter);
0133        m_params.set_OutOfTime_Filter_Window(OutOfTime_Filter_Window);
0134        m_params.set_OutOfTime_Filter(OutOfTime_Filter);
0135        m_params.set_Open_LUTs(Open_LUTs);
0136        m_params.set_EtaTrackFinder(EtaTrackFinder);
0137        m_params.set_Extrapolation_21(Extrapolation_21);
0138        m_params.setFwVersion(fwVersion);
0139        m_params.set_DisableNewAlgo(DisableNewAlgo);
0140 
0141 
0142     ///Read Pt assignment Luts
0143         std::vector<LUT> pta_lut(0); pta_lut.reserve(19);
0144         std::vector<int> pta_threshold(6); pta_threshold.reserve(9);
0145         if ( load_pt(pta_lut,pta_threshold, PT_Assignment_nbits_Phi, AssLUTpath) != 0 ) {
0146           cout << "Can not open files to load pt-assignment look-up tables for L1TMuonBarrelTrackProducer!" << endl;
0147         }
0148        m_params.setpta_lut(pta_lut);
0149        m_params.setpta_threshold(pta_threshold);
0150 
0151     ///Read Phi assignment Luts
0152         std::vector<LUT> phi_lut(0); phi_lut.reserve(2);
0153         if ( load_phi(phi_lut, PHI_Assignment_nbits_Phi, PHI_Assignment_nbits_PhiB, AssLUTpath) != 0 ) {
0154           cout << "Can not open files to load phi-assignment look-up tables for L1TMuonBarrelTrackProducer!" << endl;
0155         }
0156         m_params.setphi_lut(phi_lut);
0157 
0158 
0159 
0160 
0161        m_params.l1mudttfparams.reset();
0162 
0163        std::vector <std::string>  mask_phtf_st1 = iConfig.getParameter< std::vector <string>  >("mask_phtf_st1");
0164        std::vector <std::string>  mask_phtf_st2 = iConfig.getParameter< std::vector <string>  >("mask_phtf_st2");
0165        std::vector <std::string>  mask_phtf_st3 = iConfig.getParameter< std::vector <string>  >("mask_phtf_st3");
0166        std::vector <std::string>  mask_phtf_st4 = iConfig.getParameter< std::vector <string>  >("mask_phtf_st4");
0167 
0168        std::vector <std::string>  mask_ettf_st1 = iConfig.getParameter< std::vector <string>  >("mask_ettf_st1");
0169        std::vector <std::string>  mask_ettf_st2 = iConfig.getParameter< std::vector <string>  >("mask_ettf_st2");
0170        std::vector <std::string>  mask_ettf_st3 = iConfig.getParameter< std::vector <string>  >("mask_ettf_st3");
0171 
0172         for( int wh=-3; wh<4; wh++ ) {
0173            int sec = 0;
0174            for(char& c : mask_phtf_st1[wh+3]) {
0175                 int mask = c - '0';
0176                 m_params.l1mudttfmasks.set_inrec_chdis_st1(wh,sec,mask);
0177                 sec++;
0178             }
0179            sec = 0;
0180            for(char& c : mask_phtf_st2[wh+3]) {
0181                 int mask = c - '0';
0182                 m_params.l1mudttfmasks.set_inrec_chdis_st2(wh,sec,mask);
0183                 sec++;
0184             }
0185            sec = 0;
0186            for(char& c : mask_phtf_st3[wh+3]) {
0187                 int mask = c - '0';
0188                 m_params.l1mudttfmasks.set_inrec_chdis_st3(wh,sec,mask);
0189                 sec++;
0190             }
0191            sec = 0;
0192            for(char& c : mask_phtf_st4[wh+3]) {
0193                 int mask = c - '0';
0194                 m_params.l1mudttfmasks.set_inrec_chdis_st4(wh,sec,mask);
0195                 sec++;
0196             }
0197            sec = 0;
0198            for(char& c : mask_ettf_st1[wh+3]) {
0199                 int mask = c - '0';
0200                 m_params.l1mudttfmasks.set_etsoc_chdis_st1(wh,sec,mask);
0201                 sec++;
0202             }
0203            sec = 0;
0204            for(char& c : mask_ettf_st2[wh+3]) {
0205                 int mask = c - '0';
0206                 m_params.l1mudttfmasks.set_etsoc_chdis_st2(wh,sec,mask);
0207                 sec++;
0208             }
0209            sec = 0;
0210            for(char& c : mask_ettf_st3[wh+3]) {
0211                 int mask = c - '0';
0212                 m_params.l1mudttfmasks.set_etsoc_chdis_st3(wh,sec,mask);
0213                 //Not used in BMTF - mask
0214                 m_params.l1mudttfmasks.set_inrec_chdis_csc(wh,sec,true);
0215                 sec++;
0216             }
0217 
0218         }
0219 
0220 
0221     ///Read Extrapolation Luts
0222         std::vector<L1TMuonBarrelParams::LUTParams::extLUT> ext_lut(0); ext_lut.reserve(12);
0223         if ( load_ext(ext_lut, PHI_Assignment_nbits_Phi, PHI_Assignment_nbits_PhiB) != 0 ) {
0224           cout << "Can not open files to load extrapolation look-up tables for L1TMuonBarrelTrackProducer!" << endl;
0225         }
0226         m_params.setext_lut(ext_lut);
0227 
0228     //m_params.l1mudttfextlut.load();
0229 
0230     */
0231 
0232   m_params_helper.configFromPy(allInts, allBools, allMasks, fwVersion, AssLUTpath);
0233   if (configFromXML) {
0234     cout << "Configuring BMTF Emulator from xml files.\n";
0235     edm::FileInPath hwXmlFile(iConfig.getParameter<std::string>("hwXmlFile"));
0236     edm::FileInPath topCfgXmlFile(iConfig.getParameter<std::string>("topCfgXmlFile"));
0237     std::string xmlCfgKey = iConfig.getParameter<std::string>("xmlCfgKey");
0238 
0239     l1t::TriggerSystem trgSys;
0240     trgSys.configureSystemFromFiles(hwXmlFile.fullPath().c_str(), topCfgXmlFile.fullPath().c_str(), xmlCfgKey.c_str());
0241 
0242     /* std::map<std::string, std::string> procRole = trgSys.getProcRole();
0243 
0244       for(auto it_proc=procRole.begin(); it_proc!=procRole.end(); it_proc++ ){
0245 
0246           std::string procId = it_proc->first;
0247 
0248           std::map<std::string, l1t::Setting> settings = trgSys.getSettings(procId);
0249           std::vector<l1t::TableRow>  tRow = settings["regTable"].getTableRows();
0250           for(auto it=tRow.begin(); it!=tRow.end(); it++)
0251           {
0252             if (it->getRowValue<std::string>("register_path").find("open_lut") != std::string::npos){
0253               //std::cout << "Value is: " << it->getRowValue<bool>("register_value") << std::endl;
0254               m_params.set_Open_LUTs(it->getRowValue<bool>("register_value"));
0255             }
0256             if (it->getRowValue<std::string>("register_path").find("sel_21") != std::string::npos){
0257               //std::cout << "Value is: " << it->getRowValue<bool>("register_value") << std::endl;
0258               m_params.set_Extrapolation_21(it->getRowValue<bool>("register_value"));
0259             }
0260 
0261             if (it->getRowValue<std::string>("register_path").find("dis_newalgo") != std::string::npos){
0262               //std::cout << "Value is: " << it->getRowValue<int>("register_value") << std::endl;
0263               //int fwv = (it->getRowValue<int>("register_value")==1) ? 1 : 2;
0264               //m_params.setFwVersion(fwv);
0265               bool disnewalgo = (it->getRowValue<int>("register_value")==1);
0266               m_params.set_DisableNewAlgo(disnewalgo);
0267             }
0268 
0269             string masks[5] = {"mask_ctrl_N2", "mask_ctrl_N1", "mask_ctrl_0", "mask_ctrl_P1", "mask_ctrl_P2"};
0270 
0271             for(int m=0; m<5; m++){
0272 
0273                 if (it->getRowValue<std::string>("register_path").find(masks[m]) != std::string::npos){
0274                   string mask_ctrl = it->getRowValue<string>("register_value");
0275                   const char *hexstring = mask_ctrl.c_str();
0276                   ///Converts the last bit from str to int
0277                   int mask = (int)strtol((hexstring+7), NULL, 16);
0278                   int mask_all = (int)strtol((hexstring), NULL, 16);
0279                   ///All bits must be the same
0280                   if(!( mask_all==0x111111 || mask_all==0x222222 || mask_all==0x333333 || mask_all==0x444444 ||
0281                      mask_all==0x555555 || mask_all==0x666666 || mask_all==0x777777) )
0282                     cerr<<"BMTF: Cannot re-emulate properly. Individual link masking cannot be handled."<<endl;
0283 
0284                   if((mask&1)>0)  {
0285                      for(int sec=0; sec<12; sec++){
0286                       if(masks[m]=="mask_ctrl_N2"){
0287                                             m_params.l1mudttfmasks.set_inrec_chdis_st1(-3,sec,true);
0288                                             m_params.l1mudttfmasks.set_etsoc_chdis_st1(-3,sec,true);
0289                       }
0290                       if(masks[m]=="mask_ctrl_N1"){
0291                                             m_params.l1mudttfmasks.set_inrec_chdis_st1(-2,sec,true);
0292                                             m_params.l1mudttfmasks.set_etsoc_chdis_st1(-2,sec,true);
0293                       }
0294 
0295                       if(masks[m]=="mask_ctrl_0"){
0296                                             m_params.l1mudttfmasks.set_inrec_chdis_st1(-1,sec,true);
0297                                             m_params.l1mudttfmasks.set_inrec_chdis_st1(1,sec,true);
0298                                             m_params.l1mudttfmasks.set_etsoc_chdis_st1(-1,sec,true);
0299                                             m_params.l1mudttfmasks.set_etsoc_chdis_st1(1,sec,true);
0300                       }
0301                       if(masks[m]=="mask_ctrl_P1"){
0302                                             m_params.l1mudttfmasks.set_inrec_chdis_st1(2,sec,true);
0303                                             m_params.l1mudttfmasks.set_etsoc_chdis_st1(2,sec,true);
0304                       }
0305                       if(masks[m]=="mask_ctrl_P2"){
0306                                             m_params.l1mudttfmasks.set_inrec_chdis_st1(3,sec,true);
0307                                             m_params.l1mudttfmasks.set_etsoc_chdis_st1(3,sec,true);
0308                       }
0309                     }
0310 
0311                   }
0312 
0313                   if((mask&2)>0)  {
0314                     for(int sec=0; sec<12; sec++){
0315                       if(masks[m]=="mask_ctrl_N2"){
0316                                             m_params.l1mudttfmasks.set_inrec_chdis_st2(-3,sec,true);
0317                                             m_params.l1mudttfmasks.set_etsoc_chdis_st2(-3,sec,true);
0318                       }
0319                       if(masks[m]=="mask_ctrl_N1"){
0320                                             m_params.l1mudttfmasks.set_inrec_chdis_st2(-2,sec,true);
0321                                             m_params.l1mudttfmasks.set_etsoc_chdis_st2(-2,sec,true);
0322                       }
0323 
0324                       if(masks[m]=="mask_ctrl_0"){
0325                                             m_params.l1mudttfmasks.set_inrec_chdis_st2(-1,sec,true);
0326                                             m_params.l1mudttfmasks.set_inrec_chdis_st2(1,sec,true);
0327                                             m_params.l1mudttfmasks.set_etsoc_chdis_st2(-1,sec,true);
0328                                             m_params.l1mudttfmasks.set_etsoc_chdis_st2(1,sec,true);
0329                       }
0330                       if(masks[m]=="mask_ctrl_P1"){
0331                                             m_params.l1mudttfmasks.set_inrec_chdis_st2(2,sec,true);
0332                                             m_params.l1mudttfmasks.set_etsoc_chdis_st2(2,sec,true);
0333                       }
0334                       if(masks[m]=="mask_ctrl_P2"){
0335                                             m_params.l1mudttfmasks.set_inrec_chdis_st2(3,sec,true);
0336                                             m_params.l1mudttfmasks.set_etsoc_chdis_st2(3,sec,true);
0337                       }
0338                     }
0339                   }
0340 
0341                   if((mask&4)>0)  {
0342                     for(int sec=0; sec<12; sec++){
0343                       if(masks[m]=="mask_ctrl_N2"){
0344                                             m_params.l1mudttfmasks.set_inrec_chdis_st3(-3,sec,true);
0345                                             m_params.l1mudttfmasks.set_etsoc_chdis_st3(-3,sec,true);
0346                       }
0347                       if(masks[m]=="mask_ctrl_N1"){
0348                                             m_params.l1mudttfmasks.set_inrec_chdis_st3(-2,sec,true);
0349                                             m_params.l1mudttfmasks.set_etsoc_chdis_st3(-2,sec,true);
0350                       }
0351 
0352                       if(masks[m]=="mask_ctrl_0"){
0353                                             m_params.l1mudttfmasks.set_inrec_chdis_st3(-1,sec,true);
0354                                             m_params.l1mudttfmasks.set_inrec_chdis_st3(1,sec,true);
0355                                             m_params.l1mudttfmasks.set_etsoc_chdis_st3(-1,sec,true);
0356                                             m_params.l1mudttfmasks.set_etsoc_chdis_st3(1,sec,true);
0357                       }
0358                       if(masks[m]=="mask_ctrl_P1"){
0359                                             m_params.l1mudttfmasks.set_inrec_chdis_st3(2,sec,true);
0360                                             m_params.l1mudttfmasks.set_etsoc_chdis_st3(2,sec,true);
0361                       }
0362                       if(masks[m]=="mask_ctrl_P2"){
0363                                             m_params.l1mudttfmasks.set_inrec_chdis_st3(3,sec,true);
0364                                             m_params.l1mudttfmasks.set_etsoc_chdis_st3(3,sec,true);
0365                       }
0366                     }
0367                   }
0368 
0369                   if((mask&8)>0)  {
0370                     for(int sec=0; sec<12; sec++){
0371                       if(masks[m]=="mask_ctrl_N2"){
0372                                             m_params.l1mudttfmasks.set_inrec_chdis_st4(-3,sec,true);
0373                       }
0374                       if(masks[m]=="mask_ctrl_N1"){
0375                                             m_params.l1mudttfmasks.set_inrec_chdis_st4(-2,sec,true);
0376                       }
0377 
0378                       if(masks[m]=="mask_ctrl_0"){
0379                                             m_params.l1mudttfmasks.set_inrec_chdis_st4(-1,sec,true);
0380                                             m_params.l1mudttfmasks.set_inrec_chdis_st4(1,sec,true);
0381                       }
0382                       if(masks[m]=="mask_ctrl_P1"){
0383                                             m_params.l1mudttfmasks.set_inrec_chdis_st4(2,sec,true);
0384                       }
0385                       if(masks[m]=="mask_ctrl_P2"){
0386                                             m_params.l1mudttfmasks.set_inrec_chdis_st4(3,sec,true);
0387                       }
0388                     }
0389                   }
0390                }///if register path
0391              }///for masks
0392           }///for it tRow
0393       }///for it procRole */
0394     m_params_helper.configFromDB(trgSys);
0395   }  ///if configDB
0396      //m_params = cast_to_L1TMuonBarrelParams((L1TMuonBarrelParams_PUBLIC)m_params_helper);
0397 }
0398 
0399 L1TMuonBarrelParamsESProducer::~L1TMuonBarrelParamsESProducer() {}
0400 
0401 /*int L1TMuonBarrelParamsESProducer::load_pt(std::vector<LUT>& pta_lut,
0402                                   std::vector<int>& pta_threshold,
0403                                   unsigned short int nbitphi,
0404                                   std::string AssLUTpath
0405                                   ){
0406 
0407 
0408 // maximal number of pt assignment methods
0409 const int MAX_PTASSMETH = 19;
0410 const int MAX_PTASSMETHA = 12;
0411 
0412 // pt assignment methods
0413 enum PtAssMethod { PT12L,  PT12H,  PT13L,  PT13H,  PT14L,  PT14H,
0414                    PT23L,  PT23H,  PT24L,  PT24H,  PT34L,  PT34H,
0415                    PB12H,  PB13H,  PB14H,  PB21H,  PB23H,  PB24H, PB34H,
0416                    NODEF };
0417 
0418   // get directory name
0419   string pta_str = "";
0420   // precision : in the look-up tables the following precision is used :
0421   // phi ...12 bits (address) and  pt ...5 bits
0422   // now convert phi and phib to the required precision
0423   int nbit_phi = nbitphi;
0424   int sh_phi  = 12 - nbit_phi;
0425 
0426   // loop over all pt-assignment methods
0427   for ( int pam = 0; pam < MAX_PTASSMETH; pam++ ) {
0428     switch ( pam ) {
0429       case PT12L  : { pta_str = "pta12l"; break; }
0430       case PT12H  : { pta_str = "pta12h"; break; }
0431       case PT13L  : { pta_str = "pta13l"; break; }
0432       case PT13H  : { pta_str = "pta13h"; break; }
0433       case PT14L  : { pta_str = "pta14l"; break; }
0434       case PT14H  : { pta_str = "pta14h"; break; }
0435       case PT23L  : { pta_str = "pta23l"; break; }
0436       case PT23H  : { pta_str = "pta23h"; break; }
0437       case PT24L  : { pta_str = "pta24l"; break; }
0438       case PT24H  : { pta_str = "pta24h"; break; }
0439       case PT34L  : { pta_str = "pta34l"; break; }
0440       case PT34H  : { pta_str = "pta34h"; break; }
0441       case PB12H  : { pta_str = "ptb12h_Feb2016"; break; }
0442       case PB13H  : { pta_str = "ptb13h_Feb2016"; break; }
0443       case PB14H  : { pta_str = "ptb14h_Feb2016"; break; }
0444       case PB21H  : { pta_str = "ptb21h_Feb2016"; break; }
0445       case PB23H  : { pta_str = "ptb23h_Feb2016"; break; }
0446       case PB24H  : { pta_str = "ptb24h_Feb2016"; break; }
0447       case PB34H  : { pta_str = "ptb34h_Feb2016"; break; }
0448 
0449     }
0450 
0451     // assemble file name
0452     string lutpath = AssLUTpath;
0453     edm::FileInPath lut_f = edm::FileInPath(string(lutpath + pta_str + ".lut"));
0454     string pta_file = lut_f.fullPath();
0455 
0456     // open file
0457     L1TriggerLutFile file(pta_file);
0458     if ( file.open() != 0 ) return -1;
0459 
0460     // get the right shift factor
0461     int shift = sh_phi;
0462     int adr_old = -2048 >> shift;
0463     if (pam >= MAX_PTASSMETHA) adr_old = -512 >> shift;
0464 
0465     LUT tmplut;
0466 
0467     int number = -1;
0468     int sum_pt = 0;
0469 
0470     if ( file.good() ) {
0471       int threshold = file.readInteger();
0472       pta_threshold[pam/2] = threshold;
0473     }
0474 
0475     // read values and shift to correct precision
0476     while ( file.good() ) {
0477 
0478       int adr = (file.readInteger()) >> shift;
0479       int pt  = file.readInteger();
0480 
0481       number++;
0482       //cout<<pam<<"    "<<number<<"   "<<MAX_PTASSMETHA<<endl;
0483       if ( adr != adr_old ) {
0484         assert(number);
0485         tmplut.insert(make_pair( adr_old, (sum_pt/number) ));
0486 
0487         adr_old = adr;
0488         number = 0;
0489         sum_pt = 0;
0490       }
0491 
0492       sum_pt += pt;
0493 
0494       if ( !file.good() ) file.close();
0495 
0496     }
0497 
0498     file.close();
0499     pta_lut.push_back(tmplut);
0500   }
0501   return 0;
0502 
0503 }
0504 
0505 
0506 
0507 
0508 int L1TMuonBarrelParamsESProducer::load_phi(std::vector<LUT>& phi_lut,
0509                                   unsigned short int nbit_phi,
0510                                   unsigned short int nbit_phib,
0511                                   std::string AssLUTpath
0512                                   ) {
0513 
0514 
0515   // precision : in the look-up tables the following precision is used :
0516   // address (phib) ...10 bits, phi ... 12 bits
0517 
0518   int sh_phi  = 12 - nbit_phi;
0519   int sh_phib = 10 - nbit_phib;
0520 
0521   string phi_str;
0522   // loop over all phi-assignment methods
0523   for ( int idx = 0; idx < 2; idx++ ) {
0524     switch ( idx ) {
0525       case 0 : { phi_str = "phi12"; break; }
0526       case 1 : { phi_str = "phi42"; break; }
0527     }
0528 
0529     // assemble file name
0530     edm::FileInPath lut_f = edm::FileInPath(string(AssLUTpath + phi_str + ".lut"));
0531     string phi_file = lut_f.fullPath();
0532 
0533     // open file
0534     L1TriggerLutFile file(phi_file);
0535     if ( file.open() != 0 ) return -1;
0536 
0537     LUT tmplut;
0538 
0539     int number = -1;
0540     int adr_old = -512 >> sh_phib;
0541     int sum_phi = 0;
0542 
0543     // read values
0544     while ( file.good() ) {
0545 
0546       int adr = (file.readInteger()) >> sh_phib;
0547       int phi =  file.readInteger();
0548 
0549       number++;
0550 
0551       if ( adr != adr_old ) {
0552         assert(number);
0553         tmplut.insert(make_pair( adr_old, ((sum_phi/number) >> sh_phi) ));
0554 
0555         adr_old = adr;
0556         number = 0;
0557         sum_phi  = 0;
0558       }
0559 
0560       sum_phi += phi;
0561 
0562       if ( !file.good() ) file.close();
0563 
0564     }
0565 
0566     file.close();
0567     phi_lut.push_back(tmplut);
0568   }
0569   return 0;
0570 
0571 }
0572 
0573 
0574 int L1TMuonBarrelParamsESProducer::getPtLutThreshold(int pta_ind, std::vector<int>& pta_threshold) const {
0575 
0576   if ( pta_ind >= 0 && pta_ind < 13/2 ) {
0577     return pta_threshold[pta_ind];
0578   }
0579   else {
0580     cerr << "PtaLut::getPtLutThreshold : can not find threshold " << pta_ind << endl;
0581     return 0;
0582   }
0583 
0584 }
0585 
0586 */
0587 
0588 //
0589 // load extrapolation look-up tables
0590 //
0591 /*
0592 int L1TMuonBarrelParamsESProducer::load_ext(std::vector<L1TMuonBarrelParams::LUTParams::extLUT>& ext_lut,
0593                                             unsigned short int nbit_phi,
0594                                             unsigned short int nbit_phib) {
0595 
0596   //max. number of Extrapolations
0597   const int MAX_EXT = 12;
0598 
0599   // extrapolation types
0600   enum Extrapolation { EX12, EX13, EX14, EX21, EX23, EX24, EX34,
0601                      EX15, EX16, EX25, EX26, EX56 };
0602 
0603   // get directory name
0604   string defaultPath = "L1Trigger/L1TMuon/data/bmtf_luts/";
0605   string ext_dir = "LUTs_Ext/";
0606   string ext_str = "";
0607 
0608   // precision : in the look-up tables the following precision is used :
0609   // phi ...12 bits (low, high), phib ...10 bits (address)
0610   // now convert phi and phib to the required precision
0611 
0612   int sh_phi  = 12 - nbit_phi;
0613   int sh_phib = 10 - nbit_phib;
0614 
0615   // loop over all extrapolations
0616   for ( int ext = 0; ext < MAX_EXT; ext++ ) {
0617     switch (ext) {
0618       case EX12 : ext_str = "ext12"; break;
0619       case EX13 : ext_str = "ext13"; break;
0620       case EX14 : ext_str = "ext14"; break;
0621       case EX21 : ext_str = "ext21"; break;
0622       case EX23 : ext_str = "ext23"; break;
0623       case EX24 : ext_str = "ext24"; break;
0624       case EX34 : ext_str = "ext34"; break;
0625       case EX15 : ext_str = "ext15"; break;
0626       case EX16 : ext_str = "ext16"; break;
0627       case EX25 : ext_str = "ext25"; break;
0628       case EX26 : ext_str = "ext26"; break;
0629       case EX56 : ext_str = "ext56"; break;
0630     }
0631 
0632     // assemble file name
0633     edm::FileInPath lut_f = edm::FileInPath(string(defaultPath + ext_dir + ext_str + ".lut"));
0634     string ext_file = lut_f.fullPath();
0635 
0636     // open file
0637     L1TriggerLutFile file(ext_file);
0638     if ( file.open() != 0 ) return -1;
0639     //    if ( L1MuDTTFConfig::Debug(1) ) cout << "Reading file : "
0640     //                                         << file.getName() << endl;
0641 
0642     L1TMuonBarrelParams::LUTParams::extLUT tmplut;
0643 
0644     int number = -1;
0645     int adr_old = -512 >> sh_phib;
0646     int sum_low = 0;
0647     int sum_high = 0;
0648 
0649     // read values and shift to correct precision
0650     while ( file.good() ) {
0651 
0652       int adr  = ( file.readInteger() ) >> sh_phib; // address (phib)
0653       int low  = ( file.readInteger() );            // low value (phi)
0654       int high = ( file.readInteger() );            // high value (phi)
0655 
0656       number++;
0657 
0658       if ( adr != adr_old ) {
0659 
0660         tmplut.low[adr_old]  = sum_low  >> sh_phi;
0661         tmplut.high[adr_old] = sum_high >> sh_phi;
0662 
0663         adr_old = adr;
0664         number = 0;
0665         sum_low  = 0;
0666         sum_high = 0;
0667 
0668       }
0669 
0670       if (number == 0) sum_low  = low;
0671       if (number == 0) sum_high = high;
0672 
0673       if ( !file.good() ) file.close();
0674     }
0675 
0676     file.close();
0677     ext_lut.push_back(tmplut);
0678   }
0679   return 0;
0680 
0681 }
0682 
0683 
0684 //
0685 // member functions
0686 //
0687 */
0688 // ------------ method called to produce the data  ------------
0689 L1TMuonBarrelParamsESProducer::ReturnType L1TMuonBarrelParamsESProducer::produce(const L1TMuonBarrelParamsRcd& iRecord) {
0690   return std::make_unique<L1TMuonBarrelParams>(m_params_helper);
0691 }
0692 
0693 //define this as a plug-in
0694 DEFINE_FWK_EVENTSETUP_MODULE(L1TMuonBarrelParamsESProducer);