10 combined_to_pxd_ckf_mva_training
11 -----------------------------------------
13 Purpose of this script
14 ~~~~~~~~~~~~~~~~~~~~~~
16 This python script is used for the training and validation of the classifiers of
17 the three MVA-based state filters and one result filter of the ToPXDCKF.
18 This CKF extraplates tracks found in CDC and SVD into the PXD and adds PXD hits
19 using a combinatorial tree search and a Kalman filter based track fit in each step.
21 To avoid mistakes, b2luigi is used to create a task chain for a combined training and
22 validation of all classifiers.
24 The 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
27 generated and a number of events per task to reduce runtime. It then divides the total
28 number of events by the number of events per task and creates as ``GenerateSimTask`` as
29 needed, each with a specific random seed, so that in the end the total number of
30 training and testing events are simulated. The individual files are then combined
31 by 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
35 default, with a given set of options.
36 * The ``ResultRecordingTask`` writes out the data used for the training of the result
37 filter MVA. This task requires that the state filters have been trained before.
38 * The ``CKFResultFilterTeacherTask`` trains the MVA, FastBDT per default, with a
39 given set of FastBDT options. This requires that the result filter records have
40 been created with the ``ResultRecordingTask``.
41 * The ``ValidationAndOptimisationTask`` uses the trained weight files and cut values
42 provided to run the tracking chain with the weight file under test, and also
43 runs 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
46 and cut values on the MVA classifier output.
48 Due to the dependencies, the calls of the task are reversed. The MainTask
49 calls the ``ValidationAndOptimisationTask`` with different FastBDT options and cut
50 values, and the ``ValidationAndOptimisationTask`` itself calls the required teacher,
51 training, and simulation tasks.
53 Each combination of FastBDT options and state filter cut values and candidate selection
54 is used to train the result filter, which includes that the ``ResultRecordingTask``
55 is executed multiple times with different combinations of FastBDT options and cut value
56 and candidate selection.
58 b2luigi: Understanding the steering file
59 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
61 All trainings and validations are done in the correct order in this steering
62 file. 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.
66 Each task that has to be done is represented by a special class, which defines
67 which defines parameters, output files and which other tasks with which
68 parameters it depends on. For example a teacher task, which runs
69 ``basf2_mva_teacher.py`` to train the classifier, depends on a data collection
70 task which runs a reconstruction and writes out track-wise variables into a root
71 file for training. An evaluation/validation task for testing the classifier
72 requires both the teacher task, as it needs the weightfile to be present, and
73 also a data collection task, because it needs a dataset for testing classifier.
75 The final task that defines which tasks need to be done for the steering file to
76 finish is the ``MainTask``. When you only want to run parts of the
77 training/validation pipeline, you can comment out requirements in the Master
78 task or replace them by lower-level tasks during debugging.
83 This steering file relies on b2luigi_ for task scheduling. It can be installed
86 python3 -m pip install [--user] b2luigi
88 Use the ``--user`` option if you have not rights to install python packages into
89 your externals (e.g. because you are using cvmfs) and install them in
90 ``$HOME/.local`` instead.
95 Instead 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
97 fit to your requirements.
102 You can test the b2luigi without running it via::
104 python3 combined_to_pxd_ckf_mva_training.py --dry-run
105 python3 combined_to_pxd_ckf_mva_training.py --show-output
107 This will show the outputs and show potential errors in the definitions of the
108 luigi task dependencies. To run the the steering file in normal (local) mode,
111 python3 combined_to_pxd_ckf_mva_training.py
113 One can use the interactive luigi web interface via the central scheduler
114 which visualizes the task graph while it is running. Therefore, the scheduler
115 daemon ``luigid`` has to run in the background, which is located in
116 ``~/.local/bin/luigid`` in case b2luigi had been installed with ``--user``. For
121 Then, execute your steering (e.g. in another terminal) with::
123 python3 combined_to_pxd_ckf_mva_training.py --scheduler-port 8886
125 To view the web interface, open your webbrowser enter into the url bar::
129 If you don't run the steering file on the same machine on which you run your web
130 browser, you have two options:
132 1. Run both the steering file and ``luigid`` remotely and use
133 ssh-port-forwarding to your local host. Therefore, run on your local
136 ssh -N -f -L 8886:localhost:8886 <remote_user>@<remote_host>
138 2. Run the ``luigid`` scheduler locally and use the ``--scheduler-host <your
139 local host>`` argument when calling the steering file
141 Accessing the results / output files
142 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
144 All output files are stored in a directory structure in the ``result_path`` set in
145 ``settings.json``. The directory tree encodes the used b2luigi parameters. This
146 ensures reproducibility and makes parameter searches easy. Sometimes, it is hard to
147 find the relevant output files. You can view the whole directory structure by
148 running ``tree <result_path>``. Ise the unix ``find`` command to find the files
149 that interest you, e.g.::
151 find <result_path> -name "*.root" # find all ROOT files
158 from tracking
import add_track_finding
164 from ckf_training
import my_basf2_mva_teacher, create_fbdt_option_string
167 install_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
173 except ModuleNotFoundError:
174 print(install_helpstring_formatter.format(module=
"b2luigi"))
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.
227 Create basf2 path to process with event generation and simulation.
230 path = basf2.create_path()
234 path.add_module(
"EvtGenInput")
245 outputFileName=self.get_output_file_name(self.
output_file_nameoutput_file_name()),
254 Generate simulated Monte Carlo with background overlay.
256 Make sure to use different ``random_seed`` parameters for the training data
257 format the classifier trainings and for the test data for the respective
258 evaluation/validation tasks.
262 experiment_number = b2luigi.IntParameter()
265 random_seed = b2luigi.Parameter()
267 n_events = b2luigi.IntParameter()
269 bkgfiles_dir = b2luigi.Parameter(
280 Create output file name depending on number of events and production
281 mode that is specified in the random_seed string.
283 :param n_events: Number of events to simulate.
284 :param random_seed: Random seed to use for the simulation to create independent samples.
288 if random_seed
is None:
290 return "generated_mc_N" + str(n_events) +
"_" + random_seed +
".root"
294 Generate list of output files that the task should produce.
295 The task is considered finished if and only if the outputs all exist.
301 This task requires several GenerateSimTask to be finished so that he required number of events is created.
303 n_events_per_task = MainTask.n_events_per_task
304 quotient, remainder = divmod(self.
n_eventsn_events, n_events_per_task)
305 for i
in range(quotient):
308 num_processes=MainTask.num_processes,
309 random_seed=self.
random_seedrandom_seed +
'_' + str(i).zfill(3),
310 n_events=n_events_per_task,
316 num_processes=MainTask.num_processes,
317 random_seed=self.
random_seedrandom_seed +
'_' + str(quotient).zfill(3),
322 @b2luigi.on_temporary_files
325 When all GenerateSimTasks finished, merge the output.
327 create_output_dirs(self)
329 file_list = [item
for sublist
in self.get_input_file_names().values()
for item
in sublist]
330 print(
"Merge the following files:")
332 cmd = [
"b2file-merge",
"-f"]
333 args = cmd + [self.get_output_file_name(self.
output_file_nameoutput_file_name())] + file_list
334 subprocess.check_call(args)
335 print(
"Finished merging. Now remove the input files to save space.")
337 for tempfile
in file_list:
338 args = cmd2 + [tempfile]
339 subprocess.check_call(args)
344 Record the data for the three state filters for the ToPXDCKF.
346 This task requires that the events used for training have been simulated before, which is done using the
347 ``SplitMergeSimTask``.
350 experiment_number = b2luigi.IntParameter()
353 random_seed = b2luigi.Parameter()
355 n_events = b2luigi.IntParameter()
358 layer = b2luigi.IntParameter()
362 Generate list of output files that the task should produce.
363 The task is considered finished if and only if the outputs all exist.
365 for record_fname
in [
"records1.root",
"records2.root",
"records3.root"]:
366 yield self.add_to_output(record_fname)
370 This task only requires that the input files have been created.
381 Create a path for the recording. To record the data for the PXD state filters, CDC+SVD tracks are required, and these
382 must be truth matched before. The data have to recorded for each layer of the PXD, i.e. layers 1 and 2, but also an
385 :param layer: The layer for which the data are recorded.
386 :param records1_fname: Name of the records1 file.
387 :param records2_fname: Name of the records2 file.
388 :param records3_fname: Name of the records3 file.
390 path = basf2.create_path()
393 file_list = [fname
for sublist
in self.get_input_file_names().values()
394 for fname
in sublist
if "generated_mc_N" in fname
and "training" in fname
and fname.endswith(
".root")]
395 path.add_module(
"RootInput", inputFileNames=file_list)
397 path.add_module(
"Gearbox")
398 path.add_module(
"Geometry")
399 path.add_module(
"SetupGenfitExtrapolation")
401 add_hit_preparation_modules(path, components=[
"SVD",
"PXD"])
403 add_track_finding(path, reco_tracks=
"CDCSVDRecoTracks", components=[
"CDC",
"SVD"], prune_temporary_tracks=
False)
405 path.add_module(
'TrackFinderMCTruthRecoTracks',
406 RecoTracksStoreArrayName=
"MCRecoTracks",
412 path.add_module(
"MCRecoTracksMatcher", UsePXDHits=
False, UseSVDHits=
True, UseCDCHits=
True,
413 mcRecoTracksStoreArrayName=
"MCRecoTracks",
414 prRecoTracksStoreArrayName=
"CDCSVDRecoTracks")
415 path.add_module(
"DAFRecoFitter", recoTracksStoreArrayName=
"CDCSVDRecoTracks")
417 path.add_module(
"ToPXDCKF",
418 inputRecoTrackStoreArrayName=
"CDCSVDRecoTracks",
419 outputRecoTrackStoreArrayName=
"RecoTracks",
420 outputRelationRecoTrackStoreArrayName=
"CDCSVDRecoTracks",
421 hitFilter=
"distance",
422 seedFilter=
"distance",
426 relationCheckForDirection=
"backward",
428 writeOutDirection=
"backward",
430 firstHighFilter=
"truth",
431 firstEqualFilter=
"recording",
432 firstEqualFilterParameters={
"treeName":
"records1",
"rootFileName": records1_fname,
"returnWeight": 1.0},
433 firstLowFilter=
"none",
434 firstHighUseNStates=0,
435 firstToggleOnLayer=layer,
437 advanceHighFilter=
"advance",
439 secondHighFilter=
"truth",
440 secondEqualFilter=
"recording",
441 secondEqualFilterParameters={
"treeName":
"records2",
"rootFileName": 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)
464 Create basf2 path to process with event generation and simulation.
467 layer=self.
layerlayer,
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.
484 experiment_number = b2luigi.IntParameter()
487 random_seed = b2luigi.Parameter()
489 n_events = b2luigi.IntParameter()
491 fast_bdt_option_state_filter = b2luigi.ListParameter(
493 hashed=
True, default=[50, 8, 3, 0.1]
497 filter_number = b2luigi.IntParameter()
499 training_target = b2luigi.Parameter(
506 exclude_variables = b2luigi.ListParameter(
508 hashed=
True, default=[]
514 Name of the xml weightfile that is created by the teacher task.
515 It is subsequently used as a local weightfile in the following validation tasks.
517 :param fast_bdt_option: FastBDT option that is used to train this MVA.
518 :param filter_number: Filter number (first=1, second=2, third=3) to be trained.
520 if fast_bdt_option
is None:
522 fast_bdt_string = create_fbdt_option_string(fast_bdt_option)
523 weightfile_name = f
"trk_ToPXDStateFilter_{filter_number}" + fast_bdt_string
524 return weightfile_name +
".xml"
528 This task requires that the recordings for the state filters.
530 for layer
in [1, 2, 3]:
535 random_seed=
"training",
541 Generate list of output files that the task should produce.
542 The task is considered finished if and only if the outputs all exist.
548 Use basf2_mva teacher to create MVA weightfile from collected training
551 This is the main process that is dispatched by the ``run`` method that
552 is inherited from ``Basf2Task``.
554 records_files = self.get_input_file_names(f
"records{self.filter_number}.root")
555 tree_name = f
"records{self.filter_number}"
556 print(f
"Processed records files: {records_files=},\nfeature tree name: {tree_name=}")
558 my_basf2_mva_teacher(
559 records_files=records_files,
563 exclude_variables=self.exclude_variables,
570 Task to record data for the final result filter. This requires trained state filters.
571 The cuts on the state filter classifiers are set to rather low values to ensure that all signal is contained in the recorded
572 file. Also, the values for XXXXXHighUseNStates are chosen conservatively, i.e. rather on the high side.
576 experiment_number = b2luigi.IntParameter()
579 random_seed = b2luigi.Parameter()
581 n_events_training = b2luigi.IntParameter()
583 fast_bdt_option_state_filter = b2luigi.ListParameter(
585 hashed=
True, default=[200, 8, 3, 0.1]
589 result_filter_records_name = b2luigi.Parameter()
593 Generate list of output files that the task should produce.
594 The task is considered finished if and only if the outputs all exist.
600 This task requires that the training SplitMergeSimTask is finished, as well as that the state filters are trained using
601 the CKFStateFilterTeacherTask..
609 filter_numbers = [1, 2, 3]
610 for filter_number
in filter_numbers:
612 CKFStateFilterTeacherTask,
616 filter_number=filter_number,
622 Create a path for the recording of the result filter. This file is then used to train the result filter.
624 :param result_filter_records_name: Name of the recording file.
627 path = basf2.create_path()
630 file_list = [fname
for sublist
in self.get_input_file_names().values()
631 for fname
in sublist
if "generated_mc_N" in fname
and "training" in fname
and fname.endswith(
".root")]
632 path.add_module(
"RootInput", inputFileNames=file_list)
634 path.add_module(
"Gearbox")
635 path.add_module(
"Geometry")
636 path.add_module(
"SetupGenfitExtrapolation")
638 add_hit_preparation_modules(path, components=[
"SVD",
"PXD"])
640 add_track_finding(path, reco_tracks=
"CDCSVDRecoTracks", components=[
"CDC",
"SVD"], prune_temporary_tracks=
False)
642 path.add_module(
'TrackFinderMCTruthRecoTracks',
643 RecoTracksStoreArrayName=
"MCRecoTracks",
649 path.add_module(
"MCRecoTracksMatcher", UsePXDHits=
False, UseSVDHits=
True, UseCDCHits=
True,
650 mcRecoTracksStoreArrayName=
"MCRecoTracks",
651 prRecoTracksStoreArrayName=
"CDCSVDRecoTracks")
652 path.add_module(
"DAFRecoFitter", recoTracksStoreArrayName=
"CDCSVDRecoTracks")
655 path.add_module(
"ToPXDCKF",
656 inputRecoTrackStoreArrayName=
"CDCSVDRecoTracks",
657 outputRecoTrackStoreArrayName=
"RecoTracks",
658 outputRelationRecoTrackStoreArrayName=
"CDCSVDRecoTracks",
660 relationCheckForDirection=
"backward",
662 writeOutDirection=
"backward",
664 firstHighFilter=
"mva",
665 firstHighFilterParameters={
666 "identifier": self.get_input_file_names(f
"trk_ToPXDStateFilter_1{fast_bdt_string}.xml")[0],
668 firstHighUseNStates=10,
670 advanceHighFilter=
"advance",
672 secondHighFilter=
"mva",
673 secondHighFilterParameters={
674 "identifier": self.get_input_file_names(f
"trk_ToPXDStateFilter_2{fast_bdt_string}.xml")[0],
676 secondHighUseNStates=10,
678 updateHighFilter=
"fit",
680 thirdHighFilter=
"mva",
681 thirdHighFilterParameters={
682 "identifier": self.get_input_file_names(f
"trk_ToPXDStateFilter_3{fast_bdt_string}.xml")[0],
684 thirdHighUseNStates=10,
687 filterParameters={
"rootFileName": result_filter_records_name},
690 enableOverlapResolving=
True)
696 Create basf2 path to process with event generation and simulation.
698 return self.create_result_recording_path(
705 A teacher task runs the basf2 mva teacher on the training data for the result filter.
709 experiment_number = b2luigi.IntParameter()
712 random_seed = b2luigi.Parameter()
714 n_events = b2luigi.IntParameter()
716 fast_bdt_option_state_filter = b2luigi.ListParameter(
718 hashed=
True, default=[50, 8, 3, 0.1]
722 fast_bdt_option_result_filter = b2luigi.ListParameter(
724 hashed=
True, default=[200, 8, 3, 0.1]
728 result_filter_records_name = b2luigi.Parameter()
730 training_target = b2luigi.Parameter(
737 exclude_variables = b2luigi.ListParameter(
739 hashed=
True, default=[]
745 Name of the xml weightfile that is created by the teacher task.
746 It is subsequently used as a local weightfile in the following validation tasks.
748 :param fast_bdt_option: FastBDT option that is used to train this MVA
750 if fast_bdt_option
is None:
752 fast_bdt_string = create_fbdt_option_string(fast_bdt_option)
753 weightfile_name =
"trk_ToPXDResultFilter" + fast_bdt_string
754 return weightfile_name +
".xml"
758 Generate list of luigi Tasks that this Task depends on.
762 n_events_training=self.
n_eventsn_events,
770 Generate list of output files that the task should produce.
771 The task is considered finished if and only if the outputs all exist.
777 Use basf2_mva teacher to create MVA weightfile from collected training
780 This is the main process that is dispatched by the ``run`` method that
781 is inherited from ``Basf2Task``.
784 tree_name =
"records"
785 print(f
"Processed records files for result filter training: {records_files=},\nfeature tree name: {tree_name=}")
787 my_basf2_mva_teacher(
788 records_files=records_files,
790 weightfile_identifier=self.get_output_file_name(self.get_weightfile_xml_identifier()),
791 target_variable=self.training_target,
792 exclude_variables=self.exclude_variables,
799 Validate the performance of the trained filters by trying various combinations of FastBDT options, as well as cut values for
800 the states, the number of best candidates kept after each filter, and similar for the result filter.
803 experiment_number = b2luigi.IntParameter()
805 n_events_training = b2luigi.IntParameter()
807 fast_bdt_option_state_filter = b2luigi.ListParameter(
809 hashed=
True, default=[200, 8, 3, 0.1]
813 fast_bdt_option_result_filter = b2luigi.ListParameter(
815 hashed=
True, default=[200, 8, 3, 0.1]
819 n_events_testing = b2luigi.IntParameter()
821 state_filter_cut = b2luigi.FloatParameter()
823 use_n_best_states = b2luigi.IntParameter()
825 result_filter_cut = b2luigi.FloatParameter()
827 use_n_best_results = b2luigi.IntParameter()
831 Generate list of output files that the task should produce.
832 The task is considered finished if and only if the outputs all exist.
836 yield self.add_to_output(
837 f
"to_pxd_ckf_validation{fbdt_state_filter_string}_{fbdt_result_filter_string}.root")
841 This task requires trained result filters, trained state filters, and that an independent data set for validation was
842 created using the SplitMergeSimTask with the random seed optimisation.
846 result_filter_records_name=f
"filter_records{fbdt_state_filter_string}.root",
851 random_seed=
'training'
857 random_seed=
"optimisation",
859 filter_numbers = [1, 2, 3]
860 for filter_number
in filter_numbers:
862 CKFStateFilterTeacherTask,
865 random_seed=
"training",
866 filter_number=filter_number,
872 Create a path to validate the trained filters.
874 path = basf2.create_path()
877 file_list = [fname
for sublist
in self.get_input_file_names().values()
878 for fname
in sublist
if "generated_mc_N" in fname
and "optimisation" in fname
and fname.endswith(
".root")]
879 path.add_module(
"RootInput", inputFileNames=file_list)
881 path.add_module(
"Gearbox")
882 path.add_module(
"Geometry")
883 path.add_module(
"SetupGenfitExtrapolation")
885 add_hit_preparation_modules(path, components=[
"SVD",
"PXD"])
887 add_track_finding(path, reco_tracks=
"CDCSVDRecoTracks", components=[
"CDC",
"SVD"], prune_temporary_tracks=
False)
889 path.add_module(
"DAFRecoFitter", recoTracksStoreArrayName=
"CDCSVDRecoTracks")
893 path.add_module(
"ToPXDCKF",
894 inputRecoTrackStoreArrayName=
"CDCSVDRecoTracks",
895 outputRecoTrackStoreArrayName=
"PXDRecoTracks",
896 outputRelationRecoTrackStoreArrayName=
"CDCSVDRecoTracks",
898 relationCheckForDirection=
"backward",
900 writeOutDirection=
"backward",
902 firstHighFilter=
"mva_with_direction_check",
903 firstHighFilterParameters={
904 "identifier": self.get_input_file_names(
905 f
"trk_ToPXDStateFilter_1{fbdt_state_filter_string}.xml")[0],
907 "direction":
"backward"},
910 advanceHighFilter=
"advance",
911 advanceHighFilterParameters={
"direction":
"backward"},
913 secondHighFilter=
"mva",
914 secondHighFilterParameters={
915 "identifier": self.get_input_file_names(
916 f
"trk_ToPXDStateFilter_2{fbdt_state_filter_string}.xml")[0],
920 updateHighFilter=
"fit",
922 thirdHighFilter=
"mva",
923 thirdHighFilterParameters={
924 "identifier": self.get_input_file_names(
925 f
"trk_ToPXDStateFilter_3{fbdt_state_filter_string}.xml")[0],
931 "identifier": self.get_input_file_names(
932 f
"trk_ToPXDResultFilter{fbdt_result_filter_string}.xml")[0],
937 enableOverlapResolving=
True)
939 path.add_module(
'RelatedTracksCombiner',
940 VXDRecoTracksStoreArrayName=
"PXDRecoTracks",
941 CDCRecoTracksStoreArrayName=
"CDCSVDRecoTracks",
942 recoTracksStoreArrayName=
"RecoTracks")
944 path.add_module(
'TrackFinderMCTruthRecoTracks',
945 RecoTracksStoreArrayName=
"MCRecoTracks",
951 path.add_module(
"MCRecoTracksMatcher", UsePXDHits=
True, UseSVDHits=
True, UseCDCHits=
True,
952 mcRecoTracksStoreArrayName=
"MCRecoTracks",
953 prRecoTracksStoreArrayName=
"RecoTracks")
957 output_file_name=self.get_output_file_name(
958 f
"to_pxd_ckf_validation{fbdt_state_filter_string}_{fbdt_result_filter_string}.root"),
959 reco_tracks_name=
"RecoTracks",
960 mc_reco_tracks_name=
"MCRecoTracks",
967 def create_path(self):
969 Create basf2 path to process with event generation and simulation.
971 return self.create_optimisation_and_validation_path()
974 class MainTask(b2luigi.WrapperTask):
976 Wrapper task that needs to finish for b2luigi to finish running this steering file.
978 It is done if the outputs of all required subtasks exist. It is thus at the
979 top of the luigi task graph. Edit the ``requires`` method to steer which
980 tasks and with which parameters you want to run.
983 n_events_training = b2luigi.get_setting(
985 "n_events_training", default=1000
989 n_events_testing = b2luigi.get_setting(
991 "n_events_testing", default=500
995 n_events_per_task = b2luigi.get_setting(
997 "n_events_per_task", default=100
1001 num_processes = b2luigi.get_setting(
1003 "basf2_processes_per_worker", default=0
1008 bkgfiles_by_exp = b2luigi.get_setting(
"bkgfiles_by_exp")
1010 bkgfiles_by_exp = {int(key): val
for (key, val)
in bkgfiles_by_exp.items()}
1014 Generate list of tasks that needs to be done for luigi to finish running
1018 fast_bdt_options = [
1024 experiment_numbers = b2luigi.get_setting(
"experiment_numbers")
1027 for experiment_number, fast_bdt_option_state_filter, fast_bdt_option_result_filter
in itertools.product(
1028 experiment_numbers, fast_bdt_options, fast_bdt_options
1031 state_filter_cuts = [0.01, 0.02, 0.03, 0.05, 0.1, 0.2]
1032 n_best_states_list = [3, 5, 10]
1033 result_filter_cuts = [0.05, 0.1, 0.2]
1034 n_best_results_list = [2, 3, 5]
1035 for state_filter_cut, n_best_states, result_filter_cut, n_best_results
in \
1036 itertools.product(state_filter_cuts, n_best_states_list, result_filter_cuts, n_best_results_list):
1038 ValidationAndOptimisationTask,
1039 experiment_number=experiment_number,
1042 state_filter_cut=state_filter_cut,
1043 use_n_best_states=n_best_states,
1044 result_filter_cut=result_filter_cut,
1045 use_n_best_results=n_best_results,
1046 fast_bdt_option_state_filter=fast_bdt_option_state_filter,
1047 fast_bdt_option_result_filter=fast_bdt_option_result_filter,
1051 if __name__ ==
"__main__":
1052 b2luigi.set_setting(
"env_script",
"./setup_basf2.sh")
1053 b2luigi.set_setting(
"batch_system",
"htcondor")
1054 workers = b2luigi.get_setting(
"workers", default=1)
1055 b2luigi.process(
MainTask(), workers=workers, batch=
True)
def get_background_files(folder=None, output_file_info=True)
experiment_number
Experiment number of the conditions database, e.g.
result_filter_records_name
Name of the input file name.
n_events
Number of events to generate for the training data set.
fast_bdt_option_state_filter
Hyperparameter option of the FastBDT algorithm.
random_seed
Random basf2 seed.
def get_weightfile_xml_identifier(self, fast_bdt_option=None)
fast_bdt_option_result_filter
Hyperparameter option of the FastBDT algorithm.
def get_weightfile_xml_identifier(self, fast_bdt_option=None, filter_number=1)
experiment_number
Experiment number of the conditions database, e.g.
filter_number
Number of the filter for which the records files are to be processed.
n_events
Number of events to generate for the training data set.
fast_bdt_option_state_filter
Hyperparameter option of the FastBDT algorithm.
training_target
Feature/variable to use as truth label in the quality estimator MVA classifier.
experiment_number
Experiment number of the conditions database, e.g.
def output_file_name(self, n_events=None, random_seed=None)
Name of the ROOT output file with generated and simulated events.
n_events
Number of events to generate.
bkgfiles_dir
Directory with overlay background root files.
random_seed
Random basf2 seed.
n_events_training
Number of events to generate for the training data set.
n_events_testing
Number of events to generate for the test data set.
def create_result_recording_path(self, result_filter_records_name)
experiment_number
Experiment number of the conditions database, e.g.
result_filter_records_name
Name of the records file for training the final result filter.
n_events_training
Number of events to generate.
fast_bdt_option_state_filter
Hyperparameter option of the FastBDT algorithm.
random_seed
Random basf2 seed.
experiment_number
Experiment number of the conditions database, e.g.
def output_file_name(self, n_events=None, random_seed=None)
Name of the ROOT output file with generated and simulated events.
n_events
Number of events to generate.
bkgfiles_dir
Directory with overlay background root files.
random_seed
Random basf2 seed.
experiment_number
Experiment number of the conditions database, e.g.
n_events
Number of events to generate.
def create_state_recording_path(self, layer, records1_fname, records2_fname, records3_fname)
layer
Layer on which to toggle for recording the information for training.
random_seed
Random basf2 seed.
experiment_number
Experiment number of the conditions database, e.g.
use_n_best_results
How many results should be kept at maximum to search for overlaps.
state_filter_cut
Value of the cut on the MVA classifier output for accepting a state during CKF tracking.
def create_optimisation_and_validation_path(self)
result_filter_cut
Value of the cut on the MVA classifier output for a result candidate.
use_n_best_states
How many states should be kept at maximum in the combinatorial part of the CKF tree search.
n_events_training
Number of events to generate for the training data set.
fast_bdt_option_state_filter
FastBDT option to use to train the StateFilters.
n_events_testing
Number of events to generate for the testing, validation, and optimisation data set.
fast_bdt_option_result_filter
FastBDT option to use to train the Result Filter.
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)