Project
Loading...
Searching...
No Matches
tpc-occupancy-filter.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 <memory>
13#include <vector>
14#include <string>
15#include <unordered_map>
16#include <cstdint>
17
28
32#include "TPCBase/Sector.h"
36
37using namespace o2::framework;
38using namespace o2::tpc;
39
40// Global variable used to transport data to the completion policy
41static std::vector<InputSpec> gPolicyData;
42static uint64_t gTpcSectorMask = 0xFFFFFFFFF;
43
44// customize the completion policy
45void customize(std::vector<o2::framework::CompletionPolicy>& policies)
46{
48 // policies.push_back(CompletionPolicyHelpers::defineByName("tpc-krypton-raw-filter.*", CompletionPolicy::CompletionOp::Consume));
49 // policies.push_back(CompletionPolicyHelpers::defineByName("file-writer", CompletionPolicy::CompletionOp::Consume));
50
51 // we customize the pipeline processors to consume data as it comes
52 //
53 // the custom completion policy for the tracker
55}
56
57// we need to add workflow options before including Framework/runDataProcessing
58void customize(std::vector<ConfigParamSpec>& workflowOptions)
59{
60 std::string sectorDefault = "0-" + std::to_string(o2::tpc::Sector::MAXSECTOR - 1);
61 int defaultlanes = std::max(1u, std::thread::hardware_concurrency() / 2);
62
63 std::vector<ConfigParamSpec> options{
64 {"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings (e.g.: 'TPCCalibPedestal.FirstTimeBin=10;...')"}},
65 {"configFile", VariantType::String, "", {"configuration file for configurable parameters"}},
66 {"outputFile", VariantType::String, "./occupancy-filtered-digits.root", {"output file name for the filtered krypton file"}},
67 {"lanes", VariantType::Int, defaultlanes, {"Number of parallel processing lanes."}},
68 {"sectors", VariantType::String, sectorDefault.c_str(), {"List of TPC sectors, comma separated ranges, e.g. 0-3,7,9-15"}},
69 {"writer-type", VariantType::String, "local", {"Writer type (local, EPN, none)"}},
70 {"ccdb-path", VariantType::String, "http://ccdb-test.cern.ch:8080", {"Path to CCDB"}},
71 };
72
73 std::swap(workflowOptions, options);
74}
75
77
78template <typename T>
80
81enum class WriterType {
82 Local,
83 EPN,
84 None,
85};
86
87const std::unordered_map<std::string, WriterType> WriterMap{
88 {"local", WriterType::Local},
89 {"EPN", WriterType::EPN},
90 {"none", WriterType::None},
91};
92
94{
95
96 using namespace o2::tpc;
97
98 // set up configuration
99 o2::conf::ConfigurableParam::updateFromFile(config.options().get<std::string>("configFile"));
100 o2::conf::ConfigurableParam::updateFromString(config.options().get<std::string>("configKeyValues"));
101 o2::conf::ConfigurableParam::writeINI("o2tpccalibration_configuration.ini");
102
103 const std::string outputFile = config.options().get<std::string>("outputFile");
104
105 const auto tpcSectors = o2::RangeTokenizer::tokenize<int>(config.options().get<std::string>("sectors"));
106 const auto nSectors = (int)tpcSectors.size();
107 const auto nLanes = std::min(config.options().get<int>("lanes"), nSectors);
108
109 WriterType writerType;
110 try {
111 writerType = WriterMap.at(config.options().get<std::string>("writer-type"));
112 } catch (std::out_of_range&) {
113 throw std::invalid_argument(std::string("invalid writer-type type: ") + config.options().get<std::string>("writer-type"));
114 }
115
116 WorkflowSpec workflow;
117
118 if (nLanes <= 0) {
119 return workflow;
120 }
121
122 std::vector<int> laneConfiguration = tpcSectors; // Currently just a copy of the tpcSectors, why?
123
124 gTpcSectorMask = 0;
125 for (auto s : tpcSectors) {
126 gTpcSectorMask |= (1ul << s);
127 }
128 gPolicyData.emplace_back(o2::framework::InputSpec{"data", o2::framework::ConcreteDataTypeMatcher{"TPC", "FILTERDIG"}});
129
130 WorkflowSpec parallelProcessors;
131 parallelProcessors.emplace_back(getOccupancyFilterSpec());
132
133 parallelProcessors = parallelPipeline(
134 parallelProcessors, nLanes,
135 [&laneConfiguration]() { return laneConfiguration.size(); },
136 [&laneConfiguration](size_t index) { return laneConfiguration[index]; });
137 workflow.insert(workflow.end(), parallelProcessors.begin(), parallelProcessors.end());
138
139 if (writerType == WriterType::Local) {
141 //
142 // generation of processor specs for various types of outputs
143 // based on generic RootTreeWriter and MakeRootTreeWriterSpec generator
144 //
145 // -------------------------------------------------------------------------------------------
146 // the callbacks for the RootTreeWriter
147 //
148 // The generic writer needs a way to associate incoming data with the individual branches for
149 // the TPC sectors. The sector number is transmitted as part of the sector header, the callback
150 // finds the corresponding index in the vector of configured sectors
151 auto getIndex = [tpcSectors](o2::framework::DataRef const& ref) {
152 auto const* tpcSectorHeader = o2::framework::DataRefUtils::getHeader<o2::tpc::TPCSectorHeader*>(ref);
153 if (!tpcSectorHeader) {
154 throw std::runtime_error("TPC sector header missing in header stack");
155 }
156 if (tpcSectorHeader->sector() < 0) {
157 // special data sets, don't write
158 return ~(size_t)0;
159 }
160 size_t index = 0;
161 for (auto const& sector : tpcSectors) {
162 if (sector == tpcSectorHeader->sector()) {
163 return index;
164 }
165 ++index;
166 }
167 throw std::runtime_error("sector " + std::to_string(tpcSectorHeader->sector()) + " not configured for writing");
168 };
169 auto getName = [tpcSectors](std::string base, size_t index) {
170 return base + "_" + std::to_string(tpcSectors.at(index));
171 };
172
173 auto makeWriterSpec = [tpcSectors, laneConfiguration, getIndex, getName](const char* processName,
174 const char* defaultFileName,
175 const char* defaultTreeName,
176 auto&& databranch,
177 bool singleBranch = false) {
178 if (tpcSectors.size() == 0) {
179 throw std::invalid_argument(std::string("writer process configuration needs list of TPC sectors"));
180 }
181
182 auto amendInput = [tpcSectors, laneConfiguration](InputSpec& input, size_t index) {
183 input.binding += std::to_string(laneConfiguration[index]);
184 DataSpecUtils::updateMatchingSubspec(input, laneConfiguration[index]);
185 };
186 auto amendBranchDef = [laneConfiguration, amendInput, tpcSectors, getIndex, getName, singleBranch](auto&& def, bool enableMC = true) {
187 if (!singleBranch) {
188 def.keys = mergeInputs(def.keys, laneConfiguration.size(), amendInput);
189 // the branch is disabled if set to 0
190 def.nofBranches = enableMC ? tpcSectors.size() : 0;
191 def.getIndex = getIndex;
192 def.getName = getName;
193 } else {
194 // instead of the separate sector branches only one is going to be written
195 def.nofBranches = enableMC ? 1 : 0;
196 }
197 return std::move(def);
198 };
199
200 return std::move(MakeRootTreeWriterSpec(processName, defaultFileName, defaultTreeName,
201 std::move(amendBranchDef(databranch)))());
202 };
203
205 //
206 // a writer process for digits
207 //
208 // selected by output type 'difits'
209 using OutputType = std::vector<o2::tpc::Digit>;
210 workflow.push_back(makeWriterSpec("tpc-occupancy-writer",
211 outputFile.data(),
212 "o2sim",
213 BranchDefinition<OutputType>{InputSpec{"data", "TPC", "FILTERDIG", 0},
214 "TPCDigit",
215 "digit-branch-name"}));
216 } else if (writerType == WriterType::EPN) {
217 workflow.push_back(getFileWriterSpec<Digit>("data:TPC/FILTERDIG", BranchType::Digits));
218 }
219
220 return workflow;
221}
std::string getName(const TDataMember *dm, int index, int size)
Definition of the TPC Digit.
Writer for calibration data.
configStandalone Light OpenGL display display_light Apply smoothing to points Enable Z buffer Highlight links Highlight seeds Highlight sector tracks Highlight final tracks Show individual sector
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error s
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc Replace constant variables static by constexpr expressions Compile RTC in deterministic with NO_FAST_MATH flags and GPUCA_DETERMINISTIC_MODE define Use RTC to optimize GPU code h configStandalone Processing proc_rtctech Use a file lock to serialize access to the cache folder Print launch bounds used for RTC code as debugging for exit after def(1)) AddOption(allowOptimizedSlaveReconstruction
Configurable generator for RootTreeWriter processor spec.
Processor spec for filtering krypton raw data.
Helper function to tokenize sequences and ranges of integral numbers.
DPL completion policy helper for TPC scetor data.
static void writeINI(std::string const &filename, std::string const &keyOnly="")
static void updateFromFile(std::string const &, std::string const &paramsList="", bool unchangedOnly=false)
static void updateFromString(std::string const &)
ConfigParamRegistry & options() const
Generate a processor spec for the RootTreeWriter utility.
static constexpr int MAXSECTOR
Definition Sector.h:44
GLuint index
Definition glcorearb.h:781
GLint ref
Definition glcorearb.h:291
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
WorkflowSpec parallelPipeline(const WorkflowSpec &specs, size_t nPipelines, std::function< size_t()> getNumberOfSubspecs, std::function< size_t(size_t)> getSubSpec)
Inputs mergeInputs(InputSpec original, size_t maxIndex, std::function< void(InputSpec &, size_t)> amendCallback)
std::vector< DataProcessorSpec > WorkflowSpec
Global TPC definitions and constants.
o2::framework::DataProcessorSpec getOccupancyFilterSpec()
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
static void updateMatchingSubspec(InputSpec &in, header::DataHeader::SubSpecificationType subSpec)
Marks an empty item in the context.
std::vector< InputSpec > gPolicyData
unsigned long gTpcSectorMask
const std::unordered_map< std::string, WriterType > WriterMap
WorkflowSpec defineDataProcessing(ConfigContext const &config)
This function hooks up the the workflow specifications into the DPL driver.
void customize(std::vector< o2::framework::CompletionPolicy > &policies)