CbmRoot
Loading...
Searching...
No Matches
detectors/tof/Hit.h
Go to the documentation of this file.
1/* Copyright (C) 2022 Facility for Antiproton and Ion Research in Europe, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Dominik Smith [committer], Pierre-Alain Loizeau, Felix Weiglhofer */
4#pragma once
5
6#include "ClusterizerPars.h"
7#include "Definitions.h"
8#include "Math/Rotation3D.h"
9#include "Math/Vector3Dfwd.h"
10
11#include <boost/serialization/access.hpp>
12#include <boost/serialization/split_member.hpp>
13
14#include <cstdint>
15#include <vector>
16
18{
19 template<class Archive>
20 void save(Archive& ar, const ROOT::Math::XYZVector& val, const unsigned int /*version*/)
21 {
22 ar << val.X();
23 ar << val.Y();
24 ar << val.Z();
25 }
26
27 template<class Archive>
28 void load(Archive& ar, ROOT::Math::XYZVector& val, const unsigned int /*version*/)
29 {
30 double x, y, z;
31 ar >> x >> y >> z;
32 val.SetXYZ(x, y, z);
33 }
34
35 template<class Archive>
36 void serialize(Archive& ar, ROOT::Math::XYZVector& val, const unsigned int version)
37 {
38 split_free(ar, val, version);
39 }
40} // namespace boost::serialization
41
42
43namespace cbm::algo::tof
44{
45 struct Hit {
46 ROOT::Math::XYZVector hitPos = ROOT::Math::XYZVector(0.0, 0.0, 0.0);
47 ROOT::Math::XYZVector hitPosErr = ROOT::Math::XYZVector(0.0, 0.0, 0.0);
48 double hitTime = 0.0;
49 double hitTimeErr = 0.0;
50 int32_t address = 0;
51 size_t numchan = 0;
52 double weightsSum = 0.0;
53
54 // Interface for tracker
55
56 real X() const { return hitPos.X(); }
57 real Y() const { return hitPos.Y(); }
58 real Z() const { return hitPos.Z(); }
59 u32 Time() const { return hitTime; }
60
61 real Dx() const { return hitPosErr.X(); }
62 real Dy() const { return hitPosErr.Y(); }
63 real TimeError() const { return hitTimeErr; }
64
65 // Interface end
66
67 int32_t numChan() const { return numchan; }
68
69 void reset()
70 {
71 hitPos = ROOT::Math::XYZVector(0.0, 0.0, 0.0);
72 hitPosErr = ROOT::Math::XYZVector(0.0, 0.0, 0.0);
73 hitTime = 0.0;
74 hitTimeErr = 0.0;
75 weightsSum = 0.0;
76 address = 0;
77 numchan = 0;
78 }
79
80 void add(ROOT::Math::XYZVector pos, double time, double timeErr, double weight)
81 {
82 hitPos += pos * weight;
83 hitTime += time * weight;
84 hitTimeErr += timeErr * weight;
85 weightsSum += weight;
86 numchan++;
87 }
88
89 void normalize(double timeErr)
90 {
91 // a/=b is translated to a := a*(1/b) in the ROOT::Math::XYZVector class, which has a different
92 // rounding behavior than a := (a/b). In rare cases this leads to 1.000... becoming 0.999... inside
93 // the floor() operation in the finalize() function of this class, and results in a different
94 // channel being associated with the cluster. To reproduce the output of the old hit finder, we
95 // divide element-wise instead. Perhaps floor() should be replaced by round().
97
98 hitPos.SetXYZ(hitPos.X() / weightsSum, hitPos.Y() / weightsSum, hitPos.Z() / weightsSum);
100 hitTimeErr = timeErr;
101 }
102
103 void finalize(const TofCell& trafoCell, const ClusterizerRpcPar& par)
104 {
105 //get hit channel
106 const int32_t channel = par.fChanPar.size() / 2 + floor(hitPos.X() / trafoCell.sizeX);
107
108 // D.Smith 15.8.23: This channel correction doesn't seem to be needed
109 // if (channel < 0) channel = 0;
110 // if (channel > par.fChanPar.size() - 1) channel = par.fChanPar.size() - 1;
111 address = par.fChanPar[channel].address;
112
113 //Calibrate hit time if applicable
114 if (par.fCPTOffYRange != 0) {
115 const double dBin = (hitPos.Y() + par.fCPTOffYRange) / par.fCPTOffYBinWidth;
116 const int i1 = floor(dBin);
117 const int i2 = ceil(dBin);
118 hitTime -= par.fCPTOffY[i1] + (dBin - i1) * (par.fCPTOffY[i2] - par.fCPTOffY[i1]);
119 }
120
121 //get offset by rotation to master frame. get hit position by adding offset to cell coordinates
122 hitPos = trafoCell.pos + trafoCell.rotation(hitPos);
123
124 // Simple errors, not properly done at all for now
125 // Right way of doing it should take into account the weight distribution
126 // and real system time resolution
127 hitPosErr = ROOT::Math::XYZVector(0.5, 0.5, 0.5);
128 }
129
130 template<class Archive>
131 void serialize(Archive& ar, unsigned int /*version*/)
132 {
133 ar& hitPos;
134 ar& hitPosErr;
135 ar& hitTime;
136 ar& hitTimeErr;
137 ar& address;
138 ar& numchan;
139 ar& weightsSum;
140 }
141 };
142
143} // namespace cbm::algo::tof
Serializer for SIMD vectors.
void load(Archive &ar, ROOT::Math::XYZVector &val, const unsigned int)
void serialize(Archive &ar, ROOT::Math::XYZVector &val, const unsigned int version)
void save(Archive &ar, const ROOT::Math::XYZVector &val, const unsigned int)
std::uint32_t u32
Definition Definitions.h:21
std::vector< ClusterizerChanPar > fChanPar
void finalize(const TofCell &trafoCell, const ClusterizerRpcPar &par)
int32_t numChan() const
ROOT::Math::XYZVector hitPos
ROOT::Math::XYZVector hitPosErr
void add(ROOT::Math::XYZVector pos, double time, double timeErr, double weight)
void normalize(double timeErr)
void serialize(Archive &ar, unsigned int)
ROOT::Math::XYZVector pos
ROOT::Math::Rotation3D rotation