ROOT logo
//*-- Author : Ilse Koenig
//*-- Modified : 10/11/2003 by Ilse Koenig

//_HADES_CLASS_DESCRIPTION 
////////////////////////////////////////////////////////////////////////////////
//
//  Class for tracking medium ( includes also material )
//
////////////////////////////////////////////////////////////////////////////////

#include "hgeommedium.h"
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>

ClassImp(HGeomMedium)

HGeomMedium::HGeomMedium(const Char_t* name) : TNamed() {
  // Constructor for a medium with name and index id
  SetName(name); 
  medId=0;
  autoflag=1;
  nComponents=0;
  weightFac=0;
  ca=0;
  cz=0;
  cw=0;
  density=0.;
  radLen=0.;
  sensFlag=0;
  fldFlag=0;
  fld=0.;
  epsil=0.;
  madfld=0.;
  maxstep=0.;
  maxde=0.;
  minstep=0.;
  npckov=0;
  ppckov=0;
  absco=0;
  effic=0;
  rindex=0;
};

HGeomMedium::~HGeomMedium() {
  // Destructor
  if (nComponents>0) {
    delete [] ca;
    ca=0;
    delete [] cz;
    cz=0;
    delete [] cw;
    cw=0;
    nComponents=0;
  }
  if (npckov>0) {
    delete [] ppckov;
    ppckov=0;
    delete [] absco;
    absco=0;
    delete [] effic;
    effic=0;
    delete [] rindex;
    rindex=0;
    npckov=0;
  }
}

void HGeomMedium::setNComponents(Int_t n) {
  // Sets the number of components in the material
  if (n==0) return;
  Int_t k=abs(n);
  if (nComponents!=0 && k!=nComponents) {
    delete [] ca;
    delete [] cz;
    delete [] cw;
    nComponents=0;
  }
  if (nComponents==0) {
    nComponents=k;
    ca=new Double_t[k];  
    cz=new Double_t[k];  
    cw=new Double_t[k];
  }
  weightFac=(Int_t)(n/nComponents);
}  

Bool_t HGeomMedium::setComponent (Int_t i,Double_t a,Double_t z,Double_t weight) {
  // Defines the ith material component
  if (i<0||i>=nComponents) {
    Error("setNComponents","Wrong index");
    return kFALSE;
  }
  ca[i]=a;
  cz[i]=z;
  cw[i]=weight;
  return kTRUE;     
}

void HGeomMedium::getComponent(Int_t i,Double_t* p) {
  // Returns the ith material component
  if (i>=0&&i<nComponents) {
    p[0]=ca[i];
    p[1]=cz[i];
    p[2]=cw[i];
  } else p[0]=p[1]=p[2]=0.; 
}

void HGeomMedium::setNpckov (Int_t n) {
  // Sets the number of optical parameters for the tracking of Cerenkov light
  if (n!=npckov && npckov>0) {
    delete [] ppckov;
    delete [] absco;
    delete [] effic;
    delete [] rindex;
  }
  npckov=n;
  if (n>0) {
    ppckov=new Double_t[npckov];
    absco=new Double_t[npckov];  
    effic=new Double_t[npckov];  
    rindex=new Double_t[npckov];  
  }
}

Bool_t HGeomMedium::setCerenkovPar(Int_t i,Double_t p,Double_t a,Double_t e ,Double_t r) {  
  // Defines the ith parameter set of the optical parameters
  if (i<0 || i>=npckov) {
    Error("setNpckov","Wrong index");
    return kFALSE;
  }
  ppckov[i]=p;
  absco[i]=a;
  effic[i]=e;
  rindex[i]=r;
  return kTRUE;     
}

void HGeomMedium::getCerenkovPar(Int_t i,Double_t* p) {
  // returns the ith parameter set of the optical parameters
  if (i>=0&&i<npckov) {
    p[0]=ppckov[i];
    p[1]=absco[i];
    p[2]=effic[i];
    p[3]=rindex[i];
  } else p[0]=p[1]=p[2]=p[3]=0.;
}

void HGeomMedium::setMediumPar(Int_t sensitivityFlag,Int_t fieldFlag,
              Double_t maxField,Double_t precision,Double_t maxDeviation,
              Double_t maxStep,Double_t maxDE,Double_t minStep ) { 
  // Sets the medium parameters
  sensFlag=sensitivityFlag;
  fldFlag=fieldFlag;
  fld=maxField;
  epsil=precision;
  madfld=maxDeviation;
  maxstep=maxStep;
  maxde=maxDE;
  minstep=minStep;
}

void HGeomMedium::getMediumPar(Double_t* params) {
  // Returns the medium parameters
  params[0]=sensFlag;
  params[1]=fldFlag;
  params[2]=fld;
  params[3]=madfld;
  params[4]=maxstep;
  params[5]=maxde;
  params[6]=epsil;
  params[7]=minstep;
  params[8]=0.;
  params[9]=0.;
}

void HGeomMedium::read(fstream& fin, Int_t aflag ) {
  // Reads the parameters from file
  autoflag=aflag;
  Int_t n;
  fin>>n;
  setNComponents(n);  
  for(Int_t i=0;i<nComponents;i++) {
    fin>>ca[i];
  }
  for(Int_t i=0;i<nComponents;i++) {
    fin>>cz[i];
  }
  fin>>density;
  if (nComponents<2) {
    fin>>radLen;
    cw[0]=1.;
  } else {
    for(Int_t i=0;i<nComponents;i++) {
      fin>>cw[i];
    }
  }
  fin>>sensFlag>>fldFlag>>fld>>epsil ;
  if (autoflag<1) fin>>madfld>>maxstep>>maxde>>minstep;
  fin>>n;
  setNpckov(n);
  if (n>0) {
    for(Int_t i=0;i<n;i++)
      fin>>ppckov[i]>>absco[i]>>effic[i]>>rindex[i];
  }
}

void HGeomMedium::print() {
  // Prints the medium definition
  const Char_t* bl="  ";
  cout<<GetName()<<'\n'<<nComponents*weightFac<<bl;
  for(Int_t i=0;i<nComponents;i++) { cout<<ca[i]<<bl ;}
  for(Int_t i=0;i<nComponents;i++) { cout<<cz[i]<<bl ;}
  cout<<density<<bl;
  if (nComponents<2) cout<<radLen;
  else for(Int_t i=0;i<nComponents;i++) { cout<<cw[i]<<bl ;}
  cout<<'\n'<<sensFlag<<bl<<fldFlag<<bl<<fld<<bl<<epsil<<'\n';
  if (autoflag<1)
    cout<<madfld<<bl<<maxstep<<bl<<maxde<<bl<<minstep<<'\n';
  cout<<npckov<<'\n';
  if (npckov>0) {
    for(Int_t i=0;i<npckov;i++) {
      cout<<ppckov[i]<< bl<<absco[i]<<bl<<effic[i]<<bl<<rindex[i]<<'\n';
    }
  }
  cout<<'\n';
}

void HGeomMedium::write (fstream& fout) {
  // Writes the medium definition into stream
  const Char_t* bl="  ";
  fout<<GetName()<<'\n'<<nComponents*weightFac<<bl;
  for(Int_t i=0;i<nComponents;i++) { fout<<ca[i]<<bl ;}
  for(Int_t i=0;i<nComponents;i++) { fout<<cz[i]<<bl ;}
  fout<<density<<bl;
  if (nComponents<2) fout<<radLen;
  else for(Int_t i=0;i<nComponents;i++) { fout<<cw[i]<<bl ;}
  fout<<'\n'<<sensFlag<<bl<<fldFlag<<bl<<fld<<bl<<epsil<<'\n';
  if (autoflag<1)
    fout<<madfld<<bl<<maxstep<<bl<<maxde<<bl<<minstep<<'\n';
  fout<<npckov<<'\n';
  if (npckov>0) {
    for(Int_t i=0;i<npckov;i++) {
      fout<<ppckov[i]<< bl<<absco[i]<<bl<<effic[i]<<bl<<rindex[i]<<'\n';
    }
  }
  fout<<'\n';
}

Bool_t HGeomMedium::calcRadiationLength() {
  // calculates radiation length
  // formula in GEANT manual CONS110
  if (cz[0]<1.e-6) { // VAKUUM$
    radLen=1.e+16;
    return kTRUE;
  }
  Double_t alpha=1/137.;     // fine structure constant
  Double_t fac=.1912821;     // 4*((electron radius)**2)*(avogadro's number)
  Double_t z, a, w, az2, fc, y, xi, x0i, amol=0., x0itot=0.;
  if (weightFac>0) amol=1.;
  else {
    for (Int_t i=0;i<nComponents;i++) {
      amol+=cw[i]*ca[i];
      if (amol==0.) {
        Error("calcRadiationLength()","amol==0 for medium %s",fName.Data());
        return kFALSE;
      }
    }
  }
  for (Int_t i=0;i<nComponents;i++) {
    z=cz[i];
    a=ca[i];
    if (weightFac>0) w=cw[i]/amol;
    else w=cw[i]*a/amol;
    az2=alpha*alpha*z*z;
    fc=az2 * (1./(1.+az2) + 0.20206 - 0.0369*az2 + 0.0083*az2*az2
              - .002F*az2*az2*az2);
    y=log(183./pow(z,1./3.)) - fc;
    xi=(float)(log(1440./pow(z,2./3.)) / y);
    x0i=fac*alpha/a*z*(z+xi)*y;
    x0itot+=(x0i*w);
  }
  if (x0itot==0. || density==0.) {
    Error("calcRadiationLength()","x0itot=0 or density=0 for medium %s",fName.Data());
    return kFALSE;
  }
  radLen=1/density/x0itot;
  return kTRUE;
}
 hgeommedium.cc:1
 hgeommedium.cc:2
 hgeommedium.cc:3
 hgeommedium.cc:4
 hgeommedium.cc:5
 hgeommedium.cc:6
 hgeommedium.cc:7
 hgeommedium.cc:8
 hgeommedium.cc:9
 hgeommedium.cc:10
 hgeommedium.cc:11
 hgeommedium.cc:12
 hgeommedium.cc:13
 hgeommedium.cc:14
 hgeommedium.cc:15
 hgeommedium.cc:16
 hgeommedium.cc:17
 hgeommedium.cc:18
 hgeommedium.cc:19
 hgeommedium.cc:20
 hgeommedium.cc:21
 hgeommedium.cc:22
 hgeommedium.cc:23
 hgeommedium.cc:24
 hgeommedium.cc:25
 hgeommedium.cc:26
 hgeommedium.cc:27
 hgeommedium.cc:28
 hgeommedium.cc:29
 hgeommedium.cc:30
 hgeommedium.cc:31
 hgeommedium.cc:32
 hgeommedium.cc:33
 hgeommedium.cc:34
 hgeommedium.cc:35
 hgeommedium.cc:36
 hgeommedium.cc:37
 hgeommedium.cc:38
 hgeommedium.cc:39
 hgeommedium.cc:40
 hgeommedium.cc:41
 hgeommedium.cc:42
 hgeommedium.cc:43
 hgeommedium.cc:44
 hgeommedium.cc:45
 hgeommedium.cc:46
 hgeommedium.cc:47
 hgeommedium.cc:48
 hgeommedium.cc:49
 hgeommedium.cc:50
 hgeommedium.cc:51
 hgeommedium.cc:52
 hgeommedium.cc:53
 hgeommedium.cc:54
 hgeommedium.cc:55
 hgeommedium.cc:56
 hgeommedium.cc:57
 hgeommedium.cc:58
 hgeommedium.cc:59
 hgeommedium.cc:60
 hgeommedium.cc:61
 hgeommedium.cc:62
 hgeommedium.cc:63
 hgeommedium.cc:64
 hgeommedium.cc:65
 hgeommedium.cc:66
 hgeommedium.cc:67
 hgeommedium.cc:68
 hgeommedium.cc:69
 hgeommedium.cc:70
 hgeommedium.cc:71
 hgeommedium.cc:72
 hgeommedium.cc:73
 hgeommedium.cc:74
 hgeommedium.cc:75
 hgeommedium.cc:76
 hgeommedium.cc:77
 hgeommedium.cc:78
 hgeommedium.cc:79
 hgeommedium.cc:80
 hgeommedium.cc:81
 hgeommedium.cc:82
 hgeommedium.cc:83
 hgeommedium.cc:84
 hgeommedium.cc:85
 hgeommedium.cc:86
 hgeommedium.cc:87
 hgeommedium.cc:88
 hgeommedium.cc:89
 hgeommedium.cc:90
 hgeommedium.cc:91
 hgeommedium.cc:92
 hgeommedium.cc:93
 hgeommedium.cc:94
 hgeommedium.cc:95
 hgeommedium.cc:96
 hgeommedium.cc:97
 hgeommedium.cc:98
 hgeommedium.cc:99
 hgeommedium.cc:100
 hgeommedium.cc:101
 hgeommedium.cc:102
 hgeommedium.cc:103
 hgeommedium.cc:104
 hgeommedium.cc:105
 hgeommedium.cc:106
 hgeommedium.cc:107
 hgeommedium.cc:108
 hgeommedium.cc:109
 hgeommedium.cc:110
 hgeommedium.cc:111
 hgeommedium.cc:112
 hgeommedium.cc:113
 hgeommedium.cc:114
 hgeommedium.cc:115
 hgeommedium.cc:116
 hgeommedium.cc:117
 hgeommedium.cc:118
 hgeommedium.cc:119
 hgeommedium.cc:120
 hgeommedium.cc:121
 hgeommedium.cc:122
 hgeommedium.cc:123
 hgeommedium.cc:124
 hgeommedium.cc:125
 hgeommedium.cc:126
 hgeommedium.cc:127
 hgeommedium.cc:128
 hgeommedium.cc:129
 hgeommedium.cc:130
 hgeommedium.cc:131
 hgeommedium.cc:132
 hgeommedium.cc:133
 hgeommedium.cc:134
 hgeommedium.cc:135
 hgeommedium.cc:136
 hgeommedium.cc:137
 hgeommedium.cc:138
 hgeommedium.cc:139
 hgeommedium.cc:140
 hgeommedium.cc:141
 hgeommedium.cc:142
 hgeommedium.cc:143
 hgeommedium.cc:144
 hgeommedium.cc:145
 hgeommedium.cc:146
 hgeommedium.cc:147
 hgeommedium.cc:148
 hgeommedium.cc:149
 hgeommedium.cc:150
 hgeommedium.cc:151
 hgeommedium.cc:152
 hgeommedium.cc:153
 hgeommedium.cc:154
 hgeommedium.cc:155
 hgeommedium.cc:156
 hgeommedium.cc:157
 hgeommedium.cc:158
 hgeommedium.cc:159
 hgeommedium.cc:160
 hgeommedium.cc:161
 hgeommedium.cc:162
 hgeommedium.cc:163
 hgeommedium.cc:164
 hgeommedium.cc:165
 hgeommedium.cc:166
 hgeommedium.cc:167
 hgeommedium.cc:168
 hgeommedium.cc:169
 hgeommedium.cc:170
 hgeommedium.cc:171
 hgeommedium.cc:172
 hgeommedium.cc:173
 hgeommedium.cc:174
 hgeommedium.cc:175
 hgeommedium.cc:176
 hgeommedium.cc:177
 hgeommedium.cc:178
 hgeommedium.cc:179
 hgeommedium.cc:180
 hgeommedium.cc:181
 hgeommedium.cc:182
 hgeommedium.cc:183
 hgeommedium.cc:184
 hgeommedium.cc:185
 hgeommedium.cc:186
 hgeommedium.cc:187
 hgeommedium.cc:188
 hgeommedium.cc:189
 hgeommedium.cc:190
 hgeommedium.cc:191
 hgeommedium.cc:192
 hgeommedium.cc:193
 hgeommedium.cc:194
 hgeommedium.cc:195
 hgeommedium.cc:196
 hgeommedium.cc:197
 hgeommedium.cc:198
 hgeommedium.cc:199
 hgeommedium.cc:200
 hgeommedium.cc:201
 hgeommedium.cc:202
 hgeommedium.cc:203
 hgeommedium.cc:204
 hgeommedium.cc:205
 hgeommedium.cc:206
 hgeommedium.cc:207
 hgeommedium.cc:208
 hgeommedium.cc:209
 hgeommedium.cc:210
 hgeommedium.cc:211
 hgeommedium.cc:212
 hgeommedium.cc:213
 hgeommedium.cc:214
 hgeommedium.cc:215
 hgeommedium.cc:216
 hgeommedium.cc:217
 hgeommedium.cc:218
 hgeommedium.cc:219
 hgeommedium.cc:220
 hgeommedium.cc:221
 hgeommedium.cc:222
 hgeommedium.cc:223
 hgeommedium.cc:224
 hgeommedium.cc:225
 hgeommedium.cc:226
 hgeommedium.cc:227
 hgeommedium.cc:228
 hgeommedium.cc:229
 hgeommedium.cc:230
 hgeommedium.cc:231
 hgeommedium.cc:232
 hgeommedium.cc:233
 hgeommedium.cc:234
 hgeommedium.cc:235
 hgeommedium.cc:236
 hgeommedium.cc:237
 hgeommedium.cc:238
 hgeommedium.cc:239
 hgeommedium.cc:240
 hgeommedium.cc:241
 hgeommedium.cc:242
 hgeommedium.cc:243
 hgeommedium.cc:244
 hgeommedium.cc:245
 hgeommedium.cc:246
 hgeommedium.cc:247
 hgeommedium.cc:248
 hgeommedium.cc:249
 hgeommedium.cc:250
 hgeommedium.cc:251
 hgeommedium.cc:252
 hgeommedium.cc:253
 hgeommedium.cc:254
 hgeommedium.cc:255
 hgeommedium.cc:256
 hgeommedium.cc:257
 hgeommedium.cc:258
 hgeommedium.cc:259
 hgeommedium.cc:260
 hgeommedium.cc:261
 hgeommedium.cc:262
 hgeommedium.cc:263
 hgeommedium.cc:264
 hgeommedium.cc:265
 hgeommedium.cc:266
 hgeommedium.cc:267
 hgeommedium.cc:268
 hgeommedium.cc:269
 hgeommedium.cc:270
 hgeommedium.cc:271
 hgeommedium.cc:272
 hgeommedium.cc:273
 hgeommedium.cc:274
 hgeommedium.cc:275
 hgeommedium.cc:276
 hgeommedium.cc:277
 hgeommedium.cc:278
 hgeommedium.cc:279
 hgeommedium.cc:280
 hgeommedium.cc:281
 hgeommedium.cc:282
 hgeommedium.cc:283
 hgeommedium.cc:284
 hgeommedium.cc:285
 hgeommedium.cc:286
 hgeommedium.cc:287
 hgeommedium.cc:288
 hgeommedium.cc:289
 hgeommedium.cc:290