Belle II Software  release-05-02-19
MVATeacherAndAnalyser Class Reference

Public Member Functions

def __init__ (self, run_class, use_jupyter=True)
 
def train (self)
 
def evaluate_tracking (self)
 
def evaluate_classification (self)
 

Public Attributes

 run_class
 cached copy of the run class
 
 use_jupyter
 cached flag to use jupyter notebook
 
 recording_file_name
 cached name of the output file
 
 training_file_name
 cached path without extension of the output file More...
 
 test_file_name
 cached path with extension of the testing-output file
 
 identifier_name
 cached identifier
 
 evaluation_file_name
 cached name of the output PDF file
 
 expert_file_name
 cached path with extension of the testing-export file
 
 weight_data_location
 cached path of the weight input data
 

Private Member Functions

def _call_training_routine (self)
 
def _write_train_and_test_files (self)
 
def _create_records_file (self)
 
def _call_expert_routine (self)
 
def _call_evaluation_routine (self)
 

Detailed Description

Class for training and analysing a tracking module, which has a MVA filter in it.

Works best, if you are on a jupyter ntoebook.

You need to supply a run_class, which includes all needed settings, on how to
train and execute the module. This class will be mixed in with the normal trackfindingcdc
run classes, so you can add the setting (e.g. tracking_coverage etc.) as normal.

One examples is:

class TestClass:
    # This module will be trained
    recording_module = "FilterBasedVXDCDCTrackMerger"
    # This is the name of the parameter of this module, which will be set to "mva" etc.
    recording_parameter = "filter"

    # These mva cuts will be tested during evaluation.
    evaluation_cuts = [0.1, 0.2, ...]

    tracking_coverage = {
        'UsePXDHits': True,
        'UseSVDHits': True,
        'UseCDCHits': True,
    }

    # Some options, which will control the run classes
    fit_tracks = False
    generator_module = "EvtGenInput"

    # This will be added to the "normal" path, to record the training data (you do not have to set the module to
    # recording, as this is done automatically).
    def add_recording_modules(self, path):
        mctrackfinder = path.add_module('TrackFinderMCTruthRecoTracks',
                                RecoTracksStoreArrayName='MCRecoTracks',
                                WhichParticles=[])

        path.add_module('MCRecoTracksMatcher', mcRecoTracksStoreArrayName="MCRecoTracks",
                        prRecoTracksStoreArrayName="CDCRecoTracks", UseCDCHits=True, UsePXDHits=False, UseSVDHits=False)
        path.add_module('MCRecoTracksMatcher', mcRecoTracksStoreArrayName="MCRecoTracks",
                        prRecoTracksStoreArrayName="VXDRecoTracks", UseCDCHits=False, UsePXDHits=True, UseSVDHits=True)

        # Merge CDC and CXD tracks
        path.add_module('FilterBasedVXDCDCTrackMerger',
                        extrapolate=False,
                        CDCRecoTrackStoreArrayName="CDCRecoTracks",
                        VXDRecoTrackStoreArrayName="VXDRecoTracks",
                        MergedRecoTrackStoreArrayName="RecoTracks")

        return path

    # This will be added to the "normal" path, to evaluate the mva cuts. In most cases, this is the same as the
    # add_recording_modules (as the module parameters will be set automatically), but maybe you need
    # more here...
    def add_validation_modules(self, path):
        mctrackfinder = path.add_module('TrackFinderMCTruthRecoTracks',
                                RecoTracksStoreArrayName='MCRecoTracks',
                                WhichParticles=[])

        # Merge CDC and CXD tracks
        path.add_module('FilterBasedVXDCDCTrackMerger',
                        extrapolate=True,
                        CDCRecoTrackStoreArrayName="CDCRecoTracks",
                        VXDRecoTrackStoreArrayName="VXDRecoTracks",
                        MergedRecoTrackStoreArrayName="PrefitRecoTracks")

        path.add_module("SetupGenfitExtrapolation")

        path.add_module("DAFRecoFitter", recoTracksStoreArrayName="PrefitRecoTracks")

        path.add_module("TrackCreator", recoTrackColName="PrefitRecoTracks")

        path.add_module("FittedTracksStorer", inputRecoTracksStoreArrayName="PrefitRecoTracks",
                        outputRecoTracksStoreArrayName="RecoTracks")

        # We need to include the matching ourselves, as we have already a matching algorithm in place
        path.add_module('MCRecoTracksMatcher', mcRecoTracksStoreArrayName="MCRecoTracks",
                        prRecoTracksStoreArrayName="RecoTracks", UseCDCHits=True, UsePXDHits=True, UseSVDHits=True)

        return path

Definition at line 41 of file analyse.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  run_class,
  use_jupyter = True 
)
Constructor

Definition at line 124 of file analyse.py.

124  def __init__(self, run_class, use_jupyter=True):
125  """Constructor"""
126 
127 
128  self.run_class = run_class
129 
130  self.use_jupyter = use_jupyter
131 
132 
133  self.recording_file_name = self.run_class.recording_module + ".root"
134 
135 
136  self.file_name_path, ext = os.path.splitext(self.recording_file_name)
137 
138 
139  self.training_file_name = self.file_name_path + "Training" + ext
140 
141  self.test_file_name = self.file_name_path + "Testing" + ext
142 
143 
144  self.identifier_name = "FastBDT.weights.xml"
145 
146  self.evaluation_file_name = self.identifier_name + ".pdf"
147 
148 
149  self.expert_file_name = self.file_name_path + "TestingExport" + ext
150 
151 
152  self.weight_data_location = Belle2.FileSystem.findFile(os.path.join("tracking/data",
153  self.run_class.weight_data_location))
154 

Member Function Documentation

◆ _call_evaluation_routine()

def _call_evaluation_routine (   self)
private
Call the mva evaluation routine

Definition at line 284 of file analyse.py.

◆ _call_expert_routine()

def _call_expert_routine (   self)
private
Call the mva expert

Definition at line 273 of file analyse.py.

◆ _call_training_routine()

def _call_training_routine (   self)
private
Call the mva training routine in the train file

Definition at line 223 of file analyse.py.

◆ _create_records_file()

def _create_records_file (   self)
private
Create a path using the settings of the run_class and process it.
This will create a ROOT file with the recorded data.

Definition at line 241 of file analyse.py.

◆ _write_train_and_test_files()

def _write_train_and_test_files (   self)
private
Split the recorded file into two halves: training and test file and write it back

Definition at line 230 of file analyse.py.

◆ evaluate_classification()

def evaluate_classification (   self)
Evaluate the classification power on the test data set and produce a PDF.

Definition at line 207 of file analyse.py.

◆ evaluate_tracking()

def evaluate_tracking (   self)
Use the trained weight file and call the path again using different mva cuts. Validation using the
normal tracking validation modules.

Definition at line 165 of file analyse.py.

◆ train()

def train (   self)
Record a training file, split it in two parts and call the training method of the mva package

Definition at line 155 of file analyse.py.

Member Data Documentation

◆ training_file_name

training_file_name

cached path without extension of the output file

cached path with extension of the training-output file

Definition at line 139 of file analyse.py.


The documentation for this class was generated from the following file:
Belle2::FileSystem::findFile
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
Definition: FileSystem.cc:147