FairRoot/PandaRoot
Public Member Functions | Private Member Functions | List of all members
RhoVtxPoca Class Reference

#include <RhoVtxPoca.h>

Public Member Functions

 RhoVtxPoca ()
 
virtual ~RhoVtxPoca ()
 
Double_t GetPocaVtx (TVector3 &vertex, RhoCandidate *composite)
 
Double_t GetPocaVtx (TVector3 &vertex, RhoCandList &cands)
 

Private Member Functions

Double_t GetPoca (TVector3 &vertex, RhoCandidate *a, RhoCandidate *b)
 
Double_t GetPocaTwoCharged (TVector3 &vertex, RhoCandidate *a, RhoCandidate *b)
 
Double_t GetPocaChargedToNeutral (TVector3 &vertex, RhoCandidate *a, RhoCandidate *b)
 
Double_t GetPocaTwoNeutral (TVector3 &vertex, RhoCandidate *a, RhoCandidate *b)
 

Detailed Description

Definition at line 17 of file RhoVtxPoca.h.

Constructor & Destructor Documentation

RhoVtxPoca::RhoVtxPoca ( )

Definition at line 19 of file RhoVtxPoca.cxx.

20 {
21 }
RhoVtxPoca::~RhoVtxPoca ( )
virtual

Definition at line 23 of file RhoVtxPoca.cxx.

24 {
25 }

Member Function Documentation

Double_t RhoVtxPoca::GetPoca ( TVector3 &  vertex,
RhoCandidate a,
RhoCandidate b 
)
private

Definition at line 90 of file RhoVtxPoca.cxx.

References RhoCandidate::Charge(), and fabs().

91 {
92  // Decide which POCA algorithm to use
93 
94  if (fabs(a->Charge())>1e-6 && fabs(b->Charge())>1e-6) return GetPocaTwoCharged(vertex, a, b);
95  else if (fabs(a->Charge())<1e-6 && fabs(b->Charge())<1e-6) return GetPocaTwoNeutral(vertex, a, b);
96  else if (fabs(a->Charge())<1e-6 || fabs(b->Charge())<1e-6) return GetPocaChargedToNeutral(vertex, a, b);
97  else return -99999.;
98 }
Double_t GetPocaChargedToNeutral(TVector3 &vertex, RhoCandidate *a, RhoCandidate *b)
Definition: RhoVtxPoca.cxx:206
Double_t GetPocaTwoCharged(TVector3 &vertex, RhoCandidate *a, RhoCandidate *b)
Definition: RhoVtxPoca.cxx:100
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
Double_t GetPocaTwoNeutral(TVector3 &vertex, RhoCandidate *a, RhoCandidate *b)
Definition: RhoVtxPoca.cxx:321
Double_t Charge() const
Definition: RhoCandidate.h:184
Double_t RhoVtxPoca::GetPocaChargedToNeutral ( TVector3 &  vertex,
RhoCandidate a,
RhoCandidate b 
)
private

Definition at line 206 of file RhoVtxPoca.cxx.

References a, b, best, RhoCandidate::Charge(), Double_t, fabs(), RhoCalculationTools::GetBz(), RhoCandidate::GetPosition(), RhoCandidate::P3(), r1, and CAMath::Sqrt().

207 {
208  // POCA Approxiamtion for a helix with a line
209  // Fist mtching in x-y projection, then choose one solution in z
210  // by the smallest distance.
211 
212  RhoCandidate* charged;
213  RhoCandidate* neutral;
214  if (fabs(a->Charge())<1e-6 && fabs(b->Charge())>1e-6){
215  charged=b;
216  neutral=a;
217  } else if (fabs(a->Charge())>1e-6 && fabs(b->Charge())<1e-6){
218  charged=a;
219  neutral=b;
220  } else return -99999.;
221 
222  vertex.SetXYZ(0.,0.,0.);
223  Double_t bField = 0.1*RhoCalculationTools::GetBz(vertex); // T, assume field in z only
224  Double_t bc = 0.0029979246*bField;
225  TVector3 dB(0,0,1.0);
226  TVector3 position1 = charged->GetPosition();
227  // Momentum vectors
228  TVector3 ap3 = charged->P3();
229  Double_t pPerp1 = ap3.Perp();
230  TVector3 d1 = ap3;
231  d1.SetZ(0);
232  d1*=1.0/pPerp1;
233 
234  // Radius and center
235  Double_t rho1 = pPerp1/bc; // Radius in cm
236  TVector3 r1=d1.Cross(dB);
237  r1 *= -charged->Charge()*rho1;
238  TVector3 center1 = position1 - r1;
239  center1.SetZ(0);
240 
241  TVector3 position2 = neutral->GetPosition();
242 
243  // Momentum vectors
244  TVector3 bp3 = neutral->P3();
245  Double_t pPerp2 = bp3.Perp();
246  TVector3 d2 = bp3;
247  d2.SetZ(0);
248  d2*=1.0/pPerp2; //direction of neutral
249  TVector3 g_p = position2;
250  g_p.SetZ(0);
251  TVector3 c_to_g = (center1.Dot(d2) - g_p.Dot(d2))*d2 + g_p - center1; //vector pointing from center1 to the neutral
252 
253  Int_t nSolMax=1;
254  TVector3 newapos[2];
255  TVector3 newbpos[2];
256  if(c_to_g.Mag()<rho1)
257  {
258  newapos[0].SetZ(0.);
259  newapos[1].SetZ(0.);
260  nSolMax=2;
261 
262  newapos[0] = center1 + TMath::Sqrt(rho1*rho1 - (c_to_g.Dot(c_to_g)))*d2 + c_to_g;
263  newapos[1] = center1 - TMath::Sqrt(rho1*rho1 - (c_to_g.Dot(c_to_g)))*d2 + c_to_g;
264  newbpos[0] = center1 + TMath::Sqrt(rho1*rho1 - (c_to_g.Dot(c_to_g)))*d2 + c_to_g;
265  newbpos[1] = center1 - TMath::Sqrt(rho1*rho1 - (c_to_g.Dot(c_to_g)))*d2 + c_to_g;
266 
267  TVector3 rs1 = newapos[0] - center1;
268  // are we moving forward or backward?
269  Double_t adir=(rs1-r1).Dot(ap3)>0 ? 1.0 : -1.0;
270  Double_t aangle=adir * r1.Angle(rs1);
271  newapos[0].SetZ(position1.Z() + rho1*aangle/pPerp1 * ap3.Z());
272 
273  rs1 = newapos[1] - center1;
274  // are we moving forward or backward?
275  adir=(rs1-r1).Dot(ap3)>0 ? 1.0 : -1.0;
276  aangle=adir * r1.Angle(rs1);
277  newapos[1].SetZ(position1.Z() + rho1*aangle/pPerp1 * ap3.Z());
278 
279  // are we moving forward or backward?
280  adir = bp3.Dot(newbpos[0] - position2)>0 ? 1.0 : -1.0;
281  TVector3 length = newbpos[0] - g_p;
282  newbpos[0].SetZ(position2.Z() + length.Mag() * adir * bp3.Z()/pPerp2);
283  adir = bp3.Dot(newbpos[1] - position2)>0 ? 1.0 : -1.0;
284  length = newbpos[1] - g_p;
285  newbpos[1].SetZ(position2.Z() + length.Mag() * adir * bp3.Z()/pPerp2);
286  }
287  else
288  {
289  nSolMax=1;
290  newapos[0] = 0.5*(c_to_g*(rho1/c_to_g.Mag()) + center1 + g_p);
291  newbpos[0] = 0.5*(c_to_g*(rho1/c_to_g.Mag()) + center1 + g_p);
292 
293  TVector3 rs1 = newapos[0] - center1;
294  // are we moving forward or backward?
295  Double_t adir=(rs1-r1).Dot(ap3)>0 ? 1.0 : -1.0;
296  Double_t aangle=adir * r1.Angle(rs1);
297  newapos[0].SetZ(position1.Z() + rho1*aangle/pPerp1 * ap3.Z());
298 
299  // are we moving forward or backward?
300  adir = bp3.Dot(newbpos[0] - position2)>0 ? 1.0 : -1.0;
301  TVector3 length = newbpos[0] - g_p;
302  newbpos[0].SetZ(position2.Z() + length.Mag() * adir * bp3.Z()/pPerp2);
303  }
304 
305 
306  Int_t best=0;
307  Double_t actualDoca=1.E8;
308  for(int ns=0; ns<nSolMax; ns++){
309  Double_t delta = (newapos[ns]-newbpos[ns]).Mag();
310  // take the solution of minimal deltaZ
311  if ( delta < actualDoca ) {
312  best=ns;
313  actualDoca = delta;
314  }
315  }
316 
317  vertex=0.5*(newapos[best]+newbpos[best]);
318  return actualDoca;
319 }
TTree * b
static T Sqrt(const T &x)
Definition: PndCAMath.h:37
double r1
Int_t a
Definition: anaLmdDigi.C:126
TVector3 GetPosition() const
Definition: RhoCandidate.h:185
Double_t
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
static Double_t GetBz(const TVector3 &position)
Return the magnetic field along the z-axis in kGs
Double_t Charge() const
Definition: RhoCandidate.h:184
TVector3 P3() const
Definition: RhoCandidate.h:199
Double_t RhoVtxPoca::GetPocaTwoCharged ( TVector3 &  vertex,
RhoCandidate a,
RhoCandidate b 
)
private

Definition at line 100 of file RhoVtxPoca.cxx.

References best, RhoCandidate::Charge(), Double_t, RhoCalculationTools::GetBz(), RhoCandidate::GetPosition(), RhoCandidate::P3(), r1, r2, sign(), sqrt(), x, and y.

101 {
102  // Calculate an approximate POCA for two helices.
103  // First in 2D (x-y projection), then select best solution by minimum z distance
104 
105  vertex.SetXYZ(0.,0.,0.);
106  Double_t bField = 0.1*RhoCalculationTools::GetBz(vertex); // T, assume field in z only
107  Double_t bc = 0.0029979246*bField;
108  TVector3 dB(0,0,1.0);
109  TVector3 position1 = a->GetPosition();
110  // Momentum vectors
111  TVector3 ap3 = a->P3();
112  Double_t pPerp1 = ap3.Perp();
113  TVector3 d1 = ap3;
114  d1.SetZ(0);
115  d1*=1.0/pPerp1;
116 
117  // Radius and center
118  Double_t rho1 = pPerp1/bc; // Radius in cm
119  TVector3 r1=d1.Cross(dB);
120  r1 *= -a->Charge()*rho1;
121  TVector3 center1 = position1 - r1;
122  center1.SetZ(0);
123 
124  TVector3 position2 = b->GetPosition();
125 
126  // Momentum vectors
127  TVector3 bp3 = b->P3();
128  Double_t pPerp2 = bp3.Perp();
129  TVector3 d2 = bp3;
130  d2.SetZ(0);
131  d2*=1.0/pPerp2;
132 
133  // Radius and center
134  Double_t rho2 = pPerp2/bc; // Radius in cm
135  TVector3 r2=d2.Cross(dB);
136  r2 *= -b->Charge()*rho2;
137  TVector3 center2 = position2 - r2;
138  center2.SetZ(0);
139 
140  // distance and angle of the axis between the two centers
141  TVector3 ab = center2 - center1;
142  Double_t dab = ab.Perp();
143  Double_t cosTheAB = ab.X()/dab;
144  Double_t sinTheAB = ab.Y()/dab;
145 
146  Double_t darr = dab;
147  darr -= rho1;
148  darr -= rho2;
149 
150  // both circles do not intersect (only one solution)
151  Int_t nSolMax=1;
152  Double_t x=0;
153  Double_t y=0;
154  if (darr < 0) {
155  // sum of radii is smaller than the two centers distance, circles intersect at two points
156  nSolMax=2;
157  // x value of intersect at reduced system
158  x = 0.5*dab + ( rho1*rho1 - rho2*rho2 )/(2*dab);
159  // y*y value of intersect at reduced system for helix A
160  Double_t y2 = (rho1+x)*(rho1-x);
161  if (y2 > 0) { y = sqrt(y2); }
162  } else {
163  // no intersecting circles, take the mid point between both circles
164  x = 0.5*(dab + rho1 - rho2);
165  }
166  // now we compute the solution(s)
167  TVector3 newapos[2];
168  TVector3 newbpos[2];
169  Int_t best=0;
170  Double_t actualDoca=1.E8;
171  for (Int_t ns=0; ns<nSolMax; ns++) { // loop on the solutions
172  // radius vector of intersection point
173  Double_t sign = ns ? 1.0 : -1.0;
174  TVector3 rs1( cosTheAB*x - sinTheAB*y * sign, sinTheAB*x + cosTheAB*y * sign, 0);
175  TVector3 rs2( rs1-ab );
176 
177  // are we moving forward or backward?
178  Double_t adir=(rs1-r1).Dot(ap3)>0 ? 1.0 : -1.0;
179  Double_t aangle=adir * r1.Angle(rs1);
180  // intersection point
181  Double_t newaz=position1.Z() + rho1*aangle/pPerp1 * ap3.Z();
182  newapos[ns].SetX( center1.X() + rs1.X() );
183  newapos[ns].SetY( center1.Y() + rs1.Y() );
184  newapos[ns].SetZ( newaz );
185 
186  // same for b
187  Double_t bdir=(rs2-r2).Dot(bp3)>0 ? 1.0 : -1.0;
188  Double_t bangle=bdir * r2.Angle(rs2);
189  Double_t newbz=position2.Z() + rho2*bangle/pPerp2 * bp3.Z();
190  newbpos[ns].SetX( center2.X() + rs2.X()); // ==newapos[ns].X()
191  newbpos[ns].SetY( center2.Y() + rs2.Y()); // ==newapos[ns].Y()
192  newbpos[ns].SetZ( newbz );
193 
194  Double_t delta = (newapos[ns]-newbpos[ns]).Mag();
195 
196  // take the solution of minimal deltaZ
197  if ( delta < actualDoca ) {
198  best=ns;
199  actualDoca = delta;
200  }
201  }
202  vertex=0.5*(newapos[best]+newbpos[best]);
203  return actualDoca;
204 }
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
double r1
TVector3 GetPosition() const
Definition: RhoCandidate.h:185
Double_t
Double_t x
static Double_t GetBz(const TVector3 &position)
Return the magnetic field along the z-axis in kGs
Double_t Charge() const
Definition: RhoCandidate.h:184
int sign(T val)
Definition: PndCADef.h:48
Double_t y
double r2
TVector3 P3() const
Definition: RhoCandidate.h:199
Double_t RhoVtxPoca::GetPocaTwoNeutral ( TVector3 &  vertex,
RhoCandidate a,
RhoCandidate b 
)
private

Definition at line 321 of file RhoVtxPoca.cxx.

References a, b, bp, c, d, RhoCandidate::GetPosition(), RhoCandidate::P3(), and v.

322  {
323  // This is the exact(!) skewed line POCA
324  //
325 
326  vertex.SetXYZ(0.,0.,0.);
327 
328  TVector3 av = canda->GetPosition();
329  TVector3 ap = canda->P3();
330 
331  TVector3 bv = candb->GetPosition();
332  TVector3 bp = candb->P3();
333 
334  TVector3 u = ap.Unit();
335  TVector3 v = bp.Unit();
336  TVector3 w = av - bv;
337  double a = u.Mag(); //dot(u,u); // always >= 0
338  double b = u.Dot(v); //dot(u,v);
339  double c = v.Mag(); //dot(v,v); // always >= 0
340  double d = u.Dot(w); //dot(u,w);
341  double e = v.Dot(w); //dot(v,w);
342  double D = a*c - b*b; // always >= 0
343  double sc, tc;
344 
345  // compute the line parameters of the two closest points
346  if (D < 1e-9) { // the lines are almost parallel
347  sc = 0.0;
348  tc = (b>c ? d/b : e/c); // use the largest denominator
349  }
350  else {
351  sc = (b*e - c*d) / D; //determination of s in g: x1 = av + s*ap
352  tc = (a*e - b*d) / D; //determination of t in h: x2 = bv + t*bp
353  //using (x1-x2)*u = 0 and (x1-x2)*v = 0
354  }
355 
356  // get the difference of the two closest points
357  //TVector3 dP = w + (sc * u) - (tc * v); // = L1(sc) - L2(tc)
358  TVector3 pocaa = av + sc*u;
359  TVector3 pocab = bv + tc*v;
360  vertex = 0.5*(pocaa+pocab);
361  TVector3 diff = pocaa-pocab;
362 
363  return diff.Mag(); // return the closest distance
364 
365  }
TObjArray * d
TTree * b
__m128 v
Definition: P4_F32vec4.h:4
TF1 * bp
Definition: hist-t7.C:69
Double_t RhoVtxPoca::GetPocaVtx ( TVector3 &  vertex,
RhoCandidate composite 
)

Definition at line 27 of file RhoVtxPoca.cxx.

References RhoCandidate::Daughter(), i, RhoCandidate::NDaughters(), and RhoCandList::Put().

Referenced by RhoKinVtxFitter::Compute(), RhoKinHyperonVtxFitter::Compute(), PndPmtTask::Exec(), PndTutAnaTaskD0::Exec(), PndSoftTriggerTask::Exec(), PndSoftTriggerTask::GetPocaVtx(), poormantracks(), PndRhoTupleQA::qaPoca(), PndRhoTupleQA::qaVtx(), run_ana_mertens_evt7(), and tut_ana_d0().

28 {
29  RhoCandList cands;
30 
31  for (int i=0;i<composite->NDaughters();++i) cands.Put(composite->Daughter(i));
32 
33  return GetPocaVtx(vertex, cands);
34 }
Int_t i
Definition: run_full.C:25
RhoCandidate * Daughter(Int_t n)
Double_t GetPocaVtx(TVector3 &vertex, RhoCandidate *composite)
Definition: RhoVtxPoca.cxx:27
Int_t NDaughters() const
void Put(const RhoCandidate *, Int_t i=-1)
Definition: RhoCandList.cxx:77
Double_t RhoVtxPoca::GetPocaVtx ( TVector3 &  vertex,
RhoCandList cands 
)

Definition at line 36 of file RhoVtxPoca.cxx.

References a, b, Double_t, RhoCandList::GetLength(), and printf().

37 {
38  vertex.SetXYZ(0.,0.,0.);
39  if ( cands.GetLength() < 2 ) { return -99999.; }
40  if ( cands.GetLength() == 2 ) { return GetPoca(vertex, cands[0], cands[1]); }
41 
42  std::vector<Double_t> distances;
43  std::vector<TVector3> results;
44  // loop over daughters, take the mean value of all "best" positions
45  // TODO do this smarter by using already found vertices ?
46  TVector3 theVertex(0.,0.,0.);
47  Double_t actualDoca=0.;
48 
49  for(Int_t daug1 =0; daug1<cands.GetLength(); daug1++)
50  {
51  RhoCandidate* a=cands[daug1];
52 
53  for(Int_t daug2=daug1+1; daug2<cands.GetLength(); daug2++)
54  {
55  RhoCandidate* b=cands[daug2];
56 
57  actualDoca = GetPoca(theVertex,a,b);
58  if(actualDoca < 0)
59  {
60  printf("RhoVtxPoca - Error with getting a POCA. \"Distance\" is %g. SKIPPING Candidate pair now!",actualDoca);
61  continue;
62  }
63  distances.push_back(actualDoca);
64  results.push_back(theVertex);
65  }//daug2
66  }//daug1
67 
68  // Averaging vertex results from each track pair, weighted with 1/distance
69  std::vector<Double_t>::iterator iterDoca;
70  std::vector<TVector3>::iterator iterVtx;
71  Double_t docaweight=0,sumdocaweigts=0;
72  TVector3 vertexK;
73  for(iterVtx=results.begin(), iterDoca=distances.begin(); iterVtx!=results.end()&&iterDoca!=distances.end(); ++iterVtx,++iterDoca)
74  {
75  docaweight=1/(*iterDoca);
76  //docaweight *= docaweight;
77  vertexK=*iterVtx;
78  if (docaweight == 0) { docaweight = 1; } // right so?
79  vertexK *= docaweight;
80  vertex+=vertexK;
81  sumdocaweigts+=docaweight;
82  }
83  if (sumdocaweigts == 0) { sumdocaweigts=1; }
84  vertex*=1./sumdocaweigts;
85  //sumdocaweigts = sqrt(sumdocaweigts);
86  return cands.GetLength()/sumdocaweigts;
87 
88 }
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
Double_t GetPoca(TVector3 &vertex, RhoCandidate *a, RhoCandidate *b)
Definition: RhoVtxPoca.cxx:90
TTree * b
Int_t GetLength() const
Definition: RhoCandList.h:46
Int_t a
Definition: anaLmdDigi.C:126
Double_t

The documentation for this class was generated from the following files: