CMS 3D CMS Logo

BeamSpotOnlineProducer.cc
Go to the documentation of this file.
1 
31 
33 public:
35  explicit BeamSpotOnlineProducer(const edm::ParameterSet& iConf);
36 
38  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
39 
42 
43 private:
44  const bool changeFrame_;
45  const double theMaxZ, theSetSigmaZ;
46  double theMaxR2;
47  const bool useTransientRecord_;
52 
53  // watch IOV transition to emit warnings
55 
56  const unsigned int theBeamShoutMode;
57 };
58 
59 using namespace edm;
60 
62  : changeFrame_(iconf.getParameter<bool>("changeToCMSCoordinates")),
63  theMaxZ(iconf.getParameter<double>("maxZ")),
64  theSetSigmaZ(iconf.getParameter<double>("setSigmaZ")),
65  useTransientRecord_(iconf.getParameter<bool>("useTransientRecord")),
66  scalerToken_(useTransientRecord_ ? edm::EDGetTokenT<BeamSpotOnlineCollection>()
67  : consumes<BeamSpotOnlineCollection>(iconf.getParameter<InputTag>("src"))),
68  l1GtEvmReadoutRecordToken_(consumes<L1GlobalTriggerEvmReadoutRecord>(iconf.getParameter<InputTag>("gtEvmLabel"))),
71  theBeamShoutMode(iconf.getUntrackedParameter<unsigned int>("beamMode", 11)) {
72  theMaxR2 = iconf.getParameter<double>("maxRadius");
73  theMaxR2 *= theMaxR2;
74 
75  produces<reco::BeamSpot>();
76 }
77 
80  ps.add<bool>("changeToCMSCoordinates", false);
81  ps.add<double>("maxZ", 40.);
82  ps.add<double>("setSigmaZ", -1.);
83  ps.addUntracked<unsigned int>("beamMode", 11);
84  ps.addOptional<InputTag>("src", InputTag("hltScalersRawToDigi"))->setComment("SCAL decommissioned after Run 2");
85  ps.add<InputTag>("gtEvmLabel", InputTag(""));
86  ps.add<double>("maxRadius", 2.0);
87  ps.add<bool>("useTransientRecord", false);
88  iDesc.addWithDefaultLabel(ps);
89 }
90 
92  // product is a reco::BeamSpot object
93  auto result = std::make_unique<reco::BeamSpot>();
94  reco::BeamSpot aSpot;
95  //shout MODE only in stable beam
96  bool shoutMODE = false;
98  if (iEvent.getByToken(l1GtEvmReadoutRecordToken_, gtEvmReadoutRecord)) {
99  if (gtEvmReadoutRecord->gtfeWord().beamMode() == theBeamShoutMode)
100  shoutMODE = true;
101  } else {
102  shoutMODE = true;
103  }
104  bool fallBackToDB = false;
105  if (useTransientRecord_) {
106  auto const& spotDB = iSetup.getData(beamTransientToken_);
107  if (spotDB.beamType() != 2) {
108  if (shoutMODE && beamTransientRcdESWatcher_.check(iSetup)) {
109  edm::LogWarning("BeamSpotOnlineProducer")
110  << "Online Beam Spot producer falls back to DB value because the ESProducer returned a fake beamspot ";
111  }
112  fallBackToDB = true;
113  } else {
114  // translate from BeamSpotObjects to reco::BeamSpot
115  // in case we need to switch to LHC reference frame
116  // ignore for the moment rotations, and translations
117  double f = 1.;
118  if (changeFrame_)
119  f = -1.;
120  reco::BeamSpot::Point apoint(f * spotDB.x(), f * spotDB.y(), f * spotDB.z());
121 
123  for (int i = 0; i < reco::BeamSpot::dimension; ++i) {
124  for (int j = 0; j < reco::BeamSpot::dimension; ++j) {
125  matrix(i, j) = spotDB.covariance(i, j);
126  }
127  }
128  double sigmaZ = spotDB.sigmaZ();
129  if (theSetSigmaZ > 0)
131 
132  // this assume beam width same in x and y
133  aSpot = reco::BeamSpot(apoint, sigmaZ, spotDB.dxdz(), spotDB.dydz(), spotDB.beamWidthX(), matrix);
134  aSpot.setBeamWidthY(spotDB.beamWidthY());
135  aSpot.setEmittanceX(spotDB.emittanceX());
136  aSpot.setEmittanceY(spotDB.emittanceY());
137  aSpot.setbetaStar(spotDB.betaStar());
138  aSpot.setType(reco::BeamSpot::Tracker);
139  }
140  } else {
141  // get scalar collection
143  iEvent.getByToken(scalerToken_, handleScaler);
144 
145  // beam spot scalar object
146  BeamSpotOnline spotOnline;
147 
148  // product is a reco::BeamSpot object
149  auto result = std::make_unique<reco::BeamSpot>();
150 
151  if (!handleScaler->empty()) {
152  // get one element
153  spotOnline = *(handleScaler->begin());
154 
155  // in case we need to switch to LHC reference frame
156  // ignore for the moment rotations, and translations
157  double f = 1.;
158  if (changeFrame_)
159  f = -1.;
160 
161  reco::BeamSpot::Point apoint(f * spotOnline.x(), spotOnline.y(), f * spotOnline.z());
162 
164  matrix(0, 0) = spotOnline.err_x() * spotOnline.err_x();
165  matrix(1, 1) = spotOnline.err_y() * spotOnline.err_y();
166  matrix(2, 2) = spotOnline.err_z() * spotOnline.err_z();
167  matrix(3, 3) = spotOnline.err_sigma_z() * spotOnline.err_sigma_z();
168 
169  double sigmaZ = spotOnline.sigma_z();
170  if (theSetSigmaZ > 0)
172 
173  aSpot = reco::BeamSpot(apoint, sigmaZ, spotOnline.dxdz(), f * spotOnline.dydz(), spotOnline.width_x(), matrix);
174 
175  aSpot.setBeamWidthY(spotOnline.width_y());
176  aSpot.setEmittanceX(0.);
177  aSpot.setEmittanceY(0.);
178  aSpot.setbetaStar(0.);
179  aSpot.setType(reco::BeamSpot::LHC); // flag value from scalars
180 
181  // check if we have a valid beam spot fit result from online DQM
182  if (spotOnline.x() == 0 && spotOnline.y() == 0 && spotOnline.z() == 0 && spotOnline.width_x() == 0 &&
183  spotOnline.width_y() == 0) {
184  if (shoutMODE) {
185  edm::LogWarning("BeamSpotOnlineProducer")
186  << "Online Beam Spot producer falls back to DB value because the scaler values are zero ";
187  }
188  fallBackToDB = true;
189  }
190  double r2 = spotOnline.x() * spotOnline.x() + spotOnline.y() * spotOnline.y();
191  if (std::abs(spotOnline.z()) >= theMaxZ || r2 >= theMaxR2) {
192  if (shoutMODE) {
193  edm::LogError("BeamSpotOnlineProducer")
194  << "Online Beam Spot producer falls back to DB value because the scaler values are too big to be true :"
195  << spotOnline.x() << " " << spotOnline.y() << " " << spotOnline.z();
196  }
197  fallBackToDB = true;
198  }
199  } else {
200  //empty online beamspot collection: FED data was empty
201  //the error should probably have been send at unpacker level
202  fallBackToDB = true;
203  }
204  }
205  if (fallBackToDB) {
207  const BeamSpotObjects* spotDB = beamhandle.product();
208 
209  // translate from BeamSpotObjects to reco::BeamSpot
210  reco::BeamSpot::Point apoint(spotDB->x(), spotDB->y(), spotDB->z());
211 
213  for (int i = 0; i < reco::BeamSpot::dimension; ++i) {
214  for (int j = 0; j < reco::BeamSpot::dimension; ++j) {
215  matrix(i, j) = spotDB->covariance(i, j);
216  }
217  }
218 
219  // this assume beam width same in x and y
220  aSpot = reco::BeamSpot(apoint, spotDB->sigmaZ(), spotDB->dxdz(), spotDB->dydz(), spotDB->beamWidthX(), matrix);
221  aSpot.setBeamWidthY(spotDB->beamWidthY());
222  aSpot.setEmittanceX(spotDB->emittanceX());
223  aSpot.setEmittanceY(spotDB->emittanceY());
224  aSpot.setbetaStar(spotDB->betaStar());
225  aSpot.setType(reco::BeamSpot::Tracker);
226 
227  GlobalError bse(aSpot.rotatedCovariance3D());
228  if ((bse.cxx() <= 0.) || (bse.cyy() <= 0.) || (bse.czz() <= 0.)) {
229  edm::LogError("UnusableBeamSpot") << "Beamspot from fallback to DB with invalid errors: " << aSpot.covariance();
230  }
231  }
232 
233  *result = aSpot;
234 
235  iEvent.put(std::move(result));
236 }
237 
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:307
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