54 vector<string> values;
59 line = (line.find(
"#") != string::npos) ?
60 line.substr(0, line.find_first_of(
"#")) :
63 size_t foundAdress = line.find(a_key);
65 if (foundAdress != string::npos)
67 values =
Split(a_line);
68 values.erase (values.begin());
87 vector<string>
Split(
string a_line)
90 stringstream ss(a_line);
92 vector<string> tokens;
95 tokens.push_back(buf);
115 for(uint16_t i=0; i < ap_v.size(); i++)
119 for (
int j=0; j<i; j++)
141 int WriteVector(ofstream& file,
const string& a_key, vector <T> a_vals)
143 int n = a_vals.size();
148 for (
int i=0; i < n; i++)
153 file << ss.str() << endl;
155 file << ss.str() <<
",";
159 file << a_key <<
"0" <<endl;
164 template int WriteVector(ofstream& file,
const string& a_key, vector <double> a_vals);
180 int WriteVector(ofstream& file,
const string& a_key, vector <string> a_vals)
182 int n = a_vals.size();
187 for (
int i=0; i < n; i++)
190 file << a_vals[i] << endl;
192 file << a_vals[i] <<
",";
196 file << a_key <<
"0" <<endl;
215 int WriteVector(ofstream& file,
const string& a_key, vector <vector<string> > a_vals)
217 int n = a_vals.size();
219 for (
int i=0; i < n; i++)
220 for (
int j=0; j < 3; j++)
221 if (i == n-1 && j == 2)
222 file << a_vals[i][j] << endl;
224 file << a_vals[i][j] <<
",";
245 ifstream mac_file(a_pathMac, ios::in);
251 while(getline(mac_file, quickLine))
253 vector <string> values;
261 char first_char = values[0].at(0);
263 if(first_char ==
'/')
264 ap_pathToMacFiles.push_back(values[0]);
267 ap_pathToMacFiles.push_back(
GetPathOfFile(a_pathMac)+values[0]);
274 Cerr(
"***** GetGATEMacFiles() -> Couldn't open mac file "<< a_pathMac <<
" !" << endl);
300 vector<string> path_mac_files;
301 path_mac_files.push_back(a_pathMac);
305 Cerr(
"***** GetGATESystemType() ->Error occurred when trying to recover paths to GATE macro files !" << endl);
309 for(uint16_t f=0 ; f<path_mac_files.size() ; f++)
310 cout << f <<
" : " << path_mac_files[f] << endl;
313 for(uint16_t f=0 ; f<path_mac_files.size() ; f++)
315 ifstream mac_file(path_mac_files[f], ios::in);
320 while(getline(mac_file, line))
323 if(line.find(
"/gate/systems/") != string::npos )
325 if(line.find(
"/gate/systems/ecat") != string::npos )
328 if(line.find(
"/gate/systems/cylindricalPET") != string::npos )
331 if(line.find(
"/gate/systems/SPECThead") != string::npos )
334 if(line.find(
"/gate/systems/OPET") != string::npos ||
335 line.find(
"/gate/systems/CTSCANNER") != string::npos ||
336 line.find(
"/gate/systems/CPET") != string::npos ||
337 line.find(
"/gate/systems/ecatAccel") != string::npos ||
338 line.find(
"/gate/systems/OpticalSystem") != string::npos )
340 Cerr(
"unsupported system detected (line = " << line <<
") ! "<< endl);
341 Cerr(
"supported systems for this script are cylindricalPET, SPECThead, and ecat" << endl);
348 Cerr(
"***** GetGATESystemType() -> Error : Couldn't open mac file "<< path_mac_files[f] <<
" !" << endl);
385 string& rsector_name,
387 string& submodule_name,
388 string& crystal_name,
389 vector<string>& layers_name,
394 for(uint16_t f=0 ; f<path_mac_files.size() ; f++)
396 ifstream mac_file(path_mac_files[f].c_str(), ios::in);
401 while(getline(mac_file, quickLine))
403 vector <string> values;
405 values =
CheckGATECommand(
"/gate/systems/cylindricalPET/rsector/attach", quickLine);
409 rsector_name = values[0];
413 values =
CheckGATECommand(
"/gate/systems/cylindricalPET/module/attach", quickLine);
416 module_name = values[0];
420 values =
CheckGATECommand(
"/gate/systems/cylindricalPET/submodule/attach", quickLine);
423 submodule_name = values[0];
427 values =
CheckGATECommand(
"/gate/systems/cylindricalPET/crystal/attach", quickLine);
430 crystal_name = values[0];
439 values =
CheckGATECommand(
"/gate/systems/cylindricalPET/layer"+ss.str()+
"/attach", quickLine);
442 layers_name.push_back(values[0]);
451 Cerr(
"***** GetGATEAliasesCylindrical()->Couldn't open mac file "<< path_mac_files[f] <<
" !" << endl);
462 Cout(
"***** GetGATEAliasesCylindrical() :: Error : Missing elements in the system architecture" << endl <<
463 " At least two of the following lines are required :" << endl <<
464 " - /gate/systems/cylindricalPET/rsector/attach" << endl <<
465 " - /gate/systems/cylindricalPET/module/attach" << endl <<
466 " - /gate/systems/cylindricalPET/submodule/attach" << endl <<
467 " - /gate/systems/cylindricalPET/crystal/attach" << endl <<
468 " - /gate/systems/cylindricalPET/layeri[i=0..3]/attach" << endl);
474 if(rsector_name.empty())
476 if(module_name.empty())
479 rsector_name = submodule_name;
485 rsector_name = module_name;
492 if(!rsector_name.empty())
Cout(
"Detected rsector container's name : " << rsector_name << endl);
493 if(!module_name.empty())
Cout(
"Detected module container's name : " << module_name << endl);
494 if(!submodule_name.empty())
Cout(
"Detected submodule container's name : " << submodule_name << endl);
495 if(!crystal_name.empty())
Cout(
"Detected crystal container's name : " << crystal_name << endl);
496 for(
size_t l=0 ; l<layers_name.size() ; l++)
497 if(!layers_name[l].empty())
Cout(
"Detected layer #"<< l <<
" container's name : " << layers_name[l] << endl);
526 string& crystal_name,
531 for(uint16_t f=0 ; f<path_mac_files.size() ; f++)
533 ifstream mac_file(path_mac_files[f].c_str(), ios::in);
539 while(getline(mac_file, quickLine))
541 vector <string> values;
546 block_name = values[0];
553 crystal_name = values[0];
560 Cerr(
"***** GetGATEAliasesEcat()-> Couldn't open mac file "<< path_mac_files[f].c_str()<<
" !" << endl);
569 Cerr(
"***** GetGATEAliasesEcat() :: Error : Missing elements in the system architecture" << endl
570 <<
" The following lines are required :" << endl
571 <<
" - /gate/systems/ecat/block/attach" << endl
572 <<
" - /gate/systems/ecat/crystal/attach" << endl);
578 Cout(
"First container's name (usually block) is : " << block_name << endl
579 <<
"Second container's name (usually crystal) is : " << crystal_name << endl);
610 string& crystal_name,
616 for(uint16_t f=0 ; f<path_mac_files.size() ; f++)
618 ifstream mac_file(path_mac_files[f].c_str(), ios::in);
625 while(getline(mac_file, quickLine))
627 vector <string> values;
629 values =
CheckGATECommand(
"/gate/systems/SPECThead/base/attach", quickLine);
632 base_name = values[0];
636 values =
CheckGATECommand(
"/gate/systems/SPECThead/crystal/attach", quickLine);
639 crystal_name = values[0];
643 values =
CheckGATECommand(
"/gate/systems/SPECThead/pixel/attach", quickLine);
646 pixel_name = values[0];
654 Cerr(
"***** GetGATEAliasesSPECT()-> Couldn't open mac file "<< path_mac_files[f].c_str()<<
" !" << endl);
662 Cerr(
"***** GetGATEAliasesSPECT() :: Error : Missing elements in the system architecture" << endl
663 <<
" The following line is required :" << endl
664 <<
" - /gate/systems/SPECThead/crystal/attach" << endl);
670 Cout(
"Crystal container's name is : " << crystal_name << endl);
696 int32_t nCrystalsTransaxial,
697 int32_t nCrystalsAxial,
701 int32_t nCrystalsPerRing = nBlocksPerRing * nCrystalsTransaxial;
703 int32_t ringID = (int32_t)( blockID/nBlocksPerRing ) * nCrystalsAxial
704 + (int32_t)( crystalID/nCrystalsTransaxial );
706 int32_t castorID = nCrystalsPerRing * ringID
707 + nCrystalsTransaxial*( blockID % nBlocksPerRing )
708 + crystalID % nCrystalsTransaxial;
731 uint32_t a_nProjectionsByHead)
734 int32_t angID = round(a_rotAngle/a_angStep);
737 int32_t castorID = a_headID*a_nProjectionsByHead + angID;
774 float_t a_headAngPitch,
775 float_t a_crystalSizeAxl,
776 float_t a_crystalSizeTrs,
781 int32_t castorID = 0;
784 if (a_nbSimulatedPixels > 1)
786 castorID = a_pixelID;
793 FLTNB sizePixTrs = a_crystalSizeTrs/a_nPixTrs;
794 FLTNB sizePixAxl = a_crystalSizeAxl/a_nPixAxl;
797 uint32_t axialID = (uint32_t)(( a_gPosZ + a_nPixAxl/2*sizePixAxl) / sizePixAxl);
801 float_t ang = a_headID*a_headAngPitch + a_rotAngle;
804 float_t sin_a = sin(-ang*M_PI/180);
805 float_t cos_a = cos(-ang*M_PI/180);
806 float_t trs_pos = a_gPosX*sin_a + a_gPosY*cos_a ;
809 uint32_t transID = (uint32_t)(( trs_pos + a_nPixTrs/2*sizePixTrs) / sizePixTrs);
811 if ( axialID < a_nPixAxl && transID < a_nPixTrs )
813 castorID = axialID*a_nPixTrs + transID;
817 castorID = a_nPixAxl*a_nPixTrs;
829 uint32_t nRsectorsAxial,
830 bool a_invertDetOrder,
831 int a_rsectorIdOrder,
832 uint32_t nModulesTransaxial,
833 uint32_t nModulesAxial,
834 uint32_t nSubmodulesTransaxial,
835 uint32_t nSubmodulesAxial,
836 uint32_t nCrystalsTransaxial,
837 uint32_t nCrystalsAxial,
839 uint32_t* nCrystalPerLayer,
840 vector<uint32_t> nLayersRptTransaxial,
841 vector<uint32_t> nLayersRptAxial,
849 uint32_t castorID = 0;
853 if(nLayersRptTransaxial.size()==0 && nLayersRptAxial.size()==0)
861 for(
int l=0 ; l<layer; l++)
862 castorID += nCrystalPerLayer[l];
864 int32_t nTrsCrystalsPerSubmodule = nCrystalsTransaxial;
865 int32_t nTrsCrystalsPerModule = nTrsCrystalsPerSubmodule * nSubmodulesTransaxial;
866 int32_t nTrsCrystalsPerRsector = nTrsCrystalsPerModule * nModulesTransaxial;
867 int32_t nCrystalsPerRing = nTrsCrystalsPerRsector * nRsectorsAngPos;
871 int32_t rsectorAxlID = 0 ;
872 int32_t rsectorTrsID = 0 ;
875 if(a_rsectorIdOrder == 0)
877 rsectorAxlID = rsectorID/nRsectorsAngPos ;
878 rsectorTrsID = (int32_t)(rsectorID%nRsectorsAngPos) ;
882 rsectorAxlID = rsectorID%nRsectorsAxial ;
883 rsectorTrsID = (int32_t)(rsectorID/nRsectorsAxial) ;
888 int32_t ringID = rsectorAxlID * nModulesAxial * nSubmodulesAxial * nCrystalsAxial
889 + (int32_t)(moduleID/nModulesTransaxial) * nSubmodulesAxial * nCrystalsAxial
890 + (int32_t)(submoduleID/nSubmodulesTransaxial) * nCrystalsAxial
891 + (int32_t)(crystalID/nCrystalsTransaxial);
894 moduleID = moduleID % nModulesTransaxial;
895 submoduleID = submoduleID % nSubmodulesTransaxial;
896 crystalID = crystalID % nCrystalsTransaxial;
899 if( a_invertDetOrder )
901 moduleID = nModulesTransaxial-1 - moduleID;
902 submoduleID = nSubmodulesTransaxial-1 - submoduleID;
903 crystalID = nCrystalsTransaxial-1 - crystalID;
907 castorID += nCrystalsPerRing * ringID
908 + nTrsCrystalsPerRsector * rsectorTrsID
909 + nTrsCrystalsPerModule * moduleID
910 + nTrsCrystalsPerSubmodule * submoduleID
919 uint32_t sum_detectors_prev_layers = 0;
924 while ( layerID >= (int32_t)( sum_detectors_prev_layers
925 + ( nLayersRptTransaxial[layer]
926 * nLayersRptAxial[layer]) ) )
929 sum_detectors_prev_layers += nLayersRptTransaxial[layer]
930 * nLayersRptAxial[layer];
938 if (layer>0)layerID -= sum_detectors_prev_layers;
942 for(
int l=0 ; l<layer ; l++)
943 castorID += nCrystalPerLayer[l];
945 int32_t nTrsCrystalsPerSubmodule = nCrystalsTransaxial * nLayersRptTransaxial[layer];
946 int32_t nTrsCrystalsPerModule = nTrsCrystalsPerSubmodule * nSubmodulesTransaxial;
947 int32_t nTrsCrystalsPerRsector = nTrsCrystalsPerModule * nModulesTransaxial;
948 int32_t nCrystalsPerRing = nTrsCrystalsPerRsector * nRsectorsAngPos;
952 int32_t rsectorAxlID = 0 ;
953 int32_t rsectorTrsID = 0 ;
956 if(a_rsectorIdOrder == 0)
958 rsectorAxlID = rsectorID/nRsectorsAngPos ;
959 rsectorTrsID = (int32_t)(rsectorID%nRsectorsAngPos) ;
963 rsectorAxlID = rsectorID%nRsectorsAxial ;
964 rsectorTrsID = (int32_t)(rsectorID/nRsectorsAxial) ;
969 int32_t ringID = rsectorAxlID * nModulesAxial * nSubmodulesAxial * nCrystalsAxial * nLayersRptAxial[layer]
970 + (int32_t)(moduleID/nModulesTransaxial) * nSubmodulesAxial * nCrystalsAxial * nLayersRptAxial[layer]
971 + (int32_t)(submoduleID/nSubmodulesTransaxial) * nCrystalsAxial * nLayersRptAxial[layer]
972 + (int32_t)(crystalID/nCrystalsTransaxial) * nLayersRptAxial[layer];
975 if(!nLayersRptTransaxial.empty() )
976 ringID += (int32_t)(layerID/nLayersRptTransaxial[layer]);
980 moduleID = moduleID % nModulesTransaxial;
981 submoduleID = submoduleID % nSubmodulesTransaxial;
982 crystalID = crystalID % nCrystalsTransaxial;
983 layerID = layerID % nLayersRptTransaxial[layer];
986 if( a_invertDetOrder )
988 moduleID = nModulesTransaxial-1 - moduleID;
989 submoduleID = nSubmodulesTransaxial-1 - submoduleID;
990 crystalID = nCrystalsTransaxial-1 - crystalID;
991 layerID = nLayersRptTransaxial[layer]-1 - layerID;
995 castorID += nCrystalsPerRing * ringID
996 + nTrsCrystalsPerRsector * rsectorTrsID
997 + nTrsCrystalsPerModule * moduleID
998 + nTrsCrystalsPerSubmodule * submoduleID
1024 int comptonPhantom1,
int comptonPhantom2,
1025 int rayleighPhantom1,
int rayleighPhantom2)
1027 if (eventID1 != eventID2)
1032 if (comptonPhantom1 == 0 && comptonPhantom2 == 0 &&
1033 rayleighPhantom1 == 0 && rayleighPhantom2 == 0)
1038 if (comptonPhantom1 == 1 || comptonPhantom2 == 1 ||
1039 rayleighPhantom1 == 1 || rayleighPhantom2 == 1)
1042 if (comptonPhantom1 > 1 || comptonPhantom2 > 1 ||
1043 rayleighPhantom1 > 1 || rayleighPhantom2 > 1)
1083 uint32_t *nb_crystal_per_layer,
1084 uint32_t &nCrystalsTot,
1085 uint32_t &nCrystalsAxial,
1086 uint32_t &nCrystalsTransaxial,
1087 vector<uint32_t> &nLayersRptAxial,
1088 vector<uint32_t> &nLayersRptTransaxial,
1089 uint32_t &nSubmodulesAxial,
1090 uint32_t &nSubmodulesTransaxial,
1091 uint32_t &nModulesAxial,
1092 uint32_t &nModulesTransaxial,
1093 uint32_t &nRsectorsAxial,
1094 uint32_t &nRsectorsAngPos,
1095 bool &invert_det_order,
1096 int &rsector_id_order,
1097 uint32_t &start_time_ms,
1098 uint32_t &duration_ms,
1099 FLTNB &pet_coinc_window,
1102 vector<string> path_mac_files;
1103 path_mac_files.push_back(a_pathMac);
1108 Cerr(
"***** GetGATESystemType() ->Error occurred when trying to recover paths to GATE macro files !" << endl);
1112 string rsector_name =
"";
1113 string module_name =
"";
1114 string submodule_name =
"";
1115 string crystal_name =
"";
1116 string mod_rptr_type =
"cubicArray";
1117 string smod_rptr_type =
"cubicArray";
1118 string cry_rptr_type =
"cubicArray";
1119 string lay_rptr_type =
"cubicArray";
1121 vector <string> layers_name;
1122 bool is_rsector_Y_axis =
false;
1125 if(
GetGATEAliasesCylindrical(path_mac_files, rsector_name, module_name, submodule_name, crystal_name, layers_name, vb) )
1127 Cerr(
"***** GetGATESystemType() ->Error occurred when trying to recover aliases for the elements of the cylindricalPET !" << endl);
1132 nLayers = layers_name.size();
1135 for(uint16_t f=0 ; f<path_mac_files.size() ; f++)
1137 ifstream mac_file(path_mac_files[f].c_str(), ios::in);
1140 double time_start =-1.,
1144 while(getline(mac_file, line))
1146 vector <string> values;
1152 kword =
"/gate/"+rsector_name+
"/placement/setTranslation";
1156 if (values.size()>0)
1158 FLTNB rsector_pos_X =0.,
1164 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
1169 if(rsector_pos_Y!=0) is_rsector_Y_axis =
true;
1175 if(rsector_pos_Y > 0 || rsector_pos_X < 0)
1176 invert_det_order =
true;
1181 kword =
"/gate/"+rsector_name+
"/ring/setRepeatNumber";
1183 if (values.size()>0)
1187 Cerr(
"***** dataConversionUtilities::readMacCylindrical()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
1194 kword =
"/gate/"+rsector_name+
"/linear/setRepeatNumber";
1196 if (values.size()>0)
1200 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
1207 kword =
"/gate/"+rsector_name+
"/cubicArray/setRepeatNumberZ";
1210 if (values.size()>0)
1214 rsector_id_order = nRsectorsAngPos>1 ? 1 : 0 ;
1218 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
1229 kword = is_rsector_Y_axis ?
1230 "/gate/"+module_name+
"/cubicArray/setRepeatNumberX":
1231 "/gate/"+module_name+
"/cubicArray/setRepeatNumberY";
1234 if (values.size()>0)
1238 Cerr(
"***** dataConversionUtilities::readMacCylindrical()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
1243 kword =
"/gate/"+module_name+
"/cubicArray/setRepeatNumberZ";
1245 if (values.size()>0)
1249 Cerr(
"***** dataConversionUtilities::readMacCylindrical()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
1255 kword =
"/gate/"+module_name+
"/linear/setRepeatNumber";
1257 if (values.size()>0)
1261 Cerr(
"***** dataConversionUtilities::readMacCylindrical()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
1269 kword = is_rsector_Y_axis ?
1270 "/gate/"+submodule_name+
"/cubicArray/setRepeatNumberX":
1271 "/gate/"+submodule_name+
"/cubicArray/setRepeatNumberY";
1274 if (values.size()>0)
1278 Cerr(
"***** dataConversionUtilities::readMacCylindrical()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
1283 kword =
"/gate/"+submodule_name+
"/cubicArray/setRepeatNumberZ";
1285 if (values.size()>0)
1289 Cerr(
"***** dataConversionUtilities::readMacCylindrical()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
1295 kword =
"/gate/"+submodule_name+
"/linear/setRepeatNumber";
1297 if (values.size()>0)
1301 Cerr(
"***** dataConversionUtilities::readMacCylindrical()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
1310 kword = is_rsector_Y_axis ?
1311 "/gate/"+crystal_name+
"/cubicArray/setRepeatNumberX":
1312 "/gate/"+crystal_name+
"/cubicArray/setRepeatNumberY";
1315 if (values.size()>0)
1319 Cerr(
"***** dataConversionUtilities::readMacCylindrical()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
1324 kword =
"/gate/"+crystal_name+
"/cubicArray/setRepeatNumberZ";
1326 if (values.size()>0)
1330 Cerr(
"***** dataConversionUtilities::readMacCylindrical()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
1337 kword =
"/gate/"+crystal_name+
"/linear/setRepeatNumber";
1339 if (values.size()>0)
1343 Cerr(
"***** dataConversionUtilities::readMacCylindrical()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
1352 for(
int l=0 ; l<nLayers ; l++)
1354 kword = is_rsector_Y_axis ?
1355 "/gate/"+layers_name[l]+
"/cubicArray/setRepeatNumberX":
1356 "/gate/"+layers_name[l]+
"/cubicArray/setRepeatNumberY";
1359 if (values.size()>0)
1364 Cerr(
"***** dataConversionUtilities::readMacCylindrical()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
1367 nLayersRptTransaxial.push_back(val);
1370 kword =
"/gate/"+layers_name[l]+
"/cubicArray/setRepeatNumberZ";
1372 if (values.size()>0)
1377 Cerr(
"***** dataConversionUtilities::readMacCylindrical()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
1380 nLayersRptAxial.push_back(val);
1384 kword =
"/gate/"+layers_name[l]+
"/linear/setRepeatNumber";
1386 if (values.size()>0)
1391 Cerr(
"***** dataConversionUtilities::readMacCylindrical()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
1394 nLayersRptAxial.push_back(val);
1401 kword =
"/gate/application/setTimeStart";
1403 if (values.size()>0)
1407 Cerr(
"***** dataConversionUtilities::readMacCylindrical()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
1412 if (values.size()>1)
1414 if(values[1] ==
"s") time_start *= 1000;
1417 Cerr(
"***** dataConversionUtilities::readMacCylindrical()-> WARNING : can't read unit of '"<< kword <<
". Assuming time in seconds");
1419 start_time_ms = time_start;
1422 kword =
"/gate/application/setTimeStop";
1424 if (values.size()>0)
1428 Cerr(
"***** dataConversionUtilities::readMacCylindrical()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
1433 if (values.size()>1)
1435 if(values[1] ==
"s") time_stop *= 1000;
1438 Cerr(
"***** dataConversionUtilities::readMacCylindrical()-> WARNING : can't read unit of '"<< kword <<
". Assuming time in seconds");
1441 kword =
"/gate/application/addSlice";
1443 if (values.size()>0)
1445 double time_slice_tmp=0;
1449 Cerr(
"***** dataConversionUtilities::readMacCylindrical()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
1454 if (values.size()>1)
1456 if(values[1] ==
"s") time_slice_tmp *= 1000;
1459 Cerr(
"***** dataConversionUtilities::readMacCylindrical()-> WARNING : can't read unit of '"<< kword <<
". Assuming time in seconds");
1461 time_slices += time_slice_tmp;
1464 kword =
"/gate/digitizer/Coincidences/setWindow";
1466 if (values.size()>0)
1470 Cerr(
"***** dataConversionUtilities::readMacCylindrical()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
1475 if (values.size()>1)
1477 if(values[1] ==
"ns") pet_coinc_window *= 1000.;
1478 else if (values[1] ==
"us") pet_coinc_window *= 1000000.;
1479 else if (values[1] ==
"ps") ;
1482 Cerr(
"***** dataConversionUtilities::readMacCylindrical()-> ERROR : can't read unit of '"<< kword <<
". Must be ns, ps or us !!!");
1488 Cerr(
"***** dataConversionUtilities::readMacCylindrical()-> WARNING : can't read unit of '"<< kword <<
". Assuming time in ns");
1495 duration_ms = (time_slices>0) ?
1496 (uint32_t)(time_slices-time_start) :
1499 duration_ms = (time_start>=0 && time_stop>=0) ?
1500 (uint32_t)(time_stop-time_start) :
1509 nCrystalsTot = nRsectorsAngPos * nRsectorsAxial
1510 * nModulesTransaxial * nModulesAxial
1511 * nSubmodulesTransaxial * nSubmodulesAxial
1512 * nCrystalsTransaxial * nCrystalsAxial;
1515 for(
int l=0 ; l<nLayers ; l++)
1517 uint32_t nb_crystals_layer = nRsectorsAngPos * nRsectorsAxial
1518 * nModulesTransaxial * nModulesAxial
1519 * nSubmodulesTransaxial * nSubmodulesAxial
1520 * nCrystalsTransaxial * nCrystalsAxial;
1523 if(nLayersRptTransaxial.size()>0 || nLayersRptAxial.size()>0 )
1524 nb_crystals_layer *= nLayersRptTransaxial[l] * nLayersRptAxial[l];
1526 nb_crystal_per_layer[l] = nb_crystals_layer;
1528 nCrystalsTot += nb_crystals_layer;
1535 Cout(
"-----------------------------------------------------------" << endl);
1536 Cout(
"ReadMacCylindrical()-> Information recovered from mac file:" << endl);
1537 Cout(
"-----------------------------------------------------------" << endl);
1538 Cout(
"Number of rsectors angular position: " << nRsectorsAngPos << endl);
1539 Cout(
"Number of axial rsectors: " << nRsectorsAxial << endl);
1540 Cout(
"Number of axial modules: " << nModulesAxial << endl);
1541 Cout(
"Number of transaxial modules: " << nModulesTransaxial << endl);
1542 Cout(
"Number of axial submodules: " << nSubmodulesAxial << endl);
1543 Cout(
"Number of transaxial submodules: " << nSubmodulesTransaxial << endl);
1544 Cout(
"Number of axial crystals: " << nCrystalsAxial << endl);
1545 Cout(
"Number of transaxial crystals: " << nCrystalsTransaxial << endl);
1548 Cout(
"Number of layers: " << (uint16_t)nLayers << endl);
1549 for(
int l=0 ; l<nLayers ; l++)
1550 Cout(
"Layer "<< l <<
" : Number of crystals: " << nb_crystal_per_layer[l] << endl);
1552 Cout(
"Total number of crystals (including layers): " << nCrystalsTot << endl);
1553 Cout(
"Acquisition start time (ms): " << start_time_ms << endl);
1554 Cout(
"Acquisition duration (ms): " << duration_ms << endl);
1555 Cout(
"-----------------------------------------------------------" << endl << endl);
1582 uint32_t &nCrystalsTot,
1583 uint32_t &nCrystalsAxial,
1584 uint32_t &nCrystalsTransaxial,
1585 uint32_t &nBlocksLine,
1586 uint32_t &nBlocksPerRing,
1587 uint32_t &start_time_ms,
1588 uint32_t &duration_ms,
1589 FLTNB &pet_coinc_window,
1593 vector<string> path_mac_files;
1594 path_mac_files.push_back(a_pathMac);
1597 Cerr(
"***** GetGATESystemType() ->Error occurred when trying to recover paths to GATE macro files !" << endl);
1601 string block_name =
"block";
1602 string crystal_name =
"crystal";
1603 bool is_block_Y_axis =
false;
1608 Cerr(
"***** GetGATESystemType() ->Error occurred when trying to recover aliases for the elements of the ecat !" << endl);
1614 for(uint16_t f=0 ; f<path_mac_files.size() ; f++)
1616 ifstream mac_file(path_mac_files[f].c_str(), ios::in);
1619 double time_start=-1.,
1623 while(getline(mac_file, line))
1625 vector <string> values;
1628 kword =
"/gate/"+block_name+
"/placement/setTranslation";
1630 if (values.size()>0)
1632 FLTNB block_pos_X=0.,
1638 Cerr(
"***** dataConversionUtilities::CreateGeomWithECAT()-> Conversion error occurred while trying to parse line: " << line<< endl);
1643 if(block_pos_Y!=0) is_block_Y_axis =
true;
1646 kword =
"/gate/"+block_name+
"/ring/setRepeatNumber";
1648 if (values.size()>0)
1652 Cerr(
"***** dataConversionUtilities::readMacECAT()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
1657 kword =
"/gate/"+block_name+
"/linear/setRepeatNumber";
1659 if (values.size()>0)
1663 Cerr(
"***** dataConversionUtilities::readMacECAT()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
1668 kword = is_block_Y_axis ?
1669 "/gate/"+crystal_name+
"/cubicArray/setRepeatNumberX":
1670 "/gate/"+crystal_name+
"/cubicArray/setRepeatNumberY";
1673 if (values.size()>0)
1677 Cerr(
"***** dataConversionUtilities::readMacECAT()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
1682 kword =
"/gate/"+crystal_name+
"/cubicArray/setRepeatNumberZ";
1684 if (values.size()>0)
1688 Cerr(
"***** dataConversionUtilities::readMacECAT()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
1694 kword =
"/gate/application/setTimeStart";
1696 if (values.size()>0)
1700 Cerr(
"***** dataConversionUtilities::readMacECAT()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
1705 if (values.size()>1)
1707 if(values[1] ==
"s") time_start *= 1000;
1710 Cerr(
"***** dataConversionUtilities::readMacECAT()-> WARNING : can't read unit of '"<< kword <<
". Assuming time in seconds");
1712 start_time_ms = time_start;
1715 kword =
"/gate/application/setTimeStop";
1717 if (values.size()>0)
1721 Cerr(
"***** dataConversionUtilities::readMacECAT()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
1726 if (values.size()>1)
1728 if(values[1] ==
"s") time_stop *= 1000;
1731 Cerr(
"***** dataConversionUtilities::readMacECAT()-> WARNING : can't read unit of '"<< kword <<
". Assuming time in seconds");
1734 kword =
"/gate/application/addSlice";
1736 if (values.size()>0)
1738 double time_slice_tmp=0;
1742 Cerr(
"***** dataConversionUtilities::readMacECAT()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
1747 if (values.size()>1)
1749 if(values[1] ==
"s") time_slice_tmp *= 1000;
1752 Cerr(
"***** dataConversionUtilities::readMacECAT()-> WARNING : can't read unit of '"<< kword <<
". Assuming time in seconds");
1754 time_slices = time_slice_tmp;
1757 kword =
"/gate/digitizer/Coincidences/setWindow";
1759 if (values.size()>0)
1763 Cerr(
"***** dataConversionUtilities::readMacCylindrical()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
1768 if (values.size()>1)
1770 if(values[1] ==
"ns") pet_coinc_window *= 1000.;
1771 else if (values[1] ==
"us") pet_coinc_window *= 1000000.;
1772 else if (values[1] ==
"ps") ;
1775 Cerr(
"***** dataConversionUtilities::readMacCylindrical()-> ERROR : can't read unit of '"<< kword <<
". Must be ns, ps or us !!!");
1781 Cerr(
"***** dataConversionUtilities::readMacCylindrical()-> WARNING : can't read unit of '"<< kword <<
". Assuming time in ns");
1787 duration_ms = (time_slices>0) ?
1788 (uint32_t)(time_slices-time_start) :
1791 duration_ms = (time_start>=0 && time_stop>=0) ?
1792 (uint32_t)(time_stop-time_start) :
1799 nCrystalsTot = nCrystalsTransaxial * nCrystalsAxial
1800 * nBlocksLine * nBlocksPerRing;
1806 Cout(
"-----------------------------------------------------" << endl);
1807 Cout(
"ReadMacECAT()-> Information recovered from mac file:" << endl);
1808 Cout(
"-----------------------------------------------------" << endl);
1809 Cout(
"Number of blocks per ring: " << nBlocksPerRing << endl);
1810 Cout(
"Number of axial blocks: " << nBlocksLine << endl);
1811 Cout(
"Number of axial crystals: " << nCrystalsAxial << endl);
1812 Cout(
"Number of transaxial crystals: " << nCrystalsTransaxial << endl);
1813 Cout(
"Total number of crystals: " << nCrystalsTot << endl);
1814 Cout(
"Acquisition start time (ms): " << start_time_ms << endl);
1815 Cout(
"Acquisition duration (ms): " << duration_ms << endl);
1816 Cout(
"-----------------------------------------------------" << endl << endl);
1848 float_t &a_distToDetector,
1850 uint32_t &a_nPixAxl,
1851 uint32_t &a_nPixTrs,
1852 float_t &a_crystalSizeAxl,
1853 float_t &a_crystalSizeTrs,
1854 uint32_t &a_nProjectionsTot,
1855 uint32_t &a_nProjectionsByHead,
1856 float_t &a_head1stAngle,
1857 float_t &a_headAngPitch,
1858 float_t &a_headAngStepDeg,
1859 int &a_headRotDirection,
1860 uint32_t &a_start_time_ms,
1861 uint32_t &a_duration_ms,
1865 vector<string> path_mac_files;
1866 path_mac_files.push_back(a_pathMac);
1870 Cerr(
"***** GetGATESystemType() ->Error occurred when trying to recover paths to GATE macro files !" << endl);
1874 string head_name =
"SPECThead";
1875 string crystal_name =
"crystal";
1876 string pixel_name =
"pixel";
1877 string head_orbit_name =
"";
1878 bool is_head_Y_axis =
false;
1883 Cerr(
"***** GetGATESystemType() ->Error occurred when trying to recover aliases for the elements of the ecat !" << endl);
1888 double time_start=-1.,
1893 head_rot_speed =-1.;
1896 for(uint16_t f=0 ; f<path_mac_files.size() ; f++)
1898 ifstream mac_file(path_mac_files[f].c_str(), ios::in);
1902 while(getline(mac_file, line))
1904 vector <string> values;
1906 kword =
"/gate/"+head_name+
"/placement/setTranslation";
1908 if (values.size()>0)
1910 FLTNB head_pos_X=0.,
1916 Cerr(
"***** dataConversionUtilities::CreateGeomWithSPECT()-> Conversion error occurred while trying to parse line: " << line<< endl);
1921 if(head_pos_Y!=0) is_head_Y_axis =
true;
1923 a_distToDetector = is_head_Y_axis ? abs(head_pos_Y) : abs(head_pos_X) ;
1928 kword =
"/gate/"+head_name+
"/ring/setRepeatNumber";
1930 if (values.size()>0)
1934 Cerr(
"***** dataConversionUtilities::CreateGeomWithSPECT()-> Conversion error occurred while trying to parse line: " << line<< endl);
1939 kword =
"/gate/"+head_name+
"/ring/setFirstAngle";
1941 if (values.size()>0)
1945 Cerr(
"***** dataConversionUtilities::CreateGeomWithSPECT()-> Conversion error occurred while trying to parse line: " << line<< endl);
1950 kword =
"/gate/"+head_name+
"/ring/setAngularPitch";
1952 if (values.size()>0)
1956 Cerr(
"***** dataConversionUtilities::CreateGeomWithSPECT()-> Conversion error occurred while trying to parse line: " << line<< endl);
1961 kword =
"/gate/"+head_name+
"/moves/insert";
1963 if (values.size()>0)
1967 Cerr(
"***** dataConversionUtilities::CreateGeomWithSPECT()-> Conversion error occurred while trying to parse line: " << line<< endl);
1972 kword =
"/gate/"+head_name+
"/"+head_orbit_name+
"/setSpeed";
1974 if (values.size()>0)
1978 Cerr(
"***** dataConversionUtilities::CreateGeomWithSPECT()-> Conversion error occurred while trying to parse line: " << line<< endl);
1983 kword =
"/gate/"+head_name+
"/"+head_orbit_name+
"/setPoint2";
1985 if (values.size()>0)
1990 Cerr(
"***** dataConversionUtilities::CreateGeomWithSPECT()-> Conversion error occurred while trying to parse line: " << line<< endl);
1998 kword = is_head_Y_axis ?
1999 "/gate/"+crystal_name+
"/geometry/setXLength":
2000 "/gate/"+crystal_name+
"/geometry/setYLength";
2003 if (values.size()>0)
2007 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
2013 kword =
"/gate/"+crystal_name+
"/geometry/setZLength";
2015 if (values.size()>0)
2019 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
2026 kword = is_head_Y_axis ?
2027 "/gate/"+pixel_name+
"/cubicArray/setRepeatNumberX":
2028 "/gate/"+pixel_name+
"/cubicArray/setRepeatNumberY";
2032 if (values.size()>0)
2036 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
2041 kword =
"/gate/"+pixel_name+
"/cubicArray/setRepeatNumberZ";
2043 if (values.size()>0)
2047 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
2052 kword =
"/gate/application/setTimeStart";
2054 if (values.size()>0)
2058 Cerr(
"***** dataConversionUtilities::readMacECAT()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
2063 if (values.size()>1)
2065 if(values[1] ==
"s") time_start *= 1000;
2068 Cerr(
"***** dataConversionUtilities::readMacECAT()-> WARNING : can't read unit of '"<< kword <<
". Assuming time in seconds");
2070 a_start_time_ms = time_start;
2073 kword =
"/gate/application/setTimeSlice";
2075 if (values.size()>0)
2079 Cerr(
"***** dataConversionUtilities::readMacECAT()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
2084 if (values.size()>1)
2086 if(values[1] ==
"s") time_slice *= 1000;
2089 Cerr(
"***** dataConversionUtilities::readMacECAT()-> WARNING : can't read unit of '"<< kword <<
". Assuming time in seconds");
2091 time_slice_ms = time_slice;
2094 kword =
"/gate/application/setTimeStop";
2096 if (values.size()>0)
2100 Cerr(
"***** dataConversionUtilities::readMacECAT()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
2105 if (values.size()>1)
2107 if(values[1] ==
"s") time_stop *= 1000;
2110 Cerr(
"***** dataConversionUtilities::readMacECAT()-> WARNING : can't read unit of '"<< kword <<
". Assuming time in seconds");
2113 kword =
"/gate/application/addSlice";
2115 if (values.size()>0)
2117 double time_slice_tmp=0;
2121 Cerr(
"***** dataConversionUtilities::readMacECAT()->Error occurred while trying to get value from entry '"<< kword <<
"' in file " << path_mac_files[f] <<
"!");
2126 if (values.size()>1)
2128 if(values[1] ==
"s") time_slice_tmp *= 1000;
2131 Cerr(
"***** dataConversionUtilities::readMacECAT()-> WARNING : can't read unit of '"<< kword <<
". Assuming time in seconds");
2133 time_slices = time_slice_tmp;
2140 a_duration_ms = (time_slices>0) ?
2141 (uint32_t)(time_slices-time_start) :
2145 a_duration_ms = (time_start>=0 && time_stop>=0) ?
2146 (uint32_t)(time_stop-time_start) :
2151 a_nProjectionsByHead = a_duration_ms / time_slice_ms;
2152 a_nProjectionsTot = a_nHeads*a_nProjectionsByHead;
2155 a_headAngPitch = (a_headAngPitch<0) ?
2159 a_headAngStepDeg = head_rot_speed*time_slice_ms/1000.;
2161 if(head_rot_speed<0)
2163 Cerr(
"***** GetGATESystemType() -> Error couldn't find line '/gate/"+head_name+
"/"+head_orbit_name+
"/setSpeed' !" << endl);
2164 Cerr(
" This information is mandatory to compute the projection angle step." << endl);
2170 Cerr(
"***** GetGATESystemType() -> Error couldn't find line '/gate/application/setTimeSlice' !" << endl);
2171 Cerr(
" This information is mandatory to compute the projection angle step." << endl);
2175 if(a_duration_ms == 0)
2179 Cerr(
"***** GetGATESystemType() -> Error couldn't compute acquisition find line '/gate/application/setTimeStop' !" << endl);
2180 Cerr(
" This information is mandatory to compute the acquisition duration." << endl);
2185 Cerr(
"***** GetGATESystemType() -> Error couldn't compute acquisition find line '/gate/application/setTimeStart' !" << endl);
2186 Cerr(
" This information is mandatory to compute the acquisition duration." << endl);
2197 Cout(
"-----------------------------------------------------" << endl);
2198 Cout(
"ReadMacSPECT()-> Information recovered from mac file:" << endl);
2199 Cout(
"-----------------------------------------------------" << endl);
2200 Cout(
"Distance to detector: " << a_distToDetector << endl);
2201 Cout(
"Number of heads: " << a_nHeads << endl);
2202 Cout(
"Number of axial pixels: " << a_nPixAxl << endl);
2203 Cout(
"Number of transaxial pixels: " << a_nPixTrs << endl);
2204 Cout(
"Crystal axial size: " << a_crystalSizeAxl << endl);
2205 Cout(
"Crystal transaxial size: " << a_crystalSizeTrs << endl);
2206 Cout(
"Number of projections per head: " << a_nProjectionsByHead << endl);
2207 Cout(
"Total number of projections: " << a_nProjectionsTot << endl);
2208 Cout(
"Head(s) first transaxial angle: " << a_head1stAngle << endl);
2209 Cout(
"Head(s) angular pitch: " << a_headAngPitch << endl);
2210 Cout(
"Angular step between projections (deg): " << a_headAngStepDeg << endl);
2211 Cout(
"Rotation direction (0=CW, 1=CCW): " << a_headRotDirection << endl);
2212 Cout(
"Acquisition start time (ms): " << a_start_time_ms << endl);
2213 Cout(
"Acquisition duration (ms): " << a_duration_ms << endl);
2214 Cout(
"-----------------------------------------------------" << endl << endl);
2247 float_t &a_distToDetector,
2249 uint32_t &a_nPixAxl,
2250 uint32_t &a_nPixTrs,
2251 float_t &a_crystalSizeAxl,
2252 float_t &a_crystalSizeTrs,
2253 uint32_t &a_nProjectionsTot,
2254 uint32_t &a_nProjectionsByHead,
2255 float_t &a_head1stAngle,
2256 float_t &a_headAngPitchDeg,
2257 float_t &a_headAngStepDeg,
2258 int &a_headRotDirection,
2259 uint32_t &a_start_time_ms,
2260 uint32_t &a_duration_ms,
2267 key =
"matrix size [1]";
2270 Cerr(
"***** castor-GATERootToCastor :: Error when trying to read key: '"<< key <<
"' in interfile : " << a_pathIntf <<
"!" << endl);
2271 Cerr(
" Either key not found or conversion error" << endl);
2275 key =
"matrix size [2]";
2278 Cerr(
"***** castor-GATERootToCastor :: Error when trying to read key: '"<< key <<
"' in interfile : " << a_pathIntf <<
"!" << endl);
2279 Cerr(
" Either key not found or conversion error" << endl);
2283 FLTNB size_pix_trs = 1.,
2286 key =
"scaling factor (mm/pixel) [1]";
2289 Cerr(
"***** castor-GATERootToCastor :: Error when trying to read key: '"<< key <<
"' in interfile : " << a_pathIntf <<
"!" << endl);
2290 Cerr(
" Either key not found or conversion error" << endl);
2294 key =
"scaling factor (mm/pixel) [2]";
2297 Cerr(
"***** castor-GATERootToCastor :: Error when trying to read key: '"<< key <<
"' in interfile : " << a_pathIntf <<
"!" << endl);
2298 Cerr(
" Either key not found or conversion error" << endl);
2302 key =
"total number of images";
2305 Cerr(
"***** castor-GATERootToCastor :: Error when trying to read key: '"<< key <<
"' in interfile : " << a_pathIntf <<
"!" << endl);
2306 Cerr(
" Either key not found or conversion error" << endl);
2310 key =
"number of projections";
2313 Cerr(
"***** castor-GATERootToCastor :: Error when trying to read key: '"<< key <<
"' in interfile : " << a_pathIntf <<
"!" << endl);
2314 Cerr(
" Either key not found or conversion error" << endl);
2318 key =
"number of detector heads";
2321 Cerr(
"***** castor-GATERootToCastor :: Error when trying to read key: '"<< key <<
"' in interfile : " << a_pathIntf <<
"!" << endl);
2322 Cerr(
" Either key not found or conversion error" << endl);
2326 key =
"study duration (sec)";
2329 Cerr(
"***** castor-GATERootToCastor :: Error when trying to read key: '"<< key <<
"' in interfile : " << a_pathIntf <<
"!" << endl);
2330 Cerr(
" Either key not found or conversion error" << endl);
2334 a_duration_ms *= 1000;
2337 FLTNB size_crystal_X =0.,
2340 key =
"crystal x dimension (cm)";
2343 Cerr(
"***** castor-GATERootToCastor :: Error when trying to read key: '"<< key <<
"' in interfile : " << a_pathIntf <<
"!" << endl);
2344 Cerr(
" Either key not found or conversion error" << endl);
2348 key =
"crystal y dimension (cm)";
2351 Cerr(
"***** castor-GATERootToCastor :: Error when trying to read key: '"<< key <<
"' in interfile : " << a_pathIntf <<
"!" << endl);
2352 Cerr(
" Either key not found or conversion error" << endl);
2356 key =
"crystal z dimension (cm)";
2359 Cerr(
"***** castor-GATERootToCastor :: Error when trying to read key: '"<< key <<
"' in interfile : " << a_pathIntf <<
"!" << endl);
2360 Cerr(
" Either key not found or conversion error" << endl);
2366 if(size_crystal_X>0 && size_crystal_Y>0)
2367 a_crystalSizeTrs = (size_crystal_X>size_crystal_Y) ? size_crystal_X*10. : size_crystal_Y*10.;
2368 a_crystalSizeAxl = (a_crystalSizeAxl>0) ? a_crystalSizeAxl*10. : a_crystalSizeAxl ;
2371 FLTNB head_pos_X =-1.,
2375 key =
"head x translation (cm)";
2378 Cerr(
"***** castor-GATERootToCastor :: Error when trying to read key: '"<< key <<
"' in interfile : " << a_pathIntf <<
"!" << endl);
2379 Cerr(
" Either key not found or conversion error" << endl);
2383 key =
"head y translation (cm)";
2386 Cerr(
"***** castor-GATERootToCastor :: Error when trying to read key: '"<< key <<
"' in interfile : " << a_pathIntf <<
"!" << endl);
2387 Cerr(
" Either key not found or conversion error" << endl);
2391 key =
"head z translation (cm)";
2394 Cerr(
"***** castor-GATERootToCastor :: Error when trying to read key: '"<< key <<
"' in interfile : " << a_pathIntf <<
"!" << endl);
2395 Cerr(
" Either key not found or conversion error" << endl);
2400 if(head_pos_X > head_pos_Y)
2401 a_distToDetector = head_pos_X > head_pos_Z ? head_pos_X*10 : head_pos_Z*10;
2403 a_distToDetector = head_pos_Y > head_pos_Z ? head_pos_Y*10 : head_pos_Z*10;
2406 key =
"direction of rotation";
2410 Cerr(
"***** castor-GATERootToCastor :: Error when trying to read key: '"<< key <<
"' in interfile : " << a_pathIntf <<
"!" << endl);
2411 Cerr(
" Either key not found or conversion error" << endl);
2419 key =
"start angle";
2422 Cerr(
"***** castor-GATERootToCastor :: Error when trying to read key: '"<< key <<
"' in interfile : " << a_pathIntf <<
"!" << endl);
2423 Cerr(
" Either key not found or conversion error" << endl);
2427 key =
"extent of rotation";
2428 uint32_t extent_rotation =360;
2431 Cerr(
"***** castor-GATERootToCastor :: Error when trying to read key: '"<< key <<
"' in interfile : " << a_pathIntf <<
"!" << endl);
2432 Cerr(
" Either key not found or conversion error" << endl);
2436 a_headAngStepDeg = (
FLTNB)extent_rotation / a_nProjectionsByHead;
2438 float_t first_angle = 0;
2439 float_t second_angle = extent_rotation;
2441 key =
"start angle";
2444 Cerr(
"***** castor-GATERootToCastor :: Error when trying to read key: '"<< key <<
"' in interfile : " << a_pathIntf <<
"!" << endl);
2445 Cerr(
" Either key not found or conversion error" << endl);
2449 key =
"start angle";
2452 Cerr(
"***** castor-GATERootToCastor :: Error when trying to read key: '"<< key <<
"' in interfile : " << a_pathIntf <<
"!" << endl);
2453 Cerr(
" Either key not found or conversion error" << endl);
2457 a_headAngPitchDeg = second_angle - first_angle;
2482 string scanner_name =
GetFileFromPath(a_pathGeom.substr(0,a_pathGeom.find(
".geom")));
2483 double scanner_radius = 0.;
2484 uint32_t number_of_elements = 0;
2485 string description =
"PET system extracted from GATE macro: " + a_pathMac;
2488 string rsector_name =
"";
2489 uint32_t number_of_rsectors_ang = 1;
2490 uint32_t number_of_rsectors_axl = 1;
2491 double rsector_step_axl = 0.;
2492 double rsector_gap_axl = 0.;
2493 double rsector_first_angle = 0.;
2494 double rsector_angular_span = 360.;
2495 double rsector_pos_X = 0.;
2496 double rsector_pos_Y = 0.;
2497 uint32_t rsector_nb_zshifts = 0;
2498 vector <double> vec_rsector_Z_Shift;
2499 bool is_rsector_Y_axis =
false;
2500 double rsector_size_trs;
2501 double rsector_size_axl;
2504 string module_name =
"";
2505 uint32_t number_of_modules_trs = 1;
2506 uint32_t number_of_modules_axl = 1;
2507 double module_step_trs = 0.;
2508 double module_step_axl = 0.;
2509 double module_gap_trs = 0.;
2510 double module_gap_axl = 0.;
2511 double module_size_trs;
2512 double module_size_axl;
2515 string submodule_name =
"";
2516 uint32_t number_of_submodules_trs = 1;
2517 uint32_t number_of_submodules_axl = 1;
2518 double submodule_step_trs = 0.;
2519 double submodule_step_axl = 0.;
2520 double submodule_gap_trs = 0.;
2521 double submodule_gap_axl = 0.;
2522 double submodule_size_trs;
2523 double submodule_size_axl;
2526 string crystal_name =
"";
2527 uint32_t number_of_crystals_trs = 1;
2528 uint32_t number_of_crystals_axl = 1;
2529 double crystal_step_trs = 0.;
2530 double crystal_step_axl = 0.;
2531 double crystal_gap_trs = 0.;
2532 double crystal_gap_axl = 0.;
2533 double crystal_size_depth = 0.;
2534 double crystal_size_trs = 0.;
2535 double crystal_size_axl = 0.;
2539 int number_of_layers = 0;
2540 string n_layers =
"1";
2541 vector <uint32_t> number_of_lyr_elts_trs;
2542 vector <uint32_t> number_of_lyr_elts_axl;
2544 vector <string> layers_names;
2545 vector <vector <double> > layers_positions;
2546 vector <double> layers_size_depth;
2547 vector <double> layers_size_trs;
2548 vector <double> layers_size_axl;
2550 vector <double> layers_step_trs;
2551 vector <double> layers_step_axl;
2554 uint32_t voxels_number_trs;
2555 uint32_t voxels_number_axl;
2558 double mean_depth_of_interaction = -1.;
2559 double min_angle_diff = 0.;
2564 vector <string> vec_scanner_radius;
2567 vector <string> vec_number_of_rsectors_ang;
2568 vector <string> vec_number_of_rsectors_axl;
2569 vector <string> vec_rsector_gap_trs;
2570 vector <string> vec_rsector_gap_axl;
2571 vector <string> vec_rsector_first_angle;
2575 vector <string> vec_number_of_modules_trs;
2576 vector <string> vec_number_of_modules_axl;
2577 vector <string> vec_module_gap_trs;
2578 vector <string> vec_module_gap_axl;
2581 vector <string> vec_number_of_submodules_trs;
2582 vector <string> vec_number_of_submodules_axl;
2583 vector <string> vec_submodule_gap_trs;
2584 vector <string> vec_submodule_gap_axl;
2587 vector <string> vec_number_of_crystals_trs;
2588 vector <string> vec_number_of_crystals_axl;
2589 vector <string> vec_crystal_gap_trs;
2590 vector <string> vec_crystal_gap_axl;
2593 vector <string> vec_mean_depth_of_interaction;
2594 vector <string> vec_min_angle_diff;
2596 vector<string> path_mac_files;
2597 path_mac_files.push_back(a_pathMac);
2602 Cerr(
"***** GetGATESystemType() ->Error occurred when trying to recover paths to GATE macro files !" << endl);
2607 if(
GetGATEAliasesCylindrical(path_mac_files, rsector_name, module_name, submodule_name, crystal_name, layers_names, 2) )
2609 Cerr(
"***** GetGATESystemType() ->Error occurred when trying to recover aliases for the elements of the cylindricalPET !" << endl);
2614 n_layers = layers_names.size();
2618 for(uint16_t f=0 ; f<path_mac_files.size() ; f++)
2620 ifstream systemMac(path_mac_files[f].c_str(), ios::in);
2624 while(getline(systemMac, line))
2626 vector <string> values;
2633 entry =
"/gate/"+rsector_name+
"/placement/setTranslation";
2637 if (values.size()>0)
2642 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
2648 if(rsector_pos_X!=0 && rsector_pos_Y !=0)
2650 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
2651 Cerr(
" Rsector cartesian coordinates on either the X or Y axis expected to be equal to 0 "<< endl);
2656 if(rsector_pos_Y!=0) is_rsector_Y_axis =
true;
2659 scanner_radius += is_rsector_Y_axis ? abs(rsector_pos_Y) : abs(rsector_pos_X) ;
2687 entry = is_rsector_Y_axis ?
2688 "/gate/"+rsector_name+
"/geometry/setXLength":
2689 "/gate/"+rsector_name+
"/geometry/setYLength";
2692 if (values.size()>0)
2696 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
2705 entry =
"/gate/"+rsector_name+
"/ring/setModuloNumber";
2707 if (values.size()>0)
2711 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
2716 entry =
"/gate/"+rsector_name+
"/ring/setRepeatNumber";
2718 if (values.size()>0)
2722 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
2730 entry =
"/gate/"+rsector_name+
"/linear/setRepeatNumber";
2732 if (values.size()>0)
2736 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
2744 entry =
"/gate/"+rsector_name+
"/linear/setRepeatVector";
2746 if (values.size()>0)
2750 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
2757 entry = is_rsector_Y_axis ?
2758 "/gate/"+rsector_name+
"/cubicArray/setRepeatNumberX":
2759 "/gate/"+rsector_name+
"/cubicArray/setRepeatNumberY";
2762 if (values.size()>0)
2764 uint32_t number_of_rsectors_trs;
2768 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
2775 if(number_of_rsectors_trs>1)
2777 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Error while trying to parse line: " << line<< endl);
2778 Cerr(
" The GATE system contains more than one 'transaxial' rsector " << endl);
2779 Cerr(
" The current implementation does not support such cylindricalPET model" << endl);
2780 Cerr(
" Manual implementation of the system is required (ex: model the transaxial rsectors as modules)" << endl);
2786 entry =
"/gate/"+rsector_name+
"/cubicArray/setRepeatNumberZ";
2789 if (values.size()>0)
2793 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
2799 entry =
"/gate/"+rsector_name+
"/cubicArray/setRepeatVector";
2801 if (values.size()>0)
2805 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
2813 entry =
"/gate/"+rsector_name+
"/geometry/setZLength";
2815 if (values.size()>0)
2819 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
2826 entry =
"/gate/"+rsector_name+
"/ring/setFirstAngle";
2828 if (values.size()>0)
2832 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
2837 entry =
"/gate/"+rsector_name+
"/ring/setAngularSpan";
2839 if (values.size()>0)
2843 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
2849 for (
int i=1; i <8; i++)
2851 entry =
"/gate/"+rsector_name+
"/ring/setZShift"+
toString(i);
2853 if (values.size()>0)
2858 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
2862 vec_rsector_Z_Shift.push_back(zshift);
2871 entry =
"/gate/"+module_name+
"/placement/setTranslation";
2874 FLTNB module_pos_X =0.,
2878 if (values.size()>0)
2883 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
2889 if(module_pos_X!=0 && module_pos_Y !=0)
2891 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
2892 Cerr(
" Module cartesian coordinates on either the X or Y axis expected to be equal to 0 "<< endl);
2897 scanner_radius += is_rsector_Y_axis ? module_pos_Y : module_pos_X ;
2902 entry = is_rsector_Y_axis ?
2903 "/gate/"+module_name+
"/cubicArray/setRepeatNumberX":
2904 "/gate/"+module_name+
"/cubicArray/setRepeatNumberY";
2907 if (values.size()>0)
2911 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
2919 entry =
"/gate/"+module_name+
"/cubicArray/setRepeatNumberZ";
2922 if (values.size()>0)
2926 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
2932 entry = is_rsector_Y_axis ?
2933 "/gate/"+module_name+
"/geometry/setXLength":
2934 "/gate/"+module_name+
"/geometry/setYLength";
2937 if (values.size()>0)
2941 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
2947 entry =
"/gate/"+module_name+
"/geometry/setZLength";
2949 if (values.size()>0)
2953 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
2958 entry =
"/gate/"+module_name+
"/cubicArray/setRepeatVector";
2960 if (values.size()>0)
2962 string trs_step = is_rsector_Y_axis ?
2969 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
2978 entry =
"/gate/"+module_name+
"/linear/setRepeatNumber";
2981 if (values.size()>0)
2985 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
2990 entry =
"/gate/"+module_name+
"/linear/setRepeatVector";
2992 if (values.size()>0)
2996 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3005 entry =
"/gate/"+submodule_name+
"/placement/setTranslation";
3008 FLTNB submodule_pos_X =0.,
3009 submodule_pos_Y =0.;
3012 if (values.size()>0)
3017 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3023 if(submodule_pos_X!=0 && submodule_pos_Y !=0)
3025 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3026 Cerr(
" Submodule cartesian coordinates on either the X or Y axis expected to be equal to 0 "<< endl);
3031 scanner_radius += is_rsector_Y_axis ? submodule_pos_Y : submodule_pos_X ;
3036 entry = is_rsector_Y_axis ?
3037 "/gate/"+submodule_name+
"/cubicArray/setRepeatNumberX":
3038 "/gate/"+submodule_name+
"/cubicArray/setRepeatNumberY";
3042 if (values.size()>0)
3046 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3051 entry =
"/gate/"+submodule_name+
"/cubicArray/setRepeatNumberZ";
3053 if (values.size()>0)
3057 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3065 entry = is_rsector_Y_axis ?
3066 "/gate/"+submodule_name+
"/geometry/setXLength":
3067 "/gate/"+submodule_name+
"/geometry/setYLength";
3070 if (values.size()>0)
3074 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3079 entry =
"/gate/"+submodule_name+
"/geometry/setZLength";
3081 if (values.size()>0)
3085 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3090 entry =
"/gate/"+submodule_name+
"/cubicArray/setRepeatVector";
3092 if (values.size()>0)
3094 string trs_step = is_rsector_Y_axis ?
3101 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3109 entry =
"/gate/"+submodule_name+
"/linear/setRepeatNumber";
3112 if (values.size()>0)
3116 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3122 entry =
"/gate/"+submodule_name+
"/linear/setRepeatVector";
3124 if (values.size()>0)
3128 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3139 entry =
"/gate/"+crystal_name+
"/placement/setTranslation";
3142 FLTNB crystal_pos_X =0.,
3146 if (values.size()>0)
3151 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3157 if(crystal_pos_X!=0 && crystal_pos_Y !=0)
3159 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3160 Cerr(
" Crystal cartesian coordinates on either the X or Y axis expected to be equal to 0 "<< endl);
3165 scanner_radius += is_rsector_Y_axis ? crystal_pos_Y : crystal_pos_X ;
3170 entry = is_rsector_Y_axis ?
3171 "/gate/"+crystal_name+
"/cubicArray/setRepeatNumberX":
3172 "/gate/"+crystal_name+
"/cubicArray/setRepeatNumberY";
3176 if (values.size()>0)
3180 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3185 entry =
"/gate/"+crystal_name+
"/cubicArray/setRepeatNumberZ";
3187 if (values.size()>0)
3191 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3197 entry =
"/gate/"+crystal_name+
"/geometry/setXLength";
3199 if (values.size()>0)
3204 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3208 if (is_rsector_Y_axis)
3209 crystal_size_trs = x_length;
3211 crystal_size_depth = x_length;
3214 entry =
"/gate/"+crystal_name+
"/geometry/setYLength";
3216 if (values.size()>0)
3221 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3225 if (is_rsector_Y_axis)
3226 crystal_size_depth = y_length;
3228 crystal_size_trs = y_length;
3232 entry =
"/gate/"+crystal_name+
"/geometry/setZLength";
3234 if (values.size()>0)
3238 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3243 entry =
"/gate/"+crystal_name+
"/cubicArray/setRepeatVector";
3245 if (values.size()>0)
3247 string trs_step = is_rsector_Y_axis ?
3254 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3260 entry =
"/gate/"+crystal_name+
"/linear/setRepeatNumber";
3263 if (values.size()>0)
3267 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3272 entry =
"/gate/"+crystal_name+
"/linear/setRepeatVector";
3274 if (values.size()>0)
3278 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3285 entry =
"/gate/"+crystal_name+
"/daughters/name";
3287 if (values.size()>0)
3289 layers_names.push_back(values[0]);
3294 for (
int i=0; i < number_of_layers; i++)
3297 entry =
"/gate/"+layers_names[i]+
"/placement/setTranslation";
3300 if (values.size()>0)
3302 vector<double> layer_pos;
3303 for(
int d=0 ; d<3 ; d++)
3308 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3311 layer_pos.push_back(pos);
3314 if(is_rsector_Y_axis)
3316 double pos = layer_pos[1];
3317 layer_pos[1] = layer_pos[0];
3321 layers_positions.push_back(layer_pos);
3326 entry =
"/gate/"+layers_names[i]+
"/geometry/setXLength";
3329 if (values.size()>0)
3334 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3338 if (is_rsector_Y_axis)
3339 layers_size_trs.push_back(xlength);
3341 layers_size_depth.push_back(xlength);
3345 entry =
"/gate/"+layers_names[i]+
"/geometry/setYLength";
3347 if (values.size()>0)
3352 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3355 if (is_rsector_Y_axis)
3356 layers_size_depth.push_back(ylength);
3358 layers_size_trs.push_back(ylength);
3361 entry =
"/gate/"+layers_names[i]+
"/geometry/setZLength";
3363 if (values.size()>0)
3368 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3371 layers_size_axl.push_back(zlength);
3377 entry = is_rsector_Y_axis ?
3378 "/gate/"+layers_names[i]+
"/cubicArray/setRepeatNumberX":
3379 "/gate/"+layers_names[i]+
"/cubicArray/setRepeatNumberY";
3382 if (values.size()>0)
3387 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3390 number_of_lyr_elts_trs.push_back(step_trs);
3393 entry =
"/gate/"+layers_names[i]+
"/cubicArray/setRepeatNumberZ";
3395 if (values.size()>0)
3400 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3403 number_of_lyr_elts_axl.push_back(step_axl);
3406 entry =
"/gate/"+layers_names[i]+
"/cubicArray/setRepeatVector";
3408 if (values.size()>0)
3410 string trs_step = is_rsector_Y_axis ?
3414 double step_trs, step_axl;
3418 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3423 layers_step_trs.push_back(step_trs);
3424 layers_step_axl.push_back(step_axl);
3429 entry =
"/gate/"+layers_names[i]+
"/linear/setRepeatNumber";
3432 if (values.size()>0)
3437 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3440 number_of_lyr_elts_axl.push_back(step_axl);
3444 entry =
"/gate/"+layers_names[i]+
"/linear/setRepeatVector";
3446 if (values.size()>0)
3451 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3455 layers_step_axl.push_back(step_axl);
3460 entry =
"/gate/digitizer/Coincidences/minSectorDifference";
3462 if (values.size()>0)
3464 FLTNB min_sector_diff= 0.;
3468 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3472 min_angle_diff = 360./number_of_rsectors_ang*min_sector_diff;
3481 if(number_of_layers == 0)
3483 number_of_elements = number_of_rsectors_ang
3484 * number_of_rsectors_axl
3485 * number_of_modules_trs
3486 * number_of_modules_axl
3487 * number_of_submodules_trs
3488 * number_of_submodules_axl
3489 * number_of_crystals_trs
3490 * number_of_crystals_axl;
3493 for(
int l=0 ; l<number_of_layers ; l++)
3495 int32_t nb_crystals_layer = number_of_rsectors_ang
3496 * number_of_rsectors_axl
3497 * number_of_modules_trs
3498 * number_of_modules_axl
3499 * number_of_submodules_trs
3500 * number_of_submodules_axl
3501 * number_of_crystals_trs
3502 * number_of_crystals_axl;
3505 if(number_of_lyr_elts_trs.size()>0 || number_of_lyr_elts_axl.size()>0 )
3506 nb_crystals_layer *= number_of_lyr_elts_trs[l] * number_of_lyr_elts_axl[l];
3508 number_of_elements += nb_crystals_layer;
3515 if (crystal_step_axl - crystal_size_axl >= 0)
3516 crystal_gap_axl = crystal_step_axl - crystal_size_axl;
3518 if (crystal_step_trs - crystal_size_trs >= 0)
3519 crystal_gap_trs = crystal_step_trs - crystal_size_trs;
3522 submodule_size_axl = crystal_size_axl*number_of_crystals_axl + crystal_gap_axl*(number_of_crystals_axl-1);
3523 submodule_size_trs = crystal_size_trs*number_of_crystals_trs + crystal_gap_trs*(number_of_crystals_trs-1);
3526 if (submodule_step_axl - submodule_size_axl >= 0)
3527 submodule_gap_axl = submodule_step_axl - submodule_size_axl;
3529 if (submodule_step_trs - submodule_size_trs >= 0)
3530 submodule_gap_trs = submodule_step_trs - submodule_size_trs;
3533 module_size_axl = submodule_size_axl*number_of_submodules_axl + submodule_gap_axl*(number_of_submodules_axl-1);
3534 module_size_trs = submodule_size_trs*number_of_submodules_trs + submodule_gap_trs*(number_of_submodules_trs-1);
3537 if (module_step_axl - module_size_axl >= 0)
3538 module_gap_axl = module_step_axl - module_size_axl;
3540 if (module_step_trs - module_size_trs >= 0)
3541 module_gap_trs = module_step_trs - module_size_trs;
3544 rsector_size_axl = module_size_axl*number_of_modules_axl + module_gap_axl*(number_of_modules_axl-1);
3545 rsector_size_trs = module_size_trs*number_of_modules_trs + module_gap_trs*(number_of_modules_trs-1);
3549 if (rsector_step_axl - rsector_size_axl >= 0)
3550 rsector_gap_axl = rsector_step_axl - rsector_size_axl;
3554 fov_axl = rsector_size_axl * number_of_rsectors_axl
3555 + (number_of_rsectors_axl-1)*rsector_gap_axl;
3559 voxels_number_axl = ( number_of_crystals_axl
3560 * number_of_submodules_axl
3561 * number_of_modules_axl
3562 * number_of_rsectors_axl )
3566 fov_trs = (2*scanner_radius ) / 1.5;
3570 voxels_number_trs = ( number_of_crystals_trs
3571 * number_of_submodules_trs
3572 * number_of_modules_trs
3573 * number_of_rsectors_ang )
3579 rsector_first_angle -= round(atan2f(rsector_pos_X , rsector_pos_Y) * 180. / M_PI);
3582 if (number_of_layers > 0)
3584 for (
int l=0; l < number_of_layers ; l++)
3587 vec_scanner_radius.push_back(
toString(scanner_radius
3588 +layers_positions[ l ][ 0 ]
3589 -layers_size_depth[ l ] / 2. ) );
3592 vec_number_of_rsectors_ang.push_back(
toString(number_of_rsectors_ang) );
3593 vec_number_of_rsectors_axl.push_back(
toString(number_of_rsectors_axl) );
3594 vec_rsector_gap_axl.push_back(
toString(rsector_gap_axl) );
3595 vec_rsector_first_angle.push_back(
toString(rsector_first_angle) );
3598 vec_number_of_modules_trs.push_back(
toString(number_of_modules_trs) );
3599 vec_number_of_modules_axl.push_back(
toString(number_of_modules_axl) );
3600 vec_module_gap_trs.push_back(
toString(module_gap_trs) );
3601 vec_module_gap_axl.push_back(
toString(module_gap_axl) );
3604 vec_number_of_submodules_trs.push_back(
toString(number_of_submodules_trs) );
3605 vec_number_of_submodules_axl.push_back(
toString(number_of_submodules_axl) );
3606 vec_submodule_gap_trs.push_back(
toString(submodule_gap_trs) );
3607 vec_submodule_gap_axl.push_back(
toString(submodule_gap_axl) );
3610 uint32_t nb_tot_trs_cry = (number_of_lyr_elts_trs.size()>0) ?
3611 number_of_lyr_elts_trs[l]*number_of_crystals_trs :
3612 number_of_crystals_trs ;
3614 uint32_t nb_tot_axl_cry = (number_of_lyr_elts_axl.size()>0) ?
3615 number_of_lyr_elts_axl[l]*number_of_crystals_axl :
3616 number_of_crystals_axl ;
3618 vec_number_of_crystals_trs.push_back(
toString(nb_tot_trs_cry) );
3619 vec_number_of_crystals_axl.push_back(
toString(nb_tot_axl_cry) );
3624 if(layers_step_trs.size()>0 ||
3625 layers_step_axl.size()>0)
3627 if (layers_step_trs[l] - layers_size_trs[l] >= 0)
3628 crystal_gap_trs = layers_step_trs[l] - layers_size_trs[l];
3630 if (layers_step_axl[l] - layers_size_axl[l] >= 0)
3631 crystal_gap_axl = layers_step_axl[l] - layers_size_axl[l];
3634 vec_crystal_gap_trs.push_back(
toString(crystal_gap_trs) );
3635 vec_crystal_gap_axl.push_back(
toString(crystal_gap_axl) );
3638 vec_mean_depth_of_interaction.push_back(
toString(mean_depth_of_interaction) );
3639 vec_min_angle_diff.push_back(
toString(min_angle_diff) );
3645 layers_size_depth.push_back( crystal_size_depth );
3646 layers_size_trs.push_back( crystal_size_trs );
3647 layers_size_axl.push_back( crystal_size_axl );
3651 vec_scanner_radius.push_back(
toString(scanner_radius - crystal_size_depth/2) );
3654 vec_number_of_rsectors_ang.push_back(
toString(number_of_rsectors_ang) );
3655 vec_number_of_rsectors_axl.push_back(
toString(number_of_rsectors_axl) );
3656 vec_rsector_gap_axl.push_back(
toString(rsector_gap_axl) );
3657 vec_rsector_first_angle.push_back(
toString(rsector_first_angle) );
3660 vec_number_of_modules_trs.push_back(
toString(number_of_modules_trs) );
3661 vec_number_of_modules_axl.push_back(
toString(number_of_modules_axl) );
3662 vec_module_gap_trs.push_back(
toString(module_gap_trs) );
3663 vec_module_gap_axl.push_back(
toString(module_gap_axl) );
3666 vec_number_of_submodules_trs.push_back(
toString(number_of_submodules_trs) );
3667 vec_number_of_submodules_axl.push_back(
toString(number_of_submodules_axl) );
3668 vec_submodule_gap_trs.push_back(
toString(submodule_gap_trs) );
3669 vec_submodule_gap_axl.push_back(
toString(submodule_gap_axl) );
3672 vec_number_of_crystals_trs.push_back(
toString(number_of_crystals_trs) );
3673 vec_number_of_crystals_axl.push_back(
toString(number_of_crystals_axl) );
3674 vec_crystal_gap_trs.push_back(
toString(crystal_gap_trs) );
3675 vec_crystal_gap_axl.push_back(
toString(crystal_gap_axl) );
3678 vec_mean_depth_of_interaction.push_back(
toString(mean_depth_of_interaction) );
3679 vec_min_angle_diff.push_back(
toString(min_angle_diff) );
3682 number_of_layers = 1;
3687 ofstream fileGeom(a_pathGeom.c_str(), ios::out | ios::trunc);
3690 fileGeom <<
"# comments" << endl;
3691 fileGeom <<
"# Y _________ "<< endl;
3692 fileGeom <<
"# | / _ \\ \\ "<< endl;
3693 fileGeom <<
"# | | / \\ | |"<< endl;
3694 fileGeom <<
"# |_____ Z | | | | |"<< endl;
3695 fileGeom <<
"# \\ | | | | |" << endl;
3696 fileGeom <<
"# \\ | \\_/ | |" << endl;
3697 fileGeom <<
"# X \\___/_____/" << endl;
3698 fileGeom <<
"# Left-handed axis orientation"<< endl;
3699 fileGeom <<
"# scanner axis is z" << endl;
3700 fileGeom <<
"# positions in millimeters"<< endl;
3701 fileGeom <<
"# Use comma without space as separator in the tables." << endl;
3703 fileGeom <<
""<< endl;
3706 fileGeom <<
"# MANDATORY FIELDS"<< endl;
3707 fileGeom <<
"modality : " << modality << endl;
3708 fileGeom <<
"scanner name : " << scanner_name << endl;
3709 fileGeom <<
"number of elements : " << number_of_elements << endl;
3710 fileGeom <<
"number of layers : " << number_of_layers << endl;
3711 fileGeom <<
"" << endl;
3712 fileGeom <<
"voxels number transaxial : " << voxels_number_trs << endl;
3713 fileGeom <<
"voxels number axial : " << voxels_number_axl << endl;
3715 fileGeom <<
"field of view transaxial : " << fov_trs << endl;
3716 fileGeom <<
"field of view axial : " << fov_axl << endl << endl;
3717 fileGeom <<
"description : " << description << endl;
3718 fileGeom <<
"" << endl;
3719 WriteVector(fileGeom,
"scanner radius : ",vec_scanner_radius);
3720 WriteVector(fileGeom,
"number of rsectors : ",vec_number_of_rsectors_ang);
3721 WriteVector(fileGeom,
"number of crystals transaxial : ",vec_number_of_crystals_trs);
3722 WriteVector(fileGeom,
"number of crystals axial : ",vec_number_of_crystals_axl);
3723 fileGeom <<
""<< endl;
3724 WriteVector(fileGeom,
"crystals size depth : ", layers_size_depth);
3725 WriteVector(fileGeom,
"crystals size transaxial : ", layers_size_trs);
3726 WriteVector(fileGeom,
"crystals size axial : ", layers_size_axl);
3727 fileGeom <<
""<< endl;
3728 fileGeom <<
""<< endl;
3731 fileGeom <<
"# OPTIONAL FIELDS"<< endl;
3732 WriteVector(fileGeom,
"rsectors first angle : ",vec_rsector_first_angle);
3733 WriteVector(fileGeom,
"number of rsectors axial : ",vec_number_of_rsectors_axl);
3734 WriteVector(fileGeom,
"rsector gap transaxial : ",vec_rsector_gap_trs);
3735 WriteVector(fileGeom,
"rsector gap axial : ",vec_rsector_gap_axl);
3736 WriteVector(fileGeom,
"number of modules transaxial : ",vec_number_of_modules_trs);
3737 WriteVector(fileGeom,
"number of modules axial : ",vec_number_of_modules_axl);
3738 WriteVector(fileGeom,
"module gap transaxial : ",vec_module_gap_trs);
3739 WriteVector(fileGeom,
"module gap axial : ",vec_module_gap_axl);
3740 WriteVector(fileGeom,
"number of submodules transaxial : ",vec_number_of_submodules_trs);
3741 WriteVector(fileGeom,
"number of submodules axial : ",vec_number_of_submodules_axl);
3742 WriteVector(fileGeom,
"submodule gap transaxial : ",vec_submodule_gap_trs);
3743 WriteVector(fileGeom,
"submodule gap axial : ",vec_submodule_gap_axl);
3744 WriteVector(fileGeom,
"crystal gap transaxial : ",vec_crystal_gap_trs);
3745 WriteVector(fileGeom,
"crystal gap axial : ",vec_crystal_gap_axl);
3746 WriteVector(fileGeom,
"mean depth of interaction : ", vec_mean_depth_of_interaction);
3747 fileGeom <<
"rotation direction : CCW " << endl;
3748 fileGeom <<
""<< endl;
3751 if(min_angle_diff > 0.) fileGeom <<
"min angle difference : " << min_angle_diff << endl;
3754 if(rsector_angular_span >= 360.0005 ||
3755 rsector_angular_span <= 359.9995 )
3757 rsector_angular_span *= (double)number_of_rsectors_ang/(
double)(number_of_rsectors_ang-1);
3758 fileGeom <<
"rsectors angular span : " << rsector_angular_span << endl;
3761 if(rsector_nb_zshifts > 0) fileGeom <<
"rsectors nbZShift :" << rsector_nb_zshifts << endl;
3762 if(!vec_rsector_Z_Shift.empty())
WriteVector(fileGeom,
"rsectors ZShift : ", vec_rsector_Z_Shift);
3766 cout <<
"Output geom file written at :" << a_pathGeom << endl;
3770 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Couldn't open geom file for writing "<< a_pathGeom <<
" !" << endl);
3798 string scanner_name =
GetFileFromPath(a_pathGeom.substr(0,a_pathGeom.find_first_of(
".geom")));
3799 double scanner_radius = 0.;
3800 uint32_t number_of_elements = 0;
3801 string description =
"ECAT system extracted from GATE macro: " + a_pathMac;
3804 string block_name =
"block";
3805 uint32_t number_of_blocks = 1;
3806 uint32_t number_of_blocks_trs = 1;
3807 uint32_t number_of_blocks_axl = 1;
3808 double block_step_trs = 0.;
3809 double block_step_axl = 0.;
3810 double block_gap_trs = 0.;
3811 double block_gap_axl = 0.;
3812 double block_size_Y;
3813 double block_size_Z;
3814 double block_pos_X = 0.;
3815 double block_pos_Y = 0.;
3816 double block_first_angle = 0.;
3817 double block_angular_span = 360.;
3818 uint32_t block_nb_zshifts = 0;
3819 vector <double> vec_block_Z_Shift;
3820 bool is_block_Y_axis =
false;
3825 string crystal_name =
"crystal";
3826 uint32_t number_of_crystals_trs = 1;
3827 uint32_t number_of_crystals_axl = 1;
3828 double crystal_step_trs = 0.;
3829 double crystal_step_axl = 0.;
3830 double crystal_gap_trs = 0.;
3831 double crystal_gap_axl = 0.;
3832 double crystal_size_depth = 0.;
3833 double crystal_size_trs = 0.;
3834 double crystal_size_axl = 0.;
3837 uint32_t voxels_number_trs;
3838 uint32_t voxels_number_axl;
3841 double min_angle_diff = 0.;
3843 vector<string> path_mac_files;
3844 path_mac_files.push_back(a_pathMac);
3849 Cerr(
"***** dataConversionUtilities::CreateGeomWithECAT()->Error occurred when trying to recover paths to GATE macro files !" << endl);
3857 Cerr(
"***** dataConversionUtilities::CreateGeomWithECAT()->Error occurred when trying to recover aliases for the elements of the ecat !" << endl);
3863 for(uint16_t f=0 ; f<path_mac_files.size() ; f++)
3865 ifstream systemMac(path_mac_files[f].c_str(), ios::in);
3868 while(getline(systemMac, line))
3872 vector <string> values;
3876 entry =
"/gate/"+block_name+
"/placement/setTranslation";
3878 if (values.size()>0)
3883 Cerr(
"***** dataConversionUtilities::CreateGeomWithECAT()-> Conversion error occurred while trying to parse line: " << line<< endl);
3889 if(block_pos_X!=0 && block_pos_Y !=0)
3891 Cerr(
"***** dataConversionUtilities::CreateGeomWithECAT()-> Conversion error occurred while trying to parse line: " << line<< endl);
3892 Cerr(
" Block cartesian coordinates on either the X or Y axis expected to be equal to 0 "<< endl);
3897 if(block_pos_Y!=0) is_block_Y_axis =
true;
3899 scanner_radius += is_block_Y_axis ? abs(block_pos_Y) : abs(block_pos_X) ;
3926 entry =
"/gate/"+block_name+
"/geometry/setZLength";
3928 if (values.size()>0)
3932 Cerr(
"***** dataConversionUtilities::CreateGeomWithECAT()-> Conversion error occurred while trying to parse line: " << line<< endl);
3936 voxels_number_axl = fov_axl/4 + 1;
3941 entry =
"/gate/"+block_name+
"/ring/setRepeatNumber";
3943 if (values.size()>0)
3947 Cerr(
"***** dataConversionUtilities::CreateGeomWithECAT()-> Conversion error occurred while trying to parse line: " << line<< endl);
3953 entry =
"/gate/"+block_name+
"/ring/setFirstAngle";
3955 if (values.size()>0)
3959 Cerr(
"***** dataConversionUtilities::CreateGeomWithECAT()-> Conversion error occurred while trying to parse line: " << line<< endl);
3965 entry =
"/gate/"+block_name+
"/ring/setAngularSpan";
3967 if (values.size()>0)
3971 Cerr(
"***** dataConversionUtilities::CreateGeomWithECAT()-> Conversion error occurred while trying to parse line: " << line<< endl);
3976 entry =
"/gate/"+block_name+
"/ring/setModuloNumber";
3978 if (values.size()>0)
3982 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
3987 for (
int i=1; i<8; i++)
3989 entry =
"/gate/"+block_name+
"/ring/setZShift"+
toString(i);
3991 if (values.size()>0)
3996 Cerr(
"***** dataConversionUtilities::CreateGeomWithECAT()-> Conversion error occurred while trying to parse line: " << line<< endl);
3999 vec_block_Z_Shift.push_back(zshift);
4007 entry =
"/gate/"+block_name+
"/linear/setRepeatNumber";
4009 if (values.size()>0)
4013 Cerr(
"***** dataConversionUtilities::CreateGeomWithECAT()-> Conversion error occurred while trying to parse line: " << line<< endl);
4019 entry =
"/gate/"+block_name+
"/linear/setRepeatVector";
4021 if (values.size()>0)
4025 Cerr(
"***** dataConversionUtilities::CreateGeomWithECAT()-> Conversion error occurred while trying to parse line: " << line<< endl);
4034 entry =
"/gate/"+crystal_name+
"/placement/setTranslation";
4037 FLTNB crystal_pos_X =0.,
4040 if (values.size()>0)
4045 Cerr(
"***** dataConversionUtilities::CreateGeomWithECAT()-> Conversion error occurred while trying to parse line: " << line<< endl);
4051 if(crystal_pos_X!=0 && crystal_pos_Y !=0)
4053 Cerr(
"***** dataConversionUtilities::CreateGeomWithECAT()-> Conversion error occurred while trying to parse line: " << line<< endl);
4054 Cerr(
" Block cartesian coordinates on either the X or Y axis expected to be equal to 0 "<< endl);
4058 scanner_radius += is_block_Y_axis ? crystal_pos_Y : crystal_pos_X ;
4062 entry = is_block_Y_axis ?
4063 "/gate/"+crystal_name+
"/geometry/setYLength" :
4064 "/gate/"+crystal_name+
"/geometry/setXLength";
4067 if (values.size()>0)
4069 double crystal_size = 0.;
4072 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
4076 scanner_radius -= crystal_size/2;
4082 entry = is_block_Y_axis ?
4083 "/gate/"+crystal_name+
"/cubicArray/setRepeatNumberX":
4084 "/gate/"+crystal_name+
"/cubicArray/setRepeatNumberY";
4087 if (values.size()>0)
4091 Cerr(
"***** dataConversionUtilities::CreateGeomWithECAT()-> Conversion error occurred while trying to parse line: " << line<< endl);
4096 entry =
"/gate/"+crystal_name+
"/cubicArray/setRepeatNumberZ";
4098 if (values.size()>0)
4102 Cerr(
"***** dataConversionUtilities::CreateGeomWithECAT()-> Conversion error occurred while trying to parse line: " << line<< endl);
4108 entry =
"/gate/"+crystal_name+
"/cubicArray/setRepeatVector";
4110 if (values.size()>0)
4112 string trs_step = is_block_Y_axis ?
4119 Cerr(
"***** dataConversionUtilities::CreateGeomWithECAT()-> Conversion error occurred while trying to parse line: " << line<< endl);
4126 entry =
"/gate/"+crystal_name+
"/geometry/setXLength";
4128 if (values.size()>0)
4133 Cerr(
"***** dataConversionUtilities::CreateGeomWithECAT()-> Conversion error occurred while trying to parse line: " << line<< endl);
4137 if (is_block_Y_axis)
4138 crystal_size_trs = x_length;
4140 crystal_size_depth = x_length;
4145 entry =
"/gate/"+crystal_name+
"/geometry/setYLength";
4147 if (values.size()>0)
4152 Cerr(
"***** dataConversionUtilities::CreateGeomWithECAT()-> Conversion error occurred while trying to parse line: " << line<< endl);
4156 if (is_block_Y_axis)
4157 crystal_size_depth = y_length;
4159 crystal_size_trs = y_length;
4162 entry =
"/gate/"+crystal_name+
"/geometry/setZLength";
4164 if (values.size()>0)
4168 Cerr(
"***** dataConversionUtilities::CreateGeomWithECAT()-> Conversion error occurred while trying to parse line: " << line<< endl);
4176 entry =
"/gate/digitizer/Coincidences/minSectorDifference";
4178 if (values.size()>0)
4180 double min_sector_diff;
4183 Cerr(
"***** dataConversionUtilities::CreateGeomWithECAT()-> Conversion error occurred while trying to parse line: " << line<< endl);
4186 min_angle_diff = 360/number_of_blocks*min_sector_diff;
4193 number_of_elements = number_of_blocks *
4194 number_of_blocks_axl *
4195 number_of_crystals_trs *
4196 number_of_crystals_axl;
4201 fov_trs = (2*scanner_radius ) / 1.5;
4204 voxels_number_trs = ( number_of_crystals_trs
4205 * number_of_blocks_trs)
4209 if (crystal_step_axl - crystal_size_axl >= 0)
4210 crystal_gap_axl = crystal_step_axl - crystal_size_axl;
4212 if (crystal_step_trs - crystal_size_trs >= 0)
4213 crystal_gap_trs = crystal_step_trs - crystal_size_trs;
4217 block_size_Z = crystal_size_axl*number_of_crystals_axl + crystal_gap_axl*(number_of_crystals_axl-1);
4218 block_size_Y = crystal_size_trs*number_of_crystals_trs + crystal_gap_trs*(number_of_crystals_trs-1);
4221 if (block_step_axl - block_size_Z >= 0)
4222 block_gap_axl = block_step_axl - block_size_Z;
4224 if (block_step_trs - block_size_Y >= 0)
4225 block_gap_trs = block_step_trs - block_size_Y;
4228 block_first_angle -= round(atan2f(block_pos_X , block_pos_Y) * 180. / M_PI);
4232 ofstream fileGeom(a_pathGeom.c_str(), ios::out | ios::trunc);
4236 fileGeom <<
"# comments" << endl;
4237 fileGeom <<
"# Y _________ "<< endl;
4238 fileGeom <<
"# | / _ \\ \\ "<< endl;
4239 fileGeom <<
"# | | / \\ | |"<< endl;
4240 fileGeom <<
"# |_____ Z | | | | |"<< endl;
4241 fileGeom <<
"# \\ | | | | |" << endl;
4242 fileGeom <<
"# \\ | \\_/ | |" << endl;
4243 fileGeom <<
"# X \\___/_____/" << endl;
4244 fileGeom <<
"# Left-handed axis orientation"<< endl;
4245 fileGeom <<
"# scanner axis is z" << endl;
4246 fileGeom <<
"# positions in millimeters"<< endl;
4247 fileGeom <<
"# Use comma without space as separator in the tables." << endl;
4250 fileGeom <<
"modality : " << modality << endl;
4251 fileGeom <<
"scanner name : " << scanner_name << endl;
4252 fileGeom <<
"number of elements : " << number_of_elements << endl;
4253 fileGeom <<
"number of layers : " <<
"1" << endl;
4254 fileGeom <<
"" << endl;
4255 fileGeom <<
"# default reconstruction parameters" << endl;
4256 fileGeom <<
"voxels number transaxial : " << voxels_number_trs << endl;
4257 fileGeom <<
"voxels number axial : " << voxels_number_axl << endl;
4259 fileGeom <<
"field of view transaxial : " << fov_trs << endl;
4260 fileGeom <<
"field of view axial : " << fov_axl << endl;
4261 fileGeom <<
"" << endl;
4262 fileGeom <<
"description : " << description << endl;
4263 fileGeom <<
"" << endl;
4264 fileGeom <<
"scanner radius : " << scanner_radius << endl;
4265 fileGeom <<
"number of rsectors : " << number_of_blocks << endl;
4266 fileGeom <<
"number of crystals transaxial : " << number_of_crystals_trs << endl;
4267 fileGeom <<
"number of crystals axial : " << number_of_crystals_axl << endl;
4269 fileGeom <<
""<< endl;
4270 fileGeom <<
"# The 4 following parameters could be defined in arrays (SizeLayer1,SizeLayer2,SizeLayer3,etc..) if their is more than one layer"<< endl;
4271 fileGeom <<
"crystals size depth : " << crystal_size_depth << endl;
4272 fileGeom <<
"crystals size transaxial : " << crystal_size_trs << endl;
4273 fileGeom <<
"crystals size axial : " << crystal_size_axl << endl;
4274 fileGeom <<
""<< endl;
4277 fileGeom <<
"rsectors first angle : " << block_first_angle << endl;
4278 fileGeom <<
"number of modules transaxial : " << number_of_blocks_trs << endl;
4279 fileGeom <<
"number of modules axial : " << number_of_blocks_axl << endl;
4280 fileGeom <<
"module gap transaxial : " << block_gap_trs << endl;
4281 fileGeom <<
"module gap axial : " << block_gap_axl << endl;
4282 fileGeom <<
"crystal gap transaxial : " << crystal_gap_trs << endl;
4283 fileGeom <<
"crystal gap axial : " << crystal_gap_axl << endl;
4284 fileGeom <<
"rotation direction : CCW " << endl;
4285 fileGeom <<
""<< endl;
4288 if(min_angle_diff > 0.) fileGeom <<
"min angle difference : " << min_angle_diff << endl;
4291 if(block_angular_span >= 360.0005 ||
4292 block_angular_span <= 359.9995 )
4294 block_angular_span *= (double)(number_of_blocks)/(double)(number_of_blocks-1);
4295 fileGeom <<
"rsectors angular span : " << block_angular_span << endl;
4298 if(block_nb_zshifts > 0) fileGeom <<
"rsectors nbZShift :" << block_nb_zshifts << endl;
4299 if(!vec_block_Z_Shift.empty())
WriteVector(fileGeom,
"rsectors ZShift : ", vec_block_Z_Shift);
4303 Cout(
"Output geom file written at :" << a_pathGeom << endl);
4307 Cerr(
"***** dataConversionUtilities::CreateGeomWithECAT()-> Couldn't open geom file for writing "<< a_pathGeom <<
" !" << endl);
4332 string scanner_name =
GetFileFromPath(a_pathGeom.substr(0,a_pathGeom.find_first_of(
".geom")));
4333 FLTNB scanner_radius = -1.;
4334 string description =
"SPECT camera extracted from GATE macro: " + a_pathMac;
4337 string head_name =
"SPECThead";
4338 uint32_t number_of_heads = 0;
4339 FLTNB head_pos_X = 0.;
4340 FLTNB head_pos_Y = 0.;
4341 FLTNB head_first_angle = 0.;
4342 FLTNB head_angular_pitch = -1.;
4343 string head_orbit_name =
"";
4344 FLTNB head_rotation_speed = 0.;
4345 bool is_head_Y_axis =
false;
4348 string crystal_name =
"crystal";
4349 FLTNB crystal_size_trs = 0.;
4350 FLTNB crystal_size_axl = 0.;
4351 FLTNB crystal_depth = 0;
4354 string pixel_name =
"pixel";
4355 uint32_t number_of_pixels_trs = 1;
4356 uint32_t number_of_pixels_axl = 1;
4357 FLTNB pix_size_trs = 0.;
4358 FLTNB pix_size_axl = 0.;
4359 FLTNB pix_step_trs = 0.;
4360 FLTNB pix_step_axl = 0.;
4361 FLTNB pix_gap_trs = 0.;
4362 FLTNB pix_gap_axl = 0.;
4365 string focal_model_trs =
"constant";
4366 uint16_t nb_coeff_model_trs = 1;
4367 FLTNB coeff_model_trs = 0.;
4368 string focal_model_axl =
"constant";
4369 uint16_t nb_coeff_model_axl = 1;
4370 FLTNB coeff_model_axl = 0.;
4373 uint32_t voxels_number_trs;
4374 uint32_t voxels_number_axl;
4378 vector<string> path_mac_files;
4379 path_mac_files.push_back(a_pathMac);
4384 Cerr(
"***** dataConversionUtilities::CreateGeomWithSPECT()->Error occurred when trying to recover paths to GATE macro files !" << endl);
4392 Cerr(
"***** dataConversionUtilities::CreateGeomWithSPECT()->Error occurred when trying to recover aliases for the elements of the SPECThead !" << endl);
4397 for(uint16_t f=0 ; f<path_mac_files.size() ; f++)
4399 ifstream systemMac(path_mac_files[f].c_str(), ios::in);
4402 while(getline(systemMac, line))
4405 modality =
"SPECT_CONVERGENT";
4406 vector <string> values;
4410 entry =
"/gate/"+head_name+
"/placement/setTranslation";
4412 if (values.size()>0)
4417 Cerr(
"***** dataConversionUtilities::CreateGeomWithSPECT()-> Conversion error occurred while trying to parse line: " << line<< endl);
4423 if(head_pos_X!=0 && head_pos_Y !=0)
4425 Cerr(
"***** dataConversionUtilities::CreateGeomWithSPECT()-> Conversion error occurred while trying to parse line: " << line<< endl);
4426 Cerr(
" Block cartesian coordinates on either the X or Y axis expected to be equal to 0 "<< endl);
4431 if(head_pos_Y!=0) is_head_Y_axis =
true;
4433 scanner_radius = is_head_Y_axis ? abs(head_pos_Y) : abs(head_pos_X) ;
4437 entry =
"/gate/"+head_name+
"/geometry/setZLength";
4439 if (values.size()>0)
4443 Cerr(
"***** dataConversionUtilities::CreateGeomWithSPECT()-> Conversion error occurred while trying to parse line: " << line<< endl);
4447 voxels_number_axl = fov_axl/4 + 1;
4451 entry =
"/gate/"+head_name+
"/ring/setRepeatNumber";
4453 if (values.size()>0)
4457 Cerr(
"***** dataConversionUtilities::CreateGeomWithSPECT()-> Conversion error occurred while trying to parse line: " << line<< endl);
4463 entry =
"/gate/"+head_name+
"/ring/setFirstAngle";
4465 if (values.size()>0)
4469 Cerr(
"***** dataConversionUtilities::CreateGeomWithSPECT()-> Conversion error occurred while trying to parse line: " << line<< endl);
4475 entry =
"/gate/"+head_name+
"/ring/setAngularPitch";
4477 if (values.size()>0)
4481 Cerr(
"***** dataConversionUtilities::CreateGeomWithSPECT()-> Conversion error occurred while trying to parse line: " << line<< endl);
4486 entry =
"/gate/"+head_name+
"/moves/insert";
4488 if (values.size()>0)
4492 Cerr(
"***** dataConversionUtilities::CreateGeomWithSPECT()-> Conversion error occurred while trying to parse line: " << line<< endl);
4497 entry =
"/gate/"+head_orbit_name+
"/setSpeed";
4499 if (values.size()>0)
4503 Cerr(
"***** dataConversionUtilities::CreateGeomWithSPECT()-> Conversion error occurred while trying to parse line: " << line<< endl);
4511 entry =
"/gate/"+crystal_name+
"/geometry/setXLength";
4513 if (values.size()>0)
4518 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
4523 crystal_size_trs = x_length;
4525 crystal_depth = x_length;
4528 entry =
"/gate/"+crystal_name+
"/geometry/setYLength";
4530 if (values.size()>0)
4535 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
4540 crystal_depth = y_length;
4542 crystal_size_trs = y_length;
4546 entry =
"/gate/"+crystal_name+
"/geometry/setZLength";
4548 if (values.size()>0)
4552 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
4562 entry = is_head_Y_axis ?
4563 "/gate/"+pixel_name+
"/cubicArray/setRepeatNumberX":
4564 "/gate/"+pixel_name+
"/cubicArray/setRepeatNumberY";
4568 if (values.size()>0)
4572 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
4577 entry =
"/gate/"+pixel_name+
"/cubicArray/setRepeatNumberZ";
4579 if (values.size()>0)
4583 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
4589 entry =
"/gate/"+pixel_name+
"/geometry/setXLength";
4591 if (values.size()>0)
4596 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
4601 pix_size_trs = x_length;
4604 entry =
"/gate/"+pixel_name+
"/geometry/setYLength";
4606 if (values.size()>0)
4611 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
4615 if (!is_head_Y_axis)
4616 pix_size_trs = y_length;
4620 entry =
"/gate/"+pixel_name+
"/geometry/setZLength";
4622 if (values.size()>0)
4626 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
4632 entry =
"/gate/"+pixel_name+
"/cubicArray/setRepeatVector";
4634 if (values.size()>0)
4636 string trs_step = is_head_Y_axis ?
4643 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
4650 entry = is_head_Y_axis ?
4651 "/gate/fanbeam/geometry/setFocalDistanceY":
4652 "/gate/fanbeam/geometry/setFocalDistanceX";
4654 entry =
"/gate/fanbeam/geometry/setFocalDistanceX";
4656 if (values.size()>0)
4660 Cerr(
"***** dataConversionUtilities::CreateGeomWithCylindrical()-> Conversion error occurred while trying to parse line: " << line<< endl);
4664 focal_model_trs =
"polynomial";
4672 fov_trs = scanner_radius/2;
4674 voxels_number_trs = fov_trs/2 + 1;
4676 uint32_t nb_pixels = number_of_pixels_axl * number_of_pixels_trs;
4678 pix_size_axl = nb_pixels>1 ? pix_size_axl : crystal_size_axl;
4679 pix_size_trs = nb_pixels>1 ? pix_size_trs : crystal_size_trs;
4682 if (pix_step_axl - pix_size_axl >= 0)
4683 pix_gap_axl = pix_step_axl - pix_size_axl;
4685 if (pix_step_trs - pix_size_trs >= 0)
4686 pix_gap_trs = pix_step_trs - pix_size_trs;
4690 head_first_angle = round(atan2f(head_pos_X , head_pos_Y) * 180. / M_PI)
4695 ofstream fileGeom(a_pathGeom.c_str(), ios::out | ios::trunc);
4699 fileGeom <<
"modality : " << modality << endl;
4700 fileGeom <<
"scanner name : " << scanner_name << endl;
4701 fileGeom <<
"number of detector heads : " << number_of_heads << endl;
4702 fileGeom <<
"trans number of pixels : " << number_of_pixels_trs << endl;
4703 fileGeom <<
"trans pixel size : " << pix_size_trs << endl;
4704 fileGeom <<
"trans gap size : " << pix_gap_trs << endl;
4705 fileGeom <<
"axial number of pixels : " << number_of_pixels_axl << endl;
4706 fileGeom <<
"axial pixel size : " << pix_size_axl << endl;
4707 fileGeom <<
"axial gap size : " << pix_gap_axl << endl;
4709 fileGeom <<
"detector depth : " << crystal_depth << endl;
4711 fileGeom <<
"scanner radius : " << scanner_radius;
4712 for(
size_t h=1 ; h<number_of_heads ; h++)
4713 fileGeom <<
"," << scanner_radius;
4716 fileGeom <<
"# Collimator configuration : "<< endl << endl;
4717 for(
size_t h=0 ; h<number_of_heads ; h++)
4719 fileGeom <<
"head" << h+1 <<
":" << endl;
4720 fileGeom <<
"trans focal model: " << focal_model_trs << endl;
4721 fileGeom <<
"trans number of coef model: " << nb_coeff_model_trs << endl;
4722 fileGeom <<
"trans parameters: " << coeff_model_trs << endl;
4723 fileGeom <<
"axial focal model: " << focal_model_axl << endl;
4724 fileGeom <<
"axial number of coef model: " << nb_coeff_model_axl << endl;
4725 fileGeom <<
"axial parameters: " << coeff_model_axl << endl;
4729 fileGeom <<
"" << endl;
4730 fileGeom <<
"# default reconstruction parameters" << endl;
4731 fileGeom <<
"voxels number transaxial : " << voxels_number_trs << endl;
4732 fileGeom <<
"voxels number axial : " << voxels_number_axl << endl;
4734 fileGeom <<
"field of view transaxial : " << fov_trs << endl;
4735 fileGeom <<
"field of view axial : " << fov_axl << endl << endl ;
4736 fileGeom <<
""<< endl;
4738 fileGeom <<
"# description" << endl;
4739 fileGeom <<
"description : " << description << endl;
4743 Cout(
"Output geom file written at :" << a_pathGeom << endl);
4747 Cerr(
"***** dataConversionUtilities::CreateGeomWithSPECT()-> Couldn't open geom file for writing "<< a_pathGeom <<
" !" << endl);
This header file is mainly used to declare some macro definitions and all includes needed from the st...
uint32_t ConvertIDecat(int32_t nBlocksPerRing, int32_t nBlocksLine, int32_t nCrystalsTransaxial, int32_t nCrystalsAxial, int32_t crystalID, int32_t blockID)
Compute a CASToR crystal index of a GATE ecat system from its indexes (block/crystal) and the system ...
This file gathers various function dedicated to data conversion in order to convert various type of G...
int IntfKeyGetRecurringValueFromFile(const string &a_pathToHeader, const string &a_key, T *ap_return, int a_nbElts, int a_mandatoryFlag, uint16_t a_nbOccurrences)
vector< string > CheckGATECommand(const string &a_key, const string &a_line)
Check if the line contains the provided GATE command. In this case, parse the line and returns the va...
int GetGATEAliasesCylindrical(vector< string > path_mac_files, string &rsector_name, string &module_name, string &submodule_name, string &crystal_name, vector< string > &layers_name, int vb)
Loop over a list of path to GATE macro files passed in parameter to recover aliases of the different ...
int IntfKeyGetValueFromFile(const string &a_pathToHeader, const string &a_key, T *ap_return, int a_nbElts, int a_mandatoryFlag)
Look for "a_nbElts" elts in the "a_pathToHeader" interfile header matching the "a_keyword" key passed...
int ReadMacECAT(string a_pathMac, uint32_t &nCrystalsTot, uint32_t &nCrystalsAxial, uint32_t &nCrystalsTransaxial, uint32_t &nBlocksLine, uint32_t &nBlocksPerRing, uint32_t &start_time_ms, uint32_t &duration_ms, FLTNB &pet_coinc_window, int vb)
string GetFileFromPath(const string &a_pathToFile)
Simply return the file from a path string passed in parameter.
int ConvertFromString(const string &a_str, string *a_result)
Copy the 'a_str' string in the position pointed by 'a_result'.
int GetGATEMacFiles(const string &a_pathMac, vector< string > &ap_pathToMacFiles)
Extract the paths to each macro file contained in the main macro file.
int CreateGeomWithSPECT(string a_pathMac, string a_pathGeom)
Read a GATE macro file containing the description of a SPECThead system, and convert it to a geom fil...
int ReadIntfSPECT(string a_pathIntf, float_t &a_distToDetector, uint32_t &a_nHeads, uint32_t &a_nPixAxl, uint32_t &a_nPixTrs, float_t &a_crystalSizeAxl, float_t &a_crystalSizeTrs, uint32_t &a_nProjectionsTot, uint32_t &a_nProjectionsByHead, float_t &a_head1stAngle, float_t &a_headAngPitchDeg, float_t &a_headAngStepDeg, int &a_headRotDirection, uint32_t &a_start_time_ms, uint32_t &a_duration_ms, int vb)
Recover informations about the scanner element of an ECAT system, and acquisition duration...
void ConvertValuesTomm(vector< string > &ap_v)
Check if the vector of strings passed in parameter contains the 'cm' unit In this case...
uint32_t ConvertIDcylindrical(uint32_t nRsectorsAngPos, uint32_t nRsectorsAxial, bool a_invertDetOrder, int a_rsectorIdOrder, uint32_t nModulesTransaxial, uint32_t nModulesAxial, uint32_t nSubmodulesTransaxial, uint32_t nSubmodulesAxial, uint32_t nCrystalsTransaxial, uint32_t nCrystalsAxial, uint8_t nLayers, uint32_t *nCrystalPerLayer, vector< uint32_t > nLayersRptTransaxial, vector< uint32_t > nLayersRptAxial, int32_t layerID, int32_t crystalID, int32_t submoduleID, int32_t moduleID, int32_t rsectorID)
Compute a CASToR crystal index of a GATE cylindricalPET system from its indexes (rsector/module/submo...
int ReadMacSPECT(string a_pathMac, float_t &a_distToDetector, uint32_t &a_nHeads, uint32_t &a_nPixAxl, uint32_t &a_nPixTrs, float_t &a_crystalSizeAxl, float_t &a_crystalSizeTrs, uint32_t &a_nProjectionsTot, uint32_t &a_nProjectionsByHead, float_t &a_head1stAngle, float_t &a_headAngPitch, float_t &a_headAngStepDeg, int &a_headRotDirection, uint32_t &a_start_time_ms, uint32_t &a_duration_ms, int vb)
Recover informations about the scanner element of an ECAT system, and acquisition duration...
int ComputeKindGATEEvent(uint32_t eventID1, uint32_t eventID2, int comptonPhantom1, int comptonPhantom2, int rayleighPhantom1, int rayleighPhantom2)
Determine kind of a given coincidence event, from its attributes.
#define KEYWORD_MANDATORY
#define GATE_SYS_CYLINDRICAL
int GetGATEAliasesEcat(vector< string > path_mac_files, string &block_name, string &crystal_name, int vb)
Loop over a list of path to GATE macro files passed in parameter to recover aliases of the different ...
uint32_t ConvertIDSPECTRoot2(uint32_t a_nbSimulatedPixels, uint32_t a_nPixTrs, uint32_t a_nPixAxl, int32_t a_headID, int32_t a_crystalID, int32_t a_pixelID, float_t a_rotAngle, float_t a_headAngPitch, float_t a_crystalSizeAxl, float_t a_crystalSizeTrs, float_t a_gPosX, float_t a_gPosY, float_t a_gPosZ)
Compute a CASToR crystal index of a GATE SPECThead system.
string toString(T a_val)
Convert a value of any type into string.
string GetPathOfFile(const string &a_pathToFile)
Simply return the path to the directory of a file path string passed in parameter.
int CreateGeomWithCylindrical(string a_pathMac, string a_pathGeom)
Read a GATE macro file containing the description of a cylindricalPET system, and convert it to a geo...
uint32_t ConvertIDSPECTRoot1(int32_t a_headID, float_t a_rotAngle, float_t a_angStep, uint32_t a_nProjectionsByHead)
Compute a CASToR projection index of a GATE SPECThead system.
#define GATE_NB_MAX_LAYERS
int CreateGeomWithECAT(string a_pathMac, string a_pathGeom)
Read a GATE macro file containing the description of an ecat system, and convert it to a geom file...
vector< string > Split(string a_line)
Split the line provided in parameter into a vector of strings (separator is blankspace) ...
int WriteVector(ofstream &file, const string &a_key, vector< T > a_vals)
Write the key and its values in the file provided in parameter.
int ReadMacCylindrical(string a_pathMac, uint8_t &nLayers, uint32_t *nb_crystal_per_layer, uint32_t &nCrystalsTot, uint32_t &nCrystalsAxial, uint32_t &nCrystalsTransaxial, vector< uint32_t > &nLayersRptAxial, vector< uint32_t > &nLayersRptTransaxial, uint32_t &nSubmodulesAxial, uint32_t &nSubmodulesTransaxial, uint32_t &nModulesAxial, uint32_t &nModulesTransaxial, uint32_t &nRsectorsAxial, uint32_t &nRsectorsAngPos, bool &invert_det_order, int &rsector_id_order, uint32_t &start_time_ms, uint32_t &duration_ms, FLTNB &pet_coinc_window, int vb)
int GetGATESystemType(const string &a_pathMac)
Read a GATE macro file and identify the system type from the 'gate/systems/' command lines...
int GetGATEAliasesSPECT(vector< string > path_mac_files, string &base_name, string &crystal_name, string &pixel_name, int vb)
Loop over a list of path to GATE macro files passed in parameter to recover aliases of the different ...