Belle II Software  release-05-02-19
FittedTracksStorerModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010-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/FittedTracksStorerModule.h>
11 #include <tracking/dataobjects/RecoTrack.h>
12 #include <mdst/dataobjects/MCParticle.h>
13 #include <mdst/dataobjects/Track.h>
14 
15 using namespace std;
16 using namespace Belle2;
17 
18 REG_MODULE(FittedTracksStorer)
19 
21  Module()
22 {
23  setPropertyFlags(c_ParallelProcessingCertified);
24  setDescription("A module to copy only the fitted reco tracks to the output store array.");
25 
26  addParam("inputRecoTracksStoreArrayName", m_param_inputRecoTracksStoreArrayName, "StoreArray name of the input reco tracks.",
27  m_param_inputRecoTracksStoreArrayName);
28  addParam("outputRecoTracksStoreArrayName", m_param_outputRecoTracksStoreArrayName, "StoreArray name of the output reco tracks.",
29  m_param_outputRecoTracksStoreArrayName);
30  addParam("minimalWeight", m_param_minimalWeight, "Minimal weight for copying the hits.", m_param_minimalWeight);
31 }
32 
33 void FittedTracksStorerModule::initialize()
34 {
35  StoreArray<RecoTrack> inputRecoTracks(m_param_inputRecoTracksStoreArrayName);
36  inputRecoTracks.isRequired();
37 
38  StoreArray<RecoTrack> outputRecoTracks(m_param_outputRecoTracksStoreArrayName);
39  outputRecoTracks.registerInDataStore(DataStore::c_ErrorIfAlreadyRegistered);
40 
41  RecoTrack::registerRequiredRelations(outputRecoTracks);
42 
43  inputRecoTracks.registerRelationTo(outputRecoTracks);
44 
45  StoreArray<MCParticle> mcParticles;
46  if (mcParticles.isOptional()) {
47  outputRecoTracks.registerRelationTo(mcParticles);
48  }
49 
50  StoreArray<Track> tracks;
51  if (tracks.isOptional()) {
52  tracks.registerRelationTo(outputRecoTracks);
53  }
54 }
55 
56 
57 void FittedTracksStorerModule::event()
58 {
59  StoreArray<RecoTrack> inputRecoTracks(m_param_inputRecoTracksStoreArrayName);
60  StoreArray<RecoTrack> outputRecoTracks(m_param_outputRecoTracksStoreArrayName);
61 
62  StoreArray<MCParticle> mcParticles;
63  StoreArray<Track> tracks;
64 
65  for (RecoTrack& recoTrack : inputRecoTracks) {
66  if (recoTrack.wasFitSuccessful()) {
67  auto newRecoTrack = recoTrack.copyToStoreArray(outputRecoTracks);
68  newRecoTrack->addHitsFromRecoTrack(&recoTrack, 0, false, m_param_minimalWeight);
69 
70  // Add also relations
71  auto relatedTrack = recoTrack.getRelated<Track>();
72  if (relatedTrack) {
73  relatedTrack->addRelationTo(newRecoTrack);
74  }
75 
76  auto relatedParticle = recoTrack.getRelated<MCParticle>();
77  if (relatedParticle) {
78  newRecoTrack->addRelationTo(relatedParticle);
79  }
80 
81  recoTrack.addRelationTo(newRecoTrack);
82  }
83  }
84 }
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
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::RelationsInterface::addRelationTo
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).
Definition: RelationsObject.h:144
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::FittedTracksStorerModule
A module to copy only the fitted reco tracks to the output store array.
Definition: FittedTracksStorerModule.h:34
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::Track
Class that bundles various TrackFitResults.
Definition: Track.h:35
Belle2::MCParticle
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:43
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33