Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TpcDistortionCorrection.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TpcDistortionCorrection.cc
1 
9 
10 #include <TH1.h>
11 #include <cmath>
12 
13 #include <iostream>
14 
15 namespace
16 {
17  template<class T> inline constexpr T square( const T& x ) { return x*x; }
18 
19  // check boundaries in axis
20  /* for the interpolation to work, the value must be within the range of the provided axis, and not into the first and last bin */
21  inline bool check_boundaries( const TAxis* axis, double value )
22  {
23  const auto bin = axis->FindBin( value );
24  return( bin >= 2 && bin < axis->GetNbins() );
25  }
26 
27  // check boundaries in histogram, before interpolation
28  /* for the interpolation to work, the value must be within the range of the provided axis, and not into the first and last bin */
29  inline bool check_boundaries( const TH1* h, double r, double phi, double z )
30  {
31  return check_boundaries( h->GetXaxis(), r )
32  && check_boundaries( h->GetYaxis(), phi )
33  && check_boundaries( h->GetZaxis(), z );
34  }
35 
36  // check boundaries in histogram, before interpolation
37  /* for the interpolation to work, the value must be within the range of the provided axis, and not into the first and last bin */
38  inline bool check_boundaries( const TH1* h, double r, double phi )
39  { return check_boundaries( h->GetXaxis(), r ) && check_boundaries( h->GetYaxis(), phi ); }
40 
41 }
42 
43 //________________________________________________________
45 {
46  // get cluster radius, phi and z
47  const auto r = std::sqrt( square( source.x() ) + square( source.y() ) );
48  auto phi = std::atan2( source.y(), source.x() );
49  if( phi < 0 ) phi += 2*M_PI;
50 
51  const auto z = source.z();
52  const int index = z > 0 ? 1:0;
53 
54  // apply corrections
55  auto phi_new=phi;
56  auto r_new=r;
57  auto z_new=z;
58 
59  //if the phi correction hist units are cm, we must divide by r to get the dPhi in radians
60  auto divisor=r;
62  //if the phi correction hist units are radians, we must not divide by r.
63  divisor=1.0;
64  }
65 
66  if (dcc->dimensions==3)
67  {
68  if (dcc->m_hDPint[index] && (mask&COORD_PHI) && check_boundaries( dcc->m_hDPint[index],phi,r,z)) phi_new = phi - dcc->m_hDPint[index]->Interpolate(phi,r,z)/divisor;
69  if (dcc->m_hDRint[index] && (mask&COORD_R) && check_boundaries( dcc->m_hDRint[index],phi,r,z)) r_new = r - dcc->m_hDRint[index]->Interpolate(phi,r,z);
70  if (dcc->m_hDZint[index] && (mask&COORD_Z) && check_boundaries( dcc->m_hDZint[index],phi,r,z)) z_new = z - dcc->m_hDZint[index]->Interpolate(phi,r,z);
71  }
72  else if (dcc->dimensions==2){
73  const double zterm = (1.- std::abs(z)/105.5);
74  if (dcc->m_hDPint[index] && (mask&COORD_PHI) && check_boundaries( dcc->m_hDPint[index],phi,r)) phi_new = phi - dcc->m_hDPint[index]->Interpolate(phi,r)*zterm/divisor;
75  if (dcc->m_hDRint[index] && (mask&COORD_R) && check_boundaries( dcc->m_hDRint[index],phi,r)) r_new = r - dcc->m_hDRint[index]->Interpolate(phi,r)*zterm;
76  if (dcc->m_hDZint[index] && (mask&COORD_Z) && check_boundaries( dcc->m_hDZint[index],phi,r)) z_new = z - dcc->m_hDZint[index]->Interpolate(phi,r)*zterm;
77  }
78 
79  // update cluster
80  const auto x_new = r_new*std::cos( phi_new );
81  const auto y_new = r_new*std::sin( phi_new );
82 
83  return {x_new, y_new, z_new};
84 }