Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
//-------------------------------------------------
//
//   Class: L1MuDTPtaLut
//
//   Description: Look-up tables for pt assignment
//
//
//   $Date: 2010/05/12 23:03:43 $
//   $Revision: 1.7 $
//
//   Author :
//   N. Neumeister            CERN EP
//   J. Troconiz              UAM Madrid
//
//--------------------------------------------------

//-----------------------
// This Class's Header --
//-----------------------

#include "CondFormats/L1TObjects/interface/L1MuDTPtaLut.h"

//---------------
// C++ Headers --
//---------------

#include <iostream>
#include <ostream>
#include <iomanip>
#include <string>
#include <cstdlib>

//-------------------------------
// Collaborating Class Headers --
//-------------------------------

#include "FWCore/Utilities/interface/FileInPath.h"
#include "CondFormats/L1TObjects/interface/DTTFBitArray.h"
#include "CondFormats/L1TObjects/interface/L1MuDTAssParam.h"
#include "CondFormats/L1TObjects/interface/L1TriggerLutFile.h"

using namespace std;

// --------------------------------
//       class L1MuDTPtaLut
//---------------------------------

//----------------
// Constructors --
//----------------

L1MuDTPtaLut::L1MuDTPtaLut() : pta_lut(0), pta_threshold(MAX_PTASSMETH / 2) {
  pta_lut.reserve(MAX_PTASSMETH);
  pta_threshold.reserve(MAX_PTASSMETH / 2);
  setPrecision();

  //  if ( load() != 0 ) {
  //    cout << "Can not open files to load pt-assignment look-up tables for DTTrackFinder!" << endl;
  //  }

  //  if ( L1MuDTTFConfig::Debug(6) ) print();
}

//--------------
// Destructor --
//--------------

L1MuDTPtaLut::~L1MuDTPtaLut() {
  vector<LUT>::iterator iter;
  for (iter = pta_lut.begin(); iter != pta_lut.end(); iter++) {
    (*iter).clear();
  }

  pta_lut.clear();
  pta_threshold.clear();
}

//--------------
// Operations --
//--------------

//
// reset pt-assignment look-up tables
//
void L1MuDTPtaLut::reset() {
  pta_lut.clear();
  pta_threshold.clear();
}

//
// load pt-assignment look-up tables
//
int L1MuDTPtaLut::load() {
  // get directory name
  string defaultPath = "L1TriggerConfig/DTTrackFinder/parameters/";
  string pta_dir = "L1TriggerData/DTTrackFinder/Ass/";
  string pta_str = "";

  // precision : in the look-up tables the following precision is used :
  // phi ...12 bits (address) and  pt ...5 bits
  // now convert phi and phib to the required precision

  int sh_phi = 12 - nbit_phi;

  // loop over all pt-assignment methods
  for (int pam = 0; pam < MAX_PTASSMETH; pam++) {
    switch (pam) {
      case PT12L: {
        pta_str = "pta12l";
        break;
      }
      case PT12H: {
        pta_str = "pta12h";
        break;
      }
      case PT13L: {
        pta_str = "pta13l";
        break;
      }
      case PT13H: {
        pta_str = "pta13h";
        break;
      }
      case PT14L: {
        pta_str = "pta14l";
        break;
      }
      case PT14H: {
        pta_str = "pta14h";
        break;
      }
      case PT23L: {
        pta_str = "pta23l";
        break;
      }
      case PT23H: {
        pta_str = "pta23h";
        break;
      }
      case PT24L: {
        pta_str = "pta24l";
        break;
      }
      case PT24H: {
        pta_str = "pta24h";
        break;
      }
      case PT34L: {
        pta_str = "pta34l";
        break;
      }
      case PT34H: {
        pta_str = "pta34h";
        break;
      }
      case PT12LO: {
        pta_str = "pta12l_ovl";
        break;
      }
      case PT12HO: {
        pta_str = "pta12h_ovl";
        break;
      }
      case PT13LO: {
        pta_str = "pta13l_ovl";
        break;
      }
      case PT13HO: {
        pta_str = "pta13h_ovl";
        break;
      }
      case PT14LO: {
        pta_str = "pta14l_ovl";
        break;
      }
      case PT14HO: {
        pta_str = "pta14h_ovl";
        break;
      }
      case PT23LO: {
        pta_str = "pta23l_ovl";
        break;
      }
      case PT23HO: {
        pta_str = "pta23h_ovl";
        break;
      }
      case PT24LO: {
        pta_str = "pta24l_ovl";
        break;
      }
      case PT24HO: {
        pta_str = "pta24h_ovl";
        break;
      }
      case PT34LO: {
        pta_str = "pta34l_ovl";
        break;
      }
      case PT34HO: {
        pta_str = "pta34h_ovl";
        break;
      }
      case PT15LO: {
        pta_str = "pta15l_ovl";
        break;
      }
      case PT15HO: {
        pta_str = "pta15h_ovl";
        break;
      }
      case PT25LO: {
        pta_str = "pta25l_ovl";
        break;
      }
      case PT25HO: {
        pta_str = "pta25h_ovl";
        break;
      }
    }

    // assemble file name
    edm::FileInPath lut_f = edm::FileInPath(string(defaultPath + pta_dir + pta_str + ".lut"));
    const string& pta_file = lut_f.fullPath();

    // open file
    L1TriggerLutFile file(pta_file);
    if (file.open() != 0)
      return -1;
    //    if ( L1MuDTTFConfig::Debug(1) ) cout << "Reading file : "
    //                                         << file.getName() << endl;

    // get the right shift factor
    int shift = sh_phi;
    int adr_old = -2048 >> shift;

    LUT tmplut;

    int number = -1;
    int sum_pt = 0;

    if (file.good()) {
      int threshold = file.readInteger();
      pta_threshold[pam / 2] = threshold;
    }

    // read values and shift to correct precision
    while (file.good()) {
      int adr = (file.readInteger()) >> shift;
      int pt = file.readInteger();

      number++;

      if (adr != adr_old) {
        assert(number);
        tmplut.insert(make_pair(adr_old, (sum_pt / number)));

        adr_old = adr;
        number = 0;
        sum_pt = 0;
      }

      sum_pt += pt;

      if (!file.good())
        file.close();
    }

    file.close();
    pta_lut.push_back(tmplut);
  }
  return 0;
}

//
// print pt-assignment look-up tables
//
void L1MuDTPtaLut::print() const {
  cout << endl;
  cout << "L1 barrel Track Finder Pt-Assignment look-up tables :" << endl;
  cout << "=====================================================" << endl;
  cout << endl;
  cout << "Precision : " << endl;
  cout << '\t' << setw(2) << nbit_phi << " bits are used for phi " << endl;

  // loop over all pt-assignment methods
  for (int pam = 0; pam < MAX_PTASSMETH; pam++) {
    cout << endl;
    cout << "Pt-Assignment Method : " << static_cast<PtAssMethod>(pam) << endl;
    cout << "============================" << endl;
    cout << endl;

    cout << "\t Threshold : " << getPtLutThreshold(pam / 2) << endl << endl;

    int maxbits = nbit_phi;

    cout << "      address";
    for (int i = 0; i < maxbits; i++)
      cout << ' ';
    cout << "  value" << endl;
    for (int i = 0; i < maxbits; i++)
      cout << '-';
    cout << "-------------------------" << endl;

    LUT::const_iterator iter = pta_lut[pam].begin();
    while (iter != pta_lut[pam].end()) {
      int address = (*iter).first;
      int value = (*iter).second;

      DTTFBitArray<12> b_address(static_cast<unsigned>(abs(address)));
      DTTFBitArray<5> b_value(static_cast<unsigned>(abs(value)));

      if (address < 0)
        b_address.twoComplement();

      cout.setf(ios::right, ios::adjustfield);
      cout << " " << setbase(10) << setw(5) << address << " (";
      for (int i = maxbits - 1; i >= 0; i--)
        cout << b_address[i];
      cout << ")   " << setw(3) << value << " (";
      b_value.print();
      cout << ")" << endl;

      iter++;
    }
  }

  cout << endl;
}

//
// get pt value for a given address
//
int L1MuDTPtaLut::getPt(int pta_ind, int address) const {
  LUT::const_iterator iter = pta_lut[pta_ind].find(address);
  if (iter != pta_lut[pta_ind].end()) {
    return (*iter).second;
  } else {
    cerr << "PtaLut::getPt : can not find address " << address << endl;
    return 0;
  }
}

//
// get pt-assignment LUT threshold
//
int L1MuDTPtaLut::getPtLutThreshold(int pta_ind) const {
  if (pta_ind >= 0 && pta_ind < MAX_PTASSMETH / 2) {
    return pta_threshold[pta_ind];
  } else {
    cerr << "PtaLut::getPtLutThreshold : can not find threshold " << pta_ind << endl;
    return 0;
  }
}

//
// set precision for look-up tables
//
void L1MuDTPtaLut::setPrecision() { nbit_phi = 12; }