From 45d22a412cec615a6e8e381ca5b2ded6543e290b Mon Sep 17 00:00:00 2001 From: mmusich Date: Wed, 29 May 2024 17:13:09 +0200 Subject: [PATCH] further improvements in CalibTracker/SiStripHit* plugins --- .../plugins/SiStripHitEffFromCalibTree.cc | 100 +++++++++++------- .../test/testHitEffWorker.py | 10 -- .../plugins/SiStripHitResolFromCalibTree.cc | 97 +++++++++++------ 3 files changed, 122 insertions(+), 85 deletions(-) diff --git a/CalibTracker/SiStripHitEfficiency/plugins/SiStripHitEffFromCalibTree.cc b/CalibTracker/SiStripHitEfficiency/plugins/SiStripHitEffFromCalibTree.cc index a29991f34d69b..acb4dc6c13983 100644 --- a/CalibTracker/SiStripHitEfficiency/plugins/SiStripHitEffFromCalibTree.cc +++ b/CalibTracker/SiStripHitEfficiency/plugins/SiStripHitEffFromCalibTree.cc @@ -114,7 +114,7 @@ class SiStripHitEffFromCalibTree : public ConditionDBWriter { void totalStatistics(); void makeSummary(); void makeSummaryVsBx(); - void computeEff(vector& vhfound, vector& vhtotal, string name); + void computeEff(vector& vhfound, vector& vhtotal, string name, vector geff); void makeSummaryVsLumi(); void makeSummaryVsCM(); TString getLayerSideName(Long_t k); @@ -172,11 +172,11 @@ class SiStripHitEffFromCalibTree : public ConditionDBWriter { vector hits[::k_END_OF_LAYERS]; vector HotColdMaps; map > modCounter[::k_END_OF_LAYERS]; - TrackerMap* tkmap; - TrackerMap* tkmapbad; - TrackerMap* tkmapeff; - TrackerMap* tkmapnum; - TrackerMap* tkmapden; + TrackerMap* tkmap{nullptr}; + TrackerMap* tkmapbad{nullptr}; + TrackerMap* tkmapeff{nullptr}; + TrackerMap* tkmapnum{nullptr}; + TrackerMap* tkmapden{nullptr}; long layerfound[::k_END_OF_LAYERS]; long layertotal[::k_END_OF_LAYERS]; map > layerfound_perBx; @@ -189,6 +189,11 @@ class SiStripHitEffFromCalibTree : public ConditionDBWriter { vector layertotal_vsCM; vector layerfound_vsBX; vector layertotal_vsBX; + vector geff_vsBX; + vector geff_avg_vsBX; + vector geff_avg_vsLumi; + vector geff_avg_vsPU; + vector geff_avg_vsCM; int goodlayertotal[::k_END_OF_LAYS_AND_RINGS]; int goodlayerfound[::k_END_OF_LAYS_AND_RINGS]; int alllayertotal[::k_END_OF_LAYS_AND_RINGS]; @@ -239,6 +244,11 @@ SiStripHitEffFromCalibTree::SiStripHitEffFromCalibTree(const edm::ParameterSet& layertotal_vsCM.reserve(::k_END_OF_LAYERS); layerfound_vsBX.reserve(::k_END_OF_LAYERS); layertotal_vsBX.reserve(::k_END_OF_LAYERS); + geff_vsBX.reserve(::k_END_OF_LAYERS); + geff_avg_vsBX.reserve(::k_END_OF_LAYERS); + geff_avg_vsLumi.reserve(::k_END_OF_LAYERS); + geff_avg_vsPU.reserve(::k_END_OF_LAYERS); + geff_avg_vsCM.reserve(::k_END_OF_LAYERS); } namespace utils { @@ -296,8 +306,7 @@ SiStripHitEffFromCalibTree::~SiStripHitEffFromCalibTree() { edm::LogPrint("") << __PRETTY_FUNCTION__ << " File has inconsistent hash: " << tFile.HasInconsistentHash() << std::endl; - bool debug{false}; - + bool debug{false}; // the following is only used for debugging purposes if (!tFile.IsZombie() && tFile.IsWritable() && debug) { // Delete all objects in the file recursively utils::Recursion(&tFile, &tFile); @@ -359,7 +368,7 @@ void SiStripHitEffFromCalibTree::algoAnalyze(const edm::Event& e, const edm::Eve TH1F* resolutionPlots[::k_END_OF_LAYERS]; for (Long_t ilayer = 0; ilayer < ::k_END_OF_LAYERS; ilayer++) { - std::string lyrName = ::layerName(ilayer, showRings_, nTEClayers); + std::string lyrName = ::layerName(ilayer + 1, showRings_, nTEClayers); resolutionPlots[ilayer] = fs->make(Form("resol_layer_%i", (int)(ilayer)), lyrName.c_str(), 125, -125, 125); resolutionPlots[ilayer]->GetXaxis()->SetTitle("trajX-clusX [strip unit]"); @@ -378,11 +387,35 @@ void SiStripHitEffFromCalibTree::algoAnalyze(const edm::Event& e, const edm::Eve layertotal_vsBX.push_back(fs->make( Form("totalVsBx_layer%i", (int)ilayer), Form("layer %i", (int)ilayer), nBxInAnOrbit_, 0, nBxInAnOrbit_)); + geff_vsBX.push_back(fs->make(nBxInAnOrbit_ - 1)); + geff_vsBX[ilayer]->SetName(Form("effVsBx_layer%i", (int)ilayer)); + geff_vsBX[ilayer]->SetTitle(fmt::format("Hit Efficiency vs bx - {}", lyrName).c_str()); + + geff_avg_vsBX.push_back(fs->make(nBxInAnOrbit_ - 1)); + geff_avg_vsBX[ilayer]->SetName(Form("effVsBxAvg_layer%i", (int)ilayer)); + geff_avg_vsBX[ilayer]->SetTitle(fmt::format("Hit Efficiency vs bx - {}", lyrName).c_str()); + geff_avg_vsBX[ilayer]->SetMarkerStyle(20); + + geff_avg_vsLumi.push_back(fs->make(99)); + geff_avg_vsLumi[ilayer]->SetName(Form("effVsLumiAvg_layer%i", (int)ilayer)); + geff_avg_vsLumi[ilayer]->SetTitle(fmt::format("Hit Efficiency vs inst. lumi. - {}", lyrName).c_str()); + geff_avg_vsLumi[ilayer]->SetMarkerStyle(20); + + geff_avg_vsPU.push_back(fs->make(44)); + geff_avg_vsPU[ilayer]->SetName(Form("effVsPUAvg_layer%i", (int)ilayer)); + geff_avg_vsPU[ilayer]->SetTitle(fmt::format("Hit Efficiency vs pileup - {}", lyrName).c_str()); + geff_avg_vsPU[ilayer]->SetMarkerStyle(20); + if (useCM_) { layerfound_vsCM.push_back( fs->make(Form("layerfound_vsCM_layer_%i", (int)(ilayer)), lyrName.c_str(), 20, 0, 400)); layertotal_vsCM.push_back( fs->make(Form("layertotal_vsCM_layer_%i", (int)(ilayer)), lyrName.c_str(), 20, 0, 400)); + + geff_avg_vsCM.push_back(fs->make(19)); + geff_avg_vsCM[ilayer]->SetName(Form("effVsCMAvg_layer%i", (int)ilayer)); + geff_avg_vsCM[ilayer]->SetTitle(fmt::format("Hit Efficiency vs common Mode - {}", lyrName).c_str()); + geff_avg_vsCM[ilayer]->SetMarkerStyle(20); } layertotal[ilayer] = 0; layerfound[ilayer] = 0; @@ -1528,7 +1561,7 @@ void SiStripHitEffFromCalibTree::makeSummaryVsBx() { if (showRings_) nLayers = 20; - for (unsigned int ilayer = 1; ilayer < nLayers; ilayer++) { + for (unsigned int ilayer = 0; ilayer <= nLayers; ilayer++) { for (unsigned int ibx = 0; ibx <= nBxInAnOrbit_; ibx++) { layerfound_vsBX[ilayer]->SetBinContent(ibx, 1e-6); layertotal_vsBX[ilayer]->SetBinContent(ibx, 1); @@ -1546,17 +1579,9 @@ void SiStripHitEffFromCalibTree::makeSummaryVsBx() { layerfound_vsBX[ilayer]->Sumw2(); layertotal_vsBX[ilayer]->Sumw2(); - TGraphAsymmErrors* geff = fs->make(nBxInAnOrbit_ - 1); - geff->SetName(Form("effVsBx_layer%i", ilayer)); - - geff->SetTitle(fmt::format("Hit Efficiency vs bx - {}", ::layerName(ilayer, showRings_, nTEClayers)).c_str()); - geff->BayesDivide(layerfound_vsBX[ilayer], layertotal_vsBX[ilayer]); + geff_vsBX[ilayer]->BayesDivide(layerfound_vsBX[ilayer], layertotal_vsBX[ilayer]); //Average over trains - TGraphAsymmErrors* geff_avg = fs->make(); - geff_avg->SetName(Form("effVsBxAvg_layer%i", ilayer)); - geff_avg->SetTitle(fmt::format("Hit Efficiency vs bx - {}", ::layerName(ilayer, showRings_, nTEClayers)).c_str()); - geff_avg->SetMarkerStyle(20); int ibx = 0; int previous_bx = -80; int delta_bx = 0; @@ -1574,10 +1599,11 @@ void SiStripHitEffFromCalibTree::makeSummaryVsBx() { if (delta_bx > (int)spaceBetweenTrains_ && nbx > 0 && total > 0) { eff = found / (float)total; //LOGPRINT<<"new train "<SetPoint(ipt, sum_bx / nbx, eff); + geff_avg_vsBX[ilayer]->SetPoint(ipt, sum_bx / nbx, eff); low = TEfficiency::Bayesian(total, found, .683, 1, 1, false); up = TEfficiency::Bayesian(total, found, .683, 1, 1, true); - geff_avg->SetPointError(ipt, sum_bx / nbx - firstbx, previous_bx - sum_bx / nbx, eff - low, up - eff); + geff_avg_vsBX[ilayer]->SetPointError( + ipt, sum_bx / nbx - firstbx, previous_bx - sum_bx / nbx, eff - low, up - eff); ipt++; sum_bx = 0; found = 0; @@ -1595,14 +1621,17 @@ void SiStripHitEffFromCalibTree::makeSummaryVsBx() { //last train eff = found / (float)total; //LOGPRINT<<"new train "<SetPoint(ipt, sum_bx / nbx, eff); + geff_avg_vsBX[ilayer]->SetPoint(ipt, sum_bx / nbx, eff); low = TEfficiency::Bayesian(total, found, .683, 1, 1, false); up = TEfficiency::Bayesian(total, found, .683, 1, 1, true); - geff_avg->SetPointError(ipt, sum_bx / nbx - firstbx, previous_bx - sum_bx / nbx, eff - low, up - eff); + geff_avg_vsBX[ilayer]->SetPointError(ipt, sum_bx / nbx - firstbx, previous_bx - sum_bx / nbx, eff - low, up - eff); } } -void SiStripHitEffFromCalibTree::computeEff(vector& vhfound, vector& vhtotal, string name) { +void SiStripHitEffFromCalibTree::computeEff(vector& vhfound, + vector& vhtotal, + string name, + vector geff) { unsigned int nLayers = siStripLayers_; if (showRings_) nLayers = 20; @@ -1610,7 +1639,7 @@ void SiStripHitEffFromCalibTree::computeEff(vector& vhfound, vector& vhfound, vectorSetBinContent(i, 1); } - TGraphAsymmErrors* geff = fs->make(hfound->GetNbinsX()); - geff->SetName(Form("%s_layer%i", name.c_str(), ilayer)); - geff->BayesDivide(hfound, htotal); - if (name == "effVsLumi") - geff->SetTitle( - fmt::format("Hit Efficiency vs inst. lumi. - {}", ::layerName(ilayer, showRings_, nTEClayers)).c_str()); - if (name == "effVsPU") - geff->SetTitle(fmt::format("Hit Efficiency vs pileup - {}", ::layerName(ilayer, showRings_, nTEClayers)).c_str()); - if (name == "effVsCM") - geff->SetTitle( - fmt::format("Hit Efficiency vs common Mode - {}", ::layerName(ilayer, showRings_, nTEClayers)).c_str()); - geff->SetMarkerStyle(20); + geff[ilayer]->BayesDivide(hfound, htotal); } } @@ -1659,7 +1677,7 @@ void SiStripHitEffFromCalibTree::makeSummaryVsLumi() { float avgPU = 0; LOGPRINT << "Lumi summary: (avg over trajectory measurements)"; - for (unsigned int ilayer = 1; ilayer < nLayers; ilayer++) { + for (unsigned int ilayer = 0; ilayer <= nLayers; ilayer++) { layerLumi = layertotal_vsLumi[ilayer]->GetMean(); layerPU = layertotal_vsPU[ilayer]->GetMean(); //LOGPRINT<<" layer "< { void totalStatistics(); void makeSummary(const edm::Service& fs); void makeSummaryVsBx(const edm::Service& fs); - void ComputeEff(const edm::Service& fs, vector& vhfound, vector& vhtotal, string name); + void ComputeEff(const edm::Service& fs, + vector& vhfound, + vector& vhtotal, + string name, + vector geff); void makeSummaryVsLumi(const edm::Service& fs); void makeSummaryVsCM(const edm::Service& fs); TString GetLayerName(Long_t k); @@ -142,11 +146,11 @@ class SiStripHitResolFromCalibTree : public ConditionDBWriter { vector hits[::k_END_OF_LAYERS]; vector HotColdMaps; map > modCounter[::k_END_OF_LAYERS]; - TrackerMap* tkmap; - TrackerMap* tkmapbad; - TrackerMap* tkmapeff; - TrackerMap* tkmapnum; - TrackerMap* tkmapden; + TrackerMap* tkmap{nullptr}; + TrackerMap* tkmapbad{nullptr}; + TrackerMap* tkmapeff{nullptr}; + TrackerMap* tkmapnum{nullptr}; + TrackerMap* tkmapden{nullptr}; long layerfound[::k_END_OF_LAYERS]; long layertotal[::k_END_OF_LAYERS]; map > layerfound_perBx; @@ -159,6 +163,11 @@ class SiStripHitResolFromCalibTree : public ConditionDBWriter { vector layertotal_vsCM; vector layerfound_vsBX; vector layertotal_vsBX; + vector geff_vsBX; + vector geff_avg_vsBX; + vector geff_avg_vsLumi; + vector geff_avg_vsPU; + vector geff_avg_vsCM; int goodlayertotal[::k_END_OF_LAYS_AND_RINGS]; int goodlayerfound[::k_END_OF_LAYS_AND_RINGS]; int alllayertotal[::k_END_OF_LAYS_AND_RINGS]; @@ -208,6 +217,11 @@ SiStripHitResolFromCalibTree::SiStripHitResolFromCalibTree(const edm::ParameterS layertotal_vsCM.reserve(::k_END_OF_LAYS_AND_RINGS); layerfound_vsBX.reserve(::k_END_OF_LAYS_AND_RINGS); layertotal_vsBX.reserve(::k_END_OF_LAYS_AND_RINGS); + geff_vsBX.reserve(::k_END_OF_LAYERS); + geff_avg_vsBX.reserve(::k_END_OF_LAYERS); + geff_avg_vsLumi.reserve(::k_END_OF_LAYERS); + geff_avg_vsPU.reserve(::k_END_OF_LAYERS); + geff_avg_vsCM.reserve(::k_END_OF_LAYERS); } SiStripHitResolFromCalibTree::~SiStripHitResolFromCalibTree() { @@ -335,11 +349,40 @@ void SiStripHitResolFromCalibTree::algoAnalyze(const edm::Event& e, const edm::E layertotal_vsBX.push_back(fs->make( Form("totalVsBx_layer%i", (int)ilayer), Form("layer %i", (int)ilayer), nBxInAnOrbit, 0, nBxInAnOrbit)); + geff_vsBX.push_back(fs->make(nBxInAnOrbit - 1)); + geff_vsBX[ilayer]->SetName(Form("effVsBx_layer%i", (int)ilayer)); + geff_vsBX[ilayer]->SetTitle( + fmt::format("Hit Efficiency vs bx - {}", ::layerName(ilayer, showRings_, nTEClayers_)).c_str()); + + geff_avg_vsBX.push_back(fs->make(nBxInAnOrbit - 1)); + geff_avg_vsBX[ilayer]->SetName(Form("effVsBxAvg_layer%i", (int)ilayer)); + geff_avg_vsBX[ilayer]->SetTitle( + fmt::format("Hit Efficiency vs bx - {}", ::layerName(ilayer, showRings_, nTEClayers_)).c_str()); + geff_avg_vsBX[ilayer]->SetMarkerStyle(20); + + geff_avg_vsLumi.push_back(fs->make(99)); + geff_avg_vsLumi[ilayer]->SetName(Form("effVsLumiAvg_layer%i", (int)ilayer)); + geff_avg_vsLumi[ilayer]->SetTitle( + fmt::format("Hit Efficiency vs inst. lumi. - {}", ::layerName(ilayer, showRings_, nTEClayers_)).c_str()); + geff_avg_vsLumi[ilayer]->SetMarkerStyle(20); + + geff_avg_vsPU.push_back(fs->make(44)); + geff_avg_vsLumi[ilayer]->SetName(Form("effVsPUAvg_layer%i", (int)ilayer)); + geff_avg_vsPU[ilayer]->SetTitle( + fmt::format("Hit Efficiency vs pileup - {}", ::layerName(ilayer, showRings_, nTEClayers_)).c_str()); + geff_avg_vsPU[ilayer]->SetMarkerStyle(20); + if (useCM_) { layerfound_vsCM.push_back( fs->make(Form("layerfound_vsCM_layer_%i", (int)(ilayer)), GetLayerName(ilayer), 20, 0, 400)); layertotal_vsCM.push_back( fs->make(Form("layertotal_vsCM_layer_%i", (int)(ilayer)), GetLayerName(ilayer), 20, 0, 400)); + + geff_avg_vsCM.push_back(fs->make(19)); + geff_avg_vsCM[ilayer]->SetName(Form("effVsCMAvg_layer%i", (int)ilayer)); + geff_avg_vsCM[ilayer]->SetTitle( + fmt::format("Hit Efficiency vs common Mode - {}", ::layerName(ilayer, showRings_, nTEClayers_)).c_str()); + geff_avg_vsCM[ilayer]->SetMarkerStyle(20); } layertotal[ilayer] = 0; layerfound[ilayer] = 0; @@ -1505,7 +1548,7 @@ void SiStripHitResolFromCalibTree::makeSummaryVsBx(const edm::ServiceSetBinContent(ibx, 1e-6); layertotal_vsBX[ilayer]->SetBinContent(ibx, 1); @@ -1521,16 +1564,9 @@ void SiStripHitResolFromCalibTree::makeSummaryVsBx(const edm::ServiceSumw2(); layertotal_vsBX[ilayer]->Sumw2(); - TGraphAsymmErrors* geff = fs->make(nBxInAnOrbit - 1); - geff->SetName(Form("effVsBx_layer%i", ilayer)); - geff->SetTitle("Hit Efficiency vs bx - " + GetLayerName(ilayer)); - geff->BayesDivide(layerfound_vsBX[ilayer], layertotal_vsBX[ilayer]); + geff_vsBX[ilayer]->BayesDivide(layerfound_vsBX[ilayer], layertotal_vsBX[ilayer]); //Average over trains - TGraphAsymmErrors* geff_avg = fs->make(); - geff_avg->SetName(Form("effVsBxAvg_layer%i", ilayer)); - geff_avg->SetTitle("Hit Efficiency vs bx - " + GetLayerName(ilayer)); - geff_avg->SetMarkerStyle(20); int ibx = 0; int previous_bx = -80; int delta_bx = 0; @@ -1548,10 +1584,11 @@ void SiStripHitResolFromCalibTree::makeSummaryVsBx(const edm::Service (int)spaceBetweenTrains_ && nbx > 0 && total > 0) { eff = found / (float)total; //edm::LogInfo("SiStripHitResolFromCalibTree")<<"new train "<SetPoint(ipt, sum_bx / nbx, eff); + geff_avg_vsBX[ilayer]->SetPoint(ipt, sum_bx / nbx, eff); low = TEfficiency::Bayesian(total, found, .683, 1, 1, false); up = TEfficiency::Bayesian(total, found, .683, 1, 1, true); - geff_avg->SetPointError(ipt, sum_bx / nbx - firstbx, previous_bx - sum_bx / nbx, eff - low, up - eff); + geff_avg_vsBX[ilayer]->SetPointError( + ipt, sum_bx / nbx - firstbx, previous_bx - sum_bx / nbx, eff - low, up - eff); ipt++; sum_bx = 0; found = 0; @@ -1569,10 +1606,10 @@ void SiStripHitResolFromCalibTree::makeSummaryVsBx(const edm::ServiceSetPoint(ipt, sum_bx / nbx, eff); + geff_avg_vsBX[ilayer]->SetPoint(ipt, sum_bx / nbx, eff); low = TEfficiency::Bayesian(total, found, .683, 1, 1, false); up = TEfficiency::Bayesian(total, found, .683, 1, 1, true); - geff_avg->SetPointError(ipt, sum_bx / nbx - firstbx, previous_bx - sum_bx / nbx, eff - low, up - eff); + geff_avg_vsBX[ilayer]->SetPointError(ipt, sum_bx / nbx - firstbx, previous_bx - sum_bx / nbx, eff - low, up - eff); } } @@ -1597,7 +1634,8 @@ TString SiStripHitResolFromCalibTree::GetLayerName(Long_t k) { void SiStripHitResolFromCalibTree::ComputeEff(const edm::Service& fs, vector& vhfound, vector& vhtotal, - string name) { + string name, + vector geff) { unsigned int nLayers = 22; if (showRings_) nLayers = 20; @@ -1605,7 +1643,7 @@ void SiStripHitResolFromCalibTree::ComputeEff(const edm::Service& TH1F* hfound; TH1F* htotal; - for (unsigned int ilayer = 1; ilayer < nLayers; ilayer++) { + for (unsigned int ilayer = 0; ilayer <= nLayers; ilayer++) { hfound = vhfound[ilayer]; htotal = vhtotal[ilayer]; @@ -1620,16 +1658,7 @@ void SiStripHitResolFromCalibTree::ComputeEff(const edm::Service& htotal->SetBinContent(i, 1); } - TGraphAsymmErrors* geff = fs->make(hfound->GetNbinsX()); - geff->SetName(Form("%s_layer%i", name.c_str(), ilayer)); - geff->BayesDivide(hfound, htotal); - if (name == "effVsLumi") - geff->SetTitle("Hit Efficiency vs inst. lumi. - " + GetLayerName(ilayer)); - if (name == "effVsPU") - geff->SetTitle("Hit Efficiency vs pileup - " + GetLayerName(ilayer)); - if (name == "effVsCM") - geff->SetTitle("Hit Efficiency vs common Mode - " + GetLayerName(ilayer)); - geff->SetMarkerStyle(20); + geff[ilayer]->BayesDivide(hfound, htotal); } } @@ -1668,13 +1697,13 @@ void SiStripHitResolFromCalibTree::makeSummaryVsLumi(const edm::Service& fs) { edm::LogInfo("SiStripHitResolFromCalibTree") << "Computing efficiency vs CM" << endl; - ComputeEff(fs, layerfound_vsCM, layertotal_vsCM, "effVsCM"); + ComputeEff(fs, layerfound_vsCM, layertotal_vsCM, "effVsCM", geff_avg_vsPU); } TString SiStripHitResolFromCalibTree::GetLayerSideName(Long_t k) {