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: 2008/12/13 10:02:28 $
4  * $Revision: 1.20 $
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  DTSuperLayerId slID = (*sl2_it)->id();
215  vector<const DTLayer*>::const_iterator l_it = (*sl2_it)->layers().begin();
216  vector<const DTLayer*>::const_iterator l_end = (*sl2_it)->layers().end();
217  for(; l_it != l_end; ++l_it) {
218 
219  DTLayerId lID = (*l_it)->id();
220  MonitorElement * noisePerEventME = dbe->get(getMEName(lID));
221 
222  if (noisePerEventME) {
223  TH2F * noiseHistoPerEvent = noisePerEventME->getTH2F();
224  int nWires = muonGeom->layer(lID)->specificTopology().channels();
225  double MeanNumerator=0, MeanDenominator=0;
226  histoTag = "MeanDigiPerEvent";
227  for (int w=1; w<=nWires; w++){
228  for(int numDigi=1; numDigi<=10; numDigi++){
229  MeanNumerator+=(noiseHistoPerEvent->GetBinContent(w,numDigi)*(numDigi-1));
230  MeanDenominator+=noiseHistoPerEvent->GetBinContent(w,numDigi);
231  }
232  double Mean=MeanNumerator/MeanDenominator;
233  if (histos[histoTag].find((*l_it)->id().rawId()) == histos[histoTag].end()) bookHistos((*l_it)->id(),nWires, string("MeanDigiPerEvent"), histoTag );
234  histos[histoTag].find((*l_it)->id().rawId())->second->setBinContent(w, Mean);
235  }
236  }
237  }
238  }
239  }
240 
241  // Noise Mean test
242  histoTag = "MeanDigiPerEvent";
243  string MeanCriterionName = parameters.getUntrackedParameter<string>("meanTestName","NoiseMeanInRange");
244  for(map<uint32_t, MonitorElement*>::const_iterator hMean = histos[histoTag].begin();
245  hMean != histos[histoTag].end();
246  hMean++) {
247  const QReport * theMeanQReport = (*hMean).second->getQReport(MeanCriterionName);
248  if(theMeanQReport) {
249  vector<dqm::me_util::Channel> badChannels = theMeanQReport->getBadChannels();
250  for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin();
251  channel != badChannels.end(); channel++) {
252  LogVerbatim ("tTrigCalibration")<<"LayerId : "<<(*hMean).first<<" Bad mean channels: "<<(*channel).getBin()<<" Contents : "<<(*channel).getContents();
253  // FIXME: getMessage() sometimes returns and invalid string (null pointer inside QReport data member)
254  // LogVerbatim ("tTrigCalibration") << "-------- LayerId : "<<(*hMean).first<<" "<<theMeanQReport->getMessage()<<" ------- "<<theMeanQReport->getStatus();
255  }
256  }
257  }
258 
259 }
260 
261 
262 
264 
265  edm::LogVerbatim ("noise") <<"[DTNoiseTest] endjob called!";
266 
267  //if ( parameters.getUntrackedParameter<bool>("writeHisto", true) )
268  // dbe->save(parameters.getUntrackedParameter<string>("outputFile", "DTNoiseTest.root"));
269 
270  dbe->rmdir("DT/Tests/Noise");
271 }
272 
273 
275 
276  stringstream wheel; wheel << ch.wheel();
277  stringstream station; station << ch.station();
278  stringstream sector; sector << ch.sector();
279 
280  string folderRoot = parameters.getUntrackedParameter<string>("folderRoot", "Collector/FU0/");
281  string folderTag = parameters.getUntrackedParameter<string>("folderTag", "Occupancies");
282  string folderName =
283  folderRoot + "DT/DTDigiTask/Wheel" + wheel.str() +
284  "/Station" + station.str() +
285  "/Sector" + sector.str() + "/" + folderTag + "/";
286 
287  string histoTag = parameters.getUntrackedParameter<string>("histoTag", "OccupancyNoise_perCh");
288  string histoname = folderName + histoTag
289  + "_W" + wheel.str()
290  + "_St" + station.str()
291  + "_Sec" + sector.str();
292 
293 
294  return histoname;
295 
296 }
297 
298 string DTNoiseTest::getMEName(const DTLayerId & ly) {
299 
300  stringstream wheel; wheel << ly.wheel();
301  stringstream station; station << ly.station();
302  stringstream sector; sector << ly.sector();
303  stringstream superLayer; superLayer << ly.superlayer();
304  stringstream layer; layer << ly.layer();
305 
306  string folderRoot = parameters.getUntrackedParameter<string>("folderRoot", "Collector/FU0/");
307  string folderTag = parameters.getUntrackedParameter<string>("folderTagForDigiPerEventTest", "DigiPerEvent");
308  string folderName =
309  folderRoot + "DT/DTDigiForNoiseTask/Wheel" + wheel.str() +
310  "/Station" + station.str() +
311  "/Sector" + sector.str() + "/" + folderTag + "/";
312 
313  string histoTag = parameters.getUntrackedParameter<string>("histoTagForDigiPerEventTest", "DigiPerEvent");
314  string histoname = folderName + histoTag
315  + "_W" + wheel.str()
316  + "_St" + station.str()
317  + "_Sec" + sector.str()
318  + "_SL" + superLayer.str()
319  + "_L" + layer.str();
320 
321 
322  return histoname;
323 
324 }
325 
326 
327 void DTNoiseTest::bookHistos(const DTChamberId & ch, string folder, string histoTag ) {
328 
329  stringstream wheel; wheel << ch.wheel();
330  stringstream station; station << ch.station();
331  stringstream sector; sector << ch.sector();
332 
333  dbe->setCurrentFolder("DT/Tests/Noise/" + folder);
334 
335  string histoName = histoTag + "W" + wheel.str() + "_St" + station.str() + "_Sec" + sector.str();
336 
337  if (folder == "NoiseAverage")
338  (histos[histoTag])[ch.rawId()] = dbe->book1D(histoName.c_str(),histoName.c_str(),3,0,3);
339 
340  if ( folder == "NewNoisyChannels")
341  (histos[histoTag])[ch.rawId()] = dbe->book1D(histoName.c_str(),histoName.c_str(),3,0,3);
342 
343 }
344 
345 
346 void DTNoiseTest::bookHistos(const DTLayerId & lId, int nWires, string folder, string histoTag) {
347 
348  stringstream wheel; wheel << lId.superlayerId().wheel();
349  stringstream station; station << lId.superlayerId().station();
350  stringstream sector; sector << lId.superlayerId().sector();
351  stringstream superLayer; superLayer << lId.superlayerId().superlayer();
352  stringstream layer; layer << lId.layer();
353 
354  string histoName = histoTag + "_W" + wheel.str() + "_St" + station.str() + "_Sec" + sector.str() + "_SL" + superLayer.str() + "_L" + layer.str();
355 
356  dbe->setCurrentFolder("DT/Tests/Noise/" + folder +
357  "/Wheel" + wheel.str() +
358  "/Station" + station.str() +
359  "/Sector" + sector.str());
360 
361  (histos[histoTag])[lId.rawId()] = dbe->book1D(histoName.c_str(),histoName.c_str(),nWires,0,nWires);
362 
363 }
LuminosityBlockID id() const
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
Definition: DTNoiseTest.cc:91
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
dictionary histos
Definition: combine.py:3
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:274
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:263
Definition: Run.h:31
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &c)
DQM Client Diagnostic.
Definition: DTNoiseTest.cc:99