File indexing completed on 2024-04-06 12:22:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #include "CondTools/L1Trigger/interface/L1ConfigOnlineProdBase.h"
0023 #include "CondFormats/L1TObjects/interface/L1CaloEcalScale.h"
0024 #include "CondFormats/DataRecord/interface/L1CaloEcalScaleRcd.h"
0025 #include "CondFormats/EcalObjects/interface/EcalTPGLutIdMap.h"
0026 #include "CondFormats/EcalObjects/interface/EcalTPGLutGroup.h"
0027 #include "CondFormats/EcalObjects/interface/EcalTPGPhysicsConst.h"
0028 #include "DataFormats/EcalDigi/interface/EcalTriggerPrimitiveDigi.h"
0029 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
0030 #include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"
0031 #include "DataFormats/EcalDetId/interface/EcalElectronicsId.h"
0032
0033
0034
0035
0036
0037 class L1CaloEcalScaleConfigOnlineProd : public L1ConfigOnlineProdBase<L1CaloEcalScaleRcd, L1CaloEcalScale> {
0038 public:
0039 L1CaloEcalScaleConfigOnlineProd(const edm::ParameterSet&);
0040 ~L1CaloEcalScaleConfigOnlineProd() override;
0041
0042 std::unique_ptr<L1CaloEcalScale> newObject(const std::string& objectKey) override;
0043
0044 private:
0045 const EcalElectronicsMapping* theMapping_;
0046 std::map<int, std::vector<int>*> groupInfo;
0047 EcalTPGGroups* lutGrpMap;
0048 };
0049
0050 L1CaloEcalScaleConfigOnlineProd::L1CaloEcalScaleConfigOnlineProd(const edm::ParameterSet& iConfig)
0051 : L1ConfigOnlineProdBase<L1CaloEcalScaleRcd, L1CaloEcalScale>(iConfig) {
0052 theMapping_ = new EcalElectronicsMapping();
0053 lutGrpMap = new EcalTPGGroups();
0054 }
0055
0056 L1CaloEcalScaleConfigOnlineProd::~L1CaloEcalScaleConfigOnlineProd() {
0057
0058
0059 delete theMapping_;
0060
0061
0062 groupInfo.clear();
0063 }
0064
0065 std::unique_ptr<L1CaloEcalScale> L1CaloEcalScaleConfigOnlineProd::newObject(const std::string& objectKey) {
0066 std::cout << "object Key " << objectKey << std::endl;
0067
0068 if (objectKey == "NULL" || objectKey.empty()) {
0069 return std::make_unique<L1CaloEcalScale>(0);
0070 }
0071 if (objectKey == "IDENTITY") {
0072 return std::make_unique<L1CaloEcalScale>(1);
0073 }
0074
0075 double ee_lsb = 0.;
0076 double eb_lsb = 0.;
0077
0078 std::vector<std::string> mainStrings;
0079
0080
0081
0082 std::vector<std::string> paramStrings;
0083 paramStrings.push_back("LOGIC_ID");
0084 paramStrings.push_back("ETSAT");
0085
0086 std::vector<std::string> IDStrings;
0087 IDStrings.push_back("NAME");
0088 IDStrings.push_back("ID1");
0089 IDStrings.push_back("ID2");
0090 IDStrings.push_back("maps_to");
0091
0092 l1t::OMDSReader::QueryResults paramResults = m_omdsReader.basicQuery(paramStrings,
0093 "CMS_ECAL_CONF",
0094 "FE_CONFIG_LUTPARAM_DAT",
0095 "FE_CONFIG_LUTPARAM_DAT.LUT_CONF_ID",
0096 m_omdsReader.singleAttribute(objectKey));
0097
0098 if (paramResults.queryFailed() || (paramResults.numberRows() == 0))
0099 {
0100 edm::LogError("L1-O2O") << "Problem with L1CaloEcalScale key. Unable to find lutparam dat table";
0101 return std::unique_ptr<L1CaloEcalScale>();
0102 }
0103
0104 for (int i = 0; i < paramResults.numberRows(); i++) {
0105
0106 float etSat;
0107 paramResults.fillVariableFromRow("ETSAT", i, etSat);
0108
0109 std::string ecid_name;
0110 int logic_id;
0111 paramResults.fillVariableFromRow("LOGIC_ID", i, logic_id);
0112
0113 l1t::OMDSReader::QueryResults logicID = m_omdsReader.basicQuery(
0114 IDStrings, "CMS_ECAL_COND", "CHANNELVIEW", "CHANNELVIEW.LOGIC_ID", m_omdsReader.singleAttribute(logic_id));
0115
0116 logicID.fillVariable("NAME", ecid_name);
0117
0118 if (ecid_name == "EB")
0119 eb_lsb = etSat / 1024;
0120 else if ("EE" == ecid_name)
0121 ee_lsb = etSat / 1024;
0122 else {
0123 edm::LogError("L1-O2O")
0124 << "Problem with L1CaloEcalScale LOGIC_ID. unable to find channel view with appropiate logic id";
0125 return std::unique_ptr<L1CaloEcalScale>();
0126 }
0127 }
0128
0129
0130 std::vector<std::string> grpLUT;
0131 grpLUT.push_back("GROUP_ID");
0132 grpLUT.push_back("LUT_ID");
0133 grpLUT.push_back("LUT_VALUE");
0134
0135 l1t::OMDSReader::QueryResults lutGrpResults = m_omdsReader.basicQuery(grpLUT,
0136 "CMS_ECAL_CONF",
0137 "FE_LUT_PER_GROUP_DAT",
0138 "FE_LUT_PER_GROUP_DAT.LUT_CONF_ID",
0139 m_omdsReader.singleAttribute(objectKey));
0140
0141 if (lutGrpResults.queryFailed() || (lutGrpResults.numberRows() % 1024 != 0))
0142 {
0143 edm::LogError("L1-O2O") << "Problem with L1CaloEcalScale key. No group info";
0144 return std::unique_ptr<L1CaloEcalScale>();
0145 }
0146
0147 int nEntries = lutGrpResults.numberRows();
0148 for (int i = 0; i < nEntries; i++) {
0149 int group, lutID;
0150 float lutValue;
0151
0152 lutGrpResults.fillVariableFromRow("GROUP_ID", i, group);
0153 if (groupInfo.find(group) == groupInfo.end()) {
0154 groupInfo[group] = new std::vector<int>;
0155 (groupInfo[group])->resize(1024);
0156 }
0157
0158 lutGrpResults.fillVariableFromRow("LUT_ID", i, lutID);
0159 lutGrpResults.fillVariableFromRow("LUT_VALUE", i, lutValue);
0160 groupInfo[group]->at(lutID) = (int)lutValue;
0161 }
0162
0163 std::map<int, std::vector<int> > tpgValueMap;
0164
0165 std::map<int, std::vector<int>*>::iterator grpIt;
0166 for (grpIt = groupInfo.begin(); grpIt != groupInfo.end(); ++grpIt) {
0167 const std::vector<int>* lut_ = grpIt->second;
0168
0169 std::vector<int> tpgValue;
0170 tpgValue.resize(256);
0171 int lastValue = 0;
0172 for (int tpg = 0; tpg < 256; tpg++) {
0173 for (int i = 0; i < 1024; i++) {
0174 if (tpg == (0xff & (lut_->at(i)))) {
0175 tpgValue[tpg] = i;
0176 lastValue = i;
0177 break;
0178 }
0179 tpgValue[tpg] = lastValue;
0180 }
0181 }
0182 tpgValueMap[grpIt->first] = tpgValue;
0183 }
0184
0185 std::vector<std::string> groupMap;
0186 groupMap.push_back("LOGIC_ID");
0187 groupMap.push_back("GROUP_ID");
0188
0189 l1t::OMDSReader::QueryResults grpMapResults = m_omdsReader.basicQuery(groupMap,
0190 "CMS_ECAL_CONF",
0191 "FE_CONFIG_LUT_DAT",
0192 "FE_CONFIG_LUT_DAT.LUT_CONF_ID",
0193 m_omdsReader.singleAttribute(objectKey));
0194 if (grpMapResults.queryFailed() || (grpMapResults.numberRows() == 0))
0195 {
0196 edm::LogError("L1-O2O") << "Problem with L1CaloEcalScale key. No fe_config_lut_dat info";
0197 return std::unique_ptr<L1CaloEcalScale>();
0198 }
0199
0200 nEntries = grpMapResults.numberRows();
0201 for (int i = 0; i < nEntries; ++i) {
0202 std::string ecid_name;
0203 int logic_id;
0204 grpMapResults.fillVariableFromRow("LOGIC_ID", i, logic_id);
0205 int group_id;
0206 grpMapResults.fillVariableFromRow("GROUP_ID", i, group_id);
0207
0208
0209 l1t::OMDSReader::QueryResults IDResults = m_omdsReader.basicQuery(
0210 IDStrings, "CMS_ECAL_COND", "CHANNELVIEW", "CHANNELVIEW.LOGIC_ID", m_omdsReader.singleAttribute(logic_id));
0211 if (paramResults.queryFailed() || (paramResults.numberRows() == 0))
0212 {
0213 edm::LogError("L1-O2O") << "Problem with L1CaloEcalScale key. Unable to find logic_id channel view";
0214 return std::unique_ptr<L1CaloEcalScale>();
0215 }
0216 for (int j = 0; j < IDResults.numberRows(); j++) {
0217 std::string ecid_name, maps_to;
0218
0219 IDResults.fillVariableFromRow("NAME", j, ecid_name);
0220 IDResults.fillVariableFromRow("maps_to", j, maps_to);
0221 if (logic_id >= 2100001901 && logic_id <= 2100001916)
0222
0223 if (ecid_name != maps_to) {
0224 continue;
0225 }
0226 if (ecid_name == "EB_trigger_tower" || ecid_name == "EE_trigger_tower") {
0227 int id1, id2;
0228 IDResults.fillVariableFromRow("ID1", j, id1);
0229 IDResults.fillVariableFromRow("ID2", j, id2);
0230
0231 if (ecid_name == "EB_trigger_tower")
0232 id1 += 36;
0233 EcalTrigTowerDetId temp = theMapping_->getTrigTowerDetId(id1, id2);
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253 lutGrpMap->setValue(temp, group_id);
0254 break;
0255 }
0256 }
0257 }
0258
0259 const EcalTPGGroups::EcalTPGGroupsMap& gMap = lutGrpMap->getMap();
0260
0261 auto ecalScale = std::make_unique<L1CaloEcalScale>(0);
0262
0263 for (unsigned short ieta = 1; ieta <= L1CaloEcalScale::nBinEta; ++ieta) {
0264 EcalSubdetector subdet = (ieta <= 17) ? EcalBarrel : EcalEndcap;
0265 double et_lsb = (ieta <= 17) ? eb_lsb : ee_lsb;
0266 for (int pos = 0; pos <= 1; pos++) {
0267 int zside = (int)pow(-1, pos);
0268
0269
0270 for (int iphi = 1; iphi <= 72; iphi++) {
0271 if (!EcalTrigTowerDetId::validDetId(zside, subdet, ieta, iphi))
0272 continue;
0273 EcalTrigTowerDetId test(zside, subdet, ieta, iphi);
0274 EcalTPGGroups::EcalTPGGroupsMapItr itLut = gMap.find(test);
0275 if (itLut != gMap.end()) {
0276
0277 std::vector<int> tpgValue = tpgValueMap[itLut->second];
0278
0279 for (unsigned short irank = 0; irank < L1CaloEcalScale::nBinRank; ++irank) {
0280 ecalScale->setBin(irank, ieta, zside, et_lsb * tpgValue[irank]);
0281
0282
0283 }
0284
0285 break;
0286 }
0287 }
0288 }
0289 }
0290
0291
0292
0293
0294 return ecalScale;
0295 }
0296
0297 DEFINE_FWK_EVENTSETUP_MODULE(L1CaloEcalScaleConfigOnlineProd);