Belle II Software  release-06-02-00
recoTrack.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 
9 #include <tracking/dataobjects/RecoTrack.h>
10 #include <framework/datastore/StoreArray.h>
11 
12 #include <framework/utilities/TestHelpers.h>
13 #include <framework/gearbox/Const.h>
14 #include <vector>
15 #include <genfit/WireTrackCandHit.h>
16 
17 
18 using namespace std;
19 
20 namespace Belle2 {
26  class RecoTrackTest : public ::testing::Test {
27  protected:
29  void SetUp() override
30  {
32  m_storeArrayNameOfRecoTracks = "ILoveRecoTracks";
34  m_storeArrayNameOfCDCHits = "CDCHitsAreCool";
36  m_storeArrayNameOfSVDHits = "WhatAboutSVD";
38  m_storeArrayNameOfPXDHits = "PXDsILike";
40  m_storeArrayNameOfBKLMHits = "KeepBKLMsAlive";
42  m_storeArrayNameOfEKLMHits = "EKLMsAreImportant";
44  m_storeArrayNameOfHitInformation = "ConnectingAll";
45 
46  //--- Setup -----------------------------------------------------------------------
47  // We do not use the KLM store arrays to test, if the RecoTrack can be used without them.
48  DataStore::Instance().setInitializeActive(true);
49  StoreArray<CDCHit> cdcHits(m_storeArrayNameOfCDCHits);
50  cdcHits.registerInDataStore();
51  StoreArray<SVDCluster> svdHits(m_storeArrayNameOfSVDHits);
52  svdHits.registerInDataStore();
53  StoreArray<PXDCluster> pxdHits(m_storeArrayNameOfPXDHits);
54  pxdHits.registerInDataStore();
55  StoreArray<RecoTrack> recoTracks(m_storeArrayNameOfRecoTracks);
56  recoTracks.registerInDataStore();
57  StoreArray<RecoHitInformation> recoHitInformations(m_storeArrayNameOfHitInformation);
58  recoHitInformations.registerInDataStore();
59 
60  cdcHits.registerRelationTo(recoTracks);
61  svdHits.registerRelationTo(recoTracks);
62  pxdHits.registerRelationTo(recoTracks);
63  recoHitInformations.registerRelationTo(cdcHits);
64  recoHitInformations.registerRelationTo(svdHits);
65  recoHitInformations.registerRelationTo(pxdHits);
66 
67  recoTracks.registerRelationTo(recoHitInformations);
68 
69  //"CDCHit(tdcCount, adcCount, superLayer, layer, wire)"
70  //Indices range from 0-7
71  cdcHits.appendNew(100, 100, 0, 0, 0);
72  cdcHits.appendNew(100, 100, 2, 0, 0);
73  cdcHits.appendNew(100, 100, 4, 0, 0);
74  cdcHits.appendNew(100, 100, 6, 0, 0);
75  cdcHits.appendNew(100, 100, 8, 0, 0);
76  cdcHits.appendNew(100, 100, 1, 1, 0);
77  cdcHits.appendNew(100, 100, 3, 0, 0);
78  cdcHits.appendNew(100, 100, 5, 0, 0);
79 
80  // We add some hits to the track. Then we assure they were added properly and the hit information objects are correct.
81  TVector3 position(0, 1, 2);
82  TVector3 momentum(-1, -0.5, 1.123);
83  short int charge = 1;
84  m_recoTrack = recoTracks.appendNew(position, momentum, charge,
85  m_storeArrayNameOfCDCHits, m_storeArrayNameOfSVDHits, m_storeArrayNameOfPXDHits,
86  m_storeArrayNameOfBKLMHits, m_storeArrayNameOfEKLMHits, m_storeArrayNameOfHitInformation);
87  m_recoTrack2 = recoTracks.appendNew(position, momentum, charge,
88  m_storeArrayNameOfCDCHits, m_storeArrayNameOfSVDHits, m_storeArrayNameOfPXDHits,
89  m_storeArrayNameOfBKLMHits, m_storeArrayNameOfEKLMHits, m_storeArrayNameOfHitInformation);
90  }
91 
101  };
102 
105  {
106  StoreArray<CDCHit> cdcHits(m_storeArrayNameOfCDCHits);
107 
108  EXPECT_FALSE(m_recoTrack->hasCDCHits());
109 
110  // Add three cdc hits to the track
111  m_recoTrack->addCDCHit(cdcHits[0], 1);
112  m_recoTrack->addCDCHit(cdcHits[1], 0, RecoHitInformation::RightLeftInformation::c_right);
113  m_recoTrack->addCDCHit(cdcHits[2], 2);
114 
115  EXPECT_TRUE(m_recoTrack->hasCDCHits());
116 
117  EXPECT_TRUE(m_recoTrack->hasHit(cdcHits[0]));
118  EXPECT_TRUE(m_recoTrack->hasHit(cdcHits[1]));
119  EXPECT_TRUE(m_recoTrack->hasHit(cdcHits[2]));
120 
121  EXPECT_FALSE(m_recoTrack->hasHit(cdcHits[4]));
122 
123  ASSERT_EQ(m_recoTrack->getNumberOfCDCHits(), 3);
124  const std::vector<CDCHit*> addedCDCHits = m_recoTrack->getCDCHitList();
125  ASSERT_EQ(addedCDCHits.size(), 3);
126  EXPECT_EQ(addedCDCHits[0], cdcHits[0]);
127  EXPECT_EQ(addedCDCHits[1], cdcHits[1]);
128  EXPECT_EQ(addedCDCHits[2], cdcHits[2]);
129 
130  const std::vector<CDCHit*> sortedCDCHits = m_recoTrack->getSortedCDCHitList();
131  ASSERT_EQ(sortedCDCHits.size(), 3);
132  EXPECT_EQ(sortedCDCHits[0], cdcHits[1]);
133  EXPECT_EQ(sortedCDCHits[1], cdcHits[0]);
134  EXPECT_EQ(sortedCDCHits[2], cdcHits[2]);
135 
136  // Individual hit information
137  CDCHit* cdcHit = cdcHits[0];
138 
139  RecoHitInformation* recoHitInformation = m_recoTrack->getRecoHitInformation(cdcHit);
140  EXPECT_NE(recoHitInformation, nullptr);
141  EXPECT_EQ(recoHitInformation->getTrackingDetector(), RecoHitInformation::RecoHitDetector::c_CDC);
142  EXPECT_EQ(recoHitInformation->getRightLeftInformation(), RecoHitInformation::RightLeftInformation::c_undefinedRightLeftInformation);
143  EXPECT_EQ(recoHitInformation->getFoundByTrackFinder(), RecoHitInformation::OriginTrackFinder::c_undefinedTrackFinder);
144  EXPECT_EQ(recoHitInformation->getSortingParameter(), 1);
145 
146  cdcHit = cdcHits[1];
147  recoHitInformation = m_recoTrack->getRecoHitInformation(cdcHit);
148  EXPECT_NE(recoHitInformation, nullptr);
149  EXPECT_EQ(recoHitInformation->getRightLeftInformation(), RecoHitInformation::RightLeftInformation::c_right);
150 
151 
152 
153  // Setter and getter for the reco hit information
154  // with added hits
155  cdcHit = cdcHits[0];
156 
157  EXPECT_EQ(m_recoTrack->getTrackingDetector(cdcHit), RecoHitInformation::RecoHitDetector::c_CDC);
158  EXPECT_EQ(m_recoTrack->getRightLeftInformation(cdcHit), RecoHitInformation::RightLeftInformation::c_undefinedRightLeftInformation);
159  EXPECT_EQ(m_recoTrack->getFoundByTrackFinder(cdcHit), RecoHitInformation::OriginTrackFinder::c_undefinedTrackFinder);
160  EXPECT_EQ(m_recoTrack->getSortingParameter(cdcHit), 1);
161 
162  EXPECT_NO_THROW(m_recoTrack->setFoundByTrackFinder(cdcHit, RecoHitInformation::OriginTrackFinder::c_SegmentTrackCombiner));
163  EXPECT_NO_THROW(m_recoTrack->setRightLeftInformation(cdcHit, RecoHitInformation::RightLeftInformation::c_left));
164  EXPECT_NO_THROW(m_recoTrack->setSortingParameter(cdcHit, 3));
165 
166  EXPECT_EQ(m_recoTrack->getFoundByTrackFinder(cdcHit), RecoHitInformation::OriginTrackFinder::c_SegmentTrackCombiner);
167  EXPECT_EQ(m_recoTrack->getRightLeftInformation(cdcHit), RecoHitInformation::RightLeftInformation::c_left);
168  EXPECT_EQ(m_recoTrack->getSortingParameter(cdcHit), 3);
169 
170  // with not added hits
171  cdcHit = cdcHits[4];
172 
173  EXPECT_B2FATAL(m_recoTrack->getTrackingDetector(cdcHit));
174  EXPECT_B2FATAL(m_recoTrack->getRightLeftInformation(cdcHit));
175  EXPECT_B2FATAL(m_recoTrack->getFoundByTrackFinder(cdcHit));
176  EXPECT_B2FATAL(m_recoTrack->getSortingParameter(cdcHit));
177 
178  EXPECT_B2FATAL(m_recoTrack->setFoundByTrackFinder(cdcHit, RecoHitInformation::OriginTrackFinder::c_SegmentTrackCombiner));
179  EXPECT_B2FATAL(m_recoTrack->setRightLeftInformation(cdcHit, RecoHitInformation::RightLeftInformation::c_left));
180  }
181 
183  TEST_F(RecoTrackTest, cdcHitMCFinderCategory)
184  {
185  StoreArray<CDCHit> cdcHits(m_storeArrayNameOfCDCHits);
186 
187  EXPECT_FALSE(m_recoTrack->hasCDCHits());
188 
189  // Add three cdc hits to the track
190  m_recoTrack->addCDCHit(cdcHits[0], 1, RecoHitInformation::RightLeftInformation::c_right,
191  RecoHitInformation::OriginTrackFinder::c_MCTrackFinderPriorityHit);
192  m_recoTrack->addCDCHit(cdcHits[1], 0, RecoHitInformation::RightLeftInformation::c_right,
193  RecoHitInformation::OriginTrackFinder::c_MCTrackFinderAuxiliaryHit);
194  // the mcfinder prorperty of this hit is not provided explicitly and therefore should be set to undefined
195  m_recoTrack->addCDCHit(cdcHits[2], 2);
196 
197  // get the RecoHitInfo and check their category
198  EXPECT_EQ(m_recoTrack->getRecoHitInformation(cdcHits[0])->getFoundByTrackFinder(),
199  RecoHitInformation::OriginTrackFinder::c_MCTrackFinderPriorityHit);
200  EXPECT_EQ(m_recoTrack->getRecoHitInformation(cdcHits[1])->getFoundByTrackFinder(),
201  RecoHitInformation::OriginTrackFinder::c_MCTrackFinderAuxiliaryHit);
202  EXPECT_EQ(m_recoTrack->getRecoHitInformation(cdcHits[2])->getFoundByTrackFinder(),
203  RecoHitInformation::OriginTrackFinder::c_undefinedTrackFinder);
204  }
205 
207  TEST_F(RecoTrackTest, testGenfitConversionOne)
208  {
209  // Create a genfit track cand
210  genfit::TrackCand newCreatedTrackCand;
211  TVector3 position(4, 23, 5.6);
212  TVector3 momentum(4, 23, 5.6);
213  short int charge = 1;
214  // We can not add these parameters immediately - we hve to convert them to the perigee parameters
215  newCreatedTrackCand.setPosMomSeed(position, momentum, charge);
216  newCreatedTrackCand.addHit(new genfit::WireTrackCandHit(Const::CDC, 0, -1, 0, 0));
217  newCreatedTrackCand.addHit(new genfit::WireTrackCandHit(Const::CDC, 1, -1, 1, 0));
218  newCreatedTrackCand.addHit(new genfit::WireTrackCandHit(Const::CDC, 2, -1, 2, 0));
219 
220  // convert it to a RecoTrack
221  RecoTrack* recoTrackFromGenfit = RecoTrack::createFromTrackCand(newCreatedTrackCand, m_storeArrayNameOfRecoTracks,
222  m_storeArrayNameOfCDCHits, m_storeArrayNameOfSVDHits,
223  m_storeArrayNameOfPXDHits, m_storeArrayNameOfBKLMHits,
224  m_storeArrayNameOfEKLMHits,
225  m_storeArrayNameOfHitInformation);
226 
227  // convert it back
228 
229  const genfit::TrackCand& exportedTrackCand = recoTrackFromGenfit->createGenfitTrackCand();
230 
231  // Expect equal
232  ASSERT_EQ(exportedTrackCand.getNHits(), newCreatedTrackCand.getNHits());
233  EXPECT_NEAR(exportedTrackCand.getPosSeed().X(), newCreatedTrackCand.getPosSeed().X(), 1E-10);
234  EXPECT_NEAR(exportedTrackCand.getPosSeed().Y(), newCreatedTrackCand.getPosSeed().Y(), 1E-10);
235  EXPECT_NEAR(exportedTrackCand.getPosSeed().Z(), newCreatedTrackCand.getPosSeed().Z(), 1E-10);
236  EXPECT_NEAR(exportedTrackCand.getMomSeed().X(), newCreatedTrackCand.getMomSeed().X(), 1E-10);
237  EXPECT_NEAR(exportedTrackCand.getMomSeed().Y(), newCreatedTrackCand.getMomSeed().Y(), 1E-10);
238  EXPECT_NEAR(exportedTrackCand.getMomSeed().Z(), newCreatedTrackCand.getMomSeed().Z(), 1E-10);
239  EXPECT_EQ(exportedTrackCand.getChargeSeed(), newCreatedTrackCand.getChargeSeed());
240  EXPECT_EQ(exportedTrackCand.getHit(0)->getHitId(), newCreatedTrackCand.getHit(0)->getHitId());
241  EXPECT_EQ(exportedTrackCand.getHit(1)->getSortingParameter(), newCreatedTrackCand.getHit(1)->getSortingParameter());
242  EXPECT_EQ(exportedTrackCand.getHit(2)->getHitId(), newCreatedTrackCand.getHit(2)->getHitId());
243  }
244 
246  TEST_F(RecoTrackTest, testGenfitConversionTwo)
247  {
248  EXPECT_FALSE(m_recoTrack->hasCDCHits());
249  StoreArray<CDCHit> cdcHits(m_storeArrayNameOfCDCHits);
250 
251  // Add three cdc hits to the track
252  m_recoTrack->addCDCHit(cdcHits[0], 1);
253  m_recoTrack->addCDCHit(cdcHits[1], 0, RecoHitInformation::RightLeftInformation::c_right);
254  m_recoTrack->addCDCHit(cdcHits[2], 2);
255 
256  EXPECT_TRUE(m_recoTrack->hasCDCHits());
257 
258  const genfit::TrackCand& exportedTrackCand = m_recoTrack->createGenfitTrackCand();
259 
260  ASSERT_EQ(exportedTrackCand.getNHits(), m_recoTrack->getNumberOfTotalHits());
261  ASSERT_EQ(m_recoTrack->getNumberOfTotalHits(), 3);
262 
263  RecoTrack* recoTrackFromGenfit = RecoTrack::createFromTrackCand(exportedTrackCand, m_storeArrayNameOfRecoTracks,
264  m_storeArrayNameOfCDCHits, m_storeArrayNameOfSVDHits,
265  m_storeArrayNameOfPXDHits, m_storeArrayNameOfBKLMHits,
266  m_storeArrayNameOfEKLMHits,
267  m_storeArrayNameOfHitInformation);
268 
269  B2INFO("kjh");
270 
271  ASSERT_EQ(recoTrackFromGenfit->getNumberOfCDCHits(), m_recoTrack->getNumberOfCDCHits());
272  const auto& cdcHitListOne = recoTrackFromGenfit->getCDCHitList();
273  const auto& cdcHitListTwo = m_recoTrack->getCDCHitList();
274  ASSERT_EQ(cdcHitListOne.size(), 3);
275  ASSERT_EQ(cdcHitListTwo.size(), 3);
276  }
277 
279  TEST_F(RecoTrackTest, copyRecoTrack)
280  {
281  StoreArray<CDCHit> cdcHits(m_storeArrayNameOfCDCHits);
282 
283  // Add three cdc hits to the track
284  m_recoTrack->addCDCHit(cdcHits[0], 1);
285  m_recoTrack->addCDCHit(cdcHits[1], 0, RecoHitInformation::RightLeftInformation::c_right);
286  m_recoTrack->addCDCHit(cdcHits[2], 2);
287 
288  // create a second RecoTrack
289  StoreArray<RecoTrack> recoTracks(m_storeArrayNameOfRecoTracks);
290 
291  auto recoTrack = recoTracks.appendNew(m_recoTrack->getPositionSeed(), m_recoTrack->getMomentumSeed(), m_recoTrack->getChargeSeed(),
292  m_storeArrayNameOfCDCHits, m_storeArrayNameOfSVDHits, m_storeArrayNameOfPXDHits,
293  m_storeArrayNameOfBKLMHits, m_storeArrayNameOfEKLMHits,
294  m_storeArrayNameOfHitInformation);
295  EXPECT_FALSE(recoTrack->hasCDCHits());
296 
297  // check if the offset computation of the hit order works as expected
298  size_t offset = 3;
299  recoTrack->addHitsFromRecoTrack(m_recoTrack, offset);
300  ASSERT_EQ(recoTrack->getNumberOfCDCHits(), 3);
301 
302  size_t this_i = offset;
303  for (auto pHit : recoTrack->getSortedCDCHitList()) {
304  auto sortParam = recoTrack->getSortingParameter(pHit);
305  ASSERT_EQ(this_i, sortParam);
306  this_i++;
307  }
308  }
309 
311  TEST_F(RecoTrackTest, recoHitInformations)
312  {
313  StoreArray<CDCHit> cdcHits(m_storeArrayNameOfCDCHits);
314 
315  m_recoTrack->addCDCHit(cdcHits[0], 1);
316 
317  // create a second RecoTrack
318  StoreArray<RecoTrack> recoTracks(m_storeArrayNameOfRecoTracks);
319 
320  RecoTrack* recoTrack2 = recoTracks.appendNew(m_recoTrack->getPositionSeed(), m_recoTrack->getMomentumSeed(),
321  m_recoTrack->getChargeSeed(),
322  m_storeArrayNameOfCDCHits, m_storeArrayNameOfSVDHits, m_storeArrayNameOfPXDHits,
323  m_storeArrayNameOfBKLMHits, m_storeArrayNameOfEKLMHits,
324  m_storeArrayNameOfHitInformation);
325  recoTrack2->addCDCHit(cdcHits[1], 2);
326 
327  ASSERT_EQ(m_recoTrack->getRecoHitInformations().size(), 1);
328  ASSERT_EQ(m_recoTrack->getRecoHitInformations()[0]->getSortingParameter(), 1);
329  ASSERT_EQ(recoTrack2->getRecoHitInformations().size(), 1);
330  ASSERT_EQ(recoTrack2->getRecoHitInformations()[0]->getSortingParameter(), 2);
331  }
333 }
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
Definition: CDCHit.h:40
This class stores additional information to every CDC/SVD/PXD hit stored in a RecoTrack.
RightLeftInformation getRightLeftInformation() const
Get the right-left-information.
OriginTrackFinder getFoundByTrackFinder() const
Get which track finder has found the track.
RecoHitDetector getTrackingDetector() const
Get the detector this hit comes from.
unsigned int getSortingParameter() const
Get the sorting parameter.
Test class for the RecoTrack object.
Definition: recoTrack.cc:26
std::string m_storeArrayNameOfHitInformation
name of storeArray with hit information
Definition: recoTrack.cc:100
std::string m_storeArrayNameOfCDCHits
name of storeArray with CDC hits
Definition: recoTrack.cc:95
void SetUp() override
Setup a "working environment" with store arrays for the hits and the correct relations.
Definition: recoTrack.cc:29
std::string m_storeArrayNameOfBKLMHits
name of storeArray with BKLM hits
Definition: recoTrack.cc:98
std::string m_storeArrayNameOfRecoTracks
name of recoTracks storeArray
Definition: recoTrack.cc:94
std::string m_storeArrayNameOfSVDHits
name of storeArray with SVD hits
Definition: recoTrack.cc:96
RecoTrack * m_recoTrack2
pointer to other recoTrack
Definition: recoTrack.cc:93
std::string m_storeArrayNameOfEKLMHits
name of storeArray with EKLM hits
Definition: recoTrack.cc:99
RecoTrack * m_recoTrack
pointer to recoTrack
Definition: recoTrack.cc:92
std::string m_storeArrayNameOfPXDHits
name of storeArray with PXD hits
Definition: recoTrack.cc:97
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:76
bool addCDCHit(const UsedCDCHit *cdcHit, const unsigned int sortingParameter, RightLeftInformation rightLeftInformation=RightLeftInformation::c_undefinedRightLeftInformation, OriginTrackFinder foundByTrackFinder=OriginTrackFinder::c_undefinedTrackFinder)
Adds a cdc hit with the given information to the reco track.
Definition: RecoTrack.h:238
unsigned int getNumberOfCDCHits() const
Return the number of cdc hits.
Definition: RecoTrack.h:416
std::vector< Belle2::RecoTrack::UsedCDCHit * > getCDCHitList() const
Return an unsorted list of cdc hits.
Definition: RecoTrack.h:445
genfit::TrackCand createGenfitTrackCand() const
Create a genfit::TrackCand out of this reco track and copy all information to the track candidate.
Definition: RecoTrack.cc:175
std::vector< RecoHitInformation * > getRecoHitInformations(bool getSorted=false) const
Return a list of all RecoHitInformations associated with the RecoTrack.
Definition: RecoTrack.cc:538
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
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:246
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
Track candidate – seed values and indices.
Definition: TrackCand.h:69
TVector3 getMomSeed() const
get the seed value for track: mom.
Definition: TrackCand.h:128
void setPosMomSeed(const TVector3 &pos, const TVector3 &mom, const double charge)
sets the state to seed the track fitting.
Definition: TrackCand.cc:258
TVector3 getPosSeed() const
get the seed value for track: pos.
Definition: TrackCand.h:125
Hit object for use in TrackCand.
TEST_F(RecoTrackTest, recoHitInformations)
Test the getRecoHitInformations() function.
Definition: recoTrack.cc:311
Abstract base class for different kinds of events.