Bug Summary

File:libraries/ANALYSIS/DEventRFBunch_factory_Combo.cc
Location:line 39, column 2
Description:Called C++ object pointer is null

Annotated Source Code

1// $Id$
2//
3// File: DEventRFBunch_factory_Combo.cc
4// Created: Tue Aug 9 14:29:24 EST 2011
5// Creator: pmatt
6//
7
8#ifdef VTRACE
9#include "vt_user.h"
10#endif
11
12#include "DEventRFBunch_factory_Combo.h"
13
14//------------------
15// init
16//------------------
17jerror_t DEventRFBunch_factory_Combo::init(void)
18{
19 dShowerSelectionTag = "PreSelect";
20 dTrackSelectionTag = "PreSelect";
21 dMinThrownMatchFOM = 5.73303E-7;
22 return NOERROR;
23}
24
25//------------------
26// brun
27//------------------
28jerror_t DEventRFBunch_factory_Combo::brun(jana::JEventLoop *locEventLoop, int32_t runnumber)
29{
30 gPARMS->SetDefaultParameter("COMBO:TRACK_SELECT_TAG", dTrackSelectionTag);
31 gPARMS->SetDefaultParameter("COMBO:SHOWER_SELECT_TAG", dShowerSelectionTag);
32
33 vector<double> locBeamPeriodVector;
34 locEventLoop->GetCalib("PHOTON_BEAM/RF/beam_period", locBeamPeriodVector);
35 dBeamBunchPeriod = locBeamPeriodVector[0];
36
37 DApplication *locApplication = dynamic_cast<DApplication*> (locEventLoop->GetJApplication());
38 DGeometry *locGeometry = locApplication ? locApplication->GetDGeometry(runnumber):NULL__null;
1
Assuming 'locApplication' is null
2
'?' condition is false
3
'locGeometry' initialized to a null pointer value
39 locGeometry->GetTargetZ(dTargetCenterZ);
4
Called C++ object pointer is null
40
41 locEventLoop->GetSingle(dParticleID);
42
43 //be sure that DEventRFBunch_factory::init() and brun() are called
44 dEventRFBunchFactory = static_cast<DEventRFBunch_factory*>(locEventLoop->GetFactory("DEventRFBunch"));
45 vector<const DEventRFBunch*> locEventRFBunches;
46 locEventLoop->Get(locEventRFBunches);
47
48 //be sure that DRFTime_factory::init() and brun() are called
49 dRFTimeFactory = static_cast<DRFTime_factory*>(locEventLoop->GetFactory("DRFTime"));
50 vector<const DRFTime*> locRFTimes;
51 locEventLoop->Get(locRFTimes);
52
53 // Get DReactions:
54 // Get list of factories and find all the ones producing
55 // DReaction objects. (A simpler way to do this would be to
56 // just use locEventLoop->Get(...), but then only one plugin could
57 // be used at a time.)
58 vector<JFactory_base*> locFactories = locEventLoop->GetFactories();
59 vector<const DReaction*> locReactions;
60 for(size_t loc_i = 0; loc_i < locFactories.size(); ++loc_i)
61 {
62 JFactory<DReaction>* locFactory = dynamic_cast<JFactory<DReaction>* >(locFactories[loc_i]);
63 if(locFactory == NULL__null)
64 continue;
65 if(string(locFactory->Tag()) == "Thrown")
66 continue;
67 // Found a factory producing DReactions. The reaction objects are
68 // produced at the init stage and are persistent through all event
69 // processing so we can grab the list here and append it to our
70 // overall list.
71 vector<const DReaction*> locReactionsSubset;
72 locFactory->Get(locReactionsSubset);
73 locReactions.insert(locReactions.end(), locReactionsSubset.begin(), locReactionsSubset.end());
74 }
75
76 vector<const DMCThrown*> locMCThrowns;
77 locEventLoop->Get(locMCThrowns);
78
79 string locHistName, locHistTitle;
80 TH1I* loc1DHist;
81
82 //Create Diagnostic Histograms
83 japp->RootWriteLock();
84 {
85 string locOutputFileName = "hd_root.root";
86 if(gPARMS->Exists("OUTPUT_FILENAME"))
87 gPARMS->GetParameter("OUTPUT_FILENAME", locOutputFileName);
88 TFile* locFile = (TFile*)gROOT->FindObject(locOutputFileName.c_str());
89 if(locFile == NULL__null)
90 return NOERROR;
91 locFile->cd("");
92
93 for(size_t loc_i = 0; loc_i < locReactions.size(); ++loc_i)
94 {
95 const DReaction* locReaction = locReactions[loc_i];
96
97 //get to the correct directory
98 string locReactionName = locReaction->Get_ReactionName();
99 string locDirName = locReactionName;
100 string locDirTitle = locReactionName;
101
102 //action directory
103 locFile->cd();
104 TDirectoryFile* locDirectoryFile = static_cast<TDirectoryFile*>(locFile->GetDirectory(locDirName.c_str()));
105 if(locDirectoryFile == NULL__null)
106 locDirectoryFile = new TDirectoryFile(locDirName.c_str(), locDirTitle.c_str());
107 locDirectoryFile->cd();
108
109 //pre-combo directory
110 locDirName = "Hist_RFSelection";
111 locDirectoryFile = static_cast<TDirectoryFile*>(gDirectory(TDirectory::CurrentDirectory())->GetDirectory(locDirName.c_str()));
112 if(locDirectoryFile == NULL__null)
113 locDirectoryFile = new TDirectoryFile(locDirName.c_str(), locDirTitle.c_str());
114 locDirectoryFile->cd();
115
116 // RFTime
117 locHistName = "RFParticleDeltaT";
118 loc1DHist = static_cast<TH1I*>(gDirectory(TDirectory::CurrentDirectory())->Get(locHistName.c_str()));
119 if(loc1DHist == NULL__null)
120 {
121 locHistTitle = locReactionName + string(";#Deltat_{RF - Particle} (ns)");
122 loc1DHist = new TH1I(locHistName.c_str(), locHistTitle.c_str(), 600, -3.0, 3.0);
123 }
124 dHistMap_RFParticleDeltaT[locReaction] = loc1DHist;
125
126 if(!locMCThrowns.empty())
127 {
128 // DeltaRFTime
129 locHistName = "DeltaRFTime";
130 loc1DHist = static_cast<TH1I*>(gDirectory(TDirectory::CurrentDirectory())->Get(locHistName.c_str()));
131 if(loc1DHist == NULL__null)
132 {
133 locHistTitle = locReactionName + string(";RF #Deltat_{Selected - True} (ns)");
134 loc1DHist = new TH1I(locHistName.c_str(), locHistTitle.c_str(), 220, -11.0, 11.0);
135 }
136 dHistMap_DeltaRFTime[locReaction] = loc1DHist;
137
138 // DeltaRFTime_TruePID
139 locHistName = "DeltaRFTime_TruePID";
140 loc1DHist = static_cast<TH1I*>(gDirectory(TDirectory::CurrentDirectory())->Get(locHistName.c_str()));
141 if(loc1DHist == NULL__null)
142 {
143 locHistTitle = locReactionName + string(", True PID;RF #Deltat_{Selected - True} (ns)");
144 loc1DHist = new TH1I(locHistName.c_str(), locHistTitle.c_str(), 220, -11.0, 11.0);
145 }
146 dHistMap_DeltaRFTime_TruePID[locReaction] = loc1DHist;
147 }
148 }
149 }
150 japp->RootUnLock(); //unlock
151
152 return NOERROR;
153}
154
155//------------------
156// evnt
157//------------------
158jerror_t DEventRFBunch_factory_Combo::evnt(jana::JEventLoop *locEventLoop, uint64_t eventnumber)
159{
160#ifdef VTRACE
161 VT_TRACER("DEventRFBunch_factory_Combo::evnt()");
162#endif
163
164 //use all particles in the combo to find the vertex
165 //ignore detached vertices
166 //selection is done by propagating all times to the target center, and then voting
167 //for neutrals, use DVertex to calculate times
168 //if its the good combo: has good tracks, will be good vertex
169 //vertex should be bad only if on the wrong combo anyway, or if all tracks are junk
170
171 vector<const DParticleComboBlueprint*> locParticleComboBlueprints;
172 locEventLoop->Get(locParticleComboBlueprints);
173
174 const DEventRFBunch* locEventRFBunch = NULL__null;
175 locEventLoop->GetSingle(locEventRFBunch);
176
177 double locRFTime, locRFVariance;
178 DetectorSystem_t locTimeSource;
179 if(locEventRFBunch->dTime == locEventRFBunch->dTime)
180 {
181 locRFTime = locEventRFBunch->dTime;
182 locRFVariance = locEventRFBunch->dTimeVariance;
183 locTimeSource = locEventRFBunch->dTimeSource;
184 }
185 else if(!dEventRFBunchFactory->Get_RFTimeGuess(locEventLoop, locRFTime, locRFVariance, locTimeSource))
186 {
187 //no good RF time, set to NaN for all combos
188 DEventRFBunch* locNewEventRFBunch = new DEventRFBunch(*locEventRFBunch);
189 for(size_t loc_i = 0; loc_i < locParticleComboBlueprints.size(); ++loc_i)
190 {
191 const DParticleComboBlueprint* locParticleComboBlueprint = locParticleComboBlueprints[loc_i];
192 locNewEventRFBunch->AddAssociatedObject(locParticleComboBlueprint);
193 locNewEventRFBunch->AddAssociatedObject(locParticleComboBlueprint->Get_Reaction());
194 }
195 _data.push_back(locNewEventRFBunch);
196 return NOERROR;
197 }
198
199 vector<const DTrackTimeBased*> locTrackTimeBasedVector;
200 locEventLoop->Get(locTrackTimeBasedVector, "Combo");
201
202 vector<const DNeutralShower*> locNeutralShowers;
203 locEventLoop->Get(locNeutralShowers, dShowerSelectionTag.c_str());
204
205 vector<const DEventRFBunch*> locThrownEventRFBunches;
206 locEventLoop->Get(locThrownEventRFBunches, "Thrown");
207 const DEventRFBunch* locThrownEventRFBunch = locThrownEventRFBunches.empty() ? NULL__null : locThrownEventRFBunches[0];
208
209 vector<const DMCThrownMatching*> locMCThrownMatchingVector;
210 locEventLoop->Get(locMCThrownMatchingVector);
211 const DMCThrownMatching* locMCThrownMatching = locMCThrownMatchingVector.empty() ? NULL__null : locMCThrownMatchingVector[0];
212
213 vector<const DChargedTrack*> locChargedTracks;
214 locEventLoop->Get(locChargedTracks, dTrackSelectionTag.c_str());
215
216 const DVertex* locVertex = NULL__null;
217 locEventLoop->GetSingle(locVertex);
218
219 map<pair<int, int>, DEventRFBunch*> locComboRFBunchMap; //key pair ints are: num-rf-bunch-shifts, num-votes
220
221 //pre-sort time-based tracks
222 map<pair<const DChargedTrack*, Particle_t>, const DTrackTimeBased*> locTimeBasedSourceMap;
223 for(size_t loc_l = 0; loc_l < locTrackTimeBasedVector.size(); ++loc_l)
224 {
225 const DTrackTimeBased* locTrackTimeBased = locTrackTimeBasedVector[loc_l];
226 const DChargedTrack* locChargedTrack = NULL__null;
227 locTrackTimeBased->GetSingleT(locChargedTrack);
228 locTimeBasedSourceMap[pair<const DChargedTrack*, Particle_t>(locChargedTrack, locTrackTimeBased->PID())] = locTrackTimeBased;
229 }
230
231 //pre-calculate propagated times: charged
232 map<const DChargedTrackHypothesis*, double> dPropagatedStartTimes_Charged;
233 for(size_t loc_i = 0; loc_i < locChargedTracks.size(); ++loc_i)
234 {
235 const vector<const DChargedTrackHypothesis*>& locChargedTrackHypotheses = locChargedTracks[loc_i]->dChargedTrackHypotheses;
236 for(size_t loc_j = 0; loc_j < locChargedTrackHypotheses.size(); ++loc_j)
237 {
238 //Prefer hit time from TOF (has best time resolution, wrong-mass/path-length doesn't factor into it since voting per-combo)
239 //If time() not from TOF, use ST time instead if available
240 double locStartTime = locChargedTrackHypotheses[loc_j]->time();
241 const DSCHitMatchParams* locSCHitMatchParams = locChargedTrackHypotheses[loc_j]->Get_SCHitMatchParams();
242 if((locChargedTrackHypotheses[loc_j]->t1_detector() != SYS_TOF) && (locSCHitMatchParams != NULL__null))
243 locStartTime = locSCHitMatchParams->dHitTime - locSCHitMatchParams->dFlightTime;
244
245 double locPropagatedTime = locStartTime + (dTargetCenterZ - locChargedTrackHypotheses[loc_j]->z())/29.9792458;
246 dPropagatedStartTimes_Charged[locChargedTrackHypotheses[loc_j]] = locPropagatedTime;
247 }
248 }
249
250 //pre-calculate propagated times: time-based
251 map<const DTrackTimeBased*, double> dPropagatedStartTimes_TimeBased;
252 for(size_t loc_i = 0; loc_i < locTrackTimeBasedVector.size(); ++loc_i)
253 {
254 double locStartTime = 0.0;
255 if(!Get_StartTime(locEventLoop, locTrackTimeBasedVector[loc_i], locStartTime))
256 continue;
257 double locPropagatedTime = locStartTime + (dTargetCenterZ - locTrackTimeBasedVector[loc_i]->z())/29.9792458;
258 dPropagatedStartTimes_TimeBased[locTrackTimeBasedVector[loc_i]] = locPropagatedTime;
259 }
260
261 //pre-calculate propagated times: neutrals (ignore non-photons)
262 map<const DNeutralShower*, double> dPropagatedStartTimes_Neutral;
263 for(size_t loc_i = 0; loc_i < locNeutralShowers.size(); ++loc_i)
264 {
265 double locStartTime = Calc_StartTime(locNeutralShowers[loc_i], locVertex);
266 double locPropagatedTime = locStartTime + (dTargetCenterZ - locVertex->dSpacetimeVertex.Z())/29.9792458;
267 dPropagatedStartTimes_Neutral[locNeutralShowers[loc_i]] = locPropagatedTime;
268 }
269
270 for(size_t loc_i = 0; loc_i < locParticleComboBlueprints.size(); ++loc_i)
271 {
272 const DParticleComboBlueprint* locParticleComboBlueprint = locParticleComboBlueprints[loc_i];
273 vector<double> locPropagatedTimes;
274
275 //Charged Tracks
276 deque<pair<const DChargedTrack*, Particle_t> > locChargedTracks;
277 locParticleComboBlueprint->Get_DetectedChargedTrackSourceObjects(locChargedTracks);
278 for(size_t loc_j = 0; loc_j < locChargedTracks.size(); ++loc_j)
279 {
280 const DChargedTrack* locChargedTrack = locChargedTracks[loc_j].first;
281 Particle_t locPID = locChargedTracks[loc_j].second;
282 const DChargedTrackHypothesis* locChargedTrackHypothesis = locChargedTrack->Get_Hypothesis(locPID);
283 if(locChargedTrackHypothesis != NULL__null)
284 {
285 locPropagatedTimes.push_back(dPropagatedStartTimes_Charged[locChargedTrackHypothesis]);
286 continue;
287 }
288
289 //get from time-based
290 pair<const DChargedTrack*, Particle_t> locTrackPair(locChargedTrack, locPID);
291 map<pair<const DChargedTrack*, Particle_t>, const DTrackTimeBased*>::iterator locIterator = locTimeBasedSourceMap.find(locTrackPair);
292 if(locIterator == locTimeBasedSourceMap.end())
293 continue; //bad track
294
295 const DTrackTimeBased* locTrackTimeBased = locIterator->second;
296 locPropagatedTimes.push_back(dPropagatedStartTimes_TimeBased[locTrackTimeBased]);
297 }
298
299 //Neutrals
300 deque<pair<const DNeutralShower*, Particle_t> > locNeutralShowers;
301 locParticleComboBlueprint->Get_DetectedNeutralShowerSourceObjects(locNeutralShowers);
302 for(size_t loc_j = 0; loc_j < locNeutralShowers.size(); ++loc_j)
303 {
304 Particle_t locPID = locNeutralShowers[loc_j].second;
305 if(locPID != Gamma)
306 continue; //other neutrals (e.g. neutron) can't be used to pick the time: their momentum is defined by the time
307
308 const DNeutralShower* locNeutralShower = locNeutralShowers[loc_j].first;
309 locPropagatedTimes.push_back(dPropagatedStartTimes_Neutral[locNeutralShower]);
310 }
311
312 if(locPropagatedTimes.empty())
313 {
314 //no timing information somehow: use the pre-existing value
315 DEventRFBunch* locNewEventRFBunch = new DEventRFBunch(*locEventRFBunch);
316 locNewEventRFBunch->AddAssociatedObject(locParticleComboBlueprint);
317 locNewEventRFBunch->AddAssociatedObject(locParticleComboBlueprint->Get_Reaction());
318 _data.push_back(locNewEventRFBunch);
319 continue;
320 }
321
322 // Find # RF Bunch Shifts
323 int locNumParticleVotes = 0;
324 int locNumBunchShifts = Find_BestRFBunchShift(locRFTime, locPropagatedTimes, locNumParticleVotes);
325 double locNewRFTime = locRFTime + (double)(locNumBunchShifts)*dBeamBunchPeriod;
326
327 //Hist
328 bool locIsAllTruePID = false;
329 if(locThrownEventRFBunch != NULL__null)
330 locIsAllTruePID = Is_AllTruePID(locMCThrownMatching, locParticleComboBlueprint);
331 const DReaction* locReaction = locParticleComboBlueprint->Get_Reaction();
332 japp->RootWriteLock();
333 {
334 for(size_t loc_j = 0; loc_j < locPropagatedTimes.size(); ++loc_j)
335 {
336 double locShiftedRFTime = dRFTimeFactory->Step_TimeToNearInputTime(locNewRFTime, locPropagatedTimes[loc_j]);
337 dHistMap_RFParticleDeltaT[locReaction]->Fill(locShiftedRFTime - locPropagatedTimes[loc_j]);
338 }
339
340 if(locThrownEventRFBunch != NULL__null)
341 {
342 double locDeltaT = locNewRFTime - locThrownEventRFBunch->dTime;
343 dHistMap_DeltaRFTime[locReaction]->Fill(locDeltaT); //diff between selected & true RF times (all combos)
344 if(locIsAllTruePID)
345 dHistMap_DeltaRFTime_TruePID[locReaction]->Fill(locDeltaT); //diff between selected & true RF times (all combos)
346 }
347 }
348 japp->RootUnLock(); //unlock
349
350 // Create new RF Bunch if doesn't already exist
351 pair<int, int> locVoteResultPair(locNumBunchShifts, locNumParticleVotes); //pair ints are: num-rf-bunch-shifts, num-votes
352 if(locComboRFBunchMap.find(locVoteResultPair) != locComboRFBunchMap.end()) //already created, don't recreate identical object!
353 {
354 locComboRFBunchMap[locVoteResultPair]->AddAssociatedObject(locParticleComboBlueprint);
355 locComboRFBunchMap[locVoteResultPair]->AddAssociatedObject(locParticleComboBlueprint->Get_Reaction());
356 }
357 else
358 {
359 DEventRFBunch* locNewEventRFBunch = new DEventRFBunch();
360 locNewEventRFBunch->dTime = locNewRFTime;
361 locNewEventRFBunch->dTimeVariance = locRFVariance;
362 locNewEventRFBunch->dNumParticleVotes = locNumParticleVotes;
363 locNewEventRFBunch->dTimeSource = locTimeSource;
364 locNewEventRFBunch->AddAssociatedObject(locParticleComboBlueprint);
365 locNewEventRFBunch->AddAssociatedObject(locParticleComboBlueprint->Get_Reaction());
366 _data.push_back(locNewEventRFBunch);
367 locComboRFBunchMap[locVoteResultPair] = locNewEventRFBunch;
368 }
369 }
370
371 return NOERROR;
372}
373
374bool DEventRFBunch_factory_Combo::Get_StartTime(JEventLoop* locEventLoop, const DTrackTimeBased* locTrackTimeBased, double& locStartTime)
375{
376 const DDetectorMatches* locDetectorMatches = NULL__null;
377 locEventLoop->GetSingle(locDetectorMatches);
378
379 // Use time-based tracking time as initial guess
380 locStartTime = 0.0;
381
382 //TOF
383 DTOFHitMatchParams locTOFHitMatchParams;
384 if(dParticleID->Get_BestTOFMatchParams(locTrackTimeBased, locDetectorMatches, locTOFHitMatchParams))
385 {
386 locStartTime = locTOFHitMatchParams.dHitTime - locTOFHitMatchParams.dFlightTime;
387 return true;
388 }
389
390 //SC
391 DSCHitMatchParams locSCHitMatchParams;
392 if(dParticleID->Get_BestSCMatchParams(locTrackTimeBased, locDetectorMatches, locSCHitMatchParams))
393 {
394 locStartTime = locSCHitMatchParams.dHitTime - locSCHitMatchParams.dFlightTime;
395 return true;
396 }
397
398 //BCAL
399 DBCALShowerMatchParams locBCALShowerMatchParams;
400 if(dParticleID->Get_BestBCALMatchParams(locTrackTimeBased, locDetectorMatches, locBCALShowerMatchParams))
401 {
402 locStartTime = locBCALShowerMatchParams.dBCALShower->t - locBCALShowerMatchParams.dFlightTime;
403 return true;
404 }
405
406 //FCAL
407 DFCALShowerMatchParams locFCALShowerMatchParams;
408 if(dParticleID->Get_BestFCALMatchParams(locTrackTimeBased, locDetectorMatches, locFCALShowerMatchParams))
409 {
410 locStartTime = locFCALShowerMatchParams.dFCALShower->getTime() - locFCALShowerMatchParams.dFlightTime;
411 return true;
412 }
413
414 return false;
415}
416
417double DEventRFBunch_factory_Combo::Calc_StartTime(const DNeutralShower* locNeutralShower, const DVertex* locVertex)
418{
419 //doesn't work for neutrons!!
420
421 DVector3 locHitPoint = locNeutralShower->dSpacetimeVertex.Vect();
422 DVector3 locPath = locHitPoint - locVertex->dSpacetimeVertex.Vect();
423 double locPathLength = locPath.Mag();
424
425 double locFlightTime = locPathLength/29.9792458;
426 double locHitTime = locNeutralShower->dSpacetimeVertex.T();
427 return locHitTime - locFlightTime;
428}
429
430int DEventRFBunch_factory_Combo::Find_BestRFBunchShift(double locRFHitTime, const vector<double>& locTimes, int& locBestNumVotes)
431{
432 //then find the #beam buckets the RF time needs to shift to match it
433 //key is # RF buckets the RF time is shifted to match the track, first value is the # tracks at that shift, second value is sum(delta-t^2) (for standard deviation from 0)
434 //use delta-t^2 (related to standard deviation from 0) as tie-breaker
435
436 locBestNumVotes = 0;
437 if(locTimes.empty())
438 return 0; //shouldn't happen ...
439
440 map<int, pair<unsigned int, double> > locNumBeamBucketsShiftedMap;
441 int locBestRFBunchShift = 0;
442 for(unsigned int loc_i = 0; loc_i < locTimes.size(); ++loc_i)
443 {
444 double locDeltaT = locTimes[loc_i] - locRFHitTime;
445 int locNumBeamBucketsShifted = (locDeltaT > 0.0) ? int(locDeltaT/dBeamBunchPeriod + 0.5) : int(locDeltaT/dBeamBunchPeriod - 0.5);
446 locDeltaT -= dBeamBunchPeriod*double(locNumBeamBucketsShifted);
447
448 if(locNumBeamBucketsShiftedMap.find(locNumBeamBucketsShifted) == locNumBeamBucketsShiftedMap.end())
449 locNumBeamBucketsShiftedMap[locNumBeamBucketsShifted] = pair<unsigned int, double>(1, locDeltaT*locDeltaT);
450 else
451 {
452 ++(locNumBeamBucketsShiftedMap[locNumBeamBucketsShifted].first);
453 locNumBeamBucketsShiftedMap[locNumBeamBucketsShifted].second += locDeltaT*locDeltaT;
454 }
455 if(locNumBeamBucketsShifted == locBestRFBunchShift)
456 continue;
457
458 unsigned int locBestNumTracks = locNumBeamBucketsShiftedMap[locBestRFBunchShift].first;
459 unsigned int locNumTracks = locNumBeamBucketsShiftedMap[locNumBeamBucketsShifted].first;
460 if(locNumTracks > locBestNumTracks)
461 locBestRFBunchShift = locNumBeamBucketsShifted;
462 else if(locNumTracks == locBestNumTracks)
463 {
464 double locBestDeltaTSq = locNumBeamBucketsShiftedMap[locBestRFBunchShift].second;
465 double locDeltaTSq = locNumBeamBucketsShiftedMap[locNumBeamBucketsShifted].second;
466 if(locDeltaTSq < locBestDeltaTSq)
467 locBestRFBunchShift = locNumBeamBucketsShifted;
468 }
469 }
470
471 locBestNumVotes = locNumBeamBucketsShiftedMap[locBestRFBunchShift].first;
472 return locBestRFBunchShift;
473}
474
475bool DEventRFBunch_factory_Combo::Is_AllTruePID(const DMCThrownMatching* locMCThrownMatching, const DParticleComboBlueprint* locParticleComboBlueprint)
476{
477 //Charged
478 deque<pair<const DChargedTrack*, Particle_t> > locChargedTracks;
479 locParticleComboBlueprint->Get_DetectedChargedTrackSourceObjects(locChargedTracks);
480 for(size_t loc_j = 0; loc_j < locChargedTracks.size(); ++loc_j)
481 {
482 const DChargedTrack* locChargedTrack = locChargedTracks[loc_j].first;
483 Particle_t locPID = locChargedTracks[loc_j].second;
484
485 double locMatchFOM = 0.0;
486 const DMCThrown* locMCThrown = locMCThrownMatching->Get_MatchingMCThrown(locChargedTrack, locMatchFOM);
487 if((locMCThrown == NULL__null) || (locMatchFOM < dMinThrownMatchFOM))
488 return false;
489 if(((Particle_t)locMCThrown->type) != locPID)
490 return false;
491 }
492
493 //Neutrals
494 deque<pair<const DNeutralShower*, Particle_t> > locNeutralShowers;
495 locParticleComboBlueprint->Get_DetectedNeutralShowerSourceObjects(locNeutralShowers);
496 for(size_t loc_j = 0; loc_j < locNeutralShowers.size(); ++loc_j)
497 {
498 Particle_t locPID = locNeutralShowers[loc_j].second;
499 if(locPID != Gamma)
500 continue; //other neutrals (e.g. neutron) can't be used to pick the time: their momentum is defined by the time
501
502 const DNeutralShower* locNeutralShower = locNeutralShowers[loc_j].first;
503
504 double locMatchFOM = 0.0;
505 const DMCThrown* locMCThrown = locMCThrownMatching->Get_MatchingMCThrown(locNeutralShower, locMatchFOM);
506 if((locMCThrown == NULL__null) || (locMatchFOM < dMinThrownMatchFOM))
507 return false;
508 if(((Particle_t)locMCThrown->type) != locPID)
509 return false;
510 }
511
512 return true;
513}
514
515//------------------
516// erun
517//------------------
518jerror_t DEventRFBunch_factory_Combo::erun(void)
519{
520 return NOERROR;
521}
522
523//------------------
524// fini
525//------------------
526jerror_t DEventRFBunch_factory_Combo::fini(void)
527{
528 return NOERROR;
529}
530
531