From fd13c2d1efb8edc52ecf55fc2be6d569487d827d Mon Sep 17 00:00:00 2001 From: mmusich Date: Mon, 6 Mar 2023 17:29:48 +0100 Subject: [PATCH] fix segmentation violation in SiStripHitEffFromCalibTree and SiStripHitResolFromCalibTree in ASAN_X --- .../plugins/SiStripHitEffFromCalibTree.cc | 30 +++++++++------- .../plugins/SiStripHitResolFromCalibTree.cc | 35 +++++++++++-------- .../SiStripHitResolutionFromCalibTree_cfg.py | 22 ++++++++++-- 3 files changed, 59 insertions(+), 28 deletions(-) diff --git a/CalibTracker/SiStripHitEfficiency/plugins/SiStripHitEffFromCalibTree.cc b/CalibTracker/SiStripHitEfficiency/plugins/SiStripHitEffFromCalibTree.cc index d51f2f36adb7b..7619a84bd51d0 100644 --- a/CalibTracker/SiStripHitEfficiency/plugins/SiStripHitEffFromCalibTree.cc +++ b/CalibTracker/SiStripHitEfficiency/plugins/SiStripHitEffFromCalibTree.cc @@ -119,6 +119,7 @@ class SiStripHitEffFromCalibTree : public ConditionDBWriter { // to be used everywhere static constexpr int SiStripLayers = 22; + static constexpr double nBxInAnOrbit = 3565; edm::Service fs; SiStripDetInfo _detInfo; @@ -179,6 +180,8 @@ class SiStripHitEffFromCalibTree : public ConditionDBWriter { vector layertotal_vsPU; vector layerfound_vsCM; vector layertotal_vsCM; + vector layerfound_vsBX; + vector layertotal_vsBX; int goodlayertotal[35]; int goodlayerfound[35]; int alllayertotal[35]; @@ -284,6 +287,11 @@ void SiStripHitEffFromCalibTree::algoAnalyze(const edm::Event& e, const edm::Eve layertotal_vsPU.push_back( fs->make(Form("layertotal_vsPU_layer_%i", (int)(ilayer)), lyrName.c_str(), 45, 0, 90)); + layerfound_vsBX.push_back(fs->make( + Form("foundVsBx_layer%i", (int)ilayer), Form("layer %i", (int)ilayer), nBxInAnOrbit, 0, nBxInAnOrbit)); + layertotal_vsBX.push_back(fs->make( + Form("totalVsBx_layer%i", (int)ilayer), Form("layer %i", (int)ilayer), nBxInAnOrbit, 0, nBxInAnOrbit)); + if (_useCM) { layerfound_vsCM.push_back( fs->make(Form("layerfound_vsCM_layer_%i", (int)(ilayer)), lyrName.c_str(), 20, 0, 400)); @@ -1376,27 +1384,25 @@ void SiStripHitEffFromCalibTree::makeSummaryVsBx() { nLayers = 20; for (unsigned int ilayer = 1; ilayer < nLayers; ilayer++) { - TH1F* hfound = fs->make(Form("foundVsBx_layer%i", ilayer), Form("layer %i", ilayer), 3565, 0, 3565); - TH1F* htotal = fs->make(Form("totalVsBx_layer%i", ilayer), Form("layer %i", ilayer), 3565, 0, 3565); - for (unsigned int ibx = 0; ibx < 3566; ibx++) { - hfound->SetBinContent(ibx, 1e-6); - htotal->SetBinContent(ibx, 1); + layerfound_vsBX[ilayer]->SetBinContent(ibx, 1e-6); + layertotal_vsBX[ilayer]->SetBinContent(ibx, 1); } + map >::iterator iterMapvsBx; for (iterMapvsBx = layerfound_perBx.begin(); iterMapvsBx != layerfound_perBx.end(); ++iterMapvsBx) - hfound->SetBinContent(iterMapvsBx->first, iterMapvsBx->second[ilayer]); + layerfound_vsBX[ilayer]->SetBinContent(iterMapvsBx->first, iterMapvsBx->second[ilayer]); for (iterMapvsBx = layertotal_perBx.begin(); iterMapvsBx != layertotal_perBx.end(); ++iterMapvsBx) if (iterMapvsBx->second[ilayer] > 0) - htotal->SetBinContent(iterMapvsBx->first, iterMapvsBx->second[ilayer]); + layertotal_vsBX[ilayer]->SetBinContent(iterMapvsBx->first, iterMapvsBx->second[ilayer]); - hfound->Sumw2(); - htotal->Sumw2(); + layerfound_vsBX[ilayer]->Sumw2(); + layertotal_vsBX[ilayer]->Sumw2(); TGraphAsymmErrors* geff = fs->make(3564); geff->SetName(Form("effVsBx_layer%i", ilayer)); geff->SetTitle(fmt::format("Hit Efficiency vs bx - {}", ::layerName(ilayer, _showRings, nTEClayers)).c_str()); - geff->BayesDivide(hfound, htotal); + geff->BayesDivide(layerfound_vsBX[ilayer], layertotal_vsBX[ilayer]); //Average over trains TGraphAsymmErrors* geff_avg = fs->make(); @@ -1432,8 +1438,8 @@ void SiStripHitEffFromCalibTree::makeSummaryVsBx() { firstbx = ibx; } sum_bx += ibx; - found += hfound->GetBinContent(ibx); - total += htotal->GetBinContent(ibx); + found += layerfound_vsBX[ilayer]->GetBinContent(ibx); + total += layertotal_vsBX[ilayer]->GetBinContent(ibx); nbx++; previous_bx = ibx; diff --git a/CalibTracker/SiStripHitResolution/plugins/SiStripHitResolFromCalibTree.cc b/CalibTracker/SiStripHitResolution/plugins/SiStripHitResolFromCalibTree.cc index 125d462fe3f6c..863c3aa338275 100644 --- a/CalibTracker/SiStripHitResolution/plugins/SiStripHitResolFromCalibTree.cc +++ b/CalibTracker/SiStripHitResolution/plugins/SiStripHitResolFromCalibTree.cc @@ -97,6 +97,8 @@ class SiStripHitResolFromCalibTree : public ConditionDBWriter { TString GetLayerSideName(Long_t k); float calcPhi(float x, float y); + static constexpr double nBxInAnOrbit = 3565; + SiStripDetInfo detInfo_; edm::FileInPath FileInPath_; SiStripQuality* quality_; @@ -155,6 +157,8 @@ class SiStripHitResolFromCalibTree : public ConditionDBWriter { vector layertotal_vsPU; vector layerfound_vsCM; vector layertotal_vsCM; + vector layerfound_vsBX; + vector layertotal_vsBX; int goodlayertotal[::k_END_OF_LAYS_AND_RINGS]; int goodlayerfound[::k_END_OF_LAYS_AND_RINGS]; int alllayertotal[::k_END_OF_LAYS_AND_RINGS]; @@ -302,6 +306,11 @@ void SiStripHitResolFromCalibTree::algoAnalyze(const edm::Event& e, const edm::E layertotal_vsPU.push_back( fs->make(Form("layertotal_vsPU_layer_%i", (int)(ilayer)), GetLayerName(ilayer), 45, 0, 90)); + layerfound_vsBX.push_back(fs->make( + Form("foundVsBx_layer%i", (int)ilayer), Form("layer %i", (int)ilayer), nBxInAnOrbit, 0, nBxInAnOrbit)); + layertotal_vsBX.push_back(fs->make( + Form("totalVsBx_layer%i", (int)ilayer), Form("layer %i", (int)ilayer), nBxInAnOrbit, 0, nBxInAnOrbit)); + if (useCM_) { layerfound_vsCM.push_back( fs->make(Form("layerfound_vsCM_layer_%i", (int)(ilayer)), GetLayerName(ilayer), 20, 0, 400)); @@ -1470,27 +1479,25 @@ void SiStripHitResolFromCalibTree::makeSummaryVsBx(const edm::Servicemake(Form("foundVsBx_layer%i", ilayer), Form("layer %i", ilayer), 3565, 0, 3565); - TH1F* htotal = fs->make(Form("totalVsBx_layer%i", ilayer), Form("layer %i", ilayer), 3565, 0, 3565); - - for (unsigned int ibx = 0; ibx < 3566; ibx++) { - hfound->SetBinContent(ibx, 1e-6); - htotal->SetBinContent(ibx, 1); + for (unsigned int ibx = 0; ibx <= nBxInAnOrbit; ibx++) { + layerfound_vsBX[ilayer]->SetBinContent(ibx, 1e-6); + layertotal_vsBX[ilayer]->SetBinContent(ibx, 1); } + map >::iterator iterMapvsBx; for (iterMapvsBx = layerfound_perBx.begin(); iterMapvsBx != layerfound_perBx.end(); ++iterMapvsBx) - hfound->SetBinContent(iterMapvsBx->first, iterMapvsBx->second[ilayer]); + layerfound_vsBX[ilayer]->SetBinContent(iterMapvsBx->first, iterMapvsBx->second[ilayer]); for (iterMapvsBx = layertotal_perBx.begin(); iterMapvsBx != layertotal_perBx.end(); ++iterMapvsBx) if (iterMapvsBx->second[ilayer] > 0) - htotal->SetBinContent(iterMapvsBx->first, iterMapvsBx->second[ilayer]); + layertotal_vsBX[ilayer]->SetBinContent(iterMapvsBx->first, iterMapvsBx->second[ilayer]); - hfound->Sumw2(); - htotal->Sumw2(); + layerfound_vsBX[ilayer]->Sumw2(); + layertotal_vsBX[ilayer]->Sumw2(); - TGraphAsymmErrors* geff = fs->make(3564); + TGraphAsymmErrors* geff = fs->make(nBxInAnOrbit - 1); geff->SetName(Form("effVsBx_layer%i", ilayer)); geff->SetTitle("Hit Efficiency vs bx - " + GetLayerName(ilayer)); - geff->BayesDivide(hfound, htotal); + geff->BayesDivide(layerfound_vsBX[ilayer], layertotal_vsBX[ilayer]); //Average over trains TGraphAsymmErrors* geff_avg = fs->make(); @@ -1526,8 +1533,8 @@ void SiStripHitResolFromCalibTree::makeSummaryVsBx(const edm::ServiceGetBinContent(ibx); - total += htotal->GetBinContent(ibx); + found += layerfound_vsBX[ilayer]->GetBinContent(ibx); + total += layertotal_vsBX[ilayer]->GetBinContent(ibx); nbx++; previous_bx = ibx; diff --git a/CalibTracker/SiStripHitResolution/test/SiStripHitResolutionFromCalibTree_cfg.py b/CalibTracker/SiStripHitResolution/test/SiStripHitResolutionFromCalibTree_cfg.py index bbfc99817d68b..0c9f48ce9f8e7 100644 --- a/CalibTracker/SiStripHitResolution/test/SiStripHitResolutionFromCalibTree_cfg.py +++ b/CalibTracker/SiStripHitResolution/test/SiStripHitResolutionFromCalibTree_cfg.py @@ -4,6 +4,24 @@ process.load("Configuration.StandardSequences.GeometryRecoDB_cff") process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') + +################################################################### +# Messages +################################################################### +process.load('FWCore.MessageService.MessageLogger_cfi') +process.MessageLogger.cerr.enable = False +process.MessageLogger.SiStripHitResolFromCalibTree=dict() +process.MessageLogger.cout = cms.untracked.PSet( + enable = cms.untracked.bool(True), + threshold = cms.untracked.string("INFO"), + default = cms.untracked.PSet(limit = cms.untracked.int32(0)), + FwkReport = cms.untracked.PSet(limit = cms.untracked.int32(-1), + reportEvery = cms.untracked.int32(1000) + ), + #SiStripHitResolFromCalibTree = cms.untracked.PSet( limit = cms.untracked.int32(-1)), + enableStatistics = cms.untracked.bool(True) + ) + from Configuration.AlCa.GlobalTag import GlobalTag process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_data', '') @@ -24,7 +42,7 @@ FileName1 = InputFilePath + str(RunNumberBegin) + InputFilePathEnd -process.SiStripHitEff = cms.EDAnalyzer("SiStripHitResolFromCalibTree", +process.SiStripHitResolFromCalibTree = cms.EDAnalyzer("SiStripHitResolFromCalibTree", CalibTreeFilenames = cms.untracked.vstring(FileName1), Threshold = cms.double(0.2), nModsMin = cms.int32(25), @@ -81,4 +99,4 @@ fileName = cms.string(RootFileName) ) -process.allPath = cms.Path(process.SiStripHitEff) +process.allPath = cms.Path(process.SiStripHitResolFromCalibTree)