Skip to content

Commit

Permalink
Put CSC and GEM-CSC local trigger lookup tables in ES objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Dildick committed Jul 30, 2021
1 parent 0b98ed0 commit 16987a2
Show file tree
Hide file tree
Showing 42 changed files with 1,207 additions and 791 deletions.
78 changes: 78 additions & 0 deletions CalibMuon/CSCCalibration/python/CSCL1TPLookupTable_cff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import FWCore.ParameterSet.Config as cms

CSCL1TPLookupTableEP = cms.ESSource(
"CSCL1TPLookupTableEP",
## CCLUT
positionLUTFiles = cms.vstring(
"L1Trigger/CSCTriggerPrimitives/data/CCLUT/CSCComparatorCodePosOffsetLUT_pat0_v1.txt",
"L1Trigger/CSCTriggerPrimitives/data/CCLUT/CSCComparatorCodePosOffsetLUT_pat1_v1.txt",
"L1Trigger/CSCTriggerPrimitives/data/CCLUT/CSCComparatorCodePosOffsetLUT_pat2_v1.txt",
"L1Trigger/CSCTriggerPrimitives/data/CCLUT/CSCComparatorCodePosOffsetLUT_pat3_v1.txt",
"L1Trigger/CSCTriggerPrimitives/data/CCLUT/CSCComparatorCodePosOffsetLUT_pat4_v1.txt"
),
slopeLUTFiles = cms.vstring(
"L1Trigger/CSCTriggerPrimitives/data/CCLUT/CSCComparatorCodeSlopeLUT_pat0_v1.txt",
"L1Trigger/CSCTriggerPrimitives/data/CCLUT/CSCComparatorCodeSlopeLUT_pat1_v1.txt",
"L1Trigger/CSCTriggerPrimitives/data/CCLUT/CSCComparatorCodeSlopeLUT_pat2_v1.txt",
"L1Trigger/CSCTriggerPrimitives/data/CCLUT/CSCComparatorCodeSlopeLUT_pat3_v1.txt",
"L1Trigger/CSCTriggerPrimitives/data/CCLUT/CSCComparatorCodeSlopeLUT_pat4_v1.txt"
),
## convert pad number to 1/2-strip in ME1a
padToHsME1aFiles = cms.vstring(
"L1Trigger/CSCTriggerPrimitives/data/GEMCSC/CoordinateConversion/GEMCSCLUT_pad_hs_ME1a_even.txt",
"L1Trigger/CSCTriggerPrimitives/data/GEMCSC/CoordinateConversion/GEMCSCLUT_pad_hs_ME1a_odd.txt",
),
## convert pad number to 1/2-strip in ME1b
padToHsME1bFiles = cms.vstring(
"L1Trigger/CSCTriggerPrimitives/data/GEMCSC/CoordinateConversion/GEMCSCLUT_pad_hs_ME1b_even.txt",
"L1Trigger/CSCTriggerPrimitives/data/GEMCSC/CoordinateConversion/GEMCSCLUT_pad_hs_ME1b_odd.txt",
),
## convert pad number to 1/2-strip in ME21
padToHsME21Files = cms.vstring(
"L1Trigger/CSCTriggerPrimitives/data/GEMCSC/CoordinateConversion/GEMCSCLUT_pad_hs_ME21_even.txt",
"L1Trigger/CSCTriggerPrimitives/data/GEMCSC/CoordinateConversion/GEMCSCLUT_pad_hs_ME21_odd.txt",
),
## convert pad number to 1/8-strip in ME1a
padToEsME1aFiles = cms.vstring(
"L1Trigger/CSCTriggerPrimitives/data/GEMCSC/CoordinateConversion/GEMCSCLUT_pad_es_ME1a_even.txt",
"L1Trigger/CSCTriggerPrimitives/data/GEMCSC/CoordinateConversion/GEMCSCLUT_pad_es_ME1a_odd.txt",
),
## convert pad number to 1/8-strip in ME1b
padToEsME1bFiles = cms.vstring(
"L1Trigger/CSCTriggerPrimitives/data/GEMCSC/CoordinateConversion/GEMCSCLUT_pad_es_ME1b_even.txt",
"L1Trigger/CSCTriggerPrimitives/data/GEMCSC/CoordinateConversion/GEMCSCLUT_pad_es_ME1b_odd.txt",
),
## convert pad number to 1/8-strip in ME21
padToEsME21Files = cms.vstring(
"L1Trigger/CSCTriggerPrimitives/data/GEMCSC/CoordinateConversion/GEMCSCLUT_pad_es_ME21_even.txt",
"L1Trigger/CSCTriggerPrimitives/data/GEMCSC/CoordinateConversion/GEMCSCLUT_pad_es_ME21_odd.txt",
),
## convert eta partition to minimum wiregroup in ME11
rollToMinWgME11Files = cms.vstring(
"L1Trigger/CSCTriggerPrimitives/data/GEMCSC/CoordinateConversion/GEMCSCLUT_roll_l1_min_wg_ME11_even.txt",
"L1Trigger/CSCTriggerPrimitives/data/GEMCSC/CoordinateConversion/GEMCSCLUT_roll_l1_min_wg_ME11_odd.txt",
"L1Trigger/CSCTriggerPrimitives/data/GEMCSC/CoordinateConversion/GEMCSCLUT_roll_l2_min_wg_ME11_even.txt",
"L1Trigger/CSCTriggerPrimitives/data/GEMCSC/CoordinateConversion/GEMCSCLUT_roll_l2_min_wg_ME11_odd.txt",
),
## convert eta partition to maximum wiregroup in ME11
rollToMaxWgME11Files = cms.vstring(
"L1Trigger/CSCTriggerPrimitives/data/GEMCSC/CoordinateConversion/GEMCSCLUT_roll_l1_max_wg_ME11_even.txt",
"L1Trigger/CSCTriggerPrimitives/data/GEMCSC/CoordinateConversion/GEMCSCLUT_roll_l1_max_wg_ME11_odd.txt",
"L1Trigger/CSCTriggerPrimitives/data/GEMCSC/CoordinateConversion/GEMCSCLUT_roll_l2_max_wg_ME11_even.txt",
"L1Trigger/CSCTriggerPrimitives/data/GEMCSC/CoordinateConversion/GEMCSCLUT_roll_l2_max_wg_ME11_odd.txt",
),
## convert eta partition to minimum wiregroup in ME21
rollToMinWgME21Files = cms.vstring(
"L1Trigger/CSCTriggerPrimitives/data/GEMCSC/CoordinateConversion/GEMCSCLUT_roll_l1_min_wg_ME21_even.txt",
"L1Trigger/CSCTriggerPrimitives/data/GEMCSC/CoordinateConversion/GEMCSCLUT_roll_l1_min_wg_ME21_odd.txt",
"L1Trigger/CSCTriggerPrimitives/data/GEMCSC/CoordinateConversion/GEMCSCLUT_roll_l2_min_wg_ME21_even.txt",
"L1Trigger/CSCTriggerPrimitives/data/GEMCSC/CoordinateConversion/GEMCSCLUT_roll_l2_min_wg_ME21_odd.txt",
),
## convert eta partition to maximum wiregroup in ME21
rollToMaxWgME21Files = cms.vstring(
"L1Trigger/CSCTriggerPrimitives/data/GEMCSC/CoordinateConversion/GEMCSCLUT_roll_l1_max_wg_ME21_even.txt",
"L1Trigger/CSCTriggerPrimitives/data/GEMCSC/CoordinateConversion/GEMCSCLUT_roll_l1_max_wg_ME21_odd.txt",
"L1Trigger/CSCTriggerPrimitives/data/GEMCSC/CoordinateConversion/GEMCSCLUT_roll_l2_max_wg_ME21_even.txt",
"L1Trigger/CSCTriggerPrimitives/data/GEMCSC/CoordinateConversion/GEMCSCLUT_roll_l2_max_wg_ME21_odd.txt",
),
)
211 changes: 211 additions & 0 deletions CalibMuon/CSCCalibration/src/CSCL1TPLookupTableEP.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
// system include files
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/ParameterSet/interface/FileInPath.h"
#include "FWCore/Framework/interface/SourceFactory.h"
#include "FWCore/Framework/interface/ModuleFactory.h"
#include "FWCore/Framework/interface/ESProducer.h"
#include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"

#include "CondFormats/DataRecord/interface/CSCL1TPLookupTableCCLUTRcd.h"
#include "CondFormats/DataRecord/interface/CSCL1TPLookupTableME11ILTRcd.h"
#include "CondFormats/DataRecord/interface/CSCL1TPLookupTableME21ILTRcd.h"
#include "CondFormats/CSCObjects/interface/CSCL1TPLookupTableCCLUT.h"
#include "CondFormats/CSCObjects/interface/CSCL1TPLookupTableME11ILT.h"
#include "CondFormats/CSCObjects/interface/CSCL1TPLookupTableME21ILT.h"

// user include files
#include <fstream>
#include <string>
#include <vector>
#include <unordered_map>

class CSCL1TPLookupTableEP : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
public:
CSCL1TPLookupTableEP(const edm::ParameterSet&);
~CSCL1TPLookupTableEP() override {}

std::unique_ptr<CSCL1TPLookupTableCCLUT> produceCCLUT(const CSCL1TPLookupTableCCLUTRcd&);
std::unique_ptr<CSCL1TPLookupTableME11ILT> produceME11ILT(const CSCL1TPLookupTableME11ILTRcd&);
std::unique_ptr<CSCL1TPLookupTableME21ILT> produceME21ILT(const CSCL1TPLookupTableME21ILTRcd&);

protected:
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
const edm::IOVSyncValue&,
edm::ValidityInterval&) override;

private:
std::vector<unsigned> load(std::string fileName) const;
const edm::ParameterSet& pset_;
};

CSCL1TPLookupTableEP::CSCL1TPLookupTableEP(const edm::ParameterSet& pset) : pset_(pset) {
setWhatProduced(this, &CSCL1TPLookupTableEP::produceCCLUT);
setWhatProduced(this, &CSCL1TPLookupTableEP::produceME11ILT);
setWhatProduced(this, &CSCL1TPLookupTableEP::produceME21ILT);
}

void CSCL1TPLookupTableEP::setIntervalFor(const edm::eventsetup::EventSetupRecordKey& iKey,
const edm::IOVSyncValue& iTime,
edm::ValidityInterval& oInterval) {
oInterval = edm::ValidityInterval(edm::IOVSyncValue::beginOfTime(), edm::IOVSyncValue::endOfTime()); //infinite
}

std::unique_ptr<CSCL1TPLookupTableCCLUT> CSCL1TPLookupTableEP::produceCCLUT(const CSCL1TPLookupTableCCLUTRcd&) {
// make the LUT object
std::unique_ptr<CSCL1TPLookupTableCCLUT> lut = std::make_unique<CSCL1TPLookupTableCCLUT>();

// get the text files
std::vector<std::string> positionLUTFiles_ = pset_.getParameter<std::vector<std::string>>("positionLUTFiles");
std::vector<std::string> slopeLUTFiles_ = pset_.getParameter<std::vector<std::string>>("slopeLUTFiles");

std::unordered_map<unsigned, std::vector<unsigned>> cclutPosition;
std::unordered_map<unsigned, std::vector<unsigned>> cclutSlope;

// read the text files and extract the data
for (int i = 0; i < 5; ++i) {
cclutPosition[i] = load(positionLUTFiles_[i]);
cclutSlope[i] = load(slopeLUTFiles_[i]);
}

// set the data in the LUT object
lut->set_cclutSlope(cclutPosition);
lut->set_cclutSlope(cclutSlope);

return lut;
}

std::unique_ptr<CSCL1TPLookupTableME11ILT> CSCL1TPLookupTableEP::produceME11ILT(const CSCL1TPLookupTableME11ILTRcd&) {
// make the LUT object
std::unique_ptr<CSCL1TPLookupTableME11ILT> lut = std::make_unique<CSCL1TPLookupTableME11ILT>();

// get the text files
std::vector<std::string> padToHsME1aFiles_ = pset_.getParameter<std::vector<std::string>>("padToHsME1aFiles");
std::vector<std::string> padToHsME1bFiles_ = pset_.getParameter<std::vector<std::string>>("padToHsME1bFiles");

std::vector<std::string> padToEsME1aFiles_ = pset_.getParameter<std::vector<std::string>>("padToEsME1aFiles");
std::vector<std::string> padToEsME1bFiles_ = pset_.getParameter<std::vector<std::string>>("padToEsME1bFiles");

std::vector<std::string> rollToMaxWgME11Files_ = pset_.getParameter<std::vector<std::string>>("rollToMaxWgME11Files");
std::vector<std::string> rollToMinWgME11Files_ = pset_.getParameter<std::vector<std::string>>("rollToMinWgME11Files");

// read the text files and extract the data
const auto& GEM_pad_CSC_hs_ME1a_even_ = load(padToHsME1aFiles_[0]);
const auto& GEM_pad_CSC_hs_ME1a_odd_ = load(padToHsME1aFiles_[1]);
const auto& GEM_pad_CSC_hs_ME1b_even_ = load(padToHsME1bFiles_[0]);
const auto& GEM_pad_CSC_hs_ME1b_odd_ = load(padToHsME1bFiles_[1]);

const auto& GEM_pad_CSC_es_ME1a_even_ = load(padToEsME1aFiles_[0]);
const auto& GEM_pad_CSC_es_ME1a_odd_ = load(padToEsME1aFiles_[1]);
const auto& GEM_pad_CSC_es_ME1b_even_ = load(padToEsME1bFiles_[0]);
const auto& GEM_pad_CSC_es_ME1b_odd_ = load(padToEsME1bFiles_[1]);

const auto& GEM_roll_L1_CSC_min_wg_ME11_even_ = load(rollToMinWgME11Files_[0]);
const auto& GEM_roll_L1_CSC_min_wg_ME11_odd_ = load(rollToMinWgME11Files_[1]);
const auto& GEM_roll_L2_CSC_min_wg_ME11_even_ = load(rollToMinWgME11Files_[2]);
const auto& GEM_roll_L2_CSC_min_wg_ME11_odd_ = load(rollToMinWgME11Files_[3]);

const auto& GEM_roll_L1_CSC_max_wg_ME11_even_ = load(rollToMaxWgME11Files_[0]);
const auto& GEM_roll_L1_CSC_max_wg_ME11_odd_ = load(rollToMaxWgME11Files_[1]);
const auto& GEM_roll_L2_CSC_max_wg_ME11_even_ = load(rollToMaxWgME11Files_[2]);
const auto& GEM_roll_L2_CSC_max_wg_ME11_odd_ = load(rollToMaxWgME11Files_[3]);

// set the data in the LUT object
lut->set_GEM_pad_CSC_hs_ME1b_even(GEM_pad_CSC_hs_ME1b_even_);
lut->set_GEM_pad_CSC_hs_ME1a_even(GEM_pad_CSC_hs_ME1a_even_);
lut->set_GEM_pad_CSC_hs_ME1b_odd(GEM_pad_CSC_hs_ME1b_odd_);
lut->set_GEM_pad_CSC_hs_ME1a_odd(GEM_pad_CSC_hs_ME1a_odd_);

lut->set_GEM_pad_CSC_es_ME1b_even(GEM_pad_CSC_es_ME1b_even_);
lut->set_GEM_pad_CSC_es_ME1a_even(GEM_pad_CSC_es_ME1a_even_);
lut->set_GEM_pad_CSC_es_ME1b_odd(GEM_pad_CSC_es_ME1b_odd_);
lut->set_GEM_pad_CSC_es_ME1a_odd(GEM_pad_CSC_es_ME1a_odd_);

lut->set_GEM_roll_L1_CSC_min_wg_ME11_even(GEM_roll_L1_CSC_min_wg_ME11_even_);
lut->set_GEM_roll_L1_CSC_max_wg_ME11_even(GEM_roll_L1_CSC_max_wg_ME11_even_);
lut->set_GEM_roll_L1_CSC_min_wg_ME11_odd(GEM_roll_L1_CSC_min_wg_ME11_odd_);
lut->set_GEM_roll_L1_CSC_max_wg_ME11_odd(GEM_roll_L1_CSC_max_wg_ME11_odd_);

lut->set_GEM_roll_L2_CSC_min_wg_ME11_even(GEM_roll_L2_CSC_min_wg_ME11_even_);
lut->set_GEM_roll_L2_CSC_max_wg_ME11_even(GEM_roll_L2_CSC_max_wg_ME11_even_);
lut->set_GEM_roll_L2_CSC_min_wg_ME11_odd(GEM_roll_L2_CSC_min_wg_ME11_odd_);
lut->set_GEM_roll_L2_CSC_max_wg_ME11_odd(GEM_roll_L2_CSC_max_wg_ME11_odd_);

return lut;
}

std::unique_ptr<CSCL1TPLookupTableME21ILT> CSCL1TPLookupTableEP::produceME21ILT(const CSCL1TPLookupTableME21ILTRcd&) {
// make the LUT object
std::unique_ptr<CSCL1TPLookupTableME21ILT> lut = std::make_unique<CSCL1TPLookupTableME21ILT>();

// get the text files
std::vector<std::string> padToHsME21Files_ = pset_.getParameter<std::vector<std::string>>("padToHsME21Files");
std::vector<std::string> padToEsME21Files_ = pset_.getParameter<std::vector<std::string>>("padToEsME21Files");

std::vector<std::string> rollToMaxWgME21Files_ = pset_.getParameter<std::vector<std::string>>("rollToMaxWgME21Files");
std::vector<std::string> rollToMinWgME21Files_ = pset_.getParameter<std::vector<std::string>>("rollToMinWgME21Files");

// read the text files and extract the data
const auto& GEM_pad_CSC_hs_ME21_even_ = load(padToHsME21Files_[0]);
const auto& GEM_pad_CSC_hs_ME21_odd_ = load(padToHsME21Files_[1]);

const auto& GEM_pad_CSC_es_ME21_even_ = load(padToEsME21Files_[0]);
const auto& GEM_pad_CSC_es_ME21_odd_ = load(padToEsME21Files_[1]);

const auto& GEM_roll_L1_CSC_min_wg_ME21_even_ = load(rollToMinWgME21Files_[0]);
const auto& GEM_roll_L1_CSC_min_wg_ME21_odd_ = load(rollToMinWgME21Files_[1]);
const auto& GEM_roll_L2_CSC_min_wg_ME21_even_ = load(rollToMinWgME21Files_[2]);
const auto& GEM_roll_L2_CSC_min_wg_ME21_odd_ = load(rollToMinWgME21Files_[3]);

const auto& GEM_roll_L1_CSC_max_wg_ME21_even_ = load(rollToMaxWgME21Files_[0]);
const auto& GEM_roll_L1_CSC_max_wg_ME21_odd_ = load(rollToMaxWgME21Files_[1]);
const auto& GEM_roll_L2_CSC_max_wg_ME21_even_ = load(rollToMaxWgME21Files_[2]);
const auto& GEM_roll_L2_CSC_max_wg_ME21_odd_ = load(rollToMaxWgME21Files_[3]);

// set the data in the LUT object
lut->set_GEM_pad_CSC_hs_ME21_even(GEM_pad_CSC_hs_ME21_even_);
lut->set_GEM_pad_CSC_hs_ME21_odd(GEM_pad_CSC_hs_ME21_odd_);

lut->set_GEM_pad_CSC_es_ME21_even(GEM_pad_CSC_es_ME21_even_);
lut->set_GEM_pad_CSC_es_ME21_odd(GEM_pad_CSC_es_ME21_odd_);

lut->set_GEM_roll_L1_CSC_min_wg_ME21_even(GEM_roll_L1_CSC_min_wg_ME21_even_);
lut->set_GEM_roll_L1_CSC_max_wg_ME21_even(GEM_roll_L1_CSC_max_wg_ME21_even_);
lut->set_GEM_roll_L1_CSC_min_wg_ME21_odd(GEM_roll_L1_CSC_min_wg_ME21_odd_);
lut->set_GEM_roll_L1_CSC_max_wg_ME21_odd(GEM_roll_L1_CSC_max_wg_ME21_odd_);

lut->set_GEM_roll_L2_CSC_min_wg_ME21_even(GEM_roll_L2_CSC_min_wg_ME21_even_);
lut->set_GEM_roll_L2_CSC_max_wg_ME21_even(GEM_roll_L2_CSC_max_wg_ME21_even_);
lut->set_GEM_roll_L2_CSC_min_wg_ME21_odd(GEM_roll_L2_CSC_min_wg_ME21_odd_);
lut->set_GEM_roll_L2_CSC_max_wg_ME21_odd(GEM_roll_L2_CSC_max_wg_ME21_odd_);

return lut;
}

std::vector<unsigned> CSCL1TPLookupTableEP::load(std::string fileName) const {

std::vector<unsigned> returnV;
std::ifstream fstream;
fstream.open(edm::FileInPath(fileName.c_str()).fullPath());
// empty file, return empty lut
if (!fstream.good()) {
fstream.close();
return returnV;
}

std::string line;

while (std::getline(fstream, line)) {
//ignore comments
line.erase(std::find(line.begin(), line.end(), '#'), line.end());
std::istringstream lineStream(line);
std::pair<unsigned, unsigned> entry;
while (lineStream >> entry.first >> entry.second) {
returnV.push_back(entry.second);
}
}
return returnV;
}


DEFINE_FWK_EVENTSETUP_SOURCE(CSCL1TPLookupTableEP);
30 changes: 30 additions & 0 deletions CondFormats/CSCObjects/interface/CSCL1TPLookupTableCCLUT.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef CondFormats_CSCObjects_CSCL1TPLookupTableCCLUT_h
#define CondFormats_CSCObjects_CSCL1TPLookupTableCCLUT_h

#include "CondFormats/Serialization/interface/Serializable.h"
#include <vector>
#include <unordered_map>

class CSCL1TPLookupTableCCLUT {
public:
CSCL1TPLookupTableCCLUT() {}
~CSCL1TPLookupTableCCLUT() {}

typedef std::unordered_map<unsigned, std::vector<unsigned> > t_lut;

// setters
void set_cclutPosition(const t_lut& lut) { cclutPosition_ = lut; }
void set_cclutSlope(const t_lut& lut) { cclutSlope_ = lut; }

// getters
unsigned cclutPosition(unsigned pattern, unsigned code) const { return cclutPosition_.at(pattern)[code]; }
unsigned cclutSlope(unsigned pattern, unsigned code) const { return cclutSlope_.at(pattern)[code]; }

private:
t_lut cclutPosition_;
t_lut cclutSlope_;

COND_SERIALIZABLE;
};

#endif
Loading

0 comments on commit 16987a2

Please sign in to comment.