Bug Summary

File:/home/sdobbs/work/clang/halld_recon/src/libraries/ANALYSIS/DSourceComboTimeHandler.h
Warning:line 250, column 2
Value stored to 'locTimeCut_ns' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -main-file-name DSourceComboVertexer.cc -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /w/halld-scifs17exp/home/sdobbs/clang/llvm-project/install/lib/clang/12.0.0 -D HAVE_CCDB -D HAVE_RCDB -D HAVE_EVIO -D HAVE_TMVA=1 -D RCDB_MYSQL=1 -D RCDB_SQLITE=1 -D SQLITE_USE_LEGACY_STRUCT=ON -I .Linux_CentOS7.7-x86_64-gcc4.8.5/libraries/ANALYSIS -I libraries/ANALYSIS -I . -I libraries -I libraries/include -I /w/halld-scifs17exp/home/sdobbs/clang/halld_recon/Linux_CentOS7.7-x86_64-gcc4.8.5/include -I external/xstream/include -I /usr/include/tirpc -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/root/root-6.08.06/include -I /w/halld-scifs17exp/halld2/home/sdobbs/Software/jana/jana_0.8.2/Linux_CentOS7.7-x86_64-gcc4.8.5/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/ccdb/ccdb_1.06.06/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/rcdb/rcdb_0.06.00/cpp/include -I /usr/include/mysql -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/sqlitecpp/SQLiteCpp-2.2.0^bs130/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/sqlite/sqlite-3.13.0^bs130/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/hdds/hdds-4.9.0/Linux_CentOS7.7-x86_64-gcc4.8.5/src -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/xerces-c/xerces-c-3.1.4/include -I /group/halld/Software/builds/Linux_CentOS7.7-x86_64-gcc4.8.5/evio/evio-4.4.6/Linux-x86_64/include -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5 -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/x86_64-redhat-linux -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/backward -internal-isystem /usr/local/include -internal-isystem /w/halld-scifs17exp/home/sdobbs/clang/llvm-project/install/lib/clang/12.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /home/sdobbs/work/clang/halld_recon/src -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -o /tmp/scan-build-2021-01-21-110224-160369-1 -x c++ libraries/ANALYSIS/DSourceComboVertexer.cc
1#ifndef DSourceComboTimeHandler_h
2#define DSourceComboTimeHandler_h
3
4#include <unordered_map>
5#include <vector>
6#include <map>
7#include <memory>
8
9#include "TF1.h"
10#include "TH2I.h"
11#include "TROOT.h"
12#include "TFile.h"
13#include "TDirectoryFile.h"
14
15#include "particleType.h"
16#include "DLorentzVector.h"
17#include "PID/DKinematicData.h"
18#include "PID/DNeutralShower.h"
19#include "PID/DChargedTrackHypothesis.h"
20#include "PID/DEventRFBunch.h"
21#include "PID/DDetectorMatches.h"
22#include "ANALYSIS/DSourceCombo.h"
23#include "ANALYSIS/DReactionVertexInfo.h"
24#include "ANALYSIS/DAnalysisUtilities.h"
25
26using namespace std;
27using namespace jana;
28
29namespace DAnalysis
30{
31
32using DPhotonKinematicsByZBin = unordered_map<signed char, unordered_map<const DNeutralShower*, shared_ptr<const DKinematicData>>>; //char: z-bin
33using DPhotonShowersByBeamBunch = map<vector<int>, vector<const JObject*>>; //int: beam bunch n-shifts from nominal
34class DSourceComboer;
35class DSourceComboVertexer;
36
37class DSourceComboTimeHandler
38{
39 public:
40 DSourceComboTimeHandler(void) = delete;
41 DSourceComboTimeHandler(JEventLoop* locEventLoop, DSourceComboer* locSourceComboer, const DSourceComboVertexer* locSourceComboVertexer);
42 ~DSourceComboTimeHandler(void){Fill_Histograms();}
43 void Set_RunDependent_Data(JEventLoop *locEventLoop);
44
45 //SETUP
46 void Reset(void);
47 void Set_DebugLevel(int locDebugLevel){dDebugLevel = locDebugLevel;}
48 void Setup(const vector<const DNeutralShower*>& locNeutralShowers, const DEventRFBunch* locInitialEventRFBunch, const DDetectorMatches* locDetectorMatches);
49 void Set_BeamParticles(const vector<const DBeamPhoton*>& locBeamParticles);
50
51 //GET SETUP RESULTS
52 const DEventRFBunch* Get_InitialEventRFBunch(void) const{return dInitialEventRFBunch;}
53 DPhotonKinematicsByZBin Get_PhotonKinematics(void) const{return dPhotonKinematics;}
54 unordered_map<signed char, DPhotonShowersByBeamBunch> Get_ShowersByBeamBunchByZBin(void) const{return dShowersByBeamBunchByZBin;}
55 vector<const DKinematicData*> Get_BeamParticlesByRFBunch(int locRFBunch, unsigned int locPlusMinusBunchRange) const;
56
57 //GET CUTS
58 map<DetectorSystem_t, TF1*> Get_TimeCuts(Particle_t locPID) const;
59 bool Get_TimeCut(Particle_t locPID, DetectorSystem_t locSystem, TF1* locTimeCut_ns) const;
60
61 //GET VALID/COMMON RF BUNCHES
62 //Note that combining with an empty vector does NOT remove all bunches!!
63 //It is assumed that an empty vector means "unknown," and that you just want to use the other set instead
64 vector<int> Get_ValidRFBunches(const JObject* locObject, signed char locVertexZBin) const;
65 vector<int> Get_CommonRFBunches(const vector<int>& locRFBunches1, const JObject* locObject, signed char locVertexZBin) const;
66 vector<int> Get_CommonRFBunches(const vector<int>& locRFBunches1, const vector<int>& locRFBunches2) const;
67
68 //UTILITY FUNCTIONS
69 int Calc_RFBunchShift(double locTimeToStepTo) const{return Calc_RFBunchShift(dInitialEventRFBunch->dTime, locTimeToStepTo);}
70 int Calc_RFBunchShift(double locTimeToStep, double locTimeToStepTo) const;
71 double Calc_RFTime(int locNumRFBunchShifts) const;
72 double Calc_PropagatedRFTime(double locPrimaryVertexZ, int locNumRFBunchShifts, double locDetachedVertexTimeOffset) const;
73 double Get_BeamBunchPeriod(void) const{return dBeamBunchPeriod;}
74
75 //SELECT RF BUNCHES
76 bool Select_RFBunches_Charged(const DReactionVertexInfo* locReactionVertexInfo, const DSourceCombo* locChargedCombo, vector<int>& locValidRFBunches);
77 bool Select_RFBunches_PhotonVertices(const DReactionVertexInfo* locReactionVertexInfo, const DSourceCombo* locReactionFullCombo, vector<int>& locValidRFBunches);
78 bool Select_RFBunches_AllVerticesUnknown(const DReactionVertexInfo* locReactionVertexInfo, const DSourceCombo* locReactionFullCombo, Charge_t locCharge, vector<int>& locValidRFBunches);
79 int Select_RFBunch_Full(const DReactionVertexInfo* locReactionVertexInfo, const DSourceCombo* locReactionFullCombo, const vector<int>& locRFBunches);
80 bool Cut_Timing_MissingMassVertices(const DReactionVertexInfo* locReactionVertexInfo, const DSourceCombo* locReactionFullCombo, const DKinematicData* locBeamParticle, int locRFBunch);
81
82 //GET POCA TO VERTEX
83 DLorentzVector Get_ChargedPOCAToVertexX4(const DChargedTrackHypothesis* locHypothesis, bool locIsProductionVertex, const DSourceCombo* locReactionFullCombo, const DSourceCombo* locVertexPrimaryCombo, const DKinematicData* locBeamPhoton, bool locIsCombo2ndVertex, DVector3 locVertex);
84
85 //VERTEX-Z BINNING UTILITY FUNCTIONS
86 size_t Get_NumVertexZBins(void) const{return dNumPhotonVertexZBins;}
87 signed char Get_PhotonVertexZBin(double locVertexZ) const;
88 double Get_PhotonVertexZBinCenter(signed char locVertexZBin) const;
89 size_t Get_VertexZBin_TargetCenter(void) const{return Get_PhotonVertexZBin(dTargetCenter.Z());}
90
91 void Vote_OldMethod(const DSourceCombo* locReactionFullCombo, vector<int>& locValidRFBunches);
92
93 private:
94
95 pair<DVector3, double> Calc_Photon_Kinematics(const DNeutralShower* locNeutralShower, const DVector3& locVertex) const;
96 shared_ptr<const DKinematicData> Create_KinematicData_Photon(const DNeutralShower* locNeutralShower, const DVector3& locVertex) const;
97
98 void Calc_PhotonBeamBunchShifts(const DNeutralShower* locNeutralShower, shared_ptr<const DKinematicData>& locKinematicData, double locRFTime, signed char locZBin);
99 vector<int> Calc_BeamBunchShifts(double locVertexTime, double locOrigRFBunchPropagatedTime, double locDeltaTCut, bool locIncludeDecayTimeOffset, Particle_t locPID, DetectorSystem_t locSystem, double locP);
100
101 double Calc_MaxDeltaTError(const DNeutralShower* locNeutralShower, double locTheta) const{return Calc_MaxDeltaTError(locNeutralShower, locTheta, dPhotonVertexZBinWidth/2.0);}
102 double Calc_MaxDeltaTError(const DNeutralShower* locNeutralShower, double locTheta, double locZError) const;
103
104 bool Get_RFBunches_ChargedTrack(const DChargedTrackHypothesis* locHypothesis, bool locIsProductionVertex, const DSourceCombo* locVertexPrimaryCombo, bool locIsCombo2ndVertex, DVector3 locVertex, double locPropagatedRFTime, bool locOnlyTrackFlag, bool locDetachedVertex, vector<int>& locRFBunches);
105 TF1* Get_TimeCutFunction(Particle_t locPID, DetectorSystem_t locSystem) const;
106
107 bool Compute_RFChiSqs_UnknownVertices(const DSourceCombo* locReactionFullCombo, Charge_t locCharge, const vector<int>& locRFBunches, unordered_map<int, double>& locChiSqByRFBunch, map<int, map<Particle_t, map<DetectorSystem_t, vector<pair<float, float>>>>>& locRFDeltaTsForHisting);
108 bool Cut_PhotonPID(const DNeutralShower* locNeutralShower, const DVector3& locVertex, double locPropagatedRFTime, bool locTargetCenterFlag, bool locDetachedVertex);
109 bool Cut_TrackPID(const DChargedTrackHypothesis* locHypothesis, bool locIsProductionVertex, const DSourceCombo* locFullReactionCombo, const DSourceCombo* locVertexPrimaryCombo, const DKinematicData* locBeamPhoton, bool locIsCombo2ndVertex, DVector3 locVertex, double locPropagatedRFTime, bool locDetachedVertex);
110
111 pair<double, double> Calc_RFDeltaTChiSq(const DNeutralShower* locNeutralShower, const TVector3& locVertex, double locPropagatedRFTime) const;
112 pair<double, double> Calc_RFDeltaTChiSq(const DChargedTrackHypothesis* locHypothesis, double locVertexTime, double locPropagatedRFTime) const;
113
114 void Define_DefaultCuts(void);
115 void Get_CommandLineCuts(void);
116 void Create_CutFunctions(void);
117 void Fill_Histograms(void);
118
119
120 //HANDLERS AND UTILITIES
121 DSourceComboer* dSourceComboer;
122 const DSourceComboVertexer* dSourceComboVertexer;
123 const DAnalysisUtilities* dAnalysisUtilities;
124 int dDebugLevel = 0;
125 bool dPrintCutFlag = false;
126
127 //EXPERIMENT INFORMATION
128 DVector3 dTargetCenter;
129 double dTargetLength = 30.0;
130 double dBeamBunchPeriod = 1000.0/249.5;
131 bool dUseSigmaForRFSelectionFlag = false;
132
133
134 //VERTEX-DEPENDENT PHOTON INFORMATION
135 //For every 10cm in vertex-z, calculate the photon p4 & time for placing mass & delta-t cuts
136 //The z-range extends from the upstream end of the target - 5cm to the downstream end + 25cm
137 //so for a 30-cm-long target, it's a range of 50cm: 5bins, evaluated at the center of each bin
138 //Make sure that the center of the target is the center of a zbin!!!
139 float dPhotonVertexZBinWidth = 10.0;
140 float dPhotonVertexZRangeLow = 45.0;
141 size_t dNumPhotonVertexZBins = 6;
142 //due to detached vertices
143 double dMaxDecayTimeOffset = 0.0; //changed in constructor if needed
144 double dDetachedPathLengthUncertainty = 10.0; //guess
145 double dChargedDecayProductTimeUncertainty = 2.0; //due to uncertain path length
146
147 //SHOWERS SORTED BY RF BUNCH
148 const DEventRFBunch* dInitialEventRFBunch = nullptr;
149 const DDetectorMatches* dDetectorMatches = nullptr;
150
151 //zbins: showers are stored based on what zbins they are VALID for
152 //that means that the FCAL showers will appear in EVERY zbin: duplicate entries
153 //even though this takes less memory, it's faster than merging vectors each time they are requested
154 //Note that the RF-shift vectors are sorted
155 DPhotonKinematicsByZBin dPhotonKinematics;
156 //shower -> RFs
157 unordered_map<signed char, unordered_map<const JObject*, vector<int>>> dShowerRFBunches; //char: z-bin
158 //RF -> showers
159 unordered_map<signed char, DPhotonShowersByBeamBunch> dShowersByBeamBunchByZBin; //char: zbin
160
161 map<pair<const DKinematicData*, vector<const DKinematicData*>>, DLorentzVector> dChargedParticlePOCAToVertexX4; //pair: charged hypo, then vertex particles
162
163 unordered_map<const DSourceCombo*, pair<bool, vector<int>>> dChargedComboRFBunches; //bool: passed/failed cuts (can pass with empty vector if no timing info) //combo: charged
164 unordered_map<const DSourceCombo*, pair<bool, vector<int>>> dPhotonVertexRFBunches; //bool: passed/failed cuts (can pass with empty vector if no timing info) //combo: full
165 unordered_map<const DSourceCombo*, pair<bool, vector<int>>> dUnknownVertexRFBunches; //bool: passed/failed cuts (can pass with empty vector if no timing info) //combo: full
166 unordered_map<const DSourceCombo*, int> dFullComboRFBunches; //combo: full
167
168 unordered_map<int, vector<const DKinematicData*>> dBeamParticlesByRFBunch;
169
170 //CUTS
171 //Unknown: initial RF selection for photons (at beginning of event, prior to vertex) //can be separate cut function
172 map<Particle_t, map<DetectorSystem_t, TF1*>> dPIDTimingCuts; //function of p
173 map<Particle_t, map<DetectorSystem_t, string>> dPIDTimingCuts_TF1FunctionString;
174 string dDefaultTimeCutFunctionString; //used if not found in dPIDTimingCuts_TF1FunctionString
175 map<Particle_t, map<DetectorSystem_t, vector<double>>> dPIDTimingCuts_TF1Params;
176
177 //HISTOGRAMS
178 //Unknown: initial RF selection for photons (at beginning of event, prior to vertex) //can be separate cut function
179 TH2* dHist_BeamRFDeltaTVsBeamE;
180 map<Particle_t, map<DetectorSystem_t, TH2*>> dHistMap_RFDeltaTVsP_BestRF; //PID Unknown: photons prior to vertex selection
181 map<Particle_t, map<DetectorSystem_t, TH2*>> dHistMap_RFDeltaTVsP_AllRFs; //PID Unknown: photons prior to vertex selection
182 vector<pair<float, float>> dBeamRFDeltaTs;
183 map<Particle_t, map<DetectorSystem_t, vector<pair<float, float>>>> dSelectedRFDeltaTs; //first float is p, 2nd is delta-t //PID Unknown: photons prior to vertex selection
184 map<Particle_t, map<DetectorSystem_t, vector<pair<float, float>>>> dAllRFDeltaTs; //first float is p, 2nd is delta-t //PID Unknown: photons prior to vertex selection
185};
186
187inline void DSourceComboTimeHandler::Reset(void)
188{
189 Fill_Histograms();
190
191 dInitialEventRFBunch = nullptr;
192
193 dPhotonKinematics.clear(); //can probably delete instead of shared_ptr!!
194 for(auto& locZPair : dShowerRFBunches)
195 locZPair.second.clear();
196 for(auto& locZPair : dShowersByBeamBunchByZBin)
197 locZPair.second.clear();
198 dChargedParticlePOCAToVertexX4.clear();
199 dBeamParticlesByRFBunch.clear();
200
201 dChargedComboRFBunches.clear();
202 dPhotonVertexRFBunches.clear();
203 dUnknownVertexRFBunches.clear();
204 dFullComboRFBunches.clear();
205}
206
207inline signed char DSourceComboTimeHandler::Get_PhotonVertexZBin(double locVertexZ) const
208{
209 //given some vertex-z, what bin am I in?
210 if(locVertexZ < dPhotonVertexZRangeLow)
211 return DSourceComboInfo::Get_VertexZIndex_OutOfRange();
212 int locPhotonVertexZBin = int((locVertexZ - dPhotonVertexZRangeLow)/dPhotonVertexZBinWidth);
213 return ((locPhotonVertexZBin >= int(dNumPhotonVertexZBins)) ? DSourceComboInfo::Get_VertexZIndex_OutOfRange() : locPhotonVertexZBin);
214}
215
216inline double DSourceComboTimeHandler::Get_PhotonVertexZBinCenter(signed char locVertexZBin) const
217{
218 return dPhotonVertexZRangeLow + (double(locVertexZBin) + 0.5)*dPhotonVertexZBinWidth;
219}
220
221inline void DSourceComboTimeHandler::Set_BeamParticles(const vector<const DBeamPhoton*>& locBeamParticles)
222{
223 for(const auto& locBeamParticle : locBeamParticles)
224 {
225 auto locRFBunch = Calc_RFBunchShift(dInitialEventRFBunch->dTime, locBeamParticle->time());
226 dBeamParticlesByRFBunch[locRFBunch].push_back(locBeamParticle);
227 dBeamRFDeltaTs.emplace_back(locBeamParticle->energy(), locBeamParticle->time() - dInitialEventRFBunch->dTime);
228 }
229}
230
231inline map<DetectorSystem_t, TF1*> DSourceComboTimeHandler::Get_TimeCuts(Particle_t locPID) const
232{
233 auto locIterator = dPIDTimingCuts.find(locPID);
234 if(locIterator == dPIDTimingCuts.end())
235 return {};
236 return locIterator->second;
237}
238
239inline bool DSourceComboTimeHandler::Get_TimeCut(Particle_t locPID, DetectorSystem_t locSystem, TF1* locTimeCut_ns) const
240{
241 auto locIterator = dPIDTimingCuts.find(locPID);
242 if(locIterator == dPIDTimingCuts.end())
243 return false;
244
245 auto locSystemMap = locIterator->second;
246 auto locSystemIterator = locSystemMap.find(locSystem);
247 if(locSystemIterator == locSystemMap.end())
248 return false;
249
250 locTimeCut_ns = locSystemIterator->second;
Value stored to 'locTimeCut_ns' is never read
251 return true;
252}
253
254inline vector<const DKinematicData*> DSourceComboTimeHandler::Get_BeamParticlesByRFBunch(int locCenterRFBunch, unsigned int locPlusMinusBunchRange) const
255{
256 vector<const DKinematicData*> locBeamParticles;
257 for(auto locRFBunch = locCenterRFBunch - int(locPlusMinusBunchRange); locRFBunch <= locCenterRFBunch + int(locPlusMinusBunchRange); ++locRFBunch)
258 {
259 auto locIterator = dBeamParticlesByRFBunch.find(locRFBunch);
260 if(locIterator != dBeamParticlesByRFBunch.end())
261 locBeamParticles.insert(locBeamParticles.end(), locIterator->second.begin(), locIterator->second.end());
262 }
263 return locBeamParticles;
264}
265
266inline double DSourceComboTimeHandler::Calc_RFTime(int locNumRFBunchShifts) const
267{
268 return dInitialEventRFBunch->dTime + locNumRFBunchShifts*dBeamBunchPeriod;
269}
270
271inline double DSourceComboTimeHandler::Calc_PropagatedRFTime(double locPrimaryVertexZ, int locNumRFBunchShifts, double locDetachedVertexTimeOffset) const
272{
273 //propagate rf time to vertex and add time offset (faster to just do it here rather than for each particle)
274 return Calc_RFTime(locNumRFBunchShifts) + (locPrimaryVertexZ - dTargetCenter.Z())/SPEED_OF_LIGHT29.9792458 + locDetachedVertexTimeOffset;
275}
276
277inline shared_ptr<const DKinematicData> DSourceComboTimeHandler::Create_KinematicData_Photon(const DNeutralShower* locNeutralShower, const DVector3& locVertex) const
278{
279 auto locKinematicsPair = Calc_Photon_Kinematics(locNeutralShower, locVertex);
280 return std::make_shared<const DKinematicData>(Gamma, locKinematicsPair.first, locVertex, locKinematicsPair.second);
281}
282
283inline pair<DVector3, double> DSourceComboTimeHandler::Calc_Photon_Kinematics(const DNeutralShower* locNeutralShower, const DVector3& locVertex) const
284{
285 //returns momentum, vertex time
286 auto locPath = locNeutralShower->dSpacetimeVertex.Vect() - locVertex;
287 auto locPathLength = locPath.Mag();
288 auto locVertexTime = locNeutralShower->dSpacetimeVertex.T() - locPathLength/29.9792458;
289 auto locMomentum = locNeutralShower->dEnergy*locPath.Unit();
290 return std::make_pair(locMomentum, locVertexTime);
291}
292
293inline vector<int> DSourceComboTimeHandler::Get_ValidRFBunches(const JObject* locObject, signed char locVertexZBin) const
294{
295 const auto& locBunchesByObject = dShowerRFBunches.find(locVertexZBin)->second;
296 auto locIterator = locBunchesByObject.find(locObject);
297 if(locIterator == locBunchesByObject.end())
298 return {};
299 return locIterator->second;
300}
301
302inline int DSourceComboTimeHandler::Calc_RFBunchShift(double locTimeToStep, double locTimeToStepTo) const
303{
304 double locDeltaT = locTimeToStepTo - locTimeToStep;
305 return (locDeltaT > 0.0) ? int(locDeltaT/dBeamBunchPeriod + 0.5) : int(locDeltaT/dBeamBunchPeriod - 0.5);
306}
307
308inline vector<int> DSourceComboTimeHandler::Get_CommonRFBunches(const vector<int>& locRFBunches1, const JObject* locObject, signed char locVertexZBin) const
309{
310 return Get_CommonRFBunches(locRFBunches1, Get_ValidRFBunches(locObject, locVertexZBin));
311}
312
313inline vector<int> DSourceComboTimeHandler::Get_CommonRFBunches(const vector<int>& locRFBunches1, const vector<int>& locRFBunches2) const
314{
315 //check to see if one of the input vectors is empty //empty means "no idea": all possible bunches are valid
316 if(locRFBunches1.empty())
317 return locRFBunches2;
318 else if(locRFBunches2.empty())
319 return locRFBunches1;
320
321 vector<int> locCommonRFBunches = {}; //if charged or massive neutrals, ignore (they don't choose at this stage)
322 locCommonRFBunches.reserve(locRFBunches1.size() + locRFBunches2.size());
323 std::set_intersection(locRFBunches1.begin(), locRFBunches1.end(), locRFBunches2.begin(), locRFBunches2.end(), std::back_inserter(locCommonRFBunches));
324 return locCommonRFBunches;
325}
326
327inline pair<double, double> DSourceComboTimeHandler::Calc_RFDeltaTChiSq(const DNeutralShower* locNeutralShower, const TVector3& locVertex, double locPropagatedRFTime) const
328{
329 //calc vertex time, get delta-t cut
330 auto locPathLength = (locNeutralShower->dSpacetimeVertex.Vect() - locVertex).Mag();
331 auto locVertexTime = locNeutralShower->dSpacetimeVertex.T() - locPathLength/29.9792458;
332 auto locVertexTimeVariance = dUseSigmaForRFSelectionFlag ? (*(locNeutralShower->dCovarianceMatrix))(4, 4) : 1.0;
333
334 auto locDeltaT = locVertexTime - locPropagatedRFTime;
335 auto locChiSq = locDeltaT*locDeltaT/locVertexTimeVariance;
336 if(dDebugLevel >= 5)
337 cout << "neutral Calc_RFDeltaTChiSq(): vertex time, rf time, delta-t, chisq = " << locVertexTime << ", " << locPropagatedRFTime << ", " << locDeltaT << ", " << locChiSq << endl;
338
339 return std::make_pair(locDeltaT, locChiSq);
340}
341
342inline pair<double, double> DSourceComboTimeHandler::Calc_RFDeltaTChiSq(const DChargedTrackHypothesis* locHypothesis, double locVertexTime, double locPropagatedRFTime) const
343{
344 //calc vertex time, get delta-t cut
345 auto locErrorMatrix = locHypothesis->errorMatrix();
346 auto locVertexTimeVariance = (dUseSigmaForRFSelectionFlag && (locErrorMatrix != nullptr)) ? (*locErrorMatrix)(6, 6) : 1.0;
347 auto locDeltaT = locVertexTime - locPropagatedRFTime;
348 auto locChiSq = locDeltaT*locDeltaT/locVertexTimeVariance;
349 if(dDebugLevel >= 5)
350 cout << "charged Calc_RFDeltaTChiSq(): vertex time, rf time, delta-t, chisq = " << locVertexTime << ", " << locPropagatedRFTime << ", " << locDeltaT << ", " << locChiSq << endl;
351
352 return std::make_pair(locDeltaT, locChiSq);
353}
354
355inline TF1* DSourceComboTimeHandler::Get_TimeCutFunction(Particle_t locPID, DetectorSystem_t locSystem) const
356{
357 auto locPIDIterator = dPIDTimingCuts.find(locPID);
358 if(locPIDIterator == dPIDTimingCuts.end())
359 return nullptr;
360
361 auto& locSystemMap = locPIDIterator->second;
362 auto locSystemIterator = locSystemMap.find(locSystem);
363 if(locSystemIterator == locSystemMap.end())
364 return nullptr;
365
366 return locSystemIterator->second;
367}
368
369}
370
371#endif // DSourceComboTimeHandler_h