Skip to content

Commit

Permalink
Fixes and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cortesep committed Sep 15, 2023
1 parent 286b637 commit d156876
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 39 deletions.
6 changes: 6 additions & 0 deletions Detectors/ZDC/calib/include/ZDCCalib/WaveformCalibData.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,18 @@ struct WaveformCalibData {
inline void setFirstValid(int isig, int ipos)
{
if (ipos > mWave[isig].mFirstValid) {
#ifdef O2_ZDC_WAVEFORMCALIB_DEBUG
printf("WaveformCalibChData::%s isig=%-2d mFirstValid %5d -> %5d\n", __func__, isig, mWave[isig].mFirstValid, ipos);
#endif
mWave[isig].mFirstValid = ipos;
}
}
inline void setLastValid(int isig, int ipos)
{
if (ipos < mWave[isig].mLastValid) {
#ifdef O2_ZDC_WAVEFORMCALIB_DEBUG
printf("WaveformCalibChData::%s isig=%-2d mLastValid %5d -> %5d\n", __func__, isig, mWave[isig].mLastValid, ipos);
#endif
mWave[isig].mLastValid = ipos;
}
}
Expand Down
5 changes: 3 additions & 2 deletions Detectors/ZDC/calib/include/ZDCCalib/WaveformCalibEPN.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class WaveformCalibEPN
public:
WaveformCalibEPN() = default;
int init();
void clear(int ih = -1);
void clear();
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,
Expand All @@ -54,7 +54,7 @@ class WaveformCalibEPN

int mFirst = 0;
int mLast = 0;
int mN = 1;
int mN = 10;

void configure(int ifirst, int ilast)
{
Expand All @@ -64,6 +64,7 @@ class WaveformCalibEPN
mFirst = ifirst;
mLast = ilast;
mN = ilast - ifirst + 1;
LOG(info) << "WaveformCalibEPN::" << __func__ << " mN=" << mN << "[" << mFirst << ":" << mLast << "]";
}

WaveformCalibQueue mQueue;
Expand Down
1 change: 1 addition & 0 deletions Detectors/ZDC/calib/include/ZDCCalib/WaveformCalibQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct WaveformCalibQueue {
int mNP = 0; // Number of interpolated points in waveform
int mTimeLow[NChannels]; /// Cut on position difference low
int mTimeHigh[NChannels]; /// Cut on position difference high
int mVerbosity = 0;

const WaveformCalibConfig* mCfg = nullptr;

Expand Down
8 changes: 4 additions & 4 deletions Detectors/ZDC/calib/src/WaveformCalibConfig.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ WaveformCalibConfig::WaveformCalibConfig()
cutHigh[isig] = std::numeric_limits<float>::infinity();
}
for (int itdc = 0; itdc < NTDCChannels; itdc++) {
cutTimeLow[itdc] = -2.5;
cutTimeHigh[itdc] = 2.5;
cutTimeLow[itdc] = -1.25;
cutTimeHigh[itdc] = 1.25;
}
}

Expand Down Expand Up @@ -132,8 +132,8 @@ void WaveformCalibConfig::setCuts(double low, double high)

void WaveformCalibConfig::setCuts(int isig, double low, double high)
{
cutHigh[isig] = low;
cutLow[isig] = high;
cutLow[isig] = low;
cutHigh[isig] = high;
}

void WaveformCalibConfig::setTimeCuts(double low, double high)
Expand Down
8 changes: 7 additions & 1 deletion Detectors/ZDC/calib/src/WaveformCalibData.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,15 @@ WaveformCalibChData& WaveformCalibChData::operator+=(const WaveformCalibChData&
{
if (other.mEntries > 0) {
if (other.mFirstValid > mFirstValid) {
#ifdef O2_ZDC_WAVEFORMCALIB_DEBUG
printf("WaveformCalibChData::+= mFirstValid %5d -> %5d\n", mFirstValid, other.mFirstValid);
#endif
mFirstValid = other.mFirstValid;
}
if (other.mLastValid < mLastValid) {
#ifdef O2_ZDC_WAVEFORMCALIB_DEBUG
printf("WaveformCalibChData::+= mLastValid %5d -> %5d\n", mLastValid, other.mLastValid);
#endif
mLastValid = other.mLastValid;
}
mEntries = mEntries + other.mEntries;
Expand Down Expand Up @@ -172,7 +178,7 @@ int WaveformCalibData::saveDebugHistos(const std::string fn)
}
h.SetEntries(mWave[is].mEntries);
h.Write("", TObject::kOverwrite);
}else{
} else {
LOG(warn) << "WaveformCalibData " << __func__ << " waveform for ch " << is << " has too few entries: " << mWave[is].mEntries;
}
}
Expand Down
19 changes: 16 additions & 3 deletions Detectors/ZDC/calib/src/WaveformCalibEPN.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,29 @@ int WaveformCalibEPN::init()
if (mVerbosity > DbgZero) {
mQueue.printConf();
}
mQueue.mVerbosity = mVerbosity;

// number of bins
mNBin = cfg->nbun * TSN;
mNBin = cfg->nbun * TSN * NTimeBinsPerBC;
mFirst = cfg->ibeg;
mLast = cfg->iend;
mData.setN(cfg->nbun);
mData.mPeak = mQueue.mPeak;
LOGF(info, "o2::zdc::WaveformCalibEPN::%s mNBin=%d mFirst=%d mLast=%d mN=%d mPeak=%d", __func__, mNBin, mFirst, mLast, cfg->nbun, mData.mPeak);
mInitDone = true;
return 0;
}

void WaveformCalibEPN::clear()
{
#ifdef O2_ZDC_WAVEFORMCALIB_DEBUG
LOG(info) << "o2::zdc::WaveformCalibEPN::" << __func__;
#endif
// mQueue.clear();
mData.clearWaveforms();
mData.setN(mN);
}

//______________________________________________________________________________
int WaveformCalibEPN::process(const gsl::span<const o2::zdc::BCRecData>& RecBC,
const gsl::span<const o2::zdc::ZDCEnergy>& Energy,
Expand Down Expand Up @@ -111,9 +123,10 @@ int WaveformCalibEPN::endOfRun()
LOGF(info, "WaveformCalibEPN::endOfRun ts (%llu:%llu)", mData.mCTimeBeg, mData.mCTimeEnd);
for (int is = 0; is < NChannels; is++) {
if (mData.getEntries(is) > 0) {
LOGF(info, "Waveform %2d %s with %10d events and cuts AMP:(%g:%g) TDC:(%g:%g) Valid:[%d:%d:%d]", is, ChannelNames[is].data(),
int itdc = SignalTDC[is];
LOGF(info, "Waveform %2d %s with %10d events and cuts AMP:(%g:%g) TDC:%d:(%g:%g) Valid:[%d:%d:%d]", is, ChannelNames[is].data(),
mData.getEntries(is), mConfig->cutLow[is], mConfig->cutHigh[is],
mConfig->cutTimeLow[is], mConfig->cutTimeHigh[is],
itdc, mConfig->cutTimeLow[itdc], mConfig->cutTimeHigh[itdc],
mData.getFirstValid(is), mData.mPeak, mData.getLastValid(is));
}
}
Expand Down
2 changes: 2 additions & 0 deletions Detectors/ZDC/calib/src/WaveformCalibEPNSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ void WaveformCalibEPNSpec::run(ProcessingContext& pc)
mTimer.Stop();
mTimer.Reset();
mTimer.Start(false);
} else {
mWorker.clear();
}

auto creationTime = pc.services().get<o2::framework::TimingInfo>().creation; // approximate time in ms
Expand Down
54 changes: 28 additions & 26 deletions Detectors/ZDC/calib/src/WaveformCalibQueue.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ uint32_t WaveformCalibQueue::append(RecEventFlat& ev)
}
return mask;
} else {
// #ifdef O2_ZDC_WAVEFORMCALIB_DEBUG
// LOG(info) << "WaveformCalibQueue::" << __func__ << " IR size = " << mIR.size() << " != " << mN;
// #endif
// #ifdef O2_ZDC_WAVEFORMCALIB_DEBUG
// LOG(info) << "WaveformCalibQueue::" << __func__ << " IR size = " << mIR.size() << " != " << mN;
// #endif
return 0;
}
}
Expand Down Expand Up @@ -191,7 +191,7 @@ int WaveformCalibQueue::hasData(int isig, const gsl::span<const o2::zdc::ZDCWave
} else {
int ipos = NTimeBinsPerBC * TSN * ipkb + ipk;
#ifdef O2_ZDC_WAVEFORMCALIB_DEBUG
LOG(info) << "WaveformCalibConfig::" << __func__ << " isig = " << isig << " ipkb " << ipkb << " ipk " << ipk << " min " << min;
LOG(info) << "WaveformCalibQueue::" << __func__ << " isig = " << isig << " ipkb " << ipkb << " ipk " << ipk << " min " << min;
#endif
return ipos;
}
Expand All @@ -208,9 +208,9 @@ int WaveformCalibQueue::addData(int isig, const gsl::span<const o2::zdc::ZDCWave
bool hasInfos = false;
for (int ib = 0; ib < mN; ib++) {
bool ifound = false;
// #ifdef O2_ZDC_WAVEFORMCALIB_DEBUG
// LOG(info) << "mNW[" << ib << "/" << mN << "] = " << mNW[ib] << " mFirstW = " << mFirstW[ib];
// #endif
// #ifdef O2_ZDC_WAVEFORMCALIB_DEBUG
// LOG(info) << "mNW[" << ib << "/" << mN << "] = " << mNW[ib] << " mFirstW = " << mFirstW[ib];
// #endif
if (mHasInfos[isig][ib] || mHasInfos[TDCSignal[SignalTDC[isig]]][ib]) {
#ifdef O2_ZDC_WAVEFORMCALIB_DEBUG
LOG(info) << "isig=" << isig << " ib=" << ib << " tdcid=" << SignalTDC[isig] << " tdc_sig=" << TDCSignal[SignalTDC[isig]] << " " << mHasInfos[isig][ib] << " " << mHasInfos[TDCSignal[SignalTDC[isig]]][ib];
Expand Down Expand Up @@ -247,7 +247,7 @@ int WaveformCalibQueue::addData(int isig, const gsl::span<const o2::zdc::ZDCWave
}
if (ipkb != mPk) {
#ifdef O2_ZDC_WAVEFORMCALIB_DEBUG
LOG(info) << "WaveformCalibConfig::" << __func__ << " isig = " << isig << " ipkb " << ipkb << " != mPk " << mPk << " SKIP";
LOG(info) << "WaveformCalibQueue::" << __func__ << " isig = " << isig << " ipkb " << ipkb << " != mPk " << mPk << " SKIP";
#endif
return -1;
} else {
Expand All @@ -261,8 +261,10 @@ int WaveformCalibQueue::addData(int isig, const gsl::span<const o2::zdc::ZDCWave
return -1;
}
if ((ppos - mPeak) < mTimeLow[itdc] || (ppos - mPeak) > mTimeHigh[itdc]) {
// Put a warning message for a signal out of time
LOGF(warning, "%d.%04d Signal %2d peak position %d-%d=%d is outside allowed range [%d:%d]", mIR[mPk].orbit, mIR[mPk].bc, isig, ppos, mPeak, ppos - mPeak, mTimeLow[isig], mTimeHigh[isig]);
if (mVerbosity > DbgMinimal) {
// Put a warning message for a signal out of time
LOGF(warning, "%d.%04d Signal %2d peak position %d-%d=%d is outside allowed range [%d:%d]", mIR[mPk].orbit, mIR[mPk].bc, isig, ppos, mPeak, ppos - mPeak, mTimeLow[isig], mTimeHigh[isig]);
}
return -1;
}
}
Expand All @@ -289,7 +291,7 @@ int WaveformCalibQueue::addData(int isig, const gsl::span<const o2::zdc::ZDCWave
// Restrict validity range because of signal jitter
data.setLastValid(isig, ipos);
#ifdef O2_ZDC_WAVEFORMCALIB_DEBUG
LOG(info) << "WaveformCalibConfig::" << __func__ << " isig = " << isig << " ipkb " << ipkb << " ipk " << ipk << " min " << min << " range=[" << data.getFirstValid(isig) << ":" << ppos << ":" << data.getLastValid(isig) << "]";
LOG(info) << "WaveformCalibQueue::" << __func__ << " isig = " << isig << " ipkb " << ipkb << " ipk " << ipk << " min " << min << " range=[" << data.getFirstValid(isig) << ":" << ppos << ":" << data.getLastValid(isig) << "]";
#endif
return ipos;
}
Expand All @@ -304,53 +306,53 @@ void WaveformCalibQueue::print()
bool printed = false;
for (int j = 0; j < NChannels; j++) {
if (mHasInfos[j][i] != 0) {
if(!printed){
if (!printed) {
printf("mHasInfos:");
printed=true;
printed = true;
}
printf(" %2d=%d", j, mHasInfos[j][i] != 0);
}
}
if(printed){
if (printed) {
printf("\n");
printed=false;
printed = false;
}
for (int j = 0; j < NTDCChannels; j++) {
if (mNTDC[j][i] > 0) {
if(!printed){
if (!printed) {
printf("mNTDC:");
printed=true;
printed = true;
}
printf(" %2d=%6u", j, mNTDC[j][i]);
}
}
if(printed){
if (printed) {
printf("\n");
printed=false;
printed = false;
}
for (int j = 0; j < NTDCChannels; j++) {
if (mNTDC[j][i] > 0) {
if(!printed){
if (!printed) {
printf("mTDCA:");
printed=true;
printed = true;
}
printf(" %2d=%6.1f", j, mTDCA[j][i]);
}
}
if(printed){
if (printed) {
printf("\n");
printed=false;
printed = false;
}
for (int j = 0; j < NTDCChannels; j++) {
if (mNTDC[j][i] > 0) {
if(!printed){
if (!printed) {
printf("mTDCP:");
printed=true;
printed = true;
}
printf(" %2d=%6.1f", j, mTDCP[j][i]);
}
}
if(printed){
if (printed) {
printf("\n");
}
}
Expand Down
20 changes: 18 additions & 2 deletions Detectors/ZDC/macro/CreateWaveformCalibConfig.C
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <string>
#include <map>
#include <TFile.h>
#include "Framework/Logger.h"
#include "CCDB/CcdbApi.h"
#include "ZDCBase/Constants.h"
Expand All @@ -38,14 +39,29 @@ void CreateWaveformCalibConfig(long tmin = 0, long tmax = -1, std::string ccdbHo
// range -2048 : 2047 one should not use signals too close to
// maximum allowed amplitude (1800+2048)
conf.setCuts(100, 3000);
conf.setCuts(o2::zdc::IdZPA1, 50, 3000);
conf.setCuts(o2::zdc::IdZNA1, 100, 2500);
conf.setCuts(o2::zdc::IdZNA2, 100, 2500);
conf.setCuts(o2::zdc::IdZNA3, 100, 2500);
conf.setCuts(o2::zdc::IdZNA4, 100, 2500);
conf.setCuts(o2::zdc::IdZPA1, 50, 2500);
conf.setCuts(o2::zdc::IdZPA2, 100, 2500);
conf.setCuts(o2::zdc::IdZPA3, 100, 2500);
conf.setCuts(o2::zdc::IdZPA4, 100, 2500);
conf.setCuts(o2::zdc::IdZNC1, 100, 2500);
conf.setCuts(o2::zdc::IdZNC2, 100, 2500);
conf.setCuts(o2::zdc::IdZNC3, 100, 2500);
conf.setCuts(o2::zdc::IdZNC4, 100, 2500);
conf.setCuts(o2::zdc::IdZPC1, 100, 2500);
conf.setCuts(o2::zdc::IdZPC2, 100, 2500);
conf.setCuts(o2::zdc::IdZPC3, 100, 2500);
conf.setCuts(o2::zdc::IdZPC4, 50, 2500);

conf.setDescription("Simulated data");
conf.setMinEntries(200);

// Restrict waveform range (default is -3, 6 as defined in WaveformCalib_NBB
// WaveformCalib_NBA in file Detectors/ZDC/base/include/ZDCBase/Constants.h)
conf.restrictRange(-1, 0);
// conf.restrictRange(-1, 0);

conf.print();

Expand Down
4 changes: 3 additions & 1 deletion Detectors/ZDC/workflow/src/DigitRecoSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ void DigitRecoSpec::run(ProcessingContext& pc)
}
// Limit the number of waveforms in output message
if (mMaxWave > 0 && ntw >= mMaxWave) {
LOG(warning) << "Maximum number of output waveforms per TF reached: " << mMaxWave;
if (mVerbosity > DbgMinimal) {
LOG(warning) << "Maximum number of output waveforms per TF reached: " << mMaxWave;
}
break;
}
}
Expand Down

0 comments on commit d156876

Please sign in to comment.