Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:08:05

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   int n = 0;
0098   const std::vector<DetId>& ids = geom->getValidDetIds(det, subdetn);
0099   for (auto id : ids) {
0100     n++;
0101     auto cell = geom->getGeometry(id);
0102     if (det == DetId::Ecal) {
0103       if (subdetn == EcalLaserPnDiode) {
0104         CLHEP::Hep3Vector thisCellPos(cell->getPosition().x(), cell->getPosition().y(), cell->getPosition().z());
0105         CLHEP::Hep3Vector rotCellPos = (*fromCMStoTB_) * thisCellPos;
0106 
0107         edm::LogInfo("EcalTBGeom") << "Fiber DetId = " << HodoscopeDetId(id) << " position =  " << rotCellPos;
0108       }
0109     }
0110   }
0111 }
0112 //
0113 // member functions
0114 //
0115 
0116 // ------------ method called to produce the data  ------------
0117 void EcalTBHodoscopeGeometryAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0118   std::cout << "Here I am " << std::endl;
0119 
0120   auto const& pG = iSetup.getData(geometryToken_);
0121   //
0122   // get the ecal & hcal geometry
0123   //
0124 
0125   if (pass_ == 0) {
0126     build(pG, DetId::Ecal, EcalLaserPnDiode);
0127   }
0128 
0129   pass_++;
0130 }
0131 
0132 CLHEP::HepRotation* EcalTBHodoscopeGeometryAnalyzer::fromCMStoTB(const double& myEta, const double& myPhi) const {
0133   double myTheta = 2.0 * atan(exp(-myEta));
0134 
0135   // rotation matrix to move from the CMS reference frame to the test beam one
0136 
0137   CLHEP::HepRotation* CMStoTB = new CLHEP::HepRotation();
0138 
0139   double angle1 = 90. * deg - myPhi;
0140   CLHEP::HepRotationZ* r1 = new CLHEP::HepRotationZ(angle1);
0141   double angle2 = myTheta;
0142   CLHEP::HepRotationX* r2 = new CLHEP::HepRotationX(angle2);
0143   double angle3 = 90. * deg;
0144   CLHEP::HepRotationZ* r3 = new CLHEP::HepRotationZ(angle3);
0145   (*CMStoTB) *= (*r3);
0146   (*CMStoTB) *= (*r2);
0147   (*CMStoTB) *= (*r1);
0148 
0149   return CMStoTB;
0150 }
0151 
0152 //define this as a plug-in
0153 
0154 DEFINE_FWK_MODULE(EcalTBHodoscopeGeometryAnalyzer);