HARPO  5.1.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HarpoSimElectronics.cxx
Go to the documentation of this file.
1 #include "HarpoSimElectronics.h"
2 #include "HarpoSimStrips.h"
3 #include "HarpoDccMap.h"
4 #include "HarpoConfig.h"
5 #include "HarpoDebug.h"
6 
7 #include "TMath.h"
8 #include "TRandom.h"
9 #include <iostream>
10 
11 ClassImp(HarpoSimElectronics)
12 
14 {
15 
16  fNoise = 10.;
17  // fNoiseAGET = 0.5;
18  fZeroSuppr = 5;
19 
20  fGammaPower = 3;
21  fTau = 0.120; // Shaping time [us]
22  fSamplingFreq = 50; // Sampling frequency [MHz]
23  fTimeRange = 511;
24  fTimeOffset = 0.; // trigger time in us
25 
26  fThrSat = 4096;
27  // fThrSatCh = 5e4;
28  fThrSatCh = 26600;
29  fAmpSatCh = 28900;
30  fXtalkSatCh = 0.;
31 
32  Double_t noise;
33  if ( ! gHConfig->Lookup("Sim.Noise",noise) )
34  Info("Constructor","Use default Noise %g",fNoise);
35  else
36  fNoise = noise;
37 
38  Long64_t zeroSuppr;
39  if ( ! gHConfig->Lookup("Sim.ZeroSuppr",zeroSuppr) )
40  Info("Constructor","Use default ZeroSuppr %i",fZeroSuppr);
41  else
42  fZeroSuppr = zeroSuppr;
43 
44  Double_t tau;
45  if ( ! gHConfig->Lookup("Sim.Tau",tau) )
46  Info("Constructor","Use default Tau %g",fTau);
47  else
48  fTau = tau;
49 
50  Long64_t gammaPower;
51  if ( ! gHConfig->Lookup("Sim.GammaPower",gammaPower) )
52  Info("Constructor","Use default GammaPower %d",fGammaPower);
53  else
54  fGammaPower = gammaPower;
55 
56  Double_t samplingFreq;
57  if ( ! gHConfig->Lookup("Sim.SamplingFreq",samplingFreq) )
58  Info("Constructor","Use default SamplingFreq %g",fSamplingFreq);
59  else
60  fSamplingFreq = samplingFreq;
61 
62  Long64_t timeRange;
63  if ( ! gHConfig->Lookup("Sim.TimeRange",timeRange) )
64  Info("Constructor","Use default TimeRange %i",fTimeRange);
65  else
66  fTimeRange = timeRange;
67 
68  Double_t timeOffset;
69  if ( ! gHConfig->Lookup("Sim.TimeOffset",timeOffset) )
70  Info("Constructor","Use default TimeOffset %g",fTimeOffset);
71  else
72  fTimeOffset = timeOffset;
73 
74  Double_t thrSat;
75  if ( ! gHConfig->Lookup("Sim.ThrSat",thrSat) )
76  Info("Constructor","Use default ThrSat %g",fThrSat);
77  else
78  fThrSat = thrSat;
79 
80  Double_t thrSatCh;
81  if ( ! gHConfig->Lookup("Sim.ThrSatCh",thrSatCh) )
82  Info("Constructor","Use default ThrSatCh %g",fThrSatCh);
83  else
84  fThrSatCh = thrSatCh;
85 
86  Double_t ampSatCh;
87  if ( ! gHConfig->Lookup("Sim.AmpSatCh",ampSatCh) )
88  Info("Constructor","Use default AmpSatCh %g",fAmpSatCh);
89  else
90  fAmpSatCh = ampSatCh;
91 
92  Double_t xtalkSatCh;
93  if ( ! gHConfig->Lookup("Sim.XtalkSatCh",xtalkSatCh) )
94  Info("Constructor","Use default XtalkSatCh %g",fXtalkSatCh);
95  else
96  fXtalkSatCh = xtalkSatCh;
97 
98  fPedestals[XDCC] = new HarpoPedestal();
99  fPedestals[XDCC]->SetMean(0.);
100  fPedestals[XDCC]->SetSigma(fNoise);
101  fPedestals[YDCC] = new HarpoPedestal();
102  fPedestals[YDCC]->SetMean(0.);
103  fPedestals[YDCC]->SetSigma(fNoise);
104 
105 
106  fDccMapX = new HarpoDccMap();
107  fDccMapY = new HarpoDccMap();
108  // std::cout << "Pedestals: " << fPedestals[XDCC] << std::endl;
109  fDccMapX->SetPedestals(fPedestals[XDCC]);
110  fDccMapX->SetPedestals(fPedestals[YDCC]);
111 
112 }
113 
115 {
116  // std::cout << "fDccMapX " << fDccMapX << std::endl;
117 
118  fDccMapX = new HarpoDccMap();
120  fDccMapY = new HarpoDccMap();
122 
123 }
124 
125 Int_t HarpoSimElectronics::AddCharge(Int_t plane, Int_t channel, Double_t time, Double_t charge)
126 {
127 
128  if(plane == XPLANE) return AddCharge(fDccMapX,channel,time,charge);
129  if(plane == YPLANE) return AddCharge(fDccMapY,channel,time,charge);
130  return 0 ; // ????
131 }
132 
133 Int_t HarpoSimElectronics::AddCharge(HarpoDccMap* dccMap, Int_t channel, Double_t time, Double_t charge)
134 {
135 
136  if(gHarpoDebug>2) Info("AddCharge","###Pedestals: %p",dccMap->GetPedestals());
137  if(channel<0) return -1;
138  if(channel>=288) return -1;
139 
140  if(gHarpoDebug>2) Info("AddCharge","ch = %d, t = %.1g, Q = %.1g",channel,time,charge);
141  Double_t minCharge = 0.01;
142 
143  Double_t tautmp = fTau*fSamplingFreq;
144 
145  Double_t chargeSum = 0;
146 
147  time += fTimeOffset;
148 
149 
150  Double_t data = 0;
151  Bool_t signal = kFALSE;
152  Int_t tmin = Int_t(time*fSamplingFreq);
153  if(tmin<0) tmin = 0;
154  for(Int_t t = tmin; t<fTimeRange; t++){
155  Double_t cellCharge = 0;
156  Double_t t1 = (t-time*fSamplingFreq)/tautmp;
157  if(t1<0) continue;
158  switch(fGammaPower){
159  case 4: cellCharge = charge/(3.0/128.0*tautmp)*TMath::Power(t1,4)*TMath::Exp(-4*t1); break;
160  case 3: cellCharge = charge/(2.0/27.0*tautmp)*TMath::Power(t1,3)*TMath::Exp(-3*t1); break;
161  case -3: cellCharge = charge/(2.0/27.0*tautmp)*TMath::Power(t1,3)*TMath::Exp(-3*t1)*TMath::Sin(t1)/0.7776; break;
162  case 2: cellCharge = charge/(1.0/4.0*tautmp)*TMath::Power(t1,2)*TMath::Exp(-2*t1); break;
163  default: cellCharge = charge/(3.0/128.0*tautmp)*TMath::Power(t1,4)*TMath::Exp(-4*t1);
164  }
165  data = dccMap->GetRawData(channel,t);
166  if(data <= 0) data = cellCharge;
167  else data += cellCharge;
168  if(data<minCharge && signal) break;
169  if(data<minCharge && !signal) continue;
170  signal = kTRUE;
171 
172  if(gHarpoDebug>4) Info("AddCharge","map(%d,%d) = %g",channel,t,data);
173  // dccMap->map(channel,t) = data;
174  dccMap->SetRawData(channel,t,data);
175  chargeSum += cellCharge;
176  }
177 
178  if(gHarpoDebug>3) Info("AddCharge","*** In: %.3g, OUT: %.3g => %.3g",charge, chargeSum, chargeSum/charge);
179 
180  return 1;
181 }
182 
183 
184 
185 
187 {
188  Noise(fDccMapX);
189  Noise(fDccMapY);
192 }
193 
195 {
196  for(Int_t ch = 0; ch<NCHAN;ch++){
197  for(Int_t t = 0; t<NADC;t++){
198  // Double_t data = dccMap->map(ch,t);
199  Double_t data = dccMap->GetRawData(ch,t);
200  data += gRandom->Gaus(0,fNoise);
201  // dccMap->map(ch,t) = Int_t(data);
202  dccMap->SetRawData(ch,t, Int_t(data));
203  }
204  }
205 }
206 
208 {
209 
210  Bool_t isSat = kTRUE;
211  for(Int_t ch = 0; ch<NCHAN;ch++){
212  Double_t qtot = 0, qreadold = 0;
213  Bool_t isPrevSat = isSat;
214  isSat = kFALSE;
215  for(Int_t t = 0; t<NADC;t++){
216  // Double_t data = dccMap->map(ch,t);
217  Double_t data = dccMap->GetRawData(ch,t);
218  qtot += data;
219  Double_t qread = ChannelSat(qtot);
220  data = qread - qreadold;
221  qreadold = qread;
222  if(qtot>fThrSatCh){ // Cross-talk when saturated
223  isSat = kTRUE;
224  if(!isPrevSat && ch>0){
225  Double_t dataprev = dccMap->GetRawData(ch-1,t)+data*fXtalkSatCh;
226  if(dataprev>fThrSat) dataprev = fThrSat;
227  dccMap->SetRawData(ch-1,t, Int_t(dataprev));
228  }
229  if(ch<NCHAN-1){
230  Double_t datanext = dccMap->GetRawData(ch+1,t)+data*fXtalkSatCh;
231  if(datanext>fThrSat) datanext = fThrSat;
232  dccMap->SetRawData(ch+1,t, Int_t(datanext));
233  }
234  }
235  if(data>fThrSat) data = fThrSat;
236  dccMap->SetRawData(ch,t, Int_t(data));
237  }
238  }
239 }
240 
241 Double_t HarpoSimElectronics::ChannelSat(Double_t qreal)
242 {
243  // if(qreal<fThrSatCh) return qreal;
244  Double_t qread;
245  if(fAmpSatCh>0){
246  if(qreal<fThrSatCh) return qreal;
247  qread = fThrSatCh + fAmpSatCh*TMath::TanH((qreal-fThrSatCh)/fAmpSatCh);
248  return qread;
249  }else{
250  qread = fThrSatCh + (qreal-fThrSatCh)/(-fAmpSatCh);
251  return qread;
252  }
253 
254  // Double_t A = 0.0357923;
255  // Double_t B = 103545;
256  // Double_t C = (1-A);
257  // Double_t lambda = 5.;
258  // qread = qreal*C/TMath::Power(1+TMath::Power(qreal/B*C,lambda),1./lambda) + qreal*A;
259  // return qread;
260  Double_t thr = 40000;
261  if(qreal<thr) return qreal;
262  Double_t A = 0.8;
263  Double_t thr2 = 60000;
264  Double_t thr2real = thr+(thr2-thr)/A;
265  if(qreal<thr2real) return thr + (qreal-thr)*A;
266  Double_t A2 = 0.4;
267  Double_t thr3 = 100000;
268  Double_t thr3real = thr2real+(thr3-thr2)/A2;
269  if(qreal<thr3real) return thr2 + (qreal-thr2real)*A2;
270  Double_t A3 = 0.03;
271  return thr3 + (qreal-thr3real)*A3;
272 }
273 
275 {
278 }
279 
281 {
282  for(Int_t ch = 0; ch<304;ch++){
283  for(Int_t t = 0; t<511;t++){
284  // Double_t data = dccMap->map(ch,t);
285  Double_t data = dccMap->GetData(ch,t);
286  if(data>4096) data = 4096;
287  if(data < fZeroSuppr*fNoise)
288  dccMap->SetRawData(ch,t, -1);
289  else
290  dccMap->SetData(ch,t, data);
291  }
292  }
293 }
294 
295 // void HarpoSimElectronics::AGETmultiplicity()
296 // {
297 
298 // for(Int_t t = 0; t<NADC;t++){
299 // Double_t mult[fNchipAGET];
300 // for(Int_t i = 0; i<fNchipAGET; i++) mult[i] = 0;
301 // for(Int_t ch = 0; ch<304;ch++){
302 // Double_t dataX = fDccMapX->GetData(ch,t);
303 // if(dataX>fThrAGET){
304 // Int_t chip = GetAGETchip(XPLANE,ch);
305 // mult[chip] += 1 + gRandom->Gaus(0,fNoiseAGET);
306 // }
307 // Double_t dataY = fDccMapY->GetData(ch,t);
308 // if(dataY>fThrAGET){
309 // Int_t chip = GetAGETchip(YPLANE,ch);
310 // mult[chip] += 1 + gRandom->Gaus(0,fNoiseAGET);
311 // }
312 // }
313 // for(Int_t i = 0; i<fNaget; i++){
314 // if(mult[i] == 0) continue;
315 // fAGET->Add(i,t,mult[i]);
316 // }
317 // }
318 // }
void Saturation(HarpoDccMap *map)
Int_t AddCharge(HarpoDccMap *map, Int_t channel, Double_t time, Double_t charge)
HarpoPedestal * GetPedestals()
Definition: HarpoDccMap.h:68
#define XPLANE
Definition: HarpoConfig.h:24
#define NCHAN
Definition: HarpoDccMap.h:16
HarpoPedestal * fPedestals[2]
Double_t GetRawData(Int_t i, Int_t j)
Definition: HarpoDccMap.cxx:75
Double_t GetData(Int_t i, Int_t j)
Set/Get Data Cell.
Definition: HarpoDccMap.cxx:84
Dcc Plane X.
Definition: HarpoDet.h:19
void SetData(Int_t i, Int_t j, Double_t val)
unpacked dcc data The class contains the data map for DCC or Feminos The data is stored as a 2D TMatr...
Definition: HarpoDccMap.h:29
#define NADC
Definition: HarpoDccMap.h:18
Long64_t gHarpoDebug
Definition: HarpoDebug.cxx:9
#define YPLANE
Definition: HarpoConfig.h:25
Unknown Detector.
Definition: HarpoDet.h:18
void SetPedestals(HarpoPedestal *obj)
Ste/Get Pedstal object.
Definition: HarpoDccMap.h:67
Bool_t Lookup(const char *path, Bool_t &val)
Lookup function for scalar values.
HarpoConfig * gHConfig
Double_t ChannelSat(Double_t qreal)
void SetRawData(Int_t i, Int_t j, Double_t val)
Definition: HarpoDccMap.cxx:94