10 #include <ecl/modules/eclTrackBremFinder/ECLTrackBremFinderModule.h>
13 #include <framework/dataobjects/EventMetaData.h>
14 #include <framework/logging/Logger.h>
15 #include <framework/gearbox/Const.h>
18 #include <mdst/dataobjects/ECLCluster.h>
19 #include <mdst/dataobjects/Track.h>
20 #include <mdst/dataobjects/PIDLikelihood.h>
21 #include <mdst/dataobjects/TrackFitResult.h>
24 #include <tracking/dataobjects/RecoTrack.h>
25 #include <tracking/dataobjects/BremHit.h>
28 #include <ecl/modules/eclTrackBremFinder/BestMatchContainer.h>
29 #include <ecl/modules/eclTrackBremFinder/BremFindingMatchCompute.h>
39 setDescription(
"Use Track direction to pick up possible ECL Brem Cluster");
52 "Factor which is multiplied onto the cluster position error to check for matches",
59 "Cut on the distance between the cluster position angle and the extrapolation angle",
70 const std::string relationName =
"Bremsstrahlung";
93 double trackMomentum = trackFitResult->
getMomentum().R();
95 if (trackMomentum > 5.0) {
96 B2DEBUG(20,
"Track momentum higher than 5GeV! Track is not used for bremsstrahlung finding");
104 B2DEBUG(20,
"Checking track for related ECLCluster");
108 auto relatedClustersToTrack =
111 for (
auto& relatedCluster : relatedClustersToTrack) {
113 primaryClusterOfTrack = &relatedCluster;
123 B2DEBUG(20,
"No RecoTrack for this Track");
129 std::vector<std::pair<float, RecoHitInformation*>> extrapolationParams = {};
130 std::vector<genfit::MeasuredStateOnPlane> extrapolatedStates = {};
134 for (
auto hit : recoTrack->getRecoHitInformations(
true)) {
135 if (hit->useInFit() && recoTrack->hasTrackFitStatus()) {
137 auto measState = recoTrack->getMeasuredStateOnPlaneFromRecoHit(hit);
138 float hitRadius = measState.getPos().Perp();
139 float distance = abs(hitRadius - virtualHitRadius);
142 nearestHitContainer.
add(hit, distance);
144 }
catch (NoTrackFitResult&) {
145 B2DEBUG(29,
"No track fit result available for this hit! Event: " <<
m_evtPtr->getEvent());
148 if (nearestHitContainer.
hasMatch()) {
150 extrapolationParams.push_back({virtualHitRadius, nearestHit});
155 for (
auto param : extrapolationParams) {
156 auto fitted_state = recoTrack->getMeasuredStateOnPlaneFromRecoHit(param.second);
158 fitted_state.extrapolateToCylinder(param.first);
159 extrapolatedStates.push_back(fitted_state);
161 B2DEBUG(20,
"Extrapolation failed!");
165 B2WARNING(
"Exception" << e.what());
173 B2DEBUG(20,
"Cluster has wrong hypothesis!");
179 auto relatedTrack = cluster.getRelatedFrom<
Track>();
181 B2DEBUG(20,
"Cluster already related to track, bailing out");
187 auto relatedBremHit = cluster.getRelated<
BremHit>();
188 if (relatedBremHit) {
189 B2DEBUG(20,
"Cluster already assumed to be bremsstrahlung cluster!");
193 typedef std::tuple<ECLCluster*, genfit::MeasuredStateOnPlane, double, double > ClusterMSoPPair;
199 for (
auto hit : recoTrack->getRecoHitInformations(
true)) {
200 if (hit->getTrackingDetector() == RecoHitInformation::c_PXD || hit->getTrackingDetector() == RecoHitInformation::c_SVD) {
202 if (!recoTrack->hasTrackFitStatus()) {
205 auto measState = recoTrack->getMeasuredStateOnPlaneFromRecoHit(hit);
207 if (bremFinder.isMatch()) {
208 ClusterMSoPPair match_pair = std::make_tuple(&cluster, measState, bremFinder.getDistanceHitCluster(),
209 bremFinder.getEffAcceptanceFactor());
210 matchContainer.
add(match_pair, bremFinder.getDistanceHitCluster());
212 }
catch (NoTrackFitResult&) {
213 B2DEBUG(29,
"No track fit result available for this hit! Event: " <<
m_evtPtr->getEvent());
215 B2WARNING(
"Exception" << e.what());
221 for (
auto fitted_state : extrapolatedStates) {
223 if (bremFinder.isMatch()) {
224 ClusterMSoPPair match_pair = std::make_tuple(&cluster, fitted_state, bremFinder.getDistanceHitCluster(),
225 bremFinder.getEffAcceptanceFactor());
226 matchContainer.
add(match_pair, bremFinder.getDistanceHitCluster());
234 const auto fitted_state = std::get<1>(matchClustermSoP);
236 const auto fitted_pos = ROOT::Math::XYZVector(fitted_state.getPos());
237 const auto fitted_mom = ROOT::Math::XYZVector(fitted_state.getMom());
239 const auto hit_theta = fitted_mom.Theta();
240 const auto hit_phi = fitted_mom.Phi();
242 B2DEBUG(20,
"Best Cluster" << std::endl
243 <<
" Cluster Phi=" << std::get<0>(matchClustermSoP)->getPhi() <<
" Theta=" << std::get<0>(matchClustermSoP)->getTheta()
244 <<
" TrackHit Phi=" << hit_phi <<
" Theta=" << hit_theta);
250 double effAcceptanceFactor = std::get<3>(matchClustermSoP);
251 ECLCluster* bremCluster = std::get<0>(matchClustermSoP);
252 double clusterDistance = std::get<2>(matchClustermSoP);
257 clusterDistance, effAcceptanceFactor);
261 bremCluster->
addRelationTo(&track, effAcceptanceFactor,
"Bremsstrahlung");
263 if (primaryClusterOfTrack) {
264 primaryClusterOfTrack->
addRelationTo(bremCluster, effAcceptanceFactor);
Multiple entries can be added, but only the one will be kept, which has the best quality estimator.
TItem const & getBestMatch() const
bool add(TItem item, TEstimator est, EstimatorComparison estComparison=[](TEstimator currentBest, TEstimator newEst) {return newEst< currentBest;})
Add a new item with an estimator value.
Module to compute if an extrapolation to the ECL matches the position of an secondary ECLCLuster to f...
A bremsstrahlung hit that correlates an ECLCluster with a RecoTrack.
Provides a type-safe way to pass members of the chargedStableSet set.
@ c_WriteOut
Object/array should be saved by output modules.
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
double getEnergy(EHypothesisBit hypothesis) const
Return Energy (GeV).
@ c_nPhotons
CR is split into n photons (N1)
virtual void initialize() override
Use this to initialize resources or memory your module needs.
std::vector< float > m_virtualHitRadii
Radii where virtual hits for the extrapolation will be generated The default values are taken from br...
virtual void event() override
Called once for each event.
StoreArray< BremHit > m_bremHits
StoreArray BremHits.
double m_clusterAcceptanceFactor
Factor which is multiplied onto the cluster position error to check for matches.
StoreObjPtr< EventMetaData > m_evtPtr
StoreObjPtr EventMetaData.
std::string m_param_tracksStoreArrayName
StoreArray name of the Tracks for brem matching.
StoreArray< Track > m_tracks
StoreArray Track.
std::string m_param_recoTracksStoreArrayName
StoreArray name of the RecoTracks for brem matching.
StoreArray< ECLCluster > m_eclClusters
StoreArray ECLCluster.
std::string m_param_eclClustersStoreArrayName
StoreArray name of the ECLClusters for brem matching.
StoreArray< RecoTrack > m_recoTracks
StoreArray RecoTrack.
ECLTrackBremFinderModule()
Constructor, for setting module description and parameters.
float m_clusterDistanceCut
Cut on the distance between the cluster position angle and the extrapolation angle.
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...
This is the Reconstruction Event-Data Model Track.
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Values of the result of a track fit with a given particle hypothesis.
ROOT::Math::XYZVector getMomentum() const
Getter for vector of momentum at closest approach of track in r/phi projection.
Class that bundles various TrackFitResults.
Exception class for error handling in GENFIT (provides storage for diagnostic information)
REG_MODULE(arichBtest)
Register the Module.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Abstract base class for different kinds of events.