Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic SiStripApproximateCluster Monitoring #40295

Merged
merged 4 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
import sys
if 'runkey=hi_run' in sys.argv:
from Configuration.Eras.Era_Run3_pp_on_PbPb_approxSiStripClusters_cff import Run3_pp_on_PbPb_approxSiStripClusters
process = cms.Process("BeamMonitor", Run3_pp_on_PbPb_approxSiStripClusters)
process = cms.Process("SiStripMonitor", Run3_pp_on_PbPb_approxSiStripClusters)
else:
from Configuration.Eras.Era_Run3_cff import Run3
process = cms.Process("BeamMonitor", Run3)
process = cms.Process("SiStripMonitor", Run3)

process.MessageLogger = cms.Service("MessageLogger",
debugModules = cms.untracked.vstring('siStripDigis',
'siStripClusters',
'siStripZeroSuppression',
'SiStripClusterizer'),
'SiStripClusterizer'),
cout = cms.untracked.PSet(threshold = cms.untracked.string('ERROR')),
destinations = cms.untracked.vstring('cout')
)
Expand Down Expand Up @@ -553,8 +553,6 @@
'HLT_HIPhysics*'
]



process.SiStripMonitorDigi.UseDCSFiltering = False
process.SiStripMonitorClusterReal.UseDCSFiltering = False

Expand Down Expand Up @@ -666,6 +664,9 @@
process.TrackingClient
)

from DQM.SiStripMonitorApproximateCluster.SiStripMonitorApproximateCluster_cfi import SiStripMonitorApproximateCluster
process.siStriApproximateClusterMonitor = SiStripMonitorApproximateCluster.clone(compareClusters = cms.bool(True))
process.p.insert(-1, process.siStriApproximateClusterMonitor)

### process customizations included here
from DQM.Integration.config.online_customizations_cfi import *
Expand Down
7 changes: 7 additions & 0 deletions DQM/SiStripMonitorApproximateCluster/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<use name="FWCore/Framework"/>
<use name="FWCore/PluginManager"/>
<use name="FWCore/ParameterSet"/>
<use name="DQMServices/Core"/>
mmusich marked this conversation as resolved.
Show resolved Hide resolved
<use name="Geometry/Records"/>
<use name="Geometry/TrackerGeometryBuilder"/>
<flags EDM_PLUGIN="1"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
// -*- C++ -*-
//
// Package: DQM/SiStripMonitorApproximateCluster
// Class: SiStripMonitorApproximateCluster
//
/**\class SiStripMonitorApproximateCluster SiStripMonitorApproximateCluster.cc DQM/SiStripMonitorApproximateCluster/plugins/SiStripMonitorApproximateCluster.cc

Description: [one line class summary]

Implementation:
[Notes on implementation]
*/
//
// Original Author: Marco Musich
// Created: Thu, 08 Dec 2022 20:51:10 GMT
//
//

#include <string>

// user include files
#include "DQMServices/Core/interface/DQMEDAnalyzer.h"
#include "DQMServices/Core/interface/MonitorElement.h"
#include "DataFormats/Common/interface/DetSet.h"
#include "DataFormats/Common/interface/DetSetVector.h"
mmusich marked this conversation as resolved.
Show resolved Hide resolved
#include "DataFormats/Common/interface/DetSetVectorNew.h"
#include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
#include "DataFormats/SiStripCluster/interface/SiStripApproximateCluster.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
#include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
//
// class declaration
//

class SiStripMonitorApproximateCluster : public DQMEDAnalyzer {
public:
explicit SiStripMonitorApproximateCluster(const edm::ParameterSet&);
~SiStripMonitorApproximateCluster() override = default;

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;

void analyze(const edm::Event&, const edm::EventSetup&) override;

// ------------ member data ------------
std::string folder_;
bool compareClusters_;
MonitorElement* h_nclusters_{nullptr};
MonitorElement* h_barycenter_{nullptr};
MonitorElement* h_width_{nullptr};
MonitorElement* h_avgCharge_{nullptr};
MonitorElement* h_isSaturated_{nullptr};

// for comparisons
MonitorElement* h_isMatched_{nullptr};
MonitorElement* h_deltaBarycenter_{nullptr};
MonitorElement* h_deltaSize_{nullptr};
MonitorElement* h_deltaCharge_{nullptr};
MonitorElement* h_deltaFirstStrip_{nullptr};
MonitorElement* h_deltaEndStrip_{nullptr};

// Event Data
edm::EDGetTokenT<edmNew::DetSetVector<SiStripApproximateCluster>> approxClustersToken_;
edm::EDGetTokenT<edmNew::DetSetVector<SiStripCluster>> stripClustersToken_;
const edmNew::DetSetVector<SiStripCluster>* stripClusterCollection_;

// Event Setup Data
edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkGeomToken_;
};

//
// constructors and destructor
//
SiStripMonitorApproximateCluster::SiStripMonitorApproximateCluster(const edm::ParameterSet& iConfig)
: folder_(iConfig.getParameter<std::string>("folder")),
compareClusters_(iConfig.getParameter<bool>("compareClusters")),
// Poducer name of input StripClusterCollection
approxClustersToken_(consumes<edmNew::DetSetVector<SiStripApproximateCluster>>(
iConfig.getParameter<edm::InputTag>("ApproxClustersProducer"))) {
tkGeomToken_ = esConsumes();
if (compareClusters_) {
stripClustersToken_ =
consumes<edmNew::DetSetVector<SiStripCluster>>(iConfig.getParameter<edm::InputTag>("ClustersProducer"));
}
stripClusterCollection_ = nullptr;
}

//
// member functions
//

// ------------ method called for each event ------------
void SiStripMonitorApproximateCluster::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
using namespace edm;

const auto& tkGeom = &iSetup.getData(tkGeomToken_);
const auto tkDets = tkGeom->dets();

// get collection of DetSetVector of clusters from Event
edm::Handle<edmNew::DetSetVector<SiStripApproximateCluster>> approx_cluster_detsetvector;
iEvent.getByToken(approxClustersToken_, approx_cluster_detsetvector);
if (!approx_cluster_detsetvector.isValid()) {
edm::LogError("SiStripMonitorApproximateCluster")
<< "SiStripApproximate cluster collection is not valid!" << std::endl;

// if approximate clusters collection not available, then early return
return;
}

// if requested to perform the comparison
if (compareClusters_) {
// get collection of DetSetVector of clusters from Event
edm::Handle<edmNew::DetSetVector<SiStripCluster>> cluster_detsetvector;
iEvent.getByToken(stripClustersToken_, cluster_detsetvector);
if (!cluster_detsetvector.isValid()) {
edm::LogError("SiStripMonitorApproximateCluster")
<< "Requested to perform comparison, but regular SiStrip cluster collection is not valid!" << std::endl;
return;
} else {
stripClusterCollection_ = cluster_detsetvector.product();
}
}

int nApproxClusters{0};
const edmNew::DetSetVector<SiStripApproximateCluster>* clusterCollection = approx_cluster_detsetvector.product();

for (const auto& detClusters : *clusterCollection) {
edmNew::DetSet<SiStripCluster> strip_clusters_detset;
const auto& detid = detClusters.detId(); // get the detid of the current detset

// starts here comaparison with regular clusters
if (compareClusters_) {
edmNew::DetSetVector<SiStripCluster>::const_iterator isearch =
stripClusterCollection_->find(detid); // search clusters of detid
strip_clusters_detset = (*isearch);
}

bool isMatched{false};
for (const auto& cluster : detClusters) {
nApproxClusters++;
h_barycenter_->Fill(cluster.barycenter());
h_width_->Fill(cluster.width());
h_avgCharge_->Fill(cluster.avgCharge());
h_isSaturated_->Fill(cluster.isSaturated() ? 1 : -1);

if (compareClusters_ && !strip_clusters_detset.empty()) {
uint16_t nStrips{0};
auto det = std::find_if(tkDets.begin(), tkDets.end(), [detid](auto& elem) -> bool {
return (elem->geographicalId().rawId() == detid);
});
const StripTopology& p = dynamic_cast<const StripGeomDetUnit*>(*det)->specificTopology();
nStrips = p.nstrips() - 1;

const auto convertedCluster = SiStripCluster(cluster, nStrips);
float distance{9999.};
const SiStripCluster* closestCluster{nullptr};
for (const auto& stripCluster : strip_clusters_detset) {
float deltaBarycenter = convertedCluster.barycenter() - stripCluster.barycenter();
if (deltaBarycenter < distance) {
closestCluster = &stripCluster;
distance = deltaBarycenter;
}
}

// Matching criteria:
// - if exists a closest cluster in the DetId
// - the size coincides with the original one
if (closestCluster && (cluster.width() == closestCluster->size())) {
isMatched = true;
h_deltaBarycenter_->Fill(distance);
h_deltaSize_->Fill(closestCluster->size() - convertedCluster.size());
h_deltaCharge_->Fill(closestCluster->charge() - convertedCluster.charge());
h_deltaFirstStrip_->Fill(closestCluster->firstStrip() - convertedCluster.firstStrip());
h_deltaEndStrip_->Fill(closestCluster->endStrip() - convertedCluster.endStrip());
}

h_isMatched_->Fill(isMatched ? 1 : -1);

} // if we're doing the comparison cluster by cluster

} // loop on clusters in a detset
} // loop on the detset vector
h_nclusters_->Fill(nApproxClusters);
}

void SiStripMonitorApproximateCluster::bookHistograms(DQMStore::IBooker& ibook,
edm::Run const& run,
edm::EventSetup const& iSetup) {
ibook.setCurrentFolder(folder_);
h_nclusters_ = ibook.book1D("numberOfClusters", "total N. of clusters;N. of clusters;#clusters", 500., 0., 500000.);
h_barycenter_ =
ibook.book1D("clusterBarycenter", "cluster barycenter;cluster barycenter;#clusters", 7680., 0., 7680.);
h_width_ = ibook.book1D("clusterWidth", "cluster width;cluster width;#clusters", 128, -0.5, 127.5);
h_avgCharge_ =
ibook.book1D("clusterAvgCharge", "average strip charge;average strip charge;#clusters", 256, -0.5, 255.5);
h_isSaturated_ = ibook.book1D("clusterSaturation", "cluster saturation;is saturated?;#clusters", 3, -1.5, 1.5);
h_isSaturated_->getTH1F()->GetXaxis()->SetBinLabel(1, "Not saturated");
h_isSaturated_->getTH1F()->GetXaxis()->SetBinLabel(3, "Saturated");

// for comparisons
if (compareClusters_) {
ibook.setCurrentFolder(fmt::format("{}/ClusterComparisons", folder_));
h_deltaBarycenter_ =
ibook.book1D("deltaBarycenter", "#Delta barycenter;#Delta barycenter;cluster pairs", 201, -100.5, 100.5);
h_deltaSize_ = ibook.book1D("deltaSize", "#Delta size;#Delta size;cluster pairs", 201, -100.5, 100.5);
h_deltaCharge_ = ibook.book1D("deltaCharge", "#Delta charge;#Delta charge;cluster pairs", 500, -1000.5, 1000.5);

h_deltaFirstStrip_ =
ibook.book1D("deltaFirstStrip", "#Delta FirstStrip; #Delta firstStrip;cluster pairs", 201, -100.5, 100.5);
h_deltaEndStrip_ =
ibook.book1D("deltaEndStrip", "#Delta EndStrip; #Delta endStrip; cluster pairs", 201, -100.5, 100.5);

h_isMatched_ = ibook.book1D("isClusterMatched", "cluster matching;is matched?;#clusters", 3, -1.5, 1.5);
h_isMatched_->getTH1F()->GetXaxis()->SetBinLabel(1, "Not matched");
h_isMatched_->getTH1F()->GetXaxis()->SetBinLabel(3, "Matched");
}
}

// ------------ method fills 'descriptions' with the allowed parameters for the module ------------
void SiStripMonitorApproximateCluster::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<bool>("compareClusters", false);
desc.add<edm::InputTag>("ApproxClustersProducer", edm::InputTag("hltSiStripClusters2ApproxClusters"));
desc.add<edm::InputTag>("ClustersProducer", edm::InputTag("siStripClusters"));
desc.add<std::string>("folder", "SiStripApproximateClusters");
descriptions.addWithDefaultLabel(desc);
}

// define this as a plug-in
DEFINE_FWK_MODULE(SiStripMonitorApproximateCluster);
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import FWCore.ParameterSet.Config as cms

# SiStripMonitorCluster
from DQMServices.Core.DQMEDAnalyzer import DQMEDAnalyzer
SiStripMonitorApproximateCluster = DQMEDAnalyzer("SiStripMonitorApproximateCluster",
mmusich marked this conversation as resolved.
Show resolved Hide resolved
compareClusters = cms.bool(False),
ApproxClustersProducer = cms.InputTag('hltSiStripClusters2ApproxClusters'),
ClustersProducer = cms.InputTag('siStripClusters'),
folder = cms.string('SiStripApproximateClusters'))
16 changes: 15 additions & 1 deletion DQM/SiStripMonitorClient/python/SiStripSourceConfigTier0_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,32 @@
# *SiStripMonitorTrackMB*MonitorTrackResiduals
# *dqmInfoSiStrip)

from Configuration.ProcessModifiers.approxSiStripClusters_cff import approxSiStripClusters

SiStripDQMTier0 = cms.Sequence(
APVPhases*consecutiveHEs*siStripFEDCheck*siStripFEDMonitor*SiStripMonitorDigi*SiStripMonitorClusterBPTX
*SiStripMonitorTrackCommon*SiStripMonitorTrackIB*refittedForPixelDQM*MonitorTrackResiduals
*dqmInfoSiStrip)
from Configuration.Eras.Modifier_phase1Pixel_cff import phase1Pixel

from DQM.SiStripMonitorApproximateCluster.SiStripMonitorApproximateCluster_cfi import SiStripMonitorApproximateCluster
SiStripDQMTier0_approx = SiStripDQMTier0.copy()
SiStripDQMTier0_approx += cms.Sequence(SiStripMonitorApproximateCluster)
approxSiStripClusters.toReplaceWith(SiStripDQMTier0, SiStripDQMTier0_approx)

SiStripDQMTier0Common = cms.Sequence(
APVPhases*consecutiveHEs*siStripFEDCheck*siStripFEDMonitor*SiStripMonitorDigi*SiStripMonitorClusterBPTX
*SiStripMonitorTrackCommon*SiStripMonitorTrackIB
*dqmInfoSiStrip)

SiStripDQMTier0Common_approx = SiStripDQMTier0Common.copy()
SiStripDQMTier0Common_approx += cms.Sequence(SiStripMonitorApproximateCluster)
approxSiStripClusters.toReplaceWith(SiStripDQMTier0Common, SiStripDQMTier0Common_approx)

SiStripDQMTier0MinBias = cms.Sequence(
APVPhases*consecutiveHEs*siStripFEDCheck*siStripFEDMonitor*SiStripMonitorDigi*SiStripMonitorClusterBPTX
*SiStripMonitorTrackMB*SiStripMonitorTrackIB*refittedForPixelDQM*MonitorTrackResiduals
*dqmInfoSiStrip)

SiStripDQMTier0MinBias_approx = SiStripDQMTier0MinBias.copy()
SiStripDQMTier0MinBias_approx += cms.Sequence(SiStripMonitorApproximateCluster)
approxSiStripClusters.toReplaceWith(SiStripDQMTier0MinBias, SiStripDQMTier0MinBias_approx)