Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:20:51

0001 //-------------------------------------------------
0002 //
0003 //   Class: L1MuDTQualPatternLut
0004 //
0005 //   Description: Look-up tables for eta matching unit (EMU)
0006 //                stores lists of qualified patterns and
0007 //                coarse eta values
0008 //
0009 //
0010 //   $Date: 2007/03/30 07:48:02 $
0011 //   $Revision: 1.1 $
0012 //
0013 //   Author :
0014 //   N. Neumeister            CERN EP
0015 //   J. Troconiz              UAM Madrid
0016 //
0017 //--------------------------------------------------
0018 
0019 //-----------------------
0020 // This Class's Header --
0021 //-----------------------
0022 
0023 #include "L1Trigger/L1TMuonBarrel/interface/L1MuBMTQualPatternLut.h"
0024 
0025 //---------------
0026 // C++ Headers --
0027 //---------------
0028 
0029 #include <iostream>
0030 #include <iomanip>
0031 #include <string>
0032 
0033 //-------------------------------
0034 // Collaborating Class Headers --
0035 //-------------------------------
0036 
0037 #include "FWCore/ParameterSet/interface/FileInPath.h"
0038 #include "CondFormats/L1TObjects/interface/L1TriggerLutFile.h"
0039 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0040 
0041 using namespace std;
0042 
0043 // --------------------------------
0044 //       class L1MuDTQualPatternLut
0045 //---------------------------------
0046 
0047 //----------------
0048 // Constructors --
0049 //----------------
0050 
0051 L1MuBMTQualPatternLut::L1MuBMTQualPatternLut() {
0052   //  if ( load() != 0 ) {
0053   //    cout << "Can not open files to load eta matching look-up tables for DTTrackFinder!" << endl;
0054   //  }
0055 
0056   //  if ( L1MuDTTFConfig::Debug(6) ) print();
0057 }
0058 
0059 //--------------
0060 // Destructor --
0061 //--------------
0062 
0063 L1MuBMTQualPatternLut::~L1MuBMTQualPatternLut() {}
0064 
0065 //--------------
0066 // Operations --
0067 //--------------
0068 
0069 //
0070 // reset look-up tables
0071 //
0072 void L1MuBMTQualPatternLut::reset() { m_lut.clear(); }
0073 
0074 //
0075 // load look-up tables for EMU
0076 //
0077 int L1MuBMTQualPatternLut::load() {
0078   // get directory name
0079   string defaultPath = "L1Trigger/";                    //"L1TriggerConfig/DTTrackFinder/parameters/";
0080   string eau_dir = "L1TMuon/data/bmtf_luts/LUTs_Ass/";  //"L1TriggerData/DTTrackFinder/Eau/";
0081   string emu_str = "";
0082 
0083   // loop over all sector processors
0084   for (int sp = 0; sp < 6; sp++) {
0085     emu_str = "QualPatternList_SP" + std::to_string(sp + 1);
0086 
0087     // assemble file name
0088     edm::FileInPath lut_f = edm::FileInPath(string(defaultPath + eau_dir + emu_str + ".lut"));
0089     string emu_file = lut_f.fullPath();
0090 
0091     // open file
0092     L1TriggerLutFile file(emu_file);
0093     if (file.open() != 0)
0094       return -1;
0095     //    if ( L1MuDTTFConfig::Debug(1) ) cout << "Reading file : "
0096     //                                         << file.getName() << endl;
0097 
0098     // ignore comment lines
0099     int skip2 = getIgnoredLines(file);
0100     file.ignoreLines(skip2);
0101 
0102     // read file
0103     while (file.good()) {
0104       int id = file.readInteger();
0105       if (!file.good())
0106         break;
0107       int eta = file.readInteger();
0108       if (!file.good())
0109         break;
0110       int num = file.readInteger();
0111       if (!file.good())
0112         break;
0113 
0114       vector<short> patternlist;
0115       patternlist.reserve(num);
0116 
0117       for (int i = 0; i < num; i++) {
0118         int pattern = file.readInteger();
0119         patternlist.push_back(pattern);
0120       }
0121 
0122       m_lut[make_pair(sp + 1, id)] = make_pair(eta, patternlist);
0123 
0124       if (!file.good()) {
0125         file.close();
0126         break;
0127       }
0128     }
0129 
0130     file.close();
0131   }
0132 
0133   return 0;
0134 }
0135 
0136 //
0137 // print look-up tables for EMU
0138 //
0139 void L1MuBMTQualPatternLut::print() const {
0140   cout << endl;
0141   cout << "L1 barrel Track Finder Qual Pattern look-up tables :" << endl;
0142   cout << "====================================================" << endl;
0143   cout << endl;
0144 
0145   int spold = 0;
0146 
0147   LUT::const_iterator iter = m_lut.begin();
0148   while (iter != m_lut.end()) {
0149     int sp = (*iter).first.first;
0150     if (sp != spold) {
0151       cout << endl;
0152       cout << "Qualified Patterns for Sector Processor " << setw(1) << sp << " :" << endl;
0153       cout << "===========================================" << endl;
0154       cout << endl;
0155       spold = sp;
0156     }
0157     cout << setw(2) << (*iter).first.second << "  " << setw(3) << (*iter).second.first << "  " << setw(5)
0158          << (*iter).second.second.size() << " : ";
0159     const vector<short>& patternlist = (*iter).second.second;
0160     vector<short>::const_iterator it;
0161     for (it = patternlist.begin(); it != patternlist.end(); it++) {
0162       cout << setw(5) << (*it) << " ";
0163     }
0164     cout << endl;
0165     iter++;
0166   }
0167 
0168   cout << endl;
0169 }
0170 
0171 //
0172 // get coarse eta value for a given sector processor [1-6] and address [1-22]
0173 //
0174 int L1MuBMTQualPatternLut::getCoarseEta(int sp, int adr) const {
0175   LUT::const_iterator it = m_lut.find(make_pair(sp, adr));
0176   if (it == m_lut.end()) {
0177     edm::LogError("L1MuBMTQualPatternLut")
0178         << "Error: L1MuBMTQualPatternLut: no coarse eta found for address " << adr << endl;
0179     return 0;
0180   }
0181   return (*it).second.first;
0182 }
0183 
0184 //
0185 // get list of qualified patterns for a given sector processor [1-6] and address [1-22]
0186 //
0187 const vector<short>& L1MuBMTQualPatternLut::getQualifiedPatterns(int sp, int adr) const {
0188   LUT::const_iterator it = m_lut.find(make_pair(sp, adr));
0189   if (it == m_lut.end()) {
0190     edm::LogError("L1MuBMTQualPatternLut")
0191         << "Error: L1MuBMTQualPatternLut: no pattern list found for address " << adr << endl;
0192   }
0193   return (*it).second.second;
0194 }
0195 
0196 int L1MuBMTQualPatternLut::getIgnoredLines(L1TriggerLutFile file) const {
0197   if (file.open() != 0)
0198     return -1;
0199   int skip = 0;
0200   while (file.good()) {
0201     string str = file.readString();
0202     if (str.find('#') == 0)
0203       skip += 1;
0204     //cout<<"here "<<str<<" found "<<str.find("#")<<endl;
0205     if (!file.good()) {
0206       file.close();
0207       break;
0208     }
0209   }
0210   file.close();
0211 
0212   // skip aditional lines of comments between "---".
0213   skip += 2;
0214 
0215   return skip;
0216 }