00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "DQM/DTMonitorClient/src/DTNoiseTest.h"
00013
00014
00015 #include <FWCore/Framework/interface/EventSetup.h>
00016
00017
00018
00019 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00020 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00021 #include "Geometry/DTGeometry/interface/DTLayer.h"
00022 #include "Geometry/DTGeometry/interface/DTTopology.h"
00023
00024
00025 #include "DQMServices/Core/interface/DQMStore.h"
00026 #include "DQMServices/Core/interface/MonitorElement.h"
00027 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00028
00029 #include <stdio.h>
00030 #include <sstream>
00031 #include <math.h>
00032
00033 using namespace edm;
00034 using namespace std;
00035
00036
00037
00038 DTNoiseTest::DTNoiseTest(const edm::ParameterSet& ps){
00039
00040 edm::LogVerbatim ("noise") <<"[DTNoiseTest]: Constructor";
00041
00042 parameters = ps;
00043
00044 dbe = edm::Service<DQMStore>().operator->();
00045 dbe->setCurrentFolder("DT/Tests/Noise");
00046
00047 prescaleFactor = parameters.getUntrackedParameter<int>("diagnosticPrescale", 1);
00048
00049 }
00050
00051
00052
00053 DTNoiseTest::~DTNoiseTest(){
00054
00055 edm::LogVerbatim ("noise") <<"DTNoiseTest: analyzed " << updates << " events";
00056
00057 }
00058
00059
00060
00061 void DTNoiseTest::beginJob(){
00062
00063 edm::LogVerbatim ("noise") <<"[DTNoiseTest]: BeginJob";
00064
00065 updates = 0;
00066
00067 }
00068
00069
00070 void DTNoiseTest::beginRun(const edm::Run& run, const edm::EventSetup& context){
00071
00072 edm::LogVerbatim ("noise") <<"[DTNoiseTest]: BeginRun";
00073
00074
00075 context.get<MuonGeometryRecord>().get(muonGeom);
00076
00077 }
00078
00079
00080
00081 void DTNoiseTest::beginLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context) {
00082
00083 edm::LogVerbatim ("noise") <<"[DTNoiseTest]: Begin of LS transition";
00084
00085
00086 run = lumiSeg.run();
00087
00088 }
00089
00090
00091 void DTNoiseTest::analyze(const edm::Event& e, const edm::EventSetup& context){
00092
00093 updates++;
00094 edm::LogVerbatim ("noise") << "[DTNoiseTest]: "<<updates<<" events";
00095
00096 }
00097
00098
00099 void DTNoiseTest::endLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context) {
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 edm::LogVerbatim ("noise") <<"[DTNoiseTest]: End of LS transition, performing the DQM client operation";
00111
00112
00113 nLumiSegs = lumiSeg.id().luminosityBlock();
00114
00115
00116 if ( nLumiSegs%prescaleFactor != 0 ) return;
00117
00118 edm::LogVerbatim ("noise") <<"[DTNoiseTest]: "<<nLumiSegs<<" updates";
00119
00120 ESHandle<DTStatusFlag> statusMap;
00121 context.get<DTStatusFlagRcd>().get(statusMap);
00122
00123 context.get<DTTtrigRcd>().get(tTrigMap);
00124 float tTrig, tTrigRMS, kFactor;
00125
00126 string histoTag;
00127
00128 vector<DTChamber*>::const_iterator ch_it = muonGeom->chambers().begin();
00129 vector<DTChamber*>::const_iterator ch_end = muonGeom->chambers().end();
00130
00131 for (; ch_it != ch_end; ++ch_it) {
00132 DTChamberId ch = (*ch_it)->id();
00133 vector<const DTSuperLayer*>::const_iterator sl_it = (*ch_it)->superLayers().begin();
00134 vector<const DTSuperLayer*>::const_iterator sl_end = (*ch_it)->superLayers().end();
00135
00136 MonitorElement * noiseME = dbe->get(getMEName(ch));
00137 if (noiseME) {
00138 TH2F * noiseHisto = noiseME->getTH2F();
00139
00140
00141 double nevents = (int) noiseHisto->GetEntries();
00142
00143 double normalization =0;
00144
00145 float average=0;
00146 float nOfChannels=0;
00147 float noiseStatistics=0;
00148 int newNoiseChannels=0;
00149
00150 for(; sl_it != sl_end; ++sl_it) {
00151 const DTSuperLayerId & slID = (*sl_it)->id();
00152
00153
00154 tTrigMap->get(slID, tTrig, tTrigRMS, kFactor, DTTimeUnits::counts);
00155 if (tTrig==0) tTrig=1;
00156 const double ns_s = 1e9*(32/25);
00157 normalization = ns_s/float(tTrig*nevents);
00158
00159 noiseHisto->Scale(normalization);
00160
00161
00162
00163 for (int binY=(slID.superLayer()-1)*4+1 ; binY <= (slID.superLayer()-1)*4+4; binY++) {
00164
00165 int Y = binY - 4*(slID.superLayer()-1);
00166
00167
00168
00169 const DTLayerId theLayer(slID,Y);
00170
00171
00172 for (int binX=1; binX <= noiseHisto->GetNbinsX(); binX++) {
00173
00174 if (noiseHisto->GetBinContent(binX,binY) > parameters.getUntrackedParameter<int>("HzThreshold", 300))
00175 theNoisyChannels.push_back(DTWireId(theLayer, binX));
00176
00177
00178 else {
00179 average += noiseHisto->GetBinContent(binX,binY);
00180 nOfChannels++;
00181 }
00182 }
00183 }
00184
00185 if (nOfChannels) noiseStatistics = average/nOfChannels;
00186 histoTag = "NoiseAverage";
00187
00188 if (histos[histoTag].find((*ch_it)->id().rawId()) == histos[histoTag].end()) bookHistos((*ch_it)->id(),string("NoiseAverage"), histoTag );
00189 histos[histoTag].find((*ch_it)->id().rawId())->second->setBinContent(slID.superLayer(),noiseStatistics);
00190
00191 for ( vector<DTWireId>::const_iterator nb_it = theNoisyChannels.begin();
00192 nb_it != theNoisyChannels.end(); ++nb_it) {
00193
00194 bool isNoisy = false;
00195 bool isFEMasked = false;
00196 bool isTDCMasked = false;
00197 bool isTrigMask = false;
00198 bool isDead = false;
00199 bool isNohv = false;
00200 statusMap->cellStatus((*nb_it), isNoisy, isFEMasked, isTDCMasked, isTrigMask, isDead, isNohv);
00201
00202 if (!isNoisy) newNoiseChannels++;
00203 }
00204 theNoisyChannels.clear();
00205 histoTag = "NewNoisyChannels";
00206 if (histos[histoTag].find((*ch_it)->id().rawId()) == histos[histoTag].end()) bookHistos((*ch_it)->id(),string("NewNoisyChannels"), histoTag );
00207 histos[histoTag].find((*ch_it)->id().rawId())->second->setBinContent(slID.superLayer(), newNoiseChannels);
00208 }
00209 }
00210
00211 vector<const DTSuperLayer*>::const_iterator sl2_it = (*ch_it)->superLayers().begin();
00212 vector<const DTSuperLayer*>::const_iterator sl2_end = (*ch_it)->superLayers().end();
00213 for(; sl2_it != sl2_end; ++sl2_it) {
00214 DTSuperLayerId slID = (*sl2_it)->id();
00215 vector<const DTLayer*>::const_iterator l_it = (*sl2_it)->layers().begin();
00216 vector<const DTLayer*>::const_iterator l_end = (*sl2_it)->layers().end();
00217 for(; l_it != l_end; ++l_it) {
00218
00219 DTLayerId lID = (*l_it)->id();
00220 MonitorElement * noisePerEventME = dbe->get(getMEName(lID));
00221
00222 if (noisePerEventME) {
00223 TH2F * noiseHistoPerEvent = noisePerEventME->getTH2F();
00224 int nWires = muonGeom->layer(lID)->specificTopology().channels();
00225 double MeanNumerator=0, MeanDenominator=0;
00226 histoTag = "MeanDigiPerEvent";
00227 for (int w=1; w<=nWires; w++){
00228 for(int numDigi=1; numDigi<=10; numDigi++){
00229 MeanNumerator+=(noiseHistoPerEvent->GetBinContent(w,numDigi)*(numDigi-1));
00230 MeanDenominator+=noiseHistoPerEvent->GetBinContent(w,numDigi);
00231 }
00232 double Mean=MeanNumerator/MeanDenominator;
00233 if (histos[histoTag].find((*l_it)->id().rawId()) == histos[histoTag].end()) bookHistos((*l_it)->id(),nWires, string("MeanDigiPerEvent"), histoTag );
00234 histos[histoTag].find((*l_it)->id().rawId())->second->setBinContent(w, Mean);
00235 }
00236 }
00237 }
00238 }
00239 }
00240
00241
00242 histoTag = "MeanDigiPerEvent";
00243 string MeanCriterionName = parameters.getUntrackedParameter<string>("meanTestName","NoiseMeanInRange");
00244 for(map<uint32_t, MonitorElement*>::const_iterator hMean = histos[histoTag].begin();
00245 hMean != histos[histoTag].end();
00246 hMean++) {
00247 const QReport * theMeanQReport = (*hMean).second->getQReport(MeanCriterionName);
00248 if(theMeanQReport) {
00249 vector<dqm::me_util::Channel> badChannels = theMeanQReport->getBadChannels();
00250 for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin();
00251 channel != badChannels.end(); channel++) {
00252 LogVerbatim ("tTrigCalibration")<<"LayerId : "<<(*hMean).first<<" Bad mean channels: "<<(*channel).getBin()<<" Contents : "<<(*channel).getContents();
00253
00254
00255 }
00256 }
00257 }
00258
00259 }
00260
00261
00262
00263 void DTNoiseTest::endJob(){
00264
00265 edm::LogVerbatim ("noise") <<"[DTNoiseTest] endjob called!";
00266
00267
00268
00269
00270 dbe->rmdir("DT/Tests/Noise");
00271 }
00272
00273
00274 string DTNoiseTest::getMEName(const DTChamberId & ch) {
00275
00276 stringstream wheel; wheel << ch.wheel();
00277 stringstream station; station << ch.station();
00278 stringstream sector; sector << ch.sector();
00279
00280 string folderRoot = parameters.getUntrackedParameter<string>("folderRoot", "Collector/FU0/");
00281 string folderTag = parameters.getUntrackedParameter<string>("folderTag", "Occupancies");
00282 string folderName =
00283 folderRoot + "DT/DTDigiTask/Wheel" + wheel.str() +
00284 "/Station" + station.str() +
00285 "/Sector" + sector.str() + "/" + folderTag + "/";
00286
00287 string histoTag = parameters.getUntrackedParameter<string>("histoTag", "OccupancyNoise_perCh");
00288 string histoname = folderName + histoTag
00289 + "_W" + wheel.str()
00290 + "_St" + station.str()
00291 + "_Sec" + sector.str();
00292
00293
00294 return histoname;
00295
00296 }
00297
00298 string DTNoiseTest::getMEName(const DTLayerId & ly) {
00299
00300 stringstream wheel; wheel << ly.wheel();
00301 stringstream station; station << ly.station();
00302 stringstream sector; sector << ly.sector();
00303 stringstream superLayer; superLayer << ly.superlayer();
00304 stringstream layer; layer << ly.layer();
00305
00306 string folderRoot = parameters.getUntrackedParameter<string>("folderRoot", "Collector/FU0/");
00307 string folderTag = parameters.getUntrackedParameter<string>("folderTagForDigiPerEventTest", "DigiPerEvent");
00308 string folderName =
00309 folderRoot + "DT/DTDigiForNoiseTask/Wheel" + wheel.str() +
00310 "/Station" + station.str() +
00311 "/Sector" + sector.str() + "/" + folderTag + "/";
00312
00313 string histoTag = parameters.getUntrackedParameter<string>("histoTagForDigiPerEventTest", "DigiPerEvent");
00314 string histoname = folderName + histoTag
00315 + "_W" + wheel.str()
00316 + "_St" + station.str()
00317 + "_Sec" + sector.str()
00318 + "_SL" + superLayer.str()
00319 + "_L" + layer.str();
00320
00321
00322 return histoname;
00323
00324 }
00325
00326
00327 void DTNoiseTest::bookHistos(const DTChamberId & ch, string folder, string histoTag ) {
00328
00329 stringstream wheel; wheel << ch.wheel();
00330 stringstream station; station << ch.station();
00331 stringstream sector; sector << ch.sector();
00332
00333 dbe->setCurrentFolder("DT/Tests/Noise/" + folder);
00334
00335 string histoName = histoTag + "W" + wheel.str() + "_St" + station.str() + "_Sec" + sector.str();
00336
00337 if (folder == "NoiseAverage")
00338 (histos[histoTag])[ch.rawId()] = dbe->book1D(histoName.c_str(),histoName.c_str(),3,0,3);
00339
00340 if ( folder == "NewNoisyChannels")
00341 (histos[histoTag])[ch.rawId()] = dbe->book1D(histoName.c_str(),histoName.c_str(),3,0,3);
00342
00343 }
00344
00345
00346 void DTNoiseTest::bookHistos(const DTLayerId & lId, int nWires, string folder, string histoTag) {
00347
00348 stringstream wheel; wheel << lId.superlayerId().wheel();
00349 stringstream station; station << lId.superlayerId().station();
00350 stringstream sector; sector << lId.superlayerId().sector();
00351 stringstream superLayer; superLayer << lId.superlayerId().superlayer();
00352 stringstream layer; layer << lId.layer();
00353
00354 string histoName = histoTag + "_W" + wheel.str() + "_St" + station.str() + "_Sec" + sector.str() + "_SL" + superLayer.str() + "_L" + layer.str();
00355
00356 dbe->setCurrentFolder("DT/Tests/Noise/" + folder +
00357 "/Wheel" + wheel.str() +
00358 "/Station" + station.str() +
00359 "/Sector" + sector.str());
00360
00361 (histos[histoTag])[lId.rawId()] = dbe->book1D(histoName.c_str(),histoName.c_str(),nWires,0,nWires);
00362
00363 }