Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-14 11:45:28

0001 
0002 #include "RecoVertex/BeamSpotProducer/interface/BeamSpotProducer.h"
0003 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0004 
0005 #include "FWCore/Framework/interface/MakerMacros.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "FWCore/Framework/interface/ESHandle.h"
0008 #include "FWCore/Framework/interface/EventSetup.h"
0009 #include "FWCore/Framework/interface/IOVSyncValue.h"
0010 
0011 #include "DataFormats/Math/interface/Error.h"
0012 #include "DataFormats/Math/interface/Point3D.h"
0013 
0014 //
0015 // constructors and destructor
0016 //
0017 BeamSpotProducer::BeamSpotProducer(const edm::ParameterSet& iConf) {
0018   edm::LogInfo("RecoVertex/BeamSpotProducer") << "Initializing Beam Spot producer "
0019                                               << "\n";
0020 
0021   //fVerbose=conf.getUntrackedParameter<bool>("verbose", false);
0022   m_beamToken = esConsumes<BeamSpotObjects, BeamSpotObjectsRcd>();
0023 
0024   produces<reco::BeamSpot>();
0025 }
0026 
0027 BeamSpotProducer::~BeamSpotProducer() {}
0028 
0029 //
0030 // member functions
0031 //
0032 
0033 // ------------ method called to produce the data  ------------
0034 void BeamSpotProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0035   using namespace edm;
0036 
0037   auto result = std::make_unique<reco::BeamSpot>();
0038 
0039   reco::BeamSpot aSpot;
0040 
0041   //typedef math::XYZPoint Point;
0042   //enum { dimension = 7 };
0043   //typedef math::Error<dimension>::type CovarianceMatrix;
0044 
0045   //try {
0046   edm::LogInfo("RecoVertex/BeamSpotProducer") << "Reconstructing event number: " << iEvent.id() << "\n";
0047 
0048   edm::ESHandle<BeamSpotObjects> beamhandle = iSetup.getHandle(m_beamToken);
0049   const BeamSpotObjects* spotDB = beamhandle.product();
0050 
0051   // translate from BeamSpotObjects to reco::BeamSpot
0052   reco::BeamSpot::Point apoint(spotDB->x(), spotDB->y(), spotDB->z());
0053 
0054   reco::BeamSpot::CovarianceMatrix matrix;
0055   for (int i = 0; i < 7; ++i) {
0056     for (int j = 0; j < 7; ++j) {
0057       matrix(i, j) = spotDB->covariance(i, j);
0058     }
0059   }
0060 
0061   // this assume beam width same in x and y
0062   aSpot = reco::BeamSpot(apoint, spotDB->sigmaZ(), spotDB->dxdz(), spotDB->dydz(), spotDB->beamWidthX(), matrix);
0063   aSpot.setBeamWidthY(spotDB->beamWidthY());
0064   aSpot.setEmittanceX(spotDB->emittanceX());
0065   aSpot.setEmittanceY(spotDB->emittanceY());
0066   aSpot.setbetaStar(spotDB->betaStar());
0067 
0068   //}
0069   //
0070   //catch (std::exception & err) {
0071   //    edm::LogInfo("RecoVertex/BeamSpotProducer")
0072   //        << "Exception during event number: " << iEvent.id()
0073   //        << "\n" << err.what() << "\n";
0074   //}
0075 
0076   *result = aSpot;
0077 
0078   iEvent.put(std::move(result));
0079 }
0080 
0081 //define this as a plug-in
0082 DEFINE_FWK_MODULE(BeamSpotProducer);