Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DTAGMHit_factory.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DTAGMHit_factory.cc
4 // Created: Sat Aug 2 12:23:43 EDT 2014
5 // Creator: jonesrt (on Linux gluex.phys.uconn.edu)
6 //
7 
8 // aebarnes moved original factory to DTAGMHit_factory_Calib.cc on August 11, 2016.
9 
10 #include <iostream>
11 #include <iomanip>
12 #include <TAGGER/DTAGMHit.h>
13 using namespace std;
14 
15 // Sort by column
16 bool SortByCol(const DTAGMHit* a, const DTAGMHit* b)
17 {
18  if (a->column == b->column) return a->t < b->t;
19  return a->column < b->column;
20 }
21 
22 #include "DTAGMHit_factory.h"
23 
24 using namespace jana;
25 
26 //------------------
27 // init
28 //------------------
29 jerror_t DTAGMHit_factory::init(void)
30 {
31  // Set default configuration parameters
32  DELTA_T_CLUSTER_MAX = 5;
33  gPARMS->SetDefaultParameter("TAGMHit:DELTA_T_CLUSTER_MAX",DELTA_T_CLUSTER_MAX,
34  "Maximum time difference in ns between hits in adjacent"
35  " columns to be merged");
36 
37  MERGE_HITS = true;
38  gPARMS->SetDefaultParameter("TAGMHit:MERGE_HITS",MERGE_HITS,
39  "Merge neighboring hits when true");
40 
41  // Setting this flag makes it so that JANA does not delete the objects in _data.
42  // This factory will manage this memory.
43  SetFactoryFlag(NOT_OBJECT_OWNER);
44 
45  return NOERROR;
46 }
47 
48 //------------------
49 // brun
50 //------------------
51 jerror_t DTAGMHit_factory::brun(jana::JEventLoop *eventLoop, int32_t runnumber)
52 {
53  return NOERROR;
54 }
55 
56 //------------------
57 // evnt
58 //------------------
59 jerror_t DTAGMHit_factory::evnt(JEventLoop *loop, uint64_t eventnumber)
60 {
61  // Clear _data vector
62  Reset_Data();
63 
64  // Get (calibrated) TAGM hits
65  vector<const DTAGMHit*> hits;
66  loop->Get(hits, "Calib");
67 
68  sort(hits.begin(), hits.end(), SortByCol);
69 
70  set<uint32_t> locHitIndexUsedSoFar;
71 
72  for(uint32_t i = 0; i < hits.size(); ++i)
73  {
74  const DTAGMHit *hit_i = hits[i];
75 
76  if (hit_i->row > 0 || !MERGE_HITS)
77  {
78  _data.push_back(const_cast<DTAGMHit*>(hit_i));
79  continue;
80  }
81  if (!hit_i->has_fADC) continue;
82 
83  // check if column has been paired
84  if (locHitIndexUsedSoFar.find(i) != locHitIndexUsedSoFar.end()) continue;
85 
86  for (uint32_t j = i+1; j < hits.size(); ++j)
87  {
88  const DTAGMHit *hit_j = hits[j];
89 
90  if (!hit_j->has_fADC) continue;
91  if (hit_j->row > 0) continue;
92 
93  int colDiff = hit_i->column - hit_j->column;
94  double deltaT = hit_i->t - hit_j->t;
95 
96  if (abs(colDiff) == 1 && fabs(deltaT) <= DELTA_T_CLUSTER_MAX)
97  {
98  locHitIndexUsedSoFar.insert(j);
99  break;
100  }
101  }
102  _data.push_back(const_cast<DTAGMHit*>(hit_i));
103  }
104 
105 
106  return NOERROR;
107 }
108 
109 //------------------
110 // Reset_Data()
111 //------------------
113 {
114  // Clear _data vector
115  _data.clear();
116 }
117 
118 //------------------
119 // erun
120 //------------------
122 {
123  return NOERROR;
124 }
125 
126 //------------------
127 // fini
128 //------------------
130 {
131  return NOERROR;
132 }
jerror_t erun(void)
Called everytime run number changes, if brun has been called.
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
int row
Definition: DTAGMHit.h:20
bool SortByCol(const DTAGMHit *a, const DTAGMHit *b)
double t
Definition: DTAGMHit.h:19
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
bool has_fADC
Definition: DTAGMHit.h:27
jerror_t init(void)
Called once at program start.
jerror_t fini(void)
Called after last event of last event source has been processed.
int column
Definition: DTAGMHit.h:21