Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
dunedataprep
dunedataprep
DataPrep
Service
MedianPedestalService_service.cc
Go to the documentation of this file.
1
// MedianPedestalService_service.cc
2
3
#include "
MedianPedestalService.h
"
4
#include <iostream>
5
#include <sstream>
6
#include <iomanip>
7
#include "
art/Framework/Services/Registry/ServiceHandle.h
"
8
#include "
art/Framework/Services/Registry/ServiceDefinitionMacros.h
"
9
10
using
std::vector
;
11
using
std::string
;
12
using
std::ostream;
13
using
std::cout;
14
using
std::endl
;
15
using
std::ostringstream;
16
using
std::setw
;
17
using
art::ServiceHandle
;
18
19
//**********************************************************************
20
21
MedianPedestalService::
22
MedianPedestalService
(
fhicl::ParameterSet
const
& pset,
art::ActivityRegistry
&)
23
: m_LogLevel(1),
24
m_SkipFlaggedSamples(false),
25
m_SkipSignals(false) {
26
const
string
myname =
"MedianPedestalService::ctor: "
;
27
pset.
get_if_present
<
int
>(
"LogLevel"
,
m_LogLevel
);
28
m_UseMean
= pset.
get
<
bool
>(
"UseMean"
);
29
m_SkipFlaggedSamples
= pset.
get
<
bool
>(
"SkipFlaggedSamples"
);
30
m_SkipSignals
= pset.
get
<
bool
>(
"SkipSignals"
);
31
print
(cout, myname);
32
}
33
34
//**********************************************************************
35
36
int
MedianPedestalService::
37
evaluate
(
const
AdcChannelData
&
data
,
AdcSignal
* pped,
AdcSignal
* prms,
38
AdcSignal
* ppederr,
AdcSignal
* prmserr)
const
{
39
const
string
myname =
"MedianPedestalService::evaluate: "
;
40
AdcSignal
ped = 0.0;
41
AdcSignal
rms
= 0.0;
42
AdcSignal
pederr = 0.0;
43
AdcSignal
rmserr = 0.0;
44
const
AdcSignalVector
sigsin = data.
samples
;
45
const
AdcFlagVector
flags = data.
flags
;
46
const
AdcFilterVector
signal = data.
signal
;
47
if
( sigsin.size() == 0 )
return
0;
48
AdcSignalVector
sigs;
49
unsigned
int
nsig = sigsin.size();
50
double
sigsum = 0.0;
51
unsigned
int
nsigout = 0;
52
for
(
unsigned
int
isig=0; isig<nsig; ++isig ) {
53
AdcSignal
sig = sigsin[isig];
54
if
(
m_SkipFlaggedSamples
&& flags.size() ) {
55
AdcFlag
flag = flags[isig];
56
bool
skip = flag !=
AdcGood
;
57
if
( skip )
continue
;
58
}
59
if
(
m_SkipSignals
&& signal.size() ) {
60
bool
isSignal = signal[isig];
61
if
( isSignal )
continue
;
62
}
63
if
(
m_UseMean
) sigsum += sig;
64
else
sigs.push_back(sig);
65
++nsigout;
66
}
67
if
( nsigout ) {
68
if
(
m_UseMean
) {
69
ped = sigsum/nsigout;
70
}
else
{
71
sort(sigs.begin(), sigs.end());
72
unsigned
int
isig = sigs.size()/2;
73
bool
isodd = sigs.size()%2;
74
ped = isodd ? sigs[isig-1] : 0.5*(sigs[isig-1] + sigs[isig]);
75
}
76
}
77
if
( pped !=
nullptr
) *pped = ped;
78
if
( prms !=
nullptr
) *prms =
rms
;
79
if
( ppederr !=
nullptr
) *ppederr = pederr;
80
if
( prmserr !=
nullptr
) *prmserr = rmserr;
81
return
0;
82
}
83
84
//**********************************************************************
85
86
ostream&
MedianPedestalService::
87
print
(ostream& out,
string
prefix
)
const
{
88
out << prefix <<
"MedianPedestalService:"
<<
endl
;
89
out << prefix <<
" LogLevel: "
<<
m_LogLevel
<<
endl
;
90
out << prefix <<
" SkipFlaggedSamples: "
<<
m_SkipFlaggedSamples
<<
endl
;
91
out << prefix <<
" SkipSignals: "
<<
m_SkipSignals
<<
endl
;
92
return
out;
93
}
94
95
//**********************************************************************
96
97
DEFINE_ART_SERVICE_INTERFACE_IMPL
(
MedianPedestalService
,
PedestalEvaluationService
)
98
99
//**********************************************************************
art::ServiceHandle
Definition:
ServiceHandle.h:37
AdcFlag
short AdcFlag
Definition:
AdcTypes.h:29
cet::sqlite::rms
double rms(sqlite3 *db, std::string const &table_name, std::string const &column_name)
Definition:
statistics.cc:40
submit_ppfxjobs.prefix
string prefix
Definition:
submit_ppfxjobs.py:128
string
std::string string
Definition:
nybbler.cc:12
AdcSignal
float AdcSignal
Definition:
AdcTypes.h:21
MedianPedestalService::m_UseMean
bool m_UseMean
Definition:
MedianPedestalService.h:46
AdcFlagVector
std::vector< AdcFlag > AdcFlagVector
Definition:
AdcTypes.h:30
vector
struct vector vector
AdcChannelData
Definition:
AdcChannelData.h:95
MedianPedestalService::evaluate
int evaluate(const AdcChannelData &data, AdcSignal *pped=nullptr, AdcSignal *prms=nullptr, AdcSignal *ppederr=nullptr, AdcSignal *prmserr=nullptr) const
Definition:
MedianPedestalService_service.cc:37
AdcGood
const AdcFlag AdcGood
Definition:
AdcTypes.h:32
ServiceHandle.h
PedestalEvaluationService
Definition:
PedestalEvaluationService.h:15
MedianPedestalService::MedianPedestalService
MedianPedestalService(fhicl::ParameterSet const &pset, art::ActivityRegistry &)
Definition:
MedianPedestalService_service.cc:22
fhicl::ParameterSet::get
T get(std::string const &key) const
Definition:
ParameterSet.h:271
MedianPedestalService::m_SkipSignals
bool m_SkipSignals
Definition:
MedianPedestalService.h:48
setw
Q_EXPORT QTSManip setw(int w)
Definition:
qtextstream.h:331
make_THn_beam_input.data
data
Definition:
make_THn_beam_input.py:80
MedianPedestalService::print
std::ostream & print(std::ostream &out=std::cout, std::string prefix="") const
Definition:
MedianPedestalService_service.cc:87
AdcChannelData::signal
AdcFilterVector signal
Definition:
AdcChannelData.h:136
AdcFilterVector
std::vector< bool > AdcFilterVector
Definition:
AdcTypes.h:27
art::ActivityRegistry
Definition:
ActivityRegistry.h:52
fhicl::ParameterSet::get_if_present
std::optional< T > get_if_present(std::string const &key) const
Definition:
ParameterSet.h:224
MedianPedestalService
Definition:
MedianPedestalService.h:30
ServiceDefinitionMacros.h
AdcSignalVector
std::vector< AdcSignal > AdcSignalVector
Definition:
AdcTypes.h:22
MedianPedestalService::m_SkipFlaggedSamples
bool m_SkipFlaggedSamples
Definition:
MedianPedestalService.h:47
MedianPedestalService.h
AdcChannelData::samples
AdcSignalVector samples
Definition:
AdcChannelData.h:131
endl
QTextStream & endl(QTextStream &s)
Definition:
qtextstream.cpp:2030
MedianPedestalService::m_LogLevel
int m_LogLevel
Definition:
MedianPedestalService.h:45
AdcChannelData::flags
AdcFlagVector flags
Definition:
AdcChannelData.h:135
fhicl::ParameterSet
Definition:
ParameterSet.h:36
DEFINE_ART_SERVICE_INTERFACE_IMPL
#define DEFINE_ART_SERVICE_INTERFACE_IMPL(svc, iface)
Definition:
ServiceDefinitionMacros.h:42
Generated by
1.8.11