8 makePMTDigi(pmt_config),
9 makeArapucaDigi(arapuca_config) {}
13 CLHEP::HepRandomEngine *Engine,
25 bool ApplyTriggerLocations,
29 bool do_apply_trigger_locations =
false;
35 if (do_apply_trigger_locations) {
37 do_apply_trigger_locations =
false;
40 worker.
Start(clockData);
41 do_apply_trigger_locations = ApplyTriggerLocations;
63 std::unique_lock<std::mutex> lock(mtx);
70 std::unique_lock<std::mutex> lock(mtx);
80 return (n + fConfig.nThreads - fThreadNo - 1) / fConfig.nThreads;
85 unsigned n_per_job = n / fConfig.nThreads;
86 unsigned leftover = std::min(fThreadNo, n % fConfig.nThreads);
87 return n_per_job * fThreadNo + leftover;
92 auto arapucaDigitizer = fConfig.makeArapucaDigi(
93 *(lar::providerFrom<detinfo::LArPropertiesService>()),
98 auto pmtDigitizer = fConfig.makePMTDigi(
99 *(lar::providerFrom<detinfo::LArPropertiesService>()),
103 MakeWaveforms(pmtDigitizer.get(), arapucaDigitizer.get());
114 unsigned start = StartChannelToProcess(fConfig.nChannels);
115 unsigned n = NChannelsToProcess(fConfig.nChannels);
117 fTriggeredWaveforms->clear();
121 if (waveform.ChannelNumber() == std::numeric_limits<raw::Channel_t>::max() ) {
125 if (waveform.ChannelNumber() < start || waveform.ChannelNumber() >= start +
n)
continue;
127 std::vector<raw::OpDetWaveform> waveforms = fTriggerAlg.ApplyTriggerLocations(clockData, waveform);
129 std::move(waveforms.begin(), waveforms.end(), std::back_inserter(*fTriggeredWaveforms));
136 if(fConfig.UseSimPhotonsLite) {
137 const std::vector<art::Handle<std::vector<sim::SimPhotonsLite>>> &photon_handles = *fPhotonLiteHandles;
150 std::unordered_map<std::string, std::unordered_map<int, sim::SimPhotonsLite> > AllPhotonsMap;
151 AllPhotonsMap[
"Direct"] = std::unordered_map<int, sim::SimPhotonsLite>();
152 AllPhotonsMap[
"Reflected"] = std::unordered_map<int, sim::SimPhotonsLite>();
153 for (
const art::Handle<std::vector<sim::SimPhotonsLite>> &opdetHandle : photon_handles) {
154 const bool Reflected = (opdetHandle.provenance()->productInstanceName() ==
"Reflected");
155 for (
auto const& litesimphotons : (*opdetHandle)){
158 auto it = AllPhotonsMap[
"Reflected"].find(litesimphotons.OpChannel);
159 if(it==AllPhotonsMap[
"Reflected"].
end())
160 AllPhotonsMap[
"Reflected"][litesimphotons.OpChannel] = litesimphotons;
162 AllPhotonsMap[
"Reflected"][litesimphotons.OpChannel] += litesimphotons;
166 auto it = AllPhotonsMap[
"Direct"].find(litesimphotons.OpChannel);
167 if(it==AllPhotonsMap[
"Direct"].
end())
168 AllPhotonsMap[
"Direct"][litesimphotons.OpChannel] = litesimphotons;
170 AllPhotonsMap[
"Direct"][litesimphotons.OpChannel] += litesimphotons;
175 const double startTime = fConfig.EnableWindow[0] * 1000. ;
177 std::unordered_map<int, sim::SimPhotonsLite> DirectPhotonsMap;
178 std::unordered_map<int, sim::SimPhotonsLite> ReflectedPhotonsMap;
179 std::unordered_set<short unsigned int> coatedpmts_todigitize;
181 const unsigned start = StartChannelToProcess(fConfig.nChannels);
182 const unsigned n = NChannelsToProcess(fConfig.nChannels);
183 for (
auto const& simphotons_cols : AllPhotonsMap){
185 const bool Reflected = (simphotons_cols.first==
"Reflected");
186 for (
auto const& simphotons_map : simphotons_cols.second) {
188 auto const& litesimphotons = simphotons_map.second;
190 std::vector<short unsigned int> waveform;
191 waveform.reserve(fConfig.Nsamples);
192 const unsigned ch = litesimphotons.OpChannel;
193 const std::string pdtype = fConfig.pdsMap.pdType(ch);
196 if (ch < start || ch >= start + n)
continue;
199 if( pdtype ==
"pmt_coated" ){
201 ReflectedPhotonsMap.insert(std::make_pair(ch, litesimphotons));
203 DirectPhotonsMap.insert(std::make_pair(ch, litesimphotons));
205 coatedpmts_todigitize.insert(ch);
207 else if( (Reflected) && (pdtype ==
"pmt_uncoated") ) {
220 else if((pdtype ==
"xarapuca_vuv" && !Reflected) ||
221 (pdtype ==
"xarapuca_vis" && Reflected) ) {
222 const bool is_daphne= fConfig.pdsMap.isElectronics(ch,
"daphne");
230 fConfig.Nsamples_Daphne);
254 for(
auto ch : coatedpmts_todigitize){
255 std::vector<short unsigned int> waveform;
256 waveform.reserve(fConfig.Nsamples);
264 const std::vector<art::Handle<std::vector<sim::SimPhotons>>> &photon_handles = *fPhotonHandles;
267 std::unordered_map<std::string, std::unordered_map<int, sim::SimPhotons> > AllPhotonsMap;
268 AllPhotonsMap[
"Direct"] = std::unordered_map<int, sim::SimPhotons>();
269 AllPhotonsMap[
"Reflected"] = std::unordered_map<int, sim::SimPhotons>();
270 for (
const art::Handle<std::vector<sim::SimPhotons>> &opdetHandle : photon_handles) {
271 const bool Reflected = (opdetHandle.provenance()->productInstanceName() ==
"Reflected");
272 for (
auto const& simphotons : (*opdetHandle)){
275 auto it = AllPhotonsMap[
"Reflected"].find(simphotons.OpChannel());
276 if(it==AllPhotonsMap[
"Reflected"].
end())
277 AllPhotonsMap[
"Reflected"][simphotons.OpChannel()] = simphotons;
279 AllPhotonsMap[
"Reflected"][simphotons.OpChannel()] += simphotons;
283 auto it = AllPhotonsMap[
"Direct"].find(simphotons.OpChannel());
284 if(it==AllPhotonsMap[
"Direct"].
end())
285 AllPhotonsMap[
"Direct"][simphotons.OpChannel()] = simphotons;
287 AllPhotonsMap[
"Direct"][simphotons.OpChannel()] += simphotons;
294 std::unordered_map<int, sim::SimPhotons> DirectPhotonsMap;
295 std::unordered_map<int, sim::SimPhotons> ReflectedPhotonsMap;
296 std::unordered_set<short unsigned int> coatedpmts_todigitize;
298 const double startTime = fConfig.EnableWindow[0] * 1000. ;
300 const unsigned start = StartChannelToProcess(fConfig.nChannels);
301 const unsigned n = NChannelsToProcess(fConfig.nChannels);
302 for (
auto const& simphotons_cols : AllPhotonsMap){
304 const bool Reflected = (simphotons_cols.first==
"Reflected");
305 for (
auto const& simphotons_map : simphotons_cols.second) {
307 auto const& simphotons = simphotons_map.second;
309 std::vector<short unsigned int> waveform;
310 const unsigned ch = simphotons.OpChannel();
311 const std::string pdtype = fConfig.pdsMap.pdType(ch);
312 const bool is_daphne = fConfig.pdsMap.isElectronics(ch,
"daphne");
314 if (ch < start || ch >= start + n)
continue;
316 if( pdtype ==
"pmt_coated" ){
318 ReflectedPhotonsMap.insert(std::make_pair(ch, simphotons));
320 DirectPhotonsMap.insert(std::make_pair(ch, simphotons));
322 coatedpmts_todigitize.insert(ch);
325 else if(Reflected && pdtype ==
"pmt_uncoated") {
338 if((pdtype ==
"xarapuca_vuv" && !Reflected) ||
339 (pdtype ==
"xarapuca_vis" && Reflected)) {
347 fConfig.Nsamples_Daphne);
370 for(
auto ch : coatedpmts_todigitize){
371 std::vector<short unsigned int> waveform;
372 waveform.reserve(fConfig.Nsamples);
unsigned StartChannelToProcess(unsigned n) const
void ConstructWaveform(int ch, sim::SimPhotons const &simphotons, std::vector< short unsigned int > &waveform, std::string pdtype, double start_time, unsigned n_sample)
Utilities related to art service access.
void opDetDigitizerWorkerThread(const opDetDigitizerWorker &worker, detinfo::DetectorClocksData const &clockData, opDetDigitizerWorker::Semaphore &sem_start, opDetDigitizerWorker::Semaphore &sem_finish, bool ApplyTriggerLocations, bool *finished)
void StartopDetDigitizerWorkers(unsigned n_workers, opDetDigitizerWorker::Semaphore &sem_start)
void ConstructWaveformLiteCoatedPMT(int ch, std::vector< short unsigned int > &waveform, std::unordered_map< int, sim::SimPhotonsLite > &DirectPhotonsMap, std::unordered_map< int, sim::SimPhotonsLite > &ReflectedPhotonsMap, double start_time, unsigned n_sample)
void decrement(unsigned n=1)
void WaitopDetDigitizerWorkers(unsigned n_workers, opDetDigitizerWorker::Semaphore &sem_finish)
void ConstructWaveformLite(int ch, sim::SimPhotonsLite const &litesimphotons, std::vector< short unsigned int > &waveform, std::string pdtype, double start_time, unsigned n_sample)
unsigned NChannelsToProcess(unsigned n) const
void ConstructWaveformLite(int ch, sim::SimPhotonsLite const &litesimphotons, std::vector< short unsigned int > &waveform, std::string pdtype, bool is_daphne, double start_time, unsigned n_samples)
auto end(FixedBins< T, C > const &) noexcept
fEngine(art::ServiceHandle< rndm::NuRandomService >() ->createEngine(*this, pset,"Seed"))
void increment(unsigned n=1)
void ConstructWaveformCoatedPMT(int ch, std::vector< short unsigned int > &waveform, std::unordered_map< int, sim::SimPhotons > &DirectPhotonsMap, std::unordered_map< int, sim::SimPhotons > &ReflectedPhotonsMap, double start_time, unsigned n_sample)
opDetDigitizerWorker(unsigned no, const Config &config, CLHEP::HepRandomEngine *Engine, const opDetSBNDTriggerAlg &trigger_alg)
void Start(detinfo::DetectorClocksData const &clockData) const
Contains all timing reference information for the detector.
CLHEP::HepRandomEngine * fEngine
void MakeWaveforms(opdet::DigiPMTSBNDAlg *pmtDigitizer, opdet::DigiArapucaSBNDAlg *arapucaDigitizer) const
void ApplyTriggerLocations(detinfo::DetectorClocksData const &clockData) const
Config(const opdet::DigiPMTSBNDAlgMaker::Config &pmt_config, const opdet::DigiArapucaSBNDAlgMaker::Config &arapuca_config)
std::size_t count(Cont const &cont)
void ConstructWaveform(int ch, sim::SimPhotons const &simphotons, std::vector< short unsigned int > &waveform, std::string pdtype, bool is_daphne, double start_time, unsigned n_samples)
const opDetSBNDTriggerAlg & fTriggerAlg