Project
Loading...
Searching...
No Matches
rofs-histogrammer.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
18#include "Framework/Logger.h"
19#include "Framework/Output.h"
20#include "Framework/Task.h"
22#include <TFile.h>
23#include <THnSparse.h>
24#include <fmt/format.h>
25#include <iostream>
26#include <limits>
27#include <map>
28#include <stdexcept>
29
55
58 {
59 mMaxNofTimeFrames = ic.options().get<int>("max-nof-tfs");
60 mFirstTF = ic.options().get<int>("first-tf");
62 auto fileName = ic.options().get<std::string>("outfile");
63 mHistoFile = std::make_unique<TFile>(fileName.c_str(), "RECREATE");
64 if (ic.options().get<bool>("verbose")) {
65 fair::Logger::SetConsoleColor(true);
66 }
67 mFirstOrbit = ic.options().get<int>("first-orbit");
68 mLastOrbit = ic.options().get<int>("last-orbit");
69 }
70
72 {
73 auto firstRof = (mFirstOrbit >= 0) ? o2::InteractionRecord(0, mFirstOrbit) : mRofs.begin()->first.getBCData();
74
75 auto lastRof = (mLastOrbit >= 0) ? o2::InteractionRecord(o2::constants::lhc::LHCMaxBunches, mLastOrbit) : mRofs.rbegin()->first.getBCData();
76 auto nbins = static_cast<Int_t>(lastRof.differenceInBC(firstRof));
77 Int_t bins[1] = {nbins};
78 Double_t xmin[1] = {0.0};
79 Double_t xmax[1] = {nbins * 1.0 + 1};
80 THnSparseL h("rof_times", "rof times", 1, bins, xmin, xmax);
81 for (const auto& p : mRofs) {
82 const auto& rof = p.first;
83 Double_t x[1] = {1.0 * rof.getBCData().differenceInBC(firstRof)};
84 Double_t w = rof.getNEntries();
85 h.Fill(x, w);
86 h.SetBinError(h.GetBin(x), sqrt(w));
87 }
88 h.Write("", TObject::kWriteDelete);
89 }
90
92 {
93 bool shouldEnd = mNofProcessedTFs >= mMaxNofTimeFrames;
94 if (shouldEnd) {
95 pc.services().get<ControlService>().endOfStream();
96 return;
97 }
98
99 bool shouldProcess = (mTFid >= mFirstTF && mNofProcessedTFs < mMaxNofTimeFrames);
100 if (!shouldProcess) {
101 return;
102 }
103
104 mTFid++;
105 auto rofs = pc.inputs().get<gsl::span<o2::mch::ROFRecord>>("rofs");
106 for (const auto& rof : rofs) {
107 mRofs[rof] += rof.getNEntries();
108 }
109 writeHisto();
110 }
111 size_t mFirstTF{0}; // first timeframe to process
112 size_t mMaxNofTimeFrames{std::numeric_limits<size_t>::max()}; // max number of timeframes to process
113 size_t mNofProcessedTFs{0}; // actual number of timeframes processed so far
114 size_t mTFid{0}; // current timeframe index
115 std::unique_ptr<TFile> mHistoFile; // output histogram file
116 std::map<o2::mch::ROFRecord, int> mRofs; // accumulation of rofs
117 uint32_t mFirstOrbit;
118 uint16_t mLastOrbit;
119};
120
121void customize(std::vector<ConfigParamSpec>& workflowOptions)
122{
123 workflowOptions.push_back(ConfigParamSpec{"rofs-name", VariantType::String, "MCH/DIGITROFS", {"name of the input rofs"}});
124}
125
127
129{
130 WorkflowSpec specs;
131
132 auto rofName = cc.options().get<std::string>("rofs-name");
133 std::string inputConfig = "rofs:" + rofName;
134
135 DataProcessorSpec rofHistogrammer{
136 "mch-rofs-histogrammer",
137 Inputs{o2::framework::select(inputConfig.c_str())},
138 Outputs{},
139 AlgorithmSpec{adaptFromTask<Histogrammer>()},
140 Options{
141 {"verbose", VariantType::Bool, false, {"verbose output"}},
142 {"max-nof-tfs", VariantType::Int, 10, {"max number of timeframes to process"}},
143 {"first-tf", VariantType::Int, 0, {"first timeframe to process"}},
144 {"first-orbit", VariantType::Int, 0, {"force first orbit to use as first orbit (for histogram) (default=-1=auto)"}},
145 {"last-orbit", VariantType::Int, 0, {"force last orbit to use as last orbit (for histogram) (default=-1=auto)"}},
146 {"outfile", VariantType::String, "rofs-times.root", {"name of the histogram output file"}}}};
147
148 specs.push_back(rofHistogrammer);
149 return specs;
150}
const auto bins
Definition PID.cxx:49
Header to collect LHC related constants.
Definition of the MCH ROFrame record.
Class for time synchronization of RawReader instances.
ConfigParamRegistry const & options()
Definition InitContext.h:33
decltype(auto) get(R binding, int part=0) const
InputRecord & inputs()
The inputs associated with this processing context.
ServiceRegistryRef services()
The services registry associated with this processing context.
GLint GLenum GLint x
Definition glcorearb.h:403
GLubyte GLubyte GLubyte GLubyte w
Definition glcorearb.h:852
constexpr int LHCMaxBunches
AlgorithmSpec adaptFromTask(Args &&... args)
Definition Task.h:59
std::vector< DataProcessorSpec > WorkflowSpec
std::vector< ConfigParamSpec > Options
std::vector< InputSpec > select(char const *matcher="")
std::vector< InputSpec > Inputs
std::vector< OutputSpec > Outputs
o2::framework::WorkflowSpec WorkflowSpec
WorkflowSpec defineDataProcessing(const ConfigContext &cc)
void customize(std::vector< ConfigParamSpec > &workflowOptions)
std::map< o2::mch::ROFRecord, int > mRofs
void run(ProcessingContext &pc)
std::unique_ptr< TFile > mHistoFile
void init(o2::framework::InitContext &ic)
std::vector< o2::mch::ChannelCode > cc