All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FakePhotoS_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: FakePhotoS
3 // Plugin Type: producer (art v3_01_01)
4 // File: FakePhotoS_module.cc
5 //
6 // Generated at Tue Feb 12 13:46:25 2019 by Kazuhiro Terao using cetskelgen
7 // from cetlib version v3_05_01.
8 ////////////////////////////////////////////////////////////////////////
9 
10 #include "art/Framework/Core/EDProducer.h"
11 #include "art/Framework/Core/ModuleMacros.h"
12 #include "art/Framework/Principal/Event.h"
13 #include "art/Framework/Principal/Handle.h"
14 #include "art/Framework/Principal/Run.h"
15 #include "art/Framework/Principal/SubRun.h"
16 #include "CLHEP/Random/RandFlat.h"
17 #include "CLHEP/Random/RandFlat.h"
18 #include "CLHEP/Random/RandExponential.h"
19 #include "TRandom.h"
20 #include "nurandom/RandomUtils/NuRandomService.h"
21 #include "canvas/Utilities/InputTag.h"
22 #include "fhiclcpp/ParameterSet.h"
23 #include "messagefacility/MessageLogger/MessageLogger.h"
28 #include "larcore/CoreUtils/ServiceUtil.h" // lar::providerFrom()
29 
30 #include <memory>
31 
32 class FakePhotoS;
33 
34 
35 class FakePhotoS : public art::EDProducer {
36 public:
37  explicit FakePhotoS(fhicl::ParameterSet const& p);
38  // The compiler-generated destructor is fine for non-base
39  // classes without bare pointers or other resource use.
40 
41  // Plugins should not be copied or assigned.
42  FakePhotoS(FakePhotoS const&) = delete;
43  FakePhotoS(FakePhotoS&&) = delete;
44  FakePhotoS& operator=(FakePhotoS const&) = delete;
45  FakePhotoS& operator=(FakePhotoS&&) = delete;
46 
47  // Required functions.
48  void produce(art::Event& e) override;
49  void beginRun(art::Run& run) override;
50 
51 private:
52  std::vector<double> GenerateTime(size_t numphotons);
53  // Declare member data here.
54  bool _verbose;
55  double _frequency; ///< [MHz]
56  double _duration; ///< [us]
57  double _tstart; ///< [ns]
58  size_t _min_pe; ///< [p.e.]
59  size_t _max_pe; ///< [p.e.]
60  bool _simulate_time; ///< whether or not to simulate scintillation fall time
61  double _fast_frac; ///< fraction of prompt light
62  double _fast_tau; ///< scintillation emission time constant for fast component
63  double _slow_tau; ///< scintillation emission time constant for slow component
64  std::vector<unsigned int> _ch_v; // opchannels to create photons for
65 
66  CLHEP::HepRandomEngine &fFlatEngine;
67  CLHEP::RandFlat *fFlatRandom;
68  CLHEP::RandExponential *fExpoRandom;
69 };
70 
71 
72 FakePhotoS::FakePhotoS(fhicl::ParameterSet const& p)
73  : EDProducer{p}
74  , fFlatEngine(art::ServiceHandle<rndm::NuRandomService>()->createEngine(*this, "HepJamesRandom", "Gen", p, "Seed"))
75  // More initializers here.
76 {
77  _verbose = p.get<bool>("Verbose",false); // If you want someone to talk to you
78  auto min_pe = p.get<int>("MinPE",1); // Min of the range of PE count to be injected in one shot
79  auto max_pe = p.get<int>("MaxPE",1); // Max of the range of PE count to be injected in one shot
80  assert(min_pe <= max_pe && min_pe>0 && max_pe>0);
81  _min_pe = min_pe;
82  _max_pe = max_pe;
83  _ch_v.clear();
84  _ch_v = p.get<std::vector<unsigned int> >("Channels",_ch_v); // Specify if you want to use only select channels
85  _frequency = p.get<double>("Frequency"); // The frequency of photon(s) injection
86  _duration = p.get<double>("Duration"); // The duration of photon(s) injection period
87  _tstart = p.get<double>("G4TStart"); // The start time of photon injection period
88  produces<std::vector<sim::SimPhotons> >();
89  produces< sumdata::RunData, art::InRun >();
90  // scintillation params (yeah fine you can replace these w/ service)
91  _simulate_time = p.get<bool>("SimulateTime",false); // scintillation fall timing simulation
92  _fast_frac = p.get<double>("PromptLightFraction",0.23);
93  _fast_tau = p.get<double>("FastTimeConstant",0.006);
94  _slow_tau = p.get<double>("SlowTimeConstant",1.5);
95 
96  fFlatRandom = new CLHEP::RandFlat(fFlatEngine,_min_pe,_max_pe);
97  fExpoRandom = new CLHEP::RandExponential(fFlatEngine);
98 }
99 
100 void FakePhotoS::beginRun(art::Run& run)
101 {
102  // grab the geometry object to see what geometry we are using
103  art::ServiceHandle<geo::Geometry> geo;
104 
105  std::unique_ptr<sumdata::RunData> runData(new sumdata::RunData(geo->DetectorName()));
106 
107  run.put(std::move(runData));
108 
109  return;
110 }
111 
112 
113 std::vector<double> FakePhotoS::GenerateTime(size_t numphotons) {
114 
115  std::vector<double> res(numphotons);
116  for(int i=0; i<((int)numphotons); ++i) {
117  if(fFlatRandom->fire(0.,1.) < _fast_frac)
118  res[i] = fExpoRandom->fire(_fast_tau);
119  else res[i] = fExpoRandom->fire(_slow_tau);
120  }
121  return res;
122 }
123 
124 void FakePhotoS::produce(art::Event& e)
125 {
126  // Implementation of required member function here.
127  auto simph_v = std::unique_ptr<std::vector<sim::SimPhotons> >(new std::vector<sim::SimPhotons>());
128 
129  if(_ch_v.empty()) {
130  auto const geop = lar::providerFrom<geo::Geometry>();
131  _ch_v.reserve(geop->NOpChannels());
132  for(size_t opch=0; opch<geop->NOpChannels(); ++opch)
133  _ch_v.push_back(opch);
134  }
135  simph_v->reserve(_ch_v.size());
136  for(auto const& opch : _ch_v) {
137  if(_verbose) std::cout << "OpChannel " << opch << std::endl;
138  sim::SimPhotons sphot(opch);
139  sphot.reserve(int(_duration * _frequency));
140  double clock = 0.;
141  while(clock <= _duration) {
142 
143  size_t npe = fFlatRandom->fire(_min_pe,_max_pe+0.999999);
144  if(_verbose) std::cout << npe << "@" << (int)(_tstart + clock * 1.e3) << "[ns] " << std::flush;
145  std::vector<double> time_array(npe,0.);
146  if(_simulate_time) time_array = this->GenerateTime(npe);
147  for(size_t ctr=0;ctr<npe;++ctr) {
148  sim::OnePhoton phot;
149  phot.Time = _tstart + clock * 1.e3 + time_array[ctr];
150  sphot.emplace_back(std::move(phot));
151  }
152  clock += (1./_frequency);
153  }
154  if(_verbose) std::cout << std::endl;
155  simph_v->emplace_back(std::move(sphot));
156  }
157 
158  e.put(std::move(simph_v));
159 }
160 
161 DEFINE_ART_MODULE(FakePhotoS)
CLHEP::RandFlat * fFlatRandom
double _fast_tau
scintillation emission time constant for fast component
Utilities related to art service access.
double _frequency
[MHz]
size_t _min_pe
[p.e.]
double _slow_tau
scintillation emission time constant for slow component
FakePhotoS(fhicl::ParameterSet const &p)
pdgs p
Definition: selectors.fcl:22
All information of a photon entering the sensitive optical detector volume.
Definition: SimPhotons.h:64
FakePhotoS & operator=(FakePhotoS const &)=delete
std::vector< double > GenerateTime(size_t numphotons)
Simulation objects for optical detectors.
double _tstart
[ns]
std::vector< unsigned int > _ch_v
void beginRun(art::Run &run) override
double _duration
[us]
Collection of photons which recorded on one channel.
Definition: SimPhotons.h:136
bool _simulate_time
whether or not to simulate scintillation fall time
createEngine fFlatRandom
do i e
size_t _max_pe
[p.e.]
art framework interface to geometry description
BEGIN_PROLOG could also be cout
void produce(art::Event &e) override
CLHEP::HepRandomEngine & fFlatEngine
CLHEP::RandExponential * fExpoRandom
double _fast_frac
fraction of prompt light