Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZDC TDC calibration #9403

Merged
merged 9 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Detectors/ZDC/base/include/ZDCBase/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ const std::string CCDBPathConfigSim = "ZDC/Config/Sim";
const std::string CCDBPathConfigModule = "ZDC/Config/Module";
const std::string CCDBPathRecoConfigZDC = "ZDC/Calib/RecoConfigZDC";
const std::string CCDBPathTDCCalib = "ZDC/Calib/TDCCalib";
const std::string CCDBPathTDCCalibConfig = "ZDC/Calib/TDCCalibConfig";
const std::string CCDBPathTDCCorr = "ZDC/Calib/TDCCorr";
const std::string CCDBPathEnergyCalib = "ZDC/Calib/EnergyCalib";
const std::string CCDBPathTowerCalib = "ZDC/Calib/TowerCalib";
Expand Down
18 changes: 18 additions & 0 deletions Detectors/ZDC/calib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ o2_add_library(ZDCCalib
src/InterCalibSpec.cxx
src/InterCalibEPN.cxx
src/InterCalibEPNSpec.cxx
src/TDCCalibConfig.cxx
src/TDCCalibEPN.cxx
src/TDCCalibEPNSpec.cxx
src/TDCCalibSpec.cxx
src/TDCCalibData.cxx
src/TDCCalib.cxx
src/WaveformCalibConfig.cxx
src/WaveformCalib.cxx
src/WaveformCalibSpec.cxx
Expand Down Expand Up @@ -54,6 +60,8 @@ o2_target_root_dictionary(ZDCCalib
include/ZDCCalib/BaselineCalibConfig.h
include/ZDCCalib/InterCalibData.h
include/ZDCCalib/InterCalibConfig.h
include/ZDCCalib/TDCCalibConfig.h
include/ZDCCalib/TDCCalibData.h
include/ZDCCalib/WaveformCalibConfig.h
include/ZDCCalib/WaveformCalibData.h
include/ZDCCalib/WaveformCalibParam.h
Expand Down Expand Up @@ -83,3 +91,13 @@ o2_add_executable(baselinecalib-workflow
COMPONENT_NAME zdc
SOURCES src/zdc-baselinecalib-workflow.cxx
PUBLIC_LINK_LIBRARIES O2::ZDCWorkflow O2::ZDCCalib O2::DetectorsCalibration)

o2_add_executable(tdccalib-epn-workflow
COMPONENT_NAME zdc
SOURCES src/zdc-tdccalib-epn-workflow.cxx
PUBLIC_LINK_LIBRARIES O2::ZDCWorkflow O2::ZDCCalib O2::DetectorsCalibration)

o2_add_executable(tdccalib-workflow
COMPONENT_NAME zdc
SOURCES src/zdc-tdccalib-workflow.cxx
PUBLIC_LINK_LIBRARIES O2::ZDCWorkflow O2::ZDCCalib O2::DetectorsCalibration)
43 changes: 32 additions & 11 deletions Detectors/ZDC/calib/include/ZDCCalib/TDCCalib.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,29 @@
#include <THnBase.h>
#include <THnSparse.h>
#include <TMinuit.h>
#include <TMath.h>
#include "ZDCBase/Constants.h"
#include "DataFormatsZDC/RecEvent.h"
#include "ZDCReconstruction/ZDCEnergyParam.h"
#include "ZDCCalib/InterCalibConfig.h"
#include "ZDCReconstruction/ZDCTDCParam.h"
#include "ZDCCalib/TDCCalibConfig.h"
#include "CCDB/CcdbObjectInfo.h" //added by me
#include "CommonDataFormat/FlatHisto1D.h"
#include "CommonDataFormat/FlatHisto2D.h"
#include "ZDCCalib/TDCCalibData.h"
#include "ZDCReconstruction/ZDCTowerParam.h"

#ifndef ALICEO2_ZDC_TDCCALIB_H_
#define ALICEO2_ZDC_TDCCALIB_H_
namespace o2
{
namespace zdc
{
class InterCalib

class TDCCalib //after
{

using CcdbObjectInfo = o2::ccdb::CcdbObjectInfo; //added by me

public:
TDCCalib() = default;
int init();
Expand All @@ -36,26 +47,36 @@ class InterCalib
const gsl::span<const o2::zdc::ZDCEnergy>& energy,
const gsl::span<const o2::zdc::ZDCTDCData>& tdc,
const gsl::span<const uint16_t>& info); // Calibration of RUN3 data
int process(const TDCCalibData& data); // Calibration of RUN3 data - aggregator node
int endOfRun(); // Perform minimization
int process(const char* hname, int ic); // Calibration of RUN2 data
void replay(int ih, THnSparse* hs, int ic); // Test of calibration using RUN2 data
int mini(int ih);
double extractShift(int ih);
void add(int ih, o2::dataformats::FlatHisto1D<float>& h1);
int write(const std::string fn = "ZDCTDCCalib.root");

static void fcn(int& npar, double* gin, double& chi, double* par, int iflag);
const ZDCTDCParam& getTDCParamUpd() const { return mTDCParamUpd; };
CcdbObjectInfo& getCcdbObjectInfo() { return mInfo; }

void setTDCParam(const ZDCTDCParam* param) { mTDCParam = param; };
const ZDCTDCParam* getTDCParam() const { return mTDCParam; };
void setTDCCalibConfig(const TDCCalibConfig* param) { mTDCCalibConfig = param; };
const TDCCalibConfig* getTDCCalibConfig() const { return mTDCCalibConfig; };

void setVerbosity(int v) { mVerbosity = v; }
int getVerbosity() const { return mVerbosity; }

private:
std::array<std::unique_ptr<TH1>, NTDCChannels> mHTDC{};
std::array<std::unique_ptr<TMinuit>, NTDCChannels> mMn{};
std::array<o2::dataformats::FlatHisto1D<float>*, NTDCChannels> mCTDC{}; //array of FlatHisto1D, number of elements = NTDCChannles (= 10), defined in constants.h {} means defined but not initialized
std::array<std::unique_ptr<TH1>, NTDCChannels> mHCTDC{}; //copy of flat histo 1D in TH1F to use root functions
bool mInitDone = false;
static std::mutex mMtx; /// mutex for critical section
bool mSaveDebugHistos = true;
const TDCCalibConfig* mTDCCalibConfig = nullptr; /// Configuration of TDC calibration, this line has been swapped with the following one to be consistent with intercalibration
const ZDCTDCParam* mTDCParam = nullptr; /// TDC calibration object
const TDCCalibConfig* mTDCCalibConfig = nullptr; /// Configuration of TDC calibration
int32_t mVerbosity = DbgMinimal;

TDCCalibData mData;
ZDCTDCParam mTDCParamUpd; /// Updated TDC calibration object, added by me
CcdbObjectInfo mInfo; /// CCDB Info, added by me
void assign(int ih, bool ismod); /// Assign updated calibration object, added by me
};
} // namespace zdc
} // namespace o2
Expand Down
46 changes: 34 additions & 12 deletions Detectors/ZDC/calib/include/ZDCCalib/TDCCalibConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,43 @@
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#ifndef O2_ZDC_INTERCALIBCONFIG_H
#ifndef O2_ZDC_TDCCALIBCONFIG_H
#define O2_ZDC_TDCCALIBCONFIG_H

#include "ZDCBase/Constants.h"
#include <Rtypes.h>
#include <array>
#include <string>
#include <limits>

/// \file TDCCalibConfig.h
/// \brief Configuration of ZDC TDC calibration procedure
/// \author P. Cortese
/// \author L. Quaglia

namespace o2
{
namespace zdc
{
struct TDCCalibConfig {
static constexpr int NTDCChannels = 10; //number of TDC channels
double cutLow[NTDCChannels] = {-std::numeric_limits<float>::infinity(), -std::numeric_limits<float>::infinity(), -std::numeric_limits<float>::infinity(), -std::numeric_limits<float>::infinity(), -std::numeric_limits<float>::infinity(),
-std::numeric_limits<float>::infinity(), -std::numeric_limits<float>::infinity(), -std::numeric_limits<float>::infinity(), -std::numeric_limits<float>::infinity(), -std::numeric_limits<float>::infinity()};
double cutHigh[NTDCChannels] = {std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(),
std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()};
int nb[NH] = {0}; /// Number of bins
double amin[NH] = {0}; /// minimum
double amax[NH] = {0}; /// maximum
double l_bnd[NH] = {0.1, 0.1, 0.1, 0.1, 0.1};
double u_bnd[NH] = {10., 10., 10., 10., 10.};
double l_bnd_o[NH] = {-20., -20., -20., -20., -20.};
double u_bnd_o[NH] = {20., 20., 20., 20., 20.};
double step_o[NH] = {0., 0., 0., 0., 0.};
double min_e[NH] = {0., 0., 0., 0., 0.};
bool enabled[NTDCChannels] = {true, true, true, true, true, true, true, true, true, true}; //ZNAC, ZNAS, ZPAC, ZPAS, ZEM1, ZEM2, ZNCC, ZNCS, ZPCC, ZPCS
int nb1[NTDCChannels] = {0}; /// 1D histogram: number of bins
double amin1[NTDCChannels] = {0}; /// minimum
double amax1[NTDCChannels] = {0}; /// maximum
int nb2[NTDCChannels] = {0}; /// 2D histogram: number of bins
double amin2[NTDCChannels] = {0}; /// minimum
double amax2[NTDCChannels] = {0}; /// maximum
double l_bnd[NTDCChannels] = {0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1};
double u_bnd[NTDCChannels] = {10., 10., 10., 10., 10., 10., 10., 10., 10., 10.};
double l_bnd_o[NTDCChannels] = {-20., -20., -20., -20., -20., -20., -20., -20., -20., -20.};
double u_bnd_o[NTDCChannels] = {20., 20., 20., 20., 20., 20., 20., 20., 20., 20.};
double step_o[NTDCChannels] = {0};
double min_e[NTDCChannels] = {0};
std::string desc = "";

void print() const;
void resetCuts();
Expand All @@ -58,7 +65,22 @@ struct TDCCalibConfig {
void setBinning2D(int nb, double amin, double amax);
void setBinning1D(int ih, int nb, double amin, double amax);
void setBinning2D(int ih, int nb, double amin, double amax);
ClassDefNV(TDCCalibConfig, 1);
void setDescription(std::string d) { desc = d; }
void enable(bool c0, bool c1, bool c2, bool c3, bool c4, bool c5, bool c6, bool c7, bool c8, bool c9)
{
enabled[0] = c0;
enabled[1] = c1;
enabled[2] = c2;
enabled[3] = c3;
enabled[4] = c4;
enabled[5] = c5;
enabled[6] = c6;
enabled[7] = c7;
enabled[8] = c8;
enabled[9] = c9;
}

ClassDefNV(TDCCalibConfig, 3);
};
} // namespace zdc
} // namespace o2
Expand Down
44 changes: 44 additions & 0 deletions Detectors/ZDC/calib/include/ZDCCalib/TDCCalibData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#ifndef _ZDC_TDCCALIB_DATA_H
#define _ZDC_TDCCALIB_DATA_H

#include "ZDCBase/Constants.h"
#include <array>
#include <Rtypes.h>

/// \file TDCCalibData.h
/// \brief TDC calibration intermediate data
/// \author luca.quaglia@cern.ch

namespace o2
{
namespace zdc
{

struct TDCCalibData {
static constexpr int NTDC = 10; /// ZNAC, ZNAS, ZPAC, ZPAS, ZEM1, ZEM2, ZNCC, ZNCS, ZPCC, ZPCS
uint64_t mCTimeBeg = 0; /// Time of processed time frame
uint64_t mCTimeEnd = 0; /// Time of processed time frame
static constexpr const char* CTDC[NTDC] = {"ZNAC", "ZNAS", "ZPAC", "ZPAS", "ZEM1", "ZEM2", "ZNCC", "ZNCS", "ZPCC", "ZPCS"};
int entries[NTDC] = {0};
TDCCalibData& operator+=(const TDCCalibData& other);
int getEntries(int ih) const;
void print() const;
void setCreationTime(uint64_t ctime);
ClassDefNV(TDCCalibData, 1);
};

} // namespace zdc
} // namespace o2

#endif
79 changes: 79 additions & 0 deletions Detectors/ZDC/calib/include/ZDCCalib/TDCCalibEPN.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#include <mutex>
#include <memory>
#include <TH1.h>
#include <TH2.h>
#include <THnBase.h>
#include <THnSparse.h>
#include <TMinuit.h>
#include "ZDCBase/Constants.h"
#include "CommonDataFormat/FlatHisto1D.h"
#include "CommonDataFormat/FlatHisto2D.h"
#include "DataFormatsZDC/RecEvent.h"
#include "ZDCReconstruction/ZDCEnergyParam.h"
#include "ZDCReconstruction/ZDCTowerParam.h"
#include "ZDCReconstruction/ZDCTDCParam.h" //added by me
#include "ZDCCalib/TDCCalibData.h"
#include "ZDCCalib/TDCCalibConfig.h"

#ifndef ALICEO2_ZDC_TDCCALIBEPN_H_
#define ALICEO2_ZDC_TDCCALIBEPN_H_
namespace o2
{
namespace zdc
{
class TDCCalibEPN
{
public:
TDCCalibEPN() = default;
int init();
static constexpr int HtdcZNAC = 0;
static constexpr int HtdcZNAS = 1;
static constexpr int HtdcZPAC = 2;
static constexpr int HtdcZPAS = 3;
static constexpr int HtdcZEM1 = 4;
static constexpr int HtdcZEM2 = 5;
static constexpr int HtdcZNCC = 6;
static constexpr int HtdcZNCS = 7;
static constexpr int HtdcZPCC = 8;
static constexpr int HtdcZPCS = 9;
static constexpr int NTDC = TDCCalibData::NTDC;
void clear(int ih = -1);
int process(const gsl::span<const o2::zdc::BCRecData>& bcrec,
const gsl::span<const o2::zdc::ZDCEnergy>& energy,
const gsl::span<const o2::zdc::ZDCTDCData>& tdc,
const gsl::span<const uint16_t>& info); // Calibration of RUN3 data
int endOfRun(); // End of TDCCalib
int write(const std::string fn = "ZDCTDCCalibEPN.root");

void fill1D(int iTDC, int nHits, o2::zdc::RecEventFlat ev); //function to fill histograms;

void setTDCCalibConfig(const TDCCalibConfig* param) { mTDCCalibConfig = param; };
const TDCCalibConfig* getTDCCalibConfig() const { return mTDCCalibConfig; };
void setSaveDebugHistos() { mSaveDebugHistos = true; }
void setDontSaveDebugHistos() { mSaveDebugHistos = false; }
void setVerbosity(int val) { mVerbosity = val; }
TDCCalibData mData;
TDCCalibData& getData() { return mData; }
std::array<o2::dataformats::FlatHisto1D<float>*, NTDC> mTDC{};

private:
bool mInitDone = false;
bool mSaveDebugHistos = true;
int32_t mVerbosity = DbgMinimal;
const TDCCalibConfig* mTDCCalibConfig = nullptr; /// Configuration of intercalibration
};
} // namespace zdc
} // namespace o2

#endif
58 changes: 58 additions & 0 deletions Detectors/ZDC/calib/include/ZDCCalib/TDCCalibEPNSpec.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

/// @file TDCCalibEPNSpec.h
/// @brief ZDC TDC calibration pre-processing on EPN
/// @author luca.quaglia@cern.ch

#ifndef O2_ZDC_TDCCALIBEPN_SPEC
#define O2_ZDC_TDCCALIBEPN_SPEC

#include <TStopwatch.h>
#include "Framework/Logger.h"
#include "Framework/DataProcessorSpec.h"
#include "Framework/Task.h"
#include "CommonUtils/NameConf.h"
#include "DataFormatsZDC/ZDCTDCData.h"
#include "ZDCCalib/TDCCalibData.h"
#include "ZDCCalib/TDCCalibEPN.h"
#include "ZDCCalib/TDCCalibConfig.h"

namespace o2
{
namespace zdc
{

class TDCCalibEPNSpec : public o2::framework::Task
{
public:
TDCCalibEPNSpec();
TDCCalibEPNSpec(const int verbosity);
~TDCCalibEPNSpec() override = default;
void init(o2::framework::InitContext& ic) final;
void updateTimeDependentParams(o2::framework::ProcessingContext& pc);
void finaliseCCDB(o2::framework::ConcreteDataMatcher& matcher, void* obj) final;
void run(o2::framework::ProcessingContext& pc) final;
void endOfStream(o2::framework::EndOfStreamContext& ec) final;

private:
int mVerbosity = DbgMinimal; // Verbosity level
bool mInitialized = false; // Connect once to CCDB during initialization
TDCCalibEPN mWorker; // TDC calibration object (was mTDCCalibEPN, modified after discussion with Pietro 20 June 2022)
TStopwatch mTimer;
};

framework::DataProcessorSpec getTDCCalibEPNSpec();

} // namespace zdc
} // namespace o2

#endif
Loading