File indexing completed on 2024-09-07 04:35:37
0001 #include <stdexcept>
0002 #include <string>
0003 #include <fstream>
0004 #include <vector>
0005 #include <bitset>
0006
0007 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "FWCore/Framework/interface/MakerMacros.h"
0010
0011 #include "FWCore/Framework/interface/EventSetup.h"
0012 #include "FWCore/Utilities/interface/ESGetToken.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0015
0016 #include "CondFormats/CSCObjects/interface/CSCBadStrips.h"
0017 #include "CondFormats/DataRecord/interface/CSCBadStripsRcd.h"
0018 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
0019 #include "DataFormats/MuonDetId/interface/CSCIndexer.h"
0020
0021 namespace edmtest {
0022 class CSCReadBadStripsAnalyzer : public edm::one::EDAnalyzer<> {
0023 public:
0024 explicit CSCReadBadStripsAnalyzer(edm::ParameterSet const& ps)
0025 : outputToFile(ps.getParameter<bool>("outputToFile")),
0026 readBadChannels_(ps.getParameter<bool>("readBadChannels")),
0027 badStripsToken_{esConsumes()} {
0028 badStripWords.resize(3240, 0);
0029 }
0030
0031 ~CSCReadBadStripsAnalyzer() override {}
0032 void analyze(const edm::Event& e, const edm::EventSetup& c) override;
0033
0034
0035
0036
0037 bool readBadChannels() const { return readBadChannels_; }
0038
0039 void fillBadStripWords(edm::LogSystem&);
0040
0041
0042 const std::bitset<80>& badStripWord(const CSCDetId& id) const;
0043
0044 private:
0045 bool outputToFile;
0046 bool readBadChannels_;
0047 const edm::ESGetToken<CSCBadStrips, CSCBadStripsRcd> badStripsToken_;
0048 const CSCBadStrips* theBadStrips;
0049
0050 std::vector<std::bitset<80> > badStripWords;
0051 };
0052
0053 void CSCReadBadStripsAnalyzer::analyze(const edm::Event& e, const edm::EventSetup& context) {
0054 using namespace edm::eventsetup;
0055 edm::LogSystem log("CSCBadStrips");
0056
0057 int counter = 0;
0058 log << " RUN# " << e.id().run() << std::endl;
0059 log << " EVENT# " << e.id().event() << std::endl;
0060
0061 theBadStrips = &context.getData(badStripsToken_);
0062
0063
0064 fillBadStripWords(log);
0065
0066 CSCIndexer indexer;
0067
0068 std::vector<CSCBadStrips::BadChamber>::const_iterator itcham;
0069 std::vector<CSCBadStrips::BadChannel>::const_iterator itchan;
0070
0071 log << "Bad Chambers:" << std::endl;
0072
0073 int ibad = 0;
0074 int ifailed = 0;
0075
0076
0077
0078 for (itcham = theBadStrips->chambers.begin(); itcham != theBadStrips->chambers.end(); ++itcham) {
0079 counter++;
0080 int indexc = itcham->chamber_index;
0081 int badstart = itcham->pointer;
0082 int nbad = itcham->bad_channels;
0083 log << counter << " " << itcham->chamber_index << " " << itcham->pointer << " " << itcham->bad_channels
0084 << std::endl;
0085 CSCDetId id = indexer.detIdFromChamberIndex(indexc);
0086
0087
0088
0089 for (int ichan = badstart - 1; ichan != badstart - 1 + nbad; ++ichan) {
0090 short lay = theBadStrips->channels[ichan].layer;
0091 short chan = theBadStrips->channels[ichan].channel;
0092
0093
0094 CSCDetId id2 = CSCDetId(id.endcap(), id.station(), id.ring(), id.chamber(), lay);
0095 std::bitset<80> ibits = badStripWord(id2);
0096
0097
0098 if (ibits.test(chan - 1)) {
0099 log << "count " << ++ibad << " found bad channel " << chan << " in layer " << id2 << std::endl;
0100 } else {
0101 log << "count " << +ifailed << " failed to see bad channel " << chan << " in layer " << id2 << std::endl;
0102 }
0103 }
0104 }
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116 if (outputToFile) {
0117 std::ofstream BadStripFile("dbBadStrip.dat", std::ios::app);
0118
0119 counter = 0;
0120 for (itcham = theBadStrips->chambers.begin(); itcham != theBadStrips->chambers.end(); ++itcham) {
0121 counter++;
0122 BadStripFile << counter << " " << itcham->chamber_index << " " << itcham->pointer << " "
0123 << itcham->bad_channels << std::endl;
0124 }
0125 counter = 0;
0126 for (itchan = theBadStrips->channels.begin(); itchan != theBadStrips->channels.end(); ++itchan) {
0127 counter++;
0128 BadStripFile << counter << " " << itchan->layer << " " << itchan->channel << " " << itchan->flag1
0129 << std::endl;
0130 }
0131 }
0132 }
0133
0134 void CSCReadBadStripsAnalyzer::fillBadStripWords(edm::LogSystem& log) {
0135
0136 badStripWords.assign(3240, 0);
0137 if (readBadChannels()) {
0138
0139
0140
0141
0142
0143
0144
0145 CSCIndexer indexer;
0146
0147 int icount = 0;
0148
0149 for (size_t i = 0; i < theBadStrips->chambers.size(); ++i) {
0150 int indexc = theBadStrips->chambers[i].chamber_index;
0151
0152
0153 if (indexc == 0) {
0154 log << "WARNING: chamber index = 0. Quitting. " << std::endl;
0155 break;
0156 }
0157
0158 int start = theBadStrips->chambers[i].pointer;
0159 int nbad = theBadStrips->chambers[i].bad_channels;
0160
0161 CSCDetId id = indexer.detIdFromChamberIndex(indexc);
0162
0163 for (int j = start - 1; j < start + nbad - 1; ++j) {
0164 short lay = theBadStrips->channels[j].layer;
0165
0166
0167 if (lay == 0) {
0168 log << "WARNING: layer index = 0. Quitting. " << std::endl;
0169 break;
0170 }
0171
0172 short chan = theBadStrips->channels[j].channel;
0173
0174
0175
0176 int indexl = indexer.layerIndex(id.endcap(), id.station(), id.ring(), id.chamber(), lay);
0177
0178
0179 log << "count " << ++icount << " bad channel " << chan << " in layer " << lay << " of chamber=" << id
0180 << " chamber index=" << indexc << " layer index=" << indexl << std::endl;
0181
0182 badStripWords[indexl - 1].set(chan - 1, 1);
0183 }
0184 }
0185 }
0186 }
0187
0188 const std::bitset<80>& CSCReadBadStripsAnalyzer::badStripWord(const CSCDetId& id) const {
0189 CSCIndexer indexer;
0190 return badStripWords[indexer.layerIndex(id) - 1];
0191 }
0192
0193 DEFINE_FWK_MODULE(CSCReadBadStripsAnalyzer);
0194 }