3 #include <fwk/CentralConfig.h>
5 #include <utl/ErrorLogger.h>
6 #include <utl/Reader.h>
7 #include <utl/config.h>
9 #include <utl/TraceAlgorithm.h>
10 #include <utl/TimeStamp.h>
11 #include <utl/TimeInterval.h>
12 #include <utl/AugerUnits.h>
13 #include <utl/AugerException.h>
16 #include <evt/Event.h>
17 #include <evt/ShowerRecData.h>
18 #include <evt/ShowerRRecData.h>
19 #include <evt/ShowerRRecDataQuantities.h>
20 #include <revt/REvent.h>
21 #include <revt/Header.h>
22 #include <revt/Station.h>
23 #include <revt/StationRecData.h>
24 #include <revt/StationRRecDataQuantities.h>
25 #include <revt/StationHeader.h>
26 #include <revt/StationTriggerData.h>
27 #include <revt/Channel.h>
28 #include <revt/ChannelRecData.h>
29 #include <revt/ChannelRRecDataQuantities.h>
31 #include <det/Detector.h>
32 #include <rdet/RDetector.h>
33 #include <rdet/Station.h>
34 #include <rdet/Channel.h>
38 #define OUT(x) if ((x) <= fInfoLevel) cerr << " "
54 fScintSignalSearchWindowStart(0),
55 fScintSignalSearchWindowStop(0),
57 fSamplesToCalculateOffset(0),
58 fMinNumberOfScintTop(0),
59 fMinNumberOfScintBottom(0),
62 fWeightedBaryValues(true),
63 fSimSingleMuonEnergyDepositTop(0),
64 fSimSingleMuonEnergyDepositTopError(0),
65 fSimSingleMuonEnergyDepositBottom(0),
66 fSimSingleMuonEnergyDepositBottomError(0),
71 RdScintSignalReconstructor::~RdScintSignalReconstructor()
78 INFO(
"RdScintSignalReconstructor::Init()");
81 Branch topBranch = CentralConfig::GetInstance()->
GetTopBranch(
"RdScintSignalReconstructor");
100 OUT(
eDebug) <<
"read in scintillator calibration top" << endl;
104 fin.open(filename.c_str(), std::ios::in);
105 fin.getline(line, 256);
107 OUT(
eDebug) <<
"loop through file... filename = " << filename << endl;
109 WARNING(
"File TOP_Mp.txt could not be opened");
113 std::vector<double> vTmp;
115 double signalMuonPeak, signalMuonPeakError;
116 fin >> stationId >> signalMuonPeak >> signalMuonPeakError;
117 fin.getline(line, 256);
123 OUT(
eDebug) << stationId <<
"\t" << signalMuonPeak <<
"\t" << signalMuonPeakError << endl;
128 OUT(
eDebug) <<
"read in scintillator calibration bottom" << endl;
130 fin.open(filename.c_str(), std::ios::in);
131 fin.getline(line, 256);
133 OUT(
eDebug) <<
"loop through file... filename = " << filename << endl;
135 WARNING(
"File BOTTOM_Mp.txt could not be opened");
139 std::vector<double> vTmp;
141 double signalMuonPeak, signalMuonPeakError;
142 fin >> stationId >> signalMuonPeak >> signalMuonPeakError;
143 fin.getline(line, 256);
149 OUT(
eDebug) << stationId <<
"\t" << signalMuonPeak <<
"\t" << signalMuonPeakError << endl;
161 INFO(
"RdScintSignalReconstructor::Run()");
166 WARNING(
"No radio event found!");
170 std::stringstream fMessage;
172 REvent& rEvent =
event.GetREvent();
175 unsigned int numberOfTopScintWithPulseFound = 0;
176 unsigned int numberOfBottomScintWithPulseFound = 0;
177 unsigned int numberOfScintStationsWithPulseFound = 0;
182 int stationId = station.
GetId();
186 WARNING(
"Station has no RecData! Please call RdEventInitializer first!");
192 double relTime = recStation.
GetParameter(eTraceStartTime);
194 std::ostringstream info;
195 info <<
"Apply pulse finder on station " << station.
GetId();
199 bool ignorestation =
false;
204 ignorestation =
true;
212 double PeakBottom = 0;
217 double PeakTopTime = 0;
218 double PeakBottomTime = 0;
223 const rdet::RDetector& rDetector = det::Detector::GetInstance().GetRDetector();
239 unsigned int sample = 0;
240 unsigned int NoiseWindowSize = 0;
242 double PeakAmplitude = 0;
243 double IntegratedSignal = 0;
244 double SignalError = 0;
246 double PeakTimeError = 0;
254 ScintSearchWindowStart = min(
max(0.0, ScintSearchWindowStart), TraceStop);
255 ScintSearchWindowStop =
max(min(ScintSearchWindowStop, TraceStop),ScintSearchWindowStart);
257 double SignalWindowStart = ScintSearchWindowStart;
258 double SignalWindowStop = ScintSearchWindowStop;
261 Pulsefinder(channeltrace, PeakAmplitude, PeakTime, PeakTimeError, SignalWindowStart, SignalWindowStop, sample, samples_offset);
264 if (PeakAmplitude <
fMinSignal || sample == 0)
268 Signalwindowfinder(channeltrace, ScintSearchWindowStart, ScintSearchWindowStop, SignalWindowStart, SignalWindowStop, sample, samples_offset);
270 double SignalIntegrationWindowSize = (SignalWindowStop - SignalWindowStart);
273 NoiseWindowStart = min(
max(0.0, NoiseWindowStart), TraceStop);
274 NoiseWindowSize = SignalIntegrationWindowSize;
277 Noisefinder(channeltrace, NoiseWindowStart, NoiseWindowSize, SignalError, samples_offset, RMSNoise);
279 PulseFixedWindowIntegrator(channeltrace, SignalIntegrationWindowSize, IntegratedSignal, SignalWindowStart, SignalWindowStop, samples_offset);
281 IntegratedSignal = IntegratedSignal * channeltrace.
GetBinning();
283 SignalError = SignalError * channeltrace.
GetBinning();
291 double integratedSignalToVEMTop = 0;
294 OUT(
eDebug) <<
"Station No. " << stationId << endl;
297 if (integratedSignalToVEMTop == 0) {
300 double integratedSignalToVEMTopError =
302 double integratedSignalToDepEnergyTop =
304 double integratedSignalToDepEnergyTopError =
306 pow(integratedSignalToVEMTopError/integratedSignalToVEMTop, 2)) *
307 integratedSignalToDepEnergyTop;
309 ++numberOfTopScintWithPulseFound;
310 PeakTop = PeakAmplitude;
312 PeakTopTime = relTime + PeakTime;
317 IntegratedSignal / integratedSignalToVEMTop);
321 sqrt(IntegratedSignal / integratedSignalToVEMTop));
322 recStation.
SetParameter(eAERAScintStationDepositedEnergy,
323 IntegratedSignal * integratedSignalToDepEnergyTop);
325 eAERAScintStationDepositedEnergy,
327 pow(SignalError / IntegratedSignal, 2) +
328 pow(integratedSignalToDepEnergyTopError / integratedSignalToDepEnergyTop, 2)) *
329 IntegratedSignal * integratedSignalToDepEnergyTop
332 recChannel.
SetParameter(eAERAScintVEM, IntegratedSignal / integratedSignalToVEMTop);
333 OUT(
eDebug) <<
"Integrated Top Signal " << IntegratedSignal <<
" Top Signal in VEM " << IntegratedSignal / integratedSignalToVEMTop <<
" Calibration " << integratedSignalToVEMTop << endl;
337 sqrt(IntegratedSignal / integratedSignalToVEMTop));
340 IntegratedSignal * integratedSignalToDepEnergyTop);
342 eAERAScintDepositedEnergy,
344 pow(SignalError / IntegratedSignal, 2) +
345 pow(integratedSignalToDepEnergyTopError / integratedSignalToDepEnergyTop, 2)) *
346 IntegratedSignal * integratedSignalToDepEnergyTop
350 double integratedSignalToVEMBottom = 0;
355 if (integratedSignalToVEMBottom == 0) {
358 double integratedSignalToVEMBottomError =
360 double integratedSignalToDepEnergyBottom =
362 double integratedSignalToDepEnergyBottomError =
365 pow(integratedSignalToVEMBottomError/integratedSignalToVEMBottom, 2)) *
366 integratedSignalToDepEnergyBottom;
367 ++numberOfBottomScintWithPulseFound;
368 PeakBottom = PeakAmplitude;
370 PeakBottomTime = relTime + PeakTime;
372 recChannel.
SetParameter(eAERAScintVEM,(IntegratedSignal/integratedSignalToVEMBottom));
373 OUT(
eDebug) <<
"Integrated Bottom Signal " << IntegratedSignal <<
" Bottom Signal in VEM " << IntegratedSignal / integratedSignalToVEMBottom << endl;
377 recChannel.
SetParameter(eAERAScintDepositedEnergy,IntegratedSignal*integratedSignalToDepEnergyBottom);
378 recChannel.
SetParameterError(eAERAScintDepositedEnergy,
sqrt(
pow(SignalError/IntegratedSignal, 2) +
pow(integratedSignalToDepEnergyBottomError/integratedSignalToDepEnergyBottom, 2))*IntegratedSignal*integratedSignalToDepEnergyBottom);
382 recChannel.
SetParameter(eAERAScintSignalTime, relTime + PeakTime);
387 recChannel.
SetParameter(eAERAScintIntergratedSignal, IntegratedSignal);
390 recChannel.
SetParameter(eAERAScintSignalHeight, PeakAmplitude);
393 recChannel.
SetParameter(eAERAScintSignalWindowStart, SignalWindowStart);
394 recChannel.
SetParameter(eAERAScintSignalWindowStop, SignalWindowStop);
400 if (PeakTop != 0 && PeakBottom != 0) {
402 if (
max(PeakTop,PeakBottom) == PeakTop) {
404 recStation.
SetParameter(eAERAScintStationSignalTime, PeakTopTime);
405 recStation.
SetParameter(eAERAScintStationSignalHeight, PeakTop);
409 recStation.
SetParameter(eAERAScintStationSignalTime, PeakBottomTime);
410 recStation.
SetParameter(eAERAScintStationSignalHeight, PeakBottom);
414 ++numberOfScintStationsWithPulseFound;
416 }
else if (PeakTop != 0) {
418 recStation.
SetParameter(eAERAScintStationSignalTime, PeakTopTime);
419 recStation.
SetParameter(eAERAScintStationSignalHeight, PeakTop);
422 ++numberOfScintStationsWithPulseFound;
424 }
else if (PeakBottom != 0) {
426 recStation.
SetParameter(eAERAScintStationSignalTime, PeakBottomTime);
427 recStation.
SetParameter(eAERAScintStationSignalHeight, PeakBottom);
430 ++numberOfScintStationsWithPulseFound;
442 rShower.
SetParameter(eNumberOfAERATopScintWithPulseFound, numberOfTopScintWithPulseFound);
443 rShower.
SetParameter(eNumberOfAERABottomScintWithPulseFound, numberOfBottomScintWithPulseFound);
444 rShower.
SetParameter(eNumberOfAERAScintStationWithPulseFound, numberOfScintStationsWithPulseFound);
467 <<
" Number of Stations with ScintSignal = " << numberOfScintStationsWithPulseFound
476 RdScintSignalReconstructor::Finish()
478 INFO(
"RdScintSignalReconstructor::Finish()");
486 double ScintSearchWindowStart,
487 double ScintSearchWindowStop,
488 double& SignalWindowStart,
489 double& SignalWindowStop,
490 unsigned int SignalTime,
491 unsigned int samples_offset)
494 unsigned int startSignalwindowfinder = ScintSearchWindowStart/ channeltrace.
GetBinning();
495 unsigned int stopSignalwindowfinder = ScintSearchWindowStop/ channeltrace.
GetBinning();
497 double offset =
TraceAlgorithm::Mean(channeltrace,startSignalwindowfinder-samples_offset, startSignalwindowfinder);
499 SignalWindowStart = SignalTime;
500 SignalWindowStop = SignalTime;
502 while (SignalWindowStart > startSignalwindowfinder) {
503 if ((channeltrace[SignalWindowStart]-offset)*(-1.) >= 0.) {
505 }
else if ((channeltrace[SignalWindowStart]-offset)*(-1.) < 0. && SignalWindowStart == SignalTime) {
513 while (SignalWindowStop <= stopSignalwindowfinder) {
514 if ((channeltrace[SignalWindowStop]-offset)*(-1.) >= 0.) {
516 }
else if ((channeltrace[SignalWindowStop]-offset)*(-1.) < 0. && SignalWindowStop == SignalTime) {
524 SignalWindowStart = SignalWindowStart*channeltrace.
GetBinning();
525 SignalWindowStop = SignalWindowStop*channeltrace.
GetBinning();
531 double NoiseWindowStart,
double NoiseWindowSize,
532 double& SignalError,
unsigned int samples_offset,
536 unsigned int start = NoiseWindowStart/channeltrace.
GetBinning();
537 unsigned int size = NoiseWindowSize/channeltrace.
GetBinning();
538 RMSNoise = TraceAlgorithm::RootMeanSquare(channeltrace, start, start+size);
542 for (
unsigned int i = start; i <= start+size; ++i) {
543 SignalError = SignalError + ((channeltrace[i]-offset)*(-1.));
550 double& PeakAmplitude,
double& PeakTime,
double& PeakTimeError,
551 double SignalWindowStart,
double SignalWindowStop,
552 unsigned int& sample,
unsigned int samples_offset)
556 unsigned int start = SignalWindowStart/channeltrace.
GetBinning();
557 unsigned int stop = SignalWindowStop/channeltrace.
GetBinning();
560 for (
unsigned int i = start; i <= stop; i++) {
561 if ((channeltrace[i]-offset)*(-1.) > PeakAmplitude) {
562 PeakAmplitude = (channeltrace[i]-offset)*(-1.);
575 double IntegrationTime,
double& IntegratedSignal,
576 double SignalWindowStart,
double SignalWindowStop,
577 unsigned int samples_offset)
580 IntegratedSignal = 0.;
582 unsigned int start = SignalWindowStart/channeltrace.
GetBinning();
583 unsigned int stop = SignalWindowStop/channeltrace.
GetBinning();
587 for (
unsigned int i = start; i <= stop; i++) {
588 IntegratedSignal += (channeltrace[i]-offset)*(-1);
591 OUT(
eObscure) <<
"RdScintSignalReconstructor::PulseFixedWindowIntegrator():" << endl;
592 OUT(
eObscure) <<
" IntegrationTime = " << IntegrationTime <<
" ns" << endl;
593 OUT(
eObscure) <<
" SignalWindowStart = " << SignalWindowStart/
ns <<
" ns" << endl;
594 OUT(
eObscure) <<
" SignalWindowStop = " << SignalWindowStop/
ns <<
" ns" << endl;
600 RdScintSignalReconstructor::ComputeBaryCenter(
const revt::REvent& rEvent,
604 const det::Detector& detector = det::Detector::GetInstance();
609 const Point siteOrigin(0, 0, 0, siteCS);
611 Vector barySum(0, 0, 0, siteCS);
613 double weightSum = 0;
614 unsigned int nstations = 0;
623 if (!sRec.
HasParameter(eAERAScintStationSignalHeight)) {
627 signal = sRec.
GetParameter(eAERAScintStationSignalHeight);
629 double weight =
sqrt(signal);
632 barySum += weight * (dStation.
GetPosition() - siteOrigin);
640 barySum /= weightSum;
642 barySum /= nstations;
643 BaryCenter = barySum + siteOrigin;
648 RdScintSignalReconstructor::ComputeBaryTime(
const revt::REvent& rEvent,
double& BaryTime)
651 double weightSum = 0;
654 unsigned int nstations = 0;
661 if (!sRec.
HasParameter(eAERAScintStationSignalHeight)) {
665 signal = sRec.
GetParameter(eAERAScintStationSignalHeight);
669 double weight =
sqrt(signal);
672 TimeSum += weight * time;
680 TimeSum /= weightSum;
682 TimeSum /= nstations;
Class to access channel level reconstructed data.
Branch GetTopBranch() const
void MakeRecData()
Make channel reconstructed data object.
std::vector< std::string > fExcludedStationsName
Class to access station level reconstructed data.
void SetParameter(Parameter i, double value, bool lock=true)
void SetParameterError(Parameter i, double value, bool lock=true)
double fSimSingleMuonEnergyDepositTop
int GetId() const
Return Id of the Channel.
Report success to RunController.
Detector description interface for Station-related data.
void Noisefinder(const revt::ChannelTimeSeries &channeltrace, double NoiseWindowStart, double NoiseWindowSize, double &SignalError, unsigned int samples_offset, double &RMSNoise) const
unsigned int fMinNumberOfScint
StationRecData & GetRecData()
Get station level reconstructed data.
Interface class to access Shower Reconstructed parameters.
Station & GetStationByName(const std::string &name)
retrieve station by name, throw utl::NonExistentComponentException if n.a.
bool HasRecShower() const
Interface class to access to the Radio part of an event.
Skip remaining modules in the current loop and continue with next iteration of the loop...
Interface class to access to the RD Reconstruction of a Shower.
double fScintSignalSearchWindowStop
void SetParameter(Parameter i, double value, bool lock=true)
double GetBinning() const
size of one slot
std::string fFilenameMuonCalibrationTop
ChannelRecData & GetRecData()
Get channel level reconstructed data.
#define INFO(message)
Macro for logging informational messages.
void Signalwindowfinder(const revt::ChannelTimeSeries channeltrace, double ScintSearchWindowStart, double ScintSearchWindowStop, double &SignalWindowStart, double &SignalWindowStop, unsigned int sample, unsigned int samples_offset) const
StationIterator StationsEnd()
StationIterator StationsBegin()
void Init()
Initialise the registry.
Detector description interface for Channel-related data.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
utl::CoordinateSystemPtr GetSiteCoordinateSystem() const
Get the coordinate system for the site.
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.
bool HasRecData() const
Check whether channel reconstructed data exists.
ShowerRRecData & GetRRecShower()
std::string fFilenameMuonCalibrationBottom
double fSimSingleMuonEnergyDepositBottomError
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
double fSimSingleMuonEnergyDepositBottom
Detector description interface for RDetector-related data.
bool HasChannel(const int pmtId) const
Check if a particular Channel object exists.
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
const std::string & GetChannelType() const
Get description of Channel Type.
Class representing a document branch.
class to hold data at the radio Station level.
double GetX(const CoordinateSystemPtr &coordinateSystem) const
std::map< int, CalibrationData > fCalibrationDataTop
void SetParameterError(Parameter i, double value, bool lock=true)
bool HasRRecShower() const
Top of the hierarchy of the detector description interface.
std::map< int, CalibrationData > fCalibrationDataBottom
#define WARNING(message)
Macro for logging warning messages.
void GetData(bool &b) const
Overloads of the GetData member template function.
double fSimSingleMuonEnergyDepositTopError
int GetId() const
Get the station Id.
double fScintSignalSearchWindowStart
boost::filter_iterator< StationFilter, ConstAllStationIterator > ConstStationIterator
double GetParameter(const Parameter i) const
double GetY(const CoordinateSystemPtr &coordinateSystem) const
void Pulsefinder(const revt::ChannelTimeSeries &channeltrace, double &PeakAmplitude, double &PeakTime, double &PeakTimeError, double SignalWindowStart, double SignalWindowStop, unsigned int &sample, unsigned int samples_offset) const
ResultFlag
Flag returned by module methods to the RunController.
bool HasParameter(const Parameter i) const
void SetParameter(Parameter i, double value, bool lock=true)
Class that holds the data associated to an individual radio channel.
Report failure to RunController, causing RunController to terminate execution.
const rdet::RDetector & GetRDetector() const
void PulseFixedWindowIntegrator(const revt::ChannelTimeSeries &channeltrace, double IntegrationTime, double &IntegratedSignal, double SignalWindowStart, double SignalWindowStop, unsigned int samples_offset) const
bool HasStation(const int stationId) const
Check whether station exists.
double Mean(const std::vector< double > &v)
bool HasRecData() const
Check whether station reconstructed data exists.
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
utl::Point GetPosition() const
Tank position in Site Cartesian Coordinates.
const Station & GetStation(const int stationId) const
Get station by Station Id.
unsigned int fSamplesToCalculateOffset
void ComputeBaryTime(const revt::REvent &rEvent, double &BaryTime) const
void ComputeBaryCenter(const revt::REvent &rEvent, utl::Point &BaryCenter) const
double signalMuonPeakError