Skip to content

Commit

Permalink
Merge pull request #40963 from mmusich/fixSegFaultForSiStripFromCalib…
Browse files Browse the repository at this point in the history
…Tree_ASANX

fix segmentation violation in `SiStripHitEffFromCalibTree` and `SiStripHitResolFromCalibTree` in ASAN_X
  • Loading branch information
cmsbuild authored Mar 6, 2023
2 parents cade7ad + fd13c2d commit 84d0cf6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class SiStripHitEffFromCalibTree : public ConditionDBWriter<SiStripBadStrip> {

// to be used everywhere
static constexpr int SiStripLayers = 22;
static constexpr double nBxInAnOrbit = 3565;

edm::Service<TFileService> fs;
SiStripDetInfo _detInfo;
Expand Down Expand Up @@ -179,6 +180,8 @@ class SiStripHitEffFromCalibTree : public ConditionDBWriter<SiStripBadStrip> {
vector<TH1F*> layertotal_vsPU;
vector<TH1F*> layerfound_vsCM;
vector<TH1F*> layertotal_vsCM;
vector<TH1F*> layerfound_vsBX;
vector<TH1F*> layertotal_vsBX;
int goodlayertotal[35];
int goodlayerfound[35];
int alllayertotal[35];
Expand Down Expand Up @@ -284,6 +287,11 @@ void SiStripHitEffFromCalibTree::algoAnalyze(const edm::Event& e, const edm::Eve
layertotal_vsPU.push_back(
fs->make<TH1F>(Form("layertotal_vsPU_layer_%i", (int)(ilayer)), lyrName.c_str(), 45, 0, 90));

layerfound_vsBX.push_back(fs->make<TH1F>(
Form("foundVsBx_layer%i", (int)ilayer), Form("layer %i", (int)ilayer), nBxInAnOrbit, 0, nBxInAnOrbit));
layertotal_vsBX.push_back(fs->make<TH1F>(
Form("totalVsBx_layer%i", (int)ilayer), Form("layer %i", (int)ilayer), nBxInAnOrbit, 0, nBxInAnOrbit));

if (_useCM) {
layerfound_vsCM.push_back(
fs->make<TH1F>(Form("layerfound_vsCM_layer_%i", (int)(ilayer)), lyrName.c_str(), 20, 0, 400));
Expand Down Expand Up @@ -1376,27 +1384,25 @@ void SiStripHitEffFromCalibTree::makeSummaryVsBx() {
nLayers = 20;

for (unsigned int ilayer = 1; ilayer < nLayers; ilayer++) {
TH1F* hfound = fs->make<TH1F>(Form("foundVsBx_layer%i", ilayer), Form("layer %i", ilayer), 3565, 0, 3565);
TH1F* htotal = fs->make<TH1F>(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<unsigned int, vector<int> >::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<TGraphAsymmErrors>(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<TGraphAsymmErrors>();
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class SiStripHitResolFromCalibTree : public ConditionDBWriter<SiStripBadStrip> {
TString GetLayerSideName(Long_t k);
float calcPhi(float x, float y);

static constexpr double nBxInAnOrbit = 3565;

SiStripDetInfo detInfo_;
edm::FileInPath FileInPath_;
SiStripQuality* quality_;
Expand Down Expand Up @@ -155,6 +157,8 @@ class SiStripHitResolFromCalibTree : public ConditionDBWriter<SiStripBadStrip> {
vector<TH1F*> layertotal_vsPU;
vector<TH1F*> layerfound_vsCM;
vector<TH1F*> layertotal_vsCM;
vector<TH1F*> layerfound_vsBX;
vector<TH1F*> 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];
Expand Down Expand Up @@ -302,6 +306,11 @@ void SiStripHitResolFromCalibTree::algoAnalyze(const edm::Event& e, const edm::E
layertotal_vsPU.push_back(
fs->make<TH1F>(Form("layertotal_vsPU_layer_%i", (int)(ilayer)), GetLayerName(ilayer), 45, 0, 90));

layerfound_vsBX.push_back(fs->make<TH1F>(
Form("foundVsBx_layer%i", (int)ilayer), Form("layer %i", (int)ilayer), nBxInAnOrbit, 0, nBxInAnOrbit));
layertotal_vsBX.push_back(fs->make<TH1F>(
Form("totalVsBx_layer%i", (int)ilayer), Form("layer %i", (int)ilayer), nBxInAnOrbit, 0, nBxInAnOrbit));

if (useCM_) {
layerfound_vsCM.push_back(
fs->make<TH1F>(Form("layerfound_vsCM_layer_%i", (int)(ilayer)), GetLayerName(ilayer), 20, 0, 400));
Expand Down Expand Up @@ -1470,27 +1479,25 @@ void SiStripHitResolFromCalibTree::makeSummaryVsBx(const edm::Service<TFileServi
nLayers = 20;

for (unsigned int ilayer = 1; ilayer < nLayers; ilayer++) {
TH1F* hfound = fs->make<TH1F>(Form("foundVsBx_layer%i", ilayer), Form("layer %i", ilayer), 3565, 0, 3565);
TH1F* htotal = fs->make<TH1F>(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<unsigned int, vector<int> >::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<TGraphAsymmErrors>(3564);
TGraphAsymmErrors* geff = fs->make<TGraphAsymmErrors>(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<TGraphAsymmErrors>();
Expand Down Expand Up @@ -1526,8 +1533,8 @@ void SiStripHitResolFromCalibTree::makeSummaryVsBx(const edm::Service<TFileServi
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', '')

Expand All @@ -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),
Expand Down Expand Up @@ -81,4 +99,4 @@
fileName = cms.string(RootFileName)
)

process.allPath = cms.Path(process.SiStripHitEff)
process.allPath = cms.Path(process.SiStripHitResolFromCalibTree)

0 comments on commit 84d0cf6

Please sign in to comment.