CMS 3D CMS Logo

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