Skip to content

Commit

Permalink
Merge pull request #39369 from mmusich/tkHistoMap_fixes
Browse files Browse the repository at this point in the history
Miscellaneous updates to `TkHistoMap`
  • Loading branch information
cmsbuild authored Sep 14, 2022
2 parents 6412b68 + f9cdd0d commit 9fc5d08
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 89 deletions.
2 changes: 1 addition & 1 deletion DQM/SiStripCommon/interface/TkHistoMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TkHistoMap {
bool mechanicalView,
bool isTH2F);
TkHistoMap(const TkDetMap* tkDetMap);
~TkHistoMap(){};
~TkHistoMap() = default;

void loadServices();

Expand Down
13 changes: 10 additions & 3 deletions DQM/SiStripCommon/src/TkHistoMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ void TkHistoMap::load(const TkDetMap* tkDetMap,
bool mechanicalView,
bool isTH2F,
bool createTkMap) {
// cannot pass nullptr, otherwise methods making use of TrackerTopology will segfault
if (tkDetMap == nullptr) {
throw cms::Exception("LogicError") << " expected pointer to TkDetMap is null!\n";
}

cached_detid = 0;
cached_layer = 0;
loadServices();
Expand Down Expand Up @@ -260,12 +265,14 @@ float TkHistoMap::getValue(DetId detid) {
}
float TkHistoMap::getEntries(DetId detid) {
int16_t layer = tkdetmap_->findLayer(detid, cached_detid, cached_layer, cached_XYbin);
TkLayerMap::XYbin xybin = tkdetmap_->getXY(detid, cached_detid, cached_layer, cached_XYbin);
if (tkHistoMap_[layer]->kind() == MonitorElement::Kind::TH2F)

if (tkHistoMap_[layer]->kind() == MonitorElement::Kind::TH2F) {
return 1;
else
} else {
TkLayerMap::XYbin xybin = tkdetmap_->getXY(detid, cached_detid, cached_layer, cached_XYbin);
return tkHistoMap_[layer]->getTProfile2D()->GetBinEntries(
tkHistoMap_[layer]->getTProfile2D()->GetBin(xybin.ix, xybin.iy));
}
}

void TkHistoMap::dumpInTkMap(TrackerMap* tkmap, bool dumpEntries) {
Expand Down
5 changes: 4 additions & 1 deletion DQM/SiStripCommon/test/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<flags EDM_PLUGIN="1"/>
</library>

<library file="plugins/Test_SiStrip_HistId.cc" name="Test_SiStrip_HistId">
<library file="plugins/testSiStripHistId.cc" name="testSiStripHistId">
<flags EDM_PLUGIN="1"/>
</library>

<test name="test_TkHistoMap" command="cmsRun ${LOCALTOP}/src/DQM/SiStripCommon/test/testTkHistoMap_cfg.py"/>
<test name="test_SiStripHitId" command="cmsRun ${LOCALTOP}/src/DQM/SiStripCommon/test/testSiStripHistId_cfg.py"/>
57 changes: 0 additions & 57 deletions DQM/SiStripCommon/test/plugins/Test_SiStrip_HistId.cc

This file was deleted.

56 changes: 56 additions & 0 deletions DQM/SiStripCommon/test/plugins/testSiStripHistId.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// Original Author: Dorian Kcira
// Created: Thu Feb 23 18:50:29 CET 2006
//
//
// test HistId classes of SiStrip

// system include files
#include <memory>
#include <iostream>

// user include files
#include "DQM/SiStripCommon/interface/SiStripHistoId.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/global/EDAnalyzer.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

class testSiStripHistId : public edm::global::EDAnalyzer<> {
public:
explicit testSiStripHistId(const edm::ParameterSet&);
~testSiStripHistId() = default;

private:
void analyze(edm::StreamID, edm::Event const& iEvent, edm::EventSetup const& iSetup) const override;
};

testSiStripHistId::testSiStripHistId(const edm::ParameterSet& iConfig) {}

void testSiStripHistId::analyze(edm::StreamID, edm::Event const& iEvent, edm::EventSetup const& iSetup) const {
// use SistripHistoId for producing histogram id (and title)
SiStripHistoId hidmanager;
edm::LogPrint("testSiStripHistId") << "------------------------------------";
std::string hid1 = hidmanager.createHistoId("Cluster Distribution", "det", 2345698);
edm::LogPrint("testSiStripHistId") << "created hid1: >>" << hid1 << "<<";
std::string hid2 = hidmanager.createHistoId("Cluster Distribution", "fec", 1234);
edm::LogPrint("testSiStripHistId") << "created hid2: >>" << hid2 << "<<";
std::string hid3 = hidmanager.createHistoId("Cluster Distribution", "fed", 5678);
edm::LogPrint("testSiStripHistId") << "created hid3: >>" << hid3 << "<<";
edm::LogPrint("testSiStripHistId") << "------------------------------------";
edm::LogPrint("testSiStripHistId") << "hid1 component id / component type: " << hidmanager.getComponentId(hid1)
<< " / " << hidmanager.getComponentType(hid1);
edm::LogPrint("testSiStripHistId") << "hid2 component id / component type: " << hidmanager.getComponentId(hid2)
<< " / " << hidmanager.getComponentType(hid2);
edm::LogPrint("testSiStripHistId") << "hid3 component id / component type: " << hidmanager.getComponentId(hid3)
<< " / " << hidmanager.getComponentType(hid3);
edm::LogPrint("testSiStripHistId") << "------------------------------------";
std::string hid4 = "just for_testing% _#31";
edm::LogPrint("testSiStripHistId") << "hid4=" << hid4;
edm::LogPrint("testSiStripHistId") << "hid4 component id / component type: " << hidmanager.getComponentId(hid4)
<< " / " << hidmanager.getComponentType(hid4);
edm::LogPrint("testSiStripHistId") << "------------------------------------";
}

//define this as a plug-in
#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(testSiStripHistId);
11 changes: 7 additions & 4 deletions DQM/SiStripCommon/test/plugins/testTkHistoMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ class testTkHistoMap : public DQMOneEDAnalyzer<> {
const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkGeoToken;

bool readFromFile;
std::unique_ptr<TkHistoMap> tkhisto, tkhistoBis, tkhistoZ, tkhistoPhi, tkhistoR, tkhistoCheck;
std::unique_ptr<TkHistoMap> tkhistoID, tkhisto, tkhistoBis, tkhistoZ, tkhistoPhi, tkhistoR, tkhistoCheck;
};

//
testTkHistoMap::testTkHistoMap(const edm::ParameterSet& iConfig)
: tTopoToken(esConsumes()), tkGeoToken(esConsumes()), readFromFile(iConfig.getParameter<bool>("readFromFile")) {}

void testTkHistoMap::create(const TkDetMap* tkDetMap) {
tkhistoID = std::make_unique<TkHistoMap>(tkDetMap, "detIdV", "detIdV", -1);
tkhisto = std::make_unique<TkHistoMap>(tkDetMap, "detId", "detId", -1);
tkhistoBis = std::make_unique<TkHistoMap>(
tkDetMap,
Expand All @@ -78,13 +79,15 @@ void testTkHistoMap::create(const TkDetMap* tkDetMap) {
void testTkHistoMap::read(const TkDetMap* tkDetMap) {
edm::Service<DQMStore>().operator->()->open("test.root");

tkhistoID = std::make_unique<TkHistoMap>(tkDetMap);
tkhisto = std::make_unique<TkHistoMap>(tkDetMap);
tkhistoBis = std::make_unique<TkHistoMap>(tkDetMap);
tkhistoZ = std::make_unique<TkHistoMap>(tkDetMap);
tkhistoPhi = std::make_unique<TkHistoMap>(tkDetMap);
tkhistoR = std::make_unique<TkHistoMap>(tkDetMap);
tkhistoCheck = std::make_unique<TkHistoMap>(tkDetMap);

tkhistoID->loadTkHistoMap("detIdV", "detIdV");
tkhisto->loadTkHistoMap("detId", "detId");
tkhistoBis->loadTkHistoMap("detIdBis", "detIdBis", true);
tkhistoZ->loadTkHistoMap("Zmap", "Zmap");
Expand Down Expand Up @@ -190,7 +193,7 @@ void testTkHistoMap::analyze(const edm::Event& iEvent, const edm::EventSetup& iS

value = id % 1000000;

//tkhisto->fill(id,value);
tkhistoID->fill(id, value);
//tkhistoBis->fill(id,value);
tkhistoZ->fill(id, globalPos.z());
tkhistoPhi->fill(id, globalPos.phi());
Expand All @@ -201,9 +204,9 @@ void testTkHistoMap::analyze(const edm::Event& iEvent, const edm::EventSetup& iS
edm::LogInfo("testTkHistoMap") << "detid " << id.rawId() << " pos z " << globalPos.z() << " phi "
<< globalPos.phi() << " r " << globalPos.perp() << std::endl;

if (value != tkhisto->getValue(id))
if (value != tkhistoID->getValue(id))
edm::LogError("testTkHistoMap") << " input value " << value << " differs from read value "
<< tkhisto->getValue(id) << std::endl;
<< tkhistoID->getValue(id) << std::endl;

// For usage that reset histo content use setBinContent instead than fill
/*
Expand Down
13 changes: 13 additions & 0 deletions DQM/SiStripCommon/test/testSiStripHistId_cfg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import FWCore.ParameterSet.Config as cms

process = cms.Process("DBTest")
process.source = cms.Source("EmptySource")

process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(1)
)

process.print = cms.OutputModule("AsciiOutputModule")
process.read = cms.EDAnalyzer("testSiStripHistId")

process.p1 = cms.EndPath(process.read+process.print)
15 changes: 6 additions & 9 deletions DQM/SiStripCommon/test/testTkHistoMap_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
process = cms.Process("test")

process.load("Geometry.TrackerGeometryBuilder.trackerGeometry_cfi")

process.load("Geometry.TrackerNumberingBuilder.trackerNumberingGeometry_cfi")

process.load("Geometry.TrackerGeometryBuilder.TrackerAdditionalParametersPerDet_cfi")
process.load("Geometry.CMSCommonData.cmsIdealGeometryXML_cfi")

process.load("Alignment.CommonAlignmentProducer.FakeAlignmentSource_cfi")

process.MessageLogger = cms.Service("MessageLogger",
Expand All @@ -16,7 +14,7 @@
),
cout = cms.untracked.PSet(
enable = cms.untracked.bool(True),
threshold = cms.untracked.string('DEBUG')
threshold = cms.untracked.string('WARNING')
),
debugModules = cms.untracked.vstring('*')
)
Expand All @@ -31,9 +29,8 @@
process.load("Geometry.TrackerGeometryBuilder.trackerParameters_cfi")
process.trackerTopology = cms.ESProducer("TrackerTopologyEP")

process.tester = cms.EDAnalyzer("testTkHistoMap",
readFromFile = cms.bool(False)
)
process.p = cms.Path(process.tester)

from DQMServices.Core.DQMEDAnalyzer import DQMEDAnalyzer
process.tester = DQMEDAnalyzer("testTkHistoMap",
readFromFile = cms.bool(False))

process.p = cms.Path(process.tester)
14 changes: 0 additions & 14 deletions DQM/SiStripCommon/test/test_id_cfg.py

This file was deleted.

0 comments on commit 9fc5d08

Please sign in to comment.