File indexing completed on 2024-04-06 12:02:30
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <memory>
0013 #include <regex>
0014
0015
0016 #include "FWCore/Framework/interface/Frameworkfwd.h"
0017 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0018
0019 #include "FWCore/Framework/interface/Run.h"
0020 #include "FWCore/Framework/interface/Event.h"
0021 #include "FWCore/Framework/interface/ESHandle.h"
0022 #include "FWCore/Framework/interface/EventSetup.h"
0023 #include "FWCore/Framework/interface/MakerMacros.h"
0024 #include "FWCore/Framework/interface/IOVSyncValue.h"
0025 #include "FWCore/ServiceRegistry/interface/Service.h"
0026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0027
0028 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0029 #include "Geometry/DTGeometry/interface/DTGeometry.h"
0030 #include "Geometry/CSCGeometry/interface/CSCGeometry.h"
0031
0032 #include "CondFormats/RecoMuonObjects/interface/MuonSystemAging.h"
0033 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0034
0035
0036
0037
0038
0039 class ProduceAgingObject : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0040 public:
0041 explicit ProduceAgingObject(const edm::ParameterSet&);
0042 ~ProduceAgingObject();
0043
0044 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0045
0046 private:
0047 virtual void beginJob() override{};
0048 virtual void beginRun(const edm::Run&, const edm::EventSetup&) override;
0049 virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
0050 virtual void endRun(const edm::Run&, const edm::EventSetup&) override{};
0051 virtual void endJob() override{};
0052
0053 void createRpcAgingMap();
0054 void createDtAgingMap(const DTGeometry& dtGeom);
0055 void createCscAgingMap(const CSCGeometry& cscGeom);
0056 void printAgingMap(const std::map<uint32_t, float>& map, const std::string& type) const;
0057
0058
0059
0060 edm::ESGetToken<DTGeometry, MuonGeometryRecord> m_dtGeomToken;
0061 edm::ESGetToken<CSCGeometry, MuonGeometryRecord> m_cscGeomToken;
0062
0063 std::vector<std::string> m_DTRegEx;
0064 std::vector<std::string> m_RPCRegEx;
0065 std::vector<std::string> m_CSCRegEx;
0066
0067 std::map<uint32_t, float> m_DTChambEffs;
0068 std::map<uint32_t, float> m_RPCChambEffs;
0069 std::map<uint32_t, std::pair<uint32_t, float>> m_CSCChambEffs;
0070
0071 std::map<uint32_t, float> m_GEMChambEffs;
0072 std::map<uint32_t, float> m_ME0ChambEffs;
0073 };
0074
0075
0076
0077
0078
0079 ProduceAgingObject::ProduceAgingObject(const edm::ParameterSet& iConfig)
0080 : m_dtGeomToken(esConsumes<edm::Transition::BeginRun>()),
0081 m_cscGeomToken(esConsumes<edm::Transition::BeginRun>()),
0082 m_DTRegEx(iConfig.getParameter<std::vector<std::string>>("dtRegEx")),
0083 m_RPCRegEx(iConfig.getParameter<std::vector<std::string>>("rpcRegEx")),
0084 m_CSCRegEx(iConfig.getParameter<std::vector<std::string>>("cscRegEx")) {
0085 for (auto gemId : iConfig.getParameter<std::vector<int>>("maskedGEMIDs")) {
0086 m_GEMChambEffs[gemId] = 0.;
0087 }
0088
0089 for (auto gemId : iConfig.getParameter<std::vector<int>>("maskedME0IDs")) {
0090 m_ME0ChambEffs[gemId] = 0.;
0091 }
0092 }
0093
0094 ProduceAgingObject::~ProduceAgingObject() {}
0095
0096
0097
0098
0099
0100
0101 void ProduceAgingObject::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0102 MuonSystemAging muonAgingObject;
0103
0104 muonAgingObject.m_DTChambEffs = m_DTChambEffs;
0105 muonAgingObject.m_RPCChambEffs = m_RPCChambEffs;
0106 muonAgingObject.m_CSCChambEffs = m_CSCChambEffs;
0107
0108 muonAgingObject.m_GEMChambEffs = m_GEMChambEffs;
0109 muonAgingObject.m_ME0ChambEffs = m_ME0ChambEffs;
0110
0111 edm::Service<cond::service::PoolDBOutputService> poolDbService;
0112 if (poolDbService.isAvailable())
0113 poolDbService->writeOneIOV(muonAgingObject, poolDbService->currentTime(), "MuonSystemAgingRcd");
0114 }
0115
0116
0117 void ProduceAgingObject::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
0118 auto const& dtGeom = iSetup.getData(m_dtGeomToken);
0119 auto const& cscGeom = iSetup.getData(m_cscGeomToken);
0120
0121 createDtAgingMap(dtGeom);
0122 createCscAgingMap(cscGeom);
0123 createRpcAgingMap();
0124
0125 printAgingMap(m_GEMChambEffs, "GEM");
0126 printAgingMap(m_ME0ChambEffs, "ME0");
0127 }
0128
0129
0130 void ProduceAgingObject::createRpcAgingMap() {
0131 std::cout << "[ProduceAgingObject] List of aged RPC objects (ID, efficiency)" << std::endl;
0132 for (auto& chRegExStr : m_RPCRegEx) {
0133 std::string id = chRegExStr.substr(0, chRegExStr.find(":"));
0134 std::string eff = chRegExStr.substr(id.size() + 1, chRegExStr.find(":"));
0135
0136 std::cout << "\t( " << id << " , " << eff << " )" << std::endl;
0137 m_RPCChambEffs[std::atoi(id.c_str())] = std::atof(eff.c_str());
0138 }
0139 }
0140
0141
0142 void ProduceAgingObject::createDtAgingMap(const DTGeometry& dtGeom) {
0143 const std::vector<const DTChamber*> chambers = dtGeom.chambers();
0144
0145 std::cout << "[ProduceAgingObject] List of aged DT chambers (ChamberID, efficiency)" << std::endl;
0146 for (const DTChamber* ch : chambers) {
0147 DTChamberId chId = ch->id();
0148
0149 std::string chTag = "WH" + std::to_string(chId.wheel()) + "_ST" + std::to_string(chId.station()) + "_SEC" +
0150 std::to_string(chId.sector());
0151
0152 float eff = 1.;
0153
0154 for (auto& chRegExStr : m_DTRegEx) {
0155 std::string effTag(chRegExStr.substr(chRegExStr.find(":")));
0156
0157 const std::regex chRegEx(chRegExStr.substr(0, chRegExStr.find(":")));
0158 const std::regex effRegEx("(\\d*\\.\\d*)");
0159
0160 std::smatch effMatch;
0161
0162 if (std::regex_search(chTag, chRegEx) && std::regex_search(effTag, effMatch, effRegEx)) {
0163 std::string effStr = effMatch.str();
0164 eff = std::atof(effStr.c_str());
0165 }
0166 }
0167
0168 if (eff < 1.) {
0169 std::cout << "\t(" << chId << ", " << eff << " )" << std::endl;
0170 m_DTChambEffs[chId.rawId()] = eff;
0171 }
0172 }
0173 }
0174
0175
0176 void ProduceAgingObject::createCscAgingMap(const CSCGeometry& cscGeom) {
0177 const auto chambers = cscGeom.chambers();
0178
0179 std::cout << "[ProduceAgingObject] List of aged CSC chambers (ChamberID, efficiency, type)" << std::endl;
0180
0181 for (const auto* ch : chambers) {
0182 CSCDetId chId = ch->id();
0183
0184 std::string chTag = (chId.zendcap() == 1 ? "ME+" : "ME-") + std::to_string(chId.station()) + "/" +
0185 std::to_string(chId.ring()) + "/" + std::to_string(chId.chamber());
0186
0187 int type = 0;
0188 float eff = 1.;
0189
0190 for (auto& chRegExStr : m_CSCRegEx) {
0191 int loc = chRegExStr.find(":");
0192
0193 if (loc < 0)
0194 continue;
0195
0196 std::string effTag(chRegExStr.substr(loc));
0197
0198 const std::regex chRegEx(chRegExStr.substr(0, chRegExStr.find(":")));
0199 const std::regex predicateRegEx("(\\d*,\\d*\\.\\d*)");
0200
0201 std::smatch predicate;
0202
0203 if (std::regex_search(chTag, chRegEx) && std::regex_search(effTag, predicate, predicateRegEx)) {
0204 std::string predicateStr = predicate.str();
0205 std::string typeStr = predicateStr.substr(0, predicateStr.find(","));
0206 std::string effStr = predicateStr.substr(predicateStr.find(",") + 1);
0207 type = std::atoi(typeStr.c_str());
0208 eff = std::atof(effStr.c_str());
0209
0210 std::cout << "\t( " << chTag << " , " << eff << " , " << type << " )" << std::endl;
0211 }
0212 }
0213
0214
0215 int rawId = chId.rawIdMaker(chId.endcap(), chId.station(), chId.ring(), chId.chamber(), 0);
0216 m_CSCChambEffs[rawId] = std::make_pair(type, eff);
0217 }
0218 }
0219 void ProduceAgingObject::printAgingMap(const std::map<uint32_t, float>& map, const std::string& type) const {
0220 std::cout << "[ProduceAgingObject] List of aged " << type << " objects (ID, efficiency)" << std::endl;
0221
0222 std::map<uint32_t, float>::const_iterator mapObj = map.begin();
0223 std::map<uint32_t, float>::const_iterator mapEnd = map.end();
0224
0225 for (; mapObj != mapEnd; ++mapObj) {
0226 std::cout << "\t( " << mapObj->first << " , " << mapObj->second << " )" << std::endl;
0227 }
0228 }
0229
0230
0231 void ProduceAgingObject::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0232 edm::ParameterSetDescription desc;
0233 desc.add<std::vector<std::string>>("dtRegEx", {});
0234 desc.add<std::vector<std::string>>("rpcRegEx", {});
0235 desc.add<std::vector<std::string>>("cscRegEx", {});
0236 desc.add<std::vector<int>>("maskedGEMIDs", {});
0237 desc.add<std::vector<int>>("maskedME0IDs", {});
0238
0239 descriptions.addDefault(desc);
0240 }
0241
0242
0243 DEFINE_FWK_MODULE(ProduceAgingObject);