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

Adjusting Ntupleizer for ALLEGRO o1 v02 #357

Merged
merged 5 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 8 additions & 2 deletions analyzers/dataframe/FCCAnalyses/CaloNtupleizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,16 @@ ROOT::VecOps::RVec<float> getCaloHit_x (const ROOT::VecOps::RVec<edm4hep::Calori
ROOT::VecOps::RVec<float> getCaloHit_y (const ROOT::VecOps::RVec<edm4hep::CalorimeterHitData>& in);
ROOT::VecOps::RVec<float> getCaloHit_z (const ROOT::VecOps::RVec<edm4hep::CalorimeterHitData>& in);
ROOT::VecOps::RVec<float> getCaloHit_phi (const ROOT::VecOps::RVec<edm4hep::CalorimeterHitData>& in);
ROOT::VecOps::RVec<int> getCaloHit_phiBin (const ROOT::VecOps::RVec<edm4hep::CalorimeterHitData>& in);
ROOT::VecOps::RVec<int>
getCaloHit_phiIdx(const ROOT::VecOps::RVec<edm4hep::CalorimeterHitData> &in);
ROOT::VecOps::RVec<int>
getCaloHit_moduleIdx(const ROOT::VecOps::RVec<edm4hep::CalorimeterHitData> &in);
ROOT::VecOps::RVec<float> getCaloHit_theta (const ROOT::VecOps::RVec<edm4hep::CalorimeterHitData>& in);
ROOT::VecOps::RVec<int>
getCaloHit_thetaIdx(const ROOT::VecOps::RVec<edm4hep::CalorimeterHitData> &in);
ROOT::VecOps::RVec<float> getCaloHit_eta (const ROOT::VecOps::RVec<edm4hep::CalorimeterHitData>& in);
ROOT::VecOps::RVec<int> getCaloHit_etaBin (const ROOT::VecOps::RVec<edm4hep::CalorimeterHitData>& in);
ROOT::VecOps::RVec<int>
getCaloHit_etaIdx(const ROOT::VecOps::RVec<edm4hep::CalorimeterHitData> &in);
ROOT::VecOps::RVec<int> getCaloHit_layer (const ROOT::VecOps::RVec<edm4hep::CalorimeterHitData>& in);
ROOT::VecOps::RVec<float> getCaloHit_energy (const ROOT::VecOps::RVec<edm4hep::CalorimeterHitData>& in);
ROOT::VecOps::RVec<TVector3> getCaloHit_positionVector3 (const ROOT::VecOps::RVec<edm4hep::CalorimeterHitData>& in);
Expand Down
26 changes: 24 additions & 2 deletions analyzers/dataframe/src/CaloNtupleizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ ROOT::VecOps::RVec<float> getCaloHit_phi (const ROOT::VecOps::RVec<edm4hep::Calo
return result;
}

ROOT::VecOps::RVec<int> getCaloHit_phiBin (const ROOT::VecOps::RVec<edm4hep::CalorimeterHitData>& in){
ROOT::VecOps::RVec<int>
getCaloHit_phiIdx(const ROOT::VecOps::RVec<edm4hep::CalorimeterHitData> &in) {
ROOT::VecOps::RVec<int> result;
for (auto & p: in){
dd4hep::DDSegmentation::CellID cellId = p.cellID;
Expand All @@ -174,6 +175,26 @@ ROOT::VecOps::RVec<int> getCaloHit_phiBin (const ROOT::VecOps::RVec<edm4hep::Cal
return result;
}

ROOT::VecOps::RVec<int> getCaloHit_moduleIdx(
const ROOT::VecOps::RVec<edm4hep::CalorimeterHitData> &in) {
ROOT::VecOps::RVec<int> result;
for (auto &p : in) {
dd4hep::DDSegmentation::CellID cellId = p.cellID;
result.push_back(m_decoder->get(cellId, "module"));
}
return result;
}

ROOT::VecOps::RVec<int>
getCaloHit_thetaIdx(const ROOT::VecOps::RVec<edm4hep::CalorimeterHitData> &in) {
ROOT::VecOps::RVec<int> result;
for (auto &p : in) {
dd4hep::DDSegmentation::CellID cellId = p.cellID;
result.push_back(m_decoder->get(cellId, "theta"));
}
return result;
}

ROOT::VecOps::RVec<float> getCaloHit_theta (const ROOT::VecOps::RVec<edm4hep::CalorimeterHitData>& in){
ROOT::VecOps::RVec<float> result;
for (auto & p: in){
Expand All @@ -194,7 +215,8 @@ ROOT::VecOps::RVec<float> getCaloHit_eta (const ROOT::VecOps::RVec<edm4hep::Calo
return result;
}

ROOT::VecOps::RVec<int> getCaloHit_etaBin (const ROOT::VecOps::RVec<edm4hep::CalorimeterHitData>& in){
ROOT::VecOps::RVec<int>
getCaloHit_etaIdx(const ROOT::VecOps::RVec<edm4hep::CalorimeterHitData> &in) {
ROOT::VecOps::RVec<int> result;
for (auto & p: in){
dd4hep::DDSegmentation::CellID cellId = p.cellID;
Expand Down
14 changes: 14 additions & 0 deletions cmake/FCCAnalysesFunctions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ function(add_generic_test _testname _testcmd)
TEST_INPUT_DATA_DIR=${TEST_INPUT_DATA_DIR})
endfunction()

function(add_standalone_test _testname)
add_test(NAME fccanalysis_standalone_${_testname}
COMMAND python ${_testname} --test
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
set_property(TEST fccanalysis_standalone_${_testname} APPEND PROPERTY ENVIRONMENT
LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/e4hsource:${CMAKE_BINARY_DIR}/analyzers/dataframe:$ENV{LD_LIBRARY_PATH}
PYTHONPATH=${CMAKE_SOURCE_DIR}/python:$ENV{PYTHONPATH}
PATH=${CMAKE_SOURCE_DIR}/bin:${CMAKE_BINARY_DIR}:$ENV{PATH}
ROOT_INCLUDE_PATH=${CMAKE_BINARY_DIR}/e4hsource:${CMAKE_SOURCE_DIR}/analyzers/dataframe:$ENV{ROOT_INCLUDE_PATH}
TEST_INPUT_DATA_DIR=${TEST_INPUT_DATA_DIR}
)
endfunction()

macro(fccanalyses_addon_build _name)
set(options)
set(one_val)
Expand Down
29 changes: 20 additions & 9 deletions examples/FCCee/fullSim/caloNtupleizer/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ def str2bool(v):

parser = argparse.ArgumentParser()

parser.add_argument("-inputFiles", default = '/eos/user/b/brfranco/rootfile_storage/220618_gamma_flat_1_100_noNoise/fccsw_output_pdgID_22_pMin_1000_pMax_100000_thetaMin_50_thetaMax_130.root', help = "Input rootfiles (can be a single file or a regex)", type = str)
parser.add_argument("-inputFiles", type=str,
default='ALLEGRO_sim_digi_reco.root',
help="Input rootfiles (can be a single file or a regex)")
parser.add_argument("-t", "--test", action="store_true", default=False,
help="Run over pre-defined test file")
parser.add_argument("-outputFolder", default = os.path.join("outputs", date.today().strftime("%y%m%d")), help = "Output folder for the rootfiles", type = str)
parser.add_argument("-storeCellBranches", default = True, help="Whether or not to store cell information", type = str2bool)
parser.add_argument("-cellBranchNames", default = ["ECalBarrelPositionedCells"], help="Name of the cell branch in the input rootfile. Must have position information!", type = str)
Expand All @@ -29,12 +33,13 @@ def str2bool(v):
parser.add_argument("-storeClusterCellsBranches", default = False, help="Whether or not to store cluster cells information", type = str2bool)
parser.add_argument("-clusterCellsBranchNames", default = ["PositionedCaloClusterCells"], help="Name of the cluster-attached-cells branches in the input rootfile. Order must follow -clusterBranchNames and the cells must have positions attached!", type = str, nargs = '+')
parser.add_argument("-storeGenBranches", default = True, help="Whether or not to store gen information", type = str2bool)
parser.add_argument("-genBranchName", default = "genParticles", help="Name of the gen particle branch in the input rootfile", type = str)
parser.add_argument("-genBranchName", type=str, default="MCParticles",
help="Name of the gen particle branch in the input rootfile")
parser.add_argument("-storeSimParticleSecondaries", default = False, help="Whether to store the SimParticleSecondaries information", type = str2bool)
parser.add_argument("-simParticleSecondariesNames", default = ["SimParticleSecondaries"], help = "name of the SimParticleSecondaries branch", type = str, nargs = '+')
parser.add_argument("-useGeometry", default = True, help="Whether or not to load the FCCSW geometry. Used to get the detector segmentation for e.g. the definition of the cell layer index.", type = str2bool)
parser.add_argument("-geometryFile", default = '/afs/cern.ch/user/b/brfranco/work/public/Fellow/FCCSW/test_recipe_April2022/FCCDetectors/Detector/DetFCCeeIDEA-LAr/compact/FCCee_DectMaster.xml', help = "Path to the xml geometry file", type = str)
parser.add_argument("-readoutName", default = 'ECalBarrelPhiEta', help = "Name of the readout to use for the layer/phi/theta bin definition", type = str)
parser.add_argument("-geometryFile", default=os.environ['K4GEO'] + '/FCCee/ALLEGRO/compact/ALLEGRO_o1_v02/ALLEGRO_o1_v02.xml', help="Path to the xml geometry file", type=str)
parser.add_argument("-readoutName", default='ECalBarrelModuleThetaMerged', help="Name of the readout to use for the layer/phi/theta bin definition", type=str)
parser.add_argument("-extractHighestEnergyClusterCells", default = False, help = "Use it if you need cells attached to the higest energy cluster, will use the first cluster collection in clusterBranchNames", type = str2bool)
parser.add_argument("-isPi0", default = 0, help = "Weaver training needs a branch in the input tree with the target label: set it to 1 when running on pi0 files, 0 for photon files", type = int)
parser.add_argument("-doWeaverInference", default = False, help = "Apply weaver inference on highest energy cluster cell variables, extractHighestEnergyClusterCells must be set to True", type = str2bool)
Expand Down Expand Up @@ -72,9 +77,9 @@ def run(self):
dict_outputBranchName_function["%s_eta"%cellBranchName] = "CaloNtupleizer::getCaloHit_eta(%s)"%cellBranchName
dict_outputBranchName_function["%s_energy"%cellBranchName] = "CaloNtupleizer::getCaloHit_energy(%s)"%cellBranchName
if args.useGeometry:
dict_outputBranchName_function["%s_phiBin"%cellBranchName] = "CaloNtupleizer::getCaloHit_phiBin(%s)"%cellBranchName
dict_outputBranchName_function["%s_moduleIdx"%cellBranchName] = "CaloNtupleizer::getCaloHit_moduleIdx(%s)"%cellBranchName
dict_outputBranchName_function["%s_thetaIdx"%cellBranchName] = "CaloNtupleizer::getCaloHit_thetaIdx(%s)"%cellBranchName
dict_outputBranchName_function["%s_layer"%cellBranchName] = "CaloNtupleizer::getCaloHit_layer(%s)"%cellBranchName
dict_outputBranchName_function["%s_etaBin"%cellBranchName] = "CaloNtupleizer::getCaloHit_etaBin(%s)"%cellBranchName

# clusters
if args.storeClusterBranches:
Expand All @@ -100,9 +105,9 @@ def run(self):
dict_outputBranchName_function["%s_eta"%clusterCellsBranchName] = "CaloNtupleizer::getCaloHit_eta(%s)"%clusterCellsBranchName
dict_outputBranchName_function["%s_energy"%clusterCellsBranchName] = "CaloNtupleizer::getCaloHit_energy(%s)"%clusterCellsBranchName
if args.useGeometry:
dict_outputBranchName_function["%s_phiBin"%clusterCellsBranchName] = "CaloNtupleizer::getCaloHit_phiBin(%s)"%clusterCellsBranchName
dict_outputBranchName_function["%s_moduleIdx"%clusterCellsBranchName] = "CaloNtupleizer::getCaloHit_moduleIdx(%s)"%clusterCellsBranchName
dict_outputBranchName_function["%s_thetaIdx"%clusterCellsBranchName] = "CaloNtupleizer::getCaloHit_thetaIdx(%s)"%clusterCellsBranchName
dict_outputBranchName_function["%s_layer"%clusterCellsBranchName] = "CaloNtupleizer::getCaloHit_layer(%s)"%clusterCellsBranchName
dict_outputBranchName_function["%s_etaBin"%clusterCellsBranchName] = "CaloNtupleizer::getCaloHit_etaBin(%s)"%clusterCellsBranchName

# SimParticleSecondaries
if args.storeSimParticleSecondaries:
Expand Down Expand Up @@ -191,8 +196,14 @@ def run(self):

df2.Snapshot("events", self.outname, branchList)

if args.test:
filelist = ["https://fccsw.web.cern.ch/fccsw/testsamples/fccanalyses/ALLEGRO_sim_digi_reco.root"]
else:
filelist = glob.glob(args.inputFiles)

filelist = glob.glob(args.inputFiles)
if not filelist:
print('No input found! Aborting...')
sys.exit(3)

fileListRoot = ROOT.vector('string')()
print ("Input files:")
Expand Down
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ add_integration_test("examples/FCCee/flavour/Bc2TauNu/analysis_B2TauNu_truth.py"
add_integration_test("examples/FCCee/test/jet_constituents.py")
add_integration_test("examples/FCCee/vertex_lcfiplus/analysis_V0.py")

add_standalone_test("examples/FCCee/fullSim/caloNtupleizer/analysis.py")

# TODO: make this test run in the spack build environment
#add_generic_test(build_new_case_study "tests/build_new_case_study.sh")
Loading