Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /****************************************************************************
0002  *
0003  * This is a part of PPS offline software.
0004  * Authors:
0005  *   Edoardo Bossini
0006  *   Piotr Maciej Cwiklicki
0007  *   Laurent Forthomme
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     if (detid.station() != 1)
0083       continue;
0084     detid.channelName(ch_name);
0085     iHists.leadingTime[detid.rawId()] = iBooker.book1D("t_" + ch_name, ch_name + ";t (ns);Entries", 1200, -60., 60.);
0086     iHists.toT[detid.rawId()] = iBooker.book1D("tot_" + ch_name, ch_name + ";ToT (ns);Entries", 100, -20., 20.);
0087     iHists.leadingTimeVsToT[detid.rawId()] =
0088         iBooker.book2D("tvstot_" + ch_name, ch_name + ";ToT (ns);t (ns)", 240, 0., 60., 450, -20., 25.);
0089   }
0090 }
0091 
0092 //------------------------------------------------------------------------------
0093 
0094 void PPSTimingCalibrationPCLWorker::dqmAnalyze(const edm::Event& iEvent,
0095                                                const edm::EventSetup& iSetup,
0096                                                const TimingCalibrationHistograms& iHists) const {
0097   edm::Handle<edm::DetSetVector<CTPPSDiamondRecHit>> dsv_rechits;
0098   // then extract the rechits information for later processing
0099   searchForProduct(iEvent, diamondRecHitTokens_, RecHitTags_, dsv_rechits);
0100 
0101   // ensure timing detectors rechits are found in the event content
0102   if (dsv_rechits->empty()) {
0103     edm::LogWarning("PPSTimingCalibrationPCLWorker:dqmAnalyze") << "No rechits retrieved from the event content.";
0104     return;
0105   }
0106   for (const auto& ds_rechits : *dsv_rechits) {
0107     const CTPPSDiamondDetId detid(ds_rechits.detId());
0108     if (iHists.leadingTimeVsToT.count(detid.rawId()) == 0) {
0109       edm::LogWarning("PPSTimingCalibrationPCLWorker:dqmAnalyze")
0110           << "Pad with detId=" << detid << " is not set to be monitored.";
0111       continue;
0112     }
0113     for (const auto& rechit : ds_rechits) {
0114       // skip invalid rechits
0115       if (rechit.time() == 0. || rechit.toT() < 0.)
0116         continue;
0117       iHists.leadingTime.at(detid.rawId())->Fill(rechit.time());
0118       iHists.toT.at(detid.rawId())->Fill(rechit.toT());
0119       iHists.leadingTimeVsToT.at(detid.rawId())->Fill(rechit.toT(), rechit.time());
0120     }
0121   }
0122 }
0123 
0124 //------------------------------------------------------------------------------
0125 
0126 void PPSTimingCalibrationPCLWorker::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0127   edm::ParameterSetDescription desc;
0128   desc.add<std::vector<edm::InputTag>>("diamondRecHitTags", {edm::InputTag("ctppsDiamondRecHits")})
0129       ->setComment("input tag for the PPS diamond detectors rechits");
0130   desc.add<std::string>("dqmDir", "AlCaReco/PPSTimingCalibrationPCL")
0131       ->setComment("output path for the various DQM plots");
0132 
0133   descriptions.addWithDefaultLabel(desc);
0134 }
0135 
0136 template <typename T>
0137 bool PPSTimingCalibrationPCLWorker::searchForProduct(edm::Event const& iEvent,
0138                                                      const std::vector<edm::EDGetTokenT<T>>& tokens,
0139                                                      const std::vector<edm::InputTag>& tags,
0140                                                      edm::Handle<T>& handle) const {
0141   bool foundProduct = false;
0142   for (unsigned int i = 0; i < tokens.size(); i++)
0143     if (auto h = iEvent.getHandle(tokens[i])) {
0144       handle = h;
0145       foundProduct = true;
0146       edm::LogInfo("searchForProduct") << "Found a product with " << tags[i];
0147       break;
0148     }
0149 
0150   if (!foundProduct)
0151     throw edm::Exception(edm::errors::ProductNotFound) << "Could not find a product with any of the selected labels.";
0152 
0153   return foundProduct;
0154 }
0155 
0156 DEFINE_FWK_MODULE(PPSTimingCalibrationPCLWorker);