O2-DQ User Interface 1.0.0
Loading...
Searching...
No Matches
dqEfficiency.py
Go to the documentation of this file.
1#!/usr/bin/env python
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 For dqEfficiency.cxx: https://github.com/AliceO2Group/O2Physics/blob/master/PWGDQ/Tasks/dqEfficiency.cxx
20
21import argparse
22import os
23import re
24from urllib.request import Request, urlopen
25import ssl
26
27import argcomplete
28from argcomplete.completers import ChoicesCompleter
29from commondeps.dplAodReader import DplAodReader
30from extramodules.choicesCompleterList import ChoicesCompleterList
31
32from extramodules.actionHandler import NoAction
33from extramodules.actionHandler import ChoicesAction
34from extramodules.dqLibGetter import DQLibGetter
35from extramodules.helperOptions import HelperOptions
36
37
38class DQEfficiency(object):
39
40 """
41 Class for Interface -> dqEfficiency.cxx Task -> Configurable, Process Functions
42
43 Args:
44 object (parser_args object): dqEfficiency.cxx Interface
45 """
46
48 self, parserDQEfficiency = argparse.ArgumentParser(
49 formatter_class = argparse.ArgumentDefaultsHelpFormatter,
50 description = "Example Usage: ./runDQEfficiency.py <yourConfig.json> --arg value "
51 ), helperOptions = HelperOptions(), dplAodReader = DplAodReader()
52 ):
53 super(DQEfficiency, self).__init__()
54 self.parserDQEfficiency = parserDQEfficiency
55 self.dplAodReader = dplAodReader
56 self.helperOptions = helperOptions
57 self.parserDQEfficiency.register("action", "none", NoAction)
58 self.parserDQEfficiency.register("action", "store_choice", ChoicesAction)
59
60 def addArguments(self):
61 """
62 This function allows to add arguments for parser_args() function
63 """
64
65 # Predefined Selections
66
67 readerPath = "configs/readerConfiguration_reducedEventMC.json"
68 writerPath = "configs/writerConfiguration_dileptonMC.json"
69
70 analysisSelections = {
71 "eventSelection": "Run event selection on DQ skimmed events",
72 "muonSelection": "Run muon selection on DQ skimmed muons",
73 "trackSelection": "Run barrel track selection on DQ skimmed tracks",
74 "sameEventPairing": "Run same event pairing selection on DQ skimmed data",
75 "dileptonTrackDimuonMuonSelection": "Run dimuon-muon pairing, using skimmed data",
76 "dileptonTrackDielectronKaonSelection": "Run dielectron-kaon pairing, using skimmed data",
77 }
78 analysisSelectionsList = []
79 for k, v in analysisSelections.items():
80 analysisSelectionsList.append(k)
81
82 sameEventPairingProcessSelections = {
83 "JpsiToEE": "Run electron-electron pairing, with skimmed tracks",
84 "JpsiToMuMu": "Run muon-muon pairing, with skimmed muons",
85 "JpsiToMuMuVertexing": "Run muon-muon pairing and vertexing, with skimmed muons",
86 }
87 sameEventPairingProcessSelectionsList = []
88 for k, v in sameEventPairingProcessSelections.items():
89 sameEventPairingProcessSelectionsList.append(k)
90
91 booleanSelections = ["true", "false"]
92
93 # init for get DQ libraries
94 allAnalysisCuts, allMCSignals, allSels, allMixing = DQLibGetter.getAnalysisSelections(self)
95
96 # Interface
97
98 # analysis task selections
99 groupAnalysisSelections = self.parserDQEfficiency.add_argument_group(
100 title = "Data processor options: analysis-event-selection, analysis-muon-selection, analysis-track-selection, analysis-dilepton-track"
101 )
102 groupAnalysisSelections.add_argument(
103 "--analysis", help = "Skimmed process selections for MC Analysis", action = "store", nargs = "*", type = str,
104 metavar = "ANALYSIS", choices = analysisSelectionsList,
105 ).completer = ChoicesCompleterList(analysisSelectionsList)
106
107 for key, value in analysisSelections.items():
108 groupAnalysisSelections.add_argument(key, help = value, action = "none")
109
110 # same event pairing process function selection
111 groupProcessSEPSelections = self.parserDQEfficiency.add_argument_group(
112 title = "Data processor options: analysis-same-event-pairing"
113 )
114 groupProcessSEPSelections.add_argument(
115 "--process", help = "Skimmed process selections for analysis-same-event-pairing task", action = "store", nargs = "*",
116 type = str, metavar = "PROCESS", choices = sameEventPairingProcessSelectionsList,
117 ).completer = ChoicesCompleterList(sameEventPairingProcessSelectionsList)
118 groupProcessSEPSelections.add_argument(
119 "--cfgBarrelMCRecSignals", help = "Space separated list of MC signals (reconstructed)", nargs = "*", action = "store",
120 type = str, metavar = "CFGBARRELMCRECSIGNALS", choices = allMCSignals,
121 ).completer = ChoicesCompleterList(allMCSignals)
122 groupProcessSEPSelections.add_argument(
123 "--cfgBarrelMCGenSignals", help = "Space separated list of MC signals (generated)", nargs = "*", action = "store", type = str,
124 metavar = "CFGBARRELMCGENSIGNALS", choices = allMCSignals,
125 ).completer = ChoicesCompleterList(allMCSignals)
126 groupProcessSEPSelections.add_argument(
127 "--cfgFlatTables", help = "Produce a single flat tables with all relevant information of the pairs and single tracks",
128 action = "store", type = str.lower, choices = booleanSelections,
129 ).completer = ChoicesCompleter(booleanSelections)
130 groupProcess = self.parserDQEfficiency.add_argument_group(
131 title = "Choice List for analysis-same-event-pairing task Process options"
132 )
133
134 for key, value in sameEventPairingProcessSelections.items():
135 groupProcess.add_argument(key, help = value, action = "none")
136
137 # cfg for QA
138 groupQASelections = self.parserDQEfficiency.add_argument_group(
139 title = "Data processor options: analysis-event-selection, analysis-muon-selection, analysis-track-selection, analysis-event-mixing, analysis-dilepton-hadron"
140 )
141 groupQASelections.add_argument(
142 "--cfgQA", help = "If true, fill QA histograms", action = "store", type = str.lower, choices = (booleanSelections),
143 ).completer = ChoicesCompleter(booleanSelections)
144
145 # analysis-event-selection
146 groupAnalysisEventSelection = self.parserDQEfficiency.add_argument_group(title = "Data processor options: analysis-event-selection")
147 groupAnalysisEventSelection.add_argument(
148 "--cfgEventCuts", help = "Space separated list of event cuts", nargs = "*", action = "store", type = str,
149 metavar = "CFGEVENTCUTS", choices = allAnalysisCuts,
150 ).completer = ChoicesCompleterList(allAnalysisCuts)
151
152 # analysis-track-selection
153 groupAnalysisTrackSelection = self.parserDQEfficiency.add_argument_group(title = "Data processor options: analysis-track-selection")
154 groupAnalysisTrackSelection.add_argument(
155 "--cfgTrackCuts", help = "Space separated list of barrel track cuts", nargs = "*", action = "store", type = str,
156 metavar = "CFGTRACKCUTS", choices = allAnalysisCuts,
157 ).completer = ChoicesCompleterList(allAnalysisCuts)
158 groupAnalysisTrackSelection.add_argument(
159 "--cfgTrackMCSignals", help = "Space separated list of MC signals", nargs = "*", action = "store", type = str,
160 metavar = "CFGTRACKMCSIGNALS", choices = allMCSignals,
161 ).completer = ChoicesCompleterList(allMCSignals)
162
163 # analysis-muon-selection
164 groupAnalysisMuonSelection = self.parserDQEfficiency.add_argument_group(title = "Data processor options: analysis-muon-selection")
165 groupAnalysisMuonSelection.add_argument(
166 "--cfgMuonCuts", help = "Space separated list of muon cuts", nargs = "*", action = "store", type = str, metavar = "CFGMUONCUTS",
167 choices = allAnalysisCuts,
168 ).completer = ChoicesCompleterList(allAnalysisCuts)
169 groupAnalysisMuonSelection.add_argument(
170 "--cfgMuonMCSignals", help = "Space separated list of MC signals", nargs = "*", action = "store", type = str,
171 metavar = "CFGMUONMCSIGNALS", choices = allMCSignals,
172 ).completer = ChoicesCompleterList(allMCSignals)
173
174 # analysis-dilepton-track
175 groupAnalysisDileptonTrack = self.parserDQEfficiency.add_argument_group(title = "Data processor options: analysis-dilepton-track")
176 groupAnalysisDileptonTrack.add_argument(
177 "--cfgLeptonCuts", help = "Space separated list of barrel track cuts", nargs = "*", action = "store", type = str,
178 metavar = "CFGLEPTONCUTS", choices = allAnalysisCuts,
179 ).completer = ChoicesCompleterList(allAnalysisCuts)
180 groupAnalysisDileptonTrack.add_argument(
181 "--cfgFillCandidateTable", help = "Produce a single flat tables with all relevant information dilepton-track candidates",
182 action = "store", type = str.lower, choices = booleanSelections,
183 ).completer = ChoicesCompleter(booleanSelections)
184 groupAnalysisDileptonTrack.add_argument(
185 "--cfgBarrelDileptonMCRecSignals", help = "Space separated list of MC signals (reconstructed)", nargs = "*", action = "store",
186 type = str, metavar = "CFGBARRELDILEPTONMCRECSIGNALS", choices = allMCSignals,
187 ).completer = ChoicesCompleterList(allMCSignals)
188 groupAnalysisDileptonTrack.add_argument(
189 "--cfgBarrelDileptonMCGenSignals", help = "Space separated list of MC signals (generated)", nargs = "*", action = "store",
190 type = str, metavar = "CFGBARRELDILEPTONMCRECSIGNALS", choices = allMCSignals,
191 ).completer = ChoicesCompleterList(allMCSignals)
192
193 # Aod Writer - Reader configs
194 groupDPLReader = self.parserDQEfficiency.add_argument_group(
195 title = "Data processor options: internal-dpl-aod-reader, internal-dpl-aod-writer"
196 )
197 groupDPLReader.add_argument(
198 "--reader",
199 help = "Reader config JSON with path. For Standart Analysis use as default, for dilepton analysis change to dilepton JSON config file",
200 action = "store", default = readerPath, type = str
201 )
202 groupDPLReader.add_argument(
203 "--writer", help = "Argument for producing dileptonAOD.root. Set false for disable", action = "store", default = writerPath,
204 type = str
205 )
206
207 def parseArgs(self):
208 """
209 This function allows to save the obtained arguments to the parser_args() function
210
211 Returns:
212 Namespace: returns parse_args()
213 """
214
215 argcomplete.autocomplete(self.parserDQEfficiency, always_complete_options = False)
216 return self.parserDQEfficiency.parse_args()
217
218 def mergeArgs(self):
219 """
220 This function allows to merge parser_args argument information from different classes
221 """
222
223 self.helperOptions.parserHelperOptions = self.parserDQEfficiency
225
226 self.dplAodReader.parserDplAodReader = self.parserDQEfficiency
228
229 self.addArguments()
def __init__(self, parserDQEfficiency=argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, description="Example Usage: ./runDQEfficiency.py <yourConfig.json> --arg value "), helperOptions=HelperOptions(), dplAodReader=DplAodReader())
Definition: dqEfficiency.py:52