Belle II Software  release-08-01-10
MeasurementAdder.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/trackFitting/measurementCreator/adder/MeasurementAdder.h>
9 #include <tracking/trackFitting/measurementCreator/creators/CoordinateMeasurementCreator.h>
10 
11 #include <cdc/dataobjects/CDCRecoHit.h>
12 #include <pxd/reconstruction/PXDRecoHit.h>
13 #include <svd/reconstruction/SVDRecoHit.h>
14 #include <alignment/reconstruction/AlignableBKLMRecoHit.h>
15 #include <alignment/reconstruction/AlignableEKLMRecoHit.h>
16 
17 #include <cdc/translators/LinearGlobalADCCountTranslator.h>
18 #include <cdc/translators/RealisticCDCGeometryTranslator.h>
19 #include <cdc/translators/RealisticTDCCountTranslator.h>
20 
21 #include <genfit/MeasurementFactory.h>
22 #include <string>
23 
24 using namespace Belle2;
25 
26 
27 namespace {
29  template <class T>
30  bool checkTwoStoreArrayNames(const std::string& firstName, const std::string& secondName)
31  {
32  return ((firstName == secondName) or
33  (firstName.empty() and secondName == DataStore::defaultArrayName<T>()) or
34  (secondName.empty() and firstName == DataStore::defaultArrayName<T>()));
35  }
36 }
37 
39  const std::string& storeArrayNameOfPXDHits,
40  const std::string& storeArrayNameOfSVDHits,
41  const std::string& storeArrayNameOfCDCHits,
42  const std::string& storeArrayNameOfBKLMHits,
43  const std::string& storeArrayNameOfEKLMHits,
44  const bool initializeCDCTranslators) :
45  m_param_storeArrayNameOfPXDHits(storeArrayNameOfPXDHits),
46  m_param_storeArrayNameOfSVDHits(storeArrayNameOfSVDHits),
47  m_param_storeArrayNameOfCDCHits(storeArrayNameOfCDCHits),
48  m_param_storeArrayNameOfBKLMHits(storeArrayNameOfBKLMHits),
49  m_param_storeArrayNameOfEKLMHits(storeArrayNameOfEKLMHits)
50 {
54  if (initializeCDCTranslators) {
55  // Create new Translators and give them to the CDCRecoHits.
59  true);
60  }
63 }
64 
66 {
72 
73  // Create the related measurement factory
74  if (pxdHits.isOptional())
77  if (svdHits.isOptional())
80  if (cdcHits.isOptional())
83  if (bklmHits.isOptional())
86  if (eklmHits.isOptional())
89 }
90 
92 {
93  m_pxdMeasurementCreators = { std::shared_ptr<PXDBaseMeasurementCreator>(new PXDCoordinateMeasurementCreator(m_genfitMeasurementFactory)) };
94  m_svdMeasurementCreators = { std::shared_ptr<SVDBaseMeasurementCreator>(new SVDCoordinateMeasurementCreator(m_genfitMeasurementFactory)) };
95  m_cdcMeasurementCreators = { std::shared_ptr<CDCBaseMeasurementCreator>(new CDCCoordinateMeasurementCreator(m_genfitMeasurementFactory)) };
96  m_bklmMeasurementCreators = { std::shared_ptr<BKLMBaseMeasurementCreator>(new BKLMCoordinateMeasurementCreator(m_genfitMeasurementFactory)) };
97  m_eklmMeasurementCreators = { std::shared_ptr<EKLMBaseMeasurementCreator>(new EKLMCoordinateMeasurementCreator(m_genfitMeasurementFactory)) };
99 
100  m_skipDirtyCheck = false;
101 }
102 
104  const std::vector<std::shared_ptr<PXDBaseMeasurementCreator>>& pxdMeasurementCreators,
105  const std::vector<std::shared_ptr<SVDBaseMeasurementCreator>>& svdMeasurementCreators,
106  const std::vector<std::shared_ptr<CDCBaseMeasurementCreator>>& cdcMeasurementCreators,
107  const std::vector<std::shared_ptr<BKLMBaseMeasurementCreator>>& bklmMeasurementCreators,
108  const std::vector<std::shared_ptr<EKLMBaseMeasurementCreator>>& eklmMeasurementCreators,
109  const std::vector<std::shared_ptr<BaseMeasurementCreator>>& additionalMeasurementCreators)
110 {
111  m_pxdMeasurementCreators = pxdMeasurementCreators;
112  m_svdMeasurementCreators = svdMeasurementCreators;
113  m_cdcMeasurementCreators = cdcMeasurementCreators;
114  m_bklmMeasurementCreators = bklmMeasurementCreators;
115  m_eklmMeasurementCreators = eklmMeasurementCreators;
116  m_additionalMeasurementCreators = additionalMeasurementCreators;
117 
118  m_skipDirtyCheck = true;
119 }
120 
122  const std::map<std::string, std::map<std::string, std::string>>& pxdMeasurementCreators,
123  const std::map<std::string, std::map<std::string, std::string>>& svdMeasurementCreators,
124  const std::map<std::string, std::map<std::string, std::string>>& cdcMeasurementCreators,
125  const std::map<std::string, std::map<std::string, std::string>>& bklmMeasurementCreators,
126  const std::map<std::string, std::map<std::string, std::string>>& eklmMeasurementCreators,
127  const std::map<std::string, std::map<std::string, std::string>>& additionalMeasurementCreators)
128 {
129  PXDMeasurementCreatorFactory pxdMeasurementCreatorFactory(m_genfitMeasurementFactory);
130  SVDMeasurementCreatorFactory svdMeasurementCreatorFactory(m_genfitMeasurementFactory);
131  CDCMeasurementCreatorFactory cdcMeasurementCreatorFactory(m_genfitMeasurementFactory);
132  BKLMMeasurementCreatorFactory bklmMeasurementCreatorFactory(m_genfitMeasurementFactory);
133  EKLMMeasurementCreatorFactory eklmMeasurementCreatorFactory(m_genfitMeasurementFactory);
134  AdditionalMeasurementCreatorFactory additionalMeasurementCreatorFactory;
135 
136  pxdMeasurementCreatorFactory.setParameters(pxdMeasurementCreators);
137  svdMeasurementCreatorFactory.setParameters(svdMeasurementCreators);
138  cdcMeasurementCreatorFactory.setParameters(cdcMeasurementCreators);
139  bklmMeasurementCreatorFactory.setParameters(bklmMeasurementCreators);
140  eklmMeasurementCreatorFactory.setParameters(eklmMeasurementCreators);
141  additionalMeasurementCreatorFactory.setParameters(additionalMeasurementCreators);
142 
143  pxdMeasurementCreatorFactory.initialize();
144  svdMeasurementCreatorFactory.initialize();
145  cdcMeasurementCreatorFactory.initialize();
146  bklmMeasurementCreatorFactory.initialize();
147  eklmMeasurementCreatorFactory.initialize();
148  additionalMeasurementCreatorFactory.initialize();
149 
150  m_pxdMeasurementCreators = pxdMeasurementCreatorFactory.getCreators();
151  m_svdMeasurementCreators = svdMeasurementCreatorFactory.getCreators();
152  m_cdcMeasurementCreators = cdcMeasurementCreatorFactory.getCreators();
153  m_bklmMeasurementCreators = bklmMeasurementCreatorFactory.getCreators();
154  m_eklmMeasurementCreators = eklmMeasurementCreatorFactory.getCreators();
155  m_additionalMeasurementCreators = additionalMeasurementCreatorFactory.getCreators();
156 
157  m_skipDirtyCheck = true;
158 }
159 
161 {
162  B2ASSERT("Reco Track was built with another CDC store array: Reco Track "
163  << recoTrack.getStoreArrayNameOfCDCHits()
164  << ", this class " << m_param_storeArrayNameOfCDCHits,
165  checkTwoStoreArrayNames<RecoHitInformation::UsedCDCHit>(recoTrack.getStoreArrayNameOfCDCHits(), m_param_storeArrayNameOfCDCHits));
166  B2ASSERT("Reco Track was built with another SVD store array: Reco Track "
167  << recoTrack.getStoreArrayNameOfSVDHits()
168  << ", this class " << m_param_storeArrayNameOfSVDHits,
169  checkTwoStoreArrayNames<RecoHitInformation::UsedSVDHit>(recoTrack.getStoreArrayNameOfSVDHits(), m_param_storeArrayNameOfSVDHits));
170  B2ASSERT("Reco Track was built with another PXD store array: Reco Track "
171  << recoTrack.getStoreArrayNameOfPXDHits()
172  << ", this class " << m_param_storeArrayNameOfPXDHits,
173  checkTwoStoreArrayNames<RecoHitInformation::UsedPXDHit>(recoTrack.getStoreArrayNameOfPXDHits(), m_param_storeArrayNameOfPXDHits));
174  B2ASSERT("Reco Track was built with another BKLM store array: Reco Track "
175  << recoTrack.getStoreArrayNameOfBKLMHits()
176  << ", this class " << m_param_storeArrayNameOfBKLMHits,
177  checkTwoStoreArrayNames<RecoHitInformation::UsedBKLMHit>(recoTrack.getStoreArrayNameOfBKLMHits(),
179  B2ASSERT("Reco Track was built with another EKLM store array: Reco Track "
180  << recoTrack.getStoreArrayNameOfEKLMHits()
181  << ", this class " << m_param_storeArrayNameOfEKLMHits,
182  checkTwoStoreArrayNames<RecoHitInformation::UsedEKLMHit>(recoTrack.getStoreArrayNameOfEKLMHits(),
184 
185  if (m_cdcMeasurementCreators.size() == 0 and m_svdMeasurementCreators.size() == 0 and m_pxdMeasurementCreators.size() == 0 and
186  m_bklmMeasurementCreators.size() == 0 and m_eklmMeasurementCreators.size() == 0 and m_additionalMeasurementCreators.size() == 0) {
187  B2WARNING("No measurement creators where added to this instance, so no measurements where created. Did you forget to call setMeasurementCreators?");
188  return false;
189  }
190 
191  if (not recoTrack.getDirtyFlag() and not m_skipDirtyCheck) {
192  B2DEBUG(100, "Hit content did not change since last measurement adding and you are using default parameters." <<
193  "I will not add the measurements again. " <<
194  "If you still want to do so, set the dirty flag to true.");
195  return false;
196  }
197 
198  // Delete all other measurements.
200  recoTrack.setDirtyFlag();
201 
202  std::map<genfit::TrackPoint*, RecoHitInformation*> trackPointHitMapping;
203 
204  // Add the measurements created by the CDC, SVD and PXD measurement creators.
207  addMeasurementsFromHitToRecoTrack<RecoHitInformation::UsedPXDHit, Const::PXD>(recoTrack, recoHitInformation, pxdHit,
208  m_pxdMeasurementCreators, trackPointHitMapping);
209  });
212  addMeasurementsFromHitToRecoTrack<RecoHitInformation::UsedSVDHit, Const::SVD>(recoTrack, recoHitInformation, svdHit,
213  m_svdMeasurementCreators, trackPointHitMapping);
214  });
217  addMeasurementsFromHitToRecoTrack<RecoHitInformation::UsedCDCHit, Const::CDC>(recoTrack, recoHitInformation, cdcHit,
218  m_cdcMeasurementCreators, trackPointHitMapping);
219  });
222  addMeasurementsFromHitToRecoTrack<RecoHitInformation::UsedBKLMHit, Const::BKLM>(recoTrack, recoHitInformation, bklmHit,
223  m_bklmMeasurementCreators, trackPointHitMapping);
224  });
227  addMeasurementsFromHitToRecoTrack<RecoHitInformation::UsedEKLMHit, Const::EKLM>(recoTrack, recoHitInformation, EKLMHit,
228  m_eklmMeasurementCreators, trackPointHitMapping);
229  });
230 
231  // Special case is with the additional measurement creator factories. They do not need any hits:
233 
234  auto& genfitTrack = RecoTrackGenfitAccess::getGenfitTrack(recoTrack);
235 
236  genfitTrack.sort();
237 
238  // FIXME: hotfix:
239  // after we have a mapping between created track points and reco track information, we can use this mapping to
240  // write it back to the reco hit information. Please note, that we only store a single index for each
241  // reco hit information (although there could be multiple track points).
242  // We also assume that the track point vector is never changed again!
243  int counter = 0;
244  for (genfit::TrackPoint* trackPoint : genfitTrack.getPoints()) {
245  trackPointHitMapping[trackPoint]->setCreatedTrackPointID(counter);
246  counter += 1;
247  }
248 
249  return true;
250 }
251 
253  const std::vector<std::shared_ptr<BaseMeasurementCreator>>& measurementCreators) const
254 {
255  for (const auto& measurementCreator : measurementCreators) {
256  const std::vector<genfit::TrackPoint*>& trackPoints = measurementCreator->createMeasurementPoints(recoTrack);
257  for (genfit::TrackPoint* trackPoint : trackPoints) {
258  RecoTrackGenfitAccess::getGenfitTrack(recoTrack).insertPoint(trackPoint);
259  }
260  }
261 }
Add measurement creators that do not rely on a specific hit type, but rather add measurements without...
Add all measurement creators related to BKLM hits.
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
Definition: CDCHit.h:40
Add all measurement creators related to CDC hits.
static void setTranslators(CDC::ADCCountTranslatorBase *const adcCountTranslator, CDC::CDCGeometryTranslatorBase *const cdcGeometryTranslator, CDC::TDCCountTranslatorBase *const tdcCountTranslator, bool useTrackTime=false, bool cosmics=false)
Setter for the Translators.
Definition: CDCRecoHit.cc:33
This class simply assumes a linear translation through (0,0)
This class uses the realistic detector geometry (the one after alignment procedure) for the translati...
Translator mirroring the realistic Digitization.
This dataobject is used only for EKLM alignment.
Add all measurement creators related to EKLM hits.
KLM 2d hit.
Definition: KLMHit2d.h:33
std::vector< std::shared_ptr< BKLMBaseMeasurementCreator > > m_bklmMeasurementCreators
Internal storage of the BKLM measurement creators.
std::vector< std::shared_ptr< CDCBaseMeasurementCreator > > m_cdcMeasurementCreators
Internal storage of the CDC measurement creators.
void createGenfitMeasurementFactory()
Helper function to create a genfit::MeasurementFactory, needed in the MeasurementCreators.
std::vector< std::shared_ptr< PXDBaseMeasurementCreator > > m_pxdMeasurementCreators
Internal storage of the PXD measurement creators.
std::vector< std::shared_ptr< EKLMBaseMeasurementCreator > > m_eklmMeasurementCreators
Internal storage of the EKLM measurement creators.
std::string m_param_storeArrayNameOfPXDHits
The name of the store array for the PXD hits.
std::string m_param_storeArrayNameOfBKLMHits
The name of the store array for the BKLM hits.
void resetMeasurementCreatorsUsingFactories(const std::map< std::string, std::map< std::string, std::string >> &pxdMeasurementCreators, const std::map< std::string, std::map< std::string, std::string >> &svdMeasurementCreators, const std::map< std::string, std::map< std::string, std::string >> &cdcMeasurementCreators, const std::map< std::string, std::map< std::string, std::string >> &bklmMeasurementCreators, const std::map< std::string, std::map< std::string, std::string >> &eklmMeasurementCreators, const std::map< std::string, std::map< std::string, std::string >> &additionalMeasurementCreators)
If you want to use non-default settings for the store arrays, you can create your own instances of th...
MeasurementAdder(const std::string &storeArrayNameOfPXDHits, const std::string &storeArrayNameOfSVDHits, const std::string &storeArrayNameOfCDCHits, const std::string &storeArrayNameOfBKLMHits, const std::string &storeArrayNameOfEKLMHits, const bool initializeCDCTranslators=true)
Create a new instance of the measurement adder.
void resetMeasurementCreators(const std::vector< std::shared_ptr< PXDBaseMeasurementCreator >> &pxdMeasurementCreators, const std::vector< std::shared_ptr< SVDBaseMeasurementCreator >> &svdMeasurementCreators, const std::vector< std::shared_ptr< CDCBaseMeasurementCreator >> &cdcMeasurementCreators, const std::vector< std::shared_ptr< BKLMBaseMeasurementCreator >> &bklmMeasurementCreators, const std::vector< std::shared_ptr< EKLMBaseMeasurementCreator >> &eklmMeasurementCreators, const std::vector< std::shared_ptr< BaseMeasurementCreator >> &additionalMeasurementCreators)
If you want to use non-default settings for the store arrays, you can create your own instances of th...
genfit::MeasurementFactory< genfit::AbsMeasurement > m_genfitMeasurementFactory
Internal storage of the genfit measurement factory;.
void addMeasurementsToRecoTrack(RecoTrack &recoTrack, const std::vector< std::shared_ptr< BaseMeasurementCreator >> &measurementCreators) const
Helper: Go through all measurement creators in the given list and create the measurement without a gi...
void resetMeasurementCreatorsToDefaultSettings()
Reset the internal measurement creator storage to the default settings.
std::string m_param_storeArrayNameOfSVDHits
The name of the store array for the SVD hits.
std::vector< std::shared_ptr< BaseMeasurementCreator > > m_additionalMeasurementCreators
Internal storage of the additional measurement creators.
std::string m_param_storeArrayNameOfEKLMHits
The name of the store array for the EKLM hits.
std::string m_param_storeArrayNameOfCDCHits
The name of the store array for the CDC hits.
bool m_skipDirtyCheck
Flag to skip the dirty check. Useful when using non default measurement creators.
std::vector< std::shared_ptr< SVDBaseMeasurementCreator > > m_svdMeasurementCreators
Internal storage of the SVD measurement creators.
bool addMeasurements(RecoTrack &recoTrack) const
After you have filled the internal storage with measurement creators (either by providing your own or...
const std::vector< std::shared_ptr< BaseMeasurementCreatorType > > & getCreators() const
Return the creators to the module.
void initialize()
Use the parameters given to the module and create the measurement creators from them.
void setParameters(const std::map< std::string, std::map< std::string, std::string >> &creatorsWithParametersDictionary)
Set the parameters.
The PXD Cluster class This class stores all information about reconstructed PXD clusters The position...
Definition: PXDCluster.h:30
Add all measurement creators related to PXD hits.
This class stores additional information to every CDC/SVD/PXD hit stored in a RecoTrack.
static genfit::Track & getGenfitTrack(RecoTrack &recoTrack)
Give access to the RecoTrack's genfit::Track.
Definition: RecoTrack.cc:404
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:79
void mapOnHits(const std::string &storeArrayNameOfHits, std::function< void(RecoHitInformation &, HitType *)> const &mapFunction, std::function< bool(const RecoHitInformation &, const HitType *)> const &pickFunction)
Call a function on all hits of the given type in the store array, that are related to this track.
Definition: RecoTrack.h:766
void setDirtyFlag(const bool &dirtyFlag=true)
Set to true, if you want to rebuild the measurements and do the fit independent on changes of the hit...
Definition: RecoTrack.h:722
const std::string & getStoreArrayNameOfCDCHits() const
Name of the store array of the cdc hits.
Definition: RecoTrack.h:738
const std::string & getStoreArrayNameOfBKLMHits() const
Name of the store array of the bklm hits.
Definition: RecoTrack.h:741
const std::string & getStoreArrayNameOfSVDHits() const
Name of the store array of the svd hits.
Definition: RecoTrack.h:735
bool getDirtyFlag() const
This returns true, if a hit was added after the last fit and measurement creation and a refit should ...
Definition: RecoTrack.h:715
const std::string & getStoreArrayNameOfPXDHits() const
Name of the store array of the pxd hits.
Definition: RecoTrack.h:732
const std::string & getStoreArrayNameOfEKLMHits() const
Name of the store array of the eklm hits.
Definition: RecoTrack.h:744
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition: SVDCluster.h:29
Add all measurement creators related to SVD hits.
bool isOptional(const std::string &name="")
Tell the DataStore about an optional input.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
TClonesArray * getPtr() const
Raw access to the underlying TClonesArray.
Definition: StoreArray.h:311
void addProducer(int detID, AbsMeasurementProducer< measurement_T > *hitProd)
Register a producer module to the factory.
Template class for a measurement producer module.
Object containing AbsMeasurement and AbsFitterInfo objects.
Definition: TrackPoint.h:46
void insertPoint(TrackPoint *point, int id=-1)
Insert TrackPoint BEFORE TrackPoint with position id, if id >= 0.
Definition: Track.cc:375
void deleteTrackPointsAndFitStatus()
Delete all measurement information and the track points of the track. Does not delete track represent...
Definition: Track.cc:1691
CoordinateMeasurementCreator< RecoHitInformation::UsedSVDHit, Const::SVD > SVDCoordinateMeasurementCreator
Hit to reco hit measurement creator for the SVD.
CoordinateMeasurementCreator< RecoHitInformation::UsedPXDHit, Const::PXD > PXDCoordinateMeasurementCreator
Hit to reco hit measurement creator for the PXD.
CoordinateMeasurementCreator< RecoHitInformation::UsedBKLMHit, Const::BKLM > BKLMCoordinateMeasurementCreator
Hit to reco hit measurement creator for the BKLM.
CoordinateMeasurementCreator< RecoHitInformation::UsedCDCHit, Const::CDC > CDCCoordinateMeasurementCreator
Needed for templating.
CoordinateMeasurementCreator< RecoHitInformation::UsedEKLMHit, Const::EKLM > EKLMCoordinateMeasurementCreator
Hit to reco hit measurement creator for the EKLM.
Abstract base class for different kinds of events.