00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <DQM/DTMonitorClient/src/DTResolutionAnalysisTest.h>
00013
00014
00015 #include <FWCore/Framework/interface/Event.h>
00016 #include <FWCore/Framework/interface/EventSetup.h>
00017 #include <FWCore/ParameterSet/interface/ParameterSet.h>
00018
00019
00020
00021 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00022 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00023
00024 #include "FWCore/ServiceRegistry/interface/Service.h"
00025 #include "DQMServices/Core/interface/DQMStore.h"
00026 #include "DQMServices/Core/interface/MonitorElement.h"
00027 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00028
00029 #include <string>
00030 #include <sstream>
00031 #include <math.h>
00032
00033
00034 using namespace edm;
00035 using namespace std;
00036
00037
00038 DTResolutionAnalysisTest::DTResolutionAnalysisTest(const ParameterSet& ps){
00039
00040 LogTrace ("DTDQM|DTMonitorClient|DTResolutionAnalysisTest") << "[DTResolutionAnalysisTest]: Constructor";
00041
00042 dbe = Service<DQMStore>().operator->();
00043
00044 prescaleFactor = ps.getUntrackedParameter<int>("diagnosticPrescale", 1);
00045
00046 permittedMeanRange = ps.getUntrackedParameter<double>("permittedMeanRange",0.005);
00047 permittedSigmaRange = ps.getUntrackedParameter<double>("permittedSigmaRange",0.01);
00048
00049 topHistoFolder = ps.getUntrackedParameter<string>("topHistoFolder","DT/02-Segments");
00050
00051 doCalibAnalysis = ps.getUntrackedParameter<bool>("doCalibAnalysis",false);
00052 }
00053
00054
00055 DTResolutionAnalysisTest::~DTResolutionAnalysisTest(){
00056
00057 LogTrace ("DTDQM|DTMonitorClient|DTResolutionAnalysisTest") << "DTResolutionAnalysisTest: analyzed " << nevents << " events";
00058
00059 }
00060
00061
00062 void DTResolutionAnalysisTest::beginJob(){
00063
00064 LogTrace ("DTDQM|DTMonitorClient|DTResolutionAnalysisTest") <<"[DTResolutionAnalysisTest]: BeginJob";
00065
00066 nevents = 0;
00067
00068 }
00069
00070 void DTResolutionAnalysisTest::beginRun(const Run& run, const EventSetup& context){
00071
00072 LogTrace ("DTDQM|DTMonitorClient|DTResolutionAnalysisTest") <<"[DTResolutionAnalysisTest]: BeginRun";
00073
00074
00075 context.get<MuonGeometryRecord>().get(muonGeom);
00076
00077 }
00078
00079
00080 void DTResolutionAnalysisTest::beginLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context) {
00081
00082 LogTrace ("DTDQM|DTMonitorClient|DTResolutionAnalysisTest") <<"[DTResolutionAnalysisTest]: Begin of LS transition";
00083
00084
00085 run = lumiSeg.run();
00086
00087 }
00088
00089
00090
00091 void DTResolutionAnalysisTest::analyze(const Event& e, const EventSetup& context){
00092
00093 nevents++;
00094
00095 }
00096
00097
00098
00099 void DTResolutionAnalysisTest::endLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context) {
00100
00101 }
00102
00103
00104 void DTResolutionAnalysisTest::bookHistos() {
00105
00106
00107 dbe->setCurrentFolder(topHistoFolder);
00108 globalResSummary = dbe->book2D("ResidualsGlbSummary", "# of SLs with good mean and good sigma of residuals",12,1,13,5,-2,3);
00109
00110
00111 dbe->setCurrentFolder(topHistoFolder + "/00-MeanRes");
00112 meanDistr[-2] = dbe->book1D("MeanDistr","Mean value of the residuals all (cm)",
00113 100,-0.1,0.1);
00114 meanDistr[-1] = dbe->book1D("MeanDistr_Phi","Mean value of the residuals #phi SL (cm)",
00115 100,-0.1,0.1);
00116 meanDistr[0] = dbe->book1D("MeanDistr_ThetaWh0","Mean values of the residuals #theta SL Wh 0 (cm)",
00117 100,-0.1,0.1);
00118 meanDistr[1] = dbe->book1D("MeanDistr_ThetaWh1","Mean value of the residuals #theta SL Wh +/-1 (cm)",
00119 100,-0.1,0.1);
00120 meanDistr[2] = dbe->book1D("MeanDistr_ThetaWh2","Mean value of the residuals #theta SL Wh +/-2 (cm)",
00121 100,-0.1,0.1);
00122
00123
00124 stringstream meanRange; meanRange << (permittedMeanRange*10000);
00125 string histoTitle = "# of SLs with good mean of residuals";
00126 wheelMeanHistos[3] = dbe->book2D("MeanResGlbSummary",histoTitle.c_str(),12,1,13,5,-2,3);
00127 wheelMeanHistos[3]->setAxisTitle("Sector",1);
00128 wheelMeanHistos[3]->setAxisTitle("Wheel",2);
00129
00130
00131 dbe->setCurrentFolder(topHistoFolder + "/01-SigmaRes");
00132 sigmaDistr[-2] = dbe->book1D("SigmaDistr","Sigma value of the residuals all (cm)",
00133 50,0.0,0.2);
00134 sigmaDistr[-1] = dbe->book1D("SigmaDistr_Phi","Sigma value of the residuals #phi SL (cm)",
00135 50,0.0,0.2);
00136 sigmaDistr[0] = dbe->book1D("SigmaDistr_ThetaWh0","Sigma value of the residuals #theta SL Wh 0 (cm)",
00137 50,0.0,0.2);
00138 sigmaDistr[1] = dbe->book1D("SigmaDistr_ThetaWh1","Sigma value of the residuals #theta SL Wh +/-1 (cm)",
00139 50,0.0,0.2);
00140 sigmaDistr[2] = dbe->book1D("SigmaDistr_ThetaWh2","Sigma value of the residuals #theta SL Wh +/-2 (cm)",
00141 50,0.0,0.2);
00142
00143 stringstream sigmaRange; sigmaRange << (permittedSigmaRange*10000);
00144 histoTitle = "# of SLs with good sigma of residuals";
00145 wheelSigmaHistos[3] = dbe->book2D("SigmaResGlbSummary",histoTitle.c_str(),12,1,13,5,-2,3);
00146 wheelSigmaHistos[3]->setAxisTitle("Sector",1);
00147 wheelSigmaHistos[3]->setAxisTitle("Wheel",2);
00148
00149
00150
00151 for (int wheel=-2; wheel<=2; wheel++){
00152 bookHistos(wheel);
00153 for (int sector=1; sector<=12; sector++){
00154 bookHistos(wheel, sector);
00155 }
00156 }
00157
00158 }
00159
00160 void DTResolutionAnalysisTest::endRun(Run const& run, EventSetup const& context) {
00161
00162 if (!dbe->dirExists(topHistoFolder)) {
00163 LogTrace ("DTDQM|DTMonitorClient|DTResolutionAnalysisTest")
00164 <<"[DTResolutionAnalysisTest]: Base folder " << topHistoFolder
00165 << " does not exist. Skipping client operation." << endl;
00166 return;
00167 }
00168
00169 bookHistos();
00170
00171
00172 LogTrace ("DTDQM|DTMonitorClient|DTResolutionAnalysisTest")
00173 << "[DTResolutionAnalysisTest]: End of Run transition, performing the DQM client operation" << endl;
00174
00175
00176 resetMEs();
00177
00178 for (vector<DTChamber*>::const_iterator ch_it = muonGeom->chambers().begin();
00179 ch_it != muonGeom->chambers().end(); ++ch_it) {
00180
00181 DTChamberId chID = (*ch_it)->id();
00182
00183
00184 for(vector<const DTSuperLayer*>::const_iterator sl_it = (*ch_it)->superLayers().begin();
00185 sl_it != (*ch_it)->superLayers().end(); ++sl_it) {
00186
00187
00188 DTSuperLayerId slID = (*sl_it)->id();
00189 MonitorElement * res_histo = dbe->get(getMEName(slID));
00190
00191 if(res_histo) {
00192 float statMean = res_histo->getMean(1);
00193 float statSigma = res_histo->getRMS(1);
00194 double mean = -1;
00195 double sigma = -1;
00196 TH1F * histo_root = res_histo->getTH1F();
00197
00198
00199 int entry= (chID.station() - 1) * 3;
00200 int binSect = slID.sector();
00201 if(slID.sector() == 13) binSect = 4;
00202 else if(slID.sector() == 14) binSect = 10;
00203 int binSL = entry+slID.superLayer();
00204 if(chID.station() == 4 && slID.superLayer() == 3) binSL--;
00205 if((slID.sector()==13 || slID.sector()==14) && slID.superLayer()==1) binSL=12;
00206 if((slID.sector()==13 || slID.sector()==14) && slID.superLayer()==3) binSL=13;
00207
00208 if(histo_root->GetEntries()>20) {
00209 TF1 *gfit = new TF1("Gaussian","gaus",(statMean-(2*statSigma)),(statMean+(2*statSigma)));
00210 try {
00211 histo_root->Fit(gfit, "Q0", "", -0.1, 0.1);
00212 } catch (...) {
00213 LogWarning ("DTDQM|DTMonitorModule|DTResolutionAnalysisTask")
00214 << "[DTResolutionAnalysisTask]: Exception when fitting SL : " << slID;
00215
00216 double weight = 1/11.;
00217 if((binSect == 4 || binSect == 10) && slID.station() == 4) weight = 1/22.;
00218 globalResSummary->Fill(binSect, slID.wheel(), weight);
00219 continue;
00220 }
00221
00222 if(gfit){
00223
00224 mean = gfit->GetParameter(1);
00225 sigma = gfit->GetParameter(2);
00226
00227
00228 meanDistr[-2]->Fill(mean);
00229 sigmaDistr[-2]->Fill(sigma);
00230 if(slID.superlayer() == 2) {
00231 meanDistr[abs(slID.wheel())]->Fill(mean);
00232 sigmaDistr[abs(slID.wheel())]->Fill(sigma);
00233 } else {
00234 meanDistr[-1]->Fill(mean);
00235 sigmaDistr[-1]->Fill(sigma);
00236 }
00237
00238
00239 MeanHistos[make_pair(slID.wheel(),binSect)]->setBinContent(binSL, mean);
00240 SigmaHistos[make_pair(slID.wheel(),binSect)]->setBinContent(binSL, sigma);
00241
00242
00243 double weight = 1;
00244 if(binSect == 13) binSect = 4;
00245 if(binSect == 14) binSect = 10;
00246 if((binSect == 13 || binSect == 14) && binSL == 12) binSL=10;
00247 if((binSect == 13 || binSect == 14) && binSL == 13) binSL=11;
00248
00249
00250 if(meanInRange(mean) && sigmaInRange(sigma)) {
00251 globalResSummary->Fill(binSect, slID.wheel(), weight);
00252 wheelMeanHistos[3]->Fill(binSect,slID.wheel(),weight);
00253 wheelSigmaHistos[3]->Fill(binSect,slID.wheel(),weight);
00254 } else {
00255 if(!meanInRange(mean)) {
00256 wheelMeanHistos[slID.wheel()]->Fill(binSect,binSL);
00257 } else {
00258 wheelMeanHistos[3]->Fill(binSect,slID.wheel(),weight);
00259 }
00260 if(!sigmaInRange(sigma)) {
00261 wheelSigmaHistos[slID.wheel()]->Fill(binSect,binSL);
00262 } else {
00263 wheelSigmaHistos[3]->Fill(binSect,slID.wheel(),weight);
00264 }
00265 }
00266 }
00267 delete gfit;
00268 }
00269 else{
00270 LogVerbatim ("DTDQM|DTMonitorModule|DTResolutionAnalysisTask")
00271 << "[DTResolutionAnalysisTask] Fit of " << slID
00272 << " not performed because # entries < 20 ";
00273
00274 double weight = 1;
00275 if(binSect == 13) binSect = 4;
00276 if(binSect == 14) binSect = 10;
00277 globalResSummary->Fill(binSect, slID.wheel(), weight);
00278 wheelMeanHistos[3]->Fill(binSect,slID.wheel(),weight);
00279 wheelSigmaHistos[3]->Fill(binSect,slID.wheel(),weight);
00280 }
00281 } else {
00282 LogWarning ("DTDQM|DTMonitorModule|DTResolutionAnalysisTask")
00283 << "[DTResolutionAnalysisTask] Histo: " << getMEName(slID) << " not found" << endl;
00284 }
00285 }
00286 }
00287
00288 }
00289
00290
00291
00292 void DTResolutionAnalysisTest::bookHistos(int wh) {
00293
00294 stringstream wheel; wheel <<wh;
00295
00296 dbe->setCurrentFolder(topHistoFolder + "/00-MeanRes");
00297 string histoName = "MeanSummaryRes_W" + wheel.str();
00298 stringstream meanRange; meanRange << (permittedMeanRange*10000);
00299 string histoTitle = "# of SLs with wrong mean of residuals (Wheel " + wheel.str() + ")";
00300 wheelMeanHistos[wh] = dbe->book2D(histoName.c_str(),histoTitle.c_str(),12,1,13,11,1,12);
00301 wheelMeanHistos[wh]->setAxisTitle("Sector",1);
00302 wheelMeanHistos[wh]->setBinLabel(1,"MB1_SL1",2);
00303 wheelMeanHistos[wh]->setBinLabel(2,"MB1_SL2",2);
00304 wheelMeanHistos[wh]->setBinLabel(3,"MB1_SL3",2);
00305 wheelMeanHistos[wh]->setBinLabel(4,"MB2_SL1",2);
00306 wheelMeanHistos[wh]->setBinLabel(5,"MB2_SL2",2);
00307 wheelMeanHistos[wh]->setBinLabel(6,"MB2_SL3",2);
00308 wheelMeanHistos[wh]->setBinLabel(7,"MB3_SL1",2);
00309 wheelMeanHistos[wh]->setBinLabel(8,"MB3_SL2",2);
00310 wheelMeanHistos[wh]->setBinLabel(9,"MB3_SL3",2);
00311 wheelMeanHistos[wh]->setBinLabel(10,"MB4_SL1",2);
00312 wheelMeanHistos[wh]->setBinLabel(11,"MB4_SL3",2);
00313
00314
00315
00316
00317
00318 dbe->setCurrentFolder(topHistoFolder + "/01-SigmaRes");
00319 histoName = "SigmaSummaryRes_W" + wheel.str();
00320 stringstream sigmaRange; sigmaRange << (permittedSigmaRange*10000);
00321 histoTitle = "# of SLs with wrong sigma of residuals (Wheel " + wheel.str() + ")";
00322 wheelSigmaHistos[wh] = dbe->book2D(histoName.c_str(),histoTitle.c_str(),12,1,13,11,1,12);
00323 wheelSigmaHistos[wh]->setAxisTitle("Sector",1);
00324 wheelSigmaHistos[wh]->setBinLabel(1,"MB1_SL1",2);
00325 wheelSigmaHistos[wh]->setBinLabel(2,"MB1_SL2",2);
00326 wheelSigmaHistos[wh]->setBinLabel(3,"MB1_SL3",2);
00327 wheelSigmaHistos[wh]->setBinLabel(4,"MB2_SL1",2);
00328 wheelSigmaHistos[wh]->setBinLabel(5,"MB2_SL2",2);
00329 wheelSigmaHistos[wh]->setBinLabel(6,"MB2_SL3",2);
00330 wheelSigmaHistos[wh]->setBinLabel(7,"MB3_SL1",2);
00331 wheelSigmaHistos[wh]->setBinLabel(8,"MB3_SL2",2);
00332 wheelSigmaHistos[wh]->setBinLabel(9,"MB3_SL3",2);
00333 wheelSigmaHistos[wh]->setBinLabel(10,"MB4_SL1",2);
00334 wheelSigmaHistos[wh]->setBinLabel(11,"MB4_SL3",2);
00335
00336
00337
00338 }
00339
00340
00341 void DTResolutionAnalysisTest::bookHistos(int wh, int sect) {
00342
00343 stringstream wheel; wheel << wh;
00344 stringstream sector; sector << sect;
00345
00346
00347 string MeanHistoName = "MeanTest_W" + wheel.str() + "_Sec" + sector.str();
00348 string SigmaHistoName = "SigmaTest_W" + wheel.str() + "_Sec" + sector.str();
00349
00350 string folder = topHistoFolder + "/Wheel" + wheel.str() + "/Sector" + sector.str();
00351 dbe->setCurrentFolder(folder);
00352
00353 if(sect!=4 && sect!=10) {
00354 MeanHistos[make_pair(wh,sect)] =
00355 dbe->book1D(MeanHistoName.c_str(),"Mean (from gaussian fit) of the residuals distribution",11,1,12);
00356 } else {
00357 MeanHistos[make_pair(wh,sect)] =
00358 dbe->book1D(MeanHistoName.c_str(),"Mean (from gaussian fit) of the residuals distribution",13,1,14);
00359 }
00360 (MeanHistos[make_pair(wh,sect)])->setBinLabel(1,"MB1_SL1",1);
00361 (MeanHistos[make_pair(wh,sect)])->setBinLabel(2,"MB1_SL2",1);
00362 (MeanHistos[make_pair(wh,sect)])->setBinLabel(3,"MB1_SL3",1);
00363 (MeanHistos[make_pair(wh,sect)])->setBinLabel(4,"MB2_SL1",1);
00364 (MeanHistos[make_pair(wh,sect)])->setBinLabel(5,"MB2_SL2",1);
00365 (MeanHistos[make_pair(wh,sect)])->setBinLabel(6,"MB2_SL3",1);
00366 (MeanHistos[make_pair(wh,sect)])->setBinLabel(7,"MB3_SL1",1);
00367 (MeanHistos[make_pair(wh,sect)])->setBinLabel(8,"MB3_SL2",1);
00368 (MeanHistos[make_pair(wh,sect)])->setBinLabel(9,"MB3_SL3",1);
00369 (MeanHistos[make_pair(wh,sect)])->setBinLabel(10,"MB4_SL1",1);
00370 (MeanHistos[make_pair(wh,sect)])->setBinLabel(11,"MB4_SL3",1);
00371 if(sect==4){
00372 (MeanHistos[make_pair(wh,sect)])->setBinLabel(12,"MB4S13_SL1",1);
00373 (MeanHistos[make_pair(wh,sect)])->setBinLabel(13,"MB4S13_SL3",1);
00374 }
00375 if(sect==10){
00376 (MeanHistos[make_pair(wh,sect)])->setBinLabel(12,"MB4S14_SL1",1);
00377 (MeanHistos[make_pair(wh,sect)])->setBinLabel(13,"MB4S14_SL3",1);
00378 }
00379
00380 if(sect!=4 && sect!=10) {
00381 SigmaHistos[make_pair(wh,sect)] =
00382 dbe->book1D(SigmaHistoName.c_str(),"Sigma (from gaussian fit) of the residuals distribution",11,1,12);
00383 } else {
00384 SigmaHistos[make_pair(wh,sect)] =
00385 dbe->book1D(SigmaHistoName.c_str(),"Sigma (from gaussian fit) of the residuals distribution",13,1,14);
00386 }
00387 (SigmaHistos[make_pair(wh,sect)])->setBinLabel(1,"MB1_SL1",1);
00388 (SigmaHistos[make_pair(wh,sect)])->setBinLabel(2,"MB1_SL2",1);
00389 (SigmaHistos[make_pair(wh,sect)])->setBinLabel(3,"MB1_SL3",1);
00390 (SigmaHistos[make_pair(wh,sect)])->setBinLabel(4,"MB2_SL1",1);
00391 (SigmaHistos[make_pair(wh,sect)])->setBinLabel(5,"MB2_SL2",1);
00392 (SigmaHistos[make_pair(wh,sect)])->setBinLabel(6,"MB2_SL3",1);
00393 (SigmaHistos[make_pair(wh,sect)])->setBinLabel(7,"MB3_SL1",1);
00394 (SigmaHistos[make_pair(wh,sect)])->setBinLabel(8,"MB3_SL2",1);
00395 (SigmaHistos[make_pair(wh,sect)])->setBinLabel(9,"MB3_SL3",1);
00396 (SigmaHistos[make_pair(wh,sect)])->setBinLabel(10,"MB4_SL1",1);
00397 (SigmaHistos[make_pair(wh,sect)])->setBinLabel(11,"MB4_SL3",1);
00398 if(sect==4){
00399 (SigmaHistos[make_pair(wh,sect)])->setBinLabel(12,"MB4S13_SL1",1);
00400 (SigmaHistos[make_pair(wh,sect)])->setBinLabel(13,"MB4S13_SL3",1);
00401 }
00402 if(sect==10){
00403 (SigmaHistos[make_pair(wh,sect)])->setBinLabel(12,"MB4S14_SL1",1);
00404 (SigmaHistos[make_pair(wh,sect)])->setBinLabel(13,"MB4S14_SL3",1);
00405 }
00406
00407
00408 }
00409
00410
00411 string DTResolutionAnalysisTest::getMEName(const DTSuperLayerId & slID) {
00412
00413 stringstream wheel; wheel << slID.wheel();
00414 stringstream station; station << slID.station();
00415 stringstream sector; sector << slID.sector();
00416 stringstream superLayer; superLayer << slID.superlayer();
00417
00418 string folderName =
00419 topHistoFolder + "/Wheel" + wheel.str() +
00420 "/Sector" + sector.str() +
00421 "/Station" + station.str() + "/";
00422
00423 if(doCalibAnalysis) folderName =
00424 "DT/DTCalibValidation/Wheel" + wheel.str() +
00425 "/Station" + station.str() + "/Sector" + sector.str() + "/";
00426
00427 string histoname = folderName + "hResDist"
00428 + "_W" + wheel.str()
00429 + "_St" + station.str()
00430 + "_Sec" + sector.str()
00431 + "_SL" + superLayer.str();
00432
00433 if(doCalibAnalysis) histoname = folderName + "hResDist_STEP3"
00434 + "_W" + wheel.str()
00435 + "_St" + station.str()
00436 + "_Sec" + sector.str()
00437 + "_SL" + superLayer.str();
00438
00439 return histoname;
00440
00441 }
00442
00443
00444
00445 int DTResolutionAnalysisTest::stationFromBin(int bin) const {
00446 return (int) (bin /3.1)+1;
00447 }
00448
00449
00450 int DTResolutionAnalysisTest::slFromBin(int bin) const {
00451 int ret = bin%3;
00452 if(ret == 0 || bin == 11) ret = 3;
00453
00454 return ret;
00455 }
00456
00457
00458 bool DTResolutionAnalysisTest::meanInRange(double mean) const {
00459 return fabs(mean) < permittedMeanRange;
00460 }
00461
00462
00463 bool DTResolutionAnalysisTest::sigmaInRange(double sigma) const {
00464 return sigma < permittedSigmaRange;
00465 }
00466
00467
00468 void DTResolutionAnalysisTest::resetMEs() {
00469 globalResSummary->Reset();
00470
00471 for(map<int, MonitorElement*> ::const_iterator histo = wheelMeanHistos.begin();
00472 histo != wheelMeanHistos.end();
00473 histo++) {
00474 (*histo).second->Reset();
00475 }
00476 for(map<int, MonitorElement*> ::const_iterator histo = wheelSigmaHistos.begin();
00477 histo != wheelSigmaHistos.end();
00478 histo++) {
00479 (*histo).second->Reset();
00480 }
00481
00482 for(int indx = -2; indx != 3; ++indx) {
00483 meanDistr[indx]->Reset();
00484 sigmaDistr[indx]->Reset();
00485 }
00486 }
00487