Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:31

0001 /****************************************************************************
0002  *
0003  * Authors:
0004  *  Jan Kašpar (jan.kaspar@gmail.com)
0005  *
0006  ****************************************************************************/
0007 
0008 #include "FWCore/Framework/interface/MakerMacros.h"
0009 #include "FWCore/Utilities/interface/Exception.h"
0010 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0011 #include "FWCore/Framework/interface/Event.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/Framework/interface/EventSetup.h"
0014 #include "FWCore/Framework/interface/ESWatcher.h"
0015 
0016 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0017 #include "Geometry/Records/interface/VeryForwardRealGeometryRecord.h"
0018 #include "Geometry/Records/interface/VeryForwardMisalignedGeometryRecord.h"
0019 #include "Geometry/VeryForwardGeometryBuilder/interface/CTPPSGeometry.h"
0020 
0021 #include "DataFormats/CTPPSDetId/interface/CTPPSDetId.h"
0022 #include "DataFormats/CTPPSDetId/interface/TotemRPDetId.h"
0023 #include "DataFormats/CTPPSDetId/interface/TotemTimingDetId.h"
0024 #include "DataFormats/CTPPSDetId/interface/CTPPSPixelDetId.h"
0025 #include "DataFormats/CTPPSDetId/interface/CTPPSDiamondDetId.h"
0026 
0027 #include <iostream>
0028 #include <iomanip>
0029 
0030 //----------------------------------------------------------------------------------------------------
0031 
0032 /**
0033  * \brief Class to print out information on current geometry.
0034  **/
0035 class CTPPSGeometryInfo : public edm::one::EDAnalyzer<> {
0036 public:
0037   explicit CTPPSGeometryInfo(const edm::ParameterSet&);
0038 
0039 private:
0040   const std::string geometryType_;
0041   const bool printRPInfo_, printSensorInfo_;
0042   const edm::ESGetToken<CTPPSGeometry, IdealGeometryRecord> tokIdeal_;
0043   const edm::ESGetToken<CTPPSGeometry, VeryForwardRealGeometryRecord> tokReal_;
0044   const edm::ESGetToken<CTPPSGeometry, VeryForwardMisalignedGeometryRecord> tokMis_;
0045 
0046   edm::ESWatcher<IdealGeometryRecord> watcherIdealGeometry_;
0047   edm::ESWatcher<VeryForwardRealGeometryRecord> watcherRealGeometry_;
0048   edm::ESWatcher<VeryForwardMisalignedGeometryRecord> watcherMisalignedGeometry_;
0049 
0050   void analyze(const edm::Event&, const edm::EventSetup&) override;
0051 
0052   static std::string formatDetId(const CTPPSDetId& id, bool printDetails = true);
0053 
0054   void printGeometry(const CTPPSGeometry&, const edm::Event&);
0055 };
0056 
0057 //----------------------------------------------------------------------------------------------------
0058 
0059 CTPPSGeometryInfo::CTPPSGeometryInfo(const edm::ParameterSet& iConfig)
0060     : geometryType_(iConfig.getUntrackedParameter<std::string>("geometryType", "real")),
0061       printRPInfo_(iConfig.getUntrackedParameter<bool>("printRPInfo", true)),
0062       printSensorInfo_(iConfig.getUntrackedParameter<bool>("printSensorInfo", true)),
0063       tokIdeal_(esConsumes<CTPPSGeometry, IdealGeometryRecord>()),
0064       tokReal_(esConsumes<CTPPSGeometry, VeryForwardRealGeometryRecord>()),
0065       tokMis_(esConsumes<CTPPSGeometry, VeryForwardMisalignedGeometryRecord>()) {}
0066 
0067 //----------------------------------------------------------------------------------------------------
0068 
0069 void CTPPSGeometryInfo::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0070   if (geometryType_ == "ideal") {
0071     if (watcherIdealGeometry_.check(iSetup)) {
0072       const auto& geometry = iSetup.getData(tokIdeal_);
0073       printGeometry(geometry, iEvent);
0074     }
0075     return;
0076   }
0077 
0078   else if (geometryType_ == "real") {
0079     if (watcherRealGeometry_.check(iSetup)) {
0080       const auto& geometry = iSetup.getData(tokReal_);
0081       printGeometry(geometry, iEvent);
0082     }
0083     return;
0084   }
0085 
0086   else if (geometryType_ == "misaligned") {
0087     if (watcherMisalignedGeometry_.check(iSetup)) {
0088       const auto& geometry = iSetup.getData(tokMis_);
0089       printGeometry(geometry, iEvent);
0090     }
0091     return;
0092   }
0093 
0094   throw cms::Exception("CTPPSGeometryInfo") << "Unknown geometry type: `" << geometryType_ << "'.";
0095 }
0096 
0097 //----------------------------------------------------------------------------------------------------
0098 
0099 std::string CTPPSGeometryInfo::formatDetId(const CTPPSDetId& id, bool printDetails) {
0100   std::ostringstream oss;
0101   oss << id.rawId();
0102 
0103   const unsigned int rpDecId = id.arm() * 100 + id.station() * 10 + id.rp();
0104 
0105   if (id.subdetId() == CTPPSDetId::sdTrackingStrip) {
0106     TotemRPDetId fid(id);
0107     oss << " (strip RP " << std::setw(3) << rpDecId;
0108     if (printDetails)
0109       oss << ", plane " << fid.plane();
0110     oss << ")";
0111   }
0112 
0113   else if (id.subdetId() == CTPPSDetId::sdTrackingPixel) {
0114     CTPPSPixelDetId fid(id);
0115     oss << " (pixel RP " << std::setw(3) << rpDecId;
0116     if (printDetails)
0117       oss << ", plane " << fid.plane();
0118     oss << ")";
0119   }
0120 
0121   else if (id.subdetId() == CTPPSDetId::sdTimingDiamond) {
0122     CTPPSDiamondDetId fid(id);
0123     oss << " (diamd RP " << std::setw(3) << rpDecId;
0124     if (printDetails)
0125       oss << ", plane " << fid.plane() << ", channel " << std::setw(2) << fid.channel();
0126     oss << ")";
0127   }
0128 
0129   else if (id.subdetId() == CTPPSDetId::sdTimingFastSilicon) {
0130     TotemTimingDetId fid(id);
0131     oss << " (totim RP " << std::setw(3) << rpDecId;
0132     if (printDetails)
0133       oss << ", plane " << fid.plane() << ", channel " << std::setw(2) << fid.channel();
0134     oss << ")";
0135   }
0136 
0137   return oss.str();
0138 }
0139 
0140 //----------------------------------------------------------------------------------------------------
0141 
0142 void CTPPSGeometryInfo::printGeometry(const CTPPSGeometry& geometry, const edm::Event& event) {
0143   time_t unixTime = event.time().unixTime();
0144   char timeStr[50];
0145   strftime(timeStr, 50, "%F %T", localtime(&unixTime));
0146 
0147   std::ostringstream oss;
0148 
0149   // RP geometry
0150   if (printRPInfo_) {
0151     oss << "* RPs:\n"
0152         << "    ce: RP center in global coordinates, in mm\n";
0153 
0154     for (auto it = geometry.beginRP(); it != geometry.endRP(); ++it) {
0155       const DetGeomDesc::Translation& t = it->second->translation();
0156 
0157       oss << formatDetId(CTPPSDetId(it->first), false) << std::fixed << std::setprecision(3) << std::showpos
0158           << " | ce=(" << t.x() << ", " << t.y() << ", " << t.z() << ")\n";
0159     }
0160 
0161     edm::LogVerbatim("CTPPSGeometryInfo") << oss.str();
0162   }
0163 
0164   // sensor geometry
0165   if (printSensorInfo_) {
0166     oss << "* sensors:\n"
0167         << "    ce: sensor center in global coordinates, in mm\n"
0168         << "    a1: local axis (1, 0, 0) in global coordinates\n"
0169         << "    a2: local axis (0, 1, 0) in global coordinates\n"
0170         << "    a3: local axis (0, 0, 1) in global coordinates\n";
0171 
0172     for (auto it = geometry.beginSensor(); it != geometry.endSensor(); ++it) {
0173       CTPPSDetId detId(it->first);
0174 
0175       const auto gl_o = geometry.localToGlobal(detId, CTPPSGeometry::Vector(0, 0, 0));
0176       const auto gl_a1 = geometry.localToGlobal(detId, CTPPSGeometry::Vector(1, 0, 0)) - gl_o;
0177       const auto gl_a2 = geometry.localToGlobal(detId, CTPPSGeometry::Vector(0, 1, 0)) - gl_o;
0178       const auto gl_a3 = geometry.localToGlobal(detId, CTPPSGeometry::Vector(0, 0, 1)) - gl_o;
0179 
0180       oss << formatDetId(detId) << std::fixed << std::setprecision(3) << std::showpos << " | ce=(" << gl_o.x() << ", "
0181           << gl_o.y() << ", " << gl_o.z() << ")"
0182           << " | a1=(" << gl_a1.x() << ", " << gl_a1.y() << ", " << gl_a1.z() << ")"
0183           << " | a2=(" << gl_a2.x() << ", " << gl_a2.y() << ", " << gl_a2.z() << ")"
0184           << " | a3=(" << gl_a3.x() << ", " << gl_a3.y() << ", " << gl_a3.z() << ")\n";
0185     }
0186   }
0187 
0188   edm::LogInfo("CTPPSGeometryInfo") << "New " << geometryType_ << " geometry found in run=" << event.id().run()
0189                                     << ", event=" << event.id().event() << ", UNIX timestamp=" << unixTime << " ("
0190                                     << timeStr << ")\n"
0191                                     << oss.str();
0192 }
0193 
0194 //----------------------------------------------------------------------------------------------------
0195 
0196 DEFINE_FWK_MODULE(CTPPSGeometryInfo);