Skip to content

Commit

Permalink
ancillary functions to calculate wire positions moved to data extension
Browse files Browse the repository at this point in the history
  • Loading branch information
atolosadelgado committed Nov 22, 2024
1 parent 39555a8 commit 202faf9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 89 deletions.
10 changes: 2 additions & 8 deletions DCHdigi/include/DCHdigi_v01.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ struct DCHdigi_v01 final
void ThrowException(std::string s) const;

int CalculateLayerFromCellID(dd4hep::DDSegmentation::CellID id) const {
return m_decoder->get(id, "layer") + dch_data->nlayersPerSuperlayer * m_decoder->get(id, "superlayer") + 1;
//return m_decoder->get(id, "layer") + dch_data->nlayersPerSuperlayer * m_decoder->get(id, "superlayer") + 1;
return dch_data->CalculateILayerFromCellIDFields( m_decoder->get(id, "layer"), m_decoder->get(id, "superlayer") );
}

int CalculateNphiFromCellID(dd4hep::DDSegmentation::CellID id) const { return m_decoder->get(id, "nphi"); }
Expand All @@ -155,13 +156,6 @@ struct DCHdigi_v01 final
return {v.x() * scale, v.y() * scale, v.z() * scale};
};

// the following functions should be upstreamed to the data extension at DD4hep
// to avoid code duplication and keep it centralized
TVector3 Calculate_hitpos_to_wire_vector(int ilayer, int nphi, const TVector3& hit_position /*in cm*/) const;
TVector3 Calculate_wire_vector_ez(int ilayer, int nphi) const;
TVector3 Calculate_wire_z0_point(int ilayer, int nphi) const;
double Calculate_wire_phi_z0(int ilayer, int nphi) const;

//------------------------------------------------------------------
// cluster calculation, developed by Walaa

Expand Down
81 changes: 0 additions & 81 deletions DCHdigi/src/DCHdigi_v01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,88 +246,7 @@ void DCHdigi_v01::PrepareRandomEngine(const edm4hep::EventHeaderCollection& head
myRandom.Rndm();
}

///////////////////////////////////////////////////////////////////////////////////////
///// Ancillary functions for calculating the distance to the wire ////////
///////////////////////////////////////////////////////////////////////////////////////

TVector3 DCHdigi_v01::Calculate_wire_vector_ez(int ilayer, int nphi) const {
auto& l = this->dch_data->database.at(ilayer);

// See original paper Hoshina et al, Computer Physics Communications 153 (2003) 3
// eq. 2.9, for the definition of ez, vector along the wire

// initialize some variables
int stereosign = l.StereoSign();
double rz0 = l.radius_sw_z0;
double dphi = dch_data->twist_angle;
// kappa is the same as in eq. 2.9
double kappa = (1. / dch_data->Lhalf) * tan(dphi / 2);

//--- calculating wire position
// the points p1 and p2 correspond to the ends of the wire

// point 1
// double x1 = rz0; // m
// double y1 = 0.; // m
// double z1 = 0.; // m
double x1 = rz0; // m
double y1 = -stereosign * rz0 * kappa * dch_data->Lhalf; // m
double z1 = -dch_data->Lhalf; // m

TVector3 p1(x1, y1, z1);

// point 2
double x2 = rz0; // m
double y2 = stereosign * rz0 * kappa * dch_data->Lhalf; // m
double z2 = dch_data->Lhalf; // m

TVector3 p2(x2, y2, z2);

// calculate phi rotation of whole twisted tube, ie, rotation at z=0
double phi_z0 = Calculate_wire_phi_z0(ilayer, nphi);
p1.RotateZ(phi_z0);
p2.RotateZ(phi_z0);

//--- end calculating wire position

return (p2 - p1).Unit();
}

TVector3 DCHdigi_v01::Calculate_wire_z0_point(int ilayer, int nphi) const {
auto& l = this->dch_data->database.at(ilayer);
double rz0 = l.radius_sw_z0;
TVector3 p1(rz0, 0, 0);
double phi_z0 = Calculate_wire_phi_z0(ilayer, nphi);
p1.RotateZ(phi_z0);
return p1;
}

// calculate phi rotation of whole twisted tube, ie, rotation at z=0
double DCHdigi_v01::Calculate_wire_phi_z0(int ilayer, int nphi) const {
auto& l = this->dch_data->database.at(ilayer);
int ncells = l.nwires / 2;
double phistep = TMath::TwoPi() / ncells;
double phi_z0 = (nphi + 0.25 * (l.layer % 2)) * phistep;
return phi_z0;
}

///////////////////////////////////////////////////////////////////////////////////////
/////////////////////// Calculate vector from hit position to wire /////////////////
///////////////////////////////////////////////////////////////////////////////////////
TVector3 DCHdigi_v01::Calculate_hitpos_to_wire_vector(int ilayer, int nphi, const TVector3& hit_position /*in cm*/) const {
// Solution distance from a point to a line given here:
// https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line#Vector_formulation
TVector3 n = this->Calculate_wire_vector_ez(ilayer, nphi);
TVector3 a = this->Calculate_wire_z0_point(ilayer, nphi);
// Remember using cm as natural units of DD4hep consistently!
// TVector3 p {hit_position.x()*MM_TO_CM,hit_position.y()*MM_TO_CM,hit_position.z()*MM_TO_CM};

TVector3 a_minus_p = a - hit_position;
double a_minus_p_dot_n = a_minus_p.Dot(n);
TVector3 scaled_n = a_minus_p_dot_n * n;
//hit_to_wire_vector = a_minus_p - scaled_n;
return (a_minus_p - scaled_n);
}

///////////////////////////////////////////////////////////////////////////////////////
/////////////////////// CalculateNClusters ////////////////////////////////
Expand Down

0 comments on commit 202faf9

Please sign in to comment.