Skip to content

Commit 51c112f

Browse files
committed
Port ProtoDUNE's hit filter to sbnd
1 parent fd10e7e commit 51c112f

2 files changed

Lines changed: 136 additions & 0 deletions

File tree

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
////////////////////////////////////////////////////////////////////////
2+
//
3+
// Port of ProtoDUNE's hit count filter
4+
// Very simple module to filter out events with too many hits
5+
// - Designed to prevent jobs hanging on very large events
6+
//
7+
// Orginially by Leigh Whitehead - leigh.howard.whitehead@cern.ch
8+
//
9+
////////////////////////////////////////////////////////////////////////
10+
11+
// Framework includes
12+
#include "art/Framework/Core/EDFilter.h"
13+
#include "art/Framework/Principal/Event.h"
14+
#include "art/Framework/Principal/Run.h"
15+
#include "art/Framework/Principal/Handle.h"
16+
#include "art/Framework/Services/Registry/ServiceHandle.h"
17+
#include "art_root_io/TFileService.h"
18+
#include "art/Framework/Core/ModuleMacros.h"
19+
#include "art/Framework/Services/Registry/ActivityRegistry.h"
20+
#include "messagefacility/MessageLogger/MessageLogger.h"
21+
#include "fhiclcpp/ParameterSet.h"
22+
23+
#include "lardataobj/RecoBase/Hit.h"
24+
#include "lardata/DetectorInfoServices/DetectorPropertiesService.h"
25+
26+
namespace hit{
27+
class NumberOfHitsFilter;
28+
}
29+
30+
class hit::NumberOfHitsFilter : public art::EDFilter{
31+
public:
32+
33+
explicit NumberOfHitsFilter(fhicl::ParameterSet const& pset);
34+
virtual ~NumberOfHitsFilter();
35+
36+
void beginJob() override;
37+
bool filter(art::Event& evt) override;
38+
bool beginRun(art::Run& r) override;
39+
void endJob() override;
40+
41+
private:
42+
43+
bool fLimitPerTPC;
44+
unsigned int fHitLimit;
45+
std::string fHitModule;
46+
bool fScaleThresholdForReadoutWindow;
47+
bool fVerbose;
48+
};
49+
50+
//-----------------------------------------------------------------------
51+
hit::NumberOfHitsFilter::NumberOfHitsFilter(fhicl::ParameterSet const& pset):
52+
EDFilter(pset)
53+
{
54+
70G fLimitPerTPC = pset.get<bool>("LimitPerTPC");
55+
fHitLimit = pset.get<unsigned int>("HitLimit");
56+
fHitModule = pset.get<std::string>("HitModule");
57+
fVerbose = pset.get<bool>("Verbose");
58+
fScaleThresholdForReadoutWindow = pset.get<bool>("ScaleThresholdForReadoutWindow");
59+
}
60+
61+
//-----------------------------------------------------------------------
62+
hit::NumberOfHitsFilter::~NumberOfHitsFilter(){}
63+
64+
//-----------------------------------------------------------------------
65+
void hit::NumberOfHitsFilter::beginJob() {}
66+
//-----------------------------------------------------------------------
67+
bool hit::NumberOfHitsFilter::beginRun(art::Run& r){
68+
if (fScaleThresholdForReadoutWindow){
69+
unsigned int fSize = art::ServiceHandle<detinfo::DetectorPropertiesService const>{}->DataForJob().ReadOutWindowSize();
70+
fHitLimit = (unsigned int)(fHitLimit*fSize/3400.); //tuned to the nominal window size for SBND
71+
std::cout<<"Scale HitLimit based on readout window size "<<fSize<<std::endl;
72+
std::cout<<"HitLimit = "<<fHitLimit<<std::endl;
73+
}
74+
return true;
75+
}
76+
//-----------------------------------------------------------------------
77+
bool hit::NumberOfHitsFilter::filter(art::Event& evt){
78+
79+
// Get the hit collection from the event
80+
auto allHits = evt.getValidHandle<std::vector<recob::Hit> >(fHitModule);
81+
82+
bool result = true;
83+
84+
if(fLimitPerTPC){
85+
// Find the number of hits per TPC and then filter based on a large value
86+
std::map<unsigned int,unsigned int> hitsPerTPC;
87+
88+
for(auto const &hit : *allHits){
89+
hitsPerTPC[hit.WireID().TPC]++;
90+
}
91+
92+
for(auto const m: hitsPerTPC){
93+
94+
if (fVerbose) {
95+
std::cout << m.second << " hits in TPC " << m.first << std::endl;
96+
}
97+
98+
if(m.second > fHitLimit){
99+
result = false;
100+
break;
101+
}
102+
}
103+
}
104+
else{
105+
if (fVerbose) {
106+
std::cout << allHits->size() << " hits in all TPCs" << std::endl;
107+
}
108+
109+
110+
// This is the simplest thing we can do, just cut on the total number of hits
111+
if (allHits->size() > fHitLimit){
112+
result = false;
113+
}
114+
}
115+
116+
117+
return result;
118+
}
119+
120+
void hit::NumberOfHitsFilter::endJob() {}
121+
122+
DEFINE_ART_MODULE(hit::NumberOfHitsFilter)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
BEGIN_PROLOG
2+
3+
4+
sbnd_numberofhitsfilter:
5+
{
6+
module_type: "NumberOfHitsFilter"
7+
LimitPerTPC: true
8+
HitModule: "gaushit"
9+
HitLimit: 40000
10+
ScaleThresholdForReadoutWindow: true
11+
Verbose: false
12+
}
13+
14+
END_PROLOG

0 commit comments

Comments
 (0)