43 const std::vector<const EventData*>& eventData,
unsigned hash,
46 m_eventData(eventData),
47 m_hash(
hash), m_shapeErrorGetter(shapeErrorGetter)
50 if (
container.nDataContainers() != eventData.size())
return;
51 for (
unsigned int i = 0;
i <
container.nDataContainers();
i++)
52 m_data.push_back(
new Data(*
container.dataContainer(i), *eventData[i],
this, i));
57 const std::vector<const EventData*>&
eventData,
65 pdata->setCallBacks(
this, i);
82 for (
unsigned int k = 0; k <
nData(); k++) {
93 if (i >=
nData())
return nullptr;
100 for (
unsigned int k = 0; k <
nData(); k++) {
101 if (
data(k)->event() != event)
continue;
130 if (
nData() == 0)
return false;
135 for (
unsigned int j = 0; j <
nData(); j++) {
136 if (
sum->nPoints() !=
m_data[j]->nSamples())
return false;
137 for (
unsigned int k = 0; k <
m_data[j]->nSamples(); k++)
138 sum->add(k,
m_data[j]->pedestalSubtractedSample(k),
m_data[j]->error(k));
140 if (!thisRef) {
delete sum;
return false; }
155 if (
nData() == 0)
return false;
158 if (!
data->isValid())
return false;
169 if (
m_data[i]->isDisconnected())
return -1;
173 if (nDof) *nDof = c2c.
nDof();
185 if (oldGetter) combGetter->
add(*oldGetter);
186 combGetter->
add(*uniGetter);
188 double chi2Value =
chi2(i, lwb, upb, chi2Params);
199 for (
unsigned int i = 0; i <
nData(); i++) {
200 double chi2Value =
chi2(i, lwb, upb, chi2Params);
207OFC*
History::ofc(
unsigned int k,
int lwb,
int upb,
double time,
bool withAutoCorr)
const
209 if (k >=
nData())
return nullptr;
211 time =
data(k)->ofcTime();
218 if (!
result)
return nullptr;
224bool History::refVal(
unsigned int k,
unsigned int sample,
double& val,
double& err)
const
226 if (k >=
nData())
return false;
237 std::vector<const Data*> datas;
242 for (
unsigned int j = 0; j <
nData(); j++) {
245 for (
unsigned int k = 0; k < datas.size(); k++)
delete datas[k];
248 datas.push_back(refitData);
261 std::vector<const Data*> datas;
265 for (
unsigned int j = 0; j <
nData(); j++) {
268 for (
unsigned int k = 0; k < datas.size(); k++)
delete datas[k];
271 datas.push_back(newData);
285 if (!f.set(cuts))
return nullptr;
287 std::vector<const Data*> datas;
289 for (
unsigned int j = 0; j <
nData(); j++) {
290 if (!f.pass(
hash(), *
this, j))
continue;
291 datas.push_back(
new Data(*
data(j)));
315 if (!sed)
return nullptr;
324 if (!sed)
return nullptr;
331 if (!sed)
return nullptr;
340 if (!sed)
return nullptr;
353 if (k >=
nData() ||
data(k)->adcMax() <= 0)
return nullptr;
356 if (!sed)
return nullptr;
358 double sf = (adcMax < 0 ?
data(k)->adcMax() : adcMax);
368 if (k >=
nData())
return 0;
369 TVectorD dv =
deltas(k, sample, sample);
370 if (dv.GetNrows() == 0)
return false;
378 if (k >=
nData())
return TVectorD();
394 if (!sea)
return false;
395 if (!sea->
isInRange(sample)) {
delete sea;
return false; }
396 offset = sea->
offsets()(sample);
405 if (!sea)
return false;
406 if (!sea->
isInRange(sample1) || !sea->
isInRange(sample2)) {
delete sea;
return false; }
418 for (
unsigned int j = 0; j <
nData(); j++) {
419 if (
m_data[j]->isDisconnected())
continue;
420 if (
m_data[j]->adcMax() < 1)
continue;
423 allData->
add(*thisData);
426 else allData = thisData;
429 allRef->
add(*thisRef);
432 else allRef = thisRef;
445 if (!
allShape(allData, allRef))
return -1;
446 double chi2Value = c2c.
chi2(*allData, *allRef);
455 if ((
unsigned int)k >=
nData())
return false;
459 if (!refShape || !smpShape)
return false;
462 if (atlasTitle !=
"") {
469 bool result = drawer.draw(title,
m_data[k], refShape.get(), smpShape.get());
477 if (!
sum(dataShape, refShape))
return false;
480 return drawer.drawAndDelete(
"", dataShape, refShape);
487 cout <<
"No data" << endl;
493 if (!refitted_history)
return false;
495 delete refitted_history;
502 std::vector<const AbsShape*> shapes;
504 for (
unsigned int i = 0; i <
nData(); i++) {
505 if (
m_data[i]->adcMax() < 1)
continue;
509 for (
unsigned int k = 0; k < shape->
nPoints(); k++)
514 shapes.push_back(shape);
518 return drawer.drawAndDelete(Form(
"%s (Normalized Shape, max at 1000)",
cellInfo()->location(2).
Data()), shapes, refShape, smpShape);
524 std::vector<const AbsShape*> shapes;
525 for (
unsigned int i = 0; i <
nData(); i++) {
526 if (
m_data[i]->adcMax() < 1)
continue;
527 if (k >= 0 && k != (
int)i)
continue;
530 for (
unsigned int idx = 0; idx < shape->
nPoints(); idx++) shape->
setError(idx, 0);
531 if (!shape)
continue;
537 shapes.push_back(shape);
540 TString title = (rescale ?
"Normalized " :
"") + TString(
"residuals for %s");
541 return drawer.drawAndDelete(Form(title.Data(),
cellInfo()->location(2).
Data()), shapes);
546 bool samplesOnly)
const
549 if (adcMax < 0) adcMax =
m_data[k]->adcMax();
558 if (k >=
nData())
return nullptr;
567 if (dv.GetNrows() == 0)
return nullptr;
569 for (
int l = c2c.
lwb(); l <= c2c.
upb(); l++) shape->
set(l - c2c.
lwb(), dv(l), TMath::Sqrt(errors(l, l)));
577 for (
unsigned int i = 0; i <
nData(); i++)
578 desc += Form(
" #%-2d : ", i) +
data(i)->description(verbosity) +
"\n";
579 if (desc ==
"")
return desc;
587 for (
unsigned int k = 0; k <
nData(); k++) {
588 if (i >= 0 && i != (
int)k)
continue;
592 for (
unsigned int l = 0; l <
data(k)->nPoints(); l++)
595 ped(0) =
data(k)->value(l);
606 if (k >=
nData())
return nullptr;
607 TVectorD del =
deltas(k, -1, -1, correct);
609 (zeroTime ? 0 :
data(k)->ofcTime() ));
617 auto residuals = std::make_unique<Residuals>();
618 for (
unsigned int k = 0; k <
nData(); k++) {
620 auto res = std::unique_ptr<Residual>(
residual(k, correct, zeroTime));
621 if (!
res) { cout <<
"Error calculating residual for hash = " <<
m_hash <<
", index = " << k << endl;
return nullptr; }
623 cout <<
"Warning for hash = " <<
m_hash <<
", index = " << k <<
" : index interval changed from ["
628 for (
int i =
res->lwb(); i < res->upb(); i++) {
629 if (absResCut > 0 && TMath::Abs(
res->scaledDelta(i)) > absResCut) {
644 std::vector<unsigned int> upstreamNeighbors;
646 if (upstreamNeighbors.empty())
return -1;
647 std::vector<const Data*> unData;
649 double upstreamE = 0;
651 upstreamE +=
data->energy();
660 if (
nData() == 0 || chi2Cut <= 0)
return -1;
662 for (
unsigned int k = 0; k <
nData(); k++)
if (
chi2(k) > chi2Cut) nBadChi2++;
663 double effBad = nBadChi2/
nData();
664 double effRef = TMath::Prob(chi2Cut, nDof);
665 double dEff = sqrt(effRef*(1 - effRef))/sqrt(
nData());
666 if (dEff == 0) dEff = 1/sqrt(
nData());
667 return (effBad - effRef)/dEff;
char data[hepevt_bytes_allocation_ATLAS]
std::pair< std::vector< unsigned int >, bool > res
virtual ShapeErrorData * shapeErrorData(unsigned int hash, CaloGain::CaloGain gain, const Residual *toExclude=0) const =0
virtual ShapeErrorData * phiSymShapeErrorData(short ring, CaloGain::CaloGain gain, const Residual *toExclude=0) const =0
storage of the time histories of all the cells
TString location(int verbose=1) const
TVectorD deltas(const AbsShape &data, const AbsShape &reference, CovMatrix &errors, const ScaledErrorData *shapeError=0, int lwb=-1, int upb=-1, bool noDataError=false)
double chi2(const AbsShape &data, const AbsShape &reference, const ScaledErrorData *shapeError=0, int lwb=-1, int upb=-1)
unsigned int nDof() const
void incrementInstanceCount() const
void decrementInstanceCount() const
void add(const AbsShapeErrorGetter &getter)
void setRefit(bool refit=true)
void setFitParams(Chi2Params params)
Data * tweak(const Data &data, int evtIndex=-1) const
void setAdjust(bool adjust=true)
const DataContainer * dissolve()
bool add(const AbsShape &other)
void add(const DataContainer *data)
append data (takes ownership)
bool sum(SimpleShape *&sum, SimpleShape *&reference) const
OFC * ofc(unsigned int i, int lwb=-1, int upb=-1, double time=Definitions::none, bool useCorrs=true) const
bool drawWithReference(int i, const TString &atlasTitle="") const
TString description(unsigned int verbosity=1) const
double chi2_k(int i, double k, int lwb=-1, int upb=-1, int chi2Params=DefaultChi2) const
const ScaledErrorData * scaledErrorData(unsigned int i, double adcMax=-1, double time=Definitions::none, ShapeErrorType shapeErrorType=BestShapeError) const
std::vector< const EventData * > m_eventData
double chi2(int i, int lwb=-1, int upb=-1, int chi2Params=DefaultChi2, ShapeErrorType shapeErrorType=BestShapeError, unsigned int *nDof=0) const
History(const HistoryContainer &container, const std::vector< const EventData * > &eventData, unsigned int hash, const AbsShapeErrorGetter *shapeErrorGetter=0)
Constructor.
double chi2Anomaly(double chi2Cut, unsigned int nDof=3) const
bool drawSumWithReference() const
bool allShape(GraphShape *&allData, SimpleShape *&allRef) const
SimpleShape * deltaShape(unsigned int k, int lwb=-1, int upb=-1) const
const std::vector< const EventData * > & eventData() const
const AbsShapeErrorGetter * shapeErrorGetter() const
SimpleShape * referenceShape(unsigned int k, double adcMax=-1, double time=Definitions::none, bool samplesOnly=false) const
bool refVal(unsigned int i, unsigned int sample, double &val, double &err) const
Residuals * residuals(CaloGain::CaloGain gain=CaloGain::LARNGAIN, double absResTrunc=-1, bool correct=true, bool zeroTime=false) const
bool residualOffset(unsigned int i, short sample, double &offset, double adcMax=-1, double time=Definitions::none) const
bool delta(unsigned int i, unsigned int sample, double &del) const
TVectorD deltas(unsigned int i, int lwb=-1, int upb=-1, bool correct=true) const
Residual * residual(unsigned int k, bool correct=true, bool zeroTime=false) const
Averager * calculatePedestal(int i) const
const Interface * m_interface
const CellInfo * cellInfo() const
const AbsShapeErrorGetter * m_shapeErrorGetter
const ShapeErrorData * shapeErrorData(CaloGain::CaloGain gain, ShapeErrorType shapeErrorType=BestShapeError, const Residual *res=0) const
std::vector< const Data * > m_data
const Data * data(unsigned int i) const
HistoryContainer * dissolve()
void setShapeErrorGetter(const AbsShapeErrorGetter *err) const
bool drawResiduals(int k=-1, bool errors=true, bool rescale=true) const
History * filter(const TString &cuts) const
unsigned int nData() const
History * refit(Chi2Params pars=DefaultChi2) const
const Data * data_for_event(int event, int run=-1) const
double allChi2(Chi2Params pars) const
bool drawAllWithReference(bool refit=false) const
unsigned int hash() const
bool residualError(unsigned int i, short sample1, short sample2, double &offset, double adcMax=-1, double time=Definitions::none) const
double upstreamEnergy(unsigned int k) const
double maxChi2(int lwb=-1, int upb=-1, int chi2Params=DefaultChi2) const
bool isInRange(int i) const
storage of a pulse shape residual set
const TVectorD offsets(int first=-1, int last=-1) const
const CovMatrix errors(int first=-1, int last=-1) const
void setShapeErrorType(ShapeErrorType type)
bool add(unsigned int k, double value, double error)
unsigned int nPoints() const
void set(unsigned int i, double value, double error=-1)
void setError(unsigned int i, double error)
double value(unsigned int i) const
TMatrixTSym< double > CovMatrix
static bool isNone(double x)
static const unsigned int samplingInterval