Project
Loading...
Searching...
No Matches
EMCALChannelData.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
15// #include "Framework/Logger.h"
16// #include "CommonUtils/MemFileHelper.h"
17// #include "CCDB/CcdbApi.h"
18// #include "DetectorsCalibration/Utils.h"
19// #include <boost/histogram.hpp>
20// #include <boost/histogram/ostream.hpp>
21// #include <boost/format.hpp>
22// #include <cassert>
23// #include <iostream>
24// #include <sstream>
25// #include <TStopwatch.h>
26#if (defined(WITH_OPENMP) && !defined(__CLING__))
27#include <omp.h>
28#endif
29
30namespace o2
31{
32namespace emcal
33{
34
36using boost::histogram::indexed;
37
38//===================================================================
39//_____________________________________________
40void EMCALChannelData::PrintStream(std::ostream& stream) const
41{
42 stream << "EMCAL Cell ID: " << mHisto[0] << "\n";
43}
44//_____________________________________________
45std::ostream& operator<<(std::ostream& stream, const EMCALChannelData& emcdata)
46{
47 emcdata.PrintStream(stream);
48 return stream;
49}
50//_____________________________________________
51void EMCALChannelData::fill(const gsl::span<const o2::emcal::Cell> data)
52{
53 // the fill function is called once per event
54 mEvents++;
55
56 if (data.size() == 0) {
57 return;
58 }
59
60 auto fillfunction = [this](int thread, const gsl::span<const o2::emcal::Cell>& data, double minCellEnergy, double minCellEnergyTime) {
61 LOG(debug) << "filling in thread " << thread << " ncells = " << data.size();
62 auto& mCurrentHist = mHisto[thread];
63 auto& mCurrentHistTime = mHistoTime[thread];
64 unsigned int nEntries = 0; // counter set inside function increases speed compared to simply using mVecNEntriesInHisto[thread]. Added to global counter at end of function
65 for (const auto& cell : data) {
66 int id = cell.getTower();
67 double cellEnergy = cell.getEnergy();
68
69 if (mApplyGainCalib) {
70 LOG(debug) << " gain calib factor for cell " << id << " = " << mArrGainCalibFactors[id];
71 cellEnergy *= mArrGainCalibFactors[id];
72 }
73
74 if (cellEnergy < minCellEnergy) {
75 LOG(debug) << "skipping cell ID " << id << ": with energy = " << cellEnergy << " below threshold of " << minCellEnergy;
76 continue;
77 }
78
79 LOG(debug) << "inserting in cell ID " << id << ": energy = " << cellEnergy;
80 mCurrentHist(cellEnergy, id);
81 nEntries++;
82
83 if (cellEnergy > minCellEnergyTime) {
84 double cellTime = cell.getTimeStamp();
85 LOG(debug) << "inserting in cell ID " << id << ": time = " << cellTime;
86 mCurrentHistTime(cellTime, id);
87 }
88 }
89 mVecNEntriesInHisto[thread] += nEntries;
90 };
91
92 std::vector<gsl::span<const o2::emcal::Cell>> ranges(mNThreads);
93 auto size_per_thread = static_cast<unsigned int>(std::ceil((static_cast<float>(data.size()) / mNThreads)));
94 unsigned int currentfirst = 0;
95 for (int ithread = 0; ithread < mNThreads; ithread++) {
96 unsigned int nelements = std::min(size_per_thread, static_cast<unsigned int>(data.size() - 1 - currentfirst));
97 ranges[ithread] = data.subspan(currentfirst, nelements);
98 currentfirst += nelements;
99 }
100
101 double minCellEnergy = o2::emcal::EMCALCalibParams::Instance().minCellEnergy_bc;
102 double minCellEnergyTime = o2::emcal::EMCALCalibParams::Instance().minCellEnergyTime_bc;
103
104#if (defined(WITH_OPENMP) && !defined(__CLING__))
105 LOG(debug) << "Number of threads that will be used = " << mNThreads;
106#pragma omp parallel for num_threads(mNThreads)
107#else
108 LOG(debug) << "OPEN MP will not be used for the bad channel calibration";
109#endif
110 for (int ithread = 0; ithread < mNThreads; ithread++) {
111 fillfunction(ithread, ranges[ithread], minCellEnergy, minCellEnergyTime);
112 }
113
114 // only sum up entries if needed
115 if (!o2::emcal::EMCALCalibParams::Instance().useNEventsForCalib_bc) {
116 for (auto& nEntr : mVecNEntriesInHisto) {
117 mNEntriesInHisto += nEntr;
118 nEntr = 0;
119 }
120 }
121}
122//_____________________________________________
124{
125 LOG(debug) << *this;
126}
127//_____________________________________________
129{
130 mEvents += prev->getNEvents();
131 mNEntriesInHisto += prev->getNEntriesInHisto();
132 mHisto[0] += prev->getHisto();
133 mHistoTime[0] += prev->getHisto();
134}
135
136//_____________________________________________
138{
139 bool enough = false;
140
141 LOG(debug) << "mNEntriesInHisto: " << mNEntriesInHisto * mNThreads << " needed: " << EMCALCalibParams::Instance().minNEntries_bc << " mEvents = " << mEvents;
142 // use entries in histogram for calibration
143 if (!EMCALCalibParams::Instance().useNEventsForCalib_bc) {
144 long unsigned int nEntries = 0;
145 if (mNEntriesInHisto > EMCALCalibParams::Instance().minNEntries_bc) {
146 enough = true;
147 }
148 }
149 // use number of events (from emcal trigger record) for calibration
150 if (EMCALCalibParams::Instance().useNEventsForCalib_bc && mEvents > EMCALCalibParams::Instance().minNEvents_bc) {
151 enough = true;
152 }
153
154 return enough;
155}
156
157//_____________________________________________
159{
160 mOutputBCM = mCalibExtractor->calibrateBadChannels(mEsumHisto, getHistoTime());
161}
162//____________________________________________
163
164} // end namespace emcal
165} // end namespace o2
std::ostringstream debug
void analyzeSlot()
Peform the calibration and flag the bad channel map Average energy per hit histogram is fitted with a...
void PrintStream(std::ostream &stream) const
Print relevant info for EMCALChannelData on a given stream.
long unsigned int getNEntriesInHisto() const
void merge(EMCALChannelData *prev)
Merge the data of two slots.
void fill(const gsl::span< const o2::emcal::Cell > data)
Fill the container with the cell ID and amplitude.
const boostHisto & getHistoTime()
Get current calibration histogram with time information.
void print()
Print a useful message about the container.
const boostHisto & getHisto()
Get current calibration histogram.
bool hasEnoughData() const
Check if enough stataistics was accumulated to perform calibration.
GLboolean * data
Definition glcorearb.h:298
GLuint GLuint stream
Definition glcorearb.h:1806
GLuint id
Definition glcorearb.h:650
std::ostream & operator<<(std::ostream &stream, const Cell &cell)
Stream operator for EMCAL cell.
Definition Cell.cxx:355
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"