|
| 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 | +#include "EMCAL/FECRateVisualization.h" |
| 12 | +#include "QualityControl/DatabaseInterface.h" |
| 13 | +#include "QualityControl/QcInfoLogger.h" |
| 14 | + |
| 15 | +#include <TCanvas.h> |
| 16 | +#include <TGraph.h> |
| 17 | +#include <TH1.h> |
| 18 | +#include <TLegend.h> |
| 19 | +#include <TTree.h> |
| 20 | + |
| 21 | +#include <boost/property_tree/ptree.hpp> |
| 22 | + |
| 23 | +using namespace o2::quality_control::postprocessing; |
| 24 | +using namespace o2::quality_control::core; |
| 25 | + |
| 26 | +namespace o2::quality_control_modules::emcal |
| 27 | +{ |
| 28 | + |
| 29 | +FECRateVisualization::~FECRateVisualization() |
| 30 | +{ |
| 31 | +} |
| 32 | + |
| 33 | +void FECRateVisualization::configure(const boost::property_tree::ptree& config) |
| 34 | +{ |
| 35 | + auto taskConfig = config.get_child_optional("qc.postprocessing." + getID() + ".configuration"); |
| 36 | + if (taskConfig) { |
| 37 | + auto cfgMaxRate = taskConfig.get().get_child_optional("MaxRate"); |
| 38 | + if (cfgMaxRate) { |
| 39 | + mMaxRate = cfgMaxRate->get_value<double>(); |
| 40 | + ILOG(Info, Support) << "Found max FEC rate: " << mMaxRate << ENDM; |
| 41 | + } |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +void FECRateVisualization::initialize(Trigger, framework::ServiceRegistryRef) |
| 46 | +{ |
| 47 | + for (int ism = 0; ism < 20; ism++) { |
| 48 | + mSupermoduleCanvas[ism] = std::make_unique<TCanvas>(Form("FECRatesSM%d", ism), Form("FEC rates for supermodule %d", ism), 800, 600); |
| 49 | + getObjectsManager()->startPublishing(mSupermoduleCanvas[ism].get(), PublicationPolicy::Forever); |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +void FECRateVisualization::update(Trigger t, framework::ServiceRegistryRef services) |
| 54 | +{ |
| 55 | + std::cout << "Using max rate: " << mMaxRate << std::endl; |
| 56 | + std::array<Color_t, 10> colors = { { kRed, kGreen, kBlue, kOrange, kTeal, kMagenta, kCyan, kViolet, kGray, kBlack } }; |
| 57 | + std::array<Style_t, 10> markers = { { 20, 21, 22, 24, 25, 26, 27, 28, 29, 30 } }; |
| 58 | + |
| 59 | + const std::array<int, 12> fecs_small_A = { { 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13 } }, |
| 60 | + fecs_small_C = { { 27, 28, 29, 31, 32, 33, 34, 39, 36, 37, 38, 39 } }; |
| 61 | + const std::array<int, 24> fecs_DCAL = { { 1, 2, 3, 4, 5, 6, 7, 8, 14, 15, 16, 17, 18, 19, 21, 22, 27, 28, 29, 31, 32, 33, 34, 35 } }; |
| 62 | + enum SMType { |
| 63 | + FULL, |
| 64 | + SMALL_A, |
| 65 | + SMALL_C, |
| 66 | + DCAL |
| 67 | + }; |
| 68 | + const std::array<SMType, 20> smtypes{ { FULL, FULL, FULL, FULL, FULL, FULL, FULL, FULL, FULL, FULL, SMALL_A, SMALL_C, DCAL, DCAL, DCAL, DCAL, DCAL, DCAL, SMALL_C, SMALL_A } }; |
| 69 | + |
| 70 | + auto& qcdb = services.get<quality_control::repository::DatabaseInterface>(); |
| 71 | + auto mo = qcdb.retrieveMO("EMC/MO/CellTrendingDetailEMCAL", "CellTrendingDetailEMCAL", t.timestamp, t.activity); |
| 72 | + TTree* datatree = static_cast<TTree*>(mo->getObject()); |
| 73 | + if (!datatree) { |
| 74 | + ILOG(Error, Support) << "Tree not found" << ENDM; |
| 75 | + return; |
| 76 | + } |
| 77 | + |
| 78 | + for (int smID = 0; smID < 20; smID++) { |
| 79 | + int minfec = smID * 40; |
| 80 | + mSupermoduleCanvas[smID]->Clear(); |
| 81 | + mSupermoduleCanvas[smID]->Divide(2, 2); |
| 82 | + int currentpad = 0; |
| 83 | + TLegend* leg = nullptr; |
| 84 | + bool isFirst = true; |
| 85 | + for (int ifec = 0; ifec < 40; ifec++) { |
| 86 | + if (ifec % 10 == 0) { |
| 87 | + currentpad++; |
| 88 | + mSupermoduleCanvas[smID]->cd(currentpad); |
| 89 | + |
| 90 | + leg = new TLegend(0.15, 0.75, 0.89, 0.89); |
| 91 | + leg->SetBorderSize(0); |
| 92 | + leg->SetFillStyle(0); |
| 93 | + leg->SetTextFont(42); |
| 94 | + leg->SetNColumns(5); |
| 95 | + isFirst = true; |
| 96 | + } |
| 97 | + bool found = true; |
| 98 | + switch (smtypes[smID]) { |
| 99 | + case SMType::FULL: |
| 100 | + // exclude LEDMON (0) and TRU FECs (10, 20, 30) as they leave no data in the occupancy plot |
| 101 | + found = (ifec != 0) && (ifec != 10) && (ifec != 20) && (ifec != 30); |
| 102 | + break; |
| 103 | + case SMType::SMALL_A: |
| 104 | + found = std::find(fecs_small_A.begin(), fecs_small_A.end(), ifec) != fecs_small_A.end(); |
| 105 | + break; |
| 106 | + case SMType::SMALL_C: |
| 107 | + found = std::find(fecs_small_C.begin(), fecs_small_C.end(), ifec) != fecs_small_C.end(); |
| 108 | + break; |
| 109 | + case SMType::DCAL: |
| 110 | + found = std::find(fecs_DCAL.begin(), fecs_DCAL.end(), ifec) != fecs_DCAL.end(); |
| 111 | + break; |
| 112 | + default: |
| 113 | + break; |
| 114 | + }; |
| 115 | + if (!found) { |
| 116 | + continue; |
| 117 | + } |
| 118 | + int globalfec = ifec + minfec; |
| 119 | + const char* drawoptions = (isFirst) ? "pl" : "plsame"; |
| 120 | + datatree->Draw(Form("cellOccupancyEMCwThr_PHYS.fecCounts[%d]:time", globalfec), "", drawoptions); |
| 121 | + // gPad->GetListOfPrimitives()->ls(); |
| 122 | + auto targetgraph = static_cast<TGraph*>(gPad->GetPrimitive("Graph")); |
| 123 | + targetgraph->SetName(Form("fectrend%d", ifec)); |
| 124 | + targetgraph->SetMarkerColor(colors[ifec % 10]); |
| 125 | + targetgraph->SetLineColor(colors[ifec % 10]); |
| 126 | + targetgraph->SetMarkerStyle(markers[ifec % 10]); |
| 127 | + leg->AddEntry(targetgraph, Form("FEC %d", ifec), "lep"); |
| 128 | + |
| 129 | + if (isFirst) { |
| 130 | + auto frame = static_cast<TH1*>(gPad->GetPrimitive("htemp")); |
| 131 | + frame->SetName(Form("frame_SM%d_branch_%d", smID, ifec / 10)); |
| 132 | + frame->GetXaxis()->SetTimeDisplay(1); |
| 133 | + frame->GetXaxis()->SetNdivisions(503); |
| 134 | + frame->GetXaxis()->SetTimeFormat("%Y-%m-%d %H:%M"); |
| 135 | + frame->GetXaxis()->SetTimeOffset(0, "gmt"); |
| 136 | + frame->GetYaxis()->SetLimits(0., mMaxRate); |
| 137 | + frame->SetYTitle("FEC counts / minute"); |
| 138 | + frame->SetTitle(Form("Branch %d", ifec / 10)); |
| 139 | + leg->Draw(); |
| 140 | + isFirst = false; |
| 141 | + } |
| 142 | + |
| 143 | + gPad->Update(); |
| 144 | + } |
| 145 | + |
| 146 | + mSupermoduleCanvas[smID]->cd(); |
| 147 | + mSupermoduleCanvas[smID]->Update(); |
| 148 | + } |
| 149 | +} |
| 150 | + |
| 151 | +void FECRateVisualization::finalize(Trigger, framework::ServiceRegistryRef) |
| 152 | +{ |
| 153 | + for (auto& canvas : mSupermoduleCanvas) { |
| 154 | + getObjectsManager()->stopPublishing(canvas.get()); |
| 155 | + } |
| 156 | +} |
| 157 | + |
| 158 | +} // namespace o2::quality_control_modules::emcal |
0 commit comments