2 #include <utl/ErrorLogger.h>
5 #include <revt/REvent.h>
6 #include <revt/Header.h>
7 #include <revt/Station.h>
8 #include <revt/Channel.h>
10 #include <det/Detector.h>
11 #include <rdet/RDetector.h>
12 #include <rdet/Station.h>
13 #include <rdet/Channel.h>
15 #include <utl/Trace.h>
16 #include <utl/TraceAlgorithm.h>
17 #include <utl/ErrorLogger.h>
18 #include <utl/Reader.h>
19 #include <utl/config.h>
20 #include <utl/AugerUnits.h>
25 #include <fwk/CentralConfig.h>
30 #include <boost/tokenizer.hpp>
31 #include <boost/algorithm/string/replace.hpp>
39 typedef boost::tokenizer<boost::char_separator<char> >
mytok;
46 fPathToAsciitrace(
""),
47 fUseAlwaysTheSameTrace(false),
48 fUseRandomSeed(false),
49 fStopAtLastNoiseTrace(true)
53 RdChannelNoiseASCIIImporter::~RdChannelNoiseASCIIImporter()
66 INFO(
"RdChannelNoiseASCIIImporter::Init()");
68 Branch topBranch = CentralConfig::GetInstance()->
GetTopBranch(
"RdChannelNoiseASCIIImporter");
79 std::srand(time(NULL));
85 std::random_shuffle(
v_id.begin(),
v_id.end());
92 INFO(
"RdChannelNoiseASCIIImporter::Run()");
95 WARNING(
"end of noise list reached, traces will be reshuffled and used again");
96 std::random_shuffle(
v_id.begin(),
v_id.end());
99 cerr <<
"End of the Noise List" << endl;
103 vector<int> v_stationid;
108 ifstream inf(fname.str().c_str());
109 while (!inf.good()) {
110 INFO(
"file does not exist, moving to next file");
112 if (viter ==
v_id.end()) {
114 WARNING(
"end of noise list reached, traces will be reshuffled and used again");
115 std::random_shuffle(
v_id.begin(),
v_id.end());
116 viter =
v_id.begin();
118 cerr <<
"End of the Noise List" << endl;
125 inf.open(fname.str().c_str());
131 boost::char_separator<char> sep(
" ");
132 map<string, vector<int> > m_traces;
134 int currentStationId = 0;
135 while (getline(inf, zeline)) {
136 vector<int> v_values;
137 vector<string> v_tokens;
141 mytok tok(zeline, sep);
142 for (mytok::const_iterator titer = tok.begin(); titer != tok.end(); ++titer) {
143 v_tokens.push_back(*titer);
145 for (
unsigned int i = 3; i < v_tokens.size(); i++) {
146 int val = atoi(v_tokens[i].c_str());
147 v_values.push_back(val);
150 if(atoi(v_tokens[0].c_str()) != currentStationId) {
151 v_stationid.push_back(atoi(v_tokens[0].c_str()));
152 currentStationId = atoi(v_tokens[0].c_str());
155 m_traces[name] = v_values;
158 random_shuffle(v_stationid.begin(), v_stationid.end());
159 vector<int>::iterator randomstationiterator = v_stationid.begin();
163 WARNING(
"RdChannelNoiseASCIIImporter::No radio event found!");
168 REvent& rEvent =
event.GetREvent();
170 bool randomNoiseStationUsed =
false;
174 if(randomNoiseStationUsed) {
175 std::advance(randomstationiterator, 1);
176 randomNoiseStationUsed =
false;
184 map<string, vector<int> >::const_iterator miter = m_traces.find(name);
185 if (miter == m_traces.end()) {
186 if (randomstationiterator == v_stationid.end()) {
187 std::random_shuffle(v_stationid.begin(), v_stationid.end());
188 randomstationiterator = v_stationid.begin();
191 randomNoiseStationUsed =
true;
193 out <<
" Unable to Find Station_Channel " << name;
195 out <<
" -> Will use a station " << name <<
" instead";
199 miter = m_traces.find(name);
200 if (miter == m_traces.end()) {
203 out <<
" Damned we are unlucky station " << name <<
" is not found I give up. Setting channel as inactive";
214 short numberOfADCCounts =
pow(2., bitDepth) - 1;
216 if (miter->second.size() != timeSeries.
GetSize()) {
218 out <<
" Station_Channel " << name <<
"\n";
219 out <<
"Channel size " << timeSeries.
GetSize() <<
" \n";
220 out <<
"Noise size " << miter->second.size() <<
"\n";
221 out <<
" Channel " << name
222 <<
" Is set as inactive, please check if this is coherent with what you are doing";
227 for (
unsigned int i = 0; i < timeSeries.
GetSize(); ++i) {
228 int val = timeSeries[i] + miter->second[i];
231 if (val > numberOfADCCounts) {
233 out <<
"ADC overflow (ADC = " << val <<
", bin " << i <<
" , station "
234 << cIt->GetStationId() <<
")\tnoise = " << miter->second[i] <<
"\tsignal = "
237 val = numberOfADCCounts;
241 out <<
"ADC underflow (ADC = " << val <<
", bin " << i <<
" , station "
242 << cIt->GetStationId() <<
")\tnoise = " << miter->second[i] <<
"\tsignal = "
260 INFO(
"RdChannelNoiseASCIIImporter::Finish()");
265 string RdChannelNoiseASCIIImporter::GetStringFromStatChan(
int statid,
int chanid)
268 name << statid <<
"_" << chanid;
275 int int_mean = int(fabs(mean));
277 *it = *it - int_mean;
281 void RdChannelNoiseASCIIImporter::RemovePedestal(std::vector<int>& timeSeries)
285 for (std::vector<int>::iterator it = timeSeries.begin(); it != timeSeries.end(); ++it) {
290 int int_mean = int(fabs(mean));
291 for (std::vector<int>::iterator it = timeSeries.begin(); it != timeSeries.end(); ++it) {
292 *it = *it - int_mean;
Branch GetTopBranch() const
int GetId() const
Return Id of the Channel.
Report success to RunController.
Interface class to access to the Radio part of an event.
static double Mean(const Trace< T > &trace, const unsigned int bin1, const unsigned int bin2)
Evaluate the mean of trace between bin1 and bin2.
Skip remaining modules in the current loop and continue with next iteration of the loop...
#define INFO(message)
Macro for logging informational messages.
StationIterator StationsEnd()
StationIterator StationsBegin()
void Init()
Initialise the registry.
vector< t2list > out
output of the algorithm: a list of clusters
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
ChannelIterator ChannelsBegin()
begin Channel iterator for read/write
double pow(const double x, const unsigned int i)
boost::filter_iterator< StationFilter, AllStationIterator > StationIterator
Iterator over all (non-exculded) stations.
ChannelTimeSeries & GetChannelTimeSeries()
retrieve Channel Time Series (write access, only use this if you intend to change the data) ...
ChannelIterator ChannelsEnd()
end Channel iterator for read/write
int fNumberOfFiles
Writes out a spectrum in an ASCII file.
Class representing a document branch.
class to hold data at the radio Station level.
bool fStopAtLastNoiseTrace
bool fUseAlwaysTheSameTrace
std::string AddZero(int val)
Top of the hierarchy of the detector description interface.
void RemovePedestal(revt::ChannelTimeSeries &timeSeries)
#define WARNING(message)
Macro for logging warning messages.
void GetData(bool &b) const
Overloads of the GetData member template function.
int GetId() const
Get the station Id.
std::vector< int >::iterator viter
ResultFlag
Flag returned by module methods to the RunController.
boost::tokenizer< boost::char_separator< char > > mytok
Class that holds the data associated to an individual radio channel.
const rdet::RDetector & GetRDetector() const
const Station & GetStation(const int stationId) const
Get station by Station Id.
std::vector< double >::iterator Iterator
std::string GetStringFromStatChan(int statid, int chanid)
std::string fPathToAsciitrace