ATLAS Offline Software
Loading...
Searching...
No Matches
LArSamples::History Class Reference

#include <History.h>

Collaboration diagram for LArSamples::History:

Public Member Functions

 History (const HistoryContainer &container, std::vector< std::unique_ptr< const EventData > > &&eventData, unsigned int hash, const AbsShapeErrorGetter *shapeErrorGetter=0)
 Constructor.
 History (std::vector< std::unique_ptr< const Data > > &&data, const CellInfo &info, std::vector< std::unique_ptr< const EventData > > &&eventData, unsigned int hash, const AbsShapeErrorGetter *shapeErrorGetter=0)
virtual ~History ()
std::unique_ptr< HistoryContainerdissolve ()
unsigned int nData () const
const Datadata (unsigned int i) const
const Datadata_for_event (int event, int run=-1) const
const Datadata_for_event (const EventData &eventData) const
const CellInfocellInfo () const
const std::vector< std::unique_ptr< const EventData > > & eventData () const
bool sum (std::unique_ptr< SimpleShape > &sum, std::unique_ptr< SimpleShape > &reference) const
bool allShape (std::unique_ptr< GraphShape > &allData, std::unique_ptr< SimpleShape > &allRef) const
double allChi2 (Chi2Params pars) const
double chi2 (int i, int lwb=-1, int upb=-1, int chi2Params=DefaultChi2, ShapeErrorType shapeErrorType=BestShapeError, unsigned int *nDof=0) const
double chi2_k (int i, double k, int lwb=-1, int upb=-1, int chi2Params=DefaultChi2) const
double maxChi2 (int lwb=-1, int upb=-1, int chi2Params=DefaultChi2) const
std::unique_ptr< OFCofc (unsigned int i, int lwb=-1, int upb=-1, double time=Definitions::none, bool useCorrs=true) const
std::unique_ptr< Historyrefit (Chi2Params pars=DefaultChi2) const
std::unique_ptr< Historyadjust () const
std::unique_ptr< Historyfilter (const TString &cuts) const
bool refVal (unsigned int i, unsigned int sample, double &val, double &err) 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
bool isValid () const
TString description (unsigned int verbosity=1) const
std::unique_ptr< SimpleShapereferenceShape (unsigned int k, double adcMax=-1, double time=Definitions::none, bool samplesOnly=false) const
std::unique_ptr< SimpleShapedeltaShape (unsigned int k, int lwb=-1, int upb=-1) const
unsigned int hash () const
void setShapeErrorGetter (const AbsShapeErrorGetter *err) const
const AbsShapeErrorGettershapeErrorGetter () const
std::unique_ptr< const ShapeErrorDatashapeErrorData (CaloGain::CaloGain gain, ShapeErrorType shapeErrorType=BestShapeError, const Residual *res=0) const
std::unique_ptr< const ScaledErrorDatascaledErrorData (unsigned int i, double adcMax=-1, double time=Definitions::none, ShapeErrorType shapeErrorType=BestShapeError) const
bool residualOffset (unsigned int i, short sample, double &offset, double adcMax=-1, double time=Definitions::none) const
bool residualError (unsigned int i, short sample1, short sample2, double &offset, double adcMax=-1, double time=Definitions::none) const
bool drawWithReference (int i, const TString &atlasTitle="") const
bool drawSumWithReference () const
bool drawAllWithReference (bool refit=false) const
bool drawResiduals (int k=-1, bool errors=true, bool rescale=true) const
std::unique_ptr< AveragercalculatePedestal (int i) const
std::unique_ptr< Residualresidual (unsigned int k, bool correct=true, bool zeroTime=false) const
std::unique_ptr< Residualsresiduals (CaloGain::CaloGain gain=CaloGain::LARNGAIN, double absResTrunc=-1, bool correct=true, bool zeroTime=false) const
double upstreamEnergy (unsigned int k) const
double chi2Anomaly (double chi2Cut, unsigned int nDof=3) const
void setInterface (const Interface *interface) const

Private Attributes

std::vector< std::unique_ptr< const Data > > m_data
CellInfo m_cellInfo
std::vector< std::unique_ptr< const EventData > > m_eventData
unsigned int m_hash
const AbsShapeErrorGetterm_shapeErrorGetter
const Interfacem_interface = nullptr

Detailed Description

Definition at line 36 of file History.h.

Constructor & Destructor Documentation

◆ History() [1/2]

LArSamples::History::History ( const HistoryContainer & container,
std::vector< std::unique_ptr< const EventData > > && eventData,
unsigned int hash,
const AbsShapeErrorGetter * shapeErrorGetter = 0 )

Constructor.

◆ History() [2/2]

History::History ( std::vector< std::unique_ptr< const Data > > && data,
const CellInfo & info,
std::vector< std::unique_ptr< const EventData > > && eventData,
unsigned int hash,
const AbsShapeErrorGetter * shapeErrorGetter = 0 )

Definition at line 56 of file History.cxx.

60 : m_data(std::move(data)), m_cellInfo(info), m_eventData(std::move(eventData)), m_hash(hash),
62{
64 unsigned int i = 0;
65 for (std::unique_ptr<const Data>& pdata : m_data)
66 pdata->setCallBacks(this, i);
67}
std::vector< std::unique_ptr< const EventData > > m_eventData
Definition History.h:119
CellInfo m_cellInfo
Definition History.h:118
const AbsShapeErrorGetter * shapeErrorGetter() const
Definition History.h:94
unsigned int m_hash
Definition History.h:120
const AbsShapeErrorGetter * m_shapeErrorGetter
Definition History.h:121
const Data * data(unsigned int i) const
Definition History.cxx:88
std::vector< std::unique_ptr< const Data > > m_data
Definition History.h:117
unsigned int hash() const
Definition History.h:91
const std::vector< std::unique_ptr< const EventData > > & eventData() const
Definition History.h:61

◆ ~History()

History::~History ( )
virtual

Definition at line 70 of file History.cxx.

Member Function Documentation

◆ adjust()

std::unique_ptr< History > History::adjust ( ) const

Definition at line 250 of file History.cxx.

251{
252 std::vector<std::unique_ptr<const Data> > datas;
253 DataTweaker tw;
254 tw.setAdjust(true);
255
256 for (unsigned int j = 0; j < nData(); j++) {
257 std::unique_ptr<const Data> newData (tw.tweak(*data(j)));
258 if (!newData) {
259 return nullptr;
260 }
261 datas.push_back(std::move(newData));
262 }
263
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));
267
268 return std::make_unique<History>(std::move(datas), *cellInfo(), std::move(eventData), hash(), shapeErrorGetter());
269}
void setAdjust(bool adjust=true)
Definition DataTweaker.h:41
std::unique_ptr< Data > tweak(const Data &data, int evtIndex=-1) const
const CellInfo * cellInfo() const
Definition History.h:59
unsigned int nData() const
Definition History.h:54
float j(const xAOD::IParticle &, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d &jab_inv)

◆ allChi2()

double History::allChi2 ( Chi2Params pars) const

Definition at line 425 of file History.cxx.

426{
427 Chi2Calc c2c(pars);
428
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);
433 return chi2Value;
434}
bool allShape(std::unique_ptr< GraphShape > &allData, std::unique_ptr< SimpleShape > &allRef) const
Definition History.cxx:400

◆ allShape()

bool History::allShape ( std::unique_ptr< GraphShape > & allData,
std::unique_ptr< SimpleShape > & allRef ) const

Definition at line 400 of file History.cxx.

402{
403 allData.reset();
404 allRef.reset();
405
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());
410 if (allData) {
411 allData->add(*thisData);
412 }
413 else allData = std::move(thisData);
414 std::unique_ptr<SimpleShape> thisRef = referenceShape(j, 1); // normalized to 1, like the data
415 if (allRef) {
416 allRef->add(*thisRef);
417 }
418 else allRef = std::move(thisRef);
419 }
420
421 return true;
422}
std::unique_ptr< SimpleShape > referenceShape(unsigned int k, double adcMax=-1, double time=Definitions::none, bool samplesOnly=false) const
Definition History.cxx:527

◆ calculatePedestal()

std::unique_ptr< Averager > History::calculatePedestal ( int i) const

Definition at line 563 of file History.cxx.

564{
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;
568 std::unique_ptr<SimpleShape> reference = referenceShape(k);
569 if (!reference) continue;
570 double v,e;
571 for (unsigned int l = 0; l < data(k)->nPoints(); l++)
572 if (reference->interpolate(data(k)->time(l), v, e) == -1) { // we're before the ref shapeError
573 TVectorD ped(1);
574 ped(0) = data(k)->value(l);
575 avg->fill(ped);
576 }
577 }
578 return avg;
579}
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
time(flags, cells_name, *args, **kw)
l
Printing final latex table to .tex output file.
avg(a, b)
Definition Recovery.py:79

◆ cellInfo()

const CellInfo * LArSamples::History::cellInfo ( ) const
inline

Definition at line 59 of file History.h.

59{ return &m_cellInfo; }

◆ chi2()

double History::chi2 ( int i,
int lwb = -1,
int upb = -1,
int chi2Params = DefaultChi2,
ShapeErrorType shapeErrorType = BestShapeError,
unsigned int * nDof = 0 ) const

Definition at line 161 of file History.cxx.

162{
163 std::unique_ptr<SimpleShape> reference = referenceShape(i);
164 if (!reference) return -1;
165 Chi2Calc c2c(chi2Params);
166 if ( m_data[i]->isDisconnected()) return -1;
167 std::unique_ptr<const ScaledErrorData> sea = scaledErrorData(i, -1, Definitions::none, shapeErrorType);
168 if (!sea && shapeErrorType != NoShapeError && shapeErrorType != BestShapeError) return -1;
169 double chi2Value = c2c.chi2(*m_data[i], *reference, sea.get(), lwb, upb);
170 if (nDof) *nDof = c2c.nDof();
171 return chi2Value;
172}
std::unique_ptr< const ScaledErrorData > scaledErrorData(unsigned int i, double adcMax=-1, double time=Definitions::none, ShapeErrorType shapeErrorType=BestShapeError) const
Definition History.cxx:341

◆ chi2_k()

double History::chi2_k ( int i,
double k,
int lwb = -1,
int upb = -1,
int chi2Params = DefaultChi2 ) const

Definition at line 175 of file History.cxx.

176{
177 const AbsShapeErrorGetter* oldGetter = shapeErrorGetter();
178 UniformShapeErrorGetter uniGetter(k);
179 CombinedShapeErrorGetter combGetter;
180 if (oldGetter) combGetter.add(*oldGetter);
181 combGetter.add(uniGetter);
182 setShapeErrorGetter(&combGetter);
183 double chi2Value = chi2(i, lwb, upb, chi2Params);
184 setShapeErrorGetter(oldGetter);
185 return chi2Value;
186}
void add(const AbsShapeErrorGetter &getter)
double chi2(int i, int lwb=-1, int upb=-1, int chi2Params=DefaultChi2, ShapeErrorType shapeErrorType=BestShapeError, unsigned int *nDof=0) const
Definition History.cxx:161
void setShapeErrorGetter(const AbsShapeErrorGetter *err) const
Definition History.h:93

◆ chi2Anomaly()

double History::chi2Anomaly ( double chi2Cut,
unsigned int nDof = 3 ) const

Definition at line 637 of file History.cxx.

638{
639 if (nData() == 0 || chi2Cut <= 0) return -1;
640 double nBadChi2 = 0;
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;
647}

◆ data()

const Data * History::data ( unsigned int i) const

Definition at line 88 of file History.cxx.

89{
90 if (i >= nData()) return nullptr;
91 return m_data[i].get();
92}

◆ data_for_event() [1/2]

const Data * History::data_for_event ( const EventData & eventData) const

Definition at line 106 of file History.cxx.

107{
108 // turn off caching
109
110 //if (m_dataForEvent.size() == 0)
111 // for (unsigned int k = 0; k < nData(); k++)
112 // m_dataForEvent[data(k)->event()] = std::make_pair(data(k)->run(), data(k));
113
114 //std::unordered_map<int, std::pair<int, const Data*> >::const_iterator
115 // data = m_dataForEvent.find(eventData.event());
116 //if (data == m_dataForEvent.end()) return 0;
117 //if (data->second.first != eventData.run()) return data_for_event(eventData.event(), eventData.run()); // wrong run: revert to pedestrian method...
118 //return data->second.second;
119
120 return data_for_event(eventData.event(), eventData.run());
121}
const Data * data_for_event(int event, int run=-1) const
Definition History.cxx:95

◆ data_for_event() [2/2]

const Data * History::data_for_event ( int event,
int run = -1 ) const

Definition at line 95 of file History.cxx.

96{
97 for (unsigned int k = 0; k < nData(); k++) {
98 if (data(k)->event() != event) continue;
99 if (run > 0 && data(k)->run() != run) continue;
100 return data(k);
101 }
102 return nullptr;
103}
int run(int argc, char *argv[])

◆ delta()

bool History::delta ( unsigned int i,
unsigned int sample,
double & del ) const

Definition at line 357 of file History.cxx.

358{
359 if (k >= nData()) return 0;
360 TVectorD dv = deltas(k, sample, sample);
361 if (dv.GetNrows() == 0) return false;
362 del = dv[sample];
363 return true;
364}
TVectorD deltas(unsigned int i, int lwb=-1, int upb=-1, bool correct=true) const
Definition History.cxx:367

◆ deltas()

TVectorD History::deltas ( unsigned int i,
int lwb = -1,
int upb = -1,
bool correct = true ) const

Definition at line 367 of file History.cxx.

368{
369 if (k >= nData()) return TVectorD();
370 std::unique_ptr<SimpleShape> reference = referenceShape(k);
371 if (!reference) return TVectorD();
372 Chi2Calc c2c;
374 std::unique_ptr<const ScaledErrorData> sea = (correct ? scaledErrorData(k) : nullptr);
375 TVectorD dv = c2c.deltas(*data(k), *reference, errors, sea.get(), lwb, upb);
376 return dv;
377}
TVectorD deltas(const AbsShape &data, const AbsShape &reference, CovMatrix &errors, const ScaledErrorData *shapeError=0, int lwb=-1, int upb=-1, bool noDataError=false)
Definition Chi2Calc.cxx:36

◆ deltaShape()

std::unique_ptr< SimpleShape > History::deltaShape ( unsigned int k,
int lwb = -1,
int upb = -1 ) const

Definition at line 537 of file History.cxx.

538{
539 if (k >= nData()) return nullptr;
540 std::unique_ptr<SimpleShape> reference = referenceShape(k);
541 if (!reference) return nullptr;
542 Chi2Calc c2c;
544 std::unique_ptr<const ScaledErrorData> sea = scaledErrorData(k);
545 TVectorD dv = c2c.deltas(*data(k), *reference, errors, sea.get(), lwb, upb);
546 if (dv.GetNrows() == 0) return nullptr;
547 std::unique_ptr<SimpleShape> shape = std::make_unique<SimpleShape>(dv.GetNrows(), Definitions::samplingInterval, data(k)->time(c2c.lwb()) + data(k)->ofcTime());
548 for (int l = c2c.lwb(); l <= c2c.upb(); l++) shape->set(l - c2c.lwb(), dv(l), TMath::Sqrt(errors(l, l)));
549 return shape;
550}
int upb() const
Definition Chi2Calc.h:46
int lwb() const
Definition Chi2Calc.h:45

◆ description()

TString History::description ( unsigned int verbosity = 1) const

Definition at line 553 of file History.cxx.

554{
555 TString desc = "";
556 for (unsigned int i = 0; i < nData(); i++)
557 desc += Form(" #%-2d : ", i) + data(i)->description(verbosity) + "\n";
558 if (desc == "") return desc;
559 return cellInfo()->location(2) + "\n" + desc;
560}
TString location(int verbose=1) const
Definition CellInfo.cxx:139

◆ dissolve()

std::unique_ptr< HistoryContainer > History::dissolve ( )

Definition at line 76 of file History.cxx.

77{
78 auto histCont = std::make_unique<HistoryContainer>(new CellInfo(*cellInfo()));
79 for (unsigned int k = 0; k < nData(); k++) {
80 Data* newData = new Data(*data(k));
81 histCont->add(newData->dissolve());
82 }
83 delete this;
84 return histCont;
85}
@ Data
Definition BaseObject.h:11
const DataContainer * dissolve()
Definition Data.cxx:63

◆ drawAllWithReference()

bool History::drawAllWithReference ( bool refit = false) const

Definition at line 469 of file History.cxx.

470{
471 if (!nData()) {
472 cout << "No data" << endl;
473 return false;
474 }
475
476 if (doRefit) {
477 std::unique_ptr<History> refitted_history = refit(DefaultChi2);
478 if (!refitted_history) return false;
479 bool result = refitted_history->drawAllWithReference(false);
480 return result;
481 }
482
483 // Use the shape of the gain of the first pulse...
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;
487
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());
491 std::unique_ptr<const ScaledErrorData> sed = scaledErrorData(i, 1000);
492 if (sed) {
493 for (unsigned int k = 0; k < shape->nPoints(); k++)
494 if (sed->isInRange(k))
495 shape->set(k, shape->value(k) - sed->offsets()(k));
496 }
497 shapes.push_back(std::move(shape));
498 }
499
500 ShapeDrawer drawer(Legend);
501 return drawer.drawAndDelete(Form("%s (Normalized Shape, max at 1000)", cellInfo()->location(2).Data()), std::move(shapes), std::move(refShape), std::move(smpShape));
502}
std::unique_ptr< History > refit(Chi2Params pars=DefaultChi2) const
Definition History.cxx:227
bool isInRange(int i) const
Definition IndexRange.h:27
const TVectorD offsets(int first=-1, int last=-1) const
const ScaledErrorData * sed
@ DefaultChi2
Definition Chi2Calc.h:24

◆ drawResiduals()

bool History::drawResiduals ( int k = -1,
bool errors = true,
bool rescale = true ) const

Definition at line 505 of file History.cxx.

506{
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;
513 if (!errors)
514 for (unsigned int idx = 0; idx < shape->nPoints(); idx++) shape->setError(idx, 0);
515 if (rescale) {
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);
518 }
519 shapes.push_back(std::move(shape));
520 }
521 ShapeDrawer drawer(DataFirst);
522 TString title = (rescale ? "Normalized " : "") + TString("residuals for %s");
523 return drawer.drawAndDelete(Form(title.Data(), cellInfo()->location(2).Data()), std::move(shapes));
524}
std::unique_ptr< SimpleShape > deltaShape(unsigned int k, int lwb=-1, int upb=-1) const
Definition History.cxx:537

◆ drawSumWithReference()

bool History::drawSumWithReference ( ) const

Definition at line 458 of file History.cxx.

459{
460 std::unique_ptr<SimpleShape> dataShape;
461 std::unique_ptr<SimpleShape> refShape;
462 if (!sum(dataShape, refShape)) return false;
463
464 ShapeDrawer drawer(DataFirst | Legend);
465 return drawer.drawAndDelete("", std::move(dataShape), std::move(refShape));
466}
bool sum(std::unique_ptr< SimpleShape > &sum, std::unique_ptr< SimpleShape > &reference) const
Definition History.cxx:124

◆ drawWithReference()

bool History::drawWithReference ( int i,
const TString & atlasTitle = "" ) const

Definition at line 437 of file History.cxx.

438{
439 if ((unsigned int)k >= nData()) return false;
440 std::unique_ptr<SimpleShape> refShape = referenceShape(k);
441 std::unique_ptr<SimpleShape> smpShape = referenceShape(k, -1, Definitions::none, true);
442
443 if (!refShape || !smpShape) return false;
444 int pars = DataFirst | Legend;
445 TString title = "";
446 if (atlasTitle != "") { // Make sure AtlasStyle is set in ROOT, otherwise will not be as pretty...
447 pars |= AtlasStyle;
448 title = atlasTitle;
449 }
450 else
451 title = Form("%s, run %d, event %d", cellInfo()->location(1).Data(), m_data[k]->run(), m_data[k]->event());
452 ShapeDrawer drawer(pars);
453 bool result = drawer.draw(title, m_data[k].get(), refShape.get(), smpShape.get());
454 return result;
455}
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:130

◆ eventData()

const std::vector< std::unique_ptr< const EventData > > & LArSamples::History::eventData ( ) const
inline

Definition at line 61 of file History.h.

61{ return m_eventData; }

◆ filter()

std::unique_ptr< History > History::filter ( const TString & cuts) const

Definition at line 272 of file History.cxx.

273{
274 FilterParams f;
275 if (!f.set(cuts)) return nullptr;
276
277 std::vector<std::unique_ptr<const Data> > datas;
278
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)));
282 }
283
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));
287
288 return std::make_unique<History>(std::move(datas), *cellInfo(), std::move(eventData), hash(), shapeErrorGetter());
289}

◆ hash()

unsigned int LArSamples::History::hash ( ) const
inline

Definition at line 91 of file History.h.

91{ return m_hash; }

◆ isValid()

bool History::isValid ( ) const

Definition at line 149 of file History.cxx.

150{
151 if (!m_cellInfo.isValid()) return false;
152 if (nData() == 0) return false;
153
154 for (const std::unique_ptr<const Data>& data : m_data)
155 if (!data->isValid()) return false;
156
157 return true;
158}

◆ maxChi2()

double History::maxChi2 ( int lwb = -1,
int upb = -1,
int chi2Params = DefaultChi2 ) const

Definition at line 189 of file History.cxx.

190{
191 double maxChi2 = -2;
192 for (unsigned int i = 0; i < nData(); i++) {
193 double chi2Value = chi2(i, lwb, upb, chi2Params);
194 if (chi2Value > maxChi2) maxChi2 = chi2Value;
195 }
196 return maxChi2;
197}
double maxChi2(int lwb=-1, int upb=-1, int chi2Params=DefaultChi2) const
Definition History.cxx:189

◆ nData()

unsigned int LArSamples::History::nData ( ) const
inline

Definition at line 54 of file History.h.

54{ return m_data.size(); }

◆ ofc()

std::unique_ptr< OFC > History::ofc ( unsigned int i,
int lwb = -1,
int upb = -1,
double time = Definitions::none,
bool useCorrs = true ) const

Definition at line 201 of file History.cxx.

202{
203 if (k >= nData()) return nullptr;
204 if (Definitions::isNone(time)) {
205 time = data(k)->ofcTime();
206 //cout << "Using reference time = " << time << endl;
207 }
208 std::unique_ptr<SimpleShape> reference = referenceShape(k, 1, time); // ADC=1 : we need a normalized shape
209 if (!reference) return nullptr;
210 std::unique_ptr<const ShapeErrorData> sed = shapeErrorData(CaloGain::LARHIGHGAIN);
211 auto result = std::make_unique<OFC>(*reference, *m_data[k], lwb, upb, sed.get(), withAutoCorr); // FixMe
212 if (result->g().GetNrows() == 0) result.reset();
213 return result;
214}
std::unique_ptr< const ShapeErrorData > shapeErrorData(CaloGain::CaloGain gain, ShapeErrorType shapeErrorType=BestShapeError, const Residual *res=0) const
Definition History.cxx:293
@ LARHIGHGAIN
Definition CaloGain.h:18

◆ referenceShape()

std::unique_ptr< SimpleShape > History::referenceShape ( unsigned int k,
double adcMax = -1,
double time = Definitions::none,
bool samplesOnly = false ) const

Definition at line 527 of file History.cxx.

529{
530 if (!cellInfo()->shape(m_data[k]->gain())) return nullptr;
531 if (adcMax < 0) adcMax = m_data[k]->adcMax();
532 if (Definitions::isNone(time)) time = m_data[k]->ofcTime();
533 return std::make_unique<SimpleShape>(*cellInfo()->shape(m_data[k]->gain()), adcMax, time, samplesOnly);
534}

◆ refit()

std::unique_ptr< History > History::refit ( Chi2Params pars = DefaultChi2) const

Definition at line 227 of file History.cxx.

228{
229 std::vector<std::unique_ptr<const Data> > datas;
230 DataTweaker tw;
231 tw.setRefit(true);
232 tw.setFitParams(pars);
233
234 for (unsigned int j = 0; j < nData(); j++) {
235 std::unique_ptr<const Data> refitData (tw.tweak(*data(j)));
236 if (!refitData) {
237 return nullptr;
238 }
239 datas.push_back(std::move(refitData));
240 }
241
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));
245
246 return std::make_unique<History>(std::move(datas), *cellInfo(), std::move(eventData), hash(), shapeErrorGetter());
247}
void setRefit(bool refit=true)
Definition DataTweaker.h:39
void setFitParams(Chi2Params params)
Definition DataTweaker.h:40

◆ refVal()

bool History::refVal ( unsigned int i,
unsigned int sample,
double & val,
double & err ) const

Definition at line 217 of file History.cxx.

218{
219 if (k >= nData()) return false;
220 std::unique_ptr<SimpleShape> reference = referenceShape(k);
221 if (!reference) return false;
222 if (reference->interpolate(m_data[k]->time(sample), val, err) != 0) return false;
223 return true;
224}

◆ residual()

std::unique_ptr< Residual > History::residual ( unsigned int k,
bool correct = true,
bool zeroTime = false ) const

Definition at line 583 of file History.cxx.

584{
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() /*- Definitions::samplingTime(del.GetLwb()) */));
589}

◆ residualError()

bool History::residualError ( unsigned int i,
short sample1,
short sample2,
double & offset,
double adcMax = -1,
double time = Definitions::none ) const

Definition at line 390 of file History.cxx.

391{
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);
396 return true;
397}

◆ residualOffset()

bool History::residualOffset ( unsigned int i,
short sample,
double & offset,
double adcMax = -1,
double time = Definitions::none ) const

Definition at line 380 of file History.cxx.

381{
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);
386 return true;
387}

◆ residuals()

std::unique_ptr< Residuals > History::residuals ( CaloGain::CaloGain gain = CaloGain::LARNGAIN,
double absResTrunc = -1,
bool correct = true,
bool zeroTime = false ) const

Definition at line 593 of file History.cxx.

594{
595 Chi2Calc c2c;
596 CovMatrix dummyErrors;
597 auto residuals = std::make_unique<Residuals>();
598 for (unsigned int k = 0; k < nData(); k++) {
599 if (gain != CaloGain::LARNGAIN && data(k)->gain() != gain) continue;
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; }
602 if (residuals->size() > 0 && !residuals->hasSameRange(*res)) {
603 cout << "Warning for hash = " << m_hash << ", index = " << k << " : index interval changed from ["
604 << residuals->lwb() << ", " << residuals->upb() << "] to " << res->rangeStr() << endl;
605 return nullptr;
606 }
607 bool pass = true;
608 for (int i = res->lwb(); i < res->upb(); i++) {
609 if (absResCut > 0 && TMath::Abs(res->scaledDelta(i)) > absResCut) {
610 pass = false;
611 break;
612 }
613 }
614 if (pass) residuals->add(*res);
615 }
616 return residuals;
617}
std::pair< std::vector< unsigned int >, bool > res
std::unique_ptr< Residual > residual(unsigned int k, bool correct=true, bool zeroTime=false) const
Definition History.cxx:583
std::unique_ptr< Residuals > residuals(CaloGain::CaloGain gain=CaloGain::LARNGAIN, double absResTrunc=-1, bool correct=true, bool zeroTime=false) const
Definition History.cxx:593
@ LARNGAIN
Definition CaloGain.h:19

◆ scaledErrorData()

std::unique_ptr< const ScaledErrorData > History::scaledErrorData ( unsigned int i,
double adcMax = -1,
double time = Definitions::none,
ShapeErrorType shapeErrorType = BestShapeError ) const

Definition at line 341 of file History.cxx.

343{
344 if (shapeErrorType == NoShapeError || !shapeErrorGetter()) return nullptr;
345 if (k >= nData() || data(k)->adcMax() <= 0) return nullptr;
346
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;
350
351 double sf = (adcMax < 0 ? data(k)->adcMax() : adcMax);
352 double ts = (Definitions::isNone(time) ? data(k)->ofcTime() : time);
353 return std::make_unique<ScaledErrorData>(*sed, sf, ts);
354}
int ts
Definition globals.cxx:24

◆ setInterface()

void LArSamples::History::setInterface ( const Interface * interface) const
inline

Definition at line 113 of file History.h.

113{ m_interface = interface; }
const Interface * m_interface
Definition History.h:122

◆ setShapeErrorGetter()

void LArSamples::History::setShapeErrorGetter ( const AbsShapeErrorGetter * err) const
inline

Definition at line 93 of file History.h.

◆ shapeErrorData()

std::unique_ptr< const ShapeErrorData > History::shapeErrorData ( CaloGain::CaloGain gain,
ShapeErrorType shapeErrorType = BestShapeError,
const Residual * res = 0 ) const

Definition at line 293 of file History.cxx.

294{
295 if (shapeErrorType == NoShapeError || !shapeErrorGetter()) return nullptr;
296 if (shapeErrorType == BestShapeError) {
297 for (unsigned int i = 0; i < NShapeErrorTypes; i++) {
298 std::unique_ptr<const ShapeErrorData> sed = shapeErrorData(gain, (ShapeErrorType)i, res);
299 if (sed) return sed;
300 }
301 return nullptr;
302 }
303
304 if (shapeErrorType == CellShapeError) {
305 std::unique_ptr<ShapeErrorData> sed = shapeErrorGetter()->shapeErrorData(hash(), gain, res);
306 if (!sed) return nullptr;
308 return sed;
309 }
310
311 if (shapeErrorType == LowGainCellShapeError || shapeErrorType == MedGainCellShapeError || shapeErrorType == HighGainCellShapeError) {
314 std::unique_ptr<ShapeErrorData> sed = shapeErrorGetter()->shapeErrorData(hash(), fbGain, res);
315 if (!sed) return nullptr;
316 sed->setShapeErrorType(shapeErrorType);
317 return sed;
318 }
319
320 if (shapeErrorType == RingShapeError) {
321 std::unique_ptr<ShapeErrorData> sed = shapeErrorGetter()->phiSymShapeErrorData(cellInfo()->globalPhiRing(), gain, res);
322 if (!sed) return nullptr;
324 return sed;
325 }
326
327 if (shapeErrorType == LowGainRingShapeError || shapeErrorType == MedGainRingShapeError || shapeErrorType == HighGainRingShapeError) {
330 std::unique_ptr<ShapeErrorData> sed = shapeErrorGetter()->phiSymShapeErrorData(cellInfo()->globalPhiRing(), fbGain, res);
331 if (!sed) return nullptr;
332 sed->setShapeErrorType(shapeErrorType);
333 return sed;
334 }
335
336 return nullptr;
337}
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
void setShapeErrorType(ShapeErrorType type)
@ LARMEDIUMGAIN
Definition CaloGain.h:18
@ LARLOWGAIN
Definition CaloGain.h:18

◆ shapeErrorGetter()

const AbsShapeErrorGetter * LArSamples::History::shapeErrorGetter ( ) const
inline

Definition at line 94 of file History.h.

94{ return m_shapeErrorGetter; }

◆ sum()

bool History::sum ( std::unique_ptr< SimpleShape > & sum,
std::unique_ptr< SimpleShape > & reference ) const

Definition at line 124 of file History.cxx.

126{
127 reference.reset();
128 sum.reset();
129 if (nData() == 0) return false;
130
131 sum = std::make_unique<SimpleShape>(m_data[0]->nSamples());
132
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));
137 std::unique_ptr<SimpleShape> thisRef = referenceShape(j);
138 if (!thisRef) return false;
139 if (reference) {
140 reference->add(*thisRef);
141 }
142 else reference = std::move(thisRef);
143 }
144
145 return true;
146}

◆ upstreamEnergy()

double History::upstreamEnergy ( unsigned int k) const

Definition at line 620 of file History.cxx.

621{
622 if (!m_interface || !cellInfo()) return -1;
623 if (k >= nData()) return -1;
624 std::vector<unsigned int> upstreamNeighbors;
625 if (!m_interface->firstNeighbors(hash(), upstreamNeighbors, cellInfo()->layer() - 1)) return -1;
626 if (upstreamNeighbors.empty()) return -1;
627 std::vector<std::unique_ptr<const Data> > unData;
628 if (!m_interface->data(upstreamNeighbors, data(k)->eventData(), unData)) return -1;
629 double upstreamE = 0;
630 for (std::unique_ptr<const Data>& data : unData) {
631 upstreamE += data->energy();
632 }
633 return upstreamE;
634}
@ layer
Definition HitInfo.h:79

Member Data Documentation

◆ m_cellInfo

CellInfo LArSamples::History::m_cellInfo
private

Definition at line 118 of file History.h.

◆ m_data

std::vector<std::unique_ptr<const Data> > LArSamples::History::m_data
private

Definition at line 117 of file History.h.

◆ m_eventData

std::vector<std::unique_ptr<const EventData> > LArSamples::History::m_eventData
private

Definition at line 119 of file History.h.

◆ m_hash

unsigned int LArSamples::History::m_hash
private

Definition at line 120 of file History.h.

◆ m_interface

const Interface* LArSamples::History::m_interface = nullptr
mutableprivate

Definition at line 122 of file History.h.

◆ m_shapeErrorGetter

const AbsShapeErrorGetter* LArSamples::History::m_shapeErrorGetter
mutableprivate

Definition at line 121 of file History.h.


The documentation for this class was generated from the following files: