CMS 3D CMS Logo

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