Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_dumpcandidates.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_dumpcandidates.cc
4 // Created: Tue Feb 4 09:29:35 EST 2014
5 // Creator: davidl (on Linux ifarm1102 2.6.32-220.7.1.el6.x86_64 x86_64)
6 //
7 
9 using namespace jana;
10 
11 
12 // Routine used to create our JEventProcessor
13 #include <JANA/JApplication.h>
14 
17 #include <TRACKING/DTrackFitter.h>
18 #include <CDC/DCDCTrackHit.h>
19 #include <FDC/DFDCPseudo.h>
20 
21 extern "C"{
22 void InitPlugin(JApplication *app){
23  InitJANAPlugin(app);
24  app->AddProcessor(new JEventProcessor_dumpcandidates());
25 }
26 } // "C"
27 
28 
29 //------------------
30 // JEventProcessor_dumpcandidates (Constructor)
31 //------------------
33 {
34  events_written = 0;
35  events_discarded = 0;
36 
37  beam_origin = DVector3(0.0, 0.0, 65.0);
38  beam_dir = DVector3(0.0, 0.0, 1.0);
39 }
40 
41 //------------------
42 // ~JEventProcessor_dumpcandidates (Destructor)
43 //------------------
45 {
46 
47 }
48 
49 //------------------
50 // init
51 //------------------
53 {
54  //
55  MAX_CANDIDATE_FILTER = 1000;
56  gPARMS->SetDefaultParameter("MAX_CANDIDATE_FILTER", MAX_CANDIDATE_FILTER, "Maximum number of candidates allowed in event before any are written to file.");
57 
58 
59  // Open output file
60  ofs = new ofstream("gluex_candidates.txt");
61 
62  return NOERROR;
63 }
64 
65 //------------------
66 // brun
67 //------------------
68 jerror_t JEventProcessor_dumpcandidates::brun(JEventLoop *eventLoop, int32_t runnumber)
69 {
70  // Get pointer to geometry object
71  DApplication* dapp=dynamic_cast<DApplication*>(japp);
72  dgeom = dapp->GetDGeometry(1);
73  if(!dgeom){
74  jerr << "Couldn't get DGeometry pointer!!" << endl;
75  return UNKNOWN_ERROR;
76  }
77 
78  // Get CDC wires
79  vector<vector<DCDCWire *> > cdcwires;
80  dgeom->GetCDCWires(cdcwires);
81 
82  // Get FDC wires
83  vector<vector<DFDCWire *> > fdcwires;
84  dgeom->GetFDCWires(fdcwires);
85 
86  LockState();
87  // Generate map keyed by wire object's address
88  // (in the form of an unsigned long) and whose
89  // value is the index of the wire (i.e. position
90  // as produced by dumpwires)
91  int index = 0;
92  for(unsigned int i=0; i<cdcwires.size(); i++){
93  vector<DCDCWire *> &wires = cdcwires[i];
94  for(unsigned int j=0; j<wires.size(); j++){
95 
96  DCDCWire *w = wires[j];
97  wireID[ GetCDCWireID(w) ] = index++;
98  }
99  }
100 
101  for(unsigned int i=0; i<fdcwires.size(); i++){
102  vector<DFDCWire *> &wires = fdcwires[i];
103  for(unsigned int j=0; j<wires.size(); j++){
104 
105  DFDCWire *w = wires[j];
106  wireID[ GetFDCWireID(w) ] = index++;
107  }
108  }
109  UnlockState();
110 
111  return NOERROR;
112 }
113 
114 //------------------
115 // evnt
116 //------------------
117 jerror_t JEventProcessor_dumpcandidates::evnt(JEventLoop *loop, uint64_t eventnumber)
118 {
119  // Get track candidates
120  vector<const DTrackCandidate*> candidates;
121  loop->Get(candidates);
122  if(candidates.size()==0 || candidates.size()>MAX_CANDIDATE_FILTER){
123  events_discarded++;
124  return NOERROR;
125  }
126 
127  // Get pointer to DTrackHitSelector object
128  vector<const DTrackHitSelector *> hitselectors;
129  loop->Get(hitselectors);
130  if(hitselectors.size()<1){
131  _DBG_<<"Unable to get a DTrackHitSelector object!"<<endl;
132  return UNKNOWN_ERROR;
133  }
134  const DTrackHitSelector * hitselector = hitselectors[0];
135 
136  // Get pointer to DTrackFitter object
137  vector<const DTrackFitter *> fitters;
138  loop->Get(fitters);
139  if(fitters.size()<1){
140  _DBG_<<"Unable to get a DTrackFitter object!"<<endl;
141  return UNKNOWN_ERROR;
142  }
143  DTrackFitter *fitter = const_cast<DTrackFitter*>(fitters[0]);
144 
145  for(unsigned int i=0; i<candidates.size(); i++){
146  const DTrackCandidate *can = candidates[i];
147 
148  // Create DReferenceTrajectory for this candidate
150  rt->SetDGeometry(dgeom);
151  rt->q = can->charge();
152  rt->SetMass(0.1396);
153  rt->Swim(can->position(),can->momentum(),can->charge());
154 
155  // Get hits to be used for the fit
156  vector<const DCDCTrackHit*> cdctrackhits;
157  vector<const DFDCPseudo*> fdcpseudos;
158  loop->Get(cdctrackhits);
159  loop->Get(fdcpseudos);
160  hitselector->GetAllHits(DTrackHitSelector::kHelical, rt, cdctrackhits, fdcpseudos, fitter);
161 
162  // Get list of wire ids
163  vector<int> wire_ids;
164  for(unsigned int j=0; j<cdctrackhits.size(); j++){
165  unsigned long id = GetCDCWireID( cdctrackhits[j]->wire );
166  wire_ids.push_back(GetWireIndex( id ));
167 
168  }
169  for(unsigned int j=0; j<fdcpseudos.size(); j++){
170  unsigned long id = GetFDCWireID( fdcpseudos[j]->wire );
171  wire_ids.push_back(GetWireIndex( id ));
172  }
173 
174  // To make it easier to compare to thrown values later,
175  // find the parameters of the trajectory point closest
176  // to the beamline
177  rt->Swim(can->position(),-can->momentum(),-can->charge());
178  DKinematicData kd = (*can);
179  DVector3 commonpos;
180  double doca, var_doca;
181  rt->FindPOCAtoLine(beam_origin, beam_dir, NULL, &kd, commonpos, doca, var_doca);
182 
183  // Write candidate to string
184  stringstream ss;
185  ss << can->charge();
186  ss << " " << kd.x() << " " << kd.y() << " " << kd.z();
187  ss << " " << -kd.px() << " " << -kd.py() << " " << -kd.pz();
188  for(unsigned int j=0; j<wire_ids.size(); j++){
189  ss << " " << wire_ids[j];
190  }
191 
192  // Write candidate string to file
193  (*ofs) << ss.str() << endl;
194  events_written++;
195  }
196 
197  return NOERROR;
198 }
199 
200 //------------------
201 // erun
202 //------------------
204 {
205  return NOERROR;
206 }
207 
208 //------------------
209 // fini
210 //------------------
212 {
213  if(ofs){
214  ofs->close();
215  delete ofs;
216  ofs =NULL;
217  }
218 
219  cout << endl;
220  cout << "Wrote " << events_written << " candidate events to output file (discarded " << events_discarded << ")" << endl;
221  cout << endl;
222 
223  return NOERROR;
224 }
225 
226 
227 
DApplication * dapp
double px(void) const
The DTrackFitter class is a base class for different charged track fitting algorithms. It does not actually fit the track itself, but provides the interface and some common support features most algorthims will need to implement.
Definition: DTrackFitter.h:61
double py(void) const
double z(void) const
jerror_t fini(void)
Called after last event of last event source has been processed.
TVector3 DVector3
Definition: DVector3.h:14
double pz(void) const
static vector< vector< DFDCWire * > > fdcwires
void SetMass(double mass)
const DVector3 & position(void) const
void Swim(const DVector3 &pos, const DVector3 &mom, double q=-1000.0, const TMatrixFSym *cov=NULL, double smax=2000.0, const DCoordinateSystem *wire=NULL)
double x(void) const
static char index(char c)
Definition: base64.cpp:115
The DTrackHitSelector class is a base class for algorithms that will select hits from the drift chamb...
void SetDGeometry(const DGeometry *geom)
bool GetCDCWires(vector< vector< DCDCWire * > > &cdcwires) const
Definition: DGeometry.cc:773
JApplication * japp
double y(void) const
InitPlugin_t InitPlugin
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
DGeometry * GetDGeometry(unsigned int run_number)
#define _DBG_
Definition: HDEVIO.h:12
double charge(void) const
&lt;A href=&quot;index.html#legend&quot;&gt; &lt;IMG src=&quot;CORE.png&quot; width=&quot;100&quot;&gt; &lt;/A&gt;
const DVector3 & momentum(void) const
const DTrackFitter * fitter
jerror_t FindPOCAtoLine(const DVector3 &origin, const DVector3 &dir, const DMatrixDSym *covpoint, DKinematicData *track_kd, DVector3 &commonpos, double &doca, double &var_doca) const
const DMagneticFieldMap * GetDMagneticFieldMap(void) const
Definition: DTrackFitter.h:168
jerror_t init(void)
Called once at program start.
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
void GetAllHits(fit_type_t fit_type, const DReferenceTrajectory *rt, const vector< const DCDCTrackHit * > &cdchits_in, const vector< const DFDCPseudo * > &fdchits_in, DTrackFitter *fitter, int N=20) const
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.