Skip to content

Commit

Permalink
Merge pull request #30503 from MilanoBicocca-pix/BSforOnlineHLT_PR2_b…
Browse files Browse the repository at this point in the history
…ackport_11_1_0

BeamSpotOnline in DQM beamspot clients - backport to 11_1_X
  • Loading branch information
cmsbuild authored Jul 9, 2020
2 parents dbcfbe5 + 80ae024 commit 6429d1f
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 0 deletions.
40 changes: 40 additions & 0 deletions DQM/BeamMonitor/plugins/BeamMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ V00-03-25
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Common/interface/TriggerNames.h"
#include "DataFormats/HLTReco/interface/TriggerEvent.h"
#include "CondFormats/BeamSpotObjects/interface/BeamSpotOnlineObjects.h"
#include "CondCore/DBOutputService/interface/OnlineDBOutputService.h"
#include <numeric>
#include <cmath>
#include <memory>
Expand Down Expand Up @@ -116,6 +118,7 @@ BeamMonitor::BeamMonitor(const ParameterSet& ps)
firstAverageFit_(0),
countGapLumi_(0) {
monitorName_ = ps.getUntrackedParameter<string>("monitorName", "YourSubsystemName");
recordName_ = ps.getUntrackedParameter<string>("recordName");
bsSrc_ = consumes<reco::BeamSpot>(ps.getUntrackedParameter<InputTag>("beamSpot"));
tracksLabel_ = consumes<reco::TrackCollection>(
ps.getParameter<ParameterSet>("BeamFitter").getUntrackedParameter<InputTag>("TrackCollection"));
Expand Down Expand Up @@ -1324,6 +1327,43 @@ void BeamMonitor::FitAndFill(const LuminosityBlock& lumiSeg, int& lastlumi, int&
summaryContent_[2] += 1.;
// }

// Create the BeamSpotOnlineObjects object
BeamSpotOnlineObjects* BSOnline = new BeamSpotOnlineObjects();
BSOnline->SetLastAnalyzedLumi(fitLS.second);
BSOnline->SetLastAnalyzedRun(theBeamFitter->getRunNumber());
BSOnline->SetLastAnalyzedFill(0); // To be updated with correct LHC Fill number
BSOnline->SetPosition(bs.x0(), bs.y0(), bs.z0());
BSOnline->SetSigmaZ(bs.sigmaZ());
BSOnline->SetBeamWidthX(bs.BeamWidthX());
BSOnline->SetBeamWidthY(bs.BeamWidthY());
BSOnline->SetBeamWidthXError(bs.BeamWidthXError());
BSOnline->SetBeamWidthYError(bs.BeamWidthYError());
BSOnline->Setdxdz(bs.dxdz());
BSOnline->Setdydz(bs.dydz());
BSOnline->SetType(bs.type());
BSOnline->SetEmittanceX(bs.emittanceX());
BSOnline->SetEmittanceY(bs.emittanceY());
BSOnline->SetBetaStar(bs.betaStar());
for (int i = 0; i < 7; ++i) {
for (int j = 0; j < 7; ++j) {
BSOnline->SetCovariance(i, j, bs.covariance(i, j));
}
}
BSOnline->SetNumTracks(theBeamFitter->getNTracks());
BSOnline->SetNumPVs(theBeamFitter->getNPVs());

edm::LogInfo("BeamMonitor") << "FitAndFill::[PayloadCreation] BeamSpotOnline object created: \n" << std::endl;
edm::LogInfo("BeamMonitor") << *BSOnline << std::endl;

// Create the payload for BeamSpotOnlineObjects object
edm::Service<cond::service::OnlineDBOutputService> onlineDbService;
if (onlineDbService.isAvailable()) {
edm::LogInfo("BeamMonitor") << "FitAndFill::[PayloadCreation] onlineDbService available \n" << std::endl;
BSOnline->SetCreationTime(onlineDbService->currentTime());
onlineDbService->writeForNextLumisection(BSOnline, recordName_);
}
edm::LogInfo("BeamMonitor") << "FitAndFill::[PayloadCreation] BeamSpotOnline payload created \n" << std::endl;

} //if (theBeamFitter->runPVandTrkFitter())
else { // beam fit fails
reco::BeamSpot bs = theBeamFitter->getBeamSpot();
Expand Down
1 change: 1 addition & 0 deletions DQM/BeamMonitor/plugins/BeamMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class BeamMonitor : public DQMOneEDAnalyzer<edm::one::WatchLuminosityBlocks> {
const double dzMin_;
const double dzMax_;
std::string monitorName_;
std::string recordName_;
edm::EDGetTokenT<reco::BeamSpot> bsSrc_; // beam spot
edm::EDGetTokenT<reco::TrackCollection> tracksLabel_;
edm::EDGetTokenT<reco::VertexCollection> pvSrc_; // primary vertex
Expand Down
1 change: 1 addition & 0 deletions DQM/BeamMonitor/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<use name="RecoVertex/BeamSpotProducer"/>
<use name="DataFormats/VertexReco"/>
<use name="DataFormats/TrackerRecHit2D"/>
<use name="CondCore/DBOutputService"/>
<library file="BeamMonitor.cc" name="BeamMonitor">
<flags EDM_PLUGIN="1"/>
</library>
Expand Down
1 change: 1 addition & 0 deletions DQM/BeamMonitor/python/BeamMonitor_Cosmics_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
resetEveryNLumi = cms.untracked.int32(20),
resetPVEveryNLumi = cms.untracked.int32(2),
Debug = cms.untracked.bool(False),
recordName = cms.untracked.string('BeamSpotOnlineHLTObjectsRcd'),
BeamFitter = cms.PSet(
Debug = cms.untracked.bool(False),
TrackCollection = cms.untracked.InputTag('ctfWithMaterialTracksP5'), ## ctfWithMaterialTracksP5 for CRAFT
Expand Down
1 change: 1 addition & 0 deletions DQM/BeamMonitor/python/BeamMonitor_MC_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
fitPVEveryNLumi = cms.untracked.int32(1),
resetPVEveryNLumi = cms.untracked.int32(2),
Debug = cms.untracked.bool(False),
recordName = cms.untracked.string('BeamSpotOnlineHLTObjectsRcd'),
BeamFitter = cms.PSet(
Debug = cms.untracked.bool(False),
TrackCollection = cms.untracked.InputTag('generalTracks'), ## ctfWithMaterialTracksP5 for CRAFT
Expand Down
1 change: 1 addition & 0 deletions DQM/BeamMonitor/python/BeamMonitor_PixelLess_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
fitPVEveryNLumi = cms.untracked.int32(1),
resetPVEveryNLumi = cms.untracked.int32(2),
Debug = cms.untracked.bool(False),
recordName = cms.untracked.string('BeamSpotOnlineHLTObjectsRcd'),
BeamFitter = cms.PSet(
Debug = cms.untracked.bool(False),
TrackCollection = cms.untracked.InputTag('ctfPixelLess'),
Expand Down
1 change: 1 addition & 0 deletions DQM/BeamMonitor/python/BeamMonitor_Pixel_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
resetPVEveryNLumi = cms.untracked.int32(5),
Debug = cms.untracked.bool(False),
OnlineMode = cms.untracked.bool(True),
recordName = cms.untracked.string('BeamSpotOnlineHLTObjectsRcd'),
BeamFitter = cms.PSet(
Debug = cms.untracked.bool(False),
TrackCollection = cms.untracked.InputTag('pixelTracks'),
Expand Down
1 change: 1 addition & 0 deletions DQM/BeamMonitor/python/BeamMonitor_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
resetPVEveryNLumi = cms.untracked.int32(5),
Debug = cms.untracked.bool(False),
OnlineMode = cms.untracked.bool(True),
recordName = cms.untracked.string('BeamSpotOnlineHLTObjectsRcd'),
BeamFitter = cms.PSet(
Debug = cms.untracked.bool(False),
TrackCollection = cms.untracked.InputTag('generalTracks'),
Expand Down
44 changes: 44 additions & 0 deletions DQM/Integration/python/clients/beam_dqm_sourceclient-live_cfg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from __future__ import print_function
import FWCore.ParameterSet.Config as cms

# Define here the BeamSpotOnline record name,
# it will be used both in BeamMonitor setup and in payload creation/upload
BSOnlineRecordName = 'BeamSpotOnlineLegacyObjectsRcd'

#from Configuration.Eras.Era_Run2_2018_cff import Run2_2018
#process = cms.Process("BeamMonitor", Run2_2018) FIXME
import sys
Expand All @@ -24,14 +28,23 @@
live=False
unitTest=True

# Switch to veto the upload of the BeamSpot conditions to the DB
# when False it performs the upload
noDB = True
if 'noDB=False' in sys.argv:
noDB=False

#---------------
# Input sources
if unitTest:
process.load("DQM.Integration.config.unittestinputsource_cfi")
from DQM.Integration.config.unittestinputsource_cfi import options
elif live:
process.load("DQM.Integration.config.inputsource_cfi")
from DQM.Integration.config.inputsource_cfi import options
else:
process.load("DQM.Integration.config.fileinputsource_cfi")
from DQM.Integration.config.fileinputsource_cfi import options

#--------------------------
# HLT Filter
Expand Down Expand Up @@ -281,6 +294,7 @@
process.load("RecoVertex.BeamSpotProducer.BeamSpot_cfi")

process.dqmBeamMonitor.OnlineMode = True
process.dqmBeamMonitor.recordName = BSOnlineRecordName

process.dqmBeamMonitor.resetEveryNLumi = 5 # was 10 for HI
process.dqmBeamMonitor.resetPVEveryNLumi = 5 # was 10 for HI
Expand Down Expand Up @@ -333,6 +347,36 @@

process.dqmBeamMonitor.hltResults = cms.InputTag("TriggerResults","","HLT")

#---------
# Upload BeamSpotOnlineObject (LegacyRcd) to CondDB
process.OnlineDBOutputService = cms.Service("OnlineDBOutputService",

DBParameters = cms.PSet(
messageLevel = cms.untracked.int32(0),
authenticationPath = cms.untracked.string('')
),

# Upload to CondDB
connect = cms.string('oracle://cms_orcoff_prep/CMS_CONDITIONS'),
preLoadConnectionString = cms.untracked.string('frontier://FrontierPrep/CMS_CONDITIONS'),

runNumber = cms.untracked.uint64(options.runNumber),
lastLumiFile = cms.untracked.string(''),
writeTransactionDelay = cms.untracked.uint32(options.transDelay),
autoCommit = cms.untracked.bool(True),
toPut = cms.VPSet(cms.PSet(
record = cms.string(BSOnlineRecordName),
tag = cms.string('BSOnlineLegacy_tag'),
timetype = cms.untracked.string('Lumi'),
onlyAppendUpdatePolicy = cms.untracked.bool(True)
))
)

# If not live or noDB: produce a (local) SQLITE file
if not live or noDB:
process.OnlineDBOutputService.connect = cms.string('sqlite_file:BeamSpotOnlineLegacy.db')
process.OnlineDBOutputService.preLoadConnectionString = cms.untracked.string('sqlite_file:BeamSpotOnlineLegacy.db')

#---------
# Final path
if (not process.runType.getRunType() == process.runType.hi_run):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from __future__ import print_function
import FWCore.ParameterSet.Config as cms

# Define once the BeamSpotOnline record name,
# will be used both in BeamMonitor setup and in payload creation/upload
BSOnlineRecordName = 'BeamSpotOnlineHLTObjectsRcd'

#from Configuration.Eras.Era_Run2_2018_cff import Run2_2018
#process = cms.Process("BeamMonitor", Run2_2018) # FIMXE
import sys
Expand All @@ -25,19 +29,28 @@
if 'unitTest=True' in sys.argv:
unitTest=True

# Switch to veto the upload of the BeamSpot conditions to the DB
# when False it performs the upload
noDB = True
if 'noDB=False' in sys.argv:
noDB=False

# Common part for PP and H.I Running
#-----------------------------
if unitTest:
process.load("DQM.Integration.config.unittestinputsource_cfi")
from DQM.Integration.config.unittestinputsource_cfi import options
else:
# for live online DQM in P5
process.load("DQM.Integration.config.inputsource_cfi")
from DQM.Integration.config.inputsource_cfi import options

# new stream label
process.source.streamLabel = cms.untracked.string('streamDQMOnlineBeamspot')

# for testing in lxplus
#process.load("DQM.Integration.config.fileinputsource_cfi")
#from DQM.Integration.config.fileinputsource_cfi import options

#--------------------------
# HLT Filter
Expand Down Expand Up @@ -108,6 +121,7 @@
process.dqmBeamMonitor.monitorName = 'TrackingHLTBeamspotStream'

process.dqmBeamMonitor.OnlineMode = True
process.dqmBeamMonitor.recordName = BSOnlineRecordName

process.dqmBeamMonitor.resetEveryNLumi = 5
process.dqmBeamMonitor.resetPVEveryNLumi = 5
Expand Down Expand Up @@ -137,6 +151,36 @@

process.dqmBeamMonitor.hltResults = cms.InputTag("TriggerResults","","HLT")

#---------
# Upload BeamSpotOnlineObject (HLTRcd) to CondDB
process.OnlineDBOutputService = cms.Service("OnlineDBOutputService",

DBParameters = cms.PSet(
messageLevel = cms.untracked.int32(0),
authenticationPath = cms.untracked.string('')
),

# Upload to CondDB
connect = cms.string('oracle://cms_orcoff_prep/CMS_CONDITIONS'),
preLoadConnectionString = cms.untracked.string('frontier://FrontierPrep/CMS_CONDITIONS'),

runNumber = cms.untracked.uint64(options.runNumber),
lastLumiFile = cms.untracked.string(''),
writeTransactionDelay = cms.untracked.uint32(options.transDelay),
autoCommit = cms.untracked.bool(True),
toPut = cms.VPSet(cms.PSet(
record = cms.string(BSOnlineRecordName),
tag = cms.string('BSOnlineHLT_tag'),
timetype = cms.untracked.string('Lumi'),
onlyAppendUpdatePolicy = cms.untracked.bool(True)
))
)

# If not live or noDB: produce a (local) SQLITE file
if unitTest or noDB:
process.OnlineDBOutputService.connect = cms.string('sqlite_file:BeamSpotOnlineHLT.db')
process.OnlineDBOutputService.preLoadConnectionString = cms.untracked.string('sqlite_file:BeamSpotOnlineHLT.db')

process.p = cms.Path( process.hltTriggerTypeFilter
* process.dqmcommon
* process.offlineBeamSpot
Expand Down
12 changes: 12 additions & 0 deletions DQM/Integration/python/config/fileinputsource_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@
VarParsing.VarParsing.varType.string,
"Dataset name like '/ExpressPhysicsPA/PARun2016D-Express-v1/FEVT', or 'auto' to guess it with a DAS query. A dataset_cfi.py that defines 'readFiles' and 'secFiles' (like a DAS Python snippet) will override this, to avoid DAS queries.")

options.register('transDelay',
0, #default value, int limit -3
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.int,
"delay in seconds for the commit of the db transaction")

options.register('noDB',
True, # default value
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.bool,
"Don't upload the BeamSpot conditions to the DB")

options.parseArguments()

try:
Expand Down
12 changes: 12 additions & 0 deletions DQM/Integration/python/config/inputsource_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@
VarParsing.VarParsing.varType.bool,
"Skip (and ignore the minEventsPerLumi parameter) for the files which have been available at the begining of the processing. ")

options.register('transDelay',
0, #default value, int limit -3
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.int,
"delay in seconds for the commit of the db transaction")

options.register('noDB',
True, # default value
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.bool,
"Don't upload the BeamSpot conditions to the DB")

# Parameters for runType

options.register ('runkey',
Expand Down
12 changes: 12 additions & 0 deletions DQM/Integration/python/config/unittestinputsource_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@
VarParsing.VarParsing.varType.int,
"This number of last events in each lumisection will be processed.")

options.register('transDelay',
0, #default value, int limit -3
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.int,
"delay in seconds for the commit of the db transaction")

# This is used only by the online clients themselves.
# We need to register it here because otherwise an error occurs saying that there is an unidentified option.
options.register('unitTest',
Expand All @@ -68,6 +74,12 @@
VarParsing.VarParsing.varType.bool,
"Required to avoid the error.")

options.register('noDB',
True, # default value
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.bool,
"Don't upload the BeamSpot conditions to the DB")

options.parseArguments()

print("Querying DAS for files...")
Expand Down

0 comments on commit 6429d1f

Please sign in to comment.