CbmRoot
LitHitData.h
Go to the documentation of this file.
1 
8 #ifndef LITHITDATA_H_
9 #define LITHITDATA_H_
10 
11 #include "LitScalPixelHit.h"
12 #include "LitScalStripHit.h"
13 
14 #include <cassert>
15 #include <cmath>
16 #include <set>
17 #include <sstream>
18 #include <vector>
19 using std::endl;
20 using std::max;
21 using std::ostream;
22 using std::set;
23 using std::string;
24 using std::stringstream;
25 using std::vector;
26 
27 namespace lit {
28  namespace parallel {
29 
36  class LitHitData {
37  public:
42  : fHits()
43  , fMaxErrX()
44  , fMaxErrY()
45  , fNofStations(0)
46  , fZPosSet()
47  , fZPosBins() {}
48 
52  virtual ~LitHitData() {}
53 
58  void SetNofStations(unsigned char nofStations) {
59  fNofStations = nofStations;
60  fHits.resize(nofStations);
61  fMaxErrX.resize(nofStations);
62  fMaxErrY.resize(nofStations);
63  fZPosSet.resize(nofStations);
64  fZPosBins.resize(nofStations);
65  for (unsigned char i = 0; i < nofStations; i++) {
66  fHits[i].reserve(1500);
67  }
68  }
69 
75  void AddHit(LitScalPixelHit* hit) {
76  unsigned char station = hit->stationId;
77  assert(station < fNofStations);
78  fHits[station].push_back(hit);
79  fZPosSet[station].insert(hit->Z); // Find different Z positions of hits
80  fMaxErrX[station] = max(hit->Dx, fMaxErrX[station]);
81  fMaxErrY[station] = max(hit->Dy, fMaxErrY[station]);
82  }
83 
90  const LitScalPixelHit* GetHit(unsigned char station,
91  unsigned int hitId) const {
92  return fHits[station][hitId];
93  }
94 
100  const vector<LitScalPixelHit*>& GetHits(unsigned char station) {
101  return fHits[station];
102  }
103 
109  unsigned int GetNofHits(unsigned char station) const {
110  return fHits[station].size();
111  }
112 
118  fscal GetMaxErrX(unsigned char station) const {
119  return fMaxErrX[station];
120  }
121 
127  fscal GetMaxErrY(unsigned char station) const {
128  return fMaxErrY[station];
129  }
130 
131  const vector<int>& GetZPosBins(unsigned char station) const {
132  return fZPosBins[station];
133  }
134 
135  fscal GetZPosByBin(unsigned char station, int bin) const {
136  return GetMinZPos(station) + bin * EPSILON;
137  }
138 
139  int GetBinByZPos(unsigned char station, fscal zPos) const {
140  return (zPos - GetMinZPos(station)) / EPSILON;
141  }
142 
143  fscal GetMinZPos(unsigned char station) const {
144  return (fZPosSet[station].empty()) ? 0. : *fZPosSet[station].begin();
145  }
146 
150  void Clear() {
151  for (unsigned int i = 0; i < fNofStations; i++) {
152  fHits[i].clear();
153  fHits[i].reserve(1500);
154  fMaxErrX[i] = 0.;
155  fMaxErrY[i] = 0.;
156  fZPosSet[i].clear();
157  fZPosBins[i].clear();
158  }
159  }
160 
164  void Arrange() {
165  for (int iStation = 0; iStation < fNofStations; iStation++) {
166  if (fZPosSet[iStation].empty()) continue;
167  fscal minZ = *fZPosSet[iStation].begin();
168  // fscal maxZ = *fZPosSet[iStation].rbegin();
169  set<int> binSet;
170  set<fscal>::const_iterator it;
171  for (it = fZPosSet[iStation].begin(); it != fZPosSet[iStation].end();
172  it++) {
173  fscal z = *it;
174  int bin = (z - minZ) / EPSILON;
175  binSet.insert(bin);
176  }
177 
178  set<int>::const_iterator it2;
179  for (it2 = binSet.begin(); it2 != binSet.end(); it2++) {
180  int bin = *it2;
181  // fscal z = minZ + bin * EPSILON;
182  // fZPos[iStation].push_back(z);
183  fZPosBins[iStation].push_back(bin);
184  }
185  }
186  }
187 
192  string ToString() const {
193  stringstream ss;
194  ss << "LitHitData:" << endl;
195  for (unsigned int i = 0; i < fHits.size(); i++) {
196  ss << " station " << i << ": " << GetNofHits(i) << " hits, "
197  << "maxerrx=" << GetMaxErrX(i) << ", maxerry=" << GetMaxErrY(i)
198  << ", ";
199  ss << "zposset=(";
200  for (set<fscal>::const_iterator it = fZPosSet[i].begin();
201  it != fZPosSet[i].end();
202  it++) {
203  ss << *it << ", ";
204  }
205  ss << ")" << endl;
206  ss << "zposbins=(";
207  for (vector<int>::const_iterator it = fZPosBins[i].begin();
208  it != fZPosBins[i].end();
209  it++) {
210  ss << "|" << *it << "," << GetZPosByBin(i, *it) << "| ";
211  }
212  ss << ")" << endl;
213  }
214  return ss.str();
215  }
216 
221  friend ostream& operator<<(ostream& strm, const LitHitData& hitData) {
222  strm << hitData.ToString();
223  return strm;
224  }
225 
226  private:
227  static const fscal EPSILON;
228  vector<vector<LitScalPixelHit*>> fHits; // Array of hits
229  vector<fscal> fMaxErrX; // Array of maximum X error for each station
230  vector<fscal> fMaxErrY; // Array of maximum Y error for each station
231  unsigned char fNofStations; // Number of stations
232  vector<set<fscal>>
233  fZPosSet; // Set of Z positions of hits in each station
234  // Temporarily used for Z different Z positions calculation
235  vector<vector<int>>
236  fZPosBins; // Array of Z positions bin number of hits in each station
237  } _fvecalignment;
238 
239  } // namespace parallel
240 } // namespace lit
241 
242 #endif /* LITHITDATA_H_ */
fscal
float fscal
Definition: L1/vectors/P4_F32vec4.h:250
lit::parallel::LitScalPixelHit
Base class for scalar pixel hits.
Definition: LitScalPixelHit.h:31
lit::parallel::LitHitData::ToString
string ToString() const
Returns string representation of the class.
Definition: LitHitData.h:192
lit::parallel::LitHitData::GetZPosByBin
fscal GetZPosByBin(unsigned char station, int bin) const
Definition: LitHitData.h:135
lit::parallel::LitHitData::fZPosSet
vector< set< fscal > > fZPosSet
Definition: LitHitData.h:233
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
lit::parallel::_fvecalignment
class lit::parallel::LitDetectorLayout _fvecalignment
lit::parallel::LitHitData::GetBinByZPos
int GetBinByZPos(unsigned char station, fscal zPos) const
Definition: LitHitData.h:139
lit::parallel::LitHitData::fNofStations
unsigned char fNofStations
Definition: LitHitData.h:231
lit::parallel::LitHitData::GetMaxErrY
fscal GetMaxErrY(unsigned char station) const
Return maximum Y error in [cm] for specified station.
Definition: LitHitData.h:127
lit::parallel::LitScalPixelHit::Z
fscal Z
Definition: LitScalPixelHit.h:78
lit::parallel::LitHitData::fZPosBins
vector< vector< int > > fZPosBins
Definition: LitHitData.h:236
lit::parallel::LitHitData::GetNofHits
unsigned int GetNofHits(unsigned char station) const
Return number of hits for specified station.
Definition: LitHitData.h:109
lit::parallel::LitHitData::AddHit
void AddHit(LitScalPixelHit *hit)
Add hit.
Definition: LitHitData.h:75
lit::parallel::LitHitData::GetHit
const LitScalPixelHit * GetHit(unsigned char station, unsigned int hitId) const
Return hit pointer.
Definition: LitHitData.h:90
lit::parallel::LitHitData::GetZPosBins
const vector< int > & GetZPosBins(unsigned char station) const
Definition: LitHitData.h:131
lit::parallel::LitHitData::fHits
vector< vector< LitScalPixelHit * > > fHits
Definition: LitHitData.h:228
lit::parallel::LitHitData
Class for accessing hits in track reconstruction.
Definition: LitHitData.h:36
lit::parallel::LitHitData::fMaxErrX
vector< fscal > fMaxErrX
Definition: LitHitData.h:229
lit::parallel::LitHitData::SetNofStations
void SetNofStations(unsigned char nofStations)
Set number of stations.
Definition: LitHitData.h:58
lit::parallel::LitScalPixelHit::Dx
fscal Dx
Definition: LitScalPixelHit.h:74
lit::parallel::LitHitData::GetHits
const vector< LitScalPixelHit * > & GetHits(unsigned char station)
Return vector of hits.
Definition: LitHitData.h:100
lit::parallel::LitHitData::LitHitData
LitHitData()
Constructor.
Definition: LitHitData.h:41
lit::parallel::LitHitData::GetMaxErrX
fscal GetMaxErrX(unsigned char station) const
Return maximum X error in [cm] for specified station.
Definition: LitHitData.h:118
lit::parallel::LitScalPixelHit::Dy
fscal Dy
Definition: LitScalPixelHit.h:74
lit::parallel::LitHitData::Clear
void Clear()
Clear hit arrays.
Definition: LitHitData.h:150
LitScalPixelHit.h
Base class for scalar pixel hits.
lit::parallel::LitHitData::~LitHitData
virtual ~LitHitData()
Destructor.
Definition: LitHitData.h:52
lit::parallel::LitHitData::fMaxErrY
vector< fscal > fMaxErrY
Definition: LitHitData.h:230
LitScalStripHit.h
Base class for scalar strip hits.
lit::parallel::LitScalPixelHit::stationId
unsigned char stationId
Definition: LitScalPixelHit.h:76
lit::parallel::LitHitData::Arrange
void Arrange()
Must be called after all hits are added.
Definition: LitHitData.h:164
lit::parallel::LitHitData::GetMinZPos
fscal GetMinZPos(unsigned char station) const
Definition: LitHitData.h:143
lit::parallel::LitHitData::operator<<
friend ostream & operator<<(ostream &strm, const LitHitData &hitData)
Operator << for convenient output to ostream.
Definition: LitHitData.h:221
lit::parallel::LitHitData::EPSILON
static const fscal EPSILON
Definition: LitHitData.h:227
max
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: L1/vectors/P4_F32vec4.h:36
lit
Definition: LitTrackFinderNNVecElectron.h:19