Belle II Software  release-05-01-25
ClosestApproach.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: CDC group *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include "cdc/utilities/ClosestApproach.h"
11 
12 namespace Belle2 {
17  namespace CDC {
18 
19  double ClosestApproach(const TVector3& bwp, const TVector3& fwp, const TVector3& posIn, const TVector3& posOut,
20  TVector3& hitPosition, TVector3& wirePosition)
21  {
22  //----------------------------------------------------------
23  /* For two lines r=r1+t1.v1 & r=r2+t2.v2
24  the closest approach is d=|(r2-r1).(v1 x v2)|/|v1 x v2|
25  the point where closest approach are
26  t1=(v1 x v2).[(r2-r1) x v2]/[(v1 x v2).(v1 x v2)]
27  t2=(v1 x v2).[(r2-r1) x v1]/[(v1 x v2).(v1 x v2)]
28  if v1 x v2=0 means two lines are parallel
29  d=|(r2-r1) x v1|/|v1|
30  */
31 
32  double t2, distance;
33 
34  //--------------------------
35  // Get wirepoint @ endplate
36  //--------------------------
37  /* CDCGeometryPar& cdcgp = CDCGeometryPar::Instance();
38  TVector3 tfwp = cdcgp.wireForwardPosition(layerId, cellId);
39  G4ThreeVector fwp(tfwp.x(), tfwp.y(), tfwp.z());
40  TVector3 tbwp = cdcgp.wireBackwardPosition(layerId, cellId);
41  G4ThreeVector bwp(tbwp.x(), tbwp.y(), tbwp.z());
42  */
43 
44  TVector3 wireLine = fwp - bwp;
45  TVector3 hitLine = posOut - posIn;
46 
47  TVector3 hitXwire = hitLine.Cross(wireLine);
48  TVector3 wire2hit = fwp - posOut;
49 
50  //----------------------------------------------------------------
51  // Hitposition is the position on hit line where closest approach
52  // of two lines, but it may out the area from posIn to posOut
53  //----------------------------------------------------------------
54  if (hitXwire.Mag() == 0) {
55  distance = wireLine.Cross(wire2hit).Mag() / wireLine.Mag();
56  hitPosition = posIn;
57  t2 = (posIn - fwp).Dot(wireLine) / wireLine.Mag2();
58  } else {
59  double t1 = hitXwire.Dot(wire2hit.Cross(wireLine)) / hitXwire.Mag2();
60  hitPosition = posOut + t1 * hitLine;
61  t2 = hitXwire.Dot(wire2hit.Cross(hitLine)) / hitXwire.Mag2();
62 
63  //should not constrain hitPosition inside the cell
64  // double dInOut = (posOut - posIn).Mag();
65  // double dHitIn = (hitPosition - posIn).Mag();
66  // double dHitOut = (hitPosition - posOut).Mag();
67  // if (dHitIn <= dInOut && dHitOut <= dInOut) { //Between point in & out
68  distance = fabs(wire2hit.Dot(hitXwire) / hitXwire.Mag());
69  /*
70  } else if (dHitOut > dHitIn) { // out posIn
71  distance = wireLine.Cross(posIn - fwp).Mag() / wireLine.Mag();
72  hitPosition = posIn;
73  t2 = (posIn - fwp).Dot(wireLine) / wireLine.Mag2();
74  } else { // out posOut
75  distance = wireLine.Cross(posOut - fwp).Mag() / wireLine.Mag();
76  hitPosition = posOut;
77  t2 = (posOut - fwp).Dot(wireLine) / wireLine.Mag2();
78  }
79  */
80  }
81 
82  wirePosition = fwp + t2 * wireLine;
83  return distance;
84  }
85 
86  }
88 }
Belle2::CDC::ClosestApproach
double ClosestApproach(const TVector3 &bwp, const TVector3 &fwp, const TVector3 &posIn, const TVector3 &posOut, TVector3 &hitPosition, TVector3 &wirePosition)
Returns a closest distance between a track and a wire.
Definition: ClosestApproach.cc:27
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19