File indexing completed on 2024-09-11 04:32:26
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/Framework/interface/EventSetup.h"
0011 #include "FWCore/Framework/interface/MakerMacros.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/Utilities/interface/InputTag.h"
0014
0015 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0016 #include "DQMServices/Core/interface/DQMStore.h"
0017
0018 #include "DataFormats/Common/interface/DetSetVector.h"
0019
0020 #include "DataFormats/CTPPSDetId/interface/CTPPSDetId.h"
0021 #include "DataFormats/CTPPSDetId/interface/CTPPSPixelDetId.h"
0022 #include "DataFormats/CTPPSDigi/interface/CTPPSPixelDigi.h"
0023
0024 #include <string>
0025
0026
0027
0028 class CTPPSRandomDQMSource : public DQMEDAnalyzer {
0029 public:
0030 CTPPSRandomDQMSource(const edm::ParameterSet &ps);
0031 ~CTPPSRandomDQMSource() override = default;
0032 static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
0033
0034 protected:
0035 void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
0036 void analyze(edm::Event const &e, edm::EventSetup const &eSetup) override;
0037
0038 private:
0039 edm::EDGetTokenT<edm::DetSetVector<CTPPSPixelDigi>> const tokenDigi_;
0040
0041 static constexpr int kNArms_ = 2;
0042 static constexpr int kNStationMAX_ = 3;
0043 static constexpr int kNRPotsMAX_ = 6;
0044 static constexpr int kNplaneMAX_ = 6;
0045 static constexpr int kFirstRPn_ = 3, kLastRPn_ = 4;
0046 static constexpr int kStationIDMAX_ = 4;
0047 static constexpr int kRPotsIDMAX_ = 8;
0048
0049 const std::string folderName_ = "PPSRANDOM/RandomPixel";
0050
0051 unsigned int rpStatusWord_ = 0x8008;
0052 int rpStatus_[kStationIDMAX_][kRPotsIDMAX_];
0053 int stationStatus_[kStationIDMAX_];
0054 const int kIndexNotValid = 0;
0055
0056 MonitorElement *hBX_;
0057
0058 static constexpr int kRPotsTotalNumber_ = kNArms_ * kNStationMAX_ * kNRPotsMAX_;
0059
0060 int RPindexValid_[kRPotsTotalNumber_];
0061 MonitorElement *h2HitsVsBXRandoms_[kRPotsTotalNumber_];
0062
0063 int getRPindex(int arm, int station, int rp) const {
0064 if (arm < 0 || station < 0 || rp < 0)
0065 return (kIndexNotValid);
0066 if (arm > 1 || station >= kNStationMAX_ || rp >= kNRPotsMAX_)
0067 return (kIndexNotValid);
0068 int rc = (arm * kNStationMAX_ + station) * kNRPotsMAX_ + rp;
0069 return (rc);
0070 }
0071 };
0072
0073
0074
0075 CTPPSRandomDQMSource::CTPPSRandomDQMSource(const edm::ParameterSet &ps)
0076 : tokenDigi_(consumes<edm::DetSetVector<CTPPSPixelDigi>>(ps.getParameter<edm::InputTag>("tagRPixDigi"))),
0077 folderName_(ps.getUntrackedParameter<std::string>("folderName", "PPSRANDOM/RandomPixel")),
0078 rpStatusWord_(ps.getUntrackedParameter<unsigned int>("RPStatusWord", 0x8008)) {
0079 for (int stn = 0; stn < kStationIDMAX_; stn++) {
0080 stationStatus_[stn] = 0;
0081 for (int rp = 0; rp < kRPotsIDMAX_; rp++)
0082 rpStatus_[stn][rp] = 0;
0083 }
0084
0085 unsigned int rpSts = rpStatusWord_ << 1;
0086 for (int stn = 0; stn < kNStationMAX_; stn++) {
0087 int stns = 0;
0088 for (int rp = 0; rp < kNRPotsMAX_; rp++) {
0089 rpSts = (rpSts >> 1);
0090 rpStatus_[stn][rp] = rpSts & 1;
0091 if (rpStatus_[stn][rp] > 0)
0092 stns = 1;
0093 }
0094 stationStatus_[stn] = stns;
0095 }
0096
0097 for (int index = 0; index < 2 * 3 * kNRPotsMAX_; index++)
0098 RPindexValid_[index] = 0;
0099 }
0100
0101
0102
0103 void CTPPSRandomDQMSource::bookHistograms(DQMStore::IBooker &ibooker, edm::Run const &, edm::EventSetup const &) {
0104 ibooker.cd();
0105 ibooker.setCurrentFolder(folderName_);
0106
0107 hBX_ = ibooker.book1D("events per BX", "ctpps_pixel;Event.BX", 4002, -1.5, 4000. + 0.5);
0108
0109 for (int arm = 0; arm < kNArms_; arm++) {
0110 CTPPSDetId ID(CTPPSDetId::sdTrackingPixel, arm, 0);
0111 std::string sd;
0112 ID.armName(sd, CTPPSDetId::nShort);
0113 sd = folderName_ + "/sector " + sd;
0114
0115 ibooker.setCurrentFolder(sd);
0116
0117 for (int stn = 0; stn < kNStationMAX_; stn++) {
0118 if (stationStatus_[stn] == 0)
0119 continue;
0120 ID.setStation(stn);
0121 std::string stnd;
0122 CTPPSDetId(ID.stationId()).stationName(stnd, CTPPSDetId::nShort);
0123 stnd = sd + "/station " + stnd;
0124
0125 ibooker.setCurrentFolder(stnd);
0126
0127 for (int rp = kFirstRPn_; rp < kLastRPn_; rp++) {
0128 ID.setRP(rp);
0129 std::string rpd, rpTitle;
0130 CTPPSDetId(ID.rpId()).rpName(rpTitle, CTPPSDetId::nFull);
0131 CTPPSDetId(ID.rpId()).rpName(rpd, CTPPSDetId::nShort);
0132 rpd = stnd + "/" + rpd;
0133
0134 ibooker.setCurrentFolder(rpd);
0135
0136 int indexP = getRPindex(arm, stn, rp);
0137 RPindexValid_[indexP] = 1;
0138
0139 h2HitsVsBXRandoms_[indexP] = ibooker.book2D("Digi per plane per BX - random triggers",
0140 rpTitle + ";Event.BX;Plane",
0141 4002,
0142 -1.5,
0143 4000. + 0.5,
0144 kNplaneMAX_,
0145 0,
0146 kNplaneMAX_);
0147 h2HitsVsBXRandoms_[indexP]->getTH2F()->SetOption("colz");
0148
0149 }
0150 }
0151 }
0152
0153 return;
0154 }
0155
0156
0157
0158 void CTPPSRandomDQMSource::analyze(edm::Event const &event, edm::EventSetup const &eventSetup) {
0159 auto const pixDigi = event.getHandle(tokenDigi_);
0160
0161 if (!pixDigi.isValid())
0162 return;
0163
0164 hBX_->Fill(event.bunchCrossing());
0165
0166 for (int arm = 0; arm < 2; arm++) {
0167 for (int stn = 0; stn < kNStationMAX_; stn++) {
0168 if (!stationStatus_[stn])
0169 continue;
0170 for (int rp = 0; rp < kNRPotsMAX_; rp++) {
0171 if (!rpStatus_[stn][rp])
0172 continue;
0173 int index = getRPindex(arm, stn, rp);
0174 if (RPindexValid_[index] == 0)
0175 continue;
0176
0177 for (int p = 0; p < kNplaneMAX_; p++) {
0178 CTPPSPixelDetId planeId(arm, stn, rp, p);
0179 auto pix_d = pixDigi->find(planeId.rawId());
0180 if (pix_d != pixDigi->end()) {
0181 int n_digis = pix_d->size();
0182 h2HitsVsBXRandoms_[index]->Fill(event.bunchCrossing(), p, n_digis);
0183 }
0184 }
0185 }
0186 }
0187 }
0188 }
0189
0190
0191
0192 void CTPPSRandomDQMSource::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0193 edm::ParameterSetDescription desc;
0194 desc.add<edm::InputTag>("tagRPixDigi", edm::InputTag("ctppsPixelDigisAlCaRecoProducer", ""));
0195 desc.addUntracked<std::string>("folderName", "PPSRANDOM/RandomPixel");
0196 desc.addUntracked<unsigned int>("RPStatusWord", 0x8008);
0197 descriptions.add("ctppsRandomDQMSource", desc);
0198 }
0199
0200
0201 DEFINE_FWK_MODULE(CTPPSRandomDQMSource);