Skip to content
Snippets Groups Projects
Commit 805a6e70 authored by Frank Winklmeier's avatar Frank Winklmeier
Browse files

Merge branch 'nsw_smear2' into 'master'

Adding the NSW calib tool

See merge request atlas/athena!30771
################################################################################
#Package: NSWCalibTools
################################################################################
# Declare the package name:
atlas_subdir( NSWCalibTools )
# Declare the package's dependencies:
atlas_depends_on_subdirs( PUBLIC
GaudiKernel
MuonSpectrometer/MuonReconstruction/MuonRecEvent/MuonPrepRawData
MuonSpectrometer/MuonIdHelpers
MuonSpectrometer/MuonReconstruction/MuonRecEvent/MuonPrepRawData
MuonSpectrometer/MuonIdHelpers
PRIVATE
Control/AthenaBaseComps )
MagneticField/MagFieldInterfaces
MuonSpectrometer/MuonRDO
Control/AthenaBaseComps )
# External dependencies:
find_package( ROOT COMPONENTS Core Tree MathCore Hist )
# Component(s) in the package:
atlas_add_library( NSWCalibToolsLib
src/*.cxx
PUBLIC_HEADERS NSWCalibTools
PRIVATE_INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
LINK_LIBRARIES GaudiKernel MuonPrepRawData
PRIVATE_LINK_LIBRARIES AthenaBaseComps )
atlas_add_library( NSWCalibToolsLib
src/*.cxx
PUBLIC_HEADERS NSWCalibTools
PRIVATE_INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
LINK_LIBRARIES GaudiKernel MuonPrepRawData
PRIVATE_LINK_LIBRARIES AthenaBaseComps )
atlas_add_component( NSWCalibTools
src/components/*.cxx
INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
LINK_LIBRARIES ${ROOT_LIBRARIES} GaudiKernel AthenaBaseComps MuonPrepRawData NSWCalibToolsLib )
atlas_add_component( NSWCalibTools
src/components/*.cxx
INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
LINK_LIBRARIES ${ROOT_LIBRARIES} GaudiKernel AthenaBaseComps MuonPrepRawData NSWCalibToolsLib )
atlas_install_python_modules( python/*.py )
atlas_install_python_modules( python/*.py )
\ No newline at end of file
/*
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
#ifndef INSWCalibTool_h
#define INSWCalibTool_h
#include "GaudiKernel/IAlgTool.h"
#include "GeoPrimitives/GeoPrimitives.h"
#include <cmath>
#include <vector>
static const InterfaceID IID_INSWCalibTool("Muon::INSWCalibTool",1,0);
namespace Muon {
class MM_RawData;
class INSWCalibTool : virtual public IAlgTool {
public: // static methods
static const InterfaceID& interfaceID() {return IID_INSWCalibTool;}
public: // interface methods
virtual StatusCode calibrate(const Muon::MM_RawData* mmRawData, const Amg::Vector3D& globalPos, double& dist_drift, double& distRes_drift, double& calib_charge) = 0;
};
}
#endif
#include "NSWCalibTool.h"
#include "GaudiKernel/SystemOfUnits.h"
namespace {
static constexpr double const& toRad = M_PI/180;
}
Muon::NSWCalibTool::NSWCalibTool(const std::string& t,
const std::string& n,
const IInterface* p ) :
AthAlgTool(t,n,p),
m_idHelperTool("Muon::MuonIdHelperTool/MuonIdHelperTool"),
m_magFieldSvc("AtlasFieldSvc",n)
{
declareInterface<INSWCalibTool>(this);
declareProperty("MagFieldSvc", m_magFieldSvc, "Magnetic Field Service");
declareProperty("DriftVelocity", m_vDrift = 47., "Drift Velocity");
declareProperty("TimeResolution", m_timeRes = 25., "Time Resolution");
}
StatusCode Muon::NSWCalibTool::initialize()
{
ATH_MSG_DEBUG("In initialize()");
ATH_CHECK(m_magFieldSvc.retrieve());
// initialize the MuonIdHelperTool and check the configuration
ATH_CHECK(m_idHelperTool.retrieve());
if ( !(m_idHelperTool->hasMM() && m_idHelperTool->hasSTgc() ) ) {
ATH_MSG_ERROR("MuonIdHelperTool not properly configured, missing MM or STGC");
return StatusCode::FAILURE;
}
m_lorentzAngleFunction = new TF1("lorentzAngleFunction","[0] + [1]*x + [2]*x*x + [3]*x*x*x + [4]*x*x*x*x",0,2);
m_lorentzAngleFunction->SetParameters(0,58.87, -2.983, -10.62, 2.818);
return StatusCode::SUCCESS;
}
StatusCode Muon::NSWCalibTool::calibrate( const Muon::MM_RawData* mmRawData, const Amg::Vector3D& globalPos, double& dist_drift, double& distRes_drift, double& calib_charge)
{
double charge, time, vDriftCorrected;
charge = mmRawData->charge();
time = mmRawData->time();
Amg::Vector3D magneticField;
calib_charge = charge;
m_magFieldSvc->getField(&globalPos,&magneticField);
m_mmBFieldX = magneticField.x();
m_mmBFieldY = magneticField.y();
m_mmBFieldZ = magneticField.z();
double lorentzAngle = m_lorentzAngleFunction->Eval((magneticField.y() > 0. ? 1. : -1.) * std::fabs (magneticField.y()) ) * toRad; // in radians;
vDriftCorrected = m_vDrift * std::cos(lorentzAngle);
dist_drift = vDriftCorrected * time;
dist_drift = dist_drift * Gaudi::Units::perThousand;
distRes_drift = vDriftCorrected * m_timeRes;
distRes_drift = distRes_drift * Gaudi::Units::perThousand;
return StatusCode::SUCCESS;
}
StatusCode Muon::NSWCalibTool::finalize()
{
ATH_MSG_DEBUG("In finalize()");
m_lorentzAngleFunction->Delete();
return StatusCode::SUCCESS;
}
/*
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
#ifndef NSWCalibTool_h
#define NSWCalibTool_h
#include "NSWCalibTools/INSWCalibTool.h"
#include "GaudiKernel/ITHistSvc.h"
#include "GaudiKernel/ToolHandle.h"
#include "GaudiKernel/ServiceHandle.h"
#include "AthenaBaseComps/AthAlgTool.h"
#include "MagFieldInterfaces/IMagFieldSvc.h"
#include "MuonIdHelpers/MuonIdHelperTool.h"
#include "MuonPrepRawData/MMPrepData.h"
#include "MuonRDO/MM_RawData.h"
#include "TRandom3.h"
#include "TTree.h"
#include "TF1.h"
#include <vector>
namespace Muon {
class NSWCalibTool : virtual public INSWCalibTool, public AthAlgTool {
public:
NSWCalibTool(const std::string&, const std::string&, const IInterface*);
virtual ~NSWCalibTool() = default;
StatusCode calibrate( const Muon::MM_RawData* mmRawData, const Amg::Vector3D& globalPos, double& dist_drift, double& distRes_drift, double& calib_charge);
virtual StatusCode initialize();
virtual StatusCode finalize();
private:
ToolHandle<Muon::MuonIdHelperTool> m_idHelperTool;
ServiceHandle<MagField::IMagFieldSvc> m_magFieldSvc;
TF1* m_lorentzAngleFunction;
float m_mmBFieldX;
float m_mmBFieldY;
float m_mmBFieldZ;
float m_vDrift;
float m_timeRes;
};
}
#endif
#include "../NSWCalibSmearingTool.h"
#include "../NSWCalibTool.h"
DECLARE_COMPONENT(Muon::NSWCalibSmearingTool)
DECLARE_COMPONENT(Muon::NSWCalibTool)
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