File indexing completed on 2024-09-07 04:34:32
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include "FWCore/Framework/interface/Frameworkfwd.h"
0022 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0023 #include "FWCore/Framework/interface/EventSetup.h"
0024 #include "FWCore/Framework/interface/ESHandle.h"
0025 #include "FWCore/Framework/interface/Event.h"
0026 #include "FWCore/Framework/interface/MakerMacros.h"
0027 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0028 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0029
0030
0031 #include "Alignment/MuonAlignment/interface/MuonAlignment.h"
0032 #include "Alignment/MuonAlignment/interface/MuonAlignmentInputMethod.h"
0033 #include "Alignment/MuonAlignment/interface/MuonAlignmentInputDB.h"
0034 #include "Alignment/MuonAlignment/interface/MuonAlignmentInputSurveyDB.h"
0035 #include "Alignment/MuonAlignment/interface/MuonAlignmentInputXML.h"
0036 #include "Alignment/MuonAlignment/interface/MuonScenarioBuilder.h"
0037 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0038 #include "CondFormats/AlignmentRecord/interface/GlobalPositionRcd.h"
0039
0040
0041
0042
0043
0044 class MuonGeometryDBConverter : public edm::one::EDAnalyzer<> {
0045 public:
0046 explicit MuonGeometryDBConverter(const edm::ParameterSet &);
0047 ~MuonGeometryDBConverter() override;
0048
0049 static void fillDescriptions(edm::ConfigurationDescriptions &);
0050 void beginJob() override {}
0051 void endJob() override {}
0052
0053 private:
0054 void analyze(const edm::Event &, const edm::EventSetup &) override;
0055
0056 bool m_done;
0057 std::string m_input, m_output;
0058
0059 std::string m_dtLabel, m_cscLabel, m_gemLabel, m_dtAPELabel, m_cscAPELabel, m_gemAPELabel;
0060 double m_shiftErr, m_angleErr;
0061 std::string m_fileName;
0062 bool m_getAPEs;
0063
0064 edm::ParameterSet m_misalignmentScenario;
0065 edm::ParameterSet m_outputXML;
0066 const std::string idealGeometryLabelForInputXML, idealGeometryLabel;
0067
0068 const edm::ESGetToken<DTGeometry, MuonGeometryRecord> dtGeomIdealToken_;
0069 const edm::ESGetToken<CSCGeometry, MuonGeometryRecord> cscGeomIdealToken_;
0070 const edm::ESGetToken<GEMGeometry, MuonGeometryRecord> gemGeomIdealToken_;
0071
0072 edm::ESGetToken<DTGeometry, MuonGeometryRecord> dtGeomToken_;
0073 edm::ESGetToken<CSCGeometry, MuonGeometryRecord> cscGeomToken_;
0074 edm::ESGetToken<GEMGeometry, MuonGeometryRecord> gemGeomToken_;
0075
0076 edm::ESGetToken<Alignments, DTAlignmentRcd> dtAliToken_;
0077 edm::ESGetToken<Alignments, CSCAlignmentRcd> cscAliToken_;
0078 edm::ESGetToken<Alignments, GEMAlignmentRcd> gemAliToken_;
0079
0080 edm::ESGetToken<AlignmentErrorsExtended, DTAlignmentErrorExtendedRcd> dtAPEToken_;
0081 edm::ESGetToken<AlignmentErrorsExtended, CSCAlignmentErrorExtendedRcd> cscAPEToken_;
0082 edm::ESGetToken<AlignmentErrorsExtended, GEMAlignmentErrorExtendedRcd> gemAPEToken_;
0083
0084 const edm::ESGetToken<Alignments, GlobalPositionRcd> gprToken_;
0085 };
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098 MuonGeometryDBConverter::MuonGeometryDBConverter(const edm::ParameterSet &iConfig)
0099 : m_done(false),
0100 m_input(iConfig.getParameter<std::string>("input")),
0101 m_output(iConfig.getParameter<std::string>("output")),
0102 m_shiftErr(0.),
0103 m_angleErr(0.),
0104 m_getAPEs(false),
0105 idealGeometryLabelForInputXML("idealForInputXML"),
0106 idealGeometryLabel("idealGeometry"),
0107 dtGeomIdealToken_(esConsumes(edm::ESInputTag("", idealGeometryLabel))),
0108 cscGeomIdealToken_(esConsumes(edm::ESInputTag("", idealGeometryLabel))),
0109 gemGeomIdealToken_(esConsumes(edm::ESInputTag("", idealGeometryLabel))),
0110 gprToken_(esConsumes<Alignments, GlobalPositionRcd>(edm::ESInputTag("", ""))) {
0111
0112
0113
0114
0115
0116
0117
0118
0119 if (m_input == std::string("ideal")) {
0120 } else if (m_input == std::string("db")) {
0121 m_dtLabel = iConfig.getParameter<std::string>("dtLabel");
0122 m_cscLabel = iConfig.getParameter<std::string>("cscLabel");
0123 m_gemLabel = iConfig.getParameter<std::string>("gemLabel");
0124 m_dtAPELabel = iConfig.getParameter<std::string>("dtAPELabel");
0125 m_cscAPELabel = iConfig.getParameter<std::string>("cscAPELabel");
0126 m_gemAPELabel = iConfig.getParameter<std::string>("gemAPELabel");
0127 m_shiftErr = iConfig.getParameter<double>("shiftErr");
0128 m_angleErr = iConfig.getParameter<double>("angleErr");
0129 m_getAPEs = iConfig.getParameter<bool>("getAPEs");
0130 m_outputXML = iConfig.getParameter<edm::ParameterSet>("outputXML");
0131
0132 dtAliToken_ = esConsumes(edm::ESInputTag("", m_dtLabel));
0133 cscAliToken_ = esConsumes(edm::ESInputTag("", m_cscLabel));
0134 gemAliToken_ = esConsumes(edm::ESInputTag("", m_gemLabel));
0135
0136 dtAPEToken_ = esConsumes(edm::ESInputTag("", m_dtAPELabel));
0137 cscAPEToken_ = esConsumes(edm::ESInputTag("", m_cscAPELabel));
0138 gemAPEToken_ = esConsumes(edm::ESInputTag("", m_gemAPELabel));
0139
0140 dtGeomToken_ = esConsumes(edm::ESInputTag("", idealGeometryLabelForInputXML));
0141 cscGeomToken_ = esConsumes(edm::ESInputTag("", idealGeometryLabelForInputXML));
0142 gemGeomToken_ = esConsumes(edm::ESInputTag("", idealGeometryLabelForInputXML));
0143 } else if (m_input == std::string("surveydb")) {
0144 m_dtLabel = iConfig.getParameter<std::string>("dtLabel");
0145 m_cscLabel = iConfig.getParameter<std::string>("cscLabel");
0146 m_gemLabel = iConfig.getParameter<std::string>("gemLabel");
0147 } else if (m_input == std::string("scenario")) {
0148 m_misalignmentScenario = iConfig.getParameter<edm::ParameterSet>("MisalignmentScenario");
0149 m_shiftErr = iConfig.getParameter<double>("shiftErr");
0150 m_angleErr = iConfig.getParameter<double>("angleErr");
0151 } else if (m_input == std::string("xml")) {
0152 m_fileName = iConfig.getParameter<std::string>("fileName");
0153 m_shiftErr = iConfig.getParameter<double>("shiftErr");
0154 m_angleErr = iConfig.getParameter<double>("angleErr");
0155 dtGeomToken_ = esConsumes(edm::ESInputTag("", idealGeometryLabelForInputXML));
0156 cscGeomToken_ = esConsumes(edm::ESInputTag("", idealGeometryLabelForInputXML));
0157 gemGeomToken_ = esConsumes(edm::ESInputTag("", idealGeometryLabelForInputXML));
0158 } else {
0159 throw cms::Exception("BadConfig") << "input must be \"ideal\", \"db\", \"surveydb\", or \"xml\"." << std::endl;
0160 }
0161 if (m_output == std::string("none")) {
0162 } else if (m_output == std::string("db")) {
0163 } else if (m_output == std::string("xml")) {
0164 m_outputXML = iConfig.getParameter<edm::ParameterSet>("outputXML");
0165 } else {
0166 throw cms::Exception("BadConfig") << "output must be \"none\", \"db \", \"xml\"." << std::endl;
0167 }
0168 }
0169
0170 MuonGeometryDBConverter::~MuonGeometryDBConverter() {}
0171
0172
0173 void MuonGeometryDBConverter::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0174 if (!m_done) {
0175 if (m_input == std::string("ideal")) {
0176 MuonAlignmentInputMethod inputMethod(
0177 &iSetup.getData(dtGeomIdealToken_), &iSetup.getData(cscGeomIdealToken_), &iSetup.getData(gemGeomIdealToken_));
0178 MuonAlignment *muonAlignment = new MuonAlignment(iSetup, inputMethod);
0179 muonAlignment->fillGapsInSurvey(0., 0.);
0180 muonAlignment->saveToDB();
0181 } else if (m_input == std::string("db")) {
0182 MuonAlignmentInputDB inputMethod(&iSetup.getData(dtGeomIdealToken_),
0183 &iSetup.getData(cscGeomIdealToken_),
0184 &iSetup.getData(gemGeomIdealToken_),
0185 &iSetup.getData(dtAliToken_),
0186 &iSetup.getData(cscAliToken_),
0187 &iSetup.getData(gemAliToken_),
0188 &iSetup.getData(dtAPEToken_),
0189 &iSetup.getData(cscAPEToken_),
0190 &iSetup.getData(gemAPEToken_),
0191 &iSetup.getData(gprToken_));
0192 MuonAlignment *muonAlignment = new MuonAlignment(iSetup, inputMethod);
0193 if (m_getAPEs) {
0194 muonAlignment->copyAlignmentToSurvey(m_shiftErr, m_angleErr);
0195 }
0196 muonAlignment->writeXML(
0197 m_outputXML, &iSetup.getData(dtGeomToken_), &iSetup.getData(cscGeomToken_), &iSetup.getData(gemGeomToken_));
0198 } else if (m_input == std::string("scenario")) {
0199 MuonAlignmentInputMethod inputMethod(
0200 &iSetup.getData(dtGeomIdealToken_), &iSetup.getData(cscGeomIdealToken_), &iSetup.getData(gemGeomIdealToken_));
0201 MuonAlignment *muonAlignment = new MuonAlignment(iSetup, inputMethod);
0202
0203 MuonScenarioBuilder muonScenarioBuilder(muonAlignment->getAlignableMuon());
0204 muonScenarioBuilder.applyScenario(m_misalignmentScenario);
0205 muonAlignment->saveToDB();
0206 muonAlignment->copyAlignmentToSurvey(m_shiftErr, m_angleErr);
0207 } else if (m_input == std::string("xml")) {
0208 MuonAlignmentInputXML inputMethod(m_fileName,
0209 &iSetup.getData(dtGeomToken_),
0210 &iSetup.getData(cscGeomToken_),
0211 &iSetup.getData(gemGeomToken_),
0212 &iSetup.getData(dtGeomIdealToken_),
0213 &iSetup.getData(cscGeomIdealToken_),
0214 &iSetup.getData(gemGeomIdealToken_));
0215 MuonAlignment *muonAlignment = new MuonAlignment(iSetup, inputMethod);
0216 muonAlignment->saveToDB();
0217 muonAlignment->fillGapsInSurvey(m_shiftErr, m_angleErr);
0218 }
0219 m_done = true;
0220 }
0221 else {
0222 throw cms::Exception("BadConfig") << "Set maxEvents.input to 1. (Your output is okay.)" << std::endl;
0223 }
0224 }
0225
0226
0227 void MuonGeometryDBConverter::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0228 edm::ParameterSetDescription desc;
0229 desc.setComment("Converts muon geometry between various formats.");
0230 desc.add<std::string>("input", "ideal");
0231 desc.add<std::string>("dtLabel", "");
0232 desc.add<std::string>("cscLabel", "");
0233 desc.add<std::string>("gemLabel", "");
0234 desc.add<std::string>("dtAPELabel", "");
0235 desc.add<std::string>("cscAPELabel", "");
0236 desc.add<std::string>("gemAPELabel", "");
0237 desc.add<double>("shiftErr", 1000.0);
0238 desc.add<double>("angleErr", 6.28);
0239 desc.add<bool>("getAPEs", true);
0240 desc.add<std::string>("output", "xml");
0241 desc.add<std::string>("fileName", "REPLACEME.xml");
0242 edm::ParameterSetDescription outputXML;
0243 outputXML.add<std::string>("fileName", "REPLACEME.xml");
0244 outputXML.add<std::string>("relativeto", "ideal");
0245 outputXML.add<bool>("rawIds", false);
0246 outputXML.add<bool>("survey", false);
0247 outputXML.add<bool>("eulerAngles", false);
0248 outputXML.add<int>("precision", 10);
0249 outputXML.addUntracked<bool>("suppressDTBarrel", true);
0250 outputXML.addUntracked<bool>("suppressDTWheels", true);
0251 outputXML.addUntracked<bool>("suppressDTStations", true);
0252 outputXML.addUntracked<bool>("suppressDTChambers", false);
0253 outputXML.addUntracked<bool>("suppressDTSuperLayers", false);
0254 outputXML.addUntracked<bool>("suppressDTLayers", false);
0255 outputXML.addUntracked<bool>("suppressCSCEndcaps", true);
0256 outputXML.addUntracked<bool>("suppressCSCStations", true);
0257 outputXML.addUntracked<bool>("suppressCSCRings", true);
0258 outputXML.addUntracked<bool>("suppressCSCChambers", false);
0259 outputXML.addUntracked<bool>("suppressCSCLayers", false);
0260 outputXML.addUntracked<bool>("suppressGEMEndcaps", true);
0261 outputXML.addUntracked<bool>("suppressGEMStations", true);
0262 outputXML.addUntracked<bool>("suppressGEMRings", true);
0263 outputXML.addUntracked<bool>("suppressGEMSuperChambers", false);
0264 outputXML.addUntracked<bool>("suppressGEMChambers", true);
0265 outputXML.addUntracked<bool>("suppressGEMEtaPartitions", true);
0266 desc.add("outputXML", outputXML);
0267 descriptions.add("muonGeometryDBConverter", desc);
0268 }
0269
0270
0271 DEFINE_FWK_MODULE(MuonGeometryDBConverter);