Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 
0002 /*
0003  *  See header file for a description of this class.
0004  *
0005  *  \author G. Mila - INFN Torino
0006  */
0007 
0008 #include "DQMOffline/CalibMuon/interface/DTt0DBValidation.h"
0009 
0010 // Framework
0011 #include "FWCore/Framework/interface/ESHandle.h"
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/Framework/interface/EventSetup.h"
0014 #include "FWCore/ServiceRegistry/interface/Service.h"
0015 
0016 #include "DQMServices/Core/interface/DQMStore.h"
0017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0018 
0019 // Geometry
0020 #include "Geometry/DTGeometry/interface/DTGeometry.h"
0021 #include "Geometry/DTGeometry/interface/DTLayer.h"
0022 #include "Geometry/DTGeometry/interface/DTTopology.h"
0023 
0024 // t0
0025 #include "CondFormats/DTObjects/interface/DTT0.h"
0026 
0027 #include "TFile.h"
0028 
0029 #include <iomanip>
0030 #include <sstream>
0031 
0032 using namespace edm;
0033 using namespace std;
0034 
0035 DTt0DBValidation::DTt0DBValidation(const ParameterSet &pset)
0036     : labelDBRef_(esConsumes(edm::ESInputTag("", pset.getParameter<string>("labelDBRef")))),
0037       labelDB_(esConsumes(edm::ESInputTag("", pset.getParameter<string>("labelDB")))),
0038       muonGeomToken_(esConsumes()) {
0039   metname_ = "InterChannelSynchDBValidation";
0040   LogVerbatim(metname_) << "[DTt0DBValidation] Constructor called!";
0041 
0042   // Get the DQM needed services
0043   dbe_ = edm::Service<DQMStore>().operator->();
0044   dbe_->setCurrentFolder("DT/DtCalib/InterChannelSynchDBValidation");
0045 
0046   t0TestName_ = "t0DifferenceInRange";
0047   if (pset.exists("t0TestName"))
0048     t0TestName_ = pset.getParameter<string>("t0TestName");
0049 
0050   outputMEsInRootFile_ = false;
0051   if (pset.exists("OutputFileName")) {
0052     outputMEsInRootFile_ = true;
0053     outputFileName_ = pset.getParameter<std::string>("OutputFileName");
0054   }
0055 }
0056 
0057 DTt0DBValidation::~DTt0DBValidation() {}
0058 
0059 void DTt0DBValidation::beginRun(const edm::Run &run, const EventSetup &setup) {
0060   metname_ = "InterChannelSynchDBValidation";
0061   LogVerbatim(metname_) << "[DTt0DBValidation] Parameters initialization";
0062 
0063   tZeroRefMap_ = &setup.getData(labelDBRef_);
0064   ;
0065   LogVerbatim(metname_) << "[DTt0DBValidation] reference T0 version: " << tZeroRefMap_->version();
0066 
0067   tZeroMap_ = &setup.getData(labelDB_);
0068   LogVerbatim(metname_) << "[DTt0DBValidation] T0 to validate version: " << tZeroMap_->version();
0069 
0070   // book&reset the summary histos
0071   for (int wheel = -2; wheel <= 2; wheel++) {
0072     bookHistos(wheel);
0073     wheelSummary_[wheel]->Reset();
0074   }
0075 
0076   // Get the geometry
0077   dtGeom = &setup.getData(muonGeomToken_);
0078 
0079   // Loop over Ref DB entries
0080   for (DTT0::const_iterator tzero = tZeroRefMap_->begin(); tzero != tZeroRefMap_->end(); tzero++) {
0081     // t0s and rms are TDC counts
0082     // @@@ NEW DTT0 FORMAT
0083     //    DTWireId wireId((*tzero).first.wheelId,
0084     //          (*tzero).first.stationId,
0085     //          (*tzero).first.sectorId,
0086     //          (*tzero).first.slId,
0087     //          (*tzero).first.layerId,
0088     //          (*tzero).first.cellId);
0089     int channelId = tzero->channelId;
0090     if (channelId == 0)
0091       continue;
0092     DTWireId wireId(channelId);
0093     // @@@ NEW DTT0 END
0094     float t0mean;
0095     float t0rms;
0096     tZeroRefMap_->get(wireId, t0mean, t0rms, DTTimeUnits::counts);
0097     LogTrace(metname_) << "Ref Wire: " << wireId << endl
0098                        << " T0 mean (TDC counts): " << t0mean << " T0_rms (TDC counts): " << t0rms;
0099 
0100     t0RefMap_[wireId].push_back(t0mean);
0101     t0RefMap_[wireId].push_back(t0rms);
0102   }
0103 
0104   // Loop over Ref DB entries
0105   for (DTT0::const_iterator tzero = tZeroMap_->begin(); tzero != tZeroMap_->end(); tzero++) {
0106     // t0s and rms are TDC counts
0107     // @@@ NEW DTT0 FORMAT
0108     //    DTWireId wireId((*tzero).first.wheelId,
0109     //          (*tzero).first.stationId,
0110     //          (*tzero).first.sectorId,
0111     //          (*tzero).first.slId,
0112     //          (*tzero).first.layerId,
0113     //          (*tzero).first.cellId);
0114     int channelId = tzero->channelId;
0115     if (channelId == 0)
0116       continue;
0117     DTWireId wireId(channelId);
0118     // @@@ NEW DTT0 END
0119     float t0mean;
0120     float t0rms;
0121     tZeroMap_->get(wireId, t0mean, t0rms, DTTimeUnits::counts);
0122     LogTrace(metname_) << "Wire: " << wireId << endl
0123                        << " T0 mean (TDC counts): " << t0mean << " T0_rms (TDC counts): " << t0rms;
0124 
0125     t0Map_[wireId].push_back(t0mean);
0126     t0Map_[wireId].push_back(t0rms);
0127   }
0128 
0129   double difference = 0;
0130   for (map<DTWireId, vector<float>>::const_iterator theMap = t0RefMap_.begin(); theMap != t0RefMap_.end(); theMap++) {
0131     if (t0Map_.find((*theMap).first) != t0Map_.end()) {
0132       // Compute the difference
0133       difference = t0Map_[(*theMap).first][0] - (*theMap).second[0];
0134 
0135       // book histo
0136       DTLayerId layerId = (*theMap).first.layerId();
0137       if (t0DiffHistos_.find(layerId) == t0DiffHistos_.end()) {
0138         const DTTopology &dtTopo = dtGeom->layer(layerId)->specificTopology();
0139         const int firstWire = dtTopo.firstChannel();
0140         const int lastWire = dtTopo.lastChannel();
0141         bookHistos(layerId, firstWire, lastWire);
0142       }
0143 
0144       LogTrace(metname_) << "Filling the histo for wire: " << (*theMap).first << "  difference: " << difference;
0145       t0DiffHistos_[layerId]->Fill((*theMap).first.wire(), difference);
0146     }
0147   }  // Loop over the t0 map reference
0148 }
0149 
0150 void DTt0DBValidation::endRun(edm::Run const &run, edm::EventSetup const &setup) {
0151   // Check the histos
0152   string testCriterionName = t0TestName_;
0153   for (map<DTLayerId, MonitorElement *>::const_iterator hDiff = t0DiffHistos_.begin(); hDiff != t0DiffHistos_.end();
0154        hDiff++) {
0155     const QReport *theDiffQReport = (*hDiff).second->getQReport(testCriterionName);
0156     if (theDiffQReport) {
0157       int xBin = ((*hDiff).first.station() - 1) * 12 + (*hDiff).first.layer() + 4 * ((*hDiff).first.superlayer() - 1);
0158       if ((*hDiff).first.station() == 4 && (*hDiff).first.superlayer() == 3)
0159         xBin = ((*hDiff).first.station() - 1) * 12 + (*hDiff).first.layer() + 4 * ((*hDiff).first.superlayer() - 2);
0160 
0161       int qReportStatus = theDiffQReport->getStatus() / 100;
0162       wheelSummary_[(*hDiff).first.wheel()]->setBinContent(xBin, (*hDiff).first.sector(), qReportStatus);
0163 
0164       LogVerbatim(metname_) << "-------- layer: " << (*hDiff).first << "  " << theDiffQReport->getMessage()
0165                             << " ------- " << theDiffQReport->getStatus() << " ------- " << setprecision(3)
0166                             << theDiffQReport->getQTresult();
0167       vector<dqm::me_util::Channel> badChannels = theDiffQReport->getBadChannels();
0168       for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); channel != badChannels.end();
0169            channel++) {
0170         LogVerbatim(metname_) << "layer: " << (*hDiff).first << " Bad channel: " << (*channel).getBin()
0171                               << "  Contents : " << (*channel).getContents();
0172 
0173         // wheelSummary_[(*hDiff).first.wheel()]->Fill(xBin,(*hDiff).first.sector());
0174       }
0175     }
0176   }
0177 }
0178 
0179 void DTt0DBValidation::endJob() {
0180   // Write the histos on a file
0181   if (outputMEsInRootFile_)
0182     dbe_->save(outputFileName_);
0183 }
0184 
0185 // Book a set of histograms for a given Layer
0186 void DTt0DBValidation::bookHistos(DTLayerId lId, int firstWire, int lastWire) {
0187   LogTrace(metname_) << "   Booking histos for L: " << lId;
0188 
0189   // Compose the chamber name
0190   stringstream wheel;
0191   wheel << lId.superlayerId().chamberId().wheel();
0192   stringstream station;
0193   station << lId.superlayerId().chamberId().station();
0194   stringstream sector;
0195   sector << lId.superlayerId().chamberId().sector();
0196   stringstream superLayer;
0197   superLayer << lId.superlayerId().superlayer();
0198   stringstream layer;
0199   layer << lId.layer();
0200 
0201   string lHistoName = "_W" + wheel.str() + "_St" + station.str() + "_Sec" + sector.str() + "_SL" + superLayer.str() +
0202                       "_L" + layer.str();
0203 
0204   dbe_->setCurrentFolder("DT/DtCalib/InterChannelSynchDBValidation/Wheel" + wheel.str() + "/Station" + station.str() +
0205                          "/Sector" + sector.str() + "/SuperLayer" + superLayer.str());
0206   // Create the monitor elements
0207   MonitorElement *hDifference;
0208   hDifference = dbe_->book1D("T0Difference" + lHistoName,
0209                              "difference between the two t0 values",
0210                              lastWire - firstWire + 1,
0211                              firstWire - 0.5,
0212                              lastWire + 0.5);
0213 
0214   t0DiffHistos_[lId] = hDifference;
0215 }
0216 
0217 // Book the summary histos
0218 void DTt0DBValidation::bookHistos(int wheel) {
0219   dbe_->setCurrentFolder("DT/DtCalib/InterChannelSynchDBValidation");
0220   stringstream wh;
0221   wh << wheel;
0222   wheelSummary_[wheel] = dbe_->book2D(
0223       "SummaryWrongT0_W" + wh.str(), "W" + wh.str() + ": summary of wrong t0 differences", 44, 1, 45, 14, 1, 15);
0224   wheelSummary_[wheel]->setBinLabel(1, "M1L1", 1);
0225   wheelSummary_[wheel]->setBinLabel(2, "M1L2", 1);
0226   wheelSummary_[wheel]->setBinLabel(3, "M1L3", 1);
0227   wheelSummary_[wheel]->setBinLabel(4, "M1L4", 1);
0228   wheelSummary_[wheel]->setBinLabel(5, "M1L5", 1);
0229   wheelSummary_[wheel]->setBinLabel(6, "M1L6", 1);
0230   wheelSummary_[wheel]->setBinLabel(7, "M1L7", 1);
0231   wheelSummary_[wheel]->setBinLabel(8, "M1L8", 1);
0232   wheelSummary_[wheel]->setBinLabel(9, "M1L9", 1);
0233   wheelSummary_[wheel]->setBinLabel(10, "M1L10", 1);
0234   wheelSummary_[wheel]->setBinLabel(11, "M1L11", 1);
0235   wheelSummary_[wheel]->setBinLabel(12, "M1L12", 1);
0236   wheelSummary_[wheel]->setBinLabel(13, "M2L1", 1);
0237   wheelSummary_[wheel]->setBinLabel(14, "M2L2", 1);
0238   wheelSummary_[wheel]->setBinLabel(15, "M2L3", 1);
0239   wheelSummary_[wheel]->setBinLabel(16, "M2L4", 1);
0240   wheelSummary_[wheel]->setBinLabel(17, "M2L5", 1);
0241   wheelSummary_[wheel]->setBinLabel(18, "M2L6", 1);
0242   wheelSummary_[wheel]->setBinLabel(19, "M2L7", 1);
0243   wheelSummary_[wheel]->setBinLabel(20, "M2L8", 1);
0244   wheelSummary_[wheel]->setBinLabel(21, "M2L9", 1);
0245   wheelSummary_[wheel]->setBinLabel(22, "M2L10", 1);
0246   wheelSummary_[wheel]->setBinLabel(23, "M2L11", 1);
0247   wheelSummary_[wheel]->setBinLabel(24, "M2L12", 1);
0248   wheelSummary_[wheel]->setBinLabel(25, "M3L1", 1);
0249   wheelSummary_[wheel]->setBinLabel(26, "M3L2", 1);
0250   wheelSummary_[wheel]->setBinLabel(27, "M3L3", 1);
0251   wheelSummary_[wheel]->setBinLabel(28, "M3L4", 1);
0252   wheelSummary_[wheel]->setBinLabel(29, "M3L5", 1);
0253   wheelSummary_[wheel]->setBinLabel(30, "M3L6", 1);
0254   wheelSummary_[wheel]->setBinLabel(31, "M3L7", 1);
0255   wheelSummary_[wheel]->setBinLabel(32, "M3L8", 1);
0256   wheelSummary_[wheel]->setBinLabel(33, "M3L9", 1);
0257   wheelSummary_[wheel]->setBinLabel(34, "M3L10", 1);
0258   wheelSummary_[wheel]->setBinLabel(35, "M3L11", 1);
0259   wheelSummary_[wheel]->setBinLabel(36, "M3L12", 1);
0260   wheelSummary_[wheel]->setBinLabel(37, "M4L1", 1);
0261   wheelSummary_[wheel]->setBinLabel(38, "M4L2", 1);
0262   wheelSummary_[wheel]->setBinLabel(39, "M4L3", 1);
0263   wheelSummary_[wheel]->setBinLabel(40, "M4L4", 1);
0264   wheelSummary_[wheel]->setBinLabel(41, "M4L5", 1);
0265   wheelSummary_[wheel]->setBinLabel(42, "M4L6", 1);
0266   wheelSummary_[wheel]->setBinLabel(43, "M4L7", 1);
0267   wheelSummary_[wheel]->setBinLabel(44, "M4L8", 1);
0268 }