Commit 7363bb66 authored by Joerg Stelzer's avatar Joerg Stelzer Committed by Graeme Stewart
Browse files

remove trigger ARA example (TrigAnalysisExamples-00-00-39)

parent 01cccc41
package TrigAnalysisExamples
author Michael Begel
author Joerg Stelzer
author Tomasz Bold
use AtlasPolicy AtlasPolicy-*
use TestPolicy TestPolicy-*
# for AthenaPython
use AthenaPython AthenaPython-* Control -no_auto_imports
# for example EDM access test
use TrigCaloEvent TrigCaloEvent-* Trigger/TrigEvent
use TrigInDetEvent TrigInDetEvent-* Trigger/TrigEvent
use TrigParticle TrigParticle-* Trigger/TrigEvent
use TrigMuonEvent TrigMuonEvent-* Trigger/TrigEvent
use TrigCaloEvent TrigCaloEvent-* Trigger/TrigEvent
private
# tools for analysis
use AnalysisUtils AnalysisUtils-* PhysicsAnalysis/AnalysisCommon
use AthenaBaseComps AthenaBaseComps-* Control
use AthenaKernel AthenaKernel-* Control
use AtlasBoost AtlasBoost-* External
use CaloEvent CaloEvent-* Calorimeter
use GaudiInterface GaudiInterface-* External
use JetEvent JetEvent-* Reconstruction/Jet
use EventInfo EventInfo-* Event
use AtlasTriggerRunTime AtlasTriggerRunTime-*
use StoreGate StoreGate-* Control
# For the TrigBunchCrossingTool example:
use TrigAnalysisInterfaces TrigAnalysisInterfaces-* Trigger/TrigAnalysis
# for TrigDecisionTool test
use TrigDecisionTool TrigDecisionTool-* Trigger/TrigAnalysis
use TrigObjectMatching TrigObjectMatching-* Trigger/TrigAnalysis
# for TrigMatchExamples
use muonEvent muonEvent-* Reconstruction/MuonIdentification
use egammaEvent egammaEvent-* Reconstruction/egamma
use tauEvent tauEvent-* Reconstruction
public
# library
library TrigAnalysisExamples *.cxx components/*.cxx
apply_pattern component_library
branches src python share doc exec
apply_pattern declare_python_modules files="*.py"
# declare test job options
apply_pattern declare_joboptions files="*.py"
private
use AnalysisTriggerEvent AnalysisTriggerEvent-* PhysicsAnalysis/AnalysisTrigger
use AtlasROOT AtlasROOT-* External
use TrigSteeringEvent TrigSteeringEvent-* Trigger/TrigEvent
use tauEvent tauEvent-* Reconstruction
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
/**
@mainpage TrigAnalysisExamples Package
@mainpage TrigDecisionTool Package
@section TrigAnalysisExampleIntro Introduction
This package contains examples of usage of TrigDecisionTool.
Find more user documentation at the page:
https://twiki.cern.ch/twiki/bin/view/Atlas/TrigDecisionTool15
@htmlinclude used_packages.html
*/
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
void TriggerAnalysisTutorialJets() {
TFile *f = TFile::Open("TriggerAnalysisTutorial.root");
if(f==0) {
std::cout << "File TriggerAnalysisTutorial.root not found" << std::endl;
return;
}
TTree *tr = (TTree*)f->Get("trigtr");
TCanvas *c = new TCanvas("c","Jet Trigger Reconstruction Studies",500,700);
gStyle->SetPadBorderMode(0);
c->Divide(2,3);
c->cd(1);
tr->Draw("Trig_l2Jet_et:Trig_l1Jet_et88","","box");
c->cd(2);
tr->Draw("(Trig_l2Jet_et-Trig_l1Jet_et88)/Trig_l2Jet_et");
c->cd(3);
tr->Draw("Trig_l2Jet_eta:Trig_l1Jet_eta","","box");
c->cd(4);
tr->Draw("Trig_l2Jet_eta-Trig_l1Jet_eta");
c->cd(5);
tr->Draw("Trig_l2Jet_phi:Trig_l1Jet_phi","","box");
c->cd(6);
tr->Draw("Trig_l2Jet_phi-Trig_l1Jet_phi");
}
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
void TriggerAnalysisTutorialZee() {
TFile *f = TFile::Open("TriggerAnalysisTutorial.root");
if(f==0) {
std::cout << "File TriggerAnalysisTutorial.root not found" << std::endl;
return;
}
TTree *tr = (TTree*)f->Get("trigtr");
TCanvas *c = new TCanvas("c","Electron Trigger Studies using Tag and Probe with Z-> ee",800,600);
gStyle->SetPadBorderMode(0);
c->Divide(3,3);
c->cd(1);
tr->Draw("Zmass>>Zmass(100,0,130)");
c->cd(2);
tr->Draw("e2P>>e2P(100,0,130000)"); e2P->SetLineColor(4);
tr->Draw("e1P>>e1P(100,0,130000)","","same");
c->cd(3);
tr->Draw("e1P:e2P","","box");
c->cd(4);
tr->Draw("deltaR>>deltaR(100,0,0.005)");
c->cd(5);
tr->Draw("probeMatch>>probeMatch"); probeMatch->SetMinimum(0); probeMatch->SetTitle("Probe electron w/ matched trigger");
c->cd(6);
tr->Draw("probeP>>probeP(100,0,130000)"); probeP->SetTitle("Momentum of probe electron");
TH1* probeP = (TH1*)gDirectory->Get("probeP");
tr->Draw("probeP>>probePwM(100,0,130000)","probeMatch==1","same"); probePwM->SetLineColor(2);
c->cd(7);
tr->Draw("probeP>>probePwME(100,0,130000)","probeMatch==1");
probePwME->Sumw2();
probePwME->SetTitle("Electron trigger efficiency vs momentum");
probePwME->Divide(probeP);
}
# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
from types import (IntType,LongType,FloatType,BooleanType)
from array import array
from math import (pi,hypot)
from AthenaPython.PyAthena import StatusCode
import AthenaPython.PyAthena as PyAthena
import ROOT,PyCintex
from ROOT import (TTree,)
from AthenaCommon.SystemOfUnits import (GeV,cm)
from operator import (attrgetter,itemgetter,setitem,getitem)
class TriggerTree(PyAthena.Alg):
def __init__(self, name="JetTurnOnTree", **kw):
kw['name'] = name
super(TriggerTree,self).__init__(**kw)
return
def clearDATA(self):
for i in self.DATA:
self.DATA[i][0]=0
return
def treewrap(self,variable=None,value=None):
if not self.DATA.has_key(variable):
if type(value) in [IntType,LongType]:
CHANGE=True
self.DATA[variable]=array('i',[0])
self.BRANCHES[variable]=self.tree.Branch(variable,self.DATA[variable],"%s/I" % variable)
elif type(value) in [FloatType]:
CHANGE=True
self.DATA[variable]=array('d',[0.0])
self.BRANCHES[variable]=self.tree.Branch(variable,self.DATA[variable],"%s/D" % variable)
elif type(value) in [BooleanType]:
CHANGE=True
self.DATA[variable]=array('i',[0])
self.BRANCHES[variable]=self.tree.Branch(variable,self.DATA[variable],"%s/I" % variable)
self.DATA[variable][0]=value
return
def initialize(self):
self.msg.info('initializing [%s]...',self.name())
self.sg = PyAthena.py_svc('StoreGateSvc')
self.hsvc=PyAthena.py_svc('THistSvc')
self.trigDec = PyAthena.py_tool('Trig::TrigDecisionTool/TrigDecisionTool')
#
# TTree
#
self.DATA={}
self.BRANCHES={}
self.hsvc['/turnontree/dijets']=TTree("dijets","dijets")
self.tree=self.hsvc['/turnontree/dijets']
#
for i in ['event_number','run_number','lumi_block']:
self.treewrap(i,0)
for i in ['%s%d' % (i,j)
for i in ['px','py','pz','e','rapidity','pt']
for j in [0,1]]:
self.treewrap(i,0.0)
for i in ['roi_%s%d' % (i,j)
for i in ['eta','phi']
for j in [0,1]]:
self.treewrap(i,0.0)
return StatusCode.Success
def deltaR(self,eta1,phi1,eta2,phi2):
phi=abs(phi1-phi2)
if phi>2*pi: phi=phi-2*pi
return hypot(abs(eta1-eta2),phi)
def execute(self):
#
# This is a cooked example and is not intended for actual use in an analysis
#
#
# Require at least two jets
#
inputjets=self.sg.retrieve("JetCollection","Cone4H1TopoJets")
if len(inputjets)<2: return StatusCode.Success
#
# Need leading two jets
#
jets=map(itemgetter(1),sorted([(j.pt(),j) for j in inputjets],reverse=True))
#
# Did we fire a jet trigger?
#
jettriggers=self.trigDec.getChainGroup("EF_[jJ][0-9].*")
JETTRIGGERS=jettriggers.getListOfTriggers()
for i in JETTRIGGERS:
self.treewrap(i,0)
self.treewrap('prescale_%s' % i,1.0)
ALSOJET=map(None,
JETTRIGGERS,
map(self.trigDec.isPassed,JETTRIGGERS),
map(self.trigDec.getPrescale,JETTRIGGERS)
)
# get trigger elements
fc=jettriggers.features()
roijets=[i.cptr() for i in fc.get('TrigRoiDescriptor')('initialRoI')]
if len(roijets)<1: return StatusCode.Success # The next line doesn't work without trigger jets...
matchedroijets=[min([(self.deltaR(i.eta(),i.phi(),j.eta0(),j.phi0()),j) for j in roijets])[1] for i in jets[:2]]
#
# Event information
#
EventInfo=self.sg.retrieve('EventInfo')
evid=EventInfo.event_ID()
#
# Fill TTree
#
# note that we are creating branches on the fly and this is technically incorrect
self.clearDATA()
for i in ['event_number','run_number','lumi_block']:
self.DATA[i][0]=getattr(evid,i)()
for i,j,k in ALSOJET:
self.DATA[i][0]=j
self.DATA['prescale_%s' % i][0]=k
for i in ['px','py','pz','e','pt']:
for j in [0,1]:
self.DATA['%s%d' % (i,j)][0] =getattr(jets[j],i)()/GeV
for i in ['rapidity']:
for j in [0,1]:
self.DATA['%s%d' % (i,j)][0] =getattr(jets[j],i)()
for i in ['phi','eta']:
for j in [0,1]:
self.DATA['roi_%s%d' % (i,j)][0] = getattr(matchedroijets[j],'%s0' % i)()
self.tree.Fill()
return StatusCode.Success
def finalize(self):
return StatusCode.Success
# $Id: BunchCrossingExample_jobOptions.py 326080 2010-10-08 13:50:09Z krasznaa $
#
# This example shows how to set up a generic job that is able to use the
# TrigBunchCrossingTool package's tools.
#
# author: Attila Krasznahorkay <Attila.Krasznahorkay@cern.ch>
#
# $Revision: 326080 $
# $Date: 2010-10-08 15:50:09 +0200 (Fri, 08 Oct 2010) $
# Set up the basic job properties:
InputFiles = [ "AOD.pool.root" ]
EvtMax = 10
# Set up the needed RecEx flags:
from AthenaCommon.AthenaCommonFlags import athenaCommonFlags
athenaCommonFlags.FilesInput.set_Value_and_Lock( InputFiles )
athenaCommonFlags.EvtMax.set_Value_and_Lock( EvtMax )
# Set up what the RecExCommon job should and shouldn't do:
from RecExConfig.RecFlags import rec
rec.AutoConfiguration = [ "everything" ]
rec.doCBNT.set_Value_and_Lock( False )
rec.doWriteESD.set_Value_and_Lock( False )
rec.doWriteAOD.set_Value_and_Lock( False )
rec.doWriteTAG.set_Value_and_Lock( False )
rec.doESD.set_Value_and_Lock( False )
rec.doAOD.set_Value_and_Lock( False )
rec.doDPD.set_Value_and_Lock( False )
rec.doHist.set_Value_and_Lock( False )
rec.doPerfMon.set_Value_and_Lock( False )
# Let RecExCommon set everything up:
include( "RecExCommon/RecExCommon_topOptions.py" )
#######################################################################
# #
# Now set up the actual job... #
# #
#######################################################################
# Get ourselves a logger, mainly for fun:
from AthenaCommon.Logging import logging
logger = logging.getLogger( "BunchCrossingExample" )
logger.info( "Setting up the bunch crossing example job" )
# Access the algorithm sequence:
from AthenaCommon.AlgSequence import AlgSequence
theJob = AlgSequence()
# Add the example algorithm, configuring the appropriate Trig::IBunchCrossingTool
# in the process:
from TrigAnalysisExamples.TrigAnalysisExamplesConf import Trig__BunchCrossingExample
from TrigBunchCrossingTool.BunchCrossingTool import BunchCrossingTool
theJob += Trig__BunchCrossingExample( "BunchCrossingExample" )
theJob.BunchCrossingExample.BCTool = BunchCrossingTool()
theJob.BunchCrossingExample.OutputLevel = DEBUG
# Do some additional tweaking:
from AthenaCommon.AppMgr import theApp
theApp.EvtMax = athenaCommonFlags.EvtMax()
ServiceMgr.MessageSvc.OutputLevel = INFO
ServiceMgr.MessageSvc.defaultLimit = 10000000
#!/usr/bin/env python
### import the modules
print '... importing ROOT and PyCintex'
import ROOT, PyCintex
import AthenaROOTAccess.transientTree
### define the list of input files
print '... define list of files'
import sys
if '-c' in sys.argv:
opt = sys.argv[sys.argv.index('-c')+1]
exec(opt)
if not ('PoolAODInput1' in dir()):
PoolAODInput1=["/afs/cern.ch/user/t/tbold/public/TDTtest/menu1/AOD.pool.root"]
if not ('PoolAODInput2' in dir()):
PoolAODInput2=["/afs/cern.ch/user/t/tbold/public/TDTtest/menu2/AOD.pool.root"]
### build the transient event and metadata trees
print '... build collection and metadata trees'
#from TrigDecisionTool.BuildTransientTrees import BuildTransientTrees
#(transientTree1, transientMetaDataTree1) = BuildTransientTrees(files1)
CollectionTree1 = ROOT.AthenaROOTAccess.TChainROOTAccess('CollectionTree')
MetaDataTree1 = ROOT.AthenaROOTAccess.TChainROOTAccess('MetaData')
for file1 in PoolAODInput1:
CollectionTree1.Add(file1+'/CollectionTree')
MetaDataTree1.Add(file1+'/MetaData')
transientCollectionTree1 = AthenaROOTAccess.transientTree.makeTree(CollectionTree1)
transientMetaDataTree1 = AthenaROOTAccess.transientTree.makeTree(MetaDataTree1,
persTreeName = 'MetaData',
dhTreeName = 'MetaDataHdrDataHeader')
CollectionTree2 = ROOT.AthenaROOTAccess.TChainROOTAccess('CollectionTree')
MetaDataTree2 = ROOT.AthenaROOTAccess.TChainROOTAccess('MetaData')
for file2 in PoolAODInput2:
CollectionTree2.Add(file2+'/CollectionTree')
MetaDataTree2.Add(file2+'/MetaData')
transientCollectionTree2 = AthenaROOTAccess.transientTree.makeTree(CollectionTree2)
transientMetaDataTree2 = AthenaROOTAccess.transientTree.makeTree(MetaDataTree2,
persTreeName = 'MetaData',
dhTreeName = 'MetaDataHdrDataHeader')
### instantiate the TrigDecisionToolARA
print '... instantiate TrigDecisionToolARA'
tdt1 = ROOT.Trig.TrigDecisionToolARA(transientCollectionTree1, transientMetaDataTree1)
tdt2 = ROOT.Trig.TrigDecisionToolARA(transientCollectionTree2, transientMetaDataTree2)
### changing the output level of the TrigDecisionTool (default is ERROR)
#import AthenaCommon.Constants as Constants
#tdt.setOutputLevel(Constants.WARNING)
### create two triggers
chains1 = tdt1.getChainGroup('EF_.*')
chains2 = tdt2.getChainGroup('EF_.*')
### loop over the events
if transientCollectionTree1.GetEntries() != transientCollectionTree2.GetEntries():
print '... WARNING both files have different number of events in, ',\
transientCollectionTree1.GetEntries(), ' and ', transientCollectionTree2.GetEntries()
nevt = min(transientCollectionTree1.GetEntries(), transientCollectionTree2.GetEntries() )
print '... loop over %i events' % nevt
for evt in xrange(nevt):
eventOK=True
print "... reading event",evt
transientCollectionTree1.GetEntry(evt)
transientCollectionTree2.GetEntry(evt)
c1 = list(chains1.getListOfTriggers())
c2 = list(chains2.getListOfTriggers())
for a in c1:
if a not in c2:
print "REGTEST ... chain ", a ," present in file 1 while not in file 2"
eventOK=False
else:
if tdt1.isPassedBits(a) != tdt2.isPassedBits(a):
print "REGTEST .... chain ", a, " has different isPassedBits in file 1: ", tdt1.isPassedBits(a) ," while in file 2: ", tdt2.isPassedBits(a)
eventOK=False
if eventOK:
print "INFO event OK"
if not ('PoolESDInput' in dir()):
PoolESDInput=["/afs/cern.ch/user/t/trigcomm/w0/T0Cos/newData/myESD-express.pool.root"]
import AthenaPoolCnvSvc.ReadAthenaPool
ServiceMgr.EventSelector.InputCollections=PoolESDInput
ServiceMgr.OutputLevel=ERROR
ServiceMgr.MessageSvc.infoLimit=200000
from AthenaCommon.AthenaCommonFlags import athenaCommonFlags
athenaCommonFlags.FilesInput.set_Value_and_Lock(PoolESDInput)
from RecExConfig.AutoConfiguration import ConfigureFromListOfKeys
ConfigureFromListOfKeys(['everything'])
#
# Example Code
#
from TrigAnalysisExamples.TrigAnalysisExamplesConf import TrigExpressStreamAlg
from AthenaCommon.AlgSequence import AlgSequence
topSequence = AlgSequence()
topSequence += TrigExpressStreamAlg()
###############################
from AthenaCommon.GlobalFlags import GlobalFlags
GlobalFlags.DetGeo.set_atlas()
theApp.EvtMax=-1
theApp.OutputLevel=ERROR
#!/usr/bin/env python
### import the modules
#print '... importing ROOT and PyCintex'
import ROOT, PyCintex
import sys
if '-c' in sys.argv:
opt = sys.argv[sys.argv.index('-c')+1]
exec(opt)
if 'pool.root' in sys.argv[-1]:
exec('PoolAODInput=["'+sys.argv[-1]+'"]')
### define the list of input files
print '... define list of files'
if not ('PoolAODInput' in dir()):
PoolAODInput=['/afs/cern.ch/user/t/tbold/public/TDTtest/menu1/AOD.pool.root']
for f in PoolAODInput:
print ' + %s' % f
### build the transient event and metadata trees
#print '... build collection and metadata trees'
from TrigDecisionTool.BuildTransientTrees import BuildTransientTrees
(transientTree, transientMetaDataTree) = BuildTransientTrees(PoolAODInput)
### instantiate the TrigDecisionToolARA
#print '... instantiate TrigDecisionToolARA'
tdt = ROOT.Trig.TrigDecisionToolARA(transientTree, transientMetaDataTree)
### changing the output level of the TrigDecisionTool (default is ERROR)
#import AthenaCommon.Constants as Constants
#tdt.setOutputLevel(Constants.WARNING)
### create two triggers
#allL2 = tdt.getChainGroup('L2_.*')
#allEF = tdt.getChainGroup('EF_.*')
all = tdt.getChainGroup('(EF|L2)_.*')
### possible HLT objects
from pprint import pprint as pp
from TriggerJobOpts.TriggerEDM import EDMDetails
collection2type = {}
for t, details in EDMDetails.iteritems():
try:
collection2type[details['collection']] = t
except:
pass
# pp(collection2type)
branches = [(b.getPersBranchName(), b.GetObjClassName()) for b in list(transientTree.GetListOfBranches()) if 'HLT' == b.GetName() or 'HLT_' in b.GetName() ]
type2key = []
for i in branches:
key = i[0].split('HLT')[1].lstrip('_')