Skip to content
Merged
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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

// Copyright 2020, Jefferson Science Associates, LLC.
// Subject to the terms in the LICENSE file found in the top-level directory.

#pragma once
#include <JANA/JObject.h>
#include <cstdint>

struct ADCPulse: public JObject {

JOBJECT_PUBLIC(ADCPulse)

uint32_t crate;
uint32_t slot;
uint32_t channel;

uint32_t amplitude;
uint32_t pedestal;
uint32_t integral;
uint32_t timestamp;

void Summarize(JObjectSummary& summary) const override {
summary.add(crate, NAME_OF(crate), "%d");
summary.add(slot, NAME_OF(slot), "%d");
summary.add(channel, NAME_OF(channel), "%d");
summary.add(amplitude, NAME_OF(amplitude), "%d", "Amplitude");
summary.add(pedestal, NAME_OF(pedestal), "%d", "Pedestal");
summary.add(integral, NAME_OF(integral), "%d", "Integral");
summary.add(timestamp, NAME_OF(timestamp), "%d", "Timestamp");
}
};


Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

// Copyright 2020, Jefferson Science Associates, LLC.
// Subject to the terms in the LICENSE file found in the top-level directory.

#pragma once
#include <JANA/JObject.h>
#include <cstdint>

struct ADCWaveform: public JObject {

JOBJECT_PUBLIC(ADCWaveform)

uint32_t crate;
uint32_t slot;
uint32_t channel;

uint32_t pedestal;
uint32_t timestamp;
std::vector<uint32_t> samples;

void Summarize(JObjectSummary& summary) const override {

std::ostringstream oss;
for (auto sample: samples) {
oss << sample << ", ";
}

summary.add(crate, NAME_OF(crate), "%d");
summary.add(slot, NAME_OF(slot), "%d");
summary.add(channel, NAME_OF(channel), "%d");
summary.add(pedestal, NAME_OF(pedestal), "%d");
summary.add(timestamp, NAME_OF(timestamp), "%d");
summary.add(oss.str().c_str(), NAME_OF(samples), "%s");
}
};


Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

// Copyright 2020-2025, Jefferson Science Associates, LLC.
// Subject to the terms in the LICENSE file found in the top-level directory.

#pragma once
#include <JANA/JObject.h>
#include <cstdint>


struct TDCHit: public JObject {

JOBJECT_PUBLIC(TDCHit)

uint32_t cell_id; // Cell's id

double x; // x location of cell's center [cm]
double y; // y location of cell's center [cm]
double z; // z location of cell's center [cm]

double time; // Time [ns]


// Define a constructor that forces all fields to be initialized
TDCHit(uint32_t cell_id, double x, double y, double z, uint64_t time)
: cell_id(cell_id), x(x), y(y), z(z), time(time) {}


void Summarize(JObjectSummary& summary) const override {
summary.add(cell_id, NAME_OF(cell_id), "%d", "Cell ID");
summary.add(x, NAME_OF(x), "%f", "x location of cell center [cm]");
summary.add(y, NAME_OF(y), "%f", "y location of cell center [cm]");
summary.add(z, NAME_OF(z), "%f", "z location of cell center [cm]");
summary.add(time, NAME_OF(time), "%d", "Time [ns]");
}
};


Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

// Copyright 2020, Jefferson Science Associates, LLC.
// Subject to the terms in the LICENSE file found in the top-level directory.

#pragma once
#include <JANA/JObject.h>
#include <cstdint>

struct TDCPulse: public JObject {

JOBJECT_PUBLIC(TDCPulse)

uint32_t crate;
uint32_t slot;
uint32_t channel;

uint32_t coarse_time;
uint32_t fine_time;
bool is_leading;

void Summarize(JObjectSummary& summary) const override {
summary.add(crate, NAME_OF(crate), "%d");
summary.add(slot, NAME_OF(slot), "%d");
summary.add(channel, NAME_OF(channel), "%d");
summary.add(coarse_time, NAME_OF(coarse_time), "%d");
summary.add(fine_time, NAME_OF(fine_time), "%d");
summary.add(is_leading, NAME_OF(is_leading), "%d");
}
};


Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "CalorimeterHit.h"
#include "CalorimeterCluster.h"
#include "SimParticle.h"
#include "ADCHit.h"
#include "ADCPulse.h"

#include <JANA/JEventProcessor.h>

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

# `liblw_hit_reco_common` is a library that includes our hit reconstruction
# machinery, specifically the TranslationTable service and RecoHit factory.
# The algorithm is simple enough that we keep it in the factory for now.

add_jana_library(lw_hit_reco_common
SOURCES
HitReconstruction_factory.cc
TranslationTable_service.cc
PUBLIC_HEADER
HitReconstruction_factory.h
TranslationTable_service.h
TESTS
HitReconstruction_factory_tests.cc
)

# `add_jana_library` will create a target for us, but we still need to link it against
# its various dependencies by ourselves.

target_link_libraries(lw_hit_reco_common PUBLIC lw_datamodel)

add_jana_plugin(lw_hit_reco SOURCES hit_reco_plugin.cc)
target_link_libraries(lw_hit_reco PUBLIC lw_hit_reco_common)

Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

#include "HitReconstruction_factory.h"
#include "ADCPulse.h"
#include <JANA/JEvent.h>
#include "CalorimeterHit.h"

HitReconstruction_factory::HitReconstruction_factory() {
m_adc_pulses_in.SetRequestedDatabundleNames({"raw"});
m_calo_hits_out.SetShortNames({"rechits"});
}

void HitReconstruction_factory::ChangeRun(const JEvent& event) {

// We use ChangeRun to obtain any run-level data we need. This is ONLY called when the run number has changed.
// We cache the run-encoded data on the factory directly (Remember that there are many factories in memory at any given time!)
// If the data is large, we use shared_ptrs (under the hood here) to ensure that there is only one copy in memory, and that
// it gets deleted once the run number changes.

m_lookup_table = m_translation_table_svc->GetDAQLookupTable(event.GetRunNumber());
}

void HitReconstruction_factory::Process(const JEvent&) {

// We iterate over EACH input databundle we've been provided
for (size_t pulse_databundle_index = 0; pulse_databundle_index<m_adc_pulses_in->size(); ++pulse_databundle_index) {


// Unlike ouptuts and regular inputs, variadic inputs distinguish between 'requested' and 'realized' databundles.
// This is because variadic inputs may be flexible, i.e. they may be optional, or may use EmptyInputPolicy::IncludeEverything.

auto name = m_adc_pulses_in.GetRealizedDatabundleNames().at(pulse_databundle_index);

// In this simple example, we assume a one-to-one correspondence between input ADCPulses and output CalorimeterHits.
if (m_adc_pulses_in->size() != m_calo_hits_out->size()) {
throw JException("Found wrong number of ADCPulse inputs!");
}

LOG_DEBUG(GetLogger()) << "Reconstructing hits. "
<< m_adc_pulses_in.GetRealizedDatabundleNames().at(pulse_databundle_index)
<< " -> "
<< m_calo_hits_out.GetUniqueNames().at(pulse_databundle_index);

// Process each pulse in this databundle

for (const auto* pulse: m_adc_pulses_in->at(pulse_databundle_index)) {

// Translate from DAQ coordinates to detector coordinates

auto& row = m_lookup_table->at({pulse->crate, pulse->slot, pulse->channel});
auto& detector_coords = std::get<0>(row);
auto& calib = std::get<1>(row);

auto hit = new CalorimeterHit(detector_coords.cell_id,
detector_coords.indices.at(0), detector_coords.indices.at(1),
detector_coords.x, detector_coords.y, detector_coords.z,
0, 0);

// Apply gains and offsets

hit->energy = ((pulse->integral - pulse->pedestal) * calib.gain) - calib.pedestal;
hit->time = (pulse->timestamp * calib.tick_period) - calib.time_offset;

// Add hit to corresponding output databundle

m_calo_hits_out->at(pulse_databundle_index).push_back(hit);
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

#pragma once
#include <JANA/JFactory.h>
#include "TranslationTable_service.h"
#include <CalorimeterHit.h>
#include <ADCPulse.h>


class HitReconstruction_factory : public JFactory {

private:

VariadicInput<ADCPulse> m_adc_pulses_in {this};

VariadicOutput<CalorimeterHit> m_calo_hits_out {this};

Service<TranslationTable_service> m_translation_table_svc {this};

TranslationTable_service::DAQLookupTable m_lookup_table;

public:

HitReconstruction_factory();

void ChangeRun(const JEvent& event) override;

void Process(const JEvent& event) override;

};



Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

#define CATCH_CONFIG_MAIN
#include <catch.hpp>
#include <JANA/JApplication.h>
#include "TranslationTable_service.h"

TEST_CASE("TranslationTable_service_BasicTests") {
JApplication app;

auto sut = std::make_shared<TranslationTable_service>();
sut->AddHardcodedRow(22,
{.crate=1, .slot=1, .channel=1},
{.detector_id = 7, .cell_id = 9, .indices = {1,2,3}, .x = 0.4, .y = 0.8, .z = 0.0}, {});

sut->AddHardcodedRow(22,
{.crate=1, .slot=1, .channel=2},
{.detector_id = 7, .cell_id = 10, .indices = {1,2,4}, .x = 0.5, .y = 0.8, .z = 0.0}, {});

sut->AddHardcodedRow(22,
{.crate=1, .slot=2, .channel=1},
{.detector_id = 7, .cell_id = 11, .indices = {1,2,5}, .x = 0.6, .y = 0.8, .z = 0.0}, {});

app.ProvideService<TranslationTable_service>(sut);
app.Initialize();
auto tt = app.template GetService<TranslationTable_service>();
auto lookup_table = tt->GetDAQLookupTable(22);
const auto& row = lookup_table->at({1, 1, 2});
REQUIRE(std::get<0>(row).detector_id == 7);
REQUIRE(std::get<0>(row).cell_id== 10);
REQUIRE(std::get<0>(row).indices.at(2) == 4);
}

TEST_CASE("RecHit_factory_BasicTests") {
//REQUIRE(0 == 1);
}
Loading