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

Add P2GT decisions to L1Nano #1179

Open
artlbv opened this issue Nov 15, 2023 · 4 comments
Open

Add P2GT decisions to L1Nano #1179

artlbv opened this issue Nov 15, 2023 · 4 comments
Labels
Ntuplisation Anything to do with Ntuples produced with L1 content Phase-2 Pertains to phase-2 development

Comments

@artlbv
Copy link

artlbv commented Nov 15, 2023

The goal is to store the P2GT emulator trigger decisions in the L1Nano as done for Phase-1, e.g. having one branch L1_SingleMu22 per trigger seed. For reference: the Phase-2L1Nano setup is here: https://github.com/cms-l1-dpg/Phase2-L1Nano

For phase-1 there is a dedicated producer L1TriggerResultsConverter used in the Nano that dumps the GT trigger seed decisions to individual branches:
https://github.com/cms-sw/cmssw/blob/master/PhysicsTools/NanoAOD/python/triggerObjects_cff.py#L375-L379
The source code is here: https://github.com/cms-sw/cmssw/blob/master/PhysicsTools/NanoAOD/plugins/L1TriggerResultsConverter.cc

Hence I imagine we would need to write something similar for the P2GT->Nano conversion.

I briefly discussed/shared this with the P2GT team (Elias @qvyz , Benjamin, Hannes, Dinyar and Jaana @jheikkil ) and they were agreeing with this.

@aloeliger @epalencia, could you provide some support for this?

cc @mcepeda

Some more technical information below:

Within CMSSW the P2GT "algorithm block" decisions can be accesses as described here:
https://twiki.cern.ch/twiki/bin/viewauth/CMS/PhaseIIL1TriggerMenuTools#Accessing_the_trigger_decision_o
and here: https://twiki.cern.ch/twiki/pub/CMS/PhaseIIL1TriggerMenuTools/P2GTEmulator-AlgoBlock.pdf

#############Access the correct collection#############
token_(consumes<std::vector<P2GTAlgoBlock>>(edm::InputTag("l1tGTAlgoBlockProducer")));
const std::vector<P2GTAlgoBlock>& algos = event.get(token_);

#############Accessing trigger decision needed for each seed, here we show two as an example##############

for (const P2GTAlgoBlock& algo : algos) {
    if (algo.algoName() == "pSingleTkMuon22") {
        bool result = algo.decisionBeforeBxMaskAndPrescale();
        const P2GTCandidateVectorRef& objects = algo.trigObjects();
    } else if (algo.algoName() == "pDoubleTkMuon15_7") {
        bool result = algo.decisionBeforeBxMaskAndPrescale();
        const P2GTCandidateVectorRef& objects = algo.trigObjects();
    }  
}

With uproot one can read the decisions from the EDM/FEVT file like this:

with uproot.open(fname) as f:
        decisions_arr = f["Events"].arrays(filter_name = f"*l1tGTAlgoBlockProducer__{prod}.obj.decisionFinal_")
        gt_final = ak.to_regular(decisions_arr[f'l1tP2GTAlgoBlocks_l1tGTAlgoBlockProducer__{prod}.obj.decisionFinal_'])
        gt_final = gt_final.to_numpy()

One does however not know the order of the seeds directly here unlike in the Phase-1 version, where the algorithm seed names are encoded in the TTree aliases, but instead through the CMSSW accessor algo.algoName().
This can be done in FWlite as shown here:
https://github.com/cms-sw/cmssw/blob/master/L1Trigger/Phase2L1GT/test/menu_analyzer.py#L68C28-L68C36

@aloeliger aloeliger added Phase-2 Pertains to phase-2 development Ntuplisation Anything to do with Ntuples produced with L1 content labels Nov 15, 2023
@HaarigerHarald
Copy link

Hi @artlbv,

I think there is a bug in uproot. If you remove the const qualifier of the l1t::P2GTAlgoBlock name_ member, the following piece of code works and fetches the algorithm names.

with uproot.open("l1t_emulation.root") as f:
    arr = f["Events"].arrays(filter_name = f"l1tP2GTAlgoBlocks_l1tGTAlgoBlockProducer__{prod}.obj.algoName_")
    print(ak.to_regular(arr)[f"l1tP2GTAlgoBlocks_l1tGTAlgoBlockProducer__{prod}.obj.algoName_"][0])

I'll check the uproot source code.

@artlbv
Copy link
Author

artlbv commented Nov 16, 2023

Thanks for this @HaarigerHarald though the issue here is to get the trigger bits into "CMSSW Nano".
I don't think we can dump the P2GT decision in "EDM" format into nano...

@artlbv
Copy link
Author

artlbv commented Nov 28, 2023

An update:

First, one can use the SingleFlatTableProducer for the P2GT AlgoBlock with:

#include "DataFormats/L1Trigger/interface/P2GTAlgoBlock.h"
typedef SimpleFlatTableProducer<l1t::P2GTAlgoBlock> P2GTAlgoBlockFlatTableProducer;

And then in the cff:

gtAlgoTable = cms.EDProducer(
    "P2GTAlgoBlockFlatTableProducer",
    src = cms.InputTag('l1tGTAlgoBlockProducer'),
    cut = cms.string(""),
    name = cms.string("L1GT"),
    doc = cms.string("GT Algo Block decisions"),
    singleton = cms.bool(False), # the number of entries is variable
    variables = cms.PSet(
        name = Var("algoName",string, doc = "algo name"),
        final = Var("decisionFinal",float, doc = "final decision"),
        initial = Var("decisionBeforeBxMaskAndPrescale_",float, doc = "initial decision"),
    )
)

Next, the names need to be added and we discussed different options with @aloeliger, @qvyz and @HaarigerHarald
We might get inspiration from the HLT trigger converter to Nano: https://github.com/cms-sw/cmssw/blob/master/PhysicsTools/NanoAOD/plugins/TriggerOutputBranches.cc

(this is for L1: https://github.com/cms-sw/cmssw/blob/master/PhysicsTools/NanoAOD/plugins/L1TriggerResultsConverter.cc)

Alternatively, one would need to save the trigger names differently e.g. through the meta data or even the table producer.

@HaarigerHarald
Copy link

HaarigerHarald commented Feb 15, 2024

An equivalent to L1TriggerResultsConverter now exists in #1207 which can be added to the configuration as:

process.l1tP2GTTrigConvert = cms.EDProducer("P2GTTriggerResultsConverter",
    src = cms.InputTag("l1tGTAlgoBlockProducer")
    prefix = cms.string("L1_"),     # can be anything or omitted, default: "L1_" 
    decision = cms.string("final"), # can be "beforeBxMaskAndPrescale", "beforePrescale", "final" or omitted, default: "final"
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ntuplisation Anything to do with Ntuples produced with L1 content Phase-2 Pertains to phase-2 development
Projects
None yet
Development

No branches or pull requests

3 participants