GEMC  1.8
Geant4 Monte-Carlo Framework
bmt_strip.cc
Go to the documentation of this file.
1 // %%%%%%%%%%%%%
2 // gemc headers
3 // %%%%%%%%%%%%%
4 #include "bmt_strip.h"
5 #include "Randomize.hh"
6 #include <iostream>
7 #include <cmath>
8 #include <cstdlib>
9 
11 {
12  // all dimensions are in mm
13 
14  Pi = 3.14159265358;
15  interlayer = 16.0;
16  pitchZ = 0.540;
17  pitchC = 0.270;
18  Nsector = 3;
19  hDrift = 3.0;
20  hStrip2Det = hDrift/2.;
21  sigma_td_max = 0.4;
22  theta_L = Pi*20./180.;
23  w_i = 25.0;
24 
25  DZ_inLength = 7.5;
26  DZ_inWidth = 7.5;
27 
28  // z of the upstream part of the layer
29  Z0.push_back(-127.000); Z0.push_back(-127.000);
30  Z0.push_back(-148.000); Z0.push_back(-148.000);
31  Z0.push_back(-172.500); Z0.push_back(-172.500);
32 
33 // total z length of the layer of the layer
34  DZ.push_back(370.5); DZ.push_back(370.5);
35  DZ.push_back(420.1); DZ.push_back(420.1);
36  DZ.push_back(444.6); DZ.push_back(444.6);
37 
38  // radii of layers
39  R.push_back(146.900); R.push_back(R[0]+interlayer);
40  R.push_back(178.900); R.push_back(R[2]+interlayer);
41  R.push_back(210.900); R.push_back(R[4]+interlayer);
42 
43  // Number of strips (depends on radius, dead zones, and pitch!)
44  for(int i=0;i<6;i++)
45  { // layer 0,2,4 are Z detectors, i.e. measure phi (strips along z)
46  if((i%2)==0) Nstrips.push_back((int) ((2.*Pi*R[i]/((double) Nsector)-2.*DZ_inLength)/pitchZ));
47  if((i%2)==1) Nstrips.push_back((int) ((DZ[i]-2.*DZ_inWidth)/pitchC));
48  }
49 
50  // mid angle of the sector
51  MidTile.push_back(0); MidTile.push_back(0);
52  MidTile.push_back(0); MidTile.push_back(0);
53  MidTile.push_back(0); MidTile.push_back(0);
54 }
55 
56 vector<double> bmt_strip::FindStrip(int layer, int sector, double x, double y, double z, double Edep)
57 {
58  // the return vector is always in pairs.
59  // The first number is the ID,
60  // the second number is the sharing percentage
61  vector<double> strip_id;
62 
63  // number of electrons (Nt)
64  Nel = (int) (1e6*Edep/w_i);
65 
66  // 1st define phi of the mean hit point
67  double phi;
68  if(x>0 && y>=0) phi = atan(y/x);
69  else if(x>0 && y<0) phi = 2.*Pi+atan(y/x);
70  else if(x<0) phi = Pi+atan(y/x);
71  else if(x==0 && y>0) phi = Pi/2.;
72  else if(x==0 && y<0) phi = 3.*Pi/2.;
73  else phi = 0; // x = y = 0, phi not defined
74 
75  // now find the tile number (transverse diffusion will not change that)
76  int ti=0;
77  double theta_tmp=0;
78  for(int t=0; t<Nsector; t++)
79  {
80  theta_tmp = MidTile[layer]+2.*t*Pi/Nsector;
81  if(theta_tmp>2.*Pi) theta_tmp = theta_tmp - 2.*Pi;
82  if(theta_tmp<0) theta_tmp = theta_tmp + 2.*Pi;
83  if(fabs(phi-theta_tmp)<Pi/Nsector || fabs(2.*Pi-fabs(phi-theta_tmp))<Pi/Nsector) ti=t; // gives tile #
84  }
85 
86  double phiij = MidTile[layer]+2.*ti*Pi/Nsector;
87  if(phi-phiij<=-Pi/Nsector) phi = phi+2.*Pi;
88  if(phi-phiij>Pi/Nsector) phi = phi-2.*Pi;
89  if(phi-phiij<=-Pi/Nsector || phi-phiij>Pi/Nsector) cout << "WARNING: incorrect phi value in BMT: " << phi*180./Pi << " vs " << phiij*180./Pi << endl;
90  int ClosestStrip=0;
91 
92  // now compute the sigma of the (transverse) dispersion for this interaction
93  if((layer%2)==1) sigma_td = sigma_td_max* sqrt((sqrt(x*x+y*y)-R[layer]+hStrip2Det)/hDrift); // "C" det, transverse diffusion grows with square root of distance
94  else sigma_td = sigma_td_max* sqrt((sqrt(x*x+y*y)-R[layer]+hStrip2Det)/(cos(theta_L)*hDrift)); // same, but "Z" detectors, so Lorentz angle makes drift distance longer by 1./cos(theta_L) . Means sigma_td can be larger than sigma_td_max
95 
96  if(Nel>0)
97  {
98  for(int iel=0;iel<Nel;iel++)
99  { // loop over (total) electrons
100  if((layer%2)==1)
101  { // this for "C" layers, i.e. measuring z
102  z_real = (double) (G4RandGauss::shoot(z,sigma_td));
103  ClosestStrip = (int) (floor(((z_real-Z0[layer]-DZ_inWidth)/pitchC))+0.5);
104  }
105  if((layer%2)==0)
106  { // this for "Z" layers, i.e. measuring phi
107  phi_real = phi + ((G4RandGauss::shoot(0,sigma_td))/cos(theta_L)-(sqrt(x*x+y*y)-R[layer]+hStrip2Det)*tan(theta_L))/R[layer]; // the sign of the 2nd term (Lorentz angle) should be a "-" as the B field is along +z and the MM are convex (and electrons are negatively charged)
108  ClosestStrip = (int) (floor(((R[layer]/pitchZ)*(phi_real-phiij+Pi/Nsector-DZ_inLength/R[layer]))+0.5));
109  }
110  if(ClosestStrip>=0 && ClosestStrip<=Nstrips[layer] && z>=Z0[layer]+DZ_inWidth && z<=Z0[layer]+DZ[layer]-DZ_inWidth && phi>=phiij-Pi/Nsector+DZ_inLength/R[layer] && phi<=phiij+Pi/Nsector-DZ_inLength/R[layer])
111  { // strip is in the acceptance, check if new strip or not
112  for(int istrip=0;istrip< (int) (strip_id.size()/2);istrip++)
113  {
114  if(strip_id[2*istrip]==ClosestStrip)
115  {// already hit strip - add Edep
116  strip_id[2*istrip+1]=strip_id[2*istrip+1]+1./((double) Nel); // no gain fluctuation yet
117  ClosestStrip=-1; // not to use it anymore
118  }
119  }
120  if(ClosestStrip>-1)
121  { // this is a new strip
122  strip_id.push_back(ClosestStrip);
123  strip_id.push_back(1./((double) Nel)); // no gain fluctuation yet
124  }
125  }
126  else
127  { // not in the acceptance
128  strip_id.push_back(-1);
129  strip_id.push_back(1);
130  }
131  }
132  }
133  else
134  { // Nel=0, consider the Edep is 0
135  strip_id.push_back(-1);
136  strip_id.push_back(1);
137  }
138  return strip_id;
139 }
140 
double z_real
Definition: bmt_strip.h:36
double sigma_td_max
Definition: bmt_strip.h:31
double y
Definition: bmt_strip.h:41
vector< double > MidTile
Definition: bmt_strip.h:26
int Nel
Definition: bmt_strip.h:35
vector< double > DZ
Definition: bmt_strip.h:24
double sigma_td
Definition: bmt_strip.h:32
double DZ_inWidth
Definition: bmt_strip.h:39
double interlayer
Definition: bmt_strip.h:22
double hDrift
Definition: bmt_strip.h:29
double phi_real
Definition: bmt_strip.h:36
double pitchC
Definition: bmt_strip.h:18
double pitchZ
Definition: bmt_strip.h:18
void fill_infos()
Definition: bmt_strip.cc:10
vector< double > R
Definition: bmt_strip.h:25
double w_i
Definition: bmt_strip.h:34
vector< double > Z0
Definition: bmt_strip.h:23
double DZ_inLength
Definition: bmt_strip.h:38
double x
Definition: bmt_strip.h:41
double hStrip2Det
Definition: bmt_strip.h:30
int Nsector
Definition: bmt_strip.h:19
double theta_L
Definition: bmt_strip.h:33
double Pi
Definition: bmt_strip.h:20
double z
Definition: bmt_strip.h:41
vector< double > FindStrip(int layer, int sector, double x, double y, double z, double Edep)
Definition: bmt_strip.cc:56
vector< int > Nstrips
Definition: bmt_strip.h:27