CMS 3D CMS Logo

BeamSpotOnlineProducer.cc
Go to the documentation of this file.
1 
30 
32 public:
34  explicit BeamSpotOnlineProducer(const edm::ParameterSet& iConf);
35 
37  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
38 
41 
42 private:
43  const bool changeFrame_;
44  const double theMaxZ, theSetSigmaZ;
45  double theMaxR2;
46  const bool useTransientRecord_;
51 
52  // watch IOV transition to emit warnings
54 
55  const unsigned int theBeamShoutMode;
56 };
57 
58 using namespace edm;
59 
61  : changeFrame_(iconf.getParameter<bool>("changeToCMSCoordinates")),
62  theMaxZ(iconf.getParameter<double>("maxZ")),
63  theSetSigmaZ(iconf.getParameter<double>("setSigmaZ")),
64  useTransientRecord_(iconf.getParameter<bool>("useTransientRecord")),
65  scalerToken_(useTransientRecord_ ? edm::EDGetTokenT<BeamSpotOnlineCollection>()
66  : consumes<BeamSpotOnlineCollection>(iconf.getParameter<InputTag>("src"))),
67  l1GtEvmReadoutRecordToken_(consumes<L1GlobalTriggerEvmReadoutRecord>(iconf.getParameter<InputTag>("gtEvmLabel"))),
70  theBeamShoutMode(iconf.getUntrackedParameter<unsigned int>("beamMode", 11)) {
71  theMaxR2 = iconf.getParameter<double>("maxRadius");
72  theMaxR2 *= theMaxR2;
73 
74  produces<reco::BeamSpot>();
75 }
76 
79  ps.add<bool>("changeToCMSCoordinates", false);
80  ps.add<double>("maxZ", 40.);
81  ps.add<double>("setSigmaZ", -1.);
82  ps.addUntracked<unsigned int>("beamMode", 11);
83  ps.addOptional<InputTag>("src", InputTag("hltScalersRawToDigi"))->setComment("SCAL decommissioned after Run 2");
84  ps.add<InputTag>("gtEvmLabel", InputTag(""));
85  ps.add<double>("maxRadius", 2.0);
86  ps.add<bool>("useTransientRecord", false);
87  iDesc.addWithDefaultLabel(ps);
88 }
89 
91  // product is a reco::BeamSpot object
92  auto result = std::make_unique<reco::BeamSpot>();
93  reco::BeamSpot aSpot;
94  //shout MODE only in stable beam
95  bool shoutMODE = false;
97  if (iEvent.getByToken(l1GtEvmReadoutRecordToken_, gtEvmReadoutRecord)) {
98  if (gtEvmReadoutRecord->gtfeWord().beamMode() == theBeamShoutMode)
99  shoutMODE = true;
100  } else {
101  shoutMODE = true;
102  }
103  bool fallBackToDB = false;
104  if (useTransientRecord_) {
105  auto const& spotDB = iSetup.getData(beamTransientToken_);
106  if (spotDB.beamType() != 2) {
107  if (shoutMODE && beamTransientRcdESWatcher_.check(iSetup)) {
108  edm::LogWarning("BeamSpotFromDB")
109  << "Online Beam Spot producer falls back to DB value because the ESProducer returned a fake beamspot ";
110  }
111  fallBackToDB = true;
112  } else {
113  // translate from BeamSpotObjects to reco::BeamSpot
114  // in case we need to switch to LHC reference frame
115  // ignore for the moment rotations, and translations
116  double f = 1.;
117  if (changeFrame_)
118  f = -1.;
119  reco::BeamSpot::Point apoint(f * spotDB.x(), f * spotDB.y(), f * spotDB.z());
120 
122  for (int i = 0; i < 7; ++i) {
123  for (int j = 0; j < 7; ++j) {
124  matrix(i, j) = spotDB.covariance(i, j);
125  }
126  }
127  double sigmaZ = spotDB.sigmaZ();
128  if (theSetSigmaZ > 0)
130 
131  // this assume beam width same in x and y
132  aSpot = reco::BeamSpot(apoint, sigmaZ, spotDB.dxdz(), spotDB.dydz(), spotDB.beamWidthX(), matrix);
133  aSpot.setBeamWidthY(spotDB.beamWidthY());
134  aSpot.setEmittanceX(spotDB.emittanceX());
135  aSpot.setEmittanceY(spotDB.emittanceY());
136  aSpot.setbetaStar(spotDB.betaStar());
137  aSpot.setType(reco::BeamSpot::Tracker);
138  }
139  } else {
140  // get scalar collection
142  iEvent.getByToken(scalerToken_, handleScaler);
143 
144  // beam spot scalar object
145  BeamSpotOnline spotOnline;
146 
147  // product is a reco::BeamSpot object
148  auto result = std::make_unique<reco::BeamSpot>();
149 
150  if (!handleScaler->empty()) {
151  // get one element
152  spotOnline = *(handleScaler->begin());
153 
154  // in case we need to switch to LHC reference frame
155  // ignore for the moment rotations, and translations
156  double f = 1.;
157  if (changeFrame_)
158  f = -1.;
159 
160  reco::BeamSpot::Point apoint(f * spotOnline.x(), spotOnline.y(), f * spotOnline.z());
161 
163  matrix(0, 0) = spotOnline.err_x() * spotOnline.err_x();
164  matrix(1, 1) = spotOnline.err_y() * spotOnline.err_y();
165  matrix(2, 2) = spotOnline.err_z() * spotOnline.err_z();
166  matrix(3, 3) = spotOnline.err_sigma_z() * spotOnline.err_sigma_z();
167 
168  double sigmaZ = spotOnline.sigma_z();
169  if (theSetSigmaZ > 0)
171 
172  aSpot = reco::BeamSpot(apoint, sigmaZ, spotOnline.dxdz(), f * spotOnline.dydz(), spotOnline.width_x(), matrix);
173 
174  aSpot.setBeamWidthY(spotOnline.width_y());
175  aSpot.setEmittanceX(0.);
176  aSpot.setEmittanceY(0.);
177  aSpot.setbetaStar(0.);
178  aSpot.setType(reco::BeamSpot::LHC); // flag value from scalars
179 
180  // check if we have a valid beam spot fit result from online DQM
181  if (spotOnline.x() == 0 && spotOnline.y() == 0 && spotOnline.z() == 0 && spotOnline.width_x() == 0 &&
182  spotOnline.width_y() == 0) {
183  if (shoutMODE) {
184  edm::LogWarning("BeamSpotFromDB")
185  << "Online Beam Spot producer falls back to DB value because the scaler values are zero ";
186  }
187  fallBackToDB = true;
188  }
189  double r2 = spotOnline.x() * spotOnline.x() + spotOnline.y() * spotOnline.y();
190  if (std::abs(spotOnline.z()) >= theMaxZ || r2 >= theMaxR2) {
191  if (shoutMODE) {
192  edm::LogError("BeamSpotFromDB")
193  << "Online Beam Spot producer falls back to DB value because the scaler values are too big to be true :"
194  << spotOnline.x() << " " << spotOnline.y() << " " << spotOnline.z();
195  }
196  fallBackToDB = true;
197  }
198  } else {
199  //empty online beamspot collection: FED data was empty
200  //the error should probably have been send at unpacker level
201  fallBackToDB = true;
202  }
203  }
204  if (fallBackToDB) {
206  const BeamSpotObjects* spotDB = beamhandle.product();
207 
208  // translate from BeamSpotObjects to reco::BeamSpot
209  reco::BeamSpot::Point apoint(spotDB->x(), spotDB->y(), spotDB->z());
210 
212  for (int i = 0; i < 7; ++i) {
213  for (int j = 0; j < 7; ++j) {
214  matrix(i, j) = spotDB->covariance(i, j);
215  }
216  }
217 
218  // this assume beam width same in x and y
219  aSpot = reco::BeamSpot(apoint, spotDB->sigmaZ(), spotDB->dxdz(), spotDB->dydz(), spotDB->beamWidthX(), matrix);
220  aSpot.setBeamWidthY(spotDB->beamWidthY());
221  aSpot.setEmittanceX(spotDB->emittanceX());
222  aSpot.setEmittanceY(spotDB->emittanceY());
223  aSpot.setbetaStar(spotDB->betaStar());
224  aSpot.setType(reco::BeamSpot::Tracker);
225  }
226 
227  *result = aSpot;
228 
229  iEvent.put(std::move(result));
230 }
231 
double emittanceX() const
get emittance
float err_y() const
std::vector< BeamSpotOnline > BeamSpotOnlineCollection
math::Error< dimension >::type CovarianceMatrix
Definition: BeamSpot.h:29
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
float z() const
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
double z() const
get Z beam position
const edm::ESGetToken< BeamSpotObjects, BeamSpotTransientObjectsRcd > beamTransientToken_
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
const cms_uint16_t beamMode() const
float dydz() const
double dydz() const
get dydz slope, crossing angle in YZ
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
double covariance(int i, int j) const
get i,j element of the full covariance matrix 7x7
const edm::EDGetTokenT< L1GlobalTriggerEvmReadoutRecord > l1GtEvmReadoutRecordToken_
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
produce a beam spot class
BeamSpotOnlineProducer(const edm::ParameterSet &iConf)
constructor
const edm::EDGetTokenT< BeamSpotOnlineCollection > scalerToken_
float y() const
const L1GtfeExtWord gtfeWord() const
get / set GTFE word (record) in the GT readout record
float err_x() const
float err_z() const
math::XYZPoint Point
point in the space
Definition: BeamSpot.h:27
double beamWidthX() const
get average transverse beam width
Log< level::Error, false > LogError
float err_sigma_z() const
float dxdz() const
float width_x() const
const edm::ESGetToken< BeamSpotObjects, BeamSpotObjectsRcd > beamToken_
int iEvent
Definition: GenABIO.cc:224
T const * product() const
Definition: ESHandle.h:86
float sigma_z() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double x() const
get X beam position
double f[11][100]
edm::ESWatcher< BeamSpotTransientObjectsRcd > beamTransientRcdESWatcher_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const unsigned int theBeamShoutMode
ParameterDescriptionBase * add(U const &iLabel, T const &value)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
double beamWidthY() const
get average transverse beam width
float width_y() const
double y() const
get Y beam position
static void fillDescriptions(edm::ConfigurationDescriptions &iDesc)
Fill descriptor.
double sigmaZ() const
get sigma Z, RMS bunch length
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
double emittanceY() const
get emittance
double betaStar() const
get beta star
HLT enums.
Log< level::Warning, false > LogWarning
double dxdz() const
get dxdz slope, crossing angle in XZ
def move(src, dest)
Definition: eostools.py:511
float x() const