ATLAS Offline Software
DataTweaker.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include "LArSamplesMon/Data.h"
8 #include "LArCafJobs/EventData.h"
9 #include "LArCafJobs/CellInfo.h"
11 #include "LArCafJobs/SimpleShape.h"
13 #include "LArSamplesMon/OFC.h"
14 
15 #include <fstream>
16 #include <iostream>
17 using std::cout;
18 using std::endl;
19 
20 using namespace LArSamples;
21 
22 
23 bool 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 
38 bool 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 
47 Data* 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) return nullptr;
88  bool result = fitter.fit(data, *reference, k, deltaT, chi2, sed);
89  delete sed;
90  if (!result) return nullptr;
91  }
92 
93  if (m_adjust) {
94  if (!data.history() || data.adcMax() == 0) return nullptr;
95  OFC* ofc = data.history()->ofc(data.index());
96  if (!ofc) return nullptr;
97  k = ofc->A(data)/data.adcMax();
98  deltaT = ofc->time(data);
99  }
100 
101  if (evtIndex < 0) evtIndex = data.container().eventIndex();
102 
103  DataContainer* newContainer = new DataContainer(data.container().gain(), samples, corrs,
104  evtIndex,
105  data.container().energy(), time + deltaT, data.container().quality(),
106  data.container().pedestal(), data.container().pedestalRMS(),
107  data.container().status(), k*data.container().adcMax());
108  Data* newData = new Data(*newContainer, *data.eventData(), data.history(), data.index(), true);
109  return newData;
110 }
111 
112 
113 EventData* DataTweaker::tweak(const EventData& eventData, int runIndex) const
114 {
115  EventData* newEventData = new EventData(eventData, runIndex);
116  if (m_removeRoIs) newEventData->removeRoIs();
117  return newEventData;
118 }
LArSamples::FitterData::fitter
const ShapeFitter * fitter
Definition: ShapeFitter.cxx:23
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
LArSamples::DataTweaker::m_fitParams
Chi2Params m_fitParams
Definition: DataTweaker.h:48
get_generator_info.result
result
Definition: get_generator_info.py:21
ScaledErrorData.h
SimpleShape.h
LArSamples::DataTweaker::m_removeNoiseCorrelations
bool m_removeNoiseCorrelations
Definition: DataTweaker.h:46
Data
@ Data
Definition: BaseObject.h:11
LArSamples::SimpleShape
Definition: SimpleShape.h:25
LArSamples::DataTweaker::m_refit
bool m_refit
Definition: DataTweaker.h:46
OFC.h
LArSamples
Definition: AbsShape.h:24
reference
Definition: hcg.cxx:437
LArSamples::ShapeFitter::fit
bool fit(const LArSamples::AbsShape &data, const AbsShape &reference, double &k, double &deltaT, double &chi2, const ScaledErrorData *sed=0) const
Definition: ShapeFitter.cxx:32
LArSamples::ScaledErrorData
Definition: ScaledErrorData.h:17
DataTweaker.h
LArSamples::DataTweaker::m_removeRoIs
bool m_removeRoIs
Definition: DataTweaker.h:46
lumiFormat.i
int i
Definition: lumiFormat.py:85
LArSamples::DataTweaker::findOption
bool findOption(TString &tweaks, const TString &option) const
Definition: DataTweaker.cxx:38
chi2
double chi2(TH1 *h0, TH1 *h1)
Definition: comparitor.cxx:522
ITk::EventData
InDet::SiSpacePointsSeedMakerEventData EventData
Definition: ITkSiSpacePointsSeedMaker.h:63
EventData.h
LArSamples::OFC
Definition: OFC.h:27
LArSamples::DataTweaker::tweak
Data * tweak(const Data &data, int evtIndex=-1) const
Definition: DataTweaker.cxx:47
LArSamples::Data
Definition: Data.h:77
LArSamples::DataTweaker::m_samples
std::map< unsigned int, bool > m_samples
Definition: DataTweaker.h:47
LArSamples::DataTweaker::m_adjust
bool m_adjust
Definition: DataTweaker.h:46
LArSamples::DataContainer
Definition: DataContainer.h:25
LArSamples::EventData::removeRoIs
void removeRoIs()
Definition: LArCalorimeter/LArCafJobs/LArCafJobs/EventData.h:85
LArSamples::ShapeFitter
Definition: ShapeFitter.h:24
LArSamples::DataTweaker::set
bool set(const TString &tweaks)
Definition: DataTweaker.cxx:23
Data.h
History.h
LArSamples::FitterData::sed
const ScaledErrorData * sed
Definition: ShapeFitter.cxx:26
ShapeFitter.h
ReadOfcFromCool.ofc
ofc
Definition: ReadOfcFromCool.py:110
LArSamples::EventData
Definition: LArCalorimeter/LArCafJobs/LArCafJobs/EventData.h:29
CellInfo.h
LArSamples::DataTweaker::m_nSamplesTruncation
unsigned int m_nSamplesTruncation
Definition: DataTweaker.h:45
fitman.k
k
Definition: fitman.py:528