Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DPSCPair_factory.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DPSCPair_factory.cc
4 // Created: Tue Mar 24 21:35:49 EDT 2015
5 // Creator: nsparks (on Linux cua2.jlab.org 2.6.32-431.5.1.el6.x86_64 x86_64)
6 //
7 
8 
9 #include <iostream>
10 #include <iomanip>
11 #include <math.h>
12 using namespace std;
13 
14 #include "DPSCPair_factory.h"
15 #include "DPSCHit.h"
16 using namespace jana;
17 
18 inline bool DPSCPair_SortByTimeDifference(const DPSCPair* pair1, const DPSCPair* pair2)
19 {
20  double tdiff1 = fabs(pair1->ee.first->t-pair1->ee.second->t);
21  double tdiff2 = fabs(pair2->ee.first->t-pair2->ee.second->t);
22  return (tdiff1<tdiff2);
23 }
24 
25 //------------------
26 // init
27 //------------------
28 jerror_t DPSCPair_factory::init(void)
29 {
30  DELTA_T_PAIR_MAX = 10.0; // ns
31  gPARMS->SetDefaultParameter("PSCPair:DELTA_T_PAIR_MAX",DELTA_T_PAIR_MAX,
32  "Maximum difference in ns between a pair of hits"
33  " in left and right arm of coarse PS");
34  return NOERROR;
35 }
36 
37 //------------------
38 // brun
39 //------------------
40 jerror_t DPSCPair_factory::brun(jana::JEventLoop *eventLoop, int32_t runnumber)
41 {
42  return NOERROR;
43 }
44 
45 //------------------
46 // evnt
47 //------------------
48 jerror_t DPSCPair_factory::evnt(JEventLoop *loop, uint64_t eventnumber)
49 {
50  // get coarse pair spectrometer hits
51  vector<const DPSCHit*> hits;
52  loop->Get(hits);
53  // form PSC left-right hit pairs and sort by time difference
54  pair<const DPSCHit*,const DPSCHit*> ee;
55  if (hits.size()>1) {
56  for (unsigned int i=0; i < hits.size()-1; i++) {
57  for (unsigned int j=i+1; j < hits.size(); j++) {
58  if (!hits[i]->has_TDC||!hits[j]->has_TDC) continue;
59  if (!hits[i]->has_fADC||!hits[j]->has_fADC) continue;
60  if (std::abs(hits[i]->arm-hits[j]->arm)==1&&fabs(hits[i]->t-hits[j]->t)<DELTA_T_PAIR_MAX) {
61  if (hits[i]->arm==0) {
62  ee.first = hits[i];
63  ee.second = hits[j];
64  }
65  else if (hits[i]->arm==1) {
66  ee.first = hits[j];
67  ee.second = hits[i];
68  }
69  DPSCPair *pair = new DPSCPair;
70  pair->ee = ee;
71  _data.push_back(pair);
72  }
73  }
74  }
75  }
76  sort(_data.begin(),_data.end(),DPSCPair_SortByTimeDifference);
77 
78  return NOERROR;
79 }
80 
81 //------------------
82 // erun
83 //------------------
84 jerror_t DPSCPair_factory::erun(void)
85 {
86  return NOERROR;
87 }
88 
89 //------------------
90 // fini
91 //------------------
92 jerror_t DPSCPair_factory::fini(void)
93 {
94  return NOERROR;
95 }
96 
pair< const DPSCHit *, const DPSCHit * > ee
Definition: DPSCPair.h:19
bool DPSCPair_SortByTimeDifference(const DPSCPair *pair1, const DPSCPair *pair2)
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
jerror_t fini(void)
Called after last event of last event source has been processed.
jerror_t init(void)
Called once at program start.