6#include "GaudiKernel/ISvcLocator.h"
7#include "GaudiKernel/Bootstrap.h"
8#include "GaudiKernel/IDataProviderSvc.h"
9#include "GaudiKernel/SmartDataPtr.h"
10#include "GaudiKernel/DataSvc.h"
12#include "G4DigiManager.hh"
13#include "Randomize.hh"
16#include "CLHEP/Units/PhysicalConstants.h"
45 double time_spent = 0.;
46 clock_t begin = clock();
48 m_magConfig = magConfig;
51 string filePath = getenv(
"CGEMDIGITIZERSVCROOT");
54 fileName = filePath +
"/dat/par_settings_GTS.txt";
55 ifstream fin(fileName.c_str(), ios::in);
59 if( ! fin.is_open() ){
60 std::cout <<
"SamplingGTS::init ERROR: can not open file " << filePath << endl;
62 else std::cout <<
"SamplingGTS::init: open file " << fileName << endl;
68 getline(fin, strline);
70 else if(strpar ==
"high_voltage") {
73 else if(strpar ==
"magnetic_field") {
76 else if(strpar ==
"tuning_factor_gain") {
77 fin >> m_tuning_factor_gain;
79 else if(strpar ==
"tuning_factor_diff_perp") {
80 fin >> m_tuning_factor_diff_perp;
82 else if(strpar ==
"tuning_factor_diff_paral") {
83 fin >> m_tuning_factor_diff_paral;
87 cout <<
"SamplingGTS::init: drift and avalanche parameters" << endl;
88 cout <<
"high voltage " << m_hv <<
"V" << endl;
89 cout <<
"field " << m_field <<endl;
90 cout <<
"tuning factors:" << endl;
91 cout <<
"1) for gain " << m_tuning_factor_gain << endl;
92 cout <<
"2) for diffusion " << m_tuning_factor_diff_perp <<
" (for orthogonal) " << m_tuning_factor_diff_paral <<
" (for parallel)" << endl;
106 output =
new TFile(
"gem.root",
"RECREATE");
107 tree =
new TNtuple(
"tree",
"tree",
"dphi:darc:dx:dy:dz:z_local");
111 clock_t end = clock();
112 time_spent += (double)(end - begin) / CLOCKS_PER_SEC;
113 cout <<
"Sampling::init " << time_spent <<
" seconds" << endl;
119 cout <<
"SamplingGTS::setIonElectrons " << nElectrons << endl;
122 double time_spent = 0.;
123 clock_t begin = clock();
128 for(
int iele = 0; iele < nElectrons; iele++){
146 for(
int jele = 0; jele < tot_gain; jele++) {
147 double xf, yf, zf, tf;
167 clock_t end = clock();
168 time_spent += (double)(end - begin) / CLOCKS_PER_SEC;
169 cout <<
"Sampling::diffusion " << m_nMulElec <<
" time " << time_spent <<
" seconds" << endl;
175void SamplingGTS::clear(){
186 string filePath = getenv(
"CGEMDIGITIZERSVCROOT");
189 if(m_field) fileName = filePath +
"/dat/par_ArIso_1T_GTS.txt";
190 else fileName = filePath +
"/dat/par_ArIso_0T_GTS.txt";
192 string fileName2 = filePath +
"/dat/par_ArIso_0T_GTS.txt";
205 string filePath = getenv(
"CGEMDIGITIZERSVCROOT");
208 fileName = filePath +
"/dat/par_ArIso_GEM_GTS.txt";
209 ifstream fin(fileName.c_str(), ios::in);
213 if( ! fin.is_open() ){
214 std::cout <<
"SamplingGTS::readGemParameters ERROR: can not open file " << filePath << endl;
217 else std::cout <<
"SamplingGTS::readGemParameters: open file " << fileName << endl;
220 while(fin >> strpar){
222 if(strpar[0] ==
'#'){
223 getline(fin, strline);
225 else if( atoi(strpar.c_str()) == m_hv) {
226 fin >> m_eff_col[0] >> m_eff_col[1] >> m_eff_col[2] >> m_eff_ext[0] >> m_eff_ext[1] >> m_eff_ext[2];
232 cout <<
"SamplingGTS::readGemParameters: parameters of GEM @ HV = " << m_hv <<
" V" << endl;
233 cout <<
" collection eff GEM1: " << m_eff_col[0]
234 <<
" collection eff GEM2: " << m_eff_col[1]
235 <<
" collection eff GEM3: " << m_eff_col[2] << endl;
236 cout <<
" extraction eff GEM1: " << m_eff_ext[0]
237 <<
" extraction eff GEM2: " << m_eff_ext[1]
238 <<
" extraction eff GEM3: " << m_eff_ext[2] << endl;
239 cout <<
" is transparent " << is_tra << endl;
241 if(!is_tra)
return false;
244 fileName = filePath +
"/dat/CHECK_ArIso_EffGain_10M_GTS.root";
245 TFile *file_gain_eff =
new TFile(fileName.c_str(),
"READ");
246 TString histoname =
"h_gain_eff_0_"; histoname += m_hv;
247 h_gain_eff = (TH1F*) file_gain_eff->Get(histoname);
253 return (gRandom->Uniform() < m_eff_col[0]);
257 return m_tuning_factor_gain * h_gain_eff->GetRandom();
272 double R = TMath::Sqrt(xi*xi + yi*yi);
275 if(R < R_catout[1]) ilayer = 0;
276 else if(R < R_catout[2]) ilayer = 1;
281 double drift_thick = thick[ilayer];
282 double cat_rad_out = R_catout[ilayer];
297 double phi = TMath::ATan2(yi, xi);
300 double z_local = R - cat_rad_out;
301 if(z_local < 0 || z_local > drift_thick) cout <<
"ERRRRRRORE " << z_local << endl;
309 double shift_x = shift_x_drift + 2 * shift_x_transf;
310 double sigma_x = m_tuning_factor_diff_perp * TMath::Sqrt(pow(sigma_x_drift, 2) + 2 * pow(sigma_x_transf, 2));
315 double shift_phi = shift_x/gem3_rad_in;
316 double sigma_phi = sigma_x/gem3_rad_in;
318 double phif = phi + gRandom->Gaus(shift_phi, sigma_phi);
320 xf = gem3_rad_in * TMath::Cos(phif);
321 yf = gem3_rad_in * TMath::Sin(phif);
327 zf = zi + gRandom->Gaus(shift_y, sigma_y);
335 tf = ti + gRandom->Gaus(shift_t, sigma_t);
340 float dphi = phif-phi;
341 float darc = 1000 * gem3_rad_in * dphi;
342 float dx = 1000*(xf-xi);
343 float dy = 1000*(yf-yi);
344 float dz = 1000*(zf-zi);
346 tree->Fill(dphi, darc, dx, dy, dz, z_local);
double getInnerROfCgemFoil() const
CgemGeoFoil * getCgemFoil(int i) const
double getInnerROfCgemLayer() const
double sigma_t_drift(double z)
double sigma_x_drift(double z)
void readGasPerpParameters(std::string fileName)
void readGasParalParameters(std::string fileName)
double shift_t_drift(double z)
double shift_y_drift(double z)
double sigma_y_drift(double z)
double shift_x_drift(double z)
virtual double getThicknessOfCathode(int i) const =0
virtual CgemGeoLayer * getCgemLayer(int i) const =0
virtual double getThicknessOfGapD(int i) const =0
void init(ICgemGeomSvc *geomSvc, double magConfig)
void compute_diffusion_on_GEM3(double xi, double yi, double zi, double ti, double &xf, double &yf, double &zf, double &tf)
void setIonElectrons(int layer, int nElectrons, std::vector< double > x, std::vector< double > y, std::vector< double > z, std::vector< double > t)