54 TVectorD vect(
lwb(),
upb() + 1);
63 if (!r1.hasSameRange(r2)) {
64 cout <<
"WARNING : residuals have different ranges, this may crash the sorting..." << endl;
74 const double epsilon = 1E-5;
81 if (
m_sampling == r1.upb() + 1)
return r1.time() < r2.time() - epsilon;
82 cout <<
"WARNING : comparison on an unknown sample, this may crash the sorting..." << endl;
89 if (
size() == 0)
return false;
90 medians.ResizeTo(
lwb(),
upb() + 1);
91 widths.ResizeTo (
lwb(),
upb() + 1);
93 double halfSigmaQuantile = TMath::Prob(1,1)/2;
94 double medianQuantile = 0.5;
96 std::vector<Residual> sortedResiduals =
m_residuals;
98 for (
short i =
lwb(); i <=
upb() + 1; 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))];
133 double loHalfSigma = (i <
upb() + 1 ? loHalfSigmaRes.
scaledDelta(i) : loHalfSigmaRes.
time());
134 double hiHalfSigma = (i <
upb() + 1 ? hiHalfSigmaRes.
scaledDelta(i) : hiHalfSigmaRes.
time());
137 widths[i] = (hiHalfSigma - median > median - loHalfSigma ? median - loHalfSigma : hiHalfSigma - median);
146 TVectorD medians, widths;
150 for (
unsigned int i = 0; i < nMax; i++) original->
add(*
residual(i));
151 if (!original->
medianVars(medians, widths)) {
delete original;
return nullptr;}
155 if (!
medianVars(medians, widths))
return nullptr;
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]) {
169 if (nWidthsTime > 0 && TMath::Abs(
residual.time() - medians[
upb() + 1]) > nWidthsTime*widths[
upb() + 1])
continue;
178 TH1D*
h =
new TH1D(name,
"", nBins, xMin, xMax);
187 if (
size() == 0)
return nullptr;
199 for (
unsigned int i = 0; i <
size(); i++)
200 if (
event(i) == e &&
run(i) ==
r)
return i;
215 if (
find(residual.run(), residual.event()) >= 0)
return true;
216 add(residual.run(), residual.event());
228 int index =
find(residual.run(), residual.event());
229 if (
index == -1)
return true;
244 TVectorD xip(
lwb(),
upb());
247 if (
size() > 2) cout <<
"WARNING: variance of t < 1E-6, returning correction without derivative term. (V = " << denom <<
", N = " <<
size() <<
")" << endl;
251 TVectorD xip = TVectorD(
regresser()->covarianceMatrix()[
upb() + 1]).GetSub(
lwb(),
upb(),
"I");
254 TVectorD xipErrVect = TVectorD(
regresser()->covarianceMatrixErrors()[
upb() + 1]).GetSub(
lwb(),
upb(),
"I");
255 xipErrVect *= 1/denom;
257 for (
int k1 =
lwb(); k1 <=
upb(); k1++) xipErr(k1, k1) = TMath::Power(xipErrVect(k1), 2);
265 if (!
weigh())
return 1;
266 return TMath::Power(residual.adcMax(), 2);
273 return m_regresser.fill(residual.scaledDeltasAndTime(), w);
279 if (!
m_regresser.append(*other.regresser()))
return false;
283 for (
unsigned int i = 0; i < other.size(); i++)
add(other.run(i), other.event(i));
295 for (
unsigned int i = 0; i <
size(); i++)
296 str += Form(
"run %6d event %10d\n",
run(i),
event(i));
306 for (
unsigned int i = 0; i < 100000; i++) {
309 for (
unsigned short j = 0; j < 5; j++) d(j) =
r.Gaus(0, 1);
319 if (!truncated)
return false;
321 TH1D*
h = truncated->
histogram(0,
"h", 100, -5, 5);
double mean(unsigned int i) const
CovMatrix meanErrorMatrix() const
CovMatrix covarianceMatrix() const
void incrementInstanceCount() const
void decrementInstanceCount() const
bool isInRange(int i) const
bool fill(const Residual &residual)
bool add(int run, int event)
int find(int run, int event) const
double weight(const Residual &residual) const
TString description() const
unsigned int size() const
std::vector< int > m_runs
const Averager * regresser() const
bool append(const ResidualCalculator &other)
ShapeErrorData * shapeErrorData() const
bool remove(const Residual &residual)
int event(unsigned int i) const
bool fill_with_weight(const Residual &residual, double w)
std::vector< int > m_events
bool operator()(const Residual &r1, const Residual &r2) const
storage of a pulse shape residual set
TVectorD scaledDeltasAndTime() const
Residual(const TVectorD &deltas=TVectorD(), int run=0, int event=0, double adcMax=-1, double time=0)
const TVectorD & deltas() const
TVectorD scaledDeltas() const
double scaledDelta(short i) const
bool medianVars(TVectorD &medians, TVectorD &widths) const
unsigned int size() const
std::vector< Residual > m_residuals
Residuals * truncate(double nWidthsRes, double nWidthsTime=-1, unsigned int nMax=0) const
const Residual * residual(unsigned int i) const
bool add(const Residual &residual)
TH1D * histogram(short sample, const TString &name, int nBins, double xMin, double xMax) const
ResidualCalculator * calculator(bool weigh=false) const
TMatrixTSym< double > CovMatrix
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.