6 #include "GaudiKernel/EventContext.h"
8 #include "Acts/Definitions/Units.hpp"
9 #include "Acts/MagneticField/MagneticFieldContext.hpp"
26 #include "GaudiKernel/ITHistSvc.h"
37 : base_class(
t,
n,
p),
38 m_thistSvc(
"THistSvc",
n)
53 ATH_MSG_ERROR(
"Activate seeding on at least one between Pixel and Strip space point collections!");
54 return StatusCode::FAILURE;
76 return StatusCode::SUCCESS;
85 std::string tree_name = std::string(
"SeedTree_") +
name();
86 std::replace( tree_name.begin(), tree_name.end(),
'.',
'_' );
88 m_outputTree =
new TTree( tree_name.c_str() ,
"ActsSeedMakerValTool");
90 m_outputTree->Branch(
"eventNumber", &m_eventNumber,
"eventNumber/L");
115 std::string full_tree_name =
"/" + m_treeFolder +
"/" + tree_name;
118 return StatusCode::SUCCESS;
126 data.v_ActsSpacePointForSeed.emplace_back(sp);
137 r[3] =
static_cast<float>(Tp(0, 2));
138 r[4] =
static_cast<float>(Tp(1, 2));
139 r[5] =
static_cast<float>(Tp(2, 2));
155 std::pair<Amg::Vector3D, Amg::Vector3D>
e0 =
157 std::pair<Amg::Vector3D, Amg::Vector3D>
e1 =
168 r[3] =
static_cast<float>(b0[0]);
169 r[4] =
static_cast<float>(b0[1]);
170 r[5] =
static_cast<float>(b0[2]);
173 r[6] =
static_cast<float>(b1[0]);
174 r[7] =
static_cast<float>(b1[1]);
175 r[8] =
static_cast<float>(b1[2]);
178 r[9] =
static_cast<float>(d02[0]);
179 r[10] =
static_cast<float>(d02[1]);
180 r[11] =
static_cast<float>(d02[2]);
183 r[12] =
static_cast<float>(s0[0]) -
data.xbeam[0];
184 r[13] =
static_cast<float>(s0[1]) -
data.ybeam[0];
185 r[14] =
static_cast<float>(s0[2]) -
data.zbeam[0];
197 if (not inputSpacePointContainer.
isValid()){
199 return StatusCode::FAILURE;
205 if (prd_to_track_map_cptr !=
nullptr and
isUsed(sp, *prd_to_track_map_cptr))
continue;
209 return StatusCode::SUCCESS;
215 const std::vector<IdentifierHash>&
ids,
218 if (
ids.empty())
return StatusCode::SUCCESS;
222 if (not inputSpacePointContainer.
isValid()){
224 return StatusCode::FAILURE;
237 detElements->size());
240 if (not
accessor.isIdentifierPresent(
id)) {
245 for (
auto [firstElement, lastElement] :
ranges) {
246 for (; firstElement != lastElement; ++firstElement) {
248 if (prd_to_track_map_cptr !=
nullptr and
isUsed(sp, *prd_to_track_map_cptr))
continue;
254 return StatusCode::SUCCESS;
266 if (!inputSpacePointContainer.
isValid()){
268 return StatusCode::FAILURE;
274 if (prd_to_track_map_cptr !=
nullptr and
isUsed(sp, *prd_to_track_map_cptr))
continue;
278 return StatusCode::SUCCESS;
284 const std::vector<IdentifierHash>&
ids,
288 if (
ids.empty())
return StatusCode::SUCCESS;
292 if (not inputSpacePointContainer.
isValid()){
294 return StatusCode::FAILURE;
307 detElements->size());
310 if (not
accessor.isIdentifierPresent(
id)) {
315 for (
auto [firstElement, lastElement] :
ranges) {
316 for (; firstElement != lastElement; ++firstElement) {
318 if (prd_to_track_map_cptr !=
nullptr and
isUsed(sp, *prd_to_track_map_cptr))
continue;
324 return StatusCode::SUCCESS;
337 if (!inputSpacePointContainer.
isValid()){
339 return StatusCode::FAILURE;
345 if (prd_to_track_map_cptr !=
nullptr and
isUsed(sp, *prd_to_track_map_cptr))
continue;
349 return StatusCode::SUCCESS;
355 const std::vector<IdentifierHash>&
ids,
358 if (
ids.empty())
return StatusCode::SUCCESS;
362 if (not inputSpacePointContainer.
isValid()){
364 return StatusCode::FAILURE;
377 detElements->size());
380 if (not
accessor.isIdentifierPresent(
id)) {
385 for (
auto [firstElement, lastElement] :
ranges) {
386 for (; firstElement != lastElement; ++firstElement) {
388 if (prd_to_track_map_cptr !=
nullptr and
isUsed(sp, *prd_to_track_map_cptr))
continue;
394 return StatusCode::SUCCESS;
404 double tx =
std::tan(beamSpotHandle->beamTilt(0));
405 double ty =
std::tan(beamSpotHandle->beamTilt(1));
407 double phi = std::atan2(ty,
tx);
408 double theta = std::acos(1. / std::sqrt(1. +
tx *
tx + ty * ty));
414 data.xbeam[0] =
static_cast<float>(cb.x());
415 data.xbeam[1] =
static_cast<float>(cosTheta * cosPhi * cosPhi + sinPhi * sinPhi);
416 data.xbeam[2] =
static_cast<float>(cosTheta * sinPhi * cosPhi - sinPhi * cosPhi);
417 data.xbeam[3] = -
static_cast<float>(sinTheta * cosPhi);
419 data.ybeam[0] =
static_cast<float>(cb.y());
420 data.ybeam[1] =
static_cast<float>(cosTheta * cosPhi * sinPhi - sinPhi * cosPhi);
421 data.ybeam[2] =
static_cast<float>(cosTheta * sinPhi * sinPhi + cosPhi * cosPhi);
422 data.ybeam[3] = -
static_cast<float>(sinTheta * sinPhi);
424 data.zbeam[0] =
static_cast<float>(cb.z());
425 data.zbeam[1] =
static_cast<float>(sinTheta * cosPhi);
426 data.zbeam[2] =
static_cast<float>(sinTheta * sinPhi);
427 data.zbeam[3] =
static_cast<float>(cosTheta);
433 if ( not readHandle.isValid() ) {
434 throw std::runtime_error(
"Error while retrieving Atlas Field Cache Cond DB");
437 if (fieldCondObj ==
nullptr) {
443 Acts::MagneticFieldContext magFieldContext(fieldCondObj);
452 Acts::MagneticFieldProvider::Cache magFieldCache = magneticField.
makeCache( magFieldContext );
453 Acts::Vector3 bField = *magneticField.
getField( beamPos,
456 data.bField[0] = bField[0];
457 data.bField[1] = bField[1];
458 data.bField[2] = bField[2];
460 data.K = 2. * s_toTesla / (300. * bField[2]);
472 const std::vector<IdentifierHash>& vPixel,
473 const std::vector<IdentifierHash>& vStrip)
const
480 data.i_ITkSpacePointForSeed =
data.l_ITkSpacePointForSeed.begin();
481 data.v_ActsSpacePointForSeed.clear();
484 data.i_ITkSeed =
data.i_ITkSeeds.begin();
495 if ( not prd_handle.
isValid() ) {
498 prd_to_track_map_cptr = prd_handle.
get();
500 if (prd_to_track_map_cptr !=
nullptr) {
516 data.initialized =
true;
527 data.iteration = iteration;
534 data.i_ITkSpacePointForSeed =
data.l_ITkSpacePointForSeed.begin();
535 data.v_ActsSpacePointForSeed.clear();
540 data.i_ITkSeed =
data.i_ITkSeeds.begin();
554 if (
data.iteration == 0)
566 if ( not prd_handle.
isValid() ) {
569 prd_to_track_map_cptr = prd_handle.
get();
576 if (isPixel and not
retrievePixel(ctx,
data, prd_to_track_map_cptr).isSuccess() ) {
590 data.initialized =
true;
596 const std::list<Trk::Vertex>& )
const
599 if (
data.v_ActsSpacePointForSeed.empty() )
606 std::vector<ITk::SiSpacePointForSeed*> sp_storage;
609 std::unique_ptr< ActsTrk::SeedContainer > seedPtrs = std::make_unique< ActsTrk::SeedContainer >();
611 std::string combinationType = isPixel ?
"PPP" :
"SSS";
612 ATH_MSG_DEBUG(
"Running Seed Finding (" << combinationType <<
") ...");
619 Acts::Vector3 bField(
data.bField[0],
data.bField[1],
data.bField[2] );
624 Acts::SpacePointContainerConfig spConfig;
625 spConfig.useDetailedDoubleMeasurementInfo = not isPixel;
627 Acts::SpacePointContainerOptions spOptions;
628 spOptions.beamPos = Acts::Vector2(beamPos.x(), beamPos.y());
649 if (
sc == StatusCode::FAILURE) {
650 ATH_MSG_ERROR(
"Error during seed production (" << combinationType <<
")");
675 data.i_ITkSeed =
data.i_ITkSeeds.begin();
686 if (
data.i_ITkSeed ==
data.i_ITkSeeds.end())
690 }
while (!(*
data.i_ITkSeed++).set3(
data.seedOutput, 1./(1000. *
data.K)));
693 return &
data.seedOutput;
705 std::lock_guard<std::mutex> lock(
m_mutex);
707 if(track !=
nullptr) {
708 m_trackPt = (track->trackParameters()->front()->pT())/1000.
f;
709 m_trackEta = std::abs(track->trackParameters()->front()->eta());
716 m_z0 = seed->zVertex();
731 m_dzdr_b = seed->dzdr_b();
732 m_dzdr_t = seed->dzdr_t();
734 m_givesTrack = !(track ==
nullptr);
748 MsgStream&
out)
const
762 std::string
s2,
s3,
s4, s5;
777 out<<
"|---------------------------------------------------------------------|"
793 out<<
"| useStripOverlap | "
796 out<<
"|---------------------------------------------------------------------|"
798 out<<
"| Beam X center | "
799 <<std::setw(12)<<std::setprecision(5)<<
data.xbeam[0]
801 out<<
"| Beam Y center | "
802 <<std::setw(12)<<std::setprecision(5)<<
data.ybeam[0]
804 out<<
"| Beam Z center | "
805 <<std::setw(12)<<std::setprecision(5)<<
data.zbeam[0]
807 out<<
"| Beam X-axis direction | "
808 <<std::setw(12)<<std::setprecision(5)<<
data.xbeam[1]
809 <<std::setw(12)<<std::setprecision(5)<<
data.xbeam[2]
810 <<std::setw(12)<<std::setprecision(5)<<
data.xbeam[3]
812 out<<
"| Beam Y-axis direction | "
813 <<std::setw(12)<<std::setprecision(5)<<
data.ybeam[1]
814 <<std::setw(12)<<std::setprecision(5)<<
data.ybeam[2]
815 <<std::setw(12)<<std::setprecision(5)<<
data.ybeam[3]
817 out<<
"| Beam Z-axis direction | "
818 <<std::setw(12)<<std::setprecision(5)<<
data.zbeam[1]
819 <<std::setw(12)<<std::setprecision(5)<<
data.zbeam[2]
820 <<std::setw(12)<<std::setprecision(5)<<
data.zbeam[3]
822 out<<
"|---------------------------------------------------------------------|"
835 out<<
"|---------------------------------------------------------------------|"
838 <<std::setw(12)<<
data.ns
841 <<std::setw(12)<<
data.nsaz
844 <<std::setw(12)<<
data.nsazv
846 out<<
"|---------------------------------------------------------------------|"
864 data.v_StripSpacePointForSeed.clear();
867 std::array<const Trk::SpacePoint*, 3>
spacePoints {};
868 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()
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};
998 std::array<std::size_t, 3> indexes {
999 seed->sp()[0]->index(),
1000 seed->sp()[1]->index(),
1001 seed->sp()[2]->index()
1004 const auto [bottom_idx, medium_idx, top_idx] = indexes;
1005 std::size_t max_index =
std::max(bottom_idx,
std::max(medium_idx, top_idx));
1006 if (
data.v_PixelSpacePointForSeed.size() < max_index + 1) {
1007 data.v_PixelSpacePointForSeed.resize( max_index + 1 );
1027 *linkAcc(*seed->sp()[0]),
1028 *linkAcc(*seed->sp()[1]),
1029 *linkAcc(*seed->sp()[2])
1038 if (not pixelLinkAcc.
isAvailable(*bottom_cluster)) {
1039 ATH_MSG_FATAL(
"no pixelClusterLink for cluster associated to bottom sp!");
1042 if (not pixelLinkAcc.
isAvailable(*medium_cluster)) {
1043 ATH_MSG_FATAL(
"no pixelClusterLink for cluster associated to middle sp!");
1047 ATH_MSG_FATAL(
"no pixelClusterLink for cluster associated to top sp!");
1051 if (not
data.v_PixelSpacePointForSeed[bottom_idx])
1052 data.v_PixelSpacePointForSeed[bottom_idx] = std::make_unique<InDet::PixelSpacePoint>(bottom_cluster->
identifierHash(), *(pixelLinkAcc(*bottom_cluster)));
1053 if (not
data.v_PixelSpacePointForSeed[medium_idx])
1054 data.v_PixelSpacePointForSeed[medium_idx] = std::make_unique<InDet::PixelSpacePoint>(medium_cluster->
identifierHash(), *(pixelLinkAcc(*medium_cluster)));
1055 if (not
data.v_PixelSpacePointForSeed[top_idx])
1056 data.v_PixelSpacePointForSeed[top_idx] = std::make_unique<InDet::PixelSpacePoint>(top_cluster->
identifierHash(), *(pixelLinkAcc(*top_cluster)));
1059 data.v_PixelSpacePointForSeed[bottom_idx].get(),
1060 data.v_PixelSpacePointForSeed[medium_idx].get(),
1061 data.v_PixelSpacePointForSeed[top_idx].get()
1067 std::size_t sp_idx = indexes[
index];
1072 auto [itr, outcome] = bridge_idx_sispacepoints.try_emplace(sp_idx,
data.v_PixelSiSpacePointForSeed.size());
1073 std::size_t mapped_idx = itr->second;
1077 r[0] = seed->sp()[
index]->x();
1078 r[1] = seed->sp()[
index]->y();
1079 r[2] = seed->sp()[
index]->z();
1084 data.v_PixelSiSpacePointForSeed[mapped_idx].setQuality(-seed->seedQuality());
1085 pixelSpacePointsForSeeds[
index] = &
data.v_PixelSiSpacePointForSeed[mapped_idx];
1088 data.i_ITkSeeds.emplace_back(pixelSpacePointsForSeeds[0],
1089 pixelSpacePointsForSeeds[1],
1090 pixelSpacePointsForSeeds[2],
1092 data.i_ITkSeeds.back().setQuality(-seed->seedQuality());