diff --git a/DetectorDescription/DetDescrCnvSvc/src/DetDescrCnvSvc.cxx b/DetectorDescription/DetDescrCnvSvc/src/DetDescrCnvSvc.cxx index c54cf388c99bf361cd881360d342e7f629a0fb84..d4482743f1ca1811f90c6d25e1ef150a832fabb3 100644 --- a/DetectorDescription/DetDescrCnvSvc/src/DetDescrCnvSvc.cxx +++ b/DetectorDescription/DetDescrCnvSvc/src/DetDescrCnvSvc.cxx @@ -40,7 +40,7 @@ DetDescrCnvSvc::DetDescrCnvSvc(const std::string& name, ISvcLocator* svc) { declareProperty("DetectorManagers", m_detMgrs); declareProperty("DetectorNodes", m_detNodes ); - declareProperty("DecodeIdDict", m_decodeIdDict ); + declareProperty("DecodeIdDict", m_decodeIdDict ); declareProperty("IdDictName", m_idDictName ); declareProperty("IdDictFromRDB", m_idDictFromRDB ); declareProperty("IdDictGlobalTag", m_idDictGlobalTag ); @@ -114,11 +114,10 @@ DetDescrCnvSvc::initialize() { if (status != StatusCode::SUCCESS) return status; // IdHelpers - // status = addToDetStore(125694213, "FaserID"); - status = addToDetStore(168050226, "FaserID"); + status = addToDetStore(125694213, "FaserID"); + if (status != StatusCode::SUCCESS) return status; + status = addToDetStore(131395045, "VetoID"); if (status != StatusCode::SUCCESS) return status; - // status = addToDetStore(2516, "ScintID"); - // if (status != StatusCode::SUCCESS) return status; // status = addToDetStore(2517, "SCT_ID"); // if (status != StatusCode::SUCCESS) return status; diff --git a/DetectorDescription/FaserDetDescr/CMakeLists.txt b/DetectorDescription/FaserDetDescr/CMakeLists.txt index 3d2b5e8da2604574041760bff5b9060bf9b0e9dc..c8572d14516a4f72d67383feb5031cab76a350a0 100644 --- a/DetectorDescription/FaserDetDescr/CMakeLists.txt +++ b/DetectorDescription/FaserDetDescr/CMakeLists.txt @@ -18,7 +18,7 @@ find_package( ROOT COMPONENTS Core Tree MathCore Hist RIO pthread ) # Component(s) in the package: atlas_add_library( FaserDetDescr - src/FaserDetectorIDBase.cxx + src/FaserDetectorID.cxx src/FaserDetectorIDHelper.cxx src/FaserRegionHelper.cxx PUBLIC_HEADERS FaserDetDescr diff --git a/DetectorDescription/FaserDetDescr/FaserDetDescr/FaserDetDescrDict.h b/DetectorDescription/FaserDetDescr/FaserDetDescr/FaserDetDescrDict.h index ac9179a1743005e123672ed820855e5ae80392cf..8ab1b01b778cbdd7ffcf2c623b42bf24fc14845c 100644 --- a/DetectorDescription/FaserDetDescr/FaserDetDescr/FaserDetDescrDict.h +++ b/DetectorDescription/FaserDetDescr/FaserDetDescr/FaserDetDescrDict.h @@ -10,8 +10,7 @@ #define FASERDETDESCR_FASERDETDESCRDICT_H 1 #include "FaserDetDescr/FaserRegion.h" -#include "FaserDetDescr/FaserDetectorIDBase.h" -// #include "FaserDetDescr/FaserDetectorID.h" +#include "FaserDetDescr/FaserDetectorID.h" namespace FaserDetDescr { // Athena namespace autoloading trigger for ROOT6 diff --git a/DetectorDescription/FaserDetDescr/FaserDetDescr/FaserDetectorID.h b/DetectorDescription/FaserDetDescr/FaserDetDescr/FaserDetectorID.h index 7cfac9bddf1fae6d1396e0283d0018559ab38985..b17d61f7252e5fe254589babfa1744e62e3ae83c 100644 --- a/DetectorDescription/FaserDetDescr/FaserDetDescr/FaserDetectorID.h +++ b/DetectorDescription/FaserDetDescr/FaserDetDescr/FaserDetectorID.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration */ #ifndef FASERDETDESCR_FASERDETECTORID_H @@ -7,202 +7,99 @@ /** * @file FaserDetectorID.h * - * @brief This is an Identifier helper class for the all - * subdetectors. This class is a factory for creating compact - * Identifier objects and IdentifierHash or hash ids. And it also - * allows decoding of these ids. + * @brief This class provides an interface to generate or decode an + * identifier for the upper levels of the detector element + * hierarchy, i.e. Faser, the detector systems and detector + * subsystems. As well general "print out" methods are provide for + * all detector systems. All id helper classes derive from this + * class. This class also provides access to the version tags of the + * id dictionaries used by the helper. * + * @author RD Schaffer <R.D.Schaffer@cern.ch> + * + * Modified for FASER */ //<<<<<< INCLUDES >>>>>> -#include "FaserDetDescr/FaserDetectorIDBase.h" #include "Identifier/Identifier.h" -#include "Identifier/IdentifierHash.h" -#include "Identifier/Range.h" +#include "Identifier/IdContext.h" #include "Identifier/IdHelper.h" +#include "Identifier/Range.h" #include "IdDict/IdDictFieldImplementation.h" +#include "FaserDetTechnology.h" #include "AthenaKernel/CLASS_DEF.h" - #include <string> -#include <assert.h> -#include <algorithm> +#include <vector> -//<<<<<< PUBLIC DEFINES >>>>>> -//<<<<<< PUBLIC CONSTANTS >>>>>> //<<<<<< PUBLIC TYPES >>>>>> class IdDictDictionary; +class FaserDetectorIDHelper; -//<<<<<< PUBLIC VARIABLES >>>>>> -//<<<<<< PUBLIC FUNCTIONS >>>>>> //<<<<<< CLASS DECLARATIONS >>>>>> + /** - ** @class FaserDetectorID - ** - ** @brief This is an Identifier helper class for the FASER - ** subdetectors. This class is a factory for creating compact - ** Identifier objects and IdentifierHash or hash ids. And it also - ** allows decoding of these ids. - ** - ** Definition and the range of values for the levels of the - ** identifier are: - ** - ** @verbatim - ** element range meaning - ** ------- ----- ------- - ** - ** station - ** veto 0 - 1 front/back - ** trigger 0 single station - ** preshower 0 single station - ** sct 0 - 2 front, middle, back - ** ecal 0 single station - ** plane - ** veto 0 single plane - ** trigger 0 single plane - ** preshower 0 single plane - ** sct 0 - 2 three planes per station - ** ecal 0 single plane - ** module - ** veto 0 single plate - ** trigger 0 - 1 upper/lower plate - ** preshower 0 single plate - ** sct 0 - 7 eight modules per plane - ** ecal 0 - 3 four modules - ** submodule - ** veto 0 no segmentation - ** trigger 0 no segmentation - ** preshower 0 no segmentation - ** sct 0 - 1 two sides per module - ** ecal 0 - 66 scintillator layers - ** sensor - ** veto 0 single pmt - ** trigger 0 - 1 left/right pmt - ** preshower 0 single pmt - ** sct 0 - 767 strips - ** ecal 0 one tower per layer - ** @endverbatim - ** - */ -class FaserDetectorID : public FaserDetectorIDBase + * @class FaserDetectorID + * + * @brief This class provides an interface to generate or decode an + * identifier for the upper levels of the detector element + * hierarchy, i.e. Faser, the detector systems and detector + * subsystems. As well general "print out" methods are provide for + * all detector systems. All id helper classes derive from this + * class. This class also provides access to the version tags of the + * id dictionaries used by the helper. + **/ + +class FaserDetectorID : public IdHelper { public: - - /// @name public typedefs - //@{ - typedef Identifier::size_type size_type; - typedef std::vector<Identifier>::const_iterator const_id_iterator; - typedef MultiRange::const_identifier_factory const_expanded_id_iterator; - //@} - + /// @name strutors //@{ - FaserDetectorID(void); - virtual ~FaserDetectorID(void) = default; + FaserDetectorID(); + FaserDetectorID(const FaserDetectorID& other); + ~FaserDetectorID(void); + FaserDetectorID& operator= (const FaserDetectorID& other); //@} - - /// @name Creators for station, ids and pmt ids + + /// @name Detector system ids //@{ - /// For a single module - virtual Identifier module_id( int station, - int plane, - int module ) const = 0; - - /// For a module from a submodule id - Identifier module_id ( const Identifier& submodule_id ) const; - - /// For a single submodule - virtual Identifier submodule_id ( int station, - int plane, - int module, - int submodule ) const = 0; - - /// For a single submodule from a sensor id - Identifier submodule_id ( const Identifier& sensor_id ) const; - - /// From hash - optimized - Identifier submodule_id( IdentifierHash submodule_hash) const; - - /// For an individual sensor - virtual Identifier sensor_id ( int station, - int plane, - int module, - int submodule, - int sensor ) const = 0; - - - Identifier sensor_id ( const Identifier& submodule_id, - int sensor ) const; - + /// Detector systems: + Identifier scint (void) const; + Identifier tracker (void) const; + Identifier calo (void) const; //@} - /// @name Hash table maximum sizes + /// @name Scintillator subsystem ids //@{ - size_type submodule_hash_max (void) const; - size_type sensor_hash_max (void) const; + Identifier veto (void) const; + Identifier trigger (void) const; + Identifier preshower (void) const; //@} - /// @name Access to all ids + /// @name Tracker subsystem ids //@{ - /// Iterators over full set of ids. Submodule iterator is sorted - const_id_iterator submodule_begin (void) const; - const_id_iterator submodule_end (void) const; - /// For sensor ids, only expanded id iterators are available. Use - /// following "sensor_id" method to obtain a compact identifier - const_expanded_id_iterator sensor_begin (void) const; - const_expanded_id_iterator sensor_end (void) const; + Identifier sct (void) const; //@} + /// @name Calorimeter subsystem ids + //@{ + Identifier ecal (void) const; + //@} - /// submodule hash from id - optimized - IdentifierHash submodule_hash (Identifier submodule_id) const; - - - /// Values of different levels (failure returns 0) - int station (const Identifier& id) const; - int plane (const Identifier& id) const; - int module (const Identifier& id) const; - int submodule (const Identifier& id) const; - int sensor (const Identifier& id) const; + /// @name Contexts to provide id length - e.g. for use in generic decoding + //@{ + /// IdContext (indicates id length) for detector systems + IdContext detsystem_context (void) const; - // /// Max values for each field (-999 == failure) - int station_max (const Identifier& id) const; - int plane_max (const Identifier& id) const; - int module_max (const Identifier& id) const; - int submodule_max (const Identifier& id) const; - int sensor_max (const Identifier& id) const; + /// IdContext (indicates id length) for sub-detector + IdContext subdet_context (void) const; //@} - // /// @name module eta/phi navigation - // //@{ - // /// Previous wafer hash in phi (return == 0 for neighbor found) - // int get_prev_in_phi (const IdentifierHash& id, IdentifierHash& prev) const; - // /// Next wafer hash in phi (return == 0 for neighbor found) - // int get_next_in_phi (const IdentifierHash& id, IdentifierHash& next) const; - // /// Previous wafer hash in eta (return == 0 for neighbor found) - // int get_prev_in_eta (const IdentifierHash& id, IdentifierHash& prev) const; - // /// Next wafer hash in eta (return == 0 for neighbor found) - // int get_next_in_eta (const IdentifierHash& id, IdentifierHash& next) const; - // /// Wafer hash on other side - // int get_other_side (const IdentifierHash& id, IdentifierHash& other) const; - - // // To check for when phi wrap around may be needed, use - // bool is_phi_module_max(const Identifier& id) const; - // /// For the barrel - // bool is_eta_module_min(const Identifier& id) const; - // /// For the barrel - // bool is_eta_module_max(const Identifier& id) const; - // //@} - - // /// @name contexts to distinguish wafer id from pixel id - // //@{ - // IdContext wafer_context (void) const; - // IdContext strip_context (void) const; - // //@} - - /// @name methods from abstract interface - slower than opt version + + /// @name Generic conversion between identifier and idhash //@{ /// Create compact id from hash id (return == 0 for OK) virtual int get_id (const IdentifierHash& hash_id, @@ -215,239 +112,358 @@ public: const IdContext* context = 0) const; //@} - /// Return the lowest bit position used in the channel id - int base_bit (void) const; + /// @name Initialization and version name + //@{ + /// Initialization from the identifier dictionary + virtual int initialize_from_dictionary(const IdDictMgr& dict_mgr); - // /// Calculate a channel offset between the two identifiers. - // Identifier::diff_type calc_offset(const Identifier& base, - // const Identifier& target) const; + // retrieve version of the dictionary + virtual std::string dictionaryVersion (void) const; + //@} - // /// Create an identifier with a given base and channel offset - // Identifier strip_id_offset(const Identifier& base, - // Identifier::diff_type offset) const; - /// @name interaction with id dictionary + /// @name Generic printing of identifiers //@{ - /// Create sensor Identifier from expanded id, which is returned by the - /// id_iterators - Identifier sensor_id (const ExpandedIdentifier& sensor_id) const; - - /// Create expanded id from compact id (return == 0 for OK) - void get_expanded_id (const Identifier& id, - ExpandedIdentifier& exp_id, + /// Short print out of any identifier (optionally provide + /// separation character - default is '.'): + void show (Identifier id, + const IdContext* context = 0, + char sep = '.' ) const; + /// or provide the printout in string form + std::string show_to_string (Identifier id, + const IdContext* context = 0, + char sep = '.' ) const; + + /// Expanded print out of any identifier + void print (Identifier id, + const IdContext* context = 0) const; + /// or provide the printout in string form + std::string print_to_string (Identifier id, const IdContext* context = 0) const; + //@} + + /// @name Test of an Identifier to see if it belongs to a particular detector (sub)system: + //@{ + bool is_scint (Identifier id) const; + bool is_tracker (Identifier id) const; + bool is_calo (Identifier id) const; + bool is_veto (Identifier id) const; + bool is_trigger (Identifier id) const; + bool is_preshower (Identifier id) const; + bool is_sct (Identifier id) const; + bool is_ecal (Identifier id) const; + //@} - /// Initialization from the identifier dictionary - virtual int initialize_from_dictionary(const IdDictMgr& dict_mgr); + /// @name Test of an Identifier to see if it belongs to a particular detector (sub)system (using expanded ids): + //@{ + bool is_scint (const ExpandedIdentifier& id) const; + bool is_tracker (const ExpandedIdentifier& id) const; + bool is_calo (const ExpandedIdentifier& id) const; + bool is_veto (const ExpandedIdentifier& id) const; + bool is_trigger (const ExpandedIdentifier& id) const; + bool is_preshower (const ExpandedIdentifier& id) const; + bool is_sct (const ExpandedIdentifier& id) const; + bool is_ecal (const ExpandedIdentifier& id) const; + //@} + + /// @name Dictionary versioning: provide access to dictionary names and versions. Note that a helper may correspond to one or more id dictionary + //@{ + /// Dictionary names + std::vector<std::string> dict_names(void) const; + /// File names for subdet dictionaries + std::vector<std::string> file_names(void) const; + /// Version tags for subdet dictionaries + std::vector<std::string> dict_tags (void) const; + //@} + + /// @name Checks are performed by default in debug compilation and NOT in optimized compilation. One can switch or query this mode for any idHelper with the following methods: + //@{ + virtual bool do_checks (void) const; + virtual void set_do_checks (bool do_checks); + //@} + + /// @name neighbours are initialized by default. One can switch or query this mode with the following methods: + //@{ + virtual bool do_neighbours (void) const; + virtual void set_do_neighbours (bool do_neighbours); + //@} + + /// @name setting pointer to the MessageService + //@{ + virtual void setMessageSvc (IMessageSvc* msgSvc); + //@} + + /// Set flag for suppressing informational output. + void set_quiet (bool quiet); + + +protected: + + friend class FaserDetectorIDHelper; + + void setDictVersion (const IdDictMgr& dict_mgr, const std::string& name); + + std::string to_range (const ExpandedIdentifier& id) const; + + std::string fix_barrel_ec (const std::string& barrel_ec) const; + + /// Detector systems: + ExpandedIdentifier scint_exp (void) const; + ExpandedIdentifier tracker_exp (void) const; + ExpandedIdentifier calo_exp (void) const; + + /// Scintillator: + ExpandedIdentifier veto_exp (void) const; + ExpandedIdentifier trigger_exp (void) const; + ExpandedIdentifier preshower_exp (void) const; + + /// Tracker: + ExpandedIdentifier sct_exp (void) const; + + /// Calorimeter: + ExpandedIdentifier ecal_exp (void) const; + + /// Provide efficient access to individual field values, for + /// subclass idhelpers + int scint_field_value () const; + int tracker_field_value () const; + int calo_field_value () const; + int veto_field_value () const; + int trigger_field_value () const; + int preshower_field_value () const; + int sct_field_value () const; + int ecal_field_value () const; + + /// Register the file and tag names for a particular IdDict + /// dictionary + int register_dict_tag (const IdDictMgr& dict_mgr, + const std::string& dict_name); + + /// Test whether an idhelper should be reinitialized based on the + /// change of tags + bool reinitialize (const IdDictMgr& dict_mgr); + + /// Flag for subclasses to know whether or not to perform + /// checks. In general, this is set to false in optimized mode. + mutable bool m_do_checks; + /// Flag for subclasses to know whether or not to perform + /// neighbour initialization + mutable bool m_do_neighbours; + + /// pointer to the message service + IMessageSvc* m_msgSvc; + + /// If true, suppress DEBUG/INFO messages. + bool m_quiet; + + + /// List of dictionary names used by this helper + std::vector<std::string> m_dict_names; + + /// List of dictionary file names used by this helper + std::vector<std::string> m_file_names; + + /// List of dictionary versions used by this helper + std::vector<std::string> m_dict_tags; private: - typedef std::vector<Identifier> id_vec; - typedef id_vec::const_iterator id_vec_it; - typedef std::vector<unsigned short> hash_vec; - typedef hash_vec::const_iterator hash_vec_it; - - void submodule_id_checks ( int station, - int plane, - int module, - int submodule ) const; - - void sensor_id_checks ( int station, - int plane, - int module, - int submodule, - int sensor) const; - - int initLevelsFromDict(void); - - int init_hashes(void); - - int init_neighbors(void); - - size_type m_faser_region_index; - size_type m_SUBDET_INDEX; - size_type m_PART_INDEX; - size_type m_STATION_INDEX; - size_type m_PLANE_INDEX; - size_type m_MODULE_INDEX; - size_type m_SUBMODULE_INDEX; - size_type m_SENSOR_INDEX; - - const IdDictDictionary* m_dict; - MultiRange m_full_submodule_range; - MultiRange m_full_sensor_range; - size_type m_submodule_hash_max; - size_type m_sensor_hash_max; - id_vec m_submodule_vec; - // hash_vec m_prev_phi_wafer_vec; - // hash_vec m_next_phi_wafer_vec; - // hash_vec m_prev_eta_wafer_vec; - // hash_vec m_next_eta_wafer_vec; - - IdDictFieldImplementation m_subdet_impl ; - IdDictFieldImplementation m_part_impl ; - IdDictFieldImplementation m_station_impl ; - IdDictFieldImplementation m_plane_impl ; - IdDictFieldImplementation m_module_impl ; - IdDictFieldImplementation m_submodule_impl; - IdDictFieldImplementation m_sensor_impl ; -}; + typedef Identifier::size_type size_type; + // Identifiear numbering: + enum ID { + FASER_ID = static_cast<Identifier::value_type>(0), + MAX_BIT = Identifier::MAX_BIT, + ALL_BITS = Identifier::ALL_BITS }; + + int initLevelsFromDict(const IdDictMgr& dict_mgr); + + // dictionary version + std::string m_dict_version; + bool m_is_initialized_from_dict; + size_type m_DET_INDEX; + size_type m_SUBDET_INDEX; + int m_SCINT_ID; + int m_TRACKER_ID; + int m_CALO_ID; + int m_VETO_ID; + int m_TRIGGER_ID; + int m_PRESHOWER_ID; + int m_SCT_ID; + int m_ECAL_ID; + + /// Flag for slhc layout: + bool m_isSLHC; + + IdDictDictionary* m_faser_dict; + IdDictDictionary* m_scint_dict; + IdDictDictionary* m_tracker_dict; + IdDictDictionary* m_calo_dict; + FaserDetectorIDHelper* m_helper; + IdDictFieldImplementation m_det_impl; + IdDictFieldImplementation m_scint_part_impl; + IdDictFieldImplementation m_tracker_part_impl; + IdDictFieldImplementation m_calo_part_impl; +}; + + //<<<<<< INLINE PUBLIC FUNCTIONS >>>>>> +//using the macros below we can assign an identifier (and a version) +//This is required and checked at compile time when you try to record/retrieve +CLASS_DEF(FaserDetectorID, 125694213 , 1) + ///////////////////////////////////////////////////////////////////////////// //<<<<<< INLINE MEMBER FUNCTIONS >>>>>> ///////////////////////////////////////////////////////////////////////////// -//using the macros below we can assign an identifier (and a version) -//This is required and checked at compile time when you try to record/retrieve -CLASS_DEF(FaserDetectorID, 125694213, 1) - -//---------------------------------------------------------------------------- -// inline Identifier -// FaserDetectorID::module_id ( int station, -// int plane, -// int module ) const -// { - -// // Build identifier -// Identifier result((Identifier::value_type)0); +inline ExpandedIdentifier +FaserDetectorID::scint_exp (void) const +{ + ExpandedIdentifier result; + return (result << m_SCINT_ID); +} -// // Pack fields independently -// m_scint_impl.pack (scint_field_value(), result); -// m_veto_impl.pack (veto_field_value(), result); -// m_station_impl.pack (station, result); +inline ExpandedIdentifier +FaserDetectorID::tracker_exp (void) const +{ + ExpandedIdentifier result; + return (result << m_TRACKER_ID); +} -// return result; -// } +inline ExpandedIdentifier +FaserDetectorID::calo_exp(void) const +{ + ExpandedIdentifier result; + return (result << m_CALO_ID); +} -//---------------------------------------------------------------------------- -inline Identifier -FaserDetectorID::module_id ( const Identifier& submodule_id ) const +inline ExpandedIdentifier +FaserDetectorID::veto_exp (void) const { - Identifier result(submodule_id); - // Reset the plate and pmt fields - m_submodule_impl.reset(result); - m_sensor_impl.reset(result); - return (result); + ExpandedIdentifier result(scint_exp()); + return (result << m_VETO_ID); } -//---------------------------------------------------------------------------- -// inline Identifier -// FaserDetectorID::submodule_id ( int station, -// int plane, -// int module, -// int submodule ) const -// { -// // Build identifier -// Identifier result((Identifier::value_type)0); - -// // Pack fields independently -// m_scint_impl.pack (scint_field_value(), result); -// m_veto_impl.pack (veto_field_value(), result); -// m_station_impl.pack (station, result); -// m_plane_impl.pack (plane, result); -// m_module_impl.pack (module, result); -// m_submodule_impl.pack(submodule, result); - -// return result; -// } - -//---------------------------------------------------------------------------- -inline Identifier -FaserDetectorID::submodule_id ( const Identifier& sensor_id ) const +inline ExpandedIdentifier +FaserDetectorID::trigger_exp (void) const { - Identifier result(sensor_id); - // reset the strip field - m_sensor_impl.reset(result); - return (result); + ExpandedIdentifier result(scint_exp()); + return (result << m_TRIGGER_ID); } -inline IdentifierHash -FaserDetectorID::submodule_hash (Identifier submodule_id) const +inline ExpandedIdentifier +FaserDetectorID::preshower_exp (void) const { - id_vec_it it = std::lower_bound(m_submodule_vec.begin(), - m_submodule_vec.end(), - submodule_id); - // Require that submodule_id matches the one in vector - if (it != m_submodule_vec.end() && submodule_id == (*it)) { - return (it - m_submodule_vec.begin()); - } - IdentifierHash result; - return (result); // return hash in invalid state + ExpandedIdentifier result(scint_exp()); + return (result << m_PRESHOWER_ID); } -//---------------------------------------------------------------------------- -// inline Identifier -// FaserDetectorID::sensor_id ( int station, -// int plane, -// int module, -// int submodule, -// int sensor ) const -// { -// // Build identifier -// Identifier result((Identifier::value_type)0); - -// // Pack fields independently -// m_scint_impl.pack (scint_field_value(), result); -// m_veto_impl.pack (veto_field_value(), result); -// m_station_impl.pack (station, result); -// m_plane_impl.pack (plane, result); -// m_module_impl.pack (module, result); -// m_submodule_impl.pack(submodule, result); -// m_sensor_impl.pack (sensor, result); - -// return result; -// } - -//---------------------------------------------------------------------------- -inline Identifier -FaserDetectorID::sensor_id ( const Identifier& submodule_id, int sensor ) const +inline ExpandedIdentifier +FaserDetectorID::sct_exp (void) const { - // Build identifier - Identifier result(submodule_id); - - // Reset sensor and then add in value - m_sensor_impl.reset (result); - m_sensor_impl.pack (sensor, result); - - return result; + ExpandedIdentifier result(tracker_exp()); + return (result << m_SCT_ID); } -//---------------------------------------------------------------------------- -inline int -FaserDetectorID::station (const Identifier& id) const +inline ExpandedIdentifier +FaserDetectorID::ecal_exp (void) const { - return (m_station_impl.unpack(id)); + ExpandedIdentifier result(calo_exp()); + return (result << m_ECAL_ID); } -//---------------------------------------------------------------------------- -inline int -FaserDetectorID::plane (const Identifier& id) const +inline int +FaserDetectorID::scint_field_value () const {return (m_SCINT_ID);} + +inline int +FaserDetectorID::tracker_field_value () const {return (m_TRACKER_ID);} + +inline int +FaserDetectorID::calo_field_value () const {return (m_CALO_ID);} + +inline int +FaserDetectorID::veto_field_value () const {return (m_VETO_ID);} + +inline int +FaserDetectorID::trigger_field_value () const {return (m_TRIGGER_ID);} + +inline int +FaserDetectorID::preshower_field_value () const {return (m_PRESHOWER_ID);} + +inline int +FaserDetectorID::sct_field_value () const {return (m_SCT_ID);} + +inline int +FaserDetectorID::ecal_field_value () const {return (m_ECAL_ID);} + +inline bool +FaserDetectorID::is_scint (Identifier id) const { - return (m_plane_impl.unpack(id)); + return (m_det_impl.unpack(id) == m_SCINT_ID); } -//---------------------------------------------------------------------------- -inline int -FaserDetectorID::module (const Identifier& id) const + +inline bool +FaserDetectorID::is_tracker (Identifier id) const { - return (m_module_impl.unpack(id)); + return (m_det_impl.unpack(id) == m_TRACKER_ID); } -//---------------------------------------------------------------------------- -inline int -FaserDetectorID::submodule (const Identifier& id) const +inline bool +FaserDetectorID::is_calo (Identifier id) const { - return (m_submodule_impl.unpack(id)); + return (m_det_impl.unpack(id) == m_CALO_ID); } -//---------------------------------------------------------------------------- -inline int -FaserDetectorID::sensor (const Identifier& id) const +inline bool +FaserDetectorID::is_veto (Identifier id) const { - return (m_sensor_impl.unpack(id)); + bool result = false; + if(is_scint(id)) { + result = (m_scint_part_impl.unpack(id) == m_VETO_ID); + } + return result; } +inline bool +FaserDetectorID::is_trigger (Identifier id) const +{ + bool result = false; + if(is_scint(id)) { + result = (m_scint_part_impl.unpack(id) == m_TRIGGER_ID); + } + return result; +} + +inline bool +FaserDetectorID::is_preshower (Identifier id) const +{ + bool result = false; + if(is_scint(id)) { + result = (m_scint_part_impl.unpack(id) == m_PRESHOWER_ID); + } + return result; +} + +inline bool +FaserDetectorID::is_sct (Identifier id) const +{ + bool result = false; + if(is_tracker(id)) { + result = (m_tracker_part_impl.unpack(id) == m_SCT_ID); + } + return result; +} + +inline bool +FaserDetectorID::is_ecal (Identifier id) const +{ + bool result = false; + if(is_calo(id)) { + result = (m_calo_part_impl.unpack(id) == m_ECAL_ID); + } + return result; +} #endif // FASERDETDESCR_FASERDETECTORID_H diff --git a/DetectorDescription/FaserDetDescr/FaserDetDescr/FaserDetectorIDBase.h b/DetectorDescription/FaserDetDescr/FaserDetDescr/FaserDetectorIDBase.h deleted file mode 100644 index a7fdbc623f6c647c7b697233789da5284aa8aeb8..0000000000000000000000000000000000000000 --- a/DetectorDescription/FaserDetDescr/FaserDetDescr/FaserDetectorIDBase.h +++ /dev/null @@ -1,470 +0,0 @@ -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - -#ifndef FASERDETDESCR_FASERDETECTORIDBASE_H -#define FASERDETDESCR_FASERDETECTORIDBASE_H -/** - * @file FaserDetectorIDBase.h - * - * @brief This class provides an interface to generate or decode an - * identifier for the upper levels of the detector element - * hierarchy, i.e. Faser, the detector systems and detector - * subsystems. As well general "print out" methods are provide for - * all detector systems. All id helper classes derive from this - * class. This class also provides access to the version tags of the - * id dictionaries used by the helper. - * - * @author RD Schaffer <R.D.Schaffer@cern.ch> - * - * $Id: AtlasDetectorID.h,v 1.38 2007-02-23 09:33:30 prieur Exp $ - * Modified for FASER - */ - -//<<<<<< INCLUDES >>>>>> - -#include "Identifier/Identifier.h" -#include "Identifier/IdContext.h" -#include "Identifier/IdHelper.h" -#include "Identifier/Range.h" -#include "IdDict/IdDictFieldImplementation.h" -#include "FaserDetTechnology.h" -#include "AthenaKernel/CLASS_DEF.h" -#include <string> -#include <vector> - -//<<<<<< PUBLIC TYPES >>>>>> - -class IdDictDictionary; -class FaserDetectorIDHelper; - -//<<<<<< CLASS DECLARATIONS >>>>>> - - -/** - * @class FaserDetectorIDBase - * - * @brief This class provides an interface to generate or decode an - * identifier for the upper levels of the detector element - * hierarchy, i.e. Faser, the detector systems and detector - * subsystems. As well general "print out" methods are provide for - * all detector systems. All id helper classes derive from this - * class. This class also provides access to the version tags of the - * id dictionaries used by the helper. - **/ - -class FaserDetectorIDBase : public IdHelper -{ -public: - - /// @name strutors - //@{ - FaserDetectorIDBase(); - FaserDetectorIDBase(const FaserDetectorIDBase& other); - ~FaserDetectorIDBase(void); - FaserDetectorIDBase& operator= (const FaserDetectorIDBase& other); - //@} - - /// @name Detector system ids - //@{ - /// Detector systems: - Identifier scint (void) const; - Identifier tracker (void) const; - Identifier calo (void) const; - //@} - - /// @name Scintillator subsystem ids - //@{ - Identifier veto (void) const; - Identifier trigger (void) const; - Identifier preshower (void) const; - //@} - - /// @name Tracker subsystem ids - //@{ - Identifier sct (void) const; - //@} - - /// @name Calorimeter subsystem ids - //@{ - Identifier ecal (void) const; - //@} - - /// @name Contexts to provide id length - e.g. for use in generic decoding - //@{ - /// IdContext (indicates id length) for detector systems - IdContext detsystem_context (void) const; - - /// IdContext (indicates id length) for sub-detector - IdContext subdet_context (void) const; - //@} - - - /// @name Generic conversion between identifier and idhash - //@{ - /// Create compact id from hash id (return == 0 for OK) - virtual int get_id (const IdentifierHash& hash_id, - Identifier& id, - const IdContext* context = 0) const; - - /// Create hash id from compact id (return == 0 for OK) - virtual int get_hash (const Identifier& id, - IdentifierHash& hash_id, - const IdContext* context = 0) const; - //@} - - /// @name Initialization and version name - //@{ - /// Initialization from the identifier dictionary - virtual int initialize_from_dictionary(const IdDictMgr& dict_mgr); - - // retrieve version of the dictionary - virtual std::string dictionaryVersion (void) const; - //@} - - - /// @name Generic printing of identifiers - //@{ - /// Short print out of any identifier (optionally provide - /// separation character - default is '.'): - void show (Identifier id, - const IdContext* context = 0, - char sep = '.' ) const; - /// or provide the printout in string form - std::string show_to_string (Identifier id, - const IdContext* context = 0, - char sep = '.' ) const; - - /// Expanded print out of any identifier - void print (Identifier id, - const IdContext* context = 0) const; - /// or provide the printout in string form - std::string print_to_string (Identifier id, - const IdContext* context = 0) const; - //@} - - /// @name Test of an Identifier to see if it belongs to a particular detector (sub)system: - //@{ - bool is_scint (Identifier id) const; - bool is_tracker (Identifier id) const; - bool is_calo (Identifier id) const; - bool is_veto (Identifier id) const; - bool is_trigger (Identifier id) const; - bool is_preshower (Identifier id) const; - bool is_sct (Identifier id) const; - bool is_ecal (Identifier id) const; - //@} - - - /// @name Test of an Identifier to see if it belongs to a particular detector (sub)system (using expanded ids): - //@{ - bool is_scint (const ExpandedIdentifier& id) const; - bool is_tracker (const ExpandedIdentifier& id) const; - bool is_calo (const ExpandedIdentifier& id) const; - bool is_veto (const ExpandedIdentifier& id) const; - bool is_trigger (const ExpandedIdentifier& id) const; - bool is_preshower (const ExpandedIdentifier& id) const; - bool is_sct (const ExpandedIdentifier& id) const; - bool is_ecal (const ExpandedIdentifier& id) const; - //@} - - /// @name Dictionary versioning: provide access to dictionary names and versions. Note that a helper may correspond to one or more id dictionary - //@{ - /// Dictionary names - std::vector<std::string> dict_names(void) const; - /// File names for subdet dictionaries - std::vector<std::string> file_names(void) const; - /// Version tags for subdet dictionaries - std::vector<std::string> dict_tags (void) const; - //@} - - /// @name Checks are performed by default in debug compilation and NOT in optimized compilation. One can switch or query this mode for any idHelper with the following methods: - //@{ - virtual bool do_checks (void) const; - virtual void set_do_checks (bool do_checks); - //@} - - /// @name neighbours are initialized by default. One can switch or query this mode with the following methods: - //@{ - virtual bool do_neighbours (void) const; - virtual void set_do_neighbours (bool do_neighbours); - //@} - - /// @name setting pointer to the MessageService - //@{ - virtual void setMessageSvc (IMessageSvc* msgSvc); - //@} - - /// Set flag for suppressing informational output. - void set_quiet (bool quiet); - - -protected: - - friend class FaserDetectorIDHelper; - - void setDictVersion (const IdDictMgr& dict_mgr, const std::string& name); - - std::string to_range (const ExpandedIdentifier& id) const; - - std::string fix_barrel_ec (const std::string& barrel_ec) const; - - /// Detector systems: - ExpandedIdentifier scint_exp (void) const; - ExpandedIdentifier tracker_exp (void) const; - ExpandedIdentifier calo_exp (void) const; - - /// Scintillator: - ExpandedIdentifier veto_exp (void) const; - ExpandedIdentifier trigger_exp (void) const; - ExpandedIdentifier preshower_exp (void) const; - - /// Tracker: - ExpandedIdentifier sct_exp (void) const; - - /// Calorimeter: - ExpandedIdentifier ecal_exp (void) const; - - /// Provide efficient access to individual field values, for - /// subclass idhelpers - int scint_field_value () const; - int tracker_field_value () const; - int calo_field_value () const; - int veto_field_value () const; - int trigger_field_value () const; - int preshower_field_value () const; - int sct_field_value () const; - int ecal_field_value () const; - - /// Register the file and tag names for a particular IdDict - /// dictionary - int register_dict_tag (const IdDictMgr& dict_mgr, - const std::string& dict_name); - - /// Test whether an idhelper should be reinitialized based on the - /// change of tags - bool reinitialize (const IdDictMgr& dict_mgr); - - /// Flag for subclasses to know whether or not to perform - /// checks. In general, this is set to false in optimized mode. - mutable bool m_do_checks; - /// Flag for subclasses to know whether or not to perform - /// neighbour initialization - mutable bool m_do_neighbours; - - /// pointer to the message service - IMessageSvc* m_msgSvc; - - /// If true, suppress DEBUG/INFO messages. - bool m_quiet; - - - /// List of dictionary names used by this helper - std::vector<std::string> m_dict_names; - - /// List of dictionary file names used by this helper - std::vector<std::string> m_file_names; - - /// List of dictionary versions used by this helper - std::vector<std::string> m_dict_tags; -private: - - typedef Identifier::size_type size_type; - - // Identifiear numbering: - enum ID { - FASER_ID = static_cast<Identifier::value_type>(0), - MAX_BIT = Identifier::MAX_BIT, - ALL_BITS = Identifier::ALL_BITS }; - - int initLevelsFromDict(const IdDictMgr& dict_mgr); - - // dictionary version - std::string m_dict_version; - bool m_is_initialized_from_dict; - size_type m_DET_INDEX; - size_type m_SUBDET_INDEX; - int m_SCINT_ID; - int m_TRACKER_ID; - int m_CALO_ID; - int m_VETO_ID; - int m_TRIGGER_ID; - int m_PRESHOWER_ID; - int m_SCT_ID; - int m_ECAL_ID; - - /// Flag for slhc layout: - bool m_isSLHC; - - IdDictDictionary* m_faser_dict; - IdDictDictionary* m_scint_dict; - IdDictDictionary* m_tracker_dict; - IdDictDictionary* m_calo_dict; - FaserDetectorIDHelper* m_helper; - IdDictFieldImplementation m_det_impl; - IdDictFieldImplementation m_scint_part_impl; - IdDictFieldImplementation m_tracker_part_impl; - IdDictFieldImplementation m_calo_part_impl; -}; - - - -//<<<<<< INLINE PUBLIC FUNCTIONS >>>>>> - -//using the macros below we can assign an identifier (and a version) -//This is required and checked at compile time when you try to record/retrieve -CLASS_DEF(FaserDetectorIDBase, 168050226 , 1) - -///////////////////////////////////////////////////////////////////////////// -//<<<<<< INLINE MEMBER FUNCTIONS >>>>>> -///////////////////////////////////////////////////////////////////////////// - -inline ExpandedIdentifier -FaserDetectorIDBase::scint_exp (void) const -{ - ExpandedIdentifier result; - return (result << m_SCINT_ID); -} - -inline ExpandedIdentifier -FaserDetectorIDBase::tracker_exp (void) const -{ - ExpandedIdentifier result; - return (result << m_TRACKER_ID); -} - -inline ExpandedIdentifier -FaserDetectorIDBase::calo_exp(void) const -{ - ExpandedIdentifier result; - return (result << m_CALO_ID); -} - -inline ExpandedIdentifier -FaserDetectorIDBase::veto_exp (void) const -{ - ExpandedIdentifier result(scint_exp()); - return (result << m_VETO_ID); -} - -inline ExpandedIdentifier -FaserDetectorIDBase::trigger_exp (void) const -{ - ExpandedIdentifier result(scint_exp()); - return (result << m_TRIGGER_ID); -} - -inline ExpandedIdentifier -FaserDetectorIDBase::preshower_exp (void) const -{ - ExpandedIdentifier result(scint_exp()); - return (result << m_PRESHOWER_ID); -} - -inline ExpandedIdentifier -FaserDetectorIDBase::sct_exp (void) const -{ - ExpandedIdentifier result(tracker_exp()); - return (result << m_SCT_ID); -} - -inline ExpandedIdentifier -FaserDetectorIDBase::ecal_exp (void) const -{ - ExpandedIdentifier result(calo_exp()); - return (result << m_ECAL_ID); -} - -inline int -FaserDetectorIDBase::scint_field_value () const {return (m_SCINT_ID);} - -inline int -FaserDetectorIDBase::tracker_field_value () const {return (m_TRACKER_ID);} - -inline int -FaserDetectorIDBase::calo_field_value () const {return (m_CALO_ID);} - -inline int -FaserDetectorIDBase::veto_field_value () const {return (m_VETO_ID);} - -inline int -FaserDetectorIDBase::trigger_field_value () const {return (m_TRIGGER_ID);} - -inline int -FaserDetectorIDBase::preshower_field_value () const {return (m_PRESHOWER_ID);} - -inline int -FaserDetectorIDBase::sct_field_value () const {return (m_SCT_ID);} - -inline int -FaserDetectorIDBase::ecal_field_value () const {return (m_ECAL_ID);} - -inline bool -FaserDetectorIDBase::is_scint (Identifier id) const -{ - return (m_det_impl.unpack(id) == m_SCINT_ID); -} - -inline bool -FaserDetectorIDBase::is_tracker (Identifier id) const -{ - return (m_det_impl.unpack(id) == m_TRACKER_ID); -} - -inline bool -FaserDetectorIDBase::is_calo (Identifier id) const -{ - return (m_det_impl.unpack(id) == m_CALO_ID); -} - -inline bool -FaserDetectorIDBase::is_veto (Identifier id) const -{ - bool result = false; - if(is_scint(id)) { - result = (m_scint_part_impl.unpack(id) == m_VETO_ID); - } - return result; -} - -inline bool -FaserDetectorIDBase::is_trigger (Identifier id) const -{ - bool result = false; - if(is_scint(id)) { - result = (m_scint_part_impl.unpack(id) == m_TRIGGER_ID); - } - return result; -} - -inline bool -FaserDetectorIDBase::is_preshower (Identifier id) const -{ - bool result = false; - if(is_scint(id)) { - result = (m_scint_part_impl.unpack(id) == m_PRESHOWER_ID); - } - return result; -} - -inline bool -FaserDetectorIDBase::is_sct (Identifier id) const -{ - bool result = false; - if(is_tracker(id)) { - result = (m_tracker_part_impl.unpack(id) == m_SCT_ID); - } - return result; -} - -inline bool -FaserDetectorIDBase::is_ecal (Identifier id) const -{ - bool result = false; - if(is_calo(id)) { - result = (m_calo_part_impl.unpack(id) == m_ECAL_ID); - } - return result; -} - -#endif // FASERDETDESCR_FASERDETECTORIDBASE_H diff --git a/DetectorDescription/FaserDetDescr/FaserDetDescr/selection.xml b/DetectorDescription/FaserDetDescr/FaserDetDescr/selection.xml index ee21d32312fe1e27e5f27554ff212f45b3480fe2..e1dd6f004e601d9bc9e29984f6f5bb8bbddafb2f 100644 --- a/DetectorDescription/FaserDetDescr/FaserDetDescr/selection.xml +++ b/DetectorDescription/FaserDetDescr/FaserDetDescr/selection.xml @@ -1,6 +1,5 @@ <lcgdict> <enum pattern="FaserDetDescr::*"/> <class name="FaserDetDescr::ROOT6_NamespaceAutoloadHook" /> - <class name="FaserDetectorIDBase" /> - <!-- <class name="FaserDetectorID" /> --> + <class name="FaserDetectorID" /> </lcgdict> diff --git a/DetectorDescription/FaserDetDescr/src/FaserDetectorID.cxx b/DetectorDescription/FaserDetDescr/src/FaserDetectorID.cxx index 29b4ff691ac0ebc4974fafe3a17ef7cd49bd97ee..6bbaec02b606f0a19c04dca10c0016e435c8be77 100644 --- a/DetectorDescription/FaserDetDescr/src/FaserDetectorID.cxx +++ b/DetectorDescription/FaserDetDescr/src/FaserDetectorID.cxx @@ -1,21 +1,21 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration */ /*************************************************************************** - Scintillator identifier package - ------------------------------------------- + Detector Description + ----------------------------------------- ***************************************************************************/ //<<<<<< INCLUDES >>>>>> -#include "GaudiKernel/MsgStream.h" +#include "GaudiKernel/MsgStream.h" #include "FaserDetDescr/FaserDetectorID.h" -#include "Identifier/IdentifierHash.h" -#include "IdDict/IdDictDefs.h" -#include <set> -#include <algorithm> +#include "IdDict/IdDictDefs.h" +#include "FaserDetectorIDHelper.h" #include <iostream> +#include <stdio.h> +#include <assert.h> //<<<<<< PRIVATE DEFINES >>>>>> //<<<<<< PRIVATE CONSTANTS >>>>>> @@ -27,337 +27,1108 @@ //<<<<<< PUBLIC FUNCTION DEFINITIONS >>>>>> //<<<<<< MEMBER FUNCTION DEFINITIONS >>>>>> +FaserDetectorID::FaserDetectorID() + : + m_do_checks(false), + m_do_neighbours(true), + m_msgSvc(0), + m_quiet(false), + m_is_initialized_from_dict(false), + m_DET_INDEX(999), + m_SUBDET_INDEX(999), + m_SCINT_ID(2), + m_TRACKER_ID(3), + m_CALO_ID(4), + m_VETO_ID(1), + m_TRIGGER_ID(2), + m_PRESHOWER_ID(3), + m_SCT_ID(1), + m_ECAL_ID(1), + m_isSLHC(false), + m_faser_dict(0), + m_scint_dict(0), + m_tracker_dict(0), + m_calo_dict(0), + m_helper(0) +{} -///////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// - +FaserDetectorID::~FaserDetectorID(void) +{ + delete m_helper; +} -FaserDetectorID::FaserDetectorID(void) +FaserDetectorID::FaserDetectorID(const FaserDetectorID& other) : - m_faser_region_index(0), - m_SUBDET_INDEX(0), - m_PART_INDEX(1), - m_STATION_INDEX(2), - m_PLANE_INDEX(3), - m_MODULE_INDEX(4), - m_SUBMODULE_INDEX(5), - m_SENSOR_INDEX(6), - m_dict(0), - m_submodule_hash_max(0), - m_sensor_hash_max(0) + IdHelper(), + m_do_checks (other.m_do_checks), + m_do_neighbours (other.m_do_neighbours), + m_msgSvc (other.m_msgSvc), + m_quiet (other.m_quiet), + m_dict_version (other.m_dict_version), + m_is_initialized_from_dict(other.m_is_initialized_from_dict), + m_DET_INDEX (other.m_DET_INDEX), + m_SUBDET_INDEX (other.m_SUBDET_INDEX), + m_SCINT_ID (other.m_SCINT_ID), + m_TRACKER_ID (other.m_TRACKER_ID), + m_CALO_ID (other.m_CALO_ID), + m_VETO_ID (other.m_VETO_ID), + m_TRIGGER_ID (other.m_TRIGGER_ID), + m_PRESHOWER_ID (other.m_PRESHOWER_ID), + m_SCT_ID (other.m_SCT_ID), + m_ECAL_ID (other.m_ECAL_ID), + m_isSLHC (other.m_isSLHC), + m_faser_dict (other.m_faser_dict), + m_scint_dict (other.m_scint_dict), + m_tracker_dict (other.m_tracker_dict), + m_calo_dict (other.m_calo_dict), + m_helper (0), + m_det_impl (other.m_det_impl), + m_scint_part_impl (other.m_scint_part_impl), + m_tracker_part_impl (other.m_tracker_part_impl), + m_calo_part_impl (other.m_calo_part_impl) + { + if (other.m_helper) { + // Must copy helper + m_helper = new FaserDetectorIDHelper(*other.m_helper); + m_helper->setMsgSvc(m_msgSvc); + } } -int -FaserDetectorID::init_hashes(void) -{ - - // - // create a vector(s) to retrieve the hashes for compact ids. For - // the moment, we implement a hash for submodules but NOT for sensors - // - MsgStream log(m_msgSvc, "FaserDetectorID"); - // wafer hash - m_submodule_hash_max = m_full_submodule_range.cardinality(); - m_submodule_vec.resize(m_submodule_hash_max); - unsigned int nids = 0; - std::set<Identifier> ids; - for (unsigned int i = 0; i < m_full_submodule_range.size(); ++i) { - const Range& range = m_full_submodule_range[i]; - Range::const_identifier_factory first = range.factory_begin(); - Range::const_identifier_factory last = range.factory_end(); - for (; first != last; ++first) { - const ExpandedIdentifier& exp_id = (*first); - Identifier id = submodule_id(exp_id[m_STATION_INDEX], - exp_id[m_PLANE_INDEX], - exp_id[m_MODULE_INDEX], - exp_id[m_SUBMODULE_INDEX]); - if(!(ids.insert(id)).second) { - log << MSG::ERROR << " FaserDetectorID::init_hashes " - << " Error: duplicated id for plate id. nid " << nids - << " compact id " << id.getString() - << " id " << (std::string)exp_id << endmsg; - return (1); - } - nids++; +FaserDetectorID& +FaserDetectorID::operator= (const FaserDetectorID& other) +{ + if (this != &other) { + m_do_checks = other.m_do_checks; + m_do_neighbours = other.m_do_neighbours; + m_msgSvc = other.m_msgSvc; + m_quiet = other.m_quiet; + m_dict_version = other.m_dict_version; + m_is_initialized_from_dict = other.m_is_initialized_from_dict; + m_DET_INDEX = other.m_DET_INDEX; + m_SUBDET_INDEX = other.m_SUBDET_INDEX; + m_SCINT_ID = other.m_SCINT_ID; + m_TRACKER_ID = other.m_TRACKER_ID; + m_CALO_ID = other.m_CALO_ID; + m_VETO_ID = other.m_VETO_ID; + m_TRIGGER_ID = other.m_TRIGGER_ID; + m_PRESHOWER_ID = other.m_PRESHOWER_ID; + m_SCT_ID = other.m_SCT_ID; + m_ECAL_ID = other.m_ECAL_ID; + m_faser_dict = other.m_faser_dict; + m_scint_dict = other.m_scint_dict; + m_tracker_dict = other.m_tracker_dict; + m_calo_dict = other.m_calo_dict; + m_det_impl = other.m_det_impl; + m_scint_part_impl = other.m_scint_part_impl; + m_tracker_part_impl = other.m_tracker_part_impl; + m_calo_part_impl = other.m_calo_part_impl; + + if (other.m_helper) { + // Must copy helper. + delete m_helper; + m_helper = new FaserDetectorIDHelper(*other.m_helper); + m_helper->setMsgSvc(m_msgSvc); } } - if(ids.size() != m_submodule_hash_max) { - log << MSG::ERROR << " FaserDetectorID::init_hashes " - << " Error: set size NOT EQUAL to hash max. size " << ids.size() - << " hash max " << m_submodule_hash_max - << endmsg; - return (1); - } - nids = 0; - std::set<Identifier>::const_iterator first = ids.begin(); - std::set<Identifier>::const_iterator last = ids.end(); - for (; first != last && nids < m_submodule_vec.size(); ++first) { - m_submodule_vec[nids] = (*first); - nids++; - } + return (*this); +} + + +Identifier +FaserDetectorID::scint (void) const +{ + + Identifier result((Identifier::value_type)0); + // Pack field + m_det_impl.pack (scint_field_value(), result); + return (result); +} + +Identifier +FaserDetectorID::tracker (void) const +{ + Identifier result((Identifier::value_type)0); + // Pack field + m_det_impl.pack (tracker_field_value(), result); + return (result); +} - // sensor hash - we do not keep a vec for the sensors - m_sensor_hash_max = m_full_sensor_range.cardinality(); +Identifier +FaserDetectorID::calo(void) const +{ + Identifier result((Identifier::value_type)0); + // Pack field + m_det_impl.pack (calo_field_value(), result); + return (result); +} + +Identifier +FaserDetectorID::veto (void) const +{ + Identifier result((Identifier::value_type)0); + // Pack field + m_det_impl.pack (scint_field_value(), result); + m_scint_part_impl.pack(m_VETO_ID, result); + return (result); +} + +Identifier +FaserDetectorID::trigger (void) const +{ + Identifier result((Identifier::value_type)0); + // Pack field + m_det_impl.pack (scint_field_value(), result); + m_scint_part_impl.pack(m_TRIGGER_ID, result); + return (result); +} + +Identifier +FaserDetectorID::preshower (void) const +{ + Identifier result((Identifier::value_type)0); + // Pack field + m_det_impl.pack (scint_field_value(), result); + m_scint_part_impl.pack(m_PRESHOWER_ID, result); + return (result); +} + +Identifier +FaserDetectorID::sct (void) const +{ + Identifier result((Identifier::value_type)0); + // Pack field + m_det_impl.pack (tracker_field_value(), result); + m_tracker_part_impl.pack(m_SCT_ID, result); + return (result); +} + +Identifier +FaserDetectorID::ecal (void) const +{ + Identifier result((Identifier::value_type)0); + // Pack field + m_det_impl.pack (calo_field_value(), result); + m_calo_part_impl.pack(m_ECAL_ID, result); + return (result); +} + +/// IdContext (indicates id length) for detector systems +IdContext +FaserDetectorID::detsystem_context (void) const +{ + ExpandedIdentifier id; + return (IdContext(id, 0, m_DET_INDEX)); +} + +/// IdContext (indicates id length) for sub-detector +IdContext +FaserDetectorID::subdet_context (void) const +{ + ExpandedIdentifier id; + return (IdContext(id, 0, m_SUBDET_INDEX)); +} + + +int +FaserDetectorID::get_id (const IdentifierHash& /*hash_id*/, + Identifier& /*id*/, + const IdContext* /*context*/) const +{ return (0); } +int +FaserDetectorID::get_hash (const Identifier& /*id*/, + IdentifierHash& /*hash_id*/, + const IdContext* /*context*/) const +{ + return (0); +} int -FaserDetectorID::initialize_from_dictionary(const IdDictMgr& dict_mgr) +FaserDetectorID::register_dict_tag (const IdDictMgr& dict_mgr, + const std::string& dict_name) { - MsgStream log(m_msgSvc, "FaserDetectorID"); - log << MSG::INFO << "Initialize from dictionary" << endmsg; - - // Check whether this helper should be reinitialized - if (!reinitialize(dict_mgr)) { - log << MSG::INFO << "Request to reinitialize not satisfied - tags have not changed" << endmsg; - return (0); - } - else { - if (m_msgSvc) { - log << MSG::DEBUG << "(Re)initialize" << endmsg; + // Register version of dictionary dict_name + + // Access dictionary by name + IdDictDictionary* dict = dict_mgr.find_dictionary(dict_name); + if (!dict) return(1); + // Add in dict name, file name and version + m_dict_names.push_back(dict_name); + m_file_names.push_back(dict->file_name()); + m_dict_tags.push_back(dict->dict_tag()); + return (0); +} + +/// Test whether an idhelper should be reinitialized based on the +/// change of tags +bool +FaserDetectorID::reinitialize (const IdDictMgr& dict_mgr) +{ + // If no tag has been registered, then reinitialize + if (m_dict_tags.size() == 0) return (true); + + // If no dict names have been registered, then reinitialize + if (m_dict_names.size() == 0) return (true); + + // Loop over dict names and check version tags + if (m_dict_names.size() != m_dict_tags.size()) { + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::ERROR << "reinitialize: dict names and tags vectors not the same length " << endmsg; + log << MSG::ERROR << "names: " << m_dict_names.size() << " tags: " << m_dict_tags.size() << endmsg; } else { - std::cout << " DEBUG (Re)initialize" << std::endl; + std::cout << MSG::ERROR << "reinitialize: dict names and tags vectors not the same length " << std::endl; + std::cout << "FaserDetectorID::reinitialize ERROR names: " << m_dict_names.size() << " tags: " << m_dict_tags.size() << std::endl; + } + } + for (unsigned int i = 0; i < m_dict_names.size(); ++i) { + // Access dictionary by name + IdDictDictionary* dict = dict_mgr.find_dictionary(m_dict_names[i]); + if (!dict) { + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::ERROR << "reinitialize: could not find dict - " << m_dict_names[i] << endmsg; + } + else { + std::cout << "FaserDetectorID::reinitialize ERROR could not find dict - " << m_dict_names[i] << std::endl; + } + return(false); + } + if (m_dict_tags[i] != dict->dict_tag()) { + // Remove all memory of versions + m_dict_names.clear(); + m_dict_tags.clear(); + m_file_names.clear(); + return (true); } } - // init base object - if(FaserDetectorIDBase::initialize_from_dictionary(dict_mgr)) return (1); + // Tags match - don't reinitialize + return (false); +} + - // Register version of InnerDetector dictionary - if (register_dict_tag(dict_mgr, "Scintillator")) return(1); - m_dict = dict_mgr.find_dictionary ("Scintillator"); - if(!m_dict) { - log << MSG::ERROR << " FaserDetectorID::initialize_from_dict - cannot access Scintillator dictionary " << endmsg; - return 1; +int +FaserDetectorID::initialize_from_dictionary(const IdDictMgr& dict_mgr) +{ + + // Register version of FASER dictionary + if (register_dict_tag(dict_mgr, "FASER")) return(1); + + // Initialize helper, needed for init of FaserDetectorID + if(!m_helper) { + m_helper = new FaserDetectorIDHelper; + m_helper->setMsgSvc(m_msgSvc); } - // Initialize the field indices - if(initLevelsFromDict()) return (1); + if(m_helper->initialize_from_dictionary(dict_mgr)) return (1); - // - // Build multirange for the valid set of identifiers - // + // Initialize level indices and id values from dicts + if(initLevelsFromDict(dict_mgr)) return (1); + m_is_initialized_from_dict = true; - // Find value for the field Scintillator - const IdDictDictionary* faserDict = dict_mgr.find_dictionary ("FASER"); - int scintField = -1; - if (faserDict->get_label_value("subdet", "Scintillator", scintField)) { - log << MSG::ERROR << "Could not get value for label 'Scintillator' of field 'subdet' in dictionary " - << faserDict->m_name - << endmsg; - return (1); + if (!m_quiet) { + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::INFO << "initialize_from_dictionary - OK" << endmsg; + } + else { + std::cout << " FaserDetectorID::initialize_from_dictionary - OK " << std::endl; + } } + + return (0); +} - // Find value for the field Veto - int vetoField = -1; - if (m_dict->get_label_value("part", "Veto", vetoField)) { - log << MSG::ERROR << "Could not get value for label 'Veto' of field 'part' in dictionary " - << m_dict->m_name - << endmsg; - return (1); + +std::string +FaserDetectorID::dictionaryVersion (void) const +{ + return (m_dict_version); +} + +bool +FaserDetectorID::is_scint (const ExpandedIdentifier& id) const +{ + bool result = false; + if ( id.fields() > 0 ){ + if ( id[0] == m_SCINT_ID) result = true; } - if (m_msgSvc) { - log << MSG::DEBUG << " VetoID::initialize_from_dict " - << "Found field values: Veto " - << vetoField - << std::endl; + return result; +} + +bool +FaserDetectorID::is_tracker (const ExpandedIdentifier& id) const +{ + bool result = false; + if ( id.fields() > 0 ){ + if ( id[0] == m_TRACKER_ID) result = true; } - else { - std::cout << " DEBUG VetoID::initialize_from_dict " - << "Found field values: Veto " - << vetoField - << std::endl; + return result; +} + +bool +FaserDetectorID::is_calo (const ExpandedIdentifier& id) const +{ + bool result = false; + if ( id.fields() > 0 ){ + if ( id[0] == m_CALO_ID ) result = true; } - - // Set up id for region and range prefix - ExpandedIdentifier region_id; - region_id.add(scintField); - region_id.add(vetoField); - Range prefix; - m_full_plate_range = m_dict->build_multirange(region_id, prefix, "plate"); - m_full_pmt_range = m_dict->build_multirange(region_id, prefix); + return result; +} - - if (m_msgSvc) { - log << MSG::INFO << " VetoID::initialize_from_dict " << endmsg; - log << MSG::DEBUG - << "Plate range -> " << (std::string)m_full_plate_range - << endmsg; - log << MSG::DEBUG - << "Pmt range -> " << (std::string)m_full_pmt_range - << endmsg; +bool +FaserDetectorID::is_veto (const ExpandedIdentifier& id) const +{ + bool result = false; + if ( is_scint(id) && id.fields() > 1 ){ + if ( id[1] == m_VETO_ID ) result = true; + } + return result; +} + +bool +FaserDetectorID::is_trigger (const ExpandedIdentifier& id) const +{ + bool result = false; + if ( is_scint(id) && id.fields() > 1 ){ + if ( id[1] == m_TRIGGER_ID ) return(true); + } + return result; +} + +bool +FaserDetectorID::is_preshower (const ExpandedIdentifier& id) const +{ + bool result = false; + if ( is_scint(id) && id.fields() > 1 ){ + if ( id[1] == m_PRESHOWER_ID ) result = true; + } + return result; +} + +bool +FaserDetectorID::is_sct (const ExpandedIdentifier& id) const +{ + bool result = false; + if ( is_tracker(id) && id.fields() > 1 ){ + if ( id[1] == m_SCT_ID ) result = true; + } + return result; +} + +bool +FaserDetectorID::is_ecal (const ExpandedIdentifier& id) const +{ + bool result = false; + if ( is_calo(id) && id.fields() > 1 ){ + if ( id[1] == m_ECAL_ID ) result = true; + } + return result; +} + +// Short print out of any identifier: +void +FaserDetectorID::show (Identifier id, + const IdContext* context, + char sep ) const +{ + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::INFO << show_to_string(id, context, sep) << endmsg; } else { - std::cout << " INFO VetoID::initialize_from_dict " << std::endl; - std::cout << " DEBUG Plate range -> " << (std::string)m_full_plate_range - << std::endl; - std::cout << " DEBUG Pmt range -> " << (std::string)m_full_pmt_range - << std::endl; + std::cout << show_to_string(id, context, sep) << std::endl; } - - return 0; } -int -FaserDetectorID::initLevelsFromDict() +// or provide the printout in string form +std::string +FaserDetectorID::show_to_string (Identifier id, + const IdContext* context, + char sep ) const { + // Do a generic printout of identifier + std::string result("Unable to decode id"); + unsigned int max_index = (context) ? context->end_index() : 999; - MsgStream log(m_msgSvc, "FaserDetectorID"); - if(!m_dict) { - log << MSG::ERROR << " FaserDetectorID::initLevelsFromDict - dictionary NOT initialized " << endmsg; - return (1); + if (!m_is_initialized_from_dict) return (result); + + // Find the dictionary to use: + IdDictDictionary* dict = 0; + ExpandedIdentifier expId; + ExpandedIdentifier prefix; // default is null prefix + Identifier compact = id; + + if (is_scint(id)) { + dict = m_scint_dict; + } + else if (is_tracker(id)) { + dict = m_tracker_dict; + } + else if (is_calo(id)) { + dict = m_calo_dict; } - - // Find out which identifier field corresponds to each level. Use - // names to find each field/leve. - - m_SUBDET_INDEX = 999; - m_PART_INDEX = 999; - m_STATION_INDEX = 999; - m_PLANE_INDEX = 999; - m_MODULE_INDEX = 999; - m_SUBMODULE_INDEX = 999; - m_SENSOR_INDEX = 999; - - // Save index to a Veto region for unpacking - ExpandedIdentifier id; - id << scint_field_value() << veto_field_value(); - if (m_dict->find_region(id, m_veto_region_index)) { - log << MSG::ERROR << "FaserDetectorID::initLevelsFromDict - unable to find veto region index: id, reg " - << (std::string)id << " " << m_veto_region_index - << endmsg; - return (1); + if (!dict) return (result); + + if (dict->unpack(compact, + prefix, + max_index, + expId)) { + return (result); } - // Find a Vetp region - IdDictField* field = m_dict->find_field("subdet"); - if (field) { - m_SCINT_INDEX = field->m_index; + bool first = true; + char temp[20]; + + result = ""; + if ('.' == sep) result = "["; + for (unsigned int i = 0; i < expId.fields(); ++i) { + if (first) first = false; + else result += sep; + sprintf (temp, "%d", expId[i]); + result += temp; + } + if ('.' == sep) result += "]"; + +// result += " compact ["; +// sprintf (temp, "0x%x", (unsigned int)compact); +// result += temp; +// result += "]"; + + return (result); +} + + + +void +FaserDetectorID::print (Identifier id, + const IdContext* context) const +{ + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::INFO << print_to_string(id, context) << endmsg; } else { - log << MSG::ERROR << "VetoID::initLevelsFromDict - unable to find 'subdet' field " << endmsg; - return (1); + std::cout << print_to_string(id, context) << std::endl; } - field = m_dict->find_field("part"); - if (field) { - m_VETO_INDEX = field->m_index; +} + +std::string +FaserDetectorID::print_to_string (Identifier id, + const IdContext* context) const +{ + // Print out for any Faser identifier + std::string result; + if (m_is_initialized_from_dict) { + + // Do a generic printout of identifier from dictionary + unsigned int max_index = (context) ? context->end_index() : 999; + + // Find the dictionary to use: + IdDictDictionary* dict = 0; + ExpandedIdentifier expId; + ExpandedIdentifier prefix; // default is null prefix + Identifier compact = id; + + if (is_scint(id)) { + dict = m_scint_dict; + } + else if (is_tracker(id)) { + dict = m_tracker_dict; + } + else if (is_calo(id)) { + dict = m_calo_dict; + } + + if (!dict) return (result); + + if (dict->unpack(compact, + prefix, + max_index, + " ", + result)) { + return (result); + } + } + return (result); +} + +/// Dictionary name +std::vector<std::string> +FaserDetectorID::dict_names (void) const +{ + return (m_dict_names); +} + +/// File name +std::vector<std::string> +FaserDetectorID::file_names (void) const +{ + return (m_file_names); +} + +/// Version tag for subdet dictionary +std::vector<std::string> +FaserDetectorID::dict_tags (void) const +{ + return (m_dict_tags); +} + +bool +FaserDetectorID::do_checks (void) const +{ + return (m_do_checks); +} + +void +FaserDetectorID::set_do_checks (bool do_checks) +{ + m_do_checks = do_checks; +} + +bool +FaserDetectorID::do_neighbours (void) const +{ + return (m_do_neighbours); +} + +void +FaserDetectorID::set_do_neighbours (bool do_neighbours) +{ + m_do_neighbours = do_neighbours; +} + +void +FaserDetectorID::setMessageSvc (IMessageSvc* msgSvc) +{ + m_msgSvc = msgSvc ; +} + +void +FaserDetectorID::set_quiet (bool quiet) +{ + m_quiet = quiet ; +} + +void +FaserDetectorID::setDictVersion (const IdDictMgr& dict_mgr, const std::string& name) +{ + const IdDictDictionary* dict = dict_mgr.find_dictionary (name); + + m_dict_version = dict->m_version; +} + +std::string +FaserDetectorID::to_range (const ExpandedIdentifier& id) const +{ + + // Build a string from the contents of an identifier + + int fields = id.fields(); + char temp[10] = ""; + std::string result(""); + + for (int i = 0; i < fields; ++i) { + sprintf( temp, "%d", id[i]); + if (i > 0) result += '/'; // add '/' only if NOT last one + result += temp; + } + + return result; +} + +int +FaserDetectorID::initLevelsFromDict(const IdDictMgr& dict_mgr) +{ + + // Set do_checks flag + if (dict_mgr.do_checks()) m_do_checks = true; + // Set do_neighbours flag + if (!dict_mgr.do_neighbours()) m_do_neighbours = false; + + IdDictLabel* label = 0; + IdDictField* field = 0; + + // Find out from the dictionary the detector and subdetector + // levels and id values + m_DET_INDEX = 999; + m_SUBDET_INDEX = 999; + m_SCINT_ID = -1; + m_TRACKER_ID = -1; + m_CALO_ID = -1; + m_VETO_ID = -1; + m_TRIGGER_ID = -1; + m_PRESHOWER_ID = -1; + m_SCT_ID = -1; + m_ECAL_ID = -1; + + // Save generic dict for top levels + IdDictDictionary* top_dict = 0; + + // Get det ids + + // Initialize ids for InDet subdet + m_scint_dict = dict_mgr.find_dictionary ("Scintillator"); + if(!m_scint_dict) { + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::WARNING << "initLevelsFromDict - cannot access Scintillator dictionary" << endmsg; + } + else { + std::cout << " FaserDetectorID::initLevelsFromDict - Warning cannot access Scintillator dictionary " + << std::endl; + } } else { - log << MSG::ERROR << "VetoID::initLevelsFromDict - unable to find 'part' field " << endmsg; - return (1); + + // Found Scint dict + + top_dict = m_scint_dict; // save as top_dict + + // Check if this is SLHC layout + m_isSLHC = (m_scint_dict->m_version=="SLHC"); + + // Get Scint subdets + + field = m_scint_dict->find_field("part"); + if (!field) { + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::ERROR << "initLevelsFromDict - unable to find 'part' field for Scintillator dictionary" << endmsg; + } + else { + std::cout << "FaserDetectorID::initLevelsFromDict - unable to find 'part' field for Scintillator dictionary" + << std::endl; + } + return (1); + } + + label = field->find_label("Veto"); + if (label) { + if (label->m_valued) { + m_VETO_ID = label->m_value; + } + else { + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::ERROR << "initLevelsFromDict - label Veto does NOT have a value " + << endmsg; + } + else { + std::cout << "FaserDetectorID::initLevelsFromDict - label Veto does NOT have a value " + << std::endl; + } + return (1); + } + } + else { + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::ERROR << "initLevelsFromDict - unable to find 'Veto' label " + << endmsg; + } + else { + std::cout << "FaserDetectorID::initLevelsFromDict - unable to find 'Veto' label " + << std::endl; + } + return (1); + } + + label = field->find_label("Trigger"); + if (label) { + if (label->m_valued) { + m_TRIGGER_ID = label->m_value; + } + else { + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::ERROR << "initLevelsFromDict - label Trigger does NOT have a value " + << endmsg; + } + else { + std::cout << "FaserDetectorID::initLevelsFromDict - label Trigger does NOT have a value " + << std::endl; + } + return (1); + } + } + else { + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::ERROR << "initLevelsFromDict - unable to find 'Trigger' label " + << endmsg; + } + else { + std::cout << "FaserDetectorID::initLevelsFromDict - unable to find 'Trigger' label " + << std::endl; + } + return (1); + } + + label = field->find_label("Preshower"); + if (label) { + if (label->m_valued) { + m_PRESHOWER_ID = label->m_value; + } + else { + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::ERROR << "initLevelsFromDict - label Preshower does NOT have a value " + << endmsg; + } + else { + std::cout << "FaserDetectorID::initLevelsFromDict - label Preshower does NOT have a value " + << std::endl; + } + return (1); + } + } + else { + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::ERROR << "initLevelsFromDict - unable to find 'Preshower' label " + << endmsg; + } + else { + std::cout << "FaserDetectorID::initLevelsFromDict - unable to find 'Preshower' label " + << std::endl; + } + return (1); + } + } - field = m_dict->find_field("station"); - if (field) { - m_STATION_INDEX = field->m_index; + + // Initialize ids for Tracker + m_tracker_dict = dict_mgr.find_dictionary ("Tracker"); + if(!m_tracker_dict) { + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::WARNING << "initLevelsFromDict - cannot access Tracker dictionary " + << endmsg; + } + else { + std::cout << " FaserDetectorID::initLevelsFromDict - Warning cannot access Tracker dictionary " + << std::endl; + } } else { - log << MSG::ERROR << "VetoID::initLevelsFromDict - unable to find 'station' field " << endmsg; - return (1); + // Found Tracker dict + + if (!top_dict) top_dict = m_tracker_dict; // save as top_dict + + field = m_tracker_dict->find_field("part"); + if (!field) { + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::ERROR << "initLevelsFromDict - unable to find 'station' field for Tracker dictionary" + << endmsg; + } + else { + std::cout << "FaserDetectorID::initLevelsFromDict - unable to find 'station' field for Tracker dictionary" + << std::endl; + } + return (1); + } + + label = field->find_label("SCT"); + if (label) { + if (label->m_valued) { + m_SCT_ID = label->m_value; + } + else { + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::ERROR << "initLevelsFromDict - label SCT does NOT have a value " + << endmsg; + } + else { + std::cout << "FaserDetectorID::initLevelsFromDict - label SCT does NOT have a value " + << std::endl; + } + return (1); + } + } + else { + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::ERROR << "initLevelsFromDict - unable to find 'SCT' label " + << endmsg; + } + else { + std::cout << "FaserDetectorID::initLevelsFromDict - unable to find 'SCT' label " + << std::endl; + } + return (1); + } } - field = m_dict->find_field("plate"); - if (field) { - m_PLATE_INDEX = field->m_index; + + // Initialize id for Calo and fields for lvl1 and dead material + m_calo_dict = dict_mgr.find_dictionary ("Calorimeter"); + if(!m_calo_dict) { + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::ERROR << "initLevelsFromDict - Warning cannot access Calorimeter dictionary " + << endmsg; + } + else { + std::cout << " FaserDetectorID::initLevelsFromDict - Warning cannot access Calorimeter dictionary " + << std::endl; + } } else { - log << MSG::ERROR << "VetoID::initLevelsFromDict - unable to find 'plate' field " << endmsg; - return (1); + // Found calo dict + if (!top_dict) top_dict = m_calo_dict; // save as top_dict + + // Get Scint subdets + field = m_calo_dict->find_field("part"); + if (!field) { + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::ERROR << "initLevelsFromDict - unable to find 'part' field for Calorimeter dictionary" << endmsg; + } + else { + std::cout << "FaserDetectorID::initLevelsFromDict - unable to find 'part' field for Calorimeter dictionary" + << std::endl; + } + return (1); + } + + label = field->find_label("ECAL"); + if (label) { + if (label->m_valued) { + m_ECAL_ID = label->m_value; + } + else { + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::ERROR << "initLevelsFromDict - label ECAL does NOT have a value " + << endmsg; + } + else { + std::cout << "FaserDetectorID::initLevelsFromDict - label ECAL does NOT have a value " + << std::endl; + } + return (1); + } + } + else { + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::ERROR << "initLevelsFromDict - unable to find 'ECAL' label " + << endmsg; + } + else { + std::cout << "FaserDetectorID::initLevelsFromDict - unable to find 'ECAL' label " + << std::endl; + } + return (1); + } } - field = m_dict->find_field("pmt"); - if (field) { - m_PMT_INDEX = field->m_index; + + // set det/subdet indices + if (top_dict) { + field = top_dict->find_field("subdet"); + if (field) { + m_DET_INDEX = field->m_index; + } + else { + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::ERROR << "initLevelsFromDict - - unable to find 'subdet' field from dict " + << endmsg; + } + else { + std::cout << "FaserDetectorID::initLevelsFromDict - unable to find 'subdet' field from dict " + << top_dict->m_name + << std::endl; + } + return (1); + } + + // Get scint id + label = field->find_label("Scintillator"); + if (label) { + if (label->m_valued) { + m_SCINT_ID = label->m_value; + } + else { + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::ERROR << "initLevelsFromDict - label Scintillator does NOT have a value " + << endmsg; + } + else { + std::cout << "FaserDetectorID::initLevelsFromDict - label Scintillator does NOT have a value " + << std::endl; + } + return (1); + } + } + else { + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::ERROR << "initLevelsFromDict - unable to find 'Scintillator' label " + << endmsg; + } + else { + std::cout << "FaserDetectorID::initLevelsFromDict - unable to find 'Scintillator' label " + << std::endl; + } + return (1); + } + + // Get Tracker id + label = field->find_label("Tracker"); + if (label) { + if (label->m_valued) { + m_TRACKER_ID = label->m_value; + } + else { + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::ERROR << "initLevelsFromDict - label Tracker does NOT have a value " + << endmsg; + } + else { + std::cout << "FaserDetectorID::initLevelsFromDict - label Tracker does NOT have a value " + << std::endl; + } + return (1); + } + } + else { + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::ERROR << "initLevelsFromDict - unable to find 'Tracker' label " + << endmsg; + } + else { + std::cout << "FaserDetectorID::initLevelsFromDict - unable to find 'Tracker' label " + << std::endl; + } + return (1); + } + + // Get Calo id + label = field->find_label("Calorimeter"); + if (label) { + if (label->m_valued) { + m_CALO_ID = label->m_value; + } + else { + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::ERROR << "initLevelsFromDict - label Calorimeter does NOT have a value " + << endmsg; + } + else { + std::cout << "FaserDetectorID::initLevelsFromDict - label Calorimeter does NOT have a value " + << std::endl; + } + return (1); + } + } + else { + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::ERROR << "initLevelsFromDict - unable to find 'Calorimeter' label " + << endmsg; + } + else { + std::cout << "FaserDetectorID::initLevelsFromDict - unable to find 'Calorimeter' label " + << std::endl; + } + return (1); + } + + // Get name of next level + std::string name; + if (top_dict->m_name == "Scintillator") { + name = "part"; + } + else if (top_dict->m_name == "Calorimeter") { + name = "part"; + } + else if (top_dict->m_name == "Tracker") { + name = "part"; + } + + // While we're here, save the index to the sub-detector level + // ("part" for InDet) + field = top_dict->find_field(name); + if (field) { + m_SUBDET_INDEX = field->m_index; + } + else { + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::ERROR << "initLevelsFromDict - unable to find field " + << name << " from dict " + << top_dict->m_name + << endmsg; + } + else { + std::cout << "FaserDetectorID::initLevelsFromDict - unable to find field " + << name << " from dict " + << top_dict->m_name + << std::endl; + } + return (1); + } } else { - log << MSG::ERROR<< "VetoID::initLevelsFromDict - unable to find 'pmt' field " << endmsg; + if(m_msgSvc) { + MsgStream log(m_msgSvc, "FaserDetectorID" ); + log << MSG::ERROR << "initLevelsFromDict - no top dictionary defined " + << endmsg; + } + else { + std::cout << "FaserDetectorID::initLevelsFromDict - no top dictionary defined " + << std::endl; + } return (1); } - - // Set the field implementations: for station, plate, pmt - const IdDictRegion& region = *m_dict->m_regions[m_veto_region_index]; - m_scint_impl = region.m_implementation[m_SCINT_INDEX]; - m_veto_impl = region.m_implementation[m_VETO_INDEX]; - m_station_impl = region.m_implementation[m_STATION_INDEX]; - m_plate_impl = region.m_implementation[m_PLATE_INDEX]; - m_pmt_impl = region.m_implementation[m_PMT_INDEX]; + // Set the field implementations - if (m_msgSvc) { - log << MSG::DEBUG << "decode index and bit fields for each level: " << endmsg; - log << MSG::DEBUG << "scint " << m_scint_impl.show_to_string() << endmsg; - log << MSG::DEBUG << "veto " << m_veto_impl.show_to_string() << endmsg; - log << MSG::DEBUG << "station " << m_station_impl.show_to_string() << endmsg; - log << MSG::DEBUG << "plate " << m_plate_impl.show_to_string() << endmsg; - log << MSG::DEBUG << "pmt " << m_pmt_impl.show_to_string() << endmsg; + const IdDictRegion* region = 0; + size_type region_index = m_helper->veto_region_index(); + if (m_scint_dict && FaserDetectorIDHelper::UNDEFINED != region_index) { + region = m_scint_dict->m_regions[region_index]; + // Detector + m_det_impl = region->m_implementation[m_DET_INDEX]; + // InDet part + m_scint_part_impl = region->m_implementation[m_SUBDET_INDEX]; } - else { - std::cout << " DEBUG decode index and bit fields for each level: " << std::endl; - std::cout << " DEBUG scint " << m_scint_impl.show_to_string() << std::endl; - std::cout << " DEBUG veto " << m_veto_impl.show_to_string() << std::endl; - std::cout << " DEBUG station " << m_station_impl.show_to_string() << std::endl; - std::cout << " DEBUG plate " << m_plate_impl.show_to_string() << std::endl; - std::cout << " DEBUG pmt " << m_pmt_impl.show_to_string() << std::endl; + + region_index = m_helper->sct_region_index(); + if (m_tracker_dict && FaserDetectorIDHelper::UNDEFINED != region_index) { + region = m_tracker_dict->m_regions[region_index]; + // Detector + m_det_impl = region->m_implementation[m_DET_INDEX]; + // InDet part + m_tracker_part_impl = region->m_implementation[m_SUBDET_INDEX]; + } + + region_index = m_helper->ecal_region_index(); + if (m_calo_dict && FaserDetectorIDHelper::UNDEFINED != region_index) { + region = m_calo_dict->m_regions[region_index]; + // Detector + m_det_impl = region->m_implementation[m_DET_INDEX]; + // InDet part + m_calo_part_impl = region->m_implementation[m_SUBDET_INDEX]; } - -// std::cout << "SCT_ID::initLevelsFromDict - found levels " << std::endl; -// std::cout << "subdet " << m_INDET_INDEX << std::endl; -// std::cout << "part " << m_SCT_INDEX << std::endl; -// std::cout << "barrel_endcap " << m_BARREL_EC_INDEX << std::endl; -// std::cout << "layer or disk " << m_LAYER_DISK_INDEX << std::endl; -// std::cout << "phi_module " << m_PHI_MODULE_INDEX << std::endl; -// std::cout << "eta_module " << m_ETA_MODULE_INDEX << std::endl; -// std::cout << "side " << m_SIDE_INDEX << std::endl; -// std::cout << "strip " << m_STRIP_INDEX << std::endl; - - std::cout << "scint " << m_scint_impl.decode_index() << " " - << (std::string)m_scint_impl.ored_field() << " " - << std::hex << m_scint_impl.mask() << " " - << m_scint_impl.zeroing_mask() << " " - << std::dec << m_scint_impl.shift() << " " - << m_scint_impl.bits() << " " - << m_scint_impl.bits_offset() - << std::endl; - std::cout << "veto" << m_veto_impl.decode_index() << " " - << (std::string)m_veto_impl.ored_field() << " " - << std::hex << m_veto_impl.mask() << " " - << m_veto_impl.zeroing_mask() << " " - << std::dec << m_veto_impl.shift() << " " - << m_veto_impl.bits() << " " - << m_veto_impl.bits_offset() - << std::endl; - std::cout << "station" << m_station_impl.decode_index() << " " - << (std::string)m_station_impl.ored_field() << " " - << std::hex << m_station_impl.mask() << " " - << m_station_impl.zeroing_mask() << " " - << std::dec << m_station_impl.shift() << " " - << m_station_impl.bits() << " " - << m_station_impl.bits_offset() - << std::endl; - std::cout << "plate"<< m_plate_impl.decode_index() << " " - << (std::string)m_plate_impl.ored_field() << " " - << std::hex << m_plate_impl.mask() << " " - << m_plate_impl.zeroing_mask() << " " - << std::dec << m_plate_impl.shift() << " " - << m_plate_impl.bits() << " " - << m_plate_impl.bits_offset() - << std::endl; - std::cout << "pmt" << m_pmt_impl.decode_index() << " " - << (std::string)m_pmt_impl.ored_field() << " " - << std::hex << m_pmt_impl.mask() << " " - << m_pmt_impl.zeroing_mask() << " " - << std::dec << m_pmt_impl.shift() << " " - << m_pmt_impl.bits() << " " - << m_pmt_impl.bits_offset() - << std::endl; return (0); } - diff --git a/DetectorDescription/FaserDetDescr/src/FaserDetectorIDBase.cxx b/DetectorDescription/FaserDetDescr/src/FaserDetectorIDBase.cxx deleted file mode 100644 index fb2b3706e0ed59ea44639826a19baeaa822e5b24..0000000000000000000000000000000000000000 --- a/DetectorDescription/FaserDetDescr/src/FaserDetectorIDBase.cxx +++ /dev/null @@ -1,1134 +0,0 @@ -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - -/*************************************************************************** - Detector Description - ----------------------------------------- -***************************************************************************/ - -//<<<<<< INCLUDES >>>>>> - -#include "GaudiKernel/MsgStream.h" -#include "FaserDetDescr/FaserDetectorIDBase.h" -#include "IdDict/IdDictDefs.h" -#include "FaserDetectorIDHelper.h" -#include <iostream> -#include <stdio.h> -#include <assert.h> - -//<<<<<< PRIVATE DEFINES >>>>>> -//<<<<<< PRIVATE CONSTANTS >>>>>> -//<<<<<< PRIVATE TYPES >>>>>> -//<<<<<< PRIVATE VARIABLE DEFINITIONS >>>>>> -//<<<<<< PUBLIC VARIABLE DEFINITIONS >>>>>> -//<<<<<< CLASS STRUCTURE INITIALIZATION >>>>>> -//<<<<<< PRIVATE FUNCTION DEFINITIONS >>>>>> -//<<<<<< PUBLIC FUNCTION DEFINITIONS >>>>>> -//<<<<<< MEMBER FUNCTION DEFINITIONS >>>>>> - -FaserDetectorIDBase::FaserDetectorIDBase() - : - m_do_checks(false), - m_do_neighbours(true), - m_msgSvc(0), - m_quiet(false), - m_is_initialized_from_dict(false), - m_DET_INDEX(999), - m_SUBDET_INDEX(999), - m_SCINT_ID(2), - m_TRACKER_ID(3), - m_CALO_ID(4), - m_VETO_ID(1), - m_TRIGGER_ID(2), - m_PRESHOWER_ID(3), - m_SCT_ID(1), - m_ECAL_ID(1), - m_isSLHC(false), - m_faser_dict(0), - m_scint_dict(0), - m_tracker_dict(0), - m_calo_dict(0), - m_helper(0) -{} - -FaserDetectorIDBase::~FaserDetectorIDBase(void) -{ - delete m_helper; -} - -FaserDetectorIDBase::FaserDetectorIDBase(const FaserDetectorIDBase& other) - : - IdHelper(), - m_do_checks (other.m_do_checks), - m_do_neighbours (other.m_do_neighbours), - m_msgSvc (other.m_msgSvc), - m_quiet (other.m_quiet), - m_dict_version (other.m_dict_version), - m_is_initialized_from_dict(other.m_is_initialized_from_dict), - m_DET_INDEX (other.m_DET_INDEX), - m_SUBDET_INDEX (other.m_SUBDET_INDEX), - m_SCINT_ID (other.m_SCINT_ID), - m_TRACKER_ID (other.m_TRACKER_ID), - m_CALO_ID (other.m_CALO_ID), - m_VETO_ID (other.m_VETO_ID), - m_TRIGGER_ID (other.m_TRIGGER_ID), - m_PRESHOWER_ID (other.m_PRESHOWER_ID), - m_SCT_ID (other.m_SCT_ID), - m_ECAL_ID (other.m_ECAL_ID), - m_isSLHC (other.m_isSLHC), - m_faser_dict (other.m_faser_dict), - m_scint_dict (other.m_scint_dict), - m_tracker_dict (other.m_tracker_dict), - m_calo_dict (other.m_calo_dict), - m_helper (0), - m_det_impl (other.m_det_impl), - m_scint_part_impl (other.m_scint_part_impl), - m_tracker_part_impl (other.m_tracker_part_impl), - m_calo_part_impl (other.m_calo_part_impl) - -{ - if (other.m_helper) { - // Must copy helper - m_helper = new FaserDetectorIDHelper(*other.m_helper); - m_helper->setMsgSvc(m_msgSvc); - } -} - -FaserDetectorIDBase& -FaserDetectorIDBase::operator= (const FaserDetectorIDBase& other) -{ - if (this != &other) { - m_do_checks = other.m_do_checks; - m_do_neighbours = other.m_do_neighbours; - m_msgSvc = other.m_msgSvc; - m_quiet = other.m_quiet; - m_dict_version = other.m_dict_version; - m_is_initialized_from_dict = other.m_is_initialized_from_dict; - m_DET_INDEX = other.m_DET_INDEX; - m_SUBDET_INDEX = other.m_SUBDET_INDEX; - m_SCINT_ID = other.m_SCINT_ID; - m_TRACKER_ID = other.m_TRACKER_ID; - m_CALO_ID = other.m_CALO_ID; - m_VETO_ID = other.m_VETO_ID; - m_TRIGGER_ID = other.m_TRIGGER_ID; - m_PRESHOWER_ID = other.m_PRESHOWER_ID; - m_SCT_ID = other.m_SCT_ID; - m_ECAL_ID = other.m_ECAL_ID; - m_faser_dict = other.m_faser_dict; - m_scint_dict = other.m_scint_dict; - m_tracker_dict = other.m_tracker_dict; - m_calo_dict = other.m_calo_dict; - m_det_impl = other.m_det_impl; - m_scint_part_impl = other.m_scint_part_impl; - m_tracker_part_impl = other.m_tracker_part_impl; - m_calo_part_impl = other.m_calo_part_impl; - - if (other.m_helper) { - // Must copy helper. - delete m_helper; - m_helper = new FaserDetectorIDHelper(*other.m_helper); - m_helper->setMsgSvc(m_msgSvc); - } - } - - return (*this); -} - - -Identifier -FaserDetectorIDBase::scint (void) const -{ - - Identifier result((Identifier::value_type)0); - // Pack field - m_det_impl.pack (scint_field_value(), result); - return (result); -} - -Identifier -FaserDetectorIDBase::tracker (void) const -{ - Identifier result((Identifier::value_type)0); - // Pack field - m_det_impl.pack (tracker_field_value(), result); - return (result); -} - -Identifier -FaserDetectorIDBase::calo(void) const -{ - Identifier result((Identifier::value_type)0); - // Pack field - m_det_impl.pack (calo_field_value(), result); - return (result); -} - - -Identifier -FaserDetectorIDBase::veto (void) const -{ - Identifier result((Identifier::value_type)0); - // Pack field - m_det_impl.pack (scint_field_value(), result); - m_scint_part_impl.pack(m_VETO_ID, result); - return (result); -} - -Identifier -FaserDetectorIDBase::trigger (void) const -{ - Identifier result((Identifier::value_type)0); - // Pack field - m_det_impl.pack (scint_field_value(), result); - m_scint_part_impl.pack(m_TRIGGER_ID, result); - return (result); -} - -Identifier -FaserDetectorIDBase::preshower (void) const -{ - Identifier result((Identifier::value_type)0); - // Pack field - m_det_impl.pack (scint_field_value(), result); - m_scint_part_impl.pack(m_PRESHOWER_ID, result); - return (result); -} - -Identifier -FaserDetectorIDBase::sct (void) const -{ - Identifier result((Identifier::value_type)0); - // Pack field - m_det_impl.pack (tracker_field_value(), result); - m_tracker_part_impl.pack(m_SCT_ID, result); - return (result); -} - -Identifier -FaserDetectorIDBase::ecal (void) const -{ - Identifier result((Identifier::value_type)0); - // Pack field - m_det_impl.pack (calo_field_value(), result); - m_calo_part_impl.pack(m_ECAL_ID, result); - return (result); -} - -/// IdContext (indicates id length) for detector systems -IdContext -FaserDetectorIDBase::detsystem_context (void) const -{ - ExpandedIdentifier id; - return (IdContext(id, 0, m_DET_INDEX)); -} - -/// IdContext (indicates id length) for sub-detector -IdContext -FaserDetectorIDBase::subdet_context (void) const -{ - ExpandedIdentifier id; - return (IdContext(id, 0, m_SUBDET_INDEX)); -} - - -int -FaserDetectorIDBase::get_id (const IdentifierHash& /*hash_id*/, - Identifier& /*id*/, - const IdContext* /*context*/) const -{ - return (0); -} - -int -FaserDetectorIDBase::get_hash (const Identifier& /*id*/, - IdentifierHash& /*hash_id*/, - const IdContext* /*context*/) const -{ - return (0); -} - -int -FaserDetectorIDBase::register_dict_tag (const IdDictMgr& dict_mgr, - const std::string& dict_name) -{ - // Register version of dictionary dict_name - - // Access dictionary by name - IdDictDictionary* dict = dict_mgr.find_dictionary(dict_name); - if (!dict) return(1); - // Add in dict name, file name and version - m_dict_names.push_back(dict_name); - m_file_names.push_back(dict->file_name()); - m_dict_tags.push_back(dict->dict_tag()); - return (0); -} - -/// Test whether an idhelper should be reinitialized based on the -/// change of tags -bool -FaserDetectorIDBase::reinitialize (const IdDictMgr& dict_mgr) -{ - // If no tag has been registered, then reinitialize - if (m_dict_tags.size() == 0) return (true); - - // If no dict names have been registered, then reinitialize - if (m_dict_names.size() == 0) return (true); - - // Loop over dict names and check version tags - if (m_dict_names.size() != m_dict_tags.size()) { - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::ERROR << "reinitialize: dict names and tags vectors not the same length " << endmsg; - log << MSG::ERROR << "names: " << m_dict_names.size() << " tags: " << m_dict_tags.size() << endmsg; - } - else { - std::cout << MSG::ERROR << "reinitialize: dict names and tags vectors not the same length " << std::endl; - std::cout << "FaserDetectorIDBase::reinitialize ERROR names: " << m_dict_names.size() << " tags: " << m_dict_tags.size() << std::endl; - } - } - for (unsigned int i = 0; i < m_dict_names.size(); ++i) { - // Access dictionary by name - IdDictDictionary* dict = dict_mgr.find_dictionary(m_dict_names[i]); - if (!dict) { - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::ERROR << "reinitialize: could not find dict - " << m_dict_names[i] << endmsg; - } - else { - std::cout << "FaserDetectorIDBase::reinitialize ERROR could not find dict - " << m_dict_names[i] << std::endl; - } - return(false); - } - if (m_dict_tags[i] != dict->dict_tag()) { - // Remove all memory of versions - m_dict_names.clear(); - m_dict_tags.clear(); - m_file_names.clear(); - return (true); - } - } - - // Tags match - don't reinitialize - return (false); -} - - - -int -FaserDetectorIDBase::initialize_from_dictionary(const IdDictMgr& dict_mgr) -{ - - // Register version of FASER dictionary - if (register_dict_tag(dict_mgr, "FASER")) return(1); - - // Initialize helper, needed for init of FaserDetectorIDBase - if(!m_helper) { - m_helper = new FaserDetectorIDHelper; - m_helper->setMsgSvc(m_msgSvc); - } - - if(m_helper->initialize_from_dictionary(dict_mgr)) return (1); - - // Initialize level indices and id values from dicts - if(initLevelsFromDict(dict_mgr)) return (1); - - m_is_initialized_from_dict = true; - - if (!m_quiet) { - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::INFO << "initialize_from_dictionary - OK" << endmsg; - } - else { - std::cout << " FaserDetectorIDBase::initialize_from_dictionary - OK " << std::endl; - } - } - - return (0); -} - - -std::string -FaserDetectorIDBase::dictionaryVersion (void) const -{ - return (m_dict_version); -} - -bool -FaserDetectorIDBase::is_scint (const ExpandedIdentifier& id) const -{ - bool result = false; - if ( id.fields() > 0 ){ - if ( id[0] == m_SCINT_ID) result = true; - } - return result; -} - -bool -FaserDetectorIDBase::is_tracker (const ExpandedIdentifier& id) const -{ - bool result = false; - if ( id.fields() > 0 ){ - if ( id[0] == m_TRACKER_ID) result = true; - } - return result; -} - -bool -FaserDetectorIDBase::is_calo (const ExpandedIdentifier& id) const -{ - bool result = false; - if ( id.fields() > 0 ){ - if ( id[0] == m_CALO_ID ) result = true; - } - return result; -} - -bool -FaserDetectorIDBase::is_veto (const ExpandedIdentifier& id) const -{ - bool result = false; - if ( is_scint(id) && id.fields() > 1 ){ - if ( id[1] == m_VETO_ID ) result = true; - } - return result; -} - -bool -FaserDetectorIDBase::is_trigger (const ExpandedIdentifier& id) const -{ - bool result = false; - if ( is_scint(id) && id.fields() > 1 ){ - if ( id[1] == m_TRIGGER_ID ) return(true); - } - return result; -} - -bool -FaserDetectorIDBase::is_preshower (const ExpandedIdentifier& id) const -{ - bool result = false; - if ( is_scint(id) && id.fields() > 1 ){ - if ( id[1] == m_PRESHOWER_ID ) result = true; - } - return result; -} - -bool -FaserDetectorIDBase::is_sct (const ExpandedIdentifier& id) const -{ - bool result = false; - if ( is_tracker(id) && id.fields() > 1 ){ - if ( id[1] == m_SCT_ID ) result = true; - } - return result; -} - -bool -FaserDetectorIDBase::is_ecal (const ExpandedIdentifier& id) const -{ - bool result = false; - if ( is_calo(id) && id.fields() > 1 ){ - if ( id[1] == m_ECAL_ID ) result = true; - } - return result; -} - -// Short print out of any identifier: -void -FaserDetectorIDBase::show (Identifier id, - const IdContext* context, - char sep ) const -{ - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::INFO << show_to_string(id, context, sep) << endmsg; - } - else { - std::cout << show_to_string(id, context, sep) << std::endl; - } -} - -// or provide the printout in string form -std::string -FaserDetectorIDBase::show_to_string (Identifier id, - const IdContext* context, - char sep ) const -{ - // Do a generic printout of identifier - - std::string result("Unable to decode id"); - unsigned int max_index = (context) ? context->end_index() : 999; - - if (!m_is_initialized_from_dict) return (result); - - // Find the dictionary to use: - IdDictDictionary* dict = 0; - ExpandedIdentifier expId; - ExpandedIdentifier prefix; // default is null prefix - Identifier compact = id; - - if (is_scint(id)) { - dict = m_scint_dict; - } - else if (is_tracker(id)) { - dict = m_tracker_dict; - } - else if (is_calo(id)) { - dict = m_calo_dict; - } - - if (!dict) return (result); - - if (dict->unpack(compact, - prefix, - max_index, - expId)) { - return (result); - } - - bool first = true; - char temp[20]; - - result = ""; - if ('.' == sep) result = "["; - for (unsigned int i = 0; i < expId.fields(); ++i) { - if (first) first = false; - else result += sep; - sprintf (temp, "%d", expId[i]); - result += temp; - } - if ('.' == sep) result += "]"; - -// result += " compact ["; -// sprintf (temp, "0x%x", (unsigned int)compact); -// result += temp; -// result += "]"; - - return (result); -} - - - -void -FaserDetectorIDBase::print (Identifier id, - const IdContext* context) const -{ - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::INFO << print_to_string(id, context) << endmsg; - } - else { - std::cout << print_to_string(id, context) << std::endl; - } -} - -std::string -FaserDetectorIDBase::print_to_string (Identifier id, - const IdContext* context) const -{ - // Print out for any Faser identifier - std::string result; - if (m_is_initialized_from_dict) { - - // Do a generic printout of identifier from dictionary - unsigned int max_index = (context) ? context->end_index() : 999; - - // Find the dictionary to use: - IdDictDictionary* dict = 0; - ExpandedIdentifier expId; - ExpandedIdentifier prefix; // default is null prefix - Identifier compact = id; - - if (is_scint(id)) { - dict = m_scint_dict; - } - else if (is_tracker(id)) { - dict = m_tracker_dict; - } - else if (is_calo(id)) { - dict = m_calo_dict; - } - - if (!dict) return (result); - - if (dict->unpack(compact, - prefix, - max_index, - " ", - result)) { - return (result); - } - } - return (result); -} - -/// Dictionary name -std::vector<std::string> -FaserDetectorIDBase::dict_names (void) const -{ - return (m_dict_names); -} - -/// File name -std::vector<std::string> -FaserDetectorIDBase::file_names (void) const -{ - return (m_file_names); -} - -/// Version tag for subdet dictionary -std::vector<std::string> -FaserDetectorIDBase::dict_tags (void) const -{ - return (m_dict_tags); -} - -bool -FaserDetectorIDBase::do_checks (void) const -{ - return (m_do_checks); -} - -void -FaserDetectorIDBase::set_do_checks (bool do_checks) -{ - m_do_checks = do_checks; -} - -bool -FaserDetectorIDBase::do_neighbours (void) const -{ - return (m_do_neighbours); -} - -void -FaserDetectorIDBase::set_do_neighbours (bool do_neighbours) -{ - m_do_neighbours = do_neighbours; -} - -void -FaserDetectorIDBase::setMessageSvc (IMessageSvc* msgSvc) -{ - m_msgSvc = msgSvc ; -} - -void -FaserDetectorIDBase::set_quiet (bool quiet) -{ - m_quiet = quiet ; -} - -void -FaserDetectorIDBase::setDictVersion (const IdDictMgr& dict_mgr, const std::string& name) -{ - const IdDictDictionary* dict = dict_mgr.find_dictionary (name); - - m_dict_version = dict->m_version; -} - -std::string -FaserDetectorIDBase::to_range (const ExpandedIdentifier& id) const -{ - - // Build a string from the contents of an identifier - - int fields = id.fields(); - char temp[10] = ""; - std::string result(""); - - for (int i = 0; i < fields; ++i) { - sprintf( temp, "%d", id[i]); - if (i > 0) result += '/'; // add '/' only if NOT last one - result += temp; - } - - return result; -} - -int -FaserDetectorIDBase::initLevelsFromDict(const IdDictMgr& dict_mgr) -{ - - // Set do_checks flag - if (dict_mgr.do_checks()) m_do_checks = true; - // Set do_neighbours flag - if (!dict_mgr.do_neighbours()) m_do_neighbours = false; - - IdDictLabel* label = 0; - IdDictField* field = 0; - - // Find out from the dictionary the detector and subdetector - // levels and id values - m_DET_INDEX = 999; - m_SUBDET_INDEX = 999; - m_SCINT_ID = -1; - m_TRACKER_ID = -1; - m_CALO_ID = -1; - m_VETO_ID = -1; - m_TRIGGER_ID = -1; - m_PRESHOWER_ID = -1; - m_SCT_ID = -1; - m_ECAL_ID = -1; - - // Save generic dict for top levels - IdDictDictionary* top_dict = 0; - - // Get det ids - - // Initialize ids for InDet subdet - m_scint_dict = dict_mgr.find_dictionary ("Scintillator"); - if(!m_scint_dict) { - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::WARNING << "initLevelsFromDict - cannot access Scintillator dictionary" << endmsg; - } - else { - std::cout << " FaserDetectorIDBase::initLevelsFromDict - Warning cannot access Scintillator dictionary " - << std::endl; - } - } - else { - - // Found Scint dict - - top_dict = m_scint_dict; // save as top_dict - - // Check if this is SLHC layout - m_isSLHC = (m_scint_dict->m_version=="SLHC"); - - // Get Scint subdets - - field = m_scint_dict->find_field("part"); - if (!field) { - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::ERROR << "initLevelsFromDict - unable to find 'part' field for Scintillator dictionary" << endmsg; - } - else { - std::cout << "FaserDetectorIDBase::initLevelsFromDict - unable to find 'part' field for Scintillator dictionary" - << std::endl; - } - return (1); - } - - label = field->find_label("Veto"); - if (label) { - if (label->m_valued) { - m_VETO_ID = label->m_value; - } - else { - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::ERROR << "initLevelsFromDict - label Veto does NOT have a value " - << endmsg; - } - else { - std::cout << "FaserDetectorIDBase::initLevelsFromDict - label Veto does NOT have a value " - << std::endl; - } - return (1); - } - } - else { - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::ERROR << "initLevelsFromDict - unable to find 'Veto' label " - << endmsg; - } - else { - std::cout << "FaserDetectorIDBase::initLevelsFromDict - unable to find 'Veto' label " - << std::endl; - } - return (1); - } - - label = field->find_label("Trigger"); - if (label) { - if (label->m_valued) { - m_TRIGGER_ID = label->m_value; - } - else { - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::ERROR << "initLevelsFromDict - label Trigger does NOT have a value " - << endmsg; - } - else { - std::cout << "FaserDetectorIDBase::initLevelsFromDict - label Trigger does NOT have a value " - << std::endl; - } - return (1); - } - } - else { - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::ERROR << "initLevelsFromDict - unable to find 'Trigger' label " - << endmsg; - } - else { - std::cout << "FaserDetectorIDBase::initLevelsFromDict - unable to find 'Trigger' label " - << std::endl; - } - return (1); - } - - label = field->find_label("Preshower"); - if (label) { - if (label->m_valued) { - m_PRESHOWER_ID = label->m_value; - } - else { - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::ERROR << "initLevelsFromDict - label Preshower does NOT have a value " - << endmsg; - } - else { - std::cout << "FaserDetectorIDBase::initLevelsFromDict - label Preshower does NOT have a value " - << std::endl; - } - return (1); - } - } - else { - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::ERROR << "initLevelsFromDict - unable to find 'Preshower' label " - << endmsg; - } - else { - std::cout << "FaserDetectorIDBase::initLevelsFromDict - unable to find 'Preshower' label " - << std::endl; - } - return (1); - } - - } - - // Initialize ids for Tracker - m_tracker_dict = dict_mgr.find_dictionary ("Tracker"); - if(!m_tracker_dict) { - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::WARNING << "initLevelsFromDict - cannot access Tracker dictionary " - << endmsg; - } - else { - std::cout << " FaserDetectorIDBase::initLevelsFromDict - Warning cannot access Tracker dictionary " - << std::endl; - } - } - else { - // Found Tracker dict - - if (!top_dict) top_dict = m_tracker_dict; // save as top_dict - - field = m_tracker_dict->find_field("part"); - if (!field) { - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::ERROR << "initLevelsFromDict - unable to find 'station' field for Tracker dictionary" - << endmsg; - } - else { - std::cout << "FaserDetectorIDBase::initLevelsFromDict - unable to find 'station' field for Tracker dictionary" - << std::endl; - } - return (1); - } - - label = field->find_label("SCT"); - if (label) { - if (label->m_valued) { - m_SCT_ID = label->m_value; - } - else { - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::ERROR << "initLevelsFromDict - label SCT does NOT have a value " - << endmsg; - } - else { - std::cout << "FaserDetectorIDBase::initLevelsFromDict - label SCT does NOT have a value " - << std::endl; - } - return (1); - } - } - else { - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::ERROR << "initLevelsFromDict - unable to find 'SCT' label " - << endmsg; - } - else { - std::cout << "FaserDetectorIDBase::initLevelsFromDict - unable to find 'SCT' label " - << std::endl; - } - return (1); - } - } - - // Initialize id for Calo and fields for lvl1 and dead material - m_calo_dict = dict_mgr.find_dictionary ("Calorimeter"); - if(!m_calo_dict) { - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::ERROR << "initLevelsFromDict - Warning cannot access Calorimeter dictionary " - << endmsg; - } - else { - std::cout << " FaserDetectorIDBase::initLevelsFromDict - Warning cannot access Calorimeter dictionary " - << std::endl; - } - } - else { - // Found calo dict - if (!top_dict) top_dict = m_calo_dict; // save as top_dict - - // Get Scint subdets - field = m_calo_dict->find_field("part"); - if (!field) { - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::ERROR << "initLevelsFromDict - unable to find 'part' field for Calorimeter dictionary" << endmsg; - } - else { - std::cout << "FaserDetectorIDBase::initLevelsFromDict - unable to find 'part' field for Calorimeter dictionary" - << std::endl; - } - return (1); - } - - label = field->find_label("ECAL"); - if (label) { - if (label->m_valued) { - m_ECAL_ID = label->m_value; - } - else { - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::ERROR << "initLevelsFromDict - label ECAL does NOT have a value " - << endmsg; - } - else { - std::cout << "FaserDetectorIDBase::initLevelsFromDict - label ECAL does NOT have a value " - << std::endl; - } - return (1); - } - } - else { - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::ERROR << "initLevelsFromDict - unable to find 'ECAL' label " - << endmsg; - } - else { - std::cout << "FaserDetectorIDBase::initLevelsFromDict - unable to find 'ECAL' label " - << std::endl; - } - return (1); - } - } - - // set det/subdet indices - if (top_dict) { - field = top_dict->find_field("subdet"); - if (field) { - m_DET_INDEX = field->m_index; - } - else { - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::ERROR << "initLevelsFromDict - - unable to find 'subdet' field from dict " - << endmsg; - } - else { - std::cout << "FaserDetectorIDBase::initLevelsFromDict - unable to find 'subdet' field from dict " - << top_dict->m_name - << std::endl; - } - return (1); - } - - // Get scint id - label = field->find_label("Scintillator"); - if (label) { - if (label->m_valued) { - m_SCINT_ID = label->m_value; - } - else { - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::ERROR << "initLevelsFromDict - label Scintillator does NOT have a value " - << endmsg; - } - else { - std::cout << "FaserDetectorIDBase::initLevelsFromDict - label Scintillator does NOT have a value " - << std::endl; - } - return (1); - } - } - else { - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::ERROR << "initLevelsFromDict - unable to find 'Scintillator' label " - << endmsg; - } - else { - std::cout << "FaserDetectorIDBase::initLevelsFromDict - unable to find 'Scintillator' label " - << std::endl; - } - return (1); - } - - // Get Tracker id - label = field->find_label("Tracker"); - if (label) { - if (label->m_valued) { - m_TRACKER_ID = label->m_value; - } - else { - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::ERROR << "initLevelsFromDict - label Tracker does NOT have a value " - << endmsg; - } - else { - std::cout << "FaserDetectorIDBase::initLevelsFromDict - label Tracker does NOT have a value " - << std::endl; - } - return (1); - } - } - else { - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::ERROR << "initLevelsFromDict - unable to find 'Tracker' label " - << endmsg; - } - else { - std::cout << "FaserDetectorIDBase::initLevelsFromDict - unable to find 'Tracker' label " - << std::endl; - } - return (1); - } - - // Get Calo id - label = field->find_label("Calorimeter"); - if (label) { - if (label->m_valued) { - m_CALO_ID = label->m_value; - } - else { - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::ERROR << "initLevelsFromDict - label Calorimeter does NOT have a value " - << endmsg; - } - else { - std::cout << "FaserDetectorIDBase::initLevelsFromDict - label Calorimeter does NOT have a value " - << std::endl; - } - return (1); - } - } - else { - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::ERROR << "initLevelsFromDict - unable to find 'Calorimeter' label " - << endmsg; - } - else { - std::cout << "FaserDetectorIDBase::initLevelsFromDict - unable to find 'Calorimeter' label " - << std::endl; - } - return (1); - } - - // Get name of next level - std::string name; - if (top_dict->m_name == "Scintillator") { - name = "part"; - } - else if (top_dict->m_name == "Calorimeter") { - name = "part"; - } - else if (top_dict->m_name == "Tracker") { - name = "part"; - } - - // While we're here, save the index to the sub-detector level - // ("part" for InDet) - field = top_dict->find_field(name); - if (field) { - m_SUBDET_INDEX = field->m_index; - } - else { - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::ERROR << "initLevelsFromDict - unable to find field " - << name << " from dict " - << top_dict->m_name - << endmsg; - } - else { - std::cout << "FaserDetectorIDBase::initLevelsFromDict - unable to find field " - << name << " from dict " - << top_dict->m_name - << std::endl; - } - return (1); - } - } - else { - if(m_msgSvc) { - MsgStream log(m_msgSvc, "FaserDetectorIDBase" ); - log << MSG::ERROR << "initLevelsFromDict - no top dictionary defined " - << endmsg; - } - else { - std::cout << "FaserDetectorIDBase::initLevelsFromDict - no top dictionary defined " - << std::endl; - } - return (1); - } - - - // Set the field implementations - - const IdDictRegion* region = 0; - size_type region_index = m_helper->veto_region_index(); - if (m_scint_dict && FaserDetectorIDHelper::UNDEFINED != region_index) { - region = m_scint_dict->m_regions[region_index]; - // Detector - m_det_impl = region->m_implementation[m_DET_INDEX]; - // InDet part - m_scint_part_impl = region->m_implementation[m_SUBDET_INDEX]; - } - - region_index = m_helper->sct_region_index(); - if (m_tracker_dict && FaserDetectorIDHelper::UNDEFINED != region_index) { - region = m_tracker_dict->m_regions[region_index]; - // Detector - m_det_impl = region->m_implementation[m_DET_INDEX]; - // InDet part - m_tracker_part_impl = region->m_implementation[m_SUBDET_INDEX]; - } - - region_index = m_helper->ecal_region_index(); - if (m_calo_dict && FaserDetectorIDHelper::UNDEFINED != region_index) { - region = m_calo_dict->m_regions[region_index]; - // Detector - m_det_impl = region->m_implementation[m_DET_INDEX]; - // InDet part - m_calo_part_impl = region->m_implementation[m_SUBDET_INDEX]; - } - return (0); -} diff --git a/DetectorDescription/FaserDetDescr/src/FaserDetectorIDHelper.cxx b/DetectorDescription/FaserDetDescr/src/FaserDetectorIDHelper.cxx index d83d06cacd1b0dbdd795a17028b94e800738e547..0a877bb96448dbf00a8313a1e93b1d49a5be882a 100644 --- a/DetectorDescription/FaserDetDescr/src/FaserDetectorIDHelper.cxx +++ b/DetectorDescription/FaserDetDescr/src/FaserDetectorIDHelper.cxx @@ -11,7 +11,7 @@ #include "FaserDetectorIDHelper.h" #include "IdDict/IdDictDefs.h" -#include "FaserDetDescr/FaserDetectorIDBase.h" +#include "FaserDetDescr/FaserDetectorID.h" #include "GaudiKernel/MsgStream.h" #include <iostream> @@ -48,7 +48,7 @@ FaserDetectorIDHelper::initialize_from_dictionary(const IdDictMgr& dict_mgr) if(m_initialized) return(0); m_initialized = true; - FaserDetectorIDBase faser_id; + FaserDetectorID faser_id; ExpandedIdentifier id; const IdDictDictionary* dict = dict_mgr.find_dictionary ("Scintillator"); diff --git a/DetectorDescription/FaserReadoutGeometry/FaserReadoutGeometry/FaserDetectorManager.h b/DetectorDescription/FaserReadoutGeometry/FaserReadoutGeometry/FaserDetectorManager.h index 385b8bbc92b859b7b4f20ae36907d8fa63e3f66b..1371cc4046c0ced57deca84175801f377454b692 100644 --- a/DetectorDescription/FaserReadoutGeometry/FaserReadoutGeometry/FaserDetectorManager.h +++ b/DetectorDescription/FaserReadoutGeometry/FaserReadoutGeometry/FaserDetectorManager.h @@ -29,7 +29,7 @@ class StoreGateSvc; class AlignableTransform; class Identifier; -class FaserDetectorIDBase; +class FaserDetectorID; class GeoVAlignmentStore; class CondAttrListCollection; @@ -175,7 +175,7 @@ namespace FaserDD { const CondAttrListCollection* obj=nullptr, GeoVAlignmentStore* alignStore=nullptr) const; - virtual const FaserDetectorIDBase* getIdHelper() const = 0; + virtual const FaserDetectorID* getIdHelper() const = 0; //Declaring private message stream member. mutable Athena::MsgStreamMember m_msg; diff --git a/DetectorDescription/FaserReadoutGeometry/src/FaserDetectorManager.cxx b/DetectorDescription/FaserReadoutGeometry/src/FaserDetectorManager.cxx index 558c8bf0d1226142a1555b9dd1ba40dcacc7a241..053bf0d94fb64a9d3b5da2dd00e2ab0381ebcef4 100644 --- a/DetectorDescription/FaserReadoutGeometry/src/FaserDetectorManager.cxx +++ b/DetectorDescription/FaserReadoutGeometry/src/FaserDetectorManager.cxx @@ -7,7 +7,7 @@ #include "StoreGate/StoreGateSvc.h" #include "DetDescrConditions/AlignableTransform.h" -#include "FaserDetDescr/FaserDetectorIDBase.h" +#include "FaserDetDescr/FaserDetectorID.h" #include "GeoPrimitives/CLHEPtoEigenConverter.h" #include "AthenaPoolUtilities/CondAttrListCollection.h" #include "AthenaBaseComps/AthMsgStreamMacros.h" diff --git a/DetectorDescription/GeoModel/FaserGeoEditor/CMakeLists.txt b/DetectorDescription/GeoModel/FaserGeoEditor/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..1ce8cc6df4b93dc27f288bbfe8483d0502bccc77 --- /dev/null +++ b/DetectorDescription/GeoModel/FaserGeoEditor/CMakeLists.txt @@ -0,0 +1,44 @@ +################################################################################ +# Package: FaserGeoEdit +################################################################################ +# Author: +# Author: +################################################################################ + +# Declare the package name: +atlas_subdir( FaserGeoEditor ) + +# Declare the package's dependencies: +#atlas_depends_on_subdirs( +# PUBLIC Event/xAOD/xAODBase +# PUBLIC graphics/VP1/VP1Base +# PUBLIC graphics/VP1/VP1UtilsBase +# ) + +# External dependencies: +find_package( Qt5 COMPONENTS Core Sql OpenGL Gui Network PrintSupport Widgets REQUIRED ) + +# Generate UI files automatically: +set( CMAKE_AUTOUIC TRUE ) +# Generate MOC files automatically: +set( CMAKE_AUTOMOC TRUE ) +# Generate resource files automatically: +set( CMAKE_AUTORCC TRUE ) + +# Component(s) in the package: +#atlas_add_library( FaserGeoEditor FaserGeoEditor/*.h src/*.h src/*.cxx src/*.qrc +# PUBLIC_HEADERS FaserGeoEditor +# PRIVATE_INCLUDE_DIRS +# ${CMAKE_CURRENT_BINARY_DIR} +# LINK_LIBRARIES Qt5::Core Qt5::OpenGL Qt5::Gui Qt5::PrintSupport +# PRIVATE_LINK_LIBRARIES PathResolver Qt5::Network ) + + +atlas_add_executable( qtTest FaserGeoEditor/*.h src/*.cxx src/*.h + PRIVATE_INCLUDE_DIRS ${QT5_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR} + LINK_LIBRARIES Qt5::Core Qt5::Sql Qt5::OpenGL Qt5::Gui Qt5::Widgets Qt5::PrintSupport) + +# Install files from the package: +##atlas_install_scripts( share/* ) # installs into bin/ +atlas_install_runtime( share/* ) # install into share/ //TODO: check if we still need this! + diff --git a/DetectorDescription/GeoModel/FaserGeoEditor/src/FaserDbMainWindow.cxx b/DetectorDescription/GeoModel/FaserGeoEditor/src/FaserDbMainWindow.cxx new file mode 100644 index 0000000000000000000000000000000000000000..c605a339007404e00ee3ae914bdf4c5f304c11c1 --- /dev/null +++ b/DetectorDescription/GeoModel/FaserGeoEditor/src/FaserDbMainWindow.cxx @@ -0,0 +1,37 @@ +#include "FaserDbMainWindow.h" + +#include <QTreeView> +#include <QStandardItemModel> +#include <QStandardItem> +#include <iostream> + +FaserDbMainWindow::FaserDbMainWindow(QWidget* parent) + : QMainWindow(parent) + , m_treeView(new QTreeView(this)) + , m_standardModel(new QStandardItemModel(this)) +{ + setCentralWidget(m_treeView); + + QStandardItem* root = m_standardModel->invisibleRootItem(); + QList<QStandardItem*> firstRow = prepareRow("name 1", "leaf 1"); + root->appendRow(firstRow); + QList<QStandardItem*> secondRow = prepareRow("name 2", "leaf 2"); + root->appendRow(secondRow); + QList<QStandardItem*> subRow = prepareRow("subName 1", "subLeaf 1"); + firstRow.first()->appendRow(subRow); + + m_treeView->setModel(m_standardModel); + m_treeView->expandAll(); +} + +// FaserDbMainWindow::~FaserDbMainWindow() +// { +// if (m_standardModel != nullptr) delete m_standardModel; +// if (m_treeView != nullptr) delete m_treeView; +// } + +QList<QStandardItem*> FaserDbMainWindow::prepareRow(const QString& name, const QString& leaf) const +{ + return { new QStandardItem(name), + new QStandardItem(leaf)}; +} \ No newline at end of file diff --git a/DetectorDescription/GeoModel/FaserGeoEditor/src/FaserDbMainWindow.h b/DetectorDescription/GeoModel/FaserGeoEditor/src/FaserDbMainWindow.h new file mode 100644 index 0000000000000000000000000000000000000000..5b6cabbba1ef5f67d05a6f8879c378c0cfa90b8b --- /dev/null +++ b/DetectorDescription/GeoModel/FaserGeoEditor/src/FaserDbMainWindow.h @@ -0,0 +1,25 @@ +// #ifndef GEOMODEL_FASERDBMAINWINDOW_H +// #define GEOMODEL_FASERDBMAINWINDOW_H 1 + +#include <QMainWindow> +// #include <QtGui/QWidget> + +QT_BEGIN_NAMESPACE +class QTreeView; //forward declarations +class QStandardItemModel; +class QStandardItem; +QT_END_NAMESPACE + +class FaserDbMainWindow : public QMainWindow +{ + Q_OBJECT +private: + QTreeView* m_treeView; + QStandardItemModel* m_standardModel; + QList<QStandardItem *> prepareRow(const QString& name, const QString& leaf) const; +public: + FaserDbMainWindow(QWidget *parent = nullptr); + // virtual ~FaserDbMainWindow(); +}; + +// #endif \ No newline at end of file diff --git a/DetectorDescription/GeoModel/FaserGeoEditor/src/FaserGeoEditorApp.cxx b/DetectorDescription/GeoModel/FaserGeoEditor/src/FaserGeoEditorApp.cxx new file mode 100644 index 0000000000000000000000000000000000000000..182cd6d530f2bdba9bac97b37d095b497019fa74 --- /dev/null +++ b/DetectorDescription/GeoModel/FaserGeoEditor/src/FaserGeoEditorApp.cxx @@ -0,0 +1,24 @@ +#include <iostream> +#include "FaserGeoEditorApp.h" + +FaserGeoEditorApp::FaserGeoEditorApp(int& argc, char** argv) +: m_application(argc, argv), m_database(QSqlDatabase::addDatabase("QSQLITE")), m_mainWindow() +{ +// db file name should be first argument after command name; retrieve it + auto arguments = m_application.arguments(); + auto dbName = arguments.at(1); + std::cout << "Database name: " << dbName.toLocal8Bit().constData() << std::endl; + + m_database.setDatabaseName(dbName); + bool ok = m_database.open(); + std::cout << "Database open status: " << ok << std::endl; + + auto tables = m_database.tables(); + for (auto it = tables.constBegin(); it != tables.constEnd(); ++it) std::cout << (*it).toLocal8Bit().constData() << std::endl; +} + +int FaserGeoEditorApp::exec() +{ + m_mainWindow.show(); + return m_application.exec(); +} \ No newline at end of file diff --git a/DetectorDescription/GeoModel/FaserGeoEditor/src/FaserGeoEditorApp.h b/DetectorDescription/GeoModel/FaserGeoEditor/src/FaserGeoEditorApp.h new file mode 100644 index 0000000000000000000000000000000000000000..da0b5bc02e2d32076f8167adb12047a84acf806d --- /dev/null +++ b/DetectorDescription/GeoModel/FaserGeoEditor/src/FaserGeoEditorApp.h @@ -0,0 +1,22 @@ +#ifndef GEOMODEL_FASERGEOEDITORAPP_H +#define GEOMODEL_FASERGEOEDITORAPP_H + +#include <QStringList> +#include <QApplication> +#include <QSqlDatabase> +#include "FaserDbMainWindow.h" + +class FaserGeoEditorApp +{ + public: + FaserGeoEditorApp(int& argc, char** argv); + + int exec(); + QSqlDatabase& getDatabase() { return m_database; } + private: + QApplication m_application; + QSqlDatabase m_database; + FaserDbMainWindow m_mainWindow; +}; + +#endif \ No newline at end of file diff --git a/DetectorDescription/GeoModel/FaserGeoEditor/src/main.cxx b/DetectorDescription/GeoModel/FaserGeoEditor/src/main.cxx new file mode 100644 index 0000000000000000000000000000000000000000..d9ee9d7ae80a5c16b6d7d281966205a140aa83d0 --- /dev/null +++ b/DetectorDescription/GeoModel/FaserGeoEditor/src/main.cxx @@ -0,0 +1,21 @@ +// main.cpp +#include "FaserGeoEditorApp.h" +// #include <QTableView> +// #include <QStringList> +// #include <QSqlDatabase> +// #include <iostream> +// #include "mymodel.h" + +int main(int argc, char *argv[]) +{ + FaserGeoEditorApp a(argc, argv); + // QApplication a(argc, argv); + + // QTableView tableView; + // MyModel myModel; + // tableView.setModel(&myModel); + // tableView.show(); + // FaserDbMainWindow w; + // w.show(); + return a.exec(); +} diff --git a/DetectorDescription/GeoModel/FaserGeoModel/python/GeoModelInit.py b/DetectorDescription/GeoModel/FaserGeoModel/python/GeoModelInit.py index 9bd2f0da3ed983597facf0b56eef842f0290c0e8..6371517ce8cc4d3396cdf8d35ad22616da3fb1d6 100644 --- a/DetectorDescription/GeoModel/FaserGeoModel/python/GeoModelInit.py +++ b/DetectorDescription/GeoModel/FaserGeoModel/python/GeoModelInit.py @@ -27,7 +27,7 @@ def _setupGeoModel(): svcMgr+=GeometryDBSvc("ScintGeometryDBSvc") # from AthenaCommon import CfgGetter - from ScintGeoModel.ScintGeoModelConf import VetoDetectorTool + from VetoGeoModel.VetoGeoModelConf import VetoDetectorTool vetoDetectorTool = VetoDetectorTool( DetectorName = "Veto", Alignable = True, RDBAccessSvc = "RDBAccessSvc", diff --git a/DetectorDescription/IdDictDetDescrCnv/src/FaserIDDetDescrCnv.cxx b/DetectorDescription/IdDictDetDescrCnv/src/FaserIDDetDescrCnv.cxx index 0a9fc3970a7449d6a54cee2e61feb399ffb10279..dabb566be5e7332034158a7f834d01a9deb89e6a 100644 --- a/DetectorDescription/IdDictDetDescrCnv/src/FaserIDDetDescrCnv.cxx +++ b/DetectorDescription/IdDictDetDescrCnv/src/FaserIDDetDescrCnv.cxx @@ -18,7 +18,7 @@ #include "AthenaKernel/StorableConversions.h" #include "IdDictDetDescr/IdDictManager.h" -#include "FaserDetDescr/FaserDetectorIDBase.h" +#include "FaserDetDescr/FaserDetectorID.h" #include "CxxUtils/make_unique.h" //<<<<<< PRIVATE DEFINES >>>>>> @@ -90,7 +90,7 @@ FaserIDDetDescrCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj) { //StatusCode sc = StatusCode::SUCCESS; MsgStream log(msgSvc(), "FaserIDDetDescrCnv"); - log << MSG::INFO << "in createObj: creating a FaserDetectorIDBase helper object in the detector store" << endmsg; + log << MSG::INFO << "in createObj: creating a FaserDetectorID helper object in the detector store" << endmsg; // Create a new AtlasDetectorID @@ -132,11 +132,11 @@ FaserIDDetDescrCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj) // create the helper - auto faser_id = CxxUtils::make_unique<FaserDetectorIDBase>(); + auto faser_id = CxxUtils::make_unique<FaserDetectorID>(); faser_id->setMessageSvc(msgSvc()); if (idDictMgr->initializeHelper(*faser_id)) { - log << MSG::ERROR << "Unable to initialize FaserDetectorIDBase" << endmsg; + log << MSG::ERROR << "Unable to initialize FaserDetectorID" << endmsg; return StatusCode::FAILURE; } @@ -158,13 +158,13 @@ FaserIDDetDescrCnv::storageType() //-------------------------------------------------------------------- const CLID& FaserIDDetDescrCnv::classID() { - return ClassID_traits<FaserDetectorIDBase>::ID(); + return ClassID_traits<FaserDetectorID>::ID(); } //-------------------------------------------------------------------- FaserIDDetDescrCnv::FaserIDDetDescrCnv(ISvcLocator* svcloc) : - DetDescrConverter(ClassID_traits<FaserDetectorIDBase>::ID(), svcloc) + DetDescrConverter(ClassID_traits<FaserDetectorID>::ID(), svcloc) {} diff --git a/Scintillator/ScintDetDescr/ScintGeoModel/ScintGeoModel/ScintGeoModelAthenaComps.h b/Scintillator/ScintDetDescr/ScintGeoModel/ScintGeoModel/ScintGeoModelAthenaComps.h deleted file mode 100644 index a90869b75bac310077f365dbf8900160610e1409..0000000000000000000000000000000000000000 --- a/Scintillator/ScintDetDescr/ScintGeoModel/ScintGeoModel/ScintGeoModelAthenaComps.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration -*/ - -#ifndef ScintGeoModel_ScintGeoModelAthenaComps_H -#define ScintGeoModel_ScintGeoModelAthenaComps_H - -#include "InDetGeoModelUtils/InDetDDAthenaComps.h" - -// class VetoID; - - -/// Class to hold various Athena components -template <class ID_HELPER> -class ScintGeoModelAthenaComps : public InDetDD::AthenaComps { - -public: - - ScintGeoModelAthenaComps(const std::string& name); - - void setIdHelper(const ID_HELPER* idHelper); - - const ID_HELPER* getIdHelper() const; - -private: - const ID_HELPER* m_idHelper; - -}; - -#include "ScintGeoModel/ScintGeoModelAthenaComps.icc" - -#endif // ScintGeoModel_ScintGeoModelAthenaComps_H diff --git a/Scintillator/ScintDetDescr/ScintGeoModel/ScintGeoModel/ScintGeoModelAthenaComps.icc b/Scintillator/ScintDetDescr/ScintGeoModel/ScintGeoModel/ScintGeoModelAthenaComps.icc deleted file mode 100644 index aeed853028e1e57abb062b31b81310bccc450484..0000000000000000000000000000000000000000 --- a/Scintillator/ScintDetDescr/ScintGeoModel/ScintGeoModel/ScintGeoModelAthenaComps.icc +++ /dev/null @@ -1,26 +0,0 @@ -/* - Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration -*/ - -#include "ScintGeoModel/ScintGeoModelAthenaComps.h" - -template <class ID_HELPER> -ScintGeoModelAthenaComps<ID_HELPER>::ScintGeoModelAthenaComps(const std::string& name) - : InDetDD::AthenaComps(name), - m_idHelper(0) -{} - -template <class ID_HELPER> -void -ScintGeoModelAthenaComps<ID_HELPER>::setIdHelper(const ID_HELPER* idHelper) -{ - m_idHelper = idHelper; -} - -template <class ID_HELPER> -const ID_HELPER* -ScintGeoModelAthenaComps<ID_HELPER>::getIdHelper() const -{ - return m_idHelper; -} - diff --git a/Scintillator/ScintDetDescr/ScintGeoModel/src/components/ScintGeoModel_entries.cxx b/Scintillator/ScintDetDescr/ScintGeoModel/src/components/ScintGeoModel_entries.cxx deleted file mode 100644 index 50292b02389bf1af778b255db7200f7d6adafef3..0000000000000000000000000000000000000000 --- a/Scintillator/ScintDetDescr/ScintGeoModel/src/components/ScintGeoModel_entries.cxx +++ /dev/null @@ -1,3 +0,0 @@ -#include "ScintGeoModel/VetoDetectorTool.h" - -DECLARE_COMPONENT( VetoDetectorTool ) \ No newline at end of file diff --git a/Scintillator/ScintDetDescr/ScintGeoModelUtils/CMakeLists.txt b/Scintillator/ScintDetDescr/ScintGeoModelUtils/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..44c51708b1ae93e25dfe9f1c6e3f412163c438f1 --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintGeoModelUtils/CMakeLists.txt @@ -0,0 +1,35 @@ +################################################################################ +# Package: ScintGeoModelUtils +################################################################################ + +# Declare the package name: +atlas_subdir( ScintGeoModelUtils ) + +# Declare the package's dependencies: +atlas_depends_on_subdirs( PUBLIC + Control/AthenaKernel + Database/RDBAccessSvc + GaudiKernel + PRIVATE + Control/StoreGate + DetectorDescription/GeoModel/GeoModelInterfaces + DetectorDescription/GeoModel/GeoModelUtilities + DetectorDescription/GeoModel/GeoModelFaserUtilities + DetectorDescription/GeoPrimitives + DetectorDescription/GeometryDBSvc ) + +# External dependencies: +find_package( Boost COMPONENTS filesystem thread system ) +find_package( CLHEP ) +find_package( CORAL COMPONENTS CoralBase CoralKernel RelationalAccess ) +find_package( GeoModel ) + +# Component(s) in the package: +atlas_add_library( ScintGeoModelUtils + src/*.cxx + PUBLIC_HEADERS ScintGeoModelUtils + INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${CORAL_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} + DEFINITIONS ${CLHEP_DEFINITIONS} + LINK_LIBRARIES ${Boost_LIBRARIES} ${CORAL_LIBRARIES} ${CLHEP_LIBRARIES} ${GEOMODEL_LIBRARIES} AthenaKernel GaudiKernel StoreGateLib SGtests + PRIVATE_LINK_LIBRARIES GeoModelUtilities GeoModelFaserUtilities ) + diff --git a/Scintillator/ScintDetDescr/ScintGeoModelUtils/ScintGeoModelUtils/ScintDDAthenaComps.h b/Scintillator/ScintDetDescr/ScintGeoModelUtils/ScintGeoModelUtils/ScintDDAthenaComps.h new file mode 100644 index 0000000000000000000000000000000000000000..ab6f67bc4ae1b9113154fce54bbbdc4b3d730535 --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintGeoModelUtils/ScintGeoModelUtils/ScintDDAthenaComps.h @@ -0,0 +1,76 @@ +/* + Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ScintGeoModelUtils_ScintDDAthenaComps_H +#define ScintGeoModelUtils_ScintDDAthenaComps_H + +// Message Stream Member +#include "AthenaKernel/MsgStreamMember.h" +class StoreGateSvc; +class IGeoDbTagSvc; +class IRDBAccessSvc; +class IGeometryDBSvc; + +#include <string> +namespace ScintDD { + +/// Class to hold various Athena components. +class AthenaComps { + +public: + + AthenaComps(const std::string & msgStreamName); + + //Declaring the Message method for further use + MsgStream& msg (MSG::Level lvl) const { return m_msg << lvl; } + + //Declaring the Method providing Verbosity Level + bool msgLvl (MSG::Level lvl) const { return m_msg.get().level() <= lvl; } + + void setDetStore(StoreGateSvc *); + void setGeoDbTagSvc(IGeoDbTagSvc *); + void setRDBAccessSvc(IRDBAccessSvc *); + void setGeometryDBSvc(IGeometryDBSvc *); + + StoreGateSvc * detStore() const; + IGeoDbTagSvc * geoDbTagSvc() const; + IRDBAccessSvc * rdbAccessSvc() const; + IGeometryDBSvc * geomDB() const; + +private: + //Declaring private message stream member. + mutable Athena::MsgStreamMember m_msg; + + StoreGateSvc * m_detStore; + IGeoDbTagSvc * m_geoDbTagSvc; + IRDBAccessSvc * m_rdbAccessSvc; + IGeometryDBSvc * m_geometryDBSvc; + +}; + +inline StoreGateSvc * AthenaComps::detStore() const +{ + return m_detStore; +} + +inline IGeoDbTagSvc * AthenaComps::geoDbTagSvc() const +{ + return m_geoDbTagSvc; +} + +inline IRDBAccessSvc * AthenaComps::rdbAccessSvc() const +{ + return m_rdbAccessSvc; +} + +inline IGeometryDBSvc * AthenaComps::geomDB() const +{ + return m_geometryDBSvc; +} + +} // endnamespace + +#endif // ScintGeoModelUtils_ScintDDAthenaComps_H + + diff --git a/Scintillator/ScintDetDescr/ScintGeoModelUtils/src/ScintDDAthenaComps.cxx b/Scintillator/ScintDetDescr/ScintGeoModelUtils/src/ScintDDAthenaComps.cxx new file mode 100644 index 0000000000000000000000000000000000000000..5cfe8264309bb6bdf2058ee490769de0c8afedc4 --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintGeoModelUtils/src/ScintDDAthenaComps.cxx @@ -0,0 +1,35 @@ +/* + Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration + */ + +#include "ScintGeoModelUtils/ScintDDAthenaComps.h" + +namespace ScintDD { + AthenaComps::AthenaComps(const std::string& msgStreamName) + : m_msg(msgStreamName), + m_detStore(0), + m_geoDbTagSvc(0), + m_rdbAccessSvc(0), + m_geometryDBSvc(0) + {} + + void + AthenaComps::setDetStore(StoreGateSvc* detStore) { + m_detStore = detStore; + } + + void + AthenaComps::setGeoDbTagSvc(IGeoDbTagSvc* geoDbTagSvc) { + m_geoDbTagSvc = geoDbTagSvc; + } + + void + AthenaComps::setRDBAccessSvc(IRDBAccessSvc* rdbAccessSvc) { + m_rdbAccessSvc = rdbAccessSvc; + } + + void + AthenaComps::setGeometryDBSvc(IGeometryDBSvc* geometryDBSvc) { + m_geometryDBSvc = geometryDBSvc; + } +} diff --git a/Scintillator/ScintDetDescr/ScintIdDictFiles/data/IdDictScintillator.xml b/Scintillator/ScintDetDescr/ScintIdDictFiles/data/IdDictScintillator.xml index d7cabdf6fce023b657c51b5aadcdf35f902843b7..fbec1a8aa8e7fec1c1e5e20244125c1ad1dcf922 100644 --- a/Scintillator/ScintDetDescr/ScintIdDictFiles/data/IdDictScintillator.xml +++ b/Scintillator/ScintDetDescr/ScintIdDictFiles/data/IdDictScintillator.xml @@ -9,13 +9,13 @@ <region> <range field="part" value="Veto" /> <range field="station" minvalue="0" maxvalue="1" /> - <range field="plate" value="0" /> - <range field="pmt" value="0" /> + <range field="plate" minvalue="0" maxvalue="0" /> + <range field="pmt" minvalue="0" maxvalue="0" /> </region> <region> <range field="part" value="Trigger"/> - <range field="station" value="0" /> + <range field="station" minvalue="0" maxvalue="0" /> <range field="plate" minvalue="0" maxvalue="1" /> <range field="pmt" minvalue="0" maxvalue="1" /> </region> @@ -23,7 +23,7 @@ <region> <range field="part" value="Preshower" /> <range field="station" minvalue="0" maxvalue="1" /> - <range field="plate" value="0" /> - <range field="pmt" value="0" /> + <range field="plate" minvalue="0" maxvalue="0" /> + <range field="pmt" minvalue="0" maxvalue="0" /> </region> </IdDictionary> \ No newline at end of file diff --git a/Scintillator/ScintDetDescr/ScintIdentifier/CMakeLists.txt b/Scintillator/ScintDetDescr/ScintIdentifier/CMakeLists.txt index ae742293cc0fe6b2f47105e9aca6158b7c0084bc..660ea8422bc728b3b0bb12c687f6291a4516b1e5 100644 --- a/Scintillator/ScintDetDescr/ScintIdentifier/CMakeLists.txt +++ b/Scintillator/ScintDetDescr/ScintIdentifier/CMakeLists.txt @@ -19,21 +19,21 @@ atlas_depends_on_subdirs( PUBLIC find_package( ROOT COMPONENTS Core Tree MathCore Hist RIO pthread ) # Component(s) in the package: -#atlas_add_library( ScintIdentifier -# src/VetoID.cxx +atlas_add_library( ScintIdentifier + src/VetoID.cxx # src/TriggerID.cxx # src/PreshowerID.cxx # src/ScintillatorID.cxx -# PUBLIC_HEADERS ScintIdentifier -# PRIVATE_INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} -# LINK_LIBRARIES AthenaKernel FaserDetDescr IdDict Identifier -# PRIVATE_LINK_LIBRARIES ${ROOT_LIBRARIES} IdDictParser GaudiKernel ) + PUBLIC_HEADERS ScintIdentifier + PRIVATE_INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} + LINK_LIBRARIES AthenaKernel FaserDetDescr IdDict Identifier + PRIVATE_LINK_LIBRARIES ${ROOT_LIBRARIES} IdDictParser GaudiKernel ) -#atlas_add_dictionary( ScintIdentifierDict -# ScintIdentifier/ScintIdentifierDict.h -# ScintIdentifier/selection.xml -# INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} -# LINK_LIBRARIES ${ROOT_LIBRARIES} FaserDetDescr IdDict Identifier IdDictParser GaudiKernel ScintIdentifier ) +atlas_add_dictionary( ScintIdentifierDict + ScintIdentifier/ScintIdentifierDict.h + ScintIdentifier/selection.xml + INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} + LINK_LIBRARIES ${ROOT_LIBRARIES} FaserDetDescr IdDict Identifier IdDictParser GaudiKernel ScintIdentifier ) #atlas_add_executable( test_indet_id # test/test_indet_id.cxx diff --git a/Scintillator/ScintDetDescr/ScintIdentifier/ScintIdentifier/VetoID.h b/Scintillator/ScintDetDescr/ScintIdentifier/ScintIdentifier/VetoID.h new file mode 100644 index 0000000000000000000000000000000000000000..5a3801689840a9ca3d005d7e9d09d13053c8f8e0 --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintIdentifier/ScintIdentifier/VetoID.h @@ -0,0 +1,528 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef SCINTIDENTIFIER_VETOID_H +#define SCINTIDENTIFIER_VETOID_H +/** + * @file VetoID.h + * + * @brief This is an Identifier helper class for the Veto + * subdetector. This class is a factory for creating compact + * Identifier objects and IdentifierHash or hash ids. And it also + * allows decoding of these ids. + * + */ + +//<<<<<< INCLUDES >>>>>> + +#include "FaserDetDescr/FaserDetectorID.h" +#include "Identifier/Identifier.h" +#include "Identifier/IdentifierHash.h" +#include "Identifier/Range.h" +#include "Identifier/IdHelper.h" +#include "IdDict/IdDictFieldImplementation.h" +#include "AthenaKernel/CLASS_DEF.h" + +#include <string> +#include <assert.h> +#include <algorithm> + +//<<<<<< PUBLIC DEFINES >>>>>> +//<<<<<< PUBLIC CONSTANTS >>>>>> +//<<<<<< PUBLIC TYPES >>>>>> + +class IdDictDictionary; + +//<<<<<< PUBLIC VARIABLES >>>>>> +//<<<<<< PUBLIC FUNCTIONS >>>>>> +//<<<<<< CLASS DECLARATIONS >>>>>> + +/** + ** @class VetoID + ** + ** @brief This is an Identifier helper class for the Veto + ** subdetector. This class is a factory for creating compact + ** Identifier objects and IdentifierHash or hash ids. And it also + ** allows decoding of these ids. + ** + ** Definition and the range of values for the levels of the + ** identifier are: + ** + ** @verbatim + ** element range meaning + ** ------- ----- ------- + ** + ** station 0 to 1 longitudinal location + ** plate 0 single plate per station + ** pmt 0 single pmt per plate + ** + ** @endverbatim + ** + */ +class VetoID : public FaserDetectorID +{ +public: + + /// @name public typedefs + //@{ + typedef Identifier::size_type size_type; + typedef std::vector<Identifier>::const_iterator const_id_iterator; + typedef MultiRange::const_identifier_factory const_expanded_id_iterator; + //@} + + /// @name strutors + //@{ + VetoID(void); + virtual ~VetoID(void) = default; + //@} + + /// @name Creators for plate ids and pmt ids + //@{ + /// For a single station + Identifier station_id ( int station ) const; + Identifier station_id ( int station, + bool checks) const; + + /// For a station from a plate id + Identifier station_id ( const Identifier& plate_id ) const; + + /// For a single plate + Identifier plate_id ( int station, + int plate ) const; + Identifier plate_id ( int station, + int plate, + bool checks) const; + + /// For a single plate from a pmt id + Identifier plate_id ( const Identifier& pmt_id ) const; + + /// From hash - optimized + Identifier plate_id ( IdentifierHash plate_hash ) const; + + /// For an individual pmt + Identifier pmt_id ( int station, + int plate, + int pmt ) const; + + Identifier pmt_id ( int station, + int plate, + int pmt, + bool check ) const; + + Identifier pmt_id ( const Identifier& plate_id, + int pmt ) const; + + //@} + + + /// @name Hash table maximum sizes + //@{ + size_type plate_hash_max (void) const; + size_type pmt_hash_max (void) const; + //@} + + /// @name Access to all ids + //@{ + /// Iterators over full set of ids. Plate iterator is sorted + const_id_iterator plate_begin (void) const; + const_id_iterator plate_end (void) const; + /// For pmt ids, only expanded id iterators are available. Use + /// following "pmt_id" method to obtain a compact identifier + const_expanded_id_iterator pmt_begin (void) const; + const_expanded_id_iterator pmt_end (void) const; + //@} + + + /// @name Optimized accessors - ASSUMES id IS a sct id, i.e. NOT pixel or other + //@{ + /// wafer hash from id - optimized + IdentifierHash plate_hash (Identifier plate_id) const; + + /// Values of different levels (failure returns 0) + int station (const Identifier& id) const; + int plate (const Identifier& id) const; + int pmt (const Identifier& id) const; + + /// Max/Min values for each field (-999 == failure) + int station_max (const Identifier& id) const; + int plate_max (const Identifier& id) const; + int pmt_max (const Identifier& id) const; + //@} + + /// @name module eta/phi navigation + //@{ + // /// Previous wafer hash in phi (return == 0 for neighbor found) + // int get_prev_in_phi (const IdentifierHash& id, IdentifierHash& prev) const; + // /// Next wafer hash in phi (return == 0 for neighbor found) + // int get_next_in_phi (const IdentifierHash& id, IdentifierHash& next) const; + // /// Previous wafer hash in eta (return == 0 for neighbor found) + // int get_prev_in_eta (const IdentifierHash& id, IdentifierHash& prev) const; + // /// Next wafer hash in eta (return == 0 for neighbor found) + // int get_next_in_eta (const IdentifierHash& id, IdentifierHash& next) const; + // /// Wafer hash on other side + // int get_other_side (const IdentifierHash& id, IdentifierHash& other) const; + + // // To check for when phi wrap around may be needed, use + // bool is_phi_module_max(const Identifier& id) const; + // /// For the barrel + // bool is_eta_module_min(const Identifier& id) const; + // /// For the barrel + // bool is_eta_module_max(const Identifier& id) const; + //@} + + /// @name contexts to distinguish plate id from pixel id + //@{ + IdContext plate_context (void) const; + IdContext pmt_context (void) const; + //@} + + /// @name methods from abstract interface - slower than opt version + //@{ + /// Create compact id from hash id (return == 0 for OK) + virtual int get_id (const IdentifierHash& hash_id, + Identifier& id, + const IdContext* context = 0) const; + + /// Create hash id from compact id (return == 0 for OK) + virtual int get_hash (const Identifier& id, + IdentifierHash& hash_id, + const IdContext* context = 0) const; + //@} + + /// Return the lowest bit position used in the channel id + int base_bit (void) const; + + /// Calculate a channel offset between the two identifiers. + Identifier::diff_type calc_offset(const Identifier& base, + const Identifier& target) const; + + /// Create an identifier with a given base and channel offset + Identifier pmt_id_offset(const Identifier& base, + Identifier::diff_type offset) const; + + /// @name interaction with id dictionary + //@{ + /// Create strip Identifier from expanded id, which is returned by the + /// id_iterators + Identifier pmt_id (const ExpandedIdentifier& pmt_id) const; + + /// Create expanded id from compact id (return == 0 for OK) + void get_expanded_id (const Identifier& id, + ExpandedIdentifier& exp_id, + const IdContext* context = 0) const; + + /// Initialization from the identifier dictionary + virtual int initialize_from_dictionary(const IdDictMgr& dict_mgr); + + /// Tests of packing + void test_plate_packing (void) const; + //@} + +private: + + enum {NOT_VALID_HASH = 64000}; + + typedef std::vector<Identifier> id_vec; + typedef id_vec::const_iterator id_vec_it; + typedef std::vector<unsigned short> hash_vec; + typedef hash_vec::const_iterator hash_vec_it; + + void plate_id_checks ( int station, + int plate ) const; + + void pmt_id_checks ( int station, + int plate, + int pmt ) const; + + + int initLevelsFromDict(void); + + int init_hashes(void); + + int init_neighbors(void); + + // Temporary method for adapting an identifier for the MultiRange + // check - MR is missing the InnerDetector level + // Identifier idForCheck (const Identifier& id) const; + + size_type m_veto_region_index; + size_type m_SCINT_INDEX; + size_type m_VETO_INDEX; + size_type m_STATION_INDEX; + size_type m_PLATE_INDEX; + size_type m_PMT_INDEX; + + const IdDictDictionary* m_dict; + MultiRange m_full_plate_range; + MultiRange m_full_pmt_range; + size_type m_plate_hash_max; + size_type m_pmt_hash_max; + // Range::field m_barrel_field; + id_vec m_plate_vec; + // hash_vec m_prev_phi_wafer_vec; + // hash_vec m_next_phi_wafer_vec; + // hash_vec m_prev_eta_wafer_vec; + // hash_vec m_next_eta_wafer_vec; + // bool m_hasRows ; + + IdDictFieldImplementation m_scint_impl ; + IdDictFieldImplementation m_veto_impl ; + IdDictFieldImplementation m_station_impl ; + IdDictFieldImplementation m_plate_impl ; + IdDictFieldImplementation m_pmt_impl ; +}; + + +//<<<<<< INLINE PUBLIC FUNCTIONS >>>>>> + +///////////////////////////////////////////////////////////////////////////// +//<<<<<< INLINE MEMBER FUNCTIONS >>>>>> +///////////////////////////////////////////////////////////////////////////// + +//using the macros below we can assign an identifier (and a version) +//This is required and checked at compile time when you try to record/retrieve +CLASS_DEF(VetoID, 131395045, 1) + +//---------------------------------------------------------------------------- +inline Identifier +VetoID::station_id ( int station, + bool checks) const +{ + + // Build identifier + Identifier result((Identifier::value_type)0); + + // Pack fields independently + m_scint_impl.pack (scint_field_value(), result); + m_veto_impl.pack (veto_field_value(), result); + m_station_impl.pack (station, result); + // Do checks + if(checks) + { + plate_id_checks ( station, 0 ); + } + + return result; +} + +inline Identifier +VetoID::station_id ( int station ) const +{ + return station_id (station, do_checks()); +} + +//---------------------------------------------------------------------------- +inline Identifier +VetoID::station_id ( const Identifier& plate_id ) const +{ + Identifier result(plate_id); + // Reset the plate and pmt fields + m_plate_impl.reset(result); + m_pmt_impl.reset(result); + return (result); +} + +//---------------------------------------------------------------------------- +inline Identifier +VetoID::plate_id ( int station, + int plate, + bool checks) const +{ + // Build identifier + Identifier result((Identifier::value_type)0); + + // Pack fields independently + m_scint_impl.pack (scint_field_value(), result); + m_veto_impl.pack (veto_field_value(), result); + m_station_impl.pack (station, result); + m_plate_impl.pack (plate, result); + + // Do checks + if(checks) + { + plate_id_checks ( station, plate ); + } + return result; +} + +inline Identifier +VetoID::plate_id ( int station, + int plate ) const +{ + return plate_id (station, plate, do_checks()); +} + +//---------------------------------------------------------------------------- +inline Identifier +VetoID::plate_id ( const Identifier& pmt_id ) const +{ + Identifier result(pmt_id); + // reset the pmt field + m_pmt_impl.reset(result); + return (result); +} + +//---------------------------------------------------------------------------- +inline Identifier VetoID::plate_id ( IdentifierHash plate_hash ) const +{ + return (m_plate_vec[plate_hash]); +} + +//---------------------------------------------------------------------------- +inline IdentifierHash VetoID::plate_hash (Identifier plate_id) const +{ + id_vec_it it = std::lower_bound(m_plate_vec.begin(), + m_plate_vec.end(), + plate_id); + // Require that plate_id matches the one in vector + if (it != m_plate_vec.end() && plate_id == (*it)) { + return (it - m_plate_vec.begin()); + } + IdentifierHash result; + return (result); // return hash in invalid state +} + +//---------------------------------------------------------------------------- +inline Identifier +VetoID::pmt_id ( int station, + int plate, + int pmt, + bool checks) const +{ + // Build identifier + Identifier result((Identifier::value_type)0); + + // Pack fields independently + m_scint_impl.pack (scint_field_value(), result); + m_veto_impl.pack (veto_field_value(), result); + m_station_impl.pack (station, result); + m_plate_impl.pack (plate, result); + m_pmt_impl.pack (pmt, result); + + // Do checks + if(checks) { + pmt_id_checks ( station, plate, pmt ); + } + return result; +} + +inline Identifier +VetoID::pmt_id ( int station, + int plate, + int pmt ) const +{ + return pmt_id (station, plate, pmt, do_checks()); +} + +//---------------------------------------------------------------------------- +inline Identifier +VetoID::pmt_id (const ExpandedIdentifier& id) const +{ + // Build identifier + Identifier result((Identifier::value_type)0); + + // Pack fields independently + m_scint_impl.pack (scint_field_value(), result); + m_veto_impl.pack (veto_field_value(), result); + m_station_impl.pack (id[m_STATION_INDEX], result); + m_plate_impl.pack (id[m_PLATE_INDEX], result); + m_pmt_impl.pack (id[m_PMT_INDEX], result); + + // Do checks + if(m_do_checks) + { + pmt_id_checks ( id[m_STATION_INDEX], + id[m_PLATE_INDEX], + id[m_PMT_INDEX]); + } + return result; +} + +//---------------------------------------------------------------------------- +inline Identifier +VetoID::pmt_id ( const Identifier& plate_id, int pmt ) const +{ + // Build identifier + Identifier result(plate_id); + + // Reset strip and then add in value + m_pmt_impl.reset (result); + m_pmt_impl.pack (pmt, result); + + if(m_do_checks) + { + pmt_id_checks ( station(result), + plate(result), + pmt ); + } + return result; +} + +//---------------------------------------------------------------------------- +inline Identifier::diff_type +VetoID::calc_offset(const Identifier& base, const Identifier& target) const +{ + Identifier::diff_type tval = static_cast<Identifier::diff_type>(target.get_compact() >> base_bit()); + Identifier::diff_type bval = static_cast<Identifier::diff_type>(base.get_compact() >> base_bit()); + return (tval - bval); +} + +//---------------------------------------------------------------------------- +inline Identifier +VetoID::pmt_id_offset(const Identifier& base, + Identifier::diff_type offset) const +{ + Identifier::value_type bval = base.get_compact() >> base_bit(); + return Identifier((bval + offset) << base_bit()); +} + +//---------------------------------------------------------------------------- +inline int +VetoID::base_bit ( void ) const +{ + int base = static_cast<int>(m_pmt_impl.shift()); // lowest field base + return (base > 32) ? 32 : base; + // max base is 32 so we can still read old strip id's and differences + // from non-SLHC releases. +} + +//---------------------------------------------------------------------------- +inline IdContext +VetoID::plate_context (void) const +{ + ExpandedIdentifier id; + return (IdContext(id, 0, m_PLATE_INDEX)); +} + +//---------------------------------------------------------------------------- +inline IdContext +VetoID::pmt_context (void) const +{ + ExpandedIdentifier id; + return (IdContext(id, 0, m_PMT_INDEX)); +} + +//---------------------------------------------------------------------------- +inline int +VetoID::station (const Identifier& id) const +{ + return (m_station_impl.unpack(id)); +} + +//---------------------------------------------------------------------------- +inline int +VetoID::plate (const Identifier& id) const +{ + return (m_plate_impl.unpack(id)); +} + +//---------------------------------------------------------------------------- +inline int +VetoID::pmt (const Identifier& id) const +{ + return (m_pmt_impl.unpack(id)); +} + + +#endif // SCINTIDENTIFIER_VETOID_H diff --git a/Scintillator/ScintDetDescr/ScintIdentifier/src/VetoID.cxx b/Scintillator/ScintDetDescr/ScintIdentifier/src/VetoID.cxx new file mode 100644 index 0000000000000000000000000000000000000000..589c032d415689f952b361430da8cf63251d570c --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintIdentifier/src/VetoID.cxx @@ -0,0 +1,889 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + +/*************************************************************************** + Scintillator identifier package + ------------------------------------------- +***************************************************************************/ + +//<<<<<< INCLUDES >>>>>> +#include "GaudiKernel/MsgStream.h" + +#include "ScintIdentifier/VetoID.h" +#include "Identifier/IdentifierHash.h" +#include "IdDict/IdDictDefs.h" +#include <set> +#include <algorithm> +#include <iostream> + +//<<<<<< PRIVATE DEFINES >>>>>> +//<<<<<< PRIVATE CONSTANTS >>>>>> +//<<<<<< PRIVATE TYPES >>>>>> +//<<<<<< PRIVATE VARIABLE DEFINITIONS >>>>>> +//<<<<<< PUBLIC VARIABLE DEFINITIONS >>>>>> +//<<<<<< CLASS STRUCTURE INITIALIZATION >>>>>> +//<<<<<< PRIVATE FUNCTION DEFINITIONS >>>>>> +//<<<<<< PUBLIC FUNCTION DEFINITIONS >>>>>> +//<<<<<< MEMBER FUNCTION DEFINITIONS >>>>>> + + +///////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////// + + +VetoID::VetoID(void) + : + m_veto_region_index(0), + m_SCINT_INDEX(0), + m_VETO_INDEX(1), + m_STATION_INDEX(2), + m_PLATE_INDEX(3), + m_PMT_INDEX(4), + m_dict(0), + m_plate_hash_max(0), + m_pmt_hash_max(0) +{ +} + +void +VetoID::plate_id_checks ( int station, + int plate ) const +{ + + // Check that id is within allowed range + + // Fill expanded id + ExpandedIdentifier id; + id << scint_field_value() << veto_field_value() + << station << plate; + + if (!m_full_plate_range.match(id)) { // module range check is sufficient + MsgStream log(m_msgSvc, "VetoID"); + log << MSG::ERROR << " VetoID::plate_id result is NOT ok. ID, range " + << (std::string)id << " " << (std::string)m_full_plate_range << endmsg; + } +} + +void +VetoID::pmt_id_checks ( int station, + int plate, + int pmt) const +{ + + // Check that id is within allowed range + + // Fill expanded id + ExpandedIdentifier id; + id << scint_field_value() << veto_field_value() + << station << plate << pmt; + + if (!m_full_pmt_range.match(id)) { + MsgStream log(m_msgSvc, "VetoID"); + log << MSG::ERROR << " VetoID::pmt_id result is NOT ok. ID, range " + << (std::string)id << " " << (std::string)m_full_pmt_range << std::endl; + } +} + +int +VetoID::station_max(const Identifier& id) const +{ + // get max from dictionary + ExpandedIdentifier expId; + IdContext plate_context1 = plate_context(); + get_expanded_id(id, expId, &plate_context1); + for (unsigned int i = 0; i < m_full_plate_range.size(); ++i) { + const Range& range = m_full_plate_range[i]; + if (range.match(expId)) { + const Range::field& station_field = range[m_STATION_INDEX]; + if (station_field.has_maximum()) { + return (station_field.get_maximum()); + } + } + } + return (-999); // default +} + +int +VetoID::pmt_max (const Identifier& id) const +{ + ExpandedIdentifier expId; + IdContext station_context(expId, 0, m_STATION_INDEX); + get_expanded_id(id, expId, &station_context); + int result = -999; + for (unsigned int i = 0; i < m_full_pmt_range.size(); ++i) { + const Range& range = m_full_pmt_range[i]; + if (range.match(expId)) { + const Range::field& pmt_field = range[m_PMT_INDEX]; + if (pmt_field.has_maximum()) { + int pmt = pmt_field.get_maximum(); + if (result < pmt) result = pmt; + } + } + } + return (result); +} + +int +VetoID::plate_max(const Identifier& id) const +{ + // get max from dictionary + ExpandedIdentifier expId; + IdContext plate_context1 = plate_context(); + get_expanded_id(id, expId, &plate_context1); + for (unsigned int i = 0; i < m_full_plate_range.size(); ++i) { + const Range& range = m_full_plate_range[i]; + if (range.match(expId)) { + const Range::field& plate_field = range[m_PLATE_INDEX]; + if (plate_field.has_maximum()) { + return (plate_field.get_maximum()); + } + } + } + return -1; +} + +int +VetoID::initialize_from_dictionary(const IdDictMgr& dict_mgr) +{ + MsgStream log(m_msgSvc, "VetoID"); + log << MSG::INFO << "Initialize from dictionary" << endmsg; + + // Check whether this helper should be reinitialized + if (!reinitialize(dict_mgr)) { + log << MSG::INFO << "Request to reinitialize not satisfied - tags have not changed" << endmsg; + return (0); + } + else { + if (m_msgSvc) { + log << MSG::DEBUG << "(Re)initialize" << endmsg; + } + else { + std::cout << " DEBUG (Re)initialize" << std::endl; + } + } + + // init base object + if(FaserDetectorID::initialize_from_dictionary(dict_mgr)) return (1); + + // Register version of InnerDetector dictionary + if (register_dict_tag(dict_mgr, "Scintillator")) return(1); + + m_dict = dict_mgr.find_dictionary ("Scintillator"); + if(!m_dict) { + log << MSG::ERROR << " VetoID::initialize_from_dict - cannot access Scintillator dictionary " << endmsg; + return 1; + } + + // Initialize the field indices + if(initLevelsFromDict()) return (1); + + // + // Build multirange for the valid set of identifiers + // + + + // Find value for the field Scintillator + const IdDictDictionary* faserDict = dict_mgr.find_dictionary ("FASER"); + int scintField = -1; + if (faserDict->get_label_value("subdet", "Scintillator", scintField)) { + log << MSG::ERROR << "Could not get value for label 'Scintillator' of field 'subdet' in dictionary " + << faserDict->m_name + << endmsg; + return (1); + } + + // Find value for the field Veto + int vetoField = -1; + if (m_dict->get_label_value("part", "Veto", vetoField)) { + log << MSG::ERROR << "Could not get value for label 'Veto' of field 'part' in dictionary " + << m_dict->m_name + << endmsg; + return (1); + } + if (m_msgSvc) { + log << MSG::DEBUG << " VetoID::initialize_from_dict " + << "Found field values: Veto " + << vetoField + << std::endl; + } + else { + std::cout << " DEBUG VetoID::initialize_from_dict " + << "Found field values: Veto " + << vetoField + << std::endl; + } + + // Set up id for region and range prefix + ExpandedIdentifier region_id; + region_id.add(scintField); + region_id.add(vetoField); + Range prefix; + m_full_plate_range = m_dict->build_multirange(region_id, prefix, "plate"); + m_full_pmt_range = m_dict->build_multirange(region_id, prefix); + + // Setup the hash tables + if(init_hashes()) return (1); + + // Setup hash tables for finding neighbors + if(init_neighbors()) return (1); + + if (m_msgSvc) { + log << MSG::INFO << " VetoID::initialize_from_dict " << endmsg; + log << MSG::DEBUG + << "Plate range -> " << (std::string)m_full_plate_range + << endmsg; + log << MSG::DEBUG + << "Pmt range -> " << (std::string)m_full_pmt_range + << endmsg; + } + else { + std::cout << " INFO VetoID::initialize_from_dict " << std::endl; + std::cout << " DEBUG Plate range -> " << (std::string)m_full_plate_range + << std::endl; + std::cout << " DEBUG Pmt range -> " << (std::string)m_full_pmt_range + << std::endl; + } + + return 0; +} + +int +VetoID::init_hashes(void) +{ + + // + // create a vector(s) to retrieve the hashes for compact ids. For + // the moment, we implement a hash for plates but NOT for pmts + // + MsgStream log(m_msgSvc, "VetoID"); + // plate hash + m_plate_hash_max = m_full_plate_range.cardinality(); + m_plate_vec.resize(m_plate_hash_max); + unsigned int nids = 0; + std::set<Identifier> ids; + for (unsigned int i = 0; i < m_full_plate_range.size(); ++i) { + const Range& range = m_full_plate_range[i]; + Range::const_identifier_factory first = range.factory_begin(); + Range::const_identifier_factory last = range.factory_end(); + for (; first != last; ++first) { + const ExpandedIdentifier& exp_id = (*first); + Identifier id = plate_id(exp_id[m_STATION_INDEX], + exp_id[m_PLATE_INDEX]); + if(!(ids.insert(id)).second) { + log << MSG::ERROR << " VetoID::init_hashes " + << " Error: duplicated id for plate id. nid " << nids + << " compact id " << id.getString() + << " id " << (std::string)exp_id << endmsg; + return (1); + } + nids++; + } + } + if(ids.size() != m_plate_hash_max) { + log << MSG::ERROR << " VetoID::init_hashes " + << " Error: set size NOT EQUAL to hash max. size " << ids.size() + << " hash max " << m_plate_hash_max + << endmsg; + return (1); + } + + nids = 0; + std::set<Identifier>::const_iterator first = ids.begin(); + std::set<Identifier>::const_iterator last = ids.end(); + for (; first != last && nids < m_plate_vec.size(); ++first) { + m_plate_vec[nids] = (*first); + nids++; + } + + // pmt hash - we do not keep a vec for the pmts + m_pmt_hash_max = m_full_pmt_range.cardinality(); + + return (0); +} + +// int +// VetoID::get_prev_in_phi(const IdentifierHash& id, IdentifierHash& prev) const +// { +// unsigned short index = id; +// if (index < m_prev_phi_wafer_vec.size()) { +// if (m_prev_phi_wafer_vec[index] == NOT_VALID_HASH) return (1); +// prev = m_prev_phi_wafer_vec[index]; +// return (0); +// } +// return (1); +// } + +// int +// VetoID::get_next_in_phi(const IdentifierHash& id, IdentifierHash& next) const +// { +// unsigned short index = id; +// if (index < m_next_phi_wafer_vec.size()) { +// if (m_next_phi_wafer_vec[index] == NOT_VALID_HASH) return (1); +// next = m_next_phi_wafer_vec[index]; +// return (0); +// } +// return (1); +// } + +// int +// VetoID::get_prev_in_eta(const IdentifierHash& id, IdentifierHash& prev) const +// { +// unsigned short index = id; +// if (index < m_prev_eta_wafer_vec.size()) { +// if (m_prev_eta_wafer_vec[index] == NOT_VALID_HASH) return (1); +// prev = m_prev_eta_wafer_vec[index]; +// return (0); +// } +// return (1); +// } + +// int +// VetoID::get_next_in_eta(const IdentifierHash& id, IdentifierHash& next) const +// { +// unsigned short index = id; +// if (index < m_next_eta_wafer_vec.size()) { +// if (m_next_eta_wafer_vec[index] == NOT_VALID_HASH) return (1); +// next = m_next_eta_wafer_vec[index]; +// return (0); +// } +// return (1); +// } + +// int +// VetoID::get_other_side (const IdentifierHash& hashId, IdentifierHash& other) const +// { +// if (m_dict) { +// // get max from dictionary +// Identifier id; +// IdContext wafer_context1 = wafer_context(); +// if(!get_id(hashId, id, &wafer_context1)) { +// other = side(id) ? hashId - 1 : hashId + 1; +// return (0); +// } +// } +// return (1); +// } + +int +VetoID::init_neighbors(void) +{ + // + // create a vector(s) to retrieve the hashes for compact ids for + // wafer neighbors. + // + + MsgStream log(m_msgSvc, "VetoID"); + if (m_msgSvc) { + log << MSG::DEBUG << "VetoID::init_neighbors not yet implemented" << endmsg; + } + else { + std::cout << " DEBUG VetoID::init_neighbors not yet implemented" << std::endl; + } + + + // m_prev_phi_wafer_vec.resize(m_wafer_hash_max, NOT_VALID_HASH); + // m_next_phi_wafer_vec.resize(m_wafer_hash_max, NOT_VALID_HASH); + // m_prev_eta_wafer_vec.resize(m_wafer_hash_max, NOT_VALID_HASH); + // m_next_eta_wafer_vec.resize(m_wafer_hash_max, NOT_VALID_HASH); + + // for (unsigned int i = 0; i < m_full_wafer_range.size(); ++i) { + // const Range& range = m_full_wafer_range[i]; + // const Range::field& phi_field = range[m_PHI_MODULE_INDEX]; + // const Range::field& eta_field = range[m_ETA_MODULE_INDEX]; + // Range::const_identifier_factory first = range.factory_begin(); + // Range::const_identifier_factory last = range.factory_end(); + // for (; first != last; ++first) { + // const ExpandedIdentifier& exp_id = (*first); + // ExpandedIdentifier::element_type previous_phi; + // ExpandedIdentifier::element_type next_phi; + // ExpandedIdentifier::element_type previous_eta; + // ExpandedIdentifier::element_type next_eta; + // bool pphi = phi_field.get_previous(exp_id[m_PHI_MODULE_INDEX], previous_phi); + // bool nphi = phi_field.get_next (exp_id[m_PHI_MODULE_INDEX], next_phi); + // bool peta = eta_field.get_previous(exp_id[m_ETA_MODULE_INDEX], previous_eta); + // bool neta = eta_field.get_next (exp_id[m_ETA_MODULE_INDEX], next_eta); + + // IdContext wcontext = wafer_context(); + + // // First get primary hash id + // IdentifierHash hash_id; + // Identifier id = wafer_id(exp_id[m_BARREL_EC_INDEX], + // exp_id[m_LAYER_DISK_INDEX], + // exp_id[m_PHI_MODULE_INDEX], + // exp_id[m_ETA_MODULE_INDEX], + // exp_id[m_SIDE_INDEX]); + // if (get_hash(id, hash_id, &wcontext)) { + // log << MSG::ERROR << " VetoID::init_neighbors - unable to get hash, exp/compact " + // << show_to_string(id, &wcontext) + // << " " << (std::string)m_full_wafer_range << endmsg; + // return (1); + // } + + // // index for the subsequent arrays + // unsigned short index = hash_id; + // assert (hash_id < m_prev_phi_wafer_vec.size()); + // assert (hash_id < m_next_phi_wafer_vec.size()); + // assert (hash_id < m_prev_eta_wafer_vec.size()); + // assert (hash_id < m_next_eta_wafer_vec.size()); + + // if (pphi) { + // // Get previous phi hash id + // ExpandedIdentifier expId = exp_id; + // expId[m_PHI_MODULE_INDEX] = previous_phi; + // Identifier id = wafer_id(expId[m_BARREL_EC_INDEX], + // expId[m_LAYER_DISK_INDEX], + // expId[m_PHI_MODULE_INDEX], + // expId[m_ETA_MODULE_INDEX], + // expId[m_SIDE_INDEX]); + // if (get_hash(id, hash_id, &wcontext)) { + // log << MSG::ERROR << " VetoID::init_neighbors - unable to get previous phi hash, exp/compact " << id.getString() << " " + // << endmsg; + // return (1); + // } + // m_prev_phi_wafer_vec[index] = hash_id; + // } + + // if (nphi) { + // // Get next phi hash id + // ExpandedIdentifier expId = exp_id; + // expId[m_PHI_MODULE_INDEX] = next_phi; + // Identifier id = wafer_id(expId[m_BARREL_EC_INDEX], + // expId[m_LAYER_DISK_INDEX], + // expId[m_PHI_MODULE_INDEX], + // expId[m_ETA_MODULE_INDEX], + // expId[m_SIDE_INDEX]); + // if (get_hash(id, hash_id, &wcontext)) { + // log << MSG::ERROR << " VetoID::init_neighbors - unable to get next phi hash, exp/compact " << id.getString() << + // " " << MSG::hex << id.getString() << MSG::dec << endmsg; + // return (1); + // } + // m_next_phi_wafer_vec[index] = hash_id; + // } + + // if (peta) { + // // Get previous eta hash id + // ExpandedIdentifier expId = exp_id; + // expId[m_ETA_MODULE_INDEX] = previous_eta; + // Identifier id = wafer_id(expId[m_BARREL_EC_INDEX], + // expId[m_LAYER_DISK_INDEX], + // expId[m_PHI_MODULE_INDEX], + // expId[m_ETA_MODULE_INDEX], + // expId[m_SIDE_INDEX]); + // if (get_hash(id, hash_id, &wcontext)) { + // log << MSG::ERROR << " VetoID::init_neighbors - unable to get previous eta hash, exp/compact " << id.getString() + // << " " << std::endl; + // return (1); + // } + // m_prev_eta_wafer_vec[index] = hash_id; + // } + + // if (neta) { + // // Get next eta hash id + // ExpandedIdentifier expId = exp_id; + // expId[m_ETA_MODULE_INDEX] = next_eta; + // Identifier id = wafer_id(expId[m_BARREL_EC_INDEX], + // expId[m_LAYER_DISK_INDEX], + // expId[m_PHI_MODULE_INDEX], + // expId[m_ETA_MODULE_INDEX], + // expId[m_SIDE_INDEX]); + // if (get_hash(id, hash_id, &wcontext)) { + // log << MSG::ERROR << " VetoID::init_neighbors - unable to get next eta hash, exp/compact " << id.getString() + // << " " << endmsg; + // return (1); + // } + // m_next_eta_wafer_vec[index] = hash_id; + // } + + +// std::cout << " VetoID::init_neighbors " +// << " phi, previous, next " << id[m_PHI_MODULE_INDEX] +// << " " << pphi +// << " " << previous_phi +// << " " << nphi +// << " " << next_phi +// << " eta, previous, next " << id[m_ETA_MODULE_INDEX] +// << " " << peta +// << " " << previous_eta +// << " " << neta +// << " " << next_eta +// << " id " << (std::string)(*first) +// << std::endl; + // } + // } + return (0); +} + + + +int +VetoID::initLevelsFromDict() +{ + + + MsgStream log(m_msgSvc, "VetoID"); + if(!m_dict) { + log << MSG::ERROR << " VetoID::initLevelsFromDict - dictionary NOT initialized " << endmsg; + return (1); + } + + // Find out which identifier field corresponds to each level. Use + // names to find each field/leve. + + m_SCINT_INDEX = 999; + m_VETO_INDEX = 999; + m_STATION_INDEX = 999; + m_PLATE_INDEX = 999; + m_PMT_INDEX = 999; + + // Save index to a Veto region for unpacking + ExpandedIdentifier id; + id << scint_field_value() << veto_field_value(); + if (m_dict->find_region(id, m_veto_region_index)) { + log << MSG::ERROR << "VetoID::initLevelsFromDict - unable to find veto region index: id, reg " + << (std::string)id << " " << m_veto_region_index + << endmsg; + return (1); + } + + // Find a Veto region + IdDictField* field = m_dict->find_field("subdet"); + if (field) { + m_SCINT_INDEX = field->m_index; + } + else { + log << MSG::ERROR << "VetoID::initLevelsFromDict - unable to find 'subdet' field " << endmsg; + return (1); + } + field = m_dict->find_field("part"); + if (field) { + m_VETO_INDEX = field->m_index; + } + else { + log << MSG::ERROR << "VetoID::initLevelsFromDict - unable to find 'part' field " << endmsg; + return (1); + } + field = m_dict->find_field("station"); + if (field) { + m_STATION_INDEX = field->m_index; + } + else { + log << MSG::ERROR << "VetoID::initLevelsFromDict - unable to find 'station' field " << endmsg; + return (1); + } + field = m_dict->find_field("plate"); + if (field) { + m_PLATE_INDEX = field->m_index; + } + else { + log << MSG::ERROR<< "VetoID::initLevelsFromDict - unable to find 'plate' field " << endmsg; + return (1); + } + field = m_dict->find_field("pmt"); + if (field) { + m_PMT_INDEX = field->m_index; + } + else { + log << MSG::ERROR << "VetoID::initLevelsFromDict - unable to find 'pmt' field " << endmsg; + return (1); + } + + // Set the field implementations + + const IdDictRegion& region = *m_dict->m_regions[m_veto_region_index]; + + m_scint_impl = region.m_implementation[m_SCINT_INDEX]; + m_veto_impl = region.m_implementation[m_VETO_INDEX]; + m_station_impl = region.m_implementation[m_STATION_INDEX]; + m_plate_impl = region.m_implementation[m_PLATE_INDEX]; + m_pmt_impl = region.m_implementation[m_PMT_INDEX]; + + if (m_msgSvc) { + log << MSG::DEBUG << "decode index and bit fields for each level: " << endmsg; + log << MSG::DEBUG << "scint " << m_scint_impl.show_to_string() << endmsg; + log << MSG::DEBUG << "veto " << m_veto_impl.show_to_string() << endmsg; + log << MSG::DEBUG << "station " << m_station_impl.show_to_string() << endmsg; + log << MSG::DEBUG << "plate " << m_plate_impl.show_to_string() << endmsg; + log << MSG::DEBUG << "pmt " << m_pmt_impl.show_to_string() << endmsg; + } + else { + std::cout << " DEBUG decode index and bit fields for each level: " << std::endl; + std::cout << " DEBUG scint " << m_scint_impl.show_to_string() << std::endl; + std::cout << " DEBUG veto " << m_veto_impl.show_to_string() << std::endl; + std::cout << " DEBUG station " << m_station_impl.show_to_string() << std::endl; + std::cout << " DEBUG plate " << m_plate_impl.show_to_string() << std::endl; + std::cout << " DEBUG pmt " << m_pmt_impl.show_to_string() << std::endl; + } + +// std::cout << "VetoID::initLevelsFromDict - found levels " << std::endl; +// std::cout << "subdet " << m_INDET_INDEX << std::endl; +// std::cout << "part " << m_SCT_INDEX << std::endl; +// std::cout << "barrel_endcap " << m_BARREL_EC_INDEX << std::endl; +// std::cout << "layer or disk " << m_LAYER_DISK_INDEX << std::endl; +// std::cout << "phi_module " << m_PHI_MODULE_INDEX << std::endl; +// std::cout << "eta_module " << m_ETA_MODULE_INDEX << std::endl; +// std::cout << "side " << m_SIDE_INDEX << std::endl; +// std::cout << "strip " << m_STRIP_INDEX << std::endl; + + std::cout << "scint " << m_scint_impl.decode_index() << " " + << (std::string)m_scint_impl.ored_field() << " " + << std::hex << m_scint_impl.mask() << " " + << m_scint_impl.zeroing_mask() << " " + << std::dec << m_scint_impl.shift() << " " + << m_scint_impl.bits() << " " + << m_scint_impl.bits_offset() + << std::endl; + std::cout << "veto" << m_veto_impl.decode_index() << " " + << (std::string)m_veto_impl.ored_field() << " " + << std::hex << m_veto_impl.mask() << " " + << m_veto_impl.zeroing_mask() << " " + << std::dec << m_veto_impl.shift() << " " + << m_veto_impl.bits() << " " + << m_veto_impl.bits_offset() + << std::endl; + std::cout << "station"<< m_station_impl.decode_index() << " " + << (std::string)m_station_impl.ored_field() << " " + << std::hex << m_station_impl.mask() << " " + << m_station_impl.zeroing_mask() << " " + << std::dec << m_station_impl.shift() << " " + << m_station_impl.bits() << " " + << m_station_impl.bits_offset() + << std::endl; + std::cout << "plate" << m_plate_impl.decode_index() << " " + << (std::string)m_plate_impl.ored_field() << " " + << std::hex << m_plate_impl.mask() << " " + << m_plate_impl.zeroing_mask() << " " + << std::dec << m_plate_impl.shift() << " " + << m_plate_impl.bits() << " " + << m_plate_impl.bits_offset() + << std::endl; + std::cout << "pmt" << m_pmt_impl.decode_index() << " " + << (std::string)m_pmt_impl.ored_field() << " " + << std::hex << m_pmt_impl.mask() << " " + << m_pmt_impl.zeroing_mask() << " " + << std::dec << m_pmt_impl.shift() << " " + << m_pmt_impl.bits() << " " + << m_pmt_impl.bits_offset() + << std::endl; + + return (0); +} + +VetoID::size_type +VetoID::plate_hash_max (void) const +{ + return m_plate_hash_max; +} + +VetoID::size_type +VetoID::pmt_hash_max (void) const +{ + return m_pmt_hash_max; +} + +VetoID::const_id_iterator VetoID::plate_begin (void) const +{ + return (m_plate_vec.begin()); +} + +VetoID::const_id_iterator VetoID::plate_end (void) const +{ + return (m_plate_vec.end()); +} + +VetoID::const_expanded_id_iterator VetoID::pmt_begin (void) const +{ + return (m_full_pmt_range.factory_begin()); +} + +VetoID::const_expanded_id_iterator VetoID::pmt_end (void) const +{ + return (m_full_pmt_range.factory_end()); +} + +// From hash get Identifier +int +VetoID::get_id (const IdentifierHash& hash_id, + Identifier& id, + const IdContext* context) const +{ + + int result = 1; + id.clear(); + + size_t begin = (context) ? context->begin_index(): 0; + // cannot get hash if end is 0: + size_t end = (context) ? context->end_index() : 0; + if (0 == begin) { + // No hashes yet for ids with prefixes + if (m_PLATE_INDEX == end) { + if (hash_id < (unsigned int)(m_plate_vec.end() - m_plate_vec.begin())) { + id = m_plate_vec[hash_id]; + result = 0; + } + } + else if (m_PMT_INDEX == end) { + // Do not know how to calculate strip id from hash yet!! + std::cout << "Do not know how to calculate pmt id from hash yet!!" << std::endl; + } + } + return (result); +} + +void +VetoID::get_expanded_id (const Identifier& id, + ExpandedIdentifier& exp_id, + const IdContext* context) const +{ + exp_id.clear(); + exp_id << scint_field_value() + << veto_field_value() + << station(id) + << plate(id); + if(!context || context->end_index() == m_PMT_INDEX) + { + exp_id << pmt(id); + } +} + +int +VetoID::get_hash (const Identifier& id, + IdentifierHash& hash_id, + const IdContext* context) const +{ + + // Get the hash code from either a vec (for plate) or calculate + // it (pmts). For the former, we convert to compact and call + // get_hash again. For the latter, we calculate the hash from the + // Identifier. + + int result = 1; + hash_id = 0; + size_t begin = (context) ? context->begin_index(): 0; + size_t end = (context) ? context->end_index() : 0; + if (0 == begin) { + // No hashes yet for ids with prefixes + if (m_PLATE_INDEX == end) { + hash_id = plate_hash(id); + if (hash_id.is_valid()) result = 0; + } + else if (context && context->end_index() == m_PMT_INDEX) { + // Must calculate for strip hash + ExpandedIdentifier new_id; + get_expanded_id(id, new_id); + hash_id = m_full_pmt_range.cardinalityUpTo(new_id); + result = 0; + } + } + return (result); +} + + +void +VetoID::test_plate_packing (void) const +{ + MsgStream log(m_msgSvc, "VetoID"); + + if (m_dict) { + + int nids = 0; + int nerr = 0; + IdContext context = plate_context(); + const_id_iterator first = m_plate_vec.begin(); + const_id_iterator last = m_plate_vec.end(); + for (; first != last; ++first, ++nids) { + Identifier id = (*first); + ExpandedIdentifier exp_id; + get_expanded_id(id, exp_id, &context); + Identifier new_id = plate_id(exp_id[m_STATION_INDEX], + exp_id[m_PLATE_INDEX]); + if (id != new_id) { + log << MSG::ERROR << "VetoID::test_plate_packing: new and old compacts not equal. New/old/expanded ids " + << MSG::hex << show_to_string(id) << " " << show_to_string(new_id) << " " << MSG::dec + << (std::string)exp_id << endmsg; + nerr++; + continue; + } + // check station id + if (!exp_id[m_PLATE_INDEX]) { + + Identifier new_id1 = station_id(exp_id[m_STATION_INDEX]); + if (id != new_id1) { + log << MSG::ERROR << "VetoID::test_plate_packing: new and old station ids not equal. New/old/expanded ids " + << MSG::hex << show_to_string(id) << " " << show_to_string(new_id1) << " " << MSG::dec + << (std::string)exp_id << endmsg; + nerr++; + continue; + } + } + } + + if (m_msgSvc) { + log << MSG::DEBUG << "VetoID::test_plate_packing: tested plate and station ids. nids, errors " + << nids << " " << nerr << endmsg; + } + else { + std::cout << " DEBUG VetoID::test_plate_packing: tested plate and station ids. nids, errors " + << nids << " " << nerr << std::endl; + } + + nids = 0; + context = pmt_context(); + const_expanded_id_iterator first_veto = pmt_begin(); + const_expanded_id_iterator last_veto = pmt_end(); + for (; first_veto != last_veto; ++first_veto, ++nids) { + if (nids%10000 != 1) continue; + const ExpandedIdentifier& exp_id = *first_veto; + ExpandedIdentifier new_exp_id; + + Identifier id = plate_id(exp_id[m_STATION_INDEX], + exp_id[m_PLATE_INDEX]); + get_expanded_id(id, new_exp_id, &context); + if (exp_id[0] != new_exp_id[0] || + exp_id[1] != new_exp_id[1] || + exp_id[2] != new_exp_id[2] || + exp_id[3] != new_exp_id[3] || + exp_id[4] != new_exp_id[4]) { + log << MSG::ERROR << "VetoID::test_plate_packing: new and old ids not equal. New/old/compact ids " + << (std::string)new_exp_id << " " << (std::string)exp_id + << " " << show_to_string(id) << endmsg; + continue; + } + + Identifier pmtid ; + Identifier pmtid1 ; + pmtid = pmt_id ( + exp_id[m_STATION_INDEX], + exp_id[m_PLATE_INDEX], + exp_id[m_PMT_INDEX]); + + pmtid1 = pmt_id ( + station(pmtid), + plate(pmtid), + pmt(pmtid)); + + if (pmtid != pmtid1) { + log << MSG::ERROR << "VetoID::test_plate_packing: new and old pixel ids not equal. New/old ids " + << " " << show_to_string(pmtid1) << " " + << show_to_string(pmtid) << endmsg; + } + } + + if (m_msgSvc) { + log << MSG::DEBUG << "VetoID::test_plate_packing: Successful tested " + << nids << " ids. " + << endmsg; + } + else { + std::cout << " DEBUG VetoID::test_plate_packing: Successful tested " + << nids << " ids. " + << std::endl; + } + } + else { + log << MSG::ERROR << "VetoID::test_plate_packing: Unable to test plate packing - no dictionary has been defined. " + << endmsg; + } +} + diff --git a/Scintillator/ScintDetDescr/ScintReadoutGeometry/CMakeLists.txt b/Scintillator/ScintDetDescr/ScintReadoutGeometry/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..364640487da099ceebadc7c95487e7ce1258c767 --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintReadoutGeometry/CMakeLists.txt @@ -0,0 +1,43 @@ +################################################################################ +# Package: ScintReadoutGeometry +################################################################################ + +# Declare the package name: +atlas_subdir( ScintReadoutGeometry ) + +# Declare the package's dependencies: +atlas_depends_on_subdirs( PUBLIC + Control/AthenaBaseComps + Control/AthenaKernel + Control/CxxUtils + Control/StoreGate + DetectorDescription/FaserDetDescr + DetectorDescription/GeoModel/GeoModelFaserUtilities + DetectorDescription/GeoModel/GeoModelUtilities + DetectorDescription/GeoPrimitives + DetectorDescription/Identifier + GaudiKernel +# InnerDetector/InDetConditions/InDetCondTools + Scintillator/ScintDetDescr/ScintIdentifier + Tracking/TrkDetDescr/TrkDetElementBase + Tracking/TrkDetDescr/TrkSurfaces + Tracking/TrkEvent/TrkEventPrimitives + DetectorDescription/DetDescrCond/DetDescrConditions + PRIVATE + Database/AthenaPOOL/AthenaPoolUtilities + DetectorDescription/IdDictDetDescr ) + +# External dependencies: +find_package( CLHEP ) +find_package( Eigen ) +find_package( GeoModel ) + +# Component(s) in the package: +atlas_add_library( ScintReadoutGeometry + src/*.cxx + PUBLIC_HEADERS ScintReadoutGeometry + INCLUDE_DIRS ${CLHEP_INCLUDE_DIRS} ${EIGEN_INCLUDE_DIRS} + DEFINITIONS ${CLHEP_DEFINITIONS} + LINK_LIBRARIES ${CLHEP_LIBRARIES} ${EIGEN_LIBRARIES} ${GEOMODEL_LIBRARIES} AthenaKernel CxxUtils FaserDetDescr GeoModelFaserUtilities GeoModelUtilities GeoPrimitives Identifier GaudiKernel ScintIdentifier TrkDetElementBase TrkSurfaces TrkEventPrimitives StoreGateLib SGtests AthenaBaseComps DetDescrConditions + PRIVATE_LINK_LIBRARIES AthenaPoolUtilities IdDictDetDescr ) + diff --git a/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ExtendedAlignableTransform.h b/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ExtendedAlignableTransform.h new file mode 100644 index 0000000000000000000000000000000000000000..74076d8236cb2ac4b9b2b69133f5ac5ed2439eaf --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ExtendedAlignableTransform.h @@ -0,0 +1,57 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/////////////////////////////////////////////////////////////////// +// ExtendedAlignableTransform.h +/////////////////////////////////////////////////////////////////// +// (c) ATLAS Detector software +/////////////////////////////////////////////////////////////////// + +#ifndef SCINTREADOUTGEOMETRY_EXTENDEDALIGNABLETRANSFORM_H +#define SCINTREADOUTGEOMETRY_EXTENDEDALIGNABLETRANSFORM_H + +#include "GeoPrimitives/GeoPrimitives.h" +#include "GeoModelKernel/GeoAlignableTransform.h" +#include "GeoModelKernel/GeoVFullPhysVol.h" + +namespace ScintDD { + + /** @class ExtendedAlignableTransform + + Class to hold alignable transform plus a pointer to the child volume and + optionally a frame volume. + + @author: Grant Gorfine + - modified & maintained: Nick Styles & Andreas Salzburger + */ + + class ExtendedAlignableTransform + { + + public: + + ExtendedAlignableTransform(GeoAlignableTransform * alignableTransform, + const GeoVFullPhysVol * child, + const GeoVFullPhysVol * frame = 0) + : m_alignableTransform(alignableTransform), + m_child(child), + m_frame(frame) + {}; + + GeoAlignableTransform * alignableTransform() {return m_alignableTransform;} + const GeoVFullPhysVol * child() {return m_child;} + const GeoVFullPhysVol * frame() {return m_frame;} + + private: + + GeoAlignableTransform * m_alignableTransform; + const GeoVFullPhysVol * m_child; + const GeoVFullPhysVol * m_frame; + + }; + + +} // end namespace + +#endif // SCINTINDETREADOUTGEOMETRY_EXTENDEDALIGNABLETRANSFORM_H diff --git a/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintCommonItems.h b/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintCommonItems.h new file mode 100644 index 0000000000000000000000000000000000000000..9bdee5c23a88fdc9646c5fd219e186c172c26ea9 --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintCommonItems.h @@ -0,0 +1,92 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + +/////////////////////////////////////////////////////////////////// +// ScintCommonItems.h +/////////////////////////////////////////////////////////////////// +// (c) ATLAS Detector software +/////////////////////////////////////////////////////////////////// + +#ifndef SCINTREADOUTGEOMETRY_SCINTCOMMONITEMS_H +#define SCINTREADOUTGEOMETRY_SCINTCOMMONITEMS_H + +class FaserDetectorID; + +// Message Stream Member +#include "AthenaKernel/MsgStreamMember.h" +#include "CxxUtils/checker_macros.h" +// #include "InDetCondTools/ISiLorentzAngleTool.h" +#include "GeoPrimitives/GeoPrimitives.h" +#include "GeoModelKernel/RCBase.h" + + +#include "GaudiKernel/ServiceHandle.h" +#include "CLHEP/Geometry/Transform3D.h" + +#include <mutex> + +// mutable Athena::MsgStreamMember issues warnings. +ATLAS_NO_CHECK_FILE_THREAD_SAFETY; + +namespace ScintDD { + + /** @class ScintCommonItems + + Helper class to concentrate common items, such as the pointer to the IdHelper, + + To be used for Veto, Trigger and Preshower. + + @author: Grant Gorfine + mondified & maintained: Nick Styles, Andreas Salzburger + modified: Dave Casper + */ + + class ScintCommonItems: public RCBase + { + + public: + + ScintCommonItems(const FaserDetectorID* const idHelper); + + const FaserDetectorID* getIdHelper() const; + // const HepGeom::Transform3D & solenoidFrame() const; + // void setSolenoidFrame(const HepGeom::Transform3D & transform) const; + + //Declaring the Message method for further use + MsgStream& msg (MSG::Level lvl) const { return m_msg.get() << lvl; } + + //Declaring the Method providing Verbosity Level + bool msgLvl (MSG::Level lvl) const { return m_msg.get().level() <= lvl; } + + private: + + //Declaring private message stream member. + mutable Athena::MsgStreamMember m_msg; + + const FaserDetectorID* m_idHelper; + // mutable HepGeom::Transform3D m_solenoidFrame ATLAS_THREAD_SAFE; // Guarded by m_mutex + + mutable std::mutex m_mutex; + }; + + + inline const FaserDetectorID* ScintCommonItems::getIdHelper() const + { + return m_idHelper; + } + + + // inline const HepGeom::Transform3D & SiCommonItems::solenoidFrame() const + // { + // std::lock_guard<std::mutex> lock{m_mutex}; + // return m_solenoidFrame; + // // This reference might be changed by setSolenoidFrame. + // // However, it occurrs very rarely. + // } + + + +} // End namespace ScintDD + +#endif // SCINTREADOUTGEOMETRY_SCINTCOMMONITEMSS_H diff --git a/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintDD_Defs.h b/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintDD_Defs.h new file mode 100644 index 0000000000000000000000000000000000000000..d3b9db38016587cf56065d9caeaccdbcc76df584 --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintDD_Defs.h @@ -0,0 +1,22 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/////////////////////////////////////////////////////////////////// +// ScintDD_Defs.h +/////////////////////////////////////////////////////////////////// +// (c) ATLAS Detector software +/////////////////////////////////////////////////////////////////// + +#ifndef SCINTREADOUTGEOMETRY_SCINTDD_Defs_H +#define SCINTREADOUTGEOMETRY_SCINTDD_Defs_H + + +namespace ScintDD { + enum FrameType {local, global, other}; +// enum CarrierType {holes, electrons}; + // new enumerator to select given align-folder structure + enum AlignFolderType {none = -1, static_run1 = 0, timedependent_run2 = 1}; +} + +#endif // SCINTREADOUTGEOMETRY_SCINTDD_DEFS_H diff --git a/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintDetectorDesign.h b/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintDetectorDesign.h new file mode 100644 index 0000000000000000000000000000000000000000..b5ab7ac1b6997205c198ace3c1256ecaa927b6fa --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintDetectorDesign.h @@ -0,0 +1,203 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/////////////////////////////////////////////////////////////////// +// ScintDetectorDesign.h +/////////////////////////////////////////////////////////////////// +// (c) ATLAS Detector software +/////////////////////////////////////////////////////////////////// + +#ifndef SCINTREADOUTGEOMETRY_SCINTDETECTORDESIGN_H +#define SCINTREADOUTGEOMETRY_SCINTDETECTORDESIGN_H + +// Input/output classes +// #include "InDetReadoutGeometry/SiDiodesParameters.h" +#include "ScintReadoutGeometry/ScintDD_Defs.h" +#include "CLHEP/Geometry/Point3D.h" +#include "CLHEP/Geometry/Vector3D.h" +#include "FaserDetDescr/FaserDetectorID.h" +#include "GeoPrimitives/GeoPrimitives.h" +#include "GeoModelKernel/RCBase.h" +#include "ScintDD_Defs.h" + +#include <list> +#include <vector> + + +class Identifier; + +namespace Trk { +class SurfaceBounds; +class RectangleBounds; +} + +namespace ScintDD { +// class SiReadoutCellId; +// class SiCellId; +// class SiDiode; +// class SiReadoutCell; +class ScintLocalPosition; +class ScintIntersect; + +enum DetectorShape { + Box=0, Trapezoid, Annulus, Other +}; + +/** @class ScintDetectorDesign + + Base class for the detector design classes for Veto, Trigger and Preshower. + These hold the local description of the detector elements which are + shared by a number of detector elements. + + @author A. Calvet, Grant Gorfine + */ + +class ScintDetectorDesign: public RCBase { +public: + enum Axis { + xAxis=0, yAxis, zAxis + }; + + enum Edge { + negative = -1, both, positive + }; + /////////////////////////////////////////////////////////////////// + // Public methods: + /////////////////////////////////////////////////////////////////// +public: + /** Constructor + */ + + ScintDetectorDesign( const double thickness, + const double width, + const double length, + const int cells, + const ScintDetectorDesign::Edge readoutSide); + + + ScintDetectorDesign( const double thickness, + const double width, + const double length, + const int cells, + const ScintDetectorDesign::Edge readoutSide, + const ScintDetectorDesign::Axis photonDirection, + const ScintDetectorDesign::Axis thicknessDirection); + + /** Destructor: */ + virtual ~ScintDetectorDesign(); + + /////////////////////////////////////////////////////////////////// + // Const methods: + /////////////////////////////////////////////////////////////////// + + /** Test if point is in the active part of the detector with specified tolerances */ + ScintIntersect inDetector(const ScintLocalPosition &localPosition, double xTol, + double yTol) const; + + /** which axis in hit frame is the photon flight direction */ + /** phi corresponds to "width" */ + ScintDetectorDesign::Axis phiAxis() const; + + /** which axis in hit frame is transverse to photon flight direction */ + /** eta corresponds to "length" */ + ScintDetectorDesign::Axis etaAxis() const; + + /** which axis in hit frame is thickness direction */ + ScintDetectorDesign::Axis depthAxis() const; + + /** ReadoutSide. */ + ScintDetectorDesign::Edge readoutSide() const; + + /////////////////////////////////////////////////////////////////// + // Pure virtual methods: + /////////////////////////////////////////////////////////////////// + + /** Returns distance to nearest detector active edge + +ve = inside + -ve = outside */ + virtual void distanceToDetectorEdge(const ScintLocalPosition &localPosition, + double &xDist, double &yDist) const = 0; + + /** Method to calculate length of a module */ + virtual double length() const; + + /** Method to calculate average width of a module */ + virtual double width() const; + + /** Method which returns thickness of the silicon wafer */ + double thickness() const; + + /** Number of PMTs */ + int cells() const; + + // /** Shape of element */ + virtual DetectorShape shape() const; + + /** Element boundary */ + virtual const Trk::SurfaceBounds &bounds() const; + + /////////////////////////////////////////////////////////////////// + // Private methods: + /////////////////////////////////////////////////////////////////// +private: + ScintDetectorDesign(); + + /////////////////////////////////////////////////////////////////// + // Private data: + /////////////////////////////////////////////////////////////////// +private: + double m_thickness; // !< thickness of plate + double m_width; // !< dimension in "phi" direction (photon flight) + double m_length; // !< dimnesion in "eta" direction + int m_cells; // !< number of pmts + + ScintDetectorDesign::Axis m_phiAxis; // which axis in hit frame corresponds to photon flight direction? + ScintDetectorDesign::Axis m_etaAxis; // which axis in hit frame is normal to photon flight direction? + ScintDetectorDesign::Axis m_depthAxis; // which axis in hit frame is depth? + ScintDetectorDesign::Edge m_readoutSide; + + const Trk::RectangleBounds* m_bounds; + + // Disallow Copy and assignment; + ScintDetectorDesign(const ScintDetectorDesign &design); + ScintDetectorDesign &operator = (const ScintDetectorDesign &design); +}; + +/////////////////////////////////////////////////////////////////// +// Inline methods: +/////////////////////////////////////////////////////////////////// +inline double ScintDetectorDesign::thickness() const { + return m_thickness; +} + +inline double ScintDetectorDesign::width() const { + return m_width; +} + +inline double ScintDetectorDesign::length() const { + return m_length; +} + +inline int ScintDetectorDesign::cells() const { + return m_cells; +} + +inline ScintDetectorDesign::Axis ScintDetectorDesign::phiAxis() const { + return m_phiAxis; +} + +inline ScintDetectorDesign::Axis ScintDetectorDesign::etaAxis() const { + return m_etaAxis; +} + +inline ScintDetectorDesign::Axis ScintDetectorDesign::depthAxis() const { + return m_depthAxis; +} + +inline ScintDetectorDesign::Edge ScintDetectorDesign::readoutSide() const { + return m_readoutSide; +} + +} // namespace ScintDD +#endif // SCINTREADOUTGEOMETRY_SCINTDETECTORDESIGN_H diff --git a/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintDetectorElement.h b/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintDetectorElement.h new file mode 100644 index 0000000000000000000000000000000000000000..8a1868a9999e36cae87cb16178614ee5480997ef --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintDetectorElement.h @@ -0,0 +1,663 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + +/** + * @file ScintDetectorElement.h +**/ + +#ifndef SCINTREADOUTGEOMETRY_SCINTDETECTORELEMENT_H +#define SCINTREADOUTGEOMETRY_SCINTDETECTORELEMENT_H + +// Base class. +#include "TrkDetElementBase/TrkDetElementBase.h" + +// Data member classes +#include "CxxUtils/CachedUniquePtr.h" +#include "Identifier/Identifier.h" +#include "Identifier/IdentifierHash.h" +#include "ScintReadoutGeometry/ScintDetectorDesign.h" +#include "ScintReadoutGeometry/ScintLocalPosition.h" +#include "TrkEventPrimitives/ParamDefs.h" +#include "ScintReadoutGeometry/ScintIntersect.h" +#include "ScintReadoutGeometry/ScintCommonItems.h" +#include "ScintReadoutGeometry/ScintDD_Defs.h" +#include "GeoPrimitives/CLHEPtoEigenConverter.h" +#include "GeoPrimitives/GeoPrimitives.h" +#include "GeoModelKernel/GeoDefinitions.h" + +#include "CLHEP/Geometry/Point3D.h" + +#include <atomic> +#include <mutex> + +class FaserDetectorID; +class GeoVFullPhysVol; +class GeoAlignmentStore; + +namespace Trk{ + class Surface; + class SurfaceBounds; +} + +namespace ScintDD { + + /** + + @class ScintDetectorElement + + Class to hold geometrical description of a scintillator detector element. + A detector element is a single scintillator plate. + + @par Coordinate Frames. + + The following coordinate frames are used in these elements. + + - Global frame:\n + Currently global frame in G4/GeoModel. Probably eventually + will be global frame most suitable for reconstruction + (eg solenoid axis). + + - Local hit frame:\n + Local frame for hits. It is the same as local frame in G4 and GeoModel. + I also refer to this as the local simulation frame. + By convention elements are orientated such that: + - hitDepth = local x + - hitPhi = local y + - hitEta = local z + . + Directions of these correspond to the physical wafer. Consequently hitDepth and hitPhi axes go in + different directions depending on the orientation of the module. + The readout side is determined from design()->readoutSide(). + + - Local reconstruction frame:\n + - distPhi = local x + - distEta = local y + - distDepth = local z + . + The directions of the axes are defined as + - distPhi in direction of increasing phi + - distEta in direction of increasing z in barrel and increasing r in endcap. + - distDepth (normal) choosen to give right-handed coordinate. + => away from intersection point for barrel, decreasing z for endcap + + @par Overview of Methods + + Methods are grouped into the the following categories + + - Identification + - Navigation + - Transformation/Orientation + - Module Frame + - Element Extent + - Design methods + - Intersection Tests + - Lorentz Correction + - Readout cell id + - Miscellaneous + - Cache handling. + + + @author Grant Gorfine + - modified & maintained: Nick Styles, Andreas Salzburger + - modified Nigel Hessey: get directions from the design instead of hard-wiring them + - modified for Faser: Dave Casper + + */ + + class ScintDetectorElement : public Trk::TrkDetElementBase { + + /////////////////////////////////////////////////////////////////// + // Public methods: + /////////////////////////////////////////////////////////////////// + public: + + + /// Constructor: + ScintDetectorElement(const Identifier &id, + const ScintDetectorDesign *design, + const GeoVFullPhysVol *geophysvol, + const ScintCommonItems * commonItems, + const GeoAlignmentStore* geoAlignStore=nullptr); + + /// Destructor: + virtual ~ScintDetectorElement(); + + + /////////////////////////////////////////////////////////////////// + // + /// @name Identification + /// Methods to identify the element and identifier manipulation. + // + /////////////////////////////////////////////////////////////////// + + //@{ + + /// identifier of this detector element: + Identifier identify() const; + + /// identifier hash + IdentifierHash identifyHash() const; + + /// Returns the id helper + const FaserDetectorID* getIdHelper() const; + + bool isVeto() const; + bool isTrigger() const; + bool isPreshower() const; + + // Identifier <-> pmt + + /// Identifier from pmt + Identifier identifierFromCellId(const int& cellId) const; + + /// pmt from Identifier + int cellIdFromIdentifier(const Identifier & identifier) const; + + //@} + + + /////////////////////////////////////////////////////////////////// + // + /// @name Navigation + /// Methods to access neighbours. + // + /////////////////////////////////////////////////////////////////// + + //@{ + //@} + + /////////////////////////////////////////////////////////////////// + // + /// @name Transformation/Orientation + // + /////////////////////////////////////////////////////////////////// + + //@{ + // Position + /// Local (simulation/hit frame) to global transform + virtual const GeoTrf::Transform3D & transformHit() const; + /// Local (reconstruction frame) to global transform + const Amg::Transform3D & transform() const; + /// Default Local (reconstruction frame) to global transform + /// ie with no misalignment. + const HepGeom::Transform3D defTransformCLHEP() const; + const Amg::Transform3D defTransform() const; + /// Center in global coordinates + const Amg::Vector3D & center() const; + + const HepGeom::Transform3D & transformCLHEP() const; + + /// Simulation/Hit local frame to reconstruction local frame. 2D. + // TODO: Will change order of parameters at some point. + Amg::Vector2D hitLocalToLocal(double xEta, double xPhi) const; + /// Same as previuos method but 3D. + HepGeom::Point3D<double> hitLocalToLocal3D(const HepGeom::Point3D<double> & hitPosition) const; + + /// Transform to go from local reconstruction frame to local hit frame. + const HepGeom::Transform3D recoToHitTransform() const; + + /// Directions of hit depth,phi,eta axes relative to reconstruction local position + /// axes (LocalPosition). Returns +/-1. + double hitDepthDirection() const; + /// See previous method. + double hitPhiDirection() const; + /// See previous method. + double hitEtaDirection() const; + + // To determine if readout direction between online and offline needs swapping, see methods + // swapPhiReadoutDirection() and swapEtaReadoutDirection() below in "Readout Cell id" section + + // Orientation. + // Directions. + // phiAxis - in same direction as increasing phi and identifier phi_index/strip. + // NB. This requires some flipping of axes with repsect to the hits. + // etaAxis - in direction of increasing z in the barrel and increasing r in the endcap. + // normal - choosen to give right-handed coordinate frame (x=normal,y=phiAxis,z=etaAxis) + // NB. This requires some flipping of axes with repsect to the hits. + + /// Get reconstruction local x axes in global frame. + const Amg::Vector3D & phiAxis() const; + const HepGeom::Vector3D<double> & phiAxisCLHEP() const; + /// Get reconstruction local y axes in global frame. + const Amg::Vector3D & etaAxis() const; + const HepGeom::Vector3D<double> & etaAxisCLHEP() const; + /// Get reconstruction local normal axes in global frame. Choosen to give right-handed coordinate frame. + const Amg::Vector3D & normal() const; + + /// transform a hit local position into a global position: + HepGeom::Point3D<double> globalPositionHit(const HepGeom::Point3D<double> &simulationLocalPos) const; + Amg::Vector3D globalPositionHit(const Amg::Vector3D &simulationLocalPos) const; + + /// transform a reconstruction local position into a global position: + HepGeom::Point3D<double> globalPosition(const HepGeom::Point3D<double> &localPos) const; + Amg::Vector3D globalPosition(const Amg::Vector3D &localPos) const; + + /// as in previous method but for 2D local position + HepGeom::Point3D<double> globalPositionCLHEP(const Amg::Vector2D &localPos) const; + + Amg::Vector3D globalPosition(const Amg::Vector2D &localPos) const; + + /// transform a global position into a 2D local position (reconstruction frame) + Amg::Vector2D localPosition(const HepGeom::Point3D<double> & globalPosition) const; + + Amg::Vector2D localPosition(const Amg::Vector3D& globalPosition) const; + + /// Element Surface + virtual Trk::Surface & surface(); + virtual const Trk::Surface & surface() const; + + //@} + + /** Returns the full list of surfaces associated to this detector element */ + virtual const std::vector<const Trk::Surface*>& surfaces() const; + + /** + + @name Plate Frame + Methods to help work with the module frame. + This is mainly of of use in the SCT where the module frame can + in general be different from the element frame. It is actully + defined as the frame of one of the sides (currently the axial + side), but using these methods one does not need to make any + assumptions about what the actual frame is. In the following + methods the local element frame is the local reconstruction + frame of this element. + */ + + //@{ + + /// Plate to global frame transform. + /// Includes misalignment. + //const HepGeom::Transform3D & moduleTransform() const; + const Amg::Transform3D & plateTransform() const; + + /// Default plate to global frame transform, ie with no misalignment. + Amg::Transform3D defPlateTransform() const; + + /// Take a transform of the local element frame and return its equivalent in the module frame. + //HepGeom::Transform3D localToModuleFrame(const HepGeom::Transform3D & localTransform) const; + Amg::Transform3D localToModuleFrame(const Amg::Transform3D & localTransform) const; + + + /// Transformation from local element to module frame. This can be + /// used to take a local position in the element frame and transform + /// it to a position in the module frame. If one is already in the + /// module frame it will return the Identity transform. + //HepGeom::Transform3D localToModuleTransform() const; + Amg::Transform3D localToModuleTransform() const; + + + //@} + + /////////////////////////////////////////////////////////////////// + // + /// @name Element Extent + /// Methods to get extent of element in x, y and z. + /////////////////////////////////////////////////////////////////// + + //@{ + // Extent in x,y and z + double xMin() const; + double xMax() const; + double yMin() const; + double yMax() const; + double zMin() const; + double zMax() const; + + //@} + + /////////////////////////////////////////////////////////////////// + // + /// @name Design methods + // + /////////////////////////////////////////////////////////////////// + //@{ + + /// access to the local description: + const ScintDetectorDesign &design() const; + + // Methods from design + double width() const; // Width in x direction. + double length() const; // Length in y direction + double thickness() const; // Thickness in z direction + + virtual const Trk::SurfaceBounds & bounds() const; + + // Test that it is in the active region + // Intersect has 3 states + // bool SiIntersect::in() const // definitely in + // bool SiIntersect::out() const // definitely out + // bool SiIntersect::nearBoundary() const // near a boundary within the tolerances + // bool SiIntersect::mayIntersect() const // in() OR nearBoundary() + ScintIntersect inDetector(const Amg::Vector2D & localPosition, double phiTol, double etaTol) const; + ScintIntersect inDetector(const HepGeom::Point3D<double> & globalPosition, double phiTol, double etaTol) const; + + //@} + + /////////////////////////////////////////////////////////////////// + // + /// @name Cache handling. + // + /////////////////////////////////////////////////////////////////// + //@{. + // - Methods to handle invalidating and updating caches. The cached values include values that are affected by alignment + // Surface are only created on demand. The method updateAllCaches also creates the surfaces as well as calling updateCache. + // Conditions cache contains Lorentz angle related quantities. + + /// Signal that cached values are no longer valid. + /// Invalidate general cache + // void invalidate ATLAS_NOT_THREAD_SAFE () const; + void invalidate(); + + ///Set/calculate cache values + void setCache(){ + updateCache(); + } + ///Set/calculate all cache values including surfaces. + void setAllCaches(){ + updateAllCaches(); + } + //@} + + /////////////////////////////////////////////////////////////////// + // + /// @name Methods to satisfy TrkDetElementBase interface + // + /////////////////////////////////////////////////////////////////// + //{@ + virtual const Amg::Transform3D & transform(const Identifier&) const {return transform();} + virtual const Trk::Surface& surface (const Identifier&) const {return surface();} + virtual const Amg::Vector3D& center (const Identifier&) const {return center();} + virtual const Amg::Vector3D& normal (const Identifier&) const {return normal();} + virtual const Trk::SurfaceBounds & bounds(const Identifier&) const {return bounds();} + //@} + + ////////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////////////// + + public: + + const ScintCommonItems* getCommonItems() const; + + /////////////////////////////////////////////////////////////////// + // Private methods: + /////////////////////////////////////////////////////////////////// + + private: + /// Recalculate cached values. + void updateCache() const; + + /// Update all caches including surfaces. + void updateAllCaches() const; + + + // Common code for constructors. + void commonConstructor(); + + // Calculate extent in x, y and z. The values are cached and there + // are xMin(), xMax etc methods. + void getExtent(double &xMin, double &xMax, + double &yMin, double &yMax, + double &zMin, double &zMax) const; + + // Return the four corners of an element in local coordinates. + // Pass it an array of length 4. + // This function is used by getEtaPhiRegion() + void getCorners(HepGeom::Point3D<double> *corners) const; + + //Declaring the Message method for further use + MsgStream& msg (MSG::Level lvl) const { return m_commonItems->msg(lvl);} + + //Declaring the Method providing Verbosity Level + bool msgLvl (MSG::Level lvl) const { return m_commonItems->msgLvl(lvl);} + + + /////////////////////////////////////////////////////////////////// + // Private methods: + /////////////////////////////////////////////////////////////////// + private: + // Don't allow copying. + ScintDetectorElement(); + ScintDetectorElement(const ScintDetectorElement&); + ScintDetectorElement &operator=(const ScintDetectorElement&); + + /////////////////////////////////////////////////////////////////// + // Protected data: + /////////////////////////////////////////////////////////////////// + protected: + Identifier m_id; // identifier of this detector element + IdentifierHash m_idHash; // hash id + const ScintDetectorDesign *m_design; // local description of this detector element + const ScintCommonItems * m_commonItems; + + bool m_isVeto; + bool m_isTrigger; + bool m_isPreshower; + + // + // Cached values. + // + // Axes + ScintDetectorDesign::Axis m_hitEta; + ScintDetectorDesign::Axis m_hitPhi; + ScintDetectorDesign::Axis m_hitDepth; + + // Directions of axes. These are true if the hit/simulation and reconstruction local frames are + // in the same direction and false if they are opposite. + mutable bool m_depthDirection ATLAS_THREAD_SAFE; // Guarded by m_mutex // Direction of depth axis. + // Also direction of readout implant (n+ for pixel, p+ for SCT). + mutable bool m_phiDirection ATLAS_THREAD_SAFE; // + mutable bool m_etaDirection ATLAS_THREAD_SAFE; // + + mutable std::atomic_bool m_cacheValid; // Alignment associated quatities. + mutable std::atomic_bool m_firstTime; + + mutable std::recursive_mutex m_mutex; + + mutable Amg::Transform3D m_transform ATLAS_THREAD_SAFE; // Guarded by m_mutex + mutable HepGeom::Transform3D m_transformCLHEP ATLAS_THREAD_SAFE; // Guarded by m_mutex + + mutable Amg::Vector3D m_normal ATLAS_THREAD_SAFE; // Guarded by m_mutex + mutable Amg::Vector3D m_etaAxis ATLAS_THREAD_SAFE; // Guarded by m_mutex + mutable HepGeom::Vector3D<double> m_etaAxisCLHEP ATLAS_THREAD_SAFE; // Guarded by m_mutex + mutable Amg::Vector3D m_phiAxis ATLAS_THREAD_SAFE; // Guarded by m_mutex + mutable HepGeom::Vector3D<double> m_phiAxisCLHEP ATLAS_THREAD_SAFE; // Guarded by m_mutex + mutable Amg::Vector3D m_center ATLAS_THREAD_SAFE; // Guarded by m_mutex + mutable HepGeom::Vector3D<double> m_centerCLHEP ATLAS_THREAD_SAFE; // Guarded by m_mutex + + mutable double m_minX ATLAS_THREAD_SAFE;// Guarded by m_mutex + mutable double m_maxX ATLAS_THREAD_SAFE;// Guarded by m_mutex + mutable double m_minY ATLAS_THREAD_SAFE;// Guarded by m_mutex + mutable double m_maxY ATLAS_THREAD_SAFE;// Guarded by m_mutex + mutable double m_minZ ATLAS_THREAD_SAFE;// Guarded by m_mutex + mutable double m_maxZ ATLAS_THREAD_SAFE;// Guarded by m_mutex + + CxxUtils::CachedUniquePtrT<Trk::Surface> m_surface; + mutable std::vector<const Trk::Surface*> m_surfaces ATLAS_THREAD_SAFE; // Guarded by m_mutex + + const GeoAlignmentStore* m_geoAlignStore{}; + }; + + /////////////////////////////////////////////////////////////////// + // Inline methods: + /////////////////////////////////////////////////////////////////// + + inline HepGeom::Point3D<double> ScintDetectorElement::globalPositionHit(const HepGeom::Point3D<double> &localPos) const + { + return Amg::EigenTransformToCLHEP(transformHit())*localPos; + } + + inline Amg::Vector3D ScintDetectorElement::globalPosition(const Amg::Vector2D &localPos) const + { + if (!m_cacheValid) { + std::lock_guard<std::recursive_mutex> lock(m_mutex); + if (!m_cacheValid) updateCache(); + } + return m_center + localPos[Trk::distEta] * m_etaAxis + localPos[Trk::distPhi] * m_phiAxis; + } + + inline Amg::Vector3D ScintDetectorElement::globalPositionHit(const Amg::Vector3D &localPos) const + { + return transformHit() * localPos; + } + + inline HepGeom::Point3D<double> ScintDetectorElement::globalPositionCLHEP(const Amg::Vector2D &localPos) const + { + if (!m_cacheValid) { + std::lock_guard<std::recursive_mutex> lock(m_mutex); + if (!m_cacheValid) updateCache(); + } + return m_centerCLHEP + localPos[Trk::distEta] * m_etaAxisCLHEP + localPos[Trk::distPhi] * m_phiAxisCLHEP; + } + //here + inline Amg::Vector3D ScintDetectorElement::globalPosition(const Amg::Vector3D &localPos) const + { + return transform() * localPos; + } + + inline HepGeom::Point3D<double> ScintDetectorElement::globalPosition(const HepGeom::Point3D<double> &localPos) const + { + return transformCLHEP() * localPos; + } + + inline Amg::Vector2D ScintDetectorElement::localPosition(const HepGeom::Point3D<double> & globalPosition) const + { + if (!m_cacheValid){ + std::lock_guard<std::recursive_mutex> lock(m_mutex); + if (!m_cacheValid) updateCache(); + } + HepGeom::Vector3D<double> relativePos = globalPosition - m_centerCLHEP; + return Amg::Vector2D(relativePos.dot(m_phiAxisCLHEP), relativePos.dot(m_etaAxisCLHEP)); + } + + inline Amg::Vector2D ScintDetectorElement::localPosition(const Amg::Vector3D & globalPosition) const + { + if (!m_cacheValid){ + std::lock_guard<std::recursive_mutex> lock(m_mutex); + if (!m_cacheValid) updateCache(); + } + Amg::Vector3D relativePos = globalPosition - m_center; + return Amg::Vector2D(relativePos.dot(m_phiAxis), relativePos.dot(m_etaAxis)); + } + + inline const ScintDetectorDesign &ScintDetectorElement::design() const + { + return *m_design; + } + + inline const FaserDetectorID* ScintDetectorElement::getIdHelper() const + { + return m_commonItems->getIdHelper(); + } + + inline Identifier ScintDetectorElement::identify() const + { + return m_id; + } + + inline IdentifierHash ScintDetectorElement::identifyHash() const + { + return m_idHash; + } + + inline double ScintDetectorElement::hitDepthDirection() const + { + std::lock_guard<std::recursive_mutex> lock(m_mutex); + if (!m_cacheValid) updateCache(); + return (m_depthDirection) ? 1. : -1.; + } + + inline double ScintDetectorElement::hitPhiDirection() const + { + std::lock_guard<std::recursive_mutex> lock(m_mutex); + if (!m_cacheValid) updateCache(); + return (m_phiDirection) ? 1. : -1.; + } + + inline double ScintDetectorElement::hitEtaDirection() const + { + std::lock_guard<std::recursive_mutex> lock(m_mutex); + if (!m_cacheValid) updateCache(); + return (m_etaDirection) ? 1. : -1.; + } + + inline void ScintDetectorElement::invalidate() + { + m_cacheValid = false; + } + + inline void ScintDetectorElement::updateAllCaches() const + { + std::lock_guard<std::recursive_mutex> lock(m_mutex); + if (!m_cacheValid) updateCache(); + if (not m_surface) surface(); + } + + + inline double ScintDetectorElement::xMin() const + { + std::lock_guard<std::recursive_mutex> lock(m_mutex); + if (!m_cacheValid) updateCache(); + return m_minX; + } + + inline double ScintDetectorElement::xMax() const + { + std::lock_guard<std::recursive_mutex> lock(m_mutex); + if (!m_cacheValid) updateCache(); + return m_maxX; + } + + inline double ScintDetectorElement::yMin() const + { + std::lock_guard<std::recursive_mutex> lock(m_mutex); + if (!m_cacheValid) updateCache(); + return m_minY; + } + + inline double ScintDetectorElement::yMax() const + { + std::lock_guard<std::recursive_mutex> lock(m_mutex); + if (!m_cacheValid) updateCache(); + return m_maxY; + } + + inline double ScintDetectorElement::zMin() const + { + std::lock_guard<std::recursive_mutex> lock(m_mutex); + if (!m_cacheValid) updateCache(); + return m_minZ; + } + + inline double ScintDetectorElement::zMax() const + { + std::lock_guard<std::recursive_mutex> lock(m_mutex); + if (!m_cacheValid) updateCache(); + return m_maxZ; + } + + inline double ScintDetectorElement::width() const + { + return m_design->width(); + } + + inline double ScintDetectorElement::length() const + { + return m_design->length(); + } + + inline double ScintDetectorElement::thickness() const + { + return m_design->thickness(); + } + + inline const ScintCommonItems* ScintDetectorElement::getCommonItems() const + { + return m_commonItems; + } + +} // namespace ScintDD + +#endif // SCINTREADOUTGEOMETRY_SCINTDETECTORELEMENT_H + diff --git a/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintDetectorElementCollection.h b/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintDetectorElementCollection.h new file mode 100644 index 0000000000000000000000000000000000000000..3e3c092bcd6cc8c3798f91289ce5440e9fbd8941 --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintDetectorElementCollection.h @@ -0,0 +1,44 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + +/////////////////////////////////////////////////////////////////// +// ScintDetectorElementCollection.h +/////////////////////////////////////////////////////////////////// +// (c) ATLAS Detector software +/////////////////////////////////////////////////////////////////// + + +#ifndef SCINTREADOUTGEOMETRY_SCINTDETECTORELEMENTCOLLECTION_H +#define SCINTREADOUTGEOMETRY_SCINTDETECTORELEMENTCOLLECTION_H + +#include <vector> + +class IdentifierHash; + +namespace ScintDD { + + class ScintDetectorElement; + + /** @class ScintDetectorElementCollection + + Class to hold the ScintDetectorElement objects to be put in the detector store + + @author Grant Gorfine + @author Dave Casper + */ + + class ScintDetectorElementCollection : public std::vector<ScintDetectorElement *> { + public: + ~ScintDetectorElementCollection(); + const ScintDetectorElement* getDetectorElement(const IdentifierHash& hash) const; + }; + +} // namespace ScintDD + +#include "AthenaKernel/CLASS_DEF.h" +CLASS_DEF( ScintDD::ScintDetectorElementCollection , 1090173979 , 1 ) +#include "AthenaKernel/CondCont.h" +CONDCONT_DEF( ScintDD::ScintDetectorElementCollection, 1189378543 ); + +#endif // INDETREADOUTGEOMETRY_SIDETECTORELEMENTCOLLECTION_H diff --git a/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintDetectorManager.h b/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintDetectorManager.h new file mode 100644 index 0000000000000000000000000000000000000000..b372bdd0bd5d2457f2c1d15e58fd1c09544deae6 --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintDetectorManager.h @@ -0,0 +1,154 @@ +/* + Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration +*/ + +/////////////////////////////////////////////////////////////////// +// ScintDetectorManager.h +/////////////////////////////////////////////////////////////////// +// (c) ATLAS Detector software +/////////////////////////////////////////////////////////////////// + +#ifndef SCINTREADOUTGEOMETRY_SCINTDETECTORMANAGER_H +#define SCINTREADOUTGEOMETRY_SCINTDETECTORMANAGER_H + +#include "ScintReadoutGeometry/ScintDetectorManagerBase.h" + +#include "ScintReadoutGeometry/ScintDetectorElementCollection.h" +#include "ScintReadoutGeometry/ScintDD_Defs.h" +#include "ScintReadoutGeometry/ScintNumerology.h" + +// Amg stuff +#include "GeoPrimitives/GeoPrimitives.h" + +#include "CLHEP/Geometry/Transform3D.h" + +#include <string> +#include <map> + +class StoreGateSvc; +class Identifier; +class IdentifierHash; +class FaserDetectorID; +class GeoAlignableTransform; +class GeoVAlignmentStore; + +namespace ScintDD { + +class ScintDetectorElement; +class ScintDetectorDesign; +class ExtendedAlignableTransform; +class ScintNumerology; + + /** @class ScintDetectorManager + + Base class for Scintillator Detector managers. + + The Detector manager has methods to retrieve the Identifier + helper and methods to retrieve the detector elements. It also + manages the alignment with methods to register the call backs + and infrastructure to associate the alignment transforms with + the appropriate alignable transform in GeoModel. + + @author: Grant Gorfine + - modified and maintained by Nick Styles & Andreas Salzburger + */ + + class ScintDetectorManager : public ScintDetectorManagerBase { + + + public: + + // Constructor + ScintDetectorManager(StoreGateSvc * detStore, const std::string & name); + + // Destructor + virtual ~ScintDetectorManager() {}; + + + // + // Access Readout Elements + // + + /** access to individual elements using Identifier or IdentiferHash */ + virtual ScintDetectorElement * getDetectorElement(const Identifier &id) const = 0; + virtual ScintDetectorElement * getDetectorElement(const IdentifierHash &idHash) const = 0; + + /** access to whole collectiom */ + virtual const ScintDetectorElementCollection * getDetectorElementCollection() const = 0; + virtual ScintDetectorElementCollection::const_iterator getDetectorElementBegin() const = 0; + virtual ScintDetectorElementCollection::const_iterator getDetectorElementEnd() const = 0; + + + /** Add elememts */ + virtual void addDetectorElement(ScintDetectorElement * element) = 0; + + /** Initialize the neighbours. This can only be done when all elements are built */ + virtual void initNeighbours() = 0; + + /** Get tag used in dictionary */ + const std::string & tag() const; + + // /** Methods to query which manager we have */ + // virtual bool isPixel() const = 0; + // bool isSCT() const {return !isPixel();} + + /** Add alignable transforms. No access to these, they will be changed by manager: */ + virtual void addAlignableTransform (int level, const Identifier &id, GeoAlignableTransform *xf) = 0; + + /** Invalidate cache for all detector elements */ + virtual void invalidateAll() const; + + /** Update all caches */ + virtual void updateAll() const; + + + /** Helper method to set delta transform from a global delta - Amg interface*/ + bool setAlignableTransformGlobalDelta(ExtendedAlignableTransform * extXF, + const Amg::Transform3D & delta, + GeoVAlignmentStore* alignStore=nullptr) const; + + /** Helper method to set delta transform from a local delta - Amg interface */ + bool setAlignableTransformLocalDelta(ExtendedAlignableTransform * extXF, + const Amg::Transform3D & localToGlobalXF, + const Amg::Transform3D & delta, + GeoVAlignmentStore* alignStore=nullptr) const; + + /** Access to module design */ + void addDesign(const ScintDetectorDesign *); + int numDesigns() const; + const ScintDetectorDesign * getDesign(int i) const; + + /** Access Numerology */ + const ScintNumerology & numerology() const {return m_numerology;} + ScintNumerology & numerology() {return m_numerology;} + + private: + //** Prevent copy and assignment */ + const ScintDetectorManager & operator=(const ScintDetectorManager &right); + ScintDetectorManager(const ScintDetectorManager &right); + + /** This method is called by the ScintDetectorManagerBase */ + virtual bool setAlignableTransformDelta(int level, + const Identifier & id, + const Amg::Transform3D & delta, + FrameType frame, + GeoVAlignmentStore* alignStore) const = 0; + + + + std::string m_tag; + ScintNumerology m_numerology; + std::vector< const ScintDetectorDesign *> m_designs; + + }; + + +} // namespace ScintDD + +#ifndef GAUDI_NEUTRAL +#include "AthenaKernel/CLASS_DEF.h" + +CLASS_DEF(ScintDD::ScintDetectorManager, 209997176, 1) +#endif + +#endif // SCINTREADOUTGEOMETRY_SCINTDETECTORMANAGER_H diff --git a/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintDetectorManagerBase.h b/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintDetectorManagerBase.h new file mode 100644 index 0000000000000000000000000000000000000000..4357da297426bdba1eff01e347bb00e6bb7f6fdb --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintDetectorManagerBase.h @@ -0,0 +1,204 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + +/////////////////////////////////////////////////////////////////// +// ScintDectorManagerBase.h (was InDetDetectorManager.h) +/////////////////////////////////////////////////////////////////// +// (c) ATLAS Detector software +/////////////////////////////////////////////////////////////////// + +#ifndef SCINTREADOUTGEOMETRY_SCINTDETECTORMANAGERBASE_H +#define SCINTREADOUTGEOMETRY_SCINTDETECTORMANAGERBASE_H + +// Amg +#include "GeoPrimitives/GeoPrimitives.h" +// GeoModel stuff +#include "GeoModelKernel/GeoVDetectorManager.h" +#include "ScintReadoutGeometry/ScintDD_Defs.h" +#include "ScintReadoutGeometry/Version.h" +#include "CLHEP/Geometry/Transform3D.h" +// Message Stream Member +#include "AthenaKernel/MsgStreamMember.h" + +// IOV SVC for alignment: +#include "AthenaKernel/IIOVSvc.h" + +#include "DetDescrConditions/AlignableTransformContainer.h" + +#include "CxxUtils/checker_macros.h" + +#include <atomic> +#include <string> +#include <map> +#include <set> +#include <list> + +class StoreGateSvc; +class AlignableTransform; +class Identifier; +class FaserDetectorID; +class GeoVAlignmentStore; +class CondAttrListCollection; + +// mutable Athena::MsgStreamMember issues warnings. +ATLAS_NO_CHECK_FILE_THREAD_SAFETY; + +namespace ScintDD { + + typedef std::map<std::string, const void*> RawAlignmentObjects; + + /** @class ScintDetectorManagerBase + + Virtual base class for all Scintillator detector managers. + + It implements the processKey() method for alingment + which calls the setAlignableTransformDelta() method which + is specified in the extended classes. This method supports both, + local and global delta's in the frame and translates it to the + underlying GeoModel transform. As GeoModel (CLHEP) and tracking + (Amg) use different geo libraries, these are the methods that + act as the CLHEP <--> Amg interface + + @author: Grant Gorfine + - modified & maintained: Nick Styles & Andreas Salzburger + */ + class ScintDetectorManagerBase : public GeoVDetectorManager { + + public: + + // Constructor + ScintDetectorManagerBase(StoreGateSvc * detStore, const std::string & name); + + // Destructor + virtual ~ScintDetectorManagerBase(); + + + /** Get version information */ + const Version & getVersion() const; + const std::string & getLayout() const; // eg Initial, Final, TestBeam + void setVersion(const Version & version); + + /** Alignment access */ + void addChannel(const std::string & key, int level, FrameType frame); + void addFolder(const std::string & key); + void addSpecialFolder(const std::string & key); + void addGlobalFolder(const std::string & key); + void addAlignFolderType(const AlignFolderType alignfolder); + + StatusCode align( IOVSVC_CALLBACK_ARGS ) const; + + StatusCode align(const RawAlignmentObjects& alignObjects, GeoVAlignmentStore* alignStore) const; + + /** Invalidate cache for all detector elements */ + virtual void invalidateAll() const = 0; + + /** Update all caches */ + virtual void updateAll() const = 0; + + /** Check identifier is for this detector */ + virtual bool identifierBelongs(const Identifier & id) const = 0; + + /** Declaring the Message method for further use */ + MsgStream& msg (MSG::Level lvl) const { return m_msg.get() << lvl; } + + /** Declaring the Method providing Verbosity Level */ + bool msgLvl (MSG::Level lvl) const { return m_msg.get().level() <= lvl; } + + AlignFolderType m_alignfoldertype; + + protected: + StoreGateSvc * m_detStore; + + private: + /** @class LevelInfo + Private helper class definition. + */ + class LevelInfo { + + private: + int m_level; + FrameType m_type; + + public: + LevelInfo(): m_level(-1), m_type(ScintDD::global) {}; + LevelInfo(int level, FrameType frame): m_level(level), m_type(frame) {}; + + int level() const {return m_level;} + FrameType frame() const {return m_type;} + bool isGlobalDelta() const {return m_type == ScintDD::global;} + bool isLocalDelta() const {return m_type == ScintDD::local;} + bool isValid() const {return (m_level >= 0);} + + }; + + class AlignInfo { + + private: + AlignFolderType m_aligntype; + + public: + AlignInfo(): m_aligntype(ScintDD::none) {}; + AlignInfo(AlignFolderType alignfolder): m_aligntype(alignfolder) {}; + AlignFolderType AlignFolder() const {return m_aligntype;} + bool isValidAlign() const {return (m_aligntype != ScintDD::none);} + + }; + + + /** Retrieve level information */ + const LevelInfo & getLevel(const std::string & key) const; + + /** return align folder string to use **/ + // ScintDD::AlignFolderType getAlignInfo(); + + /** Process the alignment container, calls processKey */ + bool processAlignmentContainer(const std::string & key) const; + bool processAlignmentContainer(const AlignableTransformContainer* container, GeoVAlignmentStore* alignStore) const; + + /** Called by processAlignmentContainer, + applies only one key on the transform Collections */ + bool processKey(const std::string key, + const AlignableTransform* transformCollection, + GeoVAlignmentStore* alignStore=nullptr) const; + + /** Set method applying the delta transform (in global or local frame) + onto the geoModel transform : CLHEP <--> Amg interface */ + virtual bool setAlignableTransformDelta(int level, + const Identifier & id, + const Amg::Transform3D & delta, + FrameType frame, + GeoVAlignmentStore* alignStore=nullptr) const = 0; + + virtual bool processSpecialAlignment(const std::string & key, + ScintDD::AlignFolderType alignfolder) const = 0; + + virtual bool processSpecialAlignment(const std::string& key, + const CondAttrListCollection* obj=nullptr, + GeoVAlignmentStore* alignStore=nullptr) const = 0; + + bool processGlobalAlignmentContainer(const std::string & key, + const CondAttrListCollection* obj=nullptr, + GeoVAlignmentStore* alignStore=nullptr) const; + + virtual bool processGlobalAlignment(const std::string & key, int level, FrameType frame, + const CondAttrListCollection* obj=nullptr, + GeoVAlignmentStore* alignStore=nullptr) const; + + virtual const FaserDetectorID* getIdHelper() const = 0; + + //Declaring private message stream member. + mutable Athena::MsgStreamMember m_msg; + + Version m_version; + std::map<std::string, LevelInfo> m_keys; + std::set<std::string> m_folders; + std::set<std::string> m_specialFolders; + std::set<std::string> m_globalFolders; // new time-dependent global folders + + static const LevelInfo s_invalidLevel; + }; + +} // namespace ScintDD + +#endif // SCINTREADOUTGEOMETRY_SCINTDETECTORMANAGERBASE_H diff --git a/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintIntersect.h b/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintIntersect.h new file mode 100644 index 0000000000000000000000000000000000000000..305e62279c1a3bebc412476da0196b988a143f61 --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintIntersect.h @@ -0,0 +1,94 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/////////////////////////////////////////////////////////////////// +// ScintIntersect.h +/////////////////////////////////////////////////////////////////// +// (c) ATLAS Detector software +/////////////////////////////////////////////////////////////////// + +#ifndef SCINTREADOUTGEOMETRY_SCINTINTERSECT_H +#define SCINTREADOUTGEOMETRY_SCINTINTERSECT_H + +namespace ScintDD { + + /** @class ScintIntersect + + class to run intersection tests + + @author Grant Gorfine + */ + + class ScintIntersect { + + public: + + enum IntersectState {OUT = 0, BOUNDARY = 1, IN = 2}; + + ScintIntersect(IntersectState state = OUT); + + bool in() const; // Definitely in + bool out() const; // Definitely out + bool nearBoundary() const; // Near boundary within tolerences + bool mayIntersect() const; // in() || nearBoundary() + operator bool() const; // Equivalent to mayIntersect(). + + void setIn(); + void setOut(); + void setNearBoundary(); + + private: + IntersectState m_state; + + }; + +inline ScintIntersect::ScintIntersect(IntersectState state) + : m_state(state) +{} + +inline bool ScintIntersect::in() const +{ + return (m_state == IN); +} + +inline bool ScintIntersect::out() const +{ + return (m_state == OUT); +} + +inline bool ScintIntersect::nearBoundary() const +{ + return (m_state == BOUNDARY); +} + + +inline bool ScintIntersect::mayIntersect() const +{ + return (m_state == BOUNDARY || m_state == IN); +} + +inline ScintIntersect::operator bool() const +{ + return mayIntersect(); +} + +inline void ScintIntersect::setIn() +{ + m_state = IN; +} + +inline void ScintIntersect::setOut() +{ + m_state = OUT; +} + +inline void ScintIntersect::setNearBoundary() +{ + m_state = BOUNDARY; +} + +} // namespace ScintDD + +#endif //SCINTREADOUTGEOMETRY_SCINTINTERSECT_H + diff --git a/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintLocalPosition.h b/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintLocalPosition.h new file mode 100644 index 0000000000000000000000000000000000000000..38d01252b256e0621d8feaf86988e9a5e195cac8 --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintLocalPosition.h @@ -0,0 +1,173 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/////////////////////////////////////////////////////////////////// +// ScintLocalPosition.h +/////////////////////////////////////////////////////////////////// +// (c) ATLAS Detector software +/////////////////////////////////////////////////////////////////// + +#ifndef SCINTREADOUTGEOMETRY_SCINTLOCALPOSITION_H +#define SCINTREADOUTGEOMETRY_SCINTLOCALPOSITION_H + +#include "GeoPrimitives/GeoPrimitives.h" +#include "TrkEventPrimitives/ParamDefs.h" +#include <cmath> + +namespace Trk { + enum ExtraLocalPosParam {distDepth = 2}; // These will be defined in Trk soon. +} + +namespace ScintDD { + + /** @class ScintLocalPosition + Class to represent a position in the natural frame of a scintillator sensor, for Veto, Trigger and Preshower + */ + + class ScintLocalPosition { + + + /////////////////////////////////////////////////////////////////// + // Public methods: + /////////////////////////////////////////////////////////////////// + public: + + /** Default constructor: */ + ScintLocalPosition(); + + /** Copy constructor: */ + ScintLocalPosition(const ScintLocalPosition &position) = default; + + /** This allows one to pass a Amg::Vector2D to a ScintLocalPosition */ + ScintLocalPosition(const Amg::Vector2D &position); + + /** Constructor with parameters: + position along x direction + position along y direction + position along depth direction (default is 0) */ + ScintLocalPosition(const double x,const double y, + const double xDepth=0); + + /** Destructor: */ + ~ScintLocalPosition(); + + /** Assignment operator: */ + ScintLocalPosition &operator=(const ScintLocalPosition &) = default; + + /** Move assignment **/ + ScintLocalPosition &operator=(ScintLocalPosition &&) = default; + + /////////////////////////////////////////////////////////////////// + // Const methods: + /////////////////////////////////////////////////////////////////// + + /** position along horizontal direction:*/ + double x() const; + + /** position along vertical direction:*/ + double y() const; + + /** Cylindrical coordinate r:*/ + double r() const; + + /** Cylindrical coordinate phi:*/ + double phi() const; + + /** position along depth direction: */ + double xDepth() const; + + /////////////////////////////////////////////////////////////////// + // Non-const methods: + /////////////////////////////////////////////////////////////////// + + void x(const double x); + + void y(const double y); + + void xDepth(const double xDepth); + + // addition of positions: + ScintLocalPosition &operator+=(const ScintLocalPosition &position); + + // so we can go from ScintLocalPosition to Trk::LocalPosition + operator Amg::Vector2D(void) const; + + // scaling: + ScintLocalPosition &operator*=(const double factor); + ScintLocalPosition &operator/=(const double factor); + + /////////////////////////////////////////////////////////////////// + // Private data: + /////////////////////////////////////////////////////////////////// + + private: + double m_x; //!< position along x direction + double m_y; //!< position along y direction + double m_xDepth; //!< position along depth direction + }; + +/////////////////////////////////////////////////////////////////// +// Inline methods: +/////////////////////////////////////////////////////////////////// +inline ScintLocalPosition::~ScintLocalPosition() +{} + +inline double ScintLocalPosition::x() const +{ + return m_x; +} + +inline double ScintLocalPosition::y() const +{ + return m_y; +} + +inline double ScintLocalPosition::xDepth() const +{ + return m_xDepth; +} + +inline double ScintLocalPosition::r() const +{ + return std::sqrt(m_x * m_x + m_y * m_y); +} + +inline double ScintLocalPosition::phi() const +{ + return std::atan2(m_y, m_x); +} + +inline void ScintLocalPosition::x(const double x) +{ + m_x=x; +} + +inline void ScintLocalPosition::y(const double y) +{ + m_y=y; +} + +inline void ScintLocalPosition::xDepth(const double xDepth) +{ + m_xDepth=xDepth; +} + +/////////////////////////////////////////////////////////////////// +// Binary operators: +/////////////////////////////////////////////////////////////////// +ScintLocalPosition operator+(const ScintLocalPosition &position1, + const ScintLocalPosition &position2); + +ScintLocalPosition operator*(const ScintLocalPosition &position,const double factor); + +inline ScintLocalPosition operator*(const double factor,const ScintLocalPosition &position) +{ + return position*factor; +} + +ScintLocalPosition operator/(const ScintLocalPosition &position,const double factor); + +} // namespace ScintDD + +#endif // SCINTREADOUTGEOMETRY_SCINTLOCALPOSITION_H diff --git a/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintNumerology.h b/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintNumerology.h new file mode 100644 index 0000000000000000000000000000000000000000..98fdd4661ed8d2d0285de9ddcf2837353044b11f --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintNumerology.h @@ -0,0 +1,77 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/////////////////////////////////////////////////////////////////// +// ScintNumerology.h +/////////////////////////////////////////////////////////////////// +// (c) ATLAS Detector software +/////////////////////////////////////////////////////////////////// + + +#ifndef SCINTREADOUTGEOMETRY_SCINTNUMEROLOGY_H +#define SCINTREADOUTGEOMETRY_SCINTNUMEROLOGY_H + +#include <vector> + +namespace ScintDD { + + /** @class ScintNumerology + + Class to extract numerology for Veto, Trigger and Preshower. For example number of stations, plates, pmts, etc. + See InnerDetector/InDetExample/InDetDetDescrExample/src/SiReadSiDetectorElements.cxx for example of usage. + + @author Grant Gorfine + */ + + class ScintNumerology { + + + public: + + /** Constructor: */ + ScintNumerology(); + + // Accessors: + + /** Number of stations */ + int numStations() const; + + /** Number of plates in a station */ + int numPlatesForStation(int station) const; + + /** Number of pmts for plate */ + int numPmtsForPlate(int station, int plate) const; + + // Check presence of station + /** Check if station exists */ + bool useStation(int station) const; + + // Maximums + /** Maximum number of plates in a station */ + int maxNumPlates() const; + + /** Maximum number of pmts on a plate */ + int maxNumPmts() const; + + // Modifiers: + void setNumStations(int nStations); + void setNumPlatesForStation(int station, int nPlates); + void setNumPmtsForPlate(int station, int plate, int nPmts); + + private: + + int m_numStations; + int m_maxNumStationPlates; + int m_maxNumPlatePmts; + + std::vector<int> m_platesForStation; + std::vector<std::vector<int> > m_pmtsForPlate; + + }; + +}// End namespace + +#include "ScintNumerology.icc" + +#endif // SCINTREADOUTGEOMETRY_SCINTNUMEROLOGY_H diff --git a/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintNumerology.icc b/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintNumerology.icc new file mode 100644 index 0000000000000000000000000000000000000000..4aa49c0f4d754f1c2ce09da8ad48f41bd56eccfb --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/ScintNumerology.icc @@ -0,0 +1,40 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +namespace ScintDD { + + +inline int ScintNumerology::numStations() const +{ + return m_numStations; +} + +inline int ScintNumerology::numPlatesForStation(int station) const +{ + return m_platesForStation[station]; +} + +inline int ScintNumerology::numPmtsForPlate(int station, int plate) const +{ + return m_pmtsForPlate[station][plate]; +} + +inline int ScintNumerology::maxNumPlates() const +{ + return m_maxNumStationPlates; +} + +inline int ScintNumerology::maxNumPmts() const +{ + return m_maxNumPlatePmts; +} + + + +inline bool ScintNumerology::useStation(int station) const +{ + return (m_platesForStation[station] != 0); +} + +} // End namespace diff --git a/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/Version.h b/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/Version.h new file mode 100644 index 0000000000000000000000000000000000000000..0792d719af256cebc6460a1365249b5ff38e1863 --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/Version.h @@ -0,0 +1,91 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +//////////////////////////////////////////////////////////// +// Version.h +//////////////////////////////////////////////////////////// +// (c) ATLAS Detector software +//////////////////////////////////////////////////////////// + +#ifndef SCINTREADOUTGEOMETRY_VERSION +#define SCINTREADOUTGEOMETRY_VERSION + +#include <string> + +namespace ScintDD { + + /** @class Version + + Class to hold version information consisting of tag, name layout and description as strings, + such as their integer regpresentation in the major-minor-tag scheme + */ + + class Version { + + public: + + /** Constructor. */ + Version(const std::string & tag, + const std::string & name, + const std::string & layout, + const std::string & description, + int major, + int minor, + int patch); + + /** Constructor. DEPRECATED */ + Version(const std::string & name, + const std::string & layout, + const std::string & description, + int major, + int minor, + int patch); + + /** Empty Constructor */ + Version(); + + /** Version tag */ + const std::string & tag() const; + + /** Version label */ + const std::string & name() const; + + /** Layout (eg Initial, Final, TestBeam) */ + const std::string & layout() const; + + /** Description or comment. */ + const std::string & description() const; + + /** Major version number */ + int majorNum() const; + + /** Minor version number */ + int minorNum() const; + + /** Patch version number */ + int patchNum() const; + + /** Print out version number (eg. 2.00.00) */ + std::string versionNumber() const; + + /** Full Description + For example, + Version: SCT-DC1-00, Name: DC1, Layout: Final, Code Version: 2.00.00, Description: DC1 Geometry */ + std::string fullDescription() const; + + + private: + + std::string m_tag; + std::string m_name; + std::string m_layout; + std::string m_description; + int m_major; + int m_minor; + int m_patch; + }; + +} // namespace InDetDD + +#endif // SCINTREADOUTGEOMETRY_VERSION diff --git a/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/VetoDetectorManager.h b/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/VetoDetectorManager.h new file mode 100644 index 0000000000000000000000000000000000000000..2cdeabff25713ca8b25741b689394e25da897020 --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintReadoutGeometry/ScintReadoutGeometry/VetoDetectorManager.h @@ -0,0 +1,170 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + +/////////////////////////////////////////////////////////////////// +// VetoDetectorManager.h +/////////////////////////////////////////////////////////////////// +// (c) ATLAS Detector software +/////////////////////////////////////////////////////////////////// + +#ifndef SCINTREADOUTGEOMETRY_VETODETECTORMANAGER_H +#define SCINTREADOUTGEOMETRY_VETODETECTORMANAGER_H + +#include "GeoPrimitives/GeoPrimitives.h" + +#include "GeoModelKernel/GeoVPhysVol.h" + +#include "ScintReadoutGeometry/ScintDetectorManager.h" +#include "ScintReadoutGeometry/ScintDetectorElementCollection.h" +#include "ScintReadoutGeometry/ScintDD_Defs.h" + +#include "ScintIdentifier/VetoID.h" + +class StoreGateSvc; +class Identifier; +class IdentifierHash; +class GeoAlignableTransform; +class GeoVFullPhysVol; +class GeoVPhysVol; +class GeoVAlignmentStore; +class CondAttrListCollection; + +namespace ScintDD { + + class ScintDetectorElement; + class ExtendedAlignableTransform; + class VetoDetectorDesign; + + /** @class VetoDetectorManager + + Dedicated detector manager extending the functionality of the ScintDetectorManager + with dedicated Veto information, access. + + @author: Grant Gorfine + - modified and maintained by Nick Styles & Andreas Salzburger + */ + + class VetoDetectorManager : public ScintDetectorManager { + + public: + + // Constructor + VetoDetectorManager( StoreGateSvc* detStore ); + + // Destructor + virtual ~VetoDetectorManager(); + + /** Access Raw Geometry */ + virtual unsigned int getNumTreeTops() const override; + virtual PVConstLink getTreeTop(unsigned int i) const override; + /** Add tree top */ + void addTreeTop(PVLink); + + + // + // Access Readout Elements + // + + /** access to individual elements via Identifier */ + virtual ScintDetectorElement * getDetectorElement(const Identifier &id) const override; + + /** access to individual elements via IdentifierHash */ + virtual ScintDetectorElement * getDetectorElement(const IdentifierHash &idHash) const override; + + /** access to individual elements via module numbering schema */ + ScintDetectorElement * getDetectorElement(int station, int plate) const; + + /** access to whole collectiom via iterators */ + virtual const ScintDetectorElementCollection * getDetectorElementCollection() const override; + virtual ScintDetectorElementCollection::const_iterator getDetectorElementBegin() const override; + virtual ScintDetectorElementCollection::const_iterator getDetectorElementEnd() const override; + + /** Add elememts during construction */ + virtual void addDetectorElement(ScintDetectorElement * element) override; + + /** Add alignable transforms. No access to these, they will be changed by manager: */ + virtual void addAlignableTransform (int level, + const Identifier &id, + GeoAlignableTransform *xf, + const GeoVFullPhysVol * child); + + /** As above but does a dynamic_cast to GeoVFullPhysVol */ + virtual void addAlignableTransform (int level, + const Identifier &id, + GeoAlignableTransform *xf, + const GeoVPhysVol * child); + + // DEPRECATED + virtual void addAlignableTransform (int, const Identifier &, GeoAlignableTransform *) override {}; // For backward compatibility + + /** Initialize the neighbours. This can only be done when all elements are built. */ + virtual void initNeighbours() override; + + // /** Methods to query which manager we have */ + // virtual bool isPixel() const = 0; + // bool isSCT() const {return !isPixel();} + + /** Check identifier is for this detector */ + virtual bool identifierBelongs(const Identifier & id) const override; + + /** Access to module design, casts to VetoDetectorDesign */ + const ScintDetectorDesign * getVetoDesign(int i) const; + + /** Process new global DB folders for L1 and L2 **/ + virtual + bool processGlobalAlignment(const std::string &, int level, FrameType frame, + const CondAttrListCollection* obj, + GeoVAlignmentStore* alignStore) const override; + + // comply with InDetDetectorManager interface + bool processSpecialAlignment(const std::string & key, + ScintDD::AlignFolderType alignfolder) const override; + + bool processSpecialAlignment(const std::string& key, + const CondAttrListCollection* obj=nullptr, + GeoVAlignmentStore* alignStore=nullptr) const override; + + + private: + /** implements the main alignment update for delta transforms in different frames, + it translates into the LocalDelta or GlobalDelta function of ScintDetectorManager + */ + virtual bool setAlignableTransformDelta(int level, + const Identifier & id, + const Amg::Transform3D & delta, + FrameType frame, + GeoVAlignmentStore* alignStore) const override; + + /** Prevent copy and assignment */ + const VetoDetectorManager & operator=(const VetoDetectorManager &right); + VetoDetectorManager(const VetoDetectorManager &right); + + virtual const VetoID* getIdHelper() const override; + + // Private member data + std::vector<PVLink> m_volume; + ScintDetectorElementCollection m_elementCollection; + typedef std::map<Identifier, ExtendedAlignableTransform *> AlignableTransformMap; + std::vector< AlignableTransformMap > m_higherAlignableTransforms; + std::vector< ExtendedAlignableTransform *> m_alignableTransforms; + std::vector< ExtendedAlignableTransform *> m_moduleAlignableTransforms; + const VetoID* m_idHelper; + + /** This variable switches the how the local alignment corrections are applied + If true they will be calcualted on top of all of other corrections but in the default reference frame + If false they will be calcualted on top of all of other corrections but in the globally aligned reference frame + */ + bool m_isLogical; + + + }; + +} // namespace InDetDD + +#ifndef GAUDI_NEUTRAL +#include "AthenaKernel/CLASS_DEF.h" +CLASS_DEF(ScintDD::VetoDetectorManager, 184318568, 1) +#endif + +#endif // SCINTREADOUTGEOMETRY_VETODETECTORMANAGER_H diff --git a/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/ScintCommonItems.cxx b/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/ScintCommonItems.cxx new file mode 100644 index 0000000000000000000000000000000000000000..2f8465d40f399a34d7e304369031283e374b7b34 --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/ScintCommonItems.cxx @@ -0,0 +1,22 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + +#include "ScintReadoutGeometry/ScintCommonItems.h" + +namespace ScintDD { + +ScintCommonItems::ScintCommonItems(const FaserDetectorID* const idHelper) + : m_msg("ScintDetectorElement"), + m_idHelper(idHelper), + m_mutex{} +{} + +// void +// SiCommonItems::setSolenoidFrame(const HepGeom::Transform3D & transform) const +// { +// std::lock_guard<std::mutex> lock{m_mutex}; +// m_solenoidFrame = transform; +// } + +} // End namespace ScintDD diff --git a/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/ScintDetectorDesign.cxx b/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/ScintDetectorDesign.cxx new file mode 100644 index 0000000000000000000000000000000000000000..fa69388db2f1edcc5359010d13dc2152277b9948 --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/ScintDetectorDesign.cxx @@ -0,0 +1,87 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/////////////////////////////////////////////////////////////////// +// ScintDetectorDesign.cxx +// Implementation file for class ScintDetectorDesign +/////////////////////////////////////////////////////////////////// +// (c) ATLAS Detector software +/////////////////////////////////////////////////////////////////// +// Version 3.0 05/05/2001 David Calvet +// Modified: Grant Gorfine +// Modified: Dave Casper +/////////////////////////////////////////////////////////////////// + +#include "ScintReadoutGeometry/ScintDetectorDesign.h" +#include "ScintReadoutGeometry/ScintIntersect.h" +#include "TrkSurfaces/RectangleBounds.h" + +namespace ScintDD { +// Constructor with parameters: +ScintDetectorDesign::ScintDetectorDesign( const double thickness, + const double width, + const double length, + const int cells, + const ScintDetectorDesign::Edge readoutSide ) : + ScintDetectorDesign(thickness, width, length, cells, readoutSide, Axis::yAxis, Axis::xAxis) +{ } /* same as ATLAS SCT axes */ + +// Constructor with axes: +ScintDetectorDesign::ScintDetectorDesign( const double thickness, + const double width, + const double length, + const int cells, + const ScintDetectorDesign::Edge readoutSide, + const ScintDetectorDesign::Axis photonDirection, + const ScintDetectorDesign::Axis thicknessDirection ) : + m_thickness(thickness), + m_phiAxis(photonDirection), /* same as ATLAS SCT for now */ + m_depthAxis(thicknessDirection), + m_readoutSide(readoutSide) { + m_etaAxis = static_cast<Axis> ((xAxis + yAxis + zAxis) - (photonDirection + thicknessDirection)); + m_bounds = new Trk::RectangleBounds(0.5*width, 0.5*length); +} + + +// Destructor: +ScintDetectorDesign::~ScintDetectorDesign() { + if (m_bounds != nullptr) delete m_bounds; +} + +ScintIntersect ScintDetectorDesign::inDetector(const ScintLocalPosition &localPosition, + double xTol, double yTol) const { + double xDist = 0; + double yDist = 0; + + distanceToDetectorEdge(localPosition, xDist, yDist); + + ScintIntersect state; + + if (xDist < -xTol || yDist < -yTol) { + state.setOut(); + return state; + } + + if (xDist > xTol && yDist > yTol) { + state.setIn(); + return state; + } + + // Near boundary. + state.setNearBoundary(); + return state; +} + +DetectorShape ScintDetectorDesign::shape() const { + // Default is Box. + return ScintDD::Box; +} + +const Trk::SurfaceBounds & +ScintDetectorDesign::bounds() const +{ + return *m_bounds; +} + +} // namespace ScintDD diff --git a/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/ScintDetectorElement.cxx b/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/ScintDetectorElement.cxx new file mode 100644 index 0000000000000000000000000000000000000000..41cd8606ea1ab5b7423594b8bb2784785af23449 --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/ScintDetectorElement.cxx @@ -0,0 +1,1157 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + +/** + * @file ScintDetectorElement.cxx + * Implementation file for class ScintDetectorElement + * @author Grant Gorfine + * Based on version developed by David Calvet. +**/ + +#include "ScintReadoutGeometry/ScintDetectorElement.h" + +#include "ScintIdentifier/VetoID.h" +// #include "ScintIdentifier/TriggerID.h" +// #include "ScintIdentifier/PreshowerID.h" + +#include "GeoModelKernel/GeoVFullPhysVol.h" +#include "GeoModelUtilities/GeoAlignmentStore.h" +#include "FaserDetDescr/FaserDetectorID.h" + +#include "CLHEP/Geometry/Point3D.h" +#include "CLHEP/Geometry/Vector3D.h" +#include "CLHEP/Vector/ThreeVector.h" +#include "CLHEP/Units/PhysicalConstants.h" // for M_PI +#include "CLHEP/Units/SystemOfUnits.h" + +// #include "InDetReadoutGeometry/SiCellId.h" +// #include "InDetReadoutGeometry/SiReadoutCellId.h" +// #include "ScintReadoutGeometry/VetoDetectorDesign.h" +#include "ScintReadoutGeometry/ScintDetectorDesign.h" +// #include "InDetReadoutGeometry/StripStereoAnnulusDesign.h" + + +#include "ScintReadoutGeometry/ScintCommonItems.h" + +#include "TrkSurfaces/PlaneSurface.h" +#include "TrkSurfaces/SurfaceBounds.h" + +#include <cmath> +#include <cassert> +#include <limits> + +namespace ScintDD { +using Trk::distEta; +using Trk::distPhi; +using Trk::distDepth; + +// Constructor with parameters: +ScintDetectorElement::ScintDetectorElement(const Identifier &id, + const ScintDetectorDesign *design, + const GeoVFullPhysVol *geophysvol, + const ScintCommonItems * commonItems, + const GeoAlignmentStore* geoAlignStore) : + TrkDetElementBase(geophysvol), + m_id(id), + m_design(design), + m_commonItems(commonItems), + m_cacheValid(false), + m_firstTime(true), + m_mutex(), + m_surface{}, + m_surfaces{}, + m_geoAlignStore(geoAlignStore) +{ + //The following are fixes for coverity bug 11955, uninitialized scalars: + const bool boolDefault(true); + m_depthDirection=boolDefault; + m_phiDirection=boolDefault; + m_etaDirection=boolDefault; + const double defaultMin(std::numeric_limits<double>::max()); + const double defaultMax(std::numeric_limits<double>::lowest()); + m_minX=defaultMin; + m_maxX=defaultMax; + m_minY=defaultMin; + m_maxY=defaultMax; + m_minZ=defaultMin; + m_maxZ=defaultMax; + + m_hitEta = m_design->etaAxis(); + m_hitPhi = m_design->phiAxis(); + m_hitDepth = m_design->depthAxis(); + /// + + commonConstructor(); +} + +void +ScintDetectorElement::commonConstructor() +{ + if (!m_id.is_valid()) throw std::runtime_error("ScintDetectorElement: Invalid identifier"); + + // Set booleans for wether we are veto/trigger/preshower + m_isVeto = getIdHelper()->is_veto(m_id); + m_isTrigger = getIdHelper()->is_trigger(m_id); + m_isPreshower = getIdHelper()->is_preshower(m_id); + if (!m_isVeto && !m_isTrigger && !m_isPreshower) + { + if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Element id is not for veto, trigger or preshower" << endmsg; + } + else if ((m_isVeto && m_isTrigger) || (m_isVeto && m_isPreshower) || (m_isTrigger && m_isPreshower)) + { + if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Element id belongs to more than one of veto, trigger or preshower" << endmsg; + } + + // Set IdHash. + if (isVeto()) + { + const VetoID* vetoId = dynamic_cast<const VetoID* >(getIdHelper()); + m_idHash = vetoId->plate_hash(m_id); + } + else if (isTrigger()) + { + m_idHash = 64000; //FIXME - will blow up on invalid hash if ever reached + } + else if (isPreshower()) + { + m_idHash = 64000; //FIXME + } + + if (!m_idHash.is_valid()) throw std::runtime_error("ScintDetectorElement: Unable to set IdentifierHash"); + + // Increase the reference count of the ScintDetectorDesign objects. + m_design->ref(); + + // Increase the reference count of the ScintCommonItems objects. + m_commonItems->ref(); + + // Should we reference count the geophysvol as well? + +} + + +// Destructor: +ScintDetectorElement::~ScintDetectorElement() +{ + // The design is reference counted so that it will not be deleted until the last element is deleted. + m_design->unref(); + + m_commonItems->unref(); +} + +void +ScintDetectorElement::updateCache() const +{ + std::lock_guard<std::recursive_mutex> lock(m_mutex); + + bool firstTimeTmp = m_firstTime; + m_firstTime = false; + m_cacheValid = true; + + const GeoTrf::Transform3D & geoTransform = transformHit(); + + HepGeom::Point3D<double> centerGeoModel(0., 0., 0.); + m_centerCLHEP = Amg::EigenTransformToCLHEP(geoTransform) * centerGeoModel; + m_center = Amg::Vector3D(m_centerCLHEP[0],m_centerCLHEP[1],m_centerCLHEP[2]); + + // + // Determine directions depth, eta and phi axis in reconstruction local frame + // ie depth away from interaction point + // phi in direction of increasing phi + // eta in direction of increasing z in barrel, and increasing r in endcap + // + + // depthAxis, xAxis, and yAxis are defined to be x,y,z respectively for all detectors for hit local frame. + // depthAxis, xAxis, and yAxis are defined to be z,x,y respectively for all detectors for reco local frame. + static const HepGeom::Vector3D<double> localAxes[3] = { + HepGeom::Vector3D<double>(1,0,0), + HepGeom::Vector3D<double>(0,1,0), + HepGeom::Vector3D<double>(0,0,1) + }; + + static const HepGeom::Vector3D<double> & localRecoPhiAxis = localAxes[distPhi]; // Defined to be same as x axis + static const HepGeom::Vector3D<double> & localRecoEtaAxis = localAxes[distEta]; // Defined to be same as y axis + static const HepGeom::Vector3D<double> & localRecoDepthAxis = localAxes[distDepth]; // Defined to be same as z axis + + // We only need to calculate the rough orientation once. + //For it to change would require extreme unrealistic misalignment changes. + if (firstTimeTmp) { + // Determine the unit vectors in global frame + + const HepGeom::Vector3D<double> &geoModelPhiAxis = localAxes[m_hitPhi]; + const HepGeom::Vector3D<double> &geoModelEtaAxis = localAxes[m_hitEta]; + const HepGeom::Vector3D<double> &geoModelDepthAxis = localAxes[m_hitDepth]; + + HepGeom::Vector3D<double> globalDepthAxis(Amg::EigenTransformToCLHEP(geoTransform) * geoModelDepthAxis); + HepGeom::Vector3D<double> globalPhiAxis(Amg::EigenTransformToCLHEP(geoTransform) * geoModelPhiAxis); + HepGeom::Vector3D<double> globalEtaAxis(Amg::EigenTransformToCLHEP(geoTransform) * geoModelEtaAxis); + + // unit radial vector + HepGeom::Vector3D<double> unitR(m_center.x(), m_center.y(), 0.); + + unitR.setMag(1.); + + HepGeom::Vector3D<double> nominalEta; + HepGeom::Vector3D<double> nominalNormal; + // HepGeom::Vector3D<double> nominalPhi(-unitR.y(), unitR.x(), 0); + + // In Barrel like geometry, the etaAxis is along increasing z, and normal is in increasing radial direction. + // In Endcap like geometry, the etaAxis is along increasing r, and normal is in decreasing z direction, + // We base whether it is barrel like or endcap like by the orientation of the local z axis of the + // the element. This allows the use of endcap identifiers in a TB setup. A warning message is issued however if + // the orientation and identifier are not consistent (ie a barrel like orientation with an endcap identifier). + + // bool barrelLike = true; + // nominalEta.setZ(1); + // if (std::abs(globalEtaAxis.dot(nominalEta)) < 0.5) { // Check that it is in roughly the right direction. + // barrelLike = false; + // } + + // if (isBarrel() && !barrelLike) { + // if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Element has endcap like orientation with barrel identifier." + // << endmsg; + // } else if (!isBarrel() && barrelLike) { + // if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Element has barrel like orientation with endcap identifier." + // << endmsg; + // } + + // if (barrelLike) { + // nominalEta.setZ(1); + // nominalNormal = unitR; + // } else { // endcap like + nominalNormal.setZ(-1); + nominalEta = unitR; + // } + + // Determine if axes are to have their directions swapped. + + // + // Depth axis. + // + double depthDir = globalDepthAxis.dot(nominalNormal); + m_depthDirection = true; + if (depthDir < 0) { + // if (m_design->depthSymmetric()) { + m_depthDirection = false; + // } else { + // if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Unable to swap local depth axis." << endmsg; + // } + } + // if (std::abs(depthDir) < 0.5) { // Check that it is in roughly the right direction. + // msg(MSG::ERROR) << "Orientation of local depth axis does not follow correct convention." << endmsg; + // // throw std::runtime_error("Orientation of local depth axis does not follow correct convention."); + // m_depthDirection = true; // Don't swap. + // } + + // + // Phi axis (unclear how to handle for FASER - never swap for now) + // + // double phiDir = globalPhiAxis.dot(nominalPhi); + m_phiDirection = true; + // if (phiDir < 0) { + // if (m_design->phiSymmetric()) { + // m_phiDirection = false; + // } else { + // if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Unable to swap local xPhi axis." << endmsg; + // } + // } + + // if (std::abs(phiDir) < 0.5) { // Check that it is in roughly the right direction. + // msg(MSG::ERROR) << "Orientation of local xPhi axis does not follow correct convention." << endmsg; + // // throw std::runtime_error("Orientation of local xPhi axis does not follow correct convention."); + // m_phiDirection = true; // Don't swap. + // } + + // + // Eta axis (unclear how to handle for FASER - never swap for now) + // + // double etaDir = globalEtaAxis.dot(nominalEta); + m_etaDirection = true; + // if (etaDir < 0) { + // if (m_design->etaSymmetric()) { + // m_etaDirection = false; + // } else { + // if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "Unable to swap local xEta axis." << endmsg; + // } + // } + // if (std::abs(etaDir) < 0.5) { // Check that it is in roughly the right direction. + // msg(MSG::ERROR) << "Orientation of local xEta axis does not follow correct convention." << endmsg; + // // throw std::runtime_error("Orientation of local xEta axis does not follow correct convention."); + // m_etaDirection = true; // Don't swap + // } + + } // end if (firstTimeTmp) + + + + m_transformCLHEP = Amg::EigenTransformToCLHEP(geoTransform) * recoToHitTransform(); + //m_transform = m_commonItems->solenoidFrame() * geoTransform * recoToHitTransform(); + m_transform = Amg::CLHEPTransformToEigen(m_transformCLHEP); + + // Check that local frame is right-handed. (ie transform has no reflection) + // This can be done by checking that the determinant is >0. + if (firstTimeTmp) { // Only need to check this once. + HepGeom::Transform3D & t = m_transformCLHEP; + double det = t(0,0) * (t(1,1)*t(2,2) - t(1,2)*t(2,1)) - + t(0,1) * (t(1,0)*t(2,2) - t(1,2)*t(2,0)) + + t(0,2) * (t(1,0)*t(2,1) - t(1,1)*t(2,0)); + if (det < 0) { + // if (m_design->depthSymmetric()) { + if (msgLvl(MSG::DEBUG)) + msg(MSG::DEBUG) << "Local frame is left-handed, Swapping depth axis to make it right handed." + << endmsg; + m_depthDirection = !m_depthDirection; + m_transformCLHEP = Amg::EigenTransformToCLHEP(geoTransform) * recoToHitTransform(); + m_transform = Amg::CLHEPTransformToEigen(m_transformCLHEP); + //m_transform = m_commonItems->solenoidFrame() * geoTransform * recoToHitTransform(); + // } else { + // if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Local frame is left-handed." << endmsg; + // } + } + } + + + // Initialize various cached members + // The unit vectors + HepGeom::Vector3D<double> normalCLHEP = m_transformCLHEP * localRecoDepthAxis; + m_normal = Amg::Vector3D( normalCLHEP[0], normalCLHEP[1], normalCLHEP[2]); + + + m_phiAxisCLHEP = m_transformCLHEP * localRecoPhiAxis; + m_etaAxisCLHEP = m_transformCLHEP * localRecoEtaAxis; + + m_phiAxis = Amg::Vector3D(m_phiAxisCLHEP[0],m_phiAxisCLHEP[1],m_phiAxisCLHEP[2]); + m_etaAxis = Amg::Vector3D(m_etaAxisCLHEP[0],m_etaAxisCLHEP[1],m_etaAxisCLHEP[2]); + + getExtent(m_minX, m_maxX, m_minY, m_maxY, m_minZ, m_maxZ); + + + // Determin isStereo +// if (firstTimeTmp) { +// if (isSCT() && m_otherSide) { +// double sinStereoThis = std::abs(sinStereo()); +// double sinStereoOther = std::abs(m_otherSide->sinStereo()); +// if (sinStereoThis == sinStereoOther) { +// // If they happend to be equal then set side0 as axial and side1 as stereo. +// const SCT_ID* sctId = dynamic_cast<const SCT_ID *>(getIdHelper()); +// if (sctId) { +// int side = sctId->side(m_id); +// m_isStereo = (side == 1); +// } +// } else { +// // set the stereo side as the one with largest absolute sinStereo. +// m_isStereo = (sinStereoThis > sinStereoOther); +// } +// } else { +// m_isStereo = false; +// } +// } +} + + +const GeoTrf::Transform3D & +ScintDetectorElement::transformHit() const +{ + if (m_geoAlignStore) { + const GeoTrf::Transform3D* ptrXf = m_geoAlignStore->getAbsPosition(getMaterialGeom()); + if (ptrXf) return *ptrXf; + } + return getMaterialGeom()->getAbsoluteTransform(); +} + +const Amg::Transform3D & +ScintDetectorElement::transform() const +{ + if (!m_cacheValid){ + std::lock_guard<std::recursive_mutex> lock(m_mutex); + if (!m_cacheValid) updateCache(); + } + return m_transform; +} + +const HepGeom::Transform3D & +ScintDetectorElement::transformCLHEP() const +{ + //stuff to get the CLHEP version of the local to global transform. + if (!m_cacheValid){ + std::lock_guard<std::recursive_mutex> lock(m_mutex); + if (!m_cacheValid) updateCache(); + } + return m_transformCLHEP; +} + +const HepGeom::Transform3D +ScintDetectorElement::defTransformCLHEP() const +{ + if (m_geoAlignStore) { + const GeoTrf::Transform3D* ptrXf = m_geoAlignStore->getDefAbsPosition(getMaterialGeom()); + if (ptrXf) return Amg::EigenTransformToCLHEP(*ptrXf) * recoToHitTransform(); + } + return Amg::EigenTransformToCLHEP(getMaterialGeom()->getDefAbsoluteTransform()) * recoToHitTransform(); +} + +const Amg::Transform3D +ScintDetectorElement::defTransform() const +{ + HepGeom::Transform3D tmpTransform = defTransformCLHEP(); + return Amg::CLHEPTransformToEigen(tmpTransform); +} + +const HepGeom::Transform3D +ScintDetectorElement::recoToHitTransform() const +{ + + // Determine the reconstruction local (LocalPosition) to global transform. + + std::lock_guard<std::recursive_mutex> lock(m_mutex); + if (m_firstTime) updateCache(); + + // global = transform * recoLocal + // = transfromHit * hitLocal + // = transformHit * recoToHitTransform * recoLocal + // recoToHitTransform takes recoLocal to hitLocal + // x,y,z -> y,z,x + // equiv to a rotation around Y of 90 deg followed by a rotation around X of 90deg + // + // recoToHit is static as it needs to be calculated once only. + // We use the HepGeom::Transform3D constructor which takes one coordinates system to another where the + // coordinate system is defined by it center and two axes. + // distPhi, distEta are the reco local axes and hitPhi and hitEta are the hit local axes. + // It assume phi, eta, depth makes a right handed system which is the case. + static const HepGeom::Vector3D<double> localAxes[3] = { + HepGeom::Vector3D<double>(1,0,0), + HepGeom::Vector3D<double>(0,1,0), + HepGeom::Vector3D<double>(0,0,1) + }; + //static + + const HepGeom::Transform3D recoToHit(HepGeom::Point3D<double>(0,0,0),localAxes[distPhi],localAxes[distEta], + HepGeom::Point3D<double>(0,0,0),localAxes[m_hitPhi],localAxes[m_hitEta]); + + // Swap direction of axis as appropriate + CLHEP::Hep3Vector scale(1,1,1); + if (!m_phiDirection) scale[distPhi] = -1; + if (!m_etaDirection) scale[distEta] = -1; + if (!m_depthDirection) scale[distDepth] = -1; + return recoToHit * HepGeom::Scale3D(scale[0],scale[1],scale[2]); +} + +const Amg::Transform3D & +ScintDetectorElement::plateTransform() const +{ + return transform(); + // return (isModuleFrame()) ? transform() : m_otherSide->transform(); +} + + Amg::Transform3D + ScintDetectorElement::defPlateTransform() const +{ + return defTransform(); +// return (isModuleFrame()) ? defTransform() : m_otherSide->defTransform(); +} + + +// Take a transform in the local reconstruction and return it in the module frame +// For a given transform l in frame A. The equivalent transform in frame B is +// B.inverse() * A * l * A.inverse() * B +// Here A is the local to global transform of the element and B is the local to global +// transform of the module. +// If we are already in the module frame then there is nothing to do, we just return the +// transform that is input. Otherwise we use the above formula. +Amg::Transform3D +ScintDetectorElement::localToModuleFrame(const Amg::Transform3D & localTransform) const +{ + // if (isModuleFrame()) { + return localTransform; + // } else { + // return m_otherSide->transform().inverse() * transform() * localTransform * transform().inverse() * m_otherSide->transform(); + // } +} + +Amg::Transform3D +ScintDetectorElement::localToModuleTransform() const +{ + // if (isModuleFrame()) { + return Amg::Transform3D(); // Identity + // } else { + // return m_otherSide->transform().inverse() * transform(); + // } +} + + +// bool +// ScintDetectorElement::isModuleFrame() const +// { +// // The module frame is the axial side. +// // NB isStereo returns false for the pixel and so +// // isModuleFrame is always true for the pixel. + +// return !isStereo(); +// } + + +const Amg::Vector3D & +ScintDetectorElement::center() const +{ + if (!m_cacheValid){ + std::lock_guard<std::recursive_mutex> lock(m_mutex); + if (!m_cacheValid) updateCache(); + } + return m_center; +} + +const Amg::Vector3D & +ScintDetectorElement::normal() const +{ + if (!m_cacheValid){ + std::lock_guard<std::recursive_mutex> lock(m_mutex); + if (!m_cacheValid) updateCache(); + } + return m_normal; +} + +const HepGeom::Vector3D<double> & +ScintDetectorElement::etaAxisCLHEP() const +{ + if (!m_cacheValid){ + std::lock_guard<std::recursive_mutex> lock(m_mutex); + if (!m_cacheValid) updateCache(); + } + return m_etaAxisCLHEP; +} + +const HepGeom::Vector3D<double> & +ScintDetectorElement::phiAxisCLHEP() const +{ + if (!m_cacheValid){ + std::lock_guard<std::recursive_mutex> lock(m_mutex); + if (!m_cacheValid) updateCache(); + } + return m_phiAxisCLHEP; +} + +const Amg::Vector3D & +ScintDetectorElement::etaAxis() const +{ + if (!m_cacheValid){ + std::lock_guard<std::recursive_mutex> lock(m_mutex); + if (!m_cacheValid) updateCache(); + } + return m_etaAxis; +} + +const Amg::Vector3D & +ScintDetectorElement::phiAxis() const +{ + if (!m_cacheValid){ + std::lock_guard<std::recursive_mutex> lock(m_mutex); + if (!m_cacheValid) updateCache(); + } + return m_phiAxis; +} + +Amg::Vector2D +ScintDetectorElement::hitLocalToLocal(double xEta, double xPhi) const // Will change order to phi,eta +{ + std::lock_guard<std::recursive_mutex> lock(m_mutex); + if (!m_cacheValid) updateCache(); + if (!m_etaDirection) xEta = -xEta; + if (!m_phiDirection) xPhi = -xPhi; + return Amg::Vector2D(xPhi, xEta); +} + +HepGeom::Point3D<double> +ScintDetectorElement::hitLocalToLocal3D(const HepGeom::Point3D<double> & hitPosition) const +{ + // Equiv to transform().inverse * transformHit() * hitPosition + std::lock_guard<std::recursive_mutex> lock(m_mutex); + if (!m_cacheValid) updateCache(); + double xDepth = hitPosition[m_hitDepth]; + double xPhi = hitPosition[m_hitPhi]; + double xEta = hitPosition[m_hitEta]; + if (!m_depthDirection) xDepth = -xDepth; + if (!m_phiDirection) xPhi = -xPhi; + if (!m_etaDirection) xEta = -xEta; + return HepGeom::Point3D<double>(xPhi, xEta, xDepth); +} + + +bool ScintDetectorElement::isVeto() const +{ + return m_isVeto; +} + +bool ScintDetectorElement::isTrigger() const +{ + return m_isTrigger; +} + +bool ScintDetectorElement::isPreshower() const +{ + return m_isPreshower; +} + +// bool ScintDetectorElement::isDBM() const +// { +// return m_isDBM; +// } + +// bool ScintDetectorElement::isBlayer() const +// { +// if (isPixel() && isBarrel()) { +// const PixelID* p_pixelId = static_cast<const PixelID *>(getIdHelper()); +// return (0==p_pixelId->layer_disk(m_id)); +// } else { +// return false; +// } +// } + +// bool ScintDetectorElement::isInnermostPixelLayer() const +// { +// if (isPixel() && isBarrel()) { +// const PixelID* p_pixelId = static_cast<const PixelID *>(getIdHelper()); +// return (0==p_pixelId->layer_disk(m_id)); +// } else { +// return false; +// } +// } + +// bool ScintDetectorElement::isNextToInnermostPixelLayer() const +// { +// if (isPixel() && isBarrel()) { +// const PixelID* p_pixelId = static_cast<const PixelID *>(getIdHelper()); +// return (1==p_pixelId->layer_disk(m_id)); +// } else { +// return false; +// } +// } + +// // compute sin(tilt angle) at center: +// double ScintDetectorElement::sinTilt() const +// { +// std::lock_guard<std::recursive_mutex> lock(m_mutex); +// if (!m_cacheValid) updateCache(); + +// // Tilt is defined as the angle between a refVector and the sensor normal. +// // In barrel refVector = unit vector radial. +// // in endcap it is assumed there is no tilt. +// // sinTilt = (refVector cross normal) . z + +// // tilt angle is not defined for the endcap +// if (isEndcap()) return 0; + +// // Angle between normal and radial vector. +// // HepGeom::Vector3D<double> refVector(m_center.x(), m_center.y(), 0); +// // return (refVector.cross(m_normal)).z()/refVector.mag(); +// // or the equivalent +// return (m_center.x() * m_normal.y() - m_center.y() * m_normal.x()) / m_center.perp(); +// } + +// double ScintDetectorElement::sinTilt(const Amg::Vector2D &localPos) const +// { +// std::lock_guard<std::recursive_mutex> lock(m_mutex); +// if (!m_cacheValid) updateCache(); + +// // tilt angle is not defined for the endcap +// if (isEndcap()) return 0; + +// HepGeom::Point3D<double> point=globalPositionCLHEP(localPos); +// return sinTilt(point); +// } + +// double ScintDetectorElement::sinTilt(const HepGeom::Point3D<double> &globalPos) const +// { +// std::lock_guard<std::recursive_mutex> lock(m_mutex); +// if (!m_cacheValid) updateCache(); + +// // It is assumed that the global position is already in the plane of the element. + +// // tilt angle is not defined for the endcap +// if (isEndcap()) return 0; + +// // Angle between normal and radial vector. +// //HepGeom::Vector3D<double> refVector(globalPos.x(), globalPos.y(), 0); +// //return (refVector.cross(m_normal)).z()/refVector.mag(); +// // or the equivalent +// return (globalPos.x() * m_normal.y() - globalPos.y() * m_normal.x()) / globalPos.perp(); +// } + +// double ScintDetectorElement::sinStereo() const +// { +// std::lock_guard<std::recursive_mutex> lock(m_mutex); +// if (!m_cacheValid) updateCache(); + +// // Stereo is the angle between a refVector and a vector along the strip/pixel in eta direction. +// // I'm not sure how the sign should be defined. I've defined it here +// // with rotation sense respect to normal, +// // where normal is away from IP in barrel and in -ve z direction in endcap + +// // In Barrel refVector = unit vector along z axis, +// // in endcap refVector = unit vector radial. +// // +// // sinStereo = (refVector cross stripAxis) . normal +// // = (refVector cross etaAxis) . normal +// // = refVector . (etaAxis cross normal) +// // = refVector . phiAxis +// // +// // in Barrel we use +// // sinStereo = refVector . phiAxis +// // = phiAxis.z() +// // +// // in endcap we use +// // sinStereo = (refVector cross etaAxis) . normal +// // = -(center cross etaAxis) . zAxis +// // = (etaAxis cross center). z() + +// double sinStereo; +// if (isBarrel()) { +// sinStereo = m_phiAxis.z(); +// } else { // endcap +// sinStereo = (m_center.y() * m_etaAxis.x() - m_center.x() * m_etaAxis.y()) / m_center.perp(); +// } +// return sinStereo; +// } + +// double ScintDetectorElement::sinStereo(const Amg::Vector2D &localPos) const +// { +// std::lock_guard<std::recursive_mutex> lock(m_mutex); +// if (!m_cacheValid) updateCache(); + +// HepGeom::Point3D<double> point=globalPositionCLHEP(localPos); +// return sinStereo(point); +// } + +// double ScintDetectorElement::sinStereo(const HepGeom::Point3D<double> &globalPos) const +// { +// // +// // sinStereo = (refVector cross stripAxis) . normal +// // + +// std::lock_guard<std::recursive_mutex> lock(m_mutex); +// if (!m_cacheValid) updateCache(); + +// double sinStereo; +// if (isBarrel()) { +// if (m_design->shape() != InDetDD::Trapezoid) { +// sinStereo = m_phiAxis.z(); +// } else { // trapezoid +// assert (minWidth() != maxWidth()); +// double radius = width() * length() / (maxWidth() - minWidth()); +// HepGeom::Vector3D<double> stripAxis = radius * m_etaAxisCLHEP + globalPos - m_centerCLHEP; +// sinStereo = (stripAxis.x() * m_normal.y() - stripAxis.y() * m_normal.x()) / stripAxis.mag(); +// } +// } else { // endcap +// if (m_design->shape() != InDetDD::Trapezoid) { +// sinStereo = (globalPos.y() * m_etaAxis.x() - globalPos.x() * m_etaAxis.y()) / globalPos.perp(); +// } else { // trapezoid +// assert (minWidth() != maxWidth()); +// double radius = width() * length() / (maxWidth() - minWidth()); +// // Only need projection in xy plane. +// double stripAxisX = globalPos.x() - m_center.x() + m_etaAxis.x()*radius; +// double stripAxisY = globalPos.y() - m_center.y() + m_etaAxis.y()*radius; +// double norm = 1./(radius*sqrt(stripAxisX*stripAxisX + stripAxisY*stripAxisY)); +// sinStereo = norm * (stripAxisX * globalPos.y() - stripAxisY * globalPos.x()); +// } +// } +// return sinStereo; +// } + +// bool +// ScintDetectorElement::isStereo() const +// { +// std::lock_guard<std::recursive_mutex> lock(m_mutex); +// if (m_firstTime) updateCache(); +// return m_isStereo; +// } + + +// double +// ScintDetectorElement::sinStereoLocal(const Amg::Vector2D &localPos) const +// { +// // The equation below will work for rectangle detectors as well in which +// // case it will return 0. But we return zero immediately as there is no point doing the calculation. +// if (m_design->shape() == InDetDD::Box) return 0; +// double oneOverRadius = (maxWidth() - minWidth()) / (width() * length()); +// double x = localPos[distPhi]; +// double y = localPos[distEta]; +// return -x*oneOverRadius / sqrt( (1+y*oneOverRadius)*(1+y*oneOverRadius) + x*oneOverRadius*x*oneOverRadius ); +// } + + +// double +// ScintDetectorElement::sinStereoLocal(const HepGeom::Point3D<double> &globalPos) const +// { +// return sinStereoLocal(localPosition(globalPos)); +// } + +// // Special method for SCT to retrieve the two ends of a "strip" +// std::pair<Amg::Vector3D,Amg::Vector3D> ScintDetectorElement::endsOfStrip(const Amg::Vector2D &position) const +// { +// const std::pair<Amg::Vector2D,Amg::Vector2D> localEnds= +// m_design->endsOfStrip(position); +// return std::pair<Amg::Vector3D,Amg::Vector3D >(globalPosition(localEnds.first), +// globalPosition(localEnds.second)); +// } + + +Trk::Surface & +ScintDetectorElement::surface() +{ + if (not m_surface) m_surface.set(std::make_unique<Trk::PlaneSurface>(*this)); + return *m_surface; +} + +const Trk::Surface & +ScintDetectorElement::surface() const +{ + if (not m_surface) m_surface.set(std::make_unique<Trk::PlaneSurface>(*this)); + return *m_surface; +} + +const std::vector<const Trk::Surface*>& ScintDetectorElement::surfaces() const +{ + std::lock_guard<std::recursive_mutex> lock(m_mutex); + if (!m_surfaces.size()) { + // get this surface + m_surfaces.push_back(&surface()); + // get the other side surface + // if (otherSide()) { + // m_surfaces.push_back(&(otherSide()->surface())); + // } + } + // return the surfaces + return m_surfaces; +} + +const Trk::SurfaceBounds & +ScintDetectorElement::bounds() const +{ + return m_design->bounds(); +} + +// Get min/max or r, z,and phi +void ScintDetectorElement::getExtent(double &xMin, double &xMax, + double &yMin, double &yMax, + double &zMin, double &zMax) const +{ + + HepGeom::Point3D<double> corners[4]; + getCorners(corners); + + bool first = true; + + // double phiOffset = 0.; + + double radialShift = 0.; + const HepGeom::Transform3D rShift = HepGeom::TranslateX3D(radialShift);//in local frame, radius is x + + for (int i = 0; i < 4; i++) { + + // if (testDesign) corners[i].transform(rShift); + + HepGeom::Point3D<double> globalPoint = globalPosition(corners[i]); + + // double rPoint = globalPoint.perp(); + double xPoint = globalPoint.x(); + double yPoint = globalPoint.y(); + double zPoint = globalPoint.z(); + // double phiPoint = globalPoint.phi(); + + // Use first point to initializa min/max values. + if (first) { + + // // Put phi in a range so that we are not near -180/+180 division. + // // Do this by adding an offset if phi > 90 CLHEP::deg or < -90 CLHEP::deg. + // // This offset is later removed. + // if (phiPoint < -0.5 * M_PI) { + // phiOffset = -0.5 * M_PI; + // } else if (phiPoint > 0.5 * M_PI) { + // phiOffset = 0.5 * M_PI; + // } + // phiMin = phiMax = phiPoint - phiOffset; + // rMin = rMax = rPoint; + xMin = xMax = xPoint; + yMin = yMax = yPoint; + zMin = zMax = zPoint; + + } else { + // phiPoint -= phiOffset; + // // put phi back in -M_PI < phi < +M_PI range + // if (phiPoint < -M_PI) phiPoint += 2. * M_PI; + // if (phiPoint > M_PI) phiPoint -= 2. * M_PI; + // phiMin = std::min(phiMin, phiPoint); + // phiMax = std::max(phiMax, phiPoint); + // rMin = std::min(rMin, rPoint); + // rMax = std::max(rMax, rPoint); + xMin = std::min(xMin, xPoint); + xMax = std::max(xMax, xPoint); + yMin = std::min(yMin, yPoint); + yMax = std::max(yMax, yPoint); + zMin = std::min(zMin, zPoint); + zMax = std::max(zMax, zPoint); + } + first = false; + } + + // // put phi back in -M_PI < phi < +M_PI range + // phiMin += phiOffset; + // phiMax += phiOffset; + // if (phiMin < -M_PI) phiMin += 2. * M_PI; + // if (phiMin > M_PI) phiMin -= 2. * M_PI; + // if (phiMax < -M_PI) phiMax += 2. * M_PI; + // if (phiMax > M_PI) phiMax -= 2. * M_PI; + +} + + + +// Get eta/phi extent. Returns min/max eta and phi and r (for barrel) +// or z (for endcap) Takes as input the vertex spread in z (+-deltaZ). +// Gets 4 corners of the sensor and calculates eta phi for each corner +// for both +/- vertex spread. The returned phi is between -M_PI and M_PI +// with the direction minPhi to maxPhi always in the positive sense, +// so if the element extends across the -180/180 boundary then minPhi will +// be greater than maxPhi. +// void ScintDetectorElement::getEtaPhiRegion(double deltaZ, double &etaMin, double &etaMax, double &phiMin, +// double &phiMax, double &rz) const +// { +// std::lock_guard<std::recursive_mutex> lock(m_mutex); +// if (!m_cacheValid) updateCache(); + +// HepGeom::Point3D<double> corners[4]; +// getCorners(corners); + +// bool first = true; + +// double phiOffset = 0.; + +// for (int i = 0; i < 4; i++) { +// double etaMinPoint; +// double etaMaxPoint; +// double phiPoint; + +// // Get the eta phi value for this corner. +// getEtaPhiPoint(corners[i], deltaZ, etaMinPoint, etaMaxPoint, phiPoint); + +// if (first) { // Use the first point to initialize the min/max values. + +// // Put phi in a range so that we are not near -180/+180 division. +// // Do this by adding an offset if phi > 90 CLHEP::deg or < -90 CLHEP::deg. +// // This offset is later removed. +// if (phiPoint < -0.5 * M_PI) { +// phiOffset = -0.5 * M_PI; +// } else if (phiPoint > 0.5 * M_PI) { +// phiOffset = 0.5 * M_PI; +// } +// phiMin = phiMax = phiPoint - phiOffset; +// etaMin = etaMinPoint; +// etaMax = etaMaxPoint; +// } else { +// phiPoint -= phiOffset; +// // put phi back in -M_PI < phi < +M_PI range +// if (phiPoint < -M_PI) phiPoint += 2. * M_PI; +// if (phiPoint > M_PI) phiPoint -= 2. * M_PI; +// phiMin = std::min(phiMin, phiPoint); +// phiMax = std::max(phiMax, phiPoint); +// etaMin = std::min(etaMin, etaMinPoint); +// etaMax = std::max(etaMax, etaMaxPoint); +// } +// first = false; +// } + +// // put phi back in -M_PI < phi < +M_PI range +// phiMin += phiOffset; +// phiMax += phiOffset; +// if (phiMin < -M_PI) phiMin += 2. * M_PI; +// if (phiMin > M_PI) phiMin -= 2. * M_PI; +// if (phiMax < -M_PI) phiMax += 2. * M_PI; +// if (phiMax > M_PI) phiMax -= 2. * M_PI; + +// // Calculate rz = r (barrel) or z (endcap) +// // Use center of sensor ((0,0,0) in local coordinates) for determining this. +// // HepGeom::Point3D<double> globalCenter = globalPosition(HepGeom::Point3D<double>(0,0,0)); +// if (isBarrel()) { +// rz = center().perp(); // r +// } else { +// rz = center().z(); // z +// } + +// } + +// Gets eta phi for a point given in local coordinates. deltaZ is specified to +// account for the vertex spread. phi is independent of this vertex +// spread. etaMax will correspond to zMin (-deltaZ) and etaMin will +// correspond to zMax (+deltaZ). +// void ScintDetectorElement::getEtaPhiPoint(const HepGeom::Point3D<double> & point, double deltaZ, +// double &etaMin, double &etaMax, double &phi) const +// { +// // Get the point in global coordinates. +// HepGeom::Point3D<double> globalPoint = globalPosition(point); + +// double r = globalPoint.perp(); +// double z = globalPoint.z(); + +// double thetaMin = atan2(r,(z + deltaZ)); +// etaMax = -log(tan(0.5 * thetaMin)); +// double thetaMax = atan2(r,(z - deltaZ)); +// etaMin = -log(tan(0.5 * thetaMax)); + +// phi = globalPoint.phi(); +// } + +void ScintDetectorElement::getCorners(HepGeom::Point3D<double> *corners) const +{ + std::lock_guard<std::recursive_mutex> lock(m_mutex); + if (!m_cacheValid) updateCache(); + + // This makes the assumption that the forward SCT detectors are orientated such that + // the positive etaAxis corresponds to the top of the detector where the width is largest. + // This is currently always the case. + // For the SCT barrel and pixel detectors minWidth and maxWidth are the same and so should + // work for all orientations. + + // double minWidth = m_design->minWidth(); + // double maxWidth = m_design->maxWidth(); + double width = m_design->width(); + double length = m_design->length(); + + // Lower left + corners[0][distPhi] = -0.5 * width; + corners[0][distEta] = -0.5 * length; + corners[0][distDepth] = 0.; + + // Lower right + corners[1][distPhi] = 0.5 * width; + corners[1][distEta] = -0.5 * length; + corners[1][distDepth] = 0.; + + // Upper Right + corners[2][distPhi] = 0.5 * width; + corners[2][distEta] = 0.5 * length; + corners[2][distDepth] = 0.; + + // Upper left + corners[3][distPhi] = -0.5 * width; + corners[3][distEta] = 0.5 * length; + corners[3][distDepth] = 0.; +} + +ScintIntersect +ScintDetectorElement::inDetector(const Amg::Vector2D & localPosition, + double phiTol, double etaTol) const +{ + return m_design->inDetector(localPosition, phiTol, etaTol); +} + + +ScintIntersect +ScintDetectorElement::inDetector(const HepGeom::Point3D<double> & globalPosition, double phiTol, double etaTol) const +{ + return m_design->inDetector(localPosition(globalPosition), phiTol, etaTol); +} + +// bool +// ScintDetectorElement::nearBondGap(Amg::Vector2D localPosition, double etaTol) const +// { +// return m_design->nearBondGap(localPosition, etaTol); +// } + +// bool +// ScintDetectorElement::nearBondGap(HepGeom::Point3D<double> globalPosition, double etaTol) const +// { +// return m_design->nearBondGap(localPosition(globalPosition), etaTol); +// } + +// Amg::Vector2D +// ScintDetectorElement::rawLocalPositionOfCell(const SiCellId &cellId) const +// { +// return m_design->localPositionOfCell(cellId); +// } + +// Amg::Vector2D +// ScintDetectorElement::rawLocalPositionOfCell(const Identifier & id) const +// { +// SiCellId cellId = cellIdFromIdentifier(id); +// return m_design->localPositionOfCell(cellId); +// } + +// int +// ScintDetectorElement::numberOfConnectedCells(const SiCellId cellId) const +// { +// SiReadoutCellId readoutId = m_design->readoutIdOfCell(cellId); +// return m_design->numberOfConnectedCells(readoutId); +// } + +// SiCellId +// ScintDetectorElement::connectedCell(const SiCellId cellId, int number) const +// { +// SiReadoutCellId readoutId = m_design->readoutIdOfCell(cellId); +// return m_design->connectedCell(readoutId, number); +// } + + +// SiCellId +// ScintDetectorElement::cellIdOfPosition(const Amg::Vector2D &localPosition) const +// { +// return m_design->cellIdOfPosition(localPosition); +// } + +// Identifier +// ScintDetectorElement::identifierOfPosition(const Amg::Vector2D &localPosition) const +// { +// SiCellId cellId = m_design->cellIdOfPosition(localPosition); +// return identifierFromCellId(cellId); +// } + +// Identifier +// ScintDetectorElement::identifierFromCellId(const SiCellId & cellId) const +// { +// Identifier id; // Will be initialized in an invalid state. + +// // If something fails it returns the id in an invalid state. + +// if (cellId.isValid()) { + +// if (isPixel()) { +// const PixelID * pixelIdHelper = static_cast<const PixelID *>(getIdHelper()); +// if (pixelIdHelper) { +// id = pixelIdHelper->pixel_id(m_id, cellId.phiIndex(), cellId.etaIndex()); +// } +// } else { +// const SCT_ID * sctIdHelper = static_cast<const SCT_ID *>(getIdHelper()); +// if (sctIdHelper) { +// id = sctIdHelper->strip_id(m_id, cellId.strip()); +// } +// } +// } + +// return id; +// } + +// SiCellId +// ScintDetectorElement::cellIdFromIdentifier(const Identifier & identifier) const +// { +// SiCellId cellId; // Initialized in invalid state. + +// // If something fails it returns the cellId in an invalid state. + +// if (identifier.is_valid()) { + +// if (isPixel()) { +// const PixelID * pixelIdHelper = static_cast<const PixelID *>(getIdHelper()); +// if (pixelIdHelper) { +// cellId = SiCellId(pixelIdHelper->phi_index(identifier), pixelIdHelper->eta_index(identifier)); +// } +// } else { +// const SCT_ID * sctIdHelper = static_cast<const SCT_ID *>(getIdHelper()); +// if (sctIdHelper) { +// cellId = SiCellId(sctIdHelper->strip(identifier)); +// } +// } +// } + +// return cellId; +// } + +} // namespace ScintDD diff --git a/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/ScintDetectorElementCollection.cxx b/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/ScintDetectorElementCollection.cxx new file mode 100644 index 0000000000000000000000000000000000000000..f53c163e2efbb2fe762b3f4f020063dbdb95b9d8 --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/ScintDetectorElementCollection.cxx @@ -0,0 +1,19 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + +#include "ScintReadoutGeometry/ScintDetectorElementCollection.h" + +#include "ScintReadoutGeometry/ScintDetectorElement.h" +#include "Identifier/IdentifierHash.h" + +ScintDD::ScintDetectorElementCollection::~ScintDetectorElementCollection() { + for (ScintDD::ScintDetectorElement* ele: *this) delete ele; +} + +const ScintDD::ScintDetectorElement* +ScintDD::ScintDetectorElementCollection::getDetectorElement(const IdentifierHash& hash) const { + const unsigned int value{hash.value()}; + if (this->size()<=value) return nullptr; + return this->at(value); +} diff --git a/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/ScintDetectorManager.cxx b/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/ScintDetectorManager.cxx new file mode 100644 index 0000000000000000000000000000000000000000..4e4c5229c4c0f48eb0be1581e15368712825e674 --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/ScintDetectorManager.cxx @@ -0,0 +1,149 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + + +#include "GeoPrimitives/CLHEPtoEigenConverter.h" + +#include "ScintReadoutGeometry/ScintDetectorManager.h" +#include "FaserDetDescr/FaserDetectorID.h" +#include "IdDictDetDescr/IdDictManager.h" +#include "StoreGate/StoreGateSvc.h" + +#include "GeoModelKernel/GeoXF.h" +#include "GeoGenericFunctions/Variable.h" +#include "GeoModelKernel/GeoAlignableTransform.h" +#include "DetDescrConditions/AlignableTransformContainer.h" +#include "ScintReadoutGeometry/ScintDetectorElementCollection.h" +#include "ScintReadoutGeometry/ScintDetectorElement.h" +#include "ScintReadoutGeometry/ExtendedAlignableTransform.h" + +#include <iostream> + +namespace ScintDD +{ + + ScintDetectorManager::ScintDetectorManager(StoreGateSvc * detStore, const std::string & name) + : ScintDetectorManagerBase(detStore, name) + { + // Add default folder + addFolder("/Scint/Align"); + } + + const std::string& ScintDetectorManager::tag() const + { + return m_tag; + } + + void ScintDetectorManager::invalidateAll() const + { + for (ScintDetectorElementCollection::const_iterator element_iter = getDetectorElementBegin(); + element_iter != getDetectorElementEnd(); + ++element_iter) { + + if (*element_iter) { + (*element_iter)->invalidate(); + } + } + } + + void ScintDetectorManager::updateAll() const + { + for (ScintDetectorElementCollection::const_iterator element_iter = getDetectorElementBegin(); + element_iter != getDetectorElementEnd(); + ++element_iter) { + if (*element_iter) { + (*element_iter)->setAllCaches(); + } + } + } + + bool ScintDetectorManager::setAlignableTransformLocalDelta(ExtendedAlignableTransform * extXF, + const Amg::Transform3D & localToGlobalXF, + const Amg::Transform3D & delta, + GeoVAlignmentStore* alignStore) const + { + // ATTENTION -------------------------------------------------------- (A.S.) + // CLHEP < -- > AMG interface method + + // Sets the alignable transform delta when the supplied delta is in the local + // reconstruction frame + + // If the default transform to the local recostruction frame is + // T = A*B*C*D*E + // and the alignable transform is C with delta c and the delat in the local frame is l, then + // A*B*C*c*D*E = A*B*C*D*E*l + // c = (D*E) * l * (D*E).inverse() + // c = (A*B*C).inverse * T * l * T.inverse() * (A*B*C) + + // To get default transform up and including the alignable transform, + // we assume the next volume down is a fullphys volume and so its + // transform is the transform we want (ie A*B*C in the above example). + + if (!extXF) return false; + + const GeoVFullPhysVol* child = extXF->child(); + if (child && extXF->alignableTransform()) { + // the definitiv absolut transform is in CLHEP -> do the calculation in CLHEP + const GeoTrf::Transform3D& transform = child->getDefAbsoluteTransform(alignStore); + // calucluate the corrected delta according to the formula above + GeoTrf::Transform3D correctedDelta = transform.inverse()*localToGlobalXF // (A*B*C).inverse() * T + * delta // l + * localToGlobalXF.inverse() * transform; // T.inverse() * (A*B*C) + extXF->alignableTransform()->setDelta(correctedDelta, alignStore); + return true; + } else { + return false; + } + } + + bool ScintDetectorManager::setAlignableTransformGlobalDelta(ExtendedAlignableTransform * extXF, + const Amg::Transform3D& delta, + GeoVAlignmentStore* alignStore) const { + // ATTENTION -------------------------------------------------------- (A.S.) + // CLHEP < -- > AMG interface method + + // Sets the alignable transform delta when the supplied delta is in the global frame. + + // If the default transform down to the alignable transform is + // T = A*B*C + // and the alignable transform is C with delta c and the delta in the global frame is g, then + // A*B*C*c = g*A*B*C + // T*c = g*T + // c = T.inverse() * g * T + + // To get default transform up and including the alignable transform, + // we assume the next volume down is a fullphys volume and so its + // transform is the transform we want (ie T=A*B*C in the above example). + + + if (!extXF) return false; + + const GeoVFullPhysVol * child = extXF->child(); + if (child && extXF->alignableTransform()) { + // do the calculation in CLHEP + const GeoTrf::Transform3D& transform = child->getDefAbsoluteTransform(alignStore); + extXF->alignableTransform()->setDelta(transform.inverse() * delta * transform, alignStore); + return true; + } else { + return false; + } + } + + void ScintDetectorManager::addDesign(const ScintDetectorDesign * design) + { + m_designs.push_back(design); + } + + int ScintDetectorManager::numDesigns() const + { + return m_designs.size(); + } + + + const ScintDetectorDesign* ScintDetectorManager::getDesign(int i) const + { + return m_designs[i]; + } + +}// namespace ScintDD diff --git a/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/ScintDetectorManagerBase.cxx b/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/ScintDetectorManagerBase.cxx new file mode 100644 index 0000000000000000000000000000000000000000..43d4fb3f3bf5a4ce453de1bba59ca23b393314e5 --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/ScintDetectorManagerBase.cxx @@ -0,0 +1,424 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + + +#include "ScintReadoutGeometry/ScintDetectorManagerBase.h" + +#include "StoreGate/StoreGateSvc.h" +#include "DetDescrConditions/AlignableTransform.h" +#include "FaserDetDescr/FaserDetectorID.h" +#include "GeoPrimitives/CLHEPtoEigenConverter.h" +#include "AthenaPoolUtilities/CondAttrListCollection.h" +#include "AthenaBaseComps/AthMsgStreamMacros.h" + +#include <map> + +namespace ScintDD +{ + + ScintDetectorManagerBase::ScintDetectorManagerBase(StoreGateSvc * detStore, const std::string & name) + : m_alignfoldertype{none},m_detStore(detStore), + m_msg(name+"DetectorManager") + { + setName(name); + } + + // Destructor + ScintDetectorManagerBase::~ScintDetectorManagerBase() + {} + + + const Version& ScintDetectorManagerBase::getVersion() const + { + return m_version; + } + + const std::string& ScintDetectorManagerBase::getLayout() const + { + return m_version.layout(); + } + + void ScintDetectorManagerBase::setVersion(const Version & version) + { + m_version = version; + } + + void ScintDetectorManagerBase::addChannel(const std::string & key, int level, FrameType frame) + { + std::string frameStr = "other"; + if (frame == ScintDD::global) frameStr = "global"; + if (frame == ScintDD::local) frameStr = "local"; + ATH_MSG_INFO("Registering alignment channel with key " << key << ", level " << level + << ", with frame " << frameStr << "."); + m_keys[key] = LevelInfo(level, frame); + } + + void ScintDetectorManagerBase::addFolder(const std::string & key) + { + m_folders.insert(key); + } + + void ScintDetectorManagerBase::addSpecialFolder(const std::string & key) + { + m_specialFolders.insert(key); + } + + void ScintDetectorManagerBase::addGlobalFolder(const std::string & key) + { + m_globalFolders.insert(key); + } + + void ScintDetectorManagerBase::addAlignFolderType(const AlignFolderType alignfolder) + { + m_alignfoldertype = alignfolder; + } + + // Return the level in the hierarchy (user defined) corresponding to the key. + const ScintDetectorManagerBase::LevelInfo& ScintDetectorManagerBase::getLevel(const std::string & key) const + { + std::map<std::string, LevelInfo>::const_iterator iter; + iter = m_keys.find(key); + if (iter == m_keys.end()) return s_invalidLevel; + return iter->second; + } + + StatusCode ScintDetectorManagerBase::align( IOVSVC_CALLBACK_ARGS_P(I,keys) ) const + { + + (void) I; // avoid warning about unused parameter + + ATH_MSG_DEBUG("AlignmentCallback called "); + + if (!getIdHelper()) return StatusCode::SUCCESS; + + bool alignmentChange = false; + const AlignInfo &aligninfo = AlignInfo(m_alignfoldertype); + + // If dummy arguments + if (keys.empty()) { + + + // New global aligment folders should be processed first + for (std::set<std::string>::const_iterator iterFolders = m_globalFolders.begin(); + iterFolders != m_globalFolders.end(); + ++iterFolders) { + + try { + bool status = processGlobalAlignmentContainer(*iterFolders); + alignmentChange = (alignmentChange || status); + } catch(std::runtime_error& err) { + // keys are empty when running simualtion. It is normal for detector specific aligments not to exist. + ATH_MSG_FATAL(err.what()); + return StatusCode::FAILURE; + } + } + + // Regular alignments. Loop through folder keys. Normally only one. + for (std::set<std::string>::const_iterator iterFolders = m_folders.begin(); + iterFolders != m_folders.end(); + ++iterFolders) { + + try { + bool status = processAlignmentContainer(*iterFolders); + alignmentChange = (alignmentChange || status); + } + catch(std::runtime_error& err) { + // alignments should always exist so we return fatal if we could not process the alignment for this key + ATH_MSG_FATAL(err.what()); + return StatusCode::FAILURE; + } + } + // Detector specific aligments + for (std::set<std::string>::const_iterator iterFolders = m_specialFolders.begin(); + iterFolders != m_specialFolders.end(); + ++iterFolders) { + try { + bool status = processSpecialAlignment(*iterFolders, aligninfo.AlignFolder()); + alignmentChange = (alignmentChange || status); + } catch(std::runtime_error& err) { + // keys are empty when running simualtion. It is normal for detector specific aligments not to exist. + ATH_MSG_INFO(err.what()); + // We continue as detector specific aligments don't always exist. + } + } + + } else { + // Loop over all the keys. + for (std::list<std::string>::const_iterator itr=keys.begin(); itr!=keys.end(); ++itr) { + + const std::string & key = *itr; + + ATH_MSG_DEBUG(" Processing call back key " << key); + + if ( m_globalFolders.find(key) != m_globalFolders.end() ) { + + try { + // New global alignemnts + bool status = processGlobalAlignmentContainer(key); + alignmentChange = (alignmentChange || status); + } catch(std::runtime_error& err) { + // alignments should always exist so we return fatal if we could not process the alignment for this key + ATH_MSG_FATAL(err.what()); + return StatusCode::FAILURE; + } + + } else if ( m_folders.find(key) != m_folders.end() ) { + + try { + // Regular alignemnts + bool status = processAlignmentContainer(key); + alignmentChange = (alignmentChange || status); + } catch(std::runtime_error& err) { + // alignments should always exist so we return fatal if we could not process the alignment for this key + ATH_MSG_FATAL(err.what()); + return StatusCode::FAILURE; + } + + } else if ( m_specialFolders.find(key) != m_specialFolders.end() ) { + try { + // Detector specific alignments + bool status = processSpecialAlignment(key, aligninfo.AlignFolder()); + alignmentChange = (alignmentChange || status); + } + catch(std::runtime_error& err) { + // Should always exist if the folder was requested so we return fatal if we could not process the alignment for this key + ATH_MSG_FATAL(err.what()); + return StatusCode::FAILURE; + } + } else { + // Should not be any other keys specified in call back. + ATH_MSG_ERROR("Unrecognized key in call back."); + return StatusCode::RECOVERABLE; + } + } + } + + // We invalidate all the elements if at least one alignment changed. + if (alignmentChange) { + invalidateAll(); + } + + return StatusCode::SUCCESS; + } + + StatusCode ScintDetectorManagerBase::align(const RawAlignmentObjects& alignObjects, GeoVAlignmentStore* alignStore) const + { + + ATH_MSG_DEBUG("align() called from an alignment CondAlg"); + if (!getIdHelper()) return StatusCode::SUCCESS; // To Do: is it really a success? + + bool alignmentChange = false; + // const AlignInfo &aligninfo = AlignInfo(m_alignfoldertype); + + for(const auto& alignObj : alignObjects) { + const std::string& key = alignObj.first; + + ATH_MSG_DEBUG(" Processing folder " << key); + + if(m_globalFolders.find(key)!=m_globalFolders.end()) { + try { + // New global alignemnts + const CondAttrListCollection* obj = static_cast<const CondAttrListCollection*>(alignObj.second); + bool status = processGlobalAlignmentContainer(key,obj,alignStore); + alignmentChange = (alignmentChange || status); + } catch(std::runtime_error& err) { + // alignments should always exist so we return fatal if we could not process the alignment for this key + ATH_MSG_FATAL(err.what()); + return StatusCode::FAILURE; + } + } + else if(m_folders.find(key)!=m_folders.end()) { + try { + // Regular alignemnts + const AlignableTransformContainer* container = static_cast<const AlignableTransformContainer*>(alignObj.second); + bool status = processAlignmentContainer(container,alignStore); + alignmentChange = (alignmentChange || status); + } catch(std::runtime_error& err) { + // alignments should always exist so we return fatal if we could not process the alignment for this key + ATH_MSG_FATAL(err.what()); + return StatusCode::FAILURE; + } + } + else if(m_specialFolders.find(key)!=m_specialFolders.end()) { + try { + // Detector specific alignments + const CondAttrListCollection *obj = + static_cast<const CondAttrListCollection*>(alignObj.second); + bool status = processSpecialAlignment(key, obj, alignStore); + alignmentChange = (alignmentChange || status); + } + catch(std::runtime_error& err) { + // Should always exist if the folder was requested so we return fatal if + // we could not process the alignment for this key + ATH_MSG_FATAL(err.what()); + return StatusCode::FAILURE; + } + } + else { + // Should not be any other keys specified in raw alignment object. + ATH_MSG_ERROR("Unrecognized folder name."); + return StatusCode::RECOVERABLE; + } + } + // To Do: custom caching is not going to work in MT + /* + if(alignmentChange) invalidateAll(); + */ + + return StatusCode::SUCCESS; + } + + bool ScintDetectorManagerBase::processAlignmentContainer(const std::string & key) const + { + bool alignmentChange = false; + + ATH_MSG_DEBUG("Dealing with key as container"); + const AlignableTransformContainer* container; + if (StatusCode::SUCCESS!=m_detStore->retrieve(container, key)) { + ATH_MSG_ERROR("Cannot find AlignableTransformContainer for key " + << key << " - no misalignment"); + // This should not occur in normal situations so we force job to abort. + throw std::runtime_error("Unable to apply Scintillator alignments"); + } + // Check if container is empty - this can occur if it is an invalid IOV. + if (container->empty()) { + ATH_MSG_ERROR("AlignableTransformContainer for key " + << key << " is empty. Probably due to out of range IOV"); + // This should not occur in normal situations so we force job to abort. + throw std::runtime_error("Unable to apply Scintillator alignments."); + } + // loop over all the AlignableTransform objects in the collection + for (DataVector<AlignableTransform>::const_iterator pat=container->begin(); + pat!=container->end();++pat) { + + bool status = processKey((*pat)->tag(),*pat); + alignmentChange = (alignmentChange || status); + } + return alignmentChange; + } + + bool ScintDetectorManagerBase::processAlignmentContainer(const AlignableTransformContainer* container, GeoVAlignmentStore* alignStore) const + { + bool alignmentChange = false; + + // Check if container is empty - this can occur if it is an invalid IOV. + if (container->empty()) { + ATH_MSG_ERROR("AlignableTransformContainer " + << " is empty. Probably due to out of range IOV"); // To Do: add key to this printout for making it more informative + // This should not occur in normal situations so we force job to abort. + throw std::runtime_error("Unable to apply Scintillator alignments."); + } + // loop over all the AlignableTransform objects in the collection + // use only the last ones. + std::map<const std::string, const AlignableTransform*> stringToTransform; + for (DataVector<AlignableTransform>::const_iterator pat=container->begin(); + pat!=container->end();++pat) { + stringToTransform[(*pat)->tag()] = *pat; + } + for (std::pair<const std::string, const AlignableTransform*> value: stringToTransform) { + bool status = processKey(value.first, value.second, alignStore); + alignmentChange = (alignmentChange || status); + } + return alignmentChange; + } + + bool ScintDetectorManagerBase::processKey(const std::string key, + const AlignableTransform* transformCollection, + GeoVAlignmentStore* alignStore) const + { + bool alignmentChange = false; + + // From the key determine what level in hierarchy we are dealing with. + // returns -1 if unrecognized. + const LevelInfo & levelInfo = getLevel(key); + if (levelInfo.isValid()) { + ATH_MSG_VERBOSE("Processing channel: " << key); + } else { + ATH_MSG_DEBUG("Channel " << key << " not registered in this manager"); + } + // return silently if unrecognised - this can happen in container mode + // when a single container holds transforms for both pixel and SCT + if (!levelInfo.isValid() ) return false; + + //Loop over the effected nodes. + for (AlignableTransform::AlignTransMem_citr trans_iter = transformCollection->begin(); + trans_iter != transformCollection->end(); + ++trans_iter) { + ATH_MSG_DEBUG( "Get alignment for identifier " + << getIdHelper()->show_to_string(trans_iter->identify()) + << " at level " << levelInfo.level()); + + // The delta in the conditions DB is not necessarily the same as what is needed in the + // alignable transform. At the moment we support global frame, local frame or an alternative frame + // The setAlignableTransformDelta method takes care of this correction - this is CLHEP <--> Amg interfaced + bool status = setAlignableTransformDelta(levelInfo.level(), + trans_iter->identify(), + Amg::CLHEPTransformToEigen(trans_iter->transform()), + levelInfo.frame(), + alignStore); + + alignmentChange = (alignmentChange || status); + + if (!status) { + if (!identifierBelongs(trans_iter->identify())) { + ATH_MSG_DEBUG("Cannot set AlignableTransform for identifier." + << getIdHelper()->show_to_string(trans_iter->identify()) + << " at level " << levelInfo.level()); + } else { + ATH_MSG_WARNING("Cannot set AlignableTransform for identifier " + << getIdHelper()->show_to_string(trans_iter->identify()) + << " at level " << levelInfo.level()); + ATH_MSG_WARNING("Subsequent WARNINGS will be printed at DEBUG level."); + } + } + } + return alignmentChange; + } + + // We provide a default implementation of any detector specific alignment. + bool ScintDetectorManagerBase::processGlobalAlignmentContainer(const std::string & key, + const CondAttrListCollection* obj, + GeoVAlignmentStore* alignStore) const + { + bool alignmentChange = false; + + ATH_MSG_DEBUG("processing GlobalAlignmentContainer with key: " << key); + // From the key determine what level in hierarchy we are dealing with. + // returns -1 if unrecognized. + const LevelInfo & levelInfo = getLevel(key); + if (levelInfo.isValid()) { + ATH_MSG_VERBOSE("Processing channel: " << key); + } else { + ATH_MSG_DEBUG("Channel " << key << " not registered in this manager"); + } + // return silently if unrecognised - this can happen in container mode + // when a single container holds transforms for both pixel and SCT + if (!levelInfo.isValid() ) return false; + + // Within detector specific code + bool status = processGlobalAlignment(key, levelInfo.level(), levelInfo.frame(), obj, alignStore); + + alignmentChange = (alignmentChange || status); + + return alignmentChange; + + } + + // We provide a default implementation of any detector specific alignment. + bool ScintDetectorManagerBase::processGlobalAlignment(const std::string &, int /*level*/, FrameType /*frame*/, + const CondAttrListCollection* /*obj*/, GeoVAlignmentStore* /*alignStore*/) const + { + return false; + } + + + // We provide a default implementation of any detector specific alignment. + bool ScintDetectorManagerBase::processSpecialAlignment(const std::string &, ScintDD::AlignFolderType) const + { + return false; + } + + const ScintDetectorManagerBase::LevelInfo ScintDetectorManagerBase::s_invalidLevel; + +} // namespace ScintDD diff --git a/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/ScintLocalPosition.cxx b/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/ScintLocalPosition.cxx new file mode 100644 index 0000000000000000000000000000000000000000..0de06fe74cbabc17c08e28f6f5d6fb20a69d5228 --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/ScintLocalPosition.cxx @@ -0,0 +1,100 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/////////////////////////////////////////////////////////////////// +// ScintLocalPosition.cxx +// Implementation file for class ScintLocalPosition +/////////////////////////////////////////////////////////////////// +// (c) ATLAS Detector software +/////////////////////////////////////////////////////////////////// +// Version 2.1 01/08/2001 David Calvet +/////////////////////////////////////////////////////////////////// + +#include "ScintReadoutGeometry/ScintLocalPosition.h" + +namespace ScintDD { + +// Default constructor: +ScintLocalPosition::ScintLocalPosition() : + m_x(0), + m_y(0), + m_xDepth(0) +{} + + + +// Constructor with parameters: +ScintLocalPosition::ScintLocalPosition(const double x,const double y, + const double xDepth) : + m_x(x), + m_y(y), + m_xDepth(xDepth) +{} + +ScintLocalPosition::ScintLocalPosition(const Amg::Vector2D &position) + : m_x(position[Trk::locX]), + m_y(position[Trk::locY]), + m_xDepth(0) +{} + + +ScintLocalPosition::operator Amg::Vector2D(void) const +{ + return Amg::Vector2D(m_x, m_y); +} + + + +// addition of positions: +ScintLocalPosition &ScintLocalPosition::operator+=(const ScintLocalPosition &position) +{ + m_x+=position.m_x; + m_y+=position.m_y; + m_xDepth+=position.m_xDepth; + return *this; +} + +// scaling: +ScintLocalPosition &ScintLocalPosition::operator*=(const double factor) +{ + m_x*=factor; + m_y*=factor; + m_xDepth*=factor; + return *this; +} + +// scaling: +ScintLocalPosition &ScintLocalPosition::operator/=(const double factor) +{ + if (0!=factor) { + m_x/=factor; + m_y/=factor; + m_xDepth/=factor; + } else {} + return *this; +} + +ScintLocalPosition operator+(const ScintLocalPosition &position1, + const ScintLocalPosition &position2) +{ + ScintLocalPosition result(position1); + result+=position2; + return result; +} + +ScintLocalPosition operator*(const ScintLocalPosition &position,const double factor) +{ + ScintLocalPosition result(position); + result*=factor; + return result; +} + +ScintLocalPosition operator/(const ScintLocalPosition &position,const double factor) +{ + ScintLocalPosition result(position); + result/=factor; + return result; +} + +} // namespace InDetDD diff --git a/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/ScintNumerology.cxx b/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/ScintNumerology.cxx new file mode 100644 index 0000000000000000000000000000000000000000..7f52d17ad56021b5f755d0ea65e4f06e3259c192 --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/ScintNumerology.cxx @@ -0,0 +1,37 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "ScintReadoutGeometry/ScintNumerology.h" + + +namespace ScintDD { + +ScintNumerology::ScintNumerology() + : m_numStations(0), + m_maxNumStationPlates(0), + m_maxNumPlatePmts(0) +{} + + +void ScintNumerology::setNumStations(int nStations) +{ + m_platesForStation.resize(nStations); + m_numStations = nStations; +} + +void ScintNumerology::setNumPlatesForStation(int station, int nPlates) +{ + m_platesForStation[station] = nPlates; + m_pmtsForPlate[station].resize(nPlates); + m_maxNumStationPlates = std::max(m_maxNumStationPlates, nPlates); +} + +void ScintNumerology::setNumPmtsForPlate(int station, int plate, int nPmts) +{ + m_pmtsForPlate[station][plate] = nPmts; + m_maxNumPlatePmts = std::max(m_maxNumPlatePmts, nPmts); +} + + +} // End namespace diff --git a/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/Version.cxx b/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/Version.cxx new file mode 100644 index 0000000000000000000000000000000000000000..64751aca5cc70cac95faaee9a4516a619157271b --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/Version.cxx @@ -0,0 +1,121 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "ScintReadoutGeometry/Version.h" + +#include <sstream> +#include <string> +#include <iomanip> + +namespace ScintDD { + +Version::Version(const std::string & tag, + const std::string & name, + const std::string & layout, + const std::string & description, + int major, + int minor, + int patch) + : m_tag(tag), + m_name(name), + m_layout(layout), + m_description(description), + m_major(major), + m_minor(minor), + m_patch(patch) +{} + +// For backward compatibility +Version::Version(const std::string & name, + const std::string & layout, + const std::string & description, + int major, + int minor, + int patch) + : m_tag("-"), + m_name(name), + m_layout(layout), + m_description(description), + m_major(major), + m_minor(minor), + m_patch(patch) +{} + + + +Version::Version() + : m_major(0), + m_minor(0), + m_patch(0) +{} + +const std::string & +Version::tag() const +{ + return m_tag; +} + +const std::string & +Version::name() const +{ + return m_name; +} + +const std::string & +Version::layout() const +{ + return m_layout; +} + +const std::string & +Version::description() const +{ + return m_description; +} + +int +Version::majorNum() const +{ + return m_major; +} + +int +Version::minorNum() const +{ + return m_minor; +} + +int +Version::patchNum() const +{ + return m_patch; +} + +std::string +Version::versionNumber() const +{ + std::ostringstream ostr; + ostr << m_major + << "." << std::setfill('0') << std::setw(2) << m_minor + << "." << std::setfill('0') << std::setw(2) << m_patch; + return ostr.str(); +} + +std::string +Version::fullDescription() const +{ + + // Output of the form + // Version: SCT-DC1-00, Name: DC1, Layout: Final, Code Version: 02.01.01, Description: DC1 Geometry + + std::ostringstream ostr; + ostr << "Version: " << m_tag << ", Name: " << m_name << ", Layout: " << m_layout + << ", Code Version: " << versionNumber(); + if (!m_description.empty()) { + ostr << ", Description: " << m_description; + } + return ostr.str(); +} + +} // namespace ScintDD diff --git a/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/VetoDetectorManager.cxx b/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/VetoDetectorManager.cxx new file mode 100644 index 0000000000000000000000000000000000000000..a5f61b013464fce434f8e869a9e2b4c890c3e6d9 --- /dev/null +++ b/Scintillator/ScintDetDescr/ScintReadoutGeometry/src/VetoDetectorManager.cxx @@ -0,0 +1,407 @@ +/* + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration +*/ + +#include "ScintReadoutGeometry/VetoDetectorManager.h" + +#include "AthenaBaseComps/AthMsgStreamMacros.h" +#include "AthenaPoolUtilities/CondAttrListCollection.h" +#include "GeoPrimitives/CLHEPtoEigenConverter.h" +#include "Identifier/Identifier.h" +#include "Identifier/IdentifierHash.h" +#include "ScintIdentifier/VetoID.h" +#include "ScintReadoutGeometry/ScintDetectorElementCollection.h" +#include "ScintReadoutGeometry/ScintDetectorElement.h" +#include "ScintReadoutGeometry/ExtendedAlignableTransform.h" +#include "ScintReadoutGeometry/ScintDetectorDesign.h" +#include "StoreGate/StoreGateSvc.h" + +#include <iostream> + +namespace ScintDD { + + const int FIRST_HIGHER_LEVEL = 2; + + VetoDetectorManager::VetoDetectorManager( StoreGateSvc* detStore ) + : ScintDetectorManager(detStore, "Veto"), + m_idHelper(0), + m_isLogical(false) // Change to true to change the definition of local module corrections + { + // + // Initialized the Identifier helper. + // + StatusCode sc = detStore->retrieve(m_idHelper, "VetoID"); + if (sc.isFailure()) { + ATH_MSG_ERROR("Could not retrieve Veto id helper"); + } + // Initialize the collections. + if (m_idHelper) { + m_elementCollection.resize(m_idHelper->plate_hash_max()); + m_alignableTransforms.resize(m_idHelper->plate_hash_max()); + m_moduleAlignableTransforms.resize(m_idHelper->plate_hash_max()); + } + } + + + + VetoDetectorManager::~VetoDetectorManager() + { + // Clean up + for (size_t i=0; i < m_volume.size(); i++) { + m_volume[i]->unref(); + } + + for (size_t j=0; j < m_higherAlignableTransforms.size(); j++){ + AlignableTransformMap::iterator iterMap; + for (iterMap = m_higherAlignableTransforms[j].begin(); + iterMap != m_higherAlignableTransforms[j].end(); + ++iterMap) { + delete iterMap->second; + } + } + + for (size_t k=0; k < m_alignableTransforms.size(); k++){ + delete m_alignableTransforms[k]; + } + + for (size_t l=0; l < m_moduleAlignableTransforms.size(); l++){ + delete m_moduleAlignableTransforms[l]; + } + } + + unsigned int VetoDetectorManager::getNumTreeTops() const + { + return m_volume.size(); + } + + PVConstLink VetoDetectorManager::getTreeTop(unsigned int i) const + { + return m_volume[i]; + } + + void VetoDetectorManager::addTreeTop(PVLink vol){ + vol->ref(); + m_volume.push_back(vol); + } + + + ScintDetectorElement* VetoDetectorManager::getDetectorElement(const Identifier & id) const + { + // NB the id helpers implementation for getting a hash is not optimal. + // Essentially does a binary search. + // Make sure it is a wafer Id + Identifier waferId = m_idHelper->plate_id(id); + IdentifierHash idHash = m_idHelper->plate_hash(waferId); + if (idHash.is_valid()) { + return m_elementCollection[idHash]; + } else { + return 0; + } + } + + ScintDetectorElement* VetoDetectorManager::getDetectorElement(const IdentifierHash & idHash) const + { + return m_elementCollection[idHash]; + } + + ScintDetectorElement* VetoDetectorManager::getDetectorElement(int station, int plate) const + { + return getDetectorElement(m_idHelper->plate_id(station, plate)); + } + + const ScintDetectorElementCollection* VetoDetectorManager::getDetectorElementCollection() const + { + return &m_elementCollection; + } + + ScintDetectorElementCollection::const_iterator VetoDetectorManager::getDetectorElementBegin() const + { + return m_elementCollection.begin(); + } + + ScintDetectorElementCollection::const_iterator VetoDetectorManager::getDetectorElementEnd() const + { + return m_elementCollection.end(); + } + + + void VetoDetectorManager::addDetectorElement(ScintDetectorElement * element) + { + IdentifierHash idHash = element->identifyHash(); + if (idHash >= m_elementCollection.size()) + throw std::runtime_error("VetoDetectorManager: Error adding detector element."); + m_elementCollection[idHash] = element; + } + + void VetoDetectorManager::initNeighbours() + { + // ScintDetectorElementCollection::iterator iter; + + // // Loop over all elements and set the neighbours + // for (iter = m_elementCollection.begin(); iter != m_elementCollection.end(); ++iter){ + + // ScintDetectorElement * element = *iter; + // if (element) { + + // IdentifierHash idHash = element->identifyHash(); + // IdentifierHash idHashOther; + + // int result; + // // If no neighbour, result != 0 in which case we leave neighbour as null + // result = m_idHelper->get_next_in_eta(idHash, idHashOther); + // if (result==0) element->setNextInEta(m_elementCollection[idHashOther]); + + // result = m_idHelper->get_prev_in_eta(idHash, idHashOther); + // if (result==0) element->setPrevInEta(m_elementCollection[idHashOther]); + + // result = m_idHelper->get_next_in_phi(idHash, idHashOther); + // if (result==0) element->setNextInPhi(m_elementCollection[idHashOther]); + + // result = m_idHelper->get_prev_in_phi(idHash, idHashOther); + // if (result==0) element->setPrevInPhi(m_elementCollection[idHashOther]); + + // result = m_idHelper->get_other_side(idHash, idHashOther); + // if (result==0) element->setOtherSide(m_elementCollection[idHashOther]); + // } + // } + } + + + const VetoID* VetoDetectorManager::getIdHelper() const + { + return m_idHelper; + } + + + bool VetoDetectorManager::setAlignableTransformDelta(int level, + const Identifier & id, + const Amg::Transform3D & delta, + FrameType frame, + GeoVAlignmentStore* alignStore) const + { + + if (level == 0) { // 0 - At the element level + + // We retrieve it via a hashId. + IdentifierHash idHash = m_idHelper->plate_hash(id); + if (!idHash.is_valid()) return false; + + if (frame == ScintDD::global) { // global shift + // Its a global transform + return setAlignableTransformGlobalDelta(m_alignableTransforms[idHash], delta, alignStore); + + } else if (frame == ScintDD::local) { // local shift + + ScintDetectorElement * element = m_elementCollection[idHash]; + if (!element) return false; + + + // Its a local transform + //See header file for definition of m_isLogical + if( m_isLogical ){ + //Ensure cache is up to date and use the alignment corrected local to global transform + element->setCache(); + return setAlignableTransformLocalDelta(m_alignableTransforms[idHash], element->transform(), delta, alignStore); + } else + //Use default local to global transform + return setAlignableTransformLocalDelta(m_alignableTransforms[idHash], element->defTransform(), delta, alignStore); + + } else { + // other not supported + ATH_MSG_WARNING("Frames other than global or local are not supported."); + return false; + } + + } else if (level == 1) { // module level + + // We retrieve it via a hashId. + IdentifierHash idHash = m_idHelper->plate_hash(id); + if (!idHash.is_valid()) return false; + + int idModuleHash = idHash; + // int idModuleHash = idHash / 2; + + // if (idHash%2) { + // ATH_MSG_WARNING("Side 1 wafer id used for module id"); + // return false; + // } + + if (frame == ScintDD::global) { // global shift + // Its a global transform + return setAlignableTransformGlobalDelta(m_moduleAlignableTransforms[idModuleHash], delta, alignStore); + } else if (frame == ScintDD::local) { // local shift + ScintDetectorElement * element = m_elementCollection[idHash]; + if (!element) return false; + + // Its a local transform + //See header file for definition of m_isLogical + if( m_isLogical ){ + //Ensure cache is up to date and use the alignment corrected local to global transform + element->setCache(); + return setAlignableTransformLocalDelta(m_moduleAlignableTransforms[idModuleHash], element->plateTransform(), delta, alignStore); + } else + //Use default local to global transform + return setAlignableTransformLocalDelta(m_moduleAlignableTransforms[idModuleHash],element->defPlateTransform(), delta, alignStore); + + } else { + // other not supported + ATH_MSG_WARNING("Frames other than global or local are not supported."); + return false; + } + + } else { // higher level + + if (frame != ScintDD::global) { + ATH_MSG_WARNING("Non global shift at higher levels is not supported."); + return false; + } + + int index = level - FIRST_HIGHER_LEVEL; // level 0 and 1 is treated separately. + if (index >= static_cast<int>(m_higherAlignableTransforms.size())) return false; + + // We retrieve it from a map. + AlignableTransformMap::const_iterator iter; + iter = m_higherAlignableTransforms[index].find(id); + if (iter == m_higherAlignableTransforms[index].end()) return false; + + // Its a global transform + return setAlignableTransformGlobalDelta(iter->second, delta, alignStore); + } + + } + + void VetoDetectorManager::addAlignableTransform (int level, + const Identifier & id, + GeoAlignableTransform *transform, + const GeoVPhysVol * child) + { + if (m_idHelper) { + + const GeoVFullPhysVol * childFPV = dynamic_cast<const GeoVFullPhysVol *>(child); + if (!childFPV) { + ATH_MSG_ERROR("Child of alignable transform is not a full physical volume"); + } else { + addAlignableTransform (level, id, transform, childFPV); + } + } + } + + void VetoDetectorManager::addAlignableTransform (int level, + const Identifier & id, + GeoAlignableTransform *transform, + const GeoVFullPhysVol * child) + { + if (m_idHelper) { + if (level == 0) { + // Element + IdentifierHash idHash = m_idHelper->plate_hash(id); + if (idHash.is_valid()) { + m_alignableTransforms[idHash]= new ExtendedAlignableTransform(transform, child); + } + } else if (level == 1) { + // Module + IdentifierHash idHash = m_idHelper->plate_hash(id); + if (idHash.is_valid()) { + // m_moduleAlignableTransforms[idHash/2]=new ExtendedAlignableTransform(transform, child); + m_moduleAlignableTransforms[idHash]=new ExtendedAlignableTransform(transform, child); + } + + } else { + + // Higher levels are saved in a map. NB level=0,1 is treated above. + int index = level - FIRST_HIGHER_LEVEL; // level 0 and 1 is treated separately. + if (index >= static_cast<int>(m_higherAlignableTransforms.size())) m_higherAlignableTransforms.resize(index+1); + m_higherAlignableTransforms[index][id] = new ExtendedAlignableTransform(transform, child); + } + } + } + + bool + VetoDetectorManager::identifierBelongs(const Identifier & id) const + { + return getIdHelper()->is_veto(id); + } + + + const ScintDetectorDesign* VetoDetectorManager::getVetoDesign(int i) const + { + return dynamic_cast<const ScintDetectorDesign *>(getDesign(i)); + } + + // New global alignment folders + bool VetoDetectorManager::processGlobalAlignment(const std::string & key, int level, FrameType frame, + const CondAttrListCollection* obj, GeoVAlignmentStore* alignStore) const + { + ATH_MSG_INFO("Processing new global alignment containers with key " << key << " in the " << frame << " frame at level "); + + const CondAttrListCollection* atrlistcol=obj; + if(atrlistcol==nullptr and m_detStore->retrieve(atrlistcol,key)!=StatusCode::SUCCESS) { + ATH_MSG_INFO("Cannot find new global align Container for key " + << key << " - no new global alignment "); + return false; + } + + bool alignmentChange = false; + Identifier ident=Identifier(); + + // loop over objects in collection + for (CondAttrListCollection::const_iterator citr=atrlistcol->begin(); citr!=atrlistcol->end();++citr) { + const coral::AttributeList& atrlist=citr->second; + // SCT manager, therefore ignore all that is not a SCT Identifier + // if (atrlist["det"].data<int>()!=2) continue; + ATH_MSG_FATAL("Using invalid alignment data for Veto detector (correct treatment not yet implemented"); + ident = getIdHelper()->plate_id(atrlist["station"].data<int>(), + atrlist["plate"].data<int>()); // The last is the module side which is at this ident-level always the 0-side + + // construct new transform + // Order of rotations is defined as around z, then y, then x. + Amg::Translation3D newtranslation(atrlist["Tx"].data<float>(),atrlist["Ty"].data<float>(),atrlist["Tz"].data<float>()); + Amg::Transform3D newtrans = newtranslation * Amg::RotationMatrix3D::Identity(); + newtrans *= Amg::AngleAxis3D(atrlist["Rz"].data<float>()*CLHEP::mrad, Amg::Vector3D(0.,0.,1.)); + newtrans *= Amg::AngleAxis3D(atrlist["Ry"].data<float>()*CLHEP::mrad, Amg::Vector3D(0.,1.,0.)); + newtrans *= Amg::AngleAxis3D(atrlist["Rx"].data<float>()*CLHEP::mrad, Amg::Vector3D(1.,0.,0.)); + + ATH_MSG_DEBUG("New global DB -- channel: " << citr->first + << " ,det: " << atrlist["det"].data<int>() + << " ,bec: " << atrlist["bec"].data<int>() + << " ,layer: " << atrlist["layer"].data<int>() + << " ,ring: " << atrlist["ring"].data<int>() + << " ,sector: " << atrlist["sector"].data<int>() + << " ,Tx: " << atrlist["Tx"].data<float>() + << " ,Ty: " << atrlist["Ty"].data<float>() + << " ,Tz: " << atrlist["Tz"].data<float>() + << " ,Rx: " << atrlist["Rx"].data<float>() + << " ,Ry: " << atrlist["Ry"].data<float>() + << " ,Rz: " << atrlist["Rz"].data<float>()); + + // Set the new transform; Will replace existing one with updated transform + bool status = setAlignableTransformDelta(level, + ident, + newtrans, + frame, + alignStore); + + if (!status) { + ATH_MSG_DEBUG("Cannot set AlignableTransform for identifier." + << getIdHelper()->show_to_string(ident) + << " at level " << level << " for new global DB "); + } + + alignmentChange = (alignmentChange || status); + } + return alignmentChange; + } + +bool VetoDetectorManager::processSpecialAlignment( + const std::string &, ScintDD::AlignFolderType) const { + return false; +} + +bool VetoDetectorManager::processSpecialAlignment(const std::string& /*key*/, + const CondAttrListCollection* /*obj*/, + GeoVAlignmentStore* /*alignStore*/) const { + return false; + +} + +} // namespace ScintDD diff --git a/Scintillator/ScintDetDescr/ScintGeoModel/CMakeLists.txt b/Scintillator/ScintDetDescr/VetoGeoModel/CMakeLists.txt similarity index 82% rename from Scintillator/ScintDetDescr/ScintGeoModel/CMakeLists.txt rename to Scintillator/ScintDetDescr/VetoGeoModel/CMakeLists.txt index 47bba2ec4ef3a913db35c32ab6ada34838a1cf6a..97e45b33da4d7a8c354a317caf72a85adf68bfce 100644 --- a/Scintillator/ScintDetDescr/ScintGeoModel/CMakeLists.txt +++ b/Scintillator/ScintDetDescr/VetoGeoModel/CMakeLists.txt @@ -1,9 +1,9 @@ ################################################################################ -# Package: ScintGeoModel +# Package: VetoGeoModel ################################################################################ # Declare the package name: -atlas_subdir( ScintGeoModel ) +atlas_subdir( VetoGeoModel ) # Declare the package's dependencies: atlas_depends_on_subdirs( PUBLIC @@ -13,8 +13,8 @@ atlas_depends_on_subdirs( PUBLIC DetectorDescription/GeoModel/GeoModelFaserUtilities DetectorDescription/GeoPrimitives GaudiKernel - InnerDetector/InDetDetDescr/InDetGeoModelUtils -# InnerDetector/InDetDetDescr/InDetReadoutGeometry + Scintillator/ScintDetDescr/ScintGeoModelUtils + Scintillator/ScintDetDescr/ScintReadoutGeometry PRIVATE Control/SGTools Control/StoreGate @@ -23,7 +23,7 @@ atlas_depends_on_subdirs( PUBLIC DetectorDescription/GeoModel/GeoModelInterfaces DetectorDescription/GeometryDBSvc DetectorDescription/Identifier -# InnerDetector/InDetDetDescr/InDetIdentifier + Scintillator/ScintDetDescr/ScintIdentifier DetectorDescription/FaserDetDescr Scintillator/ScintDetDescr/ScintIdentifier ) @@ -34,11 +34,11 @@ find_package( Eigen ) find_package( GeoModel ) # Component(s) in the package: -atlas_add_component( ScintGeoModel +atlas_add_component( VetoGeoModel src/*.cxx src/components/*.cxx INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${CORAL_INCLUDE_DIRS} - LINK_LIBRARIES ${Boost_LIBRARIES} ${CORAL_LIBRARIES} ${GEOMODEL_LIBRARIES} AthenaKernel GeoModelUtilities GeoModelFaserUtilities GaudiKernel SGTools StoreGateLib SGtests AthenaPoolUtilities InDetGeoModelUtils DetDescrConditions FaserDetDescr Identifier ) + LINK_LIBRARIES ${Boost_LIBRARIES} ${CORAL_LIBRARIES} ${GEOMODEL_LIBRARIES} AthenaKernel GeoModelUtilities GeoModelFaserUtilities GaudiKernel SGTools StoreGateLib SGtests AthenaPoolUtilities DetDescrConditions FaserDetDescr ScintGeoModelUtils ScintReadoutGeometry ScintIdentifier Identifier ) #atlas_add_test( SCT_GMConfig_test # SCRIPT test/SCT_GMConfig_test.py diff --git a/Scintillator/ScintDetDescr/ScintGeoModel/ScintGeoModel/VetoDetectorTool.h b/Scintillator/ScintDetDescr/VetoGeoModel/VetoGeoModel/VetoDetectorTool.h similarity index 61% rename from Scintillator/ScintDetDescr/ScintGeoModel/ScintGeoModel/VetoDetectorTool.h rename to Scintillator/ScintDetDescr/VetoGeoModel/VetoGeoModel/VetoDetectorTool.h index a2b14569b66739f106b731b0521b6915c2ea0a0f..bad48487d32f1c098ac23d430aafd753314c289d 100644 --- a/Scintillator/ScintDetDescr/ScintGeoModel/ScintGeoModel/VetoDetectorTool.h +++ b/Scintillator/ScintDetDescr/VetoGeoModel/VetoGeoModel/VetoDetectorTool.h @@ -2,11 +2,11 @@ Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ -#ifndef SCINTGEOMODEL_VETODETECTORTOOL_H -#define SCINTGEOMODEL_VETODETECTORTOOL_H +#ifndef VETOGEOMODEL_VETODETECTORTOOL_H +#define VETOGEOMODEL_VETODETECTORTOOL_H #include "GeoModelUtilities/GeoModelTool.h" -#include "ScintGeoModel/ScintGeoModelAthenaComps.h" +#include "VetoGeoModel/VetoGeoModelAthenaComps.h" #include "GeometryDBSvc/IGeometryDBSvc.h" #include "GeoModelInterfaces/IGeoDbTagSvc.h" @@ -20,8 +20,8 @@ namespace ScintDD { class VetoDetectorManager; } -//class VetoID; -class FaserDetectorIDBase; +class VetoID; +// class FaserDetectorID; class VetoDetectorTool : public GeoModelTool { @@ -41,22 +41,21 @@ public: private: StringProperty m_detectorName{this, "DetectorName", "Veto"}; BooleanProperty m_alignable{this, "Alignable", true}; -// BooleanProperty m_useDynamicAlignFolders{this, "useDynamicAlignFolders", false}; + BooleanProperty m_useDynamicAlignFolders{this, "useDynamicAlignFolders", false}; bool m_cosmic; const ScintDD::VetoDetectorManager* m_manager; - ScintGeoModelAthenaComps<FaserDetectorIDBase> m_athenaComps; - // ScintGeoModelAthenaComps<VetoID> m_athenaComps; + VetoGeoModelAthenaComps m_athenaComps; ServiceHandle< IGeoDbTagSvc > m_geoDbTagSvc; ServiceHandle< IRDBAccessSvc > m_rdbAccessSvc; ServiceHandle< IGeometryDBSvc > m_geometryDBSvc; -// StringProperty m_run1Folder{this, "Run1Folder", "/Indet/Align"}; -// StringProperty m_run2L1Folder{this, "Run2L1Folder", "/Indet/AlignL1/ID"}; -// StringProperty m_run2L2Folder{this, "Run2L2Folder", "/Indet/AlignL2/SCT"}; -// StringProperty m_run2L3Folder{this, "Run2L3Folder", "/Indet/AlignL3"}; + StringProperty m_run1Folder{this, "Run1Folder", "/Scint/Align"}; + StringProperty m_run2L1Folder{this, "Run2L1Folder", "/Scint/AlignL1/ID"}; + StringProperty m_run2L2Folder{this, "Run2L2Folder", "/Scint/AlignL2/SCT"}; + StringProperty m_run2L3Folder{this, "Run2L3Folder", "/Scint/AlignL3"}; }; -#endif // SCINTGEOMODEL_VETODETECTORTOOL_H +#endif // VETOGEOMODEL_VETODETECTORTOOL_H diff --git a/Scintillator/ScintDetDescr/VetoGeoModel/VetoGeoModel/VetoGeoModelAthenaComps.h b/Scintillator/ScintDetDescr/VetoGeoModel/VetoGeoModel/VetoGeoModelAthenaComps.h new file mode 100644 index 0000000000000000000000000000000000000000..23beb8e5b887307c226c9cf7bae77d4c867e9d55 --- /dev/null +++ b/Scintillator/ScintDetDescr/VetoGeoModel/VetoGeoModel/VetoGeoModelAthenaComps.h @@ -0,0 +1,29 @@ +/* + Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef VetoGeoModel_VetoGeoModelAthenaComps_H +#define VetoGeoModel_VetoGeoModelAthenaComps_H 1 + +#include "ScintGeoModelUtils/ScintDDAthenaComps.h" + +class VetoID; + +/// Class to hold various Athena components +// template <class ID_HELPER> +class VetoGeoModelAthenaComps : public ScintDD::AthenaComps { + +public: + + VetoGeoModelAthenaComps(); + + void setIdHelper(const VetoID* idHelper); + + const VetoID* getIdHelper() const; + +private: + const VetoID* m_idHelper; + +}; + +#endif // VetoGeoModel_VetoGeoModelAthenaComps_H diff --git a/Scintillator/ScintDetDescr/ScintGeoModel/ScintGeoModel/VetoOptions.h b/Scintillator/ScintDetDescr/VetoGeoModel/VetoGeoModel/VetoOptions.h similarity index 58% rename from Scintillator/ScintDetDescr/ScintGeoModel/ScintGeoModel/VetoOptions.h rename to Scintillator/ScintDetDescr/VetoGeoModel/VetoGeoModel/VetoOptions.h index 7f6a590401d520592fe0fe0dea1b24d8a4f1a68d..e7ceb5332f7a4aa867aa2016ea6d43179ad187eb 100644 --- a/Scintillator/ScintDetDescr/ScintGeoModel/ScintGeoModel/VetoOptions.h +++ b/Scintillator/ScintDetDescr/VetoGeoModel/VetoGeoModel/VetoOptions.h @@ -2,8 +2,8 @@ Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration */ -#ifndef ScintGeoModel_VetoOptions_H -#define ScintGeoModel_VetoOptions_H +#ifndef VetoGeoModel_VetoOptions_H +#define VetoGeoModel_VetoOptions_H // Class for any run time options. @@ -20,16 +20,16 @@ public: // void setAlignAtModuleLevel(bool flag = true); //dynamic alignment folders -// void setDynamicAlignFolders(const bool flag = true); -// bool dynamicAlignFolders() const; + void setDynamicAlignFolders(const bool flag = true); + bool dynamicAlignFolders() const; private: bool m_alignable; // bool m_alignModule; -// bool m_dynAlignFolders; //controls which set of alignment folders is used + bool m_dynAlignFolders; //controls which set of alignment folders is used }; -#endif // ScintGeoModel_VetoOptions_H +#endif // VetoGeoModel_VetoOptions_H diff --git a/Scintillator/ScintDetDescr/ScintGeoModel/python/ScintGeoModelConfig.py b/Scintillator/ScintDetDescr/VetoGeoModel/python/VetoGeoModelConfig.py similarity index 96% rename from Scintillator/ScintDetDescr/ScintGeoModel/python/ScintGeoModelConfig.py rename to Scintillator/ScintDetDescr/VetoGeoModel/python/VetoGeoModelConfig.py index 407fa3bc6415caf1b8abd8959ab2e9eccf859bd8..b69bc0683cf7ce9cfaf7d1af1015e3df684ca7ed 100644 --- a/Scintillator/ScintDetDescr/ScintGeoModel/python/ScintGeoModelConfig.py +++ b/Scintillator/ScintDetDescr/VetoGeoModel/python/VetoGeoModelConfig.py @@ -6,7 +6,7 @@ def getVetoDetectorTool(name="VetoDetectorTool", **kwargs): kwargs.setdefault("DetectorName", "Veto"); kwargs.setdefault("Alignable", True); kwargs.setdefault("RDBAccessSvc", "RDBAccessSvc"); - kwargs.setdefault("GeometryDBSvc", "InDetGeometryDBSvc"); + kwargs.setdefault("GeometryDBSvc", "ScintGeometryDBSvc"); kwargs.setdefault("GeoDbTagSvc", "GeoDbTagSvc"); # from AthenaCommon.DetFlags import DetFlags return CfgMgr.VetoDetectorTool(name, **kwargs) @@ -18,7 +18,7 @@ from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator from AthenaConfiguration.AthConfigFlags import AthConfigFlags from IOVDbSvc.IOVDbSvcConfig import addFoldersSplitOnline -def ScintGeometryCfg( flags ): +def VetoGeometryCfg( flags ): from FaserGeoModel.GeoModelConfig import GeoModelCfg acc,geoModelSvc = GeoModelCfg( flags ) from GeometryDBSvc.GeometryDBSvcConf import GeometryDBSvc diff --git a/Scintillator/ScintDetDescr/ScintGeoModel/src/VetoDetectorTool.cxx b/Scintillator/ScintDetDescr/VetoGeoModel/src/VetoDetectorTool.cxx similarity index 56% rename from Scintillator/ScintDetDescr/ScintGeoModel/src/VetoDetectorTool.cxx rename to Scintillator/ScintDetDescr/VetoGeoModel/src/VetoDetectorTool.cxx index 30ae62864d65cdd76da3f7fcc79df321d3136cae..088739664b9b99ddd4e164c90112e13473a254cc 100644 --- a/Scintillator/ScintDetDescr/ScintGeoModel/src/VetoDetectorTool.cxx +++ b/Scintillator/ScintDetDescr/VetoGeoModel/src/VetoDetectorTool.cxx @@ -2,17 +2,16 @@ Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ -#include "ScintGeoModel/VetoDetectorTool.h" +#include "VetoGeoModel/VetoDetectorTool.h" -// #include "ScintGeoModel/VetoDetectorFactory.h" -// #include "ScintGeoModel/VetoDataBase.h" -// #include "ScintGeoModel/ScintMaterialManager.h" -#include "ScintGeoModel/VetoOptions.h" +// #include "VetoGeoModel/VetoDetectorFactory.h" +// #include "VetoGeoModel/VetoDataBase.h" +// #include "VetoGeoModel/ScintMaterialManager.h" +#include "VetoGeoModel/VetoOptions.h" // temporary -// #include "InDetIdentifier/SCT_ID.h" -// #include "ScintReadoutGeometry/VetoDetectorManager.h" -#include "FaserDetDescr/FaserDetectorIDBase.h" +#include "ScintReadoutGeometry/VetoDetectorManager.h" +#include "ScintIdentifier/VetoID.h" #include "DetDescrConditions/AlignableTransformContainer.h" #include "GeoModelUtilities/GeoModelExperiment.h" @@ -24,8 +23,8 @@ #include "AthenaKernel/ClassID_traits.h" #include "SGTools/DataProxy.h" -// using ScintDD::VetoDetectorManager; -// using ScintDD::ScintDetectorManager; +using ScintDD::VetoDetectorManager; +using ScintDD::ScintDetectorManager; // // Constructor @@ -36,7 +35,7 @@ VetoDetectorTool::VetoDetectorTool(const std::string& type, : GeoModelTool(type, name, parent), m_cosmic{false}, m_manager{nullptr}, - m_athenaComps{name}, + m_athenaComps{ }, m_geoDbTagSvc{"GeoDbTagSvc", name}, m_rdbAccessSvc{"RDBAccessSvc", name}, m_geometryDBSvc{"ScintGeometryDBSvc", name} @@ -54,10 +53,6 @@ VetoDetectorTool::VetoDetectorTool(const std::string& type, StatusCode VetoDetectorTool::create() { - // Reinit various singleton type objects. -// VetoDataBase::reinit(); -// VetoMaterialManager::reinit(); - // Get the detector configuration. ATH_CHECK(m_geoDbTagSvc.retrieve()); @@ -106,7 +101,7 @@ VetoDetectorTool::create() VetoOptions options; options.setAlignable(m_alignable.value()); - // options.setDynamicAlignFolders(m_useDynamicAlignFolders.value()); + options.setDynamicAlignFolders(m_useDynamicAlignFolders.value()); m_manager = nullptr; // @@ -123,10 +118,10 @@ VetoDetectorTool::create() m_athenaComps.setGeoDbTagSvc(&*m_geoDbTagSvc); m_athenaComps.setGeometryDBSvc(&*m_geometryDBSvc); m_athenaComps.setRDBAccessSvc(&*m_rdbAccessSvc); - const FaserDetectorIDBase* idHelper{nullptr}; - ATH_CHECK(detStore()->retrieve(idHelper, "FaserID")); + const VetoID* idHelper{nullptr}; + ATH_CHECK(detStore()->retrieve(idHelper, "VetoID")); m_athenaComps.setIdHelper(idHelper); - + idHelper->test_plate_packing(); // // This strange way of casting is to avoid an // utterly brain damaged compiler warning. @@ -158,22 +153,18 @@ VetoDetectorTool::create() */ } - // Delete unneeded singleton objects -// VetoDataBase::reinit(); -// ScintMaterialManager::reinit(); - return StatusCode::SUCCESS; } StatusCode VetoDetectorTool::clear() { - ATH_MSG_WARNING("Called unimplemented VetoDetectorTool::clear()"); -// SG::DataProxy* proxy{detStore()->proxy(ClassID_traits<VetoDetectorManager>::ID(), m_manager->getName())}; -// if (proxy) { -// proxy->reset(); -// m_manager = nullptr; -// } + ATH_MSG_WARNING("Called untested VetoDetectorTool::clear()"); + SG::DataProxy* proxy{detStore()->proxy(ClassID_traits<VetoDetectorManager>::ID(), m_manager->getName())}; + if (proxy) { + proxy->reset(); + m_manager = nullptr; + } return StatusCode::SUCCESS; } @@ -182,53 +173,52 @@ VetoDetectorTool::registerCallback() { StatusCode sc{StatusCode::FAILURE, true}; if (m_alignable.value()) { - ATH_MSG_WARNING("Called unimplemented VetoDetectorTool::registerCallback()"); - // if (m_useDynamicAlignFolders.value()) { - - // if (detStore()->contains<CondAttrListCollection>(m_run2L1Folder.value())) { - // ATH_MSG_DEBUG("Registering callback on global Container with folder " << m_run2L1Folder.value()); - // const DataHandle<CondAttrListCollection> calc; - // ATH_CHECK(detStore()->regFcn(&IGeoModelTool::align, dynamic_cast<IGeoModelTool*>(this), calc, m_run2L1Folder.value())); - // sc = StatusCode::SUCCESS; - // } else { - // ATH_MSG_WARNING("Unable to register callback on global Container with folder " << m_run2L1Folder.value()); - // return StatusCode::FAILURE; - // } - // - // if (detStore()->contains<CondAttrListCollection>(m_run2L2Folder.value())) { - // ATH_MSG_DEBUG("Registering callback on global Container with folder " << m_run2L2Folder.value()); - // const DataHandle<CondAttrListCollection> calc; - // ATH_CHECK(detStore()->regFcn(&IGeoModelTool::align, dynamic_cast<IGeoModelTool*>(this), calc, m_run2L2Folder.value())); - // sc = StatusCode::SUCCESS; - // } else { - // ATH_MSG_WARNING("Unable to register callback on global Container with folder " << m_run2L2Folder.value()); - // return StatusCode::FAILURE; - // } - // - // if (detStore()->contains<AlignableTransformContainer>(m_run2L3Folder.value())) { - // ATH_MSG_DEBUG("Registering callback on AlignableTransformContainer with folder " << m_run2L3Folder.value()); - // const DataHandle<AlignableTransformContainer> atc; - // ATH_CHECK(detStore()->regFcn(&IGeoModelTool::align, dynamic_cast<IGeoModelTool*>(this), atc, m_run2L3Folder.value())); - // sc = StatusCode::SUCCESS; - // } else { - // ATH_MSG_WARNING("Unable to register callback on AlignableTransformContainer with folder " << m_run2L3Folder.value()); - // return StatusCode::FAILURE; - // } - // - // } else { - // - // if (detStore()->contains<AlignableTransformContainer>(m_run1Folder.value())) { - // ATH_MSG_DEBUG("Registering callback on AlignableTransformContainer with folder " << m_run1Folder.value()); - // const DataHandle<AlignableTransformContainer> atc; - // ATH_CHECK(detStore()->regFcn(&IGeoModelTool::align, dynamic_cast<IGeoModelTool*>(this), atc, m_run1Folder.value())); - // sc = StatusCode::SUCCESS; - // } else { - // ATH_MSG_WARNING("Unable to register callback on AlignableTransformContainer with folder " - // << m_run1Folder.value() << ", Alignment disabled (only if no Run2 scheme is loaded)!"); - // return StatusCode::FAILURE; - // } - //} - + ATH_MSG_WARNING("Called untested VetoDetectorTool::registerCallback()"); + if (m_useDynamicAlignFolders.value()) { + + if (detStore()->contains<CondAttrListCollection>(m_run2L1Folder.value())) { + ATH_MSG_DEBUG("Registering callback on global Container with folder " << m_run2L1Folder.value()); + const DataHandle<CondAttrListCollection> calc; + ATH_CHECK(detStore()->regFcn(&IGeoModelTool::align, dynamic_cast<IGeoModelTool*>(this), calc, m_run2L1Folder.value())); + sc = StatusCode::SUCCESS; + } else { + ATH_MSG_WARNING("Unable to register callback on global Container with folder " << m_run2L1Folder.value()); + return StatusCode::FAILURE; + } + + if (detStore()->contains<CondAttrListCollection>(m_run2L2Folder.value())) { + ATH_MSG_DEBUG("Registering callback on global Container with folder " << m_run2L2Folder.value()); + const DataHandle<CondAttrListCollection> calc; + ATH_CHECK(detStore()->regFcn(&IGeoModelTool::align, dynamic_cast<IGeoModelTool*>(this), calc, m_run2L2Folder.value())); + sc = StatusCode::SUCCESS; + } else { + ATH_MSG_WARNING("Unable to register callback on global Container with folder " << m_run2L2Folder.value()); + return StatusCode::FAILURE; + } + + if (detStore()->contains<AlignableTransformContainer>(m_run2L3Folder.value())) { + ATH_MSG_DEBUG("Registering callback on AlignableTransformContainer with folder " << m_run2L3Folder.value()); + const DataHandle<AlignableTransformContainer> atc; + ATH_CHECK(detStore()->regFcn(&IGeoModelTool::align, dynamic_cast<IGeoModelTool*>(this), atc, m_run2L3Folder.value())); + sc = StatusCode::SUCCESS; + } else { + ATH_MSG_WARNING("Unable to register callback on AlignableTransformContainer with folder " << m_run2L3Folder.value()); + return StatusCode::FAILURE; + } + + } else { + + if (detStore()->contains<AlignableTransformContainer>(m_run1Folder.value())) { + ATH_MSG_DEBUG("Registering callback on AlignableTransformContainer with folder " << m_run1Folder.value()); + const DataHandle<AlignableTransformContainer> atc; + ATH_CHECK(detStore()->regFcn(&IGeoModelTool::align, dynamic_cast<IGeoModelTool*>(this), atc, m_run1Folder.value())); + sc = StatusCode::SUCCESS; + } else { + ATH_MSG_WARNING("Unable to register callback on AlignableTransformContainer with folder " + << m_run1Folder.value() << ", Alignment disabled (only if no Run2 scheme is loaded)!"); + return StatusCode::FAILURE; + } + } } else { ATH_MSG_INFO("Alignment disabled. No callback registered"); // We return failure otherwise it will try and register @@ -241,18 +231,18 @@ VetoDetectorTool::registerCallback() StatusCode VetoDetectorTool::align(IOVSVC_CALLBACK_ARGS_P(I, keys)) { - ATH_MSG_WARNING("Called unimplemented VetoDetectorTool::align()"); - void* i = &I; - void* k = &keys; - if (i == nullptr && k == nullptr) return StatusCode::SUCCESS; // suppress stupid warning -// if (m_manager==nullptr) { -// ATH_MSG_FATAL("Manager does not exist"); -// return StatusCode::FAILURE; -// } -// if (m_alignable.value()) { -// return m_manager->align(I, keys); -// } else { -// ATH_MSG_DEBUG("Alignment disabled. No alignments applied"); + ATH_MSG_WARNING("Called untested VetoDetectorTool::align()"); + void* i = &I; + void* k = &keys; + if (i == nullptr && k == nullptr) return StatusCode::SUCCESS; // suppress stupid warning + if (m_manager==nullptr) { + ATH_MSG_FATAL("Manager does not exist"); + return StatusCode::FAILURE; + } + if (m_alignable.value()) { + return m_manager->align(I, keys); + } else { + ATH_MSG_DEBUG("Alignment disabled. No alignments applied"); return StatusCode::SUCCESS; -// } + } } diff --git a/Scintillator/ScintDetDescr/VetoGeoModel/src/VetoGeoModelAthenaComps.cxx b/Scintillator/ScintDetDescr/VetoGeoModel/src/VetoGeoModelAthenaComps.cxx new file mode 100644 index 0000000000000000000000000000000000000000..000222cc05ac566d7f38ebb9db6a72ecbfeb5038 --- /dev/null +++ b/Scintillator/ScintDetDescr/VetoGeoModel/src/VetoGeoModelAthenaComps.cxx @@ -0,0 +1,23 @@ +/* + Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration +*/ + +#include "VetoGeoModel/VetoGeoModelAthenaComps.h" + +VetoGeoModelAthenaComps::VetoGeoModelAthenaComps() + : ScintDD::AthenaComps("VetoGeoModel"), + m_idHelper(0) +{} + +void +VetoGeoModelAthenaComps::setIdHelper(const VetoID* idHelper) +{ + m_idHelper = idHelper; +} + +const VetoID* +VetoGeoModelAthenaComps::getIdHelper() const +{ + return m_idHelper; +} + diff --git a/Scintillator/ScintDetDescr/ScintGeoModel/src/VetoOptions.cxx b/Scintillator/ScintDetDescr/VetoGeoModel/src/VetoOptions.cxx similarity index 66% rename from Scintillator/ScintDetDescr/ScintGeoModel/src/VetoOptions.cxx rename to Scintillator/ScintDetDescr/VetoGeoModel/src/VetoOptions.cxx index 6e5bf75492b84a0648e189b502b4f14d7a183f29..1a4691d5f4a03668b216804fe29510e9f54cddc3 100644 --- a/Scintillator/ScintDetDescr/ScintGeoModel/src/VetoOptions.cxx +++ b/Scintillator/ScintDetDescr/VetoGeoModel/src/VetoOptions.cxx @@ -2,12 +2,12 @@ Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration */ -#include "ScintGeoModel/VetoOptions.h" +#include "VetoGeoModel/VetoOptions.h" VetoOptions::VetoOptions() : m_alignable(true) // , m_alignModule(true) -// , m_dynAlignFolders(false) + , m_dynAlignFolders(false) {} void @@ -36,12 +36,12 @@ VetoOptions::alignable() const // return m_alignModule; // } -// void SCT_Options::setDynamicAlignFolders(const bool flag) -// { -// m_dynAlignFolders = flag; -// } +void VetoOptions::setDynamicAlignFolders(const bool flag) +{ + m_dynAlignFolders = flag; +} -// bool SCT_Options::dynamicAlignFolders() const -// { -// return m_dynAlignFolders; -// } +bool VetoOptions::dynamicAlignFolders() const +{ + return m_dynAlignFolders; +} diff --git a/Scintillator/ScintDetDescr/VetoGeoModel/src/components/ScintGeoModel_entries.cxx b/Scintillator/ScintDetDescr/VetoGeoModel/src/components/ScintGeoModel_entries.cxx new file mode 100644 index 0000000000000000000000000000000000000000..7279877ef3504cc6f1fa11ee932f236f7723ecb7 --- /dev/null +++ b/Scintillator/ScintDetDescr/VetoGeoModel/src/components/ScintGeoModel_entries.cxx @@ -0,0 +1,3 @@ +#include "VetoGeoModel/VetoDetectorTool.h" + +DECLARE_COMPONENT( VetoDetectorTool ) \ No newline at end of file diff --git a/Scintillator/ScintDetDescrCnv/ScintIdCnv/CMakeLists.txt b/Scintillator/ScintDetDescrCnv/ScintIdCnv/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..07a22222000efd637c17104579776ca6bd6c38ea --- /dev/null +++ b/Scintillator/ScintDetDescrCnv/ScintIdCnv/CMakeLists.txt @@ -0,0 +1,23 @@ +################################################################################ +# Package: ScintIdCnv +################################################################################ + +# Declare the package name: +atlas_subdir( ScintIdCnv ) + +# Declare the package's dependencies: +atlas_depends_on_subdirs( PRIVATE + Control/StoreGate + DetectorDescription/DetDescrCnvSvc + DetectorDescription/IdDictDetDescr + GaudiKernel + Scintillator/ScintDetDescr/ScintIdentifier ) + +# Component(s) in the package: +atlas_add_component( ScintIdCnv + src/*.cxx + LINK_LIBRARIES StoreGateLib SGtests DetDescrCnvSvcLib IdDictDetDescr GaudiKernel ScintIdentifier ) + +# Install files from the package: +atlas_install_joboptions( share/*.py ) + diff --git a/Scintillator/ScintDetDescrCnv/ScintIdCnv/share/ScintIdCnv_jobOptions.py b/Scintillator/ScintDetDescrCnv/ScintIdCnv/share/ScintIdCnv_jobOptions.py new file mode 100644 index 0000000000000000000000000000000000000000..a5d750a92fcb87a90d0ba60c47aad8d8c1da4cdb --- /dev/null +++ b/Scintillator/ScintDetDescrCnv/ScintIdCnv/share/ScintIdCnv_jobOptions.py @@ -0,0 +1,6 @@ +# +# Joboptions for the loading of the of ScintIdCnv +# + +# DLLs +theApp.Dlls += [ "ScintIdCnv" ] diff --git a/Scintillator/ScintDetDescrCnv/ScintIdCnv/src/ScintIdCnv_entries.cxx b/Scintillator/ScintDetDescrCnv/ScintIdCnv/src/ScintIdCnv_entries.cxx new file mode 100644 index 0000000000000000000000000000000000000000..6c2fee3310e2db91d2dd59fd532990b60ec4057c --- /dev/null +++ b/Scintillator/ScintDetDescrCnv/ScintIdCnv/src/ScintIdCnv_entries.cxx @@ -0,0 +1,11 @@ +// #include "PixelIDDetDescrCnv.h" +// #include "SCT_IDDetDescrCnv.h" +// #include "SiliconIDDetDescrCnv.h" +// #include "TRT_IDDetDescrCnv.h" +#include "VetoIDDetDescrCnv.h" + +// DECLARE_CONVERTER(SCT_IDDetDescrCnv) +// DECLARE_CONVERTER(PixelIDDetDescrCnv) +// DECLARE_CONVERTER(SiliconIDDetDescrCnv) +// DECLARE_CONVERTER(TRT_IDDetDescrCnv) +DECLARE_CONVERTER(VetoIDDetDescrCnv) diff --git a/Scintillator/ScintDetDescrCnv/ScintIdCnv/src/VetoIDDetDescrCnv.cxx b/Scintillator/ScintDetDescrCnv/ScintIdCnv/src/VetoIDDetDescrCnv.cxx new file mode 100644 index 0000000000000000000000000000000000000000..c467616e525a5648aaf2ff3bdedc3d9487df9065 --- /dev/null +++ b/Scintillator/ScintDetDescrCnv/ScintIdCnv/src/VetoIDDetDescrCnv.cxx @@ -0,0 +1,239 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/*************************************************************************** + Scint DetDescrCnv package + ----------------------------------------- + ***************************************************************************/ + +//<<<<<< INCLUDES >>>>>> + +#include "VetoIDDetDescrCnv.h" + +#include "DetDescrCnvSvc/DetDescrConverter.h" +#include "DetDescrCnvSvc/DetDescrAddress.h" +#include "GaudiKernel/MsgStream.h" +#include "StoreGate/StoreGate.h" + +#include "IdDictDetDescr/IdDictManager.h" +#include "ScintIdentifier/VetoID.h" + + +//<<<<<< PRIVATE DEFINES >>>>>> +//<<<<<< PRIVATE CONSTANTS >>>>>> +//<<<<<< PRIVATE TYPES >>>>>> +//<<<<<< PRIVATE VARIABLE DEFINITIONS >>>>>> +//<<<<<< PUBLIC VARIABLE DEFINITIONS >>>>>> +//<<<<<< CLASS STRUCTURE INITIALIZATION >>>>>> +//<<<<<< PRIVATE FUNCTION DEFINITIONS >>>>>> +//<<<<<< PUBLIC FUNCTION DEFINITIONS >>>>>> +//<<<<<< MEMBER FUNCTION DEFINITIONS >>>>>> + +//-------------------------------------------------------------------- + +long int +VetoIDDetDescrCnv::repSvcType() const +{ + return (storageType()); +} + +//-------------------------------------------------------------------- + +StatusCode +VetoIDDetDescrCnv::initialize() +{ + // First call parent init + StatusCode sc = DetDescrConverter::initialize(); + MsgStream log(msgSvc(), "VetoIDDetDescrCnv"); + log << MSG::DEBUG << "in initialize" << endmsg; + + if (sc.isFailure()) { + log << MSG::ERROR << "DetDescrConverter::initialize failed" << endmsg; + return sc; + } + + // The following is an attempt to "bootstrap" the loading of a + // proxy for VetoID into the detector store. However, + // VetoIDDetDescrCnv::initialize is NOT called by the conversion + // service. So for the moment, this cannot be use. Instead the + // DetDescrCnvSvc must do the bootstrap from a parameter list. + + +// // Add Scint_DetDescrManager proxy as entry point to the detector store +// // - this is ONLY needed for the manager of each system +// sc = addToDetStore(classID(), "VetoID"); +// if (sc.isFailure()) { +// log << MSG::FATAL << "Unable to add proxy for VetoID to the Detector Store!" << endmsg; +// return StatusCode::FAILURE; +// } else {} + + return StatusCode::SUCCESS; +} + +//-------------------------------------------------------------------- + +StatusCode +VetoIDDetDescrCnv::finalize() +{ + MsgStream log(msgSvc(), "VetoIDDetDescrCnv"); + log << MSG::DEBUG << "in finalize" << endmsg; + + return StatusCode::SUCCESS; +} + +//-------------------------------------------------------------------- + +StatusCode +VetoIDDetDescrCnv::createObj(IOpaqueAddress* pAddr, DataObject*& pObj) +{ + //StatusCode sc = StatusCode::SUCCESS; + MsgStream log(msgSvc(), "VetoIDDetDescrCnv"); + log << MSG::INFO << "in createObj: creating a VetoID helper object in the detector store" << endmsg; + + // Create a new VetoID + + DetDescrAddress* ddAddr; + ddAddr = dynamic_cast<DetDescrAddress*> (pAddr); + if(!ddAddr) { + log << MSG::FATAL << "Could not cast to DetDescrAddress." << endmsg; + return StatusCode::FAILURE; + } + + // Get the StoreGate key of this container. + std::string helperKey = *( ddAddr->par() ); + if ("" == helperKey) { + log << MSG::DEBUG << "No Helper key " << endmsg; + } + else { + log << MSG::DEBUG << "Helper key is " << helperKey << endmsg; + } + + + // get DetectorStore service + StoreGateSvc * detStore; + StatusCode status = serviceLocator()->service("DetectorStore", detStore); + if (status.isFailure()) { + log << MSG::FATAL << "DetectorStore service not found !" << endmsg; + return StatusCode::FAILURE; + } else {} + + // Get the dictionary manager from the detector store + const DataHandle<IdDictManager> idDictMgr; + status = detStore->retrieve(idDictMgr, "IdDict"); + if (status.isFailure()) { + log << MSG::FATAL << "Could not get IdDictManager !" << endmsg; + return StatusCode::FAILURE; + } + else { + log << MSG::DEBUG << " Found the IdDictManager. " << endmsg; + } + + // Only create new helper if it is the first pass or if there is a + // change in the the file or tag + bool initHelper = false; + + const IdDictMgr* mgr = idDictMgr->manager(); + + // Internal Scint id tag + std::string scintIDTag = mgr->tag(); + + // DoChecks flag + bool doChecks = mgr->do_checks(); + + IdDictDictionary* dict = mgr->find_dictionary("Scintillator"); + if (!dict) { + log << MSG::ERROR + << "unable to find idDict for Scintillator" + << endmsg; + return StatusCode::FAILURE; + } + + // File to be read for Scint ids + std::string scintIDFileName = dict->file_name(); + + // Tag of RDB record for Scint ids + std::string scintIdDictTag = dict->dict_tag(); + + + if (m_vetoId) { + + // Veto id helper already exists - second pass. Check for a + // change + if (scintIDTag != m_scintIDTag) { + // Internal Scint id tag + initHelper = true; + log << MSG::DEBUG << " Changed internal Scint id tag: " + << scintIDTag << endmsg; + } + if (scintIDFileName != m_scintIDFileName) { + // File to be read for Scint ids + initHelper = true; + log << MSG::DEBUG << " Changed ScintFileName:" + << scintIDFileName << endmsg; + } + if (scintIdDictTag != m_scintIdDictTag) { + // Tag of RDB record for Scint ids + initHelper = true; + log << MSG::DEBUG << " Changed ScintIdDictTag: " + << scintIdDictTag + << endmsg; + } + if (doChecks != m_doChecks) { + // DoChecks flag + initHelper = true; + log << MSG::DEBUG << " Changed doChecks flag: " + << doChecks + << endmsg; + } + } + else { + // create the helper + m_vetoId = new VetoID; + initHelper = true; + // add in message service for printout + m_vetoId->setMessageSvc(msgSvc()); + } + + if (initHelper) { + if (idDictMgr->initializeHelper(*m_vetoId)) { + log << MSG::ERROR << "Unable to initialize VetoID" << endmsg; + return StatusCode::FAILURE; + } + // Save state: + m_scintIDTag = scintIDTag; + m_scintIDFileName = scintIDFileName; + m_scintIdDictTag = scintIdDictTag; + m_doChecks = doChecks; + } + + // Pass a pointer to the container to the Persistency service by reference. + pObj = StoreGateSvc::asStorable(m_vetoId); + + return StatusCode::SUCCESS; + +} + +//-------------------------------------------------------------------- + +long +VetoIDDetDescrCnv::storageType() +{ + return DetDescr_StorageType; +} + +//-------------------------------------------------------------------- +const CLID& +VetoIDDetDescrCnv::classID() { + return ClassID_traits<VetoID>::ID(); +} + +//-------------------------------------------------------------------- +VetoIDDetDescrCnv::VetoIDDetDescrCnv(ISvcLocator* svcloc) + : + DetDescrConverter(ClassID_traits<VetoID>::ID(), svcloc), + m_vetoId(0), + m_doChecks(false) + +{} + diff --git a/Scintillator/ScintDetDescrCnv/ScintIdCnv/src/VetoIDDetDescrCnv.h b/Scintillator/ScintDetDescrCnv/ScintIdCnv/src/VetoIDDetDescrCnv.h new file mode 100644 index 0000000000000000000000000000000000000000..49c09c78f6a348ec29194d6aed47a2e01aacf215 --- /dev/null +++ b/Scintillator/ScintDetDescrCnv/ScintIdCnv/src/VetoIDDetDescrCnv.h @@ -0,0 +1,71 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/*************************************************************************** + Scint DetDescrCnv package + ----------------------------------------- + ***************************************************************************/ + +#ifndef SCINTIDCNV_VETOIDDETDESCRCNV_H +#define SCINTIDCNV_VETOIDDETDESCRCNV_H + +//<<<<<< INCLUDES >>>>>> + +#include "DetDescrCnvSvc/DetDescrConverter.h" + +//<<<<<< PUBLIC DEFINES >>>>>> +//<<<<<< PUBLIC CONSTANTS >>>>>> +//<<<<<< PUBLIC TYPES >>>>>> + +class VetoID; + +//<<<<<< PUBLIC VARIABLES >>>>>> +//<<<<<< PUBLIC FUNCTIONS >>>>>> +//<<<<<< CLASS DECLARATIONS >>>>>> + + +/** + ** This class is a converter for the VetoID an IdHelper which is + ** stored in the detector store. This class derives from + ** DetDescrConverter which is a converter of the DetDescrCnvSvc. + ** + **/ + +class VetoIDDetDescrCnv: public DetDescrConverter { + +public: + virtual long int repSvcType() const; + virtual StatusCode initialize(); + virtual StatusCode finalize(); + virtual StatusCode createObj(IOpaqueAddress* pAddr, DataObject*& pObj); + + // Storage type and class ID (used by CnvFactory) + static long storageType(); + static const CLID& classID(); + + VetoIDDetDescrCnv(ISvcLocator* svcloc); + +private: + /// The helper - only will create it once + VetoID* m_vetoId; + + /// File to be read for InDet ids + std::string m_scintIDFileName; + + /// Tag of RDB record for InDet ids + std::string m_scintIdDictTag; + + /// Internal InDet id tag + std::string m_scintIDTag; + + /// Whether or not + bool m_doChecks; + +}; + + +//<<<<<< INLINE PUBLIC FUNCTIONS >>>>>> +//<<<<<< INLINE MEMBER FUNCTIONS >>>>>> + +#endif // SCINTIDCNV_VETOIDDETDESCRCNV_H