finnlabe / B2G_TriggerEfficiencies

Code to measure trigger efficiencies for the B2G subgroup of the CMS experiment
3 stars 4 forks source link

Error loading ROOT files with multiple TTrees: Need to specify 'treepath' when using NanoEventsFactory #2

Open teteumac opened 1 week ago

teteumac commented 1 week ago

Dear users, I am using your code to work efficiently with the trigger in my study, however, when I download the repository to my lxplus directory and run the command

python3 runTriggerEfficiencies.py -i example/local/inputfiles.txt -r example/local/refTriggers.txt -t example/local/testTriggers.txt -e 22RunD --doJECs --useGoldenJSON

without making any changes. However, it gives me this error

[matheus@lxplus929 B2G_TriggerEfficiencies]$ python3 runTriggerEfficiencies.py -i example/local/inputfiles.txt -r example/local/refTriggers.txt -t example/local/testTriggers.txt -e 22RunD --doJECs --useGoldenJSON

###########################################################################

Creating histograms for efficiency calculation with the following settings:

  • era: 22RunD
  • reference triggers: IsoMu24, Mu50
  • triggers to measure: AK8PFJet420_MassSD30, AK8PFJet500, PFHT1050
  • re-applying JECs from data/corrections/jets_22RunD/
  • applying goldenJSON selection using data/goldenJSON/Cert_Collisions2022_355100_362760_Golden.json

    ###########################################################################

Starting to loop over input files... Starting to process root://xrootd-cms.infn.it//store/data/Run2022C/Muon/NANOAOD/PromptNanoAODv10-v1/2520000/babb9173-53e2-426f-b3d1-f47b0f2f7a60.root. /afs/cern.ch/user/m/matheus/.local/lib/python3.9/site-packages/coffea/nanoevents/methods/candidate.py:11: FutureWarning: In version 2025.1.0 (target date: 2024-12-31 11:59:59-06:00), this will be an error. To raise these warnings as errors (and get stack traces to find out where they're called), run import warnings warnings.filterwarnings("error", module="coffea.") after the first import coffea or use `@pytest.mark.filterwarnings("error:::coffea.")` in pytest. Issue: coffea.nanoevents.methods.vector will be removed and replaced with scikit-hep vector. Nanoevents schemas internal to coffea will be migrated. Otherwise please consider using that package!. from coffea.nanoevents.methods import vector Traceback (most recent call last): File "/afs/cern.ch/user/m/matheus/B2G_TriggerEfficiencies/runTriggerEfficiencies.py", line 95, in names, binnings, values, masks = run_multiple_files(inputfiles, File "/afs/cern.ch/user/m/matheus/B2G_TriggerEfficiencies/core.py", line 226, in run_multiple_files names, binnings, values, masks = run_one_file(inputfile, File "/afs/cern.ch/user/m/matheus/B2G_TriggerEfficiencies/core.py", line 23, in run_one_file events = NanoEventsFactory.from_root( File "/afs/cern.ch/user/m/matheus/.local/lib/python3.9/site-packages/coffea/nanoevents/factory.py", line 684, in events events = self._mapping(form_mapping=self._schema) File "/afs/cern.ch/user/m/matheus/.local/lib/python3.9/site-packages/uproot/_dask.py", line 296, in dask return _get_dak_array_delay_open( File "/afs/cern.ch/user/m/matheus/.local/lib/python3.9/site-packages/uproot/_dask.py", line 1595, in _get_dak_array_delay_open obj = uproot._util.regularize_object_path( File "/afs/cern.ch/user/m/matheus/.local/lib/python3.9/site-packages/uproot/_util.py", line 982, in regularize_object_path raise ValueError( ValueError: TTree object paths must be specified in the 'files' as {"filenames*.root": "path"} if any files have more than one TTree

TTrees: 'Events', 'LuminosityBlocks', 'Runs', 'MetaData', 'ParameterSets'

in file root://xrootd-cms.infn.it:1094//store/data/Run2022C/Muon/NANOAOD/PromptNanoAODv10-v1/2520000/babb9173-53e2-426f-b3d1-f47b0f2f7a60.root

Can you help me try to solve this problem?

finnlabe commented 1 week ago

Hi, I have never seen this before, but assume that this might be related to the version of certain packages you are using. Could you let me know what versions of coffea, uproot and awkward you are using?

Did you do source /cvmfs/sft-nightlies.cern.ch/lcg/views/dev3/latest/x86_64-centos7-gcc11-opt/setup.sh?

teteumac commented 1 week ago

Hi. This environment no longer exists for the sl7 architecture, now only these environments are available:


arm64-mac12-clang140-opt  x86_64-el8-gcc11-opt    x86_64-el9-clang16-opt  x86_64-el9-gcc12-dbg  x86_64-el9-gcc13-dbg  x86_64-el9-gcc14fp-opt  x86_64-ubuntu2004-gcc9-opt
arm64-mac13-clang150-opt  x86_64-el9-clang16-dbg  x86_64-el9-gcc11-opt    x86_64-el9-gcc12-opt  x86_64-el9-gcc13-opt  x86_64-el9-gcc14-opt    x86_64-ubuntu2204-gcc11-opt

For the versions, I have Name: coffea Version: 2024.8.3


Name: uproot Version: 5.3.12


Name: awkward Version: 2.6.7

Best, Matheus Macedo

finnlabe commented 1 week ago

Hi, this is what I assumed. The tool was written a while back and has not (as far as I know) been used for a while. So it only ever was run under the old el7 architecture, and most likely did not survive the recent OS switch (as most tools did not...)

So there are two options now that I can think of: 1) Running the tool within a singularity container (which you can create with cmssw-el7) 2) Updating the code to run with a newer version of the packages.

The former is easy if you want to run locally, but will most likely not work for submitting condor jobs.

The latter is a bit more involved. In general, the code provided here is meant as an example on how to implement something like this and is not maintained (anymore) for direct usage (at least I am not doing that since I am no longer involved in B2G triggering, and I do not know whether the current contacts still use the tool). Therefore I unfortunately can not fix this for you, but I can help you with some pointers on how one might do so.

The issue arises when reading events with the coffea NanoEventsFactory. If I understand the error message correctly, the tool is complaining that the file contains more than one TTree, and it does not know which one to read. Looking at the NanoEventsFactory method from_root in the documentation, you should be able to pass the TTree which you want to read (probably Events) as an option called treepath. I would suggest to give this a try, maybe this is already enough to fix your problem.

Otherwise, please let me know and we can discuss further!


TL;DR:

Try adding your desired TTree as treepath to the NanoEventsFactory.from_root method here.