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

Changed flatten subsample behaviour not working on batch #21

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions docs/shapes/python/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@
>>> + "*( !(Sum(PhotonGen_isPrompt==1 && PhotonGen_pt>15 && abs(PhotonGen_eta)<2.6) > 0)) * ewknloW",
>>> "FilesPerJob": 5,
>>> "subsamples": dys,
>>> "flatten_samples_map": lambda sname, sub: "%s" % (sub)
>>> # in this way flatten sampled are simply "DY_hardJets", "DY_PUJets",
>>> # and "DY_inclusive_rwgt"
>>> # default flatten_samples_map is lambda sname, sub: '%s_%s' % (sname, sub)
>>> "flatten_samples_map": 1
>>> # By default (flatten_samples_map=0), subsamples will carry the sample
>>> # name as prefix (e.g. DY_DY_hardJets, DY_DY_PUJets, ...). By specifying
>>> # flatten_samples_map=1 the sample prefix will be dropped and subsamples
>>> # names will be the one appearing in the subsamples dictionary keys
>>> # (for this example subsample shape names will be DY_hardJets, DY_PUJets)
>>> }


Expand Down
8 changes: 5 additions & 3 deletions mkShapesRDF/shapeAnalysis/latinos/LatinosUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ def flatten_samples(samples):
sample = samples[sname]
if "subsamples" not in sample:
continue
flatten_samples_map = samples[sname].get(
"flatten_samples_map", lambda sname, sub: "%s_%s" % (sname, sub)
active_fsm = samples[sname].get(
"flatten_samples_map", 0
)

if active_fsm == 0: flatten_samples_map = lambda sname, sub: "%s_%s" % (sname, sub)
else: flatten_samples_map = lambda sname, sub: "%s" % (sub)

subsamplesmap.append((sname, []))
for sub in sample["subsamples"]:
new_subsample_name = flatten_samples_map(sname, sub)
Expand Down
29 changes: 15 additions & 14 deletions mkShapesRDF/shapeAnalysis/latinos/mkDatacards.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,6 @@ def makeDatacards(

card.write("-" * 100 + "\n")
card.write("bin %s" % tagNameToAppearInDatacard + "\n")
if len(data) == 0:
self._logger.warning("no data, no fun! ")
# raise RuntimeError('No Data found!')
yieldsData["data"] = 0

card.write("observation %.0f\n" % yieldsData["data"])

card.write(
"shapes * * "
Expand All @@ -305,14 +299,21 @@ def makeDatacards(
+ "\n"
)

card.write(
"shapes data_obs * "
+ "shapes/histos_"
+ tagNameToAppearInDatacard
+ ".root"
+ " histo_Data"
+ "\n"
)
if len(data) == 0:
print("no data, no fun! ")
yieldsData["data"] = 0

else:
card.write("observation %.0f\n" % yieldsData["data"])

card.write(
"shapes data_obs * "
+ "shapes/histos_"
+ tagNameToAppearInDatacard
+ ".root"
+ " histo_Data"
+ "\n"
)

# shapes * * shapes/hww-19.36fb.mH125.of_vh2j_shape_mll.root histo_$PROCESS histo_$PROCESS_$SYSTEMATIC
# shapes data_obs * shapes/hww-19.36fb.mH125.of_vh2j_shape_mll.root histo_Data
Expand Down
8 changes: 6 additions & 2 deletions mkShapesRDF/shapeAnalysis/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,9 +854,13 @@ def splitSubsamples(self):
_sample = list(filter(lambda k: k[0] == sampleName, self.samples))[0]
for subsample in list(_sample[6].keys()):
# _sample[5] is the original dict, i.e. samples[sampleName]
flatten_samples_map = _sample[5].get(
"flatten_samples_map", lambda sname, sub: "%s_%s" % (sname, sub)

active_fsm = _sample[5].get(
"flatten_samples_map", 0
)
if active_fsm == 0: flatten_samples_map = lambda sname, sub: "%s_%s" % (sname, sub)
else: flatten_samples_map = lambda sname, sub: "%s" % (sub)

new_subsample_name = flatten_samples_map(sampleName, subsample)
self.dfs[new_subsample_name] = {}
for index in self.dfs[sampleName].keys():
Expand Down