CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/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 void AlcaBeamSpotFromDB::endLuminosityBlockProduce(edm::LuminosityBlock& lumiSeg, const edm::EventSetup& iSetup)
00052 {
00053   // read DB object
00054   edm::ESHandle< BeamSpotObjects > beamhandle;
00055   iSetup.get<BeamSpotObjectsRcd>().get(beamhandle);
00056   const BeamSpotObjects *spotDB = beamhandle.product();
00057 
00058   // translate from BeamSpotObjects to reco::BeamSpot
00059   reco::BeamSpot::Point apoint( spotDB->GetX(), spotDB->GetY(), spotDB->GetZ() );
00060   
00061   reco::BeamSpot::CovarianceMatrix matrix;
00062   for ( int i=0; i<7; ++i ) {
00063     for ( int j=0; j<7; ++j ) {
00064       matrix(i,j) = spotDB->GetCovariance(i,j);
00065     }
00066   }
00067   
00068   reco::BeamSpot aSpot;
00069   // this assume beam width same in x and y
00070   aSpot = reco::BeamSpot( apoint,
00071                           spotDB->GetSigmaZ(),
00072                           spotDB->Getdxdz(),
00073                           spotDB->Getdydz(),
00074                           spotDB->GetBeamWidthX(),
00075                           matrix );
00076   aSpot.setBeamWidthY( spotDB->GetBeamWidthY() );
00077   aSpot.setEmittanceX( spotDB->GetEmittanceX() );
00078   aSpot.setEmittanceY( spotDB->GetEmittanceY() );
00079   aSpot.setbetaStar( spotDB->GetBetaStar() );
00080 
00081   if ( spotDB->GetBeamType() == 2 ) {
00082     aSpot.setType( reco::BeamSpot::Tracker );
00083   } else{
00084     aSpot.setType( reco::BeamSpot::Fake );
00085   }
00086 
00087   std::auto_ptr<reco::BeamSpot> result(new reco::BeamSpot);
00088   *result = aSpot;
00089   lumiSeg.put(result, std::string("alcaBeamSpot"));
00090 
00091   //std::cout << " for runs: " << iEvent.id().run() << " - " << iEvent.id().run() << std::endl;
00092   std::cout << aSpot << std::endl;
00093 
00094 }
00095 
00096 
00097 void
00098 AlcaBeamSpotFromDB::beginJob()
00099 {
00100 }
00101 
00102 void
00103 AlcaBeamSpotFromDB::endJob() {
00104 }
00105 
00106 //define this as a plug-in
00107 DEFINE_FWK_MODULE(AlcaBeamSpotFromDB);