#ifndef __JDETECTOR__JDETECTORADDRESSMAPTOOLKIT__ #define __JDETECTOR__JDETECTORADDRESSMAPTOOLKIT__ #include "JLang/JTypeList.hh" #include "JLang/JNullType.hh" #include "JLang/JType.hh" #include "JLang/JException.hh" #include "JDetector/JModuleAddressMap.hh" #include "JDetector/JDetectorAddressMap.hh" /** * \file * Detector specific mapping between logical positions and readout channels of PMTs in optical modules. * \author mdejong */ namespace JDETECTOR {} namespace JPP { using namespace JDETECTOR; } namespace JDETECTOR { using JLANG::JTypeList; using JLANG::JTYPELIST; using JLANG::JNullType; using JLANG::JType; using JLANG::JIndexOutOfRange; /** * Type definitions for different detectors. */ struct JPPM_DU_t {}; //!< PPM_DU struct JKM3NeT_t {}; //!< %KM3NeT struct JMonteCarlo_t {}; //!< Monte Carlo struct JAntares_t {}; //!< %Antares struct JObsolete_t {}; //!< obsolete detector struct JKM3NeTDB_t {}; //!< %KM3NeT with cable swaps according database (see JPMTSwapDB.cc) /** * Type list of %KM3NeT detector types (specific detectors first). */ typedef JTYPELIST::typelist JDetectorTypes_t; /** * Check validity of detector identifier. * * \param type detector type * \param id detector identifier * \return true if valid match; else false */ inline bool hasDetector(JType type, const int id) { return id == 1; } inline bool hasDetector(JType type, const int id) { return id >= 116; } inline bool hasDetector(JType type, const int id) { return id >= 2 && id <= 2000000000; } inline bool hasDetector(JType type, const int id) { return id >= -2000000000 && id <= -2; } /** * Template lookup table for PMT addresses in detector.\n * The template argument refers to a specific detector.\n * This class should be specialised for each detector.\n * In the constructor of the specialised class, the various PMT swaps should be defined. */ template class JTemplateDetectorAddressMap; /** * Template specialisation of JTemplateDetectorAddressMap for obsolete detector. */ template<> class JTemplateDetectorAddressMap : public JDetectorAddressMap { public: /** * Default constructor. */ JTemplateDetectorAddressMap() : JDetectorAddressMap() {} /** * Get default module address map. * * \return module address map */ virtual const JModuleAddressMap& getDefaultModuleAddressMap() const override { static JModuleAddressMap memo; if (memo.empty()) { memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 0), JPMTPhysicalAddress('A', 1))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 1), JPMTPhysicalAddress('B', 1))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 2), JPMTPhysicalAddress('B', 2))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 3), JPMTPhysicalAddress('B', 3))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 4), JPMTPhysicalAddress('B', 4))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 5), JPMTPhysicalAddress('B', 5))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 6), JPMTPhysicalAddress('B', 6))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 7), JPMTPhysicalAddress('C', 1))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 8), JPMTPhysicalAddress('C', 2))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 9), JPMTPhysicalAddress('C', 3))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(10), JPMTPhysicalAddress('C', 4))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(11), JPMTPhysicalAddress('C', 5))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(12), JPMTPhysicalAddress('C', 6))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(13), JPMTPhysicalAddress('D', 1))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(14), JPMTPhysicalAddress('D', 2))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(15), JPMTPhysicalAddress('D', 3))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(16), JPMTPhysicalAddress('D', 4))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(17), JPMTPhysicalAddress('D', 5))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(18), JPMTPhysicalAddress('D', 6))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(19), JPMTPhysicalAddress('E', 1))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(20), JPMTPhysicalAddress('E', 2))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(21), JPMTPhysicalAddress('E', 3))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(22), JPMTPhysicalAddress('E', 4))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(23), JPMTPhysicalAddress('E', 5))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(24), JPMTPhysicalAddress('E', 6))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(25), JPMTPhysicalAddress('F', 1))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(26), JPMTPhysicalAddress('F', 2))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(27), JPMTPhysicalAddress('F', 3))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(28), JPMTPhysicalAddress('F', 4))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(29), JPMTPhysicalAddress('F', 5))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(30), JPMTPhysicalAddress('F', 6))); memo.configure(); } return memo; } }; /** * Template specialisation of JTemplateDetectorAddressMap for PPM_DU detector. */ template<> class JTemplateDetectorAddressMap : public JDetectorAddressMap { public: /** * Default constructor. */ JTemplateDetectorAddressMap() : JDetectorAddressMap() { get(103).swap(24,30); } /** * Get default module address map. * * \return module address map */ virtual const JModuleAddressMap& getDefaultModuleAddressMap() const override { static JModuleAddressMap memo; if (memo.empty()) { memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 0), JPMTPhysicalAddress('A', 1))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 6), JPMTPhysicalAddress('B', 1))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 5), JPMTPhysicalAddress('B', 2))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 4), JPMTPhysicalAddress('B', 3))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 3), JPMTPhysicalAddress('B', 4))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 2), JPMTPhysicalAddress('B', 5))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 1), JPMTPhysicalAddress('B', 6))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(12), JPMTPhysicalAddress('C', 1))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(11), JPMTPhysicalAddress('C', 2))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(10), JPMTPhysicalAddress('C', 3))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 9), JPMTPhysicalAddress('C', 4))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 8), JPMTPhysicalAddress('C', 5))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 7), JPMTPhysicalAddress('C', 6))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(18), JPMTPhysicalAddress('D', 1))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(17), JPMTPhysicalAddress('D', 2))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(16), JPMTPhysicalAddress('D', 3))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(15), JPMTPhysicalAddress('D', 4))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(14), JPMTPhysicalAddress('D', 5))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(13), JPMTPhysicalAddress('D', 6))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(19), JPMTPhysicalAddress('E', 1))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(24), JPMTPhysicalAddress('E', 2))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(23), JPMTPhysicalAddress('E', 3))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(22), JPMTPhysicalAddress('E', 4))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(21), JPMTPhysicalAddress('E', 5))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(20), JPMTPhysicalAddress('E', 6))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(25), JPMTPhysicalAddress('F', 1))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(30), JPMTPhysicalAddress('F', 2))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(29), JPMTPhysicalAddress('F', 3))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(28), JPMTPhysicalAddress('F', 4))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(27), JPMTPhysicalAddress('F', 5))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(26), JPMTPhysicalAddress('F', 6))); memo.configure(); } return memo; } }; /** * Template specialisation of JTemplateDetectorAddressMap for %KM3NeT detector. */ template<> class JTemplateDetectorAddressMap : public JDetectorAddressMap { public: /** * Default constructor. */ JTemplateDetectorAddressMap() : JDetectorAddressMap() {} /** * Get default module address map. * * \return module address map */ virtual const JModuleAddressMap& getDefaultModuleAddressMap() const override { static JModuleAddressMap memo; if (memo.empty()) { memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(22), JPMTPhysicalAddress('A', 1))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(14), JPMTPhysicalAddress('B', 1))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(19), JPMTPhysicalAddress('B', 2))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(25), JPMTPhysicalAddress('B', 3))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(24), JPMTPhysicalAddress('B', 4))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(26), JPMTPhysicalAddress('B', 5))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(18), JPMTPhysicalAddress('B', 6))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(13), JPMTPhysicalAddress('C', 1))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(21), JPMTPhysicalAddress('C', 2))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(29), JPMTPhysicalAddress('C', 3))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(28), JPMTPhysicalAddress('C', 4))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(20), JPMTPhysicalAddress('C', 5))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(17), JPMTPhysicalAddress('C', 6))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(12), JPMTPhysicalAddress('D', 1))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(15), JPMTPhysicalAddress('D', 2))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(23), JPMTPhysicalAddress('D', 3))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(30), JPMTPhysicalAddress('D', 4))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(27), JPMTPhysicalAddress('D', 5))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(16), JPMTPhysicalAddress('D', 6))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(10), JPMTPhysicalAddress('E', 1))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 6), JPMTPhysicalAddress('E', 2))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 3), JPMTPhysicalAddress('E', 3))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 2), JPMTPhysicalAddress('E', 4))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 1), JPMTPhysicalAddress('E', 5))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(11), JPMTPhysicalAddress('E', 6))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 9), JPMTPhysicalAddress('F', 1))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 8), JPMTPhysicalAddress('F', 2))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 4), JPMTPhysicalAddress('F', 3))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 0), JPMTPhysicalAddress('F', 4))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 5), JPMTPhysicalAddress('F', 5))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 7), JPMTPhysicalAddress('F', 6))); memo.configure(); } return memo; } }; /** * Template specialisation of JTemplateDetectorAddressMap for Monte Carlo detector. */ template<> class JTemplateDetectorAddressMap : public JDetectorAddressMap { public: /** * Default constructor. */ JTemplateDetectorAddressMap() : JDetectorAddressMap() {} /** * Get default module address map. * * \return module address map */ virtual const JModuleAddressMap& getDefaultModuleAddressMap() const override { static JModuleAddressMap memo; if (memo.empty()) { memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(22), JPMTPhysicalAddress('A', 1))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(14), JPMTPhysicalAddress('B', 1))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(19), JPMTPhysicalAddress('B', 2))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(25), JPMTPhysicalAddress('B', 3))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(24), JPMTPhysicalAddress('B', 4))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(26), JPMTPhysicalAddress('B', 5))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(18), JPMTPhysicalAddress('B', 6))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(13), JPMTPhysicalAddress('C', 1))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(21), JPMTPhysicalAddress('C', 2))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(29), JPMTPhysicalAddress('C', 3))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(28), JPMTPhysicalAddress('C', 4))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(20), JPMTPhysicalAddress('C', 5))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(17), JPMTPhysicalAddress('C', 6))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(12), JPMTPhysicalAddress('D', 1))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(15), JPMTPhysicalAddress('D', 2))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(23), JPMTPhysicalAddress('D', 3))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(30), JPMTPhysicalAddress('D', 4))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(27), JPMTPhysicalAddress('D', 5))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(16), JPMTPhysicalAddress('D', 6))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(10), JPMTPhysicalAddress('E', 1))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 6), JPMTPhysicalAddress('E', 2))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 3), JPMTPhysicalAddress('E', 3))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 2), JPMTPhysicalAddress('E', 4))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 1), JPMTPhysicalAddress('E', 5))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress(11), JPMTPhysicalAddress('E', 6))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 9), JPMTPhysicalAddress('F', 1))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 8), JPMTPhysicalAddress('F', 2))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 4), JPMTPhysicalAddress('F', 3))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 0), JPMTPhysicalAddress('F', 4))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 5), JPMTPhysicalAddress('F', 5))); memo.push_back(JPMTAddressTranslator(JPMTReadoutAddress( 7), JPMTPhysicalAddress('F', 6))); memo.configure(); } return memo; } }; /** * Template specialisation of JTemplateDetectorAddressMap for %KM3NeT detector. */ template<> class JTemplateDetectorAddressMap : public JTemplateDetectorAddressMap { public: /** * Default constructor. */ JTemplateDetectorAddressMap() { get(817802210).swapTDC(14,18); get(817802210).swapTDC(18,26); get(817802210).swapTDC(19,26); get(817802210).swapTDC(24,25); get(817802210).swapTDC(25,26); } }; /** * Get detector address map. * * \return detector address map */ template inline JDetectorAddressMap& getDetectorAddressMap() { static JTemplateDetectorAddressMap demo; return demo; } /** * Get module address map. * * \param id module identifier * \return module address map */ template inline JModuleAddressMap& getModuleAddressMap(int id) { return getDetectorAddressMap().get(id); } /** * Get PMT address translator for given module identifier and TDC channel. * * \param id module identifier * \param tdc TDC * \return PMT address translator */ template inline const JPMTAddressTranslator& getPMTAddressTranslator(int id, int tdc) { return getModuleAddressMap(id).getAddressTranslator(tdc); } /** * Get PMT logical index for given module identifier and TDC channel. * * \param id module identifier * \param tdc TDC * \return PMT logical index */ template inline int getPMTLogicalIndex(int id, int tdc) { return getModuleAddressMap(id).getIndex(tdc); } /** * Auxiliary class to extract detector address map from detector identifier. */ template struct JDetectorAddressMap_t; template struct JDetectorAddressMap_t< JTypeList > { /** * Get detector address map. * * \param id detector identifier * \return detector address map */ static JDetectorAddressMap& get(const int id) { if (hasDetector(JType(), id)) return getDetectorAddressMap(); else return JDetectorAddressMap_t::get(id); } /** * Has detector address map. * * \param id detector identifier * \return true if detector address map available; else false */ static bool has(const int id) { return hasDetector(JType(), id) || JDetectorAddressMap_t::has(id); } }; template struct JDetectorAddressMap_t< JTypeList > { /** * Get detector address map. * * \param id detector identifier * \return detector address map */ static JDetectorAddressMap& get(const int id) { if (hasDetector(JType(), id)) return getDetectorAddressMap(); else THROW(JIndexOutOfRange, "getDetectorAddressMap<..>(" << id << ")" ); } /** * Has detector address map. * * \param id detector identifier * \return true if detector address map available; else false */ static bool has(const int id) { return hasDetector(JType(), id); } }; /** * Get detector address map. * * \param id detector identifier * \return detector address map */ inline JDetectorAddressMap& getDetectorAddressMap(const int id) { return JDetectorAddressMap_t::get(id); } /** * Check if detector address map is available. * * \param id detector identifier * \return true if detector address map available; else false */ inline bool hasDetectorAddressMap(const int id) { return JDetectorAddressMap_t::has(id); } } #endif