diff --git a/empty_alg.py b/empty_alg.py index d2399a0..f6d2532 100644 --- a/empty_alg.py +++ b/empty_alg.py @@ -6,6 +6,9 @@ from Configurables import objectTestFind from Configurables import objectTest from Configurables import ParticleGunAlg +from Configurables import GeoSvc +from Configurables import RandomNumberSvc +from Configurables import EventCounter # # algList = [] # @@ -33,12 +36,21 @@ a.nMultiplicity = 5; a.nParticles = 10; #a.objectPath = "/Event/MyParticle4" -algList.append(a) +#algList.append(a) + +b = RandomNumberSvc("MyRndNbrSvc") + + d=EmptyAlg("MyEmptyAlg") -algList.append(d) +#algList.append(d) + +c = GeoSvc("GeoSvc") +c.detectors = ["/home/delitez/ACTS/acts/thirdparty/OpenDataDetector/xml/OpenDataDetector.xml"] +c.debugGeometry = True +c.outputFileName = "MyObjFileTESTparticleGun" from Configurables import ApplicationMgr #print("CRASH TEST") -ApplicationMgr(TopAlg=algList, EvtSel="NONE", EvtMax=5, ExtSvc=[], OutputLevel=DEBUG) +ApplicationMgr(TopAlg=algList, EvtSel="NONE", EvtMax=1, ExtSvc=[b], OutputLevel=DEBUG) diff --git a/eventgen.py b/eventgen.py index a2e6b70..173366f 100644 --- a/eventgen.py +++ b/eventgen.py @@ -17,9 +17,11 @@ a.nMultiplicity = 5; a.nParticles = 10; algList.append(a) - +from Configurables import EmptyAlg +d=EmptyAlg("MyEmptyAlg") +algList.append(d) from Configurables import ApplicationMgr -ApplicationMgr(TopAlg=algList, EvtSel="NONE", EvtMax=2, ExtSvc=[], OutputLevel=DEBUG) +ApplicationMgr(TopAlg=algList, EvtSel="NONE", EvtMax=1, ExtSvc=[], OutputLevel=DEBUG) diff --git a/k4ActsTracking/CMakeLists.txt b/k4ActsTracking/CMakeLists.txt index 16def43..7824b02 100644 --- a/k4ActsTracking/CMakeLists.txt +++ b/k4ActsTracking/CMakeLists.txt @@ -10,6 +10,7 @@ gaudi_add_module(k4ActsTrackingPlugins ActsDD4hep::ActsDD4hep Boost::program_options ROOT::Core + ActsFatras ) set(GAUDI_GENCONF_DIR "genConfDir") diff --git a/k4ActsTracking/src/components/EmptyAlg.cpp b/k4ActsTracking/src/components/EmptyAlg.cpp index 16c434a..96c67d9 100644 --- a/k4ActsTracking/src/components/EmptyAlg.cpp +++ b/k4ActsTracking/src/components/EmptyAlg.cpp @@ -10,6 +10,9 @@ StatusCode EmptyAlg::initialize() { return StatusCode::SUCCESS; } StatusCode EmptyAlg::execute() { std::cout << "HALLO WELT!" << std::endl; + const SimParticleContainer* p_partvect = p_partvec.get(); + + std::cout << "HADE WELT!" << std::endl; return StatusCode::SUCCESS; } diff --git a/k4ActsTracking/src/components/EmptyAlg.h b/k4ActsTracking/src/components/EmptyAlg.h index e33e143..e3250d3 100644 --- a/k4ActsTracking/src/components/EmptyAlg.h +++ b/k4ActsTracking/src/components/EmptyAlg.h @@ -3,6 +3,8 @@ // GAUDI #include "Gaudi/Property.h" #include "GaudiAlg/GaudiAlgorithm.h" +#include "ParticleGunAlg.h" + class EmptyAlg : public GaudiAlgorithm { public: @@ -24,4 +26,7 @@ class EmptyAlg : public GaudiAlgorithm { private: // member variable int m_member = 0; + DataObjectHandle> p_partvec{"/Event/testVec", Gaudi::DataHandle::Reader, this}; + + }; diff --git a/k4ActsTracking/src/components/GeoSvc.cpp b/k4ActsTracking/src/components/GeoSvc.cpp index f3bcb59..4864256 100644 --- a/k4ActsTracking/src/components/GeoSvc.cpp +++ b/k4ActsTracking/src/components/GeoSvc.cpp @@ -13,6 +13,7 @@ #include "DD4hep/Printout.h" #include "GaudiKernel/Service.h" #include "TGeoManager.h" +#include "RandomNumberSvc.h" using namespace Gaudi; diff --git a/k4ActsTracking/src/components/GeoSvc.h b/k4ActsTracking/src/components/GeoSvc.h index 18057f0..378d0aa 100644 --- a/k4ActsTracking/src/components/GeoSvc.h +++ b/k4ActsTracking/src/components/GeoSvc.h @@ -38,9 +38,9 @@ class GeoSvc : public extends { Acts::GeometryContext m_trackingGeoCtx; /// ACTS Tracking Geometry - // std::unique_ptr m_trackingGeo{nullptr}; std::shared_ptr m_trackingGeo{nullptr}; + /// ACTS Material Decorator std::shared_ptr m_materialDeco{nullptr}; @@ -73,12 +73,12 @@ class GeoSvc : public extends { StatusCode createGeoObj(); - // virtual const Acts::TrackingGeometry& trackingGeometry() const; - // virtual std::shared_ptr m_trackingGeo{nullptr}; virtual std::shared_ptr trackingGeometry() const; + + }; -//inline const Acts::TrackingGeometry& GeoSvc::trackingGeometry() const { return *m_trackingGeo; } inline std::shared_ptr GeoSvc::trackingGeometry() const { return m_trackingGeo; } + #endif diff --git a/k4ActsTracking/src/components/IEventGeneratorSvc.h b/k4ActsTracking/src/components/IEventGeneratorSvc.h new file mode 100644 index 0000000..ce590f5 --- /dev/null +++ b/k4ActsTracking/src/components/IEventGeneratorSvc.h @@ -0,0 +1,21 @@ +// D. Elitez, July 2022 +// Based on eic/juggler + +#ifndef IEVENTGENERATORSVC_H +#define IEVENTGENERATORSVC_H + +#include + + + +class GAUDI_API IEventGeneratorSvc : virtual public IService { +public: + + +public: + DeclareInterfaceID(IEventGeneratorSvc, 1, 0); + + virtual ~IEventGeneratorSvc() {} +}; + +#endif // IGEOSVC_H diff --git a/k4ActsTracking/src/components/IRandomNumberSvc.h b/k4ActsTracking/src/components/IRandomNumberSvc.h new file mode 100644 index 0000000..58ac2e4 --- /dev/null +++ b/k4ActsTracking/src/components/IRandomNumberSvc.h @@ -0,0 +1,21 @@ +// D. Elitez, August 2022 + + +#ifndef IRANDOMNUMBERSVC_H +#define IRANDOMNUMBERSVC_H + +#include +#include + + +class GAUDI_API IRandomNumberSvc : virtual public IService { +public: + + +public: + DeclareInterfaceID(IRandomNumberSvc, 1, 0); + virtual uint64_t getSeed() = 0; + virtual ~IRandomNumberSvc() {} +}; + +#endif diff --git a/k4ActsTracking/src/components/ParticleGunAlg.cpp b/k4ActsTracking/src/components/ParticleGunAlg.cpp index 4b6499a..fff44e1 100644 --- a/k4ActsTracking/src/components/ParticleGunAlg.cpp +++ b/k4ActsTracking/src/components/ParticleGunAlg.cpp @@ -16,7 +16,7 @@ StatusCode ParticleGunAlg::initialize() { } StatusCode ParticleGunAlg::execute() { - SimParticleContainer particles{}; + static int seed = 5; std::mt19937 rng{seed++}; @@ -32,65 +32,50 @@ StatusCode ParticleGunAlg::execute() { // Solution: set stuff per hand as rand gauss // auto vertexPosition = (*vertex)(rng); - - std::normal_distribution gauss2(0., 1.); -Acts::Vector4 vertexPosition(0., 0., 0., 0.); - // double vpx = sqrt(gauss2(rng)*gauss2(rng)); - // double vpy = sqrt(gauss2(rng)*gauss2(rng)); - // Acts::Vector4 vertexPosition(1., 5., 0., 0.); - // std::cout << "vertex position vpx and vpy: " << vpx << " and " << vpy << std::endl; - // - // -std::cout << "line 44"<< std::endl; - - auto updateParticleInPlace = [&](ActsFatras::Particle& particle) { - - const auto pid = ActsFatras::Barcode(particle.particleId()) - .setVertexPrimary(nPrimaryVertices); - std::cout << "line 50"<< std::endl; - const auto pos4 = (vertexPosition + particle.fourPosition()).eval(); - std::cout << "line 52"<< std::endl; - particle = particle.withParticleId(pid).setPosition4(pos4); - std::cout << "line 54"<< std::endl; - }; - std::cout << "line56" << std::endl; + auto vertexPosition = Acts::Vector4(1.,1.,1.,1.); auto vertexParticles = genVertexParticles(rng,gauss); - for (auto& vertexParticle : vertexParticles) { - updateParticleInPlace(vertexParticle); - } - std::cout << "line 61"<< std::endl; - particles.merge(std::move(vertexParticles)); - std::cout << "line 63"<< std::endl; - } - - - // Container *containedParticle = new Container(); - // containedParticle->m_particles = particles; - - -// This registiration must be revised because path is given in the python code and it crashes when it is not changed each time ---- TODO: Find a better way -// Question: Should particles registered individually or all together --- if all together, then the ParticleGunAlg must run only once and it is okay as it is now. -// Remark: Same name is okay if no compile, if compile, same name causes a crash - -// find a way that objectPath doesnt have to be changed all the time! --- it must work over many events - // StatusCode sc = eventSvc()->registerObject(objectPath, containedParticle); - // - // if( sc.isFailure() ) { - // std::cout << "Object cannot be registered." << std::endl; - // return StatusCode::FAILURE; - // } - // else{ - // std::cout << "Object is registered in " << objectPath << std::endl; - // } - - std::cout << "BEFORE PUT WELT!" << std::endl; -m_partvec.put(std::move(particles)); - std::cout << "AFTER PUT WELT!" << std::endl; +Acts::PdgParticle pdg = Acts::PdgParticle::eMuon; + + auto updateParticleInPlace = [&](ActsFatras::Particle& particle) { // aus truth level zu vertexpos + // std::cout << "particle before update: " << particle << std::endl; + // std::cout << "particle 4 position before update: " << particle.fourPosition() << std::endl; + // std::cout << "nPrimaryVertices: " << nPrimaryVertices << std::endl; + // const auto pid = ActsFatras::Barcode(particle.particleId()).setVertexPrimary(nPrimaryVertices); + const auto pid = ActsFatras::Barcode(0u).setParticle(nPrimaryVertices); + // std::cout << "Define pid " << std::endl; + // std::cout << "vertexPosition: " << vertexPosition << std::endl; + // std::cout << "particle four position: " << particle.fourPosition() << std::endl; + // std::cout << "pos4 evaluation: " << (vertexPosition + particle.fourPosition()).eval() << std::endl; + // + // const auto pos4 = (vertexPosition + particle.fourPosition()).eval(); + // std::cout << "Define pos4 " << std::endl; + // particle = particle.withParticleId(pid).setPosition4(pos4); + particle.setParticleId(pid); + particle.setPosition4(1.,1.,1.,1.); + // std::cout << "particle after update: " << particle << std::endl; + // std::cout << "particle 4 position after update: " << particle.fourPosition() << std::endl; + // std::cout << "nPrimaryVertices: " << nPrimaryVertices << std::endl; + + }; + + + + for (auto& vertexParticle : vertexParticles) { + updateParticleInPlace(vertexParticle); + } + particles.merge(std::move(vertexParticles)); + } + // std::cout << "BEFORE PUT WELT!" << std::endl; + m_partvec.put(std::move(particles)); + // std::cout << "AFTER PUT WELT!" << std::endl; + // + // + // @@ -107,6 +92,8 @@ StatusCode ParticleGunAlg::finalize() { SimParticleContainer ParticleGunAlg::genVertexParticles(std::mt19937& rng, std::normal_distribution& gauss) { + SimParticleContainer gen_particles; + using UniformIndex = std::uniform_int_distribution; @@ -127,8 +114,7 @@ SimParticleContainer ParticleGunAlg::genVertexParticles(std::mt19937& rng, std:: // braucht man 3 elements statt 2? const double qChoices[] = {charge,-charge, }; - SimParticleContainer particles; -std::cout << "line 130"<< std::endl; + for (size_t ip = 1 ; ip <= nParticles; ++ip) { const auto pid = ActsFatras::Barcode(0u).setParticle(ip); const unsigned int type = particleTypeChoice(rng); @@ -146,17 +132,17 @@ std::cout << "line 130"<< std::endl; direction[Acts::eMom2] = cos(theta); //TODO: Fix the mass -- how to extract it from pdg? config file? by hand? -std::cout << "line 148"<< std::endl; + double mass = 0.5; - ActsFatras::Particle particle(pid, pdg, q, mass); - particle.setDirection(direction); - particle.setAbsoluteMomentum(p); -std::cout << "line 155"<< std::endl; - particles.insert(particles.end(), std::move(particle)); -std::cout << "line 157"<< std::endl; + ActsFatras::Particle _particle(pid, pdg, q, mass); + _particle.setDirection(direction); + _particle.setAbsoluteMomentum(p); + + gen_particles.insert(gen_particles.end(), std::move(_particle)); + } -std::cout << "line 159"<< std::endl; -return particles; + +return gen_particles; }; diff --git a/k4ActsTracking/src/components/ParticleGunAlg.h b/k4ActsTracking/src/components/ParticleGunAlg.h index 9cb89e4..a66b53e 100644 --- a/k4ActsTracking/src/components/ParticleGunAlg.h +++ b/k4ActsTracking/src/components/ParticleGunAlg.h @@ -10,8 +10,7 @@ #include "GaudiAlg/GaudiAlgorithm.h" #include "GaudiKernel/DataObjectHandle.h" #include "GaudiKernel/AnyDataWrapper.h" -#include -#include "IEventGeneratorSvc.h" +#include "GaudiKernel/AnyDataHandle.h" #include "Acts/Definitions/Algebra.hpp" #include "ActsFatras/EventData/Particle.hpp" #include "ActsFatras/Utilities/ParticleData.hpp" @@ -51,25 +50,11 @@ class ParticleGunAlg : public GaudiAlgorithm { SimParticleContainer genVertexParticles(std::mt19937& rng, std::normal_distribution& gauss); - - struct MultiplicityGenerator { - virtual ~MultiplicityGenerator() = default; - virtual size_t operator()(std::mt19937& rng) const = 0; - }; - - struct VertexGenerator{ - virtual ~VertexGenerator() = default; - virtual Acts::Vector4 operator()(std::mt19937& rng) const = 0; - }; - - struct Container : public DataObject { - SimParticleContainer m_particles; - }; - +SimParticleContainer particles; private: -AnyDataHandle m_partvec{"/Event/TestVec3", Gaudi::DataHandle::Writer, this}; +DataObjectHandle> m_partvec{"/Event/testVec", Gaudi::DataHandle::Writer, this}; public: @@ -87,7 +72,7 @@ AnyDataHandle m_partvec{"/Event/TestVec3", Gaudi::DataHand Gaudi::Property objectPath{this, "objectPath", " ", "Path for the object."}; - std::shared_ptr vertex = nullptr; + // std::shared_ptr vertex = nullptr; ParticleGunAlg(const std::string& name, ISvcLocator* svc); diff --git a/k4ActsTracking/src/components/PropagatorAlg.cpp b/k4ActsTracking/src/components/PropagatorAlg.cpp index 86439bd..b140aa9 100644 --- a/k4ActsTracking/src/components/PropagatorAlg.cpp +++ b/k4ActsTracking/src/components/PropagatorAlg.cpp @@ -5,7 +5,7 @@ #include "GaudiKernel/Service.h" #include "TGeoManager.h" #include "TTree.h" - +#include "GaudiKernel/ServiceHandle.h" DECLARE_COMPONENT(PropagatorAlg) using namespace Acts; @@ -39,12 +39,21 @@ PropagatorAlg::~PropagatorAlg() {} StatusCode PropagatorAlg::initialize() { m_geoSvc = service("GeoSvc"); + m_rndSvc = service("RandomNumberSvc"); if (!m_geoSvc) { std::cout << "Unable to locate Geometry Service. " << std::endl; return StatusCode::FAILURE; } + if (!m_rndSvc) { + std::cout << "Unable to use Random Number Service. " << std::endl; + return StatusCode::FAILURE; + } + else { + std::cout << "Random Number Service is initilazied. " << std::endl; + } + if (service("THistSvc", m_ths).isFailure()) { error() << "Couldn't get THistSvc" << endmsg; return StatusCode::FAILURE; @@ -61,7 +70,12 @@ StatusCode PropagatorAlg::initialize() { StatusCode PropagatorAlg::execute() { cleanTrees(); - std::mt19937 rng{1}; + auto tSeed = m_rndSvc->getSeed(); + + std::cout << "tSeed: " << tSeed << std::endl; + +// static int seed = 5; + std::mt19937 rng{tSeed++}; std::normal_distribution gauss(0., 1.); std::round(gauss(rng)); @@ -84,30 +98,36 @@ StatusCode PropagatorAlg::execute() { testVar.push_back(i); } - // loop over number of particles - for (size_t it = 0; it < ntests; ++it) { - /// get the d0 and z0 - double d0 = d0Sigma * gauss(rng); - double z0 = z0Sigma * gauss(rng); - double phi = phiDist(rng); + const SimParticleContainer* p_partvect = p_partvec.get(); + + for (auto i = p_partvect->begin(); i < p_partvect->end(); i++) { + + double d0 = d0Sigma * gauss(rng); //TODO :: set from 4pos of the particle position + double z0 = z0Sigma * gauss(rng); /// parameter aus singleboundtrackparameters, see link from 10.8. + double phi = phiDist(rng); /// random numbers-randomnumbersvc? double eta = etaDist(rng); double theta = 2 * atan(exp(-eta)); - double pt = ptDist(rng); + double t = tSigma * gauss(rng); + + + double pt = i->transverseMomentum(); double p = pt / sin(theta); - double charge = qDist(rng) > 0.5 ? 1. : -1.; + double charge = i->charge(); double qop = charge / p; - double t = tSigma * gauss(rng); + // parameters Acts::BoundVector pars; pars << d0, z0, phi, theta, qop, t; + Acts::Vector3 sPosition(0., 0., 0.); Acts::Vector3 sMomentum(0., 0., 0.); // The covariance generation auto cov = generateCovariance(rng, gauss); + auto tGeometry = m_geoSvc->trackingGeometry(); auto bField = std::make_shared(Vector3(0., 0., 2 * Acts::UnitConstants::T)); @@ -162,7 +182,7 @@ StatusCode PropagatorAlg::execute() { } } m_outputTree->Fill(); - } + } ///// END OF FOR LOOP OVER NTESTS return StatusCode::SUCCESS; } diff --git a/k4ActsTracking/src/components/PropagatorAlg.h b/k4ActsTracking/src/components/PropagatorAlg.h index 1a406c0..ddf1944 100644 --- a/k4ActsTracking/src/components/PropagatorAlg.h +++ b/k4ActsTracking/src/components/PropagatorAlg.h @@ -12,6 +12,11 @@ #include "GaudiKernel/ServiceHandle.h" #include "IGeoSvc.h" #include "IPropagatorAlg.h" +#include "IRandomNumberSvc.h" +#include "ParticleGunAlg.h" +#include "RandomNumberSvc.h" +#include + #include "Acts/Definitions/Algebra.hpp" #include "Acts/Definitions/Units.hpp" @@ -100,10 +105,13 @@ class PropagatorAlg : public GaudiAlgorithm { private: Config m_cfg; + std::vector testvec; std::mt19937 rng; std::optional generateCovariance(std::mt19937& rng, std::normal_distribution& gauss); + + ITHistSvc* m_ths{nullptr}; TTree* m_outputTree{nullptr}; @@ -123,6 +131,8 @@ class PropagatorAlg : public GaudiAlgorithm { Config readPropagationConfig(const boost::program_options::variables_map& vm); + DataObjectHandle> p_partvec{"/Event/testVec", Gaudi::DataHandle::Reader, this}; + Gaudi::Property mode{this, "mode", 0, "Option for propagation mode."}; Gaudi::Property sterileLogger{this, "sterileLogger", false, "Option to switch the logger to sterile."}; @@ -215,6 +225,8 @@ class PropagatorAlg : public GaudiAlgorithm { public: SmartIF m_geoSvc; + SmartIF m_rndSvc; + explicit PropagatorAlg(const std::string&, ISvcLocator*); virtual ~PropagatorAlg(); diff --git a/k4ActsTracking/src/components/RandomNumberSvc.cpp b/k4ActsTracking/src/components/RandomNumberSvc.cpp new file mode 100644 index 0000000..42730ec --- /dev/null +++ b/k4ActsTracking/src/components/RandomNumberSvc.cpp @@ -0,0 +1,41 @@ +// D. Elitez, August 2022 + + +#include "RandomNumberSvc.h" +#include "GaudiKernel/Service.h" +#include "IRandomNumberSvc.h" + +using namespace Gaudi; + +DECLARE_COMPONENT(RandomNumberSvc) + +RandomNumberSvc::RandomNumberSvc(const std::string& name, ISvcLocator* svc) : base_class(name, svc), m_log(msgSvc(), name) {} + +RandomNumberSvc::~RandomNumberSvc() {} + +StatusCode RandomNumberSvc::initialize() { + + auto m_seedPtr = generateSeed(); + + return StatusCode::SUCCESS; +} + +StatusCode RandomNumberSvc::execute() { + + return StatusCode::SUCCESS; +} + +StatusCode RandomNumberSvc::finalize() { + + return StatusCode::SUCCESS; +} + +uint64_t RandomNumberSvc::generateSeed() { +uint64_t seed = 1234567890u; +const uint64_t k1 = algNum; +const uint64_t k2 = evNum; + +const uint64_t id = (k1+k2) * (k1+k2+1) / 2 + k2; +return seed + id; + +} diff --git a/k4ActsTracking/src/components/RandomNumberSvc.h b/k4ActsTracking/src/components/RandomNumberSvc.h new file mode 100644 index 0000000..dab95b3 --- /dev/null +++ b/k4ActsTracking/src/components/RandomNumberSvc.h @@ -0,0 +1,47 @@ +// D. Elitez, August 2022 + + +#ifndef RANDOMNUMBERSVC_H +#define RANDOMNUMBERSVC_H + +#include "IRandomNumberSvc.h" +#include "GaudiKernel/Service.h" +#include "GaudiKernel/ServiceHandle.h" +#include "GaudiKernel/EventIDBase.h" + + +#include + +using RandomEngine = std::mt19937; + +class RandomNumberSvc : public extends { +public: + + RandomNumberSvc(const std::string& name, ISvcLocator* svc); + + virtual ~RandomNumberSvc(); + + virtual StatusCode initialize() final; + + virtual StatusCode execute() final; + + virtual StatusCode finalize() final; + + virtual uint64_t getSeed(); + + uint64_t generateSeed(); + + +private: + + MsgStream m_log; + + uint64_t m_seedPtr; + + Gaudi::Property algNum{this, "algNum", 0, "Option for propagation mode."}; + + Gaudi::Property evNum{this, "evNum", 0, "Option for propagation mode."}; + +}; +inline uint64_t RandomNumberSvc::getSeed() { return m_seedPtr; } +#endif diff --git a/k4ActsTracking/src/components/objectTEST.cpp b/k4ActsTracking/src/components/objectTEST.cpp index de83e45..e1077d8 100644 --- a/k4ActsTracking/src/components/objectTEST.cpp +++ b/k4ActsTracking/src/components/objectTEST.cpp @@ -5,7 +5,8 @@ #include #include #include "PropagatorAlg.h" - +#include "GaudiKernel/ObjectVector.h" +#include "GaudiKernel/ContainedObject.h" //using std::filesystem::current_path; @@ -21,20 +22,18 @@ StatusCode objectTest::execute() { typedef std::vector MyTestVector; DataObject *pObject; - //std::string objectPath = "./testDir"; + MyTestVectorS *m_vector = new MyTestVectorS(); - StatusCode sc = eventSvc()->registerObject(".", pObject); - if( sc.isFailure() ) { - std::cout << "CANNOT initialize sc" << std::endl; - return StatusCode::FAILURE; - } - else{ - std::cout << "CAN initialize sc" << std::endl; - } - MyTestVector *tv = 0; - tv = dynamic_cast (pObject); + StatusCode sc = eventSvc()->registerObject("/Event/Test", m_vector); + if( sc.isFailure() ) { + std::cout << "CANNOT initialize sc" << std::endl; + return StatusCode::FAILURE; + } + else{ + std::cout << "CAN initialize sc" << std::endl; + } std::cout << "Object Test is alive!" << std::endl; diff --git a/k4ActsTracking/src/components/objectTEST.h b/k4ActsTracking/src/components/objectTEST.h index b913040..d6ea4de 100644 --- a/k4ActsTracking/src/components/objectTEST.h +++ b/k4ActsTracking/src/components/objectTEST.h @@ -4,7 +4,9 @@ #include "Gaudi/Property.h" #include "GaudiAlg/GaudiAlgorithm.h" #include "GaudiKernel/IDataProviderSvc.h" -//#include "GaudiKernel/RegistryEntry.h" +#include "GaudiKernel/ObjectVector.h" + + class objectTest : public GaudiAlgorithm { public: @@ -26,3 +28,7 @@ class objectTest : public GaudiAlgorithm { private: }; + +struct MyTestVectorS : public DataObject { + std::vector m_MyTestVector; +}; diff --git a/k4ActsTracking/src/components/objectTestFind.cpp b/k4ActsTracking/src/components/objectTestFind.cpp new file mode 100644 index 0000000..fe59dea --- /dev/null +++ b/k4ActsTracking/src/components/objectTestFind.cpp @@ -0,0 +1,47 @@ +#include "objectTestFind.h" + +#include +#include +#include +#include +#include "PropagatorAlg.h" + + +//using std::filesystem::current_path; + + +DECLARE_COMPONENT(objectTestFind) + +objectTestFind::objectTestFind(const std::string& aName, ISvcLocator* aSvcLoc) : GaudiAlgorithm(aName, aSvcLoc) {} + +objectTestFind::~objectTestFind() {} + +StatusCode objectTestFind::initialize() {return StatusCode::SUCCESS; } + +StatusCode objectTestFind::execute() { + + + typedef std::vector MyTestVector; + DataObject *pObject; + MyTestVectorS *m_vector = new MyTestVectorS(); + + + StatusCode sc; + + sc = eventSvc()->retrieveObject("/Event/Test", pObject); + if( sc.isFailure() ) { + std::cout << "(no found) initialize sc" << std::endl; + // return StatusCode::FAILURE; + return sc; + } + else{ + std::cout << " (found) initialize sc" << std::endl; + } + + + + std::cout << "Object Test Find is alive!" << std::endl; + return StatusCode::SUCCESS; +} + +StatusCode objectTestFind::finalize() { return StatusCode::SUCCESS; } diff --git a/k4ActsTracking/src/components/objectTestFind.h b/k4ActsTracking/src/components/objectTestFind.h new file mode 100644 index 0000000..9e77490 --- /dev/null +++ b/k4ActsTracking/src/components/objectTestFind.h @@ -0,0 +1,33 @@ +#pragma once + +// GAUDI +#include "Gaudi/Property.h" +#include "GaudiAlg/GaudiAlgorithm.h" +#include "GaudiKernel/IDataProviderSvc.h" +#include "GaudiKernel/ObjectVector.h" +#include "GaudiKernel/ContainedObject.h" + +class objectTestFind : public GaudiAlgorithm { +public: + explicit objectTestFind(const std::string&, ISvcLocator*); + virtual ~objectTestFind(); + /** Initialize. + * @return status code + */ + virtual StatusCode initialize() final; + /** Execute. + * @return status code + */ + virtual StatusCode execute() final; + /** Finalize. + * @return status code + */ + virtual StatusCode finalize() final; + +private: + +}; + +struct MyTestVectorS : public DataObject { + std::vector m_MyTestVector; +}; diff --git a/objectTest.py b/objectTest.py new file mode 100644 index 0000000..737fda6 --- /dev/null +++ b/objectTest.py @@ -0,0 +1,15 @@ +import os +from pprint import pprint +from Gaudi.Configuration import * + +from Configurables import objectTest + +algList = [] + + +a = objectTest("MyobjectTest") +algList.append(a) + +from Configurables import ApplicationMgr + +ApplicationMgr(TopAlg=algList, EvtSel="NONE", EvtMax=1, ExtSvc=[], OutputLevel=DEBUG) diff --git a/objectTestFind.py b/objectTestFind.py new file mode 100644 index 0000000..cce08e7 --- /dev/null +++ b/objectTestFind.py @@ -0,0 +1,15 @@ +import os +from pprint import pprint +from Gaudi.Configuration import * + +from Configurables import objectTestFind + +algList = [] + + +a = objectTestFind("MyobjectTestFind") +algList.append(a) + +from Configurables import ApplicationMgr + +ApplicationMgr(TopAlg=algList, EvtSel="NONE", EvtMax=1, ExtSvc=[], OutputLevel=DEBUG) diff --git a/propagatorAlg.py b/propagatorAlg.py index 61b20dc..a72752a 100644 --- a/propagatorAlg.py +++ b/propagatorAlg.py @@ -3,8 +3,12 @@ from pprint import pprint from Gaudi.Configuration import * +from Configurables import objectTest from Configurables import PropagatorAlg from Configurables import GeoSvc +from Configurables import ParticleGunAlg +from Configurables import RandomNumberSvc +from Configurables import EventCounter sys.path.append('/home/delitez/ACTS/spack/k4actstracking') import actsUnits @@ -12,6 +16,19 @@ algList = [] +# a = objectTest("MyobjectTest") +# algList.append(a) + + +a = ParticleGunAlg("MyParticleGunAlg") +a.d0Sigma = 15 * actsUnits.um +a.z0Sigma = 55 * actsUnits.mm +a.tSigma = 1 * actsUnits.ns +a.nMultiplicity = 5; +a.nParticles = 10; +#a.objectPath = "/Event/MyParticle4" +algList.append(a) + b = PropagatorAlg("PropagatorAlg") # b.mode = 0 @@ -30,24 +47,33 @@ b.tSigma = 1 * actsUnits.ns b.ptLoopers = 500 * actsUnits.MeV b.maxStepSize = 3 * actsUnits.m -b.sensitiveIDopt = 0 +b.sensitiveIDopt = 1 algList.append(b) -a = GeoSvc("GeoSvc") -a.detectors = ["/home/delitez/ACTS/acts/thirdparty/OpenDataDetector/xml/OpenDataDetector.xml"] -a.debugGeometry = True -a.outputFileName = "MyObjFile" + +c = GeoSvc("GeoSvc") +c.detectors = ["/home/delitez/ACTS/acts/thirdparty/OpenDataDetector/xml/OpenDataDetector.xml"] +c.debugGeometry = True +c.outputFileName = "MyObjFileParticleGunTest" + +d = RandomNumberSvc("MyRndNbrSvc") +d.algNum = len(algList); +d.evNum = b.ntests; + + +e = EventCounter("MyEventCounter") +algList.append(e) from Configurables import ApplicationMgr from Configurables import THistSvc -THistSvc().Output = ["rec DATAFILE='propagatorAlgOutput.root' TYP='ROOT' OPT='RECREATE'"] +THistSvc().Output = ["rec DATAFILE='propagatorAlgOutput_PARTICLEGUN.root' TYP='ROOT' OPT='RECREATE'"] THistSvc().OutputLevel = DEBUG THistSvc().PrintAll = True THistSvc().AutoSave = True THistSvc().AutoFlush = True -ApplicationMgr(TopAlg=algList, EvtSel="NONE", EvtMax=500, ExtSvc=[a], OutputLevel=DEBUG) +ApplicationMgr(TopAlg=algList, EvtSel="NONE", EvtMax=20, ExtSvc=[c,d], OutputLevel=DEBUG)