FairRoot/PandaRoot
RhoSimpleVertexSelector.cxx
Go to the documentation of this file.
1 // //
3 // RhoSimpleVertexSelector //
4 // //
5 // Selector class to estimate the geometric intersection of two tracks //
6 // Intended to provide the initial vertex position for V0 fits //
7 // //
8 // Author List: //
9 // Marcel Kunze, RUB, Feb. 99 //
10 // Copyright (C) 1999-2001, Ruhr-University Bochum. //
11 // Ralf Kliemt, HIM/GSI Feb.2013 (Cleanup & Restructuring) //
12 // //
14 
16 #include "RhoBase/RhoCandidate.h"
17 #include "FairRun.h"
18 #include "FairRunSim.h"
19 #include "FairRunAna.h"
20 #include "FairField.h"
21 
23 
24 TBuffer& operator>> ( TBuffer& buf, RhoSimpleVertexSelector *&obj )
25 {
26  obj = ( RhoSimpleVertexSelector* ) buf.ReadObject ( RhoSimpleVertexSelector::Class() );
27  return buf;
28 }
29 
30 #include <iostream>
31 using namespace std;
32 
34  RhoVertexSelectorBase ( name ) //, fQC(0)
35 {
36  fDoca = d;
37  fVtxip = a;
38  fRmin = r1;
39  fRmax = r2;
40 }
41 
43 
45 {
46  if ( &a==0 || &b==0 ) { return kFALSE; }
47 
48  // Position vectors
49  TVector3 position1 = a.GetPosition();
50  TVector3 position2 = b.GetPosition();
51 
52  double pnt[3], Bf[3];
53  pnt[0]=0.5* ( position1.X() +position2.X() );
54  pnt[1]=0.5* ( position1.Y() +position2.Y() );
55  pnt[2]=0.5* ( position1.Z() +position2.Z() );
56  if(FairRun::Instance()->IsAna()){
57  FairRunAna::Instance()->GetField()->GetFieldValue ( pnt, Bf ); //[kGs]
58  } else{
59  FairRunSim::Instance()->GetField()->GetFieldValue ( pnt, Bf ); //[kGs]
60  }
61  Float_t bField = Bf[2]; // Retrieve the B-Field
62 
63  // Momentum vectors
64  TVector3 ap3 = a.P3();
65  Double_t pPerp1 = ap3.Perp();
66  TVector3 d1 = ap3;
67  d1.SetZ ( 0 );
68  d1*=1.0/pPerp1;
69 
70  TVector3 bp3 = b.P3();
71  Double_t pPerp2 = bp3.Perp();
72  TVector3 d2 = bp3;
73  d2.SetZ ( 0 );
74  d2*=1.0/pPerp2;
75 
76 
77  TVector3 dB ( 0,0,1.0 );
78  // Radius and center
79  Double_t rho1 = 100. * pPerp1/ ( 0.3*bField ); // Radius in cm //FIXME really?
80  TVector3 r1=d1.Cross ( dB );
81  r1 *= -a.Charge() *rho1;
82  TVector3 center1 = position1 - r1;
83  center1.SetZ ( 0 );
84 
85  Double_t rho2 = 100. * pPerp2/ ( 0.3*bField ); // Radius in cm //FIXME really?
86  TVector3 r2=d2.Cross ( dB );
87  r2 *= -b.Charge() *rho2;
88  TVector3 center2 = position2 - r2;
89  center2.SetZ ( 0 );
90 
91  // distance and angle of the axis between the two centers
92  TVector3 ab = center2 - center1;
93  Double_t dab = ab.Perp();
94  Double_t cosTheAB = ab.X() /dab;
95  Double_t sinTheAB = ab.Y() /dab;
96 
97 
98  // x value of intersect at reduced system
99  Double_t x = dab/2 + ( rho1*rho1 - rho2*rho2 ) / ( 2*dab );
100 
101  // y*y value of intersect at reduced system for helix A
102  Double_t y2 = ( rho1+x ) * ( rho1-x );
103 
104  // both circles do not intersect (only one solution)
105  Int_t nSolMax=1;
106  Double_t y=0;
107 
108  if ( y2 > 0 ) {
109  nSolMax=2;
110  y = sqrt ( y2 );
111  } else {
112  //if( fabs(dab-rho1-rho2) > fActualDoca);
113  //return kFALSE;
114  }
115 
116  // now we compute the solution(s)
117 
118  TVector3 newap3[2];
119  TVector3 newbp3[2];
120  TVector3 newapos[2];
121  TVector3 newbpos[2];
122  Int_t best=0;
123  fActualDoca=1.E8;
124  for ( Int_t ns=0; ns<nSolMax; ns++ ) { // loop on the solutions
125 
126  // radius vector of intersection point
127  Double_t sign = ns ? 1.0 : -1.0;
128  TVector3 rs1 ( cosTheAB*x - sinTheAB*y * sign, sinTheAB*x + cosTheAB*y * sign, 0 );
129  TVector3 rs2 ( rs1-ab );
130 
131  // are we moving forward or backward?
132  Double_t adir= ( rs1-r1 ).Dot ( ap3 ) >0 ? 1.0 : -1.0;
133  Double_t aangle=adir * r1.Angle ( rs1 );
134  // intersection point
135  Double_t newaz=position1.Z() + rho1*aangle/pPerp1 * ap3.Z();
136  newapos[ns].SetX ( center1.X() + rs1.X() );
137  newapos[ns].SetY ( center1.Y() + rs1.Y() );
138  newapos[ns].SetZ ( newaz );
139 
140  // adjust momentum
141  newap3[ns]=rs1.Cross ( dB );
142  newap3[ns]*=a.Charge() /rho1*pPerp1;
143  newap3[ns].SetZ ( ap3.Z() );
144 
145 
146  // same for b
147  Double_t bdir= ( rs2-r2 ).Dot ( bp3 ) >0 ? 1.0 : -1.0;
148  Double_t bangle=bdir * r2.Angle ( rs2 );
149  Double_t newbz=position2.Z() + rho2*bangle/pPerp2 * bp3.Z();
150  newbpos[ns].SetX ( center2.X() + rs2.X() ); // ==newapos[ns].X()
151  newbpos[ns].SetY ( center2.Y() + rs2.Y() ); // ==newapos[ns].Y()
152  newbpos[ns].SetZ ( newbz );
153  newbp3[ns]=rs2.Cross ( dB );
154  newbp3[ns]*=b.Charge() /rho2*pPerp2;
155  newbp3[ns].SetZ ( bp3.Z() );
156 
157  Double_t delta = ( newapos[ns]-newbpos[ns] ).Mag();
158 
159  // take the solution of minimal deltaZ
160  if ( delta < fActualDoca ) {
161  best=ns;
162  fActualDoca = delta;
163  }
164  }
165 
166  fVertex=0.5* ( newapos[best]+newbpos[best] );
167  fMomA=newap3[best];
168  fMomB=newbp3[best];
169 
170  // Now reconstruct original flight path and
171  // calculate the angle to vertex-ip
172 
173  TVector3 p=fMomA+fMomB;
174  TVector3 vtxip = fVertex-fPrimaryVertex;
175  fActualVtxip = vtxip.Angle ( p );
176  fActualR = vtxip.Mag();
177 
178  //if (fQC!=0) fQC->Accumulate((Float_t)fActualDoca,(Float_t)fActualVtxip);
179 
180  if ( fActualDoca < fDoca &&
181  fActualR >= fRmin && fActualR < fRmax &&
182  fActualVtxip < fVtxip ) {
183 
184  return kTRUE;
185 
186  } else {
187  fMomA=ap3;
188  fMomB=bp3;
190  return kFALSE;
191  }
192  return kFALSE; //get rid of warnings
193 }
194 
195 /*
196 void TSimpleVertexSelector::ActivateQualityControl()
197 {
198  TPersistenceManager *persmgr = TRho::Instance()->GetPersistenceManager();
199  if (persmgr == 0) {
200  std::cerr << "TVertexSelector: Can not activate QC w/o PersistenceManager." << std::endl;
201  return;
202  }
203 
204  // Make a quality control directory, if needed and cd into it
205 
206  persmgr->SetDir("QC/TVertexSelector");
207  fQC = persmgr->Histogram(GetName(),100,0.0,10.,100,0.0,3.14159265358979323846);
208 }
209 */
TObjArray * d
TTree * b
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
TClonesArray * pnt
double r1
Double_t p
Definition: anasim.C:58
Int_t a
Definition: anaLmdDigi.C:126
TVector3 GetPosition() const
Definition: RhoCandidate.h:185
Double_t
virtual Bool_t Accept(RhoCandidate &a, RhoCandidate &b)
TString name
Double_t x
ClassImp(RhoSimpleVertexSelector) TBuffer &operator>>(TBuffer &buf
Double_t Charge() const
Definition: RhoCandidate.h:184
RhoSimpleVertexSelector *& obj
int sign(T val)
Definition: PndCADef.h:48
Double_t y
RhoSimpleVertexSelector(const char *name="SimpleVertexSelector", Double_t d=1.0, Double_t a=3.14159265358979323846, Double_t r1=0.0, Double_t r2=1.E8)
double r2
TVector3 P3() const
Definition: RhoCandidate.h:199
return buf