forked from cms-sw/cmssw
-
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 cms-sw#572 from jpata/vhbbHeppy80X_heppy_8_0_19
sync to cbernet/cmssw:heppy_8_0_19
- Loading branch information
Showing
216 changed files
with
12,987 additions
and
622 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
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
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 was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
PhysicsTools/HeppyCore/python/analyzers/ChargedHadronsFromB.py
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,34 @@ | ||
from PhysicsTools.HeppyCore.framework.analyzer import Analyzer | ||
from PhysicsTools.HeppyCore.particles.genbrowser import GenBrowser | ||
from PhysicsTools.HeppyCore.particles.pdgcodes import hasBottom | ||
|
||
class ChargedHadronsFromB(Analyzer): | ||
|
||
def process(self, event): | ||
genptcs = event.gen_particles | ||
bquarks = [] | ||
charged_hadrons = [] | ||
event.hadrons_from_b = [] | ||
for ptc in genptcs: | ||
if abs(ptc.pdgid())==5: | ||
bquarks.append(ptc) | ||
elif ptc.q() and ptc.status()==1: | ||
charged_hadrons.append(ptc) | ||
if len(bquarks) == 0 or len(charged_hadrons) == 0: | ||
return | ||
event.genbrowser = GenBrowser(event.gen_particles, | ||
event.gen_vertices) | ||
event.hadrons_from_b = [] | ||
event.hadrons_not_from_b = [] | ||
for hadron in charged_hadrons: | ||
ancestors = event.genbrowser.ancestors(hadron) | ||
is_from_b = False | ||
for ancestor in ancestors: | ||
if hasBottom(ancestor.pdgid() ): | ||
is_from_b = True | ||
if is_from_b: | ||
event.hadrons_from_b.append(hadron) | ||
else: | ||
event.hadrons_not_from_b.append(hadron) | ||
|
||
|
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,23 @@ | ||
from PhysicsTools.HeppyCore.framework.analyzer import Analyzer | ||
|
||
class Counter(Analyzer): | ||
'''Counts the number of objects in the input_objects collection | ||
and skip the event if this number is strictly inferior to min_number | ||
Example: | ||
from PhysicsTools.HeppyCore.analyzers.Counter import Counter | ||
gen_counter = cfg.Analyzer( | ||
Counter, | ||
input_objects = 'gen_particles_stable', | ||
min_number = 1 | ||
) | ||
* input_objects : the input collection | ||
* min_number : the minimum amount of object in input_object to not skip the event | ||
''' | ||
|
||
def process(self, event): | ||
input_collection = getattr(event, self.cfg_ana.input_objects) | ||
return len(input_collection) >= self.cfg_ana.min_number |
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,39 @@ | ||
from PhysicsTools.HeppyCore.framework.analyzer import Analyzer | ||
import collections | ||
|
||
class EventFilter (Analyzer): | ||
'''Filters events based on the contents of an input collection. | ||
When an event is rejected by the EventFilter, the analyzers | ||
placed after the filter in the sequence will not run. | ||
Example: | ||
To reject events with 1 lepton or more: | ||
from PhysicsTools.HeppyCore.analyzers.EventFilter import EventFilter | ||
lepton_filter = cfg.Analyzer( | ||
EventFilter , | ||
'lepton_filter', | ||
input_objects = 'leptons', | ||
min_number = 1, | ||
veto = True | ||
) | ||
* input_objects : the input collection. | ||
* min_number : minimum number of objects in input_objects to trigger the filtering | ||
* veto : | ||
- if False: events are selected if there are >= min_number objects in input_objects | ||
- if True: events are rejected if there are >= min_number objects in input_objects. | ||
''' | ||
|
||
def process(self, event): | ||
input_collection = getattr(event, self.cfg_ana.input_objects) | ||
if self.cfg_ana.veto: | ||
return not len(input_collection) >= self.cfg_ana.min_number | ||
else: | ||
return len(input_collection) >= self.cfg_ana.min_number | ||
|
||
|
69 changes: 69 additions & 0 deletions
69
PhysicsTools/HeppyCore/python/analyzers/EventTextOutput.py
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,69 @@ | ||
from PhysicsTools.HeppyCore.framework.analyzer import Analyzer | ||
|
||
import shelve | ||
|
||
outfilename = 'particles.shv' | ||
|
||
class SimpleParticle(object): | ||
def __init__(self, ptc): | ||
self.theta = ptc.theta() | ||
self.phi = ptc.phi() | ||
self.energy = ptc.e() | ||
self.pdgid = ptc.pdgid() | ||
|
||
def get_data(self): | ||
return self.pdgid, self.theta, self.phi, self.energy | ||
|
||
def __str__(self): | ||
return 'particle: {id} : theta={theta}, phi={phi}, energy={energy}'.format( | ||
id = self.pdgid, | ||
theta = self.theta, | ||
phi = self.phi, | ||
energy = self.energy | ||
) | ||
|
||
class SimpleEvent(object): | ||
def __init__(self, ievent, ptcs): | ||
self.ievent = ievent | ||
self.ptcs = map(SimpleParticle, ptcs) | ||
self.data = dict( | ||
ievent = ievent, | ||
particles = [ptc.get_data() for ptc in self.ptcs] | ||
) | ||
|
||
def get_data(self): | ||
return self.data | ||
|
||
def __str__(self): | ||
lines = ['event {iev}'.format(iev=self.ievent)] | ||
lines.extend( map(str, self.ptcs) ) | ||
return '\n'.join(lines) | ||
|
||
|
||
|
||
class EventTextOutput(Analyzer): | ||
|
||
def beginLoop(self, setup): | ||
super(EventTextOutput, self).beginLoop(setup) | ||
self.events = [] | ||
|
||
def process(self, event): | ||
ptcs = getattr(event, self.cfg_ana.particles ) | ||
self.events.append(SimpleEvent(event.iEv, ptcs).get_data()) | ||
|
||
def endLoop(self, setup): | ||
super(EventTextOutput, self).endLoop(setup) | ||
out = shelve.open('/'.join([self.dirName, outfilename])) | ||
out['events'] = self.events | ||
out.close() | ||
|
||
|
||
if __name__ == '__main__': | ||
|
||
import pprint | ||
sh = shelve.open(outfilename) | ||
events = sh['events'] | ||
for event in events: | ||
print 'event', event['ievent'] | ||
for pdgid, theta, phi, energy in event['particles']: | ||
print '\t', pdgid, theta, phi, energy |
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 |
---|---|---|
@@ -1,9 +1,45 @@ | ||
from PhysicsTools.HeppyCore.framework.analyzer import Analyzer | ||
import collections | ||
|
||
class Filter(Analyzer): | ||
'''Filter objects from the input_objects collection | ||
and store them in the output collection | ||
Example: | ||
from PhysicsTools.HeppyCore.analyzers.Filter import Filter | ||
def is_lepton(ptc): | ||
"""Returns true if the particle energy is larger than 5 GeV | ||
and if its pdgid is +-11 (electrons) or +-13 (muons) | ||
return ptc.e()> 5. and abs(ptc.pdgid()) in [11, 13] | ||
leptons = cfg.Analyzer( | ||
Filter, | ||
'sel_leptons', | ||
output = 'leptons', | ||
input_objects = 'rec_particles', | ||
filter_func = is_lepton | ||
) | ||
* input_objects : the input collection. | ||
if a dictionary, the filtering function is applied to the dictionary values, | ||
and not to the keys. | ||
* output : the output collection | ||
* filter_func : a function object. | ||
IMPORTANT NOTE: lambda statements should not be used, as they | ||
do not work in multiprocessing mode. looking for a solution... | ||
''' | ||
|
||
def process(self, event): | ||
input_collection = getattr(event, self.cfg_ana.input_objects) | ||
output_collection = [obj for obj in input_collection \ | ||
if self.cfg_ana.filter_func(obj)] | ||
setattr(event, self.instance_label, output_collection) | ||
output_collection = None | ||
if isinstance(input_collection, collections.Mapping): | ||
output_collection = dict( [(key, val) for key, val in input_collection.iteritems() | ||
if self.cfg_ana.filter_func(val)] ) | ||
else: | ||
output_collection = [obj for obj in input_collection \ | ||
if self.cfg_ana.filter_func(obj)] | ||
setattr(event, self.cfg_ana.output, output_collection) |
Oops, something went wrong.