Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DTOFPaddleHit_factory.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DTOFPaddleHit_factory.cc
4 // Created: Thu Jun 9 10:05:21 EDT 2005
5 // Creator: davidl (on Darwin wire129.jlab.org 7.8.0 powerpc)
6 //
7 // Modified: Wed Feb 12 13:19:10 EST 2014 by B. Zihlmann
8 // reflect the changes in the TOF geometry with
9 // 19 LWB, 2 LNB, 2 SB, 2LNB, 19 LWB
10 // 2 SB
11 // LWB: long wide bars
12 // LNB: long narrow bars
13 // SB: short bars
14 // the bar numbering goes from 1 all through 46 with
15 // bar 22 and 23 are the 4 short bars distinguished by north/south
16 //
17 
18 #include <iostream>
19 using namespace std;
20 
21 #include "DTOFPaddleHit_factory.h"
22 #include "DTOFHit.h"
23 #include "DTOFHitMC.h"
24 #include "DTOFPaddleHit.h"
25 #include <math.h>
26 
27 //#define NaN std::numeric_limits<double>::quiet_NaN()
28 #define BuiltInNaN __builtin_nan("")
29 
30 //------------------
31 // brun
32 //------------------
33 jerror_t DTOFPaddleHit_factory::brun(JEventLoop *loop, int32_t runnumber)
34 {
35 
36  map<string, double> tofparms;
37 
38  if ( !loop->GetCalib("TOF/tof_parms", tofparms)){
39  //cout<<"DTOFPaddleHit_factory: loading values from TOF data base"<<endl;
40 
41  C_EFFECTIVE = tofparms["TOF_C_EFFECTIVE"];
42  //HALFPADDLE = tofparms["TOF_HALFPADDLE"];
43  E_THRESHOLD = tofparms["TOF_E_THRESHOLD"];
44  ATTEN_LENGTH = tofparms["TOF_ATTEN_LENGTH"];
45  } else {
46  cout << "DTOFPaddleHit_factory: Error loading values from TOF data base" <<endl;
47 
48  C_EFFECTIVE = 15.; // set to some reasonable value
49  //HALFPADDLE = 126; // set to some reasonable value
50  E_THRESHOLD = 0.0005; // energy threshold in GeV
51  ATTEN_LENGTH = 400.; // 400cm attenuation length
52  }
53 
54  // load values from geometry
55  loop->Get(TOFGeom);
56  TOF_NUM_PLANES = TOFGeom[0]->Get_NPlanes();
57  TOF_NUM_BARS = TOFGeom[0]->Get_NBars();
58  HALFPADDLE = TOFGeom[0]->Get_HalfLongBarLength();
59 
60  ENERGY_ATTEN_FACTOR=exp(HALFPADDLE/ATTEN_LENGTH);
61  TIME_COINCIDENCE_CUT=2.*HALFPADDLE/C_EFFECTIVE;
62 
63  if(loop->GetCalib("TOF/propagation_speed", propagation_speed))
64  jout << "Error loading /TOF/propagation_speed !" << endl;
65 
66  if (loop->GetCalib("TOF/attenuation_lengths",AttenuationLengths))
67  jout << "Error loading /TOF/attenuation_lengths !" <<endl;
68 
69 
70  return NOERROR;
71 
72 }
73 
74 //------------------
75 // evnt
76 //------------------
77 jerror_t DTOFPaddleHit_factory::evnt(JEventLoop *loop, uint64_t eventnumber)
78 {
79 
80  vector<const DTOFHit*> hits;
81  loop->Get(hits,TOF_POINT_TAG.c_str());
82 
83  vector<const DTOFHit*> P1hitsL;
84  vector<const DTOFHit*> P1hitsR;
85  vector<const DTOFHit*> P2hitsL;
86  vector<const DTOFHit*> P2hitsR;
87 
88  //int P1L[100];
89  //int P1R[100];
90  //int P2L[100];
91  //int P2R[100];
92 
93  //int c1l = 0;
94  //int c1r = 0;
95  //int c2l = 0;
96  //int c2r = 0;
97 
98  // sort the tof hits into left and right PMTs for both planes
99 
100  for (unsigned int i = 0; i < hits.size(); i++){
101  const DTOFHit *hit = hits[i];
102  if (hit->has_fADC && hit->has_TDC){ // good hits have both ADC and TDC info
103  if (hit->plane){
104  if (hit->end){
105  P2hitsR.push_back(hit);
106  //P2R[c2r++] = i;
107  } else {
108  P2hitsL.push_back(hit);
109  //P2L[c2l++] = i;
110  }
111  } else {
112  if (hit->end){
113  P1hitsR.push_back(hit);
114  //P1R[c1r++] = i;
115  } else {
116  P1hitsL.push_back(hit);
117  //P1L[c1l++] = i;
118  }
119  }
120  }
121  }
122 
123  for (unsigned int i=0; i<P1hitsL.size(); i++){
124  int bar = P1hitsL[i]->bar;
125  if ((bar < TOFGeom[0]->Get_FirstShortBar() ) || (bar > TOFGeom[0]->Get_LastShortBar())) {
126  for (unsigned int j=0; j<P1hitsR.size(); j++){
127  if (bar==P1hitsR[j]->bar
128  && fabs(P1hitsR[j]->t-P1hitsL[i]->t)<TIME_COINCIDENCE_CUT
129  && (P1hitsL[i]->dE>E_THRESHOLD || P1hitsR[j]->dE>E_THRESHOLD)){
130  DTOFPaddleHit *hit = new DTOFPaddleHit;
131  hit->bar = bar;
132  hit->orientation = P1hitsL[i]->plane;
133  hit->E_north = P1hitsL[i]->dE;
134  hit->t_north = P1hitsL[i]->t;
135  hit->AddAssociatedObject(P1hitsL[i]);
136  hit->E_south = P1hitsR[j]->dE;
137  hit->t_south = P1hitsR[j]->t;
138  hit->AddAssociatedObject(P1hitsR[j]);
139 
140  _data.push_back(hit);
141  }
142  }
143  }
144  }
145 
146  for (unsigned int i=0; i<P1hitsL.size(); i++){
147  int bar = P1hitsL[i]->bar;
148  int found = 0;
149 
150  if ((bar < TOFGeom[0]->Get_FirstShortBar()) || (bar > TOFGeom[0]->Get_LastShortBar())) {
151  for (unsigned int j=0; j<P1hitsR.size(); j++){
152  if (bar==P1hitsR[j]->bar){
153  found = 1;
154  }
155  }
156  }
157 
158  if (!found){
159  if (P1hitsL[i]->dE>E_THRESHOLD){
160  DTOFPaddleHit *hit = new DTOFPaddleHit;
161  hit->bar = bar;
162  hit->orientation = P1hitsL[i]->plane;
163  hit->E_north = P1hitsL[i]->dE;
164  hit->t_north = P1hitsL[i]->t;
165  hit->E_south = 0.;
166  hit->t_south = 0.;
167  hit->AddAssociatedObject(P1hitsL[i]);
168 
169  _data.push_back(hit);
170  }
171  }
172  }
173 
174 
175  for (unsigned int i=0; i<P1hitsR.size(); i++){
176  int bar = P1hitsR[i]->bar;
177  int found = 0;
178 
179  if ((bar < TOFGeom[0]->Get_FirstShortBar()) || (bar > TOFGeom[0]->Get_LastShortBar())) {
180  for (unsigned int j=0; j<P1hitsL.size(); j++){
181  if (bar==P1hitsL[j]->bar){
182  found = 1;
183  }
184  }
185  }
186 
187  if (!found){
188  if (P1hitsR[i]->dE>E_THRESHOLD){
189  DTOFPaddleHit *hit = new DTOFPaddleHit;
190  hit->bar = bar;
191  hit->orientation = P1hitsR[i]->plane;
192  hit->E_south = P1hitsR[i]->dE;
193  hit->t_south = P1hitsR[i]->t;
194  hit->E_north = 0.;
195  hit->t_north = 0.;
196  hit->AddAssociatedObject(P1hitsR[i]);
197 
198  _data.push_back(hit);
199  }
200  }
201  }
202 
203  for (unsigned int i=0; i<P2hitsL.size(); i++){
204  int bar = P2hitsL[i]->bar;
205  if ((bar < TOFGeom[0]->Get_FirstShortBar()) || (bar > TOFGeom[0]->Get_LastShortBar() )){
206  for (unsigned int j=0; j<P2hitsR.size(); j++){
207  if (bar==P2hitsR[j]->bar
208  && fabs(P2hitsR[j]->t-P2hitsL[i]->t)<TIME_COINCIDENCE_CUT
209  && (P2hitsL[i]->dE>E_THRESHOLD || P2hitsR[j]->dE>E_THRESHOLD)){
210  DTOFPaddleHit *hit = new DTOFPaddleHit;
211  hit->bar = bar;
212  hit->orientation = P2hitsL[i]->plane;
213  hit->E_north = P2hitsL[i]->dE;
214  hit->t_north = P2hitsL[i]->t;
215  hit->AddAssociatedObject(P2hitsL[i]);
216  hit->E_south = P2hitsR[j]->dE;
217  hit->t_south = P2hitsR[j]->t;
218  hit->AddAssociatedObject(P2hitsR[j]);
219 
220  _data.push_back(hit);
221  }
222  }
223  }
224  }
225 
226  for (unsigned int i=0; i<P2hitsL.size(); i++){
227  int bar = P2hitsL[i]->bar;
228  int found = 0;
229 
230  if ((bar < TOFGeom[0]->Get_FirstShortBar()) || (bar > TOFGeom[0]->Get_LastShortBar())) {
231  for (unsigned int j=0; j<P2hitsR.size(); j++){
232  if (bar==P2hitsR[j]->bar){
233  found = 1;
234  }
235  }
236  }
237 
238  if (!found){
239  if (P2hitsL[i]->dE>E_THRESHOLD){
240  DTOFPaddleHit *hit = new DTOFPaddleHit;
241  hit->bar = bar;
242  hit->orientation = P2hitsL[i]->plane;
243  hit->E_north = P2hitsL[i]->dE;
244  hit->t_north = P2hitsL[i]->t;
245  hit->E_south = 0.;
246  hit->t_south = 0.;
247  hit->AddAssociatedObject(P2hitsL[i]);
248 
249  _data.push_back(hit);
250  }
251  }
252  }
253 
254 
255  for (unsigned int i=0; i<P2hitsR.size(); i++){
256  int bar = P2hitsR[i]->bar;
257  int found = 0;
258 
259  if ((bar < TOFGeom[0]->Get_FirstShortBar()) || (bar > TOFGeom[0]->Get_LastShortBar())) {
260  for (unsigned int j=0; j<P2hitsL.size(); j++){
261  if (bar==P2hitsL[j]->bar){
262  found = 1;
263  }
264  }
265  }
266 
267  if (!found){
268  if (P2hitsR[i]->dE>E_THRESHOLD){
269  DTOFPaddleHit *hit = new DTOFPaddleHit;
270  hit->bar = bar;
271  hit->orientation = P2hitsR[i]->plane;
272  hit->E_south = P2hitsR[i]->dE;
273  hit->t_south = P2hitsR[i]->t;
274  hit->E_north = 0.;
275  hit->t_north = 0.;
276  hit->AddAssociatedObject(P2hitsR[i]);
277 
278  _data.push_back(hit);
279  }
280  }
281  }
282 
283 
284  for (int i=0;i<(int)_data.size(); i++) {
285 
286  DTOFPaddleHit *hit = _data[i];
287 
288  int check = -1;
289  if (hit->E_north > E_THRESHOLD) {
290  check++;
291  }
292  if (hit->E_south > E_THRESHOLD) {
293  check++;
294  }
295 
296  if (check > 0 ){
297  int id=TOF_NUM_BARS*hit->orientation+hit->bar-1;
298  double v=propagation_speed[id];
299  hit->meantime = (hit->t_north+hit->t_south)/2. - HALFPADDLE/v;
300  hit->timediff = (hit->t_south - hit->t_north)/2.;
301  float pos = hit->timediff * v;
302  hit->pos = pos;
303  hit->dpos = 2.; // manually/artificially set to 2cm.
304 
305  // mean energy deposition at the location of the hit position
306  // use geometrical mean
307  //hit->dE = ENERGY_ATTEN_FACTOR*sqrt(hit->E_north*hit->E_south);
308 
309  float xl = HALFPADDLE - pos; // distance to left PMT
310  float xr = HALFPADDLE + pos; // distance to right PMT
311  int idl = hit->orientation*TOF_NUM_PLANES*TOF_NUM_BARS + hit->bar-1;
312  int idr = idl+TOF_NUM_BARS;
313  float d1 = AttenuationLengths[idl][0];
314  float d2 = AttenuationLengths[idl][1];
315  // reference distance is 144cm from PMT
316  float att_left = ( TMath::Exp(-144./d1) + TMath::Exp(-144./d2)) /
317  ( TMath::Exp(-xl/d1) + TMath::Exp(-xl/d2));
318  d1 = AttenuationLengths[idr][0];
319  d2 = AttenuationLengths[idr][1];
320  float att_right = ( TMath::Exp(-144./d1) + TMath::Exp(-144./d2)) /
321  ( TMath::Exp(-xr/d1) + TMath::Exp(-xr/d2));
322  hit->dE = (hit->E_north*att_left + hit->E_south*att_right)/2.;
323  } else {
324  hit->meantime = BuiltInNaN;
325  hit->timediff = BuiltInNaN;
326  hit->pos = BuiltInNaN;
327  hit->dpos = BuiltInNaN;
328  hit->dE = BuiltInNaN;
329  }
330 
331  }
332 
333  return NOERROR;
334 }
335 
int end
Definition: DTOFHit.h:23
int plane
Definition: DTOFHit.h:21
bool has_fADC
Definition: DTOFHit.h:29
jerror_t brun(JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
bool has_TDC
Definition: DTOFHit.h:30
#define BuiltInNaN
jerror_t evnt(JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
File: DTOFHit.h Created: Tue Jan 18 16:15:26 EST 2011 Creator: B. Zihlmann Purpose: Container class t...
Definition: DTOFHit.h:16