@@ -49,6 +49,7 @@ void TRestDetectorElectronDiffusionProcess::Initialize() {
49
49
fTransversalDiffusionCoefficient = 0 ;
50
50
fLongitudinalDiffusionCoefficient = 0 ;
51
51
fWValue = 0 ;
52
+ fFanoFactor = 0 ;
52
53
53
54
fOutputHitsEvent = new TRestDetectorHitsEvent ();
54
55
fInputHitsEvent = nullptr ;
@@ -96,14 +97,25 @@ void TRestDetectorElectronDiffusionProcess::InitProcess() {
96
97
<< RESTendl;
97
98
exit (1 );
98
99
#endif
99
- if (fGasPressure <= 0 ) fGasPressure = fGas ->GetPressure ();
100
- if (fElectricField <= 0 ) fElectricField = fGas ->GetElectricField ();
101
- if (fWValue <= 0 ) fWValue = fGas ->GetWvalue ();
102
-
100
+ if (fGasPressure <= 0 ) {
101
+ fGasPressure = fGas ->GetPressure ();
102
+ }
103
103
fGas ->SetPressure (fGasPressure );
104
+
105
+ if (fElectricField <= 0 ) {
106
+ fElectricField = fGas ->GetElectricField ();
107
+ }
104
108
fGas ->SetElectricField (fElectricField );
109
+
110
+ if (fWValue <= 0 ) {
111
+ fWValue = fGas ->GetWvalue ();
112
+ }
105
113
fGas ->SetW (fWValue );
106
114
115
+ if (fFanoFactor <= 0 ) {
116
+ fFanoFactor = fGas ->GetGasFanoFactor ();
117
+ }
118
+
107
119
if (fLongitudinalDiffusionCoefficient <= 0 ) {
108
120
fLongitudinalDiffusionCoefficient = fGas ->GetLongitudinalDiffusion ();
109
121
} // (cm)^1/2
@@ -124,8 +136,8 @@ TRestEvent* TRestDetectorElectronDiffusionProcess::ProcessEvent(TRestEvent* inpu
124
136
fInputHitsEvent = (TRestDetectorHitsEvent*)inputEvent;
125
137
fOutputHitsEvent ->SetEventInfo (fInputHitsEvent );
126
138
127
- set<unsigned int > hitsToProcess; // indices of the hits to process (we do not want to process veto hits)
128
- for (unsigned int n = 0 ; n < fInputHitsEvent ->GetNumberOfHits (); n++) {
139
+ set<int > hitsToProcess; // indices of the hits to process (we do not want to process veto hits)
140
+ for (int n = 0 ; n < static_cast < int >( fInputHitsEvent ->GetNumberOfHits () ); n++) {
129
141
if (fInputHitsEvent ->GetType (n) == REST_HitType::VETO) {
130
142
// keep unprocessed hits as they are
131
143
fOutputHitsEvent ->AddHit (fInputHitsEvent ->GetX (n), fInputHitsEvent ->GetY (n),
@@ -148,7 +160,7 @@ TRestEvent* TRestDetectorElectronDiffusionProcess::ProcessEvent(TRestEvent* inpu
148
160
bool isAttached;
149
161
150
162
Double_t wValue = fWValue ;
151
- const unsigned int totalElectrons = totalEnergy * REST_Units::eV / wValue;
163
+ const auto totalElectrons = static_cast < unsigned int >( totalEnergy * REST_Units::eV / wValue) ;
152
164
153
165
// TODO: double check this
154
166
if (fMaxHits > 0 && totalElectrons > fMaxHits ) {
@@ -185,15 +197,21 @@ TRestEvent* TRestDetectorElectronDiffusionProcess::ProcessEvent(TRestEvent* inpu
185
197
186
198
Double_t driftDistance = plane->GetDistanceTo ({x, y, z});
187
199
188
- Int_t numberOfElectrons;
189
- if (fPoissonElectronExcitation ) {
190
- numberOfElectrons = fRandom ->Poisson (energy * REST_Units::eV / fWValue );
191
- if (wValue != fWValue ) {
192
- // reduce the number of electrons to improve speed
193
- numberOfElectrons = numberOfElectrons * fWValue / wValue;
200
+ double numberOfElectrons = energy * REST_Units::eV / wValue;
201
+ if (fUseFanoFactor ) {
202
+ if (fFanoFactor <= 0 ) {
203
+ throw runtime_error (" Fano factor not valid" );
194
204
}
195
- } else {
196
- numberOfElectrons = energy * REST_Units::eV / wValue;
205
+ const auto sigma = TMath::Sqrt (fFanoFactor * numberOfElectrons);
206
+ numberOfElectrons = fRandom ->Gaus (numberOfElectrons, sigma);
207
+ } else if (fPoissonElectronExcitation ) {
208
+ // this is probably a bad idea, we only keep it for backwards compatibility
209
+ numberOfElectrons = fRandom ->Poisson (energy * REST_Units::eV / fWValue );
210
+ }
211
+
212
+ if (wValue != fWValue ) {
213
+ // reduce the number of electrons to improve speed
214
+ numberOfElectrons = static_cast <unsigned int >(numberOfElectrons * fWValue / wValue);
197
215
}
198
216
199
217
if (numberOfElectrons <= 0 ) {
@@ -202,14 +220,12 @@ TRestEvent* TRestDetectorElectronDiffusionProcess::ProcessEvent(TRestEvent* inpu
202
220
203
221
const Double_t energyPerElectron = energy * REST_Units::eV / numberOfElectrons;
204
222
205
- while (numberOfElectrons > 0 ) {
206
- numberOfElectrons--;
207
-
208
- Double_t longitudinalDiffusion =
209
- 10 . * TMath::Sqrt (driftDistance / 10 .) * fLongitudinalDiffusionCoefficient ; // mm
210
- Double_t transversalDiffusion =
211
- 10 . * TMath::Sqrt (driftDistance / 10 .) * fTransversalDiffusionCoefficient ; // mm
223
+ Double_t longitudinalDiffusion =
224
+ 10 . * TMath::Sqrt (driftDistance / 10 .) * fLongitudinalDiffusionCoefficient ; // mm
225
+ Double_t transversalDiffusion =
226
+ 10 . * TMath::Sqrt (driftDistance / 10 .) * fTransversalDiffusionCoefficient ; // mm
212
227
228
+ for (unsigned int i = 0 ; i < numberOfElectrons; i++) {
213
229
if (fAttachment > 0 ) {
214
230
// TODO: where is this formula from?
215
231
isAttached = (fRandom ->Uniform (0 , 1 ) > pow (1 - fAttachment , driftDistance / 10 .));
@@ -240,7 +256,7 @@ TRestEvent* TRestDetectorElectronDiffusionProcess::ProcessEvent(TRestEvent* inpu
240
256
1E-6 * plane->GetNormal ().Z ()); // add a delta to make sure readout finds it
241
257
}
242
258
243
- if (! fCheckIsInside && !plane->IsInside (positionAfterDiffusion)) {
259
+ if (fCheckIsInside && !plane->IsInside (positionAfterDiffusion)) {
244
260
// electron has been moved outside the readout plane
245
261
continue ;
246
262
}
@@ -280,13 +296,14 @@ void TRestDetectorElectronDiffusionProcess::InitFromConfigFile() {
280
296
fGasPressure = GetDblParameterWithUnits (" gasPressure" , -1 .);
281
297
fElectricField = GetDblParameterWithUnits (" electricField" , -1 .);
282
298
fWValue = GetDblParameterWithUnits (" WValue" , 0.0 ) * REST_Units::eV;
299
+ fFanoFactor = GetDblParameterWithUnits (" fanoFactor" , 0.0 );
283
300
fAttachment = StringToDouble (GetParameter (" attachment" , " 0" ));
284
301
fLongitudinalDiffusionCoefficient =
285
302
StringToDouble (GetParameter (" longitudinalDiffusionCoefficient" , " -1" ));
286
303
if (fLongitudinalDiffusionCoefficient == -1 )
287
304
fLongitudinalDiffusionCoefficient = StringToDouble (GetParameter (" longDiff" , " -1" ));
288
305
else {
289
- RESTWarning << " longitudinalDiffusionCoefficient is now OBSOLETE! It will soon dissapear ."
306
+ RESTWarning << " longitudinalDiffusionCoefficient is now OBSOLETE! It will soon disappear ."
290
307
<< RESTendl;
291
308
RESTWarning << " Please use the shorter form of this parameter : longDiff" << RESTendl;
292
309
}
@@ -295,12 +312,13 @@ void TRestDetectorElectronDiffusionProcess::InitFromConfigFile() {
295
312
if (fTransversalDiffusionCoefficient == -1 )
296
313
fTransversalDiffusionCoefficient = StringToDouble (GetParameter (" transDiff" , " -1" ));
297
314
else {
298
- RESTWarning << " transversalDiffusionCoefficient is now OBSOLETE! It will soon dissapear ." << RESTendl;
315
+ RESTWarning << " transversalDiffusionCoefficient is now OBSOLETE! It will soon disappear ." << RESTendl;
299
316
RESTWarning << " Please use the shorter form of this parameter : transDiff" << RESTendl;
300
317
}
301
318
fMaxHits = StringToInteger (GetParameter (" maxHits" , " 1000" ));
302
- fSeed = StringToDouble ( GetParameter (" seed" , " 0" ));
303
- fPoissonElectronExcitation = StringToBool (GetParameter (" poissonElectronExcitation" , " false " ));
319
+ fSeed = static_cast <UInt_t>( StringToInteger ( GetParameter (" seed" , " 0" ) ));
320
+ fPoissonElectronExcitation = StringToBool (GetParameter (" poissonElectronExcitation" , " true " ));
304
321
fUnitElectronEnergy = StringToBool (GetParameter (" unitElectronEnergy" , " false" ));
305
- fCheckIsInside = StringToBool (GetParameter (" checkIsInside" , " true" ));
322
+ fCheckIsInside = StringToBool (GetParameter (" checkIsInside" , " false" ));
323
+ fUseFanoFactor = StringToBool (GetParameter (" useFano" , " false" ));
306
324
}
0 commit comments