Belle II Software development
RecoTrackQEDataCollectionTask Class Reference
Inheritance diagram for RecoTrackQEDataCollectionTask:

Public Member Functions

 get_records_file_name (self, n_events=None, random_seed=None, recotrack_option=None)
 Filename of the recorded/collected data for the final QE MVA training.
 
 get_input_files (self, n_events=None, random_seed=None)
 
 requires (self)
 
 output (self)
 
 create_path (self)
 

Static Public Attributes

 n_events = b2luigi.IntParameter()
 Number of events to generate.
 
 experiment_number = b2luigi.IntParameter()
 Experiment number of the conditions database, e.g.
 
 random_seed = b2luigi.Parameter()
 Random basf2 seed used by the GenerateSimTask.
 
 cdc_training_target = b2luigi.Parameter()
 Feature/variable to use as truth label for the CDC track quality estimator.
 
 recotrack_option
 RecoTrack option, use string that is additive: deleteCDCQI0XY (= deletes CDCTracks with CDC-QI below 0.XY), useCDC (= uses trained CDC stored in datafiles/), useVXD (uses trained VXD stored in datafiles/), noVXD (= doesn't use the VXD MVA at all)
 
 fast_bdt_option
 Hyperparameter option of the FastBDT algorithm.
 
 process_type
 files (USESIMBB/EE) or running on existing reconstructed files (USERECBB/EE)
 
str queue = 'l'
 specify queue.
 

Detailed Description

Collect variables/features from the reco track reconstruction including the
fit and write them to a ROOT file.

These variables are to be used as labelled training data for the MVA
classifier which is the MVA track quality estimator.  The collected
variables include the classifier outputs from the VXD and CDC quality
estimators, namely the CDC and VXD quality indicators, combined with fit,
merger, timing, energy loss information etc.  This task requires the
subdetector quality estimators to be trained.

Definition at line 917 of file combined_quality_estimator_teacher.py.

Member Function Documentation

◆ create_path()

create_path ( self)
Create basf2 reconstruction path that should mirror the default path
from ``add_tracking_reconstruction()``, but with modules for the VXD QE
and CDC QE application and for collection of variables for the reco
track quality estimator.

Definition at line 1053 of file combined_quality_estimator_teacher.py.

1053 def create_path(self):
1054 """
1055 Create basf2 reconstruction path that should mirror the default path
1056 from ``add_tracking_reconstruction()``, but with modules for the VXD QE
1057 and CDC QE application and for collection of variables for the reco
1058 track quality estimator.
1059 """
1060 path = basf2.create_path()
1061 inputFileNames = self.get_input_files()
1062 path.add_module(
1063 "RootInput",
1064 inputFileNames=inputFileNames,
1065 )
1066 path.add_module("Gearbox")
1067
1068 # First add tracking reconstruction with default quality estimation modules
1069 mvaCDC = True
1070 mvaVXD = True
1071 if 'noCDC' in self.recotrack_option:
1072 mvaCDC = False
1073 if 'noVXD' in self.recotrack_option:
1074 mvaVXD = False
1075 if 'DATA' in self.random_seed:
1076 from rawdata import add_unpackers
1077 add_unpackers(path)
1078 tracking.add_tracking_reconstruction(path, add_cdcTrack_QI=mvaCDC, add_vxdTrack_QI=mvaVXD, add_recoTrack_QI=True)
1079
1080 cdc_identifier = ""
1081 # if data shall be processed check if newly trained mva files are available. Otherwise use default ones (CDB payloads):
1082 # if useCDC/VXD is specified, use the identifier lying in datafiles/ Otherwise, replace weightfile identifiers from
1083 # defaults (CDB payloads) to new weightfiles created by this b2luigi script
1084 if ('DATA' in self.random_seed or 'useCDC' in self.recotrack_option) and 'noCDC' not in self.recotrack_option:
1085 cdc_identifier = 'datafiles/' + \
1086 CDCQETeacherTask.get_weightfile_identifier(CDCQETeacherTask, fast_bdt_option=self.fast_bdt_option) + '.xml'
1087 if os.path.exists(cdc_identifier):
1088 replace_cdc_qi = True
1089 elif 'useCDC' in self.recotrack_option:
1090 raise ValueError(f"CDC QI Identifier not found: {cdc_identifier}")
1091 else:
1092 replace_cdc_qi = False
1093 elif 'noCDC' in self.recotrack_option:
1094 replace_cdc_qi = False
1095 else:
1096 cdc_identifier = self.get_input_file_names(
1097 CDCQETeacherTask.get_weightfile_identifier(
1098 CDCQETeacherTask, fast_bdt_option=self.fast_bdt_option) + '.xml')[0]
1099 replace_cdc_qi = True
1100 if ('DATA' in self.random_seed or 'useVXD' in self.recotrack_option) and 'noVXD' not in self.recotrack_option:
1101 vxd_identifier = 'datafiles/' + \
1102 VXDQETeacherTask.get_weightfile_identifier(VXDQETeacherTask, fast_bdt_option=self.fast_bdt_option) + '.xml'
1103 if os.path.exists(vxd_identifier):
1104 replace_vxd_qi = True
1105 print(f"vxd_identifier is {vxd_identifier}")
1106 elif 'useVXD' in self.recotrack_option:
1107 raise ValueError(f"VXD QI Identifier not found: {vxd_identifier}")
1108 else:
1109 replace_vxd_qi = False
1110 elif 'noVXD' in self.recotrack_option:
1111 replace_vxd_qi = False
1112 else:
1113 vxd_identifier = self.get_input_file_names(
1114 VXDQETeacherTask.get_weightfile_identifier(
1115 VXDQETeacherTask, fast_bdt_option=self.fast_bdt_option) + '.xml')[0]
1116 replace_vxd_qi = True
1117
1118 cdc_qe_mva_filter_parameters = None
1119 # if tracks below a certain CDC QI index shall be deleted online, this needs to be specified in the filter parameters.
1120 # this is also possible in case of the default (CBD) payloads.
1121 cut = 0
1122 if 'deleteCDCQI' in self.recotrack_option:
1123 cut_index = self.recotrack_option.find('deleteCDCQI') + len('deleteCDCQI')
1124 cut = int(self.recotrack_option[cut_index:cut_index+3])/100.
1125 if replace_cdc_qi:
1126 cdc_qe_mva_filter_parameters = {
1127 "identifier": cdc_identifier, "cut": cut}
1128 else:
1129 cdc_qe_mva_filter_parameters = {
1130 "cut": cut}
1131 elif replace_cdc_qi:
1132 cdc_qe_mva_filter_parameters = {
1133 "identifier": cdc_identifier}
1134 basf2.conditions.prepend_testing_payloads("localdb/database.txt")
1135
1136 if cdc_qe_mva_filter_parameters is not None and cdc_identifier is not None:
1137 name = 'TrackingMVAFilterParameters'
1138 cdc_qe_mva_filter_parameters = {'DBPayloadName': name}
1139 if replace_vxd_qi and vxd_identifier is not None:
1140 vxd_name = 'VXDQualityEstimatorMVA'
1141 # Added for debugging
1142 if cdc_qe_mva_filter_parameters is not None:
1143 # if no cut is specified, the default value is at zero and nothing is deleted.
1144 print(f'cdc_qe_mva_filter_parameters is {cdc_qe_mva_filter_parameters}')
1145 basf2.set_module_parameters(
1146 path,
1147 name="TFCDC_TrackQualityEstimator",
1148 filterParameters=cdc_qe_mva_filter_parameters,
1149 deleteTracks=True,
1150 resetTakenFlag=True,
1151 deactivateIfDeadBoard=False, # original behavior before deactivateIfDeadBoard was introduced
1152 )
1153 if replace_vxd_qi:
1154 print(f"replace_vxd_qi is true and vxd_identifier is {vxd_identifier}")
1155 basf2.set_module_parameters(
1156 path,
1157 name="VXDQualityEstimatorMVA",
1158 WeightFileIdentifier=vxd_name)
1159
1160 # Replace final quality estimator module by training data collector module
1161 track_qe_module_name = "TrackQualityEstimatorMVA"
1162 mc_track_matcher_module_name = "MCRecoTracksMatcher"
1163 qe_module_found = False
1164 mc_matcher_module_found = False
1165 new_path = basf2.create_path()
1166 for module in path.modules():
1167 if module.name() == track_qe_module_name:
1168 # the TrackCreator needs to be conducted before the Collector such that
1169 # MDSTTracks are related to RecoTracks and d0 and z0 can be read out
1170 new_path.add_module(
1171 'TrackCreator',
1172 pdgCodes=[
1173 211,
1174 321,
1175 2212],
1176 recoTrackColName='RecoTracks',
1177 trackColName='MDSTTracks') # , useClosestHitToIP=True, useBFieldAtHit=True)
1178 qe_module_found = True
1179 elif module.name() == mc_track_matcher_module_name:
1180 new_path.add_module(module)
1181 # move TrackQETrainingDataCollector module after the MCRecoTracksMatcher module
1182 new_path.add_module(
1183 "TrackQETrainingDataCollector",
1184 TrainingDataOutputName=self.get_output_file_name(self.get_records_file_name()),
1185 collectEventFeatures=True
1186 )
1187 mc_matcher_module_found = True
1188 else:
1189 new_path.add_module(module)
1190 if not qe_module_found:
1191 raise KeyError(f"No module {track_qe_module_name} found in path")
1192 if not mc_matcher_module_found:
1193 raise KeyError(f"No module {mc_matcher_module_found} found in path")
1194 path = new_path
1195 return path
1196
1197

◆ get_input_files()

get_input_files ( self,
n_events = None,
random_seed = None )
Get input file names depending on the use case: If they already exist, search in
the corresponding folders, for data check the specified list and if they are created
in the same run, check for the task that produced them.

Definition at line 988 of file combined_quality_estimator_teacher.py.

988 def get_input_files(self, n_events=None, random_seed=None):
989 """
990 Get input file names depending on the use case: If they already exist, search in
991 the corresponding folders, for data check the specified list and if they are created
992 in the same run, check for the task that produced them.
993 """
994 if n_events is None:
995 n_events = self.n_events
996 if random_seed is None:
997 random_seed = self.random_seed
998 if "USESIM" in random_seed:
999 if 'USESIMBB' in random_seed:
1000 random_seed = 'BBBAR_' + random_seed.split("_", 1)[1]
1001 elif 'USESIMEE' in random_seed:
1002 random_seed = 'BHABHA_' + random_seed.split("_", 1)[1]
1003 return ['datafiles/' + GenerateSimTask.output_file_name(GenerateSimTask,
1004 n_events=n_events, random_seed=random_seed)]
1005 elif "DATA" in random_seed:
1006 return MasterTask.datafiles
1007 else:
1008 return self.get_input_file_names(GenerateSimTask.output_file_name(
1009 GenerateSimTask, n_events=n_events, random_seed=random_seed))
1010

◆ get_records_file_name()

get_records_file_name ( self,
n_events = None,
random_seed = None,
recotrack_option = None )

Filename of the recorded/collected data for the final QE MVA training.

Create output file name depending on number of events and production
mode that is specified in the random_seed string.

Definition at line 963 of file combined_quality_estimator_teacher.py.

963 def get_records_file_name(self, n_events=None, random_seed=None, recotrack_option=None):
964 """
965 Create output file name depending on number of events and production
966 mode that is specified in the random_seed string.
967 """
968 if n_events is None:
969 n_events = self.n_events
970 if random_seed is None:
971 random_seed = self.random_seed
972 if recotrack_option is None:
973 if isinstance(self.recotrack_option, str):
974 recotrack_option = self.recotrack_option
975 else:
976 recotrack_option = self.recotrack_option._default
977 if 'rec' not in random_seed:
978 random_seed += '_rec'
979 if 'DATA' in random_seed:
980 return 'qe_records_DATA_rec.root'
981 else:
982 if 'USESIMBB' in random_seed:
983 random_seed = 'BBBAR_' + random_seed.split("_", 1)[1]
984 elif 'USESIMEE' in random_seed:
985 random_seed = 'BHABHA_' + random_seed.split("_", 1)[1]
986 return 'qe_records_N' + str(n_events) + '_' + random_seed + '_' + recotrack_option + '.root'
987

◆ output()

output ( self)
Generate list of output files that the task should produce.
The task is considered finished if and only if the outputs all exist.

Definition at line 1046 of file combined_quality_estimator_teacher.py.

1046 def output(self):
1047 """
1048 Generate list of output files that the task should produce.
1049 The task is considered finished if and only if the outputs all exist.
1050 """
1051 yield self.add_to_output(self.get_records_file_name())
1052

◆ requires()

requires ( self)
Generate list of luigi Tasks that this Task depends on.

Definition at line 1011 of file combined_quality_estimator_teacher.py.

1011 def requires(self):
1012 """
1013 Generate list of luigi Tasks that this Task depends on.
1014 """
1015 if "USESIM" in self.random_seed or "DATA" in self.random_seed:
1016 for filename in self.get_input_files():
1017 yield CheckExistingFile(
1018 filename=filename,
1019 )
1020 else:
1021 yield SplitNMergeSimTask(
1022 bkgfiles_dir=MasterTask.bkgfiles_by_exp[self.experiment_number],
1023 random_seed=self.random_seed,
1024 n_events=self.n_events,
1025 experiment_number=self.experiment_number,
1026 )
1027 if "DATA" not in self.random_seed:
1028 if 'useCDC' not in self.recotrack_option and 'noCDC' not in self.recotrack_option:
1029 yield CDCQETeacherTask(
1030 n_events_training=MasterTask.n_events_training,
1031 experiment_number=self.experiment_number,
1032 training_target=self.cdc_training_target,
1033 process_type=self.random_seed.split("_", 1)[0],
1034 exclude_variables=MasterTask.exclude_variables_cdc,
1035 fast_bdt_option=self.fast_bdt_option,
1036 )
1037 if 'useVXD' not in self.recotrack_option and 'noVXD' not in self.recotrack_option:
1038 yield VXDQETeacherTask(
1039 n_events_training=MasterTask.n_events_training,
1040 experiment_number=self.experiment_number,
1041 process_type=self.random_seed.split("_", 1)[0],
1042 exclude_variables=MasterTask.exclude_variables_vxd,
1043 fast_bdt_option=self.fast_bdt_option,
1044 )
1045

Member Data Documentation

◆ cdc_training_target

cdc_training_target = b2luigi.Parameter()
static

Feature/variable to use as truth label for the CDC track quality estimator.

Definition at line 938 of file combined_quality_estimator_teacher.py.

◆ experiment_number

experiment_number = b2luigi.IntParameter()
static

Experiment number of the conditions database, e.g.

defines simulation geometry

Definition at line 933 of file combined_quality_estimator_teacher.py.

◆ fast_bdt_option

fast_bdt_option
static
Initial value:
= b2luigi.ListParameter(
)

Hyperparameter option of the FastBDT algorithm.

default are the FastBDT default values.

Definition at line 948 of file combined_quality_estimator_teacher.py.

◆ n_events

n_events = b2luigi.IntParameter()
static

Number of events to generate.

Definition at line 931 of file combined_quality_estimator_teacher.py.

◆ process_type

process_type
static
Initial value:
= b2luigi.Parameter(
)

files (USESIMBB/EE) or running on existing reconstructed files (USERECBB/EE)

Definition at line 954 of file combined_quality_estimator_teacher.py.

◆ queue

str queue = 'l'
static

specify queue.

E.g. choose between 'l' (long), 's' (short) or 'sx' (short, extra ram)

Definition at line 960 of file combined_quality_estimator_teacher.py.

◆ random_seed

random_seed = b2luigi.Parameter()
static

Random basf2 seed used by the GenerateSimTask.

It is further used to read of the production process to preserve clearness in the b2luigi output.

Definition at line 936 of file combined_quality_estimator_teacher.py.

◆ recotrack_option

recotrack_option
static
Initial value:
= b2luigi.Parameter(
)

RecoTrack option, use string that is additive: deleteCDCQI0XY (= deletes CDCTracks with CDC-QI below 0.XY), useCDC (= uses trained CDC stored in datafiles/), useVXD (uses trained VXD stored in datafiles/), noVXD (= doesn't use the VXD MVA at all)

Definition at line 942 of file combined_quality_estimator_teacher.py.


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