Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-04-02 02:42:24

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,  // TProfile2D
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,  // For satefy, larger than 384
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_RELVAL) {
0088     mapRecHitXY_layer_.TurnOff();
0089     mapCLSAverage_.TurnOff();
0090     mapCLSOver5_.TurnOff();
0091     mapCLSPerCh_.TurnOff();
0092   }
0093 
0094   if (nRunType_ != GEMDQM_RUNTYPE_ALLPLOTS && nRunType_ != GEMDQM_RUNTYPE_RELVAL) {
0095     mapRecHitOcc_ieta_.TurnOff();
0096     mapRecHitOcc_phi_.TurnOff();
0097     mapCLSRecHit_ieta_.TurnOff();
0098   }
0099 
0100   if (nRunType_ != GEMDQM_RUNTYPE_ALLPLOTS) {
0101     mapTotalRecHitPerEvtLayer_.TurnOff();
0102     mapTotalRecHitPerEvtIEta_.TurnOff();
0103   }
0104 
0105   GenerateMEPerChamber(ibooker);
0106 }
0107 
0108 int GEMRecHitSource::ProcessWithMEMap2WithEta(BookingHelper& bh, ME3IdsKey key) {
0109   mapTotalRecHitPerEvtIEta_.bookND(bh, key);
0110 
0111   return 0;
0112 }
0113 
0114 int GEMRecHitSource::ProcessWithMEMap2AbsReWithEta(BookingHelper& bh, ME3IdsKey key) {
0115   mapCLSRecHit_ieta_.bookND(bh, key);
0116 
0117   return 0;
0118 }
0119 
0120 int GEMRecHitSource::ProcessWithMEMap3(BookingHelper& bh, ME3IdsKey key) {
0121   MEStationInfo& stationInfo = mapStationInfo_[key];
0122 
0123   Float_t fR1 = !stationInfo.listRadiusEvenChamber_.empty() ? stationInfo.listRadiusEvenChamber_.back() : 0.0;
0124   Float_t fR2 = !stationInfo.listRadiusOddChamber_.empty() ? stationInfo.listRadiusOddChamber_.back() : 0.0;
0125   Float_t fRangeRadius = (int)(std::max(fR1, fR2) * 0.11 + 0.99999) * 10.0;
0126 
0127   mapRecHitXY_layer_.SetBinLowEdgeX(-fRangeRadius);
0128   mapRecHitXY_layer_.SetBinHighEdgeX(fRangeRadius);
0129   mapRecHitXY_layer_.SetBinLowEdgeY(-fRangeRadius);
0130   mapRecHitXY_layer_.SetBinHighEdgeY(fRangeRadius);
0131   mapRecHitXY_layer_.bookND(bh, key);
0132 
0133   Int_t nNumEta = stationInfo.nNumEtaPartitions_;
0134   if (stationInfo.nNumModules_ > 1) {
0135     nNumEta = stationInfo.nNumModules_;
0136   }
0137   mapRecHitOcc_ieta_.SetBinConfX(nNumEta);
0138   mapRecHitOcc_ieta_.bookND(bh, key);
0139   mapRecHitOcc_ieta_.SetLabelForIEta(key, 1);
0140 
0141   mapRecHitOcc_phi_.SetBinLowEdgeX(stationInfo.fMinPhi_ * 180 / M_PI);
0142   mapRecHitOcc_phi_.SetBinHighEdgeX(stationInfo.fMinPhi_ * 180 / M_PI + 360);
0143   mapRecHitOcc_phi_.bookND(bh, key);
0144 
0145   mapTotalRecHitPerEvtLayer_.bookND(bh, key);
0146 
0147   Int_t nNewNumCh = stationInfo.nMaxIdxChamber_ - stationInfo.nMinIdxChamber_ + 1;
0148 
0149   mapCLSAverage_.SetBinConfX(nNewNumCh, stationInfo.nMinIdxChamber_ - 0.5, stationInfo.nMaxIdxChamber_ + 0.5);
0150   mapCLSAverage_.SetBinConfY(nNumEta, 0.5);
0151   mapCLSAverage_.bookND(bh, key);
0152   mapCLSAverage_.SetLabelForChambers(key, 1, -1, stationInfo.nMinIdxChamber_);
0153   mapCLSAverage_.SetLabelForIEta(key, 2);
0154 
0155   mapCLSOver5_.SetBinConfX(nNewNumCh, stationInfo.nMinIdxChamber_ - 0.5, stationInfo.nMaxIdxChamber_ + 0.5);
0156   mapCLSOver5_.SetBinConfY(nNumEta, 0.5);
0157   mapCLSOver5_.bookND(bh, key);
0158   mapCLSOver5_.SetLabelForChambers(key, 1, -1, stationInfo.nMinIdxChamber_);
0159   mapCLSOver5_.SetLabelForIEta(key, 2);
0160 
0161   if (keyToStation(key) == 2) {
0162     if (mapCLSAverage_.isOperating()) {
0163       mapCLSAverage_.FindHist(key)->setYTitle("Module");
0164     }
0165     if (mapCLSOver5_.isOperating()) {
0166       mapCLSOver5_.FindHist(key)->setYTitle("Module");
0167     }
0168     for (Int_t i = 1; i <= stationInfo.nNumModules_; i++) {
0169       std::string strLabel = std::string(Form("M%i", i));
0170       if (mapCLSAverage_.isOperating()) {
0171         mapCLSAverage_.FindHist(key)->setBinLabel(i, strLabel, 2);
0172       }
0173       if (mapCLSOver5_.isOperating()) {
0174         mapCLSOver5_.FindHist(key)->setBinLabel(i, strLabel, 2);
0175       }
0176     }
0177   }
0178 
0179   return 0;
0180 }
0181 
0182 int GEMRecHitSource::ProcessWithMEMap4WithChamber(BookingHelper& bh, ME4IdsKey key) {
0183   ME3IdsKey key3 = key4Tokey3(key);
0184   MEStationInfo& stationInfo = mapStationInfo_[key3];
0185 
0186   bh.getBooker()->setCurrentFolder(strFolderMain_ + "/clusterSize_" + getNameDirLayer(key3));
0187 
0188   Int_t nNumEta = stationInfo.nNumEtaPartitions_;
0189   if (stationInfo.nNumModules_ > 1) {
0190     nNumEta = stationInfo.nNumModules_;
0191   }
0192 
0193   mapCLSPerCh_.SetBinConfY(nNumEta, 0.5);
0194   mapCLSPerCh_.bookND(bh, key);
0195   mapCLSPerCh_.SetLabelForIEta(key, 2);
0196 
0197   if (keyToStation(key) == 2) {
0198     if (mapCLSPerCh_.isOperating()) {
0199       mapCLSPerCh_.FindHist(key)->setYTitle("Module");
0200     }
0201     for (Int_t i = 1; i <= stationInfo.nNumModules_; i++) {
0202       std::string strLabel = std::string(Form("M%i", i));
0203       if (mapCLSPerCh_.isOperating()) {
0204         mapCLSPerCh_.FindHist(key)->setBinLabel(i, strLabel, 2);
0205       }
0206     }
0207   }
0208 
0209   bh.getBooker()->setCurrentFolder(strFolderMain_);
0210 
0211   return 0;
0212 }
0213 
0214 void GEMRecHitSource::analyze(edm::Event const& event, edm::EventSetup const& eventSetup) {
0215   edm::Handle<GEMRecHitCollection> gemRecHits;
0216   event.getByToken(this->tagRecHit_, gemRecHits);
0217   if (!gemRecHits.isValid()) {
0218     edm::LogError(log_category_) << "GEM RecHit is not valid.\n";
0219     return;
0220   }
0221 
0222   std::map<ME3IdsKey, Int_t> total_rechit_layer;
0223   std::map<ME3IdsKey, Int_t> total_rechit_iEta;
0224   std::map<ME4IdsKey, std::map<Int_t, Bool_t>> mapCLSOver5;
0225 
0226   for (auto gid : listChamberId_) {
0227     auto chamber = gid.chamber();
0228     ME3IdsKey key3{gid.region(), gid.station(), gid.layer()};
0229     ME4IdsKey key4Ch{gid.region(), gid.station(), gid.layer(), gid.chamber()};
0230     MEStationInfo& stationInfo = mapStationInfo_[key3];
0231     for (auto iEta : mapEtaPartition_[gid]) {
0232       GEMDetId eId = iEta->id();
0233       ME3IdsKey key3IEta{gid.region(), gid.station(), eId.ieta()};
0234       ME3IdsKey key3AbsReIEta{std::abs(gid.region()), gid.station(), eId.ieta()};
0235       ME4IdsKey key4IEta{gid.region(), gid.station(), gid.layer(), eId.ieta()};
0236 
0237       Int_t nEtaModule = eId.ieta();
0238       if (gid.station() == 2) {
0239         nEtaModule = getIdxModule(2, 24 - (nEtaModule - 1) / 4);
0240       }
0241       ME4IdsKey key4IEtaMod{gid.region(), gid.station(), gid.layer(), nEtaModule};
0242 
0243       if (total_rechit_layer.find(key3) == total_rechit_layer.end())
0244         total_rechit_layer[key3] = 0;
0245 
0246       const auto& recHitsRange = gemRecHits->get(eId);
0247       auto gemRecHit = recHitsRange.first;
0248       for (auto hit = gemRecHit; hit != recHitsRange.second; ++hit) {
0249         LocalPoint recHitLP = hit->localPosition();
0250         GlobalPoint recHitGP = GEMGeometry_->idToDet(hit->gemId())->surface().toGlobal(recHitLP);
0251 
0252         // Filling of XY occupancy
0253         mapRecHitXY_layer_.Fill(key3, recHitGP.x(), recHitGP.y());
0254 
0255         // Filling of RecHit (iEta)
0256         mapRecHitOcc_ieta_.Fill(key3, nEtaModule);
0257 
0258         // Filling of RecHit (phi)
0259         Float_t fPhi = recHitGP.phi();
0260         Float_t fPhiShift = restrictAngle(fPhi, stationInfo.fMinPhi_);
0261         Float_t fPhiDeg = fPhiShift * 180.0 / M_PI;
0262         mapRecHitOcc_phi_.Fill(key3, fPhiDeg);
0263 
0264         // For total RecHits
0265         total_rechit_layer[key3]++;
0266         total_rechit_iEta[key3IEta]++;
0267 
0268         // Filling of cluster size (CLS)
0269         Int_t nCLS = hit->clusterSize();
0270         Int_t nCLSCutOff = std::min(nCLS, nCLSMax_);  // For overflow
0271         mapCLSRecHit_ieta_.Fill(key3AbsReIEta, nCLSCutOff);
0272         mapCLSPerCh_.Fill(key4Ch, nCLSCutOff, nEtaModule);
0273         mapCLSAverage_.Fill(key3, (Double_t)chamber, (Double_t)nEtaModule, nCLS);
0274         if (nCLS > 5)
0275           mapCLSOver5[key4IEtaMod][chamber] = true;
0276       }
0277     }
0278   }
0279   for (auto [key, num_total_rechit] : total_rechit_layer) {
0280     mapTotalRecHitPerEvtLayer_.Fill(key, num_total_rechit);
0281   }
0282   for (auto [key, num_total_rechit] : total_rechit_iEta) {
0283     mapTotalRecHitPerEvtIEta_.Fill(key, num_total_rechit);
0284   }
0285   for (const auto& [key, mapSub] : mapCLSOver5) {
0286     for (auto [chamber, b] : mapSub) {
0287       mapCLSOver5_.Fill(key4Tokey3(key), chamber, keyToIEta(key));
0288     }
0289   }
0290 }
0291 
0292 DEFINE_FWK_MODULE(GEMRecHitSource);