10#include <top/modules/TOPCosmicT0Finder/TOPCosmicT0FinderModule.h>
13#include <top/geometry/TOPGeometryPar.h>
14#include <top/reconstruction_cpp/TOPTrack.h>
15#include <top/reconstruction_cpp/PDFConstructor.h>
16#include <top/reconstruction_cpp/TOPRecoManager.h>
17#include <top/reconstruction_cpp/PDF1Dim.h>
18#include <top/utilities/Chi2MinimumFinder1D.h>
21#include <framework/datastore/StoreArray.h>
24#include <framework/gearbox/Const.h>
25#include <framework/logging/Logger.h>
28#include <mdst/dataobjects/Track.h>
29#include <tracking/dataobjects/ExtHit.h>
30#include <top/dataobjects/TOPBarHit.h>
31#include <top/dataobjects/TOPDigit.h>
32#include <top/dataobjects/TOPTimeZero.h>
65 "if true, use incoming track, otherwise use outcoming track",
true);
67 "minimal number of detected photons in a module", (
unsigned) 10);
69 "minimal number of expected signal photons", 5.0);
73 addParam(
"sigma",
m_sigma,
"additional time spread added to PDF [ns]", 0.0);
75 "save histograms to TOPTimeZero",
false);
110 const ExtHit* selectedExtHit = 0;
112 for (
const auto& track : tracks) {
113 const auto extHits = track.getRelationsWith<
ExtHit>();
114 const ExtHit* extHit0 = 0;
115 for (
const auto& extHit : extHits) {
117 if (extHit.getDetectorID() != Const::EDetector::TOP)
continue;
118 if (extHit.getCopyID() <= 0)
continue;
119 double dot = extHit.getPosition().Dot(extHit.getMomentum());
121 if (
dot > 0)
continue;
122 if (not extHit0) extHit0 = &extHit;
123 if (extHit.getTOF() < extHit0->getTOF()) extHit0 = &extHit;
125 if (
dot < 0)
continue;
126 if (not extHit0) extHit0 = &extHit;
127 if (extHit.getTOF() > extHit0->getTOF()) extHit0 = &extHit;
130 if (not extHit0)
continue;
131 double p = extHit0->getMomentum().R();
134 selectedExtHit = extHit0;
137 if (not selectedExtHit)
return;
140 if (not topTrack.
isValid())
return;
149 if (not pdfConstructor.
isValid())
return;
166 PDF1Dim pdf1d(pdfConstructor, 1.0, timeWindow);
171 for (
unsigned i = 0; i < bins.size(); i++) {
175 const auto& t0Rough = roughFinder.
getMinimum();
184 const auto& binCenters = finder.getBinCenters();
186 for (
unsigned i = 0; i < binCenters.size(); i++) {
187 double t0 = binCenters[i];
189 finder.add(i, -2 * LL.logL);
190 if (i == 0) numPhotons = LL.numPhotons;
192 const auto& t0 = finder.getMinimum();
193 if (t0.position < t0min or t0.position > t0max or not t0.valid)
return;
202 auto* timeZero = timeZeros.
appendNew(topTrack.
getModuleID(), t0.position, t0.error, numPhotons);
203 timeZero->addRelationTo(topTrack.
getTrack());
204 timeZero->addRelationTo(topTrack.
getExtHit());
212 name =
"chi2_" + to_string(
m_num);
213 std::string title =
"muon -2 logL vs. t0; t_{0} [ns]; -2 log L_{#mu}";
214 auto chi2 = finder.getHistogram(name, title);
216 name =
"pdf_" + to_string(
m_num);
217 auto pdf = pdf1d.
getHistogram(name,
"PDF projected to time axis");
218 pdf.SetName(name.c_str());
219 pdf.SetXTitle(
"time [ns]");
221 pdf.SetOption(
"hist");
223 name =
"hits_" + to_string(
m_num);
224 TH1F hits(name.c_str(),
"time distribution of photons (t0-subtracted)",
225 pdf.GetNbinsX(), pdf.GetXaxis()->GetXmin(), pdf.GetXaxis()->GetXmax());
226 hits.SetXTitle(
"time [ns]");
228 hits.Fill(hit.time - t0.position);
230 timeZero->setHistograms(chi2, pdf, hits);
238 for (
auto& digit : topDigits) {
239 digit.subtractT0(t0.position);
240 double err = digit.getTimeError();
241 digit.setTimeError(
sqrt(err * err + t0.error * t0.error));
242 digit.addStatus(TOPDigit::c_EventT0Subtracted);
int getPDGCode() const
PDG code.
static const ChargedStable muon
muon particle
Store one Ext hit as a ROOT object.
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...
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
bool isOptional(const std::string &name="")
Tell the DataStore about an optional input.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Accessor to arrays stored in the data store.
T * appendNew()
Construct a new T object at the end of the array.
bool registerRelationTo(const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut, const std::string &namedRelation="") const
Register a relation to the given StoreArray.
bool m_applyT0
if true, subtract T0 in TOPDigits
DBObjPtr< TOPFrontEndSetting > m_feSetting
front-end settings
bool m_saveHistograms
flag to save histograms
double m_minSignal
minimal number of expected signal photons
int m_numBins
number of bins to which time range is divided
bool m_useIncomingTrack
if true use incoming track, otherwise use outcoming
int m_successCount
counter for successfully determined T0
int m_acceptedCount
counter for accepted events
int m_num
histogram number
unsigned m_minHits
minimal number of hits on TOP module
double m_timeRange
time range in which to search [ns]
double m_sigma
additional time spread added to PDF [ns]
const TOPNominalTDC & getNominalTDC() const
Returns nominal time-to-digit conversion parameters.
@ c_syncWindows
number of windows corresponding to syncTimeBase
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.
Binned one dimensional PDF (a projection of PDF to time axis)
double getLogL(double timeShift) const
Returns log likelihood.
TH1F getHistogram(std::string name, std::string title) const
Returns binned one dimensional PDF (projection to time axis)
double getMaxT0() const
Returns upper edge of the T0 search region.
double getMinT0() const
Returns lower edge of the T0 search region.
int getNumBinsT0() const
Returns number of bins the T0 search region.
PDF construction and log likelihood determination for a given track and particle hypothesis.
void switchOffDeltaRayPDF() const
Exclude delta-ray PDF in log likelihood calculation.
LogL getLogL() const
Returns extended log likelihood (using the default time window)
bool isValid() const
Checks the object status.
double getExpectedSignalPhotons() const
Returns the expected number of signal photons within the default time window.
@ 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.
const Track * getTrack() const
Returns mdst track.
bool isValid() const
Checks if track is successfully constructed.
const ExtHit * getExtHit() const
Returns extrapolated hit (track entrance to the bar)
int getModuleID() const
Returns slot ID.
const std::vector< SelectedHit > & getSelectedHits() const
Returns selected photon hits from TOPDigits belonging to the slot ID.
const TOPBarHit * getBarHit() const
Returns bar hit of MC particle assigned to this track (if any)
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
T dot(GeneralVector< T > a, GeneralVector< T > b)
dot product of two general vectors
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
TOPCosmicT0FinderModule()
Constructor.
virtual void terminate() override
Termination action.
Abstract base class for different kinds of events.