CMS 3D CMS Logo

DTnoiseDBValidation.cc
Go to the documentation of this file.
1 
2 /*
3  * See header file for a description of this class.
4  *
5  * \author G. Mila - INFN Torino
6  */
7 
9 
10 // Framework
15 
18 
19 // Geometry
25 
26 // Noise record
29 
30 #include "TFile.h"
31 #include "TH1F.h"
32 #include <cmath>
33 #include <cstdio>
34 #include <sstream>
35 
36 using namespace edm;
37 using namespace std;
38 
40  LogVerbatim("NoiseDBValidation") << "[DTnoiseDBValidation] Constructor called!";
41 
42  // Get the DQM needed services
43  dbe_ = edm::Service<DQMStore>().operator->();
44  dbe_->setCurrentFolder("DT/DtCalib/NoiseDBValidation");
45 
46  // Get dataBase label
47  labelDBRef_ = pset.getParameter<string>("labelDBRef");
48  labelDB_ = pset.getParameter<string>("labelDB");
49 
50  diffTestName_ = "noiseDifferenceInRange";
51  if (pset.exists("diffTestName"))
52  diffTestName_ = pset.getParameter<string>("diffTestName");
53 
54  wheelTestName_ = "noiseWheelOccInRange";
55  if (pset.exists("wheelTestName"))
56  wheelTestName_ = pset.getParameter<string>("wheelTestName");
57 
58  stationTestName_ = "noiseStationOccInRange";
59  if (pset.exists("stationTestName"))
60  stationTestName_ = pset.getParameter<string>("stationTestName");
61 
62  sectorTestName_ = "noiseSectorOccInRange";
63  if (pset.exists("sectorTestName"))
64  sectorTestName_ = pset.getParameter<string>("sectorTestName");
65 
66  layerTestName_ = "noiseLayerOccInRange";
67  if (pset.exists("layerTestName"))
68  layerTestName_ = pset.getParameter<string>("layerTestName");
69 
70  outputMEsInRootFile_ = false;
71  if (pset.exists("OutputFileName")) {
72  outputMEsInRootFile_ = true;
73  outputFileName_ = pset.getParameter<std::string>("OutputFileName");
74  }
75 }
76 
78 
81  setup.get<DTStatusFlagRcd>().get(labelDBRef_, noiseRef);
82  noiseRefMap_ = &*noiseRef;
83 
84  ESHandle<DTStatusFlag> noiseValid;
85  setup.get<DTStatusFlagRcd>().get(labelDB_, noiseValid);
86  noiseMap_ = &*noiseValid;
87 
88  // Get the geometry
89  setup.get<MuonGeometryRecord>().get(dtGeom_);
90 
91  LogVerbatim("NoiseDBValidation") << "[DTnoiseDBValidation] Parameters initialization";
92 
93  noisyCellsRef_ = 0;
94  noisyCellsValid_ = 0;
95 
96  // Histo booking
97  diffHisto_ =
98  dbe_->book1D("noisyCellDiff", "percentual (wrt the previous db) total number of noisy cells", 1, 0.5, 1.5);
99  diffHisto_->setBinLabel(1, "Diff");
100  wheelHisto_ = dbe_->book1D("wheelOccupancy", "percentual noisy cells occupancy per wheel", 5, -2.5, 2.5);
101  wheelHisto_->setBinLabel(1, "Wh-2");
102  wheelHisto_->setBinLabel(2, "Wh-1");
103  wheelHisto_->setBinLabel(3, "Wh0");
104  wheelHisto_->setBinLabel(4, "Wh1");
105  wheelHisto_->setBinLabel(5, "Wh2");
106  stationHisto_ = dbe_->book1D("stationOccupancy", "percentual noisy cells occupancy per station", 4, 0.5, 4.5);
107  stationHisto_->setBinLabel(1, "St1");
108  stationHisto_->setBinLabel(2, "St2");
109  stationHisto_->setBinLabel(3, "St3");
110  stationHisto_->setBinLabel(4, "St4");
111  sectorHisto_ = dbe_->book1D("sectorOccupancy", "percentual noisy cells occupancy per sector", 12, 0.5, 12.5);
112  sectorHisto_->setBinLabel(1, "Sect1");
113  sectorHisto_->setBinLabel(2, "Sect2");
114  sectorHisto_->setBinLabel(3, "Sect3");
115  sectorHisto_->setBinLabel(4, "Sect4");
116  sectorHisto_->setBinLabel(5, "Sect5");
117  sectorHisto_->setBinLabel(6, "Sect6");
118  sectorHisto_->setBinLabel(7, "Sect7");
119  sectorHisto_->setBinLabel(8, "Sect8");
120  sectorHisto_->setBinLabel(9, "Sect9");
121  sectorHisto_->setBinLabel(10, "Sect10");
122  sectorHisto_->setBinLabel(11, "Sect11");
123  sectorHisto_->setBinLabel(12, "Sect12");
124  layerHisto_ = dbe_->book1D("layerOccupancy", "percentual noisy cells occupancy per layer", 3, 0.5, 3.5);
125  layerHisto_->setBinLabel(1, "First 10 bins");
126  layerHisto_->setBinLabel(2, "Middle bins");
127  layerHisto_->setBinLabel(3, "Last 10 bins");
128 
129  // map initialization
130  map<int, int> whMap;
131  whMap.clear();
132  map<int, int> stMap;
133  stMap.clear();
134  map<int, int> sectMap;
135  sectMap.clear();
136  map<int, int> layerMap;
137  layerMap.clear();
138 
139  // Loop over reference DB entries
140  for (DTStatusFlag::const_iterator noise = noiseRefMap_->begin(); noise != noiseRefMap_->end(); noise++) {
141  DTWireId wireId((*noise).first.wheelId,
142  (*noise).first.stationId,
143  (*noise).first.sectorId,
144  (*noise).first.slId,
145  (*noise).first.layerId,
146  (*noise).first.cellId);
147  LogVerbatim("NoiseDBValidation") << "Ref. noisy wire: " << wireId;
148  ++noisyCellsRef_;
149  }
150 
151  // Loop over validation DB entries
152  for (DTStatusFlag::const_iterator noise = noiseMap_->begin(); noise != noiseMap_->end(); noise++) {
153  DTWireId wireId((*noise).first.wheelId,
154  (*noise).first.stationId,
155  (*noise).first.sectorId,
156  (*noise).first.slId,
157  (*noise).first.layerId,
158  (*noise).first.cellId);
159  LogVerbatim("NoiseDBValidation") << "Valid. noisy wire: " << wireId;
160  ++noisyCellsValid_;
161 
162  whMap[(*noise).first.wheelId]++;
163  stMap[(*noise).first.stationId]++;
164  sectMap[(*noise).first.sectorId]++;
165 
166  const DTTopology &dtTopo = dtGeom_->layer(wireId.layerId())->specificTopology();
167  const int lastWire = dtTopo.lastChannel();
168  if ((*noise).first.cellId <= 10)
169  layerMap[1]++;
170  if ((*noise).first.cellId > 10 && (*noise).first.cellId < (lastWire - 10))
171  layerMap[2]++;
172  if ((*noise).first.cellId >= (lastWire - 10))
173  layerMap[3]++;
174 
175  const DTChamberId chId = wireId.layerId().superlayerId().chamberId();
176  if (noiseHistoMap_.find(chId) == noiseHistoMap_.end())
177  bookHisto(chId);
178  int binNumber = 4 * (wireId.superLayer() - 1) + wireId.layer();
179  noiseHistoMap_[chId]->Fill(wireId.wire(), binNumber);
180  }
181 
182  // histo filling
183  double scale = 1 / double(noisyCellsRef_);
184  diffHisto_->Fill(1, abs(noisyCellsRef_ - noisyCellsValid_) * scale);
185 
186  scale = 1 / double(noisyCellsValid_);
187  for (map<int, int>::const_iterator wheel = whMap.begin(); wheel != whMap.end(); wheel++) {
188  wheelHisto_->Fill((*wheel).first, ((*wheel).second) * scale);
189  }
190  for (map<int, int>::const_iterator station = stMap.begin(); station != stMap.end(); station++) {
191  stationHisto_->Fill((*station).first, ((*station).second) * scale);
192  }
193  for (map<int, int>::const_iterator sector = sectMap.begin(); sector != sectMap.end(); sector++) {
194  sectorHisto_->Fill((*sector).first, ((*sector).second) * scale);
195  }
196  for (map<int, int>::const_iterator layer = layerMap.begin(); layer != layerMap.end(); layer++) {
197  layerHisto_->Fill((*layer).first, ((*layer).second) * scale);
198  }
199 }
200 
202  // test on difference histo
203  // string testCriterionName;
204  // testCriterionName =
205  // parameters.getUntrackedParameter<string>("diffTestName","noiseDifferenceInRange");
206  const QReport *theDiffQReport = diffHisto_->getQReport(diffTestName_);
207  if (theDiffQReport) {
208  vector<dqm::me_util::Channel> badChannels = theDiffQReport->getBadChannels();
209  for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); channel != badChannels.end();
210  channel++) {
211  LogWarning("NoiseDBValidation") << " Bad partial difference of noisy channels! Contents : "
212  << (*channel).getContents();
213  }
214  }
215  // testCriterionName =
216  // parameters.getUntrackedParameter<string>("wheelTestName","noiseWheelOccInRange");
217  const QReport *theDiffQReport2 = wheelHisto_->getQReport(wheelTestName_);
218  if (theDiffQReport2) {
219  vector<dqm::me_util::Channel> badChannels = theDiffQReport2->getBadChannels();
220  for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); channel != badChannels.end();
221  channel++) {
222  int wheel = (*channel).getBin() - 3;
223  LogWarning("NoiseDBValidation") << " Bad percentual occupancy for wheel : " << wheel
224  << " Contents : " << (*channel).getContents();
225  }
226  }
227  // testCriterionName =
228  // parameters.getUntrackedParameter<string>("stationTestName","noiseStationOccInRange");
229  const QReport *theDiffQReport3 = stationHisto_->getQReport(stationTestName_);
230  if (theDiffQReport3) {
231  vector<dqm::me_util::Channel> badChannels = theDiffQReport3->getBadChannels();
232  for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); channel != badChannels.end();
233  channel++) {
234  LogWarning("NoiseDBValidation") << " Bad percentual occupancy for station : " << (*channel).getBin()
235  << " Contents : " << (*channel).getContents();
236  }
237  }
238  // testCriterionName =
239  // parameters.getUntrackedParameter<string>("sectorTestName","noiseSectorOccInRange");
240  const QReport *theDiffQReport4 = sectorHisto_->getQReport(sectorTestName_);
241  if (theDiffQReport4) {
242  vector<dqm::me_util::Channel> badChannels = theDiffQReport4->getBadChannels();
243  for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); channel != badChannels.end();
244  channel++) {
245  LogWarning("NoiseDBValidation") << " Bad percentual occupancy for sector : " << (*channel).getBin()
246  << " Contents : " << (*channel).getContents();
247  }
248  }
249  // testCriterionName =
250  // parameters.getUntrackedParameter<string>("layerTestName","noiseLayerOccInRange");
251  const QReport *theDiffQReport5 = layerHisto_->getQReport(layerTestName_);
252  if (theDiffQReport5) {
253  vector<dqm::me_util::Channel> badChannels = theDiffQReport5->getBadChannels();
254  for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); channel != badChannels.end();
255  channel++) {
256  if ((*channel).getBin() == 1)
257  LogWarning("NoiseDBValidation") << " Bad percentual occupancy for the first 10 wires! Contents : "
258  << (*channel).getContents();
259  if ((*channel).getBin() == 2)
260  LogWarning("NoiseDBValidation") << " Bad percentual occupancy for the middle wires! Contents : "
261  << (*channel).getContents();
262  if ((*channel).getBin() == 3)
263  LogWarning("NoiseDBValidation") << " Bad percentual occupancy for the last 10 wires! Contents : "
264  << (*channel).getContents();
265  }
266  }
267 }
268 
270  // Write the histos in a ROOT file
271  if (outputMEsInRootFile_)
272  dbe_->save(outputFileName_);
273 }
274 
276  stringstream histoName;
277  histoName << "NoiseOccupancy"
278  << "_W" << chId.wheel() << "_St" << chId.station() << "_Sec" << chId.sector();
279 
280  if (noiseHistoMap_.find(chId) == noiseHistoMap_.end()) { // Redundant check
281  // Get the chamber from the geometry
282  int nWiresMax = 0;
283  const DTChamber *dtchamber = dtGeom_->chamber(chId);
284  const vector<const DTSuperLayer *> &superlayers = dtchamber->superLayers();
285 
286  // Loop over layers and find the max # of wires
287  for (vector<const DTSuperLayer *>::const_iterator sl = superlayers.begin(); sl != superlayers.end();
288  ++sl) { // loop over SLs
289  vector<const DTLayer *> layers = (*sl)->layers();
290  for (vector<const DTLayer *>::const_iterator lay = layers.begin(); lay != layers.end();
291  ++lay) { // loop over layers
292  int nWires = (*lay)->specificTopology().channels();
293  if (nWires > nWiresMax)
294  nWiresMax = nWires;
295  }
296  }
297 
298  noiseHistoMap_[chId] = dbe_->book2D(histoName.str(), "Noise occupancy", nWiresMax, 1, (nWiresMax + 1), 12, 1, 13);
299  for (int i_sl = 1; i_sl <= 3; ++i_sl) {
300  for (int i_lay = 1; i_lay <= 4; ++i_lay) {
301  int binNumber = 4 * (i_sl - 1) + i_lay;
302  stringstream label;
303  label << "SL" << i_sl << ": L" << i_lay;
304  noiseHistoMap_[chId]->setBinLabel(binNumber, label.str(), 2);
305  }
306  }
307  }
308 }
DTWireId::wire
int wire() const
Return the wire number.
Definition: DTWireId.h:42
MessageLogger.h
DTnoiseDBValidation::DTnoiseDBValidation
DTnoiseDBValidation(const edm::ParameterSet &pset)
Constructor.
Definition: DTnoiseDBValidation.cc:39
ESHandle.h
DTnoiseDBValidation::bookHisto
void bookHisto(const DTChamberId &)
Definition: DTnoiseDBValidation.cc:275
edm::Run
Definition: Run.h:45
HLT_FULL_cff.scale
scale
Definition: HLT_FULL_cff.py:6634
DTLayerId.h
relativeConstraints.station
station
Definition: relativeConstraints.py:67
edm
HLT enums.
Definition: AlignableModifier.h:19
DTChamber
Definition: DTChamber.h:24
DQMStore.h
DTnoiseDBValidation::endJob
void endJob() override
Definition: DTnoiseDBValidation.cc:269
DTStatusFlagRcd.h
DTnoiseDBValidation::endRun
void endRun(edm::Run const &, edm::EventSetup const &) override
Definition: DTnoiseDBValidation.cc:201
DTSuperLayerId::superLayer
int superLayer() const
Return the superlayer number.
Definition: DTSuperLayerId.h:39
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
DTTopology
Definition: DTTopology.h:28
DTWireId
Definition: DTWireId.h:12
Service.h
edm::ESHandle
Definition: DTSurvey.h:22
DTStatusFlag::const_iterator
std::vector< std::pair< DTStatusFlagId, DTStatusFlagData > >::const_iterator const_iterator
Access methods to data.
Definition: DTStatusFlag.h:192
DTnoiseDBValidation::~DTnoiseDBValidation
~DTnoiseDBValidation() override
Destructor.
Definition: DTnoiseDBValidation.cc:77
dqm::implementation::DQMStore::setCurrentFolder
void setCurrentFolder(std::string const &fullpath) override
Definition: DQMStore.h:569
dbe_
dqm::legacy::DQMStore * dbe_
Definition: PFJetBenchmarkAnalyzer.cc:77
MonitorElementData::QReport::getBadChannels
const std::vector< DQMChannel > & getBadChannels() const
Definition: MonitorElementCollection.h:116
dqm::implementation::DQMStore::save
DQM_DEPRECATED void save(std::string const &filename, std::string const &path="")
Definition: DQMStore.cc:761
DTStatusFlag.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DTGeometry.h
DTStatusFlagRcd
Definition: DTStatusFlagRcd.h:5
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
DTSuperLayerId::chamberId
DTChamberId chamberId() const
Return the corresponding ChamberId.
Definition: DTSuperLayerId.h:45
plotT0FromHistos.binNumber
def binNumber(station, sl)
Definition: plotT0FromHistos.py:6
hgcalDigitizer_cfi.noise
noise
Definition: hgcalDigitizer_cfi.py:155
dtNoiseDBValidation_cfg.noiseRef
noiseRef
Definition: dtNoiseDBValidation_cfg.py:50
edm::get
T const & get(Event const &event, InputTag const &tag) noexcept(false)
Definition: Event.h:671
MonitorElementData::QReport
Definition: MonitorElementCollection.h:55
makeMuonMisalignmentScenario.wheel
wheel
Definition: makeMuonMisalignmentScenario.py:319
edm::Service
Definition: Service.h:30
dqm::impl::MonitorElement::setBinLabel
virtual void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
Definition: MonitorElement.cc:771
DTChamber::superLayers
const std::vector< const DTSuperLayer * > & superLayers() const
Return the superlayers in the chamber.
Definition: DTChamber.cc:51
edm::EventSetup
Definition: EventSetup.h:57
DTnoiseDBValidation.h
DTTopology::lastChannel
int lastChannel() const
Returns the wire number of the last wire.
Definition: DTTopology.h:81
DTChamberId::sector
int sector() const
Definition: DTChamberId.h:49
std
Definition: JetResolutionObject.h:76
writedatasetfile.run
run
Definition: writedatasetfile.py:27
DTWireId.h
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
dqm::implementation::IBooker::book2D
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:177
DTnoiseDBValidation::beginRun
void beginRun(const edm::Run &run, const edm::EventSetup &setup) override
Operations.
Definition: DTnoiseDBValidation.cc:79
DTLayerId::superlayerId
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:45
HltBtagPostValidation_cff.histoName
histoName
Definition: HltBtagPostValidation_cff.py:17
EventSetup.h
DTWireId::layerId
DTLayerId layerId() const
Return the corresponding LayerId.
Definition: DTWireId.h:45
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
DTChamberId
Definition: DTChamberId.h:14
MuonGeometryRecord.h
DTLayerId::layer
int layer() const
Return the layer number.
Definition: DTLayerId.h:42
DTTopology.h
MuonGeometryRecord
Definition: MuonGeometryRecord.h:34
DTChamberId::wheel
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
label
const char * label
Definition: PFTauDecayModeTools.cc:11
hgcalTopologyTester_cfi.layers
layers
Definition: hgcalTopologyTester_cfi.py:8
DTChamberId::station
int station() const
Return the station number.
Definition: DTChamberId.h:42
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
dqm::implementation::IBooker::book1D
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98