Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DKinFitUtils_GlueX.h
Go to the documentation of this file.
1 #ifndef _DKinFitUtils_GlueX_
2 #define _DKinFitUtils_GlueX_
3 
4 #include <deque>
5 #include <vector>
6 #include <map>
7 #include <set>
8 
9 #include "TVector3.h"
10 #include "TMatrixFSym.h"
11 #include "TLorentzVector.h"
12 
13 #include "particleType.h"
14 
15 #include "DANA/DApplication.h"
18 #include "PID/DBeamPhoton.h"
19 #include "PID/DNeutralShower.h"
20 #include "PID/DKinematicData.h"
22 
25 #include "PID/DNeutralShower.h"
26 #include "PID/DKinematicData.h"
27 #include "PID/DBeamPhoton.h"
28 
29 #include "KINFITTER/DKinFitter.h"
30 #include "KINFITTER/DKinFitUtils.h"
31 
32 #include "ANALYSIS/DReaction.h"
35 
36 using namespace std;
37 
39 {
40  public:
41 
42  /***************************************************************** INITIALIZE ***************************************************************/
43 
44  //CONSTRUCTORS //call either one
45  DKinFitUtils_GlueX(JEventLoop* locEventLoop);
46  //useful for manually using a different field:
47  DKinFitUtils_GlueX(const DMagneticFieldMap* locMagneticFieldMap, const DAnalysisUtilities* locAnalysisUtilities);
48 
49  void Reset_NewEvent(void);
50  void Set_IncludeBeamlineInVertexFitFlag(bool locIncludeBeamlineInVertexFitFlag){dIncludeBeamlineInVertexFitFlag = locIncludeBeamlineInVertexFitFlag;}
51 
52  /************************************************************** CREATE PARTICLES ************************************************************/
53 
54  //If multiple constraints, it is EXTREMELY CRITICAL that only one DKinFitParticle be created per particle,
55  //so that the particles are correctly linked across constraints!!
56  //If a particle has already been created from this source object, will instead just return the originally-created input kinfit particle
57  //This particle is guaranteed to be unchanged after it is created. Instead of updating it, the kinematic fitter clones a new (output) copy
58 
59  shared_ptr<DKinFitParticle> Make_BeamParticle(const DBeamPhoton* locBeamPhoton);
60  shared_ptr<DKinFitParticle> Make_BeamParticle(const DBeamPhoton* locBeamPhoton, const DEventRFBunch* locEventRFBunch); //sets rf time for photon
61  shared_ptr<DKinFitParticle> Make_DetectedParticle(const DKinematicData* locKinematicData);
62  using DKinFitUtils::Make_DetectedParticle; //this is necessary because the above declaration hides the base class function, which is needed by DKinFitResults_factory
63 
64  shared_ptr<DKinFitParticle> Make_DetectedShower(const DNeutralShower* locNeutralShower, Particle_t locPID); //DO NOT call this unless the neutral is also in a vertex fit!
65  shared_ptr<DKinFitParticle> Make_TargetParticle(Particle_t locPID, size_t locInstance = 0); //instance: can have target 2x in same combo: rescattering
66  shared_ptr<DKinFitParticle> Make_DecayingParticle(Particle_t locPID, const set<shared_ptr<DKinFitParticle>>& locFromInitialState, const set<shared_ptr<DKinFitParticle>>& locFromFinalState);
67  shared_ptr<DKinFitParticle> Make_MissingParticle(Particle_t locPID);
68 
69  /************************************************************** RETURN MAPPING **************************************************************/
70 
71  const JObject* Get_SourceJObject(const shared_ptr<DKinFitParticle>& locInputKinFitParticle) const;
72 
73  /************************************************************ CREATE DKINFITCHAIN ***********************************************************/
74 
75  //optional: can help make constraints
76  shared_ptr<const DKinFitChain> Make_KinFitChain(const DReactionVertexInfo* locReactionVertexInfo, const DReaction* locReaction, const DParticleCombo* locParticleCombo, DKinFitType locKinFitType);
77 
78  /************************************************************* CREATE CONSTRAINTS ***********************************************************/
79 
80  set<shared_ptr<DKinFitConstraint>> Create_Constraints(const DReactionVertexInfo* locReactionVertexInfo, const DReaction* locReaction, const DParticleCombo* locParticleCombo, const shared_ptr<const DKinFitChain>& locKinFitChain, DKinFitType locKinFitType, vector<shared_ptr<DKinFitConstraint_Vertex>>& locSortedVertexConstraints);
81 
82  /************************************************************ CONSTRAINT PREDICTORS *********************************************************/
83 
84  tuple<size_t, size_t, string> Predict_VertexConstraints(const DReactionVertexInfo* locReactionVertexInfo, bool locSpacetimeFitFlag) const;
85  string Get_ConstraintInfo(const DReactionVertexInfo* locReactionVertexInfo, const DReaction* locReaction, size_t& locNumConstraints, size_t& locNumUnknowns) const;
86 
87  /*********************************************************** CALCULATION ROUTINES ***********************************************************/
88 
89  bool Propagate_TrackInfoToCommonVertex(DKinematicData* locKinematicData, DKinFitParticle* locKinFitParticle, const TMatrixDSym* locVXi);
90 
91  inline TVector3 Make_TVector3(DVector3 locDVector3) const;
92  inline TLorentzVector Make_TLorentzVector(DLorentzVector locDLorentzVector) const;
93 
94  /******************************************************* OVERRIDE BASE CLASS FUNCTIONS ******************************************************/
95 
96  bool Get_IncludeBeamlineInVertexFitFlag(void) const;
97  TVector3 Get_BField(const TVector3& locPosition) const; //must return in units of Tesla!!
98  bool Get_IsBFieldNearBeamline(void) const;
99 
100  private:
101 
102  //PRIVATE DEFAULT CONSTRUCTOR
103  DKinFitUtils_GlueX(void){} //Cannot use default constructor. Must construct with DMagneticFieldMap as argument
104 
105  /************************************************************ CREATE DKINFITCHAIN ***********************************************************/
106 
107  shared_ptr<DKinFitChainStep> Make_KinFitChainStep(const DReactionVertexInfo* locReactionVertexInfo, const DReaction* locReaction, const DParticleCombo* locParticleCombo, DKinFitType locKinFitType, size_t locStepIndex, const shared_ptr<DKinFitChain>& locKinFitChain);
108  pair<set<shared_ptr<DKinFitParticle>>, set<shared_ptr<DKinFitParticle>>> Get_StepParticles_NonNull(const shared_ptr<const DKinFitChain>& locKinFitChain, const DReaction* locReaction, size_t locStepIndex, int locNonFixedMassParticleIndex = -99) const;
109  set<shared_ptr<DKinFitParticle>> Build_ParticleSet(const vector<pair<int, int>>& locParticleIndices, const shared_ptr<const DKinFitChain>& locKinFitChain);
110 
111  /************************************************************ CONSTRAINT PREDICTORS *********************************************************/
112 
113  string Build_VertexConstraintString(const DReactionStepVertexInfo* locVertexInfo, bool locSpacetimeFitFlag) const;
114 
115  /*************************************************************** NESTED CLASS ***************************************************************/
116 
118  {
119  public:
120  DDecayingParticleInfo(Particle_t locPID, const set<shared_ptr<DKinFitParticle>>& locFromInitialState, const set<shared_ptr<DKinFitParticle>>& locFromFinalState) :
121  dPID(locPID), dFromInitialState(locFromInitialState), dFromFinalState(locFromFinalState) {}
122 
123  bool operator<(const DDecayingParticleInfo& locDecayingParticleInfo) const;
124 
126  set<shared_ptr<DKinFitParticle>> dFromInitialState;
127  set<shared_ptr<DKinFitParticle>> dFromFinalState;
128  };
129 
130  /************************************************************ MAGNETIC FIELD MAP ************************************************************/
131 
134 
135  /************************************************************* PARTICLE MAPPING *************************************************************/
136 
137  //PARTICLE MAPPING
138  //Particles are created like so: source -> input kinfit particle -> output kinfit particle
139  //Cannot map input -> output: many outputs for a given input (same particle used in multiple kinfits)
140  //can map: source -> input, input -> source, output -> input (base class)
141 
142  //MAP: SOURCE -> KINFIT INPUT
143  //Needed internally for cloning
144  map<pair<const DBeamPhoton*, const DEventRFBunch*>, shared_ptr<DKinFitParticle>> dParticleMap_SourceToInput_Beam;
145  map<const DKinematicData*, shared_ptr<DKinFitParticle>> dParticleMap_SourceToInput_DetectedParticle;
146  map<pair<const DNeutralShower*, Particle_t>, shared_ptr<DKinFitParticle>> dParticleMap_SourceToInput_Shower;
147  map<pair<Particle_t, size_t>, shared_ptr<DKinFitParticle>> dParticleMap_SourceToInput_Target; //size_t: instance (can have target 2x in same combo: rescattering)
148  map<DDecayingParticleInfo, shared_ptr<DKinFitParticle>> dParticleMap_SourceToInput_Decaying;
149  map<Particle_t, shared_ptr<DKinFitParticle>> dParticleMap_SourceToInput_Missing;
150 
151  //MAP: KINFIT INPUT -> SOURCE
152  //no maps for missing or target: would just map to PID
153  //needed for getting back to the source particle
154  map<shared_ptr<DKinFitParticle>, const JObject*> dParticleMap_InputToSource_JObject;
156 
157  /************************************************************** MISCELLANEOUS ***************************************************************/
158 
162 };
163 
164 inline TVector3 DKinFitUtils_GlueX::Make_TVector3(DVector3 locDVector3) const
165 {
166  return TVector3(locDVector3.X(), locDVector3.Y(), locDVector3.Z());
167 }
168 
169 inline TLorentzVector DKinFitUtils_GlueX::Make_TLorentzVector(DLorentzVector locDLorentzVector) const
170 {
171  return TLorentzVector(locDLorentzVector.X(), locDLorentzVector.Y(), locDLorentzVector.Z(), locDLorentzVector.T());
172 }
173 
174 inline const JObject* DKinFitUtils_GlueX::Get_SourceJObject(const shared_ptr<DKinFitParticle>& locInputKinFitParticle) const
175 {
176  DKinFitParticleType locKinFitParticleType = locInputKinFitParticle->Get_KinFitParticleType();
177  if((locKinFitParticleType == d_DecayingParticle) || (locKinFitParticleType == d_MissingParticle) || (locKinFitParticleType == d_TargetParticle))
178  return NULL;
179 
180  auto locIterator = dParticleMap_InputToSource_JObject.find(locInputKinFitParticle);
181  return ((locIterator != dParticleMap_InputToSource_JObject.end()) ? locIterator->second : NULL);
182 }
183 
185 {
186  if(dPID < locDecayingParticleInfo.dPID)
187  return true;
188  else if(dPID > locDecayingParticleInfo.dPID)
189  return false;
190 
191  if(dFromInitialState < locDecayingParticleInfo.dFromInitialState)
192  return true;
193  else if(dFromInitialState > locDecayingParticleInfo.dFromInitialState)
194  return false;
195 
196  return (dFromFinalState < locDecayingParticleInfo.dFromFinalState);
197 }
198 
199 #endif // _DKinFitUtils_GlueX_
200 
const DAnalysisUtilities * dAnalysisUtilities
bool operator<(const DSourceComboUse &lhs, const DSourceComboUse &rhs)
Definition: DSourceCombo.h:95
TVector3 DVector3
Definition: DVector3.h:14
map< pair< const DBeamPhoton *, const DEventRFBunch * >, shared_ptr< DKinFitParticle > > dParticleMap_SourceToInput_Beam
map< Particle_t, shared_ptr< DKinFitParticle > > dParticleMap_SourceToInput_Missing
shared_ptr< DKinFitParticle > Make_DetectedParticle(int locPID, int locCharge, double locMass, TLorentzVector locSpacetimeVertex, TVector3 locMomentum, double locPathLength, const shared_ptr< const TMatrixFSym > &locCovarianceMatrix)
DKinFitParticleType
string Build_VertexConstraintString(const DReactionStepVertexInfo *locVertexInfo, bool locSpacetimeFitFlag)
TLorentzVector Make_TLorentzVector(DLorentzVector locDLorentzVector) const
TLorentzVector DLorentzVector
set< shared_ptr< DKinFitParticle > > dFromInitialState
TVector3 Make_TVector3(DVector3 locDVector3) const
DDecayingParticleInfo(Particle_t locPID, const set< shared_ptr< DKinFitParticle >> &locFromInitialState, const set< shared_ptr< DKinFitParticle >> &locFromFinalState)
map< DDecayingParticleInfo, shared_ptr< DKinFitParticle > > dParticleMap_SourceToInput_Decaying
DApplication * dApplication
map< shared_ptr< DKinFitParticle >, DDecayingParticleInfo > dParticleMap_InputToSource_Decaying
map< pair< const DNeutralShower *, Particle_t >, shared_ptr< DKinFitParticle > > dParticleMap_SourceToInput_Shower
set< shared_ptr< DKinFitParticle > > dFromFinalState
void Set_IncludeBeamlineInVertexFitFlag(bool locIncludeBeamlineInVertexFitFlag)
const JObject * Get_SourceJObject(const shared_ptr< DKinFitParticle > &locInputKinFitParticle) const
map< shared_ptr< DKinFitParticle >, const JObject * > dParticleMap_InputToSource_JObject
map< const DKinematicData *, shared_ptr< DKinFitParticle > > dParticleMap_SourceToInput_DetectedParticle
const DMagneticFieldMap * dMagneticFieldMap
map< pair< Particle_t, size_t >, shared_ptr< DKinFitParticle > > dParticleMap_SourceToInput_Target
Particle_t
Definition: particleType.h:12
bool operator<(const DDecayingParticleInfo &locDecayingParticleInfo) const