Skip to content

Add type for HGC/CALOROC output #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions edm4eic.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having just fixed a whole bunch of signed/unsigned comparisons, can we please use unsigned ints where appropriate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Most of these can be uint32_ts...

Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 10 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -70,4 +79,4 @@ if (nlohmann_json_FOUND)
set_test_env(convert_events)
endif()

add_subdirectory(utils)
add_subdirectory(utils)
21 changes: 21 additions & 0 deletions test/test_caloroc_hits.cc
Original file line number Diff line number Diff line change
@@ -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<podio::ROOTWriter, podio::ROOTReader> 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;

}
126 changes: 126 additions & 0 deletions test/test_caloroc_hits.h
Original file line number Diff line number Diff line change
@@ -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 <array>
#include <iostream>
#include <string>



// ============================================================================
//! 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 WriterT, class ReaderT>
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<uint32_t, 112> 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<WriterT, ReaderT>


#endif