16 #include "art/Framework/Core/EDProducer.h"
17 #include "art/Framework/Core/ModuleMacros.h"
18 #include "art/Framework/Principal/Event.h"
19 #include "art/Framework/Principal/Handle.h"
20 #include "art/Framework/Services/Registry/ServiceHandle.h"
21 #include "fhiclcpp/ParameterSet.h"
32 #include "CLHEP/Random/RandFlat.h"
33 #include "CLHEP/Random/RandPoisson.h"
36 #include "nurandom/RandomUtils/NuRandomService.h"
45 explicit OpMCDigi(
const fhicl::ParameterSet&);
48 void produce(art::Event&)
override;
66 void AddTimedWaveform (
int time, std::vector<double>& OldPulse, std::vector<double>& NewPulse);
78 , fInputModule{pset.get<std::string>(
"InputModule")}
80 , fSaturationScale{pset.get<
float>(
"SaturationScale")}
81 , fDarkRate{pset.get<
float>(
"DarkRate")}
84 ,
fEngine(art::ServiceHandle<rndm::NuRandomService>{}->createEngine(*
this, pset,
"Seed"))
88 produces<std::vector< raw::OpDetPulse> >();
90 art::ServiceHandle<OpDigiProperties> odp;
91 fSampleFreq = odp->SampleFreq();
92 fTimeBegin = odp->TimeBegin();
93 fTimeEnd = odp->TimeEnd();
94 fSinglePEWaveform = odp->SinglePEWaveform();
103 if( (binTime + NewPulse.size() ) > OldPulse.size()) {
104 OldPulse.resize(binTime + NewPulse.size());
108 for(
size_t i = 0; i!=NewPulse.size(); ++i) {
109 OldPulse.at(binTime+i) += NewPulse.at(i);
118 auto StoragePtr = std::make_unique<std::vector<raw::OpDetPulse>>();
120 bool const fUseLitePhotons = art::ServiceHandle<sim::LArG4Parameters const>{}->UseLitePhotons();
123 art::ServiceHandle<opdet::OpDetResponseInterface const> odresponse;
125 double const TimeBegin_ns =
fTimeBegin * 1000;
126 double const TimeEnd_ns =
fTimeEnd * 1000;
129 int const nSamples = ( TimeEnd_ns-TimeBegin_ns)*SampleFreq_ns;
130 int const NOpChannels = odresponse->NOpChannels();
134 std::vector<std::vector<double> > PulsesFromDetPhotons(NOpChannels,std::vector<double>(nSamples,0.0));
136 if(!fUseLitePhotons) {
140 for(
auto const& pr : ThePhotCollection) {
149 if(!odresponse->detected(Ch, Phot, readoutCh)) {
157 if((Phot.Time > TimeBegin_ns) && (Phot.Time < TimeEnd_ns)) {
158 auto const binTime =
static_cast<int>((Phot.Time - TimeBegin_ns) * SampleFreq_ns);
165 auto const photons = *evt.getValidHandle<std::vector<sim::SimPhotonsLite>>(
"largeant");
167 for (
auto const&
photon : photons) {
168 int const Ch=
photon.OpChannel;
171 std::map<int, int> PhotonsMap =
photon.DetectedPhotons;
174 for(
auto const& pr :
photon.DetectedPhotons) {
175 for(
int i = 0; i < pr.second; i++) {
177 if(odresponse->detectedLite(Ch, readoutCh)) {
181 if((pr.first > TimeBegin_ns) && (pr.first < TimeEnd_ns)) {
182 auto const binTime =
static_cast<int>((pr.first - TimeBegin_ns) * SampleFreq_ns);
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);
200 unsigned const int NumberOfPulses =
fPoissonRandom.fire(MeanDarkPulses);
202 for(
size_t i=0; i!=NumberOfPulses; ++i) {
204 int const binTime =
static_cast<int>(PulseTime *
fSampleFreq);
210 for(
size_t i=0; i!=PulsesFromDetPhotons[iCh].size(); ++i) {
216 std::vector<short> shortvec;
218 for(
size_t i=0; i!=PulsesFromDetPhotons[iCh].size(); ++i) {
220 int ThisSample = PulsesFromDetPhotons[iCh].at(i);
222 if(
fFlatRandom.fire(1.0) > (ThisSample - int(ThisSample)))
223 shortvec.push_back(
int(ThisSample));
225 shortvec.push_back(
int(ThisSample)+1);
228 if(
fFlatRandom.fire(1.0) > (int(ThisSample)-ThisSample))
229 shortvec.push_back(
int(ThisSample));
231 shortvec.push_back(
int(ThisSample)-1);
235 StoragePtr->emplace_back(iCh, shortvec ,0,
fTimeBegin);
239 evt.put(std::move(StoragePtr));
Store parameters for running LArG4.
process_name can override from command line with o or output photon
int OpChannel() const
Returns the optical channel number this object is associated to.
void AddTimedWaveform(int time, std::vector< double > &OldPulse, std::vector< double > &NewPulse)
All information of a photon entering the sensitive optical detector volume.
void produce(art::Event &) override
CLHEP::HepRandomEngine & fEngine
OpMCDigi(const fhicl::ParameterSet &)
Simulation objects for optical detectors.
fEngine(art::ServiceHandle< rndm::NuRandomService >() ->createEngine(*this, pset,"Seed"))
Collection of photons which recorded on one channel.
std::vector< double > fSinglePEWaveform
CLHEP::RandFlat fFlatRandom
Collection of sim::SimPhotons, indexed by channel number.
static sim::SimPhotonsCollection GetSimPhotonsCollection(const art::Event &evt, std::string moduleLabel)
CLHEP::RandPoisson fPoissonRandom