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_(consumes<BeamSpotOnlineCollection>(iconf.getParameter<InputTag>("src"))),
66  l1GtEvmReadoutRecordToken_(consumes<L1GlobalTriggerEvmReadoutRecord>(iconf.getParameter<InputTag>("gtEvmLabel"))),
69  theBeamShoutMode(iconf.getUntrackedParameter<unsigned int>("beamMode", 11)) {
70  theMaxR2 = iconf.getParameter<double>("maxRadius");
71  theMaxR2 *= theMaxR2;
72 
73  produces<reco::BeamSpot>();
74 }
75 
78  ps.add<bool>("changeToCMSCoordinates", false);
79  ps.add<double>("maxZ", 40.);
80  ps.add<double>("setSigmaZ", -1.);
81  ps.addUntracked<unsigned int>("beamMode", 11);
82  ps.add<InputTag>("src", InputTag("hltScalersRawToDigi"));
83  ps.add<InputTag>("gtEvmLabel", InputTag(""));
84  ps.add<double>("maxRadius", 2.0);
85  ps.add<bool>("useTransientRecord", false);
86  iDesc.addWithDefaultLabel(ps);
87 }
88 
90  // product is a reco::BeamSpot object
91  auto result = std::make_unique<reco::BeamSpot>();
92  reco::BeamSpot aSpot;
93  //shout MODE only in stable beam
94  bool shoutMODE = false;
96  if (iEvent.getByToken(l1GtEvmReadoutRecordToken_, gtEvmReadoutRecord)) {
97  if (gtEvmReadoutRecord->gtfeWord().beamMode() == theBeamShoutMode)
98  shoutMODE = true;
99  } else {
100  shoutMODE = true;
101  }
102  bool fallBackToDB = false;
103  if (useTransientRecord_) {
104  auto const& spotDB = iSetup.getData(beamTransientToken_);
105  if (spotDB.GetBeamType() != 2) {
106  if (shoutMODE && beamTransientRcdESWatcher_.check(iSetup)) {
107  edm::LogWarning("BeamSpotFromDB")
108  << "Online Beam Spot producer falls back to DB value because the ESProducer returned a fake beamspot ";
109  }
110  fallBackToDB = true;
111  } else {
112  // translate from BeamSpotObjects to reco::BeamSpot
113  // in case we need to switch to LHC reference frame
114  // ignore for the moment rotations, and translations
115  double f = 1.;
116  if (changeFrame_)
117  f = -1.;
118  reco::BeamSpot::Point apoint(f * spotDB.GetX(), f * spotDB.GetY(), f * spotDB.GetZ());
119 
121  for (int i = 0; i < 7; ++i) {
122  for (int j = 0; j < 7; ++j) {
123  matrix(i, j) = spotDB.GetCovariance(i, j);
124  }
125  }
126  double sigmaZ = spotDB.GetSigmaZ();
127  if (theSetSigmaZ > 0)
129 
130  // this assume beam width same in x and y
131  aSpot = reco::BeamSpot(apoint, sigmaZ, spotDB.Getdxdz(), spotDB.Getdydz(), spotDB.GetBeamWidthX(), matrix);
132  aSpot.setBeamWidthY(spotDB.GetBeamWidthY());
133  aSpot.setEmittanceX(spotDB.GetEmittanceX());
134  aSpot.setEmittanceY(spotDB.GetEmittanceY());
135  aSpot.setbetaStar(spotDB.GetBetaStar());
137  }
138  } else {
139  // get scalar collection
141  iEvent.getByToken(scalerToken_, handleScaler);
142 
143  // beam spot scalar object
144  BeamSpotOnline spotOnline;
145 
146  // product is a reco::BeamSpot object
147  auto result = std::make_unique<reco::BeamSpot>();
148 
149  if (!handleScaler->empty()) {
150  // get one element
151  spotOnline = *(handleScaler->begin());
152 
153  // in case we need to switch to LHC reference frame
154  // ignore for the moment rotations, and translations
155  double f = 1.;
156  if (changeFrame_)
157  f = -1.;
158 
159  reco::BeamSpot::Point apoint(f * spotOnline.x(), spotOnline.y(), f * spotOnline.z());
160 
162  matrix(0, 0) = spotOnline.err_x() * spotOnline.err_x();
163  matrix(1, 1) = spotOnline.err_y() * spotOnline.err_y();
164  matrix(2, 2) = spotOnline.err_z() * spotOnline.err_z();
165  matrix(3, 3) = spotOnline.err_sigma_z() * spotOnline.err_sigma_z();
166 
167  double sigmaZ = spotOnline.sigma_z();
168  if (theSetSigmaZ > 0)
170 
171  aSpot = reco::BeamSpot(apoint, sigmaZ, spotOnline.dxdz(), f * spotOnline.dydz(), spotOnline.width_x(), matrix);
172 
173  aSpot.setBeamWidthY(spotOnline.width_y());
174  aSpot.setEmittanceX(0.);
175  aSpot.setEmittanceY(0.);
176  aSpot.setbetaStar(0.);
177  aSpot.setType(reco::BeamSpot::LHC); // flag value from scalars
178 
179  // check if we have a valid beam spot fit result from online DQM
180  if (spotOnline.x() == 0 && spotOnline.y() == 0 && spotOnline.z() == 0 && spotOnline.width_x() == 0 &&
181  spotOnline.width_y() == 0) {
182  if (shoutMODE) {
183  edm::LogWarning("BeamSpotFromDB")
184  << "Online Beam Spot producer falls back to DB value because the scaler values are zero ";
185  }
186  fallBackToDB = true;
187  }
188  double r2 = spotOnline.x() * spotOnline.x() + spotOnline.y() * spotOnline.y();
189  if (std::abs(spotOnline.z()) >= theMaxZ || r2 >= theMaxR2) {
190  if (shoutMODE) {
191  edm::LogError("BeamSpotFromDB")
192  << "Online Beam Spot producer falls back to DB value because the scaler values are too big to be true :"
193  << spotOnline.x() << " " << spotOnline.y() << " " << spotOnline.z();
194  }
195  fallBackToDB = true;
196  }
197  } else {
198  //empty online beamspot collection: FED data was empty
199  //the error should probably have been send at unpacker level
200  fallBackToDB = true;
201  }
202  }
203  if (fallBackToDB) {
205  const BeamSpotObjects* spotDB = beamhandle.product();
206 
207  // translate from BeamSpotObjects to reco::BeamSpot
208  reco::BeamSpot::Point apoint(spotDB->GetX(), spotDB->GetY(), spotDB->GetZ());
209 
211  for (int i = 0; i < 7; ++i) {
212  for (int j = 0; j < 7; ++j) {
213  matrix(i, j) = spotDB->GetCovariance(i, j);
214  }
215  }
216 
217  // this assume beam width same in x and y
218  aSpot = reco::BeamSpot(
219  apoint, spotDB->GetSigmaZ(), spotDB->Getdxdz(), spotDB->Getdydz(), spotDB->GetBeamWidthX(), matrix);
220  aSpot.setBeamWidthY(spotDB->GetBeamWidthY());
221  aSpot.setEmittanceX(spotDB->GetEmittanceX());
222  aSpot.setEmittanceY(spotDB->GetEmittanceY());
223  aSpot.setbetaStar(spotDB->GetBetaStar());
225  }
226 
227  *result = aSpot;
228 
229  iEvent.put(std::move(result));
230 }
231 
ConfigurationDescriptions.h
edm::ESWatcher::check
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
BeamSpotOnline::x
float x() const
Definition: BeamSpotOnline.h:48
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
BeamSpotObjects::GetBeamWidthY
double GetBeamWidthY() const
get average transverse beam width
Definition: BeamSpotObjects.h:77
BeamSpotObjects::Getdxdz
double Getdxdz() const
get dxdz slope, crossing angle in XZ
Definition: BeamSpotObjects.h:79
BeamSpotOnlineProducer::beamToken_
const edm::ESGetToken< BeamSpotObjects, BeamSpotObjectsRcd > beamToken_
Definition: BeamSpotOnlineProducer.cc:49
BeamSpotOnlineProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &iDesc)
Fill descriptor.
Definition: BeamSpotOnlineProducer.cc:76
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
reco::BeamSpot::setBeamWidthY
void setBeamWidthY(double v)
Definition: BeamSpot.h:105
MessageLogger.h
BeamSpotPI::sigmaZ
Definition: BeamSpotPayloadInspectorHelper.h:36
makeMuonMisalignmentScenario.matrix
list matrix
Definition: makeMuonMisalignmentScenario.py:141
BeamSpotOnline::err_y
float err_y() const
Definition: BeamSpotOnline.h:54
reco::BeamSpot::setEmittanceY
void setEmittanceY(double v)
Definition: BeamSpot.h:137
edm::ESWatcher< BeamSpotTransientObjectsRcd >
ESHandle.h
align::BeamSpot
Definition: StructureType.h:95
BeamSpotTransientObjectsRcd
Definition: BeamSpotTransientObjectsRcd.h:27
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
BeamSpotOnline::err_z
float err_z() const
Definition: BeamSpotOnline.h:55
BeamSpotOnline::dxdz
float dxdz() const
Definition: BeamSpotOnline.h:51
BeamSpotOnline::y
float y() const
Definition: BeamSpotOnline.h:49
edm::EDGetTokenT< BeamSpotOnlineCollection >
BeamSpotObjects::GetSigmaZ
double GetSigmaZ() const
get sigma Z, RMS bunch length
Definition: BeamSpotObjects.h:73
edm
HLT enums.
Definition: AlignableModifier.h:19
L1GlobalTriggerEvmReadoutRecord::gtfeWord
const L1GtfeExtWord gtfeWord() const
get / set GTFE word (record) in the GT readout record
Definition: L1GlobalTriggerEvmReadoutRecord.cc:249
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
BeamSpotObjects::GetZ
double GetZ() const
get Z beam position
Definition: BeamSpotObjects.h:71
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
BeamSpotOnline::dydz
float dydz() const
Definition: BeamSpotOnline.h:52
EDProducer.h
BeamSpotOnline.h
reco::BeamSpot::LHC
Definition: BeamSpot.h:24
BeamSpotOnline::err_sigma_z
float err_sigma_z() const
Definition: BeamSpotOnline.h:63
BeamSpotOnline::width_x
float width_x() const
Definition: BeamSpotOnline.h:58
BeamSpotOnlineProducer::useTransientRecord_
const bool useTransientRecord_
Definition: BeamSpotOnlineProducer.cc:46
edm::Handle
Definition: AssociativeIterator.h:50
ESGetToken.h
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
BeamSpotOnlineProducer::theMaxR2
double theMaxR2
Definition: BeamSpotOnlineProducer.cc:45
MakerMacros.h
BeamSpotOnline::err_x
float err_x() const
Definition: BeamSpotOnline.h:53
BeamSpotObjects.h
L1GlobalTriggerEvmReadoutRecord.h
BeamSpotOnlineProducer
Definition: BeamSpotOnlineProducer.cc:31
BeamSpotObjectsRcd.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
BeamSpot.h
BeamSpotOnlineProducer::changeFrame_
const bool changeFrame_
Definition: BeamSpotOnlineProducer.cc:43
L1GlobalTriggerEvmReadoutRecord
Definition: L1GlobalTriggerEvmReadoutRecord.h:36
BeamSpotOnline::sigma_z
float sigma_z() const
Definition: BeamSpotOnline.h:60
reco::BeamSpot
Definition: BeamSpot.h:21
BeamSpotOnlineProducer::beamTransientToken_
const edm::ESGetToken< BeamSpotObjects, BeamSpotTransientObjectsRcd > beamTransientToken_
Definition: BeamSpotOnlineProducer.cc:50
reco::BeamSpot::Tracker
Definition: BeamSpot.h:24
edm::ESHandle
Definition: DTSurvey.h:22
BeamSpotObjects::GetCovariance
double GetCovariance(int i, int j) const
get i,j element of the full covariance matrix 7x7
Definition: BeamSpotObjects.h:83
reco::BeamSpot::setEmittanceX
void setEmittanceX(double v)
Definition: BeamSpot.h:136
ParameterSetDescription.h
BeamSpotOnlineProducer::theSetSigmaZ
const double theSetSigmaZ
Definition: BeamSpotOnlineProducer.cc:44
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
BeamSpotObjects::GetBetaStar
double GetBetaStar() const
get beta star
Definition: BeamSpotObjects.h:107
edm::ParameterSetDescription::addUntracked
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:100
BeamSpotObjects::GetEmittanceX
double GetEmittanceX() const
get emittance
Definition: BeamSpotObjects.h:103
BeamSpotOnlineProducer::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
produce a beam spot class
Definition: BeamSpotOnlineProducer.cc:89
edm::ParameterSet
Definition: ParameterSet.h:47
BeamSpotObjects::GetY
double GetY() const
get Y beam position
Definition: BeamSpotObjects.h:69
Event.h
reco::BeamSpot::setbetaStar
void setbetaStar(double v)
Definition: BeamSpot.h:138
diffTwoXMLs.r2
r2
Definition: diffTwoXMLs.py:73
BeamSpotTransientObjectsRcd.h
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:155
edm::stream::EDProducer
Definition: EDProducer.h:36
BeamSpotOnlineProducer::BeamSpotOnlineProducer
BeamSpotOnlineProducer(const edm::ParameterSet &iConf)
constructor
Definition: BeamSpotOnlineProducer.cc:60
BeamSpotObjectsRcd
Definition: BeamSpotObjectsRcd.h:24
BeamSpotObjects
Definition: BeamSpotObjects.h:20
edm::EventSetup
Definition: EventSetup.h:58
reco::BeamSpot::CovarianceMatrix
math::Error< dimension >::type CovarianceMatrix
Definition: BeamSpot.h:29
BeamSpotOnlineProducer::scalerToken_
const edm::EDGetTokenT< BeamSpotOnlineCollection > scalerToken_
Definition: BeamSpotOnlineProducer.cc:47
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
edm::ESGetToken< BeamSpotObjects, BeamSpotObjectsRcd >
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
BeamSpotOnline
Definition: BeamSpotOnline.h:28
BeamSpotObjects::GetBeamWidthX
double GetBeamWidthX() const
get average transverse beam width
Definition: BeamSpotObjects.h:75
eostools.move
def move(src, dest)
Definition: eostools.py:511
BeamSpotOnline::width_y
float width_y() const
Definition: BeamSpotOnline.h:59
BeamSpotObjects::GetEmittanceY
double GetEmittanceY() const
get emittance
Definition: BeamSpotObjects.h:105
BeamSpotObjects::Getdydz
double Getdydz() const
get dydz slope, crossing angle in YZ
Definition: BeamSpotObjects.h:81
BeamSpotOnlineProducer::l1GtEvmReadoutRecordToken_
const edm::EDGetTokenT< L1GlobalTriggerEvmReadoutRecord > l1GtEvmReadoutRecordToken_
Definition: BeamSpotOnlineProducer.cc:48
ESWatcher.h
BeamSpotOnlineCollection
std::vector< BeamSpotOnline > BeamSpotOnlineCollection
Definition: BeamSpotOnline.h:101
BeamSpotOnlineProducer::theMaxZ
const double theMaxZ
Definition: BeamSpotOnlineProducer.cc:44
TrackEfficiencyMonitor_cfi.theMaxZ
theMaxZ
Definition: TrackEfficiencyMonitor_cfi.py:11
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
mps_fire.result
result
Definition: mps_fire.py:311
reco::BeamSpot::Point
math::XYZPoint Point
point in the space
Definition: BeamSpot.h:27
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
BeamSpotOnlineProducer::theBeamShoutMode
const unsigned int theBeamShoutMode
Definition: BeamSpotOnlineProducer.cc:55
reco::BeamSpot::setType
void setType(BeamType type)
set beam type
Definition: BeamSpot.h:124
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
BeamSpotOnline::z
float z() const
Definition: BeamSpotOnline.h:50
edm::Event
Definition: Event.h:73
BeamSpotObjects::GetX
double GetX() const
get X beam position
Definition: BeamSpotObjects.h:67
L1GtfeExtWord::beamMode
const cms_uint16_t beamMode() const
Definition: L1GtfeExtWord.cc:215
edm::InputTag
Definition: InputTag.h:15
edm::ConfigurationDescriptions::addWithDefaultLabel
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:87
BeamSpotOnlineProducer::beamTransientRcdESWatcher_
edm::ESWatcher< BeamSpotTransientObjectsRcd > beamTransientRcdESWatcher_
Definition: BeamSpotOnlineProducer.cc:53