CMS 3D CMS Logo

DTNoiseAnalysisTest.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author G. Mila - INFN Torino
5  *
6  * threadsafe version (//-) oct/nov 2014 - WATWanAbdullah -ncpp-um-my
7  *
8  */
9 
11 
12 // Framework
16 
17 // Geometry
22 
25 
26 #include <iostream>
27 #include <sstream>
28 
29 using namespace edm;
30 using namespace std;
31 
33  : muonGeomToken_(esConsumes<edm::Transition::BeginRun>()) {
34  LogTrace("DTDQM|DTMonitorClient|DTNoiseAnalysisTest") << "[DTNoiseAnalysisTest]: Constructor";
35 
36  // get the cfi parameters
37  noisyCellDef = ps.getUntrackedParameter<int>("noisyCellDef",
38  500); //value set in DQM/DTMonitorClient/python/dtNoiseAnalysis_cfi.py
39  isCosmics = ps.getUntrackedParameter<bool>("isCosmics", false);
40 
41  // switch on/off the summaries for the Synchronous noise
42  doSynchNoise = ps.getUntrackedParameter<bool>("doSynchNoise", false);
43  detailedAnalysis = ps.getUntrackedParameter<bool>("detailedAnalysis", false);
44  maxSynchNoiseRate = ps.getUntrackedParameter<double>("maxSynchNoiseRate", 0.001);
45  noiseSafetyFactor = ps.getUntrackedParameter<double>("noiseSafetyFactor", 5.); //for collisions
46  nMinEvts = ps.getUntrackedParameter<int>("nEventsCert", 5000);
47 
48  nevents = 0;
49 
50  bookingdone = false;
51 }
52 
54  LogTrace("DTDQM|DTMonitorClient|DTNoiseAnalysisTest") << "DTNoiseAnalysisTest: analyzed " << nevents << " events";
55 }
56 
58  // Get the geometry
59  muonGeom = &context.getData(muonGeomToken_);
60 }
61 
63  DQMStore::IGetter& igetter,
64  edm::LuminosityBlock const& lumiSeg,
65  edm::EventSetup const& context) {
66  float chRate;
67 
68  if (!bookingdone) {
69  // book the histos
70  bookHistos(ibooker);
71  }
72  bookingdone = true;
73 
74  LogVerbatim("DTDQM|DTMonitorClient|DTNoiseAnalysisTest")
75  << "[DTNoiseAnalysisTest]: End of LS transition, performing the DQM client operation";
76 
77  // Reset the summary plots
78  for (map<int, MonitorElement*>::iterator plot = noiseHistos.begin(); plot != noiseHistos.end(); ++plot) {
79  (*plot).second->Reset();
80  }
81 
82  for (map<int, MonitorElement*>::iterator plot = noisyCellHistos.begin(); plot != noisyCellHistos.end(); ++plot) {
83  (*plot).second->Reset();
84  }
85 
87 
88  vector<const DTChamber*>::const_iterator ch_it = muonGeom->chambers().begin();
89  vector<const DTChamber*>::const_iterator ch_end = muonGeom->chambers().end();
90 
91  LogTrace("DTDQM|DTMonitorClient|DTNoiseAnalysisTest") << "[DTNoiseAnalysisTest]: Fill the summary histos";
92 
93  for (; ch_it != ch_end; ++ch_it) { // loop over chambers
94  DTChamberId chID = (*ch_it)->id();
95 
96  MonitorElement* histo = igetter.get(getMEName(chID));
97 
98  if (histo) { // check the pointer
99 
100  TH2D* histo_root = histo->getTH2D();
101 
102  for (int sl = 1; sl != 4; ++sl) { // loop over SLs
103  // skip theta SL in MB4 chambers
104  if (chID.station() == 4 && sl == 2)
105  continue;
106 
107  int binYlow = ((sl - 1) * 4) + 1;
108 
109  for (int layer = 1; layer <= 4; ++layer) { // loop over layers
110 
111  // Get the layer ID
112  DTLayerId layID(chID, sl, layer);
113 
114  int nWires = muonGeom->layer(layID)->specificTopology().channels();
115  int firstWire = muonGeom->layer(layID)->specificTopology().firstChannel();
116 
117  int binY = binYlow + (layer - 1);
118 
119  for (int wire = firstWire; wire != (nWires + firstWire); wire++) { // loop over wires
120 
121  double noise = histo_root->GetBinContent(wire, binY);
122  // fill the histos
123  noiseHistos[chID.wheel()]->Fill(noise);
124  noiseHistos[3]->Fill(noise);
125  int sector = chID.sector();
126 
127  if (!isCosmics) { // for collisions
128  float k = kW_MB[2 - abs(chID.wheel())][chID.station() - 1];
129  if (chID.station() == 4) { //special geometry cases for MB4
130  if (sector == 9 || sector == 10 || sector == 11)
131  k = 0.05;
132  else if (sector == 4 && chID.wheel() == 0)
133  k = 0.25;
134  }
135  noisyCellDef =
136  cellW * instLumi * k * lenghtSL_MB[(sl % 2)][chID.station() - 1]; // background expected per chamber
138  } //else value read from DQM/DTMonitorClient/python/dtNoiseAnalysis_cfi.py
139 
140  if (noise > noisyCellDef) {
141  if (sector == 13) {
142  sector = 4;
143  } else if (sector == 14) {
144  sector = 10;
145  }
146  noisyCellHistos[chID.wheel()]->Fill(sector, chID.station());
148  }
149  }
150  }
151  }
152  }
153  }
154 
155  if (detailedAnalysis) {
157  TH1F* histo = noiseHistos[3]->getTH1F();
158  for (int step = 0; step != 15; step++) {
159  int threshBin = step + 1;
160  int minBin = 26 + step * 5;
161  int nNoisyCh = histo->Integral(minBin, 101);
162  threshChannelsHisto->setBinContent(threshBin, nNoisyCh);
163  }
164  }
165 
166  // build the summary of synch noise
167 
168  if (doSynchNoise) {
169  LogTrace("DTDQM|DTMonitorClient|DTNoiseAnalysisTest")
170  << "[DTNoiseAnalysisTest]: fill summaries for synch noise" << endl;
173  for (int wheel = -2; wheel != 3; ++wheel) {
174  // Get the histo produced by DTDigiTask
175 
176  MonitorElement* histoNoiseSynch = igetter.get(getSynchNoiseMEName(wheel));
177  if (histoNoiseSynch != nullptr) {
178  for (int sect = 1; sect != 13; ++sect) { // loop over sectors
179  TH2F* histo = histoNoiseSynch->getTH2F();
180  float maxSectRate = 0;
181  for (int sta = 1; sta != 5; ++sta) {
182  if (nevents > 0)
183  chRate = histo->GetBinContent(sect, sta) / (float)nevents;
184  else
185  chRate = -1.0;
186  // in case nevents 0 e.g. counting not done
187  LogTrace("DTDQM|DTMonitorClient|DTNoiseAnalysisTest")
188  << " Wheel: " << wheel << " sect: " << sect << " station: " << sta << " rate is: " << chRate << endl;
189  if (chRate > maxSectRate)
190  maxSectRate = chRate;
191  }
192  summarySynchNoiseHisto->Fill(sect, wheel, maxSectRate > maxSynchNoiseRate ? 1 : 0);
193  float glbBinValue = 1 - 0.15 * maxSectRate / maxSynchNoiseRate;
194  glbSummarySynchNoiseHisto->Fill(sect, wheel, glbBinValue > 0 ? glbBinValue : 0);
195  }
196  } else {
197  LogWarning("DTDQM|DTMonitorClient|DTNoiseAnalysisTest")
198  << " Histo: " << getSynchNoiseMEName(wheel) << " not found!" << endl;
199  }
200  }
201  }
202 
203  string nEvtsName = "DT/EventInfo/Counters/nProcessedEventsNoise";
204 
205  MonitorElement* meProcEvts = igetter.get(nEvtsName);
206 
207  if (meProcEvts) {
208  int nProcEvts = meProcEvts->getFloatValue();
209  glbSummarySynchNoiseHisto->setEntries(nProcEvts < nMinEvts ? 10. : nProcEvts);
210  summarySynchNoiseHisto->setEntries(nProcEvts < nMinEvts ? 10. : nProcEvts);
211  } else {
214  LogVerbatim("DTDQM|DTMonitorClient|DTnoiseAnalysisTest")
215  << "[DTNoiseAnalysisTest] ME: " << nEvtsName << " not found!" << endl;
216  }
217 }
218 
220  stringstream wheel;
221  wheel << chID.wheel();
222  stringstream station;
223  station << chID.station();
224  stringstream sector;
225  sector << chID.sector();
226 
227  string folderName = "DT/05-Noise/Wheel" + wheel.str() + "/Sector" + sector.str() + "/";
228 
229  string histoname =
230  folderName + string("NoiseRate") + "_W" + wheel.str() + "_St" + station.str() + "_Sec" + sector.str();
231 
232  return histoname;
233 }
234 
236  ibooker.setCurrentFolder("DT/05-Noise");
237  string histoName;
238 
239  for (int wh = -2; wh <= 2; wh++) {
240  stringstream wheel;
241  wheel << wh;
242  histoName = "NoiseRateSummary_W" + wheel.str();
243 
244  noiseHistos[wh] = ibooker.book1D(histoName.c_str(), histoName.c_str(), 500, 0, 10000);
245  noiseHistos[wh]->setAxisTitle("rate (Hz)", 1);
246  noiseHistos[wh]->setAxisTitle("entries", 2);
247  }
248  histoName = "NoiseRateSummary";
249 
250  noiseHistos[3] = ibooker.book1D(histoName.c_str(), histoName.c_str(), 500, 0, 10000);
251  noiseHistos[3]->setAxisTitle("rate (Hz)", 1);
252  noiseHistos[3]->setAxisTitle("entries", 2);
253 
254  for (int wh = -2; wh <= 2; wh++) {
255  stringstream wheel;
256  wheel << wh;
257  histoName = "NoiseSummary_W" + wheel.str();
258 
259  noisyCellHistos[wh] = ibooker.book2D(histoName.c_str(), "# of noisy channels", 12, 1, 13, 4, 1, 5);
260  noisyCellHistos[wh]->setBinLabel(1, "MB1", 2);
261  noisyCellHistos[wh]->setBinLabel(2, "MB2", 2);
262  noisyCellHistos[wh]->setBinLabel(3, "MB3", 2);
263  noisyCellHistos[wh]->setBinLabel(4, "MB4", 2);
264  noisyCellHistos[wh]->setAxisTitle("Sector", 1);
265  }
266 
267  histoName = "NoiseSummary";
268 
269  summaryNoiseHisto = ibooker.book2D(histoName.c_str(), "# of noisy channels", 12, 1, 13, 5, -2, 3);
270  summaryNoiseHisto->setAxisTitle("Sector", 1);
271  summaryNoiseHisto->setAxisTitle("Wheel", 2);
272 
273  if (detailedAnalysis) {
274  histoName = "NoisyChannels";
275 
276  threshChannelsHisto = ibooker.book1D(histoName.c_str(), "# of noisy channels vs threshold", 15, 500, 2000);
277  threshChannelsHisto->setAxisTitle("threshold", 1);
278  threshChannelsHisto->setAxisTitle("# noisy channels", 2);
279  }
280 
281  if (doSynchNoise) {
282  ibooker.setCurrentFolder("DT/05-Noise/SynchNoise/");
283  histoName = "SynchNoiseSummary";
284 
285  summarySynchNoiseHisto = ibooker.book2D(histoName.c_str(), "Summary Synch. Noise", 12, 1, 13, 5, -2, 3);
286  summarySynchNoiseHisto->setAxisTitle("Sector", 1);
288  histoName = "SynchNoiseGlbSummary";
289 
290  glbSummarySynchNoiseHisto = ibooker.book2D(histoName.c_str(), "Summary Synch. Noise", 12, 1, 13, 5, -2, 3);
293  }
294 }
295 
296 string DTNoiseAnalysisTest::getSynchNoiseMEName(int wheelId) const {
297  stringstream wheel;
298  wheel << wheelId;
299  string folderName = "DT/05-Noise/SynchNoise/";
300  string histoname = folderName + string("SyncNoiseEvents") + "_W" + wheel.str();
301 
302  return histoname;
303 }
304 
Log< level::Info, true > LogVerbatim
int station() const
Return the station number.
Definition: DTChamberId.h:45
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
MonitorElement * threshChannelsHisto
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
virtual void setEntries(double nentries)
set # of entries
static constexpr std::array< std::array< float, 4 >, 2 > lenghtSL_MB
void beginRun(edm::Run const &run, edm::EventSetup const &context) override
BeginRun.
std::map< int, MonitorElement * > noisyCellHistos
#define LogTrace(id)
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
T getUntrackedParameter(std::string const &, T const &) const
int firstChannel() const
Returns the wire number of the first wire.
Definition: DTTopology.h:79
void Fill(long long x)
std::string getSynchNoiseMEName(int wheelId) const
virtual TH2F * getTH2F() const
virtual void Reset()
Remove all data from the ME, keept the empty histogram with all its settings.
static constexpr float cellW
virtual double getFloatValue() const
static constexpr std::array< std::array< float, 4 >, 3 > kW_MB
void bookHistos(DQMStore::IBooker &)
book the summary histograms
void dqmEndLuminosityBlock(DQMStore::IBooker &, DQMStore::IGetter &, edm::LuminosityBlock const &, edm::EventSetup const &) override
DQM Client Diagnostic.
static constexpr float instLumi
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Transition
Definition: Transition.h:12
edm::ESGetToken< DTGeometry, MuonGeometryRecord > muonGeomToken_
std::string getMEName(const DTChamberId &chID)
Get the ME name.
const DTTopology & specificTopology() const
Definition: DTLayer.cc:37
virtual void setBinContent(int binx, double content)
set content of bin (1-D)
MonitorElement * summarySynchNoiseHisto
std::map< int, MonitorElement * > noiseHistos
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:221
const DTGeometry * muonGeom
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:712
MonitorElement * glbSummarySynchNoiseHisto
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:42
HLT enums.
int sector() const
Definition: DTChamberId.h:52
~DTNoiseAnalysisTest() override
Destructor.
const std::vector< const DTChamber * > & chambers() const
Return a vector of all Chamber.
Definition: DTGeometry.cc:84
step
Definition: StallMonitor.cc:83
Log< level::Warning, false > LogWarning
MonitorElement * summaryNoiseHisto
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
DTNoiseAnalysisTest(const edm::ParameterSet &ps)
Constructor.
int channels() const
Returns the number of wires in the layer.
Definition: DTTopology.h:76
Definition: Run.h:45
constexpr unsigned int minBin
const DTLayer * layer(const DTLayerId &id) const
Return a layer given its id.
Definition: DTGeometry.cc:96
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)