ATLAS Offline Software
Loading...
Searching...
No Matches
OccupancyMonitor.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
10#include "LArCafJobs/Geometry.h"
11
12#include "TH1I.h"
13#include "TH2D.h"
14#include <map>
15#include <vector>
16
17#include <iostream>
18#include <limits>
19using std::cout;
20using std::endl;
21
22using namespace LArSamples;
23
24namespace{
25 constexpr float infinity=std::numeric_limits<float>::infinity();
26}
27
29{
30 std::map<unsigned int, unsigned int> occ;
31 for (unsigned int i = 0; i < nChannels(); i++) {
32 const History* history = cellHistory(i);
33 if (!history) continue;
34 for (unsigned int k = 0; k < history->nData(); k++)
35 occ[history->data(k)->run()]++;
36 }
37
38 unsigned int runMin = 0;
39 unsigned int runMax = 1;
40 if (!occ.empty()) {
41 runMin = occ.begin()->first;
42 runMax = occ.rbegin()->first;
43 }
44
45 TH1I* h = new TH1I("occ", "Run occupancies", runMax - runMin + 1, runMin - 0.5, runMax + 0.5);
46 h->GetXaxis()->SetTitle("Run number");
47 h->GetYaxis()->SetTitle("Occupancy");
48 for (std::map<unsigned int, unsigned int>::const_iterator run = occ.begin();
49 run != occ.end(); ++run)
50 {
51 //cout << event->first << " " << event->second << endl;
52 int bin = run->first - runMin + 1;
53 h->SetBinContent(bin, run->second);
54 h->GetXaxis()->SetBinLabel(bin, Form("%d", run->first));
55 }
56 return h;
57}
58
59
60TH1I* OccupancyMonitor::eventOccupancyHistory(unsigned int occForDump) const
61{
62 std::map<std::pair<unsigned int, unsigned int>, unsigned int> occ;
63 for (unsigned int i = 0; i < nChannels(); i++) {
64 const History* history = cellHistory(i);
65 if (!history) continue;
66 for (unsigned int k = 0; k < history->nData(); k++)
67 occ[std::make_pair(history->data(k)->run(),history->data(k)->event())]++;
68 }
69
70 TH1I* h = new TH1I("occ", "Event occupancies", occ.size(), 0, occ.size());
71 h->GetXaxis()->SetTitle("Recorded Event");
72 h->GetYaxis()->SetTitle("Occupancy");
73
74 unsigned int bin = 1;
75 for (std::map<std::pair<unsigned int, unsigned int>, unsigned int>::const_iterator event = occ.begin();
76 event != occ.end(); ++event, ++bin)
77 {
78 if (occForDump > 0 && occForDump <= event->second)
79 cout << "run = " << event->first.first << " event = " << event->first.second << " occ = " << event->second << endl;
80 h->SetBinContent(bin, event->second);
81 }
82 return h;
83}
84
85
87{
88 std::map<unsigned int, unsigned int> occ;
89 for (unsigned int i = 0; i < nChannels(); i++) {
90 const History* history = cellHistory(i);
91 if (!history) continue;
92 for (unsigned int k = 0; k < history->nData(); k++)
93 occ[history->data(k)->event()]++;
94 }
95
96 unsigned int oMin = 999999999, oMax = 0;
97
98 for (std::map<unsigned int, unsigned int>::const_iterator event = occ.begin();
99 event != occ.end(); ++event)
100 {
101 if (event->second < oMin) oMin = event->second;
102 if (event->second > oMax) oMax = event->second;
103 }
104 if (oMin > oMax) {
105 oMin = 0;
106 oMax = 1;
107 }
108
109 TH1I* h = new TH1I("occ", "Event occupancies", oMax - oMin + 1, oMin - 0.5, oMax + 0.5);
110 h->GetXaxis()->SetTitle("Occupancy");
111 h->GetYaxis()->SetTitle("Number of events");
112 for (std::map<unsigned int, unsigned int>::const_iterator event = occ.begin();
113 event != occ.end(); ++event)
114 h->Fill(event->second);
115
116 return h;
117}
118
119
120TH1I* OccupancyMonitor::cellOccupancy(int minForPrintout) const
121{
122 std::vector<unsigned int> occ(nChannels());
123 for (unsigned int i = 0; i < nChannels(); i++) {
124 const History* history = cellHistory(i);
125 if (history) {
126 occ[i] = occ[i] + history->nData();
127 }
128 }
129
130 unsigned int oMin = 999999999, oMax = 0;
131
132 for (std::vector<unsigned int>::const_iterator cell = occ.begin();
133 cell != occ.end(); ++cell)
134 {
135 if (*cell < oMin) oMin = *cell;
136 if (*cell > oMax) oMax = *cell;
137 }
138 if (oMin > oMax) {
139 oMin = 0;
140 oMax = 1;
141 }
142
143 //std::map<std::pair<unsigned int, std::string>, unsigned int> names;
144 std::map<std::pair<unsigned int, unsigned int>, std::string> names;
145 TH1I* h = new TH1I("occ", "Cell occupancies", oMax - oMin + 1, oMin - 0.5, oMax + 0.5);
146 h->GetXaxis()->SetTitle("Occupancy");
147 h->GetYaxis()->SetTitle("Number of cells");
148
149 unsigned int i = 0;
150 for (std::vector<unsigned int>::const_iterator cellOcc = occ.begin();
151 cellOcc != occ.end(); ++cellOcc, ++i) {
152 h->Fill(*cellOcc);
153 const History* history = cellHistory(i);
154 if (!history) continue;
155 if (minForPrintout >= 0) {
156 TString heading = history->cellInfo()->location(2);
157 if (history->nData() > 0) heading += " " + history->data(0)->problems();
158 names[ std::pair<unsigned int, unsigned int>(*cellOcc, i) ] = heading.Data();
159 }
160 }
161
162 if (minForPrintout >= 0) {
163/* for (std::map<std::pair<unsigned int, std::string>, unsigned int>::reverse_iterator cell = names.rbegin();
164 cell != names.rend(); ++cell)
165 {
166 if (cell->first.first < (unsigned int)minForPrintout) break;
167 cout << cell->first.first << " : " << cell->second << ", " << cell->first.second << endl;
168 }*/
169 for (std::map<std::pair<unsigned int, unsigned int>, std::string>::reverse_iterator cell = names.rbegin();
170 cell != names.rend(); ++cell)
171 {
172 if (cell->first.first < (unsigned int)minForPrintout) break;
173 cout << cell->first.first << " : " << cell->first.second << ", " << cell->second << endl;
174 }
175 }
176
177 return h;
178}
179
180
182{
183 std::map<unsigned int, unsigned int> occ;
184 FilterParams f;
185 f.addCalo(calo);
186 for (unsigned int i = 0; i < nChannels(); i++) {
187 const History* history = pass(i, f);
188 if (!history) continue;
189 for (unsigned int k = 0; k < history->nData(); k++)
190 occ[history->cellInfo()->feb()]++;
191 }
192
193 unsigned int oMin = 999999999, oMax = 0;
194
195 for (std::map<unsigned int, unsigned int>::const_iterator feb = occ.begin();
196 feb != occ.end(); ++feb)
197 {
198 if (feb->second < oMin) oMin = feb->second;
199 if (feb->second > oMax) oMax = feb->second;
200 }
201 if (oMin > oMax) {
202 oMin = 0;
203 oMax = 1;
204 }
205
206 TH1I* h = new TH1I("occ", "FEB occupancies", oMax - oMin + 1, oMin - 0.5, oMax + 0.5);
207 h->GetXaxis()->SetTitle("Occupancy");
208 h->GetYaxis()->SetTitle("Number of FEBs");
209 for (std::map<unsigned int, unsigned int>::const_iterator feb = occ.begin();
210 feb != occ.end(); ++feb)
211 h->Fill(feb->second);
212
213 return h;
214}
215
216
218{
219 TH2D* occ = Geo::partitionHist(part, TString("occupancy_") + Id::str(part), "Occupancies for partition " + Id::str(part));
220 for (unsigned int i = 0; i < nChannels(); i++) {
221 const History* history = cellHistory(i);
222 if (!history) continue;
223 if (Id::partition(history->cellInfo()->calo()) != part) continue;
224 occ->Fill(history->cellInfo()->feb(), history->cellInfo()->channel(), history->nData());
225 }
226
227 return occ;
228}
229
230
231TH2D* OccupancyMonitor::etaPhiOccupancy(CaloId calo, short layer, bool useEnergy) const
232{
233 DataFuncSet func = (useEnergy ? MonitorBase::func("energy") : MonitorBase::func("count"));
234 return etaPhiMap(func, DataFuncArgs(), Form("occupancy_%s_%d", Id::str(calo).Data(), layer),
235 calo, layer,
236 Form("Occupancies for partition %s, layer %d", Id::str(calo).Data(), layer),
237 TotalValue);
238}
239
240
241void OccupancyMonitor::dump(short verbosity) const
242{
243 for (unsigned int i = 0; i < nChannels(); i++) {
244 const History* history = cellHistory(i);
245 if (!history) continue;
246 cout << history->cellInfo()->location(verbosity);
247 if (verbosity < 5)
248 cout << " : " << history->nData() << " pulse" << endl;
249 else {
250 cout << " : ";
251 for (unsigned int i = 0; i < history->nData(); i++)
252 cout << "E = " << history->data(i)->energy() << " MeV, " << endl;
253 }
254 }
255}
256
257
258void OccupancyMonitor::cellAndRingOccupancy(CaloId calo, unsigned int nMin) const
259{
260 const unsigned int nPhiRings = 5516; // == Geo::nPhiRings()
261 using block_t = unsigned int[4][3];
262 block_t nCells, nRings;
263 std::vector<block_t> ringOccupancy (nPhiRings);
264
265 for (unsigned int i = 0; i < 4; i++)
266 for (unsigned int j = 0; j < 3; j++) {
267 for (unsigned int k = 0; k < nPhiRings; k++) ringOccupancy[k][i][j] = 0;
268 nCells[i][j] = 0;
269 nRings[i][j] = 0;
270 }
271
272 for (unsigned int i = 0; i < nChannels(); i++) {
273 if (i%10000 == 0) cout << "Processing hash = " << i << endl;
274 const History* history = cellHistory(i);
275 if (!history) continue;
276 if (!Id::matchCalo(history->cellInfo()->calo(), calo)) continue;
277 unsigned int n[3] = {0,0,0};
278 int layer = history->cellInfo()->layer();
279 for (unsigned int k = 0; k < history->nData(); k++) {
280 const auto globalPhiRing = history->cellInfo()->globalPhiRing();
281 if (globalPhiRing<0) continue;
282 ringOccupancy[globalPhiRing][layer][(int)history->data(k)->gain()]++;
283 n[(int)history->data(k)->gain()]++;
284 }
285 for (unsigned int g = 0; g < 3; g++) if (n[g] >= nMin) nCells[layer][g]++;
286 //cout << n[1] << " " << nCells[layer][1] << " " << layer << endl;
287 }
288 for (unsigned int i = 0; i < 4; i++)
289 for (unsigned int j = 0; j < 3; j++) {
290 for (unsigned int k = 0; k < nPhiRings; k++)
291 if (ringOccupancy[k][i][j] >= nMin) nRings[i][j]++;
292 }
293
294 for (unsigned int i = 0; i < 4; i++) {
295 cout << "layer " << i << endl;
296 const auto nChann = Geo::nChannels(calo,i);
297 const auto nEta = Geo::nEta(calo,i);
298 for (unsigned int j = 0; j < 3; j++) {
299 float nCellFract= infinity;
300 if (nChann>0) nCellFract = nCells[i][j]*100.0/nChann;
301 float nRingFract = infinity;
302 if (nEta > 0) nRingFract = nRings[i][j]*100.0/nEta;
303 cout << " gain " << j << " : "
304 << nCells[i][j] << " cells of " << nChann << " (" << nCellFract << " %), "
305 << nRings[i][j] << " rings of " << nEta << " (" << nRingFract << " %)." << endl;
306 }
307 }
308 for (unsigned int i = 0; i < 4; i++) {
309 const auto nChann = Geo::nChannels(calo,i);
310 const auto nEta = Geo::nEta(calo,i);
311 cout << i << " & " << nChann << " & " << nEta << " & ";
312 for (unsigned int j = 0; j < 3; j++){
313 float val = infinity;
314 if (nChann>0) val = nCells[i][j]*100.0/nChann;
315 cout << Form("%4.1f\\%% & ", val);
316 }
317 for (unsigned int j = 0; j < 3; j++){
318 float val = infinity;
319 if (nEta > 0) val = nRings[i][j]*100.0/nEta;
320 cout << Form("%4.1f\\%% & ", val);
321 }
322 cout << endl;
323 }
324}
@ Data
Definition BaseObject.h:11
const History * pass(unsigned int i, const FilterParams &f) const
virtual const History * cellHistory(unsigned int i) const
short feb() const
Definition CellInfo.cxx:102
short layer() const
Definition CellInfo.h:53
TString location(int verbose=1) const
Definition CellInfo.cxx:139
short globalPhiRing() const
Definition CellInfo.cxx:125
CaloId calo() const
Definition CellInfo.h:50
short channel() const
Definition CellInfo.h:76
CaloGain::CaloGain gain() const
Definition Data.h:85
double energy() const
Definition Data.h:108
int event() const
Definition Data.cxx:28
TString problems(bool sayNone=false) const
Definition Data.cxx:135
int run() const
Definition Data.cxx:27
static short nEta(CaloId calo, short layer, short region, short iPhi=1)
Definition Geometry.cxx:169
static int nChannels(CaloId calo, short layer, short region)
Definition Geometry.cxx:587
static TH2D * partitionHist(PartitionId part, const TString &name, const TString &title)
Definition Geometry.cxx:18
const CellInfo * cellInfo() const
Definition History.h:56
const Data * data(unsigned int i) const
Definition History.cxx:91
unsigned int nData() const
Definition History.h:51
static PartitionId partition(CaloId id)
Definition CaloId.cxx:157
static TString str(CaloId id)
Definition CaloId.cxx:15
static bool matchCalo(CaloId id, CaloId idSpec)
Definition CaloId.cxx:188
static DataFuncSet func(const TString &var)
TH2D * etaPhiMap(const DataFuncSet &func, const DataFuncArgs &args, const TString &name, CaloId calo, short layer, TString title="", CombinationType comb=AverageValue, const FilterParams &f=FilterParams()) const
TH2D * etaPhiOccupancy(CaloId calo, short layer, bool useEnergy=false) const
TH1I * eventOccupancyHistory(unsigned int occForDump=0) const
TH2D * partitionOccupancy(PartitionId part) const
void dump(short verbosity=2) const
void cellAndRingOccupancy(CaloId calo, unsigned int nMin=20) const
TH1I * cellOccupancy(int minForPrintout=-1) const
TH1I * febOccupancy(CaloId calo) const
Definition run.py:1