MiniAOD triggering
Overview
Teaching: 10 min
Exercises: 10 minQuestions
How can I access trigger information from MiniAOD files?
What are trigger objects?
Objectives
Learn how one can retrieve trigger information like pass/fail bits or prescales from MiniAOD files
Learn what trigger objects are and why they are important
How to access trigger information
We would like to understand the trigger focusing on our final goal, which is to partially reproduce a
- Directly from the data stored in the
MiniAOD
files - By accessing the conditions database
MiniAOD triggering
First make sure to fire up your CMSSW Docker container if you haven’t already:
docker start -i my_od #use the name you gave to yours
cd PhysObjectExtractorTool/PhysObjectExtractor
Investigate the contents of a MiniAOD ROOT file:
edmDumpEventContent root://eospublic.cern.ch//eos/opendata/cms/mc/RunIIFall15MiniAODv2/TT_TuneCUETP8M1_13TeV-powheg-pythia8/MINIAODSIM/PU25nsData2015v1_76X_mcRun2_asymptotic_v12_ext3-v1/00000/02837459-03C2-E511-8EA2-002590A887AC.root
Type Module Label Process
----------------------------------------------------------------------------------------------
LHEEventProduct "externalLHEProducer" "" "LHE"
GenEventInfoProduct "generator" "" "SIM"
edm::TriggerResults "TriggerResults" "" "SIM"
edm::TriggerResults "TriggerResults" "" "HLT"
HcalNoiseSummary "hcalnoise" "" "RECO"
L1GlobalTriggerReadoutRecord "gtDigis" "" "RECO"
double "fixedGridRhoAll" "" "RECO"
double "fixedGridRhoFastjetAll" "" "RECO"
double "fixedGridRhoFastjetAllCalo" "" "RECO"
double "fixedGridRhoFastjetCentral" "" "RECO"
double "fixedGridRhoFastjetCentralCalo" "" "RECO"
double "fixedGridRhoFastjetCentralChargedPileUp" "" "RECO"
double "fixedGridRhoFastjetCentralNeutral" "" "RECO"
edm::TriggerResults "TriggerResults" "" "RECO"
reco::BeamHaloSummary "BeamHaloSummary" "" "RECO"
reco::BeamSpot "offlineBeamSpot" "" "RECO"
vector<l1extra::L1EmParticle> "l1extraParticles" "Isolated" "RECO"
vector<l1extra::L1EmParticle> "l1extraParticles" "NonIsolated" "RECO"
vector<l1extra::L1EtMissParticle> "l1extraParticles" "MET" "RECO"
vector<l1extra::L1EtMissParticle> "l1extraParticles" "MHT" "RECO"
vector<l1extra::L1HFRings> "l1extraParticles" "" "RECO"
vector<l1extra::L1JetParticle> "l1extraParticles" "Central" "RECO"
vector<l1extra::L1JetParticle> "l1extraParticles" "Forward" "RECO"
vector<l1extra::L1JetParticle> "l1extraParticles" "IsoTau" "RECO"
vector<l1extra::L1JetParticle> "l1extraParticles" "Tau" "RECO"
vector<l1extra::L1MuonParticle> "l1extraParticles" "" "RECO"
edm::SortedCollection<EcalRecHit,edm::StrictWeakOrdering<EcalRecHit> > "reducedEgamma" "reducedEBRecHits" "PAT"
edm::SortedCollection<EcalRecHit,edm::StrictWeakOrdering<EcalRecHit> > "reducedEgamma" "reducedEERecHits" "PAT"
edm::SortedCollection<EcalRecHit,edm::StrictWeakOrdering<EcalRecHit> > "reducedEgamma" "reducedESRecHits" "PAT"
edm::TriggerResults "TriggerResults" "" "PAT"
edm::ValueMap<float> "offlineSlimmedPrimaryVertices" "" "PAT"
pat::PackedTriggerPrescales "patTrigger" "" "PAT"
pat::PackedTriggerPrescales "patTrigger" "l1max" "PAT"
pat::PackedTriggerPrescales "patTrigger" "l1min" "PAT"
vector<PileupSummaryInfo> "slimmedAddPileupInfo" "" "PAT"
vector<pat::Electron> "slimmedElectrons" "" "PAT"
vector<pat::Jet> "slimmedJets" "" "PAT"
vector<pat::Jet> "slimmedJetsAK8" "" "PAT"
vector<pat::Jet> "slimmedJetsPuppi" "" "PAT"
vector<pat::Jet> "slimmedJetsAK8PFCHSSoftDropPacked" "SubJets" "PAT"
vector<pat::Jet> "slimmedJetsCMSTopTagCHSPacked" "SubJets" "PAT"
vector<pat::MET> "slimmedMETs" "" "PAT"
vector<pat::MET> "slimmedMETsPuppi" "" "PAT"
vector<pat::Muon> "slimmedMuons" "" "PAT"
vector<pat::PackedCandidate> "lostTracks" "" "PAT"
vector<pat::PackedCandidate> "packedPFCandidates" "" "PAT"
vector<pat::PackedGenParticle> "packedGenParticles" "" "PAT"
vector<pat::Photon> "slimmedPhotons" "" "PAT"
vector<pat::Tau> "slimmedTaus" "" "PAT"
vector<pat::TriggerObjectStandAlone> "selectedPatTrigger" "" "PAT"
vector<reco::CATopJetTagInfo> "caTopTagInfosPAT" "" "PAT"
vector<reco::CaloCluster> "reducedEgamma" "reducedEBEEClusters" "PAT"
vector<reco::CaloCluster> "reducedEgamma" "reducedESClusters" "PAT"
vector<reco::Conversion> "reducedEgamma" "reducedConversions" "PAT"
vector<reco::Conversion> "reducedEgamma" "reducedSingleLegConversions" "PAT"
vector<reco::GenJet> "slimmedGenJets" "" "PAT"
vector<reco::GenJet> "slimmedGenJetsAK8" "" "PAT"
vector<reco::GenParticle> "prunedGenParticles" "" "PAT"
vector<reco::GsfElectronCore> "reducedEgamma" "reducedGedGsfElectronCores" "PAT"
vector<reco::PhotonCore> "reducedEgamma" "reducedGedPhotonCores" "PAT"
vector<reco::SuperCluster> "reducedEgamma" "reducedSuperClusters" "PAT"
vector<reco::Vertex> "offlineSlimmedPrimaryVertices" "" "PAT"
vector<reco::VertexCompositePtrCandidate> "slimmedSecondaryVertices" "" "PAT"
There are various entries of type edm::TriggerResults
, but we are specifically interested in the one labelled “PAT”.
In the “PAT” collection section we also find selectedPatTrigger
and patTrigger
collections.
Although we do not have such analyzer yet, we know where to find information on how to implement it. If we go to the WorkBookMiniAOD2015 CMS Twiki page, we will find the relevant information necessary to our purposes. Let’s have a look.
As you can see, an example is already provided on how to build such an analyzer with its corresponding configuration.
We have copied the analyzer example here for you:
// system include files
#include <memory>
#include <cmath>
// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "DataFormats/Math/interface/deltaR.h"
#include "FWCore/Common/interface/TriggerNames.h"
#include "DataFormats/Common/interface/TriggerResults.h"
#include "DataFormats/PatCandidates/interface/TriggerObjectStandAlone.h"
#include "DataFormats/PatCandidates/interface/PackedTriggerPrescales.h"
class MiniAODTriggerAnalyzer : public edm::EDAnalyzer {
public:
explicit MiniAODTriggerAnalyzer(const edm::ParameterSet&);
~MiniAODTriggerAnalyzer() {}
private:
virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
edm::EDGetTokenT<edm::TriggerResults> triggerBits_;
edm::EDGetTokenT<pat::TriggerObjectStandAloneCollection> triggerObjects_;
edm::EDGetTokenT<pat::PackedTriggerPrescales> triggerPrescales_;
};
MiniAODTriggerAnalyzer::MiniAODTriggerAnalyzer(const edm::ParameterSet& iConfig):
triggerBits_(consumes<edm::TriggerResults>(iConfig.getParameter<edm::InputTag>("bits"))),
triggerObjects_(consumes<pat::TriggerObjectStandAloneCollection>(iConfig.getParameter<edm::InputTag>("objects"))),
triggerPrescales_(consumes<pat::PackedTriggerPrescales>(iConfig.getParameter<edm::InputTag>("prescales")))
{
}
void MiniAODTriggerAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
{
edm::Handle<edm::TriggerResults> triggerBits;
edm::Handle<pat::TriggerObjectStandAloneCollection> triggerObjects;
edm::Handle<pat::PackedTriggerPrescales> triggerPrescales;
iEvent.getByToken(triggerBits_, triggerBits);
iEvent.getByToken(triggerObjects_, triggerObjects);
iEvent.getByToken(triggerPrescales_, triggerPrescales);
const edm::TriggerNames &names = iEvent.triggerNames(*triggerBits);
std::cout << "\n === TRIGGER PATHS === " << std::endl;
for (unsigned int i = 0, n = triggerBits->size(); i < n; ++i) {
std::cout << "Trigger " << names.triggerName(i) <<
", prescale " << triggerPrescales->getPrescaleForIndex(i) <<
": " << (triggerBits->accept(i) ? "PASS" : "fail (or not run)")
<< std::endl;
}
std::cout << "\n === TRIGGER OBJECTS === " << std::endl;
for (pat::TriggerObjectStandAlone obj : *triggerObjects) { // note: not "const &" since we want to call unpackPathNames
obj.unpackPathNames(names);
std::cout << "\tTrigger object: pt " << obj.pt() << ", eta " << obj.eta() << ", phi " << obj.phi() << std::endl;
// Print trigger object collection and type
std::cout << "\t Collection: " << obj.collection() << std::endl;
std::cout << "\t Type IDs: ";
for (unsigned h = 0; h < obj.filterIds().size(); ++h) std::cout << " " << obj.filterIds()[h] ;
std::cout << std::endl;
// Print associated trigger filters
std::cout << "\t Filters: ";
for (unsigned h = 0; h < obj.filterLabels().size(); ++h) std::cout << " " << obj.filterLabels()[h];
std::cout << std::endl;
std::vector<std::string> pathNamesAll = obj.pathNames(false);
std::vector<std::string> pathNamesLast = obj.pathNames(true);
// Print all trigger paths, for each one record also if the object is associated to a 'l3' filter (always true for the
// definition used in the PAT trigger producer) and if it's associated to the last filter of a successfull path (which
// means that this object did cause this trigger to succeed; however, it doesn't work on some multi-object triggers)
std::cout << "\t Paths (" << pathNamesAll.size()<<"/"<<pathNamesLast.size()<<"): ";
for (unsigned h = 0, n = pathNamesAll.size(); h < n; ++h) {
bool isBoth = obj.hasPathName( pathNamesAll[h], true, true );
bool isL3 = obj.hasPathName( pathNamesAll[h], false, true );
bool isLF = obj.hasPathName( pathNamesAll[h], true, false );
bool isNone = obj.hasPathName( pathNamesAll[h], false, false );
std::cout << " " << pathNamesAll[h];
if (isBoth) std::cout << "(L,3)";
if (isL3 && !isBoth) std::cout << "(*,3)";
if (isLF && !isBoth) std::cout << "(L,*)";
if (isNone && !isBoth && !isL3 && !isLF) std::cout << "(*,*)";
}
std::cout << std::endl;
}
std::cout << std::endl;
}
//define this as a plug-in
DEFINE_FWK_MODULE(MiniAODTriggerAnalyzer);
And the configuration file from where we can snatch a valid snippet for our stolen analyzer:
import FWCore.ParameterSet.Config as cms
process = cms.Process("Demo")
process.load("FWCore.MessageService.MessageLogger_cfi")
process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(10) )
process.source = cms.Source("PoolSource",
fileNames = cms.untracked.vstring(
'/store/cmst3/user/gpetrucc/miniAOD/v1/TT_Tune4C_13TeV-pythia8-tauola_PU_S14_PAT.root'
)
)
process.demo = cms.EDAnalyzer("MiniAODTriggerAnalyzer",
bits = cms.InputTag("TriggerResults","","HLT"),
prescales = cms.InputTag("patTrigger"),
objects = cms.InputTag("selectedPatTrigger"),
)
process.p = cms.Path(process.demo)
Prep the MiniAODTriggerAnalyzer (Optional / Offline)
Let’s create a
src/MiniAODTriggerAnalyzer.cc
from scratch! From your local directory just open up your favorite editor and copy paste the code. Save it and compile withscram b
, as always.Now, let’s add the python module that we need to configure it to our
python/poet_cfg.py
file. We will call itmyminiaodtrig
instead ofdemo
. From your local directory open thepython/poet_cfg.py
configuration file and add this module just before theprocess.simpletrig
module (this is just to keep things organized).Check your editing:
Now let’s make sure it runs in the CMSSW path at the end of the configuration file. Let’s just add it to both options Data or MC. Make sure you add it to the beginning of the sequence. This is because we need to avoid the intial filters that are already in place (more on this later).
Check your editing:
Lets do just one more change before we get to run POET. Let’s print out for each event, we can achive that by changing the
MessageLogger
lines to:#---- Configure the framework messaging system #---- https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideMessageLogger process.load("FWCore.MessageService.MessageLogger_cfi") #process.MessageLogger.cerr.threshold = "WARNING" #process.MessageLogger.categories.append("POET") #process.MessageLogger.cerr.INFO = cms.untracked.PSet( # limit=cms.untracked.int32(-1)) #process.options = cms.untracked.PSet(wantSummary=cms.untracked.bool(True)) process.MessageLogger.cerr.FwkReport.reportEvery = 1
I.e., comment out most of the lines leaving on only the first one and adding the
process.MessageLogger.cerr.FwkReport.reportEvery = 1
line.
Trigger dump from MiniAOD (Optional / Offline)
Now, let’s run with
cmsRun python/poet_cfg.py True
. We will get a lot of print-outs. Let’s check the printout for the last event:View dump
So, we not only get the triggers and their pass/fail status, but also the prescales and the possible trigger objects associated with them (associated with their trigger filters).
Trigger objects
Let’s explore the code which prints the last part to understand what it means. The HLT is like a reconstruction algorithm capable of identifying particles very very fast. Therefore, an HLT muon, for example, is a trigger object that has a four momentum. These trigger objects are associated to, commonly, the last filter executed by a given path in the HLT. Usually one wants to check whether a given particle that is being used in a given analysis coincides with the trigger object that fired the trigger (this is called trigger matching). We won’t go into more details about that.
std::cout << "\n === TRIGGER OBJECTS === " << std::endl;
for (pat::TriggerObjectStandAlone obj : *triggerObjects) { // note: not "const &" since we want to call unpackPathNames
obj.unpackPathNames(names);
std::cout << "\tTrigger object: pt " << obj.pt() << ", eta " << obj.eta() << ", phi " << obj.phi() << std::endl;
// Print trigger object collection and type
std::cout << "\t Collection: " << obj.collection() << std::endl;
std::cout << "\t Type IDs: ";
for (unsigned h = 0; h < obj.filterIds().size(); ++h) std::cout << " " << obj.filterIds()[h] ;
std::cout << std::endl;
// Print associated trigger filters
std::cout << "\t Filters: ";
for (unsigned h = 0; h < obj.filterLabels().size(); ++h) std::cout << " " << obj.filterLabels()[h];
std::cout << std::endl;
std::vector<std::string> pathNamesAll = obj.pathNames(false);
std::vector<std::string> pathNamesLast = obj.pathNames(true);
// Print all trigger paths, for each one record also if the object is associated to a 'l3' filter (always true for the
// definition used in the PAT trigger producer) and if it's associated to the last filter of a successfull path (which
// means that this object did cause this trigger to succeed; however, it doesn't work on some multi-object triggers)
std::cout << "\t Paths (" << pathNamesAll.size()<<"/"<<pathNamesLast.size()<<"): ";
for (unsigned h = 0, n = pathNamesAll.size(); h < n; ++h) {
bool isBoth = obj.hasPathName( pathNamesAll[h], true, true );
bool isL3 = obj.hasPathName( pathNamesAll[h], false, true );
bool isLF = obj.hasPathName( pathNamesAll[h], true, false );
bool isNone = obj.hasPathName( pathNamesAll[h], false, false );
std::cout << " " << pathNamesAll[h];
if (isBoth) std::cout << "(L,3)";
if (isL3 && !isBoth) std::cout << "(*,3)";
if (isLF && !isBoth) std::cout << "(L,*)";
if (isNone && !isBoth && !isL3 && !isLF) std::cout << "(*,*)";
}
std::cout << std::endl;
}
Finally, note that we are not writing any information into our myoutput.root
file – but everything is configurable! Any of the printed quantities could have been stored in TTree branches instead.
Key Points
It is possible to retrieve trigger information from MiniAOD files directly
Trigger objects can be checked against reconstructed objects