31 #include "canvas/Persistency/Common/FindManyP.h" 32 #include "canvas/Persistency/Common/FindOneP.h" 62 const art::Handle<std::vector<recob::PFParticle>>& pfParticleHandle,
63 const art::FindManyP<recob::Cluster>& partToClusAssns,
64 const art::FindManyP<recob::Hit>& clusToHitAssns,
68 art::FindOneP<recob::Wire>&,
72 art::FindOneP<recob::Wire>&,
125 mf::LogInfo(
"CRHitRemoval") <<
"CRHitRemoval configured\n";
133 auto const*
geo = lar::providerFrom<geo::Geometry>();
139 float const driftVelocity = detp.DriftVelocity(detp.Efield(), detp.Temperature());
143 clock_data.Time2Tick(clock_data.TriggerTime());
170 if (!hitHandle.
isValid())
return;
191 if (!pfParticleHandle.isValid()) {
206 if (!clusterHandle.
isValid()) {
216 std::vector<art::Handle<std::vector<anab::CosmicTag>>> cosmicHandleVec;
217 std::vector<std::map<int, std::vector<art::Ptr<recob::Track>>>> cosmicToTrackVecMapVec;
218 std::vector<std::map<int, std::vector<art::Ptr<recob::PFParticle>>>> trackToPFParticleVecMapVec;
219 std::vector<double> thresholdVec;
229 art::FindManyP<recob::Track> cosmicTrackAssns(cosmicHandle, evt, handleLabel);
237 std::map<int, std::vector<art::Ptr<recob::Track>>> cosmicToTrackVecMap;
238 std::map<int, std::vector<art::Ptr<recob::PFParticle>>> trackToPFParticleVecMap;
241 for (
size_t cosmicIdx = 0; cosmicIdx < cosmicHandle->size(); cosmicIdx++) {
244 std::vector<art::Ptr<recob::Track>> cosmicToTrackVec =
245 cosmicTrackAssns.at(cosmicTag.
key());
247 cosmicToTrackVecMap[cosmicTag.
key()] = cosmicToTrackVec;
249 art::FindManyP<recob::PFParticle> trackPFParticleAssns(
252 for (
auto& track : cosmicToTrackVec) {
253 std::vector<art::Ptr<recob::PFParticle>> trackToPFParticleVec =
254 trackPFParticleAssns.at(track.key());
256 for (
auto& pfParticle : trackToPFParticleVec)
257 trackToPFParticleVecMap[track.key()].push_back(pfParticle);
262 cosmicHandleVec.emplace_back(cosmicHandle);
263 cosmicToTrackVecMapVec.emplace_back(cosmicToTrackVecMap);
264 trackToPFParticleVecMapVec.emplace_back(trackToPFParticleVecMap);
271 if (cosmicHandleVec.empty()) {
289 std::set<const recob::PFParticle*> taggedSet;
293 for (
size_t idx = 0; idx != cosmicHandleVec.size(); idx++) {
296 const std::map<int, std::vector<art::Ptr<recob::Track>>>& crTagTrackVec(
297 cosmicToTrackVecMapVec[idx]);
298 const std::map<int, std::vector<art::Ptr<recob::PFParticle>>>& trackToPFParticleVecMap(
299 trackToPFParticleVecMapVec[idx]);
301 for (
size_t crIdx = 0; crIdx != cosmicHandle->size(); crIdx++) {
305 if (cosmicTag->
CosmicScore() > thresholdVec[idx]) {
307 std::vector<art::Ptr<recob::Track>> trackVec(crTagTrackVec.at(cosmicTag.
key()));
310 for (
const auto& track : trackVec) {
312 trackToPFParticleVecItr = trackToPFParticleVecMap.find(track.key());
314 if (trackToPFParticleVecItr != trackToPFParticleVecMap.end()) {
316 for (
const auto& pfParticlePtr : trackToPFParticleVecItr->second) {
326 taggedSet.insert(pfParticle);
335 if (!taggedSet.empty()) {
350 for (
const auto& pfParticle : *pfParticleHandle) {
352 if (!pfParticle.IsPrimary())
continue;
364 if (taggedSet.find(&pfParticle) != taggedSet.end()) goodHits =
false;
369 for (
const auto&
hit : tempHits) {
382 std::copy(tempHits.begin(), tempHits.end(), std::back_inserter(untaggedHits));
384 std::copy(tempHits.begin(), tempHits.end(), std::back_inserter(taggedHits));
419 const art::Handle<std::vector<recob::PFParticle>>& pfParticleHandle,
420 const art::FindManyP<recob::Cluster>& partToClusAssns,
421 const art::FindManyP<recob::Hit>& clusToHitAssns,
425 std::vector<art::Ptr<recob::Cluster>> clusterVec = partToClusAssns.at(pfParticle->
Self());
431 for (
const auto&
cluster : clusterVec) {
432 std::vector<art::Ptr<recob::Hit>> clusHitVec = clusToHitAssns.at(
cluster.key());
433 hitVec.insert(hitVec.end(), clusHitVec.begin(), clusHitVec.end());
435 int minHitTick = (*std::min_element(clusHitVec.begin(),
437 [](
const auto&
hit,
const auto&
min) {
438 return hit->PeakTimeMinusRMS() <
min->PeakTimeMinusRMS();
440 ->PeakTimeMinusRMS();
441 int maxHitTick = (*std::max_element(clusHitVec.begin(),
443 [](
const auto&
hit,
const auto&
max) {
444 return hit->PeakTimePlusRMS() >
max->PeakTimePlusRMS();
448 if (minHitTick < minTick) minTick = minHitTick;
449 if (maxHitTick < maxTick) maxTick = maxHitTick;
453 for (
const auto& daughterId : pfParticle->
Daughters()) {
457 daughter.
get(), pfParticleHandle, partToClusAssns, clusToHitAssns, hitVec);
465 art::FindOneP<recob::Wire>& wireAssns,
468 for (
const auto& hitPtr : inputHits) {
480 art::FindOneP<recob::Wire>& wireAssns,
483 for (
const auto& hitPtr : inputHits) {
509 if (used_hits.size() > 0) {
511 std::stable_sort(hits.begin(), hits.end());
512 std::stable_sort(used_hits.begin(), used_hits.end());
515 std::vector<art::Ptr<recob::Hit>>
::iterator it = std::set_difference(
516 hits.begin(), hits.end(), used_hits.begin(), used_hits.end(), hits.begin());
519 hits.erase(it, hits.end());
530 mf::LogInfo(
"CRHitRemoval") <<
"CRHitRemoval statistics:\n" 531 <<
" Number of events = " <<
fNumEvent <<
"\n" 532 <<
" Number of Cosmic Rays found = " <<
fNumCRRejects <<
", " 533 << aveCRPerEvent <<
" average/event";
const std::vector< size_t > & Daughters() const
Returns the collection of daughter particles.
std::string fPFParticleProducerLabel
PFParticle producer.
size_t Self() const
Returns the index of this particle.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
EDProducer(fhicl::ParameterSet const &pset)
int fEndTickPadding
Padding the end tick.
void copyAllHits(std::vector< art::Ptr< recob::Hit >> &, art::FindOneP< recob::Wire > &, recob::HitCollectionCreator &)
Cluster finding and building.
int fNumCRRejects
Number of tracks produced.
static void declare_products(art::ProducesCollector &collector, std::string instance_name="", bool doWireAssns=true, bool doRawDigitAssns=true)
Declares the hit products we are going to fill.
art framework interface to geometry description
bool isValid() const noexcept
Helper functions to create a hit.
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
A class handling a collection of hits and its associations.
std::vector< std::string > fAssnProducerLabels
Track to PFParticle assns producer.
#define DEFINE_ART_MODULE(klass)
std::vector< art::Ptr< recob::Hit >> HitPtrVector
std::string fHitProducerLabel
The full collection of hits.
key_type key() const noexcept
int fMaxTickDrift
Ending tick.
bool IsPrimary() const
Returns whether the particle is the root of the flow.
void emplace_back(recob::Hit &&hit, art::Ptr< recob::Wire > const &wire=art::Ptr< recob::Wire >(), art::Ptr< raw::RawDigit > const &digits=art::Ptr< raw::RawDigit >())
Adds the specified hit to the data collection.
virtual void endJob()
End job method.
std::vector< double > fCosmicTagThresholds
Thresholds for tagging.
static int max(int a, int b)
Detector simulation of raw signals on wires.
ProducesCollector & producesCollector() noexcept
void collectPFParticleHits(const recob::PFParticle *pfParticle, const art::Handle< std::vector< recob::PFParticle >> &pfParticleHandle, const art::FindManyP< recob::Cluster > &partToClusAssns, const art::FindManyP< recob::Hit > &clusToHitAssns, HitPtrVector &hitVec)
virtual void produce(art::Event &e)
Declaration of signal hit object.
Hierarchical representation of particle flow.
int fMaxOutOfTime
Max hits that can be out of time before rejecting.
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
CRHitRemoval(fhicl::ParameterSet const &pset)
void copyInTimeHits(std::vector< art::Ptr< recob::Hit >> &, art::FindOneP< recob::Wire > &, recob::HitCollectionCreator &)
int fDetectorWidthTicks
Effective drift time in ticks.
Provides recob::Track data product.
std::vector< std::string > fTrackProducerLabels
Track producer.
int fNumEvent
Number of events seen.
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
LArSoft geometry interface.
int fMinTickDrift
Starting tick.
void FilterHits(HitPtrVector &hits, HitPtrVector &used_hits)
virtual void beginJob()
Begin job method.
std::vector< std::string > fCosmicProducerLabels
List of cosmic tagger producers.