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

#include <AdcToRoi2d.h>

Inheritance diagram for AdcToRoi2d:
TpcDataTool

Public Types

using Index = unsigned int
 
using IndexVector = std::vector< Index >
 
using Name = std::string
 
using NameVector = std::vector< Name >
 

Public Member Functions

 AdcToRoi2d (fhicl::ParameterSet const &ps)
 
 ~AdcToRoi2d () override
 
DataMap updateTpcData (TpcData &tpd) const override
 

Private Attributes

int m_LogLevel
 
Index m_Option
 
IndexVector m_InputAdcMaps
 
NameVector m_OutputNames
 

Additional Inherited Members

- Private Types inherited from AdcChannelTool
using Index = unsigned int
 
- Private Member Functions inherited from TpcDataTool
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 updateMap (AdcChannelDataMap &acds) 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)
 
- Static Private Member Functions inherited from AdcChannelTool
static int interfaceNotImplemented ()
 

Detailed Description

Definition at line 34 of file AdcToRoi2d.h.

Member Typedef Documentation

using AdcToRoi2d::Index = unsigned int

Definition at line 38 of file AdcToRoi2d.h.

Definition at line 39 of file AdcToRoi2d.h.

Definition at line 40 of file AdcToRoi2d.h.

Definition at line 41 of file AdcToRoi2d.h.

Constructor & Destructor Documentation

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

Definition at line 29 of file AdcToRoi2d_tool.cc.

30 : m_LogLevel(ps.get<int>("LogLevel")),
31  m_Option(ps.get<Index>("Option")),
32  m_InputAdcMaps(ps.get<IndexVector>("InputAdcMaps")),
33  m_OutputNames(ps.get<NameVector>("OutputNames")) {
34  const string myname = "AdcToRoi2d::ctor: ";
35  if ( m_Option > 2 ) {
36  cout << myname << "WARNING: Invalid option: " << m_Option
37  << " will be treated as 0." << endl;
38  }
39  // Display the configuration.
40  if ( m_LogLevel>= 1 ) {
41  cout << myname << " LogLevel: " << m_LogLevel << endl;
42  cout << myname << " Option: " << m_Option
43  << " (" << optionString(m_Option) << ")" << endl;
44  cout << myname << " OutputNames: [";
45  bool first = true;
46  for ( Name nam : m_OutputNames ) {
47  if ( first ) first = false;
48  else cout << ", ";
49  cout << nam;
50  }
51  cout << "]" << endl;
52  }
53 }
std::vector< Index > IndexVector
int m_LogLevel
Definition: AdcToRoi2d.h:53
ChannelGroupService::Name Name
Index m_Option
Definition: AdcToRoi2d.h:54
NameVector m_OutputNames
Definition: AdcToRoi2d.h:56
unsigned int Index
static constexpr double ps
Definition: Units.h:99
std::vector< string > NameVector
IndexVector m_InputAdcMaps
Definition: AdcToRoi2d.h:55
QTextStream & endl(QTextStream &s)
AdcToRoi2d::~AdcToRoi2d ( )
override

Definition at line 57 of file AdcToRoi2d_tool.cc.

57 { }

Member Function Documentation

DataMap AdcToRoi2d::updateTpcData ( TpcData tpd) const
overridevirtual

Reimplemented from TpcDataTool.

Definition at line 61 of file AdcToRoi2d_tool.cc.

61  {
62  const string myname = "AdcToRoi2d::updateTpcData: ";
63  DataMap ret;
64  Index imax = -1;
65  LongIndex lmax = -1;
66  // Find the channel and tick ranges for each ADC map.
67  Index nacm = tpd.getAdcData().size();
68  vector<LongIndex> itck1s(nacm, lmax);
69  vector<LongIndex> itck2s(nacm, 0);
70  vector<Index> icha1s(nacm, imax);
71  vector<Index> icha2s(nacm, 0);
72  vector<Index> ndats(nacm, 0);
73  Index nerr = 0;
74  if ( m_LogLevel >= 3 ) cout << myname << "Channel map count: " << nacm << endl;
75  IndexVector mapIndices = m_InputAdcMaps;
76  if ( mapIndices.size() == 0 ) {
77  for ( Index iacm=0; iacm<nacm; ++iacm ) mapIndices.push_back(iacm);
78  }
79  for ( Index iacm : mapIndices ) {
80  if ( iacm >= tpd.getAdcData().size() ) {
81  cout << myname << "WARNING: Skipping invalid ADC map index " << iacm << endl;
82  continue;
83  }
84  LongIndex ndat = 0;
85  const TpcData::AdcDataPtr pacm = tpd.getAdcData().at(iacm);
86  if ( ! pacm ) {
87  if ( m_LogLevel >=2 ) cout << myname << "Skipping missing ADC channel map." << endl;
88  ++nerr;
89  continue;
90  }
91  if ( pacm->size() == 0 ) {
92  if ( m_LogLevel >=2 ) cout << myname << "Skipping empty ADC channel map." << endl;
93  ++nerr;
94  continue;
95  }
96  if ( m_LogLevel >= 3 ) cout << myname << " Channel count: " << pacm->size() << endl;
97  for ( const auto& iacd : *pacm ) {
98  const AdcChannelData& acd = iacd.second;
99  Index nsam = acd.samples.size();
100  Index icha1 = acd.channel();
101  Index icha2 = icha1 + 1;
102  Index itck1 = acd.tickOffset();
103  Index itck2 = itck1 + nsam;
104  if ( icha1 < icha1s[iacm] ) icha1s[iacm] = icha1;
105  if ( icha2 > icha2s[iacm] ) icha2s[iacm] = icha2;
106  if ( itck1 < itck1s[iacm] ) itck1s[iacm] = itck1;
107  if ( itck2 > itck2s[iacm] ) itck2s[iacm] = itck2;
108  if ( m_LogLevel >= 3 ) cout << myname << " Channel " << acd.channel()
109  << " sample count: " << nsam << endl;
110  ndat += nsam;
111  }
112  if ( icha1s[iacm] >= icha2s[iacm] ) {
113  cout << myname << "ERROR: Channels out of range. Skipping ADC map " << iacm << "." << endl;
114  ++nerr;
115  continue;
116  }
117  if ( ndat == 0 ) {
118  cout << myname << "ERROR: No samples found. Skipping ADC map " << iacm << "." << endl;
119  ++nerr;
120  continue;
121  }
122  if ( itck1s[iacm] >= itck2s[iacm] ) {
123  cout << myname << "ERROR: Ticks out of range. Skipping ADC map " << iacm << "." << endl;
124  ++nerr;
125  continue;
126  }
127  ndats[iacm] = ndat;
128  LongIndex ncha = icha2s[iacm] - icha1s[iacm];
129  LongIndex ntck = itck2s[iacm] - itck1s[iacm];
130  LongIndex ncht = ncha*ntck;
131  double frac = double(ndat)/double(ncht);
132  if ( m_LogLevel >= 2 ) {
133  cout << myname << " ADC map is " << ncha << " x " << ntck
134  << " with fill fraction " << frac << endl;
135  cout << myname << " Channel range: [ " << icha1s[iacm] << ", " << icha2s[iacm] << ")" << endl;
136  cout << myname << " Tick range: [ " << itck1s[iacm] << ", " << itck2s[iacm] << ")" << endl;
137  }
138  }
139  Index nroi = 0;
140  vector<int> roiNdats;
141  if ( m_Option == 1 ) {
142  for ( Index iacm=0; iacm<nacm; ++iacm ) {
143  Index icha1 = icha1s[iacm];
144  Index icha2 = icha2s[iacm];
145  LongIndex itck1 = itck1s[iacm];
146  LongIndex itck2 = itck2s[iacm];
147  if ( icha1 >= icha2 ) continue;
148  if ( itck1 >= itck2 ) continue;
149  Index ncha = icha2 - icha1;
150  Index ntck = Index(itck2 - itck1);
151  // Create and fill ROI.
152  tpd.get2dRois().emplace_back(ncha, ntck, icha1, itck1);
153  ++nroi;
154  TpcData* ptpdo = &tpd;
155  if ( m_OutputNames.size() ) {
156  if ( iacm >= m_OutputNames.size() ) {
157  cout << myname << "WARNING: No outpu name supplied for ADC map " << iacm << endl;
158  } else {
159  Name nam = m_OutputNames[iacm];
160  ptpdo = tpd.getTpcData(nam);
161  if ( ptpdo == nullptr ) {
162  ptpdo = tpd.addTpcData(nam);
163  if ( ptpdo == nullptr ) {
164  cout << myname << "ERROR: Unable to add TpcData directory " << nam << endl;
165  continue;
166  } else if ( m_LogLevel >= 2 ) {
167  cout << myname << "Added TpcData directory " << nam << endl;
168  }
169  } else if ( m_LogLevel >= 2 ) {
170  cout << myname << "Using existing TpcData directory " << nam << endl;
171  }
172  }
173  }
174  Tpc2dRoi& roi = ptpdo->get2dRois().back();
175  const TpcData::AdcDataPtr pacm = tpd.getAdcData().at(iacm);
177  Index ndat = 0;
178  for ( const auto& iacd : *pacm ) {
179  const AdcChannelData& acd = iacd.second;
180  idxs[0] = acd.channel() - icha1;
181  idxs[1] = acd.tickOffset() - itck1;
182  for ( Index isam=0; isam<acd.samples.size(); ++isam, ++idxs[1], ++ndat ) {
183  roi.data().setValue(idxs, acd.samples[isam]);
184  }
185  }
186  roiNdats.push_back(ndat);
187  if ( ndat != ndats[iacm] ) {
188  cout << myname << "ERROR: Unexpected fill count: " << ndat << " != " << ndats[iacm] << endl;
189  ++nerr;
190  }
191  }
192  } else if ( m_Option == 2 ) {
193  cout << myname << "ERROR: Merging of ADC data is not yet supported." << endl;
194  }
195  ret.setStatus(nerr);
196  ret.setInt("a2r_nroi", nroi);
197  ret.setIntVector("a2r_nsams", roiNdats);
198  return ret;
199 }
std::vector< Index > IndexVector
unsigned long int LongIndex
int m_LogLevel
Definition: AdcToRoi2d.h:53
DataMap & setStatus(int stat)
Definition: DataMap.h:130
ChannelGroupService::Name Name
std::shared_ptr< AdcChannelDataMap > AdcDataPtr
Definition: TpcData.h:35
Index m_Option
Definition: AdcToRoi2d.h:54
TpcData * addTpcData(Name nam, bool copyAdcData=true)
Definition: TpcData.cxx:24
NameVector m_OutputNames
Definition: AdcToRoi2d.h:56
unsigned int Index
void setIntVector(Name name, const IntVector &val)
Definition: DataMap.h:132
AdcDataVector & getAdcData()
Definition: TpcData.h:55
std::array< Index, 2 > IndexArray
Definition: Real2dData.h:34
AdcLongIndex tickOffset() const
void setInt(Name name, int val)
Definition: DataMap.h:131
unsigned int Index
Definition: AdcToRoi2d.h:38
Channel channel() const
TpcData * getTpcData(Name nam)
Definition: TpcData.cxx:42
int imax
Definition: tracks.py:195
const DataArray & data() const
Definition: Tpc2dRoi.h:50
IndexVector m_InputAdcMaps
Definition: AdcToRoi2d.h:55
Index setValue(const IndexArray &isams, Float val, Index *pchk=nullptr)
Definition: Real2dData.h:197
Tpc2dRoiVector & get2dRois()
Definition: TpcData.h:57
AdcSignalVector samples
QTextStream & endl(QTextStream &s)

Member Data Documentation

IndexVector AdcToRoi2d::m_InputAdcMaps
private

Definition at line 55 of file AdcToRoi2d.h.

int AdcToRoi2d::m_LogLevel
private

Definition at line 53 of file AdcToRoi2d.h.

Index AdcToRoi2d::m_Option
private

Definition at line 54 of file AdcToRoi2d.h.

NameVector AdcToRoi2d::m_OutputNames
private

Definition at line 56 of file AdcToRoi2d.h.


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