SdPMTQualityChecker.cc
Go to the documentation of this file.
1 #include "SdPMTQualityChecker.h"
2 
3 #include <fwk/CentralConfig.h>
4 #include <det/VManager.h>
5 #include <utl/Branch.h>
6 #include <evt/Event.h>
7 #include <sevt/SEvent.h>
8 #include <sevt/Station.h>
9 #include <utl/TimeStamp.h>
10 #include <sevt/PMT.h>
11 #include <sevt/PMTQuality.h>
12 #include <sdet/PMTConstants.h>
13 
14 using namespace std;
15 
16 using namespace fwk;
17 using namespace det;
18 using namespace utl;
19 using namespace evt;
20 using namespace sevt;
21 
22 
23 namespace SdPMTQualityCheckerKG {
24 
25  inline
26  bool
27  IsInRange(const double x, const pair<double, double>& r)
28  {
29  return r.first <= x && x <= r.second;
30  }
31 
32 
33  inline
34  bool
35  IsValidPositiveRange(const pair<double, double>& r)
36  {
37  return r.first >= 0 && r.second >= 0 && r.first < r.second;
38  }
39 
40 
43  {
44  const auto topB = CentralConfig::GetInstance()->GetTopBranch("SdPMTQualityChecker");
45 
46  topB.GetChild("verbose").GetData(fVerbose);
47 
48  const auto calibratorBranch = topB.GetChild("calibratorBranch").Get<string>();
49  const auto calibTopB = CentralConfig::GetInstance()->GetTopBranch(calibratorBranch);
50  calibTopB.GetChild("peakOnlineToVEMFactor").GetData(fPeakOnlineToVEMFactor);
51 
52  topB.GetChild("validGainRatioRange").GetData(fValidGainRatioRange);
53  topB.GetChild("validVEMPeakRange").GetData(fValidVEMPeakRange);
54  topB.GetChild("maxSigmaBaseline").GetData(fMaxSigmaBaseline);
55 
56  if (!IsValidPositiveRange(fValidGainRatioRange)) {
57  ERROR("error in <validGainRatioRange>");
58  return eFailure;
59  }
60 
61  if (!IsValidPositiveRange(fValidVEMPeakRange)) {
62  ERROR("error in <validVEMPeakRange>");
63  return eFailure;
64  }
65 
66  if (fMaxSigmaBaseline < 0) {
67  ERROR("error in <maxSigmaBaseline>");
68  return eFailure;
69  }
70 
71  return eSuccess;
72  }
73 
74 
76  SdPMTQualityChecker::Run(Event& event)
77  {
78  if (!event.HasSEvent())
79  return eSuccess;
80 
81  PMTChecks(event);
82 
83  return eSuccess;
84  }
85 
86 
88  SdPMTQualityChecker::PMTChecks(evt::Event& event)
89  {
90  auto& sEvent = event.GetSEvent();
91 
92  ostringstream info;
93 
94  for (auto& station : sEvent.StationsRange()) {
95 
96  /* Information related to PMTQuality and on-line values is missing
97  for upgraded (UUB) stations and for the SSD. Quality checks should
98  be implemented once this information is available. */
99  if (station.IsUUB())
100  continue;
101 
102  const unsigned int sId = station.GetId();
103  bool allbad = true;
104  int hasCalib = 0;
105 
106  for (auto& pmt : station.PMTsRange()) {
107 
108  if (!pmt.HasCalibData())
109  continue;
110  auto& pmtCalib = pmt.GetCalibData();
111 
112  ++hasCalib;
113 
114  const unsigned int pmtId = pmt.GetId();
115 
116  // transferring cuts specified in Auger event
117  if (pmt.HasQuality()) {
118  const auto& pmtQuality = pmt.GetQuality();
119  if (!pmtQuality.IsTubeOk()) {
120  pmtCalib.SetIsTubeOk(false);
121  info << "\nFlagging whole PMT " << pmtId << " of station " << sId
122  << " as bad (reason: Auger event PMT quality flag).";
123  }
124  if (!pmtQuality.HasAnode()) {
125  pmtCalib.SetIsLowGainOk(false);
126  info << "\nFlagging anode (LG) of PMT " << pmtId << " of station " << sId
127  << " as bad (reason: Auger event PMT quality flag).";
128  }
129  }
130 
131  double daRatio = 0;
132  if (pmt.HasRecData())
133  daRatio = pmt.GetRecData().GetGainRatio();
134  if (!daRatio) {
135  const int calibVersion = station.GetCalibData().GetVersion();
136  // other cuts as implemented in CDAS/Es.cc/MoreQualityCuts()
137  // this is in SdCalibrator and also in TCalibStation::Calibrate() of CDAS/EcOff.cc
138  daRatio = pmtCalib.GetGainRatio() / (calibVersion == 12 ? 1.07 : 1);
139  }
140 
141  if (!IsInRange(daRatio, fValidGainRatioRange)) {
142  info << "\nFlagging anode (LG) of PMT " << pmtId << " of station " << sId
143  << " as bad (reason: D/A out of allowed range).";
144  pmtCalib.SetIsLowGainOk(false);
145  }
146 
147  const double vemPeak = pmtCalib.GetOnlinePeak() * fPeakOnlineToVEMFactor;
148 
149  if (!IsInRange(vemPeak, fValidVEMPeakRange)) {
150  info << "\nFlagging whole PMT " << pmtId << " of station " << sId
151  << " as bad (reason: vemPeak out of allowed range).";
152  pmtCalib.SetIsTubeOk(false);
153  }
154 
155  if (pmtCalib.GetBaselineRMS() > fMaxSigmaBaseline) {
156  info << "\nFlagging whole PMT " << pmtId << " of station " << sId
157  << " as bad (reason: sigma baseline above allowed limit).";
158  pmtCalib.SetIsTubeOk(false);
159  }
160 
161  if (pmtCalib.IsTubeOk())
162  allbad = false;
163  }
164 
165  if (allbad && hasCalib > 0) {
166  info << "\nRejecting station " << sId << " because all PMTs are flagged as bad.";
167  station.SetRejected(StationConstants::eAllPMTsBad);
168  }
169 
170  }
171 
172  if (fVerbose) {
173  const string mess = info.str();
174  if (!mess.empty())
175  INFO("Applying PMT quality flags according to information in the raw event:" + mess);
176  }
177 
178  return eSuccess;
179  }
180 
181 }
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
void Init()
Initialise the registry.
bool IsValidPositiveRange(const pair< double, double > &r)
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
bool IsInRange(const double x, const vector< double > &r)
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
bool HasSEvent() const

, generated on Tue Sep 26 2023.