File indexing completed on 2024-05-10 02:20:49
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include <memory>
0017 #include <cmath>
0018
0019
0020 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0021
0022 #include "FWCore/Framework/interface/EventSetup.h"
0023 #include "FWCore/Framework/interface/MakerMacros.h"
0024 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0025 #include "FWCore/Utilities/interface/ESGetToken.h"
0026
0027 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0028 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
0029 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0030 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
0031 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0032 #include "SimDataFormats/EcalTestBeam/interface/HodoscopeDetId.h"
0033
0034 #include <CLHEP/Vector/ThreeVector.h>
0035 #include <CLHEP/Vector/Rotation.h>
0036 #include <CLHEP/Units/SystemOfUnits.h>
0037
0038 using CLHEP::deg;
0039
0040
0041
0042
0043 class EcalTBHodoscopeGeometryAnalyzer : public edm::one::EDAnalyzer<> {
0044 public:
0045 explicit EcalTBHodoscopeGeometryAnalyzer(const edm::ParameterSet&);
0046 ~EcalTBHodoscopeGeometryAnalyzer() override;
0047
0048 void beginJob() override {}
0049 void analyze(edm::Event const& iEvent, edm::EventSetup const&) override;
0050 void endJob() override {}
0051
0052 private:
0053 void build(const CaloGeometry& cg, DetId::Detector det, int subdetn);
0054
0055 CLHEP::HepRotation* fromCMStoTB(const double& myEta, const double& myPhi) const;
0056
0057 int pass_;
0058
0059 double eta_;
0060 double phi_;
0061 CLHEP::HepRotation* fromCMStoTB_;
0062
0063 edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geometryToken_;
0064 };
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077 EcalTBHodoscopeGeometryAnalyzer::EcalTBHodoscopeGeometryAnalyzer(const edm::ParameterSet& iConfig) {
0078
0079 pass_ = 0;
0080
0081 eta_ = iConfig.getUntrackedParameter<double>("eta", 0.971226);
0082 phi_ = iConfig.getUntrackedParameter<double>("phi", 0.115052);
0083
0084 fromCMStoTB_ = fromCMStoTB(eta_, phi_);
0085
0086 geometryToken_ = esConsumes<CaloGeometry, CaloGeometryRecord>(edm::ESInputTag{});
0087 }
0088
0089 EcalTBHodoscopeGeometryAnalyzer::~EcalTBHodoscopeGeometryAnalyzer() {
0090
0091
0092 delete fromCMStoTB_;
0093 }
0094
0095 void EcalTBHodoscopeGeometryAnalyzer::build(const CaloGeometry& cg, DetId::Detector det, int subdetn) {
0096 const CaloSubdetectorGeometry* geom(cg.getSubdetectorGeometry(det, subdetn));
0097
0098 const std::vector<DetId>& ids = geom->getValidDetIds(det, subdetn);
0099 for (auto id : ids) {
0100 auto cell = geom->getGeometry(id);
0101 if (det == DetId::Ecal) {
0102 if (subdetn == EcalLaserPnDiode) {
0103 CLHEP::Hep3Vector thisCellPos(cell->getPosition().x(), cell->getPosition().y(), cell->getPosition().z());
0104 CLHEP::Hep3Vector rotCellPos = (*fromCMStoTB_) * thisCellPos;
0105
0106 edm::LogInfo("EcalTBGeom") << "Fiber DetId = " << HodoscopeDetId(id) << " position = " << rotCellPos;
0107 }
0108 }
0109 }
0110 }
0111
0112
0113
0114
0115
0116 void EcalTBHodoscopeGeometryAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0117 edm::LogVerbatim("EcalGeom") << "Here I am ";
0118
0119 auto const& pG = iSetup.getData(geometryToken_);
0120
0121
0122
0123
0124 if (pass_ == 0) {
0125 build(pG, DetId::Ecal, EcalLaserPnDiode);
0126 }
0127
0128 pass_++;
0129 }
0130
0131 CLHEP::HepRotation* EcalTBHodoscopeGeometryAnalyzer::fromCMStoTB(const double& myEta, const double& myPhi) const {
0132 double myTheta = 2.0 * atan(exp(-myEta));
0133
0134
0135
0136 CLHEP::HepRotation* CMStoTB = new CLHEP::HepRotation();
0137
0138 double angle1 = 90. * deg - myPhi;
0139 CLHEP::HepRotationZ* r1 = new CLHEP::HepRotationZ(angle1);
0140 double angle2 = myTheta;
0141 CLHEP::HepRotationX* r2 = new CLHEP::HepRotationX(angle2);
0142 double angle3 = 90. * deg;
0143 CLHEP::HepRotationZ* r3 = new CLHEP::HepRotationZ(angle3);
0144 (*CMStoTB) *= (*r3);
0145 (*CMStoTB) *= (*r2);
0146 (*CMStoTB) *= (*r1);
0147
0148 return CMStoTB;
0149 }
0150
0151
0152
0153 DEFINE_FWK_MODULE(EcalTBHodoscopeGeometryAnalyzer);