ATLAS Offline Software
OccupancyMonitor.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
9 #include "LArSamplesMon/Data.h"
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>
19 using std::cout;
20 using std::endl;
21 
22 using namespace LArSamples;
23 
24 namespace{
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 
60 TH1I* 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 
105  TH1I* h = new TH1I("occ", "Event occupancies", oMax - oMin + 1, oMin - 0.5, oMax + 0.5);
106  h->GetXaxis()->SetTitle("Occupancy");
107  h->GetYaxis()->SetTitle("Number of events");
108  for (std::map<unsigned int, unsigned int>::const_iterator event = occ.begin();
109  event != occ.end(); ++event)
110  h->Fill(event->second);
111 
112  return h;
113 }
114 
115 
116 TH1I* OccupancyMonitor::cellOccupancy(int minForPrintout) const
117 {
118  std::vector<unsigned int> occ(nChannels());
119  for (unsigned int i = 0; i < nChannels(); i++) {
120  const History* history = cellHistory(i);
121  if (history) {
122  occ[i] = occ[i] + history->nData();
123  }
124  }
125 
126  unsigned int oMin = 999999999, oMax = 0;
127 
128  for (std::vector<unsigned int>::const_iterator cell = occ.begin();
129  cell != occ.end(); ++cell)
130  {
131  if (*cell < oMin) oMin = *cell;
132  if (*cell > oMax) oMax = *cell;
133  }
134 
135  //std::map<std::pair<unsigned int, std::string>, unsigned int> names;
136  std::map<std::pair<unsigned int, unsigned int>, std::string> names;
137  TH1I* h = new TH1I("occ", "Cell occupancies", oMax - oMin + 1, oMin - 0.5, oMax + 0.5);
138  h->GetXaxis()->SetTitle("Occupancy");
139  h->GetYaxis()->SetTitle("Number of cells");
140 
141  unsigned int i = 0;
142  for (std::vector<unsigned int>::const_iterator cellOcc = occ.begin();
143  cellOcc != occ.end(); ++cellOcc, ++i) {
144  h->Fill(*cellOcc);
145  const History* history = cellHistory(i);
146  if (!history) continue;
147  if (minForPrintout >= 0) {
148  TString heading = history->cellInfo()->location(2);
149  if (history->nData() > 0) heading += " " + history->data(0)->problems();
150  names[ std::pair<unsigned int, unsigned int>(*cellOcc, i) ] = heading.Data();
151  }
152  }
153 
154  if (minForPrintout >= 0) {
155 /* for (std::map<std::pair<unsigned int, std::string>, unsigned int>::reverse_iterator cell = names.rbegin();
156  cell != names.rend(); ++cell)
157  {
158  if (cell->first.first < (unsigned int)minForPrintout) break;
159  cout << cell->first.first << " : " << cell->second << ", " << cell->first.second << endl;
160  }*/
161  for (std::map<std::pair<unsigned int, unsigned int>, std::string>::reverse_iterator cell = names.rbegin();
162  cell != names.rend(); ++cell)
163  {
164  if (cell->first.first < (unsigned int)minForPrintout) break;
165  cout << cell->first.first << " : " << cell->first.second << ", " << cell->second << endl;
166  }
167  }
168 
169  return h;
170 }
171 
172 
174 {
175  std::map<unsigned int, unsigned int> occ;
176  FilterParams f;
177  f.addCalo(calo);
178  for (unsigned int i = 0; i < nChannels(); i++) {
179  const History* history = pass(i, f);
180  if (!history) continue;
181  for (unsigned int k = 0; k < history->nData(); k++)
182  occ[history->cellInfo()->feb()]++;
183  }
184 
185  unsigned int oMin = 999999999, oMax = 0;
186 
187  for (std::map<unsigned int, unsigned int>::const_iterator feb = occ.begin();
188  feb != occ.end(); ++feb)
189  {
190  if (feb->second < oMin) oMin = feb->second;
191  if (feb->second > oMax) oMax = feb->second;
192  }
193 
194  TH1I* h = new TH1I("occ", "FEB occupancies", oMax - oMin + 1, oMin - 0.5, oMax + 0.5);
195  h->GetXaxis()->SetTitle("Occupancy");
196  h->GetYaxis()->SetTitle("Number of FEBs");
197  for (std::map<unsigned int, unsigned int>::const_iterator feb = occ.begin();
198  feb != occ.end(); ++feb)
199  h->Fill(feb->second);
200 
201  return h;
202 }
203 
204 
206 {
207  TH2D* occ = Geo::partitionHist(part, TString("occupancy_") + Id::str(part), "Occupancies for partition " + Id::str(part));
208  for (unsigned int i = 0; i < nChannels(); i++) {
209  const History* history = cellHistory(i);
210  if (!history) continue;
211  if (Id::partition(history->cellInfo()->calo()) != part) continue;
212  occ->Fill(history->cellInfo()->feb(), history->cellInfo()->channel(), history->nData());
213  }
214 
215  return occ;
216 }
217 
218 
219 TH2D* OccupancyMonitor::etaPhiOccupancy(CaloId calo, short layer, bool useEnergy) const
220 {
221  DataFuncSet func = (useEnergy ? MonitorBase::func("energy") : MonitorBase::func("count"));
222  return etaPhiMap(func, DataFuncArgs(), Form("occupancy_%s_%d", Id::str(calo).Data(), layer),
223  calo, layer,
224  Form("Occupancies for partition %s, layer %d", Id::str(calo).Data(), layer),
225  TotalValue);
226 }
227 
228 
230 {
231  for (unsigned int i = 0; i < nChannels(); i++) {
232  const History* history = cellHistory(i);
233  if (!history) continue;
234  cout << history->cellInfo()->location(verbosity);
235  if (verbosity < 5)
236  cout << " : " << history->nData() << " pulse" << endl;
237  else {
238  cout << " : ";
239  for (unsigned int i = 0; i < history->nData(); i++)
240  cout << "E = " << history->data(i)->energy() << " MeV, " << endl;
241  }
242  }
243 }
244 
245 
246 void OccupancyMonitor::cellAndRingOccupancy(CaloId calo, unsigned int nMin) const
247 {
248  const unsigned int nPhiRings = 5516; // == Geo::nPhiRings()
249  unsigned int nCells[4][3], nRings[4][3];
250  unsigned int ringOccupancy[nPhiRings][4][3];
251 
252  for (unsigned int i = 0; i < 4; i++)
253  for (unsigned int j = 0; j < 3; j++) {
254  for (unsigned int k = 0; k < nPhiRings; k++) ringOccupancy[k][i][j] = 0;
255  nCells[i][j] = 0;
256  nRings[i][j] = 0;
257  }
258 
259  for (unsigned int i = 0; i < nChannels(); i++) {
260  if (i%10000 == 0) cout << "Processing hash = " << i << endl;
261  const History* history = cellHistory(i);
262  if (!history) continue;
263  if (!Id::matchCalo(history->cellInfo()->calo(), calo)) continue;
264  unsigned int n[3] = {0,0,0};
265  int layer = history->cellInfo()->layer();
266  for (unsigned int k = 0; k < history->nData(); k++) {
267  const auto globalPhiRing = history->cellInfo()->globalPhiRing();
268  if (globalPhiRing<0) continue;
269  ringOccupancy[globalPhiRing][layer][(int)history->data(k)->gain()]++;
270  n[(int)history->data(k)->gain()]++;
271  }
272  for (unsigned int g = 0; g < 3; g++) if (n[g] >= nMin) nCells[layer][g]++;
273  //cout << n[1] << " " << nCells[layer][1] << " " << layer << endl;
274  }
275  for (unsigned int i = 0; i < 4; i++)
276  for (unsigned int j = 0; j < 3; j++) {
277  for (unsigned int k = 0; k < nPhiRings; k++)
278  if (ringOccupancy[k][i][j] >= nMin) nRings[i][j]++;
279  }
280 
281  for (unsigned int i = 0; i < 4; i++) {
282  cout << "layer " << i << endl;
283  const auto nChann = Geo::nChannels(calo,i);
284  const auto nEta = Geo::nEta(calo,i);
285  for (unsigned int j = 0; j < 3; j++) {
286  float nCellFract= infinity;
287  if (nChann>0) nCellFract = nCells[i][j]*100.0/nChann;
288  float nRingFract = infinity;
289  if (nEta > 0) nRingFract = nRings[i][j]*100.0/nEta;
290  cout << " gain " << j << " : "
291  << nCells[i][j] << " cells of " << nChann << " (" << nCellFract << " %), "
292  << nRings[i][j] << " rings of " << nEta << " (" << nRingFract << " %)." << endl;
293  }
294  }
295  for (unsigned int i = 0; i < 4; i++) {
296  const auto nChann = Geo::nChannels(calo,i);
297  const auto nEta = Geo::nEta(calo,i);
298  cout << i << " & " << nChann << " & " << nEta << " & ";
299  for (unsigned int j = 0; j < 3; j++){
300  float val = infinity;
301  if (nChann>0) val = nCells[i][j]*100.0/nChann;
302  cout << Form("%4.1f\\%% & ", val);
303  }
304  for (unsigned int j = 0; j < 3; j++){
305  float val = infinity;
306  if (nEta > 0) val = nRings[i][j]*100.0/nEta;
307  cout << Form("%4.1f\\%% & ", val);
308  }
309  cout << endl;
310  }
311 }
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
LArSamples::CellInfo::feb
short feb() const
Definition: CellInfo.cxx:102
LArSamples::CellInfo::globalPhiRing
short globalPhiRing() const
Definition: CellInfo.cxx:125
LArSamples::MonitorBase::func
static DataFuncSet func(const TString &var)
Definition: LArCalorimeter/LArSamplesMon/src/MonitorBase.cxx:426
LArSamples::CellInfo::calo
CaloId calo() const
Definition: CellInfo.h:50
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
LArSamples::OccupancyMonitor::eventOccupancy
TH1I * eventOccupancy() const
Definition: OccupancyMonitor.cxx:86
LArSamples::Id::matchCalo
static bool matchCalo(CaloId id, CaloId idSpec)
Definition: CaloId.cxx:188
LArSamples::OccupancyMonitor::etaPhiOccupancy
TH2D * etaPhiOccupancy(CaloId calo, short layer, bool useEnergy=false) const
Definition: OccupancyMonitor.cxx:219
LArSamples::Id::partition
static PartitionId partition(CaloId id)
Definition: CaloId.cxx:157
LArSamples::FilterParams
Definition: FilterParams.h:50
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
LArSamples::History::cellInfo
const CellInfo * cellInfo() const
Definition: History.h:56
LArSamples::OccupancyMonitor::runOccupancyHistory
TH1I * runOccupancyHistory() const
Definition: OccupancyMonitor.cxx:28
LArSamples::AbsLArCells::cellHistory
virtual const History * cellHistory(unsigned int i) const
Definition: AbsLArCells.cxx:59
Data
@ Data
Definition: BaseObject.h:11
LArSamples::History
Definition: History.h:35
Geometry.h
LArSamples::Data::run
int run() const
Definition: Data.cxx:27
LArSamples::Id::str
static TString str(CaloId id)
Definition: CaloId.cxx:15
bin
Definition: BinsDiffFromStripMedian.h:43
LArSamples::MonitorBase::etaPhiMap
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
Definition: LArCalorimeter/LArSamplesMon/src/MonitorBase.cxx:126
LArSamples
Definition: AbsShape.h:24
LArSamples::OccupancyMonitor::febOccupancy
TH1I * febOccupancy(CaloId calo) const
Definition: OccupancyMonitor.cxx:173
LArSamples::Data::event
int event() const
Definition: Data.cxx:28
LArSamples::MonitorBase::nChannels
unsigned int nChannels() const
Definition: LArCalorimeter/LArSamplesMon/src/MonitorBase.cxx:45
beamspotman.runMax
int runMax
Definition: beamspotman.py:1619
LArSamples::History::data
const Data * data(unsigned int i) const
Definition: History.cxx:91
LArSamples::TotalValue
@ TotalValue
Definition: LArCalorimeter/LArSamplesMon/LArSamplesMon/MonitorBase.h:27
LArSamples::OccupancyMonitor::partitionOccupancy
TH2D * partitionOccupancy(PartitionId part) const
Definition: OccupancyMonitor.cxx:205
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
OccupancyMonitor.h
xAOD::nCells
setRawEt setRawPhi nCells
Definition: TrigCaloCluster_v1.cxx:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
h
python.CaloCondTools.g
g
Definition: CaloCondTools.py:15
beamspotman.n
n
Definition: beamspotman.py:731
extractSporadic.h
list h
Definition: extractSporadic.py:97
python.subdetectors.mmg.names
names
Definition: mmg.py:8
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
LArSamples::CellInfo::location
TString location(int verbose=1) const
Definition: CellInfo.cxx:139
hist_file_dump.f
f
Definition: hist_file_dump.py:135
LArSamples::PartitionId
PartitionId
Definition: CaloId.h:29
run
Definition: run.py:1
LArSamples::History::nData
unsigned int nData() const
Definition: History.h:51
LArSamples::OccupancyMonitor::cellAndRingOccupancy
void cellAndRingOccupancy(CaloId calo, unsigned int nMin=20) const
Definition: OccupancyMonitor.cxx:246
LArSamples::Geo::partitionHist
static TH2D * partitionHist(PartitionId part, const TString &name, const TString &title)
Definition: Geometry.cxx:18
LArSamples::AbsLArCells::pass
const History * pass(unsigned int i, const FilterParams &f) const
Definition: AbsLArCells.cxx:99
LArSamples::OccupancyMonitor::cellOccupancy
TH1I * cellOccupancy(int minForPrintout=-1) const
Definition: OccupancyMonitor.cxx:116
LArSamples::Data::gain
CaloGain::CaloGain gain() const
Definition: Data.h:85
covarianceTool.verbosity
verbosity
Definition: covarianceTool.py:513
LArSamples::CaloId
CaloId
Definition: CaloId.h:21
LArSamples::CellInfo::channel
short channel() const
Definition: CellInfo.h:76
LArSamples::OccupancyMonitor::eventOccupancyHistory
TH1I * eventOccupancyHistory(unsigned int occForDump=0) const
Definition: OccupancyMonitor.cxx:60
LArSamples::Data::problems
TString problems(bool sayNone=false) const
Definition: Data.cxx:135
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
LArSamples::DataFuncSet
Definition: Data.h:54
LArSamples::DataFuncArgs
Definition: Data.h:34
LArSamples::OccupancyMonitor::dump
void dump(short verbosity=2) const
Definition: OccupancyMonitor.cxx:229
LArSamples::Geo::nEta
static short nEta(CaloId calo, short layer, short region, short iPhi=1)
Definition: Geometry.cxx:169
Data.h
LArSamples::Geo::nChannels
static int nChannels(CaloId calo, short layer, short region)
Definition: Geometry.cxx:587
History.h
TrigVSI::AlgConsts::nEta
constexpr int nEta
Default bin number of eta for vertex map.
Definition: Trigger/TrigTools/TrigVrtSecInclusive/TrigVrtSecInclusive/Constants.h:26
Interface.h
beamspotman.runMin
int runMin
Definition: beamspotman.py:1618
LArSamples::CellInfo::layer
short layer() const
Definition: CellInfo.h:53
LArSamples::Data::energy
double energy() const
Definition: Data.h:108
fitman.k
k
Definition: fitman.py:528