Skip to content

Commit d10fea3

Browse files
aferrero2707aphecetche
authored andcommitted
[MCH] added review comments
1 parent 221d31b commit d10fea3

4 files changed

Lines changed: 23 additions & 85 deletions

File tree

DataFormats/Detectors/MUON/MCH/include/DataFormatsMCH/TrackMCH.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,7 @@ class TrackMCH
110110
/// set the number of the clusters attached to the track and the index of the first one
111111
void setClusterRef(int firstClusterIdx, int nClusters) { mClusRef.set(firstClusterIdx, nClusters); }
112112

113-
/// get the interaction record associated to this track
114-
InteractionRecord getIR(uint32_t refOrbit) const;
115-
113+
/// mean time associated to this track, with error
116114
const Time& getTimeMUS() const { return mTimeMUS; }
117115
Time& getTimeMUS() { return mTimeMUS; }
118116
void setTimeMUS(const Time& t) { mTimeMUS = t; }
@@ -122,6 +120,9 @@ class TrackMCH
122120
mTimeMUS.setTimeStampError(te);
123121
}
124122

123+
/// interaction record corresponding to the mean track time
124+
InteractionRecord getMeanIR(uint32_t refOrbit) const;
125+
125126
private:
126127
static constexpr int SNParams = 5; ///< number of track parameters
127128
static constexpr int SCovSize = 15; ///< number of different elements in the symmetric covariance matrix
@@ -151,7 +152,7 @@ class TrackMCH
151152
double mZAtMID = 0.; ///< z position on the MID side where the parameters are evaluated
152153
double mParamAtMID[SNParams] = {0.}; ///< 5 parameters: X (cm), SlopeX, Y (cm), SlopeY, q/pYZ ((GeV/c)^-1)
153154
double mCovAtMID[SCovSize] = {0.}; ///< reduced covariance matrix of track parameters, formated as above
154-
Time mTimeMUS; ///< associated time in microseconds from the TF start
155+
Time mTimeMUS{}; ///< associated time in microseconds from the TF start
155156

156157
ClassDefNV(TrackMCH, 3);
157158
};

DataFormats/Detectors/MUON/MCH/src/TrackMCH.cxx

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "DataFormatsMCH/TrackMCH.h"
1818

1919
#include <cmath>
20-
#include <limits>
2120
#include <fmt/format.h>
2221
#include <string>
2322
#include <iostream>
@@ -88,25 +87,11 @@ void TrackMCH::setCovariances(const TMatrixD& src, double (&dest)[SCovSize])
8887
}
8988

9089
//__________________________________________________________________________
91-
InteractionRecord TrackMCH::getIR(uint32_t refOrbit) const
90+
InteractionRecord TrackMCH::getMeanIR(uint32_t refOrbit) const
9291
{
93-
// track time converted in bunch-crossing units
94-
auto fbc = mTimeMUS.getTimeStamp() / o2::constants::lhc::LHCBunchSpacingMUS;
95-
// wrap-up one full orbit if the track time is negative,
96-
// the first TF orbit is also decreased by one to compensate
97-
if (fbc < 0) {
98-
fbc += o2::constants::lhc::LHCMaxBunches;
99-
refOrbit -= 1;
100-
}
101-
102-
// get the bc-in-orbit value
103-
uint64_t trackBCinTF = uint64_t(std::round(fbc));
104-
uint16_t trackBC = uint16_t(trackBCinTF % o2::constants::lhc::LHCMaxBunches);
105-
// get the absolute track orbit by adding the first orbit of the current TF
106-
uint32_t trackOrbit = uint32_t(trackBCinTF / o2::constants::lhc::LHCMaxBunches) + refOrbit;
107-
108-
// build the track interaction record
109-
return {trackBC, trackOrbit};
92+
InteractionRecord startIR(0, refOrbit);
93+
auto trackBCinTF = std::llround(mTimeMUS.getTimeStamp() / constants::lhc::LHCBunchSpacingMUS);
94+
return startIR + trackBCinTF;
11095
}
11196

11297
std::ostream& operator<<(std::ostream& os, const o2::mch::TrackMCH& t)

DataFormats/Detectors/MUON/MCH/src/testTrackMCH.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ BOOST_AUTO_TEST_CASE(TrackIRMatchesTrackTime)
3333
float tErr = 6.0 * o2::constants::lhc::LHCBunchSpacingMUS;
3434
track.setTimeMUS(tMean, tErr);
3535

36-
o2::InteractionRecord trackIR = track.getIR(orbitRef);
36+
o2::InteractionRecord trackIR = track.getMeanIR(orbitRef);
3737
BOOST_CHECK_EQUAL(ir, trackIR);
3838
}
3939

@@ -52,6 +52,6 @@ BOOST_AUTO_TEST_CASE(TrackIRMatchesNegativeTrackTime)
5252
float tErr = 6.0 * o2::constants::lhc::LHCBunchSpacingMUS;
5353
track.setTimeMUS(tMean, tErr);
5454

55-
o2::InteractionRecord trackIR = track.getIR(orbitRef);
55+
o2::InteractionRecord trackIR = track.getMeanIR(orbitRef);
5656
BOOST_CHECK_EQUAL(ir, trackIR);
5757
}

Detectors/MUON/MCH/Workflow/src/TrackFinderSpec.cxx

Lines changed: 12 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <stdexcept>
2323
#include <string>
2424
#include <filesystem>
25-
#include <limits>
2625

2726
#include <gsl/span>
2827

@@ -155,78 +154,31 @@ class TrackFinderTask
155154
}
156155

157156
private:
158-
std::pair<InteractionRecord, bool> trackBC2IR(double trackBCinTF, const ROFRecord& trackROF, uint32_t firstTForbit) const
157+
void setTrackTime(TrackMCH& track, const ROFRecord& clusterROF, uint32_t firstTForbit, const gsl::span<const Cluster> usedClusters, const gsl::span<const Digit> usedDigits) const
159158
{
160-
// limits of the current ROF
161-
const InteractionRecord& rofStart = trackROF.getBCData();
162-
const InteractionRecord& rofEnd = trackROF.getBCData() + int64_t(trackROF.getBCWidth());
163-
164-
// wrap-up one full orbit if the track time is negative,
165-
// the first TF orbit is also decreased by one to compensate
166-
if (trackBCinTF < 0) {
167-
trackBCinTF += o2::constants::lhc::LHCMaxBunches;
168-
firstTForbit -= 1;
169-
}
170-
171-
// get the bc-in-orbit value
172-
uint16_t trackBC = uint16_t(uint64_t(trackBCinTF) % o2::constants::lhc::LHCMaxBunches);
173-
// get the absolute track orbit by adding the first orbit of the current TF
174-
uint32_t trackOrbit = uint32_t(uint64_t(trackBCinTF) / o2::constants::lhc::LHCMaxBunches) + firstTForbit;
175-
176-
// build the track interaction record
177-
InteractionRecord trackIR{trackBC, trackOrbit};
178-
179-
// if we are outside the cluster ROF, something must be wrong
180-
// in this case we log a warning message and we return a default IR value
181-
bool isOk = true;
182-
if (trackIR < rofStart || trackIR > rofEnd) {
183-
LOG(warning) << fmt::format("track time incompatible with track ROF. TRACK: BC={}, IR={},{} ROF: start={},{}, end={},{} FIRST_TF_ORBIT: {}",
184-
trackBCinTF, trackIR.orbit, trackIR.bc, rofStart.orbit, rofStart.bc, rofEnd.orbit, rofEnd.bc, firstTForbit);
185-
isOk = false;
186-
}
187-
188-
return {trackIR, isOk};
189-
}
190-
191-
//_________________________________________________________________________________________________
192-
void setTrackTimeFromROF(TrackMCH& track, const ROFRecord& trackROF, uint32_t firstTForbit) const
193-
{
194-
// the track time is taken at the middle of the track ROF,
195-
// in microseconds relative to the beginning of the TF
196-
InteractionRecord startIR{0, firstTForbit};
197-
float rofHalfWidth = 0.5 * trackROF.getBCWidth();
198-
auto ir = trackROF.getBCData();
199-
float bcDiff = ir.differenceInBC(startIR);
200-
bcDiff += rofHalfWidth;
201-
float tMean = o2::constants::lhc::LHCBunchSpacingMUS * bcDiff;
202-
// the time resolution is estimated as the half-width of the track ROF
203-
float tErr = o2::constants::lhc::LHCBunchSpacingMUS * rofHalfWidth;
204-
track.setTimeMUS(tMean, tErr);
205-
}
206-
207-
//_________________________________________________________________________________________________
208-
void setTrackTime(TrackMCH& track, const ROFRecord& trackROF, uint32_t firstTForbit, const gsl::span<const Cluster> usedClusters, const gsl::span<const Digit> usedDigits) const
209-
{
210-
float trackBCinTF = 0;
159+
double trackBCinTF = 0;
211160
int nDigits = 0;
212161

213162
// loop over digits and compute the average track time
214163
for (const auto& cluster : usedClusters.subspan(track.getFirstClusterIdx(), track.getNClusters())) {
215164
for (const auto& digit : usedDigits.subspan(cluster.firstDigit, cluster.nDigits)) {
216165
nDigits += 1;
217-
trackBCinTF += (float(digit.getTime()) - trackBCinTF) / nDigits;
166+
trackBCinTF += (double(digit.getTime()) - trackBCinTF) / nDigits;
218167
}
219168
}
220169

221170
// set the track IR from the computed average digits time
222171
if (nDigits > 0) {
223-
float tMean = o2::constants::lhc::LHCBunchSpacingMUS * trackBCinTF;
172+
// convert the average digit time from bunch-crossing units to microseconds
173+
// add 1.5 BC to account for the fact that the actual digit time in BC units
174+
// can be between t and t+3, hence t+1.5 in average
175+
float tMean = o2::constants::lhc::LHCBunchSpacingMUS * (trackBCinTF + 1.5);
224176
float tErr = o2::constants::lhc::LHCBunchSpacingMUS * mTrackTime3Sigma;
225177
track.setTimeMUS(tMean, tErr);
226178
} else {
227179
// if no digits are found, compute the time directly from the track's ROF
228-
LOG(warning) << "no digits found when computing the track mean time";
229-
setTrackTimeFromROF(track, trackROF, firstTForbit);
180+
LOG(fatal) << "MCH: no digits found when computing the track mean time";
181+
track.setTimeMUS(clusterROF.getTimeMUS({0, firstTForbit}).first);
230182
}
231183
}
232184

@@ -277,16 +229,16 @@ class TrackFinderTask
277229
}
278230

279231
// compute the track time
280-
if (mDigits && usedDigits) {
232+
if (mDigits) {
281233
setTrackTime(mchTracks.back(), clusterROF, firstTForbit, usedClusters, *usedDigits);
282234
} else {
283-
setTrackTimeFromROF(mchTracks.back(), clusterROF, firstTForbit);
235+
mchTracks.back().setTimeMUS(clusterROF.getTimeMUS({0, firstTForbit}).first);
284236
}
285237
}
286238
}
287239

288240
bool mDigits = false; ///< send to associated digits
289-
float mTrackTime3Sigma{6.0}; ///< three times the track time resolution, in BC units
241+
float mTrackTime3Sigma{6.0}; ///< three times the digit time resolution, in BC units
290242
TrackFinder mTrackFinder{}; ///< track finder
291243
std::chrono::duration<double> mElapsedTime{}; ///< timer
292244
};

0 commit comments

Comments
 (0)