Belle II Software  release-08-01-10
CDCTriggerTrackCombinerModule.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 "trg/cdc/modules/trgcdc/CDCTriggerTrackCombinerModule.h"
9 
10 #include <framework/datastore/RelationVector.h>
11 
12 using namespace std;
13 using namespace Belle2;
14 
15 //this line registers the module with the framework and actually makes it available
16 //in steering files or the the module list (basf2 -m).
17 REG_MODULE(CDCTriggerTrackCombiner);
18 
19 CDCTriggerTrackCombinerModule::CDCTriggerTrackCombinerModule() : Module::Module()
20 {
22  "The combiner module of the CDC trigger.\n"
23  "Takes tracks from the various trigger stages (finder, fitter, neuro) "
24  "and combines them to a single track list. "
25  "The 2D track parameters are taken from the fitter, if present. "
26  "For the 3D track parameters there are different options (see parameters). "
27  "Combined tracks are not produced for tracks without 3D information "
28  "from either 3D fitter or neuro.\n"
29  );
31  addParam("finder2DCollectionName", m_2DfinderCollectionName,
32  "Name of the 2D finder track list.",
33  string("TRGCDC2DFinderTracks"));
34  addParam("fitter2DCollectionName", m_2DfitterCollectionName,
35  "Name of the 2D fitter track list.",
36  string("TRGCDC2DFitterTracks"));
37  addParam("fitter3DCollectionName", m_3DfitterCollectionName,
38  "Name of the 3D fitter track list.",
39  string("TRGCDC3DFitterTracks"));
40  addParam("neuroCollectionName", m_neuroCollectionName,
41  "Name of the neuro track list.",
42  string("TRGCDCNeuroTracks"));
43  addParam("outputCollectionName", m_outputCollectionName,
44  "Name of the output track list for the combined tracks.",
45  string("TRGCDCTracks"));
46  addParam("hitCollectionName", m_hitCollectionName,
47  "Name of track segment hit list, needed for hit relations.",
48  string(""));
49  addParam("thetaDefinition", m_thetaDefinition,
50  "Select how to define cot(theta). Valid options are "
51  "3Dfitter (use 3Dfitter if present, otherwise neuro), "
52  "neuro (use neuro if present, otherwise 3Dfitter) or "
53  "avg (average 3Dfitter and neuro).",
54  string("avg"));
55  addParam("zDefinition", m_zDefinition,
56  "Select how to define z0. Valid options are "
57  "3Dfitter (use 3Dfitter if present, otherwise neuro), "
58  "neuro (use neuro if present, otherwise 3Dfitter), "
59  "avg (average 3Dfitter and neuro), "
60  "min (smaller |z0| of 3Dfitter and neuro) or "
61  "max (larger |z0| of 3Dfitter and neuro).",
62  string("min"));
63 }
64 
65 void
67 {
68  // register DataStore elements
73  tracks2Dfitter.isRequired(m_2DfitterCollectionName);
74  tracks3Dfitter.isRequired(m_3DfitterCollectionName);
75  tracksNeuro.isRequired(m_neuroCollectionName);
77  // register relations
80 }
81 
82 void
84 {
85  for (int itrack = 0; itrack < m_tracks2Dfinder.getEntries(); ++itrack) {
86  CDCTriggerTrack* track2Dfinder = m_tracks2Dfinder[itrack];
87  CDCTriggerTrack* track2Dfitter =
88  track2Dfinder->getRelatedTo<CDCTriggerTrack>(m_2DfitterCollectionName);
89  CDCTriggerTrack* track3Dfitter =
90  (track2Dfitter)
91  ? track2Dfitter->getRelatedTo<CDCTriggerTrack>(m_3DfitterCollectionName)
92  : nullptr;
93  CDCTriggerTrack* trackNeuro =
94  track2Dfinder->getRelatedTo<CDCTriggerTrack>(m_neuroCollectionName);
95 
96  if (!track3Dfitter && !trackNeuro) {
97  B2DEBUG(100, "skip track without 3D parameters");
98  continue;
99  }
100 
101  // 2D: take fitter if present, otherwise finder
102  CDCTriggerTrack* track2D = (track2Dfitter) ? track2Dfitter : track2Dfinder;
103 
104  // 3D: get parameters separately according to options
105  double z = 0;
106  double cotTheta = 0;
107  double chi3D = 0;
108  bool usedFit = false;
109  bool usedNN = false;
110 
111  if (!track3Dfitter) {
112  B2DEBUG(100, "no 3D fitter results, use neuro results");
113  z = trackNeuro->getZ0();
114  cotTheta = trackNeuro->getCotTheta();
115  chi3D = trackNeuro->getChi3D();
116  usedNN = true;
117  } else if (!trackNeuro) {
118  B2DEBUG(100, "no neuro results, use 3D fitter results");
119  z = track3Dfitter->getZ0();
120  cotTheta = track3Dfitter->getCotTheta();
121  chi3D = track3Dfitter->getCotTheta();
122  usedFit = true;
123  } else {
124  B2DEBUG(100, "combine 3D fitter and neuro results");
125  // z options
126  if (m_zDefinition == "3Dfitter") {
127  z = track3Dfitter->getZ0();
128  usedFit = true;
129  } else if (m_zDefinition == "neuro") {
130  z = trackNeuro->getZ0();
131  usedNN = true;
132  } else if (m_zDefinition == "avg") {
133  z = (track3Dfitter->getZ0() + trackNeuro->getZ0()) / 2.;
134  usedFit = true;
135  usedNN = true;
136  } else if (m_zDefinition == "min") {
137  z = (abs(track3Dfitter->getZ0()) < abs(trackNeuro->getZ0()))
138  ? track3Dfitter->getZ0()
139  : trackNeuro->getZ0();
140  usedFit = true;
141  usedNN = true;
142  } else if (m_zDefinition == "max") {
143  z = (abs(track3Dfitter->getZ0()) > abs(trackNeuro->getZ0()))
144  ? track3Dfitter->getZ0()
145  : trackNeuro->getZ0();
146  usedFit = true;
147  usedNN = true;
148  } else {
149  B2ERROR("invalid option for zDefinition " << m_zDefinition
150  << " (choose one of 3Dfitter, neuro, avg, min, max)");
151  }
152  // theta options
153  if (m_thetaDefinition == "3Dfitter") {
154  cotTheta = track3Dfitter->getCotTheta();
155  usedFit = true;
156  } else if (m_thetaDefinition == "neuro") {
157  cotTheta = trackNeuro->getCotTheta();
158  usedNN = true;
159  } else if (m_thetaDefinition == "avg") {
160  cotTheta = (track3Dfitter->getCotTheta() + trackNeuro->getCotTheta()) / 2.;
161  usedFit = true;
162  usedNN = true;
163  } else {
164  B2ERROR("invalid option for thetaDefinition " << m_thetaDefinition
165  << " (choose one of 3Dfitter, neuro, avg)");
166  }
167  // only fitter calculates a chi2 value
168  chi3D = track3Dfitter->getChi3D();
169  }
170 
171  // create new track
172  CDCTriggerTrack* combinedTrack =
173  m_tracksCombined.appendNew(track2D->getPhi0(), track2D->getOmega(), track2D->getChi2D(),
174  z, cotTheta, chi3D);
175  track2Dfinder->addRelationTo(combinedTrack);
176  // get hit relations from all tracks, but without duplicates
177  vector<bool> usedHit(m_segmentHits.getEntries(), false);
178  for (const CDCTriggerSegmentHit& hit :
179  track2Dfinder->getRelationsTo<CDCTriggerSegmentHit>(m_hitCollectionName)) {
180  combinedTrack->addRelationTo(&hit);
181  usedHit[hit.getArrayIndex()] = true;
182  }
183  if (track2Dfitter) {
184  for (const CDCTriggerSegmentHit& hit :
185  track2Dfitter->getRelationsTo<CDCTriggerSegmentHit>(m_hitCollectionName)) {
186  if (!usedHit[hit.getArrayIndex()]) {
187  combinedTrack->addRelationTo(&hit);
188  usedHit[hit.getArrayIndex()] = true;
189  }
190  }
191  }
192  if (track3Dfitter && usedFit) {
193  for (const CDCTriggerSegmentHit& hit :
194  track3Dfitter->getRelationsTo<CDCTriggerSegmentHit>(m_hitCollectionName)) {
195  if (!usedHit[hit.getArrayIndex()]) {
196  combinedTrack->addRelationTo(&hit);
197  usedHit[hit.getArrayIndex()] = true;
198  }
199  }
200  }
201  if (trackNeuro && usedNN) {
202  for (const CDCTriggerSegmentHit& hit :
203  trackNeuro->getRelationsTo<CDCTriggerSegmentHit>(m_hitCollectionName)) {
204  if (!usedHit[hit.getArrayIndex()]) {
205  combinedTrack->addRelationTo(&hit);
206  usedHit[hit.getArrayIndex()] = true;
207  }
208  }
209  }
210  }
211 }
Combination of several CDCHits to a track segment hit for the trigger.
StoreArray< CDCTriggerTrack > m_tracks2Dfinder
list of 2D finder tracks (all others are obtained via relations)
std::string m_zDefinition
defines how to calculate z0 of the combined track
std::string m_thetaDefinition
defines how to calculate cot(theta) of the combined track
std::string m_3DfitterCollectionName
name of the 3D fitter track list
virtual void initialize() override
Initialize the module and register DataStore arrays.
virtual void event() override
Combine tracks.
StoreArray< CDCTriggerSegmentHit > m_segmentHits
list of track segment hits
std::string m_outputCollectionName
name of the output track list for the combined tracks
std::string m_neuroCollectionName
name of the neuro track list
std::string m_2DfinderCollectionName
name of the 2D finder track list
StoreArray< CDCTriggerTrack > m_tracksCombined
list of combined output tracks
std::string m_2DfitterCollectionName
name of the 2D fitter track list
std::string m_hitCollectionName
name of track segment hit list (for relations)
Track created by the CDC trigger.
float getChi3D() const
get chi2 value of 3D fitter
float getChi2D() const
get chi2 value of 2D fitter
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:246
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
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
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#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.