LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
t0::IndirectHitParticleAssns Class Reference
Inheritance diagram for t0::IndirectHitParticleAssns:
t0::IHitParticleAssociations

Public Member Functions

 IndirectHitParticleAssns (fhicl::ParameterSet const &pset)
 Constructor. More...
 
 ~IndirectHitParticleAssns ()
 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
 
art::InputTag fHitPartAssnsModuleLabel
 

Detailed Description

Definition at line 36 of file IndirectHitParticleAssns_tool.cc.

Constructor & Destructor Documentation

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

Constructor.

Parameters
psetConstructor.

Arguments:

pset - Fcl parameters.

Definition at line 74 of file IndirectHitParticleAssns_tool.cc.

References reconfigure().

75 {
76  reconfigure(pset);
77 
78  // Report.
79  mf::LogInfo("IndirectHitParticleAssns") << "Configured\n";
80 }
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
void reconfigure(fhicl::ParameterSet const &pset) override
t0::IndirectHitParticleAssns::~IndirectHitParticleAssns ( )

Destructor.

Definition at line 84 of file IndirectHitParticleAssns_tool.cc.

85 {}

Member Function Documentation

void t0::IndirectHitParticleAssns::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 108 of file IndirectHitParticleAssns_tool.cc.

References art::Assns< L, R, D >::addSingle(), recob::Hit::Channel(), DEFINE_ART_CLASS_TOOL, art::EventID::event(), fHitModuleLabel, fHitPartAssnsModuleLabel, fMCParticleModuleLabel, art::DataViewImpl::getByLabel(), art::DataViewImpl::getValidHandle(), art::Event::id(), art::Handle< T >::isValid(), art::Ptr< T >::key(), recob::Hit::PeakTimeMinusRMS(), recob::Hit::PeakTimePlusRMS(), art::Event::run(), and art::Event::subRun().

109 {
110  // This function handles the "indirect" creation of hit<-->MCParticle associations by trying to
111  // use the previously created Hit<-->MCParticle associations
112  // Its pretty much a brute force approach here... but time is short!
113  //
114  // First step is to recover the preexisting associations
115 
116  // Get a handle for the associations...
117  auto partHitAssnsHandle = evt.getValidHandle< HitParticleAssociations >(fHitPartAssnsModuleLabel);
118  auto mcParticleHandle = evt.getValidHandle< std::vector<simb::MCParticle> >(fMCParticleModuleLabel);
119 
120  if (!partHitAssnsHandle.isValid() || !mcParticleHandle.isValid())
121  {
122  throw cet::exception("IndirectHitParticleAssns") << "===>> NO MCParticle <--> Hit associations found for run/subrun/event: " << evt.run() << "/" << evt.subRun() << "/" << evt.id().event();
123  }
124 
125  // Look up the hits we want to process as well, since if they are not there then no point in proceeding
126  art::Handle< std::vector<recob::Hit> > hitListHandle;
127  evt.getByLabel(fHitModuleLabel,hitListHandle);
128 
129  if(!hitListHandle.isValid()){
130  throw cet::exception("IndirectHitParticleAssns") << "===>> NO Hit collection found to process for run/subrun/event: " << evt.run() << "/" << evt.subRun() << "/" << evt.id().event();
131  }
132 
133  // Go through the associations and build out our (hopefully sparse) data structure
134  using ParticleDataPair = std::pair<size_t, const anab::BackTrackerHitMatchingData*>;
135  using MCParticleDataSet = std::set<ParticleDataPair>;
136  using TickToPartDataMap = std::unordered_map<raw::TDCtick_t, MCParticleDataSet>;
137  using ChannelToTickPartDataMap = std::unordered_map<raw::ChannelID_t, TickToPartDataMap>;
138 
139  ChannelToTickPartDataMap chanToTickPartDataMap;
140 
141  // Build out the maps between hits/particles
142  for(HitParticleAssociations::const_iterator partHitItr = partHitAssnsHandle->begin(); partHitItr != partHitAssnsHandle->end(); ++partHitItr)
143  {
144  const art::Ptr<simb::MCParticle>& mcParticle = partHitItr->first;
145  const art::Ptr<recob::Hit>& recoHit = partHitItr->second;
146  const anab::BackTrackerHitMatchingData* data = &partHitAssnsHandle->data(partHitItr);
147 
148  TickToPartDataMap& tickToPartDataMap = chanToTickPartDataMap[recoHit->Channel()];
149 
150  for(raw::TDCtick_t tick = recoHit->PeakTimeMinusRMS(); tick <= recoHit->PeakTimePlusRMS(); tick++)
151  {
152  tickToPartDataMap[tick].insert(ParticleDataPair(mcParticle.key(),data));
153  }
154  }
155 
156  // Armed with the map, process the hit list
157  for(size_t hitIdx = 0; hitIdx < hitListHandle->size(); hitIdx++)
158  {
159  art::Ptr<recob::Hit> hit(hitListHandle,hitIdx);
160 
161  TickToPartDataMap& tickToPartDataMap = chanToTickPartDataMap[hit->Channel()];
162 
163  if (tickToPartDataMap.empty())
164  {
165  mf::LogInfo("IndirectHitParticleAssns") << "No channel information found for hit " << hit << "\n";
166  continue;
167  }
168 
169  // Keep track of results
170  MCParticleDataSet particleDataSet;
171 
172  // Go through the ticks in this hit and recover associations
173  for(raw::TDCtick_t tick = hit->PeakTimeMinusRMS(); tick <= hit->PeakTimePlusRMS(); tick++)
174  {
175  TickToPartDataMap::iterator hitInfoItr = tickToPartDataMap.find(tick);
176 
177  if (hitInfoItr != tickToPartDataMap.end())
178  {
179  for(const auto& partData : hitInfoItr->second) particleDataSet.insert(partData);
180  }
181  }
182 
183  // Now create new associations for the hit in question
184  for(const auto& partData : particleDataSet)
185  hitPartAssns->addSingle(art::Ptr<simb::MCParticle>(mcParticleHandle, partData.first), hit, *partData.second);
186  }
187 
188  return;
189 }
key_type key() const
Definition: Ptr.h:356
art::Assns< simb::MCParticle, recob::Hit, anab::BackTrackerHitMatchingData > HitParticleAssociations
SubRunNumber_t subRun() const
Definition: Event.h:72
intermediate_table::iterator iterator
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
int TDCtick_t
Type representing a TDC tick.
Definition: RawTypes.h:24
bool isValid() const
Definition: Handle.h:190
float PeakTimeMinusRMS(float sigmas=+1.) const
Returns a time sigmas RMS away from the peak time.
Definition: Hit.h:240
Detector simulation of raw signals on wires.
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
EventNumber_t event() const
Definition: EventID.h:117
float PeakTimePlusRMS(float sigmas=+1.) const
Returns a time sigmas RMS away from the peak time.
Definition: Hit.h:237
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
RunNumber_t run() const
Definition: Event.h:77
raw::ChannelID_t Channel() const
ID of the readout channel the hit was extracted from.
Definition: Hit.h:231
Definition: fwd.h:25
typename art::const_AssnsIter< L, R, D, Direction::Forward > const_iterator
Definition: Assns.h:217
EventID id() const
Definition: Event.h:56
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void t0::IndirectHitParticleAssns::reconfigure ( fhicl::ParameterSet const &  pset)
overridevirtual

Reconfigure method.

Arguments:

pset - Fcl parameter set.

Implements t0::IHitParticleAssociations.

Definition at line 94 of file IndirectHitParticleAssns_tool.cc.

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

Referenced by IndirectHitParticleAssns().

95 {
96  fHitPartAssnsModuleLabel = pset.get<art::InputTag>("HitPartAssnsLabel");
97  fMCParticleModuleLabel = pset.get<art::InputTag>("MCParticleModuleLabel");
98  fHitModuleLabel = pset.get<art::InputTag>("HitModuleLabel");
99 }

Member Data Documentation

art::InputTag t0::IndirectHitParticleAssns::fHitModuleLabel
private

Definition at line 61 of file IndirectHitParticleAssns_tool.cc.

Referenced by CreateHitParticleAssociations(), and reconfigure().

art::InputTag t0::IndirectHitParticleAssns::fHitPartAssnsModuleLabel
private

Definition at line 63 of file IndirectHitParticleAssns_tool.cc.

Referenced by CreateHitParticleAssociations(), and reconfigure().

art::InputTag t0::IndirectHitParticleAssns::fMCParticleModuleLabel
private

Definition at line 62 of file IndirectHitParticleAssns_tool.cc.

Referenced by CreateHitParticleAssociations(), and reconfigure().


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