LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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...
 
 ~DirectHitParticleAssns ()
 Destructor. More...
 
void reconfigure (fhicl::ParameterSet const &pset) override
 
void CreateHitParticleAssociations (art::Event &, HitParticleAssociations *) override
 This rebuilds the internal maps. More...
 

Private Attributes

art::InputTag fHitModuleLabel
 
art::InputTag fMCParticleModuleLabel
 
std::unordered_map< int, TrackIDEinfofTrkIDECollector
 

Detailed Description

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

References reconfigure().

80 {
81  reconfigure(pset);
82 
83  // Report.
84  mf::LogInfo("DirectHitParticleAssns") << "Configured\n";
85 }
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
void reconfigure(fhicl::ParameterSet const &pset) override
t0::DirectHitParticleAssns::~DirectHitParticleAssns ( )

Destructor.

Definition at line 89 of file DirectHitParticleAssns_tool.cc.

90 {}

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 112 of file DirectHitParticleAssns_tool.cc.

References art::Assns< L, R, D >::addSingle(), DEFINE_ART_CLASS_TOOL, anab::BackTrackerHitMatchingData::energy, fHitModuleLabel, fMCParticleModuleLabel, fTrkIDECollector, art::DataViewImpl::getByLabel(), art::DataViewImpl::getValidHandle(), cheat::BackTrackerService::HitToTrackIDEs(), anab::BackTrackerHitMatchingData::ideFraction, anab::BackTrackerHitMatchingData::ideNFraction, anab::BackTrackerHitMatchingData::isMaxIDE, anab::BackTrackerHitMatchingData::isMaxIDEN, and anab::BackTrackerHitMatchingData::numElectrons.

113 {
114  // This function handles the "direct" creation of hit<-->MCParticle associations through use of the BackTracker
115  //
116  auto mcpartHandle = evt.getValidHandle< std::vector<simb::MCParticle> >(fMCParticleModuleLabel);
117 
118  art::Handle< std::vector<recob::Hit> > hitListHandle;
119  evt.getByLabel(fHitModuleLabel,hitListHandle);
120 
121  if(!hitListHandle.isValid()){
122  std::cerr << "Hit handle is not valid! Returning empty collection" << std::endl;
123  return;
124  }
125 
126  // Access art services...
129 
130  double maxe = -1;
131  double tote = 0;
132  // int trkid = -1;
133  int maxtrkid = -1;
134  double maxn = -1;
135  double totn = 0;
136  int maxntrkid = -1;
138  std::unordered_map<int,int> trkid_lookup; //indexed by geant4trkid, delivers MC particle location
139 
140  auto const& hitList(*hitListHandle);
141  auto const& mcpartList(*mcpartHandle);
142 
143  for(size_t i_h=0; i_h<hitList.size(); ++i_h){
144  art::Ptr<recob::Hit> hitPtr(hitListHandle, i_h);
145  auto trkide_list = btService->HitToTrackIDEs(hitPtr);
146 
147  maxe = -1; tote = 0; maxtrkid = -1;
148  maxn = -1; totn = 0; maxntrkid = -1;
149  fTrkIDECollector.clear();
150 
151  //for(auto const& t : trkide_list){
152  for(size_t i_t=0; i_t<trkide_list.size(); ++i_t){
153  auto const& t(trkide_list[i_t]);
154  fTrkIDECollector[t.trackID].E += t.energy;
155  tote += t.energy;
156  if(fTrkIDECollector[t.trackID].E>maxe) { maxe = fTrkIDECollector[t.trackID].E; maxtrkid = t.trackID; }
157  fTrkIDECollector[t.trackID].NumElectrons += t.numElectrons;
158  totn += t.numElectrons;
159  if(fTrkIDECollector[t.trackID].NumElectrons > maxn) {
160  maxn = fTrkIDECollector[t.trackID].NumElectrons;
161  maxntrkid = t.trackID;
162  }
163 
164  //if not found, find mc particle...
165  if(trkid_lookup.find(t.trackID)==trkid_lookup.end()){
166  size_t i_p=0;
167  while(i_p<mcpartList.size()){
168  if(mcpartList[i_p].TrackId() == abs(t.trackID)) { trkid_lookup[t.trackID] = (int)i_p; break;}
169  ++i_p;
170  }
171  if(i_p==mcpartList.size()) trkid_lookup[t.trackID] = -1;
172  }
173 
174  }
175  //end loop on TrackIDs
176 
177  //now find the mcparticle and loop back through ...
178  for(auto const& t : fTrkIDECollector){
179  int mcpart_i = trkid_lookup[t.first];
180  if(mcpart_i==-1) continue; //no mcparticle here
181  art::Ptr<simb::MCParticle> mcpartPtr(mcpartHandle, mcpart_i);
182  bthmd.ideFraction = t.second.E / tote;
183  bthmd.isMaxIDE = (t.first==maxtrkid);
184  bthmd.ideNFraction = t.second.NumElectrons / totn;
185  bthmd.isMaxIDEN = ( t.first == maxntrkid );
186  bthmd.energy = t.second.E;
187  bthmd.numElectrons = t.second.NumElectrons;
188  hitPartAssns->addSingle(mcpartPtr, hitPtr, bthmd);
189  }
190 
191  }//end loop on hits
192 
193  return;
194 }
std::unordered_map< int, TrackIDEinfo > fTrkIDECollector
const std::vector< sim::TrackIDE > HitToTrackIDEs(recob::Hit const &hit)
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
void t0::DirectHitParticleAssns::reconfigure ( fhicl::ParameterSet const &  pset)
overridevirtual

Reconfigure method.

Arguments:

pset - Fcl parameter set.

Implements t0::IHitParticleAssociations.

Definition at line 99 of file DirectHitParticleAssns_tool.cc.

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

Referenced by DirectHitParticleAssns().

100 {
101  fMCParticleModuleLabel = pset.get<art::InputTag>("MCParticleLabel");
102  fHitModuleLabel = pset.get<art::InputTag>("HitModuleLabel");
103 }

Member Data Documentation

art::InputTag t0::DirectHitParticleAssns::fHitModuleLabel
private

Definition at line 62 of file DirectHitParticleAssns_tool.cc.

Referenced by CreateHitParticleAssociations(), and reconfigure().

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

Definition at line 63 of file DirectHitParticleAssns_tool.cc.

Referenced by CreateHitParticleAssociations(), and reconfigure().

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

Definition at line 69 of file DirectHitParticleAssns_tool.cc.

Referenced by CreateHitParticleAssociations().


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