CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
OnlineBeamSpotESProducer Class Reference
Inheritance diagram for OnlineBeamSpotESProducer:
edm::ESProducer edm::ESProductResolverFactoryProducer edm::eventsetup::ESProductResolverProvider

Public Member Functions

 OnlineBeamSpotESProducer (const edm::ParameterSet &p)
 
std::shared_ptr< const BeamSpotObjectsproduce (const BeamSpotTransientObjectsRcd &)
 
- Public Member Functions inherited from edm::ESProducer
 ESProducer ()
 
 ESProducer (const ESProducer &)=delete
 
 ESProducer (ESProducer &&)=delete
 
ESResolverIndex const * getTokenIndices (unsigned int iIndex) const
 
ESRecordIndex const * getTokenRecordIndices (unsigned int iIndex) const
 
bool hasMayConsumes () const noexcept
 
size_t numberOfTokenIndices (unsigned int iIndex) const
 
ESProduceroperator= (const ESProducer &)=delete
 
ESProduceroperator= (ESProducer &&)=delete
 
SerialTaskQueueChainqueue ()
 
template<typename Record >
std::optional< std::vector< ESResolverIndex > > updateFromMayConsumes (unsigned int iIndex, const Record &iRecord) const
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices const &) final
 
 ~ESProducer () noexcept(false) override
 
- Public Member Functions inherited from edm::ESProductResolverFactoryProducer
 ESProductResolverFactoryProducer ()
 
 ESProductResolverFactoryProducer (const ESProductResolverFactoryProducer &)=delete
 
const ESProductResolverFactoryProduceroperator= (const ESProductResolverFactoryProducer &)=delete
 
 ~ESProductResolverFactoryProducer () noexcept(false) override
 
- Public Member Functions inherited from edm::eventsetup::ESProductResolverProvider
void createKeyedResolvers (EventSetupRecordKey const &key, unsigned int nConcurrentIOVs)
 
const ComponentDescriptiondescription () const
 
 ESProductResolverProvider ()
 
 ESProductResolverProvider (const ESProductResolverProvider &)=delete
 
void fillRecordsNotAllowingConcurrentIOVs (std::set< EventSetupRecordKey > &recordsNotAllowingConcurrentIOVs) const
 
virtual void initConcurrentIOVs (EventSetupRecordKey const &key, unsigned int nConcurrentIOVs)
 
bool isUsingRecord (const EventSetupRecordKey &key) const
 
KeyedResolverskeyedResolvers (const EventSetupRecordKey &iRecordKey, unsigned int iovIndex=0)
 
const ESProductResolverProvideroperator= (const ESProductResolverProvider &)=delete
 
void setAppendToDataLabel (const edm::ParameterSet &)
 
void setDescription (const ComponentDescription &iDescription)
 
std::set< EventSetupRecordKeyusingRecords () const
 
virtual ~ESProductResolverProvider () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &desc)
 
- Static Public Member Functions inherited from edm::eventsetup::ESProductResolverProvider
static void prevalidate (ConfigurationDescriptions &)
 

Private Member Functions

const BeamSpotOnlineObjectscheckSingleBS (const BeamSpotOnlineObjects *bs1)
 
const BeamSpotOnlineObjectscompareBS (const BeamSpotOnlineObjects *bs1, const BeamSpotOnlineObjects *bs2)
 
bool isGoodBS (const BeamSpotOnlineObjects *bs1) const
 

Private Attributes

edm::ESGetToken< BeamSpotOnlineObjects, BeamSpotOnlineHLTObjectsRcdbsHLTToken_
 
edm::ESGetToken< BeamSpotOnlineObjects, BeamSpotOnlineLegacyObjectsRcdbsLegacyToken_
 
edm::ESGetToken< BeamSpotObjects, BeamSpotTransientObjectsRcd > const bsToken_
 
BeamSpotObjects fakeBS_
 
const double sigmaXYThreshold_
 
const double sigmaZThreshold_
 
const int timeThreshold_
 

Additional Inherited Members

- Protected Types inherited from edm::ESProductResolverFactoryProducer
using EventSetupRecordKey = eventsetup::EventSetupRecordKey
 
- Protected Types inherited from edm::eventsetup::ESProductResolverProvider
using KeyedResolversVector = std::vector< std::pair< DataKey, std::shared_ptr< ESProductResolver > >>
 
- Protected Member Functions inherited from edm::ESProducer
ESConsumesInfoconsumesInfoPushBackNew ()
 
unsigned int consumesInfoSize () const
 
template<typename CallbackT , typename TList , typename TRecord >
void registerProducts (std::shared_ptr< std::pair< unsigned int, std::shared_ptr< CallbackT >>> iCallback, const TList *, const TRecord *iRecord, const es::Label &iLabel)
 
template<typename CallbackT , typename TRecord >
void registerProducts (std::shared_ptr< std::pair< unsigned int, std::shared_ptr< CallbackT >>>, const eventsetup::produce::Null *, const TRecord *, const es::Label &)
 
template<typename T >
auto setWhatProduced (T *iThis, const es::Label &iLabel={})
 
template<typename T >
auto setWhatProduced (T *iThis, const char *iLabel)
 
template<typename T >
auto setWhatProduced (T *iThis, const std::string &iLabel)
 
template<typename T , typename TDecorator >
auto setWhatProduced (T *iThis, const TDecorator &iDec, const es::Label &iLabel={})
 
template<typename T , typename TReturn , typename TRecord >
auto setWhatProduced (T *iThis, TReturn(T::*iMethod)(const TRecord &), const es::Label &iLabel={})
 
template<typename T , typename TReturn , typename TRecord , typename TDecorator >
auto setWhatProduced (T *iThis, TReturn(T ::*iMethod)(const TRecord &), const TDecorator &iDec, const es::Label &iLabel={})
 
template<typename TFunc >
auto setWhatProduced (TFunc &&func, const es::Label &iLabel={})
 
template<typename TReturn , typename TRecord , typename TFunc , typename TDecorator >
ESConsumesCollectorT< TRecord > setWhatProduced (TFunc &&func, TDecorator &&iDec, const es::Label &iLabel={})
 
void usesResources (std::vector< std::string > const &)
 
- Protected Member Functions inherited from edm::ESProductResolverFactoryProducer
template<class TFactory >
void registerFactory (std::unique_ptr< TFactory > iFactory, const std::string &iLabel=std::string())
 
virtual void registerFactoryWithKey (const EventSetupRecordKey &iRecord, std::unique_ptr< eventsetup::ESProductResolverFactoryBase > iFactory, const std::string &iLabel=std::string())
 
KeyedResolversVector registerResolvers (const EventSetupRecordKey &, unsigned int iovIndex) override
 
- Protected Member Functions inherited from edm::eventsetup::ESProductResolverProvider
template<class T >
void usingRecord ()
 
void usingRecordWithKey (const EventSetupRecordKey &key)
 

Detailed Description

Definition at line 24 of file OnlineBeamSpotESProducer.cc.

Constructor & Destructor Documentation

◆ OnlineBeamSpotESProducer()

OnlineBeamSpotESProducer::OnlineBeamSpotESProducer ( const edm::ParameterSet p)

Definition at line 45 of file OnlineBeamSpotESProducer.cc.

References bsHLTToken_, bsLegacyToken_, gpuPixelDoublets::cc, MillePedeFileConverter_cfg::e, fakeBS_, BeamSpotObjects::setBeamWidthX(), BeamSpotObjects::setBeamWidthY(), BeamSpotObjects::setCovariance(), BeamSpotObjects::setPosition(), BeamSpotObjects::setSigmaZ(), BeamSpotObjects::setType(), and edm::ESProducer::setWhatProduced().

47  : timeThreshold_(p.getParameter<int>("timeThreshold")),
48  sigmaZThreshold_(p.getParameter<double>("sigmaZThreshold")),
49  sigmaXYThreshold_(p.getParameter<double>("sigmaXYThreshold") * 1E-4) {
50  auto cc = setWhatProduced(this);
51 
54  fakeBS_.setSigmaZ(15.);
55  fakeBS_.setPosition(0.0001, 0.0001, 0.0001);
56  fakeBS_.setType(-1);
57  // Set diagonal covariance, i.e. errors on the parameters
58  fakeBS_.setCovariance(0, 0, 5e-10);
59  fakeBS_.setCovariance(1, 1, 5e-10);
60  fakeBS_.setCovariance(2, 2, 0.002);
61  fakeBS_.setCovariance(3, 3, 0.002);
62  fakeBS_.setCovariance(4, 4, 5e-11);
63  fakeBS_.setCovariance(5, 5, 5e-11);
64  fakeBS_.setCovariance(6, 6, 1e-09);
65 
68 }
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:166
void setCovariance(int i, int j, double val)
set i,j element of the full covariance matrix 7x7
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
edm::ESGetToken< BeamSpotOnlineObjects, BeamSpotOnlineHLTObjectsRcd > bsHLTToken_
void setType(int type)
set beam type
edm::ESGetToken< BeamSpotOnlineObjects, BeamSpotOnlineLegacyObjectsRcd > bsLegacyToken_
void setSigmaZ(double val)
set sigma Z, RMS bunch length
void setPosition(double x, double y, double z)
set XYZ position
void setBeamWidthX(double val)
set average transverse beam width X
void setBeamWidthY(double val)
set average transverse beam width Y

Member Function Documentation

◆ checkSingleBS()

const BeamSpotOnlineObjects * OnlineBeamSpotESProducer::checkSingleBS ( const BeamSpotOnlineObjects bs1)
private

Definition at line 132 of file OnlineBeamSpotESProducer.cc.

References submitPVResolutionJobs::count, BeamSpotOnlineObjects::creationTime(), getRunInfo::hours, isGoodBS(), submitPVValidationJobs::now, and timeThreshold_.

Referenced by produce().

132  {
133  // Current time to be compared with the one read from the payload
134  auto currentTime =
135  std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch());
136 
137  // Get the beamspot creation time and compute the time difference wrt currentTime
138  auto bs1time = std::chrono::microseconds(bs1->creationTime());
139  auto diffBStime1 = (currentTime - bs1time).count();
140 
141  // Convert timeThreshold_ from hours to microseconds for comparison
142  auto limitTime = std::chrono::microseconds((std::chrono::hours)timeThreshold_).count();
143 
144  // Check that the BS is within the timeThreshold, converges and passes the sigmaZthreshold
145  if (diffBStime1 < limitTime && isGoodBS(bs1)) {
146  return bs1;
147  } else {
148  return nullptr;
149  }
150 }
cond::Time_t creationTime() const
bool isGoodBS(const BeamSpotOnlineObjects *bs1) const

◆ compareBS()

const BeamSpotOnlineObjects * OnlineBeamSpotESProducer::compareBS ( const BeamSpotOnlineObjects bs1,
const BeamSpotOnlineObjects bs2 
)
private

Definition at line 78 of file OnlineBeamSpotESProducer.cc.

References submitPVResolutionJobs::count, BeamSpotOnlineObjects::creationTime(), getRunInfo::hours, isGoodBS(), submitPVValidationJobs::now, BeamSpotObjects::sigmaZ(), and timeThreshold_.

Referenced by produce().

79  {
80  // Current time to be compared with the one read from the payload
81  auto currentTime =
82  std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch());
83 
84  // Get two beamspot creation times and compute the time difference wrt currentTime
85  auto bs1time = std::chrono::microseconds(bs1->creationTime());
86  auto diffBStime1 = (currentTime - bs1time).count();
87  auto bs2time = std::chrono::microseconds(bs2->creationTime());
88  auto diffBStime2 = (currentTime - bs2time).count();
89 
90  // Convert timeThreshold_ from hours to microseconds for comparison
91  auto limitTime = std::chrono::microseconds((std::chrono::hours)timeThreshold_).count();
92 
93  // Logic to choose between the two BeamSpots:
94  // 1. If both BS are older than limitTime retun fake BS
95  // 2. If only one BS is newer than limitTime return it only if
96  // it passes isGoodBS (checks on sigmaZ, sigmaXY and fit convergence)
97  // 3. If both are newer than the limit threshold return the BS that
98  // passes isGoodBS and has larger sigmaZ
99  if (diffBStime1 > limitTime && diffBStime2 > limitTime) {
100  edm::LogWarning("OnlineBeamSpotESProducer")
101  << "Defaulting to fake (fallback to PCL) because both payloads are too old.";
102  return nullptr;
103  } else if (diffBStime2 > limitTime) {
104  if (isGoodBS(bs1)) {
105  return bs1;
106  } else {
107  edm::LogWarning("OnlineBeamSpotESProducer") << "Defaulting to fake (fallback to PCL) because the legacy Beam "
108  "Spot is not suitable and HLT one is too old.";
109  return nullptr;
110  }
111  } else if (diffBStime1 > limitTime) {
112  if (isGoodBS(bs2)) {
113  return bs2;
114  } else {
115  edm::LogWarning("OnlineBeamSpotESProducer") << "Defaulting to fake (fallback to PCL) because the HLT Beam Spot "
116  "is not suitable and the legacy one too old.";
117  return nullptr;
118  }
119  } else {
120  if (bs1->sigmaZ() > bs2->sigmaZ() && isGoodBS(bs1)) {
121  return bs1;
122  } else if (bs2->sigmaZ() >= bs1->sigmaZ() && isGoodBS(bs2)) {
123  return bs2;
124  } else {
125  edm::LogWarning("OnlineBeamSpotESProducer") << "Defaulting to fake (fallback to PCL) because despite both "
126  "payloads are young enough, none has passed the fit sanity checks";
127  return nullptr;
128  }
129  }
130 }
cond::Time_t creationTime() const
bool isGoodBS(const BeamSpotOnlineObjects *bs1) const
double sigmaZ() const
get sigma Z, RMS bunch length
Log< level::Warning, false > LogWarning

◆ fillDescriptions()

void OnlineBeamSpotESProducer::fillDescriptions ( edm::ConfigurationDescriptions desc)
static

Definition at line 70 of file OnlineBeamSpotESProducer.cc.

References edm::ParameterSetDescription::add(), submitPVResolutionJobs::desc, and edm::ParameterDescriptionNode::setComment().

70  {
72  dsc.add<int>("timeThreshold", 48)->setComment("hours");
73  dsc.add<double>("sigmaZThreshold", 2.)->setComment("cm");
74  dsc.add<double>("sigmaXYThreshold", 4.)->setComment("um");
75  desc.addWithDefaultLabel(dsc);
76 }
void setComment(std::string const &value)
ParameterDescriptionBase * add(U const &iLabel, T const &value)

◆ isGoodBS()

bool OnlineBeamSpotESProducer::isGoodBS ( const BeamSpotOnlineObjects bs1) const
private

Definition at line 153 of file OnlineBeamSpotESProducer.cc.

References BeamSpotObjects::beamType(), BeamSpotObjects::beamWidthX(), BeamSpotObjects::beamWidthY(), sigmaXYThreshold_, BeamSpotObjects::sigmaZ(), sigmaZThreshold_, and reco::BeamSpot::Tracker.

Referenced by checkSingleBS(), and compareBS().

153  {
154  if (bs1->sigmaZ() > sigmaZThreshold_ && bs1->beamType() == reco::BeamSpot::Tracker &&
156  return true;
157  else
158  return false;
159 }
double beamWidthX() const
get average transverse beam width
int beamType() const
get beam type
double beamWidthY() const
get average transverse beam width
double sigmaZ() const
get sigma Z, RMS bunch length

◆ produce()

std::shared_ptr< const BeamSpotObjects > OnlineBeamSpotESProducer::produce ( const BeamSpotTransientObjectsRcd iRecord)

Definition at line 161 of file OnlineBeamSpotESProducer.cc.

References bsHLTToken_, bsLegacyToken_, checkSingleBS(), compareBS(), fakeBS_, and edm::eventsetup::DependentRecordImplementation< RecordT, ListT >::tryToGetRecord().

161  {
162  auto legacyRec = iRecord.tryToGetRecord<BeamSpotOnlineLegacyObjectsRcd>();
163  auto hltRec = iRecord.tryToGetRecord<BeamSpotOnlineHLTObjectsRcd>();
164  if (not legacyRec and not hltRec) {
165  edm::LogWarning("OnlineBeamSpotESProducer")
166  << "None of the Beam Spots in ES are available! \n returning a fake one (fallback to PCL).";
167  return std::shared_ptr<const BeamSpotObjects>(&fakeBS_, edm::do_nothing_deleter());
168  }
169 
171  if (legacyRec and hltRec) {
172  best = compareBS(&legacyRec->get(bsLegacyToken_), &hltRec->get(bsHLTToken_));
173  } else if (legacyRec) {
174  best = checkSingleBS(&legacyRec->get(bsLegacyToken_));
175  } else {
176  best = checkSingleBS(&hltRec->get(bsHLTToken_));
177  }
178  if (best) {
179  return std::shared_ptr<const BeamSpotObjects>(best, edm::do_nothing_deleter());
180  }
181  edm::LogWarning("OnlineBeamSpotESProducer")
182  << "None of the Online BeamSpots in the ES is suitable, \n returning a fake one(fallback to PCL).";
183  return std::shared_ptr<const BeamSpotObjects>(&fakeBS_, edm::do_nothing_deleter());
184 }
const BeamSpotOnlineObjects * checkSingleBS(const BeamSpotOnlineObjects *bs1)
edm::ESGetToken< BeamSpotOnlineObjects, BeamSpotOnlineHLTObjectsRcd > bsHLTToken_
const BeamSpotOnlineObjects * compareBS(const BeamSpotOnlineObjects *bs1, const BeamSpotOnlineObjects *bs2)
edm::ESGetToken< BeamSpotOnlineObjects, BeamSpotOnlineLegacyObjectsRcd > bsLegacyToken_
Log< level::Warning, false > LogWarning

Member Data Documentation

◆ bsHLTToken_

edm::ESGetToken<BeamSpotOnlineObjects, BeamSpotOnlineHLTObjectsRcd> OnlineBeamSpotESProducer::bsHLTToken_
private

Definition at line 36 of file OnlineBeamSpotESProducer.cc.

Referenced by OnlineBeamSpotESProducer(), and produce().

◆ bsLegacyToken_

edm::ESGetToken<BeamSpotOnlineObjects, BeamSpotOnlineLegacyObjectsRcd> OnlineBeamSpotESProducer::bsLegacyToken_
private

Definition at line 37 of file OnlineBeamSpotESProducer.cc.

Referenced by OnlineBeamSpotESProducer(), and produce().

◆ bsToken_

edm::ESGetToken<BeamSpotObjects, BeamSpotTransientObjectsRcd> const OnlineBeamSpotESProducer::bsToken_
private

Definition at line 35 of file OnlineBeamSpotESProducer.cc.

◆ fakeBS_

BeamSpotObjects OnlineBeamSpotESProducer::fakeBS_
private

Definition at line 39 of file OnlineBeamSpotESProducer.cc.

Referenced by OnlineBeamSpotESProducer(), and produce().

◆ sigmaXYThreshold_

const double OnlineBeamSpotESProducer::sigmaXYThreshold_
private

Definition at line 42 of file OnlineBeamSpotESProducer.cc.

Referenced by isGoodBS().

◆ sigmaZThreshold_

const double OnlineBeamSpotESProducer::sigmaZThreshold_
private

Definition at line 41 of file OnlineBeamSpotESProducer.cc.

Referenced by isGoodBS().

◆ timeThreshold_

const int OnlineBeamSpotESProducer::timeThreshold_
private

Definition at line 40 of file OnlineBeamSpotESProducer.cc.

Referenced by checkSingleBS(), and compareBS().