32 #include <TGeoManager.h> 33 #include <TGeoVolume.h> 34 #include <TGeoMatrix.h> 38 #include <TMultiGraph.h> 47 #include <TPolyLine.h> 69 for (
int i = 0;
i < 7;
i++) {
70 for (
int j = 0; j < 7; j++) {
76 void Set(
const double *matrix)
78 for (
int i = 0;
i < 7 * 7;
i++) {
79 M[
i / 7][
i % 7] = matrix[
i];
89 double matrix_init[49] = {1.012, 1.22, 5.216e-05, 0.2599, 1.096, -0.1589, -0.0001459, -0.5851, 1.042, 0.001092,
90 -3.991e-06, 0.3103, 1.064, -3.991e-06, -0.04447, -0.04501, 0.001764, 11.24, -0.04385, 0.007135,
91 0.0001733, -1.36e-15, 1.816e-14, 3.031e-15, 1, 1.513e-16, -2.272e-16, 7.904e-17, 0.006668, 1.356,
92 -0.0001811, 0.000127, 0.9794, -0.1215, 0.4001, -0.6638, 0.04068, 0.001168, -7.627e-06, 0.2952,
93 0.9388, -7.627e-06, -1.003e-15, -3.248e-15, 9.487e-17, 5.594e-18, 2.41e-16, -1.086e-16, 1};
97 double matrix_init[49] = {0.9633, 0.2086, -0.01173, 0.2598, 1.123, -0.03217, -0.0002463, -0.104, 0.97, -0.006443,
98 5.119e-06, 0.06427, 1.12, 5.119e-06, -0.03828, 0.005853, 0.004478, 11.24, -0.0447, 0.001794,
99 2.613e-06, 2.376e-06, -0.0003806, -2.583e-07, 1, -1.647e-05, -1.871e-05, -3.862e-07, -0.01744, 0.1777,
100 -0.01384, 0.0001758, 0.9997, -0.02581, 0.4002, -0.09394, -0.05056, -0.002047, 3.624e-05, 0.06091,
101 0.994, 3.624e-05, 2.376e-06, -0.0003806, -2.583e-07, -3.862e-07, -1.647e-05, -1.871e-05, 1};
104 cout <<
" Warning in PndLmdDimPropMat: loading identity matrix only " << endl;
105 double matrix_init[49] = {1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1,
106 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1};
116 double mommag = momdir.Mag();
118 double xip[7] = {pos.X() / 100., pos.Y() / 100., pos.Z() / 100., 1, momdir.X() / momdir.Z() * 10., momdir.Y() / momdir.Z() * 10., 1};
119 double xlmd[7] = {0, 0, 0, 0, 0, 0, 0};
120 for (
int i = 0;
i < 7;
i++) {
121 for (
int j = 0; j < 7; j++) {
122 xlmd[
i] += M[
i][j] * xip[j];
125 pos.SetXYZ(xlmd[0] * 100., xlmd[1] * 100., xlmd[2] * 100.);
126 momdir.SetXYZ(xlmd[4] / 10., xlmd[5] / 10., 1.);
127 momdir = momdir.Unit() * mommag;
141 if (half < comp.
half)
143 if (half > comp.
half)
145 if (plane < comp.
plane)
147 if (plane > comp.
plane)
153 if (side < comp.
side)
155 if (side > comp.
side)
163 if (sensor >= comp.
sensor)
170 return (half == comp.
half) && (plane == comp.
plane) && (module == comp.
module) && (side == comp.
side) && (die == comp.
die) && (sensor == comp.
sensor);
183 Tkey(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor)
198 for (
unsigned int ichar = 0; ichar < key.size(); ichar++) {
199 if (key[ichar] ==
'-') {
202 if (isdigit(key[ichar])) {
203 number = (key[ichar] -
'0') * sign;
221 cout <<
" Error in Generate_Tkey: key string " << key <<
" is not valid " << endl;
231 static int geometry_version;
234 TGeoManager *fgGeoMan;
244 vector<string> nav_paths;
262 bool Set_sensIDoffset(
int offset = -1);
507 bool Is_valid_idcall(
int ihalf,
int iplane = 0,
int imodule = 0,
int iside = 0,
int idie = 0,
int isensor = 0)
509 if (ihalf < 0 || ihalf >= 2)
511 if (iplane < 0 || (
unsigned)iplane >= n_planes)
513 if (imodule < 0 || imodule >= n_cvd_discs)
515 if (iside < 0 || iside >= 2)
517 if (idie < 0 || idie >= 2)
520 if (isensor < 0 || isensor >= n_sensors + 1)
526 int Get_sensor_id(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor)
530 int result = isensor + (iside + (imodule + (iplane + ihalf * n_planes) * nmodules) * 2) * n_sensors;
531 return result + sensIDoffset;
535 void Get_sensor_by_id(
const int sensor_id,
int &ihalf,
int &iplane,
int &imodule,
int &iside,
int &idie,
int &isensor)
537 int _sensor_id = sensor_id - sensIDoffset;
538 isensor = _sensor_id % n_sensors;
544 _sensor_id /= n_sensors;
545 iside = _sensor_id % 2;
547 imodule = _sensor_id % nmodules;
548 _sensor_id /= nmodules;
549 iplane = _sensor_id % n_planes;
550 _sensor_id /= n_planes;
551 ihalf = _sensor_id % 2;
552 if (!Is_valid_idcall(ihalf, iplane, imodule, iside, idie, isensor)) {
559 cout <<
"Error in PndLmdDim::Get_sensor_by_id: " << sensor_id <<
" is not a valid sensor id!" << endl;
582 char *
itoa(
int value,
char *result,
int base)
586 if (base < 2 || base > 36) {
590 char *ptr = result, *ptr1 = result, tmp_char;
595 *ptr++ =
"zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"[35 + (tmp_value - value * base)];
611 string Generate_key(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor)
615 ptr = itoa(ihalf, key, 10);
616 ptr = itoa(iplane, ptr, 10);
617 ptr = itoa(imodule, ptr, 10);
618 ptr = itoa(iside, ptr, 10);
619 ptr = itoa(idie, ptr, 10);
620 ptr = itoa(isensor, ptr, 10);
630 int Generate_keynumber(
unsigned int ihalf = 0,
unsigned int iplane = 0,
unsigned int imodule = 0,
unsigned int iside = 0,
unsigned int idie = 0,
unsigned int isensor = 0)
632 stringstream keystream;
633 keystream << ihalf << iplane << imodule << iside << idie << isensor;
635 key = atoi(keystream.str().c_str());
666 void Read_transformation_matrices(
string filename =
"",
bool aligned =
true,
int version_number = geometry_version);
675 void Write_transformation_matrices(
string filename,
bool aligned =
true,
int version_number = geometry_version);
684 bool Read_transformation_matrices_from_geometry(
bool aligned =
true);
698 bool Write_transformation_matrices_to_geometry(
bool aligned =
true);
706 string Get_List_of_Sensors(vector<string> &list_of_sensors,
bool found_lmd =
false,
bool first_call =
true);
712 bool Test_List_of_Sensors(vector<string> list_of_sensors,
int &offset);
717 void Get_offset(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
double &x,
double &y,
double &z,
double &rotphi,
double &rottheta,
double &rotpsi,
718 bool random =
false);
723 void Set_offset(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
double x,
double y,
double z,
double rotphi,
double rottheta,
double rotpsi);
730 void Correct_transformation_matrices();
731 void reCreate_transformation_matrices();
739 void Get_pos_lmd_global(
double &x,
double &y,
double &z,
double &rotx,
double &roty,
double &rotz,
bool misaligned =
false)
759 TVector3 Decode_hit(
const int sensorID,
const double column,
const double row,
const bool aligned =
true,
bool newVersion =
false);
772 void Propagate_fast_ip_to_lmd(TVector3 &pos, TVector3 &mom,
double pbeam);
783 bool Get_overlapping_sensor(
const TVector3 &point,
int &ihalf,
int &iplane,
int &imodule,
int &iside,
int &idie,
int &isensor,
bool aligned =
true);
788 bool Is_on_Sensor(
const TVector3 &point,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
794 int Get_overlapping_sensor(
int idie,
int isensor, vector<int> &jdie, vector<int> &jsensor);
798 TGeoHMatrix Get_transformation_global_to_lmd_local(
bool aligned =
true);
802 TGeoHMatrix Get_transformation_lmd_local_to_module_side(
int ihalf,
int iplane,
int imodule,
int iside,
bool aligned =
true);
806 TGeoHMatrix Get_transformation_module_side_to_sensor(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
810 TGeoHMatrix Get_transformation_global_to_sensor(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
814 TGeoHMatrix Get_transformation_lmd_local_to_sensor(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
818 TGeoHMatrix Get_transformation_lmd_local_to_global(
bool aligned =
true);
822 TGeoHMatrix Get_transformation_module_side_to_lmd_local(
int ihalf,
int iplane,
int imodule,
int iside,
bool aligned =
true);
826 TGeoHMatrix Get_transformation_sensor_to_module_side(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
830 TGeoHMatrix Get_transformation_sensor_to_global(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
834 TGeoHMatrix Get_transformation_sensor_to_lmd_local(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
837 TGeoHMatrix Get_transformation_sensor_to_sensor_aligned(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor);
840 TGeoHMatrix Get_transformation_sensor_aligned_to_sensor(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor);
846 TVector3 Transform_global_to_lmd_local(
const TVector3 &point,
bool isvector =
false,
bool aligned =
true);
850 TVector3 Transform_lmd_local_to_module_side(
const TVector3 &point,
int ihalf,
int iplane,
int imodule,
int iside,
bool isvector =
false,
bool aligned =
true);
854 TVector3 Transform_module_side_to_sensor(
const TVector3 &point,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool isvector =
false,
bool aligned =
true);
858 TVector3 Transform_global_to_sensor(
const TVector3 &point,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool isvector =
false,
bool aligned =
true);
862 TVector3 Transform_lmd_local_to_sensor(
const TVector3 &point,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool isvector =
false,
bool aligned =
true);
866 TVector3 Transform_lmd_local_to_global(
const TVector3 &point,
bool isvector =
false,
bool aligned =
true);
870 TVector3 Transform_module_side_to_lmd_local(
const TVector3 &point,
int ihalf,
int iplane,
int imodule,
int iside,
bool isvector =
false,
bool aligned =
true);
874 TVector3 Transform_sensor_to_module_side(
const TVector3 &point,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool isvector =
false,
bool aligned =
true);
878 TVector3 Transform_sensor_to_global(
const TVector3 &point,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool isvector =
false,
bool aligned =
true);
882 TVector3 Transform_sensor_to_lmd_local(
const TVector3 &point,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool isvector =
false,
bool aligned =
true);
885 TVector3 Transform_sensor_to_sensor_aligned(
const TVector3 &point,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool isvector =
false);
888 TVector3 Transform_sensor_aligned_to_sensor(
const TVector3 &point,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool isvector =
false);
891 TVector3 Transform_sensor_to_sensor(
const TVector3 &point,
int ihalf_from,
int iplane_from,
int imodule_from,
int iside_from,
int idie_from,
int isensor_from,
int ihalf_to,
892 int iplane_to,
int imodule_to,
int iside_to,
int idie_to,
int isensor_to,
bool isvector =
false,
bool aligned =
true);
899 TMatrixD Transform_global_to_lmd_local(
const TMatrixD &matrix,
bool aligned =
true);
904 TMatrixD Transform_lmd_local_to_module_side(
const TMatrixD &matrix,
int ihalf,
int iplane,
int imodule,
int iside,
bool aligned =
true);
909 TMatrixD Transform_lmd_local_to_sensor(
const TMatrixD &matrix,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
914 TMatrixD Transform_module_side_to_sensor(
const TMatrixD &matrix,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
919 TMatrixD Transform_global_to_sensor(
const TMatrixD &matrix,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
924 TMatrixD Transform_lmd_local_to_global(
const TMatrixD &matrix,
bool aligned =
true);
929 TMatrixD Transform_module_side_to_lmd_local(
const TMatrixD &matrix,
int ihalf,
int iplane,
int imodule,
int iside,
bool aligned =
true);
934 TMatrixD Transform_sensor_to_module_side(
const TMatrixD &matrix,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
939 TMatrixD Transform_sensor_to_lmd_local(
const TMatrixD &matrix,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
944 TMatrixD Transform_sensor_to_global(
const TMatrixD &matrix,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
948 TMatrixD Transform_sensor_to_sensor_aligned(
const TMatrixD &matrix,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor);
952 TMatrixD Transform_sensor_aligned_to_sensor(
const TMatrixD &matrix,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor);
956 TMatrixD Transform_sensor_to_sensor(
const TMatrixD &matrix,
int ihalf_from,
int iplane_from,
int imodule_from,
int iside_from,
int idie_from,
int isensor_from,
int ihalf_to,
957 int iplane_to,
int imodule_to,
int iside_to,
int idie_to,
int isensor_to,
bool aligned =
true);
964 map<Tkey, TGeoMatrix *> *Get_matrices(
bool aligned =
true);
970 TGeoMatrix *Get_matrix(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
980 TGeoHMatrix *Get_matrix(
string path,
bool aligned =
true,
int ihalf = -1,
int iplane = -1,
int imodule = -1,
int iside = -1,
int idie = -1,
int isensor = -1);
989 bool Set_matrix(
string path, TGeoHMatrix *matrix,
int ihalf = -1,
int iplane = -1,
int imodule = -1,
int iside = -1,
int idie = -1,
int isensor = -1);
996 bool Get_matrix_difference(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
double &dx,
double &dy,
double &dz,
double &dphi,
double &dtheta,
double &dpsi);
1002 void Calc_matrix_offsets();
1005 TGeoMatrix *Get_matrix_global_to_lmd_local(
bool aligned =
true);
1008 TGeoMatrix *Get_matrix_lmd_local_to_module_side(
int ihalf,
int iplane,
int imodule,
int iside,
bool aligned =
true);
1011 TGeoMatrix *Get_matrix_module_side_to_sensor(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
1017 void Transform_global_to_lmd_local(
double &x,
double &y,
double &z,
bool aligned =
true);
1021 void Transform_global_to_lmd_local_vect(
double &x,
double &y,
double &z,
bool aligned =
true);
1043 void Generate_rootgeom(TGeoVolume &mothervol,
bool misaligned =
false);
1048 bool Retrieve_version_number();
1051 void Test_matrices();
1056 void Draw_Sensors(
int iplane,
bool aligned =
true,
bool lmd_frame =
true,
int glside = 2);
1062 TPolyLine *Get_Sensor_Shape(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true,
bool lmd_frame =
true);
1075 Get_Sensor_Graph(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true,
bool lmd_frame =
true,
bool pixel_subdivision =
true);
1083 TH2Poly *Get_histogram_Plane(
int iplane,
int iside,
bool aligned =
true,
bool lmd_frame =
true,
bool pixel_subdivision =
false);
1092 TH2Poly *Get_histogram_Moduleside(
int ihalf,
int iplane,
int imodule,
int iside,
bool aligned =
true,
bool lmd_frame =
true,
bool pixel_subdivision =
true);
1101 TH2Poly *Get_histogram_Sensor(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true,
bool lmd_frame =
true);
1104 std::vector<int> getAvailableOverlapIDs();
1105 int makeOverlapID(
int firstSensorId,
int secondSensorId);
1106 int getID1fromOverlapID(
int overlapID);
1107 int getID2fromOverlapID(
int overlapID);
1110 int makeModuleID(
int overlapID);
double maps_active_pixel_size
map< Tkey, vector< double > >::iterator itoffset
void Get_pos_lmd_global(double &x, double &y, double &z, double &rotx, double &roty, double &rotz, bool misaligned=false)
Tkey(int ihalf, int iplane, int imodule, int iside, int idie, int isensor)
char * itoa(int value, char *result, int base)
bool Is_valid_idcall(int ihalf, int iplane=0, int imodule=0, int iside=0, int idie=0, int isensor=0)
double plane_half_tilt_theta
string Generate_key(int ihalf, int iplane, int imodule, int iside, int idie, int isensor)
double plane_half_offset_y
map< Tkey, TGeoMatrix * >::iterator it_transformation_matrices
map< Tkey, TGeoMatrix * > transformation_matrices_aligned
bool operator<(const Tkey &comp) const
void Propagate(TVector3 &pos, TVector3 &momdir)
double plane_half_tilt_phi
double maps_passive_right
map< Tkey, TGeoMatrix * > transformation_matrices
bool operator==(const Tkey &comp) const
double plane_half_tilt_psi
int Get_sensor_id(int ihalf, int iplane, int imodule, int iside, int idie, int isensor)
double maps_passive_bottom
unsigned int sensIDoffset
double cvd_disc_thick_half
Alignment Parameter Class for LMD.
double maps_active_offset_x
void Get_sensor_by_id(const int sensor_id, int &ihalf, int &iplane, int &imodule, int &iside, int &idie, int &isensor)
double kapton_disc_thick_half
double maps_active_offset_y
double cvd_disc_even_odd_offset
map< Tkey, vector< double > > offsets
void Set(const double *matrix)
double plane_half_offset_x
PndLmdDimPropMat(double mom_init)
double maps_active_height
double plane_half_offset_z
map< double, PndLmdDimPropMat > propagation_matrices
int Generate_keynumber(unsigned int ihalf=0, unsigned int iplane=0, unsigned int imodule=0, unsigned int iside=0, unsigned int idie=0, unsigned int isensor=0)
TMatrixT< double > TMatrixD