Belle II Software development
TrainingRunMixin Class Reference
Inheritance diagram for TrainingRunMixin:
BrowseTFileOnTerminateRunMixin PostProcessingRunMixin EmptyRun

Public Member Functions

def identifier (self)
 
def sample_file_name (self)
 
def create_argument_parser (self, **kwds)
 
def postprocess (self)
 

Public Attributes

 task
 Process each event according to the user's desired task (train, eval, explore)
 
 output_file_name
 Set file name for the TBrowser to show if demanded.
 

Static Public Attributes

str task = "train"
 Recording / training task selected.
 
None variables = None
 Input variable for the training or the classification analysis.
 
None groupby = None
 Input groupby the classification analysis.
 
None auxiliaries = None
 Input auxiliaries the classification analysis.
 
str truth = "truth"
 Truth variable name.
 

Detailed Description

Prepare and execute a basf2 job to train neural network, postprocess, and inspect

Definition at line 19 of file training.py.

Member Function Documentation

◆ create_argument_parser()

def create_argument_parser (   self,
**  kwds 
)
Create argument parser

Reimplemented from BrowseTFileOnTerminateRunMixin.

Definition at line 50 of file training.py.

50 def create_argument_parser(self, **kwds):
51 """Create argument parser"""
52 argument_parser = super().create_argument_parser(**kwds)
53
54 argument_parser.add_argument(
55 "--task",
56 choices=NonstrictChoices(["train", "eval", "explore", ]),
57 default=self.task,
58 dest="task",
59 help=("Select a prepared recording task")
60 )
61
62 return argument_parser
63

◆ identifier()

def identifier (   self)
Database identifier of the filte being trained

Definition at line 38 of file training.py.

38 def identifier(self):
39 """Database identifier of the filte being trained"""
40 return "trackfindingcdc_" + self.__class__.__name__[:-len("TrainingRun")]
41

◆ postprocess()

def postprocess (   self)
Run the training as post-processing job

To run only the training run with --postprocess-only

Reimplemented from BrowseTFileOnTerminateRunMixin.

Definition at line 64 of file training.py.

64 def postprocess(self):
65 """Run the training as post-processing job
66
67 To run only the training run with --postprocess-only
68 """
69
70 if self.task == "train":
71 cmd = [
72 "trackfindingcdc_teacher",
73 ]
74
75 if self.variables:
76 cmd += ["--variables"]
77 cmd += self.variables
78
79 cmd += [
80 "--identifier=" + self.identifier,
81 "--truth=" + self.truth,
82 self.sample_file_name,
83 ]
84 print("Running", cmd)
85 subprocess.call(cmd)
86
87 # Move training file to the right location
88 if self.identifier.endswith(".xml"):
89 tracking_data_dir_path = os.path.join(os.environ["BELLE2_LOCAL_DIR"], "tracking", "data")
90 shutil.copy(self.identifier, tracking_data_dir_path)
91
92 else:
93 cmd = [
94 "trackfindingcdc-classification-overview",
95 ]
96
97 if self.variables:
98 cmd += ["-v"]
99 cmd += self.variables
100
101 if self.groupby is not None:
102 cmd += ["-g"]
103 if isinstance(self.groupby, str):
104 cmd += [self.groupby]
105 else:
106 cmd += self.groupby
107
108 if self.auxiliaries is not None:
109 cmd += ["-a"]
110 if isinstance(self.auxiliaries, str):
111 cmd += [self.auxiliaries]
112 else:
113 cmd += self.auxiliaries
114
115 cmd += [
116 "--truth=" + self.truth,
117 self.sample_file_name,
118 ]
119 print("Running", cmd)
120 subprocess.call(cmd)
121
122 self.output_file_name = self.sample_file_name[:-len(".root")] + ".overview.root"
123
124 super().postprocess()

◆ sample_file_name()

def sample_file_name (   self)
File name of the recorded sample to be trained on

Defaults to the class name minus the mandatory TrainingRun postfix

Definition at line 43 of file training.py.

43 def sample_file_name(self):
44 """File name of the recorded sample to be trained on
45
46 Defaults to the class name minus the mandatory TrainingRun postfix
47 """
48 return self.__class__.__name__[:-len("TrainingRun")] + '_' + self.task + '.root'
49

Member Data Documentation

◆ auxiliaries

None auxiliaries = None
static

Input auxiliaries the classification analysis.

Default use none

Definition at line 32 of file training.py.

◆ groupby

None groupby = None
static

Input groupby the classification analysis.

Default use no groupby

Definition at line 29 of file training.py.

◆ output_file_name

output_file_name

Set file name for the TBrowser to show if demanded.

Definition at line 122 of file training.py.

◆ task [1/2]

str task = "train"
static

Recording / training task selected.

Definition at line 23 of file training.py.

◆ task [2/2]

task

Process each event according to the user's desired task (train, eval, explore)

Definition at line 70 of file training.py.

◆ truth

str truth = "truth"
static

Truth variable name.

Definition at line 35 of file training.py.

◆ variables

None variables = None
static

Input variable for the training or the classification analysis.

Default use all variables

Definition at line 26 of file training.py.


The documentation for this class was generated from the following file: