forked from cbernet/heppy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request cbernet#44 from selvaggi/master
added jet substructure example
- Loading branch information
Showing
5 changed files
with
202 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from heppy.framework.analyzer import Analyzer | ||
from heppy.statistics.tree import Tree | ||
from heppy.analyzers.ntuple import * | ||
from heppy.particles.tlv.resonance import Resonance2 as Resonance | ||
|
||
from ROOT import TFile | ||
|
||
class TreeProducer(Analyzer): | ||
|
||
def beginLoop(self, setup): | ||
super(TreeProducer, self).beginLoop(setup) | ||
self.rootfile = TFile('/'.join([self.dirName, | ||
'tree.root']), | ||
'recreate') | ||
self.tree = Tree( 'events', '') | ||
self.tree.var('tau1', float) | ||
self.tree.var('tau2', float) | ||
self.tree.var('tau3', float) | ||
self.tree.var('tau32', float) | ||
self.tree.var('tau31', float) | ||
self.tree.var('tau21', float) | ||
|
||
bookParticle(self.tree, 'Jet') | ||
bookParticle(self.tree, 'softDroppedJet') | ||
bookParticle(self.tree, 'leadingSoftDroppedSubJet') | ||
bookParticle(self.tree, 'trailingSoftDroppedSubJet') | ||
|
||
def process(self, event): | ||
self.tree.reset() | ||
jets = getattr(event, self.cfg_ana.fatjets) | ||
|
||
# store leading (fat) jet observables | ||
if len(jets) > 0 and len(jets[0].subjetsSoftDrop) > 2: | ||
self.tree.fill('tau1' , jets[0].tau1 ) | ||
self.tree.fill('tau2' , jets[0].tau2 ) | ||
self.tree.fill('tau3' , jets[0].tau3 ) | ||
self.tree.fill('tau31' , jets[0].tau3/jets[0].tau1 ) | ||
self.tree.fill('tau32' , jets[0].tau3/jets[0].tau2 ) | ||
self.tree.fill('tau21' , jets[0].tau2/jets[0].tau1 ) | ||
|
||
fillParticle(self.tree, 'Jet', jets[0]) | ||
|
||
# first subjet entry is the cleaned jet itself | ||
fillParticle(self.tree, 'softDroppedJet', jets[0].subjetsSoftDrop[0]) | ||
fillParticle(self.tree, 'leadingSoftDroppedSubJet', jets[0].subjetsSoftDrop[1]) | ||
fillParticle(self.tree, 'trailingSoftDroppedSubJet', jets[0].subjetsSoftDrop[2]) | ||
|
||
self.tree.tree.Fill() | ||
|
||
def write(self, setup): | ||
self.rootfile.Write() | ||
self.rootfile.Close() | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import os | ||
import copy | ||
import heppy.framework.config as cfg | ||
|
||
import logging | ||
# next 2 lines necessary to deal with reimports from ipython | ||
logging.shutdown() | ||
reload(logging) | ||
logging.basicConfig(level=logging.WARNING) | ||
|
||
comp = cfg.Component( | ||
'example', | ||
files = ['FCCDelphesOutput.root'] | ||
) | ||
selectedComponents = [comp] | ||
|
||
from heppy.analyzers.fcc.Reader import Reader | ||
source = cfg.Analyzer( | ||
Reader, | ||
|
||
fatjets = 'fatjets', | ||
jetsOneSubJettiness = 'jetsOneSubJettiness', | ||
jetsTwoSubJettiness = 'jetsTwoSubJettiness', | ||
jetsThreeSubJettiness = 'jetsThreeSubJettiness', | ||
subjetsTrimmingTagged = 'subjetsTrimmingTagged', | ||
subjetsTrimming = 'subjetsTrimming', | ||
subjetsPruningTagged = 'subjetsPruningTagged', | ||
subjetsPruning = 'subjetsPruning', | ||
subjetsSoftDropTagged = 'subjetsSoftDropTagged', | ||
subjetsSoftDrop = 'subjetsSoftDrop', | ||
|
||
) | ||
|
||
|
||
from ROOT import gSystem | ||
gSystem.Load("libdatamodelDict") | ||
from EventStore import EventStore as Events | ||
|
||
############################# | ||
## Reco Level Analysis ## | ||
############################# | ||
|
||
from heppy.analyzers.Selector import Selector | ||
# select jet above 400 GeV | ||
fatjets_400 = cfg.Analyzer( | ||
Selector, | ||
'fatjets_400', | ||
output = 'fatjets_400', | ||
input_objects = 'fatjets', | ||
filter_func = lambda jet: jet.pt()>400. | ||
) | ||
|
||
# produce flat root tree containing jet substructure information | ||
from heppy.analyzers.examples.jetsubstructure.TreeProducer import TreeProducer | ||
tree = cfg.Analyzer( | ||
TreeProducer, | ||
fatjets = 'fatjets_400', | ||
) | ||
|
||
|
||
# definition of a sequence of analyzers, | ||
# the analyzers will process each event in this order | ||
sequence = cfg.Sequence( [ | ||
source, | ||
fatjets_400, | ||
tree, | ||
] ) | ||
|
||
|
||
config = cfg.Config( | ||
components = selectedComponents, | ||
sequence = sequence, | ||
services = [], | ||
events_class = Events | ||
) | ||
|
||
if __name__ == '__main__': | ||
import sys | ||
from heppy.framework.looper import Looper | ||
|
||
def next(): | ||
loop.process(loop.iEvent+1) | ||
|
||
loop = Looper( 'looper', config, | ||
nEvents=100, | ||
nPrint=0, | ||
timeReport=True) | ||
loop.process(6) | ||
print loop.event |