Project
Loading...
Searching...
No Matches
EMCALCalibExtractor.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
13
14namespace o2
15{
16namespace emcal
17{
18
19//-------------------------------------------------------------------------------------------
20// This function builds the scaled hit distribution
21// It normalizes the hits/cell to the mean value of the row and the column of the cell
22// this is done in an iterative procedure (about 5 iterations are needed)
23// with this procedure, the effects of the TRD and SM structures on the EMCal can be minimized
24// The output is a boost histogram with the hits/cell as a function of cell ID.
25
28// ------------------------------------------------------------------------------------------
30{
31 // create the output histogram
32 boostHisto eSumHistoScaled = boost::histogram::make_histogram(boost::histogram::axis::regular<>(100, 0, 100, "t-texp"), boost::histogram::axis::integer<>(0, mNcells, "CELL ID"));
33 // create a slice for each cell with energies ranging from emin to emax
34 auto hEnergyCol = boost::histogram::make_histogram(boost::histogram::axis::regular<>(100, 0, 100., "t-texp"));
35 auto hEnergyRow = boost::histogram::make_histogram(boost::histogram::axis::regular<>(250, 0, 250., "t-texp"));
36 // temp histogram used to get the scaled energies
37 auto hEnergyScaled = boost::histogram::make_histogram(boost::histogram::axis::regular<>(100, 0, 100, "t-texp"), boost::histogram::axis::integer<>(0, mNcells, "CELL ID"));
38
39 //...........................................
40 // start iterative process of scaling of cells
41 //...........................................
42 for (int iter = 1; iter < 5; iter++) {
43 // array of vectors for calculating the mean hits per col/row
44 std::vector<double> vecCol[100];
45 std::vector<double> vecRow[250];
46
47 for (int cellID = 0; cellID < mNcells; cellID++) {
48 auto tempSlice = boost::histogram::algorithm::reduce(cellAmplitude, boost::histogram::algorithm::shrink(cellID, cellID), boost::histogram::algorithm::shrink(emin, emax));
49 // (0 - row, 1 - column)
50 auto position = mGeometry->GlobalRowColFromIndex(cellID);
51 int row = std::get<0>(position);
52 int col = std::get<1>(position);
53
54 double dCellEnergy = 0.;
55 double dNumOfHits = 0.;
56
57 // will need to change this from 100 to a normal value for the energy axis
58 auto energyAxis = boost::histogram::axis::regular<>(100, 0, 100, "t-texp");
59 auto eMinIndex = energyAxis.index(emin);
60 auto eMaxIndex = energyAxis.index(emax);
61 for (int EBin = eMinIndex; EBin < eMaxIndex; EBin++) {
62 dCellEnergy += hEnergyScaled.at(EBin, cellID) * energyAxis.value(EBin);
63 dNumOfHits += hEnergyScaled.at(EBin, cellID);
64 }
65
66 if (dCellEnergy > 0.) {
67 hEnergyCol(col + 0.5, dCellEnergy);
68 hEnergyRow(row + 0.5, dCellEnergy);
69 vecCol[col].push_back(dCellEnergy);
70 vecRow[row].push_back(dCellEnergy);
71 }
72 } // end loop over cells
73
74 // Fill the histogram: mean hit per column
75 for (int iCol = 1; iCol <= 100; iCol++) {
76 if (vecCol[iCol - 1].size() > 0.) {
77 auto colAxis = boost::histogram::axis::regular<>(100, 0, 100., "t-texp");
78 auto indexCol = colAxis.index(iCol - 0.5);
79 hEnergyCol(indexCol, hEnergyCol.at(indexCol) / vecCol[iCol - 1].size());
80 }
81 }
82
83 // Fill the histogram: mean hit per row
84 for (int iRow = 1; iRow <= 250; iRow++) {
85 if (vecRow[iRow - 1].size() > 0.) {
86 auto rowAxis = boost::histogram::axis::regular<>(250, 0, 250., "t-texp");
87 auto indexRow = rowAxis.index(iRow - 0.5);
88 hEnergyRow(indexRow, hEnergyRow.at(indexRow) / vecRow[iRow - 1].size());
89 }
90 }
91
92 // in run2 there was now a global fit to hits per row
93 // could we just do the mean?
94 auto rowResult = o2::utils::fitBoostHistoWithGaus<double>(hEnergyRow);
95 double meanValRow = rowResult.at(1);
96
97 auto colResult = o2::utils::fitBoostHistoWithGaus<double>(hEnergyCol);
98 double meanValCol = colResult.at(1);
99
100 // Scale each cell by the deviation of the mean of the column and the global mean
101 for (int iCell = 0; iCell < mNcells; iCell++) {
102 // (0 - row, 1 - column)
103 auto position = mGeometry->GlobalRowColFromIndex(iCell);
104 int col = std::get<1>(position);
105 if (hEnergyCol.at(col) > 0.) {
106 // will need to change the 100 depending on the number of energy bins we end up having
107 for (int EBin = 1; EBin < 100; EBin++) {
108 hEnergyScaled(EBin, iCell, hEnergyScaled.at(EBin, iCell) * (meanValCol / hEnergyCol.at(col)));
109 }
110 }
111 }
112
113 // Scale each cell by the deviation of the mean of the row and the global mean
114 for (int iCell = 0; iCell < mNcells; iCell++) {
115 // (0 - row, 1 - column)
116 auto position = mGeometry->GlobalRowColFromIndex(iCell);
117 int row = std::get<0>(position);
118 if (hEnergyRow.at(row) > 0.) {
119 // will need to change the 100 depending on the number of energy bins we end up having
120 for (int EBin = 1; EBin < 100; EBin++) {
121 hEnergyScaled(EBin, iCell, hEnergyScaled.at(EBin, iCell) * (meanValRow / hEnergyRow.at(row)));
122 }
123 }
124 }
125
126 //....................
127 // iteration ends here
128 //....................
129
130 } // end loop iters
131
132 //............................................................................................
133 //..here the average hit per event and the average energy per hit is caluclated for each cell.
134 //............................................................................................
135 for (Int_t cell = 0; cell < mNcells; cell++) {
136 Double_t Esum = 0;
137 Double_t Nsum = 0;
138
139 for (Int_t j = 1; j <= 100; j++) {
140 auto energyAxis = boost::histogram::axis::regular<>(100, 0, 100, "t-texp");
141 Double_t E = energyAxis.value(j);
142 Double_t N = hEnergyScaled.at(j, cell);
143 if (E < emin || E > emax) {
144 continue;
145 }
146 Esum += E * N;
147 Nsum += N;
148 }
149 if (Nsum > 0.) {
150 eSumHistoScaled(cell, Esum / (Nsum)); //..average energy per hit
151 }
152 }
153
154 return eSumHistoScaled;
155}
156
157//____________________________________________
158void EMCALCalibExtractor::checkMaskSM(o2::emcal::BadChannelMap& bcm)
159{
160
161 for (unsigned int i = 0; i < mBadCellFracSM.size(); ++i) {
163 mBadCellFracSM[i] /= 1152.;
165 mBadCellFracSM[i] /= 384.;
166 } else if (mGeometry->GetSMType(i) == o2::emcal::EMCALSMType::DCAL_STANDARD) {
167 mBadCellFracSM[i] /= 768.;
168 }
169 }
170 for (unsigned int i = 0; i < mNcells; ++i) {
171 if (mBadCellFracSM[mGeometry->GetSuperModuleNumber(i)] > EMCALCalibParams::Instance().fracMaskSMFully_bc) {
172 if (bcm.getChannelStatus(i) == o2::emcal::BadChannelMap::MaskType_t::GOOD_CELL) { // only mask good cells, to keep information about dead channels
174 }
175 }
176 }
177}
178
179//____________________________________________
180void EMCALCalibExtractor::checkMaskFEC(o2::emcal::BadChannelMap& bcm)
181{
182 for (unsigned int iSM = 0; iSM < mBadCellFracFEC.size(); ++iSM) {
183 for (unsigned int iFEC = 0; iFEC < mBadCellFracFEC[iSM].size(); ++iFEC) {
184 mBadCellFracFEC[iSM][iFEC] /= 32.; // 32 channels per FEC
185 }
186 }
187
188 for (unsigned int i = 0; i < mNcells; ++i) {
189 if (mBadCellFracFEC[mGeometry->GetSuperModuleNumber(i)][getFECNumberInSM(i)] > EMCALCalibParams::Instance().fracMaskFECFully_bc) {
190 if (bcm.getChannelStatus(i) == o2::emcal::BadChannelMap::MaskType_t::GOOD_CELL) { // only mask good cells, to keep information about dead channels
192 }
193 }
194 }
195}
196
197//____________________________________________
198unsigned int EMCALCalibExtractor::getFECNumberInSM(int absCellID) const
199{
200 std::tuple<int, int> RowCol = mGeometry->GlobalRowColFromIndex(absCellID);
201 std::tuple<int, int, int> PosInSM = mGeometry->GetPositionInSupermoduleFromGlobalRowCol(std::get<0>(RowCol), std::get<1>(RowCol));
202 int iSM = std::get<0>(PosInSM);
203 int col = std::get<1>(PosInSM);
204 int row = std::get<2>(PosInSM);
205 int FECid = static_cast<int>(row / 4.) + 12 * static_cast<int>(col / 8.);
206 LOG(debug) << "FECid " << FECid << " iSM " << iSM << " row " << row << " col " << col;
207 return FECid;
208}
209
210} // end namespace emcal
211} // end namespace o2
int32_t i
uint32_t j
Definition RawData.h:0
uint32_t col
Definition RawData.h:4
std::ostringstream debug
CCDB container for masked cells in EMCAL.
MaskType_t getChannelStatus(unsigned short channelID) const
Get the status of a certain cell.
@ BAD_CELL
Bad cell, must be excluded.
@ GOOD_CELL
GOOD cell, can be used without problems.
void addBadChannel(unsigned short channelID, MaskType_t mask)
Add bad cell to the container.
boostHisto buildHitAndEnergyMeanScaled(double emin, double emax, boostHisto mCellAmplitude)
Scaled hits per cell.
Int_t GetSuperModuleNumber(Int_t absId) const
Get cell SM, from absolute ID number.
std::tuple< int, int, int > GetPositionInSupermoduleFromGlobalRowCol(int row, int col) const
Get the posision (row, col) of a global row-col position.
Definition Geometry.cxx:834
std::tuple< int, int > GlobalRowColFromIndex(int cellID) const
get (Column,Row) pair of cell in global numbering scheme
Definition Geometry.cxx:808
EMCALSMType GetSMType(Int_t nSupMod) const
Definition Geometry.h:242
GLsizeiptr size
Definition glcorearb.h:659
boost::histogram::histogram< std::tuple< boost::histogram::axis::regular< double, boost::use_default, boost::use_default, boost::use_default >, boost::histogram::axis::integer<> >, boost::histogram::unlimited_storage< std::allocator< char > > > boostHisto
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< int > row