LDMX Software
HcalAlignPolarfires.cxx
1
2#include "Hcal/HcalAlignPolarfires.h"
3namespace hcal {
5HcalAlignPolarfires::PolarfireQueueEntry::PolarfireQueueEntry(
6 const framework::Event& event, const std::string& input_name,
7 const std::string& input_pass, std::pair<int, int>& spill_counter) {
8 int spilln = event.getObject<int>(input_name + "Spill", input_pass);
9 if (spilln != spill_counter.second) {
10 spill_counter.first++;
11 spill_counter.second = spilln;
12 }
13 spill = spill_counter.first;
14 ticks = event.getObject<int>(input_name + "Ticks", input_pass);
15 digis = event.getObject<ldmx::HgcrocDigiCollection>(input_name, input_pass);
16}
17
19 input_names_ = ps.getParameter<std::vector<std::string>>("input_names");
20 input_pass_ = ps.getParameter<std::string>("input_pass");
21 output_name_ = ps.getParameter<std::string>("output_name");
22 max_tick_diff_ = ps.getParameter<int>("max_tick_diff");
23} // configure
24
26 // put next package of decoding into the queues
28 pf1_queue.emplace(event, input_names_[1], input_pass_, pf1_spill_counter);
29
30 // remove empty events from front of queues for end-of-file condition
31 while (pf0_queue.size() > 0 and pf0_queue.front().digis.getNumDigis() == 0)
32 pf0_queue.pop();
33 while (pf1_queue.size() > 0 and pf1_queue.front().digis.getNumDigis() == 0)
34 pf1_queue.pop();
35
36 bool aligned{false};
38 if (pf0_queue.size() > 0 and pf1_queue.size() > 0) {
39 // we have non-empty events in the queues, start alignment procedure
40 if (pf0_queue.front().same_event(pf1_queue.front())) {
41 // same spill and ticks within max_tick_diff_ of each other
42 // add them together and put them into same object
43 merged = pf0_queue.front().digis;
44 const auto& unmerged{pf1_queue.front().digis};
45 for (int i{0}; i < unmerged.getNumDigis(); i++) {
46 auto digi{unmerged.getDigi(i)};
47 std::vector<ldmx::HgcrocDigiCollection::Sample> samples;
48 for (int j{0}; j < unmerged.getNumSamplesPerDigi(); j++) {
49 samples.push_back(digi.at(i));
50 }
51 merged.addDigi(digi.id(), samples);
52 }
53 aligned = true;
54 pf0_queue.pop();
55 pf1_queue.pop();
57 } else if (pf0_queue.front().earlier_event(pf1_queue.front())) {
58 // should add pf0 but signal event is unmerged
59 merged = pf0_queue.front().digis;
60 pf0_queue.pop();
62 } else {
63 // should add pf1 but signal event is unmerged
64 merged = pf1_queue.front().digis;
65 pf1_queue.pop();
67 }
68 } else if (pf0_queue.size() > 0) {
69 // only pf0 has non-empty events left
70 // should add pf0 but signal event is unmerged
71 merged = pf0_queue.front().digis;
72 pf0_queue.pop();
74 } else if (pf1_queue.size() > 0) {
75 // only pf1 has non-empty events left
76 // should add pf1 but signal event is unmerged
77 merged = pf1_queue.front().digis;
78 pf1_queue.pop();
80 } else {
81 // no more events, both decoders are returning empty events
82 abortEvent();
83 }
84
85 event.add(output_name_, merged);
86 event.add(output_name_ + "Aligned", aligned);
87} // produce
88} // namespace hcal
89
90DECLARE_PRODUCER_NS(hcal, HcalAlignPolarfires);
#define DECLARE_PRODUCER_NS(NS, CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
void abortEvent()
Abort the event immediately.
void setStorageHint(framework::StorageControl::Hint hint)
Mark the current event as having the given storage control hint from this module.
Implements an event buffer system for storing event data.
Definition Event.h:41
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89
void configure(framework::config::Parameters &ps) override
Callback for the EventProcessor to configure itself from the given set of parameters.
std::vector< std::string > input_names_
input decoded objects (vector index == polarfire index)
static int max_tick_diff_
number of 5MHz ticks difference to consider polarfires aligned
void produce(framework::Event &event) override
Process the event and put new data products into it.
std::pair< int, int > pf0_spill_counter
spill counter
std::queue< PolarfireQueueEntry > pf0_queue
queue of unmatched digis
std::string input_pass_
pass name for decoded objects
std::string output_name_
output object name
Represents a collection of the digi hits readout by an HGCROC.
void addDigi(unsigned int id, const std::vector< Sample > &digi)
Add samples to collection.
constexpr StorageControl::Hint hint_shouldKeep
storage control hint alias for backwards compatibility
constexpr StorageControl::Hint hint_shouldDrop
storage control hint alias for backwards compatibility