CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/DQM/DTMonitorClient/src/DTNoiseAnalysisTest.cc

Go to the documentation of this file.
00001 
00002 /*
00003  *  See header file for a description of this class.
00004  *
00005  *  $Date: 2011/06/21 10:47:53 $
00006  *  $Revision: 1.17 $
00007  *  \author G. Mila - INFN Torino
00008  */
00009 
00010 
00011 #include <DQM/DTMonitorClient/src/DTNoiseAnalysisTest.h>
00012 
00013 // Framework
00014 #include "FWCore/ServiceRegistry/interface/Service.h"
00015 #include <FWCore/Framework/interface/EventSetup.h>
00016 #include <FWCore/ParameterSet/interface/ParameterSet.h>
00017 
00018 
00019 // Geometry
00020 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00021 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00022 #include "Geometry/DTGeometry/interface/DTLayer.h"
00023 #include "Geometry/DTGeometry/interface/DTTopology.h"
00024 #include <DataFormats/MuonDetId/interface/DTLayerId.h>
00025 
00026 #include "DQMServices/Core/interface/DQMStore.h"
00027 #include "DQMServices/Core/interface/MonitorElement.h"
00028 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00029 
00030 #include <iostream>
00031 #include <sstream>
00032 
00033 
00034 
00035 using namespace edm;
00036 using namespace std;
00037 
00038 
00039 DTNoiseAnalysisTest::DTNoiseAnalysisTest(const edm::ParameterSet& ps){
00040   LogTrace("DTDQM|DTMonitorClient|DTNoiseAnalysisTest") << "[DTNoiseAnalysisTest]: Constructor";
00041 
00042   dbe = edm::Service<DQMStore>().operator->();
00043 
00044   // get the cfi parameters
00045   noisyCellDef = ps.getUntrackedParameter<int>("noisyCellDef",500);
00046 
00047   // switch on/off the summaries for the Synchronous noise
00048   doSynchNoise = ps.getUntrackedParameter<bool>("doSynchNoise", false);
00049   detailedAnalysis = ps.getUntrackedParameter<bool>("detailedAnalysis",false);
00050   maxSynchNoiseRate =  ps.getUntrackedParameter<double>("maxSynchNoiseRate", 0.001);
00051   nMinEvts  = ps.getUntrackedParameter<int>("nEventsCert", 5000);
00052 
00053 }
00054 
00055 
00056 DTNoiseAnalysisTest::~DTNoiseAnalysisTest(){
00057   LogTrace("DTDQM|DTMonitorClient|DTNoiseAnalysisTest") << "DTNoiseAnalysisTest: analyzed " << nevents << " events";
00058 }
00059 
00060 
00061 void DTNoiseAnalysisTest::beginJob(){
00062   LogTrace("DTDQM|DTMonitorClient|DTNoiseAnalysisTest") <<"[DTNoiseAnalysisTest]: BeginJob"; 
00063 
00064   nevents = 0;
00065 
00066   // book the histos
00067   bookHistos();
00068 
00069 }
00070 
00071 void DTNoiseAnalysisTest::beginRun(Run const& run, EventSetup const& context) {
00072 
00073   // Get the geometry
00074   context.get<MuonGeometryRecord>().get(muonGeom);
00075 
00076 }
00077 
00078 
00079 void DTNoiseAnalysisTest::beginLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context) {
00080 
00081   LogTrace("DTDQM|DTMonitorClient|DTNoiseAnalysisTest") <<"[DTNoiseAnalysisTest]: Begin of LS transition";
00082 }
00083 
00084 
00085 void DTNoiseAnalysisTest::analyze(const edm::Event& e, const edm::EventSetup& context){
00086 
00087   nevents++;
00088   if(nevents%1000 == 0) LogTrace("DTDQM|DTMonitorClient|DTNoiseAnalysisTest")
00089     << "[DTNoiseAnalysisTest]: "<<nevents<<" events";
00090 
00091 }
00092 
00093 void DTNoiseAnalysisTest::endLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context) {
00094   LogVerbatim ("DTDQM|DTMonitorClient|DTNoiseAnalysisTest")
00095     <<"[DTNoiseAnalysisTest]: End of LS transition, performing the DQM client operation";
00096 
00097   // Reset the summary plots
00098   for(map<int, MonitorElement* >::iterator plot =  noiseHistos.begin();
00099       plot != noiseHistos.end(); ++plot) {
00100     (*plot).second->Reset();
00101   }
00102 
00103   for(map<int,  MonitorElement* >::iterator plot = noisyCellHistos.begin();
00104       plot != noisyCellHistos.end(); ++plot) {
00105     (*plot).second->Reset();
00106   }
00107 
00108   summaryNoiseHisto->Reset();
00109 
00110 
00111 
00112   vector<DTChamber*>::const_iterator ch_it = muonGeom->chambers().begin();
00113   vector<DTChamber*>::const_iterator ch_end = muonGeom->chambers().end();
00114 
00115   LogTrace ("DTDQM|DTMonitorClient|DTNoiseAnalysisTest")
00116     <<"[DTNoiseAnalysisTest]: Fill the summary histos";
00117 
00118   for (; ch_it != ch_end; ++ch_it) { // loop over chambers
00119     DTChamberId chID = (*ch_it)->id();
00120 
00121     MonitorElement * histo = dbe->get(getMEName(chID));
00122 
00123     if(histo) { // check the pointer
00124 
00125       TH2F * histo_root = histo->getTH2F();
00126 
00127       for(int sl = 1; sl != 4; ++sl) { // loop over SLs
00128         // skip theta SL in MB4 chambers
00129         if(chID.station() == 4 && sl == 2) continue;
00130 
00131         int binYlow = ((sl-1)*4)+1;
00132 
00133         for(int layer = 1; layer <= 4; ++layer) { // loop over layers
00134 
00135           // Get the layer ID
00136           DTLayerId layID(chID,sl,layer);
00137 
00138           int nWires = muonGeom->layer(layID)->specificTopology().channels();
00139           int firstWire = muonGeom->layer(layID)->specificTopology().firstChannel();
00140 
00141           int binY = binYlow+(layer-1);
00142 
00143           for(int wire = firstWire; wire != (nWires+firstWire); wire++){ // loop over wires
00144 
00145             double noise = histo_root->GetBinContent(wire, binY);
00146             // fill the histos
00147             noiseHistos[chID.wheel()]->Fill(noise);
00148             noiseHistos[3]->Fill(noise);
00149             int sector = chID.sector();
00150             if(noise>noisyCellDef) {
00151               if(sector == 13) {
00152                 sector = 4;
00153               } else if(sector == 14) {
00154                 sector = 10;
00155               }
00156               noisyCellHistos[chID.wheel()]->Fill(sector,chID.station());
00157               summaryNoiseHisto->Fill(sector,chID.wheel());
00158             }
00159           }
00160         }
00161       }
00162     }
00163   }
00164 
00165   if(detailedAnalysis) {
00166     threshChannelsHisto->Reset();
00167     TH1F * histo = noiseHistos[3]->getTH1F();
00168     for(int step = 0; step != 15; step++) {
00169       int threshBin = step + 1;
00170       int minBin = 26 + step*5;
00171       int nNoisyCh = histo->Integral(minBin,101);
00172       threshChannelsHisto->setBinContent(threshBin,nNoisyCh);
00173     }
00174   }
00175 
00176   // build the summary of synch noise
00177 
00178 
00179   if(doSynchNoise) {
00180     LogTrace("DTDQM|DTMonitorClient|DTNoiseAnalysisTest")
00181       << "[DTNoiseAnalysisTest]: fill summaries for synch noise" << endl;
00182     summarySynchNoiseHisto->Reset();
00183     glbSummarySynchNoiseHisto->Reset();
00184     for(int wheel = -2; wheel != 3; ++wheel) {
00185       // Get the histo produced by DTDigiTask
00186       MonitorElement * histoNoiseSynch = dbe->get(getSynchNoiseMEName(wheel));
00187       if(histoNoiseSynch != 0) {
00188         for(int sect = 1; sect != 13; ++sect) { // loop over sectors
00189           TH2F * histo = histoNoiseSynch->getTH2F();
00190           float maxSectRate = 0;
00191           for(int sta = 1; sta != 5; ++sta) {
00192             float chRate = histo->GetBinContent(sect, sta)/(float)nevents;
00193             LogTrace("DTDQM|DTMonitorClient|DTNoiseAnalysisTest")
00194               << "   Wheel: " << wheel << " sect: " << sect
00195               << " station: " << sta
00196               << " rate is: " << chRate << endl;
00197             if (chRate > maxSectRate)
00198               maxSectRate = chRate;
00199           }
00200           summarySynchNoiseHisto->Fill(sect,wheel,
00201               maxSectRate > maxSynchNoiseRate ? 1 : 0);
00202           float glbBinValue = 1 - 0.15*maxSectRate/maxSynchNoiseRate;
00203           glbSummarySynchNoiseHisto->Fill(sect,wheel,glbBinValue>0 ? glbBinValue : 0);
00204 
00205         }
00206       } else {
00207         LogWarning("DTDQM|DTMonitorClient|DTNoiseAnalysisTest")
00208           << "   Histo: " << getSynchNoiseMEName(wheel) << " not found!" << endl;
00209       }
00210     }
00211 
00212   }
00213 
00214   string nEvtsName = "DT/EventInfo/Counters/nProcessedEventsNoise";
00215   MonitorElement * meProcEvts = dbe->get(nEvtsName);
00216 
00217   if (meProcEvts) {
00218     int nProcEvts = meProcEvts->getFloatValue();
00219     glbSummarySynchNoiseHisto->setEntries(nProcEvts < nMinEvts ? 10. : nProcEvts);
00220     summarySynchNoiseHisto->setEntries(nProcEvts < nMinEvts ? 10. : nProcEvts);
00221   } else {
00222     glbSummarySynchNoiseHisto->setEntries(nMinEvts +1);
00223     summarySynchNoiseHisto->setEntries(nMinEvts + 1);
00224     LogVerbatim ("DTDQM|DTMonitorClient|DTnoiseAnalysisTest") << "[DTNoiseAnalysisTest] ME: "
00225       <<  nEvtsName << " not found!" << endl;
00226   }
00227 
00228 
00229 }              
00230 
00231 
00232 string DTNoiseAnalysisTest::getMEName(const DTChamberId & chID) {
00233 
00234   stringstream wheel; wheel << chID.wheel();    
00235   stringstream station; station << chID.station();      
00236   stringstream sector; sector << chID.sector(); 
00237 
00238   string folderName = 
00239     "DT/05-Noise/Wheel" +  wheel.str() +
00240     //     "/Station" + station.str() +
00241     "/Sector" + sector.str() + "/";
00242 
00243   string histoname = folderName + string("NoiseRate")  
00244     + "_W" + wheel.str() 
00245     + "_St" + station.str() 
00246     + "_Sec" + sector.str();
00247 
00248   return histoname;
00249 
00250 }
00251 
00252 
00253 void DTNoiseAnalysisTest::bookHistos() {
00254 
00255   dbe->setCurrentFolder("DT/05-Noise");
00256   string histoName;
00257 
00258   for(int wh=-2; wh<=2; wh++){
00259     stringstream wheel; wheel << wh;
00260     histoName =  "NoiseRateSummary_W" + wheel.str();
00261     noiseHistos[wh] = dbe->book1D(histoName.c_str(),histoName.c_str(),100,0,2000);
00262     noiseHistos[wh]->setAxisTitle("rate (Hz)",1);
00263     noiseHistos[wh]->setAxisTitle("entries",2);
00264   }
00265   histoName =  "NoiseRateSummary";
00266   noiseHistos[3] = dbe->book1D(histoName.c_str(),histoName.c_str(),100,0,2000);
00267   noiseHistos[3]->setAxisTitle("rate (Hz)",1);
00268   noiseHistos[3]->setAxisTitle("entries",2);
00269 
00270 
00271   for(int wh=-2; wh<=2; wh++){
00272     stringstream wheel; wheel << wh;
00273     histoName =  "NoiseSummary_W" + wheel.str();
00274     noisyCellHistos[wh] = dbe->book2D(histoName.c_str(),"# of noisy channels",12,1,13,4,1,5);
00275     noisyCellHistos[wh]->setBinLabel(1,"MB1",2);
00276     noisyCellHistos[wh]->setBinLabel(2,"MB2",2);
00277     noisyCellHistos[wh]->setBinLabel(3,"MB3",2);
00278     noisyCellHistos[wh]->setBinLabel(4,"MB4",2);  
00279     noisyCellHistos[wh]->setAxisTitle("Sector",1);
00280   }
00281 
00282   histoName =  "NoiseSummary";
00283   summaryNoiseHisto =  dbe->book2D(histoName.c_str(),"# of noisy channels",12,1,13,5,-2,3);
00284   summaryNoiseHisto->setAxisTitle("Sector",1);
00285   summaryNoiseHisto->setAxisTitle("Wheel",2);
00286 
00287   if(detailedAnalysis) {
00288     histoName = "NoisyChannels";
00289     threshChannelsHisto = dbe->book1D(histoName.c_str(),"# of noisy channels vs threshold",15,500,2000);
00290     threshChannelsHisto->setAxisTitle("threshold",1);
00291     threshChannelsHisto->setAxisTitle("# noisy channels",2);
00292   }
00293 
00294   if(doSynchNoise) {
00295     dbe->setCurrentFolder("DT/05-Noise/SynchNoise/");
00296     histoName =  "SynchNoiseSummary";
00297     summarySynchNoiseHisto = dbe->book2D(histoName.c_str(),"Summary Synch. Noise",12,1,13,5,-2,3);
00298     summarySynchNoiseHisto->setAxisTitle("Sector",1);
00299     summarySynchNoiseHisto->setAxisTitle("Wheel",2);
00300     histoName =  "SynchNoiseGlbSummary";
00301     glbSummarySynchNoiseHisto = dbe->book2D(histoName.c_str(),"Summary Synch. Noise",12,1,13,5,-2,3);
00302     glbSummarySynchNoiseHisto->setAxisTitle("Sector",1);
00303     glbSummarySynchNoiseHisto->setAxisTitle("Wheel",2);
00304   }
00305 
00306 }
00307 
00308 
00309 
00310 string DTNoiseAnalysisTest::getSynchNoiseMEName(int wheelId) const {
00311 
00312   stringstream wheel; wheel << wheelId; 
00313   string folderName = 
00314     "DT/05-Noise/SynchNoise/";
00315   string histoname = folderName + string("SyncNoiseEvents")  
00316     + "_W" + wheel.str();
00317 
00318   return histoname;
00319 
00320 }
00321