Belle II Software  release-06-01-15
XHitFilterFactory.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #pragma once
10 
11 
12 #include <tracking/dataobjects/FilterID.h>
13 
14 // 2-hit:
15 #include <tracking/vxdCaTracking/TwoHitFilters.h>
16 // 3-hit:
17 #include <tracking/vxdCaTracking/ThreeHitFilters.h>
18 // 4-hit:
19 #include <tracking/vxdCaTracking/FourHitFilters.h>
20 
21 #include <framework/logging/Logger.h>
22 
23 #include <string>
24 
25 #include <TVector3.h>
26 
27 
28 namespace Belle2 {
35  template<class PointType>
37  public:
38 
40  XHitFilterFactory(double x = 0, double y = 0, double z = 0, double mField = 1.5) :
41  m_virtualIP(x, y, z)
42  {
45  }
46 
47 
48 
50  /* XHitFilterFactory() : m_virtualIP(0, 0, 0) {}*/
51 
52 
53 
56 
58  using TwoHitFunction = typename std::function<double(const PointType&, const PointType&)>;
59 
61  using ThreeHitFunction = typename std::function<double(const PointType&, const PointType&, const PointType&)>;
62 
64  using FourHitFunction = typename std::function<double(const PointType&, const PointType&, const PointType&, const PointType&)>;
65 
66 
67 
69  TwoHitFunction get2HitInterface(std::string variableName)
70  {
71  XHitFilterType varType = FilterID::getTypeEnum(variableName);
72  return get2HitInterface(varType);
73  }
74 
75 
76 
79  {
80  // prepare stuff for 2-hit-filters:
81  auto prepareStuff = [ = ](const PointType & outerHit, const PointType & innerHit) -> void {
82  TVector3 tOuterHit(outerHit.X(), outerHit.Y(), outerHit.Z());
83  TVector3 tInnerHit(innerHit.X(), innerHit.Y(), innerHit.Z());
84  m_twoHit.resetValues(tOuterHit, tInnerHit);
85  };
86 
88  if (variableType == FilterID::distance3D) {
89  return [ = ](const PointType & outerHit, const PointType & innerHit) -> double {
90  prepareStuff(outerHit, innerHit);
91  return m_twoHit.calcDist3D();
92  };
93  }
94 
95  if (variableType == FilterID::distanceXY) {
96  return [ = ](const PointType & outerHit, const PointType & innerHit) -> double {
97  prepareStuff(outerHit, innerHit);
98  return m_twoHit.calcDistXY();
99  };
100  }
101 
102  if (variableType == FilterID::distanceZ) {
103  return [ = ](const PointType & outerHit, const PointType & innerHit) -> double {
104  prepareStuff(outerHit, innerHit);
105  return m_twoHit.calcDistZ();
106  };
107  }
108 
109  if (variableType == FilterID::slopeRZ) {
110  return [ = ](const PointType & outerHit, const PointType & innerHit) -> double {
111  prepareStuff(outerHit, innerHit);
112  return m_twoHit.calcSlopeRZ();
113  };
114  }
115 
116  if (variableType == FilterID::normedDistance3D) {
117  return [ = ](const PointType & outerHit, const PointType & innerHit) -> double {
118  prepareStuff(outerHit, innerHit);
119  return m_twoHit.calcNormedDist3D();
120  };
121  }
122 
123  // prepare stuff for 2+1-hit-filters
124  auto prepareStuffHiOc = [ = ](const PointType & outerHit, const PointType & innerHit) -> void {
125  TVector3 tOuterHit(outerHit.X(), outerHit.Y(), outerHit.Z());
126  TVector3 tInnerHit(innerHit.X(), innerHit.Y(), innerHit.Z());
127  m_threeHit.resetValues(tOuterHit, tInnerHit, m_virtualIP);
128  };
129 
130 
132  if (variableType == FilterID::anglesHighOccupancy3D) {
133  return [ = ](const PointType & outerHit, const PointType & innerHit) -> double {
134  prepareStuffHiOc(outerHit, innerHit);
135  return m_threeHit.calcAngle3D();
136  };
137  }
138 
139  if (variableType == FilterID::anglesHighOccupancyXY) {
140  return [ = ](const PointType & outerHit, const PointType & innerHit) -> double {
141  prepareStuffHiOc(outerHit, innerHit);
142  return m_threeHit.calcAngleXY();
143  };
144  }
145 
146  if (variableType == FilterID::anglesHighOccupancyRZ) {
147  return [ = ](const PointType & outerHit, const PointType & innerHit) -> double {
148  prepareStuffHiOc(outerHit, innerHit);
149  return m_threeHit.calcAngleRZ();
150  };
151  }
152 
153  if (variableType == FilterID::distanceHighOccupancy2IP) {
154  return [ = ](const PointType & outerHit, const PointType & innerHit) -> double {
155  prepareStuffHiOc(outerHit, innerHit);
156  return m_threeHit.calcCircleDist2IP();
157  };
158  }
159 
160  if (variableType == FilterID::deltaSlopeHighOccupancyRZ) {
161  return [ = ](const PointType & outerHit, const PointType & innerHit) -> double {
162  prepareStuffHiOc(outerHit, innerHit);
163  return m_threeHit.calcDeltaSlopeRZ();
164  };
165  }
166 
167  if (variableType == FilterID::pTHighOccupancy) {
168  return [ = ](const PointType & outerHit, const PointType & innerHit) -> double {
169  prepareStuffHiOc(outerHit, innerHit);
170  return m_threeHit.calcPt();
171  };
172  }
173 
174  if (variableType == FilterID::helixParameterHighOccupancyFit) {
175  return [ = ](const PointType & outerHit, const PointType & innerHit) -> double {
176  prepareStuffHiOc(outerHit, innerHit);
178  };
179  }
180 
181 
182 
183  B2ERROR(" XHitFilterAdapter-2Hit: given name (raw/full): " << variableType <<
184  "/" << FilterID::getTypeName(variableType) <<
185  " is not known, returning dummy function with 0.0 as a result instead!");
186 
187  return [&](const PointType&, const PointType&) -> double { return 0.0; };
188  }
189 
190 
191 
193  ThreeHitFunction get3HitInterface(std::string variableName)
194  {
195  XHitFilterType varType = FilterID::getTypeEnum(variableName);
196  return get3HitInterface(varType);
197  }
198 
199 
200 
203  {
204  // prepare stuff for 3-hit-filters
205  auto prepareStuff3Hit = [ = ](const PointType & outerHit, const PointType & centerHit, const PointType & innerHit) -> void {
206  TVector3 tOuterHit(outerHit.X(), outerHit.Y(), outerHit.Z());
207  TVector3 tCenterHit(centerHit.X(), centerHit.Y(), centerHit.Z());
208  TVector3 tInnerHit(innerHit.X(), innerHit.Y(), innerHit.Z());
209  m_threeHit.resetValues(tOuterHit, tCenterHit, tInnerHit);
210  };
211 
213  if (variableType == FilterID::angles3D) {
214  return [ = ](const PointType & outerHit, const PointType & centerHit, const PointType & innerHit) -> double {
215  prepareStuff3Hit(outerHit, centerHit, innerHit);
216  return m_threeHit.calcAngle3D();
217  };
218  }
219 
220  if (variableType == FilterID::anglesRZ) {
221  return [ = ](const PointType & outerHit, const PointType & centerHit, const PointType & innerHit) -> double {
222  prepareStuff3Hit(outerHit, centerHit, innerHit);
223  return m_threeHit.calcAngleRZ();
224  };
225  }
226 
227  if (variableType == FilterID::anglesXY) {
228  return [ = ](const PointType & outerHit, const PointType & centerHit, const PointType & innerHit) -> double {
229  prepareStuff3Hit(outerHit, centerHit, innerHit);
230  return m_threeHit.calcAngleXY();
231  };
232  }
233 
234  if (variableType == FilterID::deltaSlopeRZ) {
235  return [ = ](const PointType & outerHit, const PointType & centerHit, const PointType & innerHit) -> double {
236  prepareStuff3Hit(outerHit, centerHit, innerHit);
237  return m_threeHit.calcDeltaSlopeRZ();
238  };
239  }
240 
241  if (variableType == FilterID::pT) {
242  return [ = ](const PointType & outerHit, const PointType & centerHit, const PointType & innerHit) -> double {
243  prepareStuff3Hit(outerHit, centerHit, innerHit);
244  return m_threeHit.calcPt();
245  };
246  }
247 
248  if (variableType == FilterID::distance2IP) {
249  return [ = ](const PointType & outerHit, const PointType & centerHit, const PointType & innerHit) -> double {
250  prepareStuff3Hit(outerHit, centerHit, innerHit);
251  return m_threeHit.calcCircleDist2IP();
252  };
253  }
254 
255  if (variableType == FilterID::helixParameterFit) {
256  return [ = ](const PointType & outerHit, const PointType & centerHit, const PointType & innerHit) -> double {
257  prepareStuff3Hit(outerHit, centerHit, innerHit);
259  };
260  }
261 
262  if (variableType == FilterID::deltaSOverZ) {
263  return [ = ](const PointType & outerHit, const PointType & centerHit, const PointType & innerHit) -> double {
264  prepareStuff3Hit(outerHit, centerHit, innerHit);
265  return m_threeHit.calcDeltaSOverZ();
266  };
267  }
268 
269  if (variableType == FilterID::deltaSlopeZOverS) {
270  return [ = ](const PointType & outerHit, const PointType & centerHit, const PointType & innerHit) -> double {
271  prepareStuff3Hit(outerHit, centerHit, innerHit);
273  };
274  }
275 
276 
277  // prepare stuff for 3+1-hit-filters
278  auto prepareStuff4Hit = [ = ](const PointType & outerHit, const PointType & centerHit,
279  const PointType & innerHit) -> void {
280  TVector3 tOuterHit(outerHit.X(), outerHit.Y(), outerHit.Z());
281  TVector3 tCenterHit(centerHit.X(), centerHit.Y(), centerHit.Z());
282  TVector3 tInnerHit(innerHit.X(), innerHit.Y(), innerHit.Z());
283  m_fourHit.resetValues(tOuterHit, tCenterHit, tInnerHit, m_virtualIP);
284  };
285 
287  if (variableType == FilterID::deltapTHighOccupancy) {
288  return [ = ](const PointType & outerHit, const PointType & centerHit, const PointType & innerHit) -> double {
289  prepareStuff4Hit(outerHit, centerHit, innerHit);
290  return m_fourHit.calcDeltapT();
291  };
292  }
293 
294  if (variableType == FilterID::deltaDistanceHighOccupancy2IP) {
295  return [ = ](const PointType & outerHit, const PointType & centerHit, const PointType & innerHit) -> double {
296  prepareStuff4Hit(outerHit, centerHit, innerHit);
298  };
299  }
300 
301 
302  B2ERROR(" XHitFilterAdapter-3Hit: given name (raw/full): " << variableType <<
303  "/" << FilterID::getTypeName(variableType) <<
304  " is not known, returning dummy function with 0.0 as a result instead!");
305 
306  return [&](const PointType&, const PointType&, const PointType&) -> double { return 0.0; };
307  }
308 
309 
310 
312  FourHitFunction get4HitInterface(std::string variableName)
313  {
314  XHitFilterType varType = FilterID::getTypeEnum(variableName);
315  return get4HitInterface(varType);
316  }
317 
318 
319 
322  {
323 
324  // prepare stuff for 4-hit-filters
325  auto prepareStuff4Hit = [ = ](const PointType & outerHit, const PointType & outerCenterHit,
326  const PointType & innerCenterHit, const PointType & innerHit) -> void {
327  TVector3 tOuterHit(outerHit.X(), outerHit.Y(), outerHit.Z());
328  TVector3 tOuterCenterHit(outerCenterHit.X(), outerCenterHit.Y(), outerCenterHit.Z());
329  TVector3 tInnerCenterHit(innerCenterHit.X(), innerCenterHit.Y(), innerCenterHit.Z());
330  TVector3 tInnerHit(innerHit.X(), innerHit.Y(), innerHit.Z());
331  m_fourHit.resetValues(tOuterHit, tOuterCenterHit, tInnerCenterHit, tInnerHit);
332  };
333 
335  if (variableType == FilterID::deltapT) {
336  return [ = ](const PointType & outerHit, const PointType & outerCenterHit,
337  const PointType & innerCenterHit , const PointType & innerHit) -> double {
338  prepareStuff4Hit(outerHit, outerCenterHit, innerCenterHit, innerHit);
339  return m_fourHit.calcDeltapT();
340  };
341  }
342 
343  if (variableType == FilterID::deltaDistance2IP) {
344  return [ = ](const PointType & outerHit, const PointType & outerCenterHit,
345  const PointType & innerCenterHit , const PointType & innerHit) -> double {
346  prepareStuff4Hit(outerHit, outerCenterHit, innerCenterHit, innerHit);
348  };
349  }
350 
351 
352  B2ERROR(" XHitFilterAdapter-4Hit: given name (raw/full): " << variableType <<
353  "/" << FilterID::getTypeName(variableType) <<
354  " is not known, returning dummy function with 0.0 as a result instead!");
355 
356  return [&](const PointType&, const PointType&, const PointType&, const PointType&) -> double { return 0.0; };
357  }
358 
359 
360 
361  protected:
362 
367  TVector3 m_virtualIP;
368  };
370 }
371 
372 
static filterTypes getTypeEnum(const std::string &filterString)
returns type of given name, needed for compatibility with other modules.
Definition: FilterID.h:240
static std::string getTypeName(filterTypes filterType)
returns name of given type, needed for compatibility with other modules
Definition: FilterID.cc:435
filterTypes
filterTyoes contains enums assigning unique values for each filter type allowing fast filter type rec...
Definition: FilterID.h:31
@ distanceHighOccupancy2IP
string name of filter d2IP high occupancy
Definition: FilterID.h:44
@ deltaDistance2IP
string name of filter dd2IP
Definition: FilterID.h:69
@ distance2IP
string name of filter d2IP
Definition: FilterID.h:56
@ deltaSlopeHighOccupancyRZ
string name of filter dslopeRZ high occupancy
Definition: FilterID.h:45
@ anglesHighOccupancy3D
string name of filter a3D high occupancy
Definition: FilterID.h:41
@ deltapT
string name of filter dPt
Definition: FilterID.h:68
@ distanceXY
string name of filter dXY
Definition: FilterID.h:34
@ anglesXY
string name of filter aXY
Definition: FilterID.h:53
@ normedDistance3D
string name of filter nd3D
Definition: FilterID.h:37
@ slopeRZ
string name of filter slopeRZ
Definition: FilterID.h:36
@ distance3D
string name of filter d3D
Definition: FilterID.h:33
@ anglesHighOccupancyXY
string name of filter aXY high occupancy
Definition: FilterID.h:42
@ helixParameterFit
string name of filter helix Paramater Fit
Definition: FilterID.h:57
@ deltaSlopeRZ
string name of filter dslopeRZ
Definition: FilterID.h:54
@ deltaDistanceHighOccupancy2IP
string name of filter dd2IP high occupancy
Definition: FilterID.h:64
@ helixParameterHighOccupancyFit
string name of filter hFit high occupancy
Definition: FilterID.h:47
@ deltapTHighOccupancy
string name of filter dPt high occupancy
Definition: FilterID.h:63
@ pTHighOccupancy
string name of filter pT high occupancy
Definition: FilterID.h:46
@ angles3D
string name of filter a3D
Definition: FilterID.h:51
@ anglesRZ
string name of filter aRZ
Definition: FilterID.h:52
@ deltaSlopeZOverS
deltaSlopeZOverS Filter
Definition: FilterID.h:59
@ distanceZ
string name of filter dZ
Definition: FilterID.h:35
@ deltaSOverZ
deltaSOverZ Filter
Definition: FilterID.h:58
@ pT
string name of filter pT
Definition: FilterID.h:55
@ anglesHighOccupancyRZ
string name of filter aRZ high occupancy
Definition: FilterID.h:43
The class 'FourHitFilters' bundles filter methods using 4 hits which are stored in TVector3s.
double calcDeltaDistCircleCenter()
calculates ddist2IP-value directly (ddist2IP= difference in magnitude of the points of closest approa...
void resetValues(const TVector3 &outer, const TVector3 &outerCenter, const TVector3 &innerCenter, const TVector3 &inner)
Overrides Constructor-Setup.
double calcDeltapT()
calculates dpt-value (dpt= difference in transverse momentum of 2 subsets of the hits),...
void resetMagneticField(const double magneticFieldStrength=1.5)
Overrides Constructor-Setup for magnetic field.
The class 'ThreeHitFilters' bundles filter methods using 3 hits which are stored in TVector3s.
double calcAngle3D()
calculates the angle between the hits/vectors (3D), returning unit: none (calculation for degrees is ...
double calcDeltaSOverZ()
calculates the helixparameter describing the deviation in arc length per unit in z.
double calcPt()
calculates the estimation of the transverse momentum of the 3-hit-tracklet, returning unit: GeV/c
double calcDeltaSlopeRZ()
calculates deviations in the slope of the inner segment and the outer segment, returning unit: none
double calcAngleRZ()
calculates the angle between the hits/vectors (RZ), returning unit: none (calculation for degrees is ...
double calcDeltaSlopeZOverS()
compares the "slopes" z over arc length.
void resetValues(const TVector3 &outerHit, const TVector3 &centerHit, const TVector3 &innerHit)
Overrides Constructor-Setup.
double calcCircleDist2IP()
calculates the distance of the point of closest approach of circle to the IP, returning unit: cm
void resetMagneticField(const double magneticFieldStrength=1.5)
Overrides Constructor-Setup for magnetic field.
double calcHelixParameterFit()
calculates the helixparameter describing the deviation in z per unit angle, returning unit: none
double calcAngleXY()
calculates the angle between the hits/vectors (XY), returning unit: none (calculation for degrees is ...
The class 'TwoHitFilters' bundles filter methods using 2 hits which are stored in TVector3s.
Definition: TwoHitFilters.h:22
double calcNormedDist3D() const
calculates the normed distance between the hits (3D), return unit: none
Definition: TwoHitFilters.h:81
void resetValues(const TVector3 &outerHit, const TVector3 &innerHit)
Overrides Constructor-Setup.
Definition: TwoHitFilters.h:46
double calcDist3D() const
calculates the distance between the hits (3D), returning unit: cm^2 for speed optimization
Definition: TwoHitFilters.h:55
double calcDistXY() const
calculates the distance between the hits (XY), returning unit: cm^2 for speed optimization
Definition: TwoHitFilters.h:61
double calcSlopeRZ() const
calculates the angle of the slope of the hits in RZ, returnValue = theta = atan(r/z)
Definition: TwoHitFilters.h:70
double calcDistZ() const
calculates the distance between the hits (Z only), returning unit: cm
Definition: TwoHitFilters.h:67
The factory serves as an interface between all x-hit-filters and a user only knowing their name (in s...
ThreeHitFunction get3HitInterface(std::string variableName)
For given name of a variableType a function for the corresponding Filter is returned.
TVector3 m_virtualIP
contains global coordinates of virtual interaction point.
typename std::function< double(const PointType &, const PointType &, const PointType &, const PointType &)> FourHitFunction
typedef for more readable function-type - to be used for 4-hit-selectionVariables.
FourHitFilters m_fourHit
contains all 4-hit-filters.
XHitFilterFactory(double x=0, double y=0, double z=0, double mField=1.5)
constructor where virtual IP has been passed
ThreeHitFunction get3HitInterface(XHitFilterType variableType)
For given name of a variableType a function for the corresponding Filter is returned.
ThreeHitFilters m_threeHit
contains all 3-hit-filters.
FourHitFunction get4HitInterface(XHitFilterType variableType)
For given name of a variableType a function for the corresponding Filter is returned.
typename std::function< double(const PointType &, const PointType &)> TwoHitFunction
typedef for more readable function-type - to be used for 2-hit-selectionVariables.
TwoHitFunction get2HitInterface(std::string variableName)
For given name of a variableType a function for the corresponding Filter is returned.
FilterID::filterTypes XHitFilterType
constructor where nothing has been passed
FourHitFunction get4HitInterface(std::string variableName)
For given name of a variableType a function for the corresponding Filter is returned.
typename std::function< double(const PointType &, const PointType &, const PointType &)> ThreeHitFunction
typedef for more readable function-type - to be used for 3-hit-selectionVariables.
TwoHitFilters m_twoHit
contains all 2-hit-filters.
TwoHitFunction get2HitInterface(XHitFilterType variableType)
For given name of a variableType a function for the corresponding Filter is returned.
Abstract base class for different kinds of events.