Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Attributes | List of all members
gar::gar_pandora::MCParticleCreator Class Reference

#include <MCParticleCreator.h>

Classes

class  eveLoc
 
class  Settings
 

Public Member Functions

 MCParticleCreator (const Settings &settings, const pandora::Pandora *const pPandora, const RotationTransformation *const pRotation)
 
 ~MCParticleCreator ()
 
pandora::StatusCode CreateMCParticles (const art::Event &pEvent)
 
pandora::StatusCode CreateMCParticles () const
 
pandora::StatusCode CreateTrackToMCParticleRelationships (const TrackVector &trackVector) const
 
pandora::StatusCode CreateCaloHitToMCParticleRelationships (const CalorimeterHitVector &calorimeterHitVector) const
 
void Reset ()
 

Static Public Member Functions

static const simb::MCParticleGetFinalStateMCParticle (const MCParticleMap &particleMap, const simb::MCParticle *inputParticle)
 
static bool IsVisible (const art::Ptr< simb::MCParticle > particle)
 

Protected Member Functions

pandora::StatusCode CollectMCParticles (const art::Event &pEvent, const std::string &label, MCParticleVector &particleVector)
 
pandora::StatusCode CollectGeneratorMCParticles (const art::Event &pEvent, const std::string &label, RawMCParticleVector &particleVector)
 
pandora::StatusCode CollectMCParticles (const art::Event &pEvent, const std::string &label, MCTruthToMCParticles &truthToParticles, MCParticlesToMCTruth &particlesToTruth)
 

Private Attributes

const Settings m_settings
 The mc particle creator settings. More...
 
const pandora::Pandora & m_pandora
 Reference to the pandora object to create the mc particles. More...
 
float m_bField
 The bfield. More...
 
const RotationTransformationm_rotation
 
const geo::GeometryCorefGeo
 
float m_origin [3] = {0, 0, 0}
 
MCParticleVector artMCParticleVector
 
RawMCParticleVector generatorArtMCParticleVector
 
MCTruthToMCParticles artMCTruthToMCParticles
 
MCParticlesToMCTruth artMCParticlesToMCTruth
 

Detailed Description

Definition at line 29 of file MCParticleCreator.h.

Constructor & Destructor Documentation

gar::gar_pandora::MCParticleCreator::MCParticleCreator ( const Settings settings,
const pandora::Pandora *const  pPandora,
const RotationTransformation *const  pRotation 
)

Definition at line 23 of file MCParticleCreator.cxx.

24  : m_settings(settings),
25  m_pandora(*pPandora),
26  m_rotation(*pRotation)
27  {
28  fGeo = gar::providerFrom<geo::GeometryGAr>();
29  auto const *magFieldService = gar::providerFrom<mag::MagneticFieldService>();
30  G4ThreeVector zerovec(0, 0, 0);
31  G4ThreeVector magfield = magFieldService->FieldAtPoint(zerovec);
32  m_bField = magfield[0]; //x component at (0, 0, 0)
33  m_origin[0] = fGeo->GetOriginX();
34  m_origin[1] = fGeo->GetOriginY();
35  m_origin[2] = fGeo->GetOriginZ();
36  }
const RotationTransformation & m_rotation
float GetOriginX() const
Definition: GeometryCore.h:548
const pandora::Pandora & m_pandora
Reference to the pandora object to create the mc particles.
const geo::GeometryCore * fGeo
float GetOriginZ() const
Definition: GeometryCore.h:552
float GetOriginY() const
Definition: GeometryCore.h:550
const Settings m_settings
The mc particle creator settings.
gar::gar_pandora::MCParticleCreator::~MCParticleCreator ( )

Definition at line 40 of file MCParticleCreator.cxx.

41  {
42  }

Member Function Documentation

pandora::StatusCode gar::gar_pandora::MCParticleCreator::CollectGeneratorMCParticles ( const art::Event pEvent,
const std::string label,
RawMCParticleVector particleVector 
)
protected

Definition at line 367 of file MCParticleCreator.cxx.

368  {
369  auto mcTruthBlocks = pEvent.getHandle< std::vector<simb::MCTruth> >(label);
370  if (!mcTruthBlocks)
371  {
372  MF_LOG_WARNING("MCParticleCreator") << " Failed to find MC Truth for generator " << label << std::endl;
373  return pandora::STATUS_CODE_NOT_FOUND;
374  }
375 
376  MF_LOG_DEBUG("MCParticleCreator") << " Found: " << mcTruthBlocks->size() << " MC truth blocks " << std::endl;
377 
378  if (mcTruthBlocks->size() != 1)
379  throw cet::exception("MCParticleCreator") << " PandoraCollector::CollectGeneratorMCParticles --- Unexpected number of MC truth blocks ";
380 
381  const art::Ptr<simb::MCTruth> mcTruth(mcTruthBlocks, 0);
382  for (int i = 0; i < mcTruth->NParticles(); ++i)
383  {
384  particleVector.push_back(mcTruth->GetParticle(i));
385  }
386 
387  return pandora::STATUS_CODE_SUCCESS;
388  }
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
#define MF_LOG_DEBUG(id)
#define MF_LOG_WARNING(category)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
pandora::StatusCode gar::gar_pandora::MCParticleCreator::CollectMCParticles ( const art::Event pEvent,
const std::string label,
MCParticleVector particleVector 
)
protected

Definition at line 345 of file MCParticleCreator.cxx.

346  {
347  auto theParticles = pEvent.getHandle< RawMCParticleVector >(label);
348  if (!theParticles)
349  {
350  MF_LOG_WARNING("MCParticleCreator") << " Failed to find MC particles for label " << label << std::endl;
351  return pandora::STATUS_CODE_NOT_FOUND;
352  }
353 
354  MF_LOG_DEBUG("MCParticleCreator") << " Found: " << theParticles->size() << " MC particles " << std::endl;
355 
356  for (unsigned int i = 0; i < theParticles->size(); ++i)
357  {
358  const art::Ptr<simb::MCParticle> particle(theParticles, i);
359  particleVector.push_back(particle);
360  }
361 
362  return pandora::STATUS_CODE_SUCCESS;
363  }
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
std::vector< simb::MCParticle > RawMCParticleVector
#define MF_LOG_DEBUG(id)
#define MF_LOG_WARNING(category)
QTextStream & endl(QTextStream &s)
pandora::StatusCode gar::gar_pandora::MCParticleCreator::CollectMCParticles ( const art::Event pEvent,
const std::string label,
MCTruthToMCParticles truthToParticles,
MCParticlesToMCTruth particlesToTruth 
)
protected

Definition at line 392 of file MCParticleCreator.cxx.

393  {
394  auto theParticles = pEvent.getHandle< RawMCParticleVector >(label);
395  if (!theParticles)
396  {
397  MF_LOG_WARNING("MCParticleCreator") << " Failed to find MC particles for label " << label << std::endl;
398  return pandora::STATUS_CODE_NOT_FOUND;
399  }
400 
401  MF_LOG_DEBUG("MCParticleCreator") << " Found: " << theParticles->size() << " MC particles " << std::endl;
402 
403  art::FindOneP<simb::MCTruth> theTruthAssns(theParticles, pEvent, label);
404 
405  for (unsigned int i = 0, iEnd = theParticles->size(); i < iEnd; ++i)
406  {
407  const art::Ptr<simb::MCParticle> particle(theParticles, i);
408  const art::Ptr<simb::MCTruth> truth(theTruthAssns.at(i));
409  truthToParticles[truth].push_back(particle);
410  particlesToTruth[particle] = truth;
411  }
412 
413  return pandora::STATUS_CODE_SUCCESS;
414  }
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
std::vector< simb::MCParticle > RawMCParticleVector
#define MF_LOG_DEBUG(id)
#define MF_LOG_WARNING(category)
QTextStream & endl(QTextStream &s)
pandora::StatusCode gar::gar_pandora::MCParticleCreator::CreateCaloHitToMCParticleRelationships ( const CalorimeterHitVector calorimeterHitVector) const

Definition at line 263 of file MCParticleCreator.cxx.

264  {
265  cheat::BackTrackerCore const* bt = gar::providerFrom<cheat::BackTracker>();
266  std::map< eveLoc, std::vector< art::Ptr<gar::rec::CaloHit> > > eveCaloHitMap;
267 
268  MCParticleMap particleMap;
269  for (MCParticlesToMCTruth::const_iterator iter = artMCParticlesToMCTruth.begin(), iterEnd = artMCParticlesToMCTruth.end(); iter != iterEnd; ++iter)
270  {
271  const art::Ptr<simb::MCParticle> particle = iter->first;
272  particleMap[particle->TrackId()] = particle;
273  }
274 
275  // loop over all hits and fill in the map
276  for( auto const& itr : calorimeterHitVector )
277  {
278  std::vector<gar::cheat::CalIDE> eveides = bt->CaloHitToCalIDEs(itr);
279 
280  // loop over all eveides for this hit
281  for(size_t ieve = 0; ieve < eveides.size(); ieve++) {
282  MF_LOG_DEBUG("MCParticleCreator::CreateCaloHitToMCParticleRelationships")
283  << " Found eveID " << eveides[ieve].trackID
284  << " associated to art hit " << itr;
285 
286  if(eveides[ieve].energyFrac < 0.1) continue;
287 
288  eveLoc el(eveides[ieve].trackID);
289  eveCaloHitMap[el].push_back(itr);
290  } // end loop over eve IDs for this hit
291  }// end loop over hits
292 
293  for(auto const &hitMapItr : eveCaloHitMap)
294  {
295  MF_LOG_DEBUG("MCParticleCreator::CreateCaloHitToMCParticleRelationships")
296  << " Trying to find mcp associated to eveID " << hitMapItr.first.GetEveID();
297 
298  const simb::MCParticle *part = bt->TrackIDToParticle(hitMapItr.first.GetEveID());
299 
300  if( nullptr == part ) {
301  MF_LOG_WARNING("MCParticleCreator::CreateCaloHitToMCParticleRelationships")
302  << "Cannot find MCParticle for eveid: " << hitMapItr.first.GetEveID();
303  continue;
304  }
305 
306  // const int eveID = hitMapItr.first.GetEveID();
307  const int trackID = part->TrackId();
308  // const float partE = part->E();
309 
310  for (MCParticleMap::const_iterator iterI = particleMap.begin(), iterEndI = particleMap.end(); iterI != iterEndI; ++iterI)
311  {
312  simb::MCParticle *pMCParticleCalo = const_cast<simb::MCParticle*>(iterI->second.get());
313 
314  if (nullptr == pMCParticleCalo)
315  continue;
316  if (trackID != pMCParticleCalo->TrackId())
317  continue;
318 
319  //Need to get the original monte carlo particle that created this one (mother <- daughters)
320  const simb::MCParticle *pMCPrimary = MCParticleCreator::GetFinalStateMCParticle(particleMap, pMCParticleCalo);
321  if (nullptr == pMCPrimary)
322  continue;
323 
324  for(auto const& itr : hitMapItr.second)
325  {
326  const gar::rec::CaloHit *hit = itr.get();
327  try
328  {
329  PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, PandoraApi::SetCaloHitToMCParticleRelationship(m_pandora, hit, pMCPrimary, hit->Energy()));
330  }
331  catch (const pandora::StatusCodeException &)
332  {
333  MF_LOG_WARNING("MCParticleCreator") << "CreateCaloHitToMCParticleRelationships - unable to create calo hit to mc particle relationship, invalid information supplied " << std::endl;
334  continue;
335  }
336  }
337  }
338  }
339 
340  return pandora::STATUS_CODE_SUCCESS;
341  }
const pandora::Pandora & m_pandora
Reference to the pandora object to create the mc particles.
static const simb::MCParticle * GetFinalStateMCParticle(const MCParticleMap &particleMap, const simb::MCParticle *inputParticle)
intermediate_table::const_iterator const_iterator
int TrackId() const
Definition: MCParticle.h:210
bt
Definition: tracks.py:83
MCParticlesToMCTruth artMCParticlesToMCTruth
float Energy() const
Definition: CaloHit.h:69
std::map< int, art::Ptr< simb::MCParticle > > MCParticleMap
Detector simulation of raw signals on wires.
#define MF_LOG_DEBUG(id)
#define MF_LOG_WARNING(category)
QTextStream & endl(QTextStream &s)
pandora::StatusCode gar::gar_pandora::MCParticleCreator::CreateMCParticles ( const art::Event pEvent)

Definition at line 46 of file MCParticleCreator.cxx.

47  {
48  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, this->CollectMCParticles(pEvent, m_settings.m_geantModuleLabel, artMCParticleVector));
50  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, this->CollectGeneratorMCParticles(pEvent, m_settings.m_generatorModuleLabel, generatorArtMCParticleVector));
51  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, this->CollectMCParticles(pEvent, m_settings.m_geantModuleLabel, artMCTruthToMCParticles, artMCParticlesToMCTruth));
52  PANDORA_RETURN_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, this->CreateMCParticles());
53 
54  return pandora::STATUS_CODE_SUCCESS;
55  }
std::string m_geantModuleLabel
The geant4 label.
pandora::StatusCode CollectMCParticles(const art::Event &pEvent, const std::string &label, MCParticleVector &particleVector)
std::string m_generatorModuleLabel
The generator label.
MCTruthToMCParticles artMCTruthToMCParticles
MCParticlesToMCTruth artMCParticlesToMCTruth
pandora::StatusCode CollectGeneratorMCParticles(const art::Event &pEvent, const std::string &label, RawMCParticleVector &particleVector)
RawMCParticleVector generatorArtMCParticleVector
pandora::StatusCode CreateMCParticles() const
const Settings m_settings
The mc particle creator settings.
pandora::StatusCode gar::gar_pandora::MCParticleCreator::CreateMCParticles ( ) const

Definition at line 59 of file MCParticleCreator.cxx.

60  {
61  MCParticleMap particleMap;
62  for (MCParticlesToMCTruth::const_iterator iter = artMCParticlesToMCTruth.begin(), iterEnd = artMCParticlesToMCTruth.end(); iter != iterEnd; ++iter)
63  {
64  const art::Ptr<simb::MCParticle> particle = iter->first;
65  particleMap[particle->TrackId()] = particle;
66  }
67 
68  int neutrinoCounter(0);
69  for (MCTruthToMCParticles::const_iterator iter1 = artMCTruthToMCParticles.begin(), iterEnd1 = artMCTruthToMCParticles.end(); iter1 != iterEnd1; ++iter1)
70  {
71  const art::Ptr<simb::MCTruth> truth = iter1->first;
72  if (truth->NeutrinoSet())
73  {
74  const simb::MCNeutrino neutrino(truth->GetNeutrino());
75  ++neutrinoCounter;
76 
77  const pandora::CartesianVector momentum(neutrino.Nu().Px(), neutrino.Nu().Py(), neutrino.Nu().Pz());
78  const pandora::CartesianVector vertex( (neutrino.Nu().Vx() - m_origin[0]) * CLHEP::cm, (neutrino.Nu().Vy() - m_origin[1]) * CLHEP::cm, (neutrino.Nu().Vz() - m_origin[2]) * CLHEP::cm);
79  const pandora::CartesianVector endpoint( (neutrino.Nu().EndX() - m_origin[0]) * CLHEP::cm, (neutrino.Nu().EndY() - m_origin[1]) * CLHEP::cm, (neutrino.Nu().EndZ() - m_origin[2]) * CLHEP::cm);
80 
81  const pandora::CartesianVector newmomentum = m_rotation.MakeRotation(momentum);
82  const pandora::CartesianVector newvertex = m_rotation.MakeRotation(vertex);
83  const pandora::CartesianVector newendpoint = m_rotation.MakeRotation(endpoint);
84 
85  PandoraApi::MCParticle::Parameters mcParticleParameters;
86  mcParticleParameters.m_energy = neutrino.Nu().E();
87  mcParticleParameters.m_momentum = newmomentum;
88  mcParticleParameters.m_vertex = newvertex;
89  mcParticleParameters.m_endpoint = newendpoint;
90  mcParticleParameters.m_particleId = neutrino.Nu().PdgCode();
91  mcParticleParameters.m_mcParticleType = pandora::MC_3D;
92  mcParticleParameters.m_pParentAddress = &neutrino;
93 
94  PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, PandoraApi::MCParticle::Create(m_pandora, mcParticleParameters));
95 
96  // Loop over associated particles
97  const MCParticleVector &particleVector = iter1->second;
98  for (MCParticleVector::const_iterator iter2 = particleVector.begin(), iterEnd2 = particleVector.end(); iter2 != iterEnd2; ++iter2)
99  {
100  const art::Ptr<simb::MCParticle> particle = *iter2;
101  // Mother/Daughter Links
102  if (particle->Mother() == 0)
103  {
104  try
105  {
106  PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, PandoraApi::SetMCParentDaughterRelationship(m_pandora, &neutrino, particle.get()));
107  }
108  catch (const pandora::StatusCodeException &)
109  {
110  MF_LOG_WARNING("MCParticleCreator") << "CreatePandoraMCParticles - unable to create mc particle relationship, invalid information supplied " << std::endl;
111  continue;
112  }
113  }
114  }
115  }
116  }
117 
118  MF_LOG_DEBUG("MCParticleCreator") << " Number of Pandora neutrinos: " << neutrinoCounter << std::endl;
119 
120  for (MCParticleMap::const_iterator iterI = particleMap.begin(), iterEndI = particleMap.end(); iterI != iterEndI; ++iterI)
121  {
122  const art::Ptr<simb::MCParticle> pMcParticle = iterI->second;
123 
124  // Lookup position and kinematics at start and end points
125  const pandora::CartesianVector momentum(pMcParticle->Px(), pMcParticle->Py(), pMcParticle->Pz());
126  const pandora::CartesianVector vertex( (pMcParticle->Vx() - m_origin[0]) * CLHEP::cm, (pMcParticle->Vy() - m_origin[1]) * CLHEP::cm, (pMcParticle->Vz() - m_origin[2]) * CLHEP::cm);
127  const pandora::CartesianVector endpoint( (pMcParticle->EndX() - m_origin[0]) * CLHEP::cm, (pMcParticle->EndY() - m_origin[1]) * CLHEP::cm, (pMcParticle->EndZ() - m_origin[2]) * CLHEP::cm);
128 
129  const pandora::CartesianVector newmomentum = m_rotation.MakeRotation(momentum);
130  const pandora::CartesianVector newvertex = m_rotation.MakeRotation(vertex);
131  const pandora::CartesianVector newendpoint = m_rotation.MakeRotation(endpoint);
132 
133  PandoraApi::MCParticle::Parameters mcParticleParameters;
134  mcParticleParameters.m_energy = pMcParticle->E();
135  mcParticleParameters.m_particleId = pMcParticle->PdgCode();
136  mcParticleParameters.m_mcParticleType = pandora::MC_3D;
137  mcParticleParameters.m_pParentAddress = pMcParticle.get();
138  mcParticleParameters.m_momentum = newmomentum;
139  mcParticleParameters.m_vertex = newvertex;
140  mcParticleParameters.m_endpoint = newendpoint;
141 
142  MF_LOG_DEBUG("MCParticleCreator") << " Adding MC Particle with parameters "
143  << " mcParticleParameters.m_energy = " << mcParticleParameters.m_energy.Get()
144  << " mcParticleParameters.m_particleId = " << mcParticleParameters.m_particleId.Get()
145  << " mcParticleParameters.m_mcParticleType = " << mcParticleParameters.m_mcParticleType.Get()
146  << " mcParticleParameters.m_pParentAddress = " << mcParticleParameters.m_pParentAddress.Get()
147  << " mcParticleParameters.m_momentum = " << mcParticleParameters.m_momentum.Get()
148  << " mcParticleParameters.m_vertex = " << mcParticleParameters.m_vertex.Get()
149  << " mcParticleParameters.m_endpoint = " << mcParticleParameters.m_endpoint.Get();
150 
151  try
152  {
153  MF_LOG_DEBUG("MCParticleCreator::CreateMCParticles")
154  << " Creating mc particle " << pMcParticle.get()
155  << " of pdg " << pMcParticle->PdgCode()
156  << " with TrackID " << pMcParticle->TrackId()
157  << " and energy " << pMcParticle->E() << " GeV";
158 
159  PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, PandoraApi::MCParticle::Create(m_pandora, mcParticleParameters));
160 
161  // Create parent-daughter relationships
162  const int id_mother(pMcParticle->Mother());
163  MCParticleMap::const_iterator iterJ = particleMap.find(id_mother);
164  if (iterJ != particleMap.end())
165  {
166  try
167  {
168  MF_LOG_DEBUG("MCParticleCreator::CreateMCParticles")
169  << " Adding daughter relation " << iterJ->second.get()
170  << " to mc particle " << pMcParticle.get();
171 
172  PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, PandoraApi::SetMCParentDaughterRelationship(m_pandora, iterJ->second.get(), pMcParticle.get()));
173  }
174  catch (const pandora::StatusCodeException &)
175  {
176  MF_LOG_WARNING("MCParticleCreator") << "CreatePandoraMCParticles - Unable to create mc particle relationship, invalid information supplied " << std::endl;
177  continue;
178  }
179  }
180  }
181  catch (const pandora::StatusCodeException &)
182  {
183  MF_LOG_WARNING("MCParticleCreator") << "CreatePandoraMCParticles - Unable to create MCParticle " << std::endl;
184  continue;
185  }
186  }
187 
188  return pandora::STATUS_CODE_SUCCESS;
189  }
static constexpr double cm
Definition: Units.h:68
double E(const int i=0) const
Definition: MCParticle.h:233
int PdgCode() const
Definition: MCParticle.h:212
const simb::MCNeutrino & GetNeutrino() const
Definition: MCTruth.h:77
double Py(const int i=0) const
Definition: MCParticle.h:231
const RotationTransformation & m_rotation
double EndZ() const
Definition: MCParticle.h:228
int Mother() const
Definition: MCParticle.h:213
double Px(const int i=0) const
Definition: MCParticle.h:230
const pandora::Pandora & m_pandora
Reference to the pandora object to create the mc particles.
intermediate_table::const_iterator const_iterator
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
double EndY() const
Definition: MCParticle.h:227
MCTruthToMCParticles artMCTruthToMCParticles
int TrackId() const
Definition: MCParticle.h:210
MCParticlesToMCTruth artMCParticlesToMCTruth
std::map< int, art::Ptr< simb::MCParticle > > MCParticleMap
const pandora::CartesianVector MakeRotation(const pandora::CartesianVector &initialVec) const
double Vx(const int i=0) const
Definition: MCParticle.h:221
#define MF_LOG_DEBUG(id)
double Pz(const int i=0) const
Definition: MCParticle.h:232
double Vz(const int i=0) const
Definition: MCParticle.h:223
bool NeutrinoSet() const
Definition: MCTruth.h:78
#define MF_LOG_WARNING(category)
def momentum(x1, x2, x3, scale=1.)
double EndX() const
Definition: MCParticle.h:226
T const * get() const
Definition: Ptr.h:149
Event generator information.
Definition: MCNeutrino.h:18
double Vy(const int i=0) const
Definition: MCParticle.h:222
QTextStream & endl(QTextStream &s)
vertex reconstruction
pandora::StatusCode gar::gar_pandora::MCParticleCreator::CreateTrackToMCParticleRelationships ( const TrackVector trackVector) const

Definition at line 193 of file MCParticleCreator.cxx.

194  {
195  MCParticleMap particleMap;
196  for (MCParticlesToMCTruth::const_iterator iter = artMCParticlesToMCTruth.begin(), iterEnd = artMCParticlesToMCTruth.end(); iter != iterEnd; ++iter)
197  {
198  const art::Ptr<simb::MCParticle> particle = iter->first;
199  particleMap[particle->TrackId()] = particle;
200  }
201 
202  for( auto const& itr : trackVector )
203  {
204  try
205  {
206  const gar::rec::Track *pTrack = itr.get();
207 
208  const float *trackParams = pTrack->TrackParEnd(); //y, z, omega, phi, lambda
209  const float omega = trackParams[2] / CLHEP::cm;
210  const float d0 = std::sqrt(trackParams[0]*trackParams[0] + trackParams[1]*trackParams[1]) * CLHEP::cm;
211  const float z0 = pTrack->End()[0] * CLHEP::cm;
212 
213  const pandora::Helix helixFit(trackParams[3], d0, z0, omega, std::tan(trackParams[4]), m_bField);
214  const float recoMomentum(helixFit.GetMomentum().GetMagnitude());
215 
216  // Use momentum magnitude to identify best mc particle
217  simb::MCParticle *pBestMCParticle = nullptr;
218  float bestDeltaMomentum(std::numeric_limits<float>::max());
219 
220  //Loop over the MCParticles
221  for (MCParticleMap::const_iterator iterI = particleMap.begin(), iterEndI = particleMap.end(); iterI != iterEndI; ++iterI)
222  {
223  simb::MCParticle *pMCParticle = const_cast<simb::MCParticle*>(iterI->second.get());
224 
225  if (nullptr == pMCParticle)
226  continue;
227 
228  const pandora::CartesianVector momentum(pMCParticle->Px(), pMCParticle->Py(), pMCParticle->Pz());
229  const pandora::CartesianVector newmomentum = m_rotation.MakeRotation(momentum);
230  const float trueMomentum(newmomentum.GetMagnitude());
231 
232  const float deltaMomentum(std::fabs(recoMomentum - trueMomentum));
233 
234  if (deltaMomentum < bestDeltaMomentum)
235  {
236  pBestMCParticle = pMCParticle;
237  bestDeltaMomentum = deltaMomentum;
238  }
239  }
240 
241  if (nullptr == pBestMCParticle)
242  continue;
243 
244  MF_LOG_DEBUG("MCParticleCreator::CreateTrackToMCParticleRelationships")
245  << "Found MCParticle " << pBestMCParticle
246  << " associated to track " << pTrack
247  << " with best delta momentum " << bestDeltaMomentum;
248 
249  PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, PandoraApi::SetTrackToMCParticleRelationship(m_pandora, pTrack, pBestMCParticle));
250  }
251  catch (pandora::StatusCodeException &statusCodeException)
252  {
253  MF_LOG_ERROR("MCParticleCreator::CreateTrackToMCParticleRelationships")
254  << "Failed to extract track to mc particle relationship: " << statusCodeException.ToString();
255  }
256  }
257 
258  return pandora::STATUS_CODE_SUCCESS;
259  }
static constexpr double cm
Definition: Units.h:68
double Py(const int i=0) const
Definition: MCParticle.h:231
const RotationTransformation & m_rotation
double Px(const int i=0) const
Definition: MCParticle.h:230
const pandora::Pandora & m_pandora
Reference to the pandora object to create the mc particles.
#define MF_LOG_ERROR(category)
intermediate_table::const_iterator const_iterator
int TrackId() const
Definition: MCParticle.h:210
MCParticlesToMCTruth artMCParticlesToMCTruth
const float * TrackParEnd() const
Definition: Track.h:152
static int max(int a, int b)
const float * End() const
Definition: Track.h:140
std::map< int, art::Ptr< simb::MCParticle > > MCParticleMap
const pandora::CartesianVector MakeRotation(const pandora::CartesianVector &initialVec) const
#define MF_LOG_DEBUG(id)
double Pz(const int i=0) const
Definition: MCParticle.h:232
def momentum(x1, x2, x3, scale=1.)
const simb::MCParticle * gar::gar_pandora::MCParticleCreator::GetFinalStateMCParticle ( const MCParticleMap particleMap,
const simb::MCParticle inputParticle 
)
static

Definition at line 418 of file MCParticleCreator.cxx.

419  {
420  // Navigate upward through MC daughter/parent links - collect this particle and all its parents
421  MCParticleVector mcVector;
422 
423  int trackID(inputParticle->TrackId());
424 
425  while(1)
426  {
427  MCParticleMap::const_iterator pIter = particleMap.find(trackID);
428  if (particleMap.end() == pIter)
429  break; // Can't find MC Particle for this track ID [break]
430 
431  const art::Ptr<simb::MCParticle> particle = pIter->second;
432  mcVector.push_back(particle);
433 
434  trackID = particle->Mother();
435  }
436 
437  // Navigate downward through MC parent/daughter links - return the first long-lived charged particle
438  for (MCParticleVector::const_reverse_iterator iter = mcVector.rbegin(), iterEnd = mcVector.rend(); iter != iterEnd; ++iter)
439  {
440  const art::Ptr<simb::MCParticle> nextParticle = *iter;
441 
442  if (MCParticleCreator::IsVisible(nextParticle))
443  return nextParticle.get();
444  }
445 
446  throw cet::exception("LArPandora"); // need to catch this exception
447  }
int Mother() const
Definition: MCParticle.h:213
intermediate_table::const_iterator const_iterator
std::vector< art::Ptr< simb::MCParticle > > MCParticleVector
int TrackId() const
Definition: MCParticle.h:210
T const * get() const
Definition: Ptr.h:149
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
static bool IsVisible(const art::Ptr< simb::MCParticle > particle)
bool gar::gar_pandora::MCParticleCreator::IsVisible ( const art::Ptr< simb::MCParticle particle)
static

Definition at line 451 of file MCParticleCreator.cxx.

452  {
453  // Include long-lived charged particles
454  const int pdg(particle->PdgCode());
455 
456  if ((pandora::E_MINUS == std::abs(pdg)) || (pandora::MU_MINUS == std::abs(pdg)) || (pandora::PROTON == std::abs(pdg)) ||
457  (pandora::PI_PLUS == std::abs(pdg)) || (pandora::K_PLUS == std::abs(pdg)) ||
458  (pandora::SIGMA_MINUS == std::abs(pdg)) || (pandora::SIGMA_PLUS == std::abs(pdg)) || (pandora::HYPERON_MINUS == std::abs(pdg)) ||
459  (pandora::PHOTON == std::abs(pdg)) || (pandora::NEUTRON == std::abs(pdg)))
460  return true;
461 
462  // TODO: What about ions, neutrons, photons? (Have included neutrons and photons for now)
463 
464  return false;
465  }
int PdgCode() const
Definition: MCParticle.h:212
T abs(T value)
void gar::gar_pandora::MCParticleCreator::Reset ( )
inline

Definition at line 97 of file MCParticleCreator.h.

98  {
99  artMCParticleVector.clear();
101  artMCTruthToMCParticles.clear();
102  artMCParticlesToMCTruth.clear();
103  }
MCTruthToMCParticles artMCTruthToMCParticles
MCParticlesToMCTruth artMCParticlesToMCTruth
RawMCParticleVector generatorArtMCParticleVector

Member Data Documentation

MCParticlesToMCTruth gar::gar_pandora::MCParticleCreator::artMCParticlesToMCTruth
private

Definition at line 94 of file MCParticleCreator.h.

MCParticleVector gar::gar_pandora::MCParticleCreator::artMCParticleVector
private

Definition at line 91 of file MCParticleCreator.h.

MCTruthToMCParticles gar::gar_pandora::MCParticleCreator::artMCTruthToMCParticles
private

Definition at line 93 of file MCParticleCreator.h.

const geo::GeometryCore* gar::gar_pandora::MCParticleCreator::fGeo
private

Definition at line 87 of file MCParticleCreator.h.

RawMCParticleVector gar::gar_pandora::MCParticleCreator::generatorArtMCParticleVector
private

Definition at line 92 of file MCParticleCreator.h.

float gar::gar_pandora::MCParticleCreator::m_bField
private

The bfield.

Definition at line 85 of file MCParticleCreator.h.

float gar::gar_pandora::MCParticleCreator::m_origin[3] = {0, 0, 0}
private

Definition at line 89 of file MCParticleCreator.h.

const pandora::Pandora& gar::gar_pandora::MCParticleCreator::m_pandora
private

Reference to the pandora object to create the mc particles.

Definition at line 84 of file MCParticleCreator.h.

const RotationTransformation& gar::gar_pandora::MCParticleCreator::m_rotation
private

Definition at line 86 of file MCParticleCreator.h.

const Settings gar::gar_pandora::MCParticleCreator::m_settings
private

The mc particle creator settings.

Definition at line 83 of file MCParticleCreator.h.


The documentation for this class was generated from the following files: