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>
16 #include <framework/datastore/StoreArray.h>
19 #include <mdst/dataobjects/ECLCluster.h>
20 #include <mdst/dataobjects/Track.h>
21 #include <mdst/dataobjects/PIDLikelihood.h>
22 #include <mdst/dataobjects/TrackFitResult.h>
25 #include <tracking/dataobjects/RecoTrack.h>
26 #include <tracking/dataobjects/BremHit.h>
29 #include <ecl/modules/eclTrackBremFinder/BestMatchContainer.h>
30 #include <ecl/modules/eclTrackBremFinder/BremFindingMatchCompute.h>
40 setDescription(
"Use Track direction to pick up possible ECL Brem Cluster");
41 setPropertyFlags(c_ParallelProcessingCertified);
43 addParam(
"eclClustersStoreArrayName", m_param_eclClustersStoreArrayName,
"StoreArray name of the ECLClusters for brem matching",
44 m_param_eclClustersStoreArrayName);
46 addParam(
"tracksStoreArrayName", m_param_tracksStoreArrayName,
"StoreArray name of the Tracks for brem matching",
47 m_param_tracksStoreArrayName);
49 addParam(
"recoTracksStoreArrayName", m_param_recoTracksStoreArrayName,
"StoreArray name of the reco tracks used for brem search",
50 m_param_recoTracksStoreArrayName);
52 addParam(
"clusterAcceptanceFactor", m_clusterAcceptanceFactor,
53 "Factor which is multiplied onto the cluster position error to check for matches",
54 m_clusterAcceptanceFactor);
56 addParam(
"virtualHitRadii", m_virtualHitRadii,
"Radii where virtual hits for the extrapolation will be generated",
59 addParam(
"relativeClusterEnergy", m_relativeClusterEnergy,
"Fraction of the tracks energy the ECL cluster has "
60 "to possess to be considered for bremsstrahlung finding",
61 m_relativeClusterEnergy);
63 addParam(
"requestedNumberOfCDCHits", m_requestedNumberOfCDCHits,
"Minimal/Maximal number of CDC hits, the track has to possess "
64 "to be considered for bremsstrahlung finding",
65 m_requestedNumberOfCDCHits);
67 addParam(
"electronProbabilityCut", m_electronProbabilityCut,
"Cut on the electron probability (from pid) of track",
68 m_electronProbabilityCut);
70 addParam(
"clusterDistanceCut", m_clusterDistanceCut,
71 "Cut on the distance between the cluster position angle and the extrapolation angle",
72 m_clusterDistanceCut);
82 const std::string relationName =
"Bremsstrahlung";
109 double highestProb = 0;
111 double probability = pid->getProbability(pdg);
112 if (probability > highestProb) {
113 highestProb = probability;
118 B2DEBUG(20,
"Track is expected not to be from electron");
124 double trackMomentum;
125 if (trackFitResult) {
126 trackMomentum = trackFitResult->
getMomentum().Mag();
128 if (trackMomentum > 5.0) {
129 B2DEBUG(20,
"Track momentum higher than 5GeV! Track is not used for bremsstrahlung finding");
137 B2DEBUG(20,
"Checking track for related ECLCluster");
141 auto relatedClustersToTrack =
144 for (
auto& relatedCluster : relatedClustersToTrack) {
146 primaryClusterOfTrack = &relatedCluster;
156 B2DEBUG(20,
"No RecoTrack for this Track");
163 B2DEBUG(20,
"RecoTrack has not requested number of CDC hits");
168 std::vector<std::pair<float, RecoHitInformation*>> extrapolationParams = {};
169 std::vector<genfit::MeasuredStateOnPlane> extrapolatedStates = {};
173 for (
auto hit : recoTrack->getRecoHitInformations(
true)) {
174 if (hit->useInFit() && recoTrack->hasTrackFitStatus()) {
176 auto measState = recoTrack->getMeasuredStateOnPlaneFromRecoHit(hit);
177 float hitRadius = measState.getPos().Perp();
178 float distance = abs(hitRadius - virtualHitRadius);
181 nearestHitContainer.
add(hit, distance);
183 }
catch (NoTrackFitResult&) {
184 B2DEBUG(29,
"No track fit result available for this hit! Event: " <<
m_evtPtr->getEvent());
187 if (nearestHitContainer.
hasMatch()) {
189 extrapolationParams.push_back({virtualHitRadius, nearestHit});
194 for (
auto param : extrapolationParams) {
195 auto fitted_state = recoTrack->getMeasuredStateOnPlaneFromRecoHit(param.second);
197 fitted_state.extrapolateToCylinder(param.first);
198 extrapolatedStates.push_back(fitted_state);
200 B2DEBUG(20,
"Extrapolation failed!");
204 B2WARNING(
"Exception" << e.what());
212 B2DEBUG(20,
"Cluster has wrong hypothesis!");
217 auto relatedTrack = cluster.getRelatedFrom<
Track>();
219 B2DEBUG(20,
"Cluster already related to track, bailing out");
225 auto relatedBremHit = cluster.getRelated<
BremHit>();
226 if (relatedBremHit) {
227 B2DEBUG(20,
"Cluster already assumed to be bremsstrahlung cluster!");
235 B2DEBUG(20,
"Relative energy of cluster higher than 1 or below threshold!");
239 typedef std::tuple<ECLCluster*, genfit::MeasuredStateOnPlane, double, double > ClusterMSoPPair;
245 for (
auto hit : recoTrack->getRecoHitInformations(
true)) {
246 if (hit->getTrackingDetector() == RecoHitInformation::c_PXD || hit->getTrackingDetector() == RecoHitInformation::c_SVD) {
248 if (!recoTrack->hasTrackFitStatus()) {
251 auto measState = recoTrack->getMeasuredStateOnPlaneFromRecoHit(hit);
253 if (bremFinder.isMatch()) {
254 ClusterMSoPPair match_pair = std::make_tuple(&cluster, measState, bremFinder.getDistanceHitCluster(),
255 bremFinder.getEffAcceptanceFactor());
256 matchContainer.
add(match_pair, bremFinder.getDistanceHitCluster());
258 }
catch (NoTrackFitResult&) {
259 B2DEBUG(29,
"No track fit result available for this hit! Event: " <<
m_evtPtr->getEvent());
261 B2WARNING(
"Exception" << e.what());
267 for (
auto fitted_state : extrapolatedStates) {
269 if (bremFinder.isMatch()) {
270 ClusterMSoPPair match_pair = std::make_tuple(&cluster, fitted_state, bremFinder.getDistanceHitCluster(),
271 bremFinder.getEffAcceptanceFactor());
272 matchContainer.
add(match_pair, bremFinder.getDistanceHitCluster());
280 const auto fitted_state = std::get<1>(matchClustermSoP);
282 const auto fitted_pos = fitted_state.getPos();
283 const auto fitted_mom = fitted_state.getMom();
284 const auto fitted_dir = fitted_state.getDir();
286 const auto hit_theta = fitted_mom.Theta();
287 const auto hit_phi = fitted_mom.Phi();
289 B2DEBUG(20,
"Best Cluster" << std::endl
290 <<
" Cluster Phi=" << std::get<0>(matchClustermSoP)->getPhi() <<
" Theta=" << std::get<0>(matchClustermSoP)->getTheta()
291 <<
" TrackHit Phi=" << hit_phi <<
" Theta=" << hit_theta);
297 double effAcceptanceFactor = std::get<3>(matchClustermSoP);
298 ECLCluster* bremCluster = std::get<0>(matchClustermSoP);
299 double clusterDistance = std::get<2>(matchClustermSoP);
304 clusterDistance, effAcceptanceFactor);
308 bremCluster->
addRelationTo(&track, effAcceptanceFactor,
"Bremsstrahlung");
310 if (primaryClusterOfTrack) {
311 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.
static const ChargedStable muon
muon particle
static const ChargedStable pion
charged pion particle
static const ChargedStable proton
proton particle
static const ChargedStable kaon
charged kaon particle
static const ChargedStable electron
electron particle
static const ChargedStable deuteron
deuteron particle
@ 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)
Module to assign ECL Clusters resulting from Bremsstrahlung to the primary electron track.
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.
float m_electronProbabilityCut
Cut on the electron probability (from pid) of track.
StoreArray< BremHit > m_bremHits
StoreArray BremHits.
std::tuple< unsigned int, unsigned int > m_requestedNumberOfCDCHits
Minimal/Maximal number of CDC hits, the track has to possess to be considered for bremsstrahlung find...
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.
double m_relativeClusterEnergy
Fraction of the tracks energy the ECL cluster has to possess to be considered for bremsstrahlung find...
float m_clusterDistanceCut
Cut on the distance between the cluster position angle and the extrapolation angle.
Class to collect log likelihoods from TOP, ARICH, dEdx, ECL and KLM aimed for output to mdst includes...
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).
Values of the result of a track fit with a given particle hypothesis.
TVector3 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)
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.