Belle II Software development
ClosestApproach.cc
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#include "cdc/utilities/ClosestApproach.h"
9
10namespace Belle2 {
15 namespace CDC {
16
17 double ClosestApproach(const B2Vector3D& bwp, const B2Vector3D& fwp, const B2Vector3D& posIn, const B2Vector3D& posOut,
18 B2Vector3D& hitPosition, B2Vector3D& wirePosition)
19 {
20 //----------------------------------------------------------
21 /* For two lines r=r1+t1.v1 & r=r2+t2.v2
22 the closest approach is d=|(r2-r1).(v1 x v2)|/|v1 x v2|
23 the point where closest approach are
24 t1=(v1 x v2).[(r2-r1) x v2]/[(v1 x v2).(v1 x v2)]
25 t2=(v1 x v2).[(r2-r1) x v1]/[(v1 x v2).(v1 x v2)]
26 if v1 x v2=0 means two lines are parallel
27 d=|(r2-r1) x v1|/|v1|
28 */
29
30 double t2, distance;
31
32 //--------------------------
33 // Get wirepoint @ endplate
34 //--------------------------
35 /* CDCGeometryPar& cdcgp = CDCGeometryPar::Instance();
36 B2Vector3D tfwp = cdcgp.wireForwardPosition(layerId, cellId);
37 G4ThreeVector fwp(tfwp.X(), tfwp.Y(), tfwp.Z());
38 B2Vector3D tbwp = cdcgp.wireBackwardPosition(layerId, cellId);
39 G4ThreeVector bwp(tbwp.X(), tbwp.Y(), tbwp.Z());
40 */
41
42 B2Vector3D wireLine = fwp - bwp;
43 B2Vector3D hitLine = posOut - posIn;
44
45 B2Vector3D hitXwire = hitLine.Cross(wireLine);
46 B2Vector3D wire2hit = fwp - posOut;
47
48 //----------------------------------------------------------------
49 // Hitposition is the position on hit line where closest approach
50 // of two lines, but it may out the area from posIn to posOut
51 //----------------------------------------------------------------
52 if (hitXwire.Mag() == 0) {
53 distance = wireLine.Cross(wire2hit).Mag() / wireLine.Mag();
54 hitPosition = posIn;
55 t2 = (posIn - fwp).Dot(wireLine) / wireLine.Mag2();
56 } else {
57 double t1 = hitXwire.Dot(wire2hit.Cross(wireLine)) / hitXwire.Mag2();
58 hitPosition = posOut + t1 * hitLine;
59 t2 = hitXwire.Dot(wire2hit.Cross(hitLine)) / hitXwire.Mag2();
60
61 //should not constrain hitPosition inside the cell
62 // double dInOut = (posOut - posIn).Mag();
63 // double dHitIn = (hitPosition - posIn).Mag();
64 // double dHitOut = (hitPosition - posOut).Mag();
65 // if (dHitIn <= dInOut && dHitOut <= dInOut) { //Between point in & out
66 distance = fabs(wire2hit.Dot(hitXwire) / hitXwire.Mag());
67 /*
68 } else if (dHitOut > dHitIn) { // out posIn
69 distance = wireLine.Cross(posIn - fwp).Mag() / wireLine.Mag();
70 hitPosition = posIn;
71 t2 = (posIn - fwp).Dot(wireLine) / wireLine.Mag2();
72 } else { // out posOut
73 distance = wireLine.Cross(posOut - fwp).Mag() / wireLine.Mag();
74 hitPosition = posOut;
75 t2 = (posOut - fwp).Dot(wireLine) / wireLine.Mag2();
76 }
77 */
78 }
79
80 wirePosition = fwp + t2 * wireLine;
81 return distance;
82 }
83
84 }
86}
B2Vector3< DataType > Cross(const B2Vector3< DataType > &p) const
Cross product.
Definition: B2Vector3.h:296
DataType Mag() const
The magnitude (rho in spherical coordinate system).
Definition: B2Vector3.h:159
DataType Mag2() const
The magnitude squared (rho^2 in spherical coordinate system).
Definition: B2Vector3.h:157
DataType Dot(const B2Vector3< DataType > &p) const
Scalar product.
Definition: B2Vector3.h:290
double ClosestApproach(const B2Vector3D &bwp, const B2Vector3D &fwp, const B2Vector3D &posIn, const B2Vector3D &posOut, B2Vector3D &hitPosition, B2Vector3D &wirePosition)
Returns a closest distance between a track and a wire.
Abstract base class for different kinds of events.