8#include <tracking/trackFindingCDC/mclookup/CDCSimHitLookUp.h>
10#include <tracking/trackFindingCDC/mclookup/CDCMCManager.h>
11#include <tracking/trackFindingCDC/mclookup/CDCMCMap.h>
13#include <tracking/trackFindingCDC/eventdata/hits/CDCRecoHit3D.h>
14#include <tracking/trackFindingCDC/eventdata/hits/CDCRecoHit2D.h>
15#include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
17#include <tracking/trackFindingCDC/topology/CDCWireTopology.h>
19#include <tracking/trackFindingCDC/geometry/Vector3D.h>
21#include <tracking/trackFindingCDC/utilities/VectorRange.h>
23#include <cdc/dataobjects/CDCSimHit.h>
24#include <cdc/dataobjects/CDCHit.h>
29using namespace TrackFindingCDC;
46 B2DEBUG(25,
"In CDCSimHitLookUp::fill()");
60 B2WARNING(
"CDCMCMap not set. Cannot setup primary sim hit map");
65 int nMissingPrimarySimHits = 0;
68 const CDCHit* ptrHit = std::get<const CDCHit* const>(relation);
69 const CDCSimHit* ptrSimHit = std::get<const CDCSimHit*>(relation);
72 B2ERROR(
"CDCHit has no related CDCSimHit in CDCSimHitLookUp::fill()");
78 if (not primarySimHit) {
79 ++nMissingPrimarySimHits;
84 if (nMissingPrimarySimHits != 0) {
85 B2WARNING(
"NO primary hit found for " << nMissingPrimarySimHits <<
" reassigned secondaries");
97 B2WARNING(
"CDCMCMap not set. Cannot find primary sim hit");
110 if (not ptrMCParticle) {
115 std::vector<const CDCSimHit*> primarySimHitsOnSameOrNeighborWire;
118 for (
const auto& simHitByMCParticleRelation : mcMap.
getSimHits(ptrMCParticle)) {
120 const CDCSimHit* ptrPrimarySimHit = std::get<const CDCSimHit*>(simHitByMCParticleRelation);
123 const CDCSimHit& primarySimHit = *ptrPrimarySimHit;
129 primarySimHitsOnSameOrNeighborWire.push_back(ptrPrimarySimHit);
135 auto compareDistanceBetweenSimHits =
136 [&simHit](
const CDCSimHit * primarySimHit,
137 const CDCSimHit * otherPrimarySimHit) ->
bool {
139 Vector3D otherPrimaryHitPos(otherPrimarySimHit->getPosTrack());
141 return primaryHitPos.
distance(secondaryHitPos) < otherPrimaryHitPos.
distance(secondaryHitPos);
144 auto itClosestPrimarySimHit = std::min_element(primarySimHitsOnSameOrNeighborWire.begin(),
145 primarySimHitsOnSameOrNeighborWire.end(),
146 compareDistanceBetweenSimHits);
148 if (itClosestPrimarySimHit != primarySimHitsOnSameOrNeighborWire.end()) {
150 return *itClosestPrimarySimHit;
160 B2WARNING(
"CDCMCMap not set in look up of closest primary sim hit.");
168 const CDCSimHit* simHit = itFoundPrimarySimHit->second;
169 if (simHit)
return simHit;
181 B2WARNING(
"CDCMCMap not set. Cannot find direction of flight");
189 if (not ptrSimHit)
return Vector3D();
194 if (not ptrPrimarySimHit) {
196 ptrPrimarySimHit = ptrSimHit;
201 const CDCSimHit& primarySimHit = *ptrPrimarySimHit;
205 return directionOfFlight;
212 B2WARNING(
"CDCMCMap not set. Cannot setup right left passage information map");
219 const CDCHit* ptrHit = std::get<const CDCHit* const>(relation);
220 const CDCSimHit* ptrSimHit = std::get<const CDCSimHit*>(relation);
222 if (not ptrSimHit)
continue;
226 if (directionOfFlight.
isNull())
continue;
230 ERightLeft rlInfo = trackPosToWire.xy().isRightOrLeftOf(directionOfFlight.
xy());
238 return itFoundHit ==
m_rightLeftInfos.end() ? ERightLeft::c_Invalid : itFoundHit->second;
244 B2WARNING(
"CDCMCMap not set. Cannot find reconstructed position");
252 B2WARNING(
"No CDCSimHit related to CDCHit");
263 B2WARNING(
"CDCMCMap not set. Cannot find reconstructed position");
271 B2WARNING(
"No CDCSimHit related to CDCHit");
282 if (ptrPrimarySimHit) {
283 const CDCSimHit& primarySimHit = *ptrPrimarySimHit;
292 if (ptrPrimarySimHit) {
293 const CDCSimHit& primarySimHit = *ptrPrimarySimHit;
301 const std::vector<CDCWireHit>& wireHits)
const
303 if (not ptrHit)
return nullptr;
306 if (wireHit.empty()) {
309 return &(wireHit.front());
314 const std::vector<CDCWireHit>& wireHits)
const
319 B2ASSERT(
"Could not find CDCWireHit for the requested hit", wireHit);
324 const std::vector<CDCWireHit>& wireHits)
const
335 const std::vector<CDCWireHit>& wireHits)
const
345 const std::vector<CDCWireHit>& wireHits)
const
352 const std::vector<CDCWireHit>& wireHits)
const
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
B2Vector3D getPosWire() const
The method to get position on wire.
WireID getWireID() const
Getter for WireID object.
B2Vector3D getPosTrack() const
The method to get position on the track.
double getDriftLength() const
The method to get drift length.
B2Vector3D getMomentum() const
The method to get momentum.
A Class to store the Monte Carlo particle information.
static const CDCSimHitLookUp & getSimHitLookUp()
Getter for the singleton instance of the CDCSimHitLookUp.
Class to organize and present the Monte Carlo hit information.
MayBePtr< const CDCSimHit > getSimHit(const CDCHit *hit) const
Seeks the CDCSimHit related to the CDCHit.
const std::multimap< const CDCHit *, const CDCSimHit * > & getSimHitsByHit() const
Getter for the CDCHit -> CDCSimHit relations.
MayBePtr< const MCParticle > getMCParticle(const CDCHit *hit) const
Seeks the MCParticle related to the CDCHit.
bool isReassignedSecondary(const CDCSimHit *ptrSimHit) const
Indicates if the CDCSimHit has been reassigned to a primary MCParticle.
auto getSimHits(const MCParticle *mcParticle) const
Getter for the range MCParticle to CDCSimHits relations which come from the given MCParticle.
Class representing an oriented hit wire including a hypotheses whether the causing track passes left ...
void setRefDriftLength(double driftLength)
Setter for the drift length at the reference position of the wire.
Class representing a two dimensional reconstructed hit in the central drift chamber.
Class representing a three dimensional reconstructed hit.
CDCRecoHit2D getRecoHit2D() const
Constructs a two dimensional reconstructed hit by carrying out the stereo ! projection to the wire re...
Singletone class to gather local information about the hits.
CDCRecoHit3D getRecoHit3D(const CDCHit *ptrHit, const std::vector< CDCWireHit > &wireHits) const
Construct an CDCRecoHit3D from the (potential secondary) CDCSimHit information related to the CDCHit.
void fillRLInfo()
Construct the look up relation for the right left passage information as used in track finding.
static const CDCSimHitLookUp & getInstance()
Getter for the singletone instance.
double getClosestPrimaryDriftLength(const CDCHit *ptrHit) const
Look up the drift length from the primary ionisation to the wire from related simulated hit.
const CDCWireHit * getWireHit(const CDCHit *ptrHit, const std::vector< CDCWireHit > &wireHits) const
Retrieve the wire hit the given CDCHit form the given wire hits.
double getDriftLength(const CDCHit *ptrHit) const
Look up the drift length from the primary ionisation to the wire from related simulated hit.
void fillPrimarySimHits()
Constructs the relation from reassigned secondary to a close by primary hit from the same MCParticle.
CDCRLWireHit getRLWireHit(const CDCHit *ptrHit, const std::vector< CDCWireHit > &wireHits) const
Retrieve the wire hit including right left passage information for the given CDCHit form the given wi...
Vector3D getDirectionOfFlight(const CDCHit *ptrHit)
Calculate the local direction of flight. If the hit is secondary take the direction of flight from a ...
Vector3D getRecoPos3D(const CDCHit *ptrHit) const
Look up the position of the primary ionisation from related simulated hit.
MayBePtr< const CDCSimHit > getClosestPrimarySimHit(const CDCSimHit *ptrSimHit) const
Helper function to find the closest primary hit for the given CDCSimHit from the same MCParticle - nu...
CDCRecoHit3D getClosestPrimaryRecoHit3D(const CDCHit *ptrHit, const std::vector< CDCWireHit > &wireHits) const
Construct an CDCRecoHit3D from the closest primary CDCSimHit information related to the CDCHit.
const CDCMCMap * m_ptrMCMap
Reference to the CDCMCMap to be used in this event.
std::map< const CDCHit *, ERightLeft > m_rightLeftInfos
Memory for the look up relation of the right left passage information as defined in tracking.
CDCRecoHit2D getClosestPrimaryRecoHit2D(const CDCHit *ptrHit, const std::vector< CDCWireHit > &wireHits) const
Construct an CDCRecoHit2D from the closest primary CDCSimHit information related to the CDCHit.
void fill(const CDCMCMap *ptrMCMap)
Gather the information about the right left passage using the CDCMCMap.
void clear()
Clear all information from the last event.
std::map< const CDCHit *, MayBePtr< const CDCSimHit > > m_primarySimHits
Memory for the look up relation of close primary CDCSimHits.
ERightLeft getRLInfo(const CDCHit *ptrHit) const
Look up the Monte Carlo right left passage information for the given hit.
CDCRecoHit2D getRecoHit2D(const CDCHit *ptrHit, const std::vector< CDCWireHit > &wireHits) const
Construct an CDCRecoHit2D from the (potential secondary) CDCSimHit information related to the CDCHit.
Vector3D getClosestPrimaryRecoPos3D(const CDCHit *ptrHit) const
Look up the position of the primary ionisation from the closest primary simulated hit.
Class representing a hit wire in the central drift chamber.
static constexpr const double c_simpleDriftLengthVariance
A default value for the drift length variance if no variance from the drift length translation is ava...
Class representing the sense wire arrangement in the whole of the central drift chamber.
bool arePrimaryNeighbors(const WireID &wireID, const WireID &otherWireID) const
Checks if two wires are primary neighbors.
static CDCWireTopology & getInstance()
Getter for the singleton instance of the wire topology.
A pair of iterators usable with the range base for loop.
A three dimensional vector.
const Vector2D & xy() const
Getter for the xy projected vector ( reference ! )
double distance(const Vector3D &rhs=Vector3D(0.0, 0.0, 0.0)) const
Calculates the distance of this point to the rhs.
bool isNull() const
Checks if the vector is the null vector.
Class to identify a wire inside the CDC.
ERightLeft
Enumeration to represent the distinct possibilities of the right left passage.
Abstract base class for different kinds of events.