Go to the documentation of this file.00001
00002 #include "RecoVertex/BeamSpotProducer/interface/BeamSpotOnlineProducer.h"
00003 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00004 #include "DataFormats/Scalers/interface/BeamSpotOnline.h"
00005
00006 #include "FWCore/Framework/interface/ESHandle.h"
00007 #include "FWCore/Framework/interface/EventSetup.h"
00008 #include "FWCore/Framework/interface/IOVSyncValue.h"
00009 #include "CondFormats/DataRecord/interface/BeamSpotObjectsRcd.h"
00010 #include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h"
00011
00012 #include "FWCore/Framework/interface/MakerMacros.h"
00013
00014 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerEvmReadoutRecord.h"
00015
00016 using namespace edm;
00017
00018
00019 BeamSpotOnlineProducer::BeamSpotOnlineProducer(const ParameterSet& iconf)
00020 {
00021
00022 scalertag_ = iconf.getParameter<InputTag>("src");
00023
00024 changeFrame_ = iconf.getParameter<bool>("changeToCMSCoordinates");
00025
00026 theMaxR2 = iconf.getParameter<double>("maxRadius");
00027 theMaxR2*=theMaxR2;
00028 theMaxZ = iconf.getParameter<double>("maxZ");
00029
00030 theSetSigmaZ = iconf.getParameter<double>("setSigmaZ");
00031
00032 thel1GtEvmReadoutRecordTag = iconf.getParameter<InputTag>("gtEvmLabel");
00033
00034 produces<reco::BeamSpot>();
00035
00036 }
00037
00038 BeamSpotOnlineProducer::~BeamSpotOnlineProducer() {}
00039
00040 void
00041 BeamSpotOnlineProducer::produce(Event& iEvent, const EventSetup& iSetup)
00042 {
00043
00044 bool shoutMODE=false;
00045 edm::Handle<L1GlobalTriggerEvmReadoutRecord> gtEvmReadoutRecord;
00046 if (iEvent.getByLabel(thel1GtEvmReadoutRecordTag, gtEvmReadoutRecord)){
00047 const boost::uint16_t beamModeValue = (gtEvmReadoutRecord->gtfeWord()).beamMode();
00048 if (beamModeValue == 11) shoutMODE=true;
00049 }
00050 else{
00051 shoutMODE=true;
00052 }
00053
00054
00055 Handle<BeamSpotOnlineCollection> handleScaler;
00056 iEvent.getByLabel( scalertag_, handleScaler);
00057
00058
00059 BeamSpotOnline spotOnline;
00060
00061
00062 std::auto_ptr<reco::BeamSpot> result(new reco::BeamSpot);
00063
00064 reco::BeamSpot aSpot;
00065
00066 bool fallBackToDB=false;
00067 if (handleScaler->size()!=0){
00068
00069 spotOnline = * ( handleScaler->begin() );
00070
00071
00072
00073 double f = 1.;
00074 if (changeFrame_) f = -1.;
00075
00076 reco::BeamSpot::Point apoint( f* spotOnline.x(), spotOnline.y(), f* spotOnline.z() );
00077
00078 reco::BeamSpot::CovarianceMatrix matrix;
00079 matrix(0,0) = spotOnline.err_x()*spotOnline.err_x();
00080 matrix(1,1) = spotOnline.err_y()*spotOnline.err_y();
00081 matrix(2,2) = spotOnline.err_z()*spotOnline.err_z();
00082 matrix(3,3) = spotOnline.err_sigma_z()*spotOnline.err_sigma_z();
00083
00084 double sigmaZ = spotOnline.sigma_z();
00085 if (theSetSigmaZ>0)
00086 sigmaZ = theSetSigmaZ;
00087
00088 aSpot = reco::BeamSpot( apoint,
00089 sigmaZ,
00090 spotOnline.dxdz(),
00091 f* spotOnline.dydz(),
00092 spotOnline.width_x(),
00093 matrix);
00094
00095 aSpot.setBeamWidthY( spotOnline.width_y() );
00096 aSpot.setEmittanceX( 0. );
00097 aSpot.setEmittanceY( 0. );
00098 aSpot.setbetaStar( 0.) ;
00099 aSpot.setType( reco::BeamSpot::LHC );
00100
00101
00102 if ( spotOnline.x() == 0 &&
00103 spotOnline.y() == 0 &&
00104 spotOnline.z() == 0 &&
00105 spotOnline.width_x() == 0 &&
00106 spotOnline.width_y() == 0 )
00107 {
00108 if (shoutMODE){
00109 edm::LogWarning("BeamSpotFromDB")
00110 << "Online Beam Spot producer falls back to DB value because the scaler values are zero ";
00111 }
00112 fallBackToDB=true;
00113 }
00114 double r2=spotOnline.x()*spotOnline.x() + spotOnline.y()*spotOnline.y();
00115 if (fabs(spotOnline.z())>=theMaxZ || r2>=theMaxR2){
00116 if (shoutMODE){
00117 edm::LogError("BeamSpotFromDB")
00118 << "Online Beam Spot producer falls back to DB value because the scaler values are too big to be true :"
00119 <<spotOnline.x()<<" "<<spotOnline.y()<<" "<<spotOnline.z();
00120 }
00121 fallBackToDB=true;
00122 }
00123 }
00124 else{
00125
00126
00127 fallBackToDB=true;
00128 }
00129
00130 if (fallBackToDB){
00131
00132 edm::ESHandle< BeamSpotObjects > beamhandle;
00133 iSetup.get<BeamSpotObjectsRcd>().get(beamhandle);
00134 const BeamSpotObjects *spotDB = beamhandle.product();
00135
00136
00137 reco::BeamSpot::Point apoint( spotDB->GetX(), spotDB->GetY(), spotDB->GetZ() );
00138
00139 reco::BeamSpot::CovarianceMatrix matrix;
00140 for ( int i=0; i<7; ++i ) {
00141 for ( int j=0; j<7; ++j ) {
00142 matrix(i,j) = spotDB->GetCovariance(i,j);
00143 }
00144 }
00145
00146
00147 aSpot = reco::BeamSpot( apoint,
00148 spotDB->GetSigmaZ(),
00149 spotDB->Getdxdz(),
00150 spotDB->Getdydz(),
00151 spotDB->GetBeamWidthX(),
00152 matrix );
00153 aSpot.setBeamWidthY( spotDB->GetBeamWidthY() );
00154 aSpot.setEmittanceX( spotDB->GetEmittanceX() );
00155 aSpot.setEmittanceY( spotDB->GetEmittanceY() );
00156 aSpot.setbetaStar( spotDB->GetBetaStar() );
00157 aSpot.setType( reco::BeamSpot::Tracker );
00158
00159 }
00160
00161 *result = aSpot;
00162
00163 iEvent.put(result);
00164
00165 }
00166
00167 DEFINE_FWK_MODULE(BeamSpotOnlineProducer);