Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:07:25

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