diff --git a/DaVinciExamples/python/DaVinciExamples/tupling/option_davinci_tupling_unreconstructed_info.py b/DaVinciExamples/python/DaVinciExamples/tupling/option_davinci_tupling_unreconstructed_info.py new file mode 100644 index 0000000000000000000000000000000000000000..9e5c935797fbffbcba97c138366900dc404b45af --- /dev/null +++ b/DaVinciExamples/python/DaVinciExamples/tupling/option_davinci_tupling_unreconstructed_info.py @@ -0,0 +1,88 @@ +############################################################################### +# (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. # +############################################################################### +""" +Read an HLT2 file and create an ntuple with truth information about unreconstructed particles +""" +import Functors as F +from FunTuple import FunctorCollection as FC +from FunTuple import FunTuple_Particles as Funtuple +from DaVinci.algorithms import add_filter +from DaVinci import make_config, Options +from DaVinci.truth_matching import configured_MCTruthAndBkgCatAlg +from PyConf.reading import get_particles + + +def main(options: Options): + #define fields + fields = {'Lb': '[Lambda_b0 -> (Lambda_c+ -> p+ K- pi+) mu-]CC'} + + #get particles to run over + line_name = 'Hlt2SLB_LbToLcMuNu_LcToPKPi_Line' + particles = get_particles(f"/Event/HLT2/{line_name}/Particles") + my_filter = add_filter("Myfilter", f"HLT_PASS('{line_name}')") + + #get configured "MCTruthAndBkgCatAlg" algorithm for HLT2 output + mctruth = configured_MCTruthAndBkgCatAlg(inputs=particles) + #add helper lambda that configures a functor to get truth information + MCTRUTH = lambda func, rels: F.MAP_INPUT(Functor=func, Relations=rels) + + #define variables and add them to all fields + # + #In MCDecay case it is possible to use the simplified decay descriptor using + #only the direct products of the parent decay and omitting other descendants + #In this case we're interested into MC information about the unreconstructed neutrino + # + #A returning value of NaN is needed whenever the FIND_MCDECAY functor + #is not able to find any MC particle from the decay, because either none or more + #than one caret is passed to the DecayDescriptor + lc_px = F.VALUE_OR(F.NaN) @ F.PX @ F.FIND_MCDECAY( + "[ Lambda_b0 => ^Lambda_c+ mu- nu_mu~ ]CC") + mu_px = F.VALUE_OR(F.NaN) @ F.PX @ F.FIND_MCDECAY( + "[ Lambda_b0 => Lambda_c+ ^mu- nu_mu~ ]CC") + nu_px = F.VALUE_OR(F.NaN) @ F.PX @ F.FIND_MCDECAY( + "[ Lambda_b0 => Lambda_c+ mu- ^nu_mu~ ]CC") + lc_true_id = F.VALUE_OR(-1) @ F.PARTICLE_ID @ F.FIND_MCDECAY( + "[ Lambda_b0 => ^Lambda_c+ mu- nu_mu~ ]CC") + mu_true_id = F.VALUE_OR(-1) @ F.PARTICLE_ID @ F.FIND_MCDECAY( + "[ Lambda_b0 => Lambda_c+ ^mu- nu_mu~ ]CC") + nu_true_id = F.VALUE_OR(-1) @ F.PARTICLE_ID @ F.FIND_MCDECAY( + "[ Lambda_b0 => Lambda_c+ mu- ^nu_mu~ ]CC") + + #A returning value of NaN is needed whenever MCAssocTable is empty + #i.e. has no relations inside + lb_variables = FC({ + 'TRUEPX': + MCTRUTH(F.PX, mctruth.MCAssocTable), + 'Lc_TRUEPX': + F.VALUE_OR(F.NaN) @ MCTRUTH(lc_px, mctruth.MCAssocTable), + 'Mu_TRUEPX': + F.VALUE_OR(F.NaN) @ MCTRUTH(mu_px, mctruth.MCAssocTable), + 'NuMu_TRUEPX': + F.VALUE_OR(F.NaN) @ MCTRUTH(nu_px, mctruth.MCAssocTable), + 'Lc_TRUEID': + F.VALUE_OR(-1) @ MCTRUTH(lc_true_id, mctruth.MCAssocTable), + 'Mu_TRUEID': + F.VALUE_OR(-1) @ MCTRUTH(mu_true_id, mctruth.MCAssocTable), + 'NuMu_TRUEID': + F.VALUE_OR(-1) @ MCTRUTH(nu_true_id, mctruth.MCAssocTable) + }) + + variables = {"Lb": lb_variables} + + #define tupling algorithm + my_tuple = Funtuple( + name="Tuple", + tuple_name="DecayTree", + fields=fields, + variables=variables, + inputs=particles) + + return make_config(options, [my_filter, my_tuple]) diff --git a/DaVinciExamples/tests/qmtest/tupling.qms/test_davinci_tupling_unreconstructed_info.qmt b/DaVinciExamples/tests/qmtest/tupling.qms/test_davinci_tupling_unreconstructed_info.qmt new file mode 100644 index 0000000000000000000000000000000000000000..9da33f2235d8d96386fe6de78a57577d1283dcc9 --- /dev/null +++ b/DaVinciExamples/tests/qmtest/tupling.qms/test_davinci_tupling_unreconstructed_info.qmt @@ -0,0 +1,29 @@ +<?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'> +<extension class="GaudiTest.GaudiExeTest" kind="test"> + <argument name="program"><text>lbexec</text></argument> + <argument name="args"><set> + <text>DaVinciExamples.tupling.option_davinci_tupling_unreconstructed_info:main</text> + </set></argument> + <argument name="options_yaml_fn"><text>$DAVINCIEXAMPLESROOT/example_data/Upgrade_LbToLcmunu.yaml</text></argument> + <argument name="extra_options_yaml"><text> + ntuple_file: tuple_LbToLcmunu_unreco.root + print_freq: 1 + </text></argument> + <argument name="reference"><text>../refs/test_davinci_tupling_unreconstructed_info.ref</text></argument> + <argument name="error_reference"><text>../refs/empty.ref</text></argument> + <argument name="validator"><text> + </text></argument> +</extension> diff --git a/DaVinciExamples/tests/refs/test_davinci_tupling_unreconstructed_info.ref b/DaVinciExamples/tests/refs/test_davinci_tupling_unreconstructed_info.ref new file mode 100644 index 0000000000000000000000000000000000000000..cab6d738ae6932e808ba3ff0dcc899e720a5964c --- /dev/null +++ b/DaVinciExamples/tests/refs/test_davinci_tupling_unreconstructed_info.ref @@ -0,0 +1,187 @@ +ApplicationMgr SUCCESS +==================================================================================================================================== + Welcome to DaVinci version 63.0 + running on lxplus772.cern.ch on Thu Nov 10 09:36:38 2022 +==================================================================================================================================== +ApplicationMgr INFO Application Manager Configured successfully +ToolSvc.GitDDDB INFO opening Git repository '/cvmfs/lhcb.cern.ch/lib/lhcb/git-conddb/DDDB.git' +ToolSvc.GitDDDB INFO using commit 'upgrade/dddb-20210617' corresponding to 1871f1bb5c0d68c81dda62e84cf1eb3a45513521 +ToolSvc.GitSIMCOND INFO opening Git repository '/cvmfs/lhcb.cern.ch/lib/lhcb/git-conddb/SIMCOND.git' +ToolSvc.GitSIMCOND INFO using commit 'upgrade/sim-20210617-vc-mu100' corresponding to 869557e04541c3250ce6b4d35ec4bffe66820c60 +DetectorPersistencySvc INFO Added successfully Conversion service:XmlCnvSvc +DetectorDataSvc SUCCESS Detector description database: git:/lhcb.xml +EventClockSvc.FakeEventTime INFO Event times generated from 0 with steps of 0 +EventClockSvc.FakeEventTime INFO Run numbers generated from 0 every 0 events +MagneticFieldGridReader INFO Opened magnetic field file: /cvmfs/lhcb.cern.ch/lib/lhcb/DBASE/FieldMap/v5r7/cdf//field.v5r0.c1.up.cdf +MagneticFieldGridReader INFO Opened magnetic field file: /cvmfs/lhcb.cern.ch/lib/lhcb/DBASE/FieldMap/v5r7/cdf//field.v5r0.c2.up.cdf +MagneticFieldGridReader INFO Opened magnetic field file: /cvmfs/lhcb.cern.ch/lib/lhcb/DBASE/FieldMap/v5r7/cdf//field.v5r0.c3.up.cdf +MagneticFieldGridReader INFO Opened magnetic field file: /cvmfs/lhcb.cern.ch/lib/lhcb/DBASE/FieldMap/v5r7/cdf//field.v5r0.c4.up.cdf +MagneticFieldSvc INFO Map scaled by factor 1 with polarity internally used: 1 signed relative current: 1 +NTupleSvc INFO Added stream file:mytuple.root as FILE1 +HLTControlFlowMgr INFO Start initialization +RootHistSvc INFO Writing ROOT histograms to: mytuple.root +HistogramPersistencySvc INFO Added successfully Conversion service:RootHistSvc +FSROutputStreamDstWriter INFO Data source: EventDataSvc output: SVC='Gaudi::RootCnvSvc' +MCTruthAndBkgCatAlg#1.DaVinciSma... INFO Will look into [/Event/HLT2/Relations/ChargedPP2MCP, /Event/HLT2/Relations/NeutralPP2MCP] +MCTruthAndBkgCatAlg#1.DaVinciSma... INFO Will look into [/Event/HLT2/Relations/ChargedPP2MCP, /Event/HLT2/Relations/NeutralPP2MCP] +MCTruthAndBkgCatAlg#1.Background... INFO Will look into [/Event/HLT2/Relations/ChargedPP2MCP, /Event/HLT2/Relations/NeutralPP2MCP] +HiveDataBrokerSvc WARNING non-reentrant algorithm: RecordStream/FSROutputStreamDstWriter +HLTControlFlowMgr INFO Concurrency level information: +HLTControlFlowMgr INFO o Number of events slots: 1 +HLTControlFlowMgr INFO o TBB thread pool size: 'ThreadPoolSize':1 +HLTControlFlowMgr INFO ---> End of Initialization. This took 14824 ms +ApplicationMgr INFO Application Manager Initialized successfully +FunctorFactory INFO New functor library will be created. +FunctorFactory INFO Compilation of functor library took 28 seconds +DeFTDetector INFO Current FT geometry version = 64 +ApplicationMgr INFO Application Manager Started successfully +EventPersistencySvc INFO Added successfully Conversion service:RootCnvSvc +EventSelector INFO Stream:EventSelector.DataStreamTool_1 Def:DATAFILE='root://eoslhcb.cern.ch//eos/lhcb/wg/dpa/wp3/tests/Upgrade_LbToLcmunu.dst' SVC='Gaudi::RootEvtSelector' OPT='READ' IgnoreChecksum='YES' +HLTControlFlowMgr INFO Will measure time between events 10 and 2147483647 (stop might be some events later) +HLTControlFlowMgr INFO Will measure time between events 10 and 2147483647 (stop might be some events later) +HLTControlFlowMgr INFO Starting loop on events +EventSelector SUCCESS Reading Event record 1. Record number within stream 1: 1 +Hlt2DecReportsDecoder#1 WARNING HltDecReports has a zero TCK, and it is not explicitly specified for decoding -- make sure that this really what you want +HltANNSvc WARNING key 0x00000000 has an explicitly configured overrule -- using that... +HltPackedBufferDecoder WARNING DstData raw bank has a zero encoding key, and it is not explicitly specified for decoding -- make sure that this really what you want +HltANNSvc WARNING key 0x00000000 has an explicitly configured overrule -- using that... +RFileCnv INFO opening Root file "mytuple.root" for writing +RCWNTupleCnv INFO Booked TTree with ID: DecayTree "DecayTree" in directory mytuple.root:/Tuple +EventSelector SUCCESS Reading Event record 2. Record number within stream 1: 2 +Hlt2DecReportsDecoder#1 WARNING HltDecReports has a zero TCK, and it is not explicitly specified for decoding -- make sure that this really what you want +HltPackedBufferDecoder WARNING DstData raw bank has a zero encoding key, and it is not explicitly specified for decoding -- make sure that this really what you want +EventSelector SUCCESS Reading Event record 3. Record number within stream 1: 3 +Hlt2DecReportsDecoder#1 WARNING HltDecReports has a zero TCK, and it is not explicitly specified for decoding -- make sure that this really what you want +HltPackedBufferDecoder WARNING DstData raw bank has a zero encoding key, and it is not explicitly specified for decoding -- make sure that this really what you want +EventSelector SUCCESS Reading Event record 4. Record number within stream 1: 4 +Hlt2DecReportsDecoder#1 WARNING HltDecReports has a zero TCK, and it is not explicitly specified for decoding -- make sure that this really what you want +HltPackedBufferDecoder WARNING DstData raw bank has a zero encoding key, and it is not explicitly specified for decoding -- make sure that this really what you want +EventSelector SUCCESS Reading Event record 5. Record number within stream 1: 5 +Hlt2DecReportsDecoder#1 WARNING HltDecReports has a zero TCK, and it is not explicitly specified for decoding -- make sure that this really what you want +HltPackedBufferDecoder WARNING DstData raw bank has a zero encoding key, and it is not explicitly specified for decoding -- make sure that this really what you want +EventSelector SUCCESS Reading Event record 6. Record number within stream 1: 6 +Hlt2DecReportsDecoder#1 WARNING HltDecReports has a zero TCK, and it is not explicitly specified for decoding -- make sure that this really what you want +HltPackedBufferDecoder WARNING DstData raw bank has a zero encoding key, and it is not explicitly specified for decoding -- make sure that this really what you want +EventSelector SUCCESS Reading Event record 7. Record number within stream 1: 7 +Hlt2DecReportsDecoder#1 WARNING HltDecReports has a zero TCK, and it is not explicitly specified for decoding -- make sure that this really what you want +HltPackedBufferDecoder WARNING DstData raw bank has a zero encoding key, and it is not explicitly specified for decoding -- make sure that this really what you want +HLTControlFlowMgr INFO No more events in event selection +HLTControlFlowMgr INFO ---> Loop over 7 Events Finished - WSS 1506.22, timing failed.. +Hlt2DecReportsDecoder#1 INFO Number of counters : 1 + | Counter | # | sum | mean/eff^* | rms/err^* | min | max | + | " HltDecReports has a zero TCK, and it is not explicitly specified for decoding -- make sure that this really what you want"| 7 | +HltPackedBufferDecoder INFO Number of counters : 1 + | Counter | # | sum | mean/eff^* | rms/err^* | min | max | + | " DstData raw bank has a zero encoding key, and it is not explicitly specified for decoding -- make sure that this really what you want"| 7 | +MCTruthAndBkgCatAlg#1 INFO Number of counters : 3 + | Counter | # | sum | mean/eff^* | rms/err^* | min | max | + | "Events" | 7 | + | "Ghosts" | 2 | 0 | 0.0000 | 0.0000 | 4.2950e+09 | 0.0000 | + | "Particles" | 48 | 0 | 0.0000 | 0.0000 | 4.2950e+09 | 0.0000 | +Myfilter INFO Number of counters : 1 + | Counter | # | sum | mean/eff^* | rms/err^* | min | max | + |*"#passed" | 7 | 7 |( 100.0000 +- 0.000000)% | +PP2MCPRelationUnpacker INFO Number of counters : 1 + | Counter | # | sum | mean/eff^* | rms/err^* | min | max | + | "# PackedData" | 7 | 34 | 4.8571 | +PP2MCPRelationUnpacker#1 INFO Number of counters : 1 + | Counter | # | sum | mean/eff^* | rms/err^* | min | max | + | "# AbsentBuffer" | 7 | 0 | 0.0000 | +ParticleUnpacker INFO Number of counters : 2 + | Counter | # | sum | mean/eff^* | rms/err^* | min | max | + | "# Linked BufferData" | 84 | 66484 | 791.48 | + | "# UnpackedData" | 14 | 1850 | 132.14 | +ProtoParticleUnpacker#1 INFO Number of counters : 1 + | Counter | # | sum | mean/eff^* | rms/err^* | min | max | + | "# AbsentBuffer" | 7 | 0 | 0.0000 | +ToolSvc.HltFactory INFO Number of counters : 1 + | Counter | # | sum | mean/eff^* | rms/err^* | min | max | + | "# loaded from PYTHON" | 1 | +Tuple INFO Number of counters : 3 + | Counter | # | sum | mean/eff^* | rms/err^* | min | max | + | "# events with multiple candidates for field Lb"| 1 | + | "# non-empty events for field Lb" | 7 | + | "# processed events" | 7 | +ApplicationMgr INFO Application Manager Stopped successfully +FSROutputStreamDstWriter INFO Set up File Summary Record +FSROutputStreamDstWriter INFO Events output: 1 +Tuple SUCCESS Booked 1 N-Tuples and 0 Event Tag Collections +Tuple SUCCESS List of booked N-Tuples in directory "FILE1/Tuple" +Tuple SUCCESS ID=DecayTree Title="DecayTree" #items=7 {Lb_TRUEPX,Lb_Lc_TRUEPX,Lb_Mu_TRUEPX,Lb_NuMu_TRUEPX,Lb_Lc_TRUEID,Lb_Mu_TRUEID,Lb_N} +HLTControlFlowMgr INFO Memory pool: used 0.00115095 +/- 0.000104943 MiB (min: 0, max: 0) in 1 +/- 0 blocks (allocated >once in 0 +/- 0% events). Allocated capacity was 10 +/- 0 MiB (min: 10, max: 10) and 12 +/- 0.92582 (min: 11, max: 18) requests were served +HLTControlFlowMgr INFO Timing table: +HLTControlFlowMgr INFO + | Name of Algorithm | Execution Count | Total Time / s | Avg. Time / us | + | Sum of all Algorithms | 7 | 3.938 | 562636.571 | + | "MCTruthAndBkgCatAlg#1" | 7 | 0.843 | 120392.369 | + | "Tuple" | 7 | 0.838 | 119771.972 | + | "ParticleUnpacker" | 7 | 0.584 | 83436.092 | + | "Gaudi__Hive__FetchDataFromFile" | 7 | 0.414 | 59115.311 | + | "Hlt2DecReportsDecoder#1" | 7 | 0.356 | 50881.069 | + | "UnpackMCVertex" | 7 | 0.277 | 39515.919 | + | "HltPackedBufferDecoder" | 7 | 0.266 | 38004.067 | + | "Myfilter" | 7 | 0.091 | 13028.560 | + | "reserveIOV" | 7 | 0.087 | 12500.015 | + | "DummyEventTime" | 7 | 0.066 | 9417.528 | + | "PP2MCPRelationUnpacker" | 7 | 0.053 | 7637.222 | + | "LHCb__UnpackRawEvent#2" | 7 | 0.043 | 6165.710 | + | "FSROutputStreamDstWriter" | 7 | 0.018 | 2607.787 | + | "UnpackMCParticle" | 7 | 0.001 | 110.716 | + | "PP2MCPRelationUnpacker#1" | 7 | 0.000 | 18.012 | + | "ProtoParticleUnpacker#1" | 7 | 0.000 | 11.990 | + | "ProtoParticleUnpacker" | 7 | 0.000 | 11.169 | + | "LHCb__UnpackRawEvent#3" | 7 | 0.000 | 7.912 | + | "Gaudi__Hive__FetchDataFromFile#8" | 7 | 0.000 | 3.173 | + | "Gaudi__Hive__FetchDataFromFile#7" | 7 | 0.000 | 1.371 | + +HLTControlFlowMgr INFO StateTree: CFNode #executed #passed +LAZY_AND: DaVinci #=7 Sum=7 Eff=|( 100.0000 +- 0.00000 )%| + NONLAZY_OR: FileSummaryRecords #=7 Sum=7 Eff=|( 100.0000 +- 0.00000 )%| + LAZY_AND: GenFSR #=7 Sum=7 Eff=|( 100.0000 +- 0.00000 )%| + RecordStream/FSROutputStreamDstWriter #=7 Sum=7 Eff=|( 100.0000 +- 0.00000 )%| + NONLAZY_OR: UserAnalysis #=7 Sum=7 Eff=|( 100.0000 +- 0.00000 )%| + LAZY_AND: default #=7 Sum=7 Eff=|( 100.0000 +- 0.00000 )%| + LoKi__HDRFilter/Myfilter #=7 Sum=7 Eff=|( 100.0000 +- 0.00000 )%| + FunTupleBase_Particles/Tuple #=7 Sum=7 Eff=|( 100.0000 +- 0.00000 )%| + +HLTControlFlowMgr INFO Histograms converted successfully according to request. +ToolSvc INFO Removing all tools created by ToolSvc +RootCnvSvc INFO Disconnected data IO:5BF389D0-0E09-11ED-888E-0025900CE178 [root://eoslhcb.cern.ch//eos/lhcb/wg/dpa/wp3/tests/Upgrade_LbToLcmunu.dst] +RFileCnv INFO dumping contents of /NTUPLES/FILE1 +TFile: name=mytuple.root, title=Gaudi Trees, option=CREATE +****************************************************************************** +*Tree :DecayTree : DecayTree * +*Entries : 8 : Total = 4858 bytes File Size = 1569 * +* : : Tree compression factor = 1.00 * +****************************************************************************** +*Br 0 :Lb_TRUEPX : Lb_TRUEPX/F * +*Entries : 8 : Total Size= 622 bytes File Size = 113 * +*Baskets : 1 : Basket Size= 32000 bytes Compression= 1.00 * +*............................................................................* +*Br 1 :Lb_Lc_TRUEPX : Lb_Lc_TRUEPX/F * +*Entries : 8 : Total Size= 637 bytes File Size = 116 * +*Baskets : 1 : Basket Size= 32000 bytes Compression= 1.00 * +*............................................................................* +*Br 2 :Lb_Mu_TRUEPX : Lb_Mu_TRUEPX/F * +*Entries : 8 : Total Size= 637 bytes File Size = 116 * +*Baskets : 1 : Basket Size= 32000 bytes Compression= 1.00 * +*............................................................................* +*Br 3 :Lb_NuMu_TRUEPX : Lb_NuMu_TRUEPX/F * +*Entries : 8 : Total Size= 647 bytes File Size = 118 * +*Baskets : 1 : Basket Size= 32000 bytes Compression= 1.00 * +*............................................................................* +*Br 4 :Lb_Lc_TRUEID : Lb_Lc_TRUEID/I * +*Entries : 8 : Total Size= 637 bytes File Size = 116 * +*Baskets : 1 : Basket Size= 32000 bytes Compression= 1.00 * +*............................................................................* +*Br 5 :Lb_Mu_TRUEID : Lb_Mu_TRUEID/I * +*Entries : 8 : Total Size= 637 bytes File Size = 116 * +*Baskets : 1 : Basket Size= 32000 bytes Compression= 1.00 * +*............................................................................* +*Br 6 :Lb_NuMu_TRUEID : Lb_NuMu_TRUEID/I * +*Entries : 8 : Total Size= 647 bytes File Size = 118 * +*Baskets : 1 : Basket Size= 32000 bytes Compression= 1.00 * +*............................................................................* +NTupleSvc INFO NTuples saved successfully +ApplicationMgr INFO Application Manager Finalized successfully +ApplicationMgr INFO Application Manager Terminated successfully