31 #include <phgeom/PHGeomUtility.h>
32 #include <phgeom/PHGeomIOTGeo.h>
33 #include <phgeom/PHGeomTGeo.h>
59 #pragma GCC diagnostic push
60 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
61 #pragma GCC diagnostic ignored "-Wuninitialized"
63 #pragma GCC diagnostic pop
75 #include <TGeoManager.h>
103 else if(
auto found = find_volume_by_name(
child.get(),
name ) )
return found;
110 template<
class T>
inline constexpr
T square(
const T&
x ) {
return x*
x; }
134 findNode::getClass<PHG4TpcCylinderGeomContainer>(topNode,
"CYLINDERCELLGEOM_SVTX");
166 for(
const auto&
surface:surfaceVector )
176 alignment_transformation.useInttSurveyGeometry(
m_inttSurvey);
179 alignment_transformation.verbosity();
181 alignment_transformation.createMap(topNode);
185 alignment_transformation.misalignmentFactor(
layer, factor);
192 { std::cout <<
"MakeActsGeometry::InitRun - TPC volume id: " <<
id << std::endl; }
195 { std::cout <<
"MakeActsGeometry::InitRun - Micromegas volume id: " <<
id << std::endl; }
258 if(TGeoManager::GetDefaultUnits() != TGeoManager::EDefaultUnits::kRootUnits)
260 std::cerr <<
"There is a potential unit mismatch in the ROOT geometry."
261 <<
" It is dangerous to continue and may lead to inconsistencies in the Acts geometry. Exiting."
266 TGeoVolume *World_vol = geoManager->GetTopVolume();
271 TGeoNode *tpc_envelope_node =
nullptr;
272 TGeoNode *tpc_gas_north_node =
nullptr;
277 std::cout <<
"EditTPCGeometry - searching under volume: ";
280 for (
int i = 0;
i < World_vol->GetNdaughters();
i++)
282 TString node_name = World_vol->GetNode(
i)->GetName();
283 if (node_name.BeginsWith(
"tpc_envelope"))
286 std::cout <<
"EditTPCGeometry - found " << node_name << std::endl;
288 tpc_envelope_node = World_vol->GetNode(
i);
293 assert(tpc_envelope_node);
296 TGeoVolume *tpc_envelope_vol = tpc_envelope_node->GetVolume();
300 std::cout <<
"EditTPCGeometry - searching under volume: ";
301 tpc_envelope_vol->Print();
304 for (
int i = 0;
i < tpc_envelope_vol->GetNdaughters();
i++)
306 TString node_name = tpc_envelope_vol->GetNode(
i)->GetName();
308 if (node_name.BeginsWith(
"tpc_gas_north"))
311 std::cout <<
"EditTPCGeometry - found " << node_name << std::endl;
313 tpc_gas_north_node = tpc_envelope_vol->GetNode(
i);
318 assert(tpc_gas_north_node);
319 TGeoVolume *tpc_gas_north_vol = tpc_gas_north_node->GetVolume();
320 assert(tpc_gas_north_vol);
322 int nfakesurfaces = 0;
323 for(
int i=0;
i<tpc_gas_north_vol->GetNdaughters();
i++)
325 TString node_name = tpc_gas_north_vol->GetNode(
i)->GetName();
326 if(node_name.BeginsWith(
"tpc_gas_measurement_"))
332 if(nfakesurfaces > 0)
337 std::cout <<
"EditTPCGeometry - gas volume: ";
338 tpc_gas_north_vol->Print();
345 geoManager->CloseGeometry();
353 TGeoManager *geoManager)
355 TGeoMedium *tpc_gas_medium = tpc_gas_vol->GetMedium();
359 std::cout <<
"MakeActsGeometry::addActsTpcSurfaces - m_nSurfPhi: " <<
m_nSurfPhi << std::endl;
364 for(
unsigned int ilayer = 0; ilayer <
m_nTpcLayers; ++ilayer)
368 sprintf(bname,
"tpc_gas_measurement_%u",ilayer);
372 double box_r_phi = 2.0 * tan_half_phi *
376 tpc_gas_measurement_vol[ilayer] = geoManager->MakeBox(bname, tpc_gas_medium,
381 tpc_gas_measurement_vol[ilayer]->SetLineColor(kBlack);
382 tpc_gas_measurement_vol[ilayer]->SetFillColor(kYellow);
383 tpc_gas_measurement_vol[ilayer]->SetVisibility(kTRUE);
387 std::cout <<
" Made box for layer " << ilayer
389 << box_r_phi <<
" ref arc "
392 tpc_gas_measurement_vol[ilayer]->Print();
393 tpc_gas_measurement_vol[ilayer]->CheckOverlaps();
396 for (
unsigned int iz = 0; iz <
m_nSurfZ; ++iz)
399 double z_center = 0.0;
403 for (
unsigned int iphi = 0; iphi <
m_nSurfPhi; ++iphi)
409 double phi_center = min_phi + m_surfStepPhi / 2.0;
410 double phi_center_degrees = phi_center * 180.0 / M_PI;
418 sprintf(rot_name,
"tpc_gas_rotation_%i", copy);
419 TGeoCombiTrans *tpc_gas_measurement_location
420 =
new TGeoCombiTrans(x_center, y_center, z_center,
421 new TGeoRotation(rot_name,
425 tpc_gas_vol->AddNode(tpc_gas_measurement_vol[ilayer],
426 copy, tpc_gas_measurement_location);
432 std::cout <<
"Box center : ("<<x_center<<
", " <<y_center
433 <<
", " << z_center <<
")" <<
" and in rphiz "
434 << sqrt(x_center*x_center+y_center*y_center)
435 <<
", " << atan2(y_center,x_center) <<
", "
436 << z_center << std::endl;
437 std::cout <<
"Box dimensions " <<
m_layerThickness[ilayer] *half_width_clearance_thick
439 <<
", " <<
m_surfStepZ*half_width_clearance_z <<
" and in xyz "
468 std::ostringstream fld;
473 "--geo-tgeo-jsonconfig", responseFile,
474 "--mat-input-type",
"file",
475 "--mat-input-file", materialFile,
476 "--bf-constant-tesla",fld.str().c_str(),
483 if(m_magField.find(
".root") != std::string::npos)
486 char *calibrationsroot = getenv(
"CALIBRATIONROOT");
487 m_magField =
"sphenix3dtrackingmapxyz.root";
489 if (calibrationsroot !=
nullptr)
496 argstr[7] =
"--bf-map-file";
498 argstr[9]=
"--bf-map-tree";
499 argstr[10] =
"fieldmap";
500 argstr[11] =
"--bf-map-lengthscale-mm";
502 argstr[13] =
"--bf-map-fieldscale-tesla";
508 std::cout <<
"Mag field now " << m_magField <<
" with rescale "
512 for (
int i = 0;
i < argc; ++
i)
515 std::cout << argstr[
i] <<
", ";
526 for(
int i=0;
i<argc;
i++)
534 responseFile =
"tgeo-sphenix-mms.json";
535 materialFile =
"sphenix-mm-material.json";
539 file.open(responseFile);
542 std::cout << responseFile
543 <<
" not found locally, use repo version"
545 char *offline_main = getenv(
"OFFLINE_MAIN");
548 (
"/share/tgeo-sphenix-mms.json");
551 file.open(materialFile);
554 std::cout << materialFile
555 <<
" not found locally, use repo version"
557 const char* calibrationroot = getenv(
"CALIBRATIONROOT");
560 (
"/ACTS/sphenix-mm-material.json");
565 std::cout <<
"using Acts material file : " << materialFile
567 std::cout <<
"Using Acts TGeoResponse file : " << responseFile
579 boost::program_options::options_description desc;
606 std::pair<std::shared_ptr<const Acts::TrackingGeometry>,
607 std::vector<std::shared_ptr<ActsExamples::IContextDecorator>>>
611 std::shared_ptr<const Acts::IMaterialDecorator>
matDeco =
nullptr;
614 auto fileName = vm[
"mat-input-file"].template as<std::string>();
616 if (fileName.find(
".json") != std::string::npos ||
617 fileName.find(
".cbor") != std::string::npos)
622 matDeco = std::make_shared<const Acts::JsonMaterialDecorator>(
627 matDeco = std::make_shared<const Acts::MaterialWiper>();
640 const auto path = vm[
"geo-tgeo-jsonconfig"].template as<std::string>();
651 std::cout <<
"There is no acts geometry response file loaded. Cannot build, exiting"
656 nlohmann::json djson;
660 config.
unitScalor = djson[
"geo-tgeo-unit-scalor"];
664 const auto beamPipeParameters =
665 djson[
"geo-tgeo-beampipe-parameters"].get<std::array<double, 3>>();
672 for (
const auto& volume : djson[
"Volumes"]) {
673 auto& vol = config.
volumes.emplace_back();
686 std::cout <<
"MakeActsGeometry::unpackVolumes - top volume: " << vol->volumeName() << std::endl;
692 auto mmBarrel = find_volume_by_name( vol,
"MICROMEGAS::Barrel" );
698 auto mvtxBarrel = find_volume_by_name( vol,
"MVTX::Barrel" );
709 auto inttBarrel = find_volume_by_name( vol,
"Silicon::Barrel" );
718 auto tpcBarrel = find_volume_by_name( vol,
"TPC::Barrel" );
731 { std::cout <<
"MakeActsGeometry::makeTpcMapPairs - tpcVolume: " << tpcVolume->volumeName() << std::endl; }
733 auto tpcLayerArray = tpcVolume->confinedLayers();
734 auto tpcLayerVector = tpcLayerArray->arrayObjects();
737 for(
unsigned int i = 0;
i < tpcLayerVector.size();
i++)
739 auto surfaceArray = tpcLayerVector.at(
i)->surfaceArray();
740 if(surfaceArray == NULL){
745 auto surfaceVector = surfaceArray->surfaces();
746 for(
unsigned int j = 0;
j < surfaceVector.size();
j++)
748 auto surf = surfaceVector.at(
j)->getSharedPtr();
752 std::vector<double> world_center = {vec3d(0) / 10.0,
762 std::map<unsigned int, std::vector<Surface>>::iterator mapIter;
768 mapIter->second.push_back(
surf);
773 std::vector<Surface> dumvec;
774 dumvec.push_back(
surf);
775 std::pair<unsigned int, std::vector<Surface>>
tmp =
776 std::make_pair(layer, dumvec);
789 { std::cout <<
"MakeActsGeometry::makeMmMapPairs - mmVolume: " << mmVolume->volumeName() << std::endl; }
790 const auto mmLayerArray = mmVolume->confinedLayers();
791 const auto mmLayerVector = mmLayerArray->arrayObjects();
794 for(
unsigned int i = 0;
i < mmLayerVector.size();
i++)
796 auto surfaceArray = mmLayerVector.at(
i)->surfaceArray();
797 if(!surfaceArray)
continue;
801 const auto surfaceVector = surfaceArray->surfaces();
803 for(
unsigned int j = 0;
j < surfaceVector.size();
j++)
805 auto surface = surfaceVector.at(
j)->getSharedPtr();
809 TVector3 world_center(
819 double delta_r_min = -1;
820 for(
auto iter = range.first; iter != range.second; ++iter )
823 const double delta_r = std::abs( this_layergeom->get_radius() -
get_r( world_center.x(), world_center.y() ) );
824 if( delta_r_min < 0 || delta_r < delta_r_min )
827 layergeom = this_layergeom;
828 delta_r_min = delta_r;
834 std::cout <<
"MakeActsGeometry::makeMmMapPairs - could not file CylinderGeomMicromegas matching ACTS surface" << std::endl;
842 std::cout <<
"MakeActsGeometry::makeMmMapPairs - could not file Micromegas tile matching ACTS surface" << std::endl;
847 { std::cout <<
"MakeActsGeometry::makeMmMapPairs - layer: " << layer <<
" tileid: " << tileid << std::endl; }
864 { std::cout <<
"MakeActsGeometry::makeInttMapPairs - inttVolume: " << inttVolume->volumeName() << std::endl; }
866 auto inttLayerArray = inttVolume->confinedLayers();
868 auto inttLayerVector = inttLayerArray->arrayObjects();
870 for (
unsigned int i = 0;
i < inttLayerVector.size();
i++)
873 auto surfaceArray = inttLayerVector.at(
i)->surfaceArray();
874 if (surfaceArray == NULL)
878 auto surfaceVector = surfaceArray->surfaces();
880 for (
unsigned int j = 0;
j < surfaceVector.size();
j++)
882 auto surf = surfaceVector.at(
j)->getSharedPtr();
885 double ref_rad[4] = {7.188, 7.732, 9.680, 10.262};
887 std::vector<double> world_center = {vec3d(0) / 10.0, vec3d(1) / 10.0, vec3d(2) / 10.0};
892 double layer_rad = sqrt(pow(world_center[0], 2) + pow(world_center[1], 2));
894 unsigned int layer = 0;
895 for (
unsigned int i = 0;
i < 4; ++
i)
897 if (fabs(layer_rad - ref_rad[
i]) < 0.1)
904 std::pair<TrkrDefs::hitsetkey, Surface>
tmp = make_pair(hitsetkey,
surf);
913 std::cout <<
"Layer radius " << layer_rad <<
" layer " << layer <<
" ladderPhi " << ladderPhi <<
" ladderZ " << ladderZ <<
" hitsetkey " << hitsetkey
914 <<
" recover surface from m_clusterSurfaceMapSilicon " << std::endl;
915 std::cout <<
" surface type " <<
surf->type() << std::endl;
916 auto assoc_layer =
surf->associatedLayer();
917 std::cout << std::endl
918 <<
" Layer type " << assoc_layer->layerType() << std::endl;
920 auto assoc_det_element =
surf->associatedDetectorElement();
921 if (assoc_det_element !=
nullptr)
923 std::cout <<
" Associated detElement has non-null pointer "
924 << assoc_det_element << std::endl;
925 std::cout << std::endl
926 <<
" Associated detElement found, thickness = "
927 << assoc_det_element->thickness() << std::endl;
930 std::cout << std::endl
931 <<
" Associated detElement is nullptr " << std::endl;
942 { std::cout <<
"MakeActsGeometry::makeMvtxMapPairs - mvtxVolume: " << mvtxVolume->volumeName() << std::endl; }
945 auto mvtxBarrelLayerArray = mvtxVolume->confinedLayers();
948 auto mvtxLayerVector1 = mvtxBarrelLayerArray->arrayObjects();
952 for (
unsigned int i = 0;
i < mvtxLayerVector1.size(); ++
i)
955 auto surfaceArray = mvtxLayerVector1.at(
i)->surfaceArray();
956 if (surfaceArray == NULL)
959 double ref_rad[3] = {2.556, 3.359, 4.134};
963 auto surfaceVector = surfaceArray->surfaces();
964 for (
unsigned int j = 0;
j < surfaceVector.size();
j++)
966 auto surf = surfaceVector.at(
j)->getSharedPtr();
968 std::vector<double> world_center = {vec3d(0) / 10.0, vec3d(1) / 10.0, vec3d(2) / 10.0};
969 double layer_rad = sqrt(pow(world_center[0], 2) + pow(world_center[1], 2));
970 unsigned int layer = 0;
971 for (
unsigned int i = 0;
i < 3; ++
i)
973 if (fabs(layer_rad - ref_rad[
i]) < 0.1)
980 std::pair<TrkrDefs::hitsetkey, Surface>
tmp = make_pair(hitsetkey,
surf);
990 std::cout <<
"Layer radius " << layer_rad <<
" Layer "
991 << layer <<
" stave " << stave <<
" chip " << chip
992 <<
" recover surface from m_clusterSurfaceMapSilicon "
996 std::cout <<
" surface type " << surf_iter->second->type()
998 auto assoc_layer =
surf->associatedLayer();
999 std::cout << std::endl <<
" Layer type "
1000 << assoc_layer->layerType() << std::endl;
1002 auto assoc_det_element =
surf->associatedDetectorElement();
1003 if (assoc_det_element !=
nullptr)
1005 std::cout <<
" Associated detElement has non-null pointer "
1006 << assoc_det_element << std::endl;
1007 std::cout << std::endl
1008 <<
" Associated detElement found, thickness = "
1009 << assoc_det_element->thickness() << std::endl;
1012 std::cout << std::endl
1013 <<
" Associated detElement is nullptr " << std::endl;
1023 unsigned int layer = 999;
1024 double layer_rad = sqrt(pow(world[0],2) + pow(world[1],2));
1025 for(
unsigned int ilayer=0;ilayer<
m_nTpcLayers;++ilayer)
1027 double tpc_ref_radius_low =
1029 double tpc_ref_radius_high =
1031 if(layer_rad >= tpc_ref_radius_low && layer_rad < tpc_ref_radius_high)
1038 if(layer >= m_nTpcLayers)
1041 <<
"Error: undefined layer, do nothing world = "
1042 << world[0] <<
" " << world[1] <<
" " << world[2]
1043 <<
" layer " << layer << std::endl;
1057 unsigned int readout_mod = 999;
1058 double phi_world = atan2(world[1], world[0]);
1063 if(phi_world >=min_phi && phi_world < max_phi)
1069 if(readout_mod >= m_nTpcModulesPerLayer)
1072 <<
"Error: readout_mod is undefined, do nothing phi_world = "
1073 << phi_world << std::endl;
1080 std::cout <<
" world = " << world[0] <<
" " << world[1]
1081 <<
" " << world[2] <<
" phi_world "
1082 << phi_world*180/M_PI <<
" layer " << layer
1083 <<
" readout_mod " << readout_mod <<
" side " << side
1084 <<
" hitsetkey " << hitset_key<< std::endl;
1096 std::cout <<
PHWHERE <<
"Did not get layergeom for layer "
1097 << layer << std::endl;
1101 unsigned int stave = 0;
1102 unsigned int chip = 0;
1105 unsigned int strobe = 0;
1108 return mvtx_hitsetkey;
1118 std::cout <<
PHWHERE <<
"Did not get layergeom for layer "
1119 << layer << std::endl;
1123 double location[3] = {world[0], world[1], world[2]};
1124 int segment_z_bin = 0;
1125 int segment_phi_bin = 0;
1127 segment_phi_bin, location);
1132 return intt_hitsetkey;
1228 int ladder_phi = -1;
1241 while ((pos = s.find(delimiter)) != std::string::npos)
1243 token = s.substr(0, pos);
1245 s.erase(0, pos + delimiter.length());
1247 layer = std::atoi(token.c_str()) + 3;
1249 itype = std::atoi(token.c_str());
1252 ladder_phi = std::atoi(token.c_str());
1253 if (s.compare(0, negz.length(), negz) == 0) zposneg = 0;
1254 if (s.compare(0, posz.length(), posz) == 0) zposneg = 1;
1259 ladder_z = itype + zposneg * 2;
1262 int ndaught = gnode->GetNdaughters();
1265 std::cout <<
PHWHERE <<
"OOPS: Did not find INTT sensor! Quit."
1271 TGeoNode *sensor_node = 0;
1272 for (
int i = 0;
i < ndaught; ++
i)
1274 std::string node_str = gnode->GetDaughter(
i)->GetName();
1276 if (node_str.compare(0, intt_refactive.length(), intt_refactive) == 0)
1278 sensor_node = gnode->GetDaughter(
i);
1287 std::pair<TrkrDefs::hitsetkey, TGeoNode *>
tmp = std::make_pair(
1288 node_key, sensor_node);
1292 std::cout <<
" INTT layer " << layer <<
" ladder_phi " << ladder_phi
1293 <<
" itype " << itype <<
" zposneg " << zposneg
1294 <<
" ladder_z " << ladder_z <<
" name "
1295 << sensor_node->GetName() << std::endl;
1317 while ((pos = s.find(delimiter)) != std::string::npos)
1319 token = s.substr(0, pos);
1321 s.erase(0, pos + delimiter.length());
1323 impr = std::atoi(token.c_str());
1338 else if (impr > 11 && impr < 28)
1350 TGeoNode *module_node = gnode->GetDaughter(0);
1351 int mnd = module_node->GetNdaughters();
1353 for (
int i = 0;
i < mnd; ++
i)
1355 std::string dstr = module_node->GetDaughter(
i)->GetName();
1356 if (dstr.compare(0, mvtx_chip.length(), mvtx_chip) == 0)
1359 std::cout <<
"Found MVTX layer " << layer <<
" stave " << stave
1360 <<
" chip " <<
i <<
" with node name "
1361 << module_node->GetDaughter(
i)->GetName() << std::endl;
1364 unsigned int strobe = 0;
1369 TGeoNode *sensor_node = module_node->GetDaughter(
i)->GetDaughter(0);
1370 std::pair<TrkrDefs::hitsetkey, TGeoNode *>
tmp = std::make_pair(
1371 node_key, sensor_node);
1375 std::cout <<
" MVTX layer " << layer <<
" stave " << stave
1376 <<
" chip " << chip <<
" name "
1377 << sensor_node->GetName() << std::endl;
1476 layeriter != layerrange.second;
1496 std::cout <<
"PAR Node missing, creating it" << std::endl;
1512 m_actsGeometry = findNode::getClass<ActsGeometry>(topNode,
"ActsGeometry");
1533 std::cout <<
PHWHERE <<
" Did not find TGeoManager, quit! "
1543 <<
" CYLINDERGEOM_MVTX node not found on node tree"
1549 findNode::getClass<PHG4TpcCylinderGeomContainer>(topNode,
"CYLINDERCELLGEOM_SVTX");
1553 <<
"ERROR: Can't find node CYLINDERCELLGEOM_SVTX"
1566 <<
" CYLINDERGEOM_INTT node not found on node tree"
1575 <<
" CYLINDERGEOM_MICROMEGAS_FULL node not found on node tree"