CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTNoiseTest.cc
Go to the documentation of this file.
1 /*
2  *
3  * $Date: 2011/11/24 09:17:30 $
4  * $Revision: 1.22 $
5  * \authors:
6  * A. Gresele - INFN Trento
7  * G. Mila - INFN Torino
8  * M. Zanetti - CERN PH
9  *
10  */
11 
13 
14 // Framework
16 
17 
18 // Geometry
23 
24 
28 
29 #include <stdio.h>
30 #include <sstream>
31 #include <math.h>
32 
33 using namespace edm;
34 using namespace std;
35 
36 
37 
39 
40  edm::LogVerbatim ("noise") <<"[DTNoiseTest]: Constructor";
41 
42  parameters = ps;
43 
44  dbe = edm::Service<DQMStore>().operator->();
45  dbe->setCurrentFolder("DT/Tests/Noise");
46 
47  prescaleFactor = parameters.getUntrackedParameter<int>("diagnosticPrescale", 1);
48 
49 }
50 
51 
52 
54 
55  edm::LogVerbatim ("noise") <<"DTNoiseTest: analyzed " << updates << " events";
56 
57 }
58 
59 
60 
62 
63  edm::LogVerbatim ("noise") <<"[DTNoiseTest]: BeginJob";
64 
65  updates = 0;
66 
67 }
68 
69 
70 void DTNoiseTest::beginRun(const edm::Run& run, const edm::EventSetup& context){
71 
72  edm::LogVerbatim ("noise") <<"[DTNoiseTest]: BeginRun";
73 
74  // Get the geometry
75  context.get<MuonGeometryRecord>().get(muonGeom);
76 
77 }
78 
79 
80 
81 void DTNoiseTest::beginLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context) {
82 
83  edm::LogVerbatim ("noise") <<"[DTNoiseTest]: Begin of LS transition";
84 
85  // Get the run number
86  run = lumiSeg.run();
87 
88 }
89 
90 
91 void DTNoiseTest::analyze(const edm::Event& e, const edm::EventSetup& context){
92 
93  updates++;
94  edm::LogVerbatim ("noise") << "[DTNoiseTest]: "<<updates<<" events";
95 
96 }
97 
98 
99 void DTNoiseTest::endLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context) {
100 
101  // counts number of updats (online mode) or number of events (standalone mode)
102  //updates++;
103  // if running in standalone perform diagnostic only after a reasonalbe amount of events
104  //if ( parameters.getUntrackedParameter<bool>("runningStandalone", false) &&
105  // updates%parameters.getUntrackedParameter<int>("diagnosticPrescale", 1000) != 0 ) return;
106 
107  //edm::LogVerbatim ("noise") <<"[DTNoiseTest]: "<<updates<<" updates";
108 
109 
110  edm::LogVerbatim ("noise") <<"[DTNoiseTest]: End of LS transition, performing the DQM client operation";
111 
112  // counts number of lumiSegs
113  nLumiSegs = lumiSeg.id().luminosityBlock();
114 
115  // prescale factor
116  if ( nLumiSegs%prescaleFactor != 0 ) return;
117 
118  edm::LogVerbatim ("noise") <<"[DTNoiseTest]: "<<nLumiSegs<<" updates";
119 
121  context.get<DTStatusFlagRcd>().get(statusMap);
122 
123  context.get<DTTtrigRcd>().get(tTrigMap);
124  float tTrig, tTrigRMS, kFactor;
125 
126  string histoTag;
127  // loop over chambers
128  vector<DTChamber*>::const_iterator ch_it = muonGeom->chambers().begin();
129  vector<DTChamber*>::const_iterator ch_end = muonGeom->chambers().end();
130 
131  for (; ch_it != ch_end; ++ch_it) {
132  DTChamberId ch = (*ch_it)->id();
133  vector<const DTSuperLayer*>::const_iterator sl_it = (*ch_it)->superLayers().begin();
134  vector<const DTSuperLayer*>::const_iterator sl_end = (*ch_it)->superLayers().end();
135 
136  MonitorElement * noiseME = dbe->get(getMEName(ch));
137  if (noiseME) {
138  TH2F * noiseHisto = noiseME->getTH2F();
139 
140  // WARNING uncorrect normalization!! TO BE PROVIDED CENTRALLY
141  double nevents = (int) noiseHisto->GetEntries();
142 
143  double normalization =0;
144 
145  float average=0;
146  float nOfChannels=0;
147  float noiseStatistics=0;
148  int newNoiseChannels=0;
149 
150  for(; sl_it != sl_end; ++sl_it) {
151  const DTSuperLayerId & slID = (*sl_it)->id();
152 
153  // ttrig and rms are counts
154  tTrigMap->get(slID, tTrig, tTrigRMS, kFactor, DTTimeUnits::counts);
155  if (tTrig==0) tTrig=1;
156  const double ns_s = 1e9*(32/25);
157  normalization = ns_s/float(tTrig*nevents);
158 
159  noiseHisto->Scale(normalization);
160 
161  // loop over layers
162 
163  for (int binY=(slID.superLayer()-1)*4+1 ; binY <= (slID.superLayer()-1)*4+4; binY++) {
164 
165  int Y = binY - 4*(slID.superLayer()-1);
166 
167  // the layer
168 
169  const DTLayerId theLayer(slID,Y);
170 
171  // loop over channels
172  for (int binX=1; binX <= noiseHisto->GetNbinsX(); binX++) {
173 
174  if (noiseHisto->GetBinContent(binX,binY) > parameters.getUntrackedParameter<int>("HzThreshold", 300))
175  theNoisyChannels.push_back(DTWireId(theLayer, binX));
176 
177  // get rid of the dead channels
178  else {
179  average += noiseHisto->GetBinContent(binX,binY);
180  nOfChannels++;
181  }
182  }
183  }
184 
185  if (nOfChannels) noiseStatistics = average/nOfChannels;
186  histoTag = "NoiseAverage";
187 
188  if (histos[histoTag].find((*ch_it)->id().rawId()) == histos[histoTag].end()) bookHistos((*ch_it)->id(),string("NoiseAverage"), histoTag );
189  histos[histoTag].find((*ch_it)->id().rawId())->second->setBinContent(slID.superLayer(),noiseStatistics);
190 
191  for ( vector<DTWireId>::const_iterator nb_it = theNoisyChannels.begin();
192  nb_it != theNoisyChannels.end(); ++nb_it) {
193 
194  bool isNoisy = false;
195  bool isFEMasked = false;
196  bool isTDCMasked = false;
197  bool isTrigMask = false;
198  bool isDead = false;
199  bool isNohv = false;
200  statusMap->cellStatus((*nb_it), isNoisy, isFEMasked, isTDCMasked, isTrigMask, isDead, isNohv);
201 
202  if (!isNoisy) newNoiseChannels++;
203  }
204  theNoisyChannels.clear();
205  histoTag = "NewNoisyChannels";
206  if (histos[histoTag].find((*ch_it)->id().rawId()) == histos[histoTag].end()) bookHistos((*ch_it)->id(),string("NewNoisyChannels"), histoTag );
207  histos[histoTag].find((*ch_it)->id().rawId())->second->setBinContent(slID.superLayer(), newNoiseChannels);
208  }
209  }
210  //To compute the Noise Mean test
211  vector<const DTSuperLayer*>::const_iterator sl2_it = (*ch_it)->superLayers().begin();
212  vector<const DTSuperLayer*>::const_iterator sl2_end = (*ch_it)->superLayers().end();
213  for(; sl2_it != sl2_end; ++sl2_it) {
214  vector<const DTLayer*>::const_iterator l_it = (*sl2_it)->layers().begin();
215  vector<const DTLayer*>::const_iterator l_end = (*sl2_it)->layers().end();
216  for(; l_it != l_end; ++l_it) {
217 
218  DTLayerId lID = (*l_it)->id();
219  MonitorElement * noisePerEventME = dbe->get(getMEName(lID));
220 
221  if (noisePerEventME) {
222  TH2F * noiseHistoPerEvent = noisePerEventME->getTH2F();
223  int nWires = muonGeom->layer(lID)->specificTopology().channels();
224  double MeanNumerator=0, MeanDenominator=0;
225  histoTag = "MeanDigiPerEvent";
226  for (int w=1; w<=nWires; w++){
227  for(int numDigi=1; numDigi<=10; numDigi++){
228  MeanNumerator+=(noiseHistoPerEvent->GetBinContent(w,numDigi)*(numDigi-1));
229  MeanDenominator+=noiseHistoPerEvent->GetBinContent(w,numDigi);
230  }
231  double Mean=MeanNumerator/MeanDenominator;
232  if (histos[histoTag].find((*l_it)->id().rawId()) == histos[histoTag].end()) bookHistos((*l_it)->id(),nWires, string("MeanDigiPerEvent"), histoTag );
233  histos[histoTag].find((*l_it)->id().rawId())->second->setBinContent(w, Mean);
234  }
235  }
236  }
237  }
238  }
239 
240  // Noise Mean test
241  histoTag = "MeanDigiPerEvent";
242  string MeanCriterionName = parameters.getUntrackedParameter<string>("meanTestName","NoiseMeanInRange");
243  for(map<uint32_t, MonitorElement*>::const_iterator hMean = histos[histoTag].begin();
244  hMean != histos[histoTag].end();
245  hMean++) {
246  const QReport * theMeanQReport = (*hMean).second->getQReport(MeanCriterionName);
247  if(theMeanQReport) {
248  vector<dqm::me_util::Channel> badChannels = theMeanQReport->getBadChannels();
249  for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin();
250  channel != badChannels.end(); channel++) {
251  LogVerbatim ("tTrigCalibration")<<"LayerId : "<<(*hMean).first<<" Bad mean channels: "<<(*channel).getBin()<<" Contents : "<<(*channel).getContents();
252  // FIXME: getMessage() sometimes returns and invalid string (null pointer inside QReport data member)
253  // LogVerbatim ("tTrigCalibration") << "-------- LayerId : "<<(*hMean).first<<" "<<theMeanQReport->getMessage()<<" ------- "<<theMeanQReport->getStatus();
254  }
255  }
256  }
257 
258 }
259 
260 
261 
263 
264  edm::LogVerbatim ("noise") <<"[DTNoiseTest] endjob called!";
265 
266  //if ( parameters.getUntrackedParameter<bool>("writeHisto", true) )
267  // dbe->save(parameters.getUntrackedParameter<string>("outputFile", "DTNoiseTest.root"));
268 
269  dbe->rmdir("DT/Tests/Noise");
270 }
271 
272 
274 
275  stringstream wheel; wheel << ch.wheel();
276  stringstream station; station << ch.station();
277  stringstream sector; sector << ch.sector();
278 
279  string folderRoot = parameters.getUntrackedParameter<string>("folderRoot", "Collector/FU0/");
280  string folderTag = parameters.getUntrackedParameter<string>("folderTag", "Occupancies");
281  string folderName =
282  folderRoot + "DT/DTDigiTask/Wheel" + wheel.str() +
283  "/Station" + station.str() +
284  "/Sector" + sector.str() + "/" + folderTag + "/";
285 
286  string histoTag = parameters.getUntrackedParameter<string>("histoTag", "OccupancyNoise_perCh");
287  string histoname = folderName + histoTag
288  + "_W" + wheel.str()
289  + "_St" + station.str()
290  + "_Sec" + sector.str();
291 
292 
293  return histoname;
294 
295 }
296 
297 string DTNoiseTest::getMEName(const DTLayerId & ly) {
298 
299  stringstream wheel; wheel << ly.wheel();
300  stringstream station; station << ly.station();
301  stringstream sector; sector << ly.sector();
302  stringstream superLayer; superLayer << ly.superlayer();
303  stringstream layer; layer << ly.layer();
304 
305  string folderRoot = parameters.getUntrackedParameter<string>("folderRoot", "Collector/FU0/");
306  string folderTag = parameters.getUntrackedParameter<string>("folderTagForDigiPerEventTest", "DigiPerEvent");
307  string folderName =
308  folderRoot + "DT/DTDigiForNoiseTask/Wheel" + wheel.str() +
309  "/Station" + station.str() +
310  "/Sector" + sector.str() + "/" + folderTag + "/";
311 
312  string histoTag = parameters.getUntrackedParameter<string>("histoTagForDigiPerEventTest", "DigiPerEvent");
313  string histoname = folderName + histoTag
314  + "_W" + wheel.str()
315  + "_St" + station.str()
316  + "_Sec" + sector.str()
317  + "_SL" + superLayer.str()
318  + "_L" + layer.str();
319 
320 
321  return histoname;
322 
323 }
324 
325 
326 void DTNoiseTest::bookHistos(const DTChamberId & ch, string folder, string histoTag ) {
327 
328  stringstream wheel; wheel << ch.wheel();
329  stringstream station; station << ch.station();
330  stringstream sector; sector << ch.sector();
331 
332  dbe->setCurrentFolder("DT/Tests/Noise/" + folder);
333 
334  string histoName = histoTag + "W" + wheel.str() + "_St" + station.str() + "_Sec" + sector.str();
335 
336  if (folder == "NoiseAverage")
337  (histos[histoTag])[ch.rawId()] = dbe->book1D(histoName.c_str(),histoName.c_str(),3,0,3);
338 
339  if ( folder == "NewNoisyChannels")
340  (histos[histoTag])[ch.rawId()] = dbe->book1D(histoName.c_str(),histoName.c_str(),3,0,3);
341 
342 }
343 
344 
345 void DTNoiseTest::bookHistos(const DTLayerId & lId, int nWires, string folder, string histoTag) {
346 
347  stringstream wheel; wheel << lId.superlayerId().wheel();
348  stringstream station; station << lId.superlayerId().station();
349  stringstream sector; sector << lId.superlayerId().sector();
350  stringstream superLayer; superLayer << lId.superlayerId().superlayer();
351  stringstream layer; layer << lId.layer();
352 
353  string histoName = histoTag + "_W" + wheel.str() + "_St" + station.str() + "_Sec" + sector.str() + "_SL" + superLayer.str() + "_L" + layer.str();
354 
355  dbe->setCurrentFolder("DT/Tests/Noise/" + folder +
356  "/Wheel" + wheel.str() +
357  "/Station" + station.str() +
358  "/Sector" + sector.str());
359 
360  (histos[histoTag])[lId.rawId()] = dbe->book1D(histoName.c_str(),histoName.c_str(),nWires,0,nWires);
361 
362 }
LuminosityBlockID id() const
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
Definition: DTNoiseTest.cc:91
dictionary parameters
Definition: Parameters.py:2
void beginRun(const edm::Run &r, const edm::EventSetup &c)
BeginRun.
Definition: DTNoiseTest.cc:70
DTNoiseTest(const edm::ParameterSet &ps)
Constructor.
Definition: DTNoiseTest.cc:38
int layer() const
Return the layer number.
Definition: DTLayerId.h:55
void beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &context)
Definition: DTNoiseTest.cc:81
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:61
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
void bookHistos()
Definition: Histogram.h:33
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
U second(std::pair< T, U > const &p)
int superLayer() const
Return the superlayer number.
RunNumber_t run() const
int nevents
#define end
Definition: vmac.h:38
const std::vector< DQMChannel > & getBadChannels(void) const
Definition: QReport.h:33
int superlayer() const
Return the superlayer number (deprecated method name)
void bookHistos(const DTChamberId &ch, std::string folder, std::string histoTag)
book the new ME
virtual ~DTNoiseTest()
Destructor.
Definition: DTNoiseTest.cc:53
const T & get() const
Definition: EventSetup.h:55
LuminosityBlockNumber_t luminosityBlock() const
int average
Definition: PDRates.py:137
#define begin
Definition: vmac.h:31
int sector() const
Definition: DTChamberId.h:63
void beginJob()
BeginJob.
Definition: DTNoiseTest.cc:61
std::string getMEName(const DTChamberId &ch)
Get the ME name.
Definition: DTNoiseTest.cc:273
int station() const
Return the station number.
Definition: DTChamberId.h:53
TH2F * getTH2F(void) const
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:47
void endJob()
Endjob.
Definition: DTNoiseTest.cc:262
Definition: Run.h:33
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &c)
DQM Client Diagnostic.
Definition: DTNoiseTest.cc:99
T w() const