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(
11 // Configure this instance of the producer
12 stripsPerArray_ = parameters.getParameter<int>("number_of_strips");
13 numberOfArrays_ = parameters.getParameter<int>("number_of_arrays");
14 meanNoise_ = parameters.getParameter<double>("mean_noise");
15 mevPerMip_ = parameters.getParameter<double>("mev_per_mip");
16 pePerMip_ = parameters.getParameter<double>("pe_per_mip");
17 inputCollection_ = parameters.getParameter<std::string>("input_collection");
18 inputPassName_ = parameters.getParameter<std::string>("input_pass_name");
19 outputCollection_ = parameters.getParameter<std::string>("output_collection");
20 verbose_ = parameters.getParameter<bool>("verbose");
21}
22
23void TrigScintDigiProducer::onNewRun(const ldmx::RunHeader &) {
24 noiseGenerator_ = std::make_unique<ldmx::NoiseGenerator>(meanNoise_, false);
25 noiseGenerator_->setNoiseThreshold(1);
26 // Set up seeds
27 const auto &rseed = getCondition<framework::RandomNumberSeedService>(
29
30 noiseGenerator_->seedGenerator(
31 rseed.getSeed("TrigScintDigiProducer::NoiseGenerator"));
32 // Random number generator for module id
33 rng_.seed(rseed.getSeed("TrigScintDigiProducer"));
34}
35
36ldmx::TrigScintID TrigScintDigiProducer::generateRandomID(int module) {
37 // Uniform distributions for integer generation
38 std::uniform_int_distribution<int> strips_dist(0, stripsPerArray_ - 1);
39 ldmx::TrigScintID tempID(module, strips_dist(rng_));
40 if (module >= TrigScintSection::NUM_SECTIONS) {
41 ldmx_log(fatal) << "TrigScintSection is not known";
42 }
43
44 return tempID;
45}
46
47void TrigScintDigiProducer::produce(framework::Event &event) {
48 std::map<ldmx::TrigScintID, int> cellPEs, cellMinPEs;
49 std::map<ldmx::TrigScintID, float> Xpos, Ypos, Zpos, Edep, Time, beamFrac;
50 std::set<ldmx::TrigScintID> noiseHitIDs;
51
52 auto numRecHits{0};
53
54 // looper over sim hits and aggregate energy depositions for each detID
55 const auto simHits{event.getCollection<ldmx::SimCalorimeterHit>(
56 inputCollection_, inputPassName_)};
57 auto particleMap{event.getMap<int, ldmx::SimParticle>("SimParticles")};
58
59 int module{-1};
60 for (const auto &simHit : simHits) {
61 ldmx::TrigScintID id(simHit.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 = simHit.getPosition();
68
69 if (verbose_) {
70 std::cout << id << std::endl;
71 }
72
73 // check if hits is from beam electron and, if so, add to beamFrac
74 for (int i = 0; i < simHit.getNumberOfContribs(); i++) {
75 auto contrib = simHit.getContrib(i);
76 if (verbose_) {
77 std::cout << "contrib " << i << " trackID: " << contrib.trackID
78 << " pdgID: " << contrib.pdgCode << " edep: " << contrib.edep
79 << std::endl;
80 std::cout << "\t particle id: "
81 << particleMap[contrib.trackID].getPdgID()
82 << " particle status: "
83 << particleMap[contrib.trackID].getGenStatus() << std::endl;
84 }
85 if (particleMap[contrib.trackID].getPdgID() == 11 &&
86 particleMap[contrib.trackID].getGenStatus() == 1) {
87 if (beamFrac.find(id) == beamFrac.end()) {
88 beamFrac[id] = contrib.edep;
89 } else {
90 beamFrac[id] += contrib.edep;
91 }
92 }
93 }
94
95 // for now, we take an energy weighted average of the hit in each strip to
96 // simulate the hit position. AJW: these should be dropped, they are likely
97 // to lead to a problem since we can't measure them anyway except roughly y
98 // and z, which is encoded in the ids.
99 if (Edep.find(id) == Edep.end()) {
100 // first hit, initialize
101 Edep[id] = simHit.getEdep();
102 Time[id] = simHit.getTime() * simHit.getEdep();
103 Xpos[id] = position[0] * simHit.getEdep();
104 Ypos[id] = position[1] * simHit.getEdep();
105 Zpos[id] = position[2] * simHit.getEdep();
106 numRecHits++;
107
108 } else {
109 // not first hit, aggregate, and store the largest radius hit
110 Xpos[id] += position[0] * simHit.getEdep();
111 Ypos[id] += position[1] * simHit.getEdep();
112 Zpos[id] += position[2] * simHit.getEdep();
113 Edep[id] += simHit.getEdep();
114 // AJW: need to figure out a better way to model this...
115 Time[id] += simHit.getTime() * simHit.getEdep();
116 }
117 }
118
119 // Create the container to hold the digitized trigger scintillator hits.
120 std::vector<ldmx::TrigScintHit> trigScintHits;
121
122 // loop over detIDs and simulate number of PEs
123 for (std::map<ldmx::TrigScintID, float>::iterator it = Edep.begin();
124 it != Edep.end(); ++it) {
125 ldmx::TrigScintID id(it->first);
126
127 double depEnergy = Edep[id];
128 Time[id] = Time[id] / Edep[id];
129 Xpos[id] = Xpos[id] / Edep[id];
130 Ypos[id] = Ypos[id] / Edep[id];
131 Zpos[id] = Zpos[id] / Edep[id];
132 double meanPE = depEnergy / mevPerMip_ * pePerMip_;
133 std::poisson_distribution<int> poisson_dist(meanPE + meanNoise_);
134 cellPEs[id] = poisson_dist(rng_);
135
136 // If a cell has a PE count above threshold, persit the hit.
137 // Thresholds are introduced (and configurable) in clustering.
138 // the cell PE >=1 suppresses artifical noise that is below one light
139 // quantum in the SiPM and unphysical.
140 if (cellPEs[id] >= 1) {
142 hit.setID(id.raw());
143 hit.setPE(cellPEs[id]);
144 hit.setMinPE(cellMinPEs[id]);
145 hit.setAmplitude(cellPEs[id]);
146 hit.setEnergy(depEnergy);
147 hit.setTime(Time[id]);
148 hit.setXPos(Xpos[id]);
149 hit.setYPos(Ypos[id]);
150 hit.setZPos(Zpos[id]);
151 hit.setModuleID(module);
152 hit.setBarID(id.bar()); // getFieldValue("bar"));
153 hit.setNoise(false);
154 hit.setBeamEfrac(beamFrac[id] / depEnergy);
155
156 trigScintHits.push_back(hit);
157 }
158
159 if (verbose_) {
160 std::cout << id << std::endl;
161 std::cout << "Edep: " << Edep[id] << std::endl;
162 std::cout << "numPEs: " << cellPEs[id] << std::endl;
163 std::cout << "time: " << Time[id] << std::endl;
164 std::cout << "z: " << Zpos[id] << std::endl;
165 std::cout << "\t X: " << Xpos[id] << "\t Y: " << Ypos[id]
166 << "\t Z: " << Zpos[id] << std::endl;
167 } // end verbose
168 }
169
170 // ------------------------------- Noise simulation -----------------------//
171 // ------------------------------------------------------------------------//
172 // only simulating for single array until
173 // all arrays are merged into one collection
174 int numEmptyCells = stripsPerArray_ - numRecHits;
175 std::vector<double> noiseHits_PE =
176 noiseGenerator_->generateNoiseHits(numEmptyCells);
177
178 ldmx::TrigScintID tempID;
179
180 for (auto &noiseHitPE : noiseHits_PE) {
182 // generate random ID from remaining cells
183 do {
184 tempID = generateRandomID(module);
185 } while (Edep.find(tempID) != Edep.end() ||
186 noiseHitIDs.find(tempID) != noiseHitIDs.end());
187
188 ldmx::TrigScintID noiseID = tempID;
189
190 noiseHitIDs.insert(noiseID);
191 hit.setID(noiseID.raw());
192 hit.setPE(noiseHitPE);
193 hit.setMinPE(noiseHitPE);
194 hit.setAmplitude(noiseHitPE);
195 hit.setEnergy(0.);
196 hit.setTime(0.);
197 hit.setXPos(0.);
198 hit.setYPos(0.);
199 hit.setZPos(0.);
200 hit.setModuleID(module);
201 hit.setBarID(noiseID.bar());
202 hit.setNoise(true);
203 hit.setBeamEfrac(0.);
204
205 trigScintHits.push_back(hit);
206 }
207 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
208 // - -
209
210 event.add(outputCollection_, trigScintHits);
211}
212} // namespace trigscint
213
214DECLARE_PRODUCER_NS(trigscint, TrigScintDigiProducer);
#define DECLARE_PRODUCER_NS(NS, 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
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