ATLAS Offline Software
Loading...
Searching...
No Matches
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
40protected:
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
51protected:
52
53 void setAddtlShapeValues(const std::vector<double> &values) {
54 setAddtlShapeValues(&values[0]);
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) {
114 m_addtlShapeValues.at(index) = 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//
133TF1* 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
163TF1* makeWaveformTF1(ZDCWaveformBase& instance, double xmin, double xmax, bool useTF1Params = true)
164{
165 return makeWaveformTF1(&instance, xmin, xmax, useTF1Params);
166}
167
168};
169#endif
std::map< std::string, double > instance
#define x
double getAddtlShapeValue(const std::string &name) const
ZDCWaveformBase * Duplicate()
double evaluate(double time) const
Definition ZDCWaveform.h:81
void setAddtlShapeValue(std::string name, double value)
TF1 * makeWaveformTF1(ZDCWaveformBase &instance, double xmin, double xmax, bool useTF1Params=true)
void setAddtlShapeValues(const std::vector< double > &values)
Definition ZDCWaveform.h:53
virtual std::string name() const =0
const std::string getName() const
void setAddtlShapeValues(const double *values)
double getTauFall() const
unsigned int m_numAddtlShapePars
Definition ZDCWaveform.h:37
void setAddtlShapeValue(unsigned int index, double value)
std::vector< double > m_addtlShapeValues
Definition ZDCWaveform.h:45
double getTauRise() const
std::string getNameTag() const
const std::string & getTag() const
double m_initialTauFall
Definition ZDCWaveform.h:36
std::map< std::string, unsigned int > m_addtlShapeNames
Definition ZDCWaveform.h:33
void setAddtlShapeParameters(const std::vector< std::string > &addtlShapeNames, const std::vector< double > &addtlShapeValues)
double evaluateRoot(double *x, double *p)
Definition ZDCWaveform.h:86
void setTaus(double tauRise, double tauFall)
double operator()(double *x, double *p)
Definition ZDCWaveform.h:95
virtual double doEvaluate(double time) const =0
std::string m_tag
Definition ZDCWaveform.h:32
TF1 * makeWaveformTF1(ZDCWaveformBase *ptr, double xmin, double xmax, bool useTF1Params=true)
double evaluateRootNoTF1Par(double *x, double *p)
Definition ZDCWaveform.h:90
virtual ~ZDCWaveformBase()=default
ZDCWaveformBase()=delete
double getAddtlShapeValue(unsigned int index) const
unsigned int getNumAddtlShapeValues() const
std::vector< double > m_addtlShapeInitialValues
Definition ZDCWaveform.h:38
double m_initialTauRise
Definition ZDCWaveform.h:35
double xmax
Definition listroot.cxx:61
double xmin
Definition listroot.cxx:60
Definition index.py:1