Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:09:17

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