23   IsolationCorrectionTool::IsolationCorrectionTool( 
const std::string &
name )
 
   24     : 
asg::AsgMetadataTool(
name), m_systDDonoff(
"PH_Iso_DDonoff") {
 
   25     declareProperty(
"CorrFile",                    m_corr_file                      = 
"IsolationCorrections/v5/isolation_ptcorrections_rel20_2.root") ;
 
   26     declareProperty(
"CorrFile_ddshift",            m_corr_ddshift_file              = 
"IsolationCorrections/v3/isolation_ddcorrection_shift.root");
 
   27     declareProperty(
"CorrFile_ddsmearing",         m_corr_ddsmearing_file           = 
"IsolationCorrections/v1/isolation_ddcorrection_smearing.root", 
"a run I smearing for MC calo iso");
 
   28     declareProperty(
"ToolVer",                     m_tool_ver_str                   = 
"REL21");
 
   29     declareProperty(
"DataDrivenVer",               m_ddVersion                      = 
"2017");
 
   30     declareProperty(
"AFII_corr",                   m_AFII_corr                      = 
false);
 
   31     declareProperty(
"IsMC",                        m_is_mc                          = 
true);
 
   32     declareProperty(
"Correct_etcone",              m_correct_etcone                 = 
false);
 
   33     declareProperty(
"Trouble_categories",          m_trouble_categories             = 
true);
 
   34     declareProperty(
"LogLogFitForLeakage",         m_useLogLogFit                   = 
false);
 
   35     declareProperty(
"FixTimingIssueInCore",        m_fixCoreTime                    = 
false);
 
   36     declareProperty(
"ForcePartType",               m_forcePartType                  = 
false);
 
   37     declareProperty(
"Apply_ddshifts",              m_apply_ddDefault                = 
false);
 
   38     declareProperty(
"Apply_SC_leakcorr",           m_apply_SC_leak_corr             = 
false);
 
   39     declareProperty(
"Apply_etaEDParPU_correction",     m_apply_etaEDParPU_corr      = 
false);
 
   40     declareProperty(
"Apply_etaEDPar_mc_correction",    m_apply_etaEDParPU_mc_corr   = 
false);
 
   41     declareProperty(
"CorrFile_etaEDParPU_correction",  m_corr_etaEDParPU_file       = 
"IsolationCorrections/v6/zetas.root");
 
   42     declareProperty(
"CorrFile_etaEDPar_mc_correction", m_corr_etaEDPar_mc_corr_file = 
"IsolationCorrections/v6/zetas_correction.root");
 
   44     m_isol_corr = 
new IsolationCorrection(
name);
 
   52     ATH_CHECK(m_centralEventShapeKey.initialize(m_apply_etaEDParPU_corr));
 
   53     ATH_CHECK(m_forwardEventShapeKey.initialize(m_apply_etaEDParPU_corr));
 
   56     m_isol_corr->msg().setLevel(this->
msg().
level());
 
   59     std::vector < std::string > corrFileNameList;
 
   60     corrFileNameList.push_back(m_corr_file);
 
   61     corrFileNameList.push_back(m_corr_ddshift_file);
 
   62     corrFileNameList.push_back(m_corr_ddsmearing_file);
 
   64     for ( 
unsigned int i=0; 
i<corrFileNameList.size(); ++
i ){
 
   69           ATH_MSG_ERROR ( 
"Could NOT resolve file name " << corrFileNameList.at(
i) );
 
   70           return StatusCode::FAILURE ;
 
   85       ATH_MSG_WARNING(
"Tool version not recognized: "<<m_tool_ver_str<<
"\nAllowed versions: REL22, REL21, REL20_2, REL17_2");
 
   86       return StatusCode::FAILURE;
 
   89     if(TString(corrFileNameList[0]).Contains(
"isolation_ptcorrections_rel17_2.root") && m_tool_ver_str != 
"REL17_2"){
 
   90       ATH_MSG_WARNING(
"The specified correction file is not for "<<m_tool_ver_str<<
" please use proper correction file");
 
   91       return StatusCode::FAILURE;
 
   94     if (TString(corrFileNameList[0]).Contains(
"isolation_ptcorrections_rel20_2.root") && !( m_tool_ver_str == 
"REL20_2" || m_tool_ver_str == 
"REL21" ) ){
 
   95       ATH_MSG_WARNING(
"The specified correction file is not for "<<m_tool_ver_str<<
" please use proper correction file");
 
   96       return StatusCode::FAILURE;
 
   98     if (TString(corrFileNameList[0]).Contains(
"isolation_ptcorrections_rel22_") &&  m_tool_ver_str != 
"REL22" ){
 
   99       ATH_MSG_WARNING(
"The specified correction file is not for "<<m_tool_ver_str<<
" please use proper correction file");
 
  100       return StatusCode::FAILURE;
 
  103     m_isol_corr->SetCorrectionFile(m_corr_file, m_corr_ddshift_file, m_corr_ddsmearing_file);
 
  104     m_isol_corr->SetToolVer(tool_ver);
 
  105     m_isol_corr->SetTroubleCategories(m_trouble_categories);
 
  106     m_isol_corr->FitType(m_useLogLogFit);
 
  107     m_isol_corr->ForcePartType(m_forcePartType);
 
  110     if (m_apply_ddDefault) {
 
  111       if (m_ddVersion == 
"2015" || m_ddVersion == 
"2015_2016" || m_ddVersion == 
"2017") {
 
  113           if (m_tool_ver_str!=
"REL21") {
 
  115             if( 
registry.registerSystematics( *
this ) != StatusCode::SUCCESS ) 
return StatusCode::FAILURE;
 
  127     if (m_tool_ver_str != 
"REL21" && m_AFII_corr) m_apply_dd = 
false;
 
  129     m_isol_corr->SetAFII(m_AFII_corr);
 
  130     m_isol_corr->SetDataMC(m_is_mc);
 
  132     if(m_apply_etaEDParPU_corr){
 
  135         ATH_MSG_ERROR ( 
"Could NOT resolve file name " << m_corr_etaEDParPU_file );
 
  136         return StatusCode::FAILURE ;
 
  139       std::unique_ptr<TFile> 
f(TFile::Open(
filename.c_str(), 
"READ"));
 
  146       if(m_apply_etaEDParPU_mc_corr){
 
  149           ATH_MSG_ERROR ( 
"Could NOT resolve file name " << m_corr_etaEDPar_mc_corr_file );
 
  150           return StatusCode::FAILURE ;
 
  153         std::unique_ptr<TFile> f_corr(TFile::Open(
filename.c_str(), 
"READ"));
 
  155         m_map_isotype_zeta_mc_corr[
xAOD::Iso::topoetcone20] = std::unique_ptr<TGraph>((TGraph*)f_corr->Get(
"topoetcone20"));
 
  156         m_map_isotype_zeta_mc_corr[
xAOD::Iso::topoetcone30] = std::unique_ptr<TGraph>((TGraph*)f_corr->Get(
"topoetcone30"));
 
  157         m_map_isotype_zeta_mc_corr[
xAOD::Iso::topoetcone40] = std::unique_ptr<TGraph>((TGraph*)f_corr->Get(
"topoetcone40"));
 
  162     return m_isol_corr->initialize();
 
  173     for (
auto type : topoisolation_types) {
 
  176           ATH_MSG_DEBUG(
"leakage correction not stored for isolation type " << xAOD::Iso::toCString(
type) << 
". Nothing done.");
 
  179       float newleak = this->GetPtCorrection(
eg,
type);
 
  181       if (!
eg.isolationValue(iso,
type)) {
 
  182           ATH_MSG_WARNING(
"Isolation variable " << xAOD::Iso::toCString(
type) << 
" not stored. Nothing done.");
 
  185       iso += (oldleak-newleak);
 
  186       bool setIso = 
eg.setIsolationValue(iso,
type);
 
  194     if (m_correct_etcone){
 
  201       for(
auto type : topoisolation_types){
 
  202         float Etcone_value_corr = m_isol_corr->GetPtCorrectedIsolation(
eg,
type);
 
  203         eg.setIsolationValue(Etcone_value_corr,
type);
 
  219     if(m_apply_SC_leak_corr){
 
  220       float topoetconecoreConeEnergyCorrection = 0;
 
  226           ATH_MSG_WARNING(
"Could not find core57cells to apply SC based core correction");
 
  229       ATH_MSG_VERBOSE(
"SC based core correction value: " << topoetconecoreConeEnergyCorrection);
 
  230       SCsub = - topoetconecoreConeEnergyCorrection + 
core57cells;
 
  233     float centralDensity = 0.;
 
  234     float forwardDensity = 0.;
 
  235     if(m_apply_etaEDParPU_corr){
 
  247     for (
auto type : topoisolation_types) {
 
  250           ATH_MSG_DEBUG(
"leakage correction not stored for isolation type " << xAOD::Iso::toCString(
type) << 
". Nothing done");
 
  254       bool gotIso   = 
eg.isolationValue(oldiso,
type);
 
  255       if (!gotIso) 
continue;
 
  259       unsigned int theRunNumber = 0 ;
 
  265             theRunNumber = randomrunnumber(*(eventInfo)) ;
 
  270       if (theRunNumber >= 320000)
 
  271           m_ddVersion = 
"2017" ;      
 
  272       else if (theRunNumber > 0)
 
  273           m_ddVersion = 
"2015_2016" ; 
 
  277       if (m_tool_ver_str != 
"REL21" && m_AFII_corr) m_apply_dd = 
false;
 
  281       if(m_apply_SC_leak_corr){
 
  283         iso += (SCsub + oldleak);
 
  287         newleak = this->GetPtCorrection(
eg,
type);
 
  288         iso += (oldleak - newleak);
 
  293       if(m_apply_etaEDParPU_corr){
 
  294         float abseta = fabs(
eg.caloCluster()->etaBE(2));
 
  295         float densityOldCorrection = 0.;
 
  297           densityOldCorrection = centralDensity;
 
  300           densityOldCorrection = forwardDensity;
 
  303         static const float a_core = 5*7*0.025*TMath::Pi()/128;
 
  304         float area = TMath::Pi()*dR*dR-a_core;
 
  305         float oldpu_corr = densityOldCorrection*
area;
 
  306         float newpu_corr = m_map_isotype_zetaPU[
type]->Eval(abseta)*centralDensity*
area;
 
  307         float pu_mc_corr = 0.;
 
  308         if(m_apply_etaEDParPU_mc_corr && m_is_mc){
 
  309           pu_mc_corr += m_map_isotype_zeta_mc_corr[
type]->Eval(abseta)*centralDensity*
area;
 
  311         iso = iso + oldpu_corr - newpu_corr + pu_mc_corr;
 
  312         ATH_MSG_VERBOSE(
"Applying parametrized pileup correction to " << 
eg.type() << 
" with |eta|="<< abseta);
 
  313         ATH_MSG_VERBOSE(
"Old parametrized pileup correction for "<<xAOD::Iso::toCString(
type)<< 
": "<<oldpu_corr);
 
  314         ATH_MSG_VERBOSE(
"New parametrized pileup correction for "<<xAOD::Iso::toCString(
type)<< 
": "<<newpu_corr);
 
  315         ATH_MSG_VERBOSE(
"Parametrized mc correction for "<<xAOD::Iso::toCString(
type)<< 
": "<<pu_mc_corr);
 
  316         ATH_MSG_VERBOSE(
"Isolation after new correction for "<<xAOD::Iso::toCString(
type)<< 
": "<<iso);
 
  317         ATH_MSG_VERBOSE(
"Isolation after old correction for "<<xAOD::Iso::toCString(
type)<< 
": "<<iso+newpu_corr-oldpu_corr-pu_mc_corr);
 
  320       if(m_fixCoreTime && eventInfo->
runNumber() > m_Run2Run3runNumberTransition ){
 
  321         float coshEta = std::cosh(
eg.caloCluster()->etaBE(2)) ;
 
  322     float outTimeCore = (decEadded_Lr2(
eg) + decEadded_Lr3(
eg))/coshEta ; 
 
  326           ddcorr = this->GetDDCorrection(
eg,
type);
 
  328             decDDcor20(
eg) = ddcorr;
 
  330             decDDcor40(
eg) = ddcorr;
 
  333       bool setIso = 
eg.setIsolationValue(iso,
type);
 
  335       ATH_MSG_VERBOSE(
"oldeak = " << oldleak << 
" ddcor = " << ddcorr << 
" leak param = " << newleak
 
  347     return m_isol_corr->GetPtCorrectedIsolation(input, isol);
 
  351     return m_isol_corr->GetPtCorrection(input, isol);
 
  355     return m_isol_corr->GetDDCorrection(input, isol, m_ddVersion);
 
  360     if( output ) 
ATH_MSG_WARNING( 
"Non-null pointer received. There's a possible memory leak!" );
 
  364       output->makePrivateStore( 
static_cast<const xAOD::Electron&
>(input) );
 
  365       return applyCorrection( *output );
 
  369       output->makePrivateStore( 
static_cast<const xAOD::Photon&
>(input) );
 
  370       return applyCorrection( *output );
 
  382     return sys.find( systematic ) != 
sys.end();
 
  391     return affectingSystematics();
 
  395     return StatusCode::SUCCESS;
 
  398   IsolationCorrectionTool::~IsolationCorrectionTool() {