64 const art::Handle<std::vector<recob::PFParticle>>& pfParticleHandle,
127 mf::LogInfo(
"CRHitRemoval") <<
"CRHitRemoval configured\n";
134 auto const*
geo = lar::providerFrom<geo::Geometry>();
140 float const driftVelocity = detp.DriftVelocity(detp.Efield(), detp.Temperature());
144 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;
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;
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));
418 const art::Handle<std::vector<recob::PFParticle>>& pfParticleHandle,
424 std::vector<art::Ptr<recob::Cluster>> clusterVec = partToClusAssns.at(pfParticle->
Self());
430 for (
const auto&
cluster : clusterVec) {
431 std::vector<art::Ptr<recob::Hit>> clusHitVec = clusToHitAssns.at(
cluster.key());
432 hitVec.insert(hitVec.end(), clusHitVec.begin(), clusHitVec.end());
434 int minHitTick = (*std::min_element(clusHitVec.begin(),
436 [](
const auto&
hit,
const auto& min) {
437 return hit->PeakTimeMinusRMS() < min->PeakTimeMinusRMS();
439 ->PeakTimeMinusRMS();
440 int maxHitTick = (*std::max_element(clusHitVec.begin(),
442 [](
const auto&
hit,
const auto& max) {
443 return hit->PeakTimePlusRMS() > max->PeakTimePlusRMS();
447 if (minHitTick < minTick) minTick = minHitTick;
448 if (maxHitTick < maxTick) maxTick = maxHitTick;
452 for (
const auto& daughterId : pfParticle->
Daughters()) {
456 daughter.
get(), pfParticleHandle, partToClusAssns, clusToHitAssns, hitVec);
466 for (
const auto& hitPtr : inputHits) {
480 for (
const auto& hitPtr : inputHits) {
505 if (used_hits.size() > 0) {
507 std::stable_sort(hits.begin(), hits.end());
508 std::stable_sort(used_hits.begin(), used_hits.end());
511 std::vector<art::Ptr<recob::Hit>>
::iterator it = std::set_difference(
512 hits.begin(), hits.end(), used_hits.begin(), used_hits.end(), hits.begin());
515 hits.erase(it, hits.end());
525 mf::LogInfo(
"CRHitRemoval") <<
"CRHitRemoval statistics:\n" 526 <<
" Number of events = " <<
fNumEvent <<
"\n" 527 <<
" Number of Cosmic Rays found = " <<
fNumCRRejects <<
", " 528 << aveCRPerEvent <<
" average/event";
const std::vector< size_t > & Daughters() const
Returns the collection of daughter particles.
std::string fPFParticleProducerLabel
PFParticle producer.
Utilities related to art service access.
size_t Self() const
Returns the index of this particle.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Declaration of signal hit object.
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.
bool isValid() const noexcept
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Helper functions to create a hit.
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.
Provides recob::Track data product.
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.
Declaration of cluster object.
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)
Hierarchical representation of particle flow.
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
int fMaxOutOfTime
Max hits that can be out of time before rejecting.
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.
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.
Namespace collecting geometry-related classes utilities.
int fMinTickDrift
Starting tick.
void FilterHits(HitPtrVector &hits, HitPtrVector &used_hits)
virtual void beginJob()
Begin job method.
art framework interface to geometry description
std::vector< std::string > fCosmicProducerLabels
List of cosmic tagger producers.