Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:56:17

0001 #include <string>
0002 #include <map>
0003 #include <vector>
0004 
0005 #include "FWCore/Framework/interface/Event.h"
0006 #include "FWCore/Framework/interface/EventSetup.h"
0007 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0008 #include "FWCore/Framework/interface/MakerMacros.h"
0009 #include "FWCore/Framework/interface/ESHandle.h"
0010 #include "CondFormats/Alignment/interface/Alignments.h"
0011 #include "CondFormats/Alignment/interface/AlignTransform.h"
0012 #include "CondFormats/AlignmentRecord/interface/GlobalPositionRcd.h"
0013 #include "DataFormats/DetId/interface/DetId.h"
0014 
0015 #include "FWCore/Framework/interface/ESWatcher.h"
0016 
0017 #include "Alignment/CommonAlignment/interface/Utilities.h"
0018 
0019 class GlobalPositionRcdScan : public edm::one::EDAnalyzer<> {
0020 public:
0021   explicit GlobalPositionRcdScan(const edm::ParameterSet& iConfig);
0022 
0023   virtual ~GlobalPositionRcdScan() = default;
0024   virtual void analyze(const edm::Event& evt, const edm::EventSetup& evtSetup);
0025   virtual void endJob();
0026 
0027 private:
0028   edm::ESWatcher<GlobalPositionRcd> watcher_;
0029   const edm::ESGetToken<Alignments, GlobalPositionRcd> GPRToken_;
0030 
0031   bool eulerAngles_;
0032   bool alignAngles_;
0033   bool matrix_;
0034   edm::RunNumber_t firstRun_;
0035   edm::RunNumber_t lastRun_;
0036 };
0037 
0038 GlobalPositionRcdScan::GlobalPositionRcdScan(const edm::ParameterSet& iConfig)
0039     : GPRToken_(esConsumes()), eulerAngles_(false), alignAngles_(false), matrix_(false), firstRun_(0), lastRun_(0) {
0040   const std::string howRot(iConfig.getParameter<std::string>("rotation"));
0041 
0042   if (howRot == "euler" || howRot == "all")
0043     eulerAngles_ = true;
0044   if (howRot == "align" || howRot == "all")
0045     alignAngles_ = true;
0046   if (howRot == "matrix" || howRot == "all")
0047     matrix_ = true;
0048 
0049   if (!eulerAngles_ && !alignAngles_ && !matrix_) {
0050     edm::LogError("BadConfig") << "@SUB=GlobalPositionRcdScan"
0051                                << "Parameter 'rotation' should be 'euler', 'align',"
0052                                << "'matrix' or 'all', but is '" << howRot << "'. Treat as 'all'.";
0053     eulerAngles_ = alignAngles_ = matrix_ = true;
0054   }
0055 }
0056 
0057 void GlobalPositionRcdScan::analyze(const edm::Event& evt, const edm::EventSetup& evtSetup) {
0058   lastRun_ = evt.run();
0059   if (0 == firstRun_)
0060     firstRun_ = lastRun_;
0061 
0062   if (watcher_.check(evtSetup)) {
0063     const Alignments* globalPositionRcd = &evtSetup.getData(GPRToken_);
0064 
0065     edm::LogPrint("GlobalPositionRcdScan")
0066         << "=====================================================\n"
0067         << "GlobalPositionRcd content starting from run " << evt.run() << ":" << std::endl;
0068 
0069     for (std::vector<AlignTransform>::const_iterator i = globalPositionRcd->m_align.begin();
0070          i != globalPositionRcd->m_align.end();
0071          ++i) {
0072       edm::LogPrint("GlobalPositionRcdScan") << "  Component ";
0073       if (i->rawId() == DetId(DetId::Tracker).rawId()) {
0074         edm::LogPrint("GlobalPositionRcdScan") << "Tracker";
0075       } else if (i->rawId() == DetId(DetId::Muon).rawId()) {
0076         edm::LogPrint("GlobalPositionRcdScan") << "Muon   ";
0077       } else if (i->rawId() == DetId(DetId::Ecal).rawId()) {
0078         edm::LogPrint("GlobalPositionRcdScan") << "Ecal   ";
0079       } else if (i->rawId() == DetId(DetId::Hcal).rawId()) {
0080         edm::LogPrint("GlobalPositionRcdScan") << "Hcal   ";
0081       } else if (i->rawId() == DetId(DetId::Calo).rawId()) {
0082         edm::LogPrint("GlobalPositionRcdScan") << "Calo   ";
0083       } else {
0084         edm::LogPrint("GlobalPositionRcdScan") << "Unknown";
0085       }
0086       edm::LogPrint("GlobalPositionRcdScan")
0087           << " entry " << i->rawId() << "\n     translation " << i->translation() << "\n";
0088       const AlignTransform::Rotation hepRot(i->rotation());
0089       if (eulerAngles_) {
0090         edm::LogPrint("GlobalPositionRcdScan") << "     euler angles " << hepRot.eulerAngles() << std::endl;
0091       }
0092       if (alignAngles_) {
0093         const align::RotationType matrix(hepRot.xx(),
0094                                          hepRot.xy(),
0095                                          hepRot.xz(),
0096                                          hepRot.yx(),
0097                                          hepRot.yy(),
0098                                          hepRot.yz(),
0099                                          hepRot.zx(),
0100                                          hepRot.zy(),
0101                                          hepRot.zz());
0102         const AlgebraicVector angles(align::toAngles(matrix));
0103         edm::LogPrint("GlobalPositionRcdScan")
0104             << "     alpha, beta, gamma (" << angles[0] << ", " << angles[1] << ", " << angles[2] << ')' << std::endl;
0105       }
0106       if (matrix_) {
0107         edm::LogPrint("GlobalPositionRcdScan") << "     rotation matrix " << hepRot << std::endl;
0108       }
0109     }
0110   }
0111 }
0112 
0113 void GlobalPositionRcdScan::endJob() {
0114   edm::LogPrint("GlobalPositionRcdScan") << "\n=====================================================\n"
0115                                          << "=====================================================\n"
0116                                          << "Checked run range " << firstRun_ << " to " << lastRun_ << "." << std::endl;
0117 }
0118 
0119 //define this as a plug-in
0120 DEFINE_FWK_MODULE(GlobalPositionRcdScan);