-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathPostProcessHitMap.cxx
More file actions
179 lines (158 loc) · 6.6 KB
/
PostProcessHitMap.cxx
File metadata and controls
179 lines (158 loc) · 6.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
///
/// \file PostProcessHitMap.cxx
/// \brief Post processing to produce a plot of the TOF hit map with the reference enabled channels
/// \author Nicolò Jacazio <nicolo.jacazio@cern.ch>
/// \since 09/07/2022
///
// O2 includes
#include "DataFormatsTOF/TOFFEElightInfo.h"
#include "TOFBase/Geo.h"
// ROOT includes
#include <TH2F.h>
#include <TCanvas.h>
#include <TPaveText.h>
#include <TColor.h>
#include <boost/property_tree/ptree.hpp>
// QualityControl includes
#include "QualityControl/MonitorObject.h"
#include "QualityControl/QcInfoLogger.h"
#include "TOF/PostProcessHitMap.h"
#include "QualityControl/DatabaseInterface.h"
using namespace std;
using namespace o2::quality_control::postprocessing;
using namespace o2::quality_control::core;
using namespace o2::quality_control;
namespace o2::quality_control_modules::tof
{
void PostProcessHitMap::configure(const boost::property_tree::ptree& config)
{
const std::string baseJsonPath = "qc.postprocessing." + getID() + ".customization.";
mCCDBPath = config.get<std::string>(baseJsonPath + "CCDBPath", "TOF/MO/TaskDigits/");
ILOG(Info, Support) << "Setting CCDBPath to " << mCCDBPath << ENDM;
mCCDBPathObject = config.get<std::string>(baseJsonPath + "CCDBPathObject", "HitMapNoiseFiltered");
ILOG(Info, Support) << "Setting CCDBPathObject to " << mCCDBPathObject << ENDM;
mRefMapCcdbPath = config.get<std::string>(baseJsonPath + "RefMapCcdbPath", "/TOF/Calib/FEELIGHT");
ILOG(Info, Support) << "Setting RefMapCcdbPath to " << mRefMapCcdbPath << ENDM;
mRefMapTimestamp = config.get<int>(baseJsonPath + "RefMapTimestamp", -1);
ILOG(Info, Support) << "Setting RefMapTimestamp to " << mRefMapTimestamp << ENDM;
mDrawRefOnTop = config.get<bool>(baseJsonPath + "DrawRefOnTop", false);
ILOG(Info, Support) << "Setting DrawRefOnTop to " << (mDrawRefOnTop ? "true" : "false") << ENDM;
}
void PostProcessHitMap::initialize(Trigger, framework::ServiceRegistryRef services)
{
// Setting up services
mDatabase = &services.get<o2::quality_control::repository::DatabaseInterface>();
mCanvasMo.reset();
mCanvasMo = std::make_shared<TCanvas>("defaultMap", "defaultMap");
getObjectsManager()->startPublishing(mCanvasMo.get());
mPhosPad.reset();
mPhosPad = std::make_shared<TPaveText>(13.f, 38.f, 16.f, 53.f, "bl");
mPhosPad->SetTextSize(0.05);
mPhosPad->SetBorderSize(1);
mPhosPad->SetTextColor(kBlack);
mPhosPad->SetFillColor(kGreen);
mPhosPad->SetFillStyle(3004);
mPhosPad->AddText("Red: No Match");
mPhosPad->AddText("Blu: RefMap");
mPhosPad->AddText("Green: HitMap");
}
void PostProcessHitMap::update(Trigger t, framework::ServiceRegistryRef services)
{
// Getting the hit map
const auto mo = mDatabase->retrieveMO(mCCDBPath, mCCDBPathObject, t.timestamp, t.activity);
TH2F* h = static_cast<TH2F*>(mo ? mo->getObject() : nullptr);
if (!h) {
ILOG(Warning, Devel) << "MO '" << mCCDBPathObject << "' not found in path " << mCCDBPath << " with timestamp " << t.timestamp << ENDM;
return;
}
// Getting the reference map
const o2::tof::TOFFEElightInfo* refmap = nullptr;
refmap = o2::quality_control::core::UserCodeInterface::retrieveConditionAny<o2::tof::TOFFEElightInfo>(mRefMapCcdbPath);
if (!mHistoRefHitMap) {
ILOG(Debug, Devel) << "making new refmap from " << mRefMapCcdbPath << " and timestamp " << mRefMapTimestamp << ENDM;
mHistoRefHitMap.reset(static_cast<TH2F*>(h->Clone("ReferenceHitMap")));
mHistoRefHitMap->SetTitle(Form("%s (With reference)", mHistoRefHitMap->GetTitle()));
mHistoRefHitMap->SetFillColor(kRed);
if (mDrawRefOnTop) {
mHistoRefHitMap->SetFillColor(kBlue);
}
}
mHistoRefHitMap->Reset();
int det[5] = { 0 }; // Coordinates
int strip = 0; // Strip
for (auto i = 0; i < refmap->NCHANNELS; i++) {
if (!refmap->getChannelEnabled(i)) {
continue;
}
o2::tof::Geo::getVolumeIndices(i, det);
strip = o2::tof::Geo::getStripNumberPerSM(det[1], det[2]); // Strip index in the SM
const int istrip = mHistoRefHitMap->GetYaxis()->FindBin(strip);
const int crate = det[0] * 4 + det[4] / 12;
const int icrate = mHistoRefHitMap->GetXaxis()->FindBin(0.25f * crate);
mHistoRefHitMap->SetBinContent(icrate, istrip, 1);
}
if (!mHistoHitMap) {
ILOG(Debug, Devel) << "making new hit map" << ENDM;
mHistoHitMap.reset(static_cast<TH2F*>(h->Clone("WithReferenceHitMap")));
mHistoHitMap->SetFillColor(kGreen);
if (mDrawRefOnTop) {
mHistoHitMap->SetFillColor(kRed);
}
}
mHistoHitMap->Reset();
for (int i = 1; i <= h->GetNbinsX(); i++) {
for (int j = 1; j <= h->GetNbinsY(); j++) {
mHistoHitMap->SetBinContent(i, j, 0);
if (h->GetBinContent(i, j) > 0) {
mHistoHitMap->SetBinContent(i, j, 1);
}
}
}
// Finalizing the plot and updating the MO on the CCDB
if (!mHistoRefHitMap) {
ILOG(Warning, Support) << "mHistoRefHitMap undefined, can't finalize" << ENDM;
return;
}
if (!mHistoHitMap) {
ILOG(Warning, Support) << "mHistoHitMap undefined, can't finalize" << ENDM;
return;
}
mCanvasMo->SetName(mHistoHitMap->GetName());
mCanvasMo->SetTitle(mHistoHitMap->GetName());
mCanvasMo->cd();
mCanvasMo->Clear();
mHistoRefHitMap->GetZaxis()->SetRangeUser(0, 1);
mHistoHitMap->GetZaxis()->SetRangeUser(0, 1);
if (!mDrawRefOnTop) {
mHistoRefHitMap->GetListOfFunctions()->Clear();
mHistoRefHitMap->Draw("BOX");
mHistoHitMap->GetListOfFunctions()->Clear();
mHistoHitMap->Draw("BOXsame");
} else {
mHistoHitMap->GetListOfFunctions()->Clear();
mHistoHitMap->Draw("BOX");
mHistoRefHitMap->GetListOfFunctions()->Clear();
mHistoRefHitMap->Draw("BOXsame");
}
mPhosPad->Draw();
// Draw the shifter message
if (mHistoHitMap->GetListOfFunctions()->FindObject(Form("%s_msg", mHistoHitMap->GetName()))) {
mHistoHitMap->GetListOfFunctions()->FindObject(Form("%s_msg", mHistoHitMap->GetName()))->Draw("same");
}
}
void PostProcessHitMap::finalize(Trigger, framework::ServiceRegistryRef)
{
// Only if you don't want it to be published after finalisation.
getObjectsManager()->stopPublishing(mCanvasMo.get());
}
} // namespace o2::quality_control_modules::tof