Roi2dToAdc_tool.cc
Go to the documentation of this file.
1 // Roi2dToAdc_tool.cc
2 
3 #include "Roi2dToAdc.h"
4 
5 using std::string;
6 using std::cout;
7 using std::endl;
8 using std::vector;
10 
14 
15 //**********************************************************************
16 // Class methods.
17 //**********************************************************************
18 
20 : m_LogLevel(ps.get<int>("LogLevel")) {
21  const string myname = "Roi2dToAdc::ctor: ";
22  // Display the configuration.
23  if ( m_LogLevel>= 1 ) {
24  cout << myname << " LogLevel: " << m_LogLevel << endl;
25  }
26 }
27 
28 //**********************************************************************
29 
31 
32 //**********************************************************************
33 
35  const string myname = "Roi2dToAdc::updateTpcData: ";
36  DataMap ret;
37  const float zero = 0.0;
38  Index nerr = 0;
39  Index nchaZeroed = 0;
40  Index nsamZeroed = 0;
41  if ( m_LogLevel >= 3 ) cout << myname << "ADC map count " << tpd.getAdcData().size() << endl;
42  // Zero the ADC samples, signal, ROIs and DFTs.
43  for ( TpcData::AdcDataPtr pacm : tpd.getAdcData() ) {
44  if ( ! pacm ) {
45  if ( m_LogLevel >= 4 ) cout << myname << " Skipping null map." << endl;
46  continue;
47  }
48  if ( m_LogLevel >= 4 ) cout << myname << " Processing map with channel count "
49  << pacm->size() << endl;
50  for ( auto& iacd : *(pacm) ) {
51  AdcChannelData& acd = iacd.second;
52  Index nsam = acd.samples.size();
53  if ( m_LogLevel >= 5 ) cout << myname << " Zeroing channel " << acd.channel()
54  << " with sample count " << nsam << endl;
55  std::fill(acd.samples.begin(), acd.samples.end(), zero);
56  nsamZeroed += nsam;
57  acd.signal.resize(nsam);
58  std::fill(acd.signal.begin(), acd.signal.end(), false);
59  acd.rois.clear();
60  acd.dftmags.clear();
61  acd.dftphases.clear();
62  ++nchaZeroed;
63  }
64  }
65  // Copy ROI samples to ADC.
66  if ( m_LogLevel >= 3 ) cout << myname << "ROI count " << tpd.get2dRois().size() << endl;
67  Index nchaFilled = 0;
68  Index nsamFilled = 0;
69  Index iroi = 0;
70  for ( const Tpc2dRoi& roi : tpd.get2dRois() ) {
71  if ( m_LogLevel >= 4 ) cout << myname << " Processing ROI " << iroi << " with "
72  << roi.channelSize() << " channels and "
73  << roi.sampleSize() << " samples." << endl;
74  Index nsamRoi = roi.sampleSize();
75  LongIndex ioffRoi = roi.sampleOffset();
76  IndexArray idxs;
77  Index& kcha = idxs[0];
78  Index& ksamRoi = idxs[1];
79  for ( kcha=0; kcha<roi.channelSize(); ++kcha ) {
80  Index icha = kcha + roi.channelOffset();
81  Index foundChannel = 0;
82  for ( TpcData::AdcDataPtr pacm : tpd.getAdcData() ) {
83  if ( pacm && pacm->count(icha) ) {
84  ++foundChannel = true;
85  AdcChannelData& acd = (*pacm)[icha];
86  Index nsamAdc = acd.samples.size();
87  if ( m_LogLevel >= 5 ) cout << myname << " Copying channel " << acd.channel()
88  << " from ROI sample count " << nsamRoi
89  << " to ADC sample count " << nsamAdc << endl;
90  LongIndex ioffAdc = acd.tickOffset();
91  bool agr = ioffAdc > ioffRoi;
92  Index isamAdc = agr ? 0 : Index(ioffRoi - ioffAdc);
93  ksamRoi = agr ? Index(ioffAdc - ioffRoi) : 0;
94  while ( ksamRoi < nsamRoi && isamAdc < nsamAdc ) {
95  acd.samples[isamAdc] = roi.data().value(idxs);
96  acd.signal[isamAdc] = true;
97  ++ksamRoi;
98  ++isamAdc;
99  ++nsamFilled;
100  } // End loop over copied samples
101  }
102  } // End loop over ADC channel maps
103  if ( foundChannel ) ++nchaFilled;
104  } // end loop over channels in the ROI
105  ++iroi;
106  } // end loop over ROIs
107  // Add ROI info.
108  for ( TpcData::AdcDataPtr pacm : tpd.getAdcData() ) {
109  if ( ! pacm ) continue;
110  for ( auto& iacd : *(pacm) ) {
111  AdcChannelData& acd = iacd.second;
112  if ( m_LogLevel >= 5 ) cout << myname << " Recording ROIs for channel " << acd.channel() << endl;
113  acd.roisFromSignal();
114  }
115  }
116  // Fill result.
117  ret.setStatus(nerr);
118  ret.setInt("r2a_nchaZeroed", nchaZeroed);
119  ret.setInt("r2a_nsamZeroed", nsamZeroed);
120  ret.setInt("r2a_nchaFilled", nchaFilled);
121  ret.setInt("r2a_nsamFilled", nsamFilled);
122  return ret;
123 }
124 
125 //**********************************************************************
126 
unsigned long int LongIndex
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
unsigned int Index
DataMap & setStatus(int stat)
Definition: DataMap.h:130
std::string string
Definition: nybbler.cc:12
Roi2dToAdc(fhicl::ParameterSet const &ps)
struct vector vector
std::shared_ptr< AdcChannelDataMap > AdcDataPtr
Definition: TpcData.h:35
DftData::IndexArray IndexArray
unsigned int Index
unsigned int Index
Definition: Roi2dToAdc.h:37
AdcDataVector & getAdcData()
Definition: TpcData.h:55
DataArray::IndexArray IndexArray
Definition: Tpc2dRoi.h:25
unsigned int Index
Definition: Tpc2dRoi.h:22
unsigned long int LongIndex
Definition: Tpc2dRoi.h:23
AdcRoiVector rois
AdcLongIndex tickOffset() const
void setInt(Name name, int val)
Definition: DataMap.h:131
AdcSignalVector dftphases
static constexpr double ps
Definition: Units.h:99
Channel channel() const
DataMap updateTpcData(TpcData &tpd) const override
AdcFilterVector signal
def fill(s)
Definition: translator.py:93
int m_LogLevel
Definition: Roi2dToAdc.h:49
~Roi2dToAdc() override
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
Tpc2dRoiVector & get2dRois()
Definition: TpcData.h:57
AdcSignalVector samples
AdcSignalVector dftmags
QTextStream & endl(QTextStream &s)