Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-24 22:51:52

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_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   mapRecHitOcc_ieta_.SetBinConfX(stationInfo.nNumEtaPartitions_);
0139   mapRecHitOcc_ieta_.bookND(bh, key);
0140   mapRecHitOcc_ieta_.SetLabelForIEta(key, 1);
0141 
0142   mapRecHitOcc_phi_.SetBinLowEdgeX(stationInfo.fMinPhi_ * 180 / M_PI);
0143   mapRecHitOcc_phi_.SetBinHighEdgeX(stationInfo.fMinPhi_ * 180 / M_PI + 360);
0144   mapRecHitOcc_phi_.bookND(bh, key);
0145 
0146   mapTotalRecHitPerEvtLayer_.bookND(bh, key);
0147 
0148   Int_t nNewNumCh = stationInfo.nMaxIdxChamber_ - stationInfo.nMinIdxChamber_ + 1;
0149 
0150   mapCLSAverage_.SetBinConfX(nNewNumCh, stationInfo.nMinIdxChamber_ - 0.5, stationInfo.nMaxIdxChamber_ + 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_.bookND(bh, key);
0157   mapCLSOver5_.SetLabelForChambers(key, 1, -1, stationInfo.nMinIdxChamber_);
0158   mapCLSOver5_.SetLabelForIEta(key, 2);
0159 
0160   return 0;
0161 }
0162 
0163 int GEMRecHitSource::ProcessWithMEMap3WithChamber(BookingHelper& bh, ME4IdsKey key) {
0164   ME3IdsKey key3 = key4Tokey3(key);
0165   MEStationInfo& stationInfo = mapStationInfo_[key3];
0166 
0167   bh.getBooker()->setCurrentFolder(strFolderMain_ + "/clusterSize_" + getNameDirLayer(key3));
0168 
0169   mapCLSPerCh_.SetBinConfY(stationInfo.nNumEtaPartitions_);
0170   mapCLSPerCh_.bookND(bh, key);
0171   mapCLSPerCh_.SetLabelForIEta(key, 2);
0172 
0173   bh.getBooker()->setCurrentFolder(strFolderMain_);
0174 
0175   return 0;
0176 }
0177 
0178 void GEMRecHitSource::analyze(edm::Event const& event, edm::EventSetup const& eventSetup) {
0179   edm::Handle<GEMRecHitCollection> gemRecHits;
0180   event.getByToken(this->tagRecHit_, gemRecHits);
0181   if (!gemRecHits.isValid()) {
0182     edm::LogError(log_category_) << "GEM RecHit is not valid.\n";
0183     return;
0184   }
0185 
0186   std::map<ME3IdsKey, Int_t> total_rechit_layer;
0187   std::map<ME3IdsKey, Int_t> total_rechit_iEta;
0188   std::map<ME4IdsKey, std::map<Int_t, Bool_t>> mapCLSOver5;
0189 
0190   for (const auto& ch : gemChambers_) {
0191     GEMDetId gid = ch.id();
0192     auto chamber = gid.chamber();
0193     ME3IdsKey key3{gid.region(), gid.station(), gid.layer()};
0194     ME4IdsKey key4Ch{gid.region(), gid.station(), gid.layer(), gid.chamber()};
0195     MEStationInfo& stationInfo = mapStationInfo_[key3];
0196     for (auto iEta : ch.etaPartitions()) {
0197       GEMDetId eId = iEta->id();
0198       ME3IdsKey key3IEta{gid.region(), gid.station(), eId.ieta()};
0199       ME3IdsKey key3AbsReIEta{std::abs(gid.region()), gid.station(), eId.ieta()};
0200       ME4IdsKey key4IEta{gid.region(), gid.station(), gid.layer(), eId.ieta()};
0201 
0202       if (total_rechit_layer.find(key3) == total_rechit_layer.end())
0203         total_rechit_layer[key3] = 0;
0204 
0205       const auto& recHitsRange = gemRecHits->get(eId);
0206       auto gemRecHit = recHitsRange.first;
0207       for (auto hit = gemRecHit; hit != recHitsRange.second; ++hit) {
0208         LocalPoint recHitLP = hit->localPosition();
0209         GlobalPoint recHitGP = GEMGeometry_->idToDet(hit->gemId())->surface().toGlobal(recHitLP);
0210 
0211         // Filling of XY occupancy
0212         mapRecHitXY_layer_.Fill(key3, recHitGP.x(), recHitGP.y());
0213 
0214         // Filling of RecHit (iEta)
0215         mapRecHitOcc_ieta_.Fill(key3, eId.ieta());
0216 
0217         // Filling of RecHit (phi)
0218         Float_t fPhi = recHitGP.phi();
0219         Float_t fPhiShift = restrictAngle(fPhi, stationInfo.fMinPhi_);
0220         Float_t fPhiDeg = fPhiShift * 180.0 / M_PI;
0221         mapRecHitOcc_phi_.Fill(key3, fPhiDeg);
0222 
0223         // For total RecHits
0224         total_rechit_layer[key3]++;
0225         total_rechit_iEta[key3IEta]++;
0226 
0227         // Filling of cluster size (CLS)
0228         Int_t nCLS = hit->clusterSize();
0229         Int_t nCLSCutOff = std::min(nCLS, nCLSMax_);  // For overflow
0230         mapCLSRecHit_ieta_.Fill(key3AbsReIEta, nCLSCutOff);
0231         mapCLSPerCh_.Fill(key4Ch, nCLSCutOff, eId.ieta());
0232         mapCLSAverage_.Fill(key3, (Double_t)chamber, (Double_t)eId.ieta(), nCLS);
0233         if (nCLS > 5)
0234           mapCLSOver5[key4IEta][chamber] = true;
0235       }
0236     }
0237   }
0238   for (auto [key, num_total_rechit] : total_rechit_layer) {
0239     mapTotalRecHitPerEvtLayer_.Fill(key, num_total_rechit);
0240   }
0241   for (auto [key, num_total_rechit] : total_rechit_iEta) {
0242     mapTotalRecHitPerEvtIEta_.Fill(key, num_total_rechit);
0243   }
0244   for (auto [key, mapSub] : mapCLSOver5) {
0245     for (auto [chamber, b] : mapSub) {
0246       mapCLSOver5_.Fill(key4Tokey3(key), chamber, keyToIEta(key));
0247     }
0248   }
0249 }
0250 
0251 DEFINE_FWK_MODULE(GEMRecHitSource);