4 #include <evt/ShowerSimData.h>
6 #include <revt/REvent.h>
7 #include <revt/Header.h>
8 #include <revt/Station.h>
9 #include <revt/Channel.h>
11 #include <det/Detector.h>
12 #include <rdet/RDetector.h>
13 #include <rdet/Station.h>
14 #include <rdet/Channel.h>
16 #include <utl/Trace.h>
17 #include <utl/TraceAlgorithm.h>
18 #include <utl/ErrorLogger.h>
19 #include <utl/Reader.h>
20 #include <utl/config.h>
21 #include <utl/AugerUnits.h>
22 #include <utl/RandomEngine.h>
23 #include <utl/UTCDateTime.h>
24 #include <utl/TimeStamp.h>
26 #include <fwk/RandomEngineRegistry.h>
27 #include <fwk/CentralConfig.h>
29 #include <boost/algorithm/string.hpp>
36 #include <CLHEP/Random/RandFlat.h>
66 ERROR(
"Imported noise for the two channels are not same size or size is 0!");
71 std::ostringstream infostr;
72 infostr <<
"\n\tRead " <<
fNoiseTraces[0].size() <<
" traces for channel 0 and "
89 WARNING(
"RdChannelASCIINoiseImporterRD::No radio event found!");
97 std::ostringstream infostr;
98 std::ostringstream warnstr;
99 std::ostringstream debugstr;
102 for (
auto& station : rEvent.StationsRange()) {
103 const int stationID = station.GetId();
107 unsigned int sampleIndexNoiseStart = 0;
113 sampleIndexNoiseStart = CLHEP::RandFlat::shootInt(
fRandomEngine, 0, 25) *
118 for (
auto& channel : station.ChannelsRange()) {
120 const unsigned int channelID = channel.GetId();
124 if (!station.HasChannel(channelID) || !channel.IsActive())
131 sampleIndexNoiseStart = CLHEP::RandFlat::shootInt(
fRandomEngine, 0, 25) *
137 const short bitDepth = rDetStation.
GetChannel(channel.GetId()).GetBitDepth();
139 double minVoltage = rDetStation.
GetChannel(channel.GetId()).GetMinVoltage();
140 double maxVoltage = rDetStation.
GetChannel(channel.GetId()).GetMaxVoltage();
141 double voltagePerCount = (maxVoltage - minVoltage) /
pow(2, bitDepth);
146 const unsigned int traceLength =
fNoiseTraces[channelID][traceIndex].size();
147 for (
unsigned int i = 0; i < timeSeries.
GetSize(); ++i) {
149 unsigned int sampleIndexNoise = (sampleIndexNoiseStart + i) % traceLength;
151 const int noiseADCValue =
fNoiseTraces.at(channelID).at(traceIndex).at(sampleIndexNoise);
158 int val = timeSeries[i] + noiseADCValue;
164 if (val > maxVoltage/voltagePerCount -1) {
165 val = maxVoltage/voltagePerCount -1;
167 infostr <<
"ADC overflow (ADC = " << val <<
", bin: " << i <<
").\tStation "
168 << channel.GetStationId() <<
")\tnoise = " << noiseADCValue <<
"\tsignal = " << timeSeries[i];
171 if (val < minVoltage/voltagePerCount) {
172 val = minVoltage/voltagePerCount;
174 infostr <<
"ADC underflow (ADC = " << val <<
", bin: " << i <<
").\tStation "
175 << channel.GetStationId() <<
")\tnoise = " << noiseADCValue <<
"\tsignal = " << timeSeries[i];
188 RdChannelASCIINoiseImporterRD::Finish()
194 RdChannelASCIINoiseImporterRD::ReadNoiseFile(
const std::string fileName,
const unsigned int channelId) {
196 std::ifstream noiseFile(fileName);
198 ERROR(
"Could not imported noise from asci file.");
200 std::vector<std::vector<int>> noiseTracesChannel;
201 if (noiseFile.is_open())
203 while (getline(noiseFile, line))
208 std::vector<std::string> lineSplited;
209 boost::split(lineSplited, line, [](
char c) {
return c ==
','; });
210 std::vector<int> noiseTrace;
213 noiseTrace.push_back(std::stoi(lineSplited[column]));
215 noiseTracesChannel.push_back(noiseTrace);
std::vector< std::vector< std::vector< int > > > fNoiseTraces
Report success to RunController.
std::string fNoiseFilePathCh1
Detector description interface for Station-related data.
Interface class to access to the Radio part of an event.
Skip remaining modules in the current loop and continue with next iteration of the loop...
void ReadNoiseFile(const std::string fileName, const unsigned int channelId)
#define INFO(message)
Macro for logging informational messages.
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
double pow(const double x, const unsigned int i)
bool fReplaceDataWithNoise
utl::RandomEngine::RandomEngineType * fRandomEngine
Detector description interface for RDetector-related data.
Class representing a document branch.
Top of the hierarchy of the detector description interface.
int fSkipTrailingColumnsInNoiseFile
#define WARNING(message)
Macro for logging warning messages.
void GetData(bool &b) const
Overloads of the GetData member template function.
std::string fNoiseFilePathCh0
bool fAddNoiseFromSameTimeToBothChannels
const Channel & GetChannel(const int id) const
Get specified Channel by id.
double fMaxTimeDifference
ResultFlag
Flag returned by module methods to the RunController.
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
Report failure to RunController, causing RunController to terminate execution.
const rdet::RDetector & GetRDetector() const
#define ERROR(message)
Macro for logging error messages.
const Station & GetStation(const int stationId) const
Get station by Station Id.
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)