RdTimeJitterAdder.cc
Go to the documentation of this file.
1 #include "RdTimeJitterAdder.h"
2 
3 #include <fwk/CentralConfig.h>
4 #include <fwk/RandomEngineRegistry.h>
5 
6 #include <evt/Event.h>
7 #include <revt/REvent.h>
8 #include <revt/Station.h>
9 #include <revt/StationRecData.h>
10 
11 #include <det/Detector.h>
12 #include <rdet/RDetector.h>
13 #include <sdet/SDetector.h>
14 
15 #include <sevt/SEvent.h>
16 #include <sevt/Station.h>
17 #include <sevt/StationSimData.h>
18 
19 #include <utl/AugerUnits.h>
20 #include <utl/Branch.h>
21 #include <utl/RandomEngine.h>
22 
23 #include <CLHEP/Random/RandGauss.h>
24 
25 using namespace fwk;
26 using namespace revt;
27 using namespace utl;
28 using namespace std;
29 
30 using CLHEP::RandGauss;
31 
32 
33 namespace RdTimeJitterAdder {
34 
37  {
38  const Branch topBranch = CentralConfig::GetInstance()->GetTopBranch("RdTimeJitterAdder");
39  topBranch.GetChild("sigma").GetData(fSigma);
40 
41  ostringstream info;
42  info << "\n\t RdTimeJitterAdder is set up with sigma of " << fSigma / ns << " ns.\n";
43  INFO(info);
44 
45  fRandomEngine = &RandomEngineRegistry::GetInstance().Get(RandomEngineRegistry::eDetector).GetEngine();
46 
47  return eSuccess;
48  }
49 
50 
52  RdTimeJitterAdder::Run(evt::Event& event)
53  {
54  // Check if there are events at all
55  if (!event.HasREvent()) {
56  WARNING("No radio event found!");
57  return eContinueLoop;
58  }
59 
60  REvent& rEvent = event.GetREvent();
61 
62  //Loop over all stations and add time jiters
63  for (auto& station : rEvent.StationsRange()) {
64 
65  if (!station.HasRecData()) {
66  ostringstream error;
67  error << "Station " << station.GetId() << " does not have rec data.";
68  ERROR(error);
69  }
70  StationRecData& sRec = station.GetRecData();
71 
72  if (!sRec.HasParameter(eTraceStartTime)) {
73  ostringstream error;
74  error << "Station " << station.GetId() << " does not have Parameter eTraceStartTime set!";
75  ERROR(error);
76  return eFailure;
77  }
78 
79  /* For RD stations we have to use the same time jitter simulated for the
80  other SD detectors (WCD, SSD). Hence if the station id indicated that
81  it is a RD station, a corresponding SEvent station is present, and the
82  SEvent station has SimData (in which the time jitter is stored), use
83  the SEvent station time jitter. If that is not the case, draw a time
84  jitter here.
85  */
86  const int stationId = station.GetId();
87  const int rdSdStationIdLink = det::Detector::GetInstance().GetRDetector().GetRdSdStationIdLink();
88 
89  if (stationId > rdSdStationIdLink) { // is a RD station
90  if (event.HasSEvent()) {
91  sevt::SEvent& sEvent = event.GetSEvent();
92 
93  if (sEvent.HasStation(stationId - rdSdStationIdLink)) {
94  const sevt::Station& sStation = sEvent.GetStation(stationId - rdSdStationIdLink);
95 
96  if (sStation.HasSimData()) {
97  const double traceStartTime = sRec.GetParameter(eTraceStartTime);
98  const double timeJitter = sStation.GetSimData().GetAbsoluteTimeOffset();
99  const double timingUncertainty =
100  det::Detector::GetInstance().GetSDetector().GetStation(stationId - rdSdStationIdLink).GetTimingUncertainty();
101 
102  // keep parameter open, might need to be overwritten
103  sRec.SetParameter(eTraceStartTime, traceStartTime + timeJitter, false);
104  sRec.SetParameterError(eTraceStartTime, timingUncertainty, false);
105 
106  continue; // time jitter applied, continue with next station
107  // if no time jitter from SD could be applied treat RD station like an AERA station
108  }
109  }
110  }
111  }
112 
113  // in case fSigma is 0, no time jitter is drawn and only the uncertainty is set to 0.
114  if (fSigma > 0) {
115  const double mean = 0;
116  const double traceStartTime = sRec.GetParameter(eTraceStartTime);
117  const double jitter = RandGauss::shoot(fRandomEngine, mean, fSigma);
118 
119  // keep parameters open because it might be overwritten by other modules
120  sRec.SetParameter(eTraceStartTime, traceStartTime + jitter, false);
121  sRec.SetParameterError(eTraceStartTime, fSigma, false);
122  } else {
123  // keep parameter open because it might be overwritten by other modules
124  sRec.SetParameterError(eTraceStartTime, 0 * utl::ns, false);
125  }
126  }
127 
128  return eSuccess;
129  }
130 
131 
133  RdTimeJitterAdder::Finish()
134  {
135  return eSuccess;
136  }
137 
138 }
Class to access station level reconstructed data.
void SetParameterError(Parameter i, double value, bool lock=true)
bool HasStation(const int stationId) const
Check whether station exists.
Definition: SEvent.cc:81
Interface class to access to the Radio part of an event.
Definition: REvent.h:42
Interface class to access to the SD part of an event.
Definition: SEvent.h:39
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
bool HasREvent() const
Class representing a document branch.
Definition: Branch.h:107
class to hold data at Station level
bool HasSimData() const
Check whether station simulated data exists.
const double ns
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
Station & GetStation(const int stationId)
retrieve station by id throw utl::NonExistentComponentException if n.a.
Definition: SEvent.h:116
utl::TimeInterval GetAbsoluteTimeOffset() const
double GetParameter(const Parameter i) const
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
bool HasParameter(const Parameter i) const
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
void SetParameter(Parameter i, double value, bool lock=true)
sevt::StationSimData & GetSimData()
Get simulated data at station level.
constexpr double ns
Definition: AugerUnits.h:162
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
bool HasSEvent() const
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)

, generated on Tue Sep 26 2023.