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