|
| 1 | + |
| 2 | + |
| 3 | +double BetheBloch(double energy, double mass){ |
| 4 | + |
| 5 | + //Need to make this configurable? Or delete... |
| 6 | + double K = .307075; |
| 7 | + double rho = 1.390; |
| 8 | + double Z = 18; |
| 9 | + double A = 40; |
| 10 | + double I = 188E-6; |
| 11 | + double me = .511; |
| 12 | + //Need to make sure this is total energy, not KE |
| 13 | + double gamma = energy/mass; |
| 14 | + double beta = sqrt( 1. - (1. / (gamma*gamma)) ); |
| 15 | + double Tmax = 2 * me * beta*beta * gamma*gamma; |
| 16 | + |
| 17 | + double first = K * (Z/A) * rho / (beta*beta); |
| 18 | + double second = .5 * log(Tmax*Tmax/(I*I)) - beta*beta; |
| 19 | + |
| 20 | + double dEdX = first*second; |
| 21 | + return dEdX; |
| 22 | +} |
| 23 | + |
| 24 | +std::vector< std::pair<double, int> > ThinSliceBetheBloch(G4ReweightTraj * theTraj, double res, double mass, bool isElastic){ |
| 25 | + |
| 26 | + std::vector< std::pair<double, int> > result; |
| 27 | + |
| 28 | + //First slice position |
| 29 | +// double sliceEdge = res; |
| 30 | +// double lastPos = 0.; |
| 31 | +// double nextPos = 0.; |
| 32 | +// double px,py,pz; |
| 33 | + int interactInSlice = 0; |
| 34 | + |
| 35 | + //Get total distance traveled in z |
| 36 | +// double totalDeltaZ = 0.; |
| 37 | + double disp = 0.; |
| 38 | +// double oldDisp = 0.; |
| 39 | +// int crossedSlices = 0; |
| 40 | + |
| 41 | + int currentSlice = 0; |
| 42 | + int oldSlice = 0; |
| 43 | + |
| 44 | + double sliceEnergy = theTraj->GetEnergy(); |
| 45 | + size_t nSteps = theTraj->GetNSteps(); |
| 46 | + for(size_t is = 0; is < nSteps; ++is){ |
| 47 | + auto theStep = theTraj->GetStep(is); |
| 48 | + |
| 49 | + disp += theStep->GetStepLength(); |
| 50 | + currentSlice = floor(disp/res); |
| 51 | + |
| 52 | + std::string theProc = theStep->GetStepChosenProc(); |
| 53 | + |
| 54 | + //Check to see if in a new slice and it's not the end |
| 55 | + if( oldSlice != currentSlice && is < nSteps - 1){ |
| 56 | + |
| 57 | + |
| 58 | + //Save Interaction info of the prev slice |
| 59 | + //and reset |
| 60 | + result.push_back( std::make_pair(sliceEnergy, interactInSlice) ); |
| 61 | + interactInSlice = 0; |
| 62 | + |
| 63 | + //Update the energy |
| 64 | + sliceEnergy = sliceEnergy - res*BetheBloch(sliceEnergy, mass); |
| 65 | + if( sliceEnergy - mass < 0.){ |
| 66 | + //std::cout << "Warning! Negative energy " << sliceEnergy - mass << std::endl; |
| 67 | + //std::cout << "Crossed " << oldSlice - currentSlice << std::endl; |
| 68 | + sliceEnergy = 0.0001; |
| 69 | + } |
| 70 | + //If it's more than 1 slice, add in non-interacting slices |
| 71 | + for(int ic = 1; ic < abs( oldSlice - currentSlice ); ++ic){ |
| 72 | + //std::cout << ic << std::endl; |
| 73 | + |
| 74 | + result.push_back( std::make_pair(sliceEnergy, 0) ); |
| 75 | + |
| 76 | + //Update the energy again |
| 77 | + sliceEnergy = sliceEnergy - res*BetheBloch(sliceEnergy, mass); |
| 78 | + if( sliceEnergy - mass < 0.){ |
| 79 | + //std::cout << "Warning! Negative energy " << sliceEnergy - mass << std::endl; |
| 80 | + //std::cout << "Crossed " << oldSlice - currentSlice << std::endl; |
| 81 | + sliceEnergy = 0.0001; |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + if ((!isElastic && theProc.find(std::string("Inelastic")) != std::string::npos) || (isElastic && theProc.find(std::string("hadElastic")) != std::string::npos)) { |
| 86 | + // std::cout << "found! " << theProc << '\n'; |
| 87 | + interactInSlice = 1; |
| 88 | + } |
| 89 | + } |
| 90 | + //It's crossed a slice and it's the last step. Save both info |
| 91 | + else if( oldSlice != currentSlice && is == nSteps - 1 ){ |
| 92 | + result.push_back( std::make_pair(sliceEnergy, interactInSlice) ); |
| 93 | + interactInSlice = 0; |
| 94 | + |
| 95 | + //Update the energy |
| 96 | + sliceEnergy = sliceEnergy - res*BetheBloch(sliceEnergy, mass); |
| 97 | + if( sliceEnergy - mass < 0.){ |
| 98 | + //std::cout << "Warning! Negative energy " << sliceEnergy - mass << std::endl; |
| 99 | + //std::cout << "Crossed " << oldSlice - currentSlice << std::endl; |
| 100 | + sliceEnergy = 0.0001; |
| 101 | + } |
| 102 | + //If it's more than 1 slice, add in non-interacting slices |
| 103 | + for(int ic = 1; ic < abs( oldSlice - currentSlice ); ++ic){ |
| 104 | + //std::cout << ic << std::endl; |
| 105 | + |
| 106 | + result.push_back( std::make_pair(sliceEnergy, 0) ); |
| 107 | + |
| 108 | + //Update the energy again |
| 109 | + sliceEnergy = sliceEnergy - res*BetheBloch(sliceEnergy, mass); |
| 110 | + if( sliceEnergy - mass < 0.){ |
| 111 | + //std::cout << "Warning! Negative energy " << sliceEnergy - mass << std::endl; |
| 112 | + //std::cout << "Crossed " << oldSlice - currentSlice << std::endl; |
| 113 | + sliceEnergy = 0.0001; |
| 114 | + } |
| 115 | + } |
| 116 | + |
| 117 | + //Save the last slice |
| 118 | + if ((!isElastic && theProc.find(std::string("Inelastic")) != std::string::npos) || (isElastic && theProc.find(std::string("hadElastic")) != std::string::npos)) { |
| 119 | + // std::cout << "found! " << theProc << '\n'; |
| 120 | + interactInSlice = 1; |
| 121 | + } |
| 122 | + result.push_back( std::make_pair(sliceEnergy, interactInSlice) ); |
| 123 | + } |
| 124 | + //It's the end, so just save this last info |
| 125 | + else if( oldSlice == currentSlice && is == nSteps - 1 ){ |
| 126 | + if ((!isElastic && theProc.find(std::string("Inelastic")) != std::string::npos) || (isElastic && theProc.find(std::string("hadElastic")) != std::string::npos)) { |
| 127 | + // std::cout << "found! " << theProc << '\n'; |
| 128 | + interactInSlice = 1; |
| 129 | + } |
| 130 | + result.push_back( std::make_pair(sliceEnergy, interactInSlice) ); |
| 131 | + } |
| 132 | + //Same slice, not the end. Check for interactions |
| 133 | + else{ |
| 134 | + if ((!isElastic && theProc.find(std::string("Inelastic")) != std::string::npos) || (isElastic && theProc.find(std::string("hadElastic")) != std::string::npos)) { |
| 135 | + // std::cout << "found! " << theProc << '\n'; |
| 136 | + interactInSlice = 1; |
| 137 | + } |
| 138 | + } |
| 139 | + |
| 140 | + //Update oldslice |
| 141 | + oldSlice = currentSlice; |
| 142 | + } |
| 143 | + |
| 144 | + return result; |
| 145 | +} |
0 commit comments