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  * threadsafe version (//-) oct/nov 2014 - WATWanAbdullah -ncpp-um-my
9  *
10  *
11  */
12 
14 
15 // Framework
17 
18 
19 // Geometry
24 
25 
29 
30 #include <stdio.h>
31 #include <sstream>
32 #include <math.h>
33 
34 using namespace edm;
35 using namespace std;
36 
37 
38 
40 
41  edm::LogVerbatim ("noise") <<"[DTNoiseTest]: Constructor";
42 
43  parameters = ps;
44 
45  prescaleFactor = parameters.getUntrackedParameter<int>("diagnosticPrescale", 1);
46 
47  bookingdone = 0;
48 
49 }
50 
51 
52 
54 
55  edm::LogVerbatim ("noise") <<"DTNoiseTest: analyzed " << updates << " events";
56 
57 }
58 
60  edm::LuminosityBlock const & lumiSeg, edm::EventSetup const & context) {
61 
62  if (!bookingdone) {
63  ibooker.setCurrentFolder("DT/Tests/Noise");
64  updates = 0;
65  // Get the geometry
66  context.get<MuonGeometryRecord>().get(muonGeom);
67  }
68  bookingdone = 1;
69 
70  edm::LogVerbatim ("noise") <<"[DTNoiseTest]: End of LS transition, performing the DQM client operation";
71 
72  // counts number of lumiSegs
73  nLumiSegs = lumiSeg.id().luminosityBlock();
74 
75  // prescale factor
76  if ( nLumiSegs%prescaleFactor != 0 ) return;
77 
78  edm::LogVerbatim ("noise") <<"[DTNoiseTest]: "<<nLumiSegs<<" updates";
79 
81  context.get<DTStatusFlagRcd>().get(statusMap);
82 
83  context.get<DTTtrigRcd>().get(tTrigMap);
84  float tTrig, tTrigRMS, kFactor;
85 
86  string histoTag;
87  // loop over chambers
88  vector<const DTChamber*>::const_iterator ch_it = muonGeom->chambers().begin();
89  vector<const DTChamber*>::const_iterator ch_end = muonGeom->chambers().end();
90 
91  for (; ch_it != ch_end; ++ch_it) {
92  DTChamberId ch = (*ch_it)->id();
93  vector<const DTSuperLayer*>::const_iterator sl_it = (*ch_it)->superLayers().begin();
94  vector<const DTSuperLayer*>::const_iterator sl_end = (*ch_it)->superLayers().end();
95 
96  MonitorElement * noiseME = igetter.get(getMEName(ch));
97  if (noiseME) {
98  TH2F * noiseHisto = noiseME->getTH2F();
99 
100  // WARNING uncorrect normalization!! TO BE PROVIDED CENTRALLY
101  double nevents = (int) noiseHisto->GetEntries();
102 
103  double normalization =0;
104 
105  float average=0;
106  float nOfChannels=0;
107  float noiseStatistics=0;
108  int newNoiseChannels=0;
109 
110  for(; sl_it != sl_end; ++sl_it) {
111  const DTSuperLayerId & slID = (*sl_it)->id();
112 
113  // ttrig and rms are counts
114  tTrigMap->get(slID, tTrig, tTrigRMS, kFactor, DTTimeUnits::counts);
115  if (tTrig==0) tTrig=1;
116  const double ns_s = 1e9*(32/25);
117  normalization = ns_s/float(tTrig*nevents);
118 
119  noiseHisto->Scale(normalization);
120 
121  // loop over layers
122 
123  for (int binY=(slID.superLayer()-1)*4+1 ; binY <= (slID.superLayer()-1)*4+4; binY++) {
124 
125  int Y = binY - 4*(slID.superLayer()-1);
126 
127  // the layer
128 
129  const DTLayerId theLayer(slID,Y);
130 
131  // loop over channels
132  for (int binX=1; binX <= noiseHisto->GetNbinsX(); binX++) {
133 
134  if (noiseHisto->GetBinContent(binX,binY) > parameters.getUntrackedParameter<int>("HzThreshold", 300))
135  theNoisyChannels.push_back(DTWireId(theLayer, binX));
136 
137  // get rid of the dead channels
138  else {
139  average += noiseHisto->GetBinContent(binX,binY);
140  nOfChannels++;
141  }
142  }
143  }
144 
145  if (nOfChannels) noiseStatistics = average/nOfChannels;
146  histoTag = "NoiseAverage";
147 
148  if (histos[histoTag].find((*ch_it)->id().rawId()) == histos[histoTag].end()) bookHistos(ibooker,(*ch_it)->id(),string("NoiseAverage"), histoTag );
149  histos[histoTag].find((*ch_it)->id().rawId())->second->setBinContent(slID.superLayer(),noiseStatistics);
150 
151  for ( vector<DTWireId>::const_iterator nb_it = theNoisyChannels.begin();
152  nb_it != theNoisyChannels.end(); ++nb_it) {
153 
154  bool isNoisy = false;
155  bool isFEMasked = false;
156  bool isTDCMasked = false;
157  bool isTrigMask = false;
158  bool isDead = false;
159  bool isNohv = false;
160  statusMap->cellStatus((*nb_it), isNoisy, isFEMasked, isTDCMasked, isTrigMask, isDead, isNohv);
161 
162  if (!isNoisy) newNoiseChannels++;
163  }
164  theNoisyChannels.clear();
165  histoTag = "NewNoisyChannels";
166 
167  if (histos[histoTag].find((*ch_it)->id().rawId()) == histos[histoTag].end())
168  bookHistos(ibooker,(*ch_it)->id(),string("NewNoisyChannels"), histoTag );
169  histos[histoTag].find((*ch_it)->id().rawId())->second->setBinContent(slID.superLayer(), newNoiseChannels);
170  }
171  }
172  //To compute the Noise Mean test
173  vector<const DTSuperLayer*>::const_iterator sl2_it = (*ch_it)->superLayers().begin();
174  vector<const DTSuperLayer*>::const_iterator sl2_end = (*ch_it)->superLayers().end();
175  for(; sl2_it != sl2_end; ++sl2_it) {
176  vector<const DTLayer*>::const_iterator l_it = (*sl2_it)->layers().begin();
177  vector<const DTLayer*>::const_iterator l_end = (*sl2_it)->layers().end();
178  for(; l_it != l_end; ++l_it) {
179 
180  DTLayerId lID = (*l_it)->id();
181  MonitorElement * noisePerEventME = igetter.get(getMEName(lID));
182 
183  if (noisePerEventME) {
184  TH2F * noiseHistoPerEvent = noisePerEventME->getTH2F();
185  int nWires = muonGeom->layer(lID)->specificTopology().channels();
186  double MeanNumerator=0, MeanDenominator=0;
187  histoTag = "MeanDigiPerEvent";
188  for (int w=1; w<=nWires; w++){
189  for(int numDigi=1; numDigi<=10; numDigi++){
190  MeanNumerator+=(noiseHistoPerEvent->GetBinContent(w,numDigi)*(numDigi-1));
191  MeanDenominator+=noiseHistoPerEvent->GetBinContent(w,numDigi);
192  }
193  double Mean=MeanNumerator/MeanDenominator;
194  if (histos[histoTag].find((*l_it)->id().rawId()) == histos[histoTag].end()) bookHistos(ibooker,(*l_it)->id(),nWires, string("MeanDigiPerEvent"), histoTag );
195  histos[histoTag].find((*l_it)->id().rawId())->second->setBinContent(w, Mean);
196  }
197  }
198  }
199  }
200  }
201 
202  // Noise Mean test
203  histoTag = "MeanDigiPerEvent";
204  string MeanCriterionName = parameters.getUntrackedParameter<string>("meanTestName","NoiseMeanInRange");
205  for(map<uint32_t, MonitorElement*>::const_iterator hMean = histos[histoTag].begin();
206  hMean != histos[histoTag].end();
207  hMean++) {
208  const QReport * theMeanQReport = (*hMean).second->getQReport(MeanCriterionName);
209  if(theMeanQReport) {
210  vector<dqm::me_util::Channel> badChannels = theMeanQReport->getBadChannels();
211  for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin();
212  channel != badChannels.end(); channel++) {
213  LogVerbatim ("tTrigCalibration")<<"LayerId : "<<(*hMean).first<<" Bad mean channels: "
214  <<(*channel).getBin()<<" Contents : "<<(*channel).getContents();
215  }
216  }
217  }
218 
219 }
220 
222 
223  edm::LogVerbatim ("noise") <<"[DTNoiseTest] endjob called!";
224 }
225 
226 
228 
229  stringstream wheel; wheel << ch.wheel();
230  stringstream station; station << ch.station();
231  stringstream sector; sector << ch.sector();
232 
233  string folderRoot = parameters.getUntrackedParameter<string>("folderRoot", "Collector/FU0/");
234  string folderTag = parameters.getUntrackedParameter<string>("folderTag", "Occupancies");
235  string folderName =
236  folderRoot + "DT/DTDigiTask/Wheel" + wheel.str() +
237  "/Station" + station.str() +
238  "/Sector" + sector.str() + "/" + folderTag + "/";
239 
240  string histoTag = parameters.getUntrackedParameter<string>("histoTag", "OccupancyNoise_perCh");
241  string histoname = folderName + histoTag
242  + "_W" + wheel.str()
243  + "_St" + station.str()
244  + "_Sec" + sector.str();
245 
246 
247  return histoname;
248 
249 }
250 
251 string DTNoiseTest::getMEName(const DTLayerId & ly) {
252 
253  stringstream wheel; wheel << ly.wheel();
254  stringstream station; station << ly.station();
255  stringstream sector; sector << ly.sector();
256  stringstream superLayer; superLayer << ly.superlayer();
257  stringstream layer; layer << ly.layer();
258 
259  string folderRoot = parameters.getUntrackedParameter<string>("folderRoot", "Collector/FU0/");
260  string folderTag = parameters.getUntrackedParameter<string>("folderTagForDigiPerEventTest", "DigiPerEvent");
261  string folderName =
262  folderRoot + "DT/DTDigiForNoiseTask/Wheel" + wheel.str() +
263  "/Station" + station.str() +
264  "/Sector" + sector.str() + "/" + folderTag + "/";
265 
266  string histoTag = parameters.getUntrackedParameter<string>("histoTagForDigiPerEventTest", "DigiPerEvent");
267  string histoname = folderName + histoTag
268  + "_W" + wheel.str()
269  + "_St" + station.str()
270  + "_Sec" + sector.str()
271  + "_SL" + superLayer.str()
272  + "_L" + layer.str();
273 
274 
275  return histoname;
276 
277 }
278 
279 void DTNoiseTest::bookHistos(DQMStore::IBooker & ibooker, const DTChamberId & ch, string folder, string histoTag ) {
280 
281  stringstream wheel; wheel << ch.wheel();
282  stringstream station; station << ch.station();
283  stringstream sector; sector << ch.sector();
284 
285  ibooker.setCurrentFolder("DT/Tests/Noise/" + folder);
286 
287  string histoName = histoTag + "W" + wheel.str() + "_St" + station.str() + "_Sec" + sector.str();
288 
289  if (folder == "NoiseAverage")
290  (histos[histoTag])[ch.rawId()] = ibooker.book1D(histoName.c_str(),histoName.c_str(),3,0,3);
291 
292  if ( folder == "NewNoisyChannels")
293  (histos[histoTag])[ch.rawId()] = ibooker.book1D(histoName.c_str(),histoName.c_str(),3,0,3);
294 
295 }
296 
297 void DTNoiseTest::bookHistos(DQMStore::IBooker & ibooker, const DTLayerId & lId, int nWires, string folder, string histoTag) {
298 
299  stringstream wheel; wheel << lId.superlayerId().wheel();
300  stringstream station; station << lId.superlayerId().station();
301  stringstream sector; sector << lId.superlayerId().sector();
302  stringstream superLayer; superLayer << lId.superlayerId().superlayer();
303  stringstream layer; layer << lId.layer();
304 
305  string histoName = histoTag + "_W" + wheel.str() + "_St" + station.str() + "_Sec" + sector.str()
306  + "_SL" + superLayer.str() + "_L" + layer.str();
307 
308  ibooker.setCurrentFolder("DT/Tests/Noise/" + folder +
309  "/Wheel" + wheel.str() +
310  "/Station" + station.str() +
311  "/Sector" + sector.str());
312 
313  (histos[histoTag])[lId.rawId()] = ibooker.book1D(histoName.c_str(),histoName.c_str(),nWires,0,nWires);
314 }
void bookHistos(DQMStore::IBooker &, const DTChamberId &ch, std::string folder, std::string histoTag)
book the new ME
LuminosityBlockID id() const
dictionary parameters
Definition: Parameters.py:2
void dqmEndLuminosityBlock(DQMStore::IBooker &, DQMStore::IGetter &, edm::LuminosityBlock const &, edm::EventSetup const &)
DQM Client Diagnostic.
Definition: DTNoiseTest.cc:59
const double w
Definition: UKUtility.cc:23
MonitorElement * get(const std::string &path)
Definition: DQMStore.cc:302
DTNoiseTest(const edm::ParameterSet &ps)
Constructor.
Definition: DTNoiseTest.cc:39
int layer() const
Return the layer number.
Definition: DTLayerId.h:53
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)
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
int superLayer() const
Return the superlayer number.
#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 setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
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:30
int sector() const
Definition: DTChamberId.h:61
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
Definition: DTNoiseTest.cc:221
std::string getMEName(const DTChamberId &ch)
Get the ME name.
Definition: DTNoiseTest.cc:227
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