Skip to content

Commit e28a707

Browse files
committed
Optionally apply correction map to cluster residuals
1 parent 9265d8a commit e28a707

1 file changed

Lines changed: 36 additions & 2 deletions

File tree

Detectors/TPC/calibration/SpacePoints/macro/staticMapCreator.C

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ bool revalidateTrack(const TrackData& trk, const SpacePointsCalibConfParam& para
122122
void staticMapCreator(std::string fileInput = "files.txt",
123123
int runNumber = 527976,
124124
std::string fileOutput = "voxRes.root",
125+
std::string voxMapInput = "",
125126
std::string trackSources = static_cast<std::string>(GID::ALL))
126127
{
127128

@@ -169,8 +170,26 @@ void staticMapCreator(std::string fileInput = "files.txt",
169170

170171
TrackResiduals trackResiduals;
171172
trackResiduals.init();
172-
trackResiduals.createOutputFile(fileOutput.c_str());
173173

174+
// Do we have a correction map available that we should apply to the clusters before the map extraction?
175+
std::array<std::vector<TrackResiduals::VoxRes>, SECTORSPERSIDE * SIDES> voxelResults{};
176+
if (voxMapInput.size()) {
177+
LOG(info) << "A correction map has been provided. Will apply the corrections to the cluster residuals";
178+
for (int iSec = 0; iSec < SECTORSPERSIDE * SIDES; ++iSec) {
179+
voxelResults[iSec].resize(trackResiduals.getNVoxelsPerSector());
180+
}
181+
TrackResiduals::VoxRes voxRes, *voxResPtr = &voxRes;
182+
std::unique_ptr<TFile> fIn = std::make_unique<TFile>(voxMapInput.c_str());
183+
std::unique_ptr<TTree> treeIn;
184+
treeIn.reset((TTree*)fIn->Get("voxResTree"));
185+
treeIn->SetBranchAddress("voxRes", &voxResPtr);
186+
for (int iEntry = 0; iEntry < treeIn->GetEntries(); ++iEntry) {
187+
treeIn->GetEntry(iEntry);
188+
voxelResults[voxRes.bsec][trackResiduals.getGlbVoxBin(voxRes.bvox)] = voxRes;
189+
}
190+
}
191+
192+
trackResiduals.createOutputFile(fileOutput.c_str());
174193
std::unique_ptr<TTree> treeBinnedResiduals = std::make_unique<TTree>("resid", "TPC binned residuals");
175194
if (!params.writeBinnedResiduals) {
176195
treeBinnedResiduals->SetDirectory(nullptr);
@@ -261,7 +280,22 @@ void staticMapCreator(std::string fileInput = "files.txt",
261280
LOGF(debug, "Dropping residual in sec(%i), x(%f), y(%f), z(%f)", sec, xPos, yPos, zPos);
262281
continue;
263282
}
264-
residVecOut.emplace_back(residIn.dy, residIn.dz, residIn.tgSlp, bvox);
283+
if (voxMapInput.size()) {
284+
// we already have a correction map available which we want to apply as consistency check
285+
const auto& voxRes = voxelResults[sec][trackResiduals.getGlbVoxBin(bvox)];
286+
float dy = residIn.dy * param::MaxResid / 0x7fff;
287+
float tgSlp = residIn.tgSlp * param::MaxTgSlp / 0x7fff;
288+
dy -= voxRes.D[TrackResiduals::ResY] - voxRes.D[TrackResiduals::ResX] * tgSlp;
289+
float dz = residIn.dz * param::MaxResid / 0x7fff;
290+
dz -= voxRes.D[TrackResiduals::ResZ] - voxRes.D[TrackResiduals::ResX] * voxRes.stat[TrackResiduals::VoxZ];
291+
dy = fabs(dy) < param::MaxResid ? dy : std::copysign(param::MaxResid, dy);
292+
dz = fabs(dz) < param::MaxResid ? dz : std::copysign(param::MaxResid, dz);
293+
short dYcorr = static_cast<short>(dy * 0x7fff / param::MaxResid);
294+
short dZcorr = static_cast<short>(dz * 0x7fff / param::MaxResid);
295+
residVecOut.emplace_back(dYcorr, dZcorr, residIn.tgSlp, bvox);
296+
} else {
297+
residVecOut.emplace_back(residIn.dy, residIn.dz, residIn.tgSlp, bvox);
298+
}
265299
auto& stat = statVecOut[trackResiduals.getGlbVoxBin(bvox)];
266300
float& binEntries = stat.nEntries;
267301
float oldEntries = binEntries++;

0 commit comments

Comments
 (0)