Public Member Functions | Private Attributes | List of all members
t0::IndirectHitParticleAssns Class Reference
Inheritance diagram for t0::IndirectHitParticleAssns:
t0::IHitParticleAssociations

Public Member Functions

 IndirectHitParticleAssns (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
 
art::InputTag fHitPartAssnsModuleLabel
 

Detailed Description

Definition at line 26 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 59 of file IndirectHitParticleAssns_tool.cc.

60 {
61  reconfigure(pset);
62 
63  // Report.
64  mf::LogInfo("IndirectHitParticleAssns") << "Configured\n";
65 }
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
void reconfigure(fhicl::ParameterSet const &pset) override

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 88 of file IndirectHitParticleAssns_tool.cc.

89 {
90  // This function handles the "indirect" creation of hit<-->MCParticle associations by trying to
91  // use the previously created Hit<-->MCParticle associations
92  // Its pretty much a brute force approach here... but time is short!
93  //
94  // First step is to recover the preexisting associations
95 
96  // Get a handle for the associations...
97  auto partHitAssnsHandle = evt.getValidHandle< HitParticleAssociations >(fHitPartAssnsModuleLabel);
98  auto mcParticleHandle = evt.getValidHandle< std::vector<simb::MCParticle> >(fMCParticleModuleLabel);
99 
100  if (!partHitAssnsHandle.isValid() || !mcParticleHandle.isValid())
101  {
102  throw cet::exception("IndirectHitParticleAssns") << "===>> NO MCParticle <--> Hit associations found for run/subrun/event: " << evt.run() << "/" << evt.subRun() << "/" << evt.id().event();
103  }
104 
105  // Loop over input hit collections
106  for(const auto& inputTag : fHitModuleLabelVec)
107  {
108  // Look up the hits we want to process as well, since if they are not there then no point in proceeding
109  art::Handle< std::vector<recob::Hit> > hitListHandle;
110  evt.getByLabel(inputTag,hitListHandle);
111 
112  if(!hitListHandle.isValid()){
113  mf::LogInfo("IndirectHitParticleAssns") << "===>> NO Hit collection found to process for run/subrun/event: " << evt.run() << "/" << evt.subRun() << "/" << evt.id().event() << "\n";
114  continue;
115  }
116 
117  // Go through the associations and build out our (hopefully sparse) data structure
118  using ParticleDataPair = std::pair<size_t, const anab::BackTrackerHitMatchingData*>;
119  using MCParticleDataSet = std::set<ParticleDataPair>;
120  using TickToPartDataMap = std::unordered_map<raw::TDCtick_t, MCParticleDataSet>;
121  using ChannelToTickPartDataMap = std::unordered_map<raw::ChannelID_t, TickToPartDataMap>;
122 
123  ChannelToTickPartDataMap chanToTickPartDataMap;
124 
125  // Build out the maps between hits/particles
126  for(HitParticleAssociations::const_iterator partHitItr = partHitAssnsHandle->begin(); partHitItr != partHitAssnsHandle->end(); ++partHitItr)
127  {
128  const art::Ptr<simb::MCParticle>& mcParticle = partHitItr->first;
129  const art::Ptr<recob::Hit>& recoHit = partHitItr->second;
130  const anab::BackTrackerHitMatchingData* data = &partHitAssnsHandle->data(partHitItr);
131 
132  TickToPartDataMap& tickToPartDataMap = chanToTickPartDataMap[recoHit->Channel()];
133 
134  for(raw::TDCtick_t tick = recoHit->PeakTimeMinusRMS(); tick <= recoHit->PeakTimePlusRMS(); tick++)
135  {
136  tickToPartDataMap[tick].insert(ParticleDataPair(mcParticle.key(),data));
137  }
138  }
139 
140  // Armed with the map, process the hit list
141  for(size_t hitIdx = 0; hitIdx < hitListHandle->size(); hitIdx++)
142  {
143  art::Ptr<recob::Hit> hit(hitListHandle,hitIdx);
144 
145  TickToPartDataMap& tickToPartDataMap = chanToTickPartDataMap[hit->Channel()];
146 
147  if (tickToPartDataMap.empty())
148  {
149  mf::LogInfo("IndirectHitParticleAssns") << "No channel information found for hit " << hit << "\n";
150  continue;
151  }
152 
153  // Keep track of results
154  MCParticleDataSet particleDataSet;
155 
156  // Go through the ticks in this hit and recover associations
157  for(raw::TDCtick_t tick = hit->PeakTimeMinusRMS(); tick <= hit->PeakTimePlusRMS(); tick++)
158  {
159  TickToPartDataMap::iterator hitInfoItr = tickToPartDataMap.find(tick);
160 
161  if (hitInfoItr != tickToPartDataMap.end())
162  {
163  for(const auto& partData : hitInfoItr->second) particleDataSet.insert(partData);
164  }
165  }
166 
167  // Now create new associations for the hit in question
168  for(const auto& partData : particleDataSet)
169  hitPartAssns->addSingle(art::Ptr<simb::MCParticle>(mcParticleHandle, partData.first), hit, *partData.second);
170  }
171  }
172 
173  return;
174 }
intermediate_table::iterator iterator
art::Assns< simb::MCParticle, recob::Hit, anab::BackTrackerHitMatchingData > HitParticleAssociations
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
int TDCtick_t
Type representing a TDC tick.
Definition: RawTypes.h:25
bool isValid() const noexcept
Definition: Handle.h:191
std::vector< art::InputTag > fHitModuleLabelVec
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
key_type key() const noexcept
Definition: Ptr.h:216
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:75
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:78
RunNumber_t run() const
Definition: DataViewImpl.cc:71
float PeakTimeMinusRMS(float sigmas=+1.) const
Definition: Hit.h:239
Detector simulation of raw signals on wires.
EventNumber_t event() const
Definition: EventID.h:116
float PeakTimePlusRMS(float sigmas=+1.) const
Returns a time sigmas RMS away from the peak time.
Definition: Hit.h:236
raw::ChannelID_t Channel() const
ID of the readout channel the hit was extracted from.
Definition: Hit.h:230
typename art::const_AssnsIter< L, R, D, Direction::Forward > const_iterator
Definition: Assns.h:237
EventID id() const
Definition: Event.cc:34
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 74 of file IndirectHitParticleAssns_tool.cc.

75 {
76  fHitPartAssnsModuleLabel = pset.get<art::InputTag >("HitPartAssnsLabel");
77  fMCParticleModuleLabel = pset.get<art::InputTag >("MCParticleModuleLabel");
78  fHitModuleLabelVec = pset.get<std::vector<art::InputTag>>("HitModuleLabelVec");
79 }
std::vector< art::InputTag > fHitModuleLabelVec

Member Data Documentation

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

Definition at line 46 of file IndirectHitParticleAssns_tool.cc.

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

Definition at line 48 of file IndirectHitParticleAssns_tool.cc.

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

Definition at line 47 of file IndirectHitParticleAssns_tool.cc.


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