LDMX Software
TrigScintDigiProducer.cxx
2
3namespace trigscint {
4
5TrigScintDigiProducer::TrigScintDigiProducer(const std::string &name,
6 framework::Process &process)
7 : Producer(name, process) {}
8
9void TrigScintDigiProducer::configure(framework::config::Parameters &ps) {
10 // Configure this instance of the producer
11 strips_per_array_ = ps.get<int>("number_of_strips");
12 number_of_arrays_ = ps.get<int>("number_of_arrays");
13 mean_noise_ = ps.get<double>("mean_noise");
14 mev_per_mip_ = ps.get<double>("mev_per_mip");
15 pe_per_mip_ = ps.get<double>("pe_per_mip");
16 input_collection_ = ps.get<std::string>("input_collection");
17 input_pass_name_ = ps.get<std::string>("input_pass_name");
18 output_collection_ = ps.get<std::string>("output_collection");
19 sim_particles_passname_ = ps.get<std::string>("sim_particles_passname");
20}
21
22void TrigScintDigiProducer::onNewRun(const ldmx::RunHeader &) {
23 noise_generator_ = std::make_unique<ldmx::NoiseGenerator>(mean_noise_, false);
24 noise_generator_->setNoiseThreshold(1);
25 // Set up seeds
26 const auto &rseed = getCondition<framework::RandomNumberSeedService>(
28
29 noise_generator_->seedGenerator(
30 rseed.getSeed("TrigScintDigiProducer::NoiseGenerator"));
31 // Random number generator for module id
32 rng_.seed(rseed.getSeed("TrigScintDigiProducer"));
33}
34
35ldmx::TrigScintID TrigScintDigiProducer::generateRandomID(int module) {
36 // Uniform distributions for integer generation
37 std::uniform_int_distribution<int> strips_dist(0, strips_per_array_ - 1);
38 ldmx::TrigScintID temp_id(module, strips_dist(rng_));
39 if (module >= TrigScintSection::NUM_SECTIONS) {
40 ldmx_log(fatal) << "TrigScintSection is not known";
41 }
42
43 return temp_id;
44}
45
46void TrigScintDigiProducer::produce(framework::Event &event) {
47 std::map<ldmx::TrigScintID, int> cell_pes, cell_min_p_es;
48 std::map<ldmx::TrigScintID, float> xpos, ypos, zpos, edep, time, beam_frac;
49 std::set<ldmx::TrigScintID> noise_hit_i_ds;
50
51 auto num_rec_hits{0};
52
53 // looper over sim hits and aggregate energy depositions for each detID
54 const auto sim_hits{event.getCollection<ldmx::SimCalorimeterHit>(
55 input_collection_, input_pass_name_)};
56 auto particle_map{event.getMap<int, ldmx::SimParticle>(
57 "SimParticles", sim_particles_passname_)};
58
59 int module{-1};
60 for (const auto &sim_hit : sim_hits) {
61 ldmx::TrigScintID id(sim_hit.getID());
62
63 // Just set the module ID to use for noise hits here. Given that
64 // we are currently processing a single module at a time, setting
65 // it within the loop shouldn't matter.
66 module = id.module();
67 std::vector<float> position = sim_hit.getPosition();
68 ldmx_log(trace) << " Module ID = " << id.raw();
69
70 // check if hits is from beam electron and, if so, add to beamFrac
71 for (int i = 0; i < sim_hit.getNumberOfContribs(); i++) {
72 auto contrib = sim_hit.getContrib(i);
73
74 ldmx_log(trace) << "contrib " << i << " trackID: " << contrib.track_id_
75 << " pdgID: " << contrib.pdg_code_
76 << " edep: " << contrib.edep_;
77 ldmx_log(trace) << "\t particle id: "
78 << particle_map[contrib.track_id_].getPdgID()
79 << " particle status: "
80 << particle_map[contrib.track_id_].getGenStatus();
81
82 if (particle_map[contrib.track_id_].getPdgID() == 11 &&
83 particle_map[contrib.track_id_].getGenStatus() == 1) {
84 if (beam_frac.find(id) == beam_frac.end()) {
85 beam_frac[id] = contrib.edep_;
86 } else {
87 beam_frac[id] += contrib.edep_;
88 }
89 }
90 }
91
92 // for now, we take an energy weighted average of the hit in each strip to
93 // simulate the hit position. AJW: these should be dropped, they are likely
94 // to lead to a problem since we can't measure them anyway except roughly y
95 // and z, which is encoded in the ids.
96 if (edep.find(id) == edep.end()) {
97 // first hit, initialize
98 edep[id] = sim_hit.getEdep();
99 time[id] = sim_hit.getTime() * sim_hit.getEdep();
100 xpos[id] = position[0] * sim_hit.getEdep();
101 ypos[id] = position[1] * sim_hit.getEdep();
102 zpos[id] = position[2] * sim_hit.getEdep();
103 num_rec_hits++;
104
105 } else {
106 // not first hit, aggregate, and store the largest radius hit
107 xpos[id] += position[0] * sim_hit.getEdep();
108 ypos[id] += position[1] * sim_hit.getEdep();
109 zpos[id] += position[2] * sim_hit.getEdep();
110 edep[id] += sim_hit.getEdep();
111 // AJW: need to figure out a better way to model this...
112 time[id] += sim_hit.getTime() * sim_hit.getEdep();
113 }
114 }
115
116 // Create the container to hold the digitized trigger scintillator hits.
117 std::vector<ldmx::TrigScintHit> trig_scint_hits;
118
119 // loop over detIDs and simulate number of PEs
120 for (std::map<ldmx::TrigScintID, float>::iterator it = edep.begin();
121 it != edep.end(); ++it) {
122 ldmx::TrigScintID id(it->first);
123
124 double dep_energy = edep[id];
125 time[id] = time[id] / edep[id];
126 xpos[id] = xpos[id] / edep[id];
127 ypos[id] = ypos[id] / edep[id];
128 zpos[id] = zpos[id] / edep[id];
129 // mean number of photoelectrons produced for the given deposited energy
130 double mean_pe = dep_energy / mev_per_mip_ * pe_per_mip_;
131 std::poisson_distribution<int> poisson_dist(mean_pe + mean_noise_);
132 cell_pes[id] = poisson_dist(rng_);
133 // energy corresponding to the number of PEs observed
134 // the minimum number of PEs is the mean number of PEs minus the noise
135 double energy_per_pe = mev_per_mip_ / pe_per_mip_;
136 double cell_energy = energy_per_pe * cell_pes[id];
137
138 // If a cell has a PE count above threshold, persit the hit.
139 // Thresholds are introduced (and configurable) in clustering.
140 // the cell PE >=1 suppresses artifical noise that is below one light
141 // quantum in the SiPM and unphysical.
142 if (cell_pes[id] >= 1) {
144 hit.setID(id.raw());
145 hit.setPE(cell_pes[id]);
146 hit.setMinPE(cell_min_p_es[id]);
147 hit.setAmplitude(cell_pes[id]);
148 hit.setEnergy(cell_energy);
149 hit.setTime(time[id]);
150 hit.setXPos(xpos[id]);
151 hit.setYPos(ypos[id]);
152 hit.setZPos(zpos[id]);
153 hit.setModuleID(module);
154 hit.setBarID(id.bar()); // getFieldValue("bar"));
155 hit.setNoise(false);
156 hit.setBeamEfrac(beam_frac[id] / dep_energy);
157
158 trig_scint_hits.push_back(hit);
159 }
160
161 ldmx_log(debug) << " ID = " << id.raw() << " Edep: " << edep[id]
162 << " numPEs: " << cell_pes[id] << " time: " << time[id]
163 << " z: " << zpos[id] << "\t X: " << xpos[id]
164 << " Y: " << ypos[id] << " Z: " << zpos[id];
165 } // end of loop over detIDs
166
167 // ------------------------------- Noise simulation -----------------------//
168 // ------------------------------------------------------------------------//
169 // only simulating for single array until
170 // all arrays are merged into one collection
171 int num_empty_cells = strips_per_array_ - num_rec_hits;
172 std::vector<double> noise_hits_pe =
173 noise_generator_->generateNoiseHits(num_empty_cells);
174
175 ldmx::TrigScintID temp_id;
176
177 for (auto &noise_hit_pe : noise_hits_pe) {
179 // generate random ID from remaining cells
180 do {
181 temp_id = generateRandomID(module);
182 } while (edep.find(temp_id) != edep.end() ||
183 noise_hit_i_ds.find(temp_id) != noise_hit_i_ds.end());
184
185 ldmx::TrigScintID noise_id = temp_id;
186
187 noise_hit_i_ds.insert(noise_id);
188 hit.setID(noise_id.raw());
189 hit.setPE(noise_hit_pe);
190 hit.setMinPE(noise_hit_pe);
191 hit.setAmplitude(noise_hit_pe);
192 hit.setEnergy(0.);
193 hit.setTime(0.);
194 hit.setXPos(0.);
195 hit.setYPos(0.);
196 hit.setZPos(0.);
197 hit.setModuleID(module);
198 hit.setBarID(noise_id.bar());
199 hit.setNoise(true);
200 hit.setBeamEfrac(0.);
201
202 trig_scint_hits.push_back(hit);
203 }
204 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
205 // - -
206
207 event.add(output_collection_, trig_scint_hits);
208}
209} // namespace trigscint
210
#define DECLARE_PRODUCER(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Class that performs digitization of simulated trigger sctintillator.
Implements an event buffer system for storing event data.
Definition Event.h:42
Class which represents the process under execution.
Definition Process.h:36
static const std::string CONDITIONS_OBJECT_NAME
Conditions object name.
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
void setYPos(float ypos)
Set the Y position of the hit [mm].
void setID(int id)
Set the detector ID.
void setZPos(float zpos)
Set the Z position of the hit [mm].
void setXPos(float xpos)
Set the X position of the hit [mm].
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 setNoise(bool yes)
Set if this hit is a noise hit.
RawValue raw() const
Definition DetectorID.h:68
void setMinPE(float minpe)
Set the minimum number of photoelectrons estimated for this hit.
Definition HcalHit.h:160
Run-specific configuration and data stored in its own output TTree alongside the event TTree in the o...
Definition RunHeader.h:57
Stores simulated calorimeter hit information.
Class representing a simulated particle.
Definition SimParticle.h:23
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 that defines the detector ID of the trigger scintillator.
Definition TrigScintID.h:14
int bar() const
Get the value of the bar field from the ID.
Definition TrigScintID.h:64
Performs digitization of simulated Trigger Scintillator data.