8 #include <evt/ShowerSimData.h>
10 #include <revt/REvent.h>
11 #include <revt/Header.h>
12 #include <revt/Station.h>
13 #include <revt/Channel.h>
15 #include <det/Detector.h>
16 #include <rdet/RDetector.h>
17 #include <rdet/Station.h>
18 #include <rdet/Channel.h>
20 #include <utl/Trace.h>
21 #include <utl/TraceAlgorithm.h>
22 #include <utl/ErrorLogger.h>
23 #include <utl/Reader.h>
24 #include <utl/config.h>
25 #include <utl/AugerUnits.h>
26 #include <utl/RandomEngine.h>
28 #include <fwk/RandomEngineRegistry.h>
29 #include <fwk/CentralConfig.h>
31 #include <CLHEP/Random/RandFlat.h>
47 topBranch.
GetChild(
"AddNoiseFromSameTimeToBothChannels").
GetData(fAddNoiseFromSameTimeToBothChannels);
49 topBranch.
GetChild(
"ReplaceDataWithNoise").
GetData(fReplaceDataWithNoise);
63 WARNING(
"No radio event found!");
68 if (fAddNoiseFromSameTimeToBothChannels) {
69 if (fNoiseTraces.first.size() != fNoiseTraces.second.size() || fNoiseTraces.first.size() == 0) {
70 ERROR(
"Imported noise for the two channels are not same size or size is 0!");
75 std::ostringstream infostr;
76 infostr <<
"\n\tRead " << fNoiseTraces.first.size() <<
" traces for channel 0 and "
77 << fNoiseTraces.second.size() <<
" traces for channel 1"
78 <<
"\n\tAddNoiseFromSameTimeToBothChannels : " << fAddNoiseFromSameTimeToBothChannels
79 <<
"\n\tAllow trace shifting : " << fTraceShifting;
85 REvent& rEvent =
event.GetREvent();
89 for (
auto& station : rEvent.StationsRange()) {
90 const int stationID = station.GetId();
93 unsigned int traceIndex = CLHEP::RandFlat::shootInt(fRandomEngine, 0, fNoiseTraces.first.size());
94 unsigned int sampleIndexNoiseStart = 0;
99 if (fTraceShifting && fAddNoiseFromSameTimeToBothChannels) {
100 sampleIndexNoiseStart = CLHEP::RandFlat::shootInt(fRandomEngine, 0, 25) *
101 fNoiseTraces.first[traceIndex].GetSize() / 25;
105 for (
auto& channel : station.ChannelsRange()) {
106 auto& timeSeries = channel.GetChannelADCTimeSeries();
107 const unsigned int channelID = channel.
GetId();
111 if (!station.HasChannel(channelID) || !channel.IsActive())
114 std::vector<ChannelADCTimeSeries> tempVec;
115 if (channelID == 0) {
116 tempVec = fNoiseTraces.first;
118 tempVec = fNoiseTraces.second;
121 if (!fAddNoiseFromSameTimeToBothChannels) {
123 traceIndex = CLHEP::RandFlat::shootInt(fRandomEngine, 0, tempVec.size());
124 if (fTraceShifting) {
125 sampleIndexNoiseStart = CLHEP::RandFlat::shootInt(fRandomEngine, 0, 25) *
126 tempVec[traceIndex].GetSize() / 25;
131 const short bitDepth = rDetStation.
GetChannel(channel.GetId()).GetBitDepth();
132 const short numberOfADCCounts =
pow(2., bitDepth) / 2;
137 const unsigned int traceLength = tempVec[traceIndex].
GetSize();
138 for (
unsigned int i = 0; i < timeSeries.GetSize(); ++i) {
140 unsigned int sampleIndexNoise = (sampleIndexNoiseStart + i) % traceLength;
142 const int noiseADCValue = tempVec.at(traceIndex).At(sampleIndexNoise);
144 int val = timeSeries[i] + noiseADCValue;
146 if (fReplaceDataWithNoise)
150 if (val > numberOfADCCounts - 1) {
151 val = numberOfADCCounts - 1;
153 infostr <<
"ADC overflow (ADC = " << val <<
", bin: " << i <<
").\tStation "
154 << channel.GetStationId() <<
")\tnoise = " << noiseADCValue <<
"\tsignal = " << timeSeries[i];
158 if (val < -1 * numberOfADCCounts) {
159 val = -1 * numberOfADCCounts;
161 infostr <<
"ADC overflow (ADC = " << val <<
", bin: " << i <<
").\tStation "
162 << channel.GetStationId() <<
")\tnoise = " << noiseADCValue <<
"\tsignal = " << timeSeries[i];
176 RdChannelNoiseImporter_RD::Finish()
183 RdChannelNoiseImporter_RD::ReadFromRootFile()
185 std::ifstream noiseFile(fNoiseFilePath);
187 ERROR(
"Given noise file not existent.");
191 TFile* fileIn = TFile::Open(fNoiseFilePath.c_str());
192 TList* keys = fileIn->GetListOfKeys();
196 while ((key = (TKey*)
next())) {
197 TObject* obj = key->ReadObj();
198 if (obj->InheritsFrom(
"TTree")) {
203 for(
int counter = 0; counter < numTrees -1; ++counter) {
204 std::string treename =
"Noisetree_" + std::to_string(counter);
205 TTree* noiseTree = (TTree*)fileIn->Get(treename.c_str());
209 TBranch* traceCh0Branch = noiseTree->GetBranch(
"traceCh0");
210 traceCh0Branch->SetAddress(&noiseEvent.
traceCh0);
211 TBranch* traceCh1Branch = noiseTree->GetBranch(
"traceCh1");
212 traceCh1Branch->SetAddress(&noiseEvent.
traceCh1);
229 for (
const auto& bin : noiseEvent.
traceCh0) {
232 for (
const auto& bin : noiseEvent.
traceCh1) {
236 fNoiseTraces.first.push_back(noiseTraceCh0);
237 fNoiseTraces.second.push_back(noiseTraceCh1);
Detector description interface for Station-related data.
Interface class to access to the Radio part of an event.
#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)
Detector description interface for RDetector-related data.
Iterator next(Iterator it)
Class representing a document branch.
Top of the hierarchy of the detector description interface.
int GetId() const
Station ID.
#define WARNING(message)
Macro for logging warning messages.
void GetData(bool &b) const
Overloads of the GetData member template function.
const Channel & GetChannel(const int id) const
Get specified Channel by id.
ResultFlag
Flag returned by module methods to the RunController.
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
const rdet::RDetector & GetRDetector() const
void PushBack(const T &value)
Insert a single value at the end.
#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)