|
| 1 | +#! /usr/bin/env python3 |
| 2 | + |
| 3 | +### @author: Paul Buehler |
| 4 | +### @email: paul.buhler@cern.ch |
| 5 | + |
| 6 | +import argparse |
| 7 | +import os |
| 8 | +import subprocess |
| 9 | + |
| 10 | +def createJson(args): |
| 11 | + templateFile = os.getenv("O2DPG_ROOT")+"/MC/config/PWGUD/templates/ALICE_Graniitti.temp" |
| 12 | + jsonFile = "ALICE_Graniitti.json" |
| 13 | + processes = { |
| 14 | + "kCon_pipi" : { |
| 15 | + "OUTPUT" : "ALICE_Con_pipi", |
| 16 | + "ENERGY" : 13600, |
| 17 | + "PROCESS" : "PP[RES+CON]<C> -> pi+ pi-", |
| 18 | + "RES" : "" |
| 19 | + }, |
| 20 | + "kConRes_pipi" : { |
| 21 | + "OUTPUT" : "ALICE_Con_pipi", |
| 22 | + "ENERGY" : 13600, |
| 23 | + "PROCESS" : "PP[RES+CON]<C> -> pi+ pi-", |
| 24 | + "RES" : '["f0_500", "rho_770", "f0_980", "phi_1020", "f2_1270", "f0_1500", "f2_1525", "f0_1710", "f2_2150"]' |
| 25 | + }, |
| 26 | + "kCon_KK" : { |
| 27 | + "OUTPUT" : "ALICE_Con_pipi", |
| 28 | + "ENERGY" : 13600, |
| 29 | + "PROCESS" : "PP[RES+CON]<C> -> pi+ pi-", |
| 30 | + "RES" : "" |
| 31 | + }, |
| 32 | + "kConRes_KK" : { |
| 33 | + "OUTPUT" : "ALICE_Con_pipi", |
| 34 | + "ENERGY" : 13600, |
| 35 | + "PROCESS" : "PP[RES+CON]<C> -> pi+ pi-", |
| 36 | + "RES" : '["f0_500", "rho_770", "f0_980", "phi_1020", "f2_1270", "f0_1500", "f2_1525", "f0_1710", "f2_2150"]' |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + # is process defined? |
| 41 | + if not args.process in processes.keys(): |
| 42 | + print("FATAL ERROR: ") |
| 43 | + print(" Process ", args.process) |
| 44 | + print(" is not defined!") |
| 45 | + exit() |
| 46 | + procdefs = processes[args.process] |
| 47 | + |
| 48 | + # copy templateFile to jsonFile |
| 49 | + cmd = "cp "+templateFile+" "+jsonFile |
| 50 | + if subprocess.call(cmd, shell=True) > 0: |
| 51 | + print("FATAL ERROR: ") |
| 52 | + print(" ", templateFile) |
| 53 | + print(" can not be copied to") |
| 54 | + print(" ", jsonFile) |
| 55 | + exit() |
| 56 | + |
| 57 | + # update jsonFile |
| 58 | + stat = 0 |
| 59 | + # OUTPUT |
| 60 | + nl = ' "OUTPUT" : "' + procdefs["OUTPUT"] + '",' |
| 61 | + cmd = "sed -i '/\"OUTPUT\"/c\\" + nl + "' " + jsonFile |
| 62 | + stat = stat + subprocess.call(cmd, shell=True) |
| 63 | + # NEVENTS |
| 64 | + nl = ' "NEVENTS" : ' + args.nEvents + ',' |
| 65 | + cmd = "sed -i '/\"NEVENTS\"/c\\" + nl + "' " + jsonFile |
| 66 | + stat = stat + subprocess.call(cmd, shell=True) |
| 67 | + # ENERGY |
| 68 | + beamEne = str(int(args.eCM)/2) |
| 69 | + nl = ' "ENERGY" : [' + beamEne + ', ' + beamEne + '],' |
| 70 | + cmd = "sed -i '/\"ENERGY\"/c\\" + nl + "' " + jsonFile |
| 71 | + stat = stat + subprocess.call(cmd, shell=True) |
| 72 | + # PROCESS |
| 73 | + nl = ' "PROCESS" : "' + procdefs["PROCESS"] + '",' |
| 74 | + cmd = "sed -i '/\"PROCESS\"/c\\" + nl + "' " + jsonFile |
| 75 | + stat = stat + subprocess.call(cmd, shell=True) |
| 76 | + # RES |
| 77 | + if procdefs["RES"] == "": |
| 78 | + nl = ' "RES" : [],' |
| 79 | + else: |
| 80 | + nl = ' "RES" : ' + procdefs["RES"] + ',' |
| 81 | + cmd = "sed -i '/\"RES\"/c\\" + nl + "' " + jsonFile |
| 82 | + stat = stat + subprocess.call(cmd, shell=True) |
| 83 | + |
| 84 | + return jsonFile |
| 85 | + |
| 86 | +# main |
| 87 | + |
| 88 | +parser = argparse.ArgumentParser(description='Make Graniitti configuration', |
| 89 | + formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
| 90 | + |
| 91 | +parser.add_argument('--process',default=None, choices=['kCon_pipi', 'kConRes_pipi', 'kCon_KK', 'kConRes_KK'], |
| 92 | + help='Process to switch on') |
| 93 | + |
| 94 | +parser.add_argument('--nEvents', default='100', |
| 95 | + help='Number of events to generate per TF') |
| 96 | + |
| 97 | +parser.add_argument('--eCM', type=float, default='13600', |
| 98 | + help='Centre-of-mass energy') |
| 99 | + |
| 100 | +parser.add_argument('--rapidity', default='cent', choices=['cent_eta', 'muon_eta'], |
| 101 | + help='Rapidity to select') |
| 102 | + |
| 103 | +parser.add_argument('--output', default='GenGraniitti.ini', |
| 104 | + help='Where to write the configuration') |
| 105 | + |
| 106 | +args = parser.parse_args() |
| 107 | + |
| 108 | +### prepare the json configuration file for graniitti |
| 109 | +jsonFile = createJson(args) |
| 110 | + |
| 111 | +### open output file |
| 112 | +fout = open(args.output, 'w') |
| 113 | + |
| 114 | +### Generator |
| 115 | +fout.write('[GeneratorExternal] \n') |
| 116 | +fout.write('fileName = ${O2DPG_ROOT}/MC/config/PWGUD/external/generator/GeneratorGraniitti.C \n') |
| 117 | +fout.write('funcName = GeneratorGraniitti("%s") \n' % ("../"+jsonFile)) |
| 118 | + |
| 119 | +###Trigger |
| 120 | +fout.write('[TriggerExternal] \n') |
| 121 | +fout.write('fileName = ${O2DPG_ROOT}/MC/config/PWGUD/trigger/selectParticlesInAcceptance.C \n') |
| 122 | +if args.rapidity == 'cent_rap': |
| 123 | + fout.write('funcName = selectMotherPartInAcc(-0.9,0.9) \n') |
| 124 | +if args.rapidity == 'muon_rap': |
| 125 | + fout.write('funcName = selectMotherPartInAcc(-4.0,-2.5) \n') |
| 126 | +if args.rapidity == 'cent_eta': |
| 127 | + fout.write('funcName = selectDaughterPartInAcc(-0.95,0.95) \n') |
| 128 | +if args.rapidity == 'muon_eta': |
| 129 | + fout.write('funcName = selectDaughterPartInAcc(-4.05,-2.45) \n') |
| 130 | + |
| 131 | +### close outout file |
| 132 | +fout.close() |
0 commit comments