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

#include <CnrByGroup.h>

Inheritance diagram for CnrByGroup:
TpcDataTool

Public Member Functions

 CnrByGroup (fhicl::ParameterSet const &ps)
 
 ~CnrByGroup () 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 >
 
- Private Types inherited from AdcChannelTool
using Index = unsigned int
 

Private Member Functions

FloatVector getCorrection (const IndexVector &channels, const AdcChannelDataMap &acds) 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
 
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 28 of file CnrByGroup.h.

Member Typedef Documentation

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

Definition at line 47 of file CnrByGroup.h.

using CnrByGroup::FloatVector = std::vector<float>
private

Definition at line 48 of file CnrByGroup.h.

using CnrByGroup::Index = unsigned int
private

Definition at line 45 of file CnrByGroup.h.

Definition at line 46 of file CnrByGroup.h.

using CnrByGroup::Name = std::string
private

Definition at line 43 of file CnrByGroup.h.

Definition at line 44 of file CnrByGroup.h.

Constructor & Destructor Documentation

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

Definition at line 20 of file CnrByGroup_tool.cc.

21 : m_LogLevel(ps.get<int>("LogLevel")),
22  m_Groups(ps.get<NameVector>("Groups")),
23  m_Options(ps.get<NameVector>("Options")) {
24  const string myname = "CnrByGroup::ctor: ";
25  // Decode the options.
26  for ( Name sopt : m_Options ) {
27  if ( sopt == "mean" ) m_useMedian = false;
28  else if ( sopt == "median" ) m_useMedian = true;
29  else cout << myname << "WARNING: Ignoring invalid option: " << sopt << endl;
30  }
31  // Build the channel map.
32  string crtName = "channelGroups";
34  const IndexRangeGroupTool* pcrt = ptm == nullptr ? nullptr : ptm->getShared<IndexRangeGroupTool>(crtName);
35  for ( Name sgrp : m_Groups ) {
36  IndexRangeGroup grp;
37  if ( pcrt != nullptr ) grp = pcrt->get(sgrp);
38  if ( ! grp.isValid() ) {
39  grp = IndexRangeGroup(sgrp);
40  }
41  if ( ! grp.isValid() ) {
42  cout << myname << "WARNING: Unable to find range group " << sgrp << endl;
43  } else {
44  grp.getIndices(m_chg[grp.name]);
45  }
46  }
47 
48  // Log the configuration.
49  if ( m_LogLevel >= 1 ) {
50  cout << myname << " LogLevel: " << m_LogLevel << endl;
51  cout << myname << " Groups: [";
52  int count = 0;
53  for ( Name nam : m_Groups ) {
54  if ( count && count%10 == 0 ) cout << "\n ";
55  if ( count++ ) cout << ", ";
56  cout << nam;
57  }
58  cout << "]" << endl;
59  cout << myname << " Options: [";
60  count = 0;
61  for ( Name nam : m_Options ) {
62  if ( count++ ) cout << ", ";
63  cout << nam;
64  }
65  cout << "]" << endl;
66  cout << myname << "Using " << (m_useMedian ? "median" : "mean") << " correction." << endl;
67  cout << myname << "Using " << (m_dropSignal ? "all" : "non-signal") << " samples." << endl;
68  cout << myname << (m_requireGoodChannel ? "R" : "Not r") << "equiring good channel status." << endl;
69  cout << myname << " Group #chan" << endl;
70  for ( const auto& ient : m_chg ) {
71  cout << myname << setw(10) << ient.first << setw(8) << ient.second.size() << endl;
72  }
73  }
74 }
NameVector m_Groups
Definition: CnrByGroup.h:52
NameVector m_Options
Definition: CnrByGroup.h:53
ChannelGroupService::Name Name
int m_LogLevel
Definition: CnrByGroup.h:51
static constexpr double ps
Definition: Units.h:99
virtual IndexRangeGroup get(Name nam) const =0
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
bool m_dropSignal
Definition: CnrByGroup.h:58
std::vector< string > NameVector
bool m_requireGoodChannel
Definition: CnrByGroup.h:59
bool m_useMedian
Definition: CnrByGroup.h:57
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)
ChannelGroups m_chg
Definition: CnrByGroup.h:56
CnrByGroup::~CnrByGroup ( )
overridedefault

Member Function Documentation

CnrByGroup::FloatVector CnrByGroup::getCorrection ( const IndexVector channels,
const AdcChannelDataMap acds 
) const
private

Definition at line 105 of file CnrByGroup_tool.cc.

105  {
106  const string myname = "CnrByGroup::getCorrection: ";
107  Index nsam = 0;
108  std::vector<FloatVector> samples;
109  for ( Index ich : channels ) {
110  auto iacd = acds.find(ich);
111  if ( iacd == acds.end() ) continue;
112  const AdcChannelData& acd = iacd->second;
113  if ( m_requireGoodChannel && acd.channelStatus() ) continue;
114  if ( acd.samples.size() > nsam ) {
115  nsam = acd.samples.size();
116  samples.resize(nsam);
117  }
118  for ( size_t isam=0; isam<acd.samples.size(); ++isam ) {
119  if ( m_dropSignal && acd.signal.size()>isam && acd.signal[isam] ) continue;
120  samples[isam].push_back(acd.samples[isam]);
121  }
122  }
123  std::vector<float> correction(nsam, 0.0);
124  Index nsamCor = 0;
125  for ( Index isam=0; isam<nsam; ++isam ) {
126  size_t nval = samples[isam].size();
127  if ( nval < 2 ) continue;
128  if ( m_useMedian ) {
129  std::sort(samples[isam].begin(), samples[isam].end());
130  if ( nval%2 == 0 ) correction[isam] = 0.5 * (samples[isam][nval/2-1] + samples[isam][nval/2]);
131  else correction[isam] = samples[isam][nval/2];
132  } else {
133  float sum = 0.0;
134  for ( float val : samples[isam] ) sum += val;
135  correction[isam] = sum/float(samples[isam].size());
136  }
137  ++nsamCor;
138  }
139  if ( m_LogLevel >= 2 ) cout << myname << "Correcting " << nsamCor << "/" << nsam << " samples." << endl;
140  return correction;
141 }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
int m_LogLevel
Definition: CnrByGroup.h:51
unsigned int Index
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
Index channelStatus() const
bool m_dropSignal
Definition: CnrByGroup.h:58
AdcFilterVector signal
bool m_requireGoodChannel
Definition: CnrByGroup.h:59
bool m_useMedian
Definition: CnrByGroup.h:57
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
AdcSignalVector samples
QTextStream & endl(QTextStream &s)
DataMap CnrByGroup::updateMap ( AdcChannelDataMap acds) const
overridevirtual

Reimplemented from AdcChannelTool.

Definition at line 78 of file CnrByGroup_tool.cc.

78  {
79  const string myname = "CnrByGroup::updateMap: ";
80  DataMap ret;
81  if ( acds.size() == 0 ) {
82  std::cout << myname << "WARNING: No channels found." << std::endl;
83  return ret.setStatus(1);
84  }
85  for ( const auto& entry : m_chg ) {
86  const IndexVector& channels = entry.second;
87  std::vector<float> correction = getCorrection(channels, acds);
88  for ( Index ich : channels) {
89  auto iacd = acds.find(ich);
90  if ( iacd == acds.end() ) continue;
91  AdcChannelData& acd = iacd->second;
92  if ( acd.samples.size() == 0 ) continue;
93  if ( acd.samples.size() > correction.size() ) correction.resize(acd.samples.size(), 0.);
94  for ( size_t isam=0; isam<acd.samples.size(); ++isam) {
95  acd.samples[isam] -= correction[isam];
96  }
97  }
98  }
99  return ret;
100 }
std::vector< Index > IndexVector
QList< Entry > entry
DataMap & setStatus(int stat)
Definition: DataMap.h:130
FloatVector getCorrection(const IndexVector &channels, const AdcChannelDataMap &acds) const
unsigned int Index
AdcSignalVector samples
QTextStream & endl(QTextStream &s)
ChannelGroups m_chg
Definition: CnrByGroup.h:56

Member Data Documentation

ChannelGroups CnrByGroup::m_chg
private

Definition at line 56 of file CnrByGroup.h.

bool CnrByGroup::m_dropSignal =true
private

Definition at line 58 of file CnrByGroup.h.

NameVector CnrByGroup::m_Groups
private

Definition at line 52 of file CnrByGroup.h.

int CnrByGroup::m_LogLevel
private

Definition at line 51 of file CnrByGroup.h.

NameVector CnrByGroup::m_Options
private

Definition at line 53 of file CnrByGroup.h.

bool CnrByGroup::m_requireGoodChannel =true
private

Definition at line 59 of file CnrByGroup.h.

bool CnrByGroup::m_useMedian =false
private

Definition at line 57 of file CnrByGroup.h.


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