File indexing completed on 2023-10-25 09:42:08
0001 #include "DQM/EcalMonitorTasks/interface/TrigPrimTask.h"
0002
0003 #include "DQM/EcalCommon/interface/EcalDQMCommonUtils.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Common/interface/TriggerResultsByName.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009
0010 #include <iomanip>
0011
0012 namespace ecaldqm {
0013 TrigPrimTask::TrigPrimTask()
0014 : DQWorkerTask(),
0015 realTps_(nullptr),
0016 runOnEmul_(false),
0017
0018
0019
0020
0021 bxBinEdges_(),
0022 bxBinEdgesFine_(),
0023 bxBin_(0.),
0024 bxBinFine_(0.),
0025 towerReadouts_(),
0026 lhcStatusInfoCollectionTag_() {}
0027
0028 void TrigPrimTask::setParams(edm::ParameterSet const& _params) {
0029 runOnEmul_ = _params.getUntrackedParameter<bool>("runOnEmul");
0030 if (!runOnEmul_) {
0031 MEs_.erase(std::string("EtMaxEmul"));
0032 MEs_.erase(std::string("EmulMaxIndex"));
0033 MEs_.erase(std::string("MatchedIndex"));
0034 MEs_.erase(std::string("EtEmulError"));
0035 MEs_.erase(std::string("FGEmulError"));
0036 MEs_.erase(std::string("RealvEmulEt"));
0037 }
0038 lhcStatusInfoCollectionTag_ = _params.getUntrackedParameter<edm::InputTag>(
0039 "lhcStatusInfoCollectionTag", edm::InputTag("tcdsDigis", "tcdsRecord"));
0040 bxBinEdges_ = _params.getUntrackedParameter<std::vector<int> >("bxBins");
0041 bxBinEdgesFine_ = _params.getUntrackedParameter<std::vector<int> >("bxBinsFine");
0042 }
0043
0044 void TrigPrimTask::addDependencies(DependencySet& _dependencies) {
0045 if (runOnEmul_)
0046 _dependencies.push_back(Dependency(kTrigPrimEmulDigi, kEBDigi, kEEDigi, kTrigPrimDigi));
0047 }
0048
0049 void TrigPrimTask::beginRun(edm::Run const&, edm::EventSetup const& _es) {
0050
0051
0052
0053 TTStatus = &_es.getData(TTStatusRcd_);
0054 StripStatus = &_es.getData(StripStatusRcd_);
0055 }
0056
0057 void TrigPrimTask::beginEvent(edm::Event const& _evt,
0058 edm::EventSetup const& _es,
0059 bool const& ByLumiResetSwitch,
0060 bool& lhcStatusSet) {
0061 using namespace std;
0062
0063 towerReadouts_.clear();
0064
0065 if (ByLumiResetSwitch) {
0066 MEs_.at("EtSummaryByLumi").reset(GetElectronicsMap());
0067 MEs_.at("TTFlags4ByLumi").reset(GetElectronicsMap());
0068 MEs_.at("LHCStatusByLumi").reset(GetElectronicsMap(), -1);
0069 }
0070
0071 if (!lhcStatusSet) {
0072
0073 MESet& meLHCStatusByLumi(static_cast<MESet&>(MEs_.at("LHCStatusByLumi")));
0074 edm::Handle<TCDSRecord> tcdsData;
0075 _evt.getByToken(lhcStatusInfoRecordToken_, tcdsData);
0076 if (tcdsData.isValid()) {
0077 meLHCStatusByLumi.fill(getEcalDQMSetupObjects(), double(tcdsData->getBST().getBeamMode()));
0078 lhcStatusSet = true;
0079 }
0080 }
0081
0082 realTps_ = nullptr;
0083
0084
0085
0086
0087 std::vector<int>::iterator pBin(std::upper_bound(bxBinEdges_.begin(), bxBinEdges_.end(), _evt.bunchCrossing()));
0088 bxBin_ = static_cast<int>(pBin - bxBinEdges_.begin()) - 0.5;
0089
0090 std::vector<int>::iterator pBinFine(
0091 std::upper_bound(bxBinEdgesFine_.begin(), bxBinEdgesFine_.end(), _evt.bunchCrossing()));
0092 bxBinFine_ = static_cast<int>(pBinFine - bxBinEdgesFine_.begin()) - 0.5;
0093
0094 const EcalTPGTowerStatusMap& towerMap = TTStatus->getMap();
0095 const EcalTPGStripStatusMap& stripMap = StripStatus->getMap();
0096
0097 MESet& meTTMaskMap(MEs_.at("TTMaskMap"));
0098
0099 for (EcalTPGTowerStatusMap::const_iterator ttItr(towerMap.begin()); ttItr != towerMap.end(); ++ttItr) {
0100 if ((*ttItr).second > 0) {
0101 const EcalTrigTowerDetId ttid((*ttItr).first);
0102
0103 meTTMaskMap.fill(getEcalDQMSetupObjects(), ttid, 1);
0104 }
0105 }
0106
0107 for (EcalTPGStripStatusMap::const_iterator stItr(stripMap.begin()); stItr != stripMap.end(); ++stItr) {
0108 if ((*stItr).second > 0) {
0109 const EcalElectronicsId stid((*stItr).first);
0110
0111 meTTMaskMap.fill(getEcalDQMSetupObjects(), stid, 1);
0112 }
0113 }
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169 }
0170
0171 template <typename DigiCollection>
0172 void TrigPrimTask::runOnDigis(DigiCollection const& _digis) {
0173 for (typename DigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr) {
0174 EcalTrigTowerDetId ttid(GetTrigTowerMap()->towerOf(digiItr->id()));
0175 towerReadouts_[ttid.rawId()]++;
0176 }
0177 }
0178
0179 void TrigPrimTask::setTokens(edm::ConsumesCollector& _collector) {
0180 lhcStatusInfoRecordToken_ = _collector.consumes<TCDSRecord>(lhcStatusInfoCollectionTag_);
0181 TTStatusRcd_ = _collector.esConsumes<edm::Transition::BeginRun>();
0182 StripStatusRcd_ = _collector.esConsumes<edm::Transition::BeginRun>();
0183 }
0184
0185 void TrigPrimTask::runOnRealTPs(EcalTrigPrimDigiCollection const& _tps) {
0186 MESet& meEtVsBx(MEs_.at("EtVsBx"));
0187 MESet& meEtReal(MEs_.at("EtReal"));
0188 MESet& meEtRealMap(MEs_.at("EtRealMap"));
0189 MESet& meEtSummary(MEs_.at("EtSummary"));
0190 MESet& meEtSummaryByLumi(MEs_.at("EtSummaryByLumi"));
0191 MESet& meLowIntMap(MEs_.at("LowIntMap"));
0192 MESet& meMedIntMap(MEs_.at("MedIntMap"));
0193 MESet& meHighIntMap(MEs_.at("HighIntMap"));
0194 MESet& meTTFlags(MEs_.at("TTFlags"));
0195 MESet& meTTFlagsVsEt(MEs_.at("TTFlagsVsEt"));
0196 MESet& meTTFlags4(MEs_.at("TTFlags4"));
0197 MESet& meTTFlags4ByLumi(MEs_.at("TTFlags4ByLumi"));
0198 MESet& meTTFMismatch(MEs_.at("TTFMismatch"));
0199 MESet& meOccVsBx(MEs_.at("OccVsBx"));
0200
0201 realTps_ = &_tps;
0202
0203 double nTP[] = {0., 0., 0.};
0204
0205 for (EcalTrigPrimDigiCollection::const_iterator tpItr(_tps.begin()); tpItr != _tps.end(); ++tpItr) {
0206 EcalTrigTowerDetId ttid(tpItr->id());
0207 float et(tpItr->compressedEt());
0208
0209 if (et > 0.) {
0210 if (ttid.subDet() == EcalBarrel)
0211 nTP[0] += 1.;
0212 else if (ttid.zside() < 0)
0213 nTP[1] += 1.;
0214 else
0215 nTP[2] += 2.;
0216 meEtVsBx.fill(getEcalDQMSetupObjects(), ttid, bxBin_, et);
0217 }
0218
0219 meEtReal.fill(getEcalDQMSetupObjects(), ttid, et);
0220 meEtRealMap.fill(getEcalDQMSetupObjects(), ttid, et);
0221 meEtSummary.fill(getEcalDQMSetupObjects(), ttid, et);
0222 meEtSummaryByLumi.fill(getEcalDQMSetupObjects(), ttid, et);
0223
0224 int interest(tpItr->ttFlag() & 0x3);
0225
0226 switch (interest) {
0227 case 0:
0228 meLowIntMap.fill(getEcalDQMSetupObjects(), ttid);
0229 break;
0230 case 1:
0231 meMedIntMap.fill(getEcalDQMSetupObjects(), ttid);
0232 break;
0233 case 3:
0234 meHighIntMap.fill(getEcalDQMSetupObjects(), ttid);
0235 break;
0236 default:
0237 break;
0238 }
0239
0240
0241 int ttF(tpItr->ttFlag());
0242 meTTFlags.fill(getEcalDQMSetupObjects(), ttid, 1.0 * ttF);
0243 meTTFlagsVsEt.fill(getEcalDQMSetupObjects(), ttid, et, 1.0 * ttF);
0244
0245
0246 if (ttF >= 4) {
0247 meTTFlags4.fill(getEcalDQMSetupObjects(), ttid);
0248 meTTFlags4ByLumi.fill(getEcalDQMSetupObjects(), ttid);
0249 }
0250 if ((ttF == 1 || ttF == 3) && towerReadouts_[ttid.rawId()] != GetTrigTowerMap()->constituentsOf(ttid).size())
0251 meTTFMismatch.fill(getEcalDQMSetupObjects(), ttid);
0252 }
0253
0254 meOccVsBx.fill(getEcalDQMSetupObjects(), EcalBarrel, bxBinFine_, nTP[0]);
0255 meOccVsBx.fill(getEcalDQMSetupObjects(), -EcalEndcap, bxBinFine_, nTP[1]);
0256 meOccVsBx.fill(getEcalDQMSetupObjects(), EcalEndcap, bxBinFine_, nTP[2]);
0257
0258
0259
0260
0261 MESet& meTTMaskMapAll(MEs_.at("TTMaskMapAll"));
0262
0263
0264 const EcalTPGTowerStatusMap& TTStatusMap(TTStatus->getMap());
0265 for (EcalTPGTowerStatusMap::const_iterator ttItr(TTStatusMap.begin()); ttItr != TTStatusMap.end(); ++ttItr) {
0266 const EcalTrigTowerDetId ttid(ttItr->first);
0267 if (ttItr->second > 0)
0268 meTTMaskMapAll.setBinContent(getEcalDQMSetupObjects(), ttid, 1);
0269 }
0270
0271
0272 const EcalTPGStripStatusMap& StripStatusMap(StripStatus->getMap());
0273 for (EcalTPGStripStatusMap::const_iterator stItr(StripStatusMap.begin()); stItr != StripStatusMap.end(); ++stItr) {
0274 const EcalTriggerElectronicsId stid(stItr->first);
0275
0276
0277 const EcalTrigTowerDetId ttid(GetElectronicsMap()->getTrigTowerDetId(stid.tccId(), stid.ttId()));
0278 if (stItr->second > 0)
0279 meTTMaskMapAll.setBinContent(getEcalDQMSetupObjects(), ttid, 1);
0280 }
0281
0282 }
0283
0284 void TrigPrimTask::runOnEmulTPs(EcalTrigPrimDigiCollection const& _tps) {
0285 MESet& meEtMaxEmul(MEs_.at("EtMaxEmul"));
0286 MESet& meEmulMaxIndex(MEs_.at("EmulMaxIndex"));
0287 MESet& meMatchedIndex(MEs_.at("MatchedIndex"));
0288 MESet& meEtEmulError(MEs_.at("EtEmulError"));
0289 MESet& meFGEmulError(MEs_.at("FGEmulError"));
0290 MESet& meRealvEmulEt(MEs_.at("RealvEmulEt"));
0291
0292 for (EcalTrigPrimDigiCollection::const_iterator tpItr(_tps.begin()); tpItr != _tps.end(); ++tpItr) {
0293 EcalTrigTowerDetId ttid(tpItr->id());
0294
0295 int et(tpItr->compressedEt());
0296
0297 float maxEt(0.);
0298 int iMax(0);
0299 for (int iDigi(0); iDigi < 5; iDigi++) {
0300 float sampleEt((*tpItr)[iDigi].compressedEt());
0301
0302 if (sampleEt > maxEt) {
0303 maxEt = sampleEt;
0304 iMax = iDigi + 1;
0305 }
0306 }
0307
0308 meEtMaxEmul.fill(getEcalDQMSetupObjects(), ttid, maxEt);
0309 if (maxEt > 0.)
0310 meEmulMaxIndex.fill(getEcalDQMSetupObjects(), ttid, iMax);
0311
0312 bool match(true);
0313 bool matchFG(true);
0314
0315
0316
0317
0318 EcalTrigPrimDigiCollection::const_iterator realItr(realTps_->find(ttid));
0319 if (realItr != realTps_->end()) {
0320 int realEt(realItr->compressedEt());
0321
0322 if (realEt > 0) {
0323 int ttF(realItr->ttFlag());
0324 if ((ttF == 1 || ttF == 3) &&
0325 towerReadouts_[ttid.rawId()] == GetTrigTowerMap()->constituentsOf(ttid).size()) {
0326 if (et != realEt)
0327 match = false;
0328 if (tpItr->fineGrain() != realItr->fineGrain())
0329 matchFG = false;
0330
0331
0332
0333 std::vector<int> matchedIndex(0);
0334
0335
0336 for (int iDigi(0); iDigi < 5; iDigi++) {
0337 if ((*tpItr)[iDigi].compressedEt() == realEt) {
0338
0339 if (iDigi != 2) {
0340 matchedIndex.push_back(iDigi + 1);
0341 }
0342
0343
0344 else {
0345 matchedIndex.clear();
0346 matchedIndex.push_back(3);
0347 break;
0348 }
0349 }
0350 }
0351 if (matchedIndex.empty())
0352 matchedIndex.push_back(0);
0353
0354
0355 meRealvEmulEt.fill(
0356 getEcalDQMSetupObjects(), ttid, realEt, (*tpItr)[2].compressedEt());
0357
0358
0359 for (std::vector<int>::iterator matchItr(matchedIndex.begin()); matchItr != matchedIndex.end();
0360 ++matchItr) {
0361 meMatchedIndex.fill(getEcalDQMSetupObjects(), ttid, *matchItr + 0.5);
0362
0363
0364
0365
0366 }
0367 }
0368 }
0369 } else {
0370 match = false;
0371 matchFG = false;
0372 }
0373
0374 if (!match)
0375 meEtEmulError.fill(getEcalDQMSetupObjects(), ttid);
0376 if (!matchFG)
0377 meFGEmulError.fill(getEcalDQMSetupObjects(), ttid);
0378 }
0379 }
0380
0381 DEFINE_ECALDQM_WORKER(TrigPrimTask);
0382 }