All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | Public Attributes | Private Attributes | List of all members
opdet::opDetDigitizerSBND Class Reference
Inheritance diagram for opdet::opDetDigitizerSBND:

Classes

struct  Config
 

Public Types

using Parameters = art::EDProducer::Table< Config >
 

Public Member Functions

 opDetDigitizerSBND (Parameters const &config)
 
 ~opDetDigitizerSBND ()
 
 opDetDigitizerSBND (opDetDigitizerSBND const &)=delete
 
 opDetDigitizerSBND (opDetDigitizerSBND &&)=delete
 
opDetDigitizerSBNDoperator= (opDetDigitizerSBND const &)=delete
 
opDetDigitizerSBNDoperator= (opDetDigitizerSBND &&)=delete
 
void produce (art::Event &e) override
 

Public Attributes

opdet::sbndPDMapAlg map
 
unsigned int nChannels = map.size()
 
std::vector< raw::OpDetWaveformfWaveforms
 

Private Attributes

bool fApplyTriggers
 
std::unordered_map
< raw::Channel_t, std::vector
< double > > 
fFullWaveforms
 
bool fUseSimPhotonsLite
 
unsigned fPMTBaseline
 
unsigned fArapucaBaseline
 
unsigned fNThreads
 
std::vector
< opdet::opDetDigitizerWorker
fWorkers
 
std::vector< std::vector
< raw::OpDetWaveform > > 
fTriggeredWaveforms
 
std::vector< std::thread > fWorkerThreads
 
std::vector< art::Handle
< std::vector
< sim::SimPhotonsLite > > > 
fPhotonLiteHandles
 
std::vector< art::Handle
< std::vector< sim::SimPhotons > > > 
fPhotonHandles
 
opdet::opDetDigitizerWorker::Semaphore fSemStart
 
opdet::opDetDigitizerWorker::Semaphore fSemFinish
 
bool fFinished
 
opdet::opDetSBNDTriggerAlg fTriggerAlg
 

Detailed Description

Definition at line 84 of file opDetDigitizerSBND_module.cc.

Member Typedef Documentation

using opdet::opDetDigitizerSBND::Parameters = art::EDProducer::Table<Config>

Definition at line 122 of file opDetDigitizerSBND_module.cc.

Constructor & Destructor Documentation

opdet::opDetDigitizerSBND::opDetDigitizerSBND ( Parameters const &  config)
explicit

Definition at line 169 of file opDetDigitizerSBND_module.cc.

170  : EDProducer{config}
171  , fApplyTriggers(config().ApplyTriggers())
172  , fUseSimPhotonsLite(config().UseSimPhotonsLite())
173  , fPMTBaseline(config().pmtAlgoConfig().pmtbaseline())
174  , fArapucaBaseline(config().araAlgoConfig().baseline())
175  , fTriggerAlg(config().trigAlgoConfig())
176  {
177  opDetDigitizerWorker::Config wConfig( config().pmtAlgoConfig(), config().araAlgoConfig());
178 
179  fNThreads = config().NThreads();
180  if (fNThreads == 0) { // autodetect -- first check env var
181  const char *env = std::getenv("SBNDCODE_OPDETSIM_NTHREADS");
182  // try to parse into positive integer
183  if (env != NULL) {
184  try {
185  int n_threads = std::stoi(env);
186  if (n_threads <= 0) {
187  throw std::invalid_argument("Expect positive integer");
188  }
189  fNThreads = n_threads;
190  }
191  catch (...) {
192  mf::LogError("OpDetDigitizer") << "Unable to parse number of threads "
193  << "in environment variable (SBNDCODE_OPDETSIM_NTHREADS): (" << env << ").\n"
194  << "Setting Number opdet threads to 1." << std::endl;
195  fNThreads = 1;
196  }
197  }
198  }
199 
200  if (fNThreads == 0) { // autodetect -- now try to get number of cpu's
201  fNThreads = std::thread::hardware_concurrency();
202  }
203  if (fNThreads == 0) { // autodetect failed
204  fNThreads = 1;
205  }
206  mf::LogInfo("OpDetDigitizer") << "Digitizing on n threads: " << fNThreads << std::endl;
207 
208  wConfig.nThreads = fNThreads;
209 
210  wConfig.UseSimPhotonsLite = config().UseSimPhotonsLite();
211  wConfig.InputModuleName = config().InputModuleName();
212 
213  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
214  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataForJob(clockData);
215  wConfig.Sampling = (clockData.OpticalClock().Frequency()) / 1000.0; //in GHz
216  wConfig.Sampling_Daphne = config().araAlgoConfig().DaphneFrequency() / 1000.0; //in GHz
217  wConfig.EnableWindow = fTriggerAlg.TriggerEnableWindow(clockData, detProp); // us
218  wConfig.Nsamples = (wConfig.EnableWindow[1] - wConfig.EnableWindow[0]) * 1000. /*us -> ns*/ * wConfig.Sampling /* GHz */;
219  wConfig.Nsamples_Daphne = (wConfig.EnableWindow[1] - wConfig.EnableWindow[0]) * 1000. /*us -> ns*/ * wConfig.Sampling_Daphne /* GHz */;
220 
221  fFinished = false;
222 
223  fWorkers.reserve(fNThreads);
225  for (unsigned i = 0; i < fNThreads; i++) {
226  // Set random number gen seed from the NuRandomService
227  art::ServiceHandle<rndm::NuRandomService> seedSvc;
228  CLHEP::HepJamesRandom *engine = new CLHEP::HepJamesRandom;
229  seedSvc->registerEngine(rndm::NuRandomService::CLHEPengineSeeder(engine), "opDetDigitizerSBND" + std::to_string(i));
230 
231  fTriggeredWaveforms.emplace_back();
232 
233  // setup worker
234  fWorkers.emplace_back(i, wConfig, engine, fTriggerAlg);
235  fWorkers[i].SetPhotonLiteHandles(&fPhotonLiteHandles);
236  fWorkers[i].SetPhotonHandles(&fPhotonHandles);
237  fWorkers[i].SetWaveformHandle(&fWaveforms);
238  fWorkers[i].SetTriggeredWaveformHandle(&fTriggeredWaveforms[i]);
239 
240  // start worker thread
242  std::cref(fWorkers[i]),
243  clockData,
244  std::ref(fSemStart),
245  std::ref(fSemFinish),
247  &fFinished);
248  }
249 
250  // Call appropriate produces<>() functions here.
251  produces< std::vector< raw::OpDetWaveform > >();
252  }
std::vector< art::Handle< std::vector< sim::SimPhotons > > > fPhotonHandles
void opDetDigitizerWorkerThread(const opDetDigitizerWorker &worker, detinfo::DetectorClocksData const &clockData, opDetDigitizerWorker::Semaphore &sem_start, opDetDigitizerWorker::Semaphore &sem_finish, bool ApplyTriggerLocations, bool *finished)
std::vector< opdet::opDetDigitizerWorker > fWorkers
std::array< double, 2 > TriggerEnableWindow(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp) const
std::vector< art::Handle< std::vector< sim::SimPhotonsLite > > > fPhotonLiteHandles
opdet::opDetDigitizerWorker::Semaphore fSemStart
BEGIN_PROLOG baseline
opdet::opDetDigitizerWorker::Semaphore fSemFinish
std::string to_string(WindowPattern const &pattern)
std::vector< std::thread > fWorkerThreads
std::vector< raw::OpDetWaveform > fWaveforms
std::vector< std::vector< raw::OpDetWaveform > > fTriggeredWaveforms
opdet::opDetSBNDTriggerAlg fTriggerAlg
auto const detProp
opdet::opDetDigitizerSBND::~opDetDigitizerSBND ( )

Definition at line 254 of file opDetDigitizerSBND_module.cc.

255  {
256  // cleanup all of the workers
257  fFinished = true;
259 
260  // join the threads
261  for (std::thread &thread : fWorkerThreads) thread.join();
262 
263  }
void StartopDetDigitizerWorkers(unsigned n_workers, opDetDigitizerWorker::Semaphore &sem_start)
opdet::opDetDigitizerWorker::Semaphore fSemStart
std::vector< std::thread > fWorkerThreads
opdet::opDetDigitizerSBND::opDetDigitizerSBND ( opDetDigitizerSBND const &  )
delete
opdet::opDetDigitizerSBND::opDetDigitizerSBND ( opDetDigitizerSBND &&  )
delete

Member Function Documentation

opDetDigitizerSBND& opdet::opDetDigitizerSBND::operator= ( opDetDigitizerSBND const &  )
delete
opDetDigitizerSBND& opdet::opDetDigitizerSBND::operator= ( opDetDigitizerSBND &&  )
delete
void opdet::opDetDigitizerSBND::produce ( art::Event &  e)
override

Definition at line 265 of file opDetDigitizerSBND_module.cc.

266  {
267  std::unique_ptr< std::vector< raw::OpDetWaveform > > pulseVecPtr(std::make_unique< std::vector< raw::OpDetWaveform > > ());
268  // Implementation of required member function here.
269  mf::LogInfo("opDetDigitizer") << "Event: " << e.id().event() << std::endl;
270 
271  // setup the waveforms
272  fWaveforms = std::vector<raw::OpDetWaveform> (nChannels);
273 
274  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(e);
275  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(e, clockData);
276 
277  if (fUseSimPhotonsLite) {
278  fPhotonLiteHandles.clear();
279  //Get *ALL* SimPhotonsCollectionLite from Event
280  fPhotonLiteHandles = e.getMany<std::vector<sim::SimPhotonsLite>>();
281  if (fPhotonLiteHandles.size() == 0)
282  mf::LogError("OpDetDigitizer") << "sim::SimPhotonsLite not found -> No Optical Detector Simulation!\n";
283  }
284  else {
285  fPhotonHandles.clear();
286  //Get *ALL* SimPhotonsCollection from Event
287  fPhotonLiteHandles = e.getMany<std::vector<sim::SimPhotonsLite>>();
288  if (fPhotonHandles.size() == 0)
289  mf::LogError("OpDetDigitizer") << "sim::SimPhotons not found -> No Optical Detector Simulation!\n";
290  }
291  // Start the workers!
292  // Run the digitizer over the full readout window
295 
296  if (fApplyTriggers) {
297  // find the trigger locations for the waveforms
298  for (const raw::OpDetWaveform &waveform : fWaveforms) {
299  raw::Channel_t ch = waveform.ChannelNumber();
300  // skip light channels which don't correspond to readout channels
301  if (ch == std::numeric_limits<raw::Channel_t>::max() /* "NULL" value*/) {
302  continue;
303  }
304  raw::ADC_Count_t baseline = (map.isPDType(ch, "pmt_uncoated") || map.isPDType(ch, "pmt_coated")) ?
306  fTriggerAlg.FindTriggerLocations(clockData, detProp, waveform, baseline);
307  }
308 
309  // combine the triggers
311  // Start the workers!
312  // Apply the trigger locations
315 
316  for (std::vector<raw::OpDetWaveform> &waveforms : fTriggeredWaveforms) {
317  // move these waveforms into the pulseVecPtr
318  pulseVecPtr->reserve(pulseVecPtr->size() + waveforms.size());
319  std::move(waveforms.begin(), waveforms.end(), std::back_inserter(*pulseVecPtr));
320  }
321  // clean up the vector
322  for (unsigned i = 0; i < fTriggeredWaveforms.size(); i++) {
323  fTriggeredWaveforms[i] = std::vector<raw::OpDetWaveform>();
324  }
325 
326  // put the waveforms in the event
327  e.put(std::move(pulseVecPtr));
328  // clear out the triggers
329  fTriggerAlg.ClearTriggerLocations();
330 
331  }
332  else {
333  // put the full waveforms in the event
334  for (const raw::OpDetWaveform &waveform : fWaveforms) {
335  if (waveform.ChannelNumber() == std::numeric_limits<raw::Channel_t>::max() /* "NULL" value*/) {
336  continue;
337  }
338  pulseVecPtr->push_back(waveform);
339  }
340  e.put(std::move(pulseVecPtr));
341  }
342 
343  // clear out the full waveforms
344  fWaveforms.clear();
345 
346  }//produce end
std::vector< art::Handle< std::vector< sim::SimPhotons > > > fPhotonHandles
void StartopDetDigitizerWorkers(unsigned n_workers, opDetDigitizerWorker::Semaphore &sem_start)
void FindTriggerLocations(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const raw::OpDetWaveform &waveform, raw::ADC_Count_t baseline)
bool isPDType(size_t ch, std::string pdname) const override
std::vector< art::Handle< std::vector< sim::SimPhotonsLite > > > fPhotonLiteHandles
void WaitopDetDigitizerWorkers(unsigned n_workers, opDetDigitizerWorker::Semaphore &sem_finish)
opdet::opDetDigitizerWorker::Semaphore fSemStart
BEGIN_PROLOG baseline
opdet::opDetDigitizerWorker::Semaphore fSemFinish
do i e
std::vector< raw::OpDetWaveform > fWaveforms
std::vector< std::vector< raw::OpDetWaveform > > fTriggeredWaveforms
opdet::opDetSBNDTriggerAlg fTriggerAlg
auto const detProp

Member Data Documentation

bool opdet::opDetDigitizerSBND::fApplyTriggers
private

Definition at line 144 of file opDetDigitizerSBND_module.cc.

unsigned opdet::opDetDigitizerSBND::fArapucaBaseline
private

Definition at line 149 of file opDetDigitizerSBND_module.cc.

bool opdet::opDetDigitizerSBND::fFinished
private

Definition at line 163 of file opDetDigitizerSBND_module.cc.

std::unordered_map< raw::Channel_t, std::vector<double> > opdet::opDetDigitizerSBND::fFullWaveforms
private

Definition at line 145 of file opDetDigitizerSBND_module.cc.

unsigned opdet::opDetDigitizerSBND::fNThreads
private

Definition at line 150 of file opDetDigitizerSBND_module.cc.

std::vector<art::Handle<std::vector<sim::SimPhotons> > > opdet::opDetDigitizerSBND::fPhotonHandles
private

Definition at line 158 of file opDetDigitizerSBND_module.cc.

std::vector<art::Handle<std::vector<sim::SimPhotonsLite> > > opdet::opDetDigitizerSBND::fPhotonLiteHandles
private

Definition at line 157 of file opDetDigitizerSBND_module.cc.

unsigned opdet::opDetDigitizerSBND::fPMTBaseline
private

Definition at line 148 of file opDetDigitizerSBND_module.cc.

opdet::opDetDigitizerWorker::Semaphore opdet::opDetDigitizerSBND::fSemFinish
private

Definition at line 162 of file opDetDigitizerSBND_module.cc.

opdet::opDetDigitizerWorker::Semaphore opdet::opDetDigitizerSBND::fSemStart
private

Definition at line 161 of file opDetDigitizerSBND_module.cc.

opdet::opDetSBNDTriggerAlg opdet::opDetDigitizerSBND::fTriggerAlg
private

Definition at line 166 of file opDetDigitizerSBND_module.cc.

std::vector<std::vector<raw::OpDetWaveform> > opdet::opDetDigitizerSBND::fTriggeredWaveforms
private

Definition at line 153 of file opDetDigitizerSBND_module.cc.

bool opdet::opDetDigitizerSBND::fUseSimPhotonsLite
private

Definition at line 147 of file opDetDigitizerSBND_module.cc.

std::vector<raw::OpDetWaveform> opdet::opDetDigitizerSBND::fWaveforms

Definition at line 141 of file opDetDigitizerSBND_module.cc.

std::vector<opdet::opDetDigitizerWorker> opdet::opDetDigitizerSBND::fWorkers
private

Definition at line 152 of file opDetDigitizerSBND_module.cc.

std::vector<std::thread> opdet::opDetDigitizerSBND::fWorkerThreads
private

Definition at line 154 of file opDetDigitizerSBND_module.cc.

opdet::sbndPDMapAlg opdet::opDetDigitizerSBND::map

Definition at line 139 of file opDetDigitizerSBND_module.cc.

unsigned int opdet::opDetDigitizerSBND::nChannels = map.size()

Definition at line 140 of file opDetDigitizerSBND_module.cc.


The documentation for this class was generated from the following file: