7#include "TrigScint/Event/TrigScintHit.h"
8#include "TrigScint/Event/TrigScintQIEDigis.h"
9#include "TrigScint/SimQIE.h"
13TrigScintRecHitProducer::TrigScintRecHitProducer(
const std::string& name,
15 : Producer(name, process) {}
17TrigScintRecHitProducer::~TrigScintRecHitProducer() {}
19void TrigScintRecHitProducer::configure(
21 pedestal_ = parameters.
get<
double>(
"pedestal");
22 gain_ = parameters.
get<
double>(
"gain");
23 mev_per_mip_ = parameters.
get<
double>(
"mev_per_mip");
24 pe_per_mip_ = parameters.
get<
double>(
"pe_per_mip");
25 input_collection_ = parameters.
get<std::string>(
"input_collection");
26 input_pass_name_ = parameters.
get<std::string>(
"input_pass_name");
27 output_collection_ = parameters.
get<std::string>(
"output_collection");
28 sample_of_interest_ = parameters.
get<
int>(
"sample_of_interest");
30 use_calib_file_ = parameters.
get<
bool>(
"use_calib_file",
false);
31 calib_file_ = parameters.
get<std::string>(
"calib_file", std::string{
""});
35 integration_window_ = parameters.
get<
int>(
"integration_window", 0);
37 if (use_calib_file_) {
38 if (calib_file_.empty()) {
39 throw std::runtime_error(
40 "TrigScintRecHitProducer: use_calib_file=true but calib_file is "
43 readCalib(calib_file_, &gains_, &pedestals_);
51 input_collection_, input_pass_name_)};
53 std::vector<ldmx::TrigScintHit> trig_scint_hits;
54 trig_scint_hits.reserve(digis.size());
56 for (
const auto& digi : digis) {
58 auto adc{digi.getADC()};
59 auto tdc{digi.getTDC()};
66 const int soi = sample_of_interest_;
67 if (soi < 0 || soi >=
int(adc.size()) || soi >=
int(tdc.size())) {
70 if (soi + 1 <
int(adc.size())) {
81 int end = int(adc.size());
82 if (integration_window_ > 0) {
83 end = std::min(start + integration_window_,
int(adc.size()));
85 const int n_samp = std::max(0, end - start);
87 float integrated_charge = 0.f;
88 for (
int i = start; i < end; ++i) {
89 integrated_charge += qie.
adc2Q(adc[i]);
92 double ped = pedestal_;
95 if (use_calib_file_) {
96 const int ch = digi.getChanID();
97 if (ch >= 0 && ch <
int(pedestals_.size())) ped = pedestals_[ch];
98 if (ch >= 0 && ch <
int(gains_.size())) gain = gains_[ch];
101 const float ped_subtr_q = integrated_charge - float(n_samp) * float(ped);
103 hit.
setEnergy(ped_subtr_q * 6250.f /
float(gain) *
float(mev_per_mip_) /
105 hit.
setPE(ped_subtr_q * 6250.f /
float(gain));
107 trig_scint_hits.push_back(hit);
109 event.add(output_collection_, trig_scint_hits);
112void TrigScintRecHitProducer::readCalib(
const std::string& filename,
113 std::vector<double>* gains,
114 std::vector<double>* pedestals) {
115 std::ifstream infile(filename);
117 throw std::runtime_error(
118 "TrigScintRecHitProducer: Could not open calibration file: " +
126 while (infile >> ch >> gain >> ped) {
127 const int bar_id = int(ch);
128 if (bar_id < 0)
continue;
129 if (bar_id >=
int(gains->size())) {
130 gains->resize(bar_id + 1, 0.0);
131 pedestals->resize(bar_id + 1, 0.0);
133 (*gains)[bar_id] = gain;
134 (*pedestals)[bar_id] = ped;
#define DECLARE_PRODUCER(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Class that builds recHits.
Implements an event buffer system for storing event data.
Class which represents the process under execution.
Class encapsulating parameters for configuring a processor.
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
void setTime(float time)
Set the time of the hit [ns].
void setAmplitude(float amplitude)
Set the amplitude of the hit, which is proportional to the signal in the calorimeter cell without sam...
void setEnergy(float energy)
Set the calorimetric energy of the hit, corrected for sampling factors [MeV].
void setPE(const float PE)
Set hit pe.
void setBarID(const int barID)
Set hit bar ID.
void setBeamEfrac(const float beamEfrac)
Set beam energy fraction of hit.
void setModuleID(const int moduleID)
Set hit module ID.
class for simulating QIE chip output
float adc2Q(int ADC)
Converting ADC back to charge.
class for storing QIE output
Organizes digis into TrigScintHits, linearizes TDC and ADC info, and converts amplitudes to PEs.