43 std::vector<std::unique_ptr<const EventData> >&& eventData,
unsigned hash,
46 m_eventData(
std::move(eventData)),
47 m_hash(
hash), m_shapeErrorGetter(shapeErrorGetter)
50 if (
container.nDataContainers() != m_eventData.size())
return;
51 for (
unsigned int i = 0;
i <
container.nDataContainers();
i++)
52 m_data.push_back(std::make_unique<Data>(*
container.dataContainer(i), *eventData[i],
this, i));
58 std::vector<std::unique_ptr<const EventData> >&&
eventData,
65 for (std::unique_ptr<const Data>& pdata :
m_data)
66 pdata->setCallBacks(
this, i);
78 auto histCont = std::make_unique<HistoryContainer>(
new CellInfo(*
cellInfo()));
79 for (
unsigned int k = 0; k <
nData(); k++) {
90 if (i >=
nData())
return nullptr;
97 for (
unsigned int k = 0; k <
nData(); k++) {
98 if (
data(k)->event() != event)
continue;
125 std::unique_ptr<SimpleShape>&
reference)
const
129 if (
nData() == 0)
return false;
131 sum = std::make_unique<SimpleShape>(
m_data[0]->nSamples());
133 for (
unsigned int j = 0; j <
nData(); j++) {
134 if (
sum->nPoints() !=
m_data[j]->nSamples())
return false;
135 for (
unsigned int k = 0; k <
m_data[j]->nSamples(); k++)
136 sum->add(k,
m_data[j]->pedestalSubtractedSample(k),
m_data[j]->error(k));
138 if (!thisRef)
return false;
152 if (
nData() == 0)
return false;
154 for (
const std::unique_ptr<const Data>&
data :
m_data)
155 if (!
data->isValid())
return false;
166 if (
m_data[i]->isDisconnected())
return -1;
170 if (nDof) *nDof = c2c.
nDof();
180 if (oldGetter) combGetter.
add(*oldGetter);
181 combGetter.
add(uniGetter);
183 double chi2Value =
chi2(i, lwb, upb, chi2Params);
192 for (
unsigned int i = 0; i <
nData(); i++) {
193 double chi2Value =
chi2(i, lwb, upb, chi2Params);
201History::ofc(
unsigned int k,
int lwb,
int upb,
double time,
bool withAutoCorr)
const
203 if (k >=
nData())
return nullptr;
205 time =
data(k)->ofcTime();
217bool History::refVal(
unsigned int k,
unsigned int sample,
double& val,
double& err)
const
219 if (k >=
nData())
return false;
222 if (
reference->interpolate(
m_data[k]->time(sample), val, err) != 0)
return false;
229 std::vector<std::unique_ptr<const Data> > datas;
234 for (
unsigned int j = 0; j <
nData(); j++) {
235 std::unique_ptr<const Data> refitData (tw.
tweak(*
data(j)));
239 datas.push_back(std::move(refitData));
242 std::vector<std::unique_ptr<const EventData> >
eventData;
243 for (
const std::unique_ptr<const EventData>& event :
m_eventData)
244 eventData.push_back(std::make_unique<EventData>(*event));
252 std::vector<std::unique_ptr<const Data> > datas;
256 for (
unsigned int j = 0; j <
nData(); j++) {
257 std::unique_ptr<const Data> newData (tw.
tweak(*
data(j)));
261 datas.push_back(std::move(newData));
264 std::vector<std::unique_ptr<const EventData> >
eventData;
265 for (
const std::unique_ptr<const EventData>& event :
m_eventData)
266 eventData.push_back(std::make_unique<EventData>(*event));
275 if (!f.set(cuts))
return nullptr;
277 std::vector<std::unique_ptr<const Data> > datas;
279 for (
unsigned int j = 0; j <
nData(); j++) {
280 if (!f.pass(
hash(), *
this, j))
continue;
281 datas.push_back(std::make_unique<Data>(*
data(j)));
284 std::vector<std::unique_ptr<const EventData> >
eventData;
285 for (
const std::unique_ptr<const EventData>& event :
m_eventData)
286 eventData.push_back(std::make_unique<EventData>(*event));
292std::unique_ptr<const ShapeErrorData>
306 if (!sed)
return nullptr;
315 if (!sed)
return nullptr;
322 if (!sed)
return nullptr;
331 if (!sed)
return nullptr;
340std::unique_ptr<const ScaledErrorData>
345 if (k >=
nData() ||
data(k)->adcMax() <= 0)
return nullptr;
347 std::unique_ptr<Residual>
res =
residual(k,
false);
348 std::unique_ptr<const ShapeErrorData> sed =
shapeErrorData(
data(k)->gain(), shapeErrorType,
res.get());
349 if (!sed)
return nullptr;
351 double sf = (adcMax < 0 ?
data(k)->adcMax() : adcMax);
353 return std::make_unique<ScaledErrorData>(*sed, sf,
ts);
359 if (k >=
nData())
return 0;
360 TVectorD dv =
deltas(k, sample, sample);
361 if (dv.GetNrows() == 0)
return false;
369 if (k >=
nData())
return TVectorD();
374 std::unique_ptr<const ScaledErrorData> sea = (correct ?
scaledErrorData(k) :
nullptr);
382 std::unique_ptr<const ScaledErrorData> sea =
scaledErrorData(k, adcMax, time);
383 if (!sea)
return false;
384 if (!sea->isInRange(sample))
return false;
385 offset = sea->offsets()(sample);
392 std::unique_ptr<const ScaledErrorData> sea =
scaledErrorData(k, adcMax, time);
393 if (!sea)
return false;
394 if (!sea->isInRange(sample1) || !sea->isInRange(sample2))
return false;
395 error = sea->errors()(sample1, sample2);
401 std::unique_ptr<SimpleShape>& allRef)
const
406 for (
unsigned int j = 0; j <
nData(); j++) {
407 if (
m_data[j]->isDisconnected())
continue;
408 if (
m_data[j]->adcMax() < 1)
continue;
409 auto thisData = std::make_unique<GraphShape>(*
m_data[j], 1/
m_data[j]->adcMax(), -
m_data[j]->ofcTime());
411 allData->add(*thisData);
413 else allData = std::move(thisData);
416 allRef->add(*thisRef);
418 else allRef = std::move(thisRef);
429 std::unique_ptr<GraphShape> allData;
430 std::unique_ptr<SimpleShape> allRef;
431 if (!
allShape(allData, allRef))
return -1;
432 double chi2Value = c2c.
chi2(*allData, *allRef);
439 if ((
unsigned int)k >=
nData())
return false;
443 if (!refShape || !smpShape)
return false;
446 if (atlasTitle !=
"") {
453 bool result = drawer.draw(title,
m_data[k].
get(), refShape.get(), smpShape.get());
460 std::unique_ptr<SimpleShape> dataShape;
461 std::unique_ptr<SimpleShape> refShape;
462 if (!
sum(dataShape, refShape))
return false;
465 return drawer.drawAndDelete(
"", std::move(dataShape), std::move(refShape));
472 cout <<
"No data" << endl;
478 if (!refitted_history)
return false;
479 bool result = refitted_history->drawAllWithReference(
false);
484 std::unique_ptr<SimpleShape> refShape =
referenceShape(0, 1000, 0);
485 std::unique_ptr<SimpleShape> smpShape =
referenceShape(0, 1000, 0,
true);
486 std::vector<std::unique_ptr<const AbsShape> > shapes;
488 for (
unsigned int i = 0; i <
nData(); i++) {
489 if (
m_data[i]->adcMax() < 1)
continue;
490 auto shape = std::make_unique<SimpleShape>(*
m_data[i], 1000/
m_data[i]->adcMax(), -
m_data[i]->ofcTime());
493 for (
unsigned int k = 0; k < shape->nPoints(); k++)
495 shape->set(k, shape->value(k) - sed->
offsets()(k));
497 shapes.push_back(std::move(shape));
501 return drawer.drawAndDelete(Form(
"%s (Normalized Shape, max at 1000)",
cellInfo()->location(2).
Data()), std::move(shapes), std::move(refShape), std::move(smpShape));
507 std::vector<std::unique_ptr<const AbsShape> > shapes;
508 for (
unsigned int i = 0; i <
nData(); i++) {
509 if (
m_data[i]->adcMax() < 1)
continue;
510 if (k >= 0 && k != (
int)i)
continue;
511 std::unique_ptr<SimpleShape> shape =
deltaShape(i);
512 if (!shape)
continue;
514 for (
unsigned int idx = 0; idx < shape->nPoints(); idx++) shape->setError(idx, 0);
516 auto scaled = std::make_unique<SimpleShape>(*shape, 1/
m_data[i]->adcMax(), 9.0*i/
nData() -
m_data[i]->ofcTime());
517 shape = std::move(scaled);
519 shapes.push_back(std::move(shape));
522 TString title = (rescale ?
"Normalized " :
"") + TString(
"residuals for %s");
523 return drawer.drawAndDelete(Form(title.Data(),
cellInfo()->location(2).
Data()), std::move(shapes));
528 bool samplesOnly)
const
531 if (adcMax < 0) adcMax =
m_data[k]->adcMax();
533 return std::make_unique<SimpleShape>(*
cellInfo()->shape(
m_data[k]->gain()), adcMax, time, samplesOnly);
539 if (k >=
nData())
return nullptr;
546 if (dv.GetNrows() == 0)
return nullptr;
548 for (
int l = c2c.
lwb(); l <= c2c.
upb(); l++) shape->set(l - c2c.
lwb(), dv(l), TMath::Sqrt(errors(l, l)));
556 for (
unsigned int i = 0; i <
nData(); i++)
557 desc += Form(
" #%-2d : ", i) +
data(i)->description(verbosity) +
"\n";
558 if (desc ==
"")
return desc;
565 auto avg = std::make_unique<Averager>(1);
566 for (
unsigned int k = 0; k <
nData(); k++) {
567 if (i >= 0 && i != (
int)k)
continue;
571 for (
unsigned int l = 0; l <
data(k)->nPoints(); l++)
574 ped(0) =
data(k)->value(l);
582std::unique_ptr<Residual>
585 if (k >=
nData())
return nullptr;
586 TVectorD del =
deltas(k, -1, -1, correct);
587 return std::make_unique<Residual>(del,
data(k)->
run(),
data(k)->event(),
data(k)->adcMax(),
588 (zeroTime ? 0 :
data(k)->ofcTime() ));
592std::unique_ptr<Residuals>
597 auto residuals = std::make_unique<Residuals>();
598 for (
unsigned int k = 0; k <
nData(); k++) {
600 auto res = std::unique_ptr<Residual>(
residual(k, correct, zeroTime));
601 if (!
res) { cout <<
"Error calculating residual for hash = " <<
m_hash <<
", index = " << k << endl;
return nullptr; }
603 cout <<
"Warning for hash = " <<
m_hash <<
", index = " << k <<
" : index interval changed from ["
608 for (
int i =
res->lwb(); i < res->upb(); i++) {
609 if (absResCut > 0 && TMath::Abs(
res->scaledDelta(i)) > absResCut) {
623 if (k >=
nData())
return -1;
624 std::vector<unsigned int> upstreamNeighbors;
626 if (upstreamNeighbors.empty())
return -1;
627 std::vector<std::unique_ptr<const Data> > unData;
629 double upstreamE = 0;
630 for (std::unique_ptr<const Data>&
data : unData) {
631 upstreamE +=
data->energy();
639 if (
nData() == 0 || chi2Cut <= 0)
return -1;
641 for (
unsigned int k = 0; k <
nData(); k++)
if (
chi2(k) > chi2Cut) nBadChi2++;
642 double effBad = nBadChi2/
nData();
643 double effRef = TMath::Prob(chi2Cut, nDof);
644 double dEff = sqrt(effRef*(1 - effRef))/sqrt(
nData());
645 if (dEff == 0) dEff = 1/sqrt(
nData());
646 return (effBad - effRef)/dEff;
char data[hepevt_bytes_allocation_ATLAS]
std::pair< std::vector< unsigned int >, bool > res
virtual std::unique_ptr< ShapeErrorData > phiSymShapeErrorData(short ring, CaloGain::CaloGain gain, const Residual *toExclude=0) const =0
virtual std::unique_ptr< ShapeErrorData > shapeErrorData(unsigned int hash, CaloGain::CaloGain gain, const Residual *toExclude=0) const =0
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)
void setAdjust(bool adjust=true)
std::unique_ptr< Data > tweak(const Data &data, int evtIndex=-1) const
const DataContainer * dissolve()
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
std::vector< std::unique_ptr< 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
std::unique_ptr< const ScaledErrorData > scaledErrorData(unsigned int i, double adcMax=-1, double time=Definitions::none, ShapeErrorType shapeErrorType=BestShapeError) const
std::unique_ptr< HistoryContainer > dissolve()
double chi2Anomaly(double chi2Cut, unsigned int nDof=3) const
std::unique_ptr< Averager > calculatePedestal(int i) const
std::unique_ptr< const ShapeErrorData > shapeErrorData(CaloGain::CaloGain gain, ShapeErrorType shapeErrorType=BestShapeError, const Residual *res=0) const
bool drawSumWithReference() const
History(const HistoryContainer &container, std::vector< std::unique_ptr< const EventData > > &&eventData, unsigned int hash, const AbsShapeErrorGetter *shapeErrorGetter=0)
Constructor.
const AbsShapeErrorGetter * shapeErrorGetter() const
bool allShape(std::unique_ptr< GraphShape > &allData, std::unique_ptr< SimpleShape > &allRef) const
bool refVal(unsigned int i, unsigned int sample, double &val, double &err) const
std::unique_ptr< Residual > residual(unsigned int k, bool correct=true, bool zeroTime=false) const
bool residualOffset(unsigned int i, short sample, double &offset, double adcMax=-1, double time=Definitions::none) const
std::unique_ptr< SimpleShape > referenceShape(unsigned int k, double adcMax=-1, double time=Definitions::none, bool samplesOnly=false) 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
const Interface * m_interface
const CellInfo * cellInfo() const
const AbsShapeErrorGetter * m_shapeErrorGetter
const Data * data(unsigned int i) const
void setShapeErrorGetter(const AbsShapeErrorGetter *err) const
bool drawResiduals(int k=-1, bool errors=true, bool rescale=true) const
unsigned int nData() const
std::vector< std::unique_ptr< const Data > > m_data
std::unique_ptr< History > filter(const TString &cuts) const
std::unique_ptr< OFC > ofc(unsigned int i, int lwb=-1, int upb=-1, double time=Definitions::none, bool useCorrs=true) const
std::unique_ptr< History > refit(Chi2Params pars=DefaultChi2) const
std::unique_ptr< Residuals > residuals(CaloGain::CaloGain gain=CaloGain::LARNGAIN, double absResTrunc=-1, bool correct=true, bool zeroTime=false) const
const Data * data_for_event(int event, int run=-1) const
bool sum(std::unique_ptr< SimpleShape > &sum, std::unique_ptr< SimpleShape > &reference) 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
std::unique_ptr< SimpleShape > deltaShape(unsigned int k, int lwb=-1, int upb=-1) const
const std::vector< std::unique_ptr< const EventData > > & eventData() const
std::unique_ptr< History > adjust() const
bool isInRange(int i) const
storage of a pulse shape residual set
const TVectorD offsets(int first=-1, int last=-1) const
void setShapeErrorType(ShapeErrorType type)
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
TMatrixTSym< double > CovMatrix
static bool isNone(double x)
static const unsigned int samplingInterval
int run(int argc, char *argv[])