Belle II Software  release-05-02-19
GenfitTrackCreatorModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Nils Braun *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <tracking/modules/fitter/GenfitTrackCreatorModule.h>
11 #include <tracking/dataobjects/RecoTrack.h>
12 #include <framework/datastore/RelationArray.h>
13 
14 #include <genfit/Track.h>
15 
16 using namespace std;
17 using namespace Belle2;
18 
19 REG_MODULE(GenfitTrackCreator)
20 
22  Module()
23 {
24  setDescription("Module turning reco tracks to genfit tracks (will be unneeded once we use reco tracks everywhere).");
25  setPropertyFlags(c_ParallelProcessingCertified);
26 
27  addParam("genfitTracksStoreArrayName", m_param_genfitTrackStoreArrayName, "StoreArray name of the output tracks.",
28  m_param_genfitTrackStoreArrayName);
29  addParam("genfitTrackCandsStoreArrayName", m_param_genfitTrackCandsStoreArrayName,
30  "StoreArray name of the related track candidates.",
31  m_param_genfitTrackCandsStoreArrayName);
32  addParam("recoTracksStoreArrayName", m_param_recoTracksStoreArrayName, "StoreArray name of the input reco tracks.",
33  m_param_recoTracksStoreArrayName);
34 }
35 
36 void GenfitTrackCreatorModule::initialize()
37 {
38  B2WARNING("This module is depricated as it uses genfit::Track(Cand)s instead of RecoTracks. It will be removed in the future. If you need information on the transition, please contact Nils Braun (nils.braun@kit.edu).");
39  StoreArray<RecoTrack> recoTracks(m_param_recoTracksStoreArrayName);
40  recoTracks.isRequired();
41 
42  StoreArray<genfit::Track> genfitTracks(m_param_genfitTrackStoreArrayName);
43  genfitTracks.registerInDataStore();
44 
45  genfitTracks.registerRelationTo(recoTracks);
46 
47  StoreArray<genfit::TrackCand> genfitTrackCands(m_param_genfitTrackCandsStoreArrayName);
48  genfitTrackCands.registerRelationTo(genfitTracks);
49 }
50 
51 void GenfitTrackCreatorModule::event()
52 {
53  StoreArray<RecoTrack> recoTracks(m_param_recoTracksStoreArrayName);
54 
55  StoreArray<genfit::Track> genfitTracks(m_param_genfitTrackStoreArrayName);
56 
57  StoreArray<genfit::TrackCand> genfitTrackCands(m_param_genfitTrackCandsStoreArrayName);
58 
59  // ugly...
60  RelationArray relationsFromTrackCandsToTracks(genfitTrackCands, genfitTracks);
61  unsigned int trackCounter = 0;
62 
63  for (RecoTrack& recoTrack : recoTracks) {
64  if (recoTrack.wasFitSuccessful()) {
65  genfitTracks.appendNew(RecoTrackGenfitAccess::getGenfitTrack(recoTrack));
66  genfit::TrackCand* relatedTrackCand = recoTrack.getRelated<genfit::TrackCand>(
67  m_param_genfitTrackCandsStoreArrayName);
68 
69  // Search for TrackCandidate in StoreArray. This is really really bad, but gnfit does not have a compatible StoreArray-interface.
70  int relatedTrackCandidateCounter = -1;
71  int trackCandidateCounter = 0;
72 
73  for (const genfit::TrackCand& trackCandidate : genfitTrackCands) {
74  if (&trackCandidate == relatedTrackCand) {
75  relatedTrackCandidateCounter = trackCandidateCounter;
76  break;
77  }
78  trackCandidateCounter++;
79  }
80 
81  if (relatedTrackCandidateCounter != -1) {
82  relationsFromTrackCandsToTracks.add(relatedTrackCandidateCounter, trackCounter);
83  } else {
84  B2WARNING("Related TrackCandidate is invalid. Do not add relation.");
85  }
86  trackCounter++;
87  }
88  }
89 }
Belle2::StoreArray::appendNew
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:256
Belle2::RelationArray
Low-level class to create/modify relations between StoreArrays.
Definition: RelationArray.h:72
Belle2::StoreArray::registerRelationTo
bool registerRelationTo(const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut, const std::string &namedRelation="") const
Register a relation to the given StoreArray.
Definition: StoreArray.h:150
genfit::TrackCand
Track candidate – seed values and indices.
Definition: TrackCand.h:69
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::RecoTrack
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:78
Belle2::GenfitTrackCreatorModule
Module turning reco tracks to genfit tracks (will be unneeded once we use reco tracks everywhere).
Definition: GenfitTrackCreatorModule.h:33
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::RelationArray::add
void add(index_type from, index_type to, weight_type weight=1.0)
Add a new element to the relation.
Definition: RelationArray.h:291
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33