Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DTrackCandidate_factory_StraightLine.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DTrackCandidate_factory_StraightLine.cc
4 // Created: Fri Aug 15 09:14:04 EDT 2014
5 // Creator: staylor (on Linux ifarm1102 2.6.32-220.7.1.el6.x86_64 x86_64)
6 //
7 
8 
9 #include <iostream>
10 #include <iomanip>
11 using namespace std;
12 
13 #include <map>
14 
16 using namespace jana;
17 #include <JANA/JApplication.h>
18 #include <JANA/JCalibration.h>
19 #include <DANA/DApplication.h>
20 #include "HDGEOMETRY/DGeometry.h"
21 
22 //------------------
23 // init
24 //------------------
26 {
27  return NOERROR;
28 }
29 
30 //------------------
31 // brun
32 //------------------
33 jerror_t DTrackCandidate_factory_StraightLine::brun(jana::JEventLoop *loop, int runnumber)
34 {
35 
36  COSMICS=false;
37  gPARMS->SetDefaultParameter("TRKFIND:COSMICS",COSMICS);
38 
39  CHI2CUT = 15.0;
40  gPARMS->SetDefaultParameter("TRKFIT:CHI2CUT",CHI2CUT);
41 
42  DO_PRUNING = 1;
43  gPARMS->SetDefaultParameter("TRKFIT:DO_PRUNING",DO_PRUNING);
44 
45  DEBUG_HISTS=false;
46  gPARMS->SetDefaultParameter("TRKFIND:DEBUG_HISTS",DEBUG_HISTS);
47 
48 
49  USE_FDC_DRIFT_TIMES=true;
50  gPARMS->SetDefaultParameter("TRKFIT:USE_FDC_DRIFT_TIMES",
51  USE_FDC_DRIFT_TIMES);
52 
53  PLANE_TO_SKIP=0;
54  gPARMS->SetDefaultParameter("TRKFIT:PLANE_TO_SKIP",PLANE_TO_SKIP);
55 
56  SKIP_CDC=false;
57  gPARMS->SetDefaultParameter("TRKFIT:SKIP_CDC",SKIP_CDC);
58 
59  SKIP_FDC=false;
60  gPARMS->SetDefaultParameter("TRKFIT:SKIP_FDC",SKIP_FDC);
61 
62  // Get pointer to TrackFinder object
63  vector<const DTrackFinder *> finders;
64  loop->Get(finders);
65 
66  if(finders.size()<1){
67  _DBG_<<"Unable to get a DTrackFinder object!"<<endl;
68  return RESOURCE_UNAVAILABLE;
69  }
70 
71  // Drop the const qualifier from the DTrackFinder pointer
72  finder = const_cast<DTrackFinder*>(finders[0]);
73 
74  if (DEBUG_HISTS){
75  Hvres=(TH2F *)gROOT->FindObject("Hvres");
76  if (!Hvres) Hvres=new TH2F("Hvres","Residual along wire",100,-0.25,0.25,24,0.5,24.5);
77  hFDCOccTrkFind=new TH1I("Occ form track finding", "Occ per plane", 24,0.5,24.5);
78  hFDCOccTrkFit=new TH1I("Occ form track fitting", "Occ per plane", 24,0.5,24.5);
79  hFDCOccTrkSmooth=new TH1I("Occ form track smoothing", "Occ per plane", 24,0.5,24.5);
80  }
81 
82  // TMatrix pool
83  dResourcePool_TMatrixFSym = std::make_shared<DResourcePool<TMatrixFSym>>();
84  dResourcePool_TMatrixFSym->Set_ControlParams(20, 20, 50);
85 
86  return NOERROR;
87 }
88 
89 //------------------
90 // evnt
91 //------------------
92 jerror_t DTrackCandidate_factory_StraightLine::evnt(JEventLoop *loop, uint64_t eventnumber)
93 {
94 
95  // Reset the track finder
96  finder->Reset();
97 
98  vector<const DCDCTrackHit*>cdcs;
99  vector<const DFDCPseudo*>pseudos;
100  loop->Get(cdcs);
101  loop->Get(pseudos);
102 
103  set<unsigned int> used_cdc;
104 
105  // Look for tracks in the FDC.
106  if(!SKIP_FDC){
107  if (pseudos.size()>4){
108  for (size_t i=0;i<pseudos.size();i++) finder->AddHit(pseudos[i]);
109  finder->FindFDCSegments();
110  finder->LinkFDCSegments();
111 
112  // Get the list of linked segments and fit the hits to lines
113  const vector<DTrackFinder::fdc_segment_t>tracks=finder->GetFDCTracks();
114  for (size_t i=0;i<tracks.size();i++){
115  // Create new track candidate
116  DTrackCandidate *cand = new DTrackCandidate;
117  cand->setPID(PiPlus);
118 
119  // Add hits as associated objects
120  vector<const DFDCPseudo *>hits=tracks[i].hits;
121  for (unsigned int k=0;k<hits.size();k++){
122  cand->AddAssociatedObject(hits[k]);
123  if(DEBUG_HISTS){
124  hFDCOccTrkFind->Fill(hits[k]->wire->layer);
125  }
126  }
127 
128  // Set position and momentum
129  double tx=tracks[i].S(state_tx),ty=tracks[i].S(state_ty);
130  double phi=atan2(ty,tx);
131  double tanl=1./sqrt(tx*tx+ty*ty);
132  double pt=5.0*cos(atan(tanl)); // arbitrary magnitude...
133  cand->setMomentum(DVector3(pt*cos(phi),pt*sin(phi),pt*tanl));
134 
135  DVector3 pos,origin,dir(0,0,1.);
136  finder->FindDoca(0,tracks[i].S,dir,origin,&pos);
137  cand->setPosition(pos);
138 
139  _data.push_back(cand);
140 
141  }
142  }
143  }
144 
145  if(!SKIP_CDC){
146  if (cdcs.size()>4){
147  for (size_t i=0;i<cdcs.size();i++) {
148  // If the CDC hit had not been grabbed by the FDC fit, try to find CDC only tracks.
149  if(used_cdc.find(i) == used_cdc.end()) finder->AddHit(cdcs[i]);
150  }
151  finder->FindAxialSegments();
152  finder->LinkCDCSegments();
153 
154  // Get the list of linked segments and fit the hits to lines
155  const vector<DTrackFinder::cdc_track_t>tracks=finder->GetCDCTracks();
156  for (size_t i=0;i<tracks.size();i++){
157  // Create new track candidate
158  DTrackCandidate *cand = new DTrackCandidate;
159  cand->setPID(PiPlus);
160 
161  // Add hits as associated objects
162  // list of axial and stereo hits for this track
163  vector<const DCDCTrackHit *>hits=tracks[i].axial_hits;
164  for (unsigned int k=0;k<hits.size();k++){
165  cand->AddAssociatedObject(hits[k]);
166  }
167  hits=tracks[i].stereo_hits;
168  for (unsigned int k=0;k<hits.size();k++){
169  cand->AddAssociatedObject(hits[k]);
170  }
171 
172  double z=tracks[i].z;
173  // state vector
174  DMatrix4x1 S(tracks[i].S);
175  double tx=tracks[i].S(state_tx),ty=tracks[i].S(state_ty);
176  double phi=atan2(ty,tx);
177  double tanl=1./sqrt(tx*tx+ty*ty);
178  // Check for tracks heading upstream
179  double phi_diff=phi-hits[0]->wire->origin.Phi()-M_PI;
180  if (phi_diff<-M_PI) phi_diff+=2.*M_PI;
181  if (phi_diff> M_PI) phi_diff-=2.*M_PI;
182  if (fabs(phi_diff)<M_PI_2){
183  tanl*=-1;
184  phi+=M_PI;
185  }
186  double pt=5.*cos(atan(tanl)); //arbitrary magnitude...
187  cand->setMomentum(DVector3(pt*cos(phi),pt*sin(phi),pt*tanl));
188 
189  if (COSMICS==false){
190  DVector3 pos,origin,dir(0,0,1.);
191  finder->FindDoca(z,tracks[i].S,dir,origin,&pos);
192  cand->setPosition(pos);
193  }
194  else{
195  cand->setPosition(DVector3(tracks[i].S(state_x),
196  tracks[i].S(state_y),z));
197  }
198 
199  _data.push_back(cand);
200  }
201  }
202  }
203 
204  // Set CDC ring & FDC plane hit patterns
205  for(size_t loc_i = 0; loc_i < _data.size(); ++loc_i)
206  {
207  vector<const DCDCTrackHit*> locCDCTrackHits;
208  _data[loc_i]->Get(locCDCTrackHits);
209 
210  vector<const DFDCPseudo*> locFDCPseudos;
211  _data[loc_i]->Get(locFDCPseudos);
212 
213  _data[loc_i]->dCDCRings = dParticleID->Get_CDCRingBitPattern(locCDCTrackHits);
214  _data[loc_i]->dFDCPlanes = dParticleID->Get_FDCPlaneBitPattern(locFDCPseudos);
215  }
216 
217  return NOERROR;
218 }
219 
220 //------------------
221 // erun
222 //------------------
224 {
225  return NOERROR;
226 }
227 
228 //------------------
229 // fini
230 //------------------
232 {
233  return NOERROR;
234 }
void setMomentum(const DVector3 &aMomentum)
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
TVector3 DVector3
Definition: DVector3.h:14
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
jerror_t init(void)
Called once at program start.
jerror_t fini(void)
Called after last event of last event source has been processed.
TLatex tx
#define _DBG_
Definition: HDEVIO.h:12
&lt;A href=&quot;index.html#legend&quot;&gt; &lt;IMG src=&quot;CORE.png&quot; width=&quot;100&quot;&gt; &lt;/A&gt;
void setPID(Particle_t locPID)
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
double sqrt(double)
double sin(double)
#define S(str)
Definition: hddm-c.cpp:84
void setPosition(const DVector3 &aPosition)
TDirectory * dir
Definition: bcal_hist_eff.C:31