-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30965 from MilanoBicocca-pix/BSESProducer_11_2_X
Online BeamSpot ESProducer for Run3 workflow
- Loading branch information
Showing
6 changed files
with
272 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
RecoVertex/BeamSpotProducer/plugins/OfflineToTransientBeamSpotESProducer.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include "CondFormats/DataRecord/interface/BeamSpotObjectsRcd.h" | ||
#include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h" | ||
#include "CondFormats/DataRecord/interface/BeamSpotTransientObjectsRcd.h" | ||
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" | ||
#include "FWCore/Framework/interface/ESProductHost.h" | ||
#include "FWCore/Utilities/interface/ReusableObjectHolder.h" | ||
#include "FWCore/Framework/interface/ESProducer.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
|
||
#include "FWCore/Framework/interface/EventSetup.h" | ||
#include "FWCore/Framework/interface/ESHandle.h" | ||
#include "FWCore/Framework/interface/ModuleFactory.h" | ||
#include "FWCore/Framework/interface/ESProducer.h" | ||
#include "FWCore/Utilities/interface/do_nothing_deleter.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" | ||
|
||
#include <iostream> | ||
#include <memory> | ||
#include <string> | ||
|
||
using namespace edm; | ||
class OfflineToTransientBeamSpotESProducer : public edm::ESProducer { | ||
public: | ||
OfflineToTransientBeamSpotESProducer(const edm::ParameterSet& p); | ||
std::shared_ptr<const BeamSpotObjects> produce(const BeamSpotTransientObjectsRcd&); | ||
static void fillDescriptions(edm::ConfigurationDescriptions& desc); | ||
|
||
private: | ||
const BeamSpotObjects dummyBS_; | ||
edm::ESGetToken<BeamSpotObjects, BeamSpotTransientObjectsRcd> const bsToken_; | ||
edm::ESGetToken<BeamSpotObjects, BeamSpotObjectsRcd> bsOfflineToken_; | ||
}; | ||
|
||
OfflineToTransientBeamSpotESProducer::OfflineToTransientBeamSpotESProducer(const edm::ParameterSet& p) { | ||
auto cc = setWhatProduced(this); | ||
|
||
bsOfflineToken_ = cc.consumesFrom<BeamSpotObjects, BeamSpotObjectsRcd>(); | ||
} | ||
|
||
void OfflineToTransientBeamSpotESProducer::fillDescriptions(edm::ConfigurationDescriptions& desc) { | ||
edm::ParameterSetDescription dsc; | ||
desc.addWithDefaultLabel(dsc); | ||
} | ||
std::shared_ptr<const BeamSpotObjects> OfflineToTransientBeamSpotESProducer::produce( | ||
const BeamSpotTransientObjectsRcd& iRecord) { | ||
auto optionalRec = iRecord.tryToGetRecord<BeamSpotObjectsRcd>(); | ||
if (not optionalRec) { | ||
return std::shared_ptr<const BeamSpotObjects>(&dummyBS_, edm::do_nothing_deleter()); | ||
} | ||
return std::shared_ptr<const BeamSpotObjects>(&optionalRec->get(bsOfflineToken_), edm::do_nothing_deleter()); | ||
}; | ||
|
||
DEFINE_FWK_EVENTSETUP_MODULE(OfflineToTransientBeamSpotESProducer); |
94 changes: 94 additions & 0 deletions
94
RecoVertex/BeamSpotProducer/plugins/OnlineBeamSpotESProducer.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#include "FWCore/Framework/interface/EventSetup.h" | ||
#include "FWCore/Framework/interface/ESHandle.h" | ||
#include "FWCore/Framework/interface/ModuleFactory.h" | ||
#include "FWCore/Framework/interface/ESProducer.h" | ||
#include "FWCore/Utilities/interface/do_nothing_deleter.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" | ||
#include "DataFormats/BeamSpot/interface/BeamSpot.h" | ||
#include "CondFormats/DataRecord/interface/BeamSpotObjectsRcd.h" | ||
#include "CondFormats/BeamSpotObjects/interface/BeamSpotOnlineObjects.h" | ||
#include "CondFormats/DataRecord/interface/BeamSpotOnlineLegacyObjectsRcd.h" | ||
#include "CondFormats/DataRecord/interface/BeamSpotOnlineHLTObjectsRcd.h" | ||
#include "CondFormats/DataRecord/interface/BeamSpotTransientObjectsRcd.h" | ||
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" | ||
|
||
#include "FWCore/Framework/interface/ESProductHost.h" | ||
#include "FWCore/Utilities/interface/ReusableObjectHolder.h" | ||
#include "FWCore/Framework/interface/ESProducer.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include <memory> | ||
#include <iostream> | ||
#include <string> | ||
|
||
using namespace edm; | ||
|
||
class OnlineBeamSpotESProducer : public edm::ESProducer { | ||
public: | ||
OnlineBeamSpotESProducer(const edm::ParameterSet& p); | ||
std::shared_ptr<const BeamSpotObjects> produce(const BeamSpotTransientObjectsRcd&); | ||
static void fillDescriptions(edm::ConfigurationDescriptions& desc); | ||
|
||
private: | ||
const BeamSpotOnlineObjects* compareBS(const BeamSpotOnlineObjects* bs1, const BeamSpotOnlineObjects* bs2); | ||
BeamSpotObjects fakeBS_; | ||
|
||
edm::ESGetToken<BeamSpotObjects, BeamSpotTransientObjectsRcd> const bsToken_; | ||
edm::ESGetToken<BeamSpotOnlineObjects, BeamSpotOnlineHLTObjectsRcd> bsHLTToken_; | ||
edm::ESGetToken<BeamSpotOnlineObjects, BeamSpotOnlineLegacyObjectsRcd> bsLegacyToken_; | ||
}; | ||
OnlineBeamSpotESProducer::OnlineBeamSpotESProducer(const edm::ParameterSet& p) { | ||
auto cc = setWhatProduced(this); | ||
|
||
fakeBS_.SetBeamWidthX(0.1); | ||
fakeBS_.SetBeamWidthY(0.1); | ||
fakeBS_.SetSigmaZ(15.); | ||
fakeBS_.SetPosition(0., 0., 0.); | ||
fakeBS_.SetType(-1); | ||
|
||
bsHLTToken_ = cc.consumesFrom<BeamSpotOnlineObjects, BeamSpotOnlineHLTObjectsRcd>(); | ||
bsLegacyToken_ = cc.consumesFrom<BeamSpotOnlineObjects, BeamSpotOnlineLegacyObjectsRcd>(); | ||
} | ||
|
||
void OnlineBeamSpotESProducer::fillDescriptions(edm::ConfigurationDescriptions& desc) { | ||
edm::ParameterSetDescription dsc; | ||
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() > 5.) { | ||
return bs1; | ||
} else { | ||
return bs2; | ||
} | ||
|
||
} else { | ||
if (bs2->GetSigmaZ() > 5.) { | ||
return bs2; | ||
} else { | ||
return bs1; | ||
} | ||
} | ||
} | ||
|
||
std::shared_ptr<const BeamSpotObjects> OnlineBeamSpotESProducer::produce(const BeamSpotTransientObjectsRcd& iRecord) { | ||
auto legacyRec = iRecord.tryToGetRecord<BeamSpotOnlineLegacyObjectsRcd>(); | ||
auto hltRec = iRecord.tryToGetRecord<BeamSpotOnlineHLTObjectsRcd>(); | ||
if (not legacyRec and not hltRec) { | ||
return std::shared_ptr<const BeamSpotObjects>(&fakeBS_, edm::do_nothing_deleter()); | ||
} | ||
|
||
const BeamSpotOnlineObjects* best; | ||
if (legacyRec and hltRec) { | ||
best = compareBS(&legacyRec->get(bsLegacyToken_), &hltRec->get(bsHLTToken_)); | ||
} else if (legacyRec) { | ||
best = &legacyRec->get(bsLegacyToken_); | ||
} else { | ||
best = &hltRec->get(bsHLTToken_); | ||
} | ||
return std::shared_ptr<const BeamSpotObjects>(best, edm::do_nothing_deleter()); | ||
}; | ||
|
||
DEFINE_FWK_EVENTSETUP_MODULE(OnlineBeamSpotESProducer); |
56 changes: 56 additions & 0 deletions
56
RecoVertex/BeamSpotProducer/plugins/OnlineBeamSpotFromDB.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/**_________________________________________________________________ | ||
class: OnlineBeamSpotFromDB.cc | ||
package: RecoVertex/BeamSpotProducer | ||
author: Francisco Yumiceva, Fermilab (yumiceva@fnal.gov) | ||
________________________________________________________________**/ | ||
|
||
#include "DataFormats/BeamSpot/interface/BeamSpot.h" | ||
#include "FWCore/MessageLogger/interface/MessageLogger.h" | ||
#include "FWCore/Framework/interface/MakerMacros.h" | ||
#include "FWCore/ServiceRegistry/interface/Service.h" | ||
#include "FWCore/Framework/interface/ESHandle.h" | ||
#include "FWCore/Framework/interface/EventSetup.h" | ||
#include "FWCore/Framework/interface/IOVSyncValue.h" | ||
#include "CondFormats/DataRecord/interface/BeamSpotTransientObjectsRcd.h" | ||
#include "CondFormats/BeamSpotObjects/interface/BeamSpotOnlineObjects.h" | ||
#include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" | ||
#include "FWCore/Framework/interface/Frameworkfwd.h" | ||
#include "FWCore/Framework/interface/ConsumesCollector.h" | ||
#include "FWCore/Framework/interface/one/EDAnalyzer.h" | ||
#include "FWCore/Framework/interface/Event.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" | ||
#include <string> | ||
|
||
class OnlineBeamSpotFromDB : public edm::one::EDAnalyzer<> { | ||
public: | ||
explicit OnlineBeamSpotFromDB(const edm::ParameterSet& iConfig); | ||
static void fillDescriptions(edm::ConfigurationDescriptions& desc); | ||
edm::ESGetToken<BeamSpotObjects, BeamSpotTransientObjectsRcd> bsToken_; | ||
|
||
private: | ||
void analyze(const edm::Event&, const edm::EventSetup&) override; | ||
}; | ||
|
||
OnlineBeamSpotFromDB::OnlineBeamSpotFromDB(const edm::ParameterSet& iConfig) | ||
: bsToken_(esConsumes<BeamSpotObjects, BeamSpotTransientObjectsRcd>()) {} | ||
|
||
void OnlineBeamSpotFromDB::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { | ||
auto const& mybeamspot = iSetup.getData(bsToken_); | ||
|
||
edm::LogInfo("Run numver: ") << iEvent.id().run(); | ||
edm::LogInfo("beamspot from HLT ") << mybeamspot; | ||
} | ||
void OnlineBeamSpotFromDB::fillDescriptions(edm::ConfigurationDescriptions& desc) { | ||
edm::ParameterSetDescription dsc; | ||
desc.addWithDefaultLabel(dsc); | ||
} | ||
|
||
//define this as a plug-in | ||
DEFINE_FWK_MODULE(OnlineBeamSpotFromDB); |
55 changes: 55 additions & 0 deletions
55
RecoVertex/BeamSpotProducer/test/readOnlineBeamSpotFromDB.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import FWCore.ParameterSet.Config as cms | ||
|
||
process = cms.Process("readDB") | ||
process.load("FWCore.MessageLogger.MessageLogger_cfi") | ||
|
||
|
||
process.load("CondCore.DBCommon.CondDBSetup_cfi") | ||
|
||
|
||
tesOnLineESProducer = True | ||
|
||
if tesOnLineESProducer: | ||
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('BSOnLineHLT_tag'), | ||
# refreshTime = cms.uint64(1) | ||
# ) | ||
|
||
), | ||
connect = cms.string('oracle://cms_orcon_prod/CMS_CONDITIONS') | ||
|
||
) | ||
process.BeamSpotESProducer = cms.ESProducer("OnlineBeamSpotESProducer") | ||
|
||
else: | ||
from Configuration.AlCa.GlobalTag import GlobalTag as customiseGlobalTag | ||
process.GlobalTag = customiseGlobalTag(globaltag = "auto:run3_hlt_GRun") | ||
process.BeamSpotESProducer = cms.ESProducer("OfflineToTransientBeamSpotESProducer") | ||
|
||
|
||
process.MessageLogger.destinations = cms.untracked.vstring('detailedInfo') | ||
process.MessageLogger.detailedInfo = cms.untracked.PSet(threshold = cms.untracked.string('INFO')) | ||
|
||
process.source = cms.Source("EmptySource") | ||
process.source.numberEventsInRun=cms.untracked.uint32(2) | ||
process.source.firstRun = cms.untracked.uint32(336365) | ||
process.source.firstLuminosityBlock = cms.untracked.uint32(13) | ||
process.source.numberEventsInLuminosityBlock = cms.untracked.uint32(1) | ||
process.maxEvents = cms.untracked.PSet( | ||
input = cms.untracked.int32(5) | ||
) | ||
process.beamspot = cms.EDAnalyzer("OnlineBeamSpotFromDB") | ||
|
||
|
||
process.p = cms.Path(process.beamspot) | ||
|