Class Reference for E1039 Core & Analysis Software
UtilTrigger.cc
Go to the documentation of this file.
1 #include <cmath>
2 #include <geom_svc/GeomSvc.h>
4 #include "UtilSQHit.h"
5 #include "TrigRoadset.h"
6 using namespace std;
7 namespace UtilTrigger {
8 
10 
13 int Hodo2Road(const int h1, const int h2, const int h3, const int h4, const int tb)
14 {
15  if (h1 * h2 * h3 * h4 * tb == 0) return 0; // if any is 0.
16  int road = (h1-1)*16*16*16 + (h2-1)*16*16 + (h3-1)*16 + h4;
17  return (tb > 0 ? +1 : -1) * road;
18 }
19 
21 void Road2Hodo(const int road, int& h1, int& h2, int& h3, int& h4, int& tb)
22 {
23  if (road == 0) {
24  h1 = h2 = h3 = h4 = tb = 0;
25  return;
26  }
27  int rr = abs(road) - 1;
28  h1 = 1 + (rr/16/16/16);
29  h2 = 1 + (rr/16/16 ) %16;
30  h3 = 1 + (rr/16 ) %16;
31  h4 = 1 + (rr ) %16;
32  tb = road>0 ? +1 : -1;
33 }
34 
36 int FlipRoadLeftRight(const int road)
37 {
38  int h1, h2, h3, h4, tb;
39  Road2Hodo(road, h1, h2, h3, h4, tb);
40  h1 = 24 - h1; // 1 <-> 23, 2 <-> 22,,,
41  h2 = 17 - h2; // 1 <-> 16, 2 <-> 15,,,
42  h3 = 17 - h3;
43  h4 = 17 - h4;
44  return Hodo2Road(h1, h2, h3, h4, tb);
45 }
46 
48 int FlipRoadTopBottom(const int road)
49 {
50  int h1, h2, h3, h4, tb;
51  Road2Hodo(road, h1, h2, h3, h4, tb);
52  return Hodo2Road(h1, h2, h3, h4, -tb);
53 }
54 
56 
62 int ExtractRoadID(const SQHitVector* vec)
63 {
64  int tb = 0; // +1 for top, -1 for bottom
65  int list_ele_id[5]; // index = station
66  memset(list_ele_id, 0, sizeof(list_ele_id));
67  for (SQHitVector::ConstIter it = vec->begin(); it != vec->end(); it++) {
68  SQHit* hit = *it;
69  string name = GeomSvc::instance()->getDetectorName( hit->get_detector_id() );
70  if (name[0] != 'H') continue; // Skip non-hodoscope plane
71  if (name[2] == 'T') {
72  if (tb < 0) return 0; // Bad as top-bottom mixed up
73  tb = +1;
74  } else if (name[2] == 'B') {
75  if (tb > 0) return 0; // Bad as top-bottom mixed up
76  tb = -1;
77  } else {
78  continue; // Skip non-X plane
79  }
80  int station = (name[1] - '0');
81  if (list_ele_id[station] != 0) return 0; // Bad as multiple hits per station
82  list_ele_id[station] = hit->get_element_id();
83  }
84  return Hodo2Road(list_ele_id[1], list_ele_id[2], list_ele_id[3], list_ele_id[4], tb);
85 }
86 
88 
101 void FindFiredRoads(const SQHitVector* vec, const TrigRoadset* rs, const bool in_time, std::vector<int>* pos_top, std::vector<int>* pos_bot, std::vector<int>* neg_top, std::vector<int>* neg_bot)
102 {
103  pos_top->clear();
104  neg_top->clear();
105  shared_ptr<SQHitVector> hv_h1t(UtilSQHit::FindFirstHits(vec, "H1T", in_time));
106  shared_ptr<SQHitVector> hv_h2t(UtilSQHit::FindFirstHits(vec, "H2T", in_time));
107  shared_ptr<SQHitVector> hv_h3t(UtilSQHit::FindFirstHits(vec, "H3T", in_time));
108  shared_ptr<SQHitVector> hv_h4t(UtilSQHit::FindFirstHits(vec, "H4T", in_time));
109  for (auto it1 = hv_h1t->begin(); it1 != hv_h1t->end(); it1++) {
110  for (auto it2 = hv_h2t->begin(); it2 != hv_h2t->end(); it2++) {
111  for (auto it3 = hv_h3t->begin(); it3 != hv_h3t->end(); it3++) {
112  for (auto it4 = hv_h4t->begin(); it4 != hv_h4t->end(); it4++) {
113  int road = Hodo2Road(
114  (*it1)->get_element_id(),
115  (*it2)->get_element_id(),
116  (*it3)->get_element_id(),
117  (*it4)->get_element_id(), +1);
118  if (rs->PosTop()->FindRoad(road)) pos_top->push_back(road);
119  if (rs->NegTop()->FindRoad(road)) neg_top->push_back(road);
120  }
121  }
122  }
123  }
124  pos_top->erase(std::unique(pos_top->begin(), pos_top->end()), pos_top->end());
125  neg_top->erase(std::unique(neg_top->begin(), neg_top->end()), neg_top->end());
126 
127  pos_bot->clear();
128  neg_bot->clear();
129  shared_ptr<SQHitVector> hv_h1b(UtilSQHit::FindHits(vec, "H1B", in_time));
130  shared_ptr<SQHitVector> hv_h2b(UtilSQHit::FindHits(vec, "H2B", in_time));
131  shared_ptr<SQHitVector> hv_h3b(UtilSQHit::FindHits(vec, "H3B", in_time));
132  shared_ptr<SQHitVector> hv_h4b(UtilSQHit::FindHits(vec, "H4B", in_time));
133  for (auto it1 = hv_h1b->begin(); it1 != hv_h1b->end(); it1++) {
134  for (auto it2 = hv_h2b->begin(); it2 != hv_h2b->end(); it2++) {
135  for (auto it3 = hv_h3b->begin(); it3 != hv_h3b->end(); it3++) {
136  for (auto it4 = hv_h4b->begin(); it4 != hv_h4b->end(); it4++) {
137  int road = UtilTrigger::Hodo2Road(
138  (*it1)->get_element_id(),
139  (*it2)->get_element_id(),
140  (*it3)->get_element_id(),
141  (*it4)->get_element_id(), -1);
142  if (rs->PosBot()->FindRoad(road)) pos_bot->push_back(road);
143  if (rs->NegBot()->FindRoad(road)) neg_bot->push_back(road);
144  }
145  }
146  }
147  }
148  pos_bot->erase(std::unique(pos_bot->begin(), pos_bot->end()), pos_bot->end());
149  neg_bot->erase(std::unique(neg_bot->begin(), neg_bot->end()), neg_bot->end());
150 }
151 
152 }; // End of "namespace UtilTrigger"
static GeomSvc * instance()
singlton instance
Definition: GeomSvc.cxx:212
std::string getDetectorName(const int &detectorID) const
Definition: GeomSvc.h:223
An SQ interface class to hold a list of SQHit objects.
Definition: SQHitVector.h:32
std::vector< SQHit * >::const_iterator ConstIter
Definition: SQHitVector.h:37
virtual ConstIter end() const =0
virtual ConstIter begin() const =0
An SQ interface class to hold one detector hit.
Definition: SQHit.h:20
virtual short get_element_id() const
Return the element ID of this hit.
Definition: SQHit.h:45
virtual short get_detector_id() const
Return the detector ID of this hit.
Definition: SQHit.h:42
Class to handle the trigger roadset.
Definition: TrigRoadset.h:34
Definition: rs_Reader.h:9
SQHitVector * FindFirstHits(const SQHitVector *vec_in, const std::string det_name, const bool in_time=false)
Extract a set of first hits that are of the given detector (det_name), where "first" means the earlie...
Definition: UtilSQHit.cc:40
SQHitVector * FindHits(const SQHitVector *vec_in, const std::string det_name, const bool in_time=false)
Extract a set of hits that are of the given detector (det_name).
Definition: UtilSQHit.cc:16
int FlipRoadLeftRight(const int road)
Flip the given road ID in the left-right direction.
Definition: UtilTrigger.cc:36
void Road2Hodo(const int road, int &h1, int &h2, int &h3, int &h4, int &tb)
Convert a roadset ID to a set of hodo IDs.
Definition: UtilTrigger.cc:21
void FindFiredRoads(const SQHitVector *vec, const TrigRoadset *rs, const bool in_time, std::vector< int > *pos_top, std::vector< int > *pos_bot, std::vector< int > *neg_top, std::vector< int > *neg_bot)
Find all fired roads enabled in rs, by taking all hit combinations from vec.
Definition: UtilTrigger.cc:101
int Hodo2Road(const int h1, const int h2, const int h3, const int h4, const int tb)
Convert a set of hodo IDs to a roadset ID.
Definition: UtilTrigger.cc:13
int FlipRoadTopBottom(const int road)
Flip the given road ID in the top-bottom direction.
Definition: UtilTrigger.cc:48
int ExtractRoadID(const SQHitVector *vec)
Find a unique road in the given list of SQHits.
Definition: UtilTrigger.cc:62