Skip to content
Snippets Groups Projects
Commit cb54836b authored by lintao@ihep.ac.cn's avatar lintao@ihep.ac.cn
Browse files

Merge branch 'master' into 'master'

The function of calculating absorbed dose/dose eq/Si-1MeV-neutron fluence/High-energy-hadron fluence

See merge request !8
parents b7f4f2ef 49ac9a0b
No related branches found
No related tags found
1 merge request!8The function of calculating absorbed dose/dose eq/Si-1MeV-neutron fluence/High-energy-hadron fluence
Pipeline #10373 passed with stage
in 3 minutes and 5 seconds
#!/usr/bin/env python
import os
import sys
# sys.exit(0)
from Gaudi.Configuration import *
##############################################################################
# Random Number Svc
##############################################################################
from Configurables import RndmGenSvc, HepRndm__Engine_CLHEP__RanluxEngine_
seed = [42]
# rndmengine = HepRndm__Engine_CLHEP__RanluxEngine_() # The default engine in Gaudi
rndmengine = HepRndm__Engine_CLHEP__HepJamesRandom_("RndmGenSvc.Engine") # The default engine in Geant4
rndmengine.SetSingleton = True
rndmengine.Seeds = seed
rndmgensvc = RndmGenSvc("RndmGenSvc")
rndmgensvc.Engine = rndmengine.name()
##############################################################################
# Event Data Svc
##############################################################################
from Configurables import k4DataSvc
dsvc = k4DataSvc("EventDataSvc")
##############################################################################
# Geometry Svc
##############################################################################
# geometry_option = "CepC_v4-onlyTracker.xml"
#geometry_option = "CepC_v4-onlyVXD.xml"
geometry_option = "CepC_v4.xml"
if not os.getenv("DETCEPCV4ROOT"):
print("Can't find the geometry. Please setup envvar DETCEPCV4ROOT." )
sys.exit(-1)
geometry_path = os.path.join(os.getenv("DETCEPCV4ROOT"), "compact", geometry_option)
if not os.path.exists(geometry_path):
print("Can't find the compact geometry file: %s"%geometry_path)
sys.exit(-1)
from Configurables import GeomSvc
geosvc = GeomSvc("GeomSvc")
geosvc.compact = geometry_path
##############################################################################
# Physics Generator
##############################################################################
from Configurables import GenAlgo
from Configurables import GtGunTool
from Configurables import StdHepRdr
from Configurables import SLCIORdr
from Configurables import HepMCRdr
from Configurables import GenPrinter
gun = GtGunTool("GtGunTool")
gun.Particles = ["mu-"]
gun.EnergyMins = [120.] # GeV
gun.EnergyMaxs = [120.] # GeV
gun.ThetaMins = [0] # rad; 45deg
gun.ThetaMaxs = [180.] # rad; 45deg
gun.PhiMins = [0] # rad; 0deg
gun.PhiMaxs = [0.] # rad; 360deg
gun.PositionXs = [0.]
gun.PositionYs = [0.]
gun.PositionZs = [0.]
# stdheprdr = StdHepRdr("StdHepRdr")
# stdheprdr.Input = "/cefs/data/stdhep/CEPC250/2fermions/E250.Pbhabha.e0.p0.whizard195/bhabha.e0.p0.00001.stdhep"
# lciordr = SLCIORdr("SLCIORdr")
# lciordr.Input = "/cefs/data/stdhep/lcio250/signal/Higgs/E250.Pbbh.whizard195/E250.Pbbh_X.e0.p0.whizard195/Pbbh_X.e0.p0.00001.slcio"
# hepmcrdr = HepMCRdr("HepMCRdr")
# hepmcrdr.Input = "example_UsingIterators.txt"
genprinter = GenPrinter("GenPrinter")
genalg = GenAlgo("GenAlgo")
genalg.GenTools = ["GtGunTool"]
# genalg.GenTools = ["StdHepRdr"]
# genalg.GenTools = ["StdHepRdr", "GenPrinter"]
# genalg.GenTools = ["SLCIORdr", "GenPrinter"]
# genalg.GenTools = ["HepMCRdr", "GenPrinter"]
##############################################################################
# Detector Simulation
##############################################################################
from Configurables import DetSimSvc
detsimsvc = DetSimSvc("DetSimSvc")
# from Configurables import ExampleAnaElemTool
# example_anatool = ExampleAnaElemTool("ExampleAnaElemTool")
from Configurables import DetSimAlg
detsimalg = DetSimAlg("DetSimAlg")
detsimalg.RandomSeeds = seed
if int(os.environ.get("VIS", 0)):
detsimalg.VisMacs = ["vis.mac"]
detsimalg.RunCmds = [
# "/tracking/verbose 1",
]
detsimalg.AnaElems = [
# example_anatool.name()
# "ExampleAnaElemTool"
"ExampleAnaDoseElemTool"
]
detsimalg.RootDetElem = "WorldDetElemTool"
from Configurables import ExampleAnaDoseElemTool
dosesimtool = ExampleAnaDoseElemTool("ExampleAnaDoseElemTool")
dosesimtool.Gridnbins = [450,1,1100]
dosesimtool.Coormin = [0,-0.5,-550]
dosesimtool.Coormax = [450,0.5,550]
dosesimtool.Regionhist = [20,1.e-12,10]
dosesimtool.filename = "testdose_"
dosesimtool.Dosecofffilename = "dosecoffe/"
dosesimtool.HEHadroncut = 0.02
from Configurables import CalorimeterSensDetTool
from Configurables import DriftChamberSensDetTool
from Configurables import TimeProjectionChamberSensDetTool
tpc_sensdettool = TimeProjectionChamberSensDetTool("TimeProjectionChamberSensDetTool")
tpc_sensdettool.TypeOption = 1
##############################################################################
# POD I/O
##############################################################################
from Configurables import PodioOutput
out = PodioOutput("outputalg")
out.filename = "test-dosesim.root"
out.outputCommands = ["keep *"]
##############################################################################
# ApplicationMgr
##############################################################################
#from Configurables import NTupleSvc
#ntsvc = NTupleSvc("NTupleSvc")
#ntsvc.Output = ["MyTuples DATAFILE='testout.root' OPT='NEW' TYP='ROOT'"]
from Configurables import ApplicationMgr
ApplicationMgr( TopAlg = [genalg, detsimalg, out],
EvtSel = 'NONE',
EvtMax = 10,
ExtSvc = [rndmengine, rndmgensvc, dsvc, geosvc],
OutputLevel=ERROR
)
......@@ -4,6 +4,7 @@ include(${Geant4_USE_FILE})
gaudi_add_module(DetSimAna
SOURCES src/Edm4hepWriterAnaElemTool.cpp
SOURCES src/ExampleAnaDoseElemTool.cpp
LINK DetSimInterface
DetSimSDLib
${DD4hep_COMPONENT_LIBRARIES}
......
This diff is collapsed.
#ifndef Edm4hepWriterAnaElemTool_h
#define Edm4hepWriterAnaElemTool_h
#include <map>
#include "GaudiKernel/AlgTool.h"
#include "k4FWCore/DataHandle.h"
#include "DetSimInterface/IAnaElemTool.h"
#include "DetSimInterface/CommonUserEventInfo.hh"
#include "DetSimInterface/CommonUserTrackInfo.hh"
#include "DetInterface/IGeomSvc.h"
#include "edm4hep/MCParticleCollection.h"
#include "edm4hep/SimTrackerHitCollection.h"
#include "edm4hep/SimCalorimeterHitCollection.h"
#include "edm4hep/CaloHitContributionCollection.h"
#include "GaudiKernel/INTupleSvc.h"
#include "GaudiKernel/NTuple.h"
#include "G4ThreeVector.hh"
#include <vector>
#include <fstream>
#include <string>
const G4int nbinscoeffdoseeqneu = 68;
const G4int nbinscoeffdoseeqproton = 33;
const G4int nbinscoeffdoseeqele = 49;
const G4int nbinscoeffdoseeqpos = 49;
const G4int nbinscoeffdoseeqhe = 24;
const G4int nbinscoeffdoseeqphoton = 64;
const G4int nbinscoeffdoseeqmup = 33;
const G4int nbinscoeffdoseeqmum = 33;
const G4int nbinscoeffdoseeqpip = 43;
const G4int nbinscoeffdoseeqpim = 43;
const G4int nbinscoeff1mevneueqfluenceneu = 1381;
const G4int nbinscoeff1mevneueqfluenceproton = 927;
const G4int nbinscoeff1mevneueqfluencepion = 900;
const G4int nbinscoeff1mevneueqfluenceele = 15;
class ExampleAnaDoseElemTool: public extends<AlgTool, IAnaElemTool> {
public:
using extends::extends;
/// IAnaElemTool interface
// Run
virtual void BeginOfRunAction(const G4Run*) override;
virtual void EndOfRunAction(const G4Run*) override;
// Event
virtual void BeginOfEventAction(const G4Event*) override;
virtual void EndOfEventAction(const G4Event*) override;
// Tracking
virtual void PreUserTrackingAction(const G4Track*) override;
virtual void PostUserTrackingAction(const G4Track*) override;
// Stepping
virtual void UserSteppingAction(const G4Step*) override;
/// Overriding initialize and finalize
StatusCode initialize() override;
StatusCode finalize() override;
private:
bool verboseOutput = false;
Gaudi::Property<std::vector<int>> m_gridnbins{this, "Gridnbins"};
Gaudi::Property<std::vector<double>> m_coormin{this, "Coormin"};
Gaudi::Property<std::vector<double>> m_coormax{this, "Coormax"};
Gaudi::Property<std::vector<double>> m_regionhist{this, "Regionhist"};
Gaudi::Property<double> m_hehadcut{this, "HEHadroncut"};
Gaudi::Property<std::string> m_filename{this, "filename"};
Gaudi::Property<std::string> m_dosecoefffilename{this, "Dosecofffilename","Simulation/DetSimAna/src/dosecoffe/"};
std::vector<G4double> fVector; //absorbed dose
std::vector<G4double> fnneu; //track length
std::vector<G4double> fdoseeqright; //dose eq
std::vector<G4double> f1mevnfluen; //1mev neutron equivalent fluence
std::vector<G4double> fhehadfluen; //high energy hadron fluence
std::vector<G4int> fdet1;
std::vector<G4int> fair;
G4ThreeVector nbins,regionhist,coormin,coormax,vecwidth;
G4double hehadcut;
void Writefile(std::string);
void Setdosevalue(const G4Step* );
void Calcudose(std::vector<G4double>& fexample, const G4int constnbins, const G4double coeffexample[][2], const G4int ijkbin[], const G4double inputtracklength, const G4double inputkinenergy);
void Readcoffe(std::string filepath, std::string filename, const G4int constnbins, G4double coeffexample[][2]);
void Initialize();
void Preparecoeff(const G4ThreeVector, const G4ThreeVector , const G4ThreeVector, const G4ThreeVector, const std::string, const G4double);
static int cmppair(const std::pair< G4ThreeVector,G4double > p1, const std::pair< G4ThreeVector,G4double > p2) {return p1.second<p2.second;};
G4double coeffneu[nbinscoeffdoseeqneu][2];
G4double coeffproton[nbinscoeffdoseeqproton][2];
G4double coeffele[nbinscoeffdoseeqele][2];
G4double coeffpos[nbinscoeffdoseeqpos][2];
G4double coeffhe[nbinscoeffdoseeqhe][2];
G4double coeffphoton[nbinscoeffdoseeqphoton][2];
G4double coeffmup[nbinscoeffdoseeqmup][2];
G4double coeffmum[nbinscoeffdoseeqmum][2];
G4double coeffpip[nbinscoeffdoseeqpip][2];
G4double coeffpim[nbinscoeffdoseeqpim][2];
G4double coeff1mevneueqfluenceneu[nbinscoeff1mevneueqfluenceneu][2];
G4double coeff1mevneueqfluenceproton[nbinscoeff1mevneueqfluenceproton][2];
G4double coeff1mevneueqfluencepion[nbinscoeff1mevneueqfluencepion][2];
G4double coeff1mevneueqfluenceele[nbinscoeff1mevneueqfluenceele][2];
std::ifstream m_inputFile_doseeqneu;
};
#endif
......@@ -12,6 +12,7 @@ RunAction::~RunAction() {
}
void
RunAction::BeginOfRunAction(const G4Run* aRun)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment