Public Member Functions | Private Member Functions | Private Attributes | List of all members
opdet::OpMCDigi Class Reference
Inheritance diagram for opdet::OpMCDigi:
art::EDProducer art::detail::Producer art::detail::LegacyModule art::Modifier art::ModuleBase art::ProductRegistryHelper

Public Member Functions

 OpMCDigi (const fhicl::ParameterSet &)
 
- Public Member Functions inherited from art::EDProducer
 EDProducer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDProducer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Producer
virtual ~Producer () noexcept
 
 Producer (fhicl::ParameterSet const &)
 
 Producer (Producer const &)=delete
 
 Producer (Producer &&)=delete
 
Produceroperator= (Producer const &)=delete
 
Produceroperator= (Producer &&)=delete
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Modifier
 ~Modifier () noexcept
 
 Modifier ()
 
 Modifier (Modifier const &)=delete
 
 Modifier (Modifier &&)=delete
 
Modifieroperator= (Modifier const &)=delete
 
Modifieroperator= (Modifier &&)=delete
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Member Functions

void produce (art::Event &) override
 
void AddTimedWaveform (int time, std::vector< double > &OldPulse, std::vector< double > &NewPulse)
 

Private Attributes

std::string fInputModule
 
float fSampleFreq
 
float fTimeBegin
 
float fTimeEnd
 
float fSaturationScale
 
float fDarkRate
 
std::vector< double > fSinglePEWaveform
 
CLHEP::HepRandomEngine & fEngine
 
CLHEP::RandFlat fFlatRandom
 
CLHEP::RandPoisson fPoissonRandom
 

Additional Inherited Members

- Public Types inherited from art::EDProducer
using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
- Public Types inherited from art::detail::Producer
template<typename UserConfig , typename KeysToIgnore = void>
using Table = Modifier::Table< UserConfig, KeysToIgnore >
 
- Public Types inherited from art::Modifier
template<typename UserConfig , typename UserKeysToIgnore = void>
using Table = ProducerTable< UserConfig, detail::ModuleConfig, UserKeysToIgnore >
 
- Static Public Member Functions inherited from art::EDProducer
static void commitEvent (EventPrincipal &ep, Event &e)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Definition at line 43 of file OpMCDigi_module.cc.

Constructor & Destructor Documentation

opdet::OpMCDigi::OpMCDigi ( const fhicl::ParameterSet )
explicit

Definition at line 76 of file OpMCDigi_module.cc.

77  : EDProducer{pset}
78  , fInputModule{pset.get<std::string>("InputModule")}
79  //, fQE{pset.get<double>("QE")}
80  , fSaturationScale{pset.get<float>("SaturationScale")}
81  , fDarkRate{pset.get<float>("DarkRate")}
82  // create a default random engine; obtain the random seed from NuRandomService,
83  // unless overridden in configuration with key "Seed"
84  , fEngine(art::ServiceHandle<rndm::NuRandomService>{}->createEngine(*this, pset, "Seed"))
87  {
88  produces<std::vector< raw::OpDetPulse> >();
89 
91  fSampleFreq = odp->SampleFreq();
92  fTimeBegin = odp->TimeBegin();
93  fTimeEnd = odp->TimeEnd();
94  fSinglePEWaveform = odp->SinglePEWaveform();
95  }
std::string string
Definition: nybbler.cc:12
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
CLHEP::HepRandomEngine & fEngine
std::string fInputModule
std::vector< double > fSinglePEWaveform
CLHEP::RandFlat fFlatRandom
CLHEP::RandPoisson fPoissonRandom

Member Function Documentation

void opdet::OpMCDigi::AddTimedWaveform ( int  time,
std::vector< double > &  OldPulse,
std::vector< double > &  NewPulse 
)
private

Definition at line 100 of file OpMCDigi_module.cc.

101  {
102 
103  if( (binTime + NewPulse.size() ) > OldPulse.size()) {
104  OldPulse.resize(binTime + NewPulse.size());
105  }
106 
107  // Add shifted NewWaveform to Waveform at pointer
108  for(size_t i = 0; i!=NewPulse.size(); ++i) {
109  OldPulse.at(binTime+i) += NewPulse.at(i);
110  }
111  }
void opdet::OpMCDigi::produce ( art::Event evt)
overrideprivatevirtual

Implements art::EDProducer.

Definition at line 116 of file OpMCDigi_module.cc.

117  {
118  auto StoragePtr = std::make_unique<std::vector<raw::OpDetPulse>>();
119 
120  bool const fUseLitePhotons = art::ServiceHandle<sim::LArG4Parameters const>{}->UseLitePhotons();
121 
122  // Service for determining opdet responses
124 
125  double const TimeBegin_ns = fTimeBegin * 1000;
126  double const TimeEnd_ns = fTimeEnd * 1000;
127  double const SampleFreq_ns = fSampleFreq / 1000;
128 
129  int const nSamples = ( TimeEnd_ns-TimeBegin_ns)*SampleFreq_ns;
130  int const NOpChannels = odresponse->NOpChannels();
131 
132 
133  // This vector will store all the waveforms we will make
134  std::vector<std::vector<double> > PulsesFromDetPhotons(NOpChannels,std::vector<double>(nSamples,0.0));
135 
136  if(!fUseLitePhotons) {
137  // Read in the Sim Photons
139  // For every OpDet:
140  for(auto const& pr : ThePhotCollection) {
141  const sim::SimPhotons& ThePhot=pr.second;
142 
143  int const Ch = ThePhot.OpChannel();
144  int readoutCh;
145 
146  // For every photon in the hit:
147  for(const sim::OnePhoton& Phot: ThePhot) {
148  // Sample a random subset according to QE
149  if(!odresponse->detected(Ch, Phot, readoutCh)) {
150  continue;
151  }
152 
153  // Convert photon arrival time to the appropriate bin,
154  // dictated by fSampleFreq. Photon arrival time is in ns,
155  // beginning time in us, and sample frequency in MHz. Notice
156  // that we have to accommodate for the beginning time
157  if((Phot.Time > TimeBegin_ns) && (Phot.Time < TimeEnd_ns)) {
158  auto const binTime = static_cast<int>((Phot.Time - TimeBegin_ns) * SampleFreq_ns);
159  AddTimedWaveform( binTime, PulsesFromDetPhotons[readoutCh], fSinglePEWaveform );
160  }
161  } // for each Photon in SimPhotons
162  }
163  }
164  else {
165  auto const photons = *evt.getValidHandle<std::vector<sim::SimPhotonsLite>>("largeant");
166  // For every OpDet:
167  for (auto const& photon : photons) {
168  int const Ch=photon.OpChannel;
169  int readoutCh;
170 
171  std::map<int, int> PhotonsMap = photon.DetectedPhotons;
172 
173  // For every photon in the hit:
174  for(auto const& pr : photon.DetectedPhotons) {
175  for(int i = 0; i < pr.second; i++) {
176  // Sample a random subset according to QE
177  if(odresponse->detectedLite(Ch, readoutCh)) {
178  // Convert photon arrival time to the appropriate bin, dictated by fSampleFreq.
179  // Photon arrival time is in ns, beginning time in us, and sample frequency in MHz.
180  // Notice that we have to accommodate for the beginning time
181  if((pr.first > TimeBegin_ns) && (pr.first < TimeEnd_ns)) {
182  auto const binTime = static_cast<int>((pr.first - TimeBegin_ns) * SampleFreq_ns);
183  AddTimedWaveform( binTime, PulsesFromDetPhotons[readoutCh], fSinglePEWaveform );
184  }
185  } // random QE cut
186  }
187  } // for each Photon in SimPhotons
188  }
189  }
190 
191  // Create vector of output objects, add dark noise and apply
192  // saturation
193 
194  std::vector<raw::OpDetPulse*> ThePulses(NOpChannels);
195  for(int iCh=0; iCh!=NOpChannels; ++iCh) {
196  PulsesFromDetPhotons[iCh].resize((TimeEnd_ns - TimeBegin_ns) * SampleFreq_ns);
197 
198  // Add dark noise
199  double const MeanDarkPulses = fDarkRate * (fTimeEnd-fTimeBegin) / 1000000;
200  unsigned const int NumberOfPulses = fPoissonRandom.fire(MeanDarkPulses);
201 
202  for(size_t i=0; i!=NumberOfPulses; ++i) {
203  double const PulseTime = (fTimeEnd-fTimeBegin)*fFlatRandom.fire(1.0);
204  int const binTime = static_cast<int>(PulseTime * fSampleFreq);
205 
206  AddTimedWaveform(binTime, PulsesFromDetPhotons[iCh], fSinglePEWaveform);
207  }
208 
209  // Apply saturation for large signals
210  for(size_t i=0; i!=PulsesFromDetPhotons[iCh].size(); ++i) {
211  if(PulsesFromDetPhotons[iCh].at(i)>fSaturationScale) PulsesFromDetPhotons[iCh].at(i) = fSaturationScale;
212  }
213 
214  // Produce ADC pulse of integers rather than doubles
215 
216  std::vector<short> shortvec;
217 
218  for(size_t i=0; i!=PulsesFromDetPhotons[iCh].size(); ++i) {
219  // Throw randoms to fairly sample +ve and -ve side of doubles
220  int ThisSample = PulsesFromDetPhotons[iCh].at(i);
221  if(ThisSample>0) {
222  if(fFlatRandom.fire(1.0) > (ThisSample - int(ThisSample)))
223  shortvec.push_back(int(ThisSample));
224  else
225  shortvec.push_back(int(ThisSample)+1);
226  }
227  else {
228  if(fFlatRandom.fire(1.0) > (int(ThisSample)-ThisSample))
229  shortvec.push_back(int(ThisSample));
230  else
231  shortvec.push_back(int(ThisSample)-1);
232  }
233  }
234 
235  StoragePtr->emplace_back(iCh, shortvec ,0, fTimeBegin);
236 
237  } // for each OpDet in SimPhotonsCollection
238 
239  evt.put(std::move(StoragePtr));
240  }
int OpChannel() const
Returns the optical channel number this object is associated to.
Definition: SimPhotons.h:254
void AddTimedWaveform(int time, std::vector< double > &OldPulse, std::vector< double > &NewPulse)
All information of a photon entering the sensitive optical detector volume.
Definition: SimPhotons.h:64
virtual bool detected(int OpChannel, const sim::OnePhoton &Phot, int &newOpChannel) const
def move(depos, offset)
Definition: depos.py:107
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
virtual bool detectedLite(int OpChannel, int &newOpChannel) const
std::string fInputModule
Index NOpChannels(Index)
Collection of photons which recorded on one channel.
Definition: SimPhotons.h:136
std::vector< double > fSinglePEWaveform
CLHEP::RandFlat fFlatRandom
Collection of sim::SimPhotons, indexed by channel number.
Definition: SimPhotons.h:192
static sim::SimPhotonsCollection GetSimPhotonsCollection(const art::Event &evt, std::string moduleLabel)
bool UseLitePhotons() const
CLHEP::RandPoisson fPoissonRandom

Member Data Documentation

float opdet::OpMCDigi::fDarkRate
private

Definition at line 58 of file OpMCDigi_module.cc.

CLHEP::HepRandomEngine& opdet::OpMCDigi::fEngine
private

Definition at line 62 of file OpMCDigi_module.cc.

CLHEP::RandFlat opdet::OpMCDigi::fFlatRandom
private

Definition at line 63 of file OpMCDigi_module.cc.

std::string opdet::OpMCDigi::fInputModule
private

Definition at line 51 of file OpMCDigi_module.cc.

CLHEP::RandPoisson opdet::OpMCDigi::fPoissonRandom
private

Definition at line 64 of file OpMCDigi_module.cc.

float opdet::OpMCDigi::fSampleFreq
private

Definition at line 52 of file OpMCDigi_module.cc.

float opdet::OpMCDigi::fSaturationScale
private

Definition at line 56 of file OpMCDigi_module.cc.

std::vector<double> opdet::OpMCDigi::fSinglePEWaveform
private

Definition at line 60 of file OpMCDigi_module.cc.

float opdet::OpMCDigi::fTimeBegin
private

Definition at line 53 of file OpMCDigi_module.cc.

float opdet::OpMCDigi::fTimeEnd
private

Definition at line 54 of file OpMCDigi_module.cc.


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