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;
36 cosTh(dir.Z()), sinTh(
sqrt(1 - cosTh * cosTh)), cosFi(dir.X() / sinTh), sinFi(dir.Y() / sinTh)
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) {
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;
147 double effi = (k < backgroundPDFs.size()) ? backgroundPDFs[k].getEfficiency() : 0;
149 for (
const auto& bkg : backgroundPDFs) effiSum += bkg.getEfficiency();
150 m_bkgRate = (effiSum > effi) ? numHitsOtherSlots * effi / (effiSum - effi) / timeWindow : 0;
156 B2ERROR(
"TOPTrack: YScanner for given module not found (must be a bug!)" <<
LogVar(
"slot",
m_moduleID));
160 unsigned numCols = yScanner->getPixelPositions().getNumPixelColumns();
162 unsigned col = (hit.pixelID - 1) % numCols;
177 const auto& module = geo->getModule(
m_moduleID);
179 auto position = module.pointGlobalToNominal(
static_cast<XYZPoint
>(globalPosition));
192 std::vector<XYZPoint> points;
193 std::vector<XYZVector> normals;
194 points.push_back(transform * XYZPoint(0, -bar.
B / 2, 0));
195 normals.push_back(transform * XYZVector(0, -1, 0));
197 points.push_back(transform * XYZPoint(0, bar.
B / 2, 0));
198 normals.push_back(transform * XYZVector(0, 1, 0));
200 points.push_back(transform * XYZPoint(-bar.
A / 2, 0, 0));
201 normals.push_back(transform * XYZVector(-1, 0, 0));
203 points.push_back(transform * XYZPoint(bar.
A / 2, 0, 0));
204 normals.push_back(transform * XYZVector(1, 0, 0));
208 std::vector<double> lengths;
209 std::vector<XYZPoint> positions;
210 for (
size_t i = 0; i < 2; i++) {
212 if (isnan(t))
return false;
214 if (std::abs(r.X()) > bar.
A / 2) {
215 auto k = (r.X() > 0) ? 3 : 2;
217 if (isnan(t))
return false;
219 if (r.Z() >= bar.
zL and std::abs(r.Y()) > bar.
B / 2)
return false;
221 lengths.push_back(t);
222 positions.push_back(r);
227 if (positions[0].Z() < bar.
zL or positions[1].Z() < bar.
zL) {
229 bool ok =
xsecPrism(lengths, positions, prism, transform);
230 if (not ok)
return false;
235 std::vector<bool> outOfBar;
236 XYZPoint rc(mirror.
xc, mirror.
yc, mirror.
zc);
237 double Rsq = mirror.
R * mirror.
R;
238 for (
const auto& r : positions) {
239 outOfBar.push_back((r - rc).Mag2() > Rsq);
241 if (outOfBar[0] and outOfBar[1])
return false;
243 if (outOfBar[0] or outOfBar[1]) {
244 if (outOfBar[0]) std::reverse(lengths.begin(), lengths.end());
245 double t1 = lengths[0];
246 double t2 = lengths[1];
247 for (
int i = 0; i < 20; i++) {
248 double t = (t1 + t2) / 2;
250 if ((r - rc).Mag2() > Rsq) {
256 lengths[1] = (t1 + t2) / 2;
261 m_length = std::abs(lengths[1] - lengths[0]);
262 double length = (lengths[0] + lengths[1]) / 2;
276 std::vector<XYZPoint> points;
277 std::vector<XYZVector> normals;
279 points.push_back(transform * XYZPoint(0, prism.
yDown, 0));
280 normals.push_back(transform * XYZVector(0, -1, 0));
282 points.push_back(transform * XYZPoint(0, prism.
yUp, 0));
283 normals.push_back(transform * XYZVector(0, 1, 0));
285 points.push_back(transform * XYZPoint(-prism.
A / 2, 0, 0));
286 normals.push_back(transform * XYZVector(-1, 0, 0));
288 points.push_back(transform * XYZPoint(prism.
A / 2, 0, 0));
289 normals.push_back(transform * XYZVector(1, 0, 0));
291 for (
size_t i = 0; i < 2; i++) {
292 if (positions[i].Z() < prism.
zR) {
294 if (isnan(t))
return false;
296 if (i == 0 and r.Z() > prism.
zFlat) {
297 auto point = transform * XYZPoint(0, -prism.
B / 2, 0);
299 if (isnan(t1))
return false;
301 for (
int iter = 0; iter < 20; iter++) {
305 if (r.Y() < ySlanted) t2 = t;
310 if (std::abs(r.X()) > prism.
A / 2) {
311 auto k = (r.X() > 0) ? 3 : 2;
313 if (isnan(t))
return false;
315 if (r.Z() < prism.
zR) {
316 if (r.Y() > prism.
yUp or r.Y() < prism.
yDown)
return false;
318 if (r.Y() < ySlanted)
return false;
320 double t1 = lengths[i];
322 for (
int iter = 0; iter < 20; iter++) {
325 if (r.Z() < prism.
zR) t1 = t;
336 if (positions[0].Z() < prism.
zL and positions[1].Z() < prism.
zL)
return false;
338 if (positions[0].Z() < prism.
zL or positions[1].Z() < prism.
zL) {
339 int i0 = (positions[0].Z() < prism.
zL) ? 0 : 1;
340 double t1 = lengths[i0];
341 double t2 = lengths[(i0 + 1) % 2];
342 for (
int iter = 0; iter < 20; iter++) {
343 double t = (t1 + t2) / 2;
345 if (r.Z() < prism.
zL) t1 = t;
348 double t = (t1 + t2) / 2;
362 if (not emissionPoint.isSet) {
365 emissionPoint.isSet =
true;
367 return emissionPoint;
374 for (
auto it = range.first; it != range.second; ++it) {
375 const auto hit = it->second;
376 for (
const auto& gaus : tts.getTTS()) {
377 double sigsq = wid + pow(gaus.sigma, 2) + pow(hit->timeErr, 2);
378 double x = pow(hit->time - time - gaus.position, 2) / sigsq;
379 if (x < 10)
return true;
Provides a type-safe way to pass members of the chargedStableSet set.
const ParticleType & find(int pdg) const
Returns particle in set with given PDG code, or invalidParticle if not found.
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.
Store one Ext hit as a ROOT object.
int getPdgCode() const
Get PDG code of this extrapolation's hypothesis.
int getCopyID() const
Get detector-element ID of sensitive element within detector.
ROOT::Math::XYZVector getMomentum() const
Get momentum at this extrapolation hit.
ROOT::Math::XYZVector getPosition() const
Get position of this extrapolation hit.
double getTOF() const
Get time of flight from the point of closest approach near the origin to this hit.
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.
RelationVector< T > getRelationsWith(const std::string &name="", const std::string &namedRelation="") const
Get the relations between this object and another store array.
Accessor to arrays stored in the data store.
Class to store track parameters of incoming MC particles relation to MCParticle filled in top/simulat...
const TOPNominalTDC & getNominalTDC() const
Returns nominal time-to-digit conversion parameters.
unsigned getNumModules() const
Returns number of modules.
@ c_syncWindows
number of windows corresponding to syncTimeBase
void moveReferencePosition(double length)
Moves reference position along helix by length.
ROOT::Math::XYZPoint getPosition(double length) const
Returns particle position at given length.
double getDistanceToPlane(const ROOT::Math::XYZPoint &point, const ROOT::Math::XYZVector &normal) const
Returns the distance along helix to the nearest intersection with the plane nearly parallel to z axis...
void setTransformation(const ROOT::Math::Transform3D &transform)
Sets transformation from the frame in which helix is constructed (nominal frame) to module local fram...
ROOT::Math::XYZVector getDirection(double length) const
Returns particle direction at given length.
void set(const ROOT::Math::XYZPoint &position, const ROOT::Math::XYZVector &momentum, double charge, double Bz)
Sets the helix.
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.
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
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_momentum
track momentum magnitude at TOP
std::map< double, TOPTrack::AssumedEmission > m_emissionPoints
assumed emission points in module local frame
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
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 TOPNominalTTS & getTTS(unsigned type) const
Returns time transition spread of a given PMT type.
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.
TrackAngles()
Default constructor.