Skip to content

Commit fa7204f

Browse files
authored
Merge pull request #268 from mirguest/master
Sync from gitlab 2023-03-17
2 parents 8408ec0 + b37737a commit fa7204f

File tree

4 files changed

+377
-0
lines changed

4 files changed

+377
-0
lines changed

.ci/gitlab/setup-gitlab-runner.sh

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/bin/bash
2+
############################################
3+
# Description:
4+
# Manage the gitlab runners
5+
# Usage:
6+
# $ ./setup-gitlab-runner new <TOKEN>
7+
# $ ./setup-gitlab-runner start
8+
#
9+
# Register in crontab:
10+
#
11+
# */10 * * * * $HOME/setup-github-runner.sh start >& /tmp/$USER/github-runner/start.log
12+
#
13+
# Author: Tao Lin <lintao AT ihep.ac.cn>
14+
############################################
15+
16+
#############################################
17+
# Configuration
18+
#############################################
19+
export RUNNER_TOP_DIR=/tmp/$USER/gitlab-runner
20+
export SINGULARITY_BINDPATH=/cvmfs
21+
export RUNNER_URL=https://code.ihep.ac.cn
22+
23+
[ -d "$RUNNER_TOP_DIR" ] || mkdir $RUNNER_TOP_DIR
24+
25+
#############################################
26+
# Create a new gitlab runner (glr)
27+
#############################################
28+
29+
# ./gitlab-runner register --url https://code.ihep.ac.cn --token XXXXXX
30+
31+
function glr-preq() {
32+
# if $HOME/gitlab-runner exists
33+
if [ -f "$HOME/gitlab-runner" ]; then
34+
cp $HOME/gitlab-runner .
35+
else
36+
curl -L --output gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
37+
fi
38+
39+
chmod +x gitlab-runner
40+
41+
}
42+
43+
function glr-new() {
44+
local runner_url=$1; shift
45+
local token=$1; shift
46+
local executor=${1:-shell}; shift
47+
local shell=${1:-bash}; shift
48+
49+
pushd $RUNNER_TOP_DIR
50+
51+
# check if gitlab-runner exists
52+
if [ ! -f gitlab-runner ]; then
53+
glr-preq
54+
fi
55+
56+
./gitlab-runner register --url $runner_url --token $token --executor $executor --shell $shell
57+
58+
popd
59+
}
60+
61+
function new() {
62+
local token=$1; shift
63+
if [ -z "$token" ]; then
64+
echo "Please pass the token to this script" 1>&2
65+
exit -1
66+
fi
67+
glr-new $RUNNER_URL $token
68+
69+
}
70+
71+
#############################################
72+
# Create a new gitlab runner (glr)
73+
#############################################
74+
75+
function glr-start() {
76+
local glr=gitlab-runner
77+
78+
pushd $RUNNER_TOP_DIR
79+
80+
apptainer instance start ~/github-runner.sif ${glr}
81+
apptainer run instance://${glr} bash -c "./gitlab-runner run -c ./config.toml &"
82+
83+
popd
84+
}
85+
86+
function start() {
87+
glr-start
88+
}
89+
90+
#############################################
91+
# Command line options
92+
#############################################
93+
94+
cmd=$1; shift
95+
if [ -z "$cmd" ]; then
96+
echo "Please specify the command to be invoked" 1>&2
97+
exit -1
98+
fi
99+
100+
case $cmd in
101+
new)
102+
new $*
103+
;;
104+
start)
105+
start $*
106+
;;
107+
*)
108+
echo "Unknown command '$cmd'" 1>&2
109+
;;
110+
esac

.gitlab-ci.yml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
##############################################################################
2+
# CI for CEPCSW at IHEP GitLab
3+
##############################################################################
4+
5+
workflow:
6+
rules:
7+
# These 3 rules from https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Workflows/MergeRequest-Pipelines.gitlab-ci.yml
8+
# Run on merge requests
9+
- if: $CI_MERGE_REQUEST_IID
10+
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
11+
# Run on tags
12+
- if: $CI_COMMIT_TAG
13+
# Run when called from an upstream pipeline https://docs.gitlab.com/ee/ci/pipelines/downstream_pipelines.html?tab=Multi-project+pipeline#use-rules-to-control-downstream-pipeline-jobs
14+
- if: $CI_PIPELINE_SOURCE == 'pipeline'
15+
- if: $CI_PIPELINE_SOURCE == 'parent-child'
16+
# Run on commits to the default branch
17+
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
18+
# The last rule above blocks manual and scheduled pipelines on non-default branch. The rule below allows them:
19+
- if: $CI_PIPELINE_SOURCE == "schedule"
20+
# Run if triggered from Web using 'Run Pipelines'
21+
- if: $CI_PIPELINE_SOURCE == "web"
22+
# Run if triggered from WebIDE
23+
- if: $CI_PIPELINE_SOURCE == "webide"
24+
25+
26+
27+
stages:
28+
- build
29+
# - test
30+
31+
##############################################################################
32+
# Build Template
33+
##############################################################################
34+
.build_template:
35+
stage: build
36+
variables:
37+
LCG_RELEASE:
38+
CEPCSW_BLDTOOL: ninja
39+
script:
40+
- bash ./.build.ci.sh
41+
42+
43+
##############################################################################
44+
# Build CentOS 7 (LCG)
45+
##############################################################################
46+
build:lcg:el7:
47+
extends: .build_template
48+
variables:
49+
LCG_RELEASE: LCG
50+
tags:
51+
- centos7
52+
53+
##############################################################################
54+
# Build CentOS 7 (KEY4HEP)
55+
##############################################################################
56+
# build:k4:el7:
57+
# extends: .build_template
58+
# variables:
59+
# LCG_RELEASE: KEY4HEP_STACK
60+
# tags:
61+
# - centos7
62+

Examples/options/detsim_tracker.py

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env python
2+
#Author: Zhan Li <[email protected]>
3+
#Created [2024-03-07 Thu 14:53]
4+
5+
import os
6+
import sys
7+
8+
import Gaudi.Configuration
9+
from Configurables import RndmGenSvc, HepRndm__Engine_CLHEP__RanluxEngine_, k4DataSvc, GeomSvc
10+
from Configurables import TimeProjectionChamberSensDetTool
11+
from Configurables import GenAlgo
12+
from Configurables import GtGunTool
13+
from Configurables import StdHepRdr
14+
from Configurables import SLCIORdr
15+
from Configurables import HepMCRdr
16+
from Configurables import GenPrinter
17+
from Configurables import GtBeamBackgroundTool
18+
from Configurables import DetSimSvc
19+
from Configurables import DetSimAlg
20+
from Configurables import AnExampleDetElemTool
21+
from Configurables import PodioOutput
22+
from Configurables import ApplicationMgr
23+
24+
seed = [42]
25+
26+
rndmengine = Gaudi.Configuration.HepRndm__Engine_CLHEP__HepJamesRandom_("RndmGenSvc.Engine")
27+
rndmengine.SetSingleton = True
28+
rndmengine.Seeds = seed
29+
30+
rndmgensvc = RndmGenSvc("RndmGenSvc")
31+
rndmgensvc.Engine = rndmengine.name()
32+
33+
34+
dsvc = k4DataSvc("EventDataSvc")
35+
#geometry_option = "CepC_v4-onlyVXD.xml"
36+
geometry_option = "CepC_v4_onlyTracker.xml"
37+
#geometry_option = "CepC_v4.xml"
38+
39+
geometry_path = os.path.join(os.getenv("DETCEPCV4ROOT"), "compact", geometry_option)
40+
geosvc = GeomSvc("GeomSvc")
41+
geosvc.compact = geometry_path
42+
43+
#Previously I do not have these 2 lines
44+
tpc_sensdettool = TimeProjectionChamberSensDetTool("TimeProjectionChamberSensDetTool")
45+
tpc_sensdettool.TypeOption = 1
46+
47+
48+
# Physics Generator
49+
bg = GtBeamBackgroundTool("GtBeamBackgroundTool")
50+
bg.InputFileMap = {"default":"/scratchfs/atlas/lizhan/cepc/CEPCSW/ToCEPCSWsingle.out"}
51+
#bg.InputFileMap = {"default":"/cefs/higgs/shihy/tools/CEPCSW/CEPCSW/Test/0/ToCEPCSW-1.out"}
52+
bg.InputBeamEnergyMap = {"default":120}
53+
bg.RotationAlongYMap = {"default":16.5e-3}
54+
55+
56+
genprinter = GenPrinter("GenPrinter")
57+
58+
genalg = GenAlgo("GenAlgo")
59+
genalg.GenTools = ["GtBeamBackgroundTool"]
60+
61+
detsimsvc = DetSimSvc("DetSimSvc")
62+
63+
detsimalg = DetSimAlg("DetSimAlg")
64+
detsimalg.RandomSeeds = seed
65+
66+
67+
detsimalg.RunCmds = []
68+
detsimalg.AnaElems = [
69+
"Edm4hepWriterAnaElemTool"
70+
]
71+
detsimalg.RootDetElem = "WorldDetElemTool"
72+
73+
example_dettool = AnExampleDetElemTool("AnExampleDetElemTool")
74+
75+
76+
# POD I/O
77+
out = PodioOutput("outputalg")
78+
out.filename = "test-SIT.root"
79+
out.outputCommands = ["keep *"]
80+
81+
ApplicationMgr( TopAlg = [genalg, detsimalg, out],
82+
EvtSel = 'NONE',
83+
EvtMax = 1,
84+
ExtSvc = [rndmengine, rndmgensvc, dsvc, geosvc],
85+
)

Examples/options/tracker_analysis.py

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/usr/bin/env python
2+
#Author: Zhan Li <[email protected]>
3+
#Created [2024-03-07 Thu 14:53]
4+
5+
import ROOT
6+
import math
7+
8+
#read
9+
#path1="/scratchfs/atlas/lizhan/cepc/CEPCSW/test-onlyVXD-single.root"
10+
#path1="/scratchfs/atlas/lizhan/cepc/CEPCSW/test-detsim10.root"
11+
12+
def GetVXDHitMapFromFile(infile_name,out_file_name):
13+
file = ROOT.TFile(infile_name)
14+
tree = file.Get("events")
15+
posx_VXD=[]
16+
posy_VXD=[]
17+
posz_VXD=[]
18+
posr_VXD=[]
19+
for entry in tree:
20+
for elem in entry.VXDCollection:
21+
x=elem.position.x
22+
y=elem.position.y
23+
z=elem.position.z
24+
r = math.sqrt(x*x + y*y)
25+
posx_VXD.append(x)
26+
posy_VXD.append(y)
27+
posz_VXD.append(z)
28+
posr_VXD.append(r)
29+
file.Close()
30+
VXDHitMap = ROOT.TH2F("VXDHitMap","Hit Map of VXD",40,-125,125,20,0,80)
31+
for i in range(0,len(posz_VXD)):
32+
VXDHitMap.Fill(posz_VXD[i],posr_VXD[i])
33+
ofile=ROOT.TFile(out_file_name,"Recreate")
34+
VXDHitMap.Write()
35+
ofile.Close()
36+
37+
38+
def GetSITHitMapFromFile(infile_path,out_file_name):
39+
file = ROOT.TFile(infile_path)
40+
tree = file.Get("events")
41+
posx_SIT=[]
42+
posy_SIT=[]
43+
posz_SIT=[]
44+
posr_SIT=[]
45+
for entry in tree:
46+
for elem in entry.SITCollection:
47+
x=elem.position.x
48+
y=elem.position.y
49+
z=elem.position.z
50+
r = math.sqrt(x*x + y*y)
51+
posx_SIT.append(x)
52+
posy_SIT.append(y)
53+
posz_SIT.append(z)
54+
posr_SIT.append(r)
55+
file.Close()
56+
SITHitMap = ROOT.TH2F("SITHitMap","Hit Map of SIT",200,-2400,2400,20,120,320)
57+
for i in range(0,len(posz_SIT)):
58+
SITHitMap.Fill(posz_SIT[i],posr_SIT[i])
59+
ofile=ROOT.TFile(out_file_name,"Recreate")
60+
SITHitMap.Write()
61+
ofile.Close()
62+
63+
print("test")
64+
65+
def GetSETHitMapFromFile(infile_path,out_file_name):
66+
file = ROOT.TFile(infile_path)
67+
tree = file.Get("events")
68+
posx_SET=[]
69+
posy_SET=[]
70+
posz_SET=[]
71+
posr_SET=[]
72+
for entry in tree:
73+
for elem in entry.SETCollection:
74+
x=elem.position.x
75+
y=elem.position.y
76+
z=elem.position.z
77+
r = math.sqrt(x*x + y*y)
78+
posx_SET.append(x)
79+
posy_SET.append(y)
80+
posz_SET.append(z)
81+
posr_SET.append(r)
82+
file.Close()
83+
SETHitMap = ROOT.TH2F("SETHitMap","Hit Map of SET",200,-2400,2400,20,1700,2000)
84+
for i in range(0,len(posz_SET)):
85+
SETHitMap.Fill(posz_SET[i],posr_SET[i])
86+
ofile=ROOT.TFile(out_file_name,"Recreate")
87+
SETHitMap.Write()
88+
ofile.Close()
89+
90+
91+
92+
#draw
93+
def DrawHitMap(in_file_name,TH2name,out_file_name):
94+
file = ROOT.TFile(in_file_name)
95+
TH2_HitMap=file.Get(TH2name)
96+
c = ROOT.TCanvas("c", "c", 800, 800)
97+
ROOT.gStyle.SetOptStat(0)
98+
TH2_HitMap.GetXaxis().SetTitle("Z [mm]")
99+
TH2_HitMap.GetXaxis().SetTitleOffset(0.77)
100+
TH2_HitMap.GetXaxis().SetTitleSize(0.05)
101+
TH2_HitMap.GetYaxis().SetTitle("R [mm]")
102+
TH2_HitMap.GetYaxis().SetTitleOffset(0.8)
103+
TH2_HitMap.GetYaxis().SetTitleSize(0.045)
104+
TH2_HitMap.Draw("COL Z CJUST SAME")
105+
106+
c.SaveAs(out_file_name+".root")
107+
c.SaveAs(out_file_name+".pdf")
108+
109+
path1="/scratchfs/atlas/lizhan/cepc/CEPCSW/test-SIT.root"
110+
111+
VXDOutFile="/scratchfs/atlas/lizhan/cepc/CEPCSW/VXDHM.root"
112+
SITOutFile="/scratchfs/atlas/lizhan/cepc/CEPCSW/SITHM.root"
113+
SETOutFile="/scratchfs/atlas/lizhan/cepc/CEPCSW/SETHM.root"
114+
GetVXDHitMapFromFile(path1,VXDOutFile)
115+
GetSITHitMapFromFile(path1,SITOutFile)
116+
GetSETHitMapFromFile(path1,SETOutFile)
117+
118+
DrawHitMap(VXDOutFile,"VXDHitMap","Full_VXDHM_1evt")
119+
DrawHitMap(SITOutFile,"SITHitMap","Full_SITHM_1evt")
120+
DrawHitMap(SETOutFile,"SETHitMap","Full_SETHM_1evt")

0 commit comments

Comments
 (0)