CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MultiProngTauSolver.cc
Go to the documentation of this file.
1 /* From SimpleFits Package
2  * Designed an written by
3  * author: Ian M. Nugent
4  * Humboldt Foundations
5  */
7 #include <iostream>
8 #include "TMatrixTSym.h"
9 
10 using namespace tauImpactParameter;
11 
12 void MultiProngTauSolver::quadratic(double& x_plus,double& x_minus,double a, double b, double c){
13  double R=b*b-4*a*c;
14  if(R<0){R=0;}
15  x_minus=(-b+sqrt(R))/(2.0*a); // opposite sign is smaller
16  x_plus=(-b-sqrt(R))/(2.0*a);
17 }
18 
19 void MultiProngTauSolver::analyticESolver(TLorentzVector& nu_plus,TLorentzVector& nu_minus, const TLorentzVector& A1){
20  double a=(A1.Pz()*A1.Pz())/(A1.E()*A1.E())-1.0;
21  double K=(PDGInfo::tau_mass()*PDGInfo::tau_mass()-A1.M2()-2.0*A1.Pt()*A1.Pt())/(2.0*A1.E());
22  double b=2.0*K*A1.Pz()/A1.E();
23  double c=K*K-A1.Pt()*A1.Pt();
24  double z_plus(0),z_minus(0);
25  quadratic(z_plus,z_minus,a,b,c);
26  nu_plus.SetPxPyPzE(-A1.Px(),-A1.Py(),z_plus,sqrt(z_plus*z_plus+A1.Pt()*A1.Pt()));
27  nu_minus.SetPxPyPzE(-A1.Px(),-A1.Py(),z_minus,sqrt(z_minus*z_minus+A1.Pt()*A1.Pt()));
28 }
29 
30 void MultiProngTauSolver::numericalESolver(TLorentzVector& nu_plus,TLorentzVector& nu_minus, const TLorentzVector& A1){
31  double rmin(-100), rmax(100), step(0.01), mtau2(PDGInfo::tau_mass()*PDGInfo::tau_mass()), z1(-999), z2(-999), zmin(-999), min(9999), prev(9999);
32  double z=rmin;
33  TLorentzVector nu,tau;
34  for(int i=0;i<=(int)(rmax-rmin)/step;i++){
35  nu.SetPxPyPzE(-A1.Px(),-A1.Py(),z,sqrt(z*z+A1.Pt()*A1.Pt()));
36  tau=A1+nu;
37  double m2=tau.M2();
38  if(m2-mtau2<0 && prev-mtau2>=0) z1=z;
39  if(m2-mtau2>0 && prev-mtau2<=0) z2=z;
40  if(min>m2){ zmin=z; min=m2;}
41  prev=m2;
42  z+=step;
43  }
44  if(z1!=-999 && z2!=-999){
45  nu_plus.SetPxPyPzE(-A1.Px(),-A1.Py(),z1,sqrt(z1*z1+A1.Pt()*A1.Pt()));
46  nu_minus.SetPxPyPzE(-A1.Px(),-A1.Py(),z2,sqrt(z2*z2+A1.Pt()*A1.Pt()));
47  }
48  else{
49  nu_plus.SetPxPyPzE(-A1.Px(),-A1.Py(),zmin,sqrt(zmin*zmin+A1.Pt()*A1.Pt()));
50  nu_minus.SetPxPyPzE(-A1.Px(),-A1.Py(),zmin,sqrt(zmin*zmin+A1.Pt()*A1.Pt()));
51  }
52 }
53 
54 void MultiProngTauSolver::solveByRotation(const TVector3& TauDir,const TLorentzVector& A1, TLorentzVector& Tau_plus,TLorentzVector& Tau_minus,
55  TLorentzVector& nu_plus,TLorentzVector& nu_minus, bool rotateback){
56  TLorentzVector A1rot=A1;
57  double phi(TauDir.Phi()),theta(TauDir.Theta());
58  A1rot.RotateZ(-phi);
59  A1rot.RotateY(-theta);
61  // numericalESolver(nu_plus,nu_minus,A1rot); // for debugging AnalyticESolver (slow)
62  //analyticESolver(nu_plus,nu_minus,A1rot);
63  analyticESolver(nu_plus,nu_minus,A1rot);
65  if(rotateback){
66  nu_plus.RotateY(theta);
67  nu_plus.RotateZ(phi);
68  Tau_plus=A1+nu_plus;
69  //
70  nu_minus.RotateY(theta);
71  nu_minus.RotateZ(phi);
72  Tau_minus=A1+nu_minus;
73  }
74  else{
75  Tau_plus=A1rot+nu_plus;
76  Tau_minus=A1rot+nu_minus;
77  }
78 }
79 
80 bool MultiProngTauSolver::setTauDirectionatThetaGJMax(const TLorentzVector& a1, double& theta,double& phi,double scale){
81  double thetaGJMax_a1 =thetaGJMax(a1);
82  double dtheta=(theta-a1.Theta());
83  double dphi=fmod(fabs(phi-a1.Phi()),2*TMath::Pi());if(phi<a1.Phi())dphi*=-1.0;
84  double dphitheta=sqrt(dtheta*dtheta+dphi*dphi);
85  if(thetaGJMax_a1<dphitheta || scale<0){
86  theta=a1.Theta()+dtheta*(thetaGJMax_a1/dphitheta)*fabs(scale);
87  phi=a1.Phi()+dphi*(thetaGJMax_a1/dphitheta)*fabs(scale);
88  return true;
89  }
90  return false;
91 }
92 
93 double MultiProngTauSolver::thetaGJMax(const TLorentzVector& a1){
94  return asin(( PDGInfo::tau_mass()*PDGInfo::tau_mass()-a1.M2())/(2.0*PDGInfo::tau_mass()*fabs(a1.P())));
95 }
96 
97 LorentzVectorParticle MultiProngTauSolver::estimateNu(const LorentzVectorParticle& a1, const TVector3& pv, int ambiguity, TLorentzVector& tau){
98  TLorentzVector lorentzA1=a1.p4();
99  TVector3 sv=a1.vertex();
100  TVector3 tauFlghtDir=sv-pv;
101  TLorentzVector nuGuess;
102 
103  TVector3 startingtauFlghtDir=tauFlghtDir.Unit();
104  if(ambiguity==zero){
105  double theta=tauFlghtDir.Theta();
106  double phi=tauFlghtDir.Phi();
107  setTauDirectionatThetaGJMax(lorentzA1,theta,phi);
108  startingtauFlghtDir.SetMagThetaPhi(1.0,theta,phi);
109  }
110  TLorentzVector tau1,tau2,nu1,nu2;
111  solveByRotation(startingtauFlghtDir,lorentzA1,tau1,tau2,nu1,nu2);
112  if(ambiguity==plus){ nuGuess=nu1; tau=tau1; }
113  if(ambiguity==minus){ nuGuess=nu2; tau=tau1; }
114  if(ambiguity==zero){ nuGuess=nu1; tau=tau1; }
115  TVectorT<double> par(LorentzVectorParticle::NLorentzandVertexPar,10);
119  par(LorentzVectorParticle::px)=nuGuess.Px();
120  par(LorentzVectorParticle::py)=nuGuess.Py();
121  par(LorentzVectorParticle::pz)=nuGuess.Pz();
122  par(LorentzVectorParticle::m) =nuGuess.M();
123  TMatrixTSym<double> Cov(LorentzVectorParticle::NLorentzandVertexPar);
124  TMatrixTSym<double> pvCov=a1.vertexCov();
126  for(int j=0; j<=i; j++){
127  if(i<LorentzVectorParticle::NVertex) Cov(i,j)=pvCov(i,j);
128  else Cov(i,j)=0;
129  }
130  double v=0;
132  if(v<1000.0) v=1000.0; // try lowing to test impact
133  Cov(i,i)+=v;
134  }
135  return LorentzVectorParticle(par,Cov,PDGInfo::nu_tau,0,a1.bField());
136 }
137 
138 TVectorT<double> MultiProngTauSolver::rotateToTauFrame(const TVectorT<double>& inpar){
139  TVectorT<double> outpar(3);
140  TVector3 res(inpar(0),inpar(1),inpar(2));
141  TVector3 Uz;Uz.SetMagThetaPhi(1,inpar(4),inpar(3));
142  res.RotateUz(Uz);
143  outpar(0)=res.X();
144  outpar(1)=res.Y();
145  outpar(2)=res.Z();
146  return outpar;
147 }
TMatrixTSym< double > vertexCov() const
const double Pi
int i
Definition: DBlmapReader.cc:9
static TVectorT< double > rotateToTauFrame(const TVectorT< double > &inpar)
Geom::Theta< T > theta() const
static void analyticESolver(TLorentzVector &nu_plus, TLorentzVector &nu_minus, const TLorentzVector &A1)
static bool setTauDirectionatThetaGJMax(const TLorentzVector &a1, double &theta, double &phi, double scale=1.0)
static double thetaGJMax(const TLorentzVector &a1)
static void numericalESolver(TLorentzVector &nu_plus, TLorentzVector &nu_minus, const TLorentzVector &A1)
float float float z
static void quadratic(double &x_plus, double &x_minus, double a, double b, double c)
T sqrt(T t)
Definition: SSEVec.h:48
static LorentzVectorParticle estimateNu(const LorentzVectorParticle &a1, const TVector3 &pv, int ambiguity, TLorentzVector &tau)
int j
Definition: DBlmapReader.cc:9
static void solveByRotation(const TVector3 &TauDir, const TLorentzVector &A1, TLorentzVector &Tau_plus, TLorentzVector &Tau_minus, TLorentzVector &nu_plus, TLorentzVector &nu_minus, bool rotateback=true)
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
virtual double bField() const
Definition: Particle.h:26
static double tau_mass()
Definition: PDGInfo.h:14
Definition: DDAxes.h:10