ATLAS Offline Software
InDetTrackSystematicsTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 #include "TFile.h"
9 
10 namespace InDet {
11 
12  InDetTrackSystematicsTool::InDetTrackSystematicsTool( const std::string& name )
13  : asg::AsgTool(name)
14  {
15  }
16 
18  {
19 
20  // add the affecting systematics to the registry
22  if (registry.registerSystematics(*this) != StatusCode::SUCCESS) {
23  ATH_MSG_ERROR( "Unable to register systematics" );
24  return StatusCode::FAILURE;
25  }
26 
27  return StatusCode::SUCCESS;
28  }
29 
30  bool InDetTrackSystematicsTool::isAffectedBySystematic( const CP::SystematicVariation& systematic ) const
31  {
32  auto affSysts = affectingSystematics();
33  return ( affSysts.find(systematic) != affSysts.end() );
34  }
35 
36  CP::SystematicSet InDetTrackSystematicsTool::recommendedSystematics() const
37  {
38  // it's probably a good idea to change this behavior to return a more intelligently thought-out list
39  return affectingSystematics();
40  }
41 
42  StatusCode InDetTrackSystematicsTool::applySystematicVariation( const CP::SystematicSet& systematics )
43  {
44 
45  // first check if we already know this systematic configuration
46  // look for it in our filter map
47  auto sysMapItr = m_sysFilterMap.find(systematics);
48 
49  if (sysMapItr == m_sysFilterMap.end()) {
50 
51  // filter the input systematic with the affecting systematics
52  const CP::SystematicSet affectingSysts = affectingSystematics();
53  CP::SystematicSet filteredSysts;
55  (systematics, affectingSysts, filteredSysts) != StatusCode::SUCCESS ) {
56  ATH_MSG_ERROR( "Recieved unsupported systematics: " << systematics.name() );
57  return StatusCode::FAILURE;
58  }
59 
60  // check in here for incompatible systematics
61  auto isIn = [&](InDet::TrackSystematic syst) {
62  // helper function to check if a systematic exists in the filtered set
63  return filteredSysts.find( InDet::TrackSystematicMap.at( syst ) ) != filteredSysts.end();
64  };
65  if ( isIn( TRK_RES_D0_MEAS) + isIn( TRK_RES_D0_MEAS_UP ) + isIn( TRK_RES_D0_MEAS_DOWN ) > 1 ) {
66  // should only have 1 of these options simultantously
67  ATH_MSG_ERROR( "You must pick only one choice for the d0 resolution systematic" );
68  return StatusCode::FAILURE;
69  }
70  if ( isIn(TRK_RES_Z0_MEAS) + isIn( TRK_RES_Z0_MEAS_UP ) + isIn( TRK_RES_Z0_MEAS_DOWN ) > 1 ) {
71  ATH_MSG_ERROR( "You must pick only one choice for the z0 resolution systematic" );
72  return StatusCode::FAILURE;
73  }
74  bool isSetTrkLoose = isIn( TRK_FAKE_RATE_LOOSE )
75  || isIn( TRK_EFF_LOOSE_GLOBAL )
76  || isIn( TRK_EFF_LOOSE_IBL )
77  || isIn( TRK_EFF_LOOSE_PP0 )
78  || isIn( TRK_EFF_LOOSE_PHYSMODEL );
79  bool isSetTrkTight = isIn( TRK_FAKE_RATE_TIGHT )
80  || isIn( TRK_EFF_TIGHT_GLOBAL )
81  || isIn( TRK_EFF_TIGHT_IBL )
82  || isIn( TRK_EFF_TIGHT_PP0 )
83  || isIn( TRK_EFF_TIGHT_PHYSMODEL );
84  if ( isSetTrkLoose && isSetTrkTight) {
85  ATH_MSG_ERROR( "Both Loose and TightPrimary versions of systematics are simultaneously active." );
86  return StatusCode::FAILURE;
87  }
88 
89  // if the systematics set looks supported, then insert it into the map for future use
90  sysMapItr = m_sysFilterMap.insert(std::make_pair(systematics, filteredSysts)).first;
91  }
92 
93  m_activeSysts = &sysMapItr->second;
94 
95  return StatusCode::SUCCESS;
96  }
97 
98  bool InDetTrackSystematicsTool::isActive( TrackSystematic syst ) const
99  {
100  if (m_activeSysts == nullptr) {
101  ATH_MSG_DEBUG( "applySystematicsVariation() has not been successfully called." );
102  return false;
103  }
104  const auto it_syst = m_activeSysts->find(InDet::TrackSystematicMap.at(syst));
105  return it_syst != m_activeSysts->end();
106  }
107 
108  std::unique_ptr<TFile> InDetTrackSystematicsTool::getFile(const std::string& filename) const
109  {
110  // now the files are stored in the calibration area
111  // filename is configurable in each tool and should include the path starting from the package name
112  // but defaults to recommendation for current release
113  std::string filenameWithFullPath = PathResolverFindCalibFile(filename);
114 
115  return std::unique_ptr<TFile>(TFile::Open(filenameWithFullPath.data(), "READ"));;
116  }
117 
118 }
python.Dso.registry
registry
Definition: Control/AthenaServices/python/Dso.py:159
InDet
Primary Vertex Finder.
Definition: VP1ErrorUtils.h:36
initialize
void initialize()
Definition: run_EoverP.cxx:894
asg
Definition: DataHandleTestTool.h:28
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
CP::SystematicVariation
Definition: SystematicVariation.h:47
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
InDet::TrackSystematicMap
static const std::unordered_map< InDet::TrackSystematic, CP::SystematicVariation, std::hash< int > > TrackSystematicMap
Definition: InDetTrackSystematics.h:56
SystematicRegistry.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
InDet::TrackSystematic
TrackSystematic
Definition: InDetTrackSystematics.h:14
CP::SystematicSet::end
const_iterator end() const
description: const iterator to the end of the set
Definition: SystematicSet.h:59
PathResolver.h
CheckAppliedSFs.systematics
def systematics
Definition: CheckAppliedSFs.py:231
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
InDetTrackSystematicsTool.h
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
CP::SystematicSet::find
iterator find(const SystematicVariation &sys) const
description: find an element in the set
Definition: SystematicSet.h:63
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
CP::SystematicSet::filterForAffectingSystematics
static StatusCode filterForAffectingSystematics(const SystematicSet &systConfig, const SystematicSet &affectingSystematics, SystematicSet &filteredSystematics)
description: filter the systematics for the affected systematics returns: success guarantee: strong f...
Definition: SystematicSet.cxx:213
CP::SystematicRegistry::getInstance
static SystematicRegistry & getInstance()
Get the singleton instance of the registry for the curren thread.
Definition: SystematicRegistry.cxx:25