10combined_cdc_to_svd_ckf_mva_training
11-----------------------------------------
16This python script is used for the training and validation of the classifiers of
17the three MVA-based state filters and one result filter of the CDCToSVDSpacePointCKF.
18This CKF extraplates tracks found in the CDC into the SVD and adds SVD hits using a
19combinatorial tree search and a Kalman filter based track fit in each step.
21To avoid mistakes, b2luigi is used to create a task chain for a combined training and
22validation of all classifiers.
24The order of the b2luigi tasks in this script is as follows (top to bottom):
25* Two tasks to create input samples for training and testing (``GenerateSimTask`` and
26``SplitNMergeSimTask``). The ``SplitNMergeSimTask`` takes a number of events to be
27generated and a number of events per task to reduce runtime. It then divides the total
28number of events by the number of events per task and creates as ``GenerateSimTask`` as
29needed, each with a specific random seed, so that in the end the total number of
30training and testing events are simulated. The individual files are then combined
31by the SplitNMergeSimTask into one file each for training and testing.
32* The ``StateRecordingTask`` writes out the data required for training the state
34* The ``CKFStateFilterTeacherTask`` trains the state filter MVAs, using FastBDT by
35default, with a given set of options.
36* The ``ResultRecordingTask`` writes out the data used for the training of the result
37filter MVA. This task requires that the state filters have been trained before.
38* The ``CKFResultFilterTeacherTask`` trains the MVA, FastBDT per default, with a
39given set of FastBDT options. This requires that the result filter records have
40been created with the ``ResultRecordingTask``.
41* The ``ValidationAndOptimisationTask`` uses the trained weight files and cut values
42provided to run the tracking chain with the weight file under test, and also
43runs the tracking validation.
44* Finally, the ``MainTask`` is the "brain" of the script. It invokes the
45``ValidationAndOptimisationTask`` with the different combinations of FastBDT options
46and cut values on the MVA classifier output.
48Due to the dependencies, the calls of the task are reversed. The MainTask
49calls the ``ValidationAndOptimisationTask`` with different FastBDT options and cut
50values, and the ``ValidationAndOptimisationTask`` itself calls the required teacher,
51training, and simulation tasks.
53Each combination of FastBDT options and state filter cut values and candidate selection
54is used to train the result filter, which includes that the ``ResultRecordingTask``
55is executed multiple times with different combinations of FastBDT options and cut value
56and candidate selection.
58b2luigi: Understanding the steering file
59~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
61All trainings and validations are done in the correct order in this steering
62file. For the purpose of creating a dependency graph, the `b2luigi
63<https://b2luigi.readthedocs.io>`_ python package is used, which extends the
64`luigi <https://luigi.readthedocs.io>`_ package developed by spotify.
66Each task that has to be done is represented by a special class, which defines
67which defines parameters, output files and which other tasks with which
68parameters it depends on. For example a teacher task, which runs
69``basf2_mva_teacher.py`` to train the classifier, depends on a data collection
70task which runs a reconstruction and writes out track-wise variables into a root
71file
for training. An evaluation/validation task
for testing the classifier
72requires both the teacher task,
as it needs the weightfile to be present,
and
73also a data collection task, because it needs a dataset
for testing classifier.
75The final task that defines which tasks need to be done
for the steering file to
76finish
is the ``MainTask``. When you only want to run parts of the
77training/validation pipeline, you can comment out requirements
in the Master
78task
or replace them by lower-level tasks during debugging.
83This steering file relies on b2luigi_
for task scheduling. It can be installed
86 python3 -m pip install [--user] b2luigi
88Use the ``--user`` option
if you have
not rights to install python packages into
89your externals (e.g. because you are using cvmfs)
and install them
in
90``$HOME/.local`` instead.
95Instead of command line arguments, the b2luigi script
is configured via a
96``settings.json`` file. Open it
in your favorite text editor
and modify it to
97fit to your requirements.
102You can test the b2luigi without running it via::
104 python3 combined_cdc_to_svd_ckf_mva_training.py --dry-run
105 python3 combined_cdc_to_svd_ckf_mva_training.py --show-output
107This will show the outputs
and show potential errors
in the definitions of the
108luigi task dependencies. To run the the steering file
in normal (local) mode,
111 python3 combined_cdc_to_svd_ckf_mva_training.py
113One can use the interactive luigi web interface via the central scheduler
114which visualizes the task graph
while it
is running. Therefore, the scheduler
115daemon ``luigid`` has to run
in the background, which
is located
in
116``~/.local/bin/luigid``
in case b2luigi had been installed
with ``--user``. For
121Then, execute your steering (e.g.
in another terminal)
with::
123 python3 combined_cdc_to_svd_ckf_mva_training.py --scheduler-port 8886
125To view the web interface, open your webbrowser enter into the url bar::
129If you don
't run the steering file on the same machine on which you run your webbrowser, you have two options:
131 1. Run both the steering file and ``luigid`` remotely
and use
132 ssh-port-forwarding to your local host. Therefore, run on your local
135 ssh -N -f -L 8886:localhost:8886 <remote_user>@<remote_host>
137 2. Run the ``luigid`` scheduler locally
and use the ``--scheduler-host <your
138 local host>`` argument when calling the steering file
140Accessing the results / output files
141~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
143All output files are stored
in a directory structure
in the ``result_path`` set
in
144``settings.json``. The directory tree encodes the used b2luigi parameters. This
145ensures reproducibility
and makes parameter searches easy. Sometimes, it
is hard to
146find the relevant output files. You can view the whole directory structure by
147running ``tree <result_path>``. Ise the unix ``find`` command to find the files
148that interest you, e.g.::
150 find <result_path> -name
"*.root"
158from tracking import add_track_finding
159from tracking.path_utils import add_hit_preparation_modules
160from tracking.harvesting_validation.combined_module import CombinedTrackingValidationModule
164from ckf_training import my_basf2_mva_teacher, create_fbdt_option_string
166# wrap python modules that are used here but not in the externals into a try except block
167install_helpstring_formatter = ("\nCould not find {module} python module.Try installing it via\n"
168 " python3 -m pip install [--user] {module}\n")
171 from b2luigi.core.utils
import create_output_dirs
172 from b2luigi.basf2_helper
import Basf2PathTask, Basf2Task
173except ModuleNotFoundError:
174 print(install_helpstring_formatter.format(module=
"b2luigi"))
178class GenerateSimTask(Basf2PathTask):
180 Generate simulated Monte Carlo with background overlay.
182 Make sure to use different ``random_seed`` parameters
for the training data
183 format the classifier trainings
and for the test data
for the respective
184 evaluation/validation tasks.
188 experiment_number = b2luigi.IntParameter()
191 random_seed = b2luigi.Parameter()
193 n_events = b2luigi.IntParameter()
195 bkgfiles_dir = b2luigi.Parameter(
206 Create output file name depending on number of events and production
207 mode that
is specified
in the random_seed string.
209 :param n_events: Number of events to simulate.
210 :param random_seed: Random seed to use
for the simulation to create independent samples.
214 if random_seed
is None:
216 return "generated_mc_N" + str(n_events) +
"_" + random_seed +
".root"
220 Generate list of output files that the task should produce.
221 The task is considered finished
if and only
if the outputs all exist.
225 def create_path(self):
227 Create basf2 path to process with event generation
and simulation.
230 path = basf2.create_path()
234 path.add_module(
"EvtGenInput")
256 Generate simulated Monte Carlo with background overlay.
258 Make sure to use different ``random_seed`` parameters
for the training data
259 format the classifier trainings
and for the test data
for the respective
260 evaluation/validation tasks.
263 experiment_number = b2luigi.IntParameter()
266 random_seed = b2luigi.Parameter()
268 n_events = b2luigi.IntParameter()
270 bkgfiles_dir = b2luigi.Parameter(
281 Create output file name depending on number of events and production
282 mode that
is specified
in the random_seed string.
284 :param n_events: Number of events to simulate.
285 :param random_seed: Random seed to use
for the simulation to create independent samples.
289 if random_seed
is None:
291 return "generated_mc_N" + str(n_events) +
"_" + random_seed +
".root"
295 Generate list of output files that the task should produce.
296 The task is considered finished
if and only
if the outputs all exist.
302 This task requires several GenerateSimTask to be finished so that he required number of events is created.
304 n_events_per_task = MainTask.n_events_per_task
305 quotient, remainder = divmod(self.n_events, n_events_per_task)
306 for i
in range(quotient):
309 num_processes=MainTask.num_processes,
310 random_seed=self.
random_seed +
'_' + str(i).zfill(3),
311 n_events=n_events_per_task,
317 num_processes=MainTask.num_processes,
318 random_seed=self.
random_seed +
'_' + str(quotient).zfill(3),
323 @b2luigi.on_temporary_files
326 When all GenerateSimTasks finished, merge the output.
328 create_output_dirs(self)
330 file_list = [item for sublist
in self.get_input_file_names().values()
for item
in sublist]
331 print(
"Merge the following files:")
333 cmd = [
"b2file-merge",
"-f"]
334 args = cmd + [self.get_output_file_name(self.
output_file_name())] + file_list
335 subprocess.check_call(args)
336 print(
"Finished merging. Now remove the input files to save space.")
337 for input_file
in file_list:
339 os.remove(input_file)
340 except FileNotFoundError:
346 Record the data for the three state filters
for the CDCToSVDSpacePointCKF.
348 This task requires that the events used
for training have been simulated before, which
is done using the
349 ``SplitMergeSimTask``.
352 experiment_number = b2luigi.IntParameter()
355 random_seed = b2luigi.Parameter()
357 n_events = b2luigi.IntParameter()
360 layer = b2luigi.IntParameter()
364 Generate list of output files that the task should produce.
365 The task is considered finished
if and only
if the outputs all exist.
367 for record_fname
in [
"records1.root",
"records2.root",
"records3.root"]:
368 yield self.add_to_output(record_fname)
372 This task only requires that the input files have been created.
383 Create a path for the recording. To record the data
for the SVD state filters, CDC tracks are required,
and these must
384 be truth matched before. The data have to recorded
for each layer of the SVD, i.e. layers 3 to 6, but also an artificial
387 :param layer: The layer
for which the data are recorded.
388 :param records1_fname: Name of the records1 file.
389 :param records2_fname: Name of the records2 file.
390 :param records3_fname: Name of the records3 file.
392 path = basf2.create_path()
395 file_list = [fname
for sublist
in self.get_input_file_names().values()
396 for fname
in sublist
if "generated_mc_N" in fname
and "training" in fname
and fname.endswith(
".root")]
397 path.add_module(
"RootInput", inputFileNames=file_list)
399 path.add_module(
"Gearbox")
400 path.add_module(
"Geometry")
401 path.add_module(
"SetupGenfitExtrapolation")
403 add_hit_preparation_modules(path, components=[
"SVD"])
405 add_track_finding(path, reco_tracks=
"CDCRecoTracks", components=[
"CDC"], prune_temporary_tracks=
False)
407 path.add_module(
'TrackFinderMCTruthRecoTracks',
408 RecoTracksStoreArrayName=
"MCRecoTracks",
414 path.add_module(
"MCRecoTracksMatcher", UsePXDHits=
False, UseSVDHits=
False, UseCDCHits=
True,
415 mcRecoTracksStoreArrayName=
"MCRecoTracks",
416 prRecoTracksStoreArrayName=
"CDCRecoTracks")
417 path.add_module(
"DAFRecoFitter", recoTracksStoreArrayName=
"CDCRecoTracks")
419 path.add_module(
"CDCToSVDSpacePointCKF",
420 inputRecoTrackStoreArrayName=
"CDCRecoTracks",
421 outputRecoTrackStoreArrayName=
"VXDRecoTracks",
422 outputRelationRecoTrackStoreArrayName=
"CDCRecoTracks",
424 relationCheckForDirection=
"backward",
426 writeOutDirection=
"backward",
428 firstHighFilter=
"truth",
429 firstEqualFilter=
"recording",
430 firstEqualFilterParameters={
"treeName":
"records1",
"rootFileName":
431 records1_fname,
"returnWeight": 1.0},
432 firstLowFilter=
"none",
433 firstHighUseNStates=0,
434 firstToggleOnLayer=layer,
436 advanceHighFilter=
"advance",
438 secondHighFilter=
"truth",
439 secondEqualFilter=
"recording",
440 secondEqualFilterParameters={
"treeName":
"records2",
"rootFileName":
441 records2_fname,
"returnWeight": 1.0},
442 secondLowFilter=
"none",
443 secondHighUseNStates=0,
444 secondToggleOnLayer=layer,
446 updateHighFilter=
"fit",
448 thirdHighFilter=
"truth",
449 thirdEqualFilter=
"recording",
450 thirdEqualFilterParameters={
"treeName":
"records3",
"rootFileName": records3_fname},
451 thirdLowFilter=
"none",
452 thirdHighUseNStates=0,
453 thirdToggleOnLayer=layer,
458 enableOverlapResolving=
False)
462 def create_path(self):
464 Create basf2 path to process with event generation
and simulation.
468 records1_fname=self.get_output_file_name(
"records1.root"),
469 records2_fname=self.get_output_file_name(
"records2.root"),
470 records3_fname=self.get_output_file_name(
"records3.root"),
476 A teacher task runs the basf2 mva teacher on the training data provided by a
477 data collection task.
479 In this task the three state filters are trained, each with the corresponding recordings
from the different layers.
480 It will be executed
for each FastBDT option defined
in the MainTask.
483 experiment_number = b2luigi.IntParameter()
486 random_seed = b2luigi.Parameter()
488 n_events = b2luigi.IntParameter()
490 fast_bdt_option_state_filter = b2luigi.ListParameter(
492 hashed=True, default=[50, 8, 3, 0.1]
496 filter_number = b2luigi.IntParameter()
498 training_target = b2luigi.Parameter(
505 exclude_variables = b2luigi.ListParameter(
508 hashed=
True, default=[
516 "seed_lowest_svd_layer",
517 "seed_lowest_cdc_layer",
518 "quality_index_triplet",
519 "quality_index_circle",
520 "quality_index_helix",
523 "mean_rest_cluster_charge",
524 "min_rest_cluster_charge",
525 "std_rest_cluster_charge",
526 "cluster_1_seed_charge",
527 "cluster_2_seed_charge",
528 "mean_rest_cluster_seed_charge",
529 "min_rest_cluster_seed_charge",
530 "std_rest_cluster_seed_charge",
533 "mean_rest_cluster_size",
534 "min_rest_cluster_size",
535 "std_rest_cluster_size",
538 "mean_rest_cluster_snr",
539 "min_rest_cluster_snr",
540 "std_rest_cluster_snr",
541 "cluster_1_charge_over_size",
542 "cluster_2_charge_over_size",
543 "mean_rest_cluster_charge_over_size",
544 "min_rest_cluster_charge_over_size",
545 "std_rest_cluster_charge_over_size",
552 Name of the xml weightfile that is created by the teacher task.
553 It
is subsequently used
as a local weightfile
in the following validation tasks.
555 :param fast_bdt_option: FastBDT option that
is used to train this MVA
556 :param filter_number: Filter number (first=1, second=2, third=3) to be trained
558 if fast_bdt_option
is None:
560 fast_bdt_string = create_fbdt_option_string(fast_bdt_option)
561 weightfile_name = f
"trk_CDCToSVDSpacePointStateFilter_{filter_number}" + fast_bdt_string
562 return weightfile_name +
".xml"
566 This task requires that the recordings for the state filters.
568 for layer
in [3, 4, 5, 6, 7]:
573 random_seed=
"training",
579 Generate list of output files that the task should produce.
580 The task is considered finished
if and only
if the outputs all exist.
586 Use basf2_mva teacher to create MVA weightfile from collected training
589 This
is the main process that
is dispatched by the ``run`` method that
590 is inherited
from ``Basf2Task``.
592 records_files = self.get_input_file_names(f"records{self.filter_number}.root")
593 tree_name = f
"records{self.filter_number}"
594 print(f
"Processed records files: {records_files=},\nfeature tree name: {tree_name=}")
596 my_basf2_mva_teacher(
597 records_files=records_files,
608 Task to record data for the final result filter. This requires trained state filters.
609 The cuts on the state filter classifiers are set to rather low values to ensure that all signal
is contained
in the
610 recorded file. Also, the values
for XXXXXHighUseNStates are chosen conservatively, i.e. rather on the high side.
614 experiment_number = b2luigi.IntParameter()
617 random_seed = b2luigi.Parameter()
619 n_events = b2luigi.IntParameter()
621 fast_bdt_option_state_filter = b2luigi.ListParameter(
623 hashed=True, default=[50, 8, 3, 0.1]
627 result_filter_records_name = b2luigi.Parameter()
631 Generate list of output files that the task should produce.
632 The task is considered finished
if and only
if the outputs all exist.
638 This task requires that the training SplitMergeSimTask is finished,
as well
as that the state filters are trained
639 using the CKFStateFilterTeacherTask..
647 filter_numbers = [1, 2, 3]
648 for filter_number
in filter_numbers:
650 CKFStateFilterTeacherTask,
654 filter_number=filter_number,
660 Create a path for the recording of the result filter. This file
is then used to train the result filter.
662 :param result_filter_records_name: Name of the recording file.
665 path = basf2.create_path()
668 file_list = [fname
for sublist
in self.get_input_file_names().values()
669 for fname
in sublist
if "generated_mc_N" in fname
and "training" in fname
and fname.endswith(
".root")]
670 path.add_module(
"RootInput", inputFileNames=file_list)
672 path.add_module(
"Gearbox")
673 path.add_module(
"Geometry")
674 path.add_module(
"SetupGenfitExtrapolation")
676 add_hit_preparation_modules(path, components=[
"SVD"])
678 add_track_finding(path, reco_tracks=
"CDCRecoTracks", components=[
"CDC"], prune_temporary_tracks=
False)
680 path.add_module(
'TrackFinderMCTruthRecoTracks',
681 RecoTracksStoreArrayName=
"MCRecoTracks",
687 path.add_module(
"MCRecoTracksMatcher", UsePXDHits=
False, UseSVDHits=
False, UseCDCHits=
True,
688 mcRecoTracksStoreArrayName=
"MCRecoTracks",
689 prRecoTracksStoreArrayName=
"CDCRecoTracks")
690 path.add_module(
"DAFRecoFitter", recoTracksStoreArrayName=
"CDCRecoTracks")
693 path.add_module(
"CDCToSVDSpacePointCKF",
694 inputRecoTrackStoreArrayName=
"CDCRecoTracks",
695 outputRecoTrackStoreArrayName=
"VXDRecoTracks",
696 outputRelationRecoTrackStoreArrayName=
"CDCRecoTracks",
698 relationCheckForDirection=
"backward",
700 writeOutDirection=
"backward",
702 firstHighFilter=
"mva_with_direction_check",
703 firstHighFilterParameters={
704 "identifier": self.get_input_file_names(f
"trk_CDCToSVDSpacePointStateFilter_1{fast_bdt_string}.xml")[0],
706 "direction":
"backward"},
707 firstHighUseNStates=10,
709 advanceHighFilter=
"advance",
710 advanceHighFilterParameters={
"direction":
"backward"},
712 secondHighFilter=
"mva",
713 secondHighFilterParameters={
714 "identifier": self.get_input_file_names(f
"trk_CDCToSVDSpacePointStateFilter_2{fast_bdt_string}.xml")[0],
716 secondHighUseNStates=10,
718 updateHighFilter=
"fit",
720 thirdHighFilter=
"mva",
721 thirdHighFilterParameters={
722 "identifier": self.get_input_file_names(f
"trk_CDCToSVDSpacePointStateFilter_3{fast_bdt_string}.xml")[0],
724 thirdHighUseNStates=10,
727 filterParameters={
"rootFileName": result_filter_records_name},
730 enableOverlapResolving=
True)
734 def create_path(self):
736 Create basf2 path to process with event generation
and simulation.
745 A teacher task runs the basf2 mva teacher on the training data provided by a
746 data collection task.
748 Since teacher tasks are needed for all quality estimators covered by this
749 steering file
and the only thing that changes
is the required data
750 collection task
and some training parameters, I decided to use inheritance
751 and have the basic functionality
in this base
class/interface
and have the
752 specific teacher tasks inherit
from it.
755 experiment_number = b2luigi.IntParameter()
758 random_seed = b2luigi.Parameter()
760 n_events = b2luigi.IntParameter()
762 fast_bdt_option_state_filter = b2luigi.ListParameter(
764 hashed=True, default=[50, 8, 3, 0.1]
768 fast_bdt_option_result_filter = b2luigi.ListParameter(
770 hashed=
True, default=[200, 8, 3, 0.1]
774 result_filter_records_name = b2luigi.Parameter()
776 training_target = b2luigi.Parameter(
783 exclude_variables = b2luigi.ListParameter(
785 hashed=
True, default=[]
791 Name of the xml weightfile that is created by the teacher task.
792 It
is subsequently used
as a local weightfile
in the following validation tasks.
794 :param fast_bdt_option: FastBDT option that
is used to train this MVA
796 if fast_bdt_option
is None:
798 fast_bdt_string = create_fbdt_option_string(fast_bdt_option)
799 weightfile_name =
"trk_CDCToSVDSpacePointResultFilter" + fast_bdt_string
800 return weightfile_name +
".xml"
804 Generate list of luigi Tasks that this Task depends on.
816 Generate list of output files that the task should produce.
817 The task is considered finished
if and only
if the outputs all exist.
823 Use basf2_mva teacher to create MVA weightfile from collected training
826 This
is the main process that
is dispatched by the ``run`` method that
827 is inherited
from ``Basf2Task``.
830 tree_name = "records"
831 print(f
"Processed records files for result filter training: {records_files=},\nfeature tree name: {tree_name=}")
833 my_basf2_mva_teacher(
834 records_files=records_files,
845 Validate the performance of the trained filters by trying various combinations of FastBDT options, as well
as cut values
846 for the states, the number of best candidates kept after each filter,
and similar
for the result filter.
849 experiment_number = b2luigi.IntParameter()
851 n_events_training = b2luigi.IntParameter()
853 fast_bdt_option_state_filter = b2luigi.ListParameter(
855 hashed=
True, default=[50, 8, 3, 0.1]
859 fast_bdt_option_result_filter = b2luigi.ListParameter(
861 hashed=
True, default=[200, 8, 3, 0.1]
865 n_events_testing = b2luigi.IntParameter()
867 state_filter_cut = b2luigi.FloatParameter()
869 use_n_best_states = b2luigi.IntParameter()
871 result_filter_cut = b2luigi.FloatParameter()
873 use_n_best_results = b2luigi.IntParameter()
877 Generate list of output files that the task should produce.
878 The task is considered finished
if and only
if the outputs all exist.
882 yield self.add_to_output(
883 f
"cdc_to_svd_spacepoint_ckf_validation{fbdt_state_filter_string}_{fbdt_result_filter_string}.root")
887 This task requires trained result filters, trained state filters, and that an independent data set
for validation was
888 created using the SplitMergeSimTask
with the random seed optimisation.
892 result_filter_records_name=f
"filter_records{fbdt_state_filter_string}.root",
897 random_seed=
'training'
903 random_seed=
"optimisation",
905 filter_numbers = [1, 2, 3]
906 for filter_number
in filter_numbers:
908 CKFStateFilterTeacherTask,
910 random_seed=
"training",
912 filter_number=filter_number,
918 Create a path to validate the trained filters.
920 path = basf2.create_path()
923 file_list = [fname
for sublist
in self.get_input_file_names().values()
924 for fname
in sublist
if "generated_mc_N" in fname
and "optimisation" in fname
and fname.endswith(
".root")]
925 path.add_module(
"RootInput", inputFileNames=file_list)
927 path.add_module(
"Gearbox")
928 path.add_module(
"Geometry")
929 path.add_module(
"SetupGenfitExtrapolation")
931 add_hit_preparation_modules(path, components=[
"SVD"])
933 add_track_finding(path, reco_tracks=
"CDCRecoTracks", components=[
"CDC"], prune_temporary_tracks=
False)
937 path.add_module(
"CDCToSVDSpacePointCKF",
939 inputRecoTrackStoreArrayName=
"CDCRecoTracks",
940 outputRecoTrackStoreArrayName=
"VXDRecoTracks",
941 outputRelationRecoTrackStoreArrayName=
"CDCRecoTracks",
943 relationCheckForDirection=
"backward",
945 writeOutDirection=
"backward",
947 firstHighFilter=
"mva_with_direction_check",
948 firstHighFilterParameters={
949 "identifier": self.get_input_file_names(
950 f
"trk_CDCToSVDSpacePointStateFilter_1{fbdt_state_filter_string}.xml")[0],
952 "direction":
"backward"},
955 advanceHighFilter=
"advance",
956 advanceHighFilterParameters={
"direction":
"backward"},
958 secondHighFilter=
"mva",
959 secondHighFilterParameters={
960 "identifier": self.get_input_file_names(
961 f
"trk_CDCToSVDSpacePointStateFilter_2{fbdt_state_filter_string}.xml")[0],
965 updateHighFilter=
"fit",
967 thirdHighFilter=
"mva",
968 thirdHighFilterParameters={
969 "identifier": self.get_input_file_names(
970 f
"trk_CDCToSVDSpacePointStateFilter_3{fbdt_state_filter_string}.xml")[0],
976 "identifier": self.get_input_file_names(
977 f
"trk_CDCToSVDSpacePointResultFilter{fbdt_result_filter_string}.xml")[0],
982 enableOverlapResolving=
True)
984 path.add_module(
'RelatedTracksCombiner',
985 VXDRecoTracksStoreArrayName=
"VXDRecoTracks",
986 CDCRecoTracksStoreArrayName=
"CDCRecoTracks",
987 recoTracksStoreArrayName=
"RecoTracks")
989 path.add_module(
'TrackFinderMCTruthRecoTracks',
990 RecoTracksStoreArrayName=
"MCRecoTracks",
996 path.add_module(
"MCRecoTracksMatcher", UsePXDHits=
False, UseSVDHits=
True, UseCDCHits=
True,
997 mcRecoTracksStoreArrayName=
"MCRecoTracks",
998 prRecoTracksStoreArrayName=
"RecoTracks")
1002 output_file_name=self.get_output_file_name(
1003 f
"cdc_to_svd_spacepoint_ckf_validation{fbdt_state_filter_string}_{fbdt_result_filter_string}.root"),
1004 reco_tracks_name=
"RecoTracks",
1005 mc_reco_tracks_name=
"MCRecoTracks",
1012 def create_path(self):
1014 Create basf2 path to process with event generation
and simulation.
1019class MainTask(b2luigi.WrapperTask):
1021 Wrapper task that needs to finish for b2luigi to finish running this steering file.
1023 It
is done
if the outputs of all required subtasks exist. It
is thus at the
1024 top of the luigi task graph. Edit the ``requires`` method to steer which
1025 tasks
and with which parameters you want to run.
1028 n_events_training = b2luigi.get_setting(
1030 "n_events_training", default=1000
1034 n_events_testing = b2luigi.get_setting(
1036 "n_events_testing", default=500
1040 n_events_per_task = b2luigi.get_setting(
1042 "n_events_per_task", default=100
1046 num_processes = b2luigi.get_setting(
1048 "basf2_processes_per_worker", default=0
1053 bkgfiles_by_exp = b2luigi.get_setting(
"bkgfiles_by_exp")
1055 bkgfiles_by_exp = {int(key): val
for (key, val)
in bkgfiles_by_exp.items()}
1059 Generate list of tasks that needs to be done for luigi to finish running
1063 fast_bdt_options = [
1069 experiment_numbers = b2luigi.get_setting("experiment_numbers")
1072 for experiment_number, fast_bdt_option_state_filter, fast_bdt_option_result_filter
in itertools.product(
1073 experiment_numbers, fast_bdt_options, fast_bdt_options
1076 state_filter_cuts = [0.01, 0.02, 0.03, 0.05, 0.1, 0.2]
1077 n_best_states_list = [3, 5, 10]
1078 result_filter_cuts = [0.05, 0.1, 0.2]
1079 n_best_results_list = [3, 5, 10]
1080 for state_filter_cut, n_best_states, result_filter_cut, n_best_results
in \
1081 itertools.product(state_filter_cuts, n_best_states_list, result_filter_cuts, n_best_results_list):
1083 ValidationAndOptimisationTask,
1084 experiment_number=experiment_number,
1087 state_filter_cut=state_filter_cut,
1088 use_n_best_states=n_best_states,
1089 result_filter_cut=result_filter_cut,
1090 use_n_best_results=n_best_results,
1091 fast_bdt_option_state_filter=fast_bdt_option_state_filter,
1092 fast_bdt_option_result_filter=fast_bdt_option_result_filter,
1096if __name__ ==
"__main__":
1097 b2luigi.set_setting(
"env_script",
"./setup_basf2.sh")
1098 b2luigi.set_setting(
"batch_system",
"htcondor")
1099 workers = b2luigi.get_setting(
"workers", default=1)
1100 b2luigi.process(
MainTask(), workers=workers, batch=
True)
def get_background_files(folder=None, output_file_info=True)
b2luigi random_seed
Random basf2 seed.
b2luigi training_target
Feature/variable to use as truth label in the quality estimator MVA classifier.
b2luigi fast_bdt_option_result_filter
Hyperparameter option of the FastBDT algorithm.
b2luigi n_events
Number of events to generate for the training data set.
b2luigi fast_bdt_option_state_filter
Hyperparameter option of the FastBDT algorithm.
b2luigi experiment_number
Experiment number of the conditions database, e.g.
b2luigi exclude_variables
List of collected variables to not use in the training of the QE MVA classifier.
def get_weightfile_xml_identifier(self, fast_bdt_option=None)
b2luigi result_filter_records_name
Name of the input file name.
def get_weightfile_xml_identifier(self, fast_bdt_option=None, filter_number=1)
b2luigi training_target
Feature/variable to use as truth label in the quality estimator MVA classifier.
b2luigi filter_number
Number of the filter for which the records files are to be processed.
b2luigi n_events
Number of events to generate for the training data set.
b2luigi fast_bdt_option_state_filter
Hyperparameter option of the FastBDT algorithm.
b2luigi experiment_number
Experiment number of the conditions database, e.g.
b2luigi exclude_variables
List of collected variables to not use in the training of the QE MVA classifier.
b2luigi random_seed
Random basf2 seed.
def output_file_name(self, n_events=None, random_seed=None)
Name of the ROOT output file with generated and simulated events.
b2luigi bkgfiles_dir
Directory with overlay background root files.
b2luigi n_events
Number of events to generate.
b2luigi experiment_number
Experiment number of the conditions database, e.g.
b2luigi n_events_training
Number of events to generate for the training data set.
b2luigi n_events_testing
Number of events to generate for the test data set.
def create_result_recording_path(self, result_filter_records_name)
b2luigi random_seed
Random basf2 seed.
b2luigi n_events
Number of events to generate for the training data set.
b2luigi fast_bdt_option_state_filter
Hyperparameter option of the FastBDT algorithm.
b2luigi experiment_number
Experiment number of the conditions database, e.g.
b2luigi result_filter_records_name
Name of the records file for training the final result filter.
b2luigi random_seed
Random basf2 seed.
def output_file_name(self, n_events=None, random_seed=None)
Name of the ROOT output file with generated and simulated events.
b2luigi bkgfiles_dir
Directory with overlay background root files.
b2luigi n_events
Number of events to generate.
b2luigi experiment_number
Experiment number of the conditions database, e.g.
b2luigi random_seed
Random basf2 seed.
def create_state_recording_path(self, layer, records1_fname, records2_fname, records3_fname)
b2luigi n_events
Number of events to generate for training.
b2luigi experiment_number
Experiment number of the conditions database, e.g.
b2luigi layer
Layer on which to toggle for recording the information for training.
b2luigi n_events_training
Number of events to generate for the training data set.
b2luigi n_events_testing
Number of events to generate for the testing, validation, and optimisation data set.
b2luigi use_n_best_states
How many states should be kept at maximum in the combinatorial part of the CKF tree search.
b2luigi use_n_best_results
How many results should be kept at maximum to search for overlaps.
b2luigi state_filter_cut
Value of the cut on the MVA classifier output for accepting a state during CKF tracking.
b2luigi fast_bdt_option_result_filter
FastBDT option to use to train the Result Filter.
def create_optimisation_and_validation_path(self)
b2luigi result_filter_cut
Value of the cut on the MVA classifier output for a result candidate.
b2luigi fast_bdt_option_state_filter
FastBDT option to use to train the StateFilters.
b2luigi experiment_number
Experiment number of the conditions database, e.g.
def add_simulation(path, components=None, bkgfiles=None, bkgOverlay=True, forceSetPXDDataReduction=False, usePXDDataReduction=True, cleanupPXDDataReduction=True, generate_2nd_cdc_hits=False, simulateT0jitter=True, isCosmics=False, FilterEvents=False, usePXDGatedMode=False, skipExperimentCheckForBG=False, save_slow_pions_in_mc=False)