FairRoot/PandaRoot
FTSCAStationArray.h
Go to the documentation of this file.
1  //-*- Mode: C++ -*-
2  // *****************************************************************************
3  // *
4  // @Autors: I.Kulakov; M.Pugach; M.Zyzak; I.Kisel *
5  // @e-mail: I.Kulakov@gsi.de; M.Pugach@gsi.de; M.Zyzak@gsi.de; I.Kisel@compeng.uni-frankfurt.de *
6  // *
7  // *****************************************************************************
8 
9 #ifndef FTSCASTATIONARRAY_H
10 #define FTSCASTATIONARRAY_H
11 
12 #include <iostream>
13 using std::cout;
14 
15 #include <vector>
16 using std::vector;
17 
18 #include "FTSCAHits.h"
19 #include "FTSCATES.h"
20 
21 
22 template< typename T >
23 class FTSCAElementsOnStation: public vector<T> {
24 
25  //* Properties of elements on station
26 
27  public:
30 
31  void SetStation( char s ) { fISta = s; fFirstElementIByHit0.resize((*fHitsRef)[s].size() + 1, -1); }
32 
33  const char& IStation() const { return fISta; }
34 
35  const FTSCAHit& GetHit( int iV, int IH, int i ) const {
36  return (*fHitsRef)[ (*this)[i].IHit(IH)[iV] ];
37  }
38 
39  const FTSCAHit& GetHit( int IH, int i ) const {
40  return (*fHitsRef)[ (*this)[i].IHit(IH) ];
41  }
42 
43  int FirstElementIByHit0( int iH ) const { return fFirstElementIByHit0[iH]; }
44  vector<int>& FirstElementIByHit0() { return fFirstElementIByHit0; }
45 
46  const FTSCAHits* HitsRef() const { return fHitsRef; }
47 
48  FTSCAElementsOnStation<T>& operator=( const FTSCAElementsOnStation<T>& a ) { // do not copy fHitsRef
49  vector<T>::operator=( a );
50  fHitsRef = (a.fHitsRef == 0 ) ? fHitsRef : a.fHitsRef; // copy only of set
51  fISta = (a.fISta == -1 ) ? fISta : a.fISta;
53  return *this;
54  }
55 
57  if (a.size() <= 0) return *this;
59  const FTSCAElementsOnStation<T> &b = *this;
60  const vector<int> &bf = fFirstElementIByHit0;
61 
62  assert( a.fFirstElementIByHit0.size() == bf.size() );
63  r.SetStation(fISta);
64 
65  // find size
66  unsigned int n = 0;
67  for( unsigned int i = 0; i < a.fFirstElementIByHit0.size() - 1; i++ ) {
68  if ( a.fFirstElementIByHit0[i] >= 0 )
69  for( int e = a.fFirstElementIByHit0[i]; e < a.fFirstElementIByHit0[i+1]; e++ ) {
70  n++;
71  }
72  if ( bf[i] >= 0 )
73  for( int e = bf[i]; e < bf[i+1]; e++ ) {
74  n++;
75  }
76  }
77  const T sample( a[0].N() );
78  r.resize( (n-1)/float_v::Size + 1, sample );
79 
80  // copy by hits
81  n = 0;
82  for( unsigned int i = 0; i < a.fFirstElementIByHit0.size()-1; i++ ) {
84  r.fFirstElementIByHit0[i+1] = n;
85  if ( a.fFirstElementIByHit0[i] >= 0 )
86  for( int e = a.fFirstElementIByHit0[i]; e < a.fFirstElementIByHit0[i+1]; e++ ) {
87  const int nV = e/float_v::Size;
88  const int iV = e%float_v::Size;
89  if ( !a[nV].IsValid()[iV] ) continue;
90 
91  const int nVt = n/float_v::Size;
92  const int iVt = n%float_v::Size;
93  r[nVt].CopyOne( iVt, a[nV], iV );
94  n++;
95  }
96  if ( bf[i] >= 0 )
97  for( int e = bf[i]; e < bf[i+1]; e++ ) {
98  const int nV = e/float_v::Size;
99  const int iV = e%float_v::Size;
100  if ( !b[nV].IsValid()[iV] ) continue;
101 
102  const int nVt = n/float_v::Size;
103  const int iVt = n%float_v::Size;
104  r[nVt].CopyOne( iVt, b[nV], iV );
105  n++;
106  }
107  r.fFirstElementIByHit0[i+1] = n;
108  }
109 
110  return r;
111  }
112 
113 // private:
115  char fISta;
116  vector<int> fFirstElementIByHit0;
117 };
118 
119 template< typename T >
121  public:
122  FTSCAElementsOnStation<T>& OnStation(char i) { assert((unsigned char)i<fElement.size() ); return fElement[i]; }
123  const FTSCAElementsOnStation<T>& OnStation(char i) const { assert((unsigned char)i<fElement.size() ); return fElement[i]; }
124  FTSCAElementsOnStation<T>& operator[](char i) { assert((unsigned char)i<fElement.size() ); return fElement[i]; }
125  const FTSCAElementsOnStation<T>& operator[](char i) const { assert((unsigned char)i<fElement.size() ); return fElement[i]; }
126 
128 
129  FTSCAStationArray( int nSta, const FTSCAHits* hits ){
130  Renew( nSta, hits );
131  }
132 
133  void Renew( int nSta, const FTSCAHits* hits ){
134  fElement.clear();
135  fElement.resize( nSta, FTSCAElementsOnStation<T>( hits ) );
136  for( int i = 0; i < nSta; ++i )
137  fElement[i].SetStation( i );
138  }
139 
140  char NStations() const { return fElement.size(); }
141 
142  const FTSCAHits* HitsRef() const {
143  if ( fElement.size() ) return fElement[0].fHitsRef;
144  else return 0;
145  }
146 
147  unsigned int Size() const {
148  unsigned int s = 0;
149  for( int i = 0; i < NStations(); ++i )
150  s += fElement[i].size();
151  return s;
152  }
153 
154  T& operator[]( TES i ) { return fElement[i.s][i.e]; }
155  const T& operator[]( TES i ) const { return fElement[i.s][i.e]; }
156 
157  void Add( const T& hit ) {
158  const int iSta = hit.Station();
159  fElement[iSta].push_back( hit );
160  }
161 
162  protected:
163  vector< FTSCAElementsOnStation<T> > fElement; // hits on stations
164 
165 };
166 
167 
168 #endif
const T & operator[](TES i) const
void Add(const T &hit)
double r
Definition: RiemannTest.C:14
FTSCAElementsOnStation< T > & operator[](char i)
Int_t i
Definition: run_full.C:25
TTree * b
const FTSCAElementsOnStation< T > & operator[](char i) const
FTSCAElementsOnStation< T > operator+(const FTSCAElementsOnStation< T > &a)
const FTSCAElementsOnStation< T > & OnStation(char i) const
TLorentzVector s
Definition: Pnd2DStar.C:50
int n
const FTSCAHit & GetHit(int IH, int i) const
FTSCAElementsOnStation< T > & operator=(const FTSCAElementsOnStation< T > &a)
TTree * T
Definition: anaLmdReco.C:32
vector< FTSCAElementsOnStation< T > > fElement
const FTSCAHit & GetHit(int iV, int IH, int i) const
Int_t a
Definition: anaLmdDigi.C:126
FTSCAElementsOnStation(const FTSCAHits *hits)
vector< int > fFirstElementIByHit0
const FTSCAHits * fHitsRef
char NStations() const
FTSCAElementsOnStation< T > & OnStation(char i)
FTSCAStationArray(int nSta, const FTSCAHits *hits)
int FirstElementIByHit0(int iH) const
vector< int > & FirstElementIByHit0()
const FTSCAHits * HitsRef() const
unsigned int Size() const
char s
Definition: FTSCATES.h:24
int hit(Int_t nEvents=0, TString inFile="sim.root", TString parFile="par.root", TString inDigi="digi.root", TString outFile="hit.root", Int_t timeBased=0)
Definition: hit.C:1
const FTSCAHits * HitsRef() const
void Renew(int nSta, const FTSCAHits *hits)
CbmHit * hits[nHits]
Definition: RiemannTest.C:19
unsigned int e
Definition: FTSCATES.h:25
Definition: FTSCATES.h:13
const char & IStation() const