CbmRoot
Loading...
Searching...
No Matches
tof/HitFinder.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 */
4
5/*
6 This algo was based on CbmTofSimpClusterizer, which can be used only for simulation of the main setup and
7 is as the name implies a simplified solution.
8 A later step will be the replacement with a version based on CbmTofEventClusterizer, which is the version
9 currently maintained, based on what we learned from real data at mCBM.
10 This step will be required to apply the algo to real/online data and to prepare
11 our simulations for first CBM beam
12*/
13
14#ifndef CBM_ALGO_TOF_HITFINDER_H
15#define CBM_ALGO_TOF_HITFINDER_H
16
17// TOF Classes and includes
18class CbmTofDigi;
19
20// ROOT Classes and includes
21#include "Math/Rotation3D.h"
22#include "Math/Vector3Dfwd.h"
23
24// C++ Classes and includes
25#include <cmath>
26#include <memory>
27#include <vector>
28
29namespace cbm::algo::tof
30{
31 struct Cell {
32 double sizeX, sizeY;
33 ROOT::Math::XYZVector pos;
34 ROOT::Math::Rotation3D rotation;
35 };
36
38 std::vector<double> fvCPTOff; //[nbSide]
39 std::vector<double> fvCPTotGain; //[nbSide]
40 std::vector<std::vector<double>> fvCPWalk; //[nbSide][nbWalkBins]
41 int32_t address; //unique address
43 };
44
46 double FeeTimeRes;
47 double SysTimeRes;
50 double TOTMax;
51 double TOTMin;
54 double gapSize;
55 int32_t numGaps;
57 std::vector<HitFinderChanPar> fChanPar = {};
58 };
59
60 struct Cluster {
61 //temporary values
62 std::vector<int32_t> vDigiIndRef;
63 ROOT::Math::XYZVector weightedPos = ROOT::Math::XYZVector(0.0, 0.0, 0.0);
64 double weightedTime = 0.0;
65 double weightedTimeErr = 0.0;
66 double weightsSum = 0.0;
67
68 //after finalization
69 ROOT::Math::XYZVector globalPos = ROOT::Math::XYZVector(0.0, 0.0, 0.0);
70 ROOT::Math::XYZVector globalErr = ROOT::Math::XYZVector(0.0, 0.0, 0.0);
71 int32_t channel = 0;
72 int32_t detId = 0;
73
74 int32_t numChan() { return vDigiIndRef.size() / 2; }
75
76 void reset()
77 {
78 vDigiIndRef.clear();
79 weightedPos = ROOT::Math::XYZVector(0.0, 0.0, 0.0);
80 globalPos = ROOT::Math::XYZVector(0.0, 0.0, 0.0);
81 globalErr = ROOT::Math::XYZVector(0.0, 0.0, 0.0);
82 weightedTime = 0.0;
83 weightedTimeErr = 0.0;
84 weightsSum = 0.0;
85 channel = 0;
86 detId = 0;
87 }
88
89 void add(ROOT::Math::XYZVector pos, double time, double timeErr, double weight, int32_t digiIndA, int32_t digiIndB)
90 {
91 vDigiIndRef.push_back(digiIndA);
92 vDigiIndRef.push_back(digiIndB);
93 weightedPos += pos * weight;
94 weightedTime += time * weight;
95 weightedTimeErr += timeErr * weight;
96 weightsSum += weight;
97 }
98
99 void normalize(double timeErr)
100 {
101 // a/=b is translated to a := a*(1/b) in the ROOT::Math::XYZVector class, which has a different
102 // rounding behavior than a := (a/b). In rare cases this leads to 1.000... becoming 0.999... inside
103 // the floor() operation in the finalize() function of this class, and results in a different
104 // channel being associated with the cluster. To reproduce the output of the old hit finder, we
105 // divide element-wise instead. Perhaps floor() should be replaced by round().
107
110 weightedTimeErr = timeErr;
111 }
112
113 void finalize(const Cell& trafoCell, const int32_t iTrafoCell, const HitFinderRpcPar& par)
114 {
115 // prepare local->global trafo
116 ROOT::Math::Rotation3D rotMatrix = trafoCell.rotation;
117
118 // get offset from weighted cluster position by rotation to master frame
119 ROOT::Math::XYZVector hitposOffset = rotMatrix(weightedPos);
120
121 //get hit position by adding offset to cell coordinates
122 globalPos = trafoCell.pos + hitposOffset;
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 ROOT::Math::XYZVector hitErrLocal;
128 hitErrLocal.SetX(trafoCell.sizeX / std::sqrt(12.0)); // Single strips approximation
129 hitErrLocal.SetY(par.FeeTimeRes * par.CPSigPropSpeed); // Use the electronics resolution
130 hitErrLocal.SetZ(par.numGaps * par.gapSize / 10.0 // Change gap size in cm
131 / std::sqrt(12.0)); // Use full RPC thickness as "Channel" Z size
132
133 //store results
134 globalErr = rotMatrix(hitErrLocal);
135 channel = iTrafoCell + floor(weightedPos.X() / trafoCell.sizeX);
136 detId = par.fChanPar[channel].address;
138 }
139 };
140
141 class HitFinder {
142 public:
143 typedef std::vector<Cluster> resultType;
144 typedef std::pair<std::vector<std::vector<CbmTofDigi*>>, std::vector<std::vector<int32_t>>> inputType;
145
150
155
159 resultType operator()(std::vector<CbmTofDigi> digisIn, const std::vector<int32_t>& digiIndexIn);
160
164 void SetParams(std::unique_ptr<HitFinderRpcPar> params) { fParams = *(std::move(params)); }
165
166 private:
168
169 inputType calibrateDigis(std::vector<CbmTofDigi>& digisIn, const std::vector<int32_t>& digiIndexIn);
171
172 int32_t numSameSide; // Digis quality
173 };
174
175} // namespace cbm::algo::tof
176
177#endif // CBM_ALGO_TOF_HITFINDER_H
Data class for expanded digital TOF information.
Definition CbmTofDigi.h:47
resultType buildClusters(inputType &input)
inputType calibrateDigis(std::vector< CbmTofDigi > &digisIn, const std::vector< int32_t > &digiIndexIn)
HitFinderRpcPar fParams
Parameter container.
resultType operator()(std::vector< CbmTofDigi > digisIn, const std::vector< int32_t > &digiIndexIn)
Build clusters out of ToF Digis and store the resulting info in a TofHit.
std::pair< std::vector< std::vector< CbmTofDigi * > >, std::vector< std::vector< int32_t > > > inputType
void SetParams(std::unique_ptr< HitFinderRpcPar > params)
Set the parameter container.
std::vector< Cluster > resultType
ROOT::Math::Rotation3D rotation
ROOT::Math::XYZVector pos
ROOT::Math::XYZVector globalErr
void add(ROOT::Math::XYZVector pos, double time, double timeErr, double weight, int32_t digiIndA, int32_t digiIndB)
void finalize(const Cell &trafoCell, const int32_t iTrafoCell, const HitFinderRpcPar &par)
void normalize(double timeErr)
std::vector< int32_t > vDigiIndRef
ROOT::Math::XYZVector weightedPos
ROOT::Math::XYZVector globalPos
std::vector< double > fvCPTotGain
std::vector< std::vector< double > > fvCPWalk
std::vector< double > fvCPTOff
std::vector< HitFinderChanPar > fChanPar