diff --git a/PhysicsAnalysis/NtupleDumper/CMakeLists.txt b/PhysicsAnalysis/NtupleDumper/CMakeLists.txt index dd8faf032f48b2c3d78453b84494e1903d64367d..24b788d23b88e95ed37a20e86a109f198e836851 100644 --- a/PhysicsAnalysis/NtupleDumper/CMakeLists.txt +++ b/PhysicsAnalysis/NtupleDumper/CMakeLists.txt @@ -7,9 +7,10 @@ atlas_add_component( src/NtupleDumperAlg.h src/NtupleDumperAlg.cxx src/component/NtupleDumper_entries.cxx - LINK_LIBRARIES AthenaBaseComps StoreGateLib xAODFaserWaveform xAODFaserCalorimeter xAODFaserTrigger xAODFaserLHC ScintIdentifier FaserCaloIdentifier GeneratorObjects FaserActsGeometryLib TrackerSimEvent TrackerSimData TrackerIdentifier TrackerReadoutGeometry TrkTrack GeoPrimitives TrackerRIO_OnTrack TrackerSpacePoint FaserActsKalmanFilterLib FaserActsmanVertexingLib + LINK_LIBRARIES AthenaBaseComps StoreGateLib xAODFaserWaveform xAODFaserCalorimeter xAODFaserTrigger xAODFaserLHC ScintIdentifier FaserCaloIdentifier GeneratorObjects FaserActsGeometryLib TrackerSimEvent TrackerSimData TrackerIdentifier TrackerReadoutGeometry TrkTrack GeoPrimitives TrackerRIO_OnTrack TrackerSpacePoint FaserActsKalmanFilterLib FaserActsmanVertexingLib AtlasHepMCLib PRIVATE_LINK_LIBRARIES nlohmann_json::nlohmann_json ) atlas_install_python_modules( python/*.py ) atlas_install_scripts( scripts/*.py scripts/*.sh ) + diff --git a/PhysicsAnalysis/NtupleDumper/src/NtupleDumperAlg.cxx b/PhysicsAnalysis/NtupleDumper/src/NtupleDumperAlg.cxx index 843ae66e59b0e1384acc2c7e5525133c3df1b5c0..def572ed1dbd7ad5e6af132eaeb17fbfc5a57f11 100644 --- a/PhysicsAnalysis/NtupleDumper/src/NtupleDumperAlg.cxx +++ b/PhysicsAnalysis/NtupleDumper/src/NtupleDumperAlg.cxx @@ -14,6 +14,7 @@ #include "TrackerReadoutGeometry/SiDetectorElement.h" #include "TrackerPrepRawData/FaserSCT_Cluster.h" #include "xAODTruth/TruthParticle.h" +#include "AtlasHepMC/GenEvent.h" #include <cmath> #include <TH1F.h> #include <numeric> @@ -89,6 +90,7 @@ void NtupleDumperAlg::addCalibratedBranches(const std::string &name, StatusCode NtupleDumperAlg::initialize() { ATH_CHECK(m_truthEventContainer.initialize()); + ATH_CHECK(m_mcEventContainer.initialize()); ATH_CHECK(m_truthParticleContainer.initialize()); ATH_CHECK(m_lhcData.initialize()); ATH_CHECK(m_trackCollection.initialize()); @@ -339,7 +341,7 @@ StatusCode NtupleDumperAlg::initialize() m_tree->Branch("truthBarcode", &m_truthBarcode, "truthBarcode/I"); m_tree->Branch("truthPdg", &m_truthPdg, "truthPdg/I"); m_tree->Branch("CrossSection", &m_crossSection, "crossSection/D"); - + m_tree->Branch("GenWeights", &m_genWeights); // first 10 truth particles @@ -455,8 +457,16 @@ StatusCode NtupleDumperAlg::execute(const EventContext &ctx) const if (truthEventContainer.isValid() && truthEventContainer->size() > 0) { isMC = true; + + } + + SG::ReadHandle<McEventCollection> mcEventContainer {m_mcEventContainer, ctx}; + if (isMC && (!mcEventContainer.isValid() || mcEventContainer->size() == 0)) { + ATH_MSG_WARNING("Could not retrieve MCEventCollection " << m_mcEventContainer); + return StatusCode::SUCCESS; } + // EventInfo data m_run_number = ctx.eventID().run_number(); m_event_number = ctx.eventID().event_number(); @@ -698,6 +708,13 @@ StatusCode NtupleDumperAlg::execute(const EventContext &ctx) const m_crossSection = m_baseEventCrossSection; } + // Store event weights if exist + const HepMC::GenEvent* genEvent = mcEventContainer->at(0); + for (auto wt : genEvent->weights()) { + m_genWeights.push_back(wt); + } + + // Find truth particle information SG::ReadHandle<xAOD::TruthParticleContainer> truthParticleContainer { m_truthParticleContainer, ctx }; if (truthParticleContainer.isValid() && truthParticleContainer->size() > 0) { @@ -1402,6 +1419,7 @@ NtupleDumperAlg::clearTree() const m_station2Clusters = 0; m_station3Clusters = 0; m_crossSection = 0; + m_genWeights.clear(); m_nspacepoints = 0; m_spacepointX.clear(); diff --git a/PhysicsAnalysis/NtupleDumper/src/NtupleDumperAlg.h b/PhysicsAnalysis/NtupleDumper/src/NtupleDumperAlg.h index 1f665c6f13744bf8c36ee22ebf611ae586a26f12..5f7dedda2c7801f58ecdd5365dc152dbdab763e7 100644 --- a/PhysicsAnalysis/NtupleDumper/src/NtupleDumperAlg.h +++ b/PhysicsAnalysis/NtupleDumper/src/NtupleDumperAlg.h @@ -24,6 +24,7 @@ #include "xAODEventInfo/EventInfo.h" #include "StoreGate/ReadDecorHandle.h" #include "FaserActsVertexing/IVertexingTool.h" +#include "GeneratorObjects/McEventCollection.h" #include <boost/dynamic_bitset.hpp> #include <vector> @@ -69,6 +70,7 @@ private: SG::ReadHandleKey<xAOD::TruthEventContainer> m_truthEventContainer { this, "EventContainer", "TruthEvents", "Truth event container name." }; SG::ReadHandleKey<xAOD::TruthParticleContainer> m_truthParticleContainer { this, "ParticleContainer", "TruthParticles", "Truth particle container name." }; + SG::ReadHandleKey<McEventCollection> m_mcEventContainer {this, "McEventCollection", "BeamTruthEvent", "MC event collection name"}; SG::ReadHandleKey<TrackerSimDataCollection> m_simDataCollection {this, "TrackerSimDataCollection", "SCT_SDO_Map"}; SG::ReadHandleKey<xAOD::FaserLHCData> m_lhcData {this, "FaserLHCDataKey", "FaserLHCData"}; @@ -316,6 +318,7 @@ private: mutable std::vector<int> m_truthParticleMatchedTracks; // vector of number of tracks to which a truth particle is matched to mutable std::vector<bool> m_truthParticleIsFiducial; // vector of boolean showing whether a truth particle is fiducial + // mother + daughter truth information mutable std::vector<double> m_truthM_P; @@ -366,10 +369,12 @@ private: mutable std::vector<int> m_truth_pdg; // pdg of first 10 truth particles - mutable double m_truthLeptonMomentum; + mutable double m_truthLeptonMomentum; mutable int m_truthBarcode; mutable int m_truthPdg; mutable double m_crossSection; + mutable std::vector<double> m_genWeights; + mutable int m_eventsPassed = 0; mutable int m_eventsFailedGRL = 0;