Commit 0439f919 authored by Niels Van Eldik's avatar Niels Van Eldik Committed by Graeme Stewart
Browse files

fix crash and clean-up memory management (MdtCalibSvc-03-00-02)

parent 7e3addfb
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef MUONCALIB_MDTCALIBREGIONSVC_H
#define MUONCALIB_MDTCALIBREGIONSVC_H
#include <vector>
#include "Identifier/Identifier.h"
#include "MuonCalibIdentifier/MdtRegionTool.h"
#include "MuonCalibIdentifier/MdtRegion.h"
/** Service providing mapping between identifiers and calibration regions
* The mapping is done using hashes to ensure fast access.
* USED ONLY BY MdtCalibSvc (IF EXPLICITELY REQUIRED BY is_testbeam PROPERTY
* OF MdtCalibrationSvc). OBSOLETE, TO BE USED ONLY FOR TB.
*/
class MdtCalibRegionSvc {
public:
/** routines for rt-calibration regions */
/** returns region hash associated with identifier */
MdtRegionHash getRtRegionHash(const MdtBasicRegionId& hash) const;
/** returns region hash associated with identifier hash */
MdtRegionHash getRtRegionHash(const MdtBasicRegionHash& hash) const;
/** return MdtRegion associated with region hash */
const MdtRegion* getRtRegion(const MdtRegionHash& key) const;
/** number of rt regions */
unsigned int numberOfRtRegions() const;
/** routines for correction function regions */
/** returns region hash associated with identifier */
MdtRegionHash getCorRegionHash(const MdtBasicRegionId& hash) const;
/** returns region hash associated with identifier hash */
MdtRegionHash getCorRegionHash(const MdtBasicRegionHash& hash) const;
/** return MdtRegion associated with region hash */
const MdtRegion* getCorRegion(const MdtRegionHash& key) const;
/** number of rt regions */
unsigned int numberOfCorRegions() const;
private:
MdtRegionTool m_rtRegionTool;
MdtRegionSet m_rtRegions;
MdtRegionTool m_corRegionTool;
MdtRegionSet m_corRegions;
};
inline
MdtRegionHash MdtCalibRegionSvc::getRtRegionHash(const MdtBasicRegionId& hash) const
{
return m_rtRegionTool.getRegionHash(hash);
}
inline
MdtRegionHash MdtCalibRegionSvc::getRtRegionHash(const MdtBasicRegionHash& hash) const
{
if( hash < 0 || hash >= m_rtRegions.size() ) return MdtRegionHash();
return m_rtRegions[hash];
}
inline
const MdtRegion* MdtCalibRegionSvc::getRtRegion(const MdtRegionHash& hash) const
{
if( hash < 0 || hash >= m_rtRegions.size() ) return 0;
return m_rtRegions[hash];
}
inline
unsigned int MdtCalibRegionSvc::numberOfRtRegions() const
{
return m_rtRegions.size();
}
inline
MdtRegionHash MdtCalibRegionSvc::getCorRegionHash(const MdtBasicRegionId& hash) const
{
return m_corRegionTool.getRegionHash(hash);
}
inline
MdtRegionHash MdtCalibRegionSvc::getCorRegionHash(const MdtBasicRegionHash& hash) const
{
if( hash < 0 || hash >= m_corRegions.size() ) return MdtRegionHash();
return m_corRegions[hash];
}
inline unsigned int MdtCalibRegionSvc::numberOfCorRegions() const
{
return m_corRegions.size();
}
inline
const MdtRegion* MdtCalibRegionSvc::getCorRegion(const MdtRegionHash& hash) const
{
if( hash < 0 || hash >= m_corRegions.size() ) return 0;
return m_corRegions[hash];
}
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
/***************************************************************************
* Mdt Calibration Database Service Base Class
* -------------------------------------------
* Copyright (C) 2005 by ATLAS Collaboration
*
* Author : Martin Woudstra
* Creation Date: 02 May 2005
* Last Update : 27 Feb 2006 by D.Orestano
***************************************************************************/
#ifndef MDTCALIBSVC_MDTCALIBRATIONDBSVC_H
#define MDTCALIBSVC_MDTCALIBRATIONDBSVC_H
#include "AthenaBaseComps/AthService.h"
#include "GaudiKernel/IInterface.h"
#include "GaudiKernel/ToolHandle.h" // for configurables
#include "AthenaKernel/IOVSvcDefs.h"
//#include "MuonCalibIdentifier/MdtRegion.h"
//#include "MuonCalibIdentifier/MdtHashTable.h"
#include "MdtCalibData/MdtRtRelationCollection.h"
#include "MdtCalibData/MdtTubeCalibContainerCollection.h"
#include "MdtCalibData/MdtCorFuncSetCollection.h"
class MdtCalibrationRegionSvc;
class MdtIdHelper;
class Identifier;
class IdentifierHash;
namespace MuonCalib{
class IMdtCalibDBTool;
struct MdtFullCalibData;
}
/** handles the retreival of constants from the DB: it uses a Tool
* derived from MuonCalib::IMdtCalibDBTool to access different types of DB
* (currently implemented ASCII files and COOL CLOBS)*/
class MdtCalibrationDbSvc : public AthService, virtual public IInterface {
public:
/** constructor */
MdtCalibrationDbSvc(const std::string& name,ISvcLocator* sl);
/** destructor */
virtual ~MdtCalibrationDbSvc();
/** IInterface implementation */
static const InterfaceID& interfaceID() {
static InterfaceID s_iID("MdtCalibrationDbSvc", 1, 0);
return s_iID;
}
/** IInterface implementation */
virtual StatusCode queryInterface(const InterfaceID& riid,void** ppvIF);
/** initialization */
virtual StatusCode initialize(void);
/** finalization */
virtual StatusCode finalize(void);
/** to be called back to update the Collections : retrieve from database */
virtual StatusCode LoadCalibration(IOVSVC_CALLBACK_ARGS);
/** to be called back to update the Collections : retrieve RTs from database*/
virtual StatusCode loadRt(IOVSVC_CALLBACK_ARGS);
/** to be called back to update the Collections :
* retrieve Tube inforsmation from database */
virtual StatusCode loadTube(IOVSVC_CALLBACK_ARGS);
/** Access to calibration constants per calibration region/chamber */
MuonCalib::MdtFullCalibData getCalibration( const Identifier& id ) const;
/** Access to RT calibration constants per calibration region/chamber directly using the hashes */
MuonCalib::MdtFullCalibData getCalibration( const IdentifierHash& chamberHash, const IdentifierHash& detElHash ) const;
/** Access to RT calibration constants per calibration region/chamber */
const MuonCalib::MdtRtRelation* getRtCalibration( const Identifier& id ) const;
/** Access to calibration constants per calibration region/chamber by hash */
const MuonCalib::MdtRtRelation* getRtCalibration( const IdentifierHash& detElHash ) const;
/** Access to Tube calibration constants per calibration region/chamber */
const MuonCalib::MdtTubeCalibContainer* getTubeCalibContainer( const Identifier& id ) const;
/** Access to Tube calibration constants per calibration region/chamber by hash */
const MuonCalib::MdtTubeCalibContainer* getTubeCalibContainer( const IdentifierHash& chamberHash ) const;
/** Access to corrections to calibration constants per calibration
* region/chamber */
const MuonCalib::MdtCorFuncSet* getCorFunctions( const Identifier& id ) const;
/** Access to corrections to calibration constants per calibration
* region/chamber by hash */
const MuonCalib::MdtCorFuncSet* getCorFunctions( const IdentifierHash& detElHash ) const;
private:
/** Indexed with MdtRegionHash for rt relations*/
mutable MdtRtRelationCollection* m_rtData;
/** Indexed with MdtChamberHash */
mutable MdtTubeCalibContainerCollection* m_tubeData;
/** Indexed with MdtRegionHash for correction function regions */
mutable MdtCorFuncSetCollection* m_corData;
/** handle to region service */
ServiceHandle<MdtCalibrationRegionSvc> m_regionSvc;
/** Id Helper used to retreive hashes from IDs */
const MdtIdHelper* m_mdtIdHelper;
/** create the correction functions */
void initialize_B_correction(MuonCalib::MdtCorFuncSet* funcSet,
const MuonCalib::MdtRtRelation* rt);
void initializeSagCorrection(MuonCalib::MdtCorFuncSet* funcSet);
/** Tool handling the DB access */
ToolHandle<MuonCalib::IMdtCalibDBTool> m_dbTool;
ServiceHandle<StoreGateSvc> m_detStore;
/** Properties: */
std::string m_tubeDataLocation;
std::string m_rtDataLocation;
std::string m_corDataLocation;
bool m_create_b_field_function; //<! flag to switch on loading of B field correction
bool m_createWireSagFunction; //<! flag to switch on loading of wire sag correction
bool m_createSlewingFunction; //<! flag to switch on loading of slewing correction
bool m_getTubeConstants; //<! flag to switch off loading of tube constants
bool m_getCorrections; //<! flag to switch off loading of correction function constants
};
#endif // MDTCALIBSVC_MDTCALIBRATIONDBSVC_H
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef MUONCALIB_MDTCALIBRATIONREGIONSVC_H
#define MUONCALIB_MDTCALIBRATIONREGIONSVC_H
#include <vector>
#include "AthenaBaseComps/AthService.h"
#include "GaudiKernel/IInterface.h"
#include "Identifier/Identifier.h"
#include "MuonCalibIdentifier/MdtRegionTool.h"
#include "MuonCalibIdentifier/MdtRegion.h"
/** Service providing mapping between identifiers and calibration regions
The mapping is done using hashes to ensure fast access.
*/
class MdtIdHelper;
class MdtCalibrationRegionSvc : public AthService, virtual public IInterface {
public:
/** constructor */
MdtCalibrationRegionSvc(const std::string& name,ISvcLocator* sl);
/** destructor */
virtual ~MdtCalibrationRegionSvc();
/** IInterface implementation */
static const InterfaceID& interfaceID() {
static InterfaceID s_iID("MdtCalibrationRegionSvc", 1, 0);
return s_iID;
}
/** IInterface implementation */
virtual StatusCode queryInterface(const InterfaceID& riid,void** ppvIF);
/** initialization */
virtual StatusCode initialize(void);
/** finalization */
virtual StatusCode finalize(void);
/** currently 2 types of mappings are hardcoded: "OnePerChamber" and "OneRt"
* and this method can be used to switch between one and the other. It is
* foreseen to store maps in DB to gain more flexibility.*/
virtual void remapRtRegions(std::string mapName);
/** routines for rt-calibration regions */
/** returns region hash associated with identifier */
MdtRegionHash getRtRegionHash(const MdtBasicRegionId& hash) const;
/** returns region hash associated with identifier hash */
MdtRegionHash getRtRegionHash(const MdtBasicRegionHash& hash) const;
/** return MdtRegion associated with region hash */
const MdtRegion* getRtRegion(const MdtRegionHash& key) const;
/** number of rt regions */
unsigned int numberOfRtRegions() const;
/** routines for correction function regions */
/** returns region hash associated with identifier */
MdtRegionHash getCorRegionHash(const MdtBasicRegionId& hash) const;
/** returns region hash associated with identifier hash */
MdtRegionHash getCorRegionHash(const MdtBasicRegionHash& hash) const;
/** return MdtRegion associated with region hash */
const MdtRegion* getCorRegion(const MdtRegionHash& key) const;
/** number of rt regions */
unsigned int numberOfCorRegions() const;
private:
void initializeRegions();
const MdtIdHelper* m_mdtIdHelper;
MdtRegionTool m_rtRegionTool;
MdtRegionTool m_corRegionTool;
};
inline
MdtRegionHash MdtCalibrationRegionSvc::getRtRegionHash(const MdtBasicRegionId& /*id*/) const
{
/** convert id into hash
return getRtRegionHash(hash);
*/
return MdtRegionHash();
}
inline
MdtRegionHash MdtCalibrationRegionSvc::getRtRegionHash(const MdtBasicRegionHash& hash) const
{
return m_rtRegionTool.getRegionHash(hash);
}
inline
const MdtRegion* MdtCalibrationRegionSvc::getRtRegion(const MdtRegionHash& hash) const
{
return m_rtRegionTool.getRegion(hash);
}
inline
unsigned int MdtCalibrationRegionSvc::numberOfRtRegions() const
{
return m_rtRegionTool.numberOfRegions();
}
inline
MdtRegionHash MdtCalibrationRegionSvc::getCorRegionHash(const MdtBasicRegionId& /*id*/) const
{
/** convert id into hash
return getCorRegionHash(hash);
*/
return MdtRegionHash();
}
inline
MdtRegionHash MdtCalibrationRegionSvc::getCorRegionHash(const MdtBasicRegionHash& hash) const
{
return m_corRegionTool.getRegionHash(hash);
}
inline
const MdtRegion* MdtCalibrationRegionSvc::getCorRegion(const MdtRegionHash& hash) const
{
return m_rtRegionTool.getRegion(hash);
}
inline
unsigned int MdtCalibrationRegionSvc::numberOfCorRegions() const
{
return m_corRegionTool.numberOfRegions();
}
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef MDTCALIBSVC_MDTCALIBRATIONSVC_H
#define MDTCALIBSVC_MDTCALIBRATIONSVC_H
/*
*
* Authors Niels van Eldik & Martin Woudstra
*
*/
#include "AthenaBaseComps/AthService.h"
#include "GaudiKernel/IInterface.h"
#include "MuonPrepRawData/MdtDriftCircleStatus.h"
class MdtCalibHit;
class MdtCalibrationSvcInput;
class MdtCalibrationSvcSettings;
namespace MuonCalib {
class MdtRtRelation;
}
/**
@class MdtCalibrationSvc
the Mdt Calib Service provides, on request, the drift radius and its
error, computed applying the proper calibration, for any hit in Mdt chambers
@author Martin Woudstra, Niels van Eldik
*/
class MdtCalibrationSvc : virtual public IInterface, public AthService {
public:
/** constructor */
MdtCalibrationSvc(const std::string& name,ISvcLocator* sl);
/** destructor */
virtual ~MdtCalibrationSvc();
/** implements IInterface */
static const InterfaceID& interfaceID() {
static InterfaceID s_iID("MdtCalibrationSvc", 1, 0);
return s_iID;
}
/** implements IInterface */
virtual StatusCode queryInterface(const InterfaceID& riid, void** ppvIF);
/** initialization */
virtual StatusCode initialize();
/** finalization */
virtual StatusCode finalize();
/** Convert the raw MDT time (+charge) into a drift radius + error.
It returns whether the conversion was successful.
@param[in,out] hit Hit must have pointer set to the MdtDigit,
as well as the global hit position (including the position along the tube!)
@param[in] signedTracklength the track length from the 'triggerpoint' to the hit.
It is used for the time-of-flight correction.
This triggerpoint is the I.P. for ATLAS p-p collisions,
typically scintillators in test-beam and cosmic teststands,
and not clear yet what is it is for cosmics in ATLAS.
The sign is for determining the sign of the time-of-flight correction.
If a muon first passes the triggerpoint, and then the MDT tube, the sign
should be positive (the case for ATLAS p-p and H8 test-beam).
If a muon first passes the MDT tube, and then de triggerpoint, the sign
should be negative (typically the case for cosmic-ray teststands).
@param[in] triggerTime the time of the 'triggerpoint' in ns. This is the time (measured with
the same clock as the MDT TDC's) when the muon passed a known point in
space: the 'triggerpoint'.
For ATLAS this is 0.0 since the TDC's are synchonised w.r.t. the bunch-crossings.
For H8 test-beam it is the trigger time, which is time when the muon passed
the trigger scintillators. For cosmic-ray teststands it is usually also the
time when the muon passed the trigger scintillators.
For cosmics in ATLAS it is not clear yet.
@param[in] resolFromRtrack indicates the method to provide the resolution as a function
of the distance of the reconstructed track from the anode wire instead of the drift
radius
*/
bool driftRadiusFromTime( MdtCalibHit& hit, double signedTrackLength, double triggerTime = 0.0, bool resolFromRtrack=false );
/** Convert the raw MDT time (+charge) into a drift radius + error.
It returns whether the conversion was successful.
*/
bool driftRadiusFromTime( MdtCalibHit& hit, const MdtCalibrationSvcInput& inputData, const MdtCalibrationSvcSettings& settings, bool resolFromRtrack=false );
/** Convert the raw MDT time (+charge) into a drift radius + error.
It returns whether the conversion was successful.
*/
bool driftRadiusFromTime( MdtCalibHit& hit, const MdtCalibrationSvcInput& inputData, bool resolFromRtrack=false );
/** TDC bin size. (25/32 ns for Atlas) */
double tdcBinSize();
/** dummy function to be removed */
void triggerCounts(int) {}
/** Convert the raw MDT times of two twin hits into a Twin position (coordinate along tube)
It returns whether the conversion was successful. */
bool twinPositionFromTwinHits( MdtCalibHit& hit, MdtCalibHit& twinhit, double signedTrackLength, double twinSignedTrackLength, bool& twinDigitIsPrompt, double triggerTime = 0.0 );
/** Convert the raw MDT times of two twin hits into a Twin position (coordinate along tube)
It returns whether the conversion was successful. */
bool twinPositionFromTwinHits( MdtCalibHit& hit, MdtCalibHit& twinhit, const MdtCalibrationSvcInput& inputData, const MdtCalibrationSvcInput& twinInputData, const MdtCalibrationSvcSettings& settings, bool& twinDigitIsPrompt );
/** Return status of drift time: in window, above/below window (with upper/lower bounds described by the settings) or invalid.
@return @c Muon::MdtDriftCircleStatus saying whether the drift time comes before, during or after the bounds of the drift time spectrum.
@param[in] driftTime is the drift time of the hit.
@param[in] rtRelation is used to obtain the upper and lower limits of the r(t) relation.
@param[in] settings define the extra window around the r(t) relationship bounds that is acceptable.
*/
Muon::MdtDriftCircleStatus driftTimeStatus( double driftTime, const MuonCalib::MdtRtRelation* rtRelation, const MdtCalibrationSvcSettings& settings );
private:
/// please don't add any datamebers here!!
/// they should be added to Imp to keep the class free from data exposed to clients
class Imp;
Imp* m_imp;
};
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef MDTCALIBSVC_MDTCALIBRATIONSVCINPUT_H
#define MDTCALIBSVC_MDTCALIBRATIONSVCINPUT_H
/*
*
* Authors Niels van Eldik & Martin Woudstra
*
*/
#include "GeoPrimitives/GeoPrimitives.h"
namespace Trk {
class StraightLineSurface;
}
/**
@class MdtCalibrationSvcInput
This class contains all possible input for the MdtCalibrationSvc.
Not all fields have to be filled to perform a calibration but if some fields
are missing one might not get the optimal resolution.
@author Martin Woudstra, Niels van Eldik
*/
struct MdtCalibrationSvcInput {
MdtCalibrationSvcInput() :
tof(0.),triggerOffset(0.),pointOfClosestApproach(0),trackDirection(0),
nominalWireSurface(0),wireSurface(0)
{
}
double tof;
double triggerOffset;
const Amg::Vector3D* pointOfClosestApproach;
const Amg::Vector3D* trackDirection;
const Trk::StraightLineSurface* nominalWireSurface;
const Trk::StraightLineSurface* wireSurface;
};
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef MDTCALIBSVC_MDTCALIBRATIONSVCOUTPUT_H
#define MDTCALIBSVC_MDTCALIBRATIONSVCOUTPUT_H