Skip to content
Snippets Groups Projects
Commit a1d3b571 authored by Ruth Pottgen's avatar Ruth Pottgen
Browse files

Merge branch 'FCS_fix' into '21.0'

Fix memory management in TFCSEnergyBinParametrization

See merge request !29922
parents f0b89234 6d787bd4
No related branches found
No related tags found
27 merge requests!46457Draft: Adding the tools to run over data,!46454Draft: Adding the tools to be able to run over data,!45045WIP: Include another condition for hit merging in FCS_StepInfoSD.cxx,!45043Merge branch 'Update-DAOD_IDNCB' into '21.2',!44869Draft: Update to candidate store,!4217921.9-first_steps-InDetTrackingGeometryXML,!42171Add LAr cell DQ plots to UPC stream,!40342WIP: ATR-22546 - add missing trigger to MC16a,!39162Draft: Insert BCM' support,!38765Bis78 cabling,!37483Fix in monitoring of Pixel FE errors,!36893Fix size of RPC active region in BIS78 and strip material,!3645821.9: Improving material map description (ATLITKSW-127),!36293WIP pixel updates,!34993KF-input adding jXERHO to the AOD outputs,!34864LH rings in front ot HR rigs,!34763Fix L1_4jJ15.0ETA25 item definition (ATR-21261),!3473421.0 fix dq servers,!33996WIP: Correct MM zpositions,!3291021.3 salva s0,!3217421.9 - Bug fix for test stream creation in RD53BEncodingTool,!3134821.9 README Update,!31345Add HEC sampling fractions macros,!31136added also PUsub for LargeR jets,!30671Merge 21.3.18 into 21.9,!30190Merge 21.0.108 into 21.3,!29922Fix memory management in TFCSEnergyBinParametrization
/*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
#include "CLHEP/Random/RandFlat.h"
......@@ -28,9 +28,9 @@ bool TFCSEnergyBinParametrization::is_match_Ekin_bin(int Ekin_bin) const
void TFCSEnergyBinParametrization::resize()
{
for (std::set<int>::iterator itid=pdgid().begin(); itid!=pdgid().end(); ++itid) {
ATH_MSG_VERBOSE("PDGid="<<*itid<<" resize to "<<n_bins()+1);
m_pdgid_Ebin_probability[*itid].resize(n_bins()+1);
for (int id : pdgid()) {
ATH_MSG_VERBOSE("PDGid=" << id << " resize to " << n_bins() + 1);
m_pdgid_Ebin_probability[id].resize(n_bins() + 1);
}
for (auto it=m_pdgid_Ebin_probability.begin(); it!=m_pdgid_Ebin_probability.end(); ++it) {
if(!is_match_pdgid(it->first)) {
......@@ -84,50 +84,44 @@ void TFCSEnergyBinParametrization::set_pdgid_Ekin_bin_probability(int id,std::ve
bool TFCSEnergyBinParametrization::load_pdgid_Ekin_bin_probability_from_file(int id, TFile* file, std::string prob_object_name)
{
add_pdgid(id);
float* prob = nullptr;
file->cd();
TVectorF* pcabinprobvector=(TVectorF*)gDirectory->Get(prob_object_name.c_str());
if(!pcabinprobvector)
{
ATH_MSG_INFO("TFCSEnergyBinParametrization::load_pdgid_Ekin_bin_probability_from_file(): "<<prob_object_name<<" is null. Using equal PCA probabilities.");
prob=new float[m_pdgid_Ebin_probability[id].size()];
prob[0]=0.0;
for(unsigned int i=1;i<m_pdgid_Ebin_probability[id].size();i++)
{
prob[i]=1.0;
}
}
if(pcabinprobvector)
auto probFromFile = dynamic_cast<TVectorF *>(gDirectory->Get(prob_object_name.c_str()));
std::vector<float> prob;
prob.reserve(m_pdgid_Ebin_probability[id].size());
if (probFromFile == nullptr)
{
if((unsigned int)pcabinprobvector->GetNoElements()!=m_pdgid_Ebin_probability[id].size())
{
ATH_MSG_ERROR("TFCSEnergyBinParametrization::load_pdgid_Ekin_bin_probability_from_file(): size of prob array does not match! in.size()=" << pcabinprobvector->GetNoElements() << " instance=" << m_pdgid_Ebin_probability[id].size());
return false;
}
prob=pcabinprobvector->GetMatrixArray();
ATH_MSG_INFO("TFCSEnergyBinParametrization::load_pdgid_Ekin_bin_probability_from_file(): "
<< prob_object_name << " is null. Using equal PCA probabilities.");
prob.push_back(0.0);
for (size_t i = 1; i < m_pdgid_Ebin_probability[id].size(); i++) {
prob.push_back(1.0);
}
} else {
auto size = static_cast<size_t>(probFromFile->GetNoElements());
if (size != m_pdgid_Ebin_probability[id].size())
{
ATH_MSG_ERROR("TFCSEnergyBinParametrization::load_pdgid_Ekin_bin_probability_from_file(): size of prob array does not match! in.size()="
<< size << " instance=" << m_pdgid_Ebin_probability[id].size());
return false;
}
const float *probArray = probFromFile->GetMatrixArray();
for (size_t i = 0; i < size; i++) {
prob.push_back(probArray[i]);
}
}
float ptot=0;
for(int iEbin=0;iEbin<=n_bins();++iEbin) ptot+=prob[iEbin];
float p=0;
for(int iEbin=0;iEbin<=n_bins();++iEbin)
float ptot{};
for (int iEbin = 0; iEbin <= n_bins(); ++iEbin) ptot += prob[iEbin];
float p{};
for (int iEbin = 0; iEbin <= n_bins(); ++iEbin)
{
p+=prob[iEbin]/ptot;
m_pdgid_Ebin_probability[id][iEbin]=p;
p += prob[iEbin] / ptot;
m_pdgid_Ebin_probability[id][iEbin] = p;
}
if(prob) delete prob;
return true;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment