PandaRoot
MeasurementFactory.h
Go to the documentation of this file.
1 /* Copyright 2008-2010, Technische Universitaet Muenchen,
2  Authors: Christian Hoeppner & Sebastian Neubert & Johannes Rauch & Tobias Schlüter
3 
4  This file is part of GENFIT.
5 
6  GENFIT is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published
8  by the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  GENFIT is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with GENFIT. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
24 #ifndef genfit_MeasurementFactory_h
25 #define genfit_MeasurementFactory_h
26 
27 #include "MeasurementProducer.h"
28 #include "TrackCand.h"
29 
30 #include <vector>
31 #include <map>
32 
33 namespace genfit {
34 
35 class AbsMeasurement;
36 
48 template <class measurement_T>
50  private:
51  std::map<int, AbsMeasurementProducer<measurement_T> *> hitProdMap_;
52 
53  public:
55  virtual ~MeasurementFactory() { clear(); }
56 
63  void addProducer(int detID, AbsMeasurementProducer<measurement_T> *hitProd);
64 
67  void clear();
68 
75  measurement_T *createOne(int detID, int index, const TrackCandHit *hit) const;
76 
88  std::vector<measurement_T *> createMany(const TrackCand &cand) const;
89 };
90 
91 template <class measurement_T>
93 {
94  typename std::map<int, AbsMeasurementProducer<measurement_T> *>::iterator it = hitProdMap_.find(detID);
95  if (it == hitProdMap_.end()) {
96  hitProdMap_[detID] = hitProd;
97  } else {
98  Exception exc("MeasurementFactory: detID already in use", __LINE__, __FILE__);
99  exc.setFatal();
100  std::vector<double> numbers;
101  numbers.push_back(detID);
102  exc.setNumbers("detID", numbers);
103  throw exc;
104  }
105 }
106 
107 template <class measurement_T>
109 {
110  typename std::map<int, AbsMeasurementProducer<measurement_T> *>::iterator it = hitProdMap_.begin();
111  while (it != hitProdMap_.end()) {
112  delete it->second;
113  ++it;
114  }
115  hitProdMap_.clear();
116 }
117 
118 template <class measurement_T>
119 measurement_T *MeasurementFactory<measurement_T>::createOne(int detID, int index, const TrackCandHit *hit) const
120 {
121  typename std::map<int, AbsMeasurementProducer<measurement_T> *>::const_iterator it = hitProdMap_.find(detID);
122 
123  if (it != hitProdMap_.end()) {
124  return it->second->produce(index, hit);
125  } else {
126  Exception exc("MeasurementFactory: no hitProducer for this detID available", __LINE__, __FILE__);
127  exc.setFatal();
128  std::vector<double> numbers;
129  numbers.push_back(detID);
130  exc.setNumbers("detID", numbers);
131  throw exc;
132  }
133 }
134 
135 template <class measurement_T>
136 typename std::vector<measurement_T *> MeasurementFactory<measurement_T>::createMany(const TrackCand &cand) const
137 {
138  typename std::vector<measurement_T *> hitVec;
139  unsigned int nHits = cand.getNHits();
140  for (unsigned int i = 0; i < nHits; i++) {
141  int detID, index;
142  const TrackCandHit *hit = cand.getHit(i);
143  cand.getHit(i, detID, index);
144  hitVec.push_back(MeasurementFactory<measurement_T>::createOne(hit->getDetId(), hit->getHitId(), hit));
145  }
146  return hitVec;
147 }
148 
149 } /* End of namespace genfit */
152 #endif // genfit_MeasurementFactory_h
Track candidate – seed values and indices.
Definition: TrackCand.h:68
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:43
TrackCandHit * getHit(int i) const
unsigned int i
Definition: P4_F32vec4.h:21
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:33
unsigned int getNHits() const
Definition: TrackCand.h:99
Exception class for error handling in GENFIT (provides storage for diagnostic information) ...
Definition: Exception.h:47
int getHitId() const
Definition: TrackCandHit.h:44
void setFatal(bool b=true)
Set fatal flag.
Definition: Exception.h:60
std::vector< measurement_T * > createMany(const TrackCand &cand) const
Create a collection of Measurements.
Matrix inversion tools.
Definition: AbsBField.h:28