-
Notifications
You must be signed in to change notification settings - Fork 2
Hadrons calo entry merge #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
b66a300
a58fd8a
424f0a4
dc19958
40d2356
c4a39e9
a837221
a254623
d4d497d
837451e
5a39456
455bd8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| #include <G4Types.hh> // for G4int, G4double | ||
| #include <vector> // for vector | ||
| #include "G4UserEventAction.hh" // for G4UserEventAction | ||
| //#include "G4Timer.hh" // for G4Timer | ||
| class G4Event; | ||
| #include "DDG4/Geant4Handle.h" | ||
| #include "DDG4/Geant4Kernel.h" | ||
| #include "DDG4/Geant4EventAction.h" | ||
| #include "CLHEP/Units/SystemOfUnits.h" | ||
| #include "CLHEP/Units/PhysicalConstants.h" | ||
|
|
||
|
|
||
| namespace ddml { | ||
|
|
||
| /** Event action for ddml. | ||
| * | ||
| * @author P. McKeown, CERN | ||
| * @date Feb 2025 | ||
| * | ||
| */ | ||
|
|
||
| class DDMLEventAction: public dd4hep::sim::Geant4EventAction{ | ||
| public: | ||
| /// Standard constructor with initializing arguments | ||
| DDMLEventAction(dd4hep::sim::Geant4Context* c, const std::string& n); | ||
| /// Default destructor | ||
| virtual ~DDMLEventAction(); | ||
| /// End-of-event callback | ||
| void end(const G4Event*) override; | ||
|
|
||
| //// Get and Set methods for Calo Face info | ||
| inline std::vector<G4int>& GetCaloMC_PDG() {return m_CaloMCPDG;} | ||
| inline std::vector<G4double>& GetCaloMC_E() {return m_CaloMCE;} | ||
| inline std::vector<G4double>& GetCaloMC_PosX() {return m_CaloMCPosX;} | ||
| inline std::vector<G4double>& GetCaloMC_PosY() {return m_CaloMCPosY;} | ||
| inline std::vector<G4double>& GetCaloMC_PosZ() {return m_CaloMCPosZ;} | ||
| inline std::vector<G4double>& GetCaloMC_DirX() {return m_CaloMCDirX;} | ||
| inline std::vector<G4double>& GetCaloMC_DirY() {return m_CaloMCDirY;} | ||
| inline std::vector<G4double>& GetCaloMC_DirZ() {return m_CaloMCDirZ;} | ||
|
|
||
| // Set methods to push back vector | ||
| inline void SetElCaloMC_PDG(G4int aValue) {m_CaloMCPDG.push_back(aValue);} | ||
| inline void SetElCaloMC_E(G4double aValue) {m_CaloMCE.push_back(aValue);} | ||
| inline void SetElCaloMC_PosX(G4double aValue) {m_CaloMCPosX.push_back(aValue);} | ||
| inline void SetElCaloMC_PosY(G4double aValue) {m_CaloMCPosY.push_back(aValue);} | ||
| inline void SetElCaloMC_PosZ(G4double aValue) {m_CaloMCPosZ.push_back(aValue);} | ||
| inline void SetElCaloMC_DirX(G4double aValue) {m_CaloMCDirX.push_back(aValue);} | ||
| inline void SetElCaloMC_DirY(G4double aValue) {m_CaloMCDirY.push_back(aValue);} | ||
| inline void SetElCaloMC_DirZ(G4double aValue) {m_CaloMCDirZ.push_back(aValue);} | ||
|
|
||
| private: | ||
| // Fast Sim Calo entrace particle properties to store in ntuple | ||
| std::vector<G4int> m_CaloMCPDG; | ||
| std::vector<G4double> m_CaloMCE; | ||
| std::vector<G4double> m_CaloMCPosX; | ||
| std::vector<G4double> m_CaloMCPosY; | ||
| std::vector<G4double> m_CaloMCPosZ; | ||
| std::vector<G4double> m_CaloMCDirX; | ||
| std::vector<G4double> m_CaloMCDirY; | ||
| std::vector<G4double> m_CaloMCDirZ; | ||
| }; | ||
|
|
||
| } //namespace | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #include <CLHEP/Units/SystemOfUnits.h> // for GeV | ||
| #include <G4String.hh> // for G4String | ||
| #include <G4ThreeVector.hh> // for G4ThreeVector | ||
| #include <G4Types.hh> // for G4int | ||
| //#include "G4Timer.hh" // for G4Timer | ||
| class G4ParticleDefinition; | ||
| #include "DDG4/Geant4Handle.h" | ||
| #include "DDG4/Geant4Kernel.h" | ||
| #include "DDG4/Geant4RunAction.h" | ||
|
|
||
|
|
||
|
|
||
| namespace ddml{ | ||
| /* Create analysis files in standard G4 manner | ||
| * | ||
| * @author P. McKeown | ||
| * @date Feb 2025 | ||
| * | ||
| */ | ||
|
|
||
| class DDMLRunAction: public dd4hep::sim::Geant4RunAction { | ||
| public: | ||
| DDMLRunAction() = delete; | ||
| /// Standard constructor with initializing arguments | ||
| DDMLRunAction(dd4hep::sim::Geant4Context* c, const std::string& n) ; | ||
| /// Default destructor | ||
| virtual ~DDMLRunAction() ; | ||
| /// begin-of-run callback | ||
| void begin(const G4Run*) override; | ||
| /// End-of-run callback | ||
| void end(const G4Run*) override; | ||
| /// begin-of-event callback | ||
| void beginEvent(const G4Event*) ; | ||
| /// End-of-event callback | ||
| void endEvent(const G4Event*) ; | ||
|
Comment on lines
+28
to
+35
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to above, only need to declare those that are actually implemented |
||
|
|
||
| }; | ||
|
|
||
| } // namespace | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,7 +49,8 @@ class LoadHdf5 : public InferenceInterface { | |
| std::vector<float> m_library{}; | ||
|
|
||
| // shower library dimensions | ||
| std::vector<unsigned long> m_dimsOut{}; | ||
| std::vector<unsigned long long> m_dimsOut{}; // This is a hot fix for older HDF5 versions! | ||
| //std::vector<unsigned long> m_dimsOut{}; | ||
|
Comment on lines
+52
to
+53
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we solve this with pre-processor checks? I suppose HDF5 exposes that somehow. Alternatively figure out the minimum version for hdf5 to go with the original version so that we can put this into the dependencies properly. |
||
|
|
||
| // properties for plugin | ||
| std::string m_filePath = {}; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| #ifndef PionClouds_H | ||
| #define PionClouds_H | ||
|
|
||
| #include "DDML/ModelInterface.h" | ||
| #include "DDML/FastMLShower.h" | ||
|
|
||
|
|
||
| namespace ddml { | ||
|
|
||
| /** Class for running a point cloud based ML model for fast shower simulation. | ||
| * Assumes a cartesian (x,y) coordinates defining the calorimeter planes (layers) and z the depth | ||
| * of the calorimeter. | ||
| * | ||
| * Based on BiBAETwoAngleModel. | ||
| * | ||
| * Implemented here for the PionClouds model intended for hadron shower simulation (ECAL+HCAL). | ||
| * | ||
| * @author A.Korol, DESY | ||
| * @author P. McKeown, CERN | ||
| * @date Feb. 2025 | ||
| */ | ||
|
|
||
| class PionCloudsModel : public ModelInterface { | ||
|
|
||
| public: | ||
| PionCloudsModel() {} ; | ||
|
|
||
| virtual ~PionCloudsModel(){}; | ||
|
|
||
| /// declare the proerties needed for the plugin | ||
| void declareProperties(dd4hep::sim::Geant4Action* plugin) { | ||
| plugin->declareProperty("LatentVectorSize", this->m_latentSize); | ||
| } | ||
|
|
||
| /** prepare the input vector and resize the output vector for this model | ||
| * based on the current FastTrack (e.g. extract kinetic energy and incident | ||
| * angles.) | ||
| */ | ||
| virtual void prepareInput(G4FastTrack const& aFastTrack, | ||
| G4ThreeVector const& localDir, | ||
| InputVecs& inputs, TensorDimVecs& tensDims, | ||
| std::vector<float>& output ) ; | ||
|
|
||
|
|
||
| /** create a vector of spacepoints per layer interpreting the model output | ||
| */ | ||
| virtual void convertOutput(G4FastTrack const& aFastTrack, | ||
| G4ThreeVector const& localDir, | ||
| const std::vector<float>& output, | ||
| std::vector<SpacePointVec>& spacepoints ) ; | ||
|
|
||
|
|
||
|
|
||
| private: | ||
|
|
||
| /// model properties for plugin | ||
| // These grid sizes were used for the two angle BIBAE | ||
| int m_numPoints = 2600; //4148; //2600; //number of points in the shower | ||
| int m_latentSize = 3; // number of input features (energy, theta, phi) | ||
| int m_maxNumElements = m_numPoints*4; // number of space points in the output multiplied by 4 (x,y,z,energy) | ||
| int m_nLayer = 78; | ||
|
|
||
| struct Vector3d{double x; double y; double z;}; | ||
|
|
||
| Vector3d crossProduct(const Vector3d& v1, const Vector3d& v2); | ||
|
|
||
| Vector3d normalize(const Vector3d& v); | ||
|
|
||
| TensorDimVecs m_tensDims = {{1, 1}, {1, 1}, {1, 1}, {1, 3}}; | ||
| }; | ||
|
|
||
| } // namespace ddml | ||
| #endif | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a runtime option rather than a compile time option? Looking at the code below where it is used, it looks like the simple runtime check for this is effectively free compared to the rest of work that is done.