Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-05-20 22:34:16

0001 #include "DQMOffline/CalibMuon/interface/DTtTrigDBValidation.h"
0002 
0003 // Framework
0004 #include "FWCore/Framework/interface/ESHandle.h"
0005 #include "FWCore/Framework/interface/Event.h"
0006 #include "FWCore/Framework/interface/EventSetup.h"
0007 #include "FWCore/ServiceRegistry/interface/Service.h"
0008 
0009 #include "DQMServices/Core/interface/DQMStore.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 
0012 // Geometry
0013 #include "Geometry/DTGeometry/interface/DTTopology.h"
0014 
0015 // DataFormats
0016 #include "DataFormats/MuonDetId/interface/DTSuperLayerId.h"
0017 
0018 #include "TFile.h"
0019 #include <cmath>
0020 #include <cstdio>
0021 #include <sstream>
0022 
0023 using namespace edm;
0024 using namespace std;
0025 
0026 DTtTrigDBValidation::DTtTrigDBValidation(const ParameterSet &pset)
0027     : metname_("TTrigDBValidation"),
0028       labelDBRef_(esConsumes(edm::ESInputTag("", pset.getParameter<string>("labelDBRef")))),
0029       labelDB_(esConsumes(edm::ESInputTag("", pset.getParameter<string>("labelDB")))),
0030       lowerLimit_(pset.getUntrackedParameter<int>("lowerLimit", 1)),
0031       higherLimit_(pset.getUntrackedParameter<int>("higherLimit", 3)),
0032       muonGeomToken_(esConsumes()) {
0033   LogVerbatim(metname_) << "[DTtTrigDBValidation] Constructor called!";
0034 }
0035 
0036 DTtTrigDBValidation::~DTtTrigDBValidation() {}
0037 
0038 void DTtTrigDBValidation::bookHistograms(DQMStore::IBooker &iBooker, edm::Run const &, edm::EventSetup const &setup) {
0039   LogVerbatim(metname_) << "[DTtTrigDBValidation] Parameters initialization";
0040   iBooker.setCurrentFolder("DT/DtCalib/TTrigDBValidation");
0041 
0042   DTTtrigRefMap = &setup.getData(labelDBRef_);
0043   LogVerbatim(metname_) << "[DTtTrigDBValidation] reference Ttrig version: " << DTTtrigRefMap->version();
0044 
0045   DTTtrigMap = &setup.getData(labelDB_);
0046   LogVerbatim(metname_) << "[DTtTrigDBValidation] Ttrig to validate version: " << DTTtrigMap->version();
0047 
0048   // book&reset the summary histos
0049   for (int wheel = -2; wheel <= 2; wheel++) {
0050     bookHistos(iBooker, wheel);
0051     tTrigDiffWheel_[wheel]->Reset();
0052   }
0053 
0054   // Get the geometry
0055   dtGeom = &setup.getData(muonGeomToken_);
0056 
0057   // Loop over Ref DB entries
0058   for (DTTtrig::const_iterator it = DTTtrigRefMap->begin(); it != DTTtrigRefMap->end(); ++it) {
0059     DTSuperLayerId slId((*it).first.wheelId, (*it).first.stationId, (*it).first.sectorId, (*it).first.slId);
0060     float tTrigMean;
0061     float tTrigRms;
0062     float kFactor;
0063     DTTtrigRefMap->get(slId, tTrigMean, tTrigRms, kFactor, DTTimeUnits::ns);
0064     float tTrigCorr = tTrigMean + kFactor * tTrigRms;
0065     LogTrace(metname_) << "Ref Superlayer: " << slId << "\n"
0066                        << " Ttrig mean (ns): " << tTrigMean << " Ttrig rms (ns): " << tTrigRms
0067                        << " Ttrig k-Factor: " << kFactor << " Ttrig value (ns): " << tTrigCorr;
0068 
0069     // tTrigRefMap[slId] = std::pair<float,float>(tTrigmean,tTrigrms);
0070     tTrigRefMap_[slId] = pair<float, float>(tTrigCorr, tTrigRms);
0071   }
0072 
0073   // Loop over Ref DB entries
0074   for (DTTtrig::const_iterator it = DTTtrigMap->begin(); it != DTTtrigMap->end(); ++it) {
0075     DTSuperLayerId slId((*it).first.wheelId, (*it).first.stationId, (*it).first.sectorId, (*it).first.slId);
0076     float tTrigMean;
0077     float tTrigRms;
0078     float kFactor;
0079     DTTtrigMap->get(slId, tTrigMean, tTrigRms, kFactor, DTTimeUnits::ns);
0080     float tTrigCorr = tTrigMean + kFactor * tTrigRms;
0081     LogTrace(metname_) << "Superlayer: " << slId << "\n"
0082                        << " Ttrig mean (ns): " << tTrigMean << " Ttrig rms (ns): " << tTrigRms
0083                        << " Ttrig k-Factor: " << kFactor << " Ttrig value (ns): " << tTrigCorr;
0084 
0085     // tTrigMap[slId] = std::pair<float,float>(tTrigmean,tTrigrms);
0086     tTrigMap_[slId] = pair<float, float>(tTrigCorr, tTrigRms);
0087   }
0088 
0089   for (map<DTSuperLayerId, pair<float, float>>::const_iterator it = tTrigRefMap_.begin(); it != tTrigRefMap_.end();
0090        ++it) {
0091     if (tTrigMap_.find((*it).first) == tTrigMap_.end())
0092       continue;
0093 
0094     // compute the difference
0095     float difference = tTrigMap_[(*it).first].first - (*it).second.first;
0096 
0097     // book histo
0098     int wheel = (*it).first.chamberId().wheel();
0099     int sector = (*it).first.chamberId().sector();
0100     if (tTrigDiffHistos_.find(make_pair(wheel, sector)) == tTrigDiffHistos_.end())
0101       bookHistos(iBooker, wheel, sector);
0102 
0103     LogTrace(metname_) << "Filling histos for super-layer: " << (*it).first << "  difference: " << difference;
0104 
0105     // Fill the test histos
0106     int entry = -1;
0107     int station = (*it).first.chamberId().station();
0108     if (station == 1)
0109       entry = 0;
0110     if (station == 2)
0111       entry = 3;
0112     if (station == 3)
0113       entry = 6;
0114     if (station == 4)
0115       entry = 9;
0116 
0117     int slBin = entry + (*it).first.superLayer();
0118     if (slBin == 12)
0119       slBin = 11;
0120 
0121     tTrigDiffHistos_[make_pair(wheel, sector)]->setBinContent(slBin, difference);
0122     if (abs(difference) < lowerLimit_) {
0123       tTrigDiffWheel_[wheel]->setBinContent(slBin, sector, 1);
0124     } else if (abs(difference) < higherLimit_) {
0125       tTrigDiffWheel_[wheel]->setBinContent(slBin, sector, 2);
0126     } else {
0127       tTrigDiffWheel_[wheel]->setBinContent(slBin, sector, 3);
0128     }
0129 
0130   }  // Loop over the tTrig map reference
0131 }
0132 
0133 void DTtTrigDBValidation::bookHistos(DQMStore::IBooker &iBooker, int wheel, int sector) {
0134   LogTrace(metname_) << "   Booking histos for Wheel, Sector: " << wheel << ", " << sector;
0135 
0136   // Compose the chamber name
0137   stringstream str_wheel;
0138   str_wheel << wheel;
0139   stringstream str_sector;
0140   str_sector << sector;
0141 
0142   string lHistoName = "_W" + str_wheel.str() + "_Sec" + str_sector.str();
0143 
0144   iBooker.setCurrentFolder("DT/DtCalib/TTrigDBValidation/Wheel" + str_wheel.str());
0145 
0146   // Create the monitor elements
0147   MonitorElement *hDifference;
0148   hDifference = iBooker.book1D("TTrigDifference" + lHistoName, "difference between the two tTrig values", 11, 0, 11);
0149 
0150   pair<int, int> mypair(wheel, sector);
0151   tTrigDiffHistos_[mypair] = hDifference;
0152 
0153   (tTrigDiffHistos_[mypair])->setBinLabel(1, "MB1_SL1", 1);
0154   (tTrigDiffHistos_[mypair])->setBinLabel(2, "MB1_SL2", 1);
0155   (tTrigDiffHistos_[mypair])->setBinLabel(3, "MB1_SL3", 1);
0156   (tTrigDiffHistos_[mypair])->setBinLabel(4, "MB2_SL1", 1);
0157   (tTrigDiffHistos_[mypair])->setBinLabel(5, "MB2_SL2", 1);
0158   (tTrigDiffHistos_[mypair])->setBinLabel(6, "MB2_SL3", 1);
0159   (tTrigDiffHistos_[mypair])->setBinLabel(7, "MB3_SL1", 1);
0160   (tTrigDiffHistos_[mypair])->setBinLabel(8, "MB3_SL2", 1);
0161   (tTrigDiffHistos_[mypair])->setBinLabel(9, "MB3_SL3", 1);
0162   (tTrigDiffHistos_[mypair])->setBinLabel(10, "MB4_SL1", 1);
0163   (tTrigDiffHistos_[mypair])->setBinLabel(11, "MB4_SL3", 1);
0164 }
0165 
0166 // Book the summary histos
0167 void DTtTrigDBValidation::bookHistos(DQMStore::IBooker &iBooker, int wheel) {
0168   stringstream wh;
0169   wh << wheel;
0170 
0171   iBooker.setCurrentFolder("DT/DtCalib/TTrigDBValidation");
0172   tTrigDiffWheel_[wheel] = iBooker.book2D(
0173       "TTrigDifference_W" + wh.str(), "W" + wh.str() + ": summary of tTrig differences", 11, 1, 12, 14, 1, 15);
0174   tTrigDiffWheel_[wheel]->setBinLabel(1, "MB1_SL1", 1);
0175   tTrigDiffWheel_[wheel]->setBinLabel(2, "MB1_SL2", 1);
0176   tTrigDiffWheel_[wheel]->setBinLabel(3, "MB1_SL3", 1);
0177   tTrigDiffWheel_[wheel]->setBinLabel(4, "MB2_SL1", 1);
0178   tTrigDiffWheel_[wheel]->setBinLabel(5, "MB2_SL2", 1);
0179   tTrigDiffWheel_[wheel]->setBinLabel(6, "MB2_SL3", 1);
0180   tTrigDiffWheel_[wheel]->setBinLabel(7, "MB3_SL1", 1);
0181   tTrigDiffWheel_[wheel]->setBinLabel(8, "MB3_SL2", 1);
0182   tTrigDiffWheel_[wheel]->setBinLabel(9, "MB3_SL3", 1);
0183   tTrigDiffWheel_[wheel]->setBinLabel(10, "MB4_SL1", 1);
0184   tTrigDiffWheel_[wheel]->setBinLabel(11, "MB4_SL3", 1);
0185 }
0186 
0187 int DTtTrigDBValidation::stationFromBin(int bin) const { return (int)(bin / 3.1) + 1; }
0188 
0189 int DTtTrigDBValidation::slFromBin(int bin) const {
0190   int ret = bin % 3;
0191   if (ret == 0 || bin == 11)
0192     ret = 3;
0193 
0194   return ret;
0195 }
0196 
0197 void DTtTrigDBValidation::analyze(const edm::Event &, const edm::EventSetup &) {}