Skip to content

Commit

Permalink
ZDC - Tower intercalibration workflow (#8526)
Browse files Browse the repository at this point in the history
* ZDC tower and ZEM intercalibration

* Correct squashing mistake

* Fix test on CreateInterCalibConfig.C

* clang-format

* Fix test on CreateInterCalibConfig.C

* Fix build errors
  • Loading branch information
cortesep authored Apr 13, 2022
1 parent 4f46f5a commit cf205f6
Show file tree
Hide file tree
Showing 42 changed files with 2,516 additions and 70 deletions.
7 changes: 4 additions & 3 deletions DataFormats/Detectors/ZDC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
o2_add_library(DataFormatsZDC
SOURCES src/ChannelData.cxx src/BCData.cxx src/BCRecData.cxx src/RecEvent.cxx src/RecEventAux.cxx src/RawEventData.cxx
src/OrbitRawData.cxx src/OrbitRecData.cxx src/OrbitData.cxx src/ZDCTDCData.cxx src/ZDCEnergy.cxx
src/CTF.cxx src/RecEventFlat.cxx
PUBLIC_LINK_LIBRARIES O2::CommonConstants O2::CommonDataFormat
src/CTF.cxx src/RecEventFlat.cxx src/InterCalibData.cxx
PUBLIC_LINK_LIBRARIES O2::CommonConstants O2::CommonDataFormat O2::DetectorsCalibration
O2::ZDCBase ROOT::MathCore FairRoot::Base
O2::SimulationDataFormat
O2::MathUtils Microsoft.GSL::GSL)
Expand All @@ -25,4 +25,5 @@ o2_target_root_dictionary(DataFormatsZDC
include/DataFormatsZDC/RecEvent.h include/DataFormatsZDC/RecEventAux.h include/DataFormatsZDC/RecEventFlat.h
include/DataFormatsZDC/OrbitRawData.h include/DataFormatsZDC/ZDCTDCData.h
include/DataFormatsZDC/BCRecData.h include/DataFormatsZDC/ZDCEnergy.h
include/DataFormatsZDC/OrbitRecData.h include/DataFormatsZDC/RawEventData.h)
include/DataFormatsZDC/OrbitRecData.h include/DataFormatsZDC/RawEventData.h
include/DataFormatsZDC/InterCalibData.h)
45 changes: 45 additions & 0 deletions DataFormats/Detectors/ZDC/include/DataFormatsZDC/InterCalibData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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_INTERCALIB_DATA_H_
#define _ZDC_INTERCALIB_DATA_H_

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

/// \file InterCalibData.h
/// \brief Intercalibration intermediate data
/// \author [email protected]

namespace o2
{
namespace zdc
{

struct InterCalibData {
static constexpr int NPAR = 6; /// Dimension of matrix (1 + 4 coefficients + offset)
static constexpr int NH = 5; /// ZNA, ZPA, ZNC, ZPC, ZEM
double mSum[NH][NPAR][NPAR] = {0}; /// Cumulated sums
uint64_t mCTimeBeg = 0; /// Time of processed time frame
uint64_t mCTimeEnd = 0; /// Time of processed time frame
static constexpr const char* DN[NH] = {"ZNA", "ZPA", "ZNC", "ZPC", "ZEM"};
InterCalibData& operator+=(const InterCalibData& other);
int getEntries(int ih) const;
void print() const;
void setCreationTime(uint64_t ctime);
ClassDefNV(InterCalibData, 1);
};

} // namespace zdc
} // namespace o2

#endif
67 changes: 41 additions & 26 deletions DataFormats/Detectors/ZDC/include/DataFormatsZDC/RecEventFlat.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "ZDCBase/Constants.h"
#include "MathUtils/Cartesian.h"
#include <Rtypes.h>
#include <gsl/span>
#include <array>
#include <vector>
#include <map>
Expand All @@ -37,31 +38,32 @@ using NElem = int;

struct RecEventFlat { // NOLINT: false positive in clang-tidy !!
o2::InteractionRecord ir;
uint32_t channels = 0; /// pattern of channels acquired
uint32_t triggers = 0; /// pattern of channels with autotrigger bit
std::map<uint8_t, float> ezdc; /// signal in ZDCs
std::vector<float> TDCVal[NTDCChannels]; /// TDC values
std::vector<float> TDCAmp[NTDCChannels]; /// TDC signal amplitudes
std::vector<bool> TDCPile[NTDCChannels]; /// TDC pile-up correction flag (TODO)
std::vector<o2::zdc::BCRecData>* mRecBC; //! Interaction record and references to data
std::vector<o2::zdc::ZDCEnergy>* mEnergy; //! ZDC energy
std::vector<o2::zdc::ZDCTDCData>* mTDCData; //! ZDC TDC
std::vector<uint16_t>* mInfo; //! Event quality information
std::vector<uint16_t> mDecodedInfo; //! Event quality information (decoded)
uint64_t mEntry = 0; //! Current entry
uint64_t mNEntries = 0; //! Number of entries
FirstEntry mFirstE = 0; //! First energy
FirstEntry mFirstT = 0; //! First TDC
FirstEntry mFirstI = 0; //! First info
FirstEntry mStopE = 0; //! Last + 1 energy
FirstEntry mStopT = 0; //! Last + 1 TDC
FirstEntry mStopI = 0; //! Last + 1 info
NElem mNE = 0; //! N energy
NElem mNT = 0; //! N TDC
NElem mNI = 0; //! N info
std::array<bool, NChannels> isBeg{}; //! Beginning of sequence
std::array<bool, NChannels> isEnd{}; //! End of sequence
o2::zdc::BCRecData mCurB; //! Current BC
uint32_t channels = 0; /// pattern of channels acquired
uint32_t ezdcDecoded = 0; /// pattern of decoded energies
uint32_t triggers = 0; /// pattern of channels with autotrigger bit
std::map<uint8_t, float> ezdc; /// signal in ZDCs
std::vector<float> TDCVal[NTDCChannels]; /// TDC values
std::vector<float> TDCAmp[NTDCChannels]; /// TDC signal amplitudes
std::vector<bool> TDCPile[NTDCChannels]; /// TDC pile-up correction flag (TODO)
gsl::span<const o2::zdc::BCRecData> mRecBC; //! Interaction record and references to data
gsl::span<const o2::zdc::ZDCEnergy> mEnergy; //! ZDC energy
gsl::span<const o2::zdc::ZDCTDCData> mTDCData; //! ZDC TDC
gsl::span<const uint16_t> mInfo; //! Event quality information
std::vector<uint16_t> mDecodedInfo; //! Event quality information (decoded)
uint64_t mEntry = 0; //! Current entry
uint64_t mNEntries = 0; //! Number of entries
FirstEntry mFirstE = 0; //! First energy
FirstEntry mFirstT = 0; //! First TDC
FirstEntry mFirstI = 0; //! First info
FirstEntry mStopE = 0; //! Last + 1 energy
FirstEntry mStopT = 0; //! Last + 1 TDC
FirstEntry mStopI = 0; //! Last + 1 info
NElem mNE = 0; //! N energy
NElem mNT = 0; //! N TDC
NElem mNI = 0; //! N info
std::array<bool, NChannels> isBeg{}; //! Beginning of sequence
std::array<bool, NChannels> isEnd{}; //! End of sequence
o2::zdc::BCRecData mCurB; //! Current BC

// Reconstruction messages
std::array<bool, NChannels> genericE{}; /// 0 Generic error
Expand Down Expand Up @@ -93,7 +95,8 @@ struct RecEventFlat { // NOLINT: false positive in clang-tidy !!
uint8_t mVerbosity = DbgZero; //! Verbosity level
uint32_t mTriggerMask = 0; //! Trigger mask for printout

void init(std::vector<o2::zdc::BCRecData>* RecBC, std::vector<o2::zdc::ZDCEnergy>* Energy, std::vector<o2::zdc::ZDCTDCData>* TDCData, std::vector<uint16_t>* Info);
void init(const std::vector<o2::zdc::BCRecData>* RecBC, const std::vector<o2::zdc::ZDCEnergy>* Energy, const std::vector<o2::zdc::ZDCTDCData>* TDCData, const std::vector<uint16_t>* Info);
void init(const gsl::span<const o2::zdc::BCRecData> RecBC, const gsl::span<const o2::zdc::ZDCEnergy> Energy, const gsl::span<const o2::zdc::ZDCTDCData> TDCData, const gsl::span<const uint16_t> Info);

int next();

Expand All @@ -102,6 +105,18 @@ struct RecEventFlat { // NOLINT: false positive in clang-tidy !!
return mNE;
}

inline bool getEnergy(int32_t i, uint8_t& key, float& val) const
{
if (i < mNE) {
auto it = ezdc.begin();
std::advance(it, i);
key = it->first;
val = it->second;
return true;
}
return false;
}

inline NElem getNTDC() const
{
return mNT;
Expand Down
4 changes: 4 additions & 0 deletions DataFormats/Detectors/ZDC/include/DataFormatsZDC/ZDCTDCData.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct ZDCTDCData {
ZDCTDCData() = default;
ZDCTDCData(uint8_t ida, int16_t vala, int16_t ampa, bool isbeg = false, bool isend = false)
{
// TDC value and amplitude are encoded externally
id = ida & 0x0f;
id = id | (isbeg ? 0x80 : 0x00);
id = id | (isend ? 0x40 : 0x00);
Expand All @@ -45,6 +46,7 @@ struct ZDCTDCData {

ZDCTDCData(uint8_t ida, float vala, float ampa, bool isbeg = false, bool isend = false)
{
// TDC value and amplitude are encoded externally
id = ida & 0x0f;
id = id | (isbeg ? 0x80 : 0x00);
id = id | (isend ? 0x40 : 0x00);
Expand Down Expand Up @@ -75,10 +77,12 @@ struct ZDCTDCData {

inline float amplitude() const
{
// Return decoded value
return FTDCAmp * amp;
}
inline float value() const
{
// Return decoded value (ns)
return FTDCVal * val;
}
inline int ch() const
Expand Down
1 change: 1 addition & 0 deletions DataFormats/Detectors/ZDC/src/DataFormatsZDCLinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#pragma link C++ class o2::zdc::RecEventFlat + ;
#pragma link C++ class o2::zdc::ZDCEnergy + ;
#pragma link C++ class o2::zdc::ZDCTDCData + ;
#pragma link C++ class o2::zdc::InterCalibData + ;
#pragma link C++ class std::vector < o2::zdc::ChannelData> + ;
#pragma link C++ class std::vector < o2::zdc::BCData> + ;
#pragma link C++ class std::vector < o2::zdc::OrbitData> + ;
Expand Down
72 changes: 72 additions & 0 deletions DataFormats/Detectors/ZDC/src/InterCalibData.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 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 "Framework/Logger.h"
#include "DataFormatsZDC/InterCalibData.h"

using namespace o2::zdc;

void InterCalibData::print() const
{
for (int i = 0; i < NH; i++) {
LOGF(info, "%s", DN[i]);
for (int j = 0; j < NPAR; j++) {
for (int k = 0; k < NPAR; k++) {
if (k == 0) {
printf("%e", mSum[i][j][k]);
} else {
printf(" %e", mSum[i][j][k]);
}
}
printf("\n");
}
}
}

InterCalibData& InterCalibData::operator+=(const InterCalibData& other)
{
for (int32_t ih = 0; ih < NH; ih++) {
for (int32_t i = 0; i < NPAR; i++) {
for (int32_t j = 0; j < NPAR; j++) {
mSum[ih][i][j] += other.mSum[ih][i][j];
}
}
}
if (mCTimeBeg == 0 || other.mCTimeBeg < mCTimeBeg) {
mCTimeBeg = other.mCTimeBeg;
}
if (other.mCTimeEnd > mCTimeEnd) {
mCTimeEnd = other.mCTimeEnd;
}
//#ifdef O2_ZDC_DEBUG
LOGF(info, "InterCalibData [%llu : %llu]: %s=%d %s=%d %s=%d %s=%d %s=%d", mCTimeBeg, mCTimeEnd, DN[0], getEntries(0), DN[1], getEntries(1),
DN[2], getEntries(2), DN[3], getEntries(3), DN[4], getEntries(4));
//#endif
return *this;
}

void InterCalibData::setCreationTime(uint64_t ctime)
{
mCTimeBeg = ctime;
mCTimeEnd = ctime;
#ifdef O2_ZDC_DEBUG
LOGF(info, "InterCalibData::setCreationTime %llu", ctime);
#endif
}

int InterCalibData::getEntries(int ih) const
{
if (ih < 0 || ih >= NH) {
LOGF(error, "InterCalibData::getEntries ih = %d is out of range", ih);
return 0;
}
return mSum[ih][5][5];
}
24 changes: 18 additions & 6 deletions DataFormats/Detectors/ZDC/src/RecEventFlat.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,24 @@

using namespace o2::zdc;

void RecEventFlat::init(std::vector<o2::zdc::BCRecData>* RecBC, std::vector<o2::zdc::ZDCEnergy>* Energy, std::vector<o2::zdc::ZDCTDCData>* TDCData, std::vector<uint16_t>* Info)
void RecEventFlat::init(const std::vector<o2::zdc::BCRecData>* RecBC, const std::vector<o2::zdc::ZDCEnergy>* Energy, const std::vector<o2::zdc::ZDCTDCData>* TDCData, const std::vector<uint16_t>* Info)
{
mRecBC = *RecBC;
mEnergy = *Energy;
mTDCData = *TDCData;
mInfo = *Info;
mEntry = 0;
mNEntries = mRecBC.size();
}

void RecEventFlat::init(const gsl::span<const o2::zdc::BCRecData> RecBC, const gsl::span<const o2::zdc::ZDCEnergy> Energy, const gsl::span<const o2::zdc::ZDCTDCData> TDCData, const gsl::span<const uint16_t> Info)
{
mRecBC = RecBC;
mEnergy = Energy;
mTDCData = TDCData;
mInfo = Info;
mEntry = 0;
mNEntries = mRecBC->size();
mNEntries = mRecBC.size();
}

void RecEventFlat::clearBitmaps()
Expand Down Expand Up @@ -55,6 +65,7 @@ void RecEventFlat::clearBitmaps()

int RecEventFlat::next()
{
ezdcDecoded = 0;
if (mEntry >= mNEntries) {
return 0;
}
Expand All @@ -68,7 +79,7 @@ int RecEventFlat::next()
}

// Get References
mCurB = mRecBC->at(mEntry);
mCurB = mRecBC[mEntry];
mCurB.getRef(mFirstE, mNE, mFirstT, mNT, mFirstI, mNI);
mStopE = mFirstE + mNE;
mStopT = mFirstT + mNT;
Expand All @@ -84,7 +95,7 @@ int RecEventFlat::next()
uint16_t code = 0;
uint32_t map = 0;
for (int i = mFirstI; i < mStopI; i++) {
uint16_t info = mInfo->at(i);
uint16_t info = mInfo[i];
if (infoState == 0) {
if (info & 0x8000) {
LOGF(error, "Inconsistent info stream at word %d: 0x%4u", i, info);
Expand Down Expand Up @@ -122,18 +133,19 @@ int RecEventFlat::next()

// Decode energy
for (int i = mFirstE; i < mStopE; i++) {
auto myenergy = mEnergy->at(i);
auto myenergy = mEnergy[i];
auto ch = myenergy.ch();
ezdc[ch] = myenergy.energy();
// Assign implicit event info
if (adcPedOr[ch] == false && adcPedQC[ch] == false && adcPedMissing[ch] == false) {
adcPedEv[ch] = true;
}
ezdcDecoded |= (0x1 << ch);
}

// Decode TDCs
for (int i = mFirstT; i < mStopT; i++) {
auto mytdc = mTDCData->at(i);
auto mytdc = mTDCData[i];
auto ch = mytdc.ch();
if (ch < NTDCChannels) {
if (mytdc.isBeg()) {
Expand Down
3 changes: 2 additions & 1 deletion Detectors/ZDC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ add_subdirectory(simulation)
add_subdirectory(reconstruction)
add_subdirectory(macro)
add_subdirectory(raw)
add_subdirectory(workflow)
add_subdirectory(workflow)
add_subdirectory(calib)
16 changes: 14 additions & 2 deletions Detectors/ZDC/base/include/ZDCBase/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ constexpr int IdZPC3 = 23;
constexpr int IdZPC4 = 24;
constexpr int IdZPCSum = 25;

constexpr uint32_t MaskZNA = 0x0000001f;
constexpr uint32_t MaskAllZNA = 0x0000003f;
constexpr uint32_t MaskZPA = 0x000007c0;
constexpr uint32_t MaskAllZPA = 0x00000fc0;
constexpr uint32_t MaskZEM = 0x00003000;
constexpr uint32_t MaskZNC = 0x000fc000;
constexpr uint32_t MaskAllZNC = 0x0007f000;
constexpr uint32_t MaskZPC = 0x01f00000;
constexpr uint32_t MaskAllZPC = 0x03f00000;

constexpr std::string_view ChannelNames[] = {
"ZNAC",
"ZNA1",
Expand Down Expand Up @@ -229,6 +239,7 @@ const std::string CCDBPathTDCCalib = "ZDC/Calib/TDCCalib";
const std::string CCDBPathTDCCorr = "ZDC/Calib/TDCCorr";
const std::string CCDBPathEnergyCalib = "ZDC/Calib/EnergyCalib";
const std::string CCDBPathTowerCalib = "ZDC/Calib/TowerCalib";
const std::string CCDBPathInterCalibConfig = "ZDC/Calib/InterCalibConfig";

enum Ped { PedND = 0,
PedEv = 1,
Expand Down Expand Up @@ -287,10 +298,11 @@ constexpr std::array<int, 10> ChEnergyCalib{IdZNAC, IdZNASum, IdZPAC, IdZPASum,
IdZEM1, IdZEM2,
IdZNCC, IdZNCSum, IdZPCC, IdZPCSum};

constexpr std::array<int, 16> ChTowerCalib{IdZNA1, IdZNA2, IdZNA3, IdZNA4,
constexpr std::array<int, 17> ChTowerCalib{IdZNA1, IdZNA2, IdZNA3, IdZNA4,
IdZPA1, IdZPA2, IdZPA3, IdZPA4,
IdZNC1, IdZNC2, IdZNC3, IdZNC4,
IdZPC1, IdZPC2, IdZPC3, IdZPC4};
IdZPC1, IdZPC2, IdZPC3, IdZPC4,
IdZEM2};

constexpr std::array<int, NChannels> CaloCommonPM{IdZNAC, IdZNAC, IdZNAC, IdZNAC, IdZNAC, IdZNAC,
IdZPAC, IdZPAC, IdZPAC, IdZPAC, IdZPAC, IdZPAC,
Expand Down
Loading

0 comments on commit cf205f6

Please sign in to comment.