LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
InteractionSelectionAlgorithm.cc
Go to the documentation of this file.
1 
9 #include "Pandora/AlgorithmHeaders.h"
10 
12 
14 
15 using namespace pandora;
16 
17 namespace lar_content
18 {
19 
20 InteractionSelectionAlgorithm::InteractionSelectionAlgorithm()
21 {
22 }
23 
24 //------------------------------------------------------------------------------------------------------------------------------------------
25 
26 StatusCode InteractionSelectionAlgorithm::Run()
27 {
28  const CaloHitList *pCaloHitList{nullptr};
29  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*this, "CaloHitList2D", pCaloHitList));
30 
31  std::set<const MCParticle *> mcSet;
32  std::map<const MCParticle *, CaloHitList> mcHitMap;
33  for (const CaloHit *pCaloHit : *pCaloHitList)
34  {
35  const MCParticle *pMCParticle{MCParticleHelper::GetMainMCParticle(pCaloHit)};
36  if (!pMCParticle)
37  continue;
38  const MCParticle *pParent{pMCParticle};
39  while (!pParent->GetParentList().empty())
40  pParent = pParent->GetParentList().front();
41  if (LArMCParticleHelper::IsNeutrino(pParent))
42  {
43  mcSet.insert(pParent);
44  mcHitMap[pParent].emplace_back(pCaloHit);
45  }
46  }
47 
48  std::cout << "Num hits: " << pCaloHitList->size() << " Num MC: " << mcSet.size() << std::endl;
49  for (auto &[pParent, caloHits] : mcHitMap)
50  std::cout << "MC: " << pParent << " (" << pParent->GetParticleId() << ") " << caloHits.size() << std::endl;
51 
52  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::RenameList<CaloHitList>(*this, "CaloHitList2D", "InputCaloHitList2D"));
53  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::RenameList<CaloHitList>(*this, "CaloHitListU", "InputCaloHitU"));
54  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::RenameList<CaloHitList>(*this, "CaloHitListV", "InputCaloHitV"));
55  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::RenameList<CaloHitList>(*this, "CaloHitListW", "InputCaloHitW"));
56 
57  int i{0};
58  MCParticleList selectedNeutrinos;
59  CaloHitList caloHitListU, caloHitListV, caloHitListW, caloHitList2D;
60  for (auto &[pParent, caloHits] : mcHitMap)
61  {
62  if (std::find(m_interactionIds.begin(), m_interactionIds.end(), i) != m_interactionIds.end())
63  {
64  selectedNeutrinos.emplace_back(pParent);
65  for (const CaloHit *pCaloHit : caloHits)
66  {
67  switch (pCaloHit->GetHitType())
68  {
69  case TPC_VIEW_U:
70  caloHitListU.emplace_back(pCaloHit);
71  caloHitList2D.emplace_back(pCaloHit);
72  break;
73  case TPC_VIEW_V:
74  caloHitListV.emplace_back(pCaloHit);
75  caloHitList2D.emplace_back(pCaloHit);
76  break;
77  case TPC_VIEW_W:
78  caloHitListW.emplace_back(pCaloHit);
79  caloHitList2D.emplace_back(pCaloHit);
80  break;
81  default:
82  break;
83  }
84  }
85  }
86  std::cout << "MC: " << pParent << " (" << pParent->GetParticleId() << ") " << caloHits.size() << std::endl;
87  ++i;
88  }
89 
90  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList(*this, selectedNeutrinos, "SelectedNeutrinos"));
91  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList(*this, caloHitList2D, "CaloHitList2D"));
92  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList(*this, caloHitListU, "CaloHitListU"));
93  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList(*this, caloHitListV, "CaloHitListV"));
94  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList(*this, caloHitListW, "CaloHitListW"));
95 
96  return STATUS_CODE_SUCCESS;
97 }
98 
99 //------------------------------------------------------------------------------------------------------------------------------------------
100 
101 StatusCode InteractionSelectionAlgorithm::ReadSettings(const TiXmlHandle xmlHandle)
102 {
103  (void)xmlHandle;
104  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadVectorOfValues(xmlHandle, "InteractionIds", m_interactionIds));
105 
106  return STATUS_CODE_SUCCESS;
107 }
108 
109 } // namespace lar_content
Header file for the post processing algorithm class.
Header file for the lar monte carlo particle helper helper class.