EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MediaSliceArray.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MediaSliceArray.cxx
1 //
2 // AYK (ayk@bnl.gov), shaped up in Nov'2015;
3 //
4 // Array of media slices;
5 //
6 
7 #include <cassert>
8 #include <cstdlib>
9 #include <cstring>
10 
11 #include <htclib.h>
12 
13 #include <MediaBank.h>
14 #include <MediaSliceArray.h>
15 
16 // ---------------------------------------------------------------------------------------
17 
19  mZ0(0.0), mThickness(0.0)
20 {
21  // Does this make sense; well, if "bank" was not initialized
22  // for some reason, I will have an empty slice array, fine;
23  if (!bank) return;
24 
25  // Well, this is not too much efficient, but done only once and
26  // does not consume too much CPU anyway;
27  for(int iq=0; iq<bank->GetMediaLayerCount(); iq++) {
28  const MediaLayer *mlayer = bank->GetMediaLayer(iq);
29 
30  // Media layer does not belong to the searched [z1,z2] range;
31  if (mlayer->GetZ0() + mlayer->GetThickness() < z1) continue;
32  if (mlayer->GetZ0() > z2) break;
33 
34  double z0 = mlayer->GetZ0() < z1 ? z1 : mlayer->GetZ0();
35  double thickness = (mlayer->GetZ0() + mlayer->GetThickness() < z2 ?
36  mlayer->GetZ0() + mlayer->GetThickness() : z2) - z0;
37  mMediaSlices.push_back(MediaSlice(mlayer, z0, thickness));
38  } //for iq
39 
40  // Sanity check; well, allow nodes outside of media scan area; typically
41  // these are nodes at negative Z (for vertex building); print a warning and assume
42  // that these nodes are at pure vacuum;
43  if (!mMediaSlices.size()) {
44  //printf("Warning: Z range [%7.1f .. %7.1f]cm - no media scan data, assume vacuum!\n",
45  // z1, z2);
46 
47  return;
48  } //if
49 
50  // Array's 'mZ0' is inherited from the very first slice;
51  mZ0 = mMediaSlices[0].GetZ0();
52 
53  // Now when all slices in the array are known, calculate effective A and Z;
54  for(int iq=0; iq<mMediaSlices.size(); iq++) {
55  MediaSlice *mslice = &mMediaSlices[iq];
56 
57  // Yes, I'm interested in "effective" thickness, namely the area
58  // where material slices are present;
59  mThickness += mslice->GetThickness();
60  } //for iq
61 } // MediaSliceArray::MediaSliceArray()
62 
63 // ---------------------------------------------------------------------------------------
64 
65 double MediaSliceArray::GetDE(t_particle_group *pgroup, int charge, double e0_kin)
66 {
67  double de_sum = 0.;
68 
69  // Do it more efficiently if CPU ever becomes a problem (at least
70  // merge same {A,Z} elements in all slices; or even create
71  // some sort of a look-up table;
72  for(int iq=0; iq<mMediaSlices.size(); iq++) {
73  MediaSlice *mslice = &mMediaSlices[iq];
74  TGeoMaterial *material = mslice->GetMediaLayer()->GetMaterial();
75 
76  // Really that strong?; relieve later;
77  //assert(material);
78 
79  switch (pgroup->dE_dx_model) {
80  case _DEDX_HADRON_:
81  for(int el=0; el<material->GetNelements(); el++) {
82  float de_dx;
83  double ad, zd, wd;
84  material->GetElementProp(ad, zd, wd, el);
85 
86  // Basically skip pure vacuum elements;
87  if (!zd) continue;
88 
89  // Consider 'e0' to be constant; so in a certain sense losses
90  // along a given media slice array (read: between 2 neighboring
91  // Kalman filter nodes) are assumed to be small;
92  G3DRELX(ad, zd, wd*material->GetDensity(), e0_kin, pgroup->mass, de_dx);
93 
94  // Add respective fraction to the overall losses;
95  de_sum += wd * de_dx * material->GetDensity() * mslice->GetThickness();
96  } //for el
97  break;
98  // Think on electron energy losses later;
99 #if _LATER_
100  case _DEDX_ELECTRON_:
101  // Skip pure vacuum slices;
102  if (material->nlmat > 1 || material->A[0])
103  {
104  double de_dx_ionization, de_dx_bremsstrahlung;
105 
106  GDRELE(e0_kin, charge, material->POTL, material->FAC,
107  material->C, material->X0, material->X1, material->AA,
108  de_dx_ionization);
109 
110  // This fraction appears to be suspiciously small; check later;
111  GBRELA(material->nlmat, material->wmat, material->A, material->Z,
112  // Convert density to g/cm3 here; @@@MM@@
114  material->AAVG, material->ZAVG, material->_density, e0_kin,
115  charge, de_dx_bremsstrahlung);
116  //printf("--> %f %f %f\n", e0_kin, de_dx_ionization, de_dx_bremsstrahlung);
117 
118  // Add respective fraction to the overall losses;
119  de_sum += (de_dx_ionization + de_dx_bremsstrahlung)*
120  material->_density*mslice->thickness;
121  } /*if*/
122  break;
123 #endif
124  default:
125  assert(0);
126  } /*switch*/
127  } /*for iq*/
128 
129  return de_sum;
130 } // MediaSliceArray::GetDE()
131 
132 // ---------------------------------------------------------------------------------------