CGEM BOSS 6.6.5.g
BESIII Offline Software System
Loading...
Searching...
No Matches
IonizationGar.cxx
Go to the documentation of this file.
2
3#include "GaudiKernel/ISvcLocator.h"
4#include "GaudiKernel/Bootstrap.h"
5#include "GaudiKernel/IDataProviderSvc.h"
6#include "GaudiKernel/SmartDataPtr.h"
7#include "GaudiKernel/DataSvc.h"
8
9#include "CLHEP/Units/PhysicalConstants.h"
10
11#include <iomanip>
12#include <iostream>
13#include <fstream>
14#include <cmath>
15
16using namespace std;
17using namespace Garfield;
18
20}
21
23 delete m_gas;
24 delete m_geo;
25 delete m_comp;
26 delete m_box;
27 delete m_sensor;
28}
29
30void IonizationGar::init(unsigned int random, ICgemGeomSvc* geomSvc, double magConfig){
31 m_random = random;
32 m_geomSvc = geomSvc;
33 m_magConfig = magConfig;
34
35 initGeoGas();
36
37 //TrackHeed*
38 m_track = new TrackHeed();
39 m_track->SetSensor(m_sensor);
40 if(m_debugging) m_track->EnableDebugging();
41 else m_track->DisableDebugging();
42 //m_track->EnableMagneticField();
43
44}
45
46void IonizationGar::setTrack(int particle, int charge, double p, double trkPosIn[], double trkPosOut[]){
47 clear();
48 int nE = 0;
49
50 double x0 = 0., y0 = 0., z0 = 0., t0 = 0.;
51
52 // //the length of track segment.
53 // double d0 = sqrt(pow((trkPosOut[0]-trkPosIn[0]),2)+pow((trkPosOut[1]-trkPosIn[1]),2)+pow((trkPosOut[2]-trkPosIn[2]),2));
54 // double d1 = sqrt(pow((trkPosOut[0]-trkPosIn[0]),2)+pow((trkPosOut[1]-trkPosIn[1]),2));
55 // double trkL = d0;
56
57 // double lambda = acos(d1/d0);
58 // double theta = acos((trkPosOut[1]-trkPosIn[1])/d1);
59
60 // double dx0 = cos(lambda)*sin(theta)/10.0; // mm->cm
61 // double dy0 = cos(lambda)*cos(theta)/10.0; // mm->cm
62 // double dz0 = sin(lambda)/10.0; // mm->cm
63
64 double dx0 = (trkPosOut[0] - trkPosIn[0])/10.0; // cm
65 double dy0 = (trkPosOut[1] - trkPosIn[1])/10.0; // cm
66 double dz0 = (trkPosOut[2] - trkPosIn[2])/10.0; // cm
67 double trkL = sqrt(dx0*dx0 + dy0*dy0 + dz0*dz0);
68
69 // cout << "track segment: " << setw(15) << trkPosIn[0] << setw(15) << trkPosIn[1] << setw(15) << trkPosIn[2]
70 // << setw(15) << trkPosOut[0] << setw(15) << trkPosOut[1] << setw(15) << trkPosOut[2] << endl;
71 // cout << setw(15) << trkL << setw(15) << dx0 << setw(15) << dy0 << setw(15) << dz0 << endl;
72
73 double minX = 0. < dx0 ? 0. : dx0;
74 double maxX = 0. < dx0 ? dx0 : 0.;
75 double minY = 0. < dy0 ? 0. : dy0;
76 double maxY = 0. < dy0 ? dy0 : 0.;
77 double minZ = 0. < dz0 ? 0. : dz0;
78 double maxZ = 0. < dz0 ? dz0 : 0.;
79 if(maxX<=minX){
80 minX += -0.1;
81 maxX += 0.1;
82 }
83 if(maxY<=minY){
84 minY += -0.1;
85 maxY += 0.1;
86 }
87 if(maxZ<=minZ){
88 minZ += -0.1;
89 maxZ += 0.1;
90 }
91
92 string particleType = getParticle(particle, charge);
93
94 m_track->SetParticle(particleType);
95 m_track->SetMomentum(p*1.e9);
96 // m_sensor->SetArea(-0.5, 0, -0.5, 0.5, 0.5, 0.5);
97 m_sensor->SetArea(minX, minY, minZ, maxX, maxY, maxZ);
98 // cout << setw(15) << minX << setw(15) << maxX << setw(15) << minY << setw(15) << maxY
99 // << setw(15) << minZ << setw(15) << maxZ << endl;
100
101 // cout << "trkpos" << endl;
102 // cout << setw(15) << trkPosIn[0] << setw(15) << trkPosIn[1] << setw(15) << trkPosIn[2]
103 // << setw(15) << trkPosOut[0] << setw(15) << trkPosOut[1] << setw(15) << trkPosOut[2] << endl;
104
105 //cout<<"new Track"<<endl;
106 m_track->NewTrack(x0, y0, z0, t0, dx0, dy0, dz0);
107 //cout<<"after new Track"<<endl;
108 // m_track->NewTrack(0, 0, 0, t0, 0, 1, 0);
109 // cout << "particle: " << particleType << ", P = " << p << endl;
110 // cout << setw(15) << x0 << setw(15) << y0 << setw(15) << z0 << setw(15) << t0
111 // << setw(15) << dx0 << setw(15) << dy0 << setw(15) << dz0 << endl;
112
113 double xc = 0., yc = 0., zc = 0., tc = 0.; // cluster position
114 int nc = 0; // number of electrons
115 double ec = 0.; // energy
116 double extra = 0.; // not used
117 int nCluster = 0;
118
119 while(m_track->GetCluster(xc, yc, zc, tc, nc, ec, extra)){
120 // cout<<"nCluster="<<nCluster<<endl;
121 double length = sqrt(pow(xc,2)+pow(yc,2)+pow(zc,2));
122 // cout << "length = " << length << ", trkL = " << trkL << endl;
123 if(length>trkL){
124 cout << "overflow -------------------------" << endl;
125 continue;
126 }
127 // cout << setw(5) << nCluster << setw(15) << xc << setw(15) << yc << setw(15) << zc << setw(15) << nc << endl;
128 nCluster++;
129 for(int j = 0; j<nc; ++j) {
130 double xe, ye, ze, te;
131 double ee, dxe, dye, dze;
132 //cout <<" get e "<<j<<endl;
133 m_track->GetElectron(j, xe, ye, ze, te, ee, dxe, dye, dze); // unit: cm
134
135 // cout << setw(5) << nE << setw(15) << xe << setw(15) << ye << setw(15) << ze << setw(15) << te << endl;
136 m_ex.push_back(trkPosIn[0] + xe*10.0); // mm
137 m_ey.push_back(trkPosIn[1] + ye*10.0); // mm
138 m_ez.push_back(trkPosIn[2] + ze*10.0); // mm
139 m_et.push_back(te);
140 nE++;
141 }
142 }
143 m_nIonE = nE;
144 //delete m_track;
145}
146
147string IonizationGar::getParticle(int particle, int charge) const{
148 string particleName;
149 if((0==particle)&&(-1==charge)) {particleName = "electron";}
150 else if((0==particle)&&(1==charge)) {particleName = "e+";}
151 else if((1==particle)&&(1==charge)) {particleName = "mu+";}
152 else if((1==particle)&&(-1==charge)) {particleName = "mu-";}
153 else if((2==particle)&&(1==charge)) {particleName = "pi+";}
154 else if((2==particle)&&(-1==charge)) {particleName = "pi-";}
155 else if((3==particle)&&(1==charge)) {particleName = "K+";}
156 else if((3==particle)&&(-1==charge)) {particleName = "K-";}
157 else if((4==particle)&&(1==charge)) {particleName = "p";}
158 else if((4==particle)&&(-1==charge)) {particleName = "p-bar";}
159 else if((5==particle)&&(1==charge)) {particleName = "d";}
160 else if((6==particle)&&(2==charge)) {particleName = "alpha";}
161 else {
162 cout << "IonizationGar::getParticle() error";
163 particleName = "error";
164 }
165 return particleName;
166}
167
168void IonizationGar::clear(){
169 m_nIonE = 0;
170 m_ex.clear();
171 m_ey.clear();
172 m_ez.clear();
173 m_et.clear();
174}
175
176void IonizationGar::initGeoGas(){
177 randomEngine.Seed(m_random);
178 m_gas = new MediumMagboltz();
179 m_gas->SetComposition("ar",90.,"isobutane",10.);
180 m_gas->SetTemperature(293.15);
181 m_gas->SetPressure(760.0);
182 m_gas->SetMaxElectronEnergy(200.);
183 m_gas->EnablePenningTransfer(0.44, 0.0, "Ar");
184 m_gas->Initialise(true);
185
186 m_box = new SolidBox(0., 0., 0., 10., 10., 10.); // center and half length
187
188 m_geo = new GeometrySimple();
189 m_geo->AddSolid(m_box, m_gas);
190
191 m_comp = new ComponentAnalyticField();
192 if(m_debugging) m_comp->EnableDebugging();
193 else m_comp->DisableDebugging();
194 m_comp->SetGeometry(m_geo);
195
196 m_sensor = new Sensor();
197 if(m_debugging) m_sensor->EnableDebugging();
198 else m_sensor->DisableDebugging();
199 m_sensor->AddComponent(m_comp);
200}
double length
void setTrack(int particle, int charge, double p, double trkPosIn[], double trkPosOut[])
void init(unsigned int random, ICgemGeomSvc *geomSvc, double magConfig)