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

fixes in TOF calibration workflow #7679

Merged
merged 2 commits into from
Nov 23, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CalibTimeSlewingParamTOF

CalibTimeSlewingParamTOF();

CalibTimeSlewingParamTOF(const CalibTimeSlewingParamTOF& source) = default;
CalibTimeSlewingParamTOF(const CalibTimeSlewingParamTOF& source);

CalibTimeSlewingParamTOF& operator=(const CalibTimeSlewingParamTOF& source) = default;

Expand Down Expand Up @@ -84,6 +84,7 @@ class CalibTimeSlewingParamTOF
}

CalibTimeSlewingParamTOF& operator+=(const CalibTimeSlewingParamTOF& other);
void bind();

private:
std::array<int, NCHANNELXSECTOR> mChannelStartSec0;
Expand Down
34 changes: 34 additions & 0 deletions DataFormats/Detectors/TOF/src/CalibTimeSlewingParamTOF.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,27 @@ float CalibTimeSlewingParamTOF::getChannelOffset(int channel) const
{
return evalTimeSlewing(channel, 0);
}
void CalibTimeSlewingParamTOF::bind()
{
mGlobalOffset[0] = &mGlobalOffsetSec0;
mGlobalOffset[1] = &mGlobalOffsetSec1;
mGlobalOffset[2] = &mGlobalOffsetSec2;
mGlobalOffset[3] = &mGlobalOffsetSec3;
mGlobalOffset[4] = &mGlobalOffsetSec4;
mGlobalOffset[5] = &mGlobalOffsetSec5;
mGlobalOffset[6] = &mGlobalOffsetSec6;
mGlobalOffset[7] = &mGlobalOffsetSec7;
mGlobalOffset[8] = &mGlobalOffsetSec8;
mGlobalOffset[9] = &mGlobalOffsetSec9;
mGlobalOffset[10] = &mGlobalOffsetSec10;
mGlobalOffset[11] = &mGlobalOffsetSec11;
mGlobalOffset[12] = &mGlobalOffsetSec12;
mGlobalOffset[13] = &mGlobalOffsetSec13;
mGlobalOffset[14] = &mGlobalOffsetSec14;
mGlobalOffset[15] = &mGlobalOffsetSec15;
mGlobalOffset[16] = &mGlobalOffsetSec16;
mGlobalOffset[17] = &mGlobalOffsetSec17;
}

//______________________________________________
float CalibTimeSlewingParamTOF::evalTimeSlewing(int channel, float totIn) const
Expand Down Expand Up @@ -164,7 +185,20 @@ CalibTimeSlewingParamTOF& CalibTimeSlewingParamTOF::operator+=(const CalibTimeSl
(*(mChannelStart[i])) = (*(other.mChannelStart[i]));
*(mFractionUnderPeak[i]) = *(other.mFractionUnderPeak[i]);
*(mSigmaPeak[i]) = *(other.mSigmaPeak[i]);
*(mGlobalOffset[i]) = *(other.mGlobalOffset[i]);
}
}
return *this;
}
//______________________________________________
CalibTimeSlewingParamTOF::CalibTimeSlewingParamTOF(const CalibTimeSlewingParamTOF& source)
{
bind();
for (int i = 0; i < NSECTORS; i++) {
*(mTimeSlewing[i]) = *(source.mTimeSlewing[i]);
(*(mChannelStart[i])) = (*(source.mChannelStart[i]));
*(mFractionUnderPeak[i]) = *(source.mFractionUnderPeak[i]);
*(mSigmaPeak[i]) = *(source.mSigmaPeak[i]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't you need to copy also mGlobalOffset?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. I probably missed it when copy and paste (and workflow didn't complain also in execution).

About #7610
I implemented an autodetection for fill scheme in case it is not provided.
It will be automatically skipped once the fill scheme will be filled with the information of collision context (at the moment I didn't know how to retrieve that info from there).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

*(mGlobalOffset[i]) = *(source.mGlobalOffset[i]);
}
}
13 changes: 9 additions & 4 deletions Detectors/GlobalTracking/src/MatchTOF.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ void MatchTOF::run(const o2::globaltracking::RecoContainer& inp)
mTimerMatchITSTPC.Reset();
mTimerTot.Reset();

mCalibInfoTOF.clear();

for (int i = 0; i < trkType::SIZEALL; i++) {
mMatchedTracks[i].clear();
mOutTOFLabels[i].clear();
Expand Down Expand Up @@ -1093,10 +1095,13 @@ void MatchTOF::selectBestMatches()
}

// add also calibration infos
mCalibInfoTOF.emplace_back(mTOFClusWork[matchingPair.getTOFClIndex()].getMainContributingChannel(),
int(mTOFClusWork[matchingPair.getTOFClIndex()].getTimeRaw() * 1E12), // add time stamp
mTOFClusWork[matchingPair.getTOFClIndex()].getTimeRaw() - intLT.getTOF(o2::track::PID::Pion) - t0info,
mTOFClusWork[matchingPair.getTOFClIndex()].getTot());
if (sourceID == o2::dataformats::GlobalTrackID::ITSTPC) {
mCalibInfoTOF.emplace_back(mTOFClusWork[matchingPair.getTOFClIndex()].getMainContributingChannel(),
int(mTOFClusWork[matchingPair.getTOFClIndex()].getTimeRaw() * 1E-12), // add time stamp
mTOFClusWork[matchingPair.getTOFClIndex()].getTimeRaw() - t0info - intLT.getTOF(o2::track::PID::Pion),
mTOFClusWork[matchingPair.getTOFClIndex()].getTot());
}

if (mMCTruthON) {
const auto& labelsTOF = mTOFClusLabels->getLabels(matchingPair.getTOFClIndex());
auto& labelTrack = mTracksLblWork[trkType][itrk];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "TOFBase/Geo.h"
#include "TOFBase/Utils.h"
#include "DataFormatsTOF/Cluster.h"
#include "TOFReconstruction/EventTimeMaker.h"
#include "TOFBase/EventTimeMaker.h"
//#include "GlobalTracking/MatchTOF.h"
#include "GlobalTrackingWorkflow/TOFEventTimeChecker.h"

Expand Down Expand Up @@ -84,7 +84,7 @@ using TimeSlewing = o2::dataformats::CalibTimeSlewingParamTOF;

bool MyFilter(const MyTrack& tr)
{
return (tr.mP < 2.0 && tr.mEta > o2::tof::Utils::mEtaMin && tr.mEta < o2::tof::Utils::mEtaMax && tr.mHasTOF);
return (tr.mP < 2.0 && tr.mEta > o2::tof::Utils::mEtaMin && tr.mEta < o2::tof::Utils::mEtaMax && tr.mHasTOF && tr.mSource == 1);
} // accept all

namespace o2
Expand Down
5 changes: 4 additions & 1 deletion Detectors/TOF/base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ o2_add_library(TOFBase
src/Strip.cxx
src/WindowFiller.cxx
src/Utils.cxx
src/CalibTOFapi.cxx
src/EventTimeMaker.cxx
PUBLIC_LINK_LIBRARIES Boost::serialization FairRoot::Base Microsoft.GSL::GSL
O2::DetectorsBase O2::CommonDataFormat O2::DetectorsRaw
O2::DataFormatsTOF)

o2_target_root_dictionary(TOFBase
HEADERS include/TOFBase/Geo.h include/TOFBase/Digit.h include/TOFBase/Utils.h
include/TOFBase/Strip.h include/TOFBase/WindowFiller.h)
include/TOFBase/Strip.h include/TOFBase/WindowFiller.h include/TOFBase/CalibTOFapi.h
include/TOFBase/EventTimeMaker.h)

o2_add_test(TOFIndex
SOURCES test/testTOFIndex.cxx
Expand Down
10 changes: 5 additions & 5 deletions Detectors/TOF/base/include/TOFBase/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ class Utils

static bool hasFillScheme();
static int getNinteractionBC();
static void addBC(float toftime);
static void addBC(double toftime) { addBC(float(toftime)); }
static void addInteractionBC(int bc) { mFillScheme.push_back(bc); }
static void addBC(float toftime, bool subLatency = false);
static void addBC(double toftime, bool subLatency = false) { addBC(float(toftime), subLatency); }
static void addInteractionBC(int bc, bool subLatency = false) { mFillScheme.push_back(bc); }
static int getInteractionBC(int ibc) { return mFillScheme[ibc]; }
static double subtractInteractionBC(double time);
static float subtractInteractionBC(float time);
static double subtractInteractionBC(double time, bool subLatency = false);
static float subtractInteractionBC(float time, bool subLatency = false);
static void init();
static void printFillScheme();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#include "TOFCalibration/CalibTOFapi.h"
#include "TOFBase/CalibTOFapi.h"
#include "FairLogger.h" // for LOG

using namespace o2::tof;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "TRandom.h"
#include "TMath.h"
#include "TOFReconstruction/EventTimeMaker.h"
#include "TOFBase/EventTimeMaker.h"

namespace o2
{
Expand Down
5 changes: 5 additions & 0 deletions Detectors/TOF/base/src/TOFBaseLinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,10 @@
#pragma link C++ class vector < o2::tof::ReadoutWindowData> + ;
#pragma link C++ class o2::tof::DigitHeader + ;
#pragma link C++ class vector < o2::tof::DigitHeader> + ;
#pragma link C++ class o2::tof::CalibTOFapi + ;
#pragma link C++ class o2::tof::eventTimeTrack + ;
#pragma link C++ class o2::tof::eventTimeTrackTest + ;
#pragma link C++ class vector < o2::tof::eventTimeTrack> + ;
#pragma link C++ class vector < o2::tof::eventTimeTrackTest> + ;
#pragma link C++ class vector < unsigned int> + ;
#endif
49 changes: 46 additions & 3 deletions Detectors/TOF/base/src/Utils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,21 @@ int Utils::getNinteractionBC()
return mFillScheme.size();
}

double Utils::subtractInteractionBC(double time)
double Utils::subtractInteractionBC(double time, bool subLatency)
{
static const int deltalat = o2::tof::Geo::BC_IN_ORBIT - o2::tof::Geo::LATENCYWINDOW_IN_BC;
int bc = int(time * o2::tof::Geo::BC_TIME_INPS_INV + 0.2);

if (subLatency) {
if (bc >= o2::tof::Geo::LATENCYWINDOW_IN_BC) {
bc -= o2::tof::Geo::LATENCYWINDOW_IN_BC;
time -= o2::tof::Geo::LATENCYWINDOW_IN_BC * o2::tof::Geo::BC_TIME_INPS;
} else {
bc += deltalat;
time += deltalat * o2::tof::Geo::BC_TIME_INPS;
}
}

int bcOrbit = bc % o2::constants::lhc::LHCMaxBunches;

int dbc = o2::constants::lhc::LHCMaxBunches, bcc = bc;
Expand All @@ -77,9 +89,21 @@ double Utils::subtractInteractionBC(double time)
return time;
}

float Utils::subtractInteractionBC(float time)
float Utils::subtractInteractionBC(float time, bool subLatency)
{
static const int deltalat = o2::tof::Geo::BC_IN_ORBIT - o2::tof::Geo::LATENCYWINDOW_IN_BC;
int bc = int(time * o2::tof::Geo::BC_TIME_INPS_INV + 0.2);

if (subLatency) {
if (bc >= o2::tof::Geo::LATENCYWINDOW_IN_BC) {
bc -= o2::tof::Geo::LATENCYWINDOW_IN_BC;
time -= o2::tof::Geo::LATENCYWINDOW_IN_BC * o2::tof::Geo::BC_TIME_INPS;
} else {
bc += deltalat;
time += deltalat * o2::tof::Geo::BC_TIME_INPS;
}
}

int bcOrbit = bc % o2::constants::lhc::LHCMaxBunches;

int dbc = o2::constants::lhc::LHCMaxBunches, bcc = bc;
Expand All @@ -88,13 +112,21 @@ float Utils::subtractInteractionBC(float time)
bcc = bc - bcOrbit + getInteractionBC(k);
dbc = abs(bcOrbit - getInteractionBC(k));
}
if (abs(bcOrbit - getInteractionBC(k) + o2::constants::lhc::LHCMaxBunches) < dbc) { // in case k is close to the right border (last BC of the orbit)
bcc = bc - bcOrbit + getInteractionBC(k) - o2::constants::lhc::LHCMaxBunches;
dbc = abs(bcOrbit - getInteractionBC(k) + o2::constants::lhc::LHCMaxBunches);
}
if (abs(bcOrbit - getInteractionBC(k) - o2::constants::lhc::LHCMaxBunches) < dbc) { // in case k is close to the left border (BC=0)
bcc = bc - bcOrbit + getInteractionBC(k) + o2::constants::lhc::LHCMaxBunches;
dbc = abs(bcOrbit - getInteractionBC(k) - o2::constants::lhc::LHCMaxBunches);
}
}
time -= o2::tof::Geo::BC_TIME_INPS * bcc;

return time;
}

void Utils::addBC(float toftime)
void Utils::addBC(float toftime, bool subLatency)
{
if (!mIsInit) {
init();
Expand All @@ -114,8 +146,19 @@ void Utils::addBC(float toftime)
}

// just fill
static const int deltalat = o2::tof::Geo::BC_IN_ORBIT - o2::tof::Geo::LATENCYWINDOW_IN_BC;
int bc = int(toftime * o2::tof::Geo::BC_TIME_INPS_INV + 0.2) % o2::constants::lhc::LHCMaxBunches;

if (subLatency) {
if (bc >= o2::tof::Geo::LATENCYWINDOW_IN_BC) {
bc -= o2::tof::Geo::LATENCYWINDOW_IN_BC;
toftime -= o2::tof::Geo::LATENCYWINDOW_IN_BC * o2::tof::Geo::BC_TIME_INPS;
} else {
bc += deltalat;
toftime += deltalat * o2::tof::Geo::BC_TIME_INPS;
}
}

mBCmult[bc]++;

if (mBCmult[bc] > mMaxBC) {
Expand Down
6 changes: 2 additions & 4 deletions Detectors/TOF/calibration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

o2_add_library(TOFCalibration
TARGETVARNAME targetName
SOURCES src/CalibTOFapi.cxx
src/CalibTOF.cxx
SOURCES src/CalibTOF.cxx
src/CollectCalibInfoTOF.cxx
src/LHCClockCalibrator.cxx
src/TOFChannelCalibrator.cxx
Expand All @@ -30,8 +29,7 @@ o2_add_library(TOFCalibration


o2_target_root_dictionary(TOFCalibration
HEADERS include/TOFCalibration/CalibTOFapi.h
include/TOFCalibration/CalibTOF.h
HEADERS include/TOFCalibration/CalibTOF.h
include/TOFCalibration/LHCClockCalibrator.h
include/TOFCalibration/TOFChannelCalibrator.h
include/TOFCalibration/TOFCalibCollector.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "TF1.h"
#include "TFile.h"
#include "TGraphErrors.h"
#include "TOFCalibration/CalibTOFapi.h"
#include "TOFBase/CalibTOFapi.h"

class TTree;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "DetectorsCalibration/TimeSlotCalibration.h"
#include "DetectorsCalibration/TimeSlot.h"
#include "DataFormatsTOF/CalibInfoTOF.h"
#include "TOFCalibration/CalibTOFapi.h"
#include "TOFBase/CalibTOFapi.h"
#include "DataFormatsTOF/CalibLHCphaseTOF.h"
#include "TOFBase/Geo.h"
#include "CCDB/CcdbObjectInfo.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "DataFormatsTOF/CalibLHCphaseTOF.h"
#include "TOFBase/Geo.h"
#include "CCDB/CcdbObjectInfo.h"
#include "TOFCalibration/CalibTOFapi.h"
#include "TOFBase/CalibTOFapi.h"

#include <array>
#include <boost/histogram.hpp>
Expand All @@ -37,6 +37,13 @@
#include "CCDB/CcdbApi.h"
#include <boost/format.hpp>

//#define DEBUGGING

#ifdef DEBUGGING
#include "TProfile.h"
#include "TH2F.h"
#endif

using o2::math_utils::fitGaus;

namespace o2
Expand All @@ -59,7 +66,11 @@ class TOFChannelData
LOG(INFO) << "Default c-tor, not to be used";
}

#ifndef DEBUGGING
TOFChannelData(int nb, float r, CalibTOFapi* cta, int nElsPerSector = o2::tof::Geo::NPADSXSECTOR, bool perstrip = false, bool safe = false) : mNBins(nb), mRange(r), mCalibTOFapi(cta), mNElsPerSector(nElsPerSector), mPerStrip(perstrip), mSafeMode(safe)
#else
TOFChannelData(int nb, float r, CalibTOFapi* cta, int nElsPerSector = o2::tof::Geo::NPADSXSECTOR, bool perstrip = false, bool safe = false, TH2F* h = nullptr) : mNBins(nb), mRange(r), mCalibTOFapi(cta), mNElsPerSector(nElsPerSector), mPerStrip(perstrip), mSafeMode(safe), mChannelDist(h)
#endif
{
if (r <= 0. || nb < 1) {
throw std::runtime_error("Wrong initialization of the histogram");
Expand Down Expand Up @@ -111,6 +122,10 @@ class TOFChannelData
std::array<boostHisto, 18> mHisto;
std::vector<int> mEntries; // vector containing number of entries per channel

#ifdef DEBUGGING
TH2F* mChannelDist;
#endif

CalibTOFapi* mCalibTOFapi = nullptr; // calibTOFapi to correct the t-text
int mNElsPerSector = o2::tof::Geo::NPADSXSECTOR;

Expand All @@ -131,6 +146,11 @@ class TOFChannelCalibrator final : public o2::calibration::TimeSlotCalibration<T
using CcdbObjectInfoVector = std::vector<CcdbObjectInfo>;
using TimeSlewingVector = std::vector<TimeSlewing>;

#ifdef DEBUGGING
TProfile* mFitCal; //("fitCal",";channel;offset (ps)",13104,0,157248);
TH2F* mChannelDist; //("channelDist",";channel; t - t_{exp}^{#pi} (ps)",13104,0,157248,1000,-100000,100000);
#endif

protected:
std::deque<o2::calibration::TimeSlot<o2::tof::TOFChannelData>>& getSlots() { return o2::calibration::TimeSlotCalibration<T, o2::tof::TOFChannelData>::getSlots(); }

Expand Down Expand Up @@ -166,6 +186,10 @@ class TOFChannelCalibrator final : public o2::calibration::TimeSlotCalibration<T
mLinFitters[i].SetDim(3);
mLinFitters[i].SetFormula("pol2");
}
#ifdef DEBUGGING
mFitCal = new TProfile("fitCal", ";channel;offset (ps)", 157248, 0, 157248);
mChannelDist = new TH2F("channelDist", ";channel; t - t_{exp}^{#pi} (ps)", 157248, 0, 157248, 1000, -100000, 100000);
#endif
}

~TOFChannelCalibrator() final = default;
Expand Down Expand Up @@ -202,7 +226,12 @@ class TOFChannelCalibrator final : public o2::calibration::TimeSlotCalibration<T
auto& cont = getSlots();
auto& slot = front ? cont.emplace_front(tstart, tend) : cont.emplace_back(tstart, tend);
int nElements = mCalibWithCosmics ? NCOMBINSTRIP * Geo::NSTRIPXSECTOR : Geo::NPADSXSECTOR; // if we calibrate with cosmics, we pass the number of possible combinations per sector; otherwise, the number of pads per sector
#ifndef DEBUGGING
slot.setContainer(std::make_unique<TOFChannelData>(mNBins, mRange, mCalibTOFapi, nElements, mPerStrip, mSafeMode));
#else
slot.setContainer(std::make_unique<TOFChannelData>(mNBins, mRange, mCalibTOFapi, nElements, mPerStrip, mSafeMode, mChannelDist));
#endif

return slot;
}

Expand Down
1 change: 0 additions & 1 deletion Detectors/TOF/calibration/src/TOFCalibrationLinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#pragma link off all classes;
#pragma link off all functions;

#pragma link C++ class o2::tof::CalibTOFapi + ;
#pragma link C++ class o2::globaltracking::CalibTOF + ;
#pragma link C++ class o2::globaltracking::CollectCalibInfoTOF + ;

Expand Down
Loading