Skip to content

Commit

Permalink
Adding a check on the BS transverse widths in OnlineBeamSpotESProducer
Browse files Browse the repository at this point in the history
  • Loading branch information
dzuolo committed Feb 10, 2023
1 parent 2f899a2 commit 16999c1
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions RecoVertex/BeamSpotProducer/plugins/OnlineBeamSpotESProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class OnlineBeamSpotESProducer : public edm::ESProducer {
private:
const BeamSpotOnlineObjects* compareBS(const BeamSpotOnlineObjects* bs1, const BeamSpotOnlineObjects* bs2);
const BeamSpotOnlineObjects* checkSingleBS(const BeamSpotOnlineObjects* bs1);
const bool isGoodBS(const BeamSpotOnlineObjects* bs1);

edm::ESGetToken<BeamSpotObjects, BeamSpotTransientObjectsRcd> const bsToken_;
edm::ESGetToken<BeamSpotOnlineObjects, BeamSpotOnlineHLTObjectsRcd> bsHLTToken_;
Expand All @@ -38,12 +39,14 @@ class OnlineBeamSpotESProducer : public edm::ESProducer {
BeamSpotObjects fakeBS_;
const int timeThreshold_;
const double sigmaZThreshold_;
const double sigmaXYThreshold_;
};

OnlineBeamSpotESProducer::OnlineBeamSpotESProducer(const edm::ParameterSet& p)
// get parameters
: timeThreshold_(p.getParameter<int>("timeThreshold")),
sigmaZThreshold_(p.getParameter<double>("sigmaZThreshold")) {
sigmaZThreshold_(p.getParameter<double>("sigmaZThreshold")),
sigmaXYThreshold_(p.getParameter<double>("sigmaXYThreshold")) {
auto cc = setWhatProduced(this);

fakeBS_.setBeamWidthX(0.1);
Expand All @@ -60,6 +63,7 @@ void OnlineBeamSpotESProducer::fillDescriptions(edm::ConfigurationDescriptions&
edm::ParameterSetDescription dsc;
dsc.add<int>("timeThreshold", 48)->setComment("hours");
dsc.add<double>("sigmaZThreshold", 2.)->setComment("cm");
dsc.add<double>("sigmaXYThreshold", 4.)->setComment("um");
desc.addWithDefaultLabel(dsc);
}

Expand All @@ -80,33 +84,33 @@ const BeamSpotOnlineObjects* OnlineBeamSpotESProducer::compareBS(const BeamSpotO

// Logic to choose between the two BeamSpots:
// 1. If both BS are older than limitTime retun fake BS
// 2. If only one BS is newer than limitTime return it only if it has
// sigmaZ larger than sigmaZthreshold_ and the fit converged (BeamType 2)
// 3. If both are newer than the limit threshold return
// the BS that converged and has larger sigmaZ
// 2. If only one BS is newer than limitTime return it only if
// it passes isGoodBS (checks on sigmaZ, sigmaXY and fit convergence)
// 3. If both are newer than the limit threshold return the BS that
// passes isGoodBS and has larger sigmaZ
if (diffBStime1 > limitTime && diffBStime2 > limitTime) {
edm::LogInfo("OnlineBeamSpotESProducer") << "Defaulting to fake because both payloads are too old.";
return nullptr;
} else if (diffBStime2 > limitTime) {
if (bs1->sigmaZ() > sigmaZThreshold_ && bs1->beamType() == 2) {
if (isGoodBS(bs1)) {
return bs1;
} else {
edm::LogInfo("OnlineBeamSpotESProducer")
<< "Defaulting to fake because the legacy Beam Spot is not suitable and HLT one is too old.";
return nullptr;
}
} else if (diffBStime1 > limitTime) {
if (bs2->sigmaZ() > sigmaZThreshold_ && bs2->beamType() == 2) {
if (isGoodBS(bs2)) {
return bs2;
} else {
edm::LogInfo("OnlineBeamSpotESProducer")
<< "Defaulting to fake because the HLT Beam Spot is not suitable and the legacy one too old.";
return nullptr;
}
} else {
if (bs1->sigmaZ() > bs2->sigmaZ() && bs1->beamType() == 2) {
if (bs1->sigmaZ() > bs2->sigmaZ() && isGoodBS(bs1)) {
return bs1;
} else if (bs2->sigmaZ() >= bs1->sigmaZ() && bs2->beamType() == 2) {
} else if (bs2->sigmaZ() >= bs1->sigmaZ() && isGoodBS(bs2)) {
return bs2;
} else {
edm::LogInfo("OnlineBeamSpotESProducer")
Expand All @@ -129,13 +133,22 @@ const BeamSpotOnlineObjects* OnlineBeamSpotESProducer::checkSingleBS(const BeamS
auto limitTime = std::chrono::microseconds((std::chrono::hours)timeThreshold_).count();

// Check that the BS is within the timeThreshold, converges and passes the sigmaZthreshold
if (diffBStime1 < limitTime && bs1->sigmaZ() > sigmaZThreshold_ && bs1->beamType() == 2) {
if (diffBStime1 < limitTime && isGoodBS(bs1)) {
return bs1;
} else {
return nullptr;
}
}

// This method is used to check the quality of the beamspot fit
const bool OnlineBeamSpotESProducer::isGoodBS(const BeamSpotOnlineObjects* bs1) {
if (bs1->sigmaZ() > sigmaZThreshold_ && bs1->beamType() == 2 && bs1->beamWidthX() > sigmaXYThreshold_ * 1E-4 &&
bs1->beamWidthY() > sigmaXYThreshold_ * 1E-4)
return true;
else
return false;
}

std::shared_ptr<const BeamSpotObjects> OnlineBeamSpotESProducer::produce(const BeamSpotTransientObjectsRcd& iRecord) {
auto legacyRec = iRecord.tryToGetRecord<BeamSpotOnlineLegacyObjectsRcd>();
auto hltRec = iRecord.tryToGetRecord<BeamSpotOnlineHLTObjectsRcd>();
Expand Down

0 comments on commit 16999c1

Please sign in to comment.