Skip to content

Commit

Permalink
Moved creating SiPixelTemplateStore from DB to an ESProducer
Browse files Browse the repository at this point in the history
All DB construction was switched to using EventSetup. Cases using
reading from files were kept local to module.
The new ESProducer was added as a Task to all needed Sequences.
  • Loading branch information
Dr15Jones committed Aug 8, 2023
1 parent bce2eaf commit a37977f
Show file tree
Hide file tree
Showing 21 changed files with 172 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class SiPixelLorentzAnglePCLWorker : public DQMEDAnalyzer {
// template stuff
edm::ESWatcher<SiPixelTemplateDBObjectESProducerRcd> watchSiPixelTemplateRcd_;
const SiPixelTemplateDBObject* templateDBobject_;
std::vector<SiPixelTemplateStore> thePixelTemp_;
const std::vector<SiPixelTemplateStore>* thePixelTemp_ = nullptr;

LorentzAngleAnalysisTypeEnum analysisType_;
std::string folder_;
Expand Down Expand Up @@ -195,6 +195,7 @@ class SiPixelLorentzAnglePCLWorker : public DQMEDAnalyzer {
edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geomEsToken_;
edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> topoEsToken_;
edm::ESGetToken<SiPixelTemplateDBObject, SiPixelTemplateDBObjectESProducerRcd> siPixelTemplateEsToken_;
edm::ESGetToken<std::vector<SiPixelTemplateStore>, SiPixelTemplateDBObjectESProducerRcd> siPixelTemplateStoreEsToken_;
edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> topoPerEventEsToken_;
edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geomPerEventEsToken_;
edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magneticFieldToken_;
Expand Down Expand Up @@ -223,6 +224,7 @@ SiPixelLorentzAnglePCLWorker::SiPixelLorentzAnglePCLWorker(const edm::ParameterS
geomEsToken_(esConsumes<edm::Transition::BeginRun>()),
topoEsToken_(esConsumes<edm::Transition::BeginRun>()),
siPixelTemplateEsToken_(esConsumes<edm::Transition::BeginRun>()),
siPixelTemplateStoreEsToken_(esConsumes<edm::Transition::BeginRun>()),
topoPerEventEsToken_(esConsumes()),
geomPerEventEsToken_(esConsumes()),
magneticFieldToken_(esConsumes()) {
Expand Down Expand Up @@ -467,7 +469,7 @@ void SiPixelLorentzAnglePCLWorker::analyze(edm::Event const& iEvent, edm::EventS

if (notInPCL_) {
// fill the template from the store (from dqmBeginRun)
SiPixelTemplate theTemplate(thePixelTemp_);
SiPixelTemplate theTemplate(*thePixelTemp_);

float locBx = (cotbeta < 0.) ? -1 : 1.;
float locBz = (cotalpha < 0.) ? -locBx : locBx;
Expand Down Expand Up @@ -639,7 +641,7 @@ void SiPixelLorentzAnglePCLWorker::analyze(edm::Event const& iEvent, edm::EventS

if (notInPCL_) {
// fill the template from the store (from dqmBeginRun)
SiPixelTemplate theTemplate(thePixelTemp_);
SiPixelTemplate theTemplate(*thePixelTemp_);

float locBx = (cotbeta < 0.) ? -1 : 1.;
float locBz = (cotalpha < 0.) ? -locBx : locBx;
Expand Down Expand Up @@ -730,11 +732,7 @@ void SiPixelLorentzAnglePCLWorker::dqmBeginRun(edm::Run const& run, edm::EventSe
// Initialize 1D templates
if (watchSiPixelTemplateRcd_.check(iSetup)) {
templateDBobject_ = &iSetup.getData(siPixelTemplateEsToken_);
if (!SiPixelTemplate::pushfile(*templateDBobject_, thePixelTemp_)) {
edm::LogError("SiPixelLorentzAnglePCLWorker")
<< "Templates not filled correctly. Check the sqlite file. Using SiPixelTemplateDBObject version "
<< (*templateDBobject_).version();
}
thePixelTemp_ = &iSetup.getData(siPixelTemplateStoreEsToken_);
}
}

Expand Down
1 change: 1 addition & 0 deletions CondFormats/SiPixelTransient/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<use name="FWCore/MessageLogger"/>
<use name="FWCore/Utilities"/>
<use name="FWCore/Framework"/>
<use name="boost"/>
<export>
<lib name="1"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// -*- C++ -*-
//
// Package: CondFormats/SiPixelTransient
// Class : T_EventSetup_SiPixelTemplateStore
//
// Implementation:
// [Notes on implementation]
//
// Original Author: Christopher Jones
// Created: Tue, 08 Aug 2023 15:33:48 GMT
//

// system include files

// user include files
#include "CondFormats/SiPixelTransient/interface/SiPixelTemplate.h"
#include "FWCore/Framework/interface/eventsetuprecord_registration_macro.h"

TYPELOOKUP_DATA_REG(std::vector<SiPixelTemplateStore>);
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from DQM.SiPixelPhase1Track.SiPixelPhase1ResidualsExtra_cfi import *
# Clusters ontrack/offtrack (also general tracks)
from DQM.SiPixelPhase1Track.SiPixelPhase1TrackClusters_cfi import *
from RecoLocalTracker.SiPixelRecHits.SiPixelTemplateStoreESProducer_cfi import *
# Hit Efficiencies
from DQM.SiPixelPhase1Track.SiPixelPhase1TrackEfficiency_cfi import *
# FED/RAW Data
Expand All @@ -24,7 +25,6 @@
from DQM.SiPixelPhase1Summary.SiPixelBarycenter_cfi import *



from RecoTracker.PixelLowPtUtilities.ClusterShapeHitFilterESProducer_cfi import *
from RecoLocalTracker.SiStripClusterizer.SiStripClusterChargeCut_cfi import *
from DQM.SiPixelPhase1Track.SiPixelPhase1EfficiencyExtras_cfi import *
Expand All @@ -39,7 +39,8 @@
+ SiPixelPhase1RecHitsAnalyzer
+ SiPixelPhase1TrackResidualsAnalyzer
+ SiPixelPhase1TrackClustersAnalyzer
+ SiPixelPhase1TrackEfficiencyAnalyzer
+ SiPixelPhase1TrackEfficiencyAnalyzer,
cms.Task(SiPixelTemplateStoreESProducer)
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@

# Cluster (track-independent) monitoring
from DQM.SiPixelPhase1Common.SiPixelPhase1Clusters_cfi import *
from RecoLocalTracker.SiPixelRecHits.SiPixelTemplateStoreESProducer_cfi import *

# Track cluster
from DQM.SiPixelPhase1Track.SiPixelPhase1TrackClusters_cfi import *
from DQM.SiPixelPhase1Track.SiPixelPhase1TrackResiduals_cfi import *


# Raw data errors
from DQM.SiPixelPhase1Common.SiPixelPhase1RawData_cfi import *

Expand All @@ -115,7 +115,8 @@
+ SiPixelPhase1ClustersAnalyzer
+ SiPixelPhase1RawDataAnalyzer
+ SiPixelPhase1TrackClustersAnalyzer
+ SiPixelPhase1TrackResidualsAnalyzer
+ SiPixelPhase1TrackResidualsAnalyzer,
cms.Task(SiPixelTemplateStoreESProducer)
)

siPixelPhase1OnlineDQM_harvesting = cms.Sequence(
Expand Down Expand Up @@ -149,7 +150,8 @@
+ SiPixelPhase1ClustersAnalyzer
+ SiPixelPhase1RawDataAnalyzer
+ SiPixelPhase1TrackClustersAnalyzer_cosmics
+ SiPixelPhase1TrackResidualsAnalyzer_cosmics
+ SiPixelPhase1TrackResidualsAnalyzer_cosmics,
cms.Task(SiPixelTemplateStoreESProducer)
)

## Additional settings for pp_run (Phase 0 test)
Expand Down Expand Up @@ -177,6 +179,7 @@
+ SiPixelPhase1RawDataAnalyzer
+ SiPixelPhase1TrackClustersAnalyzer_pprun
+ SiPixelPhase1TrackResidualsAnalyzer_pprun
+ SiPixelPhase1TrackEfficiencyAnalyzer_pprun
+ SiPixelPhase1TrackEfficiencyAnalyzer_pprun,
cms.Task(SiPixelTemplateStoreESProducer)
)

9 changes: 7 additions & 2 deletions DQM/SiPixelPhase1Config/python/SiPixelPhase1OnlineDQM_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@

# Track cluster
from DQM.SiPixelPhase1Track.SiPixelPhase1TrackClusters_cfi import *
from RecoLocalTracker.SiPixelRecHits.SiPixelTemplateStoreESProducer_cfi import *

SiPixelPhase1TrackClustersOnTrackCorrCharge.enabled=cms.bool(False)
SiPixelPhase1TrackTemplateCorr.enabled=cms.bool(False)
SiPixelPhase1TrackClustersOnTrackCorrChargeOuter.enabled=cms.bool(False)
Expand All @@ -86,6 +88,7 @@
+ SiPixelPhase1TrackClustersAnalyzer
+ SiPixelPhase1TrackResidualsAnalyzer
# + SiPixelPhase1GeometryDebugAnalyzer
, cms.Task(SiPixelTemplateStoreESProducer)
)

siPixelPhase1OnlineDQM_harvesting = cms.Sequence(
Expand Down Expand Up @@ -119,7 +122,8 @@
+ SiPixelPhase1ClustersAnalyzer
+ SiPixelPhase1RawDataAnalyzer
+ SiPixelPhase1TrackClustersAnalyzer_cosmics
+ SiPixelPhase1TrackResidualsAnalyzer_cosmics
+ SiPixelPhase1TrackResidualsAnalyzer_cosmics,
cms.Task(SiPixelTemplateStoreESProducer)
)

## Additional settings for pp_run
Expand All @@ -142,7 +146,8 @@
+ SiPixelPhase1ClustersAnalyzer
+ SiPixelPhase1RawDataAnalyzer
+ SiPixelPhase1TrackClustersAnalyzer_pprun
+ SiPixelPhase1TrackResidualsAnalyzer_pprun
+ SiPixelPhase1TrackResidualsAnalyzer_pprun,
cms.Task(SiPixelTemplateStoreESProducer)
)

siPixelPhase1OnlineDQM_timing_harvesting = siPixelPhase1OnlineDQM_harvesting.copyAndExclude([
Expand Down
13 changes: 6 additions & 7 deletions DQM/SiPixelPhase1Track/plugins/SiPixelPhase1TrackClusters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ namespace {

private:
const bool applyVertexCut_;
const SiPixelTemplateDBObject* templateDBobject_;
std::vector<SiPixelTemplateStore> thePixelTemp_;
const SiPixelTemplateDBObject* templateDBobject_ = nullptr;
const std::vector<SiPixelTemplateStore>* thePixelTemp_ = nullptr;
const TrackerTopology* tkTpl = nullptr;

edm::EDGetTokenT<reco::TrackCollection> tracksToken_;
Expand All @@ -101,6 +101,7 @@ namespace {
edm::ESGetToken<ClusterShapeHitFilter, CkfComponentsRecord> clusterShapeHitFilterToken_;

edm::ESGetToken<SiPixelTemplateDBObject, SiPixelTemplateDBObjectESProducerRcd> templateDBobjectToken_;
edm::ESGetToken<std::vector<SiPixelTemplateStore>, SiPixelTemplateDBObjectESProducerRcd> templateStoreToken_;
};

SiPixelPhase1TrackClusters::SiPixelPhase1TrackClusters(const edm::ParameterSet& iConfig)
Expand All @@ -118,6 +119,7 @@ namespace {
trackerGeomToken_ = esConsumes<edm::Transition::BeginRun>();
clusterShapeHitFilterToken_ =
esConsumes<ClusterShapeHitFilter, CkfComponentsRecord>(edm::ESInputTag("", "ClusterShapeHitFilter"));
templateStoreToken_ = esConsumes<edm::Transition::BeginRun>();
templateDBobjectToken_ = esConsumes<edm::Transition::BeginRun>();
}

Expand All @@ -127,10 +129,7 @@ namespace {

// Initialize 1D templates
templateDBobject_ = &iSetup.getData(templateDBobjectToken_);
if (!SiPixelTemplate::pushfile(*templateDBobject_, thePixelTemp_))
edm::LogError("SiPixelPhase1TrackClusters")
<< "Templates not filled correctly. Check the sqlite file. Using SiPixelTemplateDBObject version "
<< (*templateDBobject_).version() << std::endl;
thePixelTemp_ = &iSetup.getData(templateStoreToken_);
}

void SiPixelPhase1TrackClusters::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
Expand Down Expand Up @@ -162,7 +161,7 @@ namespace {
return;
}

SiPixelTemplate templ(thePixelTemp_);
SiPixelTemplate templ(*thePixelTemp_);

edm::Handle<SiPixelClusterShapeCache> pixelClusterShapeCacheH;
iEvent.getByToken(pixelClusterShapeCacheToken_, pixelClusterShapeCacheH);
Expand Down
4 changes: 3 additions & 1 deletion DQMOffline/Trigger/python/SiPixel_OfflineMonitoring_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from DQMOffline.Trigger.SiPixel_OfflineMonitoring_TrackCluster_cff import *
from RecoTracker.PixelLowPtUtilities.siPixelClusterShapeCache_cfi import *
from DQM.SiPixelMonitorTrack.RefitterForPixelDQM import *
from RecoLocalTracker.SiPixelRecHits.SiPixelTemplateStoreESProducer_cfi import *

hltSiPixelClusterShapeCache = siPixelClusterShapeCache.clone(src = 'hltSiPixelClusters')
hltrefittedForPixelDQM = refittedForPixelDQM.clone(src ='hltMergedTracks',
Expand All @@ -12,5 +13,6 @@
hltSiPixelClusterShapeCache
+ hltSiPixelPhase1ClustersAnalyzer
+ hltrefittedForPixelDQM
+ hltSiPixelPhase1TrackClustersAnalyzer
+ hltSiPixelPhase1TrackClustersAnalyzer,
cms.Task(SiPixelTemplateStoreESProducer)
)
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class PixelTemplateSmearerBase : public TrackingRecHitAlgorithm {
bool mergeHitsOn = false; // if true then see if neighboring hits might merge

//--- Template DB Object(s)
const SiPixelTemplateDBObject* pixelTemplateDBObject_ = nullptr; // needed for template<-->DetId map.
std::vector<SiPixelTemplateStore> thePixelTemp_; // our own template storage
std::vector<SiPixelTemplateStore>& thePixelTempRef = thePixelTemp_; // points to the one we will use.
const SiPixelTemplateDBObject* pixelTemplateDBObject_ = nullptr; // needed for template<-->DetId map.
std::vector<SiPixelTemplateStore> thePixelTemp_; // our own template storage
const std::vector<SiPixelTemplateStore>* thePixelTempRef = &thePixelTemp_; // points to the one we will use.
int templateId = -1;

//--- Flag to tell us whether we are in barrel or in forward.
Expand Down Expand Up @@ -92,7 +92,7 @@ class PixelTemplateSmearerBase : public TrackingRecHitAlgorithm {
void beginRun(edm::Run const& run,
const edm::EventSetup& eventSetup,
const SiPixelTemplateDBObject* pixelTemplateDBObjectPtr,
std::vector<SiPixelTemplateStore>& tempStoreRef) override;
const std::vector<SiPixelTemplateStore>& tempStoreRef) override;
// void endEvent(edm::Event& event, const edm::EventSetup& eventSetup) override;

//--- Process all unmerged hits. Calls smearHit() for each.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class TrackingRecHitAlgorithm {
virtual void beginRun(edm::Run const& run,
const edm::EventSetup& eventSetup,
const SiPixelTemplateDBObject* pixelTemplateDBObjectPtr,
std::vector<SiPixelTemplateStore>& tempStoreRef);
const std::vector<SiPixelTemplateStore>& tempStoreRef);

//this function will only be called once per event
virtual void beginEvent(edm::Event& event, const edm::EventSetup& eventSetup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ class TrackingRecHitProducer : public edm::stream::EDProducer<> {
unsigned long long _trackerTopologyCacheID = 0;
std::map<unsigned int, TrackingRecHitPipe> _detIdPipes;
void setupDetIdPipes(const edm::EventSetup& eventSetup);
std::vector<SiPixelTemplateStore> _pixelTempStore; // pixel template storage
const edm::ESGetToken<SiPixelTemplateDBObject, SiPixelTemplateDBObjectESProducerRcd> siPixelTemplateDBObjectESToken_;
const edm::ESGetToken<std::vector<SiPixelTemplateStore>, SiPixelTemplateDBObjectESProducerRcd>
siPixelTemplateStoreESToken_;
const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> trackerGeometryESToken_;
const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> trackerTopologyESToken_;

Expand Down Expand Up @@ -115,17 +116,10 @@ void TrackingRecHitProducer::beginRun(edm::Run const& run, const edm::EventSetup
// to a no-op.

const SiPixelTemplateDBObject& pixelTemplateDBObject = eventSetup.getData(siPixelTemplateDBObjectESToken_);

//--- Now that we have the DB object, load the correct templates from the DB.
// (They are needed for data and full sim MC, so in a production FastSim
// run, everything should already be in the DB.)
if (!SiPixelTemplate::pushfile(pixelTemplateDBObject, _pixelTempStore)) {
throw cms::Exception("TrackingRecHitProducer:")
<< "SiPixel Templates not loaded correctly from the DB object!" << std::endl;
}
const auto& pixelTemplateStore = eventSetup.getData(siPixelTemplateStoreESToken_);

for (auto& algo : _recHitAlgorithms) {
algo->beginRun(run, eventSetup, &pixelTemplateDBObject, _pixelTempStore);
algo->beginRun(run, eventSetup, &pixelTemplateDBObject, pixelTemplateStore);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ PixelTemplateSmearerBase::~PixelTemplateSmearerBase() {}
void PixelTemplateSmearerBase::beginRun(edm::Run const& run,
const edm::EventSetup& eventSetup,
const SiPixelTemplateDBObject* pixelTemplateDBObjectPtr,
std::vector<SiPixelTemplateStore>& tempStoreRef) {
const std::vector<SiPixelTemplateStore>& tempStoreRef) {
//--- Check if we need to use the template from the DB (namely if
// id == -1). Otherwise the template has already been loaded from
// the ascii file in constructor, and thePixelTempRef wakes up
// pointing to thePixelTemp_, so then we use our own store.
//
if (templateId == -1) {
thePixelTempRef = tempStoreRef; // we use the store from TrackingRecHitProducer
thePixelTempRef = &tempStoreRef; // we use the store from TrackingRecHitProducer
pixelTemplateDBObject_ = pixelTemplateDBObjectPtr; // needed for template<-->DetId map.
}

Expand Down Expand Up @@ -392,7 +392,7 @@ FastSingleTrackerRecHit PixelTemplateSmearerBase::smearHit(const PSimHit& simHit
}

//--- Make the template object
SiPixelTemplate templ(thePixelTempRef);
SiPixelTemplate templ(*thePixelTempRef);

//--- Produce the template that corresponds to our local angles.
templ.interpolate(ID, cotalpha, cotbeta);
Expand Down Expand Up @@ -778,7 +778,7 @@ FastSingleTrackerRecHit PixelTemplateSmearerBase::smearMergeGroup(MergeGroup* mg
}

//--- Make the template object
SiPixelTemplate templ(thePixelTempRef);
SiPixelTemplate templ(*thePixelTempRef);

//--- Produce the template that corresponds to our local angles.
templ.interpolate(ID, cotalpha, cotbeta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void TrackingRecHitAlgorithm::beginStream(const edm::StreamID& id) {
void TrackingRecHitAlgorithm::beginRun(edm::Run const& run,
const edm::EventSetup& eventSetup,
const SiPixelTemplateDBObject* pixelTemplateDBObjectPtr,
std::vector<SiPixelTemplateStore>& tempStoreRef) {
const std::vector<SiPixelTemplateStore>& tempStoreRef) {
// The default is to do nothing.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class PixelCPEClusterRepair : public PixelCPEBase {
const TrackerGeometry &,
const TrackerTopology &,
const SiPixelLorentzAngle *,
const std::vector<SiPixelTemplateStore> *,
const SiPixelTemplateDBObject *,
const SiPixel2DTemplateDBObject *);

Expand Down Expand Up @@ -97,7 +98,8 @@ class PixelCPEClusterRepair : public PixelCPEBase {
void fill2DTemplIDs();

// Template storage
std::vector<SiPixelTemplateStore> thePixelTemp_;
std::vector<SiPixelTemplateStore> const *thePixelTemp_;
std::vector<SiPixelTemplateStore> thePixelTempCache_;
std::vector<SiPixelTemplateStore2D> thePixelTemp2D_;

int speed_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class PixelCPETemplateReco : public PixelCPEBase {
const TrackerGeometry &,
const TrackerTopology &,
const SiPixelLorentzAngle *,
const std::vector<SiPixelTemplateStore> *,
const SiPixelTemplateDBObject *);

~PixelCPETemplateReco() override;
Expand All @@ -74,7 +75,8 @@ class PixelCPETemplateReco : public PixelCPEBase {
LocalError localError(DetParam const &theDetParam, ClusterParam &theClusterParam) const override;

// Template storage
std::vector<SiPixelTemplateStore> thePixelTemp_;
std::vector<SiPixelTemplateStore> thePixelTempCache_;
const std::vector<SiPixelTemplateStore> *thePixelTemp_;

int speed_;

Expand Down
Loading

0 comments on commit a37977f

Please sign in to comment.