Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Frank Gaede
SimpleCalo
Commits
afaa5c28
Commit
afaa5c28
authored
Oct 21, 2021
by
Frank Gaede
Browse files
Merge branch 'edm4hep' into 'main'
Edm4hep See merge request
!1
parents
2bf3a15f
9fc4cb2a
Changes
4
Hide whitespace changes
Inline
Side-by-side
CMakeLists.txt
View file @
afaa5c28
...
...
@@ -15,6 +15,11 @@ else()
find_package
(
Geant4 REQUIRED
)
endif
()
#---------------------------------------------------
# external packages
find_package
(
EDM4HEP REQUIRED
)
#----------------------------------------------------------------------------
# Setup Geant4 include directories and compile definitions
#
...
...
@@ -25,14 +30,24 @@ include(${Geant4_USE_FILE})
#
include_directories
(
${
PROJECT_SOURCE_DIR
}
/include
${
Geant4_INCLUDE_DIR
}
)
file
(
GLOB sources
${
PROJECT_SOURCE_DIR
}
/src/*.cc
)
file
(
GLOB headers
${
PROJECT_SOURCE_DIR
}
/include/*.hh
)
#----------------------------------------------------------------------------
# Add the executable, and link it to the
Geant4
libraries
# Add the executable, and link it to the
external
libraries
#
add_executable
(
SimpleCalo SimpleCalo.cc
${
sources
}
${
headers
}
)
target_link_libraries
(
SimpleCalo
${
Geant4_LIBRARIES
}
)
target_link_libraries
(
SimpleCalo
${
Geant4_LIBRARIES
}
EDM4HEP::edm4hep
EDM4HEP::edm4hepDict
podio::podio
podio::podioRootIO
podio::podioDict
)
#----------------------------------------------------------------------------
# Copy all scripts to the build directory, i.e. the directory in which we
...
...
include/SimpleCaloEDM4hepEventAction.hh
0 → 100644
View file @
afaa5c28
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
/// \file SimpleCaloEDM4hepEventAction.hh
/// \brief Definition of the SimpleCaloEDM4hepEventAction class
//
#ifndef SimpleCaloEDM4hepEventAction_h
#define SimpleCaloEDM4hepEventAction_h
#include
"G4UserEventAction.hh"
#include
"G4Timer.hh"
#include
"globals.hh"
#include
<string>
namespace
podio
{
class
EventStore
;
class
ROOTWriter
;
}
namespace
edm4hep
{
class
SimCalorimeterHitCollection
;
}
class
SimpleCaloEDM4hepEventAction
:
public
G4UserEventAction
{
public:
SimpleCaloEDM4hepEventAction
();
~
SimpleCaloEDM4hepEventAction
();
virtual
void
BeginOfEventAction
(
const
G4Event
*
);
virtual
void
EndOfEventAction
(
const
G4Event
*
);
private:
G4int
fNevent
;
G4double
fDtime
;
G4int
fCalorimeterCollectionId
;
G4Timer
fTimerIntern
;
std
::
string
fFileName
=
{
"SimpleCaloEDM4hep.root"
}
;
podio
::
EventStore
*
fStore
=
{}
;
podio
::
ROOTWriter
*
fWriter
=
{}
;
edm4hep
::
SimCalorimeterHitCollection
*
fSHC
=
{}
;
};
#endif
src/SimpleCaloActionInitialization.cc
View file @
afaa5c28
...
...
@@ -31,6 +31,7 @@
#include
"SimpleCaloPrimaryGeneratorAction.hh"
#include
"SimpleCaloRunAction.hh"
#include
"SimpleCaloEventAction.hh"
#include
"SimpleCaloEDM4hepEventAction.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
...
...
@@ -58,7 +59,8 @@ void SimpleCaloActionInitialization::Build() const
{
SetUserAction
(
new
SimpleCaloPrimaryGeneratorAction
);
SetUserAction
(
new
SimpleCaloRunAction
);
SetUserAction
(
new
SimpleCaloEventAction
);
// SetUserAction(new SimpleCaloEventAction);
SetUserAction
(
new
SimpleCaloEDM4hepEventAction
);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
src/SimpleCaloEDM4hepEventAction.cc
0 → 100644
View file @
afaa5c28
///
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
/// \file SimpleCaloEDM4hepEventAction.cc
/// \brief Implementation of the SimpleCaloEDM4hepEventAction class
//
// Created by Joanna Weng 26.11.2004
#include
"SimpleCaloEDM4hepEventAction.hh"
#include
"SimpleCaloHit.hh"
#include
"G4EventManager.hh"
#include
"G4SDManager.hh"
#include
"G4UImanager.hh"
#include
"G4TrajectoryContainer.hh"
#include
"G4Event.hh"
#include
"G4SystemOfUnits.hh"
//std
#include
<iostream>
#include
<algorithm>
//Gflash
using
namespace
std
;
// podio specific includes
#include
"podio/EventStore.h"
#include
"podio/ROOTWriter.h"
// edm4hep
#include
"edm4hep/SimCalorimeterHitCollection.h"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
SimpleCaloEDM4hepEventAction
::
SimpleCaloEDM4hepEventAction
()
:
G4UserEventAction
(),
fNevent
(
0
),
fDtime
(
0.0
),
fCalorimeterCollectionId
(
-
1
)
{
fStore
=
new
podio
::
EventStore
;
fWriter
=
new
podio
::
ROOTWriter
(
fFileName
,
fStore
);
// create the collections to be written
// auto& mcps = store.create<edm4hep::MCParticleCollection>("MCParticles");
// writer.registerForWrite("MCParticles");
fSHC
=
&
fStore
->
create
<
edm4hep
::
SimCalorimeterHitCollection
>
(
"SimCalorimeterHits"
);
fWriter
->
registerForWrite
(
"SimCalorimeterHits"
);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
SimpleCaloEDM4hepEventAction
::~
SimpleCaloEDM4hepEventAction
()
{
if
(
fNevent
>
0
)
{
G4cout
<<
"Internal Real Elapsed Time /event is: "
<<
fDtime
/
fNevent
<<
G4endl
;
}
fWriter
->
finish
();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void
SimpleCaloEDM4hepEventAction
::
BeginOfEventAction
(
const
G4Event
*
evt
)
{
fTimerIntern
.
Start
();
G4cout
<<
" ------ Start SimpleCaloEDM4hepEventAction ----- "
<<
G4endl
;
fNevent
=
evt
->
GetEventID
();
G4cout
<<
" Start generating event Nr "
<<
fNevent
<<
G4endl
<<
G4endl
;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void
SimpleCaloEDM4hepEventAction
::
EndOfEventAction
(
const
G4Event
*
evt
)
{
fTimerIntern
.
Stop
();
G4cout
<<
G4endl
;
G4cout
<<
"******************************************"
;
G4cout
<<
G4endl
;
G4cout
<<
"Internal Real Elapsed Time is: "
<<
fTimerIntern
.
GetRealElapsed
();
G4cout
<<
G4endl
;
G4cout
<<
"Internal System Elapsed Time: "
<<
fTimerIntern
.
GetSystemElapsed
();
G4cout
<<
G4endl
;
G4cout
<<
"Internal GetUserElapsed Time: "
<<
fTimerIntern
.
GetUserElapsed
();
G4cout
<<
G4endl
;
G4cout
<<
"******************************************"
<<
G4endl
;
fDtime
+=
fTimerIntern
.
GetRealElapsed
();
G4cout
<<
" ------ SimpleCaloEDM4hepEventAction::End of event nr. "
<<
fNevent
<<
" -----"
<<
G4endl
;
G4SDManager
*
SDman
=
G4SDManager
::
GetSDMpointer
();
G4String
colNam
;
fCalorimeterCollectionId
=
SDman
->
GetCollectionID
(
colNam
=
"SimpleCaloCollection"
);
if
(
fCalorimeterCollectionId
<
0
)
return
;
G4HCofThisEvent
*
HCE
=
evt
->
GetHCofThisEvent
();
SimpleCaloHitsCollection
*
THC
=
0
;
G4double
totE
=
0
;
// Read out of the calo
THC
=
(
SimpleCaloHitsCollection
*
)(
HCE
->
GetHC
(
fCalorimeterCollectionId
));
if
(
THC
)
{
/// Hits in sensitive Detector
int
n_hit
=
THC
->
entries
();
// FIXME: create MCParticle here ...
// G4cout<<" " << n_hit<< " hits are stored in SimpleCaloHitsCollection "<<G4endl;
// G4PrimaryVertex* pvertex=evt->GetPrimaryVertex();
// ///Computing (x,y,z) of vertex of initial particles
// G4ThreeVector vtx=pvertex->GetPosition();
// G4PrimaryParticle* pparticle=pvertex->GetPrimary();
// // direction of the Shower
// G4ThreeVector mom=pparticle->GetMomentum()/pparticle->GetMomentum().mag();
/// For now simple convert all Hits in sensitive detector
for
(
int
i
=
0
;
i
<
n_hit
;
i
++
)
{
G4double
estep
=
(
*
THC
)[
i
]
->
GetEdep
()
/
GeV
;
if
(
estep
>
0.0
)
{
auto
hit
=
fSHC
->
create
()
;
hit
.
setCellID
(
(
*
THC
)[
i
]
->
GetLayerNum
()
)
;
// fixme: add x/y coordinates ....
hit
.
setEnergy
(
(
*
THC
)[
i
]
->
GetEdep
()
/
GeV
)
;
G4ThreeVector
hitpos
=
(
*
THC
)[
i
]
->
GetPos
();
G4ThreeVector
l
(
hitpos
.
x
(),
hitpos
.
y
(),
hitpos
.
z
());
hit
.
setPosition
(
{
(
float
)
hitpos
.
x
(),
(
float
)
hitpos
.
y
(),
(
float
)
hitpos
.
z
()
}
)
;
}
}
fWriter
->
writeEvent
();
fStore
->
clearCollections
();
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment