File indexing completed on 2023-03-17 10:54:41
0001 #include "DQM/GEM/interface/GEMDigiSource.h"
0002
0003 using namespace std;
0004 using namespace edm;
0005
0006 GEMDigiSource::GEMDigiSource(const edm::ParameterSet& cfg)
0007 : GEMDQMBase(cfg), gemChMapToken_(esConsumes<GEMChMap, GEMChMapRcd, edm::Transition::BeginRun>()) {
0008 tagDigi_ = consumes<GEMDigiCollection>(cfg.getParameter<edm::InputTag>("digisInputLabel"));
0009 lumiScalers_ = consumes<LumiScalersCollection>(
0010 cfg.getUntrackedParameter<edm::InputTag>("lumiCollection", edm::InputTag("scalersRawToDigi")));
0011 nBXMin_ = cfg.getParameter<int>("bxMin");
0012 nBXMax_ = cfg.getParameter<int>("bxMax");
0013 }
0014
0015 void GEMDigiSource::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0016 edm::ParameterSetDescription desc;
0017 desc.add<edm::InputTag>("digisInputLabel", edm::InputTag("muonGEMDigis", ""));
0018 desc.addUntracked<std::string>("runType", "online");
0019 desc.addUntracked<std::string>("logCategory", "GEMDigiSource");
0020 desc.add<int>("bxMin", -10);
0021 desc.add<int>("bxMax", 10);
0022 descriptions.add("GEMDigiSource", desc);
0023 }
0024
0025 void GEMDigiSource::LoadROMap(edm::EventSetup const& iSetup) {
0026
0027 if (true) {
0028 const auto& chMap = iSetup.getData(gemChMapToken_);
0029 auto gemChMap = std::make_unique<GEMChMap>(chMap);
0030
0031 std::map<int, bool> mapCheckedType;
0032 for (auto const& p : gemChMap->chamberMap()) {
0033 auto& dc = p.second;
0034 GEMDetId gemChId(dc.detId);
0035 for (Int_t ieta = 1; ieta <= 24; ieta++) {
0036 if (!gemChMap->isValidStrip(dc.chamberType, ieta, 1))
0037 continue;
0038 mapChamberType_[{gemChId.station(), gemChId.layer(), gemChId.chamber(), ieta}] = dc.chamberType;
0039 if (mapCheckedType[dc.chamberType])
0040 continue;
0041 for (Int_t strip = 0; strip <= 3 * 128; strip++) {
0042 if (!gemChMap->isValidStrip(dc.chamberType, ieta, strip))
0043 continue;
0044 auto& stripInfo = gemChMap->getChannel(dc.chamberType, ieta, strip);
0045 mapStripToVFAT_[{dc.chamberType, ieta, strip}] = stripInfo.vfatAdd;
0046 }
0047 }
0048 mapCheckedType[dc.chamberType] = true;
0049 }
0050 } else {
0051
0052 auto gemChMap = std::make_unique<GEMChMap>();
0053 gemChMap->setDummy();
0054
0055 std::map<int, bool> mapCheckedType;
0056 for (auto const& p : gemChMap->chamberMap()) {
0057 auto& dc = p.second;
0058 GEMDetId gemChId(dc.detId);
0059
0060 for (Int_t ieta = 1; ieta <= 24; ieta++) {
0061 if (!gemChMap->isValidStrip(dc.chamberType, ieta, 1))
0062 continue;
0063 mapChamberType_[{gemChId.station(), gemChId.layer(), gemChId.chamber(), ieta}] = dc.chamberType;
0064 if (mapCheckedType[dc.chamberType])
0065 continue;
0066 mapCheckedType[dc.chamberType] = true;
0067 for (Int_t strip = 0; strip <= 3 * 128; strip++) {
0068 if (!gemChMap->isValidStrip(dc.chamberType, ieta, strip))
0069 continue;
0070 auto& stripInfo = gemChMap->getChannel(dc.chamberType, ieta, strip);
0071 mapStripToVFAT_[{dc.chamberType, ieta, strip}] = stripInfo.vfatAdd;
0072 }
0073 }
0074 }
0075 }
0076 }
0077
0078 void GEMDigiSource::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const&, edm::EventSetup const& iSetup) {
0079 initGeometry(iSetup);
0080 if (GEMGeometry_ == nullptr)
0081 return;
0082 loadChambers();
0083 LoadROMap(iSetup);
0084
0085 strFolderMain_ = "GEM/Digis";
0086
0087 fRadiusMin_ = 120.0;
0088 fRadiusMax_ = 250.0;
0089 float radS = -5.0 / 180 * M_PI;
0090 float radL = 355.0 / 180 * M_PI;
0091
0092 mapTotalDigi_layer_ = MEMap3Inf(this, "occ", "Digi Occupancy", 36, 0.5, 36.5, 24, -0.5, 24 - 0.5, "Chamber", "VFAT");
0093 mapDigiWheel_layer_ = MEMap3Inf(
0094 this, "occ_rphi", "Digi R-Phi Occupancy", 360, radS, radL, 8, fRadiusMin_, fRadiusMax_, "#phi (rad)", "R [cm]");
0095 mapDigiOcc_ieta_ = MEMap3Inf(this, "occ_ieta", "Digi iEta Occupancy", 8, 0.5, 8.5, "iEta", "Number of fired digis");
0096 mapDigiOcc_phi_ =
0097 MEMap3Inf(this, "occ_phi", "Digi Phi Occupancy", 72, -5, 355, "#phi (degree)", "Number of fired digis");
0098 mapTotalDigiPerEvtLayer_ = MEMap3Inf(this,
0099 "digis_per_layer",
0100 "Total number of digis per event for each layers",
0101 50,
0102 -0.5,
0103 99.5,
0104 "Number of fired digis",
0105 "Events");
0106 mapTotalDigiPerEvtLayer_.SetNoUnderOverflowBin();
0107 mapTotalDigiPerEvtIEta_ = MEMap3Inf(this,
0108 "digis_per_ieta",
0109 "Total number of digis per event for each eta partitions",
0110 50,
0111 -0.5,
0112 99.5,
0113 "Number of fired digis",
0114 "Events");
0115 mapTotalDigiPerEvtIEta_.SetNoUnderOverflowBin();
0116
0117 mapBX_ = MEMap2Inf(this, "bx", "Digi Bunch Crossing", 21, nBXMin_ - 0.5, nBXMax_ + 0.5, "Bunch crossing");
0118
0119 mapDigiOccPerCh_ = MEMap4Inf(this, "occ", "Digi Occupancy", 1, -0.5, 1.5, 1, 0.5, 1.5, "Digi", "iEta");
0120
0121 if (nRunType_ == GEMDQM_RUNTYPE_OFFLINE) {
0122 mapDigiWheel_layer_.TurnOff();
0123 mapBX_.TurnOff();
0124 }
0125
0126 if (nRunType_ == GEMDQM_RUNTYPE_RELVAL) {
0127 mapDigiWheel_layer_.TurnOff();
0128 mapDigiOccPerCh_.TurnOff();
0129 mapTotalDigi_layer_.TurnOff();
0130 }
0131
0132 if (nRunType_ != GEMDQM_RUNTYPE_ALLPLOTS && nRunType_ != GEMDQM_RUNTYPE_RELVAL) {
0133 mapDigiOcc_ieta_.TurnOff();
0134 mapDigiOcc_phi_.TurnOff();
0135 }
0136
0137 if (nRunType_ != GEMDQM_RUNTYPE_ALLPLOTS) {
0138 mapTotalDigiPerEvtLayer_.TurnOff();
0139 mapTotalDigiPerEvtIEta_.TurnOff();
0140 }
0141
0142 ibooker.cd();
0143 ibooker.setCurrentFolder(strFolderMain_);
0144 GenerateMEPerChamber(ibooker);
0145 }
0146
0147 int GEMDigiSource::ProcessWithMEMap2(BookingHelper& bh, ME2IdsKey key) {
0148 mapBX_.bookND(bh, key);
0149
0150 return 0;
0151 }
0152
0153 int GEMDigiSource::ProcessWithMEMap2WithEta(BookingHelper& bh, ME3IdsKey key) {
0154 mapTotalDigiPerEvtIEta_.bookND(bh, key);
0155
0156 return 0;
0157 }
0158
0159 int GEMDigiSource::ProcessWithMEMap3(BookingHelper& bh, ME3IdsKey key) {
0160 MEStationInfo& stationInfo = mapStationInfo_[key];
0161
0162 Int_t nNewNumCh = stationInfo.nMaxIdxChamber_ - stationInfo.nMinIdxChamber_ + 1;
0163 Int_t nNewMinIdxChamber = stationInfo.nNumModules_ * (stationInfo.nMinIdxChamber_ - 1) + 1;
0164 Int_t nNewMaxIdxChamber = stationInfo.nNumModules_ * stationInfo.nMaxIdxChamber_;
0165
0166 nNewNumCh *= stationInfo.nNumModules_;
0167
0168 Int_t nNumVFATPerModule = stationInfo.nMaxVFAT_ / stationInfo.nNumModules_;
0169
0170 int nNumVFATPerEta = stationInfo.nMaxVFAT_ / stationInfo.nNumEtaPartitions_;
0171
0172 mapTotalDigi_layer_.SetBinConfX(nNewNumCh, nNewMinIdxChamber - 0.5, nNewMaxIdxChamber + 0.5);
0173 mapTotalDigi_layer_.SetBinConfY(nNumVFATPerModule, -0.5);
0174 mapTotalDigi_layer_.bookND(bh, key);
0175 mapTotalDigi_layer_.SetLabelForChambers(key, 1, -1, nNewMinIdxChamber, stationInfo.nNumModules_);
0176 mapTotalDigi_layer_.SetLabelForVFATs(key, stationInfo.nNumEtaPartitions_, 2);
0177
0178 mapDigiWheel_layer_.SetBinLowEdgeX(stationInfo.fMinPhi_);
0179 mapDigiWheel_layer_.SetBinHighEdgeX(stationInfo.fMinPhi_ + 2 * M_PI);
0180 mapDigiWheel_layer_.SetNbinsX(nNumVFATPerEta * stationInfo.nNumChambers_);
0181 mapDigiWheel_layer_.SetNbinsY(stationInfo.nNumEtaPartitions_);
0182 mapDigiWheel_layer_.bookND(bh, key);
0183
0184 mapDigiOcc_ieta_.SetBinConfX(stationInfo.nNumEtaPartitions_);
0185 mapDigiOcc_ieta_.bookND(bh, key);
0186 mapDigiOcc_ieta_.SetLabelForIEta(key, 1);
0187
0188 mapDigiOcc_phi_.SetBinLowEdgeX(stationInfo.fMinPhi_ * 180 / M_PI);
0189 mapDigiOcc_phi_.SetBinHighEdgeX(stationInfo.fMinPhi_ * 180 / M_PI + 360);
0190 mapDigiOcc_phi_.bookND(bh, key);
0191 mapTotalDigiPerEvtLayer_.bookND(bh, key);
0192
0193 return 0;
0194 }
0195
0196 int GEMDigiSource::ProcessWithMEMap3WithChamber(BookingHelper& bh, ME4IdsKey key) {
0197 ME3IdsKey key3 = key4Tokey3(key);
0198 MEStationInfo& stationInfo = mapStationInfo_[key3];
0199
0200 bh.getBooker()->setCurrentFolder(strFolderMain_ + "/occupancy_" + getNameDirLayer(key3));
0201
0202 int nNumVFATPerEta = stationInfo.nMaxVFAT_ / stationInfo.nNumEtaPartitions_;
0203 int nNumCh = stationInfo.nNumDigi_;
0204
0205 mapDigiOccPerCh_.SetBinConfX(nNumCh * nNumVFATPerEta, stationInfo.nFirstStrip_ - 0.5);
0206 mapDigiOccPerCh_.SetBinConfY(stationInfo.nNumEtaPartitions_);
0207 mapDigiOccPerCh_.bookND(bh, key);
0208 mapDigiOccPerCh_.SetLabelForIEta(key, 2);
0209
0210 bh.getBooker()->setCurrentFolder(strFolderMain_);
0211
0212 return 0;
0213 }
0214
0215 void GEMDigiSource::analyze(edm::Event const& event, edm::EventSetup const& eventSetup) {
0216 edm::Handle<GEMDigiCollection> gemDigis;
0217 event.getByToken(this->tagDigi_, gemDigis);
0218 edm::Handle<LumiScalersCollection> lumiScalers;
0219 event.getByToken(lumiScalers_, lumiScalers);
0220
0221 std::map<ME3IdsKey, Int_t> total_digi_layer;
0222 std::map<ME3IdsKey, Int_t> total_digi_eta;
0223 for (auto gid : listChamberId_) {
0224 ME2IdsKey key2{gid.region(), gid.station()};
0225 ME3IdsKey key3{gid.region(), gid.station(), gid.layer()};
0226 ME4IdsKey key4Ch{gid.region(), gid.station(), gid.layer(), gid.chamber()};
0227 std::map<Int_t, bool> bTagVFAT;
0228 bTagVFAT.clear();
0229 MEStationInfo& stationInfo = mapStationInfo_[key3];
0230 const BoundPlane& surface = GEMGeometry_->idToDet(gid)->surface();
0231 if (total_digi_layer.find(key3) == total_digi_layer.end())
0232 total_digi_layer[key3] = 0;
0233 for (auto iEta : mapEtaPartition_[gid]) {
0234 GEMDetId eId = iEta->id();
0235 ME3IdsKey key3IEta{gid.region(), gid.station(), eId.ieta()};
0236 if (total_digi_eta.find(key3IEta) == total_digi_eta.end())
0237 total_digi_eta[key3IEta] = 0;
0238 const auto& digis_in_det = gemDigis->get(eId);
0239 auto nChamberType = mapChamberType_[{gid.station(), gid.layer(), gid.chamber(), eId.ieta()}];
0240 Int_t nIdxModule = getIdxModule(gid.station(), nChamberType);
0241 Int_t nCh = (gid.chamber() - 1) * stationInfo.nNumModules_ + nIdxModule;
0242 for (auto d = digis_in_det.first; d != digis_in_det.second; ++d) {
0243
0244 Int_t nIdxVFAT = mapStripToVFAT_[{nChamberType, eId.ieta(), d->strip()}];
0245 mapTotalDigi_layer_.Fill(key3, nCh, nIdxVFAT);
0246
0247
0248 mapDigiOcc_ieta_.Fill(key3, eId.ieta());
0249
0250 GlobalPoint digi_global_pos = surface.toGlobal(iEta->centreOfStrip(d->strip()));
0251 Float_t fPhi = (Float_t)digi_global_pos.phi();
0252 Float_t fPhiShift = restrictAngle(fPhi, stationInfo.fMinPhi_);
0253 Float_t fPhiDeg = fPhiShift * 180.0 / M_PI;
0254 mapDigiOcc_phi_.Fill(key3, fPhiDeg);
0255
0256
0257 Float_t fR = fRadiusMin_ + (fRadiusMax_ - fRadiusMin_) * (eId.ieta() - 0.5) / stationInfo.nNumEtaPartitions_;
0258 mapDigiWheel_layer_.Fill(key3, fPhiShift, fR);
0259
0260 mapDigiOccPerCh_.Fill(key4Ch, d->strip(), eId.ieta());
0261
0262
0263 total_digi_layer[key3]++;
0264 total_digi_eta[key3IEta]++;
0265
0266
0267 Int_t nBX = std::min(std::max((Int_t)d->bx(), nBXMin_), nBXMax_);
0268 if (bTagVFAT.find(nIdxVFAT) == bTagVFAT.end()) {
0269 mapBX_.Fill(key2, nBX);
0270 }
0271
0272 bTagVFAT[nIdxVFAT] = true;
0273 }
0274 }
0275 }
0276 for (auto [key, num_total_digi] : total_digi_layer)
0277 mapTotalDigiPerEvtLayer_.Fill(key, num_total_digi);
0278 for (auto [key, num_total_digi] : total_digi_eta)
0279 mapTotalDigiPerEvtIEta_.Fill(key, num_total_digi);
0280 }
0281
0282 DEFINE_FWK_MODULE(GEMDigiSource);