CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/Calibration/TkAlCaRecoProducers/plugins/AlcaBeamSpotFromDB.cc

Go to the documentation of this file.
00001 
00014 // C++ standard
00015 #include <string>
00016 // CMS
00017 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00018 #include "Calibration/TkAlCaRecoProducers/interface/AlcaBeamSpotFromDB.h"
00019 
00020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00021 
00022 #include "FWCore/Framework/interface/MakerMacros.h"
00023 #include "FWCore/ServiceRegistry/interface/Service.h"
00024 
00025 #include "FWCore/Framework/interface/ESHandle.h"
00026 #include "FWCore/Framework/interface/EventSetup.h"
00027 #include "FWCore/Framework/interface/IOVSyncValue.h"
00028 #include "FWCore/Framework/interface/LuminosityBlock.h"
00029 #include "CondFormats/DataRecord/interface/BeamSpotObjectsRcd.h"
00030 #include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h"
00031 
00032 
00033 AlcaBeamSpotFromDB::AlcaBeamSpotFromDB(const edm::ParameterSet& iConfig)
00034 {
00035 
00036   produces<reco::BeamSpot, edm::InLumi>("alcaBeamSpot");  
00037 }
00038 
00039 
00040 AlcaBeamSpotFromDB::~AlcaBeamSpotFromDB()
00041 {
00042         
00043 }
00044 
00045 //--------------------------------------------------------------------------------------------------                                                                      
00046 void AlcaBeamSpotFromDB::produce(edm::Event& iEvent, const edm::EventSetup& iSetup){
00047 
00048 }
00049 
00050 //--------------------------------------------------------------------------------------------------
00051 
00052 void AlcaBeamSpotFromDB::beginLuminosityBlock(edm::LuminosityBlock& lumiSeg, const edm::EventSetup& iSetup)
00053 {}
00054 
00055 //--------------------------------------------------------------------------------------------------                                                                      
00056 void AlcaBeamSpotFromDB::endLuminosityBlock(edm::LuminosityBlock& lumiSeg, const edm::EventSetup& iSetup)
00057 {
00058   // read DB object
00059   edm::ESHandle< BeamSpotObjects > beamhandle;
00060   iSetup.get<BeamSpotObjectsRcd>().get(beamhandle);
00061   const BeamSpotObjects *spotDB = beamhandle.product();
00062 
00063   // translate from BeamSpotObjects to reco::BeamSpot
00064   reco::BeamSpot::Point apoint( spotDB->GetX(), spotDB->GetY(), spotDB->GetZ() );
00065   
00066   reco::BeamSpot::CovarianceMatrix matrix;
00067   for ( int i=0; i<7; ++i ) {
00068     for ( int j=0; j<7; ++j ) {
00069       matrix(i,j) = spotDB->GetCovariance(i,j);
00070     }
00071   }
00072   
00073   reco::BeamSpot aSpot;
00074   // this assume beam width same in x and y
00075   aSpot = reco::BeamSpot( apoint,
00076                           spotDB->GetSigmaZ(),
00077                           spotDB->Getdxdz(),
00078                           spotDB->Getdydz(),
00079                           spotDB->GetBeamWidthX(),
00080                           matrix );
00081   aSpot.setBeamWidthY( spotDB->GetBeamWidthY() );
00082   aSpot.setEmittanceX( spotDB->GetEmittanceX() );
00083   aSpot.setEmittanceY( spotDB->GetEmittanceY() );
00084   aSpot.setbetaStar( spotDB->GetBetaStar() );
00085 
00086   if ( spotDB->GetBeamType() == 2 ) {
00087     aSpot.setType( reco::BeamSpot::Tracker );
00088   } else{
00089     aSpot.setType( reco::BeamSpot::Fake );
00090   }
00091 
00092   std::auto_ptr<reco::BeamSpot> result(new reco::BeamSpot);
00093   *result = aSpot;
00094   lumiSeg.put(result, std::string("alcaBeamSpot"));
00095 
00096   //std::cout << " for runs: " << iEvent.id().run() << " - " << iEvent.id().run() << std::endl;
00097   std::cout << aSpot << std::endl;
00098 
00099 }
00100 
00101 
00102 void
00103 AlcaBeamSpotFromDB::beginJob()
00104 {
00105 }
00106 
00107 void
00108 AlcaBeamSpotFromDB::endJob() {
00109 }
00110 
00111 //define this as a plug-in
00112 DEFINE_FWK_MODULE(AlcaBeamSpotFromDB);