Skip to content

Commit

Permalink
Merge pull request #35333 from francescobrivio/alca-BeamSpotOnline_lo…
Browse files Browse the repository at this point in the history
…gic_12_1_X

Add logic in OnlineBeamSpotESProducer
  • Loading branch information
cmsbuild committed Sep 23, 2021
2 parents a346606 + 19fc9ec commit f2ab957
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 36 deletions.
75 changes: 66 additions & 9 deletions RecoVertex/BeamSpotProducer/plugins/OnlineBeamSpotESProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,21 @@ class OnlineBeamSpotESProducer : public edm::ESProducer {

private:
const BeamSpotOnlineObjects* compareBS(const BeamSpotOnlineObjects* bs1, const BeamSpotOnlineObjects* bs2);
BeamSpotObjects fakeBS_;
const BeamSpotOnlineObjects* checkSingleBS(const BeamSpotOnlineObjects* bs1);

edm::ESGetToken<BeamSpotObjects, BeamSpotTransientObjectsRcd> const bsToken_;
edm::ESGetToken<BeamSpotOnlineObjects, BeamSpotOnlineHLTObjectsRcd> bsHLTToken_;
edm::ESGetToken<BeamSpotOnlineObjects, BeamSpotOnlineLegacyObjectsRcd> bsLegacyToken_;

BeamSpotObjects fakeBS_;
const int timeThreshold_;
const double sigmaZThreshold_;
};
OnlineBeamSpotESProducer::OnlineBeamSpotESProducer(const edm::ParameterSet& p) {

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

fakeBS_.SetBeamWidthX(0.1);
Expand All @@ -51,28 +59,77 @@ OnlineBeamSpotESProducer::OnlineBeamSpotESProducer(const edm::ParameterSet& p) {

void OnlineBeamSpotESProducer::fillDescriptions(edm::ConfigurationDescriptions& desc) {
edm::ParameterSetDescription dsc;
dsc.add<int>("timeThreshold", 48)->setComment("hours");
dsc.add<double>("sigmaZThreshold", 2.)->setComment("cm");
desc.addWithDefaultLabel(dsc);
}

const BeamSpotOnlineObjects* OnlineBeamSpotESProducer::compareBS(const BeamSpotOnlineObjects* bs1,
const BeamSpotOnlineObjects* bs2) {
//Random logic so far ...
if (bs1->GetSigmaZ() - 0.0001 > bs2->GetSigmaZ()) { //just temporary for debugging
if (bs1->GetSigmaZ() > 2.5) {
// Current time to be compared with the one read from the payload
auto currentTime =
std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch());

// Get two beamspot creation times and compute the time difference wrt currentTime
auto bs1time = std::chrono::microseconds(bs1->GetCreationTime());
auto diffBStime1 = (currentTime - bs1time).count();
auto bs2time = std::chrono::microseconds(bs2->GetCreationTime());
auto diffBStime2 = (currentTime - bs2time).count();

// Convert timeThreshold_ from hours to microseconds for comparison
auto limitTime = std::chrono::microseconds((std::chrono::hours)timeThreshold_).count();

// 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
if (diffBStime1 > limitTime && diffBStime2 > limitTime) {
return nullptr;
} else if (diffBStime2 > limitTime) {
if (bs1->GetSigmaZ() > sigmaZThreshold_ && bs1->GetBeamType() == 2) {
return bs1;
} else {
return nullptr;
}

} else if (diffBStime1 > limitTime) {
if (bs2->GetSigmaZ() > sigmaZThreshold_ && bs2->GetBeamType() == 2) {
return bs2;
} else {
return nullptr;
}
} else {
if (bs2->GetSigmaZ() > 2.5) {
if (bs1->GetSigmaZ() > bs2->GetSigmaZ() && bs1->GetBeamType() == 2) {
return bs1;
} else if (bs2->GetSigmaZ() > bs1->GetSigmaZ() && bs2->GetBeamType() == 2) {
return bs2;
} else {
return nullptr;
}
}
}

const BeamSpotOnlineObjects* OnlineBeamSpotESProducer::checkSingleBS(const BeamSpotOnlineObjects* bs1) {
// Current time to be compared with the one read from the payload
auto currentTime =
std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch());

// Get the beamspot creation time and compute the time difference wrt currentTime
auto bs1time = std::chrono::microseconds(bs1->GetCreationTime());
auto diffBStime1 = (currentTime - bs1time).count();

// Convert timeThreshold_ from hours to microseconds for comparison
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->GetSigmaZ() > sigmaZThreshold_ && bs1->GetBeamType() == 2) {
return bs1;
} else {
return nullptr;
}
}

std::shared_ptr<const BeamSpotObjects> OnlineBeamSpotESProducer::produce(const BeamSpotTransientObjectsRcd& iRecord) {
auto legacyRec = iRecord.tryToGetRecord<BeamSpotOnlineLegacyObjectsRcd>();
auto hltRec = iRecord.tryToGetRecord<BeamSpotOnlineHLTObjectsRcd>();
Expand All @@ -84,9 +141,9 @@ std::shared_ptr<const BeamSpotObjects> OnlineBeamSpotESProducer::produce(const B
if (legacyRec and hltRec) {
best = compareBS(&legacyRec->get(bsLegacyToken_), &hltRec->get(bsHLTToken_));
} else if (legacyRec) {
best = &legacyRec->get(bsLegacyToken_);
best = checkSingleBS(&legacyRec->get(bsLegacyToken_));
} else {
best = &hltRec->get(bsHLTToken_);
best = checkSingleBS(&hltRec->get(bsHLTToken_));
}
if (best) {
return std::shared_ptr<const BeamSpotObjects>(best, edm::do_nothing_deleter());
Expand Down
3 changes: 2 additions & 1 deletion RecoVertex/BeamSpotProducer/python/BeamSpotOnline_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from RecoVertex.BeamSpotProducer.BeamSpotOnline_cfi import *

#scalers = cms.EDProducer('ScalersRawToDigi')
BeamSpotESProducer = cms.ESProducer("OnlineBeamSpotESProducer")
import RecoVertex.BeamSpotProducer.onlineBeamSpotESProducer_cfi as _mod
BeamSpotESProducer = _mod.onlineBeamSpotESProducer.clone()

from Configuration.Eras.Modifier_run3_common_cff import run3_common
run3_common.toModify(onlineBeamSpotProducer, useTransientRecord = True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

process.source = cms.Source("PoolSource",
fileNames = cms.untracked.vstring(
"file:/eos/cms/store/data/Commissioning2021/Cosmics/RAW/v1/000/342/218/00000/fdaf9009-dfd8-4774-9246-556088e65e9b.root",
"file:/eos/cms/store/data/Commissioning2021/Cosmics/RAW/v1/000/342/094/00000/7e88d2e8-6632-40f0-a1ca-4350adf60182.root"
"file:/eos/cms/store/data/Commissioning2021/Cosmics/RAW/v1/000/344/518/00000/00130ffc-3e69-4106-8151-c69dd735ee2e.root",
"file:/eos/cms/store/data/Commissioning2021/Cosmics/RAW/v1/000/344/518/00000/001d10b6-a19e-4889-ba07-88f8f6b17bc7.root"
),
skipEvents = cms.untracked.uint32(0) )

Expand All @@ -17,31 +17,23 @@

process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(-1)
)
process.load("CondCore.DBCommon.CondDBSetup_cfi")
)
process.load("CondCore.CondDB.CondDB_cfi")

from Configuration.AlCa.GlobalTag import GlobalTag as customiseGlobalTag
process.GlobalTag = customiseGlobalTag(globaltag = "auto:run3_hlt_GRun")

process.BeamSpotDBSource = cms.ESSource("PoolDBESSource",
process.CondDBSetup,
toGet = cms.VPSet(
cms.PSet(
record = cms.string('BeamSpotOnlineLegacyObjectsRcd'),
tag = cms.string("BeamSpotOnlineTestLegacy"),
refreshTime = cms.uint64(1)

),
cms.PSet(
record = cms.string('BeamSpotOnlineHLTObjectsRcd'),
tag = cms.string('BeamSpotOnlineTestHLT'),
refreshTime = cms.uint64(1)
)

),
#connect = cms.string('oracle://cms_orcon_prod/CMS_CONDITIONS')
connect = cms.string('frontier://FrontierProd/CMS_CONDITIONS')
process.GlobalTag.toGet = cms.VPSet(
cms.PSet(
record = cms.string("BeamSpotOnlineLegacyObjectsRcd"),
refreshTime = cms.uint64(1)
),
cms.PSet(
record = cms.string("BeamSpotOnlineHLTObjectsRcd"),
refreshTime = cms.uint64(1)
)
)

process.MessageLogger = cms.Service("MessageLogger",
cerr = cms.untracked.PSet(
enable = cms.untracked.bool(False)
Expand All @@ -52,8 +44,6 @@
)
)

process.scalersRawToDigi = cms.EDProducer('ScalersRawToDigi')

process.load("RecoVertex.BeamSpotProducer.BeamSpotOnline_cff")
#process.onlineBeamSpotProducer.useTransientRecord = cms.bool(False)

Expand All @@ -64,7 +54,6 @@
)
)

process.dtRawDump = cms.Path(process.scalersRawToDigi + process.onlineBeamSpot )
#process.dtRawDump = cms.Path( process.onlineBeamSpot )
process.dtRawDump = cms.Path( process.onlineBeamSpot )

process.e = cms.EndPath( process.out )

0 comments on commit f2ab957

Please sign in to comment.