1+ /* ----------------------------------------------------------------------------
2+ *
3+ * Copyright (C) 2018-2019 Andrea Contu e Angelo Loi
4+ *
5+ * This file is part of TCode software.
6+ *
7+ * TCode is free software: you can redistribute it and/or modify
8+ * it under the terms of the GNU General Public License as published by
9+ * the Free Software Foundation, either version 3 of the License, or
10+ * (at your option) any later version.
11+ *
12+ * TCode is distributed in the hope that it will be useful,
13+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+ * GNU General Public License for more details.
16+ *
17+ * You should have received a copy of the GNU General Public License
18+ * along with TCode. If not, see <http://www.gnu.org/licenses/>.
19+ *
20+ *---------------------------------------------------------------------------*/
21+ /*
22+ * E_deposit.cpp
23+ *
24+ * Created on: 18/02/2019
25+ * Author: Angelo Loi
26+ */
27+
28+
29+ // include gli header di ROOT necessari per la simulazione
30+ #include " E_deposit.h" // classe field
31+ #include < iostream>
32+ #include < vector>
33+ #include < fstream>
34+ #include < TRandom.h>
35+ #include < cmath>
36+
37+ #define PI 3.1415926535897932384626433
38+
39+ using namespace std ;
40+
41+ E_deposit::E_deposit (){
42+ }
43+
44+ void E_deposit::G4_E_Dep_gen (TString filename){
45+ // initialises particle number
46+ N_tot = 0 ;
47+ shift = 0 ;
48+ // open G4 E_dep information file
49+ ifstream G4_file;
50+ G4_file.open (filename);
51+
52+ if (G4_file.fail ()){
53+ cout<<" FILE DOES NOT EXIST!\n " ;
54+ exit (EXIT_SUCCESS); ;
55+ }
56+ else
57+ {
58+ while (!G4_file.eof ()){
59+ // generate deposit
60+ G4_file >> X0 >> Y0 >> Z0 >> X1 >> Y1 >> Z1 >> N_eh >> pId;
61+
62+ for (int i=0 +shift; i<N_eh+shift ; i++){
63+ t = (i-shift+1 )/(N_eh);
64+ Pex.push_back (X0+(X1-X0)*t);
65+ Pey.push_back (Y0+(Y1-Y0)*t);
66+ Pez.push_back (Z0+(Z1-Z0)*t);
67+ Phx.push_back (X0+(X1-X0)*t);
68+ Phy.push_back (Y0+(Y1-Y0)*t);
69+ Phz.push_back (Z0+(Z1-Z0)*t);
70+ PIDe.push_back (pId);
71+ PIDh.push_back (pId);
72+ N_tot++;
73+ }
74+ // shift for next cycle
75+ shift = N_tot;
76+ }
77+ }
78+ G4_file.close ();
79+ }
80+
81+
82+
83+ void E_deposit::SetCustomEDep (TString filename){
84+
85+ N_tot = 0 ;
86+ shift = 0 ;
87+
88+ // open energy deposit file
89+ ifstream G4_file;
90+ G4_file.open (filename);
91+
92+ if (G4_file.fail ()){
93+ cout<<" FILE DOES NOT EXIST!\n " ;
94+ exit (EXIT_SUCCESS); ;
95+ }
96+ else {
97+ while (!G4_file.eof ()){
98+ // file imput: first row is the same as for the G4 deposit
99+ G4_file >> X0 >> Y0 >> Z0 >> X1 >> Y1 >> Z1 >> N_eh >> pId;
100+ // this row simply adds some other parameters
101+ G4_file >> T0 >> T1 >> sig0 >> sig1 >> Option;
102+
103+ for (int i=0 +shift; i<N_eh+shift ; i++){
104+ // linear evolution parameter
105+ t = (i-shift+1 )/(N_eh);
106+
107+ // evolution of the deposit is handled also lineary
108+ x_P = X0 + (X1 - X0)*t;
109+ y_P = Y0 + (Y1 - Y0)*t;
110+ z_P = Z0 + (Z1 - Z0)*t;
111+
112+ // dispersion is handled lineary...
113+ sigm = sig0 + (sig1-sig0)*t;
114+
115+ // the shape of the dispersion can be defined in 3 diff. shapes
116+ if (Option == 0 ){ // uniform
117+ disp = gRandom ->Uniform (-sigm/2 , sigm/2 );
118+ }
119+ else if (Option == 1 ){ // gaussian
120+ disp = gRandom ->Exp (sigm);
121+ }
122+ else if (Option == 2 ){ // exponential
123+ disp = gRandom ->Gaus (0 ,-sigm);
124+ }
125+ // ... and the final position is still perpendicular to the
126+ // direction of the deposit, calc. with the following function
127+ P_dir_disp ();
128+
129+ // now all electron-hole couples are generated with their casual
130+ // distribution arround the direction of the primary
131+ Pex.push_back (x_P + dispX);
132+ Pey.push_back (y_P + dispY);
133+ Pez.push_back (z_P + dispZ);
134+ Phx.push_back (x_P + dispX);
135+ Phy.push_back (y_P + dispY);
136+ Phz.push_back (z_P + dispZ);
137+ // their generation time is also included
138+ Te.push_back (T0+(T1-T0)*t);
139+ Th.push_back (T0+(T1-T0)*t);
140+ // the particle ID also
141+ PIDe.push_back (pId);
142+ PIDh.push_back (pId);
143+ N_tot++;
144+ }
145+ shift = N_tot;
146+ }
147+ }
148+ G4_file.close ();
149+ }
150+
151+ void E_deposit::P_dir_disp (){
152+ // calcs vector norm related to the deposit track
153+ mod = sqrt (((X1 - X0)*(X1 - X0) + (Y1 - Y0)*(Y1 - Y0) + (Z1 - Z0)*(Z1 - Z0)));
154+
155+ // angle of the energy deposit track with respect to all axis
156+ alpha = acos (((Z1-Z0)/mod));
157+ if (Y1 == Y0 && X1 == X0){
158+ beta = 0 ;
159+ }
160+ else {
161+ beta = atan (abs (Y1-Y0)/(X1-X0));
162+ }
163+
164+ // definition of a perpendicular vector with respect to the energy deposit track
165+ // module is defined previously with the dispertion parameter sigm.
166+ x_Y = disp*sin (alpha + PI/2 )*cos (beta);
167+ y_Y = disp*sin (alpha + PI/2 )*sin (beta);
168+ z_Y = disp*cos (alpha + PI/2 );
169+
170+
171+ // random angle generator for final rotation
172+ gamma = (rand () % 36000 )*PI/18000 ;
173+
174+ // casual rotation arround energy deposit track direction of the perpendicular vector
175+ dispX = (((X1 - X0)*(X1 - X0)*(1 /(mod*mod)) + (1 -(X1 - X0)*(X1 - X0)*(1 /(mod*mod)))*cos (gamma))*x_Y + ((X1 - X0)*(Y1 - Y0)*(1 /(mod*mod))*(1 -cos (gamma)) - (Z1 - Z0)*(1 /(mod))*sin (gamma))*y_Y + ((X1 - X0)*(Z1 - Z0)*(1 /(mod*mod))*(1 - cos (gamma)) + (Y1 - Y0)*(1 /(mod))*sin (gamma))*z_Y);
176+
177+ dispY = ((X1 - X0)*(1 /(mod*mod))*(Y1 - Y0)*(1 - cos (gamma))*x_Y + (Z1 - Z0)*(1 /(mod))*sin (gamma)*x_Y + (Y1 - Y0)*(1 /(mod*mod))*(Y1 - Y0)*y_Y + (1 -(Y1 - Y0)*(1 /(mod*mod))*(Y1 - Y0))*cos (gamma)*y_Y + (Y1 - Y0)*(1 /(mod*mod))*(Z1 - Z0)*(1 - cos (gamma))*z_Y - (X1 - X0)*(1 /(mod))*sin (gamma)*z_Y);
178+
179+ dispZ = ((X1 - X0)*(Z1 - Z0)*(1 /(mod*mod))*(1 -cos (gamma))*x_Y - (Y1 - Y0)*(1 /(mod))*sin (gamma)*x_Y + (Y1 - Y0)*(1 /(mod*mod))*(Z1 - Z0)*(1 -cos (gamma))*y_Y + (X1 - X0)*(1 /(mod*mod))*sin (gamma)*y_Y + (Z1 - Z0)*(Z1 - Z0)*(1 /(mod*mod))*z_Y + (1 -(Z1 - Z0)*(1 /(mod*mod))*(Z1 - Z0))*cos (gamma)*z_Y);
180+
181+ }
182+
183+
184+ // returns the total number of generated couples
185+ float E_deposit::Return_N_tot (){
186+ return N_tot;
187+ }
188+ // return all particles coordinates
189+ float E_deposit::GethXPos (int i){
190+ return Phx[i];
191+ }
192+ float E_deposit::GethYPos (int i){
193+ return Phy[i];
194+ }
195+ float E_deposit::GethZPos (int i){
196+ return Phz[i];
197+ }
198+ float E_deposit::GeteXPos (int i){
199+ return Pex[i];
200+ }
201+ float E_deposit::GeteYPos (int i){
202+ return Pey[i];
203+ }
204+ float E_deposit::GeteZPos (int i){
205+ return Pez[i];
206+ }
207+
208+
209+ // simply generates an output to controll all generated particles
210+ void * E_deposit::Print_E_deposit (){
211+ ofstream myfile;
212+ myfile.open (" deposit_at_t_zero.txt" );
213+ for (int i=1 ; i<Pex.size () ; i++){
214+ cout<<Pex[i]<<" " <<Pey[i]<<" " <<Pez[i]<<" " <<PIDe[i]<<" " <<Phx[i]<<" " <<Phy[i]<<" " <<Phz[i]<<" " <<PIDh[i]<<" \n " ;
215+ myfile<<Pex[i]<<" " <<Pey[i]<<" " <<Pez[i]<<" " <<PIDe[i]<<" " <<Phx[i]<<" " <<Phy[i]<<" " <<Phz[i]<<" " <<PIDh[i]<<" \n " ;
216+ }
217+ myfile.close ();
218+ cout<<N_tot<<" particles generated\n " ;
219+ }
220+
0 commit comments