Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
TestBeamEventValidationAlgorithm.cc
Go to the documentation of this file.
1
10
14
16
17#include <sstream>
18
19using namespace pandora;
20
21namespace lar_content
22{
23
27
28//------------------------------------------------------------------------------------------------------------------------------------------
29
33
34//------------------------------------------------------------------------------------------------------------------------------------------
35
37 const CaloHitList *const pCaloHitList, const PfoList *const pPfoList, ValidationInfo &validationInfo) const
38{
39 if (pMCParticleList && pCaloHitList)
40 {
41 LArMCParticleHelper::MCContributionMap targetMCParticleToHitsMap;
43 pMCParticleList, pCaloHitList, m_primaryParameters, LArMCParticleHelper::IsBeamParticle, targetMCParticleToHitsMap);
45 pMCParticleList, pCaloHitList, m_primaryParameters, LArMCParticleHelper::IsCosmicRay, targetMCParticleToHitsMap);
46
48 parameters.m_minPrimaryGoodHits = 0;
49 parameters.m_minHitsForGoodView = 0;
50 parameters.m_minHitSharingFraction = 0.f;
51 LArMCParticleHelper::MCContributionMap allMCParticleToHitsMap;
53 pMCParticleList, pCaloHitList, parameters, LArMCParticleHelper::IsBeamParticle, allMCParticleToHitsMap);
55 pMCParticleList, pCaloHitList, parameters, LArMCParticleHelper::IsCosmicRay, allMCParticleToHitsMap);
56
57 validationInfo.SetTargetMCParticleToHitsMap(targetMCParticleToHitsMap);
58 validationInfo.SetAllMCParticleToHitsMap(allMCParticleToHitsMap);
59 }
60
61 if (pPfoList)
62 {
63 PfoList allConnectedPfos;
64 LArPfoHelper::GetAllConnectedPfos(*pPfoList, allConnectedPfos);
65
66 PfoList finalStatePfos;
67 for (const ParticleFlowObject *const pPfo : allConnectedPfos)
68 {
69 if (pPfo->GetParentPfoList().empty())
70 finalStatePfos.push_back(pPfo);
71 }
72
75 finalStatePfos, validationInfo.GetAllMCParticleToHitsMap(), pfoToHitsMap, m_primaryParameters.m_foldBackHierarchy);
76
77 validationInfo.SetPfoToHitsMap(pfoToHitsMap);
78 }
79
83 validationInfo.GetPfoToHitsMap(), {validationInfo.GetAllMCParticleToHitsMap()}, pfoToMCHitSharingMap, mcToPfoHitSharingMap);
84 validationInfo.SetMCToPfoHitSharingMap(mcToPfoHitSharingMap);
85
86 LArMCParticleHelper::MCParticleToPfoHitSharingMap interpretedMCToPfoHitSharingMap;
87 this->InterpretMatching(validationInfo, interpretedMCToPfoHitSharingMap);
88 validationInfo.SetInterpretedMCToPfoHitSharingMap(interpretedMCToPfoHitSharingMap);
89}
90
91//------------------------------------------------------------------------------------------------------------------------------------------
92
94 const ValidationInfo &validationInfo, const bool useInterpretedMatching, const bool printToScreen, const bool fillTree) const
95{
96 static int eventNumber{-1};
97 ++eventNumber;
98 if (printToScreen && useInterpretedMatching)
99 std::cout << "---INTERPRETED-MATCHING-OUTPUT------------------------------------------------------------------" << std::endl;
100 else if (printToScreen)
101 std::cout << "---RAW-MATCHING-OUTPUT--------------------------------------------------------------------------" << std::endl;
102
103 const LArMCParticleHelper::MCParticleToPfoHitSharingMap &mcToPfoHitSharingMap(
104 useInterpretedMatching ? validationInfo.GetInterpretedMCToPfoHitSharingMap() : validationInfo.GetMCToPfoHitSharingMap());
105
106 MCParticleVector mcPrimaryVector;
108
109 // Test Beam Validation Bookkeeping
110 PfoVector primaryPfoVector;
111 LArMonitoringHelper::GetOrderedPfoVector(validationInfo.GetPfoToHitsMap(), primaryPfoVector);
112
113 int pfoIndex(0), testBeamPfoIndex(0);
114 PfoToIdMap pfoToIdMap, testBeamPfoToIdMap;
115
116 for (const Pfo *const pPrimaryPfo : primaryPfoVector)
117 {
118 pfoToIdMap.insert(PfoToIdMap::value_type(pPrimaryPfo, ++pfoIndex));
119 const Pfo *const pRecoTestBeam(LArPfoHelper::IsTestBeamFinalState(pPrimaryPfo) ? LArPfoHelper::GetParentPfo(pPrimaryPfo) : nullptr);
120
121 if (pRecoTestBeam && !testBeamPfoToIdMap.count(pRecoTestBeam))
122 testBeamPfoToIdMap.insert(PfoToIdMap::value_type(pRecoTestBeam, ++testBeamPfoIndex));
123 }
124
125 LArMCParticleHelper::MCParticleIntMap triggeredToLeading, triggeredToLeadingCounter;
126
127 MCParticleList associatedMCPrimaries;
128
129 int nCorrectTB(0), nTotalTB(0), nCorrectCR(0), nTotalCR(0), nFakeTB(0), nFakeCR(0), nSplitTB(0), nSplitCR(0), nLost(0);
130 int mcPrimaryIndex(0), nTargetMatches(0), nTargetTBMatches(0), nTargetCRMatches(0);
131 IntVector mcPrimaryId, mcPrimaryPdg, nMCHitsTotal, nMCHitsU, nMCHitsV, nMCHitsW;
132 FloatVector mcPrimaryE, mcPrimaryPX, mcPrimaryPY, mcPrimaryPZ;
133 FloatVector mcPrimaryVtxX, mcPrimaryVtxY, mcPrimaryVtxZ, mcPrimaryEndX, mcPrimaryEndY, mcPrimaryEndZ;
134 IntVector nPrimaryMatchedPfos, nPrimaryMatchedTBPfos, nPrimaryMatchedCRPfos;
135 IntVector bestMatchPfoId, bestMatchPfoPdg, bestMatchPfoIsTB;
136 IntVector bestMatchPfoNHitsTotal, bestMatchPfoNHitsU, bestMatchPfoNHitsV, bestMatchPfoNHitsW;
137 IntVector bestMatchPfoNSharedHitsTotal, bestMatchPfoNSharedHitsU, bestMatchPfoNSharedHitsV, bestMatchPfoNSharedHitsW;
138 FloatVector bestMatchPfoX0;
139
140 std::stringstream targetSS;
141
142 for (const MCParticle *const pMCPrimary : mcPrimaryVector)
143 {
144 const bool hasMatch(mcToPfoHitSharingMap.count(pMCPrimary) && !mcToPfoHitSharingMap.at(pMCPrimary).empty());
145 const bool isTargetPrimary(validationInfo.GetTargetMCParticleToHitsMap().count(pMCPrimary));
146
147 if (!isTargetPrimary && !hasMatch)
148 continue;
149
150 associatedMCPrimaries.push_back(pMCPrimary);
151 ++mcPrimaryIndex;
152 const CaloHitList &mcPrimaryHitList(validationInfo.GetAllMCParticleToHitsMap().at(pMCPrimary));
153
155 const int isBeamParticle(LArMCParticleHelper::IsBeamParticle(pMCPrimary));
156 const int isCosmicRay(LArMCParticleHelper::IsCosmicRay(pMCPrimary));
157#ifdef MONITORING
158 const int nTargetPrimaries(associatedMCPrimaries.size());
159 const CartesianVector &targetVertex(LArMCParticleHelper::GetParentMCParticle(pMCPrimary)->GetVertex());
160 const float targetVertexX(targetVertex.GetX()), targetVertexY(targetVertex.GetY()), targetVertexZ(targetVertex.GetZ());
161#endif
162
163 targetSS << (!isTargetPrimary ? "(Non target) " : "") << "PrimaryId " << mcPrimaryIndex << ", TB " << isBeamParticle << ", CR "
164 << isCosmicRay << ", MCPDG " << pMCPrimary->GetParticleId() << ", Energy " << pMCPrimary->GetEnergy() << ", Dist. "
165 << (pMCPrimary->GetEndpoint() - pMCPrimary->GetVertex()).GetMagnitude() << ", nMCHits " << mcPrimaryHitList.size() << " ("
166 << LArMonitoringHelper::CountHitsByType(TPC_VIEW_U, mcPrimaryHitList) << ", "
167 << LArMonitoringHelper::CountHitsByType(TPC_VIEW_V, mcPrimaryHitList) << ", "
168 << LArMonitoringHelper::CountHitsByType(TPC_VIEW_W, mcPrimaryHitList) << ")" << std::endl;
169
170 mcPrimaryId.push_back(mcPrimaryIndex);
171 mcPrimaryPdg.push_back(pMCPrimary->GetParticleId());
172 mcPrimaryE.push_back(pMCPrimary->GetEnergy());
173 mcPrimaryPX.push_back(pMCPrimary->GetMomentum().GetX());
174 mcPrimaryPY.push_back(pMCPrimary->GetMomentum().GetY());
175 mcPrimaryPZ.push_back(pMCPrimary->GetMomentum().GetZ());
176 mcPrimaryVtxX.push_back(pMCPrimary->GetVertex().GetX());
177 mcPrimaryVtxY.push_back(pMCPrimary->GetVertex().GetY());
178 mcPrimaryVtxZ.push_back(pMCPrimary->GetVertex().GetZ());
179 mcPrimaryEndX.push_back(pMCPrimary->GetEndpoint().GetX());
180 mcPrimaryEndY.push_back(pMCPrimary->GetEndpoint().GetY());
181 mcPrimaryEndZ.push_back(pMCPrimary->GetEndpoint().GetZ());
182 nMCHitsTotal.push_back(mcPrimaryHitList.size());
183 nMCHitsU.push_back(LArMonitoringHelper::CountHitsByType(TPC_VIEW_U, mcPrimaryHitList));
184 nMCHitsV.push_back(LArMonitoringHelper::CountHitsByType(TPC_VIEW_V, mcPrimaryHitList));
185 nMCHitsW.push_back(LArMonitoringHelper::CountHitsByType(TPC_VIEW_W, mcPrimaryHitList));
186
187 int matchIndex(0), nPrimaryMatches(0), nPrimaryTBMatches(0), nPrimaryCRMatches(0);
188#ifdef MONITORING
189 float recoVertexX(std::numeric_limits<float>::max()), recoVertexY(std::numeric_limits<float>::max()),
190 recoVertexZ(std::numeric_limits<float>::max());
191#endif
192 for (const LArMCParticleHelper::PfoCaloHitListPair &pfoToSharedHits : mcToPfoHitSharingMap.at(pMCPrimary))
193 {
194 const CaloHitList &sharedHitList(pfoToSharedHits.second);
195 const CaloHitList &pfoHitList(validationInfo.GetPfoToHitsMap().at(pfoToSharedHits.first));
196
197 const bool isRecoTestBeam(LArPfoHelper::IsTestBeam(pfoToSharedHits.first));
198 const bool isGoodMatch(this->IsGoodMatch(mcPrimaryHitList, pfoHitList, sharedHitList));
199
200 const int pfoId(pfoToIdMap.at(pfoToSharedHits.first));
201
202 if (0 == matchIndex++)
203 {
204 bestMatchPfoId.push_back(pfoId);
205 bestMatchPfoPdg.push_back(pfoToSharedHits.first->GetParticleId());
206 bestMatchPfoIsTB.push_back(isRecoTestBeam ? 1 : 0);
207 bestMatchPfoNHitsTotal.push_back(pfoHitList.size());
208 bestMatchPfoNHitsU.push_back(LArMonitoringHelper::CountHitsByType(TPC_VIEW_U, pfoHitList));
209 bestMatchPfoNHitsV.push_back(LArMonitoringHelper::CountHitsByType(TPC_VIEW_V, pfoHitList));
210 bestMatchPfoNHitsW.push_back(LArMonitoringHelper::CountHitsByType(TPC_VIEW_W, pfoHitList));
211 bestMatchPfoNSharedHitsTotal.push_back(sharedHitList.size());
212 bestMatchPfoNSharedHitsU.push_back(LArMonitoringHelper::CountHitsByType(TPC_VIEW_U, sharedHitList));
213 bestMatchPfoNSharedHitsV.push_back(LArMonitoringHelper::CountHitsByType(TPC_VIEW_V, sharedHitList));
214 bestMatchPfoNSharedHitsW.push_back(LArMonitoringHelper::CountHitsByType(TPC_VIEW_W, sharedHitList));
215 bestMatchPfoX0.push_back(pfoToSharedHits.first->GetPropertiesMap().count("X0") ? pfoToSharedHits.first->GetPropertiesMap().at("X0")
216 : std::numeric_limits<float>::max());
217#ifdef MONITORING
218 try
219 {
220 const Vertex *const pRecoVertex(isRecoTestBeam ? LArPfoHelper::GetTestBeamInteractionVertex(pfoToSharedHits.first)
221 : LArPfoHelper::GetVertex(pfoToSharedHits.first));
222 recoVertexX = pRecoVertex->GetPosition().GetX();
223 recoVertexY = pRecoVertex->GetPosition().GetY();
224 recoVertexZ = pRecoVertex->GetPosition().GetZ();
225 }
226 catch (const StatusCodeException &)
227 {
228 }
229#endif
230 }
231
232 if (isGoodMatch)
233 ++nPrimaryMatches;
234
235 if (isRecoTestBeam && isGoodMatch)
236 ++nPrimaryTBMatches;
237 if (!isRecoTestBeam && isGoodMatch)
238 ++nPrimaryCRMatches;
239
240 targetSS << "-" << (!isGoodMatch ? "(Below threshold) " : "") << "MatchedPfoId " << pfoId << ", TB " << isRecoTestBeam
241 << ", CR " << (!isRecoTestBeam) << ", PDG " << pfoToSharedHits.first->GetParticleId() << ", nMatchedHits "
242 << sharedHitList.size() << " (" << LArMonitoringHelper::CountHitsByType(TPC_VIEW_U, sharedHitList) << ", "
243 << LArMonitoringHelper::CountHitsByType(TPC_VIEW_V, sharedHitList) << ", "
244 << LArMonitoringHelper::CountHitsByType(TPC_VIEW_W, sharedHitList) << ")"
245 << ", nPfoHits " << pfoHitList.size() << " (" << LArMonitoringHelper::CountHitsByType(TPC_VIEW_U, pfoHitList) << ", "
247 << LArMonitoringHelper::CountHitsByType(TPC_VIEW_W, pfoHitList) << ")" << std::endl;
248 }
249
250 if (mcToPfoHitSharingMap.at(pMCPrimary).empty())
251 {
252 targetSS << "-No matched Pfo" << std::endl;
253 bestMatchPfoId.push_back(-1);
254 bestMatchPfoPdg.push_back(0);
255 bestMatchPfoIsTB.push_back(0);
256 bestMatchPfoNHitsTotal.push_back(0);
257 bestMatchPfoNHitsU.push_back(0);
258 bestMatchPfoNHitsV.push_back(0);
259 bestMatchPfoNHitsW.push_back(0);
260 bestMatchPfoNSharedHitsTotal.push_back(0);
261 bestMatchPfoNSharedHitsU.push_back(0);
262 bestMatchPfoNSharedHitsV.push_back(0);
263 bestMatchPfoNSharedHitsW.push_back(0);
264 bestMatchPfoX0.push_back(std::numeric_limits<float>::max());
265 }
266
267 nPrimaryMatchedPfos.push_back(nPrimaryMatches);
268 nPrimaryMatchedTBPfos.push_back(nPrimaryTBMatches);
269 nPrimaryMatchedCRPfos.push_back(nPrimaryCRMatches);
270 nTargetMatches += nPrimaryMatches;
271 nTargetTBMatches += nPrimaryTBMatches;
272 nTargetCRMatches += nPrimaryCRMatches;
273
274 if (fillTree)
275 {
276 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "fileIdentifier", m_fileIdentifier));
277 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "eventNumber", eventNumber));
278 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "mcNuanceCode", mcNuanceCode));
279 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "isBeamParticle", isBeamParticle));
280 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "isCosmicRay", isCosmicRay));
281 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "nTargetPrimaries", nTargetPrimaries));
282 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "targetVertexX", targetVertexX));
283 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "targetVertexY", targetVertexY));
284 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "targetVertexZ", targetVertexZ));
285 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "recoVertexX", recoVertexX));
286 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "recoVertexY", recoVertexY));
287 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "recoVertexZ", recoVertexZ));
288 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "mcPrimaryId", &mcPrimaryId));
289 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "mcPrimaryPdg", &mcPrimaryPdg));
290 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "mcPrimaryE", &mcPrimaryE));
291 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "mcPrimaryPX", &mcPrimaryPX));
292 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "mcPrimaryPY", &mcPrimaryPY));
293 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "mcPrimaryPZ", &mcPrimaryPZ));
294 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "mcPrimaryVtxX", &mcPrimaryVtxX));
295 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "mcPrimaryVtxY", &mcPrimaryVtxY));
296 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "mcPrimaryVtxZ", &mcPrimaryVtxZ));
297 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "mcPrimaryEndX", &mcPrimaryEndX));
298 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "mcPrimaryEndY", &mcPrimaryEndY));
299 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "mcPrimaryEndZ", &mcPrimaryEndZ));
300 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "mcPrimaryNHitsTotal", &nMCHitsTotal));
301 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "mcPrimaryNHitsU", &nMCHitsU));
302 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "mcPrimaryNHitsV", &nMCHitsV));
303 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "mcPrimaryNHitsW", &nMCHitsW));
304 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "nPrimaryMatchedPfos", &nPrimaryMatchedPfos));
305 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "nPrimaryMatchedTBPfos", &nPrimaryMatchedTBPfos));
306 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "nPrimaryMatchedCRPfos", &nPrimaryMatchedCRPfos));
307 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "bestMatchPfoId", &bestMatchPfoId));
308 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "bestMatchPfoPdg", &bestMatchPfoPdg));
309 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "bestMatchPfoNHitsTotal", &bestMatchPfoNHitsTotal));
310 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "bestMatchPfoNHitsU", &bestMatchPfoNHitsU));
311 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "bestMatchPfoNHitsV", &bestMatchPfoNHitsV));
312 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "bestMatchPfoNHitsW", &bestMatchPfoNHitsW));
313 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "bestMatchPfoNSharedHitsTotal", &bestMatchPfoNSharedHitsTotal));
314 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "bestMatchPfoNSharedHitsU", &bestMatchPfoNSharedHitsU));
315 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "bestMatchPfoNSharedHitsV", &bestMatchPfoNSharedHitsV));
316 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "bestMatchPfoNSharedHitsW", &bestMatchPfoNSharedHitsW));
317 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "bestMatchPfoX0", &bestMatchPfoX0));
318 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "nTargetMatches", nTargetMatches));
319 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "nTargetTBMatches", nTargetTBMatches));
320 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "nTargetCRMatches", nTargetCRMatches));
321 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "bestMatchPfoIsTB", &bestMatchPfoIsTB));
322 }
323
324 if (isBeamParticle || isCosmicRay)
325 {
327#ifdef MONITORING
328 const int interactionTypeInt(static_cast<int>(interactionType));
329#endif
330 // ATTN Some redundancy introduced to contributing variables
331 const int isCorrectTB(isBeamParticle && (nTargetTBMatches == 1) && (nTargetCRMatches == 0));
332 const int isCorrectCR(isCosmicRay && (nTargetTBMatches == 0) && (nTargetCRMatches == 1));
333 const int isFakeTB(isCosmicRay && (nTargetTBMatches > 0));
334 const int isFakeCR(!isCosmicRay && (nTargetCRMatches > 0));
335 const int isSplitTB(!isCosmicRay && (nTargetTBMatches > 1));
336 const int isSplitCR(isCosmicRay && (nTargetCRMatches > 1));
337 const int isLost(nTargetMatches == 0);
338
339 std::stringstream outcomeSS;
340 outcomeSS << LArInteractionTypeHelper::ToString(interactionType) << " (Nuance " << mcNuanceCode << ", TB " << isBeamParticle
341 << ", CR " << isCosmicRay << ")" << std::endl;
342
343 if (isBeamParticle)
344 ++nTotalTB;
345 if (isCosmicRay)
346 ++nTotalCR;
347 if (isCorrectTB)
348 ++nCorrectTB;
349 if (isCorrectCR)
350 ++nCorrectCR;
351 if (isFakeTB)
352 ++nFakeTB;
353 if (isFakeCR)
354 ++nFakeCR;
355 if (isSplitTB)
356 ++nSplitTB;
357 if (isSplitCR)
358 ++nSplitCR;
359 if (isLost)
360 ++nLost;
361
362 if (isCorrectTB)
363 outcomeSS << "IsCorrectTB ";
364 if (isCorrectCR)
365 outcomeSS << "IsCorrectCR ";
366 if (isFakeTB)
367 outcomeSS << "IsFakeTB ";
368 if (isFakeCR)
369 outcomeSS << "IsFakeCR ";
370 if (isSplitTB)
371 outcomeSS << "isSplitTB ";
372 if (isSplitCR)
373 outcomeSS << "IsSplitCR ";
374 if (isLost)
375 outcomeSS << "IsLost ";
376 if (nTargetTBMatches > 0)
377 outcomeSS << "(NTBMatches: " << nTargetTBMatches << ") ";
378 if (nTargetCRMatches > 0)
379 outcomeSS << "(NCRMatches: " << nTargetCRMatches << ") ";
380 if (printToScreen)
381 std::cout << outcomeSS.str() << std::endl << targetSS.str() << std::endl;
382
383 if (fillTree)
384 {
385 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "interactionType", interactionTypeInt));
386 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "isCorrectTB", isCorrectTB));
387 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "isCorrectCR", isCorrectCR));
388 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "isFakeTB", isFakeTB));
389 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "isFakeCR", isFakeCR));
390 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "isSplitTB", isSplitTB));
391 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "isSplitCR", isSplitCR));
392 PANDORA_MONITORING_API(SetTreeVariable(this->GetPandora(), m_treeName.c_str(), "isLost", isLost));
393 PANDORA_MONITORING_API(FillTree(this->GetPandora(), m_treeName.c_str()));
394 }
395
396 targetSS.str(std::string());
397 targetSS.clear();
398 associatedMCPrimaries.clear();
399 nTargetMatches = 0;
400 nTargetTBMatches = 0;
401 nTargetCRMatches = 0;
402 mcPrimaryId.clear();
403 mcPrimaryPdg.clear();
404 nMCHitsTotal.clear();
405 nMCHitsU.clear();
406 nMCHitsV.clear();
407 nMCHitsW.clear();
408 mcPrimaryE.clear();
409 mcPrimaryPX.clear();
410 mcPrimaryPY.clear();
411 mcPrimaryPZ.clear();
412 mcPrimaryVtxX.clear();
413 mcPrimaryVtxY.clear();
414 mcPrimaryVtxZ.clear();
415 mcPrimaryEndX.clear();
416 mcPrimaryEndY.clear();
417 mcPrimaryEndZ.clear();
418 nPrimaryMatchedPfos.clear();
419 nPrimaryMatchedTBPfos.clear();
420 nPrimaryMatchedCRPfos.clear();
421 bestMatchPfoId.clear();
422 bestMatchPfoPdg.clear();
423 bestMatchPfoIsTB.clear();
424 bestMatchPfoNHitsTotal.clear();
425 bestMatchPfoNHitsU.clear();
426 bestMatchPfoNHitsV.clear();
427 bestMatchPfoNHitsW.clear();
428 bestMatchPfoNSharedHitsTotal.clear();
429 bestMatchPfoNSharedHitsU.clear();
430 bestMatchPfoNSharedHitsV.clear();
431 bestMatchPfoNSharedHitsW.clear();
432 bestMatchPfoX0.clear();
433 }
434 }
435
436 if (useInterpretedMatching)
437 {
438 std::stringstream summarySS;
439 summarySS << "---SUMMARY--------------------------------------------------------------------------------------" << std::endl;
440 if (nTotalTB > 0)
441 summarySS << "#CorrectTB: " << nCorrectTB << "/" << nTotalTB
442 << ", Fraction: " << (nTotalTB > 0 ? static_cast<float>(nCorrectTB) / static_cast<float>(nTotalTB) : 0.f) << std::endl;
443 if (nTotalCR > 0)
444 summarySS << "#CorrectCR: " << nCorrectCR << "/" << nTotalCR
445 << ", Fraction: " << (nTotalCR > 0 ? static_cast<float>(nCorrectCR) / static_cast<float>(nTotalCR) : 0.f) << std::endl;
446 if (nFakeTB > 0)
447 summarySS << "#FakeTB: " << nFakeTB << " ";
448 if (nFakeCR > 0)
449 summarySS << "#FakeCR: " << nFakeCR << " ";
450 if (nSplitTB > 0)
451 summarySS << "#SplitTB: " << nSplitTB << " ";
452 if (nSplitCR > 0)
453 summarySS << "#SplitCR: " << nSplitCR << " ";
454 if (nLost > 0)
455 summarySS << "#Lost: " << nLost << " ";
456 if (nFakeTB || nFakeCR || nSplitTB || nSplitCR || nLost)
457 summarySS << std::endl;
458 if (printToScreen)
459 std::cout << summarySS.str();
460 }
461
462 if (printToScreen)
463 std::cout << "------------------------------------------------------------------------------------------------" << std::endl
464 << std::endl;
465}
466
467//------------------------------------------------------------------------------------------------------------------------------------------
468
473
474} // namespace lar_content
Grouping of header files for many classes of use in particle flow algorithms.
#define PANDORA_MONITORING_API(command)
Header file for the interaction type helper class.
Header file for the lar monitoring helper helper class.
Header file for the pfo helper class.
Header file for the test beam event validation algorithm.
void SetInterpretedMCToPfoHitSharingMap(const LArMCParticleHelper::MCParticleToPfoHitSharingMap &interpretedMCToPfoHitSharingMap)
Set the interpreted mc to pfo hit sharing map.
void SetAllMCParticleToHitsMap(const LArMCParticleHelper::MCContributionMap &allMCParticleToHitsMap)
Set the all mc particle to hits map.
const LArMCParticleHelper::MCParticleToPfoHitSharingMap & GetMCToPfoHitSharingMap() const
Get the mc to pfo hit sharing map.
const LArMCParticleHelper::MCParticleToPfoHitSharingMap & GetInterpretedMCToPfoHitSharingMap() const
Get the interpreted mc to pfo hit sharing map.
const LArMCParticleHelper::MCContributionMap & GetTargetMCParticleToHitsMap() const
Get the target mc particle to hits map.
const LArMCParticleHelper::MCContributionMap & GetAllMCParticleToHitsMap() const
Get the all mc particle to hits map.
void SetPfoToHitsMap(const LArMCParticleHelper::PfoContributionMap &pfoToHitsMap)
Set the pfo to hits map.
void SetTargetMCParticleToHitsMap(const LArMCParticleHelper::MCContributionMap &targetMCParticleToHitsMap)
Set the target mc particle to hits map.
const LArMCParticleHelper::PfoContributionMap & GetPfoToHitsMap() const
Get the pfo to hits map.
void SetMCToPfoHitSharingMap(const LArMCParticleHelper::MCParticleToPfoHitSharingMap &mcToPfoHitSharingMap)
Set the mc to pfo hit sharing map.
void InterpretMatching(const ValidationInfo &validationInfo, LArMCParticleHelper::MCParticleToPfoHitSharingMap &interpretedMCToPfoHitSharingMap) const
Apply an interpretative matching procedure to the comprehensive matches in the provided validation in...
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Read the algorithm settings.
LArMCParticleHelper::PrimaryParameters m_primaryParameters
The mc particle primary selection parameters.
bool IsGoodMatch(const pandora::CaloHitList &trueHits, const pandora::CaloHitList &recoHits, const pandora::CaloHitList &sharedHits) const
Whether a provided mc primary and pfo are deemed to be a good match.
static InteractionType GetInteractionType(const pandora::MCParticleList &mcPrimaryList)
Get the interaction type of an event.
static std::string ToString(const InteractionType interactionType)
Get a string representation of an interaction type.
bool m_foldBackHierarchy
whether to fold the hierarchy back to the primary (neutrino) or leading particles (test beam)
float m_minHitSharingFraction
the minimum Hit sharing fraction
unsigned int m_minPrimaryGoodHits
the minimum number of primary good Hits
unsigned int m_minHitsForGoodView
the minimum number of Hits for a good view
static bool IsCosmicRay(const pandora::MCParticle *const pMCParticle)
Return true if passed a primary cosmic ray MCParticle.
std::map< const pandora::ParticleFlowObject *, MCParticleToSharedHitsVector > PfoToMCParticleHitSharingMap
static void GetPfoMCParticleHitSharingMaps(const PfoContributionMap &pfoToReconstructable2DHitsMap, const MCContributionMapVector &selectedMCParticleToHitsMaps, PfoToMCParticleHitSharingMap &pfoToMCParticleHitSharingMap, MCParticleToPfoHitSharingMap &mcParticleToPfoHitSharingMap)
Get the mappings from Pfo -> pair (reconstructable MCparticles, number of reconstructable 2D hits sha...
static bool IsBeamParticle(const pandora::MCParticle *const pMCParticle)
Returns true if passed a primary beam MCParticle.
std::unordered_map< const pandora::ParticleFlowObject *, pandora::CaloHitList > PfoContributionMap
static void SelectReconstructableMCParticles(const pandora::MCParticleList *pMCParticleList, const pandora::CaloHitList *pCaloHitList, const PrimaryParameters &parameters, std::function< bool(const pandora::MCParticle *const)> fCriteria, MCContributionMap &selectedMCParticlesToHitsMap)
Select target, reconstructable mc particles that match given criteria.
std::unordered_map< const pandora::MCParticle *, pandora::CaloHitList > MCContributionMap
static unsigned int GetNuanceCode(const pandora::MCParticle *const pMCParticle)
Get the nuance code of an MCParticle.
static const pandora::MCParticle * GetParentMCParticle(const pandora::MCParticle *const pMCParticle)
Get the parent mc particle.
std::pair< const pandora::ParticleFlowObject *, pandora::CaloHitList > PfoCaloHitListPair
static void GetPfoToReconstructable2DHitsMap(const pandora::PfoList &pfoList, const MCContributionMap &selectedMCParticleToHitsMap, PfoContributionMap &pfoToReconstructable2DHitsMap, const bool foldBackHierarchy)
Get mapping from Pfo to reconstructable 2D hits (=good hits belonging to a selected reconstructable M...
std::unordered_map< const pandora::MCParticle *, int > MCParticleIntMap
std::map< const pandora::MCParticle *, PfoToSharedHitsVector > MCParticleToPfoHitSharingMap
static unsigned int CountHitsByType(const pandora::HitType hitType, const pandora::CaloHitList &caloHitList)
Count the number of calo hits, in a provided list, of a specified type.
static void GetOrderedMCParticleVector(const LArMCParticleHelper::MCContributionMapVector &selectedMCParticleToGoodHitsMaps, pandora::MCParticleVector &orderedMCParticleVector)
Order input MCParticles by their number of hits.
static void GetOrderedPfoVector(const LArMCParticleHelper::PfoContributionMap &pfoToReconstructable2DHitsMap, pandora::PfoVector &orderedPfoVector)
Order input Pfos by their number of hits.
static void GetAllConnectedPfos(const pandora::PfoList &inputPfoList, pandora::PfoList &outputPfoList)
Get a flat list of all pfos, recursively including all daughters and parents associated with those pf...
static bool IsTestBeam(const pandora::ParticleFlowObject *const pPfo)
Whether a pfo is a test beam particle.
static const pandora::ParticleFlowObject * GetParentPfo(const pandora::ParticleFlowObject *const pPfo)
Get the primary parent pfo.
static const pandora::Vertex * GetTestBeamInteractionVertex(const pandora::ParticleFlowObject *const pPfo)
Get the pfo test beam interaction vertex.
static bool IsTestBeamFinalState(const pandora::ParticleFlowObject *const pPfo)
Whether a pfo is a final-state particle from a test beam particle interaction.
static const pandora::Vertex * GetVertex(const pandora::ParticleFlowObject *const pPfo)
Get the pfo vertex.
void ProcessOutput(const ValidationInfo &validationInfo, const bool useInterpretedMatching, const bool printToScreen, const bool fillTree) const
Print matching information in a provided validation info object, and write information to tree if con...
std::unordered_map< const pandora::ParticleFlowObject *, unsigned int > PfoToIdMap
void FillValidationInfo(const pandora::MCParticleList *const pMCParticleList, const pandora::CaloHitList *const pCaloHitList, const pandora::PfoList *const pPfoList, ValidationInfo &validationInfo) const
Fill the validation info containers.
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
Read the algorithm settings.
CartesianVector class.
float GetX() const
Get the cartesian x coordinate.
float GetZ() const
Get the cartesian z coordinate.
float GetY() const
Get the cartesian y coordinate.
MCParticle class.
Definition MCParticle.h:26
ParticleFlowObject class.
const Pandora & GetPandora() const
Get the associated pandora instance.
Definition Process.h:116
StatusCodeException class.
Vertex class.
Definition Vertex.h:26
const CartesianVector & GetPosition() const
Get the vertex position.
Definition Vertex.h:103
MANAGED_CONTAINER< const MCParticle * > MCParticleList
std::vector< const ParticleFlowObject * > PfoVector
std::vector< int > IntVector
MANAGED_CONTAINER< const CaloHit * > CaloHitList
std::vector< float > FloatVector
std::vector< const MCParticle * > MCParticleVector
StatusCode
The StatusCode enum.
MANAGED_CONTAINER< const ParticleFlowObject * > PfoList