Skip to content

Commit a4476f7

Browse files
noferinishahor02
authored andcommitted
fix for TPC-TOF matching (thanks to Francesco)
1 parent 5e637b9 commit a4476f7

File tree

8 files changed

+64
-29
lines changed

8 files changed

+64
-29
lines changed

DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class MatchInfoTOF
2828
using evIdx = o2::dataformats::EvIndex<int, int>;
2929

3030
public:
31-
MatchInfoTOF(evIdx evIdxTOFCl, float chi2, o2::track::TrackLTIntegral trkIntLT, evGIdx evIdxTrack) : mEvIdxTOFCl(evIdxTOFCl), mChi2(chi2), mIntLT(trkIntLT), mEvIdxTrack(evIdxTrack){};
31+
MatchInfoTOF(evIdx evIdxTOFCl, float chi2, o2::track::TrackLTIntegral trkIntLT, evGIdx evIdxTrack, float dt = 0, float z = 0) : mEvIdxTOFCl(evIdxTOFCl), mChi2(chi2), mIntLT(trkIntLT), mEvIdxTrack(evIdxTrack), mDeltaT(dt), mZatTOF(z){};
3232
MatchInfoTOF() = default;
3333
void setEvIdxTOFCl(evIdx index) { mEvIdxTOFCl = index; }
3434
void setEvIdxTrack(evGIdx index) { mEvIdxTrack = index; }
@@ -46,13 +46,20 @@ class MatchInfoTOF
4646
const o2::track::TrackLTIntegral& getLTIntegralOut() const { return mIntLT; }
4747
void print() const;
4848

49+
void setDeltaT(float val) { mDeltaT = val; }
50+
float getDeltaT() const { return mDeltaT; }
51+
void setZatTOF(float val) { mZatTOF = val; }
52+
float getZatTOF() const { return mZatTOF; }
53+
4954
private:
5055
float mChi2; // chi2 of the pair track-TOFcluster
5156
o2::track::TrackLTIntegral mIntLT; ///< L,TOF integral calculated during the propagation
5257
evIdx mEvIdxTOFCl; ///< EvIdx for TOF cluster (first: ev index; second: cluster index)
5358
evGIdx mEvIdxTrack; ///< EvIdx for track (first: ev index; second: track global index)
59+
float mZatTOF = 0.0; ///< Z position at TOF
60+
float mDeltaT = 0.0; ///< tTOF - TPC (microsec)
5461

55-
ClassDefNV(MatchInfoTOF, 1);
62+
ClassDefNV(MatchInfoTOF, 2);
5663
};
5764
} // namespace dataformats
5865
} // namespace o2

Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ class MatchTOF
9090
void init();
9191
void initTPConly();
9292

93+
void setCosmics()
94+
{
95+
mIsCosmics = true;
96+
mSpaceTolerance = 150;
97+
mTimeTolerance = 50e3;
98+
}
99+
93100
///< attach DPL data and run
94101
void run(const gsl::span<const o2::dataformats::TrackTPCITS>& trackArray, const gsl::span<const Cluster>& clusterArray, const o2::dataformats::MCTruthContainer<o2::MCCompLabel>& toflab, const gsl::span<const o2::MCCompLabel>& itstpclab);
95102
void run(const gsl::span<const o2::tpc::TrackTPC>& trackArray, const gsl::span<const Cluster>& clusterArray, const o2::dataformats::MCTruthContainer<o2::MCCompLabel>& toflab, const gsl::span<const o2::MCCompLabel>& tpclab);
@@ -273,8 +280,9 @@ class MatchTOF
273280
float mTPCTBinMUSInv = 0.; ///< inverse TPC time bin duration in microseconds
274281
float mTPCBin2Z = 0.; ///< conversion coeff from TPC time-bin to Z
275282

276-
float mTimeTolerance = 1e3; ///<tolerance in ns for track-TOF time bracket matching
277-
float mSpaceTolerance = 10; ///<tolerance in cm for track-TOF time bracket matching
283+
bool mIsCosmics = false; ///< switch on to reconstruct cosmics and match with TPC
284+
float mTimeTolerance = 1e3; ///< tolerance in ns for track-TOF time bracket matching
285+
float mSpaceTolerance = 10; ///< tolerance in cm for track-TOF time bracket matching
278286
int mSigmaTimeCut = 30.; ///< number of sigmas to cut on time when matching the track to the TOF cluster
279287

280288
TTree* mInputTreeTracks = nullptr; ///< input tree for tracks

Detectors/GlobalTracking/src/MatchTOF.cxx

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -505,13 +505,12 @@ bool MatchTOF::prepareTracks()
505505
std::array<float, 3> globalPos;
506506
int itmp = 0;
507507
for (int sec = o2::constants::math::NSectors; sec--;) {
508-
Printf("sector %d", sec);
509508
auto& cacheTrk = mTracksSectIndexCache[sec]; // array of cached tracks indices for this sector; reminder: they are ordered in time!
510509
for (int itrk = 0; itrk < cacheTrk.size(); itrk++){
511510
itmp++;
512511
auto& trc = mTracksWork[cacheTrk[itrk]];
513512
trc.getXYZGlo(globalPos);
514-
printf("Track %d: Global coordinates After propagating to 371 cm: globalPos[0] = %f, globalPos[1] = %f, globalPos[2] = %f\n", itrk, globalPos[0], globalPos[1], globalPos[2]);
513+
//printf("Track %d: Global coordinates After propagating to 371 cm: globalPos[0] = %f, globalPos[1] = %f, globalPos[2] = %f\n", itrk, globalPos[0], globalPos[1], globalPos[2]);
515514
// Printf("The phi angle is %f", TMath::ATan2(globalPos[1], globalPos[0]));
516515
}
517516
}
@@ -563,10 +562,14 @@ bool MatchTOF::prepareTPCTracks()
563562
// create working copy of track param
564563
timeEst timeInfo;
565564
// set
565+
float extraErr = 0;
566+
if (mIsCosmics) {
567+
extraErr = 100;
568+
}
566569
timeInfo.setTimeStamp(trcOrig.getTime0() * mTPCTBinMUS);
567-
timeInfo.setTimeStampError((trcOrig.getDeltaTBwd() + 5) * mTPCTBinMUS);
570+
timeInfo.setTimeStampError((trcOrig.getDeltaTBwd() + 5) * mTPCTBinMUS + extraErr);
568571
mSideTPC.push_back(trcOrig.hasASideClustersOnly() ? 1 : (trcOrig.hasCSideClustersOnly() ? -1 : 0));
569-
mExtraTPCFwdTime.push_back((trcOrig.getDeltaTFwd() + 5) * mTPCTBinMUS);
572+
mExtraTPCFwdTime.push_back((trcOrig.getDeltaTFwd() + 5) * mTPCTBinMUS + extraErr);
570573

571574
o2::track::TrackLTIntegral intLT0; //mTPCTracksWork.back().getLTIntegralOut(); // we get the integrated length from TPC-ITC outward propagation
572575
// make a copy of the TPC track that we have to propagate
@@ -641,6 +644,7 @@ bool MatchTOF::prepareTPCTracks()
641644
auto& trcB = mTracksWork[b].second;
642645
return ((trcA.getTimeStamp() - trcA.getTimeStampError()) - (trcB.getTimeStamp() - trcB.getTimeStampError()) < 0.);
643646
});
647+
644648
} // loop over tracks of single sector
645649

646650
// Uncomment for local debug
@@ -653,14 +657,15 @@ bool MatchTOF::prepareTPCTracks()
653657
auto& cacheTrk = mTracksSectIndexCache[sec]; // array of cached tracks indices for this sector; reminder: they are ordered in time!
654658
for (int itrk = 0; itrk < cacheTrk.size(); itrk++){
655659
itmp++;
656-
auto& trc = mTracksWork[cacheTrk[itrk]];
660+
auto& trc = mTracksWork[cacheTrk[itrk]].first;
661+
auto& trcAttr = mTracksWork[cacheTrk[itrk]].second;
657662
trc.getXYZGlo(globalPos);
658-
printf("Track %d: Global coordinates After propagating to 371 cm: globalPos[0] = %f, globalPos[1] = %f, globalPos[2] = %f\n", itrk, globalPos[0], globalPos[1], globalPos[2]);
663+
printf("Track %d: Global coordinates After propagating to 371 cm: globalPos[0] = %f, globalPos[1] = %f, globalPos[2] = %f -- timestamp = %f +/- %f\n", itrk, globalPos[0], globalPos[1], globalPos[2],trcAttr.getTimeStamp(),trcAttr.getTimeStampError());
659664
// Printf("The phi angle is %f", TMath::ATan2(globalPos[1], globalPos[0]));
660665
}
661666
}
662667
Printf("we have %d tracks",itmp);
663-
*/
668+
*/
664669

665670
return true;
666671
}
@@ -1116,6 +1121,7 @@ void MatchTOF::doMatchingForTPC(int sec)
11161121
float vdriftInBC = Geo::BC_TIME_INPS * 1E-6 * vdrift;
11171122

11181123
int bc_grouping = 40;
1124+
int bc_grouping_tolerance = bc_grouping + mTimeTolerance / 25;
11191125
int bc_grouping_half = (bc_grouping + 1) / 2;
11201126
double BCgranularity = Geo::BC_TIME_INPS * bc_grouping;
11211127

@@ -1162,17 +1168,20 @@ void MatchTOF::doMatchingForTPC(int sec)
11621168
minTrkTime = int(minTrkTime / BCgranularity) * BCgranularity; // align min to a BC
11631169
double maxTrkTime = (trackWork.second.getTimeStamp() + mExtraTPCFwdTime[cacheTrk[itrk]]) * 1.E6; // maximum time in ps
11641170

1165-
/*
1171+
// printf("trk time %f - %f (max shift +/- %f cm)\n",minTrkTime,maxTrkTime,trackWork.second.getTimeStampError()*vdrift );
1172+
11661173
for (double tBC = minTrkTime; tBC < maxTrkTime; tBC += BCgranularity) {
11671174
unsigned long ibc = (unsigned long)(tBC * Geo::BC_TIME_INPS_INV);
11681175
BCcand.emplace_back(ibc);
11691176
nStripsCrossedInPropagation.emplace_back(0);
11701177
}
1171-
*/
11721178

1179+
/*
11731180
for (auto itof = itof0; itof < nTOFCls; itof++) {
11741181
auto& trefTOF = mTOFClusWork[cacheTOF[itof]];
11751182
1183+
// printf("clus time = %f\n",trefTOF.getTime());
1184+
11761185
if (trefTOF.getTime() < minTrkTime) { // this cluster has a time that is too small for the current track, we will get to the next one
11771186
itof0 = itof + 1;
11781187
continue;
@@ -1203,7 +1212,7 @@ void MatchTOF::doMatchingForTPC(int sec)
12031212
nStripsCrossedInPropagation.emplace_back(0);
12041213
}
12051214
}
1206-
1215+
*/
12071216
// printf("BC = %ld\n",BCcand.size());
12081217

12091218
detId.clear();
@@ -1320,8 +1329,8 @@ void MatchTOF::doMatchingForTPC(int sec)
13201329
}
13211330
}
13221331
for (int ibc = 0; ibc < BCcand.size(); ibc++) {
1323-
float minTime = (BCcand[ibc] - bc_grouping) * Geo::BC_TIME_INPS;
1324-
float maxTime = (BCcand[ibc] + bc_grouping) * Geo::BC_TIME_INPS;
1332+
float minTime = (BCcand[ibc] - bc_grouping_tolerance) * Geo::BC_TIME_INPS;
1333+
float maxTime = (BCcand[ibc] + bc_grouping_tolerance) * Geo::BC_TIME_INPS;
13251334
for (Int_t imatch = 0; imatch < nStripsCrossedInPropagation[ibc]; imatch++) {
13261335
// we take as residual the average of the residuals along the propagation in the same strip
13271336
deltaPos[ibc][imatch][0] /= nStepsInsideSameStrip[ibc][imatch];
@@ -1340,17 +1349,14 @@ void MatchTOF::doMatchingForTPC(int sec)
13401349
// printf("itof = %d\n", itof);
13411350
auto& trefTOF = mTOFClusWork[cacheTOF[itof]];
13421351
// compare the times of the track and the TOF clusters - remember that they both are ordered in time!
1343-
//Printf("trefTOF.getTime() = %f, maxTrkTime = %f, minTrkTime = %f", trefTOF.getTime(), maxTrkTime, minTrkTime);
13441352

13451353
if (trefTOF.getTime() < minTime) { // this cluster has a time that is too small for the current track, we will get to the next one
1346-
//Printf("In trefTOF.getTime() < minTrkTime");
13471354
itof0 = itof + 1; // but for the next track that we will check, we will ignore this cluster (the time is anyway too small)
13481355
continue;
13491356
}
13501357
if (trefTOF.getTime() > maxTime) { // no more TOF clusters can be matched to this track
13511358
break;
13521359
}
1353-
13541360
unsigned long bcClus = trefTOF.getTime() * Geo::BC_TIME_INPS_INV;
13551361

13561362
int mainChannel = trefTOF.getMainContributingChannel();
@@ -1402,8 +1408,13 @@ void MatchTOF::doMatchingForTPC(int sec)
14021408
LOG(DEBUG) << "Propagated Track [" << itrk << ", " << cacheTrk[itrk] << "]: detId[" << iPropagation << "] = " << detId[ibc][iPropagation][0] << ", " << detId[ibc][iPropagation][1] << ", " << detId[ibc][iPropagation][2] << ", " << detId[ibc][iPropagation][3] << ", " << detId[ibc][iPropagation][4];
14031409
float resX = deltaPos[ibc][iPropagation][0] - (indices[4] - detId[ibc][iPropagation][4]) * Geo::XPAD + posCorr[0]; // readjusting the residuals due to the fact that the propagation fell in a pad that was not exactly the one of the cluster
14041410
float resZ = deltaPos[ibc][iPropagation][2] - (indices[3] - detId[ibc][iPropagation][3]) * Geo::ZPAD + posCorr[2]; // readjusting the residuals due to the fact that the propagation fell in a pad that was not exactly the one of the cluster
1405-
resZ += (BCcand[ibc] - bcClus) * vdriftInBC * side; // add bc correction
1411+
if (BCcand[ibc] > bcClus) {
1412+
resZ += (BCcand[ibc] - bcClus) * vdriftInBC * side; // add bc correction
1413+
} else {
1414+
resZ -= (bcClus - BCcand[ibc]) * vdriftInBC * side;
1415+
}
14061416
float res = TMath::Sqrt(resX * resX + resZ * resZ);
1417+
14071418
if (indices[0] != detId[ibc][iPropagation][0]) {
14081419
continue;
14091420
}
@@ -1413,16 +1424,17 @@ void MatchTOF::doMatchingForTPC(int sec)
14131424
if (indices[2] != detId[ibc][iPropagation][2]) {
14141425
continue;
14151426
}
1427+
14161428
LOG(DEBUG) << "resX = " << resX << ", resZ = " << resZ << ", res = " << res;
1417-
float chi2 = res; // TODO: take into account also the time!
1429+
float chi2 = mIsCosmics ? resX : res; // TODO: take into account also the time!
14181430

14191431
if (res < mSpaceTolerance) { // matching ok!
14201432
LOG(DEBUG) << "MATCHING FOUND: We have a match! between track " << mTracksSectIndexCache[indices[0]][itrk] << " and TOF cluster " << mTOFClusSectIndexCache[indices[0]][itof];
14211433
foundCluster = true;
14221434
// set event indexes (to be checked)
14231435
evIdx eventIndexTOFCluster(trefTOF.getEntryInTree(), mTOFClusSectIndexCache[indices[0]][itof]);
14241436
evGIdx eventIndexTracks(mCurrTracksTreeEntry, {uint32_t(mTracksSectIndexCache[indices[0]][itrk]), o2::dataformats::GlobalTrackID::TPC});
1425-
mMatchedTracksPairs.emplace_back(eventIndexTOFCluster, chi2, trkLTInt[ibc][iPropagation], eventIndexTracks); // TODO: check if this is correct!
1437+
mMatchedTracksPairs.emplace_back(eventIndexTOFCluster, chi2, trkLTInt[ibc][iPropagation], eventIndexTracks, resZ / vdrift * side, trefTOF.getZ()); // TODO: check if this is correct!
14261438
}
14271439
}
14281440
}

Detectors/GlobalTrackingWorkflow/tofworkflow/include/TOFWorkflow/RecoWorkflowWithTPCSpec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace o2
1919
namespace tof
2020
{
2121

22-
o2::framework::DataProcessorSpec getTOFRecoWorkflowWithTPCSpec(bool useMC, bool useFIT, bool doTPCRefit);
22+
o2::framework::DataProcessorSpec getTOFRecoWorkflowWithTPCSpec(bool useMC, bool useFIT, bool doTPCRefit, bool iscosmics);
2323

2424
} // end namespace tof
2525
} // end namespace o2

Detectors/GlobalTrackingWorkflow/tofworkflow/src/RecoWorkflowWithTPCSpec.cxx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ class TOFDPLRecoWorkflowWithTPCTask
4949
bool mUseMC = true;
5050
bool mUseFIT = false;
5151
bool mDoTPCRefit = false;
52+
bool mIsCosmics = false;
5253

5354
public:
54-
explicit TOFDPLRecoWorkflowWithTPCTask(bool useMC, bool useFIT, bool doTPCRefit) : mUseMC(useMC), mUseFIT(useFIT), mDoTPCRefit(doTPCRefit) {}
55+
explicit TOFDPLRecoWorkflowWithTPCTask(bool useMC, bool useFIT, bool doTPCRefit, bool iscosmics) : mUseMC(useMC), mUseFIT(useFIT), mDoTPCRefit(doTPCRefit), mIsCosmics(iscosmics) {}
5556

5657
void init(framework::InitContext& ic)
5758
{
@@ -74,6 +75,11 @@ class TOFDPLRecoWorkflowWithTPCTask
7475

7576
void run(framework::ProcessingContext& pc)
7677
{
78+
if (mIsCosmics) {
79+
mMatcher.setCosmics();
80+
}
81+
mMatcher.print();
82+
7783
mTimer.Start(false);
7884
//>>>---------- attach input data --------------->>>
7985
const auto clustersRO = pc.inputs().get<gsl::span<o2::tof::Cluster>>("tofcluster");
@@ -142,7 +148,7 @@ class TOFDPLRecoWorkflowWithTPCTask
142148
TStopwatch mTimer;
143149
};
144150

145-
o2::framework::DataProcessorSpec getTOFRecoWorkflowWithTPCSpec(bool useMC, bool useFIT, bool doTPCRefit)
151+
o2::framework::DataProcessorSpec getTOFRecoWorkflowWithTPCSpec(bool useMC, bool useFIT, bool doTPCRefit, bool iscosmics)
146152
{
147153
std::vector<InputSpec> inputs;
148154
std::vector<OutputSpec> outputs;
@@ -174,7 +180,7 @@ o2::framework::DataProcessorSpec getTOFRecoWorkflowWithTPCSpec(bool useMC, bool
174180
"TOFRecoWorkflowWithTPC",
175181
inputs,
176182
outputs,
177-
AlgorithmSpec{adaptFromTask<TOFDPLRecoWorkflowWithTPCTask>(useMC, useFIT, doTPCRefit)},
183+
AlgorithmSpec{adaptFromTask<TOFDPLRecoWorkflowWithTPCTask>(useMC, useFIT, doTPCRefit, iscosmics)},
178184
Options{
179185
{"material-lut-path", VariantType::String, "", {"Path of the material LUT file"}}}};
180186
}

Detectors/GlobalTrackingWorkflow/tofworkflow/src/tof-matcher-tpc.cxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)
5252
workflowOptions.push_back(ConfigParamSpec{"tpc-refit", o2::framework::VariantType::Bool, false, {"refit matched TPC tracks"}});
5353
workflowOptions.push_back(ConfigParamSpec{"disable-root-input", o2::framework::VariantType::Bool, false, {"disable root-files input readers"}});
5454
workflowOptions.push_back(ConfigParamSpec{"disable-root-output", o2::framework::VariantType::Bool, false, {"disable root-files output writers"}});
55+
workflowOptions.push_back(ConfigParamSpec{"cosmics", o2::framework::VariantType::Bool, false, {"reco for cosmics"}});
5556
workflowOptions.push_back(ConfigParamSpec{"configKeyValues", o2::framework::VariantType::String, "", {"Semicolon separated key=value strings ..."}});
5657
}
5758

@@ -96,6 +97,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
9697
auto doTPCRefit = cfgc.options().get<bool>("tpc-refit");
9798
bool disableRootInput = cfgc.options().get<bool>("disable-root-input");
9899
bool disableRootOutput = cfgc.options().get<bool>("disable-root-output");
100+
auto isCosmics = cfgc.options().get<bool>("cosmics");
99101

100102
LOG(INFO) << "TOF RECO WORKFLOW configuration";
101103
LOG(INFO) << "TOF output = " << cfgc.options().get<std::string>("output-type");
@@ -146,7 +148,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
146148
}
147149

148150
LOG(INFO) << "Insert TOF Matching";
149-
specs.emplace_back(o2::tof::getTOFRecoWorkflowWithTPCSpec(useMC, useFIT, doTPCRefit));
151+
specs.emplace_back(o2::tof::getTOFRecoWorkflowWithTPCSpec(useMC, useFIT, doTPCRefit, isCosmics));
150152

151153
if (!disableRootOutput) {
152154
if (writematching) {

Detectors/TOF/reconstruction/src/Clusterer.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void Clusterer::calibrateStrip()
5454
double calib = mCalibApi->getTimeCalibration(dig->getChannel(), dig->getTOT() * Geo::TOTBIN_NS);
5555
//printf("channel %d) isProblematic = %d, fractionUnderPeak = %f\n",dig->getChannel(),mCalibApi->isProblematic(dig->getChannel()),mCalibApi->getFractionUnderPeak(dig->getChannel())); // toberem
5656
dig->setIsProblematic(mCalibApi->isProblematic(dig->getChannel()));
57-
dig->setCalibratedTime(dig->getTDC() * Geo::TDCBIN + dig->getBC() * o2::constants::lhc::LHCBunchSpacingNS * 1E3 - calib); //TODO: to be checked that "-" is correct, and we did not need "+" instead :-)
57+
dig->setCalibratedTime(dig->getTDC() * Geo::TDCBIN + dig->getBC() * o2::constants::lhc::LHCBunchSpacingNS * 1E3 - Geo::LATENCYWINDOW * 1E3 - calib); //TODO: to be checked that "-" is correct, and we did not need "+" instead :-)
5858
//printf("calibration correction = %f\n",calib); // toberem
5959
}
6060
}

Detectors/TOF/simulation/src/Digitizer.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ int Digitizer::process(const std::vector<HitType>* hits, std::vector<Digit>* dig
105105
for (auto& hit : *hits) {
106106
//TODO: put readout window counting/selection
107107

108-
processHit(hit, mEventTime.getTimeOffsetWrtBC());
108+
processHit(hit, mEventTime.getTimeOffsetWrtBC() + Geo::LATENCYWINDOW);
109109
} // end loop over hits
110110

111111
if (!mContinuous) { // fill output container per event

0 commit comments

Comments
 (0)