14 #include "HepPDT/ParticleDataTable.hh"
24 #include "EventInfo/EventInfo.h"
26 #include "GaudiKernel/ITHistSvc.h"
32 const int& eta_module_cl2,
const int& phi_module_cl2){
35 if( (eta_module_cl1==eta_module_cl2) && (phi_module_cl1==phi_module_cl2) ){
38 else if((eta_module_cl1!=eta_module_cl2) && (phi_module_cl1==phi_module_cl2) ){
41 else if((eta_module_cl1==eta_module_cl2) && (phi_module_cl1!=phi_module_cl2) ){
53 :
AthAlgorithm(
name, pSvcLocator), m_pixelID(nullptr), m_SCT_ID(nullptr), m_pixelManager(nullptr),
54 m_SCT_Manager(nullptr), m_event(0), m_selected(0), m_particlePropSvc(
"PartPropSvc",
name),
55 m_particleDataTable(0), m_offset(0) {
92 return StatusCode::FAILURE;
95 if (!
detStore()->contains<InDetDD::PixelDetectorManager>(
"Pixel") ||
98 if (!
detStore()->contains<InDetDD::PixelDetectorManager>(
"ITkPixel") ||
100 return StatusCode::FAILURE;
106 return StatusCode::FAILURE;
109 if (!
detStore()->contains<InDetDD::SCT_DetectorManager>(
"SCT") ||
112 if (!
detStore()->contains<InDetDD::SCT_DetectorManager>(
"ITkStrip") ||
114 return StatusCode::FAILURE;
121 return StatusCode::FAILURE;
127 ATH_MSG_ERROR(
"Could not get ParticleDataTable! Cannot associate pdg code with charge. Aborting. ");
128 return StatusCode::FAILURE;
135 if (
sc.isFailure()) {
142 sc = tHistSvc->regTree(fullNtupleName,
m_nt);
143 if (
sc.isFailure()) {
144 ATH_MSG_ERROR(
"Unable to register TTree: " << fullNtupleName);
166 m_CLphis =
new std::vector<std::vector<int>>;
167 m_CLetas =
new std::vector<std::vector<int>>;
168 m_CLtots =
new std::vector<std::vector<int>>;
254 m_nt->Branch(
"CLx",
m_CLx,
"CLx[nCL]/D");
255 m_nt->Branch(
"CLy",
m_CLy,
"CLy[nCL]/D");
256 m_nt->Branch(
"CLz",
m_CLz,
"CLz[nCL]/D");
314 m_nt->Branch(
"SPx",
m_SPx,
"SPx[nSP]/D");
315 m_nt->Branch(
"SPy",
m_SPy,
"SPy[nSP]/D");
316 m_nt->Branch(
"SPz",
m_SPz,
"SPz[nSP]/D");
351 return StatusCode::SUCCESS;
358 const EventContext &ctx = Gaudi::Hive::currentContext();
364 std::map<Identifier, long int> clusterIDMapIdx;
367 std::map<Identifier, long int> clusterIDMapSpacePointIdx;
371 std::map<std::pair<int, int>, std::pair<bool, int>> allTruthParticles;
375 if (not mcEventCollectionHandle.isValid()) {
377 return StatusCode::FAILURE;
379 mcCollptr = mcEventCollectionHandle.cptr();
384 if (not eventInfoHandle.
isValid()) {
386 return StatusCode::FAILURE;
388 eventInfo = eventInfoHandle.
cptr();
393 std::map<int, int> allSubEvents;
397 bool duplicateSubeventID =
false;
398 for (
unsigned int cntr = 0; cntr < mcCollptr->
size(); ++cntr) {
399 int ID = mcCollptr->
at(cntr)->event_number();
408 if (
it == allSubEvents.end())
409 allSubEvents.insert(std::make_pair(
ID, 1));
412 duplicateSubeventID =
true;
416 if (duplicateSubeventID) {
423 (*m_Part_vParentID).clear();
424 (*m_Part_vParentBarcode).clear();
427 for (
unsigned int cntr = 0; cntr < mcCollptr->
size(); ++cntr) {
428 const HepMC::GenEvent *genEvt = (mcCollptr->
at(cntr));
437 for (
auto p : *genEvt) {
439 float px,
py,
pz,
pt,
eta, vx, vy, vz,
radius,
status,
charge = 0.;
440 std::vector<int> vParentID;
441 std::vector<int> vParentBarcode;
443 int vProdNin, vProdNout, vProdStatus, vProdBarcode;
444 bool passed =
isPassed(
p,
px,
py,
pz,
pt,
eta, vx, vy, vz,
radius,
status,
charge, vParentID, vParentBarcode,
445 vProdNin, vProdNout, vProdStatus, vProdBarcode);
446 allTruthParticles.insert(std::make_pair(std::make_pair(genEvt->event_number(),
HepMC::barcode(
p)),
447 std::make_pair(
passed, 0)));
469 (*m_Part_vParentID).push_back(vParentID);
470 (*m_Part_vParentBarcode).push_back(vParentBarcode);
483 if (not pixelClusterContainerHandle.isValid()) {
485 return StatusCode::FAILURE;
491 if (not stripClusterContainerHandle.isValid()) {
493 return StatusCode::FAILURE;
497 auto cartesion_to_spherical = [](
const Amg::Vector3D &xyzVec,
float &eta_,
float &phi_) {
500 r3 += xyzVec[
idx] * xyzVec[
idx];
503 phi_ = atan2(xyzVec[1], xyzVec[0]);
504 float theta_ = acos(xyzVec[2] / r3);
505 eta_ =
log(
tan(0.5 * theta_));
514 (*m_CLhardware).clear();
515 (*m_CLparticleLink_eventIndex).clear();
516 (*m_CLparticleLink_barcode).clear();
517 (*m_CLbarcodesLinked).clear();
518 (*m_CLparticle_charge).clear();
522 (*m_CLlocal_cov).clear();
529 if (not sdoCollectionHandle.isValid()) {
531 return StatusCode::FAILURE;
533 sdoCollection = sdoCollectionHandle.cptr();
537 if (clusterCollection->empty())
548 float norm_x = fabs(my_normal.x()) > 1
e-5 ? my_normal.x() : 0.;
549 float norm_y = fabs(my_normal.y()) > 1
e-5 ? my_normal.y() : 0.;
550 float norm_z = fabs(my_normal.z()) > 1
e-5 ? my_normal.z() : 0.;
555 ATH_MSG_ERROR(
"Dynamic cast failed at " << __LINE__ <<
" of MergedPixelsTool.cxx.");
556 return StatusCode::FAILURE;
560 for (
const auto &cluster : *clusterCollection) {
566 const Amg::MatrixX &local_cov = cluster->localCovariance();
568 std::vector<std::pair<int, int>>
barcodes = {};
569 std::vector<int> particleLink_eventIndex = {};
570 std::vector<int> particleLink_barcode = {};
571 std::vector<bool> barcodesLinked = {};
572 std::vector<float>
charge = {};
573 std::vector<int> phis = {};
574 std::vector<int>
etas = {};
575 std::vector<int> tots = {};
581 float charge_count = 0;
584 for (
unsigned int rdo = 0; rdo < cluster->rdoList().
size(); rdo++) {
585 const auto &rdoID = cluster->rdoList().at(rdo);
598 charge_count += cluster->totList().at(rdo);
602 tots.push_back(cluster->totList().at(rdo));
604 auto pos = sdoCollection->find(rdoID);
605 if (
pos != sdoCollection->end()) {
606 for (
auto deposit :
pos->second.getdeposits()) {
612 particleLink_eventIndex.push_back(particleLink.
eventIndex());
613 particleLink_barcode.push_back(particleLink.
barcode());
614 charge.push_back(deposit.second);
615 barcodesLinked.push_back(particleLink.
isValid());
632 Amg::Vector3D localDirection = localEndPosition - localStartPosition;
634 float loc_eta = 0, loc_phi = 0;
635 cartesion_to_spherical(localDirection, loc_eta, loc_phi);
640 Amg::Vector3D direction = globalEndPosition - globalStartPosition;
641 float glob_eta = 0, glob_phi = 0;
642 cartesion_to_spherical(direction, glob_eta, glob_phi);
647 float trkphicomp = direction.dot(my_phiax);
648 float trketacomp = direction.dot(my_etaax);
649 float trknormcomp = direction.dot(my_normal);
650 double phi_angle = atan2(trknormcomp, trkphicomp);
651 double eta_angle = atan2(trknormcomp, trketacomp);
653 clusterIDMapIdx[cluster->identify()] =
m_selected;
654 std::vector<double> v_local_cov;
655 if (local_cov.size() > 0) {
656 for (
size_t i = 0, nRows = local_cov.rows(), nCols = local_cov.cols();
i < nRows;
i++) {
657 for (
size_t j = 0; j < nCols; ++j) {
658 v_local_cov.push_back(local_cov(
i, j));
665 (*m_CLhardware).push_back(
"PIXEL");
675 (*m_CLparticleLink_eventIndex).push_back(particleLink_eventIndex);
676 (*m_CLparticleLink_barcode).push_back(particleLink_barcode);
677 (*m_CLbarcodesLinked).push_back(barcodesLinked);
678 (*m_CLparticle_charge).push_back(
charge);
679 (*m_CLetas).push_back(
etas);
680 (*m_CLphis).push_back(phis);
681 (*m_CLtots).push_back(tots);
699 (*m_CLlocal_cov).push_back(v_local_cov);
718 if (not sdoCollectionHandle.isValid()) {
720 return StatusCode::FAILURE;
722 sdoCollection = sdoCollectionHandle.cptr();
726 if (clusterCollection->empty())
738 float norm_x = fabs(my_normal.x()) > 1
e-5 ? my_normal.x() : 0.;
739 float norm_y = fabs(my_normal.y()) > 1
e-5 ? my_normal.y() : 0.;
740 float norm_z = fabs(my_normal.z()) > 1
e-5 ? my_normal.z() : 0.;
743 for (
const auto &cluster : *clusterCollection) {
749 const Amg::MatrixX &local_cov = cluster->localCovariance();
751 std::vector<std::pair<int, int>>
barcodes = {};
752 std::vector<int> particleLink_eventIndex = {};
753 std::vector<int> particleLink_barcode = {};
754 std::vector<bool> barcodesLinked = {};
755 std::vector<float>
charge = {};
757 std::vector<int> tots = {};
758 std::vector<int> strip_ids = {};
760 int max_strip = -999;
762 float charge_count = 0;
765 for (
unsigned int rdo = 0; rdo < cluster->rdoList().
size(); rdo++) {
766 const auto &rdoID = cluster->rdoList().at(rdo);
770 if (min_strip > strip)
772 if (max_strip < strip)
774 strip_ids.push_back(strip);
779 auto pos = sdoCollection->find(rdoID);
780 if (
pos != sdoCollection->end()) {
781 for (
auto deposit :
pos->second.getdeposits()) {
788 particleLink_eventIndex.push_back(particleLink.
eventIndex());
789 particleLink_barcode.push_back(particleLink.
barcode());
790 charge.push_back(deposit.second);
791 barcodesLinked.push_back(particleLink.
isValid());
801 ATH_MSG_ERROR(
"Failed at " << __LINE__ <<
" of accessing SCT ModuleSide Design");
802 return StatusCode::FAILURE;
806 std::pair<Amg::Vector3D, Amg::Vector3D> ends(
820 Amg::Vector3D localDirection = localEndPosition - localStartPosition;
821 float loc_eta = 0, loc_phi = 0;
822 cartesion_to_spherical(localDirection, loc_eta, loc_phi);
827 Amg::Vector3D direction = globalEndPosition - globalStartPosition;
828 float glob_eta = 0, glob_phi = 0;
829 cartesion_to_spherical(direction, glob_eta, glob_phi);
834 float trkphicomp = direction.dot(my_phiax);
835 float trketacomp = direction.dot(my_etaax);
836 float trknormcomp = direction.dot(my_normal);
837 double phi_angle = atan2(trknormcomp, trkphicomp);
838 double eta_angle = atan2(trknormcomp, trketacomp);
841 clusterIDMapIdx[cluster->identify()] =
m_selected;
843 std::vector<int> cst;
844 for (
unsigned strip = 0; strip < strip_ids.size(); strip++) {
847 std::vector<double> v_local_cov;
848 if (local_cov.size() > 0) {
849 for (
size_t i = 0, nRows = local_cov.rows(), nCols = local_cov.cols();
i < nRows;
i++) {
850 for (
size_t j = 0; j < nCols; ++j) {
851 v_local_cov.push_back(local_cov(
i, j));
857 (*m_CLhardware).push_back(
"STRIP");
867 (*m_CLparticleLink_eventIndex).push_back(particleLink_eventIndex);
868 (*m_CLparticleLink_barcode).push_back(particleLink_barcode);
869 (*m_CLbarcodesLinked).push_back(barcodesLinked);
870 (*m_CLparticle_charge).push_back(
charge);
871 (*m_CLetas).push_back(strip_ids);
872 (*m_CLphis).push_back(cst);
873 (*m_CLtots).push_back(tots);
891 (*m_CLlocal_cov).push_back(v_local_cov);
911 if (not pixelSpacePointContainerHandle.isValid()) {
913 return StatusCode::FAILURE;
915 PixelSpacePointContainer = pixelSpacePointContainerHandle.cptr();
919 if (not stripSpacePointContainerHandle.isValid()) {
921 return StatusCode::FAILURE;
923 SCT_SpacePointContainer = stripSpacePointContainerHandle.cptr();
927 if (not overlapSpacePointCollectionHandle.isValid()) {
929 return StatusCode::FAILURE;
931 OverlapSpacePointCollection = overlapSpacePointCollectionHandle.cptr();
937 if (PixelSpacePointContainer && PixelSpacePointContainer->
size() > 0) {
938 for (
const auto &spCollection : *PixelSpacePointContainer) {
940 if (spCollection->empty())
944 for (
const auto &sp : *spCollection) {
967 if (SCT_SpacePointContainer && SCT_SpacePointContainer->
size() > 0) {
968 for (
const auto &spCollection : *SCT_SpacePointContainer) {
970 if (spCollection->empty())
974 for (
const auto &sp : *spCollection) {
999 for (
const auto &sp : *OverlapSpacePointCollection) {
1012 if(flag<1 || flag > 2){
1032 if (not trackCollectionHandle.isValid()) {
1034 return StatusCode::FAILURE;
1036 trackCollection = trackCollectionHandle.cptr();
1040 if (not trackTruthCollectionHandle.isValid()) {
1042 return StatusCode::FAILURE;
1044 trackTruthCollection = trackTruthCollectionHandle.cptr();
1052 (*m_TRKproperties).clear();
1053 (*m_TRKpattern).clear();
1054 (*m_TRKperigee_position).clear();
1055 (*m_TRKperigee_momentum).clear();
1056 (*m_TRKmeasurementsOnTrack_pixcl_sctcl_index).clear();
1057 (*m_TRKoutliersOnTrack_pixcl_sctcl_index).clear();
1060 for (; trackIterator < (*trackCollection).end(); ++trackIterator) {
1061 if (!((*trackIterator))) {
1075 TrackTruthCollection::const_iterator
found = trackTruthCollection->find(tracklink2);
1077 const std::bitset<Trk::TrackInfo::NumberOfTrackProperties> &
properties =
info.properties();
1078 std::vector<int> v_properties;
1081 v_properties.push_back(
i);
1085 const std::bitset<Trk::TrackInfo::NumberOfTrackRecoInfo> &
pattern =
info.patternRecognition();
1086 std::vector<int> v_pattern;
1087 for (std::size_t
i = 0;
i <
pattern.size();
i++) {
1089 v_pattern.push_back(
i);
1099 std::vector<double> position,
momentum;
1110 position.push_back(0);
1111 position.push_back(0);
1112 position.push_back(0);
1119 if (measurementsOnTrack)
1120 mot = measurementsOnTrack->
size();
1121 if (outliersOnTrack)
1122 oot = outliersOnTrack->
size();
1123 std::vector<int> measurementsOnTrack_pixcl_sctcl_index, outliersOnTrack_pixcl_sctcl_index;
1124 int TTCindex, TTCevent_index, TTCparticle_link;
1125 float TTCprobability;
1126 if (measurementsOnTrack) {
1127 for (
size_t i = 0;
i < measurementsOnTrack->
size();
i++) {
1132 measurementsOnTrack_pixcl_sctcl_index.push_back(clusterIDMapIdx[pixcl->
prepRawData()->
identify()]);
1135 measurementsOnTrack_pixcl_sctcl_index.push_back(clusterIDMapIdx[sctcl->
prepRawData()->
identify()]);
1137 measurementsOnTrack_pixcl_sctcl_index.push_back(-1);
1141 if (outliersOnTrack) {
1142 for (
size_t i = 0;
i < outliersOnTrack->
size();
i++) {
1147 outliersOnTrack_pixcl_sctcl_index.push_back(clusterIDMapIdx[pixcl->
prepRawData()->
identify()]);
1149 outliersOnTrack_pixcl_sctcl_index.push_back(clusterIDMapIdx[sctcl->
prepRawData()->
identify()]);
1151 outliersOnTrack_pixcl_sctcl_index.push_back(-1);
1155 if (
found != trackTruthCollection->end()) {
1156 TTCindex =
found->first.index();
1157 TTCevent_index =
found->second.particleLink().eventIndex();
1158 TTCparticle_link =
found->second.particleLink().barcode();
1159 TTCprobability =
found->second.probability();
1161 TTCindex = TTCevent_index = TTCparticle_link = -999;
1162 TTCprobability = -1;
1170 (*m_TRKproperties).push_back(v_properties);
1171 (*m_TRKpattern).push_back(v_pattern);
1174 (*m_TRKmeasurementsOnTrack_pixcl_sctcl_index).push_back(measurementsOnTrack_pixcl_sctcl_index);
1175 (*m_TRKoutliersOnTrack_pixcl_sctcl_index).push_back(outliersOnTrack_pixcl_sctcl_index);
1177 (*m_TRKperigee_position).push_back(position);
1178 (*m_TRKperigee_momentum).push_back(
momentum);
1198 if (not detailedTrackTruthCollectionHandle.isValid()) {
1200 return StatusCode::FAILURE;
1202 detailedTrackTruthCollection = detailedTrackTruthCollectionHandle.cptr();
1206 (*m_DTTtrajectory_eventindex).clear();
1207 (*m_DTTtrajectory_barcode).clear();
1208 (*m_DTTstTruth_subDetType).clear();
1209 (*m_DTTstTrack_subDetType).clear();
1210 (*m_DTTstCommon_subDetType).clear();
1214 DetailedTrackTruthCollection::const_iterator detailedTrackTruthIterator = (*detailedTrackTruthCollection).begin();
1215 for (; detailedTrackTruthIterator != (*detailedTrackTruthCollection).end(); ++detailedTrackTruthIterator) {
1216 std::vector<int> DTTtrajectory_eventindex, DTTtrajectory_barcode, DTTstTruth_subDetType, DTTstTrack_subDetType,
1217 DTTstCommon_subDetType;
1218 const TruthTrajectory &traj = detailedTrackTruthIterator->second.trajectory();
1219 for (
size_t j = 0; j < traj.size(); j++) {
1220 DTTtrajectory_eventindex.push_back(traj[j].
eventIndex());
1221 DTTtrajectory_barcode.push_back(traj[j].
barcode());
1239 (*m_DTTtrajectory_eventindex).push_back(DTTtrajectory_eventindex);
1240 (*m_DTTtrajectory_barcode).push_back(DTTtrajectory_barcode);
1241 (*m_DTTstTruth_subDetType).push_back(DTTstTruth_subDetType);
1242 (*m_DTTstTrack_subDetType).push_back(DTTstTrack_subDetType);
1243 (*m_DTTstCommon_subDetType).push_back(DTTstCommon_subDetType);
1254 return StatusCode::SUCCESS;
1359 return StatusCode::SUCCESS;
1364 float &
pt,
float &
eta,
float &vx,
float &vy,
float &vz,
float &
radius,
float &
status,
1365 float &
charge, std::vector<int> &vParentID, std::vector<int> &vParentBarcode,
1366 int &vProdNin,
int &vProdNout,
int &vProdStatus,
int &vProdBarcode) {
1378 int absPdgCode = std::abs(pdgCode);
1385 charge *= (pdgCode > 0.) ? 1. : -1.;
1389 if (
particle->production_vertex()) {
1390 vx =
particle->production_vertex()->position().x();
1391 vy =
particle->production_vertex()->position().y();
1392 vz =
particle->production_vertex()->position().z();
1401 if (
particle->production_vertex()) {
1402 vProdNin =
particle->production_vertex()->particles_in_size();
1403 vProdNout =
particle->production_vertex()->particles_out_size();
1404 vProdStatus =
particle->production_vertex()->id();
1407 for (
const auto &
p :
particle->production_vertex()->particles_in()) {
1408 vParentID.push_back(
p->pdg_id());
1412 for (
auto ip =
particle->production_vertex()->particles_in_const_begin();
1413 ip !=
particle->production_vertex()->particles_in_const_end();
1416 vParentID.push_back((*ip)->pdg_id());
1436 if (not passBarcode)
1439 bool passCharge = not(
charge == 0.);
1443 bool passStatus = (
status == 1);
1448 if (not passProdRadius)