Newer
Older
// converted_writer.write_row(converted_header);
for (int ielem = 0; ielem < nelem; ++ielem)
{
auto hit = hitSITCol->at(ielem);
auto simhit = SimhitSITCol->at(ielem);
auto simcellid = simhit.getCellID();
// <id>system:5,side:-2,layer:9,stave:8,module:8,sensor:5,y:-11,z:-11</id>
uint64_t m_layer = sit_decoder->get(simcellid, "layer");
uint64_t m_stave = sit_decoder->get(simcellid, "stave");
uint64_t m_module = sit_decoder->get(simcellid, "module");
uint64_t m_sensor = sit_decoder->get(simcellid, "sensor");
double acts_x = simhit.getPosition()[0];
double acts_y = simhit.getPosition()[1];
double acts_z = simhit.getPosition()[2];
double momentum_x = simhit.getMomentum()[0];
double momentum_y = simhit.getMomentum()[1];
double momentum_z = simhit.getMomentum()[2];
const Acts::Vector3 globalmom{momentum_x, momentum_y, momentum_z};
std::array<float, 6> m_covMatrix = hit.getCovMatrix();
dd4hep::rec::ISurface* surface = nullptr;
auto it = m_sit_surfaces->find(simcellid);
if (it != m_sit_surfaces->end()) {
surface = it->second;
if (!surface) {
fatal() << "found surface for SIT cell id " << simcellid << ", but NULL" << endmsg;
return 0;
}
}
else {
fatal() << "not found surface for SIT cell id " << simcellid << endmsg;
return 0;
}
// set acts geometry identifier
uint64_t acts_volume = SIT_volume_ids[m_layer];
uint64_t acts_boundary = 0;
uint64_t acts_layer = 2;
uint64_t acts_approach = 0;
uint64_t acts_sensitive = m_stave*SIT_module_nums[m_layer] + m_module + 1;
Acts::GeometryIdentifier moduleGeoId;
moduleGeoId.setVolume(acts_volume);
moduleGeoId.setBoundary(acts_boundary);
moduleGeoId.setLayer(acts_layer);
moduleGeoId.setApproach(acts_approach);
moduleGeoId.setSensitive(acts_sensitive);
// create and store the source link
uint32_t measurementIdx = measurements.size();
IndexSourceLink sourceLink{moduleGeoId, measurementIdx, hit};
sourceLinks.insert(sourceLinks.end(), sourceLink);
Acts::SourceLink sl{sourceLink};
boost::container::static_vector<Acts::SourceLink, 2> slinks;
slinks.emplace_back(sl);
// get the local position of the hit
IndexSourceLink::SurfaceAccessor surfaceAccessor{*trackingGeometry};
const Acts::Surface* acts_surface = surfaceAccessor(sl);
const Acts::Vector3 globalPos{acts_x, acts_y, acts_z};
auto acts_local_postion = acts_surface->globalToLocal(geoContext, globalPos, globalmom, onSurfaceTolerance);
if (!acts_local_postion.ok()){
info() << "Error: failed to get local position for SIT hit " << simcellid << endmsg;
acts_local_postion = acts_surface->globalToLocal(geoContext, globalPos, globalmom, 100*onSurfaceTolerance);
}
const std::array<Acts::BoundIndices, 2> indices{Acts::BoundIndices::eBoundLoc0, Acts::BoundIndices::eBoundLoc1};
const Acts::Vector2 par{acts_local_postion.value()[0], acts_local_postion.value()[1]};
// *** debug ***
debug() << "SIT measurements global position(x,y,z): " << simhit.getPosition()[0] << ", " << simhit.getPosition()[1] << ", " << simhit.getPosition()[2]
<< "; local position(loc0, loc1): "<< acts_local_postion.value()[0] << ", " << acts_local_postion.value()[1] << endmsg;
auto acts_global_postion = acts_surface->localToGlobal(geoContext, par, globalFakeMom);
debug() << "debug surface at: x:" << acts_global_postion[0] << ", y:" << acts_global_postion[1] << ", z:" << acts_global_postion[2] << endmsg;
if (ExtendSeedRange.value()) {
SimSpacePoint *hitExt = new SimSpacePoint(hit, acts_global_postion[0], acts_global_postion[1], acts_global_postion[2], 0.002, slinks);
SpacePointPtrs.push_back(hitExt);
}
// create and store the measurement
Acts::ActsSquareMatrix<2> cov = Acts::ActsSquareMatrix<2>::Identity();
cov(0, 0) = std::max<double>(double(m_covMatrix[2]), eps.value());
cov(1, 1) = std::max<double>(double(m_covMatrix[5]), eps.value());
measurements.emplace_back(Acts::Measurement<Acts::BoundIndices, 2>(sl, indices, par, cov));
// std::vector<std::string> truth_col = {std::to_string(m_layer), std::to_string(simhit.getPosition()[0]), std::to_string(simhit.getPosition()[1]), std::to_string(simhit.getPosition()[2])};
// truth_writer.write_row(truth_col);
// std::vector<std::string> converted_col = {std::to_string(m_layer), std::to_string(acts_global_postion[0]), std::to_string(acts_global_postion[1]), std::to_string(acts_global_postion[2])};
// converted_writer.write_row(converted_col);
}
} else { success = 0; }
return success;
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
}
int RecActsTracking::InitialiseFTD()
{
const edm4hep::TrackerHitCollection* hitFTDCol = nullptr;
const edm4hep::SimTrackerHitCollection* SimhitFTDCol = nullptr;
try {
hitFTDCol = _inFTDTrackHdl.get();
} catch (GaudiException& e) {
debug() << "Collection " << _inFTDTrackHdl.fullKey() << " is unavailable in event " << _nEvt << endmsg;
return 0;
}
try {
SimhitFTDCol = _inFTDColHdl.get();
} catch (GaudiException& e) {
debug() << "Collection " << _inFTDColHdl.fullKey() << " is unavailable in event " << _nEvt << endmsg;
return 0;
}
if (hitFTDCol && SimhitFTDCol)
{
int nelem = hitFTDCol->size();
debug() << "Number of FTD hits = " << nelem << endmsg;
for (int ielem = 0; ielem < nelem; ++ielem)
{
auto hit = hitFTDCol->at(ielem);
auto simhit = SimhitFTDCol->at(ielem);
auto simcellid = simhit.getCellID();
uint64_t m_system = ftd_decoder->get(simcellid, "system");
uint64_t m_side = ftd_decoder->get(simcellid, "side");
uint64_t m_layer = ftd_decoder->get(simcellid, "layer");
uint64_t m_module = ftd_decoder->get(simcellid, "module");
uint64_t m_sensor = ftd_decoder->get(simcellid, "sensor");
double acts_x = simhit.getPosition()[0];
double acts_y = simhit.getPosition()[1];
double acts_z = simhit.getPosition()[2];
double momentum_x = simhit.getMomentum()[0];
double momentum_y = simhit.getMomentum()[1];
double momentum_z = simhit.getMomentum()[2];
const Acts::Vector3 globalmom{momentum_x, momentum_y, momentum_z};
std::array<float, 6> m_covMatrix = hit.getCovMatrix();
if (m_layer > 2) {
continue;
}
dd4hep::rec::ISurface* surface = nullptr;
auto it = m_ftd_surfaces->find(simcellid);
if (it != m_ftd_surfaces->end()) {
surface = it->second;
if (!surface) {
fatal() << "found surface for FTD cell id " << simcellid << ", but NULL" << endmsg;
return 0;
}
}
// set acts geometry identifier
uint64_t acts_volume = (acts_z > 0) ? FTD_positive_volume_ids[m_layer] : FTD_negative_volume_ids[m_layer];
uint64_t acts_boundary = 0;
uint64_t acts_layer = 2;
uint64_t acts_approach = 0;
uint64_t acts_sensitive = m_module + 1;
Acts::GeometryIdentifier moduleGeoId;
moduleGeoId.setVolume(acts_volume);
moduleGeoId.setBoundary(acts_boundary);
moduleGeoId.setLayer(acts_layer);
moduleGeoId.setApproach(acts_approach);
moduleGeoId.setSensitive(acts_sensitive);
// create and store the source link
uint32_t measurementIdx = measurements.size();
IndexSourceLink sourceLink{moduleGeoId, measurementIdx, hit};
sourceLinks.insert(sourceLinks.end(), sourceLink);
Acts::SourceLink sl{sourceLink};
boost::container::static_vector<Acts::SourceLink, 2> slinks;
slinks.emplace_back(sl);
// get the local position of the hit
IndexSourceLink::SurfaceAccessor surfaceAccessor{*trackingGeometry};
const Acts::Surface* acts_surface = surfaceAccessor(sl);
const Acts::Vector3 globalPos{acts_x, acts_y, acts_z};
auto acts_local_postion = acts_surface->globalToLocal(geoContext, globalPos, globalmom, onSurfaceTolerance);
if (!acts_local_postion.ok()){
info() << "Error: failed to get local position for FTD layer " << m_layer << " module " << m_module << " sensor " << m_sensor << endmsg;
acts_local_postion = acts_surface->globalToLocal(geoContext, globalPos, globalmom, 100*onSurfaceTolerance);
}
const std::array<Acts::BoundIndices, 2> indices{Acts::BoundIndices::eBoundLoc0, Acts::BoundIndices::eBoundLoc1};
const Acts::Vector2 par{acts_local_postion.value()[0], acts_local_postion.value()[1]};
// debug
debug() << "FTD measurements global position(x,y,z): " << simhit.getPosition()[0] << ", " << simhit.getPosition()[1] << ", " << simhit.getPosition()[2]
<< "; local position(loc0, loc1): "<< acts_local_postion.value()[0] << ", " << acts_local_postion.value()[1] << endmsg;
auto acts_global_postion = acts_surface->localToGlobal(geoContext, par, globalFakeMom);
debug() << "debug surface at: x:" << acts_global_postion[0] << ", y:" << acts_global_postion[1] << ", z:" << acts_global_postion[2] << endmsg;
if (ExtendSeedRange.value()) {
SimSpacePoint *hitExt = new SimSpacePoint(hit, acts_global_postion[0], acts_global_postion[1], acts_global_postion[2], 0.002, slinks);
SpacePointPtrs.push_back(hitExt);
}
// create and store the measurement
Acts::ActsSquareMatrix<2> cov = Acts::ActsSquareMatrix<2>::Identity();
cov(0, 0) = std::max<double>(double(m_covMatrix[2]), eps.value());
cov(1, 1) = std::max<double>(double(m_covMatrix[5]), eps.value());
measurements.emplace_back(Acts::Measurement<Acts::BoundIndices, 2>(sl, indices, par, cov));
}
}
return 1;