CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoVertex/BeamSpotProducer/plugins/BeamSpotProducer.cc

Go to the documentation of this file.
00001 
00002 #include "RecoVertex/BeamSpotProducer/interface/BeamSpotProducer.h"
00003 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00004 
00005 #include "FWCore/Framework/interface/MakerMacros.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 #include "FWCore/Framework/interface/ESHandle.h"
00008 #include "FWCore/Framework/interface/EventSetup.h"
00009 #include "FWCore/Framework/interface/IOVSyncValue.h"
00010 #include "CondFormats/DataRecord/interface/BeamSpotObjectsRcd.h"
00011 #include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h"
00012 
00013 #include "DataFormats/Math/interface/Error.h"
00014 #include "DataFormats/Math/interface/Point3D.h"
00015 
00016 //
00017 // constructors and destructor
00018 //
00019 BeamSpotProducer::BeamSpotProducer(const edm::ParameterSet& iConf) {
00020         
00021         edm::LogInfo("RecoVertex/BeamSpotProducer") 
00022                 << "Initializing Beam Spot producer " << "\n";
00023   
00024         //fVerbose=conf.getUntrackedParameter<bool>("verbose", false);
00025         
00026         produces<reco::BeamSpot>();
00027 
00028 }
00029 
00030 
00031 BeamSpotProducer::~BeamSpotProducer() {}
00032 
00033 //
00034 // member functions
00035 //
00036 
00037 // ------------ method called to produce the data  ------------
00038 void
00039 BeamSpotProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
00040         
00041         using namespace edm;
00042 
00043         std::auto_ptr<reco::BeamSpot> result(new reco::BeamSpot);
00044 
00045         reco::BeamSpot aSpot;
00046 
00047         
00048         //typedef math::XYZPoint Point;
00049     //enum { dimension = 7 };
00050     //typedef math::Error<dimension>::type CovarianceMatrix;
00051 
00052         
00053         //try {
00054         edm::LogInfo("RecoVertex/BeamSpotProducer") 
00055           << "Reconstructing event number: " << iEvent.id() << "\n";
00056 
00057         edm::ESHandle< BeamSpotObjects > beamhandle;
00058         iSetup.get<BeamSpotObjectsRcd>().get(beamhandle);
00059         const BeamSpotObjects *spotDB = beamhandle.product();
00060 
00061         // translate from BeamSpotObjects to reco::BeamSpot
00062         reco::BeamSpot::Point apoint( spotDB->GetX(), spotDB->GetY(), spotDB->GetZ() );
00063                 
00064         reco::BeamSpot::CovarianceMatrix matrix;
00065         for ( int i=0; i<7; ++i ) {
00066           for ( int j=0; j<7; ++j ) {
00067             matrix(i,j) = spotDB->GetCovariance(i,j);
00068           }
00069         }
00070         
00071         // this assume beam width same in x and y
00072         aSpot = reco::BeamSpot( apoint,
00073                                 spotDB->GetSigmaZ(),
00074                                 spotDB->Getdxdz(),
00075                                 spotDB->Getdydz(),
00076                                 spotDB->GetBeamWidthX(),
00077                                 matrix );
00078         aSpot.setBeamWidthY( spotDB->GetBeamWidthY() );
00079         aSpot.setEmittanceX( spotDB->GetEmittanceX() );
00080         aSpot.setEmittanceY( spotDB->GetEmittanceY() );
00081         aSpot.setbetaStar( spotDB->GetBetaStar() );
00082                 
00083         //}
00084         //
00085         //catch (std::exception & err) {
00086         //      edm::LogInfo("RecoVertex/BeamSpotProducer") 
00087         //              << "Exception during event number: " << iEvent.id() 
00088         //              << "\n" << err.what() << "\n";
00089         //}
00090 
00091         *result = aSpot;
00092         
00093         iEvent.put(result);
00094         
00095 }
00096 
00097 //define this as a plug-in
00098 DEFINE_FWK_MODULE(BeamSpotProducer);
00099