Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:07:06

0001 /******* \class DTRunConditionVarClient *******
0002  *
0003  * Description:
0004  *  
0005  *  detailed description
0006  *
0007  * \author : Paolo Bellan, Antonio Branca
0008  * $date   : 23/09/2011 15:42:04 CET $
0009  *
0010  * Modification:
0011  *
0012  *  threadsafe version (//-) oct/nov 2014 - WATWanAbdullah -ncpp-um-my
0013  *
0014  *
0015  *********************************/
0016 
0017 #include "DQM/DTMonitorClient/src/DTRunConditionVarClient.h"
0018 #include "DQMServices/Core/interface/DQMStore.h"
0019 
0020 #include "FWCore/Framework/interface/EventSetup.h"
0021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0022 
0023 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0024 #include "Geometry/DTGeometry/interface/DTGeometry.h"
0025 
0026 #include <cstdio>
0027 #include <sstream>
0028 #include <cmath>
0029 
0030 using namespace edm;
0031 using namespace std;
0032 
0033 DTRunConditionVarClient::DTRunConditionVarClient(const ParameterSet& pSet) {
0034   LogVerbatim("DTDQM|DTMonitorClient|DTRunConditionVarClient") << "DTRunConditionVarClient: Constructor called";
0035 
0036   minRangeVDrift = pSet.getUntrackedParameter<double>("minRangeVDrift");
0037   maxRangeVDrift = pSet.getUntrackedParameter<double>("maxRangeVDrift");
0038   minRangeT0 = pSet.getUntrackedParameter<double>("minRangeT0");
0039   maxRangeT0 = pSet.getUntrackedParameter<double>("maxRangeT0");
0040 
0041   maxGoodVDriftDev = pSet.getUntrackedParameter<double>("maxGoodVDriftDev");
0042   minBadVDriftDev = pSet.getUntrackedParameter<double>("minBadVDriftDev");
0043   maxGoodT0 = pSet.getUntrackedParameter<double>("maxGoodT0");
0044   minBadT0 = pSet.getUntrackedParameter<double>("minBadT0");
0045 
0046   maxGoodVDriftSigma = pSet.getUntrackedParameter<double>("maxGoodVDriftSigma");
0047   minBadVDriftSigma = pSet.getUntrackedParameter<double>("minBadVDriftSigma");
0048   maxGoodT0Sigma = pSet.getUntrackedParameter<double>("maxGoodT0Sigma");
0049   minBadT0Sigma = pSet.getUntrackedParameter<double>("minBadT0Sigma");
0050 
0051   readLegacyVDriftDB = pSet.getParameter<bool>("readLegacyVDriftDB");
0052 
0053   nevents = 0;
0054 
0055   bookingdone = false;
0056 
0057   if (readLegacyVDriftDB) {
0058     mTimeMapToken_ = esConsumes<edm::Transition::BeginRun>();
0059   } else {
0060     vDriftToken_ = esConsumes<edm::Transition::BeginRun>();
0061   }
0062 }
0063 
0064 DTRunConditionVarClient::~DTRunConditionVarClient() {
0065   LogVerbatim("DTDQM|DTMonitorClient|DTRunConditionVarClient") << "DTRunConditionVarClient: Destructor called";
0066 }
0067 
0068 void DTRunConditionVarClient::beginRun(const Run& run, const EventSetup& context) {
0069   LogTrace("DTDQM|DTMonitorClient|DTResolutionAnalysisTest") << "[DTRunConditionVarClient]: BeginRun";
0070   // Get the map of vdrift from the setup
0071   if (readLegacyVDriftDB) {
0072     mTimeMap_ = &context.getData(mTimeMapToken_);
0073     vDriftMap_ = nullptr;
0074   } else {
0075     vDriftMap_ = &context.getData(vDriftToken_);
0076     mTimeMap_ = nullptr;
0077     // Consistency check: no parametrization is implemented for the time being
0078     int version = vDriftMap_->version();
0079     if (version != 1) {
0080       throw cms::Exception("Configuration") << "only version 1 is presently supported for VDriftDB";
0081     }
0082   }
0083 }
0084 
0085 void DTRunConditionVarClient::dqmEndLuminosityBlock(DQMStore::IBooker& ibooker,
0086                                                     DQMStore::IGetter& igetter,
0087                                                     edm::LuminosityBlock const& lumiSeg,
0088                                                     edm::EventSetup const& context) {}
0089 
0090 void DTRunConditionVarClient::dqmEndJob(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) {
0091   LogVerbatim("DTDQM|DTMonitorClient|DTRunConditionVarClient") << "DTRunConditionVarClient: end job";
0092 
0093   ibooker.setCurrentFolder("DT/02-Segments");
0094 
0095   glbVDriftSummary =
0096       ibooker.book2D("VDriftGlbSummary", "# of MBs with good mean and good sigma of vDrift", 12, 1, 13, 5, -2, 3);
0097   glbT0Summary = ibooker.book2D("T0GlbSummary", "# of MBs with good mean and good sigma of t0", 12, 1, 13, 5, -2, 3);
0098 
0099   ibooker.setCurrentFolder("DT/02-Segments/02-MeanVDrift");
0100 
0101   summaryHistos["MeanVDriftGlbSummary"] =
0102       ibooker.book2D("MeanVDriftGlbSummary", "mean VDrift average per sector", 12, 1., 13., 5, -2., 3.);
0103   allwheelHistos["allMeanVDrift"] =
0104       ibooker.book1D("VDriftMeanAllWheels", "mean VDrift for all chambers", 60, 0.0048, 0.006);
0105 
0106   ibooker.setCurrentFolder("DT/02-Segments/02-SigmaVDrift");
0107 
0108   summaryHistos["SigmaVDriftGlbSummary"] =
0109       ibooker.book2D("SigmaVDriftGlbSummary", "# of Chambers with good sigma VDrift", 12, 1., 13., 5, -2., 3.);
0110   allwheelHistos["allSigmaVDrift"] =
0111       ibooker.book1D("VDriftSigmaAllWheels", "sigma VDrift for all chambers", 30, 0., 0.0006);
0112 
0113   ibooker.setCurrentFolder("DT/02-Segments/03-MeanT0");
0114 
0115   summaryHistos["MeanT0GlbSummary"] =
0116       ibooker.book2D("MeanT0GlbSummary", "mean T0 average per sector", 12, 1., 13., 5, -2., 3.);
0117   allwheelHistos["allMeanT0"] = ibooker.book1D("T0MeanAllWheels", "mean T0 for all chambers", 100, -25., 25.);
0118 
0119   ibooker.setCurrentFolder("DT/02-Segments/03-SigmaT0");
0120 
0121   summaryHistos["SigmaT0GlbSummary"] =
0122       ibooker.book2D("SigmaT0GlbSummary", "# of Chambers with good sigma T0", 12, 1., 13., 5, -2., 3.);
0123   allwheelHistos["allSigmaT0"] = ibooker.book1D("T0SigmaAllWheels", "sigma T0 for all chambers", 50, 0, 25);
0124 
0125   for (int wh = -2; wh <= 2; wh++) {
0126     bookWheelHistos(ibooker, "MeanVDrift", "02-MeanVDrift", wh, 60, 0.0048, 0.006, true);
0127     bookWheelHistos(ibooker, "SigmaVDrift", "02-SigmaVDrift", wh, 30, 0., 0.0006);
0128     bookWheelHistos(ibooker, "MeanT0", "03-MeanT0", wh, 100, -25., 25., false, true);
0129     bookWheelHistos(ibooker, "SigmaT0", "03-SigmaT0", wh, 50, 0, 25, false, true);
0130   }
0131 
0132   for (int wheel = -2; wheel <= 2; wheel++) {
0133     for (int sec = 1; sec <= 14; sec++) {
0134       for (int stat = 1; stat <= 4; stat++) {
0135         if ((sec == 13 || sec == 14) && stat != 4)
0136           continue;
0137 
0138         // Get the ME produced by DTRunConditionVar Source
0139         MonitorElement* VDriftME = getChamberHistos(igetter, DTChamberId(wheel, stat, sec), "VDrift_FromSegm");
0140         MonitorElement* T0ME = getChamberHistos(igetter, DTChamberId(wheel, stat, sec), "T0_FromSegm");
0141 
0142         if (!VDriftME || !T0ME) {
0143           edm::LogWarning("DTRunConditionVarClient") << "ME not available" << std::endl;
0144           return;
0145         }
0146 
0147         // Get the means per chamber
0148         float vDriftMean = VDriftME->getMean();
0149         T0ME->setAxisRange(-15, 15);
0150         float t0Mean = T0ME->getMean();
0151 
0152         // Get the sigma per chamber
0153         float vDriftSigma = VDriftME->getRMS();
0154         float t0Sigma = T0ME->getRMS();
0155 
0156         if (VDriftME->getEntries() != 0) {
0157           allwheelHistos["allMeanVDrift"]->Fill(vDriftMean);
0158           allwheelHistos["allSigmaVDrift"]->Fill(vDriftSigma);
0159 
0160           (wheelHistos[wheel])["MeanVDrift"]->Fill(vDriftMean);
0161           (wheelHistos[wheel])["SigmaVDrift"]->Fill(vDriftSigma);
0162         }
0163 
0164         if (T0ME->getEntries() != 0) {
0165           allwheelHistos["allMeanT0"]->Fill(t0Mean);
0166           allwheelHistos["allSigmaT0"]->Fill(t0Sigma);
0167 
0168           (wheelRingHistos[wheel][stat])["MeanT0"]->Fill(t0Mean);
0169           (wheelRingHistos[wheel][stat])["SigmaT0"]->Fill(t0Sigma);
0170         }
0171 
0172         DTChamberId indexCh(wheel, stat, sec);
0173 
0174         float vDriftDev(0.), errvDriftDev(0.);
0175         percDevVDrift(indexCh, vDriftMean, vDriftSigma, vDriftDev, errvDriftDev);
0176 
0177         int sec_ = sec;
0178         if (sec == 13 || sec == 14)
0179           sec_ = (sec == 13) ? 4 : 10;
0180 
0181         float fillvDriftDev = max(min(vDriftDev, maxRangeVDrift), minRangeVDrift);
0182         float fillT0Mean = max(min(t0Mean, maxRangeT0), minRangeT0);
0183 
0184         float vDriftDevQ = varQuality(fabs(vDriftDev), maxGoodVDriftDev, minBadVDriftDev);
0185         float t0MeanQ = varQuality(fabs(t0Mean), maxGoodT0, minBadT0);
0186 
0187         float vDriftSigmQ = varQuality(vDriftSigma, maxGoodVDriftSigma, minBadVDriftSigma);
0188         float t0SigmQ = varQuality(t0Sigma, maxGoodT0Sigma, minBadT0Sigma);
0189 
0190         if (sec == 13 || sec == 14) {
0191           float binVDriftDev = (wheelHistos[wheel])["MeanVDriftSummary"]->getBinContent(sec_, stat);
0192           binVDriftDev = (fabs(binVDriftDev) > fabs(fillvDriftDev)) ? binVDriftDev : fillvDriftDev;
0193           (wheelHistos[wheel])["MeanVDriftSummary"]->setBinContent(sec_, stat, binVDriftDev);
0194 
0195           float binT0MeanVal = (wheelHistos[wheel])["MeanT0Summary"]->getBinContent(sec_, stat);
0196           binT0MeanVal = (fabs(binT0MeanVal) > fabs(fillT0Mean)) ? binT0MeanVal : fillT0Mean;
0197           (wheelHistos[wheel])["MeanT0Summary"]->setBinContent(sec_, stat, binT0MeanVal);
0198 
0199           float binVDriftSigmVal = (wheelHistos[wheel])["SigmaVDriftSummary"]->getBinContent(sec_, stat);
0200           binVDriftSigmVal = (binVDriftSigmVal > 0. && binVDriftSigmVal < vDriftSigmQ) ? binVDriftSigmVal : vDriftSigmQ;
0201           (wheelHistos[wheel])["SigmaVDriftSummary"]->setBinContent(sec_, stat, binVDriftSigmVal);
0202 
0203           float binT0SigmVal = (wheelHistos[wheel])["SigmaT0Summary"]->getBinContent(sec_, stat);
0204           binT0SigmVal = (binT0SigmVal > 0. && binT0SigmVal < t0SigmQ) ? binT0SigmVal : t0SigmQ;
0205           (wheelHistos[wheel])["SigmaT0Summary"]->setBinContent(sec_, stat, binT0SigmVal);
0206 
0207         } else {
0208           (wheelHistos[wheel])["MeanVDriftSummary"]->setBinContent(sec_, stat, fillvDriftDev);
0209           (wheelHistos[wheel])["MeanT0Summary"]->setBinContent(sec_, stat, fillT0Mean);
0210           (wheelHistos[wheel])["SigmaVDriftSummary"]->setBinContent(sec_, stat, vDriftSigmQ);
0211           (wheelHistos[wheel])["SigmaT0Summary"]->setBinContent(sec_, stat, t0SigmQ);
0212         }
0213 
0214         double weight = 1 / 4.;
0215         if ((sec_ == 4 || sec_ == 10) && stat == 4)
0216           weight = 1 / 8.;
0217 
0218         if (vDriftDevQ > 0.85 && vDriftSigmQ > 0.85) {
0219           glbVDriftSummary->Fill(sec_, wheel, weight);
0220           summaryHistos["MeanVDriftGlbSummary"]->Fill(sec_, wheel, weight);
0221           summaryHistos["SigmaVDriftGlbSummary"]->Fill(sec_, wheel, weight);
0222 
0223         } else {
0224           if (vDriftDevQ > 0.85 && vDriftSigmQ < 0.85) {
0225             summaryHistos["MeanVDriftGlbSummary"]->Fill(sec_, wheel, weight);
0226           }
0227           if (vDriftDevQ < 0.85 && vDriftSigmQ > 0.85) {
0228             summaryHistos["SigmaVDriftGlbSummary"]->Fill(sec_, wheel, weight);
0229           }
0230         }
0231 
0232         if (t0MeanQ > 0.85 && t0SigmQ > 0.85) {
0233           glbT0Summary->Fill(sec_, wheel, weight);
0234           summaryHistos["MeanT0GlbSummary"]->Fill(sec_, wheel, weight);
0235           summaryHistos["SigmaT0GlbSummary"]->Fill(sec_, wheel, weight);
0236         } else {
0237           if (t0MeanQ > 0.85 && t0SigmQ < 0.85) {
0238             summaryHistos["MeanT0GlbSummary"]->Fill(sec_, wheel, weight);
0239           }
0240           if (t0MeanQ < 0.85 && t0SigmQ > 0.85) {
0241             summaryHistos["SigmaT0GlbSummary"]->Fill(sec_, wheel, weight);
0242           }
0243         }
0244 
0245       }  // end loop on stations
0246     }    // end loop on sectors
0247   }      //end loop on wheels
0248 
0249   return;
0250 }
0251 
0252 float DTRunConditionVarClient::varQuality(float var, float maxGood, float minBad) {
0253   float qual(0);
0254   if (var <= maxGood) {
0255     qual = 1.;
0256   } else if (var > maxGood && var < minBad) {
0257     qual = 0.9;
0258   } else if (var >= minBad) {
0259     qual = 0.1;
0260   }
0261 
0262   return qual;
0263 }
0264 
0265 void DTRunConditionVarClient::percDevVDrift(
0266     DTChamberId indexCh, float meanVD, float sigmaVD, float& devVD, float& errdevVD) {
0267   DTSuperLayerId indexSLPhi1(indexCh, 1);
0268   DTSuperLayerId indexSLPhi2(indexCh, 3);
0269 
0270   float vDriftPhi1(0.), vDriftPhi2(0.);
0271   float ResPhi1(0.), ResPhi2(0.);
0272   if (readLegacyVDriftDB) {  // Legacy format
0273     int status1 = mTimeMap_->get(indexSLPhi1, vDriftPhi1, ResPhi1, DTVelocityUnits::cm_per_ns);
0274     int status2 = mTimeMap_->get(indexSLPhi2, vDriftPhi2, ResPhi2, DTVelocityUnits::cm_per_ns);
0275 
0276     if (status1 != 0 || status2 != 0) {
0277       DTSuperLayerId sl = (status1 != 0) ? indexSLPhi1 : indexSLPhi2;
0278       throw cms::Exception("DTRunConditionVarClient") << "Could not find vDrift entry in DB for" << sl << endl;
0279     }
0280   } else {
0281     vDriftPhi1 = vDriftMap_->get(DTWireId(indexSLPhi1.rawId()));
0282     vDriftPhi2 = vDriftMap_->get(DTWireId(indexSLPhi2.rawId()));
0283   }
0284 
0285   float vDriftMed = (vDriftPhi1 + vDriftPhi2) / 2.;
0286 
0287   devVD = (meanVD - vDriftMed) / vDriftMed;
0288   devVD = devVD < 1. ? devVD : 1.;
0289 
0290   errdevVD = sigmaVD / vDriftMed;
0291 
0292   return;
0293 }
0294 
0295 void DTRunConditionVarClient::bookWheelHistos(DQMStore::IBooker& ibooker,
0296                                               string histoType,
0297                                               string subfolder,
0298                                               int wh,
0299                                               int nbins,
0300                                               float min,
0301                                               float max,
0302                                               bool isVDCorr,
0303                                               bool makeRings) {
0304   stringstream wheel;
0305   wheel << wh;
0306 
0307   string folder = "DT/02-Segments/" + subfolder;
0308 
0309   ibooker.setCurrentFolder(folder);
0310 
0311   string histoName;
0312   string histoLabel;
0313 
0314   if (makeRings) {
0315     ibooker.setCurrentFolder(folder + "/Wheel" + wheel.str());
0316     for (int st = 1; st <= 4; st++) {
0317       stringstream station;
0318       station << st;
0319 
0320       histoName = histoType + "_W" + wheel.str() + "_MB" + station.str();
0321       histoLabel = histoType;
0322 
0323       (wheelRingHistos[wh][st])[histoType] = ibooker.book1D(histoName, histoLabel, nbins, min, max);
0324     }
0325   } else {
0326     histoName = histoType + "_W" + wheel.str();
0327     histoLabel = histoType;
0328 
0329     (wheelHistos[wh])[histoType] = ibooker.book1D(histoName, histoLabel, nbins, min, max);
0330   }
0331 
0332   ibooker.setCurrentFolder(folder);
0333 
0334   if (isVDCorr) {
0335     histoLabel = "Summary of corrections to VDrift DB values";
0336     histoName = "CorrTo" + histoType + "Summary_W" + wheel.str();
0337   } else {
0338     histoLabel = histoType + "Summary";
0339     histoName = histoType + "Summary_W" + wheel.str();
0340   }
0341 
0342   MonitorElement* me = ibooker.book2D(histoName, histoLabel, 12, 1, 13, 4, 1, 5);
0343 
0344   me->setBinLabel(1, "MB1", 2);
0345   me->setBinLabel(2, "MB2", 2);
0346   me->setBinLabel(3, "MB3", 2);
0347   me->setBinLabel(4, "MB4", 2);
0348   me->setAxisTitle("Sector", 1);
0349 
0350   (wheelHistos[wh])[histoType + "Summary"] = me;
0351 
0352   return;
0353 }
0354 
0355 DTRunConditionVarClient::MonitorElement* DTRunConditionVarClient::getChamberHistos(DQMStore::IGetter& igetter,
0356                                                                                    const DTChamberId& dtCh,
0357                                                                                    string histoType) {
0358   int wh = dtCh.wheel();
0359   int sc = dtCh.sector();
0360   int st = dtCh.station();
0361   stringstream wheel;
0362   wheel << wh;
0363   stringstream station;
0364   station << st;
0365   stringstream sector;
0366   sector << sc;
0367 
0368   string folder = "DT/02-Segments/Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" + station.str();
0369   string histoTag = "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
0370   string MEpath = folder + "/" + histoType + histoTag;
0371 
0372   igetter.setCurrentFolder(folder);
0373 
0374   LogTrace("DTDQM|DTMonitorModule|DTRunConditionVar") << "[DTRunConditionVar]: getting ME from " << folder << endl;
0375 
0376   MonitorElement* ME = igetter.get(MEpath);
0377 
0378   return ME;
0379 }