SdSimulationCalibrationFillerOG/SdSimulationCalibrationFiller.cc
Go to the documentation of this file.
1 #include <det/Detector.h>
2 
3 #include <sdet/SDetector.h>
4 #include <sdet/PMTConstants.h>
5 
6 #include <evt/Event.h>
7 
8 #include <fwk/CentralConfig.h>
9 
10 #include <sevt/SEvent.h>
11 #include <sevt/Station.h>
12 #include <sevt/StationSimData.h>
13 #include <sevt/StationCalibData.h>
14 #include <sevt/PMTCalibData.h>
15 #include <sevt/PMTSimData.h>
16 #include <sevt/PMT.h>
17 
18 #include <sdet/PMT.h>
19 
20 #include <utl/Reader.h>
21 
23 
24 using namespace std;
25 using namespace sevt;
26 using namespace utl;
27 using namespace fwk;
28 using namespace evt;
29 
30 using namespace SdSimulationCalibrationFillerOG;
31 
32 
35 {
36  auto topB = CentralConfig::GetInstance()->GetTopBranch("SdSimulationCalibrationFiller");
37 
38  const auto calibratorBranch = topB.GetChild("calibratorBranch").Get<string>();
39 
40  // get these from the config xml of SdCalibrator
41  auto calibTopB = CentralConfig::GetInstance()->GetTopBranch(calibratorBranch);
42 
43  calibTopB.GetChild("peakOnlineToVEMFactor").GetData(fPeakOnlineToVEMFactor);
44  calibTopB.GetChild("chargeOnlineToVEMFactor").GetData(fChargeOnlineToVEMFactor);
45 
46  ostringstream info;
47  info << "from top branch <" << calibratorBranch << "> of the calibrator module got "
48  "the peak online-to-vem factor " << fPeakOnlineToVEMFactor << " and "
49  "the charge online-to-vem " << fChargeOnlineToVEMFactor;
50  INFO(info);
51 
52  // continue with SdSimulationCalibrationFiller xml
53  topB.GetChild("calibrationVersion").GetData(fCalibVersion);
54 
55  // SmallPMT calibration filling
56  // TODO : temporarily here, to be moved to standard
57  // XML sim. calib. consts configuration asap
58  auto spmtCalibB = topB.GetChild("SmallPMTCalibration");
59  if (spmtCalibB) {
60  spmtCalibB.GetChild("version").GetData(fSPMTVersion);
61  spmtCalibB.GetChild("beta").GetData(fBeta);
62  spmtCalibB.GetChild("betaErr").GetData(fBetaError);
63  spmtCalibB.GetChild("chi2").GetData(fChi2);
64  info.str("");
65  info << "Got calibration constants for SmallPMT -- version " << fSPMTVersion << "\n"
66  "\tbeta = " << fBeta << " +- " << fBetaError << " (chi2 = " << fChi2 << ")";
67 
68  // Values with respect to each single LPMT
69  const auto betas = spmtCalibB.GetChild("betasLPMT").Get<vector<double>>();
70  const auto betaErrs = spmtCalibB.GetChild("betaErrsLPMT").Get<vector<double>>();
71  const auto chi2s = spmtCalibB.GetChild("chi2sLPMT").Get<vector<double>>();
72 
73  // DV: these conditions should be encoded in the xsd!
74  if (betas.size() != 3 || betaErrs.size() != 3 || chi2s.size() != 3) {
75  ERROR("Wrong SmallPMT calibration values for single LPMTs");
76  return eFailure;
77  } else {
78  info << "\tsingle LPMTs betas:";
79  for (int i = 0; i < 3; ++i) {
80  fBetaLPMT[i] = betas.at(i);
81  fBetaErrorLPMT[i] = betaErrs[i];
82  fChi2LPMT[i] = chi2s[i];
83  info << "\n"
84  "\tLPMT" << i+1
85  << " beta = " << fBetaLPMT[i] << " +- " << fBetaErrorLPMT[i]
86  << " (chi2 = " << fChi2LPMT[i] << ")";
87  }
88  }
89 
90  INFO(info);
91  }
92 
93  return eSuccess;
94 }
95 
96 
98 SdSimulationCalibrationFiller::Run(Event& event)
99 {
100  if (!event.HasSEvent())
101  event.MakeSEvent();
102 
103  auto& sEvent = event.GetSEvent();
104 
105  for (auto& station : sEvent.CandidateStationsRange()) {
106 
107  const bool isUUB = station.IsUUB();
108 
109  string signature;
110  if (station.HasSimData())
111  signature = station.GetSimData().GetSimulatorSignature();
112  else
113  ERROR("No SimData found, though it should exist at this point");
114 
115  if (!station.HasCalibData())
116  station.MakeCalibData();
117 
118  auto& stationCalib = station.GetCalibData();
119 
120  stationCalib.SetVersion(fCalibVersion);
121  stationCalib.SetStartSecond(1);
122  stationCalib.SetEndSecond(3);
123  stationCalib.SetNT1(100);
124  stationCalib.SetNT2(20);
125  stationCalib.SetNTot(1);
126 
127  for (auto& pmt : station.PMTsRange(sdet::PMTConstants::eAnyType)) {
128 
129  if (!pmt.HasCalibData())
130  pmt.MakeCalibData();
131  auto& pmtCalib = pmt.GetCalibData();
132 
133  if (!pmt.HasSimData())
134  pmt.MakeSimData();
135  auto& pmtSim = pmt.GetSimData();
136 
137  const auto& dStation = det::Detector::GetInstance().GetSDetector().GetStation(station);
138  const auto pmtId = pmt.GetId();
139  const auto& dPMT = dStation.GetPMT(pmtId);
140 
141  // apply calibration magic numbers from Laura (in reverse)
142  // clarify correct numbers for the case of small PMT
143 
144  const double onlinePeak = dPMT.GetVEMPeak(signature) / fPeakOnlineToVEMFactor;
145  pmtSim.SetTriggerVEMPeak(onlinePeak); // trigger runs with biased online peak
146  if (!isUUB)
147  pmtCalib.SetOnlinePeak(onlinePeak); // used by the calibrator
148  else {
149  // DV we assume here that compatibility VEM bias in UUB is the same as VEM bias in UB
150  const double compatPeak = dPMT.GetCompatibilityVEMPeak(signature) / fPeakOnlineToVEMFactor;
151  pmtCalib.SetOnlinePeak(compatPeak); // UUB calibrator needs compat VEM
152  pmtSim.SetCompatibilityTriggerVEMPeak(compatPeak);
153  }
154  const double onlineCharge = dPMT.GetVEMCharge(signature) / fChargeOnlineToVEMFactor;
155  pmtCalib.SetOnlineCharge(onlineCharge);
156 
158  pmtCalib.SetBaseline(dPMT.GetBaseline(gain), dPMT.GetBaselineRMS(gain), gain);
159 
160  pmtCalib.SetIsTubeOk(true);
161  pmtCalib.SetIsLowGainOk(true);
162  pmtCalib.SetRate(7e3);
163  pmtCalib.SetGainRatio(dPMT.GetGainRatio(), dPMT.GetGainRatioRMS());
164 
165  pmtCalib.SetEvolution(0);
166  pmtCalib.SetNumberTDA(0);
167  pmtCalib.SetHighGainDelay(0, 0);
168  pmtCalib.SetHighGainDelayChi2(0);
169 
170  if (pmt.GetType() == sdet::PMTConstants::eWaterCherenkovSmall) {
171  auto& spmtData = station.GetSmallPMTData();
172  if (!spmtData.HasCalibData())
173  spmtData.MakeCalibData();
174  auto& spmtCalib = spmtData.GetCalibData();
175  spmtCalib.SetIsTubeOk(true);
176  spmtCalib.SetVersion(fSPMTVersion); // temporary
177  spmtCalib.SetBeta(fBeta); // temporary
178  spmtCalib.SetBetaError(fBetaError); // temporary
179  spmtCalib.SetChi2(fChi2); // temporary
180  spmtCalib.SetCorrectionFactor(1);
181  for (const auto& lpmt : station.PMTsRange(sdet::PMTConstants::eWaterCherenkovLarge)) {
182  const auto lpmtId = lpmt.GetId();
183  const auto i = lpmtId - dStation.GetFirstPMTId();
184  spmtCalib.SetBeta(fBetaLPMT[i], lpmtId); // temporary
185  spmtCalib.SetBetaError(fBetaErrorLPMT[i], lpmtId); // temporary
186  spmtCalib.SetChi2(fChi2LPMT[i], lpmtId); // temporary
187  spmtCalib.SetCorrectionFactor(1, lpmtId);
188  }
189  }
190 
191  }
192  }
193 
194  return eSuccess;
195 }
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
void Init()
Initialise the registry.
int gain
Definition: dump1090.h:241
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
bool HasSEvent() const

, generated on Tue Sep 26 2023.