diff --git a/edm4eic.yaml b/edm4eic.yaml index 8aeead7..e0a2e35 100644 --- a/edm4eic.yaml +++ b/edm4eic.yaml @@ -265,6 +265,35 @@ datatypes: ## ========================================================================== ## Calorimetry ## ========================================================================== + + edm4eic::RawCALOROCHit: + Description: "Raw hit from a CALOROC/HGCROC chip" + Author: "D. Anderson, S. Joosten, N. Novitzky" + Members: + - uint32_t type // Chip type, 0 - type 1A (readout in only 1 gain mode), 1 - type 1B (readout in low & high gain mode) + - uint64_t cellID // Detector specific (geometrical) cell id + - int32_t samplePhase // Phase of samples in [# samples], for synchronizing across chips + - int32_t timeStamp // [TDC counts] + VectorMembers: + - uint32_t amplitude // If type == 0 - waveform amplitudes stored here, if type == 1 - low/high gain amplitude stored in lower/upper 16 bits [ADC counts] + - int32_t timeOfArrival // Calculated times of arrival, i.e. times when waveform crosses threshold upwards [TDC counts] + - int32_t timeOverThreshold // Calculated times over threshold, i.e. time from upward-crossing to downward-crossing of threshold [TDC counts] + ExtraCode: + declaration: " + bool isType1A() const {return getType() == 0;}\n + bool isType1B() const {return getType() == 1;}\n + /// If type == 1, retrieve the low gain readout (lower 16 bits) at a particular sample number\n + uint16_t getLowGainAmplitude(const size_t sample) const {\n + assert(sample < getAmplitude().size());\n + return getAmplitude(sample) & 0xFFF;\n + }\n + /// If type == 1, retrieve the high gain readout (upper 16 bits) at a particular sample number\n + uint16_t getHighGainAmplitude(const size_t sample) const {\n + assert(sample < getAmplitude().size());\n + return getAmplitude(sample) >> 16;\n + }\n + " + edm4eic::CalorimeterHit: Description: "Calorimeter hit" Author: "W. Armstrong, S. Joosten" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4d39a84..003e2b1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -29,6 +29,15 @@ add_test(NAME read_events COMMAND read_events) ) set_test_env(read_events) +add_executable(test_caloroc_hits test_caloroc_hits.cc) +target_include_directories(test_caloroc_hits PUBLIC ${PROJECT_SOURCE_DIR}/edm4eic ) +target_link_libraries(test_caloroc_hits edm4eic podio::podioRootIO) +add_test(NAME test_caloroc_hits COMMAND test_caloroc_hits) + set_property(TEST test_caloroc_hits PROPERTY + DEPENDS test_caloroc_hits + ) +set_test_env(test_caloroc_hits) + IF(TARGET ROOT::ROOTDataFrame) add_executable(test_rdf test_rdf.cc) target_include_directories(test_rdf PUBLIC ${PROJECT_SOURCE_DIR}/edm4hep ${PROJECT_SOURCE_DIR}/dataframe ) @@ -70,4 +79,4 @@ if (nlohmann_json_FOUND) set_test_env(convert_events) endif() -add_subdirectory(utils) \ No newline at end of file +add_subdirectory(utils) diff --git a/test/test_caloroc_hits.cc b/test/test_caloroc_hits.cc new file mode 100644 index 0000000..a7479e3 --- /dev/null +++ b/test/test_caloroc_hits.cc @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: Apache-2.0 + +#include "test_caloroc_hits.h" +#include "podio/ROOTWriter.h" +#include "podio/ROOTReader.h" + +int main(int argc, char* argv[]) { + + // announce start + std::cout << "Start raw CALOROC tests." << std::endl; + + // run tests + TestCALOROCHits test(1); + test.WriteHits("edm4eic_rawcalorochits.root"); + test.ReadHits("edm4eic_rawcalorochits.root"); + + // announce end & exit + std::cout << "Raw CALOROC tests finished." << std::endl; + return 0; + +} diff --git a/test/test_caloroc_hits.h b/test/test_caloroc_hits.h new file mode 100644 index 0000000..f54ea12 --- /dev/null +++ b/test/test_caloroc_hits.h @@ -0,0 +1,126 @@ +// SPDX-License-Identifier: Apache-2.0 + +#ifndef EDM4EIC_TEST_CALOROC_HITS_H +#define EDM4EIC_TEST_CALOROC_HITS_H + +// edm for caloroc hits +#include "edm4eic/RawCALOROCHitCollection.h" + +// podio-specific includes +#include "podio/Frame.h" + +// stl includes +#include +#include +#include + + + +// ============================================================================ +//! Test implementation of raw CALOROC hits +// ============================================================================ +/*! This is a simple unit test to check the implementation of both + * type 1A (1 readout) and type 1B (low and high gain readouts) + * raw CALOROC hits. + */ +template +class TestCALOROCHits { + + private: + + /// this is the threshold used to define the + /// time-of-arrival and time-over-threshold + /// values + uint32_t m_threshold; + + /// this array defines amplitudes which mock-up a + /// typical waveform produced by an HGC/CALOROC + static const std::array m_arrAdcCounts = { + 0, 0, 1, 2, 11, 43, 143, 338, 542, + 729, 875, 963, 1000, 993, 956, 902, 840, 774, + 709, 647, 593, 544, 500, 461, 428, 400, 374, + 350, 328, 307, 286, 268, 252, 236, 221, 206, + 193, 181, 169, 157, 146, 137, 129, 120, 112, + 105, 98, 91, 85, 81, 75, 70, 65, 62, + 58, 54, 50, 47, 44, 42, 39, 37, 34, + 31, 29, 28, 27, 24, 23, 21, 20, 19, + 18, 17, 16, 15, 14, 13, 12, 11, 11, + 10, 10, 10, 9, 9, 8, 8, 7, 7, + 7, 6, 6, 6, 5, 5, 5, 5, 5, + 5, 5, 5, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 3}; + + public: + + // ------------------------------------------------------------------------ + //! Test writing CALOROC hits + // ------------------------------------------------------------------------ + void WriteHits(const std::string& outfilename) { + + std::cout << "\n --- Begin raw CALOROC write test" << std::endl; + + // create writer to store output hits + WriterT writer(outfilename); + std::cout << " - created writer, writing to:\n" + << " " << outfilename + << std::endl; + + // create frame & collections to hold output hits + auto frame = podio::Frame(); + auto ahits = edm4eic::RawCALOROCHitCollection(); + auto bhits = edm4eic::RawCALOROCHitCollection(); + std::cout << " - created frame/colletions" << std::endl; + + // 1st create a type 1A hit + auto ahit = ahits.create(); + ahit.setType(0); + + /* TODO SET 1A members here */ + std::cout << " - created type 1A hit" << std::endl; + + // 2nd create a type 1B hit + auto bhit = bhits.create(); + bhit.setType(1); + + /* TODO SET 1B members here */ + std::cout << " - created type 1B hit" << std::endl; + + // write hit collections to frame & add a flag to + // indicate this is a test frame + frame.put(std::move(ahits), "RawType1ACALOROCHits"); + frame.put(std::move(bhits), "RawType1BCALOROCHits"); + frame.putParameter("FrameType", "test"); + std::cout << " - Saved hits to frame" << std::endl; + + // write frame, close writer + writer.writeFrame(frame, "events"); + writer.finish(); + std::cout << " - Wrote frame & closed writer\n" + << " - Write test complete!" + << std::endl; + + // exit + return; + + } // end 'WriteHits(std::string&)' + + // ------------------------------------------------------------------------ + //! Test reading CALOROC hits + // ------------------------------------------------------------------------ + void ReadHits(const std::string& infilename) { + + std::cout << "\n --- Begin raw CALOROC read test" << std::endl; + + /* TODO put test here */ + return; + + } // end 'ReadHits(std::string&)' + + // ctor/dtor + TestCALOROCHits(const uint32_t threshold = 1) : m_threshold(threshold) {}; + ~TestCALOROCHits() {}; + +}; // end TestCALOROCHits + + +#endif