All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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::InputTag > fHitModuleLabelVec
 
art::InputTag fMCParticleModuleLabel
 
std::unordered_map< int,
TrackIDEinfo
fTrkIDECollector
 

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.

72  {
73  reconfigure(pset);
74 
75  // Report.
76  mf::LogInfo("DirectHitParticleAssns") << "Configured\n";
77  }
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 101 of file DirectHitParticleAssns_tool.cc.

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

Reconfigure method.

Arguments:

pset - Fcl parameter set.

Implements t0::IHitParticleAssociations.

Definition at line 87 of file DirectHitParticleAssns_tool.cc.

88  {
89  fMCParticleModuleLabel = pset.get<art::InputTag>("MCParticleLabel");
90  fHitModuleLabelVec = pset.get<std::vector<art::InputTag>>("HitModuleLabelVec");
91  }
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.

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

Definition at line 55 of file DirectHitParticleAssns_tool.cc.

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

Definition at line 61 of file DirectHitParticleAssns_tool.cc.


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