Skip to content

Commit

Permalink
Reintroduced number of hits per subdetectors
Browse files Browse the repository at this point in the history
  • Loading branch information
pandreetto committed Jul 12, 2024
1 parent ef7df42 commit 38e37d4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 84 deletions.
9 changes: 4 additions & 5 deletions ACTSTracking/Helpers.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,14 @@ EVENT::Track* ACTS2Marlin_track(
std::shared_ptr<Acts::MagneticFieldProvider> magneticField,
Acts::MagneticFieldProvider::Cache& magCache);
*/
EVENT::Track* ACTS2Marlin_track(
const TrackResult& fitter_res,
std::shared_ptr<Acts::MagneticFieldProvider> magneticField,
Acts::MagneticFieldProvider::Cache& magCache);

EVENT::Track* ACTS2Marlin_track(
const TrackResult& fitter_res,
std::shared_ptr<Acts::MagneticFieldProvider> magneticField,
Acts::MagneticFieldProvider::Cache& magCache, double caloFaceR, double caloFaceZ, Acts::GeometryContext geoContext, Acts::MagneticFieldContext magFieldContext, std::shared_ptr<const Acts::TrackingGeometry> trackingGeo);
Acts::MagneticFieldProvider::Cache& magCache,
double caloFaceR, double caloFaceZ, Acts::GeometryContext geoContext,
Acts::MagneticFieldContext magFieldContext,
std::shared_ptr<const Acts::TrackingGeometry> trackingGeo);

//! Convert ACTS track state class to Marlin class
/**
Expand Down
98 changes: 19 additions & 79 deletions src/Helpers.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -241,81 +241,6 @@ EVENT::Track* ACTS2Marlin_track(
*/

EVENT::Track* ACTS2Marlin_track(
const TrackResult& fitter_res,
std::shared_ptr<Acts::MagneticFieldProvider> magneticField,
Acts::MagneticFieldProvider::Cache& magCache)
{
IMPL::TrackImpl* track = new IMPL::TrackImpl;

track->setChi2(fitter_res.chi2());
track->setNdf(fitter_res.nDoF());
track->setNholes(fitter_res.nHoles());

const Acts::Vector3 zeroPos(0, 0, 0);
Acts::Result<Acts::Vector3> fieldRes = magneticField->getField(zeroPos, magCache);
if (!fieldRes.ok()) {
throw std::runtime_error("Field lookup error: " + fieldRes.error().value());
}
Acts::Vector3 field = *fieldRes;

const Acts::BoundVector& params = fitter_res.parameters();
const Acts::BoundMatrix& covariance = fitter_res.covariance();
EVENT::TrackState* trackStateAtIP = ACTSTracking::ACTS2Marlin_trackState(
EVENT::TrackState::AtIP, params, covariance, field[2] / Acts::UnitConstants::T);
track->trackStates().push_back(trackStateAtIP);

EVENT::TrackerHitVec hitsOnTrack;
EVENT::TrackStateVec statesOnTrack;

for (const auto& trk_state : fitter_res.trackStatesReversed())
{
if (!trk_state.hasUncalibratedSourceLink()) continue;

auto sl = trk_state.getUncalibratedSourceLink()
.get<ACTSTracking::SourceLink>();
EVENT::TrackerHit* curr_hit = sl.lciohit();
hitsOnTrack.push_back(curr_hit);

const Acts::Vector3 hitPos(curr_hit->getPosition()[0],
curr_hit->getPosition()[1],
curr_hit->getPosition()[2]);

Acts::Result<Acts::Vector3> fieldRes =
magneticField->getField(hitPos, magCache);
if (!fieldRes.ok()) {
throw std::runtime_error("Field lookup error: " +
fieldRes.error().value());
}
Acts::Vector3 field = *fieldRes;

EVENT::TrackState* trackState = ACTSTracking::ACTS2Marlin_trackState(
EVENT::TrackState::AtOther, trk_state.smoothed(),
trk_state.smoothedCovariance(), field[2] / Acts::UnitConstants::T);
statesOnTrack.push_back(trackState);
}

std::reverse(hitsOnTrack.begin(), hitsOnTrack.end());
std::reverse(statesOnTrack.begin(), statesOnTrack.end());

for (EVENT::TrackerHit* hit : hitsOnTrack) {
track->addHit(hit);
}

if (statesOnTrack.size() > 0) {
dynamic_cast<IMPL::TrackStateImpl*>(statesOnTrack.back())
->setLocation(EVENT::TrackState::AtLastHit);
dynamic_cast<IMPL::TrackStateImpl*>(statesOnTrack.front())
->setLocation(EVENT::TrackState::AtFirstHit);
}

EVENT::TrackStateVec& myTrackStates = track->trackStates();
myTrackStates.insert(myTrackStates.end(), statesOnTrack.begin(),
statesOnTrack.end());

return track;
}

// Conversion with extrapolation to calorimeter face
EVENT::Track* ACTS2Marlin_track(
const TrackResult& fitter_res,
Expand All @@ -328,6 +253,7 @@ EVENT::Track* ACTS2Marlin_track(

track->setChi2(fitter_res.chi2());
track->setNdf(fitter_res.nDoF());
track->setNholes(fitter_res.nHoles());

const Acts::Vector3 zeroPos(0, 0, 0);
Acts::Result<Acts::Vector3> fieldRes = magneticField->getField(zeroPos, magCache);
Expand Down Expand Up @@ -393,7 +319,8 @@ EVENT::Track* ACTS2Marlin_track(
double time = params[Acts::eBoundTime];

Acts::Vector3 pos(d0 * cos(phi), d0 * sin(phi), z0);
Acts::CurvilinearTrackParameters start(Acts::VectorHelpers::makeVector4(pos, time), phi, theta, qoverp, covariance, Acts::ParticleHypothesis::pion());
Acts::CurvilinearTrackParameters start(Acts::VectorHelpers::makeVector4(pos, time), phi, theta,
qoverp, covariance, Acts::ParticleHypothesis::pion());

// Set propagator options
Acts::PropagatorOptions myCaloPropOptions(geoContext, magFieldContext);
Expand All @@ -416,7 +343,8 @@ EVENT::Track* ACTS2Marlin_track(
const Acts::BoundMatrix& atCaloCovariance = *(end_parameters->covariance());

EVENT::TrackState* trackStateAtCalo = ACTSTracking::ACTS2Marlin_trackState(
EVENT::TrackState::AtCalorimeter, end_parameters->parameters(), atCaloCovariance, field[2] / Acts::UnitConstants::T);
EVENT::TrackState::AtCalorimeter, end_parameters->parameters(),
atCaloCovariance, field[2] / Acts::UnitConstants::T);
track->trackStates().push_back(trackStateAtCalo);
}
else {
Expand All @@ -427,7 +355,8 @@ EVENT::Track* ACTS2Marlin_track(
const Acts::BoundMatrix& atCaloCovariance = *(end_parametersP->covariance());

EVENT::TrackState* trackStateAtCalo = ACTSTracking::ACTS2Marlin_trackState(
EVENT::TrackState::AtCalorimeter, end_parametersP->parameters(), atCaloCovariance, field[2] / Acts::UnitConstants::T);
EVENT::TrackState::AtCalorimeter, end_parametersP->parameters(),
atCaloCovariance, field[2] / Acts::UnitConstants::T);
track->trackStates().push_back(trackStateAtCalo);
}
else{
Expand All @@ -441,7 +370,8 @@ EVENT::Track* ACTS2Marlin_track(
const Acts::BoundMatrix& atCaloCovariance = *(end_parametersM->covariance());

EVENT::TrackState* trackStateAtCalo = ACTSTracking::ACTS2Marlin_trackState(
EVENT::TrackState::AtCalorimeter, end_parametersM->parameters(), atCaloCovariance, field[2] / Acts::UnitConstants::T);
EVENT::TrackState::AtCalorimeter, end_parametersM->parameters(),
atCaloCovariance, field[2] / Acts::UnitConstants::T);
track->trackStates().push_back(trackStateAtCalo);
}
else{
Expand All @@ -453,8 +383,18 @@ EVENT::Track* ACTS2Marlin_track(
std::reverse(hitsOnTrack.begin(), hitsOnTrack.end());
std::reverse(statesOnTrack.begin(), statesOnTrack.end());

UTIL::CellIDDecoder<lcio::TrackerHit> decoder(
lcio::LCTrackerCellID::encoding_string());
EVENT::IntVec& subdetectorHitNumbers = track->subdetectorHitNumbers();
subdetectorHitNumbers.resize(7, 0);
for (EVENT::TrackerHit* hit : hitsOnTrack) {
track->addHit(hit);

uint32_t sysid = decoder(hit)["system"];
if (subdetectorHitNumbers.size() <= sysid) {
subdetectorHitNumbers.resize(sysid + 1, 0);
}
subdetectorHitNumbers[sysid]++;
}

if (statesOnTrack.size() > 0) {
Expand Down

0 comments on commit 38e37d4

Please sign in to comment.