File indexing completed on 2021-05-20 22:34:16
0001
0002
0003
0004
0005
0006
0007
0008 #include "DQMOffline/CalibMuon/interface/DTnoiseDBValidation.h"
0009
0010
0011 #include "FWCore/Framework/interface/ESHandle.h"
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/Framework/interface/EventSetup.h"
0014 #include "FWCore/ServiceRegistry/interface/Service.h"
0015
0016 #include "DQMServices/Core/interface/DQMStore.h"
0017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0018
0019
0020 #include "DataFormats/MuonDetId/interface/DTLayerId.h"
0021 #include "DataFormats/MuonDetId/interface/DTWireId.h"
0022 #include "Geometry/DTGeometry/interface/DTGeometry.h"
0023 #include "Geometry/DTGeometry/interface/DTTopology.h"
0024
0025
0026 #include "CondFormats/DTObjects/interface/DTStatusFlag.h"
0027
0028 #include "TFile.h"
0029 #include "TH1F.h"
0030 #include <cmath>
0031 #include <cstdio>
0032 #include <sstream>
0033
0034 using namespace edm;
0035 using namespace std;
0036
0037 DTnoiseDBValidation::DTnoiseDBValidation(const ParameterSet &pset)
0038 : labelDBRef_(esConsumes(edm::ESInputTag("", pset.getParameter<string>("labelDBRef")))),
0039 labelDB_(esConsumes(edm::ESInputTag("", pset.getParameter<string>("labelDB")))),
0040 muonGeomToken_(esConsumes<edm::Transition::BeginRun>()) {
0041 LogVerbatim("NoiseDBValidation") << "[DTnoiseDBValidation] Constructor called!";
0042
0043
0044 dbe_ = edm::Service<DQMStore>().operator->();
0045 dbe_->setCurrentFolder("DT/DtCalib/NoiseDBValidation");
0046
0047 diffTestName_ = "noiseDifferenceInRange";
0048 if (pset.exists("diffTestName"))
0049 diffTestName_ = pset.getParameter<string>("diffTestName");
0050
0051 wheelTestName_ = "noiseWheelOccInRange";
0052 if (pset.exists("wheelTestName"))
0053 wheelTestName_ = pset.getParameter<string>("wheelTestName");
0054
0055 stationTestName_ = "noiseStationOccInRange";
0056 if (pset.exists("stationTestName"))
0057 stationTestName_ = pset.getParameter<string>("stationTestName");
0058
0059 sectorTestName_ = "noiseSectorOccInRange";
0060 if (pset.exists("sectorTestName"))
0061 sectorTestName_ = pset.getParameter<string>("sectorTestName");
0062
0063 layerTestName_ = "noiseLayerOccInRange";
0064 if (pset.exists("layerTestName"))
0065 layerTestName_ = pset.getParameter<string>("layerTestName");
0066
0067 outputMEsInRootFile_ = false;
0068 if (pset.exists("OutputFileName")) {
0069 outputMEsInRootFile_ = true;
0070 outputFileName_ = pset.getParameter<std::string>("OutputFileName");
0071 }
0072 }
0073
0074 DTnoiseDBValidation::~DTnoiseDBValidation() {}
0075
0076 void DTnoiseDBValidation::beginRun(const edm::Run &run, const EventSetup &setup) {
0077 noiseRefMap_ = &setup.getData(labelDBRef_);
0078
0079 noiseMap_ = &setup.getData(labelDB_);
0080 ;
0081
0082
0083 dtGeom = &setup.getData(muonGeomToken_);
0084
0085 LogVerbatim("NoiseDBValidation") << "[DTnoiseDBValidation] Parameters initialization";
0086
0087 noisyCellsRef_ = 0;
0088 noisyCellsValid_ = 0;
0089
0090
0091 diffHisto_ =
0092 dbe_->book1D("noisyCellDiff", "percentual (wrt the previous db) total number of noisy cells", 1, 0.5, 1.5);
0093 diffHisto_->setBinLabel(1, "Diff");
0094 wheelHisto_ = dbe_->book1D("wheelOccupancy", "percentual noisy cells occupancy per wheel", 5, -2.5, 2.5);
0095 wheelHisto_->setBinLabel(1, "Wh-2");
0096 wheelHisto_->setBinLabel(2, "Wh-1");
0097 wheelHisto_->setBinLabel(3, "Wh0");
0098 wheelHisto_->setBinLabel(4, "Wh1");
0099 wheelHisto_->setBinLabel(5, "Wh2");
0100 stationHisto_ = dbe_->book1D("stationOccupancy", "percentual noisy cells occupancy per station", 4, 0.5, 4.5);
0101 stationHisto_->setBinLabel(1, "St1");
0102 stationHisto_->setBinLabel(2, "St2");
0103 stationHisto_->setBinLabel(3, "St3");
0104 stationHisto_->setBinLabel(4, "St4");
0105 sectorHisto_ = dbe_->book1D("sectorOccupancy", "percentual noisy cells occupancy per sector", 12, 0.5, 12.5);
0106 sectorHisto_->setBinLabel(1, "Sect1");
0107 sectorHisto_->setBinLabel(2, "Sect2");
0108 sectorHisto_->setBinLabel(3, "Sect3");
0109 sectorHisto_->setBinLabel(4, "Sect4");
0110 sectorHisto_->setBinLabel(5, "Sect5");
0111 sectorHisto_->setBinLabel(6, "Sect6");
0112 sectorHisto_->setBinLabel(7, "Sect7");
0113 sectorHisto_->setBinLabel(8, "Sect8");
0114 sectorHisto_->setBinLabel(9, "Sect9");
0115 sectorHisto_->setBinLabel(10, "Sect10");
0116 sectorHisto_->setBinLabel(11, "Sect11");
0117 sectorHisto_->setBinLabel(12, "Sect12");
0118 layerHisto_ = dbe_->book1D("layerOccupancy", "percentual noisy cells occupancy per layer", 3, 0.5, 3.5);
0119 layerHisto_->setBinLabel(1, "First 10 bins");
0120 layerHisto_->setBinLabel(2, "Middle bins");
0121 layerHisto_->setBinLabel(3, "Last 10 bins");
0122
0123
0124 map<int, int> whMap;
0125 whMap.clear();
0126 map<int, int> stMap;
0127 stMap.clear();
0128 map<int, int> sectMap;
0129 sectMap.clear();
0130 map<int, int> layerMap;
0131 layerMap.clear();
0132
0133
0134 for (DTStatusFlag::const_iterator noise = noiseRefMap_->begin(); noise != noiseRefMap_->end(); noise++) {
0135 DTWireId wireId((*noise).first.wheelId,
0136 (*noise).first.stationId,
0137 (*noise).first.sectorId,
0138 (*noise).first.slId,
0139 (*noise).first.layerId,
0140 (*noise).first.cellId);
0141 LogVerbatim("NoiseDBValidation") << "Ref. noisy wire: " << wireId;
0142 ++noisyCellsRef_;
0143 }
0144
0145
0146 for (DTStatusFlag::const_iterator noise = noiseMap_->begin(); noise != noiseMap_->end(); noise++) {
0147 DTWireId wireId((*noise).first.wheelId,
0148 (*noise).first.stationId,
0149 (*noise).first.sectorId,
0150 (*noise).first.slId,
0151 (*noise).first.layerId,
0152 (*noise).first.cellId);
0153 LogVerbatim("NoiseDBValidation") << "Valid. noisy wire: " << wireId;
0154 ++noisyCellsValid_;
0155
0156 whMap[(*noise).first.wheelId]++;
0157 stMap[(*noise).first.stationId]++;
0158 sectMap[(*noise).first.sectorId]++;
0159
0160 const DTTopology &dtTopo = dtGeom->layer(wireId.layerId())->specificTopology();
0161 const int lastWire = dtTopo.lastChannel();
0162 if ((*noise).first.cellId <= 10)
0163 layerMap[1]++;
0164 if ((*noise).first.cellId > 10 && (*noise).first.cellId < (lastWire - 10))
0165 layerMap[2]++;
0166 if ((*noise).first.cellId >= (lastWire - 10))
0167 layerMap[3]++;
0168
0169 const DTChamberId chId = wireId.layerId().superlayerId().chamberId();
0170 if (noiseHistoMap_.find(chId) == noiseHistoMap_.end())
0171 bookHisto(chId);
0172 int binNumber = 4 * (wireId.superLayer() - 1) + wireId.layer();
0173 noiseHistoMap_[chId]->Fill(wireId.wire(), binNumber);
0174 }
0175
0176
0177 double scale = 1 / double(noisyCellsRef_);
0178 diffHisto_->Fill(1, abs(noisyCellsRef_ - noisyCellsValid_) * scale);
0179
0180 scale = 1 / double(noisyCellsValid_);
0181 for (map<int, int>::const_iterator wheel = whMap.begin(); wheel != whMap.end(); wheel++) {
0182 wheelHisto_->Fill((*wheel).first, ((*wheel).second) * scale);
0183 }
0184 for (map<int, int>::const_iterator station = stMap.begin(); station != stMap.end(); station++) {
0185 stationHisto_->Fill((*station).first, ((*station).second) * scale);
0186 }
0187 for (map<int, int>::const_iterator sector = sectMap.begin(); sector != sectMap.end(); sector++) {
0188 sectorHisto_->Fill((*sector).first, ((*sector).second) * scale);
0189 }
0190 for (map<int, int>::const_iterator layer = layerMap.begin(); layer != layerMap.end(); layer++) {
0191 layerHisto_->Fill((*layer).first, ((*layer).second) * scale);
0192 }
0193 }
0194
0195 void DTnoiseDBValidation::endRun(edm::Run const &run, edm::EventSetup const &setup) {
0196
0197
0198
0199
0200 const QReport *theDiffQReport = diffHisto_->getQReport(diffTestName_);
0201 if (theDiffQReport) {
0202 vector<dqm::me_util::Channel> badChannels = theDiffQReport->getBadChannels();
0203 for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); channel != badChannels.end();
0204 channel++) {
0205 LogWarning("NoiseDBValidation") << " Bad partial difference of noisy channels! Contents : "
0206 << (*channel).getContents();
0207 }
0208 }
0209
0210
0211 const QReport *theDiffQReport2 = wheelHisto_->getQReport(wheelTestName_);
0212 if (theDiffQReport2) {
0213 vector<dqm::me_util::Channel> badChannels = theDiffQReport2->getBadChannels();
0214 for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); channel != badChannels.end();
0215 channel++) {
0216 int wheel = (*channel).getBin() - 3;
0217 LogWarning("NoiseDBValidation") << " Bad percentual occupancy for wheel : " << wheel
0218 << " Contents : " << (*channel).getContents();
0219 }
0220 }
0221
0222
0223 const QReport *theDiffQReport3 = stationHisto_->getQReport(stationTestName_);
0224 if (theDiffQReport3) {
0225 vector<dqm::me_util::Channel> badChannels = theDiffQReport3->getBadChannels();
0226 for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); channel != badChannels.end();
0227 channel++) {
0228 LogWarning("NoiseDBValidation") << " Bad percentual occupancy for station : " << (*channel).getBin()
0229 << " Contents : " << (*channel).getContents();
0230 }
0231 }
0232
0233
0234 const QReport *theDiffQReport4 = sectorHisto_->getQReport(sectorTestName_);
0235 if (theDiffQReport4) {
0236 vector<dqm::me_util::Channel> badChannels = theDiffQReport4->getBadChannels();
0237 for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); channel != badChannels.end();
0238 channel++) {
0239 LogWarning("NoiseDBValidation") << " Bad percentual occupancy for sector : " << (*channel).getBin()
0240 << " Contents : " << (*channel).getContents();
0241 }
0242 }
0243
0244
0245 const QReport *theDiffQReport5 = layerHisto_->getQReport(layerTestName_);
0246 if (theDiffQReport5) {
0247 vector<dqm::me_util::Channel> badChannels = theDiffQReport5->getBadChannels();
0248 for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); channel != badChannels.end();
0249 channel++) {
0250 if ((*channel).getBin() == 1)
0251 LogWarning("NoiseDBValidation") << " Bad percentual occupancy for the first 10 wires! Contents : "
0252 << (*channel).getContents();
0253 if ((*channel).getBin() == 2)
0254 LogWarning("NoiseDBValidation") << " Bad percentual occupancy for the middle wires! Contents : "
0255 << (*channel).getContents();
0256 if ((*channel).getBin() == 3)
0257 LogWarning("NoiseDBValidation") << " Bad percentual occupancy for the last 10 wires! Contents : "
0258 << (*channel).getContents();
0259 }
0260 }
0261 }
0262
0263 void DTnoiseDBValidation::endJob() {
0264
0265 if (outputMEsInRootFile_)
0266 dbe_->save(outputFileName_);
0267 }
0268
0269 void DTnoiseDBValidation::bookHisto(const DTChamberId &chId) {
0270 stringstream histoName;
0271 histoName << "NoiseOccupancy"
0272 << "_W" << chId.wheel() << "_St" << chId.station() << "_Sec" << chId.sector();
0273
0274 if (noiseHistoMap_.find(chId) == noiseHistoMap_.end()) {
0275
0276 int nWiresMax = 0;
0277 const DTChamber *dtchamber = dtGeom->chamber(chId);
0278 const vector<const DTSuperLayer *> &superlayers = dtchamber->superLayers();
0279
0280
0281 for (vector<const DTSuperLayer *>::const_iterator sl = superlayers.begin(); sl != superlayers.end();
0282 ++sl) {
0283 vector<const DTLayer *> layers = (*sl)->layers();
0284 for (vector<const DTLayer *>::const_iterator lay = layers.begin(); lay != layers.end();
0285 ++lay) {
0286 int nWires = (*lay)->specificTopology().channels();
0287 if (nWires > nWiresMax)
0288 nWiresMax = nWires;
0289 }
0290 }
0291
0292 noiseHistoMap_[chId] = dbe_->book2D(histoName.str(), "Noise occupancy", nWiresMax, 1, (nWiresMax + 1), 12, 1, 13);
0293 for (int i_sl = 1; i_sl <= 3; ++i_sl) {
0294 for (int i_lay = 1; i_lay <= 4; ++i_lay) {
0295 int binNumber = 4 * (i_sl - 1) + i_lay;
0296 stringstream label;
0297 label << "SL" << i_sl << ": L" << i_lay;
0298 noiseHistoMap_[chId]->setBinLabel(binNumber, label.str(), 2);
0299 }
0300 }
0301 }
0302 }