Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-25 03:29:06

0001 // -*- C++ -*-
0002 //
0003 // Package:    MuonGeometryDBConverter
0004 // Class:      MuonGeometryDBConverter
0005 //
0006 /**\class MuonGeometryDBConverter MuonGeometryDBConverter.cc Alignment/MuonAlignment/plugins/MuonGeometryDBConverter.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Jim Pivarski
0015 //         Created:  Sat Feb 16 00:04:55 CST 2008
0016 // $Id: MuonGeometryDBConverter.cc,v 1.15 2011/09/15 09:12:01 mussgill Exp $
0017 //
0018 //
0019 
0020 // system include files
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 // user include files
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 // class decleration
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 // constants, enums and typedefs
0089 //
0090 
0091 //
0092 // static data member definitions
0093 //
0094 
0095 //
0096 // constructors and destructor
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   // Version V02-03-02 and earlier of this module had support for   //
0113   // "cfg" as an input/output format.  It turns out that reading    //
0114   // thousands of parameters from a configuration file takes a very //
0115   // long time, so "cfg" wasn't very practical.  When I reorganized //
0116   // the code, I didn't bother to port it.                          //
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 // ------------ method called to for each event  ------------
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   }  // end if not done
0221   else {
0222     throw cms::Exception("BadConfig") << "Set maxEvents.input to 1.  (Your output is okay.)" << std::endl;
0223   }
0224 }
0225 
0226 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
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 //define this as a plug-in
0271 DEFINE_FWK_MODULE(MuonGeometryDBConverter);