Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-05-08 23:18:54

0001 // -*- C++ -*-
0002 //
0003 // Package:    EcalTBHodoscopeGeometryAnalyzer
0004 // Class:      EcalTBHodoscopeGeometryAnalyzer
0005 //
0006 /**\class EcalTBHodoscopeGeometryAnalyzer EcalTBHodoscopeGeometryAnalyzer.cc test/EcalTBHodoscopeGeometryAnalyzer/src/EcalTBHodoscopeGeometryAnalyzer.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 
0015 // system include files
0016 #include <memory>
0017 #include <cmath>
0018 
0019 // user include files
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/GlobalSystemOfUnits.h"
0037 
0038 //
0039 // class decleration
0040 //
0041 
0042 class EcalTBHodoscopeGeometryAnalyzer : public edm::one::EDAnalyzer<> {
0043 public:
0044   explicit EcalTBHodoscopeGeometryAnalyzer(const edm::ParameterSet&);
0045   ~EcalTBHodoscopeGeometryAnalyzer() override;
0046 
0047   void beginJob() override {}
0048   void analyze(edm::Event const& iEvent, edm::EventSetup const&) override;
0049   void endJob() override {}
0050 
0051 private:
0052   void build(const CaloGeometry& cg, DetId::Detector det, int subdetn);
0053 
0054   CLHEP::HepRotation* fromCMStoTB(const double& myEta, const double& myPhi) const;
0055 
0056   int pass_;
0057 
0058   double eta_;
0059   double phi_;
0060   CLHEP::HepRotation* fromCMStoTB_;
0061 
0062   edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geometryToken_;
0063 };
0064 
0065 //
0066 // constants, enums and typedefs
0067 //
0068 
0069 //
0070 // static data member definitions
0071 //
0072 
0073 //
0074 // constructors and destructor
0075 //
0076 EcalTBHodoscopeGeometryAnalyzer::EcalTBHodoscopeGeometryAnalyzer(const edm::ParameterSet& iConfig) {
0077   //now do what ever initialization is needed
0078   pass_ = 0;
0079 
0080   eta_ = iConfig.getUntrackedParameter<double>("eta", 0.971226);
0081   phi_ = iConfig.getUntrackedParameter<double>("phi", 0.115052);
0082 
0083   fromCMStoTB_ = fromCMStoTB(eta_, phi_);
0084 
0085   geometryToken_ = esConsumes<CaloGeometry, CaloGeometryRecord>(edm::ESInputTag{});
0086 }
0087 
0088 EcalTBHodoscopeGeometryAnalyzer::~EcalTBHodoscopeGeometryAnalyzer() {
0089   // do anything here that needs to be done at desctruction time
0090   // (e.g. close files, deallocate resources etc.)
0091   delete fromCMStoTB_;
0092 }
0093 
0094 void EcalTBHodoscopeGeometryAnalyzer::build(const CaloGeometry& cg, DetId::Detector det, int subdetn) {
0095   const CaloSubdetectorGeometry* geom(cg.getSubdetectorGeometry(det, subdetn));
0096 
0097   const std::vector<DetId>& ids = geom->getValidDetIds(det, subdetn);
0098   for (auto id : ids) {
0099     auto cell = geom->getGeometry(id);
0100     if (det == DetId::Ecal) {
0101       if (subdetn == EcalLaserPnDiode) {
0102         CLHEP::Hep3Vector thisCellPos(cell->getPosition().x(), cell->getPosition().y(), cell->getPosition().z());
0103         CLHEP::Hep3Vector rotCellPos = (*fromCMStoTB_) * thisCellPos;
0104 
0105         edm::LogInfo("EcalTBGeom") << "Fiber DetId = " << HodoscopeDetId(id) << " position =  " << rotCellPos;
0106       }
0107     }
0108   }
0109 }
0110 //
0111 // member functions
0112 //
0113 
0114 // ------------ method called to produce the data  ------------
0115 void EcalTBHodoscopeGeometryAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0116   edm::LogVerbatim("EcalGeom") << "Here I am ";
0117 
0118   auto const& pG = iSetup.getData(geometryToken_);
0119   //
0120   // get the ecal & hcal geometry
0121   //
0122 
0123   if (pass_ == 0) {
0124     build(pG, DetId::Ecal, EcalLaserPnDiode);
0125   }
0126 
0127   pass_++;
0128 }
0129 
0130 CLHEP::HepRotation* EcalTBHodoscopeGeometryAnalyzer::fromCMStoTB(const double& myEta, const double& myPhi) const {
0131   double myTheta = 2.0 * atan(exp(-myEta));
0132 
0133   // rotation matrix to move from the CMS reference frame to the test beam one
0134 
0135   CLHEP::HepRotation* CMStoTB = new CLHEP::HepRotation();
0136 
0137   double angle1 = 90. * deg - myPhi;
0138   CLHEP::HepRotationZ* r1 = new CLHEP::HepRotationZ(angle1);
0139   double angle2 = myTheta;
0140   CLHEP::HepRotationX* r2 = new CLHEP::HepRotationX(angle2);
0141   double angle3 = 90. * deg;
0142   CLHEP::HepRotationZ* r3 = new CLHEP::HepRotationZ(angle3);
0143   (*CMStoTB) *= (*r3);
0144   (*CMStoTB) *= (*r2);
0145   (*CMStoTB) *= (*r1);
0146 
0147   return CMStoTB;
0148 }
0149 
0150 //define this as a plug-in
0151 
0152 DEFINE_FWK_MODULE(EcalTBHodoscopeGeometryAnalyzer);