9#ifndef FITTER3DUTILITY_H 
   10#define FITTER3DUTILITY_H 
   13#include <Math/Vector4D.h> 
   14#include <Math/Vector3D.h> 
   15#include <Math/Vector2D.h> 
   25  class TRGCDCJSignalData;
 
   40  static void rPhiFit(
double* rr, 
double* phi2, 
double* phierror, 
double& rho, 
double& myphi0);
 
   43  static void rPhiFitter(
double* rr, 
double* phi2, 
double* invphierror, 
double& rho, 
double& myphi0);
 
   46  static void rPhiFitter(
double* rr, 
double* phi2, 
double* invphierror, 
double& rho, 
double& myphi0, 
double& chi2);
 
   49  static void chargeFinder(
double* nTSs, 
double* tsIds, 
double* tsHitmap, 
double phi0, 
double inCharge, 
double& outCharge);
 
   52  static void rPhiFit2(
double* rr, 
double* phi2, 
double* phierror, 
double& rho, 
double& myphi0, 
int nTS);
 
   58  static double calPhi(
double wirePhi, 
double driftLength, 
double rr, 
int lr);
 
   61  static double calPhi(
double wirePhi, 
double driftTime, 
double eventTime, 
double rr, 
int lr);
 
   64  static double calPhi(
int localId, 
int nWires, 
double driftTime, 
double eventTime, 
double rr, 
int lr);
 
   67  static void calPhi(std::map<std::string, double> 
const& mConstD, std::map<std::string, std::vector<double> > 
const& mConstV,
 
   68                     std::map<std::string, Belle2::TRGCDCJSignal>& mSignalStorage, std::map<std::string, Belle2::TRGCDCJLUT* >& mLutStorage);
 
   71  static void saveStereoXt(std::vector<std::vector<double> >& stXts, std::string 
const& filePrefix);
 
   74  static void loadStereoXt(std::string 
const& filePrefix, 
int nFiles, std::vector<std::vector<double> >& stXts);
 
   77  static double stereoIdToPhi(std::vector<double>& stNWires, 
int iSt, 
int id);
 
   80  static void calPhiFast(std::map<std::string, std::vector<double> >& stGeometry, std::vector<std::vector<double> > 
const& stXts,
 
   81                         int eventTimeValid, 
int eventTime, std::vector<std::vector<int> > 
const& rawStTSs, std::vector<double>& stTSs);
 
   84  static double rotatePhi(
double value, 
double refPhi);
 
   87  static double rotatePhi(
double value, 
int refId, 
int nTSs);
 
   90  static int rotateTsId(
int value, 
int refId, 
int nTSs);
 
   96  static void setErrorFast(std::vector<std::vector<int> > 
const& rawStTSs, 
int eventTimeValid, std::vector<double>& invZError2);
 
   99  static void setError(std::map<std::string, double> 
const& mConstD, std::map<std::string, std::vector<double> > 
const& mConstV,
 
  100                       std::map<std::string, Belle2::TRGCDCJSignal>& mSignalStorage);
 
  103  static double calStAxPhi(
int charge, 
double anglest, 
double ztostraw, 
double rr, 
double rho, 
double phi0);
 
  106  static double calDeltaPhi(
int charge, 
double anglest, 
double ztostraw, 
double rr, 
double phi, 
double rho, 
double phi0);
 
  109  static void constrainRPerStSl(std::map<std::string, std::vector<double> > 
const& mConstV,
 
  110                                std::map<std::string, Belle2::TRGCDCJSignal>& mSignalStorage);
 
  113  static double calZ(
int charge, 
double anglest, 
double ztostraw, 
double rr, 
double phi, 
double rho, 
double phi0);
 
  116  static void calZ(std::map<std::string, double> 
const& mConstD, std::map<std::string, std::vector<double> > 
const& mConstV,
 
  117                   std::map<std::string, Belle2::TRGCDCJSignal>& mSignalStorage, std::map<std::string, Belle2::TRGCDCJLUT* >& mLutStorage);
 
  120  static double calS(
double rho, 
double rr);
 
  123  static void calS(std::map<std::string, double> 
const& mConstD, std::map<std::string, std::vector<double> > 
const& mConstV,
 
  124                   std::map<std::string, Belle2::TRGCDCJSignal>& mSignalStorage, std::map<std::string, Belle2::TRGCDCJLUT* >& mLutStorage);
 
  127  static double calIZError2(
int lr, 
double driftZError, 
double wireZError);
 
  130  static double calDen(
double* arcS, 
double* zError);
 
  137  static void rSFit(
double* iezz2, 
double* arcS, 
double* zz, 
double& z0, 
double& cot, 
double& zchi2);
 
  140  static void rSFit2(
double* iezz21, 
double* iezz22, 
double* arcS, 
double* zz, 
int* lutv,  
double& z0, 
double& cot, 
double& zchi2);
 
  143  static void rSFit(std::map<std::string, double> 
const& mConstD, std::map<std::string, std::vector<double> > 
const& mConstV,
 
  144                    std::map<std::string, Belle2::TRGCDCJSignal>& mSignalStorage, std::map<std::string, Belle2::TRGCDCJLUT* >& mLutStorage);
 
  147  static void fitter3D(std::map<std::string, std::vector<double> >& stGeometry, std::vector<std::vector<double> > 
const& stXts,
 
  148                       int eventTimeValid, 
int eventTime,
 
  149                       std::vector<std::vector<int> > 
const& rawStTSs,
 
  150                       int charge, 
double radius, 
double phi_c, 
double& z0, 
double& cot, 
double& chi2);
 
  152  static void fitter3D(std::map<std::string, std::vector<double> >& stGeometry, std::vector<std::vector<double> > 
const& stXts,
 
  153                       int eventTimeValid, 
int eventTime,
 
  154                       std::vector<std::vector<int> > 
const& rawStTSs,
 
  155                       int charge, 
double radius, 
double phi_c, 
double& z0, 
double& cot, 
double& chi2,
 
  156                       std::vector<double>& arcS, std::vector<double>& zz, std::vector<double>& invZError2);
 
  159  static void fitter3DFirm(std::map<std::string, double>& mConstD, 
const std::map<std::string, std::vector<double> >& mConstV,
 
  160                           int eventTimeValid, 
int eventTime,
 
  161                           std::vector<std::vector<int> > 
const& rawStTSs,
 
  162                           int charge, 
double radius, 
double phi_c,
 
  164                           std::map<std::string, Belle2::TRGCDCJLUT*>& mLutStorage);
 
  169  static void findImpactPosition(ROOT::Math::XYZVector* mcPosition, ROOT::Math::PxPyPzEVector* mcMomentum, 
int charge,
 
  170                                 ROOT::Math::XYVector& helixCenter,
 
  171                                 ROOT::Math::XYZVector& impactPosition);
 
  175  static void calHelixParameters(ROOT::Math::XYZVector position, ROOT::Math::XYZVector momentum, 
int charge,
 
  176                                 TVectorD& helixParameters);
 
  179  static void calVectorsAtR(
const TVectorD& helixParameters, 
int charge, 
double radius, ROOT::Math::XYZVector& position,
 
  180                            ROOT::Math::XYZVector& momentum);
 
  186  static int bitSize(
int numberBits, 
int mode);
 
  189  static void changeInteger(
int& integer, 
double real, 
double minValue, 
double maxValue, 
int bitSize);
 
  192  static void changeReal(
double& real, 
int integer, 
double minValue, 
double maxValue, 
int bitSize);
 
  195  static void findExtreme(
double& m_max, 
double& m_min, 
double value);
 
A class to hold common data for JSignals.
A class that holds functions for 3D tracking.
static void calVectorsAtR(const TVectorD &helixParameters, int charge, double radius, ROOT::Math::XYZVector &position, ROOT::Math::XYZVector &momentum)
Calculates position and momentum at a certain radius.
static void loadStereoXt(std::string const &filePrefix, int nFiles, std::vector< std::vector< double > > &stXts)
Load stereo Xt file.
static double calIZError2(int lr, double driftZError, double wireZError)
Chooses and calculates inverse z error.
static double rotatePhi(double value, double refPhi)
Rotates to range [-pi, pi].
static double calStAxPhi(int charge, double anglest, double ztostraw, double rr, double rho, double phi0)
Calculates the fitted axial phi for the stereo super layer.
static void changeReal(double &real, int integer, double minValue, double maxValue, int bitSize)
Changes integer to float value.
static void calHelixParameters(ROOT::Math::XYZVector position, ROOT::Math::XYZVector momentum, int charge, TVectorD &helixParameters)
HelixParameters: dR, phi0, keppa, dz, tanLambda Calculates the helix parameters of track.
static int findQuadrant(double value)
Finds quadrant of angle. Angle is in rad.
static int bitSize(int numberBits, int mode)
Firmware convert functions.
static void fitter3DFirm(std::map< std::string, double > &mConstD, const std::map< std::string, std::vector< double > > &mConstV, int eventTimeValid, int eventTime, std::vector< std::vector< int > > const &rawStTSs, int charge, double radius, double phi_c, Belle2::TRGCDCJSignalData *commonData, std::map< std::string, Belle2::TRGCDCJSignal > &mSignalStorage, std::map< std::string, Belle2::TRGCDCJLUT * > &mLutStorage)
Combines several functions for fitter3D firmware.
static void rPhiFitter(double *rr, double *phi2, double *invphierror, double &rho, double &myphi0)
A circle fitter with invPhiError without fit chi2 output.
static void changeInteger(int &integer, double real, double minValue, double maxValue, int bitSize)
Changes float to integer value.
static double calZ(int charge, double anglest, double ztostraw, double rr, double phi, double rho, double phi0)
Calculates z.
static double calDenWithIZError(double *arcS, double *iZError)
Calculates the denominator for fitting z and arc s.
static void setError(std::map< std::string, double > const &mConstD, std::map< std::string, std::vector< double > > const &mConstV, std::map< std::string, Belle2::TRGCDCJSignal > &mSignalStorage)
Sets error using JSignal class.
static void setErrorFast(std::vector< std::vector< int > > const &rawStTSs, int eventTimeValid, std::vector< double > &invZError2)
Sets error for fitting.
static void calPhiFast(std::map< std::string, std::vector< double > > &stGeometry, std::vector< std::vector< double > > const &stXts, int eventTimeValid, int eventTime, std::vector< std::vector< int > > const &rawStTSs, std::vector< double > &stTSs)
Calculates phi with fast simulation.
static double calDeltaPhi(int charge, double anglest, double ztostraw, double rr, double phi, double rho, double phi0)
Calculates the phi difference between fitted axial phi and stereo phi.
static double calS(double rho, double rr)
Calculates arc length.
static double stereoIdToPhi(std::vector< double > &stNWires, int iSt, int id)
Converts stereo ts id to phi.
static void fitter3D(std::map< std::string, std::vector< double > > &stGeometry, std::vector< std::vector< double > > const &stXts, int eventTimeValid, int eventTime, std::vector< std::vector< int > > const &rawStTSs, int charge, double radius, double phi_c, double &z0, double &cot, double &chi2)
Combines several functions for fitter3D.
static int findSign(double *phi2)
2D fitter functions
static double calPhi(double wirePhi, double driftLength, double rr, int lr)
Pre 3D fitter functions. rr is in cm scale. driftLength is in cm scale.
static void chargeFinder(double *nTSs, double *tsIds, double *tsHitmap, double phi0, double inCharge, double &outCharge)
Charge finder using circle fitter output and axial TSs.
static int rotateTsId(int value, int refId, int nTSs)
Rotates to range [0, nTSs-1].
static void saveStereoXt(std::vector< std::vector< double > > &stXts, std::string const &filePrefix)
Saves stereo Xt to file.
static void rPhiFit(double *rr, double *phi2, double *phierror, double &rho, double &myphi0)
A circle fitter.
static void rSFit2(double *iezz21, double *iezz22, double *arcS, double *zz, int *lutv, double &z0, double &cot, double &zchi2)
Fits z and arc S. (Will be deprecated.)
static unsigned toUnsignedTdc(int tdc, int nBits)
Changes tdc and event time to unsigned value that has # bits.
static void rSFit(double *iezz2, double *arcS, double *zz, double &z0, double &cot, double &zchi2)
3D fitter functions Fits z and arc S.
static double calDen(double *arcS, double *zError)
Calculates the denominator for fitting z and arc s.
static void rPhiFit2(double *rr, double *phi2, double *phierror, double &rho, double &myphi0, int nTS)
A circle fitter.
static void findExtreme(double &m_max, double &m_min, double value)
Finds maximum and minium values.
static void constrainRPerStSl(std::map< std::string, std::vector< double > > const &mConstV, std::map< std::string, Belle2::TRGCDCJSignal > &mSignalStorage)
Constrains R for each SL differently using JSignal and multiple constants.
static void findImpactPosition(ROOT::Math::XYZVector *mcPosition, ROOT::Math::PxPyPzEVector *mcMomentum, int charge, ROOT::Math::XYVector &helixCenter, ROOT::Math::XYZVector &impactPosition)
MC calculation functions Calculates the impact position of track.
Abstract base class for different kinds of events.