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(
"ForcePartType", m_forcePartType =
false);
36 declareProperty(
"Apply_ddshifts", m_apply_ddDefault =
false);
37 declareProperty(
"Apply_SC_leakcorr", m_apply_SC_leak_corr =
false);
38 declareProperty(
"Apply_etaEDParPU_correction", m_apply_etaEDParPU_corr =
false);
39 declareProperty(
"Apply_etaEDPar_mc_correction", m_apply_etaEDParPU_mc_corr =
false);
40 declareProperty(
"CorrFile_etaEDParPU_correction", m_corr_etaEDParPU_file =
"IsolationCorrections/v6/zetas.root");
41 declareProperty(
"CorrFile_etaEDPar_mc_correction", m_corr_etaEDPar_mc_corr_file =
"IsolationCorrections/v6/zetas_correction.root");
43 m_isol_corr =
new IsolationCorrection(
name);
51 ATH_CHECK(m_centralEventShapeKey.initialize(m_apply_etaEDParPU_corr));
52 ATH_CHECK(m_forwardEventShapeKey.initialize(m_apply_etaEDParPU_corr));
55 m_isol_corr->msg().setLevel(this->
msg().
level());
58 std::vector < std::string > corrFileNameList;
59 corrFileNameList.push_back(m_corr_file);
60 corrFileNameList.push_back(m_corr_ddshift_file);
61 corrFileNameList.push_back(m_corr_ddsmearing_file);
63 for (
unsigned int i=0;
i<corrFileNameList.size(); ++
i ){
68 ATH_MSG_ERROR (
"Could NOT resolve file name " << corrFileNameList.at(
i) );
69 return StatusCode::FAILURE ;
84 ATH_MSG_WARNING(
"Tool version not recognized: "<<m_tool_ver_str<<
"\nAllowed versions: REL22, REL21, REL20_2, REL17_2");
85 return StatusCode::FAILURE;
88 if(TString(corrFileNameList[0]).Contains(
"isolation_ptcorrections_rel17_2.root") && m_tool_ver_str !=
"REL17_2"){
89 ATH_MSG_WARNING(
"The specified correction file is not for "<<m_tool_ver_str<<
" please use proper correction file");
90 return StatusCode::FAILURE;
93 if (TString(corrFileNameList[0]).Contains(
"isolation_ptcorrections_rel20_2.root") && !( m_tool_ver_str ==
"REL20_2" || m_tool_ver_str ==
"REL21" ) ){
94 ATH_MSG_WARNING(
"The specified correction file is not for "<<m_tool_ver_str<<
" please use proper correction file");
95 return StatusCode::FAILURE;
97 if (TString(corrFileNameList[0]).Contains(
"isolation_ptcorrections_rel22_") && m_tool_ver_str !=
"REL22" ){
98 ATH_MSG_WARNING(
"The specified correction file is not for "<<m_tool_ver_str<<
" please use proper correction file");
99 return StatusCode::FAILURE;
102 m_isol_corr->SetCorrectionFile(m_corr_file, m_corr_ddshift_file, m_corr_ddsmearing_file);
103 m_isol_corr->SetToolVer(tool_ver);
104 m_isol_corr->SetTroubleCategories(m_trouble_categories);
105 m_isol_corr->FitType(m_useLogLogFit);
106 m_isol_corr->ForcePartType(m_forcePartType);
109 if (m_apply_ddDefault) {
110 if (m_ddVersion ==
"2015" || m_ddVersion ==
"2015_2016" || m_ddVersion ==
"2017") {
112 if (m_tool_ver_str!=
"REL21") {
114 if(
registry.registerSystematics( *
this ) != StatusCode::SUCCESS )
return StatusCode::FAILURE;
126 if (m_tool_ver_str !=
"REL21" && m_AFII_corr) m_apply_dd =
false;
128 m_isol_corr->SetAFII(m_AFII_corr);
129 m_isol_corr->SetDataMC(m_is_mc);
131 if(m_apply_etaEDParPU_corr){
134 ATH_MSG_ERROR (
"Could NOT resolve file name " << m_corr_etaEDParPU_file );
135 return StatusCode::FAILURE ;
138 std::unique_ptr<TFile>
f(TFile::Open(
filename.c_str(),
"READ"));
145 if(m_apply_etaEDParPU_mc_corr){
148 ATH_MSG_ERROR (
"Could NOT resolve file name " << m_corr_etaEDPar_mc_corr_file );
149 return StatusCode::FAILURE ;
152 std::unique_ptr<TFile> f_corr(TFile::Open(
filename.c_str(),
"READ"));
154 m_map_isotype_zeta_mc_corr[
xAOD::Iso::topoetcone20] = std::unique_ptr<TGraph>((TGraph*)f_corr->Get(
"topoetcone20"));
155 m_map_isotype_zeta_mc_corr[
xAOD::Iso::topoetcone30] = std::unique_ptr<TGraph>((TGraph*)f_corr->Get(
"topoetcone30"));
156 m_map_isotype_zeta_mc_corr[
xAOD::Iso::topoetcone40] = std::unique_ptr<TGraph>((TGraph*)f_corr->Get(
"topoetcone40"));
161 return m_isol_corr->initialize();
172 for (
auto type : topoisolation_types) {
175 ATH_MSG_DEBUG(
"leakage correction not stored for isolation type " << xAOD::Iso::toCString(
type) <<
". Nothing done.");
178 float newleak = this->GetPtCorrection(
eg,
type);
180 if (!
eg.isolationValue(iso,
type)) {
181 ATH_MSG_WARNING(
"Isolation variable " << xAOD::Iso::toCString(
type) <<
" not stored. Nothing done.");
184 iso += (oldleak-newleak);
185 bool setIso =
eg.setIsolationValue(iso,
type);
193 if (m_correct_etcone){
200 for(
auto type : topoisolation_types){
201 float Etcone_value_corr = m_isol_corr->GetPtCorrectedIsolation(
eg,
type);
202 eg.setIsolationValue(Etcone_value_corr,
type);
215 if(m_apply_SC_leak_corr){
216 float topoetconecoreConeEnergyCorrection = 0;
222 ATH_MSG_WARNING(
"Could not find core57cells to apply SC based core correction");
225 ATH_MSG_VERBOSE(
"SC based core correction value: " << topoetconecoreConeEnergyCorrection);
226 SCsub = - topoetconecoreConeEnergyCorrection +
core57cells;
229 float centralDensity = 0.;
230 float forwardDensity = 0.;
231 if(m_apply_etaEDParPU_corr){
243 for (
auto type : topoisolation_types) {
246 ATH_MSG_DEBUG(
"leakage correction not stored for isolation type " << xAOD::Iso::toCString(
type) <<
". Nothing done");
250 bool gotIso =
eg.isolationValue(oldiso,
type);
251 if (!gotIso)
continue;
255 unsigned int theRunNumber = 0 ;
261 theRunNumber = randomrunnumber(*(eventInfo)) ;
266 if (theRunNumber >= 320000)
267 m_ddVersion =
"2017" ;
268 else if (theRunNumber > 0)
269 m_ddVersion =
"2015_2016" ;
273 if (m_tool_ver_str !=
"REL21" && m_AFII_corr) m_apply_dd =
false;
277 if(m_apply_SC_leak_corr){
279 iso += (SCsub + oldleak);
283 newleak = this->GetPtCorrection(
eg,
type);
284 iso += (oldleak - newleak);
289 if(m_apply_etaEDParPU_corr){
290 float abseta = fabs(
eg.caloCluster()->etaBE(2));
291 float densityOldCorrection = 0.;
293 densityOldCorrection = centralDensity;
296 densityOldCorrection = forwardDensity;
299 static const float a_core = 5*7*0.025*TMath::Pi()/128;
300 float area = TMath::Pi()*dR*dR-a_core;
301 float oldpu_corr = densityOldCorrection*
area;
302 float newpu_corr = m_map_isotype_zetaPU[
type]->Eval(abseta)*centralDensity*
area;
303 float pu_mc_corr = 0.;
304 if(m_apply_etaEDParPU_mc_corr && m_is_mc){
305 pu_mc_corr += m_map_isotype_zeta_mc_corr[
type]->Eval(abseta)*centralDensity*
area;
307 iso = iso + oldpu_corr - newpu_corr + pu_mc_corr;
308 ATH_MSG_VERBOSE(
"Applying parametrized pileup correction to " <<
eg.type() <<
" with |eta|="<< abseta);
309 ATH_MSG_VERBOSE(
"Old parametrized pileup correction for "<<xAOD::Iso::toCString(
type)<<
": "<<oldpu_corr);
310 ATH_MSG_VERBOSE(
"New parametrized pileup correction for "<<xAOD::Iso::toCString(
type)<<
": "<<newpu_corr);
311 ATH_MSG_VERBOSE(
"Parametrized mc correction for "<<xAOD::Iso::toCString(
type)<<
": "<<pu_mc_corr);
312 ATH_MSG_VERBOSE(
"Isolation after new correction for "<<xAOD::Iso::toCString(
type)<<
": "<<iso);
313 ATH_MSG_VERBOSE(
"Isolation after old correction for "<<xAOD::Iso::toCString(
type)<<
": "<<iso+newpu_corr-oldpu_corr-pu_mc_corr);
318 ddcorr = this->GetDDCorrection(
eg,
type);
320 decDDcor20(
eg) = ddcorr;
322 decDDcor40(
eg) = ddcorr;
325 bool setIso =
eg.setIsolationValue(iso,
type);
327 ATH_MSG_VERBOSE(
"oldeak = " << oldleak <<
" ddcor = " << ddcorr <<
" leak param = " << newleak
339 return m_isol_corr->GetPtCorrectedIsolation(
input, isol);
343 return m_isol_corr->GetPtCorrection(
input, isol);
347 return m_isol_corr->GetDDCorrection(
input, isol, m_ddVersion);
357 return applyCorrection( *
output );
362 return applyCorrection( *
output );
374 return sys.find( systematic ) !=
sys.end();
383 return affectingSystematics();
387 return StatusCode::SUCCESS;
390 IsolationCorrectionTool::~IsolationCorrectionTool() {