File indexing completed on 2024-04-06 12:07:26
0001 #include "DQM/GEM/interface/GEMRecHitSource.h"
0002
0003 using namespace std;
0004 using namespace edm;
0005
0006 GEMRecHitSource::GEMRecHitSource(const edm::ParameterSet& cfg) : GEMDQMBase(cfg) {
0007 tagRecHit_ = consumes<GEMRecHitCollection>(cfg.getParameter<edm::InputTag>("recHitsInputLabel"));
0008
0009 nIdxFirstDigi_ = cfg.getParameter<int>("idxFirstDigi");
0010 nNumDivideEtaPartitionInRPhi_ = cfg.getParameter<int>("numDivideEtaPartitionInRPhi");
0011 nCLSMax_ = cfg.getParameter<int>("clsMax");
0012 nClusterSizeBinNum_ = cfg.getParameter<int>("ClusterSizeBinNum");
0013 }
0014
0015 void GEMRecHitSource::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0016 edm::ParameterSetDescription desc;
0017 desc.add<edm::InputTag>("recHitsInputLabel", edm::InputTag("gemRecHits", ""));
0018 desc.addUntracked<std::string>("runType", "online");
0019
0020 desc.add<int>("idxFirstDigi", 0);
0021 desc.add<int>("numDivideEtaPartitionInRPhi", 10);
0022 desc.add<int>("clsMax", 10);
0023 desc.add<int>("ClusterSizeBinNum", 9);
0024
0025 desc.addUntracked<std::string>("logCategory", "GEMRecHitSource");
0026
0027 descriptions.add("GEMRecHitSource", desc);
0028 }
0029
0030 void GEMRecHitSource::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const&, edm::EventSetup const& iSetup) {
0031 std::vector<GEMDetId> listLayerOcc;
0032
0033 initGeometry(iSetup);
0034 if (GEMGeometry_ == nullptr)
0035 return;
0036 loadChambers();
0037
0038 strFolderMain_ = "GEM/RecHits";
0039
0040 ibooker.cd();
0041 ibooker.setCurrentFolder(strFolderMain_);
0042
0043 mapRecHitXY_layer_ =
0044 MEMap3Inf(this, "occ_xy", "RecHit xy Occupancy", 160, -250, 250, 160, -250, 250, "X [cm]", "Y [cm]");
0045 mapRecHitOcc_ieta_ = MEMap3Inf(this, "occ_ieta", "RecHit iEta Occupancy", 8, 0.5, 8.5, "iEta", "Number of RecHits");
0046 mapRecHitOcc_phi_ =
0047 MEMap3Inf(this, "occ_phi", "RecHit Phi Occupancy", 72, -5, 355, "#phi (degree)", "Number of RecHits");
0048 mapTotalRecHitPerEvtLayer_ = MEMap3Inf(this,
0049 "rechits_per_layer",
0050 "Total number of RecHits per event for each layers",
0051 2000,
0052 -0.5,
0053 2000 - 0.5,
0054 "Number of RecHits",
0055 "Events");
0056 mapTotalRecHitPerEvtLayer_.SetNoUnderOverflowBin();
0057 mapTotalRecHitPerEvtIEta_ = MEMap3Inf(this,
0058 "rechits_per_ieta",
0059 "Total number of RecHits per event for each eta partitions",
0060 300,
0061 -0.5,
0062 300 - 0.5,
0063 "Number of RecHits",
0064 "Events");
0065 mapTotalRecHitPerEvtIEta_.SetNoUnderOverflowBin();
0066 mapCLSRecHit_ieta_ = MEMap3Inf(
0067 this, "cls", "Cluster size of RecHits", nCLSMax_, 0.5, nCLSMax_ + 0.5, "Cluster size", "Number of RecHits");
0068 mapCLSAverage_ = MEMap3Inf(this,
0069 "rechit_average",
0070 "Average of Cluster Sizes",
0071 36,
0072 0.5,
0073 36.5,
0074 8,
0075 0.5,
0076 8.5,
0077 0,
0078 400,
0079 "Chamber",
0080 "iEta");
0081 mapCLSOver5_ = MEMap3Inf(
0082 this, "largeCls_occ", "Occupancy of Large Clusters (>5)", 36, 0.5, 36.5, 8, 0.5, 8.5, "Chamber", "iEta");
0083
0084 mapCLSPerCh_ = MEMap4Inf(
0085 this, "cls", "Cluster size of RecHits", nCLSMax_, 0.5, nCLSMax_ + 0.5, 1, 0.5, 1.5, "Cluster size", "iEta");
0086
0087 if (nRunType_ == GEMDQM_RUNTYPE_OFFLINE) {
0088 mapCLSOver5_.TurnOff();
0089 mapCLSPerCh_.TurnOff();
0090 }
0091
0092 if (nRunType_ == GEMDQM_RUNTYPE_RELVAL) {
0093 mapRecHitXY_layer_.TurnOff();
0094 mapCLSAverage_.TurnOff();
0095 mapCLSOver5_.TurnOff();
0096 mapCLSPerCh_.TurnOff();
0097 }
0098
0099 if (nRunType_ != GEMDQM_RUNTYPE_ALLPLOTS && nRunType_ != GEMDQM_RUNTYPE_RELVAL) {
0100 mapRecHitOcc_ieta_.TurnOff();
0101 mapRecHitOcc_phi_.TurnOff();
0102 mapCLSRecHit_ieta_.TurnOff();
0103 }
0104
0105 if (nRunType_ != GEMDQM_RUNTYPE_ALLPLOTS) {
0106 mapTotalRecHitPerEvtLayer_.TurnOff();
0107 mapTotalRecHitPerEvtIEta_.TurnOff();
0108 }
0109
0110 GenerateMEPerChamber(ibooker);
0111 }
0112
0113 int GEMRecHitSource::ProcessWithMEMap2WithEta(BookingHelper& bh, ME3IdsKey key) {
0114 mapTotalRecHitPerEvtIEta_.bookND(bh, key);
0115
0116 return 0;
0117 }
0118
0119 int GEMRecHitSource::ProcessWithMEMap2AbsReWithEta(BookingHelper& bh, ME3IdsKey key) {
0120 mapCLSRecHit_ieta_.bookND(bh, key);
0121
0122 return 0;
0123 }
0124
0125 int GEMRecHitSource::ProcessWithMEMap3(BookingHelper& bh, ME3IdsKey key) {
0126 MEStationInfo& stationInfo = mapStationInfo_[key];
0127
0128 Float_t fR1 = !stationInfo.listRadiusEvenChamber_.empty() ? stationInfo.listRadiusEvenChamber_.back() : 0.0;
0129 Float_t fR2 = !stationInfo.listRadiusOddChamber_.empty() ? stationInfo.listRadiusOddChamber_.back() : 0.0;
0130 Float_t fRangeRadius = (int)(std::max(fR1, fR2) * 0.11 + 0.99999) * 10.0;
0131
0132 mapRecHitXY_layer_.SetBinLowEdgeX(-fRangeRadius);
0133 mapRecHitXY_layer_.SetBinHighEdgeX(fRangeRadius);
0134 mapRecHitXY_layer_.SetBinLowEdgeY(-fRangeRadius);
0135 mapRecHitXY_layer_.SetBinHighEdgeY(fRangeRadius);
0136 mapRecHitXY_layer_.bookND(bh, key);
0137
0138 Int_t nNumEta = stationInfo.nNumEtaPartitions_;
0139 if (stationInfo.nNumModules_ > 1) {
0140 nNumEta = stationInfo.nNumModules_;
0141 }
0142 mapRecHitOcc_ieta_.SetBinConfX(nNumEta);
0143 mapRecHitOcc_ieta_.bookND(bh, key);
0144 mapRecHitOcc_ieta_.SetLabelForIEta(key, 1);
0145
0146 mapRecHitOcc_phi_.SetBinLowEdgeX(stationInfo.fMinPhi_ * 180 / M_PI);
0147 mapRecHitOcc_phi_.SetBinHighEdgeX(stationInfo.fMinPhi_ * 180 / M_PI + 360);
0148 mapRecHitOcc_phi_.bookND(bh, key);
0149
0150 mapTotalRecHitPerEvtLayer_.bookND(bh, key);
0151
0152 Int_t nNewNumCh = stationInfo.nMaxIdxChamber_ - stationInfo.nMinIdxChamber_ + 1;
0153
0154 mapCLSAverage_.SetBinConfX(nNewNumCh, stationInfo.nMinIdxChamber_ - 0.5, stationInfo.nMaxIdxChamber_ + 0.5);
0155 mapCLSAverage_.SetBinConfY(nNumEta, 0.5);
0156 mapCLSAverage_.bookND(bh, key);
0157 mapCLSAverage_.SetLabelForChambers(key, 1, -1, stationInfo.nMinIdxChamber_);
0158 mapCLSAverage_.SetLabelForIEta(key, 2);
0159
0160 mapCLSOver5_.SetBinConfX(nNewNumCh, stationInfo.nMinIdxChamber_ - 0.5, stationInfo.nMaxIdxChamber_ + 0.5);
0161 mapCLSOver5_.SetBinConfY(nNumEta, 0.5);
0162 mapCLSOver5_.bookND(bh, key);
0163 mapCLSOver5_.SetLabelForChambers(key, 1, -1, stationInfo.nMinIdxChamber_);
0164 mapCLSOver5_.SetLabelForIEta(key, 2);
0165
0166 if (keyToStation(key) == 2) {
0167 if (mapCLSAverage_.isOperating()) {
0168 mapCLSAverage_.FindHist(key)->setYTitle("Module");
0169 }
0170 if (mapCLSOver5_.isOperating()) {
0171 mapCLSOver5_.FindHist(key)->setYTitle("Module");
0172 }
0173 for (Int_t i = 1; i <= stationInfo.nNumModules_; i++) {
0174 std::string strLabel = std::string(Form("M%i", i));
0175 if (mapCLSAverage_.isOperating()) {
0176 mapCLSAverage_.FindHist(key)->setBinLabel(i, strLabel, 2);
0177 }
0178 if (mapCLSOver5_.isOperating()) {
0179 mapCLSOver5_.FindHist(key)->setBinLabel(i, strLabel, 2);
0180 }
0181 }
0182 }
0183
0184 return 0;
0185 }
0186
0187 int GEMRecHitSource::ProcessWithMEMap4WithChamber(BookingHelper& bh, ME4IdsKey key) {
0188 ME3IdsKey key3 = key4Tokey3(key);
0189 MEStationInfo& stationInfo = mapStationInfo_[key3];
0190
0191 bh.getBooker()->setCurrentFolder(strFolderMain_ + "/clusterSize_" + getNameDirLayer(key3));
0192
0193 Int_t nNumEta = stationInfo.nNumEtaPartitions_;
0194 if (stationInfo.nNumModules_ > 1) {
0195 nNumEta = stationInfo.nNumModules_;
0196 }
0197
0198 mapCLSPerCh_.SetBinConfY(nNumEta, 0.5);
0199 mapCLSPerCh_.bookND(bh, key);
0200 mapCLSPerCh_.SetLabelForIEta(key, 2);
0201
0202 if (keyToStation(key) == 2) {
0203 if (mapCLSPerCh_.isOperating()) {
0204 mapCLSPerCh_.FindHist(key)->setYTitle("Module");
0205 }
0206 for (Int_t i = 1; i <= stationInfo.nNumModules_; i++) {
0207 std::string strLabel = std::string(Form("M%i", i));
0208 if (mapCLSPerCh_.isOperating()) {
0209 mapCLSPerCh_.FindHist(key)->setBinLabel(i, strLabel, 2);
0210 }
0211 }
0212 }
0213
0214 bh.getBooker()->setCurrentFolder(strFolderMain_);
0215
0216 return 0;
0217 }
0218
0219 void GEMRecHitSource::analyze(edm::Event const& event, edm::EventSetup const& eventSetup) {
0220 edm::Handle<GEMRecHitCollection> gemRecHits;
0221 event.getByToken(this->tagRecHit_, gemRecHits);
0222 if (!gemRecHits.isValid()) {
0223 edm::LogError(log_category_) << "GEM RecHit is not valid.\n";
0224 return;
0225 }
0226
0227 std::map<ME3IdsKey, Int_t> total_rechit_layer;
0228 std::map<ME3IdsKey, Int_t> total_rechit_iEta;
0229 std::map<ME4IdsKey, std::map<Int_t, Bool_t>> mapCLSOver5;
0230
0231 for (auto gid : listChamberId_) {
0232 auto chamber = gid.chamber();
0233 ME3IdsKey key3{gid.region(), gid.station(), gid.layer()};
0234 ME4IdsKey key4Ch{gid.region(), gid.station(), gid.layer(), gid.chamber()};
0235 MEStationInfo& stationInfo = mapStationInfo_[key3];
0236 for (auto iEta : mapEtaPartition_[gid]) {
0237 GEMDetId eId = iEta->id();
0238 ME3IdsKey key3IEta{gid.region(), gid.station(), eId.ieta()};
0239 ME3IdsKey key3AbsReIEta{std::abs(gid.region()), gid.station(), eId.ieta()};
0240 ME4IdsKey key4IEta{gid.region(), gid.station(), gid.layer(), eId.ieta()};
0241
0242 Int_t nEtaModule = eId.ieta();
0243 if (gid.station() == 2) {
0244 nEtaModule = getIdxModule(2, 24 - (nEtaModule - 1) / 4);
0245 }
0246 ME4IdsKey key4IEtaMod{gid.region(), gid.station(), gid.layer(), nEtaModule};
0247
0248 if (total_rechit_layer.find(key3) == total_rechit_layer.end())
0249 total_rechit_layer[key3] = 0;
0250
0251 const auto& recHitsRange = gemRecHits->get(eId);
0252 auto gemRecHit = recHitsRange.first;
0253 for (auto hit = gemRecHit; hit != recHitsRange.second; ++hit) {
0254 LocalPoint recHitLP = hit->localPosition();
0255 GlobalPoint recHitGP = GEMGeometry_->idToDet(hit->gemId())->surface().toGlobal(recHitLP);
0256
0257
0258 mapRecHitXY_layer_.Fill(key3, recHitGP.x(), recHitGP.y());
0259
0260
0261 mapRecHitOcc_ieta_.Fill(key3, nEtaModule);
0262
0263
0264 Float_t fPhi = recHitGP.phi();
0265 Float_t fPhiShift = restrictAngle(fPhi, stationInfo.fMinPhi_);
0266 Float_t fPhiDeg = fPhiShift * 180.0 / M_PI;
0267 mapRecHitOcc_phi_.Fill(key3, fPhiDeg);
0268
0269
0270 total_rechit_layer[key3]++;
0271 total_rechit_iEta[key3IEta]++;
0272
0273
0274 Int_t nCLS = hit->clusterSize();
0275 Int_t nCLSCutOff = std::min(nCLS, nCLSMax_);
0276 mapCLSRecHit_ieta_.Fill(key3AbsReIEta, nCLSCutOff);
0277 mapCLSPerCh_.Fill(key4Ch, nCLSCutOff, nEtaModule);
0278 mapCLSAverage_.Fill(key3, (Double_t)chamber, (Double_t)nEtaModule, nCLS);
0279 if (nCLS > 5)
0280 mapCLSOver5[key4IEtaMod][chamber] = true;
0281 }
0282 }
0283 }
0284 for (auto [key, num_total_rechit] : total_rechit_layer) {
0285 mapTotalRecHitPerEvtLayer_.Fill(key, num_total_rechit);
0286 }
0287 for (auto [key, num_total_rechit] : total_rechit_iEta) {
0288 mapTotalRecHitPerEvtIEta_.Fill(key, num_total_rechit);
0289 }
0290 for (auto [key, mapSub] : mapCLSOver5) {
0291 for (auto [chamber, b] : mapSub) {
0292 mapCLSOver5_.Fill(key4Tokey3(key), chamber, keyToIEta(key));
0293 }
0294 }
0295 }
0296
0297 DEFINE_FWK_MODULE(GEMRecHitSource);