Skip to content

Commit d7f7a1b

Browse files
Merge branch 'develop' into dbrailsf_fclreorgbugfix
2 parents 207446f + 866169c commit d7f7a1b

7 files changed

Lines changed: 159 additions & 2 deletions

File tree

sbndcode/Filters/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ cet_build_plugin(GenNuFilter art::module SOURCE GenNuFilter_module.cc LIBRARIES
3737
cet_build_plugin(LArG4CRTFilter art::module SOURCE LArG4CRTFilter_module.cc LIBRARIES ${MODULE_LIBRARIES})
3838
cet_build_plugin(LArG4FakeTriggerFilter art::module SOURCE LArG4FakeTriggerFilter_module.cc LIBRARIES ${MODULE_LIBRARIES})
3939
cet_build_plugin(SimEnergyDepFakeTriggerFilter art::module SOURCE SimEnergyDepFakeTriggerFilter_module.cc LIBRARIES ${MODULE_LIBRARIES})
40+
cet_build_plugin(NumberOfHitsFilter art::module SOURCE NumberOfHitsFilter_module.cc LIBRARIES ${MODULE_LIBRARIES})
4041

4142
install_headers()
4243
install_fhicl()
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+
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: 50000
10+
ScaleThresholdForReadoutWindow: true
11+
Verbose: false
12+
}
13+
14+
END_PROLOG

sbndcode/JobConfigurations/standard/reco/config/workflow_reco1.fcl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "crtrecoproducers_sbnd.fcl"
99
#include "mlreco_sbnd.fcl"
1010
#include "cluster_sbnd.fcl"
11+
#include "numberofhitsfilter_sbnd.fcl"
1112
#include "mctrutht0matching.fcl"
1213

1314
BEGIN_PROLOG
@@ -72,6 +73,11 @@ sbnd_reco1_producers.gaushit.CalDataModuleLabel:
7273
sbnd_reco1_producers.fasthit.DigitModuleLabel: "simtpc2d:daq"
7374
sbnd_reco1_producers.gaushitTruthMatch.HitParticleAssociations.HitModuleLabel: "gaushit"
7475

76+
sbnd_reco1_filters: {
77+
#filter events based on the number of reconstructed hits (avoids overly messy data events)
78+
numberofhitsfilter: @local::sbnd_numberofhitsfilter
79+
}
80+
7581
sbnd_reco1_analyzers: {
7682
#supera for ML reco
7783
supera: @local::sbnd_supera

sbndcode/JobConfigurations/standard/reco/reco1_data.fcl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ physics.producers:
1818
crtstrips: @local::crtstriphitproducer_data_sbnd
1919
}
2020

21-
physics.reco1: [sptpc2d, gaushit, cluster3d, crtstrips]
21+
physics.reco1: [sptpc2d, gaushit, numberofhitsfilter, cluster3d, crtstrips]
2222
physics.ana: [superadata]
23+
24+
outputs.out1.SelectEvents: [ "reco1" ]
25+
2326
physics.producers.gaushit.CalDataModuleLabel: "sptpc2d:gauss"
24-
physics.end_paths: ["stream1",ana]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "reco1_data.fcl"
2+
3+
physics.analyzers.superadata.SelectEvents: [ "reco1" ]
4+
5+
outputs.out2: @local::outputs.out1
6+
outputs.out2.SelectEvents: [ "!reco1" ]
7+
outputs.out2.fileName: "nhitsfilteredevents_%ifb_%p-%tc.root"
8+
physics.stream2: [ out2 ]
9+
physics.end_paths: [ @sequence::physics.end_paths, stream2]

sbndcode/JobConfigurations/standard/standard_reco1_sbnd.fcl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ services:
2424
physics.producers: @local::sbnd_reco1_producers
2525
physics.reco1: @local::sbnd_reco1_producer_sequence
2626
physics.trigger_paths: [ reco1 ]
27+
#filters
28+
physics.filters: @local::sbnd_reco1_filters
29+
#don't add a sequence here, because the only filter is currently for data
2730
#analysers
2831
physics.analyzers: @local::sbnd_reco1_analyzers
2932
physics.ana: @local::sbnd_reco1_analyzer_sequence

0 commit comments

Comments
 (0)