Skip to content

Commit

Permalink
further improvements in CalibTracker/SiStripHit* plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
mmusich committed May 29, 2024
1 parent 75a6c3d commit bb8ce72
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class SiStripHitEffFromCalibTree : public ConditionDBWriter<SiStripBadStrip> {
void totalStatistics();
void makeSummary();
void makeSummaryVsBx();
void computeEff(vector<TH1F*>& vhfound, vector<TH1F*>& vhtotal, string name);
void computeEff(vector<TH1F*>& vhfound, vector<TH1F*>& vhtotal, string name, vector<TGraphAsymmErrors*> geff);
void makeSummaryVsLumi();
void makeSummaryVsCM();
TString getLayerSideName(Long_t k);
Expand Down Expand Up @@ -172,11 +172,11 @@ class SiStripHitEffFromCalibTree : public ConditionDBWriter<SiStripBadStrip> {
vector<hit> hits[::k_END_OF_LAYERS];
vector<TH2F*> HotColdMaps;
map<unsigned int, pair<unsigned int, unsigned int> > 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<unsigned int, vector<int> > layerfound_perBx;
Expand All @@ -189,6 +189,11 @@ class SiStripHitEffFromCalibTree : public ConditionDBWriter<SiStripBadStrip> {
vector<TH1F*> layertotal_vsCM;
vector<TH1F*> layerfound_vsBX;
vector<TH1F*> layertotal_vsBX;
vector<TGraphAsymmErrors*> geff_vsBX;
vector<TGraphAsymmErrors*> geff_avg_vsBX;
vector<TGraphAsymmErrors*> geff_avg_vsLumi;
vector<TGraphAsymmErrors*> geff_avg_vsPU;
vector<TGraphAsymmErrors*> 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];
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -378,11 +387,40 @@ void SiStripHitEffFromCalibTree::algoAnalyze(const edm::Event& e, const edm::Eve
layertotal_vsBX.push_back(fs->make<TH1F>(
Form("totalVsBx_layer%i", (int)ilayer), Form("layer %i", (int)ilayer), nBxInAnOrbit_, 0, nBxInAnOrbit_));

geff_vsBX.push_back(fs->make<TGraphAsymmErrors>(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<TGraphAsymmErrors>(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<TGraphAsymmErrors>(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<TGraphAsymmErrors>(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<TH1F>(Form("layerfound_vsCM_layer_%i", (int)(ilayer)), lyrName.c_str(), 20, 0, 400));
layertotal_vsCM.push_back(
fs->make<TH1F>(Form("layertotal_vsCM_layer_%i", (int)(ilayer)), lyrName.c_str(), 20, 0, 400));

geff_avg_vsCM.push_back(fs->make<TGraphAsymmErrors>(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;
Expand Down Expand Up @@ -1528,7 +1566,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);
Expand All @@ -1546,17 +1584,9 @@ void SiStripHitEffFromCalibTree::makeSummaryVsBx() {
layerfound_vsBX[ilayer]->Sumw2();
layertotal_vsBX[ilayer]->Sumw2();

TGraphAsymmErrors* geff = fs->make<TGraphAsymmErrors>(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<TGraphAsymmErrors>();
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;
Expand All @@ -1574,10 +1604,11 @@ void SiStripHitEffFromCalibTree::makeSummaryVsBx() {
if (delta_bx > (int)spaceBetweenTrains_ && nbx > 0 && total > 0) {
eff = found / (float)total;
//LOGPRINT<<"new train "<<ipt<<" "<<sum_bx/nbx<<" "<<eff<<endl;
geff_avg->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;
Expand All @@ -1595,22 +1626,25 @@ void SiStripHitEffFromCalibTree::makeSummaryVsBx() {
//last train
eff = found / (float)total;
//LOGPRINT<<"new train "<<ipt<<" "<<sum_bx/nbx<<" "<<eff<<endl;
geff_avg->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<TH1F*>& vhfound, vector<TH1F*>& vhtotal, string name) {
void SiStripHitEffFromCalibTree::computeEff(vector<TH1F*>& vhfound,
vector<TH1F*>& vhtotal,
string name,
vector<TGraphAsymmErrors*> geff) {
unsigned int nLayers = siStripLayers_;
if (showRings_)
nLayers = 20;

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];

Expand All @@ -1625,18 +1659,7 @@ void SiStripHitEffFromCalibTree::computeEff(vector<TH1F*>& vhfound, vector<TH1F*
htotal->SetBinContent(i, 1);
}

TGraphAsymmErrors* geff = fs->make<TGraphAsymmErrors>(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);
}
}

Expand Down Expand Up @@ -1674,13 +1697,13 @@ void SiStripHitEffFromCalibTree::makeSummaryVsLumi() {
LOGPRINT << "Avg conditions: lumi :" << avgLumi << " pu: " << avgPU;
}

computeEff(layerfound_vsLumi, layertotal_vsLumi, "effVsLumi");
computeEff(layerfound_vsPU, layertotal_vsPU, "effVsPU");
computeEff(layerfound_vsLumi, layertotal_vsLumi, "effVsLumi", geff_avg_vsLumi);
computeEff(layerfound_vsPU, layertotal_vsPU, "effVsPU", geff_avg_vsPU);
}

void SiStripHitEffFromCalibTree::makeSummaryVsCM() {
LOGPRINT << "Computing efficiency vs CM";
computeEff(layerfound_vsCM, layertotal_vsCM, "effVsCM");
computeEff(layerfound_vsCM, layertotal_vsCM, "effVsCM", geff_avg_vsCM);
}

TString SiStripHitEffFromCalibTree::getLayerSideName(Long_t k) {
Expand Down
Loading

0 comments on commit bb8ce72

Please sign in to comment.