From 56a382267d79198c2df515378c13bfd898a98c21 Mon Sep 17 00:00:00 2001 From: BrieucF Date: Fri, 26 Apr 2024 17:43:51 +0200 Subject: [PATCH 1/9] Transformer to create tracks from gen particles --- Tracking/CMakeLists.txt | 8 ++ Tracking/components/PlotTrackHitResiduals.cpp | 97 +++++++++++++++++++ .../components/TracksFromGenParticles.cpp | 91 +++++++++++++++++ Tracking/test/runTracksFromGenParticles.py | 52 ++++++++++ 4 files changed, 248 insertions(+) create mode 100644 Tracking/components/PlotTrackHitResiduals.cpp create mode 100644 Tracking/components/TracksFromGenParticles.cpp create mode 100644 Tracking/test/runTracksFromGenParticles.py diff --git a/Tracking/CMakeLists.txt b/Tracking/CMakeLists.txt index f441d5c..617d1eb 100644 --- a/Tracking/CMakeLists.txt +++ b/Tracking/CMakeLists.txt @@ -3,11 +3,13 @@ set(PackageName Tracking) project(${PackageName}) #find_package(GenFit) +FIND_PACKAGE(MarlinUtil) #if (GenFit_FOUND) file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cpp + ${PROJECT_SOURCE_DIR}/components/*.cpp ) file(GLOB headers @@ -26,6 +28,7 @@ gaudi_add_module(${PackageName} target_include_directories(${PackageName} PUBLIC $ $ + ${MarlinUtil_INCLUDE_DIRS} ) set_target_properties(${PackageName} PROPERTIES PUBLIC_HEADER "${headers}") @@ -44,4 +47,9 @@ install(TARGETS ${PackageName} ) install(FILES ${scripts} DESTINATION test) + +SET(test_name "test_TracksFromGenParticles") +ADD_TEST(NAME ${test_name} COMMAND k4run test/runTracksFromGenParticles.py) +set_test_env(${test_name}) + #endif() diff --git a/Tracking/components/PlotTrackHitResiduals.cpp b/Tracking/components/PlotTrackHitResiduals.cpp new file mode 100644 index 0000000..36ed1af --- /dev/null +++ b/Tracking/components/PlotTrackHitResiduals.cpp @@ -0,0 +1,97 @@ +// Gaudi +#include "Gaudi/Property.h" +#include "GaudiAlg/Consumer.h" +#include "Gaudi/Accumulators/RootHistogram.h" +#include "Gaudi/Histograming/Sink/Utils.h" + +// edm4hep +#include "edm4hep/MCParticleCollection.h" +#include "edm4hep/TrackCollection.h" +#include "edm4hep/MCRecoTrackParticleAssociationCollection.h" +#include "edm4hep/SimTrackerHitCollection.h" + +// marlin +#include + +// ROOT +#include "TH1D.h" + +// Define BaseClass_t +#include "k4FWCore/BaseClass.h" + +#include + +/** @class PlotTrackHitDistances + * + * Gaudi consumer that generates a residual distribution (mm) by comparing the helix from Track AtIP and simHit position. + * This is intended to be used on tracks produced from gen particles i.e. which do not have real hits attached to them. + * + * @author Brieuc Francois + */ + +struct PlotTrackHitDistances final + : Gaudi::Functional::Consumer { + PlotTrackHitDistances(const std::string& name, ISvcLocator* svcLoc) + : Consumer( + name, svcLoc, + { + KeyValue("InputSimTrackerHits", "DCHCollection"), + KeyValue("InputTracksFromGenParticlesAssociation", "TracksFromGenParticlesAssociation"), + }) {} + + void operator()(const edm4hep::SimTrackerHitCollection& simTrackerHits, const edm4hep::MCRecoTrackParticleAssociationCollection& trackParticleAssociations) const override { + + for (const auto& trackParticleAssociation : trackParticleAssociations) { + auto genParticle = trackParticleAssociation.getSim(); + auto track = trackParticleAssociation.getRec(); + edm4hep::TrackState trackStateAtIP; + bool found_trackStateAtIP = false; + for (const auto& trackState : track.getTrackStates()) { + if (trackState.location == edm4hep::TrackState::AtIP) { + trackStateAtIP = trackState; + found_trackStateAtIP = true; + } + } + if (!found_trackStateAtIP) + throw std::runtime_error("No track state defined AtIP, exiting!"); + + // Build an helix out of the trackState + auto helixFromTrack = HelixClass_double(); + helixFromTrack.Initialize_Canonical(trackStateAtIP.phi, trackStateAtIP.D0, trackStateAtIP.Z0, trackStateAtIP.omega, trackStateAtIP.tanLambda, m_Bz); + + // Fill the histogram with residuals for hits attached to the same gen particle + for (const auto& simTrackerHit : simTrackerHits) { + auto simTrackerHitgenParticle = simTrackerHit.getParticle(); + if (simTrackerHitgenParticle.getObjectID() == genParticle.getObjectID()) { + double simTrackerHitPosition[] = {simTrackerHit.x(), simTrackerHit.y(), simTrackerHit.z()}; + double distances[3]; + helixFromTrack.getDistanceToPoint(simTrackerHitPosition, distances); + // Distance[0] - distance in R-Phi plane, Distance[1] - distance along Z axis, Distance[2] - 3D distance + ++m_residualHist[distances[2]]; + } + } + } + return; + } + Gaudi::Property m_Bz{this, "Bz", 2., "Z component of the (assumed constant) magnetic field in Tesla."}; + mutable Gaudi::Accumulators::Histogram<1> m_residualHist{this, "", "Track-hit Distances", {100, 0, 1, "Distance [mm];Entries"}}; + + StatusCode finalize() override { + TFile file("track_hit_distances.root", "RECREATE"); + std::string name = ""; + // Name that will appear in the stats table + std::string histName = "Distances"; + nlohmann::json jH {m_residualHist}; + auto [histo, dir] = Gaudi::Histograming::Sink::jsonToRootHistogram>(name, histName, jH[0]); + // Add overflow bin to the last bin + int lastBinIndex = histo.GetNbinsX(); + histo.SetBinContent(lastBinIndex, histo.GetBinContent(lastBinIndex) + histo.GetBinContent(lastBinIndex + 1)); + // Name of the histogram in the ROOT file + histo.Write("Distances"); + file.Close(); + return StatusCode::SUCCESS; + } + +}; + +DECLARE_COMPONENT(PlotTrackHitDistances) diff --git a/Tracking/components/TracksFromGenParticles.cpp b/Tracking/components/TracksFromGenParticles.cpp new file mode 100644 index 0000000..08be5b0 --- /dev/null +++ b/Tracking/components/TracksFromGenParticles.cpp @@ -0,0 +1,91 @@ +#include "Gaudi/Property.h" +#include "GaudiAlg/Transformer.h" + +// edm4hep +#include "edm4hep/MCParticleCollection.h" +#include "edm4hep/TrackCollection.h" +#include "edm4hep/MCRecoTrackParticleAssociationCollection.h" + +// marlin +#include + +// Define BaseClass_t +#include "k4FWCore/BaseClass.h" + +#include + +/** @class TracksFromGenParticles + * + * Gaudi transformer that builds an edm4hep::TrackCollection out of an edm4hep::MCParticleCollection. + * It just builds an helix out of the genParticle position, momentum, charge and user defined z component of the (constant) magnetic field. + * From this helix, different edm4hep::TrackStates (AtIP, AtFirstHit, AtLastHit and AtCalorimeter) are defined. #FIXME for now these trackstates are dummy (copies of the same helix parameters) + * This is meant to enable technical development needing edm4hep::Track and performance studies where having generator based trackis is a reasonable approximation. + * Possible inprovement: + * - Retrieve magnetic field from geometry: const DD4hep::Field::MagneticField& magneticField = detector.field(); DD4hep::DDRec::Vector3D field = magneticField.magneticField(point); + * - Properly define different trackStates + * + * @author Brieuc Francois + */ + +struct TracksFromGenParticles final + : Gaudi::Functional::MultiTransformer(const edm4hep::MCParticleCollection&), BaseClass_t> { + TracksFromGenParticles(const std::string& name, ISvcLocator* svcLoc) + : MultiTransformer( + name, svcLoc, + {KeyValue("InputGenParticles", "MCParticles")}, + {KeyValue("OutputTracks", "TracksFromGenParticles"), + KeyValue("OutputMCRecoTrackParticleAssociation", "TracksFromGenParticlesAssociation")}) { + } + +std::tuple operator()(const edm4hep::MCParticleCollection& genParticleColl) const override { + + auto outputTrackCollection = edm4hep::TrackCollection(); + auto MCRecoTrackParticleAssociationCollection = edm4hep::MCRecoTrackParticleAssociationCollection(); + + for (const auto& genParticle : genParticleColl) { + debug() << "Particle decayed in tracker: " << genParticle.isDecayedInTracker() << endmsg; + debug() << genParticle << endmsg; + + // Building an helix out of MCParticle properties and B field + auto helixFromGenParticle = HelixClass_double(); + double genParticleVertex[] = {genParticle.getVertex().x, genParticle.getVertex().y, genParticle.getVertex().z}; + double genParticleMomentum[] = {genParticle.getMomentum().x, genParticle.getMomentum().y, genParticle.getMomentum().z}; + helixFromGenParticle.Initialize_VP(genParticleVertex, genParticleMomentum, genParticle.getCharge(), m_Bz); + + // Setting the track and trackStates properties + // #FIXME for now, the different trackStates are dummy + auto trackFromGen = edm4hep::MutableTrack(); + auto trackState_IP = edm4hep::TrackState {}; + trackState_IP.location = edm4hep::TrackState::AtIP; + trackState_IP.D0 = helixFromGenParticle.getD0(); + trackState_IP.phi = helixFromGenParticle.getPhi0(); + trackState_IP.omega = helixFromGenParticle.getOmega(); + trackState_IP.Z0 = helixFromGenParticle.getZ0(); + trackState_IP.tanLambda = helixFromGenParticle.getTanLambda(); + trackFromGen.addToTrackStates(trackState_IP); + auto trackState_AtFirstHit = edm4hep::TrackState(trackState_IP); + trackState_AtFirstHit.location = edm4hep::TrackState::AtFirstHit; + trackFromGen.addToTrackStates(trackState_AtFirstHit); + auto trackState_AtLastHit = edm4hep::TrackState(trackState_IP); + trackState_AtFirstHit.location = edm4hep::TrackState::AtLastHit; + trackFromGen.addToTrackStates(trackState_AtLastHit); + auto trackState_AtCalorimeter = edm4hep::TrackState(trackState_IP); + trackState_AtFirstHit.location = edm4hep::TrackState::AtCalorimeter; + trackFromGen.addToTrackStates(trackState_AtCalorimeter); + + debug() << trackFromGen << endmsg; + outputTrackCollection.push_back(trackFromGen); + + // Building the association between tracks and genParticles + auto MCRecoTrackParticleAssociation = edm4hep::MutableMCRecoTrackParticleAssociation(); + MCRecoTrackParticleAssociation.setRec(trackFromGen); + MCRecoTrackParticleAssociation.setSim(genParticle); + MCRecoTrackParticleAssociationCollection.push_back(MCRecoTrackParticleAssociation); + } + return std::make_tuple(std::move(outputTrackCollection), std::move(MCRecoTrackParticleAssociationCollection)); + } + + Gaudi::Property m_Bz{this, "Bz", 2., "Z component of the (assumed constant) magnetic field in Tesla."}; +}; + +DECLARE_COMPONENT(TracksFromGenParticles) diff --git a/Tracking/test/runTracksFromGenParticles.py b/Tracking/test/runTracksFromGenParticles.py new file mode 100644 index 0000000..3f2d4c7 --- /dev/null +++ b/Tracking/test/runTracksFromGenParticles.py @@ -0,0 +1,52 @@ +from Configurables import ApplicationMgr +from Configurables import EventCounter +from Gaudi.Configuration import INFO, WARNING, DEBUG +import os + +if not os.path.isfile("ddsim_output_edm4hep.root"): + os.system("ddsim --enableGun --gun.distribution uniform --gun.energy '10*GeV' --gun.particle e- --numberOfEvents 100 --outputFile ddsim_output_edm4hep.root --random.enableEventSeed --random.seed 42 --compactFile $K4GEO/FCCee/IDEA/compact/IDEA_o1_v02/IDEA_o1_v02.xml") + +# Loading the output of the SIM step +from Configurables import k4DataSvc, PodioInput, PodioOutput +evtsvc = k4DataSvc('EventDataSvc') +evtsvc.input = "ddsim_output_edm4hep.root" +#evtsvc.input = "/afs/cern.ch/user/b/brfranco/work/public/MIT_tutorial/CLDConfig/CLDConfig/wzp6_ee_mumuH_ecm240_CLD_RECO_edm4hep.root" +Nevts = -1 +input_reader = PodioInput('InputReader') + +# Calling TracksFromGenParticles +from Configurables import TracksFromGenParticles +tracksFromGenParticles = TracksFromGenParticles("TracksFromGenParticles", + InputGenParticles = "MCParticles", + OutputTracks = "TracksFromGenParticles", + OutputMCRecoTrackParticleAssociation = "TracksFromGenParticlesAssociation", + Bz = 2.0, + OutputLevel = INFO) + +# produce a TH1 with distances between tracks and simTrackerHits +from Configurables import PlotTrackHitDistances +plotTrackHitDistances = PlotTrackHitDistances("PlotTrackHitDistances", + InputSimTrackerHits = "CDCHHits", + InputTracksFromGenParticlesAssociation = tracksFromGenParticles.OutputMCRecoTrackParticleAssociation, + Bz = 2.0) + +# Output +from Configurables import PodioOutput +out = PodioOutput("out", + OutputLevel=INFO) +out.outputCommands = ["keep *"] +out.filename = "tracks_from_genParticle_output.root" + +# Set auditor service +from Configurables import AuditorSvc, ChronoAuditor +chra = ChronoAuditor() +audsvc = AuditorSvc() +audsvc.Auditors = [chra] + +ApplicationMgr( + TopAlg= [input_reader, tracksFromGenParticles, plotTrackHitDistances, out], + EvtSel='NONE', + EvtMax=Nevts, + ExtSvc=[evtsvc, audsvc], + StopOnSignal=True, +) From 1aa4c7dea4cc8dd637505cb9486abe72a9afc043 Mon Sep 17 00:00:00 2001 From: BrieucF Date: Thu, 25 Jul 2024 10:14:39 +0200 Subject: [PATCH 2/9] Move away from BaseClass_t --- Tracking/components/PlotTrackHitResiduals.cpp | 11 +++++------ Tracking/components/TracksFromGenParticles.cpp | 13 ++++++------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Tracking/components/PlotTrackHitResiduals.cpp b/Tracking/components/PlotTrackHitResiduals.cpp index 36ed1af..ade1cf7 100644 --- a/Tracking/components/PlotTrackHitResiduals.cpp +++ b/Tracking/components/PlotTrackHitResiduals.cpp @@ -1,6 +1,5 @@ // Gaudi #include "Gaudi/Property.h" -#include "GaudiAlg/Consumer.h" #include "Gaudi/Accumulators/RootHistogram.h" #include "Gaudi/Histograming/Sink/Utils.h" @@ -16,8 +15,8 @@ // ROOT #include "TH1D.h" -// Define BaseClass_t -#include "k4FWCore/BaseClass.h" +// k4FWCore +#include "k4FWCore/Consumer.h" #include @@ -30,13 +29,13 @@ */ struct PlotTrackHitDistances final - : Gaudi::Functional::Consumer { + : Gaudi::Functional::Consumer { PlotTrackHitDistances(const std::string& name, ISvcLocator* svcLoc) : Consumer( name, svcLoc, { - KeyValue("InputSimTrackerHits", "DCHCollection"), - KeyValue("InputTracksFromGenParticlesAssociation", "TracksFromGenParticlesAssociation"), + KeyValues("InputSimTrackerHits", {"DCHCollection"}), + KeyValues("InputTracksFromGenParticlesAssociation", {"TracksFromGenParticlesAssociation"}), }) {} void operator()(const edm4hep::SimTrackerHitCollection& simTrackerHits, const edm4hep::MCRecoTrackParticleAssociationCollection& trackParticleAssociations) const override { diff --git a/Tracking/components/TracksFromGenParticles.cpp b/Tracking/components/TracksFromGenParticles.cpp index 08be5b0..48cd9ab 100644 --- a/Tracking/components/TracksFromGenParticles.cpp +++ b/Tracking/components/TracksFromGenParticles.cpp @@ -1,5 +1,4 @@ #include "Gaudi/Property.h" -#include "GaudiAlg/Transformer.h" // edm4hep #include "edm4hep/MCParticleCollection.h" @@ -9,8 +8,8 @@ // marlin #include -// Define BaseClass_t -#include "k4FWCore/BaseClass.h" +// k4FWCore +#include "k4FWCore/Transformer.h" #include @@ -28,13 +27,13 @@ */ struct TracksFromGenParticles final - : Gaudi::Functional::MultiTransformer(const edm4hep::MCParticleCollection&), BaseClass_t> { + : Gaudi::Functional::MultiTransformer(const edm4hep::MCParticleCollection&)> { TracksFromGenParticles(const std::string& name, ISvcLocator* svcLoc) : MultiTransformer( name, svcLoc, - {KeyValue("InputGenParticles", "MCParticles")}, - {KeyValue("OutputTracks", "TracksFromGenParticles"), - KeyValue("OutputMCRecoTrackParticleAssociation", "TracksFromGenParticlesAssociation")}) { + {KeyValues("InputGenParticles", {"MCParticles"})}, + {KeyValues("OutputTracks", {"TracksFromGenParticles"}), + KeyValues("OutputMCRecoTrackParticleAssociation", {"TracksFromGenParticlesAssociation"})}) { } std::tuple operator()(const edm4hep::MCParticleCollection& genParticleColl) const override { From c3a17f52adf113c80ef747b84a98eae14c15219a Mon Sep 17 00:00:00 2001 From: BrieucF Date: Thu, 25 Jul 2024 11:05:46 +0200 Subject: [PATCH 3/9] Adapt to the new way Transformer work --- Tracking/components/PlotTrackHitResiduals.cpp | 3 ++- Tracking/components/TracksFromGenParticles.cpp | 4 ++-- Tracking/test/runTracksFromGenParticles.py | 8 ++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Tracking/components/PlotTrackHitResiduals.cpp b/Tracking/components/PlotTrackHitResiduals.cpp index ade1cf7..02ea68e 100644 --- a/Tracking/components/PlotTrackHitResiduals.cpp +++ b/Tracking/components/PlotTrackHitResiduals.cpp @@ -29,7 +29,7 @@ */ struct PlotTrackHitDistances final - : Gaudi::Functional::Consumer { + : k4FWCore::Consumer { PlotTrackHitDistances(const std::string& name, ISvcLocator* svcLoc) : Consumer( name, svcLoc, @@ -49,6 +49,7 @@ struct PlotTrackHitDistances final if (trackState.location == edm4hep::TrackState::AtIP) { trackStateAtIP = trackState; found_trackStateAtIP = true; + break; } } if (!found_trackStateAtIP) diff --git a/Tracking/components/TracksFromGenParticles.cpp b/Tracking/components/TracksFromGenParticles.cpp index 48cd9ab..af03cb8 100644 --- a/Tracking/components/TracksFromGenParticles.cpp +++ b/Tracking/components/TracksFromGenParticles.cpp @@ -27,7 +27,7 @@ */ struct TracksFromGenParticles final - : Gaudi::Functional::MultiTransformer(const edm4hep::MCParticleCollection&)> { + : k4FWCore::MultiTransformer(const edm4hep::MCParticleCollection&)> { TracksFromGenParticles(const std::string& name, ISvcLocator* svcLoc) : MultiTransformer( name, svcLoc, @@ -72,7 +72,7 @@ std::tuple Date: Sun, 28 Jul 2024 10:32:21 +0200 Subject: [PATCH 4/9] Migrate to IOSvc --- Tracking/test/runTracksFromGenParticles.py | 34 ++++++++++------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/Tracking/test/runTracksFromGenParticles.py b/Tracking/test/runTracksFromGenParticles.py index 67bb91a..51742d1 100644 --- a/Tracking/test/runTracksFromGenParticles.py +++ b/Tracking/test/runTracksFromGenParticles.py @@ -1,5 +1,4 @@ -from Configurables import ApplicationMgr -from Configurables import EventCounter +from k4FWCore import ApplicationMgr from Gaudi.Configuration import INFO, WARNING, DEBUG import os @@ -7,12 +6,10 @@ os.system("ddsim --enableGun --gun.distribution uniform --gun.energy '10*GeV' --gun.particle e- --numberOfEvents 100 --outputFile ddsim_output_edm4hep.root --random.enableEventSeed --random.seed 42 --compactFile $K4GEO/FCCee/IDEA/compact/IDEA_o1_v02/IDEA_o1_v02.xml") # Loading the output of the SIM step -from Configurables import k4DataSvc, PodioInput, PodioOutput -evtsvc = k4DataSvc('EventDataSvc') -evtsvc.input = "ddsim_output_edm4hep.root" -#evtsvc.input = "/afs/cern.ch/user/b/brfranco/work/public/MIT_tutorial/CLDConfig/CLDConfig/wzp6_ee_mumuH_ecm240_CLD_RECO_edm4hep.root" -Nevts = -1 -input_reader = PodioInput('InputReader') +from k4FWCore import IOSvc +io_svc = IOSvc("IOSvc") +io_svc.input = "ddsim_output_edm4hep.root" +io_svc.output = "tracks_from_genParticle_output.root" # Calling TracksFromGenParticles from Configurables import TracksFromGenParticles @@ -30,23 +27,24 @@ InputTracksFromGenParticlesAssociation = tracksFromGenParticles.OutputMCRecoTrackParticleAssociation, Bz = 2.0) -# Output -from Configurables import PodioOutput -out = PodioOutput("out", - OutputLevel=INFO) -out.outputCommands = ["keep *"] -out.filename = "tracks_from_genParticle_output.root" - # Set auditor service from Configurables import AuditorSvc, ChronoAuditor chra = ChronoAuditor() audsvc = AuditorSvc() audsvc.Auditors = [chra] +tracksFromGenParticles.AuditExecute = True +plotTrackHitDistances.AuditExecute = True + +# event counter +from Configurables import EventCounter +event_counter = EventCounter('event_counter') +event_counter.Frequency = 10 +from Configurables import EventDataSvc ApplicationMgr( - TopAlg= [input_reader, tracksFromGenParticles, plotTrackHitDistances, out], + TopAlg= [event_counter, tracksFromGenParticles, plotTrackHitDistances], EvtSel='NONE', - EvtMax=Nevts, - ExtSvc=[evtsvc, audsvc], + EvtMax=-1, + ExtSvc=[EventDataSvc("EventDataSvc"), audsvc], StopOnSignal=True, ) From 27f037f4a4bc1897d7d2c09e011c726a59d2acba Mon Sep 17 00:00:00 2001 From: BrieucF Date: Tue, 6 Aug 2024 11:42:49 +0200 Subject: [PATCH 5/9] [PlotTrackHitResiduals] Remove overflow bin and use RootHistSvc --- Tracking/components/PlotTrackHitResiduals.cpp | 16 ---------------- Tracking/test/runTracksFromGenParticles.py | 8 ++++++-- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/Tracking/components/PlotTrackHitResiduals.cpp b/Tracking/components/PlotTrackHitResiduals.cpp index 02ea68e..5b8c725 100644 --- a/Tracking/components/PlotTrackHitResiduals.cpp +++ b/Tracking/components/PlotTrackHitResiduals.cpp @@ -76,22 +76,6 @@ struct PlotTrackHitDistances final Gaudi::Property m_Bz{this, "Bz", 2., "Z component of the (assumed constant) magnetic field in Tesla."}; mutable Gaudi::Accumulators::Histogram<1> m_residualHist{this, "", "Track-hit Distances", {100, 0, 1, "Distance [mm];Entries"}}; - StatusCode finalize() override { - TFile file("track_hit_distances.root", "RECREATE"); - std::string name = ""; - // Name that will appear in the stats table - std::string histName = "Distances"; - nlohmann::json jH {m_residualHist}; - auto [histo, dir] = Gaudi::Histograming::Sink::jsonToRootHistogram>(name, histName, jH[0]); - // Add overflow bin to the last bin - int lastBinIndex = histo.GetNbinsX(); - histo.SetBinContent(lastBinIndex, histo.GetBinContent(lastBinIndex) + histo.GetBinContent(lastBinIndex + 1)); - // Name of the histogram in the ROOT file - histo.Write("Distances"); - file.Close(); - return StatusCode::SUCCESS; - } - }; DECLARE_COMPONENT(PlotTrackHitDistances) diff --git a/Tracking/test/runTracksFromGenParticles.py b/Tracking/test/runTracksFromGenParticles.py index 51742d1..6a1b188 100644 --- a/Tracking/test/runTracksFromGenParticles.py +++ b/Tracking/test/runTracksFromGenParticles.py @@ -21,12 +21,16 @@ OutputLevel = INFO) # produce a TH1 with distances between tracks and simTrackerHits -from Configurables import PlotTrackHitDistances +from Configurables import PlotTrackHitDistances, RootHistSvc plotTrackHitDistances = PlotTrackHitDistances("PlotTrackHitDistances", InputSimTrackerHits = ["CDCHHits"], InputTracksFromGenParticlesAssociation = tracksFromGenParticles.OutputMCRecoTrackParticleAssociation, Bz = 2.0) +hps = RootHistSvc("HistogramPersistencySvc") +root_hist_svc = RootHistoSink("RootHistoSink") +root_hist_svc.FileName = "TrackHitDistances.root" + # Set auditor service from Configurables import AuditorSvc, ChronoAuditor chra = ChronoAuditor() @@ -45,6 +49,6 @@ TopAlg= [event_counter, tracksFromGenParticles, plotTrackHitDistances], EvtSel='NONE', EvtMax=-1, - ExtSvc=[EventDataSvc("EventDataSvc"), audsvc], + ExtSvc=[root_hist_svc, EventDataSvc("EventDataSvc"), audsvc], StopOnSignal=True, ) From 6090b03f82d7a2ca8f27aa3e8ae69d88d50ef8a2 Mon Sep 17 00:00:00 2001 From: BrieucF Date: Tue, 6 Aug 2024 12:52:13 +0200 Subject: [PATCH 6/9] [TracksFromGenParticles] Fix tests --- Tracking/test/runTracksFromGenParticles.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Tracking/test/runTracksFromGenParticles.py b/Tracking/test/runTracksFromGenParticles.py index 6a1b188..8044b80 100644 --- a/Tracking/test/runTracksFromGenParticles.py +++ b/Tracking/test/runTracksFromGenParticles.py @@ -22,6 +22,7 @@ # produce a TH1 with distances between tracks and simTrackerHits from Configurables import PlotTrackHitDistances, RootHistSvc +from Configurables import Gaudi__Histograming__Sink__Root as RootHistoSink plotTrackHitDistances = PlotTrackHitDistances("PlotTrackHitDistances", InputSimTrackerHits = ["CDCHHits"], InputTracksFromGenParticlesAssociation = tracksFromGenParticles.OutputMCRecoTrackParticleAssociation, @@ -39,14 +40,9 @@ tracksFromGenParticles.AuditExecute = True plotTrackHitDistances.AuditExecute = True -# event counter -from Configurables import EventCounter -event_counter = EventCounter('event_counter') -event_counter.Frequency = 10 - from Configurables import EventDataSvc ApplicationMgr( - TopAlg= [event_counter, tracksFromGenParticles, plotTrackHitDistances], + TopAlg= [tracksFromGenParticles, plotTrackHitDistances], EvtSel='NONE', EvtMax=-1, ExtSvc=[root_hist_svc, EventDataSvc("EventDataSvc"), audsvc], From f48ecfabc3bc91391df0848274c62dafcd3a70e7 Mon Sep 17 00:00:00 2001 From: BrieucF Date: Tue, 6 Aug 2024 12:58:49 +0200 Subject: [PATCH 7/9] [PlotTrackHitResiduals] Set histogram name --- Tracking/components/PlotTrackHitResiduals.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tracking/components/PlotTrackHitResiduals.cpp b/Tracking/components/PlotTrackHitResiduals.cpp index 5b8c725..a32e6b9 100644 --- a/Tracking/components/PlotTrackHitResiduals.cpp +++ b/Tracking/components/PlotTrackHitResiduals.cpp @@ -74,7 +74,7 @@ struct PlotTrackHitDistances final return; } Gaudi::Property m_Bz{this, "Bz", 2., "Z component of the (assumed constant) magnetic field in Tesla."}; - mutable Gaudi::Accumulators::Histogram<1> m_residualHist{this, "", "Track-hit Distances", {100, 0, 1, "Distance [mm];Entries"}}; + mutable Gaudi::Accumulators::Histogram<1> m_residualHist{this, "track_hits_distance_closest_approach", "Track-hit Distances", {100, 0, 1, "Distance [mm];Entries"}}; }; From 33f5af306d608bc0b9a5902226f9a4a39024c238 Mon Sep 17 00:00:00 2001 From: BrieucF Date: Wed, 7 Aug 2024 17:30:21 +0200 Subject: [PATCH 8/9] Fix tests following removal of GaudiAlg --- ARCdigi/test/runARCdigitizer.py | 5 ----- DCHdigi/test/runDCHsimpleDigitizer.py | 5 ----- Tracking/test/runGenFitTrackingOnSimplifiedDriftChamber.py | 5 ----- VTXdigi/test/runVTXdigitizer.py | 6 ------ 4 files changed, 21 deletions(-) diff --git a/ARCdigi/test/runARCdigitizer.py b/ARCdigi/test/runARCdigitizer.py index 712a3bb..9ecc734 100644 --- a/ARCdigi/test/runARCdigitizer.py +++ b/ARCdigi/test/runARCdigitizer.py @@ -34,13 +34,8 @@ arc_digitizer.AuditExecute = True podiooutput.AuditExecute = True -from Configurables import EventCounter -event_counter = EventCounter('event_counter') -event_counter.Frequency = 1 - ApplicationMgr( TopAlg = [ - event_counter, podioinput, arc_digitizer, podiooutput diff --git a/DCHdigi/test/runDCHsimpleDigitizer.py b/DCHdigi/test/runDCHsimpleDigitizer.py index e16b382..d310c90 100644 --- a/DCHdigi/test/runDCHsimpleDigitizer.py +++ b/DCHdigi/test/runDCHsimpleDigitizer.py @@ -129,14 +129,9 @@ geantsim.AuditExecute = True out.AuditExecute = True -from Configurables import EventCounter -event_counter = EventCounter('event_counter') -event_counter.Frequency = 1 - from Configurables import ApplicationMgr ApplicationMgr( TopAlg = [ - event_counter, genAlg, hepmc_converter, geantsim, diff --git a/Tracking/test/runGenFitTrackingOnSimplifiedDriftChamber.py b/Tracking/test/runGenFitTrackingOnSimplifiedDriftChamber.py index e726835..1427308 100644 --- a/Tracking/test/runGenFitTrackingOnSimplifiedDriftChamber.py +++ b/Tracking/test/runGenFitTrackingOnSimplifiedDriftChamber.py @@ -163,14 +163,9 @@ geantsim.AuditExecute = True out.AuditExecute = True -from Configurables import EventCounter -event_counter = EventCounter('event_counter') -event_counter.Frequency = 1 - from Configurables import ApplicationMgr ApplicationMgr( TopAlg = [ - event_counter, genAlg, hepmc_converter, geantsim, diff --git a/VTXdigi/test/runVTXdigitizer.py b/VTXdigi/test/runVTXdigitizer.py index b217704..49d2031 100644 --- a/VTXdigi/test/runVTXdigitizer.py +++ b/VTXdigi/test/runVTXdigitizer.py @@ -268,16 +268,11 @@ geantsim.AuditExecute = True out.AuditExecute = True -from Configurables import EventCounter -event_counter = EventCounter('event_counter') -event_counter.Frequency = 1 - from Configurables import ApplicationMgr # # CLD # ApplicationMgr( # TopAlg = [ -# event_counter, # genAlg, # hepmc_converter, # geantsim, @@ -293,7 +288,6 @@ # IDEA ApplicationMgr( TopAlg = [ - event_counter, genAlg, hepmc_converter, geantsim, From ace83eb047315efa0c6d50123800d72cbc05b7ba Mon Sep 17 00:00:00 2001 From: BrieucF Date: Wed, 7 Aug 2024 17:46:23 +0200 Subject: [PATCH 9/9] Fix tests following removal of GaudiAlg --- DCHdigi/test/runDCHsimpleDigitizerExtendedEdm.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/DCHdigi/test/runDCHsimpleDigitizerExtendedEdm.py b/DCHdigi/test/runDCHsimpleDigitizerExtendedEdm.py index 3d30271..4990c46 100644 --- a/DCHdigi/test/runDCHsimpleDigitizerExtendedEdm.py +++ b/DCHdigi/test/runDCHsimpleDigitizerExtendedEdm.py @@ -162,14 +162,9 @@ geantsim.AuditExecute = True out.AuditExecute = True -from Configurables import EventCounter -event_counter = EventCounter('event_counter') -event_counter.Frequency = 1 - from Configurables import ApplicationMgr ApplicationMgr( TopAlg = [ - event_counter, genAlg, hepmc_converter, geantsim,