StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StRHICfPID.cxx
1 #include "StRHICfPID.h"
2 
3 StRHICfPID::StRHICfPID()
4 {
5  init();
6 }
7 
8 void StRHICfPID::init()
9 {
10  std::fill(mPID, mPID+kRHICfNtower, -1);
11  std::fill(mPlateSumE, mPlateSumE+kRHICfNtower, 0.);
12  std::fill(mL20, mL20+kRHICfNtower, 0.);
13  std::fill(mL90, mL90+kRHICfNtower, 0.);
14  std::fill(&mPlateE[0][0], &mPlateE[kRHICfNtower-1][kRHICfNplate], 0.);
15 }
16 
17 void StRHICfPID::setPlateEnergy(int tower, int layer, float val)
18 {
19  mPlateE[tower][layer] = val;
20 }
21 
22 int StRHICfPID::getPID(int tower){return mPID[tower];}
23 float StRHICfPID::getL20(int tower){return mL20[tower];}
24 float StRHICfPID::getL90(int tower){return mL90[tower];}
25 
26 bool StRHICfPID::calculate()
27 {
28  for(int it=0; it<kRHICfNtower; it++){
29  for(int ip=0; ip<mPlateIdxNum; ip++){mPlateSumE[it] += layerSumEnergy(it, ip);}
30  mPlateSumE[it] += mPlateE[it][0];
31 
32  mL20[it] = findRadiationLength(it, mL20Const);
33  mL90[it] = findRadiationLength(it, mL90Const);
34 
35  if(mL90[it] <= 0.15 * mL20[it] + 20){mPID[it] = kRHICfPhoton;}
36  else{mPID[it] = kRHICfHadron;}
37  }
38 
39  std::cout << "StRHICfPID::calculate() -- Done " << std::endl;
40  return kRHICfOk;
41 }
42 
43 float StRHICfPID::checkStep(int layer)
44 {
45  if(layer <= 10){return 2.;}
46  return 4.;
47 }
48 
49 float StRHICfPID::layerSumEnergy(int tower, int layer)
50 {
51  float tmpSumE = (mPlateE[tower][layer] + mPlateE[tower][layer+1]) *checkStep(layer) /2.;
52  return tmpSumE;
53 }
54 
55 float StRHICfPID::findRadiationLength(int tower, float ratio)
56 {
57  float tmpSumE = mPlateSumE[tower]*ratio;
58  float length = 2.;
59  tmpSumE -= mPlateE[tower][0];
60 
61  for(int ip=0; ip<mPlateIdxNum; ip++){
62  float tmpLength = calculateEquation(tower, ip, tmpSumE);
63 
64  if(tmpLength >= 0.){
65  length += tmpLength;
66  return length;
67  }
68  else{
69  length += checkStep(ip);
70  tmpSumE -= layerSumEnergy(tower, ip);
71  }
72  }
73 
74  return 0.1;
75 }
76 
77 float StRHICfPID::calculateEquation(int tower, int layer, float sumE)
78 {
79  // Define the equation : constA*x^2 + constB*x + constC = 0
80  float constA = (mPlateE[tower][layer+1] - mPlateE[tower][layer])/checkStep(layer);
81  float constB = 2. * mPlateE[tower][layer];
82  float constC = -2. * sumE;
83 
84  // Case: No solution to the equation.
85  if(constB*constB - 4.*constA*constC < 0.){return -1;}
86 
87  // Case: 2 solution.
88  float solA = (-1. *constB - TMath::Sqrt(constB *constB -4. *constA *constC))/(2. *constA);
89  float solB = (-1. *constB + TMath::Sqrt(constB *constB -4. *constA *constC))/(2. *constA);
90 
91  if(solA >= 0. && solA <= checkStep(layer)){return solA;}
92  if(solB >= 0. && solB <= checkStep(layer)){return solB;}
93 
94  return -1.;
95 }