44 #include <TGeoManager.h> 45 #include <TGeoVolume.h> 46 #include <TGeoMatrix.h> 50 #include <TMultiGraph.h> 59 #include <TPolyLine.h> 81 for (
int i = 0;
i < 7;
i++) {
82 for (
int j = 0; j < 7; j++) {
88 void Set(
const double *matrix)
90 for (
int i = 0;
i < 7 * 7;
i++) {
91 M[
i / 7][
i % 7] = matrix[
i];
101 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,
102 -3.991e-06, 0.3103, 1.064, -3.991e-06, -0.04447, -0.04501, 0.001764, 11.24, -0.04385, 0.007135,
103 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,
104 -0.0001811, 0.000127, 0.9794, -0.1215, 0.4001, -0.6638, 0.04068, 0.001168, -7.627e-06, 0.2952,
105 0.9388, -7.627e-06, -1.003e-15, -3.248e-15, 9.487e-17, 5.594e-18, 2.41e-16, -1.086e-16, 1};
109 double matrix_init[49] = {0.9633, 0.2086, -0.01173, 0.2598, 1.123, -0.03217, -0.0002463, -0.104, 0.97, -0.006443,
110 5.119e-06, 0.06427, 1.12, 5.119e-06, -0.03828, 0.005853, 0.004478, 11.24, -0.0447, 0.001794,
111 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,
112 -0.01384, 0.0001758, 0.9997, -0.02581, 0.4002, -0.09394, -0.05056, -0.002047, 3.624e-05, 0.06091,
113 0.994, 3.624e-05, 2.376e-06, -0.0003806, -2.583e-07, -3.862e-07, -1.647e-05, -1.871e-05, 1};
116 cout <<
" Warning in PndLmdDimPropMat: loading identity matrix only " << endl;
117 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,
118 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1};
128 double mommag = momdir.Mag();
130 double xip[7] = {pos.X() / 100., pos.Y() / 100., pos.Z() / 100., 1, momdir.X() / momdir.Z() * 10., momdir.Y() / momdir.Z() * 10., 1};
131 double xlmd[7] = {0, 0, 0, 0, 0, 0, 0};
132 for (
int i = 0;
i < 7;
i++) {
133 for (
int j = 0; j < 7; j++) {
134 xlmd[
i] += M[
i][j] * xip[j];
137 pos.SetXYZ(xlmd[0] * 100., xlmd[1] * 100., xlmd[2] * 100.);
138 momdir.SetXYZ(xlmd[4] / 10., xlmd[5] / 10., 1.);
139 momdir = momdir.Unit() * mommag;
153 if (half < comp.
half)
155 if (half > comp.
half)
157 if (plane < comp.
plane)
159 if (plane > comp.
plane)
165 if (side < comp.
side)
167 if (side > comp.
side)
175 if (sensor >= comp.
sensor)
182 return (half == comp.
half) && (plane == comp.
plane) && (module == comp.
module) && (side == comp.
side) && (die == comp.
die) && (sensor == comp.
sensor);
195 Tkey(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor)
210 for (
unsigned int ichar = 0; ichar < key.size(); ichar++) {
211 if (key[ichar] ==
'-') {
214 if (isdigit(key[ichar])) {
215 number = (key[ichar] -
'0') * sign;
233 cout <<
" Error in Generate_Tkey: key string " << key <<
" is not valid " << endl;
243 static int geometry_version;
246 TGeoManager *fgGeoMan;
256 vector<string> nav_paths;
274 bool Set_sensIDoffset(
int offset = -1);
519 bool Is_valid_idcall(
int ihalf,
int iplane = 0,
int imodule = 0,
int iside = 0,
int idie = 0,
int isensor = 0)
521 if (ihalf < 0 || ihalf >= 2)
523 if (iplane < 0 || (
unsigned)iplane >= n_planes)
525 if (imodule < 0 || imodule >= n_cvd_discs)
527 if (iside < 0 || iside >= 2)
529 if (idie < 0 || idie >= 2)
532 if (isensor < 0 || isensor >= n_sensors + 1)
538 int Get_sensor_id(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor)
542 int result = isensor + (iside + (imodule + (iplane + ihalf * n_planes) * nmodules) * 2) * n_sensors;
543 return result + sensIDoffset;
547 void Get_sensor_by_id(
const int sensor_id,
int &ihalf,
int &iplane,
int &imodule,
int &iside,
int &idie,
int &isensor)
549 int _sensor_id = sensor_id - sensIDoffset;
550 isensor = _sensor_id % n_sensors;
556 _sensor_id /= n_sensors;
557 iside = _sensor_id % 2;
559 imodule = _sensor_id % nmodules;
560 _sensor_id /= nmodules;
561 iplane = _sensor_id % n_planes;
562 _sensor_id /= n_planes;
563 ihalf = _sensor_id % 2;
564 if (!Is_valid_idcall(ihalf, iplane, imodule, iside, idie, isensor)) {
571 cout <<
"Error in PndLmdDim::Get_sensor_by_id: " << sensor_id <<
" is not a valid sensor id!" << endl;
594 char *
itoa(
int value,
char *result,
int base)
598 if (base < 2 || base > 36) {
602 char *ptr = result, *ptr1 = result, tmp_char;
607 *ptr++ =
"zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"[35 + (tmp_value - value * base)];
623 string Generate_key(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor)
627 ptr = itoa(ihalf, key, 10);
628 ptr = itoa(iplane, ptr, 10);
629 ptr = itoa(imodule, ptr, 10);
630 ptr = itoa(iside, ptr, 10);
631 ptr = itoa(idie, ptr, 10);
632 ptr = itoa(isensor, ptr, 10);
642 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)
644 stringstream keystream;
645 keystream << ihalf << iplane << imodule << iside << idie << isensor;
647 key = atoi(keystream.str().c_str());
678 void Read_transformation_matrices(
string filename =
"",
bool aligned =
true,
int version_number = geometry_version);
687 void Write_transformation_matrices(
string filename,
bool aligned =
true,
int version_number = geometry_version);
696 bool Read_transformation_matrices_from_geometry(
bool aligned =
true);
710 bool Write_transformation_matrices_to_geometry(
bool aligned =
true);
718 string Get_List_of_Sensors(vector<string> &list_of_sensors,
bool found_lmd =
false,
bool first_call =
true);
724 bool Test_List_of_Sensors(vector<string> list_of_sensors,
int &offset);
729 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,
730 bool random =
false);
735 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);
742 void Correct_transformation_matrices();
743 void reCreate_transformation_matrices();
751 void Get_pos_lmd_global(
double &x,
double &y,
double &z,
double &rotx,
double &roty,
double &rotz,
bool misaligned =
false)
771 TVector3 Decode_hit(
const int sensorID,
const double column,
const double row,
const bool aligned =
true,
bool newVersion =
false);
784 void Propagate_fast_ip_to_lmd(TVector3 &pos, TVector3 &mom,
double pbeam);
795 bool Get_overlapping_sensor(
const TVector3 &point,
int &ihalf,
int &iplane,
int &imodule,
int &iside,
int &idie,
int &isensor,
bool aligned =
true);
800 bool Is_on_Sensor(
const TVector3 &point,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
806 int Get_overlapping_sensor(
int idie,
int isensor, vector<int> &jdie, vector<int> &jsensor);
810 TGeoHMatrix Get_transformation_global_to_lmd_local(
bool aligned =
true);
814 TGeoHMatrix Get_transformation_lmd_local_to_module_side(
int ihalf,
int iplane,
int imodule,
int iside,
bool aligned =
true);
818 TGeoHMatrix Get_transformation_module_side_to_sensor(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
822 TGeoHMatrix Get_transformation_global_to_sensor(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
826 TGeoHMatrix Get_transformation_lmd_local_to_sensor(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
830 TGeoHMatrix Get_transformation_lmd_local_to_global(
bool aligned =
true);
834 TGeoHMatrix Get_transformation_module_side_to_lmd_local(
int ihalf,
int iplane,
int imodule,
int iside,
bool aligned =
true);
838 TGeoHMatrix Get_transformation_sensor_to_module_side(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
842 TGeoHMatrix Get_transformation_sensor_to_global(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
846 TGeoHMatrix Get_transformation_sensor_to_lmd_local(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
849 TGeoHMatrix Get_transformation_sensor_to_sensor_aligned(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor);
852 TGeoHMatrix Get_transformation_sensor_aligned_to_sensor(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor);
858 TVector3 Transform_global_to_lmd_local(
const TVector3 &point,
bool isvector =
false,
bool aligned =
true);
862 TVector3 Transform_lmd_local_to_module_side(
const TVector3 &point,
int ihalf,
int iplane,
int imodule,
int iside,
bool isvector =
false,
bool aligned =
true);
866 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);
870 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);
874 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);
878 TVector3 Transform_lmd_local_to_global(
const TVector3 &point,
bool isvector =
false,
bool aligned =
true);
882 TVector3 Transform_module_side_to_lmd_local(
const TVector3 &point,
int ihalf,
int iplane,
int imodule,
int iside,
bool isvector =
false,
bool aligned =
true);
886 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);
890 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);
894 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);
897 TVector3 Transform_sensor_to_sensor_aligned(
const TVector3 &point,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool isvector =
false);
900 TVector3 Transform_sensor_aligned_to_sensor(
const TVector3 &point,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool isvector =
false);
903 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,
904 int iplane_to,
int imodule_to,
int iside_to,
int idie_to,
int isensor_to,
bool isvector =
false,
bool aligned =
true);
911 TMatrixD Transform_global_to_lmd_local(
const TMatrixD &matrix,
bool aligned =
true);
916 TMatrixD Transform_lmd_local_to_module_side(
const TMatrixD &matrix,
int ihalf,
int iplane,
int imodule,
int iside,
bool aligned =
true);
921 TMatrixD Transform_lmd_local_to_sensor(
const TMatrixD &matrix,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
926 TMatrixD Transform_module_side_to_sensor(
const TMatrixD &matrix,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
931 TMatrixD Transform_global_to_sensor(
const TMatrixD &matrix,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
936 TMatrixD Transform_lmd_local_to_global(
const TMatrixD &matrix,
bool aligned =
true);
941 TMatrixD Transform_module_side_to_lmd_local(
const TMatrixD &matrix,
int ihalf,
int iplane,
int imodule,
int iside,
bool aligned =
true);
946 TMatrixD Transform_sensor_to_module_side(
const TMatrixD &matrix,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
951 TMatrixD Transform_sensor_to_lmd_local(
const TMatrixD &matrix,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
956 TMatrixD Transform_sensor_to_global(
const TMatrixD &matrix,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
960 TMatrixD Transform_sensor_to_sensor_aligned(
const TMatrixD &matrix,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor);
964 TMatrixD Transform_sensor_aligned_to_sensor(
const TMatrixD &matrix,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor);
968 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,
969 int iplane_to,
int imodule_to,
int iside_to,
int idie_to,
int isensor_to,
bool aligned =
true);
976 map<Tkey, TGeoMatrix *> *Get_matrices(
bool aligned =
true);
982 TGeoMatrix *Get_matrix(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
992 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);
1001 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);
1008 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);
1014 void Calc_matrix_offsets();
1017 TGeoMatrix *Get_matrix_global_to_lmd_local(
bool aligned =
true);
1020 TGeoMatrix *Get_matrix_lmd_local_to_module_side(
int ihalf,
int iplane,
int imodule,
int iside,
bool aligned =
true);
1023 TGeoMatrix *Get_matrix_module_side_to_sensor(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
1029 void Transform_global_to_lmd_local(
double &x,
double &y,
double &z,
bool aligned =
true);
1033 void Transform_global_to_lmd_local_vect(
double &x,
double &y,
double &z,
bool aligned =
true);
1055 void Generate_rootgeom(TGeoVolume &mothervol,
bool misaligned =
false);
1060 bool Retrieve_version_number();
1063 void Test_matrices();
1068 void Draw_Sensors(
int iplane,
bool aligned =
true,
bool lmd_frame =
true,
int glside = 2);
1074 TPolyLine *Get_Sensor_Shape(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true,
bool lmd_frame =
true);
1087 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);
1095 TH2Poly *Get_histogram_Plane(
int iplane,
int iside,
bool aligned =
true,
bool lmd_frame =
true,
bool pixel_subdivision =
false);
1104 TH2Poly *Get_histogram_Moduleside(
int ihalf,
int iplane,
int imodule,
int iside,
bool aligned =
true,
bool lmd_frame =
true,
bool pixel_subdivision =
true);
1113 TH2Poly *Get_histogram_Sensor(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true,
bool lmd_frame =
true);
1116 std::vector<int> getAvailableOverlapIDs();
1117 int makeOverlapID(
int firstSensorId,
int secondSensorId);
1118 int getID1fromOverlapID(
int overlapID);
1119 int getID2fromOverlapID(
int overlapID);
1122 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