PandaRoot
MeasurementFactory.h
Go to the documentation of this file.
1 //****************************************************************************
2 //* This file is part of PandaRoot. *
3 //* *
4 //* PandaRoot is distributed under the terms of the *
5 //* GNU General Public License (GPL) version 3, *
6 //* copied verbatim in the file "LICENSE". *
7 //* *
8 //* Copyright (C) 2006 - 2024 FAIR GmbH and copyright holders of PandaRoot *
9 //* The copyright holders are listed in the file "COPYRIGHTHOLDERS". *
10 //* The authors are listed in the file "AUTHORS". *
11 //****************************************************************************
12 
13 /* Copyright 2008-2010, Technische Universitaet Muenchen,
14  Authors: Christian Hoeppner & Sebastian Neubert & Johannes Rauch & Tobias Schlüter
15 
16  This file is part of GENFIT.
17 
18  GENFIT is free software: you can redistribute it and/or modify
19  it under the terms of the GNU Lesser General Public License as published
20  by the Free Software Foundation, either version 3 of the License, or
21  (at your option) any later version.
22 
23  GENFIT is distributed in the hope that it will be useful,
24  but WITHOUT ANY WARRANTY; without even the implied warranty of
25  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  GNU Lesser General Public License for more details.
27 
28  You should have received a copy of the GNU Lesser General Public License
29  along with GENFIT. If not, see <http://www.gnu.org/licenses/>.
30 */
31 
36 #ifndef genfit_MeasurementFactory_h
37 #define genfit_MeasurementFactory_h
38 
39 #include "MeasurementProducer.h"
40 #include "TrackCand.h"
41 
42 #include <vector>
43 #include <map>
44 
45 namespace genfit {
46 
47 class AbsMeasurement;
48 
60 template <class measurement_T>
62  private:
63  std::map<int, AbsMeasurementProducer<measurement_T> *> hitProdMap_;
64 
65  public:
67  virtual ~MeasurementFactory() { clear(); }
68 
75  void addProducer(int detID, AbsMeasurementProducer<measurement_T> *hitProd);
76 
79  void clear();
80 
87  measurement_T *createOne(int detID, int index, const TrackCandHit *hit) const;
88 
100  std::vector<measurement_T *> createMany(const TrackCand &cand) const;
101 };
102 
103 template <class measurement_T>
105 {
106  typename std::map<int, AbsMeasurementProducer<measurement_T> *>::iterator it = hitProdMap_.find(detID);
107  if (it == hitProdMap_.end()) {
108  hitProdMap_[detID] = hitProd;
109  } else {
110  Exception exc("MeasurementFactory: detID already in use", __LINE__, __FILE__);
111  exc.setFatal();
112  std::vector<double> numbers;
113  numbers.push_back(detID);
114  exc.setNumbers("detID", numbers);
115  throw exc;
116  }
117 }
118 
119 template <class measurement_T>
121 {
122  typename std::map<int, AbsMeasurementProducer<measurement_T> *>::iterator it = hitProdMap_.begin();
123  while (it != hitProdMap_.end()) {
124  delete it->second;
125  ++it;
126  }
127  hitProdMap_.clear();
128 }
129 
130 template <class measurement_T>
131 measurement_T *MeasurementFactory<measurement_T>::createOne(int detID, int index, const TrackCandHit *hit) const
132 {
133  typename std::map<int, AbsMeasurementProducer<measurement_T> *>::const_iterator it = hitProdMap_.find(detID);
134 
135  if (it != hitProdMap_.end()) {
136  return it->second->produce(index, hit);
137  } else {
138  Exception exc("MeasurementFactory: no hitProducer for this detID available", __LINE__, __FILE__);
139  exc.setFatal();
140  std::vector<double> numbers;
141  numbers.push_back(detID);
142  exc.setNumbers("detID", numbers);
143  throw exc;
144  }
145 }
146 
147 template <class measurement_T>
148 typename std::vector<measurement_T *> MeasurementFactory<measurement_T>::createMany(const TrackCand &cand) const
149 {
150  typename std::vector<measurement_T *> hitVec;
151  unsigned int nHits = cand.getNHits();
152  for (unsigned int i = 0; i < nHits; i++) {
153  int detID, index;
154  const TrackCandHit *hit = cand.getHit(i);
155  cand.getHit(i, detID, index);
156  hitVec.push_back(MeasurementFactory<measurement_T>::createOne(hit->getDetId(), hit->getHitId(), hit));
157  }
158  return hitVec;
159 }
160 
161 } /* End of namespace genfit */
164 #endif // genfit_MeasurementFactory_h
Track candidate – seed values and indices.
Definition: TrackCand.h:80
void addProducer(int detID, AbsMeasurementProducer< measurement_T > *hitProd)
Register a producer module to the factory.
Factory object to create AbsMeasurement objects from digitized and clustered data.
Abstract interface class for MeasurementProducer.
void clear()
Clear all hit producers.
measurement_T * createOne(int detID, int index, const TrackCandHit *hit) const
Create a Measurement.
int getDetId() const
Definition: TrackCandHit.h:55
TrackCandHit * getHit(int i) const
unsigned int i
Definition: P4_F32vec4.h:33
void setNumbers(std::string, const std::vector< double > &)
Set list of numbers with description.
Hit object for use in TrackCand. Provides IDs and sorting parameters.
Definition: TrackCandHit.h:45
unsigned int getNHits() const
Definition: TrackCand.h:111
Exception class for error handling in GENFIT (provides storage for diagnostic information) ...
Definition: Exception.h:59
int getHitId() const
Definition: TrackCandHit.h:56
void setFatal(bool b=true)
Set fatal flag.
Definition: Exception.h:72
std::vector< measurement_T * > createMany(const TrackCand &cand) const
Create a collection of Measurements.
Matrix inversion tools.
Definition: AbsBField.h:40