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