Classes | Public Member Functions | Private Attributes | List of all members
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...
 
- Public Member Functions inherited from t0::IHitParticleAssociations
virtual ~IHitParticleAssociations () noexcept=default
 Virtual Destructor. More...
 

Private Attributes

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

Detailed Description

Definition at line 30 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 65 of file DirectHitParticleAssns_tool.cc.

66  {
67  reconfigure(pset);
68 
69  // Report.
70  mf::LogInfo("DirectHitParticleAssns") << "Configured\n";
71  }
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 95 of file DirectHitParticleAssns_tool.cc.

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

Reconfigure method.

Arguments:

pset - Fcl parameter set.

Implements t0::IHitParticleAssociations.

Definition at line 81 of file DirectHitParticleAssns_tool.cc.

82  {
83  fMCParticleModuleLabel = pset.get<art::InputTag>("MCParticleLabel");
84  fHitModuleLabelVec = pset.get<std::vector<art::InputTag>>("HitModuleLabelVec");
85  }
std::vector< art::InputTag > fHitModuleLabelVec

Member Data Documentation

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

Definition at line 48 of file DirectHitParticleAssns_tool.cc.

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

Definition at line 49 of file DirectHitParticleAssns_tool.cc.

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

Definition at line 55 of file DirectHitParticleAssns_tool.cc.


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