CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/RecoVertex/BeamSpotProducer/plugins/BeamSpotOnlineProducer.cc

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>("label");
00023   changeFrame_ = iconf.getParameter<bool>("changeToCMSCoordinates");
00024 
00025   theMaxR2 = iconf.getParameter<double>("maxRadius");
00026   theMaxR2*=theMaxR2;
00027   theMaxZ = iconf.getParameter<double>("maxZ");
00028 
00029   theSetSigmaZ = iconf.getParameter<double>("setSigmaZ");
00030   
00031   thel1GtEvmReadoutRecordTag = iconf.getParameter<InputTag>("gtEvmLabel");
00032   
00033   produces<reco::BeamSpot>();
00034 
00035 } 
00036 
00037 BeamSpotOnlineProducer::~BeamSpotOnlineProducer() {}
00038 
00039 void
00040 BeamSpotOnlineProducer::produce(Event& iEvent, const EventSetup& iSetup)
00041 {
00042   //shout MODE only in stable beam
00043   bool shoutMODE=false;
00044   edm::Handle<L1GlobalTriggerEvmReadoutRecord> gtEvmReadoutRecord;
00045   if (iEvent.getByLabel(thel1GtEvmReadoutRecordTag, gtEvmReadoutRecord)){
00046     const boost::uint16_t beamModeValue = (gtEvmReadoutRecord->gtfeWord()).beamMode();
00047     if (beamModeValue == 11) shoutMODE=true;
00048   }
00049   else{
00050     shoutMODE=true;
00051   }
00052 
00053   // get scalar collection
00054   Handle<BeamSpotOnlineCollection> handleScaler;
00055   iEvent.getByLabel( scalertag_, handleScaler);
00056 
00057   // beam spot scalar object
00058   BeamSpotOnline spotOnline;
00059 
00060   // product is a reco::BeamSpot object
00061   std::auto_ptr<reco::BeamSpot> result(new reco::BeamSpot);
00062   
00063   reco::BeamSpot aSpot;
00064 
00065   bool fallBackToDB=false;
00066   if (handleScaler->size()!=0){
00067     // get one element
00068     spotOnline = * ( handleScaler->begin() );
00069     
00070     // in case we need to switch to LHC reference frame
00071     // ignore for the moment rotations, and translations
00072     double f = 1.;
00073     if (changeFrame_) f = -1.;
00074     
00075     reco::BeamSpot::Point apoint( f* spotOnline.x(), spotOnline.y(), f* spotOnline.z() );
00076     
00077     reco::BeamSpot::CovarianceMatrix matrix;
00078     matrix(0,0) = spotOnline.err_x()*spotOnline.err_x();
00079     matrix(1,1) = spotOnline.err_y()*spotOnline.err_y();
00080     matrix(2,2) = spotOnline.err_z()*spotOnline.err_z();
00081     matrix(3,3) = spotOnline.err_sigma_z()*spotOnline.err_sigma_z();
00082     
00083     double sigmaZ = spotOnline.sigma_z();
00084     if (theSetSigmaZ>0)
00085       sigmaZ = theSetSigmaZ;
00086     
00087     aSpot = reco::BeamSpot( apoint,
00088                             sigmaZ,
00089                           spotOnline.dxdz(),
00090                             f* spotOnline.dydz(),
00091                             spotOnline.width_x(),
00092                             matrix);
00093     
00094     aSpot.setBeamWidthY( spotOnline.width_y() );
00095     aSpot.setEmittanceX( 0. );
00096     aSpot.setEmittanceY( 0. );
00097     aSpot.setbetaStar( 0.) ;
00098     aSpot.setType( reco::BeamSpot::LHC ); // flag value from scalars
00099     
00100     // check if we have a valid beam spot fit result from online DQM
00101     if ( spotOnline.x() == 0 &&
00102          spotOnline.y() == 0 &&
00103          spotOnline.z() == 0 &&
00104          spotOnline.width_x() == 0 &&
00105          spotOnline.width_y() == 0 ) 
00106       {
00107         if (shoutMODE){
00108           edm::LogWarning("BeamSpotFromDB") 
00109           << "Online Beam Spot producer falls back to DB value because the scaler values are zero ";
00110         }
00111         fallBackToDB=true;
00112       }
00113     double r2=spotOnline.x()*spotOnline.x() + spotOnline.y()*spotOnline.y();
00114     if (fabs(spotOnline.z())>=theMaxZ || r2>=theMaxR2){
00115       if (shoutMODE){
00116         edm::LogError("BeamSpotFromDB") 
00117           << "Online Beam Spot producer falls back to DB value because the scaler values are too big to be true :"
00118           <<spotOnline.x()<<" "<<spotOnline.y()<<" "<<spotOnline.z();
00119       }
00120       fallBackToDB=true;
00121     }
00122   }
00123   else{
00124     //empty online beamspot collection: FED data was empty
00125     //the error should probably have been send at unpacker level
00126     fallBackToDB=true;
00127   }
00128       
00129   if (fallBackToDB){
00130 
00131     edm::ESHandle< BeamSpotObjects > beamhandle;
00132     iSetup.get<BeamSpotObjectsRcd>().get(beamhandle);
00133     const BeamSpotObjects *spotDB = beamhandle.product();
00134 
00135     // translate from BeamSpotObjects to reco::BeamSpot
00136     reco::BeamSpot::Point apoint( spotDB->GetX(), spotDB->GetY(), spotDB->GetZ() );
00137   
00138     reco::BeamSpot::CovarianceMatrix matrix;
00139     for ( int i=0; i<7; ++i ) {
00140       for ( int j=0; j<7; ++j ) {
00141         matrix(i,j) = spotDB->GetCovariance(i,j);
00142       }
00143     }
00144   
00145     // this assume beam width same in x and y
00146     aSpot = reco::BeamSpot( apoint,
00147                             spotDB->GetSigmaZ(),
00148                             spotDB->Getdxdz(),
00149                             spotDB->Getdydz(),
00150                             spotDB->GetBeamWidthX(),
00151                             matrix );
00152     aSpot.setBeamWidthY( spotDB->GetBeamWidthY() );
00153     aSpot.setEmittanceX( spotDB->GetEmittanceX() );
00154     aSpot.setEmittanceY( spotDB->GetEmittanceY() );
00155     aSpot.setbetaStar( spotDB->GetBetaStar() );
00156     aSpot.setType( reco::BeamSpot::Tracker );
00157 
00158   }
00159   
00160   *result = aSpot;
00161 
00162   iEvent.put(result);
00163 
00164 }
00165 
00166 DEFINE_FWK_MODULE(BeamSpotOnlineProducer);