File indexing completed on 2024-04-06 12:08:51
0001
0002
0003
0004
0005 #include <sstream>
0006 #include <memory>
0007 #include <list>
0008 #include <algorithm>
0009 #include <cassert>
0010
0011 #include "FWCore/Utilities/interface/EDGetToken.h"
0012 #include "FWCore/Framework/interface/Frameworkfwd.h"
0013 #include "FWCore/Framework/interface/Event.h"
0014 #include "FWCore/Framework/interface/EventSetup.h"
0015 #include "FWCore/Framework/interface/ESWatcher.h"
0016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0017 #include "FWCore/Utilities/interface/InputTag.h"
0018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0019 #include "FWCore/ServiceRegistry/interface/Service.h"
0020 #include "FWCore/Utilities/interface/Exception.h"
0021
0022 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0023 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0024 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0025 #include "DataFormats/SiStripCommon/interface/SiStripFedKey.h"
0026 #include "DataFormats/Common/interface/DetSetVector.h"
0027 #include "DataFormats/SiStripDigi/interface/SiStripRawDigi.h"
0028 #include "DataFormats/SiStripCommon/interface/ConstantsForHardwareSystems.h"
0029
0030 #include "CondFormats/SiStripObjects/interface/SiStripPedestals.h"
0031 #include "CondFormats/DataRecord/interface/SiStripPedestalsRcd.h"
0032 #include "CondFormats/DataRecord/interface/SiStripFedCablingRcd.h"
0033 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
0034
0035 #include "EventFilter/SiStripRawToDigi/interface/SiStripFEDBuffer.h"
0036
0037
0038 #include "DQMServices/Core/interface/DQMStore.h"
0039
0040 #include "DQM/SiStripMonitorHardware/interface/SiStripFEDSpyBuffer.h"
0041 #include "DQM/SiStripMonitorHardware/interface/SiStripSpyUtilities.h"
0042 #include "DQM/SiStripMonitorHardware/interface/SPYHistograms.h"
0043
0044 #include <DQMServices/Core/interface/DQMEDAnalyzer.h>
0045
0046
0047
0048
0049
0050 class SiStripSpyMonitorModule : public DQMEDAnalyzer {
0051 public:
0052 explicit SiStripSpyMonitorModule(const edm::ParameterSet&);
0053 ~SiStripSpyMonitorModule() override;
0054
0055 private:
0056 void analyze(const edm::Event&, const edm::EventSetup&) override;
0057 void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
0058 void dqmBeginRun(const edm::Run&, const edm::EventSetup&) override;
0059
0060
0061 bool hasNegativePedSubtr(const edm::DetSetVector<SiStripRawDigi>::detset& channelDigis, uint16_t aPair);
0062
0063 bool identifyTickmarks(const edm::DetSetVector<SiStripRawDigi>::detset& channelDigis, const uint16_t threshold);
0064
0065 edm::DetSetVector<SiStripRawDigi>::detset::const_iterator findTwoConsecutive(
0066 const edm::DetSetVector<SiStripRawDigi>::detset& channelDigis, const uint16_t threshold, uint16_t& aCounter);
0067
0068
0069 edm::InputTag spyScopeRawDigisTag_;
0070 edm::InputTag spyPedSubtrDigisTag_;
0071
0072 edm::EDGetTokenT<edm::DetSetVector<SiStripRawDigi> > spyScopeRawDigisToken_;
0073 edm::EDGetTokenT<edm::DetSetVector<SiStripRawDigi> > spyPedSubtrDigisToken_;
0074
0075
0076 edm::InputTag spyL1Tag_;
0077 edm::InputTag spyTotCountTag_;
0078 edm::InputTag spyAPVeTag_;
0079
0080 edm::EDGetTokenT<std::vector<uint32_t> > spyL1Token_;
0081 edm::EDGetTokenT<std::vector<uint32_t> > spyTotCountToken_;
0082 edm::EDGetTokenT<std::vector<uint32_t> > spyAPVeToken_;
0083
0084 uint32_t minDigiRange_;
0085 uint32_t maxDigiRange_;
0086 uint32_t minDigitalLow_;
0087 uint32_t maxDigitalLow_;
0088 uint32_t minDigitalHigh_;
0089 uint32_t maxDigitalHigh_;
0090
0091 edm::EventNumber_t evt_;
0092
0093
0094 std::string folderName_;
0095
0096 bool fillAllDetailedHistograms_;
0097
0098 bool fillWithEvtNum_;
0099 bool fillWithLocalEvtNum_;
0100
0101 SPYHistograms histManager_;
0102 uint16_t firstHeaderBit_;
0103 uint16_t firstTrailerBit_;
0104
0105 sistrip::SpyUtilities::FrameQuality frameQuality_;
0106
0107 std::ofstream outfile_[20];
0108 std::vector<std::string> outfileNames_;
0109 std::map<std::string, unsigned int> outfileMap_;
0110
0111 bool writeCabling_;
0112
0113 edm::ESGetToken<TkDetMap, TrackerTopologyRcd> tkDetMapToken_;
0114 edm::ESGetToken<SiStripFedCabling, SiStripFedCablingRcd> fedCablingToken_;
0115 const SiStripFedCabling* fedCabling_;
0116 edm::ESWatcher<SiStripFedCablingRcd> cablingWatcher_;
0117 void updateFedCabling(const SiStripFedCablingRcd& rcd);
0118 };
0119
0120 using edm::LogError;
0121 using edm::LogInfo;
0122 using edm::LogWarning;
0123
0124
0125
0126
0127 SiStripSpyMonitorModule::SiStripSpyMonitorModule(const edm::ParameterSet& iConfig)
0128 : spyScopeRawDigisTag_(iConfig.getUntrackedParameter<edm::InputTag>(
0129 "SpyScopeRawDigisTag", edm::InputTag("SiStripSpyUnpacker", "ScopeRawDigis"))),
0130 spyPedSubtrDigisTag_(
0131 iConfig.getUntrackedParameter<edm::InputTag>("SpyPedSubtrDigisTag", edm::InputTag("SiStripFEDEmulator", ""))),
0132 spyL1Tag_(iConfig.getUntrackedParameter<edm::InputTag>("SpyL1Tag",
0133 edm::InputTag("SiStripSpyDigiConverter", "L1ACount"))),
0134 spyTotCountTag_(iConfig.getUntrackedParameter<edm::InputTag>(
0135 "SpyTotalEventCountTag", edm::InputTag("SiStripSpyDigiConverter", "TotalEventCount"))),
0136 spyAPVeTag_(iConfig.getUntrackedParameter<edm::InputTag>("SpyAPVeTag",
0137 edm::InputTag("SiStripSpyDigiConverter", "APVAddress"))),
0138 folderName_(iConfig.getUntrackedParameter<std::string>("HistogramFolderName",
0139 "SiStrip/ReadoutView/SpyMonitoringSummary")),
0140 fillAllDetailedHistograms_(iConfig.getUntrackedParameter<bool>("FillAllDetailedHistograms", false)),
0141 fillWithEvtNum_(iConfig.getUntrackedParameter<bool>("FillWithEventNumber", false)),
0142 fillWithLocalEvtNum_(iConfig.getUntrackedParameter<bool>("FillWithLocalEventNumber", false)),
0143 firstHeaderBit_(0),
0144 firstTrailerBit_(0),
0145 outfileNames_(iConfig.getUntrackedParameter<std::vector<std::string> >("OutputErrors")),
0146 writeCabling_(iConfig.getUntrackedParameter<bool>("WriteCabling", false)),
0147 tkDetMapToken_(esConsumes<edm::Transition::BeginRun>()),
0148 fedCablingToken_(esConsumes<>()),
0149 cablingWatcher_(this, &SiStripSpyMonitorModule::updateFedCabling) {
0150 spyScopeRawDigisToken_ = consumes<edm::DetSetVector<SiStripRawDigi> >(spyScopeRawDigisTag_);
0151 spyPedSubtrDigisToken_ = consumes<edm::DetSetVector<SiStripRawDigi> >(spyPedSubtrDigisTag_);
0152
0153 spyL1Token_ = consumes<std::vector<uint32_t> >(spyL1Tag_);
0154 spyTotCountToken_ = consumes<std::vector<uint32_t> >(spyTotCountTag_);
0155 spyAPVeToken_ = consumes<std::vector<uint32_t> >(spyAPVeTag_);
0156
0157 evt_ = 0;
0158 std::ostringstream pDebugStream;
0159 histManager_.initialise(iConfig, &pDebugStream);
0160 const unsigned int nFiles = outfileNames_.size();
0161
0162 for (unsigned int i(0); i < nFiles; i++) {
0163 std::ostringstream lName;
0164 lName << outfileNames_.at(i) << ".out";
0165 if (i < 20)
0166 outfile_[i].open(lName.str().c_str(), std::ios::out);
0167 outfileMap_[outfileNames_.at(i)] = i;
0168 }
0169
0170 frameQuality_.minDigiRange = static_cast<uint16_t>(iConfig.getUntrackedParameter<uint32_t>("MinDigiRange", 100));
0171 frameQuality_.maxDigiRange = static_cast<uint16_t>(iConfig.getUntrackedParameter<uint32_t>("MaxDigiRange", 1024));
0172 frameQuality_.minZeroLight = static_cast<uint16_t>(iConfig.getUntrackedParameter<uint32_t>("MinZeroLight", 0));
0173 frameQuality_.maxZeroLight = static_cast<uint16_t>(iConfig.getUntrackedParameter<uint32_t>("MaxZeroLight", 1024));
0174 frameQuality_.minTickHeight = static_cast<uint16_t>(iConfig.getUntrackedParameter<uint32_t>("MinTickHeight", 0));
0175 frameQuality_.maxTickHeight = static_cast<uint16_t>(iConfig.getUntrackedParameter<uint32_t>("MaxTickHeight", 1024));
0176 }
0177
0178 SiStripSpyMonitorModule::~SiStripSpyMonitorModule() {
0179 const unsigned int nFiles = outfileNames_.size();
0180 for (unsigned int i(0); i < nFiles; i++) {
0181 outfile_[i].close();
0182 }
0183
0184 outfileMap_.clear();
0185 outfileNames_.clear();
0186 }
0187
0188 void SiStripSpyMonitorModule::updateFedCabling(const SiStripFedCablingRcd& rcd) {
0189 fedCabling_ = &rcd.get(fedCablingToken_);
0190 }
0191
0192 void SiStripSpyMonitorModule::dqmBeginRun(const edm::Run& r, const edm::EventSetup& c) {
0193 evt_ = 0;
0194 firstHeaderBit_ = 0;
0195 firstTrailerBit_ = 0;
0196 }
0197
0198 void SiStripSpyMonitorModule::bookHistograms(DQMStore::IBooker& ibooker,
0199 const edm::Run& run,
0200 const edm::EventSetup& eSetup) {
0201 ibooker.setCurrentFolder(folderName_);
0202
0203 LogInfo("SiStripSpyMonitorModule") << " Histograms will be written in " << folderName_
0204 << ". Current folder is : " << ibooker.pwd() << std::endl;
0205
0206 const auto tkDetMap = &eSetup.getData(tkDetMapToken_);
0207
0208 histManager_.bookTopLevelHistograms(ibooker, tkDetMap);
0209
0210 if (fillAllDetailedHistograms_)
0211 histManager_.bookAllFEDHistograms(ibooker);
0212
0213
0214 SPYHistograms::Errors lError = {};
0215 for (uint16_t lFedId = sistrip::FED_ID_MIN; lFedId <= sistrip::FED_ID_MAX; ++lFedId)
0216 histManager_.bookFEDHistograms(ibooker, lFedId, lError, true);
0217 }
0218
0219
0220 void SiStripSpyMonitorModule::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0221
0222 cablingWatcher_.check(iSetup);
0223 if (evt_ == 0 && writeCabling_) {
0224 std::ofstream lOutCabling;
0225 lOutCabling.open("trackerDetId_FEDIdChNum_list.txt", std::ios::out);
0226 for (uint16_t lFedId = sistrip::FED_ID_MIN; lFedId <= sistrip::FED_ID_MAX; ++lFedId) {
0227 for (uint16_t lFedChannel = 0; lFedChannel < sistrip::FEDCH_PER_FED; lFedChannel++) {
0228 const FedChannelConnection& lConnection = fedCabling_->fedConnection(lFedId, lFedChannel);
0229 if (!lConnection.isConnected())
0230 continue;
0231 uint32_t lDetId = lConnection.detId();
0232 lOutCabling << "FED ID = " << lFedId << ", Channel = " << lFedChannel
0233 << ",fedkey = " << sistrip::FEDCH_PER_FED * lFedId + lFedChannel << ", detId = " << lDetId
0234 << std::endl;
0235 }
0236 }
0237 lOutCabling.close();
0238 }
0239
0240
0241
0242 edm::Handle<std::vector<uint32_t> > lSpyL1IDHandle, lSpyTotCountHandle, lSpyAPVeHandle;
0243 try {
0244 iEvent.getByToken(spyL1Token_, lSpyL1IDHandle);
0245 iEvent.getByToken(spyTotCountToken_, lSpyTotCountHandle);
0246 iEvent.getByToken(spyAPVeToken_, lSpyAPVeHandle);
0247 } catch (const cms::Exception& e) {
0248 LogError("SiStripSpyMonitorModule") << e.what();
0249 return;
0250 }
0251
0252
0253 const std::vector<uint32_t>& lSpyAPVeVec = *lSpyAPVeHandle;
0254
0255
0256 edm::Handle<edm::DetSetVector<SiStripRawDigi> > digisHandle;
0257 try {
0258 iEvent.getByToken(spyScopeRawDigisToken_, digisHandle);
0259 } catch (const cms::Exception& e) {
0260 LogError("SiStripSpyMonitorModule") << e.what();
0261 return;
0262 }
0263 const edm::DetSetVector<SiStripRawDigi>* lInputDigis = digisHandle.product();
0264
0265
0266 edm::Handle<edm::DetSetVector<SiStripRawDigi> > payloadHandle;
0267 try {
0268 iEvent.getByToken(spyPedSubtrDigisToken_, payloadHandle);
0269 } catch (const cms::Exception& e) {
0270 LogError("SiStripSpyMonitorModule") << e.what();
0271 return;
0272 }
0273 const edm::DetSetVector<SiStripRawDigi>* lPayloadDigis = payloadHandle.product();
0274
0275
0276
0277
0278
0279
0280
0281 if (evt_ == 0) {
0282 sistrip::SpyUtilities::getMajorityHeader(lInputDigis, firstHeaderBit_);
0283 firstTrailerBit_ = firstHeaderBit_ + 24 + sistrip::STRIPS_PER_FEDCH;
0284 }
0285
0286
0287 SPYHistograms::ErrorCounters lCounters;
0288 lCounters.nNoData = 0;
0289 lCounters.nLowRange = 0;
0290 lCounters.nHighRange = 0;
0291 lCounters.nMinZero = 0;
0292 lCounters.nMaxSat = 0;
0293 lCounters.nLowPb = 0;
0294 lCounters.nHighPb = 0;
0295 lCounters.nOOS = 0;
0296 lCounters.nOtherPbs = 0;
0297 lCounters.nAPVError = 0;
0298 lCounters.nAPVAddressError = 0;
0299 lCounters.nNegPeds = 0;
0300
0301
0302 const unsigned int nFiles = outfileNames_.size();
0303 for (unsigned int i(0); i < nFiles; i++) {
0304 outfile_[i] << "**** evt " << iEvent.id().event() << " ****" << std::endl;
0305 }
0306
0307
0308
0309 for (uint16_t lFedId = sistrip::FED_ID_MIN; lFedId <= sistrip::FED_ID_MAX; ++lFedId) {
0310
0311 SPYHistograms::Errors lFEDErrors;
0312 lFEDErrors.hasNoData = false;
0313 lFEDErrors.hasLowRange = false;
0314 lFEDErrors.hasHighRange = false;
0315 lFEDErrors.hasMinZero = false;
0316 lFEDErrors.hasMaxSat = false;
0317 lFEDErrors.hasLowPb = false;
0318 lFEDErrors.hasHighPb = false;
0319 lFEDErrors.hasOOS = false;
0320 lFEDErrors.hasOtherPbs = false;
0321 lFEDErrors.hasErrorBit0 = false;
0322 lFEDErrors.hasErrorBit1 = false;
0323 lFEDErrors.hasAPVAddressError0 = false;
0324 lFEDErrors.hasAPVAddressError1 = false;
0325 lFEDErrors.hasNegPeds = false;
0326
0327 uint32_t lAPVAddrRef = lSpyAPVeVec.at(lFedId);
0328
0329 for (uint16_t lFedChannel = 0; lFedChannel < sistrip::FEDCH_PER_FED; lFedChannel++) {
0330
0331 uint32_t lFedIndex = sistrip::FEDCH_PER_FED * lFedId + lFedChannel;
0332
0333 const FedChannelConnection& lConnection = fedCabling_->fedConnection(lFedId, lFedChannel);
0334
0335 if (!lConnection.isConnected())
0336 continue;
0337
0338 uint32_t lDetId = lConnection.detId();
0339
0340 uint16_t lPair = lConnection.apvPairNumber();
0341
0342 edm::DetSetVector<SiStripRawDigi>::const_iterator lDigis = lInputDigis->find(lFedIndex);
0343
0344
0345 edm::DetSetVector<SiStripRawDigi>::const_iterator lPayload = lPayloadDigis->find(lDetId);
0346
0347
0348 if (lDigis == lInputDigis->end()) {
0349 LogDebug("SiStripSpyMonitorModule") << " -- digis not found in ScopeRawDigis map for FEDID " << lFedId
0350 << " and FED channel " << lFedChannel << std::endl;
0351 continue;
0352 }
0353
0354 sistrip::SpyUtilities::Frame lFrame = sistrip::SpyUtilities::extractFrameInfo(*lDigis);
0355
0356 SPYHistograms::Errors lErrors;
0357 lErrors.hasNoData = false;
0358 lErrors.hasLowRange = false;
0359 lErrors.hasHighRange = false;
0360 lErrors.hasMinZero = false;
0361 lErrors.hasMaxSat = false;
0362 lErrors.hasLowPb = false;
0363 lErrors.hasHighPb = false;
0364 lErrors.hasOOS = false;
0365 lErrors.hasOtherPbs = false;
0366 lErrors.hasErrorBit0 = false;
0367 lErrors.hasErrorBit1 = false;
0368 lErrors.hasAPVAddressError0 = false;
0369 lErrors.hasAPVAddressError1 = false;
0370 lErrors.hasNegPeds = false;
0371
0372 uint16_t lRange = sistrip::SpyUtilities::range(lFrame);
0373 uint16_t lThreshold = sistrip::SpyUtilities::threshold(lFrame);
0374
0375 if (lRange == 0) {
0376 lCounters.nNoData++;
0377 lErrors.hasNoData = true;
0378 lFEDErrors.hasNoData = true;
0379 if (outfileMap_.find("NoData") != outfileMap_.end())
0380 outfile_[outfileMap_["NoData"]] << lFedId << " " << lFedChannel << " " << lDetId << std::endl;
0381 } else if (lFrame.digitalLow == 0 && lRange > 0) {
0382 lCounters.nMinZero++;
0383 lErrors.hasMinZero = true;
0384 lFEDErrors.hasMinZero = true;
0385 if (outfileMap_.find("MinZero") != outfileMap_.end())
0386 outfile_[outfileMap_["MinZero"]] << lFedId << " " << lFedChannel << " " << lDetId << std::endl;
0387 } else if (lFrame.digitalHigh >= 1023) {
0388 lCounters.nMaxSat++;
0389 lErrors.hasMaxSat = true;
0390 lFEDErrors.hasMaxSat = true;
0391 if (outfileMap_.find("MaxSat") != outfileMap_.end())
0392 outfile_[outfileMap_["MaxSat"]] << lFedId << " " << lFedChannel << " " << lDetId << std::endl;
0393 } else if (lRange > 0 && lRange < frameQuality_.minDigiRange) {
0394 lCounters.nLowRange++;
0395 lErrors.hasLowRange = true;
0396 lFEDErrors.hasLowRange = true;
0397 if (outfileMap_.find("LowRange") != outfileMap_.end())
0398 outfile_[outfileMap_["LowRange"]] << lFedId << " " << lFedChannel << " " << lDetId << std::endl;
0399 } else if (lRange > frameQuality_.maxDigiRange) {
0400 lCounters.nHighRange++;
0401 lErrors.hasHighRange = true;
0402 lFEDErrors.hasHighRange = true;
0403 if (outfileMap_.find("HighRange") != outfileMap_.end())
0404 outfile_[outfileMap_["HighRange"]] << lFedId << " " << lFedChannel << " " << lDetId << std::endl;
0405 } else if (lFrame.digitalLow < frameQuality_.minZeroLight || lFrame.digitalLow > frameQuality_.maxZeroLight) {
0406 lCounters.nLowPb++;
0407 lErrors.hasLowPb = true;
0408 lFEDErrors.hasLowPb = true;
0409 if (outfileMap_.find("LowPb") != outfileMap_.end())
0410 outfile_[outfileMap_["LowPb"]] << lFedId << " " << lFedChannel << " " << lDetId << std::endl;
0411 } else if (lFrame.digitalHigh < frameQuality_.minTickHeight || lFrame.digitalHigh > frameQuality_.maxTickHeight) {
0412 lCounters.nHighPb++;
0413 lErrors.hasHighPb = true;
0414 lFEDErrors.hasHighPb = true;
0415 if (outfileMap_.find("HighPb") != outfileMap_.end())
0416 outfile_[outfileMap_["HighPb"]] << lFedId << " " << lFedChannel << " " << lDetId << std::endl;
0417 } else if (lFrame.firstHeaderBit != firstHeaderBit_ &&
0418 ((lFrame.firstHeaderBit != sistrip::SPY_SAMPLES_PER_CHANNEL &&
0419 lFrame.firstTrailerBit != sistrip::SPY_SAMPLES_PER_CHANNEL &&
0420 lFrame.firstTrailerBit - lFrame.firstHeaderBit == 280) ||
0421 (lFrame.firstHeaderBit != sistrip::SPY_SAMPLES_PER_CHANNEL &&
0422 lFrame.firstTrailerBit == sistrip::SPY_SAMPLES_PER_CHANNEL &&
0423 lFrame.firstHeaderBit > 16) ||
0424 (lFrame.firstHeaderBit == sistrip::SPY_SAMPLES_PER_CHANNEL &&
0425 identifyTickmarks(*lDigis, lThreshold))
0426 )) {
0427 lCounters.nOOS++;
0428 lErrors.hasOOS = true;
0429 lFEDErrors.hasOOS = true;
0430 if (outfileMap_.find("OOS") != outfileMap_.end())
0431 outfile_[outfileMap_["OOS"]] << lFedId << " " << lFedChannel << " " << lDetId << std::endl;
0432 } else if (!(lFrame.firstHeaderBit == firstHeaderBit_ && lFrame.firstTrailerBit == firstTrailerBit_)) {
0433 lCounters.nOtherPbs++;
0434 lErrors.hasOtherPbs = true;
0435 lFEDErrors.hasOtherPbs = true;
0436 if (outfileMap_.find("OtherPbs") != outfileMap_.end())
0437 outfile_[outfileMap_["OtherPbs"]] << lFedId << " " << lFedChannel << " " << lDetId << std::endl;
0438 } else if (lFrame.apvErrorBit.first || lFrame.apvErrorBit.second) {
0439 if (lFrame.apvErrorBit.first) {
0440 lCounters.nAPVError++;
0441 lErrors.hasErrorBit0 = true;
0442 lFEDErrors.hasErrorBit0 = true;
0443 }
0444 if (lFrame.apvErrorBit.second) {
0445 lCounters.nAPVError++;
0446 lErrors.hasErrorBit1 = true;
0447 lFEDErrors.hasErrorBit1 = true;
0448 }
0449 if (outfileMap_.find("APVError") != outfileMap_.end()) {
0450 outfile_[outfileMap_["APVError"]] << lFedId << " " << lFedChannel << " " << lDetId;
0451 if (lFrame.apvErrorBit.first)
0452 outfile_[outfileMap_["APVError"]] << " APV0" << std::endl;
0453 if (lFrame.apvErrorBit.second)
0454 outfile_[outfileMap_["APVError"]] << " APV1" << std::endl;
0455 }
0456 } else if (lFrame.apvAddress.first != lAPVAddrRef || lFrame.apvAddress.second != lAPVAddrRef) {
0457 if (lFrame.apvAddress.first != lAPVAddrRef) {
0458 lCounters.nAPVAddressError++;
0459 lErrors.hasAPVAddressError0 = true;
0460 lFEDErrors.hasAPVAddressError0 = true;
0461 }
0462 if (lFrame.apvAddress.second != lAPVAddrRef) {
0463 lCounters.nAPVAddressError++;
0464 lErrors.hasAPVAddressError1 = true;
0465 lFEDErrors.hasAPVAddressError1 = true;
0466 }
0467 if (outfileMap_.find("APVAddressError") != outfileMap_.end()) {
0468 outfile_[outfileMap_["APVAddressError"]] << lFedId << " " << lFedChannel << " " << lDetId << std::endl;
0469 if (lFrame.apvAddress.first != lAPVAddrRef)
0470 outfile_[outfileMap_["APVAddressError"]] << " APV0" << std::endl;
0471 if (lFrame.apvAddress.second != lAPVAddrRef)
0472 outfile_[outfileMap_["APVAddressError"]] << " APV1" << std::endl;
0473 }
0474 } else if (lPayload != lPayloadDigis->end() && hasNegativePedSubtr(*lPayload, lPair)) {
0475 lCounters.nNegPeds++;
0476 lErrors.hasNegPeds = true;
0477 lFEDErrors.hasNegPeds = true;
0478 if (outfileMap_.find("NegPeds") != outfileMap_.end())
0479 outfile_[outfileMap_["NegPeds"]] << lFedId << " " << lFedChannel << " " << lDetId << std::endl;
0480 }
0481
0482 histManager_.fillDetailedHistograms(lErrors, lFrame, lFedId, lFedChannel);
0483
0484 }
0485
0486 histManager_.fillFEDHistograms(lFEDErrors, lFedId);
0487
0488 }
0489
0490 double lTime;
0491
0492
0493
0494
0495
0496 if (fillWithLocalEvtNum_) {
0497
0498
0499 lTime = static_cast<double>(evt_);
0500 } else {
0501
0502
0503 lTime = static_cast<double>(iEvent.id().event());
0504 }
0505
0506 histManager_.fillCountersHistograms(lCounters, lTime);
0507
0508
0509 evt_++;
0510
0511 }
0512
0513 bool SiStripSpyMonitorModule::hasNegativePedSubtr(const edm::DetSetVector<SiStripRawDigi>::detset& channelDigis,
0514 uint16_t aPair) {
0515 edm::DetSetVector<SiStripRawDigi>::detset::const_iterator iDigi = channelDigis.begin();
0516 const edm::DetSetVector<SiStripRawDigi>::detset::const_iterator endChannelDigis = channelDigis.end();
0517
0518 uint32_t count = 0;
0519 for (; iDigi != endChannelDigis; ++iDigi) {
0520 const uint16_t val = iDigi->adc();
0521 uint16_t lPair = static_cast<uint16_t>(count / sistrip::STRIPS_PER_FEDCH);
0522 if (val == 0 && lPair == aPair)
0523 return true;
0524 count++;
0525 }
0526
0527 return false;
0528 }
0529
0530 bool SiStripSpyMonitorModule::identifyTickmarks(const edm::DetSetVector<SiStripRawDigi>::detset& channelDigis,
0531 const uint16_t threshold) {
0532
0533 uint16_t count = sistrip::SPY_SAMPLES_PER_CHANNEL - 3;
0534 uint16_t lastPos = sistrip::SPY_SAMPLES_PER_CHANNEL;
0535 uint16_t nTrailers = 0;
0536 edm::DetSetVector<SiStripRawDigi>::detset::const_iterator iDigi = channelDigis.end();
0537
0538 for (; count == 0; count--) {
0539 iDigi = findTwoConsecutive(channelDigis, threshold, count);
0540
0541 if (iDigi != channelDigis.end() && (lastPos == sistrip::SPY_SAMPLES_PER_CHANNEL || count == lastPos + 1 - 70)) {
0542 nTrailers++;
0543 lastPos = count - 1;
0544 count -= 70;
0545 }
0546
0547 else
0548 count--;
0549 }
0550
0551 if (nTrailers > 1)
0552 LogDebug("SiStripSpyMonitorModule") << " -- Found " << nTrailers << " trailers every 70 clock cycles for channel "
0553 << channelDigis.detId() << ", evt " << evt_ << std::endl;
0554
0555 return (nTrailers > 1) || (nTrailers == 1 && lastPos < 280);
0556 }
0557
0558 edm::DetSetVector<SiStripRawDigi>::detset::const_iterator SiStripSpyMonitorModule::findTwoConsecutive(
0559 const edm::DetSetVector<SiStripRawDigi>::detset& channelDigis, const uint16_t threshold, uint16_t& aCounter) {
0560 const edm::DetSetVector<SiStripRawDigi>::detset::const_iterator endChannelDigis = channelDigis.end();
0561 edm::DetSetVector<SiStripRawDigi>::detset::const_iterator lStart = channelDigis.begin() + aCounter;
0562
0563 bool foundTrailer = false;
0564
0565 uint8_t aboveThreshold = 0;
0566
0567 for (; lStart != endChannelDigis; ++lStart) {
0568 if (lStart->adc() > threshold) {
0569 aboveThreshold++;
0570 } else {
0571 aboveThreshold = 0;
0572 }
0573 if (aboveThreshold == 2) {
0574 foundTrailer = true;
0575 break;
0576 }
0577 aCounter++;
0578 }
0579
0580 if (foundTrailer)
0581 return lStart;
0582 else {
0583 aCounter = sistrip::SPY_SAMPLES_PER_CHANNEL;
0584 return endChannelDigis;
0585 }
0586 }
0587
0588
0589
0590
0591
0592 #include "FWCore/Framework/interface/MakerMacros.h"
0593 DEFINE_FWK_MODULE(SiStripSpyMonitorModule);