RPCElectronicsSimulator.cc
Go to the documentation of this file.
2 using namespace RPCElectronicsSimulatorLX;
3 
4 #include <iostream>
5 #include <fstream>
6 #include <iterator>
7 
8 #include <det/Detector.h>
9 #include <cdet/CDetector.h>
10 #include <cdet/Station.h>
11 
12 #include <evt/Event.h>
13 #include <evt/ShowerSimData.h>
14 using namespace evt;
15 
16 #include <fwk/CentralConfig.h>
17 #include <fwk/RunController.h>
18 #include <fwk/LocalCoordinateSystem.h>
19 #include <fwk/CoordinateSystemRegistry.h>
20 #include <fwk/RandomEngineRegistry.h>
21 
22 using namespace fwk;
23 
24 #include <cevt/CEvent.h>
25 using namespace cevt;
26 
27 #include <utl/config.h>
28 #include <utl/Trace.h>
29 #include <utl/AugerUnits.h>
30 #include <utl/Math.h>
31 #include <utl/MathConstants.h>
32 #include <utl/PhysicalConstants.h>
33 #include <utl/TimeStamp.h>
34 #include <utl/TabulatedFunction.h>
35 #include <utl/TabularStream.h>
36 #include <utl/ErrorLogger.h>
37 #include <utl/Particle.h>
38 #include <utl/AugerCoordinateSystem.h>
39 #include <utl/UTMPoint.h>
40 #include <utl/MultiTimeDistribution.h>
41 #include <utl/GeometryUtilities.h>
42 #include <utl/RandomEngine.h>
43 
44 using namespace utl;
45 
46 #include <CLHEP/Random/RandGauss.h>
47 
48 #include <sstream>
49 #include <string>
50 #include <vector>
51 
52 using CLHEP::RandGauss;
53 
55  fVerbose(0),
56  fChargeThreshold(0.0),
57  // fDeadTime(0.0),
58  fTimeResolution(0.0),
59  fGPSTimeJitter(0.0),
60  fRandomEngine(0)
61 {
62 }
63 
65 {;}
66 
68 
69  std::ostringstream str;
70 
71  str << "RPCElectronicsSimulator::Init() \n";
72 
73  Branch topB =
74  CentralConfig::GetInstance()->GetTopBranch("RPCElectronicsSimulator");
75 
76  topB.GetChild("Verbosity").GetData(fVerbose);
77  topB.GetChild("ChargeThreshold").GetData(fChargeThreshold);
78  // topB.GetChild("DeadTime").GetData(fDeadTime);
79  topB.GetChild("TimeResolution").GetData(fTimeResolution);
80  topB.GetChild("GPSTimeJitter").GetData(fGPSTimeJitter);
81 
82  fRandomEngine =
83  &RandomEngineRegistry::GetInstance().Get(RandomEngineRegistry::eDetector);
84 
85  str << "ChargeThreshold = " << fChargeThreshold/(pico*coulomb) << " pC \n"
86  << "TimeResolution = " << fTimeResolution/ns << " ns \n"
87  << "GPSTimeJitter = " << fGPSTimeJitter/ns << " ns \n"
88  // << "DeadTime = " << fDeadTime/ns << " ns "
89  << "\n";
90 
91  INFO(str);
92 
93  return eSuccess;
94 }
95 
96 
98 
99  INFO("RPCElectronicsSimulator::Finish()");
100 
101  return eSuccess;
102 
103 }
104 
105 
107 
108  INFO("RPCElectronicsSimulator::Run()");
109 
110  if (!event.HasCEvent()) {
111  ERROR("RPCElectronicsSimulator::No CEvent!");
112  return eFailure;
113  }
114 
115 
116  const cdet::CDetector & detector = det::Detector::GetInstance().GetCDetector();
117 
118  CEvent &theCEvent = event.GetCEvent();
119 
120  TabularStream tab("|c|c|.|.|.|.|");
121 
122  if (fVerbose > 0) {
123  tab << HLine('=');
124  tab << "station" << endc
125  << "pad" << endc
126  << "time" << endc
127  << "charge" << endc
128  << "hits. time" << endc
129  << "time alive" << endr;
130 
131  tab << endc
132  << endc
133  << "[ns]" << endc
134  << "[pC]" << endc
135  << "[ns]" << endc
136  << "[ns]" << endr
137  << HLine('=');
138  }
139 
140  for (CEvent::StationIterator cIt = theCEvent.StationsBegin();
141  cIt != theCEvent.StationsEnd(); ++cIt) {
142 
143  Station& rpcStation = *cIt;
144 
145  if (rpcStation.GetNumberActivePads() == 0)
146  continue;
147 
148  if (fVerbose > 0) {
149  std::cout << "\n \n"
150  << "Number of muons/active pads in station "
151  << rpcStation.GetId() << " "
152  << rpcStation.GetSimData().GetNumberOfMuons() << "/"
153  << rpcStation.GetNumberActivePads()
154  << std::endl;
155  }
156 
157  const float deadTime = detector.GetStation(rpcStation).GetDeadTime();
158 
159  // Smearing in the definition of the time of the station due to the GPS resolution
160  const double timeGPS =
161  RandGauss::shoot(&fRandomEngine->GetEngine(),0.0,fGPSTimeJitter);
162 
163  // Loop over pads with signal for this station
164  for(Station::PadIterator pIt = rpcStation.PadsBegin();
165  pIt != rpcStation.PadsEnd(); ++pIt) {
166 
167  Pad& pad = *pIt;
168  PadSimData& padSimData = pad.GetSimData();
169 
170  // Loop over components of the charge time distributions
172  padSimData.ChargeTimeDistributionsBegin();
173  tIt != padSimData.ChargeTimeDistributionsEnd(); ++tIt) {
174 
175  const Station::SignalComponent component =
176  static_cast<Station::SignalComponent>(tIt->GetLabel());
177 
178  // Simulate signal digitization
179  TimeDistributionD& chargeDist = tIt->GetTimeDistribution();
181 
182  const double timeBin = chargeDist.GetBinning();
183 
184  double timeVeto = qIt->get<0>()*timeBin;
185 
186  for (; qIt != chargeDist.SparseEnd(); ++qIt) {
187 
188  const double time0 = qIt->get<0>() * timeBin;
189  const double charge = qIt->get<1>();
190 
191  if (fVerbose > 0 && component == Station::eTotal) {
192  tab << ' ' << rpcStation.GetId() << ' ' << endc
193  << ' ' << pad.GetId() << ' ' << endc
194  << time0/nanosecond << endc
195  << charge/(pico*coulomb) << ' ' << endc;
196  }
197 
198  if (charge > fChargeThreshold && time0 >= timeVeto) {
199 
200  // Smear time
201  const double time =
202  RandGauss::shoot(&fRandomEngine->GetEngine(),time0,fTimeResolution);
203  if (!padSimData.HasHitsTimeDistribution(component))
204  padSimData.MakeHitsTimeDistribution(component);
205 
206  padSimData.GetHitsTimeDistribution(component).AddTime(time+timeGPS);
207 
208  timeVeto = time + deadTime;
209 
210  if (fVerbose > 0 && component == Station::eTotal)
211  tab << (time+timeGPS)/nanosecond << endc
212  << timeVeto/nanosecond << endr;
213  }
214 
215  else {
216  // No trigger
217  if (fVerbose > 0 && component == Station::eTotal)
218  tab << " -- " << endc << timeVeto/nanosecond << endr;
219  }
220  }
221 
222  } // end loop over signal components
223  } // end loop over station pads
224 
225  if (fVerbose > 0)
226  tab << hline;
227 
228  } // end loop over stations
229 
230 
231  if (fVerbose > 0)
232  std::cout << tab << std::endl;
233 
234  return eSuccess;
235 }
236 
237 
238 
239 
240 
Branch GetTopBranch() const
Definition: Branch.cc:63
Report success to RunController.
Definition: VModule.h:62
Detector description interface for CDetector-related data.
Definition: CDetector.h:40
RandomEngineType & GetEngine()
Definition: RandomEngine.h:32
StationIterator StationsEnd()
End of all stations.
Definition: CEvent.h:67
utl::TimeDistributionI & GetHitsTimeDistribution(const StationConstants::SignalComponent source=StationConstants::eTotal)
Definition: PadSimData.h:134
Histogram class for time distributions with suppressed empty bins.
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
bool HasHitsTimeDistribution(const StationConstants::SignalComponent source=StationConstants::eTotal) const
Check if the digitized PAD signal (optionally for a given source)
Definition: PadSimData.h:146
ChargeTimeDistributionsIterator ChargeTimeDistributionsBegin()
Begin iterator over Pad base signal sources.
Definition: PadSimData.h:118
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
Class to hold simulated data at Pad level.
Definition: PadSimData.h:39
fwk::VModule::ResultFlag Finish(void)
Finish: invoked at end of the run (NOT end of the event)
class to hold data at Pad level
Definition: Pad.h:27
unsigned int GetId() const
Return Id of the Pad.
Definition: Pad.h:31
Class representing a document branch.
Definition: Branch.h:107
double GetBinning() const
Size of one slot.
unsigned int GetNumberOfMuons() const
Get the number of the different ionizing particle types that entered the station. ...
constexpr double pico
Definition: AugerUnits.h:63
const double ns
int GetId() const
Get the station Id.
constexpr double nanosecond
Definition: AugerUnits.h:143
const EndRow endr
const int tab
Definition: SdInspector.cc:35
class that triggers insertion of the line row in the TabularStream
fwk::VModule::ResultFlag Run(evt::Event &theEvent)
Run: invoked once per event.
class to format data in tabular form
void MakeHitsTimeDistribution(const StationConstants::SignalComponent source=StationConstants::eTotal)
Create a TimeDistributionI representing binary signal after digitization of PAD signal (optionally fo...
Definition: PadSimData.cc:33
double GetDeadTime() const
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
const Station & GetStation(const int stationId) const
Get station by Station Id.
Definition: CDetector.cc:192
SparseIterator SparseEnd() const
ChargeTimeDistributionsIterator ChargeTimeDistributionsEnd()
End iterator over Pad base signal sources.
Definition: PadSimData.h:124
class to hold data at Station level
PadIterator PadsEnd()
end Pad iterator for read/write
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
unsigned int GetNumberActivePads()
Get the number of pads with signal.
StationIterator StationsBegin()
Beginning of all stations.
Definition: CEvent.h:64
total (shower and background)
Report failure to RunController, causing RunController to terminate execution.
Definition: VModule.h:64
PadSimData & GetSimData()
Get object containing Pad simulated data.
Definition: Pad.h:41
bool HasCEvent() const
SparseIterator SparseBegin() const
Iterator over time slots with data in them (skips empty slots).
boost::indirect_iterator< InternalStationIterator, Station & > StationIterator
Iterator over all stations.
Definition: CEvent.h:59
PadIterator PadsBegin()
begin Pad iterator for read/write
constexpr double coulomb
Definition: AugerUnits.h:169
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
fwk::VModule::ResultFlag Init(void)
Initialize: invoked at beginning of run (NOT beginning of event)
void AddTime(const double time, const T weight=T(1))
Add an entry (optionally weighted) for the given time. Slot will be computed.
const HLine hline('-')
const EndColumn endc
boost::transform_iterator< InternalMapFunctor, InternalConstIterator, Tuple > SparseIterator
StationSimData & GetSimData()
Get simulated data at station level.
utl::MultiTimeDistributionD::Iterator ChargeTimeDistributionsIterator
Iterator over available Pad base signal sources.
Definition: PadSimData.h:112
Interface class to access to the SD part of an event.
Definition: CEvent.h:46

, generated on Tue Sep 26 2023.