00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <DQM/DTMonitorClient/src/DTSegmentAnalysisTest.h>
00013
00014
00015 #include <FWCore/Framework/interface/Event.h>
00016 #include "DataFormats/Common/interface/Handle.h"
00017 #include <FWCore/Framework/interface/ESHandle.h>
00018 #include <FWCore/Framework/interface/EventSetup.h>
00019 #include <FWCore/ParameterSet/interface/ParameterSet.h>
00020
00021
00022
00023 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00024 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00025 #include "Geometry/DTGeometry/interface/DTLayer.h"
00026 #include "Geometry/DTGeometry/interface/DTTopology.h"
00027
00028 #include "DQMServices/Core/interface/DQMStore.h"
00029 #include "DQMServices/Core/interface/MonitorElement.h"
00030 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00031
00032 #include "DQM/DTMonitorModule/interface/DTTimeEvolutionHisto.h"
00033
00034 #include <iostream>
00035 #include <stdio.h>
00036 #include <string>
00037 #include <sstream>
00038 #include <math.h>
00039
00040
00041 using namespace edm;
00042 using namespace std;
00043
00044
00045 DTSegmentAnalysisTest::DTSegmentAnalysisTest(const edm::ParameterSet& ps){
00046
00047 edm::LogVerbatim ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << "[DTSegmentAnalysisTest]: Constructor";
00048 parameters = ps;
00049
00050 dbe = edm::Service<DQMStore>().operator->();
00051
00052
00053 detailedAnalysis = parameters.getUntrackedParameter<bool>("detailedAnalysis","false");
00054 normalizeHistoPlots = parameters.getUntrackedParameter<bool>("normalizeHistoPlots",false);
00055 }
00056
00057
00058 DTSegmentAnalysisTest::~DTSegmentAnalysisTest(){
00059
00060 edm::LogVerbatim ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << "DTSegmentAnalysisTest: analyzed " << nevents << " events";
00061 }
00062
00063
00064 void DTSegmentAnalysisTest::beginJob(const edm::EventSetup& context){
00065
00066 edm::LogVerbatim ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") <<"[DTSegmentAnalysisTest]: BeginJob";
00067
00068 nevents = 0;
00069
00070 context.get<MuonGeometryRecord>().get(muonGeom);
00071
00072
00073 bookHistos();
00074
00075 }
00076
00077
00078 void DTSegmentAnalysisTest::beginLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context) {
00079
00080 edm::LogVerbatim ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") <<"[DTSegmentAnalysisTest]: Begin of LS transition";
00081
00082 }
00083
00084
00085 void DTSegmentAnalysisTest::analyze(const edm::Event& e, const edm::EventSetup& context){
00086
00087 nevents++;
00088 if(nevents%1000 == 0)
00089 LogVerbatim ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << "[DTSegmentAnalysisTest]: "<<nevents<<" events";
00090
00091 }
00092
00093
00094 void DTSegmentAnalysisTest::endLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context) {
00095
00096
00097 nLumiSegs = lumiSeg.id().luminosityBlock();
00098
00099 edm::LogVerbatim ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest")
00100 <<"[DTSegmentAnalysisTest]: End of LS " << nLumiSegs << ", perform DQM client operation";
00101
00102 summaryHistos[3]->Reset();
00103 vector<DTChamber*>::const_iterator ch_it = muonGeom->chambers().begin();
00104 vector<DTChamber*>::const_iterator ch_end = muonGeom->chambers().end();
00105
00106 for (; ch_it != ch_end; ++ch_it) {
00107 DTChamberId chID = (*ch_it)->id();
00108
00109 MonitorElement * segm_histo = dbe->get(getMEName(chID, "h4DSegmNHits"));
00110 MonitorElement * summary_histo = dbe->get(getMEName(chID, "numberOfSegments"));
00111
00112 if (segm_histo && summary_histo) {
00113
00114 TH1F * segmHit_histo_root = segm_histo->getTH1F();
00115 TH2F * segm_histo_root = summary_histo->getTH2F();
00116 TH2F * summary_histo_root = summaryHistos[3]->getTH2F();
00117
00118 int sector = chID.sector();
00119 if(sector == 13) sector=4;
00120 if(sector == 14) sector=10;
00121
00122
00123 if((chID.station()!=4 && segmHit_histo_root->GetMaximumBin() != 12)||
00124 (chID.station()==4 && segmHit_histo_root->GetMaximumBin() != 8)){
00125 summaryHistos[chID.wheel()]->setBinContent(sector, chID.station(),1);
00126 if(summary_histo_root->GetBinContent(sector, chID.wheel()+3)<1)
00127 summaryHistos[3]->setBinContent(sector, chID.wheel()+3,1);
00128 }
00129 else
00130 summaryHistos[chID.wheel()]->setBinContent(sector, chID.station(),0);
00131
00132 if(detailedAnalysis) {
00133 if(chID.station()!=4)
00134 segmRecHitHistos[make_pair(chID.wheel(),chID.sector())]->Fill(chID.station(),abs(12-segmHit_histo_root->GetMaximumBin()));
00135 else
00136 segmRecHitHistos[make_pair(chID.wheel(),chID.sector())]->Fill(chID.station(),abs(8-segmHit_histo_root->GetMaximumBin()));
00137 }
00138
00139 TH2F * summary2_histo_root = summaryHistos[3]->getTH2F();
00140
00141 if(segm_histo_root->GetBinContent(sector,chID.station())==0){
00142 summaryHistos[chID.wheel()]->setBinContent(sector, chID.station(),2);
00143 if(summary2_histo_root->GetBinContent(sector, chID.wheel()+3)<2)
00144 summaryHistos[3]->setBinContent(sector, chID.wheel()+3,2);
00145 }
00146
00147 } else {
00148 LogVerbatim ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << "[DTSegmentAnalysisTest]: histos not found!!";
00149 }
00150
00151 if(detailedAnalysis){
00152
00153
00154 MonitorElement * chi2_histo = dbe->get(getMEName(chID, "h4DChi2"));
00155 if(chi2_histo) {
00156 TH1F * chi2_histo_root = chi2_histo->getTH1F();
00157 double threshold = parameters.getUntrackedParameter<double>("chi2Threshold", 5);
00158 double maximum = chi2_histo_root->GetXaxis()->GetXmax();
00159 double minimum = chi2_histo_root->GetXaxis()->GetXmin();
00160 int nbins = chi2_histo_root->GetXaxis()->GetNbins();
00161 int thresholdBin = int(threshold/((maximum-minimum)/nbins));
00162
00163 double badSegments=0;
00164 for(int bin=thresholdBin; bin<=nbins; bin++){
00165 badSegments+=chi2_histo_root->GetBinContent(bin);
00166 }
00167
00168 if(chi2_histo_root->GetEntries()!=0){
00169 double badSegmentsPercentual= badSegments/double(chi2_histo_root->GetEntries());
00170 chi2Histos[make_pair(chID.wheel(),chID.sector())]->Fill(chID.station(),badSegmentsPercentual);
00171 }
00172 } else {
00173 edm::LogVerbatim ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") <<"[DTSegmentAnalysisTest]: Histo: "
00174 << getMEName(chID, "h4DChi2") << " not found!" << endl;
00175 }
00176 }
00177
00178 }
00179
00180
00181 if(detailedAnalysis){
00182
00183 string chi2CriterionName = parameters.getUntrackedParameter<string>("chi2TestName","chi2InRange");
00184 for(map<pair<int, int>, MonitorElement*> ::const_iterator histo = chi2Histos.begin();
00185 histo != chi2Histos.end();
00186 histo++) {
00187
00188 const QReport * theChi2QReport = (*histo).second->getQReport(chi2CriterionName);
00189 if(theChi2QReport) {
00190 vector<dqm::me_util::Channel> badChannels = theChi2QReport->getBadChannels();
00191 for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin();
00192 channel != badChannels.end(); channel++) {
00193 edm::LogError ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << "Wheel: "<<(*histo).first.first<< " Sector: "<<(*histo).first.second<< " Bad stations: "<<(*channel).getBin()<<" Contents : "<<(*channel).getContents();
00194 }
00195 }
00196 }
00197
00198 string segmRecHitCriterionName = parameters.getUntrackedParameter<string>("segmRecHitTestName","segmRecHitInRange");
00199 for(map<pair<int, int>, MonitorElement*> ::const_iterator histo = segmRecHitHistos.begin();
00200 histo != segmRecHitHistos.end();
00201 histo++) {
00202
00203 const QReport * theSegmRecHitQReport = (*histo).second->getQReport(segmRecHitCriterionName);
00204 if(theSegmRecHitQReport) {
00205 vector<dqm::me_util::Channel> badChannels = theSegmRecHitQReport->getBadChannels();
00206 for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin();
00207 channel != badChannels.end(); channel++) {
00208 edm::LogError ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << "Wheel: "<<(*histo).first.first<< " Sector: "<<(*histo).first.second<< " Bad stations on recHit number: "<<(*channel).getBin()<<" Contents : "<<(*channel).getContents();
00209 }
00210 }
00211 }
00212
00213 }
00214
00215 }
00216
00217
00218 string DTSegmentAnalysisTest::getMEName(const DTChamberId & chID, string histoTag) {
00219
00220 stringstream wheel; wheel << chID.wheel();
00221 stringstream station; station << chID.station();
00222 stringstream sector; sector << chID.sector();
00223
00224 string folderRoot = parameters.getUntrackedParameter<string>("folderRoot", "Collector/FU0/");
00225 string folderName =
00226 folderRoot + "DT/02-Segments/Wheel" + wheel.str() +
00227 "/Sector" + sector.str() +
00228 "/Station" + station.str() + "/";
00229
00230 string histoname = folderName + histoTag
00231 + "_W" + wheel.str()
00232 + "_St" + station.str()
00233 + "_Sec" + sector.str();
00234
00235 if(histoTag == "numberOfSegments")
00236 histoname =
00237 folderRoot + "DT/02-Segments/Wheel" + wheel.str() + "/" +
00238 histoTag + + "_W" + wheel.str();
00239
00240 return histoname;
00241
00242 }
00243
00244
00245 void DTSegmentAnalysisTest::bookHistos() {
00246
00247 for(int wh=-2; wh<=2; wh++){
00248 stringstream wheel; wheel << wh;
00249 string histoName = "segmentSummary_W" + wheel.str();
00250 dbe->setCurrentFolder("DT/02-Segments");
00251 summaryHistos[wh] = dbe->book2D(histoName.c_str(),histoName.c_str(),12,1,13,4,1,5);
00252 summaryHistos[wh]->setAxisTitle("Sector",1);
00253 summaryHistos[wh]->setBinLabel(1,"MB1",2);
00254 summaryHistos[wh]->setBinLabel(2,"MB2",2);
00255 summaryHistos[wh]->setBinLabel(3,"MB3",2);
00256 summaryHistos[wh]->setBinLabel(4,"MB4",2);
00257
00258 if(detailedAnalysis){
00259 for(int sect=1; sect<=14; sect++){
00260 stringstream sector; sector << sect;
00261 string chi2HistoName = "chi2BadSegmPercentual_W" + wheel.str() + "_Sec" + sector.str();
00262 dbe->setCurrentFolder("DT/02-Segments/Wheel" + wheel.str() + "/Tests");
00263 chi2Histos[make_pair(wh,sect)] = dbe->book1D(chi2HistoName.c_str(),chi2HistoName.c_str(),4,1,5);
00264 chi2Histos[make_pair(wh,sect)]->setBinLabel(1,"MB1");
00265 chi2Histos[make_pair(wh,sect)]->setBinLabel(2,"MB2");
00266 chi2Histos[make_pair(wh,sect)]->setBinLabel(3,"MB3");
00267 chi2Histos[make_pair(wh,sect)]->setBinLabel(4,"MB4");
00268
00269 string segmHistoName = "residualsOnSegmRecHitNumber_W" + wheel.str() + "_Sec" + sector.str();
00270 segmRecHitHistos[make_pair(wh,sect)] = dbe->book1D(segmHistoName.c_str(),segmHistoName.c_str(),4,1,5);
00271 segmRecHitHistos[make_pair(wh,sect)]->setBinLabel(1,"MB1");
00272 segmRecHitHistos[make_pair(wh,sect)]->setBinLabel(2,"MB2");
00273 segmRecHitHistos[make_pair(wh,sect)]->setBinLabel(3,"MB3");
00274 segmRecHitHistos[make_pair(wh,sect)]->setBinLabel(4,"MB4");
00275
00276 }
00277 }
00278 }
00279
00280 string histoName = "segmentSummary";
00281 dbe->setCurrentFolder("DT/02-Segments");
00282 summaryHistos[3] = dbe->book2D(histoName.c_str(),histoName.c_str(),12,1,13,5,-2,3);
00283 summaryHistos[3]->setAxisTitle("Sector",1);
00284 summaryHistos[3]->setAxisTitle("Wheel",2);
00285
00286 }
00287
00288
00289
00290
00291 void DTSegmentAnalysisTest::endJob() {
00292 }
00293
00294
00295 void DTSegmentAnalysisTest::endRun(const Run& run, const EventSetup& eSetup) {
00296
00297
00298 if(normalizeHistoPlots) {
00299 LogVerbatim ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << " Performing time-histo normalization" << endl;
00300 MonitorElement* hNevtPerLS = dbe->get("DT/EventInfo/NevtPerLS");
00301 if(hNevtPerLS != 0) {
00302 for(int wheel = -2; wheel != 3; ++wheel) {
00303 for(int sector = 1; sector <= 12; ++sector) {
00304 stringstream wheelstr; wheelstr << wheel;
00305 stringstream sectorstr; sectorstr << sector;
00306 string sectorHistoName = "DT/02-Segments/Wheel" + wheelstr.str() +
00307 "/Sector" + sectorstr.str() +
00308 "/NSegmPerEvent_W" + wheelstr.str() +
00309 "_Sec" + sectorstr.str();
00310 DTTimeEvolutionHisto hNSegmPerLS(&(*dbe), sectorHistoName);
00311 hNSegmPerLS.normalizeTo(hNevtPerLS);
00312 }
00313 }
00314 } else {
00315 edm::LogError ("DTDQM|DTMonitorClient|DTSegmentAnalysisTest") << "Histo NevtPerLS not found!" << endl;
00316 }
00317 }
00318 }
00319
00320