Skip to content

Commit f42c6be

Browse files
author
Mun Jung Jung
committed
choppy event filter
1 parent 186b4bf commit f42c6be

3 files changed

Lines changed: 282 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# cet_build_plugin(FlagChoppy art::module
2+
# lardataobj::RecoBase
3+
# ROOT::Core
4+
# ROOT::Tree
5+
# art::Framework_Core
6+
# art::Framework_Principal
7+
# art::Utilities
8+
# art_root_io::tfile_support
9+
# art_root_io::TFileService_service
10+
# canvas::canvas
11+
# fhiclcpp::fhiclcpp
12+
# cetlib::cetlib
13+
# cetlib_except::cetlib_except
14+
# messagefacility::MF_MessageLogger
15+
# lardataobj::RawData
16+
# larcore::Geometry_Geometry_service
17+
# fhiclcpp::fhiclcpp
18+
# cetlib::cetlib
19+
# CLHEP::Random
20+
# ROOT::Geom
21+
# ROOT::XMLIO
22+
# ROOT::Gdml
23+
# ROOT::FFTW
24+
# )
25+
26+
cet_build_plugin(FilterChoppy art::module
27+
lardataobj::RecoBase
28+
ROOT::Core
29+
ROOT::Tree
30+
art::Framework_Core
31+
art::Framework_Principal
32+
art::Utilities
33+
art_root_io::tfile_support
34+
art_root_io::TFileService_service
35+
canvas::canvas
36+
fhiclcpp::fhiclcpp
37+
cetlib::cetlib
38+
cetlib_except::cetlib_except
39+
messagefacility::MF_MessageLogger
40+
lardataobj::RawData
41+
larcore::Geometry_Geometry_service
42+
fhiclcpp::fhiclcpp
43+
cetlib::cetlib
44+
CLHEP::Random
45+
ROOT::Geom
46+
ROOT::XMLIO
47+
ROOT::Gdml
48+
ROOT::FFTW
49+
)
50+
51+
install_headers()
52+
install_source()
53+
install_fhicl()
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
#include <iostream>
2+
#include <stdlib.h>
3+
#include <string>
4+
#include <vector>
5+
#include <numeric>
6+
#include <getopt.h>
7+
#include <chrono>
8+
#include <float.h>
9+
10+
11+
//some ROOT includes
12+
#include "TInterpreter.h"
13+
#include "TROOT.h"
14+
#include "TH1F.h"
15+
#include "TH2D.h"
16+
#include "TCanvas.h"
17+
#include "TTree.h"
18+
#include "TFile.h"
19+
#include "TStyle.h"
20+
#include "TSystem.h"
21+
#include "TGraph.h"
22+
#include "TFFTReal.h"
23+
#include "TTimeStamp.h"
24+
#include "TLatex.h"
25+
#include "TLine.h"
26+
27+
28+
// art includes
29+
#include "canvas/Utilities/InputTag.h"
30+
#include "canvas/Persistency/Common/FindOneP.h"
31+
#include "canvas/Persistency/Common/FindManyP.h"
32+
#include "canvas/Persistency/Common/Ptr.h"
33+
#include "art/Framework/Core/EDFilter.h"
34+
#include "art/Framework/Core/ModuleMacros.h"
35+
#include "art/Framework/Principal/Event.h"
36+
#include "art/Framework/Principal/Handle.h"
37+
#include "art/Framework/Principal/Run.h"
38+
#include "art/Framework/Principal/SubRun.h"
39+
#include "fhiclcpp/ParameterSet.h"
40+
#include "messagefacility/MessageLogger/MessageLogger.h"
41+
#include "lardataobj/RecoBase/Hit.h"
42+
#include "fhiclcpp/ParameterSet.h"
43+
#include "lardataobj/RawData/RawDigit.h"
44+
#include "lardataobj/RawData/RDTimeStamp.h"
45+
#include "lardataobj/RawData/raw.h"
46+
#include "larcore/Geometry/Geometry.h"
47+
#include "canvas/Persistency/Provenance/Timestamp.h"
48+
49+
#include "art_root_io/TFileService.h"
50+
51+
#include "sbndcode/ChannelMaps/TPC/TPCChannelMapService.h"
52+
53+
54+
namespace filt{
55+
56+
class FilterChoppy : public art::EDFilter {
57+
public:
58+
59+
explicit FilterChoppy(fhicl::ParameterSet const & pset);
60+
virtual bool filter(art::Event& evt) override;
61+
void reconfigure(fhicl::ParameterSet const& pset);
62+
virtual void beginJob() override;
63+
64+
std::vector<art::Ptr<raw::RDTimeStamp>> raw_timestamps_handle;
65+
66+
private:
67+
68+
int run;
69+
int subrun;
70+
int event;
71+
long delta_tmaxmin;
72+
std::vector<long> ts_vec;
73+
std::vector<long> ts_hist_vec;
74+
int npeak;
75+
76+
};
77+
78+
79+
FilterChoppy::FilterChoppy(fhicl::ParameterSet const & pset)
80+
: EDFilter(pset)
81+
{
82+
this->reconfigure(pset);
83+
}
84+
85+
void FilterChoppy::reconfigure(fhicl::ParameterSet const& pset){
86+
}
87+
88+
89+
bool FilterChoppy::filter(art::Event & evt){
90+
91+
raw_timestamps_handle.clear();
92+
run = evt.id().run();
93+
subrun = evt.id().subRun();
94+
event = evt.id().event();
95+
96+
ts_vec.clear();
97+
ts_hist_vec.clear();
98+
npeak = 0;
99+
delta_tmaxmin = 0;
100+
101+
102+
// get the timestamps
103+
art::Handle<std::vector<raw::RDTimeStamp>> timestamp_handle;
104+
evt.getByLabel("daq", timestamp_handle);
105+
106+
// exit if the data isn't present
107+
if (!timestamp_handle.isValid()) {
108+
std::cerr << "Error: missing timestamps with producer (" << "daq" << ")" << std::endl;
109+
return false;
110+
}
111+
art::fill_ptr_vector(raw_timestamps_handle, timestamp_handle);
112+
113+
114+
// analyze timestamp distributions
115+
// collect timestamps
116+
unsigned timeindex = 0;
117+
for (auto const& timestamps: raw_timestamps_handle) {
118+
long this_ts = timestamps->GetTimeStamp();
119+
ts_vec.push_back(this_ts);
120+
timeindex++;
121+
}
122+
// make binned hist
123+
long ts_min = ts_vec[0];
124+
long ts_max = ts_vec[0];
125+
for (long ts : ts_vec) {
126+
if (ts < ts_min) {
127+
ts_min = ts;
128+
}
129+
if (ts > ts_max) {
130+
ts_max = ts;
131+
}
132+
}
133+
delta_tmaxmin = std::abs(ts_max - ts_min);
134+
135+
float nbin = 100.;
136+
float bin_width = (ts_max - ts_min)/nbin;
137+
for (int i = 0; i < 100; ++i) {
138+
float bin_low = ts_min + i*bin_width;
139+
float bin_high = ts_min + (i+1)*bin_width;
140+
int bin_count = 0;
141+
for (long ts : ts_vec) {
142+
if ((bin_low < ts) & (ts <= bin_high)) {
143+
bin_count += 1;
144+
}
145+
}
146+
ts_hist_vec.push_back(bin_count);
147+
}
148+
// find peak bins
149+
for (int bc : ts_hist_vec) {
150+
//TODO: make threshold fcl parameter
151+
if (bc > 1000) {
152+
npeak += 1;
153+
}
154+
}
155+
156+
// If the energy deposit within the beam time is greater than some limit then trigger the event
157+
if (npeak > 1){
158+
std::cout << "Event " << event << " has " << npeak << " peaks" << std::endl;
159+
}
160+
if (delta_tmaxmin > 100000){
161+
std::cout << "Event " << event << " has a delta_tmaxmin of " << delta_tmaxmin << std::endl;
162+
}
163+
//return npeak < 2;
164+
return delta_tmaxmin < 100000;
165+
166+
}
167+
168+
169+
void FilterChoppy::beginJob() {
170+
}
171+
172+
DEFINE_ART_MODULE(FilterChoppy)
173+
174+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include "services_sbnd.fcl"
2+
#include "TPCChannelMapService.fcl"
3+
4+
process_name: FilterChoppy
5+
6+
services:
7+
{
8+
TFileService: { fileName: "reco_hist.root"}
9+
MemoryTracker: {}
10+
TimeTracker: {}
11+
RandomNumberGenerator: {}
12+
message: @local::sbnd_message_services_prod_debug
13+
FileCatalogMetadata: @local::art_file_catalog_mc
14+
TPCChannelMapService: @local::SBNDTPCChannelMapServiceDefaults
15+
AuxDetExptGeoHelperInterface: { service_provider: "sbndcode/CRT/CRTGeometryHelper" }
16+
ExptGeoHelperInterface: @local::sbnd_geometry_helper
17+
Geometry: @local::sbnd_geo
18+
GeometryConfigurationWriter: {}
19+
@table::sbnd_basic_services
20+
@table::sbnd_random_services
21+
}
22+
23+
source:
24+
{
25+
module_type: RootInput
26+
maxEvents: -1
27+
}
28+
29+
outputs:
30+
{
31+
out1:
32+
{
33+
module_type: RootOutput
34+
fileName: "%ifb_filtered.root"
35+
dataTier: "filtered"
36+
fastCloning: true
37+
SelectEvents: [ filter ]
38+
}
39+
}
40+
41+
physics:
42+
{
43+
filters:
44+
{
45+
filterchoppy: {
46+
module_type: FilterChoppy
47+
}
48+
}
49+
50+
filter: [ filterchoppy ]
51+
stream1: [ out1 ]
52+
trigger_paths: [ filter ]
53+
end_paths: [ stream1 ]
54+
}
55+

0 commit comments

Comments
 (0)