ATLAS Offline Software
ZDCWaveform.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef ZDCUTILS_ZDCWAVEFORM_H
6 #define ZDCUTILS_ZDCWAVEFORM_H
7 
8 #include <string>
9 #include <vector>
10 #include <map>
11 #include "TF1.h"
12 
13 // Base class that defines the interface to all waveform classes
14 //
15 // The waveforms describe possible shapes of pulses seen in the ZDC or RPD
16 //
17 // They should be defined such that the maximum occurs at t = 0.
18 // The base class provides a rescaling to provide unity value at maximum (t = 0).
19 //
20 // Users of the waveform then produce "real" pulses by evaluating the pulse at
21 // at (t-t0) and multiplying by an amplitude.
22 //
23 // The waveforms are assumed to have at least two shape parameters, tau_1 and tau_2.
24 // They may also have additional shape parameters that are described by strings and
25 // are given default values in the constructor.
26 //
27 // The waveform should be able to be evaluated at any time, positive or negative
28 //
29 //
31 {
32  std::string m_tag;
33  std::map<std::string, unsigned int> m_addtlShapeNames;
34 
37  unsigned int m_numAddtlShapePars;
38  std::vector<double> m_addtlShapeInitialValues;
39 
40 protected:
41 
42  double m_tauRise;
43  double m_tauFall;
44 
45  std::vector<double> m_addtlShapeValues;
46 
47  void setAddtlShapeParameters(const std::vector<std::string> &addtlShapeNames,
48  const std::vector<double> &addtlShapeValues);
49  void setAddtlShapeValues(const double* values);
50 
51 protected:
52 
53  void setAddtlShapeValues(const std::vector<double> &values) {
55  }
56 
57  // The actual implementation classes must override doEvaluate to produce the corresponding waveform
58  //
59  virtual double doEvaluate(double time) const = 0;
60 
61  // The implementation classes must provide a name
62  //
63  virtual std::string name() const = 0;
64 
65  ZDCWaveformBase() = delete;
66 
67  public:
68  ZDCWaveformBase(std::string tag, double initialTauRise, double initialTauFall, const std::vector<std::string> &addtlShapeNames,
69  const std::vector<double> &addtlShapeValues);
70 
71  virtual ~ZDCWaveformBase() = default;
72 
74 
75  // Duplicate this object
76  //
78 
79  // This method provides the actual value of the waveform at the provided time
80  //
81  double evaluate(double time) const
82  {
83  return doEvaluate(time)/doEvaluate(0);
84  }
85 
86  double evaluateRoot (double *x, double *p) {
87  return this->operator()(x,p);
88  }
89 
90  double evaluateRootNoTF1Par (double *x, double *p) {
91  (void)p;
92  return evaluate(x[0]);
93  }
94 
95  double operator() (double *x, double *p) {
96  setTaus(p[0], p[1]);
98  return evaluate(x[0]);
99  }
100 
101  const std::string& getTag() const {return m_tag;}
102  std::string getNameTag() const {return name() + "_" + m_tag;}
103  const std::string getName() const {return name();}
104  double getTauRise() const {return m_tauRise;}
105  double getTauFall() const {return m_tauFall;}
106 
107  unsigned int getNumAddtlShapeValues() const {return m_numAddtlShapePars;}
108  double getAddtlShapeValue(const std::string& name) const {return m_addtlShapeValues.at(m_addtlShapeNames.find(name)->second);}
109  double getAddtlShapeValue(unsigned int index) const {return m_addtlShapeValues.at(index);}
110 
111  void setAddtlShapeValue(std::string name, double value);
112 
113  void setAddtlShapeValue(unsigned int index, double value) {
115  }
116 
117  void setTaus(double tauRise, double tauFall)
118  {
119  m_tauRise = tauRise;
120  m_tauFall = tauFall;
121  }
122 
123  // Restore the initial values for all parameters
124  //
125  void restoreInitial();
126 
127 
128 // Make a TF1 that can draw the waveform. Depending on useTF1Params, the parameters
129 // can be controlled via the TF1 or via the ZDCWaveform object. In the latter case
130 // the TF1 has no parameters
131 //
132 //
133 TF1* makeWaveformTF1(ZDCWaveformBase* ptr, double xmin, double xmax, bool useTF1Params = true)
134 {
135  std::string name = ptr->getNameTag() + "_TF1";
136 
137  TF1* newTF1 = 0;
138 
139  if (useTF1Params) {
140  unsigned int numPar = 2 + ptr->getNumAddtlShapeValues();
141 
142  newTF1= new TF1(name.c_str(), ptr, &ZDCWaveformBase::evaluateRoot, xmin, xmax, numPar,
143  "ZDCWaveformBase", "evaluateRoot");
144 
145  newTF1->SetParameter(0, ptr->getTauRise());
146  newTF1->SetParameter(1, ptr->getTauFall());
147 
148  if (numPar > 2) {
149  for (unsigned int idxpar = 2; idxpar < numPar; idxpar++) {
150  newTF1->SetParameter(idxpar, ptr->getAddtlShapeValue(idxpar - 2));
151  }
152  }
153  }
154  else {
155  newTF1= new TF1(name.c_str(), ptr, &ZDCWaveformBase::evaluateRootNoTF1Par, xmin, xmax, 0,
156  "ZDCWaveformBase", "evaluateRoot");
157  }
158 
159  newTF1->SetNpx(1000);
160  return newTF1;
161 }
162 
163 TF1* makeWaveformTF1(ZDCWaveformBase& instance, double xmin, double xmax, bool useTF1Params = true)
164 {
165  return makeWaveformTF1(&instance, xmin, xmax, useTF1Params);
166 }
167 
168 };
169 #endif
ZDCWaveformBase::doEvaluate
virtual double doEvaluate(double time) const =0
ZDCWaveformBase::operator()
double operator()(double *x, double *p)
Definition: ZDCWaveform.h:95
ZDCWaveformBase::ZDCWaveformBase
ZDCWaveformBase()=delete
ZDCWaveformBase::m_initialTauFall
double m_initialTauFall
Definition: ZDCWaveform.h:36
ZDCWaveformBase::evaluateRootNoTF1Par
double evaluateRootNoTF1Par(double *x, double *p)
Definition: ZDCWaveform.h:90
index
Definition: index.py:1
ZDCWaveformBase::setAddtlShapeParameters
void setAddtlShapeParameters(const std::vector< std::string > &addtlShapeNames, const std::vector< double > &addtlShapeValues)
Definition: ZDCWaveform.cxx:32
ZDCWaveformBase::m_addtlShapeInitialValues
std::vector< double > m_addtlShapeInitialValues
Definition: ZDCWaveform.h:38
athena.value
value
Definition: athena.py:124
ZDCWaveformBase::getNumAddtlShapeValues
unsigned int getNumAddtlShapeValues() const
Definition: ZDCWaveform.h:107
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
ZDCWaveformBase::m_addtlShapeValues
std::vector< double > m_addtlShapeValues
Definition: ZDCWaveform.h:45
x
#define x
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:805
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
ZDCWaveformBase::evaluate
double evaluate(double time) const
Definition: ZDCWaveform.h:81
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ZDCWaveformBase::m_addtlShapeNames
std::map< std::string, unsigned int > m_addtlShapeNames
Definition: ZDCWaveform.h:33
ZDCWaveformBase::getTag
const std::string & getTag() const
Definition: ZDCWaveform.h:101
ZDCWaveformBase::m_tauRise
double m_tauRise
Definition: ZDCWaveform.h:42
ZDCWaveformBase::setAddtlShapeValue
void setAddtlShapeValue(std::string name, double value)
xmin
double xmin
Definition: listroot.cxx:60
ZDCWaveformBase::makeWaveformTF1
TF1 * makeWaveformTF1(ZDCWaveformBase *ptr, double xmin, double xmax, bool useTF1Params=true)
Definition: ZDCWaveform.h:133
ZDCWaveformBase::getTauRise
double getTauRise() const
Definition: ZDCWaveform.h:104
ZDCWaveformBase::getAddtlShapeValue
double getAddtlShapeValue(const std::string &name) const
Definition: ZDCWaveform.h:108
ZDCWaveformBase::restoreInitial
void restoreInitial()
Definition: ZDCWaveform.cxx:60
ZDCWaveformBase::setAddtlShapeValues
void setAddtlShapeValues(const std::vector< double > &values)
Definition: ZDCWaveform.h:53
ZDCWaveformBase::setAddtlShapeValues
void setAddtlShapeValues(const double *values)
Definition: ZDCWaveform.cxx:54
ZDCWaveformBase::setTaus
void setTaus(double tauRise, double tauFall)
Definition: ZDCWaveform.h:117
ZDCWaveformBase::Duplicate
ZDCWaveformBase * Duplicate()
ZDCWaveformBase::m_initialTauRise
double m_initialTauRise
Definition: ZDCWaveform.h:35
ZDCWaveformBase::evaluateRoot
double evaluateRoot(double *x, double *p)
Definition: ZDCWaveform.h:86
ZDCWaveformBase::m_tauFall
double m_tauFall
Definition: ZDCWaveform.h:43
ZDCWaveformBase::getName
const std::string getName() const
Definition: ZDCWaveform.h:103
ZDCWaveformBase
Definition: ZDCWaveform.h:31
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
ZDCWaveformBase::getAddtlShapeValue
double getAddtlShapeValue(unsigned int index) const
Definition: ZDCWaveform.h:109
ZDCWaveformBase::~ZDCWaveformBase
virtual ~ZDCWaveformBase()=default
xmax
double xmax
Definition: listroot.cxx:61
ZDCWaveformBase::getNameTag
std::string getNameTag() const
Definition: ZDCWaveform.h:102
ZDCWaveformBase::name
virtual std::string name() const =0
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
ZDCWaveformBase::getTauFall
double getTauFall() const
Definition: ZDCWaveform.h:105
ZDCWaveformBase::m_tag
std::string m_tag
Definition: ZDCWaveform.h:32
ZDCWaveformBase::m_numAddtlShapePars
unsigned int m_numAddtlShapePars
Definition: ZDCWaveform.h:37
ZDCWaveformBase::makeWaveformTF1
TF1 * makeWaveformTF1(ZDCWaveformBase &instance, double xmin, double xmax, bool useTF1Params=true)
Definition: ZDCWaveform.h:163
ZDCWaveformBase::setAddtlShapeValue
void setAddtlShapeValue(unsigned int index, double value)
Definition: ZDCWaveform.h:113