-
Notifications
You must be signed in to change notification settings - Fork 257
Expand file tree
/
Copy pathMat_map_stats.C
More file actions
79 lines (59 loc) · 1.82 KB
/
Copy pathMat_map_stats.C
File metadata and controls
79 lines (59 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// This file is part of the ACTS project.
//
// Copyright (C) 2026 CERN for the benefit of the ACTS project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
#include <TROOT.h>
#include <TFile.h>
#include <TKey.h>
#include <TDirectory.h>
#include <TH2F.h>
#include <TH1F.h>
#include <TCanvas.h>
#include <string>
#include <fstream>
#include <iostream>
#include <sstream>
void makeBinCountsDist(const char* filename = "material-maps.root")
{
TFile* f = TFile::Open(filename, "READ");
if (!f || f->IsZombie()) return;
TIter nextDir(f->GetListOfKeys());
TKey* key;
while ((key = (TKey*)nextDir())) {
TObject* obj = key->ReadObj();
if (!obj->InheritsFrom(TDirectory::Class())){
continue;
}
TDirectory* dir = (TDirectory*)obj;
TH2F* h2 = nullptr;
dir->GetObject("binCounts", h2);
if (!h2){
std::cout<<"Histogram not found - continue"<<std::endl;
continue;
}
std::cout << "\nProcessing: " << dir->GetName() << std::endl;
TH1F hDist("binCountsDist",
"BinCounts distribution;count;bins",
100, 0, h2->GetMaximum() + 1);
std::size_t nEmptyBins{0};
for (int ix = 1; ix <= h2->GetNbinsX(); ++ix) {
for (int iy = 1; iy <= h2->GetNbinsY(); ++iy) {
double val = h2->GetBinContent(ix, iy);
if(val == 0){
nEmptyBins+=1;
}
hDist.Fill(val);
}
}
std::cout << "Mean = " << hDist.GetMean()
<< " ,StdDev = " << hDist.GetStdDev()
<<" ,Empty bins counted = "<< nEmptyBins
<< std::endl;
TCanvas* c = new TCanvas();
hDist.Draw();
c->SaveAs(Form("%s_binCounts.png", dir->GetName()));
}
}