Commit 46f8c50b authored by Frank Gaede's avatar Frank Gaede
Browse files

initial commit

parent 95f4a308
#----------------------------------------------------------------------------
# Setup the project
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(simplecalo)
#----------------------------------------------------------------------------
# Find Geant4 package, activating all available UI and Vis drivers by default
# You can set WITH_GEANT4_UIVIS to OFF via the command line or ccmake/cmake-gui
# to build a batch mode only executable
#
option(WITH_GEANT4_UIVIS "Build example with Geant4 UI and Vis drivers" ON)
if(WITH_GEANT4_UIVIS)
find_package(Geant4 REQUIRED ui_all vis_all)
else()
find_package(Geant4 REQUIRED)
endif()
#----------------------------------------------------------------------------
# Setup Geant4 include directories and compile definitions
#
include(${Geant4_USE_FILE})
#----------------------------------------------------------------------------
# Locate sources and headers for this project
#
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_executable(SimpleCalo SimpleCalo.cc ${sources} ${headers})
target_link_libraries(SimpleCalo ${Geant4_LIBRARIES} )
#----------------------------------------------------------------------------
# Copy all scripts to the build directory, i.e. the directory in which we
# build gflash. This is so that we can run the executable directly because it
# relies on these scripts being in the current working directory.
#
set(gflash_SCRIPTS
test.mac vis.mac
)
foreach(_script ${gflash_SCRIPTS})
configure_file(
${PROJECT_SOURCE_DIR}/${_script}
${PROJECT_BINARY_DIR}/${_script}
COPYONLY
)
endforeach()
#----------------------------------------------------------------------------
# Add program to the project targets
# (this avoids the need of typing the program name after make)
#
add_custom_target(simplecalo DEPENDS SimpleCalo)
#----------------------------------------------------------------------------
# Install the executable to 'bin' directory under CMAKE_INSTALL_PREFIX
#
set( CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR})
install(TARGETS SimpleCalo DESTINATION bin)
# --------------------------------------------------------------
# GNUmakefile for examples module. Gabriele Cosmo, 06/04/98.
# --------------------------------------------------------------
name := SimpleCalo
G4TARGET := $(name)
G4EXLIB := true
ifndef G4INSTALL
G4INSTALL = ../../../../..
endif
.PHONY: all
all: lib bin
include $(G4INSTALL)/config/architecture.gmk
include $(G4INSTALL)/config/binmake.gmk
# SimpleCalo
Simple calorimeter simulation with Geant4 and GFlash.
\ No newline at end of file
# SimpleCalo : simple program to run a calorimeter simulation with Geant4 and GFlash
- author: F.Gaede, DESY
- date: Oct 2021
- based on the `$Geant4/10.06.p02/examples/extended/parameterisations/build/gflash/gflash1`
//
// ********************************************************************
// * 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 SimpleCalo.cc
/// \brief Main program of the parameterisations/gflash/gflash1 example
//
// Created by Joanna Weng 26.11.2004
// G4 includes
#include "G4Types.hh"
#include "G4ios.hh"
#include "G4Timer.hh"
#include "G4UImanager.hh"
#ifdef G4MULTITHREADED
#include "G4MTRunManager.hh"
#else
#include "G4RunManager.hh"
#endif
// my project
#include "SimpleCaloDetectorConstruction.hh"
#include "SimpleCaloActionInitialization.hh"
#include "FTFP_BERT.hh"
#include "G4FastSimulationPhysics.hh"
#include "G4VisExecutive.hh"
#include "G4UIExecutive.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
int main(int argc,char** argv)
{
// Instantiate G4UIExecutive if interactive mode
G4UIExecutive* ui = nullptr;
if ( argc == 1 ) {
ui = new G4UIExecutive(argc, argv);
}
// timer to see GFlash performance
G4Timer timer;
timer.Start();
G4cout<<"+-------------------------------------------------------+"<<G4endl;
G4cout<<"| |"<<G4endl;
G4cout<<"| This is an example of Shower |"<<G4endl;
G4cout<<"| Parameterization with GFLASH |"<<G4endl;
G4cout<<"+-------------------------------------------------------+"<<G4endl;
#ifdef G4MULTITHREADED
G4MTRunManager * runManager = new G4MTRunManager;
runManager->SetNumberOfThreads(1);
G4cout<<"+-------------------------------------------------------+"<<G4endl;
G4cout<<"| Constructing MT run manager |"<<G4endl;
G4cout<<"+-------------------------------------------------------+"<<G4endl;
#else
G4RunManager * runManager = new G4RunManager;
G4cout<<"+-------------------------------------------------------+"<<G4endl;
G4cout<<"| Constructing sequential run manager |"<<G4endl;
G4cout<<"+-------------------------------------------------------+"<<G4endl;
#endif
// UserInitialization classes (mandatory)
G4cout<<"# GFlash Example: Detector Construction"<<G4endl;
runManager->SetUserInitialization(new SimpleCaloDetectorConstruction);
// G4cout<<"# GFlash Example: Physics "<<G4endl;
// -- Select a physics list:
G4VModularPhysicsList* physicsList = new FTFP_BERT();
// -- Create a fast simulation physics constructor, used to augment
// -- the above physics list to allow for fast simulation:
G4FastSimulationPhysics* fastSimulationPhysics = new G4FastSimulationPhysics();
// -- We now configure the fastSimulationPhysics object.
// -- The gflash model (GFlashShowerModel, see SimpleCaloDetectorConstruction.cc)
// -- is applicable to e+ and e- : we augment the physics list for these
// -- particles (by adding a G4FastSimulationManagerProcess with below's
// -- calls), this will make the fast simulation to be activated:
fastSimulationPhysics->ActivateFastSimulation("e-");
fastSimulationPhysics->ActivateFastSimulation("e+");
// -- Register this fastSimulationPhysics to the physicsList,
// -- when the physics list will be called by the run manager
// -- (will happen at initialization of the run manager)
// -- for physics process construction, the fast simulation
// -- configuration will be applied as well.
physicsList->RegisterPhysics( fastSimulationPhysics );
runManager->SetUserInitialization(physicsList);
// Action initialization:
runManager->SetUserInitialization(new SimpleCaloActionInitialization);
G4VisManager* visManager = new G4VisExecutive;
visManager->Initialize();
G4UImanager* UImanager = G4UImanager::GetUIpointer();
UImanager->ApplyCommand("/run/verbose 0");
runManager->Initialize();
UImanager->ApplyCommand("/Step/Verbose 0");
if (ui) // Define UI terminal for interactive mode
{
UImanager->ApplyCommand("/control/execute vis.mac");
ui->SessionStart();
delete ui;
}
else // Batch mode
{
G4String s=*(argv+1);
UImanager->ApplyCommand("/control/execute "+s);
}
delete visManager;
delete runManager;
timer.Stop();
G4cout << G4endl;
G4cout << "******************************************";
G4cout << G4endl;
G4cout << "Total Real Elapsed Time is: "<< timer.GetRealElapsed();
G4cout << G4endl;
G4cout << "Total System Elapsed Time: " << timer.GetSystemElapsed();
G4cout << G4endl;
G4cout << "Total GetUserElapsed Time: " << timer.GetUserElapsed();
G4cout << G4endl;
G4cout << "******************************************";
G4cout << G4endl;
return 0;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
File added
//
// ********************************************************************
// * 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 SimpleCaloActionInitialization.hh
/// \brief Definition of the SimpleCaloActionInitialization class
#ifndef SimpleCaloActionInitialization_h
#define SimpleCaloActionInitialization_h 1
#include "G4VUserActionInitialization.hh"
/// Action initialization class.
///
class SimpleCaloActionInitialization : public G4VUserActionInitialization
{
public:
SimpleCaloActionInitialization();
virtual ~SimpleCaloActionInitialization();
virtual void BuildForMaster() const;
virtual void Build() const;
};
#endif
//
// ********************************************************************
// * 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 SimpleCaloDetectorConstruction.hh
/// \brief Definition of the SimpleCaloDetectorConstruction class
//
#ifndef SimpleCaloDetectorConstruction_h
#define SimpleCaloDetectorConstruction_h 1
#include "G4VUserDetectorConstruction.hh"
#include "globals.hh"
class G4LogicalVolume;
class G4VPhysicalVolume;
class G4Region;
class GFlashHomoShowerParameterisation;
class GFlashShowerModel;
class GFlashHitMaker;
class GFlashParticleBounds;
class SimpleCaloDetectorConstruction : public G4VUserDetectorConstruction
{
public:
SimpleCaloDetectorConstruction();
~SimpleCaloDetectorConstruction();
virtual G4VPhysicalVolume* Construct();
virtual void ConstructSDandField();
const G4VPhysicalVolume* GetCristal(int aNumCrystal)
{return fCrystalPhys[aNumCrystal];};
private:
G4LogicalVolume* fCrystalLog;
G4VPhysicalVolume* fCrystalPhys[100];
G4Region* fRegion;
static G4ThreadLocal GFlashShowerModel* fFastShowerModel;
static G4ThreadLocal GFlashHomoShowerParameterisation* fParameterisation;
static G4ThreadLocal GFlashParticleBounds* fParticleBounds;
static G4ThreadLocal GFlashHitMaker* fHitMaker;
};
#endif
//
// ********************************************************************
// * 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 SimpleCaloEventAction.hh
/// \brief Definition of the SimpleCaloEventAction class
//
#ifndef SimpleCaloEventAction_h
#define SimpleCaloEventAction_h
#include "G4UserEventAction.hh"
#include "G4Timer.hh"
#include "globals.hh"
class SimpleCaloEventAction: public G4UserEventAction {
public:
SimpleCaloEventAction();
~SimpleCaloEventAction();
virtual void BeginOfEventAction(const G4Event*);
virtual void EndOfEventAction(const G4Event*);
private:
G4int fNevent;
G4double fDtime;
G4int fCalorimeterCollectionId;
G4Timer fTimerIntern;
};
#endif
//
// ********************************************************************
// * 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 SimpleCaloHit.hh
/// \brief Definition of the SimpleCaloHit class
//
#ifndef SimpleCaloHit_h
#define SimpleCaloHit_h 1
#include "G4VHit.hh"
#include "G4THitsCollection.hh"
#include "G4Allocator.hh"
#include "G4ThreeVector.hh"
#include "G4RotationMatrix.hh"
class G4LogicalVolume;
class SimpleCaloHit : public G4VHit
{
public:
SimpleCaloHit();
SimpleCaloHit(G4LogicalVolume* logVol);
~SimpleCaloHit();
SimpleCaloHit(const SimpleCaloHit &right);
const SimpleCaloHit& operator=(const SimpleCaloHit &right);
G4bool operator==(const SimpleCaloHit &right) const;
inline void *operator new(size_t);
inline void operator delete(void *aHit);
void *operator new(size_t,void*p){return p;}
#ifndef G4NOT_ISO_DELETES
void operator delete(void *,void*){}
#endif
virtual void Draw();
virtual void Print();
private:
G4double fEdep;
G4ThreeVector fPos;
G4int fCrystalNumber;
G4ThreeVector fStart;
G4RotationMatrix fRot;
const G4LogicalVolume* fLogV;
public:
inline void SetEdep(G4double de)
{ fEdep = de; };
inline void AddEdep(G4double de)
{ fEdep += de; };
inline G4double GetEdep()
{ return fEdep; };
inline void SetPos(G4ThreeVector xyz)
{ fPos = xyz; };
inline G4int GetCrystalNum()
{ return fCrystalNumber; };
inline void SetCrystalNum(G4int num)
{ fCrystalNumber=num; };
inline G4ThreeVector GetPos()
{ return fPos; };
inline void SetStart(G4ThreeVector xyz)
{ fStart = xyz; };
inline G4ThreeVector GetStart()
{ return fStart; };
inline void SetRot(G4RotationMatrix rmat)
{ fRot = rmat; };
inline G4RotationMatrix GetRot()
{ return fRot; };
inline const G4LogicalVolume * GetLogV()
{ return fLogV; };
};
typedef G4THitsCollection<SimpleCaloHit> SimpleCaloHitsCollection;
extern G4ThreadLocal G4Allocator<SimpleCaloHit>* SimpleCaloHitAllocator;
inline void* SimpleCaloHit::operator new(size_t)
{
if(!SimpleCaloHitAllocator) SimpleCaloHitAllocator = new G4Allocator<SimpleCaloHit>;
return (void *) SimpleCaloHitAllocator->MallocSingle();
}
inline void SimpleCaloHit::operator delete(void *aHit)
{
SimpleCaloHitAllocator->FreeSingle((SimpleCaloHit*) aHit);
}
#endif
//
// ********************************************************************
// * 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 SimpleCaloHitsCollection.hh
/// \brief Definition of the SimpleCaloHitsCollection class
//
#ifndef SimpleCaloHitsCollection_h
#define SimpleCaloHitsCollection_h
#include "G4THitsCollection.hh"
class SimpleCaloHit;
typedef G4THitsCollection<SimpleCaloHit> SimpleCaloHitsCollection;
#endif
//
// ********************************************************************
// * 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 *