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