32 #include <TGeoManager.h>
33 #include <TGeoVolume.h>
34 #include <TGeoMatrix.h>
38 #include <TMultiGraph.h>
47 #include <TPolyLine.h>
68 for (
int i = 0;
i < 7;
i++){
69 for (
int j = 0; j < 7; j++){
75 void Set(
const double* matrix){
76 for (
int i = 0;
i < 7*7;
i++){
77 M[
i/7][
i%7]=matrix[
i];
86 double matrix_init[49] = {
87 1.012, 1.22, 5.216e-05, 0.2599, 1.096, -0.1589, -0.0001459,
88 -0.5851, 1.042, 0.001092, -3.991e-06, 0.3103, 1.064, -3.991e-06,
89 -0.04447, -0.04501, 0.001764, 11.24, -0.04385, 0.007135, 0.0001733,
90 -1.36e-15, 1.816e-14, 3.031e-15, 1, 1.513e-16, -2.272e-16, 7.904e-17,
91 0.006668, 1.356, -0.0001811, 0.000127, 0.9794, -0.1215, 0.4001,
92 -0.6638, 0.04068, 0.001168, -7.627e-06, 0.2952, 0.9388, -7.627e-06,
93 -1.003e-15, -3.248e-15, 9.487e-17, 5.594e-18, 2.41e-16, -1.086e-16, 1
98 double matrix_init[49] = {
99 0.9633, 0.2086, -0.01173, 0.2598, 1.123, -0.03217, -0.0002463,
100 -0.104, 0.97, -0.006443, 5.119e-06, 0.06427, 1.12, 5.119e-06,
101 -0.03828, 0.005853, 0.004478, 11.24, -0.0447, 0.001794, 2.613e-06,
102 2.376e-06, -0.0003806, -2.583e-07, 1, -1.647e-05, -1.871e-05, -3.862e-07,
103 -0.01744, 0.1777, -0.01384, 0.0001758, 0.9997, -0.02581, 0.4002,
104 -0.09394, -0.05056, -0.002047, 3.624e-05, 0.06091, 0.994, 3.624e-05,
105 2.376e-06, -0.0003806, -2.583e-07, -3.862e-07, -1.647e-05, -1.871e-05, 1
109 cout <<
" Warning in PndLmdDimPropMat: loading identity matrix only " << endl;
110 double matrix_init[49] = {
127 double mommag = momdir.Mag();
129 double xip[7] = {pos.X()/100., pos.Y()/100., pos.Z()/100., 1, momdir.X()/momdir.Z()*10., momdir.Y()/momdir.Z()*10., 1};
130 double xlmd[7] = {0,0,0,0,0,0,0};
131 for (
int i = 0;
i < 7;
i++){
132 for (
int j = 0; j < 7; j++){
133 xlmd[
i] += M[
i][j] * xip[j];
136 pos.SetXYZ(xlmd[0]*100., xlmd[1]*100., xlmd[2]*100.);
137 momdir.SetXYZ(xlmd[4]/10., xlmd[5]/10., 1.);
138 momdir = momdir.Unit()*mommag;
151 if (half < comp.
half)
return true;
152 if (half > comp.
half)
return false;
153 if (plane < comp.
plane)
return true;
154 if (plane > comp.
plane)
return false;
155 if (module < comp.
module)
return true;
156 if (module > comp.
module)
return false;
157 if (side < comp.
side)
return true;
158 if (side > comp.
side)
return false;
159 if (die < comp.
die)
return true;
160 if (die > comp.
die)
return false;
167 return (half == comp.
half) &&
168 (plane == comp.
plane) &&
169 (module == comp.
module) &&
170 (side == comp.
side) &&
184 Tkey (
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor){
197 for (
unsigned int ichar = 0; ichar < key.size(); ichar++){
198 if (key[ichar] ==
'-'){
201 if (isdigit(key[ichar])){
202 number = (key[ichar]-
'0')*sign;
204 if (ikey == 0) half = number;
205 if (ikey == 1) plane = number;
206 if (ikey == 2) module = number;
207 if (ikey == 3) side = number;
208 if (ikey == 4) die = number;
209 if (ikey == 5)
sensor = number;
213 if (ikey != 6) cout <<
" Error in Generate_Tkey: key string " << key <<
" is not valid " << endl;
255 bool Set_sensIDoffset(
int offset = -1);
501 bool Is_valid_idcall(
int ihalf,
int iplane = 0,
int imodule = 0,
int iside = 0,
int idie = 0,
int isensor = 0){
502 if (ihalf < 0 || ihalf >= 2)
504 if (iplane < 0 || (
unsigned)iplane >= n_planes)
506 if (imodule < 0 || imodule >= n_cvd_discs)
508 if (iside < 0 || iside >= 2)
510 if (idie < 0 || idie >= 2)
513 if (isensor < 0 || isensor >= n_sensors + 1)
519 int Get_sensor_id(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor){
520 if (idie == 1) isensor += 2;
521 int result = isensor + (iside + (imodule + (iplane + ihalf * n_planes) * nmodules) * 2 ) * n_sensors;
522 return result + sensIDoffset;
526 void Get_sensor_by_id(
const int sensor_id,
int& ihalf,
int& iplane,
int& imodule,
int& iside,
int& idie,
int& isensor){
527 int _sensor_id = sensor_id - sensIDoffset;
528 isensor = _sensor_id % n_sensors;
534 _sensor_id /= n_sensors;
535 iside = _sensor_id % 2;
537 imodule = _sensor_id % nmodules;
538 _sensor_id /= nmodules;
539 iplane = _sensor_id % n_planes;
540 _sensor_id /= n_planes;
541 ihalf = _sensor_id % 2;
542 if (!Is_valid_idcall(ihalf, iplane, imodule, iside, idie, isensor)){
549 cout <<
"Error in PndLmdDim::Get_sensor_by_id: "<< sensor_id <<
" is not a valid sensor id!" << endl;
572 char*
itoa(
int value,
char* result,
int base) {
575 if (base < 2 || base > 36) { *result =
'\0';
return result; }
576 char* ptr = result, *ptr1 = result, tmp_char;
581 *ptr++ =
"zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)];
584 if (tmp_value < 0) *ptr++ =
'-';
596 string Generate_key(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor){
599 ptr = itoa(ihalf, key, 10);
600 ptr = itoa(iplane, ptr, 10);
601 ptr = itoa(imodule, ptr, 10);
602 ptr = itoa(iside, ptr, 10);
603 ptr = itoa(idie, ptr, 10);
604 ptr = itoa(isensor, ptr, 10);
615 unsigned int iside = 0,
unsigned int idie = 0,
unsigned int isensor = 0){
616 stringstream keystream;
617 keystream << ihalf << iplane << imodule << iside << idie << isensor;
619 key = atoi(keystream.str().c_str());
650 void Read_transformation_matrices(
string filename =
"",
bool aligned =
true,
int version_number = geometry_version);
659 void Write_transformation_matrices(
string filename,
bool aligned =
true,
int version_number = geometry_version);
668 bool Read_transformation_matrices_from_geometry(
bool aligned =
true);
682 bool Write_transformation_matrices_to_geometry(
bool aligned =
true);
690 string Get_List_of_Sensors(vector <string>& list_of_sensors,
bool found_lmd =
false,
bool first_call =
true);
696 bool Test_List_of_Sensors(vector <string> list_of_sensors,
int&
offset);
701 void Get_offset(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
702 double&
x,
double&
y,
double&
z,
703 double& rotphi,
double& rottheta,
double& rotpsi,
bool random =
false);
708 void Set_offset(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
709 double x,
double y,
double z,
710 double rotphi,
double rottheta,
double rotpsi);
717 void Correct_transformation_matrices();
718 void reCreate_transformation_matrices();
727 double& rotx,
double& roty,
double& rotz,
728 bool misaligned =
false){
735 if (misaligned) rotx += 0;
746 TVector3 Decode_hit(
const int sensorID,
const double column,
const double row,
const bool aligned =
true,
bool newVersion=
false);
759 void Propagate_fast_ip_to_lmd(TVector3&
pos, TVector3&
mom,
double pbeam);
770 bool Get_overlapping_sensor(
const TVector3&
point,
int& ihalf,
int& iplane,
int& imodule,
int& iside,
int& idie,
int& isensor,
bool aligned =
true);
775 bool Is_on_Sensor(
const TVector3&
point,
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
781 int Get_overlapping_sensor(
int idie,
int isensor, vector<int> &jdie, vector<int> &jsensor);
785 TGeoHMatrix Get_transformation_global_to_lmd_local(
bool aligned =
true);
789 TGeoHMatrix Get_transformation_lmd_local_to_module_side(
790 int ihalf,
int iplane,
int imodule,
int iside,
bool aligned =
true);
794 TGeoHMatrix Get_transformation_module_side_to_sensor(
795 int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
799 TGeoHMatrix Get_transformation_global_to_sensor(
800 int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
804 TGeoHMatrix Get_transformation_lmd_local_to_sensor(
805 int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
809 TGeoHMatrix Get_transformation_lmd_local_to_global(
bool aligned =
true);
813 TGeoHMatrix Get_transformation_module_side_to_lmd_local(
814 int ihalf,
int iplane,
int imodule,
int iside,
bool aligned =
true);
818 TGeoHMatrix Get_transformation_sensor_to_module_side(
819 int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
823 TGeoHMatrix Get_transformation_sensor_to_global(
824 int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
828 TGeoHMatrix Get_transformation_sensor_to_lmd_local(
829 int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
833 TGeoHMatrix Get_transformation_sensor_to_sensor_aligned(
834 int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor);
837 TGeoHMatrix Get_transformation_sensor_aligned_to_sensor(
838 int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor);
844 TVector3 Transform_global_to_lmd_local(
const TVector3&
point,
bool isvector =
false,
bool aligned =
true);
848 TVector3 Transform_lmd_local_to_module_side(
const TVector3&
point,
849 int ihalf,
int iplane,
int imodule,
int iside,
bool isvector =
false,
bool aligned =
true);
853 TVector3 Transform_module_side_to_sensor(
const TVector3&
point,
854 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,
859 int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool isvector =
false,
bool aligned =
true);
863 TVector3 Transform_lmd_local_to_sensor(
const TVector3&
point,
864 int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool isvector =
false,
bool aligned =
true);
868 TVector3 Transform_lmd_local_to_global(
const TVector3&
point,
bool isvector =
false,
bool aligned =
true);
872 TVector3 Transform_module_side_to_lmd_local(
const TVector3&
point,
873 int ihalf,
int iplane,
int imodule,
int iside,
bool isvector =
false,
bool aligned =
true);
877 TVector3 Transform_sensor_to_module_side(
const TVector3&
point,
878 int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool isvector =
false,
bool aligned =
true);
882 TVector3 Transform_sensor_to_global(
const TVector3&
point,
883 int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool isvector =
false,
bool aligned =
true);
887 TVector3 Transform_sensor_to_lmd_local(
const TVector3&
point,
888 int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool isvector =
false,
bool aligned =
true);
891 TVector3 Transform_sensor_to_sensor_aligned(
const TVector3&
point,
892 int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool isvector =
false);
895 TVector3 Transform_sensor_aligned_to_sensor(
const TVector3&
point,
896 int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool isvector =
false);
899 TVector3 Transform_sensor_to_sensor(
const TVector3&
point,
900 int ihalf_from,
int iplane_from,
int imodule_from,
int iside_from,
int idie_from,
int isensor_from,
901 int ihalf_to,
int iplane_to,
int imodule_to,
int iside_to,
int idie_to,
int isensor_to,
902 bool isvector =
false,
bool aligned =
true);
909 TMatrixD Transform_global_to_lmd_local(
const TMatrixD& matrix,
bool aligned =
true);
915 int ihalf,
int iplane,
int imodule,
int iside,
bool aligned =
true);
921 int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
928 int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
934 int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
939 TMatrixD Transform_lmd_local_to_global(
const TMatrixD& matrix,
bool aligned =
true);
945 int ihalf,
int iplane,
int imodule,
int iside,
bool aligned =
true);
951 int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
957 int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
963 int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
968 int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor);
973 int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor);
978 int ihalf_from,
int iplane_from,
int imodule_from,
int iside_from,
int idie_from,
int isensor_from,
979 int ihalf_to,
int iplane_to,
int imodule_to,
int iside_to,
int idie_to,
int isensor_to,
bool aligned =
true);
987 map<Tkey, TGeoMatrix* >* Get_matrices(
bool aligned =
true);
993 TGeoMatrix* Get_matrix(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
1003 TGeoHMatrix* Get_matrix(
string path,
bool aligned =
true,
1004 int ihalf = -1,
int iplane= -1,
int imodule = -1,
int iside = -1,
int idie = -1,
int isensor = -1);
1013 bool Set_matrix(
string path, TGeoHMatrix* matrix,
1014 int ihalf = -1,
int iplane= -1,
int imodule = -1,
int iside = -1,
int idie = -1,
int isensor = -1);
1021 bool Get_matrix_difference(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
1022 double&
dx,
double&
dy,
double&
dz,
double& dphi,
double&
dtheta,
double& dpsi);
1028 void Calc_matrix_offsets();
1031 TGeoMatrix* Get_matrix_global_to_lmd_local(
bool aligned =
true);
1034 TGeoMatrix* Get_matrix_lmd_local_to_module_side(
int ihalf,
int iplane,
int imodule,
int iside,
bool aligned =
true);
1037 TGeoMatrix* Get_matrix_module_side_to_sensor(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true);
1043 void Transform_global_to_lmd_local(
double&
x,
double&
y,
double&
z,
bool aligned =
true);
1047 void Transform_global_to_lmd_local_vect(
double&
x,
double&
y,
double&
z,
bool aligned =
true);
1070 void Generate_rootgeom(TGeoVolume& mothervol,
bool misaligned =
false);
1075 bool Retrieve_version_number();
1078 void Test_matrices();
1083 void Draw_Sensors(
int iplane,
bool aligned =
true,
bool lmd_frame =
true,
int glside = 2);
1089 TPolyLine* Get_Sensor_Shape(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true,
bool lmd_frame =
true);
1101 vector<TGraph*> 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);
1110 TH2Poly* Get_histogram_Plane(
int iplane,
int iside,
bool aligned =
true,
bool lmd_frame =
true,
bool pixel_subdivision =
false);
1119 TH2Poly* Get_histogram_Moduleside(
int ihalf,
int iplane,
int imodule,
int iside,
bool aligned =
true,
bool lmd_frame =
true,
bool pixel_subdivision =
true);
1128 TH2Poly* Get_histogram_Sensor(
int ihalf,
int iplane,
int imodule,
int iside,
int idie,
int isensor,
bool aligned =
true,
bool lmd_frame =
true);
1131 std::vector<int> getAvailableOverlapIDs();
1132 int makeOverlapID(
int firstSensorId,
int secondSensorId);
1133 int getID1fromOverlapID(
int overlapID);
1134 int getID2fromOverlapID(
int overlapID);
1137 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
void Propagate(TVector3 &pos, TVector3 &momdir)
double plane_half_tilt_phi
double maps_passive_right
bool operator==(const GFDetPlane &lhs, const GFDetPlane &rhs)
PndLmdDim & operator=(const PndLmdDim &instance)
void Get_List_of_Sensors(vector< string > &list_of_sensors, bool all_nodes=false, bool first_call=true)
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
static PndLmdDim * pinstance
unsigned int sensIDoffset
double cvd_disc_thick_half
bool Set_matrix(string path, TGeoHMatrix *matrix, string uniquename, int uniqueID)
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
map< Tkey, TGeoMatrix * > transformation_matrices_aligned
map< Tkey, TGeoMatrix * > transformation_matrices
double maps_active_offset_y
double cvd_disc_even_odd_offset
static int geometry_version
map< Tkey, vector< double > > offsets
void Set(const double *matrix)
double plane_half_offset_x
PndLmdDimPropMat(double mom_init)
double maps_active_height
map< Tkey, TGeoMatrix * >::iterator it_transformation_matrices
double plane_half_offset_z
vector< string > nav_paths
map< double, PndLmdDimPropMat > propagation_matrices
friend F32vec4 operator<(const F32vec4 &a, const F32vec4 &b)
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