LDMX Software
PedestalSubtractor.cxx
1#include "Tracking/Reco/PedestalSubtractor.h"
2
3#include <iostream>
4#include <vector>
5
6#include "Tracking/Event/RawSiStripHit.h"
7#include "Tracking/Reco/SiStripChannelMap.h"
8#include "Tracking/Reco/TrackerPedestals.h"
9
10namespace tracking::reco {
11
13 input_collection_ =
14 ps.get<std::string>("input_collection", input_collection_);
15 input_pass_name_ = ps.get<std::string>("input_pass_name", input_pass_name_);
16 output_collection_ =
17 ps.get<std::string>("output_collection", output_collection_);
18}
19
21 const auto& peds =
23
24 const auto& raw = event.getCollection<ldmx::RawSiStripHit>(input_collection_,
25 input_pass_name_);
26
27 std::vector<ldmx::RawSiStripHit> hits;
28 hits.reserve(raw.size());
29
30 for (const auto& raw_hit : raw) {
31 const auto* ped = peds.find(raw_hit.getFebId(), raw_hit.getHybridId(),
32 raw_hit.getApvId(), raw_hit.getChannel());
33
34 const auto& s = raw_hit.getSamples();
35 std::vector<short> sub(s.begin(), s.end());
36
37 if (!ped) {
38 // Warn once per unknown channel, pass hit through un-subtracted.
39 const auto key =
40 channelmap::channelKey(raw_hit.getFebId(), raw_hit.getHybridId(),
41 raw_hit.getApvId(), raw_hit.getChannel());
42 if (warned_channels_.insert(key).second) {
43 std::cout << "[PedestalSubtractor] WARN: no pedestal for channel "
44 << key << " — passing through un-subtracted" << std::endl;
45 }
46 } else {
47 for (int i = 0; i < channelmap::K_SAMPLES_PER_APV_TRIGGER &&
48 i < static_cast<int>(sub.size());
49 ++i)
50 sub[i] = static_cast<short>(s[i] - ped->mean_[i]);
51 }
52
53 // Emit a pedestal-subtracted RawSiStripHit that keeps the same electronics
54 // identity as the input; only the ADC samples differ.
55 ldmx::RawSiStripHit out(raw_hit.getChannel(), sub, raw_hit.getTime());
56 out.setApvId(raw_hit.getApvId());
57 out.setHybridId(raw_hit.getHybridId());
58 out.setFebId(raw_hit.getFebId());
59 out.setApvTrigger(raw_hit.getApvTrigger());
60 hits.push_back(std::move(out));
61 }
62
63 event.add(output_collection_, hits);
64}
65
66} // namespace tracking::reco
67
#define DECLARE_PRODUCER(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
const T & getCondition(const std::string &condition_name)
Access a conditions object for the current event.
Implements an event buffer system for storing event data.
Definition Event.h:42
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78
Implementation of a raw digitized hit from a silicon strip detector.
Subtract per-channel, per-sample pedestals from a RawSiStripHit collection.
void produce(framework::Event &event) override
Process the event and put new data products into it.
void configure(framework::config::Parameters &ps) override
Callback for the EventProcessor to configure itself from the given set of parameters.
static const std::string CONDITIONS_NAME
Name of the conditions object (must match the python registration).
std::string channelKey(uint8_t feb, uint8_t hybrid, uint8_t apv, uint8_t channel)
Build the per-channel pedestal-map key "feb:hybrid:apv:channel".
constexpr int K_SAMPLES_PER_APV_TRIGGER
Number of ADC samples the APV25 reads out per channel per trigger.