9#include <top/modules/TOPCommonT0Calibrator/TOPCommonT0CalibratorModule.h>
10#include <top/geometry/TOPGeometryPar.h>
11#include <top/reconstruction_cpp/TOPTrack.h>
12#include <top/reconstruction_cpp/PDFConstructor.h>
13#include <top/reconstruction_cpp/TOPRecoManager.h>
14#include <framework/dataobjects/EventMetaData.h>
15#include <framework/logging/Logger.h>
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(
"commonT0_r*.root"));
68 "PDF option, one of 'rough', 'fine', 'optimal'", std::string(
"rough"));
94 B2ERROR(
"TOPPDFDebuggerModule: unknown PDF option '" <<
m_pdfOption <<
"'");
107 for (
unsigned i = 0; i <
c_numSets; i++) {
113 if (pos != std::string::npos) {
115 auto run = std::to_string(evtMetaData->getRun());
116 while (run.size() < 5) run =
"0" + run;
117 while (pos != std::string::npos) {
126 B2ERROR(
"Cannot open output file '" <<
m_outFileName <<
"'");
131 m_hits1D = TH1F(
"numHits",
"Number of photons per slot",
134 m_hits1D.SetYTitle(
"hits per slot");
136 m_hits2D = TH2F(
"timeHits",
"Photon times vs. boardstacks",
142 m_tree =
new TTree(
"tree",
"Channel T0 calibration results");
170 if (not
m_recBunch->isReconstructed())
return;
180 B2ERROR(
"Running offset subtracted in TOPDigits: common T0 will not be correct");
185 for (
const auto& track :
m_tracks) {
189 if (not trk.
isValid())
continue;
195 if (not pdfConstructor.
isValid())
continue;
200 const auto& binCenters = finder.getBinCenters();
201 for (
unsigned ibin = 0; ibin < binCenters.size(); ibin++) {
202 double t0 = binCenters[ibin];
208 for (
const auto& digit :
m_digits) {
209 if (digit.getHitQuality() != TOPDigit::c_Good)
continue;
210 if (digit.getModuleID() != trk.
getModuleID())
continue;
211 if (digit.getTime() < timeMin)
continue;
212 if (digit.getTime() > timeMax)
continue;
215 int bs = digit.getBoardstackNumber();
216 m_hits2D.Fill((digit.getModuleID() * 4 + bs - 1.5) / 4.0, digit.getTime());
222 m_x = localPosition.X();
223 m_y = localPosition.Y();
224 m_z = localPosition.Z();
226 m_p = localMomentum.R();
227 m_theta = localMomentum.Theta();
228 m_phi = localMomentum.Phi();
248 TH1F h_pulls(
"pulls",
"Pulls of statistically independent results",
250 h_pulls.SetXTitle(
"pulls");
251 std::vector<double> pos, err;
254 if (not minimum.valid)
continue;
255 pos.push_back(minimum.position);
256 err.push_back(minimum.error);
258 for (
unsigned i = 0; i < pos.size(); i++) {
259 for (
unsigned j = i + 1; j < pos.size(); j++) {
260 double pull = (pos[i] - pos[j]) /
sqrt(err[i] * err[i] + err[j] * err[j]);
265 double scaleError = 1;
266 if (h_pulls.GetEntries() > 1) scaleError = h_pulls.GetRMS();
275 TH1F h_relCommonT0(
"relCommonT0",
"relative common T0", 1, 0, 1);
276 h_relCommonT0.SetYTitle(
"common T0 residual [ns]");
277 TH1F h_commonT0(
"commonT0",
"Common T0", 1, 0, 1);
278 h_commonT0.SetYTitle(
"common T0 [ns]");
280 const auto& minimum = finder.getMinimum();
281 auto h = finder.getHistogram(
"chi2",
"chi2");
284 h_relCommonT0.SetBinContent(1, minimum.position);
285 h_relCommonT0.SetBinError(1, minimum.error * scaleError);
286 double T0 = minimum.position;
289 h_commonT0.SetBinContent(1, T0);
290 h_commonT0.SetBinError(1, minimum.error * scaleError);
292 h_relCommonT0.Write();
307 for (
const auto& digit :
m_digits) {
308 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
TOP::Chi2MinimumFinder1D m_finders[c_numSets]
finders
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)
DBObjPtr< TOPCalCommonT0 > m_commonT0
common T0 calibration constants
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
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
@ c_numSets
number of statistically independent subsamples
@ c_numModules
number of modules
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
std::string m_outFileName
Root output file name containing results.
std::string m_pdfOption
PDF option name.
double m_bunchTimeSep
time between two bunches
TH1F m_hits1D
number of 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.
const Minimum & getMinimum()
Returns parabolic minimum.
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
const TOPGeometry * getGeometry() const
Returns pointer to geometry object using basf2 units.
static TOPGeometryPar * Instance()
Static method to obtain the pointer to its instance.
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.
double getCMSEnergy() const
Returns c.m.s energy of the track in last isSelected call.
const ROOT::Math::XYZPoint & getLocalPosition() const
Returns position at TOP in local frame of the track in last isSelected call.
void setDeltaEcms(double deltaEcms)
Sets cut on c.m.s.
void setMinMomentum(double minMomentum)
Sets momentum cut (used for "cosmics" only)
void setCutOnPOCA(double dr, double dz)
Sets cut on point of closest approach to (0, 0, 0)
const ROOT::Math::XYZVector & getPOCAPosition() const
Returns position of POCA of the track in last isSelected call.
bool isSelected(const TOPTrack &track) const
Returns selection status.
const ROOT::Math::XYZVector & getLocalMomentum() const
Returns momentum at TOP in local frame of the track in last isSelected call.
void setCutOnLocalZ(double minZ, double maxZ)
Sets cut on local z coordinate (module frame) of the track extrapolated to TOP.
const Const::ChargedStable & getChargedStable() const
Returns track hypothesis.
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.
TOPCommonT0CalibratorModule()
Constructor.
Abstract base class for different kinds of events.
double logL
extended log likelihood