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