ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
LArSamples::Residuals Class Reference

#include <Residual.h>

Inheritance diagram for LArSamples::Residuals:
Collaboration diagram for LArSamples::Residuals:

Public Member Functions

 Residuals ()
 
 Residuals (const std::vector< Residual > &r)
 
virtual ~Residuals ()
 
unsigned int size () const
 
const Residualresidual (unsigned int i) const
 
int lwb () const
 
int upb () const
 
bool add (const Residual &residual)
 
bool medianVars (TVectorD &medians, TVectorD &widths) const
 
Residualstruncate (double nWidthsRes, double nWidthsTime=-1, unsigned int nMax=0) const
 
ResidualCalculatorcalculator (bool weigh=false) const
 
TH1D * histogram (short sample, const TString &name, int nBins, double xMin, double xMax) const
 
bool isInRange (int i) const
 
bool hasSameRange (int lw, int up) const
 
bool hasSameRange (const IndexRange &other) const
 
bool hasSameRange (const TVectorD &v) const
 
bool providesRange (int lw, int up) const
 
bool providesRange (const IndexRange &other) const
 
bool providesRange (const TVectorD &v) const
 
TString rangeStr () const
 
int commonLwb (const IndexRange &other) const
 
int commonUpb (const IndexRange &other) const
 
bool checkRange (int &l, int &h) const
 

Private Attributes

std::vector< Residualm_residuals
 

Detailed Description

Definition at line 71 of file LArCalorimeter/LArSamplesMon/LArSamplesMon/Residual.h.

Constructor & Destructor Documentation

◆ Residuals() [1/2]

LArSamples::Residuals::Residuals ( )
inline

Definition at line 74 of file LArCalorimeter/LArSamplesMon/LArSamplesMon/Residual.h.

74 { }

◆ Residuals() [2/2]

LArSamples::Residuals::Residuals ( const std::vector< Residual > &  r)
inline

Definition at line 75 of file LArCalorimeter/LArSamplesMon/LArSamplesMon/Residual.h.

76  : m_residuals(r) { }

◆ ~Residuals()

virtual LArSamples::Residuals::~Residuals ( )
inlinevirtual

Definition at line 78 of file LArCalorimeter/LArSamplesMon/LArSamplesMon/Residual.h.

78 { }

Member Function Documentation

◆ add()

bool LArSamples::Residuals::add ( const Residual residual)
inline

Definition at line 86 of file LArCalorimeter/LArSamplesMon/LArSamplesMon/Residual.h.

86 { m_residuals.push_back(residual); return true; }

◆ calculator()

ResidualCalculator * Residuals::calculator ( bool  weigh = false) const

Definition at line 185 of file LArCalorimeter/LArSamplesMon/src/Residual.cxx.

186 {
187  if (size() == 0) return nullptr;
188 
189  ResidualCalculator* calc = new ResidualCalculator(lwb(), upb(), weigh);
190  for (const Residual& residual : m_residuals)
191  calc->fill(residual);
192 
193  return calc;
194 }

◆ checkRange()

bool IndexRange::checkRange ( int &  l,
int &  h 
) const
inherited

Definition at line 14 of file IndexRange.cxx.

15 {
16  if (l < 0)
17  l = lwb();
18  else if (!isInRange(l)) {
19  cout << "IndexRange::checkRange : lower bound " << l << " is out of bounds" << endl;
20  return false;
21  }
22 
23  if (h < 0)
24  h = upb();
25  else if (!isInRange(h)) {
26  cout << "IndexRange::checkRange : upper bound " << h << " is out of bounds" << endl;
27  return false;
28  }
29 
30  return true;
31 }

◆ commonLwb()

int LArSamples::IndexRange::commonLwb ( const IndexRange other) const
inlineinherited

Definition at line 39 of file IndexRange.h.

39 { return (other.lwb() > lwb() ? other.lwb() : lwb()); }

◆ commonUpb()

int LArSamples::IndexRange::commonUpb ( const IndexRange other) const
inlineinherited

Definition at line 40 of file IndexRange.h.

40 { return (other.upb() < upb() ? other.upb() : upb()); }

◆ hasSameRange() [1/3]

bool LArSamples::IndexRange::hasSameRange ( const IndexRange other) const
inlineinherited

Definition at line 30 of file IndexRange.h.

30 { return hasSameRange(other.lwb(), other.upb()); }

◆ hasSameRange() [2/3]

bool LArSamples::IndexRange::hasSameRange ( const TVectorD &  v) const
inlineinherited

Definition at line 31 of file IndexRange.h.

31 { return hasSameRange(v.GetLwb(), v.GetUpb()); }

◆ hasSameRange() [3/3]

bool LArSamples::IndexRange::hasSameRange ( int  lw,
int  up 
) const
inlineinherited

Definition at line 29 of file IndexRange.h.

29 { return (lwb() == lw && upb() == up); }

◆ histogram()

TH1D * Residuals::histogram ( short  sample,
const TString &  name,
int  nBins,
double  xMin,
double  xMax 
) const

Definition at line 176 of file LArCalorimeter/LArSamplesMon/src/Residual.cxx.

177 {
178  TH1D* h = new TH1D(name, "", nBins, xMin, xMax);
179  for (const Residual& residual : m_residuals)
180  h->Fill(sample <= upb() ? residual.scaledDelta(sample) : residual.time());
181  return h;
182 }

◆ isInRange()

bool LArSamples::IndexRange::isInRange ( int  i) const
inlineinherited

Definition at line 27 of file IndexRange.h.

27 { return (i >= lwb() && i <= upb()); }

◆ lwb()

int LArSamples::Residuals::lwb ( ) const
inlinevirtual

Implements LArSamples::IndexRange.

Definition at line 83 of file LArCalorimeter/LArSamplesMon/LArSamplesMon/Residual.h.

83 { return (size() > 0 ? residual(0)->lwb() : 0); }

◆ medianVars()

bool Residuals::medianVars ( TVectorD &  medians,
TVectorD &  widths 
) const

Definition at line 87 of file LArCalorimeter/LArSamplesMon/src/Residual.cxx.

88 {
89  if (size() == 0) return false;
90  medians.ResizeTo(lwb(), upb() + 1);
91  widths.ResizeTo (lwb(), upb() + 1);
92 
93  double halfSigmaQuantile = TMath::Prob(1,1)/2;
94  double medianQuantile = 0.5;
95 
96  std::vector<Residual> sortedResiduals = m_residuals;
97 
98  for (short i = lwb(); i <= upb() + 1; i++) {
99 // cout << "test-sorting sample " << i << " (n = " << m_residuals.size() << ")" << endl;
100 // std::vector<const Residual*> testSort(m_residuals.size());
101 // ResidualCompare comparer(i);
102 // for (unsigned int i1 = 0; i1 < m_residuals.size(); i1++) {
103 // const Residual& res1 = m_residuals[i1];
104 // unsigned int nBefore = 0;
105 // for (unsigned int i2 = 0; i2 < m_residuals.size(); i2++) {
106 // if (i1 == i2) continue;
107 // const Residual& res2 = m_residuals[i2];
108 // //cout << "comparing " << i1 << " " << i2 << endl;
109 // if (comparer(res2, res1)) nBefore++;
110 // if ((i1 == 3617 || i1 == 3886) && comparer(res2, res1))
111 // cout << i2 << " is bfore " << i1 << " " << res2.scaledDelta(i) << " < " << res1.scaledDelta(i)
112 // << (res2.scaledDelta(i) < res1.scaledDelta(i)) << " " << (res2.scaledDelta(i) < res1.scaledDelta(i) - 1E-3) << endl;
113 // }
114 // cout << "index " << i1 << " : nBefore = " << nBefore << " " << res1.scaledDelta(i) << endl;
115 // while (testSort[nBefore]) { nBefore++; if (nBefore == testSort.size()) cout << "ERROR!!! " << i1 << endl; }
116 // testSort[nBefore] = &res1;
117 // }
118 // cout << "done sorting" << endl;
119 // for (unsigned int i1 = 0; i1 < testSort.size(); i1++) {
120 // const Residual* res1 = testSort[i1];
121 // if (!res1) cout << "ERROR : null at index " << i1 << endl;
122 // for (unsigned int i2 = 0; i2 < i1; i2++) {
123 // const Residual* res2 = testSort[i2];
124 // if (comparer(*res1, *res2)) cout << "Wrong order " << i1 << " " << i2 << endl;
125 // }
126 // }
127 // cout << "done checking" << endl;
128  std::sort(sortedResiduals.begin(), sortedResiduals.end(), ResidualCompare(i));
129  Residual& medianRes = sortedResiduals[(unsigned int)(sortedResiduals.size()*medianQuantile)];
130  Residual& loHalfSigmaRes = sortedResiduals[(unsigned int)(sortedResiduals.size()*halfSigmaQuantile)];
131  Residual& hiHalfSigmaRes = sortedResiduals[(unsigned int)(sortedResiduals.size()*(1 - halfSigmaQuantile))];
132  double median = (i < upb() + 1 ? medianRes.scaledDelta(i) : medianRes.time()) ;
133  double loHalfSigma = (i < upb() + 1 ? loHalfSigmaRes.scaledDelta(i) : loHalfSigmaRes.time());
134  double hiHalfSigma = (i < upb() + 1 ? hiHalfSigmaRes.scaledDelta(i) : hiHalfSigmaRes.time());
135  //cout << loHalfSigma << " " << median << " " << hiHalfSigma << endl;
136  medians[i] = median;
137  widths[i] = (hiHalfSigma - median > median - loHalfSigma ? median - loHalfSigma : hiHalfSigma - median);
138  }
139  return true;
140 }

◆ providesRange() [1/3]

bool LArSamples::IndexRange::providesRange ( const IndexRange other) const
inlineinherited

Definition at line 34 of file IndexRange.h.

34 { return providesRange(other.lwb(), other.upb()); }

◆ providesRange() [2/3]

bool LArSamples::IndexRange::providesRange ( const TVectorD &  v) const
inlineinherited

Definition at line 35 of file IndexRange.h.

35 { return providesRange(v.GetLwb(), v.GetUpb()); }

◆ providesRange() [3/3]

bool LArSamples::IndexRange::providesRange ( int  lw,
int  up 
) const
inlineinherited

Definition at line 33 of file IndexRange.h.

33 { return (lwb() <= lw && upb() >= up); }

◆ rangeStr()

TString LArSamples::IndexRange::rangeStr ( ) const
inlineinherited

Definition at line 37 of file IndexRange.h.

37 { return Form("[%d, %d]", lwb(), upb()); }

◆ residual()

const Residual* LArSamples::Residuals::residual ( unsigned int  i) const
inline

Definition at line 81 of file LArCalorimeter/LArSamplesMon/LArSamplesMon/Residual.h.

81 { return (i < size() ? &m_residuals[i] : 0); }

◆ size()

unsigned int LArSamples::Residuals::size ( ) const
inline

Definition at line 80 of file LArCalorimeter/LArSamplesMon/LArSamplesMon/Residual.h.

80 { return m_residuals.size(); }

◆ truncate()

Residuals * Residuals::truncate ( double  nWidthsRes,
double  nWidthsTime = -1,
unsigned int  nMax = 0 
) const

Definition at line 143 of file LArCalorimeter/LArSamplesMon/src/Residual.cxx.

144 {
145  if (size() == 0) return new Residuals();
146  TVectorD medians, widths;
147 
148  if (nMax > 0) {
149  Residuals* original = new Residuals();
150  for (unsigned int i = 0; i < nMax; i++) original->add(*residual(i));
151  if (!original->medianVars(medians, widths)) { delete original; return nullptr;}
152  delete original;
153  }
154  else {
155  if (!medianVars(medians, widths)) return nullptr;
156  }
157  Residuals* truncated = new Residuals();
158 
159  for (const Residual& residual : m_residuals) {
160  bool pass = true;
161  if (nMax > 0 && truncated->size() == nMax) break;
162  for (short i = lwb(); i <= upb(); i++) {
163  if (nWidthsRes > 0 && TMath::Abs(residual.scaledDelta(i) - medians[i]) > nWidthsRes*widths[i]) {
164  pass = false;
165  break;
166  }
167  }
168  if (!pass) continue;
169  if (nWidthsTime > 0 && TMath::Abs(residual.time() - medians[upb() + 1]) > nWidthsTime*widths[upb() + 1]) continue;
170  truncated->add(residual);
171  }
172  return truncated;
173 }

◆ upb()

int LArSamples::Residuals::upb ( ) const
inlinevirtual

Implements LArSamples::IndexRange.

Definition at line 84 of file LArCalorimeter/LArSamplesMon/LArSamplesMon/Residual.h.

84 { return (size() > 0 ? residual(0)->upb() : 0); }

Member Data Documentation

◆ m_residuals

std::vector<Residual> LArSamples::Residuals::m_residuals
private

The documentation for this class was generated from the following files:
beamspotman.r
def r
Definition: beamspotman.py:676
LArSamples::IndexRange::upb
virtual int upb() const =0
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
LArSamples::Residuals::residual
const Residual * residual(unsigned int i) const
Definition: LArCalorimeter/LArSamplesMon/LArSamplesMon/Residual.h:81
LArSamples::Residuals::m_residuals
std::vector< Residual > m_residuals
Definition: LArCalorimeter/LArSamplesMon/LArSamplesMon/Residual.h:96
LArSamples::Residuals::medianVars
bool medianVars(TVectorD &medians, TVectorD &widths) const
Definition: LArCalorimeter/LArSamplesMon/src/Residual.cxx:87
python.LumiCalcWorking.lw
lw
Definition: LumiCalcWorking.py:112
LArSamples::IndexRange::hasSameRange
bool hasSameRange(int lw, int up) const
Definition: IndexRange.h:29
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
InDet::median
float median(std::vector< float > &Vec)
Definition: BTagVrtSec.cxx:35
LArSamples::ResidualCalculator
Definition: LArCalorimeter/LArSamplesMon/LArSamplesMon/Residual.h:101
LArSamples::IndexRange::isInRange
bool isInRange(int i) const
Definition: IndexRange.h:27
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:116
lumiFormat.i
int i
Definition: lumiFormat.py:85
h
extractSporadic.h
list h
Definition: extractSporadic.py:97
CalibCoolCompareRT.up
up
Definition: CalibCoolCompareRT.py:109
LArSamples::Residual::scaledDelta
double scaledDelta(short i) const
Definition: LArCalorimeter/LArSamplesMon/src/Residual.cxx:45
LArSamples::Residual
storage of a pulse shape residual set
Definition: LArCalorimeter/LArSamplesMon/LArSamplesMon/Residual.h:29
LArSamples::Residuals
Definition: LArCalorimeter/LArSamplesMon/LArSamplesMon/Residual.h:72
dumpTgcDigiJitter.nBins
list nBins
Definition: dumpTgcDigiJitter.py:29
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
LArSamples::IndexRange::lwb
virtual int lwb() const =0
python.PyAthena.v
v
Definition: PyAthena.py:154
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
std::sort
void sort(typename std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, typename std::reverse_iterator< DataModel_detail::iterator< DVL > > end, const Compare &comp)
Specialization of sort for DataVector/List.
Definition: DVL_algorithms.h:623
LArSamples::Residuals::size
unsigned int size() const
Definition: LArCalorimeter/LArSamplesMon/LArSamplesMon/Residual.h:80
LArSamples::Residuals::add
bool add(const Residual &residual)
Definition: LArCalorimeter/LArSamplesMon/LArSamplesMon/Residual.h:86
LArSamples::Residuals::upb
int upb() const
Definition: LArCalorimeter/LArSamplesMon/LArSamplesMon/Residual.h:84
LArSamples::IndexRange::providesRange
bool providesRange(int lw, int up) const
Definition: IndexRange.h:33
beamspotnt.calc
calc
Definition: bin/beamspotnt.py:1252
LArSamples::Residuals::lwb
int lwb() const
Definition: LArCalorimeter/LArSamplesMon/LArSamplesMon/Residual.h:83
LArSamples::ResidualCompare
Definition: LArCalorimeter/LArSamplesMon/LArSamplesMon/Residual.h:61
LArSamples::Residual::time
double time() const
Definition: LArCalorimeter/LArSamplesMon/LArSamplesMon/Residual.h:42
LArSamples::Residuals::Residuals
Residuals()
Definition: LArCalorimeter/LArSamplesMon/LArSamplesMon/Residual.h:74