All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
opDetDigitizerWorker.hh
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: opDetDigitizerWorker
3 //
4 // This module handles the calls to the digitization functions
5 // Created by G. Putnam and I.L. de Icaza
6 ////////////////////////////////////////////////////////////////////////
7 
8 #ifndef SBND_OPDETSIM_OPDETDIGITIZERWORKER_HH
9 #define SBND_OPDETSIM_OPDETDIGITIZERWORKER_HH
10 
11 #include <unordered_map>
12 #include <vector>
13 #include <mutex>
14 #include <condition_variable>
15 // #include <memory>
16 
21 namespace detinfo {
22  class DetectorClocksData;
23 }
24 
25 namespace opdet {
26 
28  public:
29  class Config {
30  public:
31  //arapuca and PMT digitization algorithms
34 
35  opdet::sbndPDMapAlg pdsMap; //map for photon detector types
36  unsigned int nChannels = pdsMap.size();
37 
38  unsigned nThreads;
39 
40  art::InputTag InputModuleName;
41  bool UseSimPhotonsLite; // SimPhotons have more information that SimPhotonsLite
42 
43  std::array<double, 2> EnableWindow;
44  double Sampling; //wave sampling frequency (GHz)
46  unsigned int Nsamples; //Samples per waveform
47  unsigned int Nsamples_Daphne; //Samples per waveform
48 
50  };
51 
52  class Semaphore {
53  public:
54  Semaphore(unsigned count_ = 0): count(count_) {}
55  void increment(unsigned n = 1);
56  void decrement(unsigned n = 1);
57 
58  private:
59  std::mutex mtx;
60  std::condition_variable cv;
61  unsigned count;
62  };
63 
64  opDetDigitizerWorker(unsigned no, const Config &config, CLHEP::HepRandomEngine *Engine, const opDetSBNDTriggerAlg &trigger_alg);
66 
67  void SetPhotonLiteHandles(const std::vector<art::Handle<std::vector<sim::SimPhotonsLite>>> *PhotonLiteHandles)
68  {
69  fPhotonLiteHandles = PhotonLiteHandles;
70  }
71  void SetPhotonHandles(const std::vector<art::Handle<std::vector<sim::SimPhotons>>> *PhotonHandles)
72  {
73  fPhotonHandles = PhotonHandles;
74  }
75  void SetWaveformHandle(std::vector<raw::OpDetWaveform> *Waveforms)
76  {
77  fWaveforms = Waveforms;
78  }
79  void SetTriggeredWaveformHandle(std::vector<raw::OpDetWaveform> *Waveforms)
80  {
81  fTriggeredWaveforms = Waveforms;
82  }
83 
84  void Start(detinfo::DetectorClocksData const& clockData) const;
85  void ApplyTriggerLocations(detinfo::DetectorClocksData const& clockData) const;
86 
87  private:
88  unsigned NChannelsToProcess(unsigned n) const;
89  unsigned StartChannelToProcess(unsigned n) const;
91  std::unordered_map<int, sim::SimPhotons>& directPhotonsOnPMTS,
92  std::vector<art::Handle<std::vector<sim::SimPhotons>>> photon_handles) const;
94  std::unordered_map<int, sim::SimPhotonsLite>& directPhotonsOnPMTS,
95  std::vector<art::Handle<std::vector<sim::SimPhotonsLite>>> photon_handles) const;
96  void MakeWaveforms(
97  opdet::DigiPMTSBNDAlg *pmtDigitizer,
98  opdet::DigiArapucaSBNDAlg *arapucaDigitizer) const;
99 
101  unsigned fThreadNo;
102  CLHEP::HepRandomEngine *fEngine;
104 
105  const std::vector<art::Handle<std::vector<sim::SimPhotonsLite>>> *fPhotonLiteHandles;
106  const std::vector<art::Handle<std::vector<sim::SimPhotons>>> *fPhotonHandles;
107  std::vector<raw::OpDetWaveform> *fWaveforms;
108  std::vector<raw::OpDetWaveform> *fTriggeredWaveforms;
109  };
110 
111  void StartopDetDigitizerWorkers(unsigned n_workers, opDetDigitizerWorker::Semaphore &sem_start);
112  void WaitopDetDigitizerWorkers(unsigned n_workers, opDetDigitizerWorker::Semaphore &sem_finish);
114  detinfo::DetectorClocksData const& clockData,
117  bool ApplyTriggerLocations, bool *finished);
118 
119 } // end namespace opdet
120 
121 #endif // SBND_OPDETSIM_OPDETDIGITIZERWORKER_HH
unsigned StartChannelToProcess(unsigned n) const
size_t size() const
void SetWaveformHandle(std::vector< raw::OpDetWaveform > *Waveforms)
std::vector< raw::OpDetWaveform > * fWaveforms
void CreateDirectPhotonMap(std::unordered_map< int, sim::SimPhotons > &directPhotonsOnPMTS, std::vector< art::Handle< std::vector< sim::SimPhotons >>> photon_handles) const
void opDetDigitizerWorkerThread(const opDetDigitizerWorker &worker, detinfo::DetectorClocksData const &clockData, opDetDigitizerWorker::Semaphore &sem_start, opDetDigitizerWorker::Semaphore &sem_finish, bool ApplyTriggerLocations, bool *finished)
void SetTriggeredWaveformHandle(std::vector< raw::OpDetWaveform > *Waveforms)
opdet::DigiArapucaSBNDAlgMaker makeArapucaDigi
void StartopDetDigitizerWorkers(unsigned n_workers, opDetDigitizerWorker::Semaphore &sem_start)
const std::vector< art::Handle< std::vector< sim::SimPhotonsLite > > > * fPhotonLiteHandles
void WaitopDetDigitizerWorkers(unsigned n_workers, opDetDigitizerWorker::Semaphore &sem_finish)
void SetPhotonLiteHandles(const std::vector< art::Handle< std::vector< sim::SimPhotonsLite >>> *PhotonLiteHandles)
void SetPhotonHandles(const std::vector< art::Handle< std::vector< sim::SimPhotons >>> *PhotonHandles)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
unsigned NChannelsToProcess(unsigned n) const
std::vector< raw::OpDetWaveform > * fTriggeredWaveforms
opDetDigitizerWorker(unsigned no, const Config &config, CLHEP::HepRandomEngine *Engine, const opDetSBNDTriggerAlg &trigger_alg)
const std::vector< art::Handle< std::vector< sim::SimPhotons > > > * fPhotonHandles
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)
opdet::DigiPMTSBNDAlgMaker makePMTDigi
void CreateDirectPhotonMapLite(std::unordered_map< int, sim::SimPhotonsLite > &directPhotonsOnPMTS, std::vector< art::Handle< std::vector< sim::SimPhotonsLite >>> photon_handles) const
const opDetSBNDTriggerAlg & fTriggerAlg