Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DTrackCandidate_factory_CDC_or_FDCpseudo.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DTrackCandidate_factory_CDC_or_FDCpseudo.cc
4 // Created: Thu Apr 16 09:14:49 EDT 2009
5 // Creator: davidl (on Darwin harriet.jlab.org 9.6.0 i386)
6 //
7 
8 
9 #include <iostream>
10 #include <iomanip>
11 using namespace std;
12 
14 using namespace jana;
15 
16 //------------------
17 // init
18 //------------------
20 {
21  DEBUG_LEVEL = 0;
22 
23  gPARMS->SetDefaultParameter("TRKFIND:DEBUG_LEVEL", DEBUG_LEVEL);
24 
25  return NOERROR;
26 }
27 
28 //------------------
29 // brun
30 //------------------
31 jerror_t DTrackCandidate_factory_CDC_or_FDCpseudo::brun(jana::JEventLoop *eventLoop, int32_t runnumber)
32 {
33 
34  return NOERROR;
35 }
36 
37 //------------------
38 // evnt
39 //------------------
40 jerror_t DTrackCandidate_factory_CDC_or_FDCpseudo::evnt(JEventLoop *loop, uint64_t eventnumber)
41 {
42 
43  /// This factory simply combines the list of candidates from the
44  /// DTrackCandidate:CDC and DTrackCandidate:FDCpseudo factories
45  /// into a single lit. It simply copies the pointers and flags
46  /// itself as not being the owner of any of these objects.
47  vector<const DTrackCandidate*> cdc;
48  vector<const DTrackCandidate*> fdc;
49 
50  loop->Get(cdc, "CDC");
51  loop->Get(fdc, "FDCpseudo");
52 
53  // Add FDC candidates
54  if(DEBUG_LEVEL>2)_DBG_<<"Copying "<<fdc.size()<<" FDC generated candidates to final list"<<endl;
55  for(unsigned int i=0; i<fdc.size(); i++)_data.push_back((DTrackCandidate*)fdc[i]);
56 
57  // Add CDC candidates providing they aren't clones of ones already added
58  if(DEBUG_LEVEL>2)_DBG_<<"Checking "<<cdc.size()<<" CDC generated candidates for inclusion in final list ..."<<endl;
59  for(unsigned int i=0; i<cdc.size(); i++){
60  // Look to see that we don't already have a similar candidate in the list
61  DVector3 mom1 = cdc[i]->momentum();
62  DVector3 pos1 = cdc[i]->position();
63  double q1 = cdc[i]->charge();
64  bool is_clone = false;
65  for(unsigned int j=0; j<_data.size(); j++){
66  DVector3 mom2 = _data[j]->momentum();
67  DVector3 pos2 = _data[j]->position();
68  double q2 = _data[j]->charge();
69  double curvature_diff = fabs(1.0/mom1.Mag() - 1.0/mom2.Mag())/((1.0/mom1.Mag() + 1.0/mom2.Mag())/2.0);
70  double relative_mom_diff = fabs(mom1.Mag()-mom2.Mag())/((mom1.Mag()+mom2.Mag())/2.0);
71  if(DEBUG_LEVEL>4)_DBG_<<"q1="<<q1<<" q2="<<q2<<" mom1,mom2 angle:"<<mom1.Angle(mom2)*57.3<<" curvature diff:"<<curvature_diff<<" relative_mom_diff:"<<relative_mom_diff<<" pos diff:"<<(pos1-pos2).Mag()<<endl;
72  if(q1!=q2)continue;
73  if(mom1.Angle(mom2)*57.3<5.0){ // Angle within 5 degrees
74  if(curvature_diff<0.15 || relative_mom_diff<0.15){ // curvature or momentum within 15 % (should use Perp, but this avoids division by zero)
75  if((pos1-pos2).Mag()<30.0){ // vertex position within 30cm
76  is_clone = true;
77  if(DEBUG_LEVEL>1)_DBG_<<" CDC candidate "<<i<<" is a clone of candidate "<<j<<" dropping."<<endl;
78  break;
79  }
80  }
81  }
82  }
83  if(!is_clone){
84  _data.push_back((DTrackCandidate*)cdc[i]);
85  }
86  }
87 
88  SetFactoryFlag(NOT_OBJECT_OWNER); // make sure these aren't deleted twice
89 
90  return NOERROR;
91 }
92 
93 //------------------
94 // erun
95 //------------------
97 {
98  return NOERROR;
99 }
100 
101 //------------------
102 // fini
103 //------------------
105 {
106  return NOERROR;
107 }
108 
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
TVector3 DVector3
Definition: DVector3.h:14
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
#define _DBG_
Definition: HDEVIO.h:12
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
&lt;A href=&quot;index.html#legend&quot;&gt; &lt;IMG src=&quot;CORE.png&quot; width=&quot;100&quot;&gt; &lt;/A&gt;
jerror_t fini(void)
Called after last event of last event source has been processed.