Skip to content

Commit

Permalink
Merge pull request key4hep#2 from delitez/propagatorAlg
Browse files Browse the repository at this point in the history
Fixing format
  • Loading branch information
delitez authored Aug 4, 2022
2 parents 33d4213 + 0dc4b08 commit 818434c
Show file tree
Hide file tree
Showing 8 changed files with 402 additions and 555 deletions.
53 changes: 0 additions & 53 deletions PropagatorAlgSvc.py

This file was deleted.

2 changes: 0 additions & 2 deletions k4ActsTracking/src/components/GeoSvc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ StatusCode GeoSvc::buildDD4HepGeo() {

/// Create a geometry OBJ file
StatusCode GeoSvc::createGeoObj() {


Acts::ObjVisualization3D m_obj;

if (!m_trackingGeo) {
Expand Down
8 changes: 4 additions & 4 deletions k4ActsTracking/src/components/GeoSvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class GeoSvc : public extends<Service, IGeoSvc> {
Acts::GeometryContext m_trackingGeoCtx;

/// ACTS Tracking Geometry
// std::unique_ptr<const Acts::TrackingGeometry> m_trackingGeo{nullptr};
// std::unique_ptr<const Acts::TrackingGeometry> m_trackingGeo{nullptr};
std::shared_ptr<const Acts::TrackingGeometry> m_trackingGeo{nullptr};

/// ACTS Material Decorator
Expand Down Expand Up @@ -73,9 +73,9 @@ class GeoSvc : public extends<Service, IGeoSvc> {

StatusCode createGeoObj();

// virtual const Acts::TrackingGeometry& trackingGeometry() const;
// virtual std::shared_ptr<const Acts::TrackingGeometry> m_trackingGeo{nullptr};
virtual std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry() const;
// virtual const Acts::TrackingGeometry& trackingGeometry() const;
// virtual std::shared_ptr<const Acts::TrackingGeometry> m_trackingGeo{nullptr};
virtual std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry() const;
};

//inline const Acts::TrackingGeometry& GeoSvc::trackingGeometry() const { return *m_trackingGeo; }
Expand Down
1 change: 0 additions & 1 deletion k4ActsTracking/src/components/IPropagatorAlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <unordered_map>

class GAUDI_API IPropagatorAlg : virtual public IService {

public:
DeclareInterfaceID(IPropagatorAlg, 1, 0);

Expand Down
308 changes: 132 additions & 176 deletions k4ActsTracking/src/components/PropagationOptions.hpp

Large diffs are not rendered by default.

159 changes: 65 additions & 94 deletions k4ActsTracking/src/components/PropagatorAlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@
#include "TGeoManager.h"
#include "TTree.h"


DECLARE_COMPONENT(PropagatorAlg)



using namespace Acts;



std::optional<Acts::BoundSymMatrix> PropagatorAlg::generateCovariance(std::mt19937& rng,
std::normal_distribution<double>& gauss) {
if (covarianceTransport) {

Acts::BoundSymMatrix newCov(m_cfg.correlations);

Acts::BoundVector covs_smeared = m_cfg.covariances;
Expand All @@ -44,43 +38,34 @@ PropagatorAlg::PropagatorAlg(const std::string& aName, ISvcLocator* aSvcLoc) : G
PropagatorAlg::~PropagatorAlg() {}

StatusCode PropagatorAlg::initialize() {

m_geoSvc = service("GeoSvc");


if (!m_geoSvc) {
std::cout << "Unable to locate Geometry Service. " << std::endl;
return StatusCode::FAILURE;

}
std::cout << "Unable to locate Geometry Service. " << std::endl;
return StatusCode::FAILURE;
}

if (service("THistSvc", m_ths).isFailure()) {
if (service("THistSvc", m_ths).isFailure()) {
error() << "Couldn't get THistSvc" << endmsg;
return StatusCode::FAILURE;
}

m_outputTree = new TTree ("hits", "PropagatorAlg hits ntuple");
if (m_ths->regTree("/rec/NtuplesHits", m_outputTree).isFailure()) {
m_outputTree = new TTree("hits", "PropagatorAlg hits ntuple");
if (m_ths->regTree("/rec/NtuplesHits", m_outputTree).isFailure()) {
error() << "Couldn't register hits tree" << endmsg;
}
initializeTrees();


return StatusCode::SUCCESS;
initializeTrees();

return StatusCode::SUCCESS;
}




StatusCode PropagatorAlg::execute() {

cleanTrees();
std::mt19937 rng{1};
std::normal_distribution<double> gauss(0., 1.);
std::round(gauss(rng));

std::uniform_real_distribution<double> phiDist(0 , 2*M_PI);
std::uniform_real_distribution<double> phiDist(0, 2 * M_PI);
std::uniform_real_distribution<double> etaDist(-4.0, 4.0);
std::uniform_real_distribution<double> ptDist(10., 20.);
std::uniform_real_distribution<double> qDist(0., 1.);
Expand All @@ -95,10 +80,9 @@ StatusCode PropagatorAlg::execute() {
if (recordMaterialInteractions) {
recordedMaterial.reserve(ntests);
}
for (size_t i = 0; i < 42; i++) {
testVar.push_back(i);
}

for (size_t i = 0; i < 42; i++) {
testVar.push_back(i);
}

// loop over number of particles
for (size_t it = 0; it < ntests; ++it) {
Expand All @@ -118,7 +102,6 @@ testVar.push_back(i);
Acts::BoundVector pars;
pars << d0, z0, phi, theta, qop, t;


Acts::Vector3 sPosition(0., 0., 0.);
Acts::Vector3 sMomentum(0., 0., 0.);

Expand All @@ -127,9 +110,8 @@ testVar.push_back(i);

auto tGeometry = m_geoSvc->trackingGeometry();

auto bField = std::make_shared<ConstantBField>(Vector3(0.,0.,2 * Acts::UnitConstants::T));
Acts::BoundTrackParameters startParameters(surface, std::move(pars),
std::move(cov));
auto bField = std::make_shared<ConstantBField>(Vector3(0., 0., 2 * Acts::UnitConstants::T));
Acts::BoundTrackParameters startParameters(surface, std::move(pars), std::move(cov));

auto stepper = Acts::EigenStepper<>{std::move(bField)};
using Stepper = std::decay_t<decltype(stepper)>;
Expand All @@ -138,42 +120,37 @@ testVar.push_back(i);
Acts::Navigator navigator(navCfg);
Propagator propagator(std::move(stepper), std::move(navigator));


PropagationOutput pOut;

pOut = executeTest(propagator, startParameters);



for (auto& step : pOut.first) {

Acts::GeometryIdentifier::Value volumeID = 0;
Acts::GeometryIdentifier::Value boundaryID = 0;
Acts::GeometryIdentifier::Value layerID = 0;
Acts::GeometryIdentifier::Value approachID = 0;
for (auto& step : pOut.first) {
Acts::GeometryIdentifier::Value volumeID = 0;
Acts::GeometryIdentifier::Value boundaryID = 0;
Acts::GeometryIdentifier::Value layerID = 0;
Acts::GeometryIdentifier::Value approachID = 0;
Acts::GeometryIdentifier::Value sensitiveID = 0;

if (step.surface) {
auto geoID = step.surface->geometryId();
volumeID = geoID.volume();
boundaryID = geoID.boundary();
layerID = geoID.layer();
approachID = geoID.approach();
auto geoID = step.surface->geometryId();
volumeID = geoID.volume();
boundaryID = geoID.boundary();
layerID = geoID.layer();
approachID = geoID.approach();
sensitiveID = geoID.sensitive();
}

if(sensitiveID >= sensitiveIDopt) {

// a current volume overwrites the surface tagged one
if (step.volume != nullptr) {
volumeID = step.volume->geometryId().volume();
}
// now fill
m_sensitiveID.push_back(sensitiveID);
m_approachID.push_back(approachID);
m_layerID.push_back(layerID);
m_boundaryID.push_back(boundaryID);
m_volumeID.push_back(volumeID);
if (sensitiveID >= sensitiveIDopt) {
// a current volume overwrites the surface tagged one
if (step.volume != nullptr) {
volumeID = step.volume->geometryId().volume();
}
// now fill
m_sensitiveID.push_back(sensitiveID);
m_approachID.push_back(approachID);
m_layerID.push_back(layerID);
m_boundaryID.push_back(boundaryID);
m_volumeID.push_back(volumeID);

m_x.push_back(step.position.x());
m_y.push_back(step.position.y());
Expand All @@ -182,51 +159,45 @@ testVar.push_back(i);
m_dx.push_back(direction.x());
m_dy.push_back(direction.y());
m_dz.push_back(direction.z());

}

}
m_outputTree->Fill();
}



return StatusCode::SUCCESS;
}
m_outputTree->Fill();
}

return StatusCode::SUCCESS;
}

StatusCode PropagatorAlg::finalize() { return StatusCode::SUCCESS; }

StatusCode PropagatorAlg::initializeTrees(){

m_outputTree->Branch("testVar", &testVar);
m_outputTree->Branch("g_x", &m_x);
m_outputTree->Branch("g_y", &m_y);
m_outputTree->Branch("g_z", &m_z);
m_outputTree->Branch("d_x", &m_dx);
m_outputTree->Branch("d_y", &m_dy);
m_outputTree->Branch("d_z", &m_dz);
m_outputTree->Branch("volume_id", &m_volumeID);
m_outputTree->Branch("boundary_id", &m_boundaryID);
m_outputTree->Branch("layer_id", &m_layerID);
m_outputTree->Branch("approach_id", &m_approachID);
m_outputTree->Branch("sensitive_id", &m_sensitiveID);
return StatusCode::SUCCESS;
StatusCode PropagatorAlg::initializeTrees() {
m_outputTree->Branch("testVar", &testVar);
m_outputTree->Branch("g_x", &m_x);
m_outputTree->Branch("g_y", &m_y);
m_outputTree->Branch("g_z", &m_z);
m_outputTree->Branch("d_x", &m_dx);
m_outputTree->Branch("d_y", &m_dy);
m_outputTree->Branch("d_z", &m_dz);
m_outputTree->Branch("volume_id", &m_volumeID);
m_outputTree->Branch("boundary_id", &m_boundaryID);
m_outputTree->Branch("layer_id", &m_layerID);
m_outputTree->Branch("approach_id", &m_approachID);
m_outputTree->Branch("sensitive_id", &m_sensitiveID);
return StatusCode::SUCCESS;
}

StatusCode PropagatorAlg::cleanTrees() {
testVar.clear();
m_x.clear();
m_y.clear();
m_z.clear();
m_dx.clear();
m_dy.clear();
m_dz.clear();
m_volumeID.clear();
m_boundaryID.clear();
m_layerID.clear();
m_approachID.clear();
m_sensitiveID.clear();
testVar.clear();
m_x.clear();
m_y.clear();
m_z.clear();
m_dx.clear();
m_dy.clear();
m_dz.clear();
m_volumeID.clear();
m_boundaryID.clear();
m_layerID.clear();
m_approachID.clear();
m_sensitiveID.clear();

return StatusCode::SUCCESS;
}
Loading

0 comments on commit 818434c

Please sign in to comment.