Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DChargedTrack_factory_Combo.cc
Go to the documentation of this file.
2 
3 //------------------
4 // init
5 //------------------
7 {
8  dTrackSelectionTag = "PreSelect";
9  gPARMS->SetDefaultParameter("COMBO:TRACK_SELECT_TAG", dTrackSelectionTag);
10 
11  return NOERROR;
12 }
13 
14 //------------------
15 // brun
16 //------------------
17 jerror_t DChargedTrack_factory_Combo::brun(jana::JEventLoop *locEventLoop, int32_t runnumber)
18 {
19  vector<const DChargedTrackHypothesis*> locChargedTrackHypotheses;
20  locEventLoop->Get(locChargedTrackHypotheses); //make sure that brun() is called for the default factory!!!
21  dChargedTrackHypothesisFactory = static_cast<DChargedTrackHypothesis_factory*>(locEventLoop->GetFactory("DChargedTrackHypothesis"));
22 
23  return NOERROR;
24 }
25 
26 //------------------
27 // evnt
28 //------------------
29 jerror_t DChargedTrack_factory_Combo::evnt(jana::JEventLoop *locEventLoop, uint64_t eventnumber)
30 {
32 
33  vector<const DChargedTrack*> locChargedTracks;
34  locEventLoop->Get(locChargedTracks, dTrackSelectionTag.c_str());
35 
36  map<JObject::oid_t, const DChargedTrack*> locTrackToCandidateID;
37  for(auto locChargedTrack : locChargedTracks)
38  locTrackToCandidateID.emplace(locChargedTrack->candidateid, locChargedTrack);
39 
40  vector<const DTrackTimeBased*> locTimeBasedTracks;
41  locEventLoop->Get(locTimeBasedTracks, "Combo");
42 
43  const DEventRFBunch* locEventRFBunch = nullptr;
44  locEventLoop->GetSingle(locEventRFBunch);
45 
46  const DDetectorMatches* locDetectorMatches = nullptr;
47  locEventLoop->GetSingle(locDetectorMatches, "Combo");
48 
49  //Sort new time-based tracks by charged track
50  unordered_map<const DChargedTrack*, vector<const DTrackTimeBased*>> locTimeBasedByChargedTrack;
51  for(auto& locTimeBasedTrack : locTimeBasedTracks)
52  {
53  auto locChargedTrack = locTrackToCandidateID[locTimeBasedTrack->candidateid];
54  locTimeBasedByChargedTrack[locChargedTrack].push_back(locTimeBasedTrack);
55  }
56 
57  //create and add new hypos
58  for(auto& locChargedTrack : locChargedTracks)
59  {
60  auto locNewChargedTrack = new DChargedTrack(*locChargedTrack);
61  for(auto& locTimeBasedTrack : locTimeBasedByChargedTrack[locChargedTrack])
62  {
63  //create new DChargedTrackHypothesis object
64  auto locNewChargedTrackHypothesis = dChargedTrackHypothesisFactory->Create_ChargedTrackHypothesis(locEventLoop, locTimeBasedTrack, locDetectorMatches, locEventRFBunch);
65  locNewChargedTrackHypothesis->AddAssociatedObject(locNewChargedTrack);
66  dCreatedHypotheses.push_back(locNewChargedTrackHypothesis);
67  locNewChargedTrack->dChargedTrackHypotheses.push_back(locNewChargedTrackHypothesis);
68  }
69  locNewChargedTrack->AddAssociatedObject(locChargedTrack);
70  _data.push_back(locNewChargedTrack);
71  }
72 
73  return NOERROR;
74 }
jerror_t brun(jana::JEventLoop *locEventLoop, int32_t runnumber)
Called everytime a new run number is detected.
vector< DChargedTrackHypothesis * > dCreatedHypotheses
DChargedTrackHypothesis * Create_ChargedTrackHypothesis(JEventLoop *locEventLoop, const DTrackTimeBased *locTrackTimeBased, const DDetectorMatches *locDetectorMatches, const DEventRFBunch *locEventRFBunch)
jerror_t init(void)
Called once at program start.
DChargedTrackHypothesis_factory * dChargedTrackHypothesisFactory
void Recycle_Hypotheses(vector< const DChargedTrackHypothesis * > &locHypos)
jerror_t evnt(jana::JEventLoop *locEventLoop, uint64_t eventnumber)
Called every event.