CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BeamSpotOnlineProducer.cc
Go to the documentation of this file.
1 
5 
11 
13 
15 
16 using namespace edm;
17 
18 
20 {
21 
22  scalertag_ = iconf.getParameter<InputTag>("src");
23 
24  changeFrame_ = iconf.getParameter<bool>("changeToCMSCoordinates");
25 
26  theMaxR2 = iconf.getParameter<double>("maxRadius");
27  theMaxR2*=theMaxR2;
28  theMaxZ = iconf.getParameter<double>("maxZ");
29 
30  theSetSigmaZ = iconf.getParameter<double>("setSigmaZ");
31 
32  thel1GtEvmReadoutRecordTag = iconf.getParameter<InputTag>("gtEvmLabel");
33 
34  produces<reco::BeamSpot>();
35 
36 }
37 
39 
40 void
42 {
43  //shout MODE only in stable beam
44  bool shoutMODE=false;
46  if (iEvent.getByLabel(thel1GtEvmReadoutRecordTag, gtEvmReadoutRecord)){
47  const boost::uint16_t beamModeValue = (gtEvmReadoutRecord->gtfeWord()).beamMode();
48  if (beamModeValue == 11) shoutMODE=true;
49  }
50  else{
51  shoutMODE=true;
52  }
53 
54  // get scalar collection
56  iEvent.getByLabel( scalertag_, handleScaler);
57 
58  // beam spot scalar object
59  BeamSpotOnline spotOnline;
60 
61  // product is a reco::BeamSpot object
62  std::auto_ptr<reco::BeamSpot> result(new reco::BeamSpot);
63 
64  reco::BeamSpot aSpot;
65 
66  bool fallBackToDB=false;
67  if (handleScaler->size()!=0){
68  // get one element
69  spotOnline = * ( handleScaler->begin() );
70 
71  // in case we need to switch to LHC reference frame
72  // ignore for the moment rotations, and translations
73  double f = 1.;
74  if (changeFrame_) f = -1.;
75 
76  reco::BeamSpot::Point apoint( f* spotOnline.x(), spotOnline.y(), f* spotOnline.z() );
77 
79  matrix(0,0) = spotOnline.err_x()*spotOnline.err_x();
80  matrix(1,1) = spotOnline.err_y()*spotOnline.err_y();
81  matrix(2,2) = spotOnline.err_z()*spotOnline.err_z();
82  matrix(3,3) = spotOnline.err_sigma_z()*spotOnline.err_sigma_z();
83 
84  double sigmaZ = spotOnline.sigma_z();
85  if (theSetSigmaZ>0)
86  sigmaZ = theSetSigmaZ;
87 
88  aSpot = reco::BeamSpot( apoint,
89  sigmaZ,
90  spotOnline.dxdz(),
91  f* spotOnline.dydz(),
92  spotOnline.width_x(),
93  matrix);
94 
95  aSpot.setBeamWidthY( spotOnline.width_y() );
96  aSpot.setEmittanceX( 0. );
97  aSpot.setEmittanceY( 0. );
98  aSpot.setbetaStar( 0.) ;
99  aSpot.setType( reco::BeamSpot::LHC ); // flag value from scalars
100 
101  // check if we have a valid beam spot fit result from online DQM
102  if ( spotOnline.x() == 0 &&
103  spotOnline.y() == 0 &&
104  spotOnline.z() == 0 &&
105  spotOnline.width_x() == 0 &&
106  spotOnline.width_y() == 0 )
107  {
108  if (shoutMODE){
109  edm::LogWarning("BeamSpotFromDB")
110  << "Online Beam Spot producer falls back to DB value because the scaler values are zero ";
111  }
112  fallBackToDB=true;
113  }
114  double r2=spotOnline.x()*spotOnline.x() + spotOnline.y()*spotOnline.y();
115  if (fabs(spotOnline.z())>=theMaxZ || r2>=theMaxR2){
116  if (shoutMODE){
117  edm::LogError("BeamSpotFromDB")
118  << "Online Beam Spot producer falls back to DB value because the scaler values are too big to be true :"
119  <<spotOnline.x()<<" "<<spotOnline.y()<<" "<<spotOnline.z();
120  }
121  fallBackToDB=true;
122  }
123  }
124  else{
125  //empty online beamspot collection: FED data was empty
126  //the error should probably have been send at unpacker level
127  fallBackToDB=true;
128  }
129 
130  if (fallBackToDB){
131 
133  iSetup.get<BeamSpotObjectsRcd>().get(beamhandle);
134  const BeamSpotObjects *spotDB = beamhandle.product();
135 
136  // translate from BeamSpotObjects to reco::BeamSpot
137  reco::BeamSpot::Point apoint( spotDB->GetX(), spotDB->GetY(), spotDB->GetZ() );
138 
140  for ( int i=0; i<7; ++i ) {
141  for ( int j=0; j<7; ++j ) {
142  matrix(i,j) = spotDB->GetCovariance(i,j);
143  }
144  }
145 
146  // this assume beam width same in x and y
147  aSpot = reco::BeamSpot( apoint,
148  spotDB->GetSigmaZ(),
149  spotDB->Getdxdz(),
150  spotDB->Getdydz(),
151  spotDB->GetBeamWidthX(),
152  matrix );
153  aSpot.setBeamWidthY( spotDB->GetBeamWidthY() );
154  aSpot.setEmittanceX( spotDB->GetEmittanceX() );
155  aSpot.setEmittanceY( spotDB->GetEmittanceY() );
156  aSpot.setbetaStar( spotDB->GetBetaStar() );
158 
159  }
160 
161  *result = aSpot;
162 
163  iEvent.put(result);
164 
165 }
166 
double Getdydz() const
get dydz slope, crossing angle in YZ
math::Error< dimension >::type CovarianceMatrix
Definition: BeamSpot.h:32
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
float err_y() const
float dxdz() const
double GetY() const
get Y beam position
void setbetaStar(double v)
Definition: BeamSpot.h:146
float err_x() const
float dydz() const
BeamSpotOnlineProducer(const edm::ParameterSet &iConf)
constructor
float sigma_z() const
float y() const
float x() const
double GetSigmaZ() const
get sigma Z, RMS bunch length
double GetBeamWidthX() const
get average transverse beam width
math::XYZPoint Point
point in the space
Definition: BeamSpot.h:30
float z() const
DEFINE_FWK_MODULE(HiMixingModule)
float width_y() const
double GetBeamWidthY() const
get average transverse beam width
double GetEmittanceX() const
get emittance
void setType(BeamType type)
set beam type
Definition: BeamSpot.h:132
int iEvent
Definition: GenABIO.cc:243
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
produce a beam spot class
void setBeamWidthY(double v)
Definition: BeamSpot.h:110
void setEmittanceY(double v)
Definition: BeamSpot.h:145
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
tuple result
Definition: query.py:137
int j
Definition: DBlmapReader.cc:9
double GetZ() const
get Z beam position
double f[11][100]
double Getdxdz() const
get dxdz slope, crossing angle in XZ
float err_z() const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
double GetX() const
get X beam position
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
double GetBetaStar() const
get beta star
double GetCovariance(int i, int j) const
get i,j element of the full covariance matrix 7x7
float width_x() const
double GetEmittanceY() const
get emittance
float err_sigma_z() const
void setEmittanceX(double v)
Definition: BeamSpot.h:144