LDMX Software
run_hgcroc.cxx
1
2#include "Conditions/SimpleTableCondition.h"
3#include "Framework/Configure/Parameters.h"
5#include "TFile.h"
6#include "TTree.h"
7#include "Tools/HgcrocEmulator.h"
8
9int main() {
10 double gain = 320. / 20. / 1024;
11
13 parameters.addParameter("clockCycle", 25.);
14 parameters.addParameter("timingJitter", 0.25);
15 parameters.addParameter("nADCs", 10);
16 parameters.addParameter("iSOI", 0);
17 parameters.addParameter("rateUpSlope", -0.345);
18 parameters.addParameter("timeUpSlope", 70.6547);
19 parameters.addParameter("rateDnSlope", 0.140068);
20 parameters.addParameter("timeDnSlope", 87.7649);
21 parameters.addParameter("timePeak", 77.732);
22 parameters.addParameter("noiseRMS",
23 (700. + 25. * 20.) * (0.162 / 1000.) / 20.);
24 parameters.addParameter("noise", true);
25
27 "RUN_HGCROC_TABLE",
28 {"PEDESTAL", "MEAS_TIME", "PAD_CAPACITANCE", "TOT_MAX", "DRAIN_RATE",
29 "GAIN", "READOUT_THRESHOLD", "TOA_THRESHOLD", "TOT_THRESHOLD"});
30 chip_conditions.setIdMask(0); // all ids are the same
31 chip_conditions.add(
32 0,
33 {
34 50., // PEDESTAL
35 0.0, // MEAS_TIME - ns
36 20., // PAD_CAPACITANCE - pF
37 200., // TOT_MAX - ns - maximum time chip would be in TOT mode
38 10240. / 200., // DRAIN_RATE - fC/ns
39 gain, // GAIN - 320. fC / 1024. counts / 20 pF - conversion from ADC
40 // to mV
41 50. + 3., // READOUT_THRESHOLD - 3 ADC counts above pedestal
42 50. * gain + 5 * 37 * 0.162 /
43 20., // TOA_THRESHOLD - mV - ~5 MIPs above pedestal
44 50. * gain + 50 * 37 * 0.162 /
45 20., // TOT_THRESHOLD - mV - ~50 MIPs above pedestal
46 });
47
48 ldmx::HgcrocEmulator hgcroc(parameters);
49 hgcroc.seedGenerator(420);
50 hgcroc.condition(chip_conditions);
51
52 double readout_threshold = gain * 53.;
53 double tot_threshold = 15.76225;
54
55 float min_voltage_test{0.5};
56 float max_voltage_test{20.};
57 float voltage_step{0.1};
58 int num_voltages{int((max_voltage_test - min_voltage_test) / voltage_step)};
59
60 std::vector<float> time_tests{
61 0., // nominal in-time with light speed particle
62 0.2, // off-peak but within normal shower time
63 1.0, // very late in shower
64 20., // totally separate, probably cosmic
65 -8.0, // pre-hit (e.g. cosmic)
66 };
67
68 // arbitrary cell id
69 unsigned int cell_id = 0x14002020;
70
71 TFile f("hgcroc_emulation.root", "RECREATE");
72 TTree t("hgcroc", "hgcroc");
73
74 float voltage, time;
75 int adc{0}, tdc{0};
76 bool readout, sim_totmode, digitized, digi_totmode;
77
78 t.Branch("sim_voltage", &voltage);
79 t.Branch("sim_time", &time);
80 t.Branch("sim_readout", &readout);
81 t.Branch("sim_totmode", &sim_totmode);
82
83 t.Branch("digitized", &digitized);
84 t.Branch("adc", &adc);
85 t.Branch("digi_totmode", &digi_totmode);
86 t.Branch("tdc", &tdc);
87
89 all_digis.setNumSamplesPerDigi(10);
90 all_digis.setSampleOfInterestIndex(0);
91
92 unsigned int last_digi = 0;
93 std::vector<std::pair<double, double>> the_pulse(1, {0., 0.});
94 for (const float ti : time_tests) {
95 for (int iv{0}; iv < num_voltages; iv++) {
96 voltage = min_voltage_test + iv * voltage_step;
97 time = ti;
98 readout = (voltage > readout_threshold);
99 sim_totmode = (voltage > tot_threshold);
100
101 the_pulse[0].first = voltage;
102 the_pulse[0].second = time;
103
104 std::vector<ldmx::HgcrocDigiCollection::Sample> digi_to_add;
105 digitized = hgcroc.digitize(cell_id, the_pulse, digi_to_add);
106 if (digitized) {
107 all_digis.addDigi(cell_id, digi_to_add);
108
109 auto digi = all_digis.getDigi(last_digi++);
110
111 digi_totmode = digi.isTOT();
112 if (digi_totmode) {
113 adc = 0;
114 tdc = digi.tot();
115 } else {
116 adc = digi.soi().adc_t();
117 tdc = 0;
118 }
119 } else {
120 adc = -1;
121 tdc = -1;
122 }
123 t.Fill();
124 }
125 }
126
127 t.Write();
128 f.Close();
129}
Class that represents a digitized hit in a calorimeter cell readout by an HGCROC.
void setIdMask(unsigned int mask)
Set an AND mask to be applied to the id.
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
void addParameter(const std::string &name, const T &value)
Add a parameter to the parameter list.
Definition Parameters.h:55
bool isTOT() const
Check if this DIGI is a TOT measurement.
Represents a collection of the digi hits readout by an HGCROC.
void setNumSamplesPerDigi(unsigned int n)
Set number of samples for each digi.
void setSampleOfInterestIndex(unsigned int n)
Set index of sample of interest.
void addDigi(unsigned int id, const std::vector< Sample > &digi)
Add samples to collection.
const HgcrocDigi getDigi(unsigned int digiIndex) const
Get samples for the input digi index.
Emulate the digitization procedure performed by the HGCROC.