1 #include <fwk/VModule.h>
2 #include <sdet/Station.h>
4 #include <sevt/SEvent.h>
5 #include <sevt/SortCriteria.h>
6 #include <sevt/Header.h>
7 #include <sevt/Station.h>
8 #include <sevt/StationRecData.h>
10 #include <sevt/PMTCalibData.h>
11 #include <sevt/PMTRecData.h>
12 #include <utl/ErrorLogger.h>
14 #include <utl/SVector.h>
29 template<
size_t n,
typename T>
35 for (
unsigned int i = 0; i < n; ++i)
49 : fTolerance(tolerance) { }
52 {
return abs(x - y); }
55 {
return GetDistance(x, y) <= fTolerance; }
66 : fTolerance(tolerance) { }
72 const double avg = 0.5 * (
abs(x) +
abs(y));
73 const double diff =
abs(x - y);
74 return avg ? diff/avg : diff;
78 {
return GetDistance(x, y) <= fTolerance; }
89 const TolerancePolicy<T>& tolerance = TolerancePolicy<T>(),
91 : fName(name), fType(value), fTolerance(tolerance) { }
93 operator T&() {
return fType; }
94 operator const T&()
const {
return fType; }
102 if (!fTolerance.IsCompatible((
const T&)(fType), (
const T&)(nt.
fType))) {
105 err <<
"In line " << line <<
": ";
107 << (
const T&)(fType) <<
" not compatible with " << (
const T&)(nt.
fType)
109 << fTolerance.GetDistance((
const T&)(fType), (
const T&)(nt.
fType));
127 const TolerancePolicy<T>& tolerance = TolerancePolicy<T>(),
128 const T& value = T())
129 : T(value), fName(name), fTolerance(tolerance) { }
135 if (!fTolerance.IsCompatible((
const T&)(*
this), (
const T&)(nc))) {
138 err <<
"In line " << line <<
": ";
140 << (
const T&)(*
this) <<
" not compatible with " << (
const T&)(nc)
142 << fTolerance.GetDistance((
const T&)(*
this), (
const T&)(nc));
165 fStationId(
"StationId"),
166 fHighGainSaturation(
"HighGainSaturation"),
167 fLowGainSaturation(
"LowGainSaturation"),
168 fTriggerAlgorithm(
"TriggerAlgorithm"),
180 fSignalStartSlot(
"SignalStartSlot"),
181 fSignalEndSlot(
"SignalEndSlot"),
194 return fEventId.IsCompatible(calib.
fEventId, line) &&
195 fStationId.IsCompatible(calib.
fStationId, line) &&
199 fVEMCharge.IsCompatible(calib.
fVEMCharge, line) &&
200 fVEMPeak.IsCompatible(calib.
fVEMPeak, line) &&
204 fRiseTime.IsCompatible(calib.
fRiseTime, line) &&
205 fFallTime.IsCompatible(calib.
fFallTime, line) &&
206 fT50.IsCompatible(calib.
fT50, line) &&
310 operator<<(ostream& os, const vector<T>& vec)
312 for (
const auto& v : vec)
323 istringstream lineis;
326 while (getline(is, line)) {
328 if (line.length() && line[0] !=
'#') {
333 else if (!lineis.eof()) {
335 err <<
"Read error in line " << lineNo;
349 if (x.size() != y.size()) {
350 ERROR(
"Sizes do not match!");
355 for (
typename vector<T>::const_iterator xIt = x.begin(), yIt = y.begin();
356 xIt != x.end(); ++xIt, ++yIt)
357 if (!xIt->IsCompatible(*yIt, ++line))
366 operator<<(ostream& os, const vector<int>& vec)
368 for (
const auto v : vec)
392 unsigned int fLineNo = 0;
398 static const bool fDumpHistograms =
true;
413 fReferenceValues.clear();
414 fCurrentValues.clear();
416 const string referenceFilename =
"SdCalibrationValues.ref";
417 ifstream reference(referenceFilename);
419 if (!reference || !reference.is_open()) {
420 ERROR(
"Failed to open '" + referenceFilename +
"' for reading!");
424 if (!(reference >> fReferenceValues) && reference.eof()) {
426 info <<
"Read " << fReferenceValues.size() <<
" reference items.";
429 ERROR(
"Error while reading '" + referenceFilename +
"'...");
433 if (fDumpHistograms) {
434 fMuonBaseHistoFile.open(
"MuonBaseHisto.txt");
435 fMuonChargeHistoFile.open(
"MuonChargeHisto.txt");
436 fMuonPeakHistoFile.open(
"MuonPeakHisto.txt");
437 fMuonShapeHistoFile.open(
"MuonShapeHisto.txt");
451 const auto& sEvent =
event.GetSEvent();
455 const int eventId = sEvent.GetHeader().GetId();
457 for (
const auto&
s : sEvent.StationsRange()) {
460 const int sId =
s.GetId();
464 for (
int p = 0;
p < 3; ++
p) {
465 const int pmtId =
p + firstPMT;
466 const auto& pmt =
s.GetPMT(pmtId);
467 if (!pmt.HasCalibData() && pmt.HasRecData()) {
469 err <<
"Station " << sId <<
", PMT " << pmtId <<
" "
470 "has PMTRecData but no PMTCalibData!";
474 if (fDumpHistograms && pmt.HasCalibData()) {
476 fMuonBaseHistoFile << pmt.GetCalibData().GetMuonBaseHisto() <<
"\n\n";
477 fMuonChargeHistoFile << pmt.GetCalibData().GetMuonChargeHisto() <<
"\n\n";
478 fMuonPeakHistoFile << pmt.GetCalibData().GetMuonPeakHisto() <<
"\n\n";
479 fMuonShapeHistoFile << pmt.GetCalibData().GetMuonShapeHisto() <<
"\n\n";
481 if (!pmt.HasRecData())
492 calib.
fT50[
p] = pmtRec.GetT50();
497 if (
s.HasRecData()) {
508 calib.fStationT50 = sRec.
GetT50();
512 if (fReferenceValues.size() <= fLineNo) {
513 ERROR(
"Running out of reference values!");
516 fStatus = fReferenceValues.at(fLineNo).IsCompatible(calib, fLineNo+1);
520 fCurrentValues.push_back(calib);
530 const string currentFilename =
"SdCalibrationValues.ref.new";
531 ofstream currentFile(currentFilename);
533 if (!currentFile || !currentFile.is_open()) {
534 ERROR(
"Cannot open '" + currentFilename +
"' for writing!");
538 if (!(currentFile << fCurrentValues)) {
539 ERROR(
"Cannot write current values to '" + currentFilename +
"'!");
543 if (fReferenceValues.size() != fCurrentValues.size()) {
545 err <<
"Sizes of the current (" << fCurrentValues.size() <<
") "
546 "and reference (" << fReferenceValues.size() <<
") values do not agree!";
551 if (fDumpHistograms) {
552 fMuonBaseHistoFile.close();
553 fMuonChargeHistoFile.close();
554 fMuonPeakHistoFile.close();
555 fMuonShapeHistoFile.close();
558 return fStatus ?
eSuccess : eFailure;
void operator>>(const Event &theEvent, IoSdEvent &rawSEvent)
Class to access station level reconstructed data.
double GetPeakAmplitude() const
Amplitude of signal Peak in VEM-Peak unit,averaged over pmts.
NamedType< double, RelativeDifference > fStationRiseTime
bool IsCompatible(const vector< T > &x, const vector< T > &y)
NamedClass< SVector3, RelativeDifference > fT50
NamedClass(const string &name, const TolerancePolicy< T > &tolerance=TolerancePolicy< T >(), const T &value=T())
double GetRiseTime() const
Rise time averaged over PMTs.
NamedType< double, RelativeDifference > fStationPeakAmplitude
constexpr T Sqr(const T &x)
NamedType< int > fTriggerAlgorithm
utl::SVector< 3 > SVector3
NamedClass< SVector3, RelativeDifference > fMuonChargeSlope
NamedClass< SVector3, RelativeDifference > fFallTime
RelativeDifference(const double tolerance=0)
bool is(const double a, const double b)
#define INFO(message)
Macro for logging informational messages.
NamedType< int > fSignalEndSlot
void Init()
Initialise the registry.
NamedType< double, RelativeDifference > fShapeParameter
double GetFallTime() const
Fall time averaged over PMTs.
NamedType< int > fEventId
bool IsCompatible(const T &x, const T &y) const
NamedClass< SVector3, RelativeDifference > fPeakAmplitude
NamedType< double, RelativeDifference > fTotalSignal
NamedClass< SVector3, RelativeDifference > fMuonPulseDecayTime
NamedType< double, RelativeDifference > fStationT50
class to hold reconstructed data at PMT level
utl::TimeStamp GetSignalStartTime() const
Start time of the signal.
void operator<<(Event &event, const IoSdEvent &rawEvent)
grabs the data of an IoSdEvent and stores it in evt::Event
Static (small and dense) vector class.
double abs(const SVector< n, T > &v)
double GetTotalSignal() const
Total integrated signal in VEM unit, averaged over pmts.
ofstream fMuonBaseHistoFile
NamedClass< SVector3, RelativeDifference > fRiseTime
const TolerancePolicy< T > fTolerance
unsigned int GetSignalStartSlot() const
Start time of the signal in time slots from beginning of trace.
double GetShapeParameter() const
Shape parameter averaged over PMTs.
vector< CalibrationDigest > fCurrentValues
static double GetDistance(const T &x, const T &y)
unsigned int GetSignalEndSlot() const
End time of the signal in time slots from beginning of trace.
#define REGISTER_MODULE(_moduleName_, _ModuleType_)
vector< CalibrationDigest > fReferenceValues
NamedClass< SVector3, RelativeDifference > fVEMPeak
bool IsCompatible(const T &x, const T &y) const
NamedType(const string &name, const TolerancePolicy< T > &tolerance=TolerancePolicy< T >(), const T &value=T())
ResultFlag
Flag returned by module methods to the RunController.
static unsigned int GetFirstPMTId()
Id of first pmt in station.
NamedType< int > fStationId
unsigned long GetGPSSecond() const
GPS second.
NamedClass< SVector3, RelativeDifference > fAreaOverPeak
ofstream fMuonShapeHistoFile
double GetGPSNanoSecond() const
GPS nanosecond.
NamedType< double, RelativeDifference > fStationFallTime
NamedClass< SVector< 2, int > > fSignalStartTime
NamedType< bool > fHighGainSaturation
NamedType< int > fSignalStartSlot
ofstream fMuonPeakHistoFile
T & operator=(const T &t)
#define ERROR(message)
Macro for logging error messages.
AbsoluteDifference(const double tolerance=0)
NamedClass< SVector3, RelativeDifference > fVEMCharge
static double GetDistance(const T &x, const T &y)
NamedType< bool > fLowGainSaturation
NamedClass< SVector3, RelativeDifference > fTotalCharge
ofstream fMuonChargeHistoFile
const TolerancePolicy< T > fTolerance