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