LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
t0::DirectHitParticleAssns Class Reference
Inheritance diagram for t0::DirectHitParticleAssns:
t0::IHitParticleAssociations

Classes

struct  TrackIDEinfo
 

Public Member Functions

 DirectHitParticleAssns (fhicl::ParameterSet const &pset)
 Constructor. More...
 
void reconfigure (fhicl::ParameterSet const &pset) override
 
void CreateHitParticleAssociations (art::Event &, HitParticleAssociations *) override
 This rebuilds the internal maps. More...
 

Private Attributes

std::vector< art::InputTagfHitModuleLabelVec
 
art::InputTag fMCParticleModuleLabel
 
std::unordered_map< int, TrackIDEinfofTrkIDECollector
 

Detailed Description

Definition at line 36 of file DirectHitParticleAssns_tool.cc.

Constructor & Destructor Documentation

t0::DirectHitParticleAssns::DirectHitParticleAssns ( fhicl::ParameterSet const &  pset)
explicit

Constructor.

Parameters
psetConstructor.

Arguments:

pset - Fcl parameters.

Definition at line 71 of file DirectHitParticleAssns_tool.cc.

References reconfigure().

72  {
73  reconfigure(pset);
74 
75  // Report.
76  mf::LogInfo("DirectHitParticleAssns") << "Configured\n";
77  }
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
void reconfigure(fhicl::ParameterSet const &pset) override

Member Function Documentation

void t0::DirectHitParticleAssns::CreateHitParticleAssociations ( art::Event evt,
HitParticleAssociations hitPartAssns 
)
overridevirtual

This rebuilds the internal maps.

Rebuild method -> rebuild the basic maps to get truth information

Arguments:

event - the art event used to extract all information

Implements t0::IHitParticleAssociations.

Definition at line 99 of file DirectHitParticleAssns_tool.cc.

References util::abs(), art::Assns< L, R, D >::addSingle(), DEFINE_ART_CLASS_TOOL, anab::BackTrackerHitMatchingData::energy, fHitModuleLabelVec, fMCParticleModuleLabel, fTrkIDECollector, art::ProductRetriever::getByLabel(), art::ProductRetriever::getValidHandle(), anab::BackTrackerHitMatchingData::ideFraction, anab::BackTrackerHitMatchingData::ideNFraction, anab::BackTrackerHitMatchingData::isMaxIDE, anab::BackTrackerHitMatchingData::isMaxIDEN, art::Handle< T >::isValid(), and anab::BackTrackerHitMatchingData::numElectrons.

101  {
102  // This function handles the "direct" creation of hit<-->MCParticle associations through use of the BackTracker
103  //
104  auto mcpartHandle = evt.getValidHandle<std::vector<simb::MCParticle>>(fMCParticleModuleLabel);
105 
106  // Access art services...
109 
110  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
111 
112  // Loop over input hit producer labels
113  for (const auto& inputTag : fHitModuleLabelVec) {
115  evt.getByLabel(inputTag, hitListHandle);
116 
117  if (!hitListHandle.isValid()) {
118  mf::LogInfo("DirectHitParticleAssns")
119  << "InputTag not associating to valid hit collection, tag: " << inputTag << "\n";
120  continue;
121  }
122 
124  std::unordered_map<int, int>
125  trkid_lookup; //indexed by geant4trkid, delivers MC particle location
126 
127  auto const& hitList(*hitListHandle);
128  auto const& mcpartList(*mcpartHandle);
129 
130  for (size_t i_h = 0; i_h < hitList.size(); ++i_h) {
131  art::Ptr<recob::Hit> hitPtr(hitListHandle, i_h);
132 
133  auto trkide_list = btService->HitToTrackIDEs(clockData, hitPtr);
134 
135  double maxe(-1.);
136  double tote(0.);
137  int maxtrkid(-1);
138  double maxn(-1.);
139  double totn(0.);
140  int maxntrkid(-1);
141 
142  fTrkIDECollector.clear();
143 
144  //for(auto const& t : trkide_list){
145  for (size_t i_t = 0; i_t < trkide_list.size(); ++i_t) {
146  auto const& t(trkide_list[i_t]);
147  fTrkIDECollector[t.trackID].E += t.energy;
148  tote += t.energy;
149  if (fTrkIDECollector[t.trackID].E > maxe) {
150  maxe = fTrkIDECollector[t.trackID].E;
151  maxtrkid = t.trackID;
152  }
153  fTrkIDECollector[t.trackID].NumElectrons += t.numElectrons;
154  totn += t.numElectrons;
155  if (fTrkIDECollector[t.trackID].NumElectrons > maxn) {
156  maxn = fTrkIDECollector[t.trackID].NumElectrons;
157  maxntrkid = t.trackID;
158  }
159 
160  //if not found, find mc particle...
161  if (trkid_lookup.find(t.trackID) == trkid_lookup.end()) {
162  size_t i_p = 0;
163  while (i_p < mcpartList.size()) {
164  if (mcpartList[i_p].TrackId() == abs(t.trackID)) {
165  trkid_lookup[t.trackID] = (int)i_p;
166  break;
167  }
168  ++i_p;
169  }
170  if (i_p == mcpartList.size()) trkid_lookup[t.trackID] = -1;
171  }
172  }
173  //end loop on TrackIDs
174 
175  //now find the mcparticle and loop back through ...
176  for (auto const& t : fTrkIDECollector) {
177  int mcpart_i = trkid_lookup[t.first];
178  if (mcpart_i == -1) continue; //no mcparticle here
179  art::Ptr<simb::MCParticle> mcpartPtr(mcpartHandle, mcpart_i);
180  bthmd.ideFraction = t.second.E / tote;
181  bthmd.isMaxIDE = (t.first == maxtrkid);
182  bthmd.ideNFraction = t.second.NumElectrons / totn;
183  bthmd.isMaxIDEN = (t.first == maxntrkid);
184  bthmd.energy = t.second.E;
185  bthmd.numElectrons = t.second.NumElectrons;
186  hitPartAssns->addSingle(mcpartPtr, hitPtr, bthmd);
187  }
188 
189  } //end loop on hits
190  } // end loop on producers
191 
192  return;
193  }
std::unordered_map< int, TrackIDEinfo > fTrkIDECollector
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
constexpr auto abs(T v)
Returns the absolute value of the argument.
bool isValid() const noexcept
Definition: Handle.h:203
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
std::vector< art::InputTag > fHitModuleLabelVec
void addSingle(Ptr< left_t > const &left, Ptr< right_t > const &right, data_t const &data)
Definition: Assns.h:549
void t0::DirectHitParticleAssns::reconfigure ( fhicl::ParameterSet const &  pset)
overridevirtual

Reconfigure method.

Arguments:

pset - Fcl parameter set.

Implements t0::IHitParticleAssociations.

Definition at line 86 of file DirectHitParticleAssns_tool.cc.

References fHitModuleLabelVec, fMCParticleModuleLabel, and fhicl::ParameterSet::get().

Referenced by DirectHitParticleAssns().

87  {
88  fMCParticleModuleLabel = pset.get<art::InputTag>("MCParticleLabel");
89  fHitModuleLabelVec = pset.get<std::vector<art::InputTag>>("HitModuleLabelVec");
90  }
std::vector< art::InputTag > fHitModuleLabelVec

Member Data Documentation

std::vector<art::InputTag> t0::DirectHitParticleAssns::fHitModuleLabelVec
private

Definition at line 54 of file DirectHitParticleAssns_tool.cc.

Referenced by CreateHitParticleAssociations(), and reconfigure().

art::InputTag t0::DirectHitParticleAssns::fMCParticleModuleLabel
private

Definition at line 55 of file DirectHitParticleAssns_tool.cc.

Referenced by CreateHitParticleAssociations(), and reconfigure().

std::unordered_map<int, TrackIDEinfo> t0::DirectHitParticleAssns::fTrkIDECollector
private

Definition at line 61 of file DirectHitParticleAssns_tool.cc.

Referenced by CreateHitParticleAssociations().


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