ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
LArCalorimeter
LArCafJobs
src
SimpleShape.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
LArCafJobs/SimpleShape.h
"
6
#include "TH1D.h"
7
#include "TMath.h"
8
#include "
LArCafJobs/ShapeInfo.h
"
9
10
11
12
using namespace
LArSamples
;
13
14
15
SimpleShape::SimpleShape
(
const
std::vector<double>&
values
,
const
std::vector<double>& errors,
16
double
timeInterval
,
double
startTime
)
17
:
m_values
(
values
),
m_errors
(errors),
18
m_timeInterval
(
timeInterval
),
m_startTime
(
startTime
)
19
{
20
}
21
22
23
SimpleShape::SimpleShape
(
unsigned
int
nPoints
,
double
timeInterval
,
double
startTime
)
24
:
m_values
(
nPoints
),
m_errors
(
nPoints
),
25
m_timeInterval
(
timeInterval
),
m_startTime
(
startTime
)
26
{
27
}
28
29
30
SimpleShape::SimpleShape
(
const
AbsShape
& shape,
double
scale,
double
shift)
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
}
40
41
42
SimpleShape::SimpleShape
(
const
ShapeInfo
& shapeInfo,
double
scale,
double
shift,
bool
samplingTimeOnly)
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
());
51
m_timeInterval
=
timeInterval
;
52
m_startTime
= shift - shapeInfo.
shift
();
53
}
54
55
56
double
SimpleShape::time
(
unsigned
int
i)
const
57
{
58
return
startTime
() + i*
timeInterval
();
59
}
60
61
62
SimpleShape
*
SimpleShape::diff
()
const
63
{
64
SimpleShape
*
diff
=
new
SimpleShape
(
nPoints
(),
timeInterval
(),
startTime
());
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
}
72
73
74
SimpleShape
*
SimpleShape::add
(
const
AbsShape
& other,
double
scale,
double
shift)
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
}
88
89
90
bool
SimpleShape::add
(
unsigned
int
k,
double
val,
double
err)
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
}
96
97
98
SimpleShape
*
SimpleShape::createEmpty
()
const
99
{
100
return
new
SimpleShape
(
nPoints
(),
timeInterval
(),
startTime
());
101
}
102
103
104
TH1D*
SimpleShape::histogram
(
const
char
* name,
const
char
* title,
bool
timeInUnitOfSamples)
const
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
}
122
123
124
bool
SimpleShape::add
(std::unique_ptr<SimpleShape>& s1,
const
AbsShape
& s2)
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
}
135
136
137
bool
SimpleShape::scaleAndShift
(std::unique_ptr<SimpleShape>& s1,
double
scale,
double
shift)
138
{
139
if
(!s1)
return
false
;
140
s1.reset(
new
SimpleShape
(*s1, scale, shift));
141
return
true
;
142
}
ShapeInfo.h
SimpleShape.h
LArSamples::AbsShape::nPoints
virtual unsigned int nPoints() const =0
LArSamples::AbsShape::time
virtual double time(unsigned int i) const =0
LArSamples::AbsShape::values
TVectorD values(int lwb, int upb) const
Definition
AbsShape.cxx:135
LArSamples::AbsShape::AbsShape
AbsShape()
Definition
AbsShape.h:72
LArSamples::AbsShape::error
virtual double error(unsigned int i) const
Definition
AbsShape.cxx:24
LArSamples::AbsShape::value
virtual double value(unsigned int i) const =0
LArSamples::AbsShape::interpolateDiff
int interpolateDiff(double time, double &diff) const
Definition
AbsShape.cxx:108
LArSamples::ShapeInfo
Definition
ShapeInfo.h:24
LArSamples::ShapeInfo::phase
unsigned char phase(unsigned int i) const
Definition
ShapeInfo.cxx:66
LArSamples::ShapeInfo::shift
float shift() const
Definition
ShapeInfo.h:42
LArSamples::ShapeInfo::value
double value(unsigned int i) const
Definition
ShapeInfo.cxx:58
LArSamples::ShapeInfo::nPoints
unsigned int nPoints() const
Definition
ShapeInfo.h:37
LArSamples::ShapeInfo::nIntervals
unsigned int nIntervals() const
Definition
ShapeInfo.h:41
LArSamples::SimpleShape::add
bool add(unsigned int k, double value, double error)
Definition
SimpleShape.cxx:90
LArSamples::SimpleShape::histogram
TH1D * histogram(const char *name="shape", const char *title="", bool timeInUnitOfSamples=false) const
Definition
SimpleShape.cxx:104
LArSamples::SimpleShape::nPoints
unsigned int nPoints() const
Definition
SimpleShape.h:48
LArSamples::SimpleShape::SimpleShape
SimpleShape(const std::vector< double > &values, const std::vector< double > &errors, double timeInterval=25, double startTime=0)
Constructor.
Definition
SimpleShape.cxx:15
LArSamples::SimpleShape::timeInterval
double timeInterval() const
Definition
SimpleShape.h:45
LArSamples::SimpleShape::diff
SimpleShape * diff() const
Definition
SimpleShape.cxx:62
LArSamples::SimpleShape::m_errors
std::vector< double > m_errors
Definition
SimpleShape.h:68
LArSamples::SimpleShape::m_timeInterval
double m_timeInterval
Definition
SimpleShape.h:69
LArSamples::SimpleShape::startTime
double startTime() const
Definition
SimpleShape.h:46
LArSamples::SimpleShape::scaleAndShift
static bool scaleAndShift(std::unique_ptr< SimpleShape > &s1, double scale, double shift=0)
Definition
SimpleShape.cxx:137
LArSamples::SimpleShape::createEmpty
SimpleShape * createEmpty() const
Definition
SimpleShape.cxx:98
LArSamples::SimpleShape::time
double time(unsigned int i) const
Definition
SimpleShape.cxx:56
LArSamples::SimpleShape::m_values
std::vector< double > m_values
Definition
SimpleShape.h:68
LArSamples::SimpleShape::value
double value(unsigned int i) const
Definition
SimpleShape.h:49
LArSamples::SimpleShape::m_startTime
double m_startTime
Definition
SimpleShape.h:69
h
LArSamples
Definition
AbsShape.h:24
error
Definition
IImpactPoint3dEstimator.h:72
LArSamples::Definitions::samplingInterval
static const unsigned int samplingInterval
Definition
LArCalorimeter/LArCafJobs/LArCafJobs/Definitions.h:16
Generated on
for ATLAS Offline Software by
1.17.0