Skip to content

Commit

Permalink
Fixed testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Juanki0396 committed Aug 23, 2024
1 parent 0e352bf commit 3fb2a90
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 84 deletions.
139 changes: 59 additions & 80 deletions test/integration/ReconstructedParticle.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,87 +29,66 @@ def get_file(url: str, path: str) -> None:
ROOT_FILE = "/tmp/test.root"
FINAL_ROOT_FILE = "/tmp/test_final.root"

if not Path(ROOT_FILE).exists():
if __name__ == "__main__":

print("Downloading Pythia files")
print("ReconstructedParticle Integration Test: PRE-TEST".center(80, "-"))

get_file(**PYTHIA_CARD)
get_file(**DETECTOR_CARD)
get_file(**OUTPUT_CARD)

print("Running Pythia to generate root file")

subprocess.run(
[
"DelphesPythia8_EDM4HEP",
DETECTOR_CARD["path"],
OUTPUT_CARD["path"],
PYTHIA_CARD["path"],
ROOT_FILE
],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
).check_returncode()
else:
subprocess.run(
[
"podio-dump",
ROOT_FILE
],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
).check_returncode()

print("Loading ROOT libraries")

if not ROOT.gSystem.Load("libral") and ROOT.gSystem.Load("libedm4hep"):
print('RAL Found!')
print('EDM4HEP Found!')
if ROOT.loadRal() and ROOT.edm4hep.ReconstructedParticleData():
print('RAL Loaded!')
print('EDM4HEP Loaded!')

print("Load ROOT dataframe and test ral functions")

df = ROOT.RDataFrame("events", ROOT_FILE)

ROOT.gInterpreter.ProcessLine("using namespace k4::ral;")
ROOT.gInterpreter.ProcessLine("using namespace LogicalOperators;")

df = (df
.Define("charge",
"ReconstructedParticle::get_q(ReconstructedParticles)")
.Define("energy",
"ReconstructedParticle::get_e(ReconstructedParticles)")
.Define("PDG",
"ReconstructedParticle::get_pdg(ReconstructedParticles)")
.Define("momentum",
"ReconstructedParticle::get_p(ReconstructedParticles)")
.Define("referencePoint",
"ReconstructedParticle::get_referencePoint(ReconstructedParticles)")
.Define("mass",
"ReconstructedParticle::get_m(ReconstructedParticles)")
.Define("goodnessOfPID",
"ReconstructedParticle::get_goodnessOfPID(ReconstructedParticles)")
.Define("mask_e1",
"ReconstructedParticle::mask_e(ComparisonOperator::LESS, 1., ReconstructedParticles)")
.Define("mask_e2",
"ReconstructedParticle::mask_e(ComparisonOperator::GREATER, 5., ReconstructedParticles)")
.Define("filter",
"filter<edm4hep::ReconstructedParticleData>((mask_e1 && mask_e2), ReconstructedParticles)")
)

print("Output test result in a new dataframe")

df.Snapshot("events", FINAL_ROOT_FILE,
if not Path(ROOT_FILE).exists():
print("Downloading Pythia files")
get_file(**PYTHIA_CARD)
get_file(**DETECTOR_CARD)
get_file(**OUTPUT_CARD)
print("Running Pythia to generate root file")
subprocess.run(
[
"charge",
"energy",
"PDG",
"momentum",
"referencePoint",
"mass",
"goodnessOfPID",
"filter"
])
"DelphesPythia8_EDM4HEP",
DETECTOR_CARD["path"],
OUTPUT_CARD["path"],
PYTHIA_CARD["path"],
ROOT_FILE
],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
).check_returncode()
# else:
# subprocess.run(
# [
# "podio-dump",
# ROOT_FILE
# ],
# stdout=subprocess.DEVNULL,
# stderr=subprocess.DEVNULL
# ).check_returncode()

print("ReconstructedParticle Integration Test: START".center(80, "-"))

print("Loading ROOT libraries")
if not ROOT.gSystem.Load("libral") and ROOT.gSystem.Load("libedm4hep"):
print('RAL Found!')
print('EDM4HEP Found!')
if ROOT.loadRal() and ROOT.edm4hep.ReconstructedParticleData():
print('RAL Loaded!')
print('EDM4HEP Loaded!')

print("Loading ROOT dataframe and test ral functions")
df = ROOT.RDataFrame("events", ROOT_FILE)
ROOT.gInterpreter.ProcessLine("using namespace k4::ral;")
ROOT.gInterpreter.ProcessLine("using namespace LogicalOperators;")
df = (df
.Define("e1",
"ReconstructedParticle::sel_e(ComparisonOperator::LESS, 1., ReconstructedParticles)")
.Define("e2",
"ReconstructedParticle::sel_e(ComparisonOperator::GREATER, 5., e1)")
.Define("mass",
"ReconstructedParticle::get_m(e2)")
.Define("total_mass",
"ROOT::VecOps::Sum(mass)")
)
print("Output test result in a new dataframe")
df.Snapshot("events", FINAL_ROOT_FILE,
[
"e2",
"mass",
"total_mass"
])

14 changes: 10 additions & 4 deletions test/unittest/ReconstructedParticle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@ edm4hep::ReconstructedParticleData generateRandomParticle() {
std::random_device
rd; // Will be used to obtain a seed for the random number engine
std::mt19937 gen(rd()); // Standard mersenne_twister_engine seeded with rd()
std::uniform_real_distribution<> dis_real(-1000.0, 1000.0);
std::uniform_int_distribution<> dis_int(-1000, 1000);
std::uniform_real_distribution<float> dis_real(-1000.0, 1000.0);
std::uniform_int_distribution<int> dis_int(-1000, 1000);
edm4hep::ReconstructedParticleData data;
data.PDG = dis_int(gen);
data.mass = dis_real(gen);
data.mass = std::abs(dis_real(gen));
data.charge = dis_real(gen);
data.energy = dis_real(gen);
data.energy = std::abs(dis_real(gen));
data.momentum.x = dis_real(gen);
data.momentum.y = dis_real(gen);
data.momentum.z = dis_real(gen);
data.referencePoint.x = dis_real(gen);
data.referencePoint.y = dis_real(gen);
data.referencePoint.z = dis_real(gen);
return data;
}

Expand Down

0 comments on commit 3fb2a90

Please sign in to comment.