00001
00002 #pragma once
00003 #include <string>
00004 #include <map>
00005 #include <memory>
00006
00007 #include "InDetTrackSystematicsTools/InDetTrackSystematics.h"
00008 #include "AsgTools/AsgTool.h"
00009 #include "PATInterfaces/ISystematicsTool.h"
00010 #include "PATInterfaces/SystematicSet.h"
00011
00012 #include <TFile.h>
00013
00014 namespace InDet {
00015
00016 class InDetTrackSystematicsTool : public virtual CP::ISystematicsTool, public asg::AsgTool {
00017
00018 ASG_TOOL_CLASS( InDetTrackSystematicsTool,
00019 CP::ISystematicsTool )
00020 public:
00021 InDetTrackSystematicsTool( const std::string& );
00022 virtual ~InDetTrackSystematicsTool() = default;
00023
00024 virtual StatusCode initialize();
00025
00027 virtual bool isAffectedBySystematic( const CP::SystematicVariation& ) const;
00029 virtual CP::SystematicSet affectingSystematics() const = 0;
00031 virtual CP::SystematicSet recommendedSystematics() const;
00033 virtual CP::SystematicCode applySystematicVariation( const CP::SystematicSet& );
00034
00035
00036 protected:
00039 TFile* getFile( const std::string& ) const;
00040
00042 template <class T> StatusCode initObject(T*& obj, std::string rootFileName, std::string objName) const;
00043
00044
00045
00046 std::unordered_map< CP::SystematicSet, CP::SystematicSet > m_sysFilterMap;
00047
00048 const CP::SystematicSet* m_activeSysts;
00049
00050 bool isActive( TrackSystematic ) const;
00051 };
00052
00053
00054
00055 }
00056
00057
00058 template <class T>
00059 StatusCode InDet::InDetTrackSystematicsTool::initObject(T*& obj, std::string rootFileName, std::string objName) const
00060 {
00061 if (obj != nullptr) ATH_MSG_WARNING( obj->GetName() << " is not null, yet we are now attempting to initialize from " << rootFileName );
00062 auto F = std::unique_ptr<TFile>(getFile(rootFileName));
00063 if(!F || F->IsZombie()) {
00064 ATH_MSG_ERROR( "Could not open file " << rootFileName );
00065 return StatusCode::FAILURE;
00066 }
00067 T* tempObj = nullptr;
00068 F->GetObject(objName.data(), tempObj);
00069 if(tempObj==nullptr) {
00070 ATH_MSG_ERROR( "Could not retrieve " << objName << " from file " << rootFileName );
00071 return StatusCode::FAILURE;
00072 }
00073 obj = static_cast<T*>(tempObj->Clone());
00074 obj->SetDirectory(0);
00075 F->Clear();
00076 F->Close();
00077 return StatusCode::SUCCESS;
00078 }