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 double X() const { return hitPos.X(); }
57 double Y() const { return hitPos.Y(); }
58 double Z() const { return hitPos.Z(); }
59 double Time() const { return hitTime; }
60 double Dx() const { return hitPosErr.X(); }
61 double Dy() const { return hitPosErr.Y(); }
62 double TimeError() const { return hitTimeErr; }
63
64 // Interface end
65
66 int32_t numChan() const { return numchan; }
67
68 void reset()
69 {
70 hitPos = ROOT::Math::XYZVector(0.0, 0.0, 0.0);
71 hitPosErr = ROOT::Math::XYZVector(0.0, 0.0, 0.0);
72 hitTime = 0.0;
73 hitTimeErr = 0.0;
74 weightsSum = 0.0;
75 address = 0;
76 numchan = 0;
77 }
78
79 void add(ROOT::Math::XYZVector pos, double time, double timeErr, double weight)
80 {
81 hitPos += pos * weight;
82 hitTime += time * weight;
83 hitTimeErr += timeErr * weight;
84 weightsSum += weight;
85 numchan++;
86 }
87
88 void normalize(double timeErr)
89 {
90 // a/=b is translated to a := a*(1/b) in the ROOT::Math::XYZVector class, which has a different
91 // rounding behavior than a := (a/b). In rare cases this leads to 1.000... becoming 0.999... inside
92 // the floor() operation in the finalize() function of this class, and results in a different
93 // channel being associated with the cluster. To reproduce the output of the old hit finder, we
94 // divide element-wise instead. Perhaps floor() should be replaced by round().
96
97 hitPos.SetXYZ(hitPos.X() / weightsSum, hitPos.Y() / weightsSum, hitPos.Z() / weightsSum);
99 hitTimeErr = timeErr;
100 }
101
102 void finalize(const TofCell& trafoCell, const ClusterizerRpcPar& par)
103 {
104 //get hit channel
105 const int32_t channel = par.fChanPar.size() / 2 + floor(hitPos.X() / trafoCell.sizeX);
106
107 // D.Smith 15.8.23: This channel correction doesn't seem to be needed
108 // if (channel < 0) channel = 0;
109 // if (channel > par.fChanPar.size() - 1) channel = par.fChanPar.size() - 1;
110 address = par.fChanPar[channel].address;
111
112 //Calibrate hit time if applicable
113 if (par.fCPTOffYRange != 0) {
114 const double dBin = (hitPos.Y() + par.fCPTOffYRange) / par.fCPTOffYBinWidth;
115 const int i1 = floor(dBin);
116 const int i2 = ceil(dBin);
117 hitTime -= par.fCPTOffY[i1] + (dBin - i1) * (par.fCPTOffY[i2] - par.fCPTOffY[i1]);
118 }
119
120 //get offset by rotation to master frame. get hit position by adding offset to cell coordinates
121 hitPos = trafoCell.pos + trafoCell.rotation(hitPos);
122
123 // Simple errors, not properly done at all for now
124 // Right way of doing it should take into account the weight distribution
125 // and real system time resolution
126 hitPosErr = ROOT::Math::XYZVector(0.5, 0.5, 0.5);
127 }
128
129 template<class Archive>
130 void serialize(Archive& ar, unsigned int /*version*/)
131 {
132 ar& hitPos;
133 ar& hitPosErr;
134 ar& hitTime;
135 ar& hitTimeErr;
136 ar& address;
137 ar& numchan;
138 ar& weightsSum;
139 }
140 };
141
142} // 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::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)
double TimeError() const
void normalize(double timeErr)
void serialize(Archive &ar, unsigned int)
ROOT::Math::XYZVector pos
ROOT::Math::Rotation3D rotation