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: 2009/03/10 16:54:12 $
6  * $Revision: 1.3 $
7  * \author G. Mila - INFN Torino
8  */
9 
11 
12 // Framework
17 
21 
22 // Geometry
27 
28 // noise
31 
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 
42 
43 
44 
46 
47  cout << "[DTnoiseDBValidation] Constructor called!" << endl;
48 
49  // Get the DQM needed services
50  dbe = edm::Service<DQMStore>().operator->();
51  dbe->setCurrentFolder("DT/noiseDBValidation");
52 
53  // Get dataBase label
54  labelDBRef = pset.getUntrackedParameter<string>("labelDBRef");
55  labelDB = pset.getUntrackedParameter<string>("labelDB");
56 
57  parameters = pset;
58 }
59 
60 
62 
64  ESHandle<DTStatusFlag> noise_Ref;
65  setup.get<DTStatusFlagRcd>().get(labelDBRef, noise_Ref);
66  noiseRefMap = &*noise_Ref;
67 
68  ESHandle<DTStatusFlag> noise_toTest;
69  setup.get<DTStatusFlagRcd>().get(labelDB, noise_toTest);
70  noiseMap = &*noise_toTest;
71 
72  // Get the geometry
73  setup.get<MuonGeometryRecord>().get(dtGeom);
74 }
75 
77 
78 
79  metname = "noiseDbValidation";
80  LogTrace(metname)<<"[DTnoiseDBValidation] Parameters initialization";
81 
82  outputFileName = parameters.getUntrackedParameter<std::string>("OutputFileName");
83 
84  noisyCells_Ref=0;
85  noisyCells_toTest=0;
86 
87  // histo booking
88  diffHisto = dbe->book1D("noisyCellDiff", "percentual (wrt the previous db) total number of noisy cells",1, 0.5, 1.5);
89  diffHisto->setBinLabel(1,"diff");
90  wheelHisto = dbe->book1D("wheelOccupancy", "percentual noisy cells occupancy per wheel",5, -2.5, 2.5);
91  wheelHisto->setBinLabel(1,"wh-2");
92  wheelHisto->setBinLabel(2,"wh-1");
93  wheelHisto->setBinLabel(3,"wh0");
94  wheelHisto->setBinLabel(4,"wh1");
95  wheelHisto->setBinLabel(5,"wh2");
96  stationHisto = dbe->book1D("stationOccupancy", "percentual noisy cells occupancy per station",4, 0.5, 4.5);
97  stationHisto->setBinLabel(1,"st1");
98  stationHisto->setBinLabel(2,"st2");
99  stationHisto->setBinLabel(3,"st3");
100  stationHisto->setBinLabel(4,"st4");
101  sectorHisto = dbe->book1D("sectorOccupancy", "percentual noisy cells occupancy per sector",12, 0.5, 12.5);
102  sectorHisto->setBinLabel(1,"sect1");
103  sectorHisto->setBinLabel(2,"sect2");
104  sectorHisto->setBinLabel(3,"sect3");
105  sectorHisto->setBinLabel(4,"sect4");
106  sectorHisto->setBinLabel(5,"sect5");
107  sectorHisto->setBinLabel(6,"sect6");
108  sectorHisto->setBinLabel(7,"sect7");
109  sectorHisto->setBinLabel(8,"sect8");
110  sectorHisto->setBinLabel(9,"sect9");
111  sectorHisto->setBinLabel(10,"sect10");
112  sectorHisto->setBinLabel(11,"sect11");
113  sectorHisto->setBinLabel(12,"sect12");
114  layerHisto = dbe->book1D("layerOccupancy", "percentual noisy cells occupancy per layer",3, 0.5, 3.5);
115  layerHisto->setBinLabel(1,"first 10 bins");
116  layerHisto->setBinLabel(2,"middle bins");
117  layerHisto->setBinLabel(3,"last 10 bins");
118 
119  // map initialization
120  map<int, int> whMap;
121  whMap.clear();
122  map<int, int> stMap;
123  stMap.clear();
124  map<int, int> sectMap;
125  sectMap.clear();
126  map<int, int> layerMap;
127  layerMap.clear();
128 
129  // Loop over Ref DB entries
130  for(DTStatusFlag::const_iterator noise = noiseRefMap->begin();
131  noise != noiseRefMap->end(); noise++) {
132  DTWireId wireId((*noise).first.wheelId,
133  (*noise).first.stationId,
134  (*noise).first.sectorId,
135  (*noise).first.slId,
136  (*noise).first.layerId,
137  (*noise).first.cellId);
138  cout<< "Ref Wire: " << wireId<<endl;
139  noisyCells_Ref++;
140  }
141 
142  // Loop over Ref DB entries
143  for(DTStatusFlag::const_iterator noise = noiseMap->begin();
144  noise != noiseMap->end(); noise++) {
145  DTWireId wireId((*noise).first.wheelId,
146  (*noise).first.stationId,
147  (*noise).first.sectorId,
148  (*noise).first.slId,
149  (*noise).first.layerId,
150  (*noise).first.cellId);
151  cout<< "toTest Wire: " << wireId<<endl;
152  noisyCells_toTest++;
153 
154  whMap[(*noise).first.wheelId]++;
155  stMap[(*noise).first.stationId]++;
156  sectMap[(*noise).first.sectorId]++;
157 
158  const DTTopology& dtTopo = dtGeom->layer(wireId.layerId())->specificTopology();
159  const int lastWire = dtTopo.lastChannel();
160  if((*noise).first.cellId<=10)
161  layerMap[1]++;
162  if((*noise).first.cellId>10 && (*noise).first.cellId<(lastWire-10))
163  layerMap[2]++;
164  if((*noise).first.cellId>=(lastWire-10))
165  layerMap[3]++;
166 
167  }
168 
169  //histo filling
170  double scale = 1/double(noisyCells_Ref);
171  diffHisto->Fill(1,abs(noisyCells_Ref-noisyCells_toTest)*scale);
172 
173  scale = 1/double(noisyCells_toTest);
174  for(map<int, int >::const_iterator wheel = whMap.begin();
175  wheel != whMap.end();
176  wheel++) {
177  wheelHisto->Fill((*wheel).first, ((*wheel).second)*scale);
178  }
179  for(map<int, int >::const_iterator station = stMap.begin();
180  station != stMap.end();
181  station++) {
182  stationHisto->Fill((*station).first, ((*station).second)*scale);
183  }
184  for(map<int, int >::const_iterator sector = sectMap.begin();
185  sector != sectMap.end();
186  sector++) {
187  sectorHisto->Fill((*sector).first, ((*sector).second)*scale);
188  }
189  for(map<int, int >::const_iterator layer = layerMap.begin();
190  layer != layerMap.end();
191  layer++) {
192  layerHisto->Fill((*layer).first, ((*layer).second)*scale);
193  }
194 
195 }
196 
198 
199  // test on difference histo
200  string testCriterionName = parameters.getUntrackedParameter<string>("diffTestName","noiseDifferenceInRange");
201  const QReport * theDiffQReport = diffHisto->getQReport(testCriterionName);
202  if(theDiffQReport) {
203  vector<dqm::me_util::Channel> badChannels = theDiffQReport->getBadChannels();
204  for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin();
205  channel != badChannels.end(); channel++) {
206  cout << " Bad partial difference of noisy channels! Contents : "<<(*channel).getContents()<<endl;
207  }
208  }
209  testCriterionName = parameters.getUntrackedParameter<string>("wheelTestName","noiseWheelOccInRange");
210  const QReport * theDiffQReport2 = wheelHisto->getQReport(testCriterionName);
211  if(theDiffQReport2) {
212  vector<dqm::me_util::Channel> badChannels = theDiffQReport2->getBadChannels();
213  for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin();
214  channel != badChannels.end(); channel++) {
215  int wheel = (*channel).getBin()-3;
216  cout << " Bad percentual occupancy for wheel : "<<wheel<<" Contents : "<<(*channel).getContents()<<endl;
217  }
218  }
219  testCriterionName = parameters.getUntrackedParameter<string>("stationTestName","noiseStationOccInRange");
220  const QReport * theDiffQReport3 = stationHisto->getQReport(testCriterionName);
221  if(theDiffQReport3) {
222  vector<dqm::me_util::Channel> badChannels = theDiffQReport3->getBadChannels();
223  for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin();
224  channel != badChannels.end(); channel++) {
225  cout << " Bad percentual occupancy for station : "<<(*channel).getBin()<<" Contents : "<<(*channel).getContents()<<endl;
226  }
227  }
228  testCriterionName = parameters.getUntrackedParameter<string>("sectorTestName","noiseSectorOccInRange");
229  const QReport * theDiffQReport4 = sectorHisto->getQReport(testCriterionName);
230  if(theDiffQReport4) {
231  vector<dqm::me_util::Channel> badChannels = theDiffQReport4->getBadChannels();
232  for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin();
233  channel != badChannels.end(); channel++) {
234  cout << " Bad percentual occupancy for sector : "<<(*channel).getBin()<<" Contents : "<<(*channel).getContents()<<endl;
235  }
236  }
237  testCriterionName = parameters.getUntrackedParameter<string>("layerTestName","noiseLayerOccInRange");
238  const QReport * theDiffQReport5 = layerHisto->getQReport(testCriterionName);
239  if(theDiffQReport5) {
240  vector<dqm::me_util::Channel> badChannels = theDiffQReport5->getBadChannels();
241  for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin();
242  channel != badChannels.end(); channel++) {
243  if((*channel).getBin()==1)
244  cout << " Bad percentual occupancy for the first 10 wires! Contents : "<<(*channel).getContents()<<endl;
245  if((*channel).getBin()==2)
246  cout << " Bad percentual occupancy for the middle wires! Contents : "<<(*channel).getContents()<<endl;
247  if((*channel).getBin()==3)
248  cout << " Bad percentual occupancy for the last 10 wires! Contents : "<<(*channel).getContents()<<endl;
249  }
250  }
251 
252  // write the histos on a file
253  dbe->save(outputFileName);
254 
255 }
const int lastChannel() const
Returns the wire number of the last wire.
Definition: DTTopology.h:82
T getUntrackedParameter(std::string const &, T const &) const
void beginRun(const edm::Run &run, const edm::EventSetup &setup)
const std::string metname
#define abs(x)
Definition: mlp_lapack.h:159
DTnoiseDBValidation(const edm::ParameterSet &pset)
Constructor.
std::vector< std::pair< DTStatusFlagId, DTStatusFlagData > >::const_iterator const_iterator
Access methods to data.
Definition: DTStatusFlag.h:255
tuple pset
Definition: CrabTask.py:85
const std::vector< DQMChannel > & getBadChannels(void) const
Definition: QReport.h:33
#define LogTrace(id)
const T & get() const
Definition: EventSetup.h:55
void beginJob()
Operations.
DTLayerId layerId() const
Return the corresponding LayerId.
Definition: DTWireId.h:64
virtual ~DTnoiseDBValidation()
Destructor.
tuple cout
Definition: gather_cfg.py:41
Definition: Run.h:31