#ifndef tutTestHits_hxx_seen #define tutTestHits_hxx_seen #include #include #include #include #include "IG4VHit.hxx" #include "ICOMETEvent.hxx" namespace COMET { class IG4HitContainer; } namespace TestHits { // Events for testing typedef std::vector EventVector; struct HitChecker{ private: EventVector* fEventVector; int fFirstEvent; int fLastEvent; COMET::IG4HitContainer::iterator fLastHit; COMET::IG4HitContainer::iterator fFirstHit; public: HitChecker(): fEventVector(NULL), fFirstEvent(0), fLastEvent(0) {}; HitChecker(EventVector& eventVector, int firstEvent, int lastEvent): fEventVector(&eventVector), fFirstEvent(firstEvent), fLastEvent(lastEvent) {}; class const_iterator { public: const_iterator( const HitChecker* checkHit, const EventVector::iterator evtIter, const COMET::IDataVector::iterator hitConIter, const COMET::IG4HitContainer::iterator hitIter, COMET::IG4VHit* currentHit): fEventIt(evtIter), fEventEnd(checkHit->fEventVector->begin() + checkHit->fLastEvent), fHitConIt(hitConIter), fHitIt(hitIter), fCurrent(currentHit) {} const COMET::IG4VHit& operator*() const {return *fCurrent;} const COMET::IG4VHit* operator->() const {return fCurrent;} const COMET::IG4VHit* operator&() const {return fCurrent;} bool operator==(const const_iterator &rhs) const { return (fHitIt == rhs.fHitIt); } bool operator!=(const const_iterator &rhs) const { return !((*this) == rhs); } const_iterator& operator++(); const_iterator operator++(int) { const_iterator tmp(*this); ++(*this); return tmp; } private: EventVector::iterator fEventIt; EventVector::iterator fEventEnd; COMET::IDataVector::iterator fHitConIt; COMET::IG4HitContainer::iterator fHitIt; COMET::IG4VHit* fCurrent; }; const_iterator begin()const{ EventVector::iterator beginEvent = fEventVector->begin() + fFirstEvent; COMET::IDataVector::iterator beginHitCon = (*beginEvent)->Get("truth/g4Hits")->begin(); COMET::IG4HitContainer::iterator beginHit = (*beginHitCon)->Get(".")->begin(); COMET::IG4VHit* currentHit = *beginHit; return const_iterator(this, beginEvent, beginHitCon, beginHit, currentHit);} const_iterator end()const{ if(fEventVector->empty()) return begin(); EventVector::iterator endEvent = fEventVector->begin() + fLastEvent; --endEvent; if (!(*endEvent)->Get("truth/g4Hits")->size()){ COMETError("truth/g4Hits is empty!"); return begin(); } COMET::IDataVector::iterator endHitCon = (*endEvent)->Get("truth/g4Hits")->end(); --endHitCon; COMET::IG4HitContainer::iterator endHit = (*endHitCon)->Get(".")->end(); COMET::IG4VHit* currentHit = *endHit; return const_iterator(this, ++endEvent, ++endHitCon, endHit, currentHit);} }; template int CountHitContainers (int begin, int end, EventVector& someEvents) { // Initialize return value int eventsWithHitsT = 0; // Choose begining and end points EventVector::iterator beginSample = someEvents.begin() + begin; EventVector::iterator endSample = someEvents.begin() + end; for (EventVector::iterator e = beginSample; e != endSample; ++e){ bool goodEvent = false; COMET::IHandle dv=(*e)->Get("truth/g4Hits"); for (COMET::IDataVector::iterator d = dv->begin(); d != dv->end(); ++d) { COMET::IHandle hitCon = (*d)->Get("."); for (COMET::IG4HitContainer::iterator h = hitCon->begin(); h != hitCon->end(); ++h) { const T* hit = dynamic_cast(*h); // If this is not empty, its a good event if (hit && !goodEvent) goodEvent = true; } } eventsWithHitsT += goodEvent; } return eventsWithHitsT; } } #endif