From c57961d2942c0a15733b0a633cfbc6283b2d8532 Mon Sep 17 00:00:00 2001 From: tomeichlersmith Date: Mon, 15 Jan 2024 15:08:47 -0600 Subject: [PATCH 1/2] remove EventDef header --- include/SimCore/Simulator.h | 1 - include/SimCore/SimulatorBase.h | 1 - 2 files changed, 2 deletions(-) diff --git a/include/SimCore/Simulator.h b/include/SimCore/Simulator.h index 52de7bad..7a6b7d41 100644 --- a/include/SimCore/Simulator.h +++ b/include/SimCore/Simulator.h @@ -20,7 +20,6 @@ /* Framework */ /*~~~~~~~~~~~~~~~*/ #include "Framework/Configure/Parameters.h" -#include "Framework/EventDef.h" #include "Framework/EventProcessor.h" #include "SimCore/ConditionsInterface.h" #include "SimCore/DetectorConstruction.h" diff --git a/include/SimCore/SimulatorBase.h b/include/SimCore/SimulatorBase.h index 87f0a6a6..b104067e 100644 --- a/include/SimCore/SimulatorBase.h +++ b/include/SimCore/SimulatorBase.h @@ -7,7 +7,6 @@ #include #include "Framework/Configure/Parameters.h" -#include "Framework/EventDef.h" #include "Framework/EventFile.h" #include "Framework/EventHeader.h" #include "Framework/EventProcessor.h" From 7b821bafd176ad4eefff636ec00622377232bcb0 Mon Sep 17 00:00:00 2001 From: tomeichlersmith Date: Mon, 15 Jan 2024 15:23:17 -0600 Subject: [PATCH 2/2] remove generator that is not compiling and unused we /could/ rework this generator to use the new EventFile syntax (requiring deletion to close rather than a specific close method), but this generator has gone unused for so long I don't think it would run even with this patch. Besides, the updated full re-simulation infrastructure allows users to effectively re-sim from the ECal _perfectly_ so this running mode is already covered. --- .../SimCore/Generators/RootSimFromEcalSP.h | 108 -------------- src/SimCore/Generators/RootSimFromEcalSP.cxx | 135 ------------------ 2 files changed, 243 deletions(-) delete mode 100644 include/SimCore/Generators/RootSimFromEcalSP.h delete mode 100644 src/SimCore/Generators/RootSimFromEcalSP.cxx diff --git a/include/SimCore/Generators/RootSimFromEcalSP.h b/include/SimCore/Generators/RootSimFromEcalSP.h deleted file mode 100644 index fa5d3028..00000000 --- a/include/SimCore/Generators/RootSimFromEcalSP.h +++ /dev/null @@ -1,108 +0,0 @@ -/** - * @file RootSimFromEcalSP.h - * @brief Primary generator used to generate primaries from SimParticles. - * @author Nhan Tran, Fermilab - * @author Omar Moreno, SLAC National Accelerator Laboratory - * @author Tom Eichlersmith, University of Minnesota - */ - -#ifndef SIMCORE_ROOTSIMFROMECALSP_H -#define SIMCORE_ROOTSIMFROMECALSP_H - -//----------------// -// C++ StdLib // -//----------------// -#include -#include -#include - -//----------// -// ROOT // -//----------// -#include "TFile.h" -#include "TTree.h" -#include "TVector3.h" - -//-------------// -// ldmx-sw // -//-------------// -#include "Framework/Event.h" -#include "Framework/EventFile.h" -#include "SimCore/PrimaryGenerator.h" - -class G4Event; - -namespace simcore { -namespace generators { - -/** - * @class RootSimFromEcalSP - * - * Generate primaries that correspond to particles leaving - * the ECal (passing through the Ecal Scoring Planes) before - * a time cutoff. - */ -class RootSimFromEcalSP : public PrimaryGenerator { - public: - /** - * Class constructor. - * @param name name of this generator - * @param parameters configuration parameters - * - * Parameters: - * filePath : path to root file containing events to re-sim - * timeCutoff : maximum time that a particle can pass through Ecal Scoring - * Planes and be included in re-sim (ns) ecalSPHitsCollName : name of - * collection for Ecal Scoring Plane hits ecalSPHitsPassName : name of pass - * for Ecal Scoring Plane hits - */ - RootSimFromEcalSP(const std::string& name, - const framework::config::Parameters& parameters); - - /** - * Class destructor. - */ - virtual ~RootSimFromEcalSP(); - - /** - * Generate vertices in the Geant4 event. - * @param anEvent The Geant4 event. - */ - void GeneratePrimaryVertex(G4Event* anEvent) final override; - - void RecordConfig(const std::string& id, ldmx::RunHeader& rh) final override; - - private: - /** - * The cutoff time - * - * Any particle passing through the ECal scoring planes at a time - * greater than this time is NOT re-used as a primary. - */ - double timeCutoff_; - - /** - * The Ecal Scoring Planes Hits collection name - */ - std::string ecalSPHitsCollName_; - - /** - * The Ecal Scoring Planes Hits pass name - */ - std::string ecalSPHitsPassName_; - - /** - * The input root file - */ - std::unique_ptr ifile_; - - /** - * The input ldmx event bus - */ - framework::Event ievent_; -}; - -} // namespace generators -} // namespace simcore - -#endif // SIMCORE_ROOTSIMFROMECALSP_H diff --git a/src/SimCore/Generators/RootSimFromEcalSP.cxx b/src/SimCore/Generators/RootSimFromEcalSP.cxx deleted file mode 100644 index 5ea92778..00000000 --- a/src/SimCore/Generators/RootSimFromEcalSP.cxx +++ /dev/null @@ -1,135 +0,0 @@ -/** - * @file RootSimFromEcalSP.cxx - * @brief Primary generator used to generate primaries from SimParticles. - * @author Nhan Tran, Fermilab - * @author Omar Moreno, SLAC National Accelerator Laboratory - * @author Tom Eichlersmith, University of Minnesota - */ - -#include "SimCore/Generators/RootSimFromEcalSP.h" - -//----------------// -// C++ StdLib // -//----------------// -#include - -//------------// -// Geant4 // -//------------// -#include "G4Event.hh" -#include "G4IonTable.hh" -#include "G4PhysicalConstants.hh" -#include "G4RunManager.hh" -#include "G4SystemOfUnits.hh" - -//-------------// -// ldmx-sw // -//-------------// -#include "Framework/Configure/Parameters.h" -#include "SimCore/Event/SimTrackerHit.h" - -namespace simcore { -namespace generators { - -RootSimFromEcalSP::RootSimFromEcalSP( - const std::string& name, const framework::config::Parameters& parameters) - : PrimaryGenerator(name, parameters), ievent_("InputReSim") { - framework::config::Parameters file_params; - file_params.addParameter("tree_name", "LDMX_Events"); - std::string filename = parameters.getParameter("filePath"); - ifile_ = std::make_unique(file_params, filename); - ifile_->setupEvent(&ievent_); - - timeCutoff_ = parameters.getParameter("time_cutoff"); - ecalSPHitsCollName_ = parameters.getParameter("collection_name"); - ecalSPHitsPassName_ = parameters.getParameter("pass_name"); -} - -RootSimFromEcalSP::~RootSimFromEcalSP() { - ifile_->close(); - ifile_.reset(nullptr); -} - -void RootSimFromEcalSP::GeneratePrimaryVertex(G4Event* anEvent) { - // go to next event - // if there isn't another event ==> EventFile::nextEvent returns false - if (not ifile_->nextEvent()) { - std::cout << "[ RootSimFromEcalSP ]: End of file reached." << std::endl; - G4RunManager::GetRunManager()->AbortRun(true); - anEvent->SetEventAborted(); - } - - // In this mode, we need to loop through all ECal scoring plane hits - // and find the subset of unique hits created by particles exiting - // the ECal. These particles will be stored in a container and - // re-fired into the HCal. - std::unordered_map spHits; - - auto ecalSPParticles{ievent_.getCollection( - ecalSPHitsCollName_, ecalSPHitsPassName_)}; - // Loop through all of the ECal scoring plane hits. - for (const ldmx::SimTrackerHit& spHit : ecalSPParticles) { - // First, start by skipping all hits that were created by - // particles entering the ECal volume. - if (spHit.getLayerID() == 1 and spHit.getMomentum()[2] > 0) continue; - if (spHit.getLayerID() == 2 and spHit.getMomentum()[2] < 0) continue; - if (spHit.getLayerID() == 3 and spHit.getMomentum()[1] < 0) continue; - if (spHit.getLayerID() == 4 and spHit.getMomentum()[1] > 0) continue; - if (spHit.getLayerID() == 5 and spHit.getMomentum()[0] > 0) continue; - if (spHit.getLayerID() == 6 and spHit.getMomentum()[0] < 0) continue; - - // Don't consider particles created outside of the HCal readout - // window. Currently, this is estimated to be 50 ns. - if (spHit.getTime() > timeCutoff_) continue; - - if (spHits.find(spHit.getTrackID()) == spHits.end()) { - spHits[spHit.getTrackID()] = &spHit; - } else { - float currentPMag = - sqrt(pow(spHit.getMomentum()[0], 2) + pow(spHit.getMomentum()[1], 2) + - pow(spHit.getMomentum()[2], 2)); - float pMag = sqrt(pow(spHits[spHit.getTrackID()]->getMomentum()[0], 2) + - pow(spHits[spHit.getTrackID()]->getMomentum()[1], 2) + - pow(spHits[spHit.getTrackID()]->getMomentum()[2], 2)); - - if (pMag < currentPMag) spHits[spHit.getTrackID()] = &spHit; - } - } - - for (auto const& spHit : spHits) { - auto cVertex{new G4PrimaryVertex()}; - cVertex->SetPosition(spHit.second->getPosition()[0] * mm, - spHit.second->getPosition()[1] * mm, - spHit.second->getPosition()[2] * mm); - cVertex->SetWeight(1.); - - auto primary{new G4PrimaryParticle()}; - primary->SetPDGcode(spHit.second->getPdgID()); - primary->SetMomentum(spHit.second->getMomentum()[0] * MeV, - spHit.second->getMomentum()[1] * MeV, - spHit.second->getMomentum()[2] * MeV); - - cVertex->SetPrimary(primary); - anEvent->AddPrimaryVertex(cVertex); - } - - // Create an input stream with a copy of the event seed as content. - // The input stream is then passed to the random engine to restore - // the state. - std::istringstream iss( - ievent_.getEventHeader().getStringParameter("eventSeed")); - G4Random::restoreFullState(iss); -} - -void RootSimFromEcalSP::RecordConfig(const std::string& id, - ldmx::RunHeader& rh) { - rh.setStringParameter(id + " Class", - "simcore::generators::RootSimFromEcalSP"); - rh.setStringParameter(id + " File Path", ifile_->getFileName()); - rh.setFloatParameter(id + " Time Cutoff [ns]", timeCutoff_); -} - -} // namespace generators -} // namespace simcore - -DECLARE_GENERATOR(simcore::generators::RootSimFromEcalSP)