Skip to content

Commit

Permalink
Merge pull request #6 from cms-tau-pog/master
Browse files Browse the repository at this point in the history
Hackathon + RDataframe debugging
  • Loading branch information
IzaakWN authored Mar 11, 2024
2 parents e256e7e + b5cf072 commit dccb99a
Show file tree
Hide file tree
Showing 145 changed files with 9,959 additions and 3,949 deletions.
66 changes: 37 additions & 29 deletions Fitter/ETauFR/Plotter/plotpostfit.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
argv = sys.argv
description = '''This script creates datacards with CombineHarvester.'''
parser = ArgumentParser(prog="harvestercards",description=description,epilog="Succes!")
parser.add_argument('-y', '--era', dest='eras', nargs='*', choices=['2016','2017','2018','UL2017','UL2018','UL2016_preVFP','UL2016_postVFP'], default=['UL2017'], action='store',
parser.add_argument('-y', '--era', dest='eras', nargs='*', choices=['2016','2017','2018','UL2017','UL2018','UL2016_preVFP','UL2016_postVFP', '2022_postEE', '2022_preEE'], default=['UL2017'], action='store',
help="set era" )
parser.add_argument('-c', '--channel', dest='channels', choices=['mt','et'], type=str, nargs='+', default=['mt'], action='store',
help="channels to submit")
Expand All @@ -28,13 +28,13 @@
help="do not include shape uncertainties")
parser.add_argument('-v', '--verbose', dest='verbose', default=False, action='store_true',
help="set verbose")
parser.add_argument('-wp', '--workpoint', dest='workpoint', default=False, action='store_true',
help="set verbose")
parser.add_argument('-wp', '--workpoint', dest='workpoint', choices=['VVLoose','Medium','Tight'], type=str, default=['Tight'], help="set wp")

args = parser.parse_args()


def main(args):
print ""
print("")
analysis = 'zee_fr'
obsset = args.observables
channels = args.channels
Expand All @@ -51,12 +51,12 @@ def main(args):
#STYLE.sample_colors['ZTT'] = STYLE.kOrange-4

procs = [
'ZTT', 'ZL', 'ZJ', 'TTT', 'TTJ', 'W', 'ST', 'VV', 'QCD', 'data_obs' #'STT', 'STJ'
'ZTT', 'ZL', 'ZJ', 'W', 'VV', 'ST','TTT', 'TTL', 'TTJ', 'QCD', 'data_obs' #'STT', 'STJ'
]
groups = [
(['^TT*'],'Top','ttbar'), #,STYLE.sample_colors['TT']),
#(['^TT*'],'Top','ttbar'), #,STYLE.sample_colors['TT']),
#(['^TT*','ST*'],'Top','ttbar and single top'),
(['W*','ZJ','VV','ST*'],'EWK','Electroweak'), #,STYLE.sample_colors['EWK']),
#(['W*','ZJ','VV','ST*'],'EWK','Electroweak'), #,STYLE.sample_colors['EWK']),

]
title_dict = {
Expand All @@ -66,7 +66,7 @@ def main(args):
}
tsize = 0.054
PLOT._lsize = 0.040 # label size
ratio = False
ratio = True
square = not ratio and False
exts = [ 'png', 'pdf', 'root', 'C' ]

Expand All @@ -77,36 +77,44 @@ def main(args):
for obs in obsset:
ZL = "Z -> ee"
procs_ = [
'ZL', 'ZTT', 'ZJ', 'TTT', 'TTJ', 'TTL', 'W', 'VV', 'ST', 'QCD', 'data_obs'
'ZTT', 'ZL', 'ZJ', 'W', 'VV', 'ST','TTT', 'TTL', 'TTJ', 'QCD', 'data_obs'
]
analysis = 'ETauFR'
etas= ['1p46','2p300']
etas= ['eta0to1p46','eta1p56to2p5']
if bin =="Tight":
dms = [0, 1]
else:
dms = [0, 1 , 10, 11]
#procs_ = procs[:]
pos = 'x=0.56,y=0.88'
ncol = 1
regs =['pass','fail']
for eta in etas:
if eta =='1p46':
title = "0 < #eta < 1.46"
elif eta== '2p300':
title = "1.56 < #eta < 2.30"
for reg in regs:
if reg == "pass":
title += " , Pass"
else:
title += " , Fail"
fname = "$DIR/$ANALYSIS$BINLt$ETA_PostFitShape.root"
pname = "$DIR/$ANALYSIS_$OBS_$CHANNEL-$BIN-$ERA-$ETA-$REG-$TAG_$FIT.png"
indir = "output/%s"%era
outdir = ensuredir("plots/%s"%era)
xtitle = title_dict.get(obs)
fname_ = repkey(fname,DIR=indir,ANALYSIS=analysis,OBS=obs,CHANNEL=channel,ETA=eta,BIN=bin,ERA=era,TAG=tag)
pname_ = repkey(pname,DIR=outdir,ANALYSIS=analysis,OBS=obs,CHANNEL=channel,ETA=eta,BIN=bin,ERA=era,REG=reg,TAG=tag)
drawpostfit(fname_,bin,procs_,pname=pname_,tag=tag,group=groups,title=title,xtitle=xtitle,
tsize=tsize,pos=pos,ncol=ncol,ratio=ratio,square=square,reg=reg,exts=exts)
for idm in dms:
if eta =='eta0to1p46':
title = "0 < #eta < 1.46, dm %s"%(idm)
elif eta== 'eta1p56to2p5':
title = "1.56 < #eta < 2.50 , dm %s"%(idm)
for reg in regs:
if reg == "pass":
title += " , Pass"
else:
title = title.replace(" , Pass", " ")
print(title)
title += " , Fail"
fname = "$DIR/$ANALYSIS$BIN_$ETA_dm$DM_PostFitShape.root"
pname = "$DIR/$ANALYSIS_$OBS_$CHANNEL-$BIN-$ERA-$ETA-dm$DM-$REG-$TAG_$FIT.png"
indir = "output/%s/%s"%(era,analysis)
outdir = ensuredir("plots/%s"%era)
xtitle = title_dict.get(obs)
fname_ = repkey(fname,DIR=indir,ANALYSIS=analysis,OBS=obs,CHANNEL=channel,ETA=eta,DM=idm,BIN=bin,ERA=era,TAG=tag)
pname_ = repkey(pname,DIR=outdir,ANALYSIS=analysis,OBS=obs,CHANNEL=channel,ETA=eta,DM=idm,BIN=bin,ERA=era,REG=reg,TAG=tag)
bin_merged=bin+"_"+reg
drawpostfit(fname_,bin_merged,procs_,pname=pname_,tag=tag,group=groups,title=title,xtitle=xtitle,
tsize=tsize,pos=pos,ncol=ncol,ratio=ratio,square=square,reg=reg,exts=exts)


if __name__ == '__main__':
main(args)
print ">>>\n>>> done\n"
print(">>>\n>>> done\n")

29 changes: 17 additions & 12 deletions Fitter/ETauFR/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,41 @@ DISCLAIMER: The Fitter code has been tested only for py2 and with `CMSSW_10_6_13
### Create inputs for combine.
To do so, please have a look at the `createinputs.py` script.
In this script you can set up (by hardcoding) which samples set shall be used in the fit, their systematic variations, which observable/variables to be fitted in combine, the event selctions to be applied to the samples, the Pass and Fail regions and the eta regions where perform the fit.
Using the command options, you can choose era and channel.
Using the command options, you can choose era and channel and to create (or not) the FES variations for combined fit (fV parameter).
Example:
```
python createinputs.py -c etau -y UL2017
python createinputs.py -c etau -y UL2017 -fV True
```
will produce the inputs for UL2017 samples where event selections for etau channel are applied.
will produce the inputs for UL2017 samples where event selections for etau channel are applied and the FES templates specified in the script are created.
Inputs files and plots will be stored into the `input` folder.

### Create datacards
The `combine` tool need specific datacards as input.
To create such datacards you can use the `writedatacard_DEV.py` script.
Before launching the command, you can set up (by hardcoding) which era, eta range, DeepTau WP and channel (or category) shall be used to create datacards.
To create such datacards you can use the `writedatacard.py` script.
Before launching the command, you can set up (by hardcoding) which era, eta range, dm, DeepTau WP and channel (or category) shall be used to create datacards. You can also choose if using or not the combined fit setting switching to True or False the `fesVar` variable.
No options are implemented for this script.
Datacards will be stored into the `input/<era>/ETauFR/` folder as `.txt` files.
In the same folder it will generate the `prefitFR.json` file with the prefit FR values needed when running the text2workspace.

### Perform the fit (using combine)
Run `text2workspace.py` using the `zttmodels.py`:
Run the `text2wp.py` specifying the era like this:
```
text2workspace.py -P TauFW.Fitter.ETauFR.zttmodels:ztt_eff --PO "eff={pre-fit FR}" ./input/{era}/ETauFR/{wp}_eta{eta}.txt -o ./input/{era}/ETauFR/WorkSpace{wp}_eta{eta}.root
python text2wp.py --era 2022_postEE
```
It will read the json produced in the previous step and run `text2workspace.py` using the `zttmodels.py`, like this:
```
Then you can run the fitting+plotting or the impacts or everything together, as in the following:
text2workspace.py -P TauFW.Fitter.ETauFR.zttmodels:ztt_eff --PO "eff={pre-fit FR}" ./input/{era}/ETauFR/{wp}_eta{eta}_{dm}.txt -o ./input/{era}/ETauFR/WorkSpace{wp}_eta{eta}_dm{dm}.root
```
./doFitPlots.sh {wp} {eta} {era}
Attention: the `zttmodels.py` by default sets to POIs for the combined fit, change if needed.
Then you can run the fitting+impacts+postfit macro, specifying WP eta era and dm, as in the following:
```
bash doFitsAndImpacts_combFit.sh VVLoose 0to1p46 2022_postEE 11
```
./doImpacts.sh {wp} {eta} {era}
```
Finally the postfit plots are produced with (eta and dm are specified in the script, if needed change them directly there):
```
./runAll.sh {wp} {era}
python ./Plotter/plotpostfit.py -c et -y ${era} -wp ${wp}
```

--OLD--
The script `Fitting_DEV.sh` provides several commands to perform the fit and create post-fit histograms for plotting.
Please, have a look at the script to understand where inputs and outputs of each command are stored.
Expand Down
Loading

0 comments on commit dccb99a

Please sign in to comment.