Skip to content

Commit

Permalink
add comparison with MC truth for TOF
Browse files Browse the repository at this point in the history
  • Loading branch information
noferini committed Jan 2, 2025
1 parent 7b6a2f2 commit d064539
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 23 deletions.
46 changes: 23 additions & 23 deletions Modules/PID/src/TaskFT0TOF.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -353,16 +353,17 @@ void TaskFT0TOF::monitorData(o2::framework::ProcessingContext& ctx)
mMyTracks.clear();

// Get FT0 RecPointss
// const gsl::span<o2::ft0::RecPoints>* ft0rec = nullptr;
const std::vector<o2::ft0::RecPoints>* ft0rec = nullptr;
std::vector<o2::ft0::RecPoints> ft0Sorted;
if (mUseFT0) {
auto& obj = ctx.inputs().get<const std::vector<o2::ft0::RecPoints>>("recpoints");
// const auto& obj = mRecoCont.getFT0RecPoints();
ft0rec = &obj;
for (const auto& o : obj) {
// ILOG(Info, Support) << "cand -> " << o.mIntRecord.orbit <<ENDM;
ft0Sorted.push_back(o);
}
}

if (mUseFT0) {
ILOG(Info, Support) << "FT0 rec points loaded, size = " << ft0rec->size() << ENDM;
ILOG(Info, Support) << "FT0 rec points loaded, size = " << ft0Sorted.size() << ENDM;
} else {
ILOG(Info, Support) << "FT0 rec points NOT available" << ENDM;
}
Expand Down Expand Up @@ -469,19 +470,15 @@ void TaskFT0TOF::monitorData(o2::framework::ProcessingContext& ctx)
} // END if track is ITS-TPC-TRD-TOF

std::vector<MyTrack> tracks;
std::vector<o2::ft0::RecPoints> ft0Sorted;

if (mUseFT0) {
ft0Sorted = *ft0rec;
}
std::vector<o2::ft0::RecPoints> ft0Cand;

// sorting matching in time
std::sort(mMyTracks.begin(), mMyTracks.end(),
[](MyTrack a, MyTrack b) { return a.tofSignalDouble() < b.tofSignalDouble(); });

std::sort(ft0Sorted.begin(), ft0Sorted.end(),
[](o2::ft0::RecPoints a, o2::ft0::RecPoints b) { return a.getInteractionRecord().bc2ns() < b.getInteractionRecord().bc2ns(); });
[](o2::ft0::RecPoints a, o2::ft0::RecPoints b) { return a.mIntRecord.bc2ns() < b.mIntRecord.bc2ns(); });

int ift0 = 0;

Expand Down Expand Up @@ -513,12 +510,15 @@ void TaskFT0TOF::monitorData(o2::framework::ProcessingContext& ctx)
double firstTime = tracks[0].tofSignalDouble() - 8 * o2::tof::Geo::BC_TIME_INPS;
double lastTime = tracks[ntrk - 1].tofSignalDouble() + 8 * o2::tof::Geo::BC_TIME_INPS;
for (int j = ift0; j < ft0Sorted.size(); j++) {
auto& obj = ft0Sorted[j];
if (obj.getInteractionRecord().orbit < ft0firstOrbit) {
const auto& obj = ft0Sorted[j];
if (obj.mIntRecord.orbit < ft0firstOrbit) {
ILOG(Info, Support) << "FT0 orbit comes first the first sampled one -> " << obj.mIntRecord.orbit << " - " << ft0firstOrbit << ENDM;
continue; // skip FT0 objects from previous orbits
}
uint32_t orbit = obj.getInteractionRecord().orbit - ft0firstOrbit;
double BCtimeFT0 = ((orbit)*o2::constants::lhc::LHCMaxBunches + obj.getInteractionRecord().bc) * o2::tof::Geo::BC_TIME_INPS;
uint32_t orbit = obj.mIntRecord.orbit - ft0firstOrbit;
double BCtimeFT0 = ((orbit)*o2::constants::lhc::LHCMaxBunches + obj.mIntRecord.bc) * o2::tof::Geo::BC_TIME_INPS;

// ILOG(Info, Support) << "orbit " << orbit << "-> time (ps) " << BCtimeFT0 <<ENDM;

if (BCtimeFT0 < firstTime) {
ift0 = j + 1;
Expand All @@ -528,12 +528,12 @@ void TaskFT0TOF::monitorData(o2::framework::ProcessingContext& ctx)
break;
}
// ILOG(Info, Support) << " TOF first=" << firstTime << " < " << BCtimeFT0 << " < TOF last=" << lastTime << ENDM;
// ILOG(Info, Support) << " orbit=" << obj.getInteractionRecord().orbit << " " << obj.getInteractionRecord().orbit - ft0firstOrbit << " BC=" << obj.getInteractionRecord().bc << ENDM;
// ILOG(Info, Support) << " orbit=" << obj.mIntRecord.orbit << " " << obj.mIntRecord.orbit - ft0firstOrbit << " BC=" << obj.mIntRecord.bc << ENDM;

std::array<short, 4> collTimes = { obj.getCollisionTime(0), obj.getCollisionTime(1), obj.getCollisionTime(2), obj.getCollisionTime(3) };

int pos = ft0Cand.size();
ft0Cand.emplace_back(collTimes, 0, 0, o2::InteractionRecord{ obj.getInteractionRecord().bc, orbit }, obj.getTrigger());
ft0Cand.emplace_back(collTimes, 0, 0, o2::InteractionRecord{ obj.mIntRecord.bc, orbit }, obj.getTrigger());
}
}

Expand All @@ -557,14 +557,14 @@ void TaskFT0TOF::monitorData(o2::framework::ProcessingContext& ctx)
if (!ft0.isValidTime(0)) {
continue; // skip invalid FT0AC times
}
if (ft0firstOrbit > ft0.getInteractionRecord().orbit) {
if (ft0firstOrbit > ft0.mIntRecord.orbit) {
continue; // skip FT0 objects from previous orbits
}
if (abs(ft0.getCollisionTime(0)) > 1000) {
continue; // skip bad FT0 time (not from collisions)
}

double ft0time = ((ft0.getInteractionRecord().orbit - ft0firstOrbit) * o2::constants::lhc::LHCMaxBunches + ft0.getInteractionRecord().bc) * o2::tof::Geo::BC_TIME_INPS + ft0.getCollisionTime(0);
double ft0time = ((ft0.mIntRecord.orbit - ft0firstOrbit) * o2::constants::lhc::LHCMaxBunches + ft0.mIntRecord.bc) * o2::tof::Geo::BC_TIME_INPS + ft0.getCollisionTime(0);
double timemax = ft0time + 100E3;
double timemin = ft0time - 30E3;

Expand Down Expand Up @@ -679,11 +679,11 @@ void TaskFT0TOF::processEvent(const std::vector<MyTrack>& tracks, const std::vec
mHistDeltaEvTimeTOFVsFT0C->Fill(times[0] - times[3]);

// if same BC
if (nBC % o2::constants::lhc::LHCMaxBunches == obj.getInteractionRecord().bc) {
if (nBC % o2::constants::lhc::LHCMaxBunches == obj.mIntRecord.bc) {
// no need for condition on orbit we select FT0 candidates within 8 BCs
FT0evTimes[0] = obj.getInteractionRecord().bc2ns() * 1E3 + times[1];
FT0evTimes[1] = obj.getInteractionRecord().bc2ns() * 1E3 + times[2];
FT0evTimes[2] = obj.getInteractionRecord().bc2ns() * 1E3 + times[3];
FT0evTimes[0] = obj.mIntRecord.bc2ns() * 1E3 + times[1];
FT0evTimes[1] = obj.mIntRecord.bc2ns() * 1E3 + times[2];
FT0evTimes[2] = obj.mIntRecord.bc2ns() * 1E3 + times[3];
mHistEvTimeTOFVsFT0ACSameBC->Fill(times[0], times[1]);
mHistEvTimeTOFVsFT0ASameBC->Fill(times[0], times[2]);
mHistEvTimeTOFVsFT0CSameBC->Fill(times[0], times[3]);
Expand All @@ -692,7 +692,7 @@ void TaskFT0TOF::processEvent(const std::vector<MyTrack>& tracks, const std::vec
mHistDeltaEvTimeTOFVsFT0CSameBC->Fill(times[0] - times[3]);
}

mHistDeltaBCTOFFT0->Fill(nBC % o2::constants::lhc::LHCMaxBunches - obj.getInteractionRecord().bc);
mHistDeltaBCTOFFT0->Fill(nBC % o2::constants::lhc::LHCMaxBunches - obj.mIntRecord.bc);
}
}

Expand Down
4 changes: 4 additions & 0 deletions Modules/TOF/include/TOF/TOFMatchedTracks.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ class TOFMatchedTracks final : public TaskInterface
TH2F* mDTimeTrk[18] = {};
TH2F* mDTimeTrkTPC[18] = {};
TH2F* mDTimeTrkTRD[18] = {};
TH1F* mDeltaTwMC;
TH2F* mExpTimesPiMC[matchType::SIZE] = {};
TH2F* mExpTimesKaMC[matchType::SIZE] = {};
TH2F* mExpTimesPrMC[matchType::SIZE] = {};

TEfficiency* mEffPt[matchType::SIZE] = {};
TEfficiency* mEffEta[matchType::SIZE] = {};
Expand Down
55 changes: 55 additions & 0 deletions Modules/TOF/src/TOFMatchedTracks.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,20 @@ namespace o2::quality_control_modules::tof

TOFMatchedTracks::~TOFMatchedTracks()
{
if (mUseMC) {
delete mDeltaTwMC;
}

for (int i = 0; i < matchType::SIZE; ++i) {
delete mMatchedTracksPt[i];
delete mMatchedTracksEta[i];
delete mMatchedTracks2DPtEta[i];
if (mUseMC) {
delete mFakeMatchedTracksPt[i];
delete mFakeMatchedTracksEta[i];
delete mExpTimesPiMC[i];
delete mExpTimesKaMC[i];
delete mExpTimesPrMC[i];
}
delete mInTracksPt[i];
delete mInTracksEta[i];
Expand Down Expand Up @@ -142,6 +149,11 @@ void TOFMatchedTracks::initialize(o2::framework::InitContext& /*ctx*/)
}

std::array<std::string, 3> title{ "TPC", "ITSTPC-ITSTPCTRD", "TPCTRD" };

if (mUseMC) {
mDeltaTwMC = new TH1F("mDeltaTwMC", "all types;t_{TOF} - t^{0}_{MC} - t_{geant} (ps)", 100, -500, 500);
}

for (int i = 0; i < matchType::SIZE; ++i) {
mInTracksPt[i] = new TH1F(Form("mInTracksPt_%s", title[i].c_str()), Form("mInTracksPt (matchType: %s); #it{p}_{T}; counts", title[i].c_str()), 100, 0.f, 20.f);
mInTracksEta[i] = new TH1F(Form("mInTracksEta_%s", title[i].c_str()), Form("mInTracksEta (matchType: %s); #eta; counts", title[i].c_str()), 100, -1.0f, 1.0f);
Expand All @@ -154,6 +166,9 @@ void TOFMatchedTracks::initialize(o2::framework::InitContext& /*ctx*/)
mFakeMatchedTracksEta[i] = new TH1F(Form("mFakeMatchedTracksEta_%s", title[i].c_str()), Form("mFakeMatchedTracksEta (matchType: %s); #eta; counts", title[i].c_str()), 100, -1.0f, 1.0f);
mFakeFractionTracksPt[i] = new TEfficiency(Form("mFakeFractionPt_%s", title[i].c_str()), Form("Fraction of fake matches vs Pt (matchType: %s); #it{p}_{T}; Eff", title[i].c_str()), 100, 0.f, 20.f);
mFakeFractionTracksEta[i] = new TEfficiency(Form("mFakeFractionEta_%s", title[i].c_str()), Form("Fraction of fake matches vs Eta (matchType: %s); #eta; Eff", title[i].c_str()), 100, -1.0f, 1.0f);
mExpTimesPiMC[i] = new TH2F(Form("mExpTimesPiMC_%s", title[i].c_str()), ";p_{T} (GeV/c);t_{geant} - t_{exp}^{#pi} (ps)", 10, 0, 2, 100, -1000, 1000);
mExpTimesKaMC[i] = new TH2F(Form("mExpTimesKaMC_%s", title[i].c_str()), ";p_{T} (GeV/c);t_{geant} - t_{exp}^{K} (ps)", 10, 0, 2, 100, -1000, 1000);
mExpTimesPrMC[i] = new TH2F(Form("mExpTimesPrMC_%s", title[i].c_str()), ";p_{T} (GeV/c);t_{geant} - t_{exp}^{p} (ps)", 10, 0, 2, 100, -1000, 1000);
}
mEffPt[i] = new TEfficiency(Form("mEffPt_%s", title[i].c_str()), Form("Efficiency vs Pt (matchType: %s); #it{p}_{T}; Eff", title[i].c_str()), 100, 0.f, 20.f);
mEffEta[i] = new TEfficiency(Form("mEffEta_%s", title[i].c_str()), Form("Efficiency vs Eta (matchType: %s); #eta; Eff", title[i].c_str()), 100, -1.f, 1.f);
Expand Down Expand Up @@ -181,6 +196,10 @@ void TOFMatchedTracks::initialize(o2::framework::InitContext& /*ctx*/)
}
}

if (mUseMC) {
getObjectsManager()->startPublishing(mDeltaTwMC);
}

if (mSrc[GID::Source::TPCTOF] == 1) {
getObjectsManager()->startPublishing(mInTracksPt[matchType::TPC]);
getObjectsManager()->startPublishing(mInTracksEta[matchType::TPC]);
Expand All @@ -193,6 +212,9 @@ void TOFMatchedTracks::initialize(o2::framework::InitContext& /*ctx*/)
getObjectsManager()->startPublishing(mFakeMatchedTracksEta[matchType::TPC]);
getObjectsManager()->startPublishing(mFakeFractionTracksPt[matchType::TPC]);
getObjectsManager()->startPublishing(mFakeFractionTracksEta[matchType::TPC]);
getObjectsManager()->startPublishing(mExpTimesPiMC[matchType::TPC]);
getObjectsManager()->startPublishing(mExpTimesKaMC[matchType::TPC]);
getObjectsManager()->startPublishing(mExpTimesPrMC[matchType::TPC]);
}
getObjectsManager()->startPublishing(mEffPt[matchType::TPC]);
getObjectsManager()->startPublishing(mEffEta[matchType::TPC]);
Expand All @@ -219,6 +241,9 @@ void TOFMatchedTracks::initialize(o2::framework::InitContext& /*ctx*/)
getObjectsManager()->startPublishing(mFakeMatchedTracksEta[matchType::TPCTRD]);
getObjectsManager()->startPublishing(mFakeFractionTracksPt[matchType::TPCTRD]);
getObjectsManager()->startPublishing(mFakeFractionTracksEta[matchType::TPCTRD]);
getObjectsManager()->startPublishing(mExpTimesPiMC[matchType::TPCTRD]);
getObjectsManager()->startPublishing(mExpTimesKaMC[matchType::TPCTRD]);
getObjectsManager()->startPublishing(mExpTimesPrMC[matchType::TPCTRD]);
}
getObjectsManager()->startPublishing(mEffPt[matchType::TPCTRD]);
getObjectsManager()->startPublishing(mEffEta[matchType::TPCTRD]);
Expand All @@ -245,6 +270,9 @@ void TOFMatchedTracks::initialize(o2::framework::InitContext& /*ctx*/)
getObjectsManager()->startPublishing(mFakeMatchedTracksEta[matchType::ITSTPC_ITSTPCTRD]);
getObjectsManager()->startPublishing(mFakeFractionTracksPt[matchType::ITSTPC_ITSTPCTRD]);
getObjectsManager()->startPublishing(mFakeFractionTracksEta[matchType::ITSTPC_ITSTPCTRD]);
getObjectsManager()->startPublishing(mExpTimesPiMC[matchType::ITSTPC_ITSTPCTRD]);
getObjectsManager()->startPublishing(mExpTimesKaMC[matchType::ITSTPC_ITSTPCTRD]);
getObjectsManager()->startPublishing(mExpTimesPrMC[matchType::ITSTPC_ITSTPCTRD]);
}
getObjectsManager()->startPublishing(mEffPt[matchType::ITSTPC_ITSTPCTRD]);
getObjectsManager()->startPublishing(mEffEta[matchType::ITSTPC_ITSTPCTRD]);
Expand Down Expand Up @@ -356,6 +384,11 @@ void TOFMatchedTracks::monitorData(o2::framework::ProcessingContext& ctx)
if (lbl.isFake()) {
mFakeMatchedTracksPt[matchType::TPC]->Fill(trk.getPt());
mFakeMatchedTracksEta[matchType::TPC]->Fill(trk.getEta());
} else {
mDeltaTwMC->Fill(matchTOF.getSignal() - matchTOF.getT0true() - matchTOF.getTgeant() * 1E3);
mExpTimesPiMC[matchType::TPC]->Fill(trk.getPt(), matchTOF.getTgeant() * 1E3 - matchTOF.getLTIntegralOut().getTOF(2));
mExpTimesKaMC[matchType::TPC]->Fill(trk.getPt(), matchTOF.getTgeant() * 1E3 - matchTOF.getLTIntegralOut().getTOF(3));
mExpTimesPrMC[matchType::TPC]->Fill(trk.getPt(), matchTOF.getTgeant() * 1E3 - matchTOF.getLTIntegralOut().getTOF(4));
}
}
}
Expand Down Expand Up @@ -418,6 +451,11 @@ void TOFMatchedTracks::monitorData(o2::framework::ProcessingContext& ctx)
if (lbl.isFake()) {
mFakeMatchedTracksPt[matchType::ITSTPC_ITSTPCTRD]->Fill(trkTPC.getPt());
mFakeMatchedTracksEta[matchType::ITSTPC_ITSTPCTRD]->Fill(trkTPC.getEta());
} else {
mDeltaTwMC->Fill(matchTOF.getSignal() - matchTOF.getT0true() - matchTOF.getTgeant() * 1E3);
mExpTimesPiMC[matchType::ITSTPC_ITSTPCTRD]->Fill(trkTPC.getPt(), matchTOF.getTgeant() * 1E3 - matchTOF.getLTIntegralOut().getTOF(2));
mExpTimesKaMC[matchType::ITSTPC_ITSTPCTRD]->Fill(trkTPC.getPt(), matchTOF.getTgeant() * 1E3 - matchTOF.getLTIntegralOut().getTOF(3));
mExpTimesPrMC[matchType::ITSTPC_ITSTPCTRD]->Fill(trkTPC.getPt(), matchTOF.getTgeant() * 1E3 - matchTOF.getLTIntegralOut().getTOF(4));
}
}
}
Expand Down Expand Up @@ -458,6 +496,11 @@ void TOFMatchedTracks::monitorData(o2::framework::ProcessingContext& ctx)
if (lbl.isFake()) {
mFakeMatchedTracksPt[matchType::TPCTRD]->Fill(trk.getPt());
mFakeMatchedTracksEta[matchType::TPCTRD]->Fill(trk.getEta());
} else {
mDeltaTwMC->Fill(matchTOF.getSignal() - matchTOF.getT0true() - matchTOF.getTgeant() * 1E3);
mExpTimesPiMC[matchType::TPCTRD]->Fill(trk.getPt(), matchTOF.getTgeant() * 1E3 - matchTOF.getLTIntegralOut().getTOF(2));
mExpTimesKaMC[matchType::TPCTRD]->Fill(trk.getPt(), matchTOF.getTgeant() * 1E3 - matchTOF.getLTIntegralOut().getTOF(3));
mExpTimesPrMC[matchType::TPCTRD]->Fill(trk.getPt(), matchTOF.getTgeant() * 1E3 - matchTOF.getLTIntegralOut().getTOF(4));
}
}
}
Expand Down Expand Up @@ -522,6 +565,11 @@ void TOFMatchedTracks::monitorData(o2::framework::ProcessingContext& ctx)
if (lbl.isFake()) {
mFakeMatchedTracksPt[matchType::ITSTPC_ITSTPCTRD]->Fill(trkTPC.getPt());
mFakeMatchedTracksEta[matchType::ITSTPC_ITSTPCTRD]->Fill(trkTPC.getEta());
} else {
mDeltaTwMC->Fill(matchTOF.getSignal() - matchTOF.getT0true() - matchTOF.getTgeant() * 1E3);
mExpTimesPiMC[matchType::ITSTPC_ITSTPCTRD]->Fill(trkTPC.getPt(), matchTOF.getTgeant() * 1E3 - matchTOF.getLTIntegralOut().getTOF(2));
mExpTimesKaMC[matchType::ITSTPC_ITSTPCTRD]->Fill(trkTPC.getPt(), matchTOF.getTgeant() * 1E3 - matchTOF.getLTIntegralOut().getTOF(3));
mExpTimesPrMC[matchType::ITSTPC_ITSTPCTRD]->Fill(trkTPC.getPt(), matchTOF.getTgeant() * 1E3 - matchTOF.getLTIntegralOut().getTOF(4));
}
}
}
Expand Down Expand Up @@ -839,6 +887,10 @@ void TOFMatchedTracks::reset()
{
// clean all the monitor objects here

if (mUseMC) {
mDeltaTwMC->Reset();
}

ILOG(Debug, Devel) << "Resetting the histograms" << ENDM;
for (int i = 0; i < matchType::SIZE; ++i) {
mMatchedTracksPt[i]->Reset();
Expand All @@ -847,6 +899,9 @@ void TOFMatchedTracks::reset()
if (mUseMC) {
mFakeMatchedTracksPt[i]->Reset();
mFakeMatchedTracksEta[i]->Reset();
mExpTimesPiMC[i]->Reset();
mExpTimesKaMC[i]->Reset();
mExpTimesPrMC[i]->Reset();
}
mInTracksPt[i]->Reset();
mInTracksEta[i]->Reset();
Expand Down

0 comments on commit d064539

Please sign in to comment.