Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:18:21

0001 /* Copyright 2008-2010, Technische Universitaet Muenchen,
0002    Authors: Christian Hoeppner & Sebastian Neubert & Johannes Rauch & Tobias Schlüter
0003 
0004    This file is part of GENFIT.
0005 
0006    GENFIT is free software: you can redistribute it and/or modify
0007    it under the terms of the GNU Lesser General Public License as published
0008    by the Free Software Foundation, either version 3 of the License, or
0009    (at your option) any later version.
0010 
0011    GENFIT is distributed in the hope that it will be useful,
0012    but WITHOUT ANY WARRANTY; without even the implied warranty of
0013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014    GNU Lesser General Public License for more details.
0015 
0016    You should have received a copy of the GNU Lesser General Public License
0017    along with GENFIT.  If not, see <http://www.gnu.org/licenses/>.
0018 */
0019 
0020 /** @addtogroup genfit
0021  * @{
0022  */
0023 
0024 
0025 #ifndef genfit_MeasurementFactory_h
0026 #define genfit_MeasurementFactory_h
0027 
0028 #include "MeasurementProducer.h"
0029 #include "TrackCand.h"
0030 
0031 #include <vector>
0032 #include <map>
0033 
0034 
0035 namespace genfit {
0036 
0037 class AbsMeasurement;
0038 
0039 /** @brief Factory object to create AbsMeasurement objects from digitized and clustered data
0040  *
0041  * The MeasurementFactory is used to automatically fill Track objects
0042  * with hit data. For each detector type used an
0043  * AbsMeasurementProducer has to be registered in the factory. The
0044  * factory can then use the index information from a TrackCand object
0045  * to load the indexed hits into the Track.
0046  *
0047  * @sa AbsMeasurementProducer
0048  * @sa TrackCand
0049  */
0050 template <class measurement_T>
0051 class MeasurementFactory {
0052  private:
0053   std::map<int, AbsMeasurementProducer<measurement_T>*> hitProdMap_;
0054 
0055 
0056  public:
0057   MeasurementFactory() {};
0058   virtual ~MeasurementFactory() { clear(); }
0059 
0060   /** @brief Register a producer module to the factory
0061    *
0062    * For each type of hit a separate producer is needed. The type of hit
0063    * is identified by the detector ID (detID). This index corresponds to the
0064    * detector ID that is stored in the TrackCand.
0065    */
0066   void addProducer(int detID, AbsMeasurementProducer<measurement_T>* hitProd);
0067 
0068   /** @brief Clear all hit producers
0069    */
0070   void clear();
0071 
0072   /** @brief Create a Measurement
0073    *
0074    * Measurements have to implement a Constructor which takes the cluster object
0075    * from which the Measurement is built as the only parameter.
0076    * @sa AbsMeasurementProducer
0077    */
0078   measurement_T* createOne (int detID, int index, const TrackCandHit* hit) const;
0079 
0080   /** @brief Create a collection of Measurements
0081    *
0082    * This is the standard way to prepare the hit collection for a Track. The
0083    * resulting collection can contain hits from several detectors. The order
0084    * of the hits is the same as in the TrackCand. It is assumed that this order
0085    * is already along the Track.
0086    *
0087    * Measurements have to implement a constructor which takes the cluster object
0088    * from which the Measurement is built as the only parameter.
0089    * @sa AbsMeasurementProducer
0090    */
0091   std::vector<measurement_T*> createMany(const TrackCand& cand) const;
0092 
0093 };
0094 
0095 
0096 template <class measurement_T>
0097 void MeasurementFactory<measurement_T>::addProducer(int detID, AbsMeasurementProducer<measurement_T>* hitProd) {
0098   typename std::map<int, AbsMeasurementProducer<measurement_T>*>::iterator it = hitProdMap_.find(detID);
0099   if(it == hitProdMap_.end()) {
0100     hitProdMap_[detID] = hitProd;
0101   } else {
0102     Exception exc("MeasurementFactory: detID already in use",__LINE__,__FILE__);
0103     exc.setFatal();
0104     std::vector<double> numbers;
0105     numbers.push_back(detID);
0106     exc.setNumbers("detID",numbers);
0107     throw exc;
0108   }
0109 }
0110 
0111 template <class measurement_T>
0112 void MeasurementFactory<measurement_T>::clear(){
0113   typename std::map<int, AbsMeasurementProducer<measurement_T>*>::iterator it=hitProdMap_.begin();
0114   while(it!=hitProdMap_.end()){
0115     delete it->second;
0116     ++it;
0117   }
0118   hitProdMap_.clear();
0119 }
0120 
0121 template <class measurement_T>
0122 measurement_T* MeasurementFactory<measurement_T>::createOne(int detID, int index, const TrackCandHit* hit) const {
0123   typename std::map<int, AbsMeasurementProducer<measurement_T>*>::const_iterator it = hitProdMap_.find(detID);
0124 
0125   if(it != hitProdMap_.end()) {
0126     return it->second->produce(index, hit);
0127   } else {
0128     Exception exc("MeasurementFactory: no hitProducer for this detID available",__LINE__,__FILE__);
0129     exc.setFatal();
0130     std::vector<double> numbers;
0131     numbers.push_back(detID);
0132     exc.setNumbers("detID", numbers);
0133     throw exc;
0134   }
0135 }
0136 
0137 template <class measurement_T>
0138 typename std::vector<measurement_T*> MeasurementFactory<measurement_T>::createMany(const TrackCand& cand) const {
0139   typename std::vector<measurement_T*> hitVec;
0140   unsigned int nHits=cand.getNHits();
0141   for(unsigned int i=0;i<nHits;i++) {
0142     int detID, index;
0143     const TrackCandHit* hit = cand.getHit(i);
0144     cand.getHit(i, detID, index);
0145     hitVec.push_back( MeasurementFactory<measurement_T>::createOne(hit->getDetId(), hit->getHitId(), hit) );
0146   }
0147   return hitVec;
0148 }
0149 
0150 
0151 } /* End of namespace genfit */
0152 /** @} */
0153 
0154 #endif // genfit_MeasurementFactory_h