File indexing completed on 2024-04-06 12:21:35
0001 #include "L1Trigger/RegionalCaloTrigger/interface/L1RCTProducer.h"
0002
0003
0004 #include "CondFormats/RunInfo/interface/RunInfo.h"
0005 #include "FWCore/Framework/interface/LuminosityBlock.h"
0006 #include "FWCore/Framework/interface/Run.h"
0007 #include "FWCore/Utilities/interface/Exception.h"
0008
0009 #include <vector>
0010 using std::vector;
0011 #include <iostream>
0012
0013 using std::cout;
0014 using std::endl;
0015 namespace {
0016 constexpr int crateFED[18][6] = {{613, 614, 603, 702, 718, 1118},
0017 {611, 612, 602, 700, 718, 1118},
0018 {627, 610, 601, 716, 722, 1122},
0019 {625, 626, 609, 714, 722, 1122},
0020 {623, 624, 608, 712, 722, 1122},
0021 {621, 622, 607, 710, 720, 1120},
0022 {619, 620, 606, 708, 720, 1120},
0023 {617, 618, 605, 706, 720, 1120},
0024 {615, 616, 604, 704, 718, 1118},
0025 {631, 632, 648, 703, 719, 1118},
0026 {629, 630, 647, 701, 719, 1118},
0027 {645, 628, 646, 717, 723, 1122},
0028 {643, 644, 654, 715, 723, 1122},
0029 {641, 642, 653, 713, 723, 1122},
0030 {639, 640, 652, 711, 721, 1120},
0031 {637, 638, 651, 709, 721, 1120},
0032 {635, 636, 650, 707, 721, 1120},
0033 {633, 634, 649, 705, 719, 1118}};
0034 }
0035 L1RCTProducer::L1RCTProducer(const edm::ParameterSet &conf)
0036 : rctLookupTables(new L1RCTLookupTables),
0037 rct(new L1RCT(rctLookupTables.get())),
0038 useEcal(conf.getParameter<bool>("useEcal")),
0039 useHcal(conf.getParameter<bool>("useHcal")),
0040 ecalDigis(conf.getParameter<std::vector<edm::InputTag>>("ecalDigis")),
0041 hcalDigis(conf.getParameter<std::vector<edm::InputTag>>("hcalDigis")),
0042 bunchCrossings(conf.getParameter<std::vector<int>>("BunchCrossings")),
0043 getFedsFromOmds(conf.getParameter<bool>("getFedsFromOmds")),
0044 queryDelayInLS(conf.getParameter<unsigned int>("queryDelayInLS")),
0045 queryIntervalInLS(conf.getParameter<unsigned int>("queryIntervalInLS")),
0046 conditionsLabel(conf.getParameter<std::string>("conditionsLabel")),
0047 fedUpdatedMask(nullptr),
0048
0049 rctParamsToken_(esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", conditionsLabel))),
0050 emScaleToken_(esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", conditionsLabel))),
0051 ecalScaleToken_(esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", conditionsLabel))),
0052 hcalScaleToken_(esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", conditionsLabel))),
0053
0054 beginRunRunInfoToken_(esConsumes<edm::Transition::BeginRun>()),
0055
0056 beginRunChannelMaskToken_(esConsumes<edm::Transition::BeginRun>()),
0057 beginRunHotChannelMaskToken_(esConsumes<edm::Transition::BeginRun>()) {
0058 produces<L1CaloEmCollection>();
0059 produces<L1CaloRegionCollection>();
0060
0061 if (getFedsFromOmds) {
0062 beginLumiChannelMaskToken_ = esConsumes<edm::Transition::BeginLuminosityBlock>();
0063 beginLumiHotChannelMaskToken_ = esConsumes<edm::Transition::BeginLuminosityBlock>();
0064 beginLumiRunInfoToken_ = esConsumes<edm::Transition::BeginLuminosityBlock>();
0065 omdsRunInfoToken_ = esConsumes<edm::Transition::BeginLuminosityBlock>(edm::ESInputTag("", "OmdsFedVector"));
0066 }
0067
0068 for (unsigned int ihc = 0; ihc < hcalDigis.size(); ihc++) {
0069 consumes<edm::SortedCollection<HcalTriggerPrimitiveDigi, edm::StrictWeakOrdering<HcalTriggerPrimitiveDigi>>>(
0070 hcalDigis[ihc]);
0071 }
0072
0073 for (unsigned int iec = 0; iec < ecalDigis.size(); iec++) {
0074 consumes<edm::SortedCollection<EcalTriggerPrimitiveDigi, edm::StrictWeakOrdering<EcalTriggerPrimitiveDigi>>>(
0075 ecalDigis[iec]);
0076 }
0077 }
0078
0079 void L1RCTProducer::beginRun(edm::Run const &run, const edm::EventSetup &eventSetup) {
0080
0081
0082 updateConfiguration(eventSetup);
0083
0084
0085 L1RCTChannelMask const &channelMask = eventSetup.getData(beginRunChannelMaskToken_);
0086
0087
0088 L1RCTNoisyChannelMask const &hotChannelMask = eventSetup.getData(beginRunHotChannelMaskToken_);
0089
0090 updateFedVector(channelMask, hotChannelMask, getFedVectorFromRunInfo(beginRunRunInfoToken_, eventSetup));
0091 }
0092
0093 void L1RCTProducer::beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, const edm::EventSetup &context) {
0094
0095
0096
0097 if (getFedsFromOmds) {
0098 throw cms::Exception("L1RCTProducer Configuration")
0099 << "L1RCTProducer is being run with the configuration parameter getFedsFromOmds set true. "
0100 << "Underlying Framework changes have broken the implementation of that option. "
0101 << "It was not fixed because we believe this option is no longer used or needed. "
0102 << "If you actually need this option, please report this failure to the Framework. "
0103 << "For more details see GitHub Issue 43697.";
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129 }
0130 }
0131
0132 void L1RCTProducer::updateConfiguration(const edm::EventSetup &eventSetup) {
0133
0134
0135
0136
0137
0138 const L1RCTParameters *r = &eventSetup.getData(rctParamsToken_);
0139
0140
0141
0142
0143 const L1CaloEtScale *s = &eventSetup.getData(emScaleToken_);
0144
0145
0146 const L1CaloEcalScale *e = &eventSetup.getData(ecalScaleToken_);
0147
0148
0149 const L1CaloHcalScale *h = &eventSetup.getData(hcalScaleToken_);
0150
0151
0152 rctLookupTables->setEcalScale(e);
0153 rctLookupTables->setHcalScale(h);
0154
0155 rctLookupTables->setRCTParameters(r);
0156 rctLookupTables->setL1CaloEtScale(s);
0157 }
0158
0159 void L1RCTProducer::updateFedVector(const L1RCTChannelMask &channelMask,
0160 const L1RCTNoisyChannelMask &hotChannelMask,
0161 const std::vector<int> &Feds)
0162
0163 {
0164 rctLookupTables->setNoisyChannelMask(&hotChannelMask);
0165
0166
0167
0168
0169
0170 fedUpdatedMask = std::make_unique<L1RCTChannelMask>();
0171
0172 for (int i = 0; i < 18; i++) {
0173 for (int j = 0; j < 2; j++) {
0174 for (int k = 0; k < 28; k++) {
0175 fedUpdatedMask->ecalMask[i][j][k] = channelMask.ecalMask[i][j][k];
0176 fedUpdatedMask->hcalMask[i][j][k] = channelMask.hcalMask[i][j][k];
0177 }
0178 for (int k = 0; k < 4; k++) {
0179 fedUpdatedMask->hfMask[i][j][k] = channelMask.hfMask[i][j][k];
0180 }
0181 }
0182 }
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193 bool useUpgradedHF = false;
0194
0195 std::vector<int> caloFeds;
0196
0197
0198 for (std::vector<int>::const_iterator cf = Feds.begin(); cf != Feds.end(); ++cf) {
0199 int fedNum = *cf;
0200 if ((fedNum > 600 && fedNum < 724) || fedNum == 1118 || fedNum == 1120 || fedNum == 1122)
0201 caloFeds.push_back(fedNum);
0202
0203 if (fedNum == 1118 || fedNum == 1120 || fedNum == 1122)
0204 useUpgradedHF = true;
0205 }
0206
0207 for (int cr = 0; cr < 18; ++cr) {
0208 for (crateSection cs = c_min; cs <= c_max; cs = crateSection(cs + 1)) {
0209 bool fedFound = false;
0210
0211
0212 std::vector<int>::iterator fv = std::find(caloFeds.begin(), caloFeds.end(), crateFED[cr][cs]);
0213 if (fv != caloFeds.end())
0214 fedFound = true;
0215
0216 if (!fedFound) {
0217 int eta_min = 0;
0218 int eta_max = 0;
0219 bool phi_even[2] = {false};
0220 bool ecal = false;
0221
0222 switch (cs) {
0223 case ebEvenFed:
0224 eta_min = minBarrel;
0225 eta_max = maxBarrel;
0226 phi_even[0] = true;
0227 ecal = true;
0228 break;
0229
0230 case ebOddFed:
0231 eta_min = minBarrel;
0232 eta_max = maxBarrel;
0233 phi_even[1] = true;
0234 ecal = true;
0235 break;
0236
0237 case eeFed:
0238 eta_min = minEndcap;
0239 eta_max = maxEndcap;
0240 phi_even[0] = true;
0241 phi_even[1] = true;
0242 ecal = true;
0243 break;
0244
0245 case hbheFed:
0246 eta_min = minBarrel;
0247 eta_max = maxEndcap;
0248 phi_even[0] = true;
0249 phi_even[1] = true;
0250 ecal = false;
0251 break;
0252
0253 case hfFed:
0254 if (useUpgradedHF)
0255 break;
0256
0257 eta_min = minHF;
0258 eta_max = maxHF;
0259
0260 phi_even[0] = true;
0261 phi_even[1] = true;
0262 ecal = false;
0263 break;
0264
0265 case hfFedUp:
0266 if (!useUpgradedHF)
0267 break;
0268
0269 eta_min = minHF;
0270 eta_max = maxHF;
0271
0272 phi_even[0] = true;
0273 phi_even[1] = true;
0274 ecal = false;
0275 break;
0276
0277 default:
0278 break;
0279 }
0280 for (int ieta = eta_min; ieta <= eta_max; ++ieta) {
0281 if (ieta <= 28)
0282 for (int even = 0; even <= 1; even++) {
0283 if (phi_even[even]) {
0284 if (ecal)
0285 fedUpdatedMask->ecalMask[cr][even][ieta - 1] = true;
0286 else
0287 fedUpdatedMask->hcalMask[cr][even][ieta - 1] = true;
0288 }
0289 }
0290 else
0291 for (int even = 0; even <= 1; even++)
0292 if (phi_even[even])
0293 fedUpdatedMask->hfMask[cr][even][ieta - 29] = true;
0294 }
0295 }
0296 }
0297 }
0298
0299 rctLookupTables->setChannelMask(fedUpdatedMask.get());
0300 }
0301
0302 const std::vector<int> L1RCTProducer::getFedVectorFromRunInfo(const edm::ESGetToken<RunInfo, RunInfoRcd> &token,
0303 const edm::EventSetup &eventSetup) const {
0304
0305
0306
0307 return eventSetup.getData(token).m_fed_in;
0308 }
0309
0310 const std::vector<int> L1RCTProducer::getFedVectorFromOmds(const edm::EventSetup &eventSetup) const {
0311
0312
0313
0314
0315
0316 edm::ESHandle<RunInfo> sum = eventSetup.getHandle(omdsRunInfoToken_);
0317 if (sum.isValid()) {
0318 return sum->m_fed_in;
0319 } else {
0320 return getFedVectorFromRunInfo(beginLumiRunInfoToken_, eventSetup);
0321 }
0322 }
0323
0324 void L1RCTProducer::produce(edm::Event &event, const edm::EventSetup &eventSetup) {
0325 std::unique_ptr<L1CaloEmCollection> rctEmCands(new L1CaloEmCollection);
0326 std::unique_ptr<L1CaloRegionCollection> rctRegions(new L1CaloRegionCollection);
0327
0328 if (!(ecalDigis.size() == hcalDigis.size() && hcalDigis.size() == bunchCrossings.size()))
0329 throw cms::Exception("BadInput") << "From what I see the number of your your ECAL input digi "
0330 "collections.\n"
0331 << "is different from the size of your HCAL digi input collections\n"
0332 << "or the size of your BX factor collection"
0333 << "They must be the same to correspond to the same Bxs\n"
0334 << "It does not matter if one of them is empty\n";
0335
0336
0337 for (unsigned short sample = 0; sample < bunchCrossings.size(); sample++) {
0338 edm::Handle<EcalTrigPrimDigiCollection> ecal;
0339 edm::Handle<HcalTrigPrimDigiCollection> hcal;
0340
0341 EcalTrigPrimDigiCollection ecalIn;
0342 HcalTrigPrimDigiCollection hcalIn;
0343
0344 if (useHcal && event.getByLabel(hcalDigis[sample], hcal))
0345 hcalIn = *hcal;
0346
0347 if (useEcal && event.getByLabel(ecalDigis[sample], ecal))
0348 ecalIn = *ecal;
0349
0350 rct->digiInput(ecalIn, hcalIn);
0351 rct->processEvent();
0352
0353
0354 for (int j = 0; j < 18; j++) {
0355 L1CaloEmCollection isolatedEGObjects = rct->getIsolatedEGObjects(j);
0356 L1CaloEmCollection nonisolatedEGObjects = rct->getNonisolatedEGObjects(j);
0357 for (int i = 0; i < 4; i++) {
0358 isolatedEGObjects.at(i).setBx(bunchCrossings[sample]);
0359 nonisolatedEGObjects.at(i).setBx(bunchCrossings[sample]);
0360 rctEmCands->push_back(isolatedEGObjects.at(i));
0361 rctEmCands->push_back(nonisolatedEGObjects.at(i));
0362 }
0363 }
0364
0365 for (int i = 0; i < 18; i++) {
0366 std::vector<L1CaloRegion> regions = rct->getRegions(i);
0367 for (int j = 0; j < 22; j++) {
0368 regions.at(j).setBx(bunchCrossings[sample]);
0369 rctRegions->push_back(regions.at(j));
0370 }
0371 }
0372 }
0373
0374
0375 event.put(std::move(rctEmCands));
0376 event.put(std::move(rctRegions));
0377 }
0378
0379
0380 void L1RCTProducer::printFedVector(const std::vector<int> &fedVector) {
0381 std::cout << "Contents of given fedVector: ";
0382 std::copy(fedVector.begin(), fedVector.end(), std::ostream_iterator<int>(std::cout, ", "));
0383 std::cout << std::endl;
0384 }
0385
0386
0387 void L1RCTProducer::printUpdatedFedMask() {
0388 if (fedUpdatedMask != nullptr) {
0389 fedUpdatedMask->print(std::cout);
0390 } else {
0391 std::cout << "Trying to print contents of fedUpdatedMask, but it doesn't exist!" << std::endl;
0392 }
0393 }
0394
0395
0396 void L1RCTProducer::printUpdatedFedMaskVerbose() {
0397 if (fedUpdatedMask != nullptr) {
0398
0399 std::cout << "Contents of fedUpdatedMask: ";
0400
0401
0402 std::cout << "--> ECAL mask: " << std::endl;
0403 for (int i = 0; i < 18; i++) {
0404 for (int j = 0; j < 2; j++) {
0405 for (int k = 0; k < 28; k++) {
0406 std::cout << fedUpdatedMask->ecalMask[i][j][k] << ", ";
0407 }
0408 }
0409 }
0410 std::cout << "--> HCAL mask: " << std::endl;
0411 for (int i = 0; i < 18; i++) {
0412 for (int j = 0; j < 2; j++) {
0413 for (int k = 0; k < 28; k++) {
0414 std::cout << fedUpdatedMask->hcalMask[i][j][k] << ", ";
0415 }
0416 }
0417 }
0418 std::cout << "--> HF mask: " << std::endl;
0419 for (int i = 0; i < 18; i++) {
0420 for (int j = 0; j < 2; j++) {
0421 for (int k = 0; k < 4; k++) {
0422 std::cout << fedUpdatedMask->hfMask[i][j][k] << ", ";
0423 }
0424 }
0425 }
0426
0427 std::cout << std::endl;
0428 } else {
0429
0430 std::cout << "Trying to print contents of fedUpdatedMask, but it doesn't exist!" << std::endl;
0431 }
0432 }