8#include <tracking/modules/reattachCDCWireHitsToRecoTracks/ReattachCDCWireHitsToRecoTracksModule.h>
10#include <cdc/topology/CDCWire.h>
11#include <tracking/trackingUtilities/geometry/Vector3D.h>
12#include <tracking/trackingUtilities/geometry/Vector2D.h>
13#include <tracking/trackingUtilities/eventdata/trajectories/CDCTrajectory3D.h>
14#include <tracking/trackingUtilities/eventdata/trajectories/CDCTrajectory2D.h>
15#include <tracking/trackingUtilities/eventdata/trajectories/CDCTrajectorySZ.h>
16#include <tracking/trackFitting/fitter/base/TrackFitter.h>
17#include <tracking/dataobjects/RecoHitInformation.h>
18#include <tracking/dbobjects/DAFConfiguration.h>
22using namespace TrackingUtilities;
30Module to loop over low-ADC/TOT CDCWireHits and RecoTracks
31and reattach the hits to the tracks if they are closer
32than a given distance.)DOC");
42 "Distance (cm) below which (exclusive) a CDC hit can be reattached to a track",
m_maximumDistance);
44 "ADC above which (inclusive) a CDC hit can be reattached to a track",
m_minimumADC);
46 "TOT above which (inclusive) a CDC hit can be reattached to a track",
m_minimumTOT);
48 "Only tracks with an absolute value of d0 below (exclusive) this parameter (cm) are considered",
m_maximumAbsD0);
50 "Only tracks with an absolute value of z0 below (exclusive) this parameter (cm) are considered",
m_maximumAbsZ0);
52 "Type of track fit algorithm to use the corresponding DAFParameter, the list is defined in DAFConfiguration class.",
82 const Vector3D trackPosition(recoTrack.getPositionSeed());
83 const Vector3D trackMomentum(recoTrack.getMomentumSeed());
84 const CDCTrajectory3D trajectory(trackPosition, recoTrack.getTimeSeed(), trackMomentum, recoTrack.getChargeSeed());
88 const double z0Estimate(trajectorySZ.
getZ0());
90 if (trackFitter.
fit(recoTrack)) {
99 if ((wireHit.getAutomatonCell().hasBadADCOrTOTFlag()) and
105 ERightLeft currentRlInfo(ERightLeft::c_Unknown);
112 bool neighborFound(
false);
120 neighborFound =
true;
127 recoTrack.getRecoHitInformation(hitOnTrack)));
129 if (not results.isValid) {
133 if (std::abs(results.distanceToTrack) < currentMinimalDistance) {
135 currentMinimalDistance = std::abs(results.distanceToTrack);
136 currentClosestTrack = &recoTrack;
137 currentRlInfo = results.rlInfo;
139 B2DEBUG(29,
"Background hit close to the track found..." << std::endl
140 <<
"Layer of the hit on track: " << hitOnTrack->getICLayer() << std::endl
141 <<
"Layer of the background hit: " << wireHit.getHit()->getICLayer() << std::endl
142 <<
"ID of the background hit: " << wireHit.getHit()->getID() << std::endl
143 <<
"ADC of the background hit: " << wireHit.getHit()->getADCCount() << std::endl
144 <<
"TOT of the background hit: " << wireHit.getHit()->getTOT() << std::endl
145 <<
"Distance from track to hit: " << results.distanceToTrack << std::endl);
152 hitToAddInfo.
hit = &wireHit;
153 hitToAddInfo.
rlInfo = currentRlInfo;
174 std::unordered_map<CDCWireHit*, double> previousArcLength;
175 std::unordered_map<CDCWireHit*, double> currentArcLength;
178 previousArcLength[hitToAddInfo.hit] = 0.0;
179 currentArcLength[hitToAddInfo.hit] = 0.0;
180 (hitToAddInfo.hit)->getAutomatonCell().setTakenFlag(
false);
181 (hitToAddInfo.hit)->getAutomatonCell().setBackgroundFlag(
false);
184 unsigned int sortingParameter(0);
192 recoTrack.getRecoHitInformation(hitOnTrack)));
194 previousArcLength[&hitToAdd] = currentArcLength[&hitToAdd];
195 currentArcLength[&hitToAdd] = results.arcLength;
197 B2DEBUG(29,
"Hit to be added..." << std::endl
198 <<
"Layer of the hit on track: " << hitOnTrack->getICLayer() << std::endl
199 <<
"Layer of the background hit: " << hitToAdd.
getHit()->
getICLayer() << std::endl
200 <<
"ID of the background hit: " << hitToAdd.
getHit()->
getID() << std::endl
201 <<
"ADC of the background hit: " << hitToAdd.
getHit()->
getADCCount() << std::endl
202 <<
"TOT of the background hit: " << hitToAdd.
getHit()->
getTOT() << std::endl
203 <<
"Distance from track to hit: " << results.distanceToTrack << std::endl
204 <<
"Previous arc length of the hit: " << previousArcLength[&hitToAdd] << std::endl
205 <<
"Current arc length of the hit: " << currentArcLength[&hitToAdd] << std::endl);
207 if ((previousArcLength[&hitToAdd] > 0) and (currentArcLength[&hitToAdd] < 0)) {
210 newRecoTrack->
addCDCHit(hitToAdd.
getHit(), sortingParameter, rl, RecoHitInformation::c_ReattachCDCWireHitsToRecoTracks);
219 newRecoTrack->
addCDCHit(hitOnTrack, sortingParameter, rl, foundBy);
237 const Vector3D trackPosition(mSoP.getPos());
238 const Vector3D trackMomentum(mSoP.getMom());
239 const CDCTrajectory3D trajectory(trackPosition, mSoP.getTime(), trackMomentum, mSoP.getCharge());
252 const double z(trajectorySZ.
mapSToZ(arcLength));
258 Vector2D disp2D(recoPosOnTrajectory - wirePos2DAtZ);
260 recoPos2D = wirePos2DAtZ + disp2D;
265 results.z = trajectorySZ.
mapSToZ(results.arcLength);
266 results.distanceToTrack = trajectory2D.
getDist2D(recoPos2D);
270 Vector3D trackPosToWire{hitPosition - trackPosition};
271 results.rlInfo = trackPosToWire.xy().isRightOrLeftOf(trackMomentum.
xy());
273 results.isValid =
true;
276 B2WARNING(
"Distance measurement does not work.");
277 results.isValid =
false;
285 ERightLeft rlInfo)
const
288 if (rlInfo == ERightLeft::c_Left) {
289 return RightLeftInformation::c_left;
290 }
else if (rlInfo == ERightLeft::c_Right) {
291 return RightLeftInformation::c_right;
292 }
else if (rlInfo == ERightLeft::c_Invalid) {
293 return RightLeftInformation::c_invalidRightLeftInformation;
295 return RightLeftInformation::c_undefinedRightLeftInformation;
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
unsigned short getICLayer() const
Getter for iCLayer (0-55).
unsigned short getID() const
Getter for encoded wire number.
unsigned short getADCCount() const
Getter for integrated charge.
unsigned short getTOT() const
Getter for TOT.
Class representing a sense wire in the central drift chamber.
ROOT::Math::XYVector getWirePos2DAtZ(const double z) const
Gives the xy projected position of the wire at the given z coordinate.
ROOT::Math::XYZVector getWirePos3DAtZ(const double z) const
Gives position of the wire at the given z coordinate.
static const CDCWire * getInstance(const WireID &wireID)
Getter from the wireID convenience object. Does not construct a new object.
ETrackFitType
Enum for identifying the type of track fit algorythm ( or cosmic)
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...
std::string m_outputRecoTracksStoreArrayName
Name of the output RecoTrack StoreArray.
StoreArray< RecoTrack > m_inputRecoTracks
Input tracks.
std::string m_CDCWireHitsStoreArrayName
Name of the input CDCWireHit StoreWrappedObjPtr.
StoreArray< RecoTrack > m_outputRecoTracks
Output tracks.
ReattachCDCWireHitsToRecoTracksModule()
Constructor of the module. Setting up parameters and description.
void initialize() override
Declare required StoreArray.
ReconstructionResults reconstruct(const TrackingUtilities::CDCWireHit &wireHit, const RecoTrack &recoTrack, const RecoHitInformation *recoHitInformation) const
Compute distance from a CDCWireHit to a RecoTrack using the mSoP found with a RecoHitInformation.
TrackingUtilities::StoreWrappedObjPtr< std::vector< TrackingUtilities::CDCWireHit > > m_CDCWireHits
Input CDCWireHits.
void event() override
Event processing, combine store array.
int m_minimumADC
ADC above which (inclusive) a CDC hit can be reattached to a track.
std::string m_inputRecoTracksStoreArrayName
Name of the input RecoTrack StoreArray.
std::unordered_map< RecoTrack *, std::vector< CDCHit * > > m_mapToHitsOnTrack
Map from a RecoTrack ptr to the vector of the hits that belong to this track.
double m_maximumDistance
Distance (cm) below which (exclusive) a CDC hit can be reattached to a track.
int m_minimumTOT
TOT above which (inclusive) a CDC hit can be reattached to a track.
void addHits()
Add the selected CDC hits to the RecoTracks.
double m_maximumAbsD0
Only tracks with an absolute value of d0 below (exclusive) this parameter (cm) are considered.
void findHits()
Find the hits that can be added to the RecoTracks.
RecoHitInformation::RightLeftInformation rightLeftInformationTranslator(TrackingUtilities::ERightLeft rlInfo) const
Translate a TrackingUtilities::ERightLeft into a RecoHitInformation::RightLeftInformation.
short m_trackFitType
Track Fit type to select the proper DAFParameter from DAFConfiguration; by default c_CDConly.
std::unordered_map< RecoTrack *, std::vector< HitToAddInfo > > m_mapToHitsToAdd
Map from a RecoTrack ptr to the vector of the hits that need to be added to this track.
double m_maximumAbsZ0
Only tracks with an absolute value of z0 below (exclusive) this parameter (cm) are considered.
This is the Reconstruction Event-Data Model Track.
size_t addHitsFromRecoTrack(const RecoTrack *recoTrack, unsigned int sortingParameterOffset=0, bool reversed=false, std::optional< double > optionalMinimalWeight=std::nullopt)
Add all hits from another RecoTrack to this RecoTrack.
bool addCDCHit(const UsedCDCHit *cdcHit, const unsigned int sortingParameter, RightLeftInformation rightLeftInformation=RightLeftInformation::c_undefinedRightLeftInformation, OriginTrackFinder foundByTrackFinder=OriginTrackFinder::c_undefinedTrackFinder)
Adds a cdc hit with the given information to the reco track.
RecoTrack * copyToStoreArray(StoreArray< RecoTrack > &storeArray) const
Append a new RecoTrack to the given store array and copy its general properties, but not the hits the...
static void registerRequiredRelations(StoreArray< RecoTrack > &recoTracks, std::string const &pxdHitsStoreArrayName="", std::string const &svdHitsStoreArrayName="", std::string const &cdcHitsStoreArrayName="", std::string const &bklmHitsStoreArrayName="", std::string const &eklmHitsStoreArrayName="", std::string const &recoHitInformationStoreArrayName="")
Convenience method which registers all relations required to fully use a RecoTrack.
const genfit::MeasuredStateOnPlane & getMeasuredStateOnPlaneFromRecoHit(const RecoHitInformation *recoHitInfo, const genfit::AbsTrackRep *representation=nullptr) const
Return genfit's MeasuredStateOnPlane on plane for associated with one RecoHitInformation.
Algorithm class to handle the fitting of RecoTrack objects.
bool fit(RecoTrack &recoTrack, genfit::AbsTrackRep *trackRepresentation, bool resortHits=false) const
Fit a reco track with a given non-default track representation.
void setTakenFlag(bool setTo=true)
Sets the taken flag to the given value. Default value true.
bool hasTakenFlag() const
Gets the current state of the taken marker flag.
Particle trajectory as it is seen in xy projection represented as a circle.
double calcArcLength2D(const Vector2D &point) const
Calculate the travel distance from the start position of the trajectory.
Vector2D getClosest(const Vector2D &point) const
Calculates the closest approach on the trajectory to the given point.
double getDist2D(const Vector2D &point) const
Calculates the distance from the point to the trajectory as seen from the xy projection.
Particle full three dimensional trajectory.
CDCTrajectory2D getTrajectory2D() const
Getter for the two dimensional trajectory.
CDCTrajectorySZ getTrajectorySZ() const
Getter for the sz trajectory.
Linear trajectory in sz space.
double mapSToZ(const double s=0) const
Translates the travel distance to the z coordinate.
double getZ0() const
Getter for the z coordinate at zero travel distance.
Class representing a hit wire in the central drift chamber.
const CDCHit * getHit() const
Getter for the CDCHit pointer into the StoreArray.
double getRefDriftLength() const
Getter for the drift length at the reference position of the wire.
bool isAxial() const
Indicator if the underlying wire is axial.
const CDC::CDCWire & getWire() const
Getter for the CDCWire the hit is located on.
AutomatonCell & getAutomatonCell() const
Mutable getter for the automaton cell.
Vector2D reconstruct2D(const CDCTrajectory2D &trajectory2D) const
Reconstructs a position of primary ionisation on the drift circle.
A two dimensional vector which is equipped with functions for correct handling of orientation relate...
double normalizeTo(const double toLength)
Normalizes the vector to the given length.
const Vector2D & xy() const
Getter for the xy projected vector ( reference ! )
double z() const
Getter for the z coordinate.
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.
HepGeom::Vector3D< double > Vector3D
3D Vector
Abstract base class for different kinds of events.
Internal structure to store the information about a hit to be added.
TrackingUtilities::ERightLeft rlInfo
Right-left information of the hit.
TrackingUtilities::CDCWireHit * hit
Pointer the hit to be added.
Internal structure to store the results of the reconstruction.