9#include <top/modules/collectors/TOPValidationCollectorModule.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>
16#include <framework/gearbox/Const.h>
17#include <framework/logging/Logger.h>
18#include <framework/dataobjects/EventMetaData.h>
51 setDescription(
"A collector for automatic validation of TOP calibration");
57 "time range in which to search for the minimum [ns]", 10.0);
59 "sigma in [ns] for additional smearing of PDF", 0.0);
61 "sample type: one of dimuon or bhabha", std::string(
"dimuon"));
63 "c.m.s energy window (half size) if sample is dimuon or bhabha", 0.1);
67 "minimal local z of extrapolated hit", -130.0);
69 "maximal local z of extrapolated hit", 130.0);
71 "PDF option, one of 'rough', 'fine', 'optimal'", std::string(
"rough"));
94 B2ERROR(
"Unknown PDF option '" <<
m_pdfOption <<
"'");
105 B2ERROR(
"Invalid sample type '" <<
m_sample <<
"'");
112 for (
int set = 0; set <
c_numSets; set++) {
121 string slotName = to_string(slot);
122 if (slot < 10) slotName.insert(0,
"0");
123 string name =
"chi2_slot" + slotName;
124 string title =
"Chi2 scan, slot" + slotName +
"; channel; t0 [ns]";
126 registerObject<TH2F>(name, h);
131 string slotName = to_string(slot);
132 if (slot < 10) slotName.insert(0,
"0");
133 string name =
"hits_slot" + slotName;
134 string title =
"Photon hits, slot" + slotName +
"; channel; time [ns]";
136 registerObject<TH2F>(name, h);
140 auto h =
new TH1F(
"moduleT0_pulls",
"Module T0 pulls; pulls", 200, -15.0, 15.0);
141 registerObject<TH1F>(
"moduleT0_pulls", h);
143 auto tree =
new TTree(
"tree",
"TOP calibration validation tree");
163 registerObject<TTree>(
"tree", tree);
179 for (
auto& finder : finders) finder.clear();
185 for (
unsigned module = 0; module <
c_numModules; module++) {
191 int slot = module + 1;
192 for (
unsigned channel = 0; channel <
c_numChannels; channel++) {
193 bool tbCalibrated =
false;
194 const auto* fe = fe_mapper.getMap(slot, channel / 128);
196 tbCalibrated =
m_timebase->isAvailable(fe->getScrodID(), channel);
198 B2ERROR(
"No front-end map found");
200 bool t0Calibrated =
m_channelT0->isCalibrated(slot, channel);
202 if (tbCalibrated) numTBCalibrated++;
203 if (t0Calibrated) numT0Calibrated++;
204 if (active) numActive++;
205 if (tbCalibrated and t0Calibrated and active) {
206 numActiveCalibrated++;
210 if (numActiveCalibrated > 0) thrEffi /= numActiveCalibrated;
213 for (
unsigned carrier = 0; carrier < 4; carrier++) {
214 unsigned asic = (3 * 4 + carrier) * 4;
216 std::numeric_limits<float>::quiet_NaN();
228 std::numeric_limits<float>::quiet_NaN();
238 if (not
m_recBunch->isReconstructed())
return;
245 for (
const auto& track :
m_tracks) {
249 if (not trk.
isValid())
continue;
255 if (not pdfConstructor.
isValid())
continue;
260 auto h = getObjectPtr<TH2F>(
m_namesChi[module]);
263 for (
int ibin = 0; ibin < h->GetNbinsY(); ibin++) {
264 double t0 = h->GetYaxis()->GetBinCenter(ibin + 1);
266 for (
unsigned channel = 0; channel <
c_numChannels; channel++) {
267 int pix = chMapper.getPixelID(channel) - 1;
268 double chi = h->GetBinContent(channel + 1, ibin + 1);
269 chi += -2 * pixelLogLs[pix].logL;
270 h->SetBinContent(channel + 1, ibin + 1, chi);
273 for (
auto& LL : pixelLogLs) logL += LL.logL;
274 finder.add(ibin, -2 * logL);
278 auto h1 = getObjectPtr<TH2F>(
m_namesHit[module]);
279 for (
const auto& digit :
m_digits) {
280 if (digit.getHitQuality() != TOPDigit::c_Good)
continue;
281 if (digit.getModuleID() != trk.
getModuleID())
continue;
282 h1->Fill(digit.getChannel(), digit.getTime());
294 std::vector<double> pos, err;
295 for (
int set = 0; set <
c_numSets; set++) {
296 const auto& minimum =
m_finders[set][module].getMinimum();
298 pos.push_back(minimum.position);
299 err.push_back(minimum.error);
302 auto h_pulls = getObjectPtr<TH1F>(
"moduleT0_pulls");
303 for (
unsigned i = 0; i < pos.size(); i++) {
304 for (
unsigned j = i + 1; j < pos.size(); j++) {
305 double pull = (pos[i] - pos[j]) /
sqrt(err[i] * err[i] + err[j] * err[j]);
315 for (
int set = 1; set <
c_numSets; set++) {
318 const auto& minimum = finder.getMinimum();
331 const auto& minimum = finder.getMinimum();
339 auto tree = getObjectPtr<TTree>(
"tree");
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Type-safe access to single objects in the data store.
DBObjPtr< TOPCalFillPatternOffset > m_fillPatternOffset
fill pattern offset
@ c_numChannels
number of channels per module
@ c_numSets
number of statistically independent subsamples
@ c_numModules
number of modules
DBObjPtr< TOPCalEventT0Offset > m_eventT0Offset
detector components offsets w.r.t TOP
DBObjPtr< TOPCalChannelMask > m_channelMask
list of dead/noisy channels
TOP::ValidationTreeStruct m_treeEntry
tree entry
std::vector< std::string > m_namesHit
histogram names of photon hits (time vs.
DBObjPtr< TOPCalTimebase > m_timebase
sample time calibration constants
StoreObjPtr< TOPRecBunch > m_recBunch
reconstructed bunch
DBObjPtr< TOPCalAsicShift > m_asicShift
ASIC shifts calibration constants.
TOP::TrackSelector m_selector
track selection utility
double m_sigmaSmear
additional smearing of PDF in [ns]
double m_dz
cut on POCA in z
DBObjPtr< TOPCalChannelThresholdEff > m_thresholdEff
channel threshold effi.
DBObjPtr< TOPCalChannelT0 > m_channelT0
channel T0 calibration constants
int m_numBins
number of bins to which search region is divided
double m_maxZ
maximal local z of extrapolated hit
TOP::PDFConstructor::EPDFOption m_PDFOption
PDF option.
std::vector< std::string > m_namesChi
histogram names of chi2 scans
double m_minZ
minimal local z of extrapolated hit
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]
StoreArray< TOPDigit > m_digits
collection of digits
StoreArray< ExtHit > m_extHits
collection of extrapolated hits
std::string m_pdfOption
PDF option name.
std::string m_sample
sample type
std::vector< TOP::Chi2MinimumFinder1D > m_finders[c_numSets]
minimum finders, vector index = slot - 1
Minimum finder using tabulated chi^2 values in one dimension.
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.
const FrontEndMapper & getFrontEndMapper() const
Returns front-end mapper (mapping of SCROD's to positions within TOP modules)
static void setDefaultTimeWindow()
Sets default time window (functions getMinTime(), getMaxTime() will then return default values from D...
Reconstructed track at TOP.
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.
void setDeltaEcms(double deltaEcms)
Sets cut on c.m.s.
void setCutOnPOCA(double dr, double dz)
Sets cut on point of closest approach to (0, 0, 0)
bool isSelected(const TOPTrack &track) const
Returns selection status.
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 collect() final
Replacement for event().
virtual void startRun() final
Replacement for beginRun().
TOPValidationCollectorModule()
Constructor.
virtual void closeRun() final
Replacement for endRun().
virtual void prepare() final
Replacement for initialize().
Abstract base class for different kinds of events.
int numTBCalibrated[c_numModules]
number of timebase calibrated channels, index = slot - 1
int numTracks
number of selected tracks
int numActive[c_numModules]
number of active channels, index = slot - 1
float svdOffset
SVD event T0 offset.
float svdSigma
SVD event T0 resolution.
float fillPatternFraction
fraction of reconstructed buckets matched with filled ones
float fillPatternOffset
fill pattern offset
float commonT0
common T0 residual
float commonT0Err
common T0 uncertainty (not scaled)
float thrEffi[c_numModules]
threshold efficiency: average over active calibrated channels, index = slot - 1
float moduleT0[c_numModules]
module T0 residuals, index = slot - 1
int numActiveCalibrated[c_numModules]
number of active calibrated channels, index = slot - 1
int expNo
experiment number
float cdcSigma
CDC event T0 resolution.
void clear()
Clear the structure.
float cdcOffset
CDC event T0 offset.
float moduleT0Err[c_numModules]
module T0 uncertainties (not scaled), index = slot - 1
float asicShifts[4]
carrier shifts of BS13d, index = carrier number
int numT0Calibrated[c_numModules]
number of channel T0 calibrated channels, index = slot - 1