Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DTOFPoint_factory.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DTOFPoint_factory.cc
4 // Created: Tue Oct 18 09:50:52 EST 2005
5 // Creator: remitche (on Linux mantrid00 2.4.20-18.8smp i686)
6 //
7 // Modified: Wed Feb 12 13:23:42 EST 2014 B. Zihlamnn
8 // use new TOF geometry with narrow long paddles
9 // and short paddles #22 and #23 for both north and south
10 //
11 
12 #include <cassert>
13 #include <cmath>
14 using namespace std;
15 
16 #include "DTOFPoint_factory.h"
17 
19 {
20  if(locTOFSpacetimeHitMatch2.dBothPositionsWellDefinedFlag != locTOFSpacetimeHitMatch1.dBothPositionsWellDefinedFlag)
21  return locTOFSpacetimeHitMatch1.dBothPositionsWellDefinedFlag; //one hit position is well defined and the other is not
22  return (locTOFSpacetimeHitMatch1.delta_r < locTOFSpacetimeHitMatch2.delta_r);
23 };
24 
25 bool Compare_TOFPoint_Time(const DTOFPoint *locTOFPoint1, const DTOFPoint *locTOFPoint2) {
26  return locTOFPoint1->t < locTOFPoint2->t;
27 }
28 
29 //------------------
30 // brun
31 //------------------
32 jerror_t DTOFPoint_factory::brun(JEventLoop *loop, int32_t runnumber)
33 {
34 
35  map<string, double> tofparms;
36  if( !loop->GetCalib("TOF/tof_parms", tofparms))
37  {
38  //cout<<"DTOFPoint_factory: loading values from TOF data base"<<endl;
39  //HALFPADDLE = tofparms["TOF_HALFPADDLE"];
40  E_THRESHOLD = tofparms["TOF_E_THRESHOLD"];
41  ATTEN_LENGTH = tofparms["TOF_ATTEN_LENGTH"];
42  }
43  else
44  {
45  cout << "DTOFPoint_factory: Error loading values from TOF data base" <<endl;
46  //HALFPADDLE = 126; // set to some reasonable value
47  E_THRESHOLD = 0.0005;
48  ATTEN_LENGTH = 400.;
49  }
50 
51  if(eventLoop->GetCalib("TOF/propagation_speed", propagation_speed))
52  jout << "Error loading /TOF/propagation_speed !" << endl;
53  if(eventLoop->GetCalib("TOF/paddle_resolutions", paddle_resolutions))
54  jout << "Error loading /TOF/paddle_resolutions !" << endl;
55 
56  loop->GetSingle(dTOFGeometry);
57 
58  HALFPADDLE = dTOFGeometry->Get_HalfLongBarLength();
59  HALFPADDLE_ONESIDED = dTOFGeometry->Get_HalfShortBarLength();
60  double locBeamHoleWidth = dTOFGeometry->Get_LongBarLength() - 2.0*dTOFGeometry->Get_ShortBarLength();
61  ONESIDED_PADDLE_MIDPOINT_MAG = HALFPADDLE_ONESIDED + locBeamHoleWidth/2.0;
62 
63  NUM_BARS = dTOFGeometry->Get_NBars();
64 
65  dPositionMatchCut_DoubleEnded = 9.0; //1.5*BARWIDTH
66 // dTimeMatchCut_PositionWellDefined = 1.0;
67  dTimeMatchCut_PositionWellDefined = 10.0;
68  dTimeMatchCut_PositionNotWellDefined = 10.0;
69 
70  return NOERROR;
71 }
72 
74 {
75  tof_spacetimehit_t* locTOFSpacetimeHit;
76  if(dTOFSpacetimeHitPool_Available.empty())
77  {
78  locTOFSpacetimeHit = new tof_spacetimehit_t;
79  dTOFSpacetimeHitPool_All.push_back(locTOFSpacetimeHit);
80  }
81  else
82  {
83  locTOFSpacetimeHit = dTOFSpacetimeHitPool_Available.back();
84  dTOFSpacetimeHitPool_Available.pop_back();
85  }
86  return locTOFSpacetimeHit;
87 }
88 
89 //------------------
90 // evnt
91 //------------------
92 jerror_t DTOFPoint_factory::evnt(JEventLoop *loop, uint64_t eventnumber)
93 {
94  // delete pool size if too large, preventing memory-leakage-like behavor.
95  if(dTOFSpacetimeHitPool_All.size() > MAX_TOFSpacetimeHitPoolSize)
96  {
97  for(size_t loc_i = MAX_TOFSpacetimeHitPoolSize; loc_i < dTOFSpacetimeHitPool_All.size(); ++loc_i)
98  delete dTOFSpacetimeHitPool_All[loc_i];
99  dTOFSpacetimeHitPool_All.resize(MAX_TOFSpacetimeHitPoolSize);
100  }
101  dTOFSpacetimeHitPool_Available = dTOFSpacetimeHitPool_All;
102 
103  vector<const DTOFPaddleHit*> locTOFHitVector;
104  loop->Get(locTOFHitVector);
105 
106  // create the hit spacetime information
107  deque<tof_spacetimehit_t*> locTOFSpacetimeHits_Horizontal, locTOFSpacetimeHits_Vertical;
108  set<tof_spacetimehit_t*> locUnusedTOFSpacetimeHits;
109  for(size_t loc_i = 0; loc_i < locTOFHitVector.size(); ++loc_i)
110  {
111  const DTOFPaddleHit* locTOFHit = locTOFHitVector[loc_i];
112  if(!((locTOFHit->E_north > E_THRESHOLD) || (locTOFHit->E_south > E_THRESHOLD)))
113  continue;
114 
115  if(locTOFHit->orientation) //horizontal
116  {
117  tof_spacetimehit_t* locSpacetimeHit = Build_TOFSpacetimeHit_Horizontal(locTOFHit);
118  locTOFSpacetimeHits_Horizontal.push_back(locSpacetimeHit);
119  locUnusedTOFSpacetimeHits.insert(locSpacetimeHit);
120  }
121  else //vertical
122  {
123  tof_spacetimehit_t* locSpacetimeHit = Build_TOFSpacetimeHit_Vertical(locTOFHit);
124  locTOFSpacetimeHits_Vertical.push_back(locSpacetimeHit);
125  locUnusedTOFSpacetimeHits.insert(locSpacetimeHit);
126  }
127  }
128 
129 
130  //find matches between planes and sort them by delta-r
131  deque<tof_spacetimehitmatch_t> locTOFSpacetimeHitMatches; //use list for sorting, vector for resource pool
132  for(size_t loc_i = 0; loc_i < locTOFSpacetimeHits_Horizontal.size(); ++loc_i)
133  {
134  tof_spacetimehit_t* locTOFSpacetimeHit_Horizontal = locTOFSpacetimeHits_Horizontal[loc_i];
135  for(size_t loc_j = 0; loc_j < locTOFSpacetimeHits_Vertical.size(); ++loc_j)
136  {
137  tof_spacetimehit_t* locTOFSpacetimeHit_Vertical = locTOFSpacetimeHits_Vertical[loc_j];
138 
139  tof_spacetimehitmatch_t locTOFSpacetimeHitMatch;
140  if(!Match_Hits(locTOFSpacetimeHit_Horizontal, locTOFSpacetimeHit_Vertical, locTOFSpacetimeHitMatch))
141  continue; //not a match
142 
143  locTOFSpacetimeHitMatches.push_back(locTOFSpacetimeHitMatch);
144  }
145  }
146  std::sort(locTOFSpacetimeHitMatches.begin(), locTOFSpacetimeHitMatches.end(), Compare_TOFSpacetimeHitMatches_Distance); //sort matches by delta_r
147 
148 
149  // create DTOFPoints, in order of best matches (by delta_r)
150  for(size_t loc_i = 0; loc_i < locTOFSpacetimeHitMatches.size(); ++loc_i)
151  {
152  tof_spacetimehit_t* locTOFSpacetimeHit_Horizontal = locTOFSpacetimeHitMatches[loc_i].dTOFSpacetimeHit_Horizontal;
153  if(locUnusedTOFSpacetimeHits.find(locTOFSpacetimeHit_Horizontal) == locUnusedTOFSpacetimeHits.end())
154  continue; //hit used in a previous successful match
155 
156  tof_spacetimehit_t* locTOFSpacetimeHit_Vertical = locTOFSpacetimeHitMatches[loc_i].dTOFSpacetimeHit_Vertical;
157  if(locUnusedTOFSpacetimeHits.find(locTOFSpacetimeHit_Vertical) == locUnusedTOFSpacetimeHits.end())
158  continue; //hit used in a previous successful match
159 
160  Create_MatchedTOFPoint(locTOFSpacetimeHit_Horizontal, locTOFSpacetimeHit_Vertical);
161 
162  //remove used hits from the unused list
163  locUnusedTOFSpacetimeHits.erase(locTOFSpacetimeHit_Horizontal);
164  locUnusedTOFSpacetimeHits.erase(locTOFSpacetimeHit_Vertical);
165  }
166 
167  // Loop over unused/unmatched TOF Spacetime hits, and create separate DTOFPoint's for them
168  set<tof_spacetimehit_t*>::iterator locSetIterator = locUnusedTOFSpacetimeHits.begin();
169  for(; locSetIterator != locUnusedTOFSpacetimeHits.end(); ++locSetIterator)
170  Create_UnMatchedTOFPoint(*locSetIterator);
171 
172  // make sure all the hits are sorted by time (why not?)
173  // this helps with reproducibiliy problems...
174  std::sort(_data.begin(), _data.end(), Compare_TOFPoint_Time);
175 
176 
177  return NOERROR;
178 }
179 
181 {
182  tof_spacetimehit_t* locTOFSpacetimeHit = Get_TOFSpacetimeHitResource();
183  locTOFSpacetimeHit->TOFHit = locTOFHit;
184 
185  int bar = locTOFHit->bar;
186  int id = NUM_BARS + locTOFHit->bar - 1;
187  double v = propagation_speed[id];
188 
189  if((locTOFHit->bar < dTOFGeometry->Get_FirstShortBar()) || (locTOFHit->bar > dTOFGeometry->Get_LastShortBar())) //double-ended bars
190  {
191  locTOFSpacetimeHit->dIsDoubleEndedBar = true;
192  locTOFSpacetimeHit->dIsSingleEndedNorthPaddle = false;
193  locTOFSpacetimeHit->y = dTOFGeometry->bar2y(bar);
194  if(locTOFHit->meantime != locTOFHit->meantime)
195  {
196  //NaN: only one energy hit above threshold on the double-ended bar
197  locTOFSpacetimeHit->dPositionWellDefinedFlag = false;
198  locTOFSpacetimeHit->x = 0.0;
199  if(locTOFHit->E_north > E_THRESHOLD)
200  locTOFSpacetimeHit->t = locTOFHit->t_north - HALFPADDLE/v;
201  else
202  locTOFSpacetimeHit->t = locTOFHit->t_south - HALFPADDLE/v;
203 
204  locTOFSpacetimeHit->pos_cut = 1000.0;
205  locTOFSpacetimeHit->t_cut = dTimeMatchCut_PositionNotWellDefined;
206  }
207  else
208  {
209  locTOFSpacetimeHit->dPositionWellDefinedFlag = true;
210  locTOFSpacetimeHit->x = locTOFHit->pos;
211  locTOFSpacetimeHit->t = locTOFHit->meantime;
212  locTOFSpacetimeHit->pos_cut = dPositionMatchCut_DoubleEnded;
213  locTOFSpacetimeHit->t_cut = dTimeMatchCut_PositionWellDefined;
214  }
215 
216  //printf("h: x %f y %f\n",locTOFSpacetimeHit->x,locTOFSpacetimeHit->y);
217  return locTOFSpacetimeHit;
218  }
219 
220  //single-ended bars
221  locTOFSpacetimeHit->dIsDoubleEndedBar = false;
222  locTOFSpacetimeHit->dPositionWellDefinedFlag = false;
223  locTOFSpacetimeHit->pos_cut = 1000.0;
224  locTOFSpacetimeHit->t_cut = dTimeMatchCut_PositionNotWellDefined;
225 
226  if(locTOFHit->t_south != 0.)
227  {
228  locTOFSpacetimeHit->dIsSingleEndedNorthPaddle = false;
229  locTOFSpacetimeHit->y = dTOFGeometry->bar2y(bar,1);
230  locTOFSpacetimeHit->x = -1.0*ONESIDED_PADDLE_MIDPOINT_MAG;
231  locTOFSpacetimeHit->t = locTOFHit->t_south - HALFPADDLE_ONESIDED/v;
232  }
233  else
234  {
235  locTOFSpacetimeHit->dIsSingleEndedNorthPaddle = true;
236  locTOFSpacetimeHit->y = dTOFGeometry->bar2y(bar,0);
237  locTOFSpacetimeHit->x = ONESIDED_PADDLE_MIDPOINT_MAG;
238  locTOFSpacetimeHit->t = locTOFHit->t_north - HALFPADDLE_ONESIDED/v;
239  }
240 
241  //printf("h: x %f y %f\n",locTOFSpacetimeHit->x,locTOFSpacetimeHit->y);
242  return locTOFSpacetimeHit;
243 }
244 
246 {
247  tof_spacetimehit_t* locTOFSpacetimeHit = Get_TOFSpacetimeHitResource();
248  locTOFSpacetimeHit->TOFHit = locTOFHit;
249 
250  int bar = locTOFHit->bar;
251  int id = locTOFHit->bar - 1;
252  double v = propagation_speed[id];
253 
254  if((locTOFHit->bar < dTOFGeometry->Get_FirstShortBar()) || (locTOFHit->bar > dTOFGeometry->Get_LastShortBar()))
255  {
256  //double-ended bars
257  locTOFSpacetimeHit->dIsDoubleEndedBar = true;
258  locTOFSpacetimeHit->dIsSingleEndedNorthPaddle = false;
259  locTOFSpacetimeHit->x = dTOFGeometry->bar2y(bar);
260  if(locTOFHit->meantime != locTOFHit->meantime)
261  {
262  //NaN: only one energy hit above threshold on the double-ended bar
263  locTOFSpacetimeHit->dPositionWellDefinedFlag = false;
264  locTOFSpacetimeHit->y = 0.0;
265  if(locTOFHit->E_north > E_THRESHOLD)
266  locTOFSpacetimeHit->t = locTOFHit->t_north - HALFPADDLE/v;
267  else
268  locTOFSpacetimeHit->t = locTOFHit->t_south - HALFPADDLE/v;
269  locTOFSpacetimeHit->pos_cut = 1000.0;
270  locTOFSpacetimeHit->t_cut = dTimeMatchCut_PositionNotWellDefined;
271  }
272  else
273  {
274  locTOFSpacetimeHit->dPositionWellDefinedFlag = true;
275  locTOFSpacetimeHit->y = locTOFHit->pos;
276  locTOFSpacetimeHit->t = locTOFHit->meantime;
277  locTOFSpacetimeHit->pos_cut = dPositionMatchCut_DoubleEnded;
278  locTOFSpacetimeHit->t_cut = dTimeMatchCut_PositionWellDefined;
279  }
280 
281  //printf("h: x %f y %f\n",locTOFSpacetimeHit->x,locTOFSpacetimeHit->y);
282  return locTOFSpacetimeHit;
283  }
284 
285  //single-ended bars
286  locTOFSpacetimeHit->dIsDoubleEndedBar = false;
287  locTOFSpacetimeHit->dPositionWellDefinedFlag = false;
288  locTOFSpacetimeHit->pos_cut = 1000.0;
289  locTOFSpacetimeHit->t_cut = dTimeMatchCut_PositionNotWellDefined;
290  if(locTOFHit->t_south != 0.)
291  {
292  locTOFSpacetimeHit->dIsSingleEndedNorthPaddle = false;
293  locTOFSpacetimeHit->x = dTOFGeometry->bar2y(bar,0);
294  locTOFSpacetimeHit->y = -1.0*ONESIDED_PADDLE_MIDPOINT_MAG;
295  locTOFSpacetimeHit->t = locTOFHit->t_south - HALFPADDLE_ONESIDED/v;
296  }
297  else
298  {
299  locTOFSpacetimeHit->dIsSingleEndedNorthPaddle = true;
300  locTOFSpacetimeHit->x = dTOFGeometry->bar2y(bar,1);
301  locTOFSpacetimeHit->y = ONESIDED_PADDLE_MIDPOINT_MAG;
302  locTOFSpacetimeHit->t = locTOFHit->t_north - HALFPADDLE_ONESIDED/v;
303  }
304 
305  //printf("h: x %f y %f\n",locTOFSpacetimeHit->x,locTOFSpacetimeHit->y);
306  return locTOFSpacetimeHit;
307 }
308 
309 bool DTOFPoint_factory::Match_Hits(tof_spacetimehit_t* locTOFSpacetimeHit_Horizontal, tof_spacetimehit_t* locTOFSpacetimeHit_Vertical, tof_spacetimehitmatch_t& locTOFSpacetimeHitMatch)
310 {
311  //make sure that single-ended paddles don't match each other
312  if((!locTOFSpacetimeHit_Vertical->dIsDoubleEndedBar) && (!locTOFSpacetimeHit_Horizontal->dIsDoubleEndedBar))
313  return false; //unphysical
314 
315  //make sure that (e.g. horizontal) single-ended paddles don't match (e.g. vertical) paddles on the opposite side
316  if(!locTOFSpacetimeHit_Horizontal->dIsDoubleEndedBar)
317  {
318  //horizontal is single-ended
319  if(locTOFSpacetimeHit_Horizontal->dIsSingleEndedNorthPaddle)
320  {
321  //horizontal is on north (+x) side
322  if(locTOFSpacetimeHit_Vertical->TOFHit->bar < dTOFGeometry->Get_FirstShortBar())
323  return false; //vertical is on south (-x) side: CANNOT MATCH
324  }
325  else
326  {
327  //horizontal is on south (-x) side
328  if(locTOFSpacetimeHit_Vertical->TOFHit->bar > dTOFGeometry->Get_LastShortBar())
329  return false; //vertical is on north (+x) side: CANNOT MATCH
330  }
331  }
332  else if(!locTOFSpacetimeHit_Vertical->dIsDoubleEndedBar)
333  {
334  //vertical is single-ended
335  if(locTOFSpacetimeHit_Vertical->dIsSingleEndedNorthPaddle)
336  {
337  //vertical is on north (+y) side
338  if(locTOFSpacetimeHit_Horizontal->TOFHit->bar < dTOFGeometry->Get_FirstShortBar())
339  return false; //horizontal is on south (-y) side: CANNOT MATCH
340  }
341  else
342  {
343  //vertical is on south (-y) side
344  if(locTOFSpacetimeHit_Horizontal->TOFHit->bar > dTOFGeometry->Get_LastShortBar())
345  return false; //horizontal is on north (+y) side: CANNOT MATCH
346  }
347  }
348 
349  //If the position along BOTH paddles is not well defined, cannot tell whether these hits match or not
350  //If the hit multiplicity was low, could just generate all matches
351  //However, the hit multiplicity is generally very high due to hits near the beamline: would have TOF hits everywhere
352  //Therefore, don't keep as match: register separately, let track / tof matching salvage the situation
353  if((!locTOFSpacetimeHit_Horizontal->dPositionWellDefinedFlag) && (!locTOFSpacetimeHit_Vertical->dPositionWellDefinedFlag))
354  return false; //have no idea whether these hits go together: assume they don't
355 
356  float locDeltaX = locTOFSpacetimeHit_Horizontal->x - locTOFSpacetimeHit_Vertical->x;
357  if(fabs(locDeltaX) > locTOFSpacetimeHit_Horizontal->pos_cut)
358  return false;
359 
360  float locDeltaY = locTOFSpacetimeHit_Horizontal->y - locTOFSpacetimeHit_Vertical->y;
361  if(fabs(locDeltaY) > locTOFSpacetimeHit_Vertical->pos_cut)
362  return false;
363 
364  float locDeltaT = locTOFSpacetimeHit_Horizontal->t - locTOFSpacetimeHit_Vertical->t;
365  float locTimeCut = (locTOFSpacetimeHit_Horizontal->t_cut > locTOFSpacetimeHit_Vertical->t_cut) ? locTOFSpacetimeHit_Horizontal->t_cut : locTOFSpacetimeHit_Vertical->t_cut;
366  if(fabs(locDeltaT) > locTimeCut)
367  return false;
368 
369  locTOFSpacetimeHitMatch.delta_t = locDeltaT;
370  locTOFSpacetimeHitMatch.delta_r = sqrt(locDeltaX*locDeltaX + locDeltaY*locDeltaY);
371  locTOFSpacetimeHitMatch.dTOFSpacetimeHit_Horizontal = locTOFSpacetimeHit_Horizontal;
372  locTOFSpacetimeHitMatch.dTOFSpacetimeHit_Vertical = locTOFSpacetimeHit_Vertical;
373  locTOFSpacetimeHitMatch.dBothPositionsWellDefinedFlag = (locTOFSpacetimeHit_Horizontal->dPositionWellDefinedFlag == locTOFSpacetimeHit_Vertical->dPositionWellDefinedFlag);
374 
375  return true;
376 }
377 
378 void DTOFPoint_factory::Create_MatchedTOFPoint(const tof_spacetimehit_t* locTOFSpacetimeHit_Horizontal, const tof_spacetimehit_t* locTOFSpacetimeHit_Vertical)
379 {
380  const DTOFPaddleHit* locTOFHit_Horizontal = locTOFSpacetimeHit_Horizontal->TOFHit;
381  const DTOFPaddleHit* locTOFHit_Vertical = locTOFSpacetimeHit_Vertical->TOFHit;
382 
383  int id_vert = locTOFHit_Vertical->bar - 1;
384  int id_horiz = NUM_BARS + locTOFHit_Horizontal->bar - 1;
385  double locVMatchTErr = paddle_resolutions[id_vert]; // paddle time resolutions
386  double locHMatchTErr = paddle_resolutions[id_horiz];
387  double locMatchTErr = 0.;
388 
389  //reconstruct TOF hit information, using information from the best bar: one or both of the bars may have a PMT signal below threshold
390  float locMatchX, locMatchY, locMatchZ, locMatchdE, locMatchT;
391  if(locTOFSpacetimeHit_Horizontal->dPositionWellDefinedFlag && locTOFSpacetimeHit_Vertical->dPositionWellDefinedFlag)
392  {
393  //both bars have both PMT signals above threshold
394  //is x/y resolution from energy calibration better than x/y resolution from paddle edges?
395  locMatchX = locTOFSpacetimeHit_Horizontal->x;
396  locMatchY = locTOFSpacetimeHit_Vertical->y;
397  locMatchZ = dTOFGeometry->Get_CenterMidPlane(); //z: midpoint between tof planes
398  locMatchT = 0.5*(locTOFSpacetimeHit_Horizontal->t + locTOFSpacetimeHit_Vertical->t);
399  locMatchdE = 0.5*(locTOFHit_Horizontal->dE + locTOFHit_Vertical->dE);
400  locMatchTErr = 0.5 * sqrt(locVMatchTErr*locVMatchTErr + locHMatchTErr*locHMatchTErr);
401  }
402  else if(locTOFSpacetimeHit_Horizontal->dPositionWellDefinedFlag)
403  {
404  //the vertical position from the vertical paddle is not well defined
405  locMatchX = locTOFSpacetimeHit_Horizontal->x;
406  locMatchY = locTOFSpacetimeHit_Horizontal->y;
407  locMatchT = locTOFSpacetimeHit_Horizontal->t;
408  locMatchZ = dTOFGeometry->Get_CenterHorizPlane(); //z: center of horizontal plane
409  locMatchdE = locTOFHit_Horizontal->dE;
410  locMatchTErr = locHMatchTErr;
411  }
412  else
413  {
414  //the horizontal position from the horizontal paddle is not well defined
415  locMatchX = locTOFSpacetimeHit_Vertical->x;
416  locMatchY = locTOFSpacetimeHit_Vertical->y;
417  locMatchT = locTOFSpacetimeHit_Vertical->t;
418  locMatchZ = dTOFGeometry->Get_CenterVertPlane(); //z: center of vertical plane
419  locMatchdE = locTOFHit_Vertical->dE;
420  locMatchTErr = locVMatchTErr;
421  }
422 
423  DTOFPoint* locTOFPoint = new DTOFPoint;
424  locTOFPoint->AddAssociatedObject(locTOFHit_Horizontal);
425  locTOFPoint->AddAssociatedObject(locTOFHit_Vertical);
426  locTOFPoint->pos.SetXYZ(locMatchX, locMatchY, locMatchZ);
427  locTOFPoint->t = locMatchT;
428  locTOFPoint->tErr = locMatchTErr;
429  locTOFPoint->dE = locMatchdE;
430 
431  locTOFPoint->dHorizontalBar = locTOFHit_Horizontal->bar;
432  locTOFPoint->dVerticalBar = locTOFHit_Vertical->bar;
433 
434  //Status: 0 if no hit (or none above threshold), 1 if only North hit above threshold, 2 if only South hit above threshold, 3 if both hits above threshold
435  locTOFPoint->dHorizontalBarStatus = int(locTOFHit_Horizontal->E_north > E_THRESHOLD) + 2*int(locTOFHit_Horizontal->E_south > E_THRESHOLD);
436  locTOFPoint->dVerticalBarStatus = int(locTOFHit_Vertical->E_north > E_THRESHOLD) + 2*int(locTOFHit_Vertical->E_south > E_THRESHOLD);
437 
438  _data.push_back(locTOFPoint);
439 }
440 
442 {
443  const DTOFPaddleHit* locPaddleHit = locTOFSpacetimeHit->TOFHit;
444  bool locIsHorizontalBarFlag = (locPaddleHit->orientation == 1);
445  float locPointZ = locIsHorizontalBarFlag ? dTOFGeometry->Get_CenterHorizPlane() : dTOFGeometry->Get_CenterVertPlane();
446 
447  int id_vert = locPaddleHit->bar - 1;
448  int id_horiz = NUM_BARS + locPaddleHit->bar - 1;
449  double locVTErr = paddle_resolutions[id_vert]; // paddle time resolutions
450  double locHTErr = paddle_resolutions[id_horiz];
451 
452  double locTErr = locIsHorizontalBarFlag ? locHTErr : locVTErr;
453 
454  if(locTOFSpacetimeHit->dPositionWellDefinedFlag)
455  {
456  //Position is well defined
457  DTOFPoint* locTOFPoint = new DTOFPoint;
458  locTOFPoint->AddAssociatedObject(locPaddleHit);
459 
460  locTOFPoint->pos.SetXYZ(locTOFSpacetimeHit->x, locTOFSpacetimeHit->y, locPointZ);
461  locTOFPoint->t = locTOFSpacetimeHit->t;
462  locTOFPoint->tErr = locTErr;
463  locTOFPoint->dE = locPaddleHit->dE;
464 
465  locTOFPoint->dHorizontalBar = locIsHorizontalBarFlag ? locPaddleHit->bar : 0;
466  locTOFPoint->dVerticalBar = locIsHorizontalBarFlag ? 0 : locPaddleHit->bar;
467 
468  //Status: 0 if no hit (or none above threshold), 1 if only North hit above threshold, 2 if only South hit above threshold, 3 if both hits above threshold
469  locTOFPoint->dHorizontalBarStatus = locIsHorizontalBarFlag ? 3 : 0;
470  locTOFPoint->dVerticalBarStatus = locIsHorizontalBarFlag ? 0 : 3;
471 
472  _data.push_back(locTOFPoint);
473  }
474  else
475  {
476  //position not well defined: save anyway:
477  //Will use track matching to define position in the other direction
478  //Then, will update the hit energy and time based on that position
479 
480  DTOFPoint* locTOFPoint = new DTOFPoint;
481  locTOFPoint->AddAssociatedObject(locPaddleHit);
482 
483  float locPointX = locTOFSpacetimeHit->x;
484  float locPointY = locTOFSpacetimeHit->y;
485  locTOFPoint->pos.SetXYZ(locPointX, locPointY, locPointZ);
486  locTOFPoint->t = locTOFSpacetimeHit->t;
487  locTOFPoint->tErr = locTErr;
488 
489  bool locNorthAboveThresholdFlag = (locPaddleHit->E_north > E_THRESHOLD);
490 
491  locTOFPoint->dHorizontalBar = locIsHorizontalBarFlag ? locPaddleHit->bar : 0;
492  locTOFPoint->dVerticalBar = locIsHorizontalBarFlag ? 0 : locPaddleHit->bar;
493 
494  int locBarStatus = locNorthAboveThresholdFlag ? 1 : 2;
495  locTOFPoint->dHorizontalBarStatus = locIsHorizontalBarFlag ? locBarStatus : 0;
496  locTOFPoint->dVerticalBarStatus = locIsHorizontalBarFlag ? 0 : locBarStatus;
497 
498  //Energy: Propagate to paddle mid-point
499  double locDeltaXToMidPoint = locTOFSpacetimeHit->dIsDoubleEndedBar ? HALFPADDLE : HALFPADDLE_ONESIDED;
500  float locEnergy = locNorthAboveThresholdFlag ? locPaddleHit->E_north : locPaddleHit->E_south;
501  locEnergy *= exp(locDeltaXToMidPoint/ATTEN_LENGTH);
502  locTOFPoint->dE = locEnergy;
503 
504  _data.push_back(locTOFPoint);
505  }
506 }
507 
509 {
510  for(size_t loc_i = 0; loc_i < dTOFSpacetimeHitPool_All.size(); ++loc_i)
511  delete dTOFSpacetimeHitPool_All[loc_i];
512  return NOERROR;
513 }
int dHorizontalBar
Definition: DTOFPoint.h:38
void Create_MatchedTOFPoint(const tof_spacetimehit_t *locTOFSpacetimeHit_Horizontal, const tof_spacetimehit_t *locTOFSpacetimeHit_Vertical)
float dE
Definition: DTOFPoint.h:35
int dHorizontalBarStatus
Definition: DTOFPoint.h:43
bool Match_Hits(tof_spacetimehit_t *locTOFSpacetimeHit_Horizontal, tof_spacetimehit_t *locTOFSpacetimeHit_Vertical, tof_spacetimehitmatch_t &locTOFSpacetimeHitMatch)
jerror_t evnt(JEventLoop *loop, uint64_t eventnumber)
tof_spacetimehit_t * Build_TOFSpacetimeHit_Horizontal(const DTOFPaddleHit *locTOFHit)
tof_spacetimehit_t * Get_TOFSpacetimeHitResource(void)
DVector3 pos
Definition: DTOFPoint.h:33
tof_spacetimehit_t * Build_TOFSpacetimeHit_Vertical(const DTOFPaddleHit *locTOFHit)
double sqrt(double)
int dVerticalBar
Definition: DTOFPoint.h:39
bool Compare_TOFSpacetimeHitMatches_Distance(const DTOFPoint_factory::tof_spacetimehitmatch_t &locTOFSpacetimeHitMatch1, const DTOFPoint_factory::tof_spacetimehitmatch_t &locTOFSpacetimeHitMatch2)
jerror_t brun(JEventLoop *loop, int32_t runnumber)
void Create_UnMatchedTOFPoint(const tof_spacetimehit_t *locTOFSpacetimeHit)
bool Compare_TOFPoint_Time(const DTOFPoint *locTOFPoint1, const DTOFPoint *locTOFPoint2)
float t
Definition: DTOFPoint.h:34
float tErr
Definition: DTOFPoint.h:36
int dVerticalBarStatus
Definition: DTOFPoint.h:44