CbmRoot
CbmTrdDigi.cxx
Go to the documentation of this file.
1 #include "CbmTrdDigi.h"
2 
3 #include "CbmTrdAddress.h" // for CbmTrdAddress
4 
5 #include <FairLogger.h> // for LOG
6 
7 #include <TMath.h> // for Ceil
8 
9 #include <iomanip> // for operator<<, setprecision, setw
10 #include <sstream> // for operator<<, basic_ostream, stringstream
11 #include <string> // for char_traits
12 
13 using std::endl;
14 using std::string;
15 using std::stringstream;
16 
27 Double_t CbmTrdDigi::fgClk[] = {62.5, 12.5};
28 Float_t CbmTrdDigi::fgPrecission[] = {1.e3, 1.};
29 //__________________________________________________________________________________________
30 CbmTrdDigi::CbmTrdDigi() : fInfo(0), fCharge(0), fTime(0) {}
31 //__________________________________________________________________________________________
32 CbmTrdDigi::CbmTrdDigi(Int_t padChNr,
33  Float_t chargeT,
34  Float_t chargeR,
35  ULong64_t time)
36  : fInfo(0), fCharge(0.), fTime(time) {
47  SetAsic(kFASP);
48  SetChannel(padChNr);
49  SetCharge(chargeT, chargeR);
50 }
51 
52 //__________________________________________________________________________________________
53 CbmTrdDigi::CbmTrdDigi(Int_t padChNr,
54  Int_t uniqueModuleId,
55  Float_t charge,
56  ULong64_t time,
57  Int_t triggerType,
58  Int_t errClass)
59  : fInfo(0), fCharge(0.), fTime(time) {
71  SetChannel(padChNr);
72  SetAddress(uniqueModuleId);
73  SetCharge(charge);
74  SetTriggerType(triggerType);
75  SetErrorClass(errClass);
76 }
77 
78 //__________________________________________________________________________________________
79 void CbmTrdDigi::AddCharge(CbmTrdDigi* sd, Double_t f) {
80  if (GetType() != kFASP) {
81  LOG(warn)
82  << "CbmTrdDigi::AddCharge(CbmTrdDigi*, Double_t) : Only available for "
83  "FASP. Use AddCharge(Double_t, Double_t) instead.";
84  return;
85  }
86  Char_t dt = fCharge >> 24, dts = sd->fCharge >> 24;
87  UInt_t t = ((fCharge & 0xfff000) >> 12), r = (fCharge & 0xfff),
88  ts = ((sd->fCharge & 0xfff000) >> 12), rs = (sd->fCharge & 0xfff);
89  // apply correction factor to charge
90  Float_t tsf = f * ts / fgPrecission[kFASP],
91  rsf = f * rs / fgPrecission[kFASP];
92  ts = tsf * fgPrecission[kFASP];
93  rs = rsf * fgPrecission[kFASP];
94 
95  if (t + ts < 0xfff)
96  t += ts;
97  else
98  t = 0xfff;
99  if (r + rs < 0xfff)
100  r += rs;
101  else
102  r = 0xfff;
103  dt += dts;
104  fCharge = r | (t << 12);
105  fCharge |= dt << 24;
106 }
107 
108 //__________________________________________________________________________________________
109 void CbmTrdDigi::AddCharge(Double_t c, Double_t f) {
110  if (GetType() != kSPADIC) {
111  LOG(warn) << "CbmTrdDigi::AddCharge(Double_t, Double_t) : Only available "
112  "for SPADIC. Use AddCharge(CbmTrdDigi*, Double_t) instead.";
113  return;
114  }
115  SetCharge(GetCharge() + f * c);
116 }
117 
118 //__________________________________________________________________________________________
122  return (fInfo >> fgkRoOffset) & 0xfff;
123 }
124 
125 //__________________________________________________________________________________________
129  return CbmTrdAddress::GetAddress(Layer(), Module(), 0, 0, 0);
130 }
131 
132 //__________________________________________________________________________________________
133 Double_t CbmTrdDigi::GetCharge() const {
134  if (GetType() != kSPADIC) {
135  LOG(warn) << "CbmTrdDigi::GetCharge() : Use Double_t GetCharge(Double_t "
136  "&tilt) instead.";
137  return 0;
138  }
139  return fCharge / fgPrecission[kSPADIC];
140 }
141 
142 //__________________________________________________________________________________________
143 Double_t CbmTrdDigi::GetCharge(Double_t& tilt, Int_t& dt) const {
150  if (GetType() != kFASP) {
151  LOG(warn) << "CbmTrdDigi::GetCharge(Double_t &) : Use Double_t GetCharge() "
152  "instead.";
153  return 0;
154  }
155  Char_t toff = fCharge >> 24;
156  dt = toff;
157  tilt = ((fCharge & 0xfff000) >> 12) / fgPrecission[kFASP];
158  return (fCharge & 0xfff) / fgPrecission[kFASP];
159 }
160 
161 //__________________________________________________________________________________________
162 Double_t CbmTrdDigi::GetChargeError() const { return 0; }
163 
164 //__________________________________________________________________________________________
165 Bool_t CbmTrdDigi::IsFlagged(const Int_t iflag) const {
166  if (iflag < 0 || iflag >= kNflags) return kFALSE;
167  return (fInfo >> (fgkFlgOffset + iflag)) & 0x1;
168 }
169 
170 //__________________________________________________________________________________________
171 void CbmTrdDigi::SetAddress(Int_t address) {
174 }
175 
176 //__________________________________________________________________________________________
178  if (ty == kSPADIC)
179  CLRBIT(fInfo, fgkTypOffset);
180  else
181  SETBIT(fInfo, fgkTypOffset);
182 }
183 
184 //__________________________________________________________________________________________
185 void CbmTrdDigi::SetCharge(Float_t cT, Float_t cR, Int_t dt) {
192  UInt_t r = UInt_t(cR * fgPrecission[kFASP]),
193  t = UInt_t(cT * fgPrecission[kFASP]);
194  Char_t toff = dt;
195  if (dt > 127)
196  toff = 127;
197  else if (dt < -127)
198  toff = -127;
199  if (r > 0xfff) r = 0xfff;
200  if (t > 0xfff) t = 0xfff;
201  fCharge = r | (t << 12);
202  fCharge |= toff << 24;
203 }
204 
205 //__________________________________________________________________________________________
206 void CbmTrdDigi::SetCharge(Float_t c) {
207 
208  // printf("SetCharge :: prec[%f] c[%f] uint[%d] \n", fgPrecission[kSPADIC],c,UInt_t(c*fgPrecission[kSPADIC]));
209  // std::cout<<" setcharge: "<< UInt_t(c*fgPrecission[kSPADIC])<<std::endl;
210  fCharge = UInt_t(c * fgPrecission[kSPADIC]);
211  // fCharge = UInt_t(c*1e9);
212 }
213 
214 //__________________________________________________________________________________________
215 void CbmTrdDigi::SetFlag(const Int_t iflag, Bool_t set) {
216  if (iflag < 0 || iflag >= kNflags) return;
217  if (set)
218  SETBIT(fInfo, fgkFlgOffset + iflag);
219  else
220  CLRBIT(fInfo, fgkFlgOffset + iflag);
221 }
222 
223 //__________________________________________________________________________________________
224 void CbmTrdDigi::SetTime(Double_t t) {
225  fTime = ULong64_t(TMath::Ceil(t / fgClk[GetType()]));
226 }
227 
228 //__________________________________________________________________________________________
230  if (GetType() != kFASP) return;
231  fCharge <<= 8;
232  fCharge >>= 8;
233  fCharge |= t << 24;
234 }
235 
236 //__________________________________________________________________________________________
237 void CbmTrdDigi::SetTriggerType(const Int_t ttype) {
238  if (ttype < kBeginTriggerTypes || ttype >= kNTrg) return;
239  fInfo |= (ttype << fgkTrgOffset);
240 }
241 
242 //__________________________________________________________________________________________
243 string CbmTrdDigi::ToString() const {
244  stringstream ss;
245  ss << "CbmTrdDigi(" << (GetType() == kFASP ? "T)" : "R)")
246  << " | moduleAddress=" << GetAddressModule() << " | layer=" << Layer()
247  << " | moduleId=" << Module() << " | pad=" << GetAddressChannel()
248  << " | time[ns]=" << std::fixed << std::setprecision(1) << GetTime();
249  if (GetType() == kFASP) {
250  Int_t trg(GetTriggerType()), dt;
251  Double_t t, r = GetCharge(t, dt);
252  Bool_t ttrg(trg & 1), rtrg((trg & 2) >> 1);
253  ss << " | pu=" << (IsPileUp() ? "y" : "n")
254  << " | mask=" << (IsMasked() ? "y" : "n") << " |charge=" << std::fixed
255  << std::setw(6) << std::setprecision(1) << t
256  << (!ttrg && t > 0 ? '*' : ' ') << "/" << r
257  << (!rtrg && r > 0 ? '*' : ' ') << "[" << dt << "]";
258  } else {
259  ss << " | charge=" << GetCharge() << " TriggerType=" << GetTriggerType()
260  << " ErrorClass=" << GetErrorClass();
261  }
262  ss << endl;
263  return ss.str();
264 }
265 
CbmTrdDigi::GetChargeError
Double_t GetChargeError() const
Charge error parametrisation. SPADIC specific see GetErrorClass()
Definition: CbmTrdDigi.cxx:162
CbmTrdDigi::fCharge
UInt_t fCharge
Definition: CbmTrdDigi.h:221
CbmTrdDigi::IsPileUp
Bool_t IsPileUp() const
Query digi pile-up (FASP only)
Definition: CbmTrdDigi.h:144
f
float f
Definition: L1/vectors/P4_F32vec4.h:24
CbmTrdAddress::GetAddress
static UInt_t GetAddress(Int_t layerId, Int_t moduleId, Int_t sectorId, Int_t rowId, Int_t columnId)
Return address from system ID, layer, module, sector, column and row IDs.
Definition: CbmTrdAddress.h:38
CbmTrdAddress.h
Helper class to convert unique channel ID back and forth.
CbmTrdDigi::SetTimeOffset
void SetTimeOffset(Char_t t)
Set time offset of rectangular to tilt pads for FASP (clk)
Definition: CbmTrdDigi.cxx:229
CbmTrdDigi::IsFlagged
Bool_t IsFlagged(const Int_t iflag) const
Query flag status (generic)
Definition: CbmTrdDigi.cxx:165
CbmTrdDigi::GetErrorClass
Int_t GetErrorClass() const
Channel status. SPADIC specific see LUT.
Definition: CbmTrdDigi.h:112
CbmTrdDigi::fgClk
static Double_t fgClk[kNTypes]
Definition: CbmTrdDigi.h:226
CbmTrdDigi::SetCharge
void SetCharge(Float_t c)
Charge setter for SPADIC ASIC.
Definition: CbmTrdDigi.cxx:206
CbmTrdDigi::fgkRoOffset
static const Int_t fgkRoOffset
Definition: CbmTrdDigi.h:230
CbmTrdDigi::GetAddressChannel
Int_t GetAddressChannel() const
Getter read-out id.
Definition: CbmTrdDigi.cxx:119
CbmTrdDigi::fTime
ULong64_t fTime
Definition: CbmTrdDigi.h:224
CbmTrdDigi::SetFlag
void SetFlag(const Int_t iflag, Bool_t set=kTRUE)
Generic flag status setter.
Definition: CbmTrdDigi.cxx:215
CbmTrdAddress::GetLayerId
static UInt_t GetLayerId(UInt_t address)
Return layer ID from address.
Definition: CbmTrdAddress.h:69
CbmTrdAddress::GetModuleId
static UInt_t GetModuleId(UInt_t address)
Return module ID from address.
Definition: CbmTrdAddress.h:78
CbmTrdDigi::kFASP
@ kFASP
Definition: CbmTrdDigi.h:16
CbmTrdDigi::AddCharge
void AddCharge(CbmTrdDigi *sd, Double_t f)
Charge addition in case of pile-up (FASP simulation only)
Definition: CbmTrdDigi.cxx:79
CbmTrdDigi::SetLayer
void SetLayer(const Int_t a)
Definition: CbmTrdDigi.h:210
CbmTrdDigi::SetAddress
void SetAddress(const Int_t a)
Module address setter for digi.
Definition: CbmTrdDigi.cxx:171
CbmTrdDigi.h
CbmTrdDigi::fgkFlgOffset
static const Int_t fgkFlgOffset
Definition: CbmTrdDigi.h:234
CbmTrdDigi::fgPrecission
static Float_t fgPrecission[kNTypes]
Definition: CbmTrdDigi.h:227
CbmTrdDigi::CbmTrdDigi
CbmTrdDigi()
Default constructor.
Definition: CbmTrdDigi.cxx:30
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmTrdDigi::kNTrg
@ kNTrg
Definition: CbmTrdDigi.h:23
CbmTrdDigi::IsMasked
Bool_t IsMasked() const
Query digi mask (FASP only)
Definition: CbmTrdDigi.h:142
CbmTrdDigi::GetType
CbmTrdAsicType GetType() const
Channel FEE SPADIC/FASP according to CbmTrdAsicType.
Definition: CbmTrdDigi.h:137
CbmTrdDigi::fgkTrgOffset
static const Int_t fgkTrgOffset
Definition: CbmTrdDigi.h:235
CbmTrdDigi::SetTriggerType
void SetTriggerType(const Int_t ttype)
Set digi trigger type (SPADIC only)
Definition: CbmTrdDigi.cxx:237
CbmTrdDigi::kSPADIC
@ kSPADIC
Definition: CbmTrdDigi.h:16
CbmTrdDigi::GetTriggerType
Int_t GetTriggerType() const
Channel trigger type. SPADIC specific see CbmTrdTriggerType.
Definition: CbmTrdDigi.h:135
CbmTrdDigi::Layer
Int_t Layer() const
Definition: CbmTrdDigi.h:147
CbmTrdDigi::fInfo
UInt_t fInfo
Definition: CbmTrdDigi.h:219
CbmTrdDigi::Module
Int_t Module() const
Definition: CbmTrdDigi.h:148
CbmTrdDigi
Definition: CbmTrdDigi.h:14
CbmTrdDigi::GetTime
Double_t GetTime() const
Getter for physical time [ns]. Accounts for clock representation of each ASIC. In SPADIC case physica...
Definition: CbmTrdDigi.h:127
CbmTrdDigi::fgkTypOffset
static const Int_t fgkTypOffset
Definition: CbmTrdDigi.h:236
CbmTrdDigi::SetModule
void SetModule(const Int_t a)
Definition: CbmTrdDigi.h:214
CbmTrdDigi::kNflags
@ kNflags
Definition: CbmTrdDigi.h:32
CbmTrdDigi::CbmTrdAsicType
CbmTrdAsicType
Definition: CbmTrdDigi.h:16
CbmTrdDigi::SetAsic
void SetAsic(CbmTrdAsicType ty=kSPADIC)
Definition: CbmTrdDigi.cxx:177
CbmTrdDigi::SetTime
void SetTime(Double_t t)
Set global digi time (ns)
Definition: CbmTrdDigi.cxx:224
CbmTrdDigi::SetChannel
void SetChannel(const Int_t a)
Definition: CbmTrdDigi.h:206
CbmTrdDigi::GetCharge
Double_t GetCharge() const
Charge getter for SPADIC.
Definition: CbmTrdDigi.cxx:133
CbmTrdDigi::SetErrorClass
void SetErrorClass(const Int_t n)
Set digi error class (SPADIC only)
Definition: CbmTrdDigi.h:187
CbmTrdDigi::GetAddressModule
Int_t GetAddressModule() const
Getter module address in the experiment.
Definition: CbmTrdDigi.cxx:126
CbmTrdDigi::ToString
std::string ToString() const
String representation of a TRD digi. Account for digi type and specific information.
Definition: CbmTrdDigi.cxx:243