Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-25 02:40:26

0001 // -*- C++ -*-
0002 //
0003 // Package:    CalibPPS/TimingCalibration/PPSDiamondSampicTimingCalibrationPCLWorker
0004 // Class:      PPSDiamondSampicTimingCalibrationPCLWorker
0005 //
0006 /**\class PPSDiamondSampicTimingCalibrationPCLWorker PPSDiamondSampicTimingCalibrationPCLWorker.cc CalibPPS/TimingCalibration/PPSDiamondSampicTimingCalibrationPCLWorker/plugins/PPSDiamondSampicTimingCalibrationPCLWorker.cc
0007 
0008  Description: Worker of DiamondSampic calibration which produces RecHitsTime histograms and id mapping for the Harvester
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Christopher Misan
0015 //         Created:  Mon, 26 Jul 2021 07:37:13 GMT
0016 //
0017 //
0018 
0019 #include <string>
0020 
0021 #include "FWCore/Framework/interface/Frameworkfwd.h"
0022 #include "DQMServices/Core/interface/DQMGlobalEDAnalyzer.h"
0023 
0024 #include "FWCore/Framework/interface/Event.h"
0025 #include "FWCore/Framework/interface/MakerMacros.h"
0026 
0027 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0028 
0029 #include "Geometry/VeryForwardGeometryBuilder/interface/CTPPSGeometry.h"
0030 #include "Geometry/Records/interface/VeryForwardRealGeometryRecord.h"
0031 
0032 #include "DataFormats/CTPPSDetId/interface/TotemTimingDetId.h"
0033 #include "DataFormats/CTPPSDetId/interface/CTPPSDiamondDetId.h"
0034 #include "DataFormats/CTPPSDigi/interface/TotemTimingDigi.h"
0035 #include "DataFormats/CTPPSReco/interface/TotemTimingRecHit.h"
0036 #include "DataFormats/Common/interface/DetSetVector.h"
0037 
0038 //------------------------------------------------------------------------------
0039 
0040 struct Histograms_PPSDiamondSampicTimingCalibrationPCLWorker {
0041   std::unordered_map<uint32_t, dqm::reco::MonitorElement*> timeHisto;
0042   std::unordered_map<uint32_t, dqm::reco::MonitorElement*> db;
0043   std::unordered_map<uint32_t, dqm::reco::MonitorElement*> sampic;
0044   std::unordered_map<uint32_t, dqm::reco::MonitorElement*> channel;
0045 };
0046 
0047 class PPSDiamondSampicTimingCalibrationPCLWorker
0048     : public DQMGlobalEDAnalyzer<Histograms_PPSDiamondSampicTimingCalibrationPCLWorker> {
0049 public:
0050   explicit PPSDiamondSampicTimingCalibrationPCLWorker(const edm::ParameterSet&);
0051   ~PPSDiamondSampicTimingCalibrationPCLWorker() override;
0052 
0053   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0054 
0055 private:
0056   void bookHistograms(DQMStore::IBooker&,
0057                       edm::Run const&,
0058                       edm::EventSetup const&,
0059                       Histograms_PPSDiamondSampicTimingCalibrationPCLWorker&) const override;
0060 
0061   void dqmAnalyze(edm::Event const&,
0062                   edm::EventSetup const&,
0063                   Histograms_PPSDiamondSampicTimingCalibrationPCLWorker const&) const override;
0064 
0065   template <typename T>
0066   bool searchForProduct(edm::Event const& iEvent,
0067                         const std::vector<edm::EDGetTokenT<T>>& tokens,
0068                         const std::vector<edm::InputTag>& tags,
0069                         edm::Handle<T>& handle) const;
0070 
0071   // ------------ member data ------------
0072   const std::vector<edm::InputTag> digiTags_;
0073   const std::vector<edm::InputTag> RecHitTags_;
0074 
0075   std::vector<edm::EDGetTokenT<edm::DetSetVector<TotemTimingDigi>>> totemTimingDigiTokens_;
0076   std::vector<edm::EDGetTokenT<edm::DetSetVector<TotemTimingRecHit>>> totemTimingRecHitTokens_;
0077 
0078   const edm::ESGetToken<CTPPSGeometry, VeryForwardRealGeometryRecord> geomEsToken_;
0079   const std::string folder_;
0080 };
0081 
0082 //------------------------------------------------------------------------------
0083 
0084 PPSDiamondSampicTimingCalibrationPCLWorker::PPSDiamondSampicTimingCalibrationPCLWorker(const edm::ParameterSet& iConfig)
0085     : digiTags_(iConfig.getParameter<std::vector<edm::InputTag>>("totemTimingDigiTags")),
0086       RecHitTags_(iConfig.getParameter<std::vector<edm::InputTag>>("totemTimingRecHitTags")),
0087       geomEsToken_(esConsumes<edm::Transition::BeginRun>()),
0088       folder_(iConfig.getParameter<std::string>("folder")) {
0089   for (auto& tag : digiTags_)
0090     totemTimingDigiTokens_.push_back(consumes<edm::DetSetVector<TotemTimingDigi>>(tag));
0091   for (auto& tag : RecHitTags_)
0092     totemTimingRecHitTokens_.push_back(consumes<edm::DetSetVector<TotemTimingRecHit>>(tag));
0093 }
0094 
0095 PPSDiamondSampicTimingCalibrationPCLWorker::~PPSDiamondSampicTimingCalibrationPCLWorker() {}
0096 
0097 //------------------------------------------------------------------------------
0098 
0099 void PPSDiamondSampicTimingCalibrationPCLWorker::dqmAnalyze(
0100     edm::Event const& iEvent,
0101     edm::EventSetup const& iSetup,
0102     Histograms_PPSDiamondSampicTimingCalibrationPCLWorker const& histos) const {
0103   edm::Handle<edm::DetSetVector<TotemTimingDigi>> timingDigi;
0104   edm::Handle<edm::DetSetVector<TotemTimingRecHit>> timingRecHit;
0105 
0106   searchForProduct(iEvent, totemTimingDigiTokens_, digiTags_, timingDigi);
0107   searchForProduct(iEvent, totemTimingRecHitTokens_, RecHitTags_, timingRecHit);
0108 
0109   if (timingRecHit->empty()) {
0110     edm::LogWarning("PPSDiamondSampicTimingCalibrationPCLWorker:dqmAnalyze")
0111         << "No rechits retrieved from the event content.";
0112     return;
0113   }
0114 
0115   for (const auto& digis : *timingDigi) {
0116     const CTPPSDiamondDetId detId(digis.detId());
0117     for (const auto& digi : digis) {
0118       histos.db.at(detId.rawId())->Fill(digi.hardwareBoardId());
0119       histos.sampic.at(detId.rawId())->Fill(digi.hardwareSampicId());
0120       histos.channel.at(detId.rawId())->Fill(digi.hardwareChannelId());
0121     }
0122   }
0123 
0124   for (const auto& recHits : *timingRecHit) {
0125     const CTPPSDiamondDetId detId(recHits.detId());
0126     for (const auto& recHit : recHits)
0127       histos.timeHisto.at(detId.rawId())->Fill(recHit.time());
0128   }
0129 }
0130 
0131 //------------------------------------------------------------------------------
0132 
0133 void PPSDiamondSampicTimingCalibrationPCLWorker::bookHistograms(
0134     DQMStore::IBooker& ibook,
0135     edm::Run const& run,
0136     edm::EventSetup const& iSetup,
0137     Histograms_PPSDiamondSampicTimingCalibrationPCLWorker& histos) const {
0138   ibook.setCurrentFolder(folder_);
0139   std::string ch_name;
0140   const auto& geom = iSetup.getData(geomEsToken_);
0141   for (auto it = geom.beginSensor(); it != geom.endSensor(); ++it) {
0142     if (!CTPPSDiamondDetId::check(it->first))
0143       continue;
0144     const CTPPSDiamondDetId detid(it->first);
0145 
0146     std::string path;
0147     detid.channelName(path, CTPPSDiamondDetId::nPath);
0148     detid.channelName(ch_name);
0149     histos.timeHisto[detid.rawId()] = ibook.book1D(path + "/" + ch_name, ch_name, 500, -25, 25);
0150     histos.db[detid.rawId()] = ibook.bookInt(path + "/" + ch_name + "db");
0151     histos.sampic[detid.rawId()] = ibook.bookInt(path + "/" + ch_name + "sampic");
0152     histos.channel[detid.rawId()] = ibook.bookInt(path + "/" + ch_name + "channel");
0153   }
0154 }
0155 
0156 //------------------------------------------------------------------------------
0157 
0158 void PPSDiamondSampicTimingCalibrationPCLWorker::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0159   edm::ParameterSetDescription desc;
0160   desc.add<std::vector<edm::InputTag>>("totemTimingDigiTags", {edm::InputTag("totemTimingRawToDigi", "TotemTiming")})
0161       ->setComment("input tag for the PPS diamond detectors digi");
0162   desc.add<std::vector<edm::InputTag>>("totemTimingRecHitTags", {edm::InputTag("totemTimingRecHits")})
0163       ->setComment("input tag for the PPS diamond detectors rechits");
0164   desc.add<std::string>("folder", "AlCaReco/PPSDiamondSampicTimingCalibrationPCL")
0165       ->setComment("output path for the various DQM plots");
0166   descriptions.add("PPSDiamondSampicTimingCalibrationPCLWorker", desc);
0167 }
0168 
0169 //------------------------------------------------------------------------------
0170 
0171 template <typename T>
0172 bool PPSDiamondSampicTimingCalibrationPCLWorker::searchForProduct(edm::Event const& iEvent,
0173                                                                   const std::vector<edm::EDGetTokenT<T>>& tokens,
0174                                                                   const std::vector<edm::InputTag>& tags,
0175                                                                   edm::Handle<T>& handle) const {
0176   bool foundProduct = false;
0177   for (unsigned int i = 0; i < tokens.size(); i++)
0178     if (auto h = iEvent.getHandle(tokens[i])) {
0179       handle = h;
0180       foundProduct = true;
0181       edm::LogInfo("searchForProduct") << "Found a product with " << tags[i];
0182       break;
0183     }
0184 
0185   if (!foundProduct)
0186     throw edm::Exception(edm::errors::ProductNotFound) << "Could not find a product with any of the selected labels.";
0187 
0188   return foundProduct;
0189 }
0190 
0191 DEFINE_FWK_MODULE(PPSDiamondSampicTimingCalibrationPCLWorker);