Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DChargedTrack_factory_PreSelect.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DChargedTrack_factory_PreSelect.cc
4 // Created: Thu Dec 3 17:27:55 EST 2009
5 // Creator: staylor (on Linux ifarml6 2.6.18-128.el5 x86_64)
6 //
7 
9 
10 //------------------
11 // init
12 //------------------
14 {
15  //Setting this flag makes it so that JANA does not delete the objects in _data. This factory will manage this memory.
16  //This is because some/all of these pointers are just copied from earlier objects, and should not be deleted.
17  SetFactoryFlag(NOT_OBJECT_OWNER);
18 
19  dMinTrackingFOM = -1.0;
20  dHasDetectorMatchFlag = true; //require tracks to have a detector match
21 
22  return NOERROR;
23 }
24 
25 //------------------
26 // brun
27 //------------------
28 jerror_t DChargedTrack_factory_PreSelect::brun(jana::JEventLoop *locEventLoop, int32_t runnumber)
29 {
30  gPARMS->SetDefaultParameter("PRESELECT:MIN_TRACKING_FOM", dMinTrackingFOM);
31  gPARMS->SetDefaultParameter("PRESELECT:HAS_DETECTOR_MATCH_FLAG", dHasDetectorMatchFlag);
32 
33  return NOERROR;
34 }
35 
36 //------------------
37 // evnt
38 //------------------
39 jerror_t DChargedTrack_factory_PreSelect::evnt(jana::JEventLoop *locEventLoop, uint64_t eventnumber)
40 {
41  //Clear objects from last event
42  _data.clear();
43 
44  vector<const DChargedTrack*> locChargedTracks;
45  locEventLoop->Get(locChargedTracks);
46 
47  const DDetectorMatches* locDetectorMatches = NULL;
48  locEventLoop->GetSingle(locDetectorMatches);
49 
50  //cut on min-tracking-FOM and has-detector-match
51  for(size_t loc_i = 0; loc_i < locChargedTracks.size(); ++loc_i)
52  {
53  for(auto& locChargedHypo : locChargedTracks[loc_i]->dChargedTrackHypotheses)
54  {
55  if(!Cut_TrackingFOM(locChargedHypo))
56  continue;
57  if(!Cut_HasDetectorMatch(locChargedHypo, locDetectorMatches))
58  continue;
59 
60  _data.push_back(const_cast<DChargedTrack*>(locChargedTracks[loc_i])); //don't cut: copy it
61  break;
62  }
63  }
64 
65  return NOERROR;
66 }
67 
68 bool DChargedTrack_factory_PreSelect::Cut_HasDetectorMatch(const DChargedTrackHypothesis* locChargedTrackHypothesis, const DDetectorMatches* locDetectorMatches) const
69 {
71  return true;
72  auto locTrackTimeBased = locChargedTrackHypothesis->Get_TrackTimeBased();
73  return locDetectorMatches->Get_IsMatchedToHit(locTrackTimeBased);
74 }
75 
77 {
78  auto locTrackTimeBased = locChargedTrackHypothesis->Get_TrackTimeBased();
79  double locFOM = TMath::Prob(locTrackTimeBased->chisq, locTrackTimeBased->Ndof);
80  return ((locTrackTimeBased->Ndof == 0) ? true : (locFOM >= dMinTrackingFOM));
81 }
82 
83 //------------------
84 // erun
85 //------------------
87 {
88  return NOERROR;
89 }
90 
91 //------------------
92 // fini
93 //------------------
95 {
96  return NOERROR;
97 }
98 
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
jerror_t init(void)
Called once at program start.
bool Cut_TrackingFOM(const DChargedTrackHypothesis *locChargedTrackHypothesis) const
const DTrackTimeBased * Get_TrackTimeBased(void) const
jerror_t evnt(jana::JEventLoop *locEventLoop, uint64_t eventnumber)
Called every event.
jerror_t fini(void)
Called after last event of last event source has been processed.
bool Get_IsMatchedToHit(const DTrackingData *locTrack) const
jerror_t brun(jana::JEventLoop *locEventLoop, int32_t runnumber)
Called everytime a new run number is detected.
bool Cut_HasDetectorMatch(const DChargedTrackHypothesis *locChargedTrackHypothesis, const DDetectorMatches *locDetectorMatches) const