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