Commit 0b0f004a authored by Atlas-Software Librarian's avatar Atlas-Software Librarian Committed by Graeme Stewart
Browse files

'CMakeLists.txt' (MuonErrorScalingTools-01-00-00)

parent fd22ff75
################################################################################
# Package: MuonErrorScalingTools
################################################################################
# Declare the package name:
atlas_subdir( MuonErrorScalingTools )
# Declare the package's dependencies:
atlas_depends_on_subdirs( PUBLIC
Control/AthenaBaseComps
Control/AthenaKernel
DetectorDescription/Identifier
GaudiKernel
MuonSpectrometer/MuonReconstruction/MuonRecTools/MuonRecToolInterfaces
Tracking/TrkEvent/TrkEventPrimitives
PRIVATE
Database/AthenaPOOL/AthenaPoolUtilities
MuonSpectrometer/MuonIdHelpers
MuonSpectrometer/MuonReconstruction/MuonRecEvent/MuonCompetingRIOsOnTrack )
# Component(s) in the package:
atlas_add_component( MuonErrorScalingTools
src/*.cxx
src/components/*.cxx
LINK_LIBRARIES AthenaBaseComps AthenaKernel Identifier GaudiKernel MuonRecToolInterfaces TrkEventPrimitives AthenaPoolUtilities MuonIdHelpersLib MuonCompetingRIOsOnTrack )
# Install files from the package:
atlas_install_headers( MuonErrorScalingTools )
atlas_install_joboptions( share/*.py )
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef MUONERRORSCALINGTOOLS_MUONERRORSCALEDBTOOL_H
#define MUONERRORSCALINGTOOLS_MUONERRORSCALEDBTOOL_H
#include "AthenaBaseComps/AthAlgTool.h"
#include "MuonRecToolInterfaces/IMuonErrorScaleDbTool.h"
#include "GaudiKernel/ToolHandle.h"
#include "AthenaKernel/IIOVSvc.h"
/**
@file MuonErrorScaleDbTool.h
@class MuonErrorScaleDbTool
@brief Tool for retrieving values from conditions database
to be used for error scaling of muon hits in track fitting.
@date 20 May 2010
*/
namespace Muon {
class MuonIdHelperTool;
class MuonErrorScaleDbTool : virtual public IMuonErrorScaleDbTool, public AthAlgTool {
public:
MuonErrorScaleDbTool(const std::string& type, const std::string& name,
const IInterface* parent);
virtual ~MuonErrorScaleDbTool();
virtual StatusCode initialize();
virtual StatusCode finalize();
bool doMdt() const { return m_do_mdt; }
bool doTgc() const { return m_do_tgc; }
bool doRpc() const { return m_do_rpc; }
bool doCsc() const { return m_do_csc; }
std::vector<double> errScale(const Identifier id) const;
virtual MsgStream& dump(MsgStream&) const;
private:
void registerParameters(bool&, std::vector<double>*, const std::string&);
//! conditions data handling: call-back entry to re-set scaling parameters when an IOV is new or changed.
StatusCode callback( IOVSVC_CALLBACK_ARGS );
//! internal code structuring: formatted output for scaling parameters
const std::string makeInfoString(const std::string&,const bool,
const std::vector<double>&) const;
///////////////////////////////////////////////////////////////////
// Private data members:
///////////////////////////////////////////////////////////////////
ToolHandle<MuonIdHelperTool> m_muonIdHelperTool; //!< Muon ID helper tool
//! conditions data handling: COOL folder name for Muon scaling paremeters
const std::string m_muonFolder;
//! map holding the scaling parameters for each detector region
typedef std::map<std::string,std::vector<double>*> ParamMap;
/** @brief map holding the scaling parameters for each detector region
The parammap is used at call-back/initialisation to avoid map
search at every scaling call. It maps directly to the
references of the local vector variables!
*/
ParamMap m_parammap;
bool m_do_mdt;
bool m_do_tgc;
bool m_do_rpc;
bool m_do_csc;
std::vector<double> m_scaling_mdt_barrel;
std::vector<double> m_scaling_mdt_endcap;
std::vector<double> m_scaling_tgcPhi;
std::vector<double> m_scaling_tgcEta;
std::vector<double> m_scaling_rpcPhi;
std::vector<double> m_scaling_rpcEta;
std::vector<double> m_scaling_cscPhi;
std::vector<double> m_scaling_cscEta;
};
MsgStream& operator << (MsgStream&, const MuonErrorScaleDbTool&);
inline MsgStream& operator <<
(MsgStream& sl, const MuonErrorScaleDbTool& se)
{
return se.dump(sl);
}
}
#endif // MUONERRORSCALINGTOOLS_MUONERRORSCALEDBTOOL_H
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
///////////////////////////////////////////////////////////////////
// MuonRIO_OnTrackErrorScalingTool.h, (c) ATLAS Detector software
///////////////////////////////////////////////////////////////////
#ifndef MUON_MUONRIO_ONTRACKERRORSCALINGTOOL_H
#define MUON_MUONRIO_ONTRACKERRORSCALINGTOOL_H
#include "AthenaBaseComps/AthAlgTool.h"
#include "GaudiKernel/MsgStream.h"
#include "GaudiKernel/ToolHandle.h"
#include "Identifier/Identifier.h"
#include "MuonRecToolInterfaces/IMuonRIO_OnTrackErrorScalingTool.h"
#include "TrkEventPrimitives/ParamDefs.h"
namespace Muon
{
class IMuonErrorScaleDbTool;
class MuonRIO_OnTrackErrorScalingTool : public AthAlgTool,
virtual public Muon::IMuonRIO_OnTrackErrorScalingTool {
public:
MuonRIO_OnTrackErrorScalingTool(const std::string&, const std::string&,
const IInterface*);
/** default destructor */
virtual ~MuonRIO_OnTrackErrorScalingTool();
/** standard Athena-Algorithm method */
virtual StatusCode initialize();
/** standard Athena-Algorithm method */
virtual StatusCode finalize();
virtual bool needToScaleMdt() const;
virtual bool needToScaleTgc() const;
virtual bool needToScaleRpc() const;
virtual bool needToScaleCsc() const;
virtual Amg::MatrixX*
createScaledMdtCovariance(const Amg::MatrixX&,
bool is_endcap) const;
virtual Amg::MatrixX*
createScaledTgcCovariance(const Amg::MatrixX&,
const Trk::ParamDefs=Trk::distPhi) const;
virtual Amg::MatrixX*
createScaledRpcCovariance(const Amg::MatrixX&,
const Trk::ParamDefs=Trk::distPhi) const;
virtual Amg::MatrixX*
createScaledCscCovariance(const Amg::MatrixX&,
const Trk::ParamDefs=Trk::distPhi) const;
//
virtual Amg::MatrixX*
createScaledMdtCovariance(const Amg::MatrixX&,
Identifier id) const;
// dumps the current scaling parameters (via error scaling DB tool)
MsgStream& dump(MsgStream&) const;
private:
ToolHandle<IMuonErrorScaleDbTool> m_errorScaleDbTool;
//! internal code structuring: error scaling for 2-dim measurements
void scale2by2(Amg::MatrixX&,
const std::vector<double>&,
const std::vector<double>&) const;
/** class member version of retrieving MsgStream */
mutable MsgStream m_log;
bool m_do_mdt;
bool m_do_tgc;
bool m_do_rpc;
bool m_do_csc;
std::vector<double> m_scaling_mdt_barrel;
std::vector<double> m_scaling_mdt_endcap;
std::vector<double> m_scaling_tgcPhi;
std::vector<double> m_scaling_tgcEta;
std::vector<double> m_scaling_rpcPhi;
std::vector<double> m_scaling_rpcEta;
std::vector<double> m_scaling_cscPhi;
std::vector<double> m_scaling_cscEta;
};
//________________________________________________________________________
inline bool MuonRIO_OnTrackErrorScalingTool::needToScaleMdt() const
{
return m_do_mdt;
}
inline bool MuonRIO_OnTrackErrorScalingTool::needToScaleTgc() const
{
return m_do_tgc;
}
inline bool MuonRIO_OnTrackErrorScalingTool::needToScaleRpc() const
{
return m_do_rpc;
}
inline bool MuonRIO_OnTrackErrorScalingTool::needToScaleCsc() const
{
return m_do_csc;
}
} // end of namespace
#endif // MUON_MUONRIO_ONTRACKERRORSCALINGTOOL_H
package MuonErrorScalingTools
author Robert Harrington <roberth@bu.edu>
public
use AtlasPolicy AtlasPolicy-*
use GaudiInterface GaudiInterface-* External
use AthenaKernel AthenaKernel-* Control
use AthenaBaseComps AthenaBaseComps-* Control
use Identifier Identifier-* DetectorDescription
use TrkEventPrimitives TrkEventPrimitives-* Tracking/TrkEvent
use MuonRecToolInterfaces MuonRecToolInterfaces-* MuonSpectrometer/MuonReconstruction/MuonRecTools
private
use AthenaPoolUtilities AthenaPoolUtilities-* Database/AthenaPOOL
use MuonIdHelpers MuonIdHelpers-* MuonSpectrometer
use MuonCompetingRIOsOnTrack MuonCompetingRIOsOnTrack-* MuonSpectrometer/MuonReconstruction/MuonRecEvent
apply_pattern declare_joboptions files="*.py"
apply_pattern component_library
library MuonErrorScalingTools *.cxx -s=components *.cxx
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
/**
@mainpage MuonErrorScalingTools Package
@author roberth@bu.edu
@section DescriptionMuonErrorScalingTools General description
MuonErrorScalingTools is a package providing tools used to scale errors for muon hits used in muon track reconstruction. Tools provided are:
- Muon::MuonErrorScaleDbTool, used to retrieve error scaling constants from conditions database
- Muon::MuonRIO_OnTrackErrorScalingTool, used to scale errors for muon hits
*/
/**
@page UsedMuonErrorScalingTools Used Packages
@htmlinclude used_packages.html
*/
/**
@page RequirementsMuonErrorScalingTools Requirements
@include requirements
*/
# specify database and folders
from AthenaCommon.AppMgr import ServiceMgr as svcMgr
svcMgr.IOVDbSvc.dbConnection="sqlite://X_muon;schema=mycool.db;dbname=OFLP200"
from IOVDbSvc.CondDB import conddb
conddb.addFolder("","<dbConnection>sqlite://X_muon;schema=mycool.db;dbname=OFLP200</dbConnection> /MUON/TrkErrorScaling" + "<tag>MuonTrkErrorScaling_nominal</tag>", force=True)
conddb.addFolderWithTag('mycool.db','/MUON/TrkErrorScaling','MuonTrkErrorScaling_nominal')
# configure muon hit creator tools to use error scaling
from MuonRecExample import MuonRecTools
from MuonErrorScalingTools.MuonErrorScalingToolsConf import Muon__MuonErrorScaleDbTool,Muon__MuonRIO_OnTrackErrorScalingTool
muonErrorScaleDbTool = Muon__MuonErrorScaleDbTool("MuonErrorScaleDbTool")
ToolSvc += muonErrorScaleDbTool
muonRIO_OnTrackErrorScalingTool = \
Muon__MuonRIO_OnTrackErrorScalingTool("MuonRIO_OnTrackErrorScalingTool",
ErrorScaleDbTool=muonErrorScaleDbTool)
ToolSvc += muonRIO_OnTrackErrorScalingTool
muonClusterOnTrackCreator = MuonRecTools.getPublicTool( "MuonClusterOnTrackCreator" )
muonClusterOnTrackCreator.OutputLevel = 1
muonClusterOnTrackCreator.ErrorScalingTool = ToolSvc.MuonRIO_OnTrackErrorScalingTool
muonClusterOnTrackCreator.ErrorScalingTool.OutputLevel = 1
mdtDriftCircleOnTrackCreator = MuonRecTools.getPublicTool( "MdtDriftCircleOnTrackCreator" )
mdtDriftCircleOnTrackCreator.DoFixedError = False
mdtDriftCircleOnTrackCreator.DoErrorScaling = True
mdtDriftCircleOnTrackCreator.OutputLevel = 1
mdtDriftCircleOnTrackCreator.ErrorScalingTool = ToolSvc.MuonRIO_OnTrackErrorScalingTool
mdtDriftCircleOnTrackCreator.ErrorScalingTool.OutputLevel = 1
#!/bin/env python
#
# script to turn scaling parameters into a local SQlite DB.
# does not publish directly to COOL.
# updated for COOL 2 (RJH 7/6/07)
#
import sys,traceback
from PyCool import cool,coral
# database and folder name
connect="sqlite://X;schema=mycool.db;dbname=OFLP200"
foldername="/MUON/TrkErrorScaling"
tag="MuonTrkErrorScaling_nominal"
dataset=[ ("MDT Barrel",1.0,0.0),
("MDT Endcap",1.0,0.0),
("TGC Phi",1.0,0.0),
("TGC Eta",1.0,0.0),
("RPC Phi",1.0,0.0),
("RPC Eta",1.0,0.0),
("CSC Phi",1.0,0.0),
("CSC Eta",1.0,0.0)
]
# first value is factor on error, second uncorrelated noise term
# to error given in mm
dbSvc = cool.DatabaseSvcFactory.databaseService()
try:
db = dbSvc.openDatabase(connect,False)
except Exception, e:
print e
print "Could not connect to the database"
# try to create it
try:
db=dbSvc.createDatabase(connect)
except Exception, e:
print e
print "Could not create the database either"
sys.exit(2)
# setup folder specification
spec = cool.RecordSpecification()
spec.extend("Name",cool.StorageType.String4k)
spec.extend("Len",cool.StorageType.Int32)
# assume we will not have more than 5 parameters
maxpar=5
spec.extend("par1",cool.StorageType.Double)
spec.extend("par2",cool.StorageType.Double)
spec.extend("par3",cool.StorageType.Double)
spec.extend("par4",cool.StorageType.Double)
spec.extend("par5",cool.StorageType.Double)
# check if folder exists
if (not db.existsFolder(foldername)):
print "Attempt to create",foldername
desc='<timeStamp>run-event</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"1238547719\" /></addrHeader><typeName>CondAttrListCollection</typeName>'
db.createFolder(foldername,spec,desc,cool.FolderVersioning.MULTI_VERSION,True)
print 'Folder',foldername,'created OK'
# now write data
folder=db.getFolder(foldername)
chan=0
print "Writing data to",folder,"with tag",tag
for idata in dataset:
name=idata[0]
nvals=len(idata)-1
if (nvals>maxpar):
print "Maximum of",maxpar,"parameters allowed - additional ones ignored!"
nvals=maxpar
print "Write data for name",name,"number of values",nvals,"at channel",chan
payload=cool.Record(spec)
payload['Name']=name
payload['Len']=nvals
for i in range(0,nvals):
payload['par'+str(1+i)]=idata[1+i]
folder.storeObject(cool.ValidityKeyMin,cool.ValidityKeyMax,payload,chan,tag)
chan+=1
print "All done"
db.closeDatabase()
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "GaudiKernel/ISvcLocator.h"
#include "GaudiKernel/ListItem.h"
#include "AthenaPoolUtilities/CondAttrListCollection.h"
#include "MuonIdHelpers/MuonIdHelperTool.h"
#include "MuonErrorScalingTools/MuonErrorScaleDbTool.h"
//________________________________________________________________________
Muon::MuonErrorScaleDbTool::MuonErrorScaleDbTool(const std::string& type,
const std::string& name,
const IInterface* parent)
: AthAlgTool(type,name,parent)
, m_muonIdHelperTool("Muon::MuonIdHelperTool/MuonIdHelperTool")
, m_muonFolder("/MUON/TrkErrorScaling")
, m_scaling_mdt_barrel(std::vector<double>(0))
, m_scaling_mdt_endcap(std::vector<double>(0))
, m_scaling_tgcPhi(std::vector<double>(0))
, m_scaling_tgcEta(std::vector<double>(0))
, m_scaling_rpcPhi(std::vector<double>(0))
, m_scaling_rpcEta(std::vector<double>(0))
, m_scaling_cscPhi(std::vector<double>(0))
, m_scaling_cscEta(std::vector<double>(0))
{
declareInterface<Muon::IMuonErrorScaleDbTool>(this);
declareProperty("MuonIdHelperTool", m_muonIdHelperTool);
}
//________________________________________________________________________
Muon::MuonErrorScaleDbTool::~MuonErrorScaleDbTool()
{
}
//________________________________________________________________________
StatusCode Muon::MuonErrorScaleDbTool::initialize()
{
// --- check scaling factors
registerParameters(m_do_mdt,
&m_scaling_mdt_barrel,"MDT Barrel");
registerParameters(m_do_mdt,
&m_scaling_mdt_endcap,"MDT Endcap");
registerParameters(m_do_tgc,
&m_scaling_tgcPhi,"TGC Phi");
registerParameters(m_do_tgc,
&m_scaling_tgcEta,"TGC Eta");
registerParameters(m_do_rpc,
&m_scaling_rpcPhi,"RPC Phi");
registerParameters(m_do_rpc,
&m_scaling_rpcEta,"RPC Eta");
registerParameters(m_do_csc,
&m_scaling_cscPhi,"CSC Phi");
registerParameters(m_do_csc,
&m_scaling_cscEta,"CSC Eta");
// find and register callback function for Muons
const DataHandle<CondAttrListCollection> colptr;
if (detStore()->contains<CondAttrListCollection>(m_muonFolder)) {
if (StatusCode::SUCCESS!=detStore()->
regFcn(&Muon::MuonErrorScaleDbTool::callback,
this,colptr,m_muonFolder)) {
msg(MSG::ERROR) << "Found the folder, but could not register a callback"
<< " on " << m_muonFolder << endreq;
return StatusCode::FAILURE;
}
else
msg(MSG::INFO) << "Registered callback on COOL folder "
<< m_muonFolder << endreq;
}
else {
msg(MSG::INFO) << "Folder " << m_muonFolder << " is not loaded, "
<< "intrinsic meas't errors will be used for Muon RIOs_OnTrack." << endreq;
m_do_mdt = false;
m_do_tgc = false;
m_do_rpc = false;
m_do_csc = false;
}
// set up MuonIdHelperTool
if (m_muonIdHelperTool.retrieve().isSuccess())
ATH_MSG_INFO("Retrieved "<<m_muonIdHelperTool);
else {
ATH_MSG_FATAL("Could not get MuonIdHelperTool!");
return StatusCode::FAILURE;
}
return StatusCode::SUCCESS;
}
//________________________________________________________________________
StatusCode Muon::MuonErrorScaleDbTool::finalize()
{
return StatusCode::SUCCESS;
}
//________________________________________________________________________
void Muon::MuonErrorScaleDbTool::registerParameters(bool& do_detSystem,
std::vector<double>* errscaler,
const std::string& sdet)
{
// add this set of parameters to list, always set the parameters to be
// 'used' for now
do_detSystem=true;
m_parammap.insert(ParamMap::value_type(sdet,errscaler));
// set default parameters in case no info is read from condDB for this set
errscaler->clear();
errscaler->push_back(1.0);
errscaler->push_back(0.0);
}
//________________________________________________________________________
MsgStream& Muon::MuonErrorScaleDbTool::dump( MsgStream& out ) const
{
//--- need an sprintf here.
out << std::endl << name() << " has found the following factors and constants to scale errors:" <<std::endl;