Belle II Software  release-06-02-00
FittedTracksStorerModule.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #include <tracking/modules/fitter/FittedTracksStorerModule.h>
9 #include <tracking/dataobjects/RecoTrack.h>
10 #include <mdst/dataobjects/MCParticle.h>
11 #include <mdst/dataobjects/Track.h>
12 
13 using namespace std;
14 using namespace Belle2;
15 
16 REG_MODULE(FittedTracksStorer)
17 
19  Module()
20 {
21  setPropertyFlags(c_ParallelProcessingCertified);
22  setDescription("A module to copy only the fitted reco tracks to the output store array.");
23 
24  addParam("inputRecoTracksStoreArrayName", m_param_inputRecoTracksStoreArrayName, "StoreArray name of the input reco tracks.",
25  m_param_inputRecoTracksStoreArrayName);
26  addParam("outputRecoTracksStoreArrayName", m_param_outputRecoTracksStoreArrayName, "StoreArray name of the output reco tracks.",
27  m_param_outputRecoTracksStoreArrayName);
28  addParam("minimalWeight", m_param_minimalWeight, "Minimal weight for copying the hits.", m_param_minimalWeight);
29 }
30 
31 void FittedTracksStorerModule::initialize()
32 {
33  StoreArray<RecoTrack> inputRecoTracks(m_param_inputRecoTracksStoreArrayName);
34  inputRecoTracks.isRequired();
35 
36  StoreArray<RecoTrack> outputRecoTracks(m_param_outputRecoTracksStoreArrayName);
37  outputRecoTracks.registerInDataStore(DataStore::c_ErrorIfAlreadyRegistered);
38 
39  RecoTrack::registerRequiredRelations(outputRecoTracks);
40 
41  inputRecoTracks.registerRelationTo(outputRecoTracks);
42 
43  StoreArray<MCParticle> mcParticles;
44  if (mcParticles.isOptional()) {
45  outputRecoTracks.registerRelationTo(mcParticles);
46  }
47 
48  StoreArray<Track> tracks;
49  if (tracks.isOptional()) {
50  tracks.registerRelationTo(outputRecoTracks);
51  }
52 }
53 
54 
55 void FittedTracksStorerModule::event()
56 {
57  StoreArray<RecoTrack> inputRecoTracks(m_param_inputRecoTracksStoreArrayName);
58  StoreArray<RecoTrack> outputRecoTracks(m_param_outputRecoTracksStoreArrayName);
59 
60  for (RecoTrack& recoTrack : inputRecoTracks) {
61  if (recoTrack.wasFitSuccessful()) {
62  auto newRecoTrack = recoTrack.copyToStoreArray(outputRecoTracks);
63  newRecoTrack->addHitsFromRecoTrack(&recoTrack, 0, false, m_param_minimalWeight);
64 
65  // Add also relations
66  auto relatedTrack = recoTrack.getRelated<Track>();
67  if (relatedTrack) {
68  relatedTrack->addRelationTo(newRecoTrack);
69  }
70 
71  auto relatedParticle = recoTrack.getRelated<MCParticle>();
72  if (relatedParticle) {
73  newRecoTrack->addRelationTo(relatedParticle);
74  }
75 
76  recoTrack.addRelationTo(newRecoTrack);
77  }
78  }
79 }
A module to copy only the fitted reco tracks to the output store array.
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
Base class for Modules.
Definition: Module.h:72
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:76
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
bool isOptional(const std::string &name="")
Tell the DataStore about an optional input.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
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:140
Class that bundles various TrackFitResults.
Definition: Track.h:25
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.