Project
Loading...
Searching...
No Matches
CalibratordEdx.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
13#include <fmt/core.h>
14
15#include <array>
16#include <cstddef>
17#include <memory>
18#include <string_view>
19
20// o2 includes
23#include "Framework/Logger.h"
25
26using namespace o2::tpc;
27
29{
30 // Here we initialize the vector of our output objects
31 mTFIntervals.clear();
32 mTimeIntervals.clear();
33 mCalibs.clear();
34}
35
37{
38 LOGP(info, "Finalizing slot {} <= TF <= {}", slot.getTFStart(), slot.getTFEnd());
39 slot.print();
40
41 // compute calibration values from histograms
42 CalibdEdx* container = slot.getContainer();
43 container->finalize(mMakeGaussianFits);
44 container->finalizeDebugOutput();
45 mCalibs.push_back(container->getCalib());
46
47 TFType startTF = slot.getTFStart();
48 TFType endTF = slot.getTFEnd();
49 auto startTime = slot.getStartTimeMS();
50 auto endTime = slot.getEndTimeMS();
51
52 mTFIntervals.emplace_back(startTF, endTF);
53 mTimeIntervals.emplace_back(startTime, endTime);
54
55 if (mDebugOutputStreamer) {
56 LOGP(info, "Dumping time slot data to file");
57 auto calibCopy = container->getCalib();
58 *mDebugOutputStreamer << "CalibdEdx"
59 << "startTF=" << startTF // Initial time frame ID of time slot
60 << "endTF=" << endTF // Final time frame ID of time slot
61 << "startTime=" << startTime // Initial time frame time of time slot
62 << "endTime=" << endTime // Final time frame time of time slot
63 << "correction=" << calibCopy // dE/dx corretion
64 << "\n";
65 }
66
67 if (mDumpHistograms) {
68 const auto fileName = fmt::format("o2tpc_CalibratordEdx_Histos_{}_{}_{}_{}.root", startTime, endTime, startTF, endTF);
69 const auto dumpTHn = (mDumpHistograms & 0x1) == 0x1;
70 const auto dumpTree = (mDumpHistograms & 0x2) == 0x2;
71 if (dumpTree) {
72 container->writeTTree(fileName);
73 }
74 if (dumpTHn) {
75 auto f = std::make_unique<TFile>(fileName.data(), dumpTree ? "update" : "recreate");
76 auto hn = container->getRootHist();
77 hn->Write("calibHist");
78 f->Close();
79 }
80 }
81}
82
83CalibratordEdx::Slot& CalibratordEdx::emplaceNewSlot(bool front, TFType tstart, TFType tend)
84{
85 auto& cont = getSlots();
86 auto& slot = front ? cont.emplace_front(tstart, tend) : cont.emplace_back(tstart, tend);
87
88 auto container = std::make_unique<CalibdEdx>(mdEdxBins, mMindEdx, mMaxdEdx, mAngularBins, mFitSnp);
89 container->setApplyCuts(mApplyCuts);
90 container->setCuts(mCuts);
91 container->setSectorFitThreshold(mFitThreshold[0]);
92 container->set1DFitThreshold(mFitThreshold[1]);
93 container->set2DFitThreshold(mFitThreshold[2]);
94 const auto [cut, iterations, cutLowFactor] = mElectronCut;
95 container->setElectronCut(cut, iterations, cutLowFactor);
96 container->setMaterialType(mMatType);
97 if (mEnableTrackDebug) {
98 const auto fileName = fmt::format("o2tpc_CalibratordEdx_TrackDebug_{}_{}.root", tstart, tend);
99 container->enableDebugOutput(fileName);
100 }
101
102 slot.setContainer(std::move(container));
103 return slot;
104}
105
106void CalibratordEdx::enableDebugOutput(std::string_view fileName)
107{
108 mDebugOutputStreamer = std::make_unique<o2::utils::TreeStreamRedirector>(fileName.data(), "recreate");
109}
110
112{
113 // This will call the TreeStream destructor and write any stored data.
114 mDebugOutputStreamer.reset();
115}
116
118{
119 if (mDebugOutputStreamer) {
120 LOGP(info, "Closing dump file");
121 mDebugOutputStreamer->Close();
122 }
123}
This file provides the container used for time based residual dE/dx calibration.
This file provides the time dependent dE/dx calibrator, tracking the MIP position over time.
Utils and constants for calibration and related workflows.
TFType getTFEnd() const
Definition TimeSlot.h:47
long getStartTimeMS() const
Definition TimeSlot.h:50
long getEndTimeMS() const
Definition TimeSlot.h:51
const Container * getContainer() const
Definition TimeSlot.h:53
TFType getTFStart() const
Definition TimeSlot.h:46
Class that creates dE/dx histograms from a sequence of tracks objects.
Definition CalibdEdx.h:43
void finalize(const bool useGausFits=true)
THnF * getRootHist() const
Return calib data as a THn.
const CalibdEdxCorrection & getCalib() const
Definition CalibdEdx.h:137
void finalizeDebugOutput() const
Write debug output to file.
void writeTTree(std::string_view fileName) const
Save the histograms to a TTree.
void initOutput() final
Empty the output vectors.
void disableDebugOutput()
Disable debug output to file. Also writes and closes stored time slots.
void finalizeDebugOutput() const
Write debug output to file.
void finalizeSlot(Slot &) final
Process time slot data and compute its calibration.
Slot & emplaceNewSlot(bool front, TFType tstart, TFType tend) final
Creates new time slot.
void enableDebugOutput(std::string_view fileName)
Enable debug output to file of the time slots calibrations outputs and dE/dx histograms.
GLdouble f
Definition glcorearb.h:310
Global TPC definitions and constants.
Definition SimTraits.h:167