Skip to content
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

add TrackHeedSimTool for DC cell simulation #248

Merged
merged 8 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Detector/DetDriftChamber/compact/det.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@


<define>
<constant name="tracker_region_rmax" value="1723*mm" />
<constant name="tracker_region_zmax" value="3050*mm" />
<constant name="world_size" value="2226*mm"/>
<constant name="world_x" value="world_size"/>
<constant name="world_y" value="world_size"/>
Expand Down
206 changes: 206 additions & 0 deletions Examples/options/tut_detsim_SDT_Heed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
#!/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 = "det.xml"
#geometry_option = "CepC_v4.xml"
det_root = "DETDRIFTCHAMBERROOT"
#det_root = "DETCEPCV4ROOT"#"DETDRIFTCHAMBERROOT"
if not os.getenv(det_root):
print("Can't find the geometry. Please setup envvar %s."%det_root )
sys.exit(-1)

geometry_path = os.path.join(os.getenv(det_root), "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")
print('geometry_path=',geometry_path)
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 = ["pi+"]
# gun.EnergyMins = [100.] # GeV
# gun.EnergyMaxs = [100.] # GeV

gun.Particles = ["e-"]

# gun.PositionXs = [100.] # mm
# gun.PositionYs = [100.] # mm
# gun.PositionZs = [0.] # mm


gun.EnergyMins = [10] # GeV
gun.EnergyMaxs = [10] # GeV

gun.ThetaMins = [80] # rad; 45deg
gun.ThetaMaxs = [90.] # rad; 45deg

gun.PhiMins = [0] # rad; 0deg
gun.PhiMaxs = [360.] # rad; 360deg

# 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",
]

from Configurables import DummyFastSimG4Tool
dummy_fastsim_tool = DummyFastSimG4Tool("DummyFastSimG4Tool")

detsimalg.FastSimG4Tools = [
# "DummyFastSimG4Tool"
]

detsimalg.AnaElems = [
# example_anatool.name()
# "ExampleAnaElemTool"
"Edm4hepWriterAnaElemTool"
]
detsimalg.RootDetElem = "WorldDetElemTool"

from Configurables import AnExampleDetElemTool
example_dettool = AnExampleDetElemTool("AnExampleDetElemTool")

from Configurables import CalorimeterSensDetTool
from Configurables import DriftChamberSensDetTool

calo_sensdettool = CalorimeterSensDetTool("CalorimeterSensDetTool")
driftchamber_sensdettool = DriftChamberSensDetTool("DriftChamberSensDetTool")

#dedxoption = "DummyDedxSimTool"
#dedxoption = "BetheBlochEquationDedxSimTool"
dedxoption = "TrackHeedSimTool"

driftchamber_sensdettool.DedxSimTool = dedxoption

from Configurables import DummyDedxSimTool
from Configurables import BetheBlochEquationDedxSimTool
from Configurables import TrackHeedSimTool

if dedxoption == "DummyDedxSimTool":
dedx_simtool = DummyDedxSimTool("DummyDedxSimTool")
elif dedxoption == "BetheBlochEquationDedxSimTool":
dedx_simtool = BetheBlochEquationDedxSimTool("BetheBlochEquationDedxSimTool")
dedx_simtool.material_Z = 2
dedx_simtool.material_A = 4
dedx_simtool.scale = 10
dedx_simtool.resolution = 0.0001
elif dedxoption == "TrackHeedSimTool":
dedx_simtool = TrackHeedSimTool("TrackHeedSimTool")
dedx_simtool.only_primary = False#True
dedx_simtool.use_max_step = True#True
dedx_simtool.max_step = 1#mm
#dedx_simtool.he = 50
#dedx_simtool.isob = 50
#dedx_simtool.gas_file ="/junofs/users/wxfang/MyGit/tmp/check_G4FastSim_20210121/CEPCSW/Digitisers/DigiGarfield/He_50_isobutane_50.gas"
dedx_simtool.he = 90
dedx_simtool.isob = 10
#dedx_simtool.gas_file ="/junofs/users/wxfang/MyGit/tmp/check_G4FastSim_20210121/CEPCSW/Digitisers/DigiGarfield/he_90_isobutane_10.gas"
#dedx_simtool.IonMobility_file ="/junofs/users/wxfang/MyGit/tmp/check_G4FastSim_20210121/CEPCSW/Digitisers/DigiGarfield/IonMobility_He+_He.txt"
dedx_simtool.gas_file ="he_90_isobutane_10.gas"
dedx_simtool.IonMobility_file ="IonMobility_He+_He.txt"
dedx_simtool.save_mc = True##IF this is False then ...
dedx_simtool.debug = False
dedx_simtool.sim_pulse = True
#dedx_simtool.model='/junofs/users/wxfang/MyGit/tmp/fork_cepcsw_20220418/CEPCSW/Digitisers/SimCurrentONNX/src/model_90He10C4H10_18mm.onnx'
dedx_simtool.model='model_90He10C4H10_18mm.onnx'
dedx_simtool.batchsize = 100

##############################################################################
# POD I/O
##############################################################################
from Configurables import PodioOutput
out = PodioOutput("outputalg")
out.filename = "detsim_heed.root"
out.outputCommands = ["keep *"]

##############################################################################
# ApplicationMgr
##############################################################################

from Configurables import ApplicationMgr
ApplicationMgr( TopAlg = [genalg, detsimalg, out],
EvtSel = 'NONE',
EvtMax = 20,
ExtSvc = [rndmengine, rndmgensvc, dsvc, geosvc],
OutputLevel=INFO
)
6 changes: 5 additions & 1 deletion Simulation/DetSimAna/src/Edm4hepWriterAnaElemTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Edm4hepWriterAnaElemTool::BeginOfRunAction(const G4Run*) {
} else {
error() << "Failed to find GeomSvc." << endmsg;
}

}

void
Expand Down Expand Up @@ -87,14 +88,17 @@ Edm4hepWriterAnaElemTool::BeginOfEventAction(const G4Event* anEvent) {
// reset
m_track2primary.clear();

auto SimPIonCol = m_SimPrimaryIonizationCol.createAndPut();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @wenxingfang , thank you for your update. My last question: do you think that we can also move this part to the TrackHeedSimTool? Because I see you had to const_cast the collection. If you create it in the same tool, then I think you don't need to cast.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mirguest , I don't know if there is a way to judge if this G4 simulation step is the beginning of an event in TrackHeedSimTool, because m_SimPrimaryIonizationCol.createAndPut(); should be done at the beginning of an event. Do you have any idea?


}

void
Edm4hepWriterAnaElemTool::EndOfEventAction(const G4Event* anEvent) {

msg() << "mcCol size (after simulation) : " << mcCol->size() << endmsg;
// save all data

auto SimPrimaryIonizationCol = m_SimPrimaryIonizationCol.get();
//msg() << "SimPrimaryIonizationCol size ="<<SimPrimaryIonizationCol->size()<<endmsg;
// create collections.
auto trackercols = m_trackerCol.createAndPut();
auto calorimetercols = m_calorimeterCol.createAndPut();
Expand Down
3 changes: 3 additions & 0 deletions Simulation/DetSimAna/src/Edm4hepWriterAnaElemTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "edm4hep/SimTrackerHitCollection.h"
#include "edm4hep/SimCalorimeterHitCollection.h"
#include "edm4hep/CaloHitContributionCollection.h"
#include "edm4hep/SimPrimaryIonizationClusterCollection.h"

class Edm4hepWriterAnaElemTool: public extends<AlgTool, IAnaElemTool> {

Expand Down Expand Up @@ -129,6 +130,8 @@ class Edm4hepWriterAnaElemTool: public extends<AlgTool, IAnaElemTool> {
"DriftChamberHitsCollection",
Gaudi::DataHandle::Writer, this};

// for ionized electron
DataHandle<edm4hep::SimPrimaryIonizationClusterCollection> m_SimPrimaryIonizationCol{"SimPrimaryIonizationClusterCollection", Gaudi::DataHandle::Writer, this};

private:
// in order to associate the hit contribution with the primary track,
Expand Down
16 changes: 16 additions & 0 deletions Simulation/DetSimDedx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@

find_package(Geant4 REQUIRED ui_all vis_all)
include(${Geant4_USE_FILE})
find_package(Garfield REQUIRED)
message(Garfield::Garfield)
message("libonnxruntime ${OnnxRuntime_LIBRARY}")
message("libonnxruntime include ${OnnxRuntime_INCLUDE_DIR}")
find_package(OnnxRuntime REQUIRED)

message("libonnxruntime ${OnnxRuntime_LIBRARY}")
gaudi_add_module(DetSimDedx
SOURCES src/DummyDedxSimTool.cpp
src/BetheBlochEquationDedxSimTool.cpp
src/GFDndxSimTool.cpp
src/TrackHeedSimTool.cpp

LINK DetSimInterface
DetInterface
DetSegmentation
${DD4hep_COMPONENT_LIBRARIES}
Gaudi::GaudiKernel
EDM4HEP::edm4hep EDM4HEP::edm4hepDict
k4FWCore::k4FWCore
Garfield::Garfield
OnnxRuntime
#${OnnxRuntime_LIBRARY}
#/cvmfs/sft.cern.ch/lcg/views/LCG_103/x86_64-centos7-gcc11-opt/lib/libonnxruntime.so
${CLHEP_LIBRARIES}

)

Loading
Loading