File indexing completed on 2024-04-06 11:58:37
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include "DQMServices/Core/interface/DQMGlobalEDAnalyzer.h"
0012 #include "DQMServices/Core/interface/DQMStore.h"
0013
0014 #include "FWCore/Framework/interface/Frameworkfwd.h"
0015 #include "FWCore/Framework/interface/MakerMacros.h"
0016 #include "FWCore/Framework/interface/Event.h"
0017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0018
0019 #include "Geometry/VeryForwardGeometryBuilder/interface/CTPPSGeometry.h"
0020 #include "Geometry/Records/interface/VeryForwardRealGeometryRecord.h"
0021
0022 #include "DataFormats/Common/interface/DetSetVector.h"
0023 #include "DataFormats/CTPPSDetId/interface/CTPPSDiamondDetId.h"
0024 #include "DataFormats/CTPPSReco/interface/CTPPSDiamondRecHit.h"
0025
0026 #include "CalibPPS/TimingCalibration/interface/TimingCalibrationStruct.h"
0027
0028
0029
0030 class PPSTimingCalibrationPCLWorker : public DQMGlobalEDAnalyzer<TimingCalibrationHistograms> {
0031 public:
0032 explicit PPSTimingCalibrationPCLWorker(const edm::ParameterSet&);
0033
0034 void dqmAnalyze(const edm::Event&, const edm::EventSetup&, const TimingCalibrationHistograms&) const override;
0035
0036 static void fillDescriptions(edm::ConfigurationDescriptions&);
0037
0038 private:
0039 void bookHistograms(DQMStore::IBooker&,
0040 const edm::Run&,
0041 const edm::EventSetup&,
0042 TimingCalibrationHistograms&) const override;
0043
0044 template <typename T>
0045 bool searchForProduct(edm::Event const& iEvent,
0046 const std::vector<edm::EDGetTokenT<T>>& tokens,
0047 const std::vector<edm::InputTag>& tags,
0048 edm::Handle<T>& handle) const;
0049
0050 const std::vector<edm::InputTag> RecHitTags_;
0051 std::vector<edm::EDGetTokenT<edm::DetSetVector<CTPPSDiamondRecHit>>> diamondRecHitTokens_;
0052 const edm::ESGetToken<CTPPSGeometry, VeryForwardRealGeometryRecord> geomEsToken_;
0053
0054 const std::string dqmDir_;
0055 };
0056
0057
0058
0059 PPSTimingCalibrationPCLWorker::PPSTimingCalibrationPCLWorker(const edm::ParameterSet& iConfig)
0060 : RecHitTags_(iConfig.getParameter<std::vector<edm::InputTag>>("diamondRecHitTags")),
0061 geomEsToken_(esConsumes<edm::Transition::BeginRun>()),
0062 dqmDir_(iConfig.getParameter<std::string>("dqmDir")) {
0063 for (auto& tag : RecHitTags_)
0064 diamondRecHitTokens_.push_back(consumes<edm::DetSetVector<CTPPSDiamondRecHit>>(tag));
0065 }
0066
0067
0068
0069 void PPSTimingCalibrationPCLWorker::bookHistograms(DQMStore::IBooker& iBooker,
0070 const edm::Run& iRun,
0071 const edm::EventSetup& iSetup,
0072 TimingCalibrationHistograms& iHists) const {
0073 iBooker.cd();
0074 iBooker.setCurrentFolder(dqmDir_);
0075 std::string ch_name;
0076
0077 const auto& geom = iSetup.getData(geomEsToken_);
0078 for (auto it = geom.beginSensor(); it != geom.endSensor(); ++it) {
0079 if (!CTPPSDiamondDetId::check(it->first))
0080 continue;
0081 const CTPPSDiamondDetId detid(it->first);
0082
0083 detid.channelName(ch_name);
0084 iHists.leadingTime[detid.rawId()] = iBooker.book1D("t_" + ch_name, ch_name + ";t (ns);Entries", 1200, -60., 60.);
0085 iHists.toT[detid.rawId()] = iBooker.book1D("tot_" + ch_name, ch_name + ";ToT (ns);Entries", 100, -20., 20.);
0086 iHists.leadingTimeVsToT[detid.rawId()] =
0087 iBooker.book2D("tvstot_" + ch_name, ch_name + ";ToT (ns);t (ns)", 240, 0., 60., 450, -20., 25.);
0088 }
0089 }
0090
0091
0092
0093 void PPSTimingCalibrationPCLWorker::dqmAnalyze(const edm::Event& iEvent,
0094 const edm::EventSetup& iSetup,
0095 const TimingCalibrationHistograms& iHists) const {
0096 edm::Handle<edm::DetSetVector<CTPPSDiamondRecHit>> dsv_rechits;
0097
0098 searchForProduct(iEvent, diamondRecHitTokens_, RecHitTags_, dsv_rechits);
0099
0100
0101 if (dsv_rechits->empty()) {
0102 edm::LogWarning("PPSTimingCalibrationPCLWorker:dqmAnalyze") << "No rechits retrieved from the event content.";
0103 return;
0104 }
0105 for (const auto& ds_rechits : *dsv_rechits) {
0106 const CTPPSDiamondDetId detid(ds_rechits.detId());
0107 if (iHists.leadingTimeVsToT.count(detid.rawId()) == 0) {
0108 edm::LogWarning("PPSTimingCalibrationPCLWorker:dqmAnalyze")
0109 << "Pad with detId=" << detid << " is not set to be monitored.";
0110 continue;
0111 }
0112 for (const auto& rechit : ds_rechits) {
0113
0114 if (rechit.time() == 0. || rechit.toT() < 0.)
0115 continue;
0116 iHists.leadingTime.at(detid.rawId())->Fill(rechit.time());
0117 iHists.toT.at(detid.rawId())->Fill(rechit.toT());
0118 iHists.leadingTimeVsToT.at(detid.rawId())->Fill(rechit.toT(), rechit.time());
0119 }
0120 }
0121 }
0122
0123
0124
0125 void PPSTimingCalibrationPCLWorker::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0126 edm::ParameterSetDescription desc;
0127 desc.add<std::vector<edm::InputTag>>("diamondRecHitTags", {edm::InputTag("ctppsDiamondRecHits")})
0128 ->setComment("input tag for the PPS diamond detectors rechits");
0129 desc.add<std::string>("dqmDir", "AlCaReco/PPSTimingCalibrationPCL")
0130 ->setComment("output path for the various DQM plots");
0131
0132 descriptions.addWithDefaultLabel(desc);
0133 }
0134
0135 template <typename T>
0136 bool PPSTimingCalibrationPCLWorker::searchForProduct(edm::Event const& iEvent,
0137 const std::vector<edm::EDGetTokenT<T>>& tokens,
0138 const std::vector<edm::InputTag>& tags,
0139 edm::Handle<T>& handle) const {
0140 bool foundProduct = false;
0141 for (unsigned int i = 0; i < tokens.size(); i++)
0142 if (auto h = iEvent.getHandle(tokens[i])) {
0143 handle = h;
0144 foundProduct = true;
0145 edm::LogInfo("searchForProduct") << "Found a product with " << tags[i];
0146 break;
0147 }
0148
0149 if (!foundProduct)
0150 throw edm::Exception(edm::errors::ProductNotFound) << "Could not find a product with any of the selected labels.";
0151
0152 return foundProduct;
0153 }
0154
0155 DEFINE_FWK_MODULE(PPSTimingCalibrationPCLWorker);