ATLAS Offline Software
SimpleShape.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "TH1D.h"
7 #include "TMath.h"
8 #include "LArCafJobs/ShapeInfo.h"
9 
10 #include <iostream>
11 using std::cout;
12 using std::endl;
13 
14 using namespace LArSamples;
15 
16 
17 SimpleShape::SimpleShape(const std::vector<double>& values, const std::vector<double>& errors,
18  double timeInterval, double startTime)
19  : m_values(values), m_errors(errors),
20  m_timeInterval(timeInterval), m_startTime(startTime)
21 {
22 }
23 
24 
25 SimpleShape::SimpleShape(unsigned int nPoints, double timeInterval, double startTime)
26  : m_values(nPoints), m_errors(nPoints),
27  m_timeInterval(timeInterval), m_startTime(startTime)
28 {
29 }
30 
31 
32 SimpleShape::SimpleShape(const AbsShape& shape, double scale, double shift)
33 {
34  for (unsigned int i = 0; i < shape.nPoints(); i++) {
35  m_values.push_back(shape.value(i)*scale);
36  m_errors.push_back(shape.error(i)*scale);
37  }
38 
39  m_timeInterval = (shape.time(shape.nPoints() - 1) - shape.time(0))/(shape.nPoints() - 1);
40  m_startTime = shape.time(0) + shift;
41 }
42 
43 
44 SimpleShape::SimpleShape(const ShapeInfo& shapeInfo, double scale, double shift, bool samplingTimeOnly)
45 {
46  for (unsigned int i = 0; i < shapeInfo.nPoints(); i++) {
47  if (samplingTimeOnly && shapeInfo.phase(i) != 0) continue;
48  m_values.push_back(shapeInfo.value(i)*scale);
49  m_errors.push_back(0);
50  }
51 
52  double timeInterval = 1.0*Definitions::samplingInterval/(samplingTimeOnly ? 1 : shapeInfo.nIntervals());
54  m_startTime = shift - shapeInfo.shift();
55 }
56 
57 
58 double SimpleShape::time(unsigned int i) const
59 {
60  return startTime() + i*timeInterval();
61 }
62 
63 
65 {
67  for (unsigned int i = 0; i < nPoints(); i++) {
68  double val;
70  diff->set(i, val, 0);
71  }
72  return diff;
73 }
74 
75 
76 SimpleShape* SimpleShape::add(const AbsShape& other, double scale, double shift)
77 {
78  std::vector<double> values, errors;
79  for (unsigned int k = 0; k < nPoints(); ++k) {
80  double val, err;
81  int pb = other.interpolate(time(k) - shift, val, err);
82  if (pb != 0) val = err = 0;
83  //if (pb == 1) break; //overflow: stop. underflow is OK : shape is assumed to be 0
84  values.push_back(this->value(k) + scale*val);
85  errors.push_back(TMath::Sqrt(TMath::Power(this->error(k),2) + TMath::Power(scale*err, 2)));
86  }
87 
88  return new SimpleShape(values, errors, timeInterval(), startTime());
89 }
90 
91 
92 bool SimpleShape::add(unsigned int k, double val, double err)
93 {
94  m_values[k] = m_values[k] + val;
95  m_errors [k] = TMath::Sqrt(m_errors[k]*m_errors[k] + err*err);
96  return true;
97 }
98 
99 
101 {
102  return new SimpleShape(nPoints(), timeInterval(), startTime());
103 }
104 
105 
106 TH1D* SimpleShape::histogram(const char* name, const char* title, bool timeInUnitOfSamples) const
107 {
108  double xMin = (timeInUnitOfSamples ? -1.5 : time(0) - 1.5*timeInterval());
109  double xMax = (timeInUnitOfSamples ? nPoints() + 0.5 : time(nPoints()) + 0.5*timeInterval());
110  TH1D* h = new TH1D(name, title, nPoints() + 2, xMin, xMax);
111  h->GetXaxis()->SetTitle(timeInUnitOfSamples ? "Sample Index" : "Time (ns)");
112  h->GetYaxis()->SetTitle("ADC counts");
113  h->GetYaxis()->SetTitleOffset(1.1);
114  h->SetMarkerStyle(20);
115  h->SetMarkerSize(1);
116 
117  for (unsigned int i = 0; i < nPoints(); i++) {
118  h->SetBinContent(i + 2, value(i));
119  if (error(i) > 0) h->SetBinError(i + 2, error(i));
120  }
121 
122  return h;
123 }
124 
125 
127 {
128  if (!s2) return false;
129  if (!s1) {
130  s1 = new SimpleShape(*s2);
131  return true;
132  }
133  SimpleShape* sum = s1->add(*s2);
134  if (!sum) return false;
135 
136  delete s1;
137  s1 = sum;
138  return true;
139 }
140 
141 
142 bool SimpleShape::scaleAndShift(SimpleShape*& s1, double scale, double shift)
143 {
144  if (!s1) return 0;
145  SimpleShape* newShape = new SimpleShape(*s1, scale, shift);
146  delete s1;
147  s1 = newShape;
148  return true;
149 }
LArSamples::SimpleShape::SimpleShape
SimpleShape(const std::vector< double > &values, const std::vector< double > &errors, double timeInterval=25, double startTime=0)
Constructor
Definition: SimpleShape.cxx:17
LArSamples::SimpleShape::m_values
std::vector< double > m_values
Definition: SimpleShape.h:68
LArSamples::ShapeInfo::nIntervals
unsigned int nIntervals() const
Definition: ShapeInfo.h:41
LArSamples::SimpleShape::m_timeInterval
double m_timeInterval
Definition: SimpleShape.h:69
keylayer_zslicemap.pb
pb
Definition: keylayer_zslicemap.py:188
SimpleShape.h
LArSamples::ShapeInfo::nPoints
unsigned int nPoints() const
Definition: ShapeInfo.h:37
LArSamples::SimpleShape::time
double time(unsigned int i) const
Definition: SimpleShape.cxx:58
LArSamples::ShapeInfo::phase
unsigned char phase(unsigned int i) const
Definition: ShapeInfo.cxx:66
LArSamples::AbsShape::value
virtual double value(unsigned int i) const =0
LArSamples::SimpleShape::createEmpty
SimpleShape * createEmpty() const
Definition: SimpleShape.cxx:100
lumiFormat.startTime
startTime
Definition: lumiFormat.py:102
LArSamples::SimpleShape
Definition: SimpleShape.h:25
LArSamples::SimpleShape::m_errors
std::vector< double > m_errors
Definition: SimpleShape.h:68
LArSamples::SimpleShape::nPoints
unsigned int nPoints() const
Definition: SimpleShape.h:48
LArSamples
Definition: AbsShape.h:24
yodamerge_tmp.scale
scale
Definition: yodamerge_tmp.py:138
LArSamples::ShapeInfo
Definition: ShapeInfo.h:24
LArSamples::ShapeInfo::value
double value(unsigned int i) const
Definition: ShapeInfo.cxx:58
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:797
ShapeInfo.h
LArSamples::SimpleShape::add
bool add(unsigned int k, double value, double error)
Definition: SimpleShape.cxx:92
LArSamples::SimpleShape::set
void set(unsigned int i, double value, double error=-1)
Definition: SimpleShape.h:53
LArSamples::SimpleShape::startTime
double startTime() const
Definition: SimpleShape.h:46
LArSamples::AbsShape::error
virtual double error(unsigned int i) const
Definition: AbsShape.cxx:24
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:193
lumiFormat.i
int i
Definition: lumiFormat.py:92
LArSamples::SimpleShape::timeInterval
double timeInterval() const
Definition: SimpleShape.h:45
h
extractSporadic.h
list h
Definition: extractSporadic.py:97
covarianceTool.title
title
Definition: covarianceTool.py:542
LArSamples::ShapeInfo::shift
float shift() const
Definition: ShapeInfo.h:42
mergePhysValFiles.errors
list errors
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:43
LArSamples::SimpleShape::histogram
TH1D * histogram(const char *name="shape", const char *title="", bool timeInUnitOfSamples=false) const
Definition: SimpleShape.cxx:106
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
LArSamples::SimpleShape::scaleAndShift
static bool scaleAndShift(SimpleShape *&s1, double scale, double shift=0)
Definition: SimpleShape.cxx:142
LArSamples::SimpleShape::m_startTime
double m_startTime
Definition: SimpleShape.h:69
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
LArSamples::AbsShape
Definition: AbsShape.h:28
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
ReadCellNoiseFromCoolCompare.s2
s2
Definition: ReadCellNoiseFromCoolCompare.py:379
LArSamples::Definitions::samplingInterval
static const unsigned int samplingInterval
Definition: Definitions.h:15
LArSamples::AbsShape::time
virtual double time(unsigned int i) const =0
LArSamples::SimpleShape::value
double value(unsigned int i) const
Definition: SimpleShape.h:49
error
Definition: IImpactPoint3dEstimator.h:70
LArSamples::AbsShape::values
TVectorD values(int lwb, int upb) const
Definition: AbsShape.cxx:135
LArSamples::AbsShape::interpolateDiff
int interpolateDiff(double time, double &diff) const
Definition: AbsShape.cxx:108
fitman.k
k
Definition: fitman.py:528
LArSamples::AbsShape::nPoints
virtual unsigned int nPoints() const =0
LArSamples::SimpleShape::diff
SimpleShape * diff() const
Definition: SimpleShape.cxx:64