O2-DQ User Interface 1.0.0
Loading...
Searching...
No Matches
runV0selector.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# PYTHON_ARGCOMPLETE_OK
3# -*- coding: utf-8 -*-
4
5# Copyright 2019-2020 CERN and copyright holders of ALICE O2.
6# See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
7# All rights not expressly granted are reserved.
8#
9# This software is distributed under the terms of the GNU General Public
10# License v3 (GPL Version 3), copied verbatim in the file "COPYING".
11#
12# In applying this license CERN does not waive the privileges and immunities
13# granted to it by virtue of its status as an Intergovernmental Organization
14# or submit itself to any jurisdiction.
15
16# \Author: ionut.cristian.arsene@cern.ch
17# \Interface: cevat.batuhan.tolon@cern.ch
18
19# Orginal Task: https://github.com/AliceO2Group/O2Physics/blob/master/PWGDQ/Tasks/v0selector.cxx
20
21import json
22import logging
23import logging.config
24import os
25from extramodules.converterManager import converterManager
26from extramodules.debugSettings import debugSettings
27
28from extramodules.monitoring import dispArgs
29from extramodules.dqTranscations import aodFileChecker, forgettedArgsChecker, jsonTypeChecker, mainTaskChecker, trackPropChecker
30from extramodules.pycacheRemover import runPycacheRemover
31
32from dqtasks.v0selector import V0selector
33
34
37
38centralityTableParameters = [
39 "estRun2V0M", "estRun2SPDtks", "estRun2SPDcls", "estRun2CL0", "estRun2CL1", "estFV0A", "estFT0M", "estFDDM", "estNTPV"
40 ]
41# TODO: Add genname parameter
42
43ft0Parameters = ["processFT0", "processNoFT0", "processOnlyFT0", "processRun2"]
44
45pidParameters = ["pid-el", "pid-mu", "pid-pi", "pid-ka", "pid-pr", "pid-de", "pid-tr", "pid-he", "pid-al"]
46
47ttreeList = []
48
49
52
53commonDeps = [
54 "o2-analysis-timestamp", "o2-analysis-event-selection", "o2-analysis-multiplicity-table", "o2-analysis-trackselection",
55 "o2-analysis-trackextension", "o2-analysis-pid-tof-base", "o2-analysis-pid-tof", "o2-analysis-pid-tof-full", "o2-analysis-pid-tof-beta",
56 "o2-analysis-pid-tpc-full"
57 ]
58
59# init args manually
60initArgs = V0selector()
61initArgs.mergeArgs()
62initArgs.parseArgs()
63
64args = initArgs.parseArgs()
65configuredCommands = vars(args) # for get args
66
67# Debug Settings
68debugSettings(args.debug, args.Logfile, fileName = "v0selector.log")
69
70forgettedArgsChecker(configuredCommands)
71
72
75
76# add prefix for args.pid for pid selection
77if args.pid is not None:
78 prefix_pid = "pid-"
79 args.pid = [prefix_pid + sub for sub in args.pid]
80
81# add prefix for args.FT0 for tof-event-time
82if args.FT0 is not None:
83 prefix_process = "process"
84 args.FT0 = prefix_process + args.FT0
85
86
87
88# Load the configuration file provided as the first parameter
89config = {}
90with open(args.cfgFileName) as configFile:
91 config = json.load(configFile)
92
93jsonTypeChecker(args.cfgFileName)
94
95taskNameInConfig = "v0-selector"
96taskNameInCommandLine = "o2-analysis-dq-v0-selector"
97
98mainTaskChecker(config, taskNameInConfig)
99
100
103
104logging.info("Only Select Configured as %s", args.onlySelect)
105if args.onlySelect == "true":
106 logging.info("INTERFACE MODE : JSON Overrider")
107if args.onlySelect == "false":
108 logging.info("INTERFACE MODE : JSON Additional")
109
110for key, value in config.items():
111 if isinstance(value, dict):
112 for value, value2 in value.items():
113
114 # aod
115 if value == "aod-file" and args.aod:
116 config[key][value] = args.aod
117 logging.debug(" - [%s] %s : %s", key, value, args.aod)
118 # QA Options
119 if value == "cfgWithQA" and args.cfgWithQA:
120 config[key][value] = args.cfgWithQA
121 logging.debug(" - [%s] %s : %s", key, value, args.cfgWithQA)
122
123 # PID Selections
124 if (value in pidParameters) and args.pid and key != "tof-pid":
125 if value in args.pid:
126 value2 = "1"
127 config[key][value] = value2
128 logging.debug(" - [%s] %s : %s", key, value, value2)
129 elif args.onlySelect == "true":
130 value2 = "-1"
131 config[key][value] = value2
132 logging.debug(" - [%s] %s : %s", key, value, value2)
133
134 # event-selection
135 if value == "syst" and args.syst:
136 config[key][value] = args.syst
137 logging.debug(" - [%s] %s : %s", key, value, args.syst)
138 if value == "muonSelection" and args.muonSelection:
139 config[key][value] = args.muonSelection
140 logging.debug(" - [%s] %s : %s", key, value, args.muonSelection)
141 if value == "customDeltaBC" and args.customDeltaBC:
142 config[key][value] = args.customDeltaBC
143 logging.debug(" - [%s] %s : %s", key, value, args.customDeltaBC)
144
145 # v0-selector
146 if value == "d_bz_input" and args.d_bz_input:
147 config[key][value] = args.d_bz_input
148 logging.debug(" - [%s] %s : %s", key, value, args.d_bz_input)
149 if value == "v0cospa" and args.v0cospa:
150 config[key][value] = args.v0cospa
151 logging.debug(" - [%s] %s : %s", key, value, args.v0cospa)
152 if value == "dcav0dau" and args.dcav0dau:
153 config[key][value] = args.dcav0dau
154 logging.debug(" - [%s] %s : %s", key, value, args.dcav0dau)
155 if value == "v0Rmin" and args.v0Rmin:
156 config[key][value] = args.v0Rmin
157 logging.debug(" - [%s] %s : %s", key, value, args.v0Rmin)
158 if value == "v0Rmax" and args.v0Rmax:
159 config[key][value] = args.v0Rmax
160 logging.debug(" - [%s] %s : %s", key, value, args.v0Rmax)
161 if value == "dcamin" and args.dcamin:
162 config[key][value] = args.dcamin
163 logging.debug(" - [%s] %s : %s", key, value, args.dcamin)
164 if value == "dcamax" and args.dcamax:
165 config[key][value] = args.dcamax
166 logging.debug(" - [%s] %s : %s", key, value, args.dcamax)
167 if value == "mincrossedrows" and args.mincrossedrows:
168 config[key][value] = args.mincrossedrows
169 logging.debug(" - [%s] %s : %s", key, value, args.mincrossedrows)
170 if value == "maxchi2tpc" and args.maxchi2tpc:
171 config[key][value] = args.maxchi2tpc
172 logging.debug(" - [%s] %s : %s", key, value, args.maxchi2tpc)
173
174 # centrality-table
175 if (value in centralityTableParameters) and args.est:
176 if value in args.est:
177 value2 = "1"
178 config[key][value] = value2
179 logging.debug(" - [%s] %s : %s", key, value, value2)
180 elif args.onlySelect == "true":
181 value2 = "-1"
182 config[key][value] = value2
183 logging.debug(" - [%s] %s : %s", key, value, value2)
184
185 # multiplicity-table
186 if value == "doVertexZeq" and args.isVertexZeq:
187 if args.isVertexZeq == "true":
188 config[key][value] = "1"
189 config[key]["doDummyZeq"] = "0"
190 logging.debug(" - %s %s : 1", key, value)
191 logging.debug(" - [%s] doDummyZeq : 0", key)
192 if args.isVertexZeq == "false":
193 config[key][value] = "0"
194 config[key]["doDummyZeq"] = "1"
195 logging.debug(" - %s %s : 0", key, value)
196 logging.debug(" - [%s] doDummyZeq : 1", key)
197
198 # tof-pid, tof-pid-full
199 if value == "processWSlice" and args.isWSlice:
200 if args.isWSlice == "true":
201 config[key][value] = "true"
202 config[key]["processWoSlice"] = "false"
203 logging.debug(" - %s %s : true", key, value)
204 logging.debug(" - [%s] processWoSlice : false", key)
205 if args.isWSlice == "false":
206 config[key][value] = "false"
207 config[key]["processWoSlice"] = "true"
208 logging.debug(" - %s %s : false", key, value)
209 logging.debug(" - [%s] processWoSlice : true", key)
210
211 # tof-pid-beta
212 if value == "tof-expreso" and args.tof_expreso:
213 config[key][value] = args.tof_expreso
214 logging.debug(" - [%s] %s : %s", key, value, args.tof_expreso)
215
216 # tof-event-time
217 if (value in ft0Parameters) and args.FT0 and key == "tof-event-time":
218 if value == args.FT0:
219 value2 = "true"
220 config[key][value] = value2
221 logging.debug(" - [%s] %s : %s", key, value, value2)
222 elif value is not args.FT0:
223 value2 = "false"
224 config[key][value] = value2
225 logging.debug(" - [%s] %s : %s", key, value, value2)
226
227 # track-selection
228 if args.itsMatching:
229 config[key][value] = args.itsMatching
230 logging.debug(" - [%s] %s : %s", key, value, args.itsMatching)
231
232aodFileChecker(args.aod)
233# trackPropTransaction(args.add_track_prop, commonDeps)
234
235# Regarding to perfomance issues in argcomplete package, we should import later
236from extramodules.getTTrees import getTTrees
237
238# Converter Management
239if args.aod is not None:
240 ttreeList = getTTrees(args.aod)
241else:
242 ttreeList = config["internal-dpl-aod-reader"]["aod-file"]
243
244converterManager(ttreeList, commonDeps)
245trackPropChecker(commonDeps, commonDeps)
246
247
250
251# Write the updated configuration file into a temporary file
252updatedConfigFileName = "tempConfigV0Selector.json"
253
254with open(updatedConfigFileName, "w") as outputFile:
255 json.dump(config, outputFile, indent = 2)
256
257# Check which dependencies need to be run
258depsToRun = {}
259for dep in commonDeps:
260 depsToRun[dep] = 1
261
262commandToRun = (
263 taskNameInCommandLine + " --configuration json://" + updatedConfigFileName + " --severity error --shm-segment-size 12000000000 -b"
264 )
265for dep in depsToRun.keys():
266 commandToRun += " | " + dep + " --configuration json://" + updatedConfigFileName + " -b"
267 logging.debug("%s added your workflow", dep)
268"""
269if args.add_mc_conv:
270 logging.debug("o2-analysis-mc-converter added your workflow")
271 commandToRun += (" | o2-analysis-mc-converter --configuration json://" + updatedConfigFileName + " -b")
272
273if args.add_fdd_conv:
274 commandToRun += (" | o2-analysis-fdd-converter --configuration json://" + updatedConfigFileName + " -b")
275 logging.debug("o2-analysis-fdd-converter added your workflow")
276
277if args.add_track_prop:
278 commandToRun += (" | o2-analysis-track-propagation --configuration json://" + updatedConfigFileName + " -b")
279 logging.debug("o2-analysis-track-propagation added your workflow")
280
281if args.add_weakdecay_ind:
282 commandToRun += (" | o2-analysis-weak-decay-indices --configuration json://" + updatedConfigFileName + " -b")
283 logging.debug("o2-analysis-weak-decay-indices added your workflow")
284"""
285
286print("====================================================================================================================")
287logging.info("Command to run:")
288logging.info(commandToRun)
289print("====================================================================================================================")
290
291# Listing Added Commands
292dispArgs(configuredCommands)
293
294os.system(commandToRun)
295
296runPycacheRemover()