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  * $Date: 2011/08/06 13:13:43 $
6  * $Revision: 1.7 $
7  * \author G. Mila - INFN Torino
8  */
9 
11 
12 // Framework
17 
21 
22 // Geometry
28 
29 // Noise record
32 
33 #include <stdio.h>
34 #include <sstream>
35 #include <math.h>
36 #include "TFile.h"
37 #include "TH1F.h"
38 
39 using namespace edm;
40 using namespace std;
41 
43 
44  LogVerbatim("NoiseDBValidation") << "[DTnoiseDBValidation] Constructor called!";
45 
46  // Get the DQM needed services
48  dbe_->setCurrentFolder("DT/DtCalib/NoiseDBValidation");
49 
50  // Get dataBase label
51  labelDBRef_ = pset.getParameter<string>("labelDBRef");
52  labelDB_ = pset.getParameter<string>("labelDB");
53 
54  diffTestName_ = "noiseDifferenceInRange";
55  if( pset.exists("diffTestName") ) diffTestName_ = pset.getParameter<string>("diffTestName");
56 
57  wheelTestName_ = "noiseWheelOccInRange";
58  if( pset.exists("wheelTestName") ) wheelTestName_ = pset.getParameter<string>("wheelTestName");
59 
60  stationTestName_ = "noiseStationOccInRange";
61  if( pset.exists("stationTestName") ) stationTestName_ = pset.getParameter<string>("stationTestName");
62 
63  sectorTestName_ = "noiseSectorOccInRange";
64  if( pset.exists("sectorTestName") ) sectorTestName_ = pset.getParameter<string>("sectorTestName");
65 
66  layerTestName_ = "noiseLayerOccInRange";
67  if( pset.exists("layerTestName") ) layerTestName_ = pset.getParameter<string>("layerTestName");
68 
69  outputMEsInRootFile_ = false;
70  if( pset.exists("OutputFileName") ){
71  outputMEsInRootFile_ = true;
72  outputFileName_ = pset.getParameter<std::string>("OutputFileName");
73  }
74 }
75 
76 
78 
80  ESHandle<DTStatusFlag> noiseRef;
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_ = dbe_->book1D("noisyCellDiff", "percentual (wrt the previous db) total number of noisy cells",1, 0.5, 1.5);
98  diffHisto_->setBinLabel(1,"Diff");
99  wheelHisto_ = dbe_->book1D("wheelOccupancy", "percentual noisy cells occupancy per wheel",5, -2.5, 2.5);
100  wheelHisto_->setBinLabel(1,"Wh-2");
101  wheelHisto_->setBinLabel(2,"Wh-1");
102  wheelHisto_->setBinLabel(3,"Wh0");
103  wheelHisto_->setBinLabel(4,"Wh1");
104  wheelHisto_->setBinLabel(5,"Wh2");
105  stationHisto_ = dbe_->book1D("stationOccupancy", "percentual noisy cells occupancy per station",4, 0.5, 4.5);
106  stationHisto_->setBinLabel(1,"St1");
107  stationHisto_->setBinLabel(2,"St2");
108  stationHisto_->setBinLabel(3,"St3");
109  stationHisto_->setBinLabel(4,"St4");
110  sectorHisto_ = dbe_->book1D("sectorOccupancy", "percentual noisy cells occupancy per sector",12, 0.5, 12.5);
111  sectorHisto_->setBinLabel(1,"Sect1");
112  sectorHisto_->setBinLabel(2,"Sect2");
113  sectorHisto_->setBinLabel(3,"Sect3");
114  sectorHisto_->setBinLabel(4,"Sect4");
115  sectorHisto_->setBinLabel(5,"Sect5");
116  sectorHisto_->setBinLabel(6,"Sect6");
117  sectorHisto_->setBinLabel(7,"Sect7");
118  sectorHisto_->setBinLabel(8,"Sect8");
119  sectorHisto_->setBinLabel(9,"Sect9");
120  sectorHisto_->setBinLabel(10,"Sect10");
121  sectorHisto_->setBinLabel(11,"Sect11");
122  sectorHisto_->setBinLabel(12,"Sect12");
123  layerHisto_ = dbe_->book1D("layerOccupancy", "percentual noisy cells occupancy per layer",3, 0.5, 3.5);
124  layerHisto_->setBinLabel(1,"First 10 bins");
125  layerHisto_->setBinLabel(2,"Middle bins");
126  layerHisto_->setBinLabel(3,"Last 10 bins");
127 
128  // map initialization
129  map<int, int> whMap;
130  whMap.clear();
131  map<int, int> stMap;
132  stMap.clear();
133  map<int, int> sectMap;
134  sectMap.clear();
135  map<int, int> layerMap;
136  layerMap.clear();
137 
138  // Loop over reference DB entries
139  for(DTStatusFlag::const_iterator noise = noiseRefMap_->begin();
140  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();
153  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() ) 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();
188  wheel != whMap.end();
189  wheel++) {
190  wheelHisto_->Fill((*wheel).first, ((*wheel).second)*scale);
191  }
192  for(map<int, int >::const_iterator station = stMap.begin();
193  station != stMap.end();
194  station++) {
195  stationHisto_->Fill((*station).first, ((*station).second)*scale);
196  }
197  for(map<int, int >::const_iterator sector = sectMap.begin();
198  sector != sectMap.end();
199  sector++) {
200  sectorHisto_->Fill((*sector).first, ((*sector).second)*scale);
201  }
202  for(map<int, int >::const_iterator layer = layerMap.begin();
203  layer != layerMap.end();
204  layer++) {
205  layerHisto_->Fill((*layer).first, ((*layer).second)*scale);
206  }
207 
208 }
209 
211 
212  // test on difference histo
213  //string testCriterionName;
214  //testCriterionName = parameters.getUntrackedParameter<string>("diffTestName","noiseDifferenceInRange");
215  const QReport * theDiffQReport = diffHisto_->getQReport(diffTestName_);
216  if(theDiffQReport) {
217  vector<dqm::me_util::Channel> badChannels = theDiffQReport->getBadChannels();
218  for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin();
219  channel != badChannels.end(); channel++) {
220  LogWarning("NoiseDBValidation") << " Bad partial difference of noisy channels! Contents : " << (*channel).getContents();
221  }
222  }
223  //testCriterionName = parameters.getUntrackedParameter<string>("wheelTestName","noiseWheelOccInRange");
224  const QReport * theDiffQReport2 = wheelHisto_->getQReport(wheelTestName_);
225  if(theDiffQReport2) {
226  vector<dqm::me_util::Channel> badChannels = theDiffQReport2->getBadChannels();
227  for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin();
228  channel != badChannels.end(); channel++) {
229  int wheel = (*channel).getBin()-3;
230  LogWarning("NoiseDBValidation") << " Bad percentual occupancy for wheel : " << wheel << " Contents : " << (*channel).getContents();
231  }
232  }
233  //testCriterionName = parameters.getUntrackedParameter<string>("stationTestName","noiseStationOccInRange");
234  const QReport * theDiffQReport3 = stationHisto_->getQReport(stationTestName_);
235  if(theDiffQReport3) {
236  vector<dqm::me_util::Channel> badChannels = theDiffQReport3->getBadChannels();
237  for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin();
238  channel != badChannels.end(); channel++) {
239  LogWarning("NoiseDBValidation") << " Bad percentual occupancy for station : " << (*channel).getBin() << " Contents : " << (*channel).getContents();
240  }
241  }
242  //testCriterionName = parameters.getUntrackedParameter<string>("sectorTestName","noiseSectorOccInRange");
243  const QReport * theDiffQReport4 = sectorHisto_->getQReport(sectorTestName_);
244  if(theDiffQReport4) {
245  vector<dqm::me_util::Channel> badChannels = theDiffQReport4->getBadChannels();
246  for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin();
247  channel != badChannels.end(); channel++) {
248  LogWarning("NoiseDBValidation") << " Bad percentual occupancy for sector : " << (*channel).getBin() << " Contents : " << (*channel).getContents();
249  }
250  }
251  //testCriterionName = 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();
256  channel != badChannels.end(); channel++) {
257  if((*channel).getBin()==1)
258  LogWarning("NoiseDBValidation") << " Bad percentual occupancy for the first 10 wires! Contents : " << (*channel).getContents();
259  if((*channel).getBin()==2)
260  LogWarning("NoiseDBValidation") << " Bad percentual occupancy for the middle wires! Contents : " << (*channel).getContents();
261  if((*channel).getBin()==3)
262  LogWarning("NoiseDBValidation") << " Bad percentual occupancy for the last 10 wires! Contents : "<<(*channel).getContents();
263  }
264  }
265 
266 }
267 
269  // Write the histos in a ROOT file
270  if(outputMEsInRootFile_) dbe_->save(outputFileName_);
271 }
272 
274  stringstream histoName;
275  histoName << "NoiseOccupancy"
276  << "_W" << chId.wheel()
277  <<"_St" << chId.station()
278  << "_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();
288  sl != superlayers.end(); ++sl) { // loop over SLs
289  vector<const DTLayer*> layers = (*sl)->layers();
290  for(vector<const DTLayer*>::const_iterator lay = layers.begin();
291  lay != layers.end(); ++lay) { // loop over layers
292  int nWires = (*lay)->specificTopology().channels();
293  if(nWires > nWiresMax) nWiresMax = nWires;
294  }
295  }
296 
297  noiseHistoMap_[chId] = dbe_->book2D(histoName.str(),"Noise occupancy",nWiresMax,1,(nWiresMax + 1),12,1,13);
298  for(int i_sl = 1; i_sl <= 3; ++i_sl) {
299  for(int i_lay = 1; i_lay <= 4; ++i_lay) {
300  int binNumber = 4*(i_sl - 1) + i_lay;
301  stringstream label;
302  label << "SL" << i_sl << ": L" << i_lay;
303  noiseHistoMap_[chId]->setBinLabel(binNumber,label.str(),2);
304  }
305  }
306  }
307 
308 }
T getParameter(std::string const &) const
void beginRun(const edm::Run &run, const edm::EventSetup &setup)
Operations.
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:717
DTChamberId chamberId() const
Return the corresponding ChamberId.
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:2113
bool exists(std::string const &parameterName) const
checks if a parameter exists
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)
#define abs(x)
Definition: mlp_lapack.h:159
void bookHisto(const DTChamberId &)
int layer() const
Return the layer number.
Definition: DTLayerId.h:55
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:61
int lastChannel() const
Returns the wire number of the last wire.
Definition: DTTopology.h:82
DTnoiseDBValidation(const edm::ParameterSet &pset)
Constructor.
const std::vector< const DTSuperLayer * > & superLayers() const
Return the superlayers in the chamber.
Definition: DTChamber.cc:62
int superLayer() const
Return the superlayer number.
std::vector< std::pair< DTStatusFlagId, DTStatusFlagData > >::const_iterator const_iterator
Access methods to data.
Definition: DTStatusFlag.h:255
const std::vector< DQMChannel > & getBadChannels(void) const
Definition: QReport.h:33
DQMStore * dbe_
int wire() const
Return the wire number.
Definition: DTWireId.h:58
const T & get() const
Definition: EventSetup.h:55
void endRun(edm::Run const &, edm::EventSetup const &)
DTLayerId layerId() const
Return the corresponding LayerId.
Definition: DTWireId.h:64
int sector() const
Definition: DTChamberId.h:63
virtual ~DTnoiseDBValidation()
Destructor.
int station() const
Return the station number.
Definition: DTChamberId.h:53
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:845
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:47
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429
Definition: Run.h:33