Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DFDCCathodeCluster_factory.cc
Go to the documentation of this file.
1 //******************************************************************************
2 // DFDCCathodeCluster_factory.cc
3 //
4 // Author: Craig Bookwalter (craigb at jlab.org)
5 // Date: April 2006
6 //
7 //******************************************************************************
8 
10 
11 bool DFDCHit_cmp(const DFDCHit* a, const DFDCHit* b) {
12  if (a->gLayer==b->gLayer){
13  return a->t < b->t;
14  }
15  return a->gLayer < b->gLayer;
16 }
17 
18 
19 ///
20 /// DFDCHit_gLayer_cmp():
21 /// a non-member function passed to std::sort() for sorting DFDCHit pointers by
22 /// their gLayer attributes.
23 ///
24 bool DFDCHit_gLayer_cmp(const DFDCHit* a, const DFDCHit* b) {
25  return a->gLayer < b->gLayer;
26 }
27 
28 ///
29 /// DFDCHit_element_cmp():
30 /// a non-member function passed to std::sort() for sorting DFDCHit pointers by
31 /// their element (wire or strip) numbers. Typically only used for a single layer
32 /// of hits.
33 ///
34 bool DFDCHit_element_cmp(const DFDCHit* a, const DFDCHit* b) {
35  if(a->element != b->element) return a->element < b->element;
36  if(a->t != b->t ) return a->t < b->t;
37  return a->q < b->q;
38 }
39 
40 ///
41 /// DFDCHit_time_cmp()
42 /// a non-member function passed to std::stable_sort() for sorting DFDCHit
43 /// pointers in order of increasing time, provided that the time difference is
44 /// significant.
45 ///
46 
47 bool DFDCHit_time_cmp(const DFDCHit* a, const DFDCHit* b) {
48  if (fabs(a->t-b->t)>HIT_TIME_DIFF_MIN && (a->t < b->t))
49  return true;
50  return false;
51 }
52 
53 ///
54 /// DFDCCathodeCluster_gPlane_cmp():
55 /// a non-member function passed to std::sort() for sorting DFDCCathodeCluster pointers
56 /// by their gPlane (plane number over all modules, 1-74) attributes.
57 ///
59  const DFDCCathodeCluster* b) {
60  return a->gPlane < b->gPlane;
61 }
62 
63 ///
64 /// DFDCCathodeCluster_factory::DFDCCathodeCluster_factory():
65 /// default constructor--initializes log file
66 ///
68  _log = new JStreamLog(std::cout, "DFDCCathodeCluster >>");
69 }
70 
71 ///
72 /// DFDCCathodeCluster_factory::~DFDCCathodeCluster_factory():
73 /// default destructor--closes log file.
74 ///
76  delete _log;
77 }
78 
79 ///
80 /// Initialization
81 ///
83  TIME_SLICE=100.0; //ns, Changed from 10->100 4/7/16 SJT
84  gPARMS->SetDefaultParameter("FDC:CLUSTER_TIME_SLICE",TIME_SLICE);
85  return NOERROR;
86 }
87 
88 ///
89 /// DFDCCathodeCluster_factory::evnt():
90 /// This (along with DFDCCathodeCluster_factory::pique())
91 /// is the place cathode hits are associated into cathode clusters.
92 ///
93 jerror_t DFDCCathodeCluster_factory::evnt(JEventLoop *eventLoop, uint64_t eventNo) {
94  vector<const DFDCHit*> allHits;
95  vector<const DFDCHit*> uHits;
96  vector<const DFDCHit*> vHits;
97  vector<vector<const DFDCHit*> >thisLayer;
98 
99  try {
100  eventLoop->Get(allHits);
101 
102  if (allHits.size()>0) {
103  // Sort hits by layer number and by time
104  sort(allHits.begin(),allHits.end(),DFDCHit_cmp);
105 
106  // Sift through all hits and select out U and V hits.
107  for (vector<const DFDCHit*>::iterator i = allHits.begin();
108  i != allHits.end(); ++i){
109  if ((*i)->type) {
110  if ((*i)->plane == 1)
111  vHits.push_back(*i);
112  else
113  uHits.push_back(*i);
114  }
115  }
116 
117  // Layer by layer, create clusters of U hits.
118  if (uHits.size()>0){
119  thisLayer.clear();
120  vector<const DFDCHit*>::iterator i = uHits.begin();
121  for (int iLayer=1;iLayer<25;iLayer++){
122  if (i==uHits.end()) break;
123 
124  vector<const DFDCHit*> hits;
125  float old_time=(*i)->t;
126  while((i!=uHits.end()) && ((*i)->gLayer == iLayer)){
127  // Look for hits falling within a time slice
128  if (fabs((*i)->t-old_time)>TIME_SLICE){
129  // Sort hits by element number
130  sort(hits.begin(),hits.end(),DFDCHit_element_cmp);
131  // put into the vector
132  thisLayer.push_back(hits);
133  hits.clear();
134  old_time=(*i)->t;
135  }
136  hits.push_back(*i);
137 
138  i++;
139  }
140  // Sort hits by element number
141  sort(hits.begin(),hits.end(),DFDCHit_element_cmp);
142  // add the last vector of hits
143  thisLayer.push_back(hits);
144 
145  // Create clusters from these lists of hits
146  for (unsigned int k=0;k<thisLayer.size();k++) pique(thisLayer[k]);
147 
148  // Clear the hits and layer vectors for the next ones
149  thisLayer.clear();
150  hits.clear();
151  }
152  }
153 
154  // Layer by layer, create clusters of V hits.
155  if (vHits.size()>0){
156  thisLayer.clear();
157  vector<const DFDCHit*>::iterator i = vHits.begin();
158  for (int iLayer=1;iLayer<25;iLayer++){
159  if (i==vHits.end()) break;
160 
161  vector<const DFDCHit*> hits;
162  float old_time=(*i)->t;
163  while((i!=vHits.end()) && ((*i)->gLayer == iLayer)){
164  // Look for hits falling within a time slice
165  if (fabs((*i)->t-old_time)>TIME_SLICE){
166  // Sort hits by element number
167  sort(hits.begin(),hits.end(),DFDCHit_element_cmp);
168  // put into the vector
169  thisLayer.push_back(hits);
170  hits.clear();
171  old_time=(*i)->t;
172  }
173  hits.push_back(*i);
174 
175  i++;
176  }
177  // Sort hits by element number
178  sort(hits.begin(),hits.end(),DFDCHit_element_cmp);
179  // add the last vector of hits
180  thisLayer.push_back(hits);
181 
182  // Create clusters from these lists of hits
183  for (unsigned int k=0;k<thisLayer.size();k++) pique(thisLayer[k]);
184 
185  // Clear the hits and layer vectors for the next ones
186  thisLayer.clear();
187  hits.clear();
188  }
189  }
190 
191  // Ensure that the data are still in order of Z position.
192  std::sort(_data.begin(), _data.end(), DFDCCathodeCluster_gPlane_cmp);
193  }
194  }
195  catch (JException d) {
196  cout << d << endl;
197  }
198  catch (...) {
199  cerr << "exception caught in DFDCCathodeCluster_factory" << endl;
200  }
201 
202  return NOERROR;
203 }
204 
205 //-----------------------------
206 // pique
207 //-----------------------------
208 void DFDCCathodeCluster_factory::pique(vector<const DFDCHit*>& H)
209 {
210  /// Find clusters within cathode plane.
211  ///
212  /// Upon entry, the vector "H" should already be sorted
213  /// by strip number and should only contains hits from
214  /// the same plane that are in time with each other.
215  /// This will form clusters from all contiguous strips.
216 
217  // Loop over hits
218  for(uint32_t istart=0; istart<H.size(); istart++){
219  const DFDCHit *first_hit = H[istart];
220 
221  // Find end of contiguous section
222  uint32_t iend=istart+1;
223  for(; iend<H.size(); iend++){
224  if(iend>=H.size()) break;
225  if( (H[iend]->element - H[iend-1]->element) > 1 ) break;
226  }
227  if( (iend-istart)<2 ) continue; // don't allow single strip clusters
228 
229  // istart should now point to beginning of cluster
230  // and iend to one past end of cluster
231  DFDCCathodeCluster* newCluster = new DFDCCathodeCluster();
232  newCluster->q_tot = 0.0;
233  newCluster->gLayer = first_hit->gLayer;
234  newCluster->gPlane = first_hit->gPlane;
235  newCluster->plane = first_hit->plane;
236  for(uint32_t i=istart; i<iend; i++){
237  newCluster->q_tot += H[i]->q;
238  newCluster->members.push_back(H[i]);
239  }
240  _data.push_back(newCluster);
241 
242  istart = iend-1;
243  }
244 }
245 
float q
Definition: DFDCHit.h:29
bool DFDCHit_cmp(const DFDCHit *a, const DFDCHit *b)
DFDCCathodeCluster_factory()
DFDCCathodeCluster_factory::DFDCCathodeCluster_factory(): default constructor–initializes log file...
bool DFDCHit_time_cmp(const DFDCHit *a, const DFDCHit *b)
DFDCHit_time_cmp() a non-member function passed to std::stable_sort() for sorting DFDCHit pointers in...
vector< const DFDCHit * > members
DANA identifier.
~DFDCCathodeCluster_factory()
DFDCCathodeCluster_factory::~DFDCCathodeCluster_factory(): default destructor–closes log file...
int gLayer
Definition: DFDCHit.h:28
bool DFDCHit_element_cmp(const DFDCHit *a, const DFDCHit *b)
DFDCHit_element_cmp(): a non-member function passed to std::sort() for sorting DFDCHit pointers by th...
float q_tot
total energy/charge deposited in the cluster
bool DFDCHit_gLayer_cmp(const DFDCHit *a, const DFDCHit *b)
DFDCHit_gLayer_cmp(): a non-member function passed to std::sort() for sorting DFDCHit pointers by the...
#define H(x, y, z)
int gPlane
#1-74, which plane out of all FDC modules
#define HIT_TIME_DIFF_MIN
void pique(vector< const DFDCHit * > &h)
DFDCCathodeCluster_factory::pique(): takes a single layer&#39;s worth of cathode hits and attempts to cre...
int plane
Definition: DFDCHit.h:26
jerror_t evnt(JEventLoop *eventLoop, uint64_t eventNo)
DFDCCathodeCluster_factory::evnt(): This (along with DFDCCathodeCluster_factory::pique()) is the plac...
int element
Definition: DFDCHit.h:25
int gLayer
#1-24, which detection layer of all FDC
float t
Definition: DFDCHit.h:32
bool DFDCCathodeCluster_gPlane_cmp(const DFDCCathodeCluster *a, const DFDCCathodeCluster *b)
DFDCCathodeCluster_gPlane_cmp(): a non-member function passed to std::sort() for sorting DFDCCathodeC...
jerror_t init(void)
Initialization.
int gPlane
Definition: DFDCHit.h:27
class DFDCHit: definition for a basic FDC hit data type.
Definition: DFDCHit.h:20