Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
CnrGroupWeighted Class Reference

#include <CnrGroupWeighted.h>

Inheritance diagram for CnrGroupWeighted:
TpcDataTool

Public Member Functions

 CnrGroupWeighted (fhicl::ParameterSet const &ps)
 
 ~CnrGroupWeighted () override=default
 
DataMap updateMap (AdcChannelDataMap &acds) const override
 

Private Types

using Name = std::string
 
using NameVector = std::vector< Name >
 
using Index = unsigned int
 
using IndexVector = std::vector< Index >
 
using ChannelGroups = std::map< Name, IndexVector >
 
using FloatVector = std::vector< float >
 
using FloatMap = std::map< Index, float >
 
- Private Types inherited from AdcChannelTool
using Index = unsigned int
 

Private Member Functions

void getWeights (const IndexVector &channels, const AdcChannelDataMap &acds, FloatMap &wts) const
 
FloatVector getCorrection (const IndexVector &channels, const AdcChannelDataMap &acds, const FloatMap &wts) const
 
- Private Member Functions inherited from TpcDataTool
virtual DataMap updateTpcData (TpcData &) const
 
virtual DataMap viewTpcData (const TpcData &) const
 
virtual int forwardTpcData () const
 
- Private Member Functions inherited from AdcChannelTool
virtual ~AdcChannelTool ()=default
 
virtual DataMap update (AdcChannelData &) const
 
virtual DataMap view (const AdcChannelData &acd) const
 
virtual DataMap viewMap (const AdcChannelDataMap &acds) const
 
virtual bool updateWithView () const
 
virtual bool viewWithUpdate () const
 
virtual DataMap beginEvent (const DuneEventInfo &) const
 
virtual DataMap endEvent (const DuneEventInfo &) const
 
virtual DataMap close (const DataMap *dmin=nullptr)
 

Private Attributes

int m_LogLevel
 
Name m_Weight
 
NameVector m_Groups
 
NameVector m_Options
 
ChannelGroups m_chg
 
bool m_useMedian =false
 
bool m_dropSignal =true
 
bool m_requireGoodChannel =true
 

Additional Inherited Members

- Static Private Member Functions inherited from AdcChannelTool
static int interfaceNotImplemented ()
 

Detailed Description

Definition at line 38 of file CnrGroupWeighted.h.

Member Typedef Documentation

using CnrGroupWeighted::ChannelGroups = std::map<Name, IndexVector>
private

Definition at line 57 of file CnrGroupWeighted.h.

using CnrGroupWeighted::FloatMap = std::map<Index, float>
private

Definition at line 59 of file CnrGroupWeighted.h.

Definition at line 58 of file CnrGroupWeighted.h.

using CnrGroupWeighted::Index = unsigned int
private

Definition at line 55 of file CnrGroupWeighted.h.

Definition at line 56 of file CnrGroupWeighted.h.

Definition at line 53 of file CnrGroupWeighted.h.

Definition at line 54 of file CnrGroupWeighted.h.

Constructor & Destructor Documentation

CnrGroupWeighted::CnrGroupWeighted ( fhicl::ParameterSet const &  ps)

Definition at line 20 of file CnrGroupWeighted_tool.cc.

21 : m_LogLevel(ps.get<int>("LogLevel")),
22  m_Weight(ps.get<Name>("Weight")),
23  m_Groups(ps.get<NameVector>("Groups")),
24  m_Options(ps.get<NameVector>("Options")) {
25  const string myname = "CnrGroupWeighted::ctor: ";
26  // Decode the options.
27  for ( Name sopt : m_Options ) {
28  if ( sopt == "mean" ) m_useMedian = false;
29  else if ( sopt == "median" ) m_useMedian = true;
30  else cout << myname << "WARNING: Ignoring invalid option: " << sopt << endl;
31  }
32  // Build the channel map.
33  string crtName = "channelGroups";
35  const IndexRangeGroupTool* pcrt = ptm == nullptr ? nullptr : ptm->getShared<IndexRangeGroupTool>(crtName);
36  for ( Name sgrp : m_Groups ) {
37  IndexRangeGroup grp;
38  if ( pcrt != nullptr ) grp = pcrt->get(sgrp);
39  if ( ! grp.isValid() ) {
40  grp = IndexRangeGroup(sgrp);
41  }
42  if ( ! grp.isValid() ) {
43  cout << myname << "WARNING: Unable to find range group " << sgrp << endl;
44  } else {
45  grp.getIndices(m_chg[grp.name]);
46  }
47  }
48 
49  // Log the configuration.
50  if ( m_LogLevel >= 1 ) {
51  cout << myname << " LogLevel: " << m_LogLevel << endl;
52  cout << myname << " Weight: " << m_Weight << endl;
53  cout << myname << " Groups: [";
54  int count = 0;
55  for ( Name nam : m_Groups ) {
56  if ( count && count%10 == 0 ) cout << "\n ";
57  if ( count++ ) cout << ", ";
58  cout << nam;
59  }
60  cout << "]" << endl;
61  cout << myname << " Options: [";
62  count = 0;
63  for ( Name nam : m_Options ) {
64  if ( count++ ) cout << ", ";
65  cout << nam;
66  }
67  cout << "]" << endl;
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;
74  }
75  }
76 }
ChannelGroupService::Name Name
NameVector m_Options
static constexpr double ps
Definition: Units.h:99
virtual IndexRangeGroup get(Name nam) const =0
ChannelGroups m_chg
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
std::vector< string > NameVector
bool isValid() const
void getIndices(IndexVector &idxs) const
static DuneToolManager * instance(std::string fclname="", int dbg=1)
T * getShared(std::string name)
QTextStream & endl(QTextStream &s)
CnrGroupWeighted::~CnrGroupWeighted ( )
overridedefault

Member Function Documentation

CnrGroupWeighted::FloatVector CnrGroupWeighted::getCorrection ( const IndexVector channels,
const AdcChannelDataMap acds,
const FloatMap wts 
) const
private

Definition at line 136 of file CnrGroupWeighted_tool.cc.

137  {
138  const string myname = "CnrGroupWeighted::getCorrection: ";
139  Index nsam = 0;
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;
146  const AdcChannelData& acd = iacd->second;
147  if ( m_requireGoodChannel && acd.channelStatus() ) continue;
148  if ( acd.samples.size() > nsam ) {
149  nsam = acd.samples.size();
150  wsamples.resize(nsam);
151  }
152  for ( size_t isam=0; isam<acd.samples.size(); ++isam ) {
153  if ( m_dropSignal && acd.signal.size()>isam && acd.signal[isam] ) continue;
154  if ( wt == 0 ) continue;
155  wsamples[isam].push_back(acd.samples[isam]/wt);
156  }
157  }
158  std::vector<float> correction(nsam, 0.0);
159  Index nsamCor = 0;
160  for ( Index isam=0; isam<nsam; ++isam ) {
161  size_t nval = wsamples[isam].size();
162  if ( nval < 2 ) continue;
163  if ( m_useMedian ) {
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];
167  } else {
168  float sum = 0.0;
169  for ( float val : wsamples[isam] ) sum += val;
170  correction[isam] = sum/float(wsamples[isam].size());
171  }
172  ++nsamCor;
173  }
174  if ( m_LogLevel >= 2 ) cout << myname << "Correcting " << nsamCor << "/" << nsam << " samples." << endl;
175  return correction;
176 }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
unsigned int Index
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
Index channelStatus() const
AdcFilterVector signal
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
AdcSignalVector samples
QTextStream & endl(QTextStream &s)
void CnrGroupWeighted::getWeights ( const IndexVector channels,
const AdcChannelDataMap acds,
FloatMap wts 
) const
private

Definition at line 110 of file CnrGroupWeighted_tool.cc.

111  {
112  const string myname = "CnrGroupWeighted::getWeights: ";
113  for ( Index ich : channels ) {
114  if ( m_Weight.size() == 0 ) {
115  wts[ich] = 1.0;
116  } else {
117  auto iacd = acds.find(ich);
118  if ( iacd == acds.end() ) continue;
119  const AdcChannelData& acd = iacd->second;
120  if ( acd.hasAttribute(m_Weight) ) {
121  wts[ich] = acd.getAttribute(m_Weight);
122  } else {
123  if ( m_LogLevel >= 1 ) {
124  cout << myname << "WARNING: Channel " << ich << " does not have attribute "
125  << m_Weight << endl;
126  }
127  wts[ich] = 0.0;
128  }
129  }
130  }
131 }
unsigned int Index
float getAttribute(Name mname, float def=0.0) const
bool hasAttribute(Name mname, float def=0.0) const
QTextStream & endl(QTextStream &s)
DataMap CnrGroupWeighted::updateMap ( AdcChannelDataMap acds) const
overridevirtual

Reimplemented from AdcChannelTool.

Definition at line 80 of file CnrGroupWeighted_tool.cc.

80  {
81  const string myname = "CnrGroupWeighted::updateMap: ";
82  DataMap ret;
83  if ( acds.size() == 0 ) {
84  std::cout << myname << "WARNING: No channels found." << std::endl;
85  return ret.setStatus(1);
86  }
87  // Loop over groups.
88  for ( const auto& entry : m_chg ) {
89  const IndexVector& channels = entry.second;
90  FloatMap wts;
91  getWeights(channels, acds, wts);
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;
96  AdcChannelData& acd = iacd->second;
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];
101  }
102  }
103  }
104  return ret;
105 }
std::vector< Index > IndexVector
QList< Entry > entry
FloatVector getCorrection(const IndexVector &channels, const AdcChannelDataMap &acds, const FloatMap &wts) const
DataMap & setStatus(int stat)
Definition: DataMap.h:130
unsigned int Index
ChannelGroups m_chg
void getWeights(const IndexVector &channels, const AdcChannelDataMap &acds, FloatMap &wts) const
std::map< Index, float > FloatMap
AdcSignalVector samples
QTextStream & endl(QTextStream &s)

Member Data Documentation

ChannelGroups CnrGroupWeighted::m_chg
private

Definition at line 68 of file CnrGroupWeighted.h.

bool CnrGroupWeighted::m_dropSignal =true
private

Definition at line 70 of file CnrGroupWeighted.h.

NameVector CnrGroupWeighted::m_Groups
private

Definition at line 64 of file CnrGroupWeighted.h.

int CnrGroupWeighted::m_LogLevel
private

Definition at line 62 of file CnrGroupWeighted.h.

NameVector CnrGroupWeighted::m_Options
private

Definition at line 65 of file CnrGroupWeighted.h.

bool CnrGroupWeighted::m_requireGoodChannel =true
private

Definition at line 71 of file CnrGroupWeighted.h.

bool CnrGroupWeighted::m_useMedian =false
private

Definition at line 69 of file CnrGroupWeighted.h.

Name CnrGroupWeighted::m_Weight
private

Definition at line 63 of file CnrGroupWeighted.h.


The documentation for this class was generated from the following files: