9#include <top/reconstruction_cpp/TOPTrack.h>
10#include <top/reconstruction_cpp/TOPRecoManager.h>
11#include <top/geometry/TOPGeometryPar.h>
12#include <framework/geometry/BFieldManager.h>
13#include <framework/logging/Logger.h>
14#include <mdst/dataobjects/Track.h>
15#include <mdst/dataobjects/TrackFitResult.h>
16#include <mdst/dataobjects/HitPatternCDC.h>
17#include <tracking/dataobjects/ExtHit.h>
18#include <top/dataobjects/TOPBarHit.h>
19#include <top/dataobjects/TOPDigit.h>
20#include <framework/datastore/StoreArray.h>
26using namespace ROOT::Math;
47 int pdgCode = std::abs(chargedStable.
getPDGCode());
51 for (
const auto& extHit : extHits) {
52 if (std::abs(extHit.getPdgCode()) != pdgCode)
continue;
53 if (extHit.getDetectorID() != myDetID)
continue;
54 if (extHit.getCopyID() < 1 or extHit.getCopyID() > numModules)
continue;
55 if (extHit.getTOF() < tmin) {
56 tmin = extHit.getTOF();
64 set(track, digitsName, chargedStable);
70 if (not extHit)
return;
75 B2ERROR(
"TOPTrack: no related Track found for valid ExtHit");
81 B2ERROR(
"TOPTrack: extrapolation hypothesis of ExtHit is not ChargedStable");
87 set(*track, digitsName, chargedStable);
95 const auto* fitResult = track.getTrackFitResultWithClosestMass(chargedStable);
97 B2ERROR(
"TOPTrack: no TrackFitResult available for PDGCode = " << chargedStable.
getPDGCode());
100 m_pT = fitResult->getTransverseMomentum();
104 if (fitResult->getHitPatternCDC().getNHits() == 0)
return;
112 for (
const auto& barHit : barHits) {
121 m_charge = fitResult->getChargeSign();
128 unsigned numHitsOtherSlots = 0;
130 for (
const auto& digit : digits) {
131 if (digit.getHitQuality() != TOPDigit::c_Good)
continue;
142 m_tts = &geo->getTTS(0);
143 const auto& tdc = geo->getNominalTDC();
148 double effi = (k < backgroundPDFs.size()) ? backgroundPDFs[k].getEfficiency() : 0;
150 for (
const auto& bkg : backgroundPDFs) effiSum += bkg.getEfficiency();
151 m_bkgRate = (effiSum > effi) ? numHitsOtherSlots * effi / (effiSum - effi) / timeWindow : 0;
157 B2ERROR(
"TOPTrack: YScanner for given module not found (must be a bug!)" <<
LogVar(
"slot",
m_moduleID));
161 unsigned numCols = yScanner->getPixelPositions().getNumPixelColumns();
163 unsigned col = (hit.pixelID - 1) % numCols;
179 const auto&
module = geo->getModule(m_moduleID);
180 auto globalPosition =
m_extHit->getPosition();
181 auto position =
module.pointGlobalToNominal(static_cast<XYZPoint>(globalPosition));
182 auto momentum =
module.momentumGlobalToNominal(m_extHit->getMomentum());
185 m_helix.setTransformation(transform);
194 std::vector<XYZPoint> points;
195 std::vector<XYZVector> normals;
196 points.push_back(transform * XYZPoint(0, -bar.
B / 2, 0));
197 normals.push_back(transform * XYZVector(0, -1, 0));
199 points.push_back(transform * XYZPoint(0, bar.
B / 2, 0));
200 normals.push_back(transform * XYZVector(0, 1, 0));
202 points.push_back(transform * XYZPoint(-bar.
A / 2, 0, 0));
203 normals.push_back(transform * XYZVector(-1, 0, 0));
205 points.push_back(transform * XYZPoint(bar.
A / 2, 0, 0));
206 normals.push_back(transform * XYZVector(1, 0, 0));
210 std::vector<double> lengths;
211 std::vector<XYZPoint> positions;
212 for (
size_t i = 0; i < 2; i++) {
213 double t =
m_helix.getDistanceToPlane(points[i], normals[i]);
214 if (isnan(t))
return false;
215 auto r =
m_helix.getPosition(t);
216 if (std::abs(r.X()) > bar.
A / 2) {
217 auto k = (r.X() > 0) ? 3 : 2;
218 t =
m_helix.getDistanceToPlane(points[k], normals[k]);
219 if (isnan(t))
return false;
221 if (r.Z() >= bar.
zL and std::abs(r.Y()) > bar.
B / 2)
return false;
223 lengths.push_back(t);
224 positions.push_back(r);
229 if (positions[0].Z() < bar.
zL or positions[1].Z() < bar.
zL) {
231 bool ok =
xsecPrism(lengths, positions, prism, transform);
232 if (not ok)
return false;
237 std::vector<bool> outOfBar;
238 XYZPoint rc(mirror.
xc, mirror.
yc, mirror.
zc);
239 double Rsq = mirror.
R * mirror.
R;
240 for (
const auto& r : positions) {
241 outOfBar.push_back((r - rc).Mag2() > Rsq);
243 if (outOfBar[0] and outOfBar[1])
return false;
245 if (outOfBar[0] or outOfBar[1]) {
246 if (outOfBar[0]) std::reverse(lengths.begin(), lengths.end());
247 double t1 = lengths[0];
248 double t2 = lengths[1];
249 for (
int i = 0; i < 20; i++) {
250 double t = (t1 + t2) / 2;
251 auto r =
m_helix.getPosition(t);
252 if ((r - rc).Mag2() > Rsq) {
258 lengths[1] = (t1 + t2) / 2;
263 m_length = std::abs(lengths[1] - lengths[0]);
264 double length = (lengths[0] + lengths[1]) / 2;
269 m_helix.moveReferencePosition(length);
278 std::vector<XYZPoint> points;
279 std::vector<XYZVector> normals;
281 points.push_back(transform * XYZPoint(0, prism.
yDown, 0));
282 normals.push_back(transform * XYZVector(0, -1, 0));
284 points.push_back(transform * XYZPoint(0, prism.
yUp, 0));
285 normals.push_back(transform * XYZVector(0, 1, 0));
287 points.push_back(transform * XYZPoint(-prism.
A / 2, 0, 0));
288 normals.push_back(transform * XYZVector(-1, 0, 0));
290 points.push_back(transform * XYZPoint(prism.
A / 2, 0, 0));
291 normals.push_back(transform * XYZVector(1, 0, 0));
293 for (
size_t i = 0; i < 2; i++) {
294 if (positions[i].Z() < prism.
zR) {
295 double t =
m_helix.getDistanceToPlane(points[i], normals[i]);
296 if (isnan(t))
return false;
297 auto r =
m_helix.getPosition(t);
298 if (i == 0 and r.Z() > prism.
zFlat) {
299 auto point = transform * XYZPoint(0, -prism.
B / 2, 0);
300 double t1 =
m_helix.getDistanceToPlane(point, normals[0]);
301 if (isnan(t1))
return false;
303 for (
int iter = 0; iter < 20; iter++) {
307 if (r.Y() < ySlanted) t2 = t;
312 if (std::abs(r.X()) > prism.
A / 2) {
313 auto k = (r.X() > 0) ? 3 : 2;
314 t =
m_helix.getDistanceToPlane(points[k], normals[k]);
315 if (isnan(t))
return false;
317 if (r.Z() < prism.
zR) {
318 if (r.Y() > prism.
yUp or r.Y() < prism.
yDown)
return false;
320 if (r.Y() < ySlanted)
return false;
322 double t1 = lengths[i];
324 for (
int iter = 0; iter < 20; iter++) {
327 if (r.Z() < prism.
zR) t1 = t;
334 positions[i] =
m_helix.getPosition(t);
338 if (positions[0].Z() < prism.
zL and positions[1].Z() < prism.
zL)
return false;
340 if (positions[0].Z() < prism.
zL or positions[1].Z() < prism.
zL) {
341 int i0 = (positions[0].Z() < prism.
zL) ? 0 : 1;
342 double t1 = lengths[i0];
343 double t2 = lengths[(i0 + 1) % 2];
344 for (
int iter = 0; iter < 20; iter++) {
345 double t = (t1 + t2) / 2;
346 auto r =
m_helix.getPosition(t);
347 if (r.Z() < prism.
zL) t1 = t;
350 double t = (t1 + t2) / 2;
352 positions[i0] =
m_helix.getPosition(t);
365 if (not emissionPoint.isSet) {
366 emissionPoint.position =
m_helix.getPosition(dL);
368 emissionPoint.isSet =
true;
370 return emissionPoint;
375 const auto& tts = *
m_tts;
377 for (
auto it = range.first; it != range.second; ++it) {
378 const auto hit = it->second;
379 for (
const auto& gaus : tts.getTTS()) {
380 double sigsq = wid + pow(gaus.sigma, 2) + pow(hit->timeErr, 2);
381 double x = pow(hit->time - time - gaus.position, 2) / sigsq;
382 if (x < 10)
return true;
392 if (not tofCorrections.
isValid())
return;
393 if (not tofCorrections->isCalibrated())
return;
397 const auto globalPosition =
m_extHit->getPosition();
398 const auto position = topModule.pointGlobalToNominal(
static_cast<XYZPoint
>(globalPosition));
Provides a type-safe way to pass members of the chargedStableSet set.
int getPDGCode() const
PDG code.
static const ParticleSet chargedStableSet
set of charged stable particles
EDetector
Enum for identifying the detector components (detector and subdetector).
static const double speedOfLight
[cm/ns]
static const ParticleType invalidParticle
Invalid particle, used internally.
bool isValid() const
Check whether a valid object was obtained from the database.
Class for accessing objects in the database.
Store one Ext hit as a ROOT object.
int getPdgCode() const
Get PDG code of this extrapolation's hypothesis.
A Class to store the Monte Carlo particle information.
Class for type safe access to objects that are referred to in relations.
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.
Accessor to arrays stored in the data store.
Class to store track parameters of incoming MC particles relation to MCParticle filled in top/simulat...
unsigned getNumModules() const
Returns number of modules.
@ c_syncWindows
number of windows corresponding to syncTimeBase
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 const std::vector< BackgroundPDF > & getBackgroundPDFs()
Returns background PDF's of all modules.
static const YScanner * getYScanner(int moduleID)
Returns y-scanner of a given module.
void setTOFCorrection(const DBObjPtr< TOPCalTOFCorrection > &tofCorrections)
Sets time-of-flight correction value.
double m_bkgRate
estimated background hit rate
DBObjPtr< TOPFrontEndSetting > m_feSetting
front-end settings
DBObjPtr< TOPCalModuleAlignment > m_alignment
module alignment constants
bool isScanRequired(unsigned col, double time, double wid) const
Checks if scan method of YScanner is needed to construct PDF for a given pixel column.
const TOPTrack::AssumedEmission & getEmissionPoint(double dL=0) const
Returns assumed photon emission position and track direction.
std::unordered_multimap< unsigned, const SelectedHit * > m_columnHits
selected hits mapped to pixel columns
const TOPNominalTTS * m_tts
PMT independent TTS, used by isScanRequired.
TOPTrack()
Default constructor.
bool xsecPrism(std::vector< double > &lengths, std::vector< ROOT::Math::XYZPoint > &positions, const RaytracerBase::Prism &prism, const ROOT::Math::Transform3D &transform)
Calculates intersection of trajectory with prism.
double m_TOFCorrection
time-of-flight correction
double m_momentum
track momentum magnitude at TOP
std::map< double, TOPTrack::AssumedEmission > m_emissionPoints
assumed emission points in module local frame, for dL != 0
bool m_valid
true for properly defined track
double m_pT
transverse momentum at POCA
bool setHelix(const ROOT::Math::Transform3D &transform)
Sets helix (helix is given in nominal frame)
double m_trackLength
trajectory length from IP to average photon emission point
double m_charge
track charge in units of elementary charge
std::vector< SelectedHit > m_selectedHits
selected photon hits from TOPDigits belonging to this slot ID
const MCParticle * m_mcParticle
MC particle.
TOP::HelixSwimmer m_helix
trajectory helix in nominal slot frame
double m_length
trajectory length within quartz
void set(const Track &track, const std::string &digitsName, const Const::ChargedStable &chargedStable)
Sets the object (called by constructors)
const ExtHit * m_extHit
extrapolated hit
TOPTrack::AssumedEmission m_emissionPoint0
assumed emission point in module local frame, at dL = 0
const Track * m_track
mdst track
double getBeta(const Const::ChargedStable &particle, double overrideMass=0) const
Returns particle beta.
double m_TOFLength
trajectory length corresponding to TOF of extrapolated hit
const TOPBarHit * m_barHit
bar hit
Class that bundles various TrackFitResults.
Class to store variables with their name which were sent to the logging service.
static void getField(const double *pos, double *field)
return the magnetic field at a given position.
double sqrt(double a)
sqrt for double
const TOPGeoModule & getModule(int moduleID) const
Returns module.
Abstract base class for different kinds of events.
bar segment data in module local frame.
double A
width (dimension in x)
double B
thickness (dimension in y)
spherical mirror data in module local frame.
double yc
center of curvature in y
double xc
center of curvature in x
double zc
center of curvature in z
prism data in module local frame.
double A
width (dimension in x)
double yDown
minimal y of exit window
double slope
slope of slanted surface (dy/dz)
double yUp
maximal y of exit window
double zFlat
z where flat continues to slanted surface
double zR
maximal z, i.e position of prism-bar joint
double B
thickness at bar (dimension in y)
assumed photon emission point in local frame
selected photon hit from TOPDigits
Sine and cosine of track polar and azimuthal angles at assumed photon emission.
double sinFi
sine of azimuthal angle
TrackAngles()
Default constructor.
double cosFi
cosine of azimuthal angle
double cosTh
cosine of polar angle
double sinTh
sine of polar angle