Project
Loading...
Searching...
No Matches
Clusters.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
12#include <string>
13
14// root includes
15#include "TH1.h"
16#include "TH2.h"
17#include "TFile.h"
18
19// o2 includes
20#include "TPCQC/Clusters.h"
21#include "TPCBase/Painter.h"
22#include "TPCBase/ROC.h"
23#include "TPCBase/CRU.h"
24#include "TPCBase/Mapper.h"
27
29
30using namespace o2::tpc::qc;
31
32//______________________________________________________________________________
33template <class T>
34bool Clusters::processCluster(const T& cluster, const o2::tpc::Sector sector, const int row)
35{
36 if (mIsNormalized) {
38 LOGP(warning, "calling denormalize() before filling");
39 }
40
41 const auto& mapper = Mapper::instance();
42
43 const int nROC = row < 63 ? int(sector) : int(sector) + 36;
44 const int rocRow = row < 63 ? row : row - 63;
45
46 const float pad = cluster.getPad();
47
48 size_t position = mapper.getPadNumber(mNClusters.getCalArray(nROC).getPadSubset(), mNClusters.getCalArray(nROC).getPadSubsetNumber(), rocRow, pad);
49
50 if ((nROC < mapper.getNumberOfIROCs())) { // IROC
51 if (position >= mapper.getPadsInIROC()) {
52 LOG(error) << "IROC out of range: pad position " << position << "\tROC " << nROC << "\tIROC has " << mapper.getPadsInIROC() << " pads";
53 return false;
54 }
55 } else { // OROC
56 if (position >= mapper.getPadsInOROC()) {
57 LOG(error) << "OROC out of range: pad position " << position << "\tROC " << nROC << "\tOROC has " << mapper.getPadsInOROC() << " pads";
58 return false;
59 }
60 }
61
62 const auto qMax = cluster.getQmax();
63 const auto qTot = cluster.getQtot();
64 const auto sigmaPad = cluster.getSigmaPad();
65 const auto sigmaTime = cluster.getSigmaTime();
66 const auto timeBin = cluster.getTime();
67
68 float count = mNClusters.getCalArray(nROC).getValue(rocRow, pad);
69 mNClusters.getCalArray(nROC).setValue(rocRow, pad, count + 1);
70
71 float charge = mQMax.getCalArray(nROC).getValue(rocRow, pad);
72 mQMax.getCalArray(nROC).setValue(rocRow, pad, charge + qMax);
73
74 charge = mQTot.getCalArray(nROC).getValue(rocRow, pad);
75 mQTot.getCalArray(nROC).setValue(rocRow, pad, charge + qTot);
76
77 count = mSigmaTime.getCalArray(nROC).getValue(rocRow, pad);
78 mSigmaTime.getCalArray(nROC).setValue(rocRow, pad, count + sigmaTime);
79
80 count = mSigmaPad.getCalArray(nROC).getValue(rocRow, pad);
81 mSigmaPad.getCalArray(nROC).setValue(rocRow, pad, count + sigmaPad);
82
83 count = mTimeBin.getCalArray(nROC).getValue(rocRow, pad);
84 mTimeBin.getCalArray(nROC).setValue(rocRow, pad, count + timeBin);
85
86 return true;
87}
88
89//______________________________________________________________________________
90void Clusters::fillADCValue(int cru, int rowInSector, int padInRow, int timeBin, float adcValue)
91{
92 if (mIsNormalized) {
94 LOGP(warning, "calling denormalize() before filling");
95 }
96
97 const CRU cruID(cru);
98 float val;
99 val = mNClusters.getValue(cruID.sector(), rowInSector, padInRow);
100 mNClusters.setValue(cruID.sector(), rowInSector, padInRow, val + 1);
101
102 val = mQMax.getValue(cruID.sector(), rowInSector, padInRow);
103 mQMax.setValue(cruID.sector(), rowInSector, padInRow, val + adcValue);
104
105 val = mTimeBin.getValue(cruID.sector(), rowInSector, padInRow);
106 mTimeBin.setValue(cruID.sector(), rowInSector, padInRow, val + timeBin);
107}
108
109//______________________________________________________________________________
111{
112 if (mIsNormalized) {
113 return;
114 }
115
116 mQMax /= mNClusters;
117 mQTot /= mNClusters;
118 mSigmaTime /= mNClusters;
119 mSigmaPad /= mNClusters;
120 mTimeBin /= mNClusters;
121
122 mIsNormalized = true;
123}
124
125//______________________________________________________________________________
127{
128 if (!mIsNormalized) {
129 return;
130 }
131
132 mQMax *= mNClusters;
133 mQTot *= mNClusters;
134 mSigmaTime *= mNClusters;
135 mSigmaPad *= mNClusters;
136 mTimeBin *= mNClusters;
137
138 mIsNormalized = false;
139}
140
141//______________________________________________________________________________
143{
144 mNClusters = 0;
145 mQMax = 0;
146 mQTot = 0;
147 mSigmaTime = 0;
148 mSigmaPad = 0;
149 mTimeBin = 0;
150
151 mIsNormalized = false;
152 mProcessedTFs = 0;
153}
154
155//______________________________________________________________________________
157{
158 const bool isThisNormalized = mIsNormalized;
159 const bool isOtherNormalized = clusters.mIsNormalized;
160
161 if (isThisNormalized) {
162 denormalize();
163 }
164 if (isOtherNormalized) {
165 clusters.denormalize();
166 }
167
168 mNClusters += clusters.mNClusters;
169 mQMax += clusters.mQMax;
170 mQTot += clusters.mQTot;
171 mSigmaTime += clusters.mSigmaTime;
172 mSigmaPad += clusters.mSigmaPad;
173 mTimeBin += clusters.mTimeBin;
174
175 if (isThisNormalized) {
176 normalize();
177 }
178 if (isOtherNormalized) {
179 clusters.normalize();
180 }
181}
182
183//______________________________________________________________________________
184void Clusters::dumpToFile(std::string filename, int type)
185{
186 if (filename.find(".root") != std::string::npos) {
187 filename.resize(filename.size() - 5);
188 }
189
190 if (type == 0) {
191 const std::string canvasFile = filename + "_canvas.root";
192 auto f = std::unique_ptr<TFile>(TFile::Open(canvasFile.c_str(), "recreate"));
193 f->WriteObject(o2::tpc::painter::draw(mNClusters), mNClusters.getName().data());
194 f->WriteObject(o2::tpc::painter::draw(mQMax), mQMax.getName().data());
195 f->WriteObject(o2::tpc::painter::draw(mQTot), mQTot.getName().data());
196 f->WriteObject(o2::tpc::painter::draw(mSigmaTime), mSigmaTime.getName().data());
197 f->WriteObject(o2::tpc::painter::draw(mSigmaPad), mSigmaPad.getName().data());
198 f->WriteObject(o2::tpc::painter::draw(mTimeBin), mTimeBin.getName().data());
199 f->Close();
200 }
201
202 if (type == 0 || type == 1) {
203 const std::string calPadFile = filename + ".root";
204 auto f = std::unique_ptr<TFile>(TFile::Open(calPadFile.c_str(), "recreate"));
205 TNamed nTFs("processedTFs", std::to_string(mProcessedTFs).data());
206 f->WriteObject(&mNClusters, mNClusters.getName().data());
207 f->WriteObject(&mQMax, mQMax.getName().data());
208 f->WriteObject(&mQTot, mQTot.getName().data());
209 f->WriteObject(&mSigmaTime, mSigmaTime.getName().data());
210 f->WriteObject(&mSigmaPad, mSigmaPad.getName().data());
211 f->WriteObject(&mTimeBin, mTimeBin.getName().data());
212 nTFs.Write();
213 f->Close();
214 }
215
216 if (type == 2) {
217 const std::string calPadFile = filename + ".root";
218 auto f = std::unique_ptr<TFile>(TFile::Open(calPadFile.c_str(), "recreate"));
219 f->WriteObject(this, "ClusterQC");
220 }
221}
222
223// ===| explicit instantiations |===============================================
224template bool Clusters::processCluster<o2::tpc::ClusterNative>(const o2::tpc::ClusterNative&, const o2::tpc::Sector, const int);
225template bool Clusters::processCluster<o2::tpc::KrCluster>(const o2::tpc::KrCluster&, const o2::tpc::Sector, const int);
Class of a TPC cluster in TPC-native coordinates (row, time)
ClassImp(o2::tpc::qc::Clusters)
int16_t charge
Definition RawEventData.h:5
Struct for Krypton and X-ray clusters.
const Sector sector() const
Definition CRU.h:65
void setValue(const size_t channel, const T &value)
Definition CalArray.h:95
PadSubset getPadSubset() const
Definition CalArray.h:89
int getPadSubsetNumber() const
Definition CalArray.h:93
const T getValue(const size_t channel) const
Definition CalArray.h:96
const CalType & getCalArray(size_t position) const
Definition CalDet.h:63
void setValue(const int sec, const int globalPadInSector, const T &value)
Definition CalDet.h:257
const T getValue(const int sec, const int globalPadInSector) const
Definition CalDet.h:154
const std::string & getName() const
Definition CalDet.h:85
static Mapper & instance(const std::string mappingDir="")
Definition Mapper.h:44
void fillADCValue(int cru, int rowInSector, int padInRow, int timeBin, float adcValue)
Definition Clusters.cxx:90
void merge(Clusters &clusters)
Definition Clusters.cxx:156
void dumpToFile(std::string filename, int type=0)
Definition Clusters.cxx:184
GLint GLsizei count
Definition glcorearb.h:399
GLdouble f
Definition glcorearb.h:310
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLboolean * data
Definition glcorearb.h:298
GLuint GLfloat * val
Definition glcorearb.h:1582
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
std::string filename()
static TCanvas * draw(const CalDet< T > &calDet, int nbins1D=300, float xMin1D=0, float xMax1D=0, TCanvas *outputCanvas=nullptr)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< Cluster > clusters
std::vector< int > row