5 using namespace DAnalysis;
7 jerror_t DReactionVertexInfo_factory::init(
void)
10 SetFactoryFlag(PERSISTANT);
13 gPARMS->SetDefaultParameter(
"VERTEXINFO:DEBUG_LEVEL", dDebugLevel);
18 jerror_t DReactionVertexInfo_factory::evnt(JEventLoop *locEventLoop, uint64_t locEventNumber)
23 for(
auto locReactionIterator = locReactions.begin(); locReactionIterator != locReactions.end(); ++locReactionIterator)
25 auto locReaction = *locReactionIterator;
28 auto Equality_Checker = [&locReaction](
const pair<const DReaction*, DReactionVertexInfo*>& locReactionPair) ->
bool
32 auto locSearchIterator = std::find_if(dVertexInfoMap.begin(), dVertexInfoMap.end(), Equality_Checker);
33 if(locSearchIterator != dVertexInfoMap.end())
36 auto locVertexInfo = locSearchIterator->second;
37 locVertexInfo->Add_Reaction(locReaction);
42 auto locVertexInfo = Build_VertexInfo(locReaction);
45 cout <<
"CREATED REACTION VERTEX INFO:" << endl;
49 _data.push_back(locVertexInfo);
50 dVertexInfoMap.emplace(locReaction, locVertexInfo);
58 set<size_t> locStepIndexSet;
59 vector<DReactionStepVertexInfo*> locVertexInfos;
62 if(locStepIndexSet.find(loc_i) != locStepIndexSet.end())
66 auto locVertexInfo = Setup_VertexInfo(locReaction, loc_i,
nullptr);
67 locVertexInfos.push_back(locVertexInfo);
69 auto locStepIndexVector = locVertexInfo->Get_StepIndices();
70 std::copy(locStepIndexVector.begin(), locStepIndexVector.end(), std::inserter(locStepIndexSet, locStepIndexSet.end()));
72 Group_VertexParticles(locVertexInfo);
75 cout <<
"Grouped vertex info: " << endl;
81 std::reverse(std::begin(locVertexInfos), std::end(locVertexInfos));
84 locVertexInfos = Link_Vertices(locReaction, locVertexInfos,
false);
87 cout <<
"Linked vertex infos, fitflag = false: " << endl;
88 for(
auto& locVertexInfo : locVertexInfos)
91 locVertexInfos = Link_Vertices(locReaction, locVertexInfos,
true);
98 if(locVertexInfo ==
nullptr)
100 locVertexInfo = dResourcePool_ReactionStepVertexInfo->Get_Resource();
101 locVertexInfo->
Reset();
102 locVertexInfo->
Set_Members(locReaction, locStepIndex);
110 if(locReactionStep->Get_IsInclusiveFlag())
112 for(
size_t loc_i = 0; loc_i < locReactionStep->Get_NumFinalPIDs(); ++loc_i)
116 auto locPID = locReactionStep->Get_FinalPID(loc_i);
118 Setup_VertexInfo(locReaction, locDecayStepIndex, locVertexInfo);
121 return locVertexInfo;
128 vector<pair<int, int>> locDecayingParticles, locOnlyConstrainTimeParticles;
129 vector<pair<int, int>> locFullConstrainParticles_Fit, locNoConstrainParticles_Fit, locFullConstrainParticles_Recon, locNoConstrainParticles_Recon;
132 bool locFirstStepFlag =
true;
133 for(
auto locStepIndex : locStepIndices)
135 auto locStep = locReaction->Get_ReactionStep(locStepIndex);
141 if(locStep->Get_IsBeamMissingFlag())
143 locNoConstrainParticles_Fit.emplace_back(locStepIndex, DReactionStep::Get_ParticleIndex_Initial());
144 locNoConstrainParticles_Recon.emplace_back(locStepIndex, DReactionStep::Get_ParticleIndex_Initial());
148 locFullConstrainParticles_Recon.emplace_back(locStepIndex, DReactionStep::Get_ParticleIndex_Initial());
149 if(dKinFitUtils->Get_IncludeBeamlineInVertexFitFlag())
150 locFullConstrainParticles_Fit.emplace_back(locStepIndex, DReactionStep::Get_ParticleIndex_Initial());
152 locNoConstrainParticles_Fit.emplace_back(locStepIndex, DReactionStep::Get_ParticleIndex_Initial());
156 if(locStep->Get_SecondBeamPID() !=
Unknown)
158 if(locStep->Get_IsBeamMissingFlag())
160 locNoConstrainParticles_Fit.emplace_back(locStepIndex, DReactionStep::Get_ParticleIndex_SecondBeam());
161 locNoConstrainParticles_Recon.emplace_back(locStepIndex, DReactionStep::Get_ParticleIndex_SecondBeam());
165 locFullConstrainParticles_Recon.emplace_back(locStepIndex, DReactionStep::Get_ParticleIndex_SecondBeam());
166 if(dKinFitUtils->Get_IncludeBeamlineInVertexFitFlag())
167 locFullConstrainParticles_Fit.emplace_back(locStepIndex, DReactionStep::Get_ParticleIndex_SecondBeam());
169 locNoConstrainParticles_Fit.emplace_back(locStepIndex, DReactionStep::Get_ParticleIndex_SecondBeam());
173 else if(locFirstStepFlag)
174 locDecayingParticles.emplace_back(locStepIndex, DReactionStep::Get_ParticleIndex_Initial());
177 if(locStep->Get_TargetPID() !=
Unknown)
179 locNoConstrainParticles_Fit.emplace_back(locStepIndex, DReactionStep::Get_ParticleIndex_Target());
180 locNoConstrainParticles_Recon.emplace_back(locStepIndex, DReactionStep::Get_ParticleIndex_Target());
184 auto locFinalPIDs = locStep->Get_FinalPIDs();
185 for(
size_t loc_i = 0; loc_i < locFinalPIDs.size(); ++loc_i)
189 if(locDecayStepIndex >= 0)
190 locDecayingParticles.emplace_back(locStepIndex, loc_i);
191 else if(
int(loc_i) == locStep->Get_MissingParticleIndex())
193 locNoConstrainParticles_Fit.emplace_back(locStepIndex, loc_i);
194 locNoConstrainParticles_Recon.emplace_back(locStepIndex, loc_i);
198 locFullConstrainParticles_Fit.emplace_back(locStepIndex, loc_i);
199 locFullConstrainParticles_Recon.emplace_back(locStepIndex, loc_i);
201 else if(locFinalPIDs[loc_i] ==
Gamma)
202 locOnlyConstrainTimeParticles.emplace_back(locStepIndex, loc_i);
205 locNoConstrainParticles_Fit.emplace_back(locStepIndex, loc_i);
206 locNoConstrainParticles_Recon.emplace_back(locStepIndex, loc_i);
210 locFirstStepFlag =
false;
213 locVertexInfo->
Set_ParticleIndices(
true, locFullConstrainParticles_Fit, locDecayingParticles, locOnlyConstrainTimeParticles, locNoConstrainParticles_Fit);
214 locVertexInfo->
Set_ParticleIndices(
false, locFullConstrainParticles_Recon, locDecayingParticles, locOnlyConstrainTimeParticles, locNoConstrainParticles_Recon);
217 vector<DReactionStepVertexInfo*> DReactionVertexInfo_factory::Link_Vertices(
const DReaction* locReaction, vector<DReactionStepVertexInfo*> locVertexInfos,
bool locFitFlag)
const
223 bool locProgessMadeFlag =
false;
224 bool locTryMissingParticleVertexFlag =
false;
225 auto locVertexIterator = locVertexInfos.begin();
227 vector<DReactionStepVertexInfo*> locSortedVertexInfos;
228 while(!locVertexInfos.empty())
230 if(locVertexIterator == locVertexInfos.end())
233 if(!locProgessMadeFlag)
235 if(locTryMissingParticleVertexFlag)
237 locTryMissingParticleVertexFlag =
true;
239 cout <<
"try another loop, using missing mass" << endl;
243 locVertexIterator = locVertexInfos.begin();
244 locProgessMadeFlag =
false;
249 auto locVertexInfo = *locVertexIterator;
250 if(!locTryMissingParticleVertexFlag && !locVertexInfo->Get_MissingParticles().empty())
256 locProgessMadeFlag = Associate_DecayingParticles(locFitFlag,
true, locVertexInfo, locDefinedDecayingParticles);
257 if(!locProgessMadeFlag)
261 locVertexIterator = locVertexInfos.erase(locVertexIterator);
262 locSortedVertexInfos.push_back(locVertexInfo);
268 for(
auto locVertexInfo : locVertexInfos)
270 Associate_DecayingParticles(locFitFlag,
false, locVertexInfo, locDefinedDecayingParticles);
271 locSortedVertexInfos.push_back(locVertexInfo);
275 unordered_map<size_t, DReactionStepVertexInfo*> locVertexInfoMap;
276 for(
auto locVertexInfo : locSortedVertexInfos)
278 for(
auto locStepIndex : locVertexInfo->Get_StepIndices())
279 locVertexInfoMap[locStepIndex] = locVertexInfo;
281 for(
auto locVertexInfo : locSortedVertexInfos)
283 auto locPrimaryStepIndex = locVertexInfo->Get_StepIndices().front();
284 if(locPrimaryStepIndex == 0)
287 locVertexInfo->Set_ParentVertexInfo(locVertexInfoMap[locParentStepIndex]);
290 return locSortedVertexInfos;
297 cout <<
"Associate_DecayingParticles: fit flag, link flag, info, #defined decaying: " << locFitFlag <<
", " << locLinkingFlag <<
", " << locVertexInfo <<
", " << locDefinedDecayingParticles.size() << endl;
302 vector<pair<int, int>> locNoConstrainDecayingParticles;
305 for(
auto locParticlePair : locDecayingParticles)
307 auto locIterator = locDefinedDecayingParticles.find(locParticlePair);
308 if(locIterator != locDefinedDecayingParticles.end())
309 locConstrainingDecayingParticles.emplace(*locIterator);
311 locNoConstrainDecayingParticles.emplace_back(locParticlePair);
314 cout <<
"# decaying particles, constrain/no-constrain: " << locConstrainingDecayingParticles.size() <<
", " << locNoConstrainDecayingParticles.size() << endl;
324 auto locNumConstrainingParticles = locConstrainingDecayingParticles.size() + locVertexInfo->
Get_FullConstrainParticles(locFitFlag).size();
328 cout <<
"#constraining: " << locNumConstrainingParticles << endl;
330 bool locEnoughTracksFlag = (locNumConstrainingParticles >= 2);
331 if(locLinkingFlag && !locEnoughTracksFlag)
337 for(
const auto& locMapPair : locConstrainingDecayingParticles)
341 locDefinedDecayingParticles.erase(locMapPair.first);
358 for(
auto locParticlePair : locNoConstrainDecayingParticles)
361 cout <<
"defined decaying particle indices: " << locParticlePair.first <<
", " << locParticlePair.second << endl;
362 if(locParticlePair.second < 0)
366 cout <<
"registering decaying particle indices: " << locParticlePairToRegister.first <<
", " << locParticlePairToRegister.second << endl;
367 locDefinedDecayingParticles.emplace(locParticlePairToRegister, locVertexInfo);
372 auto locParticlePairToRegister = std::make_pair(locDecayStepIndex, DReactionStep::Get_ParticleIndex_Initial());
374 cout <<
"registering decaying particle indices: " << locParticlePairToRegister.first <<
", " << locParticlePairToRegister.second << endl;
375 locDefinedDecayingParticles.emplace(locParticlePairToRegister, locVertexInfo);
vector< pair< int, int > > Get_FullConstrainParticles(bool locFitFlag, DReactionState_t locState=d_EitherState, Charge_t locCharge=d_AllCharges, bool locIncludeDecayingFlag=true) const
bool Get_IsFirstStepBeam(const DReaction *locReaction)
pair< int, int > Get_InitialParticleDecayFromIndices(const DReaction *locReaction, int locStepIndex)
void Register_DecayingNoConstrainUseVertex(bool locFitFlag, const pair< int, int > &locDecayingNoConstrainPair, const DReactionStepVertexInfo *locVertexInfo)
bool Check_ChannelEquality(const DReaction *lhs, const DReaction *rhs, bool locSameOrderFlag=true, bool locRightSubsetOfLeftFlag=false)
vector< const DReaction * > Get_Reactions(JEventLoop *locEventLoop)
void Set_Members(const DReaction *locReaction, size_t locStartStepIndex)
void Print_ReactionStepVertexInfo(const DReactionStepVertexInfo *locStepInfo)
void Set_FittableVertexFlag(bool locIsFittableVertexFlag)
static unsigned short int IsDetachedVertex(Particle_t p)
vector< pair< int, int > > Get_MissingParticles(DReactionState_t locState=d_EitherState, Charge_t locCharge=d_AllCharges) const
static int ParticleCharge(Particle_t p)
void Set_ParticleIndices(bool locFitFlag, const vector< pair< int, int >> &locFullConstrainParticles, const vector< pair< int, int >> &locDecayingParticles, const vector< pair< int, int >> &locOnlyConstrainTimeParticles, const vector< pair< int, int >> &locNoConstrainParticles)
void Print_ReactionVertexInfo(const DReactionVertexInfo *locReactionInfo)
void Set_IsInclusiveVertexFlag(bool locIsInclusiveVertexFlag)
const DReaction * Get_Reaction(void) const
void Add_ReactionStep(size_t locStepIndex)
void Set_DanglingVertexFlag(bool locIsDanglingVertexFlag)
void Register_DecayingParticleConstraints(bool locFitFlag, const vector< pair< int, int >> &locNoConstrainDecayingParticles, const map< pair< int, int >, const DReactionStepVertexInfo * > &locFullConstrainDecayingParticles)
vector< pair< int, int > > Get_DecayingParticles(DReactionState_t locState=d_EitherState, Charge_t locCharge=d_AllCharges) const
const DReactionStep * Get_ReactionStep(size_t locStepIndex) const
int Get_DecayStepIndex(const DReaction *locReaction, size_t locStepIndex, size_t locParticleIndex)
bool Get_IsInclusiveVertexFlag(void) const
vector< size_t > Get_StepIndices(void) const
size_t Get_NumReactionSteps(void) const