ATLAS Offline Software
Loading...
Searching...
No Matches
DataTweaker.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
13#include "LArSamplesMon/OFC.h"
14
15#include <fstream>
16#include <iostream>
17using std::cout;
18using std::endl;
19
20using namespace LArSamples;
21
22
23bool DataTweaker::set(const TString& tweaks)
24{
25 TString toMod = tweaks;
26
27 if (findOption(toMod, "removeNoiseCorrelations")) { m_removeNoiseCorrelations = true; cout << "--> removeNoiseCorrelations" << endl; }
28 if (findOption(toMod, "refit")) { m_refit = true; cout << "--> refit" << endl; }
29 if (findOption(toMod, "adjust")) { m_adjust = true; cout << "--> adjust" << endl; }
30 if (findOption(toMod, "removeRoIs")) { m_removeRoIs = true; cout << "--> removeRoIs" << endl; }
31
32 if (toMod == "") return true;
33 cout << "Invalid tweaker option(s) " << toMod << endl;
34 return false;
35}
36
37
38bool DataTweaker::findOption(TString& tweaks, const TString& option) const
39{
40 int i = tweaks.Index(option);
41 if (i < 0) return false;
42 tweaks = tweaks(0, i) + tweaks(i + option.Length(), tweaks.Length() - i - option.Length());
43 return true;
44}
45
46
47Data* DataTweaker::tweak(const Data& data, int evtIndex) const
48{
49 std::vector<short> samples = data.container().samples();
50 std::vector<float> corrs = data.container().corrs();
51 float time = data.container().ofcTime();
52 double k = 1, deltaT = 0;
53
55 for (unsigned int i = 1; i < corrs.size(); i++) corrs[i] = 0;
56
57 if (m_nSamplesTruncation > 0) {
58 unsigned int maxIndex = data.maxPosition();
59
60 int i1 = maxIndex - (m_nSamplesTruncation - 1)/2;
61 if (i1 < 0) i1 = 0;
62
63 int i2 = maxIndex + m_nSamplesTruncation/2 + 1;
64 if (i2 > (int)data.nSamples()) i2 = (int)data.nSamples();
65 samples.clear();
66 for (int i = i1; i < i2; i++) samples.push_back(data.sample(i));
67 corrs.resize(i2 - i1);
68 time = time - data.time(i1);
69 }
70
71 if (!m_samples.empty()) {
72 std::vector<short> oldSamples = samples;
73 samples.clear();
74 for (std::map<unsigned int, bool>::const_iterator i = m_samples.begin();
75 i != m_samples.end(); ++i)
76 {
77 samples.push_back(oldSamples[i->first]);
78 if (i == m_samples.begin()) time = time - data.time(i->first);
79 }
80 }
81
82 if (m_refit) {
83 SimpleShape* reference = data.referenceShape();
84 const ScaledErrorData* sed = data.scaledErrorData();
86 double chi2{};
87 if (!reference){
88 delete sed;
89 return nullptr;
90 }
91 bool result = fitter.fit(data, *reference, k, deltaT, chi2, sed);
92 delete sed;
93 if (!result) return nullptr;
94 }
95
96 if (m_adjust) {
97 if (!data.history() || data.adcMax() == 0) return nullptr;
98 OFC* ofc = data.history()->ofc(data.index());
99 if (!ofc) return nullptr;
100 k = ofc->A(data)/data.adcMax();
101 deltaT = ofc->time(data);
102 }
103
104 if (evtIndex < 0) evtIndex = data.container().eventIndex();
105
106 DataContainer* newContainer = new DataContainer(data.container().gain(), samples, corrs,
107 evtIndex,
108 data.container().energy(), time + deltaT, data.container().quality(),
109 data.container().pedestal(), data.container().pedestalRMS(),
110 data.container().status(), k*data.container().adcMax());
111 Data* newData = new Data(*newContainer, *data.eventData(), data.history(), data.index(), true);
112 return newData;
113}
114
115
116EventData* DataTweaker::tweak(const EventData& eventData, int runIndex) const
117{
118 EventData* newEventData = new EventData(eventData, runIndex);
119 if (m_removeRoIs) newEventData->removeRoIs();
120 return newEventData;
121}
@ Data
Definition BaseObject.h:11
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
bool findOption(TString &tweaks, const TString &option) const
Data * tweak(const Data &data, int evtIndex=-1) const
unsigned int m_nSamplesTruncation
Definition DataTweaker.h:46
bool set(const TString &tweaks)
std::map< unsigned int, bool > m_samples
Definition DataTweaker.h:48
bool fit(const LArSamples::AbsShape &data, const AbsShape &reference, double &k, double &deltaT, double &chi2, const ScaledErrorData *sed=0) const
double chi2(TH1 *h0, TH1 *h1)