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)
virtual ~TreeShapeErrorGetter ()
ShapeErrorDatashapeErrorData (unsigned int hash, CaloGain::CaloGain gain, const Residual *toExclude=0) const
ShapeErrorDataphiSymShapeErrorData (short ring, CaloGain::CaloGain gain, const Residual *toExclude=0) const
int addCell (const ResidualCalculator &calc, CaloGain::CaloGain gain)
int addRing (const ResidualCalculator &calc, CaloGain::CaloGain gain)
void dump (CaloGain::CaloGain gain) const
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 (const std::vector< const TreeShapeErrorGetter * > &getters, const TString &outputFile)

Private Attributes

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()

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

Definition at line 25 of file TreeShapeErrorGetter.cxx.

26 : m_file(nullptr), m_cellTrees(3), m_ringTrees(3), m_cellCalc(nullptr), m_ringCalc(nullptr)
27{
28 m_file = 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()

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 delete m_file;
82}

Member Function Documentation

◆ addCell()

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

Definition at line 131 of file TreeShapeErrorGetter.cxx.

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

◆ addRing()

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

Definition at line 141 of file TreeShapeErrorGetter.cxx.

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

◆ cellCalc()

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

Definition at line 49 of file TreeShapeErrorGetter.h.

49{ return m_cellCalc; }

◆ cellTree()

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

Definition at line 85 of file TreeShapeErrorGetter.cxx.

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

◆ compare()

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

Definition at line 259 of file TreeShapeErrorGetter.cxx.

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

◆ correlate()

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 TH2D* h = new 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 ShapeErrorData* data1 = shapeErrorData(i, gain);
170 if (!data1) continue;
171 ShapeErrorData* data2 = other.shapeErrorData(i, gain);
172 if (!data2) { delete data1; 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 delete data1;
180 delete data2;
181 }
182 return h;
183}

◆ dump()

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

Definition at line 151 of file TreeShapeErrorGetter.cxx.

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

◆ file()

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

Definition at line 58 of file TreeShapeErrorGetter.h.

58{ return m_file; }

◆ merge() [1/2]

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

Definition at line 217 of file TreeShapeErrorGetter.cxx.

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

◆ merge() [2/2]

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

Definition at line 186 of file TreeShapeErrorGetter.cxx.

187{
188 std::ifstream f(listFile);
189 if (!f) {
190 cout << "file " << listFile << " not accessible" << endl;
191 return 0;
192 }
193
194 std::string fileName;
195 unsigned int i = 0;
196 std::vector<const TreeShapeErrorGetter*> getters;
197
198 while (f >> fileName) {
199 //gSystem->Exec("free");
200 const TreeShapeErrorGetter* getter = new TreeShapeErrorGetter(fileName.c_str());
201 if (!getter) {
202 cout << "Skipping invalid file " << fileName << endl;
203 continue;
204 }
205 cout << std::setw(2) << ++i << " - " << fileName << endl;
206 getters.push_back(getter);
207 }
208 bool result = merge(getters, outputFile);
209
210 for (const TreeShapeErrorGetter* getter : getters)
211 delete getter;
212
213 return result;
214}
static bool merge(const TString &listFile, const TString &outputFile)

◆ phiSymShapeErrorData()

ShapeErrorData * TreeShapeErrorGetter::phiSymShapeErrorData ( short ring,
CaloGain::CaloGain gain,
const Residual * toExclude = 0 ) const
virtual

Implements LArSamples::AbsShapeErrorGetter.

Definition at line 120 of file TreeShapeErrorGetter.cxx.

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

◆ ringCalc()

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

Definition at line 50 of file TreeShapeErrorGetter.h.

50{ return m_ringCalc; }

◆ ringTree()

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

Definition at line 97 of file TreeShapeErrorGetter.cxx.

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

◆ shapeErrorData()

ShapeErrorData * TreeShapeErrorGetter::shapeErrorData ( unsigned int hash,
CaloGain::CaloGain gain,
const Residual * toExclude = 0 ) const
virtual

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 65 of file TreeShapeErrorGetter.h.

◆ m_cellTrees

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

Definition at line 63 of file TreeShapeErrorGetter.h.

◆ m_file

TFile* LArSamples::TreeShapeErrorGetter::m_file
private

Definition at line 62 of file TreeShapeErrorGetter.h.

◆ m_ringCalc

ResidualCalculator * LArSamples::TreeShapeErrorGetter::m_ringCalc
private

Definition at line 65 of file TreeShapeErrorGetter.h.

◆ m_ringTrees

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

Definition at line 64 of file TreeShapeErrorGetter.h.


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