ATLAS Offline Software
Loading...
Searching...
No Matches
LArSamples::SimpleShape Class Reference

#include <SimpleShape.h>

Inheritance diagram for LArSamples::SimpleShape:
Collaboration diagram for LArSamples::SimpleShape:

Public Member Functions

 SimpleShape (const std::vector< double > &values, const std::vector< double > &errors, double timeInterval=25, double startTime=0)
 Constructor.
 SimpleShape (unsigned int nPoints, double timeInterval=25, double startTime=0)
 SimpleShape (const SimpleShape &other)
 SimpleShape (const ShapeInfo &shapeInfo, double scale=1, double shift=0, bool samplingTimeOnly=false)
 SimpleShape (const AbsShape &other, double scale=1, double shift=0)
virtual ~SimpleShape ()
double timeInterval () const
double startTime () const
unsigned int nPoints () const
double value (unsigned int i) const
double time (unsigned int i) const
double covariance (unsigned int i, unsigned int j) const
void set (unsigned int i, double value, double error=-1)
void setError (unsigned int i, double error)
SimpleShapediff () const
bool add (unsigned int k, double value, double error)
SimpleShapeadd (const AbsShape &other, double scale=1, double shift=0)
SimpleShapecreateEmpty () const
TH1D * histogram (const char *name="shape", const char *title="", bool timeInUnitOfSamples=false) const
virtual double error (unsigned int i) const
TVectorD values (int lwb, int upb) const
int findTimeInterval (double time) const
int interpolate (double time, double &value, double &error) const
bool interpolate (const AbsShape &other, TVectorD &values, CovMatrix &errors, int lwb=-1, int upb=-1) const
int interpolateDiff (double time, double &diff) const
bool interpolateDiff (const AbsShape &other, TVectorD &diffs, int lwb=-1, int upb=-1) const
CovMatrix covarianceMatrix (int lwb=-1, int upb=-1, const CovMatrix &refErr=CovMatrix(), bool withCorrs=true) const
CovMatrix covarianceMatrix (unsigned int nPoints, bool withCorrs=true) const
CovMatrix invCovarianceMatrix (int lwb=-1, int upb=-1, const CovMatrix &refErr=CovMatrix(), bool withCorrs=true) const
CovMatrix invCovarianceMatrix (unsigned int nPoints, bool withCorrs=true) const
double maxValue (bool withErrors=false) const
double minValue (bool withErrors=false) const
int maxPosition () const
int minPosition () const
TGraphErrors * graph (bool timeInUnitOfSamples=false) const
SimpleShaperesample (unsigned int nPts) const

Static Public Member Functions

static bool add (std::unique_ptr< SimpleShape > &s1, const AbsShape &s2)
static bool scaleAndShift (std::unique_ptr< SimpleShape > &s1, double scale, double shift=0)

Private Member Functions

SimpleShapeoperator= (const SimpleShape &)

Private Attributes

std::vector< double > m_values
std::vector< double > m_errors
double m_timeInterval {}
double m_startTime {}

Detailed Description

Definition at line 25 of file SimpleShape.h.

Constructor & Destructor Documentation

◆ SimpleShape() [1/5]

SimpleShape::SimpleShape ( const std::vector< double > & values,
const std::vector< double > & errors,
double timeInterval = 25,
double startTime = 0 )

Constructor.

Definition at line 15 of file SimpleShape.cxx.

17 : m_values(values), m_errors(errors),
19{
20}
TVectorD values(int lwb, int upb) const
Definition AbsShape.cxx:135
double timeInterval() const
Definition SimpleShape.h:45
std::vector< double > m_errors
Definition SimpleShape.h:68
double startTime() const
Definition SimpleShape.h:46
std::vector< double > m_values
Definition SimpleShape.h:68

◆ SimpleShape() [2/5]

SimpleShape::SimpleShape ( unsigned int nPoints,
double timeInterval = 25,
double startTime = 0 )

Definition at line 23 of file SimpleShape.cxx.

◆ SimpleShape() [3/5]

LArSamples::SimpleShape::SimpleShape ( const SimpleShape & other)
inline

Definition at line 35 of file SimpleShape.h.

35 :
36 AbsShape(),
37 m_values(other.m_values), m_errors(other.m_errors),
38 m_timeInterval(other.m_timeInterval), m_startTime(other.m_startTime) { }

◆ SimpleShape() [4/5]

SimpleShape::SimpleShape ( const ShapeInfo & shapeInfo,
double scale = 1,
double shift = 0,
bool samplingTimeOnly = false )

Definition at line 42 of file SimpleShape.cxx.

43{
44 for (unsigned int i = 0; i < shapeInfo.nPoints(); i++) {
45 if (samplingTimeOnly && shapeInfo.phase(i) != 0) continue;
46 m_values.push_back(shapeInfo.value(i)*scale);
47 m_errors.push_back(0);
48 }
49
50 double timeInterval = 1.0*Definitions::samplingInterval/(samplingTimeOnly ? 1 : shapeInfo.nIntervals());
52 m_startTime = shift - shapeInfo.shift();
53}
unsigned char phase(unsigned int i) const
Definition ShapeInfo.cxx:66
float shift() const
Definition ShapeInfo.h:42
double value(unsigned int i) const
Definition ShapeInfo.cxx:58
unsigned int nPoints() const
Definition ShapeInfo.h:37
unsigned int nIntervals() const
Definition ShapeInfo.h:41

◆ SimpleShape() [5/5]

SimpleShape::SimpleShape ( const AbsShape & other,
double scale = 1,
double shift = 0 )

Definition at line 30 of file SimpleShape.cxx.

31{
32 for (unsigned int i = 0; i < shape.nPoints(); i++) {
33 m_values.push_back(shape.value(i)*scale);
34 m_errors.push_back(shape.error(i)*scale);
35 }
36
37 m_timeInterval = (shape.time(shape.nPoints() - 1) - shape.time(0))/(shape.nPoints() - 1);
38 m_startTime = shape.time(0) + shift;
39}

◆ ~SimpleShape()

virtual LArSamples::SimpleShape::~SimpleShape ( )
inlinevirtual

Definition at line 43 of file SimpleShape.h.

43{ }

Member Function Documentation

◆ add() [1/3]

SimpleShape * SimpleShape::add ( const AbsShape & other,
double scale = 1,
double shift = 0 )

Definition at line 74 of file SimpleShape.cxx.

75{
76 std::vector<double> values, errors;
77 for (unsigned int k = 0; k < nPoints(); ++k) {
78 double val, err;
79 int pb = other.interpolate(time(k) - shift, val, err);
80 if (pb != 0) val = err = 0;
81 //if (pb == 1) break; //overflow: stop. underflow is OK : shape is assumed to be 0
82 values.push_back(this->value(k) + scale*val);
83 errors.push_back(TMath::Sqrt(TMath::Power(this->error(k),2) + TMath::Power(scale*err, 2)));
84 }
85
86 return new SimpleShape(values, errors, timeInterval(), startTime());
87}
virtual double error(unsigned int i) const
Definition AbsShape.cxx:24
SimpleShape(const std::vector< double > &values, const std::vector< double > &errors, double timeInterval=25, double startTime=0)
Constructor.
double time(unsigned int i) const
double value(unsigned int i) const
Definition SimpleShape.h:49

◆ add() [2/3]

bool SimpleShape::add ( std::unique_ptr< SimpleShape > & s1,
const AbsShape & s2 )
static

Definition at line 124 of file SimpleShape.cxx.

125{
126 if (!s1) {
127 s1.reset(new SimpleShape(s2));
128 return true;
129 }
130 SimpleShape* sum = s1->add(s2);
131 if (!sum) return false;
132 s1.reset(sum);
133 return true;
134}

◆ add() [3/3]

bool SimpleShape::add ( unsigned int k,
double value,
double error )

Definition at line 90 of file SimpleShape.cxx.

91{
92 m_values[k] = m_values[k] + val;
93 m_errors [k] = TMath::Sqrt(m_errors[k]*m_errors[k] + err*err);
94 return true;
95}

◆ covariance()

double LArSamples::SimpleShape::covariance ( unsigned int i,
unsigned int j ) const
inlinevirtual

Implements LArSamples::AbsShape.

Definition at line 51 of file SimpleShape.h.

51{ return (i == j ? m_errors[i]*m_errors[i] : 0); }

◆ covarianceMatrix() [1/2]

CovMatrix AbsShape::covarianceMatrix ( int lwb = -1,
int upb = -1,
const CovMatrix & refErr = CovMatrix(),
bool withCorrs = true ) const
inherited

Definition at line 198 of file AbsShape.cxx.

201{
202 if (lwb < 0 || upb < 0) { lwb = 0; upb = nPoints() - 1; }
203 CovMatrix c(lwb, upb);
204 for (int i = lwb; i <= upb; i++) {
205 for (int j = lwb; j <= upb; j++) {
206 double cov = (withCorrs || i == j ? covariance(i, j) : 0);
207 if (refErr.GetNrows() > 0) cov += refErr(i, j);
208 c(i, j) = cov;
209 }
210 }
211 return c;
212}
virtual unsigned int nPoints() const =0
virtual double covariance(unsigned int i, unsigned int j) const =0

◆ covarianceMatrix() [2/2]

CovMatrix AbsShape::covarianceMatrix ( unsigned int nPoints,
bool withCorrs = true ) const
inherited

Definition at line 223 of file AbsShape.cxx.

225{
226 return covarianceMatrix(0, n - 1, CovMatrix(), withCorrs);
227}
CovMatrix covarianceMatrix(int lwb=-1, int upb=-1, const CovMatrix &refErr=CovMatrix(), bool withCorrs=true) const
Definition AbsShape.cxx:198

◆ createEmpty()

SimpleShape * SimpleShape::createEmpty ( ) const

Definition at line 98 of file SimpleShape.cxx.

99{
100 return new SimpleShape(nPoints(), timeInterval(), startTime());
101}

◆ diff()

SimpleShape * SimpleShape::diff ( ) const

Definition at line 62 of file SimpleShape.cxx.

63{
65 for (unsigned int i = 0; i < nPoints(); i++) {
66 double val;
67 interpolateDiff(time(i), val);
68 diff->set(i, val, 0);
69 }
70 return diff;
71}
int interpolateDiff(double time, double &diff) const
Definition AbsShape.cxx:108
SimpleShape * diff() const

◆ error()

double AbsShape::error ( unsigned int i) const
virtualinherited

Reimplemented in LArSamples::ScaledShiftedShape.

Definition at line 24 of file AbsShape.cxx.

25{
26 return TMath::Sqrt(covariance(i, i));
27}

◆ findTimeInterval()

int AbsShape::findTimeInterval ( double time) const
inherited

Definition at line 71 of file AbsShape.cxx.

72{
73 if (t < time(0)) return -1;
74 if (t > time(nPoints() - 1)) return int(nPoints()) - 1;
75
76 for (unsigned int i = 0; i < nPoints() - 1; i++)
77 if (time(i) <= t && t < time(i+1)) return i;
78
79 return nPoints() - 1;
80}
virtual double time(unsigned int i) const =0

◆ graph()

TGraphErrors * AbsShape::graph ( bool timeInUnitOfSamples = false) const
inherited

Definition at line 186 of file AbsShape.cxx.

187{
188 TGraphErrors* graph = new TGraphErrors(nPoints());
189 double unit = (timeInUnitOfSamples ? Definitions::samplingInterval : 1);
190 for (unsigned int i = 0; i < nPoints(); i++) {
191 graph->SetPoint(i, time(i)/unit, value(i));
192 graph->SetPointError(i, 0, error(i));
193 }
194 return graph;
195}
const PlainObject unit() const
This is a plugin that makes Eigen look like CLHEP & defines some convenience methods.
virtual double value(unsigned int i) const =0
TGraphErrors * graph(bool timeInUnitOfSamples=false) const
Definition AbsShape.cxx:186

◆ histogram()

TH1D * SimpleShape::histogram ( const char * name = "shape",
const char * title = "",
bool timeInUnitOfSamples = false ) const

Definition at line 104 of file SimpleShape.cxx.

105{
106 double xMin = (timeInUnitOfSamples ? -1.5 : time(0) - 1.5*timeInterval());
107 double xMax = (timeInUnitOfSamples ? nPoints() + 0.5 : time(nPoints()) + 0.5*timeInterval());
108 TH1D* h = new TH1D(name, title, nPoints() + 2, xMin, xMax);
109 h->GetXaxis()->SetTitle(timeInUnitOfSamples ? "Sample Index" : "Time (ns)");
110 h->GetYaxis()->SetTitle("ADC counts");
111 h->GetYaxis()->SetTitleOffset(1.1);
112 h->SetMarkerStyle(20);
113 h->SetMarkerSize(1);
114
115 for (unsigned int i = 0; i < nPoints(); i++) {
116 h->SetBinContent(i + 2, value(i));
117 if (error(i) > 0) h->SetBinError(i + 2, error(i));
118 }
119
120 return h;
121}

◆ interpolate() [1/2]

bool AbsShape::interpolate ( const AbsShape & other,
TVectorD & values,
CovMatrix & errors,
int lwb = -1,
int upb = -1 ) const
inherited

Definition at line 147 of file AbsShape.cxx.

148{
149 if (lwb < 0) lwb = 0;
150 if (upb < 0) upb = other.nPoints() - 1;
151 values.ResizeTo(lwb, upb);
152 errors.ResizeTo(lwb, upb, lwb, upb);
153 int actualLwb = -1, actualUpb = upb;
154 for (int i = lwb; i <= upb; i++) {
155 double val, err;
156 int stat = interpolate(other.time(i), val, err);
157 if (stat == 0 && actualLwb < 0) actualLwb = i;
158 if (stat == +1) { actualUpb = i - 1; break; }
159 values(i) = val;
160 errors(i, i) = err*err;
161 }
162 values.ResizeTo(actualLwb, actualUpb);
163 errors.ResizeTo(actualLwb, actualUpb, actualLwb, actualUpb);
164 return (actualLwb >= 0);
165}
int interpolate(double time, double &value, double &error) const
Definition AbsShape.cxx:83

◆ interpolate() [2/2]

int AbsShape::interpolate ( double time,
double & value,
double & error ) const
inherited

Definition at line 83 of file AbsShape.cxx.

84{
85 if (nPoints() < 2) return -1;
86
87 int status = 0;
88 int i1 = findTimeInterval(t);
89
90 if (i1 < 0) {
91 status = -1;
92 i1 = 0;
93 }
94
95 if (i1 > int(nPoints()) - 2) {
96 status = 1;
97 i1 = nPoints() - 2;
98 }
99
100 double delta = (t - time(i1))/(time(i1+1) - time(i1));
101 val = value(i1) + delta*(value(i1 + 1) - value(i1));
102 err = error(i1) + delta*(error(i1 + 1) - error(i1));
103 //cout << t << " " << i1 << " " << time(i1) << " " << delta << " " << value(i1) << " " << value(i1+1) << " " << val << " " << status << endl;
104 return status;
105}
int findTimeInterval(double time) const
Definition AbsShape.cxx:71
status
Definition merge.py:16

◆ interpolateDiff() [1/2]

bool AbsShape::interpolateDiff ( const AbsShape & other,
TVectorD & diffs,
int lwb = -1,
int upb = -1 ) const
inherited

Definition at line 168 of file AbsShape.cxx.

169{
170 if (lwb < 0) lwb = 0;
171 if (upb < 0) upb = other.nPoints() - 1;
172 diffs.ResizeTo(lwb, upb);
173 int actualLwb = -1, actualUpb = upb;
174 for (int i = lwb; i <= upb; i++) {
175 double diff;
176 int stat = interpolateDiff(other.time(i), diff);
177 if (stat == 0 && actualLwb < 0) actualLwb = i;
178 if (stat == +1) { actualUpb = i - 1; break; }
179 diffs(i) = diff;
180 }
181 diffs.ResizeTo(actualLwb, actualUpb);
182 return (actualLwb >= 0);
183}
void diff(const Jet &rJet1, const Jet &rJet2, std::map< std::string, double > varDiff)
Difference between jets - Non-Class function required by trigger.
Definition Jet.cxx:631

◆ interpolateDiff() [2/2]

int AbsShape::interpolateDiff ( double time,
double & diff ) const
inherited

Definition at line 108 of file AbsShape.cxx.

109{
110 int status = 0;
111 int i1 = findTimeInterval(t);
112 if (i1 < 0) {
113 i1 = 0;
114 status = -1;
115 }
116 if (i1 > int(nPoints()) - 1) {
117 i1 = nPoints() - 1;
118 status = 1;
119 }
120 if (i1 > 1 && i1 < int(nPoints()) - 2)
121 diff = (value(i1 - 2) - 8*value(i1 - 1) + 8*value(i1 + 1) - value(i1 + 2))/(time(i1 + 2) - time(i1 - 2))/3;
122 else
123 if (i1 > 0)
124 if (i1 < int(nPoints()) - 1)
125 diff = (value(i1 + 1) - value(i1 - 1))/(time(i1 + 1) - time(i1 - 1));
126 else
127 diff = (value(i1) - value(i1 - 1))/(time(i1) - time(i1 - 1));
128 else
129 diff = (value(i1 + 1) - value(i1))/(time(i1 + 1) - time(i1));
130
131 return status;
132}

◆ invCovarianceMatrix() [1/2]

CovMatrix AbsShape::invCovarianceMatrix ( int lwb = -1,
int upb = -1,
const CovMatrix & refErr = CovMatrix(),
bool withCorrs = true ) const
inherited

Definition at line 215 of file AbsShape.cxx.

218{
219 return covarianceMatrix(lwb, upb, refErr, withCorrs).Invert();
220}

◆ invCovarianceMatrix() [2/2]

CovMatrix AbsShape::invCovarianceMatrix ( unsigned int nPoints,
bool withCorrs = true ) const
inherited

Definition at line 230 of file AbsShape.cxx.

232{
233 return covarianceMatrix(n, withCorrs).Invert();
234}

◆ maxPosition()

int AbsShape::maxPosition ( ) const
inherited

Definition at line 52 of file AbsShape.cxx.

53{
54 int maxPosition = -1;
55 double maxValue = -1;
56 for (unsigned int i = 0; i < nPoints(); i++)
57 if (value(i) > maxValue) { maxPosition = i; maxValue = value(i); }
58 return maxPosition;
59}
int maxPosition() const
Definition AbsShape.cxx:52
double maxValue(bool withErrors=false) const
Definition AbsShape.cxx:30

◆ maxValue()

double AbsShape::maxValue ( bool withErrors = false) const
inherited
Returns
sample max parameters

Definition at line 30 of file AbsShape.cxx.

31{
32 double maxValue = -DBL_MAX;
33 for (unsigned int i = 0; i < nPoints(); i++) {
34 double val = value(i) + (withErrors ? error(i) : 0);
35 if (val > maxValue) maxValue = val;
36 }
37 return maxValue;
38}

◆ minPosition()

int AbsShape::minPosition ( ) const
inherited

Definition at line 61 of file AbsShape.cxx.

62{
63 int minPosition = -1;
65 for (unsigned int i = 0; i < nPoints(); i++)
66 if (value(i) < minValue) { minPosition = i; minValue = value(i); }
67 return minPosition;
68}
int minPosition() const
Definition AbsShape.cxx:61
double minValue(bool withErrors=false) const
Definition AbsShape.cxx:41

◆ minValue()

double AbsShape::minValue ( bool withErrors = false) const
inherited

Definition at line 41 of file AbsShape.cxx.

42{
43 double minValue = DBL_MAX;
44 for (unsigned int i = 0; i < nPoints(); i++) {
45 double val = value(i) - (withErrors ? error(i) : 0);
46 if (val < minValue) minValue = val;
47 }
48 return minValue;
49}

◆ nPoints()

unsigned int LArSamples::SimpleShape::nPoints ( ) const
inlinevirtual
Returns
data points

Implements LArSamples::AbsShape.

Definition at line 48 of file SimpleShape.h.

48{ return m_values.size(); }

◆ operator=()

SimpleShape & LArSamples::SimpleShape::operator= ( const SimpleShape & )
private

◆ resample()

SimpleShape * AbsShape::resample ( unsigned int nPts) const
inherited

Definition at line 237 of file AbsShape.cxx.

238{
239 std::vector<double> values, errors;
240 double t0 = time(0);
241 double t1 = time(nPoints() - 1);
242 double dT = (t1 - t0)/nPts;
243 double t = t0;
244 for (unsigned int i = 0; i < nPts; i++, t += dT) {
245 double val, err;
246 int inRange = interpolate(t, val, err);
247 if (inRange != 0) return nullptr;
248 values.push_back(val);
249 errors.push_back(err);
250 }
251
252 return new SimpleShape(values, errors, dT, t0);
253}
static Double_t t0
bool inRange(const double *boundaries, const double value, const double tolerance=0.02)
std::vector< ALFA_RawDataCollection_p1 > t1

◆ scaleAndShift()

bool SimpleShape::scaleAndShift ( std::unique_ptr< SimpleShape > & s1,
double scale,
double shift = 0 )
static

Definition at line 137 of file SimpleShape.cxx.

138{
139 if (!s1) return false;
140 s1.reset(new SimpleShape(*s1, scale, shift));
141 return true;
142}

◆ set()

void LArSamples::SimpleShape::set ( unsigned int i,
double value,
double error = -1 )
inline

Definition at line 53 of file SimpleShape.h.

53{ m_values[i] = value; if (error > 0) m_errors[i] = error; }

◆ setError()

void LArSamples::SimpleShape::setError ( unsigned int i,
double error )
inline

Definition at line 54 of file SimpleShape.h.

54{ m_errors[i] = error; }

◆ startTime()

double LArSamples::SimpleShape::startTime ( ) const
inline

Definition at line 46 of file SimpleShape.h.

46{ return m_startTime; }

◆ time()

double SimpleShape::time ( unsigned int i) const
virtual

Implements LArSamples::AbsShape.

Definition at line 56 of file SimpleShape.cxx.

57{
58 return startTime() + i*timeInterval();
59}

◆ timeInterval()

double LArSamples::SimpleShape::timeInterval ( ) const
inline

Definition at line 45 of file SimpleShape.h.

45{ return m_timeInterval; }

◆ value()

double LArSamples::SimpleShape::value ( unsigned int i) const
inlinevirtual

Implements LArSamples::AbsShape.

Definition at line 49 of file SimpleShape.h.

49{ return (i < m_values.size() ? m_values[i] : -1E99); }

◆ values()

TVectorD AbsShape::values ( int lwb,
int upb ) const
inherited

Definition at line 135 of file AbsShape.cxx.

136{
137 if (lwb < 0) lwb = 0;
138 if (upb < 0) upb = (int)nPoints() - 1;
139 if (upb >= (int)nPoints()) upb = (int)nPoints() - 1;
140 TVectorD vals(lwb, upb);
141 for (int i = lwb; i <= upb; i++)
142 vals(i) = value(i);
143 return vals;
144}

Member Data Documentation

◆ m_errors

std::vector<double> LArSamples::SimpleShape::m_errors
private

Definition at line 68 of file SimpleShape.h.

◆ m_startTime

double LArSamples::SimpleShape::m_startTime {}
private

Definition at line 69 of file SimpleShape.h.

69{}, m_startTime{};

◆ m_timeInterval

double LArSamples::SimpleShape::m_timeInterval {}
private

Definition at line 69 of file SimpleShape.h.

69{}, m_startTime{};

◆ m_values

std::vector<double> LArSamples::SimpleShape::m_values
private

Definition at line 68 of file SimpleShape.h.


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