Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UtilSQHit.cc
Go to the documentation of this file.
1 #include <iomanip>
2 #include <geom_svc/GeomSvc.h>
4 #include "UtilSQHit.h"
5 using namespace std;
6 
15 SQHitVector* UtilSQHit::FindHits(const SQHitVector* vec_in, const std::string det_name)
16 {
17  GeomSvc* geom = GeomSvc::instance();
18  return FindHits(vec_in, geom->getDetectorID(det_name));
19 }
20 
24 SQHitVector* UtilSQHit::FindHits(const SQHitVector* vec_in, const int det_id)
25 {
26  SQHitVector* vec = vec_in->Clone();
27  vec->clear();
28  for (SQHitVector::ConstIter it = vec_in->begin(); it != vec_in->end(); it++) {
29  SQHit* hit = *it;
30  if (hit->get_detector_id() == det_id) vec->push_back(hit);
31  }
32  return vec;
33 }
34 
38 SQHitVector* UtilSQHit::FindFirstHits(const SQHitVector* vec_in, const std::string det_name)
39 {
40  GeomSvc* geom = GeomSvc::instance();
41  return FindFirstHits(vec_in, geom->getDetectorID(det_name));
42 }
43 
47 SQHitVector* UtilSQHit::FindFirstHits(const SQHitVector* vec_in, const int det_id)
48 {
49  map<int, double> id2time; // [element ID] = first (max) tdcTime;
50  map<int, int > id2idx ; // [element ID] = index of vec_in
51  for (unsigned int idx = 0; idx < vec_in->size(); idx++) {
52  const SQHit* hit = vec_in->at(idx);
53  if (hit->get_detector_id() != det_id) continue;
54  short ele_id = hit->get_element_id();
55  double time = hit->get_tdc_time();
56  if (id2time.find(ele_id) == id2time.end() || time > id2time[ele_id]) {
57  id2time[ele_id] = time;
58  id2idx [ele_id] = idx;
59  }
60  }
61 
62  SQHitVector* vec = vec_in->Clone();
63  vec->clear();
64  for (map<int, int>::iterator it = id2idx.begin(); it != id2idx.end(); it++) {
65  vec->push_back(vec_in->at(it->second));
66  }
67  return vec;
68 }
virtual void clear()
Definition: SQHitVector.h:51
std::vector< SQHit * >::const_iterator ConstIter
Definition: SQHitVector.h:37
An SQ interface class to hold one detector hit.
Definition: SQHit.h:20
virtual ConstIter end() const
Definition: SQHitVector.h:59
virtual SQHitVector * Clone() const
Definition: SQHitVector.h:47
virtual const SQHit * at(const size_t idkey) const
Definition: SQHitVector.h:53
virtual short get_detector_id() const
Return the detector ID of this hit.
Definition: SQHit.h:42
virtual void push_back(const SQHit *hit)
Definition: SQHitVector.h:55
virtual float get_tdc_time() const
Return the TDC time (nsec) of this hit.
Definition: SQHit.h:54
An SQ interface class to hold a list of SQHit objects.
Definition: SQHitVector.h:32
static GeomSvc * instance()
singlton instance
Definition: GeomSvc.cxx:211
virtual size_t size() const
Definition: SQHitVector.h:50
SQHitVector * FindFirstHits(const SQHitVector *vec_in, const std::string det_name)
Extract a set of first hits that are of the given detector (det_name), where &quot;first&quot; means the earlie...
Definition: UtilSQHit.cc:38
int getDetectorID(const std::string &detectorName) const
Get the plane position.
Definition: GeomSvc.h:184
virtual short get_element_id() const
Return the element ID of this hit.
Definition: SQHit.h:45
virtual ConstIter begin() const
Definition: SQHitVector.h:58
SQHitVector * FindHits(const SQHitVector *vec_in, const std::string det_name)
Extract a set of hits that are of the given detector (det_name).
Definition: UtilSQHit.cc:15