8#include <tracking/modules/V0Finder/V0FinderModule.h>
10#include <framework/gearbox/Const.h>
11#include <framework/logging/Logger.h>
12#include <framework/core/ModuleParam.templateDetails.h>
14#include <mdst/dataobjects/TrackFitResult.h>
16#include <tracking/dataobjects/RecoTrack.h>
24 setDescription(
"This is a simple V0 finder for X = Ks, Lambda and converted photons "
25 "which matches all positive tracks with all negative tracks, "
26 "fitting a vertex for each pair. "
27 "Depending on the outcome of each fit, a corresponding "
28 "Belle2::V0 is stored or not.\n\n"
29 "A loose cut on the invariant mass (``massRangeX``) is applied before the fit (not considering material effects), "
30 "then a vertex fit is performed and only pairs passing a chi^2 (``vertexChi2CutOutside``) "
31 "and a second cut on the invariant mass (``invMassRangeX``) are stored as Belle2::V0. \n\n"
32 "No V0s with vertex inside the beam pipe "
33 "are saved as they can be recovered at analysis level. ");
39 "RecoTrack StoreArray name (input)", std::string(
""));
41 "RecoTrack StoreArray name (used for track refitting)", std::string(
"CopiedRecoTracks"));
43 "Belle2::TrackFitResult StoreArray name (in- and output).\n"
44 "Note that the V0s use pointers indices into these arrays, so all hell may break loose, "
45 "if you change this.", std::string(
""));
47 "Belle2::Track StoreArray name (input).\n"
48 "Note that the V0s use pointers indices into these arrays, so all hell may break loose, "
49 "if you change this.", std::string(
""));
58 "Radius at which we switch between the two classes of cuts. "
59 "The default is a little inside the beam pipe to allow some tolerance.",
63 "Maximum chi^2 for the vertex fit (NDF = 1)", 10000.);
66 "mass range in GeV for reconstructed Kshort after removing material effects and inner hits",
m_invMassRangeKshort);
69 "mass range in GeV for reconstructed Lambda after removing material effects and inner hits",
m_invMassRangeLambda);
72 "mass range in GeV for reconstructed Photon after removing material effects and inner hits",
m_invMassRangePhoton);
75 "designate which fitAndStore function is called in V0Fitter.\n"
76 " 0: store V0 at the first vertex fit, regardless of inner hits; \n"
77 " 1: remove hits inside the V0 vertex position;\n"
78 " 2: mode 1 + don't use SVD hits if there is only one available SVD hit-pair",
82 "mass range in GeV for reconstructed Kshort used for pre-selection of candidates"
85 "mass range in GeV for reconstructed Lambda used for pre-selection of candidates"
87 addParam(
"precutRho",
m_precutRho,
"preselection cut on the transverse radius of the point-of-closest-approach of two tracks. "
88 "Set value to 0 to accept all.", 0.5);
90 "Those above this cut are always accepted.", 0.9);
99 m_tracks.requireRelationTo(recoTracks);
120 B2FATAL(
"The minimum has to be smaller than the maximum of the Kshort mass range! min = " << std::get<0>
124 B2FATAL(
"The minimum has to be smaller than the maximum of the Lambda mass range! min = " << std::get<0>
147 B2DEBUG(29,
m_tracks.getEntries() <<
" tracks in event.");
150 std::vector<const Track*> tracksPlus;
151 tracksPlus.reserve(
m_tracks.getEntries());
153 std::vector<const Track*> tracksMinus;
154 tracksMinus.reserve(
m_tracks.getEntries());
156 for (
const auto& track :
m_tracks) {
158 B2ASSERT(
"No TrackFitResult available for given Track.", fitResult);
161 tracksPlus.push_back(&track);
164 tracksMinus.push_back(&track);
170 if (tracksPlus.empty() or tracksMinus.empty()) {
171 B2DEBUG(29,
"No interesting track pairs. tracksPlus " << tracksPlus.size() <<
", tracksMinus " << tracksMinus.size());
176 for (
auto& trackPlus : tracksPlus) {
177 for (
auto& trackMinus : tracksMinus) {
193 B2INFO(
"===V0Finder summary=============================================================");
195 B2INFO(
"- Inner hits successfully removed in " <<
m_nHitRemoved <<
" V0s.");
196 B2INFO(
"- The hit removal failed in " <<
m_nForceStored <<
" V0s, instead V0s before removing inner hits saved.");
202 const double* range_m2_min =
nullptr;
203 const double* range_m2_max =
nullptr;
219 double m_plus = trackHypotheses.first.getMass();
221 double E_plus =
sqrt(m_plus * m_plus + p_plus * p_plus);
224 double m_minus = trackHypotheses.second.getMass();
226 double E_minus =
sqrt(m_minus * m_minus + p_minus * p_minus);
229 double sum_E2 = (E_minus + E_plus) * (E_minus + E_plus);
232 double candmass_min2 = sum_E2 - (p_plus + p_minus) * (p_plus + p_minus);
233 double candmass_max2 = sum_E2 - (p_plus - p_minus) * (p_plus - p_minus);
236 bool in_range = candmass_max2 > *range_m2_min and candmass_min2 < *range_m2_max;
247 if (not fit1)
return false;
248 auto r1 = fit1->getPosition();
249 auto k1 = fit1->getMomentum().Unit();
252 if (not fit2)
return false;
253 auto r2 = fit2->getPosition();
254 auto k2 = fit2->getMomentum().Unit();
256 double cosAlpha = k1.Dot(k2);
269 double D = cosAlpha * cosAlpha - 1;
270 if (D == 0)
return true;
273 double b1 = dr.Dot(k1);
274 double b2 = dr.Dot(k2);
275 double lam1 = (-b1 + b2 * cosAlpha) / D;
276 double lam2 = (b2 - b1 * cosAlpha) / D;
277 auto p1 = r1 + k1 * lam1;
278 auto p2 = r2 + k2 * lam2;
279 auto poca = (p1 + p2) / 2;
288 bool isForceStored =
false, isHitRemoved =
false;
290 bool ok =
m_newV0Fitter->fitAndStore(trackPlus, trackMinus, v0Hypothesis, isForceStored, isHitRemoved);
293 bool ok =
m_v0Fitter->fitAndStore(trackPlus, trackMinus, v0Hypothesis, isForceStored, isHitRemoved);
298 }
catch (
const genfit::Exception& e) {
300 B2WARNING(
"Genfit exception caught. Skipping this track pair"
302 <<
LogVar(
"Genfit exception:", e.what()));
The ParticleType class for identifying different particle types.
int getPDGCode() const
PDG code.
static const ParticleType Lambda
Lambda particle.
static const ChargedStable pion
charged pion particle
static const ParticleType antiLambda
Anti-Lambda particle.
static const ParticleType Kshort
K^0_S particle.
static const ParticleType photon
photon particle
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...
Accessor to arrays stored in the data store.
Values of the result of a track fit with a given particle hypothesis.
short getChargeSign() const
Return track charge (1 or -1).
ROOT::Math::XYZVector getMomentum() const
Getter for vector of momentum at closest approach of track in r/phi projection.
Class that bundles various TrackFitResults.
const TrackFitResult * getTrackFitResultWithClosestMass(const Const::ChargedStable &requestedType) const
Return the track fit for a fit hypothesis with the closest mass.
std::tuple< double, double > m_preFilterMassRangeKshort
range for reconstructed Kshort mass used for pre-selection
int m_allStored
counter for all saved V0s
std::string m_arrayNameCopiedRecoTrack
StoreArray name of the RecoTracks.
std::string m_arrayNameV0
StoreArray name of the V0 (Output).
void initialize() override
Registration of StoreArrays, Relations, check proper GenFit setup.
std::tuple< double, double > m_preFilterMassRangeLambda
range for reconstructed Lambda mass used for pre-selection
bool isTrackPairSelected(const Track *track1, const Track *track2)
Track pair preselection based on a point-of-closest-approach of two tracks.
void fitAndStore(const Track *trackPlus, const Track *trackMinus, const Const::ParticleType &v0Hypothesis)
V0 fitting and storing.
void event() override
Creates Belle2::V0s from Belle2::Tracks as described in the class documentation.
int m_nForceStored
counter for saved V0s failing to remove the inner hits
std::string m_arrayNameTFResult
StoreArray name of the TrackFitResults (In- and Output).
double m_mKshortMax2
pre-calculated maximum Kshort mass squared
bool m_useValidation
on true save also fitted vertices in V0ValidationVertex StoreArray
std::string m_arrayNameV0ValidationVertex
StoreArray name of the V0ValidationVertex.
void terminate() override
Prints status summary.
double m_mLambdaMin2
pre-calculated minimum Lambda mass squared
double m_beamPipeRadius
Radius where inside/outside beampipe is defined.
V0FinderModule()
Setting of module description, parameters.
double m_mLambdaMax2
pre-calculated maximum Lambda mass squared
std::tuple< double, double > m_invMassRangePhoton
range for reconstructed Photon mass used after removing material effects and inner hits
double m_precutRho
preselection cut on transverse radius of the track pair POCA
std::unique_ptr< V0Fitter > m_v0Fitter
Object containing the actual algorithm.
StoreArray< Track > m_tracks
Actually array of mdst Tracks.
bool m_useNewV0Fitter
toggle between old (false) and new (true) V0 fitter
int m_nHitRemoved
counter for saved V0s successfully removing the inner hits
double m_vertexChi2CutOutside
Chi2 cut for V0s outside of the beampipe. Applies to all.
std::string m_arrayNameRecoTrack
StoreArray name of the RecoTracks (Input).
bool preFilterTracks(const Track *trackPlus, const Track *trackMinus, const Const::ParticleType &v0Hypothesis)
Helper function that gets the approximate mass range for the two given tracks and rejects candidates ...
int m_v0FitterMode
fitter mode
std::unique_ptr< NewV0Fitter > m_newV0Fitter
Object containing the actual algorithm.
double m_precutCosAlpha
preselection cut on opening angle of the track pair
std::tuple< double, double > m_invMassRangeKshort
range for reconstructed Kshort mass used after removing material effects and inner hits
std::tuple< double, double > m_invMassRangeLambda
range for reconstructed Lambda mass used after removing material effects and inner hits
std::string m_arrayNameTrack
StoreArray name of the Tracks (Input).
double m_mKshortMin2
pre-calculated minimum Kshort mass squared
Class to store variables with their name which were sent to the logging service.
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.
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.