LDMX Software
NtuplizeHgcrocDigiCollection.cxx
1
2#include "Conditions/SimpleTableCondition.h"
3#include "DetDescr/HcalDigiID.h"
4#include "DetDescr/HcalElectronicsID.h"
8
9namespace dqm {
10
12 std::string input_name_, input_pass_, pedestal_table_;
13 int ldmxsw_event_, version_, pf_event_, pf_ticks_, pf_spill_;
14 int raw_id_, adc_, raw_adc_, tot_, toa_, i_sample_;
15 int fpga_, link_, channel_, index_;
16 int section_, layer_, strip_, end_;
17 bool tot_prog_, tot_comp_, aligned_;
18 bool using_eid_, already_aligned_;
19 bool good_link_;
20 TTree* flat_tree_;
21
22 public:
23 NtuplizeHgcrocDigiCollection(std::string const& n, framework::Process& p)
24 : framework::Analyzer(n, p) {}
26
27 void configure(framework::config::Parameters& ps) final override {
28 input_name_ = ps.get<std::string>("input_name");
29 input_pass_ = ps.get<std::string>("input_pass");
30 pedestal_table_ = ps.get<std::string>("pedestal_table");
31 using_eid_ = ps.get<bool>("using_eid");
32 already_aligned_ = ps.get<bool>("already_aligned");
33 }
34
35 void onProcessStart() final override {
37 // cleaned up when histogram file is closed
38 flat_tree_ = new TTree("hgcroc", "Ntuplized HGC ROC Digi Collection");
39
40 flat_tree_->Branch("raw_id", &raw_id_);
41 flat_tree_->Branch("adc", &adc_);
42 flat_tree_->Branch("tot", &tot_);
43 flat_tree_->Branch("toa", &toa_);
44 flat_tree_->Branch("good_link", &good_link_);
45 flat_tree_->Branch("raw_adc", &raw_adc_);
46 flat_tree_->Branch("i_sample", &i_sample_);
47 flat_tree_->Branch("ldmxsw_event", &ldmxsw_event_);
48 if (not already_aligned_) {
49 flat_tree_->Branch("pf_event", &pf_event_);
50 flat_tree_->Branch("pf_spill", &pf_spill_);
51 flat_tree_->Branch("pf_ticks", &pf_ticks_);
52 }
53 flat_tree_->Branch("tot_prog", &tot_prog_);
54 flat_tree_->Branch("tot_comp", &tot_comp_);
55 flat_tree_->Branch("aligned", &aligned_);
56 if (using_eid_) {
57 flat_tree_->Branch("fpga", &fpga_);
58 flat_tree_->Branch("link", &link_);
59 flat_tree_->Branch("channel", &channel_);
60 flat_tree_->Branch("index", &index_);
61 } else {
62 flat_tree_->Branch("section", &section_);
63 flat_tree_->Branch("layer", &layer_);
64 flat_tree_->Branch("strip", &strip_);
65 flat_tree_->Branch("end", &end_);
66 }
67 }
68
69 void analyze(const framework::Event& event) final override;
70};
71
73 // get the reconstruction parameters
74 auto pedestal_table{
78
79 ldmxsw_event_ = event.getEventNumber();
80
81 bool is_simulation = not event.getEventHeader().isRealData();
82
83 if (not is_simulation) {
84 if (already_aligned_) {
85 aligned_ = event.getObject<bool>(input_name_ + "Aligned", input_pass_);
86 } else {
87 aligned_ = false;
88 version_ = event.getObject<int>(input_name_ + "Version", input_pass_);
89 pf_event_ = event.getObject<int>(input_name_ + "Number", input_pass_);
90 pf_ticks_ = event.getObject<int>(input_name_ + "Ticks", input_pass_);
91 pf_spill_ = event.getObject<int>(input_name_ + "Spill", input_pass_);
92 }
93 } else {
94 aligned_ = true;
95 version_ = 0;
96 pf_event_ = ldmxsw_event_;
97 pf_ticks_ = 0;
98 pf_spill_ = 0;
99 }
100
101 std::vector<bool> good_bxheader;
102 std::vector<bool> good_trailer;
103
104 if (not is_simulation) {
105 good_bxheader =
106 event.getCollection<bool>(input_name_ + "GoodLinkHeader", input_pass_);
107 good_trailer =
108 event.getCollection<bool>(input_name_ + "GoodLinkTrailer", input_pass_);
109 }
110
111 auto const& digis{
112 event.getObject<ldmx::HgcrocDigiCollection>(input_name_, input_pass_)};
113
114 for (std::size_t i_digi{0}; i_digi < digis.size(); i_digi++) {
115 auto d{digis.getDigi(i_digi)};
116 raw_id_ = static_cast<int>(d.id());
117 if (using_eid_) {
118 ldmx::HcalElectronicsID eid(d.id());
119 fpga_ = eid.fiber();
120 link_ = eid.elink();
121 if (!is_simulation) {
122 good_link_ = (good_bxheader.at(link_) and good_trailer.at(link_));
123 } else {
124 good_link_ = true;
125 }
126 channel_ = eid.channel();
127 index_ = eid.index();
128 } else {
129 ldmx::HcalDigiID detid(d.id());
130 ldmx::HcalElectronicsID eid = detmap.get(detid);
131 int link = eid.elink();
132 if (!is_simulation) {
133 good_link_ = (good_bxheader.at(link) and good_trailer.at(link));
134 } else {
135 good_link_ = true;
136 }
137 section_ = detid.section();
138 layer_ = detid.layer();
139 strip_ = detid.strip();
140 end_ = detid.end();
141 }
142
143 for (i_sample_ = 0; i_sample_ < digis.getNumSamplesPerDigi(); i_sample_++) {
144 tot_prog_ = d.at(i_sample_).isTOTinProgress();
145 tot_comp_ = d.at(i_sample_).isTOTComplete();
146 tot_ = d.at(i_sample_).tot();
147 toa_ = d.at(i_sample_).toa();
148 int adc_t = d.at(i_sample_).adcT();
149 raw_adc_ = adc_t;
150 adc_ = adc_t - pedestal_table.get(d.id(), 0);
151 flat_tree_->Fill();
152 }
153 }
154}
155
156} // namespace dqm
157
Base classes for all user event processing components to extend.
#define DECLARE_ANALYZER(CLASS)
Macro which allows the framework to construct an analyzer given its name during configuration.
Class which contains logic for how the detector items connect to and relate with the reconstruction c...
Class that represents a digitized hit in a calorimeter cell readout by an HGCROC.
void onProcessStart() final override
Callback for the EventProcessor to take any necessary action when the processing of events starts,...
void configure(framework::config::Parameters &ps) final override
Callback for the EventProcessor to configure itself from the given set of parameters.
void analyze(const framework::Event &event) final override
Process the event and make histograms or summaries.
Base class for a module which does not produce a data product.
const T & getCondition(const std::string &condition_name)
Access a conditions object for the current event.
TDirectory * getHistoDirectory()
Access/create a directory in the histogram file for this event processor to create histograms and ana...
Implements an event buffer system for storing event data.
Definition Event.h:42
Class which represents the process under execution.
Definition Process.h:36
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
static constexpr const char * CONDITIONS_OBJECT_NAME
The name of the EID <-> DetID map for the ECal.
Extension of HcalAbstractID providing access to HCal digi information.
Definition HcalDigiID.h:13
int strip() const
Get the value of the 'strip' field from the ID.
Definition HcalDigiID.h:99
int section() const
Get the value of the 'section' field from the ID.
Definition HcalDigiID.h:75
int layer() const
Get the value of the layer field from the ID.
Definition HcalDigiID.h:81
int end() const
Get the value of the 'end' field from the ID.
Definition HcalDigiID.h:105
Identifies a location in the Hcal readout chain.
unsigned int index() const
Get the compact index value.
int elink() const
Get the value of the elink from the ID.
int fiber() const
Get the value of the fiber from the ID.
int channel() const
Get the value of the channel from the ID.
Represents a collection of the digi hits readout by an HGCROC.