Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DDetectorMatches_factory_WireBased.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DDetectorMatches_factory_WireBased.cc
4 // Created: Tue Aug 9 14:29:24 EST 2011
5 // Creator: pmatt (on Linux ifarml6 2.6.18-128.el5 x86_64)
6 //
7 
9 
10 //------------------
11 // init
12 //------------------
14 {
15  return NOERROR;
16 }
17 
18 //------------------
19 // brun
20 //------------------
21 jerror_t DDetectorMatches_factory_WireBased::brun(jana::JEventLoop *locEventLoop, int32_t runnumber)
22 {
23  //LEAVE THIS EMPTY!!! OR ELSE WON'T BE INITIALIZED PROPERLY WHEN "COMBO" FACTORY CALLS Create_DDetectorMatches ON REST DATA!!
24  return NOERROR;
25 }
26 
27 //------------------
28 // evnt
29 //------------------
30 jerror_t DDetectorMatches_factory_WireBased::evnt(jana::JEventLoop* locEventLoop, uint64_t eventnumber)
31 {
32  vector<const DTrackWireBased*> locTrackWireBasedVector;
33  locEventLoop->Get(locTrackWireBasedVector);
34 
35  DDetectorMatches* locDetectorMatches = Create_DDetectorMatches(locEventLoop, locTrackWireBasedVector);
36  _data.push_back(locDetectorMatches);
37 
38  return NOERROR;
39 }
40 
41 DDetectorMatches* DDetectorMatches_factory_WireBased::Create_DDetectorMatches(jana::JEventLoop* locEventLoop, vector<const DTrackWireBased*>& locTrackWireBasedVector)
42 {
43  const DParticleID* locParticleID = NULL;
44  locEventLoop->GetSingle(locParticleID);
45 
46  vector<const DSCHit*> locSCHits;
47  locEventLoop->Get(locSCHits);
48 
49  vector<const DTOFPoint*> locTOFPoints;
50  locEventLoop->Get(locTOFPoints);
51 
52  vector<const DFCALShower*> locFCALShowers;
53  locEventLoop->Get(locFCALShowers);
54 
55  vector<const DBCALShower*> locBCALShowers;
56  locEventLoop->Get(locBCALShowers);
57 
58  DDetectorMatches* locDetectorMatches = new DDetectorMatches();
59 
60  //Match tracks to showers/hits
61  for(size_t loc_i = 0; loc_i < locTrackWireBasedVector.size(); ++loc_i)
62  {
63  MatchToBCAL(locParticleID, locTrackWireBasedVector[loc_i], locBCALShowers, locDetectorMatches);
64  MatchToTOF(locParticleID, locTrackWireBasedVector[loc_i], locTOFPoints, locDetectorMatches);
65  MatchToFCAL(locParticleID, locTrackWireBasedVector[loc_i], locFCALShowers, locDetectorMatches);
66  MatchToSC(locParticleID, locTrackWireBasedVector[loc_i], locSCHits, locDetectorMatches);
67  }
68 
69  //Find nearest tracks to showers
70  for(size_t loc_i = 0; loc_i < locBCALShowers.size(); ++loc_i)
71  MatchToTrack(locParticleID, locBCALShowers[loc_i], locTrackWireBasedVector, locDetectorMatches);
72  for(size_t loc_i = 0; loc_i < locFCALShowers.size(); ++loc_i)
73  MatchToTrack(locParticleID, locFCALShowers[loc_i], locTrackWireBasedVector, locDetectorMatches);
74 
75  //Set flight-time/p correlations
76  for(size_t loc_i = 0; loc_i < locTrackWireBasedVector.size(); ++loc_i)
77  {
78  double locFlightTimePCorrelation = locParticleID->Calc_BCALFlightTimePCorrelation(locTrackWireBasedVector[loc_i], locDetectorMatches);
79  if(isfinite(locFlightTimePCorrelation))
80  locDetectorMatches->Set_FlightTimePCorrelation(locTrackWireBasedVector[loc_i], SYS_BCAL, locFlightTimePCorrelation);
81 
82  locFlightTimePCorrelation = locParticleID->Calc_TOFFlightTimePCorrelation(locTrackWireBasedVector[loc_i], locDetectorMatches);
83  if(isfinite(locFlightTimePCorrelation))
84  locDetectorMatches->Set_FlightTimePCorrelation(locTrackWireBasedVector[loc_i], SYS_TOF, locFlightTimePCorrelation);
85 
86  locFlightTimePCorrelation = locParticleID->Calc_FCALFlightTimePCorrelation(locTrackWireBasedVector[loc_i], locDetectorMatches);
87  if(isfinite(locFlightTimePCorrelation))
88  locDetectorMatches->Set_FlightTimePCorrelation(locTrackWireBasedVector[loc_i], SYS_FCAL, locFlightTimePCorrelation);
89 
90  locFlightTimePCorrelation = locParticleID->Calc_SCFlightTimePCorrelation(locTrackWireBasedVector[loc_i], locDetectorMatches);
91  if(isfinite(locFlightTimePCorrelation))
92  locDetectorMatches->Set_FlightTimePCorrelation(locTrackWireBasedVector[loc_i], SYS_START, locFlightTimePCorrelation);
93  }
94 
95  return locDetectorMatches;
96 }
97 
98 void DDetectorMatches_factory_WireBased::MatchToBCAL(const DParticleID* locParticleID, const DTrackWireBased* locTrackWireBased, const vector<const DBCALShower*>& locBCALShowers, DDetectorMatches* locDetectorMatches) const
99 {
100  if (locTrackWireBased->extrapolations.at(SYS_BCAL).size()==0) return;
101 
102  double locInputStartTime = locTrackWireBased->t0();
103  for(size_t loc_i = 0; loc_i < locBCALShowers.size(); ++loc_i)
104  {
105  shared_ptr<DBCALShowerMatchParams>locShowerMatchParams;
106  if(locParticleID->Cut_MatchDistance(locTrackWireBased->extrapolations.at(SYS_BCAL), locBCALShowers[loc_i], locInputStartTime, locShowerMatchParams))
107  locDetectorMatches->Add_Match(locTrackWireBased, locBCALShowers[loc_i], locShowerMatchParams);
108  }
109 }
110 
111 void DDetectorMatches_factory_WireBased::MatchToTOF(const DParticleID* locParticleID, const DTrackWireBased* locTrackWireBased, const vector<const DTOFPoint*>& locTOFPoints, DDetectorMatches* locDetectorMatches) const
112 {
113  double locInputStartTime = locTrackWireBased->t0();
114  const vector<DTrackFitter::Extrapolation_t>extrapolations=locTrackWireBased->extrapolations.at(SYS_TOF);
115  for(size_t loc_i = 0; loc_i < locTOFPoints.size(); ++loc_i)
116  {
117  shared_ptr<DTOFHitMatchParams>locTOFHitMatchParams;
118  if(locParticleID->Cut_MatchDistance(extrapolations, locTOFPoints[loc_i], locInputStartTime, locTOFHitMatchParams))
119  locDetectorMatches->Add_Match(locTrackWireBased, locTOFPoints[loc_i], locTOFHitMatchParams);
120  }
121 }
122 
123 void DDetectorMatches_factory_WireBased::MatchToFCAL(const DParticleID* locParticleID, const DTrackWireBased* locTrackWireBased, const vector<const DFCALShower*>& locFCALShowers, DDetectorMatches* locDetectorMatches) const
124 {
125  double locInputStartTime = locTrackWireBased->t0();
126  const vector<DTrackFitter::Extrapolation_t>extrapolations=locTrackWireBased->extrapolations.at(SYS_FCAL);
127  for(size_t loc_i = 0; loc_i < locFCALShowers.size(); ++loc_i)
128  {
129  shared_ptr<DFCALShowerMatchParams> locShowerMatchParams;
130  if(locParticleID->Cut_MatchDistance(extrapolations, locFCALShowers[loc_i], locInputStartTime, locShowerMatchParams))
131  locDetectorMatches->Add_Match(locTrackWireBased, locFCALShowers[loc_i], locShowerMatchParams);
132  }
133 }
134 
135 void DDetectorMatches_factory_WireBased::MatchToSC(const DParticleID* locParticleID, const DTrackWireBased* locTrackWireBased, const vector<const DSCHit*>& locSCHits, DDetectorMatches* locDetectorMatches) const
136 {
137  double locInputStartTime = locTrackWireBased->t0();
138  const vector<DTrackFitter::Extrapolation_t>extrapolations=locTrackWireBased->extrapolations.at(SYS_START);
139  for(size_t loc_i = 0; loc_i < locSCHits.size(); ++loc_i)
140  {
141  shared_ptr<DSCHitMatchParams> locSCHitMatchParams;
142  if(locParticleID->Cut_MatchDistance(extrapolations, locSCHits[loc_i], locInputStartTime, locSCHitMatchParams, true))
143  locDetectorMatches->Add_Match(locTrackWireBased, locSCHits[loc_i], locSCHitMatchParams);
144  }
145 }
146 
147 void DDetectorMatches_factory_WireBased::MatchToTrack(const DParticleID* locParticleID, const DBCALShower* locBCALShower, const vector<const DTrackWireBased*>& locTrackWireBasedVector, DDetectorMatches* locDetectorMatches) const
148 {
149  double locMinDistance = 999.0;
150  double locFinalDeltaPhi = 999.0, locFinalDeltaZ = 999.0;
151  for(size_t loc_i = 0; loc_i < locTrackWireBasedVector.size(); ++loc_i)
152  {
153  shared_ptr<DBCALShowerMatchParams> locShowerMatchParams;
154  double locInputStartTime = locTrackWireBasedVector[loc_i]->t0();
155  const vector<DTrackFitter::Extrapolation_t>extrapolations=locTrackWireBasedVector[loc_i]->extrapolations.at(SYS_BCAL);
156  if(!locParticleID->Distance_ToTrack(extrapolations, locBCALShower, locInputStartTime, locShowerMatchParams))
157  continue;
158 
159  double locRSq = locBCALShower->x*locBCALShower->x + locBCALShower->y*locBCALShower->y;
160  double locDeltaPhi = locShowerMatchParams->dDeltaPhiToShower;
161  double locDeltaZ = locShowerMatchParams->dDeltaZToShower;
162  double locDistance = sqrt(locDeltaZ*locDeltaZ + locDeltaPhi*locDeltaPhi*locRSq);
163  if(locDistance >= locMinDistance)
164  continue;
165 
166  locMinDistance = locDistance;
167  locFinalDeltaPhi = locDeltaPhi;
168  locFinalDeltaZ = locDeltaZ;
169  }
170  locDetectorMatches->Set_DistanceToNearestTrack(locBCALShower, locFinalDeltaPhi, locFinalDeltaZ);
171 }
172 
173 void DDetectorMatches_factory_WireBased::MatchToTrack(const DParticleID* locParticleID, const DFCALShower* locFCALShower, const vector<const DTrackWireBased*>& locTrackWireBasedVector, DDetectorMatches* locDetectorMatches) const
174 {
175  double locMinDistance = 999.0;
176  for(size_t loc_i = 0; loc_i < locTrackWireBasedVector.size(); ++loc_i)
177  {
178  shared_ptr<DFCALShowerMatchParams> locShowerMatchParams;
179  double locInputStartTime = locTrackWireBasedVector[loc_i]->t0();
180  const vector<DTrackFitter::Extrapolation_t>extrapolations=locTrackWireBasedVector[loc_i]->extrapolations.at(SYS_FCAL);
181  if(!locParticleID->Distance_ToTrack(extrapolations, locFCALShower, locInputStartTime, locShowerMatchParams))
182  continue;
183  if(locShowerMatchParams->dDOCAToShower < locMinDistance)
184  locMinDistance = locShowerMatchParams->dDOCAToShower;
185  }
186  locDetectorMatches->Set_DistanceToNearestTrack(locFCALShower, locMinDistance);
187 }
map< DetectorSystem_t, vector< DTrackFitter::Extrapolation_t > > extrapolations
jerror_t brun(jana::JEventLoop *locEventLoop, int32_t runnumber)
Called everytime a new run number is detected.
double t0(void) const
Definition: DTrackingData.h:23
jerror_t evnt(jana::JEventLoop *locEventLoop, uint64_t eventnumber)
Called every event.
double Calc_SCFlightTimePCorrelation(const DTrackingData *locTrack, const DDetectorMatches *locDetectorMatches) const
Definition: GlueX.h:19
jerror_t init(void)
Called once at program start.
void Add_Match(const DTrackingData *locTrack, const DBCALShower *locBCALShower, const shared_ptr< const DBCALShowerMatchParams > &locShowerMatchParams)
void MatchToTrack(const DParticleID *locParticleID, const DBCALShower *locBCALShower, const vector< const DTrackWireBased * > &locTrackWireBasedVector, DDetectorMatches *locDetectorMatches) const
double Calc_TOFFlightTimePCorrelation(const DTrackingData *locTrack, DDetectorMatches *locDetectorMatches) const
double Calc_FCALFlightTimePCorrelation(const DTrackingData *locTrack, DDetectorMatches *locDetectorMatches) const
double Calc_BCALFlightTimePCorrelation(const DTrackingData *locTrack, DDetectorMatches *locDetectorMatches) const
Definition: GlueX.h:20
void MatchToSC(const DParticleID *locParticleID, const DTrackWireBased *locTrackWireBased, const vector< const DSCHit * > &locSCHits, DDetectorMatches *locDetectorMatches) const
void Set_DistanceToNearestTrack(const DBCALShower *locBCALShower, double locDeltaPhi, double locDeltaZ)
Definition: GlueX.h:22
bool Cut_MatchDistance(const DReferenceTrajectory *rt, const DBCALShower *locBCALShower, double locInputStartTime, shared_ptr< DBCALShowerMatchParams > &locShowerMatchParams, DVector3 *locOutputProjPos=nullptr, DVector3 *locOutputProjMom=nullptr) const
void MatchToBCAL(const DParticleID *locParticleID, const DTrackWireBased *locTrackWireBased, const vector< const DBCALShower * > &locBCALShowers, DDetectorMatches *locDetectorMatches) const
double sqrt(double)
void MatchToTOF(const DParticleID *locParticleID, const DTrackWireBased *locTrackWireBased, const vector< const DTOFPoint * > &locTOFPoints, DDetectorMatches *locDetectorMatches) const
bool Distance_ToTrack(const DReferenceTrajectory *rt, const DFCALShower *locFCALShower, double locInputStartTime, shared_ptr< DFCALShowerMatchParams > &locShowerMatchParams, DVector3 *locOutputProjPos=nullptr, DVector3 *locOutputProjMom=nullptr) const
Definition: DParticleID.cc:737
DDetectorMatches * Create_DDetectorMatches(jana::JEventLoop *locEventLoop, vector< const DTrackWireBased * > &locTrackWireBasedVector)
void Set_FlightTimePCorrelation(const DTrackingData *locTrack, DetectorSystem_t locDetectorSystem, double locCorrelation)
void MatchToFCAL(const DParticleID *locParticleID, const DTrackWireBased *locTrackWireBased, const vector< const DFCALShower * > &locFCALShowers, DDetectorMatches *locDetectorMatches) const