Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-22 06:26:39

0001 
0002 #include <string>
0003 #include <map>
0004 #include <vector>
0005 
0006 // Framework
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "FWCore/ServiceRegistry/interface/Service.h"
0009 #include "FWCore/Framework/interface/EventSetup.h"
0010 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0011 #include "FWCore/Framework/interface/MakerMacros.h"
0012 #include "DataFormats/DetId/interface/DetId.h"
0013 
0014 // Database
0015 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0016 
0017 // Alignment
0018 #include "Alignment/CommonAlignment/interface/Utilities.h"
0019 #include "CondFormats/Alignment/interface/Alignments.h"
0020 #include "CondFormats/Alignment/interface/AlignTransform.h"
0021 #include "CondFormats/AlignmentRecord/interface/GlobalPositionRcd.h"
0022 
0023 class GlobalPositionRcdWrite : public edm::one::EDAnalyzer<> {
0024 public:
0025   explicit GlobalPositionRcdWrite(const edm::ParameterSet& iConfig)
0026       : m_useEulerAngles(iConfig.getParameter<bool>("useEulerAngles")),
0027         m_tracker(iConfig.getParameter<edm::ParameterSet>("tracker")),
0028         m_muon(iConfig.getParameter<edm::ParameterSet>("muon")),
0029         m_ecal(iConfig.getParameter<edm::ParameterSet>("ecal")),
0030         m_hcal(iConfig.getParameter<edm::ParameterSet>("hcal")),
0031         m_calo(iConfig.getParameter<edm::ParameterSet>("calo")),
0032         nEventCalls_(0){};
0033   ~GlobalPositionRcdWrite() {}
0034   virtual void analyze(const edm::Event& evt, const edm::EventSetup& evtSetup);
0035 
0036 private:
0037   AlignTransform::Rotation toMatrix(double alpha, double beta, double gamma);
0038 
0039   bool m_useEulerAngles;
0040   edm::ParameterSet m_tracker, m_muon, m_ecal, m_hcal, m_calo;
0041   unsigned int nEventCalls_;
0042 };
0043 
0044 AlignTransform::Rotation GlobalPositionRcdWrite::toMatrix(double alpha, double beta, double gamma) {
0045   align::EulerAngles angles(3);
0046   angles(1) = alpha;
0047   angles(2) = beta;
0048   angles(3) = gamma;
0049 
0050   align::RotationType alignRotation = align::toMatrix(angles);
0051 
0052   return AlignTransform::Rotation(CLHEP::HepRep3x3(alignRotation.xx(),
0053                                                    alignRotation.xy(),
0054                                                    alignRotation.xz(),
0055                                                    alignRotation.yx(),
0056                                                    alignRotation.yy(),
0057                                                    alignRotation.yz(),
0058                                                    alignRotation.zx(),
0059                                                    alignRotation.zy(),
0060                                                    alignRotation.zz()));
0061 }
0062 
0063 void GlobalPositionRcdWrite::analyze(const edm::Event& evt, const edm::EventSetup& iSetup) {
0064   if (nEventCalls_ > 0) {
0065     edm::LogPrint("GlobalPositionRcdWrite") << "Writing to DB to be done only once, "
0066                                             << "set 'untracked PSet maxEvents = {untracked int32 input = 1}'."
0067                                             << "(Your writing should be fine.)" << std::endl;
0068     return;
0069   }
0070 
0071   Alignments globalPositions{};
0072 
0073   AlignTransform tracker(AlignTransform::Translation(m_tracker.getParameter<double>("x"),
0074                                                      m_tracker.getParameter<double>("y"),
0075                                                      m_tracker.getParameter<double>("z")),
0076                          (m_useEulerAngles != true)
0077                              ? this->toMatrix(m_tracker.getParameter<double>("alpha"),
0078                                               m_tracker.getParameter<double>("beta"),
0079                                               m_tracker.getParameter<double>("gamma"))
0080                              : AlignTransform::EulerAngles(m_tracker.getParameter<double>("alpha"),
0081                                                            m_tracker.getParameter<double>("beta"),
0082                                                            m_tracker.getParameter<double>("gamma")),
0083                          DetId(DetId::Tracker).rawId());
0084 
0085   AlignTransform muon(
0086       AlignTransform::Translation(
0087           m_muon.getParameter<double>("x"), m_muon.getParameter<double>("y"), m_muon.getParameter<double>("z")),
0088       (m_useEulerAngles != true) ? this->toMatrix(m_muon.getParameter<double>("alpha"),
0089                                                   m_muon.getParameter<double>("beta"),
0090                                                   m_muon.getParameter<double>("gamma"))
0091                                  : AlignTransform::EulerAngles(m_muon.getParameter<double>("alpha"),
0092                                                                m_muon.getParameter<double>("beta"),
0093                                                                m_muon.getParameter<double>("gamma")),
0094       DetId(DetId::Muon).rawId());
0095 
0096   AlignTransform ecal(
0097       AlignTransform::Translation(
0098           m_ecal.getParameter<double>("x"), m_ecal.getParameter<double>("y"), m_ecal.getParameter<double>("z")),
0099       (m_useEulerAngles != true) ? this->toMatrix(m_ecal.getParameter<double>("alpha"),
0100                                                   m_ecal.getParameter<double>("beta"),
0101                                                   m_ecal.getParameter<double>("gamma"))
0102                                  : AlignTransform::EulerAngles(m_ecal.getParameter<double>("alpha"),
0103                                                                m_ecal.getParameter<double>("beta"),
0104                                                                m_ecal.getParameter<double>("gamma")),
0105       DetId(DetId::Ecal).rawId());
0106 
0107   AlignTransform hcal(
0108       AlignTransform::Translation(
0109           m_hcal.getParameter<double>("x"), m_hcal.getParameter<double>("y"), m_hcal.getParameter<double>("z")),
0110       (m_useEulerAngles != true) ? this->toMatrix(m_hcal.getParameter<double>("alpha"),
0111                                                   m_hcal.getParameter<double>("beta"),
0112                                                   m_hcal.getParameter<double>("gamma"))
0113                                  : AlignTransform::EulerAngles(m_hcal.getParameter<double>("alpha"),
0114                                                                m_hcal.getParameter<double>("beta"),
0115                                                                m_hcal.getParameter<double>("gamma")),
0116       DetId(DetId::Hcal).rawId());
0117 
0118   AlignTransform calo(
0119       AlignTransform::Translation(
0120           m_calo.getParameter<double>("x"), m_calo.getParameter<double>("y"), m_calo.getParameter<double>("z")),
0121       (m_useEulerAngles != true) ? this->toMatrix(m_calo.getParameter<double>("alpha"),
0122                                                   m_calo.getParameter<double>("beta"),
0123                                                   m_calo.getParameter<double>("gamma"))
0124                                  : AlignTransform::EulerAngles(m_calo.getParameter<double>("alpha"),
0125                                                                m_calo.getParameter<double>("beta"),
0126                                                                m_calo.getParameter<double>("gamma")),
0127       DetId(DetId::Calo).rawId());
0128 
0129   edm::LogPrint("GlobalPositionRcdWrite")
0130       << "\nProvided rotation angles are interpreted as "
0131       << ((m_useEulerAngles != true) ? "rotations around X, Y and Z" : "Euler angles") << ".\n"
0132       << std::endl;
0133 
0134   edm::LogPrint("GlobalPositionRcdWrite") << "Tracker (" << tracker.rawId() << ") at " << tracker.translation() << " "
0135                                           << tracker.rotation().eulerAngles() << std::endl;
0136   edm::LogPrint("GlobalPositionRcdWrite") << tracker.rotation() << std::endl;
0137 
0138   edm::LogPrint("GlobalPositionRcdWrite")
0139       << "Muon (" << muon.rawId() << ") at " << muon.translation() << " " << muon.rotation().eulerAngles() << std::endl;
0140   edm::LogPrint("GlobalPositionRcdWrite") << muon.rotation() << std::endl;
0141 
0142   edm::LogPrint("GlobalPositionRcdWrite")
0143       << "Ecal (" << ecal.rawId() << ") at " << ecal.translation() << " " << ecal.rotation().eulerAngles() << std::endl;
0144   edm::LogPrint("GlobalPositionRcdWrite") << ecal.rotation() << std::endl;
0145 
0146   edm::LogPrint("GlobalPositionRcdWrite")
0147       << "Hcal (" << hcal.rawId() << ") at " << hcal.translation() << " " << hcal.rotation().eulerAngles() << std::endl;
0148   edm::LogPrint("GlobalPositionRcdWrite") << hcal.rotation() << std::endl;
0149 
0150   edm::LogPrint("GlobalPositionRcdWrite")
0151       << "Calo (" << calo.rawId() << ") at " << calo.translation() << " " << calo.rotation().eulerAngles() << std::endl;
0152   edm::LogPrint("GlobalPositionRcdWrite") << calo.rotation() << std::endl;
0153 
0154   globalPositions.m_align.push_back(tracker);
0155   globalPositions.m_align.push_back(muon);
0156   globalPositions.m_align.push_back(ecal);
0157   globalPositions.m_align.push_back(hcal);
0158   globalPositions.m_align.push_back(calo);
0159 
0160   edm::LogPrint("GlobalPositionRcdWrite") << "Uploading to the database..." << std::endl;
0161 
0162   edm::Service<cond::service::PoolDBOutputService> poolDbService;
0163 
0164   if (!poolDbService.isAvailable())
0165     throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
0166 
0167   //    if (poolDbService->isNewTagRequest("GlobalPositionRcd")) {
0168   //       poolDbService->createOneIOV<Alignments>(globalPositions, poolDbService->endOfTime(), "GlobalPositionRcd");
0169   //    } else {
0170   //       poolDbService->appendOneIOV<Alignments>(globalPositions, poolDbService->currentTime(), "GlobalPositionRcd");
0171   //    }
0172   poolDbService->writeOneIOV<Alignments>(globalPositions, poolDbService->currentTime(), "GlobalPositionRcd");
0173   edm::LogPrint("GlobalPositionRcdWrite") << "done!" << std::endl;
0174   nEventCalls_++;
0175 }
0176 
0177 //define this as a plug-in
0178 DEFINE_FWK_MODULE(GlobalPositionRcdWrite);