26 #include "art/Framework/Core/EDProducer.h" 
   27 #include "art/Framework/Core/ModuleMacros.h" 
   28 #include "art/Framework/Principal/Event.h" 
   29 #include "art/Framework/Principal/Handle.h" 
   30 #include "art/Framework/Services/Registry/ServiceHandle.h" 
   31 #include "canvas/Persistency/Common/Assns.h" 
   32 #include "canvas/Persistency/Common/FindManyP.h" 
   33 #include "canvas/Persistency/Common/FindOneP.h" 
   34 #include "canvas/Persistency/Common/Ptr.h" 
   35 #include "messagefacility/MessageLogger/MessageLogger.h" 
   64                              const art::Handle<std::vector<recob::PFParticle>>& pfParticleHandle,
 
   65                              const art::FindManyP<recob::Cluster>& partToClusAssns,
 
   66                              const art::FindManyP<recob::Hit>& clusToHitAssns,
 
   70                    art::FindOneP<recob::Wire>&,
 
   74                       art::FindOneP<recob::Wire>&,
 
  110   : EDProducer{pset}, fNumEvent(0), fNumCRRejects(0)
 
  112   fCosmicProducerLabels = pset.get<std::vector<std::string>>(
"CosmicProducerLabels");
 
  113   fHitProducerLabel = pset.get<std::string>(
"HitProducerLabel");
 
  114   fPFParticleProducerLabel = pset.get<std::string>(
"PFParticleProducerLabel");
 
  115   fTrackProducerLabels = pset.get<std::vector<std::string>>(
"TrackProducerLabels");
 
  116   fAssnProducerLabels = pset.get<std::vector<std::string>>(
"AssnProducerLabels");
 
  117   fCosmicTagThresholds = pset.get<std::vector<double>>(
"CosmicTagThresholds");
 
  118   fEndTickPadding = pset.get<
int>(
"EndTickPadding", 50);
 
  119   fMaxOutOfTime = pset.get<
int>(
"MaxOutOfTime", 4);
 
  127   mf::LogInfo(
"CRHitRemoval") << 
"CRHitRemoval configured\n";
 
  135   auto const* geo = lar::providerFrom<geo::Geometry>();
 
  136   auto const clock_data = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
 
  138     art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataForJob(clock_data);
 
  141   float const driftVelocity = detp.DriftVelocity(detp.Efield(), detp.Temperature()); 
 
  145     clock_data.Time2Tick(clock_data.TriggerTime()); 
 
  168   art::Handle<std::vector<recob::Hit>> hitHandle;
 
  169   evt.getByLabel(fHitProducerLabel, hitHandle);
 
  172   if (!hitHandle.isValid()) 
return;
 
  177   art::FindOneP<recob::Wire> ChannelHitWires(hitHandle, evt, fHitProducerLabel);
 
  180   art::fill_ptr_vector(ChHits, hitHandle);
 
  189   art::Handle<std::vector<recob::PFParticle>> pfParticleHandle;
 
  190   evt.getByLabel(fPFParticleProducerLabel, pfParticleHandle);
 
  193   if (!pfParticleHandle.isValid()) {
 
  204   art::Handle<std::vector<recob::Cluster>> clusterHandle;
 
  205   evt.getByLabel(fPFParticleProducerLabel, clusterHandle);
 
  208   if (!clusterHandle.isValid()) {
 
  218   std::vector<art::Handle<std::vector<anab::CosmicTag>>> cosmicHandleVec;
 
  219   std::vector<std::map<int, std::vector<art::Ptr<recob::Track>>>> cosmicToTrackVecMapVec;
 
  220   std::vector<std::map<int, std::vector<art::Ptr<recob::PFParticle>>>> trackToPFParticleVecMapVec;
 
  221   std::vector<double> thresholdVec;
 
  226     art::Handle<std::vector<anab::CosmicTag>> cosmicHandle;
 
  227     evt.getByLabel(handleLabel, cosmicHandle);
 
  229     if (cosmicHandle.isValid()) {
 
  231       art::FindManyP<recob::Track> cosmicTrackAssns(cosmicHandle, evt, handleLabel);
 
  234       art::Handle<std::vector<recob::Track>> trackHandle;
 
  235       evt.getByLabel(fTrackProducerLabels[idx], trackHandle);
 
  238       if (trackHandle.isValid()) {
 
  239         std::map<int, std::vector<art::Ptr<recob::Track>>> cosmicToTrackVecMap;
 
  240         std::map<int, std::vector<art::Ptr<recob::PFParticle>>> trackToPFParticleVecMap;
 
  243         for (
size_t cosmicIdx = 0; cosmicIdx < cosmicHandle->size(); cosmicIdx++) {
 
  244           art::Ptr<anab::CosmicTag> cosmicTag(cosmicHandle, cosmicIdx);
 
  246           std::vector<art::Ptr<recob::Track>> cosmicToTrackVec =
 
  247             cosmicTrackAssns.at(cosmicTag.key());
 
  249           cosmicToTrackVecMap[cosmicTag.key()] = cosmicToTrackVec;
 
  251           art::FindManyP<recob::PFParticle> trackPFParticleAssns(
 
  252             trackHandle, evt, fAssnProducerLabels[idx]);
 
  254           for (
auto& 
track : cosmicToTrackVec) {
 
  255             std::vector<art::Ptr<recob::PFParticle>> trackToPFParticleVec =
 
  256               trackPFParticleAssns.at(
track.key());
 
  258             for (
auto& pfParticle : trackToPFParticleVec)
 
  259               trackToPFParticleVecMap[
track.key()].push_back(pfParticle);
 
  264         cosmicHandleVec.emplace_back(cosmicHandle);
 
  265         cosmicToTrackVecMapVec.emplace_back(cosmicToTrackVecMap);
 
  266         trackToPFParticleVecMapVec.emplace_back(trackToPFParticleVecMap);
 
  267         thresholdVec.push_back(fCosmicTagThresholds[idx]);
 
  273   if (cosmicHandleVec.empty()) {
 
  285   art::FindManyP<recob::Cluster> clusterAssns(pfParticleHandle, evt, fPFParticleProducerLabel);
 
  288   art::FindManyP<recob::Hit> clusterHitAssns(clusterHandle, evt, fPFParticleProducerLabel);
 
  291   std::set<const recob::PFParticle*> taggedSet;
 
  295   for (
size_t idx = 0; idx != cosmicHandleVec.size(); idx++) {
 
  297     const art::Handle<std::vector<anab::CosmicTag>>& cosmicHandle(cosmicHandleVec[idx]);
 
  298     const std::map<int, std::vector<art::Ptr<recob::Track>>>& crTagTrackVec(
 
  299       cosmicToTrackVecMapVec[idx]);
 
  300     const std::map<int, std::vector<art::Ptr<recob::PFParticle>>>& trackToPFParticleVecMap(
 
  301       trackToPFParticleVecMapVec[idx]);
 
  303     for (
size_t crIdx = 0; crIdx != cosmicHandle->size(); crIdx++) {
 
  304       art::Ptr<anab::CosmicTag> cosmicTag(cosmicHandle, crIdx);
 
  307       if (cosmicTag->CosmicScore() > thresholdVec[idx]) {
 
  309         std::vector<art::Ptr<recob::Track>> trackVec(crTagTrackVec.at(cosmicTag.key()));
 
  312         for (
const auto& 
track : trackVec) {
 
  313           std::map<int, std::vector<art::Ptr<recob::PFParticle>>>::const_iterator
 
  314             trackToPFParticleVecItr = trackToPFParticleVecMap.find(
track.key());
 
  316           if (trackToPFParticleVecItr != trackToPFParticleVecMap.end()) {
 
  318             for (
const auto& pfParticlePtr : trackToPFParticleVecItr->second) {
 
  325                   art::Ptr<recob::PFParticle>(pfParticleHandle, pfParticle->
Parent()).
get();
 
  328               taggedSet.insert(pfParticle);
 
  337   if (!taggedSet.empty()) {
 
  352     for (
const auto& pfParticle : *pfParticleHandle) {
 
  354       if (!pfParticle.IsPrimary()) 
continue;
 
  366       if (taggedSet.find(&pfParticle) != taggedSet.end()) goodHits = 
false;
 
  371         for (
const auto& 
hit : tempHits) {
 
  376           if (nOutOfTime > fMaxOutOfTime) {
 
  384         std::copy(tempHits.begin(), tempHits.end(), std::back_inserter(untaggedHits));
 
  386         std::copy(tempHits.begin(), tempHits.end(), std::back_inserter(taggedHits));
 
  421   const art::Handle<std::vector<recob::PFParticle>>& pfParticleHandle,
 
  422   const art::FindManyP<recob::Cluster>& partToClusAssns,
 
  423   const art::FindManyP<recob::Hit>& clusToHitAssns,
 
  427   std::vector<art::Ptr<recob::Cluster>> clusterVec = partToClusAssns.at(pfParticle->
Self());
 
  433   for (
const auto& 
cluster : clusterVec) {
 
  434     std::vector<art::Ptr<recob::Hit>> clusHitVec = clusToHitAssns.at(
cluster.key());
 
  435     hitVec.insert(hitVec.end(), clusHitVec.begin(), clusHitVec.end());
 
  437     int minHitTick = (*std::min_element(clusHitVec.begin(),
 
  439                                         [](
const auto& 
hit, 
const auto& min) {
 
  440                                           return hit->PeakTimeMinusRMS() < min->PeakTimeMinusRMS();
 
  442                        ->PeakTimeMinusRMS();
 
  443     int maxHitTick = (*std::max_element(clusHitVec.begin(),
 
  445                                         [](
const auto& 
hit, 
const auto& max) {
 
  446                                           return hit->PeakTimePlusRMS() > max->PeakTimePlusRMS();
 
  450     if (minHitTick < minTick) minTick = minHitTick;
 
  451     if (maxHitTick < maxTick) maxTick = maxHitTick;
 
  455   for (
const auto& daughterId : pfParticle->
Daughters()) {
 
  456     art::Ptr<recob::PFParticle> daughter(pfParticleHandle, daughterId);
 
  459       daughter.get(), pfParticleHandle, partToClusAssns, clusToHitAssns, hitVec);
 
  467                           art::FindOneP<recob::Wire>& wireAssns,
 
  470   for (
const auto& hitPtr : inputHits) {
 
  471     art::Ptr<recob::Wire> wire = wireAssns.at(hitPtr.key());
 
  482                              art::FindOneP<recob::Wire>& wireAssns,
 
  485   for (
const auto& hitPtr : inputHits) {
 
  490     art::Ptr<recob::Wire> wire = wireAssns.at(hitPtr.key());
 
  511   if (used_hits.size() > 0) {
 
  513     std::stable_sort(hits.begin(), hits.end());
 
  514     std::stable_sort(used_hits.begin(), used_hits.end());
 
  517     std::vector<art::Ptr<recob::Hit>>::iterator it = std::set_difference(
 
  518       hits.begin(), hits.end(), used_hits.begin(), used_hits.end(), hits.begin());
 
  521     hits.erase(it, hits.end());
 
  532   mf::LogInfo(
"CRHitRemoval") << 
"CRHitRemoval statistics:\n" 
  533                               << 
"  Number of events = " << 
fNumEvent << 
"\n" 
  534                               << 
"  Number of Cosmic Rays found = " << 
fNumCRRejects << 
", " 
  535                               << 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. 
Declaration of signal hit object. 
int fEndTickPadding
Padding the end tick. 
void copyAllHits(std::vector< art::Ptr< recob::Hit >> &, art::FindOneP< recob::Wire > &, recob::HitCollectionCreator &)
process_name use argoneut_mc_hitfinder track
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. 
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. 
std::vector< art::Ptr< recob::Hit >> HitPtrVector
std::string fHitProducerLabel
The full collection of hits. 
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. 
Declaration of cluster object. 
Provides recob::Track data product. 
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. 
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. 
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock. 
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.