EcalTBHodoscopeGeometryAnalyzer

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
// -*- C++ -*-
//
// Package:    EcalTBHodoscopeGeometryAnalyzer
// Class:      EcalTBHodoscopeGeometryAnalyzer
//
/**\class EcalTBHodoscopeGeometryAnalyzer EcalTBHodoscopeGeometryAnalyzer.cc test/EcalTBHodoscopeGeometryAnalyzer/src/EcalTBHodoscopeGeometryAnalyzer.cc

 Description: <one line class summary>

 Implementation:
     <Notes on implementation>
*/
//

// system include files
#include <memory>
#include <cmath>

// user include files
#include "FWCore/Framework/interface/one/EDAnalyzer.h"

#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Utilities/interface/ESGetToken.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
#include "Geometry/CaloGeometry/interface/CaloGeometry.h"
#include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
#include "Geometry/Records/interface/CaloGeometryRecord.h"
#include "SimDataFormats/EcalTestBeam/interface/HodoscopeDetId.h"

#include <CLHEP/Vector/ThreeVector.h>
#include <CLHEP/Vector/Rotation.h>
#include <CLHEP/Units/SystemOfUnits.h>

using CLHEP::deg;
//
// class decleration
//

class EcalTBHodoscopeGeometryAnalyzer : public edm::one::EDAnalyzer<> {
public:
  explicit EcalTBHodoscopeGeometryAnalyzer(const edm::ParameterSet&);
  ~EcalTBHodoscopeGeometryAnalyzer() override;

  void beginJob() override {}
  void analyze(edm::Event const& iEvent, edm::EventSetup const&) override;
  void endJob() override {}

private:
  void build(const CaloGeometry& cg, DetId::Detector det, int subdetn);

  CLHEP::HepRotation* fromCMStoTB(const double& myEta, const double& myPhi) const;

  int pass_;

  double eta_;
  double phi_;
  CLHEP::HepRotation* fromCMStoTB_;

  edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geometryToken_;
};

//
// constants, enums and typedefs
//

//
// static data member definitions
//

//
// constructors and destructor
//
EcalTBHodoscopeGeometryAnalyzer::EcalTBHodoscopeGeometryAnalyzer(const edm::ParameterSet& iConfig) {
  //now do what ever initialization is needed
  pass_ = 0;

  eta_ = iConfig.getUntrackedParameter<double>("eta", 0.971226);
  phi_ = iConfig.getUntrackedParameter<double>("phi", 0.115052);

  fromCMStoTB_ = fromCMStoTB(eta_, phi_);

  geometryToken_ = esConsumes<CaloGeometry, CaloGeometryRecord>(edm::ESInputTag{});
}

EcalTBHodoscopeGeometryAnalyzer::~EcalTBHodoscopeGeometryAnalyzer() {
  // do anything here that needs to be done at desctruction time
  // (e.g. close files, deallocate resources etc.)
  delete fromCMStoTB_;
}

void EcalTBHodoscopeGeometryAnalyzer::build(const CaloGeometry& cg, DetId::Detector det, int subdetn) {
  const CaloSubdetectorGeometry* geom(cg.getSubdetectorGeometry(det, subdetn));

  const std::vector<DetId>& ids = geom->getValidDetIds(det, subdetn);
  for (auto id : ids) {
    auto cell = geom->getGeometry(id);
    if (det == DetId::Ecal) {
      if (subdetn == EcalLaserPnDiode) {
        CLHEP::Hep3Vector thisCellPos(cell->getPosition().x(), cell->getPosition().y(), cell->getPosition().z());
        CLHEP::Hep3Vector rotCellPos = (*fromCMStoTB_) * thisCellPos;

        edm::LogInfo("EcalTBGeom") << "Fiber DetId = " << HodoscopeDetId(id) << " position =  " << rotCellPos;
      }
    }
  }
}
//
// member functions
//

// ------------ method called to produce the data  ------------
void EcalTBHodoscopeGeometryAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
  edm::LogVerbatim("EcalGeom") << "Here I am ";

  auto const& pG = iSetup.getData(geometryToken_);
  //
  // get the ecal & hcal geometry
  //

  if (pass_ == 0) {
    build(pG, DetId::Ecal, EcalLaserPnDiode);
  }

  pass_++;
}

CLHEP::HepRotation* EcalTBHodoscopeGeometryAnalyzer::fromCMStoTB(const double& myEta, const double& myPhi) const {
  double myTheta = 2.0 * atan(exp(-myEta));

  // rotation matrix to move from the CMS reference frame to the test beam one

  CLHEP::HepRotation* CMStoTB = new CLHEP::HepRotation();

  double angle1 = 90. * deg - myPhi;
  CLHEP::HepRotationZ* r1 = new CLHEP::HepRotationZ(angle1);
  double angle2 = myTheta;
  CLHEP::HepRotationX* r2 = new CLHEP::HepRotationX(angle2);
  double angle3 = 90. * deg;
  CLHEP::HepRotationZ* r3 = new CLHEP::HepRotationZ(angle3);
  (*CMStoTB) *= (*r3);
  (*CMStoTB) *= (*r2);
  (*CMStoTB) *= (*r1);

  return CMStoTB;
}

//define this as a plug-in

DEFINE_FWK_MODULE(EcalTBHodoscopeGeometryAnalyzer);