17 dMinTrackingFOM = 0.001;
19 dMinHitRingsPerCDCSuperlayer = 2;
20 dMinHitPlanesPerFDCPackage = 4;
22 string locSystemName =
"";
23 gPARMS->SetDefaultParameter(
"RF_CALIB:SOURCE_SYSTEM", locSystemName);
24 if(locSystemName !=
"")
25 dRFTDCSourceSystem =
NameToSystem(locSystemName.c_str());
39 vector<double> locBeamPeriodVector;
40 locEventLoop->GetCalib(
"PHOTON_BEAM/RF/beam_period", locBeamPeriodVector);
41 dBeamBunchPeriod = locBeamPeriodVector[0];
43 double locTargetCenterZ;
45 dTargetCenter.SetXYZ(0.0, 0.0, locTargetCenterZ);
47 locEventLoop->GetSingle(dParticleID);
50 dCutAction_TrackHitPattern->Initialize(locEventLoop);
68 vector<const DTrackWireBased*> locTrackWireBasedVector;
69 Select_GoodTracks(locEventLoop, locTrackWireBasedVector);
72 vector<const DRFTDCDigiTime*> locRFTDCDigiTimes;
73 locEventLoop->Get(locRFTDCDigiTimes);
76 locEventLoop->GetSingle(locTTabUtilities);
78 double locRFTime = numeric_limits<double>::quiet_NaN();
79 bool locHitFoundFlag =
false;
80 for(
size_t loc_i = 0; loc_i < locRFTDCDigiTimes.size(); ++loc_i)
83 if(locRFTDCDigiTime->
dSystem != dRFTDCSourceSystem)
91 locHitFoundFlag =
true;
96 return Create_NaNRFBunch();
99 return Select_RFBunch(locEventLoop, locTrackWireBasedVector, locRFTime);
108 locSelectedWireBasedTracks.clear();
110 vector<const DTrackWireBased*> locTrackWireBasedVector;
111 locEventLoop->Get(locTrackWireBasedVector);
114 map<JObject::oid_t, const DTrackWireBased*> locBestTrackWireBasedMap;
115 for(
size_t loc_i = 0; loc_i < locTrackWireBasedVector.size(); ++loc_i)
117 if(locTrackWireBasedVector[loc_i]->FOM < dMinTrackingFOM)
119 if(!dCutAction_TrackHitPattern->Cut_TrackHitPattern(dParticleID, locTrackWireBasedVector[loc_i]))
121 JObject::oid_t locCandidateID = locTrackWireBasedVector[loc_i]->candidateid;
122 if(locBestTrackWireBasedMap.find(locCandidateID) == locBestTrackWireBasedMap.end())
123 locBestTrackWireBasedMap[locCandidateID] = locTrackWireBasedVector[loc_i];
124 else if(locTrackWireBasedVector[loc_i]->FOM > (dynamic_cast<const DTrackWireBased*>(locBestTrackWireBasedMap[locCandidateID]))->FOM)
125 locBestTrackWireBasedMap[locCandidateID] = locTrackWireBasedVector[loc_i];
129 map<JObject::oid_t, const DTrackWireBased*>::iterator locIterator;
130 for(locIterator = locBestTrackWireBasedMap.begin(); locIterator != locBestTrackWireBasedMap.end(); ++locIterator)
131 locSelectedWireBasedTracks.push_back(locIterator->second);
140 vector<const DDetectorMatches*> locDetectorMatchVector;
141 locEventLoop->Get(locDetectorMatchVector,
"WireBased");
142 if(locDetectorMatchVector.empty())
144 cout <<
"WARNING: WIREBASED TRACKS NOT PRESENT IN DEventRFBunch_factory_Calibrations(). RETURNING NaN." << endl;
145 return Create_NaNRFBunch();
149 vector<pair<double, const JObject*> > locTimes;
150 int locBestRFBunchShift = 0, locHighestNumVotes = 0;
153 if(Find_TrackTimes_SC(locDetectorMatches, locTrackWireBasedVector, locTimes))
154 locBestRFBunchShift = Conduct_Vote(locEventLoop, locRFTime, locTimes, locHighestNumVotes);
156 return Create_NaNRFBunch();
159 locEventRFBunch->
dTime = locRFTime + dBeamBunchPeriod*double(locBestRFBunchShift);
163 _data.push_back(locEventRFBunch);
171 for(
size_t loc_i = 0; loc_i < locTrackWireBasedVector.size(); ++loc_i)
173 const DTrackWireBased* locTrackWireBased = locTrackWireBasedVector[loc_i];
175 shared_ptr<const DSCHitMatchParams> locSCHitMatchParams;
176 if(!dParticleID->Get_BestSCMatchParams(locTrackWireBased, locDetectorMatches, locSCHitMatchParams))
179 double locPropagatedTime = locSCHitMatchParams->dHitTime - locSCHitMatchParams->dFlightTime + (dTargetCenter.Z() - locTrackWireBased->
z())/29.9792458;
180 locTimes.push_back(pair<double, const JObject*>(locPropagatedTime, locTrackWireBased));
183 return (!locTimes.empty());
188 map<int, vector<const JObject*> > locNumBeamBucketsShiftedMap;
189 set<int> locBestRFBunchShifts;
191 locHighestNumVotes = Find_BestRFBunchShifts(locRFTime, locTimes, locNumBeamBucketsShiftedMap, locBestRFBunchShifts);
192 if(locBestRFBunchShifts.size() == 1)
193 return *locBestRFBunchShifts.begin();
196 return Break_TieVote_Tracks(locNumBeamBucketsShiftedMap, locBestRFBunchShifts);
202 int locHighestNumVotes = 0;
203 locNumBeamBucketsShiftedMap.clear();
204 locBestRFBunchShifts.clear();
206 for(
unsigned int loc_i = 0; loc_i < locTimes.size(); ++loc_i)
208 double locDeltaT = locTimes[loc_i].first - locRFHitTime;
209 int locNumBeamBucketsShifted = (locDeltaT > 0.0) ? int(locDeltaT/dBeamBunchPeriod + 0.5) : int(locDeltaT/dBeamBunchPeriod - 0.5);
210 locNumBeamBucketsShiftedMap[locNumBeamBucketsShifted].push_back(locTimes[loc_i].second);
212 int locNumVotesThisShift = locNumBeamBucketsShiftedMap[locNumBeamBucketsShifted].size();
213 if(locNumVotesThisShift > locHighestNumVotes)
215 locHighestNumVotes = locNumVotesThisShift;
216 locBestRFBunchShifts.clear();
217 locBestRFBunchShifts.insert(locNumBeamBucketsShifted);
219 else if(locNumVotesThisShift == locHighestNumVotes)
220 locBestRFBunchShifts.insert(locNumBeamBucketsShifted);
223 return locHighestNumVotes;
232 int locBestRFBunchShift = 0;
233 pair<int, double> locBestTrackingTotals(-1, 9.9E99);
235 set<int>::const_iterator locSetIterator = locBestRFBunchShifts.begin();
236 for(; locSetIterator != locBestRFBunchShifts.end(); ++locSetIterator)
238 int locRFBunchShift = *locSetIterator;
239 int locTotalTrackingNDF = 0;
240 double locTotalTrackingChiSq = 0.0;
242 const vector<const JObject*>& locVoters = locNumBeamBucketsShiftedMap[locRFBunchShift];
243 for(
size_t loc_i = 0; loc_i < locVoters.size(); ++loc_i)
246 if(locTrackWireBased == NULL)
248 locTotalTrackingNDF += locTrackWireBased->
Ndof;
249 locTotalTrackingChiSq += locTrackWireBased->
chisq;
252 if(locTotalTrackingNDF > locBestTrackingTotals.first)
254 locBestTrackingTotals = pair<int, double>(locTotalTrackingNDF, locTotalTrackingChiSq);
255 locBestRFBunchShift = locRFBunchShift;
257 else if((locTotalTrackingNDF == locBestTrackingTotals.first) && (locTotalTrackingChiSq < locBestTrackingTotals.second))
259 locBestTrackingTotals = pair<int, double>(locTotalTrackingNDF, locTotalTrackingChiSq);
260 locBestRFBunchShift = locRFBunchShift;
264 return locBestRFBunchShift;
270 locEventRFBunch->
dTime = numeric_limits<double>::quiet_NaN();
271 locEventRFBunch->
dTimeVariance = numeric_limits<double>::quiet_NaN();
274 _data.push_back(locEventRFBunch);
jerror_t brun(jana::JEventLoop *locEventLoop, int32_t runnumber)
Called everytime a new run number is detected.
int Find_BestRFBunchShifts(double locRFHitTime, const vector< pair< double, const JObject * > > &locTimes, map< int, vector< const JObject * > > &locNumBeamBucketsShiftedMap, set< int > &locBestRFBunchShifts)
jerror_t evnt(jana::JEventLoop *locEventLoop, uint64_t eventnumber)
Called every event.
int Conduct_Vote(JEventLoop *locEventLoop, double locRFTime, vector< pair< double, const JObject * > > &locTimes, int &locHighestNumVotes)
double Convert_DigiTimeToNs_F1TDC(const JObject *locTDCDigiHit) const
jerror_t Select_RFBunch(JEventLoop *locEventLoop, vector< const DTrackWireBased * > &locTrackWireBasedVector, double locRFTime)
float chisq
Chi-squared for the track (not chisq/dof!)
jerror_t fini(void)
Called after last event of last event source has been processed.
double Convert_DigiTimeToNs_CAEN1290TDC(const JObject *locTDCDigiHit) const
DetectorSystem_t NameToSystem(const char *locSystemName)
DGeometry * GetDGeometry(unsigned int run_number)
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
void Select_GoodTracks(JEventLoop *locEventLoop, vector< const DTrackWireBased * > &locSelectedWireBasedTracks) const
int Ndof
Number of degrees of freedom in the fit.
DetectorSystem_t dTimeSource
jerror_t Create_NaNRFBunch(void)
bool Find_TrackTimes_SC(const DDetectorMatches *locDetectorMatches, const vector< const DTrackWireBased * > &locTrackWireBasedVector, vector< pair< double, const JObject * > > &locTimes) const
unsigned int dNumParticleVotes
bool GetTargetZ(double &z_target) const
z-location of center of target
jerror_t init(void)
Called once at program start.
int Break_TieVote_Tracks(map< int, vector< const JObject * > > &locNumBeamBucketsShiftedMap, set< int > &locBestRFBunchShifts)