Skip to content
Snippets Groups Projects
Commit 9e40dc59 authored by Sebastien Ponce's avatar Sebastien Ponce
Browse files

Merge branch 'HLT1reader' into 'master'

Functionality added to access HLT1 decisions using FunTuple and example options files included

See merge request !691
parents 58ebfdf5 5cdca015
No related branches found
No related tags found
2 merge requests!1103Draft: Add AnalysisHelpers to DaVinci Stack,!691Functionality added to access HLT1 decisions using FunTuple and example options files included
Pipeline #4072443 passed
###############################################################################
# (c) Copyright 2021-2022 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
# #
# In applying this licence, CERN does not waive the privileges and immunities #
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
"""
Read an HLT2 file and create an ntuple with the new DaVinci configuration, accessing HLT1 and HLT2 decisions.
To run:
./run davinci run-mc --inputfiledb test_hlt1_trigger_decisions Phys/DaVinci/options/DaVinciDB-Example.yaml --joboptfile DaVinciExamples/python/DaVinciExamples/tupling/option_trigger_decisions.yaml --user_algorithms DaVinciExamples/python/DaVinciExamples/tupling/option_trigger_decisions:main
"""
import Functors as F
from FunTuple import FunctorCollection
from FunTuple import FunTuple_Particles as Funtuple
from PyConf.components import force_location
from DaVinci.reco_objects import make_pvs_v2
from DaVinci import options
from DaVinci.algorithms import get_decreports
from FunTuple.functorcollections import SelectionInfo
options.process = 'Hlt2'
fields = {'B0': '[[B0]CC -> (D- -> K+ pi- pi-) pi+]CC'}
# Creating v2 reconstructed vertices to be used in the following functor
v2_pvs = make_pvs_v2(process=options.process)
B0_variables = FunctorCollection({"ID": F.PARTICLE_ID})
variables = {"B0": B0_variables}
def main():
b02dpi_data = force_location(
"/Event/HLT2/Hlt2B2OC_BdToDmPi_DmToPimPimKp_Line/Particles")
hlt1_dec = get_decreports("Hlt1", options)
Hlt1_decisions = [
'Hlt1TrackMVADecision', 'Hlt1TwoTrackMVADecision', 'Hlt1D2KKDecision',
'Hlt1D2KPiDecision', 'Hlt1D2PiPiDecision',
'Hlt1DiMuonHighMassDecision', 'Hlt1DiMuonLowMassDecision',
'Hlt1DiMuonSoftDecision', 'Hlt1GECPassthroughDecision',
'Hlt1KsToPiPiDecision', 'Hlt1LowPtMuonDecision',
'Hlt1LowPtDiMuonDecision', 'Hlt1SingleHighPtMuonDecision',
'Hlt1TrackMuonMVADecision'
]
#define event level variables
evt_variables = SelectionInfo("Hlt1", hlt1_dec, Hlt1_decisions)
#define FunTuple instance
my_tuple = Funtuple(
name="Tuple",
tuple_name="DecayTree",
fields=fields,
variables=variables,
event_variables=evt_variables,
inputs=b02dpi_data)
return {"UserAlgs": [my_tuple]}, []
###############################################################################
# (c) Copyright 2022 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
# #
# In applying this licence, CERN does not waive the privileges and immunities #
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
annsvc_config: 'root://eoslhcb.cern.ch//eos/lhcb/wg/dpa/wp3/tests/hlt2_integration_B0_100.tck.json'
evt_max: -1
histo_file: 'hlt2_B0_test_histo.root'
lumi: false
ntuple_file: 'hlt2_B0_test_ntuple.root'
print_freq: 1
process: 'Hlt2'
<?xml version="1.0" ?>
<!--
###############################################################################
# (c) Copyright 2021-2022 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
# #
# In applying this licence, CERN does not waive the privileges and immunities #
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
-->
<!DOCTYPE extension PUBLIC '-//QM/2.3/Extension//EN' 'http://www.codesourcery.com/qm/dtds/2.3/-//qm/2.3/extension//en.dtd'>
<!--
#######################################################
# SUMMARY OF THIS TEST
# ...................
# Author: jedavies
# Purpose: Test for the new DaVinci configuration to access HLT1 decisions using FunTuple
# Prerequisites: None
# inputfiledb test_hlt1_trigger_decisions $DAVINCIROOT/options/DaVinciDB-Example.yaml
# user_algorithms ../../python/DaVinciExamples/tupling/option_trigger_decisions:main
#######################################################
-->
<extension class="GaudiTest.GaudiExeTest" kind="test">
<argument name="program"><text>davinci</text></argument>
<argument name="args"><set>
<text>--inputfiledb</text>
<text>test_hlt1_trigger_decisions</text>
<text>$DAVINCIROOT/options/DaVinciDB-Example.yaml</text>
<text>--joboptfile</text>
<text>../../python/DaVinciExamples/tupling/option_trigger_decisions.yaml</text>
<text>--user_algorithms</text>
<text>../../python/DaVinciExamples/tupling/option_trigger_decisions:main</text>
</set></argument>
<argument name="validator"><text>
from DaVinciTests.QMTest.DaVinciExclusions import remove_known_warnings
countErrorLines({"FATAL": 0, "WARNING": 0, "ERROR": 0},
stdout=remove_known_warnings(stdout))
import sys, os, glob
from ROOT import TFile
B_vars_stored =['B0_ID',
'Hlt1_Hlt1DiMuonSoftDecision',
'Hlt1_Hlt1DiMuonLowMassDecision',
'Hlt1_Hlt1D2KKDecision',
'Hlt1_Hlt1LowPtMuonDecision',
'Hlt1_Hlt1KsToPiPiDecision',
'Hlt1_Hlt1TrackMuonMVADecision',
'Hlt1_Hlt1TwoTrackMVADecision',
'Hlt1_Hlt1LowPtDiMuonDecision',
'Hlt1_Hlt1DiMuonHighMassDecision',
'Hlt1_Hlt1GECPassthroughDecision',
'Hlt1_Hlt1SingleHighPtMuonDecision',
'Hlt1_Hlt1D2KPiDecision',
'Hlt1_Hlt1D2PiPiDecision',
'Hlt1_Hlt1TrackMVADecision',
'Hlt1_TCK'
]
#sort the expected vars
B_vars_stored = sorted(B_vars_stored)
#open the TFile and TTree
ntuple = './hlt2_B0_test_ntuple.root'
if not os.path.isfile(ntuple): raise Exception(f"File: {ntuple} does not exist!")
f = TFile.Open(ntuple)
t_B = f.Get('Tuple/DecayTree')
#sort the stores vars
b_names = sorted([b.GetName() for b in t_B.GetListOfLeaves()])
print("b_names ", b_names)
B_excluded_1 = set(B_vars_stored) - set(b_names)
B_excluded_2 = set(b_names) - set(B_vars_stored)
if len(B_excluded_1) != 0: raise Exception('Number of stored variables is less than what is expected. The extra variables expected are: ' , B_excluded_1)
if len(B_excluded_2) != 0: raise Exception('Number of stored variables is greater than what is expected. The extra variables stored are: ', B_excluded_2)
f.Close()
print('Test successfully completed!')
os.system(f"rm {ntuple}")
</text></argument>
</extension>
......@@ -35,7 +35,7 @@ remove_known_warnings = LineSkipper(regexps=[
r"HltPackedBufferDecoder +WARNING TCK in rawbank seems to be 0 .*",
r"HltPackedBufferDe...WARNING TCK in rawbank seems to be 0 .*",
r"HltDecReportsDecoder +WARNING TCK obtained from rawbank seems to be 0 .*",
r"HLT2 +WARNING TCK obtained from rawbank seems to be 0 .*",
r"Hlt. +WARNING TCK obtained from rawbank seems to be 0 .*",
r"Hlt2DecReports +WARNING TCK obtained from rawbank seems to be 0 .*",
r"SpruceDecReports +WARNING TCK obtained from rawbank seems to be 0 .*",
r"Spruce +WARNING TCK obtained from rawbank seems to be 0 .*",
......
......@@ -108,6 +108,20 @@ test_spruce_MCtools:
Data: '2022-02'
Comment: "DST file to test MC tools on Sprucing output"
test_hlt1_trigger_decisions:
filenames:
- 'root://eoslhcb.cern.ch//eos/lhcb/wg/dpa/wp3/tests/hlt2_integration_B0_100.dst'
qualifiers:
data_type: Upgrade
input_type: DST
simulation: true
conddb_tag: sim-20201218-vc-md100
dddb_tag: dddb-20201211
metadata:
Author: 'Jonathan Davies'
Data: '2022-05'
Comment: "DST file for testing accessing HLT1 decisions in DaVinci using FunTuple"
test_passthrough_thor_lines:
filenames:
- 'root://eoslhcb.cern.ch//eos/lhcb/wg/dpa/wp3/tests/hlt2_passthrough_thor_lines.dst'
......@@ -120,4 +134,4 @@ test_passthrough_thor_lines:
metadata:
Author: 'Davide Fazzini'
Data: '2022-05'
Comment: "DST file to test passthrough sample with hlt2 generic thor lines."
\ No newline at end of file
Comment: "DST file to test passthrough sample with hlt2 generic thor lines."
......@@ -25,6 +25,7 @@ from PyConf.application import (
from DaVinci.algorithms_pyconf import make_dvalgorithm
from DaVinci.config import DVAppOptions
from PyConf.components import force_location
from Gaudi.Configuration import WARNING
def setup_algorithms(user_algs_name):
......@@ -337,28 +338,31 @@ def get_hlt_reports(options, source=''):
Set the Hlt service and algorithms.
Args:
- options (DVAppOptions instance): list of DaVinci options.
- source (str): source ID required by the user.
options (list): list of DaVinci options.
source (str): source ID required by the user.
Returns:
- HltDecReportsDecoder containing the configuration for hlt2 lines.
- HltDecReportsDecoder containing the configuration for spruced lines.
- HltDecReportsDecoder containing the configuration for hlt1 lines.
- HltDecReportsDecoder containing the configuration for hlt2 lines.
- HltDecReportsDecoder containing the configuration for spruced lines.
"""
from GaudiConf import reading
process = options.process
stream = options.stream
if source == 'Hlt2':
dec_reports = reading.hlt2_decisions(
if source == 'Hlt1' or source == 'Hlt2':
dec_reports = reading.hlt_decisions(
process=process,
stream=stream,
output_loc="/Event/%s/DecReports" % source,
configurables=False)
configurables=False,
source=source,
output_level=WARNING)
elif source == 'Spruce':
dec_reports = reading.spruce_decisions(
process=process, stream=stream, configurables=False)
dec_reports = reading.hlt_decisions(
process=process, stream=stream, configurables=False, source=source)
return dec_reports
......@@ -431,11 +435,11 @@ def get_odin(dv_options):
def get_decreports(sel_stage, dv_options):
"""
Function to get the LHCb::DecReports for HLT1 or Hlt2 or Spruce
Function to get the LHCb::DecReports for HLT1, HLT2 or Sprucing.
Args:
sel_state (str): Selction stage can be "Hlt1" or "Hlt2" or "Spruce" (There does not seem to be a decoder for Hlt1 currently)
dv_options (DVAppOptions instance): Configured DaVinci.options object
sel_state (str): Selection stage can be "Hlt1" or "Hlt2" or "Spruce"
dv_options: Configured DaVinci.options object
Returns:
dec_loc: Location of the LHCb::DecReports for HLT1 or Hlt2 or Spruce
"""
......
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