6 #include "GaudiKernel/EventContext.h"
8 #include "Acts/Definitions/Units.hpp"
9 #include "Acts/MagneticField/MagneticFieldContext.hpp"
25 #include "GaudiKernel/ITHistSvc.h"
36 : base_class(
t,
n,
p),
37 m_thistSvc(
"THistSvc",
n)
52 ATH_MSG_ERROR(
"Activate seeding on at least one between Pixel and Strip space point collections!");
53 return StatusCode::FAILURE;
75 return StatusCode::SUCCESS;
84 std::string tree_name = std::string(
"SeedTree_") +
name();
85 std::replace( tree_name.begin(), tree_name.end(),
'.',
'_' );
87 m_outputTree =
new TTree( tree_name.c_str() ,
"ActsSeedMakerValTool");
89 m_outputTree->Branch(
"eventNumber", &m_eventNumber,
"eventNumber/L");
114 std::string full_tree_name =
"/" + m_treeFolder +
"/" + tree_name;
117 return StatusCode::SUCCESS;
125 data.v_ActsSpacePointForSeed.emplace_back(sp);
136 r[3] =
static_cast<float>(Tp(0, 2));
137 r[4] =
static_cast<float>(Tp(1, 2));
138 r[5] =
static_cast<float>(Tp(2, 2));
144 std::span<float,15>
r)
154 std::pair<Amg::Vector3D, Amg::Vector3D>
e0 =
156 std::pair<Amg::Vector3D, Amg::Vector3D>
e1 =
167 r[3] =
static_cast<float>(b0[0]);
168 r[4] =
static_cast<float>(b0[1]);
169 r[5] =
static_cast<float>(b0[2]);
172 r[6] =
static_cast<float>(b1[0]);
173 r[7] =
static_cast<float>(b1[1]);
174 r[8] =
static_cast<float>(b1[2]);
177 r[9] =
static_cast<float>(d02[0]);
178 r[10] =
static_cast<float>(d02[1]);
179 r[11] =
static_cast<float>(d02[2]);
182 r[12] =
static_cast<float>(s0[0]) -
data.xbeam[0];
183 r[13] =
static_cast<float>(s0[1]) -
data.ybeam[0];
184 r[14] =
static_cast<float>(s0[2]) -
data.zbeam[0];
196 if (not inputSpacePointContainer.
isValid()){
198 return StatusCode::FAILURE;
204 if (prd_to_track_map_cptr !=
nullptr and
isUsed(sp, *prd_to_track_map_cptr))
continue;
208 return StatusCode::SUCCESS;
214 const std::vector<IdentifierHash>&
ids,
217 if (
ids.empty())
return StatusCode::SUCCESS;
221 if (not inputSpacePointContainer.
isValid()){
223 return StatusCode::FAILURE;
236 detElements->
size());
239 if (not
accessor.isIdentifierPresent(
id)) {
244 for (
auto [firstElement, lastElement] :
ranges) {
245 for (; firstElement != lastElement; ++firstElement) {
247 if (prd_to_track_map_cptr !=
nullptr and
isUsed(sp, *prd_to_track_map_cptr))
continue;
253 return StatusCode::SUCCESS;
265 if (!inputSpacePointContainer.
isValid()){
267 return StatusCode::FAILURE;
273 if (prd_to_track_map_cptr !=
nullptr and
isUsed(sp, *prd_to_track_map_cptr))
continue;
277 return StatusCode::SUCCESS;
283 const std::vector<IdentifierHash>&
ids,
287 if (
ids.empty())
return StatusCode::SUCCESS;
291 if (not inputSpacePointContainer.
isValid()){
293 return StatusCode::FAILURE;
306 detElements->
size());
309 if (not
accessor.isIdentifierPresent(
id)) {
314 for (
auto [firstElement, lastElement] :
ranges) {
315 for (; firstElement != lastElement; ++firstElement) {
317 if (prd_to_track_map_cptr !=
nullptr and
isUsed(sp, *prd_to_track_map_cptr))
continue;
323 return StatusCode::SUCCESS;
336 if (!inputSpacePointContainer.
isValid()){
338 return StatusCode::FAILURE;
344 if (prd_to_track_map_cptr !=
nullptr and
isUsed(sp, *prd_to_track_map_cptr))
continue;
348 return StatusCode::SUCCESS;
354 const std::vector<IdentifierHash>&
ids,
357 if (
ids.empty())
return StatusCode::SUCCESS;
361 if (not inputSpacePointContainer.
isValid()){
363 return StatusCode::FAILURE;
376 detElements->
size());
379 if (not
accessor.isIdentifierPresent(
id)) {
384 for (
auto [firstElement, lastElement] :
ranges) {
385 for (; firstElement != lastElement; ++firstElement) {
387 if (prd_to_track_map_cptr !=
nullptr and
isUsed(sp, *prd_to_track_map_cptr))
continue;
393 return StatusCode::SUCCESS;
403 double tx =
std::tan(beamSpotHandle->beamTilt(0));
404 double ty =
std::tan(beamSpotHandle->beamTilt(1));
406 double phi = std::atan2(ty,
tx);
407 double theta = std::acos(1. / std::sqrt(1. +
tx *
tx + ty * ty));
413 data.xbeam[0] =
static_cast<float>(cb.x());
414 data.xbeam[1] =
static_cast<float>(cosTheta * cosPhi * cosPhi + sinPhi * sinPhi);
415 data.xbeam[2] =
static_cast<float>(cosTheta * sinPhi * cosPhi - sinPhi * cosPhi);
416 data.xbeam[3] = -
static_cast<float>(sinTheta * cosPhi);
418 data.ybeam[0] =
static_cast<float>(cb.y());
419 data.ybeam[1] =
static_cast<float>(cosTheta * cosPhi * sinPhi - sinPhi * cosPhi);
420 data.ybeam[2] =
static_cast<float>(cosTheta * sinPhi * sinPhi + cosPhi * cosPhi);
421 data.ybeam[3] = -
static_cast<float>(sinTheta * sinPhi);
423 data.zbeam[0] =
static_cast<float>(cb.z());
424 data.zbeam[1] =
static_cast<float>(sinTheta * cosPhi);
425 data.zbeam[2] =
static_cast<float>(sinTheta * sinPhi);
426 data.zbeam[3] =
static_cast<float>(cosTheta);
432 if ( not readHandle.isValid() ) {
433 throw std::runtime_error(
"Error while retrieving Atlas Field Cache Cond DB");
436 if (fieldCondObj ==
nullptr) {
442 Acts::MagneticFieldContext magFieldContext(fieldCondObj);
451 Acts::MagneticFieldProvider::Cache magFieldCache = magneticField.
makeCache( magFieldContext );
452 Acts::Vector3 bField = *magneticField.
getField( beamPos,
455 data.bField[0] = bField[0];
456 data.bField[1] = bField[1];
457 data.bField[2] = bField[2];
459 data.K = 2. * s_toTesla / (300. * bField[2]);
471 const std::vector<IdentifierHash>& vPixel,
472 const std::vector<IdentifierHash>& vStrip)
const
479 data.i_ITkSpacePointForSeed =
data.l_ITkSpacePointForSeed.begin();
480 data.v_ActsSpacePointForSeed.clear();
483 data.i_ITkSeed =
data.i_ITkSeeds.begin();
494 if ( not prd_handle.
isValid() ) {
497 prd_to_track_map_cptr = prd_handle.
get();
499 if (prd_to_track_map_cptr !=
nullptr) {
515 data.initialized =
true;
526 data.iteration = iteration;
533 data.i_ITkSpacePointForSeed =
data.l_ITkSpacePointForSeed.begin();
534 data.v_ActsSpacePointForSeed.clear();
539 data.i_ITkSeed =
data.i_ITkSeeds.begin();
553 if (
data.iteration == 0)
565 if ( not prd_handle.
isValid() ) {
568 prd_to_track_map_cptr = prd_handle.
get();
575 if (isPixel and not
retrievePixel(ctx,
data, prd_to_track_map_cptr).isSuccess() ) {
589 data.initialized =
true;
595 const std::list<Trk::Vertex>& )
const
598 if (
data.v_ActsSpacePointForSeed.empty() )
605 std::vector<ITk::SiSpacePointForSeed*> sp_storage;
608 std::unique_ptr< ActsTrk::SeedContainer > seedPtrs = std::make_unique< ActsTrk::SeedContainer >();
610 std::string combinationType = isPixel ?
"PPP" :
"SSS";
611 ATH_MSG_DEBUG(
"Running Seed Finding (" << combinationType <<
") ...");
618 Acts::Vector3 bField(
data.bField[0],
data.bField[1],
data.bField[2] );
623 Acts::SpacePointContainerConfig spConfig;
624 spConfig.useDetailedDoubleMeasurementInfo = not isPixel;
626 Acts::SpacePointContainerOptions spOptions;
627 spOptions.beamPos = Acts::Vector2(beamPos.x(), beamPos.y());
648 if (
sc == StatusCode::FAILURE) {
649 ATH_MSG_ERROR(
"Error during seed production (" << combinationType <<
")");
653 ATH_MSG_DEBUG(
" \\__ Created " << seedPtrs->size() <<
" seeds");
654 data.nsazv = seedPtrs->size();
674 data.i_ITkSeed =
data.i_ITkSeeds.begin();
685 if (
data.i_ITkSeed ==
data.i_ITkSeeds.end())
689 }
while (!(*
data.i_ITkSeed++).set3(
data.seedOutput, 1./(1000. *
data.K)));
692 return &
data.seedOutput;
706 if(
track !=
nullptr) {
707 m_trackPt = (
track->trackParameters()->front()->pT())/1000.
f;
708 m_trackEta = std::abs(
track->trackParameters()->front()->eta());
715 m_z0 = seed->zVertex();
730 m_dzdr_b = seed->dzdr_b();
731 m_dzdr_t = seed->dzdr_t();
733 m_givesTrack = !(
track ==
nullptr);
747 MsgStream&
out)
const
761 std::string
s2,
s3,
s4, s5;
776 out<<
"|---------------------------------------------------------------------|"
792 out<<
"| useStripOverlap | "
795 out<<
"|---------------------------------------------------------------------|"
797 out<<
"| Beam X center | "
798 <<std::setw(12)<<std::setprecision(5)<<
data.xbeam[0]
800 out<<
"| Beam Y center | "
801 <<std::setw(12)<<std::setprecision(5)<<
data.ybeam[0]
803 out<<
"| Beam Z center | "
804 <<std::setw(12)<<std::setprecision(5)<<
data.zbeam[0]
806 out<<
"| Beam X-axis direction | "
807 <<std::setw(12)<<std::setprecision(5)<<
data.xbeam[1]
808 <<std::setw(12)<<std::setprecision(5)<<
data.xbeam[2]
809 <<std::setw(12)<<std::setprecision(5)<<
data.xbeam[3]
811 out<<
"| Beam Y-axis direction | "
812 <<std::setw(12)<<std::setprecision(5)<<
data.ybeam[1]
813 <<std::setw(12)<<std::setprecision(5)<<
data.ybeam[2]
814 <<std::setw(12)<<std::setprecision(5)<<
data.ybeam[3]
816 out<<
"| Beam Z-axis direction | "
817 <<std::setw(12)<<std::setprecision(5)<<
data.zbeam[1]
818 <<std::setw(12)<<std::setprecision(5)<<
data.zbeam[2]
819 <<std::setw(12)<<std::setprecision(5)<<
data.zbeam[3]
821 out<<
"|---------------------------------------------------------------------|"
834 out<<
"|---------------------------------------------------------------------|"
837 <<std::setw(12)<<
data.ns
840 <<std::setw(12)<<
data.nsaz
843 <<std::setw(12)<<
data.nsazv
845 out<<
"|---------------------------------------------------------------------|"
863 data.v_StripSpacePointForSeed.clear();
866 std::array<const Trk::SpacePoint*, 3>
spacePoints {};
867 std::array<ITk::SiSpacePointForSeed*, 3> stripSpacePointsForSeeds {};
876 ATH_MSG_FATAL(
"no sctSpacePointLink/stripOverlapSpacePointLink for bottom sp!");
881 ATH_MSG_FATAL(
"no sctSpacePointLink/stripOverlapSpacePointLink for middle sp!");
886 ATH_MSG_FATAL(
"no sctSpacePointLink/stripOverlapSpacePointLink for top sp!");
890 for (std::size_t nsp(0
ul); nsp < 3
ul; ++nsp) {
892 ? *linkAcc(*seed->sp()[nsp])
893 : *overlaplinkAcc(*seed->sp()[nsp]);
898 const auto& bottom_idx = seed->sp()[0]->measurements();
899 const auto& medium_idx = seed->sp()[1]->measurements();
900 const auto& top_idx = seed->sp()[2]->measurements();
902 std::array<const xAOD::StripCluster*, 6> strip_cluster {
911 if (not stripLinkAcc.
isAvailable(*strip_cluster[0]) or
913 ATH_MSG_FATAL(
"no sctClusterLink for clusters associated to bottom sp!");
916 if (not stripLinkAcc.
isAvailable(*strip_cluster[2]) or
918 ATH_MSG_FATAL(
"no sctClusterLink for clusters associated to middle sp!");
921 if (not stripLinkAcc.
isAvailable(*strip_cluster[4]) or
923 ATH_MSG_FATAL(
"no sctClusterLink for clusters associated to top sp!");
927 std::pair<std::size_t, std::size_t> key_b = std::make_pair(strip_cluster[0]->
index(), strip_cluster[1]->
index());
928 std::pair<std::size_t, std::size_t> key_m = std::make_pair(strip_cluster[2]->
index(), strip_cluster[3]->
index());
929 std::pair<std::size_t, std::size_t> key_t = std::make_pair(strip_cluster[4]->
index(), strip_cluster[5]->
index());
931 std::unique_ptr<InDet::SCT_SpacePoint>& ptr_b =
data.v_StripSpacePointForSeed[key_b];
933 ptr_b = std::make_unique<InDet::SCT_SpacePoint>(std::make_pair<IdentifierHash, IdentifierHash>(strip_cluster[0]->identifierHash(), strip_cluster[1]->identifierHash()),
934 Amg::Vector3D(seed->sp()[0]->x(), seed->sp()[0]->y(), seed->sp()[0]->z()),
935 std::make_pair<const Trk::PrepRawData*, const Trk::PrepRawData*>(*(stripLinkAcc(*strip_cluster[0])), *(stripLinkAcc(*strip_cluster[1]))));
937 std::unique_ptr<InDet::SCT_SpacePoint>& ptr_m =
data.v_StripSpacePointForSeed[key_m];
939 ptr_m = std::make_unique<InDet::SCT_SpacePoint>(std::make_pair<IdentifierHash, IdentifierHash>(strip_cluster[2]->identifierHash(), strip_cluster[3]->identifierHash()),
940 Amg::Vector3D(seed->sp()[1]->x(), seed->sp()[1]->y(), seed->sp()[1]->z()),
941 std::make_pair<const Trk::PrepRawData*, const Trk::PrepRawData*>(*(stripLinkAcc(*strip_cluster[2])), *(stripLinkAcc(*strip_cluster[3]))));
943 std::unique_ptr<InDet::SCT_SpacePoint>& ptr_t =
data.v_StripSpacePointForSeed[key_t];
945 ptr_t = std::make_unique<InDet::SCT_SpacePoint>(std::make_pair<IdentifierHash, IdentifierHash>(strip_cluster[4]->identifierHash(), strip_cluster[5]->identifierHash()),
946 Amg::Vector3D(seed->sp()[2]->x(), seed->sp()[2]->y(), seed->sp()[2]->z()),
947 std::make_pair<const Trk::PrepRawData*, const Trk::PrepRawData*>(*(stripLinkAcc(*strip_cluster[4])), *(stripLinkAcc(*strip_cluster[5]))));
951 data.v_StripSpacePointForSeed[key_b].get(),
952 data.v_StripSpacePointForSeed[key_m].get(),
953 data.v_StripSpacePointForSeed[key_t].get()
959 std::array<float, 15>
r;
960 r[0] = seed->sp()[
index]->x();
961 r[1] = seed->sp()[
index]->y();
962 r[2] = seed->sp()[
index]->z();
965 stripSpacePointsForSeeds[
index]->setQuality(-seed->seedQuality());
968 data.i_ITkSeeds.emplace_back(stripSpacePointsForSeeds[0], stripSpacePointsForSeeds[1],
969 stripSpacePointsForSeeds[2], seed->z());
970 data.i_ITkSeeds.back().setQuality(-seed->seedQuality());
987 data.v_PixelSpacePointForSeed.clear();
990 data.v_PixelSiSpacePointForSeed.clear();
991 data.v_PixelSiSpacePointForSeed.reserve(
data.ns);
992 std::unordered_map<std::size_t, std::size_t> bridge_idx_sispacepoints;
994 std::array<const Trk::SpacePoint*, 3>
spacePoints {
nullptr,
nullptr,
nullptr};
995 std::array<ITk::SiSpacePointForSeed*, 3> pixelSpacePointsForSeeds {
nullptr,
nullptr,
nullptr};
999 std::array<std::size_t, 3> indexes {
1000 seed->sp()[0]->index(),
1001 seed->sp()[1]->index(),
1002 seed->sp()[2]->index()
1005 const auto [bottom_idx, medium_idx, top_idx] = indexes;
1006 std::size_t max_index =
std::max(bottom_idx,
std::max(medium_idx, top_idx));
1007 if (
data.v_PixelSpacePointForSeed.size() < max_index + 1) {
1008 data.v_PixelSpacePointForSeed.resize( max_index + 1 );
1028 *linkAcc(*seed->sp()[0]),
1029 *linkAcc(*seed->sp()[1]),
1030 *linkAcc(*seed->sp()[2])
1039 if (not pixelLinkAcc.
isAvailable(*bottom_cluster)) {
1040 ATH_MSG_FATAL(
"no pixelClusterLink for cluster associated to bottom sp!");
1043 if (not pixelLinkAcc.
isAvailable(*medium_cluster)) {
1044 ATH_MSG_FATAL(
"no pixelClusterLink for cluster associated to middle sp!");
1048 ATH_MSG_FATAL(
"no pixelClusterLink for cluster associated to top sp!");
1052 if (not
data.v_PixelSpacePointForSeed[bottom_idx])
1053 data.v_PixelSpacePointForSeed[bottom_idx] = std::make_unique<InDet::PixelSpacePoint>(bottom_cluster->
identifierHash(), *(pixelLinkAcc(*bottom_cluster)));
1054 if (not
data.v_PixelSpacePointForSeed[medium_idx])
1055 data.v_PixelSpacePointForSeed[medium_idx] = std::make_unique<InDet::PixelSpacePoint>(medium_cluster->
identifierHash(), *(pixelLinkAcc(*medium_cluster)));
1056 if (not
data.v_PixelSpacePointForSeed[top_idx])
1057 data.v_PixelSpacePointForSeed[top_idx] = std::make_unique<InDet::PixelSpacePoint>(top_cluster->
identifierHash(), *(pixelLinkAcc(*top_cluster)));
1060 data.v_PixelSpacePointForSeed[bottom_idx].get(),
1061 data.v_PixelSpacePointForSeed[medium_idx].get(),
1062 data.v_PixelSpacePointForSeed[top_idx].get()
1068 std::size_t sp_idx = indexes[
index];
1073 auto [itr, outcome] = bridge_idx_sispacepoints.try_emplace(sp_idx,
data.v_PixelSiSpacePointForSeed.size());
1074 std::size_t mapped_idx = itr->second;
1077 std::array<float, 15>
r;
1078 r[0] = seed->sp()[
index]->x();
1079 r[1] = seed->sp()[
index]->y();
1080 r[2] = seed->sp()[
index]->z();
1085 data.v_PixelSiSpacePointForSeed[mapped_idx].setQuality(-seed->seedQuality());
1086 pixelSpacePointsForSeeds[
index] = &
data.v_PixelSiSpacePointForSeed[mapped_idx];
1089 data.i_ITkSeeds.emplace_back(pixelSpacePointsForSeeds[0],
1090 pixelSpacePointsForSeeds[1],
1091 pixelSpacePointsForSeeds[2],
1093 data.i_ITkSeeds.back().setQuality(-seed->seedQuality());