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