12 , fSampling(fParams.frequency)
13 , fQEDirect(fParams.QEDirect / fParams.larProp->
ScintPreScale())
23 mf::LogInfo(
"DigiPMTSBNDAlg") <<
"PMT corrected efficiencies = "
26 if(fQERefl > 1.0001 ||
fQEDirect > 1.0001)
27 mf::LogWarning(
"DigiPMTSBNDAlg")
30 <<
"Final QE must be equal or smaller than the scintillation "
31 <<
"pre scale applied at simulation time.\n"
32 <<
"Please check this number (ScintPreScale): "
38 cet::search_path sp(
"FW_SEARCH_PATH");
40 TFile*
file = TFile::Open(fname.c_str(),
"READ");
43 std::vector<double>* timeTPB_p;
44 file->GetObject(
"timeTPB", timeTPB_p);
45 fTimeTPB = std::make_unique<CLHEP::RandGeneral>
46 (*
fEngine, timeTPB_p->data(), timeTPB_p->size());
50 mf::LogDebug(
"DigiPMTSBNDAlg") <<
" using testbench pe response";
51 std::vector<double>* SinglePEVec_p;
52 file->GetObject(
"SinglePEVec", SinglePEVec_p);
57 mf::LogDebug(
"DigiPMTSBNDAlg") <<
" using ideal pe response";
82 std::vector<short unsigned int>& waveform,
89 waveform = std::vector<short unsigned int> (waves.begin(), waves.end());
94 std::vector<short unsigned int>& waveform,
95 std::unordered_map<int, sim::SimPhotons>& DirectPhotonsMap,
96 std::unordered_map<int, sim::SimPhotons>& ReflectedPhotonsMap,
102 waveform = std::vector<short unsigned int> (waves.begin(), waves.end());
109 std::vector<short unsigned int>& waveform,
116 waveform = std::vector<short unsigned int> (waves.begin(), waves.end());
122 std::vector<short unsigned int>& waveform,
123 std::unordered_map<int, sim::SimPhotonsLite>& DirectPhotonsMap,
124 std::unordered_map<int, sim::SimPhotonsLite>& ReflectedPhotonsMap,
130 waveform = std::vector<short unsigned int> (waves.begin(), waves.end());
137 std::vector<double>& wave,
145 for(
size_t i = 0; i < simphotons.size(); i++) {
150 if(tphoton < 0.)
continue;
152 if(timeBin < wave.size()) {
AddSPE(timeBin, wave);}
165 std::vector<double>& wave,
166 std::unordered_map<int, sim::SimPhotons>& DirectPhotonsMap,
167 std::unordered_map<int, sim::SimPhotons>& ReflectedPhotonsMap)
177 if(
auto it{ DirectPhotonsMap.find(ch) }; it !=
std::end(DirectPhotonsMap) )
178 {auxphotons = it->second;}
179 for(
size_t j = 0; j < auxphotons.size(); j++) {
184 if(tphoton < 0.)
continue;
186 if(timeBin < wave.size()) {
AddSPE(timeBin, wave);}
190 if(
auto it{ ReflectedPhotonsMap.find(ch) }; it !=
std::end(ReflectedPhotonsMap) )
191 {auxphotons = it->second;}
192 for(
size_t j = 0; j < auxphotons.size(); j++) {
197 if(tphoton < 0.)
continue;
199 if(timeBin < wave.size()) {
AddSPE(timeBin, wave);}
213 std::vector<double>& wave,
218 size_t accepted_photons;
225 for (
auto const& reflectedPhotons : photonMap) {
228 mean_photons = reflectedPhotons.second*
fQERefl;
230 for(
size_t i = 0; i < accepted_photons; i++) {
233 tphoton = ttsTime + reflectedPhotons.first - t_min + ttpb +
fParams.
CableTime;
234 if(tphoton < 0.)
continue;
236 if(timeBin < wave.size()) {
AddSPE(timeBin, wave);}
249 std::vector<double>& wave,
250 std::unordered_map<int, sim::SimPhotonsLite>& DirectPhotonsMap,
251 std::unordered_map<int, sim::SimPhotonsLite>& ReflectedPhotonsMap)
254 size_t accepted_photons;
260 if (
auto it{ DirectPhotonsMap.find(ch) }; it !=
std::end(DirectPhotonsMap) ){
261 for (
auto& directPhotons : (it->second).DetectedPhotons) {
264 mean_photons = directPhotons.second*
fQEDirect;
266 for(
size_t i = 0; i < accepted_photons; i++) {
270 if(tphoton < 0.)
continue;
272 if(timeBin < wave.size()) {
AddSPE(timeBin, wave);}
278 if (
auto it{ ReflectedPhotonsMap.find(ch) }; it !=
std::end(ReflectedPhotonsMap) ){
279 for (
auto& reflectedPhotons : (it->second).DetectedPhotons) {
282 mean_photons = reflectedPhotons.second*
fQERefl;
284 for(
size_t i = 0; i < accepted_photons; i++) {
287 tphoton = ttsTime + reflectedPhotons.first - t_min + ttpb +
fParams.
CableTime;
288 if(tphoton < 0.)
continue;
290 if(timeBin < wave.size()) {
AddSPE(timeBin, wave);}
308 for(
size_t i = 0; i<fSinglePEWave.size(); i++) {
309 time =
static_cast<double>(i) /
fSampling;
330 auto min_it = std::next(wave.begin(), time_bin);
331 auto max_it = std::next(wave.begin(), max);
336 [npe](
auto a,
auto b) {
return a+npe*b; });
341 std::plus<double>( ));
348 std::replace_if(wave.begin(), wave.end(),
369 [
this](
double w) ->
double {
380 while(darkNoiseTime < wave.size()) {
381 timeBin = std::round(darkNoiseTime);
382 if(timeBin < wave.size()) {
AddSPE(timeBin, wave);}
394 std::unordered_map<int, sim::SimPhotons>& directPhotonsOnPMTS)
398 if(pdtype ==
"pmt_uncoated") {
400 for(
size_t i = 0; i < simphotons.size(); i++) {
401 if(simphotons[i].Time < t_min) t_min = simphotons[i].Time;
404 else if(pdtype ==
"pmt_coated") {
406 if (
auto it{ directPhotonsOnPMTS.find(ch) }; it !=
std::end(directPhotonsOnPMTS) )
407 {auxphotons = it->second;}
408 auxphotons += (simphotons);
410 for(
size_t i = 0; i < auxphotons.size(); i++) {
411 if(auxphotons[i].Time < t_min) t_min = auxphotons[i].Time;
415 throw cet::exception(
"DigiPMTSBNDAlg") <<
"Wrong pdtype: " << pdtype << std::endl;
426 std::unordered_map<int, sim::SimPhotonsLite>& directPhotonsOnPMTS)
429 if(pdtype ==
"pmt_uncoated") {
431 auto min = std::find_if(
434 [](
const auto& pm) {
return pm.second != 0; });
435 if(min != photonMap.end())
return double(min->first);
437 else if(pdtype ==
"pmt_coated") {
439 if (
auto it{ directPhotonsOnPMTS.find(ch) }; it !=
std::end(directPhotonsOnPMTS) )
440 {auxphotons = it->second;}
443 auxphotons += (litesimphotons);
445 auto min = std::find_if(
446 auxphotonMap.begin(),
448 [](
const auto& pm) {
return pm.second != 0; });
449 if(min != auxphotonMap.end())
return double(min->first);
452 throw cet::exception(
"DigiPMTSBNDAlg") <<
"Wrong pdtype: " << pdtype << std::endl;
468 fBaseConfig.QEDirect = config.
qEDirect();
469 fBaseConfig.QERefl = config.
qERefl();
477 fBaseConfig.TTS = config.
tts();
478 fBaseConfig.CableTime = config.
cableTime();
484 std::unique_ptr<DigiPMTSBNDAlg>
488 CLHEP::HepRandomEngine* engine
497 params.engine = engine;
499 return std::make_unique<DigiPMTSBNDAlg>(params);
std::unique_ptr< CLHEP::RandGeneral > fTimeTPB
void CreatePDWaveformLiteCoatedPMT(int ch, double t_min, std::vector< double > &wave, std::unordered_map< int, sim::SimPhotonsLite > &DirectPhotonsMap, std::unordered_map< int, sim::SimPhotonsLite > &ReflectedPhotonsMap)
void CreatePDWaveformLite(sim::SimPhotonsLite const &litesimphotons, double t_min, std::vector< double > &wave, int ch, std::string pdtype)
ConfigurationParameters_t fParams
void ConstructWaveform(int ch, sim::SimPhotons const &simphotons, std::vector< short unsigned int > &waveform, std::string pdtype, double start_time, unsigned n_sample)
CLHEP::RandExponential fExponentialGen
stream1 stream1 can override from command line with o or output services LArPropertiesService ScintPreScale
DigiPMTSBNDAlg::ConfigurationParameters_t fBaseConfig
void ConstructWaveformLiteCoatedPMT(int ch, std::vector< short unsigned int > &waveform, std::unordered_map< int, sim::SimPhotonsLite > &DirectPhotonsMap, std::unordered_map< int, sim::SimPhotonsLite > &ReflectedPhotonsMap, double start_time, unsigned n_sample)
fhicl::Atom< double > transitTime
bool MakeGainFluctuations
void CreateSaturation(std::vector< double > &wave)
fhicl::Atom< double > pmtdarkNoiseRate
std::vector< double > fSinglePEWave
void ConstructWaveformLite(int ch, sim::SimPhotonsLite const &litesimphotons, std::vector< short unsigned int > &waveform, std::string pdtype, double start_time, unsigned n_sample)
fhicl::ParameterSet GainFluctuationsParams
std::map< int, int > DetectedPhotons
Number of photons detected at each given time: time tick -> photons.
fhicl::Atom< double > pmtfallTime
const double transitTimeSpread_frac
void AddDarkNoise(std::vector< double > &wave)
double Transittimespread(double fwhm)
void AddLineNoise(std::vector< double > &wave)
std::unique_ptr< DigiPMTSBNDAlg > operator()(detinfo::LArProperties const &larProp, detinfo::DetectorClocksData const &clockData, CLHEP::HepRandomEngine *engine) const
fhicl::Atom< std::string > pmtDataFile
void CreatePDWaveformCoatedPMT(int ch, double t_min, std::vector< double > &wave, std::unordered_map< int, sim::SimPhotons > &DirectPhotonsMap, std::unordered_map< int, sim::SimPhotons > &ReflectedPhotonsMap)
auto end(FixedBins< T, C > const &) noexcept
fEngine(art::ServiceHandle< rndm::NuRandomService >() ->createEngine(*this, pset,"Seed"))
CLHEP::RandPoissonQ fPoissonQGen
CLHEP::HepRandomEngine * fEngine
Reference to art-managed random-number engine.
void ConstructWaveformCoatedPMT(int ch, std::vector< short unsigned int > &waveform, std::unordered_map< int, sim::SimPhotons > &DirectPhotonsMap, std::unordered_map< int, sim::SimPhotons > &ReflectedPhotonsMap, double start_time, unsigned n_sample)
fhicl::Atom< bool > makeGainFluctuations
fhicl::Atom< double > pmtsaturation
std::unique_ptr< opdet::PMTGainFluctuations > fPMTGainFluctuationsPtr
fhicl::Atom< double > qEDirect
ElecClock const & OpticalClock() const noexcept
Borrow a const Optical clock with time set to Trigger time [us].
DigiPMTSBNDAlg(ConfigurationParameters_t const &config)
virtual double ScintPreScale(bool prescale=true) const =0
fhicl::Atom< double > pmtmeanAmplitude
fhicl::Atom< double > pmtchargeToADC
fhicl::Atom< bool > PMTsinglePEmodel
fhicl::Atom< double > pmtbaselineRMS
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
void CreatePDWaveform(sim::SimPhotons const &SimPhotons, double t_min, std::vector< double > &wave, int ch, std::string pdtype)
Collection of photons which recorded on one channel.
Compact representation of photons on a channel.
then echo fcl sbnd_project sbnd_project sbnd_project sbnd_project production production start_time
fhicl::Atom< double > cableTime
Contains all timing reference information for the detector.
fhicl::Atom< double > tts
fhicl::Atom< double > pmtriseTime
constexpr double Frequency() const
Frequency in MHz.
void Pulse1PE(std::vector< double > &wave)
DigiPMTSBNDAlgMaker(Config const &config)
fhicl::Atom< double > qERefl
double FindMinimumTimeLite(sim::SimPhotonsLite const &litesimphotons, int ch, std::string pdtype, std::unordered_map< int, sim::SimPhotonsLite > &directPhotonsOnPMTS)
void AddSPE(size_t time_bin, std::vector< double > &wave)
fhicl::OptionalDelegatedParameter gainFluctuationsParams
detinfo::LArProperties const * larProp
CLHEP::RandGaussQ fGaussQGen
fhicl::Atom< double > pmtbaseline
double FindMinimumTime(sim::SimPhotons const &, int ch, std::string pdtype, std::unordered_map< int, sim::SimPhotons > &directPhotonsOnPMTS)