NumberOfHitsFilter_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Very simple module to filter out events with too many hits
4 // - Designed to prevent jobs hanging on very large events
5 //
6 // Leigh Whitehead - leigh.howard.whitehead@cern.ch
7 //
8 ////////////////////////////////////////////////////////////////////////
9 
10 // Framework includes
16 #include "art_root_io/TFileService.h"
20 #include "fhiclcpp/ParameterSet.h"
21 
24 
25 namespace hit{
26  class NumberOfHitsFilter;
27 }
28 
30 public:
31 
32  explicit NumberOfHitsFilter(fhicl::ParameterSet const& pset);
33  virtual ~NumberOfHitsFilter();
34 
35  void beginJob() override;
36  bool filter(art::Event& evt) override;
37  bool beginRun(art::Run& r) override;
38  void endJob() override;
39 
40 private:
41 
43  unsigned int fHitLimit;
46 };
47 
48 //-----------------------------------------------------------------------
50  EDFilter(pset)
51 {
52  fLimitPerTPC = pset.get<bool>("LimitPerTPC");
53  fHitLimit = pset.get<unsigned int>("HitLimit");
54  fHitModule = pset.get<std::string>("HitModule");
55  fScaleThresholdForReadoutWindow = pset.get<bool>("ScaleThresholdForReadoutWindow");
56 }
57 
58 //-----------------------------------------------------------------------
60 
61 //-----------------------------------------------------------------------
63 //-----------------------------------------------------------------------
66  unsigned int fSize = art::ServiceHandle<detinfo::DetectorPropertiesService const>{}->DataForJob().ReadOutWindowSize();
67  fHitLimit = (unsigned int)(fHitLimit*fSize/6000.);
68  std::cout<<"Scale HitLimit based on readout window size "<<fSize<<std::endl;
69  std::cout<<"HitLimit = "<<fHitLimit<<std::endl;
70  }
71  return true;
72 }
73 //-----------------------------------------------------------------------
75 
76  // Get the hit collection from the event
77  auto allHits = evt.getValidHandle<std::vector<recob::Hit> >(fHitModule);
78 
79  bool result = true;
80 
81  if(fLimitPerTPC){
82  // Find the number of hits per TPC and then filter based on a large value
83  std::map<unsigned int,unsigned int> hitsPerTPC;
84 
85  for(auto const hit : *allHits){
86  hitsPerTPC[hit.WireID().TPC]++;
87  }
88 
89  for(auto const m: hitsPerTPC){
90  if(m.second > fHitLimit){
91  result = false;
92  break;
93  }
94  }
95  }
96  else{
97  // This is the simplest thing we can do, just cut on the total number of hits
98  if (allHits->size() > fHitLimit){
99  result = false;
100  }
101  }
102 
103 
104  return result;
105 }
106 
108 
NumberOfHitsFilter(fhicl::ParameterSet const &pset)
static QCString result
std::string string
Definition: nybbler.cc:12
Definition: Run.h:17
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
bool beginRun(art::Run &r) override
T get(std::string const &key) const
Definition: ParameterSet.h:271
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
Detector simulation of raw signals on wires.
Declaration of signal hit object.
EDFilter(fhicl::ParameterSet const &pset)
Definition: EDFilter.h:21
bool filter(art::Event &evt) override
TCEvent evt
Definition: DataStructs.cxx:7
QTextStream & endl(QTextStream &s)