ShapedCohProtoDUNENoiseService_service.cc
Go to the documentation of this file.
1 // ShapedAndCoherentProtoDUNENoise_service.cc
2 //
3 // Pierre Lasorak, Babak Abi
4 // Dec 2020
5 
8 
9 #include "nurandom/RandomUtils/NuRandomService.h"
11 
13 #include "nurandom/RandomUtils/NuRandomService.h"
14 
15 #include "CLHEP/Random/RandFlat.h"
16 #include "CLHEP/Random/RandGauss.h"
17 #include "CLHEP/Random/RandGaussQ.h"
18 
20 
22  m_pran = new CLHEP::HepJamesRandom();
23  seedSvc->registerEngine(rndm::NuRandomService::CLHEPengineSeeder(m_pran), "ShapedCohProtoDUNENoiseService_rand");
24 
25  std::cout << "Initialising ShapedCohProtoDUNENoiseService\n";
26  double amplitude_col = pset.get<double>("amplitude_multiplicator_collection");
27  double amplitude_ind = pset.get<double>("amplitude_multiplicator_induction");
28  m_collection_plane_noise = pset.get<double>("collection_plane_noise") * amplitude_col;
29  m_induction_plane_noise = pset.get<double>("induction_plane_noise" ) * amplitude_ind;
30  m_collection_plane_noise_rms = pset.get<double>("collection_plane_noise_rms") * amplitude_col;
31  m_induction_plane_noise_rms = pset.get<double>("induction_plane_noise_rms" ) * amplitude_ind;
32 
33  m_FEMBCo_Frq_nominal = pset.get<std::vector<std::vector<double>>>("FEMBCo_Frq");
34  m_FEMBCo_Amp_nominal = pset.get<std::vector<std::vector<double>>>("FEMBCo_Amp");
35  m_FEMBCo_Phs_nominal = pset.get<std::vector<std::vector<double>>>("FEMBCo_Phs");
36  m_random_phase = pset.get<bool>("random_phase_noise");
37 
38  assert(m_FEMBCo_Frq_nominal.size() == m_n_femb);
39  assert(m_FEMBCo_Amp_nominal.size() == m_n_femb);
40  assert(m_FEMBCo_Phs_nominal.size() == m_n_femb);
41 
42  for (size_t femb=0; femb<m_n_femb; ++femb) {
43  assert(m_FEMBCo_Frq_nominal[femb].size() <= m_n_max_coh_noise);
44  assert(m_FEMBCo_Amp_nominal[femb].size() <= m_n_max_coh_noise);
45  assert(m_FEMBCo_Phs_nominal[femb].size() <= m_n_max_coh_noise);
46  }
47 
48  // HV noise
49  m_HV1_Frq_nominal = pset.get<std::vector<double>>("HV1_Frq");
50  m_HV1_Amp_nominal = pset.get<std::vector<double>>("HV1_Amp");
51  m_HV1_Phs_nominal = pset.get<std::vector<double>>("HV1_Phs");
52  assert(m_HV1_Frq_nominal.size() <= m_n_max_coh_noise);
53  assert(m_HV1_Amp_nominal.size() <= m_n_max_coh_noise);
54  assert(m_HV1_Phs_nominal.size() <= m_n_max_coh_noise);
55  m_init = false;
56 }
57 
60 
61  std::map<size_t,std::vector<size_t>> femb_se;
62  for (size_t chan=0; chan<m_n_wire_per_apa; ++chan) {
63  // int n_wire = chan%m_n_wire_per_apa; // that is one little useless statement
64  int femb = channel_map->FEMBFromOfflineChannel (chan)-1; // so that it starts from 0
65  int slot = channel_map->SlotIdFromOfflineChannel(chan); // if we ever need this...
66  // int femb_asic = channel_map->FEMBChannelFromOfflineChannel(chan) / 32; or this
67  femb_se[femb+slot*4].push_back(chan);
68  m_channel_femb[chan] = femb+slot*4;
69  }
70  m_init = true;
71  std::cout << "ShapedCohProtoDUNENoiseService initialised!\n";
72 }
73 
75 
77 
78 
79 
82  Channel c, AdcSignalVector& adcs) const {
83 
84  assert(adcs.size() <= m_n_tick);
85  int ret = addFEMBNoise(c, adcs, clock) + addHVNoise(c, adcs, clock) + addShapedNoise(c, adcs, clock);
86  return ret;
87 }
88 
90 
92  const geo::View_t view = geo->View(c);
93  CLHEP::HepRandomEngine& engine = *m_pran;
94  CLHEP::RandGauss g_ind(engine, m_induction_plane_noise , m_induction_plane_noise_rms );
96 
97  double ampl=-1;
98  while (ampl<0) {
99  switch (view) {
100  case geo::kU:
101  case geo::kV:
102  ampl = g_ind.fire();
103  break;
104  default:
105  ampl = g_col.fire();
106  break;
107  }
108  }
109  CLHEP::RandGauss rgauss(engine, 0, ampl);
110 
111  std::vector<double> noise_vec;
112  for (size_t i=0; i<m_n_tick; ++i)
113  noise_vec.push_back(rgauss.fire());
114 
116  sss->ConvoluteElectronicResponse(clock, c, noise_vec);
117 
118  std::transform(adcs.begin(), adcs.end(), noise_vec.begin(), adcs.begin(), std::plus<double>());
119 
120  return 0;
121 }
122 
124  const size_t femb = m_channel_femb.at(c%m_n_wire_per_apa);
125  const size_t apa = c/m_n_wire_per_apa;
126 
127  for (size_t sample=0; sample<adcs.size(); ++sample)
128  adcs[sample] += m_FEMBCo_Wfm_this_event_vec[apa][femb][sample];
129 
130  return 0;
131 }
132 
134 
135  for (size_t sample=0; sample<adcs.size(); ++sample)
136  adcs[sample] += m_HV1_Wfm_this_event_vec[sample];
137 
138  return 0;
139 }
140 
141 
142 
144  if (not m_init) init();
145 
146  CLHEP::RandGauss gaus(*m_pran);
147  CLHEP::RandFlat flat(*m_pran);
148  const double two_pi_tick_period = 6.2831853072/2000000;
149  for (size_t apa=0; apa<m_n_apa; ++apa) {
150  for (size_t femb=0; femb<m_FEMBCo_Frq_nominal.size(); ++femb) {
151  for (size_t noise=0; noise<m_FEMBCo_Frq_nominal[femb].size(); ++noise) {
152 
153  double frq = -1;
154  double amp = -1;
155  double phs = -1;
156 
157  while (frq<0)
158  frq = gaus.fire(m_FEMBCo_Frq_nominal[femb][noise], m_frequency_rms);
159 
160  while (amp<0)
161  amp = gaus.fire(m_FEMBCo_Amp_nominal[femb][noise], m_amplitude_rms);
162 
163  if (m_random_phase) {
164  while (phs<0)
165  phs = flat.fire(0, 6.2831853072);
166  } else {
167  throw std::runtime_error("ShapedCohProtoDUNENoiseService::newEvent(): Non random phases are not implemented yet");
168  }
169 
170  if (noise == 0) {
171  for (size_t sample=0; sample<m_n_tick; ++sample){
172  double two_pi_t_f = two_pi_tick_period*sample*frq;
173  m_FEMBCo_Wfm_this_event_vec[apa][femb][sample] = amp * sin(phs+two_pi_t_f);
174  }
175  } else {
176  for (size_t sample=0; sample<m_n_tick; ++sample){
177  double two_pi_t_f = two_pi_tick_period*sample*frq;
178  m_FEMBCo_Wfm_this_event_vec[apa][femb][sample] += amp * sin(phs+two_pi_t_f);
179  }
180  }
181  }
182  }
183  }
184 
185  for (size_t noise=0; noise<m_HV1_Frq_nominal.size(); ++noise) {
186  double frq = -1;
187  double amp = -1;
188  double phs = -1;
189 
190  while (frq<0)
191  frq = gaus.fire(m_HV1_Frq_nominal[noise], m_frequency_rms);
192 
193  while (amp<0)
194  amp = gaus.fire(m_HV1_Amp_nominal[noise], m_amplitude_rms);
195 
196  if (m_random_phase) {
197  while (phs<0)
198  phs = flat.fire(0, 6.2831853072);
199  } else {
200  throw std::runtime_error("ShaoedCohProtoDUNENoise::newEvent(): Non random phases are not implemented yet");
201  }
202 
203  if (noise == 0) {
204  for (size_t sample=0; sample<m_n_tick; ++sample){
205  double two_pi_t_f = two_pi_tick_period*sample*frq;
206  m_HV1_Wfm_this_event_vec[sample] = amp * sin(phs+two_pi_t_f);
207  }
208  } else {
209  for (size_t sample=0; sample<m_n_tick; ++sample){
210  double two_pi_t_f = two_pi_tick_period*sample*frq;
211  m_HV1_Wfm_this_event_vec[sample] += amp * sin(phs+two_pi_t_f);
212  }
213  }
214  }
215 }
216 
217 std::ostream& ShapedCohProtoDUNENoiseService::print(std::ostream& o, std::string) const {
218  return o;
219 }
220 
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
std::string string
Definition: nybbler.cc:12
std::vector< std::vector< double > > m_FEMBCo_Phs_nominal
Planes which measure V.
Definition: geo_types.h:130
std::vector< std::vector< double > > m_FEMBCo_Amp_nominal
std::ostream & print(std::ostream &, std::string) const
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
Planes which measure U.
Definition: geo_types.h:129
int addHVNoise(const Channel, AdcSignalVector &, detinfo::DetectorClocksData const &) const
unsigned int SlotIdFromOfflineChannel(unsigned int offlineChannel) const
Returns global slot ID.
static int g_col
T gaus(T x, T amplitude, T mean, T sigma)
Tests GausssianFit object with a known input.
ShapedCohProtoDUNENoiseService(fhicl::ParameterSet const &)
T get(std::string const &key) const
Definition: ParameterSet.h:271
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
void ConvoluteElectronicResponse(detinfo::DetectorClocksData const &clockData, Channel channel, std::vector< T > &func) const
int addNoise(detinfo::DetectorClocksData const &, detinfo::DetectorPropertiesData const &, Channel, AdcSignalVector &) const
Contains all timing reference information for the detector.
unsigned int FEMBFromOfflineChannel(unsigned int offlineChannel) const
Returns FEMB/fiber.
std::vector< std::vector< double > > m_FEMBCo_Frq_nominal
std::vector< AdcSignal > AdcSignalVector
Definition: AdcTypes.h:22
int addFEMBNoise(const Channel, AdcSignalVector &, detinfo::DetectorClocksData const &) const
LArSoft geometry interface.
Definition: ChannelGeo.h:16
double m_FEMBCo_Wfm_this_event_vec[m_n_apa][m_n_femb][m_n_tick]
int addShapedNoise(const Channel, AdcSignalVector &, detinfo::DetectorClocksData const &) const
#define DEFINE_ART_SERVICE_INTERFACE_IMPL(svc, iface)