9#include <top/modules/TOPChannelT0Calibrator/TOPChannelT0CalibratorModule.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/gearbox/Const.h>
16#include <framework/logging/Logger.h>
42 setDescription(
"Alternative channel T0 calibration with dimuons or bhabhas. "
43 "This module can also be used to check the calibration "
44 "(channel, module and common T0).\n"
45 "Note: after this kind of calibration one cannot do the alignment.");
51 "time range in which to search for the minimum [ns]", 10.0);
53 "sigma in [ns] for additional smearing of PDF", 0.0);
55 "sample type: one of dimuon, bhabha or cosmics", std::string(
"dimuon"));
57 "minimal track momentum if sample is cosmics", 1.0);
59 "c.m.s energy window (half size) if sample is dimuon or bhabha", 0.1);
63 "minimal local z of extrapolated hit", -130.0);
65 "maximal local z of extrapolated hit", 130.0);
67 "Root output file name containing calibration results. "
68 "File name can include *'s; "
69 "they will be replaced with a run number from the first input file",
70 std::string(
"calibrationT0_r*.root"));
72 "PDF option, one of 'rough', 'fine', 'optimal'", std::string(
"rough"));
92 B2ERROR(
"TOPPDFDebuggerModule: unknown PDF option '" <<
m_pdfOption <<
"'");
105 for (
unsigned i = 0; i < 2; i++) {
115 if (pos != std::string::npos) {
117 auto run = std::to_string(evtMetaData->getRun());
118 while (run.size() < 5) run =
"0" + run;
119 while (pos != std::string::npos) {
128 B2ERROR(
"Cannot open output file '" <<
m_outFileName <<
"'");
133 for (
unsigned module = 0; module <
c_numModules; module++) {
134 int moduleID = module + 1;
136 std::string slotNum = std::to_string(moduleID);
137 if (moduleID < 10) slotNum =
"0" + slotNum;
139 std::string name =
"numHits_slot" + slotNum;
140 std::string title =
"Number of hits per channel for slot " + slotNum;
142 h1.SetXTitle(
"channel number");
143 h1.SetYTitle(
"hits per channel");
146 name =
"timeHits_slot" + slotNum;
147 title =
"hit time vs. channel for slot " + slotNum;
150 h2.SetXTitle(
"channel number");
151 h2.SetYTitle(
"time [ns]");
157 m_tree =
new TTree(
"tree",
"Channel T0 calibration results");
184 if (not
m_recBunch->isReconstructed())
return;
194 for (
const auto& track :
m_tracks) {
198 if (not trk.
isValid())
continue;
204 if (not pdfConstructor.
isValid())
continue;
209 int sub = gRandom->Integer(2);
212 for (
unsigned ibin = 0; ibin < binCenters.size(); ibin++) {
213 double t0 = binCenters[ibin];
215 for (
unsigned channel = 0; channel <
c_numChannels; channel++) {
216 int pix = chMapper.getPixelID(channel) - 1;
217 finders[channel].add(ibin, -2 * pixelLogLs[pix].logL);
223 for (
const auto& digit :
m_digits) {
224 if (digit.getHitQuality() != TOPDigit::c_Good)
continue;
225 if (digit.getModuleID() != trk.
getModuleID())
continue;
226 if (digit.getTime() < timeMin)
continue;
227 if (digit.getTime() > timeMax)
continue;
230 h1.Fill(digit.getChannel());
232 h2.Fill(digit.getChannel(), digit.getTime());
238 m_x = localPosition.X();
239 m_y = localPosition.Y();
240 m_z = localPosition.Z();
242 m_p = localMomentum.R();
243 m_theta = localMomentum.Theta();
244 m_phi = localMomentum.Phi();
264 TH1F h_pulls(
"pulls",
"Pulls of the two statistically independent results",
266 h_pulls.SetXTitle(
"pulls");
267 for (
unsigned module = 0; module <
c_numModules; module++) {
268 for (
unsigned channel = 0; channel <
c_numChannels; channel++) {
269 std::vector<double> pos, err;
270 for (
int i = 0; i < 2; i++) {
272 if (not minimum.valid)
continue;
273 pos.push_back(minimum.position);
274 err.push_back(minimum.error);
276 if (pos.size() < 2)
continue;
277 double pull = (pos[0] - pos[1]) /
sqrt(err[0] * err[0] + err[1] * err[1]);
282 double scaleError = h_pulls.GetRMS();
286 for (
unsigned module = 0; module <
c_numModules; module++) {
287 int moduleID = module + 1;
289 std::string slotNum = std::to_string(moduleID);
290 if (moduleID < 10) slotNum =
"0" + slotNum;
292 std::string name =
"channelT0_slot" + slotNum;
293 std::string title =
"Relative channel T0 for slot " + slotNum;
295 h_channelT0.SetXTitle(
"channel number");
296 h_channelT0.SetYTitle(
"relative channel T0 [ns]");
298 for (
unsigned channel = 0; channel <
c_numChannels; channel++) {
300 const auto& minimum = finder.getMinimum();
302 h_channelT0.SetBinContent(channel + 1, minimum.position);
303 h_channelT0.SetBinError(channel + 1, minimum.error * scaleError);
313 TH1F h_moduleT0(
"moduleT0",
"Relative module T0",
315 h_moduleT0.SetXTitle(
"slot number");
316 h_moduleT0.SetYTitle(
"relative module T0 [ns]");
318 finderCommon.
clear();
319 for (
unsigned module = 0; module <
c_numModules; module++) {
322 for (
unsigned channel = 0; channel <
c_numChannels; channel++) {
323 finder.add(
m_finders[0][module][channel]);
325 finderCommon.add(finder);
326 const auto& minimum = finder.getMinimum();
328 h_moduleT0.SetBinContent(module + 1, minimum.position);
329 h_moduleT0.SetBinError(module + 1, minimum.error * scaleError);
336 TH1F h_commonT0(
"commonT0",
"Relative common T0", 1, 0, 1);
337 h_commonT0.SetYTitle(
"relative common T0 [ns]");
338 const auto& minimum = finderCommon.getMinimum();
340 h_commonT0.SetBinContent(1, minimum.position);
341 h_commonT0.SetBinError(1, minimum.error * scaleError);
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)
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
std::vector< TH1F > m_hits1D
number photon hits in a channel
TOP::PDFConstructor::EPDFOption m_PDFOption
PDF option.
double m_minZ
minimal local z of extrapolated hit
@ c_numChannels
number of channels per module
@ 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
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.
float m_z
track: extrapolated hit coordinate in local (module) frame
float m_x
track: extrapolated hit coordinate in local (module) frame
std::vector< TH2F > m_hits2D
hit times vs.
std::string m_sample
sample type
TOP::Chi2MinimumFinder1D m_finders[2][c_numModules][c_numChannels]
finders
float m_theta
track: extrapolated hit momentum in local (module) frame
Minimum finder using tabulated chi^2 values in one dimension.
const std::vector< double > & getBinCenters() const
Returns vector of bin centers.
void add(unsigned i, double chi2)
Add chi^2 value to bin i.
const Minimum & getMinimum()
Returns parabolic minimum.
void clear()
Set chi^2 values to zero.
PDF construction and log likelihood determination for a given track and particle hypothesis.
bool isValid() const
Checks the object status.
const std::vector< LogL > & getPixelLogLs(double t0, double sigt=0) const
Returns extended log likelihoods in pixels for PDF shifted in time.
@ c_Optimal
y dependent only where necessary
@ c_Fine
y dependent everywhere
@ c_Rough
no dependence on y
const ChannelMapper & getChannelMapper() const
Returns default channel mapper (mapping of channels to pixels)
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.
TOPChannelT0CalibratorModule()
Constructor.
virtual void terminate() override
Termination action.
Abstract base class for different kinds of events.