Skip to content

Commit

Permalink
added script to generate GEN files from PYTHIA fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
santanas committed Dec 14, 2017
1 parent 752b2b9 commit 256c898
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 0 deletions.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,49 @@ TrijetRes_g_ggg_BP2_testV1_MGKK5000R0p1_slc6_amd64_gcc481_CMSSW_7_1_30_GEN.root
TrijetRes_g_ggg_BP2_testV1_MGKK5000R0p7_slc6_amd64_gcc481_CMSSW_7_1_30_GEN.root
```

## Pythia production (pythia fragment -> GEN)

1) Setup CMSSW area
```
scram p CMSSW_7_1_30
cd CMSSW_7_1_30
cmsenv
cd ..
```

2) Define template for pythia gen fragment
The standard is:
```
template_pythia_cards/PROCESSNAME_TuneCUETP8M1_13TeV_pythia8_cfi.py
```
The line with THISPROCESSPARAMETERS will be replaced with the actual pythia instructions by the following script

3) Create and edit script for config file production (use makeGENfromPYTHIA.py as template)
```
cp makeGENfromPYTHIA.py makeGENfromPYTHIA_Res1ToRes2QTo3Q.py
```
* Edit makeGENfromPYTHIA_Res1ToRes2QTo3Q.py:
* specify samples and parameters to be generated (Note: the script should be modified depending on the specific model and this can be taken as example). For the trijet model, just edit these values (i.e. Res1 mass, mass ratio between Res2 and Res1, and relative width of Res1 and Res2 - the same):
```
MGKKValues = [500, 4000]
RValues = [0.1, 0.7]
relwidth = 0.01 # 1%
```
* if you just want to produce the config files - without producing the GEN .root files - you should add
```
--no_exec
```
in these lines (at the end, inside the quotation marks):
```
print("cmsDriver.py Configuration/Generator/python/%s --fileout %s/%s --mc --eventcontent RAWSIM --datatier GEN-SIM --conditions MCRUN2_71_V1::All --step GEN --magField 38T_PostLS1 --python_filename %s -n %s" % (pythonfragment,TMPDIR,outputfilename,pythonfilename,NEVENTS) )
os.system("cmsDriver.py Configuration/Generator/python/%s --fileout %s/%s --mc --eventcontent RAWSIM --datatier GEN-SIM --conditions MCRUN2_71_V1::All --step GEN --magField 38T_PostLS1 --python_filename %s -n %s" % (pythonfragment,TMPDIR,outputfilename,pythonfilename,NEVENTS) )
```

4) Launch the gen production
```
python makeGENfromPYTHIA_Res1ToRes2QTo3Q.py -n Res1ToRes2QTo3Q -v CMSSW_7_1_30 -c template_pythia_cards/PROCESSNAME_TuneCUETP8M1_13TeV_pythia8_cfi.py -t /tmp/santanas --outputDir /eos/cms/store/cmst3/user/santanas/MCsamples/Res1ToRes2QTo3Q --numberOfevents 1000
```
* Jobs are processed one after the other, in local
* The output directory can be on eos or in local (afs) directory
* The gen fragments are in $CMSSW_BASE/src/ (these files should be provided to gen group for official production)
* The final configuration files are in $CMSSW_BASE/src/Configuration/Generator/python/ (these are used to generate privately the GEN .root files in this step)
119 changes: 119 additions & 0 deletions makeGENfromPYTHIA.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!usr/bin/python
import os
import optparse
import sys
import subprocess
import datetime
import re
from subprocess import check_output
import ROOT
import numpy as nn
from random import randint

basedir_path = os.path.dirname(os.path.realpath(__file__))
print basedir_path

usage = ""
parser = optparse.OptionParser(usage='\nExample: python %prog -n MyProcess -v CMSSW_7_1_30 -c template_pythia_cards/PROCESSNAME_TuneCUETP8M1_13TeV_pythia8_cfi.py -t /tmp/santanas/ --outputDir `pwd`/TestOutput --numberOfevents 1000')
parser.add_option("-n","--genProcessName",action="store",type="string",dest="GENPROCESSNAME",default="")
parser.add_option("-v","--cmsswVersion",action="store",type="string",dest="CMSSWVERSION",default="")
parser.add_option("-c","--pythonConfig",action="store",type="string",dest="PYTHONCONFIG",default="")
parser.add_option("-t","--tmpDir",action="store",type="string",dest="TMPDIR",default="")
parser.add_option("--numberOfevents",action="store",type="string",dest="NEVENTS",default="-1")
parser.add_option("--outputDir",action="store",type="string",dest="OUTPUTDIR",default="")

(options, args) = parser.parse_args()
GENPROCESSNAME = options.GENPROCESSNAME
CMSSWVERSION = options.CMSSWVERSION
PYTHONCONFIG = options.PYTHONCONFIG
TMPDIR = options.TMPDIR
NEVENTS = options.NEVENTS
OUTPUTDIR = options.OUTPUTDIR

if not options.GENPROCESSNAME:
parser.error('ERROR: Gen process name is not given')
if not options.CMSSWVERSION:
parser.error('ERROR: CMSSW version is not given')
if not options.PYTHONCONFIG:
parser.error('ERROR: Input python config is not given')
if not options.TMPDIR:
parser.error('ERROR: Tmp directory is not given')
if not options.OUTPUTDIR:
parser.error('ERROR: Output directory is not given')

#create output dir
IsEosDir = False
if ("/eos/" in OUTPUTDIR):
print "IS EOS DIR"
IsEosDir = True
else:
print "IS NOT EOS DIR"
IsEosDir = False

if IsEosDir:
print("eos mkdir -p %s" % (OUTPUTDIR) )
os.system("eos mkdir -p %s" % (OUTPUTDIR) )
else:
print("mkdir -p %s" % (OUTPUTDIR) )
os.system("mkdir -p %s" % (OUTPUTDIR) )

os.chdir("%s/src" % (CMSSWVERSION))

# loop over samples
pythonconfignameExt = ((PYTHONCONFIG.split("/")[-1]).split("PROCESSNAME_")[-1]).split(".")[0]
#print pythonconfignameExt

MGKKValues = [500, 4000]
RValues = [0.1, 0.7]
relwidth = 0.01 # 1%

for MGKK in MGKKValues:
for R in RValues:
MR = int(MGKK*R)
print MGKK, R

Rmod = str(R)
Rmod = re.sub("\.","p",Rmod)

CURRENTPROCESS = GENPROCESSNAME+"_"+"M1-"+str(MGKK)+"_R-"+Rmod

pythonfragment = CURRENTPROCESS+"_"+pythonconfignameExt+".py"
pythonfilename = CURRENTPROCESS+"_"+pythonconfignameExt+"_GEN.py"
#print pythonfilename
outputfilename = CURRENTPROCESS+"_"+pythonconfignameExt+"_GEN.root"
#print outputfilename

#create gen fragmet
outputcard = basedir_path+"/"+CMSSWVERSION+"/src/Configuration/Generator/python/"+pythonfragment
inputcard = basedir_path+"/"+PYTHONCONFIG

GENERATETHIS = "'ExcitedFermion:dg2dStar = on',\n'4000001:onMode = off',\n'4000001:onIfMatch = 24 2',\n'4000001:m0 = %s',\n'4000001:mWidth = %s',\n'4000001:doForceWidth = on',\n'24:onMode = off',\n'24:onIfMatch = 1 2',\n'24:m0 = %s',\n'24:mWidth = %s',\n'24:doForceWidth = on',\n'ExcitedFermion:Lambda = %s',\n'ExcitedFermion:coupFprime = 1.',\n'ExcitedFermion:coupF = 1.',\n'ExcitedFermion:coupFcol = 1.'" % (str(MGKK),str(float(MGKK*relwidth)),str(MR),str(float(MR*relwidth)),str(MGKK))

with open(outputcard, "wt") as fout:
with open(inputcard, "rt") as fin:
for line in fin:
## EDIT CARD
line = re.sub("THISPROCESSPARAMETERS",GENERATETHIS,line)
##
fout.write(line)

print("cmsDriver.py Configuration/Generator/python/%s --fileout %s/%s --mc --eventcontent RAWSIM --datatier GEN-SIM --conditions MCRUN2_71_V1::All --step GEN --magField 38T_PostLS1 --python_filename %s -n %s" % (pythonfragment,TMPDIR,outputfilename,pythonfilename,NEVENTS) )
os.system("cmsDriver.py Configuration/Generator/python/%s --fileout %s/%s --mc --eventcontent RAWSIM --datatier GEN-SIM --conditions MCRUN2_71_V1::All --step GEN --magField 38T_PostLS1 --python_filename %s -n %s" % (pythonfragment,TMPDIR,outputfilename,pythonfilename,NEVENTS) )

# move output in final directory
if IsEosDir:
TMPFILE = ("%s/%s" % (TMPDIR,outputfilename))
TMPFILE = re.sub("//","/",TMPFILE)
OUTPUTFILE = ("%s/%s" % (OUTPUTDIR,outputfilename))
OUTPUTFILE = re.sub("//","/",OUTPUTFILE)

print("eos cp %s %s" % (TMPFILE,OUTPUTFILE))
os.system("eos cp %s %s" % (TMPFILE,OUTPUTFILE))
print("rm -f %s" % (TMPFILE))
os.system("rm -f %s" % (TMPFILE))
else:
print("mv %s/%s %s/%s" % (TMPDIR,outputfilename,OUTPUTDIR,outputfilename))
os.system("mv %s/%s %s/%s" % (TMPDIR,outputfilename,OUTPUTDIR,outputfilename))

os.chdir("%s" % (basedir_path))

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import FWCore.ParameterSet.Config as cms

from Configuration.Generator.Pythia8CommonSettings_cfi import *
from Configuration.Generator.Pythia8CUEP8M1Settings_cfi import *

generator = cms.EDFilter("Pythia8GeneratorFilter",
comEnergy = cms.double(13000.0),
crossSection = cms.untracked.double(1),
filterEfficiency = cms.untracked.double(1),
maxEventsToPrint = cms.untracked.int32(0),
pythiaHepMCVerbosity = cms.untracked.bool(False),
pythiaPylistVerbosity = cms.untracked.int32(1),
PythiaParameters = cms.PSet(
pythia8CommonSettingsBlock,
pythia8CUEP8M1SettingsBlock,
processParameters = cms.vstring(
THISPROCESSPARAMETERS
),
parameterSets = cms.vstring('pythia8CommonSettings',
'pythia8CUEP8M1Settings',
'processParameters',
)
)
)

ProductionFilterSequence = cms.Sequence(generator)

0 comments on commit 256c898

Please sign in to comment.