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

#include <TreeShapeErrorGetter.h>

Inheritance diagram for LArSamples::TreeShapeErrorGetter:
Collaboration diagram for LArSamples::TreeShapeErrorGetter:

Public Member Functions

 TreeShapeErrorGetter (const TString &fileName, bool recreate=false)
 TreeShapeErrorGetter (const TreeShapeErrorGetter &)=delete
TreeShapeErrorGetteroperator= (const TreeShapeErrorGetter &)=delete
virtual ~TreeShapeErrorGetter ()
virtual std::unique_ptr< ShapeErrorDatashapeErrorData (unsigned int hash, CaloGain::CaloGain gain, const Residual *toExclude=0) const override
virtual std::unique_ptr< ShapeErrorDataphiSymShapeErrorData (short ring, CaloGain::CaloGain gain, const Residual *toExclude=0) const override
int addCell (const ResidualCalculator &calc, CaloGain::CaloGain gain)
int addRing (const ResidualCalculator &calc, CaloGain::CaloGain gain)
void dump (CaloGain::CaloGain gain) const
std::unique_ptr< TH2D > correlate (const TreeShapeErrorGetter &other, CaloGain::CaloGain gain, unsigned short sample, bool xip, unsigned int nBins, double xMin, double xMax) const
bool compare (const TreeShapeErrorGetter &other, const TString &fileName, const Interface *tmpl=0) const
const ResidualCalculatorcellCalc () const
const ResidualCalculatorringCalc () const
TTree * cellTree (CaloGain::CaloGain gain) const
TTree * ringTree (CaloGain::CaloGain gain) const
TFile * file () const

Static Public Member Functions

static bool merge (const TString &listFile, const TString &outputFile)
static bool merge (std::vector< std::unique_ptr< const TreeShapeErrorGetter > > &&getters, const TString &outputFile)

Private Attributes

std::unique_ptr< TFile > m_file
std::vector< TTree * > m_cellTrees
std::vector< TTree * > m_ringTrees
ResidualCalculatorm_cellCalc
ResidualCalculatorm_ringCalc

Detailed Description

Definition at line 30 of file TreeShapeErrorGetter.h.

Constructor & Destructor Documentation

◆ TreeShapeErrorGetter() [1/2]

TreeShapeErrorGetter::TreeShapeErrorGetter ( const TString & fileName,
bool recreate = false )

Definition at line 25 of file TreeShapeErrorGetter.cxx.

26 : m_cellTrees(3), m_ringTrees(3), m_cellCalc(nullptr), m_ringCalc(nullptr)
27{
28 m_file.reset(TFile::Open(fileName, (recreate ? "RECREATE" : "READ")));
29 if (!m_file || !m_file->IsOpen()) {
30 cout << "File " << fileName << " is not accessible" << endl;
31 return;
32 }
33 if (recreate) {
34 m_cellTrees[0] = new TTree("cells_HIGH", "");
35 m_cellTrees[1] = new TTree("cells_MED", "");
36 m_cellTrees[2] = new TTree("cells_LOW", "");
37 m_ringTrees[0] = new TTree("rings_HIGH", "");
38 m_ringTrees[1] = new TTree("rings_MED", "");
39 m_ringTrees[2] = new TTree("rings_LOW", "");
40 for (unsigned int i = 0; i < 3; i++ ) {
41 m_cellTrees[i]->Branch("calc", &m_cellCalc, 32000, 0);
42 m_ringTrees[i]->Branch("calc", &m_ringCalc, 32000, 0);
43 }
44 }
45 else {
46 m_cellTrees[0] = (TTree*)m_file->Get("cells_HIGH");
47 m_cellTrees[1] = (TTree*)m_file->Get("cells_MED");
48 m_cellTrees[2] = (TTree*)m_file->Get("cells_LOW");
49 if (!m_cellTrees[0] || !m_cellTrees[1] || !m_cellTrees[2]) {
50 cout << "Trees with cell shape error data not found in " << fileName << endl;
51 return;
52 }
53 m_ringTrees[0] = (TTree*)m_file->Get("rings_HIGH");
54 m_ringTrees[1] = (TTree*)m_file->Get("rings_MED");
55 m_ringTrees[2] = (TTree*)m_file->Get("rings_LOW");
56 if (!m_ringTrees[0] || !m_ringTrees[1] || !m_ringTrees[2]) {
57 cout << "Trees with phi symmetric shape error data not found in " << fileName << endl;
58 return;
59 }
60 for (unsigned int i = 0; i < 3; i++ ) {
61 m_cellTrees[i]->SetBranchAddress("calc", &m_cellCalc);
62 m_ringTrees[i]->SetBranchAddress("calc", &m_ringCalc);
63 }
64 }
65}

◆ TreeShapeErrorGetter() [2/2]

LArSamples::TreeShapeErrorGetter::TreeShapeErrorGetter ( const TreeShapeErrorGetter & )
delete

◆ ~TreeShapeErrorGetter()

TreeShapeErrorGetter::~TreeShapeErrorGetter ( )
virtual

Definition at line 68 of file TreeShapeErrorGetter.cxx.

69{
70 if (m_file->GetOption() == TString("CREATE")) {
71 m_file->cd();
72 for (unsigned int g = 0; g < 3; g++ ) {
73 if (!m_cellTrees[g] || !m_ringTrees[g]) {
74 cout << "Missing trees, error writing data to TreeShapeErrorGetter" << endl;
75 return;
76 }
77 m_cellTrees[g]->Write();
78 m_ringTrees[g]->Write();
79 }
80 }
81}

Member Function Documentation

◆ addCell()

int TreeShapeErrorGetter::addCell ( const ResidualCalculator & calc,
CaloGain::CaloGain gain )

Definition at line 132 of file TreeShapeErrorGetter.cxx.

133{
134 if (!cellTree(gain)) return -1;
135 if (m_cellCalc) delete m_cellCalc;
136 m_cellCalc = new ResidualCalculator(calc);
137 cellTree(gain)->Fill();
138 return cellTree(gain)->GetEntries();
139}
TTree * cellTree(CaloGain::CaloGain gain) const

◆ addRing()

int TreeShapeErrorGetter::addRing ( const ResidualCalculator & calc,
CaloGain::CaloGain gain )

Definition at line 142 of file TreeShapeErrorGetter.cxx.

143{
144 if (!ringTree(gain)) return 0;
145 if (m_ringCalc) delete m_ringCalc;
146 m_ringCalc = new ResidualCalculator(calc);
147 ringTree(gain)->Fill();
148 return ringTree(gain)->GetEntries();
149}
TTree * ringTree(CaloGain::CaloGain gain) const

◆ cellCalc()

const ResidualCalculator * LArSamples::TreeShapeErrorGetter::cellCalc ( ) const
inline

Definition at line 52 of file TreeShapeErrorGetter.h.

52{ return m_cellCalc; }

◆ cellTree()

TTree * TreeShapeErrorGetter::cellTree ( CaloGain::CaloGain gain) const

Definition at line 84 of file TreeShapeErrorGetter.cxx.

85{
86 switch (gain) {
87 case CaloGain::LARHIGHGAIN : return m_cellTrees[0];
88 case CaloGain::LARMEDIUMGAIN : return m_cellTrees[1];
89 case CaloGain::LARLOWGAIN : return m_cellTrees[2];
90 default : return nullptr;
91 }
92 return nullptr;
93}
@ LARMEDIUMGAIN
Definition CaloGain.h:20
@ LARLOWGAIN
Definition CaloGain.h:20
@ LARHIGHGAIN
Definition CaloGain.h:20

◆ compare()

bool TreeShapeErrorGetter::compare ( const TreeShapeErrorGetter & other,
const TString & fileName,
const Interface * tmpl = 0 ) const

Definition at line 249 of file TreeShapeErrorGetter.cxx.

250{
251 std::unique_ptr<TFile> f(TFile::Open(fileName, "RECREATE"));
252 TTree tree ("tree", "");
253
254 int hash, gain, lwb1, lwb2, nSamples;
255 double xi1[99], xi2[99], xip1[99], xip2[99];
256 int calo;
257 int layer, ft, slot, channel;
258 double eta, phi;
259
260 tree.Branch("hash", &hash);
261
262 if (tmpl) {
263 tree.Branch("calo", &calo);
264 tree.Branch("layer", &layer);
265 tree.Branch("ft", &ft);
266 tree.Branch("slot", &slot);
267 tree.Branch("channel", &channel);
268 tree.Branch("eta", &eta);
269 tree.Branch("phi", &phi);
270 }
271 tree.Branch("gain", &gain);
272 tree.Branch("lwb1", &lwb1);
273 tree.Branch("lwb2", &lwb2);
274 tree.Branch("nSamples", &nSamples);
275 tree.Branch("xi1", xi1, "xi1[nSamples]/D");
276 tree.Branch("xi2", xi2, "xi2[nSamples]/D");
277 tree.Branch("xip1", xip1, "xip1[nSamples]/D");
278 tree.Branch("xip2", xip2, "xip2[nSamples]/D");
279
280 for (long long k = 0; k < Definitions::nChannels; k++) {
281 if (k % 10000 == 0) cout << "Processing entry " << k << endl;
282 hash = k;
283 if (tmpl) {
284 std::unique_ptr<const CellInfo> cellInfo = tmpl->cellInfo(k);
285 calo = (cellInfo ? cellInfo->calo() : -999 );
286 layer = (cellInfo ? cellInfo->layer() : -999 );
287 ft = (cellInfo ? cellInfo->feedThrough() : -999 );
288 slot = (cellInfo ? cellInfo->slot() : -999 );
289 channel = (cellInfo ? cellInfo->channel() : -999 );
290 eta = (cellInfo ? cellInfo->eta() : -999 );
291 phi = (cellInfo ? cellInfo->phi() : -999 );
292 }
293 for (unsigned int g = 0; g < 3; g++) {
294 gain = g;
295 std::unique_ptr<ShapeErrorData> data1 = shapeErrorData(k, (CaloGain::CaloGain)g);
296 std::unique_ptr<ShapeErrorData> data2 = other.shapeErrorData(k, (CaloGain::CaloGain)g);
297
298 lwb1 = (data1 ? data1->lwb() : -1);
299 lwb2 = (data2 ? data2->lwb() : -1);
300 nSamples = (data1 ? data1->nSamples() : data2 ? data2->nSamples() : 0);
301 int lwb = (lwb1 >= 0 ? lwb1 : lwb2);
302 if (lwb<0) throw std::runtime_error("TreeShapeErrorGetter::compare() attempt to access arrays with negative index");
303 for (int j = lwb; j < lwb + nSamples; j++) {
304 xi1[j] = (data1 ? data1->xi()(j) : -999);
305 xip1[j] = (data1 ? data1->xip()(j) : -999);
306 xi2[j] = (data2 && data2->isInRange(j) ? data2->xi()(j) : -999);
307 xip2[j] = (data2 && data2->isInRange(j) ? data2->xip()(j) : -999);
308 }
309 tree.Fill();
310 }
311 }
312 f->cd();
313 tree.Write();
314 return true;
315}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
virtual std::unique_ptr< const CellInfo > cellInfo(unsigned int i) const
virtual std::unique_ptr< ShapeErrorData > shapeErrorData(unsigned int hash, CaloGain::CaloGain gain, const Residual *toExclude=0) const override
@ layer
Definition HitInfo.h:79
float j(const xAOD::IParticle &, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d &jab_inv)
TChain * tree

◆ correlate()

std::unique_ptr< TH2D > TreeShapeErrorGetter::correlate ( const TreeShapeErrorGetter & other,
CaloGain::CaloGain gain,
unsigned short sample,
bool xip,
unsigned int nBins,
double xMin,
double xMax ) const

Definition at line 164 of file TreeShapeErrorGetter.cxx.

166{
167 auto h = std::make_unique<TH2D>(Form("%s_%d", xip ? "xip" : "xi", sample), "", nBins, xMin, xMax, nBins, xMin, xMax);
168 for (long long i = 0; i < Definitions::nChannels; i++) {
169 std::unique_ptr<ShapeErrorData> data1 = shapeErrorData(i, gain);
170 if (!data1) continue;
171 std::unique_ptr<ShapeErrorData> data2 = other.shapeErrorData(i, gain);
172 if (!data2) { continue; }
173 cout << i << endl;
174 unsigned int sample1 = sample + data1->xip().GetLwb(); // sample indices may not match, but we assume the range covered for the reference shape is the same
175 unsigned int sample2 = sample + data2->xip().GetLwb();
176 if (data1->isInRange(sample1) && data2->isInRange(sample2))
177 h->Fill(xip ? data1->xip()(sample1) : data1->xi()(sample1),
178 xip ? data2->xip()(sample2) : data2->xi()(sample2));
179 }
180 return h;
181}

◆ dump()

void TreeShapeErrorGetter::dump ( CaloGain::CaloGain gain) const

Definition at line 152 of file TreeShapeErrorGetter.cxx.

153{
154 if (!cellTree(gain)) return;
155 for (long long i = 0; i < cellTree(gain)->GetEntries(); i++) {
156 std::unique_ptr<ShapeErrorData> sed = shapeErrorData(i, gain);
157 if (!sed) continue;
158 cout << "-> " << i << endl;
159 sed->xi().Print();
160 sed->xip().Print();
161 }
162}
const TVectorD & xi() const
const TVectorD & xip() const
const ScaledErrorData * sed

◆ file()

TFile * LArSamples::TreeShapeErrorGetter::file ( ) const
inline

Definition at line 61 of file TreeShapeErrorGetter.h.

61{ return m_file.get(); }

◆ merge() [1/2]

bool TreeShapeErrorGetter::merge ( const TString & listFile,
const TString & outputFile )
static

Definition at line 184 of file TreeShapeErrorGetter.cxx.

185{
186 std::ifstream f(listFile);
187 if (!f) {
188 cout << "file " << listFile << " not accessible" << endl;
189 return 0;
190 }
191
192 std::string fileName;
193 unsigned int i = 0;
194 std::vector<std::unique_ptr<const TreeShapeErrorGetter> > getters;
195
196 while (f >> fileName) {
197 //std::make_unique cannot return nullptr
198 auto getter = std::make_unique<TreeShapeErrorGetter>(fileName.c_str());
199
200 cout << std::setw(2) << ++i << " - " << fileName << endl;
201 getters.push_back(std::move(getter));
202 }
203 return merge(std::move(getters), outputFile);
204}
static bool merge(const TString &listFile, const TString &outputFile)

◆ merge() [2/2]

bool TreeShapeErrorGetter::merge ( std::vector< std::unique_ptr< const TreeShapeErrorGetter > > && getters,
const TString & outputFile )
static

Definition at line 207 of file TreeShapeErrorGetter.cxx.

208{
209 auto output = std::make_unique<TreeShapeErrorGetter>(outputFile, true);
210 for (unsigned int i = 0; i < Definitions::nChannels; i++) {
211 for (unsigned int g = 0; g < 3; g++) {
212 bool gotResult = false;
213 for (std::unique_ptr<const TreeShapeErrorGetter>& getter : getters) {
214 if (getter->shapeErrorData(i, (CaloGain::CaloGain)g)) {
215 if (gotResult) {
216 cout << "TreeShapeErrorGetter::merge : input getters have non-zero overlap for cell " << i << " -- not supported, exiting." << endl;
217 return false;
218 }
219 gotResult = true;
220 cout << "Adding " << i << " " << g << " " << getter->cellCalc()->size() << endl;
221 output->addCell(*getter->cellCalc(), (CaloGain::CaloGain)g);
222 }
223 }
224 if (!gotResult) output->addCell(ResidualCalculator(), (CaloGain::CaloGain)g);
225 }
226 }
227
228 for (int i = 0; i < Geo::nPhiRings(); i++) {
229 for (unsigned int g = 0; g < 3; g++) {
230 bool gotResult = false;
231 for (std::unique_ptr<const TreeShapeErrorGetter>& getter : getters) {
232 if (getter->phiSymShapeErrorData(i, (CaloGain::CaloGain)g)) {
233 if (gotResult) {
234 cout << "TreeShapeErrorGetter::merge : input getters have non-zero overlap for ring " << i << " -- not supported, exiting." << endl;
235 return false;
236 }
237 gotResult = true;
238 cout << "Adding ring " << i << " " << g << endl;
239 output->addRing(*getter->ringCalc(), (CaloGain::CaloGain)g);
240 }
241 }
242 if (!gotResult) output->addRing(ResidualCalculator(), (CaloGain::CaloGain)g);
243 }
244 }
245 return true;
246}
static short nPhiRings()
Definition Geometry.cxx:84
output
Definition merge.py:16

◆ operator=()

TreeShapeErrorGetter & LArSamples::TreeShapeErrorGetter::operator= ( const TreeShapeErrorGetter & )
delete

◆ phiSymShapeErrorData()

std::unique_ptr< ShapeErrorData > TreeShapeErrorGetter::phiSymShapeErrorData ( short ring,
CaloGain::CaloGain gain,
const Residual * toExclude = 0 ) const
overridevirtual

Implements LArSamples::AbsShapeErrorGetter.

Definition at line 121 of file TreeShapeErrorGetter.cxx.

122{
123 if (!ringTree(gain) || ring >= ringTree(gain)->GetEntries()) return nullptr;
124 ringTree(gain)->GetEntry(ring);
125
126 if (toExclude) m_ringCalc->remove(*toExclude);
127 if (m_ringCalc->size() < 2) return nullptr;
128 return m_ringCalc->shapeErrorData();
129}
TGraphErrors * GetEntries(TH2F *histo)

◆ ringCalc()

const ResidualCalculator * LArSamples::TreeShapeErrorGetter::ringCalc ( ) const
inline

Definition at line 53 of file TreeShapeErrorGetter.h.

53{ return m_ringCalc; }

◆ ringTree()

TTree * TreeShapeErrorGetter::ringTree ( CaloGain::CaloGain gain) const

Definition at line 96 of file TreeShapeErrorGetter.cxx.

97{
98 switch (gain) {
99 case CaloGain::LARHIGHGAIN : return m_ringTrees[0];
100 case CaloGain::LARMEDIUMGAIN : return m_ringTrees[1];
101 case CaloGain::LARLOWGAIN : return m_ringTrees[2];
102 default : return nullptr;
103 }
104 return nullptr;
105}

◆ shapeErrorData()

std::unique_ptr< ShapeErrorData > TreeShapeErrorGetter::shapeErrorData ( unsigned int hash,
CaloGain::CaloGain gain,
const Residual * toExclude = 0 ) const
overridevirtual

Implements LArSamples::AbsShapeErrorGetter.

Definition at line 109 of file TreeShapeErrorGetter.cxx.

110{
111 if (!cellTree(gain) || hash >= cellTree(gain)->GetEntries()) return nullptr;
112 cellTree(gain)->GetEntry(hash);
113
114 if (toExclude) m_cellCalc->remove(*toExclude);
115 if (m_cellCalc->size() < 2) return nullptr;
116 return m_cellCalc->shapeErrorData();
117}

Member Data Documentation

◆ m_cellCalc

ResidualCalculator* LArSamples::TreeShapeErrorGetter::m_cellCalc
mutableprivate

Definition at line 68 of file TreeShapeErrorGetter.h.

◆ m_cellTrees

std::vector<TTree*> LArSamples::TreeShapeErrorGetter::m_cellTrees
private

Definition at line 66 of file TreeShapeErrorGetter.h.

◆ m_file

std::unique_ptr<TFile> LArSamples::TreeShapeErrorGetter::m_file
private

Definition at line 65 of file TreeShapeErrorGetter.h.

◆ m_ringCalc

ResidualCalculator * LArSamples::TreeShapeErrorGetter::m_ringCalc
private

Definition at line 68 of file TreeShapeErrorGetter.h.

◆ m_ringTrees

std::vector<TTree*> LArSamples::TreeShapeErrorGetter::m_ringTrees
private

Definition at line 67 of file TreeShapeErrorGetter.h.


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