17#include <fmt/format.h>
18#include <fmt/printf.h>
40const std::vector<std::string> utils::tokenize(
const std::string_view input,
const std::string_view
pattern)
44 std::cregex_token_iterator
45 first{input.begin(), input.end(), re, -1},
50TH1* utils::getBinInfoXY(
int& binx,
int& biny,
float& bincx,
float& bincy)
52 TObject* select = gPad->GetSelected();
56 if (!select->InheritsFrom(
"TH2")) {
61 TH1*
h = (TH1*)select;
62 gPad->GetCanvas()->FeedbackMode(kTRUE);
64 const int px = gPad->GetEventX();
65 const int py = gPad->GetEventY();
66 const float xx = gPad->AbsPixeltoX(px);
67 const float x = gPad->PadtoX(xx);
68 const float yy = gPad->AbsPixeltoY(py);
69 const float y = gPad->PadtoX(yy);
70 binx =
h->GetXaxis()->FindBin(
x);
71 biny =
h->GetYaxis()->FindBin(
y);
72 bincx =
h->GetXaxis()->GetBinCenter(binx);
73 bincy =
h->GetYaxis()->GetBinCenter(biny);
78void utils::addFECInfo()
81 const int event = gPad->GetEvent();
88 TH1*
h = utils::getBinInfoXY(binx, biny, bincx, bincy);
93 const float binValue =
h->GetBinContent(binx, biny);
94 const int row = int(std::floor(bincx));
95 const int cpad = int(std::floor(bincy));
99 const int roc =
h->GetUniqueID();
103 if (row < 0 || row >= (
int)mapper.getNumberOfRowsROC(
roc)) {
106 const int nPads = mapper.getNumberOfPadsInRowROC(
roc,
row);
107 const int pad = cpad + nPads / 2;
108 if (pad < 0 || pad >= (
int)nPads) {
111 const int channel = mapper.getPadNumberInROC(
PadROCPos(
roc,
row, pad));
115 const int cruNumber = mapper.getCRU(
ROC(
roc).
getSector(), channel + padOffset);
116 const CRU cru(cruNumber);
119 const int fecOffset = (nFECs + 1) / 2;
121 const int dataWrapperID = fecInPartition >= fecOffset;
122 const int globalLinkID = (fecInPartition % fecOffset) + dataWrapperID * 12;
124 const std::string title = fmt::format(
125 "#splitline{{#lower[.1]{{#scale[.5]{{"
126 "{}{:02d} ({:02d}) row: {:02d}, pad: {:03d}, globalpad: {:05d} (in roc)"
127 "}}}}}}{{#scale[.5]{{FEC: "
128 "{:02d}, Chip: {:02d}, Chn: {:02d}, CRU: {:d}, Link: {:02d} ({}{:02d}), Value: {:.3f}"
130 (
roc / 18 % 2 == 0) ?
"A" :
"C",
roc % 18,
roc,
row, pad, channel, fecInfo.getIndex(), fecInfo.getSampaChip(),
131 fecInfo.getSampaChannel(), cruNumber %
CRU::CRUperSector, globalLinkID, dataWrapperID ?
"B" :
"A", globalLinkID % 12, binValue);
133 h->SetTitle(title.data());
136void utils::saveCanvases(TObjArray& arr, std::string_view outDir, std::string_view
types, std::string_view singleOutFileName, std::string nameAdd)
140 utils::saveCanvas(*
static_cast<TCanvas*
>(
c), outDir,
types, nameAdd);
144 if (singleOutFileName.size()) {
146 for (
const auto& outFileName : outFileNames) {
147 auto fileName = fmt::format(
"{}/{}", outDir, outFileName);
149 std::unique_ptr<TFile> outFile(TFile::Open(fileName.data(),
"recreate"));
150 arr.Write(arr.GetName(), TObject::kSingleKey);
153 const auto nCanv = arr.GetEntries();
154 for (
int i = 0;
i < nCanv; ++
i) {
155 auto fileName2 = fileName;
158 }
else if (
i == nCanv - 1) {
161 auto c =
static_cast<TCanvas*
>(arr.UncheckedAt(
i));
162 c->Print(fileName2.data(), fmt::format(
"Title:{}",
c->GetTitle()).data());
169void utils::saveCanvases(std::vector<TCanvas*>& canvases, std::string_view outDir, std::string_view
types, std::string_view singleOutFileName, std::string nameAdd)
172 for (
auto c : canvases) {
179void utils::saveCanvas(TCanvas&
c, std::string_view outDir, std::string_view
types, std::string nameAdd)
185 for (
const auto&
type : typesVec) {
186 c.SaveAs(fmt::format(
"{}/{}{}.{}", outDir,
c.GetName(), nameAdd,
type).data());
190std::vector<CalPad*> utils::readCalPads(
const std::string_view fileName,
const std::vector<std::string>& calPadNames)
192 using CalPadMapType = std::unordered_map<std::string, CalPad>;
194 std::vector<CalPad*> calPads(calPadNames.size());
196 std::unique_ptr<TFile>
file(TFile::Open(fileName.data()));
202 auto firstKey = (TKey*)
file->GetListOfKeys()->At(0);
203 const auto clMap = TClass::GetClass(
typeid(CalPadMapType));
204 if (std::string_view(firstKey->GetClassName()) == std::string_view(clMap->GetName())) {
205 auto calPadMap = firstKey->ReadObject<CalPadMapType>();
206 for (
size_t iCalPad = 0; iCalPad < calPadNames.size(); ++iCalPad) {
207 calPads[iCalPad] =
new CalPad(calPadMap->at(calPadNames[iCalPad]));
211 for (
size_t iCalPad = 0; iCalPad < calPadNames.size(); ++iCalPad) {
212 file->GetObject(calPadNames[iCalPad].
data(), calPads[iCalPad]);
219std::vector<CalPad*> utils::readCalPads(
const std::string_view fileName,
const std::string_view calPadNames)
221 auto calPadNamesVec =
tokenize(calPadNames,
",");
226void utils::mergeCalPads(std::string_view outputFileName, std::string_view inputFileNames, std::string_view calPadNames,
bool average)
230 const auto calPadNamesVec = utils::tokenize(calPadNames,
",");
232 std::string_view cmd =
"ls";
233 if (inputFileNames.rfind(
".root") == std::string_view::npos) {
236 auto files = gSystem->GetFromPipe(TString::Format(
"%s %s", cmd.data(), inputFileNames.data()));
237 std::unique_ptr<TObjArray> arrFiles(files.Tokenize(
"\n"));
239 std::vector<CalPad*> mergedCalPads;
241 for (
auto ofile : *arrFiles) {
242 auto calPads = utils::readCalPads(ofile->GetName(), calPadNamesVec);
243 if (!calPads.size()) {
246 if (!mergedCalPads.size()) {
247 mergedCalPads = calPads;
249 for (
size_t iCalPad = 0; iCalPad < calPads.size(); ++iCalPad) {
250 auto calPadName = calPadNamesVec[iCalPad];
251 auto calPadMerged = mergedCalPads[iCalPad];
252 calPadMerged->setName(calPadName);
253 auto calPadToMerge = calPads[iCalPad];
255 *calPadMerged += *calPadToMerge;
257 delete calPadToMerge;
263 const auto n = arrFiles->GetEntriesFast();
265 for (
auto calPad : mergedCalPads) {
271 std::unique_ptr<TFile> outFile(TFile::Open(outputFileName.data(),
"recreate"));
272 for (
auto calPad : mergedCalPads) {
273 outFile->WriteObject(calPad, calPad->getName().data());
278TChain* utils::buildChain(std::string_view command, std::string_view treeName, std::string_view treeTitle,
bool checkSubDir)
280 const TString files = gSystem->GetFromPipe(command.data());
281 std::unique_ptr<TObjArray> arrFiles(files.Tokenize(
"\n"));
282 if (!arrFiles->GetEntriesFast()) {
283 LOGP(
error,
"command '{}' did not return results", command);
287 auto c =
new TChain(treeName.data(), treeTitle.data());
288 for (
const auto o : *arrFiles) {
290 LOGP(fatal,
"could not open alien connection to read {}", o->GetName());
294 std::unique_ptr<TFile>
f(TFile::Open(o->GetName()));
295 if (!
f->IsOpen() ||
f->IsZombie()) {
298 for (
auto ok : *
f->GetListOfKeys()) {
299 auto k =
static_cast<TKey*
>(ok);
300 if (std::string_view(k->GetClassName()) !=
"TDirectoryFile") {
303 auto df =
f->Get<TDirectoryFile>(k->GetName());
304 if (df->GetListOfKeys() && df->GetListOfKeys()->FindObject(treeName.data())) {
305 const auto fullTreePath = fmt::format(
"{}/{}", df->GetName(), treeName);
306 c->AddFile(o->GetName(), TTree::kMaxEntries, fullTreePath.data());
307 LOGP(info,
"Adding file '{}', with tree {}", o->GetName(), fullTreePath);
311 LOGP(info,
"Adding file '{}'", o->GetName());
312 c->AddFile(o->GetName());
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 Show related Highlight grid Show only individual collision Color clusters belonging to track objects Set line Enable drawing TPC data Enable drawing TOF data Enable drawing magnetic field Set field line step count Invert colors configStandalone Heavy OpenGL display display_heavy Show tracks with ITS contribution Show tracks with TOF contribution Enable propagation of loopers Show clusters at nominal x of pad row for early transformed data Split CE tracks when they cross the central Mark clusters Mark adjacent clusters Hide rejected tracks Apply filter on tracks to be displayed Separate increase X h configStandalone Camera window renderer OpenGL display display_camera Orient the camera such that the y axis is always upwards Full Screen MultiSample Anti Downsampling Anti Enable Vertical Sync Target frame or if the backend cannot limit to the refresh Use OpenGL indirect draws to reduce number of draw calls Display h configStandalone Vulkan display display_vulkan Have uniform buffers in host accessible device memory h configStandalone Internal display display_internal Number of updates the Qt GUI may send ahead of the last one the display has before it waits for the display Opacity of the console background Number of console lines the history is shortened to this when it reaches twice the size Time in seconds an info message fades out after setInfoTime h OpenGL display display Font size Do not use Freetype for font Renderer for event Frontend to use for event ROOT macros used as track filter Console script file
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 average
char error[CURL_ERROR_SIZE]
Class for time synchronization of RawReader instances.
unsigned char partition() const
static Mapper & instance(const std::string mappingDir="")
static constexpr unsigned short getPadsInIROC()
Pad and row inside a ROC.
unsigned char getNumberOfFECs() const
unsigned char getSectorFECOffset() const
Sector getSector() const
get sector
GLsizei GLenum GLenum * types
GLint GLint GLsizei GLint GLenum GLenum type
const std::vector< std::string > tokenize(const std::string_view input, const std::string_view pattern)
std::vector< CalPad * > readCalPads(const std::string_view fileName, const std::vector< std::string > &calPadNames)
void saveCanvases(TObjArray &arr, std::string_view outDir, std::string_view types="png,pdf", std::string_view rootFileName="", std::string nameAdd="")
Global TPC definitions and constants.
static bool beginsWith(const std::string &s, const std::string &start)
static std::vector< std::string > tokenize(const std::string &src, char delim, bool trimToken=true, bool skipEmpty=true)
static bool endsWith(const std::string &s, const std::string &ending)
std::array< uint16_t, 5 > pattern