HARPO  5.1.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HarpoSimReadout.cxx
Go to the documentation of this file.
1 
2 #include "HarpoSimReadout.h"
3 #include "HarpoSimElectronics.h"
4 #include "HarpoConfig.h"
5 #include "HarpoDebug.h"
6 
7 #include "TMath.h"
8 #include "TRandom3.h"
9 
10 ClassImp(HarpoSimReadout);
11 
12 
13 
15 {
16 
17  fStrips = (HarpoSimStrips*)NULL;//new HarpoSimStrips();
18 
19  // fGain = 500;
20  fGainMM = 20;
21  fGainGEM1 = 5;
22  fGainGEM2 = 5;
23  fRatioYX = 1;
24  fSigmaPrf = 0.35;
25 
26  fStripWidth = 1.;
27  fPolya = 1.;
28 
29  fDigi = (HarpoSimElectronics*)NULL;
30 
31 
32 
33  Double_t ratioYX;
34  if ( ! gHConfig->Lookup("Sim.RatioYX",ratioYX) )
35  Info("Constructor","Use default GainMM %g",fRatioYX);
36  else
37  fRatioYX = ratioYX;
38 
39  Double_t gainMM;
40  if ( ! gHConfig->Lookup("Sim.GainMM",gainMM) )
41  Info("Constructor","Use default GainMM %g",fGainMM);
42  else
43  fGainMM = gainMM;
44 
45  Double_t gainGEM1;
46  if ( ! gHConfig->Lookup("Sim.GainGEM1",gainGEM1) )
47  Info("Constructor","Use default GainGEM1 %g",fGainGEM1);
48  else
49  fGainGEM1 = gainGEM1;
50 
51  Double_t gainGEM2;
52  if ( ! gHConfig->Lookup("Sim.GainGEM2",gainGEM2) )
53  Info("Constructor","Use default GainGEM2 %g",fGainGEM2);
54  else
55  fGainGEM2 = gainGEM2;
56 
57  Double_t polya;
58  if ( ! gHConfig->Lookup("Sim.Polya",polya) )
59  Info("Constructor","Use default Polya %g",fPolya);
60  else
61  fPolya = polya;
62 
63  Double_t gain;
64  if ( ! gHConfig->Lookup("Sim.Gain",gain) )
65  Info("Constructor","Use default Gain %g/%g/%g",fGainMM,fGainGEM1,fGainGEM2);
66  else{
67  fGainMM = gain;
68  fGainGEM1 = 1;
69  fGainGEM2 = 1;
70  }
71 
72  Double_t sigmaPrf;
73  if ( ! gHConfig->Lookup("Sim.SigmaPrf",sigmaPrf) )
74  Info("Constructor","Use default SigmaPrf %g",fSigmaPrf);
75  else
76  fSigmaPrf = sigmaPrf;
77 
78  Double_t stripWidth;
79  if ( ! gHConfig->Lookup("Sim.StripWidth",stripWidth) )
80  Info("Constructor","Use default StripWidth %g",fStripWidth);
81  else
82  fStripWidth = stripWidth;
83 
84 
85  Info("HarpoSimReadout","SigmaPrf: %g",fSigmaPrf);
86 
87 
88 }
89 
90 
92 {
93 
94  fStrips->Delete();
95 
96 }
97 
99 {
100 
101  // fStrips->Reset();
102  // fStrips = new HarpoSimStrips();
103 
104 
105  return 1;
106 }
107 
108 HarpoSimStrips* HarpoSimReadout::ProcessElectron(Double_t x, Double_t y, Double_t t, hSimReadoutRegion region)
109 {
110 
111 
112  // Double_t gain = 0;
113  // if(region == hSimReadoutRegionDrift) gain = fGainGEM2*fGainGEM1*fGainMM;
114  // if(region == hSimReadoutRegionTransfer2) gain = fGainGEM1*fGainMM;
115  // if(region == hSimReadoutRegionTransfer1) gain = fGainMM;
116 
117  Double_t charge = 1;
118  if(region == hSimReadoutRegionDrift){
119  charge *= fGainGEM2;
120  charge *= fGainGEM1;
121  charge *= fGainMM;
122  }
123  if(region == hSimReadoutRegionTransfer2){
124  charge *= fGainGEM1;
125  charge *= fGainMM;
126  }
127  if(region == hSimReadoutRegionTransfer1){
128  charge *= fGainMM;
129  }
130 
131  // charge *= gRandom->Exp(1);
132  // charge *= gRandom->Exp(1)*gRandom->Exp(1)gRandom->Exp(1);
133  Double_t rndm = gRandom->Rndm();
134  charge *= 4*(1.-fPolya)*rndm*rndm*rndm + gRandom->Exp(fPolya);
135 
136 
137  if(charge<=0) return 0;
138  // Double_t charge = gain*gRandom->Exp(1);
139 
140  Double_t sigma = fSigmaPrf;
141 
142  //HarpoSimStrips* strips = new HarpoSimStrips();
143 
144  if(gHarpoDebug>4) Info("ProcessElectron","AddCharge(%f %f %f %f %f)",charge,sigma,x,y,t);
145 
146 
147  if(isBlocked(x,y)) return 0;
148 
149  //fStrips->
150  AddCharge(charge,sigma,x,y,t);
151 
152  return fStrips;
153 }
154 
155 
156 
157 
158 Int_t HarpoSimReadout::AddCharge(Double_t charge, Double_t sigma, Double_t x, Double_t y, Double_t t)
159 {
160 
161  //Info("AddCharge","%d %g %g %g %g %g",fNhitsX,charge,sigma,x,y,t);
162 
163  if(charge<0.1) return 0;
164 
165  // Find Strip number (X and Y coordinate)
166  Int_t iX = Int_t((x + 150.)/fStripWidth);
167  Int_t iY = Int_t((y + 150.)/fStripWidth);
168 
169  if(iX<0 || iX >= NCHAN) return 0;
170  if(iY<0 || iY >= NCHAN) return 0;
171 
172  Double_t chargeSum = 0;
173 
174  Int_t nbins = Int_t(5*sigma/fStripWidth);
175  for(Int_t i = iX - nbins; i<iX+nbins+1; i++){ // One layer (fStripWidth mm) in the X direction
176  Double_t Xi1 = fStripWidth*i-150.;
177  Double_t Xi2 = Xi1 + fStripWidth*0.379;
178  Double_t Xi3 = Xi2 + fStripWidth*0.1;
179  Double_t Xi4 = Xi3 + fStripWidth*0.421;
180  Double_t chXstrip = 0, chXpads = 0;
181  if(sigma>0){
182  // Charge fraction chX on the strip number i (between x = Xi1 and x = Xi2)
183  chXstrip = (TMath::Abs(TMath::Erf((x-Xi1)/sigma) - TMath::Erf((x-Xi2)/sigma)))/2;
184  // Charge fraction chY on the neighbour pads (between x = Xi3 and x = Xi4)
185  chXpads = (TMath::Abs(TMath::Erf((x-Xi3)/sigma) - TMath::Erf((x-Xi4)/sigma)))/2;
186  }else{ // punctual charge deposition (sigma = 0)
187  if(x>Xi3 && x<Xi4) chXstrip = 1;
188  if(x>Xi1 && x<Xi2) chXpads = 1;
189  }
190  chXstrip *= charge;
191  chXpads *= charge;
192  if(chXstrip>0.1){ // Add the charge to the X strip i
193  if(fStrips != NULL) fStrips->AddHit(1,i,t,chXstrip);
194  fDigi->AddCharge(XPLANE,i,t,chXstrip);
195  chargeSum += chXstrip;
196  }
197  if(chXpads<0.1) continue;
198  for(Int_t j = iY - nbins; j<iY+nbins+1; j++){ // One pad on neighbour row to the strip i
199  Double_t Yj1 = fStripWidth*j-150.;
200  Double_t Yj2 = Yj1 + fStripWidth*0.9;
201  // charge fraction chY on the pad (between x = Xi3 and x = Xi4 and y = Yj1 and y = Yj2)
202  Double_t chY = 0;
203  if(sigma>0)
204  chY = (TMath::Abs(TMath::Erf((y-Yj1)/sigma) - TMath::Erf((y-Yj2)/sigma)))/2;
205  else{ // punctual charge deposition (sigma = 0)
206  if(y>Yj1 && y<Yj2) chY = 1;
207  }
208  chY *= chXpads;
209  chY *= fRatioYX;
210  if(chY>0.1){ // Add charge to Y strip j
211  if(fStrips != NULL) fStrips->AddHit(0,i,t,chY);
212  fDigi->AddCharge(YPLANE,j,t,chY);
213  chargeSum += chY;
214  }
215  }
216 
217  }
218 
219  if(gHarpoDebug>3) Info("AddCharge","### In: %.3g, OUT: %.3g => %.3g",charge, chargeSum, chargeSum/charge);
220 
221  return 1;
222 
223 }
224 
225 
226 Bool_t HarpoSimReadout::isBlocked(Double_t x, Double_t y)
227 {
228 
229  if(TMath::Abs(fmod(TMath::Abs(x),33)-16.5)<0.5) return kTRUE; // GEM sector
230 
231  if(TMath::Abs(fmod(TMath::Abs(x),100)-50)<1) return kTRUE; // separator
232  if(TMath::Abs(fmod(TMath::Abs(y),100)-50)<1) return kTRUE; // separator
233 
234  return kFALSE;
235 }
Int_t AddCharge(HarpoDccMap *map, Int_t channel, Double_t time, Double_t charge)
#define XPLANE
Definition: HarpoConfig.h:24
#define NCHAN
Definition: HarpoDccMap.h:16
Bool_t isBlocked(Double_t x, Double_t y)
enum hSimReadoutRegion_ hSimReadoutRegion
Harpo Reader Type.
Int_t AddCharge(Double_t charge, Double_t sigma, Double_t x, Double_t y, Double_t t)
Int_t AddHit(Int_t plane, Int_t ch, Double_t t, Double_t q)
HarpoSimElectronics * fDigi
HarpoSimStrips * fStrips
Long64_t gHarpoDebug
Definition: HarpoDebug.cxx:9
#define YPLANE
Definition: HarpoConfig.h:25
Bool_t Lookup(const char *path, Bool_t &val)
Lookup function for scalar values.
Transfer region 2 (between top and bottom GEM)
Double_t fStripWidth
HarpoConfig * gHConfig
HarpoSimStrips * ProcessElectron(Double_t x, Double_t y, Double_t t, hSimReadoutRegion region)