21 : m_LogLevel(ps.
get<
int>(
"LogLevel")),
22 m_Weight(ps.
get<
Name>(
"Weight")),
25 const string myname =
"CnrGroupWeighted::ctor: ";
30 else cout << myname <<
"WARNING: Ignoring invalid option: " << sopt <<
endl;
33 string crtName =
"channelGroups";
38 if ( pcrt !=
nullptr ) grp = pcrt->
get(sgrp);
43 cout << myname <<
"WARNING: Unable to find range group " << sgrp <<
endl;
53 cout << myname <<
" Groups: [";
55 for (
Name nam : m_Groups ) {
56 if ( count && count%10 == 0 ) cout <<
"\n ";
57 if ( count++ ) cout <<
", ";
61 cout << myname <<
" Options: [";
63 for (
Name nam : m_Options ) {
64 if ( count++ ) cout <<
", ";
68 cout << myname <<
"Using " << (
m_useMedian ?
"median" :
"mean") <<
" correction." << endl;
69 cout << myname <<
"Using " << (
m_dropSignal ?
"all" :
"non-signal") <<
" samples." << endl;
70 cout << myname << (
m_requireGoodChannel ?
"R" :
"Not r") <<
"equiring good channel status." << endl;
71 cout << myname <<
" Group #chan" <<
endl;
72 for (
const auto& ient :
m_chg ) {
73 cout << myname <<
setw(10) << ient.first <<
setw(8) << ient.second.size() <<
endl;
81 const string myname =
"CnrGroupWeighted::updateMap: ";
83 if ( acds.size() == 0 ) {
84 std::cout << myname <<
"WARNING: No channels found." <<
std::endl;
92 std::vector<float> correction =
getCorrection(channels, acds, wts);
93 for (
Index ich : channels) {
94 auto iacd = acds.find(ich);
95 if ( iacd == acds.end() )
continue;
97 if ( acd.
samples.size() == 0 )
continue;
98 if ( acd.
samples.size() > correction.size() ) correction.resize(acd.
samples.size(), 0.);
99 for (
size_t isam=0; isam<acd.
samples.size(); ++isam) {
100 acd.
samples[isam] -= wts[ich]*correction[isam];
112 const string myname =
"CnrGroupWeighted::getWeights: ";
113 for (
Index ich : channels ) {
117 auto iacd = acds.find(ich);
118 if ( iacd == acds.end() )
continue;
124 cout << myname <<
"WARNING: Channel " << ich <<
" does not have attribute " 138 const string myname =
"CnrGroupWeighted::getCorrection: ";
140 std::vector<FloatVector> wsamples;
141 for (
Index ich : channels ) {
142 if ( wts.count(ich) == 0 )
continue;
143 float wt = wts.find(ich)->second;
144 auto iacd = acds.find(ich);
145 if ( iacd == acds.end() )
continue;
148 if ( acd.
samples.size() > nsam ) {
150 wsamples.resize(nsam);
152 for (
size_t isam=0; isam<acd.
samples.size(); ++isam ) {
154 if ( wt == 0 )
continue;
155 wsamples[isam].push_back(acd.
samples[isam]/wt);
158 std::vector<float> correction(nsam, 0.0);
160 for (
Index isam=0; isam<nsam; ++isam ) {
161 size_t nval = wsamples[isam].size();
162 if ( nval < 2 )
continue;
164 std::sort(wsamples[isam].
begin(), wsamples[isam].
end());
165 if ( nval%2 == 0 ) correction[isam] = 0.5 * (wsamples[isam][nval/2-1] + wsamples[isam][nval/2]);
166 else correction[isam] = wsamples[isam][nval/2];
169 for (
float val : wsamples[isam] ) sum +=
val;
170 correction[isam] = sum/
float(wsamples[isam].
size());
174 if (
m_LogLevel >= 2 ) cout << myname <<
"Correcting " << nsamCor <<
"/" << nsam <<
" samples." <<
endl;
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
std::vector< Name > NameVector
FloatVector getCorrection(const IndexVector &channels, const AdcChannelDataMap &acds, const FloatMap &wts) const
DataMap & setStatus(int stat)
float getAttribute(Name mname, float def=0.0) const
std::vector< float > FloatVector
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
bool m_requireGoodChannel
static constexpr double ps
bool hasAttribute(Name mname, float def=0.0) const
void getWeights(const IndexVector &channels, const AdcChannelDataMap &acds, FloatMap &wts) const
CnrGroupWeighted(fhicl::ParameterSet const &ps)
Q_EXPORT QTSManip setw(int w)
Index channelStatus() const
DataMap updateMap(AdcChannelDataMap &acds) const override
std::map< Index, float > FloatMap
std::vector< Index > IndexVector
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
auto const & get(AssnsNode< L, R, D > const &r)
void getIndices(IndexVector &idxs) const
QTextStream & endl(QTextStream &s)