Project
Loading...
Searching...
No Matches
PHOSTurnonCalibrator.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
14#include "PHOSBase/Geometry.h"
18#include "CCDB/CcdbApi.h"
19#include "CCDB/CcdbObjectInfo.h"
20
21#include "TF1.h"
22#include "TH1.h"
23#include "TGraphAsymmErrors.h"
24
25#include <fairlogger/Logger.h>
26#include <fstream> // std::ifstream
27
28using namespace o2::phos;
29
30PHOSTurnonSlot::PHOSTurnonSlot(bool useCCDB) : mUseCCDB(useCCDB)
31{
32 mFiredTiles.reset();
33 mNoisyTiles.reset();
34 mTurnOnHistos = std::make_unique<TurnOnHistos>();
35}
37{
38 mUseCCDB = other.mUseCCDB;
39 mRunStartTime = other.mRunStartTime;
40 mFiredTiles.reset();
41 mNoisyTiles.reset();
42 mTurnOnHistos = std::make_unique<TurnOnHistos>();
43}
44
46{
47 for (short ddl = 0; ddl < 14; ddl++) {
48 const std::array<float, TurnOnHistos::Npt>& all = mTurnOnHistos->getTotSpectrum(ddl);
49 const std::array<float, TurnOnHistos::Npt>& tr = mTurnOnHistos->getTrSpectrum(ddl);
50 float sumAll = 0, sumTr = 0.;
51 for (int i = 0; i < TurnOnHistos::Npt; i++) {
52 sumAll += all[i];
53 sumTr += tr[i];
54 }
55 LOG(info) << "DDL " << ddl << " total entries " << sumAll << " trigger clusters " << sumTr;
56 }
57}
58void PHOSTurnonSlot::fill(const gsl::span<const Cell>& cells, const gsl::span<const TriggerRecord>& cellTR,
59 const gsl::span<const Cluster>& clusters, const gsl::span<const TriggerRecord>& cluTR)
60{
61
62 auto ctr = cellTR.begin();
63 auto clutr = cluTR.begin();
64 while (ctr != cellTR.end() && clutr != cluTR.end()) {
65 //
66 // TODO! select NOT PHOS triggered events
67 // DataProcessingHeader::
68 //
69 if (ctr->getBCData() == clutr->getBCData()) {
70 scanClusters(cells, *ctr, clusters, *clutr);
71 } else {
72 LOG(error) << "Different TrigRecords for cells:" << ctr->getBCData() << " and clusters:" << clutr->getBCData();
73 }
74 ctr++;
75 clutr++;
76 }
77}
79{
80 mFiredTiles.reset();
81 mNoisyTiles.reset();
82 mTurnOnHistos.reset();
83}
84void PHOSTurnonSlot::scanClusters(const gsl::span<const Cell>& cells, const TriggerRecord& celltr,
85 const gsl::span<const Cluster>& clusters, const TriggerRecord& clutr)
86{
87 // First fill map of expected tiles from TRU cells
88 mNoisyTiles.reset();
89 int firstCellInEvent = celltr.getFirstEntry();
90 int lastCellInEvent = firstCellInEvent + celltr.getNumberOfObjects();
91 for (int i = firstCellInEvent; i < lastCellInEvent; i++) {
92 const Cell& c = cells[i];
93 if (c.getTRU()) {
94 auto channel = c.getTRUId() - Geometry::getTotalNCells() - 1;
95 if (channel >= 0) {
96 mNoisyTiles.set(channel);
97 }
98 }
99 }
100
101 // Copy to have good and noisy map
102 mFiredTiles.reset();
103 float x{0}, z{0};
104 short ddl{0};
105 int firstCluInEvent = clutr.getFirstEntry();
106 int lastCluInEvent = firstCluInEvent + clutr.getNumberOfObjects();
107 for (int i = firstCluInEvent; i < lastCluInEvent; i++) {
108 const Cluster& clu = clusters[i];
109 if (clu.getEnergy() < 1.e-4) {
110 continue;
111 }
112 char mod = clu.module();
114 // TODO: do we need separate 2x2 and 4x4 spectra? Switch?
115 // short truId2x2 = Geometry::relPosToTruId(mod, x, z, 0);
116 // short truId4x4 = Geometry::relPosToTruId(mod, x, z, 1);
117 mTurnOnHistos->fillTotSp(ddl, clu.getEnergy());
118 // if (clu.firedTrigger() & 1) { //Bit 1: 2x2, bit 2 4x4
119 // mTurnOnHistos->fillFiredSp(ddl, clu.getEnergy());
120 // //Fill trigger map
121 // mFiredTiles.set(truId);
122 // }
123 // }
124 }
125 // Fill final good and noisy maps
126 mTurnOnHistos->fillFiredMap(mFiredTiles);
127 mNoisyTiles ^= mFiredTiles;
128 mTurnOnHistos->fillNoisyMap(mNoisyTiles);
129}
130//==============================================
131
133{
134 // Extract results for the single slot
135 // if not ready yet, prepare containers
136 if (!mTurnOnHistos) {
137 mTurnOnHistos.reset(new TurnOnHistos());
138 }
139 PHOSTurnonSlot* c = slot.getContainer();
140 LOG(info) << "Finalize slot " << slot.getTFStart() << " <= TF <= " << slot.getTFEnd();
141 // Add histos
142 for (int mod = 0; mod < 8; mod++) {
143 mTurnOnHistos->merge(c->getCollectedHistos());
144 }
145 c->clear();
146}
148{
149
150 auto& cont = getSlots();
151 auto& slot = front ? cont.emplace_front(tstart, tend) : cont.emplace_back(tstart, tend);
152 slot.setContainer(std::make_unique<PHOSTurnonSlot>(mUseCCDB));
153 return slot;
154}
155
156bool PHOSTurnonCalibrator::process(uint64_t tf, const gsl::span<const Cell>& cells, const gsl::span<const TriggerRecord>& cellTR,
157 const gsl::span<const Cluster>& clusters, const gsl::span<const TriggerRecord>& cluTR)
158{
159 // process current TF
160 auto& slotTF = getSlotForTF(tf);
161 slotTF.getContainer()->setRunStartTime(tf);
162 slotTF.getContainer()->fill(cells, cellTR, clusters, cluTR);
163
164 return true;
165}
166
168{
169 // Use stored histos to calculate maps and turn-on curves
170 // return true of successful
171
172 // extract TOC
173 if (!mTriggerMap) {
174 mTriggerMap.reset(new TriggerMap());
175 }
176 TF1* th = new TF1("aTh", "[0]/(TMath::Exp(([1]-x)/[2])+1.)+(1.-[0])/(TMath::Exp(([3]-x)/[2])+1.)", 0., 40.);
177 std::array<std::array<float, 10>, TurnOnHistos::NDDL> params;
178 for (int ddl = 0; ddl < TurnOnHistos::NDDL; ddl++) {
179 TH1F hF("fired", "fired", 200, 0., 20.);
180 TH1F hA("all", "all", 200, 0., 20.);
181 const std::array<float, TurnOnHistos::Npt>& vf = mTurnOnHistos->getTrSpectrum(ddl);
182 const std::array<float, TurnOnHistos::Npt>& va = mTurnOnHistos->getTotSpectrum(ddl);
183 for (int i = 0; i < 200; i++) {
184 hF.SetBinContent(i + 1, vf[i]);
185 hA.SetBinContent(i + 1, va[i]);
186 }
187 hF.Sumw2();
188 hA.Sumw2();
189
190 TGraphAsymmErrors* gr = new TGraphAsymmErrors(&hF, &hA);
191 th->SetParameters(0.9, 3.5, 0.3, 7.5, 0.6);
192 gr->Fit(th, "Q", "", 2., 20.);
193 gr->SetName(Form("DDL_%d", ddl));
194 gr->SetTitle(Form("DDL %d", ddl));
195 // TODO!!! Add TGraph with fit to list of objects to send to QC
196 double* par = th->GetParameters();
197 for (int i = 0; i < 10; i++) {
198 params[ddl][i] = par[i];
199 }
200 }
201 std::string_view versionName{"default"};
202 mTriggerMap->addTurnOnCurvesParams(versionName, params);
203 // TODO: calculate bad map
204 // and fill object
205 // mTriggerMap->addBad2x2Channel(short cellID) ;
206}
Utils and constants for calibration and related workflows.
int32_t i
Device to calculate PHOS turn-on curve and bad map.
uint32_t c
Definition RawData.h:2
TFType getTFEnd() const
Definition TimeSlot.h:47
const Container * getContainer() const
Definition TimeSlot.h:53
TFType getTFStart() const
Definition TimeSlot.h:46
short getTRUId() const
Definition Cell.cxx:55
Contains PHOS cluster parameters.
Definition Cluster.h:39
float getEnergy() const
Definition Cluster.h:56
char module() const
Definition Cluster.h:92
void getLocalPosition(float &posX, float &posZ) const
Definition Cluster.h:76
static int getTotalNCells()
Definition Geometry.h:126
bool process(uint64_t tf, const gsl::span< const Cell > &cells, const gsl::span< const TriggerRecord > &trs, const gsl::span< const Cluster > &clusters, const gsl::span< const TriggerRecord > &cluTR)
Slot & emplaceNewSlot(bool front, TFType tstart, TFType tend) final
void fill(const gsl::span< const Cell > &cells, const gsl::span< const TriggerRecord > &trs, const gsl::span< const Cluster > &clusters, const gsl::span< const TriggerRecord > &cluTR)
Header for data corresponding to the same hardware trigger adapted from DataFormatsEMCAL/TriggerRecor...
int getNumberOfObjects() const
static constexpr short Npt
Number of bins in pt distribution.
static constexpr short NDDL
Number of DDLs.
GLint GLenum GLint x
Definition glcorearb.h:403
GLenum const GLfloat * params
Definition glcorearb.h:272
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
std::unique_ptr< GPUReconstructionTimeframe > tf
VectorOfTObjectPtrs other
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
Cluster clu
std::vector< Cluster > clusters
std::vector< Cell > cells