3 #include <fwk/CentralConfig.h>
5 #include <utl/config.h>
6 #include <utl/AugerUnits.h>
7 #include <utl/ErrorLogger.h>
8 #include <utl/Reader.h>
9 #include <utl/TraceAlgorithm.h>
10 #include <utl/String.h>
13 #include <evt/Event.h>
15 #include <revt/Header.h>
16 #include <revt/REvent.h>
17 #include <revt/Station.h>
18 #include <revt/Channel.h>
19 #include <revt/StationRecData.h>
20 #include <revt/StationTriggerData.h>
22 #include <rdet/RDetector.h>
24 #include <sevt/SEvent.h>
25 #include <sevt/Station.h>
26 #include <sevt/StationSimData.h>
27 #include <sevt/StationTriggerData.h>
29 #include <sdet/SDetector.h>
30 #include <sdet/Station.h>
31 #include <sdet/StationTriggerUtil.h>
39 using namespace sdet::Trigger;
48 CentralConfig::GetInstance()->
GetTopBranch(
"RdSimulationRadioTrigger");
53 topBranch.
GetChild(
"RejectRFIMultiplicity").
GetData(fRejectRFIMultiplicity);
56 info <<
"\n\tUsing "<< (fThresholdMethod ?
"Geometric sum" :
"Maximum channel") <<
" as RD trigger method \n"
57 <<
"\tThreshold for a radio T2 trigger: "<< fRadioT2Threshold <<
" ADC counts";
69 WARNING(
"No radio event found!");
75 vector<int> RDT2Stations;
76 REvent& rEvent =
event.GetREvent();
85 const Detector& Det = Detector::GetInstance();
89 for (
auto& rStation : rEvent.StationsRange()) {
91 std::pair<ChannelTimeSeries, ChannelTimeSeries> channelAdcTrace;
93 for (
const auto& channel : rStation.ChannelsRange()) {
95 const unsigned int channelID = channel.GetId();
99 if (!rStation.HasChannel(channelID) || !channel.IsActive())
103 GetTraceWithoutDCOffset(channelAdcTrace.first, channel);
105 GetTraceWithoutDCOffset(channelAdcTrace.second, channel);
108 if (channelAdcTrace.first.GetSize() != channelAdcTrace.second.GetSize() ) {
110 msg <<
"Station " << rStation.GetId()
111 <<
" is rejected as its channel traces do not have the same length!";
119 const int binning = rStation.GetChannel(1).GetChannelADCTimeSeries().GetBinning();
121 double peakAmplitude = 0;
125 std::vector<unsigned int> t2Bins;
126 std::vector<unsigned int> rfiBins;
127 bool signalT2 =
false;
130 std::vector<double> finalAdcTrace;
132 const int maxCh0 = *max_element(channelAdcTrace.first.Begin(),
133 channelAdcTrace.first.End(), AbsValue);
134 const int maxCh1 = *max_element(channelAdcTrace.second.Begin(),
135 channelAdcTrace.second.End(), AbsValue);
137 if (fThresholdMethod == 0) {
139 std::copy(channelAdcTrace.first.Begin(), channelAdcTrace.first.End(),
140 std::back_inserter(finalAdcTrace));
142 std::copy(channelAdcTrace.second.Begin(), channelAdcTrace.second.End(),
143 std::back_inserter(finalAdcTrace));
144 }
else if (fThresholdMethod == 1) {
145 for (
unsigned int i = 0; i < channelAdcTrace.first.GetSize() ; ++i) {
146 finalAdcTrace.push_back(
sqrt(
Sqr(channelAdcTrace.first[i]) +
Sqr(channelAdcTrace.second[i])));
149 ERROR(
"Threshold method not existent.");
153 for (
unsigned int i = 0; i < finalAdcTrace.size(); ++i) {
154 if (
std::abs(finalAdcTrace[i]) > fRadioT2Threshold)
156 if (
std::abs(finalAdcTrace[i]) > fRejectRFIThreshold)
157 rfiBins.push_back(i);
161 if (t2Bins.empty()) {
163 msg <<
"Station " << rStation.GetId()
164 <<
" has no T2 trigger (not above threshold).";
172 for (
auto const& t2bin: t2Bins) {
173 const int cnt = std::count_if(std::begin(rfiBins), std::end(rfiBins),
174 [&t2bin](
unsigned int rfibin){
return (rfibin >= t2bin+25 && rfibin <= t2bin+275);});
175 if (cnt <= fRejectRFIMultiplicity) {
176 peakAmplitude = finalAdcTrace[t2bin];
177 peakTime = t2bin * binning / 1000;
186 msg <<
"Station " << rStation.GetId()
187 <<
" is rejected as it is a RFI trace!";
190 rStation.SetRejectedReason(
eNoisy);
196 RDT2Stations.push_back(sStID);
210 rStation.GetTriggerData().SetSelfTriggerTime(
211 (peakTime + rStation.GetRecData().GetParameter(eTraceStartTime)/1000 + 13.2) * 1000 *
nanosecond);
212 rStation.GetTriggerData().SetTriggerSource(StationTriggerData::eSelf);
213 rStation.GetTriggerData().SetSelfTriggerType(StationTriggerData::eT2Threshold);
214 rStation.GetTriggerData().SetSelfTriggerBin(sample);
215 rStation.GetTriggerData().SetSelfTriggerAmp(peakAmplitude);
217 vector<const TimeDistributionI*> traces;
223 if (traces.size() < 3)
226 const auto& dStation = Detector::GetInstance().GetSDetector().GetStation(sStation);
227 const int WCDTrigBin = rStation.GetTriggerData().GetSelfTriggerTime() / dStation.GetFADCBinSize();
228 const int traceStart =
std::max(WCDTrigBin - (
int)dStation.GetFADCTraceLength(), startBin);
230 traceStart, WCDTrigBin);
233 if (!RDT2Stations.empty()) {
244 RdSimulationRadioTrigger::Finish()
247 info <<
"\n\tThere were " << fNbOfSaturatedChannels <<
" saturated channels!";
259 for (
auto& adcSignal : adcTrace)
260 currTrace.
PushBack((
double)adcSignal - mean);
265 RdSimulationRadioTrigger::AbsValue(
double a ,
double b)
Branch GetTopBranch() const
constexpr T Sqr(const T &x)
bool HasStation(const int stationId) const
Check whether station exists.
void MakeSimData()
Make station simulated data object.
void PrepareTraces(const sevt::Station &station, int &startBin, int &stopBin, std::vector< const TimeDistributionI * > &traces)
Interface class to access to the Radio part of an event.
Interface class to access to the SD 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.
Detector description interface for RDetector-related data.
Class representing a document branch.
int GetRdSdStationIdLink() const
Get Rd - Sd Station Id link.
class to hold data at Station level
bool HasSimData() const
Check whether station simulated data exists.
void SetRejected(const int reason)
Set rejected station flag.
constexpr double nanosecond
double abs(const SVector< n, T > &v)
Header & GetHeader()
access to REvent Header
Top of the hierarchy of the detector description interface.
void MakeStation(const int stationId)
make a station with specifying Id, throw if invalid stationId
#define WARNING(message)
Macro for logging warning messages.
void GetData(bool &b) const
Overloads of the GetData member template function.
Station & GetStation(const int stationId)
retrieve station by id throw utl::NonExistentComponentException if n.a.
ResultFlag
Flag returned by module methods to the RunController.
ChannelADCTimeSeries & GetChannelADCTimeSeries()
Get Channel ADC trace (write access, only use this if you intend to change the data) ...
Class that holds the data associated to an individual radio channel.
const rdet::RDetector & GetRDetector() const
double Mean(const std::vector< double > &v)
void Buffer(sevt::Station &station, const TimeStamp &eventTime, const StationTriggerData::Algorithm algorithm, const int pldBits, const int start, const int stop)
string OfSortedIds(vector< int > ids)
void PushBack(const T &value)
Insert a single value at the end.
#define ERROR(message)
Macro for logging error messages.