9#include <top/modules/TOPModuleT0Calibrator/TOPModuleT0CalibratorModule.h>
10#include <top/reconstruction_cpp/TOPTrack.h>
11#include <top/reconstruction_cpp/PDFConstructor.h>
12#include <top/reconstruction_cpp/TOPRecoManager.h>
13#include <framework/dataobjects/EventMetaData.h>
14#include <framework/logging/Logger.h>
41 "Useful when the geometrical alignment is fine.");
47 "time range in which to search for the minimum [ns]", 10.0);
49 "sigma in [ns] for additional smearing of PDF", 0.0);
51 "sample type: one of dimuon, bhabha or cosmics", std::string(
"dimuon"));
53 "minimal track momentum if sample is cosmics", 1.0);
55 "c.m.s energy window (half size) if sample is dimuon or bhabha", 0.1);
59 "minimal local z of extrapolated hit", -130.0);
61 "maximal local z of extrapolated hit", 130.0);
63 "Root output file name containing calibration results. "
64 "File name can include *'s; "
65 "they will be replaced with a run number from the first input file",
66 std::string(
"moduleT0_r*.root"));
68 "PDF option, one of 'rough', 'fine', 'optimal'", std::string(
"rough"));
91 B2ERROR(
"TOPPDFDebuggerModule: unknown PDF option '" <<
m_pdfOption <<
"'");
104 for (
unsigned i = 0; i < 2; i++) {
112 if (pos != std::string::npos) {
114 auto run = std::to_string(evtMetaData->getRun());
115 while (run.size() < 5) run =
"0" + run;
116 while (pos != std::string::npos) {
125 B2ERROR(
"Cannot open output file '" <<
m_outFileName <<
"'");
130 m_hits1D = TH1F(
"numHits",
"Number of photons per slot",
133 m_hits1D.SetYTitle(
"hits per slot");
135 m_hits2D = TH2F(
"timeHits",
"Photon times vs. boardstacks",
141 m_tree =
new TTree(
"tree",
"Channel T0 calibration results");
164 B2WARNING(
"ModuleT0 payload has changed. Calibration results may not be correct."
165 <<
LogVar(
"run", evtMetaData->getRun()));
177 if (not
m_recBunch->isReconstructed())
return;
187 B2ERROR(
"Running offset subtracted in TOPDigits: module T0 will not be correct");
192 for (
const auto& track :
m_tracks) {
196 if (not trk.
isValid())
continue;
202 if (not pdfConstructor.
isValid())
continue;
207 int sub = gRandom->Integer(2);
209 const auto& binCenters = finder.getBinCenters();
210 for (
unsigned ibin = 0; ibin < binCenters.size(); ibin++) {
211 double t0 = binCenters[ibin];
217 for (
const auto& digit :
m_digits) {
218 if (digit.getHitQuality() != TOPDigit::c_Good)
continue;
219 if (digit.getModuleID() != trk.
getModuleID())
continue;
220 if (digit.getTime() < timeMin)
continue;
221 if (digit.getTime() > timeMax)
continue;
224 int bs = digit.getBoardstackNumber();
225 m_hits2D.Fill((digit.getModuleID() * 4 + bs - 1.5) / 4.0, digit.getTime());
230 const auto& localPosition =
m_selector.getLocalPosition();
231 m_x = localPosition.X();
232 m_y = localPosition.Y();
233 m_z = localPosition.Z();
234 const auto& localMomentum =
m_selector.getLocalMomentum();
235 m_p = localMomentum.R();
236 m_theta = localMomentum.Theta();
237 m_phi = localMomentum.Phi();
238 const auto& pocaPosition =
m_selector.getPOCAPosition();
256 TH1F h_pulls(
"pulls",
"Pulls of the two statistically independent results",
258 h_pulls.SetXTitle(
"pulls");
259 for (
unsigned module = 0;
module < c_numModules;
module++) {
260 std::vector<double> pos, err;
261 for (
int i = 0; i < 2; i++) {
262 const auto& minimum =
m_finders[i][module].getMinimum();
263 if (not minimum.valid)
continue;
264 pos.push_back(minimum.position);
265 err.push_back(minimum.error);
267 if (pos.size() < 2)
continue;
268 double pull = (pos[0] - pos[1]) /
sqrt(err[0] * err[0] + err[1] * err[1]);
272 double scaleError = h_pulls.GetRMS();
276 TH1F h_relModuleT0(
"relModuleT0",
"Module T0 relative to calibration",
277 c_numModules, 0.5,
static_cast<float>(c_numModules) + 0.5);
278 h_relModuleT0.SetXTitle(
"slot number");
279 h_relModuleT0.SetYTitle(
"module T0 residual [ns]");
281 for (
unsigned module = 0;
module < c_numModules;
module++) {
282 auto& finder = m_finders[0][module].add(m_finders[1][module]);
283 const auto& minimum = finder.getMinimum();
285 h_relModuleT0.SetBinContent(module + 1, minimum.position);
286 h_relModuleT0.SetBinError(module + 1, minimum.error * scaleError);
288 std::string slotNum = to_string(module + 1);
289 auto h = finder.getHistogram(
"chi2_slot_" + slotNum,
"slot " + slotNum);
292 h_relModuleT0.Write();
295 TH1F h_moduleT0(
"moduleT0",
"Module T0",
296 c_numModules, 0.5,
static_cast<float>(c_numModules) + 0.5);
297 h_moduleT0.SetXTitle(
"slot number");
298 h_moduleT0.SetYTitle(
"module T0 [ns]");
302 for (
int slot = 1; slot <= c_numModules; slot++) {
303 if (h_relModuleT0.GetBinError(slot) > 0) {
305 if (m_moduleT0->isCalibrated(slot)) T0 = m_moduleT0->getT0(slot);
306 average += h_relModuleT0.GetBinContent(slot) + T0;
310 if (num > 0) average /= num;
312 for (
int slot = 1; slot <= c_numModules; slot++) {
314 if (m_moduleT0->isCalibrated(slot)) T0 = m_moduleT0->getT0(slot);
315 double t0 = h_relModuleT0.GetBinContent(slot) + T0 - average;
316 double err = h_relModuleT0.GetBinError(slot);
317 h_moduleT0.SetBinContent(slot, t0);
318 h_moduleT0.SetBinError(slot, err);
329 B2RESULT(num <<
"/16 calibrated. Results available in " << m_outFileName);
335 for (
const auto& digit :
m_digits) {
336 if (digit.hasStatus(TOPDigit::c_BunchOffsetSubtracted))
return true;
void setDescription(const std::string &description)
Sets the description of the module.
Type-safe access to single objects in the data store.
StoreObjPtr< TOPRecBunch > m_recBunch
reconstructed bunch
TTree * m_tree
TTree containing selected track parameters etc.
TOP::TrackSelector m_selector
track selection utility
double m_sigmaSmear
additional smearing of PDF in [ns]
int m_PDG
track MC truth (simulated data only)
TH2F m_hits2D
hit times vs.
float m_phi
track: extrapolated hit momentum in local (module) frame
double m_minMomentum
minimal track momentum if sample is "cosmics"
double m_dz
cut on POCA in z
int m_numBins
number of bins to which search region is divided
int m_numPhotons
number of photons in this slot
double m_maxZ
maximal local z of extrapolated hit
int m_moduleID
slot to which the track is extrapolated to
TOP::PDFConstructor::EPDFOption m_PDFOption
PDF option.
double m_minZ
minimal local z of extrapolated hit
@ c_numModules
number of modules
float m_p
track: extrapolated hit momentum in local (module) frame
double m_dr
cut on POCA in r
StoreArray< Track > m_tracks
collection of tracks
TOP::Chi2MinimumFinder1D m_finders[2][c_numModules]
finders
double m_deltaEcms
c.m.s energy window if sample is "dimuon" or "bhabha"
double m_timeRange
time range in which to search for the minimum [ns]
float m_y
track: extrapolated hit coordinate in local (module) frame
StoreArray< TOPDigit > m_digits
collection of digits
StoreArray< ExtHit > m_extHits
collection of extrapolated hits
DBObjPtr< TOPCalModuleT0 > m_moduleT0
module T0 calibration constants
std::string m_outFileName
Root output file name containing results.
std::string m_pdfOption
PDF option name.
TH1F m_hits1D
number photon hits in a slot
float m_z
track: extrapolated hit coordinate in local (module) frame
float m_x
track: extrapolated hit coordinate in local (module) frame
std::string m_sample
sample type
float m_theta
track: extrapolated hit momentum in local (module) frame
Minimum finder using tabulated chi^2 values in one dimension.
PDF construction and log likelihood determination for a given track and particle hypothesis.
LogL getLogL() const
Returns extended log likelihood (using the default time window)
bool isValid() const
Checks the object status.
@ c_Optimal
y dependent only where necessary
@ c_Fine
y dependent everywhere
@ c_Rough
no dependence on y
static void setDefaultTimeWindow()
Sets default time window (functions getMinTime(), getMaxTime() will then return default values from D...
static double getMaxTime()
Returns time window upper edge.
static double getMinTime()
Returns time window lower edge.
Reconstructed track at TOP.
int getPDGCode() const
Returns PDG code of associated MCParticle (returns 0 if none)
double getCharge() const
Returns charge.
bool isValid() const
Checks if track is successfully constructed.
int getModuleID() const
Returns slot ID.
Utility for the track selection - used in various calibration modules.
Class to store variables with their name which were sent to the logging service.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
double sqrt(double a)
sqrt for double
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
virtual void terminate() override
Termination action.
bool isRunningOffsetSubtracted()
Checks if running offset is subtracted in TOPDigits.
TOPModuleT0CalibratorModule()
Constructor.
virtual void beginRun() override
Called when entering a new run.
Abstract base class for different kinds of events.
double logL
extended log likelihood