/** @addtogroup genfit * @{ */ /** * @author Christian Höppner (Technische Universität München, original author) * @author Sebastian Neubert (Technische Universität München, original author) * */ #ifndef RECOHITPRODUCER_H #define RECOHITPRODUCER_H #include #include #include #include #include "TClonesArray.h" #include "FitterExceptions.h" class AbsRecoHit; /** @brief Abstract interface class for RecoHitProducer * * Defines the very basic interface of a producer. */ class AbsRecoHitProducer { public: /** @brief Virtual abstract method to produce a RecoHit. * Implemented in RecoHitProducer */ virtual AbsRecoHit* produce(int index)=0; virtual ~AbsRecoHitProducer(); }; /** @brief Template class for a hit producer module * * A RecoHitProducer module is used by RecoHitFactory to create RecoHits for * one specific detector type. * * It is assumed that each detector has as output of its digitization / * clustering some sort of cluster class which stores all information that * corresponds to a measured hit in that detector. The RecoHit producer * converts this information into a class that can be handled by genfit. * This class is realized as a RecoHit (a class inherting from AbsRecoHit). * * In order to use the RecoHitProducer facility a * RecoHit has to implement a constructor which takes as an argument * a pointer to the cluster class. This constructor serves as the initializing * constructor for the RecoHit. * * The RecoHitProducer will fetch the cluster objects from a TClonesArray and * use the initializing constructor to build the corresponding RecoHit. * * @param hit_t template parameter specifying cluster class * @param recoHit_t template parameter specifying recoHit */ template class RecoHitProducer : public AbsRecoHitProducer { private: /** @brief pointer to array with cluster data */ TClonesArray* hitArrayTClones; std::vector* hitArrayVector; public: /** @brief Constructor takes pointer to the cluster array */ RecoHitProducer(TClonesArray*); RecoHitProducer(std::vector*); virtual ~RecoHitProducer(); /** @brief Create a RecoHit from the cluster at position index * in TClonesArray */ virtual AbsRecoHit* produce(int index); }; /** @} */ template RecoHitProducer::RecoHitProducer(TClonesArray* theArr) { hitArrayTClones = theArr; hitArrayVector = NULL; } template RecoHitProducer::RecoHitProducer(std::vector* theArr) { hitArrayTClones = NULL; hitArrayVector = theArr; } template RecoHitProducer::~RecoHitProducer() { //we dont assume ownership over the hit arrays } template AbsRecoHit* RecoHitProducer::produce(int index) { assert(hitArrayTClones!=NULL || hitArrayVector!=NULL);//at least one exists assert(!(hitArrayTClones!=NULL && hitArrayVector!=NULL));//but not both if(hitArrayTClones!=NULL){ //the ROOT guys really use 0 and not NULL grrr... if(hitArrayTClones->At(index) == 0) { FitterException e("In RecoHitProducer: index for hit in TClonesArray out of bounds",__LINE__,__FILE__); e.setFatal(); throw e; } return ( new recoHit_T( (hit_T*) hitArrayTClones->At(index) ) ); } else{//after assertions this is save: the hitArrayVector is good if(index >= hitArrayVector->size()) { FitterException e("In RecoHitProducer: index for hit in std::vector out of bounds",__LINE__,__FILE__); e.setFatal(); throw e; } return ( new recoHit_T( (hit_T*) hitArrayVector->at(index) ) ); } } #endif