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

#include <FloatArrayGainCalibration.h>

Inheritance diagram for FloatArrayGainCalibration:
TpcDataTool AdcChannelTool

Public Types

using Name = std::string
 
using FloatArrayPtr = const FloatArrayTool *
 
- Public Types inherited from AdcChannelTool
using Index = unsigned int
 

Public Member Functions

 FloatArrayGainCalibration (fhicl::ParameterSet const &ps)
 
DataMap view (const AdcChannelData &acd) const override
 
DataMap update (AdcChannelData &acd) const override
 
- Public Member Functions inherited from TpcDataTool
virtual DataMap updateTpcData (TpcData &) const
 
virtual DataMap viewTpcData (const TpcData &) const
 
virtual int forwardTpcData () const
 
- Public Member Functions inherited from AdcChannelTool
virtual ~AdcChannelTool ()=default
 
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)
 

Private Attributes

int m_LogLevel
 
Name m_Unit
 
ParFormulam_GainDefault
 
AdcIndex m_AdcUnderflowDefault
 
AdcIndex m_AdcOverflowDefault
 
Name m_GainTool
 
ParFormulam_ScaleFactor
 
FloatArrayPtr m_pgains
 
const RunDataToolm_prdtool
 

Additional Inherited Members

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

Detailed Description

Definition at line 51 of file FloatArrayGainCalibration.h.

Member Typedef Documentation

Definition at line 57 of file FloatArrayGainCalibration.h.

Definition at line 56 of file FloatArrayGainCalibration.h.

Constructor & Destructor Documentation

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

Definition at line 37 of file FloatArrayGainCalibration_tool.cc.

38 : m_LogLevel(ps.get<int>("LogLevel")),
39  m_Unit(ps.get<string>("Unit")),
40  m_GainDefault(new RootParFormula("GainDefault", ps.get<Name>("GainDefault"))),
41  m_AdcUnderflowDefault(ps.get<unsigned int>("AdcUnderflowDefault")),
42  m_AdcOverflowDefault(ps.get<unsigned int>("AdcOverflowDefault")),
43  m_GainTool(ps.get<string>("GainTool")),
44  m_ScaleFactor(new RootParFormula("ScaleFactor", ps.get<Name>("ScaleFactor"))),
45  m_pgains(nullptr),
46  m_prdtool(nullptr) {
47  const string myname = "FloatArrayGainCalibration::ctor: ";
49  if ( m_GainTool.size() == 0 ) {
50  cout << myname << "INFO: No gain array tool. Default gain will be used." << endl;
51  } else if ( pdtm == nullptr ) {
52  cout << myname << "ERROR: Unable to retrieve tool manager." << endl;
53  } else {
55  if ( ! m_pgains ) {
56  cout << myname << "ERROR: Unable to retrieve gains tool " << m_GainTool << endl;
57  }
58  }
59  // Fetch run data tool.
60  if ( m_GainDefault->npar() || m_ScaleFactor->npar() ) {
61  string stnam = "runDataTool";
62  m_prdtool = pdtm->getShared<RunDataTool>(stnam);
63  if ( m_prdtool == nullptr ) {
64  cout << myname << "ERROR: RunDataTool " << stnam
65  << " not found. Formulas will not be evaluated." << endl;
66  } else {
67  cout << myname << "RunDataTool retrieved." << endl;
68  }
69  }
72  if ( m_LogLevel >= 1 ) {
73  cout << myname << " LogLevel: " << m_LogLevel << endl;
74  cout << myname << " Unit: " << m_Unit << endl;
75  cout << myname << " GainDefault: " << m_GainDefault->formulaString() << endl;
76  if ( m_pgains == nullptr ) {
77  cout << myname << " No GainTool." << endl;
78  } else {
79  cout << myname << " GainTool: " << m_GainTool << " (@" << m_pgains << ")" << endl;
80  }
81  cout << myname << " ScaleFactor: " << m_ScaleFactor->formulaString() << endl;
82  }
83 }
virtual int setDefaultEval(Value val)
Definition: ParFormula.h:74
virtual Name formulaString() const =0
ChannelGroupService::Name Name
virtual Index npar() const
Definition: ParFormula.h:44
static constexpr double ps
Definition: Units.h:99
static DuneToolManager * instance(std::string fclname="", int dbg=1)
T * getShared(std::string name)
QTextStream & endl(QTextStream &s)

Member Function Documentation

DataMap FloatArrayGainCalibration::update ( AdcChannelData acd) const
overridevirtual

Reimplemented from AdcChannelTool.

Definition at line 96 of file FloatArrayGainCalibration_tool.cc.

96  {
97  const string myname = "FloatArrayGainCalibration::update: ";
98  DataMap res;
99  AdcChannel icha = acd.channel();
100  if ( icha == AdcChannelData::badChannel() ) {
101  if ( m_LogLevel >= 2 ) {
102  cout << myname << "Data does not have a channel ID." << endl;
103  }
104  return res.setStatus(2);
105  }
106  if ( m_LogLevel >= 2 ) {
107  if ( m_pgains != nullptr && ! m_pgains->inRange(icha) ) {
108  cout << myname << "Gain not found for channel " << icha << endl;
109  }
110  }
111  if ( m_prdtool != nullptr ) {
112  RunData rdat = m_prdtool->runData(acd.run());
113  if ( ! rdat.isValid() ) cout << myname << "WARNING: RunData not found." << endl;
114  else {
117  }
118  }
119  if ( ! m_GainDefault->ready() ) {
120  cout << myname << "WARNING: Unset parameters in GainDefault: [" << m_GainDefault->unsetPars()
121  << "]. Using default value " << m_GainDefault->defaultEval() << endl;
122  }
123  if ( ! m_ScaleFactor->ready() ) {
124  cout << myname << "WARNING: Unset parameters in ScaleFactor: [" << m_ScaleFactor->unsetPars()
125  << "]. Using default value " << m_ScaleFactor->defaultEval() << endl;
126  }
127  float gdef = m_GainDefault->eval();
128  float gain = m_pgains == nullptr ? gdef :
129  gdef >= 0 ? m_pgains->value(icha, gdef) :
130  m_pgains->value(icha);
131  gain *= m_ScaleFactor->eval();
134  acd.samples.resize(acd.raw.size(), 0.0);
135  acd.flags.resize(acd.raw.size(), AdcGood);
136  AdcCount adcmin = 0;
137  AdcCount adcmax = 0;
138  Index nunder = 0;
139  Index nover = 0;
140  Index nsam = acd.raw.size();
141  Name unit = m_Unit;
142  if ( m_LogLevel >= 3 ) cout << myname << "Processing " << nsam << " samples for channel " << icha << endl;
143  for ( Index isam=0; isam<nsam; ++isam ) {
144  AdcCount adcin = acd.raw[isam];
145  if ( adcin <= adcudr ) {
146  acd.flags[isam] = AdcUnderflow;
147  ++nunder;
148  } else if ( adcin >= adcovr ) {
149  acd.flags[isam] = AdcOverflow;
150  ++nover;
151  }
152  if ( isam ==0 || adcin < adcmin ) adcmin = adcin;
153  if ( isam ==0 || adcin > adcmax ) adcmax = adcin;
154  float sigout = gain*(adcin - acd.pedestal);
155  acd.samples[isam] = sigout;
156  }
157  acd.sampleUnit = unit;
158  res.setFloat("calibGain", gain);
159  res.setInt("calibSampleCount", nsam);
160  res.setInt("calibUnderflowCount", nunder);
161  res.setInt("calibOverflowCount", nover);
162  res.setInt("calibAdcMin", adcmin);
163  res.setInt("calibAdcMax", adcmax);
164  return res;
165 }
void setFloat(Name name, float val)
Definition: DataMap.h:133
DataMap & setStatus(int stat)
Definition: DataMap.h:130
virtual double eval(const Values &vars) const =0
virtual bool ready() const
Definition: ParFormula.h:56
ChannelGroupService::Name Name
const AdcFlag AdcUnderflow
Definition: AdcTypes.h:33
virtual Names unsetPars() const =0
unsigned int Index
bool isValid() const
Definition: RunData.h:48
const AdcFlag AdcGood
Definition: AdcTypes.h:32
const AdcFlag AdcOverflow
Definition: AdcTypes.h:34
AdcIndex run() const
void setInt(Name name, int val)
Definition: DataMap.h:131
virtual RunData runData(Index run, Index subRun=0) const =0
AdcCountVector raw
Channel channel() const
AdcSignal pedestal
unsigned int AdcChannel
Definition: AdcTypes.h:50
virtual Value defaultEval() const
Definition: ParFormula.h:59
virtual float value(Index ival) const
static Index badChannel()
short AdcCount
Definition: AdcTypes.h:18
SetStat setFormulaPars(TFormula *form)
Definition: RunData.h:87
virtual bool inRange(Index ival) const
AdcSignalVector samples
QTextStream & endl(QTextStream &s)
AdcFlagVector flags
DataMap FloatArrayGainCalibration::view ( const AdcChannelData acd) const
overridevirtual

Reimplemented from AdcChannelTool.

Definition at line 87 of file FloatArrayGainCalibration_tool.cc.

87  {
89  AdcChannelData acdtmp(acd);
90  acdtmp.raw = acd.raw;
91  return update(acdtmp);
92 }
DataMap update(AdcChannelData &acd) const override
static QCString result
AdcCountVector raw

Member Data Documentation

AdcIndex FloatArrayGainCalibration::m_AdcOverflowDefault
private

Definition at line 72 of file FloatArrayGainCalibration.h.

AdcIndex FloatArrayGainCalibration::m_AdcUnderflowDefault
private

Definition at line 71 of file FloatArrayGainCalibration.h.

ParFormula* FloatArrayGainCalibration::m_GainDefault
private

Definition at line 70 of file FloatArrayGainCalibration.h.

Name FloatArrayGainCalibration::m_GainTool
private

Definition at line 73 of file FloatArrayGainCalibration.h.

int FloatArrayGainCalibration::m_LogLevel
private

Definition at line 68 of file FloatArrayGainCalibration.h.

FloatArrayPtr FloatArrayGainCalibration::m_pgains
private

Definition at line 77 of file FloatArrayGainCalibration.h.

const RunDataTool* FloatArrayGainCalibration::m_prdtool
private

Definition at line 78 of file FloatArrayGainCalibration.h.

ParFormula* FloatArrayGainCalibration::m_ScaleFactor
private

Definition at line 74 of file FloatArrayGainCalibration.h.

Name FloatArrayGainCalibration::m_Unit
private

Definition at line 69 of file FloatArrayGainCalibration.h.


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